strcpy, wcscpy, _mbscpy

Copy a string.

char *strcpy( char *strDestination, const char *strSource );

wchar_t *wcscpy( wchar_t *strDestination, const wchar_t *strSource );

unsigned char *_mbscpy( unsigned char *strDestination, const unsigned char *strSource );

Routine Required Header Compatibility
strcpy <string.h> ANSI, Win 95, Win NT
wcscpy <string.h> or <wchar.h> ANSI, Win 95, Win NT
_mbscpy <mbstring.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns the destination string. No return value is reserved to indicate an error.

Parameters

strDestination

Destination string

strSource

Null-terminated source string

Remarks

The strcpy function copies strSource, including the terminating null character, to the location specified by strDestination. No overflow checking is performed when strings are copied or appended. The behavior of strcpy is undefined if the source and destination strings overlap.

wcscpy and _mbscpy are wide-character and multibyte-character versions of strcpy. The arguments and return value of wcscpy are wide-character strings; those of _mbscpy are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tcscpy strcpy _mbscpy wcscpy

Example

/* STRCPY.C: This program uses strcpy
 * and strcat to build a phrase.
 */

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

void main( void )
{
   char string[80];
   strcpy( string, "Hello world from " );
   strcat( string, "strcpy " );
   strcat( string, "and " );
   strcat( string, "strcat!" );
   printf( "String = %s\n", string );
}

Output

String = Hello world from strcpy and strcat!

String Manipulation Routines

See Also   strcat, strcmp, strncat, strncmp, strncpy, _strnicmp, strrchr, strspn