Question

So I've been trying to get this code to compile using a gcc compiler using c (I found lots of references to c++ but none to c so I asked this) I kept on getting the error Badly placed ()'s every time I go to run the program. So I simplified it to a very simple Hello World test program and I still get the same error.

What could be causing this error?

#include <stdio.h>

int main(int argc, int* argv[])
{
        printf("Hello World\n");
        return 0;
}
Was it helpful?

Solution

It seems that you are not trying to execute the compiled binary, but that you have a system that runs a tcsh and you are feeding the C source code directly into that shell:

> tcsh /tmp/badly.c 
Badly placed ()'s.

A C program must first be compiled to a binary (here: /tmp/badly), and then you have to execute that binary:

> gcc /tmp/badly.c -Wall -o /tmp/badly
/tmp/badly.c:3:5: warning: second argument of 'main' should be 'char **' [-Wmain]
> /tmp/badly 
Hello World

As ouah already noticed in his answer, with the -Wall argument to gcc you also get the informative message that the parameters of your main function are wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top