Mail Archives: djgpp/1997/02/05/12:24:53
On Sun, 2 Feb 1997, Christian Bird wrote:
> struct cell
> {
> int left, up, right, down, used;
> };
>
> cell ** maze;
I assume you meant cell ** make_maze;
> int i;
>
> make_maze = (cell **) malloc(max_width*sizeof(cell *));
> for (i = 0; i < max_width; i++) make_maze[i] = (cell *)
> malloc(max_height*sizeof(cell));
Why not forget pointers-to-pointers and implement a simpler 1D array
with cell *
make_maze = (cell *)malloc(max_width*max_height*sizeof(cell));
Then you can just pass make_maze to a function and use it as a 1D or 2D
array.
Also make sure you free(make_maze) when you don't need it.
-- Nikita.
- Raw text -