Syntax
#include <wchar.h> wchar_t *wcsncpy(wchar_t *string1, const wchar_t *string2, size_t count);Description
wcsncpy copies up to count wide characters from string2 to string1. If string2 is shorter than count characters, string1 is padded out to count characters with wchar_t null characters.
wcsncpy operates on null-terminated wide-character strings; string arguments to this function should contain a wchar_t null character marking the end of the string.
wcsncpy returns a pointer to string1.
This example demonstrates the difference between wcscpy, which copies the entire wide-character string, and wcsncpy, which copies a specified number of wide characters from the string.
#include <stdio.h> #include <wchar.h> #define SIZE 40 int main(void) { wchar_t source[SIZE] = L"123456789"; wchar_t source1[SIZE] = L"123456789"; wchar_t destination[SIZE] = L"abcdefg"; wchar_t destination1[SIZE] = L"abcdefg"; wchar_t *return_string; int index = 5; /* This is how wcscpy works */ printf("destination is originally = '%ls'\n", destination); return_string = wcscpy(destination, source); printf("After wcscpy, destination becomes '%ls'\n\n", return_string); /* This is how wcsncpy works */ printf("destination1 is originally = '%ls'\n", destination1); return_string = wcsncpy(destination1, source1, index); printf("After wcsncpy, destination1 becomes '%ls'\n", return_string); return 0; /**************************************************************************** The output should be: destination is originally = 'abcdefg' After wcscpy, destination becomes '123456789' destination1 is originally = 'abcdefg' After wcsncpy, destination1 becomes '12345fg' ****************************************************************************/ }Related Information