HW 4
HW 4
1 Introduction
In this homework, you will be implementing an arraylist and debugging code for a “Random Message
Generator.”
Before you begin, we heavily recommend using the Docker to test your code locally. You are responsible
for making sure your code works on the Docker container we gave you, as C may work slightly differently on
different OSes. A guide for installing the docker image is on Canvas.
The files we provided include:
• main.c: main functions that generate the random message
• main.h: header file of the main function
• arraylist.c: functions that are used to manipulate the ArrayList (used by main.c)
• arraylist.h: header file of ArrayList data structure
• arraylist test.h: header file for the tests for the arraylist data structure.
• arraylist test.c: functions for testing the the arraylist data structure
• Makefile: A script that can be used for compiling the code (optional).
You will be modifying arraylist.c and main.c for this homework. Before completing the various parts of
this homework, read all the relevant files, and fill in your name and GTID at the top.
• resize: Resize the backing array to hold twice its original capacity. It should now support
arraylist->capacity ∗ 2 elements.
• destroy: Destroy the ArrayList by freeing the ArrayList itself and its backing array.
Please refer to the comments in arraylist.h for further guidelines. Also note that arraylist.c is almost blank.
In short, you need to implement the functions defined in arraylist.h. Think of arraylist.h as the interface
that your code is expected to comply with. If your code passes the arraylist tests sanity tests and your word
generator gives the expected output, then your code should be good. We reserve the right to review the
code to ensure that your implementation is not hard coded or incorrect (i.e. implemented a link list instead
of an array list).
Lastly, you can use gdb to see the value of a variable without print statements using:
$ (gdb) print <variable name>
If the program runs to completion, the variable will have a value of 0, so you will need to set a breakpoint
at the relevant spot where the value is assigned.
5 Submission
Files you will submit on Gradescope:
• Your GDB snapshots
• arraylist.c
• main.c
Please make sure to remove any extra code you have added while debugging outside of what is
outlined in this PDF (such as print statements) as this may cause issues with the autograder.