coady havens coady havens - 1 month ago 6
C Question

Easy C Program While loop Not Working

hey im lost on why this loop doesnt work it all seems right but nothing inside the while works please help the rest of the code is in other files if you need them i can post them

#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);
}
}

Answer
while(1);
{
    something;
}

is exactly the same as:

while(1)
{
}
{
    something;
}

In other words, what you have there is an infinite loop followed by a scoped block of code (which will never be reached).

Get rid of the semicolon and it should fix that particular problem.