String copy without using strcpy().
String copy without using strcpy():
Hello ,readers in this blog you will come across the concept of string copy without using strcpy() function.
strcpy() function is default inbuilt function that copy one string into another string .
But the below code will copy one string into another string without using strcpy() function.
Following method has used in programme
- Take input string from user
- Run the iteration till the length of first string.
- Copy the first string into other string.
- Then put null value at the end of second string.
Copy one string into other string
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[30],str2[30];
int i,j;
printf("Enter string\n");
gets(str1);
j=0;
for(i=0;i<str1[i]!='\0';i++)
{
str2[j]=str1[i];
j++;
}
str2[j]='\0';
printf("String after copy is");
puts(str2);
getch();
}
Thank's you enjoyed the code .Please comment on this blog.
String copy without using strcpy().
Reviewed by Deepak kumar soni
on
December 25, 2018
Rating:
No comments: