[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

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.
0
YoungJi
Asked:
YoungJi
  • 4
  • 3
  • 2
  • +2
1 Solution
 
HermeticCommented:
not sure what a "long long" represents in your compiler, but you could try "%I64"
0
 
HermeticCommented:
sorry, I missed a character "%I64d".
0
 
YoungJiAuthor Commented:
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?
0
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

 
Mayank SAssociate Director - Product EngineeringCommented:
long long ?? Was that ever allowed?
0
 
YoungJiAuthor Commented:
yes
0
 
ZoppoCommented:
Hi YoungJi,

try printf( "%Ld", number ); or printf( "%lld", number );

should work both.

hope that helps,

ZOPPO
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
YoungJiAuthor Commented:
Perfect! =)
On a side note, "%llud" will print the unsigned value.


And "%lD" does NOT work.
0
 
efnCommented:
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
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I didn't try it on my compiler.... anyways, you can check out the site.... it says that it should.

Cheers,

Mayank.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now