C Program to Copy String

« Previous Program Next Program »

Copy String in C

To copy string in C programming, you have to ask to the user to enter the string to make copy to another variable of same type using strcpy() function of string.h library.

C Programming Code to Copy String

Following C program ask to the user to enter a string to copy it into another string, then display the copied string on the screen :

/* C Program - Copy String */
void main()
	char str1[20], str2[20];
	printf("Enter a string : ");
	printf("copying string 1 into string 2 ......\n");
	strcpy(str2, str1);
	printf("String 2 after copying %s ",str2);

When the above c program is compile and executed, it will produce the following result:

c program copy string

Same Program in Other Programming Language

You may also like same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test