wmemcpy() function in C/C++
Last Updated :
05 Feb, 2021
The wmemcpy() function is specified in header file cwchar.h and copies a specified number of character from one string to the other. This function doesn’t check for any terminating null wide character in the first string called source it always copies exactly n characters to the second string called destination.
Syntax:
wchar_t* wmemcpy( wchar_t* destination, const wchar_t* source, size_t n )
Parameter: The function accepts three mandatory parameters which are described below:
- destination: specifies a pointer where the characters are to be copied.
- source: specifies a pointer where the data are present.
- n: specifies the number of characters to be copied.
Return value: The function returns the destination string.
Below programs illustrate the above function:
Program 1 :
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t destination[20];
wchar_t source[] = L "geeks are for geeks" ;
int n = 13;
wmemcpy(destination, source, n);
wcout << L "Initial string -> " << source << "\n" ;
wcout << L "Final string -> " ;
for ( int i = 0; i < n; i++)
putwchar(destination[i]);
return 0;
}
|
Output:
Initial string -> geeks are for geeks
Final string -> geeks are for
Program 2 :
C++
#include <bits/stdc++.h>
using namespace std;
int main()
{
wchar_t destination[3];
wchar_t source[] = L "GFG" ;
int n = 3;
wmemcpy(destination, source, n);
wcout << L "Initial string -> " << source << "\n" ;
wcout << L "Final string -> " ;
for ( int i = 0; i < n; i++)
putwchar(destination[i]);
return 0;
}
|
Output:
Initial string -> GFG
Final string -> GFG
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...