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 7194379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:21:34+00:00 2026-05-28T20:21:34+00:00

I have written a code to add a new member to a list .

  • 0

I have written a code to add a new member to a list . Its working fine when I take add two members. However, as soon as I add third and compile and run the code gives me an error. The code and error are as follow:

#include<stdio.h>
#include<stdlib.h>

struct list_no {
struct list_no *prev,*nest;
struct linked_list *fnl;
int seq_no;
};
static int counter = 0;

struct list_no *lists,*first;

int add_list()
{
   struct list_no *temp;

    counter++;
    if(lists == '\0')
    {
         lists = (struct list_no *)malloc(sizeof(struct list_no));
         lists->prev = '\0';
         lists->nest = '\0';
         lists->fnl  = '\0';
         lists->seq_no = 1;
         first = lists;
    }
    else
    {
         temp = lists;
         lists->nest = (struct list_no *)malloc(sizeof(struct linked_list));
         lists = lists->nest;
         lists->fnl = '\0';
         lists->prev = temp;
         lists->nest = NULL;
         lists->seq_no = counter;
    }
    return 0;
}

int main()
{
   int i=0,lcount;
   int i=0,lcount;

   char ch = 'y';
   first = '\0';
   lists = first;
   int w;

   while(i != 3)
   {
       add_list();
       printf("\n the val ::%d\n",lists->seq_no);
       i++;
   }

   return 0;
}

the error message coming after ./a.out is :

the val ::1
the val ::2

a.out: malloc.c:3097: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted

Why its not able to add third member?

  • 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-28T20:21:35+00:00Added an answer on May 28, 2026 at 8:21 pm

    You overwrite your pointer

      temp = lists;
      lists->nest = (struct list_no *)malloc(sizeof(struct linked_list));
      lists = lists->nest;
    

    So temp points to the same memory as lists. Then you allocate memory for lists->neste. And after that, you let lists point to that memory, which means, also temp points to it.

    Try

    memcpy((void*)temp, (*void) lists, sizeof(lists));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello there i have written some code in jquery to add new input type
I have written the following code choice /m Do you want to add another
First off we have the almighty code! List nodes = new List(); TreeNode Temp
I have written a code to add user into DB. I need to redirect
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have written some code for playing a .wav through my application. Now I

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.