- 在线时间
- 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>" B$ I0 o. \5 T, H" a! g
< ><FONT color=#ff0000>函数名: bar </FONT>3 |, A$ x, G/ s5 f( K
功 能: 画一个二维条形图
* f( H9 o5 Y1 A. e1 h用 法: void far bar(int left, int top, int right, int bottom); ' k: L, r" E4 U) H% ?5 G* P
程序例: </P>
3 b, u) P) Z6 K9 X< ><FONT color=#0000ff>#include <GRAPHICS.H>
$ g: J* T" I6 E% k( W#include <STDLIB.H>
( l$ d9 _3 w" c [" V) |! k#include <STDIO.H>
( B0 e+ ~1 b4 U& A#include <CONIO.H></FONT></P>9 H# o5 L' [, P; w- M. M
< ><FONT color=#0000ff>int main(void) 9 S% S. `# H- f/ ]! Z1 m3 f4 L
{
8 t& B" u, C7 e. S/* request auto detection */ / S; W7 I& M3 P: B& J) B( }( I
int gdriver = DETECT, gmode, errorcode;
" O) |7 h M- c/ u/ a9 mint midx, midy, i; </FONT></P>
" R [5 [9 \7 D, J: Z' n; z< ><FONT color=#0000ff>/* initialize graphics and local variables */
+ E. e j6 {( ~# ]initgraph(&gdriver, &gmode, ""); </FONT></P>
9 z! |" K+ d( [< ><FONT color=#0000ff>/* read result of initialization */ & D' o. @- b+ q+ n
errorcode = graphresult(); / g- x( z5 f& m, n
if (errorcode != grOk) /* an error occurred */ o, j1 @# U; f% h" Y$ c
{
, a/ v$ U* ?7 ?2 q4 z4 @printf("Graphics error: %s\n", grapherrormsg(errorcode));
* L& ?# x/ }9 b8 W6 f( ~" q$ Jprintf(" ress any key to halt:"); ( L' N3 ~: X# A% u5 e' ]7 m
getch();
! L+ P6 g* M; Y, E6 m5 L; Oexit(1); /* terminate with an error code */
+ E; E7 \' q2 X. Q1 u} </FONT></P>
1 d' I+ R- [) q& d7 G5 U< ><FONT color=#0000ff>midx = getmaxx() / 2;
- O" Q: t* c3 J' |3 p+ smidy = getmaxy() / 2; </FONT></P>: i$ a1 ?* n! I9 i, U
< ><FONT color=#0000ff>/* loop through the fill patterns */ . i% a- }/ k- K0 u2 J
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
& G3 I7 R4 `' c( J5 p/* set the fill style */
6 h* M1 g N8 Q. n7 f" lsetfillstyle(i, getmaxcolor()); </FONT></P>
, u( P) \7 u) `* _< ><FONT color=#0000ff>/* draw the bar */ 5 N& l! V3 I9 U6 n, r
bar(midx-50, midy-50, midx+50, & M+ F* L# m1 m6 X) z
midy+50); </FONT></P>- l9 u6 [6 Y1 c) f) w1 o
< ><FONT color=#0000ff>getch(); 2 Q; `, D* y) w2 \1 N. z5 w
} </FONT></P># u4 N. j" N; a1 L7 v/ J7 ^
< ><FONT color=#0000ff>/* clean up */
7 ?! o6 E: Y+ d& E7 M7 Jclosegraph(); ) W4 u) C" r) F, E
return 0; 9 ~' x9 `) j( F2 B* n
} </FONT>
; @* a+ j3 ?& ?0 H( x i7 e- J3 }! K
( U1 M8 [5 h$ G3 l; e) W5 k" e; ~& D- e
</P>1 C/ h3 H: a# T- ? @' W
< ><FONT color=#ff0000>函数名: bar3d </FONT>
7 P8 G& `3 r+ {' Z+ y- e; ^功 能: 画一个三维条形图 ! g( g7 |" S( O: r$ z3 _
用 法: void far bar3d(int left, int top, int right, int bottom,
c* w' ^. e& |int depth, int topflag);
0 S6 J& | ]6 h! x程序例: </P>
1 X) F+ g+ S% H; i< ><FONT color=#0000ff>#include <GRAPHICS.H>$ q0 X1 u1 z9 [3 |
#include <STDLIB.H>
5 N$ \/ V0 {, Y& G) u#include <STDIO.H>
. k1 P9 c( S: _+ w* f1 H1 o#include <CONIO.H></FONT></P>
: k, \% [5 h& Q0 `4 B g< ><FONT color=#0000ff>int main(void) 6 r, b. G" }) V
{
' M; x, M/ ^( W' u& C! L/* request auto detection */
1 [" ~$ D: v+ Y& z& h6 V, ^int gdriver = DETECT, gmode, errorcode;
Y' F9 Z' [6 g9 O; I* ]int midx, midy, i; </FONT></P>& J3 ~ x3 c% N+ w3 R; B. n' \/ E) O
< ><FONT color=#0000ff>/* initialize graphics, local variables */
J& }: C7 U Kinitgraph(&gdriver, &gmode, ""); </FONT></P>
& [8 s, k$ J* G4 A. q x' U |< ><FONT color=#0000ff>/* read result of initialization */ 8 y5 G0 p ~) I
errorcode = graphresult();
) R% n+ ` Z! h8 aif (errorcode != grOk) /* an error occurred */ 6 r7 W a8 R2 {
{ ) ~6 Q) {" l; B: L6 @6 o
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 w9 K' w4 _0 zprintf(" ress any key to halt:"); : o- P/ Z9 ` v- M. L$ l2 Z- Z5 Z) K
getch(); 8 R: @( ~" \3 A. h; t+ E
exit(1); /* terminate with error code */
1 \0 @* |- ], E5 ^/ @} </FONT></P>- _2 |2 B( S3 M; |
< ><FONT color=#0000ff>midx = getmaxx() / 2;
7 ~7 I" p7 B% _7 C4 {5 vmidy = getmaxy() / 2; </FONT></P>
. f7 K; U: K8 R5 U- k< ><FONT color=#0000ff>/* loop through the fill patterns */
5 C# H- u% ^# Wfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 0 I5 m/ H6 k) g5 p2 g
/* set the fill style */ : R; ?* w c+ x. G/ H
setfillstyle(i, getmaxcolor()); </FONT></P>( [+ R- r% k# l- J) T7 Z% e$ x* g
< ><FONT color=#0000ff>/* draw the 3-d bar */ . {$ u+ S3 j) y+ ]9 U
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>2 \# e4 ]* }( r& W6 ?
< ><FONT color=#0000ff>getch();
# E3 u8 v3 g. h$ d} </FONT></P>
. V0 q3 {* @5 M5 r< ><FONT color=#0000ff>/* clean up */ / ]; B; }: R u Z9 S4 w- I
closegraph(); + O4 D5 c% O" ? n2 x5 l
return 0;
4 @! G$ L3 N7 h! f} ( N2 [; T5 j* W! m' F+ R |" n
</FONT>
$ v8 b, A3 |2 C
: L& r$ Y% ^" \1 t, A' t) x) A</P>* F4 w( c, I9 ^: ]+ |9 `
< ><FONT color=#ff0000>函数名: bdos </FONT>
( T, N; `$ g3 k7 N$ d% y功 能: DOS系统调用 3 I' C1 O4 X2 `2 y0 x1 L1 G) S
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
; C) y/ ?! t% S) O3 R" ~程序例: </P>6 s$ P7 T2 |" i; c3 J1 @% f3 n
< ><FONT color=#0000ff>#include <STDIO.H>
+ x+ T( _5 S' ~5 m7 E! w#include <DOS.H></FONT></P>8 _/ N0 {# y7 `& g! y
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
) U' V9 D" i3 \& G1 f. }( zchar current_drive(void)
/ Q% V: Y( Y: Q/ h{
t+ G( m: Y5 E Lchar curdrive; </FONT></P>
( ~+ E) ?6 o% ?6 I b/ C< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ % v( ?9 D f3 o7 b: a
curdrive = bdos(0x19, 0, 0);
2 I4 W8 c& o7 Q& o7 o4 ^4 c% Hreturn('A' + curdrive); 9 R# s) H7 F* T& f8 J8 p; G
} </FONT></P>
9 |- F; _) Q! t% f< ><FONT color=#0000ff>int main(void)
# g0 ]$ C. c( ^/ U/ Z1 n/ a{
: y5 o- Q! i# xprintf("The current drive is %c:\n", current_drive()); , b( q0 M3 C. _& H
return 0; 5 h d' h* l$ O% T3 i
}
6 _0 f$ Y" V3 s {5 I; \9 o7 I! w
</FONT>
" a) V/ P( M6 m7 }" B! P</P>, X$ i+ p9 K% a0 c: W7 }
< ><FONT color=#ff0000>函数名: bdosptr </FONT>3 ~' k% P& w+ q: R& U
功 能: DOS系统调用 $ [+ X/ W$ J) ` U$ o m* A' Q# w
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
1 |' X6 h6 M0 V7 X程序例: </P>
3 G. u1 E# u- K3 B; ?< ><FONT color=#0000ff>#include <STRING.H>9 e9 ^3 t, [3 m$ e7 E6 b& e
#include <STDIO.H>! j+ y5 }+ ~+ s
#include <DIR.H>
/ |3 J) k' K& P& F( h" b$ d* `; l#include <DOS.H>0 L# }; w& K: P/ h: C
#include <ERRNO.H>8 _/ V0 s( c1 Q$ Q
#include <STDLIB.H></FONT></P>* S: V* M8 ]& _$ ]% y" _: H
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>' L& `3 C3 a) t5 K
<P><FONT color=#0000ff>int main(void) % l0 ~! k4 y4 ]2 R/ M
{ 5 x9 ~3 p6 ~: m! v5 p) A" J
char buffer[BUFLEN];
3 [( x% _! {; j8 O' h6 j) dint test; </FONT></P>
# ~7 A7 p, l" @1 d6 R2 ?4 W7 v<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
! j* O! r" c: @! r, v, n: n$ H4 ngets(buffer); </FONT></P>. s5 h9 x/ s! f7 D m, w! {: u
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
. _' K0 i4 t5 @! N1 _: @if(test) ! _0 J2 g7 _: R
{ ' Y$ M( a1 q- ]) N/ X
printf("DOS error message: %d\n", errno); 4 d' d7 ~1 o9 X
/* See errno.h for error listings */ 5 c: v3 |3 n* T) Z8 q5 \/ V% a
exit (1); 6 V o8 ~ O& ~$ s h" R# ~2 M
} </FONT></P>
- c( A3 Z# V$ P! i. k2 r' p0 t<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
k7 k/ K1 j1 \9 h( ^. b5 @printf("The current directory is: %s\n", buffer); </FONT></P>
3 t! ?, }; v& L1 K9 x8 S<P><FONT color=#0000ff>return 0;
9 I6 A+ O7 K0 M- z} " ^6 v! Y, |7 G8 U; x& B& k2 [
</FONT>
, o6 z- ?1 V( G. |1 M' N7 E2 Z! g; Z6 b
</P>- z5 e2 i+ C' P/ Z
<P><FONT color=#ff0000>函数名: bioscom </FONT>) N) O. A; f) @7 `4 U
功 能: 串行I/O通信 1 ?2 y" F( r s! z1 p& F
用 法: int bioscom(int cmd, char abyte, int port); " I& ~; l$ I' n/ H/ I, U
程序例: </P>2 H1 C7 q% M& U0 _1 u$ z* {
<P><FONT color=#0000ff>#include <BIOS.H> E0 _2 A. `& p3 @0 ~8 r4 S+ D
#include <CONIO.H></FONT></P>' I# p7 q* ]: J, F) }
<P><FONT color=#0000ff>#define COM1 0
' B$ k/ l* m( P U1 s( v4 N1 Q7 S#define DATA_READY 0x100
. j! v9 r, k; i1 h#define TRUE 1 : a" _# m/ w& K' O. D% S
#define FALSE 0 </FONT></P>
3 r& s5 ~# X7 m/ U9 _% O6 M! e<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
9 F# {5 @2 h+ L1 }: `0 Z<P><FONT color=#0000ff>int main(void)
7 C* p5 w$ ^% h0 s{ 6 I6 n/ l5 ~8 }1 O. U) g# l8 ]/ z& [
int in, out, status, DONE = FALSE; </FONT></P>
- |0 j/ @8 D5 ?+ X2 W7 l7 V<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
* {3 ?+ G e( r E6 m9 s0 Qcprintf("... BIOSCOM [ESC] to exit ...\n"); , e5 ^9 s5 N3 k. e, s
while (!DONE) 0 N6 T/ u$ |/ G4 m1 s. l, F2 S
{
, Z# \: G7 _% }6 {% }( M7 cstatus = bioscom(3, 0, COM1);
6 b+ o& K G2 @$ bif (status & DATA_READY) : X2 o, J) t! ^8 E' }+ \* e
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) # E8 S- [; ?. t" @' G! q% V) ^
putch(out);
+ N* Z# R( Z: K6 a. O/ b8 A: I$ Gif (kbhit()) 3 Q3 ?( m! j( [3 F
{
1 r4 D" S+ b' z9 t* eif ((in = getch()) == '\x1B') / E! I( E+ v' t. o0 p0 _6 y+ D) Z
DONE = TRUE;
]! S A: \! n# `bioscom(1, in, COM1); 6 T. z# T7 }# ^: g" w a- x
} $ i5 S% ~: ]7 Q, |8 b
} % }) Y I6 W3 |$ f8 Y( A3 v
return 0;
* M$ w4 b) b L1 a' h} </FONT>0 X& \( ] k+ Y. `* g
! l) V x3 v% a- H3 s; E) Y
1 G4 b. N/ {7 w' f' D' ~: C1 i
</P>- [% n5 T/ i4 p, ~
<P><FONT color=#ff0000>函数名: biosdisk </FONT>' n) Z6 M" P. J# G+ j. s
功 能: 软硬盘I/O 0 a/ e4 K/ {# O! |% Q2 s
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector : t! b: |0 s: p) R5 z& N5 ^, P4 [' e
int nsects, void *buffer);
) p' t. n( {$ N程序例: </P>0 h' }3 v+ r1 F& | H( c2 A) r
<P><FONT color=#0000ff>#include <BIOS.H>
) N% K7 g* B5 F7 D1 _. @9 W#include <STDIO.H></FONT></P>
1 @. f7 L2 C u' h9 T! U<P><FONT color=#0000ff>int main(void) ' }- B4 H0 V6 d! Y# t6 C, `# \
{ 0 b- |; I8 Z% \& a r2 j. m
int result; 9 p) S8 g5 J, {$ G. N) P# `) q- p
char buffer[512]; </FONT></P>3 S- ?' N8 @. X% C! F0 s4 b
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
5 v9 A. I6 N% iresult = biosdisk(4,0,0,0,0,1,buffer);
5 Q5 N! G% w# Rresult &= 0x02; M3 @9 U# a3 l! m* J/ Q
(result) ? (printf("Drive A: Ready\n")) : * b9 p0 Y0 ?. b# d7 J
(printf("Drive A: Not Ready\n")); </FONT></P>7 n- k/ _7 h. W2 c$ j. U
<P><FONT color=#0000ff>return 0; - s! q R' m7 \
}
* ~6 c3 R: I" i# o, T</FONT>$ g/ O( L2 [) K- H9 W1 e6 k
" F8 v+ q* X9 w! ^/ T) P
</P>$ Z$ I7 e& c. \9 P* O
<P><FONT color=#ff0000>函数名: biosequip </FONT>7 f6 z+ u$ M) j2 J0 W) \( F# J
功 能: 检查设备
- n0 U) A/ |$ U" W$ C8 V: P* A2 u- O用 法: int biosequip(void);
6 G0 Y8 M J# q& s程序例: </P>3 ~. O k- t# A9 F& X7 q' g! U
<P><FONT color=#0000ff>#include <BIOS.H>
0 G1 _3 z) O$ T2 E4 p1 v8 z#include <STDIO.H></FONT></P>3 P8 A. k1 O" i
<P><FONT color=#0000ff>int main(void) `( j" |- f( O( r8 F* s2 \
{ 7 x7 L$ H! S+ n; a8 s$ Y7 ?, `
int result;
' Z" Q6 l6 I) t: L" ?char buffer[512]; </FONT></P>/ ?7 p7 {6 p! t
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 0 u8 f; V$ S& G2 ?2 [
result = biosdisk(4,0,0,0,0,1,buffer);
/ _0 ]& p7 v' lresult &= 0x02;
) L0 K( g: `0 v" c# T(result) ? (printf("Drive A: Ready\n")) : , l5 ]9 K! P- ~) {# j' y' ?) [# @' v
(printf("Drive A: Not Ready\n")); </FONT></P>. q8 ?9 W! \( Y. X$ z
<P><FONT color=#0000ff>return 0;
7 \6 T- |: g8 S} ( c4 H; d, [1 C
</FONT>
6 h- X& G1 G4 s+ P' ?
* f) k! D- g* Y, r: K</P>
4 V9 x4 x7 a8 ^+ j<P><FONT color=#ff0000>函数名: bioskey </FONT>
! h3 }+ A" \% w; H* O& K$ ]功 能: 直接使用BIOS服务的键盘接口 # d U9 @8 J5 T I" S q" m9 J p
用 法: int bioskey(int cmd); 0 q6 E0 f2 ]% [7 T% T
程序例: </P>( w0 z4 x' y( [% Q$ _* P% |
<P><FONT color=#0000ff>#include <STDIO.H>
; o2 Z* O' q% z. Z: P3 L#include <BIOS.H>
/ `- q# M6 Q6 I& j6 K#include <CTYPE.H></FONT></P>: T, C% Q1 o. p5 O: A7 U. u) f
<P><FONT color=#0000ff>#define RIGHT 0x01 9 ^# {0 X3 l0 a1 b! T( o2 m
#define LEFT 0x02
! v( g+ B, X* e: W4 g! `+ v#define CTRL 0x04 : M# z2 x* H8 h' G9 G' d" B
#define ALT 0x08 </FONT></P>8 M2 g. b* S$ g+ M/ k+ a
<P><FONT color=#0000ff>int main(void)
, e; e) ]3 o9 G5 K& V" E4 T2 v{ 9 K f9 C. j, f# i3 e/ i
int key, modifiers; </FONT></P> M( P) y6 M# g0 f
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ 1 ^5 }( g. m# q' `$ z1 `" w
while (bioskey(1) == 0); </FONT></P>
% v1 E: w! y5 k<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
+ e" ] i5 a+ Y" A8 J3 u' _/ i# ?1 h9 ykey = bioskey(0); </FONT></P>
! ~; M( @1 g4 ~" X3 r) h1 ^<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ / T' @0 u9 U7 j5 w' B7 j! v" X
modifiers = bioskey(2); 1 R9 O, y7 i3 d+ h
if (modifiers) ( e) z* E: N% r8 @4 g+ h5 \- D
{
" h I; B9 M5 N: F1 Kprintf("[");
J# Z. z; g) hif (modifiers & RIGHT) printf("RIGHT");
- h3 ^' h( J2 s' Y. v) @1 Oif (modifiers & LEFT) printf("LEFT"); " J2 i7 U% q, H2 K3 z
if (modifiers & CTRL) printf("CTRL"); - E1 w; `1 z3 C ~3 ~) \
if (modifiers & ALT) printf("ALT");
4 `" s' l6 n; m5 B1 ?. m9 v) pprintf("]"); ' ~* ^4 X! r; i
} , C: }4 P" [5 N
/* print out the character read */ / o2 i$ `7 a& I& F* A
if (isalnum(key & 0xFF)) ! g0 m. e/ s9 u. [, m, }
printf("'%c'\n", key); 1 y0 s. a7 l$ f; j% _5 V! e5 E
else
! d/ H9 q8 i: |! A9 rprintf("%#02x\n", key); + i6 w# a3 l# E
return 0;
' o j0 T; n' ~9 H} ' [+ c2 @3 ]' j" S
, j" |# }: k5 h, z
</FONT></P>; m* v& ^) q( I1 y6 ~* z- h
<P><FONT color=#ff0000>函数名: biosmemory </FONT>' C' o) |) M. ]+ e; X; U
功 能: 返回存储块大小
9 X+ I- Z1 d' }# n( o/ x Z6 ^: C" _1 O用 法:int biosmemory(void); $ r, a0 q0 X4 U8 V l7 Q- t& ] t
程序例: </P>
" [1 v- U, D' L7 j9 g<P><FONT color=#0000ff>#include <STDIO.H>
8 O, ], V6 g9 w7 Z% H2 w#include <BIOS.H></FONT></P>. M A) W- D4 J8 [6 [
<P><FONT color=#0000ff>int main(void) ! h: d2 q: O i7 |0 S6 r
{ g4 j0 F5 ]% q2 A2 A0 b) d
int memory_size; </FONT></P>' \# o* n$ v$ i
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ 7 H- ~! L# X( f- V$ e- l* B- ^0 d# r
printf("RAM size = %dK\n",memory_size); , _: o, G- o% U1 i
return 0;
3 k& p" p' [/ Z2 R} , Y5 [$ K- B+ }8 }
</FONT>; r) I% [1 n9 @8 G# R* ?) e
3 `' i( n* }" n: ^- L# Y
</P>
% d# W1 u# N+ D: e7 L& T8 K/ l4 F<P><FONT color=#ff0000>函数名: biosprint </FONT>. S5 Y1 ]6 N5 V% a) H C6 X% \$ F l
功 能: 直接使用BIOS服务的打印机I/O ; v1 L, B3 d, w6 {
用 法: int biosprint(int cmd, int byte, int port); + k: y, s9 ]9 L/ V. S6 p
程序例: </P>
' {% ?, ]3 P+ u0 ]<P><FONT color=#0000ff>#include <STDIO.H>
& q w5 G2 j5 W% p8 W# P#include <CONIO.H>0 g& G5 L; q- k% _6 W+ |2 R
#include <BIOS.H></FONT></P>) B+ F) n2 z) ~# u7 ?, f+ { m; L
<P><FONT color=#0000ff>int main(void)
' g# ]9 e$ a. }{ 4 E5 R0 N! k6 L' Y2 o
#define STATUS 2 /* printer status command */ - m+ J6 r* `0 ^) @# u
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
* ]. V; }7 {& M6 H! O- y<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
. m ~5 h6 v: e" j* Z<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 9 ^, [* v$ u9 J$ D
getch(); , R/ {# i/ O/ R; J
status = biosprint(STATUS, abyte, PORTNUM);
) R4 U. X- s `4 a' R% c6 s4 Mif (status & 0x01) Q9 f* f E+ \! Q. y
printf("Device time out.\n");
4 d+ y+ w8 p8 r8 |6 F! kif (status & 0x08) 5 B3 u+ k H+ M
printf("I/O error.\n"); </FONT></P>) D/ \! I; N$ J2 H: j: p: w
<P><FONT color=#0000ff>if (status & 0x10) 9 H- N$ h" D0 ~! U* S) r1 @) y
printf("Selected.\n"); * O: Z, \) a9 Q. r
if (status & 0x20)
- [; R9 r; ~! n: y0 qprintf("Out of paper.\n"); </FONT></P># Q) n1 ]- w3 m6 b$ e
<P><FONT color=#0000ff>if (status & 0x40) / Z) Q# N" N* m' ^6 W6 i
printf("Acknowledge.\n"); * [4 m+ n$ B; C( k. G
if (status & 0x80)
0 r% Y N ], p' F( B$ b1 Xprintf("Not busy.\n"); </FONT></P>
4 w% G8 I# M2 N: q<P><FONT color=#0000ff>return 0;
) H- h* Y% n( E* u8 [: C} * V) S$ K; v% S
</FONT>) ^9 S+ {9 Q( b1 j; D" N
, L/ ~: V% s" v</P> t: `4 Z, f5 `" e1 o
<P><FONT color=#ff0000>函数名: biostime </FONT>) E8 J+ d9 \5 a+ |( n- i
功 能: 读取或设置BIOS时间 6 F: E. `$ p+ b7 V
用 法: long biostime(int cmd, long newtime);
P9 x6 p7 } \% v& ~程序例: </P># Y8 a0 v+ ~+ U" h( w0 h% V+ _: X
<P><FONT color=#0000ff>#include <STDIO.H> @& y) U" Y" u* O4 L* b8 p1 u
#include <BIOS.H>- ~# @. _, r* T% f3 T. n& H3 s
#include <TIME.H>
~7 g( Z# h4 g+ p9 w7 L; z#include <CONIO.H></FONT></P>
3 H5 A; l" {3 ~! N( z! @<P><FONT color=#0000ff>int main(void) ! C& }, z7 o% X* `. W5 F
{ ) a# Z# ]' X2 E/ b
long bios_time; </FONT></P>/ p& ~" V& J- P$ P( [7 o. W
<P><FONT color=#0000ff>clrscr(); " I: _5 k, r T" J8 A
cprintf("The number of clock ticks since midnight is:\r\n");
# u- E9 Z7 |" ^4 F4 kcprintf("The number of seconds since midnight is:\r\n");
/ ?9 i+ @. H' D p Tcprintf("The number of minutes since midnight is:\r\n"); & O( S5 b! i5 ]) ^: t; ]
cprintf("The number of hours since midnight is:\r\n");
! l: j4 e' v+ A9 ]1 b1 S0 ]cprintf("\r\nPress any key to quit:"); 7 o& l/ `& l5 ?0 b! `
while(!kbhit()) . V/ b' ]9 |& w/ Y, s8 `) o
{ 4 X) P5 h1 ?9 y- e
bios_time = biostime(0, 0L); </FONT></P>
3 C N' g/ X2 V; @1 [<P><FONT color=#0000ff>gotoxy(50, 1); , a% p7 p* N/ m9 H- I Q* o/ @3 S. e
cprintf("%lu", bios_time); </FONT></P>: q. x. B! P0 |' r& o
<P><FONT color=#0000ff>gotoxy(50, 2);
5 C$ N X9 r3 x$ O+ Lcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
) A" E0 h) ^* D( {# s6 G; A" b<P><FONT color=#0000ff>gotoxy(50, 3); % B- i8 \# \, r3 z
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>. u4 E1 g/ R7 {2 w
<P><FONT color=#0000ff>gotoxy(50, 4); ' w: g2 J4 `0 G# I5 T- O9 N
cprintf("%.4f", bios_time / CLK_TCK / 3600); / D! `: C- O( w) [8 H
}
" I8 \4 L0 X2 z$ P# kreturn 0; * C0 I& z* b; {: n+ P! o& e2 q
}
8 n% U+ D$ M( X( ], o</FONT>
4 b, w( o$ M( K+ Y1 y/ E- d- \0 N( o: s( L# G# ^& `% A
</P>
4 X6 G) _3 c, R* G<P><FONT color=#ff0000>函数名: brk </FONT>
% W6 y# D6 B5 K, ?功 能: 改变数据段空间分配 5 M2 o1 Y( S3 H0 G6 B; n
用 法: int brk(void *endds);
0 y* [) W' T4 D+ L程序例: </P>
" t+ L' {' c8 h6 U7 \$ t6 b8 i/ R t<P><FONT color=#0000ff>#include <STDIO.H>
+ R& S" k2 X7 V/ T I#include <ALLOC.H></FONT></P>
( i) Z" I9 A9 r. Z4 l }2 T<P><FONT color=#0000ff>int main(void) ) V; F7 V2 a, P- D! W& i
{
5 F2 o6 y. J' T3 f$ Wchar *ptr; </FONT></P>% @! [; u3 z& M5 {. ?0 h
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); / R$ X& E4 s3 j0 x1 r, `6 M
ptr = malloc(1); / C2 h3 F$ ` m1 V7 i: U( ]; E1 T
printf("Before brk() call: %lu bytes free\n", coreleft());
% I' j1 O8 ^9 x8 H, u: r$ \- Ybrk(ptr+1000);
* J7 ]) X( e6 D4 S4 Bprintf(" After brk() call: %lu bytes free\n", coreleft());
) W' J* a o6 ]return 0; # z& Z5 K+ u" G2 i4 l
}
4 H/ Z+ ~; l, ^+ p! u w! z# ]6 m$ c7 N. x5 [; h& V
</FONT>% p- ` ]: |' Y) z3 U
</P>* `) Z8 P9 j g# e
<P><FONT color=#ff0000>函数名: bsearch </FONT>* C- o6 j+ L! Y& H5 d
功 能: 二分法搜索 : S: W6 l! h- J J9 x. ?2 X
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
6 m, ], S2 P. t; ]# d9 P3 ksize_t width, int(*fcmp)(const void *, const *));
- w. F- } @7 O0 e程序例: </P>8 b, \# V8 v" [" W$ }, D( Q: r
<P><FONT color=#0000ff>#include <STDLIB.H>
! D+ A2 ^' G8 D, P#include <STDIO.H></FONT></P>
$ ?! `8 | v. s1 l* }5 m<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>' |& S/ ]8 n: T/ V- w4 s+ ^
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
9 c+ O- ^1 w- R6 d<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 3 ^1 P& Z8 d" ^: o2 Z& m
{ 6 P, J; c/ z: n1 _& X9 E5 G3 Y
return(*p1 - *p2);
( { z- `& h' W, L} </FONT></P>2 H1 y" |# h5 R- l x5 Y* p
<P><FONT color=#0000ff>int lookup(int key)
% a2 C; I! O6 G4 f$ L: {8 z{
& u: C: c3 {. W2 e: E& M8 ]int *itemptr; </FONT></P>
, a3 @; r7 K" Y) |# y5 u& C; i<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) 8 q3 E0 p2 T" V( g( O2 E* c4 p5 L
is needed to avoid a type mismatch error at
8 C( r) P4 a. L( Rcompile time */
4 l/ k( D9 D2 H$ q4 |itemptr = bsearch (&key, numarray, NELEMS(numarray), 9 N' f6 p' G% ]$ B: p( x3 X. z
sizeof(int), (int(*)(const void *,const void *))numeric);
. s+ ^2 R# b3 i k2 L* G$ Sreturn (itemptr != NULL);
- E2 W( U" ^4 s0 A# a* @} </FONT></P>
. y8 N3 [) m$ `<P><FONT color=#0000ff>int main(void)
2 |+ _3 O2 ]: d+ D3 X4 p5 ]9 u3 c{ F9 Y& @' e9 \# [. a( M
if (lookup(512)) & D/ k% ?- S0 m% P' ^0 W' F
printf("512 is in the table.\n"); ) U$ ]! ]9 U7 c9 B+ A' M/ F
else
' [" U* U$ E9 Pprintf("512 isn't in the table.\n"); </FONT></P>$ A8 U) i6 K8 V
<P><FONT color=#0000ff>return 0;
5 e& L+ U K" _! c) f0 V. v+ X4 p# V} </FONT></P> |
zan
|