Easy Tutorial
❮ C Exercise Example46 C Exercise Example77 ❯

C Library Function - strcat()

C Standard Library - <string.h>

Description

The C library function char *strcat(char *dest, const char *src) appends the string pointed to by src to the end of the string pointed to by dest.

Declaration

Here is the declaration for the strcat() function.

char *strcat(char *dest, const char *src)

Parameters

Return Value

The function returns a pointer to the final destination string dest.

Example

The following example demonstrates the usage of the strcat() function.

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

int main ()
{
   char src[50], dest[50];

   strcpy(src,  "This is source");
   strcpy(dest, "This is destination");

   strcat(dest, src);

   printf("Final destination string: |%s|", dest);

   return(0);
}

Let's compile and run the above program, which will produce the following result:

Final destination string: |This is destinationThis is source|

C Standard Library - <string.h>

❮ C Exercise Example46 C Exercise Example77 ❯