Ascii character output

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Aug 31, 2011
13
0
#1
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
 

rconn

Administrator
Staff member
May 14, 2008
10,096
85
#3
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).
 
Aug 31, 2011
13
0
#4
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?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,376
39
Albuquerque, NM
prospero.unm.edu
#5
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;
}
 
Aug 31, 2011
13
0
#6
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:
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?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,376
39
Albuquerque, NM
prospero.unm.edu
#12
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.
 
Aug 31, 2011
13
0
#13
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.
That works, thanks. I'll have to read more about code pages...