Use isdigit() Function to check user input - C Data Type

C examples for Data Type:char

Introduction

isdigit() function takes one parameter.

isdigit(x) 

If the parameter x is a digit, the isdigit() function will return a true value; otherwise, a 0 or false value.

Demo Code

#include <stdio.h> 
#include <ctype.h> 
int main()/*  ww w  .j a  va  2  s  . c  o  m*/
{ 
   char cResponse = '\0'; 

   printf("\nPlease enter a letter: "); 
   scanf("%c", &cResponse); 

   if ( isdigit(cResponse) == 0 ) 
     printf("\nThank you\n"); 
   else 
     printf("\nYou did not enter a letter\n"); 
}

Result


Related Tutorials