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

  2. use the %llu format specifier for unsigned long longs
     
    John Tsiombikas (Nuclear / the Lab), Apr 2, 2004
    #2
    1. Advertisements

  3. Does your compiler support ULLs?
    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. Damn! I used %ull instead of %llu. *embarrassed*

    Thank you so much!
     
    Joerg Schwerdtfeger, Apr 2, 2004
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.