2

I've read several articles on this topic, but some say that the way it should be done depends on the architecture and system you're in (Windows/Linux), so is there a proper way to do this platform independent?

C. P.
  • 41
  • 1
  • 1
  • 6

1 Answers1

9

%zu for size_t, with

  • %z for length, and
  • %u for unsigned

Details can be found at

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.

Community
  • 1
  • 1
artm
  • 17,291
  • 6
  • 38
  • 54