Isnum in c – isdigit C Library Function

isdigit function checks whether a character is decimal digit character or not.

Set of decimal digit(numeric) characters : 0 1 2 3 4 5 6 7 8 9.

Function prototype of isdigit

int isdigit(int c);

Isnum in c: Function isdigit takes a character as input in form of an integer. When we pass a value of type char to isdigit function, corresponding ASCII value of that character is passed.

Return value of isdigit

C programming isdigit: If passed character is a decimal digit character, then isdigit function returns non-zero integer otherwise 0.

C program using isdigit function

Isdigit c: The following program is to check whether a character is decimal digit character or not.

isdigit C Library Function

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
 
int main(){
    char string[] = "1a. A";
    int index = 0;
     
    while(string[index] != '\0'){
        if(isdigit(string[index])){
            printf("'%c' is a digit\n", string[index]);
        } else {
            printf("'%c' is not a digit\n", string[index]);
        }
        index++;
    }
     
    getch();
    return 0;
}

Output

'1' is a digit
'a' is not a digit
'.' is not a digit               
' ' is not a digit
'A' is not a digit