Download the start project here: c-integrated-start.c.
The program represents a book, consisting out of multiple pages, of which each page contains (random) text, represented as a char[]
.
The following functions are given:
printBook()
prints all pages of the book (no need to modify this)clearBook()
clears pages and frees memory (no need to modify this)createRandomBook()
creates a new book consisting out of amount
of pagescreateRandompage()
creates a new page with random textmain()
bootstraps everything.Create a simplified Makefile
which does the following when executing the command make
:
This file should also be submitted.
Please submit a zip file with your .c
and Makefile
. Make sure your make
commando runs flawlessly and the file names are in order. Submitting files separately will cost you points!
This program makes a book of 10 pages, instances of the page
struct, represented as a linked list. Each object has a random bit of text as it’s text value, stolen from the Lorem Ipsum generator (thank you, Cicero). In this exercise, you have to extend the program such that the book will be split up into two books: one with text on pages that start with a vowel, and another with text that starts with a consonant. The pages have to continue to exist, but have to be relinked. It is of paramount importance not to make copies of objects! (Remember pointers?)
So, output without modifications:
printing the list:
faucibus
quam.
eget,
elit.
dui
ipsum
faucibus
neque
dui,
velit.
end of the list
the list is empty
Output with modifications:
printing the list:
faucibus
quam.
dui
faucibus
neque
dui,
velit.
end of the list
printing the list:
eget,
elit.
ipsum
end of the list
Extend the structure in such a way that not only a pointer to the next page is available, but also to the previous one. Currently, the structure looks like this:
struct page {
char text[100];
struct page* next;
};
A third variable should be added called previous
. Think about which of the above functions you need to modify in order to set the correct values. This is essentially creating a double-linked list instead of a single-linked one.
Change the main()
and printBook()
functions such that they keep track of and print the TAIL of the list instead of the HEAD, using your newly created variable.