A question about this has been asked here End of File (EOF) in C but it still doesn't completely solve my problem.
EOF
makes sense to me in any datastream which is not stdin
, for example if I have some data.txt
file, fgetc()
will read all the chars and come to the end of file and return -1
.
What I don't understand is the concept of EOF
in stdin
. If I use getchar()
, it will wait for me to enter something, so if there is NOTHING written, End of File, (EOF
) is not returned automatically?
So is it that only the user can invoke EOF
in stdin
by pressing Ctrl+Z?
If so then what are some of the uses of EOF
in stdin
? I guess it tells the program to continue reading until the user invokes end of file? is this it?
Thank you