I am fairly new to C and have a bit of a trouble using an array as a part of a struct. I have a struct defined as follows:
typedef struct
{
int row;
int col;
int * puzzle[5][5]
} data;
Later on in a function, I am trying to use this struct as follows:
void foo(int grid[5][5])
{
data *puz = (data *)malloc(sizeof(data));
puz->row = 3;
puz->col = 2;
puz->puzzle = grid; // causes an error
}
The last statement produces an error "assignment to expression with array type". I understand that this has something to do with the equal sign and array data structure, but I am not sure how to resolve this. Any help is greatly appreciated. Thank you.
int (*puzzle)[5][5]this way.foo.ints -int puzzle[5][5], then usememcpy(careful with the size,sizeof puz->puzzle!)int *grid[5]toint (*puzzle)[5][5]is a bit tricky for a newbie