/ * Read the character function from the keyboard: When pressing the ordinary key, return to its ASCII code scan code Code = 0 * /
INT INKEY (INT * CODE)
{
Int m;
While (! bioskey (1)) / * can join the number of nobles * /;
* code = bioskey (0);
m = * code * 255;
IF (! m) m = * CODE >> 8;
* Code = * code & 255;
Return M;
}
/ * Get machine date * /
Int Date (char * s, char type)
{
Char Dat [30];
Int Num;
Struct TM * TBLOCK;
Time_t t;
T = Time (NULL);
TBLOCK = LOCALTIME (& T);
STRCPY (DT, ASCTIME (TBLOCK));
STRCPY (S, ");
Switch (Type)
{
Case 'n':
Num = (* TBLOCK) .tm_year 1900;
ITOA (NUM, S, 10);
Break;
Case 'Y':
Num = (* TBLOCK) .tm_mon 1;
ITOA (NUM, S, 10);
Break;
Case 'R':
Num = (* TBLOCK) .tm_mday;
ITOA (NUM, S, 10);
Break;
Case 's':
STRCPY (DT, ASCTIME (TBLOCK));
MID (S, DT, 12, 8);
Break;
}
}
Return Num;
}
/ * Transform floating point numbers to strings * /
/ * Parameter Description Data: The number of floating point needs to be converted; S: Output string; len: The length of the conversion * /
Void f_to_s (Double Data, Char * S, INT LEN)
{
INT DEC, SIGN, I;
CHAR * S1, S2 [100], S3 [100];
S1 = 0;
S2 [0] = 0;
S3 [0] = 0;
S1 = FCVT (Data, Len, & Dec, & Sign);
IF (! Sign && Data> = 1)
{
MID (S2, S1, DEC 1, -1);
MID (S3, S1, 1, DEC);
STRCPY (S, " ");
STRCAT (S, S3);
STRCAT (S, ".");
STRCAT (S, S2);
}
IF (Sign && Fabs (DATA)> = 1)
{
MID (S2, S1, DEC 1, -1);
STRCPY (S, "-");
MID (S3, S1, 1, DEC);
STRCAT (S, S3);
STRCAT (S, ".");
STRCAT (S, S2);
}
IF (! Sign && Dec == 0)
{
STRCPY (S, " 0.");
STRCAT (S, S1);
}
IF (Sign && Dec == 0)
{
STRCPY (S, "- 0.");
STRCAT (S, S1);
}
IF (! SIGN && DEC <0)
{
STRCPY (S, " 0.");
For (i = 1; i <= fabs (dec); i )
STRCAT (S, "0");
STRCAT (S, S1);
}
IF (Sign && Dec <0)
{
STRCPY (S, "- 0.");
For (i = 1; I <= FABS (DEC); I ) STRCAT (S, "0");
STRCAT (S, S1);
}
IF (strlen (s)> len) s [len] = 0;
}
/ * Clear screen * /
Void Clsxy (int Color, int X, int y, int in)
{
INT X1, Y1;
Union regs r;
IF (x <1 || y <1) Return;
Y--
X-;
Y1 = Y YL-1;
X1 = x XL-1;
IF (Y1> 25 || x1> 80)
Return;
R.h.ah = 6; / * Sub function number * /
R.H.al = 0; / * Scroll line number * /
R.H.CH = Y;
R.H.Cl = x;
R.H.DH = Y1;
R.h.dl = x1;
R.H.BH = Color * 16;
INT86 (16, & R, & R);
}
/*display time*/
Void Display_time (int color, int back_color, int y, int x)
{
Static char Oldtime [9] = "";
Char newtime [9];
IF (Y <1 || x <1) Return;
SetTextStyle (1,0,1);
Data (NewTime, 's');
BACK_COLOR = 7;
IF (strcmp (newtime, oldtime))
{
SetFillStyle (1, back_color);
SetColor (Color);
BAR (535, 458, 635, 475);
OutTextxy (X, Y, NewTime);
STRCPY (OldTime, NewTime);
}
}
/ * Print a rectangle * /
Void Print_KJ (int X, int y, int wide, int high)
{
INT I;
For (i = x; i
{
Gotoxy (i, y);
Cprintf ("");
}
gotoxy (x, y high);
Cprintf ("");
GotoxY (X Wide, Y HIGH);
Cprintf ("");
gotoxy (x, y);
Cprintf ("");
gotoxy (x wide, y);
Cprintf ("");
For (i = x 2; i
{
gotoxy (i, y high);
Cprintf ("");
}
FOR (i = y 1; i
{
gotoxy (x, i);
Cprintf ("");
}
FOR (i = y 1; i
{
gotoxy (x wide, i);
Cprintf ("");
}
}
/ * Cut all spaces in the string * /
Void cut_all_spc (char * s)
{
INT I, N;
Char d [10000];
n = 0;
For (i = 0; i
IF (s [i]! = 32)
{
D [n] = s [i];
N ;
}
D [N] = 0;
STRCPY (S, D);
}
/ * Sub string * /
Void Mid (Char * S, Char * T, INT N, INT M)
{
INT I, J, P;
IF (n <1) n = 1;
I = Strlen (s);
IF (i
IF (m <0) m = i;
ELSE M = N M-1;
IF (m> i) m = i; p = m-n 1;
IF (p <0) P = 0;
For (i = n-1, j = 0; i
T [j] = s [i];
T [P] = 0;
}
/ * Read characters from the file * /
INT Read_Str (Char * S, File * FP)
{
INT i = 0;
IF (! fp) Return 0;
IF (FGETS (S, 1000, FP)) i = 1;
S [Strlen (S) -1] = 0;
Return I;
}
/ * Character string left by Qi * /
Void Move_left (Char * D, Char * S, INT N)
{
INT I, L;
l = strlen (s);
IF (n> L) n = L;
For (i = 0; i
* D = * s ;
* D = 0;
}
/ * Take the left string * /
Void Left (Char * D, Char * S, INT N)
{
INT I, L;
i = 0;
l = strlen (s);
IF (n> L) n = L;
For (i = 0; i
D [i] = s [i];
D [N] = 0;
}
/ * Write data to file * /
Void Write_Str (Char * S, File * FP)
{
CHAR C = 10;
IF (! fp) return;
FPUTS (S, FP);
FPUTC (C, FP);
}
/ * Take the right string * /
Void Right (Char * Dest, Char * Source, Int Num)
{
INT I, J;
IF (Num <1) NUM = 0;
Num = Strlen (Source) -Num;
IF (Num <0) NUM = 0;
For (i = 0, j = Num; j <= strlen (source); i , j ) dest [i] = source [j];
}
/ * Open or turn the cursor * /
Void Cursor (int On2OFF)
{
Union regs r;
IF (on2off! = OFF) on2Off = 10;
R.h.ah = 1;
R.H.CH = 3;
R.H.Cl = on2OFF;
INT86 (16, & R, & R);
}
/ * Speaker vocal * /
Void Sound (Int Frequency, Int Time)
{
INT I;
i = Time * 50;
IF (i> 30000) i = 30000;
IF (i <50) i = 50;
Sound (Frequency);
Mydelay (i);
Nosound ();
}
/*time delay*/
Void MyDelay (long T)
{
Time_t oldtime;
Long T0;
T0 = T / 55;
IF (t0 <1) t0 = 1;
Oldtime = clock ();
While (Clock () - Oldtime
}
/ * Positive news * /
Void Report_Clock (Void)
{
INT I;
For (i = 0; i <5; i );
{
Sound (500, 10);
Mydelay (1000);
}
Sound (800, 10);
}
/ * Writing integration in the file * /
Void write_int (int Num, file * p)
{
Char s [20], A = 10;
IF (! p) return;
ITOA (NUM, S, 10);
FPUTS (S, P);
FPUTC (A, P);
}
/ * Read the integer from the file * /
INT read_int (int * Num, file * p) {
INT I;
CHAR S [30] = ""
IF (! p) Return 0;
IF (Fgets (S, 1000, P))
{
i = -1;
S [Strlen (S) -1] = 0;
* Num = ATOI (S);
}
ELSE I = 0;
Return I;
}
/*Call the police */
Void Warn (Void)
{
Sound (300, 1);
Sound (100, 1);
}
/ * String right back * /
Void Move_Right (Char * S, INT WIDE)
{
INT I, L, N;
l = strlen (s);
N = WIDE-L;
IF (n> 0)
{
For (i = L; I> -1; I - s [i n] = s [i];
For (i = 0; i
}
}
/ * Character string * /
Void Move_Middle (Char * S, INT WIDE)
{
INT I, L, N;
l = strlen (s);
IF (Wide> L)
{
WIDE = WIDE-1;
N = WIDE / 2;
WIDE = WIDE-N;
For (i = L; I> -1; I - s [i n] = s [i];
For (i = 0; i
For (i = 0; i
S [L N I] = 0;
}
}
/ * Delete sub-string * /
Void delete_substring (char * source, int start, int num)
{
INT I, L;
L = strlen (source);
IF (NUM> L-START 1 || Num == - 1) Num = L-START 1;
IF (Start <1 || Start> 1) Return;
For (i = start; i
Source [I-1] = Source [i Num-1];
}
/ * Find specified strings * /
Int Instr (int N, char * source, char * dest)
{
INT I, J, K1, K2, P;
INT start = 0;
IF (n == 0) n = 1;
K1 = Strlen (Source);
K2 = Strlen (DEST);
IF (n <0)
{
Char s [100];
n = -n;
MID (S, Source, N, K2);
IF (strcmp (s, dest)) Return 0;
Return n;
}
IF (K1-N 1
For (i = n-1; i
{
P = 0;
For (j = 0; J
IF (Source [i j]! = dest [j]) breaf;
ELSE P ;
IF (p == k2)
{
START = I 1;
Break;
}
}
Return Start;
}
/ * Generate space * /
Void Space (Char * S, INT N)
{
INT I;
IF (n <0) n = 0;
For (i = 0; i
* s = 0;
}
/ * Generate strings * /
Void String (int N, char * s1, char * s2)
{
INT I;
IF (n <0) n = 0;
S1 [0] = 0;
For (i = 1; i <= n; i ) STRCAT (S1, S2);
}
/ * Cut off the left side of the string * /
Void Cut_LEFT_SPACE (Char * S)
{
INT I, J, K = 0; I = Strlen (s) 1;
For (j = 0; J
For (k = 0; J
}
/ * Cut off strings on right space * /
Void cut_right_space (char * s)
{
INT I, J;
I = Strlen (S) -1;
For (j = i; j> -1; j--) IF (s [j]! = '') BREAK;
S [J 1] = 0;
}
/ * Show a string * /
Void Display (char * s)
{
Union regs regs;
Int Color, X, Y;
x = wherex ();
y = wherey ();
Color = 16 * bjys qjys;
While (* s)
{
IF (x> 80) Break;
Regs.h.ah = 9;
Regs.h.al = * S;
Regs.h.bh = 0;
Regs.h.bl = color;
Regs.x.cx = 1; / * Displayed, does not change the cursor position * /
INT86 (16, ® s, ® s);
X ;
IF (x> 80)
{
X = 1;
y ;
IF (y> 25) y = 25;
}
gotoxy (x, y);
S ;
}
}
/ * Define the screen color * /
Void Color (Int Forecolor, Int BackColor)
{
IF (Forecolor <0 || Forecolor> 15) Return;
IF (Backcolor <0 || Backcolor> 15) Return;
Qjys = forecolor;
BJYS = backcolor;
}
/ * Show prompt window * /
Void Quit_yesno (Char * S1, Char * S2)
{
Char buffer [2000], jx
GetText (30, 8, 76, 16, buffer);
Textbackground (3);
CLSXY (8, 32, 9, 30, 6);
CLSXY (4, 30, 8, 30, 6);
Color (15, 4);
gotoxy (35, 10);
Display (S1);
GotoxY (35, 12);
Display (S2);
Gotoxy (35 Strlen (S2) 1, 12);
JX = getCH ();
Puttext (30, 8, 76, 16, buffer);
IF (jx == 'n' || jx == 'n') return;
Textbackground (0);
TextColor (15);
CLRSCR ();
CURSOR (ON);
exit (0);
}
Full article:
Pengcheng C Language Teaching Website