[ACCEPTED]-How do I represent a Unicode character in a literal string ISO/ANSI C when the character set is ASCII?-unicode
For UTF8, you have to generate the encoding 6 yourself using rules found, for example, here. For 5 example, the German sharp s (ß, code point 4 0xdf), has the UTF8 encoding 0xc3,0x9f. Your 3 e-acute (é, code point 0xe9) has a UTF8 2 encoding of 0xc3,0xa9.
And you can put arbitrary 1 hex characters in your strings with:
char *cv = "r\xc3\xa9sum\xc3\xa9";
char *sharpS = "\xc3\x9f";
If you have a C99 compiler you can use <wchar.h> (and 2 <locale.h>) and enter the Unicode 1 code points directly in the source.
$ cat wc.c
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
int main(void) {
const wchar_t *name = L"r\u00e9sum\u00e9";
setlocale(LC_CTYPE, "en_US.UTF-8");
wprintf(L"name is %ls\n", name);
return 0;
}
$ /usr/bin/gcc -std=c99 -pedantic -Wall wc.c
$ ./a.out
name is résumé
wchar_t is the type you are looking for: http://opengroup.org/onlinepubs/007908799/xsh/wchar.h.html
0
wchar_t
setlocale()
seems optional
#include <stdio.h>
int main(void) {
const char *const name = "r\u00e9sum\u00e9";
printf("name is %s\n",name);
return 0;
}
$ echo $LANG
en_US.UTF-8
$ /usr/bin/gcc -std=c99 -pedantic -Wall -Wextra bc.c
$ ./a.out
name is résumé
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.