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

Run it Now
#include<stdio.h>

int main() {

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

   printf("Enter any String :");
   fgets(str1, 100, stdin);

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

   str2[i] = '\0';
   printf("\nThe First String is :%s", str1);
   printf("\nThe Second Copy String is :%s", str2);

   return 0;
}

Output:

Enter any String :Hello World
The First String is :Hello World
The Second Copy String is :Hello World