EOF的理解

来源:互联网 发布:程序员高清图 编辑:程序博客网 时间:2024/06/05 14:48

因为自己不大清楚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 两个错误。委屈

0 0
原创粉丝点击