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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With