此 scanf 应始终返回 true 直到我输入非数字输入,但此 scanf 从不执行 while 循环。为什么?
示例输入:
10.0 5.0
Press [Enter] to close the terminal ...
代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
float a, b;
while ( scanf("%f %f", &a, &b) == 1 )
{
printf("%f\n", (a - b) / (a * b));
}
return (EXIT_SUCCESS);
}
最佳答案
scanf
返回读取的项目数,在本例中为 2。
关于c++ - 为什么这个 scanf 返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3923558/