下载
libiconv 是linux 版本的iconv ,可在 http://www.gnu.org/software/libiconv/ 下载
iconv 的win32 版本可以在 http://gnuwin32.sourceforge.net/packages/libiconv.htm 下载
SVN 源码
另外,还有一些演示代码,需要的可以到我的SVN 下载
http://xcyber.googlecode.com/svn/trunk/Convert/
标签: libiconv , iconv , Big5 , GB2312 , 大五码 , 内码
001 |
/**************************************************************************** |
002 |
* Big5ToGB2312 - Convert Big5 encoding file to GB2312 encoding file |
003 |
* File: |
004 |
* Big5ToGb2312.c |
005 |
* Description: |
006 |
* Convert Big5 encoding file to GB2312 encoding file using iconv library |
007 |
* Author: |
008 |
* XCyber email:[email protected] |
009 |
* Date: |
010 |
* August 7, 2008 |
011 |
* Other: |
012 |
* visit http://www.gnu.org/software/libiconv/ for more help of iconv |
013 |
***************************************************************************/ |
014 |
|
015 |
|
016 |
#include <stdio.h> |
017 |
#include <stdlib.h> |
018 |
#include <tchar.h> |
019 |
#include <locale.h> |
020 |
#include "../iconv-1.9.2.win32/include/iconv.h" |
021 |
|
022 |
//#pragma comment(lib, "../iconv-1.9.2.win32/lib/iconv.lib") // using iconv dynamic-link lib, iconv.dll |
023 |
#pragma comment(lib, "../iconv-1.9.2.win32/lib/iconv_a.lib") // using iconv static lib |
024 |
|
025 |
#define BUFFER_SIZE 1024 //BUFFER_SIZE must >= 2 |
026 |
|
027 |
|
028 |
void usage() |
029 |
{ |
030 |
printf("\nBig5ToGB2312 - Convert Big5 encoding file to GB2312 encoding file\n"); |
031 |
printf("[email protected] on August 7, 2008\n"); |
032 |
printf(" Usage:\n"); |
033 |
printf(" Big5ToGB2312 [Big5 file(in)] [GB2312 file(out)]\n\n"); |
034 |
} |
035 |
|
036 |
|
037 |
int main(int argc, char* argv[]) |
038 |
{ |
039 |
FILE * pSrcFile = NULL; |
040 |
FILE * pDstFile = NULL; |
041 |
|
042 |
char szSrcBuf[BUFFER_SIZE]; |
043 |
char szDstBuf[BUFFER_SIZE]; |
044 |
|
045 |
size_t nSrc = 0; |
046 |
size_t nDst = 0; |
047 |
size_t nRead = 0; |
048 |
size_t nRet = 0; |
049 |
|
050 |
char *pSrcBuf = szSrcBuf; |
051 |
char *pDstBuf = szDstBuf; |
052 |
|
053 |
iconv_t icv; |
054 |
int argument = 1; |
055 |
|
056 |
//check input arguments |
057 |
if(argc != 3) |
058 |
{ |
059 |
usage(); |
060 |
return -1; |
061 |
} |
062 |
|
063 |
|
064 |
pSrcFile = fopen(argv[1],"r"); |
065 |
if(pSrcFile == NULL) |
066 |
{ |
067 |
printf("can't open source file!\n"); |
068 |
return -1; |
069 |
} |
070 |
|
071 |
pDstFile = fopen(argv[2],"w"); |
072 |
&nbs |
073 |
p;if(pSrcFile == NULL) |
074 |
{ |
075 |
printf("can't open destination file!\n"); |
076 |
return -1; |
077 |
} |
078 |
|
079 |
//initialize iconv routine, perform conversion from BIG5 to GB2312 |
080 |
//TODO: if you want to perfom other type of coversion, e.g. GB2312->BIG5, GB2312->UTF-8 ... |
081 |
//just change following two paremeters of iconv_open() |
082 |
icv = iconv_open("GB2312","BIG5"); |
083 |
if(icv == 0) |
084 |
{ |
085 |
printf("can't initalize iconv routine!\n"); |
086 |
return -1; |
087 |
} |
088 |
|
089 |
//enable "illegal sequence discard and continue" feature, so that if met illeagal sequence, |
090 |
//conversion will continue instead of being terminated |
091 |
if(iconvctl (icv ,ICONV_SET_DISCARD_ILSEQ,&argument) != 0) |
092 |
{ |
093 |
printf("can't enable \"illegal sequence discard and continue\" feature!\n"); |
094 |
return -1; |
095 |
} |
096 |
|
097 |
while(!feof(pSrcFile)) |
098 |
{ |
099 |
pSrcBuf = szSrcBuf; |
100 |
pDstBuf = szDstBuf; |
101 |
nDst = BUFFER_SIZE; |
102 |
|
103 |
// read data from source file |
104 |
nRead = fread(szSrcBuf + nSrc,sizeof(char),BUFFER_SIZE - nSrc,pSrcFile); |
105 |
if(nRead == 0) |
106 |
break; |
107 |
|
108 |
// the amount of data to be converted should include previous left data and current read data |
109 |
nSrc = nSrc + nRead; |
110 |
|
111 |
//perform conversion |
112 |
nRet = iconv(icv,(const char**)&pSrcBuf,&nSrc,&pDstBuf,&nDst); |
113 |
|
114 |
if(nRet == -1) |
115 |
{ |
116 |
// include all case of errno: E2BIG, EILSEQ, EINVAL |
117 |
// E2BIG: There is not sufficient room at *outbuf. |
118 |
// EILSEQ: An invalid multibyte sequence has been encountered in the input. |
119 |
// EINVAL: An incomplete multibyte sequence has been encountered in the input |
120 |
// move the left data to the head of szSrcBuf in other to link it with the next data block |
121 |
memmove(szSrcBuf,pSrcBuf,nSrc); |
122 |
} |
123 |
|
124 |
//wirte data to destination file |
125 |
fwrite(szDstBuf,sizeof(char),BUFFER_SIZE - nDst,pDstFile); |
126 |
|
127 |
} |
128 |
iconv_close(icv); |
129 |
fclose(pSrcFile); |
130 |
fclose(pDstFile); |
131 |
|
132 |
printf("conversion complete.\n"); |
133 |
|
134 |
return; |
135 |
} |
文章浏览阅读98次。正则表达式是由一个字符序列形成的搜索模式。当你在文本中搜索数据时,你可以用搜索模式来描述你要查询的内容。正则表达式可以是一个简单的字符,或一个更复杂的模式。正则表达式可用于所有文本搜索和文本替换的操作。
文章浏览阅读1.3k次。1024了,程序猿们节日快乐,简单整理个供小白使用的git速查手册,之后有时间再完善,其实一会一些简单的操作平时工作就够用了(只要你别闹!一般不会有什么大问题),哈哈哈文章目录Git的组成git--相关配置git--查看远程库信息git--初始化仓库git--将文件提交到暂存区git--将暂存区文件提交到本地仓库git--查看仓库当前状态git--比较文件异同git--查看历史记录git--代码..._如何查看git手册
文章浏览阅读318次。【actionscript概述】 ActionScript 动作脚本是遵循 ECMAscript第四版 的 Adobe Flash Player 运行时环境的编程语言。它在 Flash 内容和应用程序中实现交互性、数据处理以及其他功能。 ActionScript是Flash的脚本语言,与JavaScript相似,ActionScript是一种面向对象编程语言。 【actionsc..._actionscript
文章浏览阅读5.6k次,点赞7次,收藏17次。java,阿里,阿里巴巴,面试经验,经验分享,阿里面经_阿里巴巴校招经验
文章浏览阅读1.3k次。在前面我有文章介绍过生信中各种ID转换【文章:生信中各种ID转换】,我们可以通过各种基因注释包来转换各种基因ID,这里给大家介绍一下miRNA注释包:miRBaseVersions.db。..._mirbaseversions.db
文章浏览阅读1.7k次。问题描述spark 集群运行的时候,报错ImportError: No module named numpy但是想来想去记得numpy都安装了,但其实不是的问题分析spark集群运行,需要所有的机器都有numpy,自己使用了一台新的机器dl21,这个机器原本没有自带numpy,需要安装解决方案sudo apt-get updatesudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-n_spark no module named 'numpy
文章浏览阅读2.2k次。在运维的过程中,我们有时需要去追踪一些表的变更记录,如采购订单的单价更新,采购订单的入库标识何时更新等,以便我们可以更快的追踪定位到问题所在,本章给大家介绍下如何追踪系统中表的变更记录。根据表名获取更改文档对象,表:TCDOB。_sap ps 项目更改记录查询
文章浏览阅读2.4w次。演示工具:电脑型号:华硕adolbook14 2020系统版本:windows10具体原因及解决方法:1、如果是链接到本地文件的超链接无法打开,可能是相对路径和绝对路径的问题,绝对地址,是有完全的路径,如果超链接的路径写错了,就无法打开。2、检查一下被链接的文件是否被改变了存储位置,如果是,需重新设置一次。3、如果链接的是局域网上其它电脑中的文档,可能是被链接的电脑网络设置出了问题,先检查能否链接...
文章浏览阅读156次。1.基于域名www.openlab.com可以访问网站内容 welcome to openlab。#mount /dev/sr0 /mnt#yum install httpd -y2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站,基于www.openlab.com/student网站访问学生信息,www.openlab.com/data网站访问教学资料,www.openlab.com/money网站访问缴费网站。(1)学生信息网站只能song和tian两个人访问,其他用户不_那些可以在openlab网站获得支持
文章浏览阅读1.9k次。当我们在写代码的时候,其实很多基础的代码都可以直接生成的,个人比较喜欢用easycode,该插件可以自己自定义生成基础的增删改查,有提供的模板,但个人建议最好还是自己写个模板,能符合自己的项目。定制性更强,而且该代码能直接生成到项目中选择连接的数据库,右击使用。_idea打印sql语句插件
文章浏览阅读5.6k次。win10 锁屏时间无法设置 解决方法问题描述:解决方案:标题问题描述:win10 无法修改屏幕保护时间解决方案:标题将下段代码复制进txt,保存成reg,然后运行。dword:0000003C,为设置的时间16进制秒数Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]“InactivityTimeoutSecs”=d_注册表修改锁屏时间win10
文章浏览阅读5.4k次,点赞7次,收藏82次。无人机(Unmanned Aerial Vehicle),指的是一种由动力驱动的、无线遥控或自主飞行、机上无人驾驶并可重复使用的飞行器,飞机通过机载的计算机系统自动对飞行的平衡进行有效的控制,并通过预先设定或飞机自动生成的复杂航线进行飞行,并在飞行过程中自动执行相关任务和异常处理。在前面的文章中,我们分析了多旋翼无人机的飞行原理及飞行模式。链接在最后的飞行模式中, 除了纯手动模式外,简单解释了其它模式如姿态模式的原理,其中一笔带过就是形成了闭环控制,所以稳定。_无人机协调行为算法怎么学习