10.8. Multi-byte String Functions

10.8.1. The mbstowcs function

Synopsis
#include <stdlib.h>

size_t mbstowcs (wchar_t * pwcs , const char * s , size_t n );

Description

The mbstowcs function converts a sequence of multi-byte characters that begin the initial shift state from the array pointed to by s into a sequence of corresponding codes and stores not more than n codes into the array pointed to by pwcs. No multi-byte characters that follow a null character (which is converted into a code with value zero) will be examined or converted. Each multi-byte character is converted as if by a call to the mbtowc function, except the shift state of the mbtowc function is not affected.

No more n elements will be modified in the array pointed to by pwcs. If copying takes place between objects that overlap, the behavior is undefined.

Returns

If an invalid multi-byte character is encountered, the mbstowcs function returns (size_t) -1. Otherwise the mbstowcs function returns the number of array elements modified, not including a terminating zero code, if any.

See Also

Section 10.7.2.

Implementation Notes

10.8.2. The wcstombs function

Synopsis
#include <stdlib.h>

size_t wcstombs (char * s , const wchar_t * pwcs , size_t n );

Description

The wcstombs function converts a sequence of codes that correspond to multi-byte characters from the array pointed to by pwcs into a sequence of multi-byte characters that begins in the initial shift state and stores these multi-byte characters into the array pointed to by s, stopping if a multi-byte character would exceed the limit of n total bytes or if a null character is stored. Each code is converted as if by a call to the wctomb function, except the shift state of the wctomb function is not affected.

No more n bytes will be modified in the array pointed to by s. If copying takes place between objects that overlap, the behavior is undefined.

Returns

If a code is encountered that does not correspond to a valid multi-byte character, the wcstombs function returns (size_t) -1. Otherwise the wcstombs function returns the number of bytes modified, not including a terminating null character, if any.

See Also

Section 10.8.1

Implementation Notes