Dynamic Allocation of a 3d Array in C

110 Views Asked by At

I am trying to dynamically allocate memory for a 3d character array I am calling

buffer

As it is right now, my code looks like:

char buffer[50][50][20]

Eventually I will need to work with over thousands of spots in this array based on the number of rows and number of columns being read through a CSV file. I save those variables as:

numCol;
numRow;

My program finds these perfectly through a function and returns them back to main() where I want to use them to create my 'buffer'.

How do I allocate space using malloc(), or other means, to create a buffer that takes the form:

 char buffer[numCol][numRow][20]. 

The 20 can stay because that is what I define as the maximum number of characters in a CSV cell.

0

There are 0 best solutions below