Help with ASCII "C"

Hello again.. I wrote a game and I use some of these symbols "220, 221, 222, 223, 219, 17, 2.... etc" in the code with the 'printf()' function like this:

1
2
3
4
5
6
7
8
9
10
printf("%c", 220);
//or
printf("%c", 219);
//or
printf("\17");
//or
printf("\2");
.
..
... // and so on. 


The problem is that I try this game on other pc and with different windows and I see ";" or "?".. etc.. instead of symbols I used in the game.
My question is: Do I have to set the console to some page like:

1
2
3
4
5
6
7
8
   system("chcp 437"); // which set font to "raster font"
   /*
   for (int i=0; i<255; i++)
   {
      printf("%c", i);
      if (i%25==0) printf("\n");
   */
   }


to actually display correctly the symbols in the console ?

which uses extended ASCII..
Last edited on
When I use the system("chcp 437") in console I see actually this line
Active code page: 437
Well for starters you need to realize that a char is a signed char on most systems. Which means using anything larger than 127 or smaller that -127 produces undefined behavior.

Second, "\2" is an escape sequence, so I really don't know what you're trying to accomplish there.

Third, "extended" ASCII is implementation defined, and really can't be relied on to produce your desired results. If you want to reliably print your "graphic" characters I suggest you look into using the proper Unicode characters.
Hello jlb... I know char is between -127 and 127 that's why I though using
system("chcp 437") will allow to extended ASCII to 255.

Well.. for your
Second, "\2" is an escape sequence, so I really don't know what you're trying to accomplish there.
is the same if I write:

printf("%c", 2); and it is the same thing printf("\2") produces the same symbol, I mean is the same character. You should try it and see the result. Because these escape sequences I used in my game otherwise all that I printed will look something like "?" or ";" or "$" etc..., which is an undefined behavior.

And that's why I asked the forum.. or maybe if you know how to use proper the Unicode characters and understand my question, and I believe you DID understand it.. a great answer would be more like:

Yes man, setting the system chcp 437 would never solve your problem cause that is not what you though it means.

OR

No man, this problem you can solve it by doing this and that..

Since I'm a beginner and try to finish my game with the knowledge I have until now and I arrived to a point that using my code to different OS, I saw what happen and that's why I post my problem. I am not perfect, but I know how is to have a problem and want to solve it, understand it, but I rather read the problem and if I am not sure about it and don't know the answer.. better to not share.
Everything about you said in your post I already know. Why I can have a short answer ?

However thank you for your answer. I appreciate it and I'll look forward how to proper use Unicode characters.
is the same if I write:

No, not really. The escape sequence may cause something different to be outputted.

Hello jlb... I know char is between -127 and 127 that's why I though using
system("chcp 437") will allow to extended ASCII to 255.


But you should be using an unsigned char, not a char if you want to store that value in a variable.

I appreciate it and I'll look forward how to proper use Unicode characters.

I suggest you get to researching that topic. Good luck.

Edit: I also suggest that you post the question in the Windows section since it is a Windows problem, not a C++ problem.
Last edited on
Well.. Now you see what I meant jlb ? As you said in your second post:
But you should be using an unsigned char, not a char if you want to store that value in a variable.
, actually you gave me the response to my problem and a great hint..
because 'char' is signed, I did create a variable 'unsigned char ch;' and now the 'ch' value is between 0 and 255, then I set this ch = 2and now when I use this in my code
printf(%c", ch)
OR
printf("%u", (unsigned int) ch)
and add the explicit type cast, actually works and works even on other OS too.
What I mean is.. I am not upset with no one and I apologies .. don't take it personally but instead if you'd give me that possible answer to my op for the first time, wouldn't be so much waste of virtual ink.

Edit: I also suggest that you post the question in the Windows section since it is a Windows problem, not a C++ problem.

I did mention on my question "C" not "C++" ya I know still a windows problem.

Thanks again ...
Last edited on
Topic archived. No new replies allowed.