我想做一個函數,將無符號字符轉換爲無符號整型並將其存儲到數組中。但是,這最終會出現一個錯誤,說將無符號字符(數組)轉換爲無符號整數(數組)
將sprintf的參數1從不兼容的指針類型中傳遞。
int main(void) {
unsigned char key[16] = "1234567812345678";
phex(key, 16); //store into an array here
}
uint64_t* phex(unsigned char* string, long len)
{
uint64_t hex[len];
int count = 0;
for(int i = 0; i < len; ++i) {
count = i * 2;
sprintf(hex + count, "%.2x", string[i]);
}
for(int i = 0; i < 32; i++)
printf(hex[i]);
return hex;
}
你想16個整數元素的數組,每個元素只保存一個數字嗎? – Rorschach
'sprintf'將整數轉換爲字符表示,而不是其他方式 –
A [*** *** sprintf'和'printf'的很好參考](http://en.cppreference.com/w/ c/io/fprintf)應該會有所幫助。 –