Inputting float into a program that only deals with ints

后端 未结 3 1910
星月不相逢
星月不相逢 2020-12-07 02:44

I have a program, but when I input float numbers whenever the program asks for inputs, the program abruptly skips a step and moves onto the end output. The program is below:

3条回答
  •  感情败类
    2020-12-07 03:30

    It looks like scanf() is reading your "3" in the second case, and ignoring the "9".

    Then when the second scanf() is called, there is already text in the input buffer (the ".9").

    I can't tell exactly what it's doing with the ".9". It may have found the dot and just aborted there with b uninitialized. It should be a simple matter to determine what is happening by stepping through with the debugger.

    But, basically, not all the input is being processed by the first call to scanf() and so that's what the second call is trying to read. And that's why it's not waiting for you to input any data for the second call.

提交回复
热议问题