- 在线时间
- 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>
, l. D" f& |* N; @0 \* h) {< ><FONT color=#ff0000>函数名: bar </FONT>. Q* ?' l; I- a( r, S
功 能: 画一个二维条形图
/ u1 i) S) M! ], j/ J) d用 法: void far bar(int left, int top, int right, int bottom);
) |; T" f+ i1 @+ C程序例: </P>
. Q* e8 L/ `" z5 z0 h& B< ><FONT color=#0000ff>#include <GRAPHICS.H>: I/ f& V6 D0 g7 {: Y: c
#include <STDLIB.H>
2 a, o& G* |' E3 }' J#include <STDIO.H>
0 E/ z7 q' q, z% D b#include <CONIO.H></FONT></P>
/ r7 W7 {1 v2 _8 N2 F$ a- A: @< ><FONT color=#0000ff>int main(void)
; Q+ f5 L/ E) S. ^{
4 d5 f! S( O' ~9 \7 c/* request auto detection */ 1 d" e) m- M) F Z; \( @9 A
int gdriver = DETECT, gmode, errorcode;
4 J2 M& B8 U, m1 ~int midx, midy, i; </FONT></P>- L: s' n9 S$ B
< ><FONT color=#0000ff>/* initialize graphics and local variables */
9 g. M2 v: Q0 X0 r3 ~9 i* {1 Yinitgraph(&gdriver, &gmode, ""); </FONT></P>4 g' Q( Q, q4 f8 [* S" d. U, `4 M
< ><FONT color=#0000ff>/* read result of initialization */
% G' h8 `+ m) @8 Y0 ?6 W2 d8 Kerrorcode = graphresult(); 3 K/ t/ y' ]8 u/ N" D2 y4 v/ [
if (errorcode != grOk) /* an error occurred */
1 |; ~3 q$ t* w* D{
0 ~; g0 @& b+ l& X6 ~- Jprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, b$ j( v% m! B& q: C! v& u. |printf(" ress any key to halt:"); ( h7 H! z$ ^0 A0 z: F7 W4 F$ `! W
getch();
2 o3 b) L) W# {2 _0 Mexit(1); /* terminate with an error code */
7 t0 v- ^1 g0 w2 _} </FONT></P>
5 [ Y ~$ W p6 n: O6 W< ><FONT color=#0000ff>midx = getmaxx() / 2; 9 v* g8 L5 g8 p B ~( I
midy = getmaxy() / 2; </FONT></P>$ b: }& j, j7 N- L
< ><FONT color=#0000ff>/* loop through the fill patterns */
A- R i7 U& _6 k, U4 p: Pfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { # |# v) w. q6 l& z( e2 h1 i
/* set the fill style */
# {4 R2 y" h( Bsetfillstyle(i, getmaxcolor()); </FONT></P>4 O$ S& K$ q( q8 [) O' u8 c; F
< ><FONT color=#0000ff>/* draw the bar */ `3 J8 v3 ^, p; n
bar(midx-50, midy-50, midx+50, , V7 \4 |5 q; g: V/ U( J5 D
midy+50); </FONT></P>+ M0 _- a, m# n" {. t6 Z0 Q
< ><FONT color=#0000ff>getch();
3 H5 v& ]7 M' E3 t} </FONT></P>
7 J( [, k) }7 r) v< ><FONT color=#0000ff>/* clean up */
2 i a% d: b- H; B3 n9 c. E1 Eclosegraph();
4 h5 g6 F8 z* z) i! lreturn 0;
6 G( V% M" X; O5 Y$ |- a} </FONT>3 x2 S: ^! ?, M O/ T' _0 g2 e
6 [/ p- v9 {( _) t, K2 P
0 [/ D K7 m; R6 N" X1 m/ Z
</P>( R* |1 I" E5 |8 Q+ u/ ]
< ><FONT color=#ff0000>函数名: bar3d </FONT># Z- Q$ |3 U5 g- |
功 能: 画一个三维条形图
. s. w; o- H& P! x" K6 J; t9 |用 法: void far bar3d(int left, int top, int right, int bottom,
8 M7 S" w6 G/ d2 E1 qint depth, int topflag);
3 | F6 R5 m/ T& s+ D1 T- Z程序例: </P>
. {1 A/ v, R2 F' u& Y2 r& |/ }< ><FONT color=#0000ff>#include <GRAPHICS.H>& }+ C. b6 p9 I' g: T
#include <STDLIB.H>0 f$ {0 X1 x% Q( k
#include <STDIO.H>
) y8 O4 i! Q) F7 m! U#include <CONIO.H></FONT></P>4 \: d: k! a, W5 e( r
< ><FONT color=#0000ff>int main(void)
! u; ~! z7 e3 ]2 k- z{ 4 }2 O; c6 q* n& X" a
/* request auto detection */
6 [# y2 N& z- r* d3 @7 U+ _7 Aint gdriver = DETECT, gmode, errorcode;
3 P B) _. x9 V7 D. U# Oint midx, midy, i; </FONT></P>! p; q! H( {. r; K a
< ><FONT color=#0000ff>/* initialize graphics, local variables */ ' S! B1 c/ ^ J( ]& I
initgraph(&gdriver, &gmode, ""); </FONT></P>
& P" s7 Q4 Z0 ]7 e6 {< ><FONT color=#0000ff>/* read result of initialization */
5 d8 x& q9 U/ j Kerrorcode = graphresult(); 1 n) Q* L2 {; c! J q! k
if (errorcode != grOk) /* an error occurred */
0 Q# ~" R4 ~4 Z) x/ h$ o7 D+ a{ & {$ W$ e8 ^/ a* M
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 e! k2 g2 `; ?4 K
printf(" ress any key to halt:"); 2 z2 y& w* c) V7 p% l' s
getch();
3 J* i* u( X8 q2 ~8 I, I. ^2 wexit(1); /* terminate with error code */ * h6 o6 Q/ l/ X+ L X. \
} </FONT></P>( Q1 `- Z. ^1 a3 u m' |" F6 C
< ><FONT color=#0000ff>midx = getmaxx() / 2; ) a) _2 x% e$ e' [& b
midy = getmaxy() / 2; </FONT></P>: ~$ {6 J1 E; g U0 U$ Y
< ><FONT color=#0000ff>/* loop through the fill patterns */
7 S9 m8 {2 @7 e0 O8 D Gfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
" @# d6 t- n! F/* set the fill style */ ( ^ V% d+ p9 w) C9 X/ h
setfillstyle(i, getmaxcolor()); </FONT></P>5 d" v$ y! Z% h* _7 g0 @4 Q
< ><FONT color=#0000ff>/* draw the 3-d bar */
$ r% M8 H) l5 `( A; {# Dbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>& ?/ x& C( H0 ~2 a
< ><FONT color=#0000ff>getch();
$ X/ C. J# I' S/ ~} </FONT></P>/ k1 Y9 C) D& S1 Z9 @7 R$ o
< ><FONT color=#0000ff>/* clean up */
) [. [7 b. b) {5 K, `& Cclosegraph(); 5 b) ~5 l: H9 P6 D, q
return 0; 2 W* `; }' g5 j) ?
}
6 \0 Q; l# k& W" W</FONT>
8 A# ~. ]$ A0 [: v; T/ w
% H8 A7 g7 w/ P& S% U</P># c* w2 n3 R7 e5 d& n
< ><FONT color=#ff0000>函数名: bdos </FONT>
0 } C5 n) Y$ I9 h0 m功 能: DOS系统调用
4 F. {! o: t6 X+ b) J, r用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); ( E6 u4 X$ {6 j
程序例: </P>; r( l* Y$ f; P0 n5 ], G! }# s
< ><FONT color=#0000ff>#include <STDIO.H>0 B" ^+ v4 H# o1 k9 P7 u
#include <DOS.H></FONT></P>( w! U) H2 I* E& z4 U7 s
< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
- `3 m" w! V- a% B2 K/ k l, dchar current_drive(void) J: L7 J' d6 |; o& d
{ 0 [5 T! ?5 E5 |9 j9 q3 {
char curdrive; </FONT></P>
* n& b3 C* A4 v- W< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
+ I7 }! e5 _4 I& W& ~curdrive = bdos(0x19, 0, 0); : S0 p9 m6 n# ~8 y, D
return('A' + curdrive); 5 q! q0 J3 q- @3 m( N- ]( i$ n
} </FONT></P>
\- s7 j. L, O/ `< ><FONT color=#0000ff>int main(void) 1 {# J( {% {- L# Q9 I/ ?( J; c
{ . y" m7 `" t) }( M1 W8 R2 D5 o
printf("The current drive is %c:\n", current_drive()); 9 i, z0 p9 Z0 h) s' Y9 ~( w
return 0;
* O' X9 R, D& `( ?}
$ x: _7 N0 D- U" \
4 Q9 C6 p* l+ {' T8 k</FONT>% r. y+ \2 ]# `2 W* S5 k1 ] D
</P>! f6 U$ q* v; B9 k
< ><FONT color=#ff0000>函数名: bdosptr </FONT>. a2 P' N3 e, F
功 能: DOS系统调用 ; p8 ~ M5 Y! h T
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); * h# ^* ]2 g3 @* ?3 g
程序例: </P>" U! p0 |% L. Q- }. G* D+ B6 l# N
< ><FONT color=#0000ff>#include <STRING.H>
! I9 W4 q& _) k G#include <STDIO.H>
# p9 T! M' L9 G8 h! r9 l3 L#include <DIR.H>4 G, s; o6 D3 C# M$ X1 V
#include <DOS.H>
9 n5 D b4 o# f1 d+ C7 w#include <ERRNO.H>
# Q% j& ~% R) v#include <STDLIB.H></FONT></P>
. W0 E! Y# i2 O, v5 d" r<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>* `8 m! _7 V: J9 J
<P><FONT color=#0000ff>int main(void) 1 M+ }! V2 P4 o c1 T( G* L
{
D3 ^3 G! o. b7 {5 r7 dchar buffer[BUFLEN];
" O U, e2 O1 F2 B+ ]9 uint test; </FONT></P>
/ Q$ ^! T# l1 t" B8 o<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 5 x2 m$ o l# O" k
gets(buffer); </FONT></P>
: j+ u+ X' ~$ ]1 U<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
" A' o3 @: }& m# S: ^/ g! zif(test) 9 Q6 E' K; l0 }/ ]6 N$ T: }! h
{ . ]5 Q5 q. P" y5 ~0 E
printf("DOS error message: %d\n", errno);
! R) ^ F7 T0 \% P5 d2 T5 ~/* See errno.h for error listings */
9 a0 {0 P8 j+ U: Nexit (1); & b& Y7 g% b4 d% l
} </FONT></P>
- f4 p% j4 k$ J4 ~<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
# ^1 o7 o) w1 q# x a! e& Y5 P. Cprintf("The current directory is: %s\n", buffer); </FONT></P>
* v" J7 p& C% U2 {% E) ?; K<P><FONT color=#0000ff>return 0;
9 Y% X7 g: }3 m}
- R! r4 |! _! g" C* g</FONT>3 ~0 K' S9 \& V# f# N. C& n( a
" B3 m8 P* Q1 K! Y0 L9 ^</P>
# t) F# k0 K- ?<P><FONT color=#ff0000>函数名: bioscom </FONT> i4 @. `" A3 x/ O( {2 n& H$ k
功 能: 串行I/O通信
) @7 p' l' e# H" _/ a% Y# ?- Z用 法: int bioscom(int cmd, char abyte, int port);
1 j( g4 j$ m) X- |8 L; f- }( e! T程序例: </P>4 d4 t3 Z; m X6 a# S' `
<P><FONT color=#0000ff>#include <BIOS.H>
% i# V5 S1 r) ]5 ]: i! |! l; Z#include <CONIO.H></FONT></P>9 m! T3 n. U- b
<P><FONT color=#0000ff>#define COM1 0
# f' X/ S [5 J( N( }, @#define DATA_READY 0x100
% \4 ^3 ^$ R* t3 T! J1 \#define TRUE 1 ' b+ g, { A; X) j/ e: ~
#define FALSE 0 </FONT></P>
9 z! x1 U7 L) k/ f" ]8 n( g<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>5 u# o) |3 _; |- k# E% o4 k( `
<P><FONT color=#0000ff>int main(void)
5 v3 K, M3 e+ V: a9 b{ ; P5 a" F1 U' v3 V) Q
int in, out, status, DONE = FALSE; </FONT></P>, f7 E5 F4 V4 Q
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); 5 `' E; w, c$ b% S9 ?: P$ ]' s4 A
cprintf("... BIOSCOM [ESC] to exit ...\n");
: V/ f. A$ |( f/ f4 I5 s% pwhile (!DONE)
' f D8 x$ B# d) v" h6 Q( A9 q- c{ % w: R0 _+ ]+ D5 B9 o7 b/ Q
status = bioscom(3, 0, COM1);
$ M) e' ~( l6 bif (status & DATA_READY)
$ k$ }' Z) a8 r; x) jif ((out = bioscom(2, 0, COM1) & 0x7F) != 0) + s/ J! T0 c* \" p. W# F4 \
putch(out); 7 c$ ^8 _0 U+ [: {1 Y8 p$ K% A# A
if (kbhit())
: @ l9 [$ o5 g0 c{
+ I/ r8 t) k1 r, M! X) m Bif ((in = getch()) == '\x1B') 4 r4 E7 H |, r/ l6 K, T, s& O
DONE = TRUE; 1 r9 x. T8 [4 a8 y
bioscom(1, in, COM1);
' n9 A& j) w- _2 M8 A}
. Q/ f' M1 ?3 X B8 U$ _}
6 U# L+ W+ A8 jreturn 0; : @; |2 Y* @* _. N! e5 P
} </FONT>
8 g+ z" a- B* Z/ [4 h/ p& B3 a6 B5 D( a( X" Z
* K& i( K1 H$ \
</P>9 Y, ~1 N6 j& ]* |
<P><FONT color=#ff0000>函数名: biosdisk </FONT>
3 D- `# x t) A# {功 能: 软硬盘I/O 1 [6 L4 R5 B/ O* A4 N
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 1 V$ U, t0 Q2 l5 w2 o$ Y6 \4 ]6 F5 |0 t
int nsects, void *buffer); 7 a$ g" q0 Q& w, X
程序例: </P>
o- M# k' x% w. s" V5 S) [<P><FONT color=#0000ff>#include <BIOS.H>
% {3 A) t/ P0 r' V- x8 }" ]#include <STDIO.H></FONT></P>
8 E/ m# @- a. m- b5 @, i0 U<P><FONT color=#0000ff>int main(void)
9 {) I6 w4 S/ e! Z0 I3 g{
" N' \6 l/ J& u( M" @. aint result;
5 k) k* Y; j& K) tchar buffer[512]; </FONT></P>, l) _" q# K( U
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); ) ?- D, w# O2 n& v
result = biosdisk(4,0,0,0,0,1,buffer);
9 H0 n0 t: I9 a- a7 J/ mresult &= 0x02;
, v& t& S; w* U% _! w" R' y(result) ? (printf("Drive A: Ready\n")) :
/ f; U ^* Q+ y3 ](printf("Drive A: Not Ready\n")); </FONT></P>
R) B* o! @8 [/ D8 K( M7 T<P><FONT color=#0000ff>return 0; # T5 |$ i% ^. g9 W' n
}
4 z8 T& t+ R- T</FONT>
9 \* K) D$ `/ i- l) P' M4 J5 h7 b1 o3 N) J3 u
</P>
. x1 R) e( H) f<P><FONT color=#ff0000>函数名: biosequip </FONT>" M1 I6 A% M& ?/ F, D
功 能: 检查设备
3 W# z) r4 X+ e5 s% `用 法: int biosequip(void); " Z* }; y2 M. T2 }, f. z
程序例: </P>: h* T3 o. B& B& d5 d% P, H5 \
<P><FONT color=#0000ff>#include <BIOS.H>
( l9 P, [/ G* ]# r, G2 l#include <STDIO.H></FONT></P>9 d0 b4 M: h; ~! J
<P><FONT color=#0000ff>int main(void)
6 d6 I: ]# Z. d9 a* ]{
7 m% ?3 @7 t7 S! {1 k% a: jint result; 2 S1 J _- B- u8 ?* {3 r
char buffer[512]; </FONT></P>. D7 M9 K% s! Y U
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
6 F1 s/ _) v/ G( y3 tresult = biosdisk(4,0,0,0,0,1,buffer); 3 @/ ]- C# W. P4 h( d% H- C. Q2 ^
result &= 0x02; / I0 \% ]% U7 _) R* @* ~% S5 W" K2 J
(result) ? (printf("Drive A: Ready\n")) :
- ~; Q' Q2 C, @$ R( D1 w3 L; i(printf("Drive A: Not Ready\n")); </FONT></P>7 E" }. n+ u' z$ }* ?/ K/ a
<P><FONT color=#0000ff>return 0;
3 T: v! a( o! g1 T} ( ~: H# _& l# e; [
</FONT>
; _9 {+ e3 g: u- m' t5 a& V8 A4 F k
</P>
# F+ W6 |- i$ c3 O6 J2 g<P><FONT color=#ff0000>函数名: bioskey </FONT>
( I$ U5 G8 X" ~* Q" R* H功 能: 直接使用BIOS服务的键盘接口 8 S* M- W2 R! z9 X4 ]' @
用 法: int bioskey(int cmd); ; h9 \8 ~/ X$ B M. C, y& g
程序例: </P>. o; q( I0 A4 p+ ~' F9 h) q0 U8 R: N
<P><FONT color=#0000ff>#include <STDIO.H>$ s. \- P2 J% v! x+ s
#include <BIOS.H>9 r: f6 a/ K" D8 R6 f3 |, j1 o, z# j
#include <CTYPE.H></FONT></P>
$ u& `. J6 z* [; a* C<P><FONT color=#0000ff>#define RIGHT 0x01
: d1 t6 _7 |) B& a5 _, b8 \#define LEFT 0x02
2 K( e% G* { C/ R#define CTRL 0x04
. b$ E( _% k9 i+ ]5 p& q#define ALT 0x08 </FONT></P>
$ i/ U: y! w/ R, t8 P% X<P><FONT color=#0000ff>int main(void) , G9 v2 }/ E1 K" u0 r4 d
{ 6 G! @$ n6 B' V, o3 y
int key, modifiers; </FONT></P>2 I$ y4 X; A- L$ \% O
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
% Y* |& e8 R, [) J( W1 P) v. P6 M; \while (bioskey(1) == 0); </FONT></P>
! B7 g& j* [/ h: O# |5 e<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ 8 I5 F$ [4 m" x8 ?
key = bioskey(0); </FONT></P>. u+ a3 S* b r( l9 T- W
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 6 v) @; D' `4 {/ { s2 W
modifiers = bioskey(2);
( _- C# x. i# T0 C ^1 B5 |2 _if (modifiers)
* V9 V: ~! x. W; _' [ i6 L: U{
1 X5 y3 |" H+ _" {" mprintf("[");
! g/ x6 z) a5 g% W' F( r- Gif (modifiers & RIGHT) printf("RIGHT"); + v1 {; I! e t/ b3 ?4 H
if (modifiers & LEFT) printf("LEFT");
0 Z# y+ t/ @! w$ D- G% Mif (modifiers & CTRL) printf("CTRL"); + ? g5 y: y8 W! t
if (modifiers & ALT) printf("ALT");
8 s$ s" ^% a+ Y) ?8 f1 }' yprintf("]");
# O+ x( p" W/ q+ z}
( E9 `7 k( R" V/* print out the character read */ 1 r. o; k( a: k/ P/ u
if (isalnum(key & 0xFF))
( u7 p0 `/ f. T% m f0 r& [. yprintf("'%c'\n", key);
, h' \8 ~8 K, g. B: l$ [9 H4 ~else ( R& v! Q4 J4 c# ?& G/ g6 N
printf("%#02x\n", key); " `" ], E/ ?2 z! Z
return 0;
% l1 A& }( |9 A3 I# T} . U5 u6 N4 E. ? R2 M9 F/ d
4 b B: {5 @4 y! M6 E3 Q1 t8 o</FONT></P>
* H3 P, d1 G6 E1 o! Q- E<P><FONT color=#ff0000>函数名: biosmemory </FONT>4 e; q, r7 Y; @! P7 Z; o3 Q
功 能: 返回存储块大小 , i4 o. X$ i; L) |; L% k
用 法:int biosmemory(void); 2 f- V4 g% M$ r% Y+ t$ E1 \% \
程序例: </P>+ i, Z3 I3 U7 r9 J, S, c. ~
<P><FONT color=#0000ff>#include <STDIO.H>
" C1 G, |% z- R$ e* j#include <BIOS.H></FONT></P>
6 I% ^, }' t! T<P><FONT color=#0000ff>int main(void)
/ Q5 Y9 _/ B9 f( E{
5 q" \8 z$ O j, t8 Oint memory_size; </FONT></P>
a4 n1 n* P0 @6 V1 ]7 N<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ X" w4 @; N$ g# o
printf("RAM size = %dK\n",memory_size);
' Z( l, t. c$ v6 z+ f: wreturn 0;
9 Z2 a/ F1 g* ?) E2 b} " Q3 u+ Y( Q* w9 Z
</FONT>3 J) z5 H9 q$ G r# v& C5 m2 F! X
2 C! P0 k# X' L( w
</P>
/ S9 r8 Q! ]. I<P><FONT color=#ff0000>函数名: biosprint </FONT>& h5 F; j6 ^# _( m8 Q: O9 i8 p
功 能: 直接使用BIOS服务的打印机I/O ' X" Q: l2 t' J2 u7 }
用 法: int biosprint(int cmd, int byte, int port); " }( ]- K$ W% x7 X
程序例: </P>. r; Q" G4 e) `. B9 f% [" h( K
<P><FONT color=#0000ff>#include <STDIO.H>- X% u2 z* R6 _5 |% ^6 d0 X
#include <CONIO.H>2 x! l0 d& I' k4 ^ p
#include <BIOS.H></FONT></P>* p9 E- Z) \, s
<P><FONT color=#0000ff>int main(void)
Y6 O- S% u' X7 y# e{ , n( Y; |( D0 P) ~9 x5 I: Z$ |
#define STATUS 2 /* printer status command */ ' o4 ?2 B8 T+ O2 |0 w
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
0 W; w5 M( X/ {7 `<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
7 K+ F; g% x5 Y3 t<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
. r) O9 z* T) m$ N1 jgetch();
& @+ ^5 Y5 {6 @8 f% Y$ e Xstatus = biosprint(STATUS, abyte, PORTNUM);
1 H4 U3 ~: K7 ~if (status & 0x01)
0 ` v# P; H1 F. S1 Kprintf("Device time out.\n");
; W2 R! N, w* v' K" Fif (status & 0x08) 1 d1 c; L8 X4 i8 p& W- e
printf("I/O error.\n"); </FONT></P>: Q. x/ g) O3 x4 n
<P><FONT color=#0000ff>if (status & 0x10)
" W0 M5 }/ C8 g7 y) U# c( q8 H5 jprintf("Selected.\n"); & l% |/ e4 x/ H) g0 B) g: q1 Z
if (status & 0x20)
( q+ s/ V& ~3 |) W; E% Q) Oprintf("Out of paper.\n"); </FONT></P>. w/ i4 ^; q+ {1 ]. B
<P><FONT color=#0000ff>if (status & 0x40)
4 P) m4 f/ U8 a4 Q+ t+ hprintf("Acknowledge.\n"); / L, O0 [ D/ a2 s: f
if (status & 0x80) # n4 O/ ~9 @+ M; D z8 b. J# K
printf("Not busy.\n"); </FONT></P>% a) D8 t" { x, W' N P+ \% N
<P><FONT color=#0000ff>return 0;
0 T1 d& k/ \$ B# t. p' H' v2 n' f' U}
0 @/ S. A; n. Z7 K7 i" C</FONT>
$ j0 Q5 i0 A4 L4 S7 x* i& v2 a
</P>
$ U4 C( s4 v! r$ ]" a<P><FONT color=#ff0000>函数名: biostime </FONT>" w" w/ j* |8 ^) O; y4 U
功 能: 读取或设置BIOS时间 ' @. @" a4 S, Q/ w
用 法: long biostime(int cmd, long newtime);
' u4 H1 o, `/ ]8 ]0 c3 a; P! \0 d程序例: </P>0 `; N* s2 ^2 c
<P><FONT color=#0000ff>#include <STDIO.H>
+ n8 O4 o0 J8 @/ K9 Q#include <BIOS.H>
9 `3 P# A- n1 H0 C A+ Z1 P' D#include <TIME.H>
8 Q& _. a# W3 l# z5 F! I#include <CONIO.H></FONT></P>( k/ T# b) e' i: U8 o p
<P><FONT color=#0000ff>int main(void)
2 w# z8 i# O; w' v4 b3 X{
6 k! |+ p0 C$ Y$ Tlong bios_time; </FONT></P>, i3 ]1 k$ [: Q& F
<P><FONT color=#0000ff>clrscr(); * p$ K; ]7 @, E2 p1 N1 B
cprintf("The number of clock ticks since midnight is:\r\n"); ) ~) C. M( ^7 s/ U+ G
cprintf("The number of seconds since midnight is:\r\n"); 8 o' T" l6 Z, x
cprintf("The number of minutes since midnight is:\r\n");
9 S) y4 o$ f5 R6 E2 @cprintf("The number of hours since midnight is:\r\n");
8 E( p/ ~5 u, c: I0 T0 R2 ~cprintf("\r\nPress any key to quit:");
F. m2 B' J4 g) a+ Ywhile(!kbhit())
9 o0 f9 r5 B& J7 n{
, G4 o" t9 e; J \3 mbios_time = biostime(0, 0L); </FONT></P>
$ \! x* j4 C5 Y6 j9 L<P><FONT color=#0000ff>gotoxy(50, 1); 7 u; S- {7 U' E! L4 T# m9 S
cprintf("%lu", bios_time); </FONT></P>3 e3 Q9 ^6 D; o+ i% L4 ?
<P><FONT color=#0000ff>gotoxy(50, 2);
& U0 b, S; }1 |6 e& U; Ycprintf("%.4f", bios_time / CLK_TCK); </FONT></P>2 p3 H% T5 h8 M7 E. g- p' H l& l
<P><FONT color=#0000ff>gotoxy(50, 3); 8 x: x4 n; d) h6 B& |& ^6 o
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>% d0 F) i8 e6 ]& B2 H4 r" _
<P><FONT color=#0000ff>gotoxy(50, 4);
8 I, v( X7 V+ G$ K L' \2 }/ {cprintf("%.4f", bios_time / CLK_TCK / 3600);
+ a$ K- _$ l4 E; s* f6 }4 {8 y}
, E0 H* S; d- W7 {5 d3 J3 Oreturn 0;
% v6 a9 j/ }& J" S( o, W3 @. h}
7 s& a6 g+ G) R8 s$ q5 n" }; R</FONT>
! J; e8 u" ~6 R3 ^! C4 |5 l; Y+ H
</P>
+ s' o' E2 Q. I8 d' l( V<P><FONT color=#ff0000>函数名: brk </FONT>2 G, x9 b: e6 ^2 B, [% N h1 n
功 能: 改变数据段空间分配 & I7 ^* l# f% v% Q0 S% n
用 法: int brk(void *endds); - D: C) Z# C) H0 H8 \! i! N
程序例: </P>
1 u6 m3 q7 L1 |/ l, r<P><FONT color=#0000ff>#include <STDIO.H>
" g5 y9 ~+ P. c5 E7 R#include <ALLOC.H></FONT></P>
' {$ c, `! B% Y/ j4 `0 i3 V9 n<P><FONT color=#0000ff>int main(void)
% A7 w* ?5 d) [{ 6 u2 S, L4 A: I4 j4 e- W
char *ptr; </FONT></P>& Z# V" }' T8 X( p& k5 Z, g. W0 B
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); ( A/ [& `/ Y! L! d3 U9 L
ptr = malloc(1); . z+ b# Y5 k9 o/ o2 H' I: h3 Y |1 a3 L
printf("Before brk() call: %lu bytes free\n", coreleft()); , B$ |. Z1 r) L4 H. W: d% A( E
brk(ptr+1000); ' ?- C: p% F: @ v+ }4 ~) V* t, I
printf(" After brk() call: %lu bytes free\n", coreleft()); 7 m- K: d& i$ S" M' N, W ^
return 0; 2 y, i* H" s+ ?* G! P
} ( M6 H; c$ K2 Z" C7 t7 U
6 G5 Y7 x+ F7 O9 u7 R* ] e</FONT>. R; h8 T6 H& G; W& n3 }
</P>
0 M$ l8 z- `, M2 z) ?! ]<P><FONT color=#ff0000>函数名: bsearch </FONT>) v8 l3 N n. m- b- B T# U: n) ?
功 能: 二分法搜索
( l! c5 }5 c- T8 g用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
0 g* W- ?* G4 T5 Tsize_t width, int(*fcmp)(const void *, const *));
" I4 ?& c; `( X, S, |程序例: </P>
' }, h2 ?) i9 M* S<P><FONT color=#0000ff>#include <STDLIB.H>: M; M, W( u D, M1 H
#include <STDIO.H></FONT></P>
+ O; P# m* ^' C8 r4 e0 E% w<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>- ^* e2 q! c0 i' f% }
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
6 v! ~* O% `9 b4 m6 e<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) - P, j2 {. K, }4 m! _# d+ N
{ 5 [% A% o- G8 o S u
return(*p1 - *p2);
4 J6 |1 T/ u+ p: N2 q* m" _} </FONT></P>& M$ J$ E7 v! V+ `; {4 ^
<P><FONT color=#0000ff>int lookup(int key) , a6 B8 `- ?) [1 z# w, C
{ + h4 j s- w+ ^* j4 U& h
int *itemptr; </FONT></P>) o3 d& Q& l7 O4 m' z
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
' o4 @( j7 Q( o, W+ F: |4 e0 V6 b( [is needed to avoid a type mismatch error at
$ O( j$ b6 J9 B; Rcompile time */
0 {2 p! o+ q; w. Pitemptr = bsearch (&key, numarray, NELEMS(numarray),
4 N, C0 S" G! c7 f* Ksizeof(int), (int(*)(const void *,const void *))numeric);
) |7 K% J. ?* S( Sreturn (itemptr != NULL); 0 [" D9 t4 L- M& i
} </FONT></P> B$ P# D& O6 u
<P><FONT color=#0000ff>int main(void)
9 {. [- J% P# ?! {{
( F# g" e% I$ `/ u0 }7 Q# kif (lookup(512))
, g3 V* S8 @2 }' s5 A. J7 ?printf("512 is in the table.\n");
( m) \' [6 t8 qelse ) t! R8 L+ ~1 p2 w2 C3 D
printf("512 isn't in the table.\n"); </FONT></P>
' G# B C% V& \3 p+ M4 }% c' ~( U* {<P><FONT color=#0000ff>return 0;
$ K- r, C, Z" U6 i; q1 f O} </FONT></P> |
zan
|