0

I would like to check the validity of the various functions in fifteen on a step-by-step basis. For example, I hope that I managed to code the init part of the function correctly:

void init(void)
{
for (i = 0; i < d; i++, k-- )
 {
    for (j=0; j<d; j++)
    {
        int grid[i][j] = k;
    }
  }

grid[i][i]= 90
if (d%2 == 0)
   {
grid[i][d-2]=1
grid[i][d-1]=2
   }
}

Is there anyway to verify that I coded correctly at this point? Alternatively, does anyone see any glaring errors in this first part of the code?

1

You can use debug50, like debug50 ./fifteen 3, and add a break point to your init function, from which you then can go step-wise. Or add a few debug outputs that you later remove.

What I am wondering... where does your k get declared and initialised? Shouldn't that be in init, too? Also, don't you think k should be decremented once per cell, not once per row? (you could alternatively compute the value to assign from i, j, and d)

2
  • I declared k, as int k = d*d, where d = atoi(argv[1]).. To do so, it should be done outside of the for loops and within the init function, correct?
    – Haim
    May 19 '17 at 15:07
  • If I were to use it that way, I'd place int k = d*d; at the beginning of init. And then make it board[i][j] = --k; or something like that. BTW, what is grid?
    – Blauelf
    May 19 '17 at 15:24

You must log in to answer this question.

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