I have a structure with a 2d array. I'm passing a pointer to this structure to a function, where I need to edit the 2d array. I am struggling to find the correct syntax to reference the 2d array from within my function.
#define TG_WIDTH 10
#define TG_HEIGHT 20
typedef enum {
BLOCK_T = 0,
BLOCK_LINE,
BLOCK_SQUARE,
BLOCK_L,
BLOCK_L_REVERSE,
BLOCK_S,
BLOCK_S_REVERSE
} block_t;
typedef struct {
char y_max[TG_WIDTH];
block_t grid[TG_WIDTH][TG_HEIGHT];
} scratchpad_t;
bool
placeBlock(scratchpad_t *sp) {
block_t (*g)[TG_WIDTH] = sp->grid;
g[1][2] = BLOCK_T;
}
This gives me an "initialization from incompatible pointer type" warning though. What is the correct way to define/initialize "g" here?