setlocale - C locale.h

C examples for locale.h:setlocale

type

function

from


<locale.h>
<clocale>

Description

Set or retrieve locale

Prototype

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

Parameters

category is the locale affected. It is one of the following constant values defined as macros in <clocale>:

value the locale affected
LC_ALL The entire locale.
LC_COLLATE the behavior of strcoll and strxfrm.
LC_CTYPE all functions of <cctype>, except isdigit and isxdigit, and the multibyte and wide character functions.
LC_MONETARY monetary formatting information returned by localeconv.
LC_NUMERIC the decimal-point character in formatted input/output operations and string formatting functions, as well as non-monetary information returned by localeconv.
LC_TIME the behavior of strftime.

locale is C string containing the name of a C locale. These are system specific, but at least the two following locales must exist:

locale name description
"C" Minimal "C" locale
"" Environment's default locale

If the value of this parameter is NULL, the function does not make any changes to the current locale.

Return Value

On success, string value of the locale currently set for the category.

On error, a null pointer is returned.

Demo Code


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

int main ()//from   w w  w .ja  va  2 s .  c om
{
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];

  struct lconv * lc;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );

  int twice=0;

  do {
    printf ("Locale is: %s\n", setlocale(LC_ALL,NULL) );

    strftime (buffer,80,"%c",timeinfo);
    printf ("Date is: %s\n",buffer);

    lc = localeconv ();
    printf ("Currency symbol is: %s\n-\n",lc->currency_symbol);

    setlocale (LC_ALL,"");
  } while (!twice++);

  return 0;
}

Related Tutorials