Multi Array

Nov 24, 2012 at 10:56pm
I have an assignment I need to complete, where I get some data from a file and then have the output as a tic tac toe board.

On the file, it'll have something like
1
2
3
X O .
. . .
. . X


The '.' means that the spaces are blank.
I need to write a funtion to display a tic tac toe board on the screen.

1
2
3
4
5
X|O| 
-+-+-
 | | 
-+-+-
 | |X

I would just like some help starting the program. I don't know where to even begin. I need to get the file. After that i dont even know where to begin. Can someone help me out? Just a push in the right direction would be nice.
Nov 24, 2012 at 11:20pm
I don't know where to even begin. I need to get the file.


Sounds like a place to start.
Nov 25, 2012 at 12:00am
There are many threads about tic tac toe. I think you should search relevant threads by means of using keywords tic tac toe in this forum.

As for reading the file then you should decide either you will read data in a one-dimensional array of size equal to 9 or a two-dimensional array of size 3 x 3.
If all records of the file have exactly three fields then you can use operator >>.Otherwise you can use function getline.
Last edited on Nov 25, 2012 at 12:01am
Nov 25, 2012 at 12:43am
Thanks for the help, cire.

Vlad: I was thinking about it more, make and array like ticTac[3][3], and then make a loop, something like
1
2
3
4
5
6
7
8
9
10
11
12
13
 
for(int row = 0, row < 2, row++)
   {
    cout << ticTac[row][0] << "|";
    }
cout << ticTac[2][0] << endl;
cout << "-+-+-" << endl;
for(int row = 0, row < 2, row++)
   {
    cout << ticTac[row][1] << "|";
   }
cout << ticTac[2][1] << endl;
.....


Does that seem like it'd work after i read the file?
Nov 25, 2012 at 12:53am
Your code is invalid. There are three rows and three columns. So at least the loops should look like

for(int row = 0, row < 3, row++)

Also I have not understood what are you going to do by means of your code?
Nov 25, 2012 at 12:59am
What do you mean?
Nov 25, 2012 at 7:55am
What is the code snip you showed doing?
Topic archived. No new replies allowed.