- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(b开头)</FONT></B></FONT></P>5 Z3 B/ Y4 {* | C
< ><FONT color=#ff0000>函数名: bar </FONT>& c- E8 Y; p, v1 {- S
功 能: 画一个二维条形图 7 j v; [# @% }: X
用 法: void far bar(int left, int top, int right, int bottom); 4 R5 j9 C0 W3 u d/ T. o+ V
程序例: </P>% I+ I& _9 o: M- w/ Q! ^2 [2 T
< ><FONT color=#0000ff>#include <GRAPHICS.H>8 k- N8 L3 D* d/ o
#include <STDLIB.H>9 D; K. P2 U6 D: l9 |
#include <STDIO.H>
3 P+ a* h( ~' r- x9 B#include <CONIO.H></FONT></P>
) b T! {. U4 P h( D# I3 e1 E) I: ^< ><FONT color=#0000ff>int main(void) 0 V/ a# B$ ^, X; Z
{
: b% R0 M3 a4 F- c/* request auto detection */
! v$ u% ]) j( f% R5 b0 Qint gdriver = DETECT, gmode, errorcode; : d4 N3 k3 s; U3 H2 n
int midx, midy, i; </FONT></P>* w' k d7 N( \
< ><FONT color=#0000ff>/* initialize graphics and local variables */ ) o6 A0 q+ }( F2 Q, H* x
initgraph(&gdriver, &gmode, ""); </FONT></P>/ ^# O! J1 k$ ?. k" y6 p
< ><FONT color=#0000ff>/* read result of initialization */
, B! H% y3 k$ @2 T) h# Merrorcode = graphresult(); $ [. [/ {6 c8 p4 I% Z
if (errorcode != grOk) /* an error occurred */
% U, i7 ~" g: f+ Z* l% k{ 8 C+ p3 M) K6 {+ f
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * |! w* D8 I- {+ V O" Q
printf(" ress any key to halt:"); " b6 J6 |: d( t% y: g
getch(); % B- d" [. B4 f; v
exit(1); /* terminate with an error code */
* O% N$ e8 w; u0 \5 ~* y; ^1 F} </FONT></P>
* T0 ~( J2 {% v0 z' B Z& l< ><FONT color=#0000ff>midx = getmaxx() / 2; " {- r0 p) B4 M8 {0 ?2 `
midy = getmaxy() / 2; </FONT></P>
* o: F5 p# W/ Q! `- v4 l$ s< ><FONT color=#0000ff>/* loop through the fill patterns */
* {- w: M6 k$ @. q9 I) a5 rfor (i=SOLID_FILL; i<USER_FILL; <br i++)> {
5 \$ s/ j$ Y3 M4 M7 y. K* ^/* set the fill style */
; k0 H, c6 q/ o/ _( {9 tsetfillstyle(i, getmaxcolor()); </FONT></P> P5 z+ ^5 i7 d& l" u
< ><FONT color=#0000ff>/* draw the bar */ 5 @ A9 ^% K1 R' |# Z1 j
bar(midx-50, midy-50, midx+50,
+ g+ r D# r5 E$ {8 M. Xmidy+50); </FONT></P>
; d8 B l4 n& p9 ]3 C$ G& c< ><FONT color=#0000ff>getch(); 5 n# o( Y" O, \8 E: g: O
} </FONT></P>" c/ H$ x! |7 ^; Q
< ><FONT color=#0000ff>/* clean up */ 2 Q9 A$ ~- P' K+ A- x
closegraph(); + _1 T. }# {8 Y( U# t& j3 K8 t) T
return 0;
0 X& m& z, k5 n* G} </FONT>1 m3 m0 z- R1 p$ q) C
4 B$ g* z+ c. }2 U8 ^9 |& V# n
5 r& X3 A% l2 L$ r r</P>
& P( p, b i5 c5 Z2 m0 `< ><FONT color=#ff0000>函数名: bar3d </FONT>
" p. h+ O- c4 W3 }功 能: 画一个三维条形图 ' B; Y# ~: W; Y) L9 f2 l* w
用 法: void far bar3d(int left, int top, int right, int bottom,
% {# p5 [9 o$ _' l" k* z; Cint depth, int topflag);
1 v2 }8 r9 I( x" J( z4 D) ?' h程序例: </P>% L7 p, ^" _/ ]
< ><FONT color=#0000ff>#include <GRAPHICS.H>
9 ]1 S" n. O% L. Q#include <STDLIB.H>
, w. }8 @* [6 v#include <STDIO.H>" a. t3 c, y- I. u3 D2 p1 R4 U
#include <CONIO.H></FONT></P>
7 o- f5 i! T. _ Z< ><FONT color=#0000ff>int main(void)
6 V$ N" C: G! |! b{
{% J# t: S3 t0 c9 Q$ v7 c/* request auto detection */ 7 G/ b/ y+ Y* N# j* O8 l
int gdriver = DETECT, gmode, errorcode;
! d4 e& h/ i+ w( kint midx, midy, i; </FONT></P>4 Y0 N. E- L* Y7 ~) ^0 p
< ><FONT color=#0000ff>/* initialize graphics, local variables */ 7 t) Z( a% `0 y
initgraph(&gdriver, &gmode, ""); </FONT></P>
. E" V% v" V% i/ q/ _% }! }5 t: B< ><FONT color=#0000ff>/* read result of initialization */
1 {4 u! P# ]( n# F- c* Yerrorcode = graphresult();
% q5 V6 w4 T/ B; dif (errorcode != grOk) /* an error occurred */
2 T% w5 T. ^8 I$ c; ?* ]( U; f7 q{
% D2 ]! ^9 ]" Y/ @printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 n, X* Y2 b6 v
printf(" ress any key to halt:"); / S) B8 [' L$ ?" n u
getch(); & Z- Q* T9 h6 j7 ~
exit(1); /* terminate with error code */
" c( [8 ~3 { j6 x2 R} </FONT></P>0 Q! e% l3 Y* a4 t1 u0 y# Z9 Q, l `! p) s
< ><FONT color=#0000ff>midx = getmaxx() / 2;
5 U/ t) O8 N: o- u# smidy = getmaxy() / 2; </FONT></P>
! x+ ]: m9 | E- T& @3 `+ o< ><FONT color=#0000ff>/* loop through the fill patterns */ : @9 a/ C# G# ~) |1 G3 @
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 7 b( h7 p7 h7 X, E; r
/* set the fill style */ ( o* @9 t' s) e/ j4 M3 b- X* a: Y0 p
setfillstyle(i, getmaxcolor()); </FONT></P>
! O, |: J3 ^) g$ y< ><FONT color=#0000ff>/* draw the 3-d bar */ ( {$ d2 R5 w1 U1 }8 X' m2 Y6 T6 d
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1); </FONT></P>
& `6 R& T9 `5 K# Z3 u0 ^< ><FONT color=#0000ff>getch(); ; X3 ^- ~0 |) p$ l
} </FONT></P>
3 \; r- r5 Q5 p3 L< ><FONT color=#0000ff>/* clean up */
& H0 Z+ k( C# Nclosegraph(); ' ^$ z3 p( w+ |! i! Q5 k' K
return 0; % V% w" i. n7 y9 @ \: H: s0 W
}
& b8 Q+ M' t+ H7 v; X3 @9 e! ~</FONT># _% R- e: Z8 X+ h Z" ^6 u- j
* |+ V. y, n& K0 F0 s; q
</P>
: X4 O B g* G< ><FONT color=#ff0000>函数名: bdos </FONT>
3 M. R8 i- p) s8 P4 e功 能: DOS系统调用 9 A! |6 L0 {& h& L) ^# h2 L
用 法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 3 A, m9 a7 N5 ` b
程序例: </P>( c2 C3 y3 c0 M6 G S, ?2 S
< ><FONT color=#0000ff>#include <STDIO.H>4 T9 \3 M% L, u& ~6 Z
#include <DOS.H></FONT></P>
% r, M8 @8 S; G/ I4 O7 f< ><FONT color=#0000ff>/* Get current drive as 'A', 'B', ... */
' J% y5 R& U' _7 g6 c& Nchar current_drive(void) 1 z# @6 l/ Y' {- B4 b' }! z
{ % |* l' v7 |* B5 {, W( a5 u
char curdrive; </FONT></P>
- K( w! u, e0 t$ A, o. b2 w& c3 q< ><FONT color=#0000ff>/* Get current disk as 0, 1, ... */ # \+ U0 k V6 T! u/ ?: Y
curdrive = bdos(0x19, 0, 0); " i2 o+ T. |4 }
return('A' + curdrive); ( p& j/ w) w" F- H) f; f
} </FONT></P>
& U7 U. s: A" R* n< ><FONT color=#0000ff>int main(void)
$ Y1 I/ w8 T& Q1 m+ |# ]6 I& {( X{ 6 n) W- q, s; R+ M' Y- n7 a
printf("The current drive is %c:\n", current_drive());
; f( t8 G% t- v* h/ \return 0; . ~8 ~7 p# r0 ?/ m1 Q# Q0 T; B
}
- s* S3 @+ k: Y8 _. m0 Y/ l6 i* c6 b0 P. }4 l& G0 z1 E
</FONT> ^7 @2 T8 J8 l* V
</P>; f5 l$ S1 [+ w% X! Z! t
< ><FONT color=#ff0000>函数名: bdosptr </FONT>
( N! w b: s1 A% {& a功 能: DOS系统调用
) |1 l" l+ J0 R9 H* _用 法: int bdosptr(int dosfun, void *argument, unsigned dosal); 0 _/ d( B. @ Z9 _2 }0 C
程序例: </P>
3 Y4 @9 y9 D+ Q5 }/ U< ><FONT color=#0000ff>#include <STRING.H>
0 \ J$ V2 \2 q u+ C2 v#include <STDIO.H>
/ \" S4 y! M# G2 \3 F# F7 R" ]#include <DIR.H>
% V" ?: y0 ?) ^$ s2 J#include <DOS.H>
3 Z; W* [5 J2 C/ k. w#include <ERRNO.H>
% {4 J9 L `: R% A L$ ` |#include <STDLIB.H></FONT></P>4 u) T q; S. X0 G3 B/ ^
<P><FONT color=#0000ff>#define BUFLEN 80 </FONT></P>
1 S$ Z9 B3 a$ I2 n& w<P><FONT color=#0000ff>int main(void)
- i- y# T& A' K8 e$ @& ~! e& k n{
+ {# @* q$ `6 h$ x6 L- ^: }, y" Wchar buffer[BUFLEN]; $ x+ o$ _2 A: E: e. t# {; W9 F- t
int test; </FONT></P>
: q v4 U2 S0 \ y$ l: \3 C) o/ r0 U<P><FONT color=#0000ff>printf("Enter full pathname of a directory\n"); 2 o- N# W) c j# T
gets(buffer); </FONT></P>
, V( d. ]( V8 `6 b+ q<P><FONT color=#0000ff>test = bdosptr(0x3B,buffer,0); 6 [' Q4 x2 U+ N$ h0 x6 n
if(test) ~3 b% j R# Q( C) f% A+ Y
{ ) k' Z1 K) T, N2 b
printf("DOS error message: %d\n", errno); : N& E$ B! f! v: a8 w
/* See errno.h for error listings */ 9 V" h! e, i. S1 y& o" ~
exit (1);
+ z4 t3 `* Y! s, J% S& ^# h& r} </FONT></P>. v; a$ u$ C. t1 M+ T& F
<P><FONT color=#0000ff>getcwd(buffer, BUFLEN);
* l0 F ]$ \% S* b1 M8 \* E: K% wprintf("The current directory is: %s\n", buffer); </FONT></P>$ L+ O8 T! i5 R( C; E
<P><FONT color=#0000ff>return 0; & _$ a# h6 E% z: ~, T& t' P
} 0 A) ^7 h" O# ]' y) F _
</FONT>% J1 m2 I* A! Y
" v' @4 N6 |7 o# _( b# k+ V
</P>
U' U4 A" h, b# c0 w<P><FONT color=#ff0000>函数名: bioscom </FONT>4 z( y1 i, S( R/ [
功 能: 串行I/O通信
- C Y4 K" V. d( l" D; o! M用 法: int bioscom(int cmd, char abyte, int port); 7 E7 e% s- d z# r7 r Z
程序例: </P>& F) ]$ p% ^( N7 q
<P><FONT color=#0000ff>#include <BIOS.H>& S' m& M: C4 h; l+ V' Y" J e3 I2 Y" y
#include <CONIO.H></FONT></P>
7 d) p0 U& x! }( v% ?<P><FONT color=#0000ff>#define COM1 0 ) `( \. }* w# K7 \
#define DATA_READY 0x100
4 l: f2 f6 Z$ q1 R#define TRUE 1
! d0 H" ]5 f3 r( }' N#define FALSE 0 </FONT></P>1 C, |! e9 S* g
<P><FONT color=#0000ff>#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00) </FONT></P>
( O) k! ~" p- t' I' v7 z% w<P><FONT color=#0000ff>int main(void) 4 t3 k" a* A7 c- s' }( U$ h* N
{ 0 C+ N& m& m: m f; u5 U2 v
int in, out, status, DONE = FALSE; </FONT></P>7 N$ O5 b; i3 Y- [4 i+ b
<P><FONT color=#0000ff>bioscom(0, SETTINGS, COM1);
8 v$ v* g0 j) lcprintf("... BIOSCOM [ESC] to exit ...\n");
* N w4 y2 r9 Y* r! x: ~while (!DONE) 6 M3 i0 T' E- l
{ 1 D7 N9 Y7 u; r( q. Q4 m
status = bioscom(3, 0, COM1);
" Q; Z3 j6 k" w9 M" Z0 Y7 U3 gif (status & DATA_READY) 1 c+ A( \2 t) }" K" I+ X
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
0 Y2 [$ k2 s' ^8 g4 m7 Lputch(out); 4 z9 S$ M* h l6 M) R q, q' W
if (kbhit()) 4 T! o, I% H. K: l/ Z$ @1 r
{
o1 Q% p+ k. M/ G- `8 sif ((in = getch()) == '\x1B')
% m* ^3 z3 W6 \: @( DDONE = TRUE; . F& p7 B/ M0 e6 O4 o+ m
bioscom(1, in, COM1);
( v$ X2 ~2 z& x, q! i% X} 3 F* @7 N8 R0 |" d' _6 Q7 p
}
( |+ J$ E+ B/ Q! T8 z' d$ Jreturn 0;
% t& Z9 g1 U' h1 A1 I} </FONT>
" P, E. C m: J' w6 B$ f% ^ q1 `' y" [6 H
# r- i4 x5 C& z1 n: y. h9 l3 k3 U6 x</P>
# S" j4 }6 Q' x5 s6 ~2 o: {<P><FONT color=#ff0000>函数名: biosdisk </FONT>
) C+ A" U1 A/ i; |" N: f: m功 能: 软硬盘I/O
2 }6 z! o4 v8 i4 Z! L ^用 法: int biosdisk(int cmd, int drive, int head, int track, int sector 4 }+ B4 Z b; p# Q$ n9 U
int nsects, void *buffer); : N6 j& E: [% K% R3 a
程序例: </P>
7 c& d0 g1 }/ E$ ~0 p" A5 R<P><FONT color=#0000ff>#include <BIOS.H>7 X( |) t5 O! l) V0 Y5 D. b" d
#include <STDIO.H></FONT></P>
4 B8 f0 G+ ^" w. J- }8 a<P><FONT color=#0000ff>int main(void) / T8 D8 b" d! r
{
1 M- V$ Q+ Y% e5 r9 D9 sint result; - T( o" I8 z* {" s
char buffer[512]; </FONT></P>
9 Z# h! `* f9 `" s<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); & L, t7 S" F) k6 v! n
result = biosdisk(4,0,0,0,0,1,buffer);
9 O: G5 f! e: C0 N$ `* V% }result &= 0x02;
" X, D% i3 N( @+ `2 H! i( @& z6 c(result) ? (printf("Drive A: Ready\n")) : ( Z, D8 o' c8 C4 q2 `' j+ p0 ~
(printf("Drive A: Not Ready\n")); </FONT></P>0 o k2 _9 ~- c3 k
<P><FONT color=#0000ff>return 0; ) n+ e8 i& U4 |9 j7 Q3 y# [7 E
}
5 h, _8 O: {# q# E/ L5 d* S</FONT>5 ?, _# c8 W6 D+ \
: `2 B+ L' U$ ~+ l</P>
" B1 Q# v& h# |<P><FONT color=#ff0000>函数名: biosequip </FONT>
: G7 i$ j# W% l3 q+ L- W5 n功 能: 检查设备
" t& E' W. b& I* N* \) \0 j6 |3 N6 z用 法: int biosequip(void);
" w# X4 b1 n+ n6 ^ B J- \; q程序例: </P>
G! v R8 y) |5 h) x# Q<P><FONT color=#0000ff>#include <BIOS.H>
( R, B+ g0 t* j3 r#include <STDIO.H></FONT></P> F* I: Y1 k6 E/ z; u) |: k
<P><FONT color=#0000ff>int main(void)
4 a9 |, V# f; C4 ^{ - T# O4 y6 i, @
int result; , d8 t' K% K( z0 k: E. E# v, j
char buffer[512]; </FONT></P>% I: l& r: y7 m
<P><FONT color=#0000ff>printf("Testing to see if drive a: is ready\n"); % o: B' _, I) ^" t+ e c- T2 `2 T7 f
result = biosdisk(4,0,0,0,0,1,buffer); 0 Y" F' L/ @4 ~+ f- Z$ w& v
result &= 0x02;
$ @( }- e3 a0 B3 t% s(result) ? (printf("Drive A: Ready\n")) :
0 B% a7 c9 Q- z% Y3 V! j. @4 P(printf("Drive A: Not Ready\n")); </FONT></P>$ P3 `; r7 B6 `
<P><FONT color=#0000ff>return 0;
6 G* e6 Y( K+ U# }- R1 E}
, B/ {1 [+ ^) Q& w# @8 G" j</FONT># x$ Y( z5 f5 v
/ m! {2 l0 \6 V4 n% S
</P>
& d$ }/ C8 U8 ]* N<P><FONT color=#ff0000>函数名: bioskey </FONT>
2 Q3 C" H4 Q! E1 B功 能: 直接使用BIOS服务的键盘接口 : M R1 v. d! D$ u3 n
用 法: int bioskey(int cmd); $ y! B+ A5 |* A3 v* G6 c
程序例: </P>
% Q4 K0 n2 K( \, A. n6 U. w<P><FONT color=#0000ff>#include <STDIO.H>
3 t" k4 `# o$ ]. ?4 `& o) {( M( O#include <BIOS.H>$ Z+ J3 e1 _0 S- y- x) I: o
#include <CTYPE.H></FONT></P>4 u6 d5 B; `3 F* z9 r& d# Z; B6 _3 s( {; a
<P><FONT color=#0000ff>#define RIGHT 0x01 / ~# e, B$ f" G4 c: s- [
#define LEFT 0x02 4 y3 J# }; f; q. ?& s+ W
#define CTRL 0x04
/ [1 y9 q1 A/ Y# S#define ALT 0x08 </FONT></P>
" W* O* P4 n5 Q% `* x2 {<P><FONT color=#0000ff>int main(void) 1 a, K! ~8 V# g" G8 `" s4 U
{
1 n! x+ X( ]$ q1 P$ ^& nint key, modifiers; </FONT></P>
$ W$ |3 `# ], N5 e; D" j<P><FONT color=#0000ff>/* function 1 returns 0 until a key is pressed */
. r& a1 O) e9 O' B' Qwhile (bioskey(1) == 0); </FONT></P>
e/ S G& |4 f; P9 A<P><FONT color=#0000ff>/* function 0 returns the key that is waiting */ # e; G4 ]. X3 t6 s5 S5 b: ^
key = bioskey(0); </FONT></P>
" P4 U2 [* ?5 q<P><FONT color=#0000ff>/* use function 2 to determine if shift keys were used */
8 e# y0 _+ M/ V. A0 kmodifiers = bioskey(2); / y; f8 f; ?0 B R
if (modifiers)
- j2 b- h$ K& T$ H/ U- h- O1 \{
( b2 e; C- d( g: Sprintf("[");
, h. l, V8 p& T I$ _# m% nif (modifiers & RIGHT) printf("RIGHT");
- I6 q( x, T/ w4 P- b7 M3 u8 zif (modifiers & LEFT) printf("LEFT"); 5 t" k: k1 ]+ ?% w7 g' u
if (modifiers & CTRL) printf("CTRL");
3 N( l8 `: x1 o# Z A; E0 Sif (modifiers & ALT) printf("ALT"); # L' }5 D) I6 i2 _
printf("]");
& `" D" n; Q% Q& q: {4 V" Z} * r/ k8 G9 e8 Y' y5 K4 b3 p7 F1 E% n6 e
/* print out the character read */ " B- I( ~) d! R+ q
if (isalnum(key & 0xFF))
$ q' X& P3 N% Q+ B5 w! ]& [# n- ]9 S+ cprintf("'%c'\n", key);
5 `2 i8 v; I2 \* d7 `: N* {else ' T" F$ `! U1 u; |4 d, l- }; G9 [
printf("%#02x\n", key); 7 J c! Q7 ?& [0 c2 K# T: i
return 0; " I O- ^# \4 s$ U3 p# j
}
5 [ ]" E: x% s H: z3 J! y5 H* f5 y
</FONT></P>& f; g& L: L; _* i- l* F
<P><FONT color=#ff0000>函数名: biosmemory </FONT>4 ~+ [ w8 l* z# x. ~+ p4 Y5 l
功 能: 返回存储块大小
; T7 P. W! {( P用 法:int biosmemory(void);
2 A! m& V* o8 p" ?1 J9 ^) U' p- d程序例: </P>& e1 C- ?4 W# I' t F% X9 l, O
<P><FONT color=#0000ff>#include <STDIO.H>
3 E& @0 o% S' `* x: S) p3 P5 b3 o#include <BIOS.H></FONT></P>
6 S* G q- z/ s \1 \" {( m$ C<P><FONT color=#0000ff>int main(void) ! J! W2 R; k2 }2 f5 h
{ - u6 ~+ L# C2 F+ O# q# f' ^
int memory_size; </FONT></P>* r# H$ ~; _, p) L. ^3 R
<P><FONT color=#0000ff>memory_size = biosmemory(); /* returns value up to 640K */ * C8 ~% C1 `1 U* i9 F8 W
printf("RAM size = %dK\n",memory_size); 7 }* M x* K X6 M6 i
return 0;
* n; ~6 W. P7 x2 C, a5 W}
- D! A$ i- n! v1 S# z0 s$ F</FONT>
$ s4 b2 P' D. P, r
% d/ V: P0 q, c C- l4 K</P>
4 O. q2 N$ s6 r/ b<P><FONT color=#ff0000>函数名: biosprint </FONT>
' D+ E6 O5 @* j" O功 能: 直接使用BIOS服务的打印机I/O : S M% l7 a+ p4 A8 g! A
用 法: int biosprint(int cmd, int byte, int port);
! m& _3 ^; {/ m+ m) B* h" b程序例: </P>! l7 @4 o, [ J3 n
<P><FONT color=#0000ff>#include <STDIO.H>
9 f& Z+ K5 z7 D#include <CONIO.H>7 x& ~% o* S2 I; i6 n
#include <BIOS.H></FONT></P>! l* i* [8 w. X0 k
<P><FONT color=#0000ff>int main(void)
: h8 H. X: a* }' r" _3 T{
6 b7 A% C( W; [8 ~/ p( ^#define STATUS 2 /* printer status command */ 8 B- o9 f! F+ j$ Y4 d
#define PORTNUM 0 /* port number for LPT1 */ </FONT></P>; J8 e0 l2 o7 x# r# c7 k, N4 ]
<P><FONT color=#0000ff>int status, abyte=0; </FONT></P>4 ^0 |5 B b7 I( A0 Z V
<P><FONT color=#0000ff>printf("Please turn off your printer. Press any key to continue\n");
0 n# C) G: M% [( r/ D$ T0 s) tgetch();
* d$ w. f+ _" A' i1 sstatus = biosprint(STATUS, abyte, PORTNUM); 2 m, u& P) ~. W z6 T/ l U4 J
if (status & 0x01) , O! ~% b$ ?! p- A# b2 I' h. x" D
printf("Device time out.\n");
) L0 _8 h9 p# j Nif (status & 0x08) 2 g9 _, A3 u3 y/ {
printf("I/O error.\n"); </FONT></P>
% a0 X% ~2 G2 ]; A! \, m<P><FONT color=#0000ff>if (status & 0x10) H/ z- [- B' ^9 ?
printf("Selected.\n"); $ [2 H% Y1 b. }
if (status & 0x20) 2 {0 \$ E+ Y! w% k) t
printf("Out of paper.\n"); </FONT></P>
% R4 {, z! o$ E% Y<P><FONT color=#0000ff>if (status & 0x40) x/ G8 i- s/ C3 u
printf("Acknowledge.\n");
6 P& u: b8 D' q; |( }if (status & 0x80)
) O* a, i9 X1 x2 q1 z- H; V8 e' eprintf("Not busy.\n"); </FONT></P>: N. W' C7 y% T
<P><FONT color=#0000ff>return 0;
& X D% e8 P- e9 c}
% T1 K! ^# ^' e# I7 f</FONT>' v4 ?) H: w3 G6 I/ G
2 H' n- K. n7 f1 J5 Z4 S% s- [. {</P>
& H! U, m3 e' }8 I% ]. L<P><FONT color=#ff0000>函数名: biostime </FONT>
* M8 v S5 b# z9 U! D: P功 能: 读取或设置BIOS时间 0 ]& C+ J, J" F. P2 b
用 法: long biostime(int cmd, long newtime); * g# @8 U% z4 u* a* I$ |
程序例: </P>1 |% Y3 D0 m3 s8 s: {: ?0 |' G* m' O
<P><FONT color=#0000ff>#include <STDIO.H>
! A- L U, e6 |4 G) Y, H4 M#include <BIOS.H>
( i' t; d4 O Y* M0 E0 z$ F#include <TIME.H>
" O5 A, K4 d1 L. I9 K7 o8 T#include <CONIO.H></FONT></P>
/ l. U- {/ _4 H, Z2 d<P><FONT color=#0000ff>int main(void) 5 `' u" M4 I) R5 r
{ 3 @0 n: M+ B. Y0 ?- q* N
long bios_time; </FONT></P>
: V& _* P! w" ~8 v* d0 s7 u( q<P><FONT color=#0000ff>clrscr();
1 d, T9 v6 H, Qcprintf("The number of clock ticks since midnight is:\r\n");
( C6 a; q# C* ?: P" [& d3 Zcprintf("The number of seconds since midnight is:\r\n"); - X. T) |/ _: e8 ~8 S
cprintf("The number of minutes since midnight is:\r\n");
- N3 @& S. ~7 d* X. W* |+ u4 Mcprintf("The number of hours since midnight is:\r\n");
2 Y& z" Z1 n ~1 k* tcprintf("\r\nPress any key to quit:"); ; B5 I) t2 U B7 V
while(!kbhit())
/ s' `* y+ c8 T3 L: O{
. j9 U& D8 m: y5 `; v9 {( [bios_time = biostime(0, 0L); </FONT></P>
2 Z5 l2 C" k7 q<P><FONT color=#0000ff>gotoxy(50, 1); $ A5 U7 C, E4 ?' N& X
cprintf("%lu", bios_time); </FONT></P>
2 M8 Y% ]; g8 s2 `7 u. X<P><FONT color=#0000ff>gotoxy(50, 2); - S7 z7 p( }3 |2 q9 i& c
cprintf("%.4f", bios_time / CLK_TCK); </FONT></P>+ _( P0 |7 i% u% Z: V& \. j2 d
<P><FONT color=#0000ff>gotoxy(50, 3); 8 r Z' c) e% r
cprintf("%.4f", bios_time / CLK_TCK / 60); </FONT></P>
" d& U4 W3 ]6 j. |; z<P><FONT color=#0000ff>gotoxy(50, 4); . }% T( d- H% J% g5 C
cprintf("%.4f", bios_time / CLK_TCK / 3600);
1 |2 c) M7 |. ]9 |}
2 H' j2 Z4 x4 F1 L& U- Nreturn 0; ; b: \& Y8 z. Z) i; m5 T% v
}
5 X I3 q. {; d' i</FONT>" l, b2 @# C" A( E
' k6 C! O% U- W/ ]+ o$ r
</P>
- d2 y0 I9 W3 @2 [, _! ]<P><FONT color=#ff0000>函数名: brk </FONT>
$ G2 p5 y& N% V" F4 I功 能: 改变数据段空间分配
Y, q! l- D& J5 R- l/ M! P" A4 J! P用 法: int brk(void *endds); : }. ?3 ]% T& A$ }3 F
程序例: </P>; V" y: F6 j: |. m- c& }2 r
<P><FONT color=#0000ff>#include <STDIO.H>4 G; a* T& z! q- v
#include <ALLOC.H></FONT></P>- \3 L6 g& G* S, }/ ^& q3 s
<P><FONT color=#0000ff>int main(void)
7 D7 E& O; \& s7 W{ 5 f( Y9 _+ }( r, I: O' \/ g
char *ptr; </FONT></P>2 X3 j& }! U( B+ P) l. P p
<P><FONT color=#0000ff>printf("Changing allocation with brk()\n");
9 y9 B% i& A5 Q+ jptr = malloc(1); & H3 m6 R: _7 a; X3 H5 P' Y/ F
printf("Before brk() call: %lu bytes free\n", coreleft()); * e1 E3 e9 K( n$ [3 u' z. ]+ |2 n
brk(ptr+1000);
& S3 `% i5 t! f' _+ f) nprintf(" After brk() call: %lu bytes free\n", coreleft()); 2 J1 @* x1 F" }1 F, |4 s
return 0; 6 i1 l' @5 e* i# X
} X8 h' x. M8 h1 m! f4 I( A" C
0 h7 ]) c2 O, B6 R5 _2 B" V</FONT>' }& e7 i7 q( c+ t. R
</P>+ m! S: q7 t5 Q8 D6 l
<P><FONT color=#ff0000>函数名: bsearch </FONT>) o9 a Z' i/ @6 w: K8 b4 ]9 _
功 能: 二分法搜索
: I9 z. i" J/ L1 W/ s用 法: void *bsearch(const void *key, const void *base, size_t *nelem, % t& f7 C% K2 T8 N
size_t width, int(*fcmp)(const void *, const *));
5 k! w& V1 e! \# j程序例: </P>
. j2 |1 `) C1 U/ Q$ I: a; X- T<P><FONT color=#0000ff>#include <STDLIB.H>
7 ] s& s. b+ V- ~6 z#include <STDIO.H></FONT></P>
9 \) p$ j) Z# C+ g# E: p<P><FONT color=#0000ff>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0])) </FONT></P>8 \8 {! t( b0 ~- d
<P><FONT color=#0000ff>int numarray[] = {123, 145, 512, 627, 800, 933}; </FONT></P>) {0 Z. o9 x% n0 C8 I; b
<P><FONT color=#0000ff>int numeric (const int *p1, const int *p2)
2 v) x% E2 U% e. G" }0 y{
( [: s2 @0 C _0 Freturn(*p1 - *p2); 5 R* }3 m4 z+ ~4 X3 H B
} </FONT></P>
" o& u% ?; ^; B: D* Y& a5 k<P><FONT color=#0000ff>int lookup(int key) 5 g" G( R5 J0 p/ P2 }8 I
{
5 `+ p; B1 Q% s+ Q5 U A: A; w1 gint *itemptr; </FONT></P>
) M8 Z; i& A5 |! u- U' E<P><FONT color=#0000ff>/* The cast of (int(*)(const void *,const void*)) . w! t+ a0 R) O# q) d
is needed to avoid a type mismatch error at
) m* \ Z, d$ r2 w2 ocompile time */
8 Q0 d1 a8 O" l8 y! o" Nitemptr = bsearch (&key, numarray, NELEMS(numarray), & H G! Q5 L: `
sizeof(int), (int(*)(const void *,const void *))numeric);
" }6 O% b6 ?1 ~: i, ^ H) creturn (itemptr != NULL);
4 m/ K) k9 m# d} </FONT></P>
( p) c, k7 o- X; G2 U<P><FONT color=#0000ff>int main(void) # z- c$ G8 E" M$ D; `* k* L
{
- V3 X6 D; P; g. M: T) ]if (lookup(512))
9 Y6 J0 g) a4 Xprintf("512 is in the table.\n");
4 [8 e4 R$ \) l; E" |" ~* \7 D, F$ oelse * |$ v& [' l1 s+ n( \0 e: R9 i$ f
printf("512 isn't in the table.\n"); </FONT></P>
$ A6 G c! m4 C2 z+ `<P><FONT color=#0000ff>return 0; 5 D( C9 @' C5 U0 N
} </FONT></P> |
zan
|