Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print an unsigned long int with printf in C? [duplicate]

Tags:

c

printf

Possible Duplicate:
How to printf “unsigned long” in C?

I have my number like so...

int unsigned long number = 600851475143;

I am trying to print it with printf(). Every time I try, I get a warning by the compiler.

I've tried %uld, %ld and Googling hasn't seemed to find me the answer.

I'm learning C, but have not had to use a long int before, so I'm not sure what I should be using.

What is the specifier I am chasing?

like image 899
alex Avatar asked Oct 27 '10 12:10

alex


People also ask

What is format specifier for unsigned long?

The correct specifier for unsigned long is %lu .

What is %lu in printf?

%lu. Unsigned int or unsigned long. %lli or %lld.

How do I printf a long double?

%Lf format specifier for long double %lf and %Lf plays different role in printf. So, we should use %Lf format specifier for printing a long double value.


1 Answers

I recommend using standard order (i.e. unsigned long int). %lu is the format tag you're looking for.

printf("%lu", 5ul);
like image 181
eq- Avatar answered Nov 01 '22 17:11

eq-