我試圖通過值傳遞一個數組,或者更確切地說是一個指向函數BinaryToHex的數組的指針。但是,我始終得到錯誤「功能BinaryToHex相沖突的類型」。將數組傳遞給函數時出錯
這是程序的相關部分。
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);
}
可能重複的http://stackoverflow.com/questions/1549631/getting-conflicting-types-for-function-in-c-why – Downvoter 2015-04-02 07:58:11