1

I am stuck on the move part of fifteen and trying to learn how to use GDB. My thought process for moving is to search for the "tile" and if the tile is adjacent to the "_" then switch. during GDB, i would like to print out the grid number it is currently on but why if i type " P Grid", it would result in 0x7ffffffffddb0? Thanks in advance.

bool move(int tile)
{
int grid[d][d];
int blank = 0;
for (int row = 0; row < d; row++)

    {
        for (int column = 0; column <d; column++)

            {
                if (grid[row][column] == tile)
                    {
                        if (grid[row+1][column] == blank)
                            {

                                int temp = grid[row+1][column];
                                grid[row+1][column] = grid[row][column];
                                grid[row][column] = temp;
                            }
                        else
                        return false;
                    }

            }


    }

1 Answer 1

0

Instead of

p grid

try this:

p *grid@d

The staff code declares d as a global int, so you should be able to use it anywhere.

But in general the command is

For any array array of size size:

p *array@size

ADDITIONAL INFORMATION

I was reading the answer to this question and I think you might be interested in using your own draw() function. You could make a duplicate to receive a 2d array and call it during your debugging on gdb. I tried mine as it is like this, and it works pretty neatly:

call draw()
2
  • that command still gets me the same result Nov 17, 2016 at 3:10
  • trying to dgb my code, i can see main (argc=2, argv=0x7fffffffdf68) at fifteen.c:123 123 printf("\nIllegal move.\n");............how can i view what argv=0x7fffffffdf68 stands for? Nov 17, 2016 at 4:04

You must log in to answer this question.

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