Second Session : C programming

We start at 10 am at CTIC , as you can read in the title is the second session but not for me . The last sunday was the first time that I came to CTIC for a training session for Google Summer of code and I joined the group led by Julita . In this session we learn the basic of C . I coded in C in my second year in my university but I didn’t know all that Martin teach us that day.

We start with a basic program .

Sublime Text

I save this program as hello_world_1.c and after that I started to compile it I use git bash command line .With 3 commands :

  • gcc -c hello_world_1.c ( To compile)
  • gcc hello_world_1.c -o hello_world_1.exe (To link)
  • ./hello_world_1 ( Finnaly , execute)

And the program is ready!

Git Bash

We made other simple program because was necesary understand the meaning of “ int argc” and “char *argvc[]” in some programs in C. Martin explained us that :

Sublime Text
  • argc : It is the number of arguments that our program receives when it is called from the command line (and from any other side).
  • argv : Contains the values of the arguments entered by command line (and from any other side). The arguments entered are separated by spaces as long as they are not in quotation marks .
Git Bash

As we can see , the programa returns the arguments that you give it .

Expresions like “%d” , “%i” , “%s” are format specifiers and “\t” ,“\n” are escape sequences

After that we work with strings and pointers. A pointer is a variable that contains the memory address of a data or another variable that contains the data in an array. The file is called hello_string_1.c.

“hello_string_file_1.c “ — part1
“hello_string_file_1.c “ — part2

We compile the program with the 3 gcc commands previously written and the output is like this.

Output for “hello_string_file_1”

In this part of the session , Martin taught us how to make a MAKEFILE that basically make easier the process of compilation because you only need to write one command instead of three.

Makefiles are a simple way to organize code compilation
MAKEFILE on VI editor

To use the MAKEFILE we made other example , now with structus .

Arrays allow to define type of variables that can hold several data items of the same kind. Similarly structure is another user defined data type available in C that allows to combine data items of different kinds.

In this file we define a complex struct which has a real part and imaginary part both are integers. Also a method is defined to add complex numbers.

Now to compile this we use the makefile. And the result is

You can visit my repository here.

Like what you read? Give Carlos Lopez a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.