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.
*/
define _XOPEN_SOURCE 500
include
include
include
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");
}
} `