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:



  • destination: specifies the pointer to the destination array
  • source: specifies the string to be added to the destination
  • num: specifies the maximum number of character to be added

Return value: The function returns the destination.

Below programs illustrate the above function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

Geekforgeeks is the best

Program 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

only some of the  letters will be copi


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.