GBK与Unicode对照表的⽣成
#include "stdafx.h"
#include "Windows.h"
// 写GBK_UniCode表函数,参数 fp ⽂件指针,代码页起讫值,空代码值
int WriteGBK_UniCodeTable(FILE *fp,unsigned istart,unsigned iend,unsigned jstart,unsigned jend,unsigned ExNum) {
char zifu[3];
har * tmpchar = new char(3);
unsigned i,j,k;
unsigned char m,n;
for(i=istart;i<=iend;i++)
{
zifu[0] = i;
zifu[2] = 0;
fprintf(fp,"\n%02X\n\t",i); // 国标区码
for(k=0;k<=15;k++)
{
fprintf(fp,"%X\t",k); // 国标位码列
}
for(j=jstart;j<=jend;j++)
{
if(j%16==0)
fprintf(fp,"\n  %X\t",j/16); // 国标位码⾏
zifu[1] = j;
// 将国标码转换成unicode
MultiByteToWideChar(CP_ACP,0,(LPCSTR)zifu,2,(WCHAR*)tmpchar,1);
m = tmpchar[1];
n = tmpchar[0];
if (j==ExNum)
{
fprintf(fp,"\t");
}
else
fprintf(fp,"%s,%02x%02x\t",zifu,m,n); // 字符,unicode码
}
fprintf(fp,"\n");
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp = fopen("c:\\tt.txt", "w");
char zifu[3],zifu_uni[2];
char * tmpchar = new char(3);
unsigned  i,j,k;
unsigned char  m,n;
// GBK/1  A1–A9  A1–FE  846717  GB2312⾮汉字符号
fprintf(fp," GBK/1    A1–A9 A1–FE        846 717    GB2312⾮汉字符号\n\n"); WriteGBK_UniCodeTable(fp,0xa1,0xa9,0xa0,0xfe,0xa0);
// GBK/2    B0–F7  A1–FE        6,768  6,763  GB2312 汉字
fprintf(fp," \nGBK/2  B0–F7A1–FE  6,768  6,763  GB2312 汉字\n\n"); WriteGBK_UniCodeTable(fp,0xb0,0xb7,0xa0,0xfe,0xa0);
// GBK/3      81–A0  40–FE(7F除外) 6,080 6,080  扩充汉字
fprintf(fp,"\nGBK/3    81–A0 40–FE(7F除外) 6,080 6,080  扩充汉字\n\n"); WriteGBK_UniCodeTable(fp,0x81,0xa0,0x40,0xfe,0x7f);
// GBK/4    AA–FE  40–A0(7F除外) 8,160 8,160  扩充汉字
fprintf(fp,"\nGBK/4  AA–FE 40–A0(7F除外) 8,160 8,160  扩充汉字\n\n"); WriteGBK_UniCodeTable(fp,0xaa,0xfe,0x40,0xa0,0x7f);
// GBK/5  A8–A9  40–A0(7F除外) 192 166    扩充⾮汉字
fprintf(fp,"\nGBK/5  A8–A9 40–A0(7F除外) 192 166    扩充⾮汉字\n\n"); WriteGBK_UniCodeTable(fp,0xa8,0xa9,0x40,0xa0,0x7f);
//⽤户定义    AA–AF  A1–FE        564html符号代码对照表
fprintf(fp,"\n⽤户定义1    AA–AF A1–FE        564\n\n");
WriteGBK_UniCodeTable(fp,0xaa,0xaf,0xa0,0xfe,0xa0);
//⽤户定义    F8–FE A1–FE      658
fprintf(fp,"\n⽤户定义2    F8–FE A1–FE        658\n\n");
WriteGBK_UniCodeTable(fp,0xf8,0xfe,0xa0,0xfe,0xa0);
//⽤户定义    A1–A7  40–A0(7F除外) 672
fprintf(fp,"\n⽤户定义3    A1–A7 40–A0 7F除外 672\n\n");
WriteGBK_UniCodeTable(fp,0xa1,0xa7,0x40,0xa0,0x7f);
fclose(fp);
return 0;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。