utf8.c
author Markus Bröker<broeker.markus@googlemail.com>
Fri, 20 Oct 2017 06:41:27 +0200
changeset 168 dfb60716880c
parent 114 6f6850407ccf
permissions -rw-r--r--
Broken OSX Demo added

/**
 * utf8.c
 * Copyright (C) 2008 Markus Broeker
 */

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

#ifndef u_char
typedef unsigned char u_char;
#endif

int main ()
{
    char dest[6];

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

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

    printf ("%ls", str);

    while (*str != L'\n') {
        memset (&dest, 0, sizeof (dest));
        if (wctomb (dest, (*str)) < 0)
            perror ("wctomb");

        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 EXIT_SUCCESS;
}