0

I'm trying to pass by value an array, or rather a pointer to an array to the function BinaryToHex. However I consistently get the error "conflicting types for function BinaryToHex".

Here is the relevant portion of the program.

char *ConvertCodeToHex(char code[16])     
{                  
    char nibble[4];   
    char hexvalue[4];   
    int i;int j,k = 0;      

    for(i=0; code[i] != '\0'; i++)      
       {   
          if((i+5)%4 == 0)           
            {   
                nibble[j] = '\0';
                j = 0;              
                hexvalue[k] = BinaryToHex(nibble);
                k++;
            }
            nibble[j] = code[i];
            j++;
       }
    strncpy(finalhex, hexvalue, 4); //finalhex is a global character array
    return finalhex;
}
char BinaryToHex(char b[4])       //The error is caught in this line of code.
{
    int temp = 0,i; char buffer;
    for(i=4; i >= 0; i-- )   
        {
            int k = b[i]-='0';
            temp +=  k*pow(2,i);
        }
//Converting decimal to hex.
    if (temp == 10)
        return 'A';
    else if (temp == 11)
        return 'B';
    else if (temp == 12)
        return 'C';
    else if (temp == 13)
        return 'D';
    else if (temp == 14)
        return 'E';
    else if (temp == 15)
        return 'F';
    else
        return (char)(((int)'0')+ temp);

}
Nikhil Prabhu
  • 1,072
  • 3
  • 12
  • 24
  • Probably duplicate of http://stackoverflow.com/questions/1549631/getting-conflicting-types-for-function-in-c-why – cadaniluk Apr 02 '15 at 07:58

3 Answers3

0

You need to add a function forward declaration as char BinaryToHex(char b[4]); before ConvertCodeToHex(). Otherwise, when BinaryToHex() is called from ConvertCodeToHex(), you compilar won't be knowing the function description.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

You need function declaration before you call it, so put additional row on the top e.g.

char BinaryToHex(char b[4]);
char *ConvertCodeToHex(char code[16])     
{                  
    char nibble[4];   
    char hexvalue[4];   
    int i;int j,k = 0;      

    for(i=0; code[i] != '\0'; i++)      
       {   
          if((i+5)%4 == 0)           
            {   
                nibble[j] = '\0';
                j = 0;              
                hexvalue[k] = BinaryToHex(nibble);
                k++;
            }
            nibble[j] = code[i];
            j++;
       }
    strncpy(finalhex, hexvalue, 4); //finalhex is a global character array
    return finalhex;
}    
gregjer
  • 2,823
  • 2
  • 19
  • 18
0

You don't need to pass the array index in the function definition. Just simply write char BinaryToHex(char b[]). Check out it will work.

anuJ
  • 1
  • 1