C locale.h Functions

Definition
Definition and Usage
<locale.h> is the C header for simple localization. Its two functions are setlocale(), which changes or queries cultural rules, and localeconv(), which reads numeric and monetary formatting fields for the active locale.
This page is the catalog for both tutorials. Start from the beginner overview if categories and the C locale are new, then open each function guide for syntax, return values, and three examples.
Need the model first?
Read C Locales for LC_ALL, the C locale, environment locales, and struct lconv.
Quick choice
Choose a Function by Job
| I want to... | Start with |
|---|---|
| Change or query the locale | setlocale() |
| Use the portable C locale | setlocale(LC_ALL, "C") |
| Use the environment locale | setlocale(LC_ALL, "") |
| Read decimal_point or currency fields | localeconv() |
Index
C locale.h Functions Index
| Function | Description | Tutorial |
|---|---|---|
localeconv() | Read numeric and monetary formatting fields. | Open |
setlocale() | Change or query the program locale. | Open |
Remember
Key Takeaways
- Programs start in C. Use
setlocale(LC_ALL, "C")to stay portable, or""for the environment. - Check for NULL. A failed
setlocale()leaves the previous locale unchanged. - localeconv is a snapshot. Copy strings you need if you change the locale again later.
Frequently Asked Questions
It declares setlocale() and localeconv(), plus category macros such as LC_ALL and LC_NUMERIC.
Start with setlocale() to change or query the locale, then localeconv() to read decimal_point and related fields.
The portable default. Select it with setlocale(LC_ALL, "C"). Programs start there unless you change it.
It sets all categories from the environment. On success it returns a locale name; on failure it returns NULL.
setlocale() changes or queries the locale. localeconv() reads formatting details for the locale that is already active.
Start with setlocale()
Learn how to change or query the program locale first.
8 people found this page helpful
