// this file is written in UTF-8 // this program should be tested in Linux enviroment with UTF-8 locale #include #include #include #include int main() { char s[100] = {}; wchar_t ls[100] = {}; char *p; wchar_t *lp; // according to: https://stackoverflow.com/questions/19864304/mbstowcs-returns-1-on-red-hat-linux-but-not-on-solaris setlocale(LC_CTYPE, ""); // copy two strings // these test chars are from: https://en.wikipedia.org/wiki/UTF-8 strcpy(s, "hello$$¢¢€€𐍈𐍈world"); wcscpy(ls, L"hello$$¢¢€€𐍈𐍈world"); // dump two strings printf("s : "); for (p = s; *p; p++) printf("%02X ", (unsigned)(unsigned char) *p); printf("\n"); printf("ls: "); for (lp = ls; *lp; lp++) printf("%02X ", (unsigned)*lp); printf("\n"); // display two strings printf("s : %s\n", s); printf("ls: %ls\n", ls); return 0; }