【发布时间】:2020-05-17 12:37:19
【问题描述】:
当我尝试编译我的代码时,我不断收到错误“赋值从指针中生成整数而没有强制转换 [-Werror=int-conversion]”。我不确定发生了什么,因为我已经检查过所有内容都与变量类型 int* 匹配。
int main(void) {
int* sunkList, newSunkList;
char*** shipArray;
sunkList=createSunkList(nShips);
newSunkList=updateSunkList(sunkList, shipArray);
return 0;
}
newSunkList=updateSunkList(sunkList, shipArray) 是错误所在。
int* createSunkList(int nShips);
{
int i;
int* result=(int*)malloc(sizeof(int)*nShips);
for(i=0;i<nShips;i++)
result[i]=1;
return result;
}
int* updateSunkList(int* sunkList, char*** shipArray)
{
char** temp;
int i,j,k,a=0;
for(k=0;k<nShips;k++)
{
temp=shipArray[k];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(temp[i][j] = 'S')
a=1; /* If 'S' is found then a turns to 1 */
}
}
if(a==0) /* If a==0 then no 'S' has been found so the ship has sunk */
sunkList[k]=0;
}
return sunkList;
}
【问题讨论】:
-
int* sunkList, newSunkList;将声明sunkList为整数指针,将newSunkList声明为int
标签: c