只是测试一些代码;在我输入'n'之前应该运行以下内容。但它在一轮后停止。任何人都可以解释它,并帮助我实现我想要的吗?为什么C中的while循环终止了
#include <stdio.h>
int main()
{
char another = 'y';
int num;
while (another == 'y')
{
printf ("Enter an number ");
scanf ("%d", &num);
printf ("square of %d is %d", num, num * num);
printf ("\nWant to enter another number y/n\n");
scanf ("%c", &another);
}
}
谢谢。
我真的很感谢每一个人的评论。我在网上搜索GDB,稍后再使用它。我不得不说它使得更容易识别问题。 非常感谢。
参见[这个问题](https://stackoverflow.com/questions/13542055/how-to-do-scanf-为单焦型的-C)。 – vaindil
在发布SO之前,您是否曾想过使用您的调试器来检查scanf读取的内容,甚至只是为了打印出其值? –