Why does scanf appear to skip input?

前端 未结 7 1535
忘了有多久
忘了有多久 2020-12-19 13:17

I am confused about scanf\'s behaviour in the following program. scanf appears to input once, and then not input again, until a stream of characters is printed.

Belo

7条回答
  •  既然无缘
    2020-12-19 14:15

    You can never expect your users to enter valid things. The best practice is to read the input into a string and try to convert it to integer. If the input is not an integer, you can give an error message to the user.

提交回复
热议问题