Javatpoint Logo
Javatpoint Logo

Isprint() in C++

isprint() is a predefined function in C++ that handles strings and characters. The header files needed for string and character functions are cstring and cctype, respectively. If the argument has any printable characters, this function is utilised to determine that fact. In C++, there are numerous varieties of printable characters, including:

The built-in C++ function "isprint()" in the "cctype.h" header file determines whether a character is printable or not.

With the exception of the house character (' '), Isprint returns true for constant cases.

This function (Isprint) has a localised model version that may be found in the cctype header file.

To determine whether any Non-Printing characters appear in a string of sentences, use the Isprint() function.

-Isprint() is an internal function that offers an effective method of handling characters that won't print.

Programmers can reduce the number of lines of code by using -Isprint().

It is true that -Isprint() speeds up software compilation.

Include cctype.h in your software to enable several additional related functions in addition to isprint() for the user. There are additional functions in cctype.h, including

isblank (Check if character is blank ) (Check if character is blank )

Iscntrl (Check if character is a control character) (Check if character is a control character)

isdigit (Check if character is decimal digit ) (Check if character is decimal digit )

Isgraph( Check if character has graphical representation ) ( Check if character has graphical representation )

Syntax:

Time Complexity: O(n)

Auxiliary Space: O(1)

Given a string in C++, we need to calculate the number of printable characters in the string. Algorithm

1) Traverse the given string character by character upto its length, check if character is a printable character.

2) If it is a printable character, increment the counter by 1, else traverse to the next character.

3) Print the value of the counter.

Examples:


Output:

18

Parameters of Isprint() are

C is a character to be checked, casted as an int or EOF.

Example

Due to the newline character's inability to be printed, it will only print one line.

Example

Output

If we run the above code it will generate the following output -

first line n second line n

Example

Output

If we run the above code it will generate the following output -

Hellotallnhow are you

Notes Like all other functions from <cctype>, the behavior of std::isprint is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:

Similarly, they should not be directly used with standard algorithms when the iterator's value type is char or signed char. Instead, convert the value to unsigned char first:







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA