I’m writing code to read in a 7×15 block of text in a file that will represent a ‘maze’.
#include <iostream>
#include <fstream>
#include <string>
#include "board.h"
int main()
{
char charBoard[7][15]; //the array we will use to scan the maze and modify it
ifstream loadMaze("maze"); //the fstream we will use to take in a maze
char temp; //our temperary holder of each char we read in
for(int i = 0;i < 7; i++)
{
for(int j = 0; j < 15; j++)
{
temp= loadMaze.get();
charBoard[i][j] = temp;
cout << charBoard[i][j]; //testing
}
cout << endl;
}
return 0;
}
this was my original draft but this didnt work as it kept returning ? for each char it read.
This is the maze im testing with:
#############
#
############ #
#
######### ####
# ! #
############
EDIT:
The cout is printing this:
############# # ############ # # ######### #### # ! # #########
Am I not escaping \n’s?
I’ve been coding for a few hours so I think its a simple mistake I’m not catching that’s tripping me up right now. Thanks!
Try an absolute path like “c:\MyMazes\maze”.
Throw in a system(“cd”) to see where the current directory is. If you’re having trouble finding the current directory, check out this SO discussion
Here’s the complete code – this should display your entire maze (if possible) and the current directory.