C++ Programming Blog

 
 
 

Image

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

 int main( )
    {
       clrscr( );

       fstream file(\"CP-11.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 Input[85]={NULL};
       char *Output;
       char Assignments[2][100][55]={NULL};

       int number_of_replacements=0;

       do
      {
         strset(Input,NULL);

         file.getline(Input,80);

         number_of_replacements=atoi(Input);

         if(number_of_replacements==0)
        break;

         for(int i=0;i<100;i++)
        {
           strset(Assignments[0][i],NULL);
           strset(Assignments[1][i],NULL);
        }

         for(int j=0;j<number_of_replacements;j++)
        {
           strset(Input,NULL);

           file.getline(Input,80);

           int k=0;
           int l=1;

           Assignments[0][j][0]=\'{\';

           do
              {
             Assignments[0][j][l]=Input[k];
             k++;
             l++;
              }
           while(Input[k]!=\'=\');

           Assignments[0][j][l]=\'}\';
           k++;
           l=0;

           do
              {
             Assignments[1][j][l]=Input[k];
             k++;
             l++;
              }
           while(Input[k]!=NULL && Input[k]!=\' \');
        }

         strset(Input,NULL);

         file.getline(Input,80);

         int number_of_braces=0;

         for(int m=0;m<strlen(Input);m++)
        {
           if(Input[m]==\'{\')
              number_of_braces++;
        }

         Output=new char[(80+(55*number_of_braces))];

         strset(Output,NULL);
         strcpy(Output,Input);

         char *Ptr=NULL;

         for(int n=0;n<number_of_replacements;n++)
        {
           for(int o=0;o<number_of_replacements;o++)
              {
             Ptr=strstr(Output,Assignments[0][o]);

             if(Ptr!=NULL)
                {
                   int replace_point=(strlen(Output)-strlen(Ptr));

                   char *Temp=new char[strlen(Output)];

                   strset(Temp,NULL);
                   strcpy(Temp,Output);
                   strset(Output,NULL);

                   for(int p=0;p<replace_point;p++)
                  Output[p]=Temp[p];

                   strcat(Output,Assignments[1][o]);

                   p+=strlen(Assignments[1][o]);

                   int q=replace_point+strlen(Assignments[0][o]);

                   for(;q<strlen(Temp);p++,q++)
                 Output[p]=Temp[q];

                   delete Temp;
                }
              }
        }

         cout<<Output<<endl;

         delete Output;
      }
       while(1);

       file.close( );

       getch( );
       return 0;
    }

    Related Post:
  1. Program to illusrate comparision operator overloading

  2. Program to illustrate pointers , structure and passing structure pointers to function.

  3. Program to show the projection of 3D objects using Orthographics Parallel Projection w.r.t. xy-plane and along vector v

  4. PROGRAM OF OVERLOADING ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT

  5. Program that provides an example of class

  6. Program to illustrate the implementation of Translation Transformation.

  7. Program to estimate the Integral value of the function at the given points from the given data using Simpsons 1/3 Rule

  8. Program to calculate distance summation, subtraction, multiplication and comparison using overloading operators also make it friend functions

  9. Program to show the Urdu Alphabets using Stroke Method

  10. Program to fill different types of geometric shapes using Flood Fill Algorithm (Using Linked-List)

  11. Program of displaying graphical menu and operate it using arrow keys

  12. Program to illustrate the implementation of arrays as a Linear Queue ( in graphics )

  13. To parse a string using First and Follow algorithm and LL-1 parser

  14. Program that performs selection search

  15. Program to show the implementation of Bottom-Up Parsing

  16. Program to illustrate template classes

  17. Program to construct Clamped Cubic Spline Interpolant from the given data

  18. Write a function power() to raise a number m to a power n

  19. Program to read a Non-Linear equation in one variable, then evaluate it using Secant Method and display its kD accurate root

  20. Write a program to Add Two Matrix

 
 
Didn't find what you were looking for? Find more on Program to do variable replacement in a line of text