/****************************************************************
* $ID: iconv_test.c 六, 31 10月 2009 16:10:35 +0800 gzq $ *
* *
* Description: *
* *
- Maintainer: (Bruce Gu) *
* *
* *
* This file is free software; *
* you are free to modify and/or redistribute it *
* under the terms of the GNU General Public Licence (GPL). *
* *
* Last modified: 六, 31 10月 2009 20:35:37 +0800 by gzq #
****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>
#include <string.h>
#include <errno.h>
int main(int argc,char **argvs)
{
if (argc >1)
{
char *str_in = argvs[1];
int in_len = strlen(str_in);
char *str_out,*p_out;
p_out = str_out = (char *)malloc(in_len);
printf("now str_out add:%p\n",str_out);
int out_len = in_len * 3;
iconv_t cd = iconv_open("GBK","UTF-8");
if (cd == (iconv_t) -1)
{
printf("error happend in:%s,line is:%d \r \nerror message:%s\n",__FUNCTION__,__LINE__,strerror(errno));
free(p_out);
return -1;
}
int ret = iconv(cd,&str_in,&in_len,&str_out,&out_len);
printf("now str_out add:%p\n",p_out);
if (ret <0)
printf("error happend in:%s,line is:%d \r \nerror message:%s\n",__FUNCTION__,__LINE__,strerror(errno));
iconv_close(cd);
if ((iconv_t) ret != (iconv_t) -1 || !in_len)
printf("now utf-8 string is:%s\n",p_out);
// printf("now utf-8 string is:%s\n",str_out);
free(p_out);
}
else
{
printf("input need convert string \n.");
}
}
/****************** End Of File: iconv_test.c ******************/
|