Hello people,
Quick question. I am working on a mouse maze project, and I need help reading the maze into a dynamically created multi-dimensional array, called "maze". I have already implemented a working code as long as the type of "maze" is char. Below is the code for that:
bool initializeMaze(ifstream& inputFile, char **maze)
{
int rows = 0, cols = 0; // local variables
inputFile.open("copy.txt");
if (inputFile)
{
// read row and col size for the array
inputFile >> rows;
inputFile >> cols;
// create a maze of x row's and x col's.
maze = new char* [rows];
for (int row = 0; row < rows; row++)
maze[row] = new char[cols];
// read the maze into the array
for (int row = 0; row < rows; row++)
{
cout << endl;
for (int col = 0; col < cols; col++)
{
inputFile >> maze[row][col];
cout << maze[row][col];
}
}
return true;
}
else
return false;
}
Now, to my question: What if my dynamic array "maze" was an integer array? Please do not respond with liners. A fully working code would be immensely appreciated. Just take my code above and edit to create what I asked.
Also, the format of the input file is:
First two numbers on top are row's and col's. The rest is the maze.
4 4
1111
1100
1111
THANK YOU!