2017-02-09 31 views

回答

1

LC_CTYPE是一個環境變量。您可以使用任何訪問環境變量的常規方法,這些方法因平臺而異。例如,POSIX的第三envp參數main

int main(int argc, char **argv, char **envp); 

或標準C89 getenv()功能:

char *getenv(const char *name); 

例如:

#include <stdlib.h> 
char const *get_lc_ctype() 
{ 
    return getenv("LC_CTYPE"); 
} 

要小心,不要修改由getenv(3)返回的字符串,這是未定義的行爲。如果你想設置LC_CTYPE,你應該使用(POSIX標準化,但不是C-標準化)setenv(3)

int set_lc_ctype(char const *new) 
{ 
    return setenv("LC_CTYPE", new, 1); 
} 
0

一個通用的方法是使用 '的setlocale()'。 從手冊頁:

如果語言環境是一個空字符串「」,即應根據 環境變量設置進行修改語言環境的每個部分。

因此,您可以通過

#include <locale.h> 
// ... 
char* lc_type= setlocale(LC_CTYPE, ""); 
得到LC_TYPE
相關問題