Like Tree1Likes
  • 1 Post By grumpy

Display output for a limited time

This is a discussion on Display output for a limited time within the C Programming forums, part of the General Programming Boards category; HI, I want to Display an output in C for a limited amount of time and then make it disapear. ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    4

    Question Display output for a limited time

    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

  2. #2
    Registered User
    Join Date
    Feb 2012
    Location
    Albuquerque, New Mexico, United States
    Posts
    7
    Quote Originally Posted by Vixxx View Post
    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

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    I didn't see though anything concerning displaying the output for a time period and then taking it off.

  4. #4
    Registered User
    Join Date
    Feb 2012
    Location
    Albuquerque, New Mexico, United States
    Posts
    7
    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 ^__^

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    "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

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Quote Originally Posted by oogabooga View Post
    "output" is a very general term. Do you mean output to the console? Or to a gui window? What OS are you using?

    I am now using the terminal in ubuntu.

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Do you know any way to clear the screen? That is essential to your goal.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,209
    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.
    Vixxx likes this.
    Right 98% of the time, and don't care about the other 3%.

  9. #9
    Registered User
    Join Date
    Feb 2012
    Posts
    9
    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

  10. #10
    Registered User
    Join Date
    Feb 2012
    Posts
    4
    Thanks .. that work

    Quote Originally Posted by grumpy View Post
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display size and time
    By spikestar in forum C Programming
    Replies: 5
    Last Post: 01-18-2010, 10:23 PM
  2. How to display output using puchar() only ???
    By spurs01 in forum C Programming
    Replies: 11
    Last Post: 11-13-2009, 02:53 AM
  3. output file display -- Need Help
    By boostpower in forum C Programming
    Replies: 2
    Last Post: 04-06-2006, 01:50 PM
  4. Help: Display time and date
    By stansu in forum C++ Programming
    Replies: 5
    Last Post: 08-22-2003, 02:27 PM
  5. Limited output
    By Ivan! in forum C++ Programming
    Replies: 7
    Last Post: 03-24-2003, 10:20 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21