I cannot figure out how to use fscanf to understand when my loop has run through all the numbers in a file.
I tried to use
while(fscanf(ifile, "%d", &num) !=EOF)
but it did not work properly
I cannot figure out how to use fscanf to understand when my loop has run through all the numbers in a file.
I tried to use
while(fscanf(ifile, "%d", &num) !=EOF)
but it did not work properly
It's probably almost working... but if there are non-numeric things in the file the loop will never progress. You should check the returned value. If it is 1, it was a number. If it was a zero (but still not EOF), whoops.... some crappola in the file. Now you have to somehow skip over that.
Here's a little intro I found doing a quickie search: http://www.cs.bu.edu/teaching/c/file-io/intro/
thank you!