Name

isprint

Synopsis

Ascertains whether a given character is printable

#include <ctype.h>
intisprint( int c );

The isprint() function tests whether its argument is a printing character. If the argument is a printing character, isprint() returns a nonzero value (that is, true); if not, the function returns 0 (false).

“Printing” means only that the character occupies printing space on the output medium, not that it fills the space with a glyph. Thus the space is a printing character (isprint(' ') returns true), even though it does not leave a mark (isgraph(' ') returns false).

Which character codes represent printable characters depends on the current locale setting for the category LC_CTYPE, which you can query or change using the setlocale() function. In the default locale C, the printable characters are the alphanumeric characters, the punctuation characters, and the space character; the corresponding character codes are those from 32 through 126.

Example

unsigned int c; printf("\nThe current locale for the 'is ...' functions is '%s'.\n", setlocale(LC_CTYPE, NULL)); printf("Here is a table of the 'is ...' values for the characters" " from 0 to 127 in this locale:\n\n"); for ( c = 0; c < 128; c++ ) // Loop iteration for each table row. { if ( c % 24 == 0 ) // Repeat table header every 24 rows. { printf("Code char alnum alpha blank cntrl digit graph lower" " print punct space upper xdigit\n"); printf("---------------------------------------------------" "-------------------------------\n"); ...

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.