Example 1 (setlocale -- Set Locale)

This example sets the locale of the program to be "fr_fr.ibm-850" and prints the string that is associated with the locale.

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#if (1 == __TOS_OS2__)
   #define LOCNAME "fr_fr.ibm-850"      /* OS/2 name */
#else
   #define LOCNAME "fr_fr.ibm-1252"  /* Windows name */
#endif
int main(void)
{
   char *string;
   if (NULL == (string = setlocale(LC_ALL, LOCNAME)))
      printf("Locale \"%s\" could not be loaded\n", LOCNAME);
   else
      printf("The current locale is set to %s.\n", string);
   return 0;
   /*******************************************************
      The output should be similar to :
      The current locale is set to fr_fr.ibm-850.
   *******************************************************/
}

Example 2 (setlocale -- Set Locale)

This example uses setenv to set the value of the environment variable LC_TIME to FRAN, calls setlocale to set all categories to default values, then queries all categories, and uses printf to print results.

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#if (1 == __TOS_OS2__)
   #define LOCSTR "LC_TIME=fr_fr.ibm-437"     /* OS/2 name */
#else
   #define LOCSTR "LC_TIME=fr_fr.ibm-1252" /* Windows name */
#endif
int main(void)
{
   char *string;
   _putenv(LOCSTR);
   if (NULL == (string = setlocale(LC_ALL, ""))) {
      printf("setlocale(LC_ALL, \"\") failed.\n");
      exit(1);
   } else
      printf("The current locale categories are: \"%s\"\n", string);
   return 0;
   /*******************************************************************
      The output should be similar to:
      The current locale categories are: "C,C,C,C,fr_fr.ibm-437,C,C,C"
   *******************************************************************/
}