- 在线时间
- 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>函数大全(i开头)</FONT></B></FONT></P>( P/ e0 D0 c& C" n
< align=left><FONT color=#ff0000>函数名: imagesize</FONT> : x7 O4 E" T! I+ }
功 能: 返回保存位图像所需的字节数 . B& J7 J5 @& h l* g5 k3 v' g/ W
用 法: unsigned far imagesize(int left, int top, int right, int bottom); + w: l) h- h+ r
程序例: </P>2 {& Q/ x: g8 T# E8 e2 Y
< ><FONT color=#0000ff>#include <GRAPHICS.H>7 R# o! x3 ?7 Q# @# T
#include <STDLIB.H>
. t/ F/ u5 x/ S2 t$ [#include <STDIO.H>
6 }2 S( y. i' f3 x#include <CONIO.H></FONT></P>
* R+ L0 h/ X7 ~; d Z< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
- ? ^$ D' j; a8 H5 Q2 e/ `< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>) w1 f; {& I" C8 s! U% K
< ><FONT color=#0000ff>int main(void) 8 M% {. ]2 W @/ b H) ^ Y
{
' z/ l& j4 Q" b: u7 d6 V/* request autodetection */ 0 a. W4 z1 c1 c1 l) U! J
int gdriver = DETECT, gmode, errorcode; Y/ |2 r; B0 F5 k5 X3 `" N4 `
void *arrow; ( ? D% N/ B( q# L d! S
int x, y, maxx;
. _+ o4 E% y9 junsigned int size; </FONT></P>
2 i/ F8 H5 Z. h a: g< ><FONT color=#0000ff>/* initialize graphics and local variables */
# A8 Q4 v. m+ T: ^! F% ]! binitgraph(&gdriver, &gmode, ""); </FONT></P>! P. a5 g* W+ D
< ><FONT color=#0000ff>/* read result of initialization */
* j4 c; r, h. E- G0 ^) o4 ^) qerrorcode = graphresult();
7 z2 w4 p. K% Mif (errorcode != grOk) /* an error occurred */
; e# `1 {! l: t{
/ F/ Y+ O. M( Z1 Y! Aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. d1 d. d; n' |printf(" ress any key to halt:");
- L9 Z& ]- ?2 E) J; x5 _: bgetch();
0 E- i+ R7 W6 E/ G! l( T, ~0 h2 C8 |exit(1); /* terminate with an error code */ 7 T. L, }! T! A$ L5 C2 j
} </FONT></P>( a. K! a2 B" f1 _% K$ @
< ><FONT color=#0000ff>maxx = getmaxx(); 7 B, v) q4 H b. P2 l' O9 E$ R
x = 0;
) ]/ L0 J. J7 }. Y. ?* R& Y# ^4 D* Ry = getmaxy() / 2; </FONT></P>
% ?6 P8 q3 F: |% ?5 h4 u0 ^* W3 {< ><FONT color=#0000ff>/* draw the image to be grabbed */
/ Q0 f& d2 p5 h7 p' g. j) Idraw_arrow(x, y); </FONT></P>$ e( u2 U( r/ O2 C7 _
< ><FONT color=#0000ff>/* calculate the size of the image */ & g( S# J; q( [( J& Z+ ^
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>. S/ i- Z5 o, y+ z& j
< ><FONT color=#0000ff>/* allocate memory to hold the image */
' M( |* ]' j1 q9 u4 Earrow = malloc(size); </FONT></P>8 I2 S. C2 ~" O$ ?# x
< ><FONT color=#0000ff>/* grab the image */ " _3 w+ b! @' w# G- l7 u" d
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>6 M- y, h# c1 y) }
< ><FONT color=#0000ff>/* repeat until a key is pressed */ & u0 s) A- j9 x( Q6 |. J
while (!kbhit())
9 L( N# j; O5 K1 f s{ - C8 K& g. E+ Z/ G" P% E
/* erase old image */
, `0 b% o7 h6 D7 ~putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
6 N7 }" }( ]' o- T: M< ><FONT color=#0000ff>x += ARROW_SIZE; * C4 F1 i; |6 s2 s, y
if (x >= maxx)
9 m& y$ b: f! ~% B1 z! ]) T) O$ _1 {x = 0; </FONT></P>
4 Y) x! M: |' I( Y" W8 R/ P1 e< ><FONT color=#0000ff>/* plot new image */ $ ?9 c5 \5 W0 \4 E
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
: f+ K4 ^2 _7 g8 k0 V} </FONT></P>& F+ j+ C: d2 F5 H+ B) t3 |: A& \
< ><FONT color=#0000ff>/* clean up */
9 i$ I5 r3 d+ n3 rfree(arrow); ; s6 ?) G6 [! c! w6 Z% \% M
closegraph(); 8 E8 a) T2 P! q0 M% k, y/ B
return 0;
" e, `& E) P0 B7 D} </FONT></P>
( G4 T! M8 d' \1 V" ]< ><FONT color=#0000ff>void draw_arrow(int x, int y) 6 @5 J! V" G& P+ }8 y ?# c
{ 2 j8 {$ v% u2 e. m! S: V) v
/* draw an arrow on the screen */ & t2 K1 e! q: d8 x7 n0 ]3 C& M/ d
moveto(x, y);
6 U' |7 h o3 ^8 {2 X7 j/ m% Slinerel(4*ARROW_SIZE, 0); / k) H* b& ]7 D0 J) V3 i9 V# o) f# H
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
9 M2 n, e; o* G$ I: ]$ C% |linerel(0, 2*ARROW_SIZE); ( }. k7 G. ^8 e+ {* Y8 ~0 y( P
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); + {: l+ h4 L! Q4 S! k8 a
} $ s4 `! I! _' S8 i( h; a# Y6 s9 S( s
( F. I% y" [2 }! \; u. n6 q
. [! {# I4 b- t</FONT></P>
. h" E" o3 R' N2 P$ A< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
% e8 _- ]7 V) N+ @1 `. X$ V+ y& x<FONT color=#000000>功 能: 初始化图形系统
, y* H5 R& E0 H1 M用 法: void far initgraph(int far *graphdriver, int far *graphmode,
1 o" v0 b: `& Ichar far *pathtodriver); 3 U1 l( M! b3 G( Z9 g" c' ~0 ^
程序例: </FONT></FONT></P>0 p5 r' K* E+ s& L: v1 Y
< ><FONT color=#0000ff>#include <GRAPHICS.H>6 e& R3 ]* M& G3 l m0 t
#include <STDLIB.H>
, U! r: x: f" y- z; f( e+ E* o#include <STDIO.H>, H8 Y- h8 `/ D% `# A/ n. O2 s
#include <CONIO.H></FONT></P>
0 |; d! F; e& f4 Z: P5 ?< ><FONT color=#0000ff>int main(void) - k* M% R# ?7 Z7 _$ L
{
5 u% l1 g: N4 T& [. j7 a7 d/* request auto detection */ * i! |2 m# T! T" R7 j. w4 J
int gdriver = DETECT, gmode, errorcode; </FONT></P>* y+ f4 \" m! c, u9 ]* v
< ><FONT color=#0000ff>/* initialize graphics mode */
' i0 v+ b; Q. jinitgraph(&gdriver, &gmode, ""); </FONT></P>
u" w4 E% K# f. S' S+ X< ><FONT color=#0000ff>/* read result of initialization */
2 u- S2 l, n2 |2 s' a4 a- herrorcode = graphresult(); </FONT></P> _' D# }% i n% A( W8 C. C
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
9 ?' K- T8 B$ V( K3 Z{
% ?( @( {( \) [printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 b! J( U! S3 @# n/ N9 C! Z: s0 yprintf(" ress any key to halt:"); ( r) ~% ]' J3 `
getch();
2 q- p2 Z8 `* t" c" yexit(1); /* return with error code */
4 t) @$ l1 B L8 O) k; m0 ?. }3 D+ d} </FONT></P>- i2 c+ j, A- A6 @5 `
< ><FONT color=#0000ff>/* draw a line */
6 D; P+ D- z" u t* z5 A9 Zline(0, 0, getmaxx(), getmaxy()); </FONT></P>
$ Z0 V% s( R$ k7 L+ u< ><FONT color=#0000ff>/* clean up */ 6 r5 Z9 ?# c1 M2 a
getch();
5 l- N1 O5 V2 A% `9 P- x. a( _closegraph();
$ K0 {) P- a/ }3 ? F+ i" R: Dreturn 0;
0 n. z5 p' T' N9 C% {0 x} </FONT>
! Q. o2 J' r s* G- S/ J6 d7 T8 @, E' z; G! F
</P>% [% E$ @0 @4 p
< ><FONT color=#ff0000>函数名: inport </FONT>/ W7 i6 t, ~6 s+ M' h0 p. K; x
功 能: 从硬件端口中输入
! f) [! v& X7 D- ?用 法: int inp(int protid); 2 T1 ^% R; n) p% ~) ]4 O# d
程序例: </P>
2 @& U0 `, i; y7 G/ c, a; m< ><FONT color=#0000ff>#include <STDIO.H>1 s: j! k! r7 B& s1 X& R" m' @" h
#include <DOS.H></FONT></P>% u+ Z( W( Q7 F, W. i
<P><FONT color=#0000ff>int main(void) 3 N$ `/ h. J# N u, v
{ ' h- S! V& e% j( ^
int result; $ u5 Z6 o; C7 U% c. R7 b# }
int port = 0; /* serial port 0 */ </FONT></P>
2 K0 O3 R( D+ M# i<P><FONT color=#0000ff>result = inport(port);
" a1 ^" I- J3 | D% o0 l. Gprintf("Word read from port %d = 0x%X\n", port, result);
9 g6 A7 k L+ x1 Ereturn 0;
3 b& T) P( W& M}
) d4 {1 t* |. K y2 M: W2 F9 I( y7 d/ x+ C+ p, P. L
</FONT></P>* [) h1 T/ [' O. s. Y) K3 B
<P><FONT color=#ff0000>函数名: insline </FONT>
$ f3 y' e" q. q: z, F3 K功 能: 在文本窗口中插入一个空行 ! O( ?0 X. X9 h/ v# |% M0 u
用 法: void insline(void);
A: I9 E* v {" w: A5 J9 `程序例: </P># S1 N8 P0 V% x z6 |+ ^5 e# i
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>4 M2 J* e9 U; B" `* m+ r
<P><FONT color=#0000ff>int main(void) . b! d5 j2 z8 f+ R) O5 k' \; s& E. l
{ " j1 A- p' i% u7 ?
clrscr(); " w" b( s3 X' h' x7 p( L
cprintf("INSLINE inserts an empty line in the text window\r\n"); 6 q9 e0 o" O+ U
cprintf("at the cursor position using the current text\r\n");
5 ]2 Z' a2 B( T( d7 n: n5 l5 qcprintf("background color. All lines below the empty one\r\n"); ' x* s$ [4 l: Y/ \" z
cprintf("move down one line and the bottom line scrolls\r\n"); 6 x) X8 n) A e8 T7 a
cprintf("off the bottom of the window.\r\n"); 6 V5 W6 |6 Z* X0 K8 h$ ?" b
cprintf("\r\nPress any key to continue:"); 2 N4 N3 w6 Q9 K7 X4 A* V& c9 i
gotoxy(1, 3); / G' l' I: J; e0 ?6 I* m
getch(); 0 d9 B/ y& R: a& Z# {/ _6 q9 R
insline();
9 J$ ]' w Z/ cgetch(); 6 _) }( r @9 R5 ?$ B5 ?
return 0;
' u+ `9 X( C0 O w) Z}
% ?5 t/ \7 m" K& ^6 b4 ^2 v8 n</FONT>
2 Y+ p1 k g% N- r4 Q! C5 B1 s4 z6 h. }7 q2 T9 l$ F6 x; q
</P>
" e! M. K0 `9 D1 K( R/ g' P<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
" ]: h( {2 ?3 E/ ?4 u3 d. Q% s% y功 能: 安装设备驱动程序到BGI设备驱动程序表中
) E7 J- M" I* z0 i, ?用 法: int far installuserdriver(char far *name, int (*detect)(void));
+ N. W C4 R: \程序例: </P>
0 @0 B/ M) H m<P><FONT color=#0000ff>#include <GRAPHICS.H>) G5 U* Y! k+ X! ~6 S
#include <STDLIB.H>. q, |: ^+ \. h- Q5 O
#include <STDIO.H>
& E! C4 K# ~( E5 y2 c6 I#include <CONIO.H></FONT></P>' k" \* Y% _; {$ x8 B% B; F, {
<P><FONT color=#0000ff>/* function prototypes */ 4 H9 s! u1 ~$ l, n* |' J. e
int huge detectEGA(void); 8 s0 t, e! v" v) F& a0 @" T; A
void checkerrors(void); </FONT></P>, ~0 O: M) r5 [3 U
<P><FONT color=#0000ff>int main(void) " L: }; e* t" ]( m! {
{
) _% z3 \9 z/ m: h( Dint gdriver, gmode; </FONT></P>: G7 T3 d4 m" V) W* |
<P><FONT color=#0000ff>/* install a user written device driver */
# ^0 V, L& w/ U) c6 i) X1 dgdriver = installuserdriver("EGA", detectEGA); </FONT></P>2 V3 x; f9 W7 F" q: X* X) \$ N/ x8 e$ S
<P><FONT color=#0000ff>/* must force use of detection routine */
* q0 `! A4 w( Y% K: ugdriver = DETECT; </FONT></P>
* |! n1 X8 j4 m" B$ D5 y: {<P><FONT color=#0000ff>/* check for any installation errors */
3 m! O$ P: G% |3 c; B1 o$ tcheckerrors(); </FONT></P>
$ c# E) m9 W5 V8 F8 J: T/ u<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 Y7 Z! k. B0 m3 c5 P
initgraph(&gdriver, &gmode, ""); </FONT></P>
9 v0 ^( u, J3 n3 ?$ [% F: n: X<P><FONT color=#0000ff>/* check for any initialization errors */
( @7 ?- G2 Q3 @ [/ a' Ycheckerrors(); </FONT></P>- K# `* A! X p5 y _6 i& h
<P><FONT color=#0000ff>/* draw a line */ / {4 A$ [5 O% z5 _# T, C' V
line(0, 0, getmaxx(), getmaxy()); </FONT></P>$ e4 {# C, Q. ?
<P><FONT color=#0000ff>/* clean up */
" `) A) L/ s, ?/ j- ~. tgetch();
/ q/ |4 q1 F* T! ?+ Y8 ^closegraph();
4 R) i3 r. W2 |! Z, `5 j- F! hreturn 0;
, Z5 X1 z2 ?- V. Q( z# v} </FONT></P>" m" ?' z" C+ a& x: o
<P><FONT color=#0000ff>/* detects EGA or VGA cards */
9 W; @$ ?& } T. c* x( [int huge detectEGA(void)
& q6 z. K9 X4 O0 s{ * ]7 y2 F1 C* A! S% I( l" ^
int driver, mode, sugmode = 0; </FONT></P>; }4 @6 p {8 o' s7 q
<P><FONT color=#0000ff>detectgraph(&driver, &mode);
/ T" W4 k9 N! ?" U7 B8 u1 uif ((driver == EGA) || (driver == VGA))
* L) f0 w, M, m# @: S* W* \- D F/* return suggested video mode number */
/ i* m3 `$ E4 R6 G1 O ^) xreturn sugmode;
1 b: S% @: V5 Q$ u8 ielse
3 w& ^0 Z" h9 Y/* return an error code */
4 F1 f9 ^( t( M/ Ereturn grError;
6 e3 N5 }' b/ }) _} </FONT></P>7 R2 R( w2 a3 Y/ I/ H V2 v% I
<P><FONT color=#0000ff>/* check for and report any graphics errors */ . Q0 I5 L2 Y4 c- ~4 X4 j! n
void checkerrors(void)
5 @$ y# B7 q2 |; ^0 k/ V{ . n0 B5 E# B+ a1 @' A
int errorcode; </FONT></P>5 J8 U3 M! Z; L
<P><FONT color=#0000ff>/* read result of last graphics operation */
- a* D% o7 w, o1 merrorcode = graphresult(); ? J! _* Q6 {
if (errorcode != grOk)
) X6 {: h( W- Q' I+ V& a8 z{ 3 i" t. c) }4 U+ i7 ~
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - @% R# \0 x- c4 L8 t/ F
printf("Press any key to halt:");
1 S* R# j' N1 J+ Bgetch(); ' r3 K7 p$ n) o# G5 [
exit(1);
; F. z6 m/ h' v! _( W/ j$ n! Q: q3 w}
! D* i! T% S+ Z% Y% ?6 d} </FONT></P>
) S4 q3 P6 b( i<P><FONT color=#ff0000>函数名: installuserfont </FONT>7 A6 \% W0 Y/ J% X- }' @2 r
功 能: 安装未嵌入BGI系统的字体文件(CHR) 0 ~0 W2 ]. J) ]# a* ^- E1 h* L
用 法: int far installuserfont(char far *name); & r& D$ M+ N/ f& b$ j
程序例: </P>
8 I/ {7 k: u' u; d( W5 t- G0 C<P><FONT color=#0000ff>#include <GRAPHICS.H>
! r& R- g% j9 Q& f! h#include <STDLIB.H>
' J' u* E# P/ h#include <STDIO.H>
" u3 E7 a, x( Z! V1 n8 i#include <CONIO.H></FONT></P>
$ o/ y! W( s% o$ g9 i: S<P><FONT color=#0000ff>/* function prototype */
/ C- L$ Q# `) V$ \$ wvoid checkerrors(void); </FONT></P>. R9 o c C( j
<P><FONT color=#0000ff>int main(void) 5 f/ j- _# T( T* w
{ ) S7 B6 X& Y! k q% c
/* request auto detection */
* e# A4 L1 s( E9 [0 a0 ? S; c3 gint gdriver = DETECT, gmode; 8 u" V' |% s' `& P5 i$ K
int userfont; 3 E' G9 Y- o4 C& w7 t5 g
int midx, midy; </FONT></P>; G7 h+ a4 d/ z! e
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% _5 h' A; x% J Yinitgraph(&gdriver, &gmode, ""); </FONT></P>
! k* V/ D& R! L( O) ^! B0 E<P><FONT color=#0000ff>midx = getmaxx() / 2; : w% c b5 l- T& [/ S- C# p+ W
midy = getmaxy() / 2; </FONT></P>: Z, N- j' _9 I% a: q
<P><FONT color=#0000ff>/* check for any initialization errors */ - W- ^0 C* Y' x$ M
checkerrors(); </FONT></P># N( l- u; P' g) {. Z; `! r
<P><FONT color=#0000ff>/* install a user defined font file */ 1 @* n+ `1 u' a8 f# |
userfont = installuserfont("USER.CHR"); </FONT></P>" t$ w8 @% H1 C9 R! B4 k
<P><FONT color=#0000ff>/* check for any installation errors */
- n. @5 ^2 c5 E4 m ^# I3 Rcheckerrors(); </FONT></P>/ T7 B1 ]0 u! C7 I4 Q5 N8 i
<P><FONT color=#0000ff>/* select the user font */ , d5 C7 a- r$ E: ?. x
settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>5 d6 s3 R- ?& j# Z- I' j0 A0 H
<P><FONT color=#0000ff>/* output some text */
; }4 c/ @+ Z; t1 t; ]outtextxy(midx, midy, "Testing!"); </FONT></P>+ t9 w) v9 I5 ^# U3 B# ~) ?
<P><FONT color=#0000ff>/* clean up */
7 E8 R5 a- L) ~' Rgetch(); 9 W+ Z) Y) k( J* G# `
closegraph(); # U4 u# }; P5 G5 {5 ` q
return 0; 8 W( L7 H' s2 `8 o
} </FONT></P>
# h/ G( ^8 j% b% p<P><FONT color=#0000ff>/* check for and report any graphics errors */
: ^8 j; X8 b6 k' F, }5 l8 [1 Vvoid checkerrors(void)
3 }0 y6 m- q' `! }% j{ 1 @! |9 D2 @' w) l/ X- u! r
int errorcode; </FONT></P>
" A% p$ f! A; Z' z: _9 D2 v<P><FONT color=#0000ff>/* read result of last graphics operation */ ' C" @% J8 S$ Y) Q% n. \
errorcode = graphresult(); - A2 _* L" O8 n# l
if (errorcode != grOk) " s0 j& ?. e! U2 L8 @0 n
{ ; Y* L: } o- T; F* k, V1 E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 D+ W1 l9 a( ^" ~
printf("Press any key to halt:"); ' X: c) {: d7 |' T; T
getch();
* Q& X1 E4 g* y; U8 a4 L! v6 _exit(1);
" P6 [5 J; J/ y) x7 a2 n9 d2 I* c} & V2 p/ t8 }& ] s& F2 z7 F8 U5 `; |' A
} </FONT>5 G. t) f2 t- U& h# n
9 y5 _( `: Q$ n" J5 b, |( c4 ]; c; V2 g4 [$ ^
</P>
# e) g8 u- i; i, G! x<P><FONT color=#ff0000>函数名: int86 </FONT>
4 M/ ~/ t ?6 b& ]: G功 能: 通用8086软中断接口
0 T1 n( h9 U9 C用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
) q, c( I3 _' {% ~( c' ^程序例: </P>
6 j- ? a2 W2 S1 U2 E# r" M<P><FONT color=#0000ff>#include <STDIO.H>* \1 M: u8 B/ e* T* H
#include <CONIO.H>
; B1 q/ G" R3 {1 [2 \#include <DOS.H></FONT></P>7 b: f8 L9 Q7 t" ]" p
<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
3 k8 @. e/ x3 P<P><FONT color=#0000ff>void movetoxy(int x, int y)
; n8 w' E! n3 S$ W2 s{
4 J2 c. ?6 M2 munion REGS regs; </FONT></P>3 S' {9 X: n* A7 @. ~, z
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */ ; b2 b% v. \0 a# O: e p: v, M
regs.h.dh = y; 8 `+ q: S5 N6 f7 |# _
regs.h.dl = x; 1 ~+ }' `% ~, r# b# \7 i
regs.h.bh = 0; /* video page 0 */
: s v( J' ]) {int86(VIDEO, ®s, ®s); + ^$ r" J, m6 Z- v3 k9 F/ Z1 s
} </FONT></P>% N. D; y" m. c
<P><FONT color=#0000ff>int main(void) 3 d- s; z% f4 A2 G% t3 {
{ + I. L3 c M7 _2 E7 o: J% C
clrscr(); 2 a* ?9 _! }& g
movetoxy(35, 10);
l ^, D# `1 ?9 ^: S2 |, Tprintf("Hello\n");
7 l4 S$ _, `6 h5 Preturn 0; - {: `4 ~, K4 L3 g
} </FONT>
2 A$ T A, }- W5 `8 y: K9 W0 P% D3 w9 g# p
</P>
( R* x% }6 z" s4 E& p6 E<P><FONT color=#ff0000>函数名: int86x </FONT>. K: e: `& I" A+ Y2 b5 x! Y' N
功 能: 通用8086软中断接口 ( ]- f p# `( @( c
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, 0 Z" |2 y2 m" T- |# I
struct SREGS *segregs); * n* f; ?$ m% b) S$ e" n+ B
程序例: </P>$ A1 l4 r% c0 y# Y
<P><FONT color=#0000ff>#include <DOS.H>
2 d: D! J: D' e L) [5 \* o#include <PROCESS.H>
9 G8 ~+ p6 _( O, M#include <STDIO.H></FONT></P>
6 ?' v0 I; A+ F& G8 X y<P><FONT color=#0000ff>int main(void)
' a1 \5 b8 E$ s# S, R- j- p{ 8 n' e& X1 v( I
char filename[80];
, T$ }4 ]- L4 [7 l m1 d( q( tunion REGS inregs, outregs;
" G8 ]8 p3 N. m2 y% s" Gstruct SREGS segregs; </FONT></P>
( p* G3 X2 U% A I2 v/ A) `<P><FONT color=#0000ff>printf("Enter filename: "); / j% p1 W1 V! u* A% K! I
gets(filename);
0 x! ?/ V; f; z+ |inregs.h.ah = 0x43;
! w5 `; }0 x. A# _inregs.h.al = 0x21; 1 j: |+ j8 C/ R B
inregs.x.dx = FP_OFF(filename); ; Z5 W( I _- N. Z% B
segregs.ds = FP_SEG(filename);
2 p6 Z3 t$ C8 w7 z% H/ cint86x(0x21, &inregs, &outregs, &segregs); " X P% w9 p' @! I: w2 s
printf("File attribute: %X\n", outregs.x.cx);
! i8 H* W+ u+ z; Y" l5 i) i. _return 0;
' J; x* k4 i1 K! ~2 e} , M6 q+ G$ S, E- W% F" b
' L5 m* Y1 W6 E
</FONT>* b8 N% u) h6 P
</P>
! M3 K- d. }: I" ]) Q+ G9 B3 g<P><FONT color=#ff0000>函数名: intdos </FONT>
8 H" I, v2 ^( V# u' f功 能: 通用DOS接口
& a5 }. W3 h! d用 法: int intdos(union REGS *inregs, union REGS *outregs); 9 k, b; G+ K/ y1 |" p; C
程序例: </P>
, v" R# l/ z/ f1 Y<P><FONT color=#0000ff>#include <STDIO.H>8 Q0 g) q: @1 f; Y) x3 Y8 P+ h* b
#include <DOS.H></FONT></P>
0 R4 U' Y( ~# { b! D9 T$ ~<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ " \' \7 h' K3 N
int delete_file(char near *filename)
) B5 Z- c& `+ ~3 S1 u9 Z{
6 M' H2 v, W* ?union REGS regs; 4 W. j8 B2 T; v8 k- U
int ret;
% X* j+ X+ y) I7 y! l6 vregs.h.ah = 0x41; /* delete file */
# x( s2 `# o6 V/ p, r. Mregs.x.dx = (unsigned) filename; % k; D) v% p1 F/ F# O' M8 u1 X
ret = intdos(®s, ®s); </FONT></P>/ J% Z1 [' ^+ S' o* F" u: r Z/ e' c
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ # H* ~) [& K. G7 p" t7 Q0 }
return(regs.x.cflag ? ret : 0);
/ c3 I8 [8 [7 F l/ J2 W" e} </FONT></P>& p8 {0 ~$ T1 B; \& G# o: b9 d" i g
<P><FONT color=#0000ff>int main(void)
2 h. D! @3 I+ c& `6 \. l{ 5 y) P# Y* W9 d2 X. Y
int err;
) T1 Q+ A0 t: ^8 U/ F9 `, a* qerr = delete_file("NOTEXIST.$$$"); , T9 d" b6 d* m
if (!err) $ f; t" Z2 t* d7 x
printf("Able to delete NOTEXIST.$$$\n"); 7 P0 I% j% g0 S5 Z0 G4 u6 _
else
7 X, f9 n f4 zprintf("Not Able to delete NOTEXIST.$$$\n");
$ ?* W' S6 b4 l! }& {& Ireturn 0; 3 h) D, W/ q5 Z0 K' S( I- N4 X
}
0 f6 O' N$ l3 ^) i
8 _$ w" r# T; \, }. P' |</FONT>4 P g+ C$ j8 \! r' @
</P>
- F. t. |! `# _( b+ y<P><FONT color=#ff0000>函数名: intdosx </FONT>/ h3 B/ m* V2 q, D6 q5 Y% F4 ]( d
功 能: 通用DOS中断接口 8 b. ~: O+ ~: ` q( a% H3 O) P
用 法: int intdosx(union REGS *inregs, union REGS *outregs,
8 N8 @4 m" e+ N: P9 cstruct SREGS *segregs);
# {/ _+ U- O; w/ a3 e2 j, h程序例: </P>
5 U/ ~1 M3 X; M9 c<P><FONT color=#0000ff>#include <STDIO.H>3 K3 |) Y2 t- [
#include <DOS.H></FONT></P>
+ g' c# N- ]+ N6 n) ?, |<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
% j0 e+ ~; v4 `& |int delete_file(char far *filename)
9 a6 m% ?1 r+ `& k5 K8 n{
0 f6 y+ ]% q: w: |1 k1 k: X" s0 junion REGS regs; struct SREGS sregs; # v8 o. u ?6 u' z0 g
int ret;
, p* B$ @, g; X1 ~ Y1 M+ ^regs.h.ah = 0x41; /* delete file */ & J1 p2 V+ ?) c: B# w3 L8 H
regs.x.dx = FP_OFF(filename); ) A/ C% f/ m9 H6 i
sregs.ds = FP_SEG(filename); * h1 c1 H* h( Q+ p& S4 o
ret = intdosx(®s, ®s, &sregs); </FONT></P>; u; F: s. q7 E. V, B a+ @! L# }
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
8 {' b. ]* N& \7 T/ s6 U. ^return(regs.x.cflag ? ret : 0);
. H+ L# l( _9 N7 o} </FONT></P>0 C" L; a# `/ v( y
<P><FONT color=#0000ff>int main(void)
* u, O- O, u+ y) T{ : G( ~& Y9 H# _1 v
int err; , ?% V' o. a) c
err = delete_file("NOTEXIST.$$$"); - {- V% k6 F& Q7 G3 b8 `! p, k
if (!err)
; d3 b# n, Q! @+ bprintf("Able to delete NOTEXIST.$$$\n"); 1 B7 L5 p& o0 Z4 q7 G2 v! j
else - ? {& a- O+ b" g
printf("Not Able to delete NOTEXIST.$$$\n");
. m+ f- L0 g( @3 x: I) y: j2 e# Hreturn 0; 1 y f" M( a# i0 E- l
} 5 Z! _( s' x K* b
</FONT>
?& O* m! k6 b( D* I</P>
$ z0 Y" x0 ^1 S; C<P><FONT color=#ff0000>函数名: intr </FONT>
3 ~7 Z' }, `8 r功 能: 改变软中断接口
) G! E6 `/ j8 p/ Y' ?! d. S用 法: void intr(int intr_num, struct REGPACK *preg); 7 E# g; j& x/ Y/ e8 p- Q5 \0 S+ @
程序例: </P>
, ^8 {% {7 U9 Z" X<P><FONT color=#0000ff>#include <STDIO.H>
! \" ]( `* M- k* C+ J( f. i; F#include <STRING.H>
* p- W8 u! `3 o0 ~#include <DIR.H>
0 \6 P4 b. O, ]4 _- O#include <DOS.H></FONT></P>$ e. @" W; v6 F: a
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
# G/ O4 g) ]* { z- c$ m<P><FONT color=#0000ff>int main(void) 1 @ }- A0 G6 X( |# x
{
( x* u$ B' r1 t$ O/ f5 B$ V2 a ]$ Mchar directory[80]; 6 U" N2 i8 I, B
struct REGPACK reg; </FONT></P>
5 y! j' K& g9 }# y/ T6 Q<P><FONT color=#0000ff>printf("Enter directory to change t ");
+ Q5 n7 x5 E! u" k+ s/ mgets(directory); 3 V: M1 {4 ] ]: @- s
reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */ : D. D5 n% p( V, G" r& Q
reg.r_dx = FP_OFF(directory);
: A& I0 D/ l& L1 P8 @4 w, }- |) Sreg.r_ds = FP_SEG(directory);
8 h" Z) B1 d, x: ^$ ~' r$ vintr(0x21, ®);
* C" Q5 E( V, }2 zif (reg.r_flags & CF) , j; \- ]% b1 l0 V7 P8 q9 b
printf("Directory change failed\n"); - d2 F' l. Y) s. I& H
getcwd(directory, 80); , `6 {8 C; |$ z+ }
printf("The current directory is: %s\n", directory); $ | L2 F$ N9 ^% Q9 D' p6 ]
return 0; 6 v" @4 ~$ w, J
} ; o J9 W- O) ?" R
</FONT>
& U% ]* W6 J V0 r& u</P>
. @: o, e |2 _% r: x<P><FONT color=#ff0000>函数名: ioctl </FONT>+ O0 [9 F; h* ?/ _6 a- \# W( o
功 能: 控制I/O设备 ( }( C, |7 Y* R8 V! @1 |$ b3 h
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); - e1 @8 e/ s) t! _5 t3 ?
程序例: </P>
1 |( j! H) y% x# S/ j<P><FONT color=#0000ff>#include <STDIO.H>
, M/ ?+ W) n0 R3 D% j# G3 \& k, r#include <DIR.H>3 M6 Z* p) w4 ^- ~& b5 s
#include <IO.H></FONT></P>
G) _, f2 w; v: S. W0 I Q* T<P><FONT color=#0000ff>int main(void) # v }& R V: L) a. x
{
# f) V2 B* H* A# o. Aint stat; </FONT></P>
8 K: m8 T4 A0 S# N. z<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
7 B/ n! p& _- T) d+ Mstat = ioctl(0, 8, 0, 0); : [1 s) u5 j; ^2 d9 r# m
if (!stat) 4 q1 M, l A# |9 a5 e% o z0 y, y
printf("Drive %c is removable.\n", getdisk() + 'A');
2 a( b* Q5 w, helse 6 R+ ]- r( }4 O+ ~/ p+ C
printf("Drive %c is not removable.\n", getdisk() + 'A');
. b& l V5 Q. ^. x( Rreturn 0;
% I) i; h1 @1 f* T6 k+ @}
6 E" t5 Z' t3 Y$ C- k% q
+ A. {0 t: e- u</FONT>
* ?& j- h, k& r' S y; l8 r$ q</P> ^. S8 E" |4 @* l! P0 z
<P><FONT color=#ff0000>函数名: isatty </FONT>3 i: i$ w: Q" M0 L4 T! {
功 能: 检查设备类型 ; e/ ~0 A3 I" F0 d# H- ?
用 法: int isatty(int handle);
* {5 }1 q9 I& E2 L) z程序例: </P>
& |) b3 j: r8 B$ d% `+ P+ q7 `- ], F4 q<P><FONT color=#0000ff>#include <STDIO.H>
/ @5 }+ F2 Y* x* ^% J( L: S0 y#include <IO.H></FONT></P>
* Y7 A, Z) [$ F1 o" w! Q6 l<P><FONT color=#0000ff>int main(void) / e1 |7 Z( v: p$ A8 y6 ^
{ 7 W! s! O, [8 O) j f
int handle; </FONT></P>; @5 \3 y3 I* l; G1 ?6 J
<P><FONT color=#0000ff>handle = fileno(stdprn);
' x* \$ w8 I- @. t7 _1 I2 I: a& oif (isatty(handle)) : I: ^0 R7 W/ a
printf("Handle %d is a device type\n", handle);
% R$ x: z. h& @3 h' y- Yelse
8 o$ t7 |5 j8 h/ s+ ^+ u# E5 V% ~printf("Handle %d isn't a device type\n", handle); 8 P2 J2 F* ]9 j J6 y0 L6 {
return 0;
' _/ w& {9 B, x" t}
+ S- P4 g" K* \1 e$ R- O2 y4 C6 r# |( R
</FONT>
" D- H* B/ R; o5 w</P>
' C, }& F: R6 A7 \ z6 Y0 z) b<P><FONT color=#ff0000>函数名: itoa </FONT>
3 l3 X7 ^) N9 a- B1 L0 G功 能: 把一整数转换为字符串 / S9 o. j1 [8 Z9 A3 J8 R
用 法: char *itoa(int value, char *string, int radix);
! j9 D+ }+ A5 ]8 c程序例: </P>
; _$ `+ o! I6 c4 u- g' h& b<P><FONT color=#0000ff>#include <STDLIB.H>
# L. g( k4 M: E0 S/ F#include <STDIO.H></FONT></P>
K* q& f* S# O: `<P><FONT color=#0000ff>int main(void) 4 G* _2 w5 x; I8 m1 Y' K! z7 {
{ ; K1 x6 m& K0 ?( j; k8 P: B
int number = 12345; ! j |4 z. w0 [
char string[25]; </FONT></P>4 u( D, t. j, A
<P><FONT color=#0000ff>itoa(number, string, 10);
8 r/ r' e2 j. o, F2 v Uprintf("integer = %d string = %s\n", number, string); - R; Z: v/ |4 r( \/ z; G& V; A3 k- @4 z
return 0; " b$ x/ f3 d$ M; i
} </FONT><FONT color=#0000ff>
5 ]. W3 d( M8 q1 B/ M</FONT></P> |
zan
|