- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>
2 c3 t2 i# a3 ]) @. Y3 z* ?< ><FONT color=#ff0000>函数名: bar </FONT>
! J! X, q8 p& d% w) I7 g功 能: 画一个二维条形图 # M6 `: f+ }& d F* R
用 法: void far bar(int left, int top, int right, int bottom);
" r( [ ~' p2 u程序例: </P>
+ t( h) M: R7 |' s$ ~7 o$ |< ><FONT color=#0000ff>#include <GRAPHICS.H>
# G% b7 g* K1 [#include <STDLIB.H>
4 L7 s, l) f+ m#include <STDIO.H>. D2 J4 `3 x2 j# s
#include <CONIO.H></FONT></P>
W3 t3 s4 d v4 m6 j u/ l< ><FONT color=#0000ff>int main(void) * d2 r1 P; _% N0 M+ Z5 q/ {
{ & e0 s5 e/ C, i7 U. H
/* request auto detection */ ) \7 q! \ ~( i& L
int gdriver = DETECT, gmode, errorcode; p2 `, W9 s$ s z \
int midx, midy, i; </FONT></P>3 Y- \5 x6 ]+ H5 q
< ><FONT color=#0000ff>/* initialize graphics and local variables */ ' k+ w8 G z% m6 v- Z& d
initgraph(&gdriver, &gmode, ""); </FONT></P>
8 {9 W: ?; w+ {8 t7 o< ><FONT color=#0000ff>/* read result of initialization */ / Y' w# a( d9 L$ E. |& O$ J; x
errorcode = graphresult(); 2 _& _8 s! T+ L! d: h, y' R
if (errorcode != grOk) /* an error occurred */ 1 h7 h- w* O/ T( O8 T4 M
{
* }- d0 v2 O& ^9 m7 d9 c, o- v- Hprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " }( s, G' H9 g( I- @
printf(" ress any key to halt:"); # P& L# e9 ]* c; ^. p
getch();
4 u+ i0 ]& ?1 b, g8 Fexit(1); /* terminate with an error code */
" A% B# }% |* s* z" D, v} </FONT></P>
! n9 ]5 C ~4 D5 u0 J& C< ><FONT color=#0000ff>midx = getmaxx() / 2;
: z$ J4 ~% \# c' ?4 Dmidy = getmaxy() / 2; </FONT></P>( I2 C8 C' {' F$ ~5 i/ H9 \6 _
< ><FONT color=#0000ff>/* loop through the fill patterns */ ! X8 O0 q) Z5 r. b+ T! z
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
! A7 C4 ] B2 K# ~2 N0 s/* set the fill style */ + }+ Q2 F6 D% Q1 I( U
setfillstyle(i, getmaxcolor()); </FONT></P>
$ ^+ P" H h% \; Z< ><FONT color=#0000ff>/* draw the bar */
+ l6 q+ T" P: E: q% N1 K2 u: Qbar(midx-50, midy-50, midx+50, ' _5 p1 q6 i) p/ ]7 A: L
midy+50); </FONT></P>, y6 t9 h2 n, n0 v& H2 F7 ~
< ><FONT color=#0000ff>getch();
# F- ^6 W; |& [( z3 f. ]} </FONT></P>
3 r3 f; S- u, K7 |% q3 L! S; A< ><FONT color=#0000ff>/* clean up */
% @2 p8 T/ y$ L$ |: ^. Hclosegraph();
# {% U0 m" y; C: C _' Treturn 0;
3 |; J& `" E0 b2 e ?} </FONT>
4 @3 M1 y3 g4 i$ o8 @$ s" B: }/ t# s C+ h" ]
, P& F" q- L) z P( N) `' H9 |4 |</P>
! o# Z' i7 [+ [$ ~* H6 E: I3 ^; U& c$ F0 Y< ><FONT color=#ff0000>函数名: bar3d </FONT>
8 n4 }/ q' O% h/ Q: U$ R. A5 o功 能: 画一个三维条形图 & a4 ~, r% d/ H" X) ?/ v, L
用 法: void far bar3d(int left, int top, int right, int bottom,
) m3 P, r+ o" N# B+ rint depth, int topflag); Z1 K/ p% ^$ ` ^
程序例: </P>/ v0 e% Y6 e/ F
< ><FONT color=#0000ff>#include <GRAPHICS.H>
Z& p! d) u; d+ }#include <STDLIB.H>& v$ @, v- ^% M$ |
#include <STDIO.H>
5 X) s$ K. Z3 z' M/ g; D, I0 Z#include <CONIO.H></FONT></P>
, R2 {6 F/ `' u8 s: Y/ `< ><FONT color=#0000ff>int main(void)
: n: t7 @. s; C0 Y5 `& U8 r, j{
" r/ j4 Z8 `6 U. ^6 q- c/ M8 I/* request auto detection */ 9 ?, E) D/ L! C2 N
int gdriver = DETECT, gmode, errorcode;
l' _" [$ c C5 H, a: Y" cint midx, midy, i; </FONT></P>, h; y' I2 q" X% Q
< ><FONT color=#0000ff>/* initialize graphics, local variables */ + @- k S. s. q4 O
initgraph(&gdriver, &gmode, ""); </FONT></P> ]/ J" P( Y; J' L4 @- R
< ><FONT color=#0000ff>/* read result of initialization */
6 z5 h5 i4 q" `6 i# ^% U0 ]errorcode = graphresult();
9 o C1 n: W4 Y( `/ ]- W. R8 Bif (errorcode != grOk) /* an error occurred */ 2 q" e' z7 O. w# _* H& B6 o2 M2 [) k7 o
{
0 i- C* m1 K0 V `7 Q( E8 Dprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. u) }- x& z6 A- g: H7 r; oprintf(" ress any key to halt:");
: M% Y4 O& [' U: jgetch();
8 u( E7 W3 S; ]1 G' `# p' O- W0 N2 Kexit(1); /* terminate with error code */ 5 X% R3 o" m. h, \& E% t9 f
} </FONT></P>
" e, k0 K. `" C8 b% Z; ^# P< ><FONT color=#0000ff>midx = getmaxx() / 2; # Z( F( H: G; ?8 ^
midy = getmaxy() / 2; </FONT></P>
# B3 A8 C# y' I: h3 K5 |+ u7 T. o< ><FONT color=#0000ff>/* loop through the fill patterns */
4 Z* l5 d+ U& f, X9 ~ a6 Nfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
! M; Z* N! ~% K* A: R, e$ _/* set the fill style */
( S2 M2 l. q: C% Esetfillstyle(i, getmaxcolor()); </FONT></P>/ \ t& Z9 i/ W1 l* d/ _
< ><FONT color=#0000ff>/* draw the 3-d bar */
" U% r& w3 }* h$ _bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>) Z# z6 C4 }5 f- p
< ><FONT color=#0000ff>getch(); ) Q& W4 G2 z! H9 V# r! K) T
} </FONT></P>
2 ]" f2 ] H& } P1 C( y< ><FONT color=#0000ff>/* clean up */
3 D( J+ l b$ T3 ~8 E6 q" zclosegraph();
8 f: \8 Y1 j, W: h6 C* t% Oreturn 0; 5 ]- g1 S- z, N3 B# q. s( F8 f
} 5 `4 z5 d8 d- F2 b' \- R- S
</FONT>
1 e4 }1 X7 g% T. H! }6 i, E0 H7 q( \" Z
</P>
$ Z6 X, f+ i! O- X< ><FONT color=#ff0000>函数名: bdos </FONT>2 }8 z; U' y' N0 U4 W
功 能: DOS系统调用
: a4 Y. O2 A1 n; ]- D用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); ' A: q" L, U, d2 T, @1 V2 D( y
程序例: </P>
: Y+ l( c A" v( r; K6 K0 i< ><FONT color=#0000ff>#include <STDIO.H>
, o0 S1 h5 ?3 a$ n3 P#include <DOS.H></FONT></P>9 s/ S i i) O7 [
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
) z' J) S4 c6 x7 j8 achar current_drive(void)
4 L) L& g" G- E$ d; U{ 0 @* `1 a4 |2 R3 r
char curdrive; </FONT></P>
2 B6 k, @' G( E8 Q< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ $ ~! T" e/ [. R/ p7 ~4 q7 Z# r
curdrive = bdos(0x19, 0, 0); 7 m6 m+ g' ^6 T6 q ^+ b
return('A' + curdrive); 4 c T& \8 c+ p: f. {
} </FONT></P>
. c+ z! Q3 r' X< ><FONT color=#0000ff>int main(void)
% ^3 ]# b+ D# p{
! f# s) K& \! R! L+ z, d+ p9 {printf("The current drive is %c:\n", current_drive());
8 `% q$ l& v" ?" {# F* Q9 Treturn 0;
# m/ V, D4 {- {% j f}
# w% j! y7 x& |, u' V
$ m, s0 g' @, E' }- S! A</FONT>
" m8 k# b3 H0 ]& }" a( S</P>
. W: X3 f, v* `3 C- Q2 Y< ><FONT color=#ff0000>函数名: bdosptr </FONT>) m! X1 t# y, \: z
功 能: DOS系统调用 % s5 u3 z+ {" p' R+ ~9 U6 e* V
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
5 \; j" {5 Z: b; h+ c% T1 p程序例: </P>' o* `1 o) S8 J* F: d( W6 F
< ><FONT color=#0000ff>#include <STRING.H>: ]0 {9 s2 d7 w: B, d
#include <STDIO.H>
- P- D# U; j2 O0 s: V! Z" [/ a#include <DIR.H>8 h b7 w% T9 b3 @/ w
#include <DOS.H>% v4 r+ G* @) \
#include <ERRNO.H>
$ a* x9 Q' U/ c8 }, _; c4 B4 Z#include <STDLIB.H></FONT></P>( D v8 D" H8 j
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
9 _! M) ` J9 O<P><FONT color=#0000ff>int main(void)
0 q! g* f2 Q6 C$ A* T N( Q{ 4 o: G6 {2 J; ~2 I0 b+ e- F
char buffer[BUFLEN]; # l- e3 y w6 t* ~6 S
int test; </FONT></P>
* v) r+ F+ @" }" }/ h/ r( p" |<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
% w7 N7 W+ d7 L; ~' Dgets(buffer); </FONT></P>+ y1 M1 P" j3 V" g# K- J4 Z- I; U+ L
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
- C' T+ [4 p3 {% Y8 U- Rif(test) 5 d" l$ J- Q$ [( [6 n e& c7 s$ t/ C4 a$ G
{ % V$ N' S4 W5 [. t5 y
printf("DOS error message: %d\n", errno); 9 c: I; e t6 `& G' T6 c
/* See errno.h for error listings */ + j9 M- b/ ]* ^/ P' U# ~/ L
exit (1); ; i+ P$ I" ~0 v# j1 L$ j$ a
} </FONT></P>
! x3 c7 q; e3 x" c5 R& X<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
9 w# d9 ], B( k( g1 z7 cprintf("The current directory is: %s\n", buffer); </FONT></P>
/ r4 X1 E( a [' M5 K# ?. L<P><FONT color=#0000ff>return 0;
7 Z2 N- ?+ @8 } k1 z! u W* V} 4 W4 a+ y# e; T; m' p+ Q* M
</FONT>
: g" q+ y7 s" V2 E( c
+ z5 z: e- i% T) G( V</P>
( V+ I4 _ R# w* {4 f( V- S& h<P><FONT color=#ff0000>函数名: bioscom </FONT>
" s' |# s. C; F功 能: 串行I/O通信
8 p& K/ A: p; I0 G) T- `: z' B用 法: int bioscom(int cmd, char abyte, int port);
" C, K: e( v5 ^# B程序例: </P>0 C% |* v6 U- ?
<P><FONT color=#0000ff>#include <BIOS.H>
. V& y: }0 v0 k' P#include <CONIO.H></FONT></P>- N: q! y" v; g. E' _
<P><FONT color=#0000ff>#define COM1 0
4 |# T: w3 m7 ^#define DATA_READY 0x100 4 E: k& b$ \* W( `
#define TRUE 1 ! \" ]# }' L' Q: C; b2 A7 T. G8 B
#define FALSE 0 </FONT></P>" C$ l8 V2 c! s7 z+ z+ A6 r+ h' O
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>! e! o, s' G. ^' Y7 R1 t/ ~
<P><FONT color=#0000ff>int main(void)
' Z- V l; E% x4 ~, L9 j5 }& C6 f9 a{ * m& U# p( g6 T# s- x
int in, out, status, DONE = FALSE; </FONT></P>5 v( m. j5 e' a
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); ( T- v; J& B f1 R
cprintf("... BIOSCOM [ESC] to exit ...\n"); 2 `/ Y: M$ M% N
while (!DONE)
: `+ D. N1 U. |$ ]- p- l{
; K, X1 X$ G, W; mstatus = bioscom(3, 0, COM1); $ _- R, X. x& U4 z7 V
if (status & DATA_READY)
/ c, |5 D ~' q7 R0 z8 t3 k+ Xif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) ! K6 O l) P/ k: a; K& u6 @/ J
putch(out);
- N+ r5 D6 q# b( Xif (kbhit())
( v7 G8 H( W. m5 k8 a{
9 K# [& p2 G# v% R) u9 z8 ~if ((in = getch()) == '\x1B')
2 s4 k& E4 l; }' [( t8 }DONE = TRUE; # B# t; V" W$ ^ {% @% }. f: I" \
bioscom(1, in, COM1);
3 Y$ q2 o5 x- n3 {4 ?2 R}
, y3 |* D v; w3 L) _+ L}
; x, a5 T* t ]3 g6 w8 g4 c' rreturn 0;
/ h7 j T Y8 W} </FONT>
+ N# ?- S- [. f
2 ?- l) U A% V' H# m n' l( F6 J5 V7 q$ I5 C
</P>
5 t$ O" m. |; M<P><FONT color=#ff0000>函数名: biosdisk </FONT>8 i, Y- _7 W* j
功 能: 软硬盘I/O 7 [0 l- f' t, G4 G
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
) v) o7 x6 |. S# O5 Uint nsects, void *buffer); , d; o2 A1 f' g: ~0 r
程序例: </P>
; ^ ~. k G9 t) x<P><FONT color=#0000ff>#include <BIOS.H>$ [7 K& L. L* Z% M3 _8 N
#include <STDIO.H></FONT></P>
" G6 R O' x/ C: }8 S; N5 G7 [, t<P><FONT color=#0000ff>int main(void)
y m; g+ D3 t{
& z# y; S! @) U l& ?int result; - ^/ U! H2 i" l, o
char buffer[512]; </FONT></P>
. b/ l% Y {% `( z/ D<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
: H' G% D) \7 v' Z6 y% n9 Sresult = biosdisk(4,0,0,0,0,1,buffer);
0 B" e2 a9 v" ~1 O8 x, presult &= 0x02;
# I. w5 t% W. `+ h2 ^(result) ? (printf("Drive A: Ready\n")) :
3 D& B' Y% s4 m1 ?" e8 r2 u! S/ f(printf("Drive A: Not Ready\n")); </FONT></P>
3 L0 t5 h$ X" C<P><FONT color=#0000ff>return 0;
* m, l: N1 {( |6 X7 o) o} ) O4 d4 ~/ U" B6 w( d, n# `
</FONT>" P0 j5 @6 Y8 y. l+ C$ g
$ R! G) L) ` ^5 Z8 a
</P>
1 ~5 V! Y: ~- N" E<P><FONT color=#ff0000>函数名: biosequip </FONT>
4 @( }- u4 Z% L# \9 Z功 能: 检查设备
( F4 X; Z( ^5 V用 法: int biosequip(void); - W- O% \+ w3 _. C: | y5 U
程序例: </P>+ K. B3 P$ }3 q7 l
<P><FONT color=#0000ff>#include <BIOS.H>; y$ p/ l% Q$ ^
#include <STDIO.H></FONT></P>
4 ]# s' X; b2 m' n+ N: I( ^<P><FONT color=#0000ff>int main(void) ; E2 d' ]3 H5 _% I. Z `/ |
{
7 I, A; ?. H/ j& X6 q4 g4 P( x& v5 Iint result; : b# a5 }+ G3 x
char buffer[512]; </FONT></P>: W- W4 x+ V2 o* d5 ?. D4 Y
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); " f8 h: m' E1 s1 A
result = biosdisk(4,0,0,0,0,1,buffer);
8 z8 x/ \% r; u0 Q" Nresult &= 0x02; 6 ]6 b/ D; }/ j1 o4 r( M
(result) ? (printf("Drive A: Ready\n")) :
5 J1 I( p# }' D1 M+ n/ z3 w(printf("Drive A: Not Ready\n")); </FONT></P>
: u# J' j" U7 q$ k7 \" L6 y<P><FONT color=#0000ff>return 0;
2 V* x# N. T+ a" x& M}
, D2 U. d" [2 p7 q3 `. m</FONT>' [- p+ t. S$ d1 ^
# A9 p2 v- P* c: P- S% R: C6 D</P>4 j) p$ P6 X3 n' Q9 v. _$ n
<P><FONT color=#ff0000>函数名: bioskey </FONT>" P% o. F. v4 p; _. O) g- p
功 能: 直接使用BIOS服务的键盘接口 ' S9 w3 ^& z# J. f7 h7 f
用 法: int bioskey(int cmd); 1 W b! k, ~: C: M' I
程序例: </P>+ E3 p$ G8 c' g g+ U
<P><FONT color=#0000ff>#include <STDIO.H>
6 f Y! z& I0 `3 a#include <BIOS.H>
/ ^" s! _4 H5 b' S#include <CTYPE.H></FONT></P>( \ j# N( A8 u7 y p( d# o
<P><FONT color=#0000ff>#define RIGHT 0x01
, y( }- m- \4 T5 G# Z#define LEFT 0x02
5 s. Q% T9 K. q0 B0 T- i. {: O#define CTRL 0x04
# {0 P1 F- f' o4 ]' N8 \/ s! ?4 v: i% J#define ALT 0x08 </FONT></P>( V, L' H1 d; w3 A) i- V4 N( r/ S' G
<P><FONT color=#0000ff>int main(void) # N* \! Z5 a1 i& s
{
4 C, L. i R. h8 D+ \' r, x4 Nint key, modifiers; </FONT></P>3 y" _! N/ }7 X6 C
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ / T7 o; _3 \0 W3 I& x! j9 W0 m
while (bioskey(1) == 0); </FONT></P>
4 N! g3 ] m7 Q# k G$ P<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ , D, S' } I1 N) O3 }
key = bioskey(0); </FONT></P>
9 S7 C" @ k7 b- t4 ~<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
/ o, R3 E2 j; V2 t- p) Jmodifiers = bioskey(2);
) J3 k5 Q5 K: d7 n6 K8 y9 eif (modifiers) `# q! L% Y! y. u1 a* o
{
/ t% v1 {8 k+ e2 F8 Kprintf("["); 4 e* a c) ?% [' x( m6 _+ |
if (modifiers & RIGHT) printf("RIGHT"); 3 J& e/ K3 K% f4 n' D a% V
if (modifiers & LEFT) printf("LEFT");
) V4 u h7 v* m) @ U+ g E5 n# Mif (modifiers & CTRL) printf("CTRL");
! v$ w" c: I$ Tif (modifiers & ALT) printf("ALT"); 8 @1 C- h0 Y$ I# \3 p
printf("]");
2 G. _+ g5 O0 u3 {} 5 @4 W3 `$ z. y2 x7 d
/* print out the character read */
# T9 F" ]( h( e$ P7 X) n3 jif (isalnum(key & 0xFF))
6 C# T+ U% p- R' yprintf("'%c'\n", key); 1 Q, V) F/ B6 E
else
' f( s% t8 S- g6 v" H; xprintf("%#02x\n", key);
+ ?; _, o+ [% Q9 J E; Sreturn 0;
! G: n$ C+ L6 U% C. A}
7 b$ Y- g( K" s1 U! V/ ^, \0 C8 k3 ^
% `' v7 X9 \6 ^* t0 |. U</FONT></P>
) j$ Z1 h5 s7 ?; P! }* p/ W" r<P><FONT color=#ff0000>函数名: biosmemory </FONT>0 A2 s2 A6 r; e' r! z$ ?6 n R
功 能: 返回存储块大小
( d/ n: J- P y9 c用 法:int biosmemory(void); 5 _7 }9 A8 a3 \1 `: v( W
程序例: </P>
3 j/ Q. ^; L4 M5 t<P><FONT color=#0000ff>#include <STDIO.H>
& e! J5 T" w/ X8 A# i#include <BIOS.H></FONT></P>
4 y! r, ^$ B& @- T2 [/ {# S<P><FONT color=#0000ff>int main(void) 3 E3 G/ r- H G+ M G
{ , m3 O- q( U7 R
int memory_size; </FONT></P>' s! \) c, V7 M( G
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ . A% ?3 T2 P2 \! i j
printf("RAM size = %dK\n",memory_size);
" k6 Z P( @8 Z% [4 r; p n% p* Preturn 0; l; f' J, l4 U
}
+ m% m8 x; t; p; b% `8 `6 g</FONT>$ W6 |$ U) `# u5 U. c* G! P
! i7 z; O! U- h7 J s( o</P>
9 N" X/ |9 C/ a7 T# n<P><FONT color=#ff0000>函数名: biosprint </FONT>
2 ?7 j5 H% H; i功 能: 直接使用BIOS服务的打印机I/O ) @* T5 B$ m+ J; }: K0 b3 G! l- }
用 法: int biosprint(int cmd, int byte, int port); , v' i0 h! L J0 M
程序例: </P>+ P! C) [7 r0 \$ `# Y+ z. v
<P><FONT color=#0000ff>#include <STDIO.H>
3 S# Y) x/ f) n* d: r#include <CONIO.H>
7 |/ D* x0 |( K9 f#include <BIOS.H></FONT></P>
' h$ p1 Z, l6 o<P><FONT color=#0000ff>int main(void)
) l3 c5 `; I2 Y1 c( X- N- b{
! C3 O" f0 r; F k; r# [' Z#define STATUS 2 /* printer status command */ . k# o0 l3 l- W$ F7 L
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
5 R" \5 h' d) v% V6 M<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
( ^) k5 r9 R$ x" t$ Q* G6 B' H<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 9 ~5 O5 P9 }/ b$ N3 u, A
getch(); + j. ~ m3 \- t9 S
status = biosprint(STATUS, abyte, PORTNUM);
7 ?6 T# g, p H& lif (status & 0x01)
4 E& J: y3 K% Y. c4 p7 w# G0 |printf("Device time out.\n"); ! D/ S* U" |- M) J4 X: }7 s+ C
if (status & 0x08) 2 S, C, @* m# Q% I
printf("I/O error.\n"); </FONT></P>
1 [5 z1 i& B# l! M3 ~6 v8 R<P><FONT color=#0000ff>if (status & 0x10) 5 n) ~$ _1 d6 {" ]% |0 x0 M8 S
printf("Selected.\n");
V' ?" k* o0 S2 {) rif (status & 0x20) 7 ]% }7 i) e! n
printf("Out of paper.\n"); </FONT></P>
$ |: y1 {0 u ?<P><FONT color=#0000ff>if (status & 0x40) . j* z( [1 U- `: V9 F J
printf("Acknowledge.\n");
) u. V& B% B* P) n2 tif (status & 0x80) 2 U; d5 |) p1 p B' q
printf("Not busy.\n"); </FONT></P>/ W) ~( p% B# O+ o9 t% h' l1 a5 j
<P><FONT color=#0000ff>return 0; : d$ m n( U. F: A1 D+ E
}
" z5 H( M* v) K5 |2 W# g</FONT>
" t# l2 S: [. {
6 `1 B, ]6 U3 z7 q6 I# c Y</P>
# [4 {. x" y1 M<P><FONT color=#ff0000>函数名: biostime </FONT>& o6 X& ?4 @, q; T
功 能: 读取或设置BIOS时间 & e* h+ W# R7 @0 K+ U+ r' n( `
用 法: long biostime(int cmd, long newtime); 0 Y- G6 z; ?/ x5 s
程序例: </P>1 f I" X: s6 n' [
<P><FONT color=#0000ff>#include <STDIO.H>4 R8 K1 r9 C P3 @2 T1 Q2 R% A" p! G
#include <BIOS.H>
4 T" p$ B- U" Q' h( F& b j#include <TIME.H>$ _, j8 j* T' T( l* g
#include <CONIO.H></FONT></P>
; `0 @0 p' Z; m. A( ]+ |+ w<P><FONT color=#0000ff>int main(void) ; `) `9 Z* Y/ G. m% j1 ?( p
{ " O% T1 ]8 z& n: k
long bios_time; </FONT></P>$ ?6 ]( }. q e1 @1 w# e: k; k8 y" g% ^
<P><FONT color=#0000ff>clrscr(); 9 o# @/ W+ e j
cprintf("The number of clock ticks since midnight is:\r\n"); % C4 i, Y" k+ p; C
cprintf("The number of seconds since midnight is:\r\n"); 1 P" F& S" ?4 \
cprintf("The number of minutes since midnight is:\r\n"); ( Q: I ~% G3 R9 D& O" K) X
cprintf("The number of hours since midnight is:\r\n");
, M, u) {$ h' U7 G! zcprintf("\r\nPress any key to quit:"); / _$ g+ K* z5 @: i- `: @+ `) f6 [8 [" T
while(!kbhit())
, [. H) o3 ~8 z& ]: E# ^{
0 G( X) M6 M K; a7 v7 Q; [+ ibios_time = biostime(0, 0L); </FONT></P>3 w% E, r% Q7 q7 |
<P><FONT color=#0000ff>gotoxy(50, 1);
3 p: m9 X, l" V h) ~0 T, [cprintf("%lu", bios_time); </FONT></P>5 Q! T e# q8 A3 K+ p
<P><FONT color=#0000ff>gotoxy(50, 2); 4 V# E6 ?9 y; v# X2 ]' K; \
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>! t1 T6 a, n" N, u5 a. A/ l
<P><FONT color=#0000ff>gotoxy(50, 3); ; w3 x, f' e4 a; T; s, ~( D5 O9 @
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
! T) Q% v* L) |5 z ^ Z1 J8 Z, Q<P><FONT color=#0000ff>gotoxy(50, 4);
% y$ p2 H5 u' n' P# wcprintf("%.4f", bios_time / CLK_TCK / 3600); 0 B' \7 u9 K, `+ C& r
}
) y9 }. ?/ N4 Dreturn 0; & E/ X- s3 o, W! C" W% X
} 4 Z" l. m; k( B8 g
</FONT> g3 j& D! g3 X1 }7 Q i0 L
# G* E, l3 o1 h: m5 ]% `, j</P>$ w2 K0 S& p6 n Z
<P><FONT color=#ff0000>函数名: brk </FONT>2 h% G1 i$ a7 I x- [5 i3 Y* w
功 能: 改变数据段空间分配 0 P% y9 j& H, S9 E
用 法: int brk(void *endds);
4 M7 g6 n; m% l. B' Y7 J程序例: </P>, r" D3 M7 S) L, K. _: b1 a
<P><FONT color=#0000ff>#include <STDIO.H>+ N$ Z6 H1 `8 M9 h$ T/ n
#include <ALLOC.H></FONT></P>
% B- |) F0 w; Q: a; m4 E( }<P><FONT color=#0000ff>int main(void)
/ C3 ` l( K0 \3 h1 l{ * \: A% x1 `4 l1 C' R
char *ptr; </FONT></P>
$ z% O( n6 f; w ?. j% N8 O4 u5 r<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
8 n& R5 R0 ?9 c3 C8 ~# zptr = malloc(1); " V7 y) P5 B3 O8 \( u u0 y! e
printf("Before brk() call: %lu bytes free\n", coreleft()); ! f+ B2 T) T7 q( n% I4 n( R) z
brk(ptr+1000);
5 ] D( T; _9 N+ S; ^, d0 t& w Eprintf(" After brk() call: %lu bytes free\n", coreleft()); " R( E6 A, O# D$ y
return 0;
" h: `- P7 n1 E}
( t6 [% a* c6 Q0 B
4 N3 v; }1 [( m- w+ b6 r</FONT>
3 r! n( K1 o- K7 `4 V/ e6 s</P>
4 i/ m* a# S9 z<P><FONT color=#ff0000>函数名: bsearch </FONT>- X$ _# U8 ?: N$ _; ^
功 能: 二分法搜索
8 N) |# c, x2 Q" G2 U5 |用 法: void *bsearch(const void *key, const void *base, size_t *nelem, , X6 I( k3 N9 o d
size_t width, int(*fcmp)(const void *, const *));
: n$ O+ h2 z# l) V; N程序例: </P>
4 S' t8 R5 l# ]$ C. S% @<P><FONT color=#0000ff>#include <STDLIB.H>7 J1 v/ \" J; M: a2 ]9 H7 X9 H# P
#include <STDIO.H></FONT></P>1 L2 ^& s9 R& g! d) `" @* { n) @! ?
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
- P5 y* y1 u" E3 | y<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
2 v7 U( ^5 r% Y5 U4 H) U! w<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
9 U+ P, m: E1 Z3 r{ 2 o' f3 U7 R* c. D6 ]
return(*p1 - *p2);
; c9 C( M. u7 i} </FONT></P>, N% Q# r; m0 q) @
<P><FONT color=#0000ff>int lookup(int key)
" P2 ~7 h" q3 N; z- r8 C& C& @6 p{
/ D, J% h" @4 l+ v7 `' cint *itemptr; </FONT></P>
5 w D, A% i+ [' J% ] T3 o1 G<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
0 C2 |# G' U( u. [+ d2 S# C0 }5 Qis needed to avoid a type mismatch error at & y( U) f3 @( {
compile time */
/ y' m* s) J: A8 b* r9 X/ Y6 d; Y" Fitemptr = bsearch (&key, numarray, NELEMS(numarray),
+ s5 ^0 u x( Z: R; R$ n* gsizeof(int), (int(*)(const void *,const void *))numeric);
V4 A" H6 T7 j4 Q- Sreturn (itemptr != NULL);
- Z- l4 V4 ^" L# }& i} </FONT></P>
) g+ A) c# J' D; f9 Z3 ]<P><FONT color=#0000ff>int main(void)
# V3 K+ M, b! Q$ z- V+ ], j, m( M& n{
\2 G3 C5 H" a$ Kif (lookup(512)) ! n, B5 Y, B! r1 e
printf("512 is in the table.\n");
8 ?0 u+ A8 p S/ O3 J9 ielse
! O l. ]7 ]9 p- Aprintf("512 isn't in the table.\n"); </FONT></P>
( F6 D, F$ V' F- f' b- J v<P><FONT color=#0000ff>return 0; 3 p+ ?; E: v' L Q( ?+ n- }, _
} </FONT></P> |
zan
|