Dear all,
I have to use a funny structure in my code which has a 2D array and allocate it later in the program. I do it but I get error which is written below. I have urgently to finish this part of the code. Would be agreat help if you can help me. This is the code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define NUMBER_DECISION_VARIABLES (int)4
#define DIM (int)50
struct Results{
double *DV[NUMBER_DECISION_VARIABLES];
};
int main(){
int i, j;
struct Results results[DIM][DIM];
/* now I want to use malloc to get space for DV*/
for(i = 0; i < DIM; i++){
for(j = 0; j < DIM; j++){
/* it should be something like this */
results[i][j].DV = (double(*)[DIM])
malloc(DIM * sizeof(results[i][j].(*DV) ));
}
}
return 0;
}
But I get the following error during compilation:
te.c:32: error: expected identifier before ‘(’ token
te.c:32: error: incompatible types when assigning to type ‘double *[4]’ from type ‘double (*)[50]’
Could you tell me please how can I use malloc here?
Thanks in advance for your help.