- 在线时间
- 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>& z+ K! e- B; P) x2 t4 {
< ><FONT color=#ff0000>函数名: bar </FONT>) d4 }: u% O: b0 z" }) @2 i1 ~+ N
功 能: 画一个二维条形图
f$ I" y+ Q9 r5 X1 y( ]$ U/ [/ ?' D用 法: void far bar(int left, int top, int right, int bottom); * v6 J! Y+ f6 W1 j; C! R6 Q
程序例: </P>
2 K ^ b" t5 _) g; \< ><FONT color=#0000ff>#include <GRAPHICS.H>" z" X; ]8 g& q- O
#include <STDLIB.H>, O; b5 f1 K p( h0 G# R, [
#include <STDIO.H>4 o- U0 F# u) ?& X; Q
#include <CONIO.H></FONT></P>
$ t% F6 h+ V6 `5 |. i/ ?$ Y. P< ><FONT color=#0000ff>int main(void) + Y, E7 p1 s' t/ Q' g8 `
{
3 I$ y2 h; w1 }/* request auto detection */
+ d3 y. ~ a* X$ Q. j6 h: f, [2 [int gdriver = DETECT, gmode, errorcode; ( V* Z1 U" U2 f* m0 k
int midx, midy, i; </FONT></P>7 }% ^0 s5 c3 D/ ~
< ><FONT color=#0000ff>/* initialize graphics and local variables */
4 [3 J! b0 G/ X7 L: @initgraph(&gdriver, &gmode, ""); </FONT></P># W2 c# R- B( Y% Q2 J8 H
< ><FONT color=#0000ff>/* read result of initialization */
F- E1 `5 ]5 z {# H0 J3 Ferrorcode = graphresult();
3 ?" q, Y+ Y% G |* Y* M; eif (errorcode != grOk) /* an error occurred */
& V; _ O. N; ]3 j- Z0 `* ?{
2 v. K) o2 r; p7 T Y( Pprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # D. r7 @" x( S5 B: }
printf(" ress any key to halt:");
+ O$ j( G9 n4 [6 ?! u) tgetch(); # {' E7 x+ B8 n* J" t' v7 k
exit(1); /* terminate with an error code */
# r% H/ I+ V$ @6 x8 S6 f: j* H! z} </FONT></P>" ?/ b' D8 s4 e+ P& q
< ><FONT color=#0000ff>midx = getmaxx() / 2;
( s Z% X2 ~0 }/ e! X% Nmidy = getmaxy() / 2; </FONT></P>1 k4 z7 W* r* |! ~' v3 F' @
< ><FONT color=#0000ff>/* loop through the fill patterns */ 7 d8 [6 ~, K( Q* G
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { ) I8 C3 w( K/ J' m/ h
/* set the fill style */
9 {0 A E9 e! q' y: u0 Vsetfillstyle(i, getmaxcolor()); </FONT></P>3 S6 G$ X6 Q+ {8 z6 c; I4 O% i
< ><FONT color=#0000ff>/* draw the bar */ $ e# N" p3 P5 s% v
bar(midx-50, midy-50, midx+50,
. \* H9 |8 k' M0 ^- V5 V1 h. ?! kmidy+50); </FONT></P>
" `( Y' k$ V1 _; }1 l2 j* U- ]* V6 z< ><FONT color=#0000ff>getch(); # T/ a" e+ Y& M c u: `
} </FONT></P>, ^' E, ^' B8 y8 F) e% r# q
< ><FONT color=#0000ff>/* clean up */
' C' W) |8 P, v3 H" k& S. @closegraph();
4 }4 k( R4 d2 W. t: `, S) h4 sreturn 0; % \9 m- l6 t" t# h, y; \
} </FONT># p6 Y# t, }9 ?7 f1 c3 A0 e1 j) x1 D/ Z
' Z( o* R/ X; Q r6 g5 P; i* ?* D- Z+ a- h9 u( c
</P>
# B8 y9 }6 F; m8 j< ><FONT color=#ff0000>函数名: bar3d </FONT>2 C+ n5 w u5 A* P$ |
功 能: 画一个三维条形图
' }7 M! D. ^: h) h! G用 法: void far bar3d(int left, int top, int right, int bottom, 1 x, t' H8 c9 h) `* ~
int depth, int topflag);
/ u6 H$ H( S) N I0 N5 A程序例: </P>/ f/ _4 j& L- @8 }
< ><FONT color=#0000ff>#include <GRAPHICS.H>
l. h1 G' a. ?" n6 \#include <STDLIB.H>! s$ t6 ~& k% I6 ?- c5 _+ h; s
#include <STDIO.H>( X% e! e$ M- W. l- k
#include <CONIO.H></FONT></P>9 Y' U( h0 U8 T! N& w) [
< ><FONT color=#0000ff>int main(void)
! d& L# e: ?/ x5 s& {) F{ 4 `# r& K" ^% G; V! u
/* request auto detection */
( c* h( u- U" s4 n( D1 Tint gdriver = DETECT, gmode, errorcode;
8 z! k8 u- e; cint midx, midy, i; </FONT></P>$ i6 e: M0 S- Q7 x8 i: ~0 A _
< ><FONT color=#0000ff>/* initialize graphics, local variables */ ; @7 j( @; r$ r- b6 K4 M! }
initgraph(&gdriver, &gmode, ""); </FONT></P>3 D" @# g% u7 o0 ?0 [& K a
< ><FONT color=#0000ff>/* read result of initialization */
, A, W8 q7 s) Z2 a6 @errorcode = graphresult();
6 ~6 n$ F# N3 R/ ~# n( ]if (errorcode != grOk) /* an error occurred */ . v" S# g/ F5 z) r1 V
{ - b: w6 W ~# x4 J
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 a4 [9 F/ G" @) `% D8 ~! R
printf(" ress any key to halt:"); $ W, p4 S- S" z; ^6 u% V0 ?
getch();
. M3 H. ]' ]5 Dexit(1); /* terminate with error code */
) b( x. U% E7 q/ H} </FONT></P>2 A- K# F& P: E( o- C# q, H
< ><FONT color=#0000ff>midx = getmaxx() / 2;
; F, _! [7 B: @/ Gmidy = getmaxy() / 2; </FONT></P>
}, Q" o" _" I5 o! K+ i) X< ><FONT color=#0000ff>/* loop through the fill patterns */ + }5 _- F3 Y; Q" U- A/ z! z
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ) C9 `2 [% V4 Y/ ^" r$ S( U
/* set the fill style */
/ F _5 s& C/ ~; \: L1 fsetfillstyle(i, getmaxcolor()); </FONT></P>9 U) i, t; l" y) [' S# x- [+ ^
< ><FONT color=#0000ff>/* draw the 3-d bar */ + d- e% \ U9 p5 E6 j
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
S1 G E" I& P- m) M< ><FONT color=#0000ff>getch();
3 E. A n# i# m. t$ ?$ j} </FONT></P>
$ F" O" l& W! @& b6 k; t< ><FONT color=#0000ff>/* clean up */ ! x2 ^: f3 Z" b0 q: H# S
closegraph(); 1 y8 n o+ ` Q8 q. x1 F: u1 u
return 0;
% f k/ F( P4 s} 7 I% ^; Z! N+ v- ^1 o
</FONT>* J0 Y; ]3 N' K; Z v; B a$ E( |
. J# y, d; G+ N2 b+ r; m" h7 o</P>& B# a% T; u/ T7 U5 V ]
< ><FONT color=#ff0000>函数名: bdos </FONT>
- ^& z' F T. e2 R5 i* d功 能: DOS系统调用
# Y8 Q% d9 H( b7 i' [7 t. K0 p用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); % R( s" b" y% O
程序例: </P># I" C) F0 @( E. {
< ><FONT color=#0000ff>#include <STDIO.H>* R5 J) C. d7 Z" u/ u9 T' K+ z; g; e
#include <DOS.H></FONT></P>
) \. w: ~$ U* v! Q: o+ l< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ " \' R7 W' G$ _
char current_drive(void) M2 p" f( g2 _( P: P9 ^( i8 T" d
{ / M) v! T) D- I3 U
char curdrive; </FONT></P>
7 o% Y/ w' R9 I5 l, S i' D< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
( h: k( e6 z- m& }curdrive = bdos(0x19, 0, 0);
0 B0 s6 T7 m3 S1 jreturn('A' + curdrive); 0 n& _1 v" `& {0 @2 [
} </FONT></P>
2 g# o ^$ c- k< ><FONT color=#0000ff>int main(void)
7 D- g; `. J8 _! Q8 U{ ( z4 ~0 F3 X. ^
printf("The current drive is %c:\n", current_drive());
5 C* z3 b: R( @. `return 0; 2 X- Q) @8 p5 |* z$ ^9 ~
}
4 L6 }% L$ A6 j" L, L2 K8 k K, V B- _+ u! D
</FONT>
9 s/ i! n. k* ~</P>" R( l3 B, F6 A+ i4 l& W, H7 ?
< ><FONT color=#ff0000>函数名: bdosptr </FONT>. [( _( |0 n- V2 a6 V
功 能: DOS系统调用 x- W' U# x8 r3 W! r( a
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
/ l0 P- |9 r: i+ F程序例: </P>5 Q8 ~9 v1 {. O
< ><FONT color=#0000ff>#include <STRING.H>; c1 p8 o. G" ]7 J# Z1 P! h, C$ R0 f
#include <STDIO.H>
$ }3 L5 s1 P" v; u- G# e#include <DIR.H>1 t6 ~- k) f. ~* l, ]- G
#include <DOS.H>
4 P- [& e- U7 U6 N' N#include <ERRNO.H>$ Q7 F0 `, g; @. P
#include <STDLIB.H></FONT></P>: C3 W+ Y! ]* t( h5 B6 q
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
3 z" K2 E; Q# H. k, a" @8 }$ x<P><FONT color=#0000ff>int main(void) 9 j. D4 Q" s( b* e% |5 H
{ : e% g$ E$ s5 O- _' V
char buffer[BUFLEN];
" N" O! _+ ~1 v% `( y: ^int test; </FONT></P>
# k4 Y- D- W3 V) u0 ?<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 0 G& X0 ]! h2 i( f9 r$ ]
gets(buffer); </FONT></P>6 J/ }% Z/ _2 p0 Z4 g
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); Q; l) O. b9 q2 x! c9 G" U
if(test)
) T. ~' x/ e5 d a2 _" s* I& R{ . M) a; Y' d* u+ {# k
printf("DOS error message: %d\n", errno); r* o. p6 ^& }: n1 {5 z6 w
/* See errno.h for error listings */ # y3 B% ^& H) b
exit (1);
+ S: V+ _# [( j0 L7 ^} </FONT></P>
; I, C$ L; N' ~, C% f2 c& p<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
3 P9 R. D2 Z9 ~& I/ Sprintf("The current directory is: %s\n", buffer); </FONT></P>
8 a4 }3 [! R) w( d6 E4 m3 o<P><FONT color=#0000ff>return 0; & h( p" T, f1 O# F4 z U
} % I% l W& U8 l( s3 z
</FONT>
8 a1 P# ]2 f$ A/ b: a: E1 D' [: ?
) n* {/ B( W+ ] M1 H</P>
/ j7 O5 X0 O; D& O<P><FONT color=#ff0000>函数名: bioscom </FONT>
" K$ A7 t- Q0 l/ a9 G功 能: 串行I/O通信 ( s. E! x2 z# d7 l
用 法: int bioscom(int cmd, char abyte, int port); # k3 L4 X8 { |" Z7 ^
程序例: </P>5 A3 Q1 e3 _8 m& u# |7 D1 {* p
<P><FONT color=#0000ff>#include <BIOS.H>
- T) P( ^& Y( C6 T* l& I. C; w% G#include <CONIO.H></FONT></P>
3 ~: {$ s- Q/ H1 W, u<P><FONT color=#0000ff>#define COM1 0 4 f/ Z0 x8 D+ A6 s0 a! J( l$ z" ?: [
#define DATA_READY 0x100
' r6 J) v& u8 O. O#define TRUE 1 0 H; w( G# A4 l& e, ], H
#define FALSE 0 </FONT></P>
6 N3 Z* U8 L# v" T( d<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>0 F1 F8 h/ @% s2 ?
<P><FONT color=#0000ff>int main(void)
; i, g2 ~ ?) p( e/ b{
, X& q7 v) r7 {- b, K8 P/ eint in, out, status, DONE = FALSE; </FONT></P>: a s. b2 a+ K I! Z# |( y" m
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
0 k! r2 K( D8 g3 t7 t2 R( }cprintf("... BIOSCOM [ESC] to exit ...\n");
! T- T9 }) ?; y& O7 Pwhile (!DONE)
" J6 E. c6 X5 ?" V{
" F; q3 w+ G- x& `status = bioscom(3, 0, COM1);
6 v: m1 e. t- ?1 N: s1 lif (status & DATA_READY)
, U7 z7 I$ e4 s6 a$ Dif ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
3 O/ \8 C% H7 vputch(out); ' B' S$ t; S8 Z% p& X: d; V0 Y
if (kbhit())
; ^$ \- c5 x4 B9 D/ {: P' Q{
) D& w+ j0 N% Q- M! y T: N7 S" Uif ((in = getch()) == '\x1B') 7 S7 D0 @! A* v5 d( w
DONE = TRUE;
3 y8 w( X4 ?: T: j' y: ybioscom(1, in, COM1); $ e7 Z. `" S/ b8 ?( F# C: f' n- k
} . ?0 G# |: L6 o- E1 W* D
} ' O/ r3 k1 x4 W
return 0; / j$ X3 ^7 `5 x" B
} </FONT>
+ a4 O! D, @9 @* m. X! b2 K% V$ C2 @2 L1 q3 Z
9 |8 U5 S6 x+ k9 W, D& k
</P>
$ a7 |& @9 }; ^) ~<P><FONT color=#ff0000>函数名: biosdisk </FONT>2 Y8 j- Q& j# ~5 F# i/ x; x3 m" S
功 能: 软硬盘I/O ) ]8 L; K2 y: q9 e: }
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
6 X) s) Q) B& oint nsects, void *buffer); 6 x. i1 _$ t( s; Y$ y" P( F: G
程序例: </P>2 s$ `, `* R3 N1 g4 E
<P><FONT color=#0000ff>#include <BIOS.H>. k9 u; x8 t6 T s8 J) V
#include <STDIO.H></FONT></P>1 l, v5 X$ ]: \; s
<P><FONT color=#0000ff>int main(void)
4 `+ X* h2 x9 ]{
5 n( p* D6 }8 y8 R0 T# o d9 Tint result;
8 R0 j1 j5 ?: h$ C/ F8 t( schar buffer[512]; </FONT></P>
Y$ Q- y$ y! A' V4 w% W; w<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
7 ~2 M% Z2 U; e5 @" F( M( Aresult = biosdisk(4,0,0,0,0,1,buffer); 9 ~ A- H! _4 V B
result &= 0x02;
& L: c8 l1 }3 b! [( N(result) ? (printf("Drive A: Ready\n")) : # M" A2 V' @. a
(printf("Drive A: Not Ready\n")); </FONT></P>
9 O0 h6 F& l( k, M0 x3 A' x% i/ ]<P><FONT color=#0000ff>return 0; , K: n3 }2 O# J1 R4 Y
}
2 F' l4 w+ n8 S- a0 a</FONT>
+ E$ I6 A2 |1 C" i. c( H! \8 o. {9 n( c& m
</P># F& u A% ~5 O D: s2 r5 W; A
<P><FONT color=#ff0000>函数名: biosequip </FONT>8 g$ K4 p: l! l8 K
功 能: 检查设备
& d H J' B; W- s( T7 V用 法: int biosequip(void);
3 k+ S* Z4 U7 ^程序例: </P>2 A. D. [/ V% o6 Q+ }5 b2 r- P& z K
<P><FONT color=#0000ff>#include <BIOS.H>
5 v9 ~" D K- |#include <STDIO.H></FONT></P>7 l% n2 ~+ q2 @
<P><FONT color=#0000ff>int main(void)
0 K: W! G+ f% z; \( P5 M) D' H{ $ h2 o3 } N8 d% e" w
int result;
7 c$ A# k8 u5 i3 |3 h, U: ?0 Schar buffer[512]; </FONT></P>& Y5 R$ T7 w+ [2 H
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); , t6 j( I/ w) @
result = biosdisk(4,0,0,0,0,1,buffer);
. n# n5 j1 v5 U' L/ ^result &= 0x02; 8 |1 u3 X5 [: t a; j: } x
(result) ? (printf("Drive A: Ready\n")) :
+ m; e. _2 e; M0 |2 \( ?. I(printf("Drive A: Not Ready\n")); </FONT></P>
( _1 g( {- J( }, R$ r" L7 b7 [<P><FONT color=#0000ff>return 0; 3 r6 H* ~* z- P- J
} . E5 m" u8 Z) v+ G
</FONT>- f4 a0 x* j) O" j! i
+ S, M) x( ^# D) f* I
</P>
2 q. `8 B* h) ]+ B' l* W7 ^. r& u<P><FONT color=#ff0000>函数名: bioskey </FONT>9 H1 x; ^5 b- w8 }- V4 r
功 能: 直接使用BIOS服务的键盘接口
* p& _. i4 S6 q( I9 Q9 y用 法: int bioskey(int cmd);
# h7 w- p0 C8 m2 O& k* n程序例: </P>3 H5 k9 s: G! w s; o
<P><FONT color=#0000ff>#include <STDIO.H>/ ~1 N% I; k2 |9 m& m5 C W
#include <BIOS.H>4 l( d5 l' T* z& b- h
#include <CTYPE.H></FONT></P>8 q8 o& b/ W C ?/ X% l( E9 {
<P><FONT color=#0000ff>#define RIGHT 0x01
+ a. j( F0 x8 S2 _ X4 s4 X4 ?7 m#define LEFT 0x02 3 P. l! i: k2 p1 @9 k& \& ^1 x% _& g
#define CTRL 0x04 ( ~: Q ]2 T/ U& ?0 J
#define ALT 0x08 </FONT></P>
% e% S! T- e# G. k<P><FONT color=#0000ff>int main(void) 2 |! e6 F) ]) N+ X+ R, M3 t
{ 0 @$ y: f: b9 ^
int key, modifiers; </FONT></P>
3 A, |7 Y* K7 I: k9 k) o<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ + X2 ?" m" d) i4 d
while (bioskey(1) == 0); </FONT></P>
, p. Q* s7 E) }2 n<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ : r& z3 M0 Y+ P2 ^: D- C% P% o: y
key = bioskey(0); </FONT></P>
! ^( g( n+ `. ~<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
; q) g5 @& |% omodifiers = bioskey(2); - c% H2 O9 C; Z5 \1 r
if (modifiers) 8 \/ r0 B5 E& I$ K8 V
{
/ {% Q8 y$ e; u% a( d$ }* G; A6 Mprintf("[");
+ L2 G( n9 s. H6 ?! E* A4 \3 gif (modifiers & RIGHT) printf("RIGHT"); - F g& l2 t6 x0 s
if (modifiers & LEFT) printf("LEFT");
& _3 ~$ a, j7 {/ N6 B! @ mif (modifiers & CTRL) printf("CTRL");
- V J3 j9 R8 b. O+ H6 X2 V1 dif (modifiers & ALT) printf("ALT"); , ^" d& _/ ^! P$ [
printf("]");
3 s' `) L( m1 Z: N' S& t, M}
; W$ u9 |( ~: H' f y9 H+ l% X8 ]/* print out the character read */
: h y- Q% f$ ?* Y$ Bif (isalnum(key & 0xFF))
2 Y& z' M$ ~, Aprintf("'%c'\n", key); $ ]$ Z" S* I# x! |( w: d: B
else
! E. |6 E& l9 c% R; h4 Gprintf("%#02x\n", key);
% e7 D k, i5 ~0 d# F0 _: Qreturn 0;
# A: |) F$ ?) U4 s" `8 P; W7 W} / a; q/ i+ ~- p6 G
/ ?9 A3 d, |$ B
</FONT></P>
3 r# n8 k3 M# f% n1 H<P><FONT color=#ff0000>函数名: biosmemory </FONT>
- P6 a' n' e5 W' B2 b& ?# C功 能: 返回存储块大小
( C9 i) I" j* t* s c) e. n- {用 法:int biosmemory(void);
$ y5 L, l `$ D7 c3 L程序例: </P>) G: v# T( r' a# J
<P><FONT color=#0000ff>#include <STDIO.H>4 T( Z/ J+ U# B6 Z) C% k
#include <BIOS.H></FONT></P>
/ l6 c$ w" Y( S4 P, R<P><FONT color=#0000ff>int main(void)
! H0 ~, a' z& {! V{ ; v `$ R0 |/ e4 H0 g5 g
int memory_size; </FONT></P>
% A( \1 |* k$ P* c4 N<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ ) m- x4 u+ [0 h8 p1 B: p, r, N$ [
printf("RAM size = %dK\n",memory_size);
3 p+ y. D) Z- K1 P" `return 0;
1 E9 A x) c9 L; Q}
6 r) F3 M$ T2 {9 f# u- b" r</FONT>: Q4 E5 ?; l2 p6 b+ c* l( y. S
) o# p+ y& g& r, U1 i
</P>
* Q# w3 H9 V# H5 y+ k<P><FONT color=#ff0000>函数名: biosprint </FONT> Y3 w% k `4 T9 s& O% n$ C# \
功 能: 直接使用BIOS服务的打印机I/O , F/ `" ^) {9 A2 Q6 ~
用 法: int biosprint(int cmd, int byte, int port); ) O5 U$ c" _2 ?% l. q/ |0 }
程序例: </P>7 [2 H0 b" z- h) c; k& k/ f4 Y- N* J
<P><FONT color=#0000ff>#include <STDIO.H>
; X0 J3 g* c s7 o5 e$ ?' x! h#include <CONIO.H>1 w' r# @! s1 S6 @8 d5 @
#include <BIOS.H></FONT></P>
! ?0 _5 X% J( a& D6 G<P><FONT color=#0000ff>int main(void) / v$ m3 I5 C& Y! r6 L9 y
{
. Z' b2 G) P* F+ a+ k& z6 u e#define STATUS 2 /* printer status command */
3 @& K$ @2 U# {: H! Q#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>' ~8 W; ]5 h; h0 m8 Z
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>2 H9 Z3 B, m/ O* v3 d1 c- P
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
! R2 r$ h- ~" C1 r$ n' x3 Ngetch(); * ]' R7 Y# h$ M: m* B
status = biosprint(STATUS, abyte, PORTNUM); / H3 J x$ Z& _' n( k5 o" j
if (status & 0x01) ' w0 `& m P$ I- D; c
printf("Device time out.\n"); : X8 u, y; x) I+ c
if (status & 0x08)
8 z6 g4 ?7 Z- T' S7 aprintf("I/O error.\n"); </FONT></P>
( X% h+ O e" h0 c5 [<P><FONT color=#0000ff>if (status & 0x10)
! G* v" G) g8 b T0 Oprintf("Selected.\n"); 9 G/ R X$ `( r& {/ q0 [* P
if (status & 0x20)
( u2 }9 W- `2 O3 I) Z! oprintf("Out of paper.\n"); </FONT></P>3 e$ m* V5 P" D0 H
<P><FONT color=#0000ff>if (status & 0x40) ' R# r2 U+ d/ u) k6 g( c h
printf("Acknowledge.\n"); 3 |/ M* P' @! X: k, R: w# ~- L" b
if (status & 0x80) 7 q4 S, Z' I, I( C$ y9 ]4 Q
printf("Not busy.\n"); </FONT></P>0 _, I6 s4 K" Y) g! Z
<P><FONT color=#0000ff>return 0;
1 n3 Z" |" O4 X- e8 T. h} , _, R! ]6 b! S7 r5 m
</FONT>' j# I8 c% R$ l+ q1 }6 X* F. L
2 P7 j/ H0 O0 \, ?</P>
4 ?& Y% \& j7 r1 p# P% u( R4 o<P><FONT color=#ff0000>函数名: biostime </FONT>+ L, Q) O6 M9 ?) R2 k% J
功 能: 读取或设置BIOS时间
` S W* H/ S6 v- v用 法: long biostime(int cmd, long newtime); 9 B" S" \7 V# D& D
程序例: </P>
. l, O3 e2 N; }: c<P><FONT color=#0000ff>#include <STDIO.H>9 G0 `2 x) N8 U# [( q
#include <BIOS.H>8 v+ F0 d, q: N* {& ^) [
#include <TIME.H>! W; c9 O @) K
#include <CONIO.H></FONT></P>* `0 f6 F1 g* x; J& E7 M
<P><FONT color=#0000ff>int main(void) % s W$ C1 x& c2 G2 |, T
{ 7 ^# ]) H" D0 I3 f6 Y' G
long bios_time; </FONT></P>8 n T& \) `$ {1 C+ Y
<P><FONT color=#0000ff>clrscr(); * Z; g& h1 @" M* z; p7 N3 n: T4 z4 G
cprintf("The number of clock ticks since midnight is:\r\n"); 9 r+ p- u" F `2 n% y2 B. }
cprintf("The number of seconds since midnight is:\r\n"); 0 B0 ]) k5 y5 E, v2 q! ~) W/ l1 G+ n
cprintf("The number of minutes since midnight is:\r\n"); ' Q/ q, J' { U- ]
cprintf("The number of hours since midnight is:\r\n"); D3 j! f& v5 p9 A- O# U
cprintf("\r\nPress any key to quit:");
& y1 T8 x8 u+ K9 }! t" Z- S- R* Vwhile(!kbhit())
8 i2 W/ I& V/ H: S{
4 a; T+ f& g7 c1 C7 T7 ?5 y; obios_time = biostime(0, 0L); </FONT></P>
: q3 _5 J' o3 n. N<P><FONT color=#0000ff>gotoxy(50, 1);
- I% N) L5 _; ccprintf("%lu", bios_time); </FONT></P>
0 U4 y0 Z4 f0 r% p7 N<P><FONT color=#0000ff>gotoxy(50, 2);
$ N% n/ p1 I% Z) icprintf("%.4f", bios_time / CLK_TCK); </FONT></P>9 I: u( u" u% b' ?
<P><FONT color=#0000ff>gotoxy(50, 3); 1 U" a, K+ F) F$ L! Z0 r; y
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>; X; P" q7 @; F3 c2 F# Z
<P><FONT color=#0000ff>gotoxy(50, 4); 5 H) g" B4 i" Y" z% j# z6 ?9 U
cprintf("%.4f", bios_time / CLK_TCK / 3600); & r' h* X \' u v! a2 J8 Y, w
}
4 v) i% g4 l0 kreturn 0;
& D( c( z' |" Y3 ?# @} 7 ]% i. A4 b: b; P! y$ d+ d0 M0 I7 T
</FONT>
w b% q \' V
. }: m4 b! w" X</P>; D7 W+ X( L2 C6 s: t
<P><FONT color=#ff0000>函数名: brk </FONT>
8 b; v0 V" H0 x( ]& X* M% b/ l功 能: 改变数据段空间分配
: E7 E" s+ z# M1 k0 @% ?- w" ?用 法: int brk(void *endds); 8 v }: ~- H0 R- B( `" \
程序例: </P>
`4 X# s6 h3 h b<P><FONT color=#0000ff>#include <STDIO.H>
% g- A3 F8 q6 p7 [#include <ALLOC.H></FONT></P>' x( E5 A8 P0 Q/ [0 O$ R$ p0 W
<P><FONT color=#0000ff>int main(void)
! x U2 K8 p1 z$ D2 R2 L' d{ . @7 ]1 y$ k6 Y7 z
char *ptr; </FONT></P>
+ f; q7 l% `0 g: s& J& g$ S* O% X<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); ! \' H) K! U! Z7 J8 n" _1 G( J
ptr = malloc(1);
6 J ^+ A3 f: F% lprintf("Before brk() call: %lu bytes free\n", coreleft()); % v. w4 d. N, d( N! b
brk(ptr+1000); $ W1 N8 n# l' n; H
printf(" After brk() call: %lu bytes free\n", coreleft()); ' i+ I. t3 _ L9 l0 S' g9 p) P
return 0; 3 H2 v' J( Q. [8 G( j
}
* I0 l4 }$ O" d; E1 c( B
$ c1 t, ^ j6 L; ]+ S& t</FONT>5 f% j; a; n x# k& T8 P) u3 } i
</P>4 p9 A- D$ i" h# ]% a+ l
<P><FONT color=#ff0000>函数名: bsearch </FONT>
! D6 {- L' f$ O* h Z9 D: m功 能: 二分法搜索 ^9 m9 ?9 H2 s4 ?0 m
用 法: void *bsearch(const void *key, const void *base, size_t *nelem, ' D6 p1 L6 o; E
size_t width, int(*fcmp)(const void *, const *));
$ C+ ?9 G3 v1 U$ i- v" o程序例: </P>
. v$ q& Y0 y; j4 `2 z<P><FONT color=#0000ff>#include <STDLIB.H>
- n6 F7 h" L# K0 B5 T- j9 X#include <STDIO.H></FONT></P>
; [' }& O/ _8 T2 }1 F<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>/ J5 S0 Y$ t) T& J) \2 \, s
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>2 E% v# M, l4 ^2 I7 c
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 4 Q* t" l) P0 P
{
( V/ p. D# c1 Freturn(*p1 - *p2); 7 X( ?! E D5 V; Q* C8 q
} </FONT></P>9 x4 `+ q; ]" i
<P><FONT color=#0000ff>int lookup(int key)
; e% e0 u6 `1 N8 v7 u( f{ $ o% g0 p$ a! a$ L0 t5 _/ r
int *itemptr; </FONT></P>
. |# c5 B: r1 g/ L4 z3 z1 |<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) / P; B3 g" } }. p. a5 @! j
is needed to avoid a type mismatch error at
/ A& o( I+ R6 I7 ~1 \compile time */ , t$ d- H0 ]5 F+ b: Q7 i- h& {
itemptr = bsearch (&key, numarray, NELEMS(numarray),
* _- I0 R/ [$ Ysizeof(int), (int(*)(const void *,const void *))numeric); 7 g" w. r+ Y) X- A
return (itemptr != NULL);
# P0 F2 i, ], g7 i* s' N# ^/ A} </FONT></P>( T5 E, z7 Z9 ?2 @0 ?
<P><FONT color=#0000ff>int main(void)
; Q. s, K5 W1 c* Z{
/ @. }" Z. @% U5 w; oif (lookup(512)) , x5 l& x0 @ E5 D& H
printf("512 is in the table.\n");
& r3 c. Y+ q9 ^7 t, v- B% Helse 9 k! Q3 l0 k( w* b8 s
printf("512 isn't in the table.\n"); </FONT></P>
8 U1 n: U4 N6 C9 }2 J+ D' d P* C; q1 K<P><FONT color=#0000ff>return 0;
' }# W: g( y t+ p1 o6 ?} </FONT></P> |
zan
|