isblank() in C/C++
The isblank()function returns non-zero if ch is a character for which isspace() returns true and is used to separate words. Thus for English, the blank characters are space and horizontal tab.
Header File : ctype.h Declaration : int isblank(int ch)
difference between isblank() and isspace()
The isspace() simply return true if the character is a space. In other words blank character is a space character used to separate words within a line of text and isblank() is used to identify it.
isblank() considers blank characters the tab character (‘\t’) and the space character (‘ ‘).
isspace() considers space characters : (‘ ‘) – Space, (‘\t’) – Horizontal tab, (‘\n’) – Newline, (‘\v’) – Vertical tab, (‘\f’) – Feed, (‘\r’) – Carriage return
Examples:
Input: Geeks for Geeks
Output: Geeks
for
Geeks
Explanation: Since there are 2 spaces for Geeks for Geeks marked by an underscore( _ ) :
Geeks_for_Geeks
we replace the space with a newline character.
isblank() C++ Program:
This code prints out the string character by character, replacing any blank character by a newline.
// CPP program to demonstrate working // of isblank() #include <ctype.h> #include <iostream> using namespace std; int main() { string str = "Geeks for Geeks"; int i = 0; // to store count of blanks int count = 0; while (str[i]) { // to get ith character // from string char ch = str[i++]; // mark a new line when space // or horizontal tab is found if (isblank(ch)) { cout << endl; count++; } else cout << ch; } cout << "\nTotal blanks are : " << count << endl; return 0; } |
Output:
Geeks for Geeks Total blanks are : 2
Recommended Posts:
- Difference between Inheritance and Polymorphism
- Difference between Single and Multiple Inheritance in C++
- Collection Data Type in Apache Cassandra
- Difference between Abstraction and Encapsulation in C++
- How to print JavaScript console with PHP ?
- How to set PHP development environment in windows ?
- return statement in C/C++ with Examples
- size of char datatype and char array in C
- Logical Not ! operator in C with Examples
- How to implement our own Vector Class in C++?
- Web Programming in C++
- Evolution of Foldable Smartphones
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



