isdigit -- Test for Numeric Character

SYNOPSIS

 #include <ctype.h>

 int isdigit(int c);
 

DESCRIPTION

isdigit tests an integer value to determine whether it is a numeric character (digit).

RETURN VALUE

isdigit returns 0 if the character is not a digit, or a nonzero value if it is. If the argument is EOF, 0 is returned.

CAUTION

The effect of isdigit on a noncharacter argument other than EOF is undefined. Do not assume that isdigit returns either 0 or 1.

EXAMPLE

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

  #define IDMAX 40

  main()
  {
     char id[IDMAX+1];
     char *text;
     char input[IDMAX];
     int i;

     puts("Enter a string of numbers/characters (maximum 40):");
     text = gets(input);

        /* Copy a string of digits from text to id. */
     for (i = 0; i < IDMAX && isdigit(text[i]); ++i)
        id[i] = text[i];

     id[i] = '0';
        /* Only the digits should be copied. */
     printf("You first entered these digits: %sn", id);
  }

 

RELATED FUNCTIONS

isxdigit

SEE ALSO

Character Type Macros and Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.