Hi i have two basic functions
that creates a list by reading in user input and then calling add which adds it to the listCode: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; }
add:
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 isCode: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; }
"12220" when i print it out. Any ideas? Thx.



LinkBack URL
About LinkBacks


