C programming ctype.h function - int ispunct(int c)

ht‮spt‬://www.theitroad.com

The int ispunct(int c) function in the ctype.h library of C programming is used to determine whether a given character is a punctuation character.

The ispunct() function takes a single integer argument c, which is the character to be checked. The function returns an integer value, which is nonzero if the character is a punctuation character, and zero otherwise.

Here's an example of how to use the ispunct() function in C:

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

int main() {
    char c = '!';
    if (ispunct(c)) {
        printf("%c is a punctuation character\n", c);
    } else {
        printf("%c is not a punctuation character\n", c);
    }
    return 0;
}

In this example, the ispunct() function is used to check whether the character '!' is a punctuation character. Since '!' is a punctuation character, the function returns a nonzero value, and the output will be: '!' is a punctuation character'.

If the character had been a non-punctuation character such as 'a', the ispunct() function would return zero, and the output would be: 'a' is not a punctuation character'.