iswgraph() in C/C++ with Examples

The iswgraph() is a built-in function in C/C++ which checks if the given wide character has an graphical representation or not. It is defined within the cwctype header file of C++. By default, the following characters are graphic:

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

Syntax:

int iswgraph(ch)

Parameter: The function accepts a single mandatory parameter ch which specifies the wide character which we have to check that if it has a graphical representation or not.

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

  • If the ch has a graphical representation character, then a non-zero value is returned.
  • If it is not a graphical representation character, then 0 is returned.

Below programs illustrates the above function.

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswgraph() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = '?';
    wchar_t ch2 = ' ';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}

chevron_right


Output:

? has graphical representation 
  does not have graphical representation

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// iswgraph() function
#include <cwctype>
#include <iostream>
using namespace std;
  
int main()
{
  
    wchar_t ch1 = ' ';
    wchar_t ch2 = '3';
  
    // Function to check if the character
    // has a graphical representation or not
    if (iswgraph(ch1))
        wcout << ch1 << " has graphical representation ";
    else
        wcout << ch1 << " does not have graphical representation ";
    wcout << endl;
  
    if (iswgraph(ch2))
        wcout << ch2 << " has graphical representation ";
    else
        wcout << ch2 << " does not have graphical representation ";
  
    return 0;
}

chevron_right


Output:

does not have graphical representation 
3 has graphical representation


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.