ispunct - C ctype.h

C examples for ctype.h:ispunct

Type

function

From

<cctype> 
<ctype.h>

Description

Check if character is a punctuation character

Prototype

int ispunct ( int c );

Parameters

Parameter Description
c Character to be checked, casted to an int, or EOF.

Return Value

A non zero value (i.e., true) if indeed c is a punctuation character. Zero (i.e., false) otherwise.

Demo Code


#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;
}

Related Tutorials