isprint() – Character Function

isprint() – Character Function

How to check printable characters in C++?

Explanation

isprint() function is used to check for printable characters including the space but not the control symbols. It returns a zero value if it is not this type.

Syntax:

int isprint ( int c );

Example :

#include
#include
#include
int main ()
{
int i=0;
char arr[]=”HioxtHscripts….”;
while (arr[i])
{
if (isprint(arr[i]))
putchar(arr[i]);
else
putchar(arr[i]);
i++;
}
getch();
return 0;
}

Result :

HioxHscripts….

In the above example, this function is used to skip loop and print the rest of the printable characters from the array. It checks them based on ASCII values.





Leave a Reply

Your email address will not be published. Required fields are marked *