Hi, I'm trying to create a structure that will make it easier to pass general 2D arrays. I've created a struct:
struct matrix{
int rows;
int cols;
int **Data;
};
MATRIX construct_Matrix (int rows, int cols){
int i;
MATRIX A;
int *Data[rows];
int x[cols];
A.rows = rows;
A.cols = cols;
A.Data = Data;
for(i=0; i<rows; i++){
A.Data[0] = x;
}
return A;
}
So basically I am making an pointer in my struct that points to an array of pointers. Each pointer in the array points to an array of data so that the whole thing looks like a matrix.
Am I just setting all the pointers of the array of pointers to one array? If so, how can I make the pointers point to different arrays.
struct matrix{
int rows;
int cols;
int **Data;
};
MATRIX construct_Matrix (int rows, int cols){
int i;
MATRIX A;
int *Data[rows];
int x[cols];
A.rows = rows;
A.cols = cols;
A.Data = Data;
for(i=0; i<rows; i++){
A.Data[0] = x;
}
return A;
}
So basically I am making an pointer in my struct that points to an array of pointers. Each pointer in the array points to an array of data so that the whole thing looks like a matrix.
Am I just setting all the pointers of the array of pointers to one array? If so, how can I make the pointers point to different arrays.