I have a rather large program that requires me to use pointers to 2 dimensional arrays. I'm having a difficult time allocating space for the arrays.
I've already tried allocating the space at the time of declaration but I ran into a million road blocks.
I found code here: Create a pointer to two-dimensional array
I have a 2D array of pointers to an array other_arrays
I have this:
static double other_arrays[51][1];
double (*SumH)[51][1] = &other_arrays;
double (*WeightIH)[51][1] = &other_arrays;
double (*Hidden)[51][1] = &other_arrays;
double (*SumO)[51][1] = &other_arrays;
double (*WeightHO)[51][1] = &other_arrays;
double (*Output)[51][1] = &other_arrays;
double (*DeltaWeightIH)[51][1] = &other_arrays;
double (*DeltaWeightHO)[51][1] = &other_arrays;
for (i = 0; i < 2; i++){
for (j = 0; j < 51; j++){
SumH[j][i] = (double *)malloc(sizeof(double));
WeightIH[j][i] = (double *)malloc(sizeof(double));
Hidden[j][i] = (double *)malloc(sizeof(double));
SumO[j][i] = (double *)malloc(sizeof(double));
WeightHO[j][i] = (double *)malloc(sizeof(double));
Output[j][i] = (double *)malloc(sizeof(double));
DeltaWeightIH[j][i] = (double *)malloc(sizeof(double));
DeltaWeightHO[j][i] = (double *)malloc(sizeof(double));
}
}
When I compile I get: error: array type 'double [1]' is not assignable
I've tried some things I've found online such as SumH[j] = (double *)malloc(sizeof(double));
But then I get: error: array type 'double [51][1]' is not assignable
Or something like this yields the same error:
for (j = 0; j < 51; j++){
SumH[j] = (double *)malloc(sizeof(double));
WeightIH[j] = (double *)malloc(sizeof(double));
Hidden[j] = (double *)malloc(sizeof(double));
SumO[j] = (double *)malloc(sizeof(double));
WeightHO[j] = (double *)malloc(sizeof(double));
Output[j] = (double *)malloc(sizeof(double));
DeltaWeightIH[j] = (double *)malloc(sizeof(double));
DeltaWeightHO[j] = (double *)malloc(sizeof(double));
}
SOLUTION
I didn't cast malloc
*SumH[j][i] = *(double *)malloc(sizeof(double));