Computersnyou

C Programming–In Linux (Step By Step)

Posted on  1/21/2012
If you are new to linux and want to right your C programs in this platform, then this post will help you out.You don’t have to know linux in order to write your C programs on this platform.Just follow these steps:
Before getting into the steps let me remind you I am using “Fedora 15”.A newer version of Fedora is available “Fedora 16” you can try it too.So now we are ready to rock and roll.
Step 1
Go to Application -> System Tools –> Terminal and then click on “ Terminal
image
Step 2
A terminal window will pop up.
Now we need an editor like “Notepad” in Windows to write our codes.So, to do that we will use the vi editor,a built in text-editor in Linux.
Just type vi followed by name of your C program and hit enter.
For example
vi  SimpleProgram.c
Screenshot-18
A vi editor screen will appear.
Screenshot-13
Step 3
Then just press “ i ” on your keyboard to get into the “ insert mode.Now we are ready to start coding.
Screenshot-14
Step 4
Now let us write a simple program
Screenshot-16
Step 5
When you are done with your C coding and want to exit from the vi editor screen just press
Esc” key and then type “ :wq “ and hit “Enter”.
Screenshot-17
Step 5
Now we will again return to terminal screen

Screenshot-18
Step 6
Now we will compile and run our “SimpleProgram.c”.To compile just type
gcc  –o Object_Name  C_Program_Name
For example
gcc  –o Simple_obj  SimpleProgram.c
Screenshot-19
After successful compilation a Object file will be created based on your Object Name.In this case
Simple_obj
Screenshot-20
To run your c program just type
./Object_Name “ and hit “Enter
For example
./Simple_obj
Screenshot-21
The Output will be printed on the Screen.
This is what to need to do in order to write and run your C program in Linux.
If you want to know some more commands to start yourself with Linux then just visit the link below
Linux Basics
If you have any query then do post a comment.
Thanks !!!


  • Home
  • About