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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:28:36+00:00 2026-05-29T22:28:36+00:00

I have to save in an array the address of some data. Every data

  • 0

I have to save in an array the address of some data. Every data is a structure of type “dagNode”. To do my work I visit a list, and I count the number of data that I want to record its address so I allocate the right space in the memory, and finally I re-visit the list and save the address of some data.

    struct dagNode *buildBST(struct dagNode *rootList){
    struct dagNode *head, **xTest;
    head = rootList;
    int numXtest=0;

    rootList = nextNode(TYPE_XTEST, rootList);

    while ( !IS_TERMINATED( rootList ) ){   // first visit
        numXtest++;
        rootList = nextNode(TYPE_XTEST, rootList); }

    xTest = (struct dagNode **) malloc( sizeof(struct dagNode ) * numXtest);
    int i=0; rootList = nextNode(TYPE_XTEST, head);

    for(i=0; i<numXtest; i++){      // second visit, saving the address of some datas
        rootList = nextNode(TYPE_XTEST, rootList);
        xTest[i] = rootList; i++;
    >>> printf("t=%d,val=%d\t", xTest[i]->nodeType, xTest[i]->val); } // segmentation fault

    return head;
    }

EDIT:

    struct dagNode *nextNode(int typeOfNextNode, struct dagNode *node){
        if (IS_TERMINATED(node)){   return node;    }
        node = node->next;
        if (typeOfNextNode == TYPE_EDGE_OR_GAP){
            while (!IS_TERMINATED(node) && !IS_AN_EDGE(node) && !IS_A_GAP(node)){
                node = node->next;  }
               }else
        {
            while (!IS_TERMINATED(node) && (node->nodeType != typeOfNextNode)){
                node = node->next;}
        }
        return node;    }
  • 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-29T22:28:37+00:00Added an answer on May 29, 2026 at 10:28 pm

    There is a mismatch between the type of the xTest pointer and the size you allocate in malloc. If xTest is of type struct dagNode **, the proper allocation should be:

    xTest = malloc(sizeof(struct dagNode *) * numXtest);
    

    Probably you want to allocate numXtest pointers to a struct, not numXtest structs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to save an image file in various formats. The list
I have Dim a(15) as integer i wont to save this array in Viewstate
I have built an array, such as A = [a1,a2,...aN]. How to save this
I hav to save the values of NSUserDefault to the Array,and later on have
i have been trying to use some ajax to save venue location in my
I have a module where I try to create some users. $newUser = array(
Scenario : I have a member variable, an array-list,(which is not static, private member)
I have an embedded (updatable) tree structure in an array - considering the upcoming
I have two-dimensional array of integers. First index indicates the number of channels. The
When I save the information from a registration form I have some validation rules

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.