Creating arrays is not about inception-ing them into each other. You can't "add a dimention" to an array by malloc-ing it again, that'd just re-assign the new array into what used to be the first array. The solution is initiallizing it as a 3d array, like so:
const int sizeDimOne=4; // size of the first dimention
const int sizeDimTwo=4; // size of the second dimention
const int sizeDimThree=4; // size of the third dimention
int **threedim = malloc(sizeDimOne*sizeDimTwo*sizeDimThree*sizeof(int)); // declaring an array is simple : you just put in the values for each dimention.
Never forget to free it in the end of the code, data-leaks are bad! :)
free(array); // Super important!
would create the array.
If you want to manually assign the values, let me draw an example from a great site: http://www.tutorialspoint.com/cprogramming/c_multi_dimensional_arrays.htm
/*Manually assigning a double-dimentional array for example.
* a very simple solution - just assign the values you need,
* if you know what they are. */
int a[3][4] = {
{0, 1, 2, 3} , /* initializers for row indexed by 0 */
{4, 5, 6, 7} , /* initializers for row indexed by 1 */
{8, 9, 10, 11} /* initializers for row indexed by 2 */
};
EDIT: seeing your code, i see you guys use pointers for declaration. Here's a great example from one of the sources i mentioned earlier, slightly modified, regarding that exact use:
const int nrows = 3; // number of rows.
int **array;
array = malloc(nrows * sizeof(int *)); /* That's because it's an array of pointers in here,
* since you're using the pointer as an array, the amount of datarequired changes.
* dont forget to free!
*/