C examples for ctype.h:isspace
function
<cctype> <ctype.h>
Check if character is a white-space
For the C locale, white-space characters are any of:
Char | Value | Meaning |
---|---|---|
' ' | (0x20) | space (SPC) |
'\t' | (0x09) | horizontal tab (TAB) |
'\n' | (0x0a) | newline (LF) |
'\v' | (0x0b) | vertical tab (VT) |
'\f' | (0x0c) | feed (FF) |
'\r' | (0x0d) | carriage return (CR) |
int isspace ( int c );
Parameter | Description |
---|---|
c | Character to be checked, casted to an int, or EOF. |
A non zero value (i.e., true) if indeed c is a white-space character. Zero (i.e., false) otherwise.
The following code prints out the C string character by character, replacing any white-space character by a newline character.
#include <stdio.h> #include <ctype.h> int main ()/* www . j a va 2 s. c o m*/ { char c; int i=0; char str[]="this is a test. Example \tsentence to test isspace\n"; while (str[i]) { c=str[i]; if (isspace(c)) c='\n'; putchar (c); i++; } return 0; }