In the multi-byte character-wide conversion function provided by the C Runtime Library: mbstowcs ()/wcstombs (), the global variable locale (locale encoding) must be used ), to specify the encoding type of multi-byte characters
1. functions:
Used to define global variables: locale (locale encoding)
Header file:
Setlocale |
<Locale. h> |
ANSI, Win 95, Win NT |
_ Wsetlocale |
<Locale. h> or <wchar. h> |
2. prototype:
Char * setlocale (int Category, Const char *Locale );
Wchar_t * _ wsetlocale (int Category, Const wchar_t *Locale );
3. parameters:
1> category
Specify the range to be affected by the global variable locale. Macro and the corresponding impact scope are as follows:
Lc_all
All categories, as listed below
Lc_collate
TheStrcoll, _ stricoll, wcscoll, _ wcsicoll,AndStrxfrmFunctions
Lc_ctype
The character-handling functions (character tIsdigit,Isxdigit,Mbstowcs, AndMbtowc, Which are unaffected)
Lc_monetary
Monetary-formatting information returned byLocaleconvFunction
Lc_numeric
Decimal-point character for the formatted Output Routines (suchPrintf), For the data-conversion routines, and for the nonmonetary-formatting information returnedLocaleconv
Lc_time
TheStrftimeAndWcsftimeFunctions
2>Locale
Name of locale
If the value is a Null String "" (Note: It is not null), locale uses the same encoding method as the local environment (it should be useful in localization );
If the value is "C", it indicates that all character types are expressed in one byte (the value is less than 256)
Locale in simplified Chinese is named "CHS"
4. Return Value:
If both locale and category are correct, strings related to the specified locale and category are returned;
If locale or category is incorrect, a null pointer is returned. The current locale global variable will not change.
Sample Code:
Obtain the local language:
Void main () {char * locallanguage = setlocale (lc_all, ""); If (locallanguage = NULL) {printf ("failed to get the local language type \ n "); return;} printf ("locale language is % s \ n", locallanguage );}
The output is as follows:
Locale language is chinese_people 'S republic of china.936