{"id":3545,"date":"2019-03-30T00:01:00","date_gmt":"2019-03-30T07:01:00","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=3545"},"modified":"2019-03-23T12:38:00","modified_gmt":"2019-03-23T19:38:00","slug":"locale-settings-dear-to-you","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=3545","title":{"rendered":"Locale Settings Dear to You"},"content":{"rendered":"<p>The <em>setlocale()<\/em> function, mentioned in <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3541\">last week&#8217;s Lesson<\/a>, both returns the current locale string and sets a new locale. It&#8217;s not necessary to call this function to gather locale details already known to your computer. To pluck out this detail, use the <em>localeconv()<\/em> function.<br \/>\n<!--more--><br \/>\nHere&#8217;s the format:<\/p>\n<p><code>struct lconv * localeconv(void)<\/code><\/p>\n<p>Like the <em>setlocale()<\/em> function, <em>localeconv()<\/em> is prototyped in the <code>locale.h<\/code> header file. The function takes no argument and returns a pointer to an <em>lconv<\/em> structure. This structure&#8217;s members contain the various tidbits related to localization items.<\/p>\n<p>The full list of <em>lconv<\/em> structure members is found by view the <em>localeconv()<\/em> function&#8217;s <em>man<\/em> page. They may differ from system to system. Some of the members may not be available on all systems.<\/p>\n<p>The following code displays three members of the <em>lconv<\/em> structure:<\/p>\n<p><code>decimal_point<\/code> is a <em>char<\/em> pointer (string) representing the decimal point character(s).<\/p>\n<p><code>thousands_sep<\/code> is a <em>char<\/em> pointer (string) representing the character(s) used to separate thousands in a large value.<\/p>\n<p><code>currency_symbol<\/code> is a <em>char<\/em> pointer (string) representing the character(s) used as to represent a monetary value for a locale.<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;locale.h&gt;\r\n\r\nint main()\r\n{\r\n    struct lconv *locale_ptr;\r\n\r\n    locale_ptr = localeconv();\r\n\r\n    printf(\"Decimal point: %s\\n\",locale_ptr-&gt;decimal_point);\r\n    printf(\"Thousands separator: %s\\n\",locale_ptr-&gt;thousands_sep);\r\n    printf(\"Currency symbol: %s\\n\",locale_ptr-&gt;currency_symbol);\r\n\r\n    return(0);\r\n}<\/pre>\n<p>Because <em>lconv<\/em> structure variable <code>locale_ptr<\/code> is a pointer, structure member pointer notation is used at Lines 10 through 12. Here&#8217;s sample output:<\/p>\n<p><code>Decimal point: .<br \/>\nThousands separator:<br \/>\nCurrency symbol:<\/code><\/p>\n<p>On my system, the period is the decimal point character. The other two items are undefined, so their strings are empty. This output seems disappointing, but my guess is that the operating system most likely has better locale functions. It&#8217;s probably what most programs use when outputting region-specific information.<\/p>\n<p>For your C code, the locale functions come into play when generating wide-characters. You can read this blog&#8217;s series on wide characters <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2568\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Take a peek at some of the locale options on your computer. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3545\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3545","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3545"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3545\/revisions"}],"predecessor-version":[{"id":3554,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3545\/revisions\/3554"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}