C programming stdlib.h function - size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)

The wcstombs() function in the C standard library, defined in the stdlib.h header file, is used to convert a wide character string to a multibyte character string.

The function has the following signature:

size_t wcstombs(char *str, const wchar_t *pwcs, size_t n);
Source:‮i.www‬giftidea.com

where:

  • str: Pointer to the buffer where the resulting multibyte string is stored.
  • pwcs: Pointer to the wide character string to be converted.
  • n: The maximum number of bytes to be stored in the buffer pointed to by str.

The function returns the number of bytes written to the buffer pointed to by str, excluding the terminating null character.

If str is a null pointer, wcstombs() doesn't write anything to the buffer and returns the number of bytes required to hold the converted string. If the pwcs string is a null pointer, wcstombs() returns 0.