# Swapping 1 and 2 in fifteen.c

I made the init function in a different tab so I can check it, and it won't switch 1 and 2. My code is ```/** * fifteen.c * * Implements Game of Fifteen (generalized to d x d). * * Usage: fifteen d * * whereby the board's dimensions are to be d x d, * where d must be in [DIM_MIN,DIM_MAX] * * Note that usleep is obsolete, but it offers more granularity than * sleep and is simpler to use than nanosleep;```man usleep` for more. */

# include

int main(int argc, string argv[]) { if (argc == 2) {

``````int d = atoi(argv[1]);
//printf("%i\n", d);
int stnumber = d * d - 1;
//printf("%i\n", stnumber);

while (stnumber >= 0) {
printf(" ");
if (stnumber % d == 0) {
if (stnumber > 9) {
printf("%i ", stnumber);
printf("\n\n");
}
else {
printf("%i  ", stnumber);
printf("\n\n");
}
}

else {
if (stnumber > 9) {

printf("%i ", stnumber);
}
else {
if (d % 2 == 0) {
if (stnumber == 2) {
stnumber--;
}
else if (stnumber == 1) {
stnumber++;
}
}
printf("%i  ", stnumber);
}
}
stnumber--;
}
printf("\n");
}
``````

} `

Your `init` function should not be printing anything. It should be filling the `board` array with the numbers, such that, in a 3x3 game, the top left of the board `board[0][0]` is set to 8 and it counts down from there. You will probably find a loop helpful.
The `draw` function will then print the array to the screen.
• `board[i][j] = num;` (not `int num`). Commented Jul 24, 2017 at 9:23