嘿,我不知道为什么这个循环不起作用,这一切似乎都是对的,但 while 内没有任何效果,请帮助,其余的代码位于其他文件中,如果您需要它们,我可以发布它们
#include <stdio.h>
#include "weatherstation.h"
int dunits = METRIC;
void main(void)
{
char test;
InitializeWeatherStation();
while(1);
{
UpdateWeatherStation();
printf("Enter m for Metric units, b for British units, or q to quit");
scanf_s("%c",&test);
if(test == 'm')
{
dunits = METRIC;
}
else if(test == 'b')
{
dunits = BRITISH;
}
else if(test == 'q')
{
return;
}
DisplayWeatherData(dunits);
}
}
最佳答案
while(1);
{
something;
}
完全与:
while(1)
{
}
{
something;
}
换句话说,你所拥有的是一个无限循环,后面跟着一个作用域代码块(永远不会到达)。
去掉分号,它应该可以解决该特定问题。
关于c - Easy C 程序 While 循环不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40098699/