- 在线时间
- 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>( m0 Z1 U5 |1 t; i& D8 Q
< ><FONT color=#ff0000>函数名: bar </FONT>; P) l5 r5 p- _
功 能: 画一个二维条形图 2 \# z2 H1 `& }5 H
用 法: void far bar(int left, int top, int right, int bottom); ! ^ q, O4 ^% s% Z
程序例: </P>1 k' z4 f/ v7 ?$ ]0 X* D2 z
< ><FONT color=#0000ff>#include <GRAPHICS.H>
' E( q0 b! ?; r3 D, \#include <STDLIB.H>
. k t) w) _' M" o: t#include <STDIO.H>
0 m) J8 D% `7 o3 ]) p#include <CONIO.H></FONT></P>
! u$ @$ N) z6 [" |< ><FONT color=#0000ff>int main(void) 8 m+ l' A. M' ?8 t& H3 B1 a5 G2 s
{ 2 V' v' ]4 F# `+ w
/* request auto detection */
! ?8 k, v; b- [- yint gdriver = DETECT, gmode, errorcode; - b3 t9 r9 ]# X2 H4 S
int midx, midy, i; </FONT></P>. r' T4 k! ]6 d5 w
< ><FONT color=#0000ff>/* initialize graphics and local variables */
( T9 a1 v4 I0 Q4 s6 r. hinitgraph(&gdriver, &gmode, ""); </FONT></P>- [8 Y$ m9 c. O; w9 A. C1 Z5 N0 P
< ><FONT color=#0000ff>/* read result of initialization */
- T0 |, C# g/ e6 L5 Yerrorcode = graphresult(); 9 g1 J/ R, y5 Q1 u7 G& `
if (errorcode != grOk) /* an error occurred */
6 ~% ?+ {) _( \ t0 q{
6 f3 l( D% M- a4 {1 I0 i2 Aprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' y9 _' x0 x9 _ S/ Q* N
printf(" ress any key to halt:");
4 Z) J, ~' V+ tgetch();
" o' T' w( m$ m+ Y! I% s6 \exit(1); /* terminate with an error code */
: H( {2 F1 n2 X1 r} </FONT></P>( h( A' { v2 d' |2 a) e- U
< ><FONT color=#0000ff>midx = getmaxx() / 2; * p; Q! B M4 c# b, i. M0 N* [
midy = getmaxy() / 2; </FONT></P>0 v e. {, b! _
< ><FONT color=#0000ff>/* loop through the fill patterns */ * s8 E7 c& d8 }3 @
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
0 w* ^& m* h. Z$ q/* set the fill style */
2 Q; ~8 q$ d xsetfillstyle(i, getmaxcolor()); </FONT></P>. j3 {! N5 E! \
< ><FONT color=#0000ff>/* draw the bar */ : C& j0 H3 \; r6 ?& N' N
bar(midx-50, midy-50, midx+50, $ ^ h! @9 S5 i9 e' }9 N* V
midy+50); </FONT></P>
, @7 v: J: m7 t& f/ i) W5 o< ><FONT color=#0000ff>getch();
! {% ?1 ~/ {0 b5 K1 i$ k} </FONT></P>
: U- q9 x/ x# F- _% {4 I< ><FONT color=#0000ff>/* clean up */ q; ^9 {2 ~2 Y0 P: }* o
closegraph(); 1 C' w4 k8 M) ^9 g
return 0; 0 m) g* T0 X( } y
} </FONT>6 Y0 w4 V' G; {2 a' X7 l) e
4 \ K3 |- ~1 u" n! c) Q, O5 a2 d* }; G- G
</P>
7 c8 j E' r# p9 u< ><FONT color=#ff0000>函数名: bar3d </FONT>
9 H8 B9 J0 m3 J功 能: 画一个三维条形图 4 B. B6 T( P) A- Y$ V
用 法: void far bar3d(int left, int top, int right, int bottom, & d2 u& s( |( G
int depth, int topflag);
- e3 k5 v) |: M; {1 ~; a2 y程序例: </P>
. K. w$ x2 W8 t! ~" O6 X) z< ><FONT color=#0000ff>#include <GRAPHICS.H>
& y1 d' \% b+ n$ V0 ^#include <STDLIB.H>: O4 m/ \& w2 \* U; B/ u4 X
#include <STDIO.H>; M$ D: n% O0 L) P( y4 \
#include <CONIO.H></FONT></P>) |0 p5 d/ u4 F2 D4 F4 V- H
< ><FONT color=#0000ff>int main(void)
; U! `) B0 @! M' s- [( y. `{
& x& `! z6 u S6 o/* request auto detection */
+ ^$ \. ], A: o9 |int gdriver = DETECT, gmode, errorcode;
3 U! d% |( R! P4 |. Fint midx, midy, i; </FONT></P>2 Z& n" ~3 z3 r: W+ W. t: S! v$ w+ j
< ><FONT color=#0000ff>/* initialize graphics, local variables */
, P7 P% i) s7 R5 }7 @initgraph(&gdriver, &gmode, ""); </FONT></P>) i4 L3 B$ n1 g. S8 p; q
< ><FONT color=#0000ff>/* read result of initialization */ . a$ Y( `7 a4 k( v
errorcode = graphresult(); - J2 \7 D: r% C' e
if (errorcode != grOk) /* an error occurred */
2 N) T% N" f& K9 [* G{
( w& X* z* b+ z3 E( ?+ D2 \printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 {$ a2 b) h1 Z! Iprintf(" ress any key to halt:");
% i G! o9 Q, Bgetch(); ; n. n2 y) S ^
exit(1); /* terminate with error code */ # _& c4 h# s% A% I/ z! i7 j; x% `, H
} </FONT></P>
* `0 }+ d: @& y: _& g< ><FONT color=#0000ff>midx = getmaxx() / 2; ' U5 m. J! e# ]5 G
midy = getmaxy() / 2; </FONT></P>
; v) k6 W+ ?3 ]$ q, e< ><FONT color=#0000ff>/* loop through the fill patterns */
) D! a6 F! I3 x9 kfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
% c" x5 \* {$ m/* set the fill style */ + b) j3 |6 m% _, I& |
setfillstyle(i, getmaxcolor()); </FONT></P>
0 R6 U+ F4 t! _! A$ i4 J. }1 G< ><FONT color=#0000ff>/* draw the 3-d bar */
1 `" i% | Z- `* q; Y/ ?bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>5 L E1 K8 g7 K- j
< ><FONT color=#0000ff>getch(); \8 \7 C+ S# H6 }7 A1 I8 H
} </FONT></P>
2 S/ w$ b. N' k( C5 e. Y< ><FONT color=#0000ff>/* clean up */ 1 D4 L# q) [2 D: k
closegraph(); - ]2 J- v! R! [6 ?* L
return 0;
' H2 \! r" m( U' x4 Y& [( {}
2 B, h& }5 O! U6 T; O</FONT>
& |9 s' ]& `( A' Z7 ^- b1 w1 W+ t/ {3 [4 w: L; c7 h+ k
</P>
f' i, {1 g8 m0 L' l( @< ><FONT color=#ff0000>函数名: bdos </FONT>: _6 L+ W% a) P1 G/ X- d0 n4 t
功 能: DOS系统调用
5 h. b6 _2 b* Q/ K1 h$ ^用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); ) S! x) I" g; F2 S3 S
程序例: </P>, a+ {6 S; ]3 K) Y+ w2 A& ?% Z( n8 A
< ><FONT color=#0000ff>#include <STDIO.H>
* Z* ~7 H n$ P. g% I: h#include <DOS.H></FONT></P>
% Z4 E2 m2 {$ G3 S0 y< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
& x6 r1 `; w: H! q3 nchar current_drive(void)
* W/ t; z/ {( w, \{
8 j4 k& h. X7 J0 Y# X5 x$ Mchar curdrive; </FONT></P>9 a$ B! {" o) B: h7 z: ?! P
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ ; A) O; C2 G- b6 a
curdrive = bdos(0x19, 0, 0); + D, D4 _5 k5 a& Q/ B0 P& {) m S
return('A' + curdrive); 9 U/ F) V g% S8 {' q* ~8 M! e% u
} </FONT></P>8 B. G& S( n) [) s2 p. U
< ><FONT color=#0000ff>int main(void)
' ]4 [4 O" W& K ]{ - ^ N# `* G; m' E ^/ x
printf("The current drive is %c:\n", current_drive());
0 s" B% }0 R2 r1 {. Dreturn 0;
! |8 [" u, L% d$ @- g, Z}
. x) U! k K. K j
. ^- L8 Y& w: l$ s. c</FONT>
5 l. Z( i U/ m! h2 G7 s* Y</P>5 T. ], I. O) r' b4 u6 G3 R& p
< ><FONT color=#ff0000>函数名: bdosptr </FONT>
! r4 ?0 {" S+ C* y" |7 u+ X功 能: DOS系统调用 ; f# |0 u7 |. C% H* B' W/ j
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
C& u' a3 }* P. {* o, ~程序例: </P>
8 T [ B) `9 \" f. h< ><FONT color=#0000ff>#include <STRING.H>
& {: S- a& P b d/ }#include <STDIO.H>
, h5 n& x( g0 N3 Q#include <DIR.H>2 }7 D' i4 \ n: M7 G0 w
#include <DOS.H>( x+ t5 P; S/ M* }2 D9 o ?
#include <ERRNO.H>4 r' O; K% c* j; \/ v7 N
#include <STDLIB.H></FONT></P>
3 i" W. D5 U7 w9 v9 X" v+ v4 a<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
& ]( Q0 T% I J) p. z) q<P><FONT color=#0000ff>int main(void) 4 f5 P- Y: L9 Q) D' o P
{ 2 j0 e7 C- s. r- g* s$ r% q
char buffer[BUFLEN];
( c1 `! F; o7 X, yint test; </FONT></P> u0 A/ r, A/ R; B( z0 _
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
; N8 X2 O2 b8 b# ^1 Qgets(buffer); </FONT></P>
4 l/ H1 t5 P4 Y! S7 ~; T$ \<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 3 D* i5 |% x+ _
if(test) $ f) I0 B6 Z! s3 Y/ x8 o
{ 6 c4 |1 S% G7 {4 I
printf("DOS error message: %d\n", errno); , @7 |' O' Q8 M% q$ T9 ]
/* See errno.h for error listings */
7 U. y ]9 Y& g/ Z: y- oexit (1); 1 \. N* g8 R! U# I! o
} </FONT></P>
, z' d. \1 v2 L; @. _- Z<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
0 f6 ^4 x4 x w: A7 ^; zprintf("The current directory is: %s\n", buffer); </FONT></P>& q/ ?# Z2 ?2 s; g9 F! m. R
<P><FONT color=#0000ff>return 0; - t* P5 b6 o/ a8 V
} / E; j6 x* A5 W% o
</FONT>: @- M/ G! T) X Z, } v" f
$ B1 M3 X/ }, l4 k6 {, Y- J4 Q</P>
2 A/ V# A; D/ n! K& z<P><FONT color=#ff0000>函数名: bioscom </FONT>1 m9 Q* _. |$ a; k* D
功 能: 串行I/O通信
2 q6 h# f2 m/ `9 `8 s用 法: int bioscom(int cmd, char abyte, int port);
: P, s' F- m& e6 ^/ V0 S* g C! ~程序例: </P>
! F9 k$ n; i& h3 g( w; ~2 ]( K0 f<P><FONT color=#0000ff>#include <BIOS.H>6 `6 a* ~4 ~. [. [$ K! W
#include <CONIO.H></FONT></P>
" K9 _) g# z, \* _0 F2 \7 `<P><FONT color=#0000ff>#define COM1 0 # A S! D: C( S- Z! A
#define DATA_READY 0x100
' U, a) |1 A& z7 ^' C# d6 L. F9 e#define TRUE 1 # P- M$ P; d4 l/ k* e
#define FALSE 0 </FONT></P>5 b2 |1 I0 D- r+ B
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
7 K( ]9 P K' t$ @! O* G8 D0 }9 o<P><FONT color=#0000ff>int main(void)
: j. N) G m4 P1 q% w. ]* k8 w+ B{
! A9 E7 y: O& I: J6 A) r/ @int in, out, status, DONE = FALSE; </FONT></P>
- Y5 w% I% F- Y<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
) Q: ]* d! F& J% K7 V8 o6 Bcprintf("... BIOSCOM [ESC] to exit ...\n");
$ V% I- ?2 f' C0 [$ T+ l. e9 }while (!DONE)
3 @7 Q& N6 q7 H0 L{ i2 w% a( ` j& U/ A& y3 y* I6 K/ a
status = bioscom(3, 0, COM1);
) H ?& Q/ N# x1 a$ R/ {if (status & DATA_READY) . L; a; W% O+ c( S
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) 1 Q' ^2 J9 X5 Z" B' K/ u u7 k( o
putch(out);
* a q" B7 r% Q, q8 W: g4 J( Dif (kbhit()) ! V9 D4 W2 @: Y, W% a
{
; l, {6 l [" Y8 j. }if ((in = getch()) == '\x1B')
+ V# N9 s/ W. g4 ZDONE = TRUE; ! F2 u& b+ y% I$ `/ B
bioscom(1, in, COM1);
' G/ a! a: H( z5 Y}
; x8 Z; Q' m, {. S- u}
& |0 }+ [, F/ l; x; G; d* Z0 y% e- w6 _return 0;
4 R3 v) Z. a8 I( f0 q( `5 z% \+ h} </FONT>
( v2 }6 s8 @- ^8 \5 v7 W/ J* b' u6 h5 P1 F$ i1 z
* k- v* M _ J0 r8 n4 L$ U$ w
</P>
. X3 k0 F5 U7 r+ V5 K<P><FONT color=#ff0000>函数名: biosdisk </FONT>6 {2 q r* ?$ a
功 能: 软硬盘I/O
6 Y4 A& P* T$ U, V+ G6 ~+ |; ~用 法: int biosdisk(int cmd, int drive, int head, int track, int sector $ b" a. W6 n- g5 A+ p+ }0 f- ^9 ?
int nsects, void *buffer);
4 S: ?0 i$ k1 j0 ?0 ~程序例: </P>
( E1 b+ D6 `0 d0 A8 [<P><FONT color=#0000ff>#include <BIOS.H>: G) p: P2 C$ d. S
#include <STDIO.H></FONT></P>! h- z1 L" Q! E- @& D
<P><FONT color=#0000ff>int main(void)
: u" U: G' e* |, N( m ^{
6 m& V! m- p! ~0 g6 Z) Vint result;
/ c( c/ H" r+ P4 [% I5 N! Mchar buffer[512]; </FONT></P>7 h9 C$ k1 x7 f" {) \4 j
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
" T0 A! |% W% x3 z+ U! Fresult = biosdisk(4,0,0,0,0,1,buffer); 9 S0 j, ?/ F' P* Q1 n
result &= 0x02;
: a& k, ^: ?( M0 E(result) ? (printf("Drive A: Ready\n")) :
9 A3 [; K) |( ~! B& M. `4 [& S5 z(printf("Drive A: Not Ready\n")); </FONT></P>2 a* [0 }9 I3 F: ~0 [
<P><FONT color=#0000ff>return 0;
& _: U* W7 n+ w1 n7 g$ y7 u1 W}
, [! I( g5 c, @) h5 x3 B/ G</FONT> d I# ^& z& C$ |) x! @
- R0 `5 D$ h; y$ A+ m8 j0 S( G# i
</P>
" D5 x- U" u* J8 Q( p6 J/ A<P><FONT color=#ff0000>函数名: biosequip </FONT>
. c$ p( ~% @9 X1 h& X- I- e功 能: 检查设备 % e0 L& h& `# s3 @4 P$ {6 b Z
用 法: int biosequip(void);
4 O8 C9 r! x6 ^程序例: </P>( r- ? G# n: P @; l/ r5 ?
<P><FONT color=#0000ff>#include <BIOS.H>. c+ W9 V5 B. t4 b
#include <STDIO.H></FONT></P>+ i# Q! K D; y% o! \0 j, k. h5 x& }
<P><FONT color=#0000ff>int main(void) 8 V3 k- ?5 k( M N4 ~
{
; _( _' Z3 Q8 l9 e* F* `) Vint result; 1 n4 p9 A3 j: W
char buffer[512]; </FONT></P>5 ?1 O' V8 W# S8 g& }
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
5 C1 \7 b! m! {1 q- [& S) [' rresult = biosdisk(4,0,0,0,0,1,buffer);
+ p2 B) F0 T1 w2 I5 N/ qresult &= 0x02; % b* ? K# z" Q7 b
(result) ? (printf("Drive A: Ready\n")) :
4 h$ ], j: n# V" c1 H7 m9 I" m+ Y(printf("Drive A: Not Ready\n")); </FONT></P>
0 g$ b% g# a7 ^: ^<P><FONT color=#0000ff>return 0; 8 d# \9 v, ]- ?+ a3 T* F7 n3 O- S
} - C: H* C, Z, F* u
</FONT>
9 c) d# b3 I; G( Y& E
N! ?/ d- ?: r6 R2 C, o</P>
. R" N3 s& l; ^! ~5 C9 E+ U3 K<P><FONT color=#ff0000>函数名: bioskey </FONT>0 t8 i* d9 }% f& h P, c2 K/ u
功 能: 直接使用BIOS服务的键盘接口 . j# \: P6 ]4 ^1 y% ~, i+ ]3 U
用 法: int bioskey(int cmd); 9 t; \$ K! B6 l% ^* h2 e+ ?# T. D
程序例: </P>
G! W: U" t- j' E% B7 \<P><FONT color=#0000ff>#include <STDIO.H>. O3 g) q/ ^' F3 P
#include <BIOS.H>
, Q2 y% M/ }1 ^#include <CTYPE.H></FONT></P>
, g* O0 A+ `* G<P><FONT color=#0000ff>#define RIGHT 0x01
7 \" h" C q+ S1 ?( P6 `#define LEFT 0x02
$ R4 t, @, I" k8 i1 v- R#define CTRL 0x04
4 g0 z3 d8 L3 D" U+ V#define ALT 0x08 </FONT></P>
! q% w5 `0 X; X+ _<P><FONT color=#0000ff>int main(void)
' r; ^0 ?2 r+ o$ G{ 3 X! T5 C0 r% N
int key, modifiers; </FONT></P>
. [0 b0 Q, p4 j: N7 u! r1 U) w<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
$ q X. P9 u8 z. bwhile (bioskey(1) == 0); </FONT></P>
$ w3 c& C1 j- M& e! N; z( {: ]<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ * m6 k2 u" e; Z
key = bioskey(0); </FONT></P>; U, _8 s# L7 `; ]2 y! Y: A% Z: v$ ^
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 0 c+ ^* S, s. N
modifiers = bioskey(2); ! u. x! l9 W. |) z
if (modifiers) 0 {2 G2 }5 M' a2 t
{ & |! V5 a/ ^- r) ~
printf("[");
5 {" F" [( g8 R0 R7 Vif (modifiers & RIGHT) printf("RIGHT");
# b0 |1 L, A6 o$ p6 ^, D; _( f: bif (modifiers & LEFT) printf("LEFT"); # R2 `! n3 \3 t; U- C) ?) ]8 }
if (modifiers & CTRL) printf("CTRL");
) K1 a6 n" Q, W0 M5 I/ D# u6 rif (modifiers & ALT) printf("ALT");
1 j# o X8 y8 q. b' y% cprintf("]"); 9 i( n0 l* v6 t3 j$ H+ z- E0 I
}
( ^8 R" I% Y4 V: i/* print out the character read */ ' Q, O" h' t& o4 ~/ M; G: e
if (isalnum(key & 0xFF)) 6 S. ^ o; c7 q
printf("'%c'\n", key);
! f. u- K% u# f/ A- r8 welse 0 p& f, `4 [% p `5 p- |4 O! }/ \0 k# @
printf("%#02x\n", key);
7 w+ e7 S7 F& H4 Z0 d3 r1 d2 Areturn 0;
+ j* s, N/ ~$ Z7 u( U8 `/ e, j} ) {" \, v5 G: N5 @
+ y+ P# X6 F5 u) ]2 X% ?) x
</FONT></P>% o/ b9 h1 o5 i5 x6 o6 E
<P><FONT color=#ff0000>函数名: biosmemory </FONT>+ h1 B0 S6 R8 g! w
功 能: 返回存储块大小 * q7 Z0 ~8 y. L4 Y7 Z+ x( Z
用 法:int biosmemory(void); / o! e) `" Q) I, R* [ g
程序例: </P>" S4 g. I D% f
<P><FONT color=#0000ff>#include <STDIO.H>
( n0 @6 f. l+ g8 L#include <BIOS.H></FONT></P>
) A. d* I* H& m* B<P><FONT color=#0000ff>int main(void) 4 O0 z. U0 g9 K/ |
{ % h% U. M* y% F0 |; r! s0 ?
int memory_size; </FONT></P>1 ^: w- X p6 d$ \
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ D& g- v- W1 I n3 J: o
printf("RAM size = %dK\n",memory_size);
2 T0 K' J6 G0 O9 p3 o/ S! c( ~: lreturn 0;
: y# ]4 a! A# A+ _$ k1 q}
. x: h8 X9 B. R</FONT>
2 K4 b; b4 U* T x; D0 L, v! C) }; I: e! R& ~
</P>
, E( i6 O- l3 ?<P><FONT color=#ff0000>函数名: biosprint </FONT># \1 I6 t+ |3 u# Q; ~: F, w
功 能: 直接使用BIOS服务的打印机I/O
3 S8 D, s$ S# h2 {& h/ O用 法: int biosprint(int cmd, int byte, int port); 9 @8 B0 O8 |, U R
程序例: </P>
8 W- z/ a0 b/ ], E6 h: S5 x<P><FONT color=#0000ff>#include <STDIO.H>/ X1 @$ ]& @! }1 a2 u" m5 x: b* {6 s
#include <CONIO.H>" q, ]6 E) s1 a8 T( `( M* ^0 f
#include <BIOS.H></FONT></P>
& C- g6 b; s! Q<P><FONT color=#0000ff>int main(void) M# A, x; o: o% g
{
) a+ L9 w7 E# l& F# a! g#define STATUS 2 /* printer status command */
8 N5 j8 y, m$ Q& j4 q4 D! e! Q#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
! x1 j1 s# P) c3 H: W6 T<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>: U5 A7 Z1 x: I, R( P3 z
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); * t1 J+ U, u: Z8 N; Q$ ]) h a
getch();
/ p1 ~9 X, e9 `* I3 v, T$ `" H& M; Mstatus = biosprint(STATUS, abyte, PORTNUM); ( U" n: g) q8 f' z2 v" r
if (status & 0x01)
$ Z3 ], y3 c4 J3 Xprintf("Device time out.\n"); : ~$ r3 y0 S w' |, k
if (status & 0x08) - P: n" s. b7 f Q; M4 {8 Q$ ?
printf("I/O error.\n"); </FONT></P>3 X) g; C* E+ d
<P><FONT color=#0000ff>if (status & 0x10) 1 Y p3 l, ~# e9 j
printf("Selected.\n");
/ |' a/ ?* }- a6 z4 X# sif (status & 0x20)
, D( p: _% P' O* Gprintf("Out of paper.\n"); </FONT></P>5 a4 m3 b0 ~; \2 `5 t
<P><FONT color=#0000ff>if (status & 0x40) ) C1 E1 Y, Y6 |8 d' o/ K
printf("Acknowledge.\n");
5 j% \& I6 k) x: }if (status & 0x80) * u) q: H" g h, S1 V9 ^$ u
printf("Not busy.\n"); </FONT></P>. v2 Q- V$ ^. J3 \( j' |$ c
<P><FONT color=#0000ff>return 0; 6 R; Z+ Z1 @& s0 s( g9 Y: P
}
0 z: u4 G. k& {5 U( p# q m% ~( R</FONT>0 @! z- B7 L% e+ V- C/ {2 \
: f; z1 l/ a2 `- \
</P>
9 {, H* P. L" X U D( f! z<P><FONT color=#ff0000>函数名: biostime </FONT>
5 C- i$ E2 a; [7 d& B7 p( ~3 e功 能: 读取或设置BIOS时间 + c" x7 ~9 n- Q8 Y
用 法: long biostime(int cmd, long newtime);
7 m' E6 D X3 q! q+ B程序例: </P>: J5 r0 c2 O; y6 {: L% B
<P><FONT color=#0000ff>#include <STDIO.H>
% i* g' K' a2 V+ R" e `#include <BIOS.H>5 s' e+ E! ?4 p2 p* ]! |
#include <TIME.H>
5 t. R' K2 U4 S' S' ?0 `#include <CONIO.H></FONT></P>, s+ m) t4 G; J7 U7 w
<P><FONT color=#0000ff>int main(void)
! l/ ~3 k( R) v( u& w3 n; j* j( w{ 6 p1 ^( f ]+ J2 Q+ {
long bios_time; </FONT></P>8 f& M; m4 y! o; s5 k) `! M
<P><FONT color=#0000ff>clrscr(); 7 ^/ s$ \ N; x. q, ?4 s; w5 ]; w+ |
cprintf("The number of clock ticks since midnight is:\r\n");
0 i7 S! K) G* l& `0 ncprintf("The number of seconds since midnight is:\r\n"); : J+ k' a+ L. |3 x9 _
cprintf("The number of minutes since midnight is:\r\n"); + N9 I! S) J6 Y6 z. b& Z
cprintf("The number of hours since midnight is:\r\n");
$ j& `2 V1 `7 |* j1 |: l( {: y/ T, Ocprintf("\r\nPress any key to quit:");
0 ^- q! |; i# L% g+ s! owhile(!kbhit()) 6 a& y0 {1 ~& P( a; A
{
& O8 P5 t" @# T4 Tbios_time = biostime(0, 0L); </FONT></P>7 s0 @+ ^& ~* s8 p/ s! c+ ~
<P><FONT color=#0000ff>gotoxy(50, 1); / |* W) L7 w$ D& y5 }- n
cprintf("%lu", bios_time); </FONT></P>/ ?4 p; B: D! R8 g
<P><FONT color=#0000ff>gotoxy(50, 2);
; Y2 b; R0 P1 v! S5 f) g. I& b8 ^. zcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
4 l. |, Z8 N3 }, W+ ]<P><FONT color=#0000ff>gotoxy(50, 3);
) i! A" s( t5 Q0 v: @% zcprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>; P' b0 i: I: k: W$ w
<P><FONT color=#0000ff>gotoxy(50, 4);
$ _1 F8 S+ e: H) t3 U4 }$ U# i& `: Qcprintf("%.4f", bios_time / CLK_TCK / 3600); ) c4 N3 b1 L6 t! c
}
" X X2 p# y, a# n$ O0 Areturn 0; 7 k, _( t# j* q3 y9 l4 O' _. `
}
" Q6 C o$ w% p) R</FONT>
& f1 P: J; N* |+ H- V; g! h
2 K* T3 K$ w: E" D0 V* ]( e</P>
7 X6 g A7 A, ^9 \2 }/ O$ D" x! H<P><FONT color=#ff0000>函数名: brk </FONT>
, {& a9 S" J. a( P: q功 能: 改变数据段空间分配 , P/ g* r2 G6 q& C0 M
用 法: int brk(void *endds); 6 K( y1 E/ e: d, s5 G1 ^- b+ ^9 H
程序例: </P>8 t0 E; k* p! d( E5 _
<P><FONT color=#0000ff>#include <STDIO.H>* |7 B: ~) \2 g8 n# T6 G1 N
#include <ALLOC.H></FONT></P>
: p' C8 X- T0 r! q. ~<P><FONT color=#0000ff>int main(void)
5 [6 {2 _' G9 Q4 M{
& z a& n# N% D: g$ }3 ^char *ptr; </FONT></P>1 n( h9 A+ ~' Y0 |# z
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
, G4 \5 Y. M$ S+ |) Rptr = malloc(1);
6 O! |! T7 \+ a8 P$ I. L0 Oprintf("Before brk() call: %lu bytes free\n", coreleft());
. O3 ~( q }1 F( M0 {4 b0 e5 A4 e% T( Gbrk(ptr+1000);
1 b7 L5 j# M2 m7 k4 q. O7 \ oprintf(" After brk() call: %lu bytes free\n", coreleft()); , p; b4 a1 B0 a/ z* b4 H
return 0;
) V& y5 z+ G6 U- j} ( _5 m! I) S: K
( F4 M) c0 j% E4 t+ p
</FONT>: @% u5 |8 \3 H2 ?3 ^
</P>! g5 \. v, `6 L' k* g
<P><FONT color=#ff0000>函数名: bsearch </FONT>
' z6 ~1 I: I& w' e: R: ?7 I. [5 ]功 能: 二分法搜索 w% O; Y1 w' T( o9 }& r; E' A
用 法: void *bsearch(const void *key, const void *base, size_t *nelem, * o- o$ R+ {0 P8 x1 @
size_t width, int(*fcmp)(const void *, const *));
& ^$ A7 V" j# ^6 G: `程序例: </P>1 W9 B# K* p6 Q/ T7 v' ^& [. _
<P><FONT color=#0000ff>#include <STDLIB.H>
a7 `5 Y0 w$ ]1 c. d#include <STDIO.H></FONT></P>
0 T, u; x) l' T* d Y$ E6 L$ p<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
1 }0 n1 W0 S' q! ?* T<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>% c9 K# H' N, f# e
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) / e( ^7 u, C1 I( M
{
9 f/ m4 [, A5 q6 Z6 w0 ~) @return(*p1 - *p2);
! j" I1 G. x& _: m2 u} </FONT></P>/ j- `- N0 W$ K% B1 w6 e p( @
<P><FONT color=#0000ff>int lookup(int key) : s( s, U! s* x0 m8 \7 o" R3 D; G
{ * ?" G5 z& z9 n7 w# W2 r e2 H$ E
int *itemptr; </FONT></P>
) M }3 c+ Y# I- u' g8 x<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) % S, O/ [8 V1 ]4 N1 D) g! q
is needed to avoid a type mismatch error at ; H! Q0 m/ F' E! k" b
compile time */ . O% o+ i- d7 S. ]7 [
itemptr = bsearch (&key, numarray, NELEMS(numarray),
$ O: _! w# l7 ^5 t: Nsizeof(int), (int(*)(const void *,const void *))numeric);
! n" ]7 |" j# |# }9 _- o% Xreturn (itemptr != NULL);
0 N/ _% N3 r/ Q$ C4 S+ g8 p; _} </FONT></P>. u. |% Z0 a7 \; n0 R; A2 i
<P><FONT color=#0000ff>int main(void) , G; j. T8 y; ?0 G
{
9 t/ p- I+ y8 nif (lookup(512)) * q( T4 f9 p; L( X- f
printf("512 is in the table.\n"); % @ r4 Q& D8 H" m& D! J- p
else
5 y4 [7 b; Z' [9 `4 ~# G# q+ ]printf("512 isn't in the table.\n"); </FONT></P>
$ g$ v' D7 f0 B<P><FONT color=#0000ff>return 0;
8 b; ]9 B3 `6 ?, y( r9 {! M} </FONT></P> |
zan
|