uint8_t,uint16_t,...的格式说明符? [英] Format specifiers for uint8_t, uint16_t, ...?
问题描述
如果我有一个整数变量,我可以使用 sscanf
,如下所示使用格式说明符%d。
sscanf(line,整数值:%d \\\
,& my_integer);
我在哪里可以找到 uint8_t
的格式说明符, , uint16_t
, uint32_t
和 uint64_t
?
uint64_t可能有%lu。
c>< inttypes.h> 作为宏:SCNd8,SCNd16,SCNd32和SCNd64。
示例(对于int32_t):
sscanf(行,整数值:%SCNd32\\\
,& my_integer);它们的格式是PRI(对于printf)/ SCN(对于扫描),然后是o,u,x, X d,i为相应的说明符,然后没有,LEAST,FAST,MAX然后大小(显然没有MAX的大小)。一些其他示例:PRIo8,PRIuMAX,SCNoFAST16。
编辑:BTW a 相关问题问为什么使用这种方法。您可能会发现这些答案很有趣。
If I have an integer variable I can use sscanf
as shown below by using the format specifier %d.
sscanf (line, "Value of integer: %d\n", &my_integer);
Where can I find format specifiers for uint8_t
, uint16_t
, uint32_t
and uint64_t
?
uint64_t has probably %lu.
解决方案 They are declared in <inttypes.h>
as macros: SCNd8, SCNd16, SCNd32 and SCNd64.
Example (for int32_t):
sscanf (line, "Value of integer: %" SCNd32 "\n", &my_integer);
Their format is PRI (for printf)/SCN (for scan) then o, u, x, X d, i for the corresponding specifier then nothing, LEAST, FAST, MAX then the size (obviously there is no size for MAX). Some other examples: PRIo8, PRIuMAX, SCNoFAST16.
Edit: BTW a related question asked why that method was used. You may find the answers interesting.
这篇关于uint8_t,uint16_t,...的格式说明符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!