problem about "mbstowcs" 
Author Message
 problem about "mbstowcs"

Quote:

>Hi,everyone:

>   I have a problem about using function  mbstowcs . This function's first
>parameter is a (wchar_t *) string. My question is how  I can know the result
>string's size and set the destination string buffer size properly. Must I
>set the buffer to
>maximum size?

Because it takes at least one byte of the multi byte string to produce each
wide character, the upper bound on the number of characters transferred is
the strlen() of the multibyte string. In the worst case, each multi byte
char maps to one wide char, so if you want to be sure that all of the
source bytes are copied, you need a buffer to hold that many wide
characters (plus the terminating null wide character).


Fri, 23 Aug 2002 03:00:00 GMT  
 problem about "mbstowcs"


Quote:
> Hi,everyone:

>    I have a problem about using function  mbstowcs . This function's first
> parameter is a (wchar_t *) string. My question is how  I can know the
result
> string's size and set the destination string buffer size properly. Must I
> set the buffer to
> maximum size?

No you do not need to do that. Instead do

wccount = wcstombs(NULL, mbstr, mbcount);

If wccount is not -1 then that is the number of wide characters you need to
size for.

Alternatively

size_t len = mblen(mbstr);

if len is not 0 nor (size_t)-1 then you need a wchat_t buffer that is at
least len + 1 characters.

Stephen Howe



Fri, 23 Aug 2002 03:00:00 GMT  
 problem about "mbstowcs"
Hi,everyone:

   I have a problem about using function  mbstowcs . This function's first
parameter is a (wchar_t *) string. My question is how  I can know the result
string's size and set the destination string buffer size properly. Must I
set the buffer to
maximum size?

    Many thanks.



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. remove() vrs fopen("""w")

2. Displaying binary data as ascii "1"'s and "0"'s

3. Looking for "Shroud"/"Obfus"

4. ""help with TSR""

5. Parse trees and "("")"

6. Error "free"-ing "malloc"-ed memory

7. Displaying binary data as ascii "1"'s and "0"'s

8. Attention "C"/"C++" gurus and "C" newbees

9. merits of "#define", "const", and "enum" ???

10. why not "cout", "<<" , and "endl"??

11. "#define" versus "con

12. '.', '::", "->"

 

 
Powered by phpBB® Forum Software