Link to home
Start Free TrialLog in
Avatar of YoungJi
YoungJi

asked on

Printing "long long"

How do I output the type "long long" to stdout?

i.e.
I have,

     long long number;

and I want to call

   printf("???", number);

so that the decimal value of long long is printed. How?

Thanks so much in advance.
Avatar of Hermetic
Hermetic

not sure what a "long long" represents in your compiler, but you could try "%I64"
sorry, I missed a character "%I64d".
Avatar of YoungJi

ASKER

ummm... that just prints I64d.
And using "%i64d" gives 064d.

I'm dealing with numbers that could be as big as 2^64-1, so I need unsigned long long. Could there be an easier approach?
Avatar of Mayank S
long long ?? Was that ever allowed?
Avatar of YoungJi

ASKER

yes
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, Found it:

Use %lD (note that the 'l' is small and the 'D' is in caps).

You can refer to:

http://www.delorie.com/djgpp/doc/libc/libc_628.html

Its got a list of some 100 conversion characters.

Mayank.
Avatar of YoungJi

ASKER

Perfect! =)
On a side note, "%llud" will print the unsigned value.


And "%lD" does NOT work.
According to the 1999 C standard, it should be the second form Zoppo showed, "%lld".  However, if your particular compiler does not conform to the standard in this detail, that form may not work and one of the other suggestions may.

--efn
I didn't try it on my compiler.... anyways, you can check out the site.... it says that it should.

Cheers,

Mayank.