convert long long integer to string using sprintf

Discussion in 'C Programming' started by wenmang@yahoo.com, Jun 13, 2006.

  1. Guest

    what is format for sprintf to convert long long integer (64 bits) to
    string?
    , Jun 13, 2006
    #1
    1. Advertising

  2. 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
    =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?=, Jun 14, 2006
    #2
    1. Advertising

  3. Joe Wright Guest

    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 ---
    Joe Wright, Jun 14, 2006
    #3
  4. 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) <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.
    Keith Thompson, Jun 14, 2006
    #4
  5. Skarmander Guest

    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.
    Skarmander, Jun 14, 2006
    #5
  6. 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
    =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?=, Jun 14, 2006
    #6
  7. Skarmander Guest

    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.
    Skarmander, Jun 14, 2006
    #7
  8. 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>
    Maxim Yegorushkin, Jun 15, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. les ander
    Replies:
    4
    Views:
    864
    wes weston
    Oct 5, 2004
  2. Replies:
    8
    Views:
    5,843
  3. seema

    i want to convert long integer to string

    seema, Nov 28, 2004, in forum: C Programming
    Replies:
    3
    Views:
    522
    Christian Staudenmayer
    Nov 28, 2004
  4. Suresh V
    Replies:
    5
    Views:
    3,689
    SaticCaster
    Jul 5, 2010
  5. Randy Kramer
    Replies:
    12
    Views:
    360
    Robert Klemme
    Oct 25, 2007
Loading...

Share This Page