This is my code:
for(b = 0; b < 3; b++)
{
int col1 = 0;
printf("b= %d\t" , b);
fgets(payload, sizeof payload, f2);
fputs(payload, stdout);
char *token;
token = strtok(payload, " ");
token = strtok(NULL, " ");
token = strtok(NULL, " ");
while ( token != NULL)
{
int pp;
sscanf(token, "%d", &pp);
token = strtok(NULL, " ");
printf("%d\n" ,pp);
grapharray[b][col1++] = pp;
}
}
In this code, I am taking some values from the file line by line and copying them into a 2D array. I am skipping the first two values from the file. Everything is working fine except my loop -- it copies the value correctly into location grapharray[b][col1]
, where b==0
, but then skips b==1
and directly moves to b==2
and copies the next row of the file at grapharray[2][col1]
. Can anyone help me with this problem? Thanks so much, I will be grateful.