strcpy, wcscpy, _mbscpy

Copia una stringa. Sono disponibili versioni più sicure di queste funzioni; vedere strcpy_s, wcscpy_s, _mbscpy_s.

Importante

_mbscpy non può essere utilizzato in applicazioni che vengono eseguite in Windows Runtime. Per altre informazioni, vedere Funzioni CRT non supportate nelle app della piattaforma UWP (Universal Windows Platform).

Sintassi

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
);
template <size_t size>
char *strcpy(
   char (&strDestination)[size],
   const char *strSource
); // C++ only
template <size_t size>
wchar_t *wcscpy(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource
); // C++ only
template <size_t size>
unsigned char *_mbscpy(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource
); // C++ only

Parametri

strDestination
Stringa di destinazione.

strSource
Stringa di origine con terminazione null.

Valore restituito

Ognuna di queste funzioni restituisce la stringa di destinazione. Nessun valore restituito è riservato per indicare un errore.

Osservazioni:

La funzione strcpy copia strSource, incluso il carattere Null di terminazione, nel percorso specificato da strDestination. Se le stringhe di origine e di destinazione si sovrappongono, il comportamento di strcpy non è definito.

Importante

strcpy non verifica la presenza di spazio sufficiente in strDestination prima di copiare strSource; è pertanto una causa possibile dei sovraccarichi del buffer. Pertanto, è consigliabile usare strcpy_s invece .

wcscpy e _mbscpy sono versioni, rispettivamente, con caratteri wide e caratteri multibyte di strcpy. Gli argomenti e il valore restituito di sono stringhe di wcscpy caratteri wide. Gli argomenti e il valore restituito di sono stringhe di _mbscpy caratteri multibyte. A parte ciò, queste tre funzioni si comportano in modo identico.

In C++ queste funzioni presentano overload di modello che richiamano le relative controparti più recenti e sicure. Per altre informazioni, vedere Proteggere gli overload dei modelli.

Per impostazione predefinita, lo stato globale di questa funzione è limitato all'applicazione. Per modificare questo comportamento, vedere Stato globale in CRT.

Mapping di routine di testo generico

TCHAR.H Routine _UNICODE e _MBCS non definito _MBCS Definito _UNICODE Definito
_tcscpy strcpy _mbscpy wcscpy

Requisiti

Ciclo Intestazione obbligatoria
strcpy <string.h>
wcscpy <string.h> oppure <wchar.h>
_mbscpy <mbstring.h>

Per altre informazioni sulla compatibilità, vedere Compatibility (Compatibilità).

Esempio

// crt_strcpy.c
// compile with: /W3
// This program uses strcpy
// and strcat to build a phrase.

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

int main( void )
{
   char string[80];

   // If you change the previous line to
   //   char string[20];
   // strcpy and strcat will happily overrun the string
   // buffer.  See the examples for strncpy and strncat
   // for safer string handling.

   strcpy( string, "Hello world from " ); // C4996
   // Note: strcpy is deprecated; use strcpy_s instead
   strcat( string, "strcpy " );           // C4996
   // Note: strcat is deprecated; use strcat_s instead
   strcat( string, "and " );              // C4996
   strcat( string, "strcat!" );           // C4996
   printf( "String = %s\n", string );
}
String = Hello world from strcpy and strcat!

Vedi anche

Manipolazione delle stringhe
strcat, wcscat, _mbscat
strcmp, wcscmp, _mbscmp
strncat, _strncat_l, wcsncat, _wcsncat_l, _mbsncat, _mbsncat_l
strncmp, wcsncmp, _mbsncmp, _mbsncmp_l
strncpy, _strncpy_l, wcsncpy, _wcsncpy_l, _mbsncpy, _mbsncpy_l
_strnicmp, _wcsnicmp, _mbsnicmp, _strnicmp_l, _wcsnicmp_l, _mbsnicmp_l
strrchr, wcsrchr, _mbsrchr, _mbsrchr_l
strspn, wcsspn, _mbsspn, _mbsspn_l