- 在线时间
- 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>
& h+ i8 w, H v< align=left><FONT color=#ff0000>函数名: imagesize</FONT> 4 c6 e! J) B/ q2 u! J
功 能: 返回保存位图像所需的字节数 3 X) E/ R7 Y- U+ p) R/ S: U
用 法: unsigned far imagesize(int left, int top, int right, int bottom); % G- ?( q) x3 b0 u" H8 G4 ?
程序例: </P>) e6 h0 i9 x1 w
< ><FONT color=#0000ff>#include <GRAPHICS.H>
& h3 O6 O- L" ?' y" Q2 t) e#include <STDLIB.H>
) U' M: w/ N* A2 Y#include <STDIO.H>5 q8 e* \! Q2 p3 I& O
#include <CONIO.H></FONT></P>9 ^8 ~+ t7 h9 ]9 l9 N( }5 \8 U: t
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
- @" h0 R0 e& Z8 ~7 {- [, @< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>; E2 b% c2 Q+ W* W9 r3 y+ Y
< ><FONT color=#0000ff>int main(void)
+ I: S4 c8 T% r$ Q{ 4 s: }' T8 N+ C% E* O" w' @
/* request autodetection */
9 v2 u' k' p+ {3 ]int gdriver = DETECT, gmode, errorcode;
: ]! ^) T7 v- |: |$ ^void *arrow;
3 c' E& M. u5 {1 U' u" mint x, y, maxx;
6 N( R. A6 u S3 ?- q* q+ M. qunsigned int size; </FONT></P>
9 z" C; A1 Q) L- y% e t< ><FONT color=#0000ff>/* initialize graphics and local variables */ . s/ L4 r( W$ N: e4 ]" D+ ^! b
initgraph(&gdriver, &gmode, ""); </FONT></P>' Z" E) S9 u7 V5 i
< ><FONT color=#0000ff>/* read result of initialization */ 4 o; @+ {9 O1 o j. x4 E
errorcode = graphresult(); * U7 ^7 _, P0 ^0 c; b9 a
if (errorcode != grOk) /* an error occurred */ " {* L A: f- A2 s
{ ) U) o: | A2 G- X
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : x* X: k/ `& I7 V' C; P" o }% F
printf(" ress any key to halt:"); : M" ^' M: p4 ^- Z0 I# f7 d0 z
getch();
/ V0 |" H9 h7 }5 f' `- }7 V6 Nexit(1); /* terminate with an error code */
7 p" j, v2 a- A3 _} </FONT></P>" t" x2 j A( ^1 a
< ><FONT color=#0000ff>maxx = getmaxx();
0 G) S/ Z* x1 U# I0 d* mx = 0; ) Q; t4 \8 T1 H m
y = getmaxy() / 2; </FONT></P> w1 h7 m" q' N
< ><FONT color=#0000ff>/* draw the image to be grabbed */ 9 W( D1 e% R" X6 P9 x2 }
draw_arrow(x, y); </FONT></P>: p/ h0 Z7 L, f; c, l
< ><FONT color=#0000ff>/* calculate the size of the image */ ) I* S4 Q% x5 \ i
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>
$ _5 Z/ b$ c3 Z" l- q8 |< ><FONT color=#0000ff>/* allocate memory to hold the image */
* W8 i/ j! t5 s5 Z- warrow = malloc(size); </FONT></P>
7 h; u9 P+ y6 V v1 E< ><FONT color=#0000ff>/* grab the image */ 1 v% G- z8 h! U
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>0 m4 i4 m g5 S7 Z8 Q3 k: d
< ><FONT color=#0000ff>/* repeat until a key is pressed */
; ?1 N9 F. s( z3 owhile (!kbhit())
) e; e$ L; W* j0 q{ 6 J. r9 v8 b6 I" N L& p* b r# h
/* erase old image */
' d/ j$ e# |% nputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
8 D' n, t$ q6 }% R< ><FONT color=#0000ff>x += ARROW_SIZE;
7 c4 M; w; D* o/ B4 Q7 _9 Nif (x >= maxx)
& l& b J. D$ ^$ Z7 M; Y/ nx = 0; </FONT></P>
7 C4 o* V# W: l3 I0 X( C, c< ><FONT color=#0000ff>/* plot new image */ 3 m! |- x+ V* G# ?5 J$ [0 C, a0 t
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); 9 f& {+ I" f% e3 b# I$ x
} </FONT></P>
p' l8 w5 r" }, a* ]/ d< ><FONT color=#0000ff>/* clean up */ 8 u( B% a+ P5 @/ q2 |5 G( w, m
free(arrow);
# L* x% h1 J/ {; p4 V" hclosegraph();
+ {/ R* \8 s! |/ O- ^return 0;
# p( g, a( z7 {} </FONT></P>
4 V, z: h1 }: ^, s: o3 ~" d< ><FONT color=#0000ff>void draw_arrow(int x, int y) 6 H: _1 ~) W! b% H8 `- b3 [) m
{ * J5 I6 Y f( L% L) U0 H' p5 W$ t! ?2 J
/* draw an arrow on the screen */ + P$ T, J9 A Y: `% ]$ x
moveto(x, y);
) M- f& Q+ w$ w2 i4 Mlinerel(4*ARROW_SIZE, 0);
8 {7 b9 G8 {% d6 C5 ^2 ]- glinerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
" e: V" ? g% t2 [: olinerel(0, 2*ARROW_SIZE);
# H+ w6 J+ L3 f$ Clinerel(2*ARROW_SIZE, -1*ARROW_SIZE); 7 u6 E* k' T2 T$ {. `- k
} , Y* C7 k; ?- ]1 y* i& w) d
4 q: C: I, }: W7 P0 r" u
' D" a* o) D# v! o2 L+ m</FONT></P>- T5 [ l, j; L. V
< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
; Y# ^/ C. f& }: N5 u: d<FONT color=#000000>功 能: 初始化图形系统 ' q* J# g/ d1 c9 h! m+ y* s9 P
用 法: void far initgraph(int far *graphdriver, int far *graphmode, , I9 _, i6 d- l- n# O; s. u8 J/ ]/ N
char far *pathtodriver);
/ p5 F6 j+ n2 ^6 L程序例: </FONT></FONT></P>% ^6 R; a8 G v% t: g
< ><FONT color=#0000ff>#include <GRAPHICS.H>/ I9 A0 ^" B$ _
#include <STDLIB.H>! Q. I. k+ r% i& ^
#include <STDIO.H>
% K3 U9 s& Z$ g; f: V) K0 G#include <CONIO.H></FONT></P>
9 m5 j2 l/ @1 @$ m2 n) X7 J< ><FONT color=#0000ff>int main(void) - r9 C% D! B l% |0 I2 n
{
7 r/ B; |8 D3 W2 b/* request auto detection */ 9 ^5 `/ G: z6 Z; ?5 g
int gdriver = DETECT, gmode, errorcode; </FONT></P>
! V8 O! p8 ?3 q# T* E< ><FONT color=#0000ff>/* initialize graphics mode */ 0 ?$ F. s4 I3 j- f) d
initgraph(&gdriver, &gmode, ""); </FONT></P>( N! X$ P! [9 |4 i
< ><FONT color=#0000ff>/* read result of initialization */ 5 y/ x9 |& j) k* a& q
errorcode = graphresult(); </FONT></P>+ A4 }6 h# f: A4 z" _/ ~7 V
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
: h. g8 ^" Q7 i \; u0 U5 e( q{
4 m) N* u' b5 c8 o. T* Nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 u1 g, E- ~) I% }) b) Wprintf(" ress any key to halt:"); : V( ?9 u0 {' Y: B& Y5 i
getch(); 1 t( d# I5 }- T0 F" X. w4 b
exit(1); /* return with error code */
6 w% ?! |, v9 W} </FONT></P>5 G4 U) B! T4 G O3 O
< ><FONT color=#0000ff>/* draw a line */
9 l) h3 x! X" y, Lline(0, 0, getmaxx(), getmaxy()); </FONT></P>
5 E7 F5 @! e* \6 W( Q< ><FONT color=#0000ff>/* clean up */ , p5 {; {. h4 O% C
getch();
2 I6 i9 a( K; n5 tclosegraph();
1 @3 f4 {1 I4 z" |: s5 ?6 r; k6 Breturn 0; $ }+ K' k, T2 b. o( v
} </FONT>+ N* W9 `- _ i- h
9 c( z0 R0 ^9 Y# S P* E
</P>3 t! D5 F& A& J& g3 b5 `/ \
< ><FONT color=#ff0000>函数名: inport </FONT>
! c- r8 f3 s9 ~) U/ s功 能: 从硬件端口中输入 ; z1 D" a; i+ l1 W3 |+ R
用 法: int inp(int protid); 2 d0 P; ^) F3 D* A' `
程序例: </P>
$ h! L' a W. H, q( k& P- a0 I< ><FONT color=#0000ff>#include <STDIO.H>" U- d5 H$ U' c. G
#include <DOS.H></FONT></P>
2 f5 ^- Q# c0 x7 c5 ]- M<P><FONT color=#0000ff>int main(void) - l3 @* P6 U }; f; {' p/ f2 o
{ % j5 J; w; V6 X# A1 _! A% B
int result;
4 A: w* d2 u9 \% a ^& Lint port = 0; /* serial port 0 */ </FONT></P>
/ f( E( \) w) a( |<P><FONT color=#0000ff>result = inport(port);
& q$ K; w& Z( x' ~6 Q* r* rprintf("Word read from port %d = 0x%X\n", port, result); " V% g" h. T6 z0 B: n% O
return 0;
: u. C& x& Q' {/ ~3 k1 Y p}
1 V# K' S" M+ O8 N1 _! b
/ h4 k. Y- a4 N& u: N4 ~</FONT></P>/ j5 I U% u3 l1 D% r# \
<P><FONT color=#ff0000>函数名: insline </FONT>
/ c6 A( A7 ]# O u. Y0 N功 能: 在文本窗口中插入一个空行
7 v1 g' {: y) t1 [9 Y用 法: void insline(void);
! e* l8 F, U' B0 W- d5 ?程序例: </P>, ?" y6 w8 A) C$ W" t# U
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>9 [: Z. T& Z" {2 f$ J& J3 Y% ]
<P><FONT color=#0000ff>int main(void) * S8 R+ W( P: W, `
{
& \& i" s" s5 R2 Iclrscr();
/ b. j! \% P6 h1 l# I6 Xcprintf("INSLINE inserts an empty line in the text window\r\n");
V; d0 U$ F+ ]9 scprintf("at the cursor position using the current text\r\n"); 7 f9 @" f% y6 R1 S0 S, Z4 I3 K
cprintf("background color. All lines below the empty one\r\n");
( @1 `- u8 p- k; X# s( [# d; Z% t& Xcprintf("move down one line and the bottom line scrolls\r\n"); A* ]9 V4 k# [& T, q0 { X8 f
cprintf("off the bottom of the window.\r\n"); 3 R) a* {9 L& Z$ s2 A& r' y. A+ ^. n8 d& b
cprintf("\r\nPress any key to continue:"); / K6 n8 ?& p `( v' M- R' u
gotoxy(1, 3); 6 V; P2 l9 I2 [. q) w
getch(); * A0 o* y+ \ e+ |1 j8 ?
insline(); ' P) e: @2 P3 K2 L$ i
getch();
8 ]% D% K% N$ u1 }" M9 d) C8 U* nreturn 0; 2 f+ M4 v3 e& }- W0 Z* R
} " q- z' {4 N* [$ `! R4 O
</FONT> @( T: j% U% c0 t+ J+ ^7 w
2 h8 d7 e g( }, B' z7 S</P>% q0 H0 Y& q" H% G
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>; h& k: q( N1 H1 |5 F, `7 ?( k5 a
功 能: 安装设备驱动程序到BGI设备驱动程序表中 ; v5 I2 G' X& ^: i! ?% o& N }3 ?' a
用 法: int far installuserdriver(char far *name, int (*detect)(void)); 6 l: p/ P+ r. Z1 W
程序例: </P>% F' f+ r F$ a g P
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 p. J& O/ ]0 o/ m0 G" h8 {9 R#include <STDLIB.H>) I( E' M) W4 X* P, C
#include <STDIO.H>6 R+ [8 ~/ V+ R @) p) P0 ^
#include <CONIO.H></FONT></P>
+ m& Q4 ~0 k. x+ Q! J% u% y# M, w+ _<P><FONT color=#0000ff>/* function prototypes */
$ K7 Y5 R- h2 d9 S. \+ G Y7 {1 T" Nint huge detectEGA(void);
! i7 j B% r. B& b# w5 R! uvoid checkerrors(void); </FONT></P>
" s5 j* K1 N6 S* k9 q<P><FONT color=#0000ff>int main(void) - B7 }! a: [$ I/ Y: N0 M9 M5 K
{
; o# J: l8 U0 _) R D9 fint gdriver, gmode; </FONT></P>
: \' m, \3 Z7 e3 I+ v* W" v<P><FONT color=#0000ff>/* install a user written device driver */ , I, v& ^! A" Q8 Y. |1 A( Z3 Q
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
4 t% X8 k9 |% b<P><FONT color=#0000ff>/* must force use of detection routine */
% c; y3 h/ u d/ V+ fgdriver = DETECT; </FONT></P>
$ ]$ } \/ J0 u; M7 N; Z<P><FONT color=#0000ff>/* check for any installation errors */
9 Q w* q6 v e4 {9 dcheckerrors(); </FONT></P>
* }% a; d8 z, e* p1 O<P><FONT color=#0000ff>/* initialize graphics and local variables */
" _( x _& z0 Sinitgraph(&gdriver, &gmode, ""); </FONT></P>
F. m: C! ?+ ?, c2 z8 k<P><FONT color=#0000ff>/* check for any initialization errors */
) e4 D1 A; S# ^* Ccheckerrors(); </FONT></P>
8 w) X o- \; e' T5 E<P><FONT color=#0000ff>/* draw a line */
2 r9 q- `9 \( b' eline(0, 0, getmaxx(), getmaxy()); </FONT></P>
$ n" w, D- X( R9 Y+ ]<P><FONT color=#0000ff>/* clean up */ 9 c& { X$ e8 Y' i9 r
getch();
/ O0 D* x* W9 _/ e. `closegraph();
8 t2 n6 L) E2 B7 ?return 0; # X; ^# @ K2 Y7 j: ^2 J4 w5 f
} </FONT></P> G/ Q. Y9 _5 A5 G+ |
<P><FONT color=#0000ff>/* detects EGA or VGA cards */
9 N) z; x2 @/ L+ b; e. N7 J2 e& Gint huge detectEGA(void) 9 K T5 R: X/ p0 T, O
{ % }. R7 Q& r$ Y% V; V6 m
int driver, mode, sugmode = 0; </FONT></P>. t6 p k$ G: T/ Z2 b4 {) z9 k
<P><FONT color=#0000ff>detectgraph(&driver, &mode);
5 b- R' A) m. wif ((driver == EGA) || (driver == VGA))
4 h% a4 T- d, ?( U- {# E3 c9 k" V/* return suggested video mode number */
1 S8 e% G) \/ E9 n! U% vreturn sugmode;
0 ^0 f7 A8 y. f( c7 c5 f- J8 belse
+ l# l- y$ A w. y! J9 b1 {; a6 U/ Y/* return an error code */ # M$ O1 V" q* ^2 T1 ^! ~, f6 H
return grError;
$ j: M& p5 Q; V# {: N5 X0 M! L} </FONT></P>: C. {1 v0 _5 h" i O$ O5 d
<P><FONT color=#0000ff>/* check for and report any graphics errors */
6 x5 E7 _( t& c7 E4 J! I4 Zvoid checkerrors(void)
, c9 b N, O1 D0 y* c{ 1 n9 o5 {- I& ~
int errorcode; </FONT></P>- E" P3 E! X; W! ]$ }* L
<P><FONT color=#0000ff>/* read result of last graphics operation */
W, A5 y* F8 A @. ^errorcode = graphresult();
5 j/ k" m) u$ h: Q0 d4 d3 aif (errorcode != grOk)
% m' P- ?+ L* x' `{
( `9 ~5 T1 v, I/ rprintf("Graphics error: %s\n", grapherrormsg(errorcode)); + B$ R, F! y. x# M
printf("Press any key to halt:");
; Y; d% g% u6 i3 W3 ogetch(); 5 a2 @+ n4 X) K0 J
exit(1);
/ l7 G6 y4 _; b; {& g}
2 ~8 a0 W. t& o} </FONT></P> p6 _( V) G1 k4 \5 V5 O1 J8 W) K; [
<P><FONT color=#ff0000>函数名: installuserfont </FONT>& I0 O9 i0 D; Z" h- h- N
功 能: 安装未嵌入BGI系统的字体文件(CHR) % ~9 F: }4 R3 M6 M) I, N6 ?- D. g" ?; @
用 法: int far installuserfont(char far *name);
0 H, o- J6 ?5 z3 x0 U/ d程序例: </P>
9 l6 [- u" m2 y! H3 b3 N<P><FONT color=#0000ff>#include <GRAPHICS.H>
% y, g: j; j2 r5 P# O4 _#include <STDLIB.H>
1 m( T$ Q% T; X: ?% i2 r#include <STDIO.H>: m/ A7 C) s% u( ?# q
#include <CONIO.H></FONT></P>
. ?3 d* U+ `) {7 H; ]6 K- }<P><FONT color=#0000ff>/* function prototype */ # u7 X! ]. S" X" w
void checkerrors(void); </FONT></P>
* Y4 c5 b, J3 E<P><FONT color=#0000ff>int main(void)
2 h; B* E: ~# [0 J, Y/ J{
& i1 u+ k& s9 M( Y/* request auto detection */
0 _6 r( R; `2 B& _2 I9 Yint gdriver = DETECT, gmode;
% V: }4 `/ f+ s0 j Y3 l. ^int userfont;
' ?+ s' X, A' O, k' e+ tint midx, midy; </FONT></P>
' z$ W! q+ h3 b4 \$ I$ q* {<P><FONT color=#0000ff>/* initialize graphics and local variables */ & d# C: S6 X$ v
initgraph(&gdriver, &gmode, ""); </FONT></P>
1 d6 o i% N- t/ a& i<P><FONT color=#0000ff>midx = getmaxx() / 2;
/ T. m& h, J1 f& Cmidy = getmaxy() / 2; </FONT></P>
: s: t1 c; z0 X; o<P><FONT color=#0000ff>/* check for any initialization errors */ , b; Y5 B& I; r5 e; T
checkerrors(); </FONT></P>
! J; n K: g5 z* k7 ]; I<P><FONT color=#0000ff>/* install a user defined font file */
" c( z- z& M/ ?; Huserfont = installuserfont("USER.CHR"); </FONT></P>
5 B! e1 D& `7 T5 [ r. w3 k<P><FONT color=#0000ff>/* check for any installation errors */ 9 u9 s- ^+ c$ Z
checkerrors(); </FONT></P>& N8 `0 i& t2 N0 Z/ M+ c
<P><FONT color=#0000ff>/* select the user font */
" [- }8 e0 D8 k" s, ~settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>/ J6 i# q" k" j! S6 n. h Z6 V9 c
<P><FONT color=#0000ff>/* output some text */ / |& q. w- J7 o% `' {! I5 j
outtextxy(midx, midy, "Testing!"); </FONT></P>1 g' d! M* a9 E+ Y# z" V! r6 `: p& l; t
<P><FONT color=#0000ff>/* clean up */
2 A& D- S) k9 Pgetch();
2 [. o4 T0 S4 ?+ {2 Xclosegraph();
. Z" l4 o) ~( q! b2 @# V) sreturn 0;
+ D6 N$ s0 H' w1 r; D} </FONT></P>4 ^! W. u2 T7 j" i4 y
<P><FONT color=#0000ff>/* check for and report any graphics errors */
5 W% n9 E5 U( |& ovoid checkerrors(void)
9 g8 f9 j6 }! L' i+ {$ |{
. V. I. K' R$ h8 V" Xint errorcode; </FONT></P>! d2 B. y! d& e) j; [5 _$ w
<P><FONT color=#0000ff>/* read result of last graphics operation */ ( @, n, T- A N4 v* e, K* @3 E
errorcode = graphresult(); 2 Y8 z X- J4 [- ?2 l# G* | g- i
if (errorcode != grOk)
, X) P& I+ ^5 C, k{
; i# e7 K" f/ w9 Q/ }4 O5 [7 {4 kprintf("Graphics error: %s\n", grapherrormsg(errorcode)); T T, u- p1 h4 B+ B
printf("Press any key to halt:");
9 L9 ?# ]! o3 x* n& \getch(); + l1 {/ O7 R8 Z D! Y
exit(1); 2 _2 B6 I2 ]! }- Q: V2 ]! P
} 6 E+ A6 S- O3 z/ j, U g
} </FONT>
5 h. h/ ]) Q2 C$ ?% t3 a
( n+ H/ }1 Q& P# F4 b% q
R" v7 r. E; r</P>4 D* ~2 |, p1 Q5 T" H/ Z
<P><FONT color=#ff0000>函数名: int86 </FONT>
6 T @8 r) b2 @; r+ u) L功 能: 通用8086软中断接口 2 W/ `% u# S( u* w6 _1 r2 n7 i
用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
9 e8 n, ]: @# C# f; W+ C程序例: </P>7 i1 v- X: Y8 B# N% ?& ~, m! P
<P><FONT color=#0000ff>#include <STDIO.H>
( W2 R4 q" a/ y( u* O" D; I#include <CONIO.H>( x1 ?) D6 {3 n( @8 y1 F
#include <DOS.H></FONT></P>) T# R* A$ a; X
<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
6 Y" Q2 I: ^+ c& B, F" b<P><FONT color=#0000ff>void movetoxy(int x, int y) ' \* u0 M0 V9 @, K8 f
{ * b4 @& `) `8 c: t6 M' p" ^( M/ R
union REGS regs; </FONT></P>
9 S$ a# q/ y6 X) |' ?& A8 h<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
7 Y$ R7 T; a& ^regs.h.dh = y;
, n X1 Q* B" N. ~/ Q6 S$ `+ c4 Nregs.h.dl = x; 9 X# i& L9 c! T7 k
regs.h.bh = 0; /* video page 0 */
& O& l, T( C8 X+ @7 Vint86(VIDEO, ®s, ®s); , x3 ~6 A' f! o; Y
} </FONT></P>
1 |. ^- s) D" N$ p# G( x<P><FONT color=#0000ff>int main(void)
+ P1 V3 E8 ?% O7 C- a; y{ 6 ?6 [& d; | K( Z, u9 R! E; N
clrscr();
7 v& E x; v2 e1 O& N: n6 _movetoxy(35, 10); 0 R5 `! x; v* t4 b2 d8 P
printf("Hello\n");
. C) z4 O7 e2 M. E. s" x8 kreturn 0;
) k' u3 a( J) ?} </FONT>
3 u3 f3 s! s3 X2 s% {) ^3 k; V1 u \
</P>" D" E! m- |3 h6 d* }: a
<P><FONT color=#ff0000>函数名: int86x </FONT>
' x6 W$ r: A! D" L( R功 能: 通用8086软中断接口 0 P/ t* M0 X2 d( I8 l; Q6 |
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, : T' [7 h8 m1 s( F0 O C; B7 I
struct SREGS *segregs);
; E4 R1 U: _8 B程序例: </P>7 o* v( L+ E Z
<P><FONT color=#0000ff>#include <DOS.H>
; s3 `# w# \0 \7 P$ ?) w#include <PROCESS.H>1 ], O" P* X5 z) R; j
#include <STDIO.H></FONT></P>+ F* ? r! w* L u% [ \
<P><FONT color=#0000ff>int main(void) 2 ?; U9 G# E/ b* |5 n7 w
{ , M; e4 F) r$ a
char filename[80];
1 a- a. n# t' F' C$ ?union REGS inregs, outregs;
, U' p: S v+ I3 n8 }7 f0 Xstruct SREGS segregs; </FONT></P>( I. f4 L. q# U' t a
<P><FONT color=#0000ff>printf("Enter filename: "); # R% \8 A" [7 y4 Q4 w' T
gets(filename);
3 l( u. i$ e! I) kinregs.h.ah = 0x43;
( d [- |$ \1 H2 qinregs.h.al = 0x21; , v+ o5 u7 i: a+ h- i* |6 { o
inregs.x.dx = FP_OFF(filename); 8 `+ E7 {, g" P0 g
segregs.ds = FP_SEG(filename); 5 \$ @# w' `: L+ }
int86x(0x21, &inregs, &outregs, &segregs); # g* u6 ~- d( c4 e9 A( e
printf("File attribute: %X\n", outregs.x.cx); ( a1 e; J6 A) | \. t
return 0; & x4 l9 L% ]& r! s$ w
}
! t! x f# C4 B9 B7 e2 @
l9 R5 {) {' M$ f8 b* }3 L</FONT>7 Y J. b8 ~% @ x/ p
</P>4 ~. z$ t9 y" W4 m$ p
<P><FONT color=#ff0000>函数名: intdos </FONT>
- v9 i; d2 y! a. `3 D* ^功 能: 通用DOS接口 * Y# c' W$ b7 i( }3 t( O
用 法: int intdos(union REGS *inregs, union REGS *outregs);
5 E6 ]8 d2 o R% C程序例: </P>
# @* t6 _* R& G6 k& S<P><FONT color=#0000ff>#include <STDIO.H>
2 v' O2 @/ ]/ t z#include <DOS.H></FONT></P>! E7 t' ~! @7 e- ?1 D5 D
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ / \0 M' A5 j4 x; \6 d
int delete_file(char near *filename)
0 C* `+ P3 x j2 F1 n& F4 o9 O{ # A2 \9 C2 r# F
union REGS regs; % |# f( q9 c% E* H; D# q4 R8 b
int ret;
# W( u- j. `$ f' Y# tregs.h.ah = 0x41; /* delete file */
1 C6 N% e* N1 _- N4 F. @regs.x.dx = (unsigned) filename;
9 M. x: G+ K7 Tret = intdos(®s, ®s); </FONT></P>+ l7 o3 X/ t! f) [
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ 1 q1 r0 e! k2 R. m' z' E+ q
return(regs.x.cflag ? ret : 0);
( U+ u u/ B* v ^) V8 j} </FONT></P>" {" X, Z1 U8 y( `4 g3 \
<P><FONT color=#0000ff>int main(void)
3 {0 D) R. V/ g{ $ W) k8 X1 t' z$ {. k
int err;
8 w. G( s) p7 Z H, }err = delete_file("NOTEXIST.$$$");
- @- p" @# V v% p8 ?- Zif (!err) & y" Z" r+ S- ^, t) r2 o3 z1 ~) R
printf("Able to delete NOTEXIST.$$$\n");
6 v& W7 E t1 y# A' E% j/ uelse 0 @! L; K( {9 g# t) F0 @( r# p
printf("Not Able to delete NOTEXIST.$$$\n"); " t4 d1 @$ I7 [8 H. Q
return 0;
2 H3 S5 i9 }% f! d! _; w+ _}
6 F4 b+ s8 [) C. ?! s8 |3 P% M' G6 V: z* `$ v
</FONT>' S* g! x! G- f! g; N
</P>! D3 A' l5 o8 [& T8 x
<P><FONT color=#ff0000>函数名: intdosx </FONT>
, A" d% T8 H/ ]" P1 m1 `功 能: 通用DOS中断接口 & j, j- N9 S9 C4 Z6 k( D
用 法: int intdosx(union REGS *inregs, union REGS *outregs, ( @9 A7 {3 T5 M Q7 P- y
struct SREGS *segregs);
8 R: R" }3 [0 W! s, p$ z程序例: </P>7 [0 j3 s$ ^4 [. k) @; U
<P><FONT color=#0000ff>#include <STDIO.H> y' ^3 H# r7 w6 p8 J: x+ ~
#include <DOS.H></FONT></P>
. R/ ], h" ~ } {! [<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 5 \. C/ _5 Z, d& |9 b
int delete_file(char far *filename) 2 f+ n* c/ e% l! V) b$ y) M' t
{
+ }: X" o$ P3 y6 \* lunion REGS regs; struct SREGS sregs;
. e3 i4 d% t# J: i& Nint ret;
' v4 @* c% q. Y4 Q, N9 {0 tregs.h.ah = 0x41; /* delete file */ * s# P) `# t; e R* z1 L
regs.x.dx = FP_OFF(filename);
6 O" I3 g* z, n) O7 p% Y/ Vsregs.ds = FP_SEG(filename);
; o$ G) J9 X* E& z: c( \7 mret = intdosx(®s, ®s, &sregs); </FONT></P>
( G* B! D8 k3 p$ M<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ & v! u' J$ d6 ~' g7 }7 g5 Y: ~% u
return(regs.x.cflag ? ret : 0);
" O: H& t0 c1 g \. N, Y3 H& l. v} </FONT></P>
6 }# \7 A% y3 f- d: N0 r<P><FONT color=#0000ff>int main(void)
. l1 g- E1 T, S8 |/ [{ 0 H9 x s% D8 C" m5 q' b9 N, u
int err; 6 e( j* i0 R0 |! n. Q; r6 n
err = delete_file("NOTEXIST.$$$"); # I' v5 n: G7 g6 M6 h1 U: V
if (!err) & h, f( L* S; c6 |
printf("Able to delete NOTEXIST.$$$\n");
: b Y1 B3 o8 ^( {$ Y! Telse # n2 x; H6 {5 K) ?( Q. u0 U
printf("Not Able to delete NOTEXIST.$$$\n");
- ~) m3 Z# T9 }6 I# o% n4 Yreturn 0; , y3 C9 Q! \* g/ w! Q) h% p& P
} , D2 Q; s* q0 _" t ~) W' j
</FONT>
( v0 C D) X6 i</P>+ i- _ L4 \% y- \7 C. o
<P><FONT color=#ff0000>函数名: intr </FONT>( ]8 }5 I& N6 C3 M1 q' }! _9 \
功 能: 改变软中断接口
1 R' J6 T4 g, U用 法: void intr(int intr_num, struct REGPACK *preg);
) F' ?# x, l! C1 }程序例: </P>$ f2 z0 h4 E$ o: \3 a) W9 g: S
<P><FONT color=#0000ff>#include <STDIO.H>
+ m* G* @) P+ v( N5 e#include <STRING.H>
7 _" K8 d5 m. U" `#include <DIR.H>7 D. s- X+ j3 l1 X \9 i
#include <DOS.H></FONT></P>
# i/ ~9 U4 f- q0 u<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>& a# ]" w* H6 _- R' X
<P><FONT color=#0000ff>int main(void)
1 X, k0 K% Y$ D% V) M{ 0 d3 x `: T; W9 d1 Y1 N
char directory[80];
1 c- \* W: P5 p5 B4 e6 Gstruct REGPACK reg; </FONT></P>& j/ O; A7 L4 Q* S2 @, `: w1 q
<P><FONT color=#0000ff>printf("Enter directory to change t "); 8 A6 D/ {. u2 R) A" H4 a: z2 D
gets(directory);
% q" w1 u, T" U4 Z3 ?4 s: N" creg.r_ax = 0x3B << 8; /* shift 3Bh into AH */ 0 B( Q+ ^' [) [1 |) i
reg.r_dx = FP_OFF(directory); ( w( `) P- @2 L2 |
reg.r_ds = FP_SEG(directory);
/ D& Q1 D+ g y) h. r* Jintr(0x21, ®);
8 {$ [; g7 J9 d0 v# N7 Sif (reg.r_flags & CF)
M, H$ ]* w4 N7 \3 |printf("Directory change failed\n"); 6 G; @6 |+ i& i6 j9 A9 I1 K
getcwd(directory, 80); ) o6 q4 e' W; K1 ^8 a0 Y+ J- F
printf("The current directory is: %s\n", directory); 4 Q/ t! F- B4 F4 M5 x
return 0; T- i8 O8 V7 _! y0 _( y; c/ V1 P6 v
} ; F$ s* P' j/ a/ x
</FONT>/ s" p$ y& {7 D3 U- W( j6 m# ]
</P>
$ T; k+ E: P. t9 D4 l# J' [3 X2 C<P><FONT color=#ff0000>函数名: ioctl </FONT>
$ Y' _3 G6 n, Q! w: h6 q功 能: 控制I/O设备
8 f* v: O0 t1 w3 N1 r; f K/ e用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); ' N H" z: H; W& ^% W, H" [ {
程序例: </P>
?. r$ S* W# G1 j7 N1 R% S: b1 E<P><FONT color=#0000ff>#include <STDIO.H>; J0 T3 ]" x) q
#include <DIR.H>( x1 I6 d9 K; i$ n. P
#include <IO.H></FONT></P># W9 t$ @! l* F) V$ V! [% R8 x) ~
<P><FONT color=#0000ff>int main(void)
+ [6 u6 O7 P5 d: ^6 v8 z{
N7 c' U/ T3 b0 ^5 o+ Bint stat; </FONT></P>' ?* l3 |* g3 o: {: @, \" ^7 z: w1 i, z
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ % c3 [( w6 T+ M8 U, R! D
stat = ioctl(0, 8, 0, 0);
9 q, o0 t* ^5 w2 Qif (!stat) % c$ b7 w; Q0 v. n" e% {& l# d( R
printf("Drive %c is removable.\n", getdisk() + 'A');
c j3 Q* U1 g3 Q! {9 o% C' uelse ! j' p/ C2 ^7 Y, B+ L* g: I `
printf("Drive %c is not removable.\n", getdisk() + 'A'); + a1 D" k% z. p% _0 m
return 0;
5 q" g* X3 L' u! {$ d7 W} + I* i/ F1 D# p* d# v
: X) X4 M) L& r" U) E5 E- T' h</FONT>+ x/ j7 C8 g* B2 K. j @5 ^
</P>6 k j2 W% @8 y$ A
<P><FONT color=#ff0000>函数名: isatty </FONT>
9 r2 r9 U i" m功 能: 检查设备类型
* v3 F O& l! y$ b9 T: o0 H0 ~ Z% ^用 法: int isatty(int handle);
, q* F% j; N' b% s程序例: </P>2 W5 A/ K% |( e
<P><FONT color=#0000ff>#include <STDIO.H>
( o- {! |% {7 a5 h#include <IO.H></FONT></P>
$ ]+ L+ @8 m. ?3 F8 Y8 z* @<P><FONT color=#0000ff>int main(void) . y0 d7 j% n% d' R% w- l R9 B, ^
{
$ J& f% a$ o$ ~, D8 ?. f+ |int handle; </FONT></P>, {/ D7 s& v4 {
<P><FONT color=#0000ff>handle = fileno(stdprn);
! M$ v' [/ ]6 V( G- ~: Mif (isatty(handle))
+ F7 h/ v3 R5 N1 eprintf("Handle %d is a device type\n", handle); % u R& q$ j P' h+ v0 G
else ( }3 j0 F: p3 [
printf("Handle %d isn't a device type\n", handle);
. D4 T8 l' Q* K5 Y+ c) mreturn 0;
. W: N R2 F, [" c3 M) u( ?6 |}
7 R) u( T2 I; \2 e1 q+ ]1 k# }% Q( V) L x; ~, ~/ @
</FONT>
, w9 m0 |; b5 K8 j7 Z) u</P>+ ], {0 u; G; V4 t* V( q7 H3 d
<P><FONT color=#ff0000>函数名: itoa </FONT>
1 D7 ?, f! R$ O+ c3 g. M5 d, j! t功 能: 把一整数转换为字符串
$ U6 B0 ]3 f, n用 法: char *itoa(int value, char *string, int radix);
) v0 f; O- j. |! F程序例: </P>
; H" P. h2 E' N6 [<P><FONT color=#0000ff>#include <STDLIB.H>- M* g+ r+ t. c5 N+ W
#include <STDIO.H></FONT></P>
/ S3 ~. ~/ P( B+ {9 c9 Z<P><FONT color=#0000ff>int main(void)
3 e$ b6 M" i7 i! `! M{
7 y. s( l$ k) c* d! y Hint number = 12345; " B+ m/ I2 H! h8 S( z
char string[25]; </FONT></P>" {/ d! }- s2 O2 e' c
<P><FONT color=#0000ff>itoa(number, string, 10); 2 _9 Y( z9 Z% w3 `: L$ X
printf("integer = %d string = %s\n", number, string);
$ X8 l, X& k4 ?return 0; 5 n. e4 y- q/ d- t0 k
} </FONT><FONT color=#0000ff>- T) S7 } M- I9 @/ ~
</FONT></P> |
zan
|