1

When I compile the code below, using NetBeans, the output of the program is some strange characters in the terminal (teste á é õ). Unfortunately I could not find the solution for this.

Has anyone experienced this? Know the solution?

#include <stdio.h> 
#include <locale.h> 

int main(int argc, char** argv) { 
setlocale(LC_ALL,""); 
printf("teste á é õ"); 
return (0); 
} 

My compiler is MinGW, my native language is Brazilian Portuguese.

sample configuration and versions

output:

output

Renato
  • 345
  • 1
  • 5
  • 14
  • 2
    For the record, “é” is a *UTF-8* “é” misinterpreted as *ISO-8859-1*. See for example this article: [Why does “é” become “é”?](http://www.weblogism.com/item/270/why-does-e-become-a) – gx_ Nov 29 '13 at 11:13
  • so basically, your program outputs UTF-8 data, but your terminal is set to use encoding iso8859-1 – codeling Nov 29 '13 at 11:15
  • In Dev-C++ code above works perfectly. How do I fix this? I have to configure Windows Terminal or willing to set the output terminal in code? – Renato Nov 29 '13 at 11:39
  • Is this output shown in NetBeans console or Windows command line terminal? I think that NetBeans is capable of displaying only ASCII characters. For Windows console, see http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how – matejk Nov 29 '13 at 14:06
  • Both. Unfortunately even with the CHCP 65001 worked. I will continue using the Dev-C + + ;/ – Renato Nov 29 '13 at 14:36

2 Answers2

-1

They are not Ascii Characters.

ASCII characters 0-31 are various space characters and there is no standardized way to print them. This is an "extended ASCII table". There is no guarantee that those exact symbols will be printed on your particular platform.

They work fine for me in Windows 7, tested with GCC and Embarcadero C++, both print those symbols. But on another OS and/or compiler, different symbols or nothing at all might be printed.

Only ASCII characters 32 - 126 are guaranteed to be printable, and the same symbol, on all systems.

Gabson
  • 421
  • 1
  • 4
  • 20
  • I disagree. UTF8, for example, is also "guaranteed to be printable, use the same symbol, on all systems". Using the same definition for "guaranteed" and "all" -- there are 'systems' (software? computers? OS? mobile phones?) that do *not* use ASCII. – Jongware Nov 29 '13 at 15:26
-1

C++ is an English language and can only print the original ASCII code from English, some 3rd party libraries such as Curses let you get around this and print some non-ASCII ones found here: http://www.melvilletheatre.com/articles/ncurses-extended-characters/index.html

But for the most part, I can't see why you would want to print these characters since there is no practical purpose.

Other explanation: You can't do this since the original ASCII code consists of 127 types. Binary and stuff, different answer to the question, so just know their are only 127 possible letters allowed, more can be found here. enwikipedia.org/wiki/ASCII and williamrobertson.net/documents/ascii.html (This one gives you what can actually be printed by C++)

Drakon
  • 1
  • 1