#include #include // This simple program reads 25 numbers from the file ints.txt and prints them. // Because the file has only 20 numbers stored in it the results for the // last 5 numbers are strange. // // To see what is going on the program prints the return value of fscanf. // fscanf returns EOF when the end of the file is reached. // In C EOF is defined as -1. int main() { FILE* fp; if( (fp = fopen("ints.txt", "r")) == NULL) { printf("File not found!\n"); } else { int i, num; for(i=1; i<=25; i++) { int res = fscanf(fp, "%d", &num); // store the return value of fscanf printf("%2d [res= %2d]\n", num, res); // print the int and the return value } fclose(fp); } system("pause"); }