0


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

Roy Shiff
  • 63
  • 7
  • Sure you want that `*` in `typedef double *mat[4][4];`? – chux - Reinstate Monica Dec 22 '20 at 15:09
  • 1
    `char *command[256]; fgets(command,sizeof(command),stdin);` should generate a warning too. Roy, recommend to enable all warnings in your compiler. – chux - Reinstate Monica Dec 22 '20 at 15:11
  • 1
    `void findMat(mat *,char *,int *);` is not `void findMat(mat *[6],char *[3],int *[3]);` as in `void findMat(mat *matArray[6],char *matNames[3],int *numLoc[3])`. Why would you ever write `typedef double *mat[4][4];` and then `mat *matArray[6]`? Do you know what `matArray` represent? – KamilCuk Dec 22 '20 at 15:17
  • `*numLoc[j]=i` is invalid - `numLoc[j]` is `NULL` . – KamilCuk Dec 22 '20 at 15:20
  • matArray should be a pointer array for 6 matrices, unless i wrote it incorrectly – Roy Shiff Dec 22 '20 at 15:21
  • What is `mat` then? An 4x4 2d array of pointers to double? Why so many pointers? Where are _the actual double values_ stored? Sorry, but half of the code and the usage of pointers is just invalid. Go through _all the warnings_ and fix them, one by one. Ex. what do you think `command[i]!=" "` does? And no, it doesn't check if `command[i]` is equal to a space. – KamilCuk Dec 22 '20 at 15:21
  • at the start the 2d arrays are filled with zeros, in the function catcher the user insert a command which will look like this :read_mat MAT_A, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6 the numbers in the string will be at the end the numbers which fills the matrices its a work for school and i just couldn't think of a way to do it with all the function i need to build without pointer arrays – Roy Shiff Dec 22 '20 at 15:24
  • 1
    There are far too many arrays of pointers and arrays of pointers to pointers in your code, and you do not appear to be using any of them correctly. For example, why is `command` an array of pointers rather than an array of `char`? Why is `funcName` an array of pointers rather than an array of `char`? Why is `mat` a 4x4 array of pointers rather than a 4x4 array of `double`? Etc. Etc. – Ian Abbott Dec 22 '20 at 15:43

1 Answers1

0

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.

koder
  • 2,038
  • 7
  • 10