简体   繁体   中英

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.

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

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).

用双引号(如"$"将字符串文字更改为单引号'$'字符文字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM