QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 1703|回复: 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>' ?- K- L' Q2 l
<><FONT color=#ff0000>函数名: bar </FONT>/ Y, n5 L% `- d5 M
功 能: 画一个二维条形图 % u" F; v6 y) ~' {
用 法: void far bar(int left, int top, int right, int bottom);
, c3 O$ Q5 s# L$ Q( |( c程序例: </P>
+ J$ {' M* E2 h$ w9 c<><FONT color=#0000ff>#include <GRAPHICS.H>
+ V* W" F4 l& U; s, I8 ?3 X& f#include <STDLIB.H>/ s8 ?, h- u4 F# `/ s0 q8 v- j
#include <STDIO.H>  M: Y3 @2 O# H; |% T" g0 Z! P
#include <CONIO.H></FONT></P>( C4 v& t# n0 n( J" V' [
<><FONT color=#0000ff>int main(void)
1 o* G$ a7 N; j6 n$ Z{ 6 d& L, B* @3 Z4 J
/* request auto detection */ . i& q/ o  D5 k0 w5 X7 I9 K9 f- L# x' o
int gdriver = DETECT, gmode, errorcode; 4 P  K/ |+ \. Y+ G" E
int midx, midy, i; </FONT></P>' M$ a# l/ P5 b$ `8 l# c/ G
<><FONT color=#0000ff>/* initialize graphics and local variables */
: e* v, a  o; L  Vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% G' f/ V  {  A. F  ~<><FONT color=#0000ff>/* read result of initialization */ , I. N6 ^+ @, u- O1 v7 z
errorcode = graphresult();
3 @( q2 K9 a; V9 y. s; Z: b$ Tif (errorcode != grOk) /* an error occurred */ 7 `5 T  v+ @$ W* K& \
{ ) Q% D# _& T2 ~
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 L! z8 T4 [$ Gprintf("ress any key to halt:");
: j3 ?% Y% F8 n0 Ogetch();
9 ?/ [7 ~2 O8 E) V/ d8 eexit(1); /* terminate with an error code */ % l0 i, A$ d# i. A8 V: `7 b
} </FONT></P>  Y. X+ L# n, v; B: c
<><FONT color=#0000ff>midx = getmaxx() / 2; 9 F& P9 C, `4 m( ?. ~# g
midy = getmaxy() / 2; </FONT></P>
% [; r2 o$ I1 V9 l5 F" w<><FONT color=#0000ff>/* loop through the fill patterns */ 9 t6 b+ n3 H; \
for (i=SOLID_FILL; i<USER_FILL; <br i++)> { 9 w3 L# c' Y$ u2 t
/* set the fill style */
# l$ a5 A# W5 ^4 x/ Osetfillstyle(i, getmaxcolor()); </FONT></P>
: q& z$ c5 ~' }0 j) R<><FONT color=#0000ff>/* draw the bar */
% _  E* [/ i/ I' F' j1 Y$ C; abar(midx-50, midy-50, midx+50,
- ^& P3 W$ y! x' y) u* fmidy+50); </FONT></P>' @, o- W9 h# Q$ g9 i  s+ Q
<><FONT color=#0000ff>getch();
1 `; R. a  o7 ^# A, s6 u5 O( R; @} </FONT></P>
. N: w0 h/ d5 X% J6 D6 G<><FONT color=#0000ff>/* clean up */
4 I; \1 w" n+ }: `" ~1 L' Gclosegraph();
5 d* i: N$ E% s5 }1 Y) p/ Wreturn 0; ; |6 Z9 q, t# c5 Q
} </FONT>5 [' }* E( F. w! P; ?
2 H3 I8 X1 f2 W9 ?* y$ k

# ~2 A/ k3 x+ e8 j6 ?</P>- X. e: ~* _& [9 _7 ?" T
<><FONT color=#ff0000>函数名: bar3d </FONT>
9 h  U' U' H8 D- m功 能: 画一个三维条形图 8 u4 U" o+ @0 D: |3 j2 x
用 法: void far bar3d(int left, int top, int right, int bottom,
* o! O7 `$ |9 |$ v, y* l, ^int depth, int topflag);
/ G1 M) W8 F. g# q程序例: </P>
% I6 @5 D+ o$ l; Z<><FONT color=#0000ff>#include <GRAPHICS.H>4 G* o2 I9 l- b" ]
#include <STDLIB.H>! F! r+ L- W, {+ _
#include <STDIO.H>
! H4 Q: o+ v1 {' P#include <CONIO.H></FONT></P>
  i4 V5 M% i' r<><FONT color=#0000ff>int main(void)
. ]4 n" `3 P8 M) P/ L  I# K5 y9 i{
" y6 }$ @+ K2 W0 T+ [( @) b9 a/* request auto detection */ 1 z1 D8 @3 y* M5 }
int gdriver = DETECT, gmode, errorcode; ) c( p* f- z. ?: a5 V. `
int midx, midy, i; </FONT></P>* x7 `9 }4 p2 U0 h( @5 o- \1 G
<><FONT color=#0000ff>/* initialize graphics, local variables */
+ w! z" _9 O2 i7 C5 e' k3 ?initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. G9 Q6 t3 X4 b3 y( \+ L
<><FONT color=#0000ff>/* read result of initialization */
+ g$ r8 g3 Q' p, ~4 |4 i: |, ferrorcode = graphresult(); : e1 W8 {" b( S! e
if (errorcode != grOk) /* an error occurred */ , i9 Y* O  f# m+ A' M- c- l
{ " a' p6 L' W% r$ V$ t# Q
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 Z- f. d1 R, {5 j$ U
printf("ress any key to halt:"); 5 u# G/ o3 X- t3 c
getch(); 0 {& {' T9 `% L/ O' P
exit(1); /* terminate with error code */
: k- t3 b+ C* M( F* x} </FONT></P>  B, Z  S  Q/ c
<><FONT color=#0000ff>midx = getmaxx() / 2;
& h6 j2 \8 D* x+ Hmidy = getmaxy() / 2; </FONT></P>
  s. i. G  N& P! `- n$ e; m<><FONT color=#0000ff>/* loop through the fill patterns */ 2 w! Y/ m* b. S7 @$ q6 N# ]
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { . i$ B$ J/ x. {, x. R5 S6 O/ Z( X
/* set the fill style */
/ B& m9 r$ ]+ s& ysetfillstyle(i, getmaxcolor()); </FONT></P>
1 p" x- T7 |/ Y<><FONT color=#0000ff>/* draw the 3-d bar */
2 h* U/ G' e) S- K2 abar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>- k- r" D8 ?, U5 K
<><FONT color=#0000ff>getch();
4 s6 A7 ^8 e" p} </FONT></P>4 C, V$ T9 N% w$ F6 u
<><FONT color=#0000ff>/* clean up */ , n* _. d! t0 Y4 j$ _5 ~9 t
closegraph(); 6 O) }; g! Y$ a/ C6 _9 b( l
return 0; ) L5 O0 z' L/ Y$ z2 m
} + h; p  ?, ]$ Q9 a; i+ _; D; T0 o' p  V
</FONT>
( F- a/ I2 N0 N/ P# {
4 B* Z1 n2 e( `3 W</P>$ E7 D: P% g& ~! i7 q
<><FONT color=#ff0000>函数名: bdos </FONT>2 \! Q+ C8 x, e' R+ l
功 能: DOS系统调用 + d8 n+ z7 B7 Q5 Q+ M
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
& s+ t/ _! l  ^程序例: </P>" A% k  _" y$ K
<><FONT color=#0000ff>#include <STDIO.H>
2 `1 z( j) G8 y6 [8 m#include <DOS.H></FONT></P>0 b; X# x1 j6 i. B7 ?! @
<><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */ 1 ?- c: d: ?0 u2 {* Z
char current_drive(void)   a0 f+ E) Z: Z% R* t
{ & a' b* u7 Q. u% y; f% L  n
char curdrive; </FONT></P>0 z; l& G: z! q# H. g
<><FONT color=#0000ff>/* Get current disk as 0, 1, ... */
+ d! s3 b+ |/ Bcurdrive = bdos(0x19, 0, 0);
# L% x) f  f0 D* V3 j. U+ nreturn('A' + curdrive);
0 C: \; T, X+ Y1 h3 p} </FONT></P>- t, m; u, Y' Q9 Y) H/ \
<><FONT color=#0000ff>int main(void)
5 e! p+ P8 \8 R; h$ \{
  L3 s' J6 y2 a+ }: nprintf("The current drive is %c:\n", current_drive());
) t9 [4 h( t4 V- S0 ^; |( l# sreturn 0;
% ^3 x% S5 }* e: s: X$ w* Z}
% w' b2 U* [5 w+ X0 B& t
+ C( q9 ]- J; m/ G3 @' |' R</FONT>
' P) l. k9 i  e9 C" ~</P>) y1 ~( J, t, T6 F: Q. j
<><FONT color=#ff0000>函数名: bdosptr </FONT>
: F; {8 q2 c$ I功 能: DOS系统调用 9 f2 q( h, Y' @# b& A0 Y
用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); . x1 Q/ z9 J5 Z' R2 C3 Q
程序例: </P>
3 I7 I$ ]* R# S4 I# B<><FONT color=#0000ff>#include <STRING.H>. ^# @8 ^: C/ n
#include <STDIO.H>1 t; L9 Q) ~9 E
#include <DIR.H>
( l2 w- e" k# `4 S: N# y#include <DOS.H>1 g8 Y& I# \/ S8 w& c
#include <ERRNO.H>) q& x, B$ j6 z
#include <STDLIB.H></FONT></P>
( t9 @6 m7 y, f: `. o% s1 ?<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
. `0 l7 ~- E6 k<P><FONT color=#0000ff>int main(void) 8 V' Y5 S! X! A; y: a
{ 6 N3 N8 R6 w$ U, R  V
char buffer[BUFLEN]; - k6 \. A: X6 i3 S. z
int test; </FONT></P>6 A3 p( V  u% `8 ~
<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n");
3 z3 v: b4 V9 p+ a, F- lgets(buffer); </FONT></P>2 d* T8 q  d3 L; u* H
<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); ) P% c* M! R& L* I+ p$ o
if(test)
: J  Q. m2 y. @; L+ n{ + b! \. F! q1 p  ]/ n
printf("DOS error message: %d\n", errno); , ?$ b! e2 M" t' j+ i
/* See errno.h for error listings */ " j$ h0 @, p. k7 M4 y% d
exit (1); ' f' {* r7 M; I0 V0 [
} </FONT></P>) u5 y4 C. P1 _! A% z
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
0 @7 Y. i+ p% J0 Wprintf("The current directory is: %s\n", buffer); </FONT></P>
% R+ N3 ^+ M# t1 G; h6 z<P><FONT color=#0000ff>return 0; ( ~) ^8 O' V0 Q- u( }# O& ~( B
} " E" j8 K7 Z+ ]( F2 Z! B* e; Q
</FONT>+ \8 L0 i; U6 U3 s* Y2 A
& O+ G. o# x- t; q
</P>* O7 l* x, i1 e4 E. w/ @
<P><FONT color=#ff0000>函数名: bioscom </FONT>/ U( J, F# r, h! K+ H! y% u
功 能: 串行I/O通信
# z5 G  f$ I9 R: k( |7 n7 U5 b用 法: int bioscom(int cmd, char abyte, int port);
: f) y( }( x8 L: z程序例: </P>8 |. R  X, `, D
<P><FONT color=#0000ff>#include <BIOS.H>) X, P' l$ q1 O+ O6 Y8 z
#include <CONIO.H></FONT></P>
7 ~0 g, i  P# B5 ^<P><FONT color=#0000ff>#define COM1 0 ' K, |* M2 U. y9 Z% t9 p
#define DATA_READY 0x100 + i" I$ o6 f% M. w6 p
#define TRUE 1 ) J' N( f3 ?) A4 U, S
#define FALSE 0 </FONT></P>5 B# G- o" Y5 }- ?% M& H" u0 J
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
- P; Y7 \* r0 I8 T, r! O1 P& r<P><FONT color=#0000ff>int main(void)
4 y9 K$ j: x. `$ b- p{
) f- }( S+ k: ?+ R) Lint in, out, status, DONE = FALSE; </FONT></P>
: O9 H2 C& Y: }9 L<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
& X( n) C+ E" f# Z" Dcprintf("... BIOSCOM [ESC] to exit ...\n"); 5 }7 c* U0 y* E4 V% D' E
while (!DONE) : p4 a  ~( O# w4 Y) h
{ , e" ]+ |4 [" F0 S' c1 F7 u1 n: A
status = bioscom(3, 0, COM1);
, e5 l- [: }4 C' h0 y1 c. Wif (status &amp; DATA_READY) 0 L- r3 t3 }* T; W9 m
if ((out = bioscom(2, 0, COM1) &amp; 0x7F) != 0) : {( `& w" m0 X' ^
putch(out); - `& K; U& S7 ~* X; y
if (kbhit()) ! U( {3 V+ e: x( f8 ?- [% {# ^
{ 0 ^$ _* r7 ]: ]: ^
if ((in = getch()) == '\x1B')
; @8 @) l& [) |+ W4 C2 @) vDONE = TRUE;
% l) C: d  s- z  d# _. vbioscom(1, in, COM1);
6 D1 }6 T  `. ~8 A" [9 p}
# u% M3 W6 H# Z& ]} 4 S: N4 D( E' q1 Q% H' K$ P
return 0; 3 f0 ^9 J: ^; l  }, f
} </FONT>
0 z* o5 N. C; [3 V- ?% X' N
# O' K) z' D1 D  t! I9 z1 J3 A5 v; Z/ H4 l" Q! f
</P>
9 y; h' M9 {$ G" Y1 k2 a/ A<P><FONT color=#ff0000>函数名: biosdisk </FONT>
- H+ b5 x/ S4 \3 F) K1 M0 g功 能: 软硬盘I/O 3 ^  P+ H+ x/ K8 _( D
用 法: int biosdisk(int cmd, int drive, int head, int track, int sector ) g8 J5 m' B$ k4 [# m
int nsects, void *buffer);
: X5 ^# T. M% c程序例: </P>
( w( }/ q) h- j7 @6 V<P><FONT color=#0000ff>#include <BIOS.H>2 ^/ x9 f5 A2 P8 ~8 a! e' [
#include <STDIO.H></FONT></P>
$ B$ I2 [% G  }0 c! D8 k<P><FONT color=#0000ff>int main(void) ; j- F$ Z" y0 b* `
{
; S8 k. M7 A7 aint result;
' m9 }; n9 |) b$ s5 T# ?  S* jchar buffer[512]; </FONT></P>
* E# g" P+ i' @1 k<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n");
, T& M5 U; @  D; ]6 C0 P# ?! kresult = biosdisk(4,0,0,0,0,1,buffer);
: _4 J: N# u  F; [/ _result &amp;= 0x02;
) r: j8 B; r7 N) f" ](result) ? (printf("Drive A: Ready\n")) :
% u( J& D; @- J- U* @0 y(printf("Drive A: Not Ready\n")); </FONT></P>5 h( C* `7 I5 O& X
<P><FONT color=#0000ff>return 0;
! y7 j' X7 b+ W/ v}
& ~. r- T0 _6 Z! W/ g8 m! L! S$ d; r</FONT>% y, |2 {; k! I7 x
/ H: K, T* p3 s; E4 m
</P>
: ?' W1 M8 _: y2 G1 y; e4 F<P><FONT color=#ff0000>函数名: biosequip </FONT>
  j; V3 o( S, Z, n功 能: 检查设备 , ?2 u9 ]2 J$ b! Z/ p8 g
用 法: int biosequip(void);
/ }4 U$ N9 E8 u! J- j6 L程序例: </P>
. c8 G0 t1 k9 A8 u0 j6 o. b<P><FONT color=#0000ff>#include <BIOS.H>
3 `* k7 t/ w0 z4 i, M#include <STDIO.H></FONT></P>, G* B0 u1 @+ N
<P><FONT color=#0000ff>int main(void) 8 l" m$ S; N% J# ^2 k
{
7 Q$ H2 A2 h* x- z. F7 Jint result;   r8 ]3 ~' o9 X/ F
char buffer[512]; </FONT></P>
/ @- H; R" v- E1 ?& o9 W& z" \<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); / ]% V4 p% F0 \+ ^* p3 T
result = biosdisk(4,0,0,0,0,1,buffer);
; g4 _7 H7 {* xresult &amp;= 0x02;
% @. M9 v4 q2 G, w* K(result) ? (printf("Drive A: Ready\n")) :
! F3 V  h8 p! I" c  [(printf("Drive A: Not Ready\n")); </FONT></P>
! m7 T& u9 g3 q! n5 A0 Y' U, o: w<P><FONT color=#0000ff>return 0;
* V9 b2 m1 m6 a5 m. K+ ?}
1 a+ G, k% p+ R% z2 S' @, y</FONT>! b* V. b+ F! O3 K! g% Y- l9 z

) Y/ ^/ v" y+ P# A+ y$ H) l4 X</P>1 t8 o* u) P# G, T- o
<P><FONT color=#ff0000>函数名: bioskey </FONT>+ j. y' }+ w. J1 M# F$ v* B' k
功 能: 直接使用BIOS服务的键盘接口
" x" |* U  h$ F3 J用 法: int bioskey(int cmd);
# [' v$ r! U* U% g% a! D; }程序例: </P>
9 j8 j& B, q! s. d<P><FONT color=#0000ff>#include <STDIO.H>, R& ~! M' i( o* U* b# R
#include <BIOS.H>, ?) b( ?7 `7 p% t  E5 p7 U5 F/ u: {
#include <CTYPE.H></FONT></P>
4 H% D8 P( T' n' p- t<P><FONT color=#0000ff>#define RIGHT 0x01 4 t" @! B& i0 J9 p" [+ q, o
#define LEFT 0x02
1 {4 Q2 x* K7 z' o0 q+ z$ G#define CTRL 0x04
1 j9 T2 m) U+ u  O& z#define ALT 0x08 </FONT></P>  `  p: t( Y) D" v& n
<P><FONT color=#0000ff>int main(void) 7 c1 q% @; F5 k; |& ~2 Z& ~9 q
{
0 ?' Y5 H' O8 q+ l' nint key, modifiers; </FONT></P>5 z9 F2 v0 e3 c* z7 |
<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */ / t- ^' a- V0 G
while (bioskey(1) == 0); </FONT></P>
8 ?) m6 V6 h7 v4 ?6 @- M1 \2 J<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */
2 {" u+ [+ y5 g* ikey = bioskey(0); </FONT></P>- u% n; H) z0 y" A
<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */ 2 E* I. v. M6 l
modifiers = bioskey(2);
. ^3 p( ~  ?6 G$ {, j7 d: Aif (modifiers)
5 r4 y+ X' C, p4 [0 c3 e9 K{
0 p9 i1 B  I  x0 i4 Yprintf("[");
. X4 l4 t- f; B( I  M8 j! Y$ s1 n3 lif (modifiers &amp; RIGHT) printf("RIGHT");   b$ c; f8 u/ j
if (modifiers &amp; LEFT) printf("LEFT");
( F0 V: L. B: E. J! Mif (modifiers &amp; CTRL) printf("CTRL"); * `" C) Z2 {/ p( r; I  ~) E& q7 T
if (modifiers &amp; ALT) printf("ALT");
7 H" L/ C  B, X; cprintf("]");
, F5 ~* j( W. f( r7 d4 ^0 h}
3 _5 t. M; z  s: o/ q8 c/* print out the character read */ 5 p8 @5 b  n  `7 {
if (isalnum(key &amp; 0xFF)) 8 s3 T0 m6 Y+ d; C3 j" ^. }0 w; V
printf("'%c'\n", key); 0 K0 n8 u2 M- Y1 n/ P3 O
else
! Y" }( Q. f5 f; f1 L9 Z4 wprintf("%#02x\n", key); ; o# [  H# }4 {4 P* P
return 0;
4 n# B9 p" i  y& N. O) l; t}
: g8 J7 ?' j0 v
6 [/ B9 Z: w' _6 R( v- ]</FONT></P>
/ N0 V. ^# C) R" ~2 E" P; y<P><FONT color=#ff0000>函数名: biosmemory </FONT>
( f7 A, C5 q( E9 b功 能: 返回存储块大小
+ w  Q3 s- v& R& \# o用 法:int biosmemory(void); # R( o( `; U/ Z$ B' ~7 P! w+ j' _' }
程序例: </P>) B* d% Q4 F' c. j- W
<P><FONT color=#0000ff>#include <STDIO.H>5 D; M. J" `, b( R" o
#include <BIOS.H></FONT></P>
" D, g4 f  c+ u! j<P><FONT color=#0000ff>int main(void) ; u& t0 o- e. W" \( Y, U
{
  B, ~; h, z- U5 M$ e2 _int memory_size; </FONT></P>8 `/ {8 g; s8 |% s4 c
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */
. K3 ^4 F1 q8 n+ H& {* W# f6 Zprintf("RAM size = %dK\n",memory_size);
+ Q  S# ?. ^  {1 a, Lreturn 0;
% X6 F: y. J" m9 F. m# N} - [( F" u9 S8 o5 ?4 @
</FONT>
" D. E7 z5 w( Y8 t# t0 @6 A0 v9 C6 S4 K# c, {& n( L6 \
</P>
+ V( \9 B- @4 K& L" S; {<P><FONT color=#ff0000>函数名: biosprint </FONT>
! c5 u! ~, A7 [/ }2 A+ s( E功 能: 直接使用BIOS服务的打印机I/O ! y4 b! [* c2 t" Y. }3 w+ f" s
用 法: int biosprint(int cmd, int byte, int port); ' t# N' E4 b0 E, r# h
程序例: </P>  T  j9 g& V4 s' T5 M+ D
<P><FONT color=#0000ff>#include <STDIO.H>
- e4 G6 \0 p  ~+ z! T1 |9 a+ `7 H: [#include <CONIO.H>
! L0 o# G5 k( G#include <BIOS.H></FONT></P>* W& G1 \& p; ?% k
<P><FONT color=#0000ff>int main(void) " G8 R0 Y8 i( k; y
{ 3 Q1 M  l# h! B
#define STATUS 2 /* printer status command */
( H$ n# F# }/ I#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>5 P2 {1 N$ F$ \+ D7 c1 \. W
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P># w% f/ a4 P7 ~5 A' e
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n"); 3 G1 l- ?; F: c4 I7 {, ~
getch(); * x. C$ n% V2 U( d
status = biosprint(STATUS, abyte, PORTNUM);
# d# ?- {8 P0 S: X+ m& e8 bif (status &amp; 0x01) + Y' V% E9 a0 B; k' q' y/ `" }
printf("Device time out.\n"); 4 o2 y. B( H6 `& t/ c
if (status &amp; 0x08)
0 n6 N& D0 s  a. zprintf("I/O error.\n"); </FONT></P>
( Z8 m4 S5 v4 }) E2 D: W<P><FONT color=#0000ff>if (status &amp; 0x10)
# e3 y2 P+ e+ S% C2 Qprintf("Selected.\n");
2 \  m# l- F; Mif (status &amp; 0x20) 9 V5 h% B# L: L0 X+ Z( }5 s+ [
printf("Out of paper.\n"); </FONT></P>9 f: T% `7 n4 ^3 I) ^1 H
<P><FONT color=#0000ff>if (status &amp; 0x40) ; w; O2 }7 E9 C2 F2 S, n
printf("Acknowledge.\n");
2 @0 J; ?' d; ^. M# H6 K# B: ]if (status &amp; 0x80)
0 ]" T% n5 C3 S) w. o4 F" _$ T4 z0 nprintf("Not busy.\n"); </FONT></P>
8 G' A6 P1 I! V! V<P><FONT color=#0000ff>return 0; % V. |6 F; T' X
} ! Y( z# ]6 F% F- Z
</FONT>7 M" c$ _# S: q4 ]3 @

0 k* \$ z) c. M9 L8 q3 @2 O</P>
* K+ {2 g7 A5 G+ }& Q+ v<P><FONT color=#ff0000>函数名: biostime </FONT>
5 P8 e+ z: }, w, l0 S+ l* z7 ]6 H功 能: 读取或设置BIOS时间 3 o1 `6 G) Y% P% \- p: L
用 法: long biostime(int cmd, long newtime);
- X+ F! d' G2 M) m) V程序例: </P>
9 {/ P* N0 k9 N# Q8 S<P><FONT color=#0000ff>#include <STDIO.H>
) ~( L& H7 p1 k#include <BIOS.H>3 K( g1 U5 h9 E' H& m0 {$ M
#include <TIME.H>, d* z6 l" a) k& x0 y0 S
#include <CONIO.H></FONT></P>$ Y  r( d" W, z
<P><FONT color=#0000ff>int main(void) 1 L+ h, v' n6 |" ]5 ]- ~( H9 s
{ 9 r3 O% v& h* k$ ?
long bios_time; </FONT></P>' R5 i) C- L; J! }
<P><FONT color=#0000ff>clrscr(); : W4 \* A# @0 ^( X5 b% b$ C
cprintf("The number of clock ticks since midnight is:\r\n");
* l7 Z; f9 P3 L; k- V8 F0 kcprintf("The number of seconds since midnight is:\r\n"); 0 i! G9 A, T9 i/ n
cprintf("The number of minutes since midnight is:\r\n");
3 g8 e) `* C6 {  s8 ~0 Z. {cprintf("The number of hours since midnight is:\r\n");
- k5 D) a  {7 `1 Y, d3 ncprintf("\r\nPress any key to quit:");
: E' X1 e7 x5 h# a& p: r& Mwhile(!kbhit())
$ {& A, B. B6 U& ]$ v3 \{
6 G, w  e( S3 H# \7 F: n! ubios_time = biostime(0, 0L); </FONT></P>
. {# A. n) N9 |+ \/ E<P><FONT color=#0000ff>gotoxy(50, 1); 4 f, R" a. f! M/ R0 P% R! f# ?9 v
cprintf("%lu", bios_time); </FONT></P>5 ]# N  S6 V! l) M
<P><FONT color=#0000ff>gotoxy(50, 2);
" f7 W- r( z$ u  R) g6 J) ncprintf("%.4f", bios_time / CLK_TCK); </FONT></P>
2 u2 Z0 @% R; ]2 j0 d7 V<P><FONT color=#0000ff>gotoxy(50, 3);
  O: S: ?# k& ]7 P4 O) G/ B/ l. ]/ Ecprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
0 q1 n, y7 n) h+ X% ^<P><FONT color=#0000ff>gotoxy(50, 4);
' k! U5 I2 b% j3 C$ Kcprintf("%.4f", bios_time / CLK_TCK / 3600);
6 k" C1 Z' `# Q: C4 t( R7 ?}
* l2 `6 _% P' P5 {return 0; / H' g' U% E/ O
}
. ^9 G8 _) A. w4 c6 D4 l</FONT>
9 Z' w( ?" c# L
# }) Z# S4 n$ p/ d  @</P>
- d+ D, Z& o/ R0 Y<P><FONT color=#ff0000>函数名: brk </FONT>
! a; B0 Y! i7 Q1 U功 能: 改变数据段空间分配
* J7 q) B( Y- {( K+ q用 法: int brk(void *endds);
# B: u& Q7 o7 Y5 Y- _  ?程序例: </P>
, t8 ?1 O5 l* T8 x% a" z<P><FONT color=#0000ff>#include <STDIO.H>
( N  m( _( c. }8 d/ |) a4 [#include <ALLOC.H></FONT></P>- Q1 b* J9 i6 y$ p& b1 M& j
<P><FONT color=#0000ff>int main(void)
% J6 Q  R6 K; {" D7 e8 e- I, w& r{ 4 q+ s4 k3 O* y/ w
char *ptr; </FONT></P>
* O7 K! |8 W' m/ d<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
9 q- W5 y6 k$ K0 v$ Iptr = malloc(1);
, T8 e4 H/ L/ V+ ?% Gprintf("Before brk() call: %lu bytes free\n", coreleft()); . l% [9 B$ o, p" ?' v& z+ c
brk(ptr+1000);
! e: z- i" [& T  P! ~$ }printf(" After brk() call: %lu bytes free\n", coreleft());
* F5 q7 ]4 M' c! N6 f% ^8 Qreturn 0; + V4 d  B  h# q
} ( w3 `+ Q! J4 Q0 c2 x
$ G9 x, z% V! x$ ]& D6 z1 u
</FONT>
% s! K: Y' f# L2 `: o</P>3 r$ {, k; F1 c0 E0 U
<P><FONT color=#ff0000>函数名: bsearch </FONT>
; f" d5 Y' d& }9 L8 u) F, g# \功 能: 二分法搜索   R) Z; C1 Y3 a' x  `
用 法: void *bsearch(const void *key, const void *base, size_t *nelem,
# I* n2 q" D$ u( x. D: ksize_t width, int(*fcmp)(const void *, const *));
4 v- L; R/ [$ ^1 M' H6 @- b程序例: </P>
5 k. M$ {/ a& h<P><FONT color=#0000ff>#include <STDLIB.H>/ P! A" x( b3 a; w* `
#include <STDIO.H></FONT></P>
( ~7 n/ f  G6 t( c  s: E4 I<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>; h# r/ N# L& m6 c3 O4 f" z
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>
+ f, R0 N- ?' h3 f<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2) 2 ?/ a( ~# q% j/ j, q2 c
{
6 S& y5 V0 `8 s% Areturn(*p1 - *p2); ' |: X, G2 I6 c* x+ X
} </FONT></P>
2 j/ n  F0 Q3 t<P><FONT color=#0000ff>int lookup(int key)
* W' `5 `. F  j$ _5 r{
0 I+ W/ r: K6 @, m) Nint *itemptr; </FONT></P>1 a9 k' x3 F" N8 F! V' v7 U0 `5 W
<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*))
. i/ C# o9 ]2 b" f# t0 _is needed to avoid a type mismatch error at : Q$ O( Q$ L$ n- }
compile time */
# L! n4 F  I/ Oitemptr = bsearch (&amp;key, numarray, NELEMS(numarray), & i& B: [) f( M+ j  X* K) u
sizeof(int), (int(*)(const void *,const void *))numeric);
' ]. v" P' J, h% Q/ xreturn (itemptr != NULL); : K) ]& I# j1 P3 F
} </FONT></P>
! W* W- Y. M5 {* C* B. g- L/ M<P><FONT color=#0000ff>int main(void) + {3 Q* W, U! t$ g. y. Y% H
{
- N3 N2 a9 l$ ~& g" W4 q* [if (lookup(512)) 4 M; K6 l" b2 D- N$ S
printf("512 is in the table.\n");
! t# J6 k+ o/ `/ d5 Qelse
& O+ v- J  B' q/ Fprintf("512 isn't in the table.\n"); </FONT></P>, ?2 C& T* i2 r2 X3 \7 o
<P><FONT color=#0000ff>return 0; % _: g" |1 k) t- j) t$ f& I
} </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 11:50 , Processed in 0.504440 second(s), 52 queries .

回顶部