#include <ctype.h> int isxdigit(int c);
isxdigit
tests an integer value c
to determine whether it is a
hexadecimal digit (uppercase or lowercase).
isxdigit
returns 0 if the character is not a hexadecimal digit, or a
nonzero value if it is. If the argument is EOF
, 0 is returned.
isxdigit
on a noncharacter argument other than
EOF
is undefined. Do not assume that isxdigit
returns
either 0 or 1.
#include <ctype.h> #include <stdio.h> #define IDLEN 40 main() { char line[IDLEN]; char id[IDLEN+1]; char *text; int i; puts("Enter a string consisting of hexadecimal characters: "); text = gets(line); /* Copy from text to id. */ for (i = 0; i < IDLEN ; ++i) { if (isxdigit(text[i])) id[i] = text[i]; else id[i] = '*'; } id[i] = '0'; /* All nonhex characters have been replaced by '*'. */ puts("You have entered the following hexadecimal characters:"); printf("%sn", id); }
isdigit
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.