strcpy - C string.h

C examples for string.h:strcpy

Type

function

From

<cstring> 
<string.h>

Description

Copies the C string from source into the destination, including the terminating null character.

Prototype

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

Parameters

Parameter Description
destination Pointer to the destination array.
source C string to be copied.

Return Value

destination is returned.

Demo Code

#include <stdio.h>
#include <string.h>

int main ()/*from   w  ww  .j  ava2 s .c  o  m*/
{
  char str1[]="Sample string";
  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;
}

Related Tutorials