Board dimensions are taken in and if the user enters:
row = 4
columns = 3
I have written the code but I can only get the board to display:
...
...
...
...
Board* createBoard(int rows, int cols) {
Board *board = malloc(sizeof(Board));
board->contents = malloc(sizeof(char*) * rows);
for (int i = 0 ; i < rows ; ++i) {
board->contents[i] = malloc(sizeof(char) * (cols+2));
memset(board->contents[i], '.', cols);
board->contents[i][cols] = '\n';
board->contents[i][cols+1] = '\0';
}
board->rows = rows;
board->cols = cols;
return board;
}
void show_Board(Board *board) {
int j = 0;
for (int i = 0 ; i < board->rows; ++i) {
fprintf(stdout,"%s",board->contents[i]);
}
}
int main () {
Board *board = malloc(sizeof(Board));
board = createBoard(4,3);
show_Board(board);
}
The format of the playing board after input from user.
......
......
......
......
So instead of just showing one character per column, in this case dot(.), I need to show two characters per column like above.