Nathan said:
Hi All,
To do something that requires clearing the screen and redrawing it
wouldn't you need to use a third-party library like ncurses or can you
still do it using just standard C?
Kind Regards,
Anthony Irwin
It's a FAQ:
19.4: How can I clear the screen?
How can I print text in color?
How can I move the cursor to a specific x, y position?
A: Such things depend on the terminal type (or display) you're
using. You will have to use a library such as termcap,
terminfo, or curses, or some system-specific routines, to
perform these operations. On MS-DOS systems, two functions
to look for are clrscr() and gotoxy().
For clearing the screen, a halfway portable solution is to print
a form-feed character ('\f'), which will cause some displays to
clear. Even more portable (albeit even more gunky) might be to
print enough newlines to scroll everything away. As a last
resort, you could use system() (see question 19.27) to invoke
an operating system clear-screen command.
References: PCS Sec. 5.1.4 pp. 54-60, Sec. 5.1.5 pp. 60-62.
Related FAQs:
19.5: How do I read the arrow keys? What about function keys?
A: Terminfo, some versions of termcap, and some versions of curses
have support for these non-ASCII keys. Typically, a special key
sends a multicharacter sequence (usually beginning with ESC,
'\033'); parsing these can be tricky. (curses will do the
parsing for you, if you call keypad() first.)
Under MS-DOS, if you receive a character with value 0 (*not*
'0'!) while reading the keyboard, it's a flag indicating that
the next character read will be a code indicating a special key.
See any DOS programming guide for lists of keyboard scan codes.
(Very briefly: the up, left, right, and down arrow keys are 72,
75, 77, and 80, and the function keys are 59 through 68.)
References: PCS Sec. 5.1.4 pp. 56-7.
19.6: How do I read the mouse?
A: Consult your system documentation, or ask on an appropriate
system-specific newsgroup (but check its FAQ list first). Mouse
handling is completely different under the X window system, MS-
DOS, the Macintosh, and probably every other system.
References: PCS Sec. 5.5 pp. 78-80.
19.10: How can I do graphics?
A: Once upon a time, Unix had a fairly nice little set of device-
independent plot functions described in plot(3) and plot(5).
The GNU libplot package maintains the same spirit and supports
many modern plot devices;
see
http://www.gnu.org/software/plotutils/plotutils.html .
If you're programming for MS-DOS, you'll probably want to use
libraries conforming to the VESA or BGI standards.
If you're trying to talk to a particular plotter, making it draw
is usually a matter of sending it the appropriate escape
sequences; see also question 19.9. The vendor may supply a C-
callable library, or you may be able to find one on the net.
If you're programming for a particular window system (Macintosh,
X windows, Microsoft Windows), you will use its facilities; see
the relevant documentation or newsgroup or FAQ list.
References: PCS Sec. 5.4 pp. 75-77.