Strcat

From aldeid
Jump to: navigation, search

Syntax

char * strcat ( char * destination, const char * source );

Description

Concatenate strings

Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination.

destination and source shall not overlap.

Parameters

destination
Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.
source
C string to be appended. This should not overlap destination.

Return Value

destination is returned.

Example

Source Run
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
  char hello[10] = "Hello";
  char space[2] = " ";
  char world[10] = "World";

  strcat(hello, space);
  strcat(hello, world);
  printf("%s\n", hello);

  return 0;
}
$ ./code
Hello World