I'm receiving a segementation fault with the code below. I've played with the code a little bit. I'm assuming there are problems in the move and won functions as well, but I'm unable to check them, given the two errors below.
:( init initializes 3x3 board correctly
\ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 276..."
:( init initializes 4x4 board correctly
\ expected output, not standard error of "/opt/sandbox50/bin/run.sh: line 31: 276..."
Here is the relevant code below.
void init(void)
{
//tells the program how many slots to create, partial credit to Craig Rodrigues for parts of the code
int slots = (d*d) - 1;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
board[i][j] = slots;
slots -= 1;
}
}
//Is the number of the respective tiles odd? If so, switch them
if (slots % 2 == 0)
{
int replacement = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = replacement;
}
}
Okay, it's also quite possible that the error is in draw, and not init. I'll update the code by showing my draw code, just in case you guys see anything.
void draw(void)
{
//Print the board, replacing the zero with a blank tile
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; i++)
{
if (board[i][j] == 0)
{
printf(" [] ");
}
else
{
printf("[%d]", board[i][j]);
}
printf("\n");
}
}
}
I'm going add one last thing here: https://sandbox.cs50.net/checks/cd3fae3fe2e44b6681be5a12e70ca53a
UPDATE: After some playing around with the program, I've found that this actually triggers a segmentation fault. I'm still unaware of how to fix this though, but hey, at least I found the reason for the error! (finally...)