That's a lot of questions.
Why EOF
is -1: usually -1 in POSIX system calls is returned on error, so i guess the idea is "EOF is kind of error"
any boolean operation (including !=) returns 1 in case it's TRUE, and 0 in case it's FALSE, so getchar() != EOF
is 0
when it's FALSE, meaning getchar()
returned EOF
.
in order to emulate EOF
when reading from stdin
press Ctrl+D