Before starting working on the tutorials and programming assignments you should make sure you are familiar with a few important C programming concepts.
To test your C programming skills you are encouraged to solve the programming exercise described below.
Before you continue, you must clone the
From the terminal, navigate to a directory where you want the cloned directory to be created and execute the following command.
$ git https://github.com/uu-os-2018/address-book.git
The functions you need to implement are already declared in
You should also define the structures you will need in
address_book.h. You are
free to create more functions if you want.
In the file
address_book.c you should implement the functions declared in
main() function, which is the entry point of your program will be in a
Create a struct Person that will be used to represent a person. This struct should store:
It is up to you to choose the right datatypes for the fields of the structure.
Create a struct
Address_book that will contain a pointer to an
array of struct
Person, as well as the size of this array (the number
of persons in the address book).
Create a function
print_person() that takes a pointer to a
Person structure and
prints its details on the standard output.
A possible output for a person named John Doe, 42 years old, with the phone number +46712345678:
Name: John Doe Age: 42 Phone number: +46712345678
Create a function
print_address_book() that takes a pointer to an address book
and prints its details on the standard output. Make use of the
function you just created.
A possible output for an address book containing two entries is:
==== Address book (2 entries) ===== Name: John Doe Age: 42 Phone number: +46712345678 Name: Foo Bar Age: 24 Phone number: +46787654321
We will now read information from the user and store it into an address book.
create_address_book() function. This function should:
Personof the correct size and store a pointer to it in the address book. You are not allowed to use Variable Length Arrays!
Hints: Dynamic allocation is done with
malloc(). Reading from the standard input can be done using