Created
August 16, 2010 22:24
-
-
Save chryss/527861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <wchar.h> | |
#include <locale.h> | |
#define MYLOCALE "de_DE.UTF-8" | |
int widecharcomp(const wchar_t *arg1, const wchar_t *arg2) | |
{ | |
return wcscoll(arg1, arg2); | |
} | |
int main (void) { | |
struct lconv *locale_ptr; | |
wchar_t a = L'a'; | |
wchar_t a1 = L'ä'; | |
wchar_t b = L'z'; | |
wchar_t jpn = L'\x3074'; // single Japanese character | |
wchar_t wrd[] = {a, a1, b, '\0'}; // putting chars together into string | |
wchar_t french[] = L"\x0152uf"; | |
wchar_t chararray[] = {b, a, a1}; // array of wide single characters | |
size_t length; | |
setlocale(LC_ALL, MYLOCALE); | |
if (setlocale(LC_COLLATE, MYLOCALE) == NULL) { | |
fprintf(stderr, "Can't set the locale %s. " | |
"Check LANG, LC_CTYPE, LC_ALL.\n", MYLOCALE); | |
return 1; | |
} | |
locale_ptr = localeconv(); | |
length = wcslen(chararray); | |
qsort(chararray, length, sizeof(wchar_t), widecharcomp); | |
// qsort(chararray, length, sizeof(wchar_t), wcscoll); | |
chararray[length++] = '\0'; | |
printf("Currency symbol: %s\n", locale_ptr->currency_symbol); | |
printf("A single ascii character: %lc\n", a); | |
printf("A single accentuated Latin character: %lc\n", a1); | |
printf("A single Japanese character %lc\n", jpn); | |
printf("A word in French: %ls\n", french); | |
printf("Three characters in an array: %ls\n", wrd); | |
printf("The same characters alphabetically sorted: %ls\n", chararray); | |
printf("Size in bytes of the French word: %zu\n", sizeof french); | |
printf("...of the Latin non-ascii char: %zu\n", sizeof a1); | |
printf("...of the Japanese char: %zu\n", sizeof jpn); | |
printf("Length of the char array: %zu\n", wcslen(chararray)); | |
printf("Comparison of first two chars in char array: %d\n", wcscoll(&a, &a1)); | |
printf("Comparison of last two chars in char array: %d\n", wcscoll(&a1, &b)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment