English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function ispunct()

C Standard Library <ctype.h>

ispunct() function checks whether a character is a punctuation symbol.

The prototype of ispunct() function is:

int ispunct(int argument);

If the character passed to the ispunct() function is a punctuation symbol, it returns a non-zero integer. If not, it returns 0.

In C language programming, char characters are internally treated as integers. This is why ispunct() uses an integer parameter.

The ispunct() function inctype.hDefined in header files.

Example1Check punctuation program

#include <stdio.h>
#include <ctype.h>
int main() {
   char c;
   int result;
   c = ':';
   result = ispunct(c);
   if (result == 0) {
      printf("%c is not a punctuation symbol", c);
   } else {
      printf("%c is a punctuation symbol", c);
   }
   return 0;
}

Output Result

: It is a punctuation symbol

Example2Print all punctuations

#include <stdio.h>
#include <ctype.h>
int main()
{
    int i;
    printf("All punctuation symbols in C:\n");
    //traverse all ASCII characters
    for (i = 0; i <= 127; ++i)
        if (ispunct(i) != 0)
            printf("%c ", i);
    return 0;
}

Output Result

All Punctuation Symbols in C: 
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~

C Standard Library <ctype.h>