iconv API を使用して sjis 文字列を utf-8 に変換しようとしています。すでに正常にコンパイルされていますが、出力は期待したものではありません。私のコード:
void convertUtf8ToSjis(char* utf8, char* sjis){
iconv_t icd;
int index = 0;
char *p_src, *p_dst;
size_t n_src, n_dst;
icd = iconv_open("Shift_JIS", "UTF-8");
int c;
p_src = utf8;
p_dst = sjis;
n_src = strlen(utf8);
n_dst = 32; // my sjis string size
iconv(icd, &p_src, &n_src, &p_dst, &n_dst);
iconv_close(icd);
}
ランダムな数字しか得られませんでした。何か案は?
編集:私の入力は
char utf8[] = "\xe4\xba\x9c"; //亜
出力は次のようになります: 0x88 0x9F
しかし実際には: 0x30 0x00 0x00 0x31 0x00 ...