- 在线时间
- 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>3 Z& H% `) k/ E+ g1 W3 S2 T5 m
< align=left><FONT color=#ff0000>函数名: imagesize</FONT>
$ S* I8 \* |) k& C& z8 f功 能: 返回保存位图像所需的字节数 L) X; y3 K# B& O6 c
用 法: unsigned far imagesize(int left, int top, int right, int bottom); % s& b1 e$ h6 w+ M/ z
程序例: </P>
2 o& F2 B0 y2 ^" f% _: |< ><FONT color=#0000ff>#include <GRAPHICS.H>
7 ]. P: I8 V& p/ V#include <STDLIB.H>7 M; D) W4 Q) W# ?
#include <STDIO.H>
4 O$ K# P* D+ u$ S# i#include <CONIO.H></FONT></P>
' U4 Y' r& l& T1 R8 B9 F< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>9 A" d* K# h$ k" l' m8 b
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>5 X$ G# e o6 X
< ><FONT color=#0000ff>int main(void) : T( o [% Q' [* m. ]
{ 1 v2 E6 s6 H0 D0 ~0 w
/* request autodetection */
: S X5 A1 J6 y# s2 W( dint gdriver = DETECT, gmode, errorcode; ~. ^# P- g8 g* U- t; t9 P) @) o
void *arrow; - Q0 D( z, t, J3 I! e& t
int x, y, maxx; 9 n" r0 ^# ~* G; [- S3 l1 w
unsigned int size; </FONT></P>
& d/ D/ Z' I ]% G< ><FONT color=#0000ff>/* initialize graphics and local variables */
! w5 K. ^! A, f% Binitgraph(&gdriver, &gmode, ""); </FONT></P>, o" D7 M g$ g( u. I- f# {
< ><FONT color=#0000ff>/* read result of initialization */
6 Y4 d6 B$ k( U% {1 x, gerrorcode = graphresult(); 2 n1 M3 }% w$ P u2 Y
if (errorcode != grOk) /* an error occurred */
* v I' c5 x7 X" j5 R{
$ g& l' S5 l- t, b4 K# iprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * q" E+ ^ r8 {2 b
printf(" ress any key to halt:"); # E, i" \* T; E2 f0 Q$ ]# \
getch(); * U6 G4 @: _ U7 h3 f- D$ s* |
exit(1); /* terminate with an error code */
$ o5 v. l/ |, d} </FONT></P>
9 S1 q% G. _6 m/ O( |< ><FONT color=#0000ff>maxx = getmaxx();
1 J* F. W7 D( |0 ^x = 0;
# P# B. ]' O9 K6 E' F% Q) O) E4 {y = getmaxy() / 2; </FONT></P>
) M3 h$ r, I: H5 F7 `1 o2 y< ><FONT color=#0000ff>/* draw the image to be grabbed */
E/ k) O0 g6 l2 W( W% \$ {draw_arrow(x, y); </FONT></P>
& p5 C2 A( A- {( D: M- r) H< ><FONT color=#0000ff>/* calculate the size of the image */ ; f' k8 U7 n" e' n% }
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>8 x9 M" Z, D# {) @
< ><FONT color=#0000ff>/* allocate memory to hold the image */
, x3 c/ Z# h4 O5 M, u% Darrow = malloc(size); </FONT></P>* f3 l) m' K- w! N- H/ p
< ><FONT color=#0000ff>/* grab the image */
( a6 P& l1 _, M# U# p6 Agetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
% D# b& H9 U% P2 n* Z4 T. @< ><FONT color=#0000ff>/* repeat until a key is pressed */ , o6 x% S; g0 ?8 u! A1 A' M+ h
while (!kbhit())
7 B! g5 v+ G/ g- p4 N4 U{ : T+ z& c- Q8 `( u
/* erase old image */
2 b; A) A2 h7 _ \3 O Vputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
# d9 n" `& R/ @& `" `4 @" c3 `< ><FONT color=#0000ff>x += ARROW_SIZE; 6 ]9 K3 N$ c6 L3 u
if (x >= maxx)
: y* f% c7 I3 O6 j: wx = 0; </FONT></P>
/ x* f$ s( C* ^- R" J e' D< ><FONT color=#0000ff>/* plot new image */
9 J3 W7 S& n0 ]8 t! hputimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
$ w, V. b& @/ K, Y5 c5 R* [} </FONT></P>
* K. a- I1 h) E' J) z0 e% b/ F< ><FONT color=#0000ff>/* clean up */ " A8 C; S2 ^0 H7 l# K
free(arrow);
9 V) l' T4 r8 O X- xclosegraph(); , ~+ M6 e& B+ d/ f1 ]( y
return 0; % `, N% P7 h. |. l* U) {% x. [* f
} </FONT></P>0 r) _9 G0 K! l6 ^9 J, @
< ><FONT color=#0000ff>void draw_arrow(int x, int y) " O/ y# P4 _% J8 u" D
{
% d3 q$ z9 w' a+ d" @0 \3 U$ _" ~/* draw an arrow on the screen */ , d4 H& M! R9 W) h
moveto(x, y); - z- R/ E+ x% k- I1 y
linerel(4*ARROW_SIZE, 0); 4 Q+ _% X. ~, j
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
$ M( h1 O; g) f) [. Blinerel(0, 2*ARROW_SIZE); / u1 O2 C( r: l6 c; _! c$ Q& z
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 0 `3 @0 r3 N) F5 I4 x3 o1 w8 F/ C
}
" R* y1 A$ W \* r. D; I
$ c) p4 D( d/ u& ]( A, G9 x a( K6 h7 Y6 l8 |+ Z
</FONT></P>
9 K) W O* p& J" s. H< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
3 i4 C2 w& d5 y4 ^<FONT color=#000000>功 能: 初始化图形系统
* b# c" p9 y; ^$ o% J用 法: void far initgraph(int far *graphdriver, int far *graphmode, 7 v# k) Q% O6 b- b4 k. v) W& }
char far *pathtodriver);
; ?6 p" c, B, A+ j1 `: w程序例: </FONT></FONT></P>+ \! @# q' a2 r5 X. Q
< ><FONT color=#0000ff>#include <GRAPHICS.H>
% \# f/ [! c9 R: c0 U( _#include <STDLIB.H>
( B5 l }" E3 ^* O0 l3 u3 H#include <STDIO.H>0 v! Y9 A& B) G: I, n; K
#include <CONIO.H></FONT></P>
2 E5 K5 p" q9 I< ><FONT color=#0000ff>int main(void) q! D) e1 E! h1 i. P2 Y7 [# F
{ 8 b: L* t# Q; S' t4 C* W; Z# S
/* request auto detection */ % C1 s7 ?6 X7 b$ ^4 C
int gdriver = DETECT, gmode, errorcode; </FONT></P>6 a7 ?2 ~: P' K* H/ z8 R: M9 G
< ><FONT color=#0000ff>/* initialize graphics mode */ ' q2 Y0 m7 B! Z; _
initgraph(&gdriver, &gmode, ""); </FONT></P>
/ f! H7 |7 \, N5 A$ A) j< ><FONT color=#0000ff>/* read result of initialization */ 7 ^! K* A+ b# I- m G
errorcode = graphresult(); </FONT></P>( k+ b2 z5 k) z
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
6 s' T6 K5 _4 X8 x5 w{
% Y3 H u% p& Z% a. r1 m) eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
`) a4 c2 q0 e- w/ Sprintf(" ress any key to halt:"); + H& l- @) N( U' ]0 E& f( g, `
getch();
" J, b! j, T2 s& hexit(1); /* return with error code */ . v$ W% ^# r2 C8 {3 D
} </FONT></P>- @; M+ ~% E7 A! H
< ><FONT color=#0000ff>/* draw a line */
) X; N Y% P3 o; L5 {7 hline(0, 0, getmaxx(), getmaxy()); </FONT></P># D/ @+ L$ i r. d
< ><FONT color=#0000ff>/* clean up */ 8 ^8 K% {' i: m& c$ q- r
getch(); - w! ]$ B% C9 I
closegraph(); 1 R N- X: C; c/ @
return 0; . i" `; L' [' x5 R1 a4 u
} </FONT>/ L* b1 r" Y- x' j- C3 f( ?
+ S% ?0 d$ P/ \8 i9 |% \, p$ H: z
</P>
; b8 U( ?( q* s9 z% n- M3 S< ><FONT color=#ff0000>函数名: inport </FONT>
9 \. X/ b* ~2 [, |功 能: 从硬件端口中输入
# ?4 b7 G+ w0 ?1 Y用 法: int inp(int protid);
0 I/ x$ x1 O3 E4 k( Q程序例: </P>% _1 z) f$ q. Q/ s+ [
< ><FONT color=#0000ff>#include <STDIO.H>: [& w; h0 J+ o; G
#include <DOS.H></FONT></P>
: F% C' J& V3 ?: r/ R; s8 d4 Y<P><FONT color=#0000ff>int main(void) Y( W# X+ L- R
{ $ @+ o* ?# `$ ]2 n h8 e" p
int result; 0 L- G# p& Y9 e8 N Q5 o4 {
int port = 0; /* serial port 0 */ </FONT></P>
, Q$ S1 ~) N# y. n+ X% _* ]<P><FONT color=#0000ff>result = inport(port); 0 |4 E# i6 m7 n" p% V, ^
printf("Word read from port %d = 0x%X\n", port, result); / L3 q2 R8 ~7 R, d+ w5 M# |
return 0; 1 Y+ C5 O/ `; Y: J8 K' B
} , h8 I8 j5 P3 p/ O$ p( M
: c0 r; \( }% w5 e9 x
</FONT></P>
3 Q7 v4 {4 |$ B* S, n<P><FONT color=#ff0000>函数名: insline </FONT>
+ o( x, E* c+ `" R% a+ d功 能: 在文本窗口中插入一个空行
, x+ _ J/ E0 R6 N5 j* b. U用 法: void insline(void); 0 l% Q6 z7 U: Z! ~ n2 u( P d
程序例: </P>
+ I5 `; F: ^8 A' X$ m<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>. Y) H0 G7 r9 I6 X
<P><FONT color=#0000ff>int main(void) : }& E* Q& `3 u1 a7 T4 d/ S
{ . ?9 q' h7 Q+ E
clrscr();
' f: i" y' N: G' Z+ P; d, E' xcprintf("INSLINE inserts an empty line in the text window\r\n"); ' e* O8 {8 O# {7 k5 ]( o& X0 ~
cprintf("at the cursor position using the current text\r\n");
5 k0 O1 ^* o8 J/ V6 Pcprintf("background color. All lines below the empty one\r\n"); : w$ ~' T% `& ^7 z0 m" f( p
cprintf("move down one line and the bottom line scrolls\r\n"); 4 |) Z" e& ^) p* j6 j
cprintf("off the bottom of the window.\r\n");
8 t8 {0 k* W7 D- h" T7 U9 P' A2 i! ecprintf("\r\nPress any key to continue:");
- O1 T7 s! m. ?% b+ H! Kgotoxy(1, 3); % z8 [, K. \0 B: }- O r
getch();
6 O8 _! P3 q5 _& M4 U3 V/ Binsline(); ; p% l4 D3 L4 ~
getch();
2 }/ U) x' B* Y; [9 |3 |: A7 e6 Areturn 0;
' _" K [: z, M$ B5 `% a3 l}
S5 m9 h4 Y! ?" W0 w: ^. ^0 P</FONT>
: N5 B: B) t1 k2 \0 J: r; [
; b4 ^, k9 D! p4 `( L</P>6 e" _- X8 p7 n+ h I
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>2 R. c5 h& ]! z& k
功 能: 安装设备驱动程序到BGI设备驱动程序表中 ) D! {5 V/ f! v9 J, u, h" ?& `
用 法: int far installuserdriver(char far *name, int (*detect)(void)); 2 z' h3 g3 l; C" D
程序例: </P>+ L& w! r; W8 k: k% N* s
<P><FONT color=#0000ff>#include <GRAPHICS.H>
. g7 t0 H' u5 l#include <STDLIB.H>% T6 g3 v+ T- |& X% @
#include <STDIO.H> W! a4 M+ h+ Y( I
#include <CONIO.H></FONT></P>. G% g! A9 k" [ N' E
<P><FONT color=#0000ff>/* function prototypes */
& B0 \: `! A( pint huge detectEGA(void);
j. v& B/ I. [- pvoid checkerrors(void); </FONT></P>
$ m, o* J0 ~, p9 E* Y6 {# Q% o<P><FONT color=#0000ff>int main(void)
0 U3 d- ~8 D' d+ e{
% p; w0 J- k4 P) gint gdriver, gmode; </FONT></P>
2 y1 y' Z; Q t c3 y8 J* M<P><FONT color=#0000ff>/* install a user written device driver */ 0 Q* V2 A* e1 V' {
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
4 j2 u* t$ K# _6 a& H& w! X% T! Z<P><FONT color=#0000ff>/* must force use of detection routine */ 5 B {3 N6 W* u& ~
gdriver = DETECT; </FONT></P>" L$ @2 ~$ W/ T c, H3 _# N
<P><FONT color=#0000ff>/* check for any installation errors */ , C, n; ?4 H0 M8 W
checkerrors(); </FONT></P>& U: U7 d( ^! _
<P><FONT color=#0000ff>/* initialize graphics and local variables */ * ?( F2 T M) k6 f2 ~8 B2 }
initgraph(&gdriver, &gmode, ""); </FONT></P>( _- I- Z4 H) k8 w& [1 W
<P><FONT color=#0000ff>/* check for any initialization errors */ 6 V/ t" L% c9 T; B
checkerrors(); </FONT></P>
8 t: L- n( x; L+ [' T7 m<P><FONT color=#0000ff>/* draw a line */ 1 g2 u- F4 u' c/ \8 s% y0 X
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
! H- w6 m H8 q( q4 |<P><FONT color=#0000ff>/* clean up */
1 r. ]# M" N# lgetch();
2 A3 @0 W+ |/ s2 a- Hclosegraph();
( p# \) y. |9 s4 a4 {( Sreturn 0;
* L) s `1 K7 m" N; o6 M. S$ j/ n} </FONT></P>
, ~: n- f: d$ m, E& i$ I, X. I<P><FONT color=#0000ff>/* detects EGA or VGA cards */ 0 n" u0 C* i' O& V2 g
int huge detectEGA(void) ' U; y- L, e7 Q# r$ ~8 C7 Z0 P3 c
{ & | s, J8 p7 g
int driver, mode, sugmode = 0; </FONT></P>
3 b: x0 z6 b# E0 w0 e<P><FONT color=#0000ff>detectgraph(&driver, &mode);
- I- }) F/ ] {if ((driver == EGA) || (driver == VGA))
9 m/ W, K) h' s7 c5 h4 X. R, f/* return suggested video mode number */
0 Z! ^' i" n; breturn sugmode; " T: \7 o0 p( S2 x
else / Z) B+ P, M4 b. N
/* return an error code */
1 {$ A) w$ L2 e( e( {return grError; / }: v6 b) k2 a' \
} </FONT></P>
# h# Y* B7 V. D6 J; P% L<P><FONT color=#0000ff>/* check for and report any graphics errors */
, F* g' P+ O$ C( ^" D# A3 Z8 Vvoid checkerrors(void) 5 C) K4 @+ I6 y! G# i! t
{ ' o0 ]; @4 ?+ w) F( z# F1 U( c
int errorcode; </FONT></P>
; P0 |7 K8 O4 }# `/ Z6 P<P><FONT color=#0000ff>/* read result of last graphics operation */
# p. B' P; D; U- l2 n* Xerrorcode = graphresult();
3 m0 c* I. S: G8 X/ T! h. vif (errorcode != grOk) 6 v# P {+ l4 P f
{
3 Y! P1 B, k6 R, S+ X2 U$ |7 n/ Uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 w$ m/ M& _* l/ q2 ?* F1 bprintf("Press any key to halt:"); # l/ E, s/ ]) S6 l9 T" X
getch();
) S: \+ }, l1 p1 r" r! C8 }exit(1); : K: x% s; I' l8 h9 A! S
}
2 v: s5 k$ O1 ^} </FONT></P>
9 ]) Q' O" N1 d" k; Q9 w1 |- I) P<P><FONT color=#ff0000>函数名: installuserfont </FONT>& D s. R# L! B
功 能: 安装未嵌入BGI系统的字体文件(CHR)
8 x" H* l$ T- |( @用 法: int far installuserfont(char far *name);
2 O5 X3 q/ g2 H, X2 \" f9 F程序例: </P>9 l5 i6 i& @: m8 F; |8 m) x
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! N, ]) b9 b- R! P9 W#include <STDLIB.H>
( R6 b& @8 K# ~# }#include <STDIO.H>
c. t8 P! t' ] ?" ]5 Q#include <CONIO.H></FONT></P>( f2 w/ q7 j+ V: I, }5 X& i" M5 A6 x
<P><FONT color=#0000ff>/* function prototype */
) M4 s* N9 Y4 }, D# evoid checkerrors(void); </FONT></P>
4 v3 q/ E, Q m4 O# v<P><FONT color=#0000ff>int main(void) # R3 h% U2 P7 _: }# v
{
) b7 X7 Z) A( | w# N/* request auto detection */ ! N" B' l2 R$ T9 v' _! H h
int gdriver = DETECT, gmode; . {% p" v4 V. x3 |+ _0 [
int userfont;
9 Y; q2 k7 p) b2 ~; m: R$ W1 j% z! `int midx, midy; </FONT></P>
/ L7 u6 L, J; g( F. f<P><FONT color=#0000ff>/* initialize graphics and local variables */ " Q) ^$ k8 ?* N0 ^
initgraph(&gdriver, &gmode, ""); </FONT></P>
8 L: {1 N5 O( h2 {+ q4 G; i<P><FONT color=#0000ff>midx = getmaxx() / 2; - S* r* A" O; ]. {6 A
midy = getmaxy() / 2; </FONT></P>
s8 [8 l7 d% C) \4 k4 H3 t<P><FONT color=#0000ff>/* check for any initialization errors */
& |# O' E6 s/ L' wcheckerrors(); </FONT></P>. N7 s4 u+ B5 `: Q
<P><FONT color=#0000ff>/* install a user defined font file */
$ _5 e3 \: r2 O/ D- Q4 u- |5 iuserfont = installuserfont("USER.CHR"); </FONT></P>
0 S+ f$ `: B# r1 ]- \; C w<P><FONT color=#0000ff>/* check for any installation errors */ " z a+ W- Z7 h! k
checkerrors(); </FONT></P>8 M( u4 m+ [4 P# l1 e
<P><FONT color=#0000ff>/* select the user font */
" [2 D6 r4 f, l: k* Gsettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
4 M% X% s% ~, ?' x4 e0 A<P><FONT color=#0000ff>/* output some text */
3 y+ A7 R( F# l, g# ^) Z7 mouttextxy(midx, midy, "Testing!"); </FONT></P>
2 s( I! n4 p7 l/ P<P><FONT color=#0000ff>/* clean up */ * B: y$ h; h* B
getch(); 3 u$ I9 X0 a* T( O4 O
closegraph(); 2 K7 C# A4 a, g9 L2 N
return 0; 1 b: M; r0 F. m, K- j
} </FONT></P>. W1 e8 G2 v9 u: y, T
<P><FONT color=#0000ff>/* check for and report any graphics errors */ % \7 Q2 B" g! o4 Q* ]. R. p
void checkerrors(void)
( Q k+ r+ b# M1 S8 [% c5 g" b/ L{
/ f: e9 h* E. x h! Eint errorcode; </FONT></P>
# @# b. d2 n/ U<P><FONT color=#0000ff>/* read result of last graphics operation */ ' I: y ?2 }. g* \* G3 e* ^1 Y
errorcode = graphresult();
! a0 J: b/ k. {4 bif (errorcode != grOk)
# {6 T9 y7 P. w; a{
, @: h7 \* z8 p9 Tprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ [7 z9 |9 e0 K* L' H0 @
printf("Press any key to halt:"); 4 Z, i* @" ^7 Y/ \4 U
getch();
4 l& ]( [% f- s! k& }1 Nexit(1); , | |5 Y, g/ U6 r/ @
} 8 n3 `) ]* S4 x& Q9 o6 ?' p
} </FONT>
* ^# x: ~5 ~" Q+ C' L0 q! g. s' L; h5 T0 ?$ X, t# b. r
" J5 k6 p, n5 u& \
</P>
) a7 M& [0 U6 [; P<P><FONT color=#ff0000>函数名: int86 </FONT>
# E( W! A4 t' u5 B% x功 能: 通用8086软中断接口
% x6 ?; H, O$ |) R9 U1 T用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); / v. M0 i: \- ?) O$ W- E
程序例: </P>
- f. J& _$ V2 \) c<P><FONT color=#0000ff>#include <STDIO.H>
2 T, P9 W; T& N; k: E4 h#include <CONIO.H>
9 H2 k( i9 f* ~% @' e#include <DOS.H></FONT></P>
4 W" `0 \. x! M8 u<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>; Q7 `, m3 s8 v2 y
<P><FONT color=#0000ff>void movetoxy(int x, int y)
0 b$ v1 ^& f3 O7 ?# u3 @" M{ 8 X- c# x# B* [/ y# k
union REGS regs; </FONT></P>$ s1 ^- t( c% R, u0 C
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
" {' y, W# ?9 V) o$ ]1 Q, fregs.h.dh = y; ; ?, ^! x/ t6 Z3 c$ F; q9 p
regs.h.dl = x;
2 ?2 @& h+ D2 k) c' @regs.h.bh = 0; /* video page 0 */
+ l/ e; Q, m; L1 k0 L. V4 R4 w8 hint86(VIDEO, ®s, ®s); g7 Z2 h2 B: }) G; Y. k
} </FONT></P>3 S D2 M4 h0 V
<P><FONT color=#0000ff>int main(void) * u5 m+ y; c3 F4 q2 |
{
) G0 |. C2 T" q/ M% dclrscr();
8 \) G. {$ i! Cmovetoxy(35, 10);
4 B' y+ s, a$ j, Nprintf("Hello\n"); " v' A" b' V. w; r0 j
return 0;
. M' O, D7 X3 ]7 c/ v} </FONT>
/ k, s6 `/ o8 \% L* v6 j/ h4 Q; p! p2 Z3 y
</P>
V5 ^) x% Z; C$ q<P><FONT color=#ff0000>函数名: int86x </FONT>
5 v( `: [" E0 C% B功 能: 通用8086软中断接口
0 E6 O* C6 V+ u; q+ y e用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, , F* q: Q- N8 ~
struct SREGS *segregs);
1 ~ d9 _; H5 q程序例: </P>
! ]: ^ U) ^: K1 ~ x5 p+ [<P><FONT color=#0000ff>#include <DOS.H>
) F q7 d8 O7 g; K$ h& ~#include <PROCESS.H>; q$ Y4 E+ [# r( [/ c
#include <STDIO.H></FONT></P>
- r+ _/ J8 i# g& w6 J/ Y' y- J<P><FONT color=#0000ff>int main(void) , F N+ G7 _, c+ k" ?' T
{ 8 S7 E2 `0 ~" l9 K0 _3 r0 E
char filename[80]; ; Z2 o# `5 H9 i+ y" e7 a+ |
union REGS inregs, outregs; 9 o7 E5 _& p y( t
struct SREGS segregs; </FONT></P>
) i" U& @1 D/ G. P<P><FONT color=#0000ff>printf("Enter filename: ");
2 `( h* B9 C3 H* Kgets(filename);
! D, W6 }7 ^* x7 O& N/ [1 u- \inregs.h.ah = 0x43; + I" J7 } w1 n/ h# O8 z) n
inregs.h.al = 0x21;
/ t1 s& e" j+ i. r b' `9 Vinregs.x.dx = FP_OFF(filename);
; V( @1 Q9 L5 n1 c+ b) u+ z2 |segregs.ds = FP_SEG(filename); 4 V! A" S# }0 C& Z, Z) |
int86x(0x21, &inregs, &outregs, &segregs);
8 `/ p; B* Z6 e1 P& A& p7 ]1 o; Hprintf("File attribute: %X\n", outregs.x.cx);
( x( }2 U2 [& T0 x Creturn 0; " ]! s0 Z/ f2 ~% B; H
} 2 z9 j1 H+ L0 c: t! s
* ]5 ?/ b" }2 j; X' o</FONT>5 n4 D) k0 j3 w6 m
</P>
3 T: ^' Q' d6 w; O5 H2 i8 G<P><FONT color=#ff0000>函数名: intdos </FONT>
9 P/ L+ H# w( z2 i功 能: 通用DOS接口
$ O' j F/ V! V* a! b用 法: int intdos(union REGS *inregs, union REGS *outregs);
* ?, `' I4 \) c2 C4 P* z程序例: </P>: d, \7 \) @ k B) Z7 c
<P><FONT color=#0000ff>#include <STDIO.H>/ U8 M/ p: f5 H4 V: Q& ^0 z6 u
#include <DOS.H></FONT></P> l; T% p& |3 G: Y: {$ q, ?6 y# u. @
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 4 b& z/ V" p/ Q' h g
int delete_file(char near *filename)
2 l* x. v, E$ W7 W; `{ ; ]+ T( Z% ]$ F: X L
union REGS regs;
2 Q- c- J: H* Z( X4 K6 Lint ret;
; @0 I/ r4 c* ]/ Wregs.h.ah = 0x41; /* delete file */
9 B+ M2 _+ B/ L" ?& a4 \regs.x.dx = (unsigned) filename;
- `4 { N9 g% r% p( S. `ret = intdos(®s, ®s); </FONT></P>. a" ^% c# Z: R: n5 \
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
* ]$ L8 ~- V& t0 I7 creturn(regs.x.cflag ? ret : 0);
4 S( ~. C% y! V} </FONT></P>
, I# n7 q( Y" n* g<P><FONT color=#0000ff>int main(void) " S+ y4 `7 [: Y5 F1 I' G8 Q7 X
{ 7 N. F4 ?0 B* D' d5 x
int err;
9 [" U5 q( z) l$ w) e: a$ Werr = delete_file("NOTEXIST.$$$"); , {0 L, U9 |; m! J% O
if (!err) ! [% F) R" r! S
printf("Able to delete NOTEXIST.$$$\n"); $ i# U: K3 ?3 B6 [4 J }
else - p+ @7 m F% o) M! W% `4 |; L9 H
printf("Not Able to delete NOTEXIST.$$$\n");
( H% U7 ]$ Z% L9 Y' r# Breturn 0;
( h" s% ^1 b# T v! N& B} : L9 H5 O5 I( A \ \
; x* S7 b. z1 l% k0 b1 F
</FONT>
5 G3 |% m2 D( C7 n) V9 u</P>
, U( w/ G& |7 l( Y: }% R<P><FONT color=#ff0000>函数名: intdosx </FONT>
& |* z- y' ?1 {6 D& W, A功 能: 通用DOS中断接口 # L! b, ?/ d: T/ j; w, r
用 法: int intdosx(union REGS *inregs, union REGS *outregs,
( K* v* M0 O( S/ ~' E5 X; A. l9 sstruct SREGS *segregs); 7 k5 T, W) P# ~3 p4 a* F
程序例: </P>! z" n4 J3 e/ V( R; j" x
<P><FONT color=#0000ff>#include <STDIO.H>8 Y+ {3 @, E! t7 ^' O$ }
#include <DOS.H></FONT></P>8 \: f; X5 R! n8 j! [
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
6 t2 K0 F @1 W* f' K. Jint delete_file(char far *filename) 1 D8 T( M/ g: J6 D# ~
{
5 K7 n( w1 S8 o% N* v' ?, I" a' Gunion REGS regs; struct SREGS sregs;
2 V' `; \; B- ~: J! iint ret; + N) A4 o8 g1 G6 f. o6 }
regs.h.ah = 0x41; /* delete file */
7 G: L4 e# P) [5 ?regs.x.dx = FP_OFF(filename);
4 P. {" J, Y, c/ D7 vsregs.ds = FP_SEG(filename);
7 b6 r# R: V+ H# m* rret = intdosx(®s, ®s, &sregs); </FONT></P>
8 O) W) v; p% |: Z3 J" K* }: O1 M<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
" f2 B' o+ K6 D% yreturn(regs.x.cflag ? ret : 0); 4 R" Q4 @, M" }/ Q' G1 f4 q9 G
} </FONT></P>- ?1 f f0 S$ [4 i
<P><FONT color=#0000ff>int main(void) ) d6 ~7 C9 T3 m
{ 5 n) \9 ~0 Z0 s( u+ H
int err; 0 O: e. o. ~8 t
err = delete_file("NOTEXIST.$$$");
, T$ B' s9 s' R, E# Rif (!err) # @5 y7 k& D l6 H! X$ V5 s
printf("Able to delete NOTEXIST.$$$\n"); 2 X/ [ K. O" r3 f
else % f& ~ d# A# K' E7 Y6 X, c
printf("Not Able to delete NOTEXIST.$$$\n"); + @2 Z# q2 b- E* ?) b2 x7 O/ i
return 0;
3 Z3 Q7 o0 t1 ^}
4 f+ Y& l5 w" f% E4 I</FONT> Q/ Y5 Q/ u! F
</P>' `8 l0 O/ C/ l9 ~. }* v) q, c P
<P><FONT color=#ff0000>函数名: intr </FONT>: K" f. a1 H/ i
功 能: 改变软中断接口 2 R) `/ Z& _' V& ?* v
用 法: void intr(int intr_num, struct REGPACK *preg); / ~" e7 N& u3 A# ^+ d3 j; }, q
程序例: </P>
?% b) j; o, R; B5 K, T<P><FONT color=#0000ff>#include <STDIO.H>3 u! c9 {+ K+ z/ e6 R0 R* B; Z
#include <STRING.H>
9 B, V+ [! D& \# J6 ]/ l#include <DIR.H>
# f2 l' H8 ^8 C8 m#include <DOS.H></FONT></P>
; g$ o( ?1 R; }2 S<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>! [7 j8 t- \( U
<P><FONT color=#0000ff>int main(void) , V# }* M9 u" @# z
{ ) F4 y. Y- f' Q/ N1 X9 |4 o/ a+ ~
char directory[80]; / y( P! S& T2 d% P6 x, m& _, a
struct REGPACK reg; </FONT></P>
2 o7 i: n( m# N" N! s" X<P><FONT color=#0000ff>printf("Enter directory to change t "); ( @3 G1 J- d* c# }% }$ |* H+ O2 Q3 n- u
gets(directory);
9 ^0 O9 j; K$ K/ b8 K( @$ s% rreg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
' y0 z* M& Y+ y+ |# U& `reg.r_dx = FP_OFF(directory);
6 T) N G I0 ^! U0 ]reg.r_ds = FP_SEG(directory);
# O" ?' _/ [+ K2 |7 j Dintr(0x21, ®);
# X$ o" J' P( o/ e5 ]8 Tif (reg.r_flags & CF) ) d' E* N3 Q, M! E9 m; O
printf("Directory change failed\n"); / B/ ~: j( C: a( h; R+ y, C
getcwd(directory, 80);
) ?1 C7 v8 ~3 u% B) O( B1 C, o% ]8 Oprintf("The current directory is: %s\n", directory); 1 o5 H U: v; [( x: J# ^# \
return 0;
* s8 [5 n7 l% W7 L- u} 9 q E. ~3 }- q4 D' d. u, p* q3 ~
</FONT>
* L8 r- ~/ [! N B</P>- z2 X6 J1 p! F: [0 f5 A
<P><FONT color=#ff0000>函数名: ioctl </FONT> g9 b4 p4 u, X, D
功 能: 控制I/O设备 6 @3 I9 F/ @/ w. F& M1 F
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
& E! l! s$ F/ r J1 S3 c, e程序例: </P>
! c2 _3 n+ |8 E9 K<P><FONT color=#0000ff>#include <STDIO.H>2 F2 A* B: M- B* ~4 \. w6 f
#include <DIR.H>
9 [) f9 A0 k% |5 H \% K6 v#include <IO.H></FONT></P>2 X; a2 P* {9 [' H3 k
<P><FONT color=#0000ff>int main(void) ( ]6 x, Z, p* E4 E+ F
{ # d7 `( p; f1 y ~
int stat; </FONT></P>" q8 k/ w! c; C, }; w, w
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ 7 \5 ?, R( N# H
stat = ioctl(0, 8, 0, 0); 4 F8 {$ k. f4 h- n2 S% F
if (!stat) * E% H4 a9 H. m7 b
printf("Drive %c is removable.\n", getdisk() + 'A');
( _) B* F6 Z1 \- @else
# z d5 h9 |& ~7 N& v" Zprintf("Drive %c is not removable.\n", getdisk() + 'A'); * J. } H- s7 t% R
return 0; 2 J$ K+ }+ z; w) ^
} 3 V. o. h5 g7 F r$ D8 {" C1 y
/ X: r8 T3 p# m$ H# ~
</FONT>( B8 X5 _$ t# I# x" _$ _2 b
</P>2 W; u/ W8 n. A9 a0 }. b
<P><FONT color=#ff0000>函数名: isatty </FONT>
( j; c8 r5 R% i1 c: N; q; A功 能: 检查设备类型 # c+ s( E: \* G3 G7 v0 X8 P
用 法: int isatty(int handle);
. ?( Q4 G. f- b. m7 P+ [4 k# l程序例: </P>4 F. q r- W! [! o# o
<P><FONT color=#0000ff>#include <STDIO.H>
* O u, w$ }' h! j7 c2 v0 `#include <IO.H></FONT></P>+ \$ O. t0 A: [. T8 L b
<P><FONT color=#0000ff>int main(void) Q \" y# ]. c' ~. f! W/ J
{
$ ?- t$ ~* G) D5 V' x& V% [int handle; </FONT></P>9 k" P2 x8 V3 E5 k; t: P' `
<P><FONT color=#0000ff>handle = fileno(stdprn);
' S e5 X( h+ N `if (isatty(handle)) 5 q, o8 @: o1 y3 J' r/ }
printf("Handle %d is a device type\n", handle); % u% P& w# I& P" i
else
" @6 [" {: a6 M* `$ [5 Kprintf("Handle %d isn't a device type\n", handle); . Y2 }6 w" D+ l+ ^/ J1 \6 @
return 0;
- K+ b% G6 ^7 ^2 Z( H}
. O# Q L3 z1 {! p) G+ Q
9 A' m& e# h0 S) G: H9 j6 N; ]$ ]- q</FONT>. d- ]6 w C# E# l; v& a
</P>) _& z1 @9 C9 E0 F% b1 ?" i% x' q
<P><FONT color=#ff0000>函数名: itoa </FONT>: K4 D4 w4 g. j* `# z
功 能: 把一整数转换为字符串
: C4 C/ I* ^& a V* f! g用 法: char *itoa(int value, char *string, int radix);
- ]# |* y5 V4 b) u$ o+ T程序例: </P>5 P& X$ {5 }( b1 L% t6 L, Y
<P><FONT color=#0000ff>#include <STDLIB.H>
' z, [2 }, J# p) H1 X; I3 G# B#include <STDIO.H></FONT></P>
/ t1 q9 ?' v6 n0 q2 q) L! {' W<P><FONT color=#0000ff>int main(void) 3 [1 J! t4 }- E- [8 Y- ^# x6 m
{
# d z0 [! Z# G2 S1 D4 Oint number = 12345;
" z, d1 q- e* h. O. d" b6 ychar string[25]; </FONT></P>
' r" Z+ h% i' q9 v<P><FONT color=#0000ff>itoa(number, string, 10);
1 J8 E+ U2 `8 x% ^- N) _: oprintf("integer = %d string = %s\n", number, string);
/ J( @+ j# `+ V* }2 }, Areturn 0; , `: a5 c# e4 W( K3 v/ U N: L" g$ v
} </FONT><FONT color=#0000ff>3 w7 R' U- r! z' W
</FONT></P> |
zan
|