isspace() - Character Function

How is "isspace()" used in C++?


isspace() function is used to check whether the argument contains white-space characters like space, horizontal, vertical tab, formfeed, carriage return or a newline. It returns zero if these white-spaces are not found.


int isspace( int c );

Example :

#include <stdio.h>
#include <cctype.h>
int main ()
int i ,count=0;
char str[100]=" assd aad aada dadad" ;
char c;
if (isspace(c)) count++;
printf( "The string has %d space characters", count);
return 0;

Result :

The string has 5 space characters

In the above example, this function is used to check the number of white-space characters in a string. It is checked based on the ASCII value.

C++ Tutorial

Ask Questions

Ask Question