Problem with displaying a character that has code number 219

Wojciech Sobiesiak 71 Reputation points
2023-01-09T09:01:29.71+00:00

Compiler is dev c++ 6.3 and OS is windows10
There is one problem with displaying a character that has code number 219. Console application doesn't display it but shows some blue lines instead at the end of string(and red at the begining).
At the begining it works fine, but after using "SetConsoleTextAttribute(console, 0x07);" (I assume) it starts to show this blue lines.
What is important is function "draw_cursor()".
I also send printscreen of output.

Output: problem.jpg
Code: problem.txt

http://infinityhost.cba.pl/problem.txt
http://infinityhost.cba.pl/problem.jpg

The code is:

include <stdio.h>

include <string.h>

include <conio.h>

include <windows.h>

include <iostream>

using namespace std;
char tab[10][30]; // an array of names
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // console handle

// placing cursor into new position
void gotoxy(short x, short y) {COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);}

// hiding cursor
void hidecursor(){
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(consoleHandle, &info);}

void draw_cursor(int pos){
SetConsoleOutputCP(850);
SetConsoleTextAttribute(console, 0x07);
int poz=2;

                for(int i=0;i<9;i++){  
                gotoxy(2,poz+i);  
                printf("%s",tab[i]);}     

                gotoxy(2,pos+2);  
                SetConsoleTextAttribute(console, 0x70);  

                // PROBLEM !!!!  
                // DOESN'T DISPLAY 219 CHARACTER BUT BLUE LINES  
                for(int u=2;u<18;u++){  
                gotoxy(u,pos+2);      
                printf("%c",219);     
                //cout<<(unsigned char)219; doesn't work also  
                }  

                //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  
                gotoxy(2,pos+2);  
                printf("%s",tab[pos]);}   

void draw_frame(){

                short start_x,start_y;  
                start_x=1;start_y=8;  
                // upper horizonttal  
                gotoxy(start_x,1);printf("%c",201);gotoxy(25,1);printf("%c",187);  
                for(int i=0;i<24;i++){gotoxy(i+start_x,1);printf("%c",205);}  
                gotoxy(start_x,1);  
                printf("%c",201);  
                // lower horizontal  
                gotoxy(start_x,1+10);  
                printf("%c",200);  
                gotoxy(25,1+10);  
                printf("%c",188);  
                for(int i=0;i<24;i++){gotoxy(i+start_x,1+10);printf("%c",205);}  
                gotoxy(start_x,1+10);  
                printf("%c",200);  

                for(int i=1;i<10;i++){gotoxy(start_x,i+1);printf("%c",186);gotoxy(start_x+24,i+1);printf("%c",186);}}  

void prepare_an_array(){ strcpy(tab[0],"Charlie");
strcpy(tab1,"John");
strcpy(tab2,"Mike");
strcpy(tab[3],"Robert");
strcpy(tab[4],"Thomas");
strcpy(tab[5],"Endriu");
strcpy(tab[6],"James");
strcpy(tab[7],"Lucas");
strcpy(tab[8],"Bradley");}

int main()
{

hidecursor();

char z;
int position=0;

prepare_an_array();
draw_frame();
draw_cursor(0);

do{
z=getch();

if(z!=27){  

    if(z==80 && position<8){position++;draw_cursor(position);}  
    if(z==72 && position>0){position--;draw_cursor(position);}}  

}while(z!=27);

return 0;
}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.5K Reputation points
    2023-01-09T10:58:56.987+00:00

    It is not clear why do you need the character 219, but maybe you can do this:

    void draw_cursor( int pos )  
    {  
        SetConsoleOutputCP( 850 );  
        SetConsoleTextAttribute( console, 0x07 );  
        int poz = 2;  
      
        for( int i = 0; i < 9; i++ )   
        {  
            gotoxy( 2, poz + i );  
            printf( " %-22s", tab[i] );  
        }  
      
        SetConsoleTextAttribute( console, 0x70 );  
      
        gotoxy( 2, pos + 2 );  
        printf( " %-22s", tab[pos] );  
    }  
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Wojciech Sobiesiak 71 Reputation points
    2023-01-09T11:07:54.697+00:00

    Why I do need 219 character? Because when I draw whole arrey of text (names in this case) I have white text and black background. When I draw a highlighted text the background should be white and text (the choosen name) black. And that is what happens. But I need all the text to the end of the frame to have white background.

    Yes Your solution works!!! :D

    Thank You very, very much.

    Can You explain me what was wrong in my version?

    Where from those red and blue lines come from?
    I may be forced to write some characters in the future, and it would be nice to know what I should do not.

    Have You seen the picture?