![]() Chapter Contents |
![]() Previous |
![]() Next |
| isdigit |
| Portability: | ISO/ANSI C conforming, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| CAUTION | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| 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: %s\n", id);
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.