Thread: Storing the whole number

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    3

    Storing the whole number

    is there anyway to store a number such as 012345 or 012346 or 012347 as an integer or double, not as a string, without losing the zero at the beginning?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    No - the zero is simply a means of representing an integer
    1
    and
    000000001
    are the same numeric value

    printing things with leading zeros is up to you
    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.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    Well, think you are unaware of the fact that any literal preceeded by 0 is not taken as a decimal number by C, rather it is taken to be an octal number. So if you put 0 before any numeric literal, you actually mean to say to the c Compiler that it is an octal number and that may generate an error too if you have used some digit more than or equal to 8.

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: Storing the whole number

    Originally posted by flip114
    is there anyway to store a number such as 012345 or 012346 or 012347 as an integer or double, not as a string, without losing the zero at the beginning?
    As Salem said, "No"

    But he didn't mention that the way to output a number with the leading 0's use the format specifier with a leading 0:

    printf("Number is %06d \n", val);

    will print a 6-character value with leading 0s'
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  4. Finding a number within a number
    By jeev2005 in forum C Programming
    Replies: 2
    Last Post: 01-10-2006, 08:57 PM
  5. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM