how to check input is decimal or not?

This is a discussion on how to check input is decimal or not? within the C Programming forums, part of the General Programming Boards category; hello friends, how to check whether my input is integer or not. isdigit() check for each character. i want to ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    14

    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.

    example,

    if user input is 123er34, then the compiler should through error that the input value is not a decimal value.it 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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What's WRONG with isdigit(), you just have to take each character in the string and check with isdigit..

    --
    Mats

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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
    Posts
    5,006
    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, 10: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, 12:57 PM
  5. Input check
    By Extol in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2003, 11:31 AM

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