My question is simple, but I can not find it on google, so I'm here.
Basically, as an example, I read a bunch of integers before EOF from the input file. I used fgetc to check, but then it moves the file pointer to the address of the second integer. How can I check the EOF in this while loop without moving the file pointer while checking it?
Keep in mind that I will do something much more complex with this loop than scanning in integers. Also, I don't know how to use fscanf instead of fgets. This is just a simple example to show you what I mean.
while(fgetc(ifp) != EOF) { fscanf(ifp, "%d", &test); printf("%d\n", test); }
If the input file has integers 1-10, for example, the above code will print:
2 3 4 5 6 7 8 9 10
Missing 1!
source share