SYM2RR
SYM2RR

Reputation: 31

Warning says comparison between pointer and integer in array assignment

char playingfield[4][8] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
void dropbomb(void)
{
    int row = 3 , column = 0;
    for(row;row>=0;row--)
    {
        for(column; column<=8;column++)
        {
            if(playingfield[row][column] == "#")
            {
                playingfield[row][column] = "$";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
            }
            else if(playingfield[row][column] =="$")
            {
                playingfield[row][column] = " ";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="*";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]=".";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]=",";
                }
            }
            else if(playingfield[row][column]==",")
                stage = "finished";
            else if(playingfield[row][column]=="%")
            {
                playingfield[row][column] = "&";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
            }
            else if (playingfield[row][column]=="&")
            {
                playingfield[row][column] = " ";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="+";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]="/";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]="-";
                }
            }
            else if (playingfield [row][column]=="*")
            {
                playingfield[row][column] = "$";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="*";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]=".";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]=",";
                }
            }
            else if (playingfield[row][column]=="+")
            {
                playingfield[row][column] = "&";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="*";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]=".";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]=",";
                }
            }
            else if(playingfield[row][column] == "-")
            {
                score=score+1;
                playingfield[row][column] == "'";
            }
            else if (playingfield[row][column] == ".")
            {
                playingfield[row][column] = "$";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {
                if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="+";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]="/";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]="-";
                }
            }
            else if (playingfield[row][column] == "/")
            {
                playingfield[row][column] = "&";
                OledSetCursor(column,row);
                OledPutChar(playingfield[row][column]);
                if(row<3)
                {
                if(playingfield[row+1][column]=="$")
                    playingfield[row+1][column]="+";
                else if(playingfield[row+1][column]=="&")
                    playingfield[row+1][column]="/";
                else if (playingfield[row+1][column]=="'")
                    playingfield[row+1][column]="-";
                }
            }
        }
    }

I was trying to go through the cells in this array one by one. However, for anywhere that "playingfield[row][column]" is involved, it told me that comparison between pointer and integer. Also a warning says that Assignment Makes Integer from pointer without a cast.

Upvotes: 0

Views: 313

Answers (2)

Wojtek Surowka
Wojtek Surowka

Reputation: 20993

Change your string literals in double quotes like "$" to character literals in single quotes '$'.

Upvotes: 0

Some programmer dude
Some programmer dude

Reputation: 409176

String literals, like "#" is actually a pointer to the first character in an array. What you are doing in e.g.

playingfield[row][column] == "#")

is comparing a char with a char *.

I think you meant to use character literals:

playingfield[row][column] == '#')

Note the change from double-quote " to single-quote '.


When you get this to compile, you have a worse error though: Look at the column loop condition, it includes the index 8, which is beyond the bounds of the arrays (it's the ninth index in the array).

Upvotes: 2

Related Questions