Reputation: 1805
char ch;
while((ch=getc(stdin))!=EOF)
{
putc(ch,stdout);
}
As we know that EOF character can be inputted by ctrl-z
.
I ran the program two times:-
1- When I input ctrl-z
, the loop gets terminated, which is acceptable.
2- When I input ctrl-z
along with some other text like demo
and then press ctrl-z
, then the loop does not get terminated.
So my question is that why the loop is getting terminated only by inputing ctrl-z
alone?
Upvotes: 0
Views: 63
Reputation: 22542
EOF
is not a character that you can put into a stream. It's a meta-control character that can be returned by getc
, but can not be written. ctrl-z
does not technically send EOF
, it sends SIGTSTP
to the process and getc
is programmed to respond to it by returning EOF
.
Upvotes: 2