strcpy()

Copies one character array to another.

  #include <string.h>
  
  char *strcpy(char *dest, const char *source);    
Parameter

dest

A pointer to a memory area to copy the character string to.

source

A pointer to the character string to copy.

Remarks

This function function copies the character array pointed to by source to the character array pointed to dest. The source argument must point to a null-terminated character array. The resulting character array at dest will be null-terminated.

This function has undefined behavior if the arrays pointed to by dest and source overlap. This function can be the cause of buffer overflow bugs in your program if the memory area pointed to by dest is not large enough to contain source. Consider using strncpy() instead.

The function returns the value of dest.

This facility may not be available on some configurations of the EWL.

Listing: Example of strcpy() usage

#include <string.h>

#include <stdio.h>

int main(void)

{

char s[] = "woodworking";

/* String d must be large enough to contain string s. */

char d[30] = "";

printf(" s=%s\n d=%s\n", s, d);

strcpy(d, s);

printf(" s=%s\n d=%s\n", s, d);

return 0;

}

Output:

s=woodworking

d=

s=woodworking

d=woodworking