#include <stdlib.h>
#include <locale.h>

/*
 * The following example uses the wcstombs and wcslen subroutines
 * to convert a wide character string to multibyte form.
 */
int main(int argc, char **argv) {
    wchar_t *pwcs; /* Source wide character string */
    char    *s;    /* Destination multibyte character string */
    size_t   n;
    size_t   retval;
 
    setlocale(LC_ALL, "");
    
    /*
     * Calculate the maximum number of bytes needed to
     * store the wide character buffer in multibyte form in the 
     * current code page and malloc() the appropriate storage,
     * including the terminating null.
     */
    s = (char *)malloc(wcslen(pwcs) * MB_CUR_MAX + 1); 
    retval = wcstombs(s, pwcs, n); 
    
    if (retval == -1) {
        /* Error handling */
        /* now, s points to the multibyte character string. */
    }
}