Actually it was a different problem, but it changed, so I decided to open a new question.
My code
typedef struct inner_list
{
int count;
char word[100];
inner_list*next;
} inner_list;
typedef struct outer_list
{
char word [100];
inner_list * head;
int count;
outer_list * next;
} outer_list;
void delnode(outer_list **head,char num[100])
{
outer_list *temp, *m;
m=temp=*head;
while(temp!=NULL) {
if(strcmp(temp->word,num)==0) {
if(temp==*head) {
delinner(temp->head);
*head=temp->next;
free(temp);
return;
} else {
delinner(temp->head);
m->next=temp->next;
free(temp);
return;
}
} else {
m=temp;
temp= temp->next;
}
}
printf(" ELEMENT %s NOT FOUND ", num);
}
void delinner(inner_list *head) {
inner_list *temp;
temp=head;
while(temp!=NULL) {
head=temp->next;
free(temp);
temp=head;
}
}
void delnode2(outer_list *up,inner_list **head,char num[100])
{
inner_list *temp2,*temp, *m;
outer_list *p;
p = up;
while(p!=NULL){m=temp=temp2=p->head;
while(temp!=NULL) {
if(strcmp(temp->word,num)==0) {
if(temp==(*head)) {
*head=temp->next;
free(temp);
return;
} else {
m->next=temp->next;
free(temp);
return;
}
} else {
m=temp;
temp= temp->next;
}
}
p=p->next;
}
printf(" ELEMENT %s NOT FOUND ", num);
}
void print_node(outer_list *parent_node)
{
while(parent_node!=NULL){
printf("%s\t%d\t", parent_node->word, parent_node->count);
inner_list *child_node = parent_node->head;
printf("list: ");
if(child_node ==NULL){printf("BUARADA");}
while (child_node != NULL) {
printf("%s-%d", child_node->word,child_node->count);
child_node = child_node->next;
if (child_node != NULL) {
printf("->");
}
}
printf("\n");
parent_node = parent_node->next;
}
}
When removing an item from an external list, I also try to remove the same item from inner_list too.
For example: - Let say aaa is an element of the linked list external_list and indicate it with external_list * p - This aaa can also be associated with the list associated with the internal list. (it may be in p-> head or another internal list.) Now the tricky part is again. I tried to apply the same rules with removing the outer_name, but whenever I delete the head_list element, it gives an error. Where is the error in print_node or delnode2?
:
, _list node, . delinner.
:
outer inner
aaa bb->cc
bb aaa->cc
when i wanted to delete "aaa" The result should be:
outer inner
bb cc