I want to run a c program on ubuntu 18.04, on a virtual machine, and I get this error:

./test.c: line 3: syntax error near unexpected token `('
./test.c: line 3: `void main(int argc, char** argv)'

I compiled and ran the file like this:

gcc -o test test.c

I gave permission to the folder using:

sudo chmod a+rwx

I've searched online, and what I know is that ( is a special character in the shell/terminal but I could not understand/find a way to use it when I write code without error.

Can someone please help me solve this problem?


In gcc -o test test.c the test after -o flag is the name of actual executable, so you need to run ./test. When you do ./test.c the shell will attempt to read your C source code ( which is just text file ) as shell script and execute it according to current shell's syntax ( i.e., shell tries to read it a shell script, not as compiled C code).

On side note, please don't use test as name for executable. There's already /usr/bin/test and that can lead to confusion later. And overall using system executable names for personal programs is just bad practice

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.