数学建模社区-数学中国

标题: 函数大全(b开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 03:03
标题: 函数大全(b开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>
* v. D* n" K$ R& b<><FONT color=#ff0000>函数名: bar </FONT>7 [  T; @& y4 g
功 能: 画一个二维条形图
# K, d" d- ~/ j% [' D4 n  ], b2 q用 法: void far bar(int left, int top, int right, int bottom); ) P; O9 Q* @, P
程序例: </P>
1 X' R7 x/ Z$ u6 G/ J. R<><FONT color=#0000ff>#include <GRAPHICS.H>. H3 y9 ^- E" |& z* \
#include <STDLIB.H>7 V; I) L& k+ Z
#include <STDIO.H>
" o' Z% V8 a/ ]" i#include <CONIO.H></FONT></P>
* B) v5 t: T. J6 E; `8 ~7 `<><FONT color=#0000ff>int main(void) 3 r( ?! k$ a, {2 p  g
{ / T3 j- O1 R  A' G
/* request auto detection */
" v, r7 i" ^5 g( r* G: Jint gdriver = DETECT, gmode, errorcode;
/ t6 e" D. \1 _; I& J9 iint midx, midy, i; </FONT></P>1 C5 E7 {) p  _
<><FONT color=#0000ff>/* initialize graphics and local variables */
; |- b) ?. ]8 \/ Q0 iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* |5 v* }! R) J0 I7 F1 i, b2 @7 p" o3 a
<><FONT color=#0000ff>/* read result of initialization */ 5 n( {3 G3 R9 a& l' _+ ?8 Y
errorcode = graphresult(); ! ]$ r1 l9 Z; Q0 i0 x7 _$ W
if (errorcode != grOk) /* an error occurred */ 0 u$ [) Z* Z) P7 e9 v! q  A
{
8 K% d3 X1 \  w3 G, B- Hprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! A$ x+ u, J3 R+ I! Iprintf("ress any key to halt:"); % j2 ^- g: _* R" s
getch(); / K$ j, O5 h% ?* X1 e
exit(1); /* terminate with an error code */
1 l- F5 y: k" d4 S2 x( W} </FONT></P>1 p1 W. \4 I6 S3 j( i
<><FONT color=#0000ff>midx = getmaxx() / 2;
  m. j( h1 j( m: |  r+ ]midy = getmaxy() / 2; </FONT></P>
, k, |9 |* C+ N, S4 j<><FONT color=#0000ff>/* loop through the fill patterns */
  I( k0 z2 o' F! X5 q$ ^7 z' ]/ jfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { 3 g" o! C7 [# [% j, v
/* set the fill style */
* }# ^/ @: m% P' zsetfillstyle(i, getmaxcolor()); </FONT></P>
. q8 E) `8 T% l' g( y<><FONT color=#0000ff>/* draw the bar */
8 K) t3 z2 g1 \7 V& S2 pbar(midx-50, midy-50, midx+50, : c$ E7 h/ L$ O4 K
midy+50); </FONT></P>
" s4 z# o. {, J+ a% P<><FONT color=#0000ff>getch();
6 a! @' S) L0 A' d0 N& t} </FONT></P>& Y* A, T: l" L5 E1 l( p
<><FONT color=#0000ff>/* clean up */ / K' D* W- G$ f
closegraph();
: U! ^+ [+ f: o7 e- M. t1 Yreturn 0; ' w) q" D: v& m, Q8 R1 V% O& ~5 h5 z
} </FONT>- E  G) d2 o- f- K4 |% Y

$ Q  `6 i- P0 }
5 s" L, @6 h- r, k% N# D# i1 t</P>
$ V/ E- ^5 E- I+ X<><FONT color=#ff0000>函数名: bar3d </FONT>
& }; j" g0 A- J* _% m* Q  v7 i9 W功 能: 画一个三维条形图 . ~+ C: s6 K0 g' t! T
用 法: void far bar3d(int left, int top, int right, int bottom,
6 H/ x3 W2 S8 z3 l) ^& o# zint depth, int topflag);
9 t! Y6 D4 ]0 P: c+ {6 u8 N5 X程序例: </P>9 i0 B( k' e2 Z2 [
<><FONT color=#0000ff>#include <GRAPHICS.H>
4 l2 P& v5 o7 {0 q" b+ P1 j/ g: l#include <STDLIB.H>1 T- s, i/ ?0 L1 l# ]9 g
#include <STDIO.H>
! ^  C1 a5 z; C# R$ J& G#include <CONIO.H></FONT></P>
, Z) ?2 S' [$ O: L  z; c  o8 O<><FONT color=#0000ff>int main(void)
% L: [; k0 B1 N6 n( V0 `( M{ + K4 A/ Z8 D7 ~) O7 n$ T/ W  o+ p
/* request auto detection */
  o9 D- A/ e+ t! P9 i7 Zint gdriver = DETECT, gmode, errorcode; ! b+ s. A2 ~; w7 u5 O  \; ~' F
int midx, midy, i; </FONT></P>
/ r4 R0 v7 C4 v0 f) c* e<><FONT color=#0000ff>/* initialize graphics, local variables */
' e* z- O6 b( l- ~; v5 [6 ^/ [) D1 \initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 w. M5 Y8 J2 `, y. g
<><FONT color=#0000ff>/* read result of initialization */
, m5 @, s: f8 V, Aerrorcode = graphresult();
/ h+ I8 g' R6 ]if (errorcode != grOk) /* an error occurred */
! y. h( z2 N( c6 U7 c7 T/ G{
4 ], z( p6 e$ M1 Tprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 w& s, r, U6 c% _* V% r" }3 Z
printf("ress any key to halt:");
8 f! o( j8 y: R# `1 y+ [getch(); ( G* |4 C# L2 ^2 r' r% F  w  T) @
exit(1); /* terminate with error code */ ' J/ Y( l& J+ \8 G
} </FONT></P>2 S. Z3 m$ H0 `8 Q1 C: M  N- }2 }( M
<><FONT color=#0000ff>midx = getmaxx() / 2;
' P2 R  Z! q: {) B# ]midy = getmaxy() / 2; </FONT></P>" m& q6 X  \8 j: N( B' G2 I
<><FONT color=#0000ff>/* loop through the fill patterns */ ' v0 P& a% H' m( u/ x3 k, T7 a6 v
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
9 k, f# U6 E4 r* H* I$ `1 U/* set the fill style */ ( V7 j" J- ^; |% t# g3 `+ ]9 t
setfillstyle(i, getmaxcolor()); </FONT></P>; A9 c7 Q/ p2 T% U- r; s
<><FONT color=#0000ff>/* draw the 3-d bar */ $ Y# v1 a$ e& ?* d
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
8 I8 n$ [6 J* M+ x" K1 e* Q; ^<><FONT color=#0000ff>getch(); ' _: c! G* L/ C: @9 e9 n
} </FONT></P>
5 \  m9 m) }0 U' H4 h, K7 m# H0 {, n<><FONT color=#0000ff>/* clean up */
. }; f: @( O4 N( n4 g" fclosegraph();
* \4 |. y( \- r  b% Oreturn 0; 8 ~1 V1 R5 }) I' ~
} ' a4 V% W3 v5 k5 w4 h- n1 Z7 F
</FONT>7 b1 Y2 @+ n3 Z) ]0 D

' Y) S$ ?1 C4 F* I1 Q</P>0 q, ]5 K7 a2 }0 S# N; W  c
<><FONT color=#ff0000>函数名: bdos </FONT>; S0 ~8 S% A* [0 k$ r5 D  U% b
功 能: DOS系统调用 9 i6 [5 J  x$ F  A* L
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
/ }' T; B. H% i# T程序例: </P>. `+ |$ f1 p5 l0 a8 x. `) r- ]. X
<><FONT color=#0000ff>#include <STDIO.H>! W3 Z5 v4 P* S
#include <DOS.H></FONT></P>  g5 P4 l* ~" ~" A3 L$ F% Y2 E5 e$ V2 @
<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ 8 m" O4 B5 N2 q' i+ `
char current_drive(void)
# _6 V' V  n' |5 Q0 {$ l{ . {- s7 c" G9 _  R, c  N
char curdrive; </FONT></P>
% Z$ e: c6 I4 a4 J! ?: T; j9 Q- m<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
/ K* p  S- |( [8 f! b4 y) Z; Ocurdrive = bdos(0x19, 0, 0);   T% Y* K) o4 Z* X3 l- q- \; d6 e' D
return('A' + curdrive);
: ~$ i5 f/ [7 `* t} </FONT></P>
, u1 a) B7 B: O<><FONT color=#0000ff>int main(void) , B" w: D' i7 Q  U
{ 4 O% W* d) g' K- c, t: `7 w
printf("The current drive is %c:\n", current_drive());
5 V! S% b3 W/ i( preturn 0;
: D  s/ o9 e% U1 r* u}
$ e) K) D+ q/ k& {- `' W2 y" r7 T8 J/ ~" q, L8 `: s
</FONT>
+ U' m. L$ S# A! V</P>
9 v$ i6 s, O+ v( i: |3 V" l' {+ l<><FONT color=#ff0000>函数名: bdosptr </FONT>6 w' N- R& {4 }- g2 Y3 y$ r1 ^
功 能: DOS系统调用
9 h* d5 W* h( A( [用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
4 q4 ^; c" H) W  j0 n程序例: </P>
6 ~! [9 U/ F4 G- v2 d* D<><FONT color=#0000ff>#include <STRING.H>
' x* A" \7 K) r) H" H8 Y#include <STDIO.H>
0 B2 |2 i6 u9 E1 e1 b6 b) U5 @7 x#include <DIR.H>
6 r( O; {# z' ?8 C! Y#include <DOS.H>- p: `" A. E/ l5 D
#include <ERRNO.H>
4 p1 C6 c, N* z#include <STDLIB.H></FONT></P>
; |9 C; d: [8 ]+ w& R<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
( d7 |( x& {) f- \: L<P><FONT color=#0000ff>int main(void) 4 a. n9 z- u# C# S& a; [
{ 3 y2 X1 f/ N* K4 o  z9 d# U
char buffer[BUFLEN]; 7 y3 G6 n. T7 `* J. `2 Y
int test; </FONT></P>
6 l& p7 i5 ?1 x& L2 Y5 d! G<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 8 V/ j9 W; D# T! d1 v
gets(buffer); </FONT></P>) T; D# V# e  y
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); ) E' \7 `7 A; B- t- T7 @
if(test) & V8 x* m; t& H7 Z% S5 B5 h
{
! Z8 V5 t# {. s. r4 Z! ^, Rprintf("DOS error message: %d\n", errno); ) o" p' Z% i: m9 m: H! \
/* See errno.h for error listings */
# U9 y* L6 y; X$ h0 \) lexit (1); ; p. r6 E6 t, t. I3 M! e
} </FONT></P>( |7 {7 L  |( E8 h! h: A
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 1 K; Z, q* N; [( p9 g  ]
printf("The current directory is: %s\n", buffer); </FONT></P>
5 c1 Z. A+ D7 w; e+ P3 W7 N1 T<P><FONT color=#0000ff>return 0; % N5 F' Q) Y) N5 m
}
% u) g! _2 E8 K. x* }</FONT>7 [3 Z/ X% ]- N) B" `" _0 ~# h
! \$ M$ q! D  y
</P>
! T( q' }2 f% x) A& l$ M0 I<P><FONT color=#ff0000>函数名: bioscom </FONT>6 \  z' Q. L0 B- O) V8 ]
功 能: 串行I/O通信
4 f4 p' Z7 m) b* T. M) j, B用 法: int bioscom(int cmd, char abyte, int port);
4 H+ p& Q) V/ P9 m程序例: </P>
  B, [  \$ z, _7 \$ Q<P><FONT color=#0000ff>#include <BIOS.H>, u* l- f2 \8 j) a
#include <CONIO.H></FONT></P>
5 Q& `+ `, y. Q<P><FONT color=#0000ff>#define COM1 0
- }$ ~( n# e% q, @+ \/ m! z#define DATA_READY 0x100 1 j' D) z+ F; O9 x' p1 c+ p  i
#define TRUE 1 ( h! i( U% D+ z0 u
#define FALSE 0 </FONT></P>; @* i( J, L! V2 @4 d9 M
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>+ V& x+ S& Z2 w/ T3 \2 ?
<P><FONT color=#0000ff>int main(void)   q6 d7 F: i6 j
{
( A/ ]$ V" C/ l2 W7 z1 ~int in, out, status, DONE = FALSE; </FONT></P>
- `* K& A" X; u+ c, h<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); * v+ ^- v2 ]/ r
cprintf("... BIOSCOM [ESC] to exit ...\n");   G& n" n# Y/ m& p
while (!DONE) 8 ^" {$ P2 t8 O' ^1 q) a. e3 D
{
5 F& _4 g7 ~; P: tstatus = bioscom(3, 0, COM1);
8 N" y( ^& B, Aif (status &amp; DATA_READY) $ ~0 ]! L1 Q  L3 |% T6 {* P
if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
8 G: R4 N: f% p  |2 X) G* |putch(out);
8 }; o7 g. ~( _3 C2 U. \/ Aif (kbhit())
' f# T" {) v# F{ 4 ]2 ~: j$ Q0 b! f$ K/ J6 v4 C
if ((in = getch()) == '\x1B')
$ L2 p2 O* g2 D8 K1 n( V0 EDONE = TRUE; & r& _. U( |5 ~; M" G
bioscom(1, in, COM1);
1 o8 p. \' a7 I# _! Z}
1 s1 q. T, Y2 j! r. v  h! }7 K} $ H7 D1 w1 M- }3 O& j: l7 B
return 0; 7 L3 n, ], }) A* h7 G* c
} </FONT>. z8 _3 r) [, l+ R+ U, V

5 v# I4 \: ^' j/ b6 n7 x" I5 `: B
" l& Y% r+ D8 [% ]6 r7 H</P>
. b$ |) ], c! |! G<P><FONT color=#ff0000>函数名: biosdisk </FONT>
, g7 H, F! `" T8 [% D功 能: 软硬盘I/O
8 I$ }" l4 ?2 d4 K, x用 法: int biosdisk(int cmd, int drive, int head, int track, int sector ; v: u' W$ U) l
int nsects, void *buffer);
; T& a0 u1 A% d9 t& q- K# Y程序例: </P>- h3 T+ p7 J8 o0 P- K: c2 e( L* |
<P><FONT color=#0000ff>#include <BIOS.H>+ G7 h) o0 n. ]9 C* i
#include <STDIO.H></FONT></P>2 }9 A7 r+ ]# Q3 _3 j" A9 l, t
<P><FONT color=#0000ff>int main(void)
$ ]" |, F! T6 L7 l% L6 O) M7 I. k{
7 Z$ x$ S5 F5 T4 G. Wint result; : y5 Z0 H, D: m: ~9 F0 H/ N; D2 W
char buffer[512]; </FONT></P>, _& n: w) x" X- `7 S+ x
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
/ G, f# b9 B" }7 ~. h) hresult = biosdisk(4,0,0,0,0,1,buffer); 3 x: X% l9 y" V" k" m: n7 v, }
result &amp;= 0x02;
/ E" |9 ?$ Q5 g9 ^8 u. i6 V: J(result) ? (printf("Drive A: Ready\n")) :
- \" k, w6 Q( V, q# x$ T(printf("Drive A: Not Ready\n")); </FONT></P>3 ^2 r  G& }7 L5 k3 w: q; |3 f4 ~
<P><FONT color=#0000ff>return 0;
- f( K% m  I- x1 A" F: F} " G% |  @! O/ L/ W% ?( C
</FONT>: e' X; n6 F& C1 a' C: u
- g! r% Z& P2 q  R
</P>
2 H! m- h1 A( r: m<P><FONT color=#ff0000>函数名: biosequip </FONT>
4 v, N9 a. T2 m2 b# d5 y' }0 w功 能: 检查设备 ; M: i* A$ M# k0 J+ [
用 法: int biosequip(void);
& S; Y! p2 Z/ X% x' [程序例: </P>. a9 }8 |, l7 s' n5 u6 ^0 Y0 Q
<P><FONT color=#0000ff>#include <BIOS.H>+ G6 w0 H* C$ k& b8 v8 }' K
#include <STDIO.H></FONT></P>
7 w8 A4 h* c3 a9 H9 a; j, T<P><FONT color=#0000ff>int main(void)   a/ i8 t6 W% r5 P0 y* @4 R
{ 1 W+ {' }0 X4 D* \$ y9 @# _
int result;
! D5 U/ y# c+ N# ~3 W4 G  U- xchar buffer[512]; </FONT></P>4 W  }% |3 d+ A# u
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 4 ?$ j! L- C8 y; R$ ]
result = biosdisk(4,0,0,0,0,1,buffer); 4 R) ?$ p& i) R" `: {
result &amp;= 0x02;
/ O0 ~' m0 ~( r- Q0 m(result) ? (printf("Drive A: Ready\n")) : / S* F: I; A" H: D
(printf("Drive A: Not Ready\n")); </FONT></P>  P4 v  u7 r! P; l; B
<P><FONT color=#0000ff>return 0;
2 W5 h$ y& R* ]' e( z}
5 n0 c) F: p; N</FONT>
# h% z% V  s$ O3 ?  I; y' l& }4 O, q8 {$ l* h
</P>
  A/ k. ]# {3 x<P><FONT color=#ff0000>函数名: bioskey </FONT>: g" f* O# T8 m; ]" }+ u+ k
功 能: 直接使用BIOS服务的键盘接口
5 {7 F2 @2 a3 g% q4 T, @! G6 U用 法: int bioskey(int cmd);
& m  e! O& \6 a( ~' o+ Q程序例: </P>
# H1 e' ~! i( X" k4 ^( |* O2 x<P><FONT color=#0000ff>#include <STDIO.H>
& A; C' p! a! D+ ]9 @#include <BIOS.H>
2 I$ _/ b: T. h  d, G& ^) W#include <CTYPE.H></FONT></P>2 ]/ u; P, R0 p4 J
<P><FONT color=#0000ff>#define RIGHT 0x01
( H3 x+ A+ p8 {( E+ O0 ^#define LEFT 0x02   Y- O2 z' n; |: {
#define CTRL 0x04 + ]4 u" _1 a( m7 G* p
#define ALT 0x08 </FONT></P>
# n. ^7 H1 K" P# B<P><FONT color=#0000ff>int main(void)
. [! f+ ]- g* N0 v( }' |. {  J: V2 T{
( \5 P. p+ S6 }( U0 Sint key, modifiers; </FONT></P>
. f% _! h& ~  v7 {<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ ' \/ B. m$ o- @( l( G1 N' j
while (bioskey(1) == 0); </FONT></P>8 ?4 q7 e, l( x3 E3 X
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */   i4 ?# `7 }( q( o. D3 `2 f
key = bioskey(0); </FONT></P>4 _* y; a9 ], @  ?6 b6 G
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
+ W1 {$ M! o" F: I" `modifiers = bioskey(2);
4 t  H# Y8 }& v5 Q5 Mif (modifiers)
% V+ a- H% t+ I" i$ i' ?{ * ]5 h9 ?) W( k1 A6 J
printf("[");
3 O1 T. K" q; uif (modifiers &amp; RIGHT) printf("RIGHT"); " i. v* _2 M- S0 N8 Z
if (modifiers &amp; LEFT) printf("LEFT"); 7 c0 t; `- i: Q2 i& O
if (modifiers &amp; CTRL) printf("CTRL"); / [0 x' }4 a! X: y! B
if (modifiers &amp; ALT) printf("ALT"); . \- N0 k+ q2 j% b6 P- y
printf("]");
6 z0 \2 M& a& \' L. b5 Q' X}
2 N* U& s1 c  n: ]9 v! x6 t- r* F# M/* print out the character read */
7 L" {0 p7 S0 V0 @3 iif (isalnum(key &amp; 0xFF))
) ^) h' c7 z) l) F7 Wprintf("'%c'\n", key); 2 X( y, @" o5 i6 _
else
! {& \) Y- ]( ?& ^- aprintf("%#02x\n", key); 4 ^, Y, z! `# L" ?9 T
return 0;
5 Q- X) m6 Y, I; f" j0 s2 [} ' u8 Z: g# D0 n6 H$ B8 r
6 f8 b& s& K' ~$ v' Z% ^
</FONT></P>% P3 N3 R7 ?* X& d5 ]' O
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
% X  t) O$ G' f, w6 _2 K功 能: 返回存储块大小 . C( _* i% D: |; d! E
用 法:int biosmemory(void);
8 Q- d7 S# i6 f; _! s程序例: </P>% G) C# T0 S; P4 X6 P, r
<P><FONT color=#0000ff>#include <STDIO.H>
  ~7 O/ Y" o- u) i% X#include <BIOS.H></FONT></P>
$ g9 C. o9 D# l  q, [- b<P><FONT color=#0000ff>int main(void) . q+ `9 M$ n, o& {5 [# \
{ : g( d( D+ v# ^( ]/ K: h. I
int memory_size; </FONT></P>8 u2 Q- e/ _. B  C
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ ; G' X% j& t4 w
printf("RAM size = %dK\n",memory_size);
% b8 c" }. f* F- N! W2 |+ {% B+ p+ ^return 0; : b+ L5 `3 E( O5 W  {
}
( g1 f* ~# A8 U; _% s; E</FONT>
5 R* W/ V$ O% c* \1 T7 `0 y9 N/ K. q
4 m6 X* [  h0 r, I. B/ z; B8 h</P>
! L1 C0 u& J$ n% F7 T0 q+ ?<P><FONT color=#ff0000>函数名: biosprint </FONT>7 y7 Q% m  j' B' H" H5 a6 H
功 能: 直接使用BIOS服务的打印机I/O 1 U7 n4 ?0 b+ [3 ~6 y
用 法: int biosprint(int cmd, int byte, int port);
' Y2 u6 Q& g+ J2 F. e1 s, R程序例: </P>3 x* k4 B) ~: e5 s, n
<P><FONT color=#0000ff>#include <STDIO.H>
# y2 M+ k1 X" J# u9 Q#include <CONIO.H>& G0 Y  }$ K; u8 S3 v& _
#include <BIOS.H></FONT></P>) Y$ N9 z1 K+ t8 p9 ^$ R
<P><FONT color=#0000ff>int main(void)
8 B; K* i" P# L5 F{ 3 T& V/ ?$ c% _
#define STATUS 2 /* printer status command */
1 V, Q: t- W, a#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
7 @5 ^* _$ }1 E# i/ X7 I3 G<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
7 h  t9 I* q& h* Y" @& @$ W<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 1 Z! w- f8 V/ z( K
getch();   Q  n, k7 ]9 H. e' g( z4 j; A
status = biosprint(STATUS, abyte, PORTNUM);
. q# M! L8 x% c) T7 Zif (status &amp; 0x01)
& X1 l: c! M2 g; }, q( q6 o7 r+ R$ n: uprintf("Device time out.\n"); 2 l% F/ y  D0 n( a
if (status &amp; 0x08)
- U/ ^; C8 `2 Z# N5 ]0 l# Nprintf("I/O error.\n"); </FONT></P>
) I; C  _+ W, ]; ^' H% Q6 j' m<P><FONT color=#0000ff>if (status &amp; 0x10) 3 ~. z% }+ W2 ^' |) A  y
printf("Selected.\n");
0 l( v. [+ M5 E! D' eif (status &amp; 0x20)
8 h$ m( V7 R  f/ K( ^" C! n  Kprintf("Out of paper.\n"); </FONT></P>
3 t, h' q9 q. z<P><FONT color=#0000ff>if (status &amp; 0x40)
- @" {  R0 Z8 ^. x0 Y$ d! tprintf("Acknowledge.\n");
' s, [  g5 o4 U4 V2 Nif (status &amp; 0x80) 7 ?% @0 F1 \) Z0 G
printf("Not busy.\n"); </FONT></P>
  W# H, b! d! _- f) I4 C<P><FONT color=#0000ff>return 0; ! ^$ t, I+ R0 ~* R+ f" e3 x' C
} & {2 z) f4 l# y+ v
</FONT>
- c# k$ K" [3 Z5 o+ A) p) T  d% Q$ F$ A5 F
</P>
# p  }* g  C0 p7 k; ~: F' H<P><FONT color=#ff0000>函数名: biostime </FONT>
0 z0 e9 k9 X$ [( v, z% i功 能: 读取或设置BIOS时间
: W6 ?" l2 i' D% g& p用 法: long biostime(int cmd, long newtime); 6 ~; H& v+ N* f$ V( [
程序例: </P>
* a& Q: v& A; j  G' v8 D6 ?<P><FONT color=#0000ff>#include <STDIO.H>& r: w* ~* ?( y/ c/ G" r4 L
#include <BIOS.H>
* q# U$ v  q6 |, j# L" ?7 M0 L, G8 d#include <TIME.H>
1 a; r! ~4 R' Q3 M8 q#include <CONIO.H></FONT></P>4 G' Q3 I( `6 ~( z- [; O
<P><FONT color=#0000ff>int main(void)
% k2 j3 j( ?" d) g7 q5 t9 N{ ' B6 y( [. q4 ?6 F$ B+ r# W! A7 o
long bios_time; </FONT></P>
- T# q) U3 R- q<P><FONT color=#0000ff>clrscr();
/ A+ l; Q& |2 J2 @/ Tcprintf("The number of clock ticks since midnight is:\r\n"); , {- T6 u2 J. `* t2 r% t8 H6 l
cprintf("The number of seconds since midnight is:\r\n");
6 C5 e/ p2 \' E  Xcprintf("The number of minutes since midnight is:\r\n");
1 b/ [2 L& P- v. R) {5 Q, Pcprintf("The number of hours since midnight is:\r\n");
' N" H, e: ^2 y% ~) x+ g7 Wcprintf("\r\nPress any key to quit:"); # O% h, ~4 C" d+ K
while(!kbhit())
* f, n" W- `/ d! j9 N  [, d{ ( o5 {$ c' |  X# Z7 a9 t8 f+ E( e
bios_time = biostime(0, 0L); </FONT></P>
1 W7 `; h( t" o$ d3 p' D, I<P><FONT color=#0000ff>gotoxy(50, 1);
# o+ @5 E; _: X* B7 ?* Fcprintf("%lu", bios_time); </FONT></P>
- b/ E& m5 g! F0 L5 \. g<P><FONT color=#0000ff>gotoxy(50, 2); : v' b; d! x- R/ s- n
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P># Z: i' D- |4 X
<P><FONT color=#0000ff>gotoxy(50, 3);
8 R6 q! N1 u' P7 H$ s8 X' Z% Scprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
# E5 X% t1 R7 w0 v<P><FONT color=#0000ff>gotoxy(50, 4); , D3 [7 l1 m9 ?) L# Z
cprintf("%.4f", bios_time / CLK_TCK / 3600); 1 l0 Z; }, W. n5 d: c# _$ O
} 1 C* m1 b6 P& t# |/ b
return 0;
( J( W$ A$ D3 Z1 F! x1 ]/ e} : w8 t& b) T# e% L( e
</FONT># S! m" _  |' ~) X

2 ?9 B7 j/ Y( n$ A2 h2 C$ d</P>
- B, F' E9 O- E/ A7 a<P><FONT color=#ff0000>函数名: brk </FONT>. p, c/ U2 h6 ]4 a9 [% u
功 能: 改变数据段空间分配 & F" o" x) @0 b+ y1 k
用 法: int brk(void *endds);
* F6 |* |- o7 M& a+ ^( B9 I2 C程序例: </P>' T8 {! R# X& e9 |5 O3 E2 Y
<P><FONT color=#0000ff>#include <STDIO.H>8 l# ]( G; U3 L$ L
#include <ALLOC.H></FONT></P>
/ m. ~& S. }2 m- `6 [4 I0 }<P><FONT color=#0000ff>int main(void) / ^* E. g3 J! l7 @& J; d
{
: |8 r! p0 D  w0 F1 U, Wchar *ptr; </FONT></P>$ I' u/ P% E& z8 C8 p* o
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
2 m" M# P( e+ ~- g6 h/ U6 b4 Pptr = malloc(1);
. b; I4 D9 u$ J0 X: b* x9 w9 g: ^: b, \printf("Before brk() call: %lu bytes free\n", coreleft()); . J) A3 z9 p. {9 \4 {% r  `8 ^
brk(ptr+1000); / W0 p$ L* \, T$ [
printf(" After brk() call: %lu bytes free\n", coreleft());
) i9 l9 b' s" x5 v9 `  d0 wreturn 0;
2 Z) o3 y( I) q" |  R}
$ z* Q7 _, m/ B5 u. l& h2 I
6 t# I" _5 G$ q, Y- m</FONT>  j7 x/ }! \; s( a$ H0 x
</P>5 n0 R% |6 d# c* ^
<P><FONT color=#ff0000>函数名: bsearch </FONT>& T9 N. `0 P+ P/ c
功 能: 二分法搜索 5 ]$ x: ]  ^' {
用 法: void *bsearch(const void *key, const void *base, size_t *nelem, & a7 [# |0 F& e6 e
size_t width, int(*fcmp)(const void *, const *));
+ i7 \1 |+ M9 N9 I, X/ g  r3 \程序例: </P>: K$ ?9 Q8 y* D% f, p
<P><FONT color=#0000ff>#include <STDLIB.H>
8 {  n3 K; {7 N& o#include <STDIO.H></FONT></P>* k! k5 S. x5 m6 @% ?- n+ }
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
; Q: Y( B8 n2 z) N% Z( n<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>" p- A8 Q8 P, P* ?
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
" P" B: ^4 c+ ~+ M- B) G{ $ v: @( n0 s6 x2 G
return(*p1 - *p2);
5 r' B- d5 [. F! F! Q7 V} </FONT></P>
% {: o3 m/ F* [% n  H<P><FONT color=#0000ff>int lookup(int key)
: h5 m; k# C2 m: \8 s{
6 D' ~  M6 }9 C! S: F4 ^int *itemptr; </FONT></P>
! Q+ U/ O- [# \) r<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
/ W- u! t5 Y: R" n/ _is needed to avoid a type mismatch error at 4 A& v0 \* M; Y; ^$ p& q+ |
compile time */ : {  T7 J1 w8 I5 y3 e3 x- [' n
itemptr = bsearch (&amp;key, numarray, NELEMS(numarray), & ~' e3 ^& {. l# _, U0 ^
sizeof(int), (int(*)(const void *,const void *))numeric); ) k! m8 @, X- Y% k+ ^- q* f
return (itemptr != NULL); " M9 _% N% F8 U$ S" `* ~, x
} </FONT></P>' G+ U5 F) T, n( z
<P><FONT color=#0000ff>int main(void)
3 d1 L: w1 b& o' l# G{ & {9 z# \5 f& d, ]
if (lookup(512)) $ g  X0 f" _  P
printf("512 is in the table.\n"); 0 ?* ?+ p, U: k- @/ ]
else
8 a+ }$ i# @: r7 C8 \3 p+ l2 {printf("512 isn't in the table.\n"); </FONT></P>
1 n$ N3 L0 Y- V5 {& x* t! Z<P><FONT color=#0000ff>return 0;
6 B* b! i0 c& z. A! E6 M6 C} </FONT></P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5