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

前端 未结 6 850
梦毁少年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:45

    Here is my one,
    i went through the same problem and same answer but i finally found what every body want to say.
    System specification :: Ubuntu 14.04 lts
    Software :: gcc
    
    
    yes the value of EOF is -1 based on this statement
    printf("%i",EOF);
    
    but if your code contain like this statement
    while((char c=getchar)!=EOF);;
    and you are trying to end this loop using -1 value, it could not work.
    
    But instead of -1 you press Ctrl+D your while loop will terminate and you will get your output. 
    

提交回复
热议问题