因为自己不大清楚EOF 在terminal里面是怎么输入的,所以做了一个小实验。
#include <stdio.h>
#include <string.h>
int main()
{
int c ;
// FILE * fp;
// fp = fopen("hello.txt","r+");
c = fgetc(stdin);
if (c == EOF)
printf(" this is fun\n");
else
printf("this is stupid\n");
return 0;
}
输入ctrl +D 会输出 this is fun
直接回车 会输出 this si stupid
输入abc 回车,输出同上。
这个小例子 自己还曾把 c 定义为char*c 和c = EOF 两个错误。