枚举BIG5中的汉字

该博客给出了一个用C语言编写的程序,用于输出BIG5编码字符。程序定义了不同类型字符的编码范围,如图形码、常用字、次常用字等,通过DumpRange函数按范围输出字符,最后在main函数中调用DumpBIG5函数将结果写入big5.txt文件。

//Build: gcc -g big5.c -o big5.exe

//

//0xa140 to 0xa3bf "Graphical characters" 圖形碼

//0xa3c0 to 0xa3fe Reserved for user-defined characters 造字

//0xa440 to 0xc67e Frequently used characters 常用字

//0xc6a1 to 0xc8fe Reserved for user-defined characters

//0xc940 to 0xf9d5 Less frequently used characters 次常用字

//0xf9d6 to 0xfefe Reserved for user-defined characters

//First byte ("lead byte") 0xa1 to 0xfe

//Second byte 0x40 to 0x7e, 0xa1 to 0xfe

//

//

#include <stdio.h>

<!--[if !supportEmptyParas]--><!--[endif]-->

static void DumpRange(FILE* fp, unsigned short start, unsigned short end)

{

unsigned char cHigh = 0;

unsigned char cLow = 0;

unsigned short i = 0;

for(i = start ; i < end; i++)

{

cHigh = i >> 8;

cLow = i & 0xFF;

if((cLow >= 0x40 && cLow <= 0x7e) || (cLow >= 0xa1 && cLow <= 0xfe))

{

fwrite(&cHigh, sizeof(cHigh), 1, fp);

fwrite(&cLow, sizeof(cLow), 1, fp);

}

}

fflush(fp);

<!--[if !supportEmptyParas]--><!--[endif]-->

return;

}

<!--[if !supportEmptyParas]--><!--[endif]-->

static void DumpBIG5(void)

{

unsigned short i = 0;

FILE* fp = fopen("big5.txt", "wb+");

if(fp != NULL)

{

DumpRange(fp, 0xa140, 0xa3bf);

DumpRange(fp, 0xa440, 0xc67e);

DumpRange(fp, 0xc940, 0xf9d5);

fclose(fp);

}

else

{

perror("fopen");

}

<!--[if !supportEmptyParas]--><!--[endif]-->

return;

}

<!--[if !supportEmptyParas]--><!--[endif]-->

int main(int argc, char* argv[])

{

DumpBIG5();

<!--[if !supportEmptyParas]--><!--[endif]-->

return 0;

}

<!--[if !supportEmptyParas]--><!--[endif]-->

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值