Re: Pass an EOF before pressing enter



Camellia wrote:

When I try to run the code:
....
while (scanf("%c", &c) == 1)
printf("%c", c);
....
I input "abcd" follows by an EOF(Ctrl + d) instead of pressing
enter, and the program prints "abcd" on the screen. And then I
pass an EOF signal the program ends.

My question is why doesn't the program end the first it encounters
the EOF after the "abcd"?

Because you may really want to input a ^d it is only an EOF signal
when presented at the beginning of a line. You probably had to hit
ENTER (or return) after the first ^d.

And also if I DO press enter after "abcd", do I pass the characters
'a', 'b', 'c', 'd', '\n' to the program?

Yes.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>


.