In C, strcat() copies the second string onto the end of the first. It starts writing where the old '\0' was, then writes a new ending '\0'.
You pass the destination and the source. Both are required. The destination array must already hold a C-string and still have free space for the new characters. Include <string.h>.
Syntax
Pass the destination, then the text to add. Start with this call.
C
strcat(dest, " world");
Call
What it does
strcat(dest, " world")
Adds the second text after the text already in dest.
Include <string.h>. The destination must have enough free space. This call does not grow the array.
Library declarations
C
char *strcat(char *dest, const char *src);
Parameters
Parameter
Description
dest
Required. The C-string you add onto. It must already have room for the new text and a final '\0'.
src
Required. The C-string you copy from. It is not changed.
Return Value
Return Value
Description
dest pointer
The same destination pointer you passed in.
C Examples
Example 1 — Append One String
Join a short suffix onto an existing string. The buffer must be larger than the final result.