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();
}
Latest posts by Mohit Arora (see all)
- MongoDB Operators Tutorial – What are Different Operators Available? - October 5, 2019
- MongoDB Projection Tutorial : Return Specific Fields From Query - March 9, 2019
- MongoDB Index Tutorial – Create Index & MongoDB Index Types - July 6, 2018