This is a problem in C
. The program Control flow is not as expected. It ask to enter the character in but fail to ask to enter character x.
int foo
To clarify the comments mentioned above, in the process of giving input, you're pressing Y and then pressing ENTER. So, the y
is considered as the input to first getchar()
, and the ENTER
key press [\n
] is stored in the input buffer.
On the call to next getchar()
, the \n
is read, which is considered a perfectly valid input for getchar()
and hence your code is not waiting for the next input.