From: http://www.yesky.com/483/1800983.shtml
Source: only C world Author: responsible editor: Ark·Yesky comments (0)
Question: we often need to use clear screen processing when programming, such as CLS in DOS and clrscr () in Turbo C, however, these are general clear screens, and their clear screen rules are not displayed. Sometimes, in order to achieve the artistic appearance of the screen, there are some specific requirements for the screen, such as opening screen, Closing screen, supernatant screen, bottom screen, and center screen. Therefore, several sub-functions are compiled in C language. When used in a program, the screen can be cleared and the artistic appearance of the screen can be increased.
Sub-functions and demo programs:
# Include <stdio. h> # include <dos. h> # include <conio. h> void goto_xy (int x, int y); void DClS (INT X1, int X2, int Y1, int Y2); void bcls (INT X1, int X2, int Y1, int Y2); void kcls (INT X1, int X2, int Y1, int Y2); void recls (INT X1, int X2, int Y1, int Y2 ); void zcls (INT X1, int X2, int Y1, int Y2); void puta (void);/* -------------- demo program ------------------- */main () {puta (); getch (); DClS (,); getch (); puta (); getch (); bcls (,); getch (); puta (); getch (); zcls (,); getch () ;}/ ********* Center clear screen (center clear screen) * *********/void zcls (INT X1, int X2, int Y1, int Y2) {int x00, y00, x0, y0, I, d; If (y2-y1)> (x2-x1) {d = (x2-x1)/2; X0 = (X1 + x2)/2; Y0 = Y1 + D; y00 = y2-d; for (I = 0; I <(D + 1); I ++) recls (x0-i), (x00 + I), (y0-i ), (y00 + I); delay (10);} else {d = (y2-y1)/2; Y0 = (Y1 + y2)/2; X0 = X1 + D; x00 = x2-d; for (I = 0; I <D + 1; I ++) recls (x0-i, x00 + I, y0-i, y00 + I ); delay (10) ;}}/************* clear rectangle side (rectangular side clear screen) * ********************/void recls (INT X1, int X2, int Y1, int Y2) {int I, j; for (I = Y1; I <Y2; I ++) {goto_xy (x1, I); putchar (''); goto_xy (X2, i); putchar (''); delay (10) ;}for (j = x1; j <X2; j ++) {goto_xy (I, Y1 ); putchar (''); goto_xy (J, Y2); putchar (''); delay (10 );}} /******************* Open Screen clear (Open Screen clear) * ******************/void kcls (INT X1, int X2, int Y1, int Y2) {int T, S, I, j; t = s = (Y1 + y2)/2; for (; t <= Y2; t ++, s --) for (j = x1; j <X2; j ++) {goto_xy (J, T); putchar (''); goto_xy (J, S ); putchar (''); delay (10 );}} /**************** close screen clear ************ * *****/void bcls (INT X1, int X2, int Y1, int Y2) {int T, S, J; t = Y1; S = Y2; For (t = Y1; t <(Y1 + y2) /2; t ++, s --) for (j = x1; j <X2; j ++) {goto_xy (J, T); putchar (''); goto_xy (J, S); putchar (''); delay (10 );}} /******************* bottom screen clear (from bottom screen) * *****************/void DClS (INT X1, int X2, int Y1, int Y2) {int t, s, J, I; t = s = (Y1 + y2)/2; for (j = x2; j> x1; j --) for (I = Y1; I <Y2; I ++) {goto_xy (J, I); putchar (''); delay (10 );}} /***************** set the cursor subfunction ***************** */void goto_xy (int x, int y) {Union regs R; R. h. ah = 2; R. h. DL = y; R. h. DH = x; R. h. BH = 0; int86 (0x10, & R, & R );} /********************** a series of a letters are printed on the screen for the demo program ****** * ***********/void puta (void) {int I, j; for (I = 0; I <24; I ++) {for (j = 0; j <79; j ++) {goto_xy (I, j); printf ("");}}}