What is iswblank in C?

The iswblank function in C checks if a given wide character is a blank character.

A wide character is similar to the normal character data type, except it represents the Unicode character set instead of the ASCII character set.

To use the iswblank function, you will need to include the <wctype.h> library in the program, as shown below:

#include <wctype.h>

The prototype of the iswblank function is shown below:

int iswblank(wint_t ch);

Note: The wint_t data type shown above refers to a wide integer in C.

Parameters

The iswblank function takes a single mandatory parameter of the wide integer data type.

Return value

If the argument passed to the iswblank function is a blank character, then the function returns a non-zero integer; otherwise, it returns 00.

Example

The code below shows how the iswblank function works in C:

#include <stdio.h>
#include <wctype.h>
#include <wchar.h>
int main() {
// initializing string
wchar_t str[] = L"Count the number of blanks in the sentence";
// initializing counter
int blanks = 0;
// extracting characters
for(int i = 0; i < wcslen(str); i++)
{
// checking blank character
if(iswblank(str[i]))
{
blanks++;
}
}
printf("The string contains %d blank characters.", blanks);
return 0;
}

Explanation

First, the code initializes a character array. The ‘L’ identifier in line 8 informs the compiler that the Unicode character set is being used. Additionally, a counter variable, blanks, is initialized to store the number of blank characters present in the array.

A for-loop iterates over the array and extracts each character. The wcslen function calculates the array’s length so that the loop can terminate correctly.

Each extracted character is provided as an argument to the iswblank function in line 18. The iswblank function proceeds to check if the character is blank and updates the counter accordingly.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved