I have been working on this program more than a week and even started once again from the beginning. I created init() function and draw() function in a separate file (they both are in main function there) and they work perfectly there, but when I put them in fifteen.c the array won't initialize (all values are 0) and it prints out underscore because of the condition in my draw() function. I just don't understand what changes, why it works in my original file and not in fifteen.c file.
here's the link to the fifteen.c https://gist.github.com/anatkachen/7d6b1695a95fe52b4d679fd3a51fec18
here's my code from original file
int main (int argc, string argv[])
{
if (argc != 2)
{
printf("Command-lineargument is not valid. Rerun the program. Type in the key.\n");
return 1;
}
if (argv[1] == NULL)
{
printf("error");
return 2;
}
int d = atoi (argv[1]);
if( d < 3 || d > 9 )
{
printf ("the number is wrong");
}
int tilevalue = d*d - 1;
int board [d][d];
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
// printing __ instead of 0 for the last tile
if ( j == d - 1 && i == d - 1)
{
board[i][j] = 0;
}
// switching 1 and 2 for even user imput
else if ( i == d - 1 && j == d - 3)
{
if (d % 2 == 0)
{
board[i][j] = 1;
}
else
{
board[i][j] = tilevalue;
tilevalue = tilevalue - 1;
}
}
else if ( i == d - 1 && j == d - 2)
{
if (d % 2 == 0)
{
board[i][j] = 2;
}
else
{
board[i][j] = tilevalue;
tilevalue = tilevalue - 1;
}
}
//setting value to tiles and printing them out
else
{
board[i][j] = tilevalue;
tilevalue = tilevalue - 1;
}
}
}
printf("\n");
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] == 0)
{
printf (" _ ");
}
else
{
printf ("%2i ", board[i][j]);
}
}
printf("\n");
}
return 0;
}