Related Tags

c

# What is iswblank in C?

Talha Ashar

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 $0$.

## 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.

RELATED TAGS

c

CONTRIBUTOR

Talha Ashar