数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:03
标题: 函数大全(b开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>- B8 a% O7 i- J# X% n! K3 {& r* p
<><FONT color=#ff0000>函数名: bar </FONT>
9 \/ P, k% h5 C9 h& g功 能: 画一个二维条形图
' j$ R$ a8 W  F8 m7 z7 \用 法: void far bar(int left, int top, int right, int bottom);
8 s0 n' ^" C& ?* B程序例: </P>
  I9 H2 v5 D. s% R9 p<><FONT color=#0000ff>#include <GRAPHICS.H>
/ i# \3 J2 p" k' T#include <STDLIB.H>6 e( Q7 [* Z6 u2 i
#include <STDIO.H>6 m* m& D( s# j# S) x$ _7 G$ X
#include <CONIO.H></FONT></P>! A+ v3 a' p+ S( r, `: S& S
<><FONT color=#0000ff>int main(void) : Y8 W2 s, j6 g3 `* x' s) ^
{ . f* ~# g6 L( @# ~
/* request auto detection */ : |+ O, j, b  f1 w  ?
int gdriver = DETECT, gmode, errorcode; / I! J3 z" K5 m% ]
int midx, midy, i; </FONT></P>1 ^0 S/ e) @. O
<><FONT color=#0000ff>/* initialize graphics and local variables */ 3 ?& B. e' z$ q- }+ V% z8 a0 i0 r. f. J
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; `* i# A* ^+ @& g<><FONT color=#0000ff>/* read result of initialization */
" v3 u' n' o( P8 k( X9 Qerrorcode = graphresult();
( }% \0 N3 ]$ l- {# bif (errorcode != grOk) /* an error occurred */ & V: b, B# _" {* o
{   N  r8 y$ W: v. C) D; s
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# ^* U: u/ \) B0 \printf("ress any key to halt:");
7 i  A0 Z1 S6 `; S' bgetch();
1 W- c( J* C0 Q; N4 [( Dexit(1); /* terminate with an error code */
: y( x! F, j! _} </FONT></P>
. I: G1 q( v+ D* a' e2 W8 S<><FONT color=#0000ff>midx = getmaxx() / 2;
- N2 W8 L  W' T6 smidy = getmaxy() / 2; </FONT></P># _. J$ k. ?# l: s3 z! Z6 d4 E/ N. f, y$ V
<><FONT color=#0000ff>/* loop through the fill patterns */
. E: F& G% S+ L% Q8 Yfor (i=SOLID_FILL; i<USER_FILL; <br i++)> {
' b8 s: Q" m1 U; J) ^% G, D/* set the fill style */
% o: e* S7 `/ m# L! vsetfillstyle(i, getmaxcolor()); </FONT></P>
8 I- ?, `* G1 |7 @* P+ x; i7 O+ o<><FONT color=#0000ff>/* draw the bar */
0 o1 q6 U& O% f0 sbar(midx-50, midy-50, midx+50, 6 @* j1 s/ f$ f
midy+50); </FONT></P>& g3 G2 X; R5 V. t
<><FONT color=#0000ff>getch();
/ Q0 c  A' Y( ^) R3 s} </FONT></P>: A! C0 O, l9 x$ D
<><FONT color=#0000ff>/* clean up */
3 x/ h, e( Q( Q$ }closegraph();
' @+ H( C8 M* s% T5 ]- qreturn 0; 1 g8 U# c, e+ [6 b' E: x( E0 n7 y& D
} </FONT>1 o% |4 }. x) P; @+ O9 ^7 a
% _: @5 r: D# y1 k

% w5 o3 i7 y5 s6 c( l3 f% j) ?</P>
+ Q* J6 i& A6 R<><FONT color=#ff0000>函数名: bar3d </FONT>
6 X* f4 C$ q6 H  j. M5 p8 z+ I# a  _6 h功 能: 画一个三维条形图 4 P# o; E; W* y0 `
用 法: void far bar3d(int left, int top, int right, int bottom, * L' e, m- l+ \, K* z# H
int depth, int topflag);
5 T) G3 O  D4 A, F$ y) n程序例: </P>
, }$ x/ S" d4 W<><FONT color=#0000ff>#include <GRAPHICS.H>
( g, \% p+ H; \$ }5 g+ s$ |#include <STDLIB.H>
. i9 M- z/ d2 r4 K) T/ K#include <STDIO.H>/ M' s+ ?  ]0 g3 L; u
#include <CONIO.H></FONT></P>; j9 ^( h1 K' ?% A
<><FONT color=#0000ff>int main(void) 9 Z1 G! F0 M8 z; J4 X5 b
{
  _5 y6 q8 ?1 U+ @/* request auto detection */ 6 b/ d. s! W  t+ f0 ?- V+ ~. J. ?
int gdriver = DETECT, gmode, errorcode;
7 o3 w/ c) T! Uint midx, midy, i; </FONT></P>
& S) Y7 w7 a. v2 o3 V2 j" L' J<><FONT color=#0000ff>/* initialize graphics, local variables */
8 D! }7 ]" T4 k; U" h0 V% kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; y; s% |9 O, x& F8 d" @* S* z<><FONT color=#0000ff>/* read result of initialization */ ! e6 L/ [! t8 x" m- y1 A8 ~) H; C1 R
errorcode = graphresult();
2 f& @  l# f  u: D, o0 g3 r& |if (errorcode != grOk) /* an error occurred */ - m4 `! X# J# u
{ % z- S; p' d6 w
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* O$ d6 F1 n, T4 m5 x3 \+ xprintf("ress any key to halt:"); " X! d0 }% c+ v
getch(); 5 `5 ~4 w( c$ p  b- G+ I" ]$ v- h
exit(1); /* terminate with error code */ 3 E/ Z* Z: H- w3 B5 \
} </FONT></P>
5 W1 ]3 Z! u5 f  F' x<><FONT color=#0000ff>midx = getmaxx() / 2;
' g9 r/ e# K! ?  Y3 Hmidy = getmaxy() / 2; </FONT></P>
) H+ L$ s" z  w9 z<><FONT color=#0000ff>/* loop through the fill patterns */ 0 b% m5 D% U' F
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
+ _  w) c% h1 Z5 L4 _6 _/* set the fill style */ + w, f7 X1 M" J: Y
setfillstyle(i, getmaxcolor()); </FONT></P>
, l2 d; }! `. z4 ^  ?<><FONT color=#0000ff>/* draw the 3-d bar */
" c/ ~6 V; T0 R1 a. |! M8 V8 Tbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
8 Z- n1 O; L( r7 g# B. l& ^  `<><FONT color=#0000ff>getch();
+ F0 K7 x5 y6 G8 x1 G5 h} </FONT></P># T6 o$ g1 K! k# A& g2 |
<><FONT color=#0000ff>/* clean up */ - ^1 u8 ], {. O* `
closegraph();
$ _. f5 @2 b" u+ ?5 ]) ]$ I/ Freturn 0;
/ [9 Q! k# [; t8 E}
" e) C+ w# [  o- r" v6 u</FONT>
6 W, W4 y. f% W4 Y- Z, K; r6 j& H" W4 y) }
</P>
  b1 P- E1 s/ m7 U2 C<><FONT color=#ff0000>函数名: bdos </FONT>' h7 y; ^. `' e# A  a
功 能: DOS系统调用
5 h$ x/ X  ?& V9 r" A$ D, `用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
6 v8 c: t* O3 J# }" B( }程序例: </P>
% ~% W6 W& z/ ?  @8 z3 o# a<><FONT color=#0000ff>#include <STDIO.H>) a" s. A: p7 |2 f  ]
#include <DOS.H></FONT></P>
* @8 ]: a2 |! x+ H0 W<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
4 G8 A+ x( z  O+ D3 X. ^# s# n: }char current_drive(void)
2 H9 p0 a+ ?1 v- o* c' [{
6 x- V& E, D2 Mchar curdrive; </FONT></P>; n( Z& [) @2 D8 f6 X1 w4 k0 P
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ % P4 {4 ]7 j) g: C7 A4 I
curdrive = bdos(0x19, 0, 0);
$ f( m0 h/ q4 a6 v- D1 \9 n5 t9 x. Freturn('A' + curdrive); 7 {, N8 I! v( V3 x9 p0 s7 q
} </FONT></P>4 G3 _. l0 J, C
<><FONT color=#0000ff>int main(void) / Z. I2 e2 x1 Q8 z0 A& V
{
9 F  H$ y6 r, V' Qprintf("The current drive is %c:\n", current_drive());
/ W. K0 ?# a8 A  a: ?2 Nreturn 0;
3 p" V1 }, M: d( T} 4 ~( p' l# E! h
1 N2 y! S7 s% e: M% o
</FONT>
' A- @6 b& U1 X$ B* }2 z</P>  b3 W( ]+ m  V. N* n1 n
<><FONT color=#ff0000>函数名: bdosptr </FONT>1 H& n/ G" m. ]* d$ \
功 能: DOS系统调用
7 c8 I, G: }9 b0 \( E* ]' `6 }用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);   x: T  p0 m8 R+ ?' M2 {
程序例: </P>
. {: }. r) |: d; N/ \<><FONT color=#0000ff>#include <STRING.H>
9 m& W$ L/ x! _+ f9 B0 t- ~, I#include <STDIO.H>
) i& O# i! j3 F" v- K7 I#include <DIR.H>) y6 h8 \& r0 I) c5 {- m* W1 S( d
#include <DOS.H>: ]( O) j; R, {  D% u# q
#include <ERRNO.H>
& s: O+ x/ T  t7 Q- d, G3 d4 T2 ?#include <STDLIB.H></FONT></P>
/ R+ U  o5 K6 a& r2 @  ]. p<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
" w, Z/ m- v5 a8 p) ?- R<P><FONT color=#0000ff>int main(void)
0 J* O3 a! f6 @{ , Y0 _- C4 t' w
char buffer[BUFLEN]; , @. O* @6 M0 [8 N
int test; </FONT></P>; _! h" w" ]' k, C2 C
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
; W1 ]. l  x! }! t4 {. B9 T3 B% jgets(buffer); </FONT></P>
, }. l5 ~1 D8 ^<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
6 Q9 p" C! P6 b5 ]3 yif(test) 4 q/ p; r$ N3 J" W; s0 x
{ 5 J5 \% |) P7 [
printf("DOS error message: %d\n", errno);
6 e* ]- R& q5 i1 X2 N( @/* See errno.h for error listings */
( M$ |: V' z  X& l( Wexit (1);
2 l6 T1 U* G- b8 p" [} </FONT></P>
5 ]& ]# ^( X, M1 [* Y: f<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
. V( H4 F$ g1 I% Jprintf("The current directory is: %s\n", buffer); </FONT></P>
, M% w4 ?" s: ^! g$ o( k<P><FONT color=#0000ff>return 0; 3 {. r: Q7 r: y* h  P
}
: E" {7 S. y) q& @</FONT>
, u8 v  P5 d; Q+ c
' u6 A" d1 P# k6 m* C</P>' [$ M9 M5 x3 I- k/ j: ~, T/ K) A
<P><FONT color=#ff0000>函数名: bioscom </FONT>/ B6 L. _$ E+ L# l" P% Q, B
功 能: 串行I/O通信
" ^7 |! D: {# H$ K7 n0 e用 法: int bioscom(int cmd, char abyte, int port);
$ T) R2 h) o( i3 T( z4 G8 U程序例: </P>1 _" x$ n& N6 {1 `
<P><FONT color=#0000ff>#include <BIOS.H>9 R* A) A( w- [  A0 v5 }
#include <CONIO.H></FONT></P>, E9 o% |3 \% r5 N
<P><FONT color=#0000ff>#define COM1 0 ! S) R9 Q  j8 |& _. R
#define DATA_READY 0x100
$ M2 A) d! z- N$ {0 Y#define TRUE 1 4 t% K# z9 c/ h/ q( U
#define FALSE 0 </FONT></P>0 V6 `; p0 Q  r2 C, H
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>+ ?% z% l8 [# {, u: c5 P. y. h$ T
<P><FONT color=#0000ff>int main(void)   i) m* N* N8 \
{
& v+ I5 s( |9 c; {int in, out, status, DONE = FALSE; </FONT></P>
0 ]. r4 o* q# H% N9 E. B<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
% [4 h6 w, _4 W% ?2 {cprintf("... BIOSCOM [ESC] to exit ...\n");
% @! Q' w( S+ S" _while (!DONE) ( _: q; s  f, N' g7 X' @
{ % e; z; ]8 l. q9 H( h1 C+ V9 o
status = bioscom(3, 0, COM1);
5 u( K" ~. v# P" F8 C, p! pif (status &amp; DATA_READY)
7 V' l9 G9 f" w& [$ z! o* eif ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)   }1 s/ ?; J* }. g6 i- _$ x
putch(out);
) B$ m; y5 s" C! zif (kbhit())
; [4 i) s- f! c6 s2 O  _6 Z% B{ ( ]0 h" q( G8 G  i% ~4 s+ N# {9 g; m
if ((in = getch()) == '\x1B')
+ @5 g. k" X  H' f+ k- i. cDONE = TRUE;
9 ?8 J  o) l# W5 _9 x7 |( ~4 a+ |bioscom(1, in, COM1);
# u+ o9 r1 P" O* L4 G}
4 m: P% e! o7 e5 c. F}
  f& t9 Z7 Q4 [4 _( k7 I, hreturn 0;
$ D+ T2 A7 E2 Z: a) G} </FONT>
. V) @0 y/ o4 Y+ W  [3 B7 t& n# @4 h3 |: A
+ ~( w. z8 h. X4 }8 y- D( B
</P>
8 o3 H8 a5 ^) u2 t8 H+ L<P><FONT color=#ff0000>函数名: biosdisk </FONT>: t$ |+ \5 Q7 h1 K! d! l, Z
功 能: 软硬盘I/O
' I- A& ]) q8 F. V3 O% M1 S用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
: L5 z% A: t0 r4 B/ q+ Mint nsects, void *buffer); $ {  _# {4 V: }% h+ Y5 N9 O+ V
程序例: </P>1 H4 Q7 b- O/ H) Z
<P><FONT color=#0000ff>#include <BIOS.H>
1 F' C3 C* r# |9 F4 `( H; `7 K#include <STDIO.H></FONT></P>/ r  J& ?" M& U+ y+ s2 z; N1 ]
<P><FONT color=#0000ff>int main(void) 4 d/ @+ e* `1 V: @2 {: @
{ $ @) ~! [4 D  B. g  b& @& Z
int result;
5 U2 M* T$ z; W2 m0 H! B" o% ychar buffer[512]; </FONT></P>2 k! }$ [' B1 B$ L$ }5 v! l: X
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 4 N- R  l. m* I
result = biosdisk(4,0,0,0,0,1,buffer); / t0 ?7 Z; {4 r0 }# X. M7 S
result &amp;= 0x02; 1 a" f+ N' E7 c$ V
(result) ? (printf("Drive A: Ready\n")) :
+ Y  m1 E8 i4 @) F+ }8 X6 \(printf("Drive A: Not Ready\n")); </FONT></P>
2 T; n7 V4 F4 b. H% o: V. ]) g/ d  F<P><FONT color=#0000ff>return 0;
8 j( |7 u# r# u. }% x: o} $ Z* @8 X# m. D2 Z
</FONT>1 \8 c& J0 ?( f- e/ i+ b5 t; A% ^
1 G# E, Y9 w' u/ Y3 ]( F
</P>
" E# `$ h" M" H2 |, N<P><FONT color=#ff0000>函数名: biosequip </FONT>
3 \; ^# M# A. R2 @1 J' ~6 ?功 能: 检查设备
0 g5 V. h" T; k# O3 d, {, `用 法: int biosequip(void);
8 k5 q6 x5 ]9 m/ n6 w( R% Q! p8 f) E程序例: </P>6 C+ _) n! f4 _: J; R' X, p
<P><FONT color=#0000ff>#include <BIOS.H>
/ I4 @3 \2 p) M* l1 t1 P4 I#include <STDIO.H></FONT></P>9 s: \; l4 D) n0 F+ h/ s3 E
<P><FONT color=#0000ff>int main(void) 4 s; E: P5 V% a/ f/ g7 M
{ 0 i* O% t4 T/ ~+ }
int result; 0 i2 E: o1 _: a( F& `$ \( R6 m- `( b- Q
char buffer[512]; </FONT></P>
& I7 O" l' j: C. p% f( O5 Q<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 5 }. r/ P9 o4 g% O; c! p# J
result = biosdisk(4,0,0,0,0,1,buffer); / H. z6 L, W7 R$ X% D% L- S
result &amp;= 0x02;
/ [6 J/ f2 j; a2 y7 T(result) ? (printf("Drive A: Ready\n")) :
/ C) Q+ k1 G+ M, _+ W(printf("Drive A: Not Ready\n")); </FONT></P>( ~/ T6 F0 p4 N' u1 t
<P><FONT color=#0000ff>return 0;
$ G' ~3 R! x8 A( z8 m0 o}
% s' i. Q6 X" Q</FONT>
1 f& n3 f! M) @/ m4 Y& ]4 h
# f+ y9 C5 d1 L/ a2 m0 T</P>+ v% l  d8 ^# \( x
<P><FONT color=#ff0000>函数名: bioskey </FONT>
, J) \5 w- u( v" [: x功 能: 直接使用BIOS服务的键盘接口 ' |3 `2 m0 i# k" S/ e$ c" {
用 法: int bioskey(int cmd); ; O% t. t9 `# h. M
程序例: </P>+ C9 o1 m5 n7 r; j1 M' d0 \
<P><FONT color=#0000ff>#include <STDIO.H>
. A. F; H9 g3 ~" T$ W#include <BIOS.H>' e. |+ M8 T8 g% a+ S( T
#include <CTYPE.H></FONT></P>
/ T! k3 k, v" f; x6 L<P><FONT color=#0000ff>#define RIGHT 0x01 6 O& Q0 c; `! }$ ?% j
#define LEFT 0x02
, U$ p( A( l& s; H#define CTRL 0x04
" Y! A2 E/ Y9 b" K& F#define ALT 0x08 </FONT></P>3 t* {4 [9 i4 Z1 c, z
<P><FONT color=#0000ff>int main(void) , J. I* t/ Z7 t' b1 P9 Q
{
" \0 V+ Q& l" {1 |int key, modifiers; </FONT></P>7 }) V+ g4 G0 D, q% ?
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
1 l2 V6 o0 W/ z# o7 zwhile (bioskey(1) == 0); </FONT></P>. S/ w/ j7 Y  t
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
, S3 a* l/ O! w2 G! e1 L) ^- nkey = bioskey(0); </FONT></P>
+ V' i# ?, r8 q* k- t3 I1 J<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ ! O! T- @/ R  |) ]& |$ c5 O3 Q
modifiers = bioskey(2); # L/ m( i) B4 q- V! E
if (modifiers)
, b% m) B/ w9 \$ p- P7 f5 w{
. r& \" x7 _5 g" Y. kprintf("[");
* F! s2 @8 |* \* _8 k8 |2 u$ _if (modifiers &amp; RIGHT) printf("RIGHT");
8 o" [* Y- ]' v2 e0 hif (modifiers &amp; LEFT) printf("LEFT"); / ?+ B- s" c  C5 Y5 G' c0 o
if (modifiers &amp; CTRL) printf("CTRL"); ! J+ Z4 q; B" \( O& G; t% k0 m
if (modifiers &amp; ALT) printf("ALT"); . Z- j6 j  r# B/ A6 m3 ?, J0 J
printf("]");
  f& w* F4 t- d" ~6 X} ' H6 W- f. c1 _. X* V
/* print out the character read */ " ~1 B2 l5 T7 i  m8 w8 m
if (isalnum(key &amp; 0xFF))
7 l) w8 b- n, i# f8 C) W1 M9 ], _printf("'%c'\n", key); ) b! d- j+ q' d& b% }
else
; y) ]2 U* z' a3 U; p8 X1 |printf("%#02x\n", key);
( F6 i4 |8 A1 @; E7 J2 g0 ?return 0; - m- O: B) a6 l; Y! q
}
* c- q3 Q' c& K; s- x
/ x; ]+ d) Q3 e+ x9 f  e</FONT></P>
, A/ ]1 y4 p5 m& A! u/ I<P><FONT color=#ff0000>函数名: biosmemory </FONT>5 U3 x3 w: m/ M: R
功 能: 返回存储块大小
, y' o* T0 z* V" t4 Y; C! ^) L0 Z" W用 法:int biosmemory(void);
1 d, V  u) ~+ W3 c0 z; R' `程序例: </P>1 _) \8 E) ?7 i, @/ L# |& d
<P><FONT color=#0000ff>#include <STDIO.H>
9 O2 Z* {- Y. n2 A4 B4 k#include <BIOS.H></FONT></P>3 n8 t# ~* Y* m) u
<P><FONT color=#0000ff>int main(void)
4 P" F4 Y4 A6 m6 y! p6 N+ a, A{
1 N) z  q1 p% }: qint memory_size; </FONT></P>9 p7 K2 z/ ?7 ]) M9 b8 h
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
& u1 I+ g  e5 v# lprintf("RAM size = %dK\n",memory_size);
  w/ T6 {) b* A% \% z. C  i/ wreturn 0; / {  {, Z! d- c9 D
} ' T: l; O& i: k0 j1 ^; b* d
</FONT>5 x/ d; s# [' ^5 e: S

  _- r. r( V! }& {' o2 @# ~</P>
+ g# p1 i' r6 k<P><FONT color=#ff0000>函数名: biosprint </FONT>3 c/ Q  ^% x5 q9 F" _! Y& w
功 能: 直接使用BIOS服务的打印机I/O 4 [: l  A0 [8 z# ~; R: L- W
用 法: int biosprint(int cmd, int byte, int port); 4 N  d6 z3 J' [
程序例: </P>
4 q7 `6 g. \( w! m! O) N$ V" C<P><FONT color=#0000ff>#include <STDIO.H>1 }( L( |' k% B4 q/ v( r
#include <CONIO.H>1 s2 h( O. y, }' ~" o! ]) z
#include <BIOS.H></FONT></P>- R! e# E$ w5 ~
<P><FONT color=#0000ff>int main(void) 2 e  M- x$ x% ]4 K
{   B% c$ J4 Q# X( @3 \+ H/ y
#define STATUS 2 /* printer status command */ ; c. w6 v) h) H% {* j0 G: Q- Y
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
, _' Z+ P/ ~# S. ?. k<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
+ `6 |- J# r, f1 k6 V8 K6 t<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); # \; e' F/ W9 {% [4 p0 D
getch();
9 Y4 Y+ T& }# qstatus = biosprint(STATUS, abyte, PORTNUM); ( Z2 c( Q" m8 U) O2 F4 x7 l+ _
if (status &amp; 0x01) 7 n( Q' `* f' D+ ?$ ^
printf("Device time out.\n");
) N4 J1 r% I8 Oif (status &amp; 0x08) - d1 X/ B! u. h1 B6 P; s
printf("I/O error.\n"); </FONT></P>! u. w9 r7 D8 N. \
<P><FONT color=#0000ff>if (status &amp; 0x10)
/ O2 \+ @0 F- `printf("Selected.\n");
& O: H- [2 `( a$ f0 |8 |; Uif (status &amp; 0x20)
9 M; i) ~+ M* mprintf("Out of paper.\n"); </FONT></P>
7 i! _% E0 |! J<P><FONT color=#0000ff>if (status &amp; 0x40)   a, a' ]) @4 x
printf("Acknowledge.\n");
( f) S, ]2 r9 J7 Aif (status &amp; 0x80)
+ D9 ~2 s" S* e2 e) L* Aprintf("Not busy.\n"); </FONT></P>
' n' e) z) y+ O( r% ?: A<P><FONT color=#0000ff>return 0; ( k* r, l' G2 O# F
} 3 p/ Y* s5 H+ ^' T- w
</FONT>* T: H/ S( M6 K6 c! F; j, m
/ l9 n6 [" }$ g4 A
</P>
  w0 N2 j3 Q/ _. r. T' t<P><FONT color=#ff0000>函数名: biostime </FONT>  h$ t% j* Z. F: o* N- x( g
功 能: 读取或设置BIOS时间 " p2 R! U8 L% w% `7 I/ b8 u
用 法: long biostime(int cmd, long newtime);
8 J1 Q$ l# }! ^1 e程序例: </P>) s" f9 g' h9 D2 p9 E! S
<P><FONT color=#0000ff>#include <STDIO.H>% S. G7 G  G- Z; d
#include <BIOS.H>/ G* C/ c2 l; f) D6 [$ E% j
#include <TIME.H>
( E' J9 k: B- }) H* f( S. e' V#include <CONIO.H></FONT></P>
# A( q! n; R3 a  p5 g, L<P><FONT color=#0000ff>int main(void) 1 k& @! k+ r4 W
{
. {; D$ r2 X+ B" N, b# S6 L# Jlong bios_time; </FONT></P>
3 b+ C5 z* C& ]/ c2 J( q. b, h, y0 L<P><FONT color=#0000ff>clrscr();
. f' S& ~: ]4 S$ p1 l* \1 Bcprintf("The number of clock ticks since midnight is:\r\n");
' k  h$ v) e) v1 c( G* o( Acprintf("The number of seconds since midnight is:\r\n");
1 W7 K6 q1 M! p$ V; x0 i( bcprintf("The number of minutes since midnight is:\r\n"); + e- V6 c2 z6 m" I3 y
cprintf("The number of hours since midnight is:\r\n"); ! j# V. F9 F6 s
cprintf("\r\nPress any key to quit:");
7 R! W) e! Q2 lwhile(!kbhit()) ; X' c8 g) ?( j3 s+ _
{
3 _1 e1 |1 z7 J! Wbios_time = biostime(0, 0L); </FONT></P>. I8 H+ z- h2 E& O$ M
<P><FONT color=#0000ff>gotoxy(50, 1); # p- l; {4 `& v2 @0 P/ [
cprintf("%lu", bios_time); </FONT></P>
. o+ n- Q" B5 l<P><FONT color=#0000ff>gotoxy(50, 2); % @4 R! ?- i, M& U
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
, d1 ]* A+ B- [  f8 u- i! x% @<P><FONT color=#0000ff>gotoxy(50, 3); 3 u& {9 k7 ^: r% O9 J6 s  m
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>) e0 V, \5 O- \6 R3 i9 d
<P><FONT color=#0000ff>gotoxy(50, 4); + x% V. v- h- J9 |
cprintf("%.4f", bios_time / CLK_TCK / 3600); 7 F, ^/ J8 Z3 U( j, ~3 s
} ) ~' \' b$ [+ T  A: P0 ~6 P8 [
return 0;
9 s0 i! o2 w4 ?: R; I  e( T3 G} 9 g/ g, z" Y3 L3 `. O
</FONT>0 y! J- V! K* M/ @0 g1 a  b3 ~

' F8 s6 U- R; m! x; f</P>
8 k6 {$ t9 a2 [  O' y( [<P><FONT color=#ff0000>函数名: brk </FONT>
$ g1 k* p6 s2 M. x. g功 能: 改变数据段空间分配 ! |6 J' q$ h8 H7 M  [: [
用 法: int brk(void *endds);
9 u1 a1 l# r& E# u$ T/ E5 U程序例: </P>8 v4 p! n# P  O
<P><FONT color=#0000ff>#include <STDIO.H>2 m" `- c: Q2 G. ~
#include <ALLOC.H></FONT></P>+ f; f* C$ A1 h0 C2 S+ ~
<P><FONT color=#0000ff>int main(void)
- X4 V) J! x/ K6 D, h0 f' G{ ) u* w& s( x. }! g
char *ptr; </FONT></P>; i1 o  Q9 ]8 Z" w
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
8 T# p  k7 a' H. J! z* ]5 xptr = malloc(1);
7 Y6 o/ q( Y9 e4 R" [- K; o0 y* yprintf("Before brk() call: %lu bytes free\n", coreleft());
- M; N* I- ]/ M8 E. d' M! C; mbrk(ptr+1000);
. K/ }* o7 J9 J3 C1 p. S) |( xprintf(" After brk() call: %lu bytes free\n", coreleft());
5 W' f0 V% c% g7 T, J7 P/ L6 hreturn 0;
& O) G# I+ _8 D8 e6 L/ [  t7 u7 y! ^}
) y0 P9 {2 c1 l* b; F* w# j7 |' e
6 }/ B  ?$ f  g9 n7 b& F4 Y9 j</FONT>
5 b" T' J* f; y# q</P>2 ^1 C2 d3 m6 Q2 S; D0 @
<P><FONT color=#ff0000>函数名: bsearch </FONT>
6 l7 j1 M8 Z9 {  {5 s( V  k/ J功 能: 二分法搜索 3 E. {0 G! Q: H
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
" o8 S8 I' x6 w& csize_t width, int(*fcmp)(const void *, const *));
# T( C; X* m1 @0 q7 |( Q程序例: </P>
! C$ e9 d% S) c3 C% [& C2 P<P><FONT color=#0000ff>#include <STDLIB.H>
2 m* R) n% T9 }/ _6 q+ B#include <STDIO.H></FONT></P>
" D& J" X: j* ~7 O* z4 Y<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>( |  S3 `+ [1 h, G
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
: x  T7 L  W. E<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
7 q! G! ?; x, P& p% s{ 2 y5 K- o* B+ r& R3 z4 r4 b+ |
return(*p1 - *p2);
- @% j! n# D/ P' M( e} </FONT></P>
* e7 K6 U  g9 Y7 K' \! M- S( H<P><FONT color=#0000ff>int lookup(int key)
' O+ v3 V' V7 Q& y) A{
6 _! V$ f5 p5 }, Q- D/ X$ hint *itemptr; </FONT></P>
" N& y4 W8 X- {( J' b( Z; C! u<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
2 y; e7 w. f& e  H" \  m, ?is needed to avoid a type mismatch error at ! N+ ~. @6 j& E: \" F
compile time */
9 L6 u$ d5 Q8 m; Kitemptr = bsearch (&amp;key, numarray, NELEMS(numarray), 2 n* n4 x/ I  X) L
sizeof(int), (int(*)(const void *,const void *))numeric); ( Q5 J8 b# {: @$ M  t. k9 l
return (itemptr != NULL);
- p9 R; {$ {* z) {% ]5 Q( V} </FONT></P>
1 C. q' }  ^2 z) q5 o; E<P><FONT color=#0000ff>int main(void) 9 g0 ^3 J. h4 E% D1 W$ A' }
{
+ e9 h- W# _* |+ Qif (lookup(512)) 9 S# r4 e! ^8 O( W" ^% k/ y
printf("512 is in the table.\n");
$ T" `4 `  m  E4 I) Nelse $ v$ e7 C- m% z
printf("512 isn't in the table.\n"); </FONT></P>9 y$ [" b& h0 a/ T* A3 x( q
<P><FONT color=#0000ff>return 0;
* p! w3 C  [; v} </FONT></P>




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