Hi,
I have a unique case where I need an array of structs that grows and
within this array is another struct that grows in some cases. I'm
having trouble allocating memory. Since I have never done this before,
I'm sure it's a rookie mistake but I cannot seem to find it. Can
someone render some assistance please?
struct Fpos {
grib_handle *h;
char level[MAX_VAL_LEN];
};
struct Parameter {
double *lvlpress;
double *geomethgt;
double *ab_array;
double *pottemp;
int nlev;
size_t size;
char parameter[MAX_VAL_LEN];
unsigned char **GribNameValue s;
struct Fpos **filepos;
} **Darray;
Darray = (struct Parameter **)realloc(Darr ay,(num + 1)*sizeof(struc t
Parameter *));
/* allocate memory for one struct Parameter */
Darray[num] = (struct Parameter *)smalloc(sizeo f(struct Parameter));
/* same as above but for the nested struct */
Darrray[num]->filepos = (struct Fpos **)realloc(file pos,(lvlnum +
1)*sizeof(struc t Fpos *));
Darrray[num]->filepos[lvlnum] = (struct Fpos *)smalloc(sizeo f(struct
Fpos));
When I compile, I get an error saying that filepos is not declared and
is new.
How should this be done properly?
/M
I have a unique case where I need an array of structs that grows and
within this array is another struct that grows in some cases. I'm
having trouble allocating memory. Since I have never done this before,
I'm sure it's a rookie mistake but I cannot seem to find it. Can
someone render some assistance please?
struct Fpos {
grib_handle *h;
char level[MAX_VAL_LEN];
};
struct Parameter {
double *lvlpress;
double *geomethgt;
double *ab_array;
double *pottemp;
int nlev;
size_t size;
char parameter[MAX_VAL_LEN];
unsigned char **GribNameValue s;
struct Fpos **filepos;
} **Darray;
Darray = (struct Parameter **)realloc(Darr ay,(num + 1)*sizeof(struc t
Parameter *));
/* allocate memory for one struct Parameter */
Darray[num] = (struct Parameter *)smalloc(sizeo f(struct Parameter));
/* same as above but for the nested struct */
Darrray[num]->filepos = (struct Fpos **)realloc(file pos,(lvlnum +
1)*sizeof(struc t Fpos *));
Darrray[num]->filepos[lvlnum] = (struct Fpos *)smalloc(sizeo f(struct
Fpos));
When I compile, I get an error saying that filepos is not declared and
is new.
How should this be done properly?
/M
Comment