- 在线时间
- 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># d7 |" T4 F/ {1 }) a! y
< ><FONT color=#ff0000>函数名: bar </FONT>
8 B9 D0 k5 _) S8 N功 能: 画一个二维条形图 , S1 e- Q7 l- D! \0 s3 l
用 法: void far bar(int left, int top, int right, int bottom); 1 a. k: t: V; z# F( z! k0 I
程序例: </P>
3 D- C$ u% m0 j$ j: E" @< ><FONT color=#0000ff>#include <GRAPHICS.H>+ v/ S7 J- I# D4 |) L. b& C
#include <STDLIB.H>. Q* Q2 i" ]. j' C1 f
#include <STDIO.H>! ~" p! a4 U' W! L* ?
#include <CONIO.H></FONT></P> [7 i; X0 z+ Q* L4 N5 {
< ><FONT color=#0000ff>int main(void)
, k: ?; c( T$ g4 `$ e{
1 r5 R' i' d5 e- p9 l/* request auto detection */
4 b+ v3 @0 N0 j8 N0 l: Eint gdriver = DETECT, gmode, errorcode; 1 i" o: e, o1 p
int midx, midy, i; </FONT></P>
* J) W5 c: [- x7 x- e% V2 V! K2 X< ><FONT color=#0000ff>/* initialize graphics and local variables */
, A- p2 ?' {7 y3 o( A+ pinitgraph(&gdriver, &gmode, ""); </FONT></P>
0 \& H- L5 v% @1 B6 @9 Q0 Q5 }< ><FONT color=#0000ff>/* read result of initialization */
! }) n! D# p. perrorcode = graphresult();
8 }0 h$ c* m; V0 z0 D) iif (errorcode != grOk) /* an error occurred */
/ _" e8 f. S3 F: O' y3 i{ ( u4 v* S; O# X8 f8 x2 K' Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 {1 V9 t! ~' D$ z& s9 Wprintf(" ress any key to halt:"); 1 y* J, }5 I: |# |8 t/ u7 ?
getch();
" j) E5 |" `" f1 B; G; ]/ Gexit(1); /* terminate with an error code */
+ `8 |# ~! \5 H} </FONT></P>% T( [8 d! r! @% Q
< ><FONT color=#0000ff>midx = getmaxx() / 2;
( k/ I9 ^9 j+ z* amidy = getmaxy() / 2; </FONT></P>
: `/ Y1 r: g$ R d& X o! i( c. o< ><FONT color=#0000ff>/* loop through the fill patterns */
$ x. b& m* s# N1 s' Ffor (i=SOLID_FILL; i<USER_FILL; <br i++)> {
" T5 J# v* G; I1 f( n4 m$ {$ X" K/* set the fill style */
; s! V6 c" {; @* t" Msetfillstyle(i, getmaxcolor()); </FONT></P>
2 e! t( Q4 a, A" F; M( ]; c< ><FONT color=#0000ff>/* draw the bar */ # q/ a- s3 y( x5 w7 P; F
bar(midx-50, midy-50, midx+50, " i6 v B+ n L7 Z$ ^3 J5 M
midy+50); </FONT></P>
$ k+ c* ^" b ?& [/ H. j* q- k< ><FONT color=#0000ff>getch();
! N. Y' R. I' I0 z, v) s} </FONT></P>
" e0 A* x/ ^( Z5 y: a< ><FONT color=#0000ff>/* clean up */ 6 J8 ` l6 @: t9 Q" [
closegraph();
/ U& C$ w1 ~7 P( Breturn 0;
. c8 b( J& ?( w! [0 j7 z% B} </FONT>( h; D- j7 w% L3 T1 K
% ]6 ?- Y+ _/ ]0 E
6 a) G: [' S F9 d# t</P>
; Z$ R. x7 y* d1 r. E! ?# x< ><FONT color=#ff0000>函数名: bar3d </FONT>) u& R* }6 x5 `3 f0 Q9 I2 K
功 能: 画一个三维条形图
5 N+ Q" Y: M9 A+ r' Y. S) Q* ?6 m用 法: void far bar3d(int left, int top, int right, int bottom, ( v( ~, x& C0 U- D0 R! ^
int depth, int topflag);
" L0 C( O( o/ W6 K3 M3 J8 q程序例: </P>- @, _5 w$ q* t. u. i
< ><FONT color=#0000ff>#include <GRAPHICS.H>
1 \6 |7 w$ g. g4 q t#include <STDLIB.H>) E' ?$ }- A8 q. I! D5 h
#include <STDIO.H>
- r1 C' P$ o3 a#include <CONIO.H></FONT></P>5 L; Y) Z' Q) ?. b6 V
< ><FONT color=#0000ff>int main(void)
* o8 N2 C1 Y) _1 q( t" u{ 0 J% E7 [. J1 m- L& f8 i* ]
/* request auto detection */ 1 n& w, T. Z" _# B6 m8 A0 F+ @
int gdriver = DETECT, gmode, errorcode;
, N2 f F4 W- B# G; H3 i" Sint midx, midy, i; </FONT></P>
2 h# e' W, d8 t; p A k( B< ><FONT color=#0000ff>/* initialize graphics, local variables */
7 t! R$ C3 {) Z5 h& F. f$ Finitgraph(&gdriver, &gmode, ""); </FONT></P>
0 C/ \ e# L; Z$ r: X< ><FONT color=#0000ff>/* read result of initialization */ % b3 I x: r! r* J
errorcode = graphresult();
, x+ S9 d/ U) O8 ]$ [1 H. Z0 hif (errorcode != grOk) /* an error occurred */ : g" ?: n9 l' @; W7 {, | _
{
* H3 X( l# Q2 I) y. W Q2 ]printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' D, z8 N) j" O- N
printf(" ress any key to halt:");
: J6 s/ R7 a0 y" u% D' ogetch();
4 Q: P( s9 @% a S3 hexit(1); /* terminate with error code */
) J9 P" ^) P1 q0 {} </FONT></P>( V O7 T5 U2 O, p0 e
< ><FONT color=#0000ff>midx = getmaxx() / 2;
* i7 o& j& ?- L7 [/ d. Dmidy = getmaxy() / 2; </FONT></P># D O l. R" ~; x) Q
< ><FONT color=#0000ff>/* loop through the fill patterns */ ; ^8 \( X$ D" x; n6 S
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { - x- @, u4 j6 L' M
/* set the fill style */
1 U# `$ e' y7 v) `7 Z: _; v) f3 U/ Msetfillstyle(i, getmaxcolor()); </FONT></P>) y' e) K9 ]4 ]; T: g
< ><FONT color=#0000ff>/* draw the 3-d bar */ ; y% i/ C$ b1 Z) n( g
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
' V# i1 l& B) P0 d# G a, `& U< ><FONT color=#0000ff>getch();
# G+ O `/ b& i; Z5 C, I. v} </FONT></P>
/ u6 ]0 ^" K6 a# ?3 K8 [) Z5 `. {< ><FONT color=#0000ff>/* clean up */
1 |4 {: ~* ^8 E4 Y; Oclosegraph();
( v2 m6 C2 ~" i, G6 u \$ w: Ireturn 0;
+ t6 l9 Q0 ~3 Q2 {} ! |$ S7 {$ f4 e; H
</FONT>
/ N5 b' y+ K0 U* [* s/ F
' V' |5 E$ U3 P+ m</P>9 l& B' H0 k: q/ k
< ><FONT color=#ff0000>函数名: bdos </FONT>* E$ s& K9 D6 N8 F: q# ]4 _
功 能: DOS系统调用
" [7 M+ U2 V+ u, V! Y0 C8 ]1 l用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
. U2 ~* c1 S9 u( a8 O+ a) ?程序例: </P>
: ]5 `8 }! J& g w1 I' X& t4 |< ><FONT color=#0000ff>#include <STDIO.H>
9 p6 R8 N: K7 Z$ J) f#include <DOS.H></FONT></P>) |4 d+ A' h4 h5 x8 u: J( ]
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ % ]) o' ]9 u& h+ g7 H2 m1 l4 s; h
char current_drive(void) " v" l# n% ^2 |' I) ^4 U0 O& O4 w
{ 5 y6 o6 m+ @) U0 K
char curdrive; </FONT></P>
" M1 l8 D& u# q" S8 U+ I& J6 U2 |< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
2 E% G) L. Q& L8 ^) ucurdrive = bdos(0x19, 0, 0); 9 N7 l/ k6 }% R7 Y
return('A' + curdrive);
* L' |2 F: h# V7 q} </FONT></P>
( ]3 B4 M! D! o+ Z. I# u/ o% I< ><FONT color=#0000ff>int main(void)
9 i* h* j9 S- u( Q2 ~3 U{
2 B9 q5 z( o* u" @# yprintf("The current drive is %c:\n", current_drive()); 1 \8 S8 L" ~$ x+ v+ t8 I- B$ T. f$ o. R
return 0; : b/ y5 h- ~# b+ C
}
$ s9 C0 C* X1 Z7 u5 k
; T6 F! B, w5 x</FONT>1 ^8 p# s( b% z( Y
</P>
6 S+ }0 C1 A$ Y1 ~# X' c5 Z- Y7 F9 q, d< ><FONT color=#ff0000>函数名: bdosptr </FONT>/ X; q' s1 G6 M! s& M
功 能: DOS系统调用 ( p Q( b4 H" i3 q
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); : k' l+ d3 K M# y$ s4 _0 A3 Y
程序例: </P>5 ], E( s7 P" B+ Y
< ><FONT color=#0000ff>#include <STRING.H>
4 M! E1 C' s8 Y7 I' L- o) M" C( H#include <STDIO.H>
: H4 g: T. @7 k( E& x4 [#include <DIR.H>
1 h/ l3 ]7 e: O8 ]0 s#include <DOS.H>
; T. F# O# r% y: x# F: g#include <ERRNO.H>
% g( ~1 Y3 S7 [0 e. O) Y; y, `#include <STDLIB.H></FONT></P>
/ J$ m0 |+ B1 e, l, X! D7 Y) g<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
. `+ Y# K) D. c8 L* D<P><FONT color=#0000ff>int main(void)
0 }: C& C- u# w1 T$ Q{
; l( L! _/ |% L8 r" H6 Xchar buffer[BUFLEN]; " a& Q' w# z: q1 G, P
int test; </FONT></P>
& B$ h. i- d& W; X2 V" C3 p5 l3 s<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); \. k" ?- o/ h% S! Z6 Q
gets(buffer); </FONT></P>
2 P0 N: ?1 l/ Z& `, S4 Y7 x<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
# a Z2 H, O& O0 `* Cif(test) % `1 t0 t( A4 E: z' D' D
{
4 ^% k. e& @1 q" C: l# |2 Aprintf("DOS error message: %d\n", errno);
* g1 A, b# ]2 N( L/* See errno.h for error listings */ 7 I% g# d Y0 M8 N1 @6 q/ l. [; I
exit (1); 2 _3 X! t4 \7 g4 V" q. A0 |
} </FONT></P>
3 E6 }: R* E3 z; M, z* S<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); # e' h! d, f H o ?, W/ d4 C
printf("The current directory is: %s\n", buffer); </FONT></P> L U# m+ E3 n1 W
<P><FONT color=#0000ff>return 0;
) }) j( I- X& ~# }5 O* e5 P4 P& j}
p" Q0 j/ ?" q</FONT>" U' `- z/ W* M g1 ?7 A9 @0 g
/ k& B; I- I/ w) c</P>
% @$ C0 G. s: |2 r6 D<P><FONT color=#ff0000>函数名: bioscom </FONT>/ `; O5 h( w: S
功 能: 串行I/O通信 - b( S$ G9 p2 ^$ g6 h
用 法: int bioscom(int cmd, char abyte, int port);
5 h! m4 U8 F0 l程序例: </P>% ~3 L& ~9 p$ @ ?* F) M& Q8 U
<P><FONT color=#0000ff>#include <BIOS.H>
; _2 g, ?' Z W7 v, B: x' H" b9 J#include <CONIO.H></FONT></P>) N# x5 c2 {$ K' F F, d+ O
<P><FONT color=#0000ff>#define COM1 0 ; v- g6 j+ U5 ?3 Z
#define DATA_READY 0x100 4 H7 {3 l7 L6 O( N3 V% A
#define TRUE 1 6 t ^; N) V- y1 W
#define FALSE 0 </FONT></P>
. N; R8 b+ a/ h& R' g3 z" _2 L<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P># s6 S i, m8 v4 J% c
<P><FONT color=#0000ff>int main(void)
4 j& @! q6 {. A. d1 u8 C d) C{ : Z. v; Y4 g8 q' L, ^
int in, out, status, DONE = FALSE; </FONT></P>
$ \' n4 P3 v @6 X<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); - E! ]) D/ K! L7 h
cprintf("... BIOSCOM [ESC] to exit ...\n");
& X( i2 Z* S) f0 u5 U" cwhile (!DONE) . ?3 ]2 r6 y' y3 J0 j
{ 1 u0 D( R& a5 X& I7 n' q$ C! G6 I
status = bioscom(3, 0, COM1);
4 @% n$ x- a$ t; v( yif (status & DATA_READY) . o# H4 Y7 h& \
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) * p5 q) r$ t, q# A) [. t, U/ D l
putch(out);
8 E; W1 I) ^& ~: Q% }$ T5 z2 Eif (kbhit()) 5 W- _7 @5 ]5 x/ e# A
{ 2 D$ R) c) R* u1 Z& E9 F
if ((in = getch()) == '\x1B') : k/ y2 [2 X0 s! D) M) f
DONE = TRUE; ! U: b- x; @' Q' f
bioscom(1, in, COM1);
m9 Y( ]2 g/ O& O) j8 n, ?} 1 b( `/ {! Q& u5 ?. K7 n
} ' }, W- ~( U/ V
return 0; . p% @, S$ L) w8 [" B
} </FONT>/ S2 i$ x- W+ u9 m& [( N, H1 F8 i
+ v, |" M$ v) M* T
' M2 Q; v( o- r9 r) _* _ \9 @; O</P>
( z# P5 o# y3 r" x<P><FONT color=#ff0000>函数名: biosdisk </FONT>% E) Y/ F% [" u( p6 h9 Z
功 能: 软硬盘I/O , k5 \" u+ p4 A. U8 k
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector $ [* s7 E% ?4 Z3 o& r8 \) ~
int nsects, void *buffer); 2 E' W/ p, P/ k# R
程序例: </P>
* c$ L4 s2 X' [2 P0 G<P><FONT color=#0000ff>#include <BIOS.H>- K* P' [5 [+ Z9 ^
#include <STDIO.H></FONT></P>, f$ ~' U# X& R# o; k4 X) X" R
<P><FONT color=#0000ff>int main(void)
2 M9 W2 S3 A% `{ . M* z h: z% b; J/ I
int result;
/ d3 t$ x. G v6 T3 nchar buffer[512]; </FONT></P>
+ ]! F8 x# N: S6 Z<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); & L: d0 o9 [1 \9 }" c
result = biosdisk(4,0,0,0,0,1,buffer);
* X, M g4 u. _: R' D0 k4 Hresult &= 0x02;
q+ F# L: O+ B4 Q: g' L(result) ? (printf("Drive A: Ready\n")) : 6 K8 W/ A* X. Z0 G: s9 {0 r' U" ], p7 z: h
(printf("Drive A: Not Ready\n")); </FONT></P>
: [* k. u& u! C$ H+ V<P><FONT color=#0000ff>return 0; * }3 t- C" F" w% k' V) U+ p' I
} 6 P" u( }! ^# t3 ?, Q" R4 g
</FONT>
8 k7 e) m1 N+ x: c4 P$ x0 l
3 d* e7 ]' T) V: }; f! ^</P>; n" |, B5 w, N: p
<P><FONT color=#ff0000>函数名: biosequip </FONT>. @" F! i$ J/ h
功 能: 检查设备 . h0 a e, t" l6 p3 q
用 法: int biosequip(void);
# C. a. q5 m; r; O; [程序例: </P>+ x5 Z) i: d, ]
<P><FONT color=#0000ff>#include <BIOS.H>, A9 H9 n6 V9 Y/ V7 e6 y- Z
#include <STDIO.H></FONT></P>
* H8 [; o+ L/ A<P><FONT color=#0000ff>int main(void)
- R$ s& e5 e# Q) a& ^3 G$ E0 C{ # Z4 R6 }0 X' _6 z% l
int result; + K$ i. W) j% ?6 k7 M6 U. d/ d
char buffer[512]; </FONT></P>9 e: v& C+ i& o7 M# S+ z2 F) S ^
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); p3 }3 G) w! {
result = biosdisk(4,0,0,0,0,1,buffer);
0 y- U+ A |3 u5 `; _5 u& Fresult &= 0x02;
; k4 |7 ~- e$ J* M* G Q(result) ? (printf("Drive A: Ready\n")) : + S0 ~! R1 M7 x2 I# ^
(printf("Drive A: Not Ready\n")); </FONT></P>
; c* K3 g3 g3 R9 l7 N0 c5 ]<P><FONT color=#0000ff>return 0;
) H* J. h. G( ~2 X4 d, [}
% E! @6 r$ r& h0 V2 K</FONT>
/ l" O6 O. J2 K! N* j# W0 w9 N* A. ^, E
</P>
7 E; `* I! A* d) d! b& i6 n+ w<P><FONT color=#ff0000>函数名: bioskey </FONT>9 O1 m: W' o& v7 \
功 能: 直接使用BIOS服务的键盘接口 8 q) V( ~3 k; S8 h% X/ }
用 法: int bioskey(int cmd);
- H$ d$ F2 L( v: G程序例: </P>
+ m% M: i& }; q<P><FONT color=#0000ff>#include <STDIO.H>: @! I6 N( I) C7 [% q6 Z" r
#include <BIOS.H>) U2 E: ~' J. ]. ~: o6 p4 s
#include <CTYPE.H></FONT></P>' F) \2 y* ^4 x* y( B" \# S2 {
<P><FONT color=#0000ff>#define RIGHT 0x01 : X8 m% T0 C8 N4 L, Y
#define LEFT 0x02 d) B* ~5 v/ _4 `8 M+ d7 X- G
#define CTRL 0x04
% Y, G# s1 [6 H* B. A4 r0 B#define ALT 0x08 </FONT></P>
5 g7 F9 {# B8 Y D<P><FONT color=#0000ff>int main(void)
8 L' N. G- n' F" t* @0 l{ " Q' z) V$ W8 v# ~% O& A. A
int key, modifiers; </FONT></P>) C B9 L# e; F3 ]
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ . s8 l9 ]) c; @& {
while (bioskey(1) == 0); </FONT></P>+ Q! ?/ c$ k/ A. b& ^
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
: `5 K+ L% q/ y/ |& s: zkey = bioskey(0); </FONT></P>) U# `& s" H& S) ~* G5 p( V, C
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
* T$ z0 i5 f5 R7 C; |modifiers = bioskey(2);
& h" Q; P7 Z! r0 C0 v. m4 F2 W: Tif (modifiers)
- {" a* r. `* J9 c. P{ 8 \, @0 h) E5 Y
printf("[");
! b! w) S, v( T" fif (modifiers & RIGHT) printf("RIGHT"); ) \/ k) n* t9 b6 }: B
if (modifiers & LEFT) printf("LEFT");
! Y: Q# _3 L; i6 n9 }* ?" Uif (modifiers & CTRL) printf("CTRL"); 4 \ q5 J2 {& e2 l
if (modifiers & ALT) printf("ALT"); , r1 [# H2 ]& X. K- W! u/ v4 \
printf("]"); ) F! \3 V r7 T6 A
} * E% `/ {, s* a6 n. a
/* print out the character read */
8 ?. P1 e& d. o4 U& S4 r* M) dif (isalnum(key & 0xFF))
, J# X7 V* O& O, }' z$ d2 bprintf("'%c'\n", key);
* m* \# A; d% o7 ~1 Melse ; N+ F! t4 c9 Y& }: [2 K% ~+ S
printf("%#02x\n", key);
- R9 c& |/ b' i/ a3 |return 0;
0 Q( s. O/ T5 d- ?4 S}
& _5 G7 N7 g) D$ g; {) L2 @
4 G" b# h6 L- y* }2 F9 R</FONT></P>) s! s' s" s& ^2 c
<P><FONT color=#ff0000>函数名: biosmemory </FONT>+ ~3 F5 j: G4 H
功 能: 返回存储块大小 % a S' K0 H& g7 z1 V( J- u7 u* E3 J
用 法:int biosmemory(void); W0 ^& y- ^4 V7 o' h
程序例: </P>1 K! x' N! F0 {
<P><FONT color=#0000ff>#include <STDIO.H>0 ?6 C* }9 [! z5 `( s
#include <BIOS.H></FONT></P>
" S' T6 V) m: V/ q u<P><FONT color=#0000ff>int main(void)
+ L, g7 @ }% S{ * D4 O/ `+ N$ b# n8 z, p* A- P
int memory_size; </FONT></P>
8 a4 v/ A& p; g% l3 C# u4 l6 o6 `<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
8 W, Z( t6 s# iprintf("RAM size = %dK\n",memory_size);
7 y ^5 L1 l) z L. ireturn 0; / Y y+ C# Q, J+ x6 s: q
} " O q3 A. Q) i' J
</FONT>% e) I# O# @/ g0 J
* W# j# `: \1 t4 p9 G) ^
</P>
6 y3 {0 [! w' L4 e. |<P><FONT color=#ff0000>函数名: biosprint </FONT>& K1 Q: r( |5 m. P% c2 U* [
功 能: 直接使用BIOS服务的打印机I/O ( D, l- L3 N6 p) f
用 法: int biosprint(int cmd, int byte, int port); + Q2 o) ~* V& P: V1 U' p- A8 L7 a
程序例: </P>
5 b$ C- z1 O# e1 E<P><FONT color=#0000ff>#include <STDIO.H>7 H# B! l1 X) @
#include <CONIO.H>, l4 N7 o; z; Z' }
#include <BIOS.H></FONT></P>6 l& m4 \( w# a1 V E; E
<P><FONT color=#0000ff>int main(void)
5 J# y0 y. @, S{ 1 n# x, u* g) B. q- y: R
#define STATUS 2 /* printer status command */ . A# [* L6 b- F6 |4 J
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>' k8 d1 {) i) m% ^2 ~5 y$ j
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>) e8 h" R1 r+ m+ F9 E
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); n$ v8 i% b7 P; I
getch();
* e1 s7 H9 p, r0 Qstatus = biosprint(STATUS, abyte, PORTNUM); 5 a/ z6 Z2 j. J
if (status & 0x01)
% o6 g5 i- G: p& z, Jprintf("Device time out.\n");
4 k% G7 x3 ^7 k, R5 Nif (status & 0x08) ; n9 }0 w" G! Q; G& T) s7 j+ Q: {
printf("I/O error.\n"); </FONT></P>, j$ ~6 g6 a+ B# A, z
<P><FONT color=#0000ff>if (status & 0x10) ! l% s: V" e6 p
printf("Selected.\n"); 0 F2 c5 O$ z* V! S7 }% }0 Y
if (status & 0x20)
4 u' y4 f( ]+ b3 b0 B. Z" U- wprintf("Out of paper.\n"); </FONT></P>
' p2 c/ |* Z9 r. z( L<P><FONT color=#0000ff>if (status & 0x40) + C% O! X9 Y" D1 ~* @3 R2 z
printf("Acknowledge.\n"); 9 ~! M, Q" D6 c/ Q
if (status & 0x80)
2 r+ v6 A+ u! d! Cprintf("Not busy.\n"); </FONT></P>
5 a5 J! C0 t; y8 I2 \( q& i0 y<P><FONT color=#0000ff>return 0; , A- q. c$ K7 T% I3 H
} 5 f: V- B) z: [
</FONT>) t3 K: Y ^! m8 G1 B6 l1 N
- j& U3 Z4 H( C8 h( y U$ T</P>( @ _9 }0 f. T7 {& @# O7 U& J- n
<P><FONT color=#ff0000>函数名: biostime </FONT>8 f# P: [2 {4 L" J& j3 C7 c
功 能: 读取或设置BIOS时间
]$ e; _% |3 \8 h o2 x0 _" U用 法: long biostime(int cmd, long newtime); ; P) ?8 S! m* y7 x E, }
程序例: </P>. @7 R3 E% w! e
<P><FONT color=#0000ff>#include <STDIO.H>
, r3 T" S2 B' f& a: f0 C9 p#include <BIOS.H>" I0 u" Y& c/ M/ V: i2 f
#include <TIME.H>/ G% b. c# l) Q" U: d
#include <CONIO.H></FONT></P>
1 j. Q6 T7 @* `! x" e0 N6 H* p<P><FONT color=#0000ff>int main(void) - f2 U/ c' D8 z+ p: M1 v& ~; }
{
& ]: p2 _1 p3 u7 l/ {2 C8 C; blong bios_time; </FONT></P>
; s. b' a' n) W4 r" s7 \<P><FONT color=#0000ff>clrscr(); " w0 ?& i7 Y7 k& b
cprintf("The number of clock ticks since midnight is:\r\n");
- R/ _( j: I6 \cprintf("The number of seconds since midnight is:\r\n");
3 q6 P. K. z& _+ [+ i" icprintf("The number of minutes since midnight is:\r\n");
6 y- Y5 ~' _2 ^" r6 @0 w# P+ ?! m" Ncprintf("The number of hours since midnight is:\r\n");
9 a3 l6 K1 e# \cprintf("\r\nPress any key to quit:");
9 |- F9 z' R- _0 o& Iwhile(!kbhit())
$ A, o2 K3 M1 f2 l1 L{ ) J9 M3 x+ g( @ W) U& N/ }
bios_time = biostime(0, 0L); </FONT></P>( k9 i# t, d. k$ E: K
<P><FONT color=#0000ff>gotoxy(50, 1); " E: G) H q P' H; @$ Y
cprintf("%lu", bios_time); </FONT></P>+ u D6 [& j4 k' [7 f Q
<P><FONT color=#0000ff>gotoxy(50, 2);
( ~. z- [$ z$ F! f, Qcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
9 K' k9 P/ T9 I! X9 D" q<P><FONT color=#0000ff>gotoxy(50, 3); 0 F) C' x: P: M2 _, W
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
8 B+ O* W& ~% E+ {, h; N, k<P><FONT color=#0000ff>gotoxy(50, 4); ) y* K: O( p/ ?0 s+ w
cprintf("%.4f", bios_time / CLK_TCK / 3600); . I" P+ ~# p- v3 Q
} ) c6 h# C# I. f0 [7 T% i! C% E
return 0;
! q. I6 s0 Y1 T6 [2 N' r# I1 {} # p8 @- U; I# E
</FONT>
U) C$ d4 m, p* o( C& }
4 i: G; n( Z3 \3 v$ i9 z</P>, j$ n3 N$ |" n" A( b
<P><FONT color=#ff0000>函数名: brk </FONT>
, W% f" |! I+ m% [功 能: 改变数据段空间分配 F8 d6 `& G6 J; c
用 法: int brk(void *endds); 5 K/ t8 S% f3 p/ i. r
程序例: </P>
. E& `8 V6 P* I1 B9 r5 M# D! }<P><FONT color=#0000ff>#include <STDIO.H>
7 x) t0 g' `8 {#include <ALLOC.H></FONT></P>
3 p9 f+ p2 }, u( Y9 b4 {5 t<P><FONT color=#0000ff>int main(void)
2 d. k% c' [- ?2 i) H0 g{
. y% J# o' k1 Q- E L% |9 \' }' Tchar *ptr; </FONT></P>" j3 m: @% h0 ]/ f# N
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); 2 f }: J- L }( c f2 a0 d) T1 G
ptr = malloc(1); 3 M% i5 }2 x0 A6 {
printf("Before brk() call: %lu bytes free\n", coreleft());
* e0 ?% g7 o$ B$ Ubrk(ptr+1000);
0 M/ \* b% F4 M6 ?printf(" After brk() call: %lu bytes free\n", coreleft()); 4 D2 N' w: Q3 ~6 T! |: L
return 0;
6 y% @4 }* B! W/ W; K2 S}
+ C- d4 E6 }: y+ V, t! G3 N9 L) v! X2 e9 @' T. J' X/ c B# M
</FONT>
0 I B' v) q8 v/ @</P>
( t6 n) v# y; ` b( ]<P><FONT color=#ff0000>函数名: bsearch </FONT>: x; C. ^* `& P. p: L$ p
功 能: 二分法搜索
5 Z. M- i% P! w- s4 F/ J用 法: void *bsearch(const void *key, const void *base, size_t *nelem, 1 L0 A# d9 E. d, z
size_t width, int(*fcmp)(const void *, const *));
- x9 O) Q% |# Z! b: T/ [; Y程序例: </P>
: V$ T! y I7 ^1 C% f. U<P><FONT color=#0000ff>#include <STDLIB.H>
( z6 Y& [; {" x& [& ~! w6 a& `#include <STDIO.H></FONT></P>
" e4 f, A" L6 i/ r4 @1 k2 g<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
4 m, M* E3 N& O- \<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
3 F- Z4 V; l8 j8 [) B2 w @<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
7 \8 |4 [! l' v! j. W0 q- S: S6 Q) I{ 6 w) O% J7 J# k$ D
return(*p1 - *p2); ) M' C7 V. D( l! w" `
} </FONT></P>, |- g2 X: P+ s& n6 A$ ?8 M z
<P><FONT color=#0000ff>int lookup(int key)
5 D' e* ~3 K0 v/ `8 H" c{
9 T: e8 M) o1 ~int *itemptr; </FONT></P>; V9 ~5 m1 {+ p" [" {
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) $ x0 D4 [5 Q+ E9 |, t. p7 l( g
is needed to avoid a type mismatch error at 8 x m) I- k8 u, S9 p/ [
compile time */ 0 \0 J# {: p5 P' t
itemptr = bsearch (&key, numarray, NELEMS(numarray), $ @" |$ O3 r/ g, S2 H, q
sizeof(int), (int(*)(const void *,const void *))numeric);
* ~; p2 _: X: K4 b2 k; Q) p" areturn (itemptr != NULL);
- C# V- Y% v$ P3 p+ D5 X} </FONT></P>
9 F9 ]" R8 L- d* Y2 o4 v( Z5 l3 R<P><FONT color=#0000ff>int main(void) . |3 w" R+ s: d+ ?2 P1 y
{ 6 ]- y& C; t3 Z5 H' @+ w" O& ^6 E
if (lookup(512))
4 u+ ^& v+ ?0 c6 p& |: R# Dprintf("512 is in the table.\n");
, r8 C# @( j# V9 q- z( Q5 }else 8 W3 [8 l2 n6 A1 e1 v
printf("512 isn't in the table.\n"); </FONT></P>9 v) k6 N/ ~! U3 g( L
<P><FONT color=#0000ff>return 0; ; ` u- h( o% E; T! J
} </FONT></P> |
zan
|