我在Fedora 15計算機上存在一條線,我有一個簡單的代碼看起來像這樣的fscanf讀取不以文件
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x[50], y[50];
int i;
FILE *f_in = fopen("readtest.dat","r");
if (f_in == NULL) printf("No file...\n");
else
{
i = 0;
while (!feof(f_in))
{
fscanf(f_in,"%d %d",&x[i],&y[i]);
printf("%d %d\n", x[i], y[i]);
i++;
}
printf("I've read %d data.\n", i);
}
return 0;
}
的文件被讀的是這個
1 1
2 2
3 3
4 4
5 5
但我不知道爲什麼輸出看起來像這樣。
1 1
2 2
3 3
4 4
5 5
1250259108 1250140145
I've read 6 data.
我在想我在文件中留下了一個空白的新行,但我沒有。我再次用gedit和vim檢查了這個文件,沒有找到空行。我爲什麼要閱讀這條出現的線?
http://c-faq.com/stdio/feof.html – user786653