我想通过按“Enter”键而不是任何字母键来结束 while 循环。我不知道我该怎么做。 我已经这样做了,如果输入不是数字它将退出,但我希望输入是“Enter”键。
void main (void)
{
float f;
float total=0.0;
printf("Enter numbers to be add: ");
while (scanf("%f",&f)==1)
{
total=total+f;
printf("Enter another # to be add: ");
scanf("%1.0f",&f);
}
printf("Addition Total = %1.0f",total);
}
最佳答案
试试 fgets
... 应该可以。
http://www.codecogs.com/reference/computing/c/stdio.h/fgets.php
关于c - 如何通过按 'Enter' 键而不是任何字母键来结束 while 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999057/