Advertisement
Guest User

Untitled

a guest
May 28th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. void removeItem(List * list){
  2.  
  3. Node * node = list->head;
  4. Node * prev = NULL;
  5. Node * temp = NULL;
  6. char user_inputA[6], *tokenA[6];
  7. user_inputA[0] = 0;
  8.  
  9.  
  10.  
  11. printf("Purchase Item\n");
  12. printf("-------------\nPlease enter the id of the item you wish to remove:");
  13. while (strlen(user_inputA) <= 1 || strlen(user_inputA) > 82) {
  14. fgets(user_inputA, sizeof(user_inputA), stdin); /* fgets statement to start the menu*/
  15. size_t len = strlen(user_inputA);
  16. if (len > 0 && user_inputA[len-1] == '\n') {
  17. user_inputA[--len] = '\0';} /* shaves off the /n at the ends of the stdin stream input*/
  18. }
  19.  
  20. tokenA[0] = strtok(user_inputA, "\n");
  21. while(node != NULL)
  22. {
  23. if(strcmp(tokenA[0], node->data->id) == 0){
  24. if(prev){
  25. prev->next = node->next;
  26. printf("Item deleted!\n");}
  27. else{
  28. temp->next = node->next;
  29. list->head->next = temp->next;
  30. printf("Item deleted!\n");}
  31. }
  32.  
  33.  
  34. prev = node;
  35. node = node->next;
  36.  
  37. ;
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement