2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by vedro-compota
2

Read characters until a newline or EOF is reached:

int ch;

do
    ch = getchar();
while (ch != '\n' && ch != EOF);

This is the only portable method, but it also has a downside of blocking for input if the stream is already empty when the loop starts. Unfortunately, there's no way to get around that without breaking portability.

Votes + Comments
0

Read characters until a newline or EOF is reached:

I mean - read the characters coming from keyboard ))

0

>I mean - read the characters coming from keyboard
Yes, I assumed that's what you meant by "input stream of the console". How does my answer not apply?

1

You can signal EOF with a keyboard combination. On Windows it's Ctrl+Z, and on POSIX systems it's Ctrl+D.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.