C 中 sscanf 中数字的格式

问题描述 投票:0回答:1

我需要读取(使用

sscanf
)适合
uint32_t
的整数。该数字以十六进制给出。我应该使用什么格式来读取和打印这样的数字?

c scanf
1个回答
1
投票

头文件中有特殊宏

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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.