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:


#include<stdio.h>
#include<ctype.h>
int main()
{
	int counter=0;
	int counter2=0;

	char str[]="Hello, World!!";
	while (str[counter])
	{
		if (ispunct(str[counter])) counter2++;
		counter++;
	}
	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. You can leave a response, or trackback from your own site. Tweet This! Tweet This! or use to share this post with others.

Leave a Reply: