我想做一个函数,将无符号字符转换为无符号整型并将其存储到数组中。但是,这最终会出现一个错误,说将无符号字符(数组)转换为无符号整数(数组)
将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)应该会有所帮助。 –