Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 800905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:21:41+00:00 2026-05-14T23:21:41+00:00

Actually this was another problem but it changed so I decided to open a

  • 0

Actually this was another problem but it changed so I decided to open a new question.

My code is

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])//thanks to both Nir Levy and Jeremy P.
{
    outer_list *temp, *m;
    m=temp=*head; /*FIX #1*/
    while(temp!=NULL) {
        if(strcmp(temp->word,num)==0) {
            if(temp==*head) {
                delinner(temp->head); /* FIX#2 */
    *head=temp->next;

                free(temp);
                return;
            } else {
                delinner(temp->head); /* FIX#2 */ 
    m->next=temp->next;

                free(temp);
                return;
            }
        } else {
            m=temp;
            temp= temp->next;
        }
    }
    printf(" ELEMENT %s NOT FOUND ", num);
}
void delinner(inner_list *head) { /* FIX#2 */
    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;
 }
}

While deleting an element from outer list I am also trying the delete the same element from inner_list too.

For example: – Let’s say aaa is an element of outer_list linked list and let’s point it with outer_list *p – This aaa can also be in an inner_list linked list too. (it can be in p->head or another innerlist.) Now, the tricky part again. I tried to apply the same rules with outer_list deletion but whenever i delete the head element of inner_list it gives an error. Where is the wrong thing in print_node or delnode2?

Edit:
actually if it a outer_list node deleted the linked list of inner_list inside of it should be removed too. This is why delinner method used.

For example:

outer     inner
aaa       bb->cc
bb        aaa->cc

when i wanted to delete "aaa" The result should be:
outer     inner
bb         cc 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:21:42+00:00Added an answer on May 14, 2026 at 11:21 pm

    What is the inner_list **head parameter of delnode() ? I assume that up is the outer list node, from whose inner list you want to remove the node containing the string given in num. head just doesn’t fit into this picture. And you don’t seem to be using it properly anyway. I rewrote the function a bit, omitting the parameter, changing the commented lines, and giving more meaningful names:

    void del_inner_node(outer_list *up, char num[100])
    {
      inner_list *temp, *m;
      outer_list *p;
      p = up;
    
      while (p != NULL) {
        m = temp = p->head;
        while(temp!=NULL) {
          if(strcmp(temp->word,num)==0) {
            if(temp==p->head) {   // refer to p->head
              p->head=temp->next; // refer to p->head
              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);
    }
    

    Note that temp2 is not used, so I removed it.

    Now, in your code there is no call to delnode2 (del_inner_node). You could actually call it within delnode, in case the searched string was not found in the current outer node:

    void del_all_nodes(outer_list **head,char num[100])//thanks to both Nir Levy and Jeremy P.
    {
        ...
        while(temp!=NULL) {
            if(strcmp(temp->word,num)==0) {
                ...
            } else {
                del_inner_node(temp,num);
                m=temp;
                temp= temp->next;
            }
        }
        ...
    }
    

    This way you can remove all nodes containing “aaa” with a single call:

    outer_list *head;
    // set up the lists
    del_all_nodes(&head, "aaa");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try with the following mark-up instead of directly specifying height:… May 15, 2026 at 12:36 am
  • Editorial Team
    Editorial Team added an answer CASE WHEN ISNULL(SUM(MyTable.Total), 0) <= 0 THEN 0 ELSE SUM(MyTable.Total)… May 15, 2026 at 12:36 am
  • Editorial Team
    Editorial Team added an answer I believe the linked question perfectly answers your question. Nothing… May 15, 2026 at 12:36 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.