Question: #include #include readline.h #include equipment.h int main(void) { char code; struct equipment *e_list = NULL; printf(Operation Code: a for appending to the list, u for

#include
#include "readline.h"
#include "equipment.h"
int main(void)
{
char code;
struct equipment *e_list = NULL;
printf("Operation Code: a for appending to the list, u for updating an equipment, p for printing the list; q for quit. ");
for (;;)
{
printf("Enter operation code: ");
scanf(" %c", &code);
while (getchar() != ' ') /* skips to end of line */;
switch (code)
{
case 'a':
e_list = append_to_list(e_list);
break;
case 'u':
update(e_list);
break;
case 'p':
printList(e_list);
break;
case 'd':
delete_from_list(e_list);
break;
case 'q':
clearList(e_list);
return 0;
default:
printf("Illegal code ");
}
printf(" ");
}
}
#include #include #include "equipment.h" #include #include "readline.h" #define NAME_LEN 30 /***************************************************** * append_to_list: allows user to input equipment type * description and quantity. Then searches list and if * already found does not append to list. * **************************************************/ struct equipment *append_to_list(struct equipment *list) { struct equipment *new_node = (struct equipment *)malloc(sizeof(struct equipment)); printf("Enter equipment type: "); read_line(new_node->type, NAME_LEN); printf("Enter equipment Description: "); read_line(new_node->description, NAME_LEN); printf("Enter Equipment quantity: "); scanf("%d", &new_node->quantity); new_node->next = NULL; if (list == NULL) { list = new_node; } else { struct equipment *temp = list, *prev; while (temp != NULL) { if (strcmp(temp->type, new_node->type) == 0 && strcmp(temp->description, new_node->description) == 0) { printf("Equipment Already Exists "); free(new_node); return list; } prev = temp; temp = temp->next; } prev->next = new_node; } return list; } /*********************************************** * update: Allows user to update an item quantity * that is already on the list **********************************************/ void update(struct equipment *list) { char type[NAME_LEN + 1], descrip[NAME_LEN + 1]; int quantity; printf("Enter Equipment type: "); read_line(type, NAME_LEN); printf("Enter Equipment Description: "); read_line(descrip, NAME_LEN); struct equipment *temp = list; while (temp != NULL) { if (strcmp(temp->type, type) == 0 && strcmp(temp->description, descrip) == 0) { printf("Enter New equipment quantity: "); scanf("%d", &quantity); temp->quantity += quantity; break; } temp = temp->next; } if (temp == NULL) printf("Equipment Does not exist. "); } /************************************************* * printlist: allows user to print all current * items that have been added to list ************************************************/ void printList(struct equipment *list) { struct equipment *p = list; printf(" TYPE DESCRIPTION QUANTITY "); while (p != NULL) { printf("%-20s %-10s %-6d ", p->type, p->description, p->quantity); p = p->next; } } /************************************************* * clearlist: Allows user to clear items in the * list. ************************************************/ void clearList(struct equipment *list) { struct equipment *p = list, *prev = NULL; while (p != NULL) { prev = p; p = p->next; free(prev); } }
1. (70 points) Modify project 10 by adding and modifying the following functions: 1) Add a delete function in equipment. C that delete an equipment from the list. The function should delete an equipment by its type and description. Type and description will be entered by the user. The function should have the following prototype: struct equipment* delete from list (struct equipment *list) You will also need to add the function prototype to the header file; modify the main function in group_equip.c to add d' for delete option in the menu and it calls the delete function when the 'd' option is selected