Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - isdigit()

C Library Function - isdigit()

C Standard Library - <ctype.h> C Standard Library -

Description

C Library Function int isdigit(int c) Check 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);

Parameters

Return Value

If c is a digit, the function returns a nonzero value; otherwise, it returns 0.

Example

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



#include 

#include 



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's compile and run the above program, which will produce the following result:



var1 = |h| 不是一个数字

var2 = |2| 是一个数字

C Standard Library - <ctype.h> C Standard Library -