同样遇到字节对齐的问题,问题就是:
汉字取模后,只有一个汉字无法显示,这个汉字是“过”这个字。存在结构体中用汉字来当索引,检索取模后的十六进制数。结构体如下:
typedef struct
{
unsigned char Index[2];
unsigned char Msk[128];
}typFNT_GB32;
//#pragma pack()
const typFNT_GB32 code tfont32[]={
"未",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x03,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x81,0x01,0xC0,0xFF,
0xFF,0x03,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x0C,0xF8,0xFF,0xFF,0x1F,0x00,0xE0,0x03,0x00,
0x00,0xE0,0x05,0x00,0x00,0xB0,0x0D,0x00,0x00,0xB8,0x09,0x00,0x00,0x98,0x11,0x00,0x00,0x8C,0x31,0x00,0x00,0x86,0x61,0x00,0x00,0x83,0xC1,0x01,0x80,0x81,0x81,0x03,0x60,0x80,
0x01,0x0F,0x30,0x80,0x01,0x3E,0x08,0x80,0x01,0x0C,0x00,0x80,0x01,0x00,0x00,0x80,0x01,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,/*"未",0*/
通过分析发现,当结构内存储的是“过”这个字的时候是无法显示的。调试发现,Index[2]数组中的Index[1]取值不完整。如下:
k=10
indx0=0xd5
indx1=0xcf
k=11
indx0=0xb9
indx1=0x0
k=12
indx0=0xc7
indx1=0xb7
上边的“k=11”这个就是“过”这个汉字的序号,打印出来后居然是“indx1=0x0”,缺少数据,正常应该是“indx1=0xfd”。即:indx0=0xb9,indx1=0xfd。正好对应GB2312码表中“过”这个汉字十六进制编码0xb9fd。
请各位大神指教,如何解决。问题是:只有这一个汉字这样,其它汉字没有问题。从上述打印出来的k=10、k=12的索引汉字就能看出来。 |