6.3.5 isdigit Function

Test for a decimal digit.

Include

<ctype.h>

Prototype

int isdigit(int c);

Argument

c
The character to test.

Return Value

Returns a non-zero integer value if the character, c, is a digit; otherwise, returns zero.

Remarks

A character is considered to be a digit character if it is in the range of '0'-'9'.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  int ch;

  ch = '3';
  if (isdigit(ch))
    printf("3 is a digit\n");
  else
    printf("3 is NOT a digit\n");

  ch = '#';
  if (isdigit(ch))
    printf("# is a digit\n");
  else
    printf("# is NOT a digit\n");
}

Example Output

3 is a digit
# is NOT a digit