[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

_wmemcpy problem

The following code produces unexpected results whereby the buffer is populated correctly by memcpy bur not so buy _memcpy; _wmemcpy appends additional characters after "Hello" I have tried this with BCB 5 and BCB6 with the same results in each case.

Is this a bug ?

#include <mem.h>
#include <string.h>

char buff[40];

memset(buff,0,sizeof(buff));
memcpy(buff,"Hello",5);
_wmemcpy(buff,"Hello",5);

0
alcindor
Asked:
alcindor
1 Solution
 
balderCommented:
It is not a bug.

_wmemcpy is a wide string version of memcpy, the string you have given is 5 bytes long, but you instruct the function to copy 5 words (10 bytes)

correct could would be:
 _wmemcpy( buff, L"Hello", 5 );
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now