- Joined
- Nov 24, 2022
- Messages
- 80
- Reaction score
- 7
Compiler is devc++ 6.3 and OS is windows10.
Application creates an array of names (tab), draw frame, fills it with this names, and according to user keypress moves cursor up or down.
But there is 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.
At the begining of this program, everything works fine, but after using "SetConsoleTextAttribute(console, 0x07);" or " SetConsoleOutputCP(852);" (I assume) it starts to show this blue and red lines at the begining of the string and at the end.
Output of draw_cursor should be beautiful white field from the begining of current name highlighted string to the end of frame.
What is important is function "draw_cursor()".
I also send printscreen of output.
#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(852);
SetConsoleTextAttribute(console, 0x07);
int poz=2;
for(int i=0;i<9;i++){
gotoxy(2,poz+i);
printf("%s",tab);}
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(tab[1],"John");
strcpy(tab[2],"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;
}
Application creates an array of names (tab), draw frame, fills it with this names, and according to user keypress moves cursor up or down.
But there is 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.
At the begining of this program, everything works fine, but after using "SetConsoleTextAttribute(console, 0x07);" or " SetConsoleOutputCP(852);" (I assume) it starts to show this blue and red lines at the begining of the string and at the end.
Output of draw_cursor should be beautiful white field from the begining of current name highlighted string to the end of frame.
What is important is function "draw_cursor()".
I also send printscreen of output.
#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(852);
SetConsoleTextAttribute(console, 0x07);
int poz=2;
for(int i=0;i<9;i++){
gotoxy(2,poz+i);
printf("%s",tab);}
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(tab[1],"John");
strcpy(tab[2],"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;
}