Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c错误:赋值从指针生成整数而不进行转换[-Werror=int转换]_C - Fatal编程技术网

c错误:赋值从指针生成整数而不进行转换[-Werror=int转换]

c错误:赋值从指针生成整数而不进行转换[-Werror=int转换],c,C,当我试图编译代码时,我不断地遇到错误“赋值从指针生成整数而不使用强制转换[-Werror=int conversion]”。我不确定发生了什么,因为我检查了所有内容是否与变量类型int*匹配 int main(void) { int* sunkList, newSunkList; char*** shipArray; sunkList=createSunkList(nShips); newSunkList=updateSunkList(sunkList, sh

当我试图编译代码时,我不断地遇到错误“赋值从指针生成整数而不使用强制转换[-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*createSunkList(int-nShips);
{
int i;
int*result=(int*)malloc(sizeof(int)*nShips);
对于(i=0;i

    int* sunkList, newSunkList;
sunkList
声明为整数指针(
int*
),将
newSunkList
声明为普通
int
,因此警告:

warning: assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast [-Wint-conversion]
要修复此错误,应按如下方式声明两个变量:

int *sunkList, *newSunkList;
或:


int*sunkList,newSunkList;
sunkList
声明为整数指针,
newSunkList
声明为
int
int *sunkList;
int *newSunkList;