I'm working on my 'draw' function. I'm managing to print the array yet for some reason, it's printing it in one long line as opposed to a grid.
Here is my code:
void init(void)
{
// initilizes array
int total = d * d;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
board[i][j] = --total;
}
}
// Swap 2 and 1 if even number of spaces
if(total % 2 == 0)
{
int temp = board[d-1][d-2];
board[d-1][d-2] = board[d-1][d-3];
board[d-1][d-3] = temp;
}
}
void draw(void)
{
// TODO
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if(board[i][j] == 0)
{
printf(" ");
}
else
{
printf("%2d ", board[i][j]);
}
printf("\n");
}
}
Any idea? I would've thought that after I've the iterated through inner loop of 'draw' and added new line that it would print out correctly.
Instead, I just get them printed in one long column.
Any suggestions please?