multibyte length

J

Jordan Abel

Is there a function to find the length, in wide characters, of a
multibyte string?
 
M

Micah Cowan

Jordan Abel said:
Is there a function to find the length, in wide characters, of a
multibyte string?

<OT>
If you have the POSIX version of mbstowcs, you can pass it a NULL
first argument to get this number.
</OT>

If you limit yourself to Standard C, I think you have to actually
perform the conversion, and then find out with wcslen().
 
J

Jordan Abel

<OT>
If you have the POSIX version of mbstowcs, you can pass it a NULL
first argument to get this number.

Given that this came up when i was trying to answer someone's question
in c.u.p, this is relevant, thanks.
</OT>

If you limit yourself to Standard C, I think you have to actually
perform the conversion, and then find out with wcslen().

The reason for this was to be able to perform the conversion into memory
that is from malloc while calling malloc only once. in order to make a
wide copy of argv to pass to a "wmain"
 
M

Micah Cowan

Jordan Abel said:
Given that this came up when i was trying to answer someone's question
in c.u.p, this is relevant, thanks.


The reason for this was to be able to perform the conversion into memory
that is from malloc while calling malloc only once. in order to make a
wide copy of argv to pass to a "wmain"

Makes sense to me: snprintf() allows this. It's beyond me why Standard
C neglected to provide such a thing in the first place. I kind of hope
that future versions will add the POSIX behavior, as it's very useful,
and certainly not hard to implement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top