It seems like you're reversing the list a little too well; the NULL
at the end of your list is becoming the new head, which is creating that empty space you were concerned about.
To fix it, I would suggest checking if head->next
is NULL
inside your while loop:
node *rev(node *head){
node *r_head = NULL;
while (head->next) {
node *next = head->next;
head->next = rev_head;
r_head = head;
head = next;
}
r_head = head;
return r_head;
}
This code has not been tested, but I believe it should work.