in order for mycreatedynamicstorage() to work, main() has to pass it a pointer to pointer to pointers (whew!) -- that's three stars, not two. That allows mycreatedynamicstorage() to change the pointer declared in main().
Code:
const int MaxX = 20;
const int MaxY = 20;
void mycreatedynamicstorage(int ***MyArray)
{
int i;
int ** ay = malloc(MaxY * sizeof(int *));
for(i = 0; i < MaxY; i++)
ay[i] = malloc(MaxX * sizeof(int));
*MyArray = ay;
}
or better yet, pass the x and y values
Code:
void mycreatedynamicstorage(int ***MyArray, int x, int y)
{
int i;
int ** ay = malloc(y * sizeof(int *));
for(int i = 0; i < y; i++)
ay[i] = malloc(x * sizeof(int));
*MyArray = ay;
}