Question: PROBLEM STATEMENT: Write a C program to implement a doubly linked list of dynamically allocated nodes, utilizing structures, unions and enums. You will build the

PROBLEM STATEMENT:
Write a C program to implement a doubly linked list of dynamically allocated nodes, utilizing structures, unions and enums. You will build the linked list, traverse the linked list to display the node entries in forward and reverse directions.
Set-up will include creating the data structures and initial file structure, including makefile(s).
In Part 1 of your program, you will create the initial code base with minimal "Hello World" functionality.
In Part 2, you will add the creation of the data structures (node and linked list)
Finally, in Part \(\mathbf{3}\) you will add the ability to read data from a provided file (input.dat), load the linked list and then print out the nodes of the list with a provided printNode() function.
LAB SET-UP
Try to take it one step at a time, it's easier to start with a small amount of code, get that building with minimal functionality and then expand functionality step by step.
Create a "lab8" project directory under your /csc60 directory. Under your lab8 directory, make subdirectories named "data", "src" and "include" subdirectory. The data directory will hold the input data file.
Use the following provided content for 3 files:
1) makefile - The top-level makefile, put this in your lab8(project) directory.
Here are the contents of the top-level makefile to place in your \(\sim /\csc 60/\) lab8 directory:
```
# Example solution: Lab8
# Csc60 Eall '24
all:
mkdir -p lib
cd src; make
clean:
cd src; make clean
```
With that, you will be able to run make from the project directory, or when in the src directory. This is just to demonstrate make calling make.
Note: the "-p" argument to mkdir will cause mkdir not to fail when lib already exists. We just want to be able to create the non-existent lib directory the first time we run make
2) The printNode() function: Copy and paste this code snippet to your utils.c file:
```
void printNode (node_t *pNode){
printf("%4d\t%02d/%02d/s02d\t%s\t
",
pNode->id,
pNode->dueDate.month, pNode->dueDate.day, pNode->dueDate.year,
statusNames [pNode->status]
);
}
```3) Input.dat - The input data for creating nodes, put this in your data directory.
```
lllll
2
4
```
Er each Part of this lab:
- Build your project
Run make. Note, you will likely have to incrementally get it all working, i.e. run it, observe errors, fix those then try again. That's normal, but easier with make (-) Then, move on to the next part.
Also, In all .c files, display error message to stderr (standard error) rather then stdout. - Hint: use fprintf(stderr,"msg",...) or perror("msg") to print the message and the current value of errno.
- Run lab8
Run the lab88executable to observe the behavior and iterate through any bug fixes/changes.
Part 1: Base code
- Basic structure for the base program: makefile, src/makefile, lab8.c, include/lab8.h
- Lab8.c should simply display the Title line: "CSc60 Lab8: Structs, Unions and Enums"
- The text of the Title should be set as a \#define in lab8.h (to be used in lab8.c)
- Build out the structure below for an initial, simple "Hello world" program:
Note: lab8/lib directory will be created by the top-level make
Lab8/data/input.dat \(\leftarrow \) the input data file, see above for content
lab8/include/lab8.h \(\leftarrow \) includes \#defines, typedefs, externs, ...
lab8/makefile \(\leftarrow \) contents provided above
lab8/src/makefile \(\leftarrow \) everything to build the lab8 executable
lab8/src/lab8.c \(\leftarrow \) holds the main() function
lab8/src/utils.c \(\leftarrow \) holds utility functions
After running a build, you will also have:
lab8/lab8\(\quad \leftarrow \) to be built by make, the executable
lab8/lib/lab8.a \(\quad \leftarrow \) to be built by make, holds all .o's except lab8.o (just utils.o)
lab8/src/lab8.o \(\quad \leftarrow \) the compiled object file for lab8.c
lab8/src/utils.o \(\leftarrow \) the compiled object file for utils.c
Part 1 Test:
- Run the lab8 executable to observe its behavior Part 2: Create the data structures
- In lab8.h - You will create the node and date structs and a typedef them to node_t and date_t
- The three node_t data fields: unsigned int id, status_t status, date_t date
- Also include prev and next pointers in the node_t to support a doubly linked listCreate status_t as an enum with 4 constants: open, inprog, complete, blocked. Create a typedef for this enum of prioritiesCreate date_t as a struct (same as in our Wk-9 lecture deck)Create a global variable char * statusNames[] separately to provide the appropriate Names to coincide with the priority enum -\{"Open","In Progress", "Done", "Blocked"\}Create global variables "head" and "tail" pointers for the doubly linked list of nodes
Hint: put typedefs, structs and enums in lab8.h. Define the global variables in
lab8.c at file scope. Remember to include externs for these variables in lab8.h
- Create a utils function "loadList()" which will (for Part 2):
- Create a single node using dynamic memory allocation
- Fill the new node with some made-up data
- Set the global head and tail pointers of the linked list
- Add the function "printNode()" provided above to your utils.c.
- Adjust pri - Example Output for final lab8- e
PROBLEM STATEMENT: Write a C program to implement

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!