Thread: how to check input is decimal or not?

  1. #1
    Registered User
    Join Date
    Apr 2006

    how to check input is decimal or not?

    hello friends,

    how to check whether my input is integer or not.

    isdigit() check for each character.

    i want to check the user input (whatever) is decimal or not.


    if user input is 123er34, then the compiler should through error that the input value is not a decimal only accept integer (like 1,2,...9...100.....1000000).

    is there any c fn other than isdigit().

    give u'r opinions.

    thank you.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    What's WRONG with isdigit(), you just have to take each character in the string and check with isdigit..


  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    You could use strtol() or strtod() and use the error checking ability it has.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 02:18 AM
  2. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  3. Check if input has been recieved
    By bertazoid in forum C Programming
    Replies: 13
    Last Post: 10-21-2008, 09:20 AM
  4. how to check if input is only positive number?
    By hanek in forum C Programming
    Replies: 16
    Last Post: 04-26-2004, 11:57 AM
  5. Input check
    By Extol in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2003, 11:31 AM