Question
Extra Credit Problem - C Programming: Create a C-string linked list data structure for storing character strings using a header file (list.h) and a separate
Extra Credit Problem - C Programming:
Create a C-string linked list data structure for storing character strings using a header file (list.h) and a separate source file (list.c) for all functions.
You need to implement the following functions, as well as define the struct(s) necessary for your list to work correctly.
Do not use arrays. Do not declare arrays. There is no need to use [] anywhere. Do not use C++ including C++ Standard Template Library, Boost, cout or new.
/* Allocates and initializes a new list. */
list* create_list( );
/* Adds item to end of the list. This function allocates a * new buffer and copies the string from item (use malloc, * strlen, and strncpy; or try strdup). * Returns 0 if successful, non-zero otherwise. */
int add_to_list(list* ll, char* item);
/* Removes the string from the front of the list and * returns a pointer to it. The caller is expected to free * the string returned when finished with it. Returns NULL * if the list is empty. */
char* remove_from_list(list* ll);
/* Prints every string in the list, with a new line * character at the end of each string. */
void print_list(list *ll);
/* Flushes (clears) the entire list and re-initializes the * list. The passed pointer ll should still point to a * valid, empty list when this function returns. Any memory * allocated to store items in the list should be freed. * Returns the number of items flushed from the list. */
int flush_list(list* ll);
/* De-allocates all data for the list. Ensure all memory * allocated for this list is freed, including any * allocated strings and the list itself. */
void free_list(list *ll);
Note: After flush_list() the list can still be used, just as if it has just been created. After free_list() it is invalid to still use the list pointer.
Requirements
Develop a solution Put any struct definitions, typedefs, and the above function prototypes in a header file list.h and function bodies (implementations) in a source file list.c. Your source code must use UNIX style EOL characters not DOS style .
You can write code on Windows, but you must convert it to Unix text files.
The dos2unix command may be useful for this.
Make a test file list_test.c that tests your list implementation.
Your test file should try various combinations of your create_list, add_to_list, remove_from_list, flush_list, print_list, and free_list functions.
You should check return values on any function that can possibly fail.
Write a Makefile that compiles list.c and list_test.c to create a binary executable named list_test.
Your program should compile without any warnings or errors when using all standard GCC warnings in -Wall.
Write a plain text README.txt file that explains how to build and run your program, gives a brief description of the pieces.
Document your code. Put a comment block at the top of every file.
Some helpful C functions are:
strlen, strncmp, printf, strncpy, strdup, malloc, free (man these if necessary.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started