This is an assignment from school, I have spent a week bashing my head against the wall atrying to figure out how to get this to work. The program reads in a 'maze' or X's and stuff from, a file, and my functions are to fill a pre diminshied char** array and then display it, there is a recursive maze solving problem as well but I think I have that figured out but I wont know till I can get it to display in the first place! let me know if anyone has any pointers thankS!
void Maze::fill(const char fileName[])
{
ifstream inFile;
int row = 0, newRows = 0, newCols = 0;
string buffer;
// Attempt to open the file
inFile.open(fileName);
if (inFile.fail())
{
throw exception("Failed to open input file");
}
// Get the number of maze rows and columns
// and allocate the maze grid
inFile >> newRows >> newCols;
setRows(newRows);
setCols(newCols);
grid = new char*[getRows()];
for (row = 0; row < getRows(); ++row)
{
grid[row] = new char[getCols()];
}
// Move past the trailing new line after the column
getline(inFile, buffer);
// Fill in the grid for the maze
row = 0; // start at the first row of the grid
while (!inFile.eof())
{
// Get a row of grid data
getline(inFile, buffer);
// CODE NEEDED: A single inner loop
// Loop through the length of the string buffer (buffer.length())
// and assign the characters from buffer to each cell in
// the current grid row. If encountering a START or EXIT character,
// then also call setStart or setExit accordingly.
for(int x = 0 ; x < buffer.length() ; x++)
{
(grid[row][x]) = buffer[x] ;
if ((grid[row][x]) == START)
setStart(row,x);
if((grid[row][x]) == EXIT)
setExit(row,x);
}
// display();
row++; // next row in the grid
}
inFile.close();
}
HERE IS THE DISPLAY FUNCTION
void Maze::display()
{
for (int x = 0 ; x < getRows() ; x ++)
{
for (int y = 0 ; y < getCols() ; y++)
{
cout<<grid[x,y];
}
cout<<endl;
}
}
any help would be greatly appreciated!!! thanks!