Function to change content in 2 dimensional array

Hi, I'm learning C++ on my own by reading different tutorials on the web. I'm trying to create a simple TicTacToe-game to play in the console window and want to create a funtion that initializes the board (a char 2-dim array) back to being all '_' char's, to use if the player wants to play again. Here is how I try to do this. I know there are probably much better ways of doing this than using an array but I want to understand this error before moving on to the better ways of doing things (first learn the basics...) :-)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define ROWS 3
#define COLS 3

void initializeBoard (char *aBoardArray, int nBoardDim)
{
	int nSize = sizeof(char);
	for (int row = 0; row < nBoardDim; row++)
	{
		for (int col = 0; col < nBoardDim; col++)
		{
			aBoardArray[row + nSize*col] = "_";
		}
	}
}

int main()
{
	char aBoard[ROWS][COLS];

	initializeBoard(&aBoard[0][0], ROWS);
		
	return 0;
}

I get the following error when trying to build: error C2440: '=' : cannot convert from 'const char [2]' to 'char'
The error is pointing to the row
 
aBoardArray[row + nSize*col] = "_";

in the initializeBoard-function.

Where is this const char [2] coming from? I can't understand why the array is being considered as const char?
Last edited on
Your are making an assignment
`from' means right side
`to' means left side

aBoardArray[row+nSize*col] is a char

"_" is a const char[2] (null terminated)


'_' is a char
Last edited on
oh, I had been struggling with this for hours but totally missed that I was using " instead of '. Though it was something more complex than that.
Thanks a lot!
Topic archived. No new replies allowed.