Does anyone know the header file to include for isdigit and isalpha?
Printable View
Does anyone know the header file to include for isdigit and isalpha?
ctype.h
What does isdigit do
Code:# include<iostream>
using namespace std;
int main ()
{
char number = '1';
if (isdigit(number))
cout << "Yes " << endl;
return 0;
}
compile this
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...
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)