Session 2 : C programming

We are going to learn programming in C in Linux with nano, the first thing that we had to do was create a directory called part-1 and there create a file with the command touch called hello_world_1.c but before we try to open it with nano we have to install obviously nano

fi1.pngNow, we are ready to open the file with nano, just type nano hello_world_1.c

fi2

First  gcc -c hello_world_1.c compiles hello_world_1.c into a machine code file named hello_world_1.o and then links hello_world_1.o with some system libraries to produce the final program hello_world_1.exe in this case

ccccc.png

So, finally we can run this first example with ./hello_world_1.exe

fifififi.png

Now we will create in part-1 the directory called example-02 and there create the file hello_echo_1.c

2

Open it with nano and type all this

ya

Then we are going to do the same thing that we did in the first example

4

And finally we can run hello_echo_1

6

We wanted to upload to our repository in github just the files which have the code, so we create the hidden file .gitignore

7

with vi we type this

8

then we notice that we have it with the command ls -a to show the hidden files

9

Now in another directory called example-03 we are going to do the example 3 called hello_strings_1.c , in the picture I was wrong with the name so I renamed it with the command mv

12

Now type all this for the example

13

We have to the files .o and .exe to run our program and this will be the output

14

For the fourth example, we are going to do something new, create the file Makefile and also create the program called hello_structs.c

1

We open Makefile and type this to replace our command gcc

2

Now open the file hello_structs_1.c and type this

3

4

We said that with Makefile we are going to replace gcc, so now we will type make clean to remove our file .o and .exe, for that reason when we type ls -1 we have only two files hello_structs_1.c and Makefile, then with make we are going to create .o and .exe files and finally with make run we have the output of the program

5

And that’s all, we have to upload it in our repository 6

You can visit my repository here.

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s