How to run C language program in Ubuntu (Linux)
This pictorial tutorial on How to run C language program in Ubuntu.
I am using Ubuntu (Linux) here to show you how to run C code in Ubuntu & I am considering that you have some basic knowledge about Ubuntu and Linux It doesn't mean that I am hoping kernel level programming in Linux but only your basic knowledge about Ubuntu operating system like what is Terminal and GUI(Graphical user interface).
Also see, How to install Ubuntu in Win-7.
Okay so let's start.Its like eating piece of cake to run C language code in Ubuntu.All you need to do is just follow below few step and you are done.
Step 1:
Start with creating new document in Ubuntu.Right click > Create New Document > Empty Document.Then name the file as yourfile.c or test.c Whatever the file name you are giving it but don't forget to put extension .c and while giving file a name keep in mind that Ubuntu is case-sensitive.That means that in Ubuntu FILE.c is not same as file.c
Step 2:
Now open that file by double clicking it and it will be open in gedit named text editor.Now write your C program over there.See the example below.
Sample Code:
#include<stdio.h> //Include library
main()
{
printf("\nHello World!!!");
printf("\nhttp://www.engineerscur.com/");
}
Step 3:
After writing C code you need to compile the program.To do so open Terminal Alt+Ctrl+T.After that go to the directory(Folder) you are working on.In this case I am working on Desktop so I write below code.
cd ~/Desktop
cd is change directory command
~ is for Home directory shortcut
After that you should see following change in Terminal
If you see this that means you changed Directory successfully.
Step 4:
After that to compile your program enter below code.
gcc ./test.c -o test.out
gcc is compiler that you have to use(Its comes with Ubuntu so you don't need to worry about it).
-o is command which will tell your computer to give file name to output.
test.out is file name you are giving to output file which will be generated after compilation.
Which will generate output file named as test.out on which directory(folder) you are working on.
Step 5:
Now you have to run this .out (output) file.To do do type following code,
./test.out
And you are done !!!
---> Step by Step running your program will looks like this,
Remember Ubuntu is case-sensitive So don't get confused.