我想将其他编码中的数据转换为UTF-8.我陷入了以下问题:
pointer being freed was not allocatediconv().为什么iconv与我的记忆一起玩?void utf8(char **dst, char **src, const char *enc)
{
iconv_t cd;
size_t len_src,
len_dst;
len_src = strlen(*src);
len_dst = len_src * 8; // is that enough for ASCII to UTF8?
cd = iconv_open("UTF-8", enc);
*dst = (char *)calloc(len_dst+1, 1);
iconv(cd, src, &len_src, dst, &len_dst);
iconv_close(cd);
}
int main(int argc, char **argv)
{
char *src = "hello world";
char *dst;
utf8(&dst, &src, "ASCII");
printf("%s\n", dst);
free(dst);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 如何从字符串中获取具有最大ascii值的char?
$str = 'abcb'
# extract biggest char somehow
# as a result $char contains "c"
Run Code Online (Sandbox Code Playgroud)