Question: 1) Add a delete function in equipment.c that deletes an equipment from the list. The function should delete an equipment by its type and description.
1) Add a delete function in equipment.c that deletes 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);
2) Modify the append_to_list function so an equipment is inserted into an ordered list (by type, then by description) and the list remains ordered after the insertion. For example, dumbbell should be before stability ball in the list; stability ball, large should be before stability ball, small in the list.
Here's what I have so far. This is somehow not letting me append anything to the program.. please help!
#include #include #include #include #include "equipment.h" #define NAME_LEN 30 struct equipment *append_to_list(struct equipment *list) { struct equipment *q = (struct equipment *) malloc (sizeof(struct equipment)); printf("Enter type: "); scanf("%s", q -> type); printf("Enter description: "); scanf("%s", q -> description); printf("Enter quantity: "); scanf("%d", &q -> quantity); q -> next = NULL; if(list == NULL) list = q; else { struct equipment *p = list; while (p -> next != NULL) p = p -> next; p -> next = q; } return NULL; } void update(struct equipment *list) { char type[NAME_LEN + 1]; char description[NAME_LEN + 1]; int quantity; printf("Enter type :"); scanf("%s", type); printf("Enter description :"); scanf("%s", description); printf("Enter quantity :"); scanf("%d", &quantity); if (list == NULL) { printf("The list is empty "); } else { struct equipment *p = list; int found = 0; while(p!=NULL) { if (strcmp(p -> type, type) == 0 && strcmp(p -> description, description) == 0) { p -> quantity = quantity; found = 1; break; } p = p->next; } if (found == 0) printf("List not found "); else printf("List updated "); } } void printList(struct equipment *list) { if (list != NULL) { struct equipment *p = list; //while(p!=NULL) { printf("Type: %s ", p -> type); printf("Description: %s ", p -> description); printf("Quantity: %d ", p -> quantity); printf(" "); p = p -> next; } } else printf("The list is empty "); } void clearList(struct equipment *list) { if (list == NULL) { printf("The list is empty "); } else { struct equipment *p = list; while (list != NULL) { p = list; list = list->next; free(p); } } }