English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
isdigit() function checks if a character is a digit character (0-9)。
int isdigit(int arg);
The function isdigit() accepts a single parameter in integer form and returns a value of type int.
Even if isdigit() takes an integer as a parameter, the character is passed to the function. Internally, the character is converted to its ASCII value for checking.
It is<ctype.h>Defined in header file.
Return value | Description |
---|---|
Non-zero integer (x > 0) | The parameter is a digit character. |
0 | The parameter is not a digit character. |
#include <stdio.h> #include <ctype.h> int main() { char c; c='5'; printf("Result when passing a digit character: %d", isdigit(c)); c='+'; printf("\nResult when passing a non-digit character: %d", isdigit(c)); return 0; }
Output Result
Result when passing a digit character: 1 Result when passing a non-digit character: 0
#include <stdio.h> #include <ctype.h> int main() { char c; printf("Enter a character: "); scanf("%c", &c); if (isdigit(c) == 0) printf("%c is not a number.", c); else printf("%c is a number.", c); return 0; }
Output Result
Enter a character: 8 8It is a number.