C/C++の宿題を片付けます 122代目at TECH
C/C++の宿題を片付けます 122代目 - 暇つぶし2ch167:デフォルトの名無しさん
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