【问题标题】:Easy C Program While loop Not Working [closed]Easy C Program While循环不工作[关闭]
【发布时间】:2016-10-18 02:46:20
【问题描述】:

嘿,我迷失了为什么这个循环不起作用,这一切似乎都是正确的,但是 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);
}
}

【问题讨论】:

标签: c loops while-loop infinite-loop


【解决方案1】:
while(1);
{
    something;
}

一模一样

while(1)
{
}
{
    something;
}

换句话说,你所拥有的是一个无限循环,后跟一个范围内的代码块(永远不会到达)。

去掉分号,它应该可以解决这个特定的问题。

【讨论】:

【解决方案2】:

您不能以分号结尾while(1)。因为那是你在里面写的一个空语句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2018-02-23
    相关资源
    最近更新 更多