×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
compare two string - String
copy a string into another - String - String - C Language
1663    Arnab De    15/04/2019

Write a C program to copy a string into another string

Travel the source string, and copy the character one by one into targeted string. and add a null character at the end of the targeted string. We can also use strcpy() method to copy a string. for that, we must include string.h header file.

softetechnologies
int main()
{
	char str1[30],str2[30],i,fl=1;
	printf("Enter A String: ");
	gets(str1);
	for(i=0;str1[i]!='\0';i++)
	{
		str2[i]=str1[i];
	}
	str2[i]='\0';
	printf("\nCopied String : ");
	puts(str2);
	return 0;
}

Copy a string using strcpy() method

softetechnologies
#include<string.h> // for strcmp()
int main()
{
	char str1[30],str2[30],i,fl=1;
	printf("Enter A String: ");
	gets(str1);
	strcpy(str2,str1);
	printf("\nCopied String : ");
	puts(str2);
	return 0;
}
softetechnologies
compare two string - String
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
A nation is advanced in proportion to education and intelligence spread among the masses.
Swami Vivekananda
570
54.7
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     42637
01/01/2018     36193
25/06/2018     34314
28/06/2017     34309
02/08/2017     32620
01/08/2017     27136
06/07/2017     26963
15/05/2017     26592
14/07/2017     22156
21/04/2018     20848
softetechnologies