全角・半角の判定(シフトJIS)

文字列 s が全角か半角か判定します。
第2バイト目があることが前提ですが、NULL文字で終わる文字列なら平気です。

全角判定

// 全角判定(シフトJIS)
is_zenkaku(char *s){
    unsigned char c = s[0];
    if ( (c>=0x81 && c<=0x9f) || (c>=0xe0 && c<=0xfc)){    // 全角の第1バイト
        c=s[1];
        if (c>=0x40 && c<=0xfc) return 1;    // 全角の第2バイト
    }
    return 0;
}






戻る