I'm having trouble getting my dynamic 2d array to work consistantly in my program.
Here's the code:
#include <iostream>
#include <string>
#include "DisjSet.h"
using namespace std;
struct cell
{
bool nWall;
bool sWall;
bool wWall;
bool eWall;
};
void CreateMaze(cell** &maze, int x, int y);
void LoadMaze(cell** &maze, int x, int y);
int main()
{
int x = 0, y = 0, totCells = 0;
cell **maze = 0;
cout << "Enter the maze's dimensions separated by a comma. " << endl;
cout << "Format x,y: ";
cin >> x;
cin.get();
cin >> y;
cout << endl;
totCells = x * y;
DisjSet<char> djSet(totCells);
CreateMaze(maze, x, y);
LoadMaze(maze, x, y);
cout << endl << "cout << maze[][].*Wall; in main()" << endl;
cout << maze[x][y].nWall << endl;
system("pause");
return 0;
}
void CreateMaze(cell** &maze, int x, int y)
{
maze = new cell*[y];
for (int i = 0; i < y; i++)
maze[i] = new cell[x];
}
void LoadMaze(cell** &maze, int x, int y)
{
cout << "cout << maze[][].*Wall; in LoadMaze()" << endl << endl;
for (int i = 0; i < y; i++)
{
for (int j = 0; j < x; j++)
{
cout << i << "," << j << " stores ";
maze[i][j].nWall = true;
maze[i][j].sWall = true;
maze[i][j].wWall = true;
maze[i][j].eWall = true;
cout << maze[i][j].nWall << " " << maze[i][j].sWall << " " << maze[i][j].wWall << " " << maze[i][j].eWall << " " << endl;
}
}
}
Here's the output:
Enter the maze's dimensions separated by a comma.
Format x,y: 3,5
cout << maze[][].*Wall; in LoadMaze()
0,0 stores 1 1 1 1
0,1 stores 1 1 1 1
0,2 stores 1 1 1 1
1,0 stores 1 1 1 1
1,1 stores 1 1 1 1
1,2 stores 1 1 1 1
2,0 stores 1 1 1 1
2,1 stores 1 1 1 1
2,2 stores 1 1 1 1
3,0 stores 1 1 1 1
3,1 stores 1 1 1 1
3,2 stores 1 1 1 1
4,0 stores 1 1 1 1
4,1 stores 1 1 1 1
4,2 stores 1 1 1 1
cout << maze[][].*Wall; in LoadMaze()
171
Press any key to continue...
Why is it giving me '171'? Thanks!