isspace() - Character Function
How is "isspace()" used in C++?
Explanation
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.
Syntax:
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; for(i=0;str[i]!=' ';i++) { c=str[i]; 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.