QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1771|回复: 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>
. c: r; X' J2 Z3 W0 X<><FONT color=#ff0000>函数名: bar </FONT>9 E* C& f( P* T- q! ]+ s' Q
功 能: 画一个二维条形图 9 t, H: x0 g: i" a
用 法: void far bar(int left, int top, int right, int bottom); - z0 g" O9 h0 v2 M/ V# t) C
程序例: </P>
) d9 j2 k" N. l" v3 v% H<><FONT color=#0000ff>#include <GRAPHICS.H>
) _' ?1 U$ B; ~' f8 O6 ~4 ]#include <STDLIB.H>4 B( y) B* K. H6 ?5 g7 q
#include <STDIO.H>
! h% M  l5 L7 G2 @4 i3 g* S#include <CONIO.H></FONT></P>8 [' }  I3 q$ o9 C1 w1 S
<><FONT color=#0000ff>int main(void) 6 ~; ?) g% _/ b6 }% [5 a
{
& e( G7 z& F- l2 K4 }7 W: f& m/* request auto detection */ 9 v7 ?- l9 u$ Q3 V- c
int gdriver = DETECT, gmode, errorcode; ( _1 t. \9 h) u5 F9 e0 i& K+ C
int midx, midy, i; </FONT></P>5 W# ^' Z& O$ r! l, r" q& S
<><FONT color=#0000ff>/* initialize graphics and local variables */
9 J1 Z6 l) |; m' oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 B; _' e% A7 b, k( l/ x) z<><FONT color=#0000ff>/* read result of initialization */
3 {* ~3 F3 L( V/ ]9 f* B; gerrorcode = graphresult();
2 K# j" s6 g! q- q( W8 U! Qif (errorcode != grOk) /* an error occurred */   W6 n. p2 ?1 O9 J, \" o$ x; T& M
{ - Q6 u9 R  G5 _5 K) |+ b  ~7 o5 X
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 F5 M3 V! M; c: f) D8 Q: |
printf("ress any key to halt:");
, e6 X/ _) r* C8 rgetch();
, z* v* H# [* p5 c6 w- Z+ i  |exit(1); /* terminate with an error code */
7 e+ h5 l1 F/ ^! O3 d3 }} </FONT></P>
' w2 u2 W! b, k& X7 z<><FONT color=#0000ff>midx = getmaxx() / 2;
8 @5 M4 r# y/ J: I* c2 R6 kmidy = getmaxy() / 2; </FONT></P>+ I* @6 F! e, M* I8 t
<><FONT color=#0000ff>/* loop through the fill patterns */ 2 y- n5 v3 `( O/ w! [: g- B1 |6 K
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
$ `6 C- L) N9 C- _! X2 ^' U/* set the fill style */ 3 `7 t# s: R! |; `7 A+ J
setfillstyle(i, getmaxcolor()); </FONT></P>; K4 o+ ~3 c6 ?- m6 {, |
<><FONT color=#0000ff>/* draw the bar */
- u- j% x! `, L0 N& sbar(midx-50, midy-50, midx+50,
! L. F  ^& _1 Q0 K  bmidy+50); </FONT></P>
0 d$ Q  s+ P: v" N) F, e<><FONT color=#0000ff>getch();
8 b) N2 ^0 T- j+ c: F; F} </FONT></P>
1 A2 _; T7 v% E1 u- J! E<><FONT color=#0000ff>/* clean up */ 5 Y3 l, }8 s( r0 o' m$ p
closegraph();
% e* x# f8 E* ?) ~, hreturn 0; 6 Q- p( l- U; J, @, ?" X4 w' P
} </FONT>% q1 v- C8 n6 |7 k8 J- ^" g
  Q0 O& k6 h. X( Y) k

8 I& s0 F, a. ~% E5 L8 L</P>: P* x7 p  Q' b; o. [/ ^
<><FONT color=#ff0000>函数名: bar3d </FONT>! t# i$ M) H8 w' j2 w# Q
功 能: 画一个三维条形图
6 P* z- L) f2 r7 }: l: k% x用 法: void far bar3d(int left, int top, int right, int bottom,
( D. V  `( g& i! I9 |int depth, int topflag);
" `) `8 ^, v! R: k1 A2 X程序例: </P>
0 h: {7 C& u- X<><FONT color=#0000ff>#include <GRAPHICS.H>/ Q  j- X2 f$ m+ K6 r9 `
#include <STDLIB.H>
1 C8 M' G# r5 A% l#include <STDIO.H>
1 K% I  n! j2 |& f#include <CONIO.H></FONT></P>
' ?1 Q( m4 C/ r/ a<><FONT color=#0000ff>int main(void) / C' `/ R7 m/ z, o& B  A
{
6 Q: p% l: o3 n* [. [* ~/* request auto detection */ 0 Y# M1 R( A" s+ Q2 A# U
int gdriver = DETECT, gmode, errorcode;
' f3 t8 Q  v% S4 j8 }2 Mint midx, midy, i; </FONT></P>, |: ?3 ]; Y" u; I. b  k
<><FONT color=#0000ff>/* initialize graphics, local variables */
4 m' ]# @2 j6 Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
& x  y% N5 l7 C6 |6 G! {<><FONT color=#0000ff>/* read result of initialization */
3 {+ e. g0 D7 A9 l, {" `errorcode = graphresult();
$ j8 X% X+ N$ s/ P' z# k& Cif (errorcode != grOk) /* an error occurred */
5 D3 j7 H- ?' M0 w{ 1 X5 L- M! _) q# u0 d+ r2 a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
, L- ~" @  Y7 W. q4 y. ^printf("ress any key to halt:"); , l# ^. `  m: t5 W2 X$ t
getch(); 5 @+ y% A% \' F' s$ l
exit(1); /* terminate with error code */
8 Z& z7 K$ m1 E5 b" T4 D} </FONT></P>0 j1 \! {9 p; {6 v/ S# I
<><FONT color=#0000ff>midx = getmaxx() / 2;
. U0 {/ d5 P9 c. x! x1 |midy = getmaxy() / 2; </FONT></P>
% I! I& N2 p4 j<><FONT color=#0000ff>/* loop through the fill patterns */
0 U9 [5 I. q; Z2 G4 B* efor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 3 q& W/ U/ ^4 W. }. [$ `9 s
/* set the fill style */ ( \9 \0 ?! V& R& K% ^% t
setfillstyle(i, getmaxcolor()); </FONT></P>
. ~  Q* i. E1 Y( B$ s% t3 J0 U<><FONT color=#0000ff>/* draw the 3-d bar */ 5 h, D. {( p$ C3 e& x9 c
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
) E/ u/ M/ k. J2 W! v<><FONT color=#0000ff>getch(); 5 F' y1 y# _. C- L+ \  q3 G: L  A" i2 g
} </FONT></P>! s. \; B& H  r! B+ f
<><FONT color=#0000ff>/* clean up */
6 b( r# D4 j  D; h, p$ eclosegraph(); 3 `( q; w, }9 j3 n0 t  ?$ o2 N' Q
return 0; 7 w! i" C/ `4 M8 Q3 U
} % L- t& _7 L. T) B# J/ F$ z4 L- b
</FONT>
2 x, y6 q$ T5 A! t* F3 e  l% w. u! w+ G
</P>* u: [' X5 I1 |
<><FONT color=#ff0000>函数名: bdos </FONT>0 w0 I& r( R: c' D
功 能: DOS系统调用 6 _1 _6 p+ P/ i. r# \2 d- i6 K5 S
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
) p" I4 a2 `& a+ K2 w" m( X程序例: </P>* I9 K$ j) R2 t- a5 ?7 o( S
<><FONT color=#0000ff>#include <STDIO.H>
- k; e( v- X) A" q) ~) ~1 r( \#include <DOS.H></FONT></P>. [" [" y  y( k
<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
& O3 Y3 @/ _1 J1 Q. Achar current_drive(void) 0 i1 d. c% q$ \9 t
{
4 ~5 N' G. z( }1 o- R# }0 C0 R& nchar curdrive; </FONT></P>$ q+ k" }# Z. F; Z
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
6 E) ?( g; \3 w. S# |1 n$ |  Acurdrive = bdos(0x19, 0, 0);
8 b8 @0 Q! P5 I- C+ _/ _9 ]return('A' + curdrive);
0 r. m' ?' D# v; ]- u$ h} </FONT></P>: B8 }: }) m" Q8 b2 C
<><FONT color=#0000ff>int main(void) + W3 g# I0 `1 M
{ ( e  }& j. x$ }' X) J
printf("The current drive is %c:\n", current_drive()); : C, S) K) T& w  }
return 0;
' q/ h/ H) G9 b" y}
+ u7 ^/ Z! E3 t& Z( q& w5 n) M0 ?. H: @. x; T9 W$ j) i# t* t$ C
</FONT>7 t8 {& S; ?; w
</P>
/ k+ Y8 ?0 m9 \$ V) b* ]<><FONT color=#ff0000>函数名: bdosptr </FONT>0 I+ S  T: }$ g7 P1 a
功 能: DOS系统调用 ( `' n# S, t) D$ O2 h  n
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); 5 c  K& ?/ J5 q* j
程序例: </P>
2 }7 D  D. r( G- q7 [1 [& F6 D<><FONT color=#0000ff>#include <STRING.H>. s) Y- v% n2 v2 K& f
#include <STDIO.H>* P3 {* y0 i0 U1 p0 ]! ?9 t, N
#include <DIR.H>1 y  o9 ^( q+ ^# Y( c% ^
#include <DOS.H>  o) v/ e/ f  I( \1 \# N# q
#include <ERRNO.H>4 k7 x6 e+ x' R( d$ \! ^
#include <STDLIB.H></FONT></P>8 k# R% B3 g3 u  b8 U. y/ v
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
& e, B5 p. n) w' T0 h+ w) K<P><FONT color=#0000ff>int main(void) % R0 i+ K5 S+ u2 s' M+ E
{
- p0 j7 v" ~: u' y5 M1 l3 Qchar buffer[BUFLEN]; 7 p9 i+ a% b# H. R* Y/ ~: b+ t' ^
int test; </FONT></P>
4 g+ p2 V+ d  N- N! `+ s  e' ?<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); ' E: [3 p4 M3 y5 U  @  ?/ j0 `
gets(buffer); </FONT></P>5 B* F  ~) z. m- @
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 4 U. b, m. E. X/ o$ F3 \* B- p; C
if(test)
2 N4 n! }0 ~: Q# ?* S' N; z% v{ 2 ~9 c0 I! g  z  ^0 c' F
printf("DOS error message: %d\n", errno); ' t( J1 K' L8 |* Q0 ~7 h7 s' a
/* See errno.h for error listings */ 7 }9 M3 {' B  T, ]
exit (1);
1 \) }0 u5 U0 h9 W2 o} </FONT></P>
& Z( B* |7 X/ B* O: G<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); 9 j, F, ?! |7 g- b1 o& X
printf("The current directory is: %s\n", buffer); </FONT></P>0 w  O. B7 [* n2 \) m8 p$ X0 z8 _
<P><FONT color=#0000ff>return 0; % s. [/ q" ^. E* o3 Z. u
}
2 k# v) T8 O% _( W; I5 O- }</FONT>; M' W& a! V0 r$ @; k; Z
7 z) @' ?7 p: c$ d$ F5 G; d/ @+ I# _
</P>
& T( U) m; O0 {0 [<P><FONT color=#ff0000>函数名: bioscom </FONT>
3 _; R# x2 b( G- ~" E# c3 t功 能: 串行I/O通信
1 [6 M6 X$ Z4 Q, w用 法: int bioscom(int cmd, char abyte, int port); 6 ?' L( ^- I3 N$ |+ C0 I, R
程序例: </P>5 u, H! k* }6 _$ r
<P><FONT color=#0000ff>#include <BIOS.H>
9 R: K/ C7 ]. h' P# k( U#include <CONIO.H></FONT></P>' `$ X* l4 q3 P6 f2 [1 H+ ^, [' Y# W
<P><FONT color=#0000ff>#define COM1 0 % v' q  F$ v5 t4 h4 c8 \( W
#define DATA_READY 0x100
* u. x+ j$ J% U) \#define TRUE 1
  E2 S- G0 B. r1 _7 {9 f#define FALSE 0 </FONT></P>. B4 ?# R4 H- a1 I, t$ j
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
' N9 R7 U# ~$ h0 E<P><FONT color=#0000ff>int main(void) 2 D- w% r& |( ]. W$ r' {: I
{ % |7 {+ _4 b2 t% ?+ H0 E% r
int in, out, status, DONE = FALSE; </FONT></P>
( ]. O, ^! C' q% l" `/ \: i, F: m<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
+ h' N: u. h$ m/ h# acprintf("... BIOSCOM [ESC] to exit ...\n"); 5 i7 H+ B0 G( N2 T+ B+ h
while (!DONE)
" [2 ~$ v) A6 ?2 ^7 Y# `1 Q( [8 q2 Z{ ' E/ V3 @8 [- {* n" Y. }0 X
status = bioscom(3, 0, COM1);
+ G9 C2 v. G/ T8 A% Rif (status &amp; DATA_READY)
( K% u7 l# i' S3 k4 Lif ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
4 `1 j3 k$ m) w$ [  zputch(out);
1 l9 k, y5 H+ u5 a; Iif (kbhit()) ! {, T5 c9 _- S" [. G* n; v
{
( w. O: F# X! Y2 i5 g- nif ((in = getch()) == '\x1B')
; \1 s7 f8 O" x) U: c3 T: [6 CDONE = TRUE;
6 r3 s9 f8 Q3 J/ k6 Q7 I- {1 Nbioscom(1, in, COM1);
/ `' [6 @4 m, L! ^- z} / P' O1 R8 u# m. H* u4 D6 c
} 2 O0 G3 W6 x% f# \+ [
return 0;
1 |7 H/ O% H! O) E0 O1 T} </FONT>
* i; ]. [) L3 G/ z3 _5 F, j2 E2 N+ g7 K
( f' D5 C% K$ k& i) z) H" M! T
</P>& y5 {- ^4 w* J, F
<P><FONT color=#ff0000>函数名: biosdisk </FONT>' k) e1 C, _! c& s, G
功 能: 软硬盘I/O ' ?& X5 s) b0 @7 Q8 y
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 7 K" d( m" J1 y/ n6 Z# l
int nsects, void *buffer);
. s- k0 `$ e5 ?3 ~$ I+ C程序例: </P>
; ^+ k6 i2 Z( {, U0 N; R<P><FONT color=#0000ff>#include <BIOS.H>2 ?0 F' c- f2 R7 F  X$ a" n
#include <STDIO.H></FONT></P>% f9 M! S+ X$ S& z5 T' A
<P><FONT color=#0000ff>int main(void)
5 {3 D) A1 s4 e: h: |{ * h; |: u& T7 J7 p9 o; k- |7 L
int result; 9 N9 W* j" T+ J) m, ~1 o
char buffer[512]; </FONT></P>
: v! Y" t, E3 v/ R9 e0 N' X<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
$ {/ J- T- R/ h. Z  G0 gresult = biosdisk(4,0,0,0,0,1,buffer);
, f) C& _" v  H; d1 D7 a4 uresult &amp;= 0x02; : l3 E* |9 ?$ N, Y  L
(result) ? (printf("Drive A: Ready\n")) :
; l5 w2 d% }) J& P- f(printf("Drive A: Not Ready\n")); </FONT></P>
" D- l( g) o3 v+ x<P><FONT color=#0000ff>return 0;
( F" X, d# s: D( p+ w} 5 ]. E+ ^- X- n' b0 q
</FONT>
8 O. k$ a4 w" |1 R* V+ m1 R$ ^9 f- f+ G1 N7 V7 z, q
</P>
; J) B+ w2 J) H) U% ^8 V3 o<P><FONT color=#ff0000>函数名: biosequip </FONT>
1 [( v1 B# c/ g- p( |功 能: 检查设备 & d: I% {* e9 v! c$ x9 F
用 法: int biosequip(void);
5 O4 U( A& g# K- d程序例: </P>9 }% g# ^7 w7 {6 a* j: v  L# g& p) p
<P><FONT color=#0000ff>#include <BIOS.H>
, h# U: W; g: V+ x+ d#include <STDIO.H></FONT></P>& j3 L: O8 K2 @7 f" T
<P><FONT color=#0000ff>int main(void) 7 W9 c% u" j: H3 K
{
8 b. p8 v0 p) I5 P: Q) d1 k1 Eint result;
+ b4 m7 K/ G( Y0 }) `& _. ichar buffer[512]; </FONT></P>% z- _- A5 l& k8 i& i6 u$ l+ A' i
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
; g2 \- C  i& ~; {" f( A" qresult = biosdisk(4,0,0,0,0,1,buffer); 0 F+ x+ F2 {, p4 r
result &amp;= 0x02;
0 R  p$ J8 U* K' O* d, h# F1 ~! N(result) ? (printf("Drive A: Ready\n")) :
7 P; Z" d  ?" C- I* a- ~(printf("Drive A: Not Ready\n")); </FONT></P>
$ c! C+ G5 \" b<P><FONT color=#0000ff>return 0; , Q2 _' L6 J* v2 U- |! B
} 4 V) f3 W1 W: E/ \3 H, A) s
</FONT>
! g4 g/ P% e; E; t! T- [5 `8 M& G8 F1 b1 ~$ m
</P>
& d. p( l7 b' Z' W0 @0 K6 f<P><FONT color=#ff0000>函数名: bioskey </FONT>. A/ ]# F+ X4 H& X
功 能: 直接使用BIOS服务的键盘接口 " s, R& ]! q  I2 w0 q
用 法: int bioskey(int cmd); 2 w( B" g  |1 ?8 d) h, m9 a
程序例: </P>( O: h; M9 `( f$ S
<P><FONT color=#0000ff>#include <STDIO.H>
0 k+ V9 e! d! F0 e8 B0 @) T) K* e#include <BIOS.H>
$ s/ v9 ^: V  A/ i: m, h1 A" X#include <CTYPE.H></FONT></P>
- `1 r( S4 H+ [<P><FONT color=#0000ff>#define RIGHT 0x01 7 c- }- f/ I: W1 E2 b8 h
#define LEFT 0x02 , c; ]1 [: Z4 k& c3 k
#define CTRL 0x04 1 }  n+ ], Z: _) c3 e# v  t
#define ALT 0x08 </FONT></P>
2 c$ Z& a# f/ T7 p! Z& ]<P><FONT color=#0000ff>int main(void)
! H& S  |1 d  u7 \! s4 y{
  O! v% a! F( H1 pint key, modifiers; </FONT></P>
9 O/ M" w8 X" C$ P<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ 7 d$ j$ h: x3 z2 e7 z
while (bioskey(1) == 0); </FONT></P>$ B1 W5 R, F0 i4 g4 @3 z
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
; d& ^2 C9 v9 D# X! V. w% D* zkey = bioskey(0); </FONT></P>/ d# J. }8 J6 Y$ `, L: T. [, G
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ # ~+ ?' G" p( n: S+ x
modifiers = bioskey(2);
9 Z0 v6 a4 c( b4 K: {6 ^if (modifiers)   M' p  ^- @* }. q+ ]0 ]! s
{
9 u5 i& ?3 }! ?; N0 ?printf("["); ' g' B+ }+ _; p# J
if (modifiers &amp; RIGHT) printf("RIGHT"); ) C  B. M2 Z$ Y
if (modifiers &amp; LEFT) printf("LEFT"); 7 u: G2 {. U; k8 u
if (modifiers &amp; CTRL) printf("CTRL");
& U, o, F0 Y- |: ^1 _1 tif (modifiers &amp; ALT) printf("ALT");
1 s$ [2 g6 `" f1 i# e) Sprintf("]"); 4 `  V" A6 e1 k8 c( e, G
} + A, b: B% Y! F/ |( K
/* print out the character read */ 3 d; F3 f# L( [" q! Z+ t8 t/ \+ W. o9 g
if (isalnum(key &amp; 0xFF))
& [" V+ B! H8 D, y$ E8 F3 Kprintf("'%c'\n", key); + z5 a( V; o, c4 ^% K1 E, {
else
* N* e+ I* U& a# G$ T0 Eprintf("%#02x\n", key); / Y7 m1 v2 `9 B" t
return 0; 7 M0 u& y% p2 r# [
}
' O2 b) E1 r8 s. v2 f+ y7 f9 c8 w+ F9 L9 f- F3 V; |% E
</FONT></P>: m' c. V# z  i( I1 ^! V
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
8 U0 P9 D: I. \/ b; J9 ]+ W3 P. k功 能: 返回存储块大小
& p7 d' R, {% z+ G- X& n用 法:int biosmemory(void);
+ e' t0 T0 r" ^/ q- J程序例: </P>" U$ y# m, U6 \9 O" Z
<P><FONT color=#0000ff>#include <STDIO.H>
8 N1 j. \% `( Q! f# \' {: c, d#include <BIOS.H></FONT></P>
1 u8 Z6 B( h$ P! E( ^  C<P><FONT color=#0000ff>int main(void)
! S$ n' {& q+ p{
1 Q' L) `7 Y$ X8 Z; Aint memory_size; </FONT></P>. X$ J2 g5 N  t
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
5 O$ l9 ~( S. Fprintf("RAM size = %dK\n",memory_size);
5 G7 V. o' \6 W0 e7 k6 ureturn 0; $ S2 d. l- C/ V. S8 h- T& H
}   h/ o5 e1 V: i8 {
</FONT>
) v1 R) [. _6 F' ^2 x2 L0 i; F8 b# }8 n* q+ g: V
</P>
9 Q! k! I. Y" Z" s<P><FONT color=#ff0000>函数名: biosprint </FONT>4 r; ^! \/ p3 L$ I/ u5 g
功 能: 直接使用BIOS服务的打印机I/O
9 @! y0 j+ n: Q用 法: int biosprint(int cmd, int byte, int port); ' O  t) b& o* l, l
程序例: </P>
* d. ?9 w' M) U8 `  t<P><FONT color=#0000ff>#include <STDIO.H>& y! y# |+ g7 O: f& W+ ~  ^/ U" \
#include <CONIO.H>3 f5 w. o$ d! `) \3 I
#include <BIOS.H></FONT></P>; M8 L$ f5 ]( W
<P><FONT color=#0000ff>int main(void) - c5 h5 K; f, M" g" X, J: K) t, L% u
{
  i0 j; r' P; I/ f#define STATUS 2 /* printer status command */
" F$ Z% L) h! `( P, A" _#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
4 n0 J5 z2 Y' X% }<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
" x; A4 H3 u- X- \<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
; [* M- g# H' R$ g/ ^5 Cgetch();
. h9 u' b2 B( f2 Bstatus = biosprint(STATUS, abyte, PORTNUM);
  X& L( Q# z; dif (status &amp; 0x01)
9 A  ^8 G% J- z* o' ]% f6 tprintf("Device time out.\n"); 0 w. c% d, V$ r* t) k# f
if (status &amp; 0x08)
0 ~$ ~7 X5 K) x- R: Cprintf("I/O error.\n"); </FONT></P>
# P2 d) I+ ]0 a/ S1 R. Q<P><FONT color=#0000ff>if (status &amp; 0x10)
7 }. T( z" V. h2 j8 bprintf("Selected.\n"); - \1 _$ c& h9 b- Y* g
if (status &amp; 0x20)
4 L" c3 U( R8 A! {3 |printf("Out of paper.\n"); </FONT></P>
8 U) D5 ]0 S9 k( _7 ~<P><FONT color=#0000ff>if (status &amp; 0x40)
& c; N1 g6 m! x' Q- T( Jprintf("Acknowledge.\n"); $ m7 U4 X. l2 M3 \  U8 P
if (status &amp; 0x80) 8 f' E: e! V3 Q2 L. ?! ?
printf("Not busy.\n"); </FONT></P>" ?+ L2 ^. _( G3 D
<P><FONT color=#0000ff>return 0; 4 X. ~# S# t+ I8 r1 }
}
% f8 D0 h4 o* O7 M</FONT>+ d6 b$ F" j) W( {
! q3 T. E4 X' j' Z0 ]. J# g& c
</P>
+ L& w3 c7 o. s% _1 s+ X) y, r8 |<P><FONT color=#ff0000>函数名: biostime </FONT>
* t, C- C0 B' K功 能: 读取或设置BIOS时间   U% q  ]  M/ m5 ]6 ?4 v
用 法: long biostime(int cmd, long newtime);
+ `- j' f$ \) P. f4 W7 \9 l程序例: </P>( A# n0 g% e7 N" ~
<P><FONT color=#0000ff>#include <STDIO.H>) y/ P* r; }3 O  G1 N9 O
#include <BIOS.H>
8 y4 z3 }6 _0 a( U; h; S( q5 Z0 A#include <TIME.H>; [% f* M$ }: w' L& V
#include <CONIO.H></FONT></P>  j- T- q( a  h% ~+ C
<P><FONT color=#0000ff>int main(void) * g0 ^9 b, c; R$ u
{ 0 X- D& G( {. O- m
long bios_time; </FONT></P>
7 C1 d( j6 H0 a/ \* z  ^<P><FONT color=#0000ff>clrscr();
6 i" I- e1 \) v/ G) f6 L0 g: kcprintf("The number of clock ticks since midnight is:\r\n"); . \; s- @3 n7 z6 n
cprintf("The number of seconds since midnight is:\r\n"); ! e5 {7 {7 y! ?% Y. W$ ~0 `
cprintf("The number of minutes since midnight is:\r\n"); / l8 S* @' r7 ]) D) \# b" D* Y
cprintf("The number of hours since midnight is:\r\n");
) m9 i7 Y& D+ U7 Kcprintf("\r\nPress any key to quit:"); # v' ?' Z9 p8 |
while(!kbhit()) ; F  Y" q5 m- E  \
{ & V) Y5 ]# v" }0 W/ E) i9 a0 d
bios_time = biostime(0, 0L); </FONT></P>* D- u/ N% {0 [
<P><FONT color=#0000ff>gotoxy(50, 1);
9 b3 _3 t( q: D% S7 l" ]( hcprintf("%lu", bios_time); </FONT></P>
+ t$ M7 @! a9 x<P><FONT color=#0000ff>gotoxy(50, 2);
: b% E7 F' m3 y' ]0 scprintf("%.4f", bios_time / CLK_TCK); </FONT></P>0 ~* ?& _. w- `, D& S6 B# {. y
<P><FONT color=#0000ff>gotoxy(50, 3); 3 l  m: q7 g9 r0 d3 G
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>6 g: G4 L. ^( J: B. k
<P><FONT color=#0000ff>gotoxy(50, 4); 9 ?% p/ T# e$ Y8 Q
cprintf("%.4f", bios_time / CLK_TCK / 3600); , f; N* `# r6 Z( r' h9 n
}
" G9 K& Q% p( M" Z) K5 e1 @return 0;
! c2 n. e9 x$ O' \}
1 Z( j8 |) |! ]9 a) T</FONT>
9 I! C; K# V1 _; O1 q" ~; U2 P) I* S9 B
</P>
! Z3 ^2 }* F  W<P><FONT color=#ff0000>函数名: brk </FONT>( k2 w$ h$ Q- U9 X
功 能: 改变数据段空间分配 4 A4 }# Z. D& w5 g5 X
用 法: int brk(void *endds);
7 }; ^$ M$ G: \: t2 m程序例: </P>4 @& n( C9 p; I# ~5 P( v
<P><FONT color=#0000ff>#include <STDIO.H>3 c# q/ N4 `+ s) n3 D( a/ Y
#include <ALLOC.H></FONT></P>
, z9 O- l1 p8 Y" M3 L+ l<P><FONT color=#0000ff>int main(void) % `6 J9 P7 p/ k. _- i) b9 Z8 \
{
: r+ Z2 i; G  |4 f* c- @char *ptr; </FONT></P>
% M  u) A7 m1 h" r8 e$ I<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); " W- D% k. u3 b* Q. p# Q5 b
ptr = malloc(1); + R# ?1 m# y) B2 X9 b
printf("Before brk() call: %lu bytes free\n", coreleft()); 6 y, ^0 O- `( f4 T9 L$ @
brk(ptr+1000); * S# Q9 y! C9 B' R6 d
printf(" After brk() call: %lu bytes free\n", coreleft()); + R% h! S# U4 k
return 0;
4 ]/ t) r# E. r3 k9 Q}
; r' J, E3 C* P" e9 W# h7 j2 l- v4 N- v- x, }% N
</FONT>
7 n$ ^- W* a- g& o  b& m+ A  M</P>
" U) p, v  W+ I<P><FONT color=#ff0000>函数名: bsearch </FONT>
* O5 Y* Q$ ~# H+ `( J5 R功 能: 二分法搜索
) z  }' i) |/ @* [1 H用 法: void *bsearch(const void *key, const void *base, size_t *nelem, 3 l) g% p& l1 |& q: S$ S4 v2 Y
size_t width, int(*fcmp)(const void *, const *)); # i- K; s3 ~+ m1 k$ \
程序例: </P>
2 v2 C* ~; @! {$ m<P><FONT color=#0000ff>#include <STDLIB.H>4 M+ k7 c) S% Z( E
#include <STDIO.H></FONT></P># y4 ?% {' Z! f7 E
<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>
; m* s# a2 l) K: e, k* ]! j4 O! P<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
5 H# r8 @1 K2 |/ K: w6 R3 @. X<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) * q: H- Z4 x- W1 T' @2 X8 O% q  j
{ / l  G# H3 l& b' C6 d& W
return(*p1 - *p2);
& N2 V+ o7 q+ S" a2 |+ Q} </FONT></P>
1 s+ D7 m* F) ^- i<P><FONT color=#0000ff>int lookup(int key)
9 G8 v2 ?8 X0 |# |+ Y: g$ w{
; P) l3 l: T9 }8 B* p' g9 U3 G6 }. tint *itemptr; </FONT></P>: P& ]( g1 t( P. ~' l+ u$ e  a
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) % Z! Y9 E' M+ F0 V. {2 Z
is needed to avoid a type mismatch error at
2 h; K0 [/ V+ ecompile time */
: l' m4 e9 ~% hitemptr = bsearch (&amp;key, numarray, NELEMS(numarray), " Q/ {, f$ Q( y
sizeof(int), (int(*)(const void *,const void *))numeric); ! r  t, J  U+ U! D4 d0 T9 a+ ~
return (itemptr != NULL);   Z7 b- g& ~& g+ @
} </FONT></P>
5 X/ Q# y% h; W2 q- V4 h<P><FONT color=#0000ff>int main(void) : i7 A6 B' M) ]/ c. d, O8 i
{
7 f" h( f( C+ Q0 o+ dif (lookup(512)) + I2 N4 W: |  E5 v  x0 b* b5 U9 R
printf("512 is in the table.\n");
8 q3 S3 |" ^( L" Z9 Belse ; i' i% e1 L5 z7 E' R. o9 B+ c
printf("512 isn't in the table.\n"); </FONT></P>  i- M$ V% w" N0 z. N. j; O. V
<P><FONT color=#0000ff>return 0;
& l' c2 Q+ B( H} </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-10-23 09:00 , Processed in 2.035260 second(s), 51 queries .

回顶部