Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
120 views

C Isdigit - C Standard Library

The isdigit() function checks whether a character is a numeric character between 0-9. It takes an integer as a parameter, but a character is actually passed in. It returns a non-zero integer if the character is numeric, or zero if it is not numeric. The function is defined in the ctype.h header file. Examples demonstrate passing numeric and non-numeric characters to isdigit() and printing the return values.

Uploaded by

Marcelo Luna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views

C Isdigit - C Standard Library

The isdigit() function checks whether a character is a numeric character between 0-9. It takes an integer as a parameter, but a character is actually passed in. It returns a non-zero integer if the character is numeric, or zero if it is not numeric. The function is defined in the ctype.h header file. Examples demonstrate passing numeric and non-numeric characters to isdigit() and printing the return values.

Uploaded by

Marcelo Luna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Firefox https://www.programiz.com/c-programming/library-function/ctype.

h/isdigit

C isdigit()
The isdigit() function checks whether a character is
numeric character (0-9) or not.

Function Prototype of isdigit()

int isdigit( int arg );

Function isdigit() takes a single argument in the form of


an integer and returns the value of type int .

Even though, isdigit() takes integer as an argument,


character is passed to the function. Internally, the
character is converted to its ASCII value for the check.

It is defined in <ctype.h> (/c-programming/library-


function/ctype.h) header file.

C isdigit() Return value

Return Value Remarks

Non-zero integer ( x > 0


Argument is a numeric character.
)

Argument is not a numeric


Zero (0)
character.

Example: C isdigit() function

1 of 3 9/9/2022, 9:33 PM
Firefox https://www.programiz.com/c-programming/library-function/ctype.h/isdigit

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

int main()
{
char c;
c='5';
printf("Result when numeric character is passed: %d"

c='+';
printf("\nResult when non-numeric character is passed: %d"

return 0;
}

Output

Result when numeric character is passed: 1


Result when non-numeric character is passed: 0

Example: C Program to Check whether a


Character Entered by User 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

2 of 3 9/9/2022, 9:33 PM
Firefox https://www.programiz.com/c-programming/library-function/ctype.h/isdigit

Enter a character: 8
8 is a digit.

3 of 3 9/9/2022, 9:33 PM

You might also like