I have to write a slide puzzle program for class. I have the program finished and working except that I can not get the blank space to print out. I wrote code that would find the number I used for the blank space. I have the puzzle print out using two for loops, then before the line that prints it I used an IF statement to find the number. I have tried using a break statement, but it does not finish the rest of the for loop for the columns. I also tried to have it print then used the backspace in an attempt to delete it. When I do that and swap the blank space with the number on the left a few times it distorts the puzzle. I tried to advance the column when it finds the number I want to skip but can not get the numbers to move around. We are getting into to pointers on the next lesson so I know I can not use them. I tried to change the array to character but that did not work either. When I leave the number in that I used for a blank space, which is 100, the program works great.
Expand|Select|Wrap|Line Numbers
- void print(){
- printf("\n");
- int i=0;int j=0;
- for (i=0;i<4;i++){
- for (j=0;j<4;j++){
- puzzle[i][j];
- if (puzzle[i][j]==100)
- j=j+1; /*This was the last attempt.*/
- printf("%d\t", puzzle[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- }
Thank you for taking a look.