bodacydo bodacydo - 1 year ago 94
C Question

How to printf "unsigned long" in C?

I can never understand how to print

unsigned long
datatype in C.

is an
unsigned long
, then I try:

  • printf("%lu\n", unsigned_foo)

  • printf("%du\n", unsigned_foo)

  • printf("%ud\n", unsigned_foo)

  • printf("%ll\n", unsigned_foo)

  • printf("%ld\n", unsigned_foo)

  • printf("%dl\n", unsigned_foo)

And all of them print some kind of
number instead of
unsigned long
that I have.

Answer Source

%lu is the correct format for unsigned long. Sounds like there are other issues at play here, such as memory corruption or an uninitialized variable. Perhaps show us a larger picture?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download