C programming
To study operating system concepts we will use the C programming language.
To study operating system concepts we will use the C programming language.
To study operating system concepts we will use the C programming language. To be able to understand the tutorials and solve the programming assignments you will need to be familiar with the following C programming concepts.
int
and char
.char
).#define
directive.printf()
to print text to the terminal.if-then-else
control structure.switch
control structure.while
loop.for
loop.For the tutorials and programming assignments you will be required to use the C programming language. If you are new to C or need to refresh you knowledge there are plenty of resources available on the web. On this page you find a small collections of recommended links.
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 c-address-book repository. From the terminal, navigate to a directory where you want the cloned directory to be created and execute the following command.
git clone https://github.com/os-assignments/c-address-book.git
The functions you need to implement are already declared in address_book.h
.
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
adress_book.h
.
The main()
function, which is the entry point of your program will be in a
file called main.c
.
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 print_person()
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 a create_address_book()
function. This function should:
Person
of 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 scanf()
or fgets()
.