数学建模社区-数学中国

标题: 函数大全(i开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 02:59
标题: 函数大全(i开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>7 c9 }! d5 x6 J+ i3 i
< align=left><FONT color=#ff0000>函数名: imagesize</FONT> 9 K4 U) q, o" U1 ]
功 能: 返回保存位图像所需的字节数 . a0 A6 g" L3 i9 x
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
& I- W" F5 O+ `9 v程序例: </P>8 W% C# [/ C1 L! o( H. n$ s$ M
<><FONT color=#0000ff>#include <GRAPHICS.H>
8 [: f* j* @, D#include <STDLIB.H>
: c% G2 S& u4 \. d- z. {# ~#include <STDIO.H>
/ s& a: C$ }) K0 {#include <CONIO.H></FONT></P>
# Y% q. V. S1 A, F: g<><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>: d. e/ {0 w* g' ]
<><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>
6 r5 A5 s) f# y$ R3 d$ ?# `<><FONT color=#0000ff>int main(void) " u; K5 Q: z$ p
{ ( l$ l0 b  Y+ q0 T
/* request autodetection */
' T: L) \0 z! N) yint gdriver = DETECT, gmode, errorcode; 8 O. N4 X# q3 `4 X) x) K
void *arrow;
8 ]9 L# j3 j3 |* V# Rint x, y, maxx;
7 s1 p! B. }$ s) ]unsigned int size; </FONT></P>8 L  Y! F# Y1 p7 ~/ H6 Q
<><FONT color=#0000ff>/* initialize graphics and local variables */
( c; P9 b7 D5 i9 P. f/ _9 Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! a' U) P3 ?, ]  L+ F( [' u% `% ?3 I
<><FONT color=#0000ff>/* read result of initialization */ 4 e# V( r  S  a
errorcode = graphresult(); 0 D! \3 c6 E  k8 y4 U' ]( h& e
if (errorcode != grOk) /* an error occurred */
2 d. P" i9 [! \; C, V% a6 ^+ \# R; f{ 3 }9 p5 d5 U; u5 n
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) L4 v' o; v& n" \7 D5 x. @
printf("ress any key to halt:");
  q- T0 E* J& s. k% |4 Sgetch(); - _* M1 y/ G- X9 @& n- ^! L* A
exit(1); /* terminate with an error code */ * Z7 w% L' Z3 c+ _
} </FONT></P>+ ^: L2 A* h+ T% R
<><FONT color=#0000ff>maxx = getmaxx();
0 s6 u0 H- S; ?4 [+ t$ l: o& T. mx = 0;   j2 S0 f0 `. J$ G1 |6 \
y = getmaxy() / 2; </FONT></P># {+ ?. G$ ~: z9 \5 U
<><FONT color=#0000ff>/* draw the image to be grabbed */ 7 z; K- a6 c5 F( X4 I
draw_arrow(x, y); </FONT></P>
2 D9 J# T# K, [0 x' b% m<><FONT color=#0000ff>/* calculate the size of the image */ 5 a3 U" W' ]. W) j8 V
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>
* i. D" A  o: ?  C6 \3 R( L& R& A<><FONT color=#0000ff>/* allocate memory to hold the image */
2 I8 p; ?9 _! u7 {5 narrow = malloc(size); </FONT></P>
# u7 z9 e, f8 S& z$ z* C8 u<><FONT color=#0000ff>/* grab the image */ + @. B# N: x' Q2 D& y; t! U* C$ o- d
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
# Y. E) c& J8 k$ E9 e<><FONT color=#0000ff>/* repeat until a key is pressed */
( f1 F  q4 K% D8 z* i3 j- L3 xwhile (!kbhit())   w: H7 s, Q+ B% Z' a
{
% B4 y' f$ I; G( |' t, Z/* erase old image */
3 I: D+ G3 c" {$ Rputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
: F3 c: ?8 c2 [1 d<><FONT color=#0000ff>x += ARROW_SIZE;
6 K. V7 G  b+ P4 v/ p- l, Tif (x &gt;= maxx)
# r& P+ [  v5 t# j' S' cx = 0; </FONT></P>; Z- l& D: w2 m7 x* d8 o
<><FONT color=#0000ff>/* plot new image */ 8 U- W- L' v( a; W6 W- y: x3 ^/ p
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); ! M3 @- s5 @5 c
} </FONT></P>
7 |* [( `0 R- ~# i8 c/ u<><FONT color=#0000ff>/* clean up */ % {! a& d# ^7 E6 v* o
free(arrow);
% S$ E8 T5 [( F9 P1 T' I' ]closegraph();
3 |' E) D& c; J" k4 a& Kreturn 0;
- C5 q0 h( a2 _} </FONT></P>0 x  b  c8 E; N9 I, k' y
<><FONT color=#0000ff>void draw_arrow(int x, int y) 4 v% p3 a) C) A
{
# ^. x  f7 q& K% ^/ \/* draw an arrow on the screen */
* p* y4 [& ]$ c, ]6 u4 fmoveto(x, y); ! f0 U2 L7 W" `6 j8 b! n% j
linerel(4*ARROW_SIZE, 0); # a. t; d/ r$ m: Z( W  q
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); # G* E: j  R) E! }
linerel(0, 2*ARROW_SIZE); . @5 m4 h& i# \  I1 H: y" [
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); . P& N8 C% r. v3 i/ S+ b+ ^
} * ~0 L9 z0 p# I  V' F
; @" D, H: o7 s) A2 a. N

- C% K; O9 W1 e; C, Q' F3 w</FONT></P>
# \) `2 Q) b, G# w- i+ Z. z<><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>3 |* n  `0 S+ G6 h. c) X2 u
<FONT color=#000000>功 能: 初始化图形系统 ; r% ]% T( T8 C. h0 J' X
用 法: void far initgraph(int far *graphdriver, int far *graphmode, 8 ~) w# T! v9 ^, b
char far *pathtodriver);
9 h6 q; ^# }# |7 A, R! U' b程序例: </FONT></FONT></P>
7 O* _* U" j, M1 L' [( x4 w<><FONT color=#0000ff>#include <GRAPHICS.H>- u- x6 c  q$ z; n3 n
#include <STDLIB.H>0 s3 x; h1 {5 @% Z0 n; L
#include <STDIO.H>/ }7 P: i9 F9 q" I
#include <CONIO.H></FONT></P>5 u" r0 ]: l9 @9 R; f( P0 y5 H* Z
<><FONT color=#0000ff>int main(void)
4 c& o- V8 s* j! W  ?- k{ 5 R1 h3 X* p/ i% s+ k" q
/* request auto detection */ ' f. b# w1 N- o" w0 N8 k2 F$ f4 `
int gdriver = DETECT, gmode, errorcode; </FONT></P>. {# `3 q( W. d5 n2 h8 G$ O
<><FONT color=#0000ff>/* initialize graphics mode */
8 i6 I0 ~* \/ ^2 Vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; d/ E0 i% u4 X' V/ b<><FONT color=#0000ff>/* read result of initialization */
0 v8 M2 G1 f0 Q' o8 H1 _1 Verrorcode = graphresult(); </FONT></P>
4 v/ J: |3 H: p0 `5 @+ U- H0 n<><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
& Y- V3 I  M. S5 m' u; K$ ]8 H{
! a1 z- i* m/ u7 Mprintf("Graphics error: %s\n", grapherrormsg(errorcode));
& b: f4 K# |3 E; Y8 u$ Mprintf("ress any key to halt:"); ! ?# v  ~8 D3 O$ u- L0 m
getch();
3 X* N; j: b/ m# {) f7 G! E8 z- Jexit(1); /* return with error code */ : |' `0 x9 H) m/ \( p6 @1 e
} </FONT></P>
- t& c( j3 c$ {2 A; K<><FONT color=#0000ff>/* draw a line */
0 H0 t9 V; m& O. Xline(0, 0, getmaxx(), getmaxy()); </FONT></P>% Y2 A" J) a& \3 P: h
<><FONT color=#0000ff>/* clean up */ : G+ k3 K1 a% o6 X
getch();
2 C. P+ r6 C& u. Y) M# Sclosegraph();
, V& x! W: g/ `return 0;   u+ L, N1 W6 S7 s
} </FONT>
. k" }3 a, A9 d& t- {3 t
: k) p+ r" p5 r' d. x" }</P>1 [8 \; t. I7 [* _3 w" y
<><FONT color=#ff0000>函数名: inport </FONT>8 J0 V8 [$ A4 @/ Q+ B
功 能: 从硬件端口中输入 6 M0 Q6 f) z7 S3 W6 W5 F
用 法: int inp(int protid);
% C. A5 p, z+ I8 a, y1 Q) }) v程序例: </P>* K; l7 v; {4 g* r& P
<><FONT color=#0000ff>#include <STDIO.H>0 P: {8 c" O+ \' ~( w0 H1 U/ V
#include <DOS.H></FONT></P>( G9 ^  k9 w3 Z2 J4 N8 @2 G9 `# O
<P><FONT color=#0000ff>int main(void) ! a$ h. ?7 q8 M$ e2 d$ P: I
{
3 c$ X% G. N! a( Z/ K+ Oint result;
9 L- a0 l2 e0 D3 k9 _- dint port = 0; /* serial port 0 */ </FONT></P>
% U8 N5 R( _3 J& C<P><FONT color=#0000ff>result = inport(port);
: v; U. S, l, R1 z3 oprintf("Word read from port %d = 0x%X\n", port, result); : C9 y" \  e$ S9 _' c6 `; _
return 0;
6 r9 u  \, G7 ?1 j$ E7 s9 U! |}
* A. k2 s) n- F$ @1 d* k, w+ S6 W5 t) z5 U8 k8 S
</FONT></P>* E* ~) V" F8 }2 b& ^
<P><FONT color=#ff0000>函数名: insline </FONT>
0 t' J9 v& p# y$ W; w6 _功 能: 在文本窗口中插入一个空行 + F; e2 G* d# {7 ?9 a
用 法: void insline(void);
2 Q2 p5 s, ?  w. m9 f程序例: </P>
+ M9 |# A8 t% W<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
( c# S" U" }" d2 K) Y* Y% \6 ~<P><FONT color=#0000ff>int main(void)
$ p+ x: e% `1 J/ A{ + a5 u$ H& p. o- A$ m, k7 |; s
clrscr(); 9 q. O5 o  h* C/ ?6 o
cprintf("INSLINE inserts an empty line in the text window\r\n");
4 D/ r9 n* E$ @1 i( V# Z$ Ccprintf("at the cursor position using the current text\r\n"); 8 q0 `( a  r; v( t  @, d
cprintf("background color. All lines below the empty one\r\n");
3 {) L3 C  c) l" N  j8 k/ ?cprintf("move down one line and the bottom line scrolls\r\n"); : D7 G8 E; i! X! E% V1 I+ v* ^
cprintf("off the bottom of the window.\r\n");
" ]" u9 n) p9 X" ncprintf("\r\nPress any key to continue:");
) W( V8 T6 ?/ T$ Xgotoxy(1, 3);
% W% m2 O) Q) j5 s0 @+ tgetch();
7 S3 L8 [! i# R) Y2 S, i+ I4 ?  Zinsline(); + n5 F9 Z; n/ H8 v; J2 g5 ~) d+ z
getch(); " |* ~2 l$ j$ W7 K3 J3 P8 C" X
return 0;
( B: K3 O" F! c& Q4 f} * m9 H  r0 S1 ^. c9 H9 ]: Y9 D
</FONT>- C# p" u6 W5 C! s7 K2 }" _
  T: U8 }6 S" W1 X: P. p3 N
</P>
( M' }! T- w2 X9 P! h& s<P><FONT color=#ff0000>函数名: installuserdriver </FONT>2 ]: {- [4 n+ X; _
功 能: 安装设备驱动程序到BGI设备驱动程序表中 2 y1 U5 x$ g3 l) z$ n7 Y! f
用 法: int far installuserdriver(char far *name, int (*detect)(void));
2 T4 Z& U3 q9 h7 q  U# N程序例: </P>4 L0 p" C5 x' L( T! l4 U+ ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>: h) s6 A9 l' b6 ]6 R
#include <STDLIB.H>
  y* O" w$ V# ?- }7 w/ G#include <STDIO.H>0 i* _0 B) c5 n! X+ \: A( }( f; y
#include <CONIO.H></FONT></P># A" p' w' }5 g' T
<P><FONT color=#0000ff>/* function prototypes */
* ]+ z' `, Y; A" r; L! @int huge detectEGA(void);
. _2 j0 P9 ~; d  `; z4 Tvoid checkerrors(void); </FONT></P>
' f  f4 r$ x' b$ F6 W+ C1 N<P><FONT color=#0000ff>int main(void) ) d1 ]7 M! {4 D
{
! n5 T- P: n+ {' @int gdriver, gmode; </FONT></P>( u) Y$ F! _$ m2 I  ~
<P><FONT color=#0000ff>/* install a user written device driver */
2 Q: T; y8 R- K9 v9 Y! c$ Ugdriver = installuserdriver("EGA", detectEGA); </FONT></P>' x  T; Z8 ~, E- a  G. z7 v0 E
<P><FONT color=#0000ff>/* must force use of detection routine */
- g% b) V/ f# ?) E( ggdriver = DETECT; </FONT></P>' q6 n% P% |: E3 N' F- X+ V
<P><FONT color=#0000ff>/* check for any installation errors */ . i! S& X: h1 t" o7 C0 h
checkerrors(); </FONT></P>
" |) k$ q* w$ g- e# J% b) t/ h( i! J<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ o7 Y5 U3 e6 d6 xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; R! {+ b7 w( r  W: y, Z3 D
<P><FONT color=#0000ff>/* check for any initialization errors */
7 C2 Q5 S) D! _! w1 W* T+ X5 Bcheckerrors(); </FONT></P>' q3 G/ @! L# l4 \$ p; |: P  _
<P><FONT color=#0000ff>/* draw a line */ ( [- X$ U( d! n# P$ H7 P% [2 ]
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
/ n+ V- D$ Q4 V/ Z* [# F<P><FONT color=#0000ff>/* clean up */
; p5 k! _9 z) B2 m3 U4 ~getch();
+ h6 Q. f: }$ {5 C' W& |6 Eclosegraph(); ! v' |7 I- H# w
return 0; + t& [- l0 x$ w+ z1 s4 u: ~
} </FONT></P>
$ @* {; O2 i& b0 t# U* n# P<P><FONT color=#0000ff>/* detects EGA or VGA cards */ 5 E: ?* W9 `; K
int huge detectEGA(void)
$ \0 R$ [' q9 d4 M2 _{ 3 K# K" K+ o' \# z7 l
int driver, mode, sugmode = 0; </FONT></P>
. h' ], r6 ~( {3 [8 ?7 c<P><FONT color=#0000ff>detectgraph(&amp;driver, &amp;mode); / S. |6 l& D5 f, D/ l6 A
if ((driver == EGA) || (driver == VGA))
: \, {5 ]! _1 b7 m# J2 W# L# U# B4 }/* return suggested video mode number */
& [+ v7 `  D6 z3 Rreturn sugmode; # v5 E3 }: y- `( M# `+ s! M$ U
else
0 M  U3 D! Y" M, e, B/ w" B& j/* return an error code */
! c$ m# T( y( ~2 ereturn grError;
+ K# c7 Q2 H0 |& \( v) R} </FONT></P>" D8 @' K: ]+ b( [5 m2 G2 p. ^& A
<P><FONT color=#0000ff>/* check for and report any graphics errors */ / a0 P- ?/ d, T( i* k; K
void checkerrors(void)
6 y/ [! k1 {, n7 a% ^' M{ 9 a9 n/ ^; \8 a7 `
int errorcode; </FONT></P>
+ U/ a- Y" N) n( P0 }+ f<P><FONT color=#0000ff>/* read result of last graphics operation */
! {3 d2 u( X  herrorcode = graphresult(); 2 t) c) g( H# a4 p  i) M
if (errorcode != grOk)
2 p! [5 ]1 U! {" c+ X6 Z{
2 O6 f' G4 `; v0 H* x  c4 z8 Vprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 o6 N5 q4 S) t
printf("Press any key to halt:");
5 g0 \+ M: `! D* pgetch(); 8 z, a6 p' M1 l+ B
exit(1);   i& p6 A2 a* D" R1 H- p. z
} / A. e, d( N3 a/ i: ?7 b3 D
} </FONT></P>
5 c! s2 Q( ?6 I* J% h9 i( E- f3 b<P><FONT color=#ff0000>函数名: installuserfont </FONT>2 O" I; {0 u; P. L. }! T( [" l
功 能: 安装未嵌入BGI系统的字体文件(CHR)
- W6 B8 d* Y' V. A- z$ K/ D用 法: int far installuserfont(char far *name);
! F5 @, \- \" M0 e程序例: </P>7 O+ d6 S  p( ?! O- s
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ K% O) M+ A& y#include <STDLIB.H>& p, O1 m  B1 V5 b( ~+ T/ c
#include <STDIO.H>. \* E! {9 U; M1 N/ M1 ]  a
#include <CONIO.H></FONT></P>- M; d5 Y9 {/ w; O# A$ N
<P><FONT color=#0000ff>/* function prototype */
( x# |* Q5 A4 _; Bvoid checkerrors(void); </FONT></P>6 E9 f) K) v+ Q& P+ c; V+ _2 w3 W
<P><FONT color=#0000ff>int main(void) " Q- D' J, Y- L5 ~
{
8 U3 [; K( W0 N5 M) v) g" O/* request auto detection */ 6 A( x6 T5 @( `  X- L
int gdriver = DETECT, gmode;
$ _" X: Q/ Q( D" ]3 `# |* P0 X$ o$ Aint userfont; 0 l3 `# S( w, @( D
int midx, midy; </FONT></P>
* a6 g+ N2 x; N2 Q$ E' S- ^6 ]; h<P><FONT color=#0000ff>/* initialize graphics and local variables */ * \1 B" V. ~, l6 t8 R9 O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 y. a* E2 a6 \. \  E. X: E$ I<P><FONT color=#0000ff>midx = getmaxx() / 2; ( H9 @6 N+ f3 ]* P) r. c
midy = getmaxy() / 2; </FONT></P>
( h% a) }1 W! @/ z6 ?  x<P><FONT color=#0000ff>/* check for any initialization errors */
# R9 k+ f% @2 jcheckerrors(); </FONT></P>2 p" d0 y8 I4 m% V6 k
<P><FONT color=#0000ff>/* install a user defined font file */
% U/ g0 S8 i0 }- Fuserfont = installuserfont("USER.CHR"); </FONT></P>9 f# y0 ^8 t8 C" W" C
<P><FONT color=#0000ff>/* check for any installation errors */ , t0 }9 S, A& u' Q: O3 N
checkerrors(); </FONT></P>
- _# }8 R9 Q0 c' F2 B% v0 S<P><FONT color=#0000ff>/* select the user font */
5 n% P1 V* Y7 p' P( `5 b# n' I8 csettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>! z4 ?5 X: \. [! R- e
<P><FONT color=#0000ff>/* output some text */
# @" b1 k4 F& E9 X% Bouttextxy(midx, midy, "Testing!"); </FONT></P>
% X3 R2 D0 V8 i<P><FONT color=#0000ff>/* clean up */ # ^. R' @) [* s# s5 B
getch(); % u7 r' U1 L" o# h' w6 O. \) I7 v
closegraph();
3 z9 v* r3 q, P, v6 z3 k) Treturn 0; ) ^8 z% W8 l& {( `* ?5 A) c
} </FONT></P>
5 q$ h# f, ?+ y1 x5 w/ \& K! Q) a<P><FONT color=#0000ff>/* check for and report any graphics errors */
& {# `) ]& ~. G, T3 gvoid checkerrors(void) 5 ~. b8 w5 z" ]0 o4 Y+ n
{
/ f' x0 g$ e. R. }# dint errorcode; </FONT></P>. v. T) p5 N. N9 Z. x8 m5 @
<P><FONT color=#0000ff>/* read result of last graphics operation */ ( P0 {( V# w3 Q/ J# k, w1 ~+ b/ _
errorcode = graphresult();
( a' |0 [! u* A: N  d$ o0 Gif (errorcode != grOk) 4 \4 b. F1 q+ m: c" `* a
{ 1 g- ], S# E" X! v8 b
printf("Graphics error: %s\n", grapherrormsg(errorcode));
' o5 C9 N: [, Z' D7 @. sprintf("Press any key to halt:"); " \' ~) K$ x5 a4 b- f  u
getch();
$ ?0 H" h* I# oexit(1);
% G, Q0 Q9 B! |# e6 p8 U5 K}
5 F6 e! C# u8 Q4 G} </FONT>0 x; {9 M; r4 m8 R( k7 z9 b
1 a; m, D5 y! y8 D( G: a1 M

# K- w6 Q6 W4 O. N1 U) k! N' Y6 D8 k</P>/ ?* j' Q9 ^/ V7 m! h# R6 H" z- e8 S
<P><FONT color=#ff0000>函数名: int86 </FONT>
4 |% ^7 X4 `- U5 ]5 F/ H$ ~功 能: 通用8086软中断接口
! L% ?' _3 y8 u% B, m) t用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); / f8 I- d; |" z$ O
程序例: </P>
. z2 q5 |0 R$ M4 w- _9 o& v+ `<P><FONT color=#0000ff>#include <STDIO.H>
  G. @$ ~1 ]- Q+ D4 W3 c#include <CONIO.H>
) Z2 E3 G/ V- v: u0 Y7 z6 U. e! _#include <DOS.H></FONT></P>
9 C$ Z7 y' v8 \<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
9 ~# a( f3 s8 R" w<P><FONT color=#0000ff>void movetoxy(int x, int y) 5 r. B+ t+ D9 b; b- ]! }
{ / y- z, e& X- s/ }% }$ t9 z7 r
union REGS regs; </FONT></P>
; ]6 o, ]0 L5 y7 j2 F<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
2 R' u- ^- S2 Z2 \+ Z! fregs.h.dh = y;
5 V7 l3 S- d' l% t! Xregs.h.dl = x;
& w2 ]1 b9 M: V) s/ Wregs.h.bh = 0; /* video page 0 */ 8 Q, _9 l$ x$ k6 f" `
int86(VIDEO, &reg;s, &reg;s);
3 v) N- T! M" u. v9 g2 _5 `1 J; `} </FONT></P>5 ~3 }* O3 I* N' y  V. n' e
<P><FONT color=#0000ff>int main(void) 3 {3 M! V5 [* A2 q7 X: a* z& N
{ ) j1 K' j) ~' i/ _8 M' u
clrscr();
: C5 Y( v4 {9 v$ [+ pmovetoxy(35, 10); 6 W2 p) R/ V8 O6 b( w
printf("Hello\n");   D/ i7 y: O3 ?0 y2 p
return 0;
8 A4 B) |, G  _. ?* \} </FONT>* I8 R8 A, w0 d$ |# ^) R/ Z
( h3 h9 d2 s, z$ b
</P>
% V: B6 x1 w8 o. B5 c. }. t# a<P><FONT color=#ff0000>函数名: int86x </FONT>
7 M" L& s2 m7 X6 A/ U功 能: 通用8086软中断接口 % J, @; n: g% a
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, * L. G! ]: s. \- z. p
struct SREGS *segregs);
- D6 J! S9 O& l程序例: </P>: j$ l# d, k. c0 P
<P><FONT color=#0000ff>#include <DOS.H>, ~# ^( p& }7 \0 u/ s" X8 q6 W
#include <PROCESS.H>
( z: z9 G+ ~/ o4 _6 ?$ c# h- `#include <STDIO.H></FONT></P>8 B/ _, f5 z: Y& }, {/ k3 }  @" r
<P><FONT color=#0000ff>int main(void)
2 f& T: t, k  E; F) e{
) A' b% e: F& j; }$ Cchar filename[80];
& m% n) _2 W% tunion REGS inregs, outregs; $ V3 F' q- S2 @2 u# O8 U) D5 ^
struct SREGS segregs; </FONT></P>
; U2 A1 w3 h7 r<P><FONT color=#0000ff>printf("Enter filename: ");
5 s! `' [; R) \gets(filename); 9 h4 ?6 w& n& M; h( i8 Y  J. D. d
inregs.h.ah = 0x43;
, l8 x; L( @# N# U- Rinregs.h.al = 0x21; ' R& n+ J5 C$ u$ h
inregs.x.dx = FP_OFF(filename);
3 z( v' M9 t- ?4 N0 Z# j0 k3 fsegregs.ds = FP_SEG(filename); % Z7 ?1 G. S" N0 y- X* D2 B( Y
int86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs);
( D5 g' _; H, @: J  iprintf("File attribute: %X\n", outregs.x.cx); / {5 y' T% ]; t  W: K
return 0; # A( d" ^  e  K5 c# i9 N/ ~5 [  j
} % d! k! n8 Q7 p! Y
; N0 G  J0 _! m; s  m- F
</FONT>
6 H4 G7 H8 h7 \</P>2 q& w) f3 c9 n  u
<P><FONT color=#ff0000>函数名: intdos </FONT>
1 @+ S/ I5 q9 |$ ~: c; I功 能: 通用DOS接口 ( q3 H3 U* }) W" H" ^$ x5 t
用 法: int intdos(union REGS *inregs, union REGS *outregs);
: W  A' W3 s% Y7 E: [4 T% R" N  S程序例: </P>
$ Z) C* ?* D0 I<P><FONT color=#0000ff>#include <STDIO.H>- b% Z; K# b2 n- L9 ?
#include <DOS.H></FONT></P>9 w0 n% A( ?% J, C0 `2 \2 l* ~
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
/ u! i' ^  Z% ^% F9 q+ oint delete_file(char near *filename)
7 a) A. d3 S% u, b6 p6 n7 t# ^4 e# N{ 0 z$ F* Q$ H: I
union REGS regs; ) n' w7 z4 s) t7 z
int ret; : A: q7 ?  C# {9 a
regs.h.ah = 0x41; /* delete file */
' p6 c- J4 j" d* y; C% \6 }# }regs.x.dx = (unsigned) filename;
7 }& b4 V$ u9 Q9 {" pret = intdos(&reg;s, &reg;s); </FONT></P>; ?& _( v, R4 j' Q: O: g+ H
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ 5 F8 r* P- N+ w$ i: ?7 m0 ]
return(regs.x.cflag ? ret : 0);
' r6 K: q% w4 L. h9 L/ a} </FONT></P>
( l3 z* ^7 C& V3 D/ g<P><FONT color=#0000ff>int main(void) ! c% x6 ?' |8 X8 g
{ ; U: M/ G5 E8 j9 p* A, j( C4 n
int err; 6 T" I2 \  V0 ^' k
err = delete_file("NOTEXIST.$$$"); 8 R+ {! |* g8 F9 h
if (!err)
. {; b/ I( R. Cprintf("Able to delete NOTEXIST.$$$\n"); : J  a/ S  T1 N
else - h, c" g$ H9 X
printf("Not Able to delete NOTEXIST.$$$\n");
! Z* E) J. c! n8 I) j% l! |return 0;
8 A7 K$ B. i" c/ w/ h/ j2 g" X}
* H* v8 e/ c: e) }& m3 A2 g
1 b8 @8 h8 `+ {* r' @+ R3 Y, P</FONT>
8 S! _, ?# `* j) T1 f' q4 _, R5 e</P>& Z* |" ^# K- ^* g6 t
<P><FONT color=#ff0000>函数名: intdosx </FONT>" g3 A/ C, V- O0 i3 D5 p
功 能: 通用DOS中断接口
7 j# @* @% a9 u# i0 z- R4 T用 法: int intdosx(union REGS *inregs, union REGS *outregs, % E7 ^+ F3 k, m
struct SREGS *segregs); % R! B& \( [& Y# ~. t! D
程序例: </P>
+ k- g! G* j# n# N( u/ p7 G9 D<P><FONT color=#0000ff>#include <STDIO.H>% S1 z1 F# K/ q$ m" c/ C5 b
#include <DOS.H></FONT></P>; @! E' i) B# _: ?
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
9 ], g. a& j4 Y) F2 Q8 Rint delete_file(char far *filename)
0 \$ S9 R0 g5 A2 \! @; x{
$ X9 k5 ^! t1 [union REGS regs; struct SREGS sregs;
+ j, u! b* E( `) m1 Sint ret;
  _8 q, D/ ^% B5 g7 ~( @regs.h.ah = 0x41; /* delete file */ 5 e3 r8 V( ~8 B9 L6 n- ~9 g
regs.x.dx = FP_OFF(filename);
: Q0 C: J$ s* H7 f5 Xsregs.ds = FP_SEG(filename); * G; a- ^" d& t( P' V
ret = intdosx(&reg;s, &reg;s, &amp;sregs); </FONT></P>
& |  H( ]: K* ~<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
% r& G2 g+ h  p- s4 C( D. ]return(regs.x.cflag ? ret : 0);
" H5 x* `0 p) D; j} </FONT></P>
# O) {  o6 T5 K; W6 O* d$ A2 Q<P><FONT color=#0000ff>int main(void)
7 {" Q4 W6 R- |{ 2 U( n7 B1 `7 k7 w2 K
int err;
3 {/ I+ r5 B2 v+ c; X, B. Merr = delete_file("NOTEXIST.$$$"); 7 i  ?. q0 R2 K
if (!err) ) u* g. z. q- h: `2 a6 t; J. s3 x+ g
printf("Able to delete NOTEXIST.$$$\n"); 1 R; s. K2 G9 G# |* A
else $ B( e7 u9 k: d# x7 X" v: v, `
printf("Not Able to delete NOTEXIST.$$$\n");
- |( Y$ l, r" _) w. Z  hreturn 0; # p( i# R$ D. Z+ _$ V
}
! ?! Q5 t( {5 L' U* [1 U</FONT>3 {3 s5 {5 H/ ~. t7 K& o
</P>
& A9 W. ~% D& w2 p4 g" O' r<P><FONT color=#ff0000>函数名: intr </FONT>
* n: V# Z  u% k# S5 K功 能: 改变软中断接口
; x& ^/ l/ @* ^0 C2 u- T3 F用 法: void intr(int intr_num, struct REGPACK *preg);
  m. \/ I1 ?( `9 a7 B3 ?程序例: </P>2 @- k7 C% f9 Z$ p0 W+ l
<P><FONT color=#0000ff>#include <STDIO.H>
3 D; v+ s' ~& ]5 \/ P#include <STRING.H>0 ~% P) i; F( }  v( W& o9 N
#include <DIR.H>
# V& f. ^- n2 t' o#include <DOS.H></FONT></P>" Q7 j  ]" @: v- I
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>/ i: z# b+ g0 n1 k: H. Q/ b
<P><FONT color=#0000ff>int main(void) " x* k9 q. P. n6 S5 y
{ 3 T1 O1 t) @/ m6 j  Z1 W
char directory[80];
1 e+ H8 x% e8 q0 Lstruct REGPACK reg; </FONT></P>. h) ]( b1 Q' B' \* f" F
<P><FONT color=#0000ff>printf("Enter directory to change t "); 3 |  V, ^- }* K; w# a4 a2 X" }
gets(directory); : Q5 S9 [1 c7 }2 X( d! O: Z
reg.r_ax = 0x3B &lt;&lt; 8; /* shift 3Bh into AH */ 0 V2 r3 ?0 @9 @- s& \/ U$ W
reg.r_dx = FP_OFF(directory);
6 c- s8 l: \( R  P% ireg.r_ds = FP_SEG(directory);
9 l$ i- \- ^- U7 |* F, wintr(0x21, &reg;); 9 A% ]4 n: ?0 H9 {* ]
if (reg.r_flags &amp; CF)
; C& _5 _# n$ E, Xprintf("Directory change failed\n");
' t8 O3 G- a' ?4 Xgetcwd(directory, 80); - w+ |$ \3 c$ }9 @. A# a
printf("The current directory is: %s\n", directory);
. m# e# w, m+ T) Z& O! Breturn 0; # ]: U' x! y9 x9 t" y2 w0 x& D
}
7 }9 X; b9 ^9 T, |</FONT>
, ~3 q, b1 k2 _, i& B$ p</P>
& {( W5 G% y! U7 ?8 |- D& `<P><FONT color=#ff0000>函数名: ioctl </FONT>& h" S; j$ t& g2 f
功 能: 控制I/O设备 : Z$ Y  b, q% j0 b5 x$ x
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
* k$ x& Q/ {7 B程序例: </P>/ i) T3 }2 A7 ]5 }
<P><FONT color=#0000ff>#include <STDIO.H>
* ?4 n2 B7 X" p#include <DIR.H>/ F; ]! s3 P1 B) n( d/ P
#include <IO.H></FONT></P>; ~+ O/ W' {- s3 t4 W3 x. ^/ W" |- i
<P><FONT color=#0000ff>int main(void)
* K5 f3 F. n/ M4 ]8 g{
9 D6 H0 u+ o2 ?- N7 Zint stat; </FONT></P>% ?. A7 v: T  e- U* Y, s' @
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ 6 l( R4 X/ \  Q5 a! N
stat = ioctl(0, 8, 0, 0);
1 }) k& N+ z( Eif (!stat) 9 `" _& M) A; ]) m* e
printf("Drive %c is removable.\n", getdisk() + 'A'); ( n: T% b) Z  i1 i1 [
else
, u% s$ X+ W5 s/ F. o1 `- pprintf("Drive %c is not removable.\n", getdisk() + 'A'); / M. P! S7 Y! z4 y7 O
return 0;
6 t- C1 a: L& H2 V- J" ^! n}
7 x, j. Q# B$ ?' m, @
9 L4 e: l6 A1 k2 h  r</FONT>
; `) U: w& C1 h4 n5 o( e# o$ }" k</P>: T6 {0 i1 I1 p
<P><FONT color=#ff0000>函数名: isatty </FONT>
) O% S% F0 x- r/ v4 p9 K5 U8 @功 能: 检查设备类型 3 u5 Q* p6 i' x. d- I
用 法: int isatty(int handle);
9 w- r# A  ~, w( y程序例: </P>
# v# l4 v" {$ \7 x" u2 e<P><FONT color=#0000ff>#include <STDIO.H>
- b. Z3 v) X* v; h#include <IO.H></FONT></P>& d9 K- d, G+ r8 j3 _5 k  a" k
<P><FONT color=#0000ff>int main(void) 8 m7 p- v! p+ |& R/ @
{ 8 T+ E' F* ^) i- j! w
int handle; </FONT></P>9 H' M8 ?1 R3 D( e2 T; `  c+ p
<P><FONT color=#0000ff>handle = fileno(stdprn); & ]$ j" I( v1 m* t: f: T. L
if (isatty(handle))
3 q; U. ?7 o* o$ D& F# F3 Aprintf("Handle %d is a device type\n", handle);
) q9 N* z4 T) G" [/ pelse . Z6 y& t! E# C6 z
printf("Handle %d isn't a device type\n", handle);
& v6 w* W0 M5 v3 V4 n" G0 r2 oreturn 0; 7 N) p5 ]! ]4 I; T6 L
} : X. |7 z& \4 G- O
8 n0 z1 a7 v% Z7 Z( Q
</FONT>3 V% L8 w8 ^- s  k2 p0 Z
</P>
1 H3 r, \# [) a  J0 L<P><FONT color=#ff0000>函数名: itoa </FONT>( }- [4 Q6 b7 N  j) O- x1 P$ t
功 能: 把一整数转换为字符串 0 n, Q( I' R9 }+ r
用 法: char *itoa(int value, char *string, int radix);
" b8 {5 @" h) ~# P程序例: </P>
" u: f2 m  F" C: f. D3 ]. P& e<P><FONT color=#0000ff>#include <STDLIB.H>& `5 f, ]8 K: o  w) k
#include <STDIO.H></FONT></P>8 |# V7 E+ m' K, U" @
<P><FONT color=#0000ff>int main(void)
1 G' r% o( j0 K% h& h{
9 V6 ]' z/ T% Z5 l- ]+ u$ \0 }7 vint number = 12345;
+ y+ a0 u7 L. Tchar string[25]; </FONT></P>: x* x8 T' L6 t; ~- |
<P><FONT color=#0000ff>itoa(number, string, 10); & C7 \" {; D9 L  f6 ~3 e4 N( ~
printf("integer = %d string = %s\n", number, string); , [3 u$ f& ?/ I+ d% |. N& L) ~
return 0;
2 @# y- ?3 H3 L$ F( @5 f} </FONT><FONT color=#0000ff>
0 d/ j6 J! B1 b</FONT></P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5