I am having trouble trying to dereference a double pointer to an array of structs.
The struct is defined:
struct node_list_t {
struct node_t **node_ptr;
};
I have done the following to allocate memory and initialize values:
struct node_t *nodeArray;
struct node_list_t *mainList = (struct node_list_t*)malloc(sizeof(struct node_list_t));
nodeArray =(struct node_t*)malloc(10 * sizeof(struct node_t));
for (i=0;i<size;i++) {
nodeArray[i].mass = i;
}
mainList->node_ptr = &nodeArray;
Since we are being required to use a double pointer I am trying the following unsuccessfully to dereference as such:
printf("%f\n",mainList->node_ptr[i]->mass);
We are forced to keep node_ptr as a double pointer, so I cannot change that. How would I dereference this? Thanks.