Blink and color text using textcolor ()

While executing the below code, I expected to get the PLAYER MENU string in red and blinking mode. However, I do not get so. Please help me as I need to get this code ready ASAP.

Note : Have tried textattr () function as well. I'm using Turbo C++ Version 3.0.

PS : Sorry for posting such a long code for such a minor error. Thank you for your time and energy.


See this code:

void menu ()
{
int x1, y1, x2, y2, x3, y3;
char choice;
textcolor (YELLOW);
textbackground (0);
do
{
clrscr ();
disptime ();
cout << " ";
x1 = wherex ();
y1 = wherey ();
for (int i = 1; i <= 55; i ++)
cout << "_";
x2 = wherex () - 1;
y2 = wherey ();
gotoxy (x1, y1 + 1);
cout << "|";
gotoxy (x2, y2 + 1);
cout << "|";
gotoxy (x1, y1 + 2);
cout << "|";
gotoxy (x2, y2 + 2);
cout << "|";
gotoxy (x1, y1 + 3);
cout << "|";
textcolor (RED + BLINK);
cout << " PLAYER MENU";
textcolor (YELLOW);
gotoxy (x2, y2 + 3);
cout << "|";
gotoxy (x1, y1 + 4);
cout << "|";
gotoxy (x2, y2 + 4);
cout << "|";
gotoxy (x1, y1 + 5);
cout << "|";
cout << " (1) Enter new player";
gotoxy (x2, y2 + 5);
cout << "|";
gotoxy (x1, y1 + 6);
cout << "|";
cout << " (2) Update player details";
gotoxy (x2, y2 + 6);
cout << "|";
gotoxy (x1, y1 + 7);
cout << "|";
cout << " (3) Modify player details";
gotoxy (x2, y2 + 7);
cout << "|";
gotoxy (x1, y1 + 8);
cout << "|";
cout << " (4) Search player";
gotoxy (x2, y2 + 8);
cout << "|";
gotoxy (x1, y1 + 9);
cout << "|";
cout << " (5) Delete player";
gotoxy (x2, y2 + 9);
cout << "|";
gotoxy (x1, y1 + 10);
cout << "|";
cout << " (6) Hourly Lucky Draw";
gotoxy (x2, y2 + 10);
cout << "|";
gotoxy (x1, y1 + 11);
cout << "|";
cout << " (7) Silver Club Championship";
gotoxy (x2, y2 + 11);
cout << "|";
gotoxy (x1, y1 + 12);
cout << "|";
cout << " (8) Instruction manual";
gotoxy (x2, y2 + 12);
cout << "|";
gotoxy (x1, y1 + 13);
cout << "|";
cout << " (9) System Settings";
gotoxy (x2, y2 + 13);
cout << "|";
gotoxy (x1, y1 + 14);
cout << "|";
cout << " (0) Exit";
gotoxy (x2, y2 + 14);
cout << "|";
gotoxy (x1, y1 + 15);
cout << "|";
gotoxy (x2, y2 + 15);
cout << "|";
gotoxy (x1, y1 + 16);
cout << "|";
cout << " Enter your choice here :- ";
x3 = wherex ();
y3 = wherey ();
gotoxy (x2, y2 + 16);
cout << "|";
gotoxy (x1, y1 + 17);
cout << "|";
gotoxy (x2, y2 + 17);
cout << "|";
gotoxy (x1, y1 + 18);
cout << "|";
gotoxy (x2, y2 + 18);
cout << "|";
gotoxy (x1, y1 + 19);
cout << "|";
gotoxy (x2, y2 + 19);
cout << "|";
gotoxy (x1, y1 + 20);
cout << "|";
gotoxy (x2, y2 + 20);
cout << "|";
gotoxy(x1, y1 + 20);
for (i = 1; i <= 55; i ++)
cout << "-";
gotoxy (x3, y3);
choice = getche ();
switch (choice)
{
case '1' : newplayer ();
break;
case '2' : update ();
break;
case '3' : break;
case '4' : break;
case '5' : break;
case '6' : break;
case '7' : break;
case '8' : break;
case '9' : break;
case '0' : break;
default : gotoxy (x1 + 1, y1 + 18);
cout << " Invalid choice. Try again!!!";
getch ();
}
} while (choice != '0');
}

Comments

  • try using cprintf instead of cout... cprintf("|");

    if the program is run in an emulated window (2k, xp, vista, etc), then you may get goofy output as these functions were designed for the text mode screen.
  • I tried it mate. Some weird characters are coming in the line of 'PLAYER MENU'. Thanks for you time.
  • the weird char is probably the tabs in the strings.

    If you need or want to draw a border around your menu, check your docs for charset codes. I can't recall all of them now, but there are some for making two or three different box styles... it may depend on your keyboard layout though.

    If you don't have the docs, just use a loop to cycle through them

    [code]
    unsigned i;

    for(i=128; i < 256; i++) {
    printf("0x%2X %c
    ", i, i);
    }[/code]

    Something like that.
  • What are tabs in the strings?
  • I'm thinking the odd character is the you've got in the strings; it's probably printing the character mapped to 0x09.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories