Okay, I'm having a kind of weird issue here. I'm working on a program where a "maze," represented by various characters, is read from a file and solved by the computer.
Right now I'm attempting to have the maze be read into a 2d array. I'm also having the maze be printed twice at the moment, once as it is being read into memory, and again afterwards to ensure everything got saved correctly. The first printing goes correctly, but the second printing shows me that the last row of the array has somehow overridden all the other rows. Any attempt to access a specific value of the array will confirm this. To give you an idea of what Im talking about, here's what the maze is supposed to look like, and what the first printing shows:
S#.#...##.G
..##..#..#.
.#..#.#....
...##..#...
..#.....###
#...#...#..
..#..#.#...
.####.....#
...##.##...
.#....####.
###........
Meanwhile, here's what the second printing shows, and what any attempt to access the array will tell you:
###........
###........
###........
###........
###........
###........
###........
###........
###........
###........
###........
Obviously this is quite frustrating to me. Anyways, here's the code for reading and printing the array:
ifstream input(fileLocation);
//get the maze dimensions
input >> dimX;
input >> dimY;
maze = new char[(dimX - 1), (dimY - 1)]; //Allocate memory for the maze
//read the maze into memory and prints it for reference
cout << "Initial Maze:" << endl;
for (int i = 0; i < dimY; i++) {
for (int j = 0; j < dimX; j++) {
input >> maze[i, j];
cout << maze[i, j];
//recognizing the start space
if (maze[i,j] == 'S') {
currPos = &maze[i,j];
}
else if (maze[i, j] == 'G') { //recognizing the end space
goalX = j;
goalY = i;
}
}
cout << endl;
}
input.close();
//second print for test
for (int i = 0; i < dimX; i++) {
for (int j = 0; j < dimY; j++) {
cout << maze[i, j];
}
cout << endl;
}
Any help at all would be appreciated. Please don't hesitate to let me know if you need more information.