C isdigit() function
C isdigit(int ch)
The isdigit() function is used to check whether a character is numeric character (0-9) or not. The function is defined in the ctype.h header file.
Numerical digit: A numerical digit (often shortened to just digit) is a single symbol used alone (such as "2") or in combinations (such as "25"), to represent numbers in a positional numeral system. The name "digit" comes from the fact that the ten digits (Latin digiti meaning fingers) of the hands correspond to the ten symbols of the common base 10 numeral system, i.e. the decimal (ancient Latin adjective decem meaning ten) digits.
Function Prototype of isdigit()
int isdigit( int arg );
isdigit() Parameters:
Name | Description | Required /Optional |
---|---|---|
ch | ch is a character of class digit in the current locale. | Required |
Return value from isdigit()
- The isdigit() function returns non-zero if ch is a decimal digit; otherwise, returns 0.
Example: C isdigit() function
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch = '5';
printf("\nIf %c is digit character or not? %d", ch, isdigit(ch));
ch='+';
printf("\nIf %c is digit character or not? %d", ch, isdigit(ch));
ch = 'f';
printf("\nIf %c is digit character or not? %d", ch, isdigit(ch));
return 0;
}
Output:
If 5 is digit character or not? 1 If + is digit character or not? 0 If f is digit character or not? 0
Example: C Program to check a input character is numeric character or not
#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 digit.",c);
else
printf("%c is a digit.",c);
return 0;
}
Output:
Input a character: 7 7 is a digit. ----------------------- Input a character: A A is not a digit.
C Programming Code Editor:
Contribute your code and comments through Disqus.
Previous C Programming: C iscntrl()
Next C Programming: C isgraph()
C Programming: Tips of the Day
What does the comma operator, do?
The expression:
(expression1, expression2)
First expression1 is evaluated, then expression2 is evaluated, and the value of expression2 is returned for the whole expression.
Ref : https://bit.ly/2XcIcsI
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook