I'm trying to initialize this matrix with a constant string (i.e. "@"), in order to fill it later. Hence, the output is not what I'm expecting. Can you please tell me what I'm doing wrong? Can you give me some advice on how to better initialize the matrix with a constant string?
#include <iostream>
#include <string>
using namespace std;
char* Board[3][3];
char* PLAYER = "X";
char* COMPUTER = "O";
void displayBoard() {
printf(" %c | %c | %c ", Board[0][0], Board[0][1], Board[0][2]);
printf("\n---|---|---\n", Board[0][0], Board[0][1], Board[0][2]);
printf(" %c | %c | %c ", Board[1][0], Board[1][1], Board[1][2]);
printf("\n---|---|---\n", Board[0][0], Board[0][1], Board[0][2]);
printf(" %c | %c | %c ", Board[2][0], Board[2][1], Board[2][2]);
printf("\n---|---|---\n", Board[0][0], Board[0][1], Board[0][2]);
}
void FillBoard() {
char* initialValue = "@";
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
Board[i][j] = initialValue;
}
}
}
int main () {
FillBoard();
displayBoard();
}
Output:
f | f | f
---|---|---
f | f | f
---|---|---
f | f | f
---|---|---