C++ isblank()

isblank() Prototype

int isblank(int ch);

The isblank() function checks if ch is a blank character or not as classified by the currently installed C locale. By default, space and horizontal tab are considered as blank characters.

The behaviour of isblank() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

isblank() Parameters

ch: The character to check.

isblank() Return value

The isblank() function returns non zero value if ch is a blank character, otherwise returns zero.

Example: How isblank() function works

#include <cctype>
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char str[] = "Hello, I am here.";
    int count = 0;

    for (int i=0; i<=strlen(str); i++)
    {
        if (isblank(str[i]))
            count ++;
    }

    cout << "Number of blank characters: " << count << endl;

    return 0;
}

When you run the program, the output will be:

Number of blank characters: 3
Did you find this article helpful?