// crt_wcstombs_s.c
// This example converts a wide character
// string to a multibyte character string.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define BUFFER_SIZE 100
int main( void )
{
size_t i;
char *pMBBuffer = (char *)malloc( BUFFER_SIZE );
wchar_t*pWCBuffer = L"Hello, world.";
printf( "Convert wide-character string:\n" );
// Conversion
wcstombs_s(&i, pMBBuffer, (size_t)BUFFER_SIZE,
pWCBuffer, (size_t)BUFFER_SIZE );
// Output
printf(" Characters converted: %u\n", i);
printf(" Multibyte character: %s\n\n",
pMBBuffer );
// Free multibyte character buffer
if (pMBBuffer)
{
free(pMBBuffer);
}
}
// This example converts a wide character
// string to a multibyte character string.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define BUFFER_SIZE 100
int main( void )
{
size_t i;
char *pMBBuffer = (char *)malloc( BUFFER_SIZE );
wchar_t*pWCBuffer = L"Hello, world.";
printf( "Convert wide-character string:\n" );
// Conversion
wcstombs_s(&i, pMBBuffer, (size_t)BUFFER_SIZE,
pWCBuffer, (size_t)BUFFER_SIZE );
// Output
printf(" Characters converted: %u\n", i);
printf(" Multibyte character: %s\n\n",
pMBBuffer );
// Free multibyte character buffer
if (pMBBuffer)
{
free(pMBBuffer);
}
}