Why Ctrl-Z does not trigger EOF?

前端 未结 2 1232
既然无缘
既然无缘 2020-11-30 14:40

Why Ctrl+Z does not trigger the loop to finish on the following small program?

#include 

        
2条回答
  •  被撕碎了的回忆
    2020-11-30 15:06

    EOF like you use it is not a character. It's the status in which that stream is.

    I mean, heck, you even link this question, so you might as well read the accepted answer:

    The underlying form of an EOF is a zero-length read.

    It's not an "EOF character".

    http://www.c-faq.com/stdio/getcharc.html cites a different case than yours, where someone stored the return value of getchar in a char. The underlying problem still occurs occasionally: different runtimes implement different values for the EOF integer (which is why I said, it's not an EOF character), and things love to go wrong. Especially in Visual C++, which is not a "real" C compiler but a C++ compiler with a compatibility mode, it seems things can go wrong.

提交回复
热议问题