char c;
int i=0;
while( ( c = fgetc(file) ) != EOF )
{
fgets (array[i].word, 101, file);
printf(array[i].word);
i++;
}
变量
array
是一个struct
类型,struct
具有字段:char word[101]
。file
是我们正在读取的文件。文本文件包含:
Hey You
Look!
但我的程序输出是:
ey You
ook!
有人知道为什么会这样吗?
最佳答案
有人知道为什么会这样吗?
是的,您正在用fgetc
阅读第一个字符。
使用while(1)
和fgets
的返回代码来确定您是否在输入文件的末尾。