Jump to content

C++ Programming/Code/Standard C Library/Functions/strcat

From Wikibooks, open books for an open world

strcat

[edit | edit source]
Syntax
#include <cstring>
char *strcat( char *str1, const char *str2 );

The strcat() function concatenates str2 onto the end of str1, and returns str1. For example:

printf( "Enter your name: " );
scanf( "%s", name );
title = strcat( name, " the Great" );
printf( "Hello, %s\n", title );  ;

Note that strcat() does not perform bounds checking, and thus risks overrunning str1 or str2. For a similar (and safer) function that includes bounds checking, see strncat().


Related topics
strchr - strcmp - strcpy - strncat