isdigit function(Test for Digit) in C Language – example and detail

In the C Programming Language, the isdigit characteristic exams whether or not 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 feature returns a nonzero fee if c is a digit and returns zero if c is no longer 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 characteristic 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:

isxdigit function <ctype.h>

See Also

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

isalnum function <ctype.h>