convert long long integer to string using sprintf
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > convert long long integer to string using sprintf




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    convert long long integer to string using sprintf  
wenmang@yahoo.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:21 AM

what is format for sprintf to convert long long integer (64 bits) to
string?






[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:21 AM

wenmang@yahoo.com writes:

> what is format for sprintf to convert long long integer (64 bits) to
> string?

The format for "long long" is %lld (or %llx etc.).  Keep in mind
though, that a long long is not necessarily 64 bits.  If you
specifically need 64 bits, use the types defined in stdint.h and the
format macros in inttypes.h.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Joe Wright


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:21 AM

wenmang@yahoo.com wrote:
> what is format for sprintf to convert long long integer (64 bits) to
> string?
>
You could look it up? If int is %d and long is %ld could it be %lld ?
Just guessing. I haven't looked it up.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Keith Thompson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 12:21 AM

Måns Rullgård <mru@inprovide.com> writes:
> wenmang@yahoo.com writes: 
>
> The format for "long long" is %lld (or %llx etc.).  Keep in mind
> though, that a long long is not necessarily 64 bits.  If you
> specifically need 64 bits, use the types defined in stdint.h and the
> format macros in inttypes.h.

And keep in mind that your runtime library's version of sprintf()
might not support "%lld".  Mismatches between a compiler and the
runtime library it uses (for example, where the compiler supports
"long long", but sprintf() doesn't) are not uncommon.

Some older versions of sprintf() *might* use "%Ld" rather than "%lld".

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Skarmander


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 06:24 PM

Joe Wright wrote:
> wenmang@yahoo.com wrote: 
> You could look it up? If int is %d and long is %ld could it be %lld ?
> Just guessing. I haven't looked it up.
>
Hmm, and since %f is used to printf() a double, I can use %f to scanf() a
double, right?

Looking it up (or, indeed, asking in an ng) nearly always beats trying the
obvious if the language wasn't specifically designed to accommodate that. C
definitely isn't.

S.





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-14-06 06:24 PM

Skarmander <invalid@dontmailme.com> writes:

> Joe Wright wrote: 
> Hmm, and since %f is used to printf() a double, I can use %f to
> scanf() a double, right?

Wrong.  With scanf %f denotes a float, and %lf denotes a double.  This
difference is because the arguments to printf are subject to type
promotion, so any float arguments are converted to double.  The
arguments to scanf are pointers, so there is a need to differentiate
between pointer to float and pointer to double.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Skarmander


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-15-06 12:22 AM

Måns Rullgård wrote:
> Skarmander <invalid@dontmailme.com> writes:
> 
>
> Wrong.  With scanf %f denotes a float, and %lf denotes a double.  This
> difference is because the arguments to printf are subject to type
> promotion, so any float arguments are converted to double.  The
> arguments to scanf are pointers, so there is a need to differentiate
> between pointer to float and pointer to double.
>
You're ruining my fun.

For those who were enlightened by the above, read the FAQ at
http://www.c-faq.com as well. It covers the above and much more.

S.





[ Post a follow-up to this message ]



    Re: convert long long integer to string using sprintf  
Maxim Yegorushkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-15-06 12:26 PM


M=E5ns Rullg=E5rd wrote:
> wenmang@yahoo.com writes:
> 
>
> The format for "long long" is %lld (or %llx etc.).  Keep in mind
> though, that a long long is not necessarily 64 bits.

It is at least 64 bits to be precise.

The New C Standard by Derek M. Jones
<q>
The C compiler for the Unisys e-@ction Application Development
Solutions (formerly known as the Universal Compiling System, UCS)[1331]
has 9-bit character types- 18-bit short, 36-bit int and long, and
72-bit long long.
</q>






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:11 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register