C/C中的iswpunt()函数++

这个 iswpunct() 是C/C++中的一个函数,用于测试 宽字符码 代表着一种阶级特征 点刺 在程序的当前区域设置中。如果宽字符是标点符号宽字符代码,则返回非零,否则返回0。此函数在中定义 cwctype 头文件。该函数检查 中国 是不是标点符号。标点符号如下

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

语法:

int iswpunct(ch)

参数: 该函数只接受一个强制参数 中国 它指定要检查的字符。

返回值: 如果字符ch是标点符号,则函数返回非零值,否则返回零。

下面的程序演示了上述功能:

C++

// 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 :" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
}
// This code is contributed by shivanisinghss2110


C

// 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 :" , count_);
for ( int i = 0; i < count_; i++)
printf ( "%c " , string2[i]);
return 0;
}


输出:

The sentence contains 2 punct. character :~ !

项目2:

C++

// 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 :" ;
for ( int i = 0; i < count_; i++)
cout << " " << string2[i];
return 0;
}
// This code is contributed by shivanisinghss2110


C

// 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 :" , count_);
for ( int i = 0; i < count_; i++)
printf ( "%c " , string2[i]);
return 0;
}


输出:

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

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享