Hi i have two basic functions
Code:
llnode* createList(){
char tmp;
llnode *head = NULL;
if ((head =(llnode *) malloc(sizeof(llnode))) == NULL) {
(void)exit();
}
while((tmp = getchar()) != '\n'){
add(&head,(int)(tmp-'0'));
}
return head;
}
that creates a list by reading in user input and then calling add which adds it to the list
add:
Code:
void add(llnode **head, int data_in) {
llnode *tmp;
if ((tmp =(llnode*) malloc(sizeof(llnode))) == NULL) {
(void)exit();
}
tmp->digit = data_in;
tmp->next = *head;
*head = tmp;
}
For some reason when i run this I ask the user to input a number so say they type in "2221" it will add everythingto the list however it adds a zero aswell for some reason. So my lists is
"12220" when i print it out. Any ideas? Thx.