Score:0

syntax error near unexpected token '(' when initializing main

vn flag

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?

hr flag
Please [edit] your question to describe exactly what you are doing when you encounter this error - it *sounds* like you are trying to execute C source code with a shell interpreter
Score:2
fr flag

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
./test

This 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; }.|
0000002e

I use the man command man ascii in a terminal to get an ascii table for reference.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.