I was trying to make this simple Hello World program, however I receive the following errors. Someone can explain me why?
Program:
#include <cs50.h>
#include <stdio.h>
int main (void)
{
printf("hello, world! \n");
}
Errors:
~/workspace/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wno-deprecated-declarations -Wshadow hello.c -lcs50 -lm -o hello
hello.c:1:9: error: expected ';' after top level
declarator
int main
^
;
1 error generated.
make: *** [hello] Error 1
~/workspace/ $ ls
hello.c pset1/
~/workspace/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wno-deprecated-declarations -Wshadow hello.c -lcs50 -lm -o hello
hello.c:1:9: error: expected ';' after top level
declarator
int main
^
~/workspace/ $ cd
~/workspace/ $ make hello
make: *** No rule to make target `hello'. Stop.
~/workspace/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wno-deprecated-declarations -Wshadow hello.c -lcs50 -lm -o hello
hello.c:1:9: error: expected ';' after top level
declarator
int main
^
;
1 error generated.
make: *** [hello] Error 1
~/workspace/ $ clea
bash: clea: command not found
~/workspace/ $ clear
~/workspace/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wno-deprecated-declarations -Wshadow hello.c -lcs50 -lm -o hello
hello.c:1:9: error: expected ';' after top level declarator
int main
^
;
1 error generated.
make: *** [hello] Error 1
Thanks in advance.
UPDATE:
Hello,first of all thanks for your fast answers.
I have cheked to be in the rigth directory, and also that there is no copy of the file in other in different directories, but I still recive the same error.
Now I have deleted the file and created a new one also named hello.c inside the pset1 directory.
~/workspace/pset1/ $ ls
hello.c hello.txt
Again , I've tried to "make" the file but I still recive the same error, in fact, doing several tests, I have seen to recive this same error in every program that I do,independently of the code, as, I deduce that the problem is not the the sintax of the code.
~/workspace/pset1/ $ make hello
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wno-deprecated-declarations -Wshadow hello.c -lcs50 -lm -o hello
hello.c:1:9: error: expected ';' after top level declarator
int main
^
;
1 error generated.
make: *** [hello] Error 1
~/workspace/pset1/ $
On the other hand i've seen that in the CS50 videos, inside the terminal window, instead of having ~/workspace
they have the name of the user infront of the ~/
, is this a problem, or just an update of the CS50 IDE.
By the way,can be a problem to use the cloud based CS50 IDE, instead of the CS50 Appliance.
If you have any idea of where is the problem, I would really aperciate it, as now I'm completly stuck in this low level.
UPDATE2:
This is the result of the commands that you suggested:
~/workspace/ $ cd ~
~/ $ ls
bin/ lib/ sessions/ workspace/
~/ $ cat hello.c
cat: hello.c: No such file or directory
~/ $ cd workspace
~/workspace/ $ ls
pset1/
~/workspace/ $ cat hello.c
cat: hello.c: No such file or directory
~/workspace/ $ ls pset1
hello.c hello.txt
~/workspace/ $ find . -name hello.c
./pset1/hello.c
./.c9/metadata/workspace/hello.c
./.c9/metadata/workspace/pset1/hello.c
And this is the result of:
for i in $(find ~ -name hello.c ! -path "*/.c9/*"); do echo $i:; cat $i; echo; done
~/workspace/ $ for i in $(find ~ -name hello.c ! -path "*/.c9/*"); do echo $i:; cat $i; echo; done
/home/ubuntu/workspace/pset1/hello.c:
#include<stdio.h>
main()
{
printf("Hello World");
}
~/workspace/ $
And finally this is the code "hello world" that I'm working with:
#include<stdio.h>
int main(void)
{
printf("Hello World");
}
@NullityNull @Matt Obert
hello.c
file -- at least, to your own satisfaction. However, what you're typing doesn't help us to see that. I recommend sharing the output of exactly the commands I pasted in my answer below. Thecat hello.c
command will allow us to see that the code in that file actually matches what you pasted above. Thefind . -name hello.c
command will search for copies, in such a way that we can tell by the output whether any others are found, without needing to take your word for it.