C language string compression algorithm code demonstration

From , 5 Years ago, written in C++, viewed 186 times.
URL https://pastebin.vip/view/88b05733
  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #include <stdlib.h>  
  4.  
  5. int main()  
  6. {  
  7.     char str[100] = {'\0'};  
  8.     char res[100] = {'\0'};  
  9.  
  10.     scanf("%s",str);  
  11.     int length = strlen(str);  
  12.     int i=0, j=0, k=0;  
  13.     int count = 0;  
  14.  
  15.     do  
  16.     {  
  17.         if(i < length && str[i++] == str[j])  
  18.             count++;  
  19.  
  20.         if(str[i] != str[j])  
  21.         {  
  22.             if(count <= 1)  
  23.                 res[k++] = str[j];  
  24.             else  
  25.             {  
  26.                 if(count > 1)  
  27.                 {  
  28.                     char temp[10] = {'\0'};  
  29.                     itoa(count,temp,10);  
  30.                     strcpy(res+k,temp);  
  31.                     k+=strlen(temp);  
  32.                     res[k++] = str[j];  
  33.                 }  
  34.             }  
  35.  
  36.             j = i;  
  37.             count = 0;  
  38.         }  
  39.     }while(i<length);  
  40.      
  41.     res[k] = '\0';  
  42.     printf("The result is : %s\n",res);  
  43.     return 0;  
  44. }  
  45. //cpp/8976

Reply to "C language string compression algorithm code demonstration"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website