- 在线时间
- 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>) _. R' `- _5 C1 ~
< ><FONT color=#ff0000>函数名: bar </FONT>2 _ s9 J& L; P* J, ^1 O G
功 能: 画一个二维条形图
) L& j. u. s) J8 m用 法: void far bar(int left, int top, int right, int bottom);
) Z- m9 u0 {1 a3 K, M程序例: </P>9 R& x. a. O7 I n W( d' i( b
< ><FONT color=#0000ff>#include <GRAPHICS.H>
" D7 I) f6 U9 i) S& X2 c' f( P#include <STDLIB.H>* t) {) ^! J4 W9 i- {( _- B2 _( r$ H1 k
#include <STDIO.H>
0 |0 b5 F6 |3 _) J( v. H#include <CONIO.H></FONT></P>
0 i }% |+ O& q# e8 @$ F I* C9 D< ><FONT color=#0000ff>int main(void)
s5 n5 V4 M4 H6 X; f( u {2 i Z{ 9 N5 K+ T; f# t h& d, a
/* request auto detection */
1 \7 e J" b7 v0 `5 u; x3 Cint gdriver = DETECT, gmode, errorcode;
7 ^6 J9 }7 o/ a* L% _. j0 Fint midx, midy, i; </FONT></P>
( ?& ~2 b9 W: u( e" }1 a C. k" s< ><FONT color=#0000ff>/* initialize graphics and local variables */
2 A5 y. h0 M$ C4 Uinitgraph(&gdriver, &gmode, ""); </FONT></P>5 W! ^+ f* q& X' t2 N+ X
< ><FONT color=#0000ff>/* read result of initialization */ 8 \2 _7 q4 i$ Z5 b. m
errorcode = graphresult(); ) W( ^6 w9 ^- R3 Q( H
if (errorcode != grOk) /* an error occurred */ ( {. `1 @% f& r# x9 f
{
1 r7 W# K3 A# Zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ; A( ~- F5 R& J* W$ o4 R
printf(" ress any key to halt:");
2 q- {5 [( `7 c/ Bgetch();
) t* B Z7 t8 O" Oexit(1); /* terminate with an error code */
4 z- l8 p! g, I2 F} </FONT></P>
5 g4 ^- k* I, \% E- h0 X1 @# v% E, a< ><FONT color=#0000ff>midx = getmaxx() / 2;
, m6 }4 K& H, K# ]' _midy = getmaxy() / 2; </FONT></P>
8 }! C' E6 P8 t8 F& ?- Y( l7 d, W< ><FONT color=#0000ff>/* loop through the fill patterns */ 9 R& S3 b* p+ d& K4 L
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { ! n) H, Q. n* r& {3 ^! j6 {: T
/* set the fill style */ 8 Y7 c6 y \, b
setfillstyle(i, getmaxcolor()); </FONT></P>
0 n# j% @6 v3 D# p o< ><FONT color=#0000ff>/* draw the bar */ 6 D2 b( T k5 E* m- D
bar(midx-50, midy-50, midx+50,
7 R/ Z0 i5 t2 ^0 Y" Cmidy+50); </FONT></P>
/ [# L# M! |9 p) A& o< ><FONT color=#0000ff>getch(); 9 J/ N% r) d8 Y9 N
} </FONT></P>
* X6 G" k! j0 b+ H' E< ><FONT color=#0000ff>/* clean up */
1 p) M8 S6 f5 G- ]closegraph(); ! l8 N4 f" ^- l" P" z l
return 0;
# c4 }9 l; a. T5 \} </FONT>' x) T8 \$ L' ^/ X
# Q! L- t6 X4 |& L* r" |2 T' i6 U A5 q: a& N* D+ U9 e. o. A
</P>6 b# r+ z2 n) e; z p7 m& f. ^& |
< ><FONT color=#ff0000>函数名: bar3d </FONT>: J- i4 K; I1 E$ w' P4 \3 p, T+ y, Y4 O
功 能: 画一个三维条形图
6 \) [; Z. ?& q; t- A& |7 I4 {: m用 法: void far bar3d(int left, int top, int right, int bottom,
8 n# n( F% |7 k- h& o, {! o/ Lint depth, int topflag); 9 T) K0 U: G( ]( O: S3 A4 G* a0 v
程序例: </P>+ D" b3 v( [9 R$ n1 r7 @- \
< ><FONT color=#0000ff>#include <GRAPHICS.H># l6 ]; Y* _8 q6 }* D, \2 M, f
#include <STDLIB.H>
j1 _$ \7 J% i2 M3 T& E#include <STDIO.H>
4 T( D2 L6 \0 P6 N( A/ A( j! n#include <CONIO.H></FONT></P>3 q6 N. @) `0 \/ Y/ n D
< ><FONT color=#0000ff>int main(void)
6 L% x7 F# E: n* `{ $ t* w( r8 c J) Q% r2 o
/* request auto detection */ 4 |3 ]# y/ {) M5 a. I% I4 o
int gdriver = DETECT, gmode, errorcode; % U3 X5 }% C% K+ y) Q
int midx, midy, i; </FONT></P>, n$ v2 Y. j i+ w4 g8 M7 R3 t
< ><FONT color=#0000ff>/* initialize graphics, local variables */ + } S7 P2 U4 g4 m
initgraph(&gdriver, &gmode, ""); </FONT></P>
7 i; p4 f( v y, F/ {< ><FONT color=#0000ff>/* read result of initialization */ ( e6 X, @! a3 _
errorcode = graphresult();
+ \+ y5 \3 N7 o Uif (errorcode != grOk) /* an error occurred */
9 l6 k' i* J) u{ 4 S& ?0 \: Z) X9 K0 M3 \
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 ~6 `% T+ H- u' ]3 m. h
printf(" ress any key to halt:"); ) g; i% v* h! M: q& ]" P" d
getch();
* g& h% G x1 \3 Cexit(1); /* terminate with error code */ - A( ^0 x$ `1 U- e; o( O
} </FONT></P>! d) m! ^" c' Q
< ><FONT color=#0000ff>midx = getmaxx() / 2;
# m6 L9 X1 @# Y! y# B, x0 c zmidy = getmaxy() / 2; </FONT></P>5 y |8 U9 H o6 ?
< ><FONT color=#0000ff>/* loop through the fill patterns */
0 m" D4 P S5 r/ {& H3 }4 R, \# ^for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
8 ]1 f1 @& U* J% ]/ [/* set the fill style */ # {5 j, Y; Z6 I8 V. _/ e
setfillstyle(i, getmaxcolor()); </FONT></P>
2 C5 p% h. H" W! i7 R) z, g) u< ><FONT color=#0000ff>/* draw the 3-d bar */
9 K* b. ~ A+ C' ~1 F5 P! b/ b) obar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>" B! g+ c! y5 [8 a* G; S0 ^/ h
< ><FONT color=#0000ff>getch(); 6 R2 B( U3 B9 i
} </FONT></P>1 A& F$ z1 \6 X8 }% P+ c# }; g% c
< ><FONT color=#0000ff>/* clean up */ & D0 t; D8 W% v5 A
closegraph();
" x) H. Q* f L0 d& N, F0 I8 F! wreturn 0; : ]# P" ^1 U0 q! \5 O: c; O
} * ]) l; H6 E' C- s. P
</FONT>
9 H9 ]8 e% Q. X0 P; S' Q4 Q( t# t
</P>
: p% t$ }& }" W0 t; C< ><FONT color=#ff0000>函数名: bdos </FONT>
8 A% w# Y2 T* \6 P# t/ E7 Z功 能: DOS系统调用 . |( N6 J, k* g
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
5 @" }9 X: a: L6 E程序例: </P>. a# R1 T9 P. m1 F. {
< ><FONT color=#0000ff>#include <STDIO.H>
: u( N% ?- o3 c* X#include <DOS.H></FONT></P>( j7 V) h7 Q# e6 Z9 ]# u8 L
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
% P2 r4 B4 Y1 D5 H+ ~! @4 C$ K6 Ichar current_drive(void) % ~5 z' {' |$ _6 w. w
{
4 A; a* Z' E/ @char curdrive; </FONT></P>" J; F2 H) C( Q/ e8 C+ E( h, Q4 x
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ 8 p0 m8 {+ b3 t
curdrive = bdos(0x19, 0, 0); + R1 l2 o1 N5 }$ R( m, n
return('A' + curdrive); ) `7 a5 m8 f5 o k# _! E$ J
} </FONT></P>4 G# Z9 f8 G+ ]3 n8 P3 M: g7 I
< ><FONT color=#0000ff>int main(void) 4 e" v a, Z7 L% ~
{
; k1 p$ d1 t% T4 F3 Q- qprintf("The current drive is %c:\n", current_drive());
/ `( M. I* k# r3 Y* V) p2 x( lreturn 0; : M3 a, C9 k3 U/ I; X. c
}
$ u. S) V$ [1 g3 c2 F
" b0 ?" }% P' |& C</FONT>: \5 D9 ~' N w; s! `
</P>
) M$ [2 e& g8 h( |& o# t7 }< ><FONT color=#ff0000>函数名: bdosptr </FONT>
" i4 X. N8 Z" ]5 T功 能: DOS系统调用 4 H T/ J1 W A V- J" K9 J- c
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
! t) E7 x5 ?1 O4 s# J x程序例: </P>9 H: ? @# [0 ~1 X: |
< ><FONT color=#0000ff>#include <STRING.H>0 | B8 n0 w8 m+ S& F' a
#include <STDIO.H>
9 e) |2 }/ t; f" s+ x, {#include <DIR.H>+ h" N& ^; H; e/ Q; }! ?
#include <DOS.H>
3 a( V! v, ]: ^1 Q#include <ERRNO.H>
7 w: j4 A; Y/ |' @: D0 F/ T5 S#include <STDLIB.H></FONT></P>
* C: A& X, E w7 W; A c( ?<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>$ m- Y* l9 T" j6 p1 M' [
<P><FONT color=#0000ff>int main(void)
T1 m. b4 f6 j ]$ F! y5 w{
8 {& w5 v1 `& M. m" r) b. T( f8 Q$ Mchar buffer[BUFLEN]; ) E L& V. z& u3 F& ]
int test; </FONT></P>, ?; m9 _0 ~. ^) U" g, b) X
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); " R+ L& D M4 V2 W
gets(buffer); </FONT></P>) D* B& P! v4 D" l
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
# X( i) H& e2 i# G! Cif(test) ' K7 C% ^, Z) U n+ [: L
{
" \8 g* F# Z* E3 ] v9 o, @/ }printf("DOS error message: %d\n", errno);
8 k6 O$ ^# [0 J2 u, Q$ d3 w/* See errno.h for error listings */
3 U2 o+ ]- }" K( R9 fexit (1);
! t! o; A" }3 g* v8 q1 x) U7 y} </FONT></P>
0 L. k/ }- r/ C& x9 m<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
9 T$ i% H7 N2 W6 j' `( Eprintf("The current directory is: %s\n", buffer); </FONT></P>
8 v1 Q" W/ H% _% p! }" C% ^: h! F& q<P><FONT color=#0000ff>return 0;
( t9 z# J! f- j3 X% V2 c}
; s- p. L5 @" u& F</FONT>
% a" j; S" Y/ T3 O8 J
8 P- x7 s. S3 }7 j" V9 J/ c$ C! _</P>& l' ], I" l( ? D" l9 P
<P><FONT color=#ff0000>函数名: bioscom </FONT> n) |2 U% {4 z! c3 S0 S6 Y- h% O- V
功 能: 串行I/O通信
4 D" |% L' d' f( b) J用 法: int bioscom(int cmd, char abyte, int port);
9 q7 C+ r3 x; s# Z5 [程序例: </P>
; P/ ^( Z/ o- d( E* N. T: F* v<P><FONT color=#0000ff>#include <BIOS.H>
) S- o2 U6 t! P8 n6 ^5 q$ r+ L" Z#include <CONIO.H></FONT></P>
0 W' E9 H l8 |" l4 W. t1 |<P><FONT color=#0000ff>#define COM1 0 4 |, O/ \1 @2 l: H. o
#define DATA_READY 0x100
1 T1 T- P7 i8 p6 f- n#define TRUE 1
- ?; o5 I& A5 b3 e4 T#define FALSE 0 </FONT></P>
& p# I4 e; \3 B6 Y; s<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
8 C% Z( a9 Y; @5 }8 }, I<P><FONT color=#0000ff>int main(void)
' H; e! z$ n% r3 G* U! S{
, q, M8 K1 `0 Yint in, out, status, DONE = FALSE; </FONT></P>
1 I1 u! H$ | e) }# [; Y<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); ( ^* J. D! y) @
cprintf("... BIOSCOM [ESC] to exit ...\n"); - N/ k9 V9 J' K1 f
while (!DONE) 7 @. }4 I& a# d6 s! ?) t- ?
{ ' s" R+ n6 ~3 D# ^3 k/ s- a p
status = bioscom(3, 0, COM1); $ ~/ E" `7 z% {; J0 x/ ^3 ~
if (status & DATA_READY)
0 |% |; P0 L4 Q8 l9 |9 S! h4 @if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) ( X( i6 o+ W8 M2 M
putch(out); 6 V) Q3 _, F# Y4 S2 i
if (kbhit())
9 W9 _3 H6 J+ A ^& n0 H4 n{
) j5 j# d) K9 \# oif ((in = getch()) == '\x1B') " h- \1 y$ b+ ]4 m" c
DONE = TRUE;
- [8 T5 `8 f) r7 W2 }bioscom(1, in, COM1); V. a9 d- y/ N% y& X# u
}
$ y7 f9 |$ Q% e3 j. Y! @}
5 j! d, S& ~" `/ dreturn 0;
' @5 b4 J1 D% h' i' z* M& f/ r} </FONT>
3 \) j: A) c9 i1 I; A% v4 D$ q4 W
4 X0 x, l/ D$ x" {+ d
</P>, z8 F- z# b# G+ N: [" P- T9 T
<P><FONT color=#ff0000>函数名: biosdisk </FONT>; h; J. t9 t9 p; u
功 能: 软硬盘I/O
' J" N, z# Y- N. W) ?; l用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
8 Q0 s+ G! _7 d6 H+ Pint nsects, void *buffer);
9 o' h0 z' u. Q7 t0 J程序例: </P>
% ]# L# T7 d3 D, W- ^. E<P><FONT color=#0000ff>#include <BIOS.H>' A: }4 P! T) s# m/ t! `
#include <STDIO.H></FONT></P>+ V) Q/ D. [& _& p& m1 i
<P><FONT color=#0000ff>int main(void)
7 E( O$ g8 K# f. Y2 b9 V8 p3 C{ 3 `2 ~" Z$ m. _" `; `7 x8 s8 C9 A
int result; 6 Z# Z- J" b+ E
char buffer[512]; </FONT></P>" B: M7 `4 B: V( t
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
4 X1 U! ]- h8 gresult = biosdisk(4,0,0,0,0,1,buffer); 6 D% I+ d9 ?! N2 ^1 F7 O |
result &= 0x02;
3 x+ { t$ k" f: H. k- w' e O(result) ? (printf("Drive A: Ready\n")) : & o5 Z$ n& z& T; u" f
(printf("Drive A: Not Ready\n")); </FONT></P>. `2 }$ u( d6 h2 Q' Q, |8 V
<P><FONT color=#0000ff>return 0;
1 p" q, M7 y. D- b! f} # U( `4 r1 Y' f2 z
</FONT>: M" M$ K" u4 a1 W( |
5 l0 h6 f) t3 m& s# S( H; L</P>
1 c: ~% Y$ i6 d4 @3 [1 Y1 f<P><FONT color=#ff0000>函数名: biosequip </FONT>. A6 ^5 z9 q) {
功 能: 检查设备 6 M; t$ {0 \! o, `
用 法: int biosequip(void);
k, F6 n$ ~+ w程序例: </P>; S8 _8 v0 @3 ^. |* ~9 o/ m& S( W" t
<P><FONT color=#0000ff>#include <BIOS.H>
% o; X1 r! \" R( _- i#include <STDIO.H></FONT></P>1 E' y3 D) g/ \ _
<P><FONT color=#0000ff>int main(void) ; h! [: b8 @4 X% V6 X& D/ J
{
. J" l/ T' D6 i+ {int result; 4 i6 t& _: }% }8 a
char buffer[512]; </FONT></P>
* S3 R, s1 G0 r$ k' `! A) d5 u<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 5 p" q6 }% ^$ w
result = biosdisk(4,0,0,0,0,1,buffer); 7 v. Z8 [8 p& O
result &= 0x02; . {4 k$ l+ g6 U6 k# x) k# K
(result) ? (printf("Drive A: Ready\n")) : ! W! w' ^6 H7 v F1 p& q4 x
(printf("Drive A: Not Ready\n")); </FONT></P>, j4 K& z" z. T. M1 _4 i
<P><FONT color=#0000ff>return 0; : F' R7 u- `4 O( p
} 0 x7 \) \4 ^9 L/ C. G( ^* p
</FONT>) N8 m* Q" G" ]+ t- o, n' f
* ?% Z1 _; C) ^$ t# q) S</P>5 w) _; f/ e8 H3 q* a$ d, i
<P><FONT color=#ff0000>函数名: bioskey </FONT>( W. b0 a. ^' l, \( r n" y
功 能: 直接使用BIOS服务的键盘接口 ( e* b) _% L1 y* e
用 法: int bioskey(int cmd); + ?( ?- \# ?# h
程序例: </P>
) _. ?* |4 e2 a1 M) A<P><FONT color=#0000ff>#include <STDIO.H>6 y x, [. I* u1 M9 a
#include <BIOS.H>8 b0 {! w2 }7 ~% r
#include <CTYPE.H></FONT></P>3 s$ E ?1 ~3 p7 O k' L
<P><FONT color=#0000ff>#define RIGHT 0x01 / p; |1 J2 z0 O4 T7 m
#define LEFT 0x02 $ p+ @/ Z" ~& C; D
#define CTRL 0x04
0 P3 D& F, V0 Y; }* g, I#define ALT 0x08 </FONT></P>. I9 q, n9 u1 @* R0 w" i
<P><FONT color=#0000ff>int main(void)
6 _5 L. f) ? a( W: n- I{ - R$ ^, d" V' A4 o
int key, modifiers; </FONT></P>! H' o2 D4 M/ L; x+ \( j
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
5 Z+ c9 g) J! V/ _/ _# x+ {# Owhile (bioskey(1) == 0); </FONT></P>. c6 }5 Z) D( }- U; O3 i
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
& \! G3 \0 J! C( rkey = bioskey(0); </FONT></P>
+ |" ]" k4 k: `. e7 t<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
1 x" _5 E& o6 i6 _0 lmodifiers = bioskey(2); 0 r$ B; f% X* N8 _
if (modifiers) / }$ r% |8 }$ {: w3 y8 H6 N3 x
{ ! ~# M( x1 \9 J( W& q0 \! y! Q
printf("[");
7 Q" [% |1 x, I! l! }" C9 A) x. M! W' Kif (modifiers & RIGHT) printf("RIGHT"); . D: T3 _& T& z2 X2 C
if (modifiers & LEFT) printf("LEFT"); ( |, u* b8 f0 @" { t# S
if (modifiers & CTRL) printf("CTRL");
+ ~9 O! B0 D5 ^) N9 oif (modifiers & ALT) printf("ALT"); ( l: c" \7 u9 v- P4 R3 _
printf("]");
% U7 ]) ~: a7 E+ V; H* B: q}
. o" a f0 @& ^1 u' k- P/* print out the character read */
4 s+ M# {1 H: G3 Z! }1 wif (isalnum(key & 0xFF))
H& x' y* Y Y* c7 xprintf("'%c'\n", key);
) D2 u+ v+ Z2 D# H( T$ u \else
7 a6 }( |) r) _printf("%#02x\n", key); 0 e9 h- l5 S& \( n R
return 0;
/ }% D0 ?4 e3 z} * z3 {: H+ t% K; O* u
7 D+ o$ X3 y p- @</FONT></P>
" f& Z, _$ L; D- m. f- f' J8 b<P><FONT color=#ff0000>函数名: biosmemory </FONT>: m6 ?9 `( u- @( ^3 M: H3 v r
功 能: 返回存储块大小 & @* T, \3 Q1 a& J4 H7 E9 C+ Z# W
用 法:int biosmemory(void); 2 f7 @9 O }* Y L: u
程序例: </P>
6 { D; n# V5 p$ Y9 G<P><FONT color=#0000ff>#include <STDIO.H>7 x2 E+ v5 s, Q( ?4 _
#include <BIOS.H></FONT></P>
* w' D- _0 g& F<P><FONT color=#0000ff>int main(void) % O: W' x/ f" I) T
{ # H% l& F, `2 ?3 |) T6 I$ N" c
int memory_size; </FONT></P>+ |- M. X! j% v+ s( E% t
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ + s5 v. d7 J/ o' }
printf("RAM size = %dK\n",memory_size);
: H, z n0 }& Zreturn 0; ) T) w8 f0 W, S! l
} 2 j( p9 f) C9 @' E( g5 s& i( Y) G3 z
</FONT>6 I; f0 j9 s. G5 ^; c8 D
# Q' g5 q2 p' k3 A% ?" |
</P>
: d% ?$ c% f0 ~, n, O1 X; b<P><FONT color=#ff0000>函数名: biosprint </FONT>; O8 Q4 G' [& T. S
功 能: 直接使用BIOS服务的打印机I/O 6 |- S& F& M' [! ~# L; ~9 ~! K
用 法: int biosprint(int cmd, int byte, int port);
/ e5 _0 a9 X) p/ Y" J0 g& A程序例: </P>: ^# D0 V2 \" `9 K$ G) ^6 Z
<P><FONT color=#0000ff>#include <STDIO.H>' A) `+ i; f7 q1 V& j9 L2 G+ J! G
#include <CONIO.H>
: o- O. k% W2 j$ b#include <BIOS.H></FONT></P>
" b+ ]: @! j' Q. w8 m) M2 p<P><FONT color=#0000ff>int main(void) v2 g$ k* }" J" ?
{
]+ f7 r" ^% p" `#define STATUS 2 /* printer status command */ - r, Z2 W% m2 F0 r; Y7 H6 }
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
, [0 y$ Z! E9 w W I<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>/ }/ B9 X" O7 b8 `: }
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
( Q9 z( ~3 m6 J1 ~0 E$ ~5 r) qgetch(); ) F" G D( x" K% z* U
status = biosprint(STATUS, abyte, PORTNUM); 0 F* Z8 P3 }; v, V# y
if (status & 0x01) + ~; R6 Y+ p6 p% P
printf("Device time out.\n"); . X7 L1 n& ?- n" v5 Z9 o
if (status & 0x08) ( G' s- U Q8 \+ `% V
printf("I/O error.\n"); </FONT></P>
5 {) v' ~/ x! s! O2 W( |<P><FONT color=#0000ff>if (status & 0x10) 4 S) ?6 |6 R: ]
printf("Selected.\n"); 2 P9 v: v( r! z, ~$ l) X
if (status & 0x20) ) m9 s4 Y6 @6 P5 i( i
printf("Out of paper.\n"); </FONT></P>
4 y% }( K4 ` L F# |8 N' M/ w<P><FONT color=#0000ff>if (status & 0x40)
- ~1 `8 Q W( m! m1 Cprintf("Acknowledge.\n"); ; X! z9 o$ g$ A. P K2 U; S
if (status & 0x80)
7 Q# \/ m/ u# E7 c; ~2 `( Q+ uprintf("Not busy.\n"); </FONT></P>1 o6 ?. \ z$ b/ E9 @) j& T3 O) y
<P><FONT color=#0000ff>return 0;
* }* C) r/ J1 ~/ [} ) h! u3 Q1 g O3 s6 H8 f+ X! _1 Z
</FONT>" t5 J' ^0 U$ G$ F" U; I
5 s/ A; x7 B8 m! ], [3 S0 E' ]</P>" @ W3 e. h- W* X! M
<P><FONT color=#ff0000>函数名: biostime </FONT>; F. N# n, k; X8 W4 f7 \
功 能: 读取或设置BIOS时间
/ T, |3 E6 }# z/ L用 法: long biostime(int cmd, long newtime); " P9 I' s$ N; S9 H& q. w) t
程序例: </P>
' \8 O' n# g, D<P><FONT color=#0000ff>#include <STDIO.H>8 ~; e! v) p# ?* S7 f; V ]
#include <BIOS.H>7 L3 [+ w) {: b( s- F3 r+ z: U
#include <TIME.H>
4 e2 t; V% c0 @ z: I#include <CONIO.H></FONT></P>
' h" L4 |6 m% Y# U. s& U! @<P><FONT color=#0000ff>int main(void)
% R7 F- b% `4 `% T6 D! b, L$ i{
& K/ I) {8 U$ J1 r, l( t2 Slong bios_time; </FONT></P>
, d2 C6 {& i0 o; s, e<P><FONT color=#0000ff>clrscr(); 7 _" R' a% v7 q; m1 Q# b
cprintf("The number of clock ticks since midnight is:\r\n"); 8 W K2 M& u( N( s: J0 N7 _
cprintf("The number of seconds since midnight is:\r\n"); 4 D5 Z. @: |* |0 I- O
cprintf("The number of minutes since midnight is:\r\n"); - b; W, c+ Z' Y$ L# F0 ^0 e
cprintf("The number of hours since midnight is:\r\n"); 5 M+ [, C1 Q- t* U2 T
cprintf("\r\nPress any key to quit:"); * V% x: c' a" N! ?3 s
while(!kbhit()) 2 [% {/ X9 J# R3 P
{ [5 A/ h3 } a( F3 p Z
bios_time = biostime(0, 0L); </FONT></P>
6 u2 U% E' x& C: a+ O; p<P><FONT color=#0000ff>gotoxy(50, 1); 7 y3 }) y u: p( S
cprintf("%lu", bios_time); </FONT></P>
0 A2 E: m+ Z1 q: M, n+ N<P><FONT color=#0000ff>gotoxy(50, 2); 1 C# w5 C8 G) p( @
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>- U' t$ Z( N% Y- D) h6 I
<P><FONT color=#0000ff>gotoxy(50, 3);
- Z! @" a8 T; p! Rcprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
8 w6 z" d5 z; T# }( C<P><FONT color=#0000ff>gotoxy(50, 4);
z3 ~) |9 ]# V* ?% y; C8 R+ Ucprintf("%.4f", bios_time / CLK_TCK / 3600);
: W# A* F0 f* J* p, G& u}
" T, T ]) }! M5 Z) z1 ureturn 0;
/ n) {# K! d- |8 X} . }+ e6 A- g* ?( g: v2 m' g, Z2 Y
</FONT>
# i' z6 [+ H* @) x5 Y' i
7 `$ k4 g. p% r1 x6 {) @8 U: A</P>) j- v. |; [& `4 v! R7 Z
<P><FONT color=#ff0000>函数名: brk </FONT>
; k9 @0 J: ?' o( V功 能: 改变数据段空间分配
/ ]" g8 Y. o7 W1 b( ~用 法: int brk(void *endds); % q! i, g* {! j" S3 g
程序例: </P>* n5 l1 r" o. S4 G
<P><FONT color=#0000ff>#include <STDIO.H>/ q7 j3 }+ ]5 t( |8 Q9 {: z+ f
#include <ALLOC.H></FONT></P>
* ^' t3 F+ [1 z' S<P><FONT color=#0000ff>int main(void) , |; ]) C3 N% D, C* Z
{ ( K; I) @# r$ S ~$ S8 F) x, R
char *ptr; </FONT></P>
% t4 l2 P. ^3 y( ^" b! l! J<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); ) }6 m' K! l7 I p6 B9 q4 x' x
ptr = malloc(1);
8 o# g y( F. s9 Z& {; ]9 S/ w3 rprintf("Before brk() call: %lu bytes free\n", coreleft()); & A5 [- f2 L: |
brk(ptr+1000);
1 j1 X, W$ k& S5 t3 e( n0 mprintf(" After brk() call: %lu bytes free\n", coreleft());
8 } t; S& H! Jreturn 0;
" B m* ]4 b5 `# z3 l3 p}
5 `3 y2 ^- ~- \/ C
$ x0 \7 [4 i, V# L9 P" S4 s</FONT>4 B- U @( f# A, E! ?0 V
</P>+ y) W& y7 O' i) q" f( n
<P><FONT color=#ff0000>函数名: bsearch </FONT>
& w* i- U7 }$ C) e- [% m功 能: 二分法搜索 : ^+ `4 `: M/ F0 Z" @% i% I& K
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
# M/ b$ ^* P. x* n3 \8 gsize_t width, int(*fcmp)(const void *, const *)); $ x# J6 z5 Y; i
程序例: </P>
+ J: J3 l$ l7 C" W$ R0 v/ V<P><FONT color=#0000ff>#include <STDLIB.H>) x* J( t/ O0 J1 @/ G
#include <STDIO.H></FONT></P># z' ^/ S* ?- f1 R( ~
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
/ U% T' W, ~9 k; Q- _' F9 s5 ^<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
6 B- e9 `1 G! F/ W0 \& M<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) & q2 \: t) X2 r' V; ?
{
2 t0 S! k+ \; m7 J% f I, d9 kreturn(*p1 - *p2); 4 i1 V0 b) ^: x
} </FONT></P>8 ^- M9 {; d4 ]; j, ?4 ]
<P><FONT color=#0000ff>int lookup(int key)
% a4 {8 C/ ~: S% A3 c5 f{
+ p( R# R+ a2 X# @8 m7 r& Pint *itemptr; </FONT></P>
( q2 _% L$ q8 D7 K<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) + N; d/ I D5 G G3 N
is needed to avoid a type mismatch error at
8 \! k& E8 r) l c' D1 ]( L3 C- H" Pcompile time */
: r3 N. k+ k, ~& J- J7 `itemptr = bsearch (&key, numarray, NELEMS(numarray), & w( | Y" [8 W8 o0 z8 T
sizeof(int), (int(*)(const void *,const void *))numeric); $ ~% r$ b* p7 J) e7 i" P
return (itemptr != NULL);
9 R* r8 y, j' k, @8 {( q4 J} </FONT></P>+ \0 d B8 }# w5 I
<P><FONT color=#0000ff>int main(void) / J( H8 [9 o9 j, y$ {
{ 6 e9 ] t$ z4 f) q; t
if (lookup(512))
+ m9 s' p" Z5 b! `) a, Rprintf("512 is in the table.\n"); 1 d+ q+ m- g$ Y5 J R. w8 d
else
3 q% z5 i4 D. k4 g9 ]6 R1 G1 iprintf("512 isn't in the table.\n"); </FONT></P>
8 I* E o" x& y! J: ?9 [2 S<P><FONT color=#0000ff>return 0; - i4 W: v( m$ s+ r6 [$ q
} </FONT></P> |
zan
|