Beginning C Programming in Linux

Don't ask a lot to begin C programming in Linux. Just grab your tools and start small. This time, I just wanna show you how to start C programming in linux. You can use any Linux distro. However, if you are beginner, just follow me using Ubuntu Linux.

1. Install the required packages.
First of all, you have to make sure that you have C compiler to compile your code. In linux, we use "gcc - GNU project C and C++ compiler".

In Debian, Ubuntu and it's family distro, all the basic programming tools for C programming can be found in build-essential package. Use this command to install this package:

$ sudo apt-get install build-essential 

2. Write your first program
Now, after installing the required package, we can start coding our first program. As usual, you may start with a "Hello World" program.

Create new project directory
Under your home directory, you may start creating your project directory to begin with. In this example, I'm calling it as myhello:

$ mkdir myhello

Then, get into our project directory:

$ cd myhello

Now, create our hello.c file. You may follow this example "hello world" code or be imaginative to modified it as you like. Experiments to see what is possible to modify in this code:
#include <stdio.h>

int main() {

    printf("Hello My friend, Let's do C programming\n");
}

3. Compile your program.
To compile your first linux C program, launch your terminal and go to current directory where you put your hello.c code. Then, run this command:
$ gcc hello.c -o hello

After that, you will have an executable file called hello in this directory. Congratulations! you have created your first C program in linux. You can now, execute this program using this command:
$ ./hello

The output will be printed on your screen. You can add more stuff and experiments. Until next time, I hope you enjoy this. Happy coding...

Comments

Popular posts from this blog

How to Create Hyperlink on Blogger Post

How to Add a Sudo User on AlmaLinux 9.2 (Turquoise Kodkod): A Step-by-Step Guide

How to Check AlmaLinux Version on the Command Line: A Quick Guide