C ispunct() library function

ispunct() function checks whether a character is punctuation character or not. A character is a punctuation character, If it is a graphical character but not an alphanumeric character.

For Example
% & ' $ + - * ? etc.

Function prototype of ispunct

int ispunct(int c);
Function ispunct() takes a character as input in form of an integer. When we pass a value of type char to ispunct() function, corresponding ASCII value of that character is passed.

Return value of ispunct

If passed character is a punctuation character, then ispunct function returns non-zero(true) integer otherwise 0(false).

C program using ispunct function

The following program is to check whether a character is punctuation character or not.

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

int main(){
    char string[] = "A1,/?";
    int index = 0;
    
    while(string[index] != '\0'){
        if(ispunct(string[index])){
            printf("'%c' is a punctuation character\n", string[index]);
        } else {
            printf("'%c' is not a punctuation character\n", string[index]);
        }
        index++;
    }
    
    return 0;
}

Output
'A' is not a punctuation character
'1' is not a punctuation character
',' is a punctuation character
'/' is a punctuation character
'?' is a punctuation character