C++ isalpha() function














































C++ isalpha() function



isalpha() -

  1. It is a C++ function which checks whether a given character is an alphabet or not.
  2. It treats both lower-case and upper-case letters as alphabets.
  3. It takes in character as input value, as already mentioned.
  4. It returns a non-zero integer when an alphabet is encountered while zero for the rest.
  5. It has <cctype> as header file.

Syntax - isalpha <int character_variable_name>

Code -

#include <iostream>
#include <cctype>
using namespace std;
int main()
{
    char ch;
    cout<<"Enter ~ to stop"<<endl;
    cout<<"Enter a character : ";
    cin>>ch;
    while(ch!='~')     //One can put any symbol for the condition.
    {
        cout<<isalpha(ch)<<endl;
        cout<<"Enter a character : ";
        cin>>ch;
    }
    return 0;
}

Output -

Enter ~ to stop
Enter a character : M
1
Enter a character : e
2
Enter a character : 3
0
Enter a character : &
0
Enter a character : +
0
Enter a character : ~


Comments