iswprint() in C/C++ with Examples


The iswprint() is a built-in function in C/C++ which checks if the given wide character can be printed or not. It is defined within the cwctype header file of C++. By default, the following characters are printable:

  • Digits (0 to 9)
  • Uppercase letters (A to Z)
  • Lowercase letters (a to z)
  • Punctuation characters (!”#$%&'()*+, -./:;?@[\]^_`{|}~)
  • Space

Syntax:

int iswprint(ch)

Parameters: The function accepts a single mandatory parameter ch which specifies the wide character which has to be checked if printable or not.



Return Value: The function returns two values as shown below.

  • If the parameter ch, is printable, then a non-zero value is returned.
  • If it is not a printable character then 0 is returned.

Below programs illustrates the above function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// towprint() function
#include <cwchar>
#include <cwctype>
#include <iostream>
using namespace std;
int main()
{
  
    wchar_t str[] = L"Geeks\tfor\tGeeks";
    for (int i = 0; i < wcslen(str); i++) {
  
        // Function to check if the characters are
        // printable or not. If not, then replace
        // all non printable character by comma
        if (!iswprint(str[i]))
            str[i] = ', ';
    }
    wcout << "Printing, if the given wide 
    character cannot be printed\n";
    wcout << str;
    return 0;
}

chevron_right


Output:

Printing , if the given wide character cannot be printed
Geeks, for, Geeks

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Program to illustrate
// towprint() function
#include <cwchar>
#include <cwctype>
#include <iostream>
using namespace std;
int main()
{
  
    wchar_t str[] = L"Ishwar Gupta\t123\t!@#";
    for (int i = 0; i < wcslen(str); i++) {
  
        // Function to check if the characters are
        // printable or not. If not, then replace
        // all non printable character by comma
        if (!iswprint(str[i]))
            str[i] = ', ';
    }
    wcout << "Printing, if the given wide 
    character cannot be printed\n";
    wcout << str;
    return 0;
}

chevron_right


Output:

Printing , if the given wide character cannot be printed
Ishwar Gupta, 123, !@#


My Personal Notes arrow_drop_up

Budding Web DeveloperKeen learnerAverage CoderDancer&Social Activist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.