I'm new here. I am trying to do a forever loop with while (true) but can't seem to get it working. I have tried iterations without int main(void) as well.
#include <cs50.h>
#include <stdio.h>
int main(void)
while (true)
{
printf("goddamnit\n")
}
~/ $ make goddamnit
[clang -ggdb3 -00 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno
-unused-parameter-Wno-unused-variable-Wshadow
goddamnit. c
-cryp
-Ics50 -1m -0 goddamnit
goddamnit.c:5:1: error: expected function body after function declarator
while (true)
A
1 error generated.
make:
*** \[‹builtin>; goddamnit\] Error 1][1]
Same problem on my <> loop
int i = 0;
while (i < 50)
{
printf(“goddamnit\n”);
i ;
}
Note: Image in linked error
CodePudding user response:
You are missing {} braces around your main() function's body, it needs to look more like this instead:
#include <cs50.h>
#include <stdio.h>
int main(void)
{ // <-- add this
while (true)
{
printf("goddamnit\n")
}
} // <-- add this
Block statements like if, for, while, etc can omit {} when their body is a single statement. Functions cannot do that.

