unsigned short to unicode conversion

Hi,

I have a requirement to convert the “unsiged short” string into unicode format (i.e wchar_t type)

For example :

unsigned short str[50];

strcpy((char *)str, “How are you”);

Here the “str” should be converted to unicode (wchar_t)

Appreciate your help.

Regards,
-Subu

store your string in a char* and use mbstowcs().

RTFM :wink:

Thanks for your information. I cannot makeit as char * as I’ m reading the string from third party and their type is “unsigned short”

–Thanks

Hmm, that’s mean:

ordinary string is 1 Byte per character.
unicode is 2 Byte per character, unsigned short is 2 bytes per character (so you are already getting unicode)
wchar_t is 4 byte for whatever reason.

so all I can think off now is to copy character by character in a loop

[code]//assuming your string is terminated by \0

unsigned short src[100];
wchar_t dst[100];
int idx=0;

while((src[idx]) && (idx<99)) {
dst[idx]=src[idx++];
}

dst[idx]=0; //terminating character
[/code]

but this:

would make your str an onrdinary ‘1byte string’.