C library functions -isdigit()

C Standard Library - <ctype.h>

Description

C Library Functionsint isdigit(int c)Checks whether the passed character is a decimal digit character.

The decimal digits are: 0 1 2 3 4 5 6 7 8 9

Declaration

Below is the declaration of the isdigit() function.

int isdigit(int c);

Parameter

  • c-- This is the character to be checked.

Return Value

If c is a digit, the function returns a non-zero value; otherwise, it returns 0.

Example

The following example demonstrates the usage of the isdigit() function.

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

int main()
{
   int var1 = 'h';
   int var2 = '2';
    
   if( isdigit(var1) )
   {
      printf("var1 = |%c| 是一个数字\n", var1 );
   }
   else
   {
      printf("var1 = |%c| 不是一个数字\n", var1 );
   }
   if( isdigit(var2) )
   {
      printf("var2 = |%c| 是一个数字\n", var2 );
   }
   else
   {
      printf("var2 = |%c| 不是一个数字\n", var2 );
   }
  
   return(0);
}

Let us compile and run the above program, which will produce the following result:

var1 = |h| 不是一个数字
var2 = |2| 是一个数字

C Standard Library - <ctype.h>

other extensions