totn C Functions

C Language: ispunct function
(Test for Punctuation Character)

In the C Programming Language, the ispunct function tests whether c is a punctuation character. Punctuation characters are considered to be all printing characters except alphanumeric characters and space.

Syntax

The syntax for the ispunct function in the C Language is:

int ispunct(int c);

Parameters or Arguments

c
The value to test whether it is a punctuation character. Punctuation characters are considered to be all printing characters except alphanumeric characters and space.

Returns

The ispunct function returns a nonzero value if c is a punctuation character and returns zero if c is not a punctuation character.

Required Header

In the C Language, the required header for the ispunct function is:

#include <ctype.h>

Applies To

In the C Language, the ispunct function can be used in the following versions:

  • ANSI/ISO 9899-1990

ispunct Example

/* Example using ispunct by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define a temporary variable */
    unsigned char test;

    /* Assign a test punctuation character to the variable */
    test = ',';

    /* Test to see if this character is a punctuation character */
    if (ispunct(test) != 0) printf("%c is a punctuation character\n", test);
    else printf("%c is not a punctuation character\n", test);

    /* Assign a non-punctuation character to the variable */
    test = 'T';

    /* Test to see if this character is a punctuation character */
    if (ispunct(test) != 0) printf("%c is a punctuation character\n", test);
    else printf("%c is not a punctuation character\n", test);

    return 0;
}

When compiled and run, this application will output:

, is a punctuation character
T is not a punctuation character

Similar Functions

Other C functions that are similar to the ispunct function: