Grid

This is a discussion on Grid within the C Programming forums, part of the General Programming Boards category; I want to create a 9x9 grid for a sudoku program I'm making. I've got a randomly generated set of ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    19

    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..

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    I thought [8][8] is what I need, because it starts at [0][0]?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    True, but the max allowed subscript is one LESS than the dimension size (because you start counting at 0, not 1)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    I'm not following you. surely sudoku[8][8] will be nine rows of
    [0][1][2][3][4][5][6][7][8]

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by mortalc View Post
    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.
    Hope is the first step on the road to disappointment.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mortalc View Post
    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...

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    19
    OOOOOOOOOOOOOOOOOOOOOHHHHHHHHHH!

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another hard C problem
    By alexbcg in forum C Programming
    Replies: 12
    Last Post: 11-23-2010, 07:03 AM
  2. More Windows Trouble
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 04-12-2005, 10:02 AM
  3. Cleaning up a Grid of Memory
    By Epo in forum C++ Programming
    Replies: 9
    Last Post: 02-25-2005, 09:23 AM
  4. Find a word in a 2d grid
    By The_Kingpin in forum C++ Programming
    Replies: 2
    Last Post: 02-24-2005, 04:38 PM
  5. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21