Nemesis
Nemesis

Reputation: 109

array of wchar_t

I would like to have an array of wchar_t's.

The following works:

char** stringArray;
int maxWords = 3;
stringArray = new char*[maxWords];
stringArray[0] = "I";
stringArray[1] = " Love ";
stringArray[2] = "C++"

but this does not

wchar_t ** wcAltFinalText;
wcAltFinalText = new wchar_t *[MAX_ALT_SOURCE];   // MAX_ALT_SOURCE = 4
wcAltFinalText[0] = L'\0';
wcAltFinalText[1] = L'\0';
wcAltFinalText[2] = L'\0';
wcAltFinalText[3] = L'\0';

I do not get any error but wcAltFinalText is a bad ptr

Any help and comments are much appreciated.

Upvotes: 2

Views: 10803

Answers (3)

Erik
Erik

Reputation: 91300

wcAltFinalText[0] = L'\0';

L'\0' is a wide character literal, this is an integral type - the above line corresponds to

wcAltFinalText[0] = 0;

What you want is a string literal, L"\0";

Upvotes: 5

Naveen
Naveen

Reputation: 73473

You are using '' instead of "", so the assignment wcAltFinalText[0] = L'\0'; is equivalent to wcAltFinalText[0] = 0;

Upvotes: 7

sharptooth
sharptooth

Reputation: 170509

Well, you just set all elements in the newly created array to null pointers (because L'\0' is "null character", not an "empty string") - what else would you expect? You have the same effect as with this code:

wcAltFinalText[0] = 0;
wcAltFinalText[1] = 0;
wcAltFinalText[2] = 0;
wcAltFinalText[3] = 0;

and Visual Studio displays null pointers as "bad ptr" meaning no data can be behind such pointer.

Upvotes: 2

Related Questions