Line overwriting

Discussion in 'C Programming' started by Steven Jones, Feb 13, 2006.

  1. Steven Jones

    Steven Jones Guest

    I have a C program that prints out two lines as follows:

    Line 1
    Line 2

    What I would like is for this program to sleep for one second, and then
    print out two more lines, overwriting the previous two. The sleeping bit
    is trivial but, what about the overwriting? I am assuming that the output
    will be displayed on a standard terminal emulator, like xterm.
     
    Steven Jones, Feb 13, 2006
    #1
    1. Advertisements

  2. Allow me to be the first to say this - and I say it from the deepness of my
    heart, with all the kindness and love one has come to associate with the
    helpful posts you get in this newsgroup:

    Not portable. Can't discuss it here. Blah, blah, blah.
     
    Kenny McCormack, Feb 13, 2006
    #2
    1. Advertisements

  3. Steven Jones

    Lew Pitcher Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    printf("\r"); fflush(stdout);


    But, while this will work on most any display device (including hard copy
    devices), it is likely to leave output in a mess on most of them.

    - --
    Lew Pitcher
    IT Specialist, Enterprise Data Systems,
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed are my own, not my employers')
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (MingW32)

    iD8DBQFD8IgYagVFX4UWr64RAlVaAJsHIcbBegJsQf1pu669WsBbpAy1lwCg7RBb
    bdLqgwKLNM3qDtTvOeU10Vc=
    =tvu6
    -----END PGP SIGNATURE-----
     
    Lew Pitcher, Feb 13, 2006
    #3
  4. As already mentioned, this is off topic in this newsgroup. You might
    want to have a look at the NCURSES library.


    August
     
    August Karlstrom, Feb 13, 2006
    #4
  5. Steven Jones

    Eric Sosman Guest

    The question seems entirely topical: "How can I do _X_
    in C?" As it happens, the answer is either "You cannot"
    (for strict constructionists) or "You need facilities that
    are not part of C, but may be available as extensions on
    the platforms that interest you" (for people of a helpful
    bent). An *extremely* helpful person might even suggest a
    look at Questions 19.3 and 19.4 in the comp.lang.c Frequently
    Asked Questions (FAQ) list at http://c-faq.com/ -- but that's
    *really* going too far, and anyone who did so would be rightly
    castigated.

    See also "praeterition."
     
    Eric Sosman, Feb 13, 2006
    #5
  6. Given that he wants to overwrite both lines with two new lines[*], the
    above solution won't work.

    This comes down to the need to use some sort of extension, perhaps the
    curses library, in order to do it. The use of curses (or any other
    library which may perform this function) is OT in clc. I'm not sure
    where curses is topical.


    [*] As opposed to "two newlines". :)

    --
    +-------------------------+--------------------+-----------------------------+
    | Kenneth J. Brody | www.hvcomputer.com | |
    | kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
    +-------------------------+--------------------+-----------------------------+
    Don't e-mail me at: <mailto:>
     
    Kenneth Brody, Feb 13, 2006
    #6
  7. Steven Jones

    Steven Jones Guest

    You guys are right: This is off-topic in this group. I realized shortly
    after posting; my apologies. Anyway, in case anyone is interested, on an
    xterm terminal emulator the effect can be achieved with

    printf("\x1b[2A") ;

    just before (or after) the sleep() call.
     
    Steven Jones, Feb 13, 2006
    #7
  8. Steven Jones

    CBFalconer Guest

    Whatever an "xterm emulator" may be, that code won't work unless
    the destination falls in the class of ANSI standard CRT terminals
    (which are OT here). These are only one of many possible terminal
    types, and are the reason why such things as termtype and curses
    (both also OT here) were invented.

    --
    "The power of the Executive to cast a man into prison without
    formulating any charge known to the law, and particularly to
    deny him the judgement of his peers, is in the highest degree
    odious and is the foundation of all totalitarian government
    whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
     
    CBFalconer, Feb 13, 2006
    #8
  9. Steven Jones

    Flash Gordon Guest

    As Eric Sosman said, the question is on topic, it's just that the answer
    is that you need something beyond standard C.
    For increased portability look at the various screen handling libraries
    such as Curses as others have suggested.
    --
    Flash Gordon
    Living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidlines and intro -
    http://clc-wiki.net/wiki/Intro_to_clc
     
    Flash Gordon, Feb 13, 2006
    #9
  10. This is a FAQ - search for entries relating to in-situ altering of
    files - but essentially you can't do this in standard C.
    Mark McIntyre
     
    Mark McIntyre, Feb 18, 2006
    #10
  11. I think he's trying to overwrite text on the display, not data in a
    file. (You can't do that in standard C either.)
     
    Keith Thompson, Feb 18, 2006
    #11
  12. Yes, indeed. I see that on rereading it. Its still a FAQ tho - a
    search for gotoxy will turn up 19.4



    Mark McIntyre
     
    Mark McIntyre, Feb 19, 2006
    #12
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.