The setlocale() function is the interface to the program’s locale. Any program that uses the invocation country’s conventions should place a call such as the following example early in the program’s execution path.
#include <locale.h> /*...*/ setlocale(LC_ALL, "");
This call causes the program’s current locale to change to the appropriate local version, because LC_ALL is the macro that specifies the entire locale instead of one category. The standard categories are:
Sorting information
Character classification information
Currency printing information
Numeric printing information
Date and time printing information
Any of these macros can be passed as the first argument to setlocale() to specify that category.
The setlocale() function returns the name of the current locale for a given category (or LC_ALL) and serves in an inquiry-only capacity when its second argument is a null pointer. Thus, code similar to the following example can be used to change the locale or a portion thereof for a limited duration:
#include <locale.h> /*...*/ char *oloc; /*...*/ oloc = setlocale(LC_category, NULL); if (setlocale(LC_category, "new") != 0) { /* use temporarily changed locale */ (void)setlocale(LC_category, oloc); }
Most programs do not need this capability.