Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Clear TTY

rootroot Member Posts: 103
hi can someone help me with some C code to clear the tty?
in borland c its clrscr(); but not in gcc any ideas ??
thanks,
ed.

Comments

  • IDKIDK Member Posts: 1,784
    : hi can someone help me with some C code to clear the tty?
    : in borland c its clrscr(); but not in gcc any ideas ??
    : thanks,
    : ed.
    :
    It's not ansi, so it's not possible with gcc.

    You'll need to use a library.
    ncurses is the most used and best one.
  • nugentnugent Member Posts: 87
    : hi can someone help me with some C code to clear the tty?
    : in borland c its clrscr(); but not in gcc any ideas ??
    : thanks,
    : ed.
    :

    this is possible without ncurses if your terminal supports control sequences (and most do). a control sequence is just a string that when printed to stdout is interupted by the terminal and an action is performed. control sequences begin with the ESC char and a left square braket ([).

    some useful codes are
    nA - move the cursor up n rows
    nB - move the cursor down n rows
    nC - move the cursor right n columns
    nD - move the cursor lieft n columns
    nJ - clear part of screen (n=0: to end of screen, n=1: beginning of screen, n=2: entire screen)

    there are others for setting foreground / background colours etc.

    you must clear the screen and move the cursor, so here is the code

    [code]
    #include

    int main()
    {
    printf("33[60A"); /* move the cursor up 60 lines, change 60 to what ever number of rows your terminal has */
    printf("33[2J"); /* clear entire screen */

    return 0;
    }
    [/code]

    ------
    nugent



Sign In or Register to comment.