char ch;
int n = 0;
FILE* fp;
fp = fopen("test.txt", "r");
while(!feof(fp)){
n++;
fscanf(fp, "%c", &ch);
fprintf("%c", ch);
}
printf("%d\n", n);
test.txt below
abcd
I tried to count how many time does this while loop go by printing out integer n. I thought the result would be 4 cuz fp only contains 4 characters, "abcd". But actual result was 6. There are two newline character which is ascii code 10 before EOF.
I double-checked test.txt file and it contains no other character then abcd. Where did these 2 newline characters come from? I used vim editor.