Advertisement

C Program to copy one string to another without using library functions


In this program, You will learn how to copy one string to another without using library functions in c.


strcpy(str2, str1);

Example: How to copy one string to another without using library functions in c

#include<stdio.h>
int main() {

   char str1[100], str2[100];
   int i = 0, k;

   printf("Enter any string:");
   scanf("%[^\n]%*c", str1); 

   while (str1[i] != '\0') {
       str2[i] = str1[i];
       i++;
   }

   str2[i] = '\0';
   printf("First String is:%s", str1);
   printf("\nSecond copy string is:%s", str2);

   return 0;
}

Output:

Enter any string:Xiith.com
First String is:Xiith.com
Second copy string is:Xiith.com