I'm trying to print out the contents of a linked list.To do that, I have created pointers of the lists in the main function here:
and passed them into the add function here:
when I try to print it in the main
it prints "head:" Where is my data getting lost? I haven't quite "grasped" pointers yet, so I'm sure this is a silly question. Thanks for your help!
Code:
int main(void){
List *l1, *l2;
l1 = (List *)malloc(sizeof(node));
l2 = (List *)malloc(sizeof(node));
l1->head = (node *)malloc(sizeof(node));
l2->head = (node *)malloc(sizeof(node));
l1->head->str = (char *)malloc(80 * sizeof(char));
l2->head->str = (char *)malloc(80 * sizeof(char));
//stuff...
return 0;
}
and passed them into the add function here:
Code:
void addEnd(List *strList, char *string){
node *current = strList->head;
while(1){
if(current == NULL) break;
else current = current->next;
}
current = (node *)malloc(sizeof(node));
current->str = (char *)malloc(80 * sizeof(char));
current->str = string;
}
when I try to print it in the main
Code:
printf("head: %s", l1->head->str);