totn C Functions

C Language: isdigit function
(Test for Digit)

In the C Programming Language, the isdigit function tests whether c is a digit.

Syntax

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

int isdigit(int c);

Parameters or Arguments

c
The value to test whether it is a digit.

Returns

The isdigit function returns a nonzero value if c is a digit and returns zero if c is not a digit.

Required Header

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

#include <ctype.h>

Applies To

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

  • ANSI/ISO 9899-1990

isdigit Example

/* Example using isdigit 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 decimal digit character to the variable */
    test = '7';

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

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

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

    return 0;
}

When compiled and run, this application will output:

7 is a decimal digit character
T is not a decimal digit character

Similar Functions

Other C functions that are similar to the isdigit function:

See Also

Other C functions that are noteworthy when dealing with the isdigit function: