- 在线时间
- 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>
0 n# p1 G- }& i) U! d+ i< ><FONT color=#ff0000>函数名: bar </FONT>
2 `5 G8 A) E. C! B功 能: 画一个二维条形图 4 r x2 e, A7 J. w8 A& E
用 法: void far bar(int left, int top, int right, int bottom); 8 d# H% T. m6 {7 s- F! p/ Z
程序例: </P>/ y* L+ g: c2 G' Q4 a& Q4 L- _
< ><FONT color=#0000ff>#include <GRAPHICS.H>
: z8 N1 j2 ?" {; b/ ?6 p#include <STDLIB.H>) R# b/ ^4 s1 a9 {- J# q6 P
#include <STDIO.H>
) @% p+ \1 P7 F3 |' F1 B+ y4 k9 d#include <CONIO.H></FONT></P>2 M. y z# @* L2 P
< ><FONT color=#0000ff>int main(void)
, ?& l4 x/ b2 e5 O3 y7 _{ $ _. }0 g+ l$ a U! }
/* request auto detection */
. y* R5 e+ q$ W( L# \$ tint gdriver = DETECT, gmode, errorcode;
6 V, U2 g; `, J1 X. k& c aint midx, midy, i; </FONT></P>4 [0 S$ a" s; W) P
< ><FONT color=#0000ff>/* initialize graphics and local variables */
9 H- Z: \" i; o' Z8 {initgraph(&gdriver, &gmode, ""); </FONT></P>
1 e. S/ W( L: A( q% O3 O, r0 G, z< ><FONT color=#0000ff>/* read result of initialization */
" W! G: L% c: b& G) Cerrorcode = graphresult(); ) }/ N$ ?* ^5 r/ h6 g! v$ J
if (errorcode != grOk) /* an error occurred */
/ A0 {4 F0 P) B{ ) o% T4 U. Z5 Y, ^$ i4 a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
, N, y6 r* m; W" d3 ]1 Gprintf(" ress any key to halt:");
+ h6 S2 F% r. i/ `; \/ wgetch();
9 l9 P+ p, L: d8 U) \exit(1); /* terminate with an error code */ ! U7 d# x( Y% S" T
} </FONT></P>' t' Q( J7 h6 W& Q
< ><FONT color=#0000ff>midx = getmaxx() / 2; 1 \4 f- N6 c1 E" G2 z1 N
midy = getmaxy() / 2; </FONT></P>7 u6 Y, z3 f6 j% S, |
< ><FONT color=#0000ff>/* loop through the fill patterns */
2 Z! N- Q2 ?" x) k1 dfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { ( f* h" ?8 ?/ v# e
/* set the fill style */
+ z F+ {/ L" }3 E5 U$ f8 r5 X( |setfillstyle(i, getmaxcolor()); </FONT></P>
( G5 ~. `; Z" @( h- E# g: d< ><FONT color=#0000ff>/* draw the bar */
: e. k, J0 Q4 y! K9 O, L& h% V' tbar(midx-50, midy-50, midx+50,
2 f# h$ N3 B& d. q; | |midy+50); </FONT></P>
5 f/ ^2 [! K) G* v0 n) r* j1 s4 I< ><FONT color=#0000ff>getch(); : K! H7 }2 Y) ]7 }6 d- @" W
} </FONT></P>' t8 s; h _ v$ p+ A; R& n
< ><FONT color=#0000ff>/* clean up */
2 K7 K' k3 x3 {' |closegraph(); ) f: t: P( N# [
return 0; 2 G+ l1 K0 G* n) h7 x$ L
} </FONT>
8 q1 k( i* A+ V" f" v6 J# [. K/ w @3 ]$ u V$ Q
% I9 Q6 p; a6 M) B; p; \
</P>/ Q" L% c4 i1 H) [* P% r4 }/ }+ m
< ><FONT color=#ff0000>函数名: bar3d </FONT>* S! m5 q! o: v, T
功 能: 画一个三维条形图
* L, R5 q8 l; t0 u0 v- P- P8 b) `用 法: void far bar3d(int left, int top, int right, int bottom, 7 z5 ?- p8 h9 N; ^+ l2 ^
int depth, int topflag);
/ Z0 D# |4 O2 i* e程序例: </P>
' @# B; B ~6 ?< ><FONT color=#0000ff>#include <GRAPHICS.H>9 B1 ?8 O, e) @
#include <STDLIB.H>* C7 O3 w% {" b, e
#include <STDIO.H># o3 F1 w- k3 ~$ e: F; n
#include <CONIO.H></FONT></P>7 S7 {) |; v) W' D
< ><FONT color=#0000ff>int main(void) ; f* t3 [+ ?/ l
{
) x( P" ]7 J" Z. _" h9 D! B/* request auto detection */ 2 v+ ^, Y' y. w' \+ _0 I, k
int gdriver = DETECT, gmode, errorcode; : R/ ~) L3 ]5 T. H
int midx, midy, i; </FONT></P>% w, f& [/ Y+ K8 q7 G. m: _
< ><FONT color=#0000ff>/* initialize graphics, local variables */
^* N3 O# @; w5 X8 Minitgraph(&gdriver, &gmode, ""); </FONT></P>
8 M& Y0 ~& d$ v1 ?0 N, m) V< ><FONT color=#0000ff>/* read result of initialization */
# s1 I2 ^' j3 V2 S Oerrorcode = graphresult();
5 C! M+ E5 h$ X$ W9 F' ]/ [ L! ^7 Rif (errorcode != grOk) /* an error occurred */ 5 K p( ]% {4 ^8 s" q/ c& G$ j
{ h p$ E7 e7 a8 [
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 _9 ~4 l( O$ b: @5 c/ P. R' Uprintf(" ress any key to halt:"); 9 M$ P1 w( G' A! q. c
getch();
" G5 N5 G! F4 O4 @* \: H. Hexit(1); /* terminate with error code */
6 @& p2 q0 m& @" ~} </FONT></P>
" I) ~5 t7 L; o9 V< ><FONT color=#0000ff>midx = getmaxx() / 2;
% i% s% G7 g7 F, d8 w8 Mmidy = getmaxy() / 2; </FONT></P>7 b: S' H# g+ R; l1 F* Q
< ><FONT color=#0000ff>/* loop through the fill patterns */
! V& {+ Z/ k( ?2 i0 l g7 V! Lfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
1 n0 @ z) `2 E; c& B3 n/* set the fill style */ , Z, O9 \! o3 z& N6 B. ^* W
setfillstyle(i, getmaxcolor()); </FONT></P>- |# l- U6 Z% x, Q
< ><FONT color=#0000ff>/* draw the 3-d bar */ 9 k6 _% a+ P: F
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
+ q z. |; w# K3 i! } K< ><FONT color=#0000ff>getch(); 8 y2 u: Z" o4 e. f; v; F; `6 ]
} </FONT></P>
: u- H* H. u6 |+ N< ><FONT color=#0000ff>/* clean up */
9 k& @2 k' @7 B) r- `" Uclosegraph(); ( @' q5 y' a7 {1 O' _- v
return 0;
' S8 k I, S& S% E: \- Q" q) x}
0 u6 h5 g& z1 P6 F% Z. V</FONT>
4 V2 r9 z: J" I
7 @9 R; s9 b+ [, [</P>) I0 j' N& U8 r
< ><FONT color=#ff0000>函数名: bdos </FONT>
% o* [# |3 T5 |功 能: DOS系统调用
: V( ]" q2 j, `1 ^, E用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
- G7 a8 N, {: x3 _2 D+ c5 H h程序例: </P>
* Y K* S3 C; W0 m2 ]: I< ><FONT color=#0000ff>#include <STDIO.H> Q' G( v, B1 t, `
#include <DOS.H></FONT></P>
8 R2 E9 E. N5 C1 b; g( i, C< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
( v4 ?! a1 \# O. T: a( {char current_drive(void)
6 L0 `7 C2 F6 q* ^& A" A1 j{ " r* V( B# j) ^1 Z
char curdrive; </FONT></P>
2 P$ d" i: x) [< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
( Z' k. F: B& ]curdrive = bdos(0x19, 0, 0); 3 N9 M0 U' ?' L' \+ t, v, }
return('A' + curdrive);
8 Q, s( P, L* L' U+ j5 s} </FONT></P>8 T, j. l9 [2 N. f& |: z
< ><FONT color=#0000ff>int main(void)
- B% [0 K( n% @: m) N{ + [% }) q; e5 V: q, Y
printf("The current drive is %c:\n", current_drive());
0 |: X# Z; S q) preturn 0; ' ~5 Y: I. ]" |
} 1 t8 p; n" c5 i; j) o1 ] U
; A0 ^, p+ x4 G, U" o. H</FONT>
9 q2 F* q6 g; Q5 u9 ?</P>/ T s, ?: p3 H7 B$ o
< ><FONT color=#ff0000>函数名: bdosptr </FONT>
1 y( _! M! m) {; z" l/ |功 能: DOS系统调用
. a! t! h1 y) `$ |/ Z* _7 L用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); + U! F& L5 d+ M; [: K6 l) ~: C
程序例: </P>, U# _+ \. X/ H2 G
< ><FONT color=#0000ff>#include <STRING.H>
: y2 j* \$ H8 g#include <STDIO.H>6 M0 e9 w I ?
#include <DIR.H>
2 X! X4 k2 U! M: r( J5 d#include <DOS.H>
. d# b5 O! g: Q#include <ERRNO.H>, T5 A8 ^' V$ _* U* k
#include <STDLIB.H></FONT></P>
+ j' P5 M! N, U<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
; E; H8 z& p: O) C<P><FONT color=#0000ff>int main(void) }' A% A1 q3 j8 m& r; ?
{
# X$ X P; Y6 ^! echar buffer[BUFLEN];
4 ]/ R8 {" H& s- }* Xint test; </FONT></P>+ }& u1 h/ G$ U) X
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 7 @0 P7 ?- b. x6 V4 I! o
gets(buffer); </FONT></P>+ W% i' }. D- i9 f% C1 I
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
$ S. T" ?, \4 r5 d9 C! A/ hif(test) 6 W# |3 u1 C! ?- n7 K3 A7 N& s' r+ A
{ 0 ]3 R* P& z+ E* [
printf("DOS error message: %d\n", errno); 4 S& y+ N$ {+ @, n" N" d
/* See errno.h for error listings */ ' U2 f# ]5 p) ?- V
exit (1); " Q$ y# n6 L( O! Y+ _; s$ J- s
} </FONT></P>( o8 v% x2 f0 |; J
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
! H6 o1 i1 C7 S8 |printf("The current directory is: %s\n", buffer); </FONT></P> ^- b% P4 n' o! {7 w9 O6 i- W
<P><FONT color=#0000ff>return 0;
: I* m4 p! B6 H& s0 S} . [6 ~1 l) j2 S' Z
</FONT>
$ S% j8 D1 M3 [' _3 q2 K
9 Y2 S: l2 s, T9 z9 L& t0 R</P>
' L: [) ~! T( U- U/ A<P><FONT color=#ff0000>函数名: bioscom </FONT>
" `0 {; ?( S9 p0 \- \8 z功 能: 串行I/O通信
% l' E$ r0 K8 i, t用 法: int bioscom(int cmd, char abyte, int port); 8 G- M9 V p1 M3 R, I# [8 e: g+ S
程序例: </P>% Y8 ?5 e6 m- i0 i# P9 [& P
<P><FONT color=#0000ff>#include <BIOS.H>
: F# N3 N* k9 S8 \- y#include <CONIO.H></FONT></P>* K1 W. C# L; Y7 W6 U# D# t
<P><FONT color=#0000ff>#define COM1 0
6 H( [7 E- _ C# i" q5 A u#define DATA_READY 0x100
, M- c' E; U0 k- x#define TRUE 1
- v8 J" G4 L% y, [9 n3 y#define FALSE 0 </FONT></P>( ^* l7 C$ H/ v. \; n0 q
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
7 Z9 `) E, D: D<P><FONT color=#0000ff>int main(void) 0 L8 d* z6 e5 f2 c$ b! m
{ + G/ p: k1 ]) H W& E, P& i- q) R* i
int in, out, status, DONE = FALSE; </FONT></P>. _% {; X( v) u/ V
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
1 c& l. i3 g' bcprintf("... BIOSCOM [ESC] to exit ...\n"); 2 @7 }8 U+ B6 X5 u
while (!DONE) 8 b' c A" E' }$ B
{ 5 n6 x* W& p9 ^( j6 {
status = bioscom(3, 0, COM1);
& y4 Q P/ Q4 Rif (status & DATA_READY)
7 w. V8 w2 a9 ^- i4 Lif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) 3 L) G% _0 O/ Q$ j% ]9 T* _
putch(out);
; h; p7 ^8 K0 @7 m* p- p. tif (kbhit()) : X0 C9 i3 ~- r* ^) h$ x
{
; p, S" g2 N( q& _if ((in = getch()) == '\x1B')
7 e, R! ]- n$ y" v ]DONE = TRUE;
- _9 N" A2 \* \" B1 y, ibioscom(1, in, COM1);
: j( e" \% X4 u: H# Y} 9 B. e) b9 {) V- j1 R0 ~1 O6 d8 y
}
9 L7 r! |! l6 L8 {8 a4 greturn 0; : P5 u+ \) B6 p) |2 d
} </FONT>) c) u+ X u8 S3 s4 s/ F0 E
0 O7 @+ R4 @9 I$ W4 p8 c
6 s1 O8 h; P4 }</P>
$ e- K( A. z N' z% c) z<P><FONT color=#ff0000>函数名: biosdisk </FONT>
: v2 [$ E$ H# ~+ D功 能: 软硬盘I/O
; m$ c& h" L. T用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 9 l8 _3 M* n( W- _# S# k8 b {4 G
int nsects, void *buffer); 0 x8 |- ? S- ?3 k+ G" C6 z+ }
程序例: </P>
! G4 q( g+ {; k& J6 s$ P<P><FONT color=#0000ff>#include <BIOS.H>
$ N- S3 B) E/ J- E1 x3 C#include <STDIO.H></FONT></P>
. o1 j! W" b! Y# [0 U& {) C<P><FONT color=#0000ff>int main(void)
7 b& z% H7 K F. m) m0 b7 l( O; L{ # [) e! ?2 i; j; O% r3 t& B
int result; ) M9 \( O4 U, _0 M2 F: j8 O8 S# Z
char buffer[512]; </FONT></P>
: k7 H' S- ~2 l<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
' Q4 _+ t; K z, c: s. k: } I7 Sresult = biosdisk(4,0,0,0,0,1,buffer);
* y! ^* V& J7 _% O1 w% ]9 F% Fresult &= 0x02;
! b# `3 D' p; g3 M4 ?(result) ? (printf("Drive A: Ready\n")) :
- e8 c. s& i3 ~5 Y(printf("Drive A: Not Ready\n")); </FONT></P>
% r; f# s! W) [+ K" W1 \' r<P><FONT color=#0000ff>return 0; ; l. @* O5 e! [5 p) y1 Q
}
' Z; s9 l$ s2 s2 N% i( o( O, z</FONT>
, A+ X: ~' W2 O/ X
& s4 S( E7 M: A6 `! a/ C6 r</P>
; ?, I7 {8 O! d Z! |& p8 G" Y<P><FONT color=#ff0000>函数名: biosequip </FONT>
& _1 O( e. s1 y2 A; m功 能: 检查设备
: C6 O2 U# N* t. [, n用 法: int biosequip(void); - J- G8 h w9 @0 E
程序例: </P>2 M# |" Z# B4 I9 p4 ?
<P><FONT color=#0000ff>#include <BIOS.H>- I- o3 W2 ?6 k
#include <STDIO.H></FONT></P>
, t5 I1 F5 x1 N<P><FONT color=#0000ff>int main(void) 9 k/ }& j7 c8 S- ]5 W4 x( o
{
/ k B+ I6 u5 i( bint result; 5 ~: ~8 [/ ~3 J- Z* y ^
char buffer[512]; </FONT></P>
" r( p- d: h7 p" W" P* a<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
7 o) x; @# n. i Bresult = biosdisk(4,0,0,0,0,1,buffer);
( `) d$ N4 _& f9 v7 T+ }, n, Tresult &= 0x02; - Z. y2 P7 D N' s) d5 Y& C
(result) ? (printf("Drive A: Ready\n")) : / }4 g. J+ j8 \. P8 U& @
(printf("Drive A: Not Ready\n")); </FONT></P>6 y' C }& L5 G. @5 k3 J4 b* D9 h
<P><FONT color=#0000ff>return 0;
' |. w- q4 N3 C$ d}
) N! M& [/ [& S B* a* c</FONT>1 \* [( Y$ p/ e0 M3 e! T
# h: x# @. B( `: X& _
</P>
- u& Y6 i3 n% J( r f3 i, n<P><FONT color=#ff0000>函数名: bioskey </FONT>8 V# Q' d: J/ w
功 能: 直接使用BIOS服务的键盘接口
$ s( \, u) H0 ~) }6 Y/ R) r用 法: int bioskey(int cmd); * l5 J+ I* h. F
程序例: </P>
+ P( l3 |& i! [! J<P><FONT color=#0000ff>#include <STDIO.H># O" u. ]4 |( c/ _1 ]1 W
#include <BIOS.H>' u. C/ M) N; q
#include <CTYPE.H></FONT></P>6 O- y9 u k( A9 {( p# M
<P><FONT color=#0000ff>#define RIGHT 0x01
) I+ Y4 {+ t. M/ r% B8 q, |#define LEFT 0x02
6 P3 A6 g3 s2 C3 @8 s# C2 Y2 n4 k#define CTRL 0x04
2 J! r3 o" Z4 E( a. z# \#define ALT 0x08 </FONT></P>2 J9 b4 H- @' V( j h
<P><FONT color=#0000ff>int main(void) 9 |% V) h$ A. c. L
{ % B; x1 c3 Y+ Y" X% ]6 O
int key, modifiers; </FONT></P>
' M* k1 P6 `& s<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
5 [4 G& {6 i. B' b# w% vwhile (bioskey(1) == 0); </FONT></P>
( V3 P0 N+ J0 k, q" g3 ~6 d<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ ; y* D0 |0 K5 Q: S
key = bioskey(0); </FONT></P>: n$ K* ~# X2 C# W& \8 S6 v- B
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ % i( v( g5 \, F- g; i6 p; B
modifiers = bioskey(2);
/ h' B2 W* z6 ?if (modifiers)
, H" W1 ]4 K* m{ - @( J4 G# L4 R
printf("["); * i4 C9 @0 J" { H" o7 w K0 o
if (modifiers & RIGHT) printf("RIGHT");
5 w+ B3 w% v0 ?9 s- I4 lif (modifiers & LEFT) printf("LEFT");
5 B; R: S5 ?9 r3 e, O/ T! pif (modifiers & CTRL) printf("CTRL");
& H8 |, W% a3 }% C7 ]if (modifiers & ALT) printf("ALT");
5 S" A! }1 b3 n k- N( zprintf("]"); @4 D/ K0 R/ b; O8 S
} 3 B8 o. }: I6 W' \3 x4 {
/* print out the character read */ 4 W4 _/ s" d3 [9 T9 H& z3 [) [
if (isalnum(key & 0xFF))
E6 v) c' [* W9 Tprintf("'%c'\n", key); 9 x3 O3 x; @) d
else
% i) G: [, p9 z4 ]) o9 C! D5 F' t- ]5 kprintf("%#02x\n", key); / g1 k- ]% V# y; b4 L
return 0;
. A0 O8 h5 O% A}
: |& L9 E1 T/ H0 |: K6 E4 X5 q5 o9 M+ P+ _+ y
</FONT></P>
) ~8 }* L5 _5 L3 F7 c/ D<P><FONT color=#ff0000>函数名: biosmemory </FONT>
+ P5 J T- C1 r4 A功 能: 返回存储块大小 , r$ F- q- M: ]# N2 t0 D
用 法:int biosmemory(void); " |: M2 h+ `* d4 o4 ~) C/ x3 s
程序例: </P>
; J1 R6 ^5 _8 u<P><FONT color=#0000ff>#include <STDIO.H>
) f( Z2 Z: f4 w8 t( p8 {#include <BIOS.H></FONT></P>
& s5 M- f t) Y% e<P><FONT color=#0000ff>int main(void)
' f' G% i9 R8 w6 r8 n' u{
5 F5 y" u/ U- d4 i# y0 ]& w4 H. h. Gint memory_size; </FONT></P>
/ d6 {; |* [2 S! _& t<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ 0 U1 ]* _% {# B5 H2 @9 b
printf("RAM size = %dK\n",memory_size);
( A- K1 T$ |5 n( o0 `; Hreturn 0; 3 i, |3 A$ n V3 f( C: g1 S( s
} ' B6 X! f5 w' f6 p% t. Q
</FONT>" D7 N7 |7 l+ x# i" {# V4 p
+ i3 Z4 r% U, @6 F" K! q</P>) G: R4 N1 \- U& {0 A
<P><FONT color=#ff0000>函数名: biosprint </FONT>
% d f/ l3 @' X功 能: 直接使用BIOS服务的打印机I/O 7 g' Z! h' j) [ N0 C
用 法: int biosprint(int cmd, int byte, int port); ( o' A$ @8 t/ y1 J& a+ }! j
程序例: </P>! s9 x' P2 @% j5 l W
<P><FONT color=#0000ff>#include <STDIO.H>" r$ R) W6 V9 ]3 _6 ?1 x ]1 k. i1 P7 R! s
#include <CONIO.H>2 b6 l8 `) _; L: m" i V3 p
#include <BIOS.H></FONT></P>. W5 [" k# G/ ?! l% u1 f
<P><FONT color=#0000ff>int main(void) - g8 }6 Z' I' D
{
2 x; p5 A1 ^- M3 m9 C+ I#define STATUS 2 /* printer status command */
# x. ^4 K; T0 V, U- F$ t#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
& `! F7 N7 |1 Z/ M6 |<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
5 w: D' b+ b" s0 [( B, |' r<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
) C9 U, g+ Y' sgetch();
. r6 |0 n8 c ]$ jstatus = biosprint(STATUS, abyte, PORTNUM); ' y7 A- y: u% D4 n8 \4 ~
if (status & 0x01)
* `( O9 S7 v' N) { n' zprintf("Device time out.\n"); % P- Q D% b/ C! l" D6 H6 c5 j
if (status & 0x08) 9 r; u$ r! P0 G* T5 P* h
printf("I/O error.\n"); </FONT></P>! h8 i. r0 q" w, ?, g' ^! a V. f: |
<P><FONT color=#0000ff>if (status & 0x10)
& n j! m. w( K3 P6 sprintf("Selected.\n"); / c+ ~- x1 }0 r
if (status & 0x20) + o7 T# j7 k- |# I" R
printf("Out of paper.\n"); </FONT></P>
, E" v7 U9 V U5 A<P><FONT color=#0000ff>if (status & 0x40)
/ d+ P& ~" t+ L, ^/ E5 e& z- O) K- Nprintf("Acknowledge.\n"); , }8 y! @3 I$ b, ?* a
if (status & 0x80)
8 y, G' O$ w& tprintf("Not busy.\n"); </FONT></P>9 J7 I X; d. A; x7 z
<P><FONT color=#0000ff>return 0; $ K; Z$ {+ K# C2 p$ l! N: Z
} 5 I' G7 v7 Z4 r n5 K/ C
</FONT>
- P# ~( A1 v" _$ |4 |
9 `/ V$ B/ ~' R8 R5 E! a</P>1 X r4 X9 Q; g {
<P><FONT color=#ff0000>函数名: biostime </FONT>, f" k$ }! N8 B
功 能: 读取或设置BIOS时间
* R! B4 C* m) j/ p5 v7 B, P/ W6 |用 法: long biostime(int cmd, long newtime);
* z9 [3 G! w$ Z; Q: c) o* Q程序例: </P>& n- d2 U& A6 @9 F5 Y
<P><FONT color=#0000ff>#include <STDIO.H>9 G/ T8 T; \- W' [; }/ `0 `' d
#include <BIOS.H>5 A7 h ^8 R: _3 _/ L- }) ?; L
#include <TIME.H>8 p, G& C2 ?4 l. ^; [' ^& [2 }3 j3 [
#include <CONIO.H></FONT></P>
3 ?6 P7 b7 w' h* k' Y<P><FONT color=#0000ff>int main(void) ! n4 ]2 c3 T! F" p: i' X# a, G2 e
{
$ R/ O A% |) W4 Olong bios_time; </FONT></P>
! ~: v. }1 z M- p: z, o" G$ B<P><FONT color=#0000ff>clrscr();
1 |& k9 {% K2 L+ T7 Pcprintf("The number of clock ticks since midnight is:\r\n"); 3 g3 d9 O$ A4 {2 V' c5 O: {
cprintf("The number of seconds since midnight is:\r\n"); ! i$ K: n. D k
cprintf("The number of minutes since midnight is:\r\n"); 1 z+ v) f3 u' v& O* O
cprintf("The number of hours since midnight is:\r\n");
" o* u- T% B2 c; G3 V, i: }cprintf("\r\nPress any key to quit:"); " i1 G! K5 Z5 P6 W; v
while(!kbhit()) ; V- ]' l, V' ^1 r2 }" ]# p! o
{ % q f1 t; B8 ~' K8 D
bios_time = biostime(0, 0L); </FONT></P>2 b! O5 S4 P. M
<P><FONT color=#0000ff>gotoxy(50, 1); ! q! e1 A; U' n9 Q P& B
cprintf("%lu", bios_time); </FONT></P>
# A. k6 e7 }- h9 J- G0 T<P><FONT color=#0000ff>gotoxy(50, 2);
! Q$ {" w- Z# N, j% @+ ~cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>( i; q9 x& F4 h4 |+ I6 r$ i
<P><FONT color=#0000ff>gotoxy(50, 3); ) V) d* r( F5 R t$ {2 m
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
; x$ l, }0 w0 V5 o<P><FONT color=#0000ff>gotoxy(50, 4); 8 {) P. x- r8 p" q& Y9 }
cprintf("%.4f", bios_time / CLK_TCK / 3600);
, m0 D! @$ q: g- B( p1 w} ) V, f+ u; X3 ?
return 0; 1 H2 ]' k) l; X5 b# M2 i- k
} 0 e4 j$ g( H' A3 }" Q, ^2 q; Q7 G- X: V
</FONT>
& B9 }6 J& m$ Y( a
! o4 k4 u) `. D8 u</P>: g% [: e: s" O! B
<P><FONT color=#ff0000>函数名: brk </FONT>
; H# A) n$ i% R3 c: S. e8 a: [功 能: 改变数据段空间分配 ' n5 f& W3 \( }4 m+ S# p6 l1 T
用 法: int brk(void *endds);
9 Y5 q' I$ N0 U程序例: </P>6 _% ]+ ]0 l- Y8 f; P
<P><FONT color=#0000ff>#include <STDIO.H>7 D, q7 {/ e6 e4 h; o6 ~% G
#include <ALLOC.H></FONT></P>% d4 k$ B. D$ h6 W* k
<P><FONT color=#0000ff>int main(void)
2 O- G& C- V7 o. q{ , K- N( p1 A7 S4 T% h4 o* C: T
char *ptr; </FONT></P>
: I/ Q- R0 ]- d, j4 s( T Q2 E<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); 6 z5 z3 f, [% v& k$ h7 p. `& @
ptr = malloc(1);
0 t [, w) N4 Gprintf("Before brk() call: %lu bytes free\n", coreleft()); , B! o5 J1 r3 S$ X& Y
brk(ptr+1000);
: B6 _4 d5 M6 _' u0 `) Dprintf(" After brk() call: %lu bytes free\n", coreleft());
9 I+ @1 C% V7 x3 i0 `6 C6 ^return 0; 2 X1 _& W) T e! ?0 K9 v- t/ K
} " D8 c& P, X" l( @. J- }! w# ~
& \3 e. v' I# ]" V* F8 i, H3 I</FONT>
" q3 i1 n3 l5 J6 w" W* [7 s( E</P>
- v0 P- j0 i) M i0 ?- [0 `<P><FONT color=#ff0000>函数名: bsearch </FONT>
! U1 t/ U/ c! m$ U功 能: 二分法搜索
6 u: [7 p1 | |" M" y H/ i# r1 W用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
" ?* j9 e- T1 o' g5 [size_t width, int(*fcmp)(const void *, const *));
1 O$ N' s, q( U* m' J( ]! Q程序例: </P>
+ d5 @- X0 p: i; U, m7 U6 x<P><FONT color=#0000ff>#include <STDLIB.H>
& _. w- c: Q+ h#include <STDIO.H></FONT></P>
& _) X& q; q) J7 R8 B4 `/ l9 H<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
. w% N, q( X9 @<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
( I- Y# Z9 r1 R; h/ x. P2 n<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 3 K- K |1 e9 Q) f
{ F& \" o6 a0 | H2 p* ^2 E
return(*p1 - *p2); % v5 u2 H! P0 k- k# Y1 e
} </FONT></P>
) e+ E \" C/ D" O<P><FONT color=#0000ff>int lookup(int key) . L4 r4 }' ^% d
{
: v% y- K- o( {( ?int *itemptr; </FONT></P>
. B4 N, {" s; |9 M. ~<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
" B0 u7 y6 c7 F4 k* l- W( _$ S+ Vis needed to avoid a type mismatch error at ; t; Q# Y, q9 @. j! ~: n
compile time */
1 ]" L6 V' s9 Z' Z4 Xitemptr = bsearch (&key, numarray, NELEMS(numarray), & n) I' v. N9 S' f. K+ R9 D' s3 i
sizeof(int), (int(*)(const void *,const void *))numeric); " z5 G0 D$ v Z3 r
return (itemptr != NULL);
' u% S) p; B5 z: i- \/ G} </FONT></P>) r/ a; c1 S( Z. F3 |& r
<P><FONT color=#0000ff>int main(void)
/ E- ], _) L i, @6 b{
7 d% Z& K) Y" Cif (lookup(512)) : l/ {1 v( N0 F) M
printf("512 is in the table.\n");
1 d1 W2 A# n$ w9 }2 W: \5 _5 x5 |! a: ~% Jelse
6 k4 _( X% `0 V# }. xprintf("512 isn't in the table.\n"); </FONT></P>
& G6 h( ~4 F2 P<P><FONT color=#0000ff>return 0; 7 Z0 P5 n- c" x0 v+ i
} </FONT></P> |
zan
|