mbstowcs

Converts a sequence of multibyte characters into their corresponding wide-character codes and stores them in an array.

Library:LibC
Classification:ANSI
Service:General C Services

Syntax

  #include <stdlib.h> 
   
  size_t mbstowcs (
     wchar_t      *pwcs,   
     const char   *s,   
     size_t        n);
  

Parameters

pwcs

(OUT) Points to the array of wide-character codes.

s

(IN) Points to the array of multibyte characters to be converted.

n

(IN) Specifies the number of codes to be stored in the array pointed to by pwcs.

Return Values

Returns the actual number of bytes that have been copied from the array pointed to by s to the array pointed to by pwcs. If the return value is equal to n, the wide-character string is not null-terminated.

If pwcs is a NULL pointer, returns the length required to convert the entire array, but no values are stored.

If an invalid character is encountered, returns -1.

Remarks

The mbstowcs function converts a sequence of multibyte characters pointed to by s into their corresponding wide-character codes and stores not more than n codes into the array pointed to by pwcs.

The mbstowcs function does not convert any multibyte characters beyond the null-terminating character. At most, n elements of the array pointed to by pwcs are modified.

See Also