HI, I want to Display an output in C for a limited amount of time and then make it disapear. Any ideas how to do it ? Thanks
HI, I want to Display an output in C for a limited amount of time and then make it disapear. Any ideas how to do it ? Thanks
From experimenting, there is a time.h library that can be used to basically count in seconds or whatever by using, what i think, is your cpu clock (please correct me if im mistaken, lol)
But here is a quick referance for it, hope it helps ^_^
ctime (time.h) - C++ Reference
I didn't see though anything concerning displaying the output for a time period and then taking it off.
Maybe make a print statement with a bunch of carrige returns after the data you want shown disappears?
Sorry, I have no idea, but hope that gets you started in the right direction ^__^
"output" is a very general term. Do you mean output to the console? Or to a gui window? What OS are you using?
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
Do you know any way to clear the screen? That is essential to your goal.
It depends on what you mean by "disappear" too.
For example, by disappear, do you mean the whole content of the terminal screen being cleared? A simple way to achieve that is to output a bunch of newlines ('\n') until the previous output scrolls off the top of the screen. Or do you just mean that a specific line is overwritten somehow?
There are no universal techniques. If you are using a particular API to produce the original output (for example, win32 console functions, or curses under unix) then you need to look up techniques that involve the same API.
If you are just writing directly to stdout or stderr, you might get away with the following. A backspace character ('\b') moves the cursor one left, a space character (typically) will overwrite any character at the cursor location and move one right, a return ('\r') will move to the left margin without a newline. As long as you keep the cursor on the same line as the output you want to overwrite, and keep track of how many characters you have written to that line, combinations of backspace, return, and space characters can be used to selectively overwrite that output. All bets are off with this technique if you have outputted a newline, as there is no general way from vanilla C to move the cursor up one line. Note that this technique is also affected by configuration settings of the display itself (the display or, in your case, the ubuntu terminal window). It can also be upset if you mix up usage of stdout and stderr.
In time.h there is a structure "timeval" with arguments "tv_sec" and "tv_usec".
Use the gettimeofday() function to get the time value into the above variables.
After this maybe u could track the value of time using a temprory variable and a loop and use the idea grumpy gave to make output dissapear.
hope this helps.
Gaurav