strcpy, wcscpy (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Copy a string.

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

Parameters

  • strDestination
    Destination string.
  • strSource
    Null-terminated source string.

Return Values

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

Remarks

These functions are supported by all versions of the C run-time libraries.

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 is the wide-character version of strcpy. The arguments and return value of wcscpy are wide-character strings. These two functions behave identically otherwise.

The NULL pointer is not allowed to the wcscpy function. The system behavior is unpredictable if a NULL pointer is used for either source or destination string pointer of the wcscpy function.

The first argument, strDestination, must be large enough to hold strSource and the closing '\0'; otherwise, a buffer overrun can occur.

This can lead to a denial of service attack against the application if an access violation occurs, or in the worst case, allow an attacker to inject executable code into your process. This is especially true if strDestination is a stack-based buffer. Consider using strncpy or wcsncpy, or consider using an appropriate strsafe function.

For more information, see Safe String Functions.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_tcscpy wcscpy

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

This program uses strcpy and strcat to build a phrase.

Code

#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!

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, string.h.

Link Library: coredll.dll.

See Also

strcat | strcmp | strncat | strncmp | strncpy

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.