C Standard Library

C <string.h> - strcat() Function



The C <string.h> strcat() function is used to append a copy of the character string pointed to by source to the end of character string pointed to by destination. The terminating null character in destination is overwritten by the first character of source, and the resulting byte string is null-terminated.

The behavior is undefined if the destination is not large enough for the content of resulting byte string (including the null character), or if the strings overlap.

Syntax

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

Parameters

destination Specify pointer to the null-terminated byte string to append to.
source Specify pointer to the null-terminated byte string to copy from.

Return Value

Returns destination.

Example:

The example below shows the usage of strcat() function.

#include <stdio.h>
#include <string.h>
 
int main (){
  char str[100] = "Hello ";
  strcat(str, "World!.");
  printf("%s\n", str);  

  char str2[50] = " Programming is fun.";
  strcat(str, str2);
  printf("%s\n", str);   
  return 0;
}

The output of the above code will be:

Hello World!.
Hello World!. Programming is fun.

❮ C <string.h> Library