0

I'm new using Ubuntu OS, I've Ubuntu 12.04 and I'm trying to run a simple Hello world C program

#include <stdio.h>
int main(){
printf("Hello world!");
return 0;
}

When using gcc --version command at cmd, it returns 4.6.3 (I think that is the version), the problem is that when I try to use the command gcc helloworld.c in the address where the helloworld.c file is, it doesn't prompt anything, not the hello world! printing nor an error, the cmd just change line like if the enter key was pressed, but it appears that an a.out file were create by the command.

I've been working with python in the same way by using python file.py command and have no problem, what am I doing wrong?

Thanks for reading!

0

2 Answers 2

2

When write programs in C, you must compile the program with a compiler (here gcc). So you get an executable file (here a.out).

you should give that file execution permissions with the following command:

chmod +x a.out

and then run your compiled program with

./a.out
2
  • Do I've to give execution permissions everytime I write a new code? Thanks you solved my problem! :)
    – Esteban
    Apr 26, 2016 at 2:01
  • 1
    gcc already marks the file as executable.
    – psusi
    Apr 26, 2016 at 2:28
1

You can also customize the output file by using gcc <sourcefilename> -o <destinationfilename>

Note: you can even dump the output file in a different folder by including the path in the file name. Ex

gcc mysource.c -o ./myfolder/mybinary.out

This will create a file named mybinary.out in the folder, myfolder, within your current working directory. ./ is short had for the current working directory.

0

Not the answer you're looking for? Browse other questions tagged .