C String Functions - C strcpy






char *strcpy(char *str1 , const char *str2 );

Copies the string pointed to by str2 to str1.

Copies up to and including the null character of str2. If str1 and str2 overlap the behavior is undefined.

Prototype

char * strcpy ( char * destination, const char * source );

Parameter

This function has the following parameter.

destination
Pointer to the destination array where the content is to be copied.
source
C string to be copied.

Return

destination is returned.

Example


#include <stdio.h>
#include <string.h>
/*ww w . j  a  v a 2  s . c  om*/
int main (){
  char str1[]="this is a test";
  char str2[40];
  char str3[40];
  strcpy (str2,str1);
  strcpy (str3,"copy successful");
  printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
  return 0;
}        

The code above generates the following result.