?
, errno printf!
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
int main(void)
{
wchar_t *s;
s = (wchar_t *) malloc(sizeof(wchar_t) * 2);
s[0] = 0xC389;
s[1] = 0;
if (printf("%ls\n", s) < 0) {
perror("printf");
}
free(s);
return (0);
}
:
$ gcc test.c && ./a.out
printf: Invalid or incomplete multibyte or wide character
, C - C ( POSIX), ASCII. setlocale, setlocale(LC_ALL,"").
LC_ALL, LC_CTYPE LANG , UTF-8 , . setlocale(LC_ALL, "C.UTF-8") - C , UTF-8 C .
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
wchar_t *s;
s = (wchar_t *) malloc(sizeof(wchar_t) * 2);
s[0] = 0xC389;
s[1] = 0;
setlocale(LC_ALL, "");
if (printf("%ls\n", s) < 0) {
perror("printf");
}
free(s);
return (0);
}
:
$ gcc test.c && ./a.out
쎉
, , , wchar_t (, UTF-32), (, UTF-8). , wchar_t 32 GNU C, C . UTF-32BE (.. 0x000000C9), :
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
wchar_t *s;
s = (wchar_t *) malloc(sizeof(wchar_t) * 2);
s[0] = 0xC9;
s[1] = 0;
setlocale(LC_ALL, "");
if (printf("%ls\n", s) < 0) {
perror("printf");
}
free(s);
return (0);
}
:
$ gcc test.c && ./a.out
É
, LC (locale) :
$ LC_ALL=C.UTF-8
$ ./a.out
É