strncat : <string.h> library function

The function char *strncat(char *destination, const char *source, size_t n); appends first n characters of string pointed by source at the end of string pointed by destination. It will overwrite null character of destination string and append a null character at the end of combined string. Destination string should be large enough to contain the concatenated string.

Function prototype of strncat

char *strncat(char *destination, const char *source, size_t n);
  • destination : This is pointer to destination array(containing a null terminated string) where we want to append characters from source string.
  • source : It is a pointer to a string to be appended. This should not overlap with destination string.
  • n : Number of characters to be appended.

Return value of strncat

This function returns a pointer to destination string(after appending characters from source string).

C program to show the use of strncat function

The following program shows the use of strncat function to append characters from one string at the end of another string.

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

int main()
   char stringOne[100], stringTwo[100];

   printf("Enter first string\n");
   printf("Enter second string\n");
   strncat(stringTwo, stringOne, 5);
   printf("Second string after strncat\n%s", stringTwo);


Program Output
Enter first string
Enter second string
Second string after strncat