编码转换(utf8转换为gb2312)

//编码转换(utf8转换为gb2312)
int utf8togb2312(char *sourcebuf,size_t sourcelen,char *destbuf,size_t destlen)
{
    iconv_t cd;
    if( (cd = iconv_open("gb2312", "utf-8")) ==0 )
    {
        return -1;
    }
    memset(destbuf,0,destlen);
    char** source = &sourcebuf;
    char** dest = &destbuf;
    if(-1 == iconv(cd,source,&sourcelen,dest,&destlen))
    {
        return -1;
    }
    iconv_close(cd);


    return 0;
}

你可能感兴趣的:(编码转换(utf8转换为gb2312))