Length of a longggg integer !?? - C ?

Discussion in 'C' started by rforravi, Jan 22, 2010.

  1. rforravi

    rforravi New Member

    Joined:
    Aug 24, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    hey.

    I'm just trying to find out the length of a long int in C.

    I'm trying to accept a number from the user as :

    {
    long int i;

    printf("Enter a no: ");
    scanf("&ld", &i);

    ..
    ......

    }

    The user can give any integer for i -- lets say from 1 digit to 20 digits
    So, how do i find the length of the number he gives?
    Suppose say he enters " 62351235123512" it should display length=14

    Also, I'm unable to get if i need to specify as 'long' or 'double' when declaring ' int i' ??
    Please help me on this.
    I've tried using ' itoa' function and also sprintf() function but unable to get it !!

    Thx
     
  2. Deadly Ghos7

    Deadly Ghos7 New Member

    Joined:
    Dec 19, 2009
    Messages:
    55
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Earth
    Home Page:
    http://www.techgaun.com
    your scanf(); might have fault... %ld should have been used. Check with that.
     
  3. rforravi

    rforravi New Member

    Joined:
    Aug 24, 2008
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    oh sorry.
    it was a typo in my above post.

    It doesn't work with %ld too . in scanf !! :( :(
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Read it in as a string instead of as a number. Then you can do strlen on it, and you can use atoi and other functions if the length is short enough, or you can use your own custom functions to convert it into some binary representation if it won't fit into the C types.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice