I'm trying to write a program that will create and work with matrices, but im having problems with a pointer to a 2d array.

I created this structure in a header file:

the header file also has the function prototypes.Code:typedef struct { int rowdim, coldim; double* element; } matrix;

Here is the file where i define the functions:

however, there is a compile error for:Code:#include "matrix.h" matrix create_empty(int rdim, int cdim) { matrix* new_matrix; new_matrix = malloc(sizeof(matrix)); new_matrix -> rowdim = rdim; new_matrix -> coldim = cdim; new_matrix -> element = malloc((rdim*cdim) * sizeof(double)); return *new_matrix; } matrix create_initval(int rdim, int cdim, double* values) { int i, j; matrix* new_matrix; new_matrix = malloc(sizeof(matrix)); new_matrix -> rowdim = rdim; new_matrix -> coldim = cdim; new_matrix -> element = malloc((rdim*cdim) * sizeof(double)); for (i=0; i<cdim; i++) { for(j=0; j<rdim; j++) new_matrix -> element[i][j] = values[i][j]; { return *new_matrix; } void destroy(matrix a) { free(&a.element); } void matrix_print(matrix a) { int i, j; printf("\n"); for (i=0; i<a.coldim; i++) { for(j=0; i<a.rowdim; j++) { printf(" %f ", a.element[i][j]); } } } }

that reads: subscripted value is neither array nor pointerCode:new_matrix -> element[i][j] = values[i][j];

Im not sure why, because i know the program works when creating a one dimensional vector, but when its 2d, i have the problem