MParker
MParker

Reputation: 315

Beginner: syntax error before int main ()

I'm trying to run a Hello World program but am getting the error

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

or

./ex1.c: 3: ./ex1.c: Syntax error: "(" unexpected

or

./ex1.c:3: unknown file attribute: i
./ex1.c:4: parse error near `}'

The weird thing is I've run this same program before and had no issues.

Not sure if these issues are related but the problem happened after I installed Valgrind to run exercise 4 in Learn C The Hard Way. I received an error that said permission denied which I fixed using chmod +x. Then all my .c files needed permission which they had not before. I then did chmod -R 0777 for the directory with all of my .c practice files. So the permission problem is fixed but then the error above started. They may be completed unrelated but wanted to include just in case.

Upvotes: 8

Views: 33418

Answers (2)

ThinkTankShark
ThinkTankShark

Reputation: 39

After you compile the program by using make "your program name" (like make mario in this case), then just use ./"your program name" (this case ./mario). DO NOT add .c when running the program.

Upvotes: -2

nneonneo
nneonneo

Reputation: 179717

You can't run a .c file just by using ./ex1.c; you have to compile it into a runnable program first.

Assuming you have a Linux/OS X machine, use gcc -Wall ex1.c -o ex1 to compile it (or, more simply, make ex1). Then you can ./ex1 to run the program.

Upvotes: 12

Related Questions