test for any printable character, including space
#include <ctype.h> int isprint( int c );
The isprint() function tests for any printable character, including space (' '). The isgraph() function is similar, except that the space character is excluded from the character set being tested.
A nonzero value when the argument is a printable character; otherwise, zero.
#include <stdio.h> #include <ctype.h> char chars[] = {'A', 0x09, ' ', 0x7d}; #define SIZE sizeof( chars ) / sizeof( char ) void main() { int i; for( i = 0; i < SIZE; i++ ) { printf( "Char %c is %sa printable character\n", chars[i], ( isprint( chars[i] ) ) ? "" : "not " ); } }
produces the output
Char A is a printable character Char is not a printable character Char is a printable character Char } is a printable character
ANSI
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
isalnum(), isalpha(), iscntrl(), isdigit(), isgraph(), islower(), ispunct(), isspace(), isupper(), isxdigit()