Strcpy

From aldeid
Jump to: navigation, search

Syntax

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

Description

Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).

To avoid overflows, the size of the array pointed by destination shall be long enough to contain the same C string as source (including the terminating null character), and should not overlap in memory with source.

Parameters

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

Return Value

destination is returned.

Example

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

int main(int argc, char *argv[])
{
  char hello[10] = "Hello";
  char world[10] = "World";

  printf("Before strcpy: %s %s\n", hello, world);

  strcpy(world, hello);
  printf("After strcpy: %s %s\n", hello, world);

  return 0;
}
$ ./code
Before strcpy: Hello World
After strcpy: Hello Hello