我正在尝试一次一行地输出文件中的文本.我目前正在硬编码,到目前为止我有这个:
int main(int argc, char *argv[])
{
int x;
int k;
int limit = 5;
FILE *file;
file = fopen("C:\\Documents and Settings\\jon\\My Documents\\Visual Studio 2008\\Projects\\Project1\\Assignment8_2\\Debug\\TestFile1.txt", "r");
if (file == NULL) {
perror("Error");
}
for (k = 1; k <= limit; k++) {
while ((x = fgetc(file)) != '\n') {
printf("%c", x);
}
}
fclose(file);
}
Run Code Online (Sandbox Code Playgroud)
我想知道上面的代码在哪里,如果有的话,我可以检查EOF.我想我需要这样做,但不知道为什么.还在学习....谢谢!