0

I'm working on a program where you find any path through a graph. When inputting the graph using an array, I found the number in position[0][8][9] gets set as 1 rather than 0 after position[0][9][1] is read in to memory.

I've tried both gcc 3.3.2 and 4.0, and get the same result on both. Does anyone else get the same results?

#include <iostream>

using namespace std;

typedef char board[4][9][9];
board maze; //maze is global so we don't have to pass it in every recursive call.

int main()
  {
	cout << "Position [0][8][9] should be a 0.  It is a 1." << endl;
	//Enter just a simple 1-level maze
	maze[0][0][0] = '0';
	maze[0][0][1] = '0';
	maze[0][0][2] = '0';
	maze[0][0][3] = '0';
	maze[0][0][4] = '1';
	maze[0][0][5] = '1';
	maze[0][0][6] = '1';
	maze[0][0][7] = '1';
	maze[0][0][8] = '1';
	maze[0][0][9] = '1';
	
	maze[0][1][0] = '1';
	maze[0][1][1] = '1';
	maze[0][1][2] = '1';
	maze[0][1][3] = '0';
	maze[0][1][4] = '1';
	maze[0][1][5] = '1';
	maze[0][1][6] = '1';
	maze[0][1][7] = '1';
	maze[0][1][8] = '1';
	maze[0][1][9] = '1';
	
	maze[0][2][0] = '1';
	maze[0][2][1] = '1';
	maze[0][2][2] = '1';
	maze[0][2][3] = '0';
	maze[0][2][4] = '1';
	maze[0][2][5] = '1';
	maze[0][2][6] = '1';
	maze[0][2][7] = '1';
	maze[0][2][8] = '1';
	maze[0][2][9] = '1';
	
	maze[0][3][0] = '1';
	maze[0][3][1] = '0';
	maze[0][3][2] = '0';
	maze[0][3][3] = '0';
	maze[0][3][4] = '1';
	maze[0][3][5] = '0';
	maze[0][3][6] = '0';
	maze[0][3][7] = '0';
	maze[0][3][8] = '0';
	maze[0][3][9] = '1';
	
	maze[0][4][0] = '1';
	maze[0][4][1] = '0';
	maze[0][4][2] = '1';
	maze[0][4][3] = '1';
	maze[0][4][4] = '1';
	maze[0][4][5] = '0';
	maze[0][4][6] = '1';
	maze[0][4][7] = '1';
	maze[0][4][8] = '0';
	maze[0][4][9] = '1';
	
	maze[0][5][0] = '1';
	maze[0][5][1] = '0';
	maze[0][5][2] = '0';
	maze[0][5][3] = '0';
	maze[0][5][4] = '0';
	maze[0][5][5] = '0';
	maze[0][5][6] = '1';
	maze[0][5][7] = '0';
	maze[0][5][8] = '0';
	maze[0][5][9] = '1';
	
	maze[0][6][0] = '1';
	maze[0][6][1] = '0';
	maze[0][6][2] = '0';
	maze[0][6][3] = '0';
	maze[0][6][4] = '0';
	maze[0][6][5] = '1';
	maze[0][6][6] = '1';
	maze[0][6][7] = '0';
	maze[0][6][8] = '0';
	maze[0][6][9] = '1';
	
	maze[0][7][0] = '1';
	maze[0][7][1] = '0';
	maze[0][7][2] = '1';
	maze[0][7][3] = '1';
	maze[0][7][4] = '0';
	maze[0][7][5] = '1';
	maze[0][7][6] = '1';
	maze[0][7][7] = '0';
	maze[0][7][8] = '0';
	maze[0][7][9] = '1';
	
	maze[0][8][0] = '1';
	maze[0][8][1] = '0';
	maze[0][8][2] = '0';
	maze[0][8][3] = '0';
	maze[0][8][4] = '0';
	maze[0][8][5] = '1';
	maze[0][8][6] = '1';
	maze[0][8][7] = '0';
	maze[0][8][8] = '0';
	maze[0][8][9] = '0';
	
	maze[0][9][0] = '1';
	maze[0][9][1] = '1';
	maze[0][9][2] = '1';
	maze[0][9][3] = '1';
	maze[0][9][4] = '1';
	maze[0][9][5] = '1';
	maze[0][9][6] = '1';
	maze[0][9][7] = '1';
	maze[0][9][8] = '0';
	maze[0][9][9] = '0';
//Debug:  Print out the maze and wait for enter to be pressed
for (int i=0; i<=9; i++)
  {
	cout  << i << " ";
	for (int column=0; column<=9; column++)
	  cout << maze[0][i][column];
	cout << endl;
	}

	}
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by Dave Sinkula
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.