- 在线时间
- 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>
5 m9 x5 i7 V {4 [< ><FONT color=#ff0000>函数名: bar </FONT>
) Z. Z( d8 E. g* C) v% Q) h3 A功 能: 画一个二维条形图
, C+ R$ y! B7 \" O/ B, `用 法: void far bar(int left, int top, int right, int bottom); % T$ {9 U" ?5 I4 q8 k3 T# Z4 t
程序例: </P>% K( |; Q" n5 z( W/ Q! H7 {( q1 c
< ><FONT color=#0000ff>#include <GRAPHICS.H>$ L3 C; w0 d( Z4 F+ B8 l
#include <STDLIB.H>
9 m8 ~! M+ D/ d% h$ B#include <STDIO.H>% K* S9 v+ ?: i# ^ @% p3 Z
#include <CONIO.H></FONT></P>4 J/ J( A7 @8 x
< ><FONT color=#0000ff>int main(void) % w T& w: @7 ]. ^7 C5 }
{ # C( H. w) s# z1 }' p5 s
/* request auto detection */ 3 C# }* ~/ y3 X% B
int gdriver = DETECT, gmode, errorcode; 6 T5 C1 E1 X0 ~. B1 c. B: p2 h
int midx, midy, i; </FONT></P>! N( U$ w3 P+ j+ v$ u7 l
< ><FONT color=#0000ff>/* initialize graphics and local variables */ 7 n8 h& G+ x1 c3 S& e& _
initgraph(&gdriver, &gmode, ""); </FONT></P>
& ` |1 G/ G& @6 p) ^! J< ><FONT color=#0000ff>/* read result of initialization */ 2 o1 S5 p, `% w, B* v( {5 o
errorcode = graphresult();
* T) A' h' Q: Vif (errorcode != grOk) /* an error occurred */ ' j- A+ w. `( Y5 A
{ 5 U3 j( A( n# l: D& v3 A% h
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 ~. X1 r( ^2 l2 J& tprintf(" ress any key to halt:");
5 Y/ m8 @! D' Egetch();
0 R2 \8 F5 g' W" Fexit(1); /* terminate with an error code */ ' X4 O( @$ c' l/ Q; O# l# L6 W0 \1 v
} </FONT></P>
3 I {7 m% Z, m< ><FONT color=#0000ff>midx = getmaxx() / 2; " r0 @9 A! r7 t, p" \3 s% Z
midy = getmaxy() / 2; </FONT></P>
) S/ V9 X9 Q' ^3 _# }* p< ><FONT color=#0000ff>/* loop through the fill patterns */ & a' W" s0 z. `
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
2 j2 \3 d6 T0 w, C/* set the fill style */
3 W" v) O4 q+ S0 c; nsetfillstyle(i, getmaxcolor()); </FONT></P>; b& i& T* A" Y. X( T5 G* P
< ><FONT color=#0000ff>/* draw the bar */
# U# z1 x! R k: [0 x1 Hbar(midx-50, midy-50, midx+50,
: w7 h' G! l; f1 R$ Vmidy+50); </FONT></P>- \5 Y* a0 e8 C& \$ z
< ><FONT color=#0000ff>getch();
# q% l; e% v% v} </FONT></P>, Y# n, l# ~' d- `: A/ v; `7 a
< ><FONT color=#0000ff>/* clean up */ 8 m8 z5 A, b4 y& C( y
closegraph();
- J& K2 d) k1 d5 Qreturn 0;
& V: h- |- {; h1 E* ]/ i. v& \. b} </FONT>0 ?3 W; T4 z, E6 A0 R; y
$ t1 C, |8 Q8 [- {& I( [( i5 N6 w+ S* y
</P>
4 W: W4 h" L) e6 |) H! Y; C< ><FONT color=#ff0000>函数名: bar3d </FONT>
5 X* L5 W9 P, U: W# i+ x9 i' V功 能: 画一个三维条形图
' N& l% B' U5 }用 法: void far bar3d(int left, int top, int right, int bottom,
# c7 p) L2 f B- t& D2 q; qint depth, int topflag);
: t) p3 i {7 _: J# C, ]" Y; k程序例: </P>6 R8 ?* U8 h% f c0 ?* ?
< ><FONT color=#0000ff>#include <GRAPHICS.H>
! v5 H( g! t- ~: j#include <STDLIB.H>
6 a6 f8 h# h, x- \% R#include <STDIO.H>
( \" g7 d g3 J; K- U S1 E$ y#include <CONIO.H></FONT></P>
6 o* s& i0 x d. w/ m< ><FONT color=#0000ff>int main(void) 3 [, I2 I5 ]! d7 M* d( H
{ ' l. F! r2 n! }& w
/* request auto detection */
% U r: L, M7 B$ ~6 Jint gdriver = DETECT, gmode, errorcode; ' Q# |8 R: w8 w5 q" e, ]
int midx, midy, i; </FONT></P>
$ ^* G1 e7 L% @% v< ><FONT color=#0000ff>/* initialize graphics, local variables */
* |* b) v4 u- d; b5 g8 d2 @6 g0 einitgraph(&gdriver, &gmode, ""); </FONT></P>5 T+ H3 v6 @& C* g: k {. i
< ><FONT color=#0000ff>/* read result of initialization */
& b- ?) x3 H( L6 y0 Rerrorcode = graphresult(); & B2 d8 y) k9 X( j `/ M
if (errorcode != grOk) /* an error occurred */
1 J9 U6 ~1 d# a" E- d{
# e) F! e) G, k: Q( C2 m- bprintf("Graphics error: %s\n", grapherrormsg(errorcode)); - s/ x* J) S+ Y- _/ d( e) K4 L3 j- y: L
printf(" ress any key to halt:"); * [* _) U; }; V* Y+ P [2 S7 r& Z
getch(); " b# C: B: a1 T. B- Y
exit(1); /* terminate with error code */
1 N- u. Y8 y$ \} </FONT></P>" P# H! j3 h0 N! T6 y2 I
< ><FONT color=#0000ff>midx = getmaxx() / 2; - a( l. p: ?' M3 N$ y
midy = getmaxy() / 2; </FONT></P>
% Q1 c- ^6 D9 e Q5 x< ><FONT color=#0000ff>/* loop through the fill patterns */
8 ?/ f/ c: L, ?for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 9 \8 U; i6 M- R1 U( O# v0 y1 q
/* set the fill style */
! Q' P9 Q6 M! ?( |4 D# ssetfillstyle(i, getmaxcolor()); </FONT></P>
' B$ [! [3 N+ t4 e/ P& x* W< ><FONT color=#0000ff>/* draw the 3-d bar */
6 ?, j/ l" r4 r4 G" y# y9 rbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P># Q2 j [6 e$ N3 H, w4 {
< ><FONT color=#0000ff>getch();
7 [* w8 ^1 q* u! M. o- d} </FONT></P>6 {( l# k! o( t0 f: i! P
< ><FONT color=#0000ff>/* clean up */ 0 F4 Q$ L( J9 H4 d
closegraph(); 7 A Z6 i% P% S
return 0;
: a' o+ u! }6 \+ x. F3 \, L}
& g% V: S' Y% d9 i3 v+ ^& l</FONT>
/ s; b# w/ `2 R& E% R3 J M1 o8 _
: d$ T J& F: `" d) u</P>2 H8 f( C! U& |5 t8 y1 \; P3 x) I
< ><FONT color=#ff0000>函数名: bdos </FONT>* a2 V5 n! o7 v! {
功 能: DOS系统调用 4 h+ `* {; M2 Z9 \3 C1 e$ z
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
3 K6 e3 z, w5 \( y9 I. ]( o' q1 f程序例: </P>( x2 g w1 [% }6 ?0 r
< ><FONT color=#0000ff>#include <STDIO.H>
% A' A' a8 m( R! F#include <DOS.H></FONT></P>
5 U& y& d! y- M9 X< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
C) B1 L5 a3 [# r6 U. G! z+ A" E# Qchar current_drive(void) 7 W7 W X( t; ^( p
{
& t8 `& Z) ]2 Z5 ?8 rchar curdrive; </FONT></P>
2 x) @, L- }3 d/ |3 t8 l- l< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ ; }. Z- [- R6 P% `: s* t4 t8 J
curdrive = bdos(0x19, 0, 0); + v B& }: _5 r
return('A' + curdrive); & T3 t+ U3 k* }" w
} </FONT></P>
7 R( V0 f4 ~2 x3 P0 s< ><FONT color=#0000ff>int main(void)
- z1 |6 X2 ^" g" H: u' U+ N5 L t{ " Y4 i* a" C) i/ l1 S- f
printf("The current drive is %c:\n", current_drive()); 5 ^! q+ F Y* C. P9 r0 x5 c1 U& z
return 0;
4 q; ^' T6 r Y. o& @}
! b" y- {6 w8 v( X' A
# `2 `) x; S; L</FONT># z d* F. q) L: o
</P>
% R; E& G8 |: I/ U) [9 ?3 b< ><FONT color=#ff0000>函数名: bdosptr </FONT>- }% l+ j+ t* f! v I: c/ y
功 能: DOS系统调用
& {0 E& r( Z4 b6 M5 P8 t用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
7 G- w: e( C/ p: F, M+ \) g$ ~程序例: </P>5 R; D; e( @# a5 I1 x( F, K1 M
< ><FONT color=#0000ff>#include <STRING.H>) G/ d. c3 t0 m+ x6 ]7 z d( d3 p) y
#include <STDIO.H>
; Y" p2 f& V" s& k: M1 ~! _#include <DIR.H>
7 s6 C) ]& W3 b1 v* j) R#include <DOS.H>
# f$ H* U& ~: j#include <ERRNO.H>! A# L# F, w0 u+ A
#include <STDLIB.H></FONT></P>
5 ~) S% h' W' z2 N<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>/ R/ S, c6 }2 d+ R
<P><FONT color=#0000ff>int main(void) 1 u5 N- a, f3 q% {/ a, O% v$ e' V, }
{
( T9 e# G6 D, F3 |. @ cchar buffer[BUFLEN];
+ P# p7 A+ {' ]' s/ ^int test; </FONT></P>
3 T7 ^8 N; }& r, P" k( L" D<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
$ I- C+ P& t; \/ E4 Mgets(buffer); </FONT></P>5 U) w! @8 X7 Y, c) [8 M
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); # z6 y/ y* M, b% {& J4 Q
if(test) " R6 U6 |' P" N5 ?$ U) }$ Z7 N3 m) h
{
& e Z5 S, B$ Lprintf("DOS error message: %d\n", errno); / @/ W1 Z3 B4 x( i1 E9 Y5 I: ?
/* See errno.h for error listings */ ! D; j" ^2 _: y' W# r9 B3 g& j& e
exit (1); , q9 U0 L0 o7 W, r# Y' j1 y3 Q
} </FONT></P>
6 w, z: k% e9 G6 J+ {<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 9 d1 z2 L4 [# U1 ~6 J+ G8 m7 @
printf("The current directory is: %s\n", buffer); </FONT></P>% F2 t, O" }7 E8 _# b
<P><FONT color=#0000ff>return 0; 9 S( C2 ^! W( C' C6 ^5 Z2 |5 j
} 7 \( [6 `6 P: i/ X" v5 o: f
</FONT>
4 s9 C1 t" N0 l" r- K" s3 C& ~% [( z* y" n
</P>
0 n3 s2 ^$ b: @7 y/ v7 A0 s<P><FONT color=#ff0000>函数名: bioscom </FONT>& E) m& B) t( d; E2 @1 W
功 能: 串行I/O通信 9 O- \" d* A+ T
用 法: int bioscom(int cmd, char abyte, int port);
- |0 f0 i! w$ a; ]程序例: </P>
! _' y$ h; H& r) ]2 B<P><FONT color=#0000ff>#include <BIOS.H>
. O; M: ~6 i7 d9 h, j#include <CONIO.H></FONT></P>
* K8 U6 |4 ` b! ^8 T<P><FONT color=#0000ff>#define COM1 0
( c' V, m5 a3 o _3 v# X5 W- _#define DATA_READY 0x100 - H2 F/ g0 s* }6 a
#define TRUE 1
* ?+ }6 k/ [. p#define FALSE 0 </FONT></P>3 X# W9 Q4 e) `" p3 a
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>7 J: c( s0 w8 }0 M( W. C
<P><FONT color=#0000ff>int main(void)
* {0 I! n: l- g1 X# e{
0 E$ ?& O1 Z2 gint in, out, status, DONE = FALSE; </FONT></P>4 S# |. c3 M6 m) g7 O/ E
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
; ~' n8 Q% W3 R7 Rcprintf("... BIOSCOM [ESC] to exit ...\n"); 4 S: w3 f Q. j, l$ D
while (!DONE)
9 N6 `( ?# Q5 V/ l) @- c X7 m{
: z$ ]9 ~' V& U( T; z7 Dstatus = bioscom(3, 0, COM1);
: ^, m, ~! `; Zif (status & DATA_READY)
+ u2 }0 f' K( W- p: Sif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) * q. p' {6 V0 D0 Y; P
putch(out);
# A5 \1 p. C A& @if (kbhit()) ! f8 V" j( D, H2 F+ S& V
{ 1 X! [& E9 E' Y! m Q0 t0 }
if ((in = getch()) == '\x1B') - U, _/ O3 ?3 ?- m9 N8 u7 U! }
DONE = TRUE; 3 U/ m+ D$ t3 x( L' o& N
bioscom(1, in, COM1); ) n5 F S/ E$ n8 O3 h% F: g9 W; \5 [
}
* S' n8 q0 v" e- W A7 E; C- D} 4 v; Y# o/ G6 v+ F4 ]
return 0; , V1 N- ~; m8 Q9 b- d
} </FONT>5 C/ j# J, m& G
; L O% m/ m7 v$ | U" i
8 U7 Y! }6 F B* I</P> \3 [4 Z$ ~1 }- \" o
<P><FONT color=#ff0000>函数名: biosdisk </FONT>1 E% X4 A9 O5 u# e; z0 H8 A
功 能: 软硬盘I/O
- a- E. | E# W3 C. I用 法: int biosdisk(int cmd, int drive, int head, int track, int sector % i1 L; T+ p) [. r& e% A
int nsects, void *buffer); : E7 }3 @5 t0 A6 _* ^
程序例: </P>& \* y3 r# y; H. u$ c% U) {3 h
<P><FONT color=#0000ff>#include <BIOS.H>
9 h2 [0 E+ a h#include <STDIO.H></FONT></P> K ^6 A4 V u9 Y t3 e
<P><FONT color=#0000ff>int main(void)
3 R4 ^9 ~2 j2 v7 W{
( F: I8 M/ G. Q Z6 V" S7 N9 Y" R* Qint result; - }. ?) T% M8 n# _# C" [; r
char buffer[512]; </FONT></P>
2 [: P$ F* k8 y7 N5 i, ~. g2 [$ k<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 3 s( I- e1 j! Z
result = biosdisk(4,0,0,0,0,1,buffer);
% Y* O& D+ x1 V( Kresult &= 0x02;
. o' U6 ~' V7 [8 `" U(result) ? (printf("Drive A: Ready\n")) :
& _2 g6 V+ D6 G(printf("Drive A: Not Ready\n")); </FONT></P>" M. ]0 J* U) S0 |
<P><FONT color=#0000ff>return 0; 4 W" t. p/ p5 Z% u" b7 J! G# k0 z& E
}
: O8 h3 v7 K$ Y</FONT>
$ \0 T; b n( N2 `: T1 X. S* E _6 q1 y2 u. D8 q( z
</P># v5 O( X6 @/ p; Q
<P><FONT color=#ff0000>函数名: biosequip </FONT>. } ` t9 u( S& {8 g( n4 H
功 能: 检查设备 ; l9 B7 D7 T, z9 c/ C. Y9 ]
用 法: int biosequip(void); * f- E P! @+ A a! s& T
程序例: </P>7 b; C8 X& s6 t0 C* A
<P><FONT color=#0000ff>#include <BIOS.H>. ~& p- e7 f2 P% l
#include <STDIO.H></FONT></P>8 ?- x* X7 Y2 ^& }
<P><FONT color=#0000ff>int main(void)
& N3 H& ^1 w8 o) K- [! ^* i* E{
/ A! F" k# V0 d) z; V4 c2 _int result; , f1 L( q% X& m4 O. T( A* J
char buffer[512]; </FONT></P>
5 f* }& U( L- q" p# C# F6 J$ U9 u<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
4 g: Y5 I, r) L+ X9 B% r- K4 W/ ]9 eresult = biosdisk(4,0,0,0,0,1,buffer);
* X% w$ O$ r. C+ [7 {2 b7 z- P) i9 Wresult &= 0x02;
9 B$ c5 J& \7 H(result) ? (printf("Drive A: Ready\n")) : # s& y6 r5 K6 J4 ?/ c/ Z" \6 A7 s, O
(printf("Drive A: Not Ready\n")); </FONT></P>) O# E% U j* {2 d% o) U
<P><FONT color=#0000ff>return 0; ) H% @* N. h+ R. V
} 4 i( {7 C1 m$ A8 k* X) ?
</FONT>& Z/ {# c- o! G5 V# A- }6 M4 L
. ]! n# P+ _- z: [# s</P>2 P% o$ L& g; j7 J; z
<P><FONT color=#ff0000>函数名: bioskey </FONT>
: M& c7 l% } @! d* ?4 C/ w功 能: 直接使用BIOS服务的键盘接口
6 {* z9 _' t3 |; i) j. {0 b用 法: int bioskey(int cmd); $ t+ o4 M* a3 g- U
程序例: </P>8 c, ]- g* ~( e# u7 O- F
<P><FONT color=#0000ff>#include <STDIO.H>
& e {1 ~; q% H a; D0 U3 w; O0 r! j L5 p#include <BIOS.H>4 m# a7 u2 ?0 n7 [% S7 u
#include <CTYPE.H></FONT></P>
9 P% Q; ^+ j* [, ~<P><FONT color=#0000ff>#define RIGHT 0x01 2 O: l+ v7 y7 E+ ^7 B9 C1 }! G8 m
#define LEFT 0x02
2 D" C4 s: M( A#define CTRL 0x04 6 Z3 n7 z. r1 S
#define ALT 0x08 </FONT></P>. e4 s7 G0 Y; g9 K. J
<P><FONT color=#0000ff>int main(void)
' |+ ~/ Q' h6 p4 |{
$ g: ~( d6 f' ^9 Y$ @/ xint key, modifiers; </FONT></P>
% O. t4 C) M/ E6 k o# M) l+ V<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
7 b+ @+ G. i# w5 {5 _; U" N! A. Xwhile (bioskey(1) == 0); </FONT></P>0 ~- ?4 \* `+ ~9 o
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ - Y9 ]( E6 a( W0 N. g# [% T5 n L" W% ^
key = bioskey(0); </FONT></P>6 x3 K; ~5 F; { R9 f
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
% z$ r4 Q% h; n! D. qmodifiers = bioskey(2); 9 O! n* e* O- p
if (modifiers) 2 I/ z; x( ]; G [" c7 I0 |* B
{ 8 M! p3 N0 r' C3 X! J( K
printf("["); 9 _5 y) r% ^3 R4 j" H
if (modifiers & RIGHT) printf("RIGHT");
D4 T6 O- \& i( D8 Eif (modifiers & LEFT) printf("LEFT"); 8 q2 U+ o4 r( f+ R
if (modifiers & CTRL) printf("CTRL"); ) G2 g5 v L" ^( x
if (modifiers & ALT) printf("ALT"); f1 L: n) j% f# J) ?$ @, D
printf("]"); 6 M0 @: C" g F) U2 Q8 S/ k! o9 _
}
" }& x0 @1 ^2 ]& x/* print out the character read */
. N# a+ ^6 I# q5 I( tif (isalnum(key & 0xFF)) ! S' J9 Q; a# L$ r
printf("'%c'\n", key);
/ q" r, R! f4 A( qelse ; O6 @ Z; D' j1 z6 G- P/ f- M. N" O
printf("%#02x\n", key); 7 W5 C! \2 W" t# d
return 0; 4 d2 t$ Y. l' [2 i$ w+ A
}
4 x' J7 G; n3 I' C7 c# O) t$ w
: ]9 @$ B- F0 E- Y</FONT></P>
. X; { Z" H' T H<P><FONT color=#ff0000>函数名: biosmemory </FONT>! e5 t: k" F( ^; v8 e. R [
功 能: 返回存储块大小 % z6 b9 I: M/ n: ]# P0 u
用 法:int biosmemory(void);
/ m j; s' z6 p6 I程序例: </P>2 c! r2 g& D$ W2 c- B
<P><FONT color=#0000ff>#include <STDIO.H>8 a1 P" V/ J! N+ h8 s! K# S6 |
#include <BIOS.H></FONT></P>9 `* ~+ E3 w$ b9 a
<P><FONT color=#0000ff>int main(void)
+ I! ~6 T H6 O9 m* m8 N. H{ $ }4 R+ B3 }8 L7 f8 w
int memory_size; </FONT></P>; ^' S' k/ ] X8 M
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ : q: i/ |8 `( N* h
printf("RAM size = %dK\n",memory_size);
! f% x; x; j3 v3 B3 jreturn 0;
) ]8 s1 c7 L+ X( c) r7 @% Y} ; `6 r/ i6 l- n) o6 t" k8 p0 s
</FONT>5 h& I5 A1 _. M) i! m. g2 @
& R" m3 J" O. \. m7 W' H4 s! h</P># j2 L- v1 \' P9 A
<P><FONT color=#ff0000>函数名: biosprint </FONT>* h0 C n9 ^ ]& p7 W3 h" t
功 能: 直接使用BIOS服务的打印机I/O 9 z. Z/ _4 u3 v6 M9 F
用 法: int biosprint(int cmd, int byte, int port); : R E; n. n. D+ p( n
程序例: </P>
' ~( n) W' _7 Z* Q z9 {<P><FONT color=#0000ff>#include <STDIO.H>1 y: L: C. _' K: v
#include <CONIO.H>3 K, y6 H/ a$ d+ F. @8 l
#include <BIOS.H></FONT></P># Z2 r2 i' P9 p7 d: D! Q
<P><FONT color=#0000ff>int main(void) % J; ^. m, u; r3 O, ~6 \0 ]/ \/ A
{ ' x( I% o4 h ~' v `* T2 [1 a/ E
#define STATUS 2 /* printer status command */ + i; s$ q- a- B* s
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
. G! |& B% A# M. _& o/ w0 t& {( s<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
. A/ U2 H3 U; Z( P<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); " N- o( W3 N i" G9 v
getch(); ) a3 |$ u0 p2 [, W+ M
status = biosprint(STATUS, abyte, PORTNUM); / ]4 ?& o* B. j8 u, T* S1 @
if (status & 0x01) 7 r2 ^( p6 `& k
printf("Device time out.\n");
b) x3 _3 d$ U3 h; H) y/ x: a# hif (status & 0x08) % l) d9 v& J0 O3 P- O# m4 `
printf("I/O error.\n"); </FONT></P>) h, f: y' |: _% O2 b2 }" d
<P><FONT color=#0000ff>if (status & 0x10) 6 W* k* K. w' b2 O( h( P
printf("Selected.\n");
) {4 c6 F. n y1 \) @; h) Hif (status & 0x20)
1 S3 `/ b% |! E- r7 K. L8 kprintf("Out of paper.\n"); </FONT></P>
' J" u/ a, J5 p* g. M<P><FONT color=#0000ff>if (status & 0x40)
v) ^" y- G$ U% Hprintf("Acknowledge.\n"); : a! T. _9 N" P
if (status & 0x80) ' w& `+ b+ a# R2 n+ ~
printf("Not busy.\n"); </FONT></P>
! y( b/ F% V1 r6 E& P0 u<P><FONT color=#0000ff>return 0; 5 ?6 \1 v/ A5 i
}
$ x ^* F& G, ]3 B$ z9 @ o</FONT>( R4 U/ t9 V2 {
r7 q9 U. R) H; {$ p) m
</P>( [+ H' G& }( k; N t' B* E. o
<P><FONT color=#ff0000>函数名: biostime </FONT>
; |8 T- X6 I( e' D/ ^功 能: 读取或设置BIOS时间
* `' I$ L' n$ J; k4 e/ ~: o; t用 法: long biostime(int cmd, long newtime); & j) S$ D2 N& g) V$ I9 \; P1 Z3 ^
程序例: </P>
4 t( U# f9 t" g( |3 z<P><FONT color=#0000ff>#include <STDIO.H>
1 Z3 r9 f8 N( F9 U9 A#include <BIOS.H>
" _" O& V% u; v. u0 V8 v#include <TIME.H>8 n1 R0 w" ~2 e* K. v: F& P
#include <CONIO.H></FONT></P>. Z+ t- r& ?4 |4 t5 N7 o1 J
<P><FONT color=#0000ff>int main(void) 7 Q# [( s @ h8 ~% u, P
{
# I( F I7 @! ~, zlong bios_time; </FONT></P>9 k j+ F) d- I
<P><FONT color=#0000ff>clrscr();
6 F' \: \ |& x$ S6 N) icprintf("The number of clock ticks since midnight is:\r\n");
, u M" L- y8 M d, O9 Rcprintf("The number of seconds since midnight is:\r\n"); ) o7 b: ~+ o& |; }: j; `0 J5 I3 V( n
cprintf("The number of minutes since midnight is:\r\n");
: C" P9 i: ]0 D3 T3 F8 r/ X3 Ncprintf("The number of hours since midnight is:\r\n");
8 D9 r) g# o; M' p! bcprintf("\r\nPress any key to quit:");
+ I3 m5 h( A! C% Y, l( k/ R6 O4 ewhile(!kbhit())
7 j) ^- \# w0 E7 m& M# H4 H0 a{ 1 s6 ? N" u3 O# T7 D+ x. A4 d
bios_time = biostime(0, 0L); </FONT></P>
. C- M& q6 V- v5 }* r<P><FONT color=#0000ff>gotoxy(50, 1);
! _, u( p1 _" o$ ocprintf("%lu", bios_time); </FONT></P>
# \4 Q- f0 N3 `$ F- W; w: [# f- T<P><FONT color=#0000ff>gotoxy(50, 2); % H0 p' z' N4 H7 ^% i
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>$ a3 T. n4 M4 K; Y" o
<P><FONT color=#0000ff>gotoxy(50, 3); " j3 @# z4 b! {: u# _3 a$ S& }. J
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
( I8 l% z+ T) p5 f# K$ I: k<P><FONT color=#0000ff>gotoxy(50, 4); 6 t1 u7 a$ o& b L+ |5 ~) | [
cprintf("%.4f", bios_time / CLK_TCK / 3600); 2 i& i& g9 ], W3 x6 m: ]
}
" i7 u x* N% U- c Zreturn 0; / s, x' M' Z7 Z7 F4 X
}
' F/ D8 U! r; T6 V$ y p</FONT>
O+ z0 [5 ]0 i) l, Y, J/ k% R3 l. h; ~9 x) N1 A+ @8 g4 e
</P>. z6 S$ X) O/ i- p) Z5 h
<P><FONT color=#ff0000>函数名: brk </FONT>, a, T; O$ @' c1 e) J, v1 z1 `. i- @
功 能: 改变数据段空间分配
: ]9 a, C0 M, F用 法: int brk(void *endds);
0 k4 q+ N9 P! m, l# d+ T程序例: </P>% b4 z. w' \" q: J; A5 [9 P/ A
<P><FONT color=#0000ff>#include <STDIO.H>
- y- T$ b7 \9 d0 P* P$ h#include <ALLOC.H></FONT></P>
0 B4 ^& S/ U/ z& S1 W5 R: C% i<P><FONT color=#0000ff>int main(void)
+ z0 B* f9 \" G{
7 e5 F$ _" y- | o( j0 dchar *ptr; </FONT></P>
- J. H8 g6 R! c1 \9 _$ g<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); ( r1 l2 T6 E) E# X/ b8 U
ptr = malloc(1); , Y6 g' x/ j& c( `) V f1 B( S3 g
printf("Before brk() call: %lu bytes free\n", coreleft());
5 q& ]( K- }2 S3 p4 j- ?# b6 P. {3 Rbrk(ptr+1000); ' k$ K' A. K5 `* x% A& W! \
printf(" After brk() call: %lu bytes free\n", coreleft());
# W `9 h5 Y* g+ L. ?return 0;
6 c- W' [# ]8 {) b! h} ; Z5 I7 v7 j D- S
; _: X$ N G- Y, F/ f5 O& k
</FONT>
- [' \, r4 {" H3 s# u</P>
# O0 \' M \6 Q9 T, z<P><FONT color=#ff0000>函数名: bsearch </FONT>) d* b7 I/ I" B
功 能: 二分法搜索 0 V h# a% P" _" i2 S4 E" P$ E+ y
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
{4 A$ V) }5 M/ ~1 \" |& j& @$ e: tsize_t width, int(*fcmp)(const void *, const *));
# M4 O, b6 l0 [. w0 N! \6 v程序例: </P>
) C2 S) g; d: c* B$ S' [<P><FONT color=#0000ff>#include <STDLIB.H>) s" a# @" Z" C" S& T# B/ H
#include <STDIO.H></FONT></P> q% Q- L6 w- T$ o5 X7 C
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P># J# ~3 t% W t8 Z& j
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>+ k& t" h. O2 J" k
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) `+ I7 `- N% |. k+ q8 R* p
{
: k9 B6 Z3 n; U. ireturn(*p1 - *p2);
" i7 n" Y9 U( g6 h} </FONT></P>
% w& a% d$ c) @1 ]4 w<P><FONT color=#0000ff>int lookup(int key)
l1 g9 J- t! P" ^{
- y/ |: @. q, ?1 U% sint *itemptr; </FONT></P>
, W7 G8 n- r% T<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) , o: y+ |: K( N: x2 y
is needed to avoid a type mismatch error at , l2 s) h" l" M" J6 W0 t/ z3 y
compile time */ , u: {2 R( ^: ?! y( h1 ]
itemptr = bsearch (&key, numarray, NELEMS(numarray),
- `8 R- x/ \- m* [: @sizeof(int), (int(*)(const void *,const void *))numeric); * G5 c. _) h- }: f8 e% F
return (itemptr != NULL);
& ^2 \% @, z( v6 j: Z} </FONT></P>
$ `6 T& C* t9 w<P><FONT color=#0000ff>int main(void) ( c# H q5 h: n( o$ K2 e/ D# c
{ % Q2 E& @3 S; k, F. F
if (lookup(512)) 3 _6 W8 x* T# X5 D: m# {
printf("512 is in the table.\n");
* o3 I: P) l' i. ?else
2 h/ V9 r+ [$ Cprintf("512 isn't in the table.\n"); </FONT></P>
' f/ W, V# r& Y) i3 g- |<P><FONT color=#0000ff>return 0; % k" f; M# Q+ l, K, A$ ~+ S
} </FONT></P> |
zan
|