I'm trying to make a program that prints a random file path. Here's the code I have, but I don't think it's correct because it crashes.
This code is supposed to create a new wchar variable, fill it with the system directory path, add "\x", and add a char converted from a random int between 97-123.
srand(time(NULL)); WCHAR path[MAX_PATH]; wcscpy_s(path, systemdirectory); wcscat_s(path, L"\\x"); WCHAR randomname[MAX_PATH]; swprintf_s(randomname, L"%s", char(rand() % (123 - 97) + 97)); //this crashes my program wcscat_s(path, randomname); wcscat_s(path, L".exe"); std::wcout << path;
The error is: "Access violation reading location 0x0000006a."
Any hints?
Thanks.

New Topic/Question
Reply


MultiQuote


|