Creating, Compiling and Running a C program in C

To create a C program in linux environment, firstly we need to open the terminal by typing Ctrl+Alt+T or open terminal application using GUI. After that we can create a C program using the following editor command with a filename having extension .c:

gedit filename.c

As soon as we type the command a text-editor window opens up. We type our program in the window, save and then close the window.

Then to compile the program we type the following command:

gcc -o filename filename.c

If there is any error in the program, we need to edit the program again using the editor command otherwise we need to run the output file generated after compiling.We type the following command to run the program:

./filename

Note:For linking the math functions from the standard C library i.e. the program includes the math.h library then we use the following command to compile the program.

gcc -o filename filename.c -lm
Advertisements

Author: Hifzur

I am a linux, programming and robotics enthusiast. I also love to write blog about life.

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