Hi folks,
I am trying to set up a list of menu choices for a small device. What I want to do is list the choices in a const array, and show them up on screen one by one as the user cycles through the menu. Unfortunately, the device's code page is UTF16, so I need to preface each choice with an L and store it in a wchar_t variable.
Here's what I have so far.
In the global variables section, I set up the constant wchar_t array of choices.
These will be individually copied into the TextToShow variable, which is picked up by the display function in another module.Code:const wchar_t* menuChoices[] = {
L"Increase Brightness",
L"Decrease Brightness",
L"Check Temp",
L"Save Temp",
L"Exit"
}; //menuChoices
So far so good. Now we move to the main function, when the user presses the Next button. I try to copy the next choice into the VarToShow variable, and that's when things go horribly wrong.Code:extern char TextToShow[];
(The device white-screens at this point, indicating a memory read or write error).Code://Compute string length of this choice
ccLen = wcslen (menuChoices[uCurrentChoiceIndex]);
//Insure it will fit (128-byte limit)
if (ccLen>128) ccLen=128;
//Clear buffer (fill with null characters)
memset(TextToShow, 0, 128);
//Copy text into TTS Buffer
memcpy (TextToShow, menuChoices[uCurrentChoiceIndex], ccLen);
//Show the current choice
ShowMenuText;
However, the below code works fine.
I also tried using strcpy and it didn't crash, but it also only copied the first character (showed I instead of Increase Brightness).Code:memcpy (TextToShow, L"Increase Brightness", 59);
ShowMenuText;
I realize that TextToShow is a char, but the compiler won't let me store L"Hello" in a char. But perhaps wchar_t isn't the correct variable type for menuChoices, either.
Have you any idea what I'm doing wrong? If you can write out an example of the correct procedure, I'd be so thankful!
Thank you so much for reading! I'm completely baffled. Any help at all would be greatly appreciated!