ispunct() function in C

Using the ispunct() function in C

The ispunct() function in C is used to check whether a character is a punctuation character. The function takes a character as input and returns a non-zero value if the character is a punctuation character, or zero if the character is not a punctuation character.

A punctuation character is a character that is used to separate words or clauses in a sentence. Some examples of punctuation characters are:

  • Period (.)

  • Comma (,)

  • Question mark (?)

  • Exclamation point (!)

  • Apostrophe (‘)

  • Quotation mark (” or ‘)

  • Hyphen (-)

  • Dash (-)

  • Slash (/)

  • Backslash ()

Here is an example of how to use the ispunct() function:

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

int32_t main(int32_t argc, char const *argv[])
{
    char c = ',';

    int32_t result = ispunct(c);

    if (result > 0x00)
    {
        printf("The character '%c' is a punctuation character.\n", c);
    }
    else
    {
        printf("The character '%c' is not a punctuation character.\n", c);
    }

    return 0;
}

The ispunct() function takes a character as input and returns a non-zero value if the character is a punctuation character, or zero if the character is not a punctuation character. In this example, the character '.' is a punctuation character, so the function will return a non-zero value and the printf() statement will print the output.

Explore the complete list of functions available in ctype header in C standard library.

0
Subscribe to my newsletter

Read articles from Muhammad Hassaan Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Muhammad Hassaan Shah
Muhammad Hassaan Shah

Passionate about new technological trends and like to share practical tips and tutorials about C, C++, Python, MATLAB, STM32, Arduino, ESP32, and more …