我正在尝试将 UTF-16 字符串转换为 utf-8 并撞到一堵小墙。输出字符串包含字符但有空格!?输入是hi\0
and 如果我查看输出,它会说h\0i\0
而不是hi\0
.
你看到这里的问题了吗?非常感谢!
size_t len16 = 3 * sizeof(wchar_t);
size_t len8 = 7;
wchar_t utf16[3] = { 0x0068, 0x0069, 0x0000 }, *_utf16 = utf16;
char utf8[7], *_utf8 = utf8;
iconv_t utf16_to_utf8 = iconv_open("UTF-8", "UTF-16LE");
size_t result = iconv(utf16_to_utf8, (char **)&_utf16, &len16, &_utf8, &len8);
printf("%d - %s\n", (int)result, utf8);
iconv_close(utf16_to_utf8);