C/C++の宿題を片付けます 122代目
at TECH
167:デフォルトの名無しさん
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;
}
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5377日前に更新/102 KB
担当:undef