1, locale.h1-1, Function introduction
char *setlocale (int category, const char *locale)//Set locale information
category is a constant that specifies the category of functions that are affected by the locale.
Lc_all includes all of the following options.
lc_collate string comparisons. Affects strcoll ().
lc_ctype character classification and conversion.
lc_monetary currency format.
lc_numeric the decimal separator character.
Lc_time The date and time format for strftime ().
lc_messages System response.
locale represents the country (language), if NULL or "" is set according to the environment variable.
struct Lconv *localeconv (void)//Read geo-Information
struct lconv{char *Decimal_point;//Decimal formChar *Thousands_sep;//thousand separatorsChar *Grouping;//show how to group numbers in an ArrayChar *Int_curr_symbol;//International currency symbolChar *Currency_symbol;//national currency symbol Char *Mon_decimal_point;//Currency decimal symbolChar *Mon_thousands_sep;//Currency thousand separatorChar *mon_grouping;//show how to group the Array of currency numbersChar *positive_sign;// plus signChar *negative_sign;//minus sign Charint_frac_digits;//International decimal numberCharfrac_digits;//local decimal number CharP_cs_precedes;//Currency symbol is true (1) before positive value, otherwise false (0)CharP_sep_by_space;//If there is space between the currency symbol and the positive value, it is (1), otherwise (0). CharN_cs_precedes;//Currency symbol is 1 before negative value, no 0CharN_sep_by_space;//If there is space between the currency symbol and the negative value, it is (1), otherwise (0). CharP_sign_posn;//formatting options: 0-The number and the currency symbol around the parentheses 1-the number and the currency symbol before the ' + ' number and the ' + ' sign after the ' + ' number 3-currency symbol before the ' + ' sign 4-the ' + ' sign after the currency symbol//2-CharN_sign_posn;//formatting options: 0-parentheses around number and currency symbol 1-number and currency symbol before-number//2-number and currency symbol after-number 3-Before currency symbol-Number 4-symbol after currency sign} ;
1-2. Sample Code
#include <stdio.h> #include <locale.h> #include <string.h>int main () { char *str1,*str2; int CMP; struct Lconv *lv; STR1 = "we"; str2 = "Wo good"; SetLocale (Lc_all, "中文版"); CMP = strcoll (STR1,STR2); printf ("%d\n", CMP);//-1 only suitable for comparison english 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 using Hanyu Pinyin to compare 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;}
2, stddef.h2-1, function introduction
Offsetof (type, member-designator)
The function generates an integer constant of type size_t , which is the byte offset of a struct member relative to the beginning of the structure.
The member is given by Member-designator , and the name of the struct is given in the type .
2-2. Sample Code
#include <stddef.h> #include <stdio.h>struct address{ char name[50]; Char street[50]; int phone;}; int main () { name offset in the address structure =%d bytes. \ n ",//0 offsetof (struct address, name)); printf (the street offset in the address structure =%d bytes. \ n ",//50 offsetof (struct address, street)); printf (the phone offset in the address structure =%d bytes. \ n ",//100 offsetof (struct address, phone)); return 0;}
Locale.h and Stddef.h