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 awide integer
in C.
The iswblank
function takes a single mandatory parameter of the wide integer
data type.
If the argument passed to the iswblank
function is a blank character, then the function returns a non-zero integer; otherwise, it returns .
The code below shows how the iswblank
function works in C:
#include <stdio.h>#include <wctype.h>#include <wchar.h>int main() {// initializing stringwchar_t str[] = L"Count the number of blanks in the sentence";// initializing counterint blanks = 0;// extracting charactersfor(int i = 0; i < wcslen(str); i++){// checking blank characterif(iswblank(str[i])){blanks++;}}printf("The string contains %d blank characters.", blanks);return 0;}
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