I need help with pointers in C. I've two structures a struct made like this:
typedef struct s{
s2** d;
struct s* next;
}s;
typedef struct s2{
c* fi;
struct s2* next;
}s2;
And I have a function like this one:
void modify(c* a, s2* b){ //c* is a pointer to a struct
s* rd = malloc(sizeof(s);
rd->next = NULL;
//need also to initialize the field "d" of the "s" struct
}
This is generating error. I need the structure rd to point to b as in the example. I need to store a double pointer because s2 are linked in list-like fashion, so I need the ** pointer to have the possibility to remove the first element of the list. I was doing the assignment in the comment like rd->d = &b but when I try to deference the field "d" in a function I have an invalid memory read and I can't understand why.