I have not been able to draw the board properly. Whenever i run the code

~/workspace/pset3/fifteen/ $ ./fifteen 4
15 14 13 12 
11 0 0 4196528 
0 0 -186283616 32766 
48 -186283632 32766 -186283824 
Tile to move: 

Here is my draw function : https://gist.github.com/bf36b2cc5d55efa1e1010da457eee677

and my init function : https://gist.github.com/86bdd4c778dc8001ea475b63cb91a79b

Any help would be much appreciated!!

1 Answer 1


The board[][] array is a global variable. In both functions, the code is creating a shadow array called board[][].

int board[DIM_MAX][DIM_MAX];

By redeclaring the board array in each function, it is creating a local array that takes precedence, hiding the global array. This is not the same array as the global array. Once the function ends, the local array no longer exists and the global array is once again present and available for use. You need to use the global array, not a local shadow.

My best guess as to why you are getting partial success is that the two functions just happen to be using some or all of the same memory for the shadow arrays, but intermediate processing is also briefly using some of that memory, changing the contents. But this is just an educated guess. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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