strcat(3)

strcat3

String copy/catenate

Part of strcpy(3).

Usage

#include <string.h>

char *strcpy(char *restrict dst, const char *restrict src); char *strcat(char *restrict dst, const char *restrict src);

Library

Standard C library (libc, -lc)

Overview

strcpy()

This function copies the string pointed to by src, into a string at the buffer pointed to by dst. The programmer is responsible for allocating a destination buffer large enough, that is, strlen(src) + 1.

It is equivalent to

stpcpy(dst, src), dst
strcat()

This function catenates the string pointed to by src, after the string pointed to by dst (overwriting its terminating null byte). The programmer is responsible for allocating a destination buffer large enough, that is, strlen(dst) + strlen(src) + 1.

It is equivalent to

stpcpy(strnul(dst), src), dst

Return value

These functions return dst.

Attributes

For an explanation of the terms used in this section, see attributes(7).

InterfaceAttributeValue
strcpy(), strcat()Thread safetyMT-Safe

Caveats

The strings src and dst may not overlap.

If the destination buffer is not large enough, the behavior is undefined. See _FORTIFY_SOURCE in feature_test_macros(7).

Examples

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(void)
{
    char    *buf1;
    size_t  len, size;
    size = strlen("Hello ") + strlen("world") + strlen("!") + 1;
    buf1 = malloc(sizeof(*buf1) * size);
    if (buf1 == NULL)
        err(EXIT_FAILURE, "malloc()");
    strcpy(buf1, "Hello ");
    strcat(buf1, "world");
    strcat(buf1, "!");
    len = strlen(buf1);
    printf("[len = %zu]: ", len);
    puts(buf1);  // "Hello world!"
    free(buf1);
    exit(EXIT_SUCCESS);
}

Releases

19 releases since Debian 1.1 (Buzz); the text changed 13 times.

  1. 1.1–2.2
  2. 3.0
  3. 3.1
  4. 4.0
  5. 5.0
  6. 6.0
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. Arch

Standards

C11, POSIX.1-2008.

History

POSIX.1-2001, C89, SVr4, 4.3BSD.

From man-pages 6.19-1 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.