What is wrong with this append func in C
Posted
by LuckySlevin
on Stack Overflow
See other posts from Stack Overflow
or by LuckySlevin
Published on 2010-05-13T14:17:00Z
Indexed on
2010/05/13
14:34 UTC
Read the original article
Hit count: 168
My Struct Definitions.
typedef struct inner_list {char word[100]; inner_list*next;} inner_list;
typedef struct outer_list
{ char word [100];
inner_list * head;
outer_list * next; } outer_list;
And The problem part:
void append(outer_list **q,char num[100],inner_list *p)
{ outer_list *temp,*r;
temp = *q;
char *str;
if(*q==NULL)
{ temp = (outer_list *)malloc(sizeof(outer_list));
strcpy(temp->word,num);
temp->head = p;
temp->next=NULL;
*q=temp;
}
else
{ temp = *q;
while(temp->next !=NULL)
{ temp=temp->next;
}
r = (outer_list *)malloc(sizeof(outer_list));
strcpy(r->word,num);
temp->head = p;
r->next=NULL;
temp->next=r;
}
}
I don't know what is i'm doing wrong in this append function i'm sending a char array and a linked list to be stored another linked list. But i can't store the linked list in another linked list. I couldn't figure out the problem. Any ideas?
© Stack Overflow or respective owner