C Standard Library

C <wchar.h> - wcsncat() Function



The C <wchar.h> wcsncat() function is used to append first num characters of wide string pointed to by source to the end of wide string pointed to by destination. The terminating null character in destination is overwritten by the first character of source, and the resulting wide string is null-terminated.

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

Syntax

wchar_t* wcsncat (wchar_t* destination, const wchar_t* source, size_t num);

Parameters

destination Specify pointer to the null-terminated wide string to append to.
source Specify pointer to the null-terminated wide string to copy from.
num Specify maximum number of characters to copy.
size_t is an unsigned integer type.

Return Value

Returns destination.

Example:

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

#include <stdio.h>
#include <wchar.h>
 
int main (){
  wchar_t str1[256] = L"Hello ";
  wchar_t str2[256] = L"World!. Programming is fun.";
  
  //concatenating str1 with first 
  //7 characters of str2
  wcsncat(str1, str2, 7);
  printf("str1 is: %ls\n", str1);  
 
  return 0;
}

The output of the above code will be:

str1 is: Hello World!.

❮ C <wchar.h> Library

5