Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isprint — C23 character classification function

`isprint(c)` from `<ctype.h>` returns a nonzero value for a printing character in the current locale. Unlike `isgraph`, it also includes the space character; control characters such as newline and horizontal tab are not printing.

Version: C23

Syntax

int isprint(int c);

isprint(c) from <ctype.h> returns a nonzero value for a printing character in the current locale. Unlike isgraph, it also includes the space character; control characters such as newline and horizontal tab are not printing.

The example tests A, space, \n, and \t in the C locale and normalizes with != 0. Output 1 1 0 0 demonstrates a printable letter and spacing character, then rejects the two control characters.

The argument must be EOF or representable as unsigned char; a negative plain char has undefined behavior. For a byte use isprint((unsigned char)ch), preserving EOF separately. The result follows LC_CTYPE and does not guarantee that a byte is valid Unicode or that a terminal displays it in one column.

Examples

#include <ctype.h>
#include <stdio.h>
int main(void){int values[]={'A',' ','\n','\t'};printf("%d %d %d %d\n",isprint(values[0])!=0,isprint(values[1])!=0,isprint(values[2])!=0,isprint(values[3])!=0);return 0;}

Result

1 1 0 0

The example tests `A`, space, `\n`, and `\t` in the `C` locale and normalizes with `!= 0`. Output `1 1 0 0` demonstrates a printable letter and spacing character, then rejects the two control characters.

Sources