C examples for ctype.h:ispunct
function
<cctype> <ctype.h>
Check if character is a punctuation character
int ispunct ( int c );
Parameter | Description |
---|---|
c | Character to be checked, casted to an int, or EOF. |
A non zero value (i.e., true) if indeed c is a punctuation character. Zero (i.e., false) otherwise.
#include <stdio.h> #include <ctype.h> int main ()//from w w w .j av a 2 s.c om { int i=0; int cx=0; char str[]="Hello, welcome!"; while (str[i]) { if (ispunct(str[i])) cx++; i++; } printf ("Sentence contains %d punctuation characters.\n", cx); return 0; }