QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1701|回复: 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>* c3 N+ G; }' P, v( H) |$ H5 K
<><FONT color=#ff0000>函数名: bar </FONT>
5 c+ ?9 v" E) \' b功 能: 画一个二维条形图
' C+ b, o! M' P6 a用 法: void far bar(int left, int top, int right, int bottom); ( i) ~1 P* t* F+ J- Y- J6 C
程序例: </P>+ D5 _0 o2 v2 v6 [% w4 x& f0 V
<><FONT color=#0000ff>#include <GRAPHICS.H>
6 _6 O: c' A! R; h3 F  l- b#include <STDLIB.H>5 B4 v* e6 @0 {! F9 y4 v# Y
#include <STDIO.H>
/ l) h  f) h, N( @( c+ _8 }#include <CONIO.H></FONT></P># L  [( b* p/ U7 c3 Z8 A$ e
<><FONT color=#0000ff>int main(void)
$ E" Z( H. ^( |, i: ?{ 5 {& f: q# A! m2 z% K# h1 X  T
/* request auto detection */
1 h. \; V- A) Y$ L+ pint gdriver = DETECT, gmode, errorcode;
: J, C- E8 b" _# f: ?6 R4 yint midx, midy, i; </FONT></P>
/ A, L; H, |9 F<><FONT color=#0000ff>/* initialize graphics and local variables */
2 g& C6 J' o+ G1 ^initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( Y+ ^6 @2 _" B- a- C$ E<><FONT color=#0000ff>/* read result of initialization */
1 P+ T. @* n8 l5 i# C8 e6 merrorcode = graphresult();
0 n7 t$ q- U# }- w6 ]' Eif (errorcode != grOk) /* an error occurred */ 4 g1 L& i* P% J6 A1 E
{ ! y' V  X4 x5 F5 Y5 |  V# X3 O
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ c) C/ v/ ]) rprintf("ress any key to halt:");
' q% T: Z( `# m) S, |$ K  ^getch();
  H- ^+ i% |# Nexit(1); /* terminate with an error code */
3 E' v$ f5 t8 F5 g% z} </FONT></P>, T$ X5 k: B, k# Z: u
<><FONT color=#0000ff>midx = getmaxx() / 2;
- \9 O2 R9 ^. K" B) A$ umidy = getmaxy() / 2; </FONT></P>& Y; Z1 p$ W& @, j5 ^2 {
<><FONT color=#0000ff>/* loop through the fill patterns */
/ b# l# e2 ^) Yfor (i=SOLID_FILL; i<USER_FILL; <br i++)> { # ?# h& n5 y  t6 e
/* set the fill style */
+ U& a( u  r% R$ R! S3 q9 Rsetfillstyle(i, getmaxcolor()); </FONT></P>
% s/ v5 E7 W* i+ O0 U<><FONT color=#0000ff>/* draw the bar */ 3 O, z: }5 n) |$ p
bar(midx-50, midy-50, midx+50, 2 p, U! D; {  ^( Q
midy+50); </FONT></P>- t: S! P3 v5 G) X4 q  ]2 A. u
<><FONT color=#0000ff>getch(); $ X: [9 a( b: c" y: w. S4 X
} </FONT></P>) B5 [& t" r# L0 ~3 _% ]. L9 z
<><FONT color=#0000ff>/* clean up */
* Z" H  x; q* d- _' gclosegraph();
( r1 ]7 [7 R3 _4 Y. }4 O. areturn 0;
7 Y# B# V# k, k( V: _: ^} </FONT>9 u4 E' w9 @  `  k( {
& Q- p( O$ M' \5 O) I
  L  u  y3 X8 r% ?
</P>
% e, B6 e0 A5 K9 P# L% j# S<><FONT color=#ff0000>函数名: bar3d </FONT>
$ C$ R3 E. Y, [+ c# V2 L  `! a功 能: 画一个三维条形图 ' c2 L# H5 P. x6 [7 {
用 法: void far bar3d(int left, int top, int right, int bottom,
1 [. l0 i0 Y6 L8 A1 y1 Jint depth, int topflag);
" w+ I! V7 u3 A) ~8 I, Y程序例: </P>
6 K# D6 ^% ], W, a* l<><FONT color=#0000ff>#include <GRAPHICS.H>& u, X5 a" {  p
#include <STDLIB.H>
: g) d  Z% t7 D+ p% c+ g#include <STDIO.H>" p7 Q4 F, u  f
#include <CONIO.H></FONT></P>" D# p1 \# A  e$ \* O
<><FONT color=#0000ff>int main(void)
4 H& p" c3 L! k. x{
5 j5 K4 D: C) @0 h- E7 k/* request auto detection */ ; B9 I: s$ w8 k: T6 n1 ~+ _
int gdriver = DETECT, gmode, errorcode; ! ]( H4 m- F4 U3 W$ Q
int midx, midy, i; </FONT></P>
' Z4 U) `8 @& z2 T8 b6 ~<><FONT color=#0000ff>/* initialize graphics, local variables */ * m: h" B5 ]9 i) b2 c
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, k3 Z7 Z, V+ I! T. z6 N, N0 g
<><FONT color=#0000ff>/* read result of initialization */ 7 E5 B& ?5 g# ~2 Y: ?! v& ^
errorcode = graphresult();
* a. n* I: T( Q1 G# O% {; a5 nif (errorcode != grOk) /* an error occurred */
- N& A" J; _0 R' p{ 2 P) p7 [4 U5 B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- C8 K3 L/ l$ ^% k- j, ~printf("ress any key to halt:");
& u5 E5 _" _" h7 S7 B  |# Jgetch(); . q8 F3 b! B* z9 t5 _: L' ?
exit(1); /* terminate with error code */ ( |) t5 w# @! H
} </FONT></P>
6 P: v" s6 n3 r4 X<><FONT color=#0000ff>midx = getmaxx() / 2;
" V1 ~# Z9 \7 M  h) umidy = getmaxy() / 2; </FONT></P>+ p+ d* k2 ?2 K
<><FONT color=#0000ff>/* loop through the fill patterns */ 6 P8 K4 V( }2 `/ T
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
! C% Z5 v6 M% L$ }2 k/* set the fill style */ / F1 K5 i/ b1 s- |
setfillstyle(i, getmaxcolor()); </FONT></P>! J% _) d4 a: O' r: [3 v
<><FONT color=#0000ff>/* draw the 3-d bar */
3 k' s. K8 i8 Vbar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>2 u. p% q9 o5 t/ {
<><FONT color=#0000ff>getch();
4 f- g5 b5 t* M9 b( w. j) |} </FONT></P>* n: U3 d. D% `
<><FONT color=#0000ff>/* clean up */ & A& [' w9 u+ H3 t" U$ U5 Y( Q
closegraph(); * }8 h0 s1 T* _9 F1 h7 j/ d) {
return 0; # w9 ?3 y0 S2 Y- y$ z: h: n
}   J" X4 p* `- b+ c
</FONT>. J* |2 }" N9 V$ W  Z, n! P

5 z0 V% f: F  f; q9 a7 c/ i</P>3 g5 I$ l% N. c' E
<><FONT color=#ff0000>函数名: bdos </FONT>1 G5 z5 i6 L1 z+ n- d
功 能: DOS系统调用
5 |% N7 r5 D4 O6 ]0 {/ B. h$ C' s用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
' b# _5 k' w6 t( E* n  }' F程序例: </P>2 y) x. g. p- M* F2 {# a9 H( ~, w
<><FONT color=#0000ff>#include <STDIO.H>9 [  j; X# j& m& G* u
#include <DOS.H></FONT></P>
7 D8 l# Q* c* h<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ 7 I( J4 B4 g  H0 W- _+ O
char current_drive(void) 7 X3 C  v9 y7 I+ ^. ]. V
{ 0 ]# T, R, ]: q6 h6 [# O) e
char curdrive; </FONT></P>8 i/ O2 Z( @* M
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ . h8 P. G7 R/ S
curdrive = bdos(0x19, 0, 0);
2 A3 N! _% m! d( _! ^  k- Lreturn('A' + curdrive);
5 Y! \; F% C8 J* r7 R: `) I} </FONT></P>
5 w" U0 o$ b' R, `' h) k: n8 T<><FONT color=#0000ff>int main(void)
- @& t) l9 h9 V8 x7 N{
! V; q1 e! M$ b# Qprintf("The current drive is %c:\n", current_drive()); / _8 F9 H! f4 _9 y6 K) |( z
return 0; 0 z4 b! H  N7 N, N- H( v
}
5 w* J& F0 q' M, D# g  X, A1 D- ^& R3 \' C: ?
</FONT>; U' G% z: W9 A3 |7 s+ k
</P>
  G1 G  D1 Q( h* ~% i6 g( A<><FONT color=#ff0000>函数名: bdosptr </FONT>
9 o6 {9 ]9 U* J5 e; L# V% w+ ?% j功 能: DOS系统调用
$ z- L5 _7 _$ `+ \用 法: int bdosptr(int dosfun, void *argument, unsigned dosal);
* h* o( v$ J5 I; \' ~5 b# W7 o8 _程序例: </P>
& W$ a( S! S' A7 N; h& P  Z) W+ N<><FONT color=#0000ff>#include <STRING.H>( A. O* S- I) o& {5 p
#include <STDIO.H>9 @9 Z' M$ D2 m5 `3 V; [1 I3 D
#include <DIR.H>
$ t+ l# d) U* ~#include <DOS.H>
: a' ?/ z$ v# d$ {: V% x#include <ERRNO.H>0 z) I. x1 s" K( d/ ~9 U7 \
#include <STDLIB.H></FONT></P>) J+ s6 ?4 V0 B
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
. ^7 L/ Q0 z5 R  Y( F<P><FONT color=#0000ff>int main(void)   z) H0 R% C# n+ O; i1 h
{
. T! A9 J# \+ T6 j7 Wchar buffer[BUFLEN];
% [5 Y2 t. S  ~: Uint test; </FONT></P>5 I! u& {; q( g& E8 b5 P) m: ^0 `
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
  B, h+ _# `4 n' m0 M5 U4 Bgets(buffer); </FONT></P>
1 G* }) ?1 x3 D# a( A<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0);
0 b. u4 r& {' c& ^9 J4 Bif(test) / I  {: l0 g- T! c7 w2 P7 i7 H' M
{ 9 M% ]. y- N. z; K
printf("DOS error message: %d\n", errno);
$ B3 \3 \- I! D4 V' n/* See errno.h for error listings */ " Y8 I- w! c% H& k$ z
exit (1);   V* |' U8 w2 `. X& ^
} </FONT></P>
* Z+ Z5 }: M- D" W0 b7 x<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
! L2 k5 M& Y7 z  U6 `& E2 Hprintf("The current directory is: %s\n", buffer); </FONT></P>' e/ h6 R0 j8 C3 K
<P><FONT color=#0000ff>return 0;
& h, C7 p7 n4 M- {}
# }4 z1 C" s+ X; L( |7 Q2 T</FONT>
: Q* ^9 X7 G  G  E* s% i) `+ Z& m
+ K5 W( P. W' Z+ ~; S</P>, e" ^# ~& F# N
<P><FONT color=#ff0000>函数名: bioscom </FONT>
- b5 H+ w- @3 n. W" e+ M9 @功 能: 串行I/O通信
$ [8 p8 _' }$ X6 d  T4 `用 法: int bioscom(int cmd, char abyte, int port);
$ B( Z& z: [/ x5 D& x5 X程序例: </P>
, C  p& L* K! f3 R5 i4 T# m<P><FONT color=#0000ff>#include <BIOS.H>3 T2 T/ x. K  v1 `( y
#include <CONIO.H></FONT></P>
/ R: k8 ~' X- f0 Y<P><FONT color=#0000ff>#define COM1 0
5 V' V- ?3 `3 B#define DATA_READY 0x100 % `3 @( N+ V# ~8 p, A6 V
#define TRUE 1
1 Q( |5 K" a$ O7 Q* Z( G4 I#define FALSE 0 </FONT></P>
# R9 C2 q! ]; b/ e" k/ w* E$ v8 V<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
# M7 m, h* G2 e<P><FONT color=#0000ff>int main(void)
" y( Q$ u+ Z3 h/ e) u* O{
/ r! W& Y; W' {! uint in, out, status, DONE = FALSE; </FONT></P>& s; O6 ^! w, ?7 L
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
& S+ D: M6 c2 Zcprintf("... BIOSCOM [ESC] to exit ...\n"); / t4 @! `# }: s6 V5 o3 }
while (!DONE)
( O( I; s: _" X' N{
5 l: T* y) M; t! g6 \8 K% J! i8 [status = bioscom(3, 0, COM1); 7 _+ h* m: V9 g+ B3 J
if (status &amp; DATA_READY) 1 s! t1 |! j" o- U
if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0) 4 D5 h$ ~1 e- M, Y4 c9 V
putch(out); - J, C1 O- U5 ^5 T
if (kbhit())
' |, F4 i1 Y* A: e; F5 V! z8 A{ # a+ j1 Y  O8 u! L( w
if ((in = getch()) == '\x1B') 4 s: V* x. P! b
DONE = TRUE;
  v8 O8 y2 g- S9 `: ^bioscom(1, in, COM1); + ?4 O6 f3 e2 \, Q. X7 N
}
6 W1 F1 ~& V- B6 j} 2 Z1 }6 r$ U) `6 v. C7 z
return 0; 4 i- E  D2 P# B) l% a( ]3 t
} </FONT>
/ A* Q9 H8 h& |- H% a  V7 y+ X7 j

# m- m; Y( \0 p$ y) B</P>
/ P; ^/ A( h; x<P><FONT color=#ff0000>函数名: biosdisk </FONT>
: O+ {' K* u+ S* K# k' A& a/ J功 能: 软硬盘I/O . Q9 |4 `* Z; o( m+ _1 V) @
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector - O9 ?' s" i. J- X
int nsects, void *buffer);
: h  i2 J* `+ b  v5 K3 t# q" T程序例: </P>
6 u: `) t7 [: s, u; n<P><FONT color=#0000ff>#include <BIOS.H>
! D4 Q( d; x4 x' q#include <STDIO.H></FONT></P>
5 Q  y0 w- y- k% P6 S<P><FONT color=#0000ff>int main(void)
+ N* l" o( F5 U8 o4 B1 f{
- S5 N8 k9 z- Oint result; & G; N; B+ T; X5 Q, a
char buffer[512]; </FONT></P>
- S# a. b+ u" ?3 n, s* A5 P* {<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
" r% n: l3 Q  @$ J' I, H  c& xresult = biosdisk(4,0,0,0,0,1,buffer);
6 A; t$ m' F& x7 v) X. l, B3 qresult &amp;= 0x02; 2 k, H* o: f  R2 u# c" y: ?( {. D5 F  j+ O
(result) ? (printf("Drive A: Ready\n")) : - h$ q. G% R* z' z
(printf("Drive A: Not Ready\n")); </FONT></P>
8 I% S$ l3 N& }; L6 @: H, E$ F/ \<P><FONT color=#0000ff>return 0;
0 O5 X) i' Y8 Q  }} ; r! O0 D5 l2 I% V1 }4 Y$ |
</FONT>
& e( K  M% x1 A0 c
& @: B/ q( f0 J6 r4 O: k% J</P>
7 `. n1 S6 Q' ?2 h<P><FONT color=#ff0000>函数名: biosequip </FONT>/ ]( [7 K; j" \! q6 K- p
功 能: 检查设备 2 \/ }& L8 t/ f, {+ E' t
用 法: int biosequip(void);
. y! K5 ~6 B) Z! L# g3 D9 G4 T/ q; l! T程序例: </P>9 T0 z6 w1 D8 P8 E) W& s6 p7 M4 u
<P><FONT color=#0000ff>#include <BIOS.H>! E3 j# ?9 u1 ]1 M
#include <STDIO.H></FONT></P>
9 f! y/ ]7 _6 ^, c: p7 s<P><FONT color=#0000ff>int main(void)
2 {  K- q8 A+ O2 }0 }1 {{
# B; w' V! L* [; xint result;
  ~& u  T$ P( ~" q7 `' Ochar buffer[512]; </FONT></P>
" ?) L8 O, W* E, k<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); 8 ~6 k9 J8 u8 B2 E4 j
result = biosdisk(4,0,0,0,0,1,buffer); 7 P$ r1 t, V" `7 e! e; H
result &amp;= 0x02;
! |8 p8 `; _6 e8 ?, a(result) ? (printf("Drive A: Ready\n")) :
. ^& N' i; H* Z& s8 k! P(printf("Drive A: Not Ready\n")); </FONT></P># F5 A8 K9 G8 N- |% J/ F
<P><FONT color=#0000ff>return 0;
! m+ Y$ Q; N3 u0 z}
3 ~4 X6 [8 |+ s: r$ ^& C</FONT>
( s7 o% b! y! ~5 X- ]
' ~; j$ n; N0 m" i! ~% \. ^( \</P>
( p* w  T9 R/ r& K9 y( v; H<P><FONT color=#ff0000>函数名: bioskey </FONT>
( R: F, d$ G1 a功 能: 直接使用BIOS服务的键盘接口
7 a: q" p9 b8 v' I用 法: int bioskey(int cmd);
4 v" y) g' ]& w8 H1 r! a2 O6 \( \程序例: </P>) w; P! o' q/ w1 l3 p8 o7 X2 X
<P><FONT color=#0000ff>#include <STDIO.H>
% m0 e- {4 D- H0 f0 |" d#include <BIOS.H>
% z  `- S9 w# f* M8 a3 p' z#include <CTYPE.H></FONT></P>/ C4 L) T6 h2 [! O+ c& ]
<P><FONT color=#0000ff>#define RIGHT 0x01
3 P8 ?4 ]1 a$ @9 l9 g3 {# t. U. L#define LEFT 0x02 1 f2 z  J0 U/ ]! U
#define CTRL 0x04 : i! F8 a# e  r, T+ U6 \6 t: e
#define ALT 0x08 </FONT></P>  r! R2 @5 i8 h4 C$ n) m
<P><FONT color=#0000ff>int main(void)
: O( t+ v1 n) v" m{
4 ], z$ m5 @. s7 c& _) ]int key, modifiers; </FONT></P>  g$ l1 W) |! x9 Q- |7 a
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ 7 t2 u) L3 _9 B4 j; I
while (bioskey(1) == 0); </FONT></P>$ J- E, D6 V1 F: C4 r1 o# j" n. l1 j
<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ % P: }, x4 M1 s* q( q- Y: C& {
key = bioskey(0); </FONT></P>
( E0 `' ^, C5 L- L. E/ [<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 7 w- A) ?! |6 D) |) q8 _
modifiers = bioskey(2); : |& }6 S7 V7 g  }( b8 E( S
if (modifiers) - t* Y& O0 o8 c+ I% |2 q/ N! c0 i
{ ' C, l' Y  f& L' ~  h- B, }; m8 R
printf("[");
( T5 t8 |8 w* i8 j  Q% {" G; jif (modifiers &amp; RIGHT) printf("RIGHT");
; R6 x. x, {3 q6 y7 Iif (modifiers &amp; LEFT) printf("LEFT");
, W! _4 O5 U8 B, @if (modifiers &amp; CTRL) printf("CTRL");
' L2 A- h% T% f( D( Gif (modifiers &amp; ALT) printf("ALT"); . W1 S1 a7 r8 D& q) h8 i1 g# V
printf("]"); ) @/ Q( ?: ^" a9 B6 @) s( L, F
} 1 i& G8 Q, s1 r; e" X+ X  W
/* print out the character read */ 0 E" V  \$ g2 D! r' A+ ]$ n* A
if (isalnum(key &amp; 0xFF)) ; w1 e2 q: C- R2 J, x* X$ `
printf("'%c'\n", key);
7 v  j9 K* v, J: l& eelse $ O. n; s2 W- k. N
printf("%#02x\n", key);
2 x1 w* q6 u. D) K$ W* s! m8 \return 0;
# i) M* b4 v9 _5 c9 }. X} , Y( |9 a- _: H

5 G5 _2 Y- d; V: l) d</FONT></P>; {" R! `5 r' H6 @* `' T. I
<P><FONT color=#ff0000>函数名: biosmemory </FONT>
0 N' h7 [2 i7 U功 能: 返回存储块大小
/ u, O! p% o8 R1 l  y6 ^" s用 法:int biosmemory(void); $ m' e' v6 j6 m- y
程序例: </P>( p# _: c0 Z3 V3 i  l+ \4 r6 X
<P><FONT color=#0000ff>#include <STDIO.H>" D) g$ L; P  p6 f1 C& W8 J
#include <BIOS.H></FONT></P>
3 \( O4 O3 j, M<P><FONT color=#0000ff>int main(void) " S! g3 u+ p, d: h
{
' a8 K: A* N: X  ~( g4 Z$ \- eint memory_size; </FONT></P>. w* y- W& ]- m% g: z8 M
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
* T+ I/ O8 V, C4 @1 {- Z/ Oprintf("RAM size = %dK\n",memory_size);
, a" ]& L4 G# [! r; D3 yreturn 0; 8 R) ?( V4 P" M5 r! G% |
}
) \. a# p& G+ x</FONT>
% [% {. g' F6 l2 o# c
1 s) Z+ l& P4 D$ B- s</P>
# w; a! `' h' j1 A6 `+ j$ m. E6 T<P><FONT color=#ff0000>函数名: biosprint </FONT>: W, R, A% t. V9 S+ K
功 能: 直接使用BIOS服务的打印机I/O
7 G% ]: n) |/ J" V5 k( r6 l用 法: int biosprint(int cmd, int byte, int port);
* k; `, [! O% d# ?: B2 V程序例: </P>( N8 e0 l  M& B6 E/ ~
<P><FONT color=#0000ff>#include <STDIO.H>* v9 m; t: r$ t- M  j4 z( ]
#include <CONIO.H>0 S, G2 i! r2 x9 g. I1 t
#include <BIOS.H></FONT></P>
, D, `! t5 I" W<P><FONT color=#0000ff>int main(void)
. O4 S- r2 B& T3 v4 ]+ p- P: t{
9 L9 j- U, J2 b5 w- C. J5 i#define STATUS 2 /* printer status command */   u2 l/ G* V1 a
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>
4 g) L4 B$ Y6 C% g2 ^<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>
7 ?5 S4 y* O$ {  R1 b0 \/ F<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); & @; Y. q# D7 g4 F
getch(); $ z' g  z" ~$ a6 u" H
status = biosprint(STATUS, abyte, PORTNUM); 3 Q) B8 y$ `) m8 N* N5 d  H. j
if (status &amp; 0x01)
1 ~  r) f; \' a- kprintf("Device time out.\n");
( j2 G4 l/ U/ e$ C( {; w- ?1 }if (status &amp; 0x08)
/ v0 N) l7 z) ]/ ?, D% yprintf("I/O error.\n"); </FONT></P>4 {6 E* F5 A. p
<P><FONT color=#0000ff>if (status &amp; 0x10) 1 ?8 w( F, ]# H6 N  s
printf("Selected.\n"); : y; W4 g* O7 f' u
if (status &amp; 0x20)
% z( S, @& {" D0 H7 ^printf("Out of paper.\n"); </FONT></P>
# \$ j" \8 ^# u; k<P><FONT color=#0000ff>if (status &amp; 0x40)
  `* e+ s! ^) q- b7 s! V8 U- Lprintf("Acknowledge.\n"); 3 C" p* w. t& F+ m
if (status &amp; 0x80)
. B3 v- G- ~2 p! y, \printf("Not busy.\n"); </FONT></P>: Z* Y5 y& ~& m4 m
<P><FONT color=#0000ff>return 0;
! |5 o1 X! @4 P}
7 n3 k' Y/ J- d# n) C9 b</FONT>1 ^% Q  z5 |$ `- |8 D. Y9 t/ U

% v/ ?; T% V' P; i: }& X</P>( Q6 B' \, ^- c
<P><FONT color=#ff0000>函数名: biostime </FONT>7 A; `& q# `- B4 q7 A+ m& Q" B8 h- Y
功 能: 读取或设置BIOS时间
3 O+ H7 ]$ l6 s- F用 法: long biostime(int cmd, long newtime);
2 E- k8 H  J1 U+ j程序例: </P>
  [& R) m" ]9 d6 ^  T- ~6 ?* Q+ X<P><FONT color=#0000ff>#include <STDIO.H>
/ {( J+ x! A, \7 v5 o; S#include <BIOS.H>' J  c: |- a- `  ~
#include <TIME.H>( D7 |1 X& }; n/ r, b
#include <CONIO.H></FONT></P>( {( p3 J; `/ c
<P><FONT color=#0000ff>int main(void) # o& V$ K0 T: U9 ?5 V8 D
{ 4 k- g7 a2 N$ X2 a# R% f
long bios_time; </FONT></P>
6 n0 J$ J+ M' r" p, n<P><FONT color=#0000ff>clrscr();
3 c2 L, D, Z( S+ xcprintf("The number of clock ticks since midnight is:\r\n");
" M, Z6 e& l6 ]2 N4 q* J; Tcprintf("The number of seconds since midnight is:\r\n"); & X1 y$ X$ y% r0 s5 R8 k) x
cprintf("The number of minutes since midnight is:\r\n"); 8 F# X+ ~7 |3 h' a# D" x; ]0 P# c
cprintf("The number of hours since midnight is:\r\n");
. i$ C( h9 {& q1 Wcprintf("\r\nPress any key to quit:");
1 T( x2 h8 S; M& h& }* p4 O3 Qwhile(!kbhit()) 8 p; L3 b) t0 ^+ F! R4 ~% c
{ : F- h; N% `- b& r
bios_time = biostime(0, 0L); </FONT></P>
- P0 O$ ^$ A4 T9 y<P><FONT color=#0000ff>gotoxy(50, 1); + r, L( k) D7 d8 e5 m
cprintf("%lu", bios_time); </FONT></P>
6 F5 B8 \2 z( g/ q0 A<P><FONT color=#0000ff>gotoxy(50, 2); 2 Q& ]/ H5 N. ]- z9 S( F
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
/ _9 i$ |1 l+ d# c, j: d<P><FONT color=#0000ff>gotoxy(50, 3); # I0 U2 m- d6 w+ k
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>, B; c# ^! z' V4 |
<P><FONT color=#0000ff>gotoxy(50, 4); 0 F6 C& \! L8 K9 X" x
cprintf("%.4f", bios_time / CLK_TCK / 3600);   q0 d1 g" o2 O+ [7 o; W4 O/ d
}
( N. g% _( {  a3 t4 @1 Creturn 0;   f- _& M) h- M- C( _
} & @0 p& U9 N+ X$ Z) h
</FONT>/ Z8 h5 V6 p3 v; O  U9 ~
* x, `. B+ l- \$ o3 {$ R
</P>  m/ {9 p* M: R# [. y
<P><FONT color=#ff0000>函数名: brk </FONT>( m4 O, @% n2 \7 {
功 能: 改变数据段空间分配
6 f- d9 w7 y  _: C# w" [0 B用 法: int brk(void *endds); + E. r4 {1 L$ T$ H. z  j8 B& C
程序例: </P>
4 M* `) e- K& i5 M<P><FONT color=#0000ff>#include <STDIO.H>2 L7 I: K; B& r- r$ B# }! C
#include <ALLOC.H></FONT></P>
' I6 B1 _3 w2 T* s<P><FONT color=#0000ff>int main(void) 2 A0 D+ C9 P) `& G: x
{   L( l! S1 k6 s9 [
char *ptr; </FONT></P>/ l6 z0 U6 g5 p( K& F
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n"); + P  d& ^/ ?4 h5 Z1 D
ptr = malloc(1); 1 ]2 `, Y6 l  |2 g" g
printf("Before brk() call: %lu bytes free\n", coreleft());
$ N( T. ]- t  w" x- Ybrk(ptr+1000);
) {! O5 M4 O" }2 V: hprintf(" After brk() call: %lu bytes free\n", coreleft());
7 ?- b6 m- Y8 `6 Z2 Vreturn 0;
; v. d% S7 K  I3 i9 [} ) F6 B+ O/ x7 @5 K& ?( c

- A- l1 Q8 s9 e1 b" ^' L" q' P( R</FONT>7 O- y  [7 |* A7 M5 F& v( L
</P>, k( _5 I4 g. c! }, N2 H
<P><FONT color=#ff0000>函数名: bsearch </FONT># j) F8 t2 r, a: m9 f
功 能: 二分法搜索
( z' h' }; e+ B- s2 r3 @6 k用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
, `9 E# W* O# H1 {) fsize_t width, int(*fcmp)(const void *, const *));
  Z, Z( A! k: ?1 j# _程序例: </P>
" @- }) Y  a' v0 F& r1 |1 v2 y' p$ X<P><FONT color=#0000ff>#include <STDLIB.H>
, l5 M% v% U# B  D; V" F#include <STDIO.H></FONT></P>
) h: @2 c1 O7 @& V: [" `- N& n! A<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>' ]4 j/ ?% o% _' G; F
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>5 H( o$ {& W* {$ [. r/ ^
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
1 I, G& v5 v# C. f+ [9 G{ , n. L) ~4 n" D" Y6 D
return(*p1 - *p2);
" @' _+ t+ y* W2 g* q3 E+ X} </FONT></P>" B. H) A. v  L# o0 z
<P><FONT color=#0000ff>int lookup(int key) ; Q% g4 R7 {( ^- P
{ : T1 U1 {- r) f8 A& |
int *itemptr; </FONT></P>
* U2 j) F# e. U$ s' V# ~4 E<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) $ ^* s3 Z4 s) N2 R) X, U7 Q7 }
is needed to avoid a type mismatch error at ( m" C+ ]  n. j9 F
compile time */
8 F/ k" O: j2 z0 u* k$ q  A" w9 kitemptr = bsearch (&amp;key, numarray, NELEMS(numarray),
3 \% @# k8 m- E: z; t1 `* zsizeof(int), (int(*)(const void *,const void *))numeric); 1 L4 N9 j9 F5 T! ]( |$ q' Q
return (itemptr != NULL); % i5 H3 R! n( T+ ^7 |& Y$ }$ N# G
} </FONT></P>
% _& ~3 f0 f$ f6 W<P><FONT color=#0000ff>int main(void)
+ Y8 E, ?  H3 }* q( k- c+ `{ ' ^* _  P& W$ G% h8 ]
if (lookup(512)) - w7 z, U- ]! W* S4 U
printf("512 is in the table.\n");
+ G" b& j  L  \, {7 i2 Felse
8 b& m1 t3 d/ A* f  H+ Iprintf("512 isn't in the table.\n"); </FONT></P>
2 J: D: v' g7 X7 Q. U: w<P><FONT color=#0000ff>return 0;
- B/ h0 h- J9 t4 Y8 H6 w0 l} </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-20 06:14 , Processed in 0.292347 second(s), 52 queries .

回顶部