标签:
char *setlocale(int category, const char *locale)//设置地域化信息
category是一个常量,指定了受区域设置影响的函数类别。
LC_ALL 包括下面的所有选项。
LC_COLLATE 字符串比较。影响strcoll()。
LC_CTYPE 字符分类和转换。
LC_MONETARY 货币格式。
LC_NUMERIC 小数点分隔符。
LC_TIME 日期和时间格式,针对 strftime()。
LC_MESSAGES 系统响应。
locale表示国家(语言),如果为NULL或“”则根据环境变量设置。
struct lconv *localeconv(void)//读取地域化信息
struct lconv { char *decimal_point;//小数点形式 char *thousands_sep;//千位分隔符 char *grouping;//显示如何分组数字的 Array char *int_curr_symbol;//国际货币符号 char *currency_symbol;//本国货币符号 char *mon_decimal_point;//货币小数点符号 char *mon_thousands_sep;//货币千位分隔符 char *mon_grouping;//显示如何分组货币数字的 Array char *positive_sign;//正号 char *negative_sign;//负号 char int_frac_digits;//国际小数数字 char frac_digits;//本地小数数字 char p_cs_precedes;//货币符号在正值前为true(1),否则false(0) char p_sep_by_space;//如果货币符号与正值之间有空间,则是(1),否则是(0)。 char n_cs_precedes;//货币符号在负值前为1,否为0 char n_sep_by_space;//如果货币符号与负值之间有空间,则是(1),否则是(0)。 char p_sign_posn;//格式化选项:0-在数量和货币符号周围的圆括号 1-数量和货币符号之前的‘+‘号 //2-数量和货币符号之后的‘+’号 3-货币符号之前的‘+’号 4-货币符号之后的‘+’号 char n_sign_posn;//格式化选项:0 - 在数量和货币符号周围的圆括号 1 - 数量和货币符号之前的 - 号 //2 - 数量和货币符号之后的 - 号 3 - 货币符号之前的 - 号 4 - 货币符号之后的 - 号 };
#include <stdio.h> #include <locale.h> #include <string.h> int main() { char *str1,*str2; int cmp; struct lconv *lv; str1 = "我们"; str2 = "wo好"; setlocale(LC_ALL,"English"); cmp = strcoll(str1,str2); printf("%d\n",cmp);//-1仅适合比较英文 lv = localeconv(); printf("Local Currency Symbol: %s\n",lv->currency_symbol); printf("International Currency Symbol: %s\n",lv->int_curr_symbol); printf("Decimal Point = %s\n", lv->decimal_point); setlocale(LC_ALL,"Chinese"); cmp = strcoll(str1,str2); printf("%d\n",cmp);//1使用汉语拼音进行比较 lv = localeconv(); printf("Local Currency Symbol: %s\n",lv->currency_symbol); printf("International Currency Symbol: %s\n",lv->int_curr_symbol); printf("Decimal Point = %s\n", lv->decimal_point); return 0; }
offsetof(type, member-designator)
该函数会生成一个类型为 size_t 的整型常量,它是一个结构成员相对于结构开头的字节偏移量。
成员是由 member-designator 给定的,结构的名称是在 type 中给定的。
#include <stddef.h> #include <stdio.h> struct address { char name[50]; char street[50]; int phone; }; int main() { printf("address 结构中的 name 偏移 = %d 字节。\n",//0 offsetof(struct address, name)); printf("address 结构中的 street 偏移 = %d 字节。\n",//50 offsetof(struct address, street)); printf("address 结构中的 phone 偏移 = %d 字节。\n",//100 offsetof(struct address, phone)); return 0; }
标签:
原文地址:http://blog.csdn.net/sddxqlrjxr/article/details/51364970