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的返回代码来确定您是否在输入文件的末尾。

10-05 21:10
查看更多