C++ Programming Blog

 
 
 

Image

 # include <iostream.h>
 # include <fstream.h>
 # include <string.h>
 # include <stdlib.h>
 # include <ctype.h>
 # include <conio.h>


 int main( )
    {
       clrscr( );

       fstream File(\"CP-21.txt\",ios::in|ios::nocreate);

       if(!File)
      {
         cout<<\"\\n Unable to open the input file.\"<<endl;
         cout<<\"\\n Press any key to exit.\";

         getch( );
         exit(EXIT_FAILURE);
      }

       char Data[100]={NULL};

       do
      {
         strset(Data,NULL);

         File.getline(Data,80);

         if(strcmp(Data,NULL)==0)
        break;

         char Duplication_factor[10]={NULL};

         int index=0;
         int length=strlen(Data);

         do
        {
           strset(Duplication_factor,NULL);

           while(isdigit(Data[index]))
              {
             char Temp[5]={NULL};

             Temp[0]=Data[index];

             strcat(Duplication_factor,Temp);

             index++;
              }

           int duplication_factor=0;

           duplication_factor=atoi(Duplication_factor);

           if(duplication_factor==0)
              cout<<Data[index];

           else
              {
             for(int count=0;count<duplication_factor;count++)
                cout<<Data[index];
              }

           index++;
        }
         while(index<length);

         cout<<endl;
      }
       while(1);

       File.close( );

       getch( );
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to represent or compress \‘2ABCDE to string \‘AABCDE\’