Here's a little thing that might cause a problem:
Code:
scanf("%d", &first->value);
Again, this is a value vs. reference issue; scanf expects an address reference, so use the &address of operator.
It's not that the printList while loop isn't executing, it's that createNewNode doesn't work. Also, why do you have a malloc call in printList()? Malloc allocates memory for a node -- that is part of what is missing in createNewNode.
You do not need to create more than one *node in main(), namely "head", and malloc it there. No matter what, for the first entry, use that one. For the subsequent ones, you pass the head to createNewNode, which malloc's a new node and set's the last node's next to that:
Code:
void createNewNode(node *head, int val) {
node *new = malloc(sizeof(node)), *cur=head;
new->value = val;
while (cur->next) cur=cur->next;
cur->next=new;
}
So now your main should look something like this:
Code:
node *first = malloc(sizeof(node));
int numberOfEntries = 0, value;
int i = 0;
printf("Number of Entries: ");
scanf("%d", &numberOfEntries);
printf("\n");
printf("Enter Value: ");
scanf("%d", &first->value);
printf("\n");
while(i < numberOfEntries-1) {
printf("Enter Value: ");
scanf("%d", &value);
printf("\n");
createNewNode(first,value);
i++;
}
Zlatko, becasue of issue #5 above, uses a pointer to a pointer (**) to accomplish the same thing, you may find my method somewhat simpler and easy to understand (or it may be the other way around).
@tabstop: my point was the unorthodox typedef'ing is the first mistake that needs correcting. Neither I nor you nor anyone else will want to correct the OP while maintaining that.