HELPLIB.HLB  —  CRTL  setlocale  Example
        #include <errno.h>
        #include <stdio.h>
        #include <locale.h>

        /* This program 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 successful\n");

            errno = 0;
            printf("\n\nsetlocale (LC_ALL, \"junk.junk_codeset\")");
            ret_str = (char *) setlocale(LC_ALL, "junk.junk_codeset");

            if (ret_str == NULL)
                perror(" returned error");
            else
                printf(" call was successful\n");

            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(" returned error");
            else
                printf(" call was successful\n");
        }

      Running the example program produces the following result:

        setlocale (LC_ALL, "POSIX") call was successful

        setlocale (LC_ALL, "junk.junk_codeset")
        returned error: no such file or directory

        setlocale (LC_ALL, "sys$login:login.com")
        returned error: nontranslatable vms error code: 0x35C07C
        %c-f-localebad, not a locale file
Close Help