Code:
int main()
{
char weight[6];
int validity, break_flag;
while(1)
{
break_flag = getinput (weight);
if (break_flag == 1)
break;
validity = validate(weight);
if (validity == 1)
printf("%s - Too Heavy\n", weight);
else
printf("%s - Cleared\n", weight);
}
return 0;
}
I have the following code as my main function but I have just been told I'm not allowed to have a loop in my main. I tried moving the while loop to new function and using main to call that function (as below) but got the following errors:
weight.c: In function `loop':
weight.c:111: warning: control reaches end of non-void function
weight.c: In function `main':
weight.c:115: warning: statement with no effect
The program works fine before the changes.
Code:
int loop()
{
char weight[6];
int validity, break_flag;
while(1)
{
break_flag = getinput (weight);
if (break_flag == 1)
break;
validity = validate(weight);
if (validity == 1)
printf("%s - Too Heavy\n", weight);
else
printf("%s - Cleared\n", weight);
}
}
int main()
{
loop;
return 0;
}