setlocale

Description

Defines the locale.

#include <locale.h>

char *setlocale( int category, const char *locale );

category Category affected by locale  
locale Name of the locale that will control the specified category  

Remarks

The setlocale function sets the categories specified by category to the locale specified by locale. The “locale” refers to the locality (country and language) for which certain aspects of your program can be customized. Some locale-dependent aspects include the formatting of dates and the display format for monetary values.

The setlocale function is used to set or get the program's current entire locale or simply portions of the locale information. The category argument specifies which portion of a program's locale information will be affected. The macros used for the category argument are listed below:

Category Parts of Program Affected

LC_ALL All categories listed below.
LC_COLLATE The strcoll and strxfrm functions.
LC_CTYPE The character-handling functions (except for isdigit, isxdigit, mbstowcs, and mbtowc, which are unaffected).
LC_MONETARY Monetary formatting information returned by the localeconv function.
LC_NUMERIC Decimal point character for the formatted output routines (such as printf), for the data conversion routines, and for the nonmonetary formatting information returned by the localeconv function.
LC_TIME The strftime function.

The locale argument is a pointer to a string that specifies the name of the locale. If locale points to an empty string, the locale is the implementation-defined native environment. A value of "C" specifies the minimal ANSI conforming environment for C translation. This is the only locale supported in Microsoft C version 6.0 and Microsoft C/C++ version 7.0.

If the locale argument is a null pointer, setlocale returns a pointer to the string associated with the category of the program's locale. The program's current locale setting is not changed.

Return Value

If a valid locale and category are given, setlocale returns a pointer to the string associated with the specified category for the previous locale. If the locale or category is invalid, the setlocale function returns a null pointer and the program's current locale settings are not changed.

The pointer to a string returned by setlocale can be used in subsequent calls to restore that part of the program's locale information, assuming that your program does not alter the pointer or the string. Later calls to setlocale will overwrite the string; you can use the _strdup function to save a specific locale string.

Compatibility

Standards:ANSI

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

localeconv, mblen, mbstowcs, mbtowc, strcoll, strftime, strxfrm, wcstombs, wctomb