VMS Help  —  CRTL  nl_langinfo
    Returns a pointer to a string that contains information obtained
    from the program's current locale.

    Format

      #include  <langinfo.h>

      char *nl_langinfo  (nl_item item);

1  –  Argument

 item

    The name of a constant that specifies the information required.
    These constants are defined in <langinfo.h>.

    The following constants are valid:

    Constant     Category     Description

    D_T_FMT      LC_TIME      String for formatting date and time
    D_FMT        LC_TIME      String for formatting date
    T_FMT        LC_TIME      String for formatting time
    T_FMT_AMPM   LC_TIME      Time format with AM/PM string
    AM_STR       LC_TIME      String that represents AM in 12-hour
                              clock notation
    PM_STR       LC_TIME      String that represents PM in 12-hour
                              clock notation
    DAY_1        LC_TIME      The name of the first day of the week
     . . .
    DAY_7        LC_TIME      The name of the seventh day of the week
    ABDAY_1      LC_TIME      The abbreviated name of the first day
                              of the week
     . . .
    ABDAY_7      LC_TIME      The abbreviated name of the seventh day
                              of the week
    MON_1        LC_TIME      The name of the first month in the year
     . . .
    MON_12       LC_TIME      The name of the twelfth month in the
                              year
    ABMON_1      LC_TIME      The abbreviated name of the first month
                              in the year
     . . .
    ABMON_12     LC_TIME      The abbreviated name of the twelfth
                              month in the year
    ERA          LC_TIME      Era description strings
    ERA_D_FMT    LC_TIME      Era date format string
    ERA_T_FMT    LC_TIME      Era time format
    ERA_D_T_FMT  LC_TIME      Era date and time format
    ALT_DIGITS   LC_TIME      Alternative symbols for digits
    RADIXCHAR    LC_NUMERIC   The radix character
    THOUSEP      LC_NUMERIC   The character used to separate groups
                              of digits in nonmonetary values
    YESEXP       LC_MESSAGES  The expression for affirmative
                              responses to yes/no questions
    NOEXP        LC_MESSAGES  The expression for negative responses
                              to yes/no questions
    CRNCYSTR     LC_MONETARY  The currency symbol. It is preceded by
                              one of the following:

                              o  A minus (-)  if the symbol is to
                                 appear before the value

                              o  A plus (+)  if the symbol is to
                                 appear after the value

                              o  A period (.)  if the symbol replaces
                                 the radix character

    CODESET      LC_CTYPE     Codeset name

2  –  Description

    If the current locale does not have language information defined,
    the function returns information from the C locale. The program
    should not modify the string returned by the function. This
    string might be overwritten by subsequent calls to nl_langinfo.

    If the setlocale function is called after a call to nl_langinfo,
    then the pointer returned by the previous call to nl_langinfo
    will be unspecified. In this case, the nl_langinfo function
    should be called again.

3  –  Return Value

    x                  Pointer to the string containing the requested
                       information. If item is invalid, the function
                       returns an empty string.

4  –  Example

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

        /* This test sets up the British English locale, and then       */
        /* inquires on the data and time format, first day of the week, */
        /* and abbreviated first day of the week.                       */

        #include <stdlib.h>
        #include <string.h>

        int main()
        {
            char *return_val;
            char *nl_ptr;

            /* set the locale, with user supplied locale name  */

            return_val = setlocale(LC_ALL, "en_gb.iso8859-1");
            if (return_val == NULL) {
                printf("ERROR : The locale is unknown");
                exit(1);
            }
            printf("+----------------------------------------+\n");

            /* Get the date and time format from the locale.  */

            printf("D_T_FMT = ");

            /*  Compare the returned string from nl_langinfo with */
            /*  an empty string.                                  */

            if (!strcmp((nl_ptr = (char *) nl_langinfo(D_T_FMT)), "")) {

          /* The string returned was empty this could mean that either */
          /* 1) The locale does not contain a value for this item      */
          /* 2) The value for this item is an empty string             */

                printf("nl_langinfo returned an empty string\n");
            }
            else {
                /* Display the date and time format  */

                printf("%s\n", nl_ptr);
            }

        /* Get the full name for the first day of the week from locale */
           printf("DAY_1 = ");

          /*  Compare the returned string from nl_langinfo with */
          /*  an empty string.                                  */

            if (!strcmp((nl_ptr = (char *) nl_langinfo(DAY_1)), "")) {

          /* The string returned was empty this could mean that either */
          /*    1) The locale does not contain a value for the first   */
          /*       day of the week                                     */
          /*    2) The value for the first day of the week is          */
          /*       an empty string                                     */

                printf("nl_langinfo returned an empty string\n");
            }

            else {
             /* Display the full name of the first day of the week     */

                printf("%s\n", nl_ptr);
            }
  /* Get the abbreviated name for the first day of the week from locale*/

            printf("ABDAY_1 = ");

         /* Compare the returned string from nl_
 langinfo with an empty */
         /* string.                                                    */

            if (!strcmp((nl_ptr = (char *) nl_langinfo(ABDAY_1)), "")) {

         /* The string returned was empty this could mean that either  */
         /*    1) The locale does not contain a value for the first    */
         /*       day of the week                                      */
         /*    2) The value for the first day of the week is an        */
         /*       empty string                                         */

                printf("nl_langinfo returned an empty string\n");
            }

            else {

         /* Display the abbreviated name of the first day of the week  */

                printf("%s\n", nl_ptr);
           }
        }

      Running the example program produces the following result:

        +----------------------------------------+
        D_T_FMT = %a %e %b %H:%M:%S %Y
        DAY_1 = Sunday
        ABDAY_1 = Sun
Close Help