#include #include #define STR_MAX 20 #define FALSE 0 #define TRUE 1 int chk_hex( str ) char *str; { while ( *str ) { if ( !isxdigit( *str ) ) return FALSE; str++; } return TRUE; } main() { char hex[STR_MAX]; int num; printf("hexadecimal = "); scanf("%s", hex); if ( chk_hex( hex ) ) { sscanf(hex, "%x", &num); printf("%d\n", num); exit(0); } else { printf("not a hexiadecimal number\n"); exit(1); } }