By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,440 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,440 IT Pros & Developers. It's quick & easy.

Pass an EOF instead of pressing enter

P: n/a
Hi all,

I'll get straight into it.

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"?
And also if I DO press enter after "abcd", do I pass the characters
'a', 'b', 'c', 'd', '\n' to the program?

Any suggestions are appreciated.

Dec 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <11*********************@73g2000cwn.googlegroups.c om>,
Camellia <br*********@gmail.comwrote:
>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"?
This is really a question about your operating system, not about C.
Unix behaves as you describe - the EOF key only sends EOF after a
newline or another EOF.
>And also if I DO press enter after "abcd", do I pass the characters
'a', 'b', 'c', 'd', '\n' to the program?
Yes. This is the usual situation. Pressing EOF without a newline
first is a way of sending a line without a newline at the end.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.