Ok, I am trying to solve this super small error and I cannot figure it out. In this program you would read a board into a 2D array (this is the practice). The file contains "X" , "O" , and "." The program would then read through it and display it in the correct board format along with the X's and O's.
The main issue that I have is I can't figure out how to convert those "." (periods) from the file and turn them into " " (spaces), on the actual display. Is this going to be an IF statement? The only thing I can think of is to write:
The short answer is it looks OK, without testing it. There's no harm taking into account Handy's comments too.
I would declare cell_char outside the double loop. cell_char is just a name for a char variable. You can choose whatever you like for a name (within reason and C++ rules)
So you end up with something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//Read from file into array
char joemf88;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
fin >> joemf88;
if(joemf88 == '.')
ticTacBoard[i][j] = ' ';
else
tictTacBoard[i][j] = joemf88;
}
}
Ok I think that I have fixed that part except now that I have the error that if I am saving the file to a temporary location and then reading it again, the written file is suppose to look the same as the written file.
Am I suppose to do something in the "write board to file" code to make sure that its the same?
How in the world do I write this?
Also when I switch the arrays [j][i] to the other way, all get a lot more errors.
I think that it is a 9x9 because of the board because I tried to make it a 3x3 by making sure that the array syntax shows a 3 instead of a 9. I just got more errors.
HAHAHA this is hilarious. I made the changes that I saw in that code. I kept getting errors until I just decided to make it [j][i] instead of [i][j]. I don't know why it works that way. The nested for loop runs [i] as the rows and then [j] as the columns in the multi dimensional arrays, so you would think [i][j] would be the right code.
This program runs different txt files that have different tic tac toe boards. there is 3 and finally all 3 of those boards displayed correctly. thanks a ton for your help. this was driving me crazy!
I just had another look at your original code which I didn't look at all that carefully beyond the immediate problem. I think the reason is your display function. You have transposed rows and columns. That's why [j][i] worked and not [i][j].
You'll need to go through and stick to one single convention in all the functions.