Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Mar 2008 08:00:19 +0100
From:      chris <le_briocheur@yahoo.fr>
To:        freebsd-i18n@freebsd.org
Subject:   convert greek chars to unicode problem (mbtowc)
Message-ID:  <47CF9683.9040906@yahoo.fr>

next in thread | raw e-mail | index | archive | help
Hello,

i have a problem with the C code below (code + output)
the goal is to convert the "PI" greek character to unicode

the locale dependent representation of PI letter is byte 0xD0 (ISO 8859-7)
the resulting unicode character should be 0x03A0

i dont understand why the function returns the original char without 
conversion... maybe someone can see what is wrong in this code ?

by the way : i use a fresh 6.2 installation on i386

any help greatly welcome !
Best Regards,
Chris



#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <limits.h>

int main( int argc, char** argv)
{
  char mb = '\xD0';
  char* loc = NULL;
  int i;
  wchar_t wc = 0;

  loc = setlocale( LC_CTYPE, "el_GR.ISO8859-7" );
  if ( loc != NULL ) fprintf(stderr,"locale changed to %s\n",loc);
  else fprintf(stderr,"locale NOT changed\n");

  mbtowc(0,0,0);
  i = mbtowc( &wc, &mb, 1 );
  if ( i < 0 ) fprintf(stderr,"conversion error\n");
  else fprintf(stderr,"conversion(%d) : %08x\n",i,wc );

  return 0;
}



The OUTPUT is :

locale changed to el_GR.ISO8859-7
conversion(1) : 000000d0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47CF9683.9040906>