De functie ispunct () controleert of een teken een leesteken is of niet.
Het functieprototype van ispunct()
is:
int ispunct(int argument);
Als een teken dat aan de ispunct()
functie wordt doorgegeven een interpunctie is, retourneert het een geheel getal dat niet gelijk is aan nul. Als dit niet het geval is, wordt 0 geretourneerd.
Bij C-programmering worden karakters intern als gehele getallen behandeld. Dat is waarom ispunct()
een integer-argument wordt gebruikt.
De ispunct()
functie is gedefinieerd in het header-bestand ctype.h.
Voorbeeld 1: programma om interpunctie te controleren
#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; )
Uitvoer
: is een interpunctie
Voorbeeld 2: druk alle leestekens af
#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; )
Uitvoer
Alle leestekens in C:! "# $% & '() * +, -. /:;? @ () _` (|) ~