数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:03
标题: 函数大全(b开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>5 {3 Y$ o' H2 e3 D0 W
<><FONT color=#ff0000>函数名: bar </FONT>
. n7 {  a; M" P" T3 r功 能: 画一个二维条形图
: Q5 ?- _3 J6 _2 J! L用 法: void far bar(int left, int top, int right, int bottom);   {* I# r5 t# j* Z& s
程序例: </P>
" U/ A$ W9 m1 I; l6 K6 }( G  O<><FONT color=#0000ff>#include <GRAPHICS.H>
  h% S' j- Y- ^" c( _/ T" G#include <STDLIB.H>
7 z3 a, g' U4 w  @( r! K#include <STDIO.H>
- e: k. T( s! W#include <CONIO.H></FONT></P>
4 Z; Q3 b3 ~; [# \( k<><FONT color=#0000ff>int main(void)
' N2 |5 ^# @8 j- t% ?{
# y0 g5 S$ ]2 B4 O/* request auto detection */ 2 N5 M) k% E# o$ H  ~  H
int gdriver = DETECT, gmode, errorcode; / f# c. s- a5 m+ V
int midx, midy, i; </FONT></P>
/ ^+ W' I9 f/ t<><FONT color=#0000ff>/* initialize graphics and local variables */
* C8 y8 X# ~& ^" b) @2 l* linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 |6 g3 q% C- Q1 d6 M- P<><FONT color=#0000ff>/* read result of initialization */ 8 v+ F8 W5 ]0 N% ~* s" ?# S
errorcode = graphresult();
  U9 E! _5 b' W$ }' Kif (errorcode != grOk) /* an error occurred */
. h+ d* {8 g% W{ " H5 G5 s2 Q4 p
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - l' [5 E/ O- }
printf("ress any key to halt:"); : D) Q5 S8 I. M  G5 Y
getch(); - G/ R0 P  s: F. T+ V& z3 B
exit(1); /* terminate with an error code */
+ X% S, k5 k4 }} </FONT></P># U+ ^) W' A5 F6 s
<><FONT color=#0000ff>midx = getmaxx() / 2;
- P0 w, d* `7 K: r& Y: J9 r" y7 Lmidy = getmaxy() / 2; </FONT></P>" I0 L* e) T1 Z. ]& d
<><FONT color=#0000ff>/* loop through the fill patterns */ 5 i: u9 _1 e+ S. y$ G: h1 V
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { " o) o8 q% F$ ~
/* set the fill style */ 4 o# C1 h' O+ t; [; d! q1 {9 |' X" L. a
setfillstyle(i, getmaxcolor()); </FONT></P>  t+ i# Z* _' F* y3 c4 D: R7 c0 _
<><FONT color=#0000ff>/* draw the bar */
( e" p6 b# I0 R0 p. p  _8 j" \bar(midx-50, midy-50, midx+50,
* d1 Y( G' k" i+ t/ C1 H$ Umidy+50); </FONT></P>0 N6 N& ^- Y$ r' A1 o
<><FONT color=#0000ff>getch(); 6 P, y& d9 S/ i7 X% U
} </FONT></P>
* e& c: R) J9 |; A7 Y* r<><FONT color=#0000ff>/* clean up */
1 n2 ^! F: w  y2 y; o0 Q6 fclosegraph(); ; F* q/ z9 Q4 c. |4 N# R
return 0;
2 J2 w* Q. E$ _& e0 y1 x4 R6 A} </FONT>& X3 p7 `+ i( v" `
+ }$ Z9 Z7 {1 y' q+ Q6 C
4 g  p( W; F% F+ o% i7 Z* l
</P>, m3 }0 _) o- g% h1 _
<><FONT color=#ff0000>函数名: bar3d </FONT>. [! C( p7 B9 x1 P  i- l; r9 G
功 能: 画一个三维条形图
' V' ?+ f$ C* b8 z/ C用 法: void far bar3d(int left, int top, int right, int bottom,
# G8 k5 }- l( vint depth, int topflag); 3 @8 }; j! v3 h
程序例: </P>
  S2 z" \( l" g. _) z( Q- Q<><FONT color=#0000ff>#include <GRAPHICS.H>
' y. {# q4 e( c+ i7 L#include <STDLIB.H>
, e) W2 w6 q: l6 Z#include <STDIO.H>
( S( }! }% `+ D9 n8 H! P#include <CONIO.H></FONT></P>
0 [1 q; P1 \  L% ~; _% }% N/ b<><FONT color=#0000ff>int main(void) 2 N# Z# I+ _8 x
{
4 M: D' N5 P, W: I1 _/ r2 T; A/* request auto detection */
; I: T; V& `8 Yint gdriver = DETECT, gmode, errorcode; & y9 R$ G5 u2 P$ _) C( H7 o& m
int midx, midy, i; </FONT></P>% P! a; h7 M8 y6 t/ [
<><FONT color=#0000ff>/* initialize graphics, local variables */
5 f0 V2 ]1 n: r- @* _initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ d# c  ?2 j. H# ?  Z4 J
<><FONT color=#0000ff>/* read result of initialization */
3 A* H& c- L, u& |0 R) h1 ?errorcode = graphresult(); & G* S) o4 S/ O8 Q: ^3 W! x
if (errorcode != grOk) /* an error occurred */
0 f" a4 F" M1 }: q) G  w4 {8 }9 {{
  v  E  o& c' o8 i( d& zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : ]4 ]7 H6 L3 h3 j4 g7 c
printf("ress any key to halt:"); " D$ `) O7 e# h$ L8 j1 G
getch(); $ W0 R; ]  U' v+ z+ W3 O# v6 t( m
exit(1); /* terminate with error code */
+ u9 f- Y" B7 n4 s/ N} </FONT></P>7 c5 a% A* m! J) ^" Q  T
<><FONT color=#0000ff>midx = getmaxx() / 2;
9 V7 W  d1 q4 ~. _2 `; @; Lmidy = getmaxy() / 2; </FONT></P>
( x/ m3 u" J4 s<><FONT color=#0000ff>/* loop through the fill patterns */
6 k' U( Y8 C) n  Z/ r% Pfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ( P) f, P. i! l. K3 S* @
/* set the fill style */ 5 X/ T8 I: L' C4 o9 p9 m
setfillstyle(i, getmaxcolor()); </FONT></P>8 b- Y) q9 h2 s/ K( Z& I
<><FONT color=#0000ff>/* draw the 3-d bar */
, a7 O( Z, C  V8 ~0 j) bbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
! l' ^8 ^/ ~/ Y, E! ?4 s) E/ J<><FONT color=#0000ff>getch(); 5 }5 f/ z# Y* Y5 P" L
} </FONT></P>: F6 r4 D5 {$ K4 u( b% a7 N5 e
<><FONT color=#0000ff>/* clean up */ 0 J% _/ N/ K+ p* W# t
closegraph();
) C* k) O, G2 F# r' Jreturn 0; 2 @% h( A$ X2 y
} 4 ?. a" d0 b! m0 S; t* h
</FONT>  _* g3 `. G; h# |( j: S& O" ~

6 P3 D6 l' v0 V</P>
; q0 j' h) i/ E  [2 H; v5 p8 w<><FONT color=#ff0000>函数名: bdos </FONT>
) {# D8 G6 b8 Y( X* t$ h0 |! U% e功 能: DOS系统调用
4 |) u1 e0 I1 `, G' _( J用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
3 g1 j; _$ |, X3 w" ?* n程序例: </P>: m8 g% s6 Y' L+ {
<><FONT color=#0000ff>#include <STDIO.H>7 ^% ~; F6 l: Q+ E5 _$ F
#include <DOS.H></FONT></P>
. @$ L) B: V5 F6 A0 A" s4 j<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
/ O6 f  r) s# K) W- ]  uchar current_drive(void)
/ l5 J/ d: }% D8 N( k# Q0 O( J" t{
% _% m1 R' @+ e, `$ \6 Vchar curdrive; </FONT></P>
& f2 a: A2 `) E2 u. ]% i% V<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ : i: z; _# E. _' y: D
curdrive = bdos(0x19, 0, 0);
+ k& G. u/ X3 ~9 {! b2 F  Treturn('A' + curdrive);
2 j& e: V: \) m8 Y} </FONT></P>
- i' y# T# O" x) v. f4 p<><FONT color=#0000ff>int main(void)
" f+ F5 ?% T* z( @' `- F{ 5 u9 x1 p- u$ F1 M2 r0 z  c8 J( M
printf("The current drive is %c:\n", current_drive());
5 n, p6 J/ U. T( o% n# ?1 Wreturn 0;
! ]" A* _) }- z  J/ o& X+ U* n9 y5 K2 `} 9 h: u1 m6 x  q, P. N2 y

# \& F1 p2 N/ H% P</FONT>
( ]$ z4 @% B9 Q0 L9 Z: N</P>. T: B  M5 P8 |/ v, Y$ r# j* k) n) D+ m
<><FONT color=#ff0000>函数名: bdosptr </FONT>9 U+ a5 V  ?& q9 i3 F) K
功 能: DOS系统调用
! \% P6 S+ p1 U' E0 W7 B% F用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
- I' d/ w/ _% E7 v* H. L8 Y( {* w程序例: </P>
3 }! k# O1 L# W+ k$ o: C<><FONT color=#0000ff>#include <STRING.H>& D! A. v% x  d+ |5 C, |
#include <STDIO.H>
1 N" P7 d" z* F5 X9 b- g#include <DIR.H>
, {# J2 a' l/ c& Z; i% {# X* r8 h#include <DOS.H>, {# u' X! h$ [; D( i; s: }
#include <ERRNO.H>
# j* M4 u- [- ~8 _- r#include <STDLIB.H></FONT></P>! s! e" d$ R1 e2 l. T
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
, h) j7 H% n+ T+ h  W<P><FONT color=#0000ff>int main(void) , b8 P1 w2 h$ S/ ?& Q& U6 e
{
8 L$ R; m0 R  f7 G. Y# @5 K: Pchar buffer[BUFLEN]; . c5 ]* Q7 G8 E- n
int test; </FONT></P>
9 v  m! F" m: y<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
: y2 U  D$ H6 S2 Ngets(buffer); </FONT></P>
1 b, I0 z) `) g8 q<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
; Y: E& L1 ~" y- R/ kif(test) ) {2 D) \: h# X9 U% g6 G3 m% h
{
" f. [  X1 ?6 \0 @printf("DOS error message: %d\n", errno);   Y6 e  L; }3 {+ c& V
/* See errno.h for error listings */
% ~! n2 L* I5 ]+ i9 T/ Mexit (1);
1 a3 s& H" d# ~; ]8 w4 Y- d* ]6 ?} </FONT></P>7 A( w1 S2 r: V& [
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 0 `( t3 W1 A- r/ d- L8 @
printf("The current directory is: %s\n", buffer); </FONT></P>6 j3 y6 h7 {! U8 s) r" w
<P><FONT color=#0000ff>return 0; " m' t8 U4 i. h% X% {. ^
} - K9 B& g; T4 h$ k) C* H
</FONT>1 C- P! c9 e: t: |1 I% d* b

" L7 @! V0 b* r; B& s! j</P>- m1 Z4 J/ S4 x2 c4 W' ~
<P><FONT color=#ff0000>函数名: bioscom </FONT>4 s: C* I0 G9 B7 Y0 r4 k* b
功 能: 串行I/O通信 * o. ]# [2 h( H) q% _
用 法: int bioscom(int cmd, char abyte, int port); / O% g" N0 ^. [& L
程序例: </P>8 K! R  @/ Q: G9 |  M  y$ d1 P3 `4 S
<P><FONT color=#0000ff>#include <BIOS.H>% V" `0 f" G$ l8 E( b
#include <CONIO.H></FONT></P>
, r1 r( I3 e3 q1 k) P<P><FONT color=#0000ff>#define COM1 0 , n/ q1 C9 K9 f/ Y  d/ m5 r6 R
#define DATA_READY 0x100
6 m9 }% w. O$ Q7 {#define TRUE 1 & M; z& V5 U: c- x( f
#define FALSE 0 </FONT></P>- f! Z- @/ e) m5 F
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>6 L* y% N, v2 c/ T8 q! J
<P><FONT color=#0000ff>int main(void)
& c) T' {  e) o, h' X{
  W# c0 M) C( x2 y1 ^# z: O/ yint in, out, status, DONE = FALSE; </FONT></P>2 x8 Q  d6 f# Y4 ^( J+ F
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
, X# W' Q, u, g. U! b9 a8 Ocprintf("... BIOSCOM [ESC] to exit ...\n"); : S* T' P5 c/ d; C7 D! U
while (!DONE) - k, y8 _; G! D$ e9 A, k0 X
{
5 {/ C# D6 m# V6 ?& hstatus = bioscom(3, 0, COM1); 0 C/ M* E  r, g' n4 I6 p
if (status &amp; DATA_READY)
; z1 [1 t0 m$ Cif ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0) & H- Y. N# O* P2 Y" r
putch(out);
$ S: r' K/ Y- `if (kbhit())
" ~$ @3 A/ ^2 R, D/ q{ & y2 S- h' x/ F- Z7 {3 j2 L# W
if ((in = getch()) == '\x1B') % i/ I6 r0 _6 G/ L- R. Z
DONE = TRUE; " s2 V# G, P. L; p& B
bioscom(1, in, COM1);
8 S& D1 a" ?9 t7 `} 8 M" Z3 ~9 w2 X; S4 H* [
} 3 D) v, ^/ B% Z! ^
return 0;
% f* S- J4 y# D9 l  z} </FONT>2 z; F1 V7 n/ A. y, h7 ~' Q

8 _, _' c( z( ~9 K4 C* ]! N8 E( N$ z  c+ f" F- A4 a
</P>
( K! V" e1 [2 \# T- a<P><FONT color=#ff0000>函数名: biosdisk </FONT>" U- F( I7 U+ g$ w' i* x9 |* S
功 能: 软硬盘I/O
. N2 y: X0 Z/ n- x用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
( Q' Z* `/ w- i8 sint nsects, void *buffer); 9 K7 ]9 K* S) J  Z1 {( X
程序例: </P>
' ?/ ~. f, P" ?1 \# y& i<P><FONT color=#0000ff>#include <BIOS.H>: `' A+ w/ p! k" y# r
#include <STDIO.H></FONT></P>
2 |0 B& X+ P# |; f% z4 B# \0 }" {<P><FONT color=#0000ff>int main(void) 0 r9 F0 F' v- j  g& O
{ # b. o$ ^0 G2 P" i* J% d: f
int result;
8 N& K& A- d# ^. G' F; K! l3 ^% ichar buffer[512]; </FONT></P>
8 s# [0 J  B4 k<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
2 e- q+ c. L; ]5 Q& z5 ]result = biosdisk(4,0,0,0,0,1,buffer);
& Y$ [) a; E( X% l6 x* m. {result &amp;= 0x02; 9 z4 K, h4 C( G% G8 Z
(result) ? (printf("Drive A: Ready\n")) :
% W. a2 q5 ^, d. x/ u(printf("Drive A: Not Ready\n")); </FONT></P>
$ e* o4 _6 F4 a3 b, p<P><FONT color=#0000ff>return 0; 7 U4 c9 b! y& Q$ ?& n2 q3 K; a: b
}
. ~; T7 F) M5 j! H</FONT>
+ Y3 ^0 m& E7 c$ e! w1 ]1 x. k8 F0 H
% Z3 Y2 Q% ]' M3 L; P4 W* ^& P</P>
) h( {# f4 l. H  g2 s( V<P><FONT color=#ff0000>函数名: biosequip </FONT>
/ t; X& M* U0 B功 能: 检查设备 , z* [4 V2 Q# I6 [! e
用 法: int biosequip(void);
" ^/ ^, b$ E' _' ~: t4 R" @程序例: </P>
" G0 s# |. d' c" ^6 Y( j- K<P><FONT color=#0000ff>#include <BIOS.H>. V: E. K& }0 f* n
#include <STDIO.H></FONT></P>
% A% f  j1 C$ g& m4 T9 {9 @& |<P><FONT color=#0000ff>int main(void)
% |0 S/ K! g9 t1 N8 K, r& G; O{
' b2 h' P+ d. X& S1 \5 A4 sint result; 2 P9 Q: s5 `- c7 i3 p8 N
char buffer[512]; </FONT></P>, [! u* s) n( i7 W, P7 D; x
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 6 L% G7 i- p; K( p
result = biosdisk(4,0,0,0,0,1,buffer);
1 M" P# a5 u% H7 A1 ?: Qresult &amp;= 0x02; $ a6 S3 B1 k3 q' ]. v* T) ?! m* G
(result) ? (printf("Drive A: Ready\n")) :
* g4 u8 L; _. o3 e(printf("Drive A: Not Ready\n")); </FONT></P>
, I6 l$ |( ^9 B<P><FONT color=#0000ff>return 0;
9 e0 U( P% O# T* {  V4 ]}
' B$ a  d6 ~2 @/ M2 g% ^4 k</FONT>& C4 @/ B) p( o) R! v6 N6 n

: L0 d: [$ R0 h</P>
, J: V. m) p+ a- x& ~6 v: J) j# d<P><FONT color=#ff0000>函数名: bioskey </FONT>9 O% P: d  j$ s% o% n. O! `: S
功 能: 直接使用BIOS服务的键盘接口 5 N' T4 u) w9 l8 a( v; K
用 法: int bioskey(int cmd);
; r6 O4 @$ N9 U/ r( c程序例: </P>
% t1 B3 ^% ]! F$ g<P><FONT color=#0000ff>#include <STDIO.H>4 t' A* |5 S$ u$ q% E
#include <BIOS.H>. i' }$ x) i, A. w
#include <CTYPE.H></FONT></P>
7 l8 O9 E/ h; R" k$ q<P><FONT color=#0000ff>#define RIGHT 0x01 / `  b# w2 B% v2 v2 Q8 H) [+ z
#define LEFT 0x02
( r/ R' ]  ~, ~& ?2 }1 Y) O#define CTRL 0x04
; {+ F4 h: a# H, u- |5 i+ l) J  {#define ALT 0x08 </FONT></P>8 h- M# s8 T, M- `. p
<P><FONT color=#0000ff>int main(void)
/ q1 E" M& ?/ K3 w) W9 r$ ^! f( V{ 8 o7 i$ r! O( G" U. k+ F- T
int key, modifiers; </FONT></P>0 J4 V1 X5 X1 Q8 T8 n
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ * k. T8 p3 v2 T6 P! i
while (bioskey(1) == 0); </FONT></P>( S, z( L/ L3 f
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ 5 E1 t5 e8 @( n8 D" W2 c
key = bioskey(0); </FONT></P>1 V3 J, u+ B  }& x1 w
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ / B5 P; q$ b7 P) Q( c; z
modifiers = bioskey(2); , e/ @* ~& C: |9 M+ L
if (modifiers) . K4 H" E& ^" h
{ 3 y/ c" ]* _( E) t! _+ l: x- U
printf("[");
; w4 d& U* U2 x' p" k5 Jif (modifiers &amp; RIGHT) printf("RIGHT");
5 F8 E6 U# M5 N8 h8 U7 gif (modifiers &amp; LEFT) printf("LEFT"); , v% q" G5 ~: q) w, k/ `  x
if (modifiers &amp; CTRL) printf("CTRL");
) b/ R) @6 E. |, xif (modifiers &amp; ALT) printf("ALT"); 0 C( {- d2 a& A( |; U7 L* M) x8 H8 p
printf("]"); % L; |9 a0 n: c3 a5 ]  C
} * R/ f" r( j  m+ n" n) ?: ^* s
/* print out the character read */ 4 G9 S7 W  K: @" a0 Y
if (isalnum(key &amp; 0xFF)) ; s& g0 C, d+ x1 X( A
printf("'%c'\n", key); . |; ]7 O6 [' C; K
else
( ^4 T4 `9 d1 _6 `) Q7 o. \8 Qprintf("%#02x\n", key); 7 d2 j* y) ~9 U( l% Y4 \5 k) ?
return 0;
" t, U7 G4 p% N4 c$ \, a} 5 {6 z  C+ Y$ P" ^4 D. P% i

3 R- R  ]5 ^( Z( [</FONT></P>
2 l& f' V/ A) V" D) o) j0 `<P><FONT color=#ff0000>函数名: biosmemory </FONT>
# j4 n' e$ {+ N0 p3 [功 能: 返回存储块大小 7 T) C* y' @# q( M4 j( a
用 法:int biosmemory(void); $ |, X. [1 i$ ?' l5 q2 u; T
程序例: </P>
2 P9 u9 a" Q1 T$ U. D$ m/ G$ j* n<P><FONT color=#0000ff>#include <STDIO.H>% I7 [) p  ^+ r% z; Y1 Y
#include <BIOS.H></FONT></P>! g5 O+ n# N( ~/ u& ^  y& H
<P><FONT color=#0000ff>int main(void)
) V7 \8 g* w- |5 g% ~{
/ b; X9 x& [, P/ y0 ?. w0 l0 r: M0 Aint memory_size; </FONT></P>3 X3 A" v5 J' e' C
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
" E+ O+ a. L" }" s) F( ?8 Vprintf("RAM size = %dK\n",memory_size);
9 }: W7 K( d( N7 d" {return 0;
9 A9 N) q3 z. T, _" p# }2 n} 9 J% b& F' B6 f4 j
</FONT>
8 r1 Z/ U' J: ?$ N0 b
1 [0 ]" m; F( l( e</P>
* i& B+ X$ z5 ^7 Q<P><FONT color=#ff0000>函数名: biosprint </FONT>
6 x4 q- X  i" X; V7 v; g( E功 能: 直接使用BIOS服务的打印机I/O 9 d" \* e9 g+ U
用 法: int biosprint(int cmd, int byte, int port);
* ^4 n2 i2 Y% ^. q( Q" M程序例: </P>
/ c  s" b. w4 d- I<P><FONT color=#0000ff>#include <STDIO.H>8 [8 y' x; O9 l0 t2 f
#include <CONIO.H>5 d# |% p; @  |4 @
#include <BIOS.H></FONT></P>
* ~5 Z) C" S) G5 X) C0 f' [) H<P><FONT color=#0000ff>int main(void) 8 F7 F5 _5 Z6 e) J. r
{ 4 m" S' v8 Y4 V; S' ^
#define STATUS 2 /* printer status command */
4 H! O0 T8 t9 J( F9 @" a0 X#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>, i+ [$ J/ s% c
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>0 u* }* F& B/ _6 f
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
+ O4 K& I1 r( A% dgetch(); , I! i/ B; g% L0 X  k/ o8 L
status = biosprint(STATUS, abyte, PORTNUM);
+ R% R. I  C$ ^/ x# Sif (status &amp; 0x01)
' ]9 x- T, i* P( P8 F# _printf("Device time out.\n"); 5 r9 l# s5 t- a! a3 H
if (status &amp; 0x08)
% i! y) j5 d9 }- u7 `printf("I/O error.\n"); </FONT></P>9 ~, J& P9 h: A6 S. x! V
<P><FONT color=#0000ff>if (status &amp; 0x10)
  w/ Q, @+ B' H+ {4 q1 |) v8 cprintf("Selected.\n"); ! q! J$ Z  f. i( q9 h
if (status &amp; 0x20) ( P; s: m; S3 M' p4 ^
printf("Out of paper.\n"); </FONT></P>
! I8 d* R* J$ }. C<P><FONT color=#0000ff>if (status &amp; 0x40) ! {! G% [$ Y! r2 q: I. v! A+ B( Y
printf("Acknowledge.\n");
5 m3 P/ C/ l  Q% u6 K& iif (status &amp; 0x80) ( f  [6 i/ R8 ^0 H) t. S
printf("Not busy.\n"); </FONT></P>
0 k' V+ i$ n$ S% o; y; _6 e& s<P><FONT color=#0000ff>return 0;
; B5 f# U, l% a  r} - m  y& F/ B2 q( w+ d  z
</FONT>$ q1 [6 G2 \0 f

7 W( K1 ^% }& w* L" S# ~6 F0 p4 R5 k</P>* s2 m  g/ v2 b- p! K. J: a  r
<P><FONT color=#ff0000>函数名: biostime </FONT>" U6 ~. t7 ^8 H. V, E
功 能: 读取或设置BIOS时间
/ e% `5 j% I* ]2 [用 法: long biostime(int cmd, long newtime); ! M5 z! ~/ u7 R1 o
程序例: </P>( y( _' ?) X, t- j' h% o
<P><FONT color=#0000ff>#include <STDIO.H>
+ k' N7 q, `9 e/ X" j3 P+ n#include <BIOS.H>8 C/ D* F5 M, k, x) I; V
#include <TIME.H>
3 Y: M; ?% P* D- {# n#include <CONIO.H></FONT></P>
& J8 D* p& G. N<P><FONT color=#0000ff>int main(void)
' i. t2 T  a/ R/ z- s1 ?- O( _{ ! _6 E, k) G) @& w+ B& g
long bios_time; </FONT></P>
  e- J) {  @. O2 ?. _1 d! A<P><FONT color=#0000ff>clrscr(); 9 Y0 p$ @  \. j  |8 g0 J/ B7 z
cprintf("The number of clock ticks since midnight is:\r\n");
0 I  m' z3 @2 q' [1 ccprintf("The number of seconds since midnight is:\r\n"); 7 T* N; V  D3 t* _/ {, b8 N- M
cprintf("The number of minutes since midnight is:\r\n"); 5 d2 X% W$ c& A, P) T, g8 j
cprintf("The number of hours since midnight is:\r\n"); ( W4 m" z1 u- u9 I, I
cprintf("\r\nPress any key to quit:");
9 D# J6 k# R7 nwhile(!kbhit())
) t. E+ L" B6 c' u8 G4 P{ & U7 {; @: b: t
bios_time = biostime(0, 0L); </FONT></P>
1 p9 e' `1 L- {3 _# [- p( t: M0 y<P><FONT color=#0000ff>gotoxy(50, 1);
) J6 Z- j7 \; d; W9 m2 D( \1 P3 Qcprintf("%lu", bios_time); </FONT></P>. n6 U+ Z& }6 h6 n* z% }7 ^' n
<P><FONT color=#0000ff>gotoxy(50, 2); 9 z- N" u7 O9 D9 t! \0 j, l9 b
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
9 a9 B3 H- x& Q& m4 z<P><FONT color=#0000ff>gotoxy(50, 3); & z9 e4 a9 Q# ?% I5 H: b
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
8 o4 h! F, g1 l) e# q( S' `<P><FONT color=#0000ff>gotoxy(50, 4);
$ l& Y( D- C3 m6 R+ V9 L2 \+ Kcprintf("%.4f", bios_time / CLK_TCK / 3600);
; F7 R' N& H" Q7 Q% O- E  E+ E}
+ |, n/ {% z: {' @7 D3 ~return 0;
2 ?5 J' ?+ m9 f5 m2 p5 U) ~: E, k: j} $ I# m2 W1 _: Y9 d' s" b
</FONT>; X5 @! ^3 _: Y# E; ?% d/ L9 m

: l2 @, e% X( {3 l</P>
& a; U, H, {3 \<P><FONT color=#ff0000>函数名: brk </FONT>
+ c0 Y/ G( i+ G% T; `  G功 能: 改变数据段空间分配
" S3 g% B3 `0 M$ v- u用 法: int brk(void *endds); 3 d- K0 o  w" B8 [- f, V& m( P$ q9 Z7 s
程序例: </P>
2 n) n) d# P2 R: P! X0 q<P><FONT color=#0000ff>#include <STDIO.H>
! S+ m9 W- N# {4 A* J/ h; G#include <ALLOC.H></FONT></P>
& }+ _  O4 P0 M9 p7 r<P><FONT color=#0000ff>int main(void)   X7 u- l. _0 z% X( L
{
' ^; Y' K  C3 E1 X6 F4 P: Achar *ptr; </FONT></P>. T9 k3 U: j1 T
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
  L) S# m, j3 O/ `  L/ W  hptr = malloc(1);
, {) ]; j7 j& Rprintf("Before brk() call: %lu bytes free\n", coreleft());
- [0 d7 h' W  \brk(ptr+1000);
$ Q2 W' |  M% y* Vprintf(" After brk() call: %lu bytes free\n", coreleft());
- o) x# y' t" M1 g% B4 Q* M( Z# ireturn 0; ! Z8 m$ u! b8 [# |+ a+ P$ Y7 ]
}
$ s# B3 w8 I4 p4 q5 l2 h6 _) I7 v
</FONT>
. O& x$ i9 C3 a</P>
3 r4 w( W$ ~# S+ R<P><FONT color=#ff0000>函数名: bsearch </FONT>' i/ m: d& }# d5 `: s. j5 |
功 能: 二分法搜索
3 w0 v$ W2 |3 g% u: {- C! W; {用 法: void *bsearch(const void *key, const void *base, size_t *nelem, ( h" s( U) A* C) {( F# u& w5 w
size_t width, int(*fcmp)(const void *, const *));
0 T; c/ D/ e( C% [( W程序例: </P>
, F& C, e) [4 F4 `<P><FONT color=#0000ff>#include <STDLIB.H>  i/ I, B. G% r' y9 I
#include <STDIO.H></FONT></P>
4 Z  t" v' i- m<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>4 p. \$ N+ |+ X1 x* I9 t2 t
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
) c2 h7 K7 R$ ~+ M$ Q9 P* ~. B! W<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) # n# ]) F- ]0 ?! M6 w% n# t
{
+ s4 `7 ~' s* S! W3 Greturn(*p1 - *p2);
" p/ R$ F8 Y6 N" _2 H$ M! k& z* b} </FONT></P>
9 {1 T( g/ @4 m1 R1 e<P><FONT color=#0000ff>int lookup(int key) ; |( u" h5 a. l3 T5 }
{
$ c- |) `. M$ ^/ Sint *itemptr; </FONT></P>
% n7 F* B8 l  S3 S7 f6 m<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) 4 W$ u: R1 \( I
is needed to avoid a type mismatch error at 7 ^' D! c, Q) M' ^3 W4 B
compile time */
: Z1 S1 o$ v& A; T  Vitemptr = bsearch (&amp;key, numarray, NELEMS(numarray),
+ Q. q9 f! L! C, i' p. u3 k, ksizeof(int), (int(*)(const void *,const void *))numeric);
& N5 U# F! t7 [' b( x+ j  zreturn (itemptr != NULL);
% j8 F# T  V2 {  c1 K" S} </FONT></P>3 ?0 v* Z1 ^& U" |3 j+ W
<P><FONT color=#0000ff>int main(void)
. x" o" i9 o& |$ X. g{
- i9 P4 h( P; {if (lookup(512))
5 ]0 c$ c0 k; \3 U$ Uprintf("512 is in the table.\n"); 7 D1 l; T' S: w! c& e
else 8 I8 s; t% _1 k/ \) L, j# i
printf("512 isn't in the table.\n"); </FONT></P>
" t# D# ?! J% v% e* X' ~+ |0 {<P><FONT color=#0000ff>return 0; . Q+ x4 u* F4 E, a$ c& D9 Z
} </FONT></P>




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