UTF-8 Chars in console mode || Way to convert a short to a char

This is a discussion on UTF-8 Chars in console mode || Way to convert a short to a char within the C++ Programming forums, part of the General Programming Boards category; I'm losing an unbelievable amount of time finding the right Hex and Dec codes to write "\x82" or char(178) for ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    2

    Question UTF-8 Chars in console mode || Way to convert a short to a char

    I'm losing an unbelievable amount of time finding the right Hex and Dec codes to write "\x82" or char(178) for example, so the right characters can be displayed correctly in the console.

    Isn't there any way to simply switch the console in UTF-8 mode?

    I am programming in French and I have to use a lot of accents.




    I also have another problem.
    I am now programming a game of minesweeper in console mode.
    The way it works is that I am using an array of structures.


    Code:
    struct table
    {
            short number ; // Mine = 9, empty square = 0, other than that, 1 to 8
            char char_ ;      // Char displayed in the grid of the mine sweeper
    
            int x,		//Used to display in the console
    	     y ;
    } ;

    The tests done when the player performs an action on a square are done using the char_ variable.
    At the beginning of the game, all char_ are initialized to the char displayed when the square is covered.
    So, when someone "clicks" (I use the keyboard to play), I must change the content of char_ in order do display the square as uncovered (blank), with a number or with a mine.
    The problem comes when the player clicks on a number, I have to change the value char_ for the value of number_ in order to display the right number.

    So, I must do something like

    tabMineSweeper[x][y].char_ = someconvertingfeature(tabMineSweeper[x][y].number) ;

    So, I need a simple way to convert a short to a char.
    I could use switch or ifs but it will make my code uselessly long.
    Is there any way to do that?

    Thanks!


    ---Edit---
    I am not used with :: that I see everywhere in almost every code sample (std::sting for example)... so if anyone could explain without using these it would be great. Thanks <3
    Last edited by Pinkfish; 10-22-2008 at 08:01 PM. Reason: I love watermelons.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You may not like ::, but it's not as though C++ works without them.

    Anyway, do you mean you need to convert 5 into '5'? Provided you know it's a single digit (which, if it's minesweeper, you should), you can do char = short + '0'.

    As to the console changing, it depends on the OS. I don't know how to do it, and I don't believe it can be done once the console is running, but I will gladly let someone prove me wrong.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    2
    Quote Originally Posted by tabstop View Post
    You may not like ::, but it's not as though C++ works without them.

    Anyway, do you mean you need to convert 5 into '5'? Provided you know it's a single digit (which, if it's minesweeper, you should), you can do char = short + '0'.

    As to the console changing, it depends on the OS. I don't know how to do it, and I don't believe it can be done once the console is running, but I will gladly let someone prove me wrong.

    Thank you very much, it seems to work (no error!)

    <3<3<3<3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading string one character at a time.
    By mkthnx001 in forum C++ Programming
    Replies: 10
    Last Post: 06-14-2009, 03:18 PM
  2. strcat - cannot convert char to const char
    By ulillillia in forum C Programming
    Replies: 14
    Last Post: 12-07-2006, 10:00 AM
  3. Error
    By Kaho in forum C Programming
    Replies: 5
    Last Post: 08-19-2005, 02:56 AM
  4. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 02:13 PM
  5. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 10:14 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21