Your getchar()
call returns one character from the standard input. When a users enters an answer, he then hits an enter/return key which translates to new line character which is part of the line that is then sent to standard input.
What you should probably do is to only check first character returned by getchar
and then, in loop, read and discard all characters until you get new line character (\n
). Only then, you can proceed to ask the question another time.
You should use this loop because your user may enter several characters at once. For example he may enter "yes" which will count as 4 characters.