Saturday 15 October 2016

// //

How to run C program in Linux??




Most of the students are having habit of using Turbo-C to write C  and C++ programs.They think it as easy to use and easy to run. But Turbo-C software is not giving actual sense of running c program.
 When you runs c program in turbo-c you have to write getch() to block or freeze output window.
Actually you are not freezing output window that is called as incomplete execution of program.
your program is waiting to get character from keyboard to come out from that command prompt.
When you are using Linux operating system to run your C program there is need of GCC compiler that is GNU Compiler Collection is used to compile c program. Most of the time it is by default present in Linux operating system. The explanation given below is related with Ubuntu.
You can check GCC version and whether it is installed or not by using simple command on terminal.
Command: gcc -v


If It is not showing the result then you have to install it through terminal.
Command for the same: sudo apt-get install gcc

After successful installation of GCC major question is how to run your c program.
Type your c program in editor such as gedit or any other editor which you like.
Save that program with .c extension.now from your terminal go to respective directory where you saved your c program.
After that you have to compile your C program with GCC.
Command for that is: gcc hi.c -o bye
I would like to explain the command 
gcc is command for compilation. Instead of gcc you can also use cc.
hi.c is file name
-o is attribute for output 
bye is output file name.
This Command will create executable file having name "bye".

After successful compilation compiler will create executable file bye.
now we have just type ./bye to run that executable.

You successfully executed c program.
In Next post we will see what actually happen behind the screen when you compile c program.