How To Run C Program In Ubuntu?

Ubuntu is an open-source and open-access operating system. Ubuntu is used in research, software applications belonging to the research domain of mobile ad-hoc network provide more accurate results when run Ubuntu as compared to when run windows operating system.

Compilers of programming languages such as C are mostly installed on the Windows platform so when it is required to install on Ubuntu students often face difficulty in doing so. Developing a C program and executing it on Ubuntu requires learning of specific commands. This article provides you with basic commands and steps to install C language on Ubuntu 20.

Ubuntu terminal program is used for – installing C language, developing C program and executing C program. Following are the steps to attain desired objective:

Configuring build essential packages

Use this command to configure the build essential package.

$ sudo apt-get install build-essential         

To complete the installation process the user will have to enter the password for root.

Developing C program

Use this command to terminal prompt:

$ gedit

            Example:

              $ gedit  samPrg.c

This command will create a samPrg.c file which can be used to write a C program.

Ubuntu graphical text editor will get open with a blank file having name samPrg.c

//samPrg.c

#include
int main()
{
printf (“\n A sample c program”);
return 0;
}

Using gcc Compiler to compile samPrg.c

Use the following command to compile samPrg.c

$ gcc -o < program_Name without file extension >

$ gcc samPrg.c  -o samPrg

To compile using the above command the program should be in the Home folder otherwise the path to the developed program has to be entered in the above command.

Executing developed C program

To execute the C program following command must be used:

$ ./<Program_Name>
$ ./samPrg.c