Copy one string into another string in C++ by R4R Team

Here we copy one string into another string without any use of predefined function.

program:

#include< iostream>
int main()
{
char ch1[20],ch2[20];
int i=0;
//input of string
cout<<"Enter string"<< endl;
cin>>ch1;
//Now copy in another
while(ch1[i]!='')
{
ch2[i]=ch1[i];
i++;
}
ch2[i]='';
cout<<"String After copy is "<< ch2;
}


output-

Enter string
Myprogramming
String After copy is Myprogramming

-In this program, we create a two string ch1 and ch2 having the max size of 20, then we take an input in string one (i.e., ch1) and we run the while loop until string terminate then each character of string1 are copied i string2.
-At last we display that second string(i.e.,ch2)




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!