QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1720|回复: 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>4 _! s; i  U, u0 n$ k8 |$ ?
<><FONT color=#ff0000>函数名: bar </FONT>/ m; h% X! |+ Q% P
功 能: 画一个二维条形图 % A7 ]7 R3 A/ D' g6 Y9 e) Q* {1 K
用 法: void far bar(int left, int top, int right, int bottom);
. t0 @$ \8 M! K  _% S( O程序例: </P>3 Z( ^% n) _8 _- ]9 e- e1 y
<><FONT color=#0000ff>#include <GRAPHICS.H>
3 w6 a7 G2 q* Y- \" a4 [#include <STDLIB.H>
  p( D$ w6 g/ ?8 b  @; T#include <STDIO.H>
/ a( y( l9 f( }4 t+ ~% a#include <CONIO.H></FONT></P>
. ]" `( e: }- E; o% T! q9 D2 F( }<><FONT color=#0000ff>int main(void)   V3 I2 {" N' J
{
0 ?, y' o( k- m# U( w* i/* request auto detection */
: h* c7 e, J1 y* r4 ^4 Bint gdriver = DETECT, gmode, errorcode;
/ G% i9 W- c/ l* Xint midx, midy, i; </FONT></P>, H, D, S4 d* P) A2 |* l
<><FONT color=#0000ff>/* initialize graphics and local variables */ % a: V) n: E. t- d- |# ]  C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' H) K: o8 ]* L! Y# U) p& E<><FONT color=#0000ff>/* read result of initialization */ / w- G2 q2 I& ^" `$ B
errorcode = graphresult();
2 m" y0 }1 ~1 `8 G3 D2 \if (errorcode != grOk) /* an error occurred */
/ ?3 V' p6 ~5 A. g  h6 }8 f{
: K6 Y; S1 B, W: q  b  xprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : T' c5 c! p+ T
printf("ress any key to halt:");
) y0 w( S0 @& n, E& `getch(); / h0 Z% @0 P6 F9 r, J
exit(1); /* terminate with an error code */
5 H. R  s" ^# S3 B! j} </FONT></P>
. a+ ?7 I% W1 k% F9 {0 f1 L, K, f<><FONT color=#0000ff>midx = getmaxx() / 2; - Y# O0 b) a7 Q0 j4 u
midy = getmaxy() / 2; </FONT></P>0 }: c  E( X" b
<><FONT color=#0000ff>/* loop through the fill patterns */
0 {2 R; v) @9 `# pfor (i=SOLID_FILL; i<USER_FILL; <br i++)> {
# n2 x* S$ M8 M. ~2 P/* set the fill style */
* I! E( o% B  q& _setfillstyle(i, getmaxcolor()); </FONT></P>4 Z+ N6 V, o+ l3 `; O4 ~& ^: v
<><FONT color=#0000ff>/* draw the bar */
9 q% G  k0 k2 P/ Obar(midx-50, midy-50, midx+50,
, s9 g7 D, M* e! w- Dmidy+50); </FONT></P>3 v: G' w" s- S% M2 G5 ~' g, W1 N
<><FONT color=#0000ff>getch();
) P! N! Y) f8 z} </FONT></P>
  Y  }7 A  S3 H<><FONT color=#0000ff>/* clean up */ ) h# [( j' e4 Q9 C- {3 R* O+ ~7 c
closegraph(); 8 L, ]3 [* y& S
return 0; & {& s2 o( q2 e  \1 Y
} </FONT>. A* F+ f1 d4 h, J

4 v* o) j8 f7 F! \& D3 Q  A
% p6 e9 D$ G3 v0 f" ?% \) C</P>, s$ B% l- v$ n' Y
<><FONT color=#ff0000>函数名: bar3d </FONT>/ m  k- v1 Y3 U" }
功 能: 画一个三维条形图
& r( N  T) r! K. i, U$ F用 法: void far bar3d(int left, int top, int right, int bottom, 6 v# U0 H/ ~- p' p' o# `& Q
int depth, int topflag);
3 i) W# i# |( v. \0 ~程序例: </P>' D  b! C6 l, U, @* Y- W) n
<><FONT color=#0000ff>#include <GRAPHICS.H>
# y! a; f) s4 M  M5 b#include <STDLIB.H>
- F# i  M- ^9 I' A( a% y' m#include <STDIO.H>
% k1 V8 k1 |+ g! W( w9 s% l: w8 d8 h; Z#include <CONIO.H></FONT></P>
4 Z7 A! f- \  Y8 h<><FONT color=#0000ff>int main(void)
% j; g1 ^: {; `0 W: b, B; W{ 3 X( a9 G. l! R. s7 l1 u% C
/* request auto detection */
$ `( B2 t$ X! {+ q0 ~1 eint gdriver = DETECT, gmode, errorcode;
) r; D# l  h- oint midx, midy, i; </FONT></P>
0 A4 {' K1 Z. d' o) m9 }- Y" ~7 d<><FONT color=#0000ff>/* initialize graphics, local variables */
6 k& s- X- T- z4 E% z9 Q1 @; yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 R8 Z; S7 h3 A/ g" N<><FONT color=#0000ff>/* read result of initialization */
8 n+ U( I4 C. w; G- werrorcode = graphresult();
: h! ]; M4 }! F3 N8 rif (errorcode != grOk) /* an error occurred */ 2 s$ j, s- a; e! y5 [9 i
{
5 J7 r  H# U* H  ~printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 P$ L. E7 P# W% d  V5 p
printf("ress any key to halt:");
) l  E: T. A- \: N4 z0 `  n5 [getch(); ( [0 ^4 K- U* O$ H5 s
exit(1); /* terminate with error code */
$ ^0 m' {' [' A0 u% a) ^} </FONT></P>0 G  x' m2 H' ~/ R9 V# a6 z/ a
<><FONT color=#0000ff>midx = getmaxx() / 2; 6 K" y; W1 |9 m
midy = getmaxy() / 2; </FONT></P>9 y1 ]6 Q# _( f7 s- j
<><FONT color=#0000ff>/* loop through the fill patterns */ 9 \5 m8 V+ [8 I1 W* [5 }; V
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
8 A) p" w3 P) w1 o/* set the fill style */
% v' i8 j1 Y* U* U# Q$ nsetfillstyle(i, getmaxcolor()); </FONT></P>
  y; v* w' V, o; z- `<><FONT color=#0000ff>/* draw the 3-d bar */
3 C+ R! d3 {  Lbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>7 Y1 o, W8 Z% H3 d: e) s3 m* x
<><FONT color=#0000ff>getch(); - \8 g9 D( e$ u# \' |- i1 A
} </FONT></P>9 R. C- |* G" K" }7 V0 t" ^
<><FONT color=#0000ff>/* clean up */ 8 c( h$ ]6 [9 N& T9 b% e/ f5 ~: y
closegraph();
# m% W  q, M/ Z, mreturn 0; 3 }4 M! ^8 ~/ R$ b- |0 l9 p* I+ U
} 5 Z4 B( W$ ?3 J3 v3 M( v8 L0 q
</FONT>
1 V- j* i7 X8 G8 L/ t
1 g0 M6 B3 n" L; q</P>* L  O" v& ^/ G0 i9 _) x: i- n
<><FONT color=#ff0000>函数名: bdos </FONT>; B/ q! d  F" k2 O# f1 e
功 能: DOS系统调用 3 b& b# R- Y( _4 k
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
& R% W6 A) b9 ?9 r2 n( E0 S2 f程序例: </P>$ A, S  r6 W7 ^# E, U$ S8 U* B+ Z
<><FONT color=#0000ff>#include <STDIO.H>
) `8 O+ p+ S% }9 D: P#include <DOS.H></FONT></P>
/ X! p: x0 t; f4 G4 P; a# l<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
# H  N0 w  u4 pchar current_drive(void) ) K: J6 [$ o4 Y/ c& m7 x2 l
{ $ }) }) U; r1 n" V
char curdrive; </FONT></P>
$ d- q1 x7 C* j: _. H( A<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
3 d8 T' w- F2 O& l' hcurdrive = bdos(0x19, 0, 0); . ~9 Q( N" s1 ]* t  r
return('A' + curdrive);
3 }# W& A( H( W: [9 z* A} </FONT></P>
2 [* g, O0 r- @<><FONT color=#0000ff>int main(void) ; F0 s- Y  k' Y* H2 P5 k
{
6 t# E7 h. m1 a% o+ rprintf("The current drive is %c:\n", current_drive()); 1 z" x) h* v1 i
return 0; # x* h0 |7 E7 H7 Q$ _
}
) E1 f; f* O- P' o+ ]7 ~) h4 u6 T% S/ o# p  Q
</FONT>* W0 R3 A/ l9 L- M! @2 O, E$ ^
</P>
* f$ K+ G: W( v. P. I# W<><FONT color=#ff0000>函数名: bdosptr </FONT>1 `0 A* q( J4 C. s( ^. Q* E
功 能: DOS系统调用 2 j- `1 F- f, d& ?" `4 J8 J7 V
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
# h1 n' l8 P1 O% E$ x% t程序例: </P>( v: d% |! b5 w0 S7 ]% l/ P
<><FONT color=#0000ff>#include <STRING.H>/ v* u! F( U/ ~. S5 v" g! R
#include <STDIO.H># {: N0 L+ l7 S
#include <DIR.H>
# ?( N6 i- U( U% @9 F, @: A, C#include <DOS.H>
* ?+ D. r- s) C9 M2 w* v* d#include <ERRNO.H>  y- B2 J% r' l  L6 X
#include <STDLIB.H></FONT></P>6 M6 j" w) s. |9 t) q
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
0 |8 J/ s% {$ q  G, u3 O9 H1 Z1 f<P><FONT color=#0000ff>int main(void) 3 _' w  ?" E( u9 p1 i. f: H
{ 6 S# x( f  B, Y
char buffer[BUFLEN];
: w% b1 l  Q+ Hint test; </FONT></P>
9 }: U9 a" d  L6 I) F8 _+ m1 ?<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
/ ~. s/ m8 G+ I' B; Zgets(buffer); </FONT></P>
$ _% X/ T3 L4 q  H<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); - o3 `4 }8 c1 M& g& L
if(test) * X. M4 _8 I( X) [; l
{ # \& A+ Q  V: {; R! l
printf("DOS error message: %d\n", errno);
, B  B0 ?+ S" z- [$ S; ^7 ]& I/* See errno.h for error listings */
6 H+ Y1 ^& }$ n2 Q- ?. a% m4 T$ Vexit (1); 9 l/ @- {0 g9 ^! J
} </FONT></P>
9 D( N5 j# g# ~& f; O$ u, c<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); " J& k2 Y' L1 o' r/ \7 h
printf("The current directory is: %s\n", buffer); </FONT></P>
/ i( \% i+ a0 j0 Q5 M3 ~4 t<P><FONT color=#0000ff>return 0;
% G; M# o- T& U/ A* l8 U0 V}
2 L7 h+ G- O" c) m: F. Q2 R  b</FONT>- u7 o2 k6 U& h' n- S

8 `9 }" ]8 W: F; E; J4 I</P>6 C( v( Z% j* _- |% f0 i3 A( a
<P><FONT color=#ff0000>函数名: bioscom </FONT>. D! q$ N$ F1 a7 Y: \; z7 X: J
功 能: 串行I/O通信
" ]/ s( \3 ?+ [/ ?- K用 法: int bioscom(int cmd, char abyte, int port); # S! ?: O: ~$ w5 P. r
程序例: </P># t# ]& J- Q/ i% K
<P><FONT color=#0000ff>#include <BIOS.H>! s7 x3 s0 k) b- h8 |: [) \$ l! U
#include <CONIO.H></FONT></P>
( g/ k" U  Q3 Z<P><FONT color=#0000ff>#define COM1 0 . \$ z6 Z1 J1 `7 }6 p7 S
#define DATA_READY 0x100
  U* h) q3 s( c7 I( S; [#define TRUE 1
& `) _/ m( @5 {7 f" x; A#define FALSE 0 </FONT></P>' _! u$ {, C$ `! N% Y
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
  K) ?! ?. N3 Z, y' U' f8 u" S<P><FONT color=#0000ff>int main(void) ; Y0 M& O0 l8 q
{ * h! B- G6 p2 U) J* z" F+ \! c% H
int in, out, status, DONE = FALSE; </FONT></P>
# o/ f* `% _) i( ]; k# Z<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1); ' @: B% z$ k' {+ g, H
cprintf("... BIOSCOM [ESC] to exit ...\n"); 3 S" A% c3 ~- j$ K  r
while (!DONE)
$ @, e! h! j) ?" m& T0 `0 |{ . o* g/ ~$ ]$ e8 Y0 q
status = bioscom(3, 0, COM1); : S- A/ ~9 S; A- k- r
if (status &amp; DATA_READY)
* F: [+ n: s  o6 {- rif ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
" X" s/ w+ r, o1 I. f1 t* {# bputch(out); 9 {9 V% o& V: i/ \  A
if (kbhit()) ; m3 {/ @3 j$ e5 p% o: l: {# F
{
% W. c9 Q: l) Y9 p9 N9 J7 Oif ((in = getch()) == '\x1B') : p0 I" |. H$ \( ?
DONE = TRUE;
, M0 A: L7 L  @; g3 _6 S$ ]bioscom(1, in, COM1);
5 c+ ~/ S% `' H2 M' ]% J) M! m( y5 ^} 5 T5 X( x. n0 I3 F, g! Z& M, X
}
% J' N7 A2 M9 Vreturn 0;
8 U6 W1 u" T* L8 f4 c} </FONT>% P2 H2 a* H. c/ Q
7 x. C, o5 Z' F. v

2 c3 F$ M( B! t; h% l</P>! c5 p1 p3 a3 u
<P><FONT color=#ff0000>函数名: biosdisk </FONT>/ d: g1 K7 A  r; X8 E: T
功 能: 软硬盘I/O
, t* R. x# i" h4 ]0 v& B用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 4 M! b- B5 P" ~
int nsects, void *buffer);
' c( |0 Z# ]% d2 D% g6 u程序例: </P>$ ?4 \: R5 I1 Q
<P><FONT color=#0000ff>#include <BIOS.H>. X7 j  F, k) K: u6 C( u
#include <STDIO.H></FONT></P>
. x& k. C% ~% B2 r# p6 f<P><FONT color=#0000ff>int main(void) 1 [: t7 u9 u9 L
{ - Z3 M6 H' w: ^, M( `. W: M" U2 J& q$ @
int result;
% O" \3 c9 y9 ]2 Q) S1 {0 K) Z! R6 M: Tchar buffer[512]; </FONT></P>
% ^( @. {9 A1 R& R" R" z0 A/ H8 O<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); $ p4 R5 V0 n# c# Z
result = biosdisk(4,0,0,0,0,1,buffer); ; d/ f& Z5 V/ Y  f' X: G4 a
result &amp;= 0x02; . Z1 E0 x& b1 F6 Y
(result) ? (printf("Drive A: Ready\n")) : 0 J9 Z5 z& i) E! d4 T$ k$ d
(printf("Drive A: Not Ready\n")); </FONT></P>
. F& |) x8 [- o4 |<P><FONT color=#0000ff>return 0;
" o' E$ }5 _- L1 N9 Q}
  F- m# d1 e+ V</FONT>9 p" C! s( K& H" @# J) I! `9 \

: U; w, S5 ?* W% S/ }! I$ y</P>
# }$ J/ u( Z4 t3 L- _3 ]<P><FONT color=#ff0000>函数名: biosequip </FONT>
0 E8 N3 @1 s4 g. W' y8 M功 能: 检查设备
/ }6 V4 c+ B% \6 Z, N  Y- l( a用 法: int biosequip(void); + j4 |9 l2 V' d
程序例: </P>' W! z  Z  A0 X  N+ E. i+ l
<P><FONT color=#0000ff>#include <BIOS.H>
' C9 u+ O) b8 C! Q0 P$ Z9 z#include <STDIO.H></FONT></P>0 j# N% O& i) K9 d2 b+ ~0 U
<P><FONT color=#0000ff>int main(void) & n  k; I" u0 A: c: E
{ $ a( J9 a6 W/ ]% Y/ Y4 k% A, J- F* N  h# j
int result; ) b' C- R: B$ M  Z2 U
char buffer[512]; </FONT></P>
. C, R! y; r8 \# i8 b<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
% D, K, o; A$ o" a# wresult = biosdisk(4,0,0,0,0,1,buffer);
* a$ Z3 q8 O; R! z! w4 Mresult &amp;= 0x02; + T. j5 Q% s# ?8 v) d+ ]
(result) ? (printf("Drive A: Ready\n")) : ! b! X4 ]$ E3 Q- Z0 K
(printf("Drive A: Not Ready\n")); </FONT></P>( u# n/ l) Z; W8 R! _* r4 ~! u
<P><FONT color=#0000ff>return 0; ! @9 ^- f7 C, e5 ^$ X; s
} $ e' g# Q/ D( M1 ?  P
</FONT>: p0 X0 B( g# C) ?9 k: m  r9 r

5 i! |; c; |& @</P>; K8 h, v8 m4 |. @
<P><FONT color=#ff0000>函数名: bioskey </FONT>
1 s" D  C) T; a6 _: C; }功 能: 直接使用BIOS服务的键盘接口 . J2 l- B) l5 m; A$ L* W. l* P/ S
用 法: int bioskey(int cmd); : e8 d( a/ ^) I! `+ w# j
程序例: </P>6 Q/ }1 V" j) l% D; f1 e, K' Q
<P><FONT color=#0000ff>#include <STDIO.H>
9 M3 F4 S* ?2 b1 @% q0 z#include <BIOS.H>
1 k; x0 L$ t* [#include <CTYPE.H></FONT></P>  q( J( y* p* q' {( l
<P><FONT color=#0000ff>#define RIGHT 0x01
1 M7 l4 q3 w2 P! ~' T#define LEFT 0x02 - F: T) A, ^; B6 F9 n- v3 o! s
#define CTRL 0x04
3 ^: t1 z( F& U9 k2 C! [4 w: d2 W#define ALT 0x08 </FONT></P>
1 K! ]( A* H* n( I7 }; Q<P><FONT color=#0000ff>int main(void)
# h/ p+ M' f/ {{ 5 g/ h" a5 f/ x# x3 p
int key, modifiers; </FONT></P>
0 H3 J6 h# c7 N! {: P+ N  _<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
" ~# r; V0 Z, p' I* Ewhile (bioskey(1) == 0); </FONT></P>
6 c6 \5 Z: Q  {& d8 L; |<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
- }' {! h8 c. e5 ?1 `key = bioskey(0); </FONT></P>; x4 G0 ]; ]5 y
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ ! }! S3 L' s; C+ k2 ]. A0 u! y+ u
modifiers = bioskey(2); 1 t2 W( ~: o0 F7 {5 v) W% \; H
if (modifiers) " N; l2 }& E2 p$ `3 e" B# b
{
! N3 p2 m" c3 |, Xprintf("["); % A* g' L! w& t- J! j; f
if (modifiers &amp; RIGHT) printf("RIGHT");
! {+ D6 C1 p8 Y- o4 H+ Cif (modifiers &amp; LEFT) printf("LEFT"); / O7 _' r# w) a% m2 C, S4 J
if (modifiers &amp; CTRL) printf("CTRL");
8 A$ [' }6 O- S- _' m. Nif (modifiers &amp; ALT) printf("ALT"); : B# f2 a5 ~* |/ P
printf("]");
2 C; A* N" B& a& r( m}
$ w8 \( @, z) A; W/* print out the character read */ ' ]# P( f; U2 ^3 b, }7 u' u0 J
if (isalnum(key &amp; 0xFF))
6 f9 _3 j6 r! L, p4 ^printf("'%c'\n", key);
6 @! }- E8 x" ]  z6 O% helse
4 l2 a8 t& j" V- {: Kprintf("%#02x\n", key);
& \1 S$ Y, H: o  `, x$ Rreturn 0;
0 n5 y: h1 f4 d7 O2 o, n* N}
5 ]9 s4 m" Q6 D0 A+ I8 ^9 k" ~8 c  J/ ?
</FONT></P>2 @! N+ `8 `! }8 m
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
8 e1 M/ q7 j; i# @5 d1 b6 t功 能: 返回存储块大小
' E: Z) j5 q  x; p# Z$ w) U用 法:int biosmemory(void); : m7 ^% j. B+ r4 L1 g
程序例: </P>; N8 ?: E- c* n
<P><FONT color=#0000ff>#include <STDIO.H>! g* O! [$ R$ }
#include <BIOS.H></FONT></P>
; l2 w. F; j: j( i. K- _- L- I. `<P><FONT color=#0000ff>int main(void) ( E9 h% n1 T; @1 [  i4 D5 y+ g
{
  k& G  {$ S1 F: r' Y! ~int memory_size; </FONT></P>
6 A/ L7 I* @; N# u. ^- D<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ 3 n! A* c8 l" ]+ S* j9 H
printf("RAM size = %dK\n",memory_size);
! q1 \! u3 X7 q) a! rreturn 0;
: {& R5 q' y, W# z' \  ]}
# }; C& J( o* Z2 B' I</FONT>4 K4 T+ y7 N" N! H
: C+ B" m& h) ?2 G
</P>" q# t/ u3 g( k
<P><FONT color=#ff0000>函数名: biosprint </FONT>/ P9 J5 ^; h- y9 `4 u
功 能: 直接使用BIOS服务的打印机I/O $ }% a" w  ~! }4 s
用 法: int biosprint(int cmd, int byte, int port); 2 W9 u: X. D. h6 \! P8 E
程序例: </P>" J4 l7 a  i/ a% [2 t. S9 Y
<P><FONT color=#0000ff>#include <STDIO.H>
' ^4 r9 g+ j1 r& m#include <CONIO.H>2 k/ F5 Q/ _8 I- |: L
#include <BIOS.H></FONT></P>; R6 H- @  ~4 U. x
<P><FONT color=#0000ff>int main(void) 2 y, E# ?* Q. ]  @$ i+ g
{
  {/ {; P: n/ ~2 |$ a#define STATUS 2 /* printer status command */ 0 V& K, r( w% |% h! l2 Z9 L1 b
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
" A3 h) v6 _' q5 q; |' }: ~<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
/ S# P* G8 Y1 B5 g. F<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 1 k. D; X( T; Q$ u$ y. u5 l5 j2 B( R& ]
getch();
* _6 q; F. N5 c. fstatus = biosprint(STATUS, abyte, PORTNUM); 9 D! _4 a( U5 V5 P( D
if (status &amp; 0x01)
/ E/ G" ~/ ^* O; n! Q+ K3 Q" T/ \3 S: Xprintf("Device time out.\n"); 1 E9 U1 Z4 e/ M, D& r- G9 L& Q
if (status &amp; 0x08) 5 e8 b0 B+ K! l* n0 O
printf("I/O error.\n"); </FONT></P>
3 |( w, t: o9 s" d$ i<P><FONT color=#0000ff>if (status &amp; 0x10) + u. _6 |# ?% c+ X
printf("Selected.\n"); : d3 o- u& \; X9 ^
if (status &amp; 0x20) 7 W) g# E# t" o2 n+ R+ O+ K
printf("Out of paper.\n"); </FONT></P>
) i* s, J' L2 {$ r! M# u<P><FONT color=#0000ff>if (status &amp; 0x40) . g1 |$ U# [$ q
printf("Acknowledge.\n");
9 [! {, X9 `1 i: E4 p, Pif (status &amp; 0x80) ; @: |8 r% f% s  K# ^
printf("Not busy.\n"); </FONT></P>
5 p! Z  i/ h; \9 n<P><FONT color=#0000ff>return 0;   f8 v4 o* X: E% w# Z
}
1 p* s. n/ H5 R9 P3 C</FONT>
3 c4 z4 H/ e) @3 ~& c& n0 C$ D+ i% S2 ]+ D2 Z) k) `
</P>
, A' V# C; G% y# E. `2 v% ^<P><FONT color=#ff0000>函数名: biostime </FONT>* p6 ]5 j4 B1 v. p9 y
功 能: 读取或设置BIOS时间 $ q( H: j/ r- \3 Q9 k7 }& B
用 法: long biostime(int cmd, long newtime); $ A! ]/ s% |3 G
程序例: </P>
1 N& C6 U  W" v<P><FONT color=#0000ff>#include <STDIO.H>; U% i: I. O, ^9 K) @
#include <BIOS.H>: h( G) |, O- y' q) `# P& z- O
#include <TIME.H>
% p2 s3 r! J- d, {7 e- k7 U: N#include <CONIO.H></FONT></P>
2 h- D" S% V6 z/ j3 E<P><FONT color=#0000ff>int main(void)
; j4 ~# S' ?: y7 c8 B) Q{
; n: H) U, R( C# S1 j- h" N  _( xlong bios_time; </FONT></P>' [- g6 A, W2 J, e4 o
<P><FONT color=#0000ff>clrscr(); - K, O3 |' E" Y- t& H# O1 @
cprintf("The number of clock ticks since midnight is:\r\n");
: v# N  Q3 O' w: _. _$ ncprintf("The number of seconds since midnight is:\r\n"); - \- N) e' S6 }4 [
cprintf("The number of minutes since midnight is:\r\n"); 6 X" |( Z2 G  }! _2 G7 e
cprintf("The number of hours since midnight is:\r\n");   I5 ]+ E: y7 U2 A1 r: i
cprintf("\r\nPress any key to quit:");
( n" m. X! s- H# }* |6 Y- s4 S1 U3 {while(!kbhit())
+ I; {+ Y+ ~& D{ 0 R" j0 J) b, h! h; V. m9 M
bios_time = biostime(0, 0L); </FONT></P>
+ _. ?' H# l2 q<P><FONT color=#0000ff>gotoxy(50, 1); , l$ }5 q# H1 u- s# A' Y5 h
cprintf("%lu", bios_time); </FONT></P>- p. g" u& a+ |' j7 o4 R/ C7 Z
<P><FONT color=#0000ff>gotoxy(50, 2);
# Q( P, X1 \+ d: }  Qcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>( K1 p0 F$ `3 v% v
<P><FONT color=#0000ff>gotoxy(50, 3);
$ f+ E* \& v  _! n$ W7 Wcprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>; j) O, H# r- p9 y/ i, ?+ w
<P><FONT color=#0000ff>gotoxy(50, 4); ( g: s3 m! D: l9 [9 O! A
cprintf("%.4f", bios_time / CLK_TCK / 3600);
3 r6 p+ h: `# s& V; ^} " T2 @' l2 ^3 K+ x. P/ N
return 0; * z) D8 u# \2 b! @
}
8 x7 O( K, h+ C; Z/ b% R: P. l</FONT>
4 P" {' P9 |" X. M+ w5 v9 r; @: e/ Q/ Z
</P>
% f% }  y+ @5 r& n<P><FONT color=#ff0000>函数名: brk </FONT>5 h2 P! u. F0 h  J+ t5 }6 ]- D) D
功 能: 改变数据段空间分配
5 z* u6 q* X  m9 j' G用 法: int brk(void *endds);
% Y5 l/ W/ {2 E& _程序例: </P>
, O! B5 p  L' ~- E<P><FONT color=#0000ff>#include <STDIO.H>* y  M1 K2 ?* `3 g, A
#include <ALLOC.H></FONT></P># ]+ H1 ~9 k' x( r. l& h8 _" v
<P><FONT color=#0000ff>int main(void)
( k% ?" [( y5 _. P3 ]4 a( m+ N{
  ^7 L- j1 I9 l! M$ F$ ^char *ptr; </FONT></P>
7 z8 N% m# H9 g1 q6 {2 }<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
( D. t' w' Z1 P5 X* v+ U4 \ptr = malloc(1); ) _! H2 s  }' _+ r; u4 i
printf("Before brk() call: %lu bytes free\n", coreleft()); ; N. q  X) |8 @3 c+ S" s( F
brk(ptr+1000);
6 h6 N# ^: k5 O% `) h4 Eprintf(" After brk() call: %lu bytes free\n", coreleft());
! ?% I' U- U* K5 t3 i) r' {return 0;
2 A, K- P+ F, N}
9 Q; O' \1 w  Q5 @0 D$ E3 B
$ D" F/ b0 e/ |' ]</FONT>: u" x" N; u% r9 r6 r  F  c5 M0 D
</P>
& s6 a  F+ h2 y$ N' }2 f1 H<P><FONT color=#ff0000>函数名: bsearch </FONT>
& l* E  d6 K- U& E( t功 能: 二分法搜索
) P7 L) H  y- s9 t* c& a用 法: void *bsearch(const void *key, const void *base, size_t *nelem, % E" C1 c4 N6 t. Z9 }6 q- z, W
size_t width, int(*fcmp)(const void *, const *));
  V/ i+ H) M3 ?! k6 G程序例: </P>
! P/ c2 N% t, k<P><FONT color=#0000ff>#include <STDLIB.H>9 \6 j" T( X- i: I
#include <STDIO.H></FONT></P>
* {+ {& k  W( B$ Y9 `6 ~3 F<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
% k, C3 [6 Q, k. N/ u$ p<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
' H* [- P2 k! _4 q<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
# o: V8 j4 y3 U" P{ 1 U% [' U8 d# g2 O( H5 C
return(*p1 - *p2);
/ `7 `$ J  g, ^+ R" S6 ^} </FONT></P>! i& q3 J+ Q0 H
<P><FONT color=#0000ff>int lookup(int key)   |6 v, K. s; z7 D  Q
{
+ L9 n0 o% e1 n, V% y$ m) @int *itemptr; </FONT></P>$ G" t, X0 m1 T. S; o8 t
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) : t" R5 ?$ ?& |2 c/ w' f
is needed to avoid a type mismatch error at
7 [9 x. Y- B: S4 g' `compile time */
' v; d, }7 V, d9 \) L/ ?7 Iitemptr = bsearch (&amp;key, numarray, NELEMS(numarray), 0 h. w' c: i; C  o) ~0 a
sizeof(int), (int(*)(const void *,const void *))numeric); " E. T0 Y$ g: Z. x; z/ ~3 W
return (itemptr != NULL); ' A9 r; _; s: @9 O/ d- a
} </FONT></P>
- _+ k# P8 B$ n<P><FONT color=#0000ff>int main(void) # I+ v. [/ t+ O  B! X) X) P& M
{
1 w  h3 r7 A8 Z) i( Z4 n* K1 N) F% M  j- Eif (lookup(512)) 1 `1 \7 D4 \% W4 _
printf("512 is in the table.\n"); / T7 {7 U7 f( H8 ^$ P/ T1 n
else ; a/ @2 S7 L, K% _/ y; o! |
printf("512 isn't in the table.\n"); </FONT></P>- Z2 |3 Y0 y0 ]' K/ t3 d
<P><FONT color=#0000ff>return 0; $ S+ E/ {2 T: k
} </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-12 13:11 , Processed in 0.408064 second(s), 52 queries .

回顶部