I'm trying to solve a sudoku checker for a game I'm building in C. Essentially these nested for loops are supposed to check through the smaller boxes of 9 numbers to ensure there are no duplicates. Unfortunately, the continue seems to make the checker not work. :(

576 -------the "5"s should trip up the function to send the show_banner() warning

The reason the first if statement exists is to make sure that the original coordinate is not check against itself. So, if I just typed the two in the above example, I want the for loops here to check everything, but the two that I typed (And in this case the warning would not be displayed.)

I troubleshooted the for loops and found that when I do eliminate the first if statement the banner does show up properly, but the loops are still checking the inputted value against itself.

i also tried inputting != into the top if statement and then placing the second if statement under the first one, but it still didn't work.

I hopped around the message boards and could not find an answer to this particular dilemma, so please help!!!

for (int k = 0; k < 2; k++)
        for (int l = 0; l < 2; l++)
            if (((((g.y/3)*3)+k) == g.y) && ((((g.x/3)*3)+l) == g.x)) 

            if (g.board[((g.y/3)*3)+k][((g.x/3)*3)+l] == g.board[g.y][g.x])
                    show_banner("You sure that's a good move?");


The 'math' in your if statements is very sloppy, it's hardly readable what's going on.

First off, why are you doing stuff like

if( (g.y/3)*3 == something )

g.y/3 * 3 is the same as g.y

So the two if reads:

if( g.y+k == g.y && g.x+l == g.x ) 

if( g.board[g.y+k][g.x+l] == g.board[g.y][g.x] )

So, now that things look clearer what exactly do you need to do?
- Take the element at [0,0], compare to every other element in the set.
- Take the element at [0,1], ...
- etc.

I think you can get that working.

Now, you say that the element that it currently being checked should not be checked to itself. Why not? Where is the harm?

If I check for duplicates in the array [ 0 1 2 2 ].
I'd take the first element 0, compare it to 0, 1, 2, 2 increasing a number when they are equal. At the end of this loop you can just say 'There are duplicates if I found more than 1 match'.

Hope that helped