Vinayak Risbud <vinayak_risbud at asiansonly.net>
> Kindly inform me how to clear the console of Linux using C .
Raf <turiel at RedBrick.DCU.IE>
> printf("\033[H\033[J\r\n");
Justin MacCarthy <<macarthy at iol.ie>
> It's been a while but I think... system(clear)?????
Ugh, ugh, ugh.
Clearing the screen should really be done in the context of a larger
terminal-management system. I seem to recall Vinayak asking earlier
questions concerning curses, so I presume that's what he's using. The
curses command to clear the screen is clear();
As with almost all curses functions, this function doesn't actually send
any data to the console - it puts it in the curses screen buffer, ready
to be written to the screen at next update (curses tries to minimise the
quantity of data which is written to the output stream, so it keeps an
internal image of what's currently on the screen, and what we want on
it, and only outputs diffs). To force an update of the screen, use the
curses function refresh();
Sample use in a curses program:
#include <curses.h>
WINDOW *stdscr;
int main(int argc, char *argv[])
{
/* Initialise curses, set up stdscr to point to the whole screen */
stdscr = initscr();
/* ... other curses code ... */
/* clear the screen and force an update */
clear();
refresh();
/* ... more curses code ... */
endwin();
return 0;
}
Hope this helps,
Colm
--
Colm Buckley BA BF | NewWorld Commerce, 44 Westland Row, Dublin 2, Ireland
colm at tuatha.org (personal) | colm.buckley at nwcgroup.com (business)
+353 87 2469146 | whois cb3765 | http://www.tuatha.org/~colm/
Never put off until tomorrow what you can avoid doing altogether.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!