Thread: Blinking???

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    11

    Blinking???

    How do I make a line blink, as if it were an alert?? I know the getch() bit to stop the blink, I just don't know how to mak eit blink???
    Ilan

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    getch()

    Presto, a blinking line.

    Are you trying to do something with visual appeal? Something that looks like it's pulsating?

    P.S more code, with tags, what compiler
    The world is waiting. I must leave you now.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    ok...so I want the program to alert the user if a certain event happens....

    if(amount[count] <= optimal[count]/4)
    printf("Warning. Supply of %s is getting low.", products[count]);
    getch();

    something in the lines of that, but instead of just printf...I want a blinking affect??

    Ilan

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This is implementation specific. You could use ANSI escape codes, a Borland compiler and some of their functions (I believe so anyway), ncurses in linux will do this I think, or some Windows programming.

    Again, this all depends on your specific application / implementation.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    I was personally thinking that he might've wanted to do something you could only do with graphics / allegro ( animated text ).
    The world is waiting. I must leave you now.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Shadow
    I was personally thinking that he might've wanted to do something you could only do with graphics / allegro ( animated text ).
    That very well may be. It's not like he was pinpoint specific on his requirements or problem description.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    11
    This is all very ell and good and I understand the idea, but practically, how do you write it out?? like printf....or something along those lines?

  8. #8
    Unregistered
    Guest
    First, you will need to position your printf's. You need to have a header file that will allow you to do this (I know VC++ has one, I use a school made one). After this, you put your code in a loop.

    keep in mind I'm doing this off the top of my head
    Code:
    while(1)
    {
        xya(1,1);//cursor positioning
        printf("Your blinking message);
        cls();//premade clearscreen in my header file
    }
    This will loop it, you'll need to make something to stop the loop obviously, and something to slow it down. As it is like this, it will blink, but probably so fast it will just look grey.

  9. #9
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    /*
    
    	Program:
    	AnimText.c
    	
    	Purpose:
    	Demonstrates how to make text "flash".
    
    */
    
    #include <stdio.h>
    #include <time.h>
    #include <windows.h>
    
    void clrscr(void);
    
    int main(void)
    {
    	while(1)
    	{
    		printf("Warning. Supply of %s is getting low.", products[count]); 
    		sleep(150);
    		clrscr();
    		sleep(150);
    		clrscr();
    	}
    	return 0;
    }
    
    void clrscr(void)
    {
        	COORD coordScreen = { 0, 0 };
        	DWORD cCharsWritten;
        	CONSOLE_SCREEN_BUFFER_INFO csbi;
        	DWORD dwConSize;
        	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
        	GetConsoleScreenBufferInfo(hConsole, &csbi);
        	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        	FillConsoleOutputCharacter(hConsole, TEXT(' '), 
        	dwConSize, coordScreen, &cCharsWritten);
        	GetConsoleScreenBufferInfo(hConsole, &csbi);
        	FillConsoleOutputAttribute(hConsole, csbi.wAttributes, 
        	dwConSize, coordScreen, &cCharsWritten);
        	SetConsoleCursorPosition(hConsole, coordScreen);
    }
    Does this help?
    Did you get this figured out even?
    The world is waiting. I must leave you now.

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    31

    asdf

    you could try this:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    
    void warning(char *string, int flash, long speed);
    void sleep(long milli);
    
    int main(void)
    {
       warning("coffee", 50, 90);
    
       return 0;
    }
    
    void warning(char *string, int flash, long speed)
    {
       char warningMsg[50];
       int  bspace;
       int  i;
    
       sprintf(warningMsg, "Warning. Supply of %s is getting low.", string);
    
       bspace = strlen(warningMsg);
       speed /=2;
       
       while(flash--)
       {
          printf("%s", warningMsg);
          sleep(speed);
          for(i = 0; i < bspace; ++i)
          {
             printf("\b \b");
          }
          sleep(speed);
       }
       printf("%s", warningMsg);
    }
    
    //thanks Prelude for this
    void sleep(long milli)
    {
       //djgpp clocks per sec 91
      //msvc++ clocks per sec 1000
    
      clock_t current = clock();
      clock_t end;
    
      for(end = current + milli; current < end; current = clock());
    }
    you might need to modify it a bit.
    Last edited by CtrlAltKick; 05-16-2002 at 02:10 PM.

  11. #11
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    50 milliseconds. Fast.
    The world is waiting. I must leave you now.

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    31
    yeah, kind of slow when compiled with djgpp. just bring it up a notch if using msvc or something else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. blinking output
    By wanex in forum C++ Programming
    Replies: 7
    Last Post: 03-26-2006, 06:02 AM
  2. Darned Blinking Cursor
    By VOX in forum C Programming
    Replies: 18
    Last Post: 11-23-2004, 06:36 PM
  3. blinking cd-rw
    By lambs4 in forum Tech Board
    Replies: 8
    Last Post: 11-07-2003, 10:52 AM
  4. blinking cursor
    By dP munky in forum Game Programming
    Replies: 6
    Last Post: 02-15-2003, 11:21 PM
  5. blinking not even winking
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-05-2001, 01:41 PM