Hi! there!
Can someone help me in this. Is it possible to make my text blinking? if it is, How do I can?
tnx!!!
Hi! there!
Can someone help me in this. Is it possible to make my text blinking? if it is, How do I can?
tnx!!!
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
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.
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].
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.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; }
--
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.
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.
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.
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