Tuesday, 22 November 2016

String Manipulation Using Function Overloading

#include<iostream.h>
#include<conio.h>
void scopy(char str[])         //This Code Copies The Enire String
 {
       char st[15];
       int i=0;
   while(str[I]!='\0')
    {
      st[i]=str[i];
      i++;
    }
      st[i]='\0';
      cout<<"Copied String: "<<st;
 }
void scopy(char str[],int pos)     //pos=position
 {                                                //This Code Copy String From Nth Position
       char st[15];
       int i=pos,j=0;
   while(str[I]!='\0')
      st[j++]=str[I++];
      st[j]='\0';
      cout<<"Copied String: "<<st;
 }
void scopy(char str[],int pos,int epos)      //epos=end position
 {                                                               //This Code Copy The Sub String
       char st[15];
       int i=pos,j=0;
   while(i<=epos)
      st[j++]=str[I++];
      st[j]='\0';
      cout<<"Copied String: "<<st;
 }
  main()
{
   char s1[15];
   int ch,p,ep;
   clrscr();
   cout<<"Enter The Choice : ";
   cin>>ch;
 switch(ch)
 {
   case1:
     cout<<"Enter The String :";
     cin>>s1;
     scopy(s1);
     break;
   case2:
     cout<<"Enter The String :";
     cin>>s1;
     cout<<"Enter The String Starting Position :";
     cin>>p;
     scopy(s1,p);
     break;
   case1:
     cout<<"Enter The String :";
     cin>>s1;
     cout<<"Enter The String Starting Position :";
     cin>>p;
     cout<<"Enter The String Ending Position :";
     cin>>ep;
     scopy(s1,p,ep);
     break;
 }
 getch();
}

No comments:

Post a Comment