Trying to make a tic-tac-toe game and having trouble with the grid, I'm new to C and have looked everywhere but nothing seems to work.
int main(void) {
char grid[GRID_HEIGHT][GRID_WIDTH];
grid = make_grid((char **)grid);
print_grid((char **)grid);
}
char ** make_grid(char **grid) {
char grid[GRID_HEIGHT][GRID_WIDTH] = {
{ '\n', ' ', '1', ' ', '|', ' ', '2', ' ', '|', ' ', '3', ' ' } ,
{ '\n', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' } ,
{ '\n', ' ', '4', ' ', '|', ' ', '5', ' ', '|', ' ', '6', ' ' } ,
{ '\n', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-' } ,
{ '\n', ' ', '7', ' ', '|', ' ', '8', ' ', '|', ' ', '9', ' ' }
};
return grid;
}
void print_grid(char **grid) {
for (int row = 0; row < GRID_HEIGHT; row++) {
for (int column = 0; column < GRID_WIDTH; column++) {
printf("%c", grid[row][column]);
}
}
printf("\n");
}
How would I parse the grid into a function and also return it without the program crashing?