/*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <ctype.h>
/*---------------------------------------------------------------------------*/
int htoi(char *hex) {

    int index,value;

    if (hex[0] == '0' && toupper(hex[1]) == 'X')
        index = 1;
    else index = -1;
    value = 0;

    while (hex[++index] != '\0') {
        if (!isxdigit(hex[index]))
                return(-1);
        else value = value*16 + ((isdigit(hex[index])) ? hex[index] - '0' :
toupper(hex[index]) - 'A' + 10);
    }

    return(value);
}

/*---------------------------------------------------------------------------*/
int main(int argc,char *argv[]) {

    printf("Value of %s is %d\n",argv[1],htoi(argv[1]));

    return(0);
}
/*---------------------------------------------------------------------------*/
