Need help understanding 2 dimension Char array

I am new to c++ and am confused about char arrays. I think it has something to do with the null terminator(or maybe not). Here is what I am trying to do:

char board[3][3] = {{"*","*","*"},{"*","*","*"},{"*","*","*",}};

I am trying to initialize an array (Tic Tac Tow board) 3 x 3 with * in each space and have tried formatting the initializing data in many different ways and always get an error(too many initializes, expected } ....etc).

Any help is appreciated, Thanks
Your problem is that you are trying to make a 3 dimensional array: An array of arrays of strings - where strings are arrays of chars. You can specify you want arrays of chars by using single quotes instead of double quotes:
1
2
3
4
5
char board[3][3] = {
    {'*', '*', '*'}, 
    {'*', '*', '*'}, 
    {'*', '*', '*'}
};
Last edited on
when you use double quotes "" it is considered a string of chars and a \0 null character get applied to the end, use ' single quote to surround the asterix
@ NT3 wow you just beat me :P
Last edited on
Ha!

I am not going to admit to how long I have been messing with this array to try to get it working. My first language learned was php and the looseness of php has been killing me in c++

Thank you
Please Mark this thread as solved. Help us help you.
Topic archived. No new replies allowed.