0

Hi could you please help us in copying one wchar_t* to another wchar_t*.

I'm using the following code:

wchar_t* str1=L"sreeni";
wchar_t* str2; 

wcscpy(str2,str1); 

In the last line I'm getting a run time error as without allocating memory to *str2, i'm trying to copy the value of str1;

is there any method like wcscpy to copy wchar_t pointer to another wchar_t pointer?

I dont want to use wide character arrays, i.e there shouldn't be any restriction on the size of string. And I want to copy the content of complete string str1 into string str2.

T. Junghans
  • 11,385
  • 7
  • 52
  • 75

1 Answers1

0

I assume you mean you want to duplicate the string, rather than just the pointer.

wcsdup() is the wide equivalent of strdup(), which will allocate the memory for the duplicated string.

JasonD
  • 16,464
  • 2
  • 29
  • 44