The iswpunct() is a function in C/C++ which test whether 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-zero 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 <iostream> using namespace std;
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
cout << "The sentence contains" << count_ << "punct. character :\n" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
} // This code is contributed by shivanisinghss2110 |
// C++ program to illustrate // the iswpunct() function #include <stdio.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 <iostream> using namespace std;
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
cout << "The sentence contains " << count_ << "punct. character :\n" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
} // This code is contributed by shivanisinghss2110 |
// 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 : @ # $ ^