The following code does what you want...If you get in any trouble let me know.
Hope i helped.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Functions.
int ***Create3dArray(int D, int R, int C)
{
int i,j;
int ***ptrArray = NULL;
ptrArray = (int ***)calloc(D, sizeof(int **));
if(ptrArray)
{
for(i = 0; i < D && (ptrArray[i] = (int **)calloc(R, sizeof(int*))) != NULL; i++);
if(i == D)
{
for(i = 0; i < D; i++)
for(j = 0; j < R; j++)
ptrArray[i][j] = (int *)calloc(C, sizeof(int));
if(i == D && j == R)
return ptrArray;
else
return NULL;
}
else
return NULL;
}
else
return NULL;
}
void Print3dArray(int ***ptrArray, int D, int R, int C)
{
int i, j , k;
for(i = 0; i < D; i++)
{
for(j = 0; j < R; j++)
{
for(k = 0; k < C; k++)
{
printf("Array[%d][%d][%d] = %d\n", i,j,k, ptrArray[i][j][k]);
}
printf("\n");
}
printf("\n\n");
}
}
void InitArray(int ***Array, int D, int R, int C, int Start)
{
if(Array)
{
int i , j , k;
int CStart = Start;
int r = 1;
for(i = 0; i < D; i++)
{
for(j = 0; j < R; j++)
{
for(k = 0; k < C; k++)
{
Array[i][j][k] = CStart * r;
r += 1;
}
r = 1;
CStart += Start;
}
CStart = ++Start;
r = 1;
}
}
else
printf("Array is NULL.\n");
}
int main(int argc, char *argv[])
{
int ***Array = Create3dArray(3,4,4);
InitArray(Array, 3,4,4,1);
Print3dArray(Array, 3, 4, 4);
printf("Hit any key to continue...\n");
getch();
return 0;
}