printf / sscanf unsigned long long int variables

Discussion in 'C Programming' started by Joerg Schwerdtfeger, Apr 2, 2004.

  1. Hi everyone,

    I want to input & output an unsigned long long int variable, but
    printf/sscanf seems to interpret the least significant 32 bits only.

    I assume this is a bloody newbie-question, but reading the clc-faq and
    googleing for this issue, I only found out that this might be a known
    problem - but how can I fix it? Are there any workarounds, e.g. other
    io-routines who can handle ull-ints?

    Thanks in advance,
    Joerg
    Joerg Schwerdtfeger, Apr 2, 2004
    #1
    1. Advertising

  2. Joerg Schwerdtfeger wrote:
    > Hi everyone,
    >
    > I want to input & output an unsigned long long int variable, but
    > printf/sscanf seems to interpret the least significant 32 bits only.


    use the %llu format specifier for unsigned long longs

    --
    John Tsiombikas (Nuclear / the Lab)

    http://thelab.demoscene.gr/nuclear/
    John Tsiombikas (Nuclear / the Lab), Apr 2, 2004
    #2
    1. Advertising

  3. "Joerg Schwerdtfeger" <> wrote in message news:c4inin$a7t$05$-online.com...
    > Hi everyone,
    >
    > I want to input & output an unsigned long long int variable, but
    > printf/sscanf seems to interpret the least significant 32 bits only.


    Does your compiler support ULLs?

    >
    > I assume this is a bloody newbie-question, but reading the clc-faq and
    > googleing for this issue, I only found out that this might be a known
    > problem - but how can I fix it? Are there any workarounds, e.g. other
    > io-routines who can handle ull-ints?
    >
    > Thanks in advance,
    > Joerg
    >


    F:\Vijay\C> type ull.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <limits.h>

    int
    main ( void )
    {
    unsigned long long int ull;
    printf ( "ULLONG_MAX: %llu\n", ULLONG_MAX );
    printf ( "Enter an ull value: " );
    scanf ( "%llu", &ull );
    printf ( "\nThe ull value is: " );
    printf ( "%llu", ull );
    return EXIT_SUCCESS;
    }

    F:\Vijay\C> gcc -std=c99 -Wall
    F:\Vijay\C> a.exe
    ULLONG_MAX: 18446744073709551615
    Enter an ull value: 18446744073709551614
    The ull value is: 18446744073709551614
    Vijay Kumar R Zanvar, Apr 2, 2004
    #3
  4. Vijay Kumar R Zanvar wrote:
    > scanf ( "%llu", &ull );
    > printf ( "%llu", ull );


    Damn! I used %ull instead of %llu. *embarrassed*

    Thank you so much!
    Joerg Schwerdtfeger, Apr 2, 2004
    #4
    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. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    655
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,173
    Peter Shaggy Haywood
    Sep 20, 2005
  3. pereges

    Promoting unsigned long int to long int

    pereges, Jun 30, 2008, in forum: C Programming
    Replies:
    112
    Views:
    2,024
    David Thompson
    Jul 28, 2008
  4. pozz
    Replies:
    12
    Views:
    716
    Tim Rentsch
    Mar 20, 2011
  5. Hans Vlems

    long long int and sscanf, printf

    Hans Vlems, Sep 7, 2012, in forum: C Programming
    Replies:
    5
    Views:
    1,522
    Hans Vlems
    Sep 7, 2012
Loading...

Share This Page