Make a function that allocates a new grid:
Code:
char**newgrid( int cols, int rows )
{
char **g = NULL;
int c = 0;
g = malloc( y * sizeof *g );
for( c = 0; c < cols; c++ )
g[ c ] = malloc( r * sizeof **g );
return g;
}
I did no error checking there, normally you would. Anyway, now that you can make grids that you want of any size, after you've copied the new contents over top of it:
Code:
void foo( char **g, int c, int r )
{
for each column
for each row
if( g[ c ][ r ] == notempty ) break;
if r == max rows
we made it to the end of a column without encountering anything valid
free( g[ c ] )
g[ c ] = NULL
}
Quzah.
}