Format specifiers for uint8_t, uint16_t, …?

后端 未结 7 1502
执念已碎
执念已碎 2020-11-30 20:26

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\", &         


        
7条回答
  •  眼角桃花
    2020-11-30 21:28

    They are declared in 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.

提交回复
热议问题