- 在线时间
- 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>& s! W+ k7 h# D. L6 D
< ><FONT color=#ff0000>函数名: bar </FONT>
7 K2 ]4 a2 k! U. Z功 能: 画一个二维条形图 % L J6 ?! z- k1 C5 T
用 法: void far bar(int left, int top, int right, int bottom);
, u3 p7 @! p% E) v; ?+ T$ Y( y) {程序例: </P>
2 Y/ q/ m2 [; C: }$ X. f< ><FONT color=#0000ff>#include <GRAPHICS.H>
2 [$ r; \6 K& a3 @0 w: E% I' n* }#include <STDLIB.H>/ e' d$ }9 e# }2 Y. {& }: T- a
#include <STDIO.H>3 b+ b3 m: ^" O* f2 j9 o
#include <CONIO.H></FONT></P>2 O, ?, F4 R$ x' n- i' X
< ><FONT color=#0000ff>int main(void) & g& R$ W6 F6 y/ R# f6 r
{
H+ |6 O* e, g0 \0 g/* request auto detection */ $ H2 N. S' N; c* J
int gdriver = DETECT, gmode, errorcode;
$ t) K, F2 q- D$ D: V6 v! Hint midx, midy, i; </FONT></P>
' B% `: j; P j) I- p/ ~$ f" E< ><FONT color=#0000ff>/* initialize graphics and local variables */
: `6 W" o! y m& b1 L) i9 [# Binitgraph(&gdriver, &gmode, ""); </FONT></P>
- z9 ^# W( z& E/ T& r/ c< ><FONT color=#0000ff>/* read result of initialization */
9 e" {0 c; q/ y! |( A/ |errorcode = graphresult(); 6 s- v/ d2 V/ d& j" H- f n" ~
if (errorcode != grOk) /* an error occurred */
$ |; P! I1 a/ N& w# r7 m( \3 c- W{ 2 ^" j2 Y$ }* _5 a& \' B' I1 `: u
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 ?& [5 B! H1 `) M* ^4 y+ G0 E M/ O& Zprintf(" ress any key to halt:");
: s. g1 @1 n. l1 Q6 y- I& y, dgetch();
) N w* I' B/ Q! S, Gexit(1); /* terminate with an error code */
4 \" j i/ G) W( B Z) R} </FONT></P>
# d6 D8 O! x- e) y; g8 Q< ><FONT color=#0000ff>midx = getmaxx() / 2; 4 f) v; u r* l3 {" l1 M
midy = getmaxy() / 2; </FONT></P>
, S& V3 |; k! o8 v0 Q/ [2 y/ J< ><FONT color=#0000ff>/* loop through the fill patterns */ / ]; F% Q% d) n8 V. N7 k
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { . A& h1 d0 \5 k9 ^* N
/* set the fill style */
' }% u3 t0 P) P: w* @7 I osetfillstyle(i, getmaxcolor()); </FONT></P>1 M! G+ y: ^2 Y% u6 b d( ` q
< ><FONT color=#0000ff>/* draw the bar */ # f' E4 b6 h# b1 ^
bar(midx-50, midy-50, midx+50, / P% x, J# a* j2 `$ \
midy+50); </FONT></P>
" g5 h8 j0 Y1 f2 J< ><FONT color=#0000ff>getch();
+ U" }0 B6 k; q# y} </FONT></P>
* K! ?: ]% f$ E6 b< ><FONT color=#0000ff>/* clean up */
2 w4 s# {( m6 m2 wclosegraph(); $ G8 I/ P! q2 l6 f4 ?
return 0; ( R& s! }/ ?0 f
} </FONT>; B! E K5 |4 K! C
/ Z5 k0 ]4 c# ] c- M H* h
2 g1 `' T4 ?% f+ M0 R</P>9 d' z8 P9 f& @9 V) d. X
< ><FONT color=#ff0000>函数名: bar3d </FONT>
" ?& n4 y- ^: k7 f* v$ C功 能: 画一个三维条形图
* |. g" i2 n$ f/ F9 o用 法: void far bar3d(int left, int top, int right, int bottom,
& U+ { W0 i$ \* V9 y: qint depth, int topflag); # a4 C+ K- I7 [+ r J. _5 I: w
程序例: </P>
: C0 c2 D" j) X5 @< ><FONT color=#0000ff>#include <GRAPHICS.H>
* g/ O3 E& \- J#include <STDLIB.H>. {! L8 U6 A7 L. C/ C1 G
#include <STDIO.H>
$ ` w0 T% W3 S8 f6 g#include <CONIO.H></FONT></P>
; f, {8 Y8 @+ H9 r< ><FONT color=#0000ff>int main(void)
% i5 l8 u* c, j5 e2 t" a{
/ n& N" ^* r% J. B7 B5 X! ?- o5 J/* request auto detection */ - l! z. I/ f0 V6 D
int gdriver = DETECT, gmode, errorcode;
" v6 E6 `* C8 a3 q6 [3 _int midx, midy, i; </FONT></P>
! s- a" e: V0 D5 \( t< ><FONT color=#0000ff>/* initialize graphics, local variables */ ; L; C# ~, I" K5 B' T0 k8 z! F
initgraph(&gdriver, &gmode, ""); </FONT></P>
6 w* O3 @8 P" w+ h< ><FONT color=#0000ff>/* read result of initialization */
' G O! v$ D0 verrorcode = graphresult(); 9 n7 ^0 d5 j$ E& C: D+ D9 T
if (errorcode != grOk) /* an error occurred */ ( p. M/ k% X6 a/ d, c' M
{ * R% D; Y; A4 @4 f0 w7 A! W
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ X1 A% V' R2 U5 i4 V' dprintf(" ress any key to halt:"); " k- w0 b) E" r k
getch(); 4 M4 W5 X T5 i9 v$ E7 V% R2 ^
exit(1); /* terminate with error code */
0 B$ Z4 X) ~6 F: \+ L' `} </FONT></P>
, w ?+ H$ @0 O1 h< ><FONT color=#0000ff>midx = getmaxx() / 2; / Q" ^+ n! A& w, G5 F4 g
midy = getmaxy() / 2; </FONT></P>
( }$ M9 z; r4 m4 }6 z< ><FONT color=#0000ff>/* loop through the fill patterns */ & [; J1 B) e$ h9 l1 P7 f
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
) h7 ~7 ?' M# ]/* set the fill style */ ( `/ _! D* [5 ~+ U
setfillstyle(i, getmaxcolor()); </FONT></P> b# S" _" u2 ^( V. E: z H3 `2 Q
< ><FONT color=#0000ff>/* draw the 3-d bar */
3 Q. ]5 F! c- l* ?1 a6 g9 Kbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
0 D$ q# G; J6 P! y< ><FONT color=#0000ff>getch();
% `6 T- M: d/ U7 R3 Z3 ?} </FONT></P>
! t2 L; `" S2 C" C. R5 h3 s< ><FONT color=#0000ff>/* clean up */ V( q4 o& l* m$ e3 K. s
closegraph();
% N& a- M2 S$ V, [# u" preturn 0; $ k1 j0 V4 H( k U; Q
}
1 a+ j0 L; M5 }: x ?</FONT>
! n" X {- X) m$ r- o k. t% P ]$ X/ i: S: i: n6 Q' X2 I \
</P>( y1 b& Z7 m" E* \
< ><FONT color=#ff0000>函数名: bdos </FONT>
! r8 X, O& ^1 W功 能: DOS系统调用 6 x9 W1 C0 E' {6 ~% ]
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 0 ^" ?2 u: I; R! v* L$ v b/ \
程序例: </P>+ e: S4 `9 j$ H0 ]# ?3 z7 C- `8 m
< ><FONT color=#0000ff>#include <STDIO.H>
/ ]0 K/ R" g2 U6 F. ^% F#include <DOS.H></FONT></P>
- @# Q. @! ]1 a& T< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
0 {/ {, n# t5 i. X. Achar current_drive(void) $ y7 x" ~& }# T( t
{ * Y1 v, |7 u8 F4 ] |3 u" E* x: N
char curdrive; </FONT></P>7 v; f- a/ H8 m' I5 p
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ % `! B, |( r9 P) @
curdrive = bdos(0x19, 0, 0);
* X0 ], r: V7 L: K# {3 Sreturn('A' + curdrive); ]. N4 e. s3 l% d# e0 t, h
} </FONT></P>
' K4 m9 g4 \+ ]8 a9 I' M< ><FONT color=#0000ff>int main(void)
* C! c! A- a K) f{
6 T( e! H7 @6 d& Lprintf("The current drive is %c:\n", current_drive()); : S( b! _- [* a* ]4 _& a, X
return 0; 5 V4 J" q/ {/ v* b
}
2 B/ F i+ c& }5 D' J, b, B& ^1 P. Y' c5 X0 [& U9 h
</FONT>0 k3 ~$ |5 t+ m
</P>7 U* K8 a3 z7 |- U J
< ><FONT color=#ff0000>函数名: bdosptr </FONT>
+ F. O+ P- r4 X: w. V功 能: DOS系统调用
' t2 Y1 p6 }3 N8 I2 T用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
j! o$ {5 }% e+ o: {程序例: </P>7 @( c; p: @ l+ W: t1 S2 d0 s
< ><FONT color=#0000ff>#include <STRING.H>
. b6 k' Q: I. f( A0 E8 B#include <STDIO.H>9 R* Z- G0 P3 M. ?8 x$ Z! Y
#include <DIR.H>
6 L& s. A3 W! a( V#include <DOS.H>9 ?3 i. y( X. z' J/ E
#include <ERRNO.H>' W s. C8 Z: Z! ^2 R Z v5 b
#include <STDLIB.H></FONT></P>+ t3 z/ c% u) E0 X* @ |1 V. t
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
n. J% c' i3 @3 ]<P><FONT color=#0000ff>int main(void)
. K# D; C" M3 u: m6 |& k! M. ^{ " H5 s: P( D' A, x" q' x/ l9 j' o
char buffer[BUFLEN]; # }8 |1 L: L( R; w C
int test; </FONT></P>8 ~, ~" M8 c- ] j' P5 v/ b
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); / h: u1 ^% P! g1 j% g: g' ]4 O+ c
gets(buffer); </FONT></P>) ^7 {' v, t) B9 s, @: \
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
- X$ L( K6 W" N5 [* K/ Iif(test) " m5 k" ?4 A8 X) Z' Q
{
# J& A/ n$ m6 Xprintf("DOS error message: %d\n", errno);
( b0 P( N$ I% e3 v+ ?/ n2 D7 ]/* See errno.h for error listings */
$ |$ ]# x9 T5 m* o5 z4 X. rexit (1); ; a" \5 A# O }, c
} </FONT></P>
* f8 M0 g! C! E<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
+ F1 E h. F4 A/ e' _. H; w3 Tprintf("The current directory is: %s\n", buffer); </FONT></P>
' |) |1 G. s+ R$ |) m; H3 Y7 `: m<P><FONT color=#0000ff>return 0;
1 S, z( a$ c d6 t* a6 J, i} ( i& w% @0 h" d; I' T, W
</FONT>
: G- W' `; e" F2 g( ~1 e& A/ Z& j1 N+ r
</P> r4 b0 T: q2 p$ I( ~! M! D
<P><FONT color=#ff0000>函数名: bioscom </FONT>+ Q* A8 O7 y6 L; c
功 能: 串行I/O通信
T( L& N# k" z8 b% f( M4 B用 法: int bioscom(int cmd, char abyte, int port); 8 M0 f5 C: ~4 i' u- ~
程序例: </P>
* k: L- ^ K/ M1 _2 _7 I- \9 Q<P><FONT color=#0000ff>#include <BIOS.H>
1 A1 C! X+ z5 l#include <CONIO.H></FONT></P> V" t$ ]) |2 x, m% E- U2 Y6 `
<P><FONT color=#0000ff>#define COM1 0 : P* K4 J, }* p( C5 x: e6 a
#define DATA_READY 0x100 : P5 W* F7 F2 [- V2 Y
#define TRUE 1 9 @+ y4 N$ z2 R' y+ L
#define FALSE 0 </FONT></P>
0 Y9 q5 {$ S+ p/ S<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
+ X- B& w/ l2 Y<P><FONT color=#0000ff>int main(void) $ P8 z: d- s# o% k1 I/ C
{
: a3 T, n& M" K$ }% t3 Jint in, out, status, DONE = FALSE; </FONT></P>. n# H+ x, D9 U, M- P: C2 D
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); 1 x0 G& Z. [! ?
cprintf("... BIOSCOM [ESC] to exit ...\n");
# Q) e, U. q6 {# E& D' \' ?while (!DONE) - L1 R4 v: X& U% C6 \
{ : [7 U& L. Y( a8 R4 M h: B) j8 k. l
status = bioscom(3, 0, COM1); 9 z6 c- o' s5 y2 i
if (status & DATA_READY)
) ^; `: q1 f5 S: w% [5 Vif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) 4 n, x' n! v8 P9 Q n0 y% Y
putch(out); 1 o! N1 k# h# F$ ?9 L A, D, _ X
if (kbhit()) , o4 D8 l+ G: u( b! _' Q
{
; `/ R' ~5 Y1 hif ((in = getch()) == '\x1B')
6 {! N [. I& M% ^DONE = TRUE;
3 C% }0 @- U; p2 M$ E3 u4 t% T6 T8 E- fbioscom(1, in, COM1); 5 q+ t% s( L6 E8 i8 C' m
} " b/ h$ R5 ~. a( p
}
: I- p% ^3 o2 T6 I- B8 v7 v8 ?return 0;
' L4 ^5 k2 A5 Q8 K+ c% P! t" e4 y% e} </FONT>
( \/ F! k; A: v; `
* A' J- q5 \6 W+ d* m8 M6 z4 [, x# k, q; f. ]) c& }! X
</P>
5 {9 J+ a ?! T<P><FONT color=#ff0000>函数名: biosdisk </FONT>" _! v, G$ E+ @7 e7 c
功 能: 软硬盘I/O / o( H% a, X3 w' u
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 8 M5 s! P8 e& P, J& D, [
int nsects, void *buffer);
( i7 a7 s1 i7 G4 ^0 ] N0 f- i程序例: </P>8 V: M5 ?+ `$ g# w6 d$ \. L
<P><FONT color=#0000ff>#include <BIOS.H>
, x$ U- l0 L1 ~5 F% a#include <STDIO.H></FONT></P>4 L* @" y- L& Z$ q7 c( V, f
<P><FONT color=#0000ff>int main(void)
% J/ @) {* A. @' m" }# @{ 9 o6 V- L+ q) o! \# t; g
int result;
, I8 a7 S2 ~" S* Q) Z9 {4 k( P+ W8 n* wchar buffer[512]; </FONT></P>
: m5 \/ f% R! `<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 9 I; N* L0 K! e$ R0 g; F
result = biosdisk(4,0,0,0,0,1,buffer);
: Q, b' d G' i8 g# s- cresult &= 0x02;
/ u7 n, F5 [3 b, S( M% d(result) ? (printf("Drive A: Ready\n")) :
5 F5 X5 H L% [! ^8 x6 H8 g$ y) F(printf("Drive A: Not Ready\n")); </FONT></P>8 E+ w* v! H8 M- M, o
<P><FONT color=#0000ff>return 0; 7 x$ ?1 U r4 Q+ w7 \: e
}
- P7 I1 q0 y; e6 |</FONT>
/ Y# L; T& \: B( F1 f" y$ A( @, N; K( ]" l0 `3 H
</P>: s+ I1 M8 h0 B/ W% u! v
<P><FONT color=#ff0000>函数名: biosequip </FONT>
$ L6 \% u- W$ g. }& w. {7 j# \功 能: 检查设备
: N* j: y; X/ O/ l( ~4 |) P用 法: int biosequip(void);
2 o& J) [/ G' d程序例: </P>. W$ B( e- _/ I+ @9 H5 p
<P><FONT color=#0000ff>#include <BIOS.H>
K0 u" U ?* |0 B1 c) T3 T#include <STDIO.H></FONT></P>+ y7 U( q6 I5 @
<P><FONT color=#0000ff>int main(void) # W! F3 v8 y$ ~0 [! x* V( \* |+ S! q8 I1 @
{
" p; O2 ?/ u, _; p/ r X) j# L2 {; gint result; 4 f+ @: M$ x" v/ `' g$ {
char buffer[512]; </FONT></P>: Q/ l9 G o7 O
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); . l: ~* w2 `! Q, L2 x
result = biosdisk(4,0,0,0,0,1,buffer);
' y$ P$ N; l" _: m! {/ Presult &= 0x02;
& ?6 J3 F; i. v5 @(result) ? (printf("Drive A: Ready\n")) :
9 m: ]) q2 y" J(printf("Drive A: Not Ready\n")); </FONT></P>, h8 w8 v! U7 ~
<P><FONT color=#0000ff>return 0;
; q0 l: ?6 u4 J2 _}
% @( v; r, x$ F% J5 H$ a</FONT>0 R9 n9 O) C! l! J8 u
+ w/ G) p+ z/ x( g
</P> _: p/ r) t3 a
<P><FONT color=#ff0000>函数名: bioskey </FONT>+ i0 K& ^' p# A
功 能: 直接使用BIOS服务的键盘接口
' L# q; d9 z7 e2 D4 n用 法: int bioskey(int cmd); " S3 s8 O! C" m* F# D* F
程序例: </P>
0 N! C) a' u, z<P><FONT color=#0000ff>#include <STDIO.H>, y$ c" I3 ]7 e% \; o( B4 b0 t
#include <BIOS.H>
) c* V ~ Z! n#include <CTYPE.H></FONT></P>
9 |: x7 w- v x' c<P><FONT color=#0000ff>#define RIGHT 0x01 0 R4 l& E7 o1 L% ?$ `
#define LEFT 0x02 : z( ^+ x7 h9 c9 Y$ }
#define CTRL 0x04
/ [: d" E$ y: W/ F2 M+ A#define ALT 0x08 </FONT></P>, O) M0 P( O* n+ t0 ~4 B
<P><FONT color=#0000ff>int main(void) . c0 j2 [) _2 f+ k/ X) l8 d
{
6 t* A) A$ y4 a) h+ I3 S8 bint key, modifiers; </FONT></P>
+ [0 ?2 g! f3 ^9 U<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ # y" a/ a7 a4 B% J$ P
while (bioskey(1) == 0); </FONT></P>9 S$ `* b6 V% d o
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ R: a/ r* O! Y" t. Q
key = bioskey(0); </FONT></P>! ]8 c$ b8 N6 N; E% {5 t
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
9 ?+ t3 @) U( I& z1 X% {* emodifiers = bioskey(2);
4 ~! k( k; E: ~* Z3 wif (modifiers)
7 ]9 P6 x9 v) }6 y7 ?# ]2 ^{ / ~2 Y# B. P; F' M/ g1 L. o
printf("[");
) S( u/ D) j- h, s; Cif (modifiers & RIGHT) printf("RIGHT"); ; {* z0 e v' B; B V8 w: Y# S* c
if (modifiers & LEFT) printf("LEFT"); 3 K$ N$ a* D2 X; o6 k' Q0 Y' h" Y. ]
if (modifiers & CTRL) printf("CTRL"); 9 o x8 S7 E+ Z
if (modifiers & ALT) printf("ALT");
4 O, n" R, t/ Z+ Yprintf("]");
3 q* c$ g8 @& U4 G} + |+ ~: @- ?4 S3 m+ i( t" t
/* print out the character read */
. g' S% G8 @; [4 T1 i, _if (isalnum(key & 0xFF))
" l7 |* Q2 A+ d, {5 Qprintf("'%c'\n", key);
! S, ?5 r; H* ^6 H+ B3 lelse $ \4 ]* x( L' r, T1 m
printf("%#02x\n", key);
* i# x3 ]; z# D- t% [return 0;
9 F4 k1 {3 Y$ T! b} 1 K5 L& n) u+ n. T5 M, o
) \5 ^7 `9 |" t
</FONT></P>
$ S! A4 x) D) N1 T<P><FONT color=#ff0000>函数名: biosmemory </FONT>
1 k( O$ I" L/ I0 n功 能: 返回存储块大小
! o- `" |& L5 W用 法:int biosmemory(void); 4 x; I2 f9 D8 ~( d5 z# u
程序例: </P>; d) s5 t4 m0 v/ @3 i
<P><FONT color=#0000ff>#include <STDIO.H>0 t! z2 v: w6 X7 A3 x
#include <BIOS.H></FONT></P>1 K8 F. l+ j. |- Q& H) h% a
<P><FONT color=#0000ff>int main(void)
% s: ~- v6 M& Q& `+ |{
- b; t: g$ x, }int memory_size; </FONT></P>. M4 E. v/ n3 |9 d e5 m w. a
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ ! R% O4 x+ o% `; U9 ?, t7 B6 S
printf("RAM size = %dK\n",memory_size); 0 g( V. D; w; ~8 d7 P
return 0;
: M; b- E% n- R& Q8 O# V+ @} 9 g+ N( k- @! O( G% ~. {, P
</FONT>
) B$ X+ [* K7 G( ~. B' r" L1 ]8 u7 N+ W
</P>
B j+ }& F; ?4 O<P><FONT color=#ff0000>函数名: biosprint </FONT>9 { s1 [8 Z& ?9 }, ?- g
功 能: 直接使用BIOS服务的打印机I/O " a) t# @' \6 b. p# c s
用 法: int biosprint(int cmd, int byte, int port);
+ b/ U3 \: I9 K' o程序例: </P>
3 {9 w& G$ M9 U3 r6 }* j<P><FONT color=#0000ff>#include <STDIO.H>
' q4 k2 R3 P2 g" \: G#include <CONIO.H>/ l4 x4 j* p6 T6 m6 }0 s" r% _
#include <BIOS.H></FONT></P>3 K6 F- } V! Y
<P><FONT color=#0000ff>int main(void)
4 P6 Z, y9 J3 t* V, Y1 w2 f0 c{
+ O4 I- j( p, D7 @2 H! K#define STATUS 2 /* printer status command */
. {+ `' G5 i; E% F#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
: k1 }8 J" Z! V+ E& D<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
. z% C/ i* U3 E! P. b- e9 l<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
$ N2 w' Y# _# B* b: c/ y( d( p& ogetch(); ( H8 i5 {# `/ Y
status = biosprint(STATUS, abyte, PORTNUM);
/ ~% S/ Z/ _) C* T+ z7 g# vif (status & 0x01)
3 Y6 D8 _5 u$ V. z! Z( v" w& Gprintf("Device time out.\n"); 6 W$ j( |, U: o) z
if (status & 0x08) 1 C$ |: M5 O1 y9 j) {
printf("I/O error.\n"); </FONT></P>3 _% Z9 r4 S0 G
<P><FONT color=#0000ff>if (status & 0x10)
, Y7 w) J M: w0 s$ B4 E9 Jprintf("Selected.\n"); - E( O3 |! J. c g% j
if (status & 0x20)
1 K2 |" o3 t! r+ c. Wprintf("Out of paper.\n"); </FONT></P>( l' w( C- n2 m) C
<P><FONT color=#0000ff>if (status & 0x40) * y$ Z! i6 m* ^
printf("Acknowledge.\n");
: M( j" ]9 \% h" N9 Iif (status & 0x80) 5 G0 w: ~* T0 P: }0 `5 R
printf("Not busy.\n"); </FONT></P>4 e; I7 Q9 O" s* ]0 ?' k
<P><FONT color=#0000ff>return 0;
" }5 U: U: u' E- [( u3 N# Z}
3 J5 J" @$ }4 {7 r1 t" q" |: Y z</FONT>
- Z% h4 \% x$ b6 S
3 a8 T' h9 y9 Y8 |7 C</P>
6 _) }& g2 Y6 ^8 L# I( l/ P<P><FONT color=#ff0000>函数名: biostime </FONT>" X" w/ u! E5 b% i: Y& |
功 能: 读取或设置BIOS时间
! G w( z- W+ M用 法: long biostime(int cmd, long newtime);
% v$ h$ p2 m$ r& d+ `, B* v7 t3 R程序例: </P>3 y; J. \) M5 a/ X/ ]2 z7 U
<P><FONT color=#0000ff>#include <STDIO.H>' |1 ?/ n# ?' g( F5 P6 c7 X
#include <BIOS.H>
9 y/ T. }4 h& |; _) S+ r#include <TIME.H>5 S+ l0 _* G6 o: s) q8 N
#include <CONIO.H></FONT></P>$ G- k$ ?: V& Z5 N, ?
<P><FONT color=#0000ff>int main(void) / H, F/ f$ D5 A: u! i6 |
{ . y! i. s( J% {0 H! G& K
long bios_time; </FONT></P>/ i9 i$ N) d& G* P
<P><FONT color=#0000ff>clrscr();
, D- U* x! X& \+ P, C/ o s* U2 Fcprintf("The number of clock ticks since midnight is:\r\n");
6 U8 N, D2 V0 T3 `cprintf("The number of seconds since midnight is:\r\n"); / _9 z% J: f% N" N" f
cprintf("The number of minutes since midnight is:\r\n"); l' n5 M* y3 L5 y4 C1 G
cprintf("The number of hours since midnight is:\r\n");
3 W; A8 v3 A- }/ N& x; u2 k4 S) Fcprintf("\r\nPress any key to quit:");
; I5 G% x% z+ N) S) Nwhile(!kbhit()) ( f$ a' G7 l7 g; T# J" z
{
) T+ t3 x1 E4 D" Q0 `bios_time = biostime(0, 0L); </FONT></P>
" z+ i0 o0 h/ C, j3 }, m<P><FONT color=#0000ff>gotoxy(50, 1);
$ \* E: q# T5 J; c- X. l: i! Ncprintf("%lu", bios_time); </FONT></P>
- v. d# X5 ` h! X<P><FONT color=#0000ff>gotoxy(50, 2);
7 O+ Y2 _! f5 X/ hcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
9 B) K. \, V/ [<P><FONT color=#0000ff>gotoxy(50, 3);
8 _; P7 h4 f" N3 H! @cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>9 O7 u0 l L. u( g% F) V3 Q
<P><FONT color=#0000ff>gotoxy(50, 4);
# X! D, K8 n% Z: `; \: S1 Ocprintf("%.4f", bios_time / CLK_TCK / 3600); - E0 g, M+ P7 a3 j' v+ s
}
& k. g0 P8 T! ]2 @! Ireturn 0;
( e5 K" y& D6 r; `3 }}
" l. [1 o4 ]3 d. B7 @9 E</FONT>
2 v+ ?" r. H6 Q$ A$ b# z1 T6 o7 a6 H- Z! P
</P>
8 g0 B6 K' k1 u. ` M$ u4 R3 p<P><FONT color=#ff0000>函数名: brk </FONT>7 k0 o' G2 U0 G, p
功 能: 改变数据段空间分配
1 z# g5 m/ [* J$ G- c/ `4 L( q用 法: int brk(void *endds); $ u9 a0 J+ s3 s- L. s; K
程序例: </P>5 S7 a& S6 z2 l' X
<P><FONT color=#0000ff>#include <STDIO.H>+ f4 v. P" S2 t& u; w
#include <ALLOC.H></FONT></P>0 X& p/ ~* @0 p/ F; y: g' t
<P><FONT color=#0000ff>int main(void) ; A! h6 i6 P* K) j4 @/ U
{ 0 M/ [7 n4 Q9 Z2 a4 M
char *ptr; </FONT></P>
/ _5 j9 a5 \: i# }/ g1 k- m- N<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
% T2 E0 G7 m& ]& g0 u# @ptr = malloc(1);
7 E% J% D6 j$ e: g# u& Yprintf("Before brk() call: %lu bytes free\n", coreleft());
( k$ v" y! a2 L2 U4 Z: P3 p# l3 nbrk(ptr+1000);
! o7 |$ a" ^- h1 f3 [printf(" After brk() call: %lu bytes free\n", coreleft()); " [* q( b% j2 V7 }) g5 R) s0 W
return 0; & X7 |# e, H' l7 g' m
}
( ]' k, l* u1 P Y1 |( w& x, U* J; a2 S4 U: U
</FONT>
2 ]7 a" {) ]1 I</P>6 y$ a, k# ~0 D) V' L. _& a
<P><FONT color=#ff0000>函数名: bsearch </FONT>7 `+ x/ S( {+ u/ v; B/ J
功 能: 二分法搜索
/ I8 C2 P M2 K; M5 C0 u用 法: void *bsearch(const void *key, const void *base, size_t *nelem, 9 }$ ^3 v7 y/ d8 J( |
size_t width, int(*fcmp)(const void *, const *)); 7 R0 R0 J1 ?& y" Y+ i# I
程序例: </P>7 W3 j) d4 d9 J1 N8 n5 H& M8 ]; l4 o
<P><FONT color=#0000ff>#include <STDLIB.H>
% x6 v1 c: k$ a$ i0 k. r& D7 \9 s7 T: L#include <STDIO.H></FONT></P>3 n) [3 j; ?9 ?- t
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
9 C( O7 {& F7 ~8 d<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>7 ~6 _: k3 m$ v! F
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
/ t8 \% P( t- ?+ R. Z! ~0 d: n{ 7 H& M6 g8 F8 D) b' _" n7 X6 f
return(*p1 - *p2); R0 X X' Z0 v/ \2 z" [# K4 O
} </FONT></P>
6 u2 s! j& j8 e# C& J' v<P><FONT color=#0000ff>int lookup(int key)
1 [6 ^) L# m% X/ X- ~% I: `# m{
+ j/ W' a- ?; G9 Oint *itemptr; </FONT></P>
0 C2 I2 R2 o; N) B( D3 M- I<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) 2 r- _8 \' \1 B" c
is needed to avoid a type mismatch error at 7 w. d6 t8 Q/ c/ A% c
compile time */
|( j/ i* f' i( ritemptr = bsearch (&key, numarray, NELEMS(numarray), 6 M- M' h1 T/ D! Y: ?$ E: R+ g
sizeof(int), (int(*)(const void *,const void *))numeric); " s0 v4 k& [4 ^2 L1 v; _3 {- U% L
return (itemptr != NULL);
. V3 A @) U( R- n) s! F+ P} </FONT></P>0 C, k" N$ f" Y, O2 Q, g9 V3 j: q' d
<P><FONT color=#0000ff>int main(void)
& w. E( N+ e: A$ I! |( z* j; r/ B{
r: h/ @* F) Jif (lookup(512)) $ C; j! M, l$ S& ]
printf("512 is in the table.\n");
. S6 r# Z$ ]5 O2 ], felse
7 X/ ^6 C) b6 e/ B6 wprintf("512 isn't in the table.\n"); </FONT></P>
# K0 n$ O* l+ p+ {0 ]" E9 I2 o+ n+ ]<P><FONT color=#0000ff>return 0; . U9 C; }' |& J6 x e! Y# ^
} </FONT></P> |
zan
|