F
Fabian Wauthier
Hi list,
I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of
pointers to a struct Atom (i.e. the head of a linked list). I am not
sure if this is the right way to do it:
/* Allocate 1st dimension */
if((Screen = (Atom ***) malloc(sizeof(Atom **) * Width)) == NULL)
perrexit("malloc");
/* Allocate 2nd dimension */
for(i = 0; i < Width; i++)
if((Screen = (Atom **) malloc(sizeof(Atom *) * Height)) == NULL)
perrexit("malloc");
/* Set Screen all NULL initially */
for(i = 0; i < Width; i++)
for(j = 0; j < Height; j++)
Screen[j] = NULL; /* Can I do this? */
Can I then access Screen using normal Array subscript notation?
I keep getting strange behaviour in another part of the program, and
I'm not sure if this is the problem.
I hope this wasn't to verbose.
Thanks for any pointers.
Fabian
I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of
pointers to a struct Atom (i.e. the head of a linked list). I am not
sure if this is the right way to do it:
/* Allocate 1st dimension */
if((Screen = (Atom ***) malloc(sizeof(Atom **) * Width)) == NULL)
perrexit("malloc");
/* Allocate 2nd dimension */
for(i = 0; i < Width; i++)
if((Screen = (Atom **) malloc(sizeof(Atom *) * Height)) == NULL)
perrexit("malloc");
/* Set Screen all NULL initially */
for(i = 0; i < Width; i++)
for(j = 0; j < Height; j++)
Screen[j] = NULL; /* Can I do this? */
Can I then access Screen using normal Array subscript notation?
I keep getting strange behaviour in another part of the program, and
I'm not sure if this is the problem.
I hope this wasn't to verbose.
Thanks for any pointers.
Fabian