scanf 和 printf size_t 变量的正确方法(平台无关)

Proper way to scanf and printf a size_t variable (platform independent)

我已经阅读了几篇关于这个主题的文章,但有些人说它应该完成的方式取决于你所处的体系结构和系统(Windows/Linux),那么有没有合适的方法来这个平台独立吗?

%zu size_t

  • %z 长度,
  • %u 无符号

详情请见

7.21.6.1 The fprintf function

6 The flag characters and their meanings are:

...

z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.