I'm trying to scan in a grid of letters. cases
is the number of letter grids and r
, c
are for number of rows and columns of each grid. I figured I could create an array of structs with 2D arrays inside. I've been working on this for a few hours now and it's still giving me problems:
Warnings:
- Warning C4477 (Line 12) - ‘scanf_s’ : format string ‘%s’ requires an argument of type ‘char*’, but variadic argument 1 has type ‘int’
- Warning C4473 (Line 12) - ‘scanf_s’ : not enough arguments passed for format string
Errors:
The code:
scanf_s("%d", &cases);
struct grid {
char **grid;
};
struct grid *grids = (struct grid*)malloc(cases * sizeof(struct grid));
for (i = 0; i < cases; i++) {
scanf_s("%d %d", &r, &c);
grids[i].grid = (char**)malloc(sizeof(char*) * r);
for (k = 0; k < r; k++) {
grids[i].grid[k] = (char*)malloc(sizeof(char) * (c+1));
scanf_s("%s", grids[i].grid[k], (c+1));
}
}