utf8.c
changeset 0 af501b0c1716
child 8 96d16dfe787a
equal deleted inserted replaced
-1:000000000000 0:af501b0c1716
       
     1 /**
       
     2  *     $Id: utf8.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
       
     3  * $Source: /development/c/demos/utf8.c,v $
       
     4  *
       
     5  */
       
     6 
       
     7 #include <stdio.h>
       
     8 #include <stdlib.h>
       
     9 #include <wchar.h>
       
    10 #include <locale.h>
       
    11 
       
    12 #ifndef u_char
       
    13 typedef unsigned char u_char;
       
    14 #endif
       
    15 
       
    16 int main ()
       
    17 {
       
    18     char dest[4];
       
    19 
       
    20     wchar_t *str = L"Unicode Example with german umlauts: ÄÖÜäöü߀\n";
       
    21 
       
    22     if (!setlocale (LC_CTYPE, "")) {
       
    23         perror ("SETLOCALE");
       
    24         return EXIT_FAILURE;
       
    25     }
       
    26 
       
    27     printf ("%ls", str);
       
    28 
       
    29     while (*str != '\n') {
       
    30         dest[0] = 0;
       
    31         dest[1] = 0;
       
    32         dest[2] = 0;
       
    33         dest[3] = 0;
       
    34         if (wctomb (dest, (*str)) == -1)
       
    35             return -1;
       
    36 
       
    37         printf ("%lc -> [%4X] (%2X:%2X:%2X:%2X)\n",
       
    38                 *str, *str, (u_char) dest[0], (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]);
       
    39         str++;
       
    40     }
       
    41 
       
    42     printf ("DIFF: %d : 0x%2X\n", 0x40, 0x40);
       
    43     return 0;
       
    44 }