I am beginning to sound like a stuck record, why are you not taking in what I am saying, you are still stopping the while loop 1 iteration too late, you have not changed your loop end condition.
You have removed first as a parameter, which is good because then you can correctly set the head of the list if there isn't one yet.
Unfortunately you operate directly on first, the first time you execute the code
first - first->next;
you destroy your current list and cause a memory leak (of the first item in the list). In fact your current while loop effective discards all of the current list and replaces with a single new item.
Having removed first as an input parameter you need to heed the advice Laharl gave and copy first to a local variable before operating on it.
I can see in the comments that you have tried using a local variable the and you definitely need to instate (most of) this. But that alone will not make you code work until you fix the logical errors in your while loop end condition.
You have removed first as a parameter, which is good because then you can correctly set the head of the list if there isn't one yet.
Unfortunately you operate directly on first, the first time you execute the code
first - first->next;
you destroy your current list and cause a memory leak (of the first item in the list). In fact your current while loop effective discards all of the current list and replaces with a single new item.
Having removed first as an input parameter you need to heed the advice Laharl gave and copy first to a local variable before operating on it.
I can see in the comments that you have tried using a local variable the and you definitely need to instate (most of) this. But that alone will not make you code work until you fix the logical errors in your while loop end condition.
Comment