C isdigit function checks to see if a character is a digit or not

Syntax

C isdigit function has the following syntax.

int isdigit(int ch);

C isdigit function is from header file ctype.h.

Description

C isdigit function returns nonzero if ch is a digit or zero is returned.

Example

The following code uses C isdigit function to check if a character is a digit.


#include <ctype.h>
#include <stdio.h>
/*ww  w  . j ava 2s  .c  o  m*/
int main(void)
{
  char ch;

  for(;;) {
    ch = getchar();
    if(ch == '.'){
        break;
    }
    if(isdigit(ch)){
        printf("%c is a digit\n", ch);
    }
  }

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h