C Library - isblank() function



The C ctype library isblank() function is used to check whether a given character is a blank character or not. Blank characters typically include spaces and horizontal tabs.

Syntax

Following is the C library syntax of the isblank() function −

int isblank(int c);

Parameters

This function accepts a single parameter −

  • c − This is the character to be checked, passed as an int. It must be representable as an unsigned char or the value of EOF.

Return Value

The function returns a non-zero value (true) if the character is a blank character (space ' ' or horizontal tab '\t').It returns 0 (false) otherwise.

Example 1: Checking Space Character

Here we check if a space character (' ') is a blank character using isblank(), which returns true.

#include <stdio.h>
#include <ctype.h>

int main() {
   char ch = ' ';
   if (isblank(ch)) {
      printf("The character is a blank character.\n");
   } else {
      printf("The character is not a blank character.\n");
   }
   return 0;
}

Output

The above code produces following result−

The character is a blank character.

Example 2: Checking Non-Blank Character

#include <stdio.h>
#include <ctype.h>

int main() {
   char ch = 'A';
   if (isblank(ch)) {
      printf("The character is a blank character.\n");
   } else {
      printf("The character is not a blank character.\n");
   }
   return 0;
}

Output

After execution of above code, we get the following result −

The character is not a blank character.
Advertisements