I have two structures parent and child as you can see in my code below. The parent structure has an array of pointers of type child. I get a segmetation error when the the program enters the for loop. Is there any thing wrong in my code? The reason why I don't want to use square brackets is that I have a function that takes a pointer parameter of type child and I want to pass every child pointer to that function without the need to use &.
Any help would be appreciated Thank you
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
int id;
} child;
typedef struct {
child** c;
} parent;
int main(int argc, char **argv) {
int number_of_children = 5;
parent* p = (parent*)malloc(sizeof(parent));
p -> c = (child **) malloc(number_of_children * sizeof(child*));
int i;
for(i=0; i<number_of_children; i++)
p -> c[i] -> id = i;
}
child*s point to.