iswpunct() function in C/C++
Last Updated :
23 Sep, 2021
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++
#include <iostream>
using namespace std;
int main()
{
int i = 0;
int count_ = 0;
char string1[] = "~Hello geekforgeeks !" ;
char string2[count_];
while (string1[i]) {
if (iswpunct(string1[i])) {
string2[count_] = string1[i];
count_++;
}
i++;
}
cout << "The sentence contains" << count_ << "punct. character :\n" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
}
|
C
#include <stdio.h>
int main()
{
int i = 0;
int count_ = 0;
char string1[] = "~Hello geekforgeeks !" ;
char string2[count_];
while (string1[i]) {
if (iswpunct(string1[i])) {
string2[count_] = string1[i];
count_++;
}
i++;
}
printf ( "The sentence contains %d punct. character :\n" , count_);
for ( int i = 0; i < count_; i++)
printf ( "%c " , string2[i]);
return 0;
}
|
Output:
The sentence contains 2 punct. character :
~ !
Program 2 :
C++
#include <iostream>
using namespace std;
int main()
{
int i = 0;
int count_ = 0;
char string1[] = "@#$^gfg" ;
char string2[count_];
while (string1[i]) {
if (iswpunct(string1[i])) {
string2[count_] = string1[i];
count_++;
}
i++;
}
cout << "The sentence contains " << count_ << "punct. character :\n" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
}
|
C
#include <bits/stdc++.h>
int main()
{
int i = 0;
int count_ = 0;
char string1[] = "@#$^gfg" ;
char string2[count_];
while (string1[i]) {
if (iswpunct(string1[i])) {
string2[count_] = string1[i];
count_++;
}
i++;
}
printf ( "The sentence contains %d punct. character :\n" , count_);
for ( int i = 0; i < count_; i++)
printf ( "%c " , string2[i]);
return 0;
}
|
Output:
The sentence contains 4 punct. character :
@ # $ ^
Share your thoughts in the comments
Please Login to comment...