Easy Tutorial
❮ C Function Putchar C Function Scanf ❯

C Library Function - strncat()

C Standard Library - <string.h>

Description

The C library function char *strncat(char *dest, const char *src, size_t n) appends the string pointed to by src to the end of the string pointed to by dest up to n characters long.

Declaration

Here is the declaration for the strncat() function.

char *strncat(char *dest, const char *src, size_t n)

Parameters

Return Value

The function returns a pointer to the resulting string dest.

Example

The following example demonstrates the use of the strncat() function.

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

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

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

   strncat(dest, src, 15);

   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 Function Putchar C Function Scanf ❯