EOF
is just a macro with a value (usually -1). You have to test something against EOF
, such as the result of a getchar()
call.
One way to test for the end of a stream is with the feof
function.
if (feof(stdin))
Note, that the 'end of stream' state will only be set after a failed read.
In your example you should probably check the return value of scanf and if this indicates that no fields were read, then check for end-of-file.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…