learnprogramming123

LEARN PROGRAMMING 123
your resources to programming and free tutition



Navigation

 
C
 
C++ soon here!
VB - soon here!

Search

 

 

Next Back


<locale.h>        -        Localization

jump to: demonstration of <locale.h>

This header provides functions to control aspects of the library that depend upon the country or other geographical location. Those include the character used as the decimal point, the currency symbol and the appearance of the date and the time.

struct *localeconv(void);

The function localeconv returns a pointer to the structure specifying the current locale and is specified as follows in the header file <locale.h>


struct *localeconv(void);
{
    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 n_cs_precedes;
    char n_sep_by_space;
    char p_sign_posn;
    char n_sign_posn;
};

char *setlocale(int category, const char *locale);

The function setlocale may be used to set or query the program's current locale, where category specifies the action required and can take one of the following values.

LC_ALL specifies the entire locale
LC_COLLATE specifies the behaviour of functions strcoll and strxfrm
LC_CTYPE specifies the behaviour of the character and multi-byte functions
LC_MONETARY specifies the formatting information returned by localeconv
LC_NUMERIC specifies the decimal point character for the formatted I/O functions and string conversion functions
LC_TIME specifies the behaviour of the strftime function
   

Locale points to a specification for the locale. A value of "C" for locale specifies the minimal C environment, a value of "" specifies the native environment.

If a valid string is given for the locale argument, the area of the locale specified by category is changed to that value. If an error occurs a NULL value is returned. If the value of locale is "", the current setting for the portion of the locale is returned and the locale remains unchanged.

Example:

#include <stdio.h>
#include <locale.h>
#include <limits.h>

int main(void)
{
   
    struct loonv *current_locale;

    setlocale(LC_ALL, "C");
    current_locale = localeconv();

    printf("%s\n", current_locale -> decimal_point);
    printf("%s\n", current_locale -> frac_digits);

    return 0;

}

Results of program being run:

127

go to <math.h>        back to top        back to main

 

 

 

 






1