Character Classification Functions in C++ Programming


Character classification in C++ is possible using functions specified in function library. These functions are included in the cctype header file. These can be classification functions like isalpha, isalnum, isdigit, islower, isupper, etc.

The program demonstrates the usage of character classification functions in C++ programming, specifically the isspace() function.

  • The isspace() function is a part of the cctype library and is used to check if a given character is whitespace, i.e., space, tab, newline, vertical tab, form feed, or carriage return.
  • In the program, an array of characters a is initialized with the values "R@ 1a". A for loop is used to iterate through each character of the array. For each character, the isspace() function is used to check if it is whitespace. If the character is whitespace, it is printed along with the message "Space" using the cout statement.

Source Code

#include <iostream>
#include <cctype>
using namespace std;
int main()
{
    /*
    Character Classification Functions in C++ Programming
      isalnum
      isalpha
      isdigit
      islower
      isupper
      isspace
    */
    char a[6]="R@ 1a";
    for (int i=0; i<=5; i++)
    {
        if(isspace(a[i]))
            cout<<a[i]<<" Space"<<endl;
    }
    return 0;
}
 

Output

  Space
To download raw file Click Here

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples