QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1722|回复: 0
打印 上一主题 下一主题

函数大全(b开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:03 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>, j  e; K0 X( `# c4 v7 K/ Y# Y
<><FONT color=#ff0000>函数名: bar </FONT>0 }5 `' O/ t7 I7 \  q5 g5 T0 m5 ~
功 能: 画一个二维条形图 2 w# i, j/ {8 C( W6 U% ?
用 法: void far bar(int left, int top, int right, int bottom);
) Q: Q) o" I. \  E7 A! h- s/ Z/ z程序例: </P>
; ~( e  E/ D( Q0 M" U- B<><FONT color=#0000ff>#include <GRAPHICS.H>$ t+ |, V: W) N, U
#include <STDLIB.H>6 C, L7 \: N+ m3 w0 N% p
#include <STDIO.H>
8 s8 s0 x& X' J+ q4 P7 ^$ A- H#include <CONIO.H></FONT></P>3 P" V3 s9 n0 S5 I  X
<><FONT color=#0000ff>int main(void) + r# Q, E  V. |9 u" K% f
{
- j+ {6 _/ V  T) |* ~: c/* request auto detection */ # D# m+ w0 H0 |/ @
int gdriver = DETECT, gmode, errorcode; , \# j. g# Y5 v5 O
int midx, midy, i; </FONT></P>
$ H  B# U# l8 a5 Q8 g<><FONT color=#0000ff>/* initialize graphics and local variables */ 9 }! Z$ O, @# W- [
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. N: w( I/ E- C; U5 C0 r# G" }0 k
<><FONT color=#0000ff>/* read result of initialization */ 3 Z& \- {6 ~5 L) N; P1 c
errorcode = graphresult();
5 P/ z7 ^( V; fif (errorcode != grOk) /* an error occurred */   [: L* N& b: B9 k4 h5 s9 g* ~
{ ' ]* L- O% _" ?3 D/ Y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ! ?( u+ A0 _' I& i. s$ J$ F
printf("ress any key to halt:"); ) H+ c, |& F; M2 u" Q, o
getch();
: l) r- M2 f0 y" B0 sexit(1); /* terminate with an error code */
& t3 n. j: g6 _+ x! x+ `- ]} </FONT></P>
3 \) r; z3 ^* g" p1 d! l0 I, ^<><FONT color=#0000ff>midx = getmaxx() / 2;
5 `  t7 Q" a3 I# I3 i. Tmidy = getmaxy() / 2; </FONT></P>
' T9 }/ }: p) S' M<><FONT color=#0000ff>/* loop through the fill patterns */ 5 ]" S$ n2 V0 U6 q2 {6 @2 d9 a
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { 0 b! ~! I4 [) z8 X# S" s* w
/* set the fill style */ & U: U3 J! S2 {$ V7 a, d8 r8 f
setfillstyle(i, getmaxcolor()); </FONT></P>- D) g# }3 A6 Y7 ^6 V' @
<><FONT color=#0000ff>/* draw the bar */ 3 O- y: J% _& H9 A- h5 w& B
bar(midx-50, midy-50, midx+50, ' h% B  ?% O3 B, c1 l5 u- B; F+ P" o
midy+50); </FONT></P>
, w3 Z/ B" Z5 D# d7 J4 n<><FONT color=#0000ff>getch();
. }+ x) \3 B: A# I4 A8 f' w3 @} </FONT></P>) ]5 F( y- k& G5 d7 V5 i
<><FONT color=#0000ff>/* clean up */
+ Y; r( P# E2 x' zclosegraph(); 7 P: J  s& l- F( s
return 0;
, S) Z+ Y+ j9 ?4 Y4 o$ ?3 ~} </FONT>
& }& S1 c+ c9 Q% @: N
: ~: S- K" u1 }% o! V! p7 v4 S. x3 |0 Y( ~' }
</P>
$ v1 R: D, n0 N$ V3 M. |<><FONT color=#ff0000>函数名: bar3d </FONT>
0 b. n: g& P; K6 _- O+ [7 Z功 能: 画一个三维条形图 7 \! [& v" f4 R! L' [
用 法: void far bar3d(int left, int top, int right, int bottom,
) W3 h% ~5 l+ V2 Q& }/ o7 e- nint depth, int topflag);   m& T/ l5 v' F, J
程序例: </P>2 t3 o/ d; [9 r' S& U+ B
<><FONT color=#0000ff>#include <GRAPHICS.H>
/ h( Q7 K' A$ |4 _#include <STDLIB.H>
; K+ u7 a' m" _) k* W0 T" K2 X#include <STDIO.H>
( O: p9 o, b/ P" R/ j" V8 \  \#include <CONIO.H></FONT></P>- T5 X! b  D2 V; [
<><FONT color=#0000ff>int main(void)
0 D' G0 k- [; S7 Q: f/ ~" q' N{ : A4 [5 G6 }7 r, _  H, x: a
/* request auto detection */
& F' `% a6 @: p8 ]int gdriver = DETECT, gmode, errorcode;
. q# Q4 u7 K0 O3 e' G- @# Xint midx, midy, i; </FONT></P>
2 V. X( k% i5 P2 w7 H# w! m. E<><FONT color=#0000ff>/* initialize graphics, local variables */
8 s2 o9 N/ u) Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 m$ c6 `. Z! S/ t( Z
<><FONT color=#0000ff>/* read result of initialization */
5 t2 X3 t& E& j# X* Rerrorcode = graphresult();
( i$ z$ q' w: o7 E! i9 C/ v  Uif (errorcode != grOk) /* an error occurred */
0 t9 @, q* N5 }7 P{
+ q9 ]* t9 X1 n% T/ Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . ]7 L- ?* t0 M1 |4 R8 \$ q; a
printf("ress any key to halt:");
$ }2 F; O$ o5 ~7 }$ Ugetch(); & G: i) V/ t  J8 Q, ]$ S
exit(1); /* terminate with error code */ 2 j2 [2 ~  }6 c8 J4 {7 I
} </FONT></P>
6 N; C( ]  l9 w* ^<><FONT color=#0000ff>midx = getmaxx() / 2; ( v& F9 q. [- n
midy = getmaxy() / 2; </FONT></P>
9 J! N4 k# f" k5 Q3 t) ?<><FONT color=#0000ff>/* loop through the fill patterns */
$ v0 n3 @5 `0 f+ G9 Tfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
* I/ `# P3 J$ b6 m( n6 S/* set the fill style */
- [3 Q2 ^' z8 ^$ p6 m# nsetfillstyle(i, getmaxcolor()); </FONT></P>
+ b! e6 g. n' m7 t; D, F, N<><FONT color=#0000ff>/* draw the 3-d bar */
+ F3 R) k0 k1 `; a' jbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
. ]" ?, x# d- m3 S1 [) j' p<><FONT color=#0000ff>getch();
1 Y% n) I; i4 I} </FONT></P>
5 q+ D+ ]' Q6 [3 F/ e<><FONT color=#0000ff>/* clean up */ - X& n7 O' @7 I. K' {
closegraph(); ' p4 P8 T( c& j" C1 A
return 0;
; u5 a* t4 k+ U$ A5 G: M}
# Y, M; `. K( \7 o4 b4 n5 T' g</FONT>6 k- \3 A$ r$ h
. A/ L; w/ |+ l6 {# T$ u  P7 |- i+ D
</P>" r9 J1 |2 ?* f% m
<><FONT color=#ff0000>函数名: bdos </FONT>
! u1 a) u6 `6 m功 能: DOS系统调用 ) U- P% t% V( A) |6 n
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); & l( z5 F# l( y7 t: z- ?
程序例: </P>$ d* M* A9 p* Z; g% B+ o
<><FONT color=#0000ff>#include <STDIO.H>
4 [. Q% S/ @6 i' `9 G6 W#include <DOS.H></FONT></P>
1 p: y9 T; G: {5 n1 d; T( ^. [& I<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
) g  X# O1 C8 _: Q) jchar current_drive(void)
8 r/ e! {& _3 h; A" p* v{
  U) P+ X1 i8 ]" L; U+ B4 Q4 D  Wchar curdrive; </FONT></P>
1 N3 B) W; e- E' H+ k<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
( E2 \1 i/ T) gcurdrive = bdos(0x19, 0, 0);
4 ^  i  ]' g/ R! a7 treturn('A' + curdrive); 1 g7 g: i* e6 h9 G. c
} </FONT></P>. C/ u8 q: i$ O" l
<><FONT color=#0000ff>int main(void)   S6 o6 u( G; |. q( h7 y4 X
{ ! P5 [9 f3 \, R7 ?: |" b
printf("The current drive is %c:\n", current_drive());   Q: e$ c9 I" Z# ]7 a9 C7 d
return 0;
* G" A$ R/ E# e; }) k3 N} ) H; _% K) C% n4 q' k: u

$ @' I) ~/ ?0 c" x9 R, e' |</FONT>
% ^" f( ^: `/ b  \</P>
' {( T1 \7 ~, ^4 `0 n( g<><FONT color=#ff0000>函数名: bdosptr </FONT>, e- [" d7 o. @! T# Y
功 能: DOS系统调用
- w; a' }" B( G) K3 g8 Q用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); & a' s3 v& \8 W" f2 z# Z$ `/ o3 l+ k
程序例: </P>) \+ p& N9 H1 T: L7 {  a$ y
<><FONT color=#0000ff>#include <STRING.H>
: H9 `6 w2 A. }+ O#include <STDIO.H>
- e$ O2 T# r( v! f% T#include <DIR.H>
2 |5 i: a/ ], w$ d  w#include <DOS.H>* b# F. ^  C  M! x/ s( p
#include <ERRNO.H>
7 ^1 e: d' s( A. ~#include <STDLIB.H></FONT></P>
, @) g6 [* h2 q3 V8 j& N; j<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
8 K4 b6 c4 ^2 p8 z$ S8 T* M9 O<P><FONT color=#0000ff>int main(void)
0 [2 i* k; H) P4 S6 u{ 7 ~1 G* I# W. N5 R- H) T; a3 ~: A
char buffer[BUFLEN];
1 ^9 ^# t7 j: u* O, fint test; </FONT></P>
+ D5 S6 z4 w/ G  ?. o( d<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 4 R* E& X$ R" p- f( _
gets(buffer); </FONT></P>+ y1 D5 v( k0 K0 K* W
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
& |5 W/ [6 N- z1 Vif(test)
: C+ h1 P3 ^7 f2 G- ?+ Y8 ?. P  v; G5 I{
; z) f) O4 }' R- _, rprintf("DOS error message: %d\n", errno); 5 Z$ ]( G) @- C9 h
/* See errno.h for error listings */
8 W% A& ?& G, ]exit (1); 3 g% q1 m* B0 Q
} </FONT></P>
! v7 _# v) V. J, N<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); : }& S6 z2 e7 N8 l
printf("The current directory is: %s\n", buffer); </FONT></P>
" S9 K  {& c: q# h0 a<P><FONT color=#0000ff>return 0;
. K7 ]' h8 l/ O; H}
. [' E% y- H( O9 O</FONT>1 A8 F, B/ i! Z* R2 o# i
* z. `+ j! D5 K
</P>
4 H; o% P+ T! O8 G1 _<P><FONT color=#ff0000>函数名: bioscom </FONT>
6 U2 ~6 j! d4 L3 x+ q, A; x! z9 D$ M/ z功 能: 串行I/O通信 5 a# e* ^; j% w& g% W6 ^
用 法: int bioscom(int cmd, char abyte, int port); ' O) q0 [& k- V2 D$ Y
程序例: </P>5 p# [( \% {, J& I+ {2 j
<P><FONT color=#0000ff>#include <BIOS.H>
6 U& I: }2 ~+ z: Q9 l$ a#include <CONIO.H></FONT></P>& c0 B- P5 s1 ~0 M, x0 Z( {, s' k
<P><FONT color=#0000ff>#define COM1 0 2 ]2 x0 o/ V$ |) V7 E
#define DATA_READY 0x100 + v3 V: T+ X% t5 v7 s6 X+ `  O3 U
#define TRUE 1 . Q) s$ U' R) T& v7 Y2 |8 a0 g
#define FALSE 0 </FONT></P>
# M, f9 A# l! k7 ^: U9 N<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>' C/ |/ a! y0 t' @
<P><FONT color=#0000ff>int main(void) ' \9 v. ?7 `' r1 o4 {( u
{ / R* H2 Y6 v3 v# I, T4 j
int in, out, status, DONE = FALSE; </FONT></P>/ \+ ~* `) ^7 X7 q# c! A" P6 V
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); - T, @3 ?9 a2 z! |
cprintf("... BIOSCOM [ESC] to exit ...\n");
: I6 R& ~* w( c& ^while (!DONE)
" T3 `) f0 W) ?" |$ T0 v{ & ~+ U/ r4 j  o1 Y) o# o
status = bioscom(3, 0, COM1);
% `; e1 V/ N, ~( Mif (status &amp; DATA_READY) 0 o9 Q& ?& k+ |' u) Y2 h* x+ I! N
if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
7 X1 r& n+ b  t) X: [0 F& V( Qputch(out);
8 V" P' t. q% o1 r9 U' uif (kbhit()) 7 j$ R' C9 a" w
{ 2 d1 R' _) J; D; r1 P
if ((in = getch()) == '\x1B')
+ y0 y0 S0 ]8 u9 X" A  Q# _, u5 }2 UDONE = TRUE;
3 R* r+ g! Q4 \8 x. m" Cbioscom(1, in, COM1); ( S- q, x1 G/ U
} , s( e6 U( x6 \* S# p% h
}
0 O" l+ C' Y8 c) U  f  hreturn 0; . m; b& G3 m6 v. d  W. U
} </FONT>" ?+ P7 a1 D) t- i9 j

) K% E1 K/ l9 p/ d$ Z6 R" q! F1 ?- A9 G& f9 o
</P>
- T& n9 t& k4 z& N0 V<P><FONT color=#ff0000>函数名: biosdisk </FONT>6 I5 s. B! I/ _' L4 h5 ?+ q, V$ l- U
功 能: 软硬盘I/O 5 t& `; x5 L6 ]8 y( b7 Q  J
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector * i' U& w/ {) `, D' m- i9 I' {
int nsects, void *buffer); ( ^( N% ?  D& Z& T8 v; F1 G- `
程序例: </P>
+ ]' j2 p3 `1 R/ a! T/ k<P><FONT color=#0000ff>#include <BIOS.H>
3 n" U# p( e- u! f1 |#include <STDIO.H></FONT></P>: p( f# V- n( A' y3 [, p
<P><FONT color=#0000ff>int main(void)
8 {' o& O; `8 [& y, |+ I+ ]{ + I* v" F4 z, V* D
int result;
) R: m9 L5 S7 N1 N" N; I) _char buffer[512]; </FONT></P>
; M& a1 `+ [5 u8 J<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
; C. I. Q4 `' X0 \6 H- Hresult = biosdisk(4,0,0,0,0,1,buffer);
2 M3 o1 A, }- K, j* i, Gresult &amp;= 0x02;
1 Y4 h" w( H4 t+ p+ I% \(result) ? (printf("Drive A: Ready\n")) : 9 y) W' u# ?% K! m2 U$ @
(printf("Drive A: Not Ready\n")); </FONT></P>
) e# o- r  H- `, S5 Q' e2 l+ K<P><FONT color=#0000ff>return 0; 1 H! K( O% C& |* K/ a& b
}
/ O. h, @: j: j) J</FONT>1 h9 I( A0 @( C/ |$ n; N
  i- b9 L/ [. X7 K
</P>; l& ^  K( `3 V0 t$ Z+ z7 m
<P><FONT color=#ff0000>函数名: biosequip </FONT>1 Y! i, [1 V8 E% g! ]% K
功 能: 检查设备
  y9 y7 y& l8 ~8 J) r用 法: int biosequip(void);
: h0 e) N' p/ Z程序例: </P>
" j- X! }$ X2 `<P><FONT color=#0000ff>#include <BIOS.H>, [# N8 O+ B1 c) f3 T3 X, ?
#include <STDIO.H></FONT></P>1 c2 L8 L+ f8 B
<P><FONT color=#0000ff>int main(void)
  `6 Y8 T  u! o) a* |' _6 N{
3 F% N3 ?* B- d8 Q' Z! e( Kint result; 2 d; f& d# n( @9 M/ A
char buffer[512]; </FONT></P>
, a2 S% L& F! N, k, S! K<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); , L' ^; ~$ C5 {7 R
result = biosdisk(4,0,0,0,0,1,buffer); 5 h6 k4 X, o  m" z
result &amp;= 0x02;
% D3 ?  I* c  H; ?- v1 @# A& t(result) ? (printf("Drive A: Ready\n")) : : @9 E3 d$ Q, h# u6 f/ L
(printf("Drive A: Not Ready\n")); </FONT></P>
* P9 X) x6 i1 z7 K<P><FONT color=#0000ff>return 0;   [" E0 i( B3 Q; E3 ~5 `2 b3 ?
} 5 P8 U4 Q, B: Y/ m! n
</FONT>
0 `7 t5 E% Z% O0 o1 a; x5 h' a  K$ h1 Q+ [# |8 z& F1 _
</P>4 C1 c9 G9 s5 j, x% `2 p: Z7 u3 N
<P><FONT color=#ff0000>函数名: bioskey </FONT>9 @* v, f2 X: v' I9 p8 J9 a/ m/ Z3 B
功 能: 直接使用BIOS服务的键盘接口 9 p# x% P3 S- C4 j5 m: y
用 法: int bioskey(int cmd);
1 s9 |6 N& `* C& k, h程序例: </P>2 q& r/ B6 @* ~" A
<P><FONT color=#0000ff>#include <STDIO.H>  U. H% Y/ R5 \  P0 z! j
#include <BIOS.H>! n& y' u% [+ V4 W3 [
#include <CTYPE.H></FONT></P>5 a' R$ [- ~- J- j7 Q
<P><FONT color=#0000ff>#define RIGHT 0x01
8 D* Y; Y5 N& X0 J#define LEFT 0x02 6 \: x( W: A9 ^9 J
#define CTRL 0x04
* _* l+ j: L, V# a* V4 S#define ALT 0x08 </FONT></P>
& R+ r; X' P: k2 o8 ?4 f<P><FONT color=#0000ff>int main(void) . {7 B0 @/ @4 u
{
3 {) y% A+ v. p/ Cint key, modifiers; </FONT></P>9 G! v7 H: g* }8 q" t
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
+ C) B+ V" A! U; Y  M( F0 Y" h1 }- H% F" _while (bioskey(1) == 0); </FONT></P>
( ~5 X, |$ n( T/ H1 `& V: N<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
0 H/ @& u7 I8 Y2 a' o1 Mkey = bioskey(0); </FONT></P>% H8 {+ d& Y7 E5 o4 p( |7 r
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
8 e2 B' j6 R& p9 e6 `5 c" h" i- Imodifiers = bioskey(2);
/ }) D+ G1 ~. h( c6 mif (modifiers) 8 n/ q) u- h# D1 s2 r% }' A! }! i& q" P
{
5 f( D$ M; E/ r$ Yprintf("["); ) b0 ^* _: V" ~1 {1 W9 }$ r
if (modifiers &amp; RIGHT) printf("RIGHT");
* D* |" T. g6 Y8 P4 [' B( zif (modifiers &amp; LEFT) printf("LEFT"); . i" D2 ?. g: m' Y  g( d% j$ ?5 X; \
if (modifiers &amp; CTRL) printf("CTRL");
$ N* z& M6 b9 B+ i/ Nif (modifiers &amp; ALT) printf("ALT"); " O+ H. Z- A4 a: B1 h/ l; B6 a; \* z
printf("]");
/ ^; @' j" O( H1 r} 2 w# `% Y+ F8 v" ~
/* print out the character read */
, g5 N# P& j9 j3 j$ m8 P2 Aif (isalnum(key &amp; 0xFF)) & q: s7 G- i; w4 j, Z5 W- [
printf("'%c'\n", key); + E6 x! D4 s3 z! Q' `+ W
else
. {9 n& Z6 a: \9 X: uprintf("%#02x\n", key);
& I& E3 e  R6 {1 }) Q9 Preturn 0; & g1 K6 z2 r7 A+ K# G
} % `8 D& {$ `) r7 j! @9 R

# f% A$ W) t1 [" `1 p; Y: B</FONT></P>
5 }/ P7 H) k& r( I$ h2 m/ v<P><FONT color=#ff0000>函数名: biosmemory </FONT>  H5 E. S. U% b* v# z7 P2 o
功 能: 返回存储块大小 ( s6 q; p6 X- C: X* L0 B) F
用 法:int biosmemory(void);
* F5 l& L' ?; R" s+ o; h& O程序例: </P>/ f: _% q9 G' Q  l% n' P
<P><FONT color=#0000ff>#include <STDIO.H>
% o3 o4 ?, Y' F; P5 W: q  ~! T#include <BIOS.H></FONT></P>! V6 |" O5 ~$ a; T( g
<P><FONT color=#0000ff>int main(void) : M; I7 j( [, x0 n. R; i6 Q
{
0 @5 n* R3 [' Y$ h& e5 Vint memory_size; </FONT></P>5 e7 J% s; d% z2 Z1 R
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ 7 @, {( U& X4 S
printf("RAM size = %dK\n",memory_size); 5 M7 @9 Q" G* b' q* c
return 0; . N( O  o) L6 R, D# {
}
2 O& @% L* b" r( H</FONT>
, o! W0 k- Q% e/ K- ~2 D6 Q1 Y- l+ a; c/ y3 O0 p
</P>
6 O$ t! q2 V* T# ~<P><FONT color=#ff0000>函数名: biosprint </FONT>
: \6 C! {9 A4 O, ?, p# t- _( e/ @功 能: 直接使用BIOS服务的打印机I/O ; A- p8 g. c; a
用 法: int biosprint(int cmd, int byte, int port);
1 Q1 d- [6 S8 ?' z% v, C1 [9 Q程序例: </P>
9 S: b. s0 K' t- ?- _<P><FONT color=#0000ff>#include <STDIO.H>
( l  j' t+ D/ I. s& ]#include <CONIO.H>
' ?' ]8 ~" ?' L3 O1 ~  G- @/ a#include <BIOS.H></FONT></P>
3 O, H4 r" \, @! e<P><FONT color=#0000ff>int main(void)
8 b& F8 {* y! q9 F# F{ ; d  Y; g" _/ Y% C: I) ]4 z
#define STATUS 2 /* printer status command */
/ |  j& L8 y; L: v#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
' N3 Y* ]4 s! F* y% G. s<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>, G  S7 Y0 w5 x1 v
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
# `7 @2 B0 n- T3 h  Wgetch(); ) D0 i8 B8 B! C6 ]7 I
status = biosprint(STATUS, abyte, PORTNUM); : F" D( p* D% |/ G5 \0 t5 v
if (status &amp; 0x01)
$ {7 X* d, b4 I$ u: T( D3 l; d) P- }3 Dprintf("Device time out.\n");
& e2 V( `7 w& eif (status &amp; 0x08)
1 l8 k  o4 q8 P/ zprintf("I/O error.\n"); </FONT></P>
) b! w% ]3 G2 w$ x9 R# Y<P><FONT color=#0000ff>if (status &amp; 0x10)
" l6 |7 z& z, o) U/ Aprintf("Selected.\n"); 2 J, T6 l8 M9 d
if (status &amp; 0x20)
' z% ^# h9 ?1 l1 D: K* Bprintf("Out of paper.\n"); </FONT></P>" V! N$ E2 T! H5 c
<P><FONT color=#0000ff>if (status &amp; 0x40) % {+ x0 h  S/ e" u. `# `
printf("Acknowledge.\n");
6 |; E% A8 l& a/ W8 c2 Vif (status &amp; 0x80)
+ a( v& O) @, T6 q8 ~+ c5 Cprintf("Not busy.\n"); </FONT></P>
# T# \4 T8 ]( O. y6 Z; x" ]<P><FONT color=#0000ff>return 0; $ N$ t' Q- G. a" x( Y
} ) q' D6 `1 S5 r! M7 Q" n
</FONT>
1 F# r/ {- L/ B6 c* H6 `6 R4 U! L" K5 |3 q0 ~( E
</P>
# J& N( n- f+ I2 b! A9 K<P><FONT color=#ff0000>函数名: biostime </FONT>) X4 q+ [7 Z/ E) f9 e0 @& u1 B8 X- M
功 能: 读取或设置BIOS时间
/ @* ]) ?0 T. @5 }用 法: long biostime(int cmd, long newtime);
7 |4 P: ]8 C2 S, z. q9 y3 O程序例: </P>
4 }4 d* t: O4 E6 h9 x, Y<P><FONT color=#0000ff>#include <STDIO.H>$ m" a! ^8 n. b2 h
#include <BIOS.H>
: o/ n4 }- N5 V) a, n& M#include <TIME.H>+ k7 `# a. x( ?  z9 I! ^7 o  ^
#include <CONIO.H></FONT></P>. U' {9 k( `6 e$ y" P* v( b# T
<P><FONT color=#0000ff>int main(void) - W' e- |5 w9 c# O! e
{
* q' S  R5 T$ \3 vlong bios_time; </FONT></P>
! {8 s; t9 ?& C5 f8 u  y<P><FONT color=#0000ff>clrscr();
1 g0 ~0 W! g% c; x! w% y/ K% `- Pcprintf("The number of clock ticks since midnight is:\r\n");
% t$ r# c* }! O- \cprintf("The number of seconds since midnight is:\r\n"); 2 k- r% n, v, F' l% w! H' V* I
cprintf("The number of minutes since midnight is:\r\n"); ( ?8 O8 x8 F! N) X' R3 b
cprintf("The number of hours since midnight is:\r\n");
. X% D$ L' h( k1 g  Lcprintf("\r\nPress any key to quit:"); ! \3 a6 x6 O' A6 C% \- X
while(!kbhit())
6 I) a  D  S1 T9 R6 H& b9 f{
7 L6 Q' b2 f9 c: q$ U' o6 Ibios_time = biostime(0, 0L); </FONT></P>
& K# I% p3 y* b, f% p<P><FONT color=#0000ff>gotoxy(50, 1); ' |# _& l- s; P# O( T
cprintf("%lu", bios_time); </FONT></P>
! E; S4 l% @+ q<P><FONT color=#0000ff>gotoxy(50, 2);
- C7 p' ~% Y: t6 b1 @6 p+ scprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
+ K  D9 O# ^( _! a. x! `<P><FONT color=#0000ff>gotoxy(50, 3); . O4 U; I9 ^' R$ O
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
5 j. e1 E9 {- J) [- g<P><FONT color=#0000ff>gotoxy(50, 4);
( X: \, v  N- g6 P* g, Vcprintf("%.4f", bios_time / CLK_TCK / 3600); , g. M) I- K; G7 F3 z4 c
}
3 D( H4 w$ Y, x$ V5 Breturn 0; " U4 m- r9 N! z+ V3 k: K
} % I2 z& N* e* T2 r) v
</FONT>% a: {0 B3 k) j( {9 a: e8 k

& g+ x; }6 |8 ]9 m. g0 t* l</P>/ l. o$ O0 ], _# r# _; N
<P><FONT color=#ff0000>函数名: brk </FONT>+ \1 s) j3 l, l1 D
功 能: 改变数据段空间分配
8 {3 I! _0 U1 |% i8 `用 法: int brk(void *endds); # c* y& P$ o% _" ^; C
程序例: </P>2 F! Q" l; [% W( f
<P><FONT color=#0000ff>#include <STDIO.H>
$ H* K, z5 }  ?7 ]. f#include <ALLOC.H></FONT></P>
0 b6 z" @$ b0 L<P><FONT color=#0000ff>int main(void) 0 x! O: v/ g9 l3 u5 o. G0 g
{
/ _: S# u5 z; {  l0 a$ k1 \char *ptr; </FONT></P>! o7 N; {; @; `! `7 \8 ^
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); $ z9 I' J8 \) F# ~* I
ptr = malloc(1); 7 R3 ]! m5 J: W
printf("Before brk() call: %lu bytes free\n", coreleft());   F9 r& `3 b' R. A8 @+ }
brk(ptr+1000);
1 C: }- U. j3 S+ {. k( `printf(" After brk() call: %lu bytes free\n", coreleft());
$ J" @1 I4 `3 `9 U1 S! c5 p: _return 0; " \! M- S+ {3 O2 b- M
}
) f' e+ G0 Q) U) z- J1 K1 z. h9 u; k  O: `4 Y( R6 J0 U. x/ Y
</FONT>
  ^4 u( [% }* O) v, I. L</P>
3 ^5 T2 u  |$ K9 U7 r8 S<P><FONT color=#ff0000>函数名: bsearch </FONT>) n  j/ f! t: g) d& y8 {3 |1 _
功 能: 二分法搜索
$ B, {! I* G" J( j用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
* j+ H1 ^9 {/ l9 Usize_t width, int(*fcmp)(const void *, const *)); 4 L: m3 k0 m3 a+ c; t! r. S0 d
程序例: </P>4 V  ?) A- `0 x9 t
<P><FONT color=#0000ff>#include <STDLIB.H>0 d3 ~' f. c6 V( u  k9 p
#include <STDIO.H></FONT></P>& H& R* j: X+ ?* J" O6 K
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
, _! r& `% d, |<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>" h8 L9 W$ A7 o) X* ^5 c0 ^
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 7 x% F5 r/ R* E; o+ k
{ # Y" H% [  o* T4 O8 K7 A
return(*p1 - *p2); , t# d2 c: v" r8 A# l
} </FONT></P>
2 H) k* w- z/ ^. ?& h5 k! I<P><FONT color=#0000ff>int lookup(int key) ( R: a! N) L. [3 @" L
{
0 }* v! n$ q% G+ a- I/ @int *itemptr; </FONT></P>" G" M0 i; L# h% Y" V8 L
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
# |! n; g# ^6 W9 A' G7 u" fis needed to avoid a type mismatch error at 5 r% H. m8 p  [% S2 B6 a
compile time */ 8 L( _" t& p) K
itemptr = bsearch (&amp;key, numarray, NELEMS(numarray), / [! e! O) q3 G4 G  A8 M0 V& ~
sizeof(int), (int(*)(const void *,const void *))numeric); % _! z, u% u. \1 |+ c5 M4 K% {( r
return (itemptr != NULL); * [7 P9 N) h3 V7 U
} </FONT></P>* f8 X, w2 r1 E# M- e% ^; v5 U. `) Y
<P><FONT color=#0000ff>int main(void) / y2 W5 ~* n' W1 \; g
{
9 Y1 I$ h  m7 L5 ?$ N+ vif (lookup(512)) # Y9 L3 `, z1 K4 F: u8 C
printf("512 is in the table.\n"); ! B! Z2 e0 _8 h9 ~/ t1 _- F
else
/ U8 T! Z' m& k2 Oprintf("512 isn't in the table.\n"); </FONT></P>
9 }* e- B6 j, `6 X) I4 C<P><FONT color=#0000ff>return 0; % _9 S8 C& w* o: i
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-6-15 00:22 , Processed in 0.443565 second(s), 51 queries .

回顶部