# C 標準庫 - <locale.h>
## 簡介
**locale.h** 頭文件定義了特定地域的設置,比如日期格式和貨幣符號。接下來我們將介紹一些宏,以及一個重要的結構 **struct lconv** 和兩個重要的函數。
## 庫宏
下面列出了頭文件 locale.h 中定義的宏,這些宏將在下列的兩個函數中使用:
| 宏 | 描述 |
| --- | --- |
| **LC_ALL** | 設置下面的所有選項。 |
| **LC_COLLATE** | 影響 strcoll 和 strxfrm 函數。 |
| **LC_CTYPE** | 影響所有字符函數。 |
| **LC_MONETARY** | 影響 localeconv 函數提供的貨幣信息。 |
| **LC_NUMERIC** | 影響 localeconv 函數提供的小數點格式化和信息。 |
| **LC_TIME** | 影響 strftime 函數。 |
## 庫函數
下面列出了頭文件 locale.h 中定義的函數:
| 函數 | 描述 |
| --- | --- |
| [char \*setlocale(int category, const char \*locale)](c-function-setlocale.html) | 設置或讀取地域化信息。 |
| [struct lconv *localeconv(void)](c-function-localeconv.html) | 設置或讀取地域化信息。 |
## 庫結構
```
typedef struct {
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
} lconv
```
以下是各字段的描述:
| 字段 | 描述 |
| --- | --- |
| **decimal_point** | 用于非貨幣值的小數點字符。 |
| **thousands_sep** | 用于非貨幣值的千位分隔符。 |
| **grouping** | 一個表示非貨幣量中每組數字大小的字符串。每個字符代表一個整數值,每個整數指定當前組的位數。值為 0 意味著前一個值將應用于剩余的分組。 |
| **int_curr_symbol** | 國際貨幣符號使用的字符串。前三個字符是由 ISO 4217:1987 指定的,第四個字符用于分隔貨幣符號和貨幣量。 |
| **currency_symbol** | 用于貨幣的本地符號。 |
| **mon_decimal_point** | 用于貨幣值的小數點字符。 |
| **mon_thousands_sep** | 用于貨幣值的千位分隔符。 |
| **mon_grouping** | 一個表示貨幣值中每組數字大小的字符串。每個字符代表一個整數值,每個整數指定當前組的位數。值為 0 意味著前一個值將應用于剩余的分組。 |
| **positive_sign** | 用于正貨幣值的字符。 |
| **negative_sign** | 用于負貨幣值的字符。 |
| **int_frac_digits** | 國際貨幣值中小數點后要顯示的位數。 |
| **frac_digits** | 貨幣值中小數點后要顯示的位數。 |
| **p_cs_precedes** | 如果等于 1,則 currency_symbol 出現在正貨幣值之前。如果等于 0,則 currency_symbol 出現在正貨幣值之后。 |
| **p_sep_by_space** | 如果等于 1,則 currency_symbol 和正貨幣值之間使用空格分隔。如果等于 0,則 currency_symbol 和正貨幣值之間不使用空格分隔。 |
| **n_cs_precedes** | 如果等于 1,則 currency_symbol 出現在負貨幣值之前。如果等于 0,則 currency_symbol 出現在負貨幣值之后。 |
| **n_sep_by_space** | 如果等于 1,則 currency_symbol 和負貨幣值之間使用空格分隔。如果等于 0,則 currency_symbol 和負貨幣值之間不使用空格分隔。 |
| **p_sign_posn** | 表示正貨幣值中正號的位置。 |
| **n_sign_posn** | 表示負貨幣值中負號的位置。 |
下面的值用于 **p_sign_posn** 和 **n_sign_posn**:
| 值 | 描述 |
| --- | --- |
| 0 | 封裝值和 currency_symbol 的括號。 |
| 1 | 放置在值和 currency_symbol 之前的符號。 |
| 2 | 放置在值和 currency_symbol 之后的符號。 |
| 3 | 緊挨著放置在值和 currency_symbol 之前的符號。 |
| 4 | 緊挨著放置在值和 currency_symbol 之后的符號。 |
- C語言教程
- C 簡介
- C 環境設置
- C 程序結構
- C 基本語法
- C 數據類型
- C 變量
- C 常量
- C 存儲類
- C 運算符
- C 判斷
- C 循環
- C 函數
- C 作用域規則
- C 數組
- C 指針
- C 字符串
- C 結構體
- C 共用體
- C 位域
- C typedef
- C 輸入 & 輸出
- C 文件讀寫
- C 預處理器
- C 頭文件
- C 強制類型轉換
- C 錯誤處理
- C 遞歸
- C 可變參數
- C 內存管理
- C 命令行參數
- C語言參考
- C 標準庫 - <assert.h>
- C 庫宏 - assert()
- C 標準庫 - <ctype.h>
- C 庫函數 - isalnum()
- C 庫函數 - isalpha()
- C 庫函數 - iscntrl()
- C 庫函數 - isdigit()
- C 庫函數 - isgraph()
- C 庫函數 - islower()
- C 庫函數 - isprint()
- C 庫函數 - ispunct()
- C 庫函數 - isspace()
- C 庫函數 - isupper()
- C 庫函數 - isxdigit()
- C 標準庫 - <errno.h>
- C 庫宏 - errno
- C 庫宏 - EDOM
- C 庫宏 - ERANGE
- C 標準庫 - <float.h>
- C 標準庫 - <limits.h>
- C 標準庫 - <locale.h>
- C 庫函數 - setlocale()
- C 庫函數 - localeconv()
- C 標準庫 - <math.h>
- C 庫函數 - acos()
- C 庫函數 - asin()
- C 庫函數 - atan()
- C 庫函數 - atan2()
- C 庫函數 - cos()
- C 庫函數 - cosh()
- C 庫函數 - sin()
- C 庫函數 - sinh()
- C 庫函數 - tanh()
- C 庫函數 - exp()
- C 庫函數 - frexp()
- C 庫函數 - ldexp()
- C 庫函數 - log()
- C 庫函數 - log10()
- C 庫函數 - modf()
- C 庫函數 - pow()
- C 庫函數 - sqrt()
- C 庫函數 - ceil()
- C 庫函數 - fabs()
- C 庫函數 - floor()
- C 庫函數 - fmod()
- C 標準庫 - <setjmp.h>
- C 庫宏 - setjmp()
- C 庫函數 - longjmp()
- C 標準庫 - <signal.h>
- C 庫函數 - signal()
- C 庫函數 - raise()
- C 標準庫 - <stdarg.h>
- C 庫宏 - va_start()
- C 庫宏 - va_arg()
- C 庫宏 - va_end()
- C 標準庫 - <stddef.h>
- C 庫宏 - NULL
- C 庫宏 - offsetof()
- C 標準庫 - <stdio.h>
- C 庫函數 - fclose()
- C 庫函數 - clearerr()
- C 庫函數 - feof()
- C 庫函數 - ferror()
- C 庫函數 - fflush()
- C 庫函數 - fgetpos()
- C 庫函數 - fopen()
- C 庫函數 - fread()
- C 庫函數 - freopen()
- C 庫函數 - fseek()
- C 庫函數 - fsetpos()
- C 庫函數 - ftell()
- C 庫函數 - fwrite()
- C 庫函數 - remove()
- C 庫函數 - rename()
- C 庫函數 - rewind()
- C 庫函數 - setbuf()
- C 庫函數 - tmpfile()
- C 庫函數 - tmpnam()
- C 庫函數 - fprintf()
- C 庫函數 - printf()
- C 庫函數 - sprintf()
- C 庫函數 - vfprintf()
- C 庫函數 - vprintf()
- C 庫函數 - vsprintf()
- C 庫函數 - fscanf()
- C 庫函數 - scanf()
- C 庫函數 - sscanf()
- C 庫函數 - fgetc()
- C 庫函數 - fgets()
- C 庫函數 - fputc()
- C 庫函數 - fputs()
- C 庫函數 - getc()
- C 庫函數 - getchar()
- C 庫函數 - gets()
- C 庫函數 - putc()
- C 庫函數 - putchar()
- C 庫函數 - puts()
- C 庫函數 - ungetc()
- C 庫函數 - perror()
- C 標準庫 - <stdlib.h>
- C 庫函數 - atof()
- C 庫函數 - atoi()
- C 庫函數 - atol()
- C 庫函數 - strtod()
- C 庫函數 - strtol()
- C 庫函數 - strtoul()
- C 庫函數 - calloc()
- C 庫函數 - free()
- C 庫函數 - malloc()
- C 庫函數 - realloc()
- C 庫函數 - abort()
- C 庫函數 - atexit()
- C 庫函數 - exit()
- C 庫函數 - getenv()
- C 庫函數 - system()
- C 庫函數 - bsearch()
- C 庫函數 - qsort()
- C 庫函數 - abs()
- C 庫函數 - div()
- C 庫函數 - labs()
- C 庫函數 - ldiv()
- C 庫函數 - rand()
- C 庫函數 - srand()
- C 庫函數 - mblen()
- C 庫函數 - mbstowcs()
- C 庫函數 - mbtowc()
- C 庫函數 - wcstombs()
- C 庫函數 - wctomb()
- C 標準庫 - <string.h>
- C 庫函數 - memchr()
- C 庫函數 - memcmp()
- C 庫函數 - memcpy()
- C 庫函數 - memmove()
- C 庫函數 - memset()
- C 庫函數 - strcat()
- C 庫函數 - strncat()
- C 庫函數 - strchr()
- C 庫函數 - strcmp()
- C 庫函數 - strncmp()
- C 庫函數 - strcoll()
- C 庫函數 - strcpy()
- C 庫函數 - strncpy()
- C 庫函數 - strcspn()
- C 庫函數 - strerror()
- C 庫函數 - strlen()
- C 庫函數 - strpbrk()
- C 庫函數 - strrchr()
- C 庫函數 - strspn()
- C 庫函數 - strstr()
- C 庫函數 - strtok()
- C 庫函數 - strxfrm()
- C 標準庫 - <time.h>
- C 庫函數 - asctime()
- C 庫函數 - clock()
- C 庫函數 - ctime()
- C 庫函數 - difftime()
- C 庫函數 - gmtime()
- C 庫函數 - localtime()
- C 庫函數 - mktime()
- C 庫函數 - strftime()
- C 庫函數 - time()
- 免責聲明