strcpy

#include <string.h>
char *strcpy(char *str1, const char *str2);

Description

strcpy copy a c string pointed by str2 into the array pointed by str1 including the terminating null character.

strcpy C Example Code

/* 
 * strcpy c example code
 * http://code-reference.com/c/string.h/strcpy 
 */
#include <stdio.h> /* including standard library */
#include <string.h>
 
int main( void ) 
{
  char string[] = "copy me"; /* the size of the array is calculated automatically */
  char string2[20];
 
 
  if( strcpy(string2, string) != 0 )
    printf( "copy success: %s\n",  string2 );
  else
    printf( "copy failure\n" );
  return 0;
}

Output of strcpy example

  user@host:~$ ./strcpy 
  copy success: copy me