打印GBK、GB2312字符集全字符

 

根据编码表填充数据就可以了~~~~(>_<)~~~~~\(≧▽≦)/~啦啦啦

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <string.h>
  4 
  5 /*
  6   GBK编码规则:
  7 
  8   码段          未编码段       字数
  9 
 10   8140 - A0FE               190 * 32 = 6080
 11   A140 - A7FE    40 - A0    94  * 7  = 658
 12   A840 - A9FE               190 * 2  = 380
 13   AA40 - AFFE    A1 - FE    96  * 6  = 576
 14   B040 - F7FE               190 * 72 = 13680
 15   F840 - FEFE    A1 - FE    96  * 7  = 672
 16                                 总共 = 22046
 17 */
 18 void fun_gbk( void )
 19 {
 20     unsigned char code[3] = {0x00, 0x00, 0x00};
 21     
 22     // 8140 - A0FE               190 * 32 = 6080
 23     for( code[0] = 0x81; code[0] <= 0xA0; code[0]++ )
 24     {
 25         printf("\n%02x\n", code[0]);
 26         for( code[1] = 0x40; code[1] <= 0xFE; code[1]++ )
 27         {
 28             printf("%s", code);    
 29         }    
 30     }
 31     // A140 - A7FE    40 - A0    94  * 7  = 658
 32     for( code[0] = 0xA1; code[0] <= 0xA7; code[0]++ )
 33     {
 34         printf("\n%02x\n", code[0]);
 35         for( code[1] = 0xA1; code[1] <= 0xFE; code[1]++ )
 36         {
 37             printf("%s", code);    
 38         }    
 39     }
 40     // A840 - A9FE               190 * 2  = 380
 41     for( code[0] = 0xA8; code[0] <= 0xA9; code[0]++ )
 42     {
 43         printf("\n%02x\n", code[0]);
 44         for( code[1] = 0x40; code[1] <= 0xFE; code[1]++ )
 45         {
 46             printf("%s", code);    
 47         }    
 48     }
 49     // AA40 - AFFE    A1 - FE    96  * 6  = 576
 50     for( code[0] = 0xAA; code[0] <= 0xAF; code[0]++ )
 51     {
 52         printf("\n%02x\n", code[0]);
 53         for( code[1] = 0x40; code[1] <= 0xA0; code[1]++ )
 54         {
 55             printf("%s", code);    
 56         }    
 57     }    
 58     // B040 - F7FE               190 * 72 = 13680
 59     for( code[0] = 0xB0; code[0] <= 0xF7; code[0]++ )
 60     {
 61         printf("\n%02x\n", code[0]);
 62         for( code[1] = 0x40; code[1] <= 0xFE; code[1]++ )
 63         {
 64             printf("%s", code);    
 65         }    
 66     }
 67     // F840 - FEFE    A1 - FE    96  * 7  = 672
 68     for( code[0] = 0xF8; code[0] <= 0xFE; code[0]++ )
 69     {
 70         printf("\n%02x\n", code[0]);
 71         for( code[1] = 0x40; code[1] <= 0xA0; code[1]++ )
 72         {
 73             printf("%s", code);    
 74         }    
 75     }
 76 }
 77 
 78 
 79 /*
 80   GB2312编码空间
 81   A1A1 - A9FE   846
 82   B0A1 - F7FE   6768
 83                 7614
 84 */    
 85 void fun_gb2312( void )
 86 {
 87     unsigned char code[3] = {0x00, 0x00, 0x00};
 88     char tmp[20];
 89 
 90     // 打印GB2312字符集全部字符
 91     for(code[0]=0xA1; code[0]<=0xA9; code[0]++)
 92     {
 93         printf("0x%x\n", code[0]);
 94         //sprintf(tmp, "\n0x%x\n", code[0]);
 95         //sendEsc(tmp, strlen(tmp));
 96         
 97         for(code[1]=0xA1; code[1]<=0xFE; code[1]++)
 98         {
 99             printf("%s", code);
100             //sendEsc( code, strlen(code));
101         }
102     }
103 
104     for(code[0]=0xB0; code[0]<=0xF7; code[0]++)
105     {
106         printf("\n0x%x\n", code[0]);
107         sprintf(tmp, "\n0x%x\n", code[0]);
108         //sendEsc(tmp, strlen(tmp));
109         
110         for(code[1]=0xA1; code[1]<=0xFE; code[1]++)
111         {
112             printf("%s", code);
113             //sendEsc( code, strlen(code));
114         }
115     }
116 }
117 
118 
119 int main( void )
120 {
121     printf("\r\n--------------- GBK ----------------\r\n");
122     fun_gbk();
123     
124     printf("\r\n--------------- GB2312 ------------------\r\n");
125     fun_gb2312();
126     
127     return 0;    
128 }

 

转载于:https://www.cnblogs.com/utank/p/6722768.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值