我需要读取(使用
sscanf
)适合uint32_t
的整数。该数字以十六进制给出。我应该使用什么格式来读取和打印这样的数字?
头文件中有特殊宏
inttypes.h
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
int main(void)
{
uint32_t x;
if(scanf("%" SCNx32, &x) == 1)
{
printf("Scanned successfully. The value is %" PRIx32 "\n", x);
}
else
{
printf("Scanf error\n", x);
}
}