#include #include #include struct donaNode { char donInvType[30]; float donAmount; struct donaNode *link; }; int main (){ int option; struct donaNode *head; struct donaNode node1; head = NULL; printf(" your options are: ... ... ...\n"); scanf ("%d",&option); while (option != 5) { if (option == 1) { // prompt for word, don_quant scanf ("%s", &(node1.donInvType); scanf ("%d", &(node1.donAmount)); found = search (head, node1); // found in either a pointer to the found word (node), // or it is NULL if (found == NULL) // not found { head = insertatbackinlist (head, node1); } // end-if-found else found->donAmount += node1.donAmount; } // end-if-option-1 else if (option==4) // other options { printlist(head); } //re-Print the menu and scan the new option } // end-while return 0; } // end main // define search function here struct donaNode *search(struct donaNode *l, struct donaNode node1) { struct donaNode *temp; temp=NULL; if (l==NULL) printf("while searching, list began Empty\n"); while (l != NULL) { if (strcmp(l->donInvType,node1.donInvType) == 0) { temp = l; } l = l -> link; } return (temp); struct donaNode *insertatbackinlist(struct donaNode *l, struct donaNode node1) { struct node *temp, *temp2, *temp3; temp= (struct node *) malloc ( sizeof (struct node)); strcpy(temp->donInvType,node1.donInvType); temp->next = NULL; temp2 = l; if (l==NULL) l=temp; else { while (temp2 != NULL){ temp3= temp2; temp2 = temp2->link; } temp3->link = temp; } return (l); } void printlist(struct donaNode *l) { if (l==NULL) printf("Empty\n"); while (l != NULL) { printf("Name=%s \n", l->donInvType); l= l->link; }; }