Question: how eof works in c?
Answer: The value of EOF is -1 because it has to be different from any return value from getchar that is an actual character. So getchar returns any character value as an unsigned char, converted to int, which will therefore be non-negative. ... EOF will be false, and the loop will terminate.