Thread: Header file for isdigit

  1. #1
    Sub
    Guest

    Question Header file for isdigit

    Does anyone know the header file to include for isdigit and isalpha?

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    ctype.h

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    32
    What does isdigit do
    I am a C++ newb
    using: Visual C++ 6.0
    thanx for any Help

  4. #4
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Code:
    # include<iostream>
    using namespace std;
    
    int main ()
    {
    
    	char number = '1';
    
    	if (isdigit(number))
               cout << "Yes " << endl;
    
    
    return 0;
    }

    compile this
    Last edited by Betazep; 12-18-2001 at 01:00 AM.
    Blue

  5. #5
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    isdigit can be found in iostream as well...

    Imagine in the above program if the character held in 'number' was an 'a'.

    Would "Yes " still be outputted to the screen. Well no... 'a' isn't a digit. '1' is a digit.

    Pretty straightforward...
    Blue

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    Basically how it's done:

    Code:
    bool isdigit(char c)
    {
            if(c >= '0' && c <= '9')
                     return true;
    
            return false;
    }
    Or, even more compactly, you could make a macro:

    Code:
    #define isdigit(c) ((c >= '0' && c <= '9') ? true : false)
    That's all there is to it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  4. Replies: 6
    Last Post: 04-02-2002, 05:46 AM