?
Solved

Printing "long long"

Posted on 2003-03-30
11
Medium Priority
?
178 Views
Last Modified: 2010-04-15
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
Comment
Question by:YoungJi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:Hermetic
ID: 8236657
not sure what a "long long" represents in your compiler, but you could try "%I64"
0
 
LVL 1

Expert Comment

by:Hermetic
ID: 8236663
sorry, I missed a character "%I64d".
0
 

Author Comment

by:YoungJi
ID: 8236744
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Expert Comment

by:Mayank S
ID: 8236884
long long ?? Was that ever allowed?
0
 

Author Comment

by:YoungJi
ID: 8236944
yes
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 300 total points
ID: 8237030
Hi YoungJi,

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

should work both.

hope that helps,

ZOPPO
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8237055
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
 

Author Comment

by:YoungJi
ID: 8237090
Perfect! =)
On a side note, "%llud" will print the unsigned value.


And "%lD" does NOT work.
0
 
LVL 15

Expert Comment

by:efn
ID: 8237095
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8237099
I didn't try it on my compiler.... anyways, you can check out the site.... it says that it should.

Cheers,

Mayank.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question