我有以下代碼將 的值寫入time緩沖區temp。
#include<stdio.h>
int main() {
unsigned char temp[8];
unsigned int time = 0x00101010;
sprintf(temp, "%x", time);
}
temp和都是time無符號值;但是,我仍然收到以下警告:
Pointer targets in passing argument 1 of ‘sprintf’ differ in signedness
有人可以解釋為什么我收到此警告以及如何洗掉它嗎?
uj5u.com熱心網友回復:
要么做:
#include<stdio.h>
int main() {
char temp[8];
unsigned int time = 0x00101010;
sprintf(temp, "%x", time);
}
或者
#include<stdio.h>
int main() {
unsigned char temp[8];
unsigned int time = 0x00101010;
sprintf((char*) &temp, "%x", time);
}
sprintf 定義為sprintf(char*, const char*, ...),因此第一個引數需要是有符號字符指標。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524599.html
標籤:C打印警告未签名
上一篇:指標值遞增究竟是如何作業的?
