0


我在不同的文件上有这个主要功能和另外 2 个功能

/*decleration of the functions on one file*/
typedef double *mat[4][4];
void catcher(void *,mat *);
void findMat(mat *,char *,int *);
int main()
{
mat MAT_A={0};
mat MAT_B={0};
mat MAT_C={0};
mat MAT_D={0};
mat MAT_E={0};
mat MAT_F={0};
mat *matArray[6]={&MAT_A,&MAT_B,&MAT_C,&MAT_D,&MAT_E,&MAT_F};
void (*funcArray[5])(mat)={read_mat,print_mat,add_mat,sub_mat,mul_mat,mul_scalar,trans_mat,stop};
catcher(&funcArray,&matArray);

return 1;
}
/*same file as main function*/
void catcher(void *funcArray,mat *matArray){
    char *command[256];
    char *funcName[11];/*size of the longest function name*/
    char *matName1[6],*matName2[6],*matName3[6];
    char *matNames[3]={&matName1,&matName2,&matName3};
    int *numLoc[3]={0};
    int i,k,j=0;
    double *numbers[16]={0};
    printf("Please insert a command\n");
    fgets(command,sizeof(command),stdin);/*reads a string for command*/
    puts(command);
    
    for(i=0;command[i]!=" ";i++){/*gets the name of the function the user wants to run*/
        /*if(command[i]!=" "){*/
            funcName[j]=command[i];
            j++;
        /*}*/
    }
    funcName[j]="\0";
    
    if(funcName=="read_mat"){
        matNameReader(&funcName,i,&command,&matNames);
        numReader(i,&command,&numbers);
        findMat(&matArray,&matNames,&numLoc);
        read_mat(&matNames[*numLoc[1]],&numbers);
        catch(&funcArray,&matArray);
    }
}
/*diffrent file with all other functions*/
void findMat(mat *matArray[6],char *matNames[3],int *numLoc[3])
{
    int i,j=0;
    for (i=0;i<6;i++){
        if(*matNames[j]==*matArray[i]){
            *numLoc[j]=i;
            j++;
        }
    }
}

当我尝试运行代码时出现此错误

错误:'findMat' 的类型冲突 void findMat(mat *matArray[6],char *matNames[3],int *"

我看了一个小时的代码,我看不出有什么冲突的类型。

请帮助我了解这里出了什么问题

4

1 回答 1

0

的声明findMat

无效 findMat(mat *,char *,int *);

定义:

无效 findMat(mat *matArray[6],char *matNames[3],int *numLoc[3])

参数类型显然一样。

mat *matArray是“指向垫子的指针”,mat *matArray[6]是“指向垫子的指针”(因为数组不能是函数参数,它们会自动衰减到指针)

您可以在声明定义中执行void findMat(mat *matArray, char *matNames, int *numLoc)void findMat(mat matArray[], char matNames[], int numLoc[])获取相同的类型。

于 2020-12-23T21:47:11.603 回答