Skip to content

🈂️ Unicode Support

Feldwor edited this page Jul 22, 2021 · 14 revisions
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>

int main()
{
    const wchar_t hmm[] = L"äö";

    setlocale(LC_ALL, "");
    wprintf(L"%ls\n", hmm);
    wprintf(L"%lc\n", hmm[0]);
    wprintf(L"%i\n", wcslen(hmm));

    return 0;
}

https://stackoverflow.com/questions/14083706/iterating-through-a-char-array-with-non-standard-chars/14083757#14083757

☺Emoji support

https://stackoverflow.com/questions/23915322/printing-a-smiley-using-c-in-netbeans

https://stackoverflow.com/questions/50603067/using-code-page-437-and-setlocale-at-the-same-time

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <locale.h>
#include <wchar.h>
#include <time.h>
int main(void)
   {
   setlocale(LC_ALL, ".437");
   wchar_t * smiley = L"įšįėų ☺ ☻ ♥ ♦ ♣ ♠ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ ♂ ♀ ‼";   
   wprintf(L"[%s]\n", smiley);


   setlocale(LC_ALL, ".1251");
   wchar_t * symbols = L"įšįėų ©°×";   
   wprintf(L"[%s]\n", symbols);

   return(0);
   }

List all the characters in the range.

#include <stdio.h>
#include <locale.h>

#ifndef __STDC_ISO_10646__
#error "Oops, our wide chars are not Unicode codepoints, sorry!"
#endif
int main()
{
        int i;
        setlocale(LC_ALL, "");

        for (i = 0; i < 0xffff; i++) {
		// Find specific character 
		// if ( (wchar_t)i == 'c') printf("%x - %lc\n", i, i);
                printf("%x - %lc\n", i, i);
        }

        return 0;
}

Source: https://stackoverflow.com/questions/25033430/how-to-iterate-through-unicode-characters-and-print-them-on-the-screen-with-prin/25035638#25035638

Ways to set the code page in C

https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers


setlocale(LC_ALL, "");
setlocale(LC_ALL, ".65001");
char* res = setlocale(LC_ALL, ".UTF8");