十六进制压缩二进制

 1 #include<stdio.h>
 2 #include<string.h>
 3 
 4 char*CompressStr(char s[]){
 5     
 6     char t[255];
 7     int i = 0,j,k = 0;
 8     
 9     while( s[i] ){
10         
11     j = i+1;
12     
13     while(s[i] == s[j]) 
14     ++j;
15     
16     t[k++] = j-i+'0';
17     t[k++] = s[i];
18     i=j;
19     
20     }
21     
22     t[k]='';
23     strcpy(s,t);
24     return s;
25 }
26 
27 int main(void)
28 {
29     
30     char i,s[][20] = {"111225555","333AAAbbbb","ASXDCdddddd"};
31     
32     for(i=0;i<3;++i){
33         
34     printf("原串:%s
",s[i]);
35     printf("压缩后:%s
",CompressStr(s[i]));
36     
37 }
38     return  0;
39 }

原串:111225555
压缩后:312245
原串:333AAAbbbb
压缩后:333A4b
原串:ASXDCdddddd
压缩后:1A1S1X1D1C6d

原文地址:https://www.cnblogs.com/ghwxxg/p/14347257.html