setlocale() – C函数

C库函数 char *setlocale(int category, const char *locale) 设置或读取位置相关的信息。

声明

以下是声明的setLocale() 函数。

char*setlocale(int category,constchar*locale)

参数

  • category -- 这是已命名的的常数,指定受区域设置的功能类别。

    • LC_ALL for all of the below.

    • LC_COLLATE for string comparison. see strcoll().

    • LC_CTYPE for character classification and conversion. For example strtoupper()

    • LC_MONETARY for monetary formatting for localeconv().

    • LC_NUMERIC for decimal separator for localeconv().

    • LC_TIME for date and time formatting with strftime().

    • LC_MESSAGES for system responses.

  • locale -- 如果locale是NULL或空字符串' ',语言环境的名称将被设置环境变量的值与上述类别相同的名称。

返回值

一个成功的调用setlocale()返回一个不透明的字符串所对应的语言环境集合。如果不能兑现的请求,返回值是NULL。

例子

下面的例子显示使用的setlocale()函数。

#include<locale.h>#include<stdio.h>#include<time.h>int main (){time_t currtime;struct tm *timer;char buffer[80];
time(&currtime );
timer = localtime(&currtime );
printf("Locale is: %s
", setlocale(LC_ALL,"en_GB"));
strftime(buffer,80,"%c", timer );
printf("Date is: %s
", buffer);
printf("Locale is: %s
", setlocale(LC_ALL,"de_DE"));
strftime(buffer,80,"%c", timer );
printf("Date is: %s
", buffer);return(0);}

让我们编译和运行上面的程序,这将产生以下结果:

Locale is: en_GB
Date is: Thu 23 Aug 2012 06:39:32 MST
Locale is: de_DE
Date is: Do 23 Aug 2012 06:39:32 MST

以上是setlocale() – C函数的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>