Unicode strings

How can I convert a unicode string into an ordinary one (using the system
locale), and vice-versa?

How can I convert a unicode string into an ordinary one (using the system
locale), and vice-versa?

I think I have to be more specific.
What I found out is that in QNX unicode strings are 32-bit (why could it
be?), but I’m used to 16-bit. So, to make the conversion, I had to write
something like this:

uint16_t source[100]; // 16-bit unicode
wchar_t temp[100]; // 32-bit unicode
char dest[100]; // multibyte
int i;
for (i = 0; i < 100; i++) temp = source;
wcstombs(dest, temp, 100);

I don’t think this is the right way. Could somebody please give me a tip?

Domo <domoratski@mail.ru> wrote:

How can I convert a unicode string into an ordinary one (using the system
locale), and vice-versa?

I think I have to be more specific.
What I found out is that in QNX unicode strings are 32-bit (why could it
be?), but I’m used to 16-bit. So, to make the conversion, I had to write
something like this:

uint16_t source[100]; // 16-bit unicode
wchar_t temp[100]; // 32-bit unicode
char dest[100]; // multibyte
int i;
for (i = 0; i < 100; i++) temp > = source> ;
wcstombs(dest, temp, 100);

I don’t think this is the right way. Could somebody please give me a tip?

Wide characters changed from 16-bits to 32-bits in the past, not too sure when,
but I remember the heartache! Anyhow, all the c-lib routines require 32-bit
wide characters. The reason for 32-bit wide characters is twofold, alignment
as well as speed of operating on 32-bit words, and Unicode 4.0 will extend the range
of Unicode past 16-bits.

You conversion is correct. Standard GNU has gone to 32-bits as well.
Is there as reason you wish to store everything in 16-bits? It be easier
just to store everything in 32-bits from the start.

Regards.