# Pset3, Error in init function

This is the error I get:

:( init initializes 3x3 board correctly

\ expected file to be of length 18, not 19

:( init initializes 4x4 board correctly

\ expected file to be of length 38, not 39

However, my code for init function is as follows:

``````void init(void)
{

for(int i = 0; i < d; i++)
{
for(int j = 0; j < d; j++)
{
board[i][j] = d*(d - j) - (i + 1);
}
}

board[d - 1][d - 1] = '_';
}
``````

How can I solve this?

It looks like the original code that you had was more correct than after the changes you made, whatever they were. The original problem lies here:

``````board[d - 1][d - 1] = '_';
``````

Since board[][] is an int array, you actually set the value to 95, the ASCII value of an underscore. Since check50 is expecting 0 but got 95, it got an extra digit, thus the error.

The value of the blank tile in the array should be set to 0. The underscore needs only be substituted when printing out the array in draw().

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

• I did that but the error still exists: { :( init initializes 3x3 board correctly \ expected "7" character 3 of line 1, not "5" } I have no idea why this is happening, it's annoying now. Commented Aug 31, 2016 at 14:58
• Your code is calculating the initial values by column and then by row, when it should be by row and then column. I suspect that your draw is doing the same. Unfortunately, check50 and the log.txt code depend on the top row being in board[0][x], not board[x][0]. Try reversing the i and j in the formula that calculates the initial values, and make the necessary changes in draw as well. Commented Aug 31, 2016 at 18:48
• that worked! thanks :) Commented Sep 3, 2016 at 6:09

The last element in your board does not need to be initialized by you.
Remember you should organize your elements differently depending on the board size.
The way you initialize your elements doesn't feel right, try writing by hand the expected values generated when making a small board, say the smallest value for d as possible and increase it by 1 or 2 if you don't find anything wrong.

For example a 3x3 board should be:

8 7 6
5 4 3
2 1 0

So your code should first generate the first row:
` 8 7 6 `
Second row:
` 5 4 3 `
And third row:
` 2 1 0 `