C++ <cctype> - isalpha() Function
The C++ <cctype> isalpha() function is used to check if the given character is an alphabetic letter. In the default "C" locale, an alphabetic letter is a letter for which either isupper or islower function returns true. Other locales may consider a different selection of characters as alphabetic letters.
Syntax
int isalpha ( int ch );
Parameters
ch |
Specify the character to be checked, casted to an int, or EOF. |
Return Value
Returns non-zero value (i.e, true) if ch is an alphabetic letter, else returns zero (i.e, false).
Example:
The example below shows the usage of isalpha() function.
#include <iostream> #include <cctype> using namespace std; int main (){ char str[50] = "98Hi@@"; //counting the numbers of //alphabetic letters in str int i = 0, count = 0; while(str[i]) { if(isalpha(str[i])) count++; i++; } //displaying the output cout<<str<<" contains "<<count<< " alphabetic letters."; return 0; }
The output of the above code will be:
98Hi@@ contains 2 alphabetic letters.
❮ C++ <cctype> Library