i am currently developing program with winhttp and getting stuck while modify value of LPWSTR in URL_COMPONENT struct.
I am make simple script that describe my problem
#include <windows.h>
#include <stdio.h>
int main(int argc, char const *argv[])
{
LPWSTR country = L"America, England, Belgium";
size_t pos = 0;
while(country[pos] != 44) pos++;
country[pos] = 0;
printf("%ls\n", country); // 0x4015b0
return 0;
}
The program receive signal SIGSEGV in line country[pos] = 0
Thanks in advance
>Solution :
LPWSTR country = L"America, England, Belgium";
country is a pointer to the string literal. Attempt to modify string literal invokes Undefined Behaviour which in your case expresses itself as SEGFAULT.
You need to define modifiable wchar array:
wchar_t country[] = L"America, England, Belgium";
You can also use compound literal to initialize pointer:
LPWSTR country = (wchar_t[]){L"America, England, Belgium"};