tags:

views:

76

answers:

2

While using wmemset api (http://msdn.microsoft.com/en-us/library/1fdeehz6(VS.80).aspx) for the count parameter should I have to multiply the length of the target string by 2 and provide or will wmemset will itself take care of the conversion?

+3  A: 

The answer is no. They have an example on the page you linked to:

#include <wchar.h>
#include <stdio.h>

int main( void )
{
    wchar_t buffer[] = L"This is a test of the wmemset function";

    wprintf( L"Before: %s\n", buffer );
    wmemset( buffer, '*', 4 );
    wprintf( L"After:  %s\n", buffer );
}

Output:

Before: This is a test of the wmemset function
After:  **** is a test of the wmemset function

Of course, the destination must have enough space (sizeof(wchar_t) times the number of characters being written to).

Alok
Thanks.. My mistake. Should have read completely.. :)
bdhar
+1  A: 

No, you should not. Length is in string characters (wchar_t), not in bytes (char). You need to pass the number of wide characters.

sharptooth