Strcpy in C



Arrays and Strings in Tamil


Strcpy

  • The strcpy(destination, source) function copies the source string in destination.
 String Copy

String Copy

Example

#include<stdio.h> 
#include <string.h>
void main()
{
	char ch[20]={'k', 'a', 'a', 's', 'h',  'i', 'v', 'i', 'n', 'f','o','t','e','c','h','\0’}; 
	char ch2[20];
	strcpy(ch2,ch);
	printf("Value of second string is: %s",ch2);
	getch();
}
 StrCpy

StrCpy

Output

Value of second string is: kaashivinfotech

String Copy Without Using StringCpy()

#include <stdio.h>
#include <string.h>
void main()
{
       char string1[20], string2[20];
       int i;
       printf("Enter the value of string 1 ");
       scanf("%s",string1);
       for(i=0; string1[i]!='\0'; i++)
       	string2[i]=string1[i];
       string2[i]='\0';
       printf(" The value of string2 is: ");
       printf("%d",string2);
       getch();
}
 String Copy Without Using Strcpy()

String Copy Without Using Strcpy()

Output :

Enter the value of string1 kaashivinfotech
The value of string2 is : kaashivinfotech


Related Searches to Strcpy in C