Hi guys! ))
please reply - how to clear the input stream of the console?
thanks in advance ))

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.

commented: +++ +1

Read characters until a newline or EOF is reached:

I mean - read the characters coming from keyboard ))

>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?

Narue, you are right but what is EOF (EndOfFile - as I know) in the console ?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.