function::isdigit - Linux


Overview

The isdigit function in Linux determines whether a character is a digit (0-9). It is commonly used in programming to validate user input, perform numerical operations, and parse data.

Syntax

bool isdigit(int c);
  • c: The ASCII value of the character to be tested.

Options/Flags

None.

Examples

# Check if '7' is a digit
if (isdigit('7'))
    printf("True\n");
else
    printf("False\n");

# Check if 'a' is a digit
if (isdigit('a'))
    printf("True\n");
else
    printf("False\n");

Common Issues

  • Non-ASCII characters: isdigit only works with ASCII characters. For non-ASCII characters, use ctype.h functions like iswdigit.

Integration

isdigit can be used with other standard library functions, such as:

  • strtol: Convert a string to a long integer, checking for non-digits.
  • atoi: Convert a string to an integer, ignoring non-digits.

Related Commands

  • isalpha: Checks if a character is alphabetical.
  • isalnum: Checks if a character is alphanumeric.
  • isgraph: Checks if a character is a printable character (not whitespace or control character).