Ubuntu – GCC Fatal Error

cgccprogramming

everyone

Here's my problem; So, I'm new to Ubuntu and programming and I just wanted to start with C. I created the classic "hello.c" file

#include <stdio.h>   
main ()
{
    printf("Hello World!");
}

Then I typed within the terminal:

cd /Desktop

Because the file is located in Desktop

And then I typed

gcc hello.c -o hello

But here come the troubles, it suddenly appeared a problem that says:

gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

So, how can I fix that?

Best Answer

Desktop is not located at /Desktop rather it is located at ~/Desktop. Thus execute these commands.

  1. cd ~/Desktop (for changing directory to Desktop)
  2. gcc hello.c -o hello (for compiling C program)
  3. Then execute your application by ./hello , if it shows any error change its permissions with chmod +x hello
Related Question