iswpunct() function in C/C++

The iswpunct() is a function in C/C++ which test swhether Wide-Character code is representing a character of class punct in the program’s current locale. It returns non-zero if Wide-Character is a punctuation wide-character code, otherwise, it shall return 0. This function is defined in cwctype header file.The function checks if ch is a punctuation character or not.The Punctuation characters are as follows

! " # $ % & ' () * +, - . / : ;  ? @ [\] ^ _ ` {|} ~

Syntax :

int iswpunct(ch)

Parameters: The function accepts a single mandatory parameter ch which specifies the character to be checked.



Return Value : The function returns a non-zeroo value if character ch is a punctuation character else it returns zero.

Below program illustrate the above function:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// the iswpunct() function
#include <bits/stdc++.h>
int main()
{
    int i = 0;
    int count_ = 0;
  
    // string declaration
    char string1[] = "~Hello geekforgeeks !";
    char string2[count_];
  
    // iterate in the string
    while (string1[i]) {
  
        // check if the character is
        // punctuation mark or not
        if (iswpunct(string1[i])) {
  
            // store the punctuation characters
            string2[count_] = string1[i];
            count_++;
        }
        i++;
    }
    // prints the punctuation character
    printf("The sentence contains %d punct. character :\n", count_);
    for (int i = 0; i < count_; i++)
        printf("%c ", string2[i]);
    return 0;
}
chevron_right

Output:
The sentence contains 2 punct. character :
~ !

Program 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// the iswpunct() function
#include <bits/stdc++.h>
int main()
{
    int i = 0;
    int count_ = 0;
  
    // string declaration
    char string1[] = "@#$^gfg";
    char string2[count_];
  
    // iterate in the string
    while (string1[i]) {
  
        // check if the character is
        // punctuation mark or not
        if (iswpunct(string1[i])) {
  
            // store the punctuation characters
            string2[count_] = string1[i];
            count_++;
        }
        i++;
    }
    // prints the punctuation character
    printf("The sentence contains %d punct. character :\n", count_);
    for (int i = 0; i < count_; i++)
        printf("%c ", string2[i]);
    return 0;
}
chevron_right

Output:
The sentence contains 4 punct. character :
@ # $ ^



Check out this Author's contributed articles.

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 :
C
Practice Tags :