utf8.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:57:57 +0100
changeset 5 d752cbe8208e
parent 0 af501b0c1716
child 8 96d16dfe787a
permissions -rw-r--r--
asm and parser demos added committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 *     $Id: utf8.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
 * $Source: /development/c/demos/utf8.c,v $
 *
 */

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

#ifndef u_char
typedef unsigned char u_char;
#endif

int main ()
{
    char dest[4];

    wchar_t *str = L"Unicode Example with german umlauts: ÄÖÜäöü߀\n";

    if (!setlocale (LC_CTYPE, "")) {
        perror ("SETLOCALE");
        return EXIT_FAILURE;
    }

    printf ("%ls", str);

    while (*str != '\n') {
        dest[0] = 0;
        dest[1] = 0;
        dest[2] = 0;
        dest[3] = 0;
        if (wctomb (dest, (*str)) == -1)
            return -1;

        printf ("%lc -> [%4X] (%2X:%2X:%2X:%2X)\n",
                *str, *str, (u_char) dest[0], (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]);
        str++;
    }

    printf ("DIFF: %d : 0x%2X\n", 0x40, 0x40);
    return 0;
}