-2

I want to print size_t type data in C but wasn't able to print it. I am trying to print it by using %d specifier but I got following error:

warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’

  • 2
    Why have you tagged this question `java` if you're actually writing in C? Additionally, please show your code rather than just describing it. – Jon Skeet Aug 09 '15 at 19:09
  • Welcome to SO. Please search the site before asking. This already has an answer here: [How should I print types like off\_t and size\_t?](http://stackoverflow.com/questions/586928/how-should-i-print-types-like-off-t-and-size-t) – Jens Gustedt Aug 09 '15 at 21:04

1 Answers1

2

In order to print the size_t variable, use the %zu modifier instead of %d.

  • z tells that the argument size is equal to size_t size.
  • u stands for unsigned.

If you are working with the Microsoft compiler, use the %Iu modifier instead.

kefir500
  • 3,551
  • 6
  • 34
  • 41
  • 1
    Notice that the `z` size modifier is only available from C99. I'm not sure if Microsoft's crappy libc has it. – fuz Aug 09 '15 at 20:42