QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1718|回复: 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># F5 q/ d9 N) V
<><FONT color=#ff0000>函数名: bar </FONT>
* C% F: {0 b$ }2 J3 W- Z+ t功 能: 画一个二维条形图
7 O8 l: X0 X0 w( j用 法: void far bar(int left, int top, int right, int bottom);
% u/ y* m) u, l" o5 z! u1 t程序例: </P>% [: c6 d  O3 F+ S/ t
<><FONT color=#0000ff>#include <GRAPHICS.H>
8 V4 ~9 D2 T- ^' y+ d& z2 e5 R#include <STDLIB.H>
  }3 e6 I. r; c. P) O0 p#include <STDIO.H>
! I" Z, M. u0 ?% M/ `$ ~#include <CONIO.H></FONT></P>
& {" X6 P* y" r2 G<><FONT color=#0000ff>int main(void)
& o$ d! b' J9 w0 I/ {2 H/ t1 B2 d5 ^{
; g0 h! q1 J# J6 o# D% h  i" A/* request auto detection */ , [3 K5 \, ^' [) @* W  E! J! w2 t
int gdriver = DETECT, gmode, errorcode;
# h3 G3 b" d1 i- t% dint midx, midy, i; </FONT></P>
- W  F* H3 i  l$ E5 x" |: h<><FONT color=#0000ff>/* initialize graphics and local variables */   ^4 e% I! S3 R) k, T% `
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 r2 ^4 \- G# `( k8 w& w. B<><FONT color=#0000ff>/* read result of initialization */
' m! ]6 N/ u. H8 H: herrorcode = graphresult();
5 L4 [9 y7 u  Q+ p. Y0 K- p' hif (errorcode != grOk) /* an error occurred */ ! B* |+ F+ w0 m5 [
{ 1 z# l1 V' J4 X
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . N# V( M" }% ]; e2 z$ c- t
printf("ress any key to halt:"); / S- l' J* Q! v: H/ z& \
getch();
* N* h  L) z2 j: E: Hexit(1); /* terminate with an error code */
2 s4 a% J4 a7 b3 S: i/ y) f} </FONT></P>* y! {- Y) T; r+ x
<><FONT color=#0000ff>midx = getmaxx() / 2; + D$ k# e! j4 @3 @$ Y6 e
midy = getmaxy() / 2; </FONT></P>- x0 [, B; V* W8 S$ R
<><FONT color=#0000ff>/* loop through the fill patterns */ - h/ u6 v- v+ M1 I* D
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { / |. G& Q* N1 L% U
/* set the fill style */ - b+ N2 g  r. A3 o' P5 H& D
setfillstyle(i, getmaxcolor()); </FONT></P>
7 a# R) j5 ~, N* P4 [9 B9 [0 ~8 K<><FONT color=#0000ff>/* draw the bar */ 5 y; e: A1 s+ T: e, O: R3 R' H' N
bar(midx-50, midy-50, midx+50, ; K3 p; J' B! W" G5 x7 u
midy+50); </FONT></P>& V& \, f) ?) I$ a+ m3 \  z  H
<><FONT color=#0000ff>getch(); ) H9 N  @/ c& |9 z. Q- A3 X1 D
} </FONT></P>5 y# b$ E! F9 x  |6 x- }0 y" E' A
<><FONT color=#0000ff>/* clean up */ . O3 C: w2 e. V) I2 G
closegraph();
1 ]1 X1 g3 b' W2 y6 qreturn 0;
1 \0 q) @! |# G  c& h$ Y} </FONT>
% c5 L7 f8 c9 |" x2 e  s* M
1 P6 v/ u8 {' M" L3 j% T4 d, o: D2 z& ?8 s
</P>
6 E) u0 @* y; G<><FONT color=#ff0000>函数名: bar3d </FONT>
' j* o! X* A) K- a# ?! U" m; y3 ]功 能: 画一个三维条形图
! b: E* ~8 p7 m" J6 H用 法: void far bar3d(int left, int top, int right, int bottom, % K4 D4 J$ Y5 W4 p/ E
int depth, int topflag); " v$ Z" I2 a* s# _3 }
程序例: </P>+ ^0 B) s- [' v  y. g! u% T" O
<><FONT color=#0000ff>#include <GRAPHICS.H>
6 W) ?) B0 w7 X9 H#include <STDLIB.H>3 R: w6 f6 j( F  H
#include <STDIO.H>
2 C5 t0 p. }2 l$ V$ }#include <CONIO.H></FONT></P>& x9 I# U6 ~( m8 x1 S
<><FONT color=#0000ff>int main(void) ( x% D& [% R% D
{
7 P5 d" A! `( Y/* request auto detection */ ( N& p" ]/ J! _& x
int gdriver = DETECT, gmode, errorcode;
8 A1 q$ |  Z- A' a9 kint midx, midy, i; </FONT></P>* M4 E2 w, j6 Q2 V
<><FONT color=#0000ff>/* initialize graphics, local variables */
) [% N0 m; ?& U# {  E5 b- kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. S1 Z9 C4 o# _' K; U# M
<><FONT color=#0000ff>/* read result of initialization */ : e% O2 X, \1 a
errorcode = graphresult();
# a( v+ D  n$ g1 _* w) H! Oif (errorcode != grOk) /* an error occurred */
$ q" H% f0 v' N( X  G+ `{ 0 d6 V' Q/ O$ V* H$ Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ W! q5 z& J' J" iprintf("ress any key to halt:");
; R" h9 e) t- b8 S4 A* Hgetch(); 2 }1 j6 o0 j( E
exit(1); /* terminate with error code */ ( j5 L1 {, P) D. r/ A
} </FONT></P>
+ q  E' q7 |5 l0 i# p<><FONT color=#0000ff>midx = getmaxx() / 2;
+ `, Q! Z0 t/ E; d1 A$ V% Wmidy = getmaxy() / 2; </FONT></P>
/ n1 C# K8 H( l2 v1 ^" e7 A" r<><FONT color=#0000ff>/* loop through the fill patterns */ 0 ~! @# w+ T  r' y
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ( g8 z! A$ O% f8 z! V& C& s5 @9 e
/* set the fill style */ $ }# d! F: l3 t& [
setfillstyle(i, getmaxcolor()); </FONT></P>
; F1 c, b/ N3 T<><FONT color=#0000ff>/* draw the 3-d bar */
% S* I( h5 M9 n! p3 _7 ^bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>; m* a1 s! _" M
<><FONT color=#0000ff>getch(); 1 ]' t! L  s  [$ A& I5 c" U% T
} </FONT></P>
( M) A# s7 f& ]8 P<><FONT color=#0000ff>/* clean up */
% ^* Y3 B( f' W1 qclosegraph();
4 c+ r. j0 p7 d, c: ^return 0;
* V! {# ]  V' U/ e+ M4 U0 [}
# o9 r+ r  [, \4 q7 K</FONT>3 m( S/ A% K: I( J% U! k( W" M

5 [- G; |7 n( B</P>/ R# n( t, j) E, k6 ]1 f' ?
<><FONT color=#ff0000>函数名: bdos </FONT>6 _3 f/ _1 y3 O9 i: i; h* n
功 能: DOS系统调用 , n4 d8 N5 c, M* m/ g" n
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
3 R) F8 {& z$ R4 a" X! i  j程序例: </P># q$ w8 h' U0 u# _) I
<><FONT color=#0000ff>#include <STDIO.H>1 C# \+ m4 Y" K: F+ D2 S0 t6 Q
#include <DOS.H></FONT></P>
5 b+ n' D3 g8 j% L<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
* S  s) U+ h0 I! Y0 Lchar current_drive(void) . y& `: l+ Z6 ~# S1 Q
{ $ \* P  [2 q* M* e6 S0 w# j, B; o
char curdrive; </FONT></P>( [8 C& |7 t& i* W2 e9 V- M
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
. s- D- O* f% F/ u+ O" o* o1 fcurdrive = bdos(0x19, 0, 0);
" d( d/ \. S  u6 |  Freturn('A' + curdrive);
3 {3 `3 ?1 K/ ?: D} </FONT></P>
+ D- O# V9 K4 `3 g' i( s. t<><FONT color=#0000ff>int main(void) / a: z; n/ ~, L
{ 1 \+ d( L) ~% m+ W% R+ g
printf("The current drive is %c:\n", current_drive()); $ I3 y2 P( ~  e: u0 X4 Z3 A+ p2 M
return 0; ; C* J- b" T, g; u7 [, B1 Y
}
* K3 E' Y% T5 _3 w7 o" ~/ a) m
' G8 X4 a, ^8 R% w' c</FONT>9 u0 e% r3 O% I% V5 M
</P>
' q' n6 p$ Q* }<><FONT color=#ff0000>函数名: bdosptr </FONT>
. I; b# j- {( _/ j  H) W功 能: DOS系统调用
  Q" g- E- e2 R  Y: k用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); * g8 F1 U! h; S2 u) ]
程序例: </P>5 Z3 ?. X( G/ G& V3 F5 H) e# o
<><FONT color=#0000ff>#include <STRING.H>
8 p/ o" }4 y0 F: `0 x% s7 C% X#include <STDIO.H>0 \$ R0 r5 J% p/ a- D1 p; T' G
#include <DIR.H>6 f0 z/ ~0 [  [2 x4 B: W8 C
#include <DOS.H>
3 Z3 ?& Z/ E( X0 p# h- [#include <ERRNO.H>
2 N2 c: C5 v: ]$ k2 {#include <STDLIB.H></FONT></P>
& f/ \1 f6 `8 u( V9 D' g3 U7 R' I<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
6 e, h; C5 }' k1 k) M<P><FONT color=#0000ff>int main(void)
9 [1 V& R2 k2 r6 X{ # d9 g  b; |8 I2 `) d* ?# |: L
char buffer[BUFLEN]; 6 `0 ?/ b7 j  e, Z" i! Q
int test; </FONT></P>  @+ {9 p, P/ V
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");   j$ \! K& m9 c$ p+ p. B
gets(buffer); </FONT></P>
2 G1 X0 K2 j# A# I<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); & t/ c2 Z+ b4 X
if(test)
0 f8 F2 S* U5 ]1 j$ p( o{
6 V* Q9 H+ K# U7 Z* ]printf("DOS error message: %d\n", errno); . |5 D% X1 L2 N0 n$ v
/* See errno.h for error listings */ , h" b( S0 V/ `; N7 `" A! A
exit (1);
+ }$ N' v) c$ p} </FONT></P>9 O* V$ I2 l( D" P3 e
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 4 {1 |6 X# n; i$ n5 N
printf("The current directory is: %s\n", buffer); </FONT></P>
; b0 m# I' d; P' y7 j<P><FONT color=#0000ff>return 0; - |& Y$ D+ |0 a) b# j
} 1 M# D- G* q% [; o4 n" A! r
</FONT>$ t- o6 y# ?! u6 k  Q6 {* _* i
& v0 N0 ^  @( G
</P>
/ Z' C6 f2 {. ]; {<P><FONT color=#ff0000>函数名: bioscom </FONT>
8 w9 V3 a- |1 g- |& l8 c功 能: 串行I/O通信
& _" l- i# y0 e% j8 r用 法: int bioscom(int cmd, char abyte, int port);
$ `1 N$ S  b1 m# O7 H程序例: </P>
; p' V; @( E6 ~" |( B<P><FONT color=#0000ff>#include <BIOS.H>
( c) {* F& }4 _# S4 z/ v#include <CONIO.H></FONT></P>
8 q# Q4 a% S: G<P><FONT color=#0000ff>#define COM1 0
6 |& Z7 Z! C. `8 s#define DATA_READY 0x100
) D3 k& a9 J9 z- e$ Q$ o3 e#define TRUE 1 ; ]. D- Z* [$ d" ^0 h* l
#define FALSE 0 </FONT></P>
* q) l7 l# h+ Z<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
1 E1 o0 O6 U+ M$ n<P><FONT color=#0000ff>int main(void) ! s5 ?( V; F) t+ o4 _
{ . H5 O2 C3 w* X6 d6 m# W5 u. C: s
int in, out, status, DONE = FALSE; </FONT></P>
0 N7 d8 O0 ]; Y* w  y# u. a<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
1 G6 z# `3 A1 V3 O  Dcprintf("... BIOSCOM [ESC] to exit ...\n");
" A, R# z7 j/ H# q4 K9 Twhile (!DONE)
) L& D# x; `$ N# W$ V( _{
! @) b% M3 L4 `! B, S) I7 d+ y/ x9 ?status = bioscom(3, 0, COM1);
% ^+ G% A! c( I% C: x$ J! Cif (status &amp; DATA_READY) , `; {: j+ _! ^
if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0) ! J  \4 I% {/ `) G* J9 `
putch(out);
; q# C( ^3 u# i( E& a" r( Eif (kbhit())
' h1 D5 f7 |7 M, m{ / h6 r$ T8 W1 _; L
if ((in = getch()) == '\x1B') 7 r1 [1 G7 o/ g4 ]
DONE = TRUE;
/ k6 P3 i) }% c1 r- ~bioscom(1, in, COM1);
+ W4 j  f. D  O} ' O0 N+ F# A" Z1 x4 z
} / F: o' Z: k: ?, j8 o' F6 _. ]
return 0;
9 w. k8 K: R# \; [4 @# c% g} </FONT>5 K5 q; M2 G6 l& f
* [' A1 i% Z0 E# m! c

- ^4 B' |, ]! B! }  C0 N</P>7 Z  c% t( w  |" S  R
<P><FONT color=#ff0000>函数名: biosdisk </FONT>( @; B, B. G% R1 \( I8 j% g% i
功 能: 软硬盘I/O
- V# i5 A7 H# a7 s7 `1 T用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 3 P4 B" K' p0 M! }7 h9 W' S
int nsects, void *buffer); ( F2 J) _# }: x2 b- b8 ?, w* o
程序例: </P>
2 j- \2 D0 l5 l7 I- ?; }; \- A. F<P><FONT color=#0000ff>#include <BIOS.H>
4 k8 {  q6 r% Z: a5 B, b#include <STDIO.H></FONT></P>1 V+ o8 P# F! h8 @5 T( `1 n2 r/ j
<P><FONT color=#0000ff>int main(void)
' U9 d+ B6 s% _{
3 q. I% d$ P# d5 {" K8 Xint result; - h2 P  `2 ^2 p+ L; t
char buffer[512]; </FONT></P>
7 |: X; x) }+ ~3 U9 N<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); ' X& o* ^% J7 Y( c
result = biosdisk(4,0,0,0,0,1,buffer);
. w8 `3 l7 l/ L& ~! \result &amp;= 0x02; 1 F! F! Z& ~7 |
(result) ? (printf("Drive A: Ready\n")) : + M2 k' ]0 z  B# Q
(printf("Drive A: Not Ready\n")); </FONT></P>
+ `$ s$ z  A/ j2 T# V! x( z<P><FONT color=#0000ff>return 0;
0 B+ Z5 a: z9 Z3 V} " d5 n" H' z& Q2 M) |
</FONT>+ r4 Y' y+ k2 B+ d( p4 A2 t
: s6 u! l; ]" a( B! u* _, M
</P>( b1 Y% l6 C. f" D  q
<P><FONT color=#ff0000>函数名: biosequip </FONT>
8 c& P& I8 @2 Q  S9 m8 J. ]  H) d功 能: 检查设备
/ U( s4 v7 `8 ^& `4 O$ r用 法: int biosequip(void);
" h7 L0 Z0 W# x% P, F6 K程序例: </P>
, P5 s1 H! e* L<P><FONT color=#0000ff>#include <BIOS.H>) n. q, @- W! O% e- |+ g$ \
#include <STDIO.H></FONT></P>& D. B  k2 `8 `! @% y
<P><FONT color=#0000ff>int main(void)
. @7 S; @% t. X: A! \7 U{ $ i- q5 _- g  Q) `, h" ~9 X
int result;
4 N8 u. U# w4 h: Zchar buffer[512]; </FONT></P>
, ]) n, Z$ y6 y  |: e  A; G<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
7 c3 B3 u/ C' ~' \3 J% Zresult = biosdisk(4,0,0,0,0,1,buffer);
6 B4 M/ [  ^+ S$ t" j5 b9 j# q8 dresult &amp;= 0x02; 3 s- C- i$ P- h" x
(result) ? (printf("Drive A: Ready\n")) :   \2 V, P% o% b. w$ w0 ~+ d
(printf("Drive A: Not Ready\n")); </FONT></P>! @% b& ?( L' U. Y6 \. I6 v
<P><FONT color=#0000ff>return 0;
" d; V3 `8 b9 d& T} , b9 H* F) O8 P( l  W/ ]
</FONT>
: r' J$ ~- L' z$ K
( N# t% _3 q* i" W( i6 T3 s1 S</P>* Y1 l7 M- l4 U; f  j( X
<P><FONT color=#ff0000>函数名: bioskey </FONT>
2 P/ F7 R+ r, f功 能: 直接使用BIOS服务的键盘接口 * n2 e  d0 L# @4 W
用 法: int bioskey(int cmd);
" W* h2 E: \/ |, v4 `程序例: </P>
, f/ n' U2 R1 K0 y6 A+ `<P><FONT color=#0000ff>#include <STDIO.H>. R# Q  g5 z7 t; |2 D4 s& ^5 X. y  w- E
#include <BIOS.H>4 r- f7 \+ {  ]! {% U
#include <CTYPE.H></FONT></P>" i8 i4 y6 c' U0 A. x$ r
<P><FONT color=#0000ff>#define RIGHT 0x01
. u8 l9 J! i; q& ]2 b#define LEFT 0x02 . o- u2 E" {, |' ]# m1 x0 Y
#define CTRL 0x04
9 @& J5 @$ s8 j$ j. ?# V7 K, ^& W#define ALT 0x08 </FONT></P>
( `" j% m2 L1 d$ x; A8 J<P><FONT color=#0000ff>int main(void) % c1 }0 I& V# s8 T
{ / Z* m7 B% _/ U; c# {0 }
int key, modifiers; </FONT></P>0 W2 v& [5 g. O
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
, R0 x8 o% e4 M- F, Fwhile (bioskey(1) == 0); </FONT></P>5 q) L9 r6 E  h. o# ^
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
. n* w9 I! w1 q: J/ N) {( Skey = bioskey(0); </FONT></P>
- m/ X$ t3 f5 Y. T4 E6 |<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
4 i7 O4 S: R" t- ?modifiers = bioskey(2); ; A& c( s8 ~- y8 V& t% C* _+ m8 ]
if (modifiers)
) p  G. G8 q  u$ u' {! B{
- O' L' N) g. M& w$ c% m# Eprintf("[");
8 l% o7 Q( ]' V/ b/ Gif (modifiers &amp; RIGHT) printf("RIGHT");
+ `" s8 @+ C9 b2 X1 X7 a1 @if (modifiers &amp; LEFT) printf("LEFT");
; W4 B6 J; w* Y- _  nif (modifiers &amp; CTRL) printf("CTRL"); + m, B  ^3 \: _# B7 Y3 k; n( A
if (modifiers &amp; ALT) printf("ALT"); - A( a! u9 n9 N& j  ^9 j
printf("]"); : o; W2 r% H* W) s, a: q
}
7 t! |  ?$ b# d7 C3 P  S/* print out the character read */ ; }, q# v( q8 G; K
if (isalnum(key &amp; 0xFF)) ' K1 U% G7 @5 e, ~  I# x
printf("'%c'\n", key); 0 x$ {, u' [4 p) h& m
else
" k% R$ t7 ^3 t. r! fprintf("%#02x\n", key); + E8 E! ]( l. b, ~/ J! C
return 0;
/ {( |. @- @8 z9 a! j- l4 u+ V}
' d5 Y& E2 n1 n' h. x( O8 g& K7 {$ b' z  B3 @' @8 b  Z
</FONT></P>
+ ?1 [; `4 W: U; y6 E& ?* S# y3 N9 r, @<P><FONT color=#ff0000>函数名: biosmemory </FONT>) q# k$ T# l& n8 `
功 能: 返回存储块大小 . I! i+ f7 K! k, E
用 法:int biosmemory(void); , o& D3 z3 D/ q% P- A5 }" W
程序例: </P>
  h/ z0 i/ g. G& W$ B0 P. I<P><FONT color=#0000ff>#include <STDIO.H>+ ^4 E8 e+ g# c- B% Z" @
#include <BIOS.H></FONT></P>9 ~$ [% g; W' P+ S
<P><FONT color=#0000ff>int main(void) & E9 q" _) N, Z* a- B. b
{ : ~- \4 x% G) P2 j$ P$ O6 z7 J
int memory_size; </FONT></P>
- t2 Z/ a9 @" G& D<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ ! u* ?& E3 h- O  Z) a- d4 {
printf("RAM size = %dK\n",memory_size); ) g/ }% H4 Q" [  h* w: |. `9 p2 h/ c
return 0; / x; A5 a3 C% Y" W5 q# p( u
}
; w1 ?% j  y4 B( n8 j" ~  E</FONT>
3 I' i" r+ v1 m3 C" W2 \' y
: D. R1 Z- S" X$ i</P>
8 y, r% W" H9 c! {& V- A<P><FONT color=#ff0000>函数名: biosprint </FONT>
" i1 N+ s' ]' ~/ I1 W! d功 能: 直接使用BIOS服务的打印机I/O
6 o( W8 Z! }) G+ {8 j用 法: int biosprint(int cmd, int byte, int port);
/ k+ \! j1 ]0 F6 X2 W# P2 O程序例: </P>
: s) l0 m, c6 i3 M<P><FONT color=#0000ff>#include <STDIO.H>1 ~9 e: c! r- n9 T1 _: @
#include <CONIO.H>
" y& w) E7 S; Z2 W0 t#include <BIOS.H></FONT></P>
# I, B7 K. |$ W% o. e, G" x<P><FONT color=#0000ff>int main(void) $ y; B8 `" {: h# ?+ {) z
{ . D! b! ]5 P# B8 z
#define STATUS 2 /* printer status command */
6 S% k' t3 p- G#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
8 G7 i, s. n' o7 J# B<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
" |4 ~( e9 E% ]6 t! s% ?<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
2 n" F( j9 i" }, d1 l" q  m# ~getch();
3 j* f; V+ e  l" H) s. z8 U# Z7 Q6 Gstatus = biosprint(STATUS, abyte, PORTNUM); . X9 y. {) n# G
if (status &amp; 0x01)
$ @( T, W' u) B9 I& uprintf("Device time out.\n"); % l' t5 t% K- m8 D& c
if (status &amp; 0x08) , D; [/ l0 z. i9 E. g" W4 s- ]4 A! N6 @
printf("I/O error.\n"); </FONT></P>3 u: C! y" B/ `8 M- W* T% ^1 D# Q9 }
<P><FONT color=#0000ff>if (status &amp; 0x10) . C1 e% M( D3 l) J3 W7 l  I
printf("Selected.\n");
5 X& K3 S7 [4 B% bif (status &amp; 0x20) 3 z8 u0 B& ]% ]% u3 g
printf("Out of paper.\n"); </FONT></P>0 t, T5 a* M8 h+ y
<P><FONT color=#0000ff>if (status &amp; 0x40)
$ E9 n1 H+ c; v- C( pprintf("Acknowledge.\n");
+ @, A5 u5 F% i0 mif (status &amp; 0x80)
* i7 _2 I; s/ Z/ kprintf("Not busy.\n"); </FONT></P>
# ?7 i  W# w" ~<P><FONT color=#0000ff>return 0; 9 F+ e% ~# o# x( Y& z- ^, q
} - I6 S+ `* }# g8 j
</FONT>
: G/ C$ X9 I8 S( x) M2 x: }
7 ~$ u; T& w' g) x$ d% i/ Q* j</P>) J2 ~7 J# P3 l& |( m8 H8 B( x
<P><FONT color=#ff0000>函数名: biostime </FONT>, t+ ]5 n" Q' P8 r0 @6 J9 o* W
功 能: 读取或设置BIOS时间
' q2 i0 K- p& k, C$ f5 }1 x' _7 ]* \3 y用 法: long biostime(int cmd, long newtime);
/ I$ g5 X* S1 D0 q6 n; B程序例: </P>
: ^; x" W6 p$ x4 f- z4 U: u- P<P><FONT color=#0000ff>#include <STDIO.H>& p9 o) O, F: D; b6 {+ c
#include <BIOS.H>
5 c8 U* d! c" b- d, W9 L! C( G8 B#include <TIME.H>1 }+ L4 u& Q1 s' R) g6 L7 G
#include <CONIO.H></FONT></P>
+ L# K/ s$ s( m3 `' Z" g9 a  ~<P><FONT color=#0000ff>int main(void) 9 R# R: e- F8 O0 Q; m
{ 6 {' ?4 A3 e0 d! S! \
long bios_time; </FONT></P>- ]+ S! s& d2 [0 G: U/ ^4 F
<P><FONT color=#0000ff>clrscr(); # n( t" Q  p6 Z* M
cprintf("The number of clock ticks since midnight is:\r\n"); - C$ R* U7 @7 u% z  M& p
cprintf("The number of seconds since midnight is:\r\n");
  r6 q+ x5 a* g/ g4 `cprintf("The number of minutes since midnight is:\r\n");
$ m+ ?! T) L: U! [/ I5 scprintf("The number of hours since midnight is:\r\n"); ) t- X8 s# X/ U3 W& w3 z
cprintf("\r\nPress any key to quit:");
1 K' O$ N) D: W: L0 vwhile(!kbhit())
. _' I& C* E; v. M1 e, }- x. J# p{
% p5 m( V: _2 Z2 Kbios_time = biostime(0, 0L); </FONT></P>
5 D) W' ]: j& P* ^5 n% l<P><FONT color=#0000ff>gotoxy(50, 1); - X) v: C4 E3 d% S
cprintf("%lu", bios_time); </FONT></P>
6 m3 O0 v7 _# h% i! Q( _/ O<P><FONT color=#0000ff>gotoxy(50, 2);
% T6 S: S/ J; u4 k& }: K- O( icprintf("%.4f", bios_time / CLK_TCK); </FONT></P>% `9 T2 D' I2 B( h; {
<P><FONT color=#0000ff>gotoxy(50, 3); ; @# I# c0 }( S9 ~/ R! t4 p
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>& s" v4 y5 M; u5 j! Y
<P><FONT color=#0000ff>gotoxy(50, 4); " q2 i% R* u8 F8 S- W3 b* h
cprintf("%.4f", bios_time / CLK_TCK / 3600); ( ]" T, E6 {' n  p6 o7 c+ F! a) p# e
} . n# _7 h: _& t& `
return 0;
' A- j1 Z  z0 E9 K9 C9 H" M} * k% Y' P, c( C: [: ^7 D
</FONT>
3 w" D1 P. ~8 T% l
, \4 ?5 e% K3 i4 t7 x8 T</P>
9 ^9 I7 A8 R% S$ d+ [) h* _: w<P><FONT color=#ff0000>函数名: brk </FONT>0 G! O+ o! c) U
功 能: 改变数据段空间分配 - w& y# c/ x3 a6 N2 @
用 法: int brk(void *endds); 8 a8 _6 L. L) J2 J' Y1 X
程序例: </P>
8 P0 f4 v- l0 m<P><FONT color=#0000ff>#include <STDIO.H>: Z1 o$ C9 n' \0 c4 v
#include <ALLOC.H></FONT></P>4 i0 Q1 C2 r, L4 k" r
<P><FONT color=#0000ff>int main(void) , Q; p$ K/ l0 Y3 e  w+ l  Q# w
{ " I: h% ~  p- W6 ~5 u
char *ptr; </FONT></P>1 S4 X, M2 a# M9 p0 G9 H& D
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); 6 [1 ^2 I: w, @2 E* q$ @
ptr = malloc(1);
; L, B2 S% g  t8 W1 E+ [) A7 aprintf("Before brk() call: %lu bytes free\n", coreleft()); - k# k9 I! i* Z* N' T8 H5 O
brk(ptr+1000);
- b3 m( m1 c% g( m* y( m, X  @printf(" After brk() call: %lu bytes free\n", coreleft());
, V0 S* |0 A! j% W2 E3 m  p# Y( L) areturn 0; 4 L4 X! v  a$ @2 Q" _6 B3 T( D, h0 E
}
! A/ c3 E  }/ t* [0 c! H# H' r4 D$ M" a& W  q
</FONT>
& @& U! C6 U# Y; Z3 E( u/ T</P>
- m5 T8 [" y/ x: e0 V2 Y<P><FONT color=#ff0000>函数名: bsearch </FONT>0 O, b% c# J) X9 ]
功 能: 二分法搜索 ; h0 v* K) \; k5 ~
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,   @2 I: G* U( Q8 Z: c8 C* ]
size_t width, int(*fcmp)(const void *, const *));
6 v: g4 O2 M$ N/ U% ^* r程序例: </P>/ E" j! z7 C! C+ k
<P><FONT color=#0000ff>#include <STDLIB.H>
! [9 g0 B3 {4 @8 }5 D# ?2 V#include <STDIO.H></FONT></P>
8 ?0 a1 A: c) c0 ^* S! d# |* z( a<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>! F. p! `* h3 t8 m# M9 ~+ m% x
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
6 _2 X& t5 M% \+ q) k4 {. }* P<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) . i& I! @% D2 [& z1 |
{
: g/ X+ h( D) r5 l- k1 zreturn(*p1 - *p2);
, Z. }8 R6 d) G+ q+ ?% W1 k/ R} </FONT></P>
  y1 l" K* ]# ]- I, Y<P><FONT color=#0000ff>int lookup(int key)
1 q4 I. ^9 g* X3 C{
+ R9 i( f) ?7 L7 S2 yint *itemptr; </FONT></P>
, P4 X% Y8 ?7 Y& Q3 f<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
: x! ]' z3 q9 T/ \is needed to avoid a type mismatch error at
% P" Z/ s5 S4 [/ j0 dcompile time */
. N6 C# Q* o- Citemptr = bsearch (&amp;key, numarray, NELEMS(numarray),
  j' S% b7 ?6 z- qsizeof(int), (int(*)(const void *,const void *))numeric);
6 v& j: O5 \7 h" g' Q: K7 c: C( x' greturn (itemptr != NULL);
' t. S4 v* w4 s! ?' v* P9 Z& d2 T% ^} </FONT></P>
4 k, O; Z9 q! z, N' R7 F7 y<P><FONT color=#0000ff>int main(void)
' v- y" H; i* W3 o' |; D{
3 w; {5 Z( |* a& R2 T9 v2 Fif (lookup(512))
. [- x' r9 p+ D* W' rprintf("512 is in the table.\n"); ) D. m/ v& Z$ q5 p3 T- k
else
' o; J* z* M. s( Z2 rprintf("512 isn't in the table.\n"); </FONT></P>  }( A  O4 I+ Z- ~, r
<P><FONT color=#0000ff>return 0; * ^- C" [+ \0 Z) G9 _
} </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-11 08:37 , Processed in 0.395979 second(s), 52 queries .

回顶部