I'm making a program due tomorrow where we have to use a multidimensional array. The program is supposed to call for the name of a file. The file will be in this format:
X O .
. . .
. O .
We need to have a multidimensional array which save this information into itself, and then we will print it out with a board in this format
X | O |
---+---+---
| |
---+---+---
| X |
(sorry I just realized the formatting didn't come in correctly there... Imagine them to be nice squares...)
Will the code I have do the trick? I'm currently getting an error on the first for loop where I'm trying to save board[row][column] = fin. It's saying something about unable to convert void* to char or something like that. I'm not quite sure what it means.
I guess my main issue is I have absolutely no clue how to work with multidimensional arrays, and my book isn't helping much and the lecture on the topic isn't until tomorrow...
fin is an object of ifstream, you cannot assign directly an object to a primitive type like int char.. etc.
i think you array size should be 3x3 not 3x5, spaces *aren't read when reading files*
You need to have a temporary variable where you will extract the readed character, then copy it to board[ index ][ index ] like :
1 2 3 4 5 6
char temp;
for( int i = 0; i < 3; i++ ) {
for( int j = 0; j < 3; j++ ) {
fin >> temp; // extract a character to temp variable
board[ i ][ j ] = temp;
}
And IMO, you should read a file instead using while() loop with fin >> temp as the condition, this is to prevent accidental reading even if something went wrong w/ the file