c - Easy C 程序 While 循环不工作

标签 c loops while-loop infinite-loop

嘿,我不知道为什么这个循环不起作用,这一切似乎都是对的,但 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/

相关文章:

c - MPI 如何决定我们创建多少个进程

c - 什么是 .dbg 文件以及它们与 gcc 中的 `-g` 选项有什么关系

java - 导航不同对象的复杂树的最佳方法是什么?

c - 这个语句在 C 程序中意味着什么? "While (scanf ("%d", &t) ==1)"为什么我应该在 while 循环中编写程序的其余部分?

c - 编译Linux内核模块时出错: "CONFIG_X86_X32 enabled but no binutils support" and unwanted "n" characters

c++ - 带指针的 bitWrite 函数

java - 未创建或显示异常

PostgreSQL 循环通知

c - 如何在c中输入两个空格分隔的单词有时可以省略一个单词

c - 为什么“while(!feof(file))”总是错误的?