Windows客户端 Linux服务器通讯 字符编码问题

Windows下的字符编码默认是gb2312 在Linux下需要转成utf8 才能正确的看到对应的中文编码 提供转换函数

/*---------------------------------------------------
Date: 2014-12-15
Author: fangjunmin
Modify:
Description: 编码转换模块
----------------------------------------------------*/
#include "encode.h"
#include "stdio.h"
#include <errno.h>
#include <iconv.h> bool ConvertEncode( const char *from_charset, const char *to_charset, char *inbuf , size_t inlen,char *outbuf, size_t& outlen )
{
char *pin = inbuf;
char *pout = outbuf;
size_t ulInLen = inlen;
size_t ulOutLen = outlen; iconv_t cd = iconv_open(to_charset, from_charset);
if( cd == (iconv_t)(-1) )
{
return false;
} memset(outbuf, 0, outlen);
int nRet = iconv(cd, &pin, (size_t*)&ulInLen, &pout, (size_t*)&ulOutLen);
iconv_close(cd); //切记 outlen -= ulOutLen; if( nRet == -1 )
{
int nError = errno;
switch( nError)
{
case EINVAL:
{
return true;
}
case E2BIG:
{
printf("转码失败,转码缓冲不够\n系统错误信息:%m\n");
return false;
}
case EILSEQ:
{
printf("转码失败(有可能同码相转)\n系统错误信息:%m\n");
return false;
}
default:
{
printf("转码失败\n系统错误信息:%m\n");
return false;
}
}
} return true;
} bool GB2312ToUtf8(const char* szSrc, int iSrcLen, char* szDst, size_t& iDstLen)
{
return ConvertEncode("GB18030", "utf-8", (char*)szSrc, iSrcLen, szDst, iDstLen);
}

  

上一篇:SAL-9 获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'


下一篇:Centos常用命令之:VI