Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > convert long long integer to string using sprintf

Reply
Thread Tools

convert long long integer to string using sprintf

 
 
wenmang@yahoo.com
Guest
Posts: n/a
 
      06-13-2006
what is format for sprintf to convert long long integer (64 bits) to
string?

 
Reply With Quote
 
 
 
 
=?iso-8859-1?Q?M=E5ns_Rullg=E5rd?=
Guest
Posts: n/a
 
      06-13-2006
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

 
Reply With Quote
 
 
 
 
Joe Wright
Guest
Posts: n/a
 
      06-14-2006
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 ---
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-14-2006
Måns Rullgård <> writes:
> 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.


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- <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.
 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      06-14-2006
Joe Wright wrote:
> 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.
>

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.
 
Reply With Quote
 
=?iso-8859-1?Q?M=E5ns_Rullg=E5rd?=
Guest
Posts: n/a
 
      06-14-2006
Skarmander <> writes:

> Joe Wright wrote:
>> 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.
>>

> 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

 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      06-14-2006
Måns Rullgård wrote:
> Skarmander <> writes:
>
>> Joe Wright wrote:
>>> 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.
>>>

>> 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.
>

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.
 
Reply With Quote
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      06-15-2006

Måns Rullgård wrote:
> 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.


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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Size of Integer , long Integer, Long double Suresh V C++ 5 07-05-2010 08:09 AM
Split string (then) Convert string into Integer news ASP General 2 05-26-2010 11:58 AM
Change a string to an integer, report an error if the string does not represent an integer? Randy Kramer Ruby 12 10-25-2007 09:56 PM
i want to convert long integer to string seema C Programming 3 11-28-2004 03:13 PM
convert scientific integer to normal integer les ander Python 4 10-05-2004 04:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57