cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : C Library : cctype (ctype.h) : isprint
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cctype (ctype.h)
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
tolower
toupper

-

isprint function
int isprint ( int c );
<cctype>

Check if character is printable

Checks if parameter c is a printable character. A printable character is any character that is not a control character.

For the standard ASCII character set, control characters are those between ASCII codes 0x00 (NUL) and 0x1f (US), plus 0x7f (DEL). Therefore, printable characters are all but these, although specific compiler implementations for certain platforms may define additional control characters in the extended character set (above 0x7f).

isgraph returns true for the same cases as isprint except for the whitespace characters (like ' '), which return true when checked with isprint but false when checked with isgraph.

For a detailed chart on what the different ctype functions return for each character of the standard ANSII character set, see the reference for the <cctype> header.

Parameters

c
Character to be checked, casted to an int, or EOF.

Return Value

A value different from zero (i.e., true) if indeed c is a printable character. Zero (i.e., false) otherwise.

Example

/* isprint example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  char str[]="first line \n second line \n";
  while (isprint(str[i]))
  {
    putchar (str[i]);
    i++;
  }
  return 0;
}

This code prints a string character by character until a character that is not printable is checked and breaks the while-loop. In this case, only the first line would be printed, since the line ends with a newline character ('\n'), which is not a printable character.

See also

iscntrl Check if character is a control character (function)
isspace Check if character is a white-space (function)
isalnum Check if character is alphanumeric (function)

Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us