Open In App

wcsncat() function in C/C++

The wcsncat() function appends the characters of the source to the destination, including a terminating null wide character. If the length of the string in source is less than num. Then only the content up to the terminating null wide character is copied.

Syntax:

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

Parameters: The function accepts three mandatory parameters which are described below:

Return value: The function returns the destination.

Below programs illustrate the above function:

Program 1:




// C++ program to illustrate
// wcsncat() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // maximum length of the destination string
    wchar_t destination[20];
  
    // maximum length of the source string
    wchar_t source[20];
  
    // initialize the destination string
    wcscpy(destination, L"Geekforgeeks ");
  
    // initialize the source string
    wcscpy(source, L"is the best");
  
    // initialize the length of
    // the resulted string you want
    wcsncat(destination, source, 20);
    wprintf(L"%ls\n", destination);
    return 0;
}

Output:
Geekforgeeks is the best

Program 2 :




// C++ program to illustrate
// wcsncat() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // maximum length of the destination string
    wchar_t destination[40];
  
    // maximum length of the source string
    wchar_t source[40];
  
    // initialize the destination string
    wcscpy(destination, L"only some of the  ");
  
    // initialize the source string
    wcscpy(source, L"letters will be copied");
  
    // initialize the length of
    // the resulted string you want
    wcsncat(destination, source, 20);
    wprintf(L"%ls\n", destination);
    return 0;
}

Output:
only some of the  letters will be copi

Article Tags :