1) Open the terminal: Go to Applications => Accessories => Terminal
2) Create folder in home directory (It is always a good practice to save your programs in one folder. You may create it anywhere for your convenience)
Type the following in your terminal to create folder then press enter key
mkdir cprograms
Notes:
- cprogram is the name of your folder, replace it with the name you like!
- Skip to step three if you have your folder ready
3) Change directory to this folder you have created. Type the following and then press enter
cd cprograms
4) Create the source file. This is the file containing your source code. Suppose our file is named hello.c
gedit hello.c
5) In the editor that opened, type your program. Suppose the program is to display Hello World! on the screen, you type the following
#include
int main(){
printf("Hello World!\n");
return 0;
}
6) Save and close your editor
7) Compile your program: Type the following then press enter
gcc -o hello hello.c
Notes
- gcc is GNU C Compiler, it is shifted with ubuntu, and get installed automatically once you install ubuntu in your box
- hello is the executable created after successfully compilation
./hello
9) you will see your program output displayed on your terminal. In our example "Hello World!"
That is all you can do to create and run your program.
No comments:
Post a Comment