wctomb _wctomb_l
將寬字元轉換為對應的多位元組字元。 這些函式更安全版本都可使用; see wctomb_s _wctomb_s_l.
int wctomb(
char *mbchar,
wchar_t wchar
);
int _wctomb_l(
char *mbchar,
wchar_t wchar,
_locale_t locale
);
參數
mbchar
多位元組字元的位址。wchar
廣泛的字元。
傳回值
如果wctomb轉換寬字元為多位元組的字元,它會傳回的位元組數目 (也就是永遠不會大於MB_CUR_MAX) 中廣泛的字元。 如果wchar是寬字元的 null 字元 (L '\ 0'), wctomb ,則傳回 1。 如果目標指標mbchar為 NULL, wctomb會傳回 0。 如果該轉換是不可能在目前的地區設定中, wctomb會傳回 – 1 及errno設定為 [ EILSEQ。
備註
wctomb函式會將其wchar為對應的多位元組字元的引數,並儲存結果,在mbchar。 您可以從任何程式中的任何點,來呼叫函式。 wctomb使用目前的地區設定的任何地區設定相關的行為。 _wctomb_l是相同的wctomb不同之處在於它所使用的地區設定中傳遞。 如需詳細資訊,請參閱 地區設定。
wctomb驗證其參數。 如果mbchar是NULL,不正確的參數處理常式會叫用,如所述參數驗證。 如果要繼續,請允許執行errno設定為 [ EINVAL ,則函數會傳回-1。
需求
常式 |
所需的標頭 |
---|---|
wctomb |
<stdlib.h> |
其他的相容性資訊,請參閱相容性在簡介中。
範例
此程式會說明 wctomb 函式的行為。
// crt_wctomb.cpp
// compile with: /W3
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int i;
wchar_t wc = L'a';
char *pmb = (char *)malloc( MB_CUR_MAX );
printf( "Convert a wide character:\n" );
i = wctomb( pmb, wc ); // C4996
// Note: wctomb is deprecated; consider using wctomb_s
printf( " Characters converted: %u\n", i );
printf( " Multibyte character: %.1s\n\n", pmb );
}
.NET Framework 對等用法
不適用。 若要呼叫標準的 c 函式,使用PInvoke。 如需詳細資訊,請參閱平台叫用範例。