Monday, 19 May 2014

C Library -

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

C Library - <locale.h>

Introduction

The locale.h header defines location specific settings, such as date formats and currency symbols. You will find several macros defined along with an important structure struct lconv and two important functions listed below.

Library Macros

Following are the macros defined in the header and these macros will be used in two functions listed below:
S.N.Macro & Description
1LC_ALL
Set everything.
2LC_COLLATE
Affects strcoll and strxfrm functions.
3LC_CTYPE
Affects all character functions.
4LC_MONETARY
Affects the monetary information provided by localeconv function.
5LC_NUMERIC
Affects decimal-point formatting and the information provided by localeconv function.
6LC_TIME
Affects the strftime function.

Library Functions

Following are the functions defined in the header locale.h:
S.N.Function & Description
1char *setlocale(int category, const char *locale)
Sets or reads location dependent information.
2struct lconv *localeconv(void)
Sets or reads location dependent information.

Library Structure

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
Following is the description of each of the fields:
S.N.Field & Description
1decimal_point
Decimal point character used for non-monetary values.
2thousands_sep
Thousands place separator character used for non-monetary values..
3grouping
A string that indicates the size of each group of digits in non-monetary quantities. Each character represents an integer value which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.
4int_curr_symbol
A string of the international currency symbols used. The first three characters are those specified by ISO 4217:1987 and the fourth is the character which separates the currency symbol from the monetary quantity.
5currency_symbol
The local symbol used for currency.
6mon_decimal_point
The decimal point character used for monetary values.
7mon_thousands_sep
The thousands place grouping character used for monetary values.
8mon_grouping
A string whose elements define the size of the grouping of digits in monetary values. Each character represents an integer value which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.
9positive_sign
The character used for positive monetary values.
10negative_sign
The character used for negative monetary values.
11int_frac_digits
Number of digits to show after the decimal point in international monetary values.
12frac_digits
Number of digits to show after the decimal point in monetary values.
13p_cs_precedes
If equal to 1, then the currency_symbol appears before a positive monetary value. If equal to 0, then the currency_symbol appears after a positive monetary value.
14p_sep_by_space
If equal to 1, then the currency_symbol is separated by a space from a positive monetary value. If equal to 0, then there is no space between the currency_symbol and a positive monetary value.
15n_cs_precedes
If equal to 1, then the currency_symbol precedes a negative monetary value. If equal to 0, then the currency_symbol succeeds a negative monetary value.
16n_sep_by_space
If equal to 1, then the currency_symbol is separated by a space from a negative monetary value. If equal to 0, then there is no space between the currency_symbol and a negative monetary value.
17p_sign_posn
Represents the position of the positive_sign in a positive monetary value.
18n_sign_posn
Represents the position of the negative_sign in a negative monetary value.
The following values are used for p_sign_posn and n_sign_posn:
ValueDescription
0Parentheses encapsulate the value and the currency_symbol.
1The sign precedes the value and currency_symbol.
2The sign succeeds the value and currency_symbol.
3The sign immediately precedes the value and currency_symbol.
4The sign immediately succeeds the value and currency_symbol.

0 comments: