rdippold@maui.qualcomm.com (Ron Dippold) (02/20/91)
In article <1991Feb19.062220.26093@agate.berkeley.edu> bmyers@garnet.berkeley.edu (Brian Myers) writes: > >The following code was excerpted from a longer program for constructing >crossword puzzles. This short program does not work because each >assignment statement seems inexplicably to assign a value to *two* >different array elements at the same time. I observed this double >action with the "Watch Value" feature on the Debug menu. > >CELL grid[14][14]; /* crossword puzzle grid 15x15 */ > There's your problem... When you declare an array x[14], you are declaring an array with a size of 14, from [0] to [13]. So your grid[14][14] is the same as a pascal declaration grid[0..13][0..13]. That's why it changes "two" values. grid[1][14] IS actually grid[2][0].
acunger@netmbx.UUCP (Arnie Unger) (02/20/91)
bmyers@garnet.berkeley.edu (Brian Myers) writes: >The following code was excerpted from a longer program for constructing >crossword puzzles. This short program does not work because each >assignment statement seems inexplicably to assign a value to *two* >different array elements at the same time. I observed this double >action with the "Watch Value" feature on the Debug menu. >typedef struct puzzlecell { /* defines one cell in a 15x15 */ > char letter; /* crossword puzzle grid */ > int number; >} CELL; >CELL grid[14][14]; /* crossword puzzle grid 15x15 */ /********************************************************************* Your problem is right here, and it is an easy one. If you allocate a 14 X 14 grid, you only get valid addresses of 0 to 13 (an easy error to make) Try allocating it as 15 X 15 and you can use grid[10][14].letter with no error. By poking into grid[10][14], you were probably in the memory location for grid[11][0], or so... **********************************************************************/ >void main (void) >{ > /* each line _should_ write a Z in one square of the grid. */ > /* each line _does_ write a Z in _two_ squares. */ > grid[4][0].letter = 'Z'; /* also puts 'Z' at grid[3][14].letter */ > grid[10][14].letter = 'Z'; /* also puts 'Z' at grid[11][0].letter */ >} >/* A similar problem occurs whenever the second index is 0 or 14. */ >/* When the second index is > 0 and < 14, no problems occur. */ >--------------------------------------------------------------------------- >Brian Myers bmyers@garnet.berkeley.edu Note the change with the declaration of grid as 15 X 15 vice 14 X 14. You were one address short. With 15 X 15, your valid addresses are 0 to 14. Arnie Unger (acunger%netmbx@tmpmbx.UUCP) Berlin, Germany --- Seen on a F-111 bomb: TO ANY IRAQI SERVICEMEMBER!