Holland

yarle

Oct 10th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. void Compress(char * a_File, char * a_ToFile)
  2. {
  3.     char t_Line[128];
  4.     FILE * t_File = fopen(a_File, "r+");
  5.     if(t_File==NULL) return;
  6.    
  7.     FILE * t_WriteFile = fopen(a_ToFile, "w");
  8.     fclose(t_WriteFile);
  9.     t_WriteFile = fopen(a_ToFile, "a");
  10.     if(t_File==NULL) return;
  11.  
  12.     char t_Char = 0;
  13.     char t_Count = 0;
  14.     for(int i = 0; fgets(t_Line, 128, t_File); i++)
  15.     {
  16.         for(int j = 0; j<=strlen(t_Line); j++)
  17.         {
  18.             if(t_Line[j]==t_Char) t_Count++;
  19.             else
  20.             {
  21.                 if(t_Count!=0)
  22.                 {
  23.                     fputc((int)t_Char, t_WriteFile);
  24.                     fputc ((int)t_Count, t_WriteFile);
  25.                 }
  26.                 t_Char = t_Line[j];
  27.                 t_Count = 1;
  28.             }
  29.         }
  30.     }
  31.     fclose(t_File);
  32.     fclose(t_WriteFile);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment