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:
// 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; } |
The sentence contains 2 punct. character : ~ !
Program 2 :
// 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; } |
The sentence contains 4 punct. character : @ # $ ^
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- exp() function C++
- log() function in C++
- arc function in C
- fma() function in C++
- wctype() function in C/C++
- mbsrtowcs() function in C/C++
- isunordered() function in C++
- strtoimax() function in C++
- wcsrchr() function in C/C++
- mbrtowc() function in C/C++
- strcmpi() function in C
- wcspbrk() function in C/C++
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.



