1

I'm trying to make draw function but i can't seem to have values which i have done in init() function. When i compile and run the program i have zeros all over the display. Can anyone address me please whats going wrong here ?

The Init Function

void init(void)
{

int fill = d*d-1;

int size = d;

int board[d][d];

for(int i = 0; i < size; i ++)
{
    for(int j = 0; j < size; j++)
    {
        board[i][j] = fill;
        printf("%d ",board[i][j]);
        fill--;
    }
}

if(d%2 == 0)
{
int temp;
    temp = board[d-1][d-1];
    board[d-1][d-1]=board[d-2][d-2];
    board[d-2][d-2] = temp; 
}      
}



The Draw Function

void draw(void)
{
  int board[d][d];
  for(int i = 0; i < d; i++)
  {
    for(int j = 0; j < d; j++)
    {
            if(board[i][j]==0)
            {
                printf("_ ");
            }
            else
            {
                printf("%d",board[i][j]);
            }
    }
    printf("\n");
  }
}
2

I just tested your code and got it working with a couple minor tweaks. My advice is to go look back at your global variables. Something you have in both those functions has been declared earlier in order to be accessible across all the fifteen.c functions. It's part of the distribution code.

Also, on an aesthetic level, and this is only a suggestion, it looks really clean to have tabs between numbers when you call draw(). Totally optional, but it's worth looking into to see how to implement that. It's much easier to see all the numbers that way, especially when you get the bigger boards.

2
  • yea i have discovered that, thanks for your reply anyway now i'm looking forward to make Move function Feb 10 '16 at 17:52
  • Awesome! You are welcome. Happy to help. If this question is now resolved, please check the answer. Thanks!
    – Peter
    Feb 10 '16 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .