C language programming skills-general Linux technology-Linux programming and kernel information. The following is a detailed description. /* Read characters from the keyboard function: When you press the normal key, return its ascii code scan CODE = 0 */
Int INKEY (int * code)
{
Int m;
While (! Bioskey (1)/* can be added to the ERA code without buttons */;
* Code = bioskey (0 );
M = * code * 255;
If (! M) m = * code> 8;
* Code = x code & 255;
Return m;
}
/* Get the 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;
}
/* Convert a floating point number to a string */
/* Parameter description data: floating point number to be converted; s: Output string; len: converted length */
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 the screen */
Void CLSXY (int color, int x, int y, int xl, int yl)
{
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;/* Number of rolling rows */
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 down all spaces in the string */
Void CUT_ALL_SPC (char * s)
{
Int I, n;
Char d [10000];
N = 0;
For (I = 0; iif (s
! = 32) { D [n] = s; N ++; } D [n] = 0; Strcpy (s, d ); }
/* Obtain the 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 (iif (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; it [j] = s; 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, 10000, fp) I = 1; S [strlen (s)-1] = 0; Return I; }
/* String matching on the left */ 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; id= S; D [n] = 0; }
/* Write data to a file */ Void WRITE_STR (char * s, FILE * fp) { Char c = 10; If (! Fp) return; Fputs (s, fp ); Fputc (c, fp ); }
/* Obtain 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= Source [j]; }
/* Open or close 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 */ 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}
/* Start time */ Void REPORT_CLOCK (void) { Int I; For (I = 0; I <5; I ++ ); { SOUND ); MYDELAY (1000 ); } SOUND (800,10 ); }
/* Write the integer 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 integers from the file */ Int READ_INT (int * num, FILE * p) { Int I; Char s [30] = ""; If (! P) return 0; If (fgets (s, 10000, p )) { I =-1; S [strlen (s)-1] = 0; * Num = atoi (s ); } Else I = 0; Return I; }
/* String matching on the right */ 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; For (I = 0; I} }
/* Center the 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; For (I = 0; ifor (I = 0; is [l + n + I] = 0; } }
/* Delete the substring */ 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; isource [I-1] = source [I + num-1]; }
/* Find the specified string */ 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 + 1for (I = n-1; I { P = 0; For (j = 0; jif (source [I + j]! = Dest [j]) break; 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 a string */ 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 the left space of the string */ Void CUT_LEFT_SPACE (char * s) { Int I, j, k = 0; I = strlen (s) + 1; For (j = 0; jfor (k = 0; j}
/* Cut the right space of the string */ 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; }
/* Display 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;/* Number of times displayed, without changing the cursor position */ Int86 (16 ,? S ,? S ); X ++; If (x> 80) { X = 1; Y ++; If (y> 25) y = 25; } Gotoxy (x, y ); S ++; } }
/* Define screen color */ Void COLOR (int ForeColor, int BackColor) { If (ForeColor <0 | ForeColor> 15) return; If (BackColor <0 | BackColor> 15) return; Qjys = ForeColor; Bjys = BackColor; }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.