数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 02:59
标题: 函数大全(i开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>
9 L3 v5 X' s# e5 i. x, f< align=left><FONT color=#ff0000>函数名: imagesize</FONT>
) ~5 w' D. j7 V  a& x% {功 能: 返回保存位图像所需的字节数 % @3 Q8 Z5 a2 N" v
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
% \0 h) d; o/ K7 j程序例: </P>
* S% k' T3 W# j<><FONT color=#0000ff>#include <GRAPHICS.H>
6 l4 @. I( L0 N3 @  ], @7 m, X" J#include <STDLIB.H>' ^6 O9 o7 r+ w# l! o- w6 Y. H
#include <STDIO.H>
8 I) I1 U0 J2 q! O8 W) e#include <CONIO.H></FONT></P>( _* v/ p1 R% ?2 |$ S( \5 x
<><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>6 P3 B0 q; J2 K: T) u+ G
<><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>
+ E; Y4 k5 I. M/ J% j8 |<><FONT color=#0000ff>int main(void) 7 \& O- j2 @: E* o( }$ W% d
{ 9 f7 l" Z/ i* N9 ~5 a+ ]  O
/* request autodetection */
( O+ a; v* n2 F1 s$ Wint gdriver = DETECT, gmode, errorcode;
: O7 }+ W. z# m9 E6 S, v3 f: ^8 `void *arrow;
: I( G/ \6 w% Z' w& @0 Xint x, y, maxx;   {. U) r$ r! n  e- n0 Z% j- Y
unsigned int size; </FONT></P>' r* N% J8 L. s2 r8 {1 A( h) \
<><FONT color=#0000ff>/* initialize graphics and local variables */
. R( C, e$ Y3 R$ a7 Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% |8 K- E9 j( S* P<><FONT color=#0000ff>/* read result of initialization */
3 O+ ]/ \- B3 f5 T) Jerrorcode = graphresult(); - c; k( L9 d+ o$ h; H
if (errorcode != grOk) /* an error occurred */
3 z9 j# s# d' l* K, ~{ ) a3 [  r6 ?5 H8 |( ^6 t
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ! I- s9 d3 M* ^+ e/ h
printf("ress any key to halt:");
. k* {* C3 @- |% [' Dgetch(); 0 H: X4 d: k; E
exit(1); /* terminate with an error code */ 6 o/ ~! V( r: j6 p. h% K
} </FONT></P>
+ p- J7 C0 y/ ]9 H<><FONT color=#0000ff>maxx = getmaxx(); 0 r8 f) j' h4 q
x = 0;
: \) e7 e! F" ~2 a- Z" d, |y = getmaxy() / 2; </FONT></P>
+ w! F* R+ x2 g<><FONT color=#0000ff>/* draw the image to be grabbed */
2 \% p% L1 V: ^5 U; P# Kdraw_arrow(x, y); </FONT></P>1 d: l# p. r& @( r' y8 z8 Y
<><FONT color=#0000ff>/* calculate the size of the image */
% Y! M5 ]5 ^6 P. B( J8 Y$ B$ Csize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>' g* y) N) G. z( b2 g" t
<><FONT color=#0000ff>/* allocate memory to hold the image */ ( ?) C# E% D, g' P" W2 R. _
arrow = malloc(size); </FONT></P>. |  X4 P2 X( c; E
<><FONT color=#0000ff>/* grab the image */
4 |8 z- X/ V, P( K; W8 C6 Ugetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
% r$ S0 t8 a$ m, e$ u6 v<><FONT color=#0000ff>/* repeat until a key is pressed */ 6 Z% w4 f- r! Q. k% G$ [" ]
while (!kbhit())
& j2 ~. j* M4 ?6 H1 a{ 5 f, q  P# s0 M: \' }$ z
/* erase old image */ 4 {5 [5 y) x: b+ B
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>2 G# y6 m) Z( G9 d% ~
<><FONT color=#0000ff>x += ARROW_SIZE; % T5 V; P4 Y8 v- m& M
if (x &gt;= maxx) 1 |4 C9 U. c, p5 T4 K
x = 0; </FONT></P>3 g1 V; F% J3 }1 ~$ X: q
<><FONT color=#0000ff>/* plot new image */
9 O" _8 m# ~5 ~2 N3 J1 P( p# Wputimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
$ }. g1 h; W3 L2 v1 d& }1 H9 N} </FONT></P>+ s8 G! a  t" ?+ j
<><FONT color=#0000ff>/* clean up */ 2 |8 {2 x: R8 C6 i
free(arrow);
8 r, b! H5 S  W: p! S( Iclosegraph(); + Z. j- S0 D+ g" K# W2 J* s) x
return 0; 4 r8 I& ?' T- Q: F; N4 D
} </FONT></P>; o& T7 q/ x, A  C- {! b
<><FONT color=#0000ff>void draw_arrow(int x, int y)
0 I5 c+ ]! c5 B{ / @$ V% N% M, |2 A
/* draw an arrow on the screen */ 4 u4 T3 q) f) \& Z8 Z4 ~
moveto(x, y);
7 Z$ f0 Q% L; W3 d7 k5 O  R) e2 Vlinerel(4*ARROW_SIZE, 0);
2 n  [: ?' a. L! S2 @. N" |linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); + {2 d/ S& [8 T5 y
linerel(0, 2*ARROW_SIZE);
" \% P: \2 }6 [& Q+ Nlinerel(2*ARROW_SIZE, -1*ARROW_SIZE);
4 {( L; \8 }8 d8 D( j5 }9 \. V2 b/ n- t} 8 y& |0 O0 m( m7 l$ U0 \' E

2 I# s/ S5 H( I7 B& \3 i6 m& c, ~
# H& \! @4 H" G6 p' O% C' e</FONT></P>
/ V( R0 O! z$ f( b+ N5 `<><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
! [! a9 j, Q6 p<FONT color=#000000>功 能: 初始化图形系统
+ A, C; s8 S+ |用 法: void far initgraph(int far *graphdriver, int far *graphmode,
) ?. p& `  z$ ]char far *pathtodriver);
$ S! Y1 i* X  o# B程序例: </FONT></FONT></P>8 a# s# W: ~8 u  M$ l. I, ^- D7 R
<><FONT color=#0000ff>#include <GRAPHICS.H>
" ?5 [1 @4 ]! V0 M  G#include <STDLIB.H>' I- W# V  _% V/ k+ r7 ^
#include <STDIO.H>
  U0 T$ r3 w2 [+ X- @/ A# t6 j; N& H2 |#include <CONIO.H></FONT></P>5 H' s: V) I. }) K  [
<><FONT color=#0000ff>int main(void) 3 z7 F7 G! U: X6 B+ t
{ $ `0 V1 z- R) E* Y
/* request auto detection */ ! @  N# M) k/ [8 i
int gdriver = DETECT, gmode, errorcode; </FONT></P>, f* x% E- l6 W2 e! e% V
<><FONT color=#0000ff>/* initialize graphics mode */ , x" L( }2 M, W3 F$ _
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ f0 M# [  c) i9 T
<><FONT color=#0000ff>/* read result of initialization */
: H4 [9 Q3 K# P6 \* }errorcode = graphresult(); </FONT></P>
2 @4 T4 x* A5 h) r" f8 M<><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ 3 r+ t* ]; W" G2 C
{ ' n8 C1 ~: [5 R1 V/ ]
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* _: y2 H& O7 L2 ?printf("ress any key to halt:");
. E' M: l' t+ u, i8 rgetch();
" t/ w' Y2 a# f: i( n* cexit(1); /* return with error code */
+ K, J  I" ]( z} </FONT></P>3 C2 f; h1 I* A. s+ f
<><FONT color=#0000ff>/* draw a line */
  y$ O0 Y% g9 f" M: kline(0, 0, getmaxx(), getmaxy()); </FONT></P>
1 N( h. g9 `* h6 d) }% p4 h<><FONT color=#0000ff>/* clean up */ # v. W2 e' {9 D
getch(); - ^2 G0 R, F6 S1 X+ I
closegraph();
9 L6 K# X: w! q* Z, Areturn 0;
. x: F/ X# Q! m- v+ y} </FONT>
2 H$ a" `' _+ _1 j, l3 F
6 b" k3 c5 z) I/ L# q</P>
6 Y: V! N' W5 {1 }. r/ ^<><FONT color=#ff0000>函数名: inport </FONT>
  X5 y3 I3 t% U: K功 能: 从硬件端口中输入
* R3 l* L" S4 D5 G# V" x( Q  W( r用 法: int inp(int protid);
) {9 G1 W$ @% O8 y! T; @# m程序例: </P>( {. Q4 {9 O! g6 `. o
<><FONT color=#0000ff>#include <STDIO.H>
0 }4 v0 t8 D) H) i& x  b3 b+ }#include <DOS.H></FONT></P>$ c; S% w: I, F. F# d# `0 g3 k
<P><FONT color=#0000ff>int main(void)
  z9 T+ Y1 s& a2 w) Q{ 2 X" N9 s' S2 a, \( A
int result; % F; x9 s$ C& V! F
int port = 0; /* serial port 0 */ </FONT></P>
1 V7 `( Q' `% J4 ^/ a<P><FONT color=#0000ff>result = inport(port);
7 k! }: R# r6 U) D! R& O4 D9 G8 oprintf("Word read from port %d = 0x%X\n", port, result); 6 j8 L! w# x5 G% u
return 0; ' A5 c, m9 {5 k* s- P
} , K9 U1 g0 B# F$ A& j

8 |6 ~# B) |" g; ]$ b, W</FONT></P>/ @& X$ C8 e  u: r
<P><FONT color=#ff0000>函数名: insline </FONT>  J+ b$ g/ g8 G& M; t8 i/ j( ?
功 能: 在文本窗口中插入一个空行
9 V7 N: {. d8 x4 i, c& R用 法: void insline(void); $ B* j; ]' q; l4 @! _& Q0 U
程序例: </P>/ z  ]/ T0 p/ g* o$ h! h+ Q
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>  O$ v1 m- k# z, ]1 ?7 k9 m# A3 m
<P><FONT color=#0000ff>int main(void)
/ B6 D. |) b0 j$ |1 }; U3 J. g% P{
& ~, B# I6 p5 u8 y! p& @  Z% Aclrscr();
& ^% r' n4 R( m7 S1 b$ Xcprintf("INSLINE inserts an empty line in the text window\r\n");
; W! A) O5 b, Dcprintf("at the cursor position using the current text\r\n");
8 C& |) F6 ?! j* F, ~. \  ccprintf("background color. All lines below the empty one\r\n"); / C& q, Z  d9 ^) K1 t5 r
cprintf("move down one line and the bottom line scrolls\r\n");
  ^! g5 Y" v$ q1 fcprintf("off the bottom of the window.\r\n");
! d2 M# P$ T* z& d3 acprintf("\r\nPress any key to continue:");
6 z/ w2 j. I* Z) I4 F8 n4 Ngotoxy(1, 3); 6 C2 a9 y: |; e6 j' l
getch(); , \( J( b7 Q$ u. \% B: h' D0 }
insline(); 9 ?# `0 G, ?2 f
getch(); * V  S) A) Y" t+ E
return 0;
2 G1 [4 e/ M# k4 t# ?6 e+ G# [}
: l7 r- b& H7 u4 e</FONT>) k. q6 ]5 i. V2 h2 l

6 e$ z: O7 d  g7 @/ v4 B6 [* a</P>
: y; b: D3 o1 U. j" }) M<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
% m) Z3 x0 {) T" ]0 c4 T5 F+ b功 能: 安装设备驱动程序到BGI设备驱动程序表中
3 Z  A( M" Z- n) p  v* [用 法: int far installuserdriver(char far *name, int (*detect)(void)); $ {3 P) d+ j1 x+ p( _! K* q; m8 q
程序例: </P>7 `* ]1 _& T$ _
<P><FONT color=#0000ff>#include <GRAPHICS.H>. x% a5 @+ B( W
#include <STDLIB.H>" O8 t. u+ N. w; O
#include <STDIO.H>
' l9 b8 C; s8 U- B#include <CONIO.H></FONT></P>
  d) C( K0 o9 V- m' q% e8 j4 R<P><FONT color=#0000ff>/* function prototypes */ $ K  ~$ x! V/ ^
int huge detectEGA(void);
4 N7 w! p# c9 h$ e! `void checkerrors(void); </FONT></P>' k9 R5 Y5 I) d5 ?! j9 l
<P><FONT color=#0000ff>int main(void) 6 M* h7 L5 G% l/ x  T+ S9 x
{
0 w5 m* u! n  \( T, z" cint gdriver, gmode; </FONT></P>
' a; w7 L. f' T" O<P><FONT color=#0000ff>/* install a user written device driver */
/ A, K5 U6 x4 A' X: Vgdriver = installuserdriver("EGA", detectEGA); </FONT></P>
2 E% a) C% ~, Z$ z<P><FONT color=#0000ff>/* must force use of detection routine */
6 q3 `; n4 \5 z) |6 `! igdriver = DETECT; </FONT></P>
% Z$ c. j& u1 Z! T( s& y9 N8 ?- T2 H<P><FONT color=#0000ff>/* check for any installation errors */
- a5 ?& \# t9 J, F/ S# C1 [checkerrors(); </FONT></P>4 t) R" l! O: J% E: g
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' d' D9 c# G  e* R0 G% f! o7 Dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  z$ n  n9 I( R) F& ~9 u<P><FONT color=#0000ff>/* check for any initialization errors */
% V) ^: q! w0 Q" ncheckerrors(); </FONT></P>
$ i; n; y; H) s6 ]<P><FONT color=#0000ff>/* draw a line */
; n7 ^6 E9 ~9 G4 |. L( p( j! M1 Dline(0, 0, getmaxx(), getmaxy()); </FONT></P>
0 }( _- Y* F6 h7 e<P><FONT color=#0000ff>/* clean up */
9 ~+ }( v6 R$ s( p$ w" _5 |getch();
: q0 w6 a8 x& [1 E0 xclosegraph();
5 z6 O" w0 M4 a  t) m! Kreturn 0; * n! B/ B; H9 _. T8 ]3 q) J4 I  g
} </FONT></P>
) N& k7 E/ y1 O7 B2 Y- n% Q4 H: {6 e<P><FONT color=#0000ff>/* detects EGA or VGA cards */ . ]6 u, T9 g2 N7 D, X4 I
int huge detectEGA(void)
( H9 n; g) [8 s! V4 N4 f{
3 q2 u& X+ I# M; Jint driver, mode, sugmode = 0; </FONT></P>
/ F, S$ H* z" s9 ?) S<P><FONT color=#0000ff>detectgraph(&amp;driver, &amp;mode); & Z  J; d) z6 g. }4 F( D. E
if ((driver == EGA) || (driver == VGA))
+ K; @5 _. a6 B% ^/* return suggested video mode number */
% D1 E# j5 C8 _; O: Hreturn sugmode;
' |( y5 G4 U) c$ nelse
4 t- R& E9 b$ l+ I/ E2 n! O/* return an error code */ 5 ~. Y4 z% O, X" f( {+ u
return grError;
5 w8 d  x/ O/ [( c3 p5 G} </FONT></P>
; g7 Y' {1 ~( K, ?' r+ g<P><FONT color=#0000ff>/* check for and report any graphics errors */ 9 N/ V6 I) V6 V) l
void checkerrors(void)
8 J$ c+ J3 @- @$ O  K{ ( h  u0 A7 B( D6 U0 ~
int errorcode; </FONT></P>
" |9 M* O; v6 z* j5 p<P><FONT color=#0000ff>/* read result of last graphics operation */
9 j9 B+ ]. h5 B1 ~  Lerrorcode = graphresult();
/ R8 P; ^0 D4 C! \: j- ?if (errorcode != grOk)
8 i( B2 Z9 t% I6 w7 q  V{ 4 j3 ~" ^1 y$ J4 m7 ?/ F. P" U' @
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) W5 [9 @$ N: g  q8 q
printf("Press any key to halt:");
* c& q/ g/ a& |. A  k9 \getch();   l$ I4 j: v% Y; Y
exit(1);
% f7 {! c8 H& L; k}
+ [6 y+ p' K$ W# u} </FONT></P>
4 T% Q" e- V2 J0 J" [( S7 p6 a<P><FONT color=#ff0000>函数名: installuserfont </FONT>9 \! }6 x! _* d/ v7 F3 x8 }
功 能: 安装未嵌入BGI系统的字体文件(CHR)
0 [: b8 p5 l; j2 x1 V2 t2 E用 法: int far installuserfont(char far *name); 5 g" l4 s1 S  h2 o* w: P
程序例: </P>
+ G# o! ^+ Q: S5 T5 u2 {+ K<P><FONT color=#0000ff>#include <GRAPHICS.H>* p8 p; ?5 Z: D- g4 n5 z% B
#include <STDLIB.H>
# o& a& r0 d) a#include <STDIO.H>
! q! A# \* S# z7 Q+ O; \, U#include <CONIO.H></FONT></P># D3 D) c. `5 T  [
<P><FONT color=#0000ff>/* function prototype */
) O. B1 l3 ~6 m: ^* k/ f! j5 j0 }9 k1 }void checkerrors(void); </FONT></P>  A  l( f1 E$ v# }* ~: y
<P><FONT color=#0000ff>int main(void)
/ {/ j# c2 G* c4 V3 X{ , @" `/ K% |# T6 ~& _$ G$ u( m( C
/* request auto detection */
! n, p& }6 y1 r- h1 \0 qint gdriver = DETECT, gmode;
! f2 c/ n1 Q* {$ D$ r# C. gint userfont; $ R8 s; V+ `: F3 L" `: q4 N7 _
int midx, midy; </FONT></P>
0 f- B: Z, Y: k<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 V$ u0 \, \1 @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, P6 R% {) E. z# j
<P><FONT color=#0000ff>midx = getmaxx() / 2; : [. q: c2 ^& C6 W$ x' \! x5 ~
midy = getmaxy() / 2; </FONT></P>5 S1 S. {' v8 C* ?" a
<P><FONT color=#0000ff>/* check for any initialization errors */ 8 Z: m4 j( l. K' c# v. A
checkerrors(); </FONT></P>+ f" q5 i6 C$ A3 p
<P><FONT color=#0000ff>/* install a user defined font file */ 2 a7 M& }( L" E# `0 ~1 [2 a# D6 d
userfont = installuserfont("USER.CHR"); </FONT></P>
- l- k' _7 d/ Q0 ?. U% q8 A, l<P><FONT color=#0000ff>/* check for any installation errors */ . I/ `% K, X  n* a  B1 X! [+ {
checkerrors(); </FONT></P>3 J. s1 ~1 E' e! i% P6 T  e
<P><FONT color=#0000ff>/* select the user font */ 5 P' Y1 k3 h* o6 F
settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>7 M" ]9 A: Z: n6 `# |, U3 H
<P><FONT color=#0000ff>/* output some text */
+ q, ^# S2 r* r+ j& `0 Pouttextxy(midx, midy, "Testing!"); </FONT></P>
: D! d1 ^, d& H1 r<P><FONT color=#0000ff>/* clean up */
- d) T6 m4 }; G, _8 s: Ggetch(); ' \7 w0 i% t3 \* M9 g. A8 v/ C# _
closegraph(); " L4 c% h2 e7 N% f9 N1 a' w/ q
return 0; 7 N. u( A6 n. z, O
} </FONT></P>
# ^  a3 j( D( _. p# b2 W<P><FONT color=#0000ff>/* check for and report any graphics errors */ 6 W3 h* h. q+ U+ `: N) j; P
void checkerrors(void) 6 `. W7 H  D$ x6 ~" u4 S
{ 8 Q, T1 ^5 O; l7 i8 K# Z# D& Z/ ^
int errorcode; </FONT></P>2 D* u) g4 U  n' U1 ~: _
<P><FONT color=#0000ff>/* read result of last graphics operation */
7 {9 N7 O% O% z1 L0 S5 ?2 |6 Oerrorcode = graphresult();
, b6 p% j7 f& f. }6 ]) eif (errorcode != grOk) 8 Z8 ^$ R, ^, w0 x
{
0 j2 X# `; ?, ?  q" B8 Rprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 a$ e" U8 y  W; G9 C' ~: Gprintf("Press any key to halt:"); $ n5 z' u$ X; T, L% t  `
getch(); 0 S! D3 R6 }9 S
exit(1);
" K0 A) u$ u& c8 I* l$ x4 Q}
2 ?, o+ P2 S% q2 s4 I} </FONT>4 B% V5 s# h8 N/ ^8 e: v! L* I8 Y

+ B9 G2 {( ^7 s& q  P2 M3 h, Q: e' T; A! e8 x1 @) `
</P>
& b# n: O2 P0 L; y  [: W<P><FONT color=#ff0000>函数名: int86 </FONT>
: @. @( x6 q- R, ?- q6 J功 能: 通用8086软中断接口
! Q, z" a6 X$ p) f# b用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); 5 E4 O8 H4 ~* k2 r
程序例: </P>
+ B, `* i3 a/ y% T5 u; Y<P><FONT color=#0000ff>#include <STDIO.H>. W8 d- v6 n( C9 s' K2 y  [5 s
#include <CONIO.H>
1 o- R* `% g6 q. X9 Q6 z#include <DOS.H></FONT></P>
' `# j( q" }, X: e' `<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>7 \$ v9 }; `- S2 [& u  Y
<P><FONT color=#0000ff>void movetoxy(int x, int y)
  y/ C2 v7 P9 Q0 r' J8 a0 r{
9 ]( ~0 G0 C$ S. a( L. Yunion REGS regs; </FONT></P>
& ~# [4 X3 u, d<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */ 7 c5 G, n2 w' t1 n
regs.h.dh = y;
3 c) |* L- _1 @1 {$ k8 N6 mregs.h.dl = x;
: m" `  r7 d8 O+ `regs.h.bh = 0; /* video page 0 */ ! I$ t: Z/ v* {- X+ H, u
int86(VIDEO, &reg;s, &reg;s); 3 t4 _) B" N" A1 M
} </FONT></P>0 M. E" O) [( E
<P><FONT color=#0000ff>int main(void)
, U: `5 V7 O3 t4 |: k{
# _3 t- s, }2 dclrscr();
. u0 }/ o* K6 i+ f: f' r9 W& A3 f+ N0 Fmovetoxy(35, 10); 2 N: p) O1 N. L  i( w! ]
printf("Hello\n");
) A. I: m! u: }+ Q. r9 r; Dreturn 0;
' B# O) v, M8 |/ e" V; i' K4 |} </FONT>- u9 ]) H& \1 }6 h
, r0 @1 q5 Q( A( `* T
</P>
% }5 a2 }' ]/ Q. Q3 x% N4 B; G, _<P><FONT color=#ff0000>函数名: int86x </FONT>
. r6 \) g9 r. I- q功 能: 通用8086软中断接口
& Y$ F! C8 s' s* H% ?用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
: E9 p6 d$ `" [: p" c; e4 kstruct SREGS *segregs); ! w* V1 ?# ~& M4 t4 F
程序例: </P>
* V* Y) Q, f: m4 B, W' {<P><FONT color=#0000ff>#include <DOS.H>
  @! s) M' R5 X3 b#include <PROCESS.H>4 |; {# |. ^2 L" ]; d0 X- Y
#include <STDIO.H></FONT></P>
" J1 c9 B0 z% V7 ?<P><FONT color=#0000ff>int main(void)
$ _$ V% \1 x9 g2 V) _. s{ : N5 D2 X. s, y
char filename[80];
4 R% @' C2 T1 Y! a. z( ~/ U% eunion REGS inregs, outregs;
! C- z# E6 p( \struct SREGS segregs; </FONT></P>
6 c3 [: g6 X, o$ \# U8 h5 W<P><FONT color=#0000ff>printf("Enter filename: ");
, s9 {! X. a; v. G% `3 g8 c8 sgets(filename);
( T9 @, R6 Q- ]inregs.h.ah = 0x43; 3 g4 J5 R$ ~! C2 r0 q3 ]
inregs.h.al = 0x21; , u5 t9 x3 V- |8 [0 A
inregs.x.dx = FP_OFF(filename); ; h0 ?. I8 V4 T: ^
segregs.ds = FP_SEG(filename);
6 D' K% l1 z" H# p) i' Kint86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs); & u- L. G) F$ x/ q9 }
printf("File attribute: %X\n", outregs.x.cx);   l- P% {, i. `% d+ V& t% A0 d8 \* K
return 0; " T+ v. h) d9 r% y: T3 H; j4 j4 P
} 1 N& j: B: x" _3 I; _( k
  l5 @  D: N5 d% E2 F
</FONT>
1 I) `' k$ D8 }4 ^</P>
" Z0 `4 b0 n6 V9 r. D5 ~; ]<P><FONT color=#ff0000>函数名: intdos </FONT>% ]" {* ?! t2 I4 e3 l% n
功 能: 通用DOS接口
0 [$ E7 j' s% v. ]/ f0 u用 法: int intdos(union REGS *inregs, union REGS *outregs); / r* k) F$ E+ i9 c- Z
程序例: </P>
# e4 X* b4 r  t: F* c" g<P><FONT color=#0000ff>#include <STDIO.H>: d- O& j$ q2 K( i! j
#include <DOS.H></FONT></P>
' h& v! L) w) G& S, K7 D4 ^<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
5 d* _4 B, p. d5 B& r1 ]int delete_file(char near *filename)
: _+ Y0 t- L$ ~. q# a9 o6 i* ~{ . F, [8 U, m1 Q1 ^( Y! X
union REGS regs; 1 N7 v( O+ Z9 Q3 d/ h/ n
int ret;
5 d: r. [3 l9 S. ]( A8 ], sregs.h.ah = 0x41; /* delete file */
5 c. {: ^( d* E1 Oregs.x.dx = (unsigned) filename;
  }, T4 u2 o' q, C8 R" `3 L" hret = intdos(&reg;s, &reg;s); </FONT></P>' ^$ E9 |3 Y: Z! H, k- o( C) }7 ?' q
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
) ~2 a4 v- u+ hreturn(regs.x.cflag ? ret : 0);
5 j; d9 w6 D# d$ Y$ y  `} </FONT></P>+ {; G7 Z) b" r
<P><FONT color=#0000ff>int main(void) ( |" d$ n2 h5 T) u, A  ~' ~7 e& t2 O
{ / H9 u! a9 i+ C( n0 i
int err; % j! s4 x3 i( e. U0 _8 c# d
err = delete_file("NOTEXIST.$$$"); 6 R, ~$ ~( ^- M4 J0 S# {
if (!err)
& f2 x3 s) L" L# u% Eprintf("Able to delete NOTEXIST.$$$\n"); 3 D$ Q  h1 o/ J+ y
else
( O7 _; c7 ^" H# Xprintf("Not Able to delete NOTEXIST.$$$\n"); 2 E9 l: D. P9 g2 [2 l1 h
return 0;
0 p4 _7 L9 J3 A! n; D4 D4 T} 2 M+ u1 J, v6 P7 C& `

) y( I1 X5 m, `! `, B' J</FONT>
- V3 [; x, u! W6 k( L- z</P>* h8 a' t2 K' B0 \
<P><FONT color=#ff0000>函数名: intdosx </FONT>$ A" ^/ x+ }4 k) D9 {1 c9 o
功 能: 通用DOS中断接口 ' Y. W4 q% S" l4 o- i9 U. h
用 法: int intdosx(union REGS *inregs, union REGS *outregs, $ `3 O1 [7 T1 Z, r, h
struct SREGS *segregs); ( u. l0 n6 t3 \- }  {+ N2 z7 a8 T8 m
程序例: </P>
! ^" T' ]+ c1 Y" s- r<P><FONT color=#0000ff>#include <STDIO.H>3 h9 Z, s0 P4 ]/ {" z) k
#include <DOS.H></FONT></P>0 s& C, i, I! N2 `6 w/ L
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 6 b6 h* f" B1 [+ o: P
int delete_file(char far *filename) " I4 o: z* O4 D
{
# C: D& ]$ O( x7 `, F8 k, C7 Uunion REGS regs; struct SREGS sregs; " a0 a" W8 a  B
int ret;
- _  ]  r) `' A$ W7 z- w9 @1 `5 y' lregs.h.ah = 0x41; /* delete file */ $ P, R1 i- p9 ~* M% [
regs.x.dx = FP_OFF(filename); ) {* g/ O) y3 C; C
sregs.ds = FP_SEG(filename);
* D; K3 O: [. t* Rret = intdosx(&reg;s, &reg;s, &amp;sregs); </FONT></P>
8 R5 r- A$ b' {' _6 t<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
# v- b1 o2 a. s# n6 N5 {: Mreturn(regs.x.cflag ? ret : 0);
, ~6 |5 I' Z9 M' C} </FONT></P>2 m/ P5 J* ^0 n+ t/ X
<P><FONT color=#0000ff>int main(void)
5 A) H5 ~4 _- @* z6 U  }  p# W{ % \  a  E& D8 ~/ j. `
int err;
+ G4 g# b; F, n% _, h/ h, zerr = delete_file("NOTEXIST.$$$"); - `* j5 U% @6 }" r' l* n3 N
if (!err)
6 }5 c) I% E: a9 u( H# `printf("Able to delete NOTEXIST.$$$\n"); ) o' ?3 p% F8 f9 V' Y" L
else 4 X8 `4 J9 Y! l  v2 T3 W3 F  r0 \$ X
printf("Not Able to delete NOTEXIST.$$$\n"); ' S3 d5 V+ N8 G
return 0; , I% ~9 v9 `; q0 \( ^. g0 b
}
# I% T/ P8 A; @# _+ Q</FONT>
' X7 G# }; V  {5 E3 U$ ~</P>) L6 A! w& f/ `3 r7 j# t- a: O5 |  _8 w
<P><FONT color=#ff0000>函数名: intr </FONT>
! {% }% z" s6 m. U功 能: 改变软中断接口
3 [: h% C( T" ~8 [, I  S用 法: void intr(int intr_num, struct REGPACK *preg);
1 _6 K+ d  Z; y  f5 v3 G  S# }1 O, P程序例: </P>' X8 ]1 c! t) ~' W5 Z, g
<P><FONT color=#0000ff>#include <STDIO.H>
4 U% c7 ^' e4 h) J, [6 E  Y) z#include <STRING.H>
& g! P9 O1 g) |1 T#include <DIR.H>
. r5 J9 n7 D3 A' w( F3 o#include <DOS.H></FONT></P>' _, E0 Z: D2 M/ I+ P3 Z+ k& Y
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
# V6 n4 i0 \! ]1 f3 A<P><FONT color=#0000ff>int main(void)
# V$ p- c5 |+ j& T2 |! \5 m{ & q1 r) T; S# X, L# g. \$ q
char directory[80];
+ {# J, f3 A) B: R3 j7 b! t' [' estruct REGPACK reg; </FONT></P>
7 {3 d7 S$ Q& X  y. |  X<P><FONT color=#0000ff>printf("Enter directory to change t ");
; K& M+ m9 J0 Q8 B% V% e$ B2 y* ygets(directory);
! h, D0 G( P" {/ ^reg.r_ax = 0x3B &lt;&lt; 8; /* shift 3Bh into AH */
  ~( B- x% w* dreg.r_dx = FP_OFF(directory);
; n7 t* o8 Q7 D" M: N4 Greg.r_ds = FP_SEG(directory);
$ P9 T5 P0 R- h# \- _intr(0x21, &reg;);
5 \; V6 S. a  C3 K8 Sif (reg.r_flags &amp; CF) ! ^" G- ~& {# p4 |1 v. u/ v
printf("Directory change failed\n");
7 k6 h" p8 k- ]getcwd(directory, 80);
8 K' i" k" C* E' s. Pprintf("The current directory is: %s\n", directory);
# t% B& Y5 U" w! d3 a. G" z1 q5 greturn 0;
9 q/ D6 v8 x  [; B0 h}
8 P# C3 Z4 d0 Q$ t</FONT>: w, x. }# M; [" y. B  f1 U% [$ T0 I
</P>
8 K0 x) o6 g2 i, a1 _<P><FONT color=#ff0000>函数名: ioctl </FONT>
8 S. [2 y$ x$ c! v: N* O功 能: 控制I/O设备
. f" H8 y$ A/ d用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); * |4 s1 \; |2 p5 w
程序例: </P>/ ^$ Q( c. z. \, {6 z1 W
<P><FONT color=#0000ff>#include <STDIO.H>
  @7 [; h7 p. @#include <DIR.H>
% V  {9 N0 O) b+ J; i& `4 ^3 m#include <IO.H></FONT></P>( d. x& I  z4 p: `) W9 H
<P><FONT color=#0000ff>int main(void) . a& ^6 m0 ?: k( K* t
{ 5 e% P7 {# t- X( U2 h
int stat; </FONT></P>
$ O  H7 p& _; x; @<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
6 B1 }9 Z0 c8 G7 D+ a- z0 ~stat = ioctl(0, 8, 0, 0);
) |/ A$ P- N" L9 V- Q- ], |8 ~if (!stat) & D3 o5 s5 m# @2 M& K
printf("Drive %c is removable.\n", getdisk() + 'A');
+ r+ K) l; s# Oelse ' ^8 }4 W7 z7 ?0 l# d
printf("Drive %c is not removable.\n", getdisk() + 'A');
. M" s6 C9 {% E2 k# Jreturn 0;
5 e- Y; S( A# O8 c  d5 s( i} 4 ^* R& h2 `$ Y7 P

8 a! ~+ q/ ~2 n/ `- Z6 T4 W</FONT>
, M# p7 Y! N& n7 m+ F. A: N4 p</P>
+ ~  l6 ]- J* R5 h+ B8 [<P><FONT color=#ff0000>函数名: isatty </FONT>! [& j; l9 y4 E- ~  u
功 能: 检查设备类型
; _5 |% S% L3 v, Q0 s0 K用 法: int isatty(int handle); $ H) [' O, Y! t
程序例: </P>
. \- m3 C1 h5 Z1 h4 c<P><FONT color=#0000ff>#include <STDIO.H>; H( C3 q/ G, H, I: w5 z
#include <IO.H></FONT></P>7 b+ ?& Q* X4 K& H' ?
<P><FONT color=#0000ff>int main(void) : c( {3 `, Z: h2 ^) q3 m6 O
{ ! U8 B5 F4 r# {6 k! |* ^
int handle; </FONT></P>5 E! k) h) M# [) _
<P><FONT color=#0000ff>handle = fileno(stdprn);
9 F4 A5 t  w4 Hif (isatty(handle))
8 c) |1 A( K% T$ Q& S+ }( ?printf("Handle %d is a device type\n", handle); 5 I4 G3 V  T( O2 O. x/ g
else
6 P/ _  ]3 o) f$ @2 U, h. {printf("Handle %d isn't a device type\n", handle); ( w  i8 u* i# k6 C
return 0; 4 q# e4 l4 Y4 U% I6 O9 U7 c+ ?  Q/ b
} - T1 @+ x0 j3 Y" {! a; L
6 C4 H, K1 r& d% _5 M( G
</FONT>
' m' v% A) \9 l; s6 ~; R</P>
9 w) I- n0 i1 Q/ L<P><FONT color=#ff0000>函数名: itoa </FONT>
9 b0 r- v3 _# q: c7 E) [功 能: 把一整数转换为字符串
0 k0 O$ P8 M. a  [9 C' p( a用 法: char *itoa(int value, char *string, int radix);
: [& ]2 @# L' E, {5 h, w5 j程序例: </P>
/ A8 K' b( e5 ?+ Y<P><FONT color=#0000ff>#include <STDLIB.H>
) f$ ~% ^# |: \0 s4 W2 q#include <STDIO.H></FONT></P>
9 f. W5 A5 M# T# ~8 A" [<P><FONT color=#0000ff>int main(void)
0 `, X) u# X1 a0 |2 o5 d{
# B$ y3 R6 b& `1 K) J9 ~" ^+ Q3 hint number = 12345; 5 W  s! e6 C* R- h  d5 c) u$ k
char string[25]; </FONT></P>
5 N2 g, T+ ?: Z<P><FONT color=#0000ff>itoa(number, string, 10);
$ v$ m! P1 s3 D0 i$ b1 z! O# Yprintf("integer = %d string = %s\n", number, string); : Z: m. s8 Q6 H1 b+ |' n
return 0;
6 R. M. h2 O8 P. I: @# {} </FONT><FONT color=#0000ff>
: n9 o$ p. y* Q</FONT></P>




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