You have a few conceptual issues. First you need to know the distinction between the pointer and the memory it points to;
int a1 = 0;
int a2 = 0;
int *b = &a1;
*b = 3;
// now a1 = 3, a2 = 0
b = &a2;
*b = 2;
// now a1 = 3, a2 = 2
That means that in these two lines:
cur = NewList;
cur = malloc(sizeof(numlist));
the second completely replaces the first assignment.
Now this line:
cur = cur->next_num;
Well next_num
hasn't been set yet, so cur is set to garbage memory (malloc doesn't zero the memory so it's not even NULL). What you should do is;
cur->next_num = malloc( sizeof( numlist ) );
cur = cur->next_num;
cur->next_num = NULL; // explicitly NULL-cap, because of issue mentioned above.
Finally, NewList is still NULL at the end. You should use NewList = cur;
after your first malloc line.
In real code, you would put most of this into reusable functions, but for learning those fixes should suffice.
Also the crash after printing the last element which you mention is likely because of the NULLing issue. Your while
loop itself is fine as far as I can see.