- 在线时间
- 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>
i( i/ Q. i: h4 b! j< ><FONT color=#ff0000>函数名: bar </FONT>
, ~9 v0 B* f) i; V功 能: 画一个二维条形图 7 L' u1 u( L2 y0 I8 G5 D+ p. l+ E. B
用 法: void far bar(int left, int top, int right, int bottom);
* N* g6 K' V5 T; ~程序例: </P>
% o: R5 \- [( J2 @$ `< ><FONT color=#0000ff>#include <GRAPHICS.H>/ N. r% G2 ]( E5 W; T
#include <STDLIB.H>
, T9 s2 x- _& D, f#include <STDIO.H>& t! ?7 e o+ K& b( `7 r; d$ n
#include <CONIO.H></FONT></P>
4 U' V2 k( R& i0 J9 v< ><FONT color=#0000ff>int main(void) # _; L$ H% m0 a
{
1 u, U( C+ O* A/* request auto detection */ * S5 {/ P4 s4 v# V0 u$ x
int gdriver = DETECT, gmode, errorcode;
. J% ]2 u. P( C2 d2 i# ^int midx, midy, i; </FONT></P>
' }; o$ p& N# V0 n& R/ ?7 o$ {< ><FONT color=#0000ff>/* initialize graphics and local variables */ 1 U/ n- B3 S4 b$ n3 j. g0 p- f5 p
initgraph(&gdriver, &gmode, ""); </FONT></P>
( c2 C" G4 C$ I2 t! v- Z! |< ><FONT color=#0000ff>/* read result of initialization */ # m& x; A5 S; C; [
errorcode = graphresult();
. u. h/ K4 ?* ^- Wif (errorcode != grOk) /* an error occurred */
6 | U8 l7 K( c{ * `8 s) q7 O8 w& E; y( F& g
printf("Graphics error: %s\n", grapherrormsg(errorcode));
: q. l# _6 t, V0 x; O! {printf(" ress any key to halt:");
3 B$ m: V1 L+ z9 w. Z8 X7 Ygetch();
1 `/ S- h/ h3 ?: P8 s( s/ _4 Rexit(1); /* terminate with an error code */ ( e ^3 ~; t) ~7 C+ G# Z
} </FONT></P>7 ^) V' P+ _4 R; W& k8 W8 f" h
< ><FONT color=#0000ff>midx = getmaxx() / 2;
1 X1 `+ d4 H) d# }' Mmidy = getmaxy() / 2; </FONT></P>
4 [' B7 S& a$ n. ?% D) N< ><FONT color=#0000ff>/* loop through the fill patterns */ ( D& D( Q, u4 w" {! O+ n- s7 O8 ? O
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { ! s% A+ Z+ U( F) N! l# ]4 U
/* set the fill style */ " d, T( p" X( g. x3 X0 ~8 C
setfillstyle(i, getmaxcolor()); </FONT></P>& J4 i5 I# ]6 F- G7 x
< ><FONT color=#0000ff>/* draw the bar */ . \; |" r$ A( U; U+ a, a0 T
bar(midx-50, midy-50, midx+50, 9 [! k3 J* X: Q0 M& t
midy+50); </FONT></P>
# P% @/ [/ z6 R: e< ><FONT color=#0000ff>getch();
7 M; |* y1 m. q+ [# E0 z} </FONT></P>
6 q" @4 U# `! {6 h$ J" { O# ?8 {4 t1 I< ><FONT color=#0000ff>/* clean up */ % W6 r0 j% W- T; @# r. I
closegraph();
7 Z* m* h2 a6 z3 K- W( T1 n6 qreturn 0;
1 l5 N2 [# E1 `9 J' B8 n" ?/ ^: s. W1 X} </FONT>( T6 w& v$ {' a; I: v
6 M! M0 ~7 f9 p' p4 v7 R1 U# w5 k3 w q: ~8 I2 Z
</P>1 R A6 _' F' Z2 `4 g) @9 e, s
< ><FONT color=#ff0000>函数名: bar3d </FONT>" o- v0 l. |. ^! l
功 能: 画一个三维条形图
4 m8 u7 E$ K& I3 v用 法: void far bar3d(int left, int top, int right, int bottom,
. Z5 x6 i; J& b* i- Zint depth, int topflag);
1 m) y/ E9 G4 e程序例: </P>2 B- ?8 `2 Y# T3 R0 a$ V# A
< ><FONT color=#0000ff>#include <GRAPHICS.H>
+ \ Z9 r$ `2 R#include <STDLIB.H>
. }- y4 X, w; h#include <STDIO.H>6 P9 F m* `; r A! y: P9 h; M
#include <CONIO.H></FONT></P>1 O4 I5 ]2 x) T/ v
< ><FONT color=#0000ff>int main(void) 8 i2 z- C2 H5 Y% G. S% P9 Y
{
$ z" f) Q$ R; F% r2 @. l- @/* request auto detection */
r4 D$ B) d0 t5 B- R, f' P0 Xint gdriver = DETECT, gmode, errorcode;
' c. I% u1 m" u% Z* I7 q# D# T- Vint midx, midy, i; </FONT></P>: Y2 `0 e1 N% ^3 k3 h. a% A. C1 j/ {
< ><FONT color=#0000ff>/* initialize graphics, local variables */
' C' V. x. {. a0 ]4 zinitgraph(&gdriver, &gmode, ""); </FONT></P>
8 G9 P* i: I% E, K/ R< ><FONT color=#0000ff>/* read result of initialization */ ! g! ]+ O$ J: Z1 Q+ l* L5 @
errorcode = graphresult(); ) ?' I0 Y9 v+ X- i( |( F
if (errorcode != grOk) /* an error occurred */
3 l8 e0 ]% T0 l7 T4 G' z7 x% Q2 H{
1 J r4 u3 \; ?7 @5 m; l4 Q, Lprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" Y3 L: A6 v7 W) g. Q- w4 f! p& Bprintf(" ress any key to halt:");
" M+ v3 j1 F3 ?+ M) dgetch();
4 } _ v2 ]5 T3 \4 Kexit(1); /* terminate with error code */ ' ]/ m7 h, N/ ~- A
} </FONT></P>+ G. _: Z2 g/ s' G* ?
< ><FONT color=#0000ff>midx = getmaxx() / 2;
9 X \: a$ }% W& Fmidy = getmaxy() / 2; </FONT></P>
4 ~1 G. w7 g; R& C2 R< ><FONT color=#0000ff>/* loop through the fill patterns */ . q6 S; z# {1 C) F
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { $ W. A7 K. D/ y% U1 N7 h$ ]8 q
/* set the fill style */ / @4 Z% m' j" ^( S) A
setfillstyle(i, getmaxcolor()); </FONT></P>; p* e' [* l- |0 _* q. F" b
< ><FONT color=#0000ff>/* draw the 3-d bar */
$ k) Y0 Z+ p r- k3 G( V" nbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
, N! [' g2 N; ^) ~$ C; F6 V< ><FONT color=#0000ff>getch(); ! q: Q G. V# o' J6 H& Z
} </FONT></P>. C6 F! X% M2 H2 C2 s
< ><FONT color=#0000ff>/* clean up */
4 k2 G+ v8 @0 k+ [6 _6 g, c1 hclosegraph(); 0 ^6 c* l# f% }+ J$ d8 M
return 0; + g. o1 Z" `: h$ V. u$ M
} - Z* j/ T! J. \2 V. r+ Y
</FONT>$ j$ a5 R( n' U$ r( {$ H9 K, L7 U
* x& @7 F* F! m, R2 o" B4 i
</P>; p+ {$ q" B0 `! \) z0 Z8 o
< ><FONT color=#ff0000>函数名: bdos </FONT>
( }' c0 g: e- q* ^* y" ~功 能: DOS系统调用 % a8 m& S% R1 T/ B
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
* }! ^7 d6 D4 e程序例: </P>
1 V% D$ D4 `; [ b< ><FONT color=#0000ff>#include <STDIO.H>9 f R% C- `8 P3 g
#include <DOS.H></FONT></P>8 a" T) U: b$ R
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
* Z6 ^, a0 t" W: Jchar current_drive(void) + ^# q' {0 W& I( [/ I: O
{
: I; m1 Y- e Mchar curdrive; </FONT></P>- k. S Q! B/ {, d& m7 E/ Q8 t( S
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
2 K* e" \8 m! |0 S+ icurdrive = bdos(0x19, 0, 0);
* R, H6 s) ` |0 H6 Wreturn('A' + curdrive);
& _& F7 `% F0 u, N. C3 e} </FONT></P>
. X4 {& \: _9 a/ S< ><FONT color=#0000ff>int main(void) $ ^+ Z1 J2 Q! l. f6 K
{
2 S# G2 e6 R# _. I7 i- ]% |2 lprintf("The current drive is %c:\n", current_drive());
' \- A1 c9 x* [0 ~+ }5 h: G0 V: Freturn 0; % Z( m) l7 K+ T' \
}
; c; I( v) h( c. r0 @1 U8 Z& w Y
/ F; ?# B: X. B( Y</FONT>
6 e: K0 J; I r' S( I% o3 S$ F</P>
+ N7 U. J! h1 P1 Z4 T9 v+ u< ><FONT color=#ff0000>函数名: bdosptr </FONT>2 I, I* h V$ Q7 A3 f+ l* c$ M& ?
功 能: DOS系统调用 : f. I( v1 D* B9 C, w1 g9 z
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); ( Z& [* m* e8 {: L: I
程序例: </P>) k8 V$ O3 h: P V
< ><FONT color=#0000ff>#include <STRING.H>, ~5 R- @, M8 {. P
#include <STDIO.H>
# |9 g( G2 v9 N6 F7 T7 ]#include <DIR.H>$ j7 i" N3 P' R' ?
#include <DOS.H>
( R/ H( `: f3 V#include <ERRNO.H># J# G% G7 m z }$ F" Q
#include <STDLIB.H></FONT></P>
: J% M% J: A6 c$ y$ s0 O* W* J! B<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>0 b5 q2 G) w8 p; _) K. T6 ~* f
<P><FONT color=#0000ff>int main(void)
. T$ [1 N, q# }1 g K6 L6 ^{
# F0 p" l- m: e, E/ `char buffer[BUFLEN];
2 _! d {( P$ s3 Q8 x8 ?# Jint test; </FONT></P>
U4 |" f5 l: h; g<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 8 G$ n1 t9 }6 i6 O8 m: K0 {
gets(buffer); </FONT></P>
6 @1 v- _# Y9 p* h4 g1 z" d<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); ' L7 U- e0 f; h* }) b. Q
if(test)
; [+ S0 B9 W& q8 E s5 M& U( Y+ I" ?{ L X; n+ \* Z: L& e
printf("DOS error message: %d\n", errno);
- e( `4 w( v4 h/* See errno.h for error listings */ ' u! r" q/ e7 w/ a' {
exit (1);
9 i. f$ Q7 y: @} </FONT></P>
7 o, a4 O- m3 }3 [1 U N<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); # W {& ?$ ^$ G# c
printf("The current directory is: %s\n", buffer); </FONT></P>/ t) n; Z5 F" W+ J
<P><FONT color=#0000ff>return 0;
( v m$ H& w3 `3 ^ C3 z} 6 v4 J6 h1 Q, h
</FONT>
+ U) b: S1 K% t2 G7 ~! `! i, [
$ z( m6 {; O( x</P>* h. H# y5 ~5 l+ v
<P><FONT color=#ff0000>函数名: bioscom </FONT># C- p# I2 e1 w* w
功 能: 串行I/O通信 8 z/ s, Y; O( J( C2 z( g8 y J _
用 法: int bioscom(int cmd, char abyte, int port); 1 p. e2 S+ E' a+ q( }
程序例: </P>
% U9 k' I' N3 s( M* E( y<P><FONT color=#0000ff>#include <BIOS.H>
3 i7 K- m* ]) Y- J J& H: p4 J: k#include <CONIO.H></FONT></P>8 c& O! [5 i0 f" L' B! E! F
<P><FONT color=#0000ff>#define COM1 0
8 E+ H& }* b' L: Z# ^. E( t4 Y/ S#define DATA_READY 0x100
9 u2 s8 p' Q R3 k; I# M#define TRUE 1 2 q1 X; w3 L) S/ G; e- L
#define FALSE 0 </FONT></P>3 h/ t: K0 p. e# p- a2 P
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>4 w/ z7 R5 n/ D% e
<P><FONT color=#0000ff>int main(void)
4 c# n8 k) q% |- s1 k4 z+ e{ 8 x2 U4 ]' f+ i" y
int in, out, status, DONE = FALSE; </FONT></P># g+ T; w" z$ a) K% j5 N' p
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
1 o+ Q) X0 R4 ^7 g# H0 _- Q3 Jcprintf("... BIOSCOM [ESC] to exit ...\n");
5 U" j' V4 L' L! `while (!DONE)
" [2 l) d1 J$ \) {{
e Z5 P' @; @+ dstatus = bioscom(3, 0, COM1);
+ J6 n3 Q2 }1 `$ i$ Zif (status & DATA_READY) , |( Y9 U! o+ i, z; y% O* U
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) ' v) C6 r" P3 f4 r1 }" ?5 F
putch(out); 5 g/ A0 S3 X0 y- \& f
if (kbhit())
/ \$ w+ r% e. {, [- W{
: @$ U! f, X5 ^" |, W3 c* Tif ((in = getch()) == '\x1B')
6 v( w V$ ?$ V; p: sDONE = TRUE;
. T2 A. e% F/ ~$ T# x+ xbioscom(1, in, COM1); 9 M7 F% Q) Q8 n, g9 G6 H
}
* z; m- F' e) C: q$ |} , q9 \5 w4 A& C4 m( D8 S, F8 q0 e
return 0;
: P+ Q/ a+ }5 ?' I} </FONT> o0 [3 V; |+ |9 R- R
/ w L% @7 m/ I8 S, R2 f/ k2 m Q8 v+ s8 s; B
</P>
9 f) F& d# o: E$ z" p7 f<P><FONT color=#ff0000>函数名: biosdisk </FONT>) p/ w& S4 r: r% V
功 能: 软硬盘I/O
- @7 l, ]5 e) e( b5 {# a用 法: int biosdisk(int cmd, int drive, int head, int track, int sector . {) F: T7 R$ |. A% ~8 V
int nsects, void *buffer); $ p: @2 ^$ U4 z2 ^% S2 W0 N. N
程序例: </P>: ~% r; H, T4 n+ Y
<P><FONT color=#0000ff>#include <BIOS.H>
8 r: b( a5 T/ x3 y#include <STDIO.H></FONT></P>3 z( ~% D" B( p- x$ q0 e
<P><FONT color=#0000ff>int main(void)
% {' p! M- Z, O* T6 ~# P3 [{ 3 j8 m6 a& y& V- p$ Q) r5 u
int result; , D4 E* g* b/ V/ O8 x) L. p* S
char buffer[512]; </FONT></P>
. l7 t" Q) _* Q: [<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); " R8 q$ E# r: ]. ]3 q2 l
result = biosdisk(4,0,0,0,0,1,buffer); : x2 v, Z6 ]+ @; k; p
result &= 0x02;
" K% j7 |9 j- k( @) M4 [(result) ? (printf("Drive A: Ready\n")) :
6 ^1 k! W; [1 H(printf("Drive A: Not Ready\n")); </FONT></P>
3 X! l3 I% T7 b7 E/ i( F<P><FONT color=#0000ff>return 0; 2 ]$ M, ^" l I8 x, ^
}
; Q# [4 d' ~9 s0 i W</FONT>" z5 b" C, f+ {, q7 n/ e. ^
& w$ c6 r% @4 P
</P>6 a9 f( ~* s4 [8 Q3 {- F
<P><FONT color=#ff0000>函数名: biosequip </FONT>
9 }; A! J3 x5 }) A功 能: 检查设备 6 D& d4 {5 L* ~( G
用 法: int biosequip(void);
: c! N1 i4 J0 R' ]! u. J程序例: </P>7 N- Z5 b+ s/ F
<P><FONT color=#0000ff>#include <BIOS.H>
$ m7 o3 h. _6 s$ @8 p7 r7 u0 _ h7 j#include <STDIO.H></FONT></P>
+ _% ]/ q! p+ k<P><FONT color=#0000ff>int main(void) , n( H- O" H6 J
{ , \. T. ?, R0 K8 D( K4 d+ n6 c* m
int result; + f1 O& g9 ?6 x7 t* ^. V5 }
char buffer[512]; </FONT></P>/ I# N- O \2 y3 D$ e \
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
3 A3 H: W2 }/ R! ?1 }, rresult = biosdisk(4,0,0,0,0,1,buffer);
! L- i' R7 y# ^" }- T# i) ~0 `result &= 0x02;
* {/ P2 Y' g* [' y6 l(result) ? (printf("Drive A: Ready\n")) :
7 a; {$ w. A9 L; U, t: w(printf("Drive A: Not Ready\n")); </FONT></P>- W& v6 _, w( Z) D1 l1 J3 I: @7 j8 A
<P><FONT color=#0000ff>return 0;
7 g5 o2 _7 c9 ^- x( E+ {- y}
/ V) i3 @/ _. z' L" n</FONT>! e# d* @/ o& O1 v7 ]
& V2 D6 Y6 ]$ g( Z0 }</P>- R4 F$ w+ e/ B2 `. Z
<P><FONT color=#ff0000>函数名: bioskey </FONT>4 _6 d! t& v9 }% i
功 能: 直接使用BIOS服务的键盘接口
, U7 a# X) {5 P! u3 s! h9 R用 法: int bioskey(int cmd);
% E3 B* h0 A+ ^ s1 T' d: H+ j程序例: </P>
: k4 S9 X. d) ?<P><FONT color=#0000ff>#include <STDIO.H># D: p" _ e! N/ [" H, X% j: I# P
#include <BIOS.H>- w0 |+ S' h: A! a7 E
#include <CTYPE.H></FONT></P>
& P. R0 D' }& F( k; K<P><FONT color=#0000ff>#define RIGHT 0x01
0 Z- Q+ r' ?& {3 y5 I#define LEFT 0x02
" G; L7 i% P: o. ?8 k5 D#define CTRL 0x04
1 r5 I: H* o; e2 V, V4 E" k; }! {#define ALT 0x08 </FONT></P>
% B8 w5 r( W/ r<P><FONT color=#0000ff>int main(void)
/ ^2 g' Y1 A% Y3 [1 T/ T8 S{
+ L- h( G" s3 g& d& J" ^int key, modifiers; </FONT></P>6 L6 ~+ X J- b- |. U
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
+ d4 T4 ~) g% e" A! j2 Y. kwhile (bioskey(1) == 0); </FONT></P>
8 Q# c* a3 W; O, I, o3 q<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
3 ^) R6 j9 S( tkey = bioskey(0); </FONT></P>) l" i! r0 p- Q7 E) i0 C" L
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
! W$ q! b9 P6 m" W7 r. A! F! tmodifiers = bioskey(2); , X1 I3 @7 a; \
if (modifiers)
& F' c: p6 Y( e; X! U; w{
# E- y! N' D/ e. E5 S$ Cprintf("["); * P7 i5 ?5 Z5 @1 S( m/ }
if (modifiers & RIGHT) printf("RIGHT"); % ^4 w/ o* ]3 |4 N
if (modifiers & LEFT) printf("LEFT"); # ?! M9 d; _( `# [
if (modifiers & CTRL) printf("CTRL");
# I {8 v- _5 l! ?/ j7 Sif (modifiers & ALT) printf("ALT"); 7 M" `. V: L r
printf("]"); 3 n& V4 ?) \% R8 n* Q$ v7 u$ r
}
, n7 X! ?$ k y* a+ x+ ?2 K$ T/* print out the character read */
8 z4 b% Z$ p$ e. b+ s9 [if (isalnum(key & 0xFF)) 1 |5 {. t& Q( Q6 v& H @
printf("'%c'\n", key);
) U, ~/ S* ]) a4 E2 q/ ^else
5 h5 R0 a$ f8 ~/ `, i5 U7 A/ X6 _printf("%#02x\n", key); 5 P' O. u9 ] k6 h1 X
return 0; # M, `1 Z/ Q/ C6 _3 A5 k, _0 o
} l7 T1 Y! |, d# g8 P, x" r" x
! U p/ Z9 w' d3 E1 u8 I2 I( C9 u% q
</FONT></P>
0 e! Q' L0 {6 _- z; q) b1 z3 c2 _0 s<P><FONT color=#ff0000>函数名: biosmemory </FONT> v; }3 E8 ?+ \) L0 s! {
功 能: 返回存储块大小
, [0 {" V; @* h( y/ g3 o用 法:int biosmemory(void);
: z5 U: q. I: G, @# Q, b, w" w程序例: </P>) D2 d& W8 [! m( p9 w1 t9 e
<P><FONT color=#0000ff>#include <STDIO.H>
* k, o. ^; {2 z, t/ M0 z* ?#include <BIOS.H></FONT></P>1 x$ i7 s- w. E# m
<P><FONT color=#0000ff>int main(void) P0 a) A7 i4 Z! L5 E5 B
{
" J3 B( \% {1 [* j+ I( xint memory_size; </FONT></P>1 e: v. S& E# K) A" L6 M1 c: ]' a
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ : }7 e( J7 m- b! u
printf("RAM size = %dK\n",memory_size); : P+ X3 v! k9 Z# g8 b
return 0; - Z3 l* i4 W9 {& a% R6 R9 S& D- l
} e, J7 i# P) m" Q J
</FONT>& P- b" f: G' \ l' U( } z
( e. r8 ~* E- a2 h6 B6 H- l
</P>
& l# {* `) p0 r4 K' p<P><FONT color=#ff0000>函数名: biosprint </FONT>% {, A8 U) j# l
功 能: 直接使用BIOS服务的打印机I/O
5 ~- A0 G- I) T用 法: int biosprint(int cmd, int byte, int port);
/ N" u2 j4 n6 H+ O }程序例: </P>
' ?5 q7 S( G8 P<P><FONT color=#0000ff>#include <STDIO.H>
- s0 S/ l- V% y. C#include <CONIO.H>
`! `6 \0 X! w0 W0 k! N#include <BIOS.H></FONT></P>' v( L+ [6 D! ]5 _0 V
<P><FONT color=#0000ff>int main(void)
/ B* c( B) V- H8 [' L1 Q{
' f/ o4 b8 n" Q2 Y1 g! v$ n#define STATUS 2 /* printer status command */
) P7 A3 s1 h2 U+ [1 c. D#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>+ P7 Y# r( B0 D- G
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>+ [ J. e3 T; o& u/ S
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
$ U) a8 v' E! B% ggetch(); . A4 ?# F( r5 ]/ i1 t; c0 Q' x
status = biosprint(STATUS, abyte, PORTNUM); 4 c' s* c$ e1 g5 G0 c! g1 |+ X/ P) Q
if (status & 0x01) % r E: ]7 w, c$ q- W
printf("Device time out.\n"); # N* J8 u) E" F6 S. O
if (status & 0x08)
; X2 K7 `9 O: L6 l$ t, V# Hprintf("I/O error.\n"); </FONT></P>
' W! \1 ?8 R% B<P><FONT color=#0000ff>if (status & 0x10)
/ F# e; T9 \6 h: v1 Iprintf("Selected.\n"); * j$ B# Y& G, u' {. s
if (status & 0x20) 1 C. H( f' T% ^% P# ~9 |8 f* R8 A
printf("Out of paper.\n"); </FONT></P>- e4 E" k* ?0 I5 }4 s
<P><FONT color=#0000ff>if (status & 0x40) ; r) Y7 s3 O" a' t. ^
printf("Acknowledge.\n");
1 v) G3 ^- U3 B8 A N+ gif (status & 0x80) - E* s. i, n; C2 j$ }, J$ \
printf("Not busy.\n"); </FONT></P>
/ C2 H! w) _1 W$ ?# y) Z9 I& G<P><FONT color=#0000ff>return 0; - c5 k6 E4 j* R
}
7 G- E" K5 x4 C ?</FONT>
/ b5 B; S/ j" r' T
/ F- ?' U6 Z; r; N0 I# o6 a</P>
0 |) d) A; h9 f<P><FONT color=#ff0000>函数名: biostime </FONT>1 k5 h1 i6 _* ]7 \: E( T! b d
功 能: 读取或设置BIOS时间
2 ?( ]* W; x% S( j$ j3 [ r$ u用 法: long biostime(int cmd, long newtime); 3 T \+ T8 r: H& v
程序例: </P>! V5 l/ Q* e. N2 ^( p
<P><FONT color=#0000ff>#include <STDIO.H>
! @) Z1 ]7 e7 o+ o#include <BIOS.H>9 a/ i' k1 w$ M
#include <TIME.H>
$ b% S+ @& r' {. `5 H! r#include <CONIO.H></FONT></P>
# k* f y: B% R/ V/ J/ \( G<P><FONT color=#0000ff>int main(void) 8 g1 c* Q3 J0 h: U- c
{ ) f C7 j9 L" e! v
long bios_time; </FONT></P>% t( O$ |0 ]+ [ l6 i* s2 E1 g N
<P><FONT color=#0000ff>clrscr(); * s9 u7 w7 V2 [$ N
cprintf("The number of clock ticks since midnight is:\r\n");
# L, Q9 V* F5 `/ D5 a1 a* W& }cprintf("The number of seconds since midnight is:\r\n");
, j& y6 N+ `( N' W; F. f; q" E' ]* Scprintf("The number of minutes since midnight is:\r\n"); 0 k% |1 |$ ?0 r) _3 x) o0 _
cprintf("The number of hours since midnight is:\r\n"); $ i6 U" ]$ {+ w, Q4 M* \' ]" \& o
cprintf("\r\nPress any key to quit:"); # ?8 m4 R/ f* ?0 o( Z. E
while(!kbhit())
! @5 ]; r* M+ y/ T( i! Q$ |( l{
/ }) w# K' |* ]# f0 D- {bios_time = biostime(0, 0L); </FONT></P>9 o( \5 G( w0 h2 M; _' \5 k7 j+ }
<P><FONT color=#0000ff>gotoxy(50, 1);
$ Z4 w# [2 ?" x' Z) P+ L; t- xcprintf("%lu", bios_time); </FONT></P>% l* Z( F: h8 ]: T: h
<P><FONT color=#0000ff>gotoxy(50, 2); $ f, t3 W& w* l3 O
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
$ W2 G# C9 V m& ]<P><FONT color=#0000ff>gotoxy(50, 3);
# o1 b# m' U2 z- t1 ccprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
# c+ p2 G9 M. X! a4 i6 c<P><FONT color=#0000ff>gotoxy(50, 4);
% ?0 [+ O2 g" \2 E3 _. N0 W5 Bcprintf("%.4f", bios_time / CLK_TCK / 3600); + O: a: W: \: [$ z. D
} 7 z. z8 c4 L( u. Z" f2 s2 _. ?8 x
return 0;
/ C+ G! A$ M- W7 ~- C7 I6 c} ) W' k: z: x. |+ s0 H* V. ?
</FONT>
w0 }- @0 }9 [0 O" S4 o. A
8 s/ l' B! X: ]0 @; M</P>! M- p+ A6 L1 S b/ D
<P><FONT color=#ff0000>函数名: brk </FONT> @) e4 c/ V' P& @! ^/ _) k* ?
功 能: 改变数据段空间分配 ( T3 q& y l( h7 E" d/ D
用 法: int brk(void *endds);
! I" {- g2 r+ u2 k) l( z. W程序例: </P>
$ N) @: D6 n# K1 q- t: q$ }<P><FONT color=#0000ff>#include <STDIO.H>$ a+ w7 K8 M+ O5 q0 l
#include <ALLOC.H></FONT></P>4 N8 V& N6 b% H$ W2 e7 }
<P><FONT color=#0000ff>int main(void)
6 Z1 N! e1 v5 J: C1 e: J7 F' e{ 7 U" G; F0 b7 W4 y
char *ptr; </FONT></P>
$ Q) T1 W. ]5 c6 ?<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); $ d: ~; f; s0 }7 y3 x; x7 Y+ n
ptr = malloc(1); " D; [; V! |! U2 s
printf("Before brk() call: %lu bytes free\n", coreleft());
5 z) [% [& K. B3 {# J! B; ~! kbrk(ptr+1000);
+ A, @& E* |9 T$ yprintf(" After brk() call: %lu bytes free\n", coreleft());
c2 a$ T$ L+ g9 @+ areturn 0; ( ^# A* R- X( A" {
} % C |4 m1 A5 Z4 g% v1 x% Q
! U- N) r' _, G! w: a
</FONT>8 e. ]' j5 ~# l: b
</P>/ |" ^5 f+ A1 h' @' [3 W
<P><FONT color=#ff0000>函数名: bsearch </FONT>3 B3 b+ { t5 H% n/ `0 T
功 能: 二分法搜索
z& b3 b, f- Y0 W7 P# k用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
, Q2 [- l b& l* X; m& N9 Z9 f9 Esize_t width, int(*fcmp)(const void *, const *)); 6 T( y1 W" D2 \# ~, Y
程序例: </P>
0 w8 c$ U, V m1 c! l2 D' c b<P><FONT color=#0000ff>#include <STDLIB.H>& f) K; V- C0 m6 k! \
#include <STDIO.H></FONT></P>4 ?; o0 x4 p7 U3 u; S( T4 N& w/ e
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>" n/ q. j! e, s( n+ \
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
9 d+ H& a" t6 K7 w<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 5 `% q. k: [3 o% a1 C- u+ ]
{
% X, ~4 p/ u* C4 l5 creturn(*p1 - *p2); " C' B$ p2 a9 w, \
} </FONT></P>9 E* }5 V) { \- |8 N
<P><FONT color=#0000ff>int lookup(int key)
, ^# r- B y3 ~ p{ , E% ?* y' ^. p, L% |6 p% q9 P
int *itemptr; </FONT></P>7 M1 T: }% B. g, f7 W
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
0 Q: [* p/ L3 O4 Ais needed to avoid a type mismatch error at
6 \2 z# @3 |5 d# y& R8 T% Jcompile time */
v' W) f5 N! bitemptr = bsearch (&key, numarray, NELEMS(numarray), . H4 I6 O6 @( t4 o
sizeof(int), (int(*)(const void *,const void *))numeric); & V; Y* Z `: o1 g0 Z: l( u s) g% l
return (itemptr != NULL); 1 Q) M; T* o( _9 {" E' L, o
} </FONT></P>5 H% s. a. S7 w3 e! L, u3 I
<P><FONT color=#0000ff>int main(void)
7 I0 D% @0 b. U, F% o: G! ~{ 6 |, N- }, g3 x s C! f1 x d
if (lookup(512)) 5 e; T( ^% U9 f5 O1 U9 Q
printf("512 is in the table.\n"); # r% `# O9 B! _
else
1 ?. K4 {9 Z. e# i6 M7 g% tprintf("512 isn't in the table.\n"); </FONT></P>
& l% f. n ?3 b) R! y<P><FONT color=#0000ff>return 0; . v1 o# M% S5 {4 f- l
} </FONT></P> |
zan
|