Y
yong
I want to use iconv.h to convert some text to another charset.
The code is below:
======
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>
int main()
{
iconv_t cd;
char instr[]="汉å—";
char *inbuf;
char *outbuf;
unsigned int insize=7;
unsigned int avail=10;
unsigned int nconv;
inbuf=instr;
outbuf=malloc(10);
cd=iconv_open("gbk","utf-8");
if(cd==(iconv_t)-1)
{
printf("fail.\n");
}
nconv=iconv(cd,&inbuf,&insize,&outbuf,&avail);
outbuf[5]='\0';
printf("%s\n",outbuf);
printf("nconv is: %d",nconv);
return 0;
}
======
But after all things is done the buffer area "outbuf" is still empty.It
doesn't output anything.Could someone give me some help?
Thanks.
The code is below:
======
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>
int main()
{
iconv_t cd;
char instr[]="汉å—";
char *inbuf;
char *outbuf;
unsigned int insize=7;
unsigned int avail=10;
unsigned int nconv;
inbuf=instr;
outbuf=malloc(10);
cd=iconv_open("gbk","utf-8");
if(cd==(iconv_t)-1)
{
printf("fail.\n");
}
nconv=iconv(cd,&inbuf,&insize,&outbuf,&avail);
outbuf[5]='\0';
printf("%s\n",outbuf);
printf("nconv is: %d",nconv);
return 0;
}
======
But after all things is done the buffer area "outbuf" is still empty.It
doesn't output anything.Could someone give me some help?
Thanks.