Programming skills

xiaoxiao2021-03-06  107

/ * Show warning windows * /

Void Warn_Message (Char * S1, Char * S2)

{

CHAR BUFFER [2000];

GetText (30, 8, 76, 16, buffer);

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 (40, 13);

DISPLAY ("Press any key to continue ...");

Getch ();

Puttext (30, 8, 76, 16, buffer);

}

/ * Get file length * /

Long getFileLength (Char * file)

{

File * fp;

INT I;

IF ((fp = fopen (file, "rb") == null)

{

CLRSCR ();

Printf ("can't open the file% s.", file);

Return 0;

}

i = 0;

While (! feof (fp))

{

i ;

FGETC (FP);

}

Fclose (fp);

Return (I-1);

}

/ * Window scroll * /

Void WINDOW_ROLL (int y1, int x1, int yl, int xl, int Direct)

{

Union regs regs;

INT X2, Y2;

X1--

Y1--

X2 = x1 XL-1;

Y2 = Y1 YL-1;

Regs.h.ah = 5 Direct; / * ah = 06h rolled the current page * /

/ * AH = 07h down. . . * /

Regs.h.al = 1;

Regs.h.bh = 16 * PMBJ PMQJ;

Regs.h.ch = Y1; / * Left corner * /

Regs.h.cl = x1; / * column * /

Regs.h.dh = Y2; / * Right lower line * /

Regs.h.dl = x2; / * column * /

INT86 (16, ® s, ® s);

}

/ * Scan keyboard * /

INT scan_keyboard (int * m)

{

Union inkey

{

UNSIGNED CHAR CH [2];

INT II;

} cc;

While (! Bioskey (1))

{;

Cc.ii = bioskey (0);

* m = cc.ch [1];

Return cc.ch [0];

}

/ * Insert string * /

Void Insert_String (Char * DS, Char * SS, INT N)

{

Char s [100];

MID (DS, S, N, -1);

DS [N-1] = 0;

STRCAT (DS, SS);

STRCAT (DS, S);

}

Void str_add_char (char * s, char ch)

{

CHAR S1 [2];

S1 [0] = CH;

S1 [1] = 0;

STRCAT (S, S1);

}

/ * Detect whether the disk is ready * /

Int CheckdiskReading (int N)

{

Int result;

Char buffer [512];

Result = BiosDisk (4, N, 0, 0, 0, 1, Buffer);

Result = result & 0x02;

IF (Result! = 0x02) Return 0;

Return 1;

}

/ * Detect whether the disk is written protection * /

INT CheckdiskWriteprof (Void)

{

Int result;

Char buffer [512];

Result = BiosDisk (5, 0, 0, 0, 0, 1, buffer);

IF (Result == 0x03) Return 0; Return 1;

}

/ * Modify a line of the file * /

INT ModifyFileLine (Char * FileName, Char * S, INT N)

{

Char Data [20] [80];

INT I;

File * fp;

IF ((FP = FOPEN (FileName, "R")) == null) Return 0;

i = 0;

While (read_str (Data [i], fp))

i ;

Fclose (fp);

FP = fopen (filename, "w");

STRCPY (Data [N-1], S);

n = i-1;

For (i = 0; i <= n; i )

Write_str (Data [i], fp);

Fclose (fp);

Return 1;

}

/ * Batch copy file * /

INT Copyfile (Char * sfile, char * DFILE, INT F2D, INT Barlong, int Height, int x, int y)

{

INT CopyFile (Char * sf, char * DF);

INT Makendir (Char * DIR);

Char filename [200] [13], d [40], s [40], s1 [40];

Struct ffblk ffblk;

INT DONE, I, J, L, LEN;

i = 0;

DONE = FindFirst (sfile, & ffblk, 0);

IF (! done) STRCPY (filename [i], ffblk.ff_name);

While (! done)

{

DONE = FINDNEXT (& FFBLK);

IF (! done)

{

i ;

STRCPY (filename [i], ffblk.ff_name);

}

}

IF (F2D)

{

CopyFile (Sfile, DFILE);

Return 1;

}

STRCPY (S, SFILE);

L = strlen (sfile);

For (j = l-1; j> = 0; J -)

IF (s [j] == '//')

{

S [J 1] = 0;

Break;

}

/ * Copy a file * /

INT Copyfile (Char * sf, char * df)

{

FILE * IN, * OUT;

CHAR CH;

IN = 0;

OUT = 0;

IF ((IN = fopen (sf, "rb")) == null)

exit (0);

IF ((out = fopen)) == null)

exit (0);

While (! Feof (in))

{

CH = fgetc (in);

IF (ferror (in)) returnograph;

FPUTC (CH, OUT);

IF (FERROR (OUT) RETURN 0;

}

Fclose (in);

Fclose (OUT);

Return 1;

}

/ * Establish a directory * /

INT Makendir (Char * DIR)

{

INT I, L, J;

Char s [10] [40];

J = 0;

L = strlen (dir);

For (i = 0; i

IF (DIR [i] == '//')

{

Left (S [J], DIR, I);

J ;

}

STRCPY (S [J], DIR);

For (i = 0; i <= j; i )

IF (Access (S [I], 0)) MKDIR (S [i]);

Return 1;

}

/ * Get a directory * /

Int getdir (Char * Dirf, Char Datak [] [14])

{

Struct ffblk ffblk;

Int done;

INT I;

i = 0;

DONE = FindFirst (Dirf, & ffblk, fa_direc);

While (! done)

{

IF (ffblk.ff_attrib == 16 || ffblk.ff_attrib == 17)

{

STRCPY (DATAK [I], FFBLK.ff_name);

STRCAT (DATAK [I], "//");

i ;

}

DONE = FINDNEXT (& FFBLK);

}

Return I;

}

/ * Get file name * /

Int getfile (char * dirf, char data [] [14])

{

Struct ffblk ffblk;

Int done;

INT I;

i = 0;

DONE = FindFirst (Dirf, & ffblk, 0);

While (! done)

{

STRCPY (DATAK [I], FFBLK.ff_name);

DONE = FINDNEXT (& FFBLK);

i ;

}

Return I;

}

/ * Any two positive integers (<80) * /

/ * Parameter description: NUMA, NUMB is the result of addex and plus addex, resulting in Result * /

Void Add (Char * NUMA, Char * Numb, Char * Result)

{

INT I, J, A, B, C, JW, ALEN, BLEN; / * Define Variables * /

CHAR NUM [81];

Char numc [81]; / * Define new strings, the length is the same as NUMA * /

CHAR CH;

Char s [1];

NUM [0] = 0;

NUMC [0] = 0;

IF (Strlen> = 80) Return;

IF (strlen> = 80) Return;

For (i = 0; i

IF (! isdigit (NUMA [i])) Return; / * If illegal return results are empty * /

For (i = 0; i

IF (! isdigit)) Return;

IF (Strlen (NUMA)

{

STRCPY (NUM, NUMA);

STRCPY (NUMA, NUMB);

STRCPY (NUMB, NUM);

NUM [0] = 0;

}

Alen = Strlen (NUMA);

Blen = Strlen (NUMB);

STRCPY (NUMC, NUMB);

For (i = 0; i

NUMC [Alen-I-1] = NUMC [BLEN-I-1];

For (i = 0; i

NUMC [I] = '0';

JW = 0; / * carry * /

For (i = 0; i

{

S [0] = NUMA [Alen-I-1];

S [1] = 0;

A = ATOI (S);

S [0] = NUMC [alen-i-1];

S [1] = 0;

B = ATOI (S);

C = a b jw;

IF (c> = 10)

{

JW = 1;

C = C-10;

}

ELSE JW = 0;

ITOA (C, S, 10);

Num [i] = s [0];

}

IF (jw == 1) {NUM [i] = '1'; NUM [i 1] = 0;}

Else Num [i] = 0;

J = Strlen (NUM);

For (i = 0; i

{

CH = NUM ​​[I];

NUM [I] = NUM ​​[J-I-1]; / * Reverse Num Reverse * / NUM [J-I-1] = CH;

}

STRCPY (RESULT, NUM);

Return; / * Returns Add Results * /

}

/ * Any two positive integers multiplied * /

/ * Parameter description: NUMA, NUMB is multiplier and multiplier, Resultm storage * /

Void Mult (Char * NUMA, Char * Numb, Char * Resultm)

{

INT I, J, K, L, M, A, B, C, JW, Alen, Blen, f; / * Define variables * /

Char Resulta [82];

CHAR NUM [161];

CHAR CH;

Char s [1];

NUM [0] = 0;

f = 0;

IF (Strlen> = 80) Return;

IF (strlen> = 80) Return;

For (i = 0; i

IF (! isdigit (NUMA [i])) Return; / * If illegal return results are empty * /

For (i = 0; i

IF (! isdigit)) Return;

IF (Strlen (NUMA)

{

STRCPY (NUM, NUMA);

STRCPY (NUMA, NUMB);

STRCPY (NUMB, NUM);

NUM [0] = 0;

}

Alen = Strlen (NUMA);

Blen = Strlen (NUMB);

STRCPY (ResultM, "0");

For (i = 0; i

{

s [0] = NUMB [BLEN-I-1];

S [1] = 0;

C = ATOI (S);

STRCPY (Resulta, Numa);

IF (c == 0) STRCPY (ResULTA, "0");

For (j = 0; J

l = strlen (resulta);

For (k = 0; K

{

Resulta [L K] = '0';

Resulta [L K 1] = 0;

}

Add (ResultM, Resulta, Resultm);

}

}

Full article:

Pengcheng C Language Teaching Website

转载请注明原文地址:https://www.9cbs.com/read-123972.html

New Post(0)