Blinking Statement Program C/C++


Hey guys, in this article, we will explore how we can make this.

We will use the below way to make it. 

  1. Using the in-build function.
  2. Using Logic

1. Using in-build function

As we know in "conio.h" header file is having lots of predefined methods, textcolor() is one of them, which helps to make this.

prototype:

void textcolor(int newcolor);
  • textcolor selects the foreground character color.
  • in parameter, we have to use Symbolic color constants, which is an integer type,
note: To use this method you need to use cprintf() methods.
           remember don't use whitespace like :\n \r \t etc in cprintf() method.

screen-short of Symbolic Color constants

in the above screenshot,  constant and value, so in parameter, we have to write value according to our need.

Example

If we want to display the statement with blue foreground color, then

            #include<conio.h>
            #include<stdio.h>
          
            int main()
            {
               clrscr();
                 textcolor(1);// here 1 is a value for blue color
                  cprintf("My name is Abdul Rizwan");
               getch();
          }
     

   so I hope now you understood how to use this textcolor() method,


Now to blink the statement


#include<stdio.h>
#include<conio.h>

void main()
{
  clrscr();
   textcolor(128+6); // or textcolor(134) [128:blinking and 6:brown color]
   cprintf("My Name is Abdul Rizwan");
  getch();
}

here 128 has been used because this is the value for blinking and 6 is used for brown color.


this will show you this statement with blinking.



Using Logic

It's very easy only blink a statement, 

       #include<stdio.h>
       #include<conio.h>
       #include<dos.h> //we need to add this header file becs we are using sleep() method.
     
      void main()
     {
        for(int i=1;i<=15;i++) //15 time statement will blink
         {
             clrscr();   //clear the screen
             sleep(1);//wait for a second
             printf("My name is Abdul Rizwan"); //print this statement on screen.
            sleep(1); //wait for a second 
          }
     }

run this program and see, statement will blink 15 times. Thanks

Comments

  1. how to create the snake game in c++

    ReplyDelete
  2. very nice sir.....
    I want to know that how to make andriod developer or android apk..
    plz sir you answer ..i wait for your answer...... thanks

    ReplyDelete

Post a Comment