Deleting a node from linked list in C
- by LuckySlevin
My problem is deleting a node from linked list.
I have two structs :
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;
My problem is in deleting a node from outer_list linked list. For example when user entered aaa to delete, delete function should find the node with outer_list->word = aaa and delete this node and reconnect the list again. I tried the below code to do this. but After finding and deleting I'm losing the list. I don't know what's wrong. Please notice that outer_list have also a linked list of inner_list inside.
void delnode(outer_list *head,char num[100])
{
outer_list *temp, *m;
temp=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;
}
}
printf(" ELEMENT %s NOT FOUND ", num);
}
What are your ideas about this?