Rohit Rohit - 1 year ago 87
C Question

getchar() in c while using it

main ()
int c;
while ((c = getchar()) != EOF)

I know that
buffers the character. If i execute this program and input some character like
and without pressing enter I pressed
character why it printing
again and asking for new character?

Answer Source

When you type the 'EOF' character, the terminal driver makes all the characters in the input buffer available to the program, even if you've not typed a newline. Since the code underneath getchar() got some characters, it wasn't at EOF yet. When you type the second 'EOF', there are no characters left to be sent (but the terminal driver lets the read() function know there were 0 bytes available), so the read gets 0 bytes returned, which indicates EOF.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download