• 打印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("
    %02x
    ", 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("
    %02x
    ", 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("
    %02x
    ", 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("
    %02x
    ", 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("
    %02x
    ", 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("
    %02x
    ", 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
    ", code[0]);
     94         //sprintf(tmp, "
    0x%x
    ", 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("
    0x%x
    ", code[0]);
    107         sprintf(tmp, "
    0x%x
    ", 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("
    --------------- GBK ----------------
    ");
    122     fun_gbk();
    123     
    124     printf("
    --------------- GB2312 ------------------
    ");
    125     fun_gb2312();
    126     
    127     return 0;    
    128 }
  • 相关阅读:
    只要你拥有爱心,你就会拥有快乐。
    解决升级 Office 2010 之后 Outlook 提示“无法打开 Microsoft Outlook”
    《老人与海》
    UML模型的组成
    2009年11月11日
    IBatis存取图片在Oracle Blob大字段中Asp.Net
    “北京今年入冬的第一场雪”,纪念博客园写日志一年了
    UML建模实践概述
    UML 类图
    UML 用例图
  • 原文地址:https://www.cnblogs.com/utank/p/6722768.html
Copyright © 2020-2023  润新知