Weird bug...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Weird bug...

 
0
  #1
Nov 30th, 2005
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?

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. typedef char board[4][9][9];
  6. board maze; //maze is global so we don't have to pass it in every recursive call.
  7.  
  8. int main()
  9. {
  10. cout << "Position [0][8][9] should be a 0. It is a 1." << endl;
  11. //Enter just a simple 1-level maze
  12. maze[0][0][0] = '0';
  13. maze[0][0][1] = '0';
  14. maze[0][0][2] = '0';
  15. maze[0][0][3] = '0';
  16. maze[0][0][4] = '1';
  17. maze[0][0][5] = '1';
  18. maze[0][0][6] = '1';
  19. maze[0][0][7] = '1';
  20. maze[0][0][8] = '1';
  21. maze[0][0][9] = '1';
  22.  
  23. maze[0][1][0] = '1';
  24. maze[0][1][1] = '1';
  25. maze[0][1][2] = '1';
  26. maze[0][1][3] = '0';
  27. maze[0][1][4] = '1';
  28. maze[0][1][5] = '1';
  29. maze[0][1][6] = '1';
  30. maze[0][1][7] = '1';
  31. maze[0][1][8] = '1';
  32. maze[0][1][9] = '1';
  33.  
  34. maze[0][2][0] = '1';
  35. maze[0][2][1] = '1';
  36. maze[0][2][2] = '1';
  37. maze[0][2][3] = '0';
  38. maze[0][2][4] = '1';
  39. maze[0][2][5] = '1';
  40. maze[0][2][6] = '1';
  41. maze[0][2][7] = '1';
  42. maze[0][2][8] = '1';
  43. maze[0][2][9] = '1';
  44.  
  45. maze[0][3][0] = '1';
  46. maze[0][3][1] = '0';
  47. maze[0][3][2] = '0';
  48. maze[0][3][3] = '0';
  49. maze[0][3][4] = '1';
  50. maze[0][3][5] = '0';
  51. maze[0][3][6] = '0';
  52. maze[0][3][7] = '0';
  53. maze[0][3][8] = '0';
  54. maze[0][3][9] = '1';
  55.  
  56. maze[0][4][0] = '1';
  57. maze[0][4][1] = '0';
  58. maze[0][4][2] = '1';
  59. maze[0][4][3] = '1';
  60. maze[0][4][4] = '1';
  61. maze[0][4][5] = '0';
  62. maze[0][4][6] = '1';
  63. maze[0][4][7] = '1';
  64. maze[0][4][8] = '0';
  65. maze[0][4][9] = '1';
  66.  
  67. maze[0][5][0] = '1';
  68. maze[0][5][1] = '0';
  69. maze[0][5][2] = '0';
  70. maze[0][5][3] = '0';
  71. maze[0][5][4] = '0';
  72. maze[0][5][5] = '0';
  73. maze[0][5][6] = '1';
  74. maze[0][5][7] = '0';
  75. maze[0][5][8] = '0';
  76. maze[0][5][9] = '1';
  77.  
  78. maze[0][6][0] = '1';
  79. maze[0][6][1] = '0';
  80. maze[0][6][2] = '0';
  81. maze[0][6][3] = '0';
  82. maze[0][6][4] = '0';
  83. maze[0][6][5] = '1';
  84. maze[0][6][6] = '1';
  85. maze[0][6][7] = '0';
  86. maze[0][6][8] = '0';
  87. maze[0][6][9] = '1';
  88.  
  89. maze[0][7][0] = '1';
  90. maze[0][7][1] = '0';
  91. maze[0][7][2] = '1';
  92. maze[0][7][3] = '1';
  93. maze[0][7][4] = '0';
  94. maze[0][7][5] = '1';
  95. maze[0][7][6] = '1';
  96. maze[0][7][7] = '0';
  97. maze[0][7][8] = '0';
  98. maze[0][7][9] = '1';
  99.  
  100. maze[0][8][0] = '1';
  101. maze[0][8][1] = '0';
  102. maze[0][8][2] = '0';
  103. maze[0][8][3] = '0';
  104. maze[0][8][4] = '0';
  105. maze[0][8][5] = '1';
  106. maze[0][8][6] = '1';
  107. maze[0][8][7] = '0';
  108. maze[0][8][8] = '0';
  109. maze[0][8][9] = '0';
  110.  
  111. maze[0][9][0] = '1';
  112. maze[0][9][1] = '1';
  113. maze[0][9][2] = '1';
  114. maze[0][9][3] = '1';
  115. maze[0][9][4] = '1';
  116. maze[0][9][5] = '1';
  117. maze[0][9][6] = '1';
  118. maze[0][9][7] = '1';
  119. maze[0][9][8] = '0';
  120. maze[0][9][9] = '0';
  121. //Debug: Print out the maze and wait for enter to be pressed
  122. for (int i=0; i<=9; i++)
  123. {
  124. cout << i << " ";
  125. for (int column=0; column<=9; column++)
  126. cout << maze[0][i][column];
  127. cout << endl;
  128. }
  129.  
  130. }
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Weird bug...

 
0
  #2
Nov 30th, 2005
Arrays are zero-based. If you have T array[10], it may be indexed from 0-9, not 0-10.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC