I am doing a mazetraversal program that inputs a .dat text file.
Im having trouble taking in account of the whitespace.
Here is my code and were the ?????? is where it needs to go.
I think its just a small "if" statement taking it in account.
#include <iostream>
#include <ctime>
#include <fstream>
using std::cout;
using std::endl;
using namespace std;
void mazeTraverse( char [][12], int, int );
//This is were expected identifiers are placed.
int main()
{
ifstream inFile("themaze.dat");
if (inFile.fail())
{
cout << "unable to open file input.dat for reading" << endl;
exit(1);
}
char x=inFile.get();
inFile.get();
char y=inFile.get();
int j=0;
int i=0;
char mynumb;
char array[12][12];
while ( j<12)
{
while( i<12)
{
mynumb = inFile.get();
?????????
array[j][i]= mynumb;
i++;
}
j++;
}
mazeTraverse(array, 2,0);
} // end main
void mazeTraverse( char move[][12], int x, int y )
{
//The first step of the algorithm for walking through the maze.
static int update = time( 0 ) % 10;
while ( time(0) % 10 != update )
; // wait
if ( time( 0 ) % 10 == 9 )
update = 0;
else
update = (time( 0 ) % 10) + 1;
move[x][y] = '@'; // This is were it marks the visited places.
//Seperates each maze as the moves are made.
cout << "Maze seperation/Checking directions."<<endl;
// This prints the maze and starts the execution
for ( int row = 0; row < 12; row++ )
{
for ( int column = 0; column < 12; column++ )
cout << move[row][column];
cout << '\n';
}
if ( move[x][y] == 'M' )
{
cout << "\nEndofMaze\n";
return;
}
//Steps that finds the directions to travel.
else
{
if ( move[x-1][y] == '.' || move[x-1][y] == 'M' ) //Checks to go up
mazeTraverse( move, x-1, y ); // Moves Up
if ( move[x+1][y] == '.' || move[x+1][y] == 'M' ) //Checks to go down
mazeTraverse( move, x+1, y ); // Moves Down
if ( move[x][y-1] == '.' || move[x][y-1] == 'M' ) // Checks to go left
mazeTraverse( move, x, y-1 ); // Moves Left
if ( move[x][y+1] == '.' || move[x][y+1] == 'M' ) // Checks to go right
mazeTraverse( move, x, y+1 ); // Move Right
move[x][y] = '.';
return;
}
} // end function mazeTraverse