- 在线时间
- 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>, j8 T* ?1 S) ]; X+ D% W/ T
< ><FONT color=#ff0000>函数名: bar </FONT>- B7 ]4 `% y# _4 `& v
功 能: 画一个二维条形图
/ h2 d$ m' B3 [' H/ ?8 _7 q用 法: void far bar(int left, int top, int right, int bottom); , P+ u) |: h9 K' z2 e
程序例: </P>
- p2 ?# q8 Z5 J$ s9 [< ><FONT color=#0000ff>#include <GRAPHICS.H>
6 E" X3 r/ {! X9 ?9 s2 p+ t#include <STDLIB.H>8 v9 w; u3 C9 H1 b* P7 o* d/ s* B- b
#include <STDIO.H>
( Y* Q" u' B" Y; ?#include <CONIO.H></FONT></P>
7 h( R7 H: F# N8 Y< ><FONT color=#0000ff>int main(void) 0 R6 S. s( k7 H. }
{ 8 E! F2 z, Q* ~; h( y2 U
/* request auto detection */
* L1 N, }- K7 S# B8 P0 sint gdriver = DETECT, gmode, errorcode;
* `- Q' ]" J/ z, Dint midx, midy, i; </FONT></P>
) M! ~; ]- b7 M- Z+ i' _< ><FONT color=#0000ff>/* initialize graphics and local variables */ 0 p0 D+ r* s3 m$ N4 C
initgraph(&gdriver, &gmode, ""); </FONT></P>
( q) u' e2 {, E H( c< ><FONT color=#0000ff>/* read result of initialization */
5 h& r9 w# |. V9 o$ @, Serrorcode = graphresult();
) O2 N8 a% @! L6 T' W/ S) }' G9 Lif (errorcode != grOk) /* an error occurred */ 9 D5 J& y, n7 s2 F
{ ( N, \3 n L3 }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- K) T0 I. ]* Z8 Q1 \printf(" ress any key to halt:");
8 j. M2 h; z! T0 a. y$ jgetch();
4 Y- _8 }5 r6 Z" nexit(1); /* terminate with an error code */
* Q& x! y3 }4 g/ N# U} </FONT></P>
& g8 d u" ? \) _2 o2 J8 Y: z< ><FONT color=#0000ff>midx = getmaxx() / 2; % q6 R8 A( d9 x3 R: [9 a5 z& ^
midy = getmaxy() / 2; </FONT></P>7 C, Y9 D' p4 s$ c4 Q
< ><FONT color=#0000ff>/* loop through the fill patterns */
$ l5 E9 W3 E) p; [4 [. q, a: qfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { 3 C1 \2 Y$ I9 R- Q. s
/* set the fill style */
8 L% \+ `" O' B9 t7 \. g* L! w( ksetfillstyle(i, getmaxcolor()); </FONT></P>
; w: M) {9 J8 A< ><FONT color=#0000ff>/* draw the bar */
$ s9 t8 |1 }3 v7 y" I1 r, Wbar(midx-50, midy-50, midx+50,
3 @( B T, t" |, [0 Q* P) }midy+50); </FONT></P>2 Q; A5 h% U+ V, F5 t% W+ f, H
< ><FONT color=#0000ff>getch(); ! e- q3 ~+ c# n5 n# v" R# D
} </FONT></P>
1 Z8 g! ?# q: @5 u5 q5 m9 n< ><FONT color=#0000ff>/* clean up */ 6 H* K8 j) E1 R/ i, W+ ?
closegraph(); 9 M9 I$ j* j; z$ |, W8 a
return 0; + k2 c, T/ L8 r1 v/ ]7 _/ v
} </FONT>) D- v9 j5 e8 f8 R' C. Y- J) [ H
H4 k1 Y) j$ t* s/ P
6 x: R+ o: G& | j</P>( T7 n+ y. g! \) E( t' k$ R5 l
< ><FONT color=#ff0000>函数名: bar3d </FONT>
* J- C) i% r! a2 K# E功 能: 画一个三维条形图
) I/ B4 ?6 z( L7 J用 法: void far bar3d(int left, int top, int right, int bottom,
- U( u% _4 y8 N; Kint depth, int topflag);
' Z$ w: ^, W1 r6 g4 G; d! n; p程序例: </P>. y! g* @$ _. X2 r# M+ H
< ><FONT color=#0000ff>#include <GRAPHICS.H>4 g, ~. t* }# W: _1 A `3 X. W
#include <STDLIB.H>
: R4 U3 a4 u* c#include <STDIO.H>4 P6 p" j. t9 A) M
#include <CONIO.H></FONT></P>
0 A$ D- H# G/ K0 ^/ Z1 g< ><FONT color=#0000ff>int main(void) - P( S; ]- [$ i3 S1 j
{
) V4 u, L2 Q3 F) ^/* request auto detection */
/ H; p( {& ^1 G Fint gdriver = DETECT, gmode, errorcode;
4 G) R- L6 R* sint midx, midy, i; </FONT></P>
# x1 t8 ?& U; [8 R/ G< ><FONT color=#0000ff>/* initialize graphics, local variables */ 8 [2 p. J6 m Q0 @% ?% {
initgraph(&gdriver, &gmode, ""); </FONT></P>6 [' M& s9 j! f2 {6 ?
< ><FONT color=#0000ff>/* read result of initialization */ # X- M: _9 w( ?0 s
errorcode = graphresult(); ! K) n s4 ?5 }7 v- y
if (errorcode != grOk) /* an error occurred */ 6 K6 k/ @1 Z) f% d# o
{ / Q A6 E/ |1 v" ^2 N/ D9 J. P3 _
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ ^8 m- W1 `7 h: C4 }$ \printf(" ress any key to halt:");
8 b- S+ ?) @$ J, C( _/ vgetch();
& o w" i5 t6 B( e/ H& c, pexit(1); /* terminate with error code */
- R9 A$ |1 z( C' Q6 [} </FONT></P>( @7 [$ m7 m' h' t
< ><FONT color=#0000ff>midx = getmaxx() / 2; 4 ~6 x/ I5 _/ D& U
midy = getmaxy() / 2; </FONT></P>
6 ~" `# j6 v0 I! h5 b _< ><FONT color=#0000ff>/* loop through the fill patterns */ . J0 O2 E( `9 `( _& |8 e5 E7 i; H
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
- Z9 C% j u: t1 z4 }: ]& v/* set the fill style */
a; V$ E/ K' ?/ J; O* Vsetfillstyle(i, getmaxcolor()); </FONT></P>
' ^0 B3 o1 V# \" e+ y< ><FONT color=#0000ff>/* draw the 3-d bar */
1 y8 J9 `8 F+ B, ubar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
7 ^6 v. h+ }8 b5 E# l< ><FONT color=#0000ff>getch();
) I o8 p/ N; s3 e% ^( L} </FONT></P>
$ I; T; v- M1 V< ><FONT color=#0000ff>/* clean up */
6 \) @, k5 N# H9 Y* H8 C! dclosegraph(); ' \4 T# V# L3 \2 g8 [1 Q1 L% g
return 0; ' n/ {( `9 W4 l0 d/ q+ ]
} . l0 d: R! [7 K! O: Z# Y. \
</FONT>/ j; j3 U0 k* I! c; E
5 t% W: d1 }# H1 t% _$ f; f# h- M</P>
# s% o# V/ t- Q6 j+ _< ><FONT color=#ff0000>函数名: bdos </FONT>
6 R6 X, F- W6 I7 r! C5 }6 B2 ~功 能: DOS系统调用 : q a" y2 l! Z5 Q7 G
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
7 ]! P% C' q0 @$ E' b# L程序例: </P>
; f( ]0 H& k7 S+ x, q; U F< ><FONT color=#0000ff>#include <STDIO.H>
9 {+ R7 z% s3 D# ~/ a9 _# X5 b#include <DOS.H></FONT></P>
+ a `: m" Q, d8 U6 Y3 [< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ ) Z. l/ G J$ F$ ] x! P" [
char current_drive(void)
) X0 S( c7 x) R' C, @: B{ 5 O9 H$ x6 b* F% D4 P. h# } X
char curdrive; </FONT></P>
* ]9 z \2 l6 J# d# ^) w$ t) a3 }< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ & a' s& g: e0 j. d; w
curdrive = bdos(0x19, 0, 0);
0 W! ], ~6 `6 e$ O0 c- Oreturn('A' + curdrive); 2 Y& F3 t4 z! ?- ]2 W
} </FONT></P>
8 ~( k9 h& P6 i< ><FONT color=#0000ff>int main(void) : Q& b) W8 H7 f0 Y
{ - d" l. s. \ [& Q3 r
printf("The current drive is %c:\n", current_drive()); 0 l# v% J" T( {; f
return 0;
2 O8 T# z- u8 J5 k} k/ J$ ~4 W$ ]- j" J
3 u" ^8 {" u& Z ~# z</FONT>
- P/ d+ [$ e6 P1 {9 a</P>
9 P, s6 [- f3 W; L8 Y2 u< ><FONT color=#ff0000>函数名: bdosptr </FONT>! U5 _3 L+ x8 m; P" D7 P
功 能: DOS系统调用 0 O" d5 N- [8 ^: c7 n
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); ; b# n- `% k; t3 Y! D: G
程序例: </P>' U% j: I+ S0 F* u4 ^/ A
< ><FONT color=#0000ff>#include <STRING.H>, N6 j3 F+ U9 C7 ]% y' ~
#include <STDIO.H>; f1 F7 C6 \- a# p F+ \) g& w
#include <DIR.H>$ p3 k2 G- J' l# j( `# ]5 Q
#include <DOS.H>6 z u$ S! n' u
#include <ERRNO.H>! k6 C0 F* S* B; e& z9 B6 R, e: a
#include <STDLIB.H></FONT></P>+ d/ x1 K4 W8 f1 E& X3 q% j
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>9 Q; E! \0 ?/ g3 j- q1 B
<P><FONT color=#0000ff>int main(void) / E' H8 Z) y9 H" G6 b6 O* f; B
{ . @: ]2 b8 ~# o5 c
char buffer[BUFLEN]; % ~3 N0 l7 x0 X/ X# g
int test; </FONT></P>: ~3 V6 Y3 j, s
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); ) u. R5 l6 E- w ?
gets(buffer); </FONT></P>
& N, B3 A% H# K! m, ?<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 7 z; w/ L4 N# k: [. |
if(test)
, y( o6 Z, ]8 S3 t/ \$ [3 e2 P{ 3 j( C% b W" x1 ~& V
printf("DOS error message: %d\n", errno);
5 C7 |/ s$ d& R/* See errno.h for error listings */
1 @& ^* e- |* z& jexit (1);
) k* P# S4 e# A& o0 g} </FONT></P>
1 `2 n [6 G2 A: Q8 E<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); + n9 I# z+ p7 N& {6 |" Y' w
printf("The current directory is: %s\n", buffer); </FONT></P>* \9 g- Q* W1 j0 ^. B5 w
<P><FONT color=#0000ff>return 0;
$ a& x. B4 E* |0 Z# d* y* o} 9 K6 c! C4 ?# n) p# j6 ^9 U k* Z
</FONT>
3 @ [0 x. _" q9 t
3 {2 O% V( T7 T) f2 i" W) X1 K</P>
' w% x3 a* e6 ^! [* L<P><FONT color=#ff0000>函数名: bioscom </FONT>
" x" w2 } g. b& C( X功 能: 串行I/O通信 , b# J: _9 x* |( n8 U
用 法: int bioscom(int cmd, char abyte, int port); 4 J$ C# n6 }( t+ b, @
程序例: </P>4 T$ t5 H& e) Y, g8 H0 M* `
<P><FONT color=#0000ff>#include <BIOS.H>" h) y o, I. G9 g0 K) D
#include <CONIO.H></FONT></P>
2 f. J& e; @9 S/ J9 Z' D3 B<P><FONT color=#0000ff>#define COM1 0 % c8 j* f; P; `- K$ N- y
#define DATA_READY 0x100
: d* k7 p9 d! i; @$ w; m6 H- @* R- m#define TRUE 1 * q" k" i, M1 d
#define FALSE 0 </FONT></P>4 S: ^( u& p, U: ~( ~0 F9 I
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>0 i) ]( x4 X! f5 b* b2 U, R9 q' @
<P><FONT color=#0000ff>int main(void) " \- P7 x+ |( b
{
6 @" a$ s1 F6 V, o7 @' ~& H4 r, Dint in, out, status, DONE = FALSE; </FONT></P>
$ p& A7 @% T& @: r7 {; t<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); ; q3 i+ e# V# }, z+ Q s. ?4 x
cprintf("... BIOSCOM [ESC] to exit ...\n"); ' o8 C8 a' S$ c, V$ V
while (!DONE)
2 P8 V- G! {# S1 t4 |8 w# V{ ! k$ O8 ? T3 i5 V: H% R- y
status = bioscom(3, 0, COM1); ! b; ]0 s( E7 R! a& _* @
if (status & DATA_READY)
. k8 S; D0 \( Q; R5 Q5 _* }7 aif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) ; ~ L0 `. ]2 K% n; ^
putch(out);
, r# S! V- Q- |3 P: L0 Cif (kbhit())
$ _1 P& ?* @0 j4 y{
4 u1 r/ i9 n, ^if ((in = getch()) == '\x1B')
: |6 I& K W4 [$ l/ h$ d) u3 }" p; D0 O% uDONE = TRUE; 0 H9 I- X/ N" d% O2 k8 A
bioscom(1, in, COM1);
( `, c1 p8 \! \8 o4 g& C}
2 q) C9 N4 ]$ j) i" V! }} % z+ ^$ Y! L: I
return 0;
: w4 C" o9 n% v" F+ }3 K/ h6 p T9 k# Z} </FONT>) B @8 E8 V2 ] s. |- |" [
1 \! s7 W9 B/ _" @3 y
3 v& R* R6 c! V) j6 T</P>' D! W3 S+ B3 g
<P><FONT color=#ff0000>函数名: biosdisk </FONT>! R7 V. [9 M4 ] {+ i! i
功 能: 软硬盘I/O
% L+ |; X) e6 |- @. {6 I, B5 W用 法: int biosdisk(int cmd, int drive, int head, int track, int sector
- D K( n- d$ X/ Q) lint nsects, void *buffer); - a$ [4 i8 q' a- g
程序例: </P>& i3 a: X9 L( p4 s
<P><FONT color=#0000ff>#include <BIOS.H>* l6 t: s: i/ p
#include <STDIO.H></FONT></P>- M$ A- k, u9 I5 v
<P><FONT color=#0000ff>int main(void) " x( K9 F! T* e8 Z4 K
{ q* ^3 f2 j* I, y. p$ ]: A
int result;
( T" v9 @) S' L% y5 ^8 {char buffer[512]; </FONT></P>
3 D' E3 }5 x& B<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); , Y O+ \8 L/ S
result = biosdisk(4,0,0,0,0,1,buffer); I) Q# A' a; e2 D& Y% k) ~
result &= 0x02;
/ P! L5 z& F" z/ m, w/ e4 [(result) ? (printf("Drive A: Ready\n")) :
# v0 Z$ _2 n% |% ?: d(printf("Drive A: Not Ready\n")); </FONT></P>
$ H9 p4 l' R$ O<P><FONT color=#0000ff>return 0;
* y! m" \0 e3 g& R}
8 A5 L9 j5 m8 j/ V0 a+ W+ v</FONT>
# R8 ?& o3 R9 `, ?
1 W) z& v8 j$ a4 u8 [7 h- Y1 w. p6 H</P>
' [' n9 q7 ^; M; q4 k<P><FONT color=#ff0000>函数名: biosequip </FONT>
* }8 I5 R4 c; k/ s# o功 能: 检查设备 & Y- q8 a8 n- C9 k0 u* V4 v; q
用 法: int biosequip(void);
\. l. A0 }6 f, @4 ?程序例: </P>
& p. g8 \9 q8 J4 n6 J% M3 W<P><FONT color=#0000ff>#include <BIOS.H>* K' M {2 n/ ^# Z
#include <STDIO.H></FONT></P>& ~+ M) O! F4 S9 G8 s6 x
<P><FONT color=#0000ff>int main(void) & W3 G6 g' _6 D; q* b4 d q
{
& o; V7 F) J" D; g; I) A. gint result;
+ |$ n9 ]2 t: s; W, Zchar buffer[512]; </FONT></P>
% {1 B/ V' s* b% T l<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
8 K6 v' I0 O$ x0 @result = biosdisk(4,0,0,0,0,1,buffer);
" g9 ?+ ?( ?( t g$ kresult &= 0x02; * F9 \5 y8 N, |! k
(result) ? (printf("Drive A: Ready\n")) : / ]) V, `6 g+ R* D3 d8 Y7 F$ e
(printf("Drive A: Not Ready\n")); </FONT></P>
; u s" G. |9 }: y3 s<P><FONT color=#0000ff>return 0;
! Q& }. j3 \1 {' E$ i1 Z) J9 u} ; E4 {$ }0 D8 r+ Y
</FONT>: D, O- X( ]' T) n1 ^. T# Y
4 e3 ^, R9 `& [2 j</P>8 }: q0 U4 F: q* X3 G7 E5 J4 @
<P><FONT color=#ff0000>函数名: bioskey </FONT>9 T- s P1 L6 j% Q7 _7 L
功 能: 直接使用BIOS服务的键盘接口 ( k, [. j% v+ U& l C% F
用 法: int bioskey(int cmd);
; H+ W% k( o- R" ^* q4 z# a程序例: </P>3 l9 e4 ?" k( Z* j$ A
<P><FONT color=#0000ff>#include <STDIO.H>) \+ r- I0 n, {8 Y- j* e3 p1 m
#include <BIOS.H>, j3 |$ F, q. z
#include <CTYPE.H></FONT></P>& [8 @$ U. u, T3 @0 d; n: Z
<P><FONT color=#0000ff>#define RIGHT 0x01
' d) O, _! Y: m#define LEFT 0x02 3 K3 h" W" ~( r' ]7 j+ C4 m7 G
#define CTRL 0x04 . _# m/ C v) @4 g" R. I
#define ALT 0x08 </FONT></P>
! d% ]$ K9 O6 w5 h5 ]6 a, [<P><FONT color=#0000ff>int main(void)
2 v9 u4 Y- b2 g7 i+ g, t. w+ Z3 \{ . O, T3 d0 A; Y( X- e
int key, modifiers; </FONT></P>
' E/ |+ c' |4 W2 f<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
/ F. I) c" K8 @4 E* Y7 F- Iwhile (bioskey(1) == 0); </FONT></P>
+ N. D* d& O" n9 D<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ ' F- p5 b* Y" I8 s
key = bioskey(0); </FONT></P>3 W% y6 X' V9 ~* a" Q' G
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ L# i: r/ Z4 G0 W2 `
modifiers = bioskey(2); A7 }' J( p& Q+ o! Q. D. W3 _
if (modifiers)
; f! }% U2 E9 _/ h; m" i _6 n; Y1 l0 D{
4 p- z! U" G4 Aprintf("["); 4 U: O. Z- t* Z$ O
if (modifiers & RIGHT) printf("RIGHT"); 2 U8 f+ I' | s+ d% a9 ~" H
if (modifiers & LEFT) printf("LEFT"); 5 s, m. K, \6 \; W* | j2 |6 b- i( f
if (modifiers & CTRL) printf("CTRL"); 6 F5 G% q, X9 |& f! R) n4 ^
if (modifiers & ALT) printf("ALT"); , ^$ z/ C5 j2 q% W# w
printf("]"); - M( {5 s8 }/ v+ {
} $ e* s$ H! K+ E8 [" L' X
/* print out the character read */
& h) o: @4 Y$ e A. }# ]if (isalnum(key & 0xFF)) ; c; E. Y) L. f; C1 n
printf("'%c'\n", key);
. [2 P4 v4 h" Jelse
% d$ k5 f* N" k- }: fprintf("%#02x\n", key); 9 J) }' r/ ~# l& P0 O( E
return 0;
& R8 {0 k7 }2 ^. B: k4 K: d} " F& w& c& S* e6 l( G- j( p, Z
) `$ z# d4 T0 t8 Q, X
</FONT></P>+ a% c# `3 h; W3 s
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
) z; N$ P9 U( {8 x' R) k功 能: 返回存储块大小 # a4 F/ D6 O0 F. f4 y2 C0 ?" L
用 法:int biosmemory(void); , i* N; k( Q5 p) d
程序例: </P>
" i! s5 D0 ?! k% R: l% L<P><FONT color=#0000ff>#include <STDIO.H>% \8 C7 V G1 ?; i9 N5 q" g! r
#include <BIOS.H></FONT></P>% ^# o! Z: a# M# z e' j: I6 M2 Z
<P><FONT color=#0000ff>int main(void) / D& v- T/ j. n- n
{ 4 i: \, {# ^3 ]& x* a2 u. g2 a+ Z" M
int memory_size; </FONT></P>4 A# S3 G9 |; X' E+ i
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ 8 j+ p0 s7 D( L! G8 x8 q- h
printf("RAM size = %dK\n",memory_size);
, `% C1 F* o5 b6 {return 0;
2 f3 Q: ^3 ^& m/ m1 l% q; m$ n}
' p% S2 r! v, I F</FONT>
4 [0 D( r$ \ e5 K9 M
y9 ^5 k2 p& F9 `3 ]( p) r</P>: {2 j, a, u( v7 G# L4 J4 |/ {
<P><FONT color=#ff0000>函数名: biosprint </FONT>
: H1 Z- u* i( [5 D5 r功 能: 直接使用BIOS服务的打印机I/O 6 m* e2 x8 A, B+ N3 h. q: Q$ c
用 法: int biosprint(int cmd, int byte, int port); 2 Q6 I& M6 t% O. [9 k2 Q* D
程序例: </P>/ G5 b) G7 z9 o* t/ d! S. T
<P><FONT color=#0000ff>#include <STDIO.H>& P/ u( i, l `$ D( h
#include <CONIO.H>9 T |! i( p: T* R
#include <BIOS.H></FONT></P>
" P$ r8 x6 v1 V! H8 i% B: ~ @<P><FONT color=#0000ff>int main(void)
# O1 S$ ~$ J+ B, M1 U( ~. I{ ( d, M& p( K9 K. a
#define STATUS 2 /* printer status command */ {/ M. \. u5 `4 k, Y6 s4 p
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
+ W% S* T( o ~<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>0 B1 p8 R' f" x5 R; r7 u, ]4 c
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 9 \8 f6 ]5 P& o) ~
getch(); " J4 K" G9 ]2 N5 J. N! q2 c
status = biosprint(STATUS, abyte, PORTNUM); 4 N* E$ A* \$ \
if (status & 0x01) ' a7 G( o, T# t9 J" B% g/ k3 L
printf("Device time out.\n");
" B- [5 e/ x/ J9 Fif (status & 0x08) 7 U* c" A% h0 s! X
printf("I/O error.\n"); </FONT></P>
" n5 X. c. V+ h5 y<P><FONT color=#0000ff>if (status & 0x10) $ Y- W% r7 f; D9 ^ n% U4 a( A
printf("Selected.\n");
5 N$ C! v0 W- |0 R4 xif (status & 0x20) / X0 n" @4 s9 \! n# ^+ a
printf("Out of paper.\n"); </FONT></P>
" R8 |. w, D& r<P><FONT color=#0000ff>if (status & 0x40)
: u7 P1 L4 ?8 W5 v9 J. Tprintf("Acknowledge.\n");
0 L( ?/ Z9 G3 d g$ uif (status & 0x80)
. s% c# Q2 k$ d' F, Kprintf("Not busy.\n"); </FONT></P>
8 k3 Y0 f+ Y& \) }' y; @<P><FONT color=#0000ff>return 0; 1 p3 F& ?/ {, x. A: m
}
j0 K3 f: V# g, c* g</FONT>1 y! D# M, W2 c" B( t6 e
7 d0 a% x4 w/ ?( i& M
</P>
! T5 G9 A1 j+ o9 ~<P><FONT color=#ff0000>函数名: biostime </FONT>% f' m! U' v% }6 k" [# Q5 U
功 能: 读取或设置BIOS时间
' z! p' z* D' ~0 D3 y用 法: long biostime(int cmd, long newtime);
1 x' v- I% |" b; {" j程序例: </P>- F6 h$ Z7 d) `! S3 J
<P><FONT color=#0000ff>#include <STDIO.H>) j8 U( X- t1 `7 b& m
#include <BIOS.H>/ I9 V+ J: x" U6 y
#include <TIME.H>
8 ]8 k1 y9 z Y#include <CONIO.H></FONT></P>& R: ]" K4 B& @& O: l
<P><FONT color=#0000ff>int main(void)
- n- n; W* |% ^5 `{
- s( x4 L4 _6 B# j/ U2 l2 Olong bios_time; </FONT></P>
9 N5 s( r2 H9 N9 P! S<P><FONT color=#0000ff>clrscr(); % f6 U" R. K$ d- f) ^( n" k% c
cprintf("The number of clock ticks since midnight is:\r\n"); 5 v$ R6 {# I: y% _9 }: L
cprintf("The number of seconds since midnight is:\r\n"); # d, `' C2 k/ b/ }
cprintf("The number of minutes since midnight is:\r\n");
( m" N) `/ Z# t$ z! p& U. Acprintf("The number of hours since midnight is:\r\n");
7 y% V. ~/ ^( B3 B9 z$ ]+ Ecprintf("\r\nPress any key to quit:");
8 }: k7 C2 p. ~" x0 q7 z2 P" Zwhile(!kbhit())
5 r4 x! v& X$ `- U, z8 f6 Y3 m{
% _3 s! h6 u2 Y4 x$ rbios_time = biostime(0, 0L); </FONT></P>0 q9 h4 t2 ?+ [8 m+ R# r( n0 q4 I
<P><FONT color=#0000ff>gotoxy(50, 1);
8 h# h; h4 \3 P2 A! lcprintf("%lu", bios_time); </FONT></P>1 n- M& w/ Z' l- P& o# M
<P><FONT color=#0000ff>gotoxy(50, 2);
% P( r) e% a* ecprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
5 B# d8 F& H) K3 ]- C6 N<P><FONT color=#0000ff>gotoxy(50, 3); ; k+ f1 Y% w3 A7 s/ d2 C
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
1 `9 G5 D- k2 y<P><FONT color=#0000ff>gotoxy(50, 4); + G# h- Y3 L, a/ l- [/ V
cprintf("%.4f", bios_time / CLK_TCK / 3600); & y$ C5 {% r$ T W# q
}
, A% O0 r3 o5 K) M4 r" dreturn 0; % l6 x; e9 h8 a
}
; ?( D7 Y" ?1 n _/ ]" H5 v$ T</FONT>. v. r3 b1 Y9 H8 Z& g
1 w2 H) S; Y+ H0 M0 M, m+ z
</P>
4 y# y+ j9 H0 W' a<P><FONT color=#ff0000>函数名: brk </FONT>& F2 t' t: k% V8 @ Y! D: J: |
功 能: 改变数据段空间分配 ! {# k( M# I, x+ t4 J( i" Z4 o
用 法: int brk(void *endds); / M0 [; V' ?' Z7 j6 D: |& f
程序例: </P>
/ H8 G( B% y2 w# h: @& w+ ?/ B<P><FONT color=#0000ff>#include <STDIO.H>9 S) `0 a/ ?% m& l. @: F+ B
#include <ALLOC.H></FONT></P>
" P" G: Y1 `/ ^<P><FONT color=#0000ff>int main(void) + |2 i: P. T- B8 Q/ C5 T' K1 y
{
' F s6 i$ C9 _/ T X6 g Tchar *ptr; </FONT></P>! p' T* J; f; h4 _+ H8 ^; B
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); y; p4 L* }$ S/ |. P- ~
ptr = malloc(1); 9 ]) u% j1 F( x9 e' V! p
printf("Before brk() call: %lu bytes free\n", coreleft());
) E5 S( g5 H; @' p+ K n3 q; G+ Nbrk(ptr+1000);
, ^8 ~# }6 x/ z/ {9 c3 @6 {printf(" After brk() call: %lu bytes free\n", coreleft());
' Q+ V# E ^+ L& Y2 _* Rreturn 0; & l1 q1 S7 Q1 x3 P: v5 e1 p
}
0 ]3 R& I1 N6 P1 s
' w1 L: b7 v: @/ Q</FONT>4 @, t' W/ Q; ~5 Z! v
</P>: e$ H+ v; K* a2 E$ t$ P M
<P><FONT color=#ff0000>函数名: bsearch </FONT>
, k: g9 @: j0 x功 能: 二分法搜索
y6 i6 S( n! T7 @$ e用 法: void *bsearch(const void *key, const void *base, size_t *nelem, 4 X* z! o5 P: q- i
size_t width, int(*fcmp)(const void *, const *)); % W! H& W, q6 e1 a; _1 O6 |- |. h
程序例: </P>/ Z9 x$ v' b' m+ J; M& z _4 o
<P><FONT color=#0000ff>#include <STDLIB.H>
: p1 x! b' I: q) y, Y#include <STDIO.H></FONT></P> P6 |1 q, e2 J2 ?
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>( f; p$ q. d2 ?- W0 M
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
" Z$ P( m" V7 t( ]" i' k<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 8 T% @1 O( [- m
{
! g4 j8 ?0 J3 t+ g0 z; Sreturn(*p1 - *p2); + V6 _. H9 N' [
} </FONT></P>
# A5 k$ y# r0 t& Q7 C<P><FONT color=#0000ff>int lookup(int key)
1 r3 z7 t/ w# n8 J{
0 u, b# N3 f7 D! O% O, D: ^3 oint *itemptr; </FONT></P>
! Z- d, V8 G9 T, e. Z# ~<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
: O: |0 |! P1 t- Lis needed to avoid a type mismatch error at
( E2 d m' L" D, v Fcompile time */
e% b. b$ s6 f5 Ritemptr = bsearch (&key, numarray, NELEMS(numarray), z5 r" q" X& Q5 G/ K7 t2 q2 T
sizeof(int), (int(*)(const void *,const void *))numeric); 4 M2 ~8 H5 C9 S
return (itemptr != NULL);
0 l! M; Q/ P( r% a3 ~} </FONT></P>
9 ]6 `& X$ ^. V1 G' g* g<P><FONT color=#0000ff>int main(void) 2 k: [- `5 I3 a
{ * ^. X5 X. Z. X8 S ^( \
if (lookup(512))
7 X# W! L" p$ V6 h1 i. l0 yprintf("512 is in the table.\n"); ! \3 J c& `2 R! X6 }3 |
else
( d* c/ q* ?# U5 L& l1 Zprintf("512 isn't in the table.\n"); </FONT></P>
1 e3 S& ?6 X- p1 @<P><FONT color=#0000ff>return 0;
$ E* \7 H3 Z3 P4 x- j} </FONT></P> |
zan
|