C Standard Libraries C++

wcsncpy()

Declaration

wchar_t* wcsncpy(wchar_t* wpDest,
         		const wchar_t* kwpSource,
         		size_t uiCopySize);

Description

This function copies the first "uiCopySize" wide-characters of "kwpSource" to the beginning of the string "wpDest." The function returns a pointer to "wpDest."

Example

#include <cwchar>

int main()
{
    wchar_t waString1[] = L"Video Tutorials";
    wchar_t waString2[] = L"XoaX.net";
    size_t uiCopySize = 5;

    wprintf(L"%u characters of \"%ws\" were copied to \"%ws\"\n",
        uiCopySize, waString2, waString1);
    // Copy the first 5 characters
    wcsncpy(waString1, waString2, uiCopySize);
    wprintf(L"The Result is = %ws\n", waString1);

    // Keep the window open until "Enter" is pressed
    getwchar();
    return 0;
}

Output

wcsncpy() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.