Storing the whole number

This is a discussion on Storing the whole number within the C Programming forums, part of the General Programming Boards category; is there anyway to store a number such as 012345 or 012346 or 012347 as an integer or double, not ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,156

    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-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05: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, 07:57 PM
  5. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 12:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21