I am working on the move function for pset3. I was having trouble matching the tile value to the board value, so I am now using print to make sure the correct value is coming up when I type board[i][j], which you can see after the word "TEST". You can see what I've written here:

bool move(int tile)
int board[d][d];
for (int i = 0; i < d; i++)
    for (int j = 0; j < d; j++)
        printf("TEST: %i ", board[i][j]);
        if (tile == board[i][j])
            printf("FOUND IT: %i %i\n", i, j);
            return true;
return false;

With the code I've written, I would expect each value from the board to print. Rather than the board values showing up, I see long, random numbers, such as:

TEST: 10 TEST: 0 TEST: 27602960 TEST: 0 TEST: 2 TEST: 0 TEST: -730284032 TEST: 32618 TEST: -792540512

Why am I getting these long numbers? How can I ensure that the board values appear as they do with my draw function? Thank you.

1 Answer 1


Delete this: int board[d][d];

The reason is that board has already been declared globally int board[DIM_MAX][DIM_MAX] and filled with values by init(). Int board[d][d] declares new, local variable and computer allocates memory for it in stack. This memory is filled with some junk that you print.

  • Thanks for the suggestion. It got rid of the long numbers, but then this was the output instead: TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 TEST: 0 Do you know why it's not populating with the values from the initiated board? My init and draw functions are both working properly. Please let me know if it would be helpful for me to share these functions as well. Thank you!
    – melbez
    Commented Jul 15, 2017 at 21:20
  • No idea. What is in log.txt?
    – obesman
    Commented Jul 15, 2017 at 21:34
  • It works now! The issue was that I had also declared int board[d][d] in both the init and draw functions, even though I hadn't needed to for the exact reason that you explained above. Thank you so much!!!
    – melbez
    Commented Jul 15, 2017 at 21:46

You must log in to answer this question.

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