How does C handle EOF? [duplicate]
问题 This question already has answers here : Why is “while ( !feof (file) )” always wrong? (4 answers) Closed 6 years ago . #include <stdio.h> int main() { FILE* f=fopen("book2.txt","r"); char a[200]; while(!feof(f)) { fscanf(f,"%s",a); printf("%s ",a); printf("%d\n",ftell(f)); } fclose(f); return 0; } I have the code above. book2.txt contains "abcdef abcdef" with the cursor move to a newline(ie:abcdef abcdef\n). I get the results below. abcdef 6 abcdef 13 abcdef 19 I expect to get abcdef 6