confilicting types in C

78 Views Asked by At


i have this main and 2 more functions each on different file

/*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++;
        }
    }
}

when i try to run the code i get this error

error: conflicting types for ‘findMat’ void findMat(mat *matArray[6],char *matNames[3],int * "

i looked at the code for an hour and i can't see what are the conflicting types.

please help me understand what is wrong here

1

There are 1 best solutions below

0
On

The declaration of findMat:

void findMat(mat *,char *,int *);

The definition:

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

The parameter types are clearly not the same.

mat *matArray is a "pointer to mat", mat *matArray[6] is a "pointer to a pointer to mat" (as arrays can not be function parameters they decay to a pointer automatically)

You could do void findMat(mat *matArray, char *matNames, int *numLoc) or void findMat(mat matArray[], char matNames[], int numLoc[]) to get the same types in the declaration and the definition.