嘿,我迷失了为什么这个循环不起作用这一切看起来都正确但是没有任何内部工作请帮助其余的代码在其他文件中,如果你需要它我可以发布它们
#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);
}
}
答案 0 :(得分:2)
while(1);
{
something;
}
与完全相同:
while(1)
{
}
{
something;
}
换句话说,你所拥有的是一个无限循环,后跟一个范围的代码块(永远不会到达)。
摆脱分号,它应该解决这个特殊问题。
答案 1 :(得分:1)
你不能以分号格式结束while(1)
。因为那是你在那里写的空语句。