C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<string.h>
 #include<stdio.h>
 #include<conio.h>



 //-------------------------  copy_string  -------------------------------//


 class copy_string
    {
      private:
        char string[100];

      public:
        copy_string()  { strcpy(string,\"\"); }
        void get_value();
        void show_value(copy_string,copy_string,int,int);
    };



 //---------------------------  get_value( )  ----------------------------//


 void copy_string::get_value()
    {
       cout<<\"\\n Enter the string :\";
       gets(string);
    }


 //------------  show_value(copy_string,copy_string,int,int)  ------------//


 void copy_string::show_value(copy_string string_1,copy_string string_2,
                    int position,int number_of_char)
    {
       int count=position+number_of_char;

       for(int i=position,j=0;i<number_of_char,j<number_of_char;i++,j++)
      string_1.string[i]=string_2.string[j];

       cout<<\"\\n The resultant string is :\";

       for(int k=0;k<count;k++)
      cout<<string_1.string[k];

       cout<<endl;
    }



 //-----------------------------  Main( )  -------------------------------//



 main( )
    {
       clrscr();

       copy_string s;
       copy_string ss;

       int po;
       int no;

       s.get_value();
       ss.get_value();

       cout<<\"\\n Enter the position number \'p\' = \";
       cin>>po;

       cout<<\" Enter the number of characters \'n\' = \";
       cin>>no;

       s.show_value(s,ss,po,no);

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to copy n number of characters from one string to another at position p