Header File
stdlib.h
Category
Conversion Routines, Memory and String Manipulation Routines
Prototype
size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
Description
Converts a multibyte string to a wchar_t array.
The function converts the multibyte string s into the array pointed to by pwcs. No more than n values are stored in the array. If an invalid multibyte sequence is encountered, mbstowcs returns (size_t) -1.
The pwcs array will not be terminated with a zero value if mbstowcs returns n.
Return Value
If an invalid multibyte sequence is encountered, mbstowcs returns (size_t) -1. Otherwise, the function returns the number of array elements modified, not including the terminating code, if any.
Example
#include <stdio.h> #include <stdlib.h> void main(void) { int x; char *mbst = (char *)malloc(MB_CUR_MAX); wchar_t *pwst = L"Hi"; wchar_t *pwc = (wchar_t *)malloc(sizeof( wchar_t)); printf ("Convert to multibyte string:\n"); x = wcstombs (mbst, pwst, MB_CUR_MAX); printf ("\tCharacters converted %u\n",x); printf ("\tHEx value of first"); printf (" multibyte character: %#.4x\n\n", mbst); printf ("Convert back to wide character string:\n"); x = mbstowcs(pwc, mbst, MB_CUR_MAX); printf( "\tCharacters converted: %u\n",x); printf( "\tHex value of first"); printf( "wide character: %#.4x\n\n", pwc); }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
+ |
+ |
+ |
+ |
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|