wcsncpy() function in C++ with example
Last Updated :
05 Oct, 2018
The wcsncpy() function is defined in cwchar.h header file. The wcsncpy() function copies a specified number of wide characters from source to destination.
Syntax:
wchar_t *wcsncpy(wchar_t *dest,
const wchar_t *src,
size_t n);
Parameters: This method accepts the following three parameters:
- dest: specifies the pointer to the destination array.
- src: specifies the pointer to the source array.
- n: represents the number of character to copy.
Return Value: This function returns the modified destination.
Below programs illustrate the above function:-
Example 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t src[] = L "A Computer Science portal for geeks" ;
wchar_t dest[40];
wcsncpy(dest, src, 19);
wcout << "Destination string is : " << dest;
return 0;
}
|
Output:
Destination string is : A Computer Science
Example 2:-
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t src[] = L "GeeksforGeeks" ;
wchar_t dest[40];
wcsncpy(dest, src, 5);
wcout << "Destination string is : " << dest;
return 0;
}
|
Output:
Destination string is : Geeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...