Die Funktion ispunct () prüft, ob ein Zeichen ein Interpunktionszeichen ist oder nicht.
Der Funktionsprototyp von ispunct()
ist:
int ispunct(int argument);
Wenn ein an die ispunct()
Funktion übergebenes Zeichen eine Interpunktion ist, wird eine Ganzzahl ungleich Null zurückgegeben. Wenn nicht, wird 0 zurückgegeben.
Bei der C-Programmierung werden Zeichen intern als Ganzzahlen behandelt. Deshalb ispunct()
wird ein ganzzahliges Argument verwendet.
Die ispunct()
Funktion ist in der Header-Datei ctype.h definiert.
Beispiel 1: Programm zur Überprüfung der Interpunktion
#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; )
Ausgabe
: ist eine Interpunktion
Beispiel 2: Alle Interpunktionen drucken
#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; )
Ausgabe
Alle Interpunktionen in C :! "# $% & '() * +, -. /:;? @ () _` (|) ~