I am working on "Move" of exercise Fifteen in PSET3 of CS50.

I am unsure about how to keep track of the blank space. I have tried to add the row and column number of the initial blank space as a global variable, as was suggested on this forum.

Like so:

// board
int board[DIM_MAX][DIM_MAX];
int blank_row = d-1;
int blank_column = d-1;

When I do this, I get the error "initializer element is not a compile-time constant".

When I changed my program, and added the same lines after init() instead, I got the error "unused variable".

When I add it to the move function itself, the problem is that it reset the blank space to initial position every time the function is called.

How to go about this?

Help is greatly appreciated!

1 Answer 1


A little bit of both :). You need to declare them globally (ie "before" main) so they can be accessed in the various functions. But you cannot set them to d - 1 because d has no value yet (thus the "compile-time constant") error.

You need to set them to the initial values (ie d - 1) in main (or perhaps init). Then set them to the current values in the move function.

You must log in to answer this question.

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