iswpunct () es una función en C/C++ que comprueba si el código de caracteres anchos representa un carácter de clase punct en la configuración regional actual del programa. Devuelve un valor distinto de cero si Wide-Character es un código de puntuación de caracteres anchos; de lo contrario, devolverá 0. Esta función se define en el archivo de encabezado cwctype . La función comprueba si ch es un carácter de puntuación o no. Los caracteres de puntuación son como sigue
! " # $ % & ' () * +, - . / : ; ? @ [\] ^ _ ` {|} ~
Sintaxis:
int iswpunct(ch)
Parámetros: la función acepta un único parámetro obligatorio ch que especifica el carácter que se va a comprobar.
Valor devuelto: la función devuelve un valor distinto de cero si el carácter ch es un carácter de puntuación; de lo contrario, devuelve cero.
El siguiente programa ilustra la función anterior:
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 :\n"; 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 :\n", count_); for (int i = 0; i < count_; i++) printf("%c ", string2[i]); return 0; }
The sentence contains 2 punct. character : ~ !
Programa 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 :\n"; 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 :\n", count_); for (int i = 0; i < count_; i++) printf("%c ", string2[i]); return 0; }
The sentence contains 4 punct. character : @ # $^
Publicación traducida automáticamente
Artículo escrito por AmanSrivastava1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA