0

So I am stuck at initializing the board. my for loop is doing what it should but it stops when it is not actually done. The board I initialize is made of the dimensions d * d and should start left to right, top to bottom from d*d-1 counting down and leave the last one empty. I'm not far enough to let the last one empty, my problem is it stops whenever it reaches the number 9, it doesn't matter which size I run it with, it will always stop when it reaches the number 9.

void init(void)
{
int down=1;
for(int i=0;i<d;i++)
{
    for(int j=0;j<d;j++)
    {
        board[i][j]=(d*d)-down;
        down++;
        printf("Number:%i, i=%i, j=%i\n", board[i][j], i, j);
    }
}
}

Number:15, i=0, j=0
Number:14, i=0, j=1
Number:13, i=0, j=2
Number:12, i=0, j=3
Number:11, i=1, j=0
Number:10, i=1, j=1
Number:9, i=1, j=2

This is when I give it the size of 4x4. I'm using printf to find where it goes wrong. I don't understand why it stops when i=1 and j=2 while I declared it to only stop when it would reach 4. If I choose 8x8 or anything else it will still stop when it reaches the number 9. Has this something to do with the defined dimensions of the board?

define DIM_MIN 3

define DIM_MAX 9

I really can not figure this out. friends i asked told me my code works just fine for them. Please help me.

EDIT: If I set a breakpoint at int down=1; and then keep on clicking on step over in the debugger the program will work just fine and count all the way down to 0. I've tried everything but the only way for the code to work is skip through it in the debugger.

1 Answer 1

1

Your Code seem fine

I just executed it and it runs okay. Update and restart your IDE and see if that solve your problem. Your code output

3
  • It is updated and I started from scratch too after re downloading everything. Commented Sep 5, 2017 at 17:39
  • If I set a breakpoint at int down=1; and then keep on clicking on step over in the debugger the program will work just fine and count all the way down to 0. I've tried everything but the only way for the code to work is skip through it in the debugger. Commented Sep 5, 2017 at 17:39
  • You can always try a different implementation. Commented Sep 6, 2017 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .