So I keep getting an error: syntax error near unexpected token '(' and it's referring to the line 'int main(){' in my code. I don't know why I'm getting this error, can someone please help?
11 Answer
There are a few things that could be going on, first try to build and run this minimal program by typing the following lines in a terminal.
echo "int main(int argc, char* argv[]){ return 0; }" > test.c
gcc test.c -o test
./testThis will show whether you have the minimal set of tools available to build a C program.
If this works it is possible that there are some odd characters in your source code, this can sometimes happen if you have copied the code from a document or website.
running the hexdump command in a terminal on your source code file and checking that the characters are all standard ascii might help find a rogue character.
hexdump -C test.c
00000000 69 6e 74 20 6d 61 69 6e 28 69 6e 74 20 61 72 67 |int main(int arg|
00000010 63 2c 20 63 68 61 72 2a 20 61 72 67 76 5b 5d 29 |c, char* argv[])|
00000020 7b 20 72 65 74 75 72 6e 20 30 3b 20 7d 0a |{ return 0; }.|
0000002eI use the man command man ascii in a terminal to get an ascii table for reference.