I have a multidimensional array that stores some data, and I want to print it in a matrix form (so far no prolem), thing is I want to add a few columns and rows to make it readable. Something like this:
3 |
2 |
1 |
_ _ _
1 2 3
(the "inside square" is my actual 2d array)
My question is, what is the best way to do this?
My current code looks like this:
void printBoard(char board[N][N]) {
for (int i = N-1; i >= 0; i--) {
printf("%d %c ", i, BAR);
for (int j = 0; j < N; j++) {
printf("%c ", board[i][j]);
}
printf("\n");
}
for (int l = 0; l < 2; l++) {
for(int k = -4; k < N; k++) {
if(k < 0) {
printf("%c", SPACE);
}
else {
if(l == 0) {
printf("%c ", EMDASH);
}
else {
printf("%d ", k);
}
}
}
printf("\n");
}
}
It works fine but feels rather messy. Also, if I change the size of my array to be more than 10 rows/columns, the numbers don't fit right. Is there a way to format this properly without changing the original array (the one I'm passing into the function)?
Thanks!