Copy one string into another in C program by R4R Team

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

program-

#include< stdio.h>
int main()
{
char ch1[20],ch2[20];
int i=0;
//input of string
printf("Enter string\n");
scanf("%s",&ch1);
//Now copy in another
while(ch1[i]!='')
{
ch2[i]=ch1[i];
i++;
}
ch2[i]='';
printf("String After copy is %s",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!