C/C++ Access violation writing when changing array value

0

This will be a foolishness, but this code to change the Drive letter of the Wide-String throws me an Acces violation when writting the new value. (0xC0000005)

wchar_t* disk2 = L"D";
wchar_t* wszDrive = L"\\\\.\\C:";
wszDrive[5] = *disk2; //here is the acces violation

I'm using the lattest version of Visual Studio 2019.

Also I tried this way:

wchar_t* disk2 = L"D";
wchar_t* wszDrive = L"\\\\.\\C:";
memcpy(&wszDrive[5], disk2, 2);

And this other way:

wchar_t* disk2 = L"D";
wchar_t* wszDrive = L"\\\\.\\C:";
memcpy(wszDrive+10, disk2, 2);
c
memory
runtime-error
access-violation
asked on Stack Overflow May 23, 2021 by user1814720

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0