- 在线时间
- 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>3 r) i3 H0 M# w4 P# @
< ><FONT color=#ff0000>函数名: bar </FONT>
% J* s% Q0 E* ^& A6 h! L功 能: 画一个二维条形图
2 Q* l8 f V9 b( _9 ~9 ^: U2 p# f用 法: void far bar(int left, int top, int right, int bottom);
3 x' Y) }( t/ S- X& P* e* V程序例: </P>
6 ~0 Q! ~* X% B- |< ><FONT color=#0000ff>#include <GRAPHICS.H>4 p6 i5 i5 E0 S- N& l! U
#include <STDLIB.H>
% ~ Z: ?( H' T( k2 U. e- Z#include <STDIO.H>
. X: j9 v& O1 F E0 n#include <CONIO.H></FONT></P>
4 @ j: R- w+ z/ W) A* J- v4 _< ><FONT color=#0000ff>int main(void) : \9 q7 V! E' Q4 J; w- Q
{
7 ?+ Y% |2 ^9 }2 v6 e0 N/* request auto detection */
; U( w; V0 B+ V! l3 cint gdriver = DETECT, gmode, errorcode; . c0 Z1 D! f6 F2 |1 {6 e
int midx, midy, i; </FONT></P>
2 D& i1 I, G3 Y1 m6 P< ><FONT color=#0000ff>/* initialize graphics and local variables */ 3 Z0 m" D- J1 Q5 u1 v! l
initgraph(&gdriver, &gmode, ""); </FONT></P>" G- Q& G, C5 K+ i; z
< ><FONT color=#0000ff>/* read result of initialization */
. ^$ \7 \% w5 I' k( Y* z' P( verrorcode = graphresult(); 8 S# s+ q) ]$ w: }5 r- N: H0 s
if (errorcode != grOk) /* an error occurred */
( J& |5 J, \2 `$ d" ^) v# w{
8 W$ @9 |2 u7 `9 t, H+ uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 l+ Z' Q7 r* o/ B% v' `( R/ H" K4 Mprintf(" ress any key to halt:"); 2 I* F q) l# r
getch(); 1 Y3 L; \4 Y3 z6 l3 i+ d9 G
exit(1); /* terminate with an error code */ , [1 t. P9 l" o8 Q6 A
} </FONT></P>8 A3 y& B. b2 f7 I0 ]1 [
< ><FONT color=#0000ff>midx = getmaxx() / 2;
( ^ `% u! M( y$ Tmidy = getmaxy() / 2; </FONT></P>
" u! u0 G5 R8 N5 u$ l< ><FONT color=#0000ff>/* loop through the fill patterns */ ; z0 E! H8 t6 M3 j
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
! T8 P1 Y# @1 p" W4 V' ]5 D% z4 t/* set the fill style */
. \% L. _4 R. @2 w& D( Q3 | nsetfillstyle(i, getmaxcolor()); </FONT></P>+ U4 h3 |- I6 S% d& u/ C, y
< ><FONT color=#0000ff>/* draw the bar */ 2 f# p- k$ @( m, r6 E6 c! k4 _8 n
bar(midx-50, midy-50, midx+50, ! d+ J: Q+ T2 l
midy+50); </FONT></P>$ i. n1 R: G7 t# t! H3 E! Z4 E
< ><FONT color=#0000ff>getch();
% o, d4 ~4 F' G2 u- X} </FONT></P>
) s# B2 Q3 F8 I# ~0 z< ><FONT color=#0000ff>/* clean up */
7 R* b( L% S3 e; t3 Lclosegraph();
4 u% T/ Y4 K: @) P- vreturn 0; # y. S8 M& m2 I& B5 M
} </FONT>
+ H4 [! W9 s* h$ ~: n- M) m* x R6 g2 A! V1 C, L3 g
# U L6 J+ j* T" r* r; s8 s
</P>1 G( `( s1 s5 x( U, Z
< ><FONT color=#ff0000>函数名: bar3d </FONT>
8 S: X5 W/ P$ k5 x! K( n功 能: 画一个三维条形图
4 p* h" z) X8 L5 q+ ~1 l) ]* H用 法: void far bar3d(int left, int top, int right, int bottom, : q1 Q c% |3 m) e. N+ D9 r
int depth, int topflag); 8 u2 `' n! r8 l& q. J
程序例: </P>
/ R m2 d1 o% M5 }0 j< ><FONT color=#0000ff>#include <GRAPHICS.H>( J" p$ L( \( l: R0 h5 Y! j
#include <STDLIB.H>6 i: [: V4 w4 w7 ^/ a
#include <STDIO.H>
5 W, y: t! b: e# v5 y#include <CONIO.H></FONT></P> I; y8 q0 ^: D- u/ O
< ><FONT color=#0000ff>int main(void)
1 r7 O$ [# D( u! I3 h- E; n3 `3 K3 t$ v$ E{
0 {# \* E0 Q: v: H6 k. K) Q) O/* request auto detection */ 8 t! A- E4 ]7 S
int gdriver = DETECT, gmode, errorcode; 1 x& ?, ` _: n* X, M0 r% t
int midx, midy, i; </FONT></P># k7 `- v, v3 E+ t9 ?5 w3 O" Q. m9 b
< ><FONT color=#0000ff>/* initialize graphics, local variables */ ^" g2 t" |1 Z. D' w
initgraph(&gdriver, &gmode, ""); </FONT></P>
; a9 z0 Z8 [) Y8 J0 S1 T* g< ><FONT color=#0000ff>/* read result of initialization */ ( i# K' U& i! V/ y# m$ `! d) X
errorcode = graphresult();
3 J: r; @2 b4 S, dif (errorcode != grOk) /* an error occurred */ 2 U9 l, T, [ b6 n
{
: o9 |# h7 P2 m( R7 I+ m: [printf("Graphics error: %s\n", grapherrormsg(errorcode));
( b. T; Y7 k1 I2 Oprintf(" ress any key to halt:");
- d, _4 m' a: w9 {getch();
' x0 A) k" i; B; E' J- Gexit(1); /* terminate with error code */ 7 Z' }6 S1 K; q5 |1 h
} </FONT></P>
- R5 l6 B3 t" E< ><FONT color=#0000ff>midx = getmaxx() / 2;
2 X! Q( U \ C# B" s2 { F: xmidy = getmaxy() / 2; </FONT></P>
+ G3 @+ G( H8 \$ [4 T9 V! e< ><FONT color=#0000ff>/* loop through the fill patterns */
d C. N! u0 W$ O4 n6 |for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 4 W# P* x2 a' h% h, K% Q p5 L
/* set the fill style */
9 ^& E. Q$ V0 u; lsetfillstyle(i, getmaxcolor()); </FONT></P>
$ V! _" b% z+ h1 K8 z) W; Y& |7 E< ><FONT color=#0000ff>/* draw the 3-d bar */ 9 {& a3 R$ T$ |6 G2 W2 u
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>; U2 O& n/ s, h4 V9 l; E
< ><FONT color=#0000ff>getch();
# Q! c" M+ b; O7 X$ k} </FONT></P>
$ `9 }4 X3 F+ Z W5 i< ><FONT color=#0000ff>/* clean up */ 3 U" }" P( ^0 ~. ^6 d! n% t
closegraph();
4 o& z h' Z9 {- Lreturn 0; 4 _/ Z; i0 f+ ?! K$ S% s" e5 s' l) J
} 5 ~; O5 {# O6 w$ l
</FONT>
7 K" n3 |- ^+ B( z/ C) E8 Y- J
</P>
. h2 c" i" _4 F6 l* y( E1 h1 u6 W< ><FONT color=#ff0000>函数名: bdos </FONT>+ c7 J; x# V6 s. ]3 b# m
功 能: DOS系统调用 5 `( R1 ^% V6 y2 F& D4 X
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); $ Z9 h$ ?3 A) | k6 j' c, A/ D# o/ Z
程序例: </P>0 |1 U* Q2 m0 n& I: v- _& z1 |" n+ J7 `
< ><FONT color=#0000ff>#include <STDIO.H>! U& l" Q6 E& {' W Y
#include <DOS.H></FONT></P>
% `$ f z* I$ s; g: e1 s< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ $ W- s8 Z8 U) J- c4 B8 h6 J
char current_drive(void)
! y* U- J5 b( I" Q- F3 r7 e6 ?! Z{ 7 o! Q/ W7 H* I) N
char curdrive; </FONT></P>) z' y( F/ Q( N5 I9 l
< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
! \ ]& L2 k$ U, tcurdrive = bdos(0x19, 0, 0);
" W4 j) D( t/ U6 oreturn('A' + curdrive);
& B, T- e8 |$ x0 h6 P" r; ]} </FONT></P>
y# i8 z7 t0 P x5 g% E< ><FONT color=#0000ff>int main(void)
# G% s. V( O, o6 S. u+ ]2 S{
/ S6 I) Z6 N+ Y6 ?& k, Jprintf("The current drive is %c:\n", current_drive());
& ~0 Z. ?. ^- k; Nreturn 0; . x# f0 P5 V2 Z7 R+ C5 E
}
5 X2 X- C7 w2 t/ _ T7 P% r: U- _; m9 B" {! b# I
</FONT>
2 ?* w1 p8 @$ z/ E7 b</P>
! e% v8 {; J: W" ]1 n< ><FONT color=#ff0000>函数名: bdosptr </FONT>
% H7 d6 n9 p V* V. F* t" ?功 能: DOS系统调用 $ P, i8 S# v5 I: K
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
5 I1 _6 t9 Y- H9 E& o程序例: </P>
' L* V# V2 ~% ^< ><FONT color=#0000ff>#include <STRING.H>
1 [0 ]5 {9 w- K! [# s1 E. [#include <STDIO.H>
9 W- d6 e0 W; E [4 ~#include <DIR.H>
9 \8 z# V0 [9 ~" m5 e#include <DOS.H>
8 j6 B4 u% u* g8 L#include <ERRNO.H>
- ?" T: {- u; Z, e I1 G#include <STDLIB.H></FONT></P>) I; X Q3 i) u+ n
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
! u" c3 o, N4 t<P><FONT color=#0000ff>int main(void) 6 P8 f) s7 s; O& c/ D& m! d* J) G) ~
{
- C) N5 ^) B/ z7 V: g# m4 Schar buffer[BUFLEN];
. c, D" T. S7 W0 `0 w+ L0 |- [7 w& M# rint test; </FONT></P>/ O, A8 J: L6 O }4 U3 {
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
. h! C; l% }9 o( G- o# Hgets(buffer); </FONT></P>6 \. Z h# Y3 V2 u1 B+ E& j
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 4 O, T! w) h3 I/ A5 y1 f
if(test)
! k6 t) N1 s& g" c$ y% o{
7 j- e% e m/ E. r, X$ `& uprintf("DOS error message: %d\n", errno);
; C( V; B' h4 E/* See errno.h for error listings */ 3 r7 w* M: I; _7 d
exit (1);
- J1 M/ Y( L+ h+ \- R" x( B4 m) O' y} </FONT></P>
, ]1 d/ o4 |, f+ m( s: A<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 5 I n* r7 G. ^ ~5 O8 c/ P
printf("The current directory is: %s\n", buffer); </FONT></P>
' i' b/ ~. Y) U8 a<P><FONT color=#0000ff>return 0;
* w3 E9 |( b% ]( `! g} % }$ w$ p: U6 J5 i! r% P
</FONT>
+ g F+ Z$ k, ]
9 L/ \; l* |4 ?( N4 U</P>
$ j& a0 f3 D$ o, x, ~<P><FONT color=#ff0000>函数名: bioscom </FONT>
& z" v; R8 N) v+ ?: Q; e; x( x功 能: 串行I/O通信 " x3 _4 h$ w8 p6 ] g8 ^) z9 M: X
用 法: int bioscom(int cmd, char abyte, int port);
+ V, a" Q% J: S/ ^! D Y& [程序例: </P>
/ D$ J, R: c* \1 ^# I/ x<P><FONT color=#0000ff>#include <BIOS.H>
4 l) E& W* S8 S! ]' D- B( `0 W4 j#include <CONIO.H></FONT></P>
0 ?# u% z) @4 O4 i' f<P><FONT color=#0000ff>#define COM1 0 & l( z3 C* V4 A: {8 n3 |
#define DATA_READY 0x100 ) f" ]6 g, x; A& _3 `- r
#define TRUE 1
% |6 \ n @( b$ Z6 I }4 l#define FALSE 0 </FONT></P>
5 `; I) |7 ]4 {, l$ e<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
2 z: l+ i# }( \<P><FONT color=#0000ff>int main(void) ! ^, h; D: i# T
{ 8 N) ^+ G# z' q
int in, out, status, DONE = FALSE; </FONT></P>- ` E3 d s, @/ A" O9 X. i3 T& v
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); 8 h; ~) t8 j9 n: F6 P
cprintf("... BIOSCOM [ESC] to exit ...\n"); ; h0 `9 L0 z/ A9 U3 e1 N
while (!DONE)
8 ^/ Y' a3 R7 Z{
5 L1 P/ J3 z8 b' A9 j; |/ gstatus = bioscom(3, 0, COM1);
- X; B8 l+ @- `& p5 N/ d5 U+ Rif (status & DATA_READY) % p8 r8 |' @% z
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
: L; X( S( q( m' r0 U' s* F/ ]1 \putch(out); ! M4 b0 B V5 F- |# W; Z
if (kbhit()) 6 l! y" C9 D( w: v6 u1 M
{ 9 j: u0 f9 N$ B3 k# ]3 i- B
if ((in = getch()) == '\x1B')
6 m: ]+ N, h; P+ {9 RDONE = TRUE; $ q# x& A0 d7 w# e! N3 c+ r
bioscom(1, in, COM1); % O) J; `- C. R& g" N7 ^. S' ~
}
; U# k6 D1 M* R$ g7 i. n}
R3 G" g. D/ A* r" u3 _# x+ Xreturn 0;
7 d- T- g- F) o5 d! z} </FONT>
) o5 b: O( A8 [) f$ A- n, H, o& s' G, ~0 F8 }9 ^
6 j k# G6 B/ c+ {! B/ N* ]</P>1 u- p! d0 v; A0 \- n# {2 k2 o
<P><FONT color=#ff0000>函数名: biosdisk </FONT>
' D8 e6 d1 z& y) j. N8 e功 能: 软硬盘I/O
4 x* S1 h; A# }+ V+ ]$ ~' ^) r用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
) g/ A! @4 s4 G$ k( `" Tint nsects, void *buffer);
4 u. P+ w a# D' p1 @程序例: </P>
3 y( u) y8 `, i. F* Z<P><FONT color=#0000ff>#include <BIOS.H>
, C- t& q& }2 v6 f: ~#include <STDIO.H></FONT></P>7 d3 \- p9 W: e$ N: S: i
<P><FONT color=#0000ff>int main(void)
/ `; ]4 g/ V6 p4 j! c- |{ / s1 y0 P' E& E( _
int result;
0 n& p8 r# k4 X" T. }4 hchar buffer[512]; </FONT></P>
- B& p" \7 S% J% B; M3 k) i* Y- X: o<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 2 v3 ]% C, B, k$ P; _
result = biosdisk(4,0,0,0,0,1,buffer); % k2 r: @6 k) W3 X3 \0 S. l; ?6 ^
result &= 0x02;
; ?8 ]& `$ Z) b(result) ? (printf("Drive A: Ready\n")) : / {7 b' v( E5 ?5 y6 j2 G
(printf("Drive A: Not Ready\n")); </FONT></P>
5 {$ r3 U7 s/ y) E5 s<P><FONT color=#0000ff>return 0; 8 @+ B x! O) W# ?6 s
} 4 B1 O: A4 c1 k4 l$ d
</FONT>. [) C- u. k. i5 L: P
) C8 t2 I7 u& N$ Z; G+ }# |" G8 }, G
</P>
$ c O$ X# ]. X5 v" E6 @9 G<P><FONT color=#ff0000>函数名: biosequip </FONT>: H) X$ B. R/ `& X% |, @6 P
功 能: 检查设备
/ P( \# ?, G( `$ V/ P8 `$ w# e用 法: int biosequip(void);
9 \: W0 @: L) r4 o$ q程序例: </P>" }6 F& ^1 }5 t _6 W; p" [
<P><FONT color=#0000ff>#include <BIOS.H>
8 y& ^9 M9 v: y- u" p! K2 Q! `#include <STDIO.H></FONT></P>; q% o" V, A3 i, l# x
<P><FONT color=#0000ff>int main(void) + K& j# Q" j9 k, p& K& j* [
{ * e5 O# K; j( ~2 K" A' Y" J3 k
int result; . u a8 b4 B+ |: u1 [0 d- e: e: l
char buffer[512]; </FONT></P>
p; {( f, f& {<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
/ E- I! G; f; O% |+ G" Aresult = biosdisk(4,0,0,0,0,1,buffer); , |8 z3 ?. r, s8 K. \- P
result &= 0x02; . q3 D* n5 n* \* c5 b
(result) ? (printf("Drive A: Ready\n")) :
/ |, o3 z7 h4 N(printf("Drive A: Not Ready\n")); </FONT></P>
, [; _+ p2 `; b- N# Y) b4 }- f<P><FONT color=#0000ff>return 0;
7 ?1 l" H% Z. l, m; X% g$ H} . ~3 P/ V6 n+ {- E3 D
</FONT>8 z" g4 C2 z6 n4 i' ]8 `6 M6 s
, {8 `1 Y! i* g; ?$ L s A+ u! B</P>
a3 }/ k2 H+ U+ b<P><FONT color=#ff0000>函数名: bioskey </FONT>
* ^0 p5 f; B) m, g" D功 能: 直接使用BIOS服务的键盘接口 0 z0 Q- Z0 L: g: `
用 法: int bioskey(int cmd); 2 f- e6 u/ i3 O" H2 Y9 c( |
程序例: </P>
0 i: X% [, @" a4 O# `<P><FONT color=#0000ff>#include <STDIO.H>) p9 ?8 M* s$ ?! ?- S3 @
#include <BIOS.H>9 M+ r3 p+ Z) s
#include <CTYPE.H></FONT></P>6 }. e' M. B! U
<P><FONT color=#0000ff>#define RIGHT 0x01
0 e8 ], s% G3 [4 E4 h' H! U#define LEFT 0x02 * a; `- r6 f! T& [; p7 c$ a* [
#define CTRL 0x04
9 b" ^0 ~9 v. b- l/ u% ~" e9 n#define ALT 0x08 </FONT></P>8 d3 M7 X, m) e$ v6 n. J% w
<P><FONT color=#0000ff>int main(void) ; N7 R' t) Y8 \0 F
{ & R( a- m- j) H) a7 l; `
int key, modifiers; </FONT></P>
- s' J" u9 C. n& p4 v<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
* E0 A7 N2 ~( `0 dwhile (bioskey(1) == 0); </FONT></P>
* G2 ~2 _) D3 X9 e<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ 0 i( z w( m" A2 o- E
key = bioskey(0); </FONT></P>
+ u1 l# U1 |2 [: b8 c<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 2 s1 p& g, k* m/ o' Y
modifiers = bioskey(2);
: [- v( e' ^, Z1 a1 jif (modifiers)
, k+ Z7 g6 k' J0 W# @3 |' E/ s{
5 O- D' y1 a5 K+ H1 j( e% X9 D6 hprintf("[");
5 r) W8 H2 X2 b; L& i8 q9 B5 xif (modifiers & RIGHT) printf("RIGHT");
! f. ] m3 ?& |! M1 X% Q$ Eif (modifiers & LEFT) printf("LEFT"); - e1 e) O# G3 Y: i' |( ^
if (modifiers & CTRL) printf("CTRL"); $ C. t: C( W# \
if (modifiers & ALT) printf("ALT"); 1 [" Q# w5 I! D" Y
printf("]"); , W g" R8 ]& {2 C" ~) D, U
} & Z, X$ Q) h; F+ M8 z# S/ d% ?4 D: z
/* print out the character read */ ( o# Q$ J& G* z% q. A2 m. |
if (isalnum(key & 0xFF))
7 b! R# c0 ^3 |. S8 W2 I; Wprintf("'%c'\n", key);
# w& G7 r8 x7 p+ y) _else
7 C. H& N+ V' C1 bprintf("%#02x\n", key); 0 Z; o+ I- f( \' X3 K! o$ h" m
return 0; & Y4 P% j8 \2 [1 k6 H
}
* G: e/ c/ F9 }/ v
0 K# P+ _6 s% ]7 j y! N2 O</FONT></P>! _. o. H$ F. Q# n: l
<P><FONT color=#ff0000>函数名: biosmemory </FONT>& k9 C& L9 O. y) d7 j8 M5 S
功 能: 返回存储块大小
# J5 w4 H# `0 l7 ~8 s& I2 |用 法:int biosmemory(void);
3 s: w Y4 m8 \; S, x5 K1 K; f程序例: </P>
8 b0 f' j1 U' ^& k7 v1 Q, O* x<P><FONT color=#0000ff>#include <STDIO.H>. G! W& s6 T" A, |' \
#include <BIOS.H></FONT></P>- P' \' s8 x, H3 @* f; p
<P><FONT color=#0000ff>int main(void) 7 @% [) z' q8 w5 T8 l4 H
{ . _7 Z6 F* l/ |& @
int memory_size; </FONT></P>6 D" P: J' Z2 a3 Q4 b) `2 E
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ : M9 X/ ~! z7 G9 }( B1 A" |
printf("RAM size = %dK\n",memory_size);
+ x# n& m) G8 l/ F4 {; Jreturn 0; 7 K$ T5 c2 W! K$ O
} ; s' w( ?8 E2 p% ]/ q. a. l6 o
</FONT>
# p" j/ t8 O8 L4 v/ _
1 w5 p2 H ?0 `0 G9 A" E" ^</P>
* o4 x* C$ J1 g: Q; v) h2 e<P><FONT color=#ff0000>函数名: biosprint </FONT>5 _( k2 }, G. u4 d0 m$ |
功 能: 直接使用BIOS服务的打印机I/O & {# B x3 E" Z
用 法: int biosprint(int cmd, int byte, int port); 4 W6 e+ G! a% C. h* w
程序例: </P>
* G. } C6 j6 \5 ]' m2 ^<P><FONT color=#0000ff>#include <STDIO.H>9 o6 Z' n5 c" v5 h4 @- Q- b3 X
#include <CONIO.H>1 \/ U) i8 d$ S
#include <BIOS.H></FONT></P>
6 _+ B3 Y6 I/ `) W. r$ }- {% D. G<P><FONT color=#0000ff>int main(void)
1 w' a, }6 ]0 G/ Y/ P- r% J) n& e{ 9 @7 D x3 U) _* k. T' M* a( Y5 }% M
#define STATUS 2 /* printer status command */ ' e1 U8 @+ t5 A$ K2 l9 O% t6 Y
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>) d: h% z) ^# I5 A$ T$ P1 B8 q1 u
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>5 K2 }7 a: ^& t( o
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); # |+ o6 h' T$ r. D& t
getch();
" B% _9 n2 Y. ~% p6 T! G% ustatus = biosprint(STATUS, abyte, PORTNUM);
y, x9 x3 B# x# v$ kif (status & 0x01) ( @0 h1 t- j# P) [% D9 [
printf("Device time out.\n");
' z; I' F" \4 _" X3 o( C$ G. n1 x: ?if (status & 0x08) ( c4 M2 `2 F. z" g; E
printf("I/O error.\n"); </FONT></P>& x2 d. }7 L5 A$ G
<P><FONT color=#0000ff>if (status & 0x10) ; w/ a3 ?5 w" N+ v: Q2 d7 X6 z
printf("Selected.\n"); % }" a$ \5 h O4 a# r2 ^ J
if (status & 0x20) % k$ z) [% o+ V
printf("Out of paper.\n"); </FONT></P>1 g, a8 x/ X; l8 y* l
<P><FONT color=#0000ff>if (status & 0x40) / C3 P, `" Y0 F3 L
printf("Acknowledge.\n"); 0 `9 H! T! l4 b7 h5 f. ^" z% y" t
if (status & 0x80)
3 _1 `5 E+ a1 Q d) fprintf("Not busy.\n"); </FONT></P>9 ]& G/ y8 B/ N; K; Z/ j
<P><FONT color=#0000ff>return 0;
" `1 ~% s& b% k! R} + `2 c$ S7 `' t4 C# [) E
</FONT>
( j$ |. T# ~( d* t* R3 i+ R M% g# m
</P>
+ t* r. ]: c0 t" w: l<P><FONT color=#ff0000>函数名: biostime </FONT>9 K* u `. ?! b7 W6 P4 D2 B# a6 R
功 能: 读取或设置BIOS时间
; Y* O* g& h4 z5 j3 A9 w, h# P用 法: long biostime(int cmd, long newtime);
$ d5 F2 f. d) o& h7 d5 N& J程序例: </P>9 m! z3 g- {2 M9 k5 u2 T
<P><FONT color=#0000ff>#include <STDIO.H>
8 A2 o$ Z1 D" Z( u5 D#include <BIOS.H>% L$ m Q+ u6 W1 u; r0 z
#include <TIME.H>
6 z* F0 o1 d6 o4 S# v' e#include <CONIO.H></FONT></P>; d f9 a9 m! \4 B7 v% m8 f
<P><FONT color=#0000ff>int main(void)
5 @8 b: j8 W* j, Y{ x6 ^% T( e* ~
long bios_time; </FONT></P>
. k' x/ }/ u+ t" ]' M8 F. W<P><FONT color=#0000ff>clrscr(); & o' J7 ]4 `. h7 l* C/ T* R6 k. i
cprintf("The number of clock ticks since midnight is:\r\n"); / i, r/ }* F: M. a
cprintf("The number of seconds since midnight is:\r\n"); 3 I3 P ` _* F; f6 j
cprintf("The number of minutes since midnight is:\r\n");
' H& `2 x8 N% d# f+ mcprintf("The number of hours since midnight is:\r\n"); : U# f" Z, ]& B& m/ v+ }( i
cprintf("\r\nPress any key to quit:");
$ j! J" x# B2 J! Z% ?5 P. ~. ]% C& twhile(!kbhit())
3 _) _" h2 m- ^5 ]$ P3 k, d0 p& |0 l{
; R) y$ k% n6 U* `bios_time = biostime(0, 0L); </FONT></P>
. d2 @: j" j/ E$ n: a: Z<P><FONT color=#0000ff>gotoxy(50, 1); 1 n, [6 \( A- t: K6 U0 x* K
cprintf("%lu", bios_time); </FONT></P>% A8 W; k( f6 S+ Z) [
<P><FONT color=#0000ff>gotoxy(50, 2);
% J, _3 n+ }/ k$ q9 t; V9 U$ Y& }cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
5 T" \; J5 F" U+ r/ |4 Y<P><FONT color=#0000ff>gotoxy(50, 3);
& s3 {4 g0 }- l7 v- u; H: |" W& q9 z/ Jcprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>* ^& I- V' O+ n$ \+ E
<P><FONT color=#0000ff>gotoxy(50, 4);
- }" T7 c4 d# T5 M7 t0 b% xcprintf("%.4f", bios_time / CLK_TCK / 3600); 3 i# G; _9 j$ E% h) s' n$ o
}
/ j* J( M/ _( g, R5 xreturn 0; / J" N( `- _# C6 U
} 8 X, q9 Y8 x1 t$ @5 \; H8 h
</FONT>
x6 l- e% A% f n6 ]: I& H. d2 J5 {" S5 K J
</P>
# M& L' T, X; B7 _<P><FONT color=#ff0000>函数名: brk </FONT>/ N# y3 z* C, A( B
功 能: 改变数据段空间分配 , w) Y4 O. Y7 Z2 I
用 法: int brk(void *endds); 8 i' S+ p1 L3 j0 }. z/ D* Y
程序例: </P>
+ l3 x2 {6 |$ d<P><FONT color=#0000ff>#include <STDIO.H>. P2 f U, _7 Y- T
#include <ALLOC.H></FONT></P>( y* j9 r/ P: V/ h( C/ v
<P><FONT color=#0000ff>int main(void)
( w3 d# g( T" R3 b{ 7 M R4 T1 f1 @* D0 G
char *ptr; </FONT></P>, l0 K s% M& d% W; @$ C4 ?
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); / G5 r \) H: {6 ~5 ?# d
ptr = malloc(1);
4 F5 X2 Y. E, A' B, Y8 Wprintf("Before brk() call: %lu bytes free\n", coreleft()); 5 [" u+ [+ j, Y- M" c
brk(ptr+1000);
8 q$ E/ l+ d# x* ]) B7 Rprintf(" After brk() call: %lu bytes free\n", coreleft()); 5 T& y% H+ }# P1 j
return 0;
7 V7 F8 C& t4 q2 u# k, a* r9 u4 a}
& n# I/ D$ g5 l" R4 @9 V: Q
! z7 V0 O6 {: ]8 x+ Y; \* y</FONT>
2 g2 y3 Y q. B& ? ^5 v5 [/ Z</P>+ ^; K+ m% d- A- N9 W; m
<P><FONT color=#ff0000>函数名: bsearch </FONT>5 |; {: H* s0 U8 C O4 b7 f$ b9 E
功 能: 二分法搜索 4 ?9 P4 z( Z! r/ w# f( B9 h* O
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
, [( i0 A7 _. r" g7 x: h5 Hsize_t width, int(*fcmp)(const void *, const *)); 5 @ N8 V/ \* \ @% i P- g& o
程序例: </P>
. `) d% i. R& W/ N; b7 i4 t7 w0 v$ p<P><FONT color=#0000ff>#include <STDLIB.H>
; { n# |6 v7 g" [) j2 J7 Y7 p) E#include <STDIO.H></FONT></P>! c4 I/ { N8 r, S" H; ?
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>: |0 s0 n. |5 t
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>8 e, S2 e. q% E% p
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
# { ]5 A( }, P% F4 ?& {/ ^{ 3 W' t. N) Y$ u- t g
return(*p1 - *p2); + {( V: E( w7 p
} </FONT></P>! w% M" B" b0 j
<P><FONT color=#0000ff>int lookup(int key) ) j7 f9 `/ g& {: C. P0 i
{ + T8 \" f( w* `2 m. s* W! i
int *itemptr; </FONT></P>
* m1 K7 r. w. f; g- B<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
. p' O# u# b R9 }, Zis needed to avoid a type mismatch error at 4 `4 X. u0 |! m8 q
compile time */ % R$ P$ `: U) G
itemptr = bsearch (&key, numarray, NELEMS(numarray), ! d; O) \: k0 s" p0 [8 ?4 f: m
sizeof(int), (int(*)(const void *,const void *))numeric); 6 b3 d# \3 O' |
return (itemptr != NULL); ! t* i! E7 {: e- T u& D' e7 c
} </FONT></P>
3 \. n# G3 U8 C<P><FONT color=#0000ff>int main(void) 0 J% _, T5 v( J* S! q. a/ M
{ ! h% `# }+ ^1 `6 h, p; s( A) f, ?, @4 p8 Y
if (lookup(512)) 0 @8 U$ k0 g {6 c, p. ~! p
printf("512 is in the table.\n");
+ ?6 g3 Z7 h8 x9 s3 Oelse
3 }9 P, J O. y7 ]& M# [printf("512 isn't in the table.\n"); </FONT></P>( E! N! x. Q/ `
<P><FONT color=#0000ff>return 0; 7 u: t( u4 s; D3 o: j
} </FONT></P> |
zan
|