- 在线时间
- 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>' ]( Q! k+ `2 I2 H
< align=left><FONT color=#ff0000>函数名: imagesize</FONT>
4 e% f. Y" L& R6 d2 g) B' y+ R功 能: 返回保存位图像所需的字节数 $ Z* X K" L4 P& Y, _1 l
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
6 e$ L2 M$ Y% r: F程序例: </P>
+ P" Y* l) F; l/ I) Z4 T< ><FONT color=#0000ff>#include <GRAPHICS.H>& B7 b- v# b( E, }. r
#include <STDLIB.H>% J* z, e. F% c* O- Y' Q$ B
#include <STDIO.H>. ?$ [0 h5 h3 \9 W- G* G+ P a# k
#include <CONIO.H></FONT></P>! @+ C* S; d# [, w3 i7 Y- A, Z* J( p
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>9 B- l# `" v1 p0 B2 T/ w9 V7 Z+ @! }
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>- c: ~9 N$ {1 G2 C5 b. T6 i& _, O7 r# d
< ><FONT color=#0000ff>int main(void) 5 S( x9 }3 v ^9 a7 f, t
{
2 O- P- ?& ?- H. S& L* R/* request autodetection */ 3 H" u5 U1 _# U+ e X
int gdriver = DETECT, gmode, errorcode; : c$ P$ m% T* A* R: s) \& z$ Q
void *arrow; 0 F: n. f, p* T5 |0 `, }
int x, y, maxx;
1 G& s Q, m9 k' ]8 H1 N8 y8 B. hunsigned int size; </FONT></P>
$ I- a) j$ k! y& J< ><FONT color=#0000ff>/* initialize graphics and local variables */ 6 D( t* m! z. k" u! Z
initgraph(&gdriver, &gmode, ""); </FONT></P>/ U: X* J: m5 e) f
< ><FONT color=#0000ff>/* read result of initialization */ 9 U9 H) ^" s F, d( p
errorcode = graphresult(); - W w0 ?- G# h# J% j$ X
if (errorcode != grOk) /* an error occurred */ 6 b. C8 I( \, V1 F4 i/ x6 d& [
{
; m' ~" X4 M/ `& G; Bprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' Q! V K3 t5 p2 U
printf(" ress any key to halt:"); # C* p$ ^, S, {! b1 r5 v) B
getch();
2 q+ q9 v& I. W) L" ^8 J' Aexit(1); /* terminate with an error code */ 2 D0 p( `! k" g+ n+ ^. W o
} </FONT></P>) M4 `" o' v) L6 E0 @. N# Q% K' @
< ><FONT color=#0000ff>maxx = getmaxx(); 8 \( |: K% H6 g, ]7 }
x = 0;
2 h+ W2 h6 c1 N: m3 e* my = getmaxy() / 2; </FONT></P>, [ d% h' F+ }, `( h- W
< ><FONT color=#0000ff>/* draw the image to be grabbed */
3 f+ u9 p9 R4 ~8 Jdraw_arrow(x, y); </FONT></P>
8 _ H7 W0 E" F4 Z< ><FONT color=#0000ff>/* calculate the size of the image */
8 N) R: L# Z0 G+ D5 Psize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>8 F) c/ d- l% P. q* S/ g$ N$ G4 a
< ><FONT color=#0000ff>/* allocate memory to hold the image */
, N* C) Z j+ v7 K0 i$ uarrow = malloc(size); </FONT></P>
: {6 |$ a& h0 W- V/ B< ><FONT color=#0000ff>/* grab the image */ $ K0 o. _4 R- k, h& J1 Y. d
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
# i5 a( X: S) E+ c< ><FONT color=#0000ff>/* repeat until a key is pressed */
0 T4 H* v5 o$ ]4 |* \) y2 Y) uwhile (!kbhit())
3 j* h+ T: r S7 d{
; Y3 t' p3 h2 f5 c( g' ~( e" j/* erase old image */
( s/ T+ Z( A' x( J7 H( s4 Q' hputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>0 U9 f6 q- V' t) l
< ><FONT color=#0000ff>x += ARROW_SIZE;
7 [" u9 R5 }/ Oif (x >= maxx)
. v. G1 j: s1 Q- {x = 0; </FONT></P>
$ J4 S# t0 r3 R' x% y+ v0 H< ><FONT color=#0000ff>/* plot new image */ - g2 B2 i2 @: _7 j' G% {
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); & h" x* [, v. s1 w% n% S
} </FONT></P>
2 e' g$ _$ S, U5 m7 F1 C" }< ><FONT color=#0000ff>/* clean up */ 6 {( d& V- H7 M: }% ]$ `. ]. I! z$ r
free(arrow);
- Q/ v& l' X; I( u" X9 y: Zclosegraph();
3 D6 N# l7 N+ Y: w9 y( kreturn 0;
" L5 z7 O2 n# ?0 q8 ~3 H6 f} </FONT></P>( \1 b. f( d! v9 j s, k, z3 X6 P
< ><FONT color=#0000ff>void draw_arrow(int x, int y) & O2 ^1 q O) f4 ~4 E
{ % }2 z0 J9 r& J# D, @6 B V
/* draw an arrow on the screen */
! b- U7 c" y: W: X l4 P7 rmoveto(x, y);
( j8 u3 D$ D% c! a1 ?linerel(4*ARROW_SIZE, 0);
; A6 p8 A; ~8 ylinerel(-2*ARROW_SIZE, -1*ARROW_SIZE); 6 T* t) f: Y% N! g' v2 j8 l' ~
linerel(0, 2*ARROW_SIZE); 0 E+ ]. t: f- }
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 0 K" G+ a4 N4 c: A" h
}
6 p# b& }: N$ f+ x( Y/ m" g' B* A: p# m7 K, U. U
" |7 E0 }2 G' A2 v% V% k</FONT></P>
& g% U; U' }: t< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
; l0 v! Z% b: Y$ W! `<FONT color=#000000>功 能: 初始化图形系统
" m! K& d3 D" u" [用 法: void far initgraph(int far *graphdriver, int far *graphmode, 9 p( u( D0 `# {# z4 h2 j& ~) M' I
char far *pathtodriver);
( e! ]! h, ?6 l( I/ w' e( i; l程序例: </FONT></FONT></P>& M9 i9 |( I6 \: m% f" q( A
< ><FONT color=#0000ff>#include <GRAPHICS.H>
0 N3 j$ O: j# x6 U# G/ M# ~#include <STDLIB.H>
. d$ C: l9 x$ @' c/ e6 ~#include <STDIO.H>
, ^. ]' y" O( I7 F#include <CONIO.H></FONT></P>0 T' S% x; U+ ]6 \
< ><FONT color=#0000ff>int main(void) 0 A B* c" Y7 p; e5 m3 v) K. U8 f
{
# S1 }- z' k) A$ m! ^/* request auto detection */ 0 e* V% s8 l, s1 m m; A
int gdriver = DETECT, gmode, errorcode; </FONT></P>3 i6 i2 y& B2 G3 `) I5 n$ S
< ><FONT color=#0000ff>/* initialize graphics mode */ " C/ d5 o1 F6 F3 A5 Y% E$ ]
initgraph(&gdriver, &gmode, ""); </FONT></P>
# V4 y. u3 k! k- ^. Y< ><FONT color=#0000ff>/* read result of initialization */ 2 Z3 q6 A8 f# i* n! F0 k! [) C
errorcode = graphresult(); </FONT></P>' [8 o. B5 Q! J' k5 M' Y
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ % Y( A5 f# k: @
{
8 z4 X2 ?+ X; l) k9 P& pprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 `+ S7 n0 t& K4 C
printf(" ress any key to halt:"); , I" I& A/ k/ |! I) N1 Q
getch();
/ @8 J, ~; s* J5 }exit(1); /* return with error code */
6 x& j+ F2 v( }9 w4 m" |} </FONT></P>. ~! {% d( [. z% i$ A
< ><FONT color=#0000ff>/* draw a line */ 2 a ^8 _0 C4 r0 G+ E7 R
line(0, 0, getmaxx(), getmaxy()); </FONT></P>4 N7 \7 G% \* W% J$ @' D8 ]6 O
< ><FONT color=#0000ff>/* clean up */
2 m5 t1 w, C( k, mgetch();
5 i1 t: N* e9 h& v3 g5 ~6 y0 |closegraph(); ) |: l: Y7 `# ^5 Q9 t9 ~ y
return 0;
" R" ^% @( s+ U6 E7 G7 R" S} </FONT>
. f- q4 z7 s) {2 j. l) Y3 ]- | h
9 E/ J. [! G+ j2 R9 |</P>" K, t) a/ h/ R9 ~/ G
< ><FONT color=#ff0000>函数名: inport </FONT>
5 K( \4 t4 C# D5 O) l5 G) f( B功 能: 从硬件端口中输入
& G; ^* x( Q2 E" g用 法: int inp(int protid); m3 l0 a4 w& x! o& N/ Q3 T7 K3 B
程序例: </P>
! s) S r1 q0 j2 L' s. ~% L4 I< ><FONT color=#0000ff>#include <STDIO.H>
0 t+ `$ D, z3 H# {. s1 f$ {#include <DOS.H></FONT></P>2 K2 F! c4 d" y! z( F' J$ ?3 j ?
<P><FONT color=#0000ff>int main(void)
0 Z3 M, {; R3 G8 C{ + x+ j1 k: g+ P! E8 p) ^9 m
int result;
$ ?8 s! L7 m+ cint port = 0; /* serial port 0 */ </FONT></P>, T! @/ G7 R# f5 J# j
<P><FONT color=#0000ff>result = inport(port);
2 l8 I3 D& C% Z/ _% Xprintf("Word read from port %d = 0x%X\n", port, result);
$ h% k0 C7 k# L/ \/ Mreturn 0; $ K' {9 \1 s s" h# H
} ( C1 ^6 f0 D. w% K8 c7 X7 E4 D
$ p9 r K$ k W5 \4 l$ Q</FONT></P>
- p/ V0 i- K) F' z: p<P><FONT color=#ff0000>函数名: insline </FONT>1 U6 H: L( D5 G: j; c! ?
功 能: 在文本窗口中插入一个空行
" g( t% G: C6 g* P) ~( P' k用 法: void insline(void); , o, D, E+ D1 d9 Q* C
程序例: </P>
& l4 C3 W( w, }+ a, |<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
% D: @- j. l: D<P><FONT color=#0000ff>int main(void)
: o1 n( R. z4 e I! F3 _" Q{
# v9 z8 N1 I% J" fclrscr();
% W' [, A+ e3 @; M- X! b# W/ }6 Lcprintf("INSLINE inserts an empty line in the text window\r\n");
7 [1 y- u' t% c9 Acprintf("at the cursor position using the current text\r\n");
8 H7 B( ~ N4 g4 ?cprintf("background color. All lines below the empty one\r\n"); , |. I4 e J. g6 p4 u3 F6 }, A
cprintf("move down one line and the bottom line scrolls\r\n");
. s% b( r) {; q2 ^cprintf("off the bottom of the window.\r\n"); 3 G; K+ M6 Z2 w$ h: f& R
cprintf("\r\nPress any key to continue:"); 5 J: O6 C4 f8 ?
gotoxy(1, 3);
# i3 u# N# i- k+ k7 Pgetch(); " Y" x2 ~+ \1 W! K: [( G
insline(); 3 P5 }; @+ G; J7 ]9 Y8 a" i2 q
getch(); ! ?8 R% T2 N% \% G
return 0;
, I. w! X5 D# g; m& y} . Z( r4 K/ j' `
</FONT>
) [4 r' {5 K' t3 d) q3 \, j3 P% B8 k& e4 i
</P>
+ X# y+ o f/ Q* y0 S& `<P><FONT color=#ff0000>函数名: installuserdriver </FONT>' O1 v$ B, f+ P: r% o, Q
功 能: 安装设备驱动程序到BGI设备驱动程序表中
8 ?# A+ c+ h; }% I6 y用 法: int far installuserdriver(char far *name, int (*detect)(void)); & u5 S- x; M5 R! H/ V& r
程序例: </P>0 t5 v. v1 W2 g
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 s; Z l. I1 |2 t4 A) R
#include <STDLIB.H>$ p0 w6 K# N0 {8 R' l
#include <STDIO.H>
" i' q# B" T3 k8 l& M! e- |8 X#include <CONIO.H></FONT></P>8 ^$ i$ [: z* J J, C% W& X
<P><FONT color=#0000ff>/* function prototypes */
: d$ v9 A3 i) h9 e8 t/ |int huge detectEGA(void);
5 q7 R4 z& M. w& a. T, fvoid checkerrors(void); </FONT></P>
" _9 a$ ^% k5 x7 R* t1 I<P><FONT color=#0000ff>int main(void) 0 o( l0 E3 ~9 R! J% n' c
{
# V: P% ?, ] y) m; z8 u, t9 O( Nint gdriver, gmode; </FONT></P>
7 C" T [( F( {0 v. L8 n3 F7 d<P><FONT color=#0000ff>/* install a user written device driver */ 1 u/ O% v$ q$ N2 `+ |4 W# K F
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>7 A" w6 y! f5 z, T# U
<P><FONT color=#0000ff>/* must force use of detection routine */
% Y+ L+ H! q9 l& B2 U7 vgdriver = DETECT; </FONT></P>& S3 A8 J; X1 z7 m; k% _6 T
<P><FONT color=#0000ff>/* check for any installation errors */
; d/ o$ }7 A5 d \+ Zcheckerrors(); </FONT></P>
7 i, m& z: v( ~! E4 Q B% q<P><FONT color=#0000ff>/* initialize graphics and local variables */ # q. W1 N; |) C' C/ q
initgraph(&gdriver, &gmode, ""); </FONT></P>5 f4 G" _7 N9 w; q7 M
<P><FONT color=#0000ff>/* check for any initialization errors */
& t8 i3 }5 ?0 L# w2 G% \checkerrors(); </FONT></P>
$ f/ s4 c* \% t1 n/ W5 b<P><FONT color=#0000ff>/* draw a line */ 2 Z; m3 p2 u% O& P& c% r- D
line(0, 0, getmaxx(), getmaxy()); </FONT></P># Q! ], o2 ]: @, L( I/ W
<P><FONT color=#0000ff>/* clean up */ }3 P: l0 i# M ~, {7 X
getch(); 1 V# H, t e+ `, N- r- Z+ {. I2 d
closegraph(); $ r. ^" a. K q/ c9 _6 }
return 0;
5 \. Y& Q6 Z# {} </FONT></P>
6 c& b: D! H$ n& D- l<P><FONT color=#0000ff>/* detects EGA or VGA cards */ ! M' E$ B0 \7 p1 b1 O
int huge detectEGA(void) - }8 K" s1 d9 J/ E
{ ( D' d; { x: T- M' `* C
int driver, mode, sugmode = 0; </FONT></P>. P: |2 |9 n9 ?
<P><FONT color=#0000ff>detectgraph(&driver, &mode); & Y0 t+ ] I( l% J1 O
if ((driver == EGA) || (driver == VGA))
; Z) t2 h8 A. m3 r) T/* return suggested video mode number */
9 j+ l5 y+ x) Q: U' S3 g9 B' Hreturn sugmode; 6 }* T; {6 _# e
else - U+ z F4 v* Z
/* return an error code */
7 K, J; n) O3 b. r3 Z( V9 D, N# Zreturn grError;
' ^: V+ i; `: u* J( ^/ ^6 i9 d- U} </FONT></P>
1 Z' C& \4 y/ @, Y$ `& B" V, U<P><FONT color=#0000ff>/* check for and report any graphics errors */
8 \5 R: C3 P( o3 Tvoid checkerrors(void) * M0 P" L- e: ]; M
{
& t5 E& |$ p# v) S) Lint errorcode; </FONT></P>5 B2 M9 v2 s+ a9 X$ e. n* a& f: D
<P><FONT color=#0000ff>/* read result of last graphics operation */
, R9 Z, {6 r; S! w" w w+ T& O+ Zerrorcode = graphresult(); " J, z- S+ h; O3 k
if (errorcode != grOk)
! T' ]$ e! B& f; {3 N9 N{ / l7 I ? H" H+ P/ d6 d4 @: \
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 \. L% C$ e" M) a; g* O
printf("Press any key to halt:");
, J! E# g- ]: _2 S) Z2 X0 p( W2 ?getch(); " T3 \0 `* d' X1 Y
exit(1); 6 M# N, d2 d+ I' m. o
}
+ `! c2 O) {; ~$ \} </FONT></P>, `' E, ^* m9 w2 }; B# Z
<P><FONT color=#ff0000>函数名: installuserfont </FONT>5 I2 R! d4 P3 @! R" A
功 能: 安装未嵌入BGI系统的字体文件(CHR) $ q, I; r6 T5 L0 N5 K; |4 i) J
用 法: int far installuserfont(char far *name);
3 d! K6 B. P) @) `程序例: </P>
$ H0 v9 x) C7 w* O5 y. n* a: X k<P><FONT color=#0000ff>#include <GRAPHICS.H>
, ]# Y j* c% S* }& v& D7 z6 N _- R#include <STDLIB.H>
( O9 B& Y$ V2 a; M3 l" |#include <STDIO.H>
! ~: O% n6 _( l" b+ B" _) p#include <CONIO.H></FONT></P># ]2 [; t+ ~: q6 F6 {: U' L4 @
<P><FONT color=#0000ff>/* function prototype */ 7 ]9 F- \% V3 W4 {# k( f7 g8 S( g% z
void checkerrors(void); </FONT></P>
# k( O/ B6 T" \+ \ V<P><FONT color=#0000ff>int main(void)
- X1 B5 c# t0 k: t- @# b{ ! }, g$ s1 r4 i! ?4 l k7 C' X
/* request auto detection */
5 @. }4 }5 Z! a! t0 B8 lint gdriver = DETECT, gmode; 3 }. z- e+ h7 [# t
int userfont; c* t; g+ R/ {/ m
int midx, midy; </FONT></P>7 n0 C8 e% F# K$ W" C* F- q1 s
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 \$ A% _1 f' g. j
initgraph(&gdriver, &gmode, ""); </FONT></P>, F' j* m; Y2 @) Q( M" i' @
<P><FONT color=#0000ff>midx = getmaxx() / 2; 2 r2 T. N. j& j5 ~7 j# b
midy = getmaxy() / 2; </FONT></P>" `2 Q: W2 t# T. u6 z
<P><FONT color=#0000ff>/* check for any initialization errors */
1 f f: d( Q9 Acheckerrors(); </FONT></P>
, v. I; ?1 l" K( [<P><FONT color=#0000ff>/* install a user defined font file */ ) A# b+ H1 r9 }( X) n4 k$ G5 o* C
userfont = installuserfont("USER.CHR"); </FONT></P>. E% ^ v2 J( S& H
<P><FONT color=#0000ff>/* check for any installation errors */
$ N3 t' f9 R2 `4 c! }3 Ccheckerrors(); </FONT></P>
! l2 n+ Z$ e" q<P><FONT color=#0000ff>/* select the user font */
1 I( H$ ` W7 \settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
: X5 U/ N: c0 n- p8 M<P><FONT color=#0000ff>/* output some text */ 5 E+ R" q# r" Z: y+ l/ c
outtextxy(midx, midy, "Testing!"); </FONT></P>! q& Q4 c' H0 L1 l2 |( q
<P><FONT color=#0000ff>/* clean up */
z! [" A) p& \5 Q3 Y# dgetch();
6 `5 @& \* ]8 ?' \3 jclosegraph(); 1 Q. G* j y3 q1 w
return 0; , }% ?- }- X( z1 q$ _& A" D
} </FONT></P>
9 n; E0 G- e+ Y! K- W2 }<P><FONT color=#0000ff>/* check for and report any graphics errors */
( {- f; b& _$ K$ {+ E& Q$ W9 M6 B) zvoid checkerrors(void) 4 h* B. T0 B5 q2 \; D. i4 ~/ ~0 U
{
0 l. {: M$ i; q8 Q$ m# S- I: m uint errorcode; </FONT></P>
% w/ W8 O. R- I4 l! }) f5 j<P><FONT color=#0000ff>/* read result of last graphics operation */
; {( s- q$ b0 \( v7 f) T* xerrorcode = graphresult();
) s' ~! [+ e* g" |. s/ P8 ~$ h7 i/ [if (errorcode != grOk)
" A2 e4 b( K) |% C{
: Z# I [+ `7 V5 P6 f6 O+ Rprintf("Graphics error: %s\n", grapherrormsg(errorcode));
+ w' P$ K1 B7 A$ pprintf("Press any key to halt:");
' g; u' m$ g4 u5 ^1 b( \. rgetch();
" B! a. w3 u3 ^$ H7 C" S6 H/ [exit(1); 9 d5 B. h! v/ L) C+ }8 Y
}
1 B1 J; E" e6 a} </FONT>
$ J3 S w" c b- s5 G- ]- M8 }0 L1 @& K0 R& g9 h
& J8 z1 T, N# Q5 R</P>1 y' i8 }- F F; t
<P><FONT color=#ff0000>函数名: int86 </FONT>& |2 S. ]: A& y& f% O5 [
功 能: 通用8086软中断接口
( ~+ i+ T% y8 |( U用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); ! Z6 I0 F g* R6 `
程序例: </P>
0 O5 Q/ _) f) Z7 f( v `<P><FONT color=#0000ff>#include <STDIO.H>
% g% g1 y0 Y; B9 Y" _4 P#include <CONIO.H>
+ ~1 c0 N/ M7 v$ _5 l- ~* \+ U#include <DOS.H></FONT></P>8 A7 X7 p. Q9 c. D! |
<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
0 Y. i, ~- f" x. v& y2 Z/ M9 f<P><FONT color=#0000ff>void movetoxy(int x, int y) 0 n% ?) O3 d7 c6 y) T6 C) Q
{
5 \3 H3 z, }5 X4 sunion REGS regs; </FONT></P>
( X I4 }$ h M& s6 ~6 {<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */ - M j) o8 m, H1 Z, q, Z7 K
regs.h.dh = y;
" H) S" |* a& F" R5 B- K' q0 iregs.h.dl = x; . U! z8 f! }" P( h
regs.h.bh = 0; /* video page 0 */ % ^8 u7 S$ L, F! B
int86(VIDEO, ®s, ®s);
+ h2 v3 H- z/ l. H% z6 V} </FONT></P>
/ ~( ~- ?4 I2 y4 f9 B' V4 i<P><FONT color=#0000ff>int main(void)
; g- I7 r( Y7 e{
# }7 F b3 C- E3 Qclrscr();
! \1 q/ D/ ^+ J! h) bmovetoxy(35, 10); : V, {8 G& |3 @: ^
printf("Hello\n"); + K- w& K4 ^9 R5 c8 Q
return 0; , Q4 s7 L* y. w- Y7 L
} </FONT>/ S: U4 S0 Q. g r2 o H/ | \( |
: x3 }. Z8 g3 Y8 |/ N7 p5 ~( l: _
</P>
' L( r3 G0 j" s# a; k4 I<P><FONT color=#ff0000>函数名: int86x </FONT>& e3 M2 {& o, }3 m' K3 F
功 能: 通用8086软中断接口
) l( z" |6 r' J, V1 m用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, 2 p+ `% ^2 p5 S! t( H: k
struct SREGS *segregs);
I; O: X5 i8 X( U, E' ~5 h' c: Z程序例: </P>
4 U: y7 G" B, c! a! D<P><FONT color=#0000ff>#include <DOS.H>
+ e. j' h, U* c4 a2 h#include <PROCESS.H>
' E n4 B4 k4 B& `! F#include <STDIO.H></FONT></P>
* T6 ]/ L% z8 m8 T4 ]<P><FONT color=#0000ff>int main(void) . k% r& e7 A" s/ \ V' |
{
2 B- d" V' q5 U; d9 |$ f3 lchar filename[80]; 1 c0 a, d7 n, m" E
union REGS inregs, outregs;
" w" x" T) P% C0 _" @4 k" c7 Rstruct SREGS segregs; </FONT></P>
) ~* W. {6 Z. R( G F" o<P><FONT color=#0000ff>printf("Enter filename: "); + L, d# i+ P" m' X
gets(filename); : ^( x# d D' Q; |( N: q
inregs.h.ah = 0x43;
" ^* B* ] o6 Kinregs.h.al = 0x21;
9 ]3 l$ ?- [+ qinregs.x.dx = FP_OFF(filename);
' U1 c; m4 c" ksegregs.ds = FP_SEG(filename); 0 M; V8 A, Z, V2 p
int86x(0x21, &inregs, &outregs, &segregs); 7 ` d# {# ?" K2 J" c5 p; `" j. ^
printf("File attribute: %X\n", outregs.x.cx);
$ J, p0 G u! J7 ], J3 f% }) A3 sreturn 0; * f* {$ a% Y1 k
}
/ m, d b5 c3 D
# i- y' e1 ?6 r9 _, ?</FONT>! f0 m' G$ e% @0 O0 c* S
</P>
$ K# V1 h4 r) z! g<P><FONT color=#ff0000>函数名: intdos </FONT>
: y" f3 i+ \2 |9 b( ?功 能: 通用DOS接口
* A7 e5 Z/ R; D" ?4 v8 E用 法: int intdos(union REGS *inregs, union REGS *outregs); X: x! P/ j. d4 s" P9 p; w
程序例: </P>
$ {( q/ a9 @3 j& l4 I& Q6 d; x<P><FONT color=#0000ff>#include <STDIO.H>; [: Y+ V+ C+ M {
#include <DOS.H></FONT></P>: i4 q- ]8 K! O K4 B( f
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
! F+ K7 }) ^$ y8 _; Pint delete_file(char near *filename) * X& ]( J# C; u" K
{ & y$ r4 J9 J1 Z
union REGS regs;
9 }* d, u# [1 m7 w+ vint ret;
. N, Z1 v/ |" U9 V" \) v! Wregs.h.ah = 0x41; /* delete file */
( C9 n: v! ^" `1 Mregs.x.dx = (unsigned) filename;
+ c" \7 w6 {5 D. O2 c- Iret = intdos(®s, ®s); </FONT></P>
. \% Z+ K; A8 s- n: [<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
. @& B1 e, ?* K `3 q5 l3 U8 ~/ Xreturn(regs.x.cflag ? ret : 0);
% i. h7 t r4 Q( F% s( _} </FONT></P>9 a& H( D$ G$ T0 C j: Q7 Z5 Q) p
<P><FONT color=#0000ff>int main(void)
* Y4 W; I2 e6 S& Q{ 7 \7 Q4 |( ^' R, e
int err;
6 W0 J6 s1 ~9 {4 ierr = delete_file("NOTEXIST.$$$"); ! {! b0 g7 V8 }% u# N6 l
if (!err)
) C4 o' Z! E4 [4 D; V2 wprintf("Able to delete NOTEXIST.$$$\n"); ' h. C9 w0 L- e; t
else
% N/ q7 V6 O! U3 K0 b$ |8 B( t. u$ Kprintf("Not Able to delete NOTEXIST.$$$\n");
/ V4 m2 N# w1 N o! k& z8 Z7 ?return 0;
+ k' a( E% Y8 \. I3 w! C}
6 J4 {1 @( i1 p8 K( h! }" Q, g6 _* R* V' j( i
</FONT>
8 K1 f3 `+ a$ S& e</P>
+ E6 }: l2 y- C, }( s<P><FONT color=#ff0000>函数名: intdosx </FONT>
. B" \3 F" J) Q功 能: 通用DOS中断接口
+ o6 f3 u6 E2 c. o- f3 a用 法: int intdosx(union REGS *inregs, union REGS *outregs, ! K. k9 {( Z: z( F
struct SREGS *segregs); ! Q+ U' C! I6 F7 {% J
程序例: </P>
- A; c$ N9 v/ b# f& N<P><FONT color=#0000ff>#include <STDIO.H>% S" [$ y6 p v; I" T# Q9 `5 ?7 l
#include <DOS.H></FONT></P>
2 ]& o% U0 T1 \; T<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
' x1 S( o9 _' [6 ^! ^6 Nint delete_file(char far *filename)
5 l& L" x, n) F) S' [{ n. M7 Z9 U9 l, g+ w
union REGS regs; struct SREGS sregs; ) K+ h. H2 Z& l* y( p
int ret; 4 s/ l" X8 I0 G7 L
regs.h.ah = 0x41; /* delete file */
9 p9 C; F( y6 k% P" `0 B% \' J3 ~regs.x.dx = FP_OFF(filename);
# }2 y9 G5 ~: B: u. F" i* Q5 Vsregs.ds = FP_SEG(filename); 5 a; e% P* }+ h; V4 [8 @) H
ret = intdosx(®s, ®s, &sregs); </FONT></P>4 L5 R! h+ W; P- S) ?4 ~7 x" @
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
8 Y) B# W }( j7 D3 Creturn(regs.x.cflag ? ret : 0); 8 |0 h3 Q1 R0 W. a
} </FONT></P>
- @4 }1 \/ I% r! O) n! e3 w& z<P><FONT color=#0000ff>int main(void) % h6 i$ a1 ?$ F
{
" L+ V; L( ]7 p- H( V4 a: k) P, Vint err;
0 V( T1 U3 \% D4 `- W$ [- qerr = delete_file("NOTEXIST.$$$");
/ o! j' A" p" Y% R' {# e. l& B; U/ q4 mif (!err) 4 _/ o5 L# l' r0 T _3 N
printf("Able to delete NOTEXIST.$$$\n"); $ i. Z; o- I4 ^' v: l5 {4 G8 x
else ( v7 ~8 ]: H* D& h" o& ^* B; m
printf("Not Able to delete NOTEXIST.$$$\n"); : n7 d3 U3 _4 z! ~! \' e
return 0;
& s6 H6 ]) L) |$ e9 T) u} / i$ S+ Q$ _8 L5 ]! p/ y
</FONT>
# Y. T- F) J V! v4 C; R9 U6 w</P>
+ W& k8 y2 x% X2 l! e<P><FONT color=#ff0000>函数名: intr </FONT>
0 j5 M+ _! n/ y# [9 O3 I功 能: 改变软中断接口
8 {3 A; e8 ~1 W4 C) A用 法: void intr(int intr_num, struct REGPACK *preg); n! d1 A, q* N" Z0 p
程序例: </P>
5 f$ k3 t8 R! o! y<P><FONT color=#0000ff>#include <STDIO.H>1 E& W W/ l6 N: p) s: H
#include <STRING.H>
) }2 ?# e! {: Z& R+ Y8 L2 t#include <DIR.H>
2 M/ `9 u1 g' p6 I$ ~. _' A: q& `#include <DOS.H></FONT></P>
! V3 f1 Y a/ q0 e5 ^9 f<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>1 u- T8 a% a/ W, t2 V) O
<P><FONT color=#0000ff>int main(void)
$ X* m# `1 C' z5 `& V{ 6 C J! g& Z K- L& F9 v6 [
char directory[80];
4 [) ^/ L" ?% M8 C: o7 mstruct REGPACK reg; </FONT></P>
' f9 ^, Y2 a8 \9 j* r<P><FONT color=#0000ff>printf("Enter directory to change t "); 1 _# a) R; r% C" K
gets(directory); # N& |; x) E7 [8 r" L6 y' U, V
reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
/ }) t+ F" M; I, ureg.r_dx = FP_OFF(directory); ( [7 Y, J: Q* i. l, J
reg.r_ds = FP_SEG(directory);
$ O/ X D }. i3 v$ Mintr(0x21, ®);
3 F9 T' F9 m, o( Jif (reg.r_flags & CF)
0 ?) }1 B5 z% R0 b5 p! m) R" p/ Hprintf("Directory change failed\n"); 7 T- n( ~" V- y# ^( s$ W
getcwd(directory, 80); + \9 B7 k0 Z' w4 T N
printf("The current directory is: %s\n", directory); % i4 F2 C# T3 ~- u) w0 x
return 0;
" f. f" k5 }7 l} ' P2 [! ?9 w0 u- i: B0 G
</FONT>/ F3 m7 |3 w. o1 U
</P># _7 y0 J( \& B" `/ y+ f
<P><FONT color=#ff0000>函数名: ioctl </FONT>
) }/ D$ y8 {5 t功 能: 控制I/O设备
& t1 e& x- x2 c4 W用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
8 t" \0 d' ^- a6 S程序例: </P>" N- V% U$ b& v* p% ?* C
<P><FONT color=#0000ff>#include <STDIO.H>1 w, H, T1 C; j% x
#include <DIR.H>5 I3 ]6 B# m+ P3 m
#include <IO.H></FONT></P>
8 r0 G7 Y8 N# |* F) w2 V4 r<P><FONT color=#0000ff>int main(void)
7 l% Q$ t. }0 {{
' ?3 g: b3 | I8 N' n* ~: @( r0 ^) y: dint stat; </FONT></P>$ l, a: m& h4 B
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ & d2 `$ g( D) Q1 K& ?+ C
stat = ioctl(0, 8, 0, 0);
1 k" o4 B% o+ E2 wif (!stat)
6 I, z2 s+ w( N4 U+ x6 f# E m2 w* ~printf("Drive %c is removable.\n", getdisk() + 'A'); . w6 _ L9 ~' a6 z! ~
else
% q! Q; F) I/ p2 P, e1 Nprintf("Drive %c is not removable.\n", getdisk() + 'A');
8 n1 y& g. I9 n# areturn 0; # g( [$ z3 n# F4 L/ b5 p
} 8 D+ J' R& q+ l1 w! T1 B
n% }) r0 U6 ~2 i5 ?+ C: B</FONT>
' V! ^! p+ |/ @</P>. B) J. s+ F$ q# Q G
<P><FONT color=#ff0000>函数名: isatty </FONT>. u% `. _. q F' Z: N% L( @4 A
功 能: 检查设备类型 % \" M; Z9 d* S. b9 g; d) Q! g" Q
用 法: int isatty(int handle);
5 O* D2 O \; d( |6 Q4 b程序例: </P>
. P f) w) g3 H4 o* a1 `<P><FONT color=#0000ff>#include <STDIO.H>
! k+ j W2 y# m- [1 d#include <IO.H></FONT></P>* u2 `9 `. _6 ?, b
<P><FONT color=#0000ff>int main(void) $ o6 V! t+ ~; {8 Z S
{
8 M, e5 q) D" U! fint handle; </FONT></P>, p$ g/ f3 y" J/ d
<P><FONT color=#0000ff>handle = fileno(stdprn);
8 y6 O8 R+ k" U# h, w8 O1 cif (isatty(handle)) 5 i2 X! s0 o- P, \
printf("Handle %d is a device type\n", handle);
- T/ N2 r$ K' {2 lelse
9 S* U+ t) t# ^# T @3 _printf("Handle %d isn't a device type\n", handle);
! W" H2 q( x3 a4 K. }return 0;
7 s- x# u5 w$ V}
8 ]4 u. `) C o# l4 ^" r# @) r% T
* X7 D8 U$ J! r4 h( n6 m8 n</FONT>5 D6 \& u' L2 s# x+ @2 Z
</P>5 F3 a* w# T3 j G! H9 f
<P><FONT color=#ff0000>函数名: itoa </FONT>8 j) g' W B- r' e6 h
功 能: 把一整数转换为字符串
8 b. ~% C. D: d. Z! }; t1 c5 e用 法: char *itoa(int value, char *string, int radix);
4 p6 a! f) F2 f( [5 S程序例: </P>/ m: {! o9 n& ? w
<P><FONT color=#0000ff>#include <STDLIB.H>8 F4 M0 t" G" w5 ~' Y
#include <STDIO.H></FONT></P>
7 h7 W/ A6 S& |$ ^- q$ l<P><FONT color=#0000ff>int main(void) * I. |: U" [5 J$ ^
{
& |: l& j6 v: H0 w- j5 G# ]int number = 12345;
4 q# E; g5 G9 e: H! f' u$ Dchar string[25]; </FONT></P>- _5 m$ \4 y0 ^% u+ \/ t
<P><FONT color=#0000ff>itoa(number, string, 10); - ]4 ] |, p# ]4 ?' l
printf("integer = %d string = %s\n", number, string);
! S" f0 o, t$ E! o$ {return 0;
# z9 t$ D" \9 P7 u} </FONT><FONT color=#0000ff>
. I0 e- k( P! E: V. P</FONT></P> |
zan
|