当前位置: 技术问答>linux和unix
关于用iconv函数作编码转换的问题
来源: 互联网 发布时间:2015-06-07
本文导语: /* test.c */ #include #define BUFFLEN 1024 int main(){ char inbuff[BUFFLEN]; char outbuff[BUFFLEN]; int inlen,outlen,i; char* pin=inbuff; char* pout=outbuff; iconv_t cd; outlen=BUFFLEN; strcpy(inbuff,"HI,你好。这是测试I。"); inlen=strlen(inbuff); if(...
/* test.c */
#include
#define BUFFLEN 1024
int main(){
char inbuff[BUFFLEN];
char outbuff[BUFFLEN];
int inlen,outlen,i;
char* pin=inbuff;
char* pout=outbuff;
iconv_t cd;
outlen=BUFFLEN;
strcpy(inbuff,"HI,你好。这是测试I。");
inlen=strlen(inbuff);
if((cd=iconv_open("GB2312","UNICODE"))==(iconv_t)-1)
perror("Fail openn");
if(iconv(cd,&pin,&inlen,&pout,&outlen)==(size_t)-1)
perror("Fail iconvn");
iconv_close(cd);
printf("%sn",inbuff);
for(i=0;i
#include
#define BUFFLEN 1024
int main(){
char inbuff[BUFFLEN];
char outbuff[BUFFLEN];
int inlen,outlen,i;
char* pin=inbuff;
char* pout=outbuff;
iconv_t cd;
outlen=BUFFLEN;
strcpy(inbuff,"HI,你好。这是测试I。");
inlen=strlen(inbuff);
if((cd=iconv_open("GB2312","UNICODE"))==(iconv_t)-1)
perror("Fail openn");
if(iconv(cd,&pin,&inlen,&pout,&outlen)==(size_t)-1)
perror("Fail iconvn");
iconv_close(cd);
printf("%sn",inbuff);
for(i=0;i