Does anyone know the header file to include for isdigit and isalpha?
Does anyone know the header file to include for isdigit and isalpha?
ctype.h
What does isdigit do
I am a C++ newb
using: Visual C++ 6.0
thanx for any Help
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
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
Basically how it's done:
Or, even more compactly, you could make a macro:Code:bool isdigit(char c) { if(c >= '0' && c <= '9') return true; return false; }
That's all there is to itCode:#define isdigit(c) ((c >= '0' && c <= '9') ? true : false)