convert greek chars to unicode problem (mbtowc)

chris le_briocheur at yahoo.fr
Thu Mar 6 07:29:16 UTC 2008


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


More information about the freebsd-i18n mailing list