当前位置: 技术问答>linux和unix
mysql编码转换
来源: 互联网 发布时间:2016-06-25
本文导语: 请给出linux下c语言实现的编码转换从gb2312转换为utf8。谢谢了。刚接触linux.谢谢大家帮助! | #include #include #include #define OUTLEN 255 int code_convert(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char ...
请给出linux下c语言实现的编码转换从gb2312转换为utf8。谢谢了。刚接触linux.谢谢大家帮助!
|
#include
#include
#include
#define OUTLEN 255
int code_convert(char *from_charset,char *to_charset,char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
iconv_t cd;
char **pin = &inbuf;
char **pout = &outbuf;
cd = iconv_open(to_charset,from_charset);
if (cd==0) return -1;
memset(outbuf,0,outlen);
if (iconv(cd,pin,&inlen,pout,&outlen)==(size_t)-1) return -1;
iconv_close(cd);
return 0;
}
int u2g(char *inbuf,int inlen,char *outbuf,int outlen)
{
return code_convert("utf-8","gb2312",inbuf,inlen,outbuf,outlen);
}
int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
return code_convert("gb2312","utf-8",inbuf,inlen,outbuf,outlen);
}
|
|
up,iconv,好像系统本身就有