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

  • Home
  • SEARCH
  • 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 8913367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:26:36+00:00 2026-06-15T04:26:36+00:00

I am storing my information in an array of pointers to structs. In other

  • 0

I am storing my information in an array of pointers to structs. In other words, each element of the array is a pointer to a linked list.

I don’t know how long the array should be, so instead of initializing the array in my main() function, I instead intialize the double pointer

struct graph** graph_array;

Then once I obtain the length of the array, I try to initialize each element of graph_array using a function GraphInitialize:

int GraphInitialize(struct graph* *graph_array,int vertices)
{ 
  struct graph* graph_array2[vertices+1];
  graph_array = graph_array2;
  int i;

  for (i=0;i<vertices+1;i++)
  {
    graph_array[i] = NULL;
  }

  return 0;
}

But for some reason this is not returning the updated graph_array to main(). Basically, this function is updating graph_array locally, and no change is being made. As a result, any time I try to access an element of graph_array it seg faults because it is not initialized. What am I doing wrong?

Edit: Following the convo with Tom Ahh I should add something else that makes this more confusing.

I don’t call GraphIntialize directly from main(). Instead, I call getdata() from main, and pass a pointer to graph_array to getdata as shown below.

    getdata(argc, argv, vertpt, edgept, &graph_array)

    int getdata(int argc, char *argv[], int *verts, int *edges, struct graph* **graph_array)

Then getdata gets the number of vertices from my input file, and uses that to call GraphInitialize:

    if ((GraphInitialize(&graph_array, *verts)) == -1)
    {
      printf("GraphCreate failed");
      return 0;
    }

This results in an error: “expected ‘struct graph 3ASTERISKS’ but argument is of type ‘struct graph 4ASTERISKS’.

  • 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-15T04:26:37+00:00Added an answer on June 15, 2026 at 4:26 am

    When you assign something to graph_array, you simply assign it to its local copy. The changes made to it in the function will not be see-able by the caller. You need to pass it by pointer value to be able to change its value. Change your function prototype to int GraphInitialize(struct graph ***graph_array,int vertices) and when you call it, use GraphInitialize(&graph_array, 42).

    Second problem in your code is when you create graph_array2, you declare it to be local to your GraphInitialize() function. Thus, when exiting your function, graph_array2 is destroyed, even if you assigned it to *graph_array. (the star dereferences the pointer to assign it to the value it points to).

    change your assignation to *graph_array = malloc(sizeof(*graph_array) * vertices); and you should be fine.

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

Sidebar

Related Questions

I am storing my information in an array of pointers to structs. In other
I want to have a List or Array of some sort, storing this information
hi all i am getting three types of array list information storing in one
I am running an image analysis code on an array storing information about the
I'm dynamically storing information in the database depending on the request: // table, id
I'm building a WebApp in jsf 2.0 and it's about storing information and displaying
I have 2 tables - one storing user information (id, username, password) and the
Whats the recommended way for storing authentication information in iOS that could be easily
Storing credit card information securely and legally is very difficult and should not be
I am retrieving information from my database and storing it in a reader. The

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.