I'm having issues with returning a multidimensional array. I create the array in a function and then modify it in another function. In the main function I want to print out the contents of the array as indicated below but, I am not getting anything to show up in the console.
Any suggestions? Thanks.
//Build the grid array given the number of rows, columns and levels
char ***buildGrid(int numRows, int numCols, int numLevels)
{
char ***levels;
levels = malloc(numLevels *sizeof(char *)); //Contains all levels
int rowIndex, levelIndex;
for (levelIndex = 0; levelIndex < numLevels; levelIndex++)
{
char **level = malloc(numRows * sizeof(char *)); //Contains all rows
for(rowIndex = 0; rowIndex < numRows; rowIndex++)
{
level[rowIndex] = malloc(numCols * sizeof(char)); //Contains all columns
}
levels[levelIndex] = level;
}
return levels;
}
void readGrid(char ***grid)
{
grid = buildGrid(3,3,3);
grid[0][0][0] = 'a';
}
int main (int argc, const char * argv[])
{
char ***gridData;
readGrid(gridData);
printf("%c", gridData[0][0][0]); //This does not output anything
return 0;
}
***or****you are probably not looking in the right direction!