setlocale

Selects the appropriate portion of the program's locale as specified by the category and locale arguments. You can use this function to change or query one category or the program's entire current locale.

Format

#include  <locale.h>

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

Arguments

category
The name of the category. Specify LC_ALL to change or query the entire locale. Other valid category names are:
locale
Pointer to a string that specifies the locale.

Description

This function sets or queries the appropriate portion of the program's locale as specified by the category and locale arguments. Specifying LC_ALL for the category argument names the entire locale; specifying the other values name only a portion of the program's locale.

The locale argument points to a character string that identifies the locale to be used. This argument can be one of the following:

Return Values
Pointer to a string describing the locale. 
NULL  Indicates an error occurred; errno is set. 

Example

    #include <errno.h>
    #include <stdio.h>
    #include <locale.h>
    
    /* This test calls setlocale() three times. The second call is for   */
    /* a nonexistent locale. The third call is for an existing file that */
    /* is not a locale file.                                             */
    
    main()
      {
      char  *ret_str;
    
      errno = 0;
      printf ("setlocale (LC_ALL, \"POSIX\")");
      ret_str = (char *)setlocale (LC_ALL, "POSIX");
      if (ret_str == NULL)
       perror("setlocale error");
      else
       printf(" call was succesfull");
    
      errno = 0;
      printf ("\n\nsetlocale (LC_ALL, \"junk.junk_codeset\")");
      ret_str = (char *)setlocale (LC_ALL, "junk.junk_codeset");
    
      if (ret_str == NULL)
       perror("\rreturned error");
      else
       printf(" call was succesfull");
    
      errno = 0;
      printf ("\n\nsetlocale (LC_ALL, \"sys$login:login.com\")");
      ret_str = (char *)setlocale (LC_ALL, "sys$login:login.com");
    
      if (ret_str == NULL)
       perror("\rreturned error");
      else
       printf(" call was succesfull\n");
    
      }
    

    Running the example program produces the following result:

    setlocale (LC_ALL, "POSIX") call was succesfull
    
    setlocale (LC_ALL, "junk.junk_codeset")
    returned error: no such file or directory
    
    setlocale (LC_ALL, "sys$login:login.com")
    returned error: non-translatable vms error code: 0x35C07C
    %c-f-localebad, not a locale file
    


Previous Page | Next Page | Table of Contents | Index