Why does scanf appear to skip input?

前端 未结 7 1580
忘了有多久
忘了有多久 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:14

    You could check the return value of scanf to determine if an integer has been parsed correctly (return should =1). On failure, you have choices: either notify the user of the error and terminate, or recover by reading the next token with a scanf("%s" ...) perhaps with a warning.

提交回复
热议问题