Thread: how so i blink my text?

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    philippiines
    Posts
    10

    how so i blink my text?

    Hi! there!

    Can someone help me in this. Is it possible to make my text blinking? if it is, How do I can?

    tnx!!!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What? Blinking? Ugh!

    Not in standard C++ anyway. You need platform-specific functionality. For POSIX, look for ANSI escape codes. There's a special escape sequence. For Win32 consoles, I don't think it's possible. And of course, if you use a GUI, you use a timer and show and hide the widget that shows the text.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I seem to remember old Windows 98 DOS terminals supporting blinking, but I might be imagining it. I think it would also be less likely to work on newer terminals.

    You could always try the ANSI escape sequence, as CornedBee mentioned. http://ascii-table.com/ansi-escape-sequences.php

    But personally, I hate blinking text. It's far more trouble than it's worth, and what's more, it's extremely annoying.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I agree, blinking text is a pain in the eyes.

    If you still insist of using blinking text, this is relatively portable [but limited to one line of text].

    Code:
    #include <stdio.h>
    #include <windows.h>  // Or other include file for "sleep" function. 
    
    int main()
    {
       const char *msg = "Hello, World";
       int i;
       for(i = 0; i < 10; i++)
       {
          printf("%s\r", msg);
          Sleep(100);
          // replace with Suitable "sleep" function if needed... 
          printf("%*s\r", strlen(msg), "");
       }
       return 0;
    }
    This will work on Windows with a 32-bit compiler - on Linux you'd probably want usleep(100 * 1000). Other OS's have other "do nothing for x amount of time.

    --
    Mats
    Last edited by matsp; 01-12-2009 at 05:43 PM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That's a good idea, actually -- but it doesn't let you, for example, receive user input at the same time. (e.g., you can't display something like "Enter your name, LAST NAME FIRST" where part of the message is blinking, and then get the user to enter their name at the same time.)

    Of course, you could simulate blinking text in this way if you had a way to detect whether keyboard input was entered and a way to get user input without requiring enter to be pressed. And a way to position the cursor on the screen.

    Sounds like you'd be better off going with ncurses or something at that point.

    One last note -- sometimes it can look weird to have the cursor at the beginning of a line of text, so I like to print the \r only when you're erasing the text. (Oh, and you're missing a few characters at the end of the second printf() line, but I think we can extrapolate what they are. )
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ah, yes, simple typo fixed, and it was more to show the principle rather than an attempt to make the best possible code for this purpose.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Banned
    Join Date
    Jan 2009
    Posts
    30
    Dear clique,

    I would like to inquire as to which operating system you are utilizing for your project. There are some OS specific ways to do something more like what Mr. dwks was asking about. It is possible to demonstrate blinking text whilst awaiting user input. However, such feats are beyond the standard and probably always will be since the utility of such functionality is extremely limited for most application programming needs.

    -sphynxster

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM