I have a very basic question regarding arrays in C. i have this struct:
struct Matrix{
int rows;
int cols;
int** matrix;
};
and when i tried to use this struct and to declare a Matrix, i have come across this problem
Matrix matrix;
matrix->matrix = (int**) malloc(3*sizeof(int*));//allocates pointer to a pointers array
for (int i = 0; i <3; i++){
matrix->matrix[i] = (int*) malloc(3*sizeof(int));
}//allocating a 3X3 array
matrix->matrix={1,2,3,4,5,6,7,8,9};
however that last line won't work, apparently because the compiler doesn't understand the size of my array.
even when I try to do it this way:
matrix->matrix={{1,2,3},{4,5,6},{7,8,9}};
does anyone know how to do this ? it seems to me like something very simple. thanks a lot!