Hi I cannot understand why I do not get printed the last node of the list (just the LAST time). The first time I'm just printing the list (and everything works), the second I'm going to sum all the previous numbers of a node to that node (and it works and all nodes are printed) the last time I want to sum just the number before of the one they have (if the list is 1 2 3 it needs to be modified as 1 3 5), in my program everything is working fine but i do not get printed the last node so i would be printed just 1 and 3 not the 5. cannot understand why, can you help?
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node * next;
} node_t;
int main () {
int num, m=0;
printf("How many numbers you want to gimme: ");
scanf("%d", &num);
node_t *head = NULL;
head = (node_t *)malloc(sizeof(node_t));
head->next = NULL;
node_t * current = head;
while (current->next != NULL){
current = current->next;
}
while (num > 0){
num--;
current -> next = (node_t *)malloc(sizeof(node_t));
printf("Inserisci un valore: ");
scanf("%d", ¤t->next->val);
current = current->next;
current->next = NULL;
}
current = head->next;
while (current != NULL){
printf("%d ", current-> val);
current = current->next;
}
printf("\nI'm going to modify the list :D \n");
current = head->next;
while (current->next != NULL){
current->next->val += current->val;
current = current->next;
}
current = head->next;
while (current != NULL){
printf("%d ", current->val);
current = current -> next;
}
printf("\nI'm going to modify the list once again :D \n");
current = head->next;
while (current->next != NULL){
current->next->val += ((current->val)-m);
m = current->val-m;
current = current->next;
}
current = head->next;
while (current->next != NULL){
printf ("%d ", current->val);
current = current->next;
}
printf("\n");
return 0;
}