QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1705|回复: 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>
$ |2 c6 z) c% O<><FONT color=#ff0000>函数名: bar </FONT>
9 ~6 ]# \' X: i4 O/ p3 K7 c功 能: 画一个二维条形图
7 o- U2 E  [. s8 Q' O5 h7 S用 法: void far bar(int left, int top, int right, int bottom);
' G6 I3 H9 K- U7 @* x. j, ?0 |程序例: </P>
& t+ q( y9 e* w9 k( B8 L<><FONT color=#0000ff>#include <GRAPHICS.H>5 ^" d' j& T, g* D1 z! m
#include <STDLIB.H>
' |) T& d. T4 @. {4 g#include <STDIO.H>
$ L4 D; Z, p2 q: }6 b#include <CONIO.H></FONT></P>
" e+ {: v9 f: H7 y<><FONT color=#0000ff>int main(void)
$ _% a7 ]) {9 B8 D  E2 V{
! K1 l; ?$ L$ Z+ Q: D1 |/ C/* request auto detection */ ! a- }5 {" H0 X1 K  s3 T
int gdriver = DETECT, gmode, errorcode;
7 v7 D/ R+ {; z% A3 X. j1 A1 \int midx, midy, i; </FONT></P>' w) {( t5 f$ V$ c, A
<><FONT color=#0000ff>/* initialize graphics and local variables */
- M) T  w8 M4 v) o9 @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) [0 \3 m  o8 R0 Z<><FONT color=#0000ff>/* read result of initialization */
- v$ U! a/ u* c# Xerrorcode = graphresult(); 4 _- D$ L$ k5 H& O; X3 b) z
if (errorcode != grOk) /* an error occurred */ 5 a: X" m' ^' N
{ 0 {. Q( `8 ^& W3 ?9 G: L9 q
printf("Graphics error: %s\n", grapherrormsg(errorcode));
% G1 g2 d1 d5 l5 L& K  y, u( ^5 _printf("ress any key to halt:");
8 ^% E  |0 x# ^- {( I& _7 ~getch();
& O# n) u" s5 M# F& `exit(1); /* terminate with an error code */ + Y+ @! N/ P* u
} </FONT></P>
2 M4 j1 Z% A0 d( G2 i: v& B- z! P; x<><FONT color=#0000ff>midx = getmaxx() / 2; ( u) _8 W) F7 }& F3 Y
midy = getmaxy() / 2; </FONT></P>
9 U! a; S9 j  N9 T! ^  p6 L" @<><FONT color=#0000ff>/* loop through the fill patterns */ 3 X3 A4 m% s1 D- _5 q4 W
for (i=SOLID_FILL; i<USER_FILL; <br i++)> {
1 }# {, c! R  x" z+ V5 J9 D/* set the fill style */
. Y) j' b1 D: l2 q6 Osetfillstyle(i, getmaxcolor()); </FONT></P>
4 r$ A7 n6 m2 @5 w<><FONT color=#0000ff>/* draw the bar */ 3 h2 H: T. b1 ~4 T# A$ v% ^  G
bar(midx-50, midy-50, midx+50, 0 ]' z& e  A' U- H3 L) b
midy+50); </FONT></P>
# L7 I0 L- F6 T<><FONT color=#0000ff>getch();
" S1 Z  i( C3 m* {1 j} </FONT></P>
3 A7 v6 b+ ~* d$ B- G$ s<><FONT color=#0000ff>/* clean up */ 0 n  z; {2 c* [2 b- B
closegraph(); 2 Q. j" F3 T& F% N7 ~: x3 _8 r
return 0;
( D+ F  C1 h6 j; x9 b; n# L# }. _} </FONT>6 {$ f6 _$ h* t# K- g  P& t

, o, d" `. `8 B( \6 l
: `. N$ r# ]9 z" ^</P>4 y8 ^, x# C/ c" \
<><FONT color=#ff0000>函数名: bar3d </FONT>
3 y: N4 {; q4 N- K) W. N5 z功 能: 画一个三维条形图 " T7 `- T# A8 K9 h# b" l
用 法: void far bar3d(int left, int top, int right, int bottom,
( _9 Y" r- b8 k1 h! t) X* t. pint depth, int topflag); / K8 h# i; ~8 V, g, X
程序例: </P>
8 K# c4 t* N5 n9 V" U6 {0 c<><FONT color=#0000ff>#include <GRAPHICS.H>
$ c, x, l; J2 L. ~% \* v#include <STDLIB.H>+ h" j1 c% F6 S8 @7 `9 c
#include <STDIO.H>
8 @! l" s' l: @1 c& b) o#include <CONIO.H></FONT></P>
+ O$ Z/ E$ _2 V2 t<><FONT color=#0000ff>int main(void) : H% m$ j( x' ^6 t3 m$ p
{ 0 C0 o" s4 j. _4 }
/* request auto detection */
0 P% @- f& O) U$ b' jint gdriver = DETECT, gmode, errorcode; ; D& w* m/ ~& }0 h. s+ p0 e3 D: \
int midx, midy, i; </FONT></P>
6 ]: J8 a6 r7 q8 ~<><FONT color=#0000ff>/* initialize graphics, local variables */
4 Q- e8 @( H1 M0 c2 c' Finitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 K4 o+ h- E+ Z4 y7 X' q$ H8 ?* u
<><FONT color=#0000ff>/* read result of initialization */ ( c  H# K$ }' |' r
errorcode = graphresult();
4 e  t' C; i; x5 mif (errorcode != grOk) /* an error occurred */ % t. o) R3 S- e! x1 E1 u, |4 n3 A
{
4 H% i' ~9 H6 L1 [+ c7 F  x0 _# Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " v' r$ B/ W' b" d' X# x# T
printf("ress any key to halt:");
( V* n% H3 N4 z; y1 ?getch();
7 m& |$ ?6 B* r6 O% z, ~: `exit(1); /* terminate with error code */ 7 J9 j. j$ v: F) b7 |; T! @
} </FONT></P># T( t# V& U! X4 T; X# c
<><FONT color=#0000ff>midx = getmaxx() / 2; 8 V# \+ Z2 R2 N" x7 ~
midy = getmaxy() / 2; </FONT></P>
% x4 P* K+ e, v<><FONT color=#0000ff>/* loop through the fill patterns */
" \$ p( @7 C# Ofor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { : L8 l6 B6 i8 Y
/* set the fill style */
$ q4 b! h3 h- B* J9 tsetfillstyle(i, getmaxcolor()); </FONT></P>6 ~6 J- f: {, M' I0 Q! _
<><FONT color=#0000ff>/* draw the 3-d bar */ 4 p7 {# Z) I: J+ l/ e- t  K& Z8 q
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>  X- O* e4 M5 l' \8 U
<><FONT color=#0000ff>getch(); 5 q9 `' d5 @3 t# ?) k0 {/ o. ^
} </FONT></P>+ U. a3 S' W- q; N* |0 V
<><FONT color=#0000ff>/* clean up */ 2 T( n  F9 t7 Z
closegraph();
$ t1 ^0 ~4 y- ?( m2 [, _return 0; 2 g* n* V3 v5 o: _
}
) L+ N& [, t7 s# ^</FONT># t4 }8 V3 w" t& |5 L! h

. @; M) Q  u" H</P>
/ s9 `2 m- I5 [7 j<><FONT color=#ff0000>函数名: bdos </FONT>
) g0 c! H6 C' L- }: T1 L4 i1 O功 能: DOS系统调用
$ d' }2 d0 P' i用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 1 O9 r6 W) T- R5 V! N
程序例: </P>
8 }. i% \( Q) `<><FONT color=#0000ff>#include <STDIO.H>
0 v& ~$ w* n' i% H#include <DOS.H></FONT></P>
. X  m' J: ^1 L. T0 q! A7 @* p<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
, U8 s% _" H6 ~. C' {1 Lchar current_drive(void) 2 o( f) E* }' q. x7 _; y  R
{ " M; f: Y7 h* C) t6 Q7 G
char curdrive; </FONT></P>2 |! k! U$ [3 M8 O' R% j
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */   v5 P/ q' c# g7 W' A$ f
curdrive = bdos(0x19, 0, 0); , P3 X  F! Z& c  U' l
return('A' + curdrive);
% c/ ^5 h; G  c/ z} </FONT></P>, a2 R+ y: U/ v) J
<><FONT color=#0000ff>int main(void) 2 t6 X; b( f$ o9 |' W7 H9 T
{
& F; }7 N9 X* q- G; H- Pprintf("The current drive is %c:\n", current_drive());
  q: A0 C# r5 Qreturn 0;
# X0 C- k* B, P7 P  k5 Z* x6 x} 6 J% u9 K) w& r0 a$ j- X* q$ U

) D" e0 }/ u! v6 |9 D% \</FONT>
6 U4 Z2 I6 {# ^% _! s/ A</P>
9 h1 S* [* z  x; P; t& p- g<><FONT color=#ff0000>函数名: bdosptr </FONT>
9 t- F2 V( }  X功 能: DOS系统调用 + [3 ~1 O$ b9 [7 I; i/ K/ ]
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
! C4 K8 r# a3 z# R/ L9 A0 I& B程序例: </P>
5 b) O" {* k) M3 {0 O$ d# C" A+ \: e<><FONT color=#0000ff>#include <STRING.H>
6 G8 c( [" X  w* j" @#include <STDIO.H>
2 K& p7 n7 B( ?! y$ p! ~: {#include <DIR.H>
- ~6 d: c( f* X/ e+ _#include <DOS.H>% g6 H) ^; |, ~
#include <ERRNO.H>
) r2 ]; b- Y  X& g#include <STDLIB.H></FONT></P>
6 S6 f( y0 ]0 @4 d/ f8 M<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
- c2 x! |# i9 e2 x7 b/ a. A# L- ~3 G<P><FONT color=#0000ff>int main(void) * T. Y! d$ ^  E* N& J1 w
{ ( p" |# e1 r$ H3 W" Y
char buffer[BUFLEN]; 8 @. s9 E6 F2 O1 v( K) x
int test; </FONT></P>7 S( b) c) h& r/ \9 i: W6 X" q, p
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); # y( T% m. e: W7 B
gets(buffer); </FONT></P>' t2 W  D2 |2 u0 U* c5 S7 D! X
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); - o6 D( G' ?( f' ]  @+ C, @% G$ x
if(test)
+ O3 O8 M$ _% d9 b5 B6 z* S& x{ + l4 Y1 @5 ^  Y' z
printf("DOS error message: %d\n", errno);
* g* Z# _* m4 m6 L% y" R/* See errno.h for error listings */ $ `! n& F" [$ ?+ s6 t* p/ X
exit (1); ( i) n9 j, Y0 K: `( ?) A
} </FONT></P>
, F( i% O; v# U0 ~4 r' r: |<P><FONT color=#0000ff>getcwd(buffer, BUFLEN); & }) @  R& N- C
printf("The current directory is: %s\n", buffer); </FONT></P>
/ W4 f1 V$ S9 F! J9 _+ X4 U<P><FONT color=#0000ff>return 0; 3 _( I5 H5 ~( O- T3 U
}
' _& j0 ~. n5 |1 C% U* [8 h</FONT>' b! {$ P1 }# H

- @; |9 S- x, h/ f3 T* U</P>
6 M# W2 j9 y0 f5 V7 j9 U6 b7 [: I) Z<P><FONT color=#ff0000>函数名: bioscom </FONT>8 i" u# s1 `# ?2 H
功 能: 串行I/O通信
3 e1 D8 a" x+ v8 U; l$ ]) l! s用 法: int bioscom(int cmd, char abyte, int port);
; l  \* l* O- z! t# v2 Y! E程序例: </P>
! K* w- I0 S, V& Y. I<P><FONT color=#0000ff>#include <BIOS.H>/ t" q, N( C9 ]+ L5 Z
#include <CONIO.H></FONT></P>
% \8 V1 h/ O  D1 g<P><FONT color=#0000ff>#define COM1 0 ) @5 V" \! j9 F6 i0 Q& r
#define DATA_READY 0x100 . a& t9 l: u! X4 K3 [, V( V# @
#define TRUE 1 " A, R7 b4 ]0 H" G6 n9 s
#define FALSE 0 </FONT></P>
3 e. U, `2 r. w% i<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>% A+ _9 Y9 N/ A; |  f# ^
<P><FONT color=#0000ff>int main(void)
# x4 x/ Z& ~, w+ E4 e. R& l{
- L( A* g+ g7 H, q' dint in, out, status, DONE = FALSE; </FONT></P>
6 `. \# a. A8 V3 A: |* I<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
1 z2 P- L* Q) y1 l% n& ^cprintf("... BIOSCOM [ESC] to exit ...\n");
* ~3 D; Z% N3 r2 L) Lwhile (!DONE) $ |9 X! s5 m( d- i  d6 X7 K
{ 7 I3 b0 R9 T2 i. _" {" g
status = bioscom(3, 0, COM1); 5 f$ S0 R& ^' M; ^! E/ O
if (status &amp; DATA_READY)
) k/ _, F; G* r: N0 ~) Xif ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0)
% V( ^  j( y8 C  E/ u2 Q/ E) L. B2 sputch(out);
9 ^( |, U& e9 I2 Z+ yif (kbhit())
* m, d0 {! P% I! Q5 ^{
0 k6 [1 ?5 ~1 M4 S+ qif ((in = getch()) == '\x1B')
& t: Z; d: Z) n! y5 H9 ?8 rDONE = TRUE;
9 T- t$ z+ @8 G8 D1 Kbioscom(1, in, COM1); ! N/ _& `# v/ [
}
& c) I" B# m/ h% ~& X- W/ k1 R} 1 e6 {9 \! K' i$ I; r. @, i
return 0;
1 @$ X" o2 ^' y} </FONT>( a+ l7 \1 d4 V1 A& m5 `

8 C+ I+ h, e" k
1 W& s% b& A. Z</P>
2 @2 d6 y# B8 U3 ^9 A<P><FONT color=#ff0000>函数名: biosdisk </FONT>
8 t3 k, y: I9 R+ \: @功 能: 软硬盘I/O ( O* J; Y# ]0 m6 L# K: }
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 9 m" z* [$ p8 G3 H
int nsects, void *buffer); / K) v: q( S2 G, }) n) H
程序例: </P>
9 {4 P" Y) h! }6 E<P><FONT color=#0000ff>#include <BIOS.H>
8 m2 G& s  X7 U) x4 t1 K#include <STDIO.H></FONT></P>5 K3 z/ _6 u3 l# G( b& `' x
<P><FONT color=#0000ff>int main(void)
2 M& u4 H' G  N& c{ ' i8 a: y8 w4 n7 r
int result; 9 \% a+ m5 E, Q/ q
char buffer[512]; </FONT></P>( ^9 U/ Z; i( S* r$ ?$ G
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); - z4 v! G! @) N8 |4 }  z
result = biosdisk(4,0,0,0,0,1,buffer); / a% i) T3 f4 Y8 C
result &amp;= 0x02;
( r1 V& z: y; G- T. ](result) ? (printf("Drive A: Ready\n")) : * L! N/ n: A% p4 T
(printf("Drive A: Not Ready\n")); </FONT></P>' t1 e0 p; {6 F; l1 x
<P><FONT color=#0000ff>return 0; 0 T: r6 `, r; n- t% ^
}
* ]3 e5 L/ F. h& ]0 b</FONT>
3 @/ {% Q, T& M: {  ~* t* G) D; u$ E+ N+ j5 j0 i$ z
</P>0 W0 Y  J! i) b5 M8 t8 V+ @
<P><FONT color=#ff0000>函数名: biosequip </FONT>
1 S2 Q0 o1 I5 v6 F* i功 能: 检查设备
/ {5 \- `. O8 |$ w3 B用 法: int biosequip(void); 1 o4 d3 ~4 l% |  w9 d
程序例: </P>
3 u% e0 o; W2 `& g# u4 A/ D<P><FONT color=#0000ff>#include <BIOS.H>: C; g) P* c% [1 u" ?' Z: L+ P4 Z
#include <STDIO.H></FONT></P>+ {; }+ k! G9 H7 H( v
<P><FONT color=#0000ff>int main(void)
6 [8 o+ t8 H3 z$ m  G/ w{
8 V/ c4 S/ v6 d7 v2 c4 y$ V+ aint result;
3 X1 ]; o( ]. B3 z5 lchar buffer[512]; </FONT></P>
+ O- C9 u7 @- v* [. }4 P+ r2 A0 Y<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); $ T7 C3 `9 g- e
result = biosdisk(4,0,0,0,0,1,buffer);
6 U& ]$ c( n' V$ k* O& mresult &amp;= 0x02;
8 o1 a+ t7 ^4 s( q/ q& \5 |1 t; B3 F(result) ? (printf("Drive A: Ready\n")) :
: |, X! b; |) c2 E2 H0 q# _(printf("Drive A: Not Ready\n")); </FONT></P># r. Z# J: `* l  w4 Q
<P><FONT color=#0000ff>return 0;
6 m: L$ T% l5 ]5 ]( R. c. d' l$ `}
( E, P! e% z" T, d</FONT>
, h& j+ d2 n4 _" ?
+ [$ l! o% v' J4 m1 w</P>9 I* h5 [. {3 V; E- d- N
<P><FONT color=#ff0000>函数名: bioskey </FONT>
  [7 a/ e6 b1 E) |; m8 R功 能: 直接使用BIOS服务的键盘接口 / {; ]2 g8 j( @# F/ \
用 法: int bioskey(int cmd); 7 s, j6 h/ {$ i. X
程序例: </P>
9 C, f6 `' k- ]5 G5 h<P><FONT color=#0000ff>#include <STDIO.H>% m# e6 J1 {2 s& g6 g3 }; D, b
#include <BIOS.H>
% \/ @$ U2 `$ h) S3 {5 B* ^  G#include <CTYPE.H></FONT></P>
' h- h% J/ Q# |% Q9 c/ F7 a, ~<P><FONT color=#0000ff>#define RIGHT 0x01
0 U7 ^1 Q$ _. k, o" ~7 ^#define LEFT 0x02 0 ?- B$ H! k0 M$ S
#define CTRL 0x04 9 G/ g" f6 Q: C/ f
#define ALT 0x08 </FONT></P>1 O0 `+ M! I' \( Y9 k" C: g
<P><FONT color=#0000ff>int main(void)
, f/ I( {& u" \{
8 B$ N! A$ y0 L' b$ @. f$ sint key, modifiers; </FONT></P>
7 X% Q) R4 @! G+ @& Y) ~<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ " F9 ?6 c1 D! M% @
while (bioskey(1) == 0); </FONT></P>! ~% s8 u9 m4 ?# u
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ ' T0 T1 x- V  L0 R( w6 k$ r, L
key = bioskey(0); </FONT></P>5 t9 f# u8 \* `, V: m
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 3 @1 m! \# F* o6 }3 G: Z2 K
modifiers = bioskey(2); 9 L. a4 B6 U; H+ L. T% s% }# p
if (modifiers) / V- L; Y8 t9 o; d7 U" {
{ & E  {9 A1 @: B3 H, x6 h7 {
printf("["); 1 V) V/ \/ B2 e$ W
if (modifiers &amp; RIGHT) printf("RIGHT");
: S: _8 `- j, @, P9 k7 zif (modifiers &amp; LEFT) printf("LEFT"); # o( P: h' N6 e6 K0 F: y
if (modifiers &amp; CTRL) printf("CTRL"); . N" k% E( g5 K( i* V5 N5 v
if (modifiers &amp; ALT) printf("ALT");
% e- I% s( e( K0 ~printf("]");
0 P$ [8 u2 t& ~% j2 z+ V3 ^) {" I}
' }  |( l6 O9 y, N, Q, s9 ]/* print out the character read */
& q: J1 v7 |9 k, Y1 W% ~1 ?if (isalnum(key &amp; 0xFF))
: M. N6 o* v9 g6 o5 e8 qprintf("'%c'\n", key);
. g8 V! A; }" ]9 a  ]$ X8 [else
1 ^+ D, ~4 f4 e" w3 s+ D7 e" }printf("%#02x\n", key); 6 ?5 ^2 M: h- T5 I' w# x' T/ A0 _/ E
return 0; 0 c; `" k$ }3 X* n2 x$ L: U8 W. Y
}
; d4 o, t- O8 E+ g" o/ V% |
- |" |5 s& C$ o$ x$ Q</FONT></P>
' a, |: N9 n  s: v* P( q<P><FONT color=#ff0000>函数名: biosmemory </FONT>
: n5 O1 @- x4 z" g功 能: 返回存储块大小 # n, Q) B3 p! h3 P
用 法:int biosmemory(void); . n% r9 _' s. Q9 @
程序例: </P>
3 C" S: g) b( r* Q3 M) T- u<P><FONT color=#0000ff>#include <STDIO.H>; I/ h) O( G1 B; p
#include <BIOS.H></FONT></P>1 x) \* A* ?' ~+ |0 \
<P><FONT color=#0000ff>int main(void)
" |& w4 b) U8 U0 G% {+ {. Y0 O{
  `+ j4 s+ P$ ^5 S9 G9 M6 |: eint memory_size; </FONT></P>" f; W  M0 n1 r* m
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ % r' _" J" Q, B3 |9 T* q
printf("RAM size = %dK\n",memory_size); ( q; ]9 L! l  [1 Y3 D8 Q/ K# s, X
return 0; 5 r8 G+ C- X  Z( O3 [
}
0 y7 k/ m* s# Z, b</FONT>
7 l0 I) ]: e( C6 F+ P( i9 u$ f+ `2 K0 B, k3 q4 @* K* f
</P>' b$ q8 C+ }! Q# D( S
<P><FONT color=#ff0000>函数名: biosprint </FONT>$ \3 K+ ~! R% Z( W
功 能: 直接使用BIOS服务的打印机I/O 0 N+ \$ V% i$ n5 c8 x
用 法: int biosprint(int cmd, int byte, int port); 4 S$ n/ {' [7 o1 @
程序例: </P>
2 m4 _' m, c) F/ |! a) g2 K6 o$ B/ g<P><FONT color=#0000ff>#include <STDIO.H>
5 Y4 c+ j, L8 y2 I' a, J#include <CONIO.H>
2 x2 y; O: r0 y$ u; c7 Z8 Y1 j#include <BIOS.H></FONT></P>
: z# v2 e) e9 ^<P><FONT color=#0000ff>int main(void)
4 q) l) R, r6 ?/ }7 }) ~{ 2 D5 i/ l, T( l6 ^% H. q
#define STATUS 2 /* printer status command */ ' I: u. K( Z2 Q
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>! V% e! g/ h" M3 }% `
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>( k# R- ^0 b, {; j
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
+ x  r& _! ~* M3 |" K  g. _getch(); 6 @! `- @, g- U# p0 V1 i
status = biosprint(STATUS, abyte, PORTNUM); 9 S- H- F  x9 d: I8 `
if (status &amp; 0x01) # h& \  n4 c! ^$ v
printf("Device time out.\n");
6 m- p5 [; y/ i( L, Rif (status &amp; 0x08) % |& |' C5 I/ \
printf("I/O error.\n"); </FONT></P>1 R6 ?$ Q; R2 a. k# k$ f" M
<P><FONT color=#0000ff>if (status &amp; 0x10) + M8 Q& X2 L6 j$ A- m1 `" D- x  t
printf("Selected.\n"); & R- H- q; \/ J  R& `% @+ b6 X
if (status &amp; 0x20)
( B! C( z5 l& q9 S) S8 O& zprintf("Out of paper.\n"); </FONT></P>: u; O. _/ ~; T
<P><FONT color=#0000ff>if (status &amp; 0x40) : y" b( W* l2 A& @7 F: \2 ~
printf("Acknowledge.\n");
0 i7 {% S4 q+ ~( M! xif (status &amp; 0x80) " n5 C+ I  `+ C& \& g% x
printf("Not busy.\n"); </FONT></P>
+ d+ J% [! s: L" S) a) p<P><FONT color=#0000ff>return 0; - z* N- V( o- c
}
3 x" f( i/ c( e: O& f6 H; l</FONT># _: x2 A. e2 k; V

/ w3 f: r  I! ?</P>
' S  u8 u; Z& U; w- P7 V; M<P><FONT color=#ff0000>函数名: biostime </FONT>. l6 N, w) K3 c  A# f
功 能: 读取或设置BIOS时间
! e1 I3 j, a0 G" }; t& A/ W: S0 T用 法: long biostime(int cmd, long newtime);
8 j" _3 }, C% n3 G2 ]程序例: </P>
0 G, p7 X" _( y. W1 x, \<P><FONT color=#0000ff>#include <STDIO.H>
+ j* P/ l' R9 D8 h5 `* |#include <BIOS.H>; t$ J# f9 d! N# Z, R7 B& W# Q
#include <TIME.H>( P" n" w9 ]/ K
#include <CONIO.H></FONT></P>
9 C: H) C/ K  X; O' G<P><FONT color=#0000ff>int main(void) 7 @  `+ M. d+ k" ^
{ ) ]3 F3 `  N# m+ }7 X% G3 ~
long bios_time; </FONT></P>4 v! [* q% Y' K/ I% x1 W- Z
<P><FONT color=#0000ff>clrscr(); . G' t$ D/ |" v( @- g0 p
cprintf("The number of clock ticks since midnight is:\r\n");
6 `) u6 U; m7 D) R4 vcprintf("The number of seconds since midnight is:\r\n"); 1 Z8 c4 |8 p& ~2 E
cprintf("The number of minutes since midnight is:\r\n"); 1 e. Y! O& y) z% |6 X
cprintf("The number of hours since midnight is:\r\n"); : {9 k: h" U7 |
cprintf("\r\nPress any key to quit:"); & g! O8 N4 O3 B7 ^. h& ^4 S
while(!kbhit())
& Z, X0 K8 B% ?5 ?+ q/ |1 S{ & ?9 a  Z& y1 a1 y( l$ x
bios_time = biostime(0, 0L); </FONT></P>, k! g) _% Y. z$ b: }$ o9 E
<P><FONT color=#0000ff>gotoxy(50, 1); ! w2 o  s3 X9 P
cprintf("%lu", bios_time); </FONT></P>" v. v! |$ J6 y$ S
<P><FONT color=#0000ff>gotoxy(50, 2);
. X5 A9 g4 k) v- L2 qcprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
& |) u8 d) ]/ ?- v) B<P><FONT color=#0000ff>gotoxy(50, 3);
% A$ h( P: U( v9 X/ i$ ]" h) z# Jcprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>% }4 |/ K! O6 G/ k" z% E; {
<P><FONT color=#0000ff>gotoxy(50, 4);
) P* t& B9 p: g5 xcprintf("%.4f", bios_time / CLK_TCK / 3600);
8 Y: K: K: r& j' H& }! m- _} ' ]: M8 I8 J5 N. I0 g+ i3 p
return 0;
- O" Q' E" |  f8 m$ X0 t) H}
: }  H) L( v( P: Q  @</FONT>8 r# U+ z, v1 Z! G3 b

2 z4 @1 ^7 ]/ Z5 m</P>
( O* [  p4 N9 `# Q7 W# s' P) E, _<P><FONT color=#ff0000>函数名: brk </FONT>! q8 n$ t% k3 G9 }" m" @
功 能: 改变数据段空间分配 9 W  K* Q) T  @! W
用 法: int brk(void *endds); ! E( B! m7 r, I8 d' X8 ]5 O
程序例: </P>0 p3 E4 R* V9 i0 j% P! k# l1 W  |
<P><FONT color=#0000ff>#include <STDIO.H>
( z$ i1 i1 V6 O: z7 D& v1 Z" w#include <ALLOC.H></FONT></P>5 ~# o0 \4 \7 ?" w1 W% D- _
<P><FONT color=#0000ff>int main(void) 9 m, R* k5 d9 A6 {9 `( w
{ 2 F. i7 `3 Z( P0 G4 d" }# k
char *ptr; </FONT></P>
- h# e/ J- W- C* }<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
& O# S. Q% J0 |) Nptr = malloc(1); 3 Q6 a" d5 P/ W" N( f. ]
printf("Before brk() call: %lu bytes free\n", coreleft()); ' j0 {  d5 P& m0 C/ h' L) Q
brk(ptr+1000);
/ @% I0 E6 a; v3 E8 Cprintf(" After brk() call: %lu bytes free\n", coreleft()); 1 j9 D, e& ^$ Y( D
return 0; ) T3 E* E- ~, L4 b+ Q: m1 o& }/ O
}
; A$ M: [) t* g) Z. H5 t1 H  ~1 m. d; s1 u( m+ S
</FONT>+ K9 B( V" `) F9 D2 y
</P>
' K! f5 K6 x- o2 v<P><FONT color=#ff0000>函数名: bsearch </FONT>, ]: l$ Q" |# {8 U0 J1 ~  z
功 能: 二分法搜索
% i4 [0 i1 R/ X* L6 \; C用 法: void *bsearch(const void *key, const void *base, size_t *nelem, ) [* k/ Z/ f! L6 a1 ~/ ?) h; c
size_t width, int(*fcmp)(const void *, const *)); ' Y$ C- ~7 }! F9 [1 I% s5 o9 r( M
程序例: </P>
+ n, y% q% d! p5 p8 Y4 v<P><FONT color=#0000ff>#include <STDLIB.H>
& S* w6 q3 Q9 H+ H3 R#include <STDIO.H></FONT></P>
( Z. L/ O/ K, b<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>3 q- `9 b4 X( W4 j7 V( q7 q, O1 l
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>, u/ {, B' M8 w. E
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) + D/ g7 W6 f% _
{
) [8 ]$ ^; j& w1 u# l4 ereturn(*p1 - *p2);
7 J6 I- L9 B  P} </FONT></P>) H1 B& u' |/ l) ~
<P><FONT color=#0000ff>int lookup(int key) 6 ?) V! s5 P7 C) M+ P( f
{
# e! ?) }; ]: N4 }' uint *itemptr; </FONT></P>, Q$ v- G  r" G* J$ |2 i
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) 8 D+ s2 f. S2 v  u0 y8 u
is needed to avoid a type mismatch error at ! E# R4 v: M0 d$ g, o
compile time */ ; k1 \& m9 U; M7 }
itemptr = bsearch (&amp;key, numarray, NELEMS(numarray), 4 \8 p2 k& H1 B, h) N' }
sizeof(int), (int(*)(const void *,const void *))numeric); ; W6 v/ b! i& k2 ?
return (itemptr != NULL);
& G& Y9 ^# B) f} </FONT></P>9 H8 q) m4 l0 ?$ c* O: m
<P><FONT color=#0000ff>int main(void)
6 w0 A: \! }% U{ 6 t( {8 n8 `% }# s1 B
if (lookup(512))
8 |2 j9 ]3 o8 ]printf("512 is in the table.\n");
7 a$ ~9 O7 L' @2 y* i  P& Ielse
1 q; _, F7 O& b2 ~printf("512 isn't in the table.\n"); </FONT></P>7 \0 C- h& c3 b
<P><FONT color=#0000ff>return 0; , i8 d; w; V+ C/ n, J9 }
} </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-4-21 10:06 , Processed in 0.434575 second(s), 51 queries .

回顶部