C Reference Punctuation Character: ispunct()

The ispunct() function returns a non-zero if its argument is a punctuation character. (All characters except alphanumeric or white-space). If the argument is not a punctuation character, then zero is returned.

ispunct() source code example:

int main()
	int counter=0;
	int counter2=0;

	char str[]="Hello, World!!";
	while (str[counter])
		if (ispunct(str[counter])) counter2++;
	printf ("%d punctuation characters in the sentence.\n", counter2);
  	return 0;

Note: in this case there are three punctuation characters (the , and !! ).

This entry was posted in C Reference ctype.h Functions. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed. Tweet This! Tweet This! or use to share this post with others.

Comments are closed.