The program control flow doesn't work as expected

前端 未结 1 1408
醉梦人生
醉梦人生 2021-01-29 13:41

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         


        
相关标签:
1条回答
  • 2021-01-29 14:18

    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.

    0 讨论(0)
提交回复
热议问题