Tutorials

How to program in c from linux

Table of contents:

Anonim

If you are starting out in the fabulous world of programming and you use Ubuntu (a good environment for programming), today we want to tell you how to program in C from Linux. You will surely ask yourself this question at first, because you may be very lost and find absolutely no confidence. In today's article, we are going to tell you a trick that will come in handy to compile and run C programs on Linux.

How to program in C from Linux

These are the steps you have to follow:

The first thing is to install the build packages. To do this, open a console and run the following command with permissions (it will ask for your password, it's yours for Ubuntu):

  • sudo apt-get install build-essential

Once everything is installed, you have the environment ready to compile your projects.

  • Create a plain text file but save it with the extension " .c ". Now, in terminal, run:
    • gcc program.c -o program (compiles the file program.c we call it "program") ./program (runs the program).

In order for your C program to do something, you will have to add the necessary code.

It starts with the classic "Hello World"

One of the most suitable codes to start in any programming language is Hello World . You just have to open a text file and copy and paste the following text.

#include int main () {printf ("Hello world"); printf ("\ n"); system ("pause"); return 0; }

You can save it as “ holamundo.c “. Then, you compile and run it as we told you above and it should work for you. Since it has a printf, all it does is display the hello world text string (on the console) and then leave a line break.

I hope that now you know how to program in C from Linux. You see that installing the previous package from the console will serve you for any Linux distribution. You can program in C in Ubuntu easy whenever you want. You will only need to create a text file with a.c extension, compile it and run it as we saw above.

Tutorials

Editor's choice

Back to top button