当前位置: 技术问答>linux和unix
iconv.h 问题
来源: 互联网 发布时间:2016-05-21
本文导语: 请问iconv.h中的iconv函数怎么用的 是c语言的 ,谢谢!! | #include ; #include ; #include ; #include ; #include ; #include ; #include ; #define BUFLEN 200 main() { char inbuf[BUFLEN]; char outbuf[BUFLEN];...
请问iconv.h中的iconv函数怎么用的 是c语言的 ,谢谢!!
|
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#define BUFLEN 200
main()
{
char inbuf[BUFLEN];
char outbuf[BUFLEN];
char* pin = inbuf;
char* pout = outbuf;
//读入GB2312数据到inbuf,数据长度为 len
int inleft = 10;
int outleft = BUFLEN;
memset(inbuf,0,sizeof(inbuf));
memset(outbuf,0,sizeof(outbuf));
sprintf(inbuf,"我是中国人");
iconv_t cd;
if((cd = iconv_open("gb2312","unicode")) == (iconv_t)-1)
{
perror("iconv_open():");
exit(0);
}
if(iconv(cd, &pin, &inleft, &pout, &outleft) == (size_t)-1)
{
perror("iconv():");
exit(0);
}
iconv_close(cd);
printf("%s",outbuf);
}
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#define BUFLEN 200
main()
{
char inbuf[BUFLEN];
char outbuf[BUFLEN];
char* pin = inbuf;
char* pout = outbuf;
//读入GB2312数据到inbuf,数据长度为 len
int inleft = 10;
int outleft = BUFLEN;
memset(inbuf,0,sizeof(inbuf));
memset(outbuf,0,sizeof(outbuf));
sprintf(inbuf,"我是中国人");
iconv_t cd;
if((cd = iconv_open("gb2312","unicode")) == (iconv_t)-1)
{
perror("iconv_open():");
exit(0);
}
if(iconv(cd, &pin, &inleft, &pout, &outleft) == (size_t)-1)
{
perror("iconv():");
exit(0);
}
iconv_close(cd);
printf("%s",outbuf);
}