How to blink particular text continuously all time during input and output?

udit043 picture udit043 · Jul 7, 2015 · Viewed 15.8k times · Source

Here is my code which blinks 'Welcome' after user enter his name.

'Welcome' does not blink when user is writing his name. As user hits enter then caret goes into the while loop. Then caret position is set back to the coordinates of 'Welcome' & cout prints 'Welcome' with 5 colors again & again so it seems that 'Welcome' is blinking.

But I want that 'Welcome' blinks continuously as the program starts.

So more likely this question also ask - can we have two caret/cursor at the same time ?

#include <iostream>
#include <conio.h> 
#include <windows.h>
 using namespace std;
 int main(int argc, char** argv)
 {
   int x,y,i;char name[10];
   textcolor(10);
   x=wherex();y=wherey();       //corrdinates of caret will be stored in x & y.
   cout<<"\t\t\t\tWelcome\n";
   textcolor(15);
   cout<<"\nEnter your name\n";
   gets(name);
   while(1)
   {
      for(i=10;i<15;i++)
      {
         textcolor(i);
         gotoxy(x,y);          //Transferring caret to the coordinates stored in x & y.
         cout<<"\t\t\t\tWelcome";
         Sleep(300);
      }
   }
   return 0;
 }

Answer

udit043 picture udit043 · Nov 13, 2015

I wrote a small code for this question , it's not 100% correct answer. I am just posting this answer just for giving little bit idea to newbie.

#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
int x,y,b,l,n=0;
char c;
void blink()
{
    {
        int m;
        for(m=10;m<15;m++)
        {
            textcolor(m);
            gotoxy(x,y);
            cout<<"\t\t\t\tWelcome";
            Sleep(60);
        }
   }
}
int main(int argc, char** argv)
{
   char i;int key_stroke;
   textcolor(10);
   x=wherex();y=wherey();
   cout<<"\t\t\t\tWelcome\n";
   textcolor(15);
   cout<<"\nEnter your name\n";
   l=wherex();b=wherey();
   z:
   {
     while (1)
     {
          if(!(_kbhit()))
        {
               blink();
                 goto z;
        }
        else 
          {
             i=_getch();
             if(i==13)
             {
                gotoxy(l+n,b+1);
                    return 0;
               }
               textcolor(10);
               gotoxy(l+n,b);
               cout<<i;n=n+1;
          }
     }
   }
   return 0;
}