Any Array containing Characters is called as 'String'. This string can copied using function called 'strcpy()' but here in this program we are going to see how to copy a string into another string without using strcpy() function.
Program:
//Copy string without using strcpy. Program by slashmycode.com
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
char s1[10],s2[10];
clrscr();
printf("\nEnter the string 1\n");
gets(s1);
printf("\nEnter the string 2\n");
gets(s2);
printf("\nString 1: %s",s1);
printf("\nString 2: %s",s2);
while(s1[i]!=NULL)
{
s2[i]=s1[i];
i++;
}
s2[i]='\0';
printf("\nAfter copying, the string 2 is: %s",s2);
//Copy string without using strcpy. Program by slashmycode.com
getch();
}
Output:
No comments:
Post a Comment
Feel free to ask us any question regarding this post