N
N Yiannakoulias
Hello all,
I am trying to initialize a pointer inside an evil global structure. The
pointer neighbour_id is of different size for each of the 10 cells
initialized in the function main:
struct cells
{
int id;
int x;
int y;
int number_neighbours;
int *neighbour_id;
};
int main(void)
{
struct cells *the_cells;
the_cells=malloc(sizeof(*the_cells)*10);
/*check for memory availability...*/
/*
For each element of the structure, there are different number of
neighbours (thus neighbour_id, a list of neighbour
identifiers, is a different size for each element of the
structure. How do I initialize this on a 'cell-by'cell' basis?
is it something like:
the_cells.neighbour_id=malloc(sizeof(??))*5) if I want to
allocate space for 5 'values' in the pointer?
*/
free(the_cells);
/*I'll also want to free memory used by the pointers in
the structure? Is that necessary?*/
return 0;
}
Thanks for any guidance,
N
I am trying to initialize a pointer inside an evil global structure. The
pointer neighbour_id is of different size for each of the 10 cells
initialized in the function main:
struct cells
{
int id;
int x;
int y;
int number_neighbours;
int *neighbour_id;
};
int main(void)
{
struct cells *the_cells;
the_cells=malloc(sizeof(*the_cells)*10);
/*check for memory availability...*/
/*
For each element of the structure, there are different number of
neighbours (thus neighbour_id, a list of neighbour
identifiers, is a different size for each element of the
structure. How do I initialize this on a 'cell-by'cell' basis?
is it something like:
the_cells.neighbour_id=malloc(sizeof(??))*5) if I want to
allocate space for 5 'values' in the pointer?
*/
free(the_cells);
/*I'll also want to free memory used by the pointers in
the structure? Is that necessary?*/
return 0;
}
Thanks for any guidance,
N