- 在线时间
- 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>1 Y& G( [( H6 r4 z" Y
< ><FONT color=#ff0000>函数名: bar </FONT>
, I% I0 F/ z/ ^, `7 k功 能: 画一个二维条形图
" a" r( p% V! y! E4 O用 法: void far bar(int left, int top, int right, int bottom); - h. g2 v7 @! }! d
程序例: </P>+ x6 L4 g5 W: L5 d9 t' }
< ><FONT color=#0000ff>#include <GRAPHICS.H>
- G# F; a/ K& c6 b' m( ^ }8 z#include <STDLIB.H> v' g0 e" A+ A: F/ @
#include <STDIO.H>* F5 A' ?& W5 \, o
#include <CONIO.H></FONT></P>6 K$ V f ]- J
< ><FONT color=#0000ff>int main(void)
4 ` T9 l% h/ o! W* z2 T9 b: N{ ' U* D5 K3 ~5 h" e5 A5 b
/* request auto detection */ 3 G1 Y! r( Q' K: X4 t
int gdriver = DETECT, gmode, errorcode;
2 P4 \) G- R9 h" vint midx, midy, i; </FONT></P>4 h! }$ W5 F6 |$ _: [' w
< ><FONT color=#0000ff>/* initialize graphics and local variables */ - w6 j0 c5 s0 ]! N
initgraph(&gdriver, &gmode, ""); </FONT></P>
+ L# c2 R, I7 k' g* ]' r) |< ><FONT color=#0000ff>/* read result of initialization */ + U/ T9 M. }7 A% J1 @* `; R2 e# K, g1 I
errorcode = graphresult(); ( D% `' H( ]" g+ h9 k1 Z4 W
if (errorcode != grOk) /* an error occurred */ " _* a) K/ L5 v1 K! z6 ^
{
9 r8 \- |: I8 w; K: Hprintf("Graphics error: %s\n", grapherrormsg(errorcode));
& Y$ K; W; A4 ^! d" a6 Y' ?printf(" ress any key to halt:"); 1 {% z0 x6 }# T Z* M
getch(); 5 V) J S/ Q+ w7 [; g
exit(1); /* terminate with an error code */ ; j7 j1 ^* @; C; J8 h; x+ R! D; f6 z p
} </FONT></P>
1 G# M2 K/ U6 u+ P< ><FONT color=#0000ff>midx = getmaxx() / 2; * B# e; R/ E/ q: H1 S; h
midy = getmaxy() / 2; </FONT></P>& @2 M& ^' j" g! S
< ><FONT color=#0000ff>/* loop through the fill patterns */
: ^% D4 g9 t' F0 u6 Zfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { 4 ~. n/ ?, ]+ ]) O4 j$ ^' k
/* set the fill style */ ; k. L, A, |, U2 Y8 q2 K& O
setfillstyle(i, getmaxcolor()); </FONT></P>( h, ~5 `8 ?5 K
< ><FONT color=#0000ff>/* draw the bar */ " u h& t! @0 V" \( j
bar(midx-50, midy-50, midx+50, 8 c, i; ?. L7 c) V+ P# L. r
midy+50); </FONT></P>% N, u0 o( v4 p! f) o+ v8 G! c1 u
< ><FONT color=#0000ff>getch(); 7 N5 M. D6 ~# c, s7 d6 R
} </FONT></P> P: N r J6 |0 |4 p6 t6 ~
< ><FONT color=#0000ff>/* clean up */
' `! Y- U) Z8 ^) B" Z% Nclosegraph(); ' o' o+ x9 y1 w1 v- r* y% M+ v
return 0; ) M3 u) k+ b4 h4 w' s. H: _' O, R
} </FONT>8 v# `8 l, }$ t0 h- [( Q7 P6 h
& f# y0 D. s) v: l0 r
8 G* d7 H# n" w1 G s/ R9 o$ K+ g</P>, |9 ^- T' ~" p- O; I
< ><FONT color=#ff0000>函数名: bar3d </FONT>) B) A- G' t* _7 c( B( _( }5 l, \
功 能: 画一个三维条形图
& X- Y1 U- j( e( U# L用 法: void far bar3d(int left, int top, int right, int bottom, 1 X7 A$ O6 q! j' ?
int depth, int topflag);
$ c8 V) e# w/ C' x* w程序例: </P>
$ @6 q1 T/ u! j< ><FONT color=#0000ff>#include <GRAPHICS.H>
+ m( c9 `9 G" o' D! U6 ^#include <STDLIB.H>- r: D) o" Y$ y1 Q
#include <STDIO.H>) `5 m+ q9 R- K
#include <CONIO.H></FONT></P>
1 f3 E8 f/ P5 J1 t ^& _# ~< ><FONT color=#0000ff>int main(void) 0 \# X0 m5 i9 N8 H
{
8 o D! d0 A. B, E2 y- e7 N1 ~! r/* request auto detection */
5 f: \" c; Y4 E, Vint gdriver = DETECT, gmode, errorcode; 4 L6 m# Z% {, Q+ {/ a$ E7 t) m
int midx, midy, i; </FONT></P> y: S3 ~: S0 Q% g9 K
< ><FONT color=#0000ff>/* initialize graphics, local variables */ 9 [. t5 ^) x. C" U: c& l1 \" o
initgraph(&gdriver, &gmode, ""); </FONT></P>0 K. A* A- l1 i8 T, K0 B
< ><FONT color=#0000ff>/* read result of initialization */ ) Z A+ {2 a3 Z& e8 z
errorcode = graphresult(); + \$ t' @9 E- ?% @+ o: k
if (errorcode != grOk) /* an error occurred */ 1 q, @, }1 V7 S# T" O' M2 H
{ 1 g0 r: S3 ]( R" f$ K$ q
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# C) I7 ~: M$ eprintf(" ress any key to halt:");
6 j T% X7 }2 e( E bgetch(); * s4 m& i: i# S
exit(1); /* terminate with error code */
+ e0 e, N, T% u' ?3 W} </FONT></P>' ]" C {* I! A7 l& j$ s4 }
< ><FONT color=#0000ff>midx = getmaxx() / 2; ) _8 T' q9 n; U! x, F6 G- \
midy = getmaxy() / 2; </FONT></P>, x {1 I7 o. U# N2 R
< ><FONT color=#0000ff>/* loop through the fill patterns */ 7 }4 n2 V2 w; }# `; F
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
- c( P j! D3 q/ A' v V+ p3 ?/* set the fill style */ + D" G$ e5 H, r6 j1 E0 H. w
setfillstyle(i, getmaxcolor()); </FONT></P>
5 b$ v; ^0 [) N; k& |< ><FONT color=#0000ff>/* draw the 3-d bar */ T) b& m% `, c+ Z, A
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>* U+ T& @4 P8 ^' z( V
< ><FONT color=#0000ff>getch();
/ M+ a! v/ `5 y3 j5 ^8 i} </FONT></P>
; v1 B& a: W/ O/ Q3 y< ><FONT color=#0000ff>/* clean up */ 9 e" D4 x8 a# H
closegraph();
% X# N$ d0 _, }0 ^% P, Yreturn 0;
7 x0 B& r7 G; h: C' N& O} , ~& b1 {& j- f
</FONT>
, Y, y- z8 p W! m. M6 j
3 e0 J; ?9 {& z" H: X</P>/ Q3 ~ k2 O& Q
< ><FONT color=#ff0000>函数名: bdos </FONT>
# J2 C0 q+ I- @4 P0 r功 能: DOS系统调用 ' b2 }) Y2 r v6 T# H+ M! _
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); " J# S3 i6 E. f8 ?! x! c3 N f" `
程序例: </P>: j+ G& m8 B4 C) G5 Y+ M; t
< ><FONT color=#0000ff>#include <STDIO.H>
) ~, i% c8 B$ M. {' e( y#include <DOS.H></FONT></P>( ?5 C+ \8 d) U X% `9 A- w1 s
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ 5 d& N$ V( d; X* a
char current_drive(void)
$ w1 R, U( t' [{ / f a; q m( q) g" }, _; c: |! B
char curdrive; </FONT></P>5 f4 ^( z9 N9 }! ?
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ ' f8 L0 J0 c3 Z' ?# P$ c
curdrive = bdos(0x19, 0, 0);
/ f8 J7 A0 J/ e' f* xreturn('A' + curdrive); ) n0 G9 B/ G& m5 z; \
} </FONT></P>
. R% u8 s& Z; X4 C* C1 s0 ]# _; f< ><FONT color=#0000ff>int main(void) 4 y. |4 g( {% } C- S" {) T+ x0 W
{ ! R+ \8 T, i* T
printf("The current drive is %c:\n", current_drive()); / M1 H/ }" ]6 n
return 0;
' u/ r% N% E* S5 q1 M}
U0 d) k2 K/ I$ L
7 @. |4 U! v/ N0 {# u</FONT>
( K; k. D% D5 V</P>+ K& o; A) D9 P [( _
< ><FONT color=#ff0000>函数名: bdosptr </FONT>! i) `1 \7 Q, ^/ S8 z4 b
功 能: DOS系统调用 ) z. {! }' h* d( ?# G3 h! d
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
0 ]6 @8 {9 \+ m' U" T3 O程序例: </P>! }1 i# ~8 H+ a
< ><FONT color=#0000ff>#include <STRING.H>/ j' W7 m: U0 Z) C" H, O6 R5 {$ V2 Q
#include <STDIO.H>
( N, X: I; {, w/ k$ }#include <DIR.H>
# B# c( M3 S, C/ [1 n% e& i#include <DOS.H>% j& v% o1 i4 A( e+ J" W' Y: b/ d
#include <ERRNO.H>
3 p t( \ Z$ a* o- `8 x2 @2 ~' ]9 M#include <STDLIB.H></FONT></P># X& X7 G! l7 L) w
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>- ?% Y* y- n+ m7 Q% e
<P><FONT color=#0000ff>int main(void)
3 N5 w2 E* @+ u+ } [# J+ x( ~{
. G+ Z. k) n# t3 h4 \/ G& achar buffer[BUFLEN];
) }0 G" a C9 s9 |+ m; F: p1 dint test; </FONT></P>
/ x+ m' k0 T( J* e. {7 v<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 1 Q7 S9 m8 l' N P6 e7 u* H
gets(buffer); </FONT></P>0 V1 J) E. }2 q/ ^9 T
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 4 r, n! I" w1 \+ F; V- I
if(test) 8 u+ [! I3 G8 u$ C8 t: w
{ / I: V8 }$ C: [7 i9 Q* V- ]1 m
printf("DOS error message: %d\n", errno);
4 p+ s& O7 M1 P, n6 d/* See errno.h for error listings */ 1 R3 u# v- K6 |0 W
exit (1); - a. [# |% h9 i# n
} </FONT></P>
6 m; Z6 J+ t- K, K! L' B<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); ; m& \" k3 c: w) X& p
printf("The current directory is: %s\n", buffer); </FONT></P>- c% l$ h7 h C( s7 [5 J
<P><FONT color=#0000ff>return 0; : P, b3 K. [1 X g
} : m2 @% _$ r! F4 z/ Y! c. D
</FONT>' ]" F I# Z" u5 f: h
% t0 ^9 L2 A, P2 Z G" l
</P>
$ i1 y& ^$ g. o! q! a<P><FONT color=#ff0000>函数名: bioscom </FONT>
; H) E) Z% U; T+ g- h' z) D: M功 能: 串行I/O通信
. ^ P' W5 k* ^& @9 ~# k4 H/ z* B+ E: ]用 法: int bioscom(int cmd, char abyte, int port);
- h: l; u/ k X- E9 W" p8 J$ y程序例: </P>. Y8 N2 q/ E2 k# j' V' }4 ]/ J$ u
<P><FONT color=#0000ff>#include <BIOS.H>
$ y5 m d* j$ P: I8 ?$ y$ T4 u#include <CONIO.H></FONT></P>
7 n; a+ {6 A: W<P><FONT color=#0000ff>#define COM1 0
* y- ^9 Y, u' H6 W2 ~0 @: |0 A& {#define DATA_READY 0x100
/ c( R# F# X; S3 v: B) v#define TRUE 1
5 Y7 K6 ~0 D! d' P3 @) f: J#define FALSE 0 </FONT></P>* e0 N9 _& `7 [4 j4 v; x
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P> n: }1 _4 s2 T0 K3 m% d0 Q
<P><FONT color=#0000ff>int main(void) : @, N) ~5 x" n4 I; ?& `; q8 @ q" U. s
{ ' \% }' N4 g- b Y5 m
int in, out, status, DONE = FALSE; </FONT></P>% k& Y: s" @2 ~* x" E4 B
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
" M5 l$ X: o7 b( P$ ~6 s: A" o; Bcprintf("... BIOSCOM [ESC] to exit ...\n"); & ^ @, y3 |& w E
while (!DONE) 4 w& s2 n7 W0 u% @4 i
{
/ _. R z! ?5 `5 [8 h2 ?, Tstatus = bioscom(3, 0, COM1);
* C( F. l9 @6 {$ Pif (status & DATA_READY)
8 S3 w4 K8 z% E1 ^if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
8 i7 Q0 A7 X8 K2 m# kputch(out);
8 t/ q& P* h2 J9 Gif (kbhit()) 0 `5 u( _$ s" d ?; I
{ % j4 S0 i# C& u# l/ w
if ((in = getch()) == '\x1B')
0 D& r. G( q2 X, q- ADONE = TRUE; ! P/ n9 f0 _: C( y) l4 j& R+ [; ]
bioscom(1, in, COM1);
" D4 M( P K; C* L: ?} " J9 o# r5 o O" k$ \6 L
}
. s# O' M- _" t) ?3 g. V+ I8 Mreturn 0;
8 p& |# q, N6 p* u9 p8 _} </FONT>
. W& V, P7 f% Q" S# p7 `
' u& v8 i: m/ E% `/ y# B! E8 S/ H4 J9 s8 n y* }0 {
</P> }4 X" A& j4 U5 ^2 P5 e! v4 E4 ]
<P><FONT color=#ff0000>函数名: biosdisk </FONT>
6 H0 S+ M; ], s$ F1 H" L功 能: 软硬盘I/O
: S7 J5 \- S7 ?) _4 H A用 法: int biosdisk(int cmd, int drive, int head, int track, int sector % K2 A! M1 ]9 |$ f" `
int nsects, void *buffer); ! [1 Q v) l4 s+ y+ W! j! W
程序例: </P>
+ G. B( _2 g$ G4 a<P><FONT color=#0000ff>#include <BIOS.H>
" D8 ^8 Q' D( E2 x#include <STDIO.H></FONT></P>& m( r# {) i8 e' D' E# Y
<P><FONT color=#0000ff>int main(void)
! T: O* n+ r& c$ h9 i{
8 u* ]4 G6 S: V0 d9 O5 uint result;
& @; i9 E9 j" H: `# uchar buffer[512]; </FONT></P>* N0 {# E4 i) Z* J; I5 L' E& b
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
7 A! K8 b" [: w6 W/ y0 W* jresult = biosdisk(4,0,0,0,0,1,buffer); * F: f: T1 ]5 U& ^
result &= 0x02;
% A" J6 q1 F% [+ _7 j( P, B(result) ? (printf("Drive A: Ready\n")) : 4 C3 s' J( `: S. o# d" O/ G% d
(printf("Drive A: Not Ready\n")); </FONT></P>4 P' S- l8 t; L
<P><FONT color=#0000ff>return 0; 9 ?/ W$ G& [# Z* T6 m; o' Z) E! _
} ! q1 P4 O' \' O* e* \
</FONT>
* z* K$ w( `$ a4 c/ l
) n7 N9 T5 y, j. m</P>
) d7 x5 R( x, P6 l<P><FONT color=#ff0000>函数名: biosequip </FONT>9 x/ ^1 t. ^% x
功 能: 检查设备 0 z+ c" \0 F+ P; W
用 法: int biosequip(void); # ~ w; o# q( d
程序例: </P>) [1 X! `8 H" n3 O5 Y4 q1 i; m
<P><FONT color=#0000ff>#include <BIOS.H>
6 }. U! W3 P; g#include <STDIO.H></FONT></P>! B- [" O% {; P% B
<P><FONT color=#0000ff>int main(void)
, ?4 X5 J* d& h0 _{ ! v2 G/ Z- V% B4 p9 s; E( B6 ^7 P
int result; : G' c) e f0 g8 ^$ R# ^
char buffer[512]; </FONT></P>9 U5 w5 r) j7 R w( v
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
: W8 Z( {( c" d5 F% k; j( i2 Yresult = biosdisk(4,0,0,0,0,1,buffer); ) c$ O9 n( i/ C" k8 t* c. j1 y! ^% W: L
result &= 0x02;
% m) D( M3 H- Y% `(result) ? (printf("Drive A: Ready\n")) : ! V9 t/ A' [. h# Q
(printf("Drive A: Not Ready\n")); </FONT></P>
5 c# r# U" ]# G+ L<P><FONT color=#0000ff>return 0;
- O3 x" ~/ j: D3 @}
' L+ {) M: E4 B- q; C4 {</FONT>
7 A7 Q# B& }% i9 _$ F
+ L( f% j) ?) ~1 ^</P>
& w; K1 K0 {3 V2 `9 Q<P><FONT color=#ff0000>函数名: bioskey </FONT>
4 c0 i3 j2 h7 O* u! u功 能: 直接使用BIOS服务的键盘接口
5 ~1 T" u/ A! A7 _4 n# @用 法: int bioskey(int cmd);
7 M+ X; R' E7 H: {5 @0 O程序例: </P>+ o/ \6 H9 z! T. U
<P><FONT color=#0000ff>#include <STDIO.H>9 b ~% f* a7 e2 \2 }6 }
#include <BIOS.H>2 ~6 ~) Z2 q5 n& O4 I# m
#include <CTYPE.H></FONT></P>7 h) C" J2 y- P* S4 F: P
<P><FONT color=#0000ff>#define RIGHT 0x01 1 L* q0 a& f, a: F# P
#define LEFT 0x02 * y- T4 G! M' F
#define CTRL 0x04
6 i ~/ A: c5 V) t9 p9 S& P6 I#define ALT 0x08 </FONT></P>( b" o1 w" |: f0 x1 [# ^3 P, p1 ?
<P><FONT color=#0000ff>int main(void) : {& q6 f6 N& `& w
{
; ]1 E f0 W( o- o+ Q& p$ aint key, modifiers; </FONT></P>
s2 J* f9 g4 d- H; [<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ 2 J: e g5 d5 e! y8 m5 x
while (bioskey(1) == 0); </FONT></P>
9 O O5 `( r8 l; g! a<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
! b; k T! k& r0 @6 o6 Akey = bioskey(0); </FONT></P>; O* T( U' D" g
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
, A/ Y; Q! ^. omodifiers = bioskey(2); + b+ u! G: k- F+ d
if (modifiers)
+ `* M+ S5 i$ l; F& J2 Z3 d( A: z{
- W" W# [2 V9 }* L* j" A4 f) eprintf("["); $ i2 a. W6 l; U; r
if (modifiers & RIGHT) printf("RIGHT");
e2 r7 ^$ M. v& iif (modifiers & LEFT) printf("LEFT");
- |* B% w, w4 Y' _0 C& G* Dif (modifiers & CTRL) printf("CTRL"); U& G) B) H) g4 S
if (modifiers & ALT) printf("ALT");
6 I- ?5 {3 A' U" g% ]printf("]");
, P$ G8 W# B E9 P}
) ^5 ^ s' W" @/ K" V* R6 |/* print out the character read */
- b ]; k6 `6 Q D0 v$ N6 \if (isalnum(key & 0xFF)) 3 y! i5 e0 y/ v- a" u
printf("'%c'\n", key);
! H I" ^* T5 J) h3 e9 _( Zelse 2 q& E6 s8 N/ E( ?3 m8 W/ s
printf("%#02x\n", key);
# p! k6 `% y }+ U2 Sreturn 0; " I. P* H: B6 b3 ?& x# o
}
# t! \) Y+ ^! |( \, y+ G% T+ @8 ^# I, P8 W5 ]+ D! j
</FONT></P>! J, X2 m! Y% {5 H4 M
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
- k3 o8 ~) M8 _功 能: 返回存储块大小
7 }" @& W! E* ?( o* e/ _0 Y$ l" f用 法:int biosmemory(void);
8 d, {* h4 f2 g+ L: J4 y7 J程序例: </P>9 B+ J/ X& O4 @3 J
<P><FONT color=#0000ff>#include <STDIO.H>
0 U! @" Q6 |& Q# s* k( g% t1 d#include <BIOS.H></FONT></P>. Q' h0 v# G: W* [
<P><FONT color=#0000ff>int main(void)
4 l8 Q$ a, T, {; y. ^. K{
8 \+ ?: m- A) Y+ Dint memory_size; </FONT></P>' X$ d2 ^( K; [1 R6 a% n5 z( Q7 l7 ^- Y
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
8 }: O) ~! O4 I- Fprintf("RAM size = %dK\n",memory_size); % O$ T2 q9 w: L% X+ s2 ~' R2 d
return 0;
: r% |$ [, }% i9 g) H3 A* b$ {}
8 n/ O8 ~+ ^3 n3 Z. n1 u9 `</FONT>
. g( g- T. p. e" _2 ]1 d/ C& y# f3 n" D) I8 I& V' ]
</P>0 I8 z+ j# t/ s: t* s M4 z
<P><FONT color=#ff0000>函数名: biosprint </FONT>( W% b+ n& }$ y( J9 n4 O4 m
功 能: 直接使用BIOS服务的打印机I/O
; w( x# C: ?8 w1 }3 r* f用 法: int biosprint(int cmd, int byte, int port);
( Z3 H& ^& a/ M6 W# O* P) J8 T# N程序例: </P>
- r3 l% D: S& s% x<P><FONT color=#0000ff>#include <STDIO.H>: f/ _! z( z, e* X$ Q4 _, Y! i0 X1 Y
#include <CONIO.H>& ~9 r# u- H' ~
#include <BIOS.H></FONT></P>& f* W2 g8 O6 y8 U
<P><FONT color=#0000ff>int main(void) ; ?- @+ Y6 w) B1 Z% L
{
: ~/ k6 s# @+ _" c% S#define STATUS 2 /* printer status command */ " G; Y" n2 z5 G
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>: Z" t; w8 B0 b
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>9 w O# k4 r W
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
- j! j# ^# g! g; F! g* l- igetch();
1 g. Y2 C" a, {# jstatus = biosprint(STATUS, abyte, PORTNUM); . v+ |1 E1 F7 Q. d- Q
if (status & 0x01) ! N6 c# R x9 m: M! G
printf("Device time out.\n");
' u+ M z# C3 D9 W4 k4 rif (status & 0x08) 8 P8 q! W! v7 |/ Z! \; I
printf("I/O error.\n"); </FONT></P>
3 l5 D3 b) n& a) K. w. c, p<P><FONT color=#0000ff>if (status & 0x10) 2 v. n* \5 q6 E1 j. p' ^
printf("Selected.\n");
( ?: \2 S, B; [, U e' [if (status & 0x20)
/ ?5 ?! C7 e. \- Iprintf("Out of paper.\n"); </FONT></P>
4 R7 D( ], d8 c9 \2 n5 p<P><FONT color=#0000ff>if (status & 0x40) 5 `7 @1 L U4 S' c$ B
printf("Acknowledge.\n");
( ~* j: e% E/ V( G0 s, Aif (status & 0x80)
0 C$ u/ {% I8 G' T/ Gprintf("Not busy.\n"); </FONT></P>; U" Z& U# ~; Q; I
<P><FONT color=#0000ff>return 0;
* L4 b# Z- F7 J}
% c( k8 \8 g7 f; `4 c- U</FONT>0 L/ J N: R7 a5 S
; x) F6 D1 S0 c" w9 `' @. s0 ~</P>1 I1 ^$ g( Q( l8 P
<P><FONT color=#ff0000>函数名: biostime </FONT>5 [' F3 Z6 o; {6 `
功 能: 读取或设置BIOS时间 / n8 P" ^. [. \) s0 @* \: ?
用 法: long biostime(int cmd, long newtime); 0 E9 _# F; o8 I
程序例: </P>
* z$ a% Z* O3 ]6 Q' T1 N" k- U<P><FONT color=#0000ff>#include <STDIO.H>* |0 ^9 Z! K+ D
#include <BIOS.H>2 r8 p9 @1 [) P6 ^: N
#include <TIME.H>
# O5 P: o: {( a3 i. ]' H#include <CONIO.H></FONT></P>
$ ^& T' w- t# e; o! n M<P><FONT color=#0000ff>int main(void)
I( O+ Z$ e, I9 C& O& u{ 8 p9 O8 v; q4 T9 e- k: g7 I2 W
long bios_time; </FONT></P>
. K7 C5 L0 r$ g$ J+ ?* f4 W<P><FONT color=#0000ff>clrscr(); 9 |$ w" @/ C9 Z1 b
cprintf("The number of clock ticks since midnight is:\r\n"); ; x4 C/ o0 a6 j' Z6 F5 Y
cprintf("The number of seconds since midnight is:\r\n"); 5 L0 R8 y, b7 m
cprintf("The number of minutes since midnight is:\r\n"); 3 F# d- F$ l, Q' H- _
cprintf("The number of hours since midnight is:\r\n");
/ r! j. t+ f8 G3 r+ T% Rcprintf("\r\nPress any key to quit:");
2 ^' Y, K" O. x. {' }- s; pwhile(!kbhit()) 9 o# t' ` b+ T V- \( v x# A
{
- N3 W; `2 M: M0 sbios_time = biostime(0, 0L); </FONT></P>$ w" Q7 Z& W: Y, { z
<P><FONT color=#0000ff>gotoxy(50, 1); : g/ ~* E$ x, R/ O2 W4 A7 g
cprintf("%lu", bios_time); </FONT></P>
5 A9 G ~, H; i+ K<P><FONT color=#0000ff>gotoxy(50, 2); 4 I! S5 b# T. ^ d! J
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
! Z ^4 y5 u# O* R3 E<P><FONT color=#0000ff>gotoxy(50, 3);
, `1 f5 n% ?% ^' }* E5 |cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>) g. a) l7 c5 Q! R& `
<P><FONT color=#0000ff>gotoxy(50, 4); + m/ b7 q" P& }/ x* N/ D
cprintf("%.4f", bios_time / CLK_TCK / 3600); + V. Y' K5 m7 F; A3 M- _
} 5 | s( w3 e% A. O4 T( D7 k
return 0;
, X1 S1 ]" n% j$ ^} " F: ~+ [- f- u- a' V
</FONT>
- m$ \; l: O0 y6 l0 }
! S- a2 O3 l/ ]2 }* v</P>
- E8 ^7 L$ w7 G8 z: R9 r5 G2 P1 v<P><FONT color=#ff0000>函数名: brk </FONT>7 ^% |4 q; l( \4 ?
功 能: 改变数据段空间分配 9 q0 a ]- T2 {0 i B
用 法: int brk(void *endds); ! d- \9 _5 U3 Z! h% P$ n
程序例: </P>
: a3 @6 V# r) d, n4 L3 X<P><FONT color=#0000ff>#include <STDIO.H>
0 A3 v; @/ M5 Q% g$ t( }' Z#include <ALLOC.H></FONT></P>" K' U7 O- |( i4 _4 `7 s
<P><FONT color=#0000ff>int main(void) 0 e, r% [9 j3 ?
{
6 ~& C/ O: N& I `8 achar *ptr; </FONT></P>
" u1 }3 Q8 x' E% X) y<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); 0 F$ m3 D* |0 S) P# G
ptr = malloc(1); 7 s3 q2 b; u* `0 F
printf("Before brk() call: %lu bytes free\n", coreleft()); " t$ }- l1 X$ T+ R% |8 Y
brk(ptr+1000); + _7 B% v+ A! ?' r- e8 r
printf(" After brk() call: %lu bytes free\n", coreleft()); 8 ^8 V% [* f) ~6 n% h
return 0; ! z- k: h$ P% I1 W
}
m3 c" _! A% D6 @1 N
1 t* M0 B1 N& b3 V% Z1 Z</FONT>* d0 h8 D( D: u* l$ `! |
</P>
% M8 E% x: V: x! H& T! U0 a<P><FONT color=#ff0000>函数名: bsearch </FONT>
' n2 X5 ]: g6 [) I8 n功 能: 二分法搜索
0 X4 Z, N. j0 y用 法: void *bsearch(const void *key, const void *base, size_t *nelem, 8 x8 W1 `4 i0 x w- V+ I
size_t width, int(*fcmp)(const void *, const *));
/ g5 o0 n5 w& ]3 G. G, l程序例: </P>
. v! l; ^) f& D' S4 x<P><FONT color=#0000ff>#include <STDLIB.H>
6 ?) A" R. a" j4 d2 L#include <STDIO.H></FONT></P>4 ?! o' S) W) m4 k! w
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
% o% g* o0 ]: `% s6 X. H<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>' s5 ?9 v* C' d4 \+ n" l
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) / l" q# D( f# l% A; y
{
2 D" r/ t$ Q" o; r% t: k5 greturn(*p1 - *p2);
0 r& E1 n; w3 m3 h. s9 o' e} </FONT></P>
! q1 I. q5 S/ x9 J# A1 H1 l& n& W<P><FONT color=#0000ff>int lookup(int key) $ X4 p% I7 W/ I0 y. t d$ k6 y
{ # K! y) M& w& e% f6 Z) |, v8 M- P
int *itemptr; </FONT></P>3 x6 [, Y T- ]( W' ]: b8 A' o
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
/ {: X8 W# k' @is needed to avoid a type mismatch error at + o1 A/ B/ V* \: a; b: F% ?
compile time */
6 w9 A" y' e2 U. O: F' {itemptr = bsearch (&key, numarray, NELEMS(numarray), $ _/ j! L$ B8 Y. p, c
sizeof(int), (int(*)(const void *,const void *))numeric); - n1 g" E! e9 |6 G9 ^$ _
return (itemptr != NULL); & m' b! v* j6 v9 e6 L# g
} </FONT></P>
9 _ |3 B3 ]+ |* V! E( k<P><FONT color=#0000ff>int main(void) ; s3 O+ j% f0 \" P* N6 `) `
{
1 v7 H* ~0 Z( |* o$ ?0 cif (lookup(512))
0 }* B/ Z; z; Y) S2 qprintf("512 is in the table.\n");
9 l4 x/ Q! s) ]( l% Selse
5 G* [' y6 M0 u6 e) f! U Xprintf("512 isn't in the table.\n"); </FONT></P>% E1 X5 K4 R: {6 V; H
<P><FONT color=#0000ff>return 0; 8 s( B1 @* k8 T# {0 @
} </FONT></P> |
zan
|