Program to Copy one String to Another string without using strcpy()

Whenever we are asked to write a program to copy one string to another string, we make use of inbuilt function- strcpy (). Obviously, it is the easy method and we can use that. But sometimes, we are asked not to use the strcpy (). This program helps to copy one String to Another string without using strcpy()

 #include <stdio.h>

#include <conio.h>

#include <string.h>

 Void main()

{

 char string1[20], string2[20];

 int i;

 printf(” Enter the first STRING you want to copy: \n”);

 gets(string1);

  for(i=0; string1[i]!=’\0′; i++)

 string2[i]=string1[i];

 string2[i]=’\0′;

 printf(“\n The value of new string after copying old string is :\n”);

 puts(string2);

 getch();

}

Mohit Arora
Follow me