isdigit in cpp code example

Example 1: isdigit c++

str = "10"
  
//Evaluates to True
isdigit(str[0])

Example 2: isdigit c++

int isdigit ( int c );
Checks whether c is a decimal digit character.
  
A value different from zero (i.e., true)
if indeed c is a decimal digit. Zero (i.e., false) otherwise.


/* isdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
  char str[]="1776ad";
  int year;
  if (isdigit(str[0]))
  {
    year = atoi (str);
    printf ("The year that followed %d was %d.\n",year,year+1);
  }
  return 0;
}  

/* Output */
The year that followed 1776 was 1777

Tags:

Cpp Example