C ispunct () - C Standardbibliotek

Funktionen ispunct () kontrollerer, om et tegn er et tegnsætningstegn eller ej.

Funktionsprototypen for ispunct()er:

 int ispunct(int argument);

Hvis et tegn, der sendes til ispunct()funktionen, er en tegnsætning, returnerer det et heltal, der ikke er nul. Hvis ikke, returnerer den 0.

I C-programmering behandles tegn internt som heltal. Derfor ispunct()tager et heltal argument.

Den ispunct()funktion er defineret i ctype.h header fil.

Eksempel 1: Program til at kontrollere tegnsætning

 #include #include int main() ( char c; int result; c = ':'; result = ispunct(c); if (result == 0) ( printf("%c is not a punctuation", c); ) else ( printf("%c is a punctuation", c); ) return 0; )

Produktion

 : er tegnsætning 

Eksempel 2: Udskriv alle tegnsætninger

 #include #include int main() ( int i; printf("All punctuations in C: "); // looping through all ASCII characters for (i = 0; i <= 127; ++i) if(ispunct(i)!= 0) printf("%c ", i); return 0; ) 

Produktion

Alle tegnsætninger i C:! "# $% & '() * +, -. /:;? @ () _` (|) ~

Interessante artikler...