Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2006 17:51:01 +0400 (MSD)
From:      "Andrey V. Elsukov" <bu7cher@yandex.ru>
To:        freebsd-stable@freebsd.org
Cc:        maxim@freebsd.org
Subject:   setlocale howto
Message-ID:  <44DDDCC5.000001.21350@pantene.yandex.ru>

next in thread | raw e-mail | index | archive | help
Hi, All.

I have one question, how use setlocale?
My system is FreeBSD 6.1-STABLE.
A simple test program:

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

int main(int argc, char *argv[])
{
    const char* loc="ru_RU.KOI8-R";
    int i;
    char *loc_ret;
    char buf[]="тестовая строка abcdef";

    loc_ret = setlocale(LC_CTYPE, loc);
    if (!loc_ret) return (-1);

    printf("original string = %s\n", buf);
    for(i = 0; i < sizeof(buf); i++)
        buf[i] = (char)toupper(buf[i]);
    printf("toupper string = %s\n", buf);
    return (0);
}

This programm don't work correctly. Cyrillic symbols don't converted to upper case.
But in the same time perl programm work fine:

use locale;
use POSIX qw(locale_h);

my $str = "тестовая строка abcdef";
setlocale(LC_CTYPE, "ru_RU.KOI8-R");
print uc ($str);

What is wrong?
-- 
WBR, Andrey V. Elsukov



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44DDDCC5.000001.21350>