[英]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.
但是,对于涉及“playfield [row] [column]”的任何地方,它告诉我指针和整数之间的比较。 Also a warning says that Assignment Makes Integer from pointer without a cast.
另外一个警告说,Assignment使指针从没有强制转换的指针生成。
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 *
. 将
char
与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). 当你编译它时,你会遇到更糟糕的错误:查看
column
循环条件,它包括索引8
,它超出了数组的范围(它是数组中的第九个索引)。
用双引号(如"$"
将字符串文字更改为单引号'$'
字符文字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.