strcat() — Concatenate strings
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <string.h>
char *strcat(char * __restrict__string1, const char * __restrict__string2);
General description
The strcat() built-in function concatenates string2 with string1 and ends the resulting string with the NULL character. In other words, strcat() appends a copy of the string pointed to by string2—including the terminating NULL byte— to the end of a string pointed to by string1, with its last byte (that is, the terminating NULL byte of string1) overwritten by the first byte of the appended string.
Do 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.
Returned value
Returns the value of string1, the concatenated string.
Example
CELEBS34
/* CELEBS34
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
buffer1 = computer program