How do we implement clrscr()? Googling it I found that \x1b[2j can be used to clear the screen but how do we use it?
How do we implement clrscr() ? Googling it I found that \x1b[2j can be
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The standard C library doesn’t provide a way of clearing the screen. You need an operating-system-dependent library for that.
Under DOS and Windows, for a program running in a DOS or Windows console, you can use the DOS/Windows extensions provided in the core C library shipped with the OS:
Under unix systems, you can use the curses library, which is provided with the OS. Ports of the curses library exist for most operating systems, including Windows, so this is the way to go in a portable program. Link your program with
-lcursesand useSome terminals and terminal emulators perform special functions such as clearing the screen when they receive an escape sequence. Most terminals follow the ANSI standard which defines a number of escape sequences;
"\x1b[2J"is such a sequence, and its effect is to clear the screen. Note the capitalJ. On such a terminal,fputs("\x1b[2J", stdout)clears the screen. This is in fact what the curses library does when you callerase()on such a terminal; the curses library includes a database of terminal types and what escape sequences to use on the various types.