Ascii character output

Aug 31, 2011
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
 

rconn

Administrator
Staff member
May 14, 2008
12,404
152
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
14
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?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,491
90
Albuquerque, NM
prospero.unm.edu
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
14
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?
 
Aug 31, 2011
14
0
Notepad and TCC are using the Lucida Console font. Here is a screenshot.

ss1.png
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,491
90
Albuquerque, NM
prospero.unm.edu
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
14
0
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
Thread starter Title Forum Replies Date
S Fixed Build 48 - Non-ASCII Character mishandling Support 3
gschizas Fixed Using codepage 65001 (UTF-8) breaks non-ASCII characters Support 8
Peter Murschall WAD FOR reads Text in ASCII !??!? Support 7
M Problem with Extended Search and non-ASCII characters in directories names Support 3
Charles Dye @ASCII vs. @UNICODE Support 5
C @ascii[] btwn v8 and v14 Support 6
dcantor Convert ASCII to Unicode or vice versa? Support 6
nikbackm Output of non-ascii characters via pipe Support 1
vefatica WAD TCC: inconsistent character handling Support 11
vefatica @INT with comma as decimal character Support 2
vefatica What's this character? Support 12
rps Regex problem: \xnn not recognized as a hex character Support 0
old coot Regex problem: \xnn not recognized as a hex character Support 12
L How to? Character transfer among @BALLOC buffers, command tails, and possibly redirected standard streams Support 11
D How to? Filenames with "&" character Support 3
samintz WAD Copy/append adds a character Support 3
B Fixed FFIND doesn't find last character in file without CR/LF at EOF Support 1
M I'm unable to use @replace[] with a % character in string2 Support 12
Exolon V17 beta, debugger: STRG-S is inserting character instead of saving Support 12
J Passing % character through command line to .btm Support 5
M Fixed character set in dir/copy Support 3
dcantor Fixed Ctrl+Shift+Insert repeats last character Support 3
D Copy to clip changes character Support 24
nickles Literal tab character Support 21
R One character alias prevents completion? Support 8
S Forum character encoding Support 2
M Escape-character issue... Support 7
vefatica @SUBST ... how replace character with a caret? Support 9
M Programmatically getting the console width in character Support 18
J How to pass a character like " " to a function Support 3
Jay Sage Dealing With Filenames Containing Slash Character Support 5
B A swedish character sent through keystack gets converted Support 4
nikbackm Alias expansion and switch character Support 2
A How to? TEE - duplicate output to STDERR Support 3
FreezerBurnt ANSI Prompt messes up list output. Support 39
Ó Recent git output not shown on TCC Support 1
Peter Murschall TEE cannot handle Unicode output Support 2
C TEE command appending null characters to output Support 6
Jesse Heines webform output different in ver. 26 than ver. 25 Support 2
vefatica Piping the output of a DO loop. Support 4
vefatica TCMD output invisible on Win10 Support 22
B How can TCC make an output as a part of command string Support 2
Enigma Take Command 23 duplicates output Support 0
Joe Caverly Works with CMD.EXE, no output with TCC.EXE Support 7
S Output from debugger Support 4
M TCC incorrect dir output since Windows 1803 Support 6
A WAD Output redirection to IF block fails with "unbalanced brackets" Support 7
P Scrollable colored output Support 3
scottb How to? ipconfig output in current window Support 4
David McClelland TEE command puts it's output file in c:\ Support 4

Similar threads