void fill_list(t_dlist *list, char **av) { int y; y = 1; while (av[y]) { add_list_end(list, av[y]); y++; } }
int main() { int sel, code; float grd; student stud, *ptr; head = NULL; while(1) { printf("\nMenu selections\n"); printf("---------------\n"); printf("1. Add student at the end\n"); printf("2. Add student\n"); printf("3. View all students\n"); printf("4. View student\n"); printf("5. Modify student\n"); printf("6. Delete student\n"); printf("7. Exit\n"); printf("\nEnter choice: "); scanf("%d", &sel); switch(sel) { case 1: case 2: /* To avoid the repetition of the same code we use the same case. Then, the if statement checks the user’s choice and calls the respective function. */ getchar(); printf("Name: "); gets(stud.name); printf("Code: "); scanf("%d", &stud.code); printf("Grade: "); scanf("%f", &stud.grd); if(sel == 1) add_list_end(&stud); else { printf("\nEnter student code after which the new student will be added: "); scanf("%d", &code); add_list(&stud, code); } break; case 3: if(head == NULL) printf("\nThe list is empty\n"); else show_list(); break; case 4: if(head == NULL) printf("\nThe list is empty\n"); else { printf("\nEnter student code to search: "); scanf("%d", &code); ptr = find_node(code); if(ptr == NULL) printf("\nStudent with code = %d does not exist\n", code); else printf("\nData:%s %.2f\n\n", ptr->name, ptr->grd); } break; case 5: if(head == NULL) printf("\nThe list is empty\n"); else { printf("\nEnter student code to modify: "); scanf("%d", &code); printf("Enter new grade: "); scanf("%f", &grd); ptr = find_node(code); if(ptr != NULL) ptr->grd = grd; else printf("\nStudent with code = %d does not exist\n", code); } break; case 6: if(head == NULL) printf("\nThe list is empty\n"); else { printf("\nEnter student code to delete: "); scanf("%d", &code); del_node(code); } break; case 7: if(head != NULL) free_list(); return 0; default: printf("\nWrong choice\n"); break; } } return 0; }