setlocale howto
Andrey V. Elsukov
bu7cher at yandex.ru
Sat Aug 12 13:51:19 UTC 2006
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
More information about the freebsd-stable
mailing list