I have a simple assignment that the professor wants us to do. Basically to pull in some numbers from a text file and load into a linked list. I don\'t want to get to much in
This line:
lst = lstTemp;
Only changes the value of lst
inside the function. It won't propagate back to the copy of the pointer that the caller has.
You can either use a pointer-to-a-pointer, or if you can't change the function signature, insert somewhere other than the head of the list.
Though the typical way of handling this is to not point to the first element in the list - rather, you have some sort of list structure that holds a pointer to the first element, and some other information about the list (say, how many elements it has). Then you pass a pointer to that structure around.