C - Badly Placed ()'s?

风流意气都作罢 提交于 2019-12-11 20:24:38

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/19753406/c-badly-placed-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!