This line
while(temp->next != NULL)
explicitly says “stop when you get to the element that points to end-of-list” (i.e stop when you get to the last element but before you use it).
Instead use
while(temp != NULL)
which says “stop when you are no-longer in the list”.
4
solved Linked List in C not printing the last value [closed]