wcsncat() function in C/C++
Last Updated :
17 Sep, 2018
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:
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t destination[20];
wchar_t source[20];
wcscpy(destination, L "Geekforgeeks " );
wcscpy(source, L "is the best" );
wcsncat(destination, source, 20);
wprintf(L "%ls\n" , destination);
return 0;
}
|
Output:
Geekforgeeks is the best
Program 2 :
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t destination[40];
wchar_t source[40];
wcscpy(destination, L "only some of the " );
wcscpy(source, L "letters will be copied" );
wcsncat(destination, source, 20);
wprintf(L "%ls\n" , destination);
return 0;
}
|
Output:
only some of the letters will be copi
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...