I think what you want to do is create the array like this:
int ***array;
array = (int***) malloc( sizeof( int** ) * X_SIZE );
for( int i = 0 ; i < X_SIZE ; i++ )
{
array[i] = (int**) malloc( sizeof( int* ) * Y_SIZE );
for( int j = 0 ; j < Y_SIZE ; j++ )
{
array[i][j] = (int*) malloc( sizeof( int ) * Z_SIZE );
}
}
int ***array;
array = (int***) malloc( sizeof( int** ) * X_SIZE );
for( int i = 0 ; i < X_SIZE ; i++ )
{
array[i] = (int**) malloc( sizeof( int* ) * Y_SIZE );
for( int j = 0 ; j < Y_SIZE ; j++ )
{
array[i][j] = (int*) malloc( sizeof( int ) * Z_SIZE );
}
}
To copy to clipboard, switch view to plain text mode
This should create your 3-D array in whatever sizes you need assuming the array is:
array[X_SIZE][Y_SIZE][Z_SIZE]
array[X_SIZE][Y_SIZE][Z_SIZE]
To copy to clipboard, switch view to plain text mode
Hope this helps!
Bookmarks