I have an issue that involves many concepts that I think I understand, but am having trouble with when combined together into one very large problem.
I am working on making a game for my EECS 183 class where you have to read in a file of integers in a grid form and put them into a game board that is basically a matrix.
The program has already been designed for us by our professor so the only thing we have to do is implement them, so I can't change the design.
Already defined for us in the header file is a struct. I'll post it below.
struct Cell
{
int number; // If number is 0, the square is not occupied.
bool permanent; // the border values
};
The function I am having trouble with involves reading the ints from the file into the game board, which is basically a sudoku board (but the game isn't sudoku).
The function takes in the ifstream variable called ins, and array called board that is of type Cell, and another int variable.
To handle the task at hand I have the file read the first int of the file (which determines the size of the board) into a variable, then use that variable in two for loops which controls how the remaining integers are read into the matrix.
void readIntFile(ifstream& ins, Cell board[BOARD_SIZE][BOARD_SIZE], int& numTowers){
string junk;
int boardSize;
ins >> boardSize;
for (int i = 0;i < boardSize + 2;i++){
for(int j = 0; j < boardSize + 2;j++){
ins >> board.number;
board[i][j] = board.number;
}
getline(ins,junk);
}
}
I think my problem has to do with how it is assigning the integers into the array, but I havn't been able to find a solution to my problem on google, or on here.
Any help would be greatly appreciated.
I hope this formats correctly.