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

I'm not absolutely sure, but it may be because its in a loop. Why exactly do you have it getting the file 12 times? It has been a while since I have done c++ but that may be a problem, also when you have a while inside a while, they cant run simultaneously, only one while can run at once, so that may be a part of your problem? I don't really know what you're trying to get it for etc. and like I said its been a while.

I'm not absolutely sure, but it may be because its in a loop. Why exactly do you have it getting the file 12 times? It has been a while since I have done c++ but that may be a problem, also when you have a while inside a while, they cant run simultaneously, only one while can run at once, so that may be a part of your problem? I don't really know what you're trying to get it for etc. and like I said its been a while.

Its a 12 by 12 Maze. My input code may be wrong im sitting here working on it. The program runs but crashes due to whitespace, some how i have to take it into account. Any suggestions would be apprecaited.

Thanks

mynumb = inFile.get();
?????????
array[j]= mynumb;

Try changing the above to

inFile >> array[j];

and looking up the difference between the behaviour of get() vs >>. They both have their uses.

This article has been dead for over six months. Start a new discussion instead.