gpt4 book ai didi

c - 警告说数组赋值中指针和整数之间的比较

转载 作者:太空宇宙 更新时间:2023-11-04 08:42:56 24 4
gpt4 key购买 nike

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]="-";
}
}
}
}

我试图一个一个地遍历这个数组中的单元格。但是,对于涉及“playingfield[row][column]”的任何地方,它告诉我指针和整数之间的比较。还有一条警告说,Assignment Makes Integer from pointer without a cast。

最佳答案

字符串文字,如"#" 实际上是指向数组中第一个字符的指针。例如,你在做什么

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

正在将 charchar * 进行比较。

我认为您打算使用字 rune 字:

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

注意从双引号 " 到单引号 ' 的变化。


当你让它编译时,你有一个更糟糕的错误:看看 column 循环条件,它包括索引 8 ,这超出了数组的范围(它是数组中的第九个索引)。

关于c - 警告说数组赋值中指针和整数之间的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com