1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ascii character output

Discussion in 'Support' started by wcfi, Jan 23, 2012.

  1. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    When I run the following, the characters are not displayed as they should be, whether or not Unicode is set in TCC Options. When I output it to a file and view the file in a text editor (gvim), the characters are correct. How can I get them to be displayed correctly in Take Command/TCC? I use the same font in gvim as I do in Take Command (Bitstream Vera Sans Mono).

    #include <stdio.h>
    int main() {
    printf("xæøx");
    return 0;
    }
    > a.out
    xµ°x
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Is this a standalone executable that you're talking about? Does it work as you expect in a plain old CMD.EXE window?
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,730
    Likes Received:
    80
    Not sure what you're referring to with "Unicode is set in TCC Options" -- there isn't any Unicode display output option in TCC. There is a "Unicode output" option in the Startup tab, but that's for redirected output to files.

    You need to make sure you're using a Unicode font in TCC. That is set in the Windows system properties -- start a stand-alone TCC session, click on the icon in the upper left corner, select Properties / Font, and select a Unicode font like Lucida or Consolas. (Raster fonts will not display Unicode characters.) The Take Command font also needs to be a Unicode font (I don't know whether Vera Sans Mono is Unicode).
     
  4. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    The are extended ascii characters (above 126). Notepad shows them using Lucida Console, but tcc and cmd do not. Anything that can be done to make it consistent?
     
  5. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    First, if you want Unicode characters, you really should be using wide-character strings: wprintf( L"xæøx" ), not printf( "xæøx" ). Second, stdout uses the OEM character set by default. You can change it using _setmode(); do this at the start of your program, before you output any text:

    Code:
    #include <stdio.h>
    #include <io.h>
    #include <fcntl.h>
    
    int main() {
        _setmode( _fileno( stdout ), _O_U16TEXT );
        wprintf( L"xæøx" );
        return 0;
    }
     
    
     
  6. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    But if it is not my software that is outputting these characters (so I can not change the source), can I get them to display consistently in console output?
     
  7. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    If you redirect this program's output to a file, does the file contain the correct characters?
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,730
    Likes Received:
    80
    Did you change the console (TCC) and TCMD fonts to Unicode fonts?
     
  9. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    Notepad and TCC are using the Lucida Console font. Here is a screenshot.

    ss1.png
     
  10. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    What's the size, in bytes, of the output file?
     
  11. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    4
     
  12. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Four characters, two of them above 127, in four bytes: that definitely isn't Unicode. Notepad is interpreting it as ANSI, which is pretty close to what you want. The console is using some other code page, maybe 437?

    You could try CHCP 1252 before running your program.
     
  13. wcfi

    Joined:
    Aug 31, 2011
    Messages:
    13
    Likes Received:
    0
    That works, thanks. I'll have to read more about code pages...
     

Share This Page