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!
            Asked
            
        
        
            Active
            
        
            Viewed 827 times
        
    2
            
            
        - 
                    This question is tagged with `8859-2`. Is that the `8859` character set you want? Not `8859-1` also called `latin-1`? – Marlin Pierce Oct 21 '19 at 17:23
 - 
                    no, I i would like to display char from different charsets, e.g. 8859-2, WINDOWS-1250 etc. – ChillyWilly88 Oct 21 '19 at 21:29
 
2 Answers
2
            
            
        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:
ÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øù
        David Ranieri
        
- 39,972
 - 7
 - 52
 - 94
 
- 
                    
 - 
                    1Ah, you are on debian, in this case [iconv](http://man7.org/linux/man-pages/man3/iconv_open.3.html) can help – David Ranieri Oct 21 '19 at 21:46
 - 
                    
 - 
                    Of course, iconv can convert between different encodings i.e. utf8 to code page 1250 and viceversa.Another option is save your source files (.c) with the desired encoding, c will assume this encoding for your I/O operations – David Ranieri Oct 21 '19 at 22:17
 - 
                    
 
0
            
            
        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
        Ingo Leonhardt
        
- 9,435
 - 2
 - 24
 - 33
 
- 
                    Well, but i don't want to print a fixed string of chars, i want to print chars from the table of a certain charset – ChillyWilly88 Oct 21 '19 at 21:27