/*** gb2312 convert utf-8 ***/
#include
#include
#include
#include
int convertcode(char *inbuf,int inlen,char *outbuf,int outlen);
int main(void)
{
int len1,len2=20;
char *apin="我爱你";
len1=strlen(apin);
char apout[len2];
convertcode(apin,len1,apout,len2);
printf("the utf-8 is %s\n",apout);
return 0;
}
int convertcode(char *inbuf,int inlen,char *outbuf,int outlen)
{
iconv_t handle;
char **pin=&inbuf;
char **pout=&outbuf;
handle=iconv_open("utf-8","gb2312");
if( handle == 0 )
printf("error!\n");
memset(outbuf,0,outlen);
if(iconv(handle,pin,(size_t *)&inlen,pout,(size_t *)&outlen) == -1){
printf("iconv error!\n");
return -1;
}
iconv_close(handle);
return 0;
}
阅读(2687) | 评论(0) | 转发(0) |