Thread: C function "strtoull" failing

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    1

    C function "strtoull" failing

    I have a code in which I am passing string "5368709120" to function strtoull() and it should had returned me number 5368709120 but instead it returns me 1073741824 which is incorrect.

    What may be the possible cause of this and how to rectify it?

    Code:
        typedef unsigned long long    ULL_Type;
        char *quotaStr = "5368709120";
        ULL_Type            quota;
    
        quota = strtoull(quotaStr, NULL, 10);

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    how do you print this number?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    .
    Join Date
    Nov 2003
    Posts
    307
    C function "strtoull" failing - The UNIX and Linux Forums

    Please do not post the same question everywhere. This requires that you read about one paragraph of documentation on printf format strings. You can't print the correct value.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Works for me....
    Code:
    $ cat foo.c
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        typedef unsigned long long    ULL_Type;
        char *numStr = "5368709120";
        ULL_Type            num;
        num = strtoull(numStr, NULL, 10);
        printf("%s converted to numeric=%llu\n", numStr, num);
    
      return 0;
    }
    $ gcc -Wall foo.c
    $ ./a.out 
    5368709120 converted to numeric=5368709120
    Perhaps it's the brain damage you're using to try and print the result.
    Perhaps you're not using %llu as the printf format.
    Perhaps you're using code::blocks or Orwell dev-C++ on windows, in which case you need to use the platform specific formats for the 64-bit types.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2009, 05:59 AM
  2. Replies: 3
    Last Post: 03-27-2008, 11:44 PM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM