简体   繁体   中英

What are the format specifiers I can use?

I'm using code::blocks with windows to program in c. Lately, I've hit a few problems trying to find out the addresses and values stored in the addresses of floats, long longs, etc. I've figured out that I need to use "I64d" instead of "lld". Is there a list of the format specifiers that I must use instead of the "normal" ones (eg "d", "ld", "lld", etc)? Thanks.

All the format specifiers are shown in the standard. The current C11 standard shows the "normal ones" in 7.20.6.1 The fprintf function .

However, there are also the "extra" integer types (such as uint16_t ) defined in stdint.h . The corresponding fprintf macros to use as format specifiers for those types are included in inttypes.h and detailed in the standard, 7.8.1 Macros for format specifiers .

An example would be:

int16_t val = 42;
printf ("val = %2" PRId16 "\n", val);

Keep in mind that there are also equivalents for the fscanf side of things as well, with the macros starting with SCN instead of PRI .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM