Latest web development tutorials

C library functions - isdigit ()

C standard library - <ctype.h> C standard library - <ctype.h>

description

C library functionsvoid isdigit (int c) Check preaching character is a decimal digit character.

The decimal numbers: 0123456789

statement

Here is () statement isdigit function.

int isdigit(int c);

parameter

  • c - This was a test of character.

return value

If c is a number, the function returns a nonzero value, otherwise return 0.

Examples

The following example demonstrates isdigit () function is used.

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

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

C standard library - <ctype.h> C standard library - <ctype.h>