Format
#include <string.h>
char *strcat(char *string1, const char *string2);
Language Level: ANSI
Threadsafe: Yes.
Description
The strcat() function concatenates string2 to string1 and ends the resulting string with the null character.
The strcat() function operates on null-ended strings. The string arguments to the function should contain a null character (\0) that marks the end of the string. No length checking is performed. You should not use a literal string for a string1 value, although string2 may be a literal string.
If the storage of string1 overlaps the storage of string2, the behavior is undefined.
Return Value
The strcat() function returns a pointer to the concatenated string (string1).
Example that uses strcat()
This example creates the string "computer program" using strcat().
#include <stdio.h>
#include <string.h>
#define SIZE 40
int main(void)
{
char buffer1[SIZE] = "computer";
char * ptr;
ptr = strcat( buffer1, " program" );
printf( "buffer1 = %s\n", buffer1 );
}
/***************** Output should be similar to: *****************
buffer1 = computer program
*/
Related Information