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

htt‮p‬s://www.theitroad.com

The int isdigit(int c) function in the ctype.h library of C programming is used to determine whether a given character is a decimal digit (0-9).

The isdigit() 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 digit, and zero otherwise.

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

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

int main() {
    char c = '7';
    if (isdigit(c)) {
        printf("%c is a digit\n", c);
    } else {
        printf("%c is not a digit\n", c);
    }
    return 0;
}

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

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