# Grid

• 03-11-2011
mortalc
Grid
I want to create a 9x9 grid for a sudoku program I'm making. I've got a randomly generated set of numbers stored in sudoku[8][8]. some will be a number between 1 and 9, others will be an empty value. What I need is a 9x9 grid which has the following properties:

1. Each cell corresponds to a number in the sudoku array, so if sudoku[0][0] is 7, the top left-hand box will be 7.
2. The ones with no value can be written in - but only one digit and only a number between 1 and 9.
3. If you press 'enter' after writing the digit, the number will be transfered to the corresponding array slot
4. However you can still go back and change them

I think I can do 3., and 4. probably comes with 2. So I just want to know how to do 1. and 2..
• 03-11-2011
Salem
Well apart from needing [9][9] as the array size, what code do you have?

You could have a separate array of booleans, which tell you whether a particular cell is read-only or modifyable.
• 03-11-2011
mortalc
I thought [8][8] is what I need, because it starts at [0][0]?
• 03-11-2011
Salem
True, but the max allowed subscript is one LESS than the dimension size (because you start counting at 0, not 1)
• 03-12-2011
mortalc
I'm not following you. surely sudoku[8][8] will be nine rows of
[0][1][2][3][4][5][6][7][8]
• 03-12-2011
quzah
Quote:

Originally Posted by mortalc
I'm not following you. surely sudoku[8][8] will be nine rows of
[0][1][2][3][4][5][6][7][8]

No. If you do:
Code:

`int sudoku[8][8];`
You only get 0 through 7. You don't get to access sudoku[8]. You are declaring the number of elements. Not the last number you want available to access. Why would 8 x 8 = 81? That's 9 x 9.

Quzah.
• 03-12-2011
CommonTater
Quote:

Originally Posted by mortalc
I'm not following you. surely sudoku[8][8] will be nine rows of
[0][1][2][3][4][5][6][7][8]

You are mistaking "the number of elements" for "the number of the element"...

To make a 9 x 9 grid use sudoku[9][9] ... which will give you 9 elements numbered from 0 to 8... Go ahead count them...
• 03-12-2011
mortalc
OOOOOOOOOOOOOOOOOOOOOHHHHHHHHHH!

I didn't know that it would stop at 7!