How to write compile and run C program on linux

Posted: March 2, 2017 in C
Tags: , , ,

In this tutorial we will learn how to compile and run C program in Linux.If you are a C programmer or an Engineering student you always need to write C program and compile and run it.But many of you even some  good C programmers don’t have idea how to write and compile C program in Linux.C programming in Linux is not a difficult task, it’s just you don’t know that.After reading this article you will be able to write compile and run C program in Linux easily.Let’s have a look and understand C programming in Linux through few simple steps.

STEP 1: Install C Compiler.

 

[root@localhost ~]# yum install gcc*
Loaded plugins: rhnplugin, security
Repository 'a' is missing name in configuration, using id
This system is not registered with RHN.
RHN support will be disabled.
a                                                                                      | 1.3 kB     00:00
Setting up Install Process
Package gcc-4.1.2-46.el5.i386 already installed and latest version
Package gcc44-gfortran-4.4.0-6.el5.i386 already installed and latest version
Package gcc-objc-4.1.2-46.el5.i386 already installed and latest version
Package gcc44-c++-4.4.0-6.el5.i386 already installed and latest version
Package gcc-gfortran-4.1.2-46.el5.i386 already installed and latest version
Package gcc-gnat-4.1.2-46.el5.i386 already installed and latest version
Package gcc44-4.4.0-6.el5.i386 already installed and latest version
Package gcc-java-4.1.2-46.el5.i386 already installed and latest version
Package gcc-objc++-4.1.2-46.el5.i386 already installed and latest version
Package gcc-c++-4.1.2-46.el5.i386 already installed and latest version
Nothing to do
[root@localhost ~]#

 

STEP 2: Write and Save C program in Linux.

 

[root@localhost ~]# cat > satish.c
#include<stdio.h>
void main()
{
printf ("Satish Tiwary From Ethical Hacking Tuition center jaipur");
}
[root@localhost ~]#

 

STEP3:Compile  C  Program “satish.c”  Now

here i have compiled  c program satish.c and save it executable file in cprogram file.

 

[root@localhost ~]# gcc satish.c -o cprogram

 

STEP4:RUN C PROGRAM

Now run the C program and check your output.

[root@localhost ~]# ./cprogram
Satish Tiwary From Ethical Hacking Tuition center jaipur

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s