Thread: declaring a decimal number in c

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    2

    declaring a decimal number in c

    Hello,

    This is my first time using this message board so if i am doing something wrong please let me know.

    OK, I am trying to read the following number in from a card reader: 0001292114. I can store the number in a int just fine, but when I try to verify that the entered number is correct
    ( if(x == 0001292114) )
    I get the following error: illegal digit '9' for base '8'.
    I understand that a number starting with "0" is an octal number. My question is how do you declare the number 0xxxxxxxx as a decimal value?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Unfortunately, you can't. That's just how C works when you specify a literal value like that, if there's a leading 0, it's octal, period. If you want to check an exact match, with leading zeros and everything, your best bet is to treat everything as a string, and use strcmp to compare.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    2
    Quote Originally Posted by anduril462 View Post
    Unfortunately, you can't. That's just how C works when you specify a literal value like that, if there's a leading 0, it's octal, period. If you want to check an exact match, with leading zeros and everything, your best bet is to treat everything as a string, and use strcmp to compare.
    thank you very much, i hadn't thought comparing strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Typing decimal number and cover it binary number!
    By Kazumi in forum C Programming
    Replies: 32
    Last Post: 04-16-2011, 07:21 PM
  2. Number of digits in a decimal number
    By maverix in forum C Programming
    Replies: 7
    Last Post: 11-04-2007, 12:12 PM
  3. How to set a number of decimal spaces?
    By Diablo02 in forum C# Programming
    Replies: 2
    Last Post: 09-26-2007, 02:10 PM
  4. how to remove zero after decimal number
    By abhay_m8 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2007, 02:30 AM
  5. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM