unsigned short to unicode conversion


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.


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”


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]=0; //terminating character

but this:

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