Why can't I find the value of EOF in C?

前端 未结 6 902
梦毁少年i
梦毁少年i 2020-12-30 13:48

I\'m reading the book \"The C Programming Language\" and there is an exercise that asked to verify that the expression getchar() != EOF is returning 1 or 0. Now

6条回答
  •  渐次进展
    2020-12-30 14:41

    EOF can be triggered through keyboard by pressing keys ctrl+d in Unix and ctrl+c in Windows.

    Sample Code:

        void main()
        {
               printf(" value of getchar() != eof is %d ",(getchar() != EOF));
               printf("value of eof %d", EOF);
        }
    

    Output:

    [root@aricent prac]# ./a.out 
    a
     value of  getchar() != eof is 1 value of eof -1
    [root@aricent prac]# ./a.out 
    Press    ctrl+d
     value of   getchar() !=  eof is 0 value of eof -1[root@aricent prac]# 
    

提交回复
热议问题