strcat_s, wcscat_s, _mbscat_s, _mbscat_s_l

Aggiunge una stringa. Queste versioni di , includono _mbscat miglioramenti per la sicurezza, come descritto in Funzionalità di sicurezza in CRT. wcscatstrcat

Importante

_mbscat_s e _mbscat_s_l non possono essere usati nelle applicazioni eseguite in Windows Runtime. Per altre informazioni, vedere Funzioni CRT non supportate nelle app della piattaforma UWP (Universal Windows Platform).

Sintassi

errno_t strcat_s(
   char *strDestination,
   size_t numberOfElements,
   const char *strSource
);
errno_t wcscat_s(
   wchar_t *strDestination,
   size_t numberOfElements,
   const wchar_t *strSource
);
errno_t _mbscat_s(
   unsigned char *strDestination,
   size_t numberOfElements,
   const unsigned char *strSource
);
errno_t _mbscat_s_l(
   unsigned char *strDestination,
   size_t numberOfElements,
   const unsigned char *strSource,
   _locale_t locale
);
template <size_t size>
errno_t strcat_s(
   char (&strDestination)[size],
   const char *strSource
); // C++ only
template <size_t size>
errno_t wcscat_s(
   wchar_t (&strDestination)[size],
   const wchar_t *strSource
); // C++ only
template <size_t size>
errno_t _mbscat_s(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource
); // C++ only
template <size_t size>
errno_t _mbscat_s_l(
   unsigned char (&strDestination)[size],
   const unsigned char *strSource,
   _locale_t locale
); // C++ only

Parametri

strDestination
Buffer della stringa di destinazione con terminazione Null.

numberOfElements
Dimensioni del buffer della stringa di destinazione.

strSource
Buffer della stringa di origine che termina con Null.

locale
Impostazioni locali da usare.

Valore restituito

Zero se con esito positivo; un codice di errore in caso di errore.

Condizioni di errore

strDestination numberOfElements strSource Valore restituito Contenuto di strDestination
NULL o senza terminazione qualsiasi qualsiasi EINVAL non modificato
qualsiasi qualsiasi NULL EINVAL strDestination[0] impostato su 0
qualsiasi 0 o troppo piccolo qualsiasi ERANGE strDestination[0] impostato su 0

Osservazioni:

La funzione strcat_s aggiunge strSource a strDestination e termina la stringa risultante con un carattere Null. Il carattere iniziale di strSource sovrascrive il carattere Null di terminazione di strDestination. Se le stringhe di origine e di destinazione si sovrappongono, il comportamento di strcat_s non è definito.

Il secondo parametro è la dimensione totale del buffer, non le dimensioni rimanenti:

char buf[16];
strcpy_s(buf, 16, "Start");
strcat_s(buf, 16, " End");               // Correct
strcat_s(buf, 16 - strlen(buf), " End"); // Incorrect

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

Se strDestination è un puntatore Null o non è con terminazione Null o se strSource è un NULL puntatore o se la stringa di destinazione è troppo piccola, viene richiamato il gestore di parametri non validi, come descritto in Convalida dei parametri. Se l'esecuzione può continuare, queste funzioni restituiscono EINVAL e impostano errno su EINVAL.

Le versioni delle funzioni con il _l suffisso hanno lo stesso comportamento, ma usano il parametro delle impostazioni locali passato anziché le impostazioni locali correnti. Per altre informazioni, vedere Locale.

In C++ l'utilizzo di queste funzioni è semplificato dagli overload dei modelli. Gli overload possono dedurre la lunghezza del buffer automaticamente (eliminando la necessità di specificare un argomento di dimensione) e possono sostituire automaticamente le funzioni precedenti e non sicure con le controparti più recenti e sicure. Per altre informazioni, vedere Proteggere gli overload dei modelli.

Le versioni della libreria di debug di queste funzioni riempiono prima di tutto il buffer con 0xFE. Per disabilitare questo comportamento, usare _CrtSetDebugFillThreshold.

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
_tcscat_s strcat_s _mbscat_s wcscat_s

Requisiti

Ciclo Intestazione obbligatoria
strcat_s <string.h>
wcscat_s <string.h> oppure <wchar.h>
_mbscat_s <mbstring.h>

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

Esempio

Vedere l'esempio di codice in strcpy_s, wcscpy_s, _mbscpy_s.

Vedi anche

Manipolazione delle stringhe
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