I'm trying to put a 15x15 maze from a text file into a 2D array. So far, it's printing out a really stranger version so the maze looks weird and I can't move around a character.
static const int WIDTH = 15;
static const int HEIGHT = 15;
//declared an array to read and store the maze
char mazeArray[HEIGHT][WIDTH];
ifstream fin;
fin.open("lvl1.txt");
char ch;
while (!fin.eof())
{
fin.get(ch);
for(int i=0 ; i < HEIGHT ; i++)
{
for(int j=0 ; j < WIDTH ; j++)
{
fin >> mazeArray[i][j];
cout << ch;
}
}
}
fin.close();
# # # # # # # # # # # # # # #
# # # # # # # # #
# # # # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # #
# # # # # # # # # #
# # # # # # # # #
# # # # # # # # # #
# # # # # # # O #
# # # # # # # # # #
# # # # # # # # # #
# # # # # # # # # #
# # # # #
# # # # # # # # # # #
# # # # # # # # # # # # # # #
Above is a function which is supposed to read the file and place into a 2D array so I can call it later. Below it is the maze i'm trying to read out. Any ideas on why it's printing out wrong?