Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Ascii character output

Aug
14
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
 
Is this a standalone executable that you're talking about? Does it work as you expect in a plain old CMD.EXE window?
 
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).
 
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?
 
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;
}
 
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?
 
If you redirect this program's output to a file, does the file contain the correct characters?
 
Notepad and TCC are using the Lucida Console font. Here is a screenshot.

ss1.png
 
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.
 
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...
 

Similar threads

Back
Top