参考文章:http://jimmee.iteye.com/blog/2174693
关于windows上编译libiconv的库,请参见:http://www.cnblogs.com/tangxin-blog/p/5608751.html
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdint.h> 4 #include <stdlib.h> 5 #include "iconv.h" 6 7 #define MAX_BUF_SIZE 1024 8 9 int code_convert(char *from_charset, char *to_charset, char *inbuf, size_t inlen, 10 char *outbuf, size_t outlen) { 11 iconv_t cd; 12 char **pin = &inbuf; 13 char **pout = &outbuf; 14 15 cd = iconv_open(to_charset, from_charset); 16 if (cd == 0) 17 return -1; 18 memset(outbuf, 0, outlen); 19 if (iconv(cd, pin, &inlen, pout, &outlen) == -1) 20 return -1; 21 iconv_close(cd); 22 *pout = '