Reputation: 29
I would like to make my C program print signs from other charset, not from the ASCII table as it is default. For example, I want to print chars in range [200,250] from the ISO-8859 charset. Is it possible at all? How the compiler should be set? Thanks in advance for help!
Upvotes: 2
Views: 1455
Reputation: 41046
Setting you locales and using wide characters:
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(void)
{
setlocale(LC_CTYPE, "");
for (wchar_t c = 200; c < 250; c++)
{
wprintf(L"%lc", c);
}
wprintf(L"\n");
return 0;
}
Output:
ÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øù
Upvotes: 2
Reputation: 9904
In fact C functions don't care about encoding, so if you have a code like that:
#include <stdio.h>
int main( void )
{
printf( "Hällo Wörld\n" );
return( 0 );
}
It will print out 'germanzied' "Hello World" in exactly the encoding of the C source file, indepedent from system settings etc. The same is true of course if you print strings that you read from a file. If you want to reencode strings (say from UTF-8 to ISO-8859) you have to do t manually or search for an appropriate library
Upvotes: 0