The C99 standard allows for run-time assignment of array dimensions, but few compilers are compliant in that respect. Consequently, we fake it. Suppose we want a 2D array of dimensions m x n. We ask malloc to give us memory for m pointers to the element type. We then ask malloc to give us memory for n elements. We store the pointer to that memory in the first array. We then repeat that second request until we have done it m times, storing each of those pointers in the first array.

This gives us m pointers to arrays containing n elements. Job done. Understand that this is not a true 2D array, in that it is not all contiguous, but it gives us a means of addressing any element, given a value for m and a value for n.

Take a shot at implementing that. If you have problems, please post back.