Home > Electronics Tutorials > C Language Tutorial > locale.h - setlocale

C Language Programming Library Reference Guide

locale.h - setlocale

Declaration:

char *setlocale(int category, const char *locale); Sets or reads location dependent information.

category can be one of the following:

LC_ALL Set everything.
LC_COLLATE Affects strcoll and strxfrm functions.
LC_CTYPE Affects all character functions.
LC_MONETARY Affects the monetary information provided by localeconv function.
LC_NUMERIC Affects decimal-point formatting and the information provided by localeconv function.
LC_TIME Affects the strftime function.
 

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.

After a successful set, setlocale returns a pointer to a string which represents the previous location setting. On failure it returns NULL.

Example:

#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;
}
Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......