Correct way of doing this?
I am getting some strange results from the following code:
Code:
while (fgets(buffer, 2048, pfile) != NULL)
{
sscanf(buffer, "%d %d", &stid[i], &stsc[i]);
printf("%d %d\n", stid[i], stsc[i]);
i++;
}
As you can see, its reading from a file with this type of format:
Code:
item1 subitem1
item2 subitem2
But after the while loop, and I call stsc[0], it contains elements that are supposed to be in stid. But this only happens AFTER the loop. During the loop, the output is correct. I need to use the arrays later on for something else, and with this happening, this isn't possible. Can anyone see if I'm misusing memory in some way?