Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void removeItem(List * list){
- Node * node = list->head;
- Node * prev = NULL;
- Node * temp = NULL;
- char user_inputA[6], *tokenA[6];
- user_inputA[0] = 0;
- printf("Purchase Item\n");
- printf("-------------\nPlease enter the id of the item you wish to remove:");
- while (strlen(user_inputA) <= 1 || strlen(user_inputA) > 82) {
- fgets(user_inputA, sizeof(user_inputA), stdin); /* fgets statement to start the menu*/
- size_t len = strlen(user_inputA);
- if (len > 0 && user_inputA[len-1] == '\n') {
- user_inputA[--len] = '\0';} /* shaves off the /n at the ends of the stdin stream input*/
- }
- tokenA[0] = strtok(user_inputA, "\n");
- while(node != NULL)
- {
- if(strcmp(tokenA[0], node->data->id) == 0){
- if(prev){
- prev->next = node->next;
- printf("Item deleted!\n");}
- else{
- temp->next = node->next;
- list->head->next = temp->next;
- printf("Item deleted!\n");}
- }
- prev = node;
- node = node->next;
- ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement