TCHAR 转 char
// 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);
}
}
基本语法:
errno_t wcstombs_s(
size_t *pConvertedChars,
char *mbstr,
size_t sizeInBytes,
const wchar_t *wcstr,
size_t count
);
参数说明:
- [out] pConvertedChars
-
Filled with the number of characters converted.
- [out] mbstr
-
The address of a sequence of multibyte characters.
- [in] sizeInBytes
-
Buffer size for mbstr.
- [in] wcstr
-
The address of a sequence of wide characters.
- [in] count
-
The maximum number of bytes that can be stored in the multibyte output string, or _TRUNCATE.
- [in] locale
-
The locale to use.
返回值:
Zero if successful, otherwise an error code.
浙公网安备 33010602011771号