Why does scanf appear to skip input?

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

    You are ignoring the return value. See what the manual says about scanf(3):

    RETURN VALUE
    These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.

    It fails matching an integer.

提交回复
热议问题