C String Function : strncat()

The strncat() function is used to concatenate(combine) two strings. It is same as strncat() function except that in strncat() we have to specify that how much byte of source data in concatenated into the destination. The syntax for strcat() is as follows :
char * strncat ( char * destination, const char * source, size_t num );
Example :
strncat( str1, str2, 5);
The above statement concatenates the 5 bytes of str1's content into the end of str2 and returns atr1 as a new concatenated string. n strncat( ) operation, null character of destination string is overwritten by source string’s first character and null character is added at the end of new destination string which is created after strncat( ) operation.

Example C Program :
#include <stdio.h>
#include <string.h>

int main() {
  char str1[] = "This is String.";
  char str2[] = "Hello world.";

  strncat(str1, str2, 5);
  printf("%s\n", str1);
  return 0;
Output :

This is String.Hello

Note : We have to include the string.h header in our program to use the string function.

Links :