This is the print function, called as a function pointer in traverse
Code:
void print_int(void* node){
lnode *converted_node=(lnode*)node;
int *p=(int *)converted_node->data;
int a=*p;
printf("data %d\n",a);
}
This is my main function, (runs through a bunch of different tests).
Code:
int main(void) {
llist list={NULL};
/* test case 1 - what does an empty list contain? */
printf("TEST CASE 1\n");
traverse(&list, print_int);
printf("\n");
/* test case 2 - what happens when you add a node to the
front of an empty list? */
printf("TEST CASE 2\n");
int *p=malloc(sizeof(int));
*p=10;
add_front(&list, (void*)p);
traverse(&list,print_int);
printf("\n");
/* test case 3 - what happens when you add a node to the front
of a list with one node? */
printf("TEST CASE 3\n");
p=malloc(sizeof(int));
*p=20;
add_front(&list, (void*)p);
traverse(&list, print_int);
printf("\n");
/* test case 4 - what happens when you add a node to the front
of a list with more than one node? */
printf("TEST CASE 4\n");
p=malloc(sizeof(int));
*p=30;
add_front(&list, (void*)p);
traverse(&list, print_int);
printf("\n");
/* test case 5 - what happens when you remove a node from the front
of a list with more than one node? */
printf("TEST CASE 5\n");
remove_front(&list);
traverse(&list, print_int);
printf("\n");
/* test case 6 - what happens when you remove a node from the front
of a list with one node? */
printf("TEST CASE 6\n");
remove_front(&list);
traverse(&list, print_int);
printf("\n");
return 0;
}
Not really sure what the issue is here, thanks for taking a look!
EDIT: Just going to give you everything.
Make New Node:
Code:
lnode* make_node(void* data) {
lnode *tmp;
tmp = malloc(sizeof(lnode));
if(tmp ==NULL)
{
printf("make_node failed at line %d", __LINE__);
exit(99);
}
tmp->data = data;
return tmp;
}
Free List:
Code:
void free_list(llist* list) {
if(!list->head){
lnode *current = list->head;
while(!current) {
lnode *next = current->next;
free(current);
current = next;
}
}
list->head = NULL;
}