286 lines
11 KiB
HTML
286 lines
11 KiB
HTML
<html>
|
|
<head>
|
|
<title>
|
|
C Guide--2.6 locale.h
|
|
</title>
|
|
<!-- Changed by: eric huss, 12-Mar-1997 -->
|
|
</head>
|
|
<body text="#000000" bgcolor="#FFFFFF">
|
|
|
|
<center>
|
|
<table border=0 width=100%>
|
|
<tr>
|
|
<td align=left width=20% valign=top>
|
|
<a href="2.5.html">
|
|
<img src="left.gif" border=0>
|
|
Previous Section<br>
|
|
2.5 limits.h</a></td>
|
|
<td align=center width=60% valign=top>
|
|
| <a href="index.html">Table of Contents</a> |
|
|
<a href="index2.html">Index</a> |</td>
|
|
<td align=right width=20% valign=top>
|
|
<a href="2.7.html">
|
|
Next Section
|
|
<img src="right.gif" border=0><br>
|
|
2.7 math.h</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<hr>
|
|
|
|
|
|
<h1>2.6 locale.h</h1>
|
|
<p>
|
|
The locale header is useful for setting location specific information.
|
|
<p>
|
|
Variables:
|
|
<blockquote><code><b>
|
|
struct lconv
|
|
</b></code></blockquote>
|
|
Macros:
|
|
<blockquote><code><b>
|
|
NULL<br>
|
|
LC_ALL<br>
|
|
LC_COLLATE<br>
|
|
LC_CTYPE<br>
|
|
LC_MONETARY<br>
|
|
LC_NUMERIC<br>
|
|
LC_TIME<br>
|
|
</b></code></blockquote>
|
|
Functions:
|
|
<blockquote><code><b>
|
|
localeconv();<br>
|
|
setlocale();<br>
|
|
</b></code></blockquote>
|
|
<p>
|
|
<a name="variables"></a>
|
|
<h2>2.6.1 Variables and Definitions</h2>
|
|
<p>
|
|
The <code><b>lconv</b></code> structure contains the following variables in any order. The use of this
|
|
structure is described in <b>2.6.3 localeconv</b>.
|
|
<blockquote><code><b>
|
|
char *decimal_point;<br>
|
|
char *thousands_sep;<br>
|
|
char *grouping;<br>
|
|
char *int_curr_symbol;<br>
|
|
char *currency_symbol;<br>
|
|
char *mon_decimal_point;<br>
|
|
char *mon_thousands_sep;<br>
|
|
char *mon_grouping;<br>
|
|
char *positive_sign;<br>
|
|
char *negative_sign;<br>
|
|
char int_frac_digits;<br>
|
|
char frac_digits;<br>
|
|
char p_cs_precedes;<br>
|
|
char p_sep_by_space;<br>
|
|
char n_cs_precedes;<br>
|
|
char n_sep_by_space;<br>
|
|
char p_sign_posn;<br>
|
|
char n_sign_posn;<br>
|
|
</b></code></blockquote>
|
|
The <b><code>LC_</code></b> macros are described in <b>2.6.2 setlocale</b>.
|
|
<b><code>NULL</code></b> is the value of a null pointer constant.
|
|
<p>
|
|
<a name="setlocale"></a>
|
|
<h2>2.6.2 setlocale</h2>
|
|
<p>
|
|
Declaration:
|
|
<blockquote><code><b>
|
|
char *setlocale(int</b></code> <i>category</i><code><b>, const char *</b></code><i>locale</i><code><b>);
|
|
</b></code></blockquote>
|
|
Sets or reads location dependent information.
|
|
<p>
|
|
<i>category</i> can be one of the following:
|
|
<table border=0>
|
|
<tr>
|
|
<td><code><b>LC_ALL</b></code></td><td> Set everything.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code><b>LC_COLLATE</b></code></td><td> Affects strcoll and strxfrm functions.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code><b>LC_CTYPE</b></code></td><td> Affects all character functions.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code><b>LC_MONETARY</b></code></td><td> Affects the monetary information provided by localeconv function.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code><b>LC_NUMERIC</b></code></td><td> Affects decimal-point formatting and the information provided by
|
|
<code><b>localeconv</b></code> function.</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code><b>LC_TIME</b></code></td><td> Affects the strftime function.</td>
|
|
</tr>
|
|
</table>
|
|
<p>
|
|
A value of "C" for locale sets the locale to the normal C translation environment settings
|
|
(default). A null value ("") sets the native environment settings. A null pointer (NULL) causes
|
|
setlocale to return a pointer to the string associated with this category for the current settings (no
|
|
changes occur). All other values are implementation-specific.
|
|
<p>
|
|
After a successful set, <code><b>setlocale</b></code> returns a pointer to a string which represents the previous
|
|
location setting. On failure it returns NULL.
|
|
<p>
|
|
Example:
|
|
<blockquote><code><b><pre>
|
|
#include<locale.h>
|
|
#include<stdio.h>
|
|
|
|
int main(void)
|
|
{
|
|
char *old_locale;
|
|
|
|
old_locale=setlocale(LC_ALL,"C");
|
|
printf("The preivous setting was %s.\n",old_locale);
|
|
return 0;
|
|
}
|
|
</pre></b></code></blockquote>
|
|
<a name="localeconv"></a>
|
|
<h2>2.6.3 localeconv</h2>
|
|
<p>
|
|
Declaration:
|
|
<blockquote><code><b>
|
|
struct lconv *localeconv(void);
|
|
</b></code></blockquote>
|
|
Sets the structure <code><b>lconv</b></code> to represent the current location settings.
|
|
<p>
|
|
The string pointers in the structure may point to a null string ("") which indicates that the
|
|
value is not available. The char types are nonnegative numbers. If the value is <code><b>CHAR_MAX</b></code>,
|
|
then the value is not available.
|
|
<p>
|
|
<code><b>lconv</b></code> variables:
|
|
<table border=0>
|
|
<tr>
|
|
<td><code><b>char *decimal_point</b></code></td>
|
|
<td> Decimal point character used for non-monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char *thousands_sep</b></code></td>
|
|
<td> Thousands place separator character used for non-monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char *grouping</b></code></td>
|
|
<td> 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.
|
|
</td></tr><tr>
|
|
<td><code><b>char *int_curr_symbol</b></code></td>
|
|
<td> 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.
|
|
</td></tr><tr>
|
|
<td><code><b>char *currency_symbol</b></code></td>
|
|
<td> The local symbol used for currency.
|
|
</td></tr><tr>
|
|
<td><code><b>char *mon_decimal_point</b></code></td>
|
|
<td> The decimal point character used for monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char *mon_thousands_sep</b></code></td>
|
|
<td> The thousands place grouping character used for monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char *mon_grouping</b></code></td>
|
|
<td> 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.
|
|
</td></tr><tr>
|
|
<td><code><b>char *positive_sign</b></code></td>
|
|
<td> The character used for positive monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char *negative_sign</b></code></td>
|
|
<td> The character used for negative monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char int_frac_digits</b></code></td>
|
|
<td> Number of digits to show after the decimal point in international monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char frac_digits</b></code></td>
|
|
<td> Number of digits to show after the decimal point in monetary values.
|
|
</td></tr><tr>
|
|
<td><code><b>char p_cs_precedes</b></code></td>
|
|
<td> If equal to 1, then the <code><b>currency_symbol</b></code> appears before a positive monetary value. If
|
|
equal to 0, then the <code><b>currency_symbol</b></code> appears after a positive monetary value.
|
|
</td></tr><tr>
|
|
<td><code><b>char p_sep_by_space</b></code></td>
|
|
<td> If equal to 1, then the <code><b>currency_symbol</b></code> is separated by a space from a positive monetary
|
|
value. If equal to 0, then there is no space between the <code><b>currency_symbol</b></code> and a positive
|
|
monetary value.
|
|
</td></tr><tr>
|
|
<td><code><b>char n_cs_precedes</b></code></td>
|
|
<td> If equal to 1, then the <code><b>currency_symbol</b></code> precedes a negative monetary value. If equal to
|
|
0, then the <code><b>currency_symbol succeeds a negative monetary value.
|
|
</td></tr><tr>
|
|
<td><code><b>char n_sep_by_space</b></code></td>
|
|
<td> If equal to 1, then the <code><b>currency_symbol</b></code> is separated by a space from a negative monetary
|
|
value. If equal to 0, then there is no space between the <code><b>currency_symbol</b></code> and a negative
|
|
monetary value.
|
|
</td></tr><tr>
|
|
<td><code><b>char p_sign_posn</b></code></td>
|
|
<td> Represents the position of the <code><b>positive_sign</b></code> in a positive monetary value.
|
|
</td></tr><tr>
|
|
<td><code><b>char n_sign_posn</b></code></td>
|
|
<td> Represents the position of the <code><b>negative_sign</b></code> in a negative monetary value.
|
|
</tr>
|
|
</table>
|
|
<p>
|
|
The following values are used for <b><code>p_sign_posn</code></b> and <b><code>n_sign_posn</code></b>:
|
|
<table border=0>
|
|
<tr><td><code><b>0</b></code></td><td> Parentheses encapsulate the value and the currency_symbol.</td></tr>
|
|
<tr><td><code><b>1</b></code></td><td> The sign precedes the value and currency_symbol.</td></tr>
|
|
<tr><td><code><b>2</b></code></td><td> The sign succeeds the value and currency_symbol.</td></tr>
|
|
<tr><td><code><b>3</b></code></td><td> The sign immediately precedes the value and currency_symbol.</td></tr>
|
|
<tr><td><code><b>4</b></code></td><td> The sign immediately succeeds the value and currency_symbol.</td></tr>
|
|
</table>
|
|
<p>
|
|
Example:<br>
|
|
<blockquote><code><b><pre>
|
|
|
|
#include<locale.h>
|
|
#include<stdio.h>
|
|
int main(void)
|
|
{
|
|
struct lconv locale_structure;
|
|
struct lconv *locale_ptr=&locale_structure;
|
|
|
|
locale_ptr=lcoaleconv();
|
|
printf("Decimal point: %s",locale_ptr->decimal_point);
|
|
printf("Thousands Separator: %s",locale_ptr->thousands_sep);
|
|
printf("Grouping: %s",locale_ptr->grouping);
|
|
printf("International Currency Symbol: %s",locale_ptr->int_curr_symbol);
|
|
printf("Currency Symbol: %s",locale_ptr->currency_symbol);
|
|
printf("Monetary Decimal Point: %s",locale_ptr->mon_decimal_point);
|
|
printf("Monetary Thousands Separator: %s",locale_ptr->mon_thousands_sep);
|
|
printf("Monetary Grouping: %s",locale_ptr->mon_grouping);
|
|
printf("Monetary Positive Sign: %s",locale_ptr->positive_sign);
|
|
printf("Monetary Negative Sign: %s",locale_ptr->negative_sign);
|
|
printf("Monetary Intl Decimal Digits: %c",locale_ptr->int_frac_digits);
|
|
printf("Monetary Decimal Digits: %c",locale_ptr->frac_digits);
|
|
printf("Monetary + Precedes: %c",locale_ptr->p_cs_precedes);
|
|
printf("Monetary + Space: %c",locale_ptr->p_sep_by_space);
|
|
printf("Monetary - Precedes: %c",locale_ptr->n_cs_precedes);
|
|
printf("Monetary - Space: %c",locale_ptr->n_sep_by_space);
|
|
printf("Monetary + Sign Posn: %c",locale_ptr->p_sign_posn);
|
|
printf("Monetary - Sign Posn: %c",locale_ptr->n_sign_posn);
|
|
}
|
|
</pre></b></code></blockquote>
|
|
<hr>
|
|
|
|
<center>
|
|
<table border=0 width=100%>
|
|
<tr>
|
|
<td align=left width=20% valign=top>
|
|
<a href="2.5.html">
|
|
<img src="left.gif" border=0>
|
|
Previous Section<br>
|
|
2.5 limits.h</a></td>
|
|
<td align=center width=60% valign=top>
|
|
| <a href="index.html">Table of Contents</a> |
|
|
<a href="index2.html">Index</a> |</td>
|
|
<td align=right width=20% valign=top>
|
|
<a href="2.7.html">
|
|
Next Section
|
|
<img src="right.gif" border=0><br>
|
|
2.7 math.h</a></td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
</body>
|
|
</html>
|