- 日志
- 好友
- 卖家信用

- 买家信用

- 注册时间
- 2010-11-23
- 在线时间
- 小时
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
x
本帖最后由 憨吃迷糊睡 于 2011-8-28 14:11 编辑
转载请标明出处:小春论坛http://www.incnjp.com/thread-1651043-1-1.html
// libiconv_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//////
// C:\libiconv_test\libiconv_test.cpp
#pragma comment( lib , "C:/lib_x86/lib/iconv.lib" )
#include <stdlib.h>
#include "C:/lib_x86/include/iconv.h"
#define BUFFER_SIZE 3
//////
//int _tmain(int argc, _TCHAR* argv[])
int main(int argc, char *argv[])
{
//////
char fromstring[BUFFER_SIZE];
char tostring[BUFFER_SIZE];
fromstring[0] = (char)((atoi( argv[argc-1] ) & 0xFF00) >> 8);
fromstring[1] = (char) (atoi( argv[argc-1] ) & 0x00FF);
fromstring[2] = '\0';
tostring[0] = '\0';
tostring[1] = '\0';
tostring[2] = '\0';
//////
//////
iconv_t return_value_of_iconv_open;
const char* tocode;
const char* fromcode;
int return_value_of_iconvctl;
iconv_t iconvctl_cd;
int request;
//void * argument;
int argument;
size_t return_value_of_iconv;
iconv_t iconv_cd;
const char* inbuf = fromstring;
size_t inbytesleft = BUFFER_SIZE;
char* outbuf = tostring;
size_t outbytesleft= BUFFER_SIZE;
int return_value_of_iconv_close;
iconv_t iconv_close_cd;
//////
//////
return_value_of_iconv_open = iconv_open (
tocode = "GB18030",
fromcode = "UTF-16"
);
return_value_of_iconvctl = iconvctl (
iconvctl_cd = return_value_of_iconv_open,
request = ICONV_GET_DISCARD_ILSEQ,
&argument
);
return_value_of_iconv = iconv (
iconv_cd = return_value_of_iconv_open,
&inbuf,
&inbytesleft,
&outbuf,
&outbytesleft
);
return_value_of_iconv_close = iconv_close (
iconv_close_cd = return_value_of_iconv_open
);
//////
//////
if( (fromstring[0] & 0x0f) == (fromstring[0] & 0xff) )
{
if( (fromstring[0] & 0xf0) == (fromstring[0] & 0xff) )
{
printf("00"); //0x00
}
else
{
printf("0%X",fromstring[0] & 0xff); //0x0x
}
}
else
{
printf("%X",fromstring[0] & 0xff); //0xxx
}
if( (fromstring[1] & 0x0f) == (fromstring[1] & 0xff) )
{
if( (fromstring[1] & 0xf0) == (fromstring[1] & 0xff) )
{
printf("00"); //0x00
}
else
{
printf("0%X",fromstring[1] & 0xff); //0x0x
}
}
else
{
printf("%X",fromstring[1] & 0xff); //0xxx
}
printf(",");
if( (tostring[0] & 0x0f) == (tostring[0] & 0xff) )
{
if( (tostring[0] & 0xf0) == (tostring[0] & 0xff) )
{
printf("00"); //0x00
}
else
{
printf("0%X",tostring[0] & 0xff); //0x0x
}
}
else
{
printf("%X",tostring[0] & 0xff); //0xxx
}
if( (tostring[1] & 0x0f) == (tostring[1] & 0xff) )
{
if( (tostring[1] & 0xf0) == (tostring[1] & 0xff) )
{
printf("00"); //0x00
}
else
{
printf("0%X",tostring[1] & 0xff); //0x0x
}
}
else
{
printf("%X",tostring[1] & 0xff); //0xxx
}
printf("\n");
//////
return 0;
}
|
|