What i am trying to do is edit the strings of a node in a linked list.Code:shift(buffer,4); tmp_buffer1 = malloc(strlen(buffer) * sizeof(char)); get_first_num(buffer,tmp_buffer1); check = strlen(tmp_buffer1)+1; shift(buffer,check); check=0; item_num=0; tmp_item_list=item_list; while(tmp_item_list) { if (strcmp(tmp_item_list->number,tmp_buffer1)==0 && atoi(buffer)>atoi(tmp_item_list->current_price)) { tmp_buffer2 = malloc(strlen(buffer) * sizeof(char)); strcpy(tmp_buffer2, tmp_item_list->name); tmp_buffer3 = malloc(strlen(buffer) * sizeof(char)); strcpy(tmp_buffer3, tmp_item_list->number); tmp_buffer4 = malloc(strlen(buffer) * sizeof(char)); strcpy(tmp_buffer4, buffer); item_list = add_item(tmp_buffer2, tmp_buffer3, tmp_buffer4, "DUDE", item_list); remove_item(item_list, item_num+1, 0); send_message(i, "OK"); check=1; break; } tmp_item_list=tmp_item_list->next; item_num++; } if (check==0) send_message(i, "NO");
The way i am doing it is, first finding the node in a copied version of the linked list (which i don't think i did right), then making a new node and coping the details to the new node, and adding my own string, then add the new node to the front of the list, then delete the found node from the list. Right now this isn't working as the list isn't circular, just linear (supposed to be linear and stops) which stops somewhere. After doing this, the list ends up repeated like 2 times... which is bad... what is wrong here?