Newline stays in buffer after fgets()?

I am unable to replicate your problem using GCC on a Mac OS X system. Are you perhaps using a Windows system where pressing ENTER might produce both a CR and an LF? In any event, note that getchar() will not usually return immediately after a single key press because by default on most systems stdin is line buffered meaning that the terminal subsystem won't deliver any characters to the user process until ENTER is pressed getchar() is not a substitute for the old DOS conio.

H functions like getch() Getting around that depends on what O/S you're on.

I am unable to replicate your problem using GCC on a Mac OS X system. Are you perhaps using a Windows system where pressing ENTER might produce both a CR and an LF? In any event, note that getchar() will not usually return immediately after a single key press because by default on most systems stdin is line buffered, meaning that the terminal subsystem won't deliver any characters to the user process until ENTER is pressed.Getchar() is not a substitute for the old DOS functions like getch().

Getting around that depends on what O/S you're on.

Nope, I am on Linux. – linkmaster03 Dec 6 '10 at 0:02 fgets always reads in a newline if it sees one. If a newline is read, it is stored into the buffer.

– Alex Dec 6 '10 at 0:08 1 yup, I didn't say otherwise. What's unclear is why apparently pressing enter just once causes both his fgets() and getchar() calls to complete. It just works, for me.

– Alnitak Dec 6 '10 at 0:10.

In any event, note that getchar() will not usually return immediately after a single key press because by default on most systems stdin is line buffered, meaning that the terminal subsystem won't deliver any characters to the user process until ENTER is pressed. Getchar() is not a substitute for the old DOS functions like getch().

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions