09/01/17 18:20:56
>>163
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int do_hex(char *str)
{
static const char hex[] = "0123456789abcdef";
static const int digit = sizeof(hex) - 1;
int ch, ret = 0;
char *p;
while(*str != '\0'){
ch = tolower(*str);
p = strchr(hex, ch);
if(p == NULL){
fprintf(stderr, "卑猥な文字:%c\n", *str);
exit(1);
}
ret = digit * ret + (int)(p - hex);
str++;
}
return ret;
}
int main(void)
{
char buf[256];
scanf("%255s", buf);
printf("%s(16) -> %d(10)\n", buf, do_hex(buf));
return 0;
}