📜  C / C++中的iswpunct()函数

📅  最后修改于: 2021-05-25 23:45:57             🧑  作者: Mango

iswpunct()是C / C++中的一个函数,用于测试Wide-Character代码是否表示程序当前语言环境中的punct类字符。如果Wide-Character是标点符号宽字符代码,则返回非零值,否则应返回0。此函数在cwctype头文件中定义。该函数检查ch是否为标点字符。标点字符为跟随

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

句法 :

int iswpunct(ch)

参数:该函数接受单个强制参数ch ,该参数指定要检查的字符。

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

下面的程序说明了上述函数:

// C++ program to illustrate
// the iswpunct() function
#include 
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 :
~ !

程序2:

// C++ program to illustrate
// the iswpunct() function
#include 
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 :
@ # $ ^
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。