Tag: 无限循环

C在按键上退出无限循环

当按下某个键时,如何退出无限循环? 目前我正在使用getch,但它会尽快开始阻止我的循环,因为没有更多的输入要读取。

是while(1); C中的未定义行为?

在C ++ 11中,它是未定义的行为 ,但在C中是这样的, while(1); 是未定义的行为?

scanf忽略,无限循环

int flag = 0; int price = 0; while (flag==0) { printf(“\nEnter Product price: “); scanf(“%d”,&price); if (price==0) printf(“input not valid\n”); else flag=1; } 当我输入有效数字时,循环按预期结束。 但是如果我输入一些不是数字的东西,比如hello ,那么代码会进入无限循环。 它只是保持打印Enter Product price:并且input not valid 。 但它不等我输入一个新号码。 这是为什么?