Chinaunix首页 | 论坛 | 博客
  • 博客访问: 173986
  • 博文数量: 31
  • 博客积分: 1075
  • 博客等级: 少尉
  • 技术积分: 215
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 17:51
个人简介

1

文章分类

全部博文(31)

文章存档

2013年(1)

2012年(4)

2010年(26)

我的朋友

分类: LINUX

2010-04-21 14:59:25

 
转自:


楼主,我给你一段代码。在linux gsoap和java axis webservice传数据屡试不爽。。。

int code_convert(char *from_charset, char *to_charset, char *inbuf, int inlen, char *outbuf, int outlen)
{
iconv_t cd;
int rc;
char **pin = &inbuf;
char **pout = &outbuf;

cd = iconv_open(to_charset, from_charset);

if (cd == 0)
return 1;

memset(outbuf, 0, outlen);

if (iconv(cd, pin, &inlen, pout, &outlen) == -1)
return 1;

iconv_close(cd);
return 0;
}



我也发一个自己写的程序,一直在用的

/******************************************************
EncodingConv.c
使用iconv进行字符编码转换
SUNLAN
2006/08/17
******************************************************/

#include
#include
#include
#include
#include "SDKpub.h"

#ifndef ERRFILE
#define ERRFILE "errlog"
#endif

char * EncodingConv(  const char * in, char *encFrom, char *encTo )
{

char *buff, *sin, *sout;
int lenin, lenout;
iconv_t ct;

if( (ct=iconv_open(encTo, encFrom)) == (iconv_t)-1 )
{
SDKerrlog( ERRFILE, "%s|%d| iconv_open error! %s", __FILE__,
__LINE__, strerror(errno) );
return( NULL );
}

iconv( ct, NULL, NULL, NULL, NULL );

sin = (char *)in;
lenin  = strlen(in) + 1;

if( (buff=malloc( lenin*2 ))==NULL )
{
SDKerrlog( ERRFILE, "%s|%d| malloc error! %s", __FILE__, __LINE__,
strerror(errno) );
iconv_close( ct );
return( NULL );
}
sout   = buff;
lenout = lenin*2;

if( iconv( ct, &sin, (size_t *)&lenin, &sout, (size_t *)&lenout) == -1 )
{
SDKerrlog( ERRFILE, "%s|%d| iconv() error! errno=%d %s", __FILE__,
__LINE__, errno, strerror(errno) );
free( buff );
iconv_close( ct );
return NULL;
}

iconv_close( ct );

sout=strdup(buff);
free( buff );

return( sout );
}

over
阅读(2180) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~