I'm trying to hand over the "test_array" to the double pointer "**values" which is a member of the "Matrix" struct.
I want to avoid using "malloc" because I want to use the code for an embedded system application. There are matrices with different sizes and I only want to use one struct. The idea behind this is to point to a static 2d array in order to have no memory conflicts.
#include <stdio.h>
struct Matrix {
int rows;
int columns;
double **values;
};
static double test_array[2][3] = {{1,2,3},{4,5,6}};
int main (void)
{
struct Matrix matrix;
int i,j;
matrix.rows = 2;
matrix.columns = 3;
matrix.values = test_array;
for (i=0; i<matrix.rows; i++) {
for (j=0; j<matrix.columns; j++) {
printf("%f ", *(*(matrix.values + i) + j));
}
printf("\n");
}
}
Pointing to a 1-d array is not a big deal, but how does it work for a 2-d array?