- 在线时间
- 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>4 v0 ^3 W% u5 ]" V
< ><FONT color=#ff0000>函数名: bar </FONT>
: ]" S# b9 m8 v功 能: 画一个二维条形图 , T9 V# _$ ]2 Q: i
用 法: void far bar(int left, int top, int right, int bottom);
$ q3 V/ D2 U9 f- R程序例: </P>4 H* J* V2 r$ j' T! O
< ><FONT color=#0000ff>#include <GRAPHICS.H>9 z3 q4 C$ H; i# t: U( @" M0 e
#include <STDLIB.H>" e0 X) K4 ]' h7 E+ d8 k! @) g
#include <STDIO.H>
9 Y, c/ }8 S& q3 h, Y q" j#include <CONIO.H></FONT></P>1 L& B( j# j) ]7 P
< ><FONT color=#0000ff>int main(void) ( Q0 _: q" ?$ W$ Q* J
{ . y) x+ V* V/ w; j, R$ X
/* request auto detection */
( A( r! e1 N5 z3 \& G4 u2 hint gdriver = DETECT, gmode, errorcode;
9 u, q }4 F& H6 {int midx, midy, i; </FONT></P>& }5 Y: G; D. z5 y
< ><FONT color=#0000ff>/* initialize graphics and local variables */ 4 ^% | ~0 v6 l* X
initgraph(&gdriver, &gmode, ""); </FONT></P>
) Z" l% }2 ]2 _2 O/ c< ><FONT color=#0000ff>/* read result of initialization */
) k9 t# b4 W. Perrorcode = graphresult(); & Y3 h7 f: {- ?* ~6 J, s' A4 I" }/ p
if (errorcode != grOk) /* an error occurred */
' F% g" j0 U( z2 F1 U0 M& y; ?{ 7 W, k, N R: t( }# s
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 _; h+ `. Z5 O3 `: vprintf(" ress any key to halt:"); 0 N: o# O) b. |6 O1 q
getch();
7 s+ i- o- c8 O) W0 Qexit(1); /* terminate with an error code */
6 U& }$ e1 n6 Y, D) }+ A, v} </FONT></P>
7 g3 a6 b3 T% C$ t; J- R< ><FONT color=#0000ff>midx = getmaxx() / 2;
9 \2 }( _0 G1 omidy = getmaxy() / 2; </FONT></P>5 a0 z% w& a+ k; z B
< ><FONT color=#0000ff>/* loop through the fill patterns */ 0 [9 T, y. @$ _# @, I. S" j
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { 1 ?, g& `& R$ r* i
/* set the fill style */
7 e6 W, N& C8 a1 Ssetfillstyle(i, getmaxcolor()); </FONT></P>5 ]6 i' y, f P( N2 _- V7 p: l1 K* T
< ><FONT color=#0000ff>/* draw the bar */ - Q ~8 z! t" j- v
bar(midx-50, midy-50, midx+50, 4 Y- P7 v; g8 P/ G3 ^0 P: h/ c7 c
midy+50); </FONT></P>
6 g- x8 X7 [. R9 C% [3 D/ \2 q u- T< ><FONT color=#0000ff>getch();
3 q# B$ k! D ?, O+ C2 Z: f} </FONT></P>
. c4 `( V. t. e9 D' N! Y< ><FONT color=#0000ff>/* clean up */ 0 y. z8 @3 }4 B: f9 Q- S
closegraph();
1 r: p8 T! m* f6 vreturn 0;
. G9 r- {1 s: c1 w} </FONT>
1 ~. y9 c( H4 V8 `5 O( G$ c: J5 ~' C, m7 Z# x) H3 l9 [8 F- S' z9 h
1 j0 C8 t, H# K! v1 Q0 K& y1 I, C4 f</P>% i g( c; i8 t
< ><FONT color=#ff0000>函数名: bar3d </FONT>
' K w" v5 l5 \1 \ Y功 能: 画一个三维条形图 , f9 G" P. g- `1 L& }; `) r
用 法: void far bar3d(int left, int top, int right, int bottom,
; Z$ _1 T5 D9 b0 |9 d' e5 u( kint depth, int topflag); ; J! E |+ k% f; I) h# }7 I
程序例: </P>0 j6 j/ r( m X9 s2 n u, C4 c
< ><FONT color=#0000ff>#include <GRAPHICS.H>
2 q9 y+ s9 g9 u#include <STDLIB.H>
8 M! r- S- w8 U7 g" I, G#include <STDIO.H>& H7 M" o9 q3 V0 v5 h
#include <CONIO.H></FONT></P>
: Y* |, d+ B' n. X4 _* T< ><FONT color=#0000ff>int main(void) . P* N2 q0 C; Q0 m1 B- o! q( H* E
{
& c, J' M. b- v2 E2 V: \* D9 y/* request auto detection */
% p2 j7 [8 j* T7 `, y2 bint gdriver = DETECT, gmode, errorcode; 9 q9 E& F# e$ x/ O
int midx, midy, i; </FONT></P>" ?2 ^" {0 r- a% A; y; |' z/ L
< ><FONT color=#0000ff>/* initialize graphics, local variables */
7 } ]1 Y4 Z X0 oinitgraph(&gdriver, &gmode, ""); </FONT></P>
: o/ `2 i( }3 x) l< ><FONT color=#0000ff>/* read result of initialization */ : ~9 C1 ]% C D
errorcode = graphresult();
3 X7 i: }* c# k- n% T9 t9 }if (errorcode != grOk) /* an error occurred */
' {0 o' w( E3 ~! Y) [{ 8 K% K+ @" Q8 G# ]4 V: g; R
printf("Graphics error: %s\n", grapherrormsg(errorcode));
; f4 V- `$ m, S; f% h% Dprintf(" ress any key to halt:");
, H9 _ N6 ]6 q/ `7 s# i8 E1 }getch(); 3 O5 ], n) V+ b, Q1 B8 A
exit(1); /* terminate with error code */
1 I: ]" I. M. n; @3 [! b+ \( s} </FONT></P>; S" z- W+ `. s
< ><FONT color=#0000ff>midx = getmaxx() / 2; / J: H# v2 k! F
midy = getmaxy() / 2; </FONT></P>* Y; K: s6 G) D# x
< ><FONT color=#0000ff>/* loop through the fill patterns */ 0 L! q8 g9 k F2 M
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
, d8 ]0 G$ {8 |- u: b h/* set the fill style */
3 g" t1 G: w3 T& r* b* w! ^setfillstyle(i, getmaxcolor()); </FONT></P>/ Y- s8 p' }6 N* o
< ><FONT color=#0000ff>/* draw the 3-d bar */
& D$ e; A4 G* _# C' k6 B; ebar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>/ j, S+ D2 @" ~. R
< ><FONT color=#0000ff>getch(); 2 R) Q! T9 ?1 N1 k. B
} </FONT></P>) i1 K- x- X: `+ e( k$ G
< ><FONT color=#0000ff>/* clean up */ % D7 j. v. i' M) O8 m
closegraph(); " O9 D/ F: I# G# A+ J
return 0;
6 X# s- r- l+ |7 V7 F} ) n4 i2 k% E5 Z6 b- w
</FONT>
1 d$ u* S1 b+ Z
! m# H8 ?1 C$ o/ C g, h$ j</P>
6 e6 u, g3 m5 {: B6 d5 _) G9 U' d< ><FONT color=#ff0000>函数名: bdos </FONT>
3 f3 E! y0 a, d1 g1 Q; x/ |5 N# F功 能: DOS系统调用
; x( W; d1 d- K4 H用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 1 J) p; P2 G5 P( M) _1 t; g, a* P' Z4 A
程序例: </P>
8 i5 i! {- o* r8 b6 w9 G: @< ><FONT color=#0000ff>#include <STDIO.H>
7 W+ T1 [, j9 V F- C#include <DOS.H></FONT></P>7 t9 ?. _ @0 e! x$ x
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ - t, i5 N4 o/ G- g- M2 w$ {
char current_drive(void) 1 c+ P3 _) h3 T+ D) G, B
{
% ]; b6 [+ Z. Schar curdrive; </FONT></P>
, A9 D6 J8 R, K! Q( ^" u< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ 8 y6 j9 F1 l0 O/ D
curdrive = bdos(0x19, 0, 0); . z. r# q4 C0 |3 e
return('A' + curdrive);
; C9 G! c3 I: [; ?4 F! e} </FONT></P>: ?6 y# Q6 @0 R e1 N( E
< ><FONT color=#0000ff>int main(void)
; C$ j$ Y3 b; F) w$ K/ R3 h{
; e+ \/ }( c6 n: w/ Dprintf("The current drive is %c:\n", current_drive()); 6 l" X7 W+ r0 F! t! C0 Z
return 0;
2 f$ ~. K9 o l. @, ^6 ?} ( u( Z( P+ U0 S5 ?% r# ^) ?
9 V4 [ e/ V4 i7 n8 z* C1 d! e</FONT>
Y: N0 D$ D# K' }</P>
( a+ D0 I! L' m$ n3 [ J< ><FONT color=#ff0000>函数名: bdosptr </FONT>
0 Q& ^9 a z" R. B% n. t3 _% N功 能: DOS系统调用
: ]+ W3 d( a% p; x3 T, h- h用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); " f5 m3 e7 ?5 k/ x5 A, F _* ]
程序例: </P>/ i! ~1 j0 ~2 n4 [, |0 Z
< ><FONT color=#0000ff>#include <STRING.H>
" |$ D" @' T6 A0 E6 @; _#include <STDIO.H>! Y- ~ A( U& x; F$ q! _2 f6 Y: H
#include <DIR.H>
- g5 l' g/ P2 q# C3 N#include <DOS.H>
$ t* }# k3 g5 y) G6 p#include <ERRNO.H>
8 w! L) l4 a, A0 l6 Z1 _6 O" ^# c#include <STDLIB.H></FONT></P>! v0 K8 q `: R0 q& r' a4 i- e
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>/ J) Z' N! e1 q& L8 Y
<P><FONT color=#0000ff>int main(void) ! E& |. {* k! d3 o& A
{
' @( E9 t1 x# g- [. }char buffer[BUFLEN];
) w4 T0 V5 |; I: f$ t5 X" [9 ~6 Pint test; </FONT></P>
6 G& t/ v6 X* g! ]2 }8 ^<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
. F3 d& W, ` I( s) jgets(buffer); </FONT></P>
- [, n! @( e2 B8 B' ~$ b3 a<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
% n3 m- _% }, ?4 `$ m `if(test)
6 {: N' E) m4 k/ U{ # c) g6 J [ R% O+ J* j' U) [
printf("DOS error message: %d\n", errno);
[) |# R" b% Z7 B2 M- p/* See errno.h for error listings */ 5 c7 a) p% K+ D' n5 e
exit (1); 6 T' G7 K$ t/ t! ~$ F& y( M
} </FONT></P>
4 \. E4 F" b% T. P3 f( G% w7 w' j<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
) W9 K- U v, C. }# C" s3 ]. i+ hprintf("The current directory is: %s\n", buffer); </FONT></P>9 l& y) ?& H# B
<P><FONT color=#0000ff>return 0; / Q" I" l) [$ O$ J7 Z2 F* h
} ; `% N" k$ T$ d6 F1 `
</FONT> @: m. E' I$ p, e& W% z
% H$ B) E4 a/ @1 e# W2 h
</P>
4 L& P! r O3 M2 P( Q* ~# Y<P><FONT color=#ff0000>函数名: bioscom </FONT>$ j8 `' C; N" ^ ^: P$ j. E
功 能: 串行I/O通信
/ l$ p: D! }+ K* f; U2 F5 {' b0 m用 法: int bioscom(int cmd, char abyte, int port);
. z' C* j) T( L. }7 k程序例: </P>
0 D2 V; ^* u* Z( g. r' ?. o<P><FONT color=#0000ff>#include <BIOS.H> y* t8 ?' e2 j: t
#include <CONIO.H></FONT></P>
% w, a) k- N6 z2 J" B# j0 x, r<P><FONT color=#0000ff>#define COM1 0
/ G9 I2 E- t+ v h5 f" S#define DATA_READY 0x100 / S3 J" ^# {& ~ F) Z: U
#define TRUE 1
, G; b# m u4 M% c: h1 [#define FALSE 0 </FONT></P>% v( y4 L" r4 [ S b! }+ t
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>' x2 p" H2 C% \1 M: y
<P><FONT color=#0000ff>int main(void) : d9 E+ A+ D& L5 b% q4 ?, Y& |' K
{ ' U! l% I$ @ O- C8 P3 E- u6 {
int in, out, status, DONE = FALSE; </FONT></P>
% c! w9 R( c) |+ \4 o) t<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); 4 D' R! i) K E
cprintf("... BIOSCOM [ESC] to exit ...\n"); , k' ]" N/ w5 x9 ?0 d
while (!DONE)
B/ N, @1 A/ M' W' p{
# O& U- p1 w( k% T& X# ?status = bioscom(3, 0, COM1);
. B5 z" @* I& V) rif (status & DATA_READY) 2 ^1 C; d' I- Y
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) 2 N4 p) r7 i- e% z5 U, B+ ] T
putch(out); 8 H. J" ]* H9 W% w' Z' i
if (kbhit()) 7 E$ j6 g# |3 N7 o# _
{
7 Q: ^. j0 g% \- Eif ((in = getch()) == '\x1B')
. {3 U; J3 s X6 zDONE = TRUE;
4 t2 _+ h$ X6 R U9 j1 @! \bioscom(1, in, COM1);
, s, k( x! S" _7 w1 ^/ d* a9 j( y} : G6 ^+ S: V5 `9 Y8 g5 I; E
}
$ x! p4 ]- M) W3 wreturn 0;
3 D) n9 v' ^6 \/ p& f} </FONT>
& \/ D/ A( r" e9 z) g
: Q) ^: x7 J$ f$ A4 J8 T( w3 t6 |1 g ?+ Q/ S+ z6 ]8 V% _
</P>
, o2 Q. f0 Z! J2 V<P><FONT color=#ff0000>函数名: biosdisk </FONT>
1 T% Z/ {, v0 c. m, ?& Q功 能: 软硬盘I/O 6 [2 N. m8 H9 w4 d+ Y, {" t9 U/ C
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 7 u1 @ ~( K/ }. \+ [2 T
int nsects, void *buffer);
2 ?$ `# i; S/ n$ f/ o程序例: </P>: i+ d6 \& t+ G1 ?
<P><FONT color=#0000ff>#include <BIOS.H>
+ Z; t5 v5 c0 E#include <STDIO.H></FONT></P>
P/ X4 R' F9 a9 }3 w& `% S7 c- a2 M<P><FONT color=#0000ff>int main(void)
$ V2 }3 t6 X$ j{
: g- E9 `; F1 y( Wint result;
! l- M# n9 h: W$ P; V8 nchar buffer[512]; </FONT></P>
3 o4 V& D! K1 ?$ x<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); $ Z8 {$ y, l. }) Y
result = biosdisk(4,0,0,0,0,1,buffer); 5 q2 R/ F0 w! n* \! p3 f( a' {, ?
result &= 0x02;
( t' L- O& o$ |4 W: l4 q, N L(result) ? (printf("Drive A: Ready\n")) :
7 |, K; h" \/ I3 C(printf("Drive A: Not Ready\n")); </FONT></P>5 ?* {/ E1 o+ u4 |
<P><FONT color=#0000ff>return 0; & b; e/ x3 v% X2 T& \0 Q$ _5 f( p' k5 l
} ' l4 f0 ]; G. s4 w! L% |
</FONT>6 Y) O( M( p6 V! C
; |* a8 ^' X& W9 u }</P>" [& X! S2 V( x8 F9 t
<P><FONT color=#ff0000>函数名: biosequip </FONT>! p3 z# P j: K: p" a) ?6 h# m
功 能: 检查设备
1 `8 O6 T. \8 j3 N" o" v用 法: int biosequip(void); $ s/ k4 n. { z* E
程序例: </P>
$ h- }$ m) c @* p<P><FONT color=#0000ff>#include <BIOS.H>
0 \* b' ] o7 |2 |$ v* t#include <STDIO.H></FONT></P>
; R& e- W* [0 B2 M<P><FONT color=#0000ff>int main(void) + F& h; j% M# s- P w3 |# Q. s
{
1 u1 N r& Z ~8 Z- ~int result;
9 C5 Q9 q4 m) x) n9 N" ichar buffer[512]; </FONT></P>" l; n$ i' a N; H, r; M
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); / X8 m6 j! F2 t# j( _$ p
result = biosdisk(4,0,0,0,0,1,buffer);
5 r9 I' E/ S. l8 `7 }- Tresult &= 0x02; % N+ z2 f z/ N H+ \+ D- b+ A; ?$ I
(result) ? (printf("Drive A: Ready\n")) : - x* U* `9 t3 l$ L: E
(printf("Drive A: Not Ready\n")); </FONT></P>
6 @4 k5 {6 E& w4 h3 V7 a<P><FONT color=#0000ff>return 0;
4 l0 O* F: U& A2 y3 F# K} 8 W: P% v- O5 K, e
</FONT>5 t! h9 ^$ w) e( O9 A' k* U3 e
9 U: w+ i' e' t: N) j' K9 C5 z& g! I</P>0 i1 e. {; t k$ q
<P><FONT color=#ff0000>函数名: bioskey </FONT>
% _5 U' o) d+ d* o. ~功 能: 直接使用BIOS服务的键盘接口 6 y! V# X) M+ f2 o1 J
用 法: int bioskey(int cmd); 5 m( c& [) Y, g3 B/ w
程序例: </P>
9 P6 `0 C. u: H$ u<P><FONT color=#0000ff>#include <STDIO.H>
! _* }7 [6 k% _! Y#include <BIOS.H>) a, E9 f: j7 a, n9 T/ ~* d
#include <CTYPE.H></FONT></P># o3 M: Z }9 A6 ~9 N
<P><FONT color=#0000ff>#define RIGHT 0x01 ) h* t; l/ e& A: r( D
#define LEFT 0x02
4 p$ I8 y2 |$ I! q#define CTRL 0x04 5 _* i m- A) `9 H, C
#define ALT 0x08 </FONT></P>+ ]; m7 a' [% U8 P+ F/ ^3 o
<P><FONT color=#0000ff>int main(void)
& X, S' a8 W# e/ M{ 8 g3 R1 _6 a4 n2 F1 k
int key, modifiers; </FONT></P>6 d- H$ O; k: H& `
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
& s) ]6 Z1 W* O! d# ]3 Iwhile (bioskey(1) == 0); </FONT></P> L* ?' M; @( b: c
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ : [, a% H2 O9 E
key = bioskey(0); </FONT></P>% V) D5 L# e- z: r6 O0 _" A
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
. F# C( |; `+ |) [modifiers = bioskey(2); $ f3 [7 j) b0 K
if (modifiers)
* h) s7 Q4 U* d5 F( I% O! s) X{ / R1 U0 l% `8 J) `* u
printf("["); 8 N% V0 l+ o0 V8 K
if (modifiers & RIGHT) printf("RIGHT"); 6 i! X. E8 b) v8 z; l k
if (modifiers & LEFT) printf("LEFT"); 6 y. Z4 M% O% O3 |/ }/ e
if (modifiers & CTRL) printf("CTRL");
* ~0 P4 \% V: K8 U' Zif (modifiers & ALT) printf("ALT");
6 L+ Q. A! ^) N6 {+ Yprintf("]"); ) o8 t* B4 y$ E5 v/ l z
}
/ j. \4 x2 [: G& g* U/* print out the character read */
7 _0 U7 I8 Z5 a/ n aif (isalnum(key & 0xFF)) - y, o# A1 [. G5 X7 J
printf("'%c'\n", key); 3 J0 u6 a1 {6 _. K" d3 x' y/ W
else
& e4 Y* x6 P# M6 k6 b6 O3 Gprintf("%#02x\n", key); ; U8 y' g, G: W
return 0; 4 O) A& Y$ m; `% s2 `( c+ ^% i
}
% f4 W6 q0 H1 n; x2 G/ n) X, K) N& F
</FONT></P>
- @" z3 s2 `/ l0 |) o1 y<P><FONT color=#ff0000>函数名: biosmemory </FONT>9 r8 e) ~3 f C K/ `0 Z
功 能: 返回存储块大小
4 i0 }3 a: [9 H9 g用 法:int biosmemory(void);
( a0 P4 f! V: b3 \, }" V程序例: </P>
# W+ o( M8 f( I2 {) u: \( K0 ~<P><FONT color=#0000ff>#include <STDIO.H>
* v) s. f1 f" h* B' F#include <BIOS.H></FONT></P>
% B5 A* V& _2 l9 U& \$ t& s9 F<P><FONT color=#0000ff>int main(void)
' `7 M4 d. w2 F& b{
3 R- k, I3 e. Q8 t. Uint memory_size; </FONT></P>
7 U4 M n& K1 u* A1 R* v( ~' h<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
$ J Y. C. V! b% C7 R3 M& ^, Oprintf("RAM size = %dK\n",memory_size); # L* x( c) o! w& E7 k$ ?8 C
return 0; 0 J! K( {( F7 y+ d" h5 o
} 6 W5 p. Q! x$ c4 ]: Y; i
</FONT>
2 Q# X9 ?0 r6 i3 ]7 _
! B1 X2 z0 w, D- ^</P>
l2 P% ^" y+ g$ N2 w<P><FONT color=#ff0000>函数名: biosprint </FONT>
- O/ R" y- J6 m* g3 z+ S功 能: 直接使用BIOS服务的打印机I/O
5 L, j( {* W' Z- I4 E6 P6 B- i! J用 法: int biosprint(int cmd, int byte, int port); ) G# _1 F. L- }% i6 g6 |
程序例: </P>6 [0 g- m d+ S& T
<P><FONT color=#0000ff>#include <STDIO.H>
6 F3 G2 j2 l6 ?5 g#include <CONIO.H>
/ Z0 m# f; [2 f+ D7 L- N#include <BIOS.H></FONT></P>
3 a Q; c( }9 K' c<P><FONT color=#0000ff>int main(void)
9 R# p7 k' @" b# D: v) E1 A5 q{
+ z7 O5 ]. Q$ n% \, K#define STATUS 2 /* printer status command */
2 c$ N- E; ]+ S8 n) i. r#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>& w) `7 w' d. {6 x4 n% D3 `
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
7 {- ?1 D. p+ I1 O) e8 Z& x<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
/ C+ ]' B# z, n/ i# W0 S- ?getch(); 7 ~! r: M4 p- n) W! l/ ~7 j
status = biosprint(STATUS, abyte, PORTNUM); 8 g$ Q, k" s* t3 b* i
if (status & 0x01)
- ^3 d! p" |* c | E( aprintf("Device time out.\n"); , m3 I7 a9 Y* Z
if (status & 0x08)
1 k) U9 x5 j3 C7 w: Jprintf("I/O error.\n"); </FONT></P>
+ \( ?- P9 b7 z: S" h<P><FONT color=#0000ff>if (status & 0x10)
* i4 v0 d$ f9 s1 Fprintf("Selected.\n");
0 k7 F1 \# M+ ~! U1 Oif (status & 0x20) # E8 K9 y$ {6 B6 j
printf("Out of paper.\n"); </FONT></P>$ D6 B3 u( r; ~% { b
<P><FONT color=#0000ff>if (status & 0x40) 4 C8 m X2 E4 R9 a' m
printf("Acknowledge.\n"); 4 G( F$ x# x( G+ H5 h1 J6 ^
if (status & 0x80) ( j1 T$ i5 U5 R- K
printf("Not busy.\n"); </FONT></P>* l9 f; [ s0 T4 z: V% L; [
<P><FONT color=#0000ff>return 0;
. q5 m: l+ A: ?3 ?}
5 F g% y Z2 O) ]% B</FONT>% ?3 N% d/ w. L3 p8 h* s2 E
6 q2 {. ]2 C, ]: I" d# J& p0 Y</P>/ g6 \! j- I+ b0 s, e% Y
<P><FONT color=#ff0000>函数名: biostime </FONT>
$ ^) z0 T) l' E8 Z) O& A功 能: 读取或设置BIOS时间
% v- t2 c d. W* V/ L1 j用 法: long biostime(int cmd, long newtime); 6 c; x4 X/ R: W3 N, |4 Y2 w* ]
程序例: </P>
: w* I. I) M* v2 Y# r' i# t5 D<P><FONT color=#0000ff>#include <STDIO.H>
& V5 F4 T6 {' H# i#include <BIOS.H>
0 |2 o3 |) z6 T: N#include <TIME.H>1 o1 L, K. B9 j5 ` }( I
#include <CONIO.H></FONT></P>
# d* c8 _9 W' }<P><FONT color=#0000ff>int main(void) : o) f: I. e4 f* H
{ 8 q) q7 H/ @6 |2 d! {% c% h0 T7 t
long bios_time; </FONT></P>! s+ V+ J% q' M/ h- o7 U% ]) D
<P><FONT color=#0000ff>clrscr();
: L* _% y9 K" q, Zcprintf("The number of clock ticks since midnight is:\r\n"); ) W7 D: k5 ]' m
cprintf("The number of seconds since midnight is:\r\n"); $ r( ?* }. K% i3 Y, O
cprintf("The number of minutes since midnight is:\r\n"); 2 g# z/ q- B0 y: R- j" a1 c
cprintf("The number of hours since midnight is:\r\n"); : r0 P* S7 M* p+ {8 e" S8 } n
cprintf("\r\nPress any key to quit:"); " \; U: X3 @, a, Q' ~) n
while(!kbhit()) . J1 l# l* C9 o
{ . \" r; ] Y4 R! V- S" B. z
bios_time = biostime(0, 0L); </FONT></P>8 Z2 O. c* M7 a+ j) B- m
<P><FONT color=#0000ff>gotoxy(50, 1);
; z/ @7 r h" J" Ycprintf("%lu", bios_time); </FONT></P>
) d! T! ]! c v<P><FONT color=#0000ff>gotoxy(50, 2);
/ Y7 L5 d9 g* J' ycprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
) D8 r Q7 L F<P><FONT color=#0000ff>gotoxy(50, 3);
2 J% C, O9 v ucprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
% E( V' [# r: N<P><FONT color=#0000ff>gotoxy(50, 4);
4 @! q: h7 V) l- {6 E6 Qcprintf("%.4f", bios_time / CLK_TCK / 3600); ) i; Y: C/ p' K% z
} 2 e$ Q& |& Y* s) ^) e
return 0;
/ n. u6 z* Z) J1 f, t$ }: H, z} % w: x5 s6 h1 u& u$ g. c
</FONT>) p* A" X* w5 [
# H/ O, ?9 U. ]8 |2 |; \% m: u</P>
( u$ V( ?1 T( V6 T7 d& c' w$ I<P><FONT color=#ff0000>函数名: brk </FONT>
- H" D% b* Y! s* @+ s功 能: 改变数据段空间分配
2 o* p( F! j5 H& U8 P& J* l7 B/ W用 法: int brk(void *endds); w) G; ^/ @6 s/ Q' E
程序例: </P>% Y# s+ [8 ]+ B7 t
<P><FONT color=#0000ff>#include <STDIO.H>
# D5 R0 h( c+ G+ z/ \# }9 s#include <ALLOC.H></FONT></P># B/ u* [" n$ Q$ T
<P><FONT color=#0000ff>int main(void) 6 n' m- O& f; P& M; O/ H
{
2 V% [8 w. a2 \4 h+ M1 I) ]char *ptr; </FONT></P>; d* B# s1 o; g2 {9 F
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
) } q( ~! {3 Z7 q. W( \/ sptr = malloc(1);
" e$ j8 R( J. J% c9 V6 jprintf("Before brk() call: %lu bytes free\n", coreleft());
7 Y+ {$ T( X: R/ pbrk(ptr+1000); : J8 L) q- s9 y; }! g
printf(" After brk() call: %lu bytes free\n", coreleft());
% ]: n" B3 t& v) Z" {: Areturn 0;
+ V& o; P1 ~1 ?9 o}
4 D: W1 G0 c1 o. ? e5 r& \4 M& {9 t5 |8 ]9 V+ X
</FONT>7 h. E w6 ~4 y
</P>8 @! n7 }2 O! x; A% q
<P><FONT color=#ff0000>函数名: bsearch </FONT>
% o9 C3 ]$ l! K* Z1 e* o) Z功 能: 二分法搜索 9 D b' m7 n$ u7 X) h$ X+ d: |
用 法: void *bsearch(const void *key, const void *base, size_t *nelem, * i3 p- }4 \: V+ Q. R0 }- A7 t" B
size_t width, int(*fcmp)(const void *, const *));
/ W( u3 k( U7 @0 I. |, C' Y. D- i2 C程序例: </P>: H4 Y) e" N' M" H" ?
<P><FONT color=#0000ff>#include <STDLIB.H> J9 ~, e7 u5 Z& R: @+ X7 h% x! ^
#include <STDIO.H></FONT></P>* F; i7 ~. m6 V& _8 t4 `
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>8 E5 v$ u3 Y3 m/ ~2 `% f" b' W
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
/ {- r5 S5 J+ B; h$ y+ w! R<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) + T, W s9 l) M/ K
{
7 S- L5 h* Y" ]/ [$ d- c$ u* d( u" J- [return(*p1 - *p2); ' j! |/ m" O. z$ [
} </FONT></P>
2 v4 T( b% _# e<P><FONT color=#0000ff>int lookup(int key)
* A. @2 d/ z7 b$ M; b) f5 b' A{
, T: _4 R, n& S% l* _% q& _4 Q; Bint *itemptr; </FONT></P>
; P; L5 }' k7 E. @0 T: g0 y) a<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) " [! m7 { K9 a; o7 K% C) K3 M
is needed to avoid a type mismatch error at
3 @+ ~. @+ c) O: `% C+ S* ]compile time */ 9 w: z0 y/ b# S' V/ G3 C3 u6 j0 }5 V
itemptr = bsearch (&key, numarray, NELEMS(numarray),
# ^5 H* O6 S; ]$ p9 E3 H) Q& dsizeof(int), (int(*)(const void *,const void *))numeric); % m$ P- B% k1 b# T* y3 U) |
return (itemptr != NULL);
" L! t( `9 V( @; _: X8 ~} </FONT></P>6 R. v( n& h1 X2 a1 \& w: o6 ?
<P><FONT color=#0000ff>int main(void)
9 O: O { O. m" c{ : q5 w# b5 N8 ^4 Q, h
if (lookup(512))
1 a9 A9 q' I7 G- `. l8 yprintf("512 is in the table.\n");
! I8 D7 i" N: s% ^+ `else ! D* n L8 i$ {7 j
printf("512 isn't in the table.\n"); </FONT></P>+ W; O' e- R. m
<P><FONT color=#0000ff>return 0; ! c; ~7 J' p5 j( ?& G
} </FONT></P> |
zan
|