author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:02 +0100 | |
changeset 9 | c3fecc82ade6 |
parent 8 | 96d16dfe787a |
child 48 | b94d657a9acb |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/utf8.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
*/ |
5 |
||
6 |
#include <stdio.h> |
|
7 |
#include <stdlib.h> |
|
8 |
#include <wchar.h> |
|
9 |
#include <locale.h> |
|
10 |
||
11 |
#ifndef u_char |
|
12 |
typedef unsigned char u_char; |
|
13 |
#endif |
|
14 |
||
15 |
int main () |
|
16 |
{ |
|
17 |
char dest[4]; |
|
18 |
||
19 |
wchar_t *str = L"Unicode Example with german umlauts: ÄÖÜäöü߀\n"; |
|
20 |
||
21 |
if (!setlocale (LC_CTYPE, "")) { |
|
22 |
perror ("SETLOCALE"); |
|
23 |
return EXIT_FAILURE; |
|
24 |
} |
|
25 |
||
26 |
printf ("%ls", str); |
|
27 |
||
28 |
while (*str != '\n') { |
|
29 |
dest[0] = 0; |
|
30 |
dest[1] = 0; |
|
31 |
dest[2] = 0; |
|
32 |
dest[3] = 0; |
|
33 |
if (wctomb (dest, (*str)) == -1) |
|
34 |
return -1; |
|
35 |
||
36 |
printf ("%lc -> [%4X] (%2X:%2X:%2X:%2X)\n", |
|
37 |
*str, *str, (u_char) dest[0], (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
38 |
str++; |
|
39 |
} |
|
40 |
||
41 |
printf ("DIFF: %d : 0x%2X\n", 0x40, 0x40); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
42 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
43 |
return EXIT_SUCCESS; |
0 | 44 |
} |