codescracker


c

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 */
		
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	clrscr();
	char str1[20], str2[20];
	printf("Enter a string : ");
	gets(str1);
	printf("copying string 1 into string 2 ......\n");
	strcpy(str2, str1);
	printf("String 2 after copying %s ",str2);
	getch();
}

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 »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test