isblank() in C/C++


The function isblank() is used to check that the passed character is blank or not. It is basically a space character and it also considers tab character(\t). This function is declared in “ctype.h” header file in C language and “cctype”” header file in C++ language.

Here is the syntax of isblank() in C++ language,

int isblank(int char);

Here is an example of isblank() in C++ language,

Example

 Live Demo

#include <ctype.h>
#include <iostream>
using namespace std;
int main() {
   string s = "The space between words. ";
   int i = 0;
   int count = 0;
   while(s[i]) {
      char c = s[i++];
      if (isblank(c)) {
         count++;
      }
   }
   cout << "\nNumber of blanks in sentence : " << count << endl;
   return 0;
}

Output

Number of blanks in sentence : 4

In the above program, a string is passed in variable s. The function isblank() is used to check the spaces or blanks in the passed string as shown in the following code snippet.

string s = "The space between words. ";
int i = 0;
int count = 0;
while(s[i]) {
   char c = s[i++];
   if (isblank(c)) {
      count++;
   }
}

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

569 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements