6.3.9 ispunct Function

Test for a punctuation character.

Include

<ctype.h>

Prototype

int ispunct (int c);

Argument

c
The character to test.

Return Value

Returns a non-zero integer value if the character, c, is a punctuation character; otherwise, returns zero.

Remarks

A character is considered to be a punctuation character if it is a printable character which is neither a space nor an alphanumeric character. Punctuation characters consist of the following:
'!'  '"'  '#'  '$'  '%'  '&'  '''  '('  ')'  '*'  '+'  ','  '-'  '.'  '/'  ':'
';'  '<'  '='  '>'  '?'  '@'  '['  '\'  ']'  '^'  '_'  '`'  '{'  '|'  '}'  '~'

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <ctype.h>
#include <stdio.h>

int main(void)
{
  int ch;

  ch = '&';
  if (ispunct(ch))
    printf("& is a punctuation character\n");
  else
    printf("& is NOT a punctuation character\n");

  ch = '\t';
  if (ispunct(ch))
    printf("A tab is a punctuation character\n");
  else
    printf("A tab is NOT a punctuation character\n");
}

Example Output

& is a punctuation character
A tab is NOT a punctuation character