Home

setlocale

Setlocale is a function in the C standard library that sets or queries the program’s current locale for one or more categories. It is declared in locale.h and has the prototype char *setlocale(int category, const char *locale). The category selects which aspect of localization to affect, such as LC_ALL, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, and LC_MESSAGES; some platforms may expose additional categories and some categories may not be fully controllable at runtime.

The locale parameter specifies the locale to use. If locale is non-null, setlocale attempts to switch the

Categories control different aspects of localization. LC_ALL applies changes to all categories at once; other categories

In practice, setlocale affects locale-dependent functions and behavior, including string collation, numeric formatting, monetary formatting, and

named
category
(or
categories)
to
that
locale
and
returns
a
string
containing
the
actual
locale
name
in
effect.
If
locale
is
NULL,
setlocale
returns
the
current
locale
name
for
the
specified
category
without
changing
it.
If
locale
is
the
empty
string
"",
the
environment
variables
(for
example
LC_ALL,
LC_CTYPE,
LANG)
are
consulted
to
determine
the
locale.
If
the
specified
locale
name
is
invalid
or
unsupported,
setlocale
returns
NULL
and
the
processor’s
locale
for
that
category
is
not
changed.
control
specific
areas
such
as
character
encoding
and
classification
(LC_CTYPE),
number
formatting
(LC_NUMERIC),
date
and
time
formatting
(LC_TIME),
string
collation
order
(LC_COLLATE),
monetary
formatting
(LC_MONETARY),
and
message
translations
(LC_MESSAGES).
The
exact
behavior
can
vary
by
implementation.
character
classification,
by
selecting
the
appropriate
locale
for
the
targeted
category.