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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:19:36+00:00 2026-06-08T19:19:36+00:00

I’m having some trouble copying a single linklist over to a double-linklist. Not sure

  • 0

I’m having some trouble copying a single linklist over to a double-linklist. Not sure what is going on but I’m having a gdb debugging error:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000100000d86 in doublify (list=0x1001008c0) at lists.c:62
62     newDlist->item = curr->item;

The one-directional link list is working,

My .h Header File:

typedef struct _node {
   Item item;
   link next;
} node;

typedef struct _dnode *dlink;

typedef struct _dnode {
   Item item;
   dlink prev;
   dlink next;
} dnode;

My Code:

link newLink (Item item){
   link createLink = malloc(sizeof(node));
   createLink->item = item;

   return createLink;
}

link fromTo (int start, int end) {
   link newList = NULL;

   if(start <= end ){
       newList = newLink(start);
       newList->next = fromTo(start+1, end);
   }

   return newList;
}

//Heres where it isn't able to copy the linklist item over into the new dlist.
dlink doublify (link list) {
   dlink newDlist = malloc (sizeof (dnode));
   link curr = list;

   while(curr != NULL){
       newDlist->item = curr->item;
       curr = curr->next;
       newDlist = newDlist->next;
   }
   return newDlist;
}
  • 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-06-08T19:19:37+00:00Added an answer on June 8, 2026 at 7:19 pm

    The problem happens on the second iteration of the while loop. When you assign newDlist to the ‘next’ item, the ‘next’ field might contain any value. The thing is that malloc simply gives you a pointer to a data region where any values might be (it doesn’t clean it or init in some way).

    You simply need to allocate a new node on each iteration and setup the pointers appropriately. Here is one of the ways how that can be done.

    dlink prevNode = NULL;
    
    // Insert the first item (if present) to simplify the loop
    if ( curr != NULL )
    {
       dlink newDlist = malloc(sizeof(dnode));
    
       newDlist->item = curr->item;
       newDlist->next = NULL;
       newDlist->prev = NULL;
       prevNode = newDlist;
    
       curr = curr->next;
    }
    
    while ( curr != NULL )
    {
       dlink newDlist = malloc(sizeof(dnode));
    
       newDlist->item = curr->item;
    
       prevNode->next = newDlist;
       newDlist->prev = prevNode;
       newDlist->next = NULL;
    
       prevNode = newDlist;
       curr = curr->next;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but

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.