I'm using following code:
int main () {
wchar_t *serial = new wchar_t[1];
wchar_t *user = new wchar_t[1];
size_t strLen;
do {
wprintf (L"Username (between 4 and 30 characters): ");
wscanf (L"%ls", user);
} while ((strLen = wcslen (user)) < 4 || strLen > 30);
wprintf (L"Serial key: ");
wscanf (L"%ls", serial);
std::getchar ();
std::getchar (); // Twice, because of trailing \n of wscanf()
delete[] serial; // Error!
delete[] user;
return 0;
}
Everytime I'm getting an assertion failure. Here I read that I have to use delete[]
instead of delete
, if I want to deallocate arrays. So I corrected my code and was still getting the exact same error. In this forum I read that the pointer that I want to delete mustn't change. I checked my pointer with cout << (int)serial;
and the printed number wasn't changing. How to deallocate an array? Everytime I use delete
(no matter when/where) I get assertion failures. Am I making something wrong?