I have been desperately scouring the net for information on how to use malloc, and I seriously still don't even understand the concept behind it. I just want to create a 3D array with dimensions [4][11][5], and my assignment requires dynamic mem allocation.
I found this code that I adapted, and I guess that allocates space for my theoretical array. Now I need to define the values for it, and I don't know how to do that without doing the other way of defining values for an array, which would defeat the purpose of malloc.
here's what I have...
Code:
int dim1 = 4, dim2 = 11, dim3 = 5;
int i,j,k;
double *** grades = (double ***)malloc(dim1*sizeof(double**));
for (i = 0; i< dim1; i++) {
grades[i] = (double **) malloc(dim2*sizeof(double *));
for (j = 0; j < dim2; j++) {
grades[i][j] = (double *)malloc(dim3*sizeof(double));
}
}