Created
May 4, 2024 07:48
-
-
Save multitudes/8f07ad3cb1e09bdfea0d85d14f767aef to your computer and use it in GitHub Desktop.
extended ascii and display locale
This file contains hidden or 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 <locale.h> | |
#include <wchar.h> | |
#include <stdio.h> | |
int main() { | |
// Set the locale to the user's default locale | |
setlocale(LC_ALL, ""); | |
// wchat_t is a wide character type | |
wchar_t c1 = L'ò'; | |
wchar_t c2 = L'¡'; | |
// %lc is the format specifier for a wide character | |
wprintf(L"%lc %lc\n", c1, c2); | |
return 0; | |
} |
This file contains hidden or 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 <locale.h> | |
#include <wchar.h> | |
#include <stdio.h> | |
int main() { | |
// Set the locale to the user's default locale | |
setlocale(LC_ALL, ""); | |
//print the locale | |
wprintf(L"Locale is: %s\n", setlocale(LC_ALL, "")); | |
for (int i = 128; i <= 255; i++) { | |
wchar_t c = (wchar_t)i; | |
//starts printing anything recognizable from the 161th character | |
wprintf(L"%lc ", c); | |
} | |
wprintf(L"\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the first would print the chars ò ¡ WITHOUT using unicode, only extended ascii... I believe.
And trying to print from 128 to 255 I get these chars according to my locale.
¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
And to set the locale. Interestingly for those doing minishell, it is set as an environmental variable in bash! Like
export LC_ALL=en_US.UTF-8
It is using UTF-8 behind the scenes?
locale -a
Would list the available locale. I tried of course export LC_ALL=ja_JP.eucJP but my terminal did not like it...