数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 02:59
标题: 函数大全(i开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>* l& L7 g# c. ^( _7 W0 ~# @
< align=left><FONT color=#ff0000>函数名: imagesize</FONT>
; S% H5 B' m% M功 能: 返回保存位图像所需的字节数 ' H! G3 x6 _# U4 U- A- t( M
用 法: unsigned far imagesize(int left, int top, int right, int bottom); 2 E. t% A9 Q- i' N) t  B
程序例: </P>1 G: X1 l! l5 t
<><FONT color=#0000ff>#include <GRAPHICS.H>7 F1 ]/ `) a: j9 x2 p/ R: H: M$ d
#include <STDLIB.H>3 c( V, |0 s; p5 ~7 ?" ?, q
#include <STDIO.H>: T2 G  t- h+ \# O$ P8 q% h
#include <CONIO.H></FONT></P>+ K( u5 W2 J$ r+ l+ M; }0 q3 d
<><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
6 J0 X. c% ?6 x3 ]<><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>
5 b1 s7 D& T5 N( ]2 Y<><FONT color=#0000ff>int main(void) $ h$ R2 K0 D1 m8 v
{ 9 k$ \5 a, g$ D
/* request autodetection */
' B1 L& f5 ~3 Iint gdriver = DETECT, gmode, errorcode;
" X. a0 K: t$ l. A- e1 |void *arrow;
2 B0 Y2 s; R. g2 g) b+ w. ?int x, y, maxx;
0 i' D% [0 c6 Bunsigned int size; </FONT></P>: D" n  s& q) O
<><FONT color=#0000ff>/* initialize graphics and local variables */
" G! Y$ J# o9 ?+ H0 C1 ^initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: ^7 N$ L4 C% R& k2 H: r0 H<><FONT color=#0000ff>/* read result of initialization */
6 s" @+ ]8 O0 `errorcode = graphresult(); 8 _) x# M5 I$ b9 ]  N5 p
if (errorcode != grOk) /* an error occurred */ : I# K7 g3 z+ ^* Z/ f; f. q: a
{
! S& Y' p+ j0 {  Lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 W" ~0 T4 u# g4 I
printf("ress any key to halt:");
2 ?3 O# ^, L; B' X+ P+ m1 V) Y8 Egetch(); 6 d" L1 ?$ I" J) t* Q+ M. {
exit(1); /* terminate with an error code */
! T! P2 u9 ^& W" t* o" d} </FONT></P>0 R. y  A. R5 l) g* s2 e9 o) E
<><FONT color=#0000ff>maxx = getmaxx(); & A; R5 |1 i# j8 H* _- z
x = 0;
" ]$ ~/ J" v" h) u% ?% v& Ry = getmaxy() / 2; </FONT></P>
  W: [7 X6 H5 O6 s2 u<><FONT color=#0000ff>/* draw the image to be grabbed */ 7 K& @- L' p- E4 G
draw_arrow(x, y); </FONT></P>/ N; Y7 u5 m# L, Y' _" C
<><FONT color=#0000ff>/* calculate the size of the image */
, }' S4 W1 r7 {& Qsize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>8 X$ H) y& ?+ R% K9 j
<><FONT color=#0000ff>/* allocate memory to hold the image */
. V. W2 ~# {& F  g3 A5 Iarrow = malloc(size); </FONT></P>
8 `. |: R" c! _& t  g<><FONT color=#0000ff>/* grab the image */
$ }1 j$ T2 t2 _! Kgetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>8 ~3 b5 r" b1 d( I
<><FONT color=#0000ff>/* repeat until a key is pressed */
: i" {( A2 }9 A2 M0 Z* m  D1 E. awhile (!kbhit())   X2 g4 a& r/ E
{
9 s3 c1 ^3 T7 V+ s0 x2 h  d6 @/* erase old image */
- q' f( t9 x- m7 ~: Oputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>% }2 D3 U; v: O7 z6 b
<><FONT color=#0000ff>x += ARROW_SIZE; 9 ~5 |8 s( b/ Z( |& q6 u
if (x &gt;= maxx)
% y, A3 p; j8 L8 ox = 0; </FONT></P>; h6 j1 n. C2 g! a- n/ f
<><FONT color=#0000ff>/* plot new image */ % M5 B: ?3 Z# T  T* C# c' i6 L: S
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); . c0 G6 \9 i- g7 J" U$ s
} </FONT></P>
! M" h8 l# J! u% X8 R<><FONT color=#0000ff>/* clean up */ ( V. c% J6 i" N6 ]
free(arrow);
5 A0 L3 ?  b' e% W: ?closegraph();
( \: _9 @8 n- }0 S, u! C  greturn 0; # A8 ^9 Z" {% ]: N$ V
} </FONT></P>
4 R% s- C9 X% X2 M<><FONT color=#0000ff>void draw_arrow(int x, int y)
8 P, S* q1 u5 o8 u{
/ ]/ d* w! R9 N* T$ \% P) A/* draw an arrow on the screen */ " z0 L$ v7 a& c, H. p" x
moveto(x, y);
: b  C; x, Z# _linerel(4*ARROW_SIZE, 0); ! G# o) L( }: |# V$ B+ V% Q9 _  C  a
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); + r) I+ ?0 R# C6 B. ?8 ~5 H, b
linerel(0, 2*ARROW_SIZE); - W! f. g, Z8 o' t6 `8 @
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); , p- _5 U& l. T: h/ N
} 4 u% u5 ~0 X- `+ W: c; u

, M! F: b, k0 P) \, e( ?1 @$ W9 z' ]  K1 l
</FONT></P>
3 X# t" b0 n; C& U. Z<><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
7 e7 `$ l, H1 K, s  l2 H0 l<FONT color=#000000>功 能: 初始化图形系统
. Y0 G: L9 N+ e! D! k) O用 法: void far initgraph(int far *graphdriver, int far *graphmode, - J  f" e- R* w. y
char far *pathtodriver);
4 u& }( Z# @2 w; x! ^+ ^; t程序例: </FONT></FONT></P>) t2 A0 R- P# x8 x
<><FONT color=#0000ff>#include <GRAPHICS.H>' q& \8 r1 f' n2 P8 _
#include <STDLIB.H>
/ y( n/ {7 _, H0 T" v7 L2 u#include <STDIO.H>
3 u1 Y' h0 x, a+ R#include <CONIO.H></FONT></P>
3 x! ~  z* K& _1 u& \<><FONT color=#0000ff>int main(void)
0 i  N  N: G7 W% }{ & _- M0 P0 m2 x0 q0 A  ~3 k: T
/* request auto detection */
+ H( H, [1 \4 k- p- @/ ]int gdriver = DETECT, gmode, errorcode; </FONT></P>
& G6 ^; [9 i+ h: `( u0 W- N<><FONT color=#0000ff>/* initialize graphics mode */
# R3 ?3 Z  R1 T& winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( ?. [+ z+ i3 o) ?  d2 @$ ~- S
<><FONT color=#0000ff>/* read result of initialization */
# ^0 o! K1 C+ yerrorcode = graphresult(); </FONT></P>. G( g4 X3 P0 N9 ?/ _
<><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
: u! m* f1 t  a0 ^% _( I9 s: b{
: h$ ]- w" A3 `& Zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ( e# ^- ?9 M; \; I  D9 R! @
printf("ress any key to halt:");   Z9 Q2 R, ]+ Y7 T& z
getch();
+ s1 l% a) l0 T6 b' _! ?  Pexit(1); /* return with error code */
- g4 ^2 T2 \% A' O# `! f} </FONT></P>0 m4 ^+ j8 C; [( W8 Q
<><FONT color=#0000ff>/* draw a line */
" k- T/ y9 b/ Z6 f  e7 j; _" S2 F5 @, kline(0, 0, getmaxx(), getmaxy()); </FONT></P>, E  Y. F/ K8 W" }* A$ {
<><FONT color=#0000ff>/* clean up */
  e( j4 k6 k7 [- ggetch();
- D+ |: E; Y7 i4 c# V/ f' a& [closegraph(); ( A4 F. F: w6 S  }* `: J
return 0;
3 z$ g. D  N' W0 j0 g4 {} </FONT>
7 x3 @: }' ]7 Y) Z7 R- ^
7 @3 p* D$ N" J$ }</P>
% L9 ^# m& E- e) g. h<><FONT color=#ff0000>函数名: inport </FONT>5 F& P0 y7 Y0 u
功 能: 从硬件端口中输入 , u, j; c: f" S
用 法: int inp(int protid);
) O% S; ]0 J- M3 f4 O/ y& M程序例: </P>
$ K0 u: M6 ?* I: k' B- m/ E<><FONT color=#0000ff>#include <STDIO.H>( V' m' _; ^2 f! H" A' {
#include <DOS.H></FONT></P>5 G& S7 v- B' l1 S5 \
<P><FONT color=#0000ff>int main(void) ! i+ A& I/ u, z- @% X6 `
{ ( V0 E9 ]: W( F, M! v
int result;
0 l6 g3 Q( W& F8 h$ Oint port = 0; /* serial port 0 */ </FONT></P>
  F9 D+ r+ i& w6 i8 E# d0 L<P><FONT color=#0000ff>result = inport(port); ! s3 p+ V9 ^2 @  c( J% ?, I4 \" b
printf("Word read from port %d = 0x%X\n", port, result);
0 ^6 P" O4 V6 P  P2 X- T  Xreturn 0; ) c5 S" o* X" D9 u9 z  [  P
}
5 }" L* H4 ]" h; G( u
4 p6 J1 ?/ |5 ?/ \/ P</FONT></P>
) }* N& A! c, P* d: c1 G' c/ |2 F5 l<P><FONT color=#ff0000>函数名: insline </FONT>5 |' K0 i9 D. i* n; k$ N
功 能: 在文本窗口中插入一个空行 - N- `4 Y$ r" U+ Y5 V6 z# D4 j" Q
用 法: void insline(void); 9 _1 x+ i% d4 o" y% M
程序例: </P>
; m0 P4 I+ h/ Y( t0 ~8 }<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>9 c% r- g7 N4 z9 C/ B
<P><FONT color=#0000ff>int main(void)
4 z7 F" i+ w7 t6 @# g{ " F0 V* o: o3 u5 K. ^' h
clrscr();
  G4 K" D7 J1 f# Y- o# Ycprintf("INSLINE inserts an empty line in the text window\r\n"); . h3 f% o) `/ k  A
cprintf("at the cursor position using the current text\r\n"); 4 h% W+ S; M) I& |7 y( ^% L& ~
cprintf("background color. All lines below the empty one\r\n"); ! \5 ~! j% X$ U
cprintf("move down one line and the bottom line scrolls\r\n"); " U' L' U% }" t( {7 {# _
cprintf("off the bottom of the window.\r\n");
3 ], z# I8 k/ U/ Jcprintf("\r\nPress any key to continue:"); # ?3 b. a* [6 m& ^8 ]5 @
gotoxy(1, 3);
# T/ T' |+ [( j: Z/ S" d- p; [) Mgetch();
* _" O& ~7 q# J+ w/ Iinsline();
# G" n. T) d6 Lgetch(); + `8 f* I: o6 L* n
return 0;
- n9 u5 y; o( L2 O} % B: H" t% [1 x
</FONT>
, @$ h- h) _# E, e% h- N+ e; _/ D* b; j/ r: w
</P>* D5 W+ i! z4 c2 G5 @, b5 U9 ]  _
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>$ l, j; ]' o. p" N; |, |9 B
功 能: 安装设备驱动程序到BGI设备驱动程序表中 / e# C. e# Q# @- O7 t1 e  O- N* a
用 法: int far installuserdriver(char far *name, int (*detect)(void)); 2 L" s- z! O1 Z- x1 d. f
程序例: </P>
7 a$ K& R3 X4 r) C<P><FONT color=#0000ff>#include <GRAPHICS.H>
' j# ]7 ^4 T' s4 ~9 E0 ^9 {. n- p3 B#include <STDLIB.H>7 V9 }% `5 C! v7 ]+ W8 h
#include <STDIO.H>
/ K# w0 W1 J- R( X# N. h#include <CONIO.H></FONT></P>$ X3 @6 ]/ {' p6 {$ r( x- v
<P><FONT color=#0000ff>/* function prototypes */
! ]3 V% H7 r3 N8 m/ Zint huge detectEGA(void); ) N6 G. D& O) Y" _# \
void checkerrors(void); </FONT></P>. G% |- ~$ _& D
<P><FONT color=#0000ff>int main(void) 9 }) f$ g! `0 V
{ ) E) h4 @% F- H; T
int gdriver, gmode; </FONT></P>- ]$ b* W5 I9 O) n0 H5 D
<P><FONT color=#0000ff>/* install a user written device driver */ ( n! e! r5 R$ @2 I' e6 o  i
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>% K: K" ]7 r: r4 Z4 |' C) E! A
<P><FONT color=#0000ff>/* must force use of detection routine */
! K0 P$ x5 k3 rgdriver = DETECT; </FONT></P>% U' a$ M. U  {0 R' m
<P><FONT color=#0000ff>/* check for any installation errors */ : G  R5 K+ y+ |7 j3 X
checkerrors(); </FONT></P>! Q! J  B! R1 Q; o5 ]" w8 h2 g
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 `& X" j! e, R% L- g' s, ^8 r8 U( t
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. A8 i0 S# \/ Z! K
<P><FONT color=#0000ff>/* check for any initialization errors */ 5 K; D8 Z9 y- i6 m: b; t$ l% W
checkerrors(); </FONT></P>; h$ G: k0 y* h& x& U
<P><FONT color=#0000ff>/* draw a line */ 6 u) b2 R7 P) Z- d0 a
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
! y) i5 g% O! q3 v<P><FONT color=#0000ff>/* clean up */ ! h# ?( Q% c+ D5 O: h9 X" T8 M6 v3 n% K
getch(); ! A% Y( S4 G$ i. D
closegraph(); ; ~# n1 ]( P( D6 j) {
return 0;
5 T# [! ^9 p  c$ O8 U' q} </FONT></P>
' U; P  P* l$ }( f<P><FONT color=#0000ff>/* detects EGA or VGA cards */
2 g9 j7 b+ A# O7 r6 Pint huge detectEGA(void) : _! X  C% h  q( T& }( I2 e+ T
{
0 T/ C% n& g/ [) i& O, tint driver, mode, sugmode = 0; </FONT></P>- D$ c! T) u% ^7 B! _) Z: j
<P><FONT color=#0000ff>detectgraph(&amp;driver, &amp;mode); . y9 h0 O* l% R- ~/ D
if ((driver == EGA) || (driver == VGA))   u$ K) o( F% O9 y
/* return suggested video mode number */
7 c1 j9 n( G: i' x" Qreturn sugmode;
- E* p2 C. b% l4 ^else
2 F2 [) h' v5 V1 s+ Y( I4 `, o/* return an error code */
$ W  L' e7 t- V. Areturn grError; ( s6 X1 ]4 a) f) ^" r
} </FONT></P>: n4 J! g; l( T7 j0 i/ g! Q
<P><FONT color=#0000ff>/* check for and report any graphics errors */   J+ f" l. g- r3 l3 h. U/ ~- K
void checkerrors(void) / A6 W$ d3 ~: y6 T
{
$ _( ]: I7 H0 i! vint errorcode; </FONT></P>; z8 O  c( x& U0 I/ t9 |
<P><FONT color=#0000ff>/* read result of last graphics operation */
! e8 D) j! m+ m7 x) Q, jerrorcode = graphresult();
2 n- B0 P( o1 b0 Gif (errorcode != grOk)
# Z  Z) O0 j, ?& @0 y{ 6 g0 K- R1 F1 p
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 R& h5 y2 w& T% ]7 hprintf("Press any key to halt:");
! ], b! ~2 `8 c. L( Qgetch();
& x6 ~+ H( _( K' @5 k0 Gexit(1);
/ A3 c- d. h) s} 0 T2 }: W: t; e8 S6 t8 W
} </FONT></P># B, B1 ]8 o3 P2 M! M7 |! ~6 V
<P><FONT color=#ff0000>函数名: installuserfont </FONT>
4 S+ t" A  Q% E/ @/ i+ v! a  P4 @功 能: 安装未嵌入BGI系统的字体文件(CHR) - w/ [/ w( S. C1 n
用 法: int far installuserfont(char far *name);
9 |% E0 a/ E4 w2 r6 M% E程序例: </P>
! Q' I! J- v7 ?: u9 u! V8 H8 d) J<P><FONT color=#0000ff>#include <GRAPHICS.H>) c7 K( s5 t2 U, Q3 f' C  V
#include <STDLIB.H>0 a! o- G7 i+ o8 ?+ `
#include <STDIO.H>
/ L0 O  k( |) i  s3 ~5 S#include <CONIO.H></FONT></P>
+ [+ Q# B  N4 D% u" S<P><FONT color=#0000ff>/* function prototype */ : D5 v$ s& {. I% e
void checkerrors(void); </FONT></P>
& A  u0 D' ^; G- A2 v) _5 `5 W# j# M<P><FONT color=#0000ff>int main(void)
" G: q9 a: y: \6 F9 k' h( K( y{ - C% D9 g1 Q, J+ q* U  p
/* request auto detection */ ; @  Y4 B6 ^5 s8 j  q' O2 e- V
int gdriver = DETECT, gmode; * D6 h+ a) q  N2 T2 T) `& |1 ?
int userfont; 9 Z& a1 n4 V4 W( n
int midx, midy; </FONT></P>
6 R' L8 N8 a$ s<P><FONT color=#0000ff>/* initialize graphics and local variables */
* x# N& n' W& E! _6 G. t- qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ x, F+ U  E! g5 M# @, H: j0 M/ d<P><FONT color=#0000ff>midx = getmaxx() / 2; . f+ Y& e$ I# k" v( P# ~
midy = getmaxy() / 2; </FONT></P>
8 s2 b; y3 k6 r* W) V# c! C<P><FONT color=#0000ff>/* check for any initialization errors */
% p! b: m# D% D8 D4 u& |+ b" gcheckerrors(); </FONT></P>0 w  X- u2 U0 i1 [
<P><FONT color=#0000ff>/* install a user defined font file */
# ^) {8 V9 _- ~8 vuserfont = installuserfont("USER.CHR"); </FONT></P>
# e  z- v: i8 e7 S. s* s9 n/ e  D<P><FONT color=#0000ff>/* check for any installation errors */ ( ^: f' b: h# |
checkerrors(); </FONT></P>
; W4 [: Z$ Y1 m  t" ]2 P<P><FONT color=#0000ff>/* select the user font */
! k, @8 z! ^' ?3 c5 l5 ksettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
; Y6 h' x; z4 W9 {& U' U' E$ }' b( e<P><FONT color=#0000ff>/* output some text */
1 M/ |9 `1 ?& |: H0 a' D& q, M$ e% e  Couttextxy(midx, midy, "Testing!"); </FONT></P>/ \% Q6 ^& b- \4 L9 o/ |% {2 A* k
<P><FONT color=#0000ff>/* clean up */ ( s! {  E4 ^# ~/ o1 D6 o# G
getch(); 0 R  c/ b" ?/ d& g7 r2 [1 T; e
closegraph(); 5 A( o1 ]1 C+ S9 c! l8 g( @- m
return 0; - L6 e3 t& `* o& ]8 J: L) `
} </FONT></P>: h# y. G7 P+ E7 t3 s+ u- v5 q
<P><FONT color=#0000ff>/* check for and report any graphics errors */ / _' S6 |, \  l$ z4 `3 D' o1 j# A
void checkerrors(void) # E5 t9 r5 @- {8 {: P( ~# K
{ : j. W) ~- U8 v2 g+ L4 l3 H
int errorcode; </FONT></P>
+ N7 Y9 M* g7 {( b) j<P><FONT color=#0000ff>/* read result of last graphics operation */ - W6 y! W# W8 `) ?/ ]
errorcode = graphresult(); ! e0 j) y9 H7 u- X+ V
if (errorcode != grOk)
7 u4 v% `6 l- E7 j6 G! ]{ 0 k& U* F3 W7 p# I
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * O$ y( N9 r3 c& _- ~
printf("Press any key to halt:"); 7 W$ f; P) E* S
getch(); - U. A  `0 l4 N& r0 s2 e3 A
exit(1); ) _% O% `: ^0 K0 v- n) R/ x( N
} 6 f* F$ w# n4 Y! T3 l& _3 w
} </FONT>
+ f, V6 u- R- T* s
3 H* F1 Q6 `' Z; H, p6 b/ `* Z( z# [9 C/ v( D8 F3 n% @( s
</P>3 k; E& l# r% y. `: i% W
<P><FONT color=#ff0000>函数名: int86 </FONT>! B( k$ o) @% a2 m. P
功 能: 通用8086软中断接口
1 ]. D* c( t1 A1 g3 w用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
/ O7 T3 W) @, d7 K8 K& ?7 @) R+ P" P程序例: </P>
5 U; r( v( \# K% O# _<P><FONT color=#0000ff>#include <STDIO.H>
7 l% I" m! f. _0 Q1 C#include <CONIO.H>
- q! K' l' f7 @! W. {! |#include <DOS.H></FONT></P>! P; q/ l, l: ?! |# o( C3 S! R5 S
<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>8 @! J: p$ j8 ~
<P><FONT color=#0000ff>void movetoxy(int x, int y)
* R+ j( k% S% ^( T1 w" R{
. z* p# O' B. s$ Z/ Zunion REGS regs; </FONT></P>, B8 j& [, ]. r# b
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
5 T6 k4 y, \" o! y8 _regs.h.dh = y; ! M4 J  @+ X/ O" P. a2 g) z' U
regs.h.dl = x;
# a/ D6 g1 @& t; x+ r+ eregs.h.bh = 0; /* video page 0 */
8 ^( X' j9 ^0 @* x' Oint86(VIDEO, &reg;s, &reg;s);
3 Z7 [. c$ _2 K: ~6 q# b} </FONT></P>7 j5 w  U% b7 x
<P><FONT color=#0000ff>int main(void) & E/ Z! b: `7 k
{ 4 D! T& l+ U# t# V8 h
clrscr();
9 ?1 q( T0 c( x, |( amovetoxy(35, 10); , m7 I3 X2 W* a! b! L+ \& u
printf("Hello\n");
* i* E8 K4 t& B  A, D5 kreturn 0;
% y2 b; E$ F) M, J$ k9 g: D} </FONT>: H  e* b$ a& b' v9 J8 O# i' ]4 r

, l& I: f' P2 q. a1 a</P>
  q6 x* ~3 y: n% B0 \<P><FONT color=#ff0000>函数名: int86x </FONT>* g/ |2 b# Y1 S& n" q7 c
功 能: 通用8086软中断接口 ( X& j! v2 s4 ]* ]& a; m
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
3 K6 _; ^1 @) Y# vstruct SREGS *segregs);
5 e/ }4 Z4 i* O: s1 D1 {程序例: </P>
4 h. d: m" [0 w( u- b8 y7 V4 r<P><FONT color=#0000ff>#include <DOS.H>3 g/ ], d* |& r: O) e
#include <PROCESS.H>
( T6 u5 ~* X( L#include <STDIO.H></FONT></P>
9 p8 z  O5 _' x; s2 D' M" l* f<P><FONT color=#0000ff>int main(void)
8 l$ W. V7 i& G- f. B{
. ^1 h2 N3 a8 ]" X0 t8 Ichar filename[80];
; E& E4 P, k9 [8 k; ]( Gunion REGS inregs, outregs; / R; X# h2 ^' |* [% t
struct SREGS segregs; </FONT></P>
/ i! s5 c  a7 \% A" z3 V<P><FONT color=#0000ff>printf("Enter filename: "); $ K8 C# ?: R4 S" z  A8 }
gets(filename); / ~% ^0 l. Q6 N, e
inregs.h.ah = 0x43; ' _4 u! J% Z* ?, U5 ?% M- N
inregs.h.al = 0x21;
# q7 U9 T% t! n0 e  i, [- rinregs.x.dx = FP_OFF(filename);
5 d& g1 g7 p* o' ~segregs.ds = FP_SEG(filename);
4 p, [8 M% k8 e* Wint86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs); 0 g) a  ^8 J1 b7 l7 K  f: b8 u
printf("File attribute: %X\n", outregs.x.cx); ) v8 a( t. X- |# Q
return 0;
% i) q2 I( t% v' j( @: x9 W}
" }( r. C8 f+ `; c) }' K1 ]* h: r4 o  z# G  ^
</FONT>/ K3 c, s1 g* ^
</P># {5 _0 |3 X( g. O1 D5 w0 o
<P><FONT color=#ff0000>函数名: intdos </FONT>
2 D" b8 n" w  d* H  r2 B+ c' @功 能: 通用DOS接口 4 n/ \( p- }+ J) x/ y% E
用 法: int intdos(union REGS *inregs, union REGS *outregs); 3 J% Q9 ]9 N( }3 a0 U4 [
程序例: </P>( U, a, b' y1 m1 a& J4 l* h
<P><FONT color=#0000ff>#include <STDIO.H>
' w+ I! q& \. p2 s6 D! e3 a6 @9 d#include <DOS.H></FONT></P>
% h" l* [& n' S9 h4 W) p<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ * z6 X9 b8 \6 d3 ~1 Y
int delete_file(char near *filename)
( c& g, A, y8 T( |{
! L! A5 ?; ]. j( ?# `union REGS regs;
3 D3 @9 H5 q* o0 g4 t$ l& B% t& Zint ret; + `7 g  ]/ q/ t# o- O
regs.h.ah = 0x41; /* delete file */
. F0 U! p+ w0 _9 a; J8 Sregs.x.dx = (unsigned) filename;
; D3 H1 [, ?( I4 E- j4 m6 Oret = intdos(&reg;s, &reg;s); </FONT></P>3 v' i9 u  x: _
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
. f3 ^$ C- X. Y1 Ureturn(regs.x.cflag ? ret : 0);
6 O" x" s. `6 d4 [} </FONT></P>
, J: V* I9 e" q- Y8 s* z. g<P><FONT color=#0000ff>int main(void) 6 y, |: K8 G( y, o
{
8 ?; u. r7 L7 \0 L8 \8 xint err;
6 t. B' V/ S1 g$ @5 q- Uerr = delete_file("NOTEXIST.$$$");
$ D8 o9 H8 N) q7 ~" F: |3 Wif (!err)
, [$ Z* Q( [/ E, K: G$ }6 Lprintf("Able to delete NOTEXIST.$$$\n"); 0 `) ]- m' V+ I
else
- p; {9 S. B+ tprintf("Not Able to delete NOTEXIST.$$$\n");
3 h+ ~  v+ K3 S, creturn 0; / H+ Z2 X: s# O8 e
} . p8 d) u3 n2 X" a5 Y

+ _" z) l% g, R/ `/ ^3 Y9 ^</FONT>; h* ~9 K7 O9 n, f! R
</P>
; N' Y1 U) D' k4 u<P><FONT color=#ff0000>函数名: intdosx </FONT>
: j; o7 x( `6 l. o* J) b功 能: 通用DOS中断接口 3 f# _/ J* i* C( @- m6 d4 Q
用 法: int intdosx(union REGS *inregs, union REGS *outregs, ) u- W/ |% c0 C" h' Q% J( h1 P- v2 o% q
struct SREGS *segregs); 6 w+ O3 \; ~  V( ~/ o: E3 y" m
程序例: </P>
) i& u" c; `0 P$ K1 C$ [, W<P><FONT color=#0000ff>#include <STDIO.H>
. ~/ K- V6 C. I) L4 ~0 J#include <DOS.H></FONT></P>5 o' Z; g+ p* [; |
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 1 P! f* P4 d+ d) l0 d0 Q6 ^5 C; e
int delete_file(char far *filename)
0 A! O7 G" ~: D7 }3 m- x: j& o{ * c4 H2 m+ j7 B# m/ B# D
union REGS regs; struct SREGS sregs; 5 z* e1 G8 F: y5 x! b
int ret;
* _0 w* C8 S" Cregs.h.ah = 0x41; /* delete file */ 9 J4 U8 u% d4 d+ V. ^. k
regs.x.dx = FP_OFF(filename);
% q" |* l! |4 v/ N) ksregs.ds = FP_SEG(filename); . ]" O5 Q1 o$ C: J0 T
ret = intdosx(&reg;s, &reg;s, &amp;sregs); </FONT></P>
( K, [: @6 I. s<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
) h- i4 y) i8 T0 \return(regs.x.cflag ? ret : 0);   B2 u: R% g" g! v6 y4 a% K. V- ]
} </FONT></P>2 T3 m/ U' y8 e2 L$ }! w
<P><FONT color=#0000ff>int main(void) ! D0 [3 R! J* I7 H* ^& c' X! G1 T
{
9 U& E1 {6 P; b* S" X- T; Xint err;
7 K& Q9 k" J. H8 w, b1 {err = delete_file("NOTEXIST.$$$");
/ l' W$ O6 t2 E4 m- e$ M' [6 W0 Jif (!err) 3 W* Z( N( |1 I+ f" I
printf("Able to delete NOTEXIST.$$$\n"); $ K9 U: m' H! P
else 7 X/ y( }. G  d
printf("Not Able to delete NOTEXIST.$$$\n"); 3 q$ o! m4 R: E! w  j
return 0; ( j  x; P' Q3 S2 r& R
}
" U0 n2 h) L0 `  h</FONT>
. w1 t8 F/ `" x0 U, x</P>
* T; W" l8 g2 I$ W# ]# m& Z<P><FONT color=#ff0000>函数名: intr </FONT>; }' L: W- R" C# W& q& H% {1 T
功 能: 改变软中断接口 3 x; o, \5 _! S8 W( Q# X% ^
用 法: void intr(int intr_num, struct REGPACK *preg); 8 e- V0 z$ u% `2 }
程序例: </P>
# ^% a# K, s$ i/ b% h# j1 }<P><FONT color=#0000ff>#include <STDIO.H>, l4 f; B0 W$ p& `4 M, s+ e5 B
#include <STRING.H>( V  q, d9 a) [& h6 z! o" V) e
#include <DIR.H>
' ~1 ~  V! Q+ L9 u5 Q9 w#include <DOS.H></FONT></P>
; k$ \' Y8 c5 \6 }* R. I4 e<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>' ]% L  e6 \) M' p  S
<P><FONT color=#0000ff>int main(void)
6 r9 ~3 }" A1 f) N- w8 y( @% ?{ 1 T) C5 ^( {( R9 ?- p! E4 i+ a
char directory[80];
3 r8 ?% p* M7 G1 A" I1 _' F% nstruct REGPACK reg; </FONT></P>; P; F) X+ B4 Y- u1 k
<P><FONT color=#0000ff>printf("Enter directory to change t "); ( Z: R0 `  R5 a# J
gets(directory);
. x' b0 H& F& d& s/ freg.r_ax = 0x3B &lt;&lt; 8; /* shift 3Bh into AH */
% n2 u  s8 l1 breg.r_dx = FP_OFF(directory);
. i( A0 v( \9 A. \) o8 Lreg.r_ds = FP_SEG(directory); / J, D, d2 a3 q1 A7 Z' N
intr(0x21, &reg;);
0 G$ P! m7 o* @4 y! a/ e3 H- zif (reg.r_flags &amp; CF) 8 F8 t  N& {: b; P: d/ R
printf("Directory change failed\n"); * g6 v9 ~2 C- ?* y) p% p' Z/ k
getcwd(directory, 80);
8 W/ n9 L* _5 f' R' y1 Fprintf("The current directory is: %s\n", directory);
/ T  o; |3 l; x+ ereturn 0; $ Z, Z, d4 ~8 Z, y
}
. x' s$ Y  c* n1 p; O9 [</FONT>
: A6 K! o9 N; e( a9 C% y</P>' J) `8 Y0 z/ v( b: q+ t
<P><FONT color=#ff0000>函数名: ioctl </FONT># q* L; `/ t4 [# m4 U, u9 Q
功 能: 控制I/O设备
$ a( W1 M- B! L5 h8 N: g' Y8 W: e& D2 [' \用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); 9 `0 _% o0 F2 R8 E
程序例: </P># P! x3 \* M+ z8 g$ B8 k
<P><FONT color=#0000ff>#include <STDIO.H>" o  \$ K# B  b) b4 P
#include <DIR.H>" h1 Q0 Z2 g, a4 g9 z8 ^
#include <IO.H></FONT></P>
; @- _9 E1 M' `  g+ j/ {3 b( r- |3 c<P><FONT color=#0000ff>int main(void)
1 A5 u* m4 m7 T. U4 D{
+ s+ n5 o0 a3 R$ g, cint stat; </FONT></P>/ H7 K+ h9 ~+ |% E4 e9 s5 q  B) u
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ $ s. c& f9 p; B7 R3 g8 `1 y) O
stat = ioctl(0, 8, 0, 0); , T* k& W0 D9 L% N; x3 K
if (!stat)
! ~; {# ?: r4 V0 L* `4 ^8 Y: Pprintf("Drive %c is removable.\n", getdisk() + 'A'); 7 o# q1 P  j) e4 w
else
1 G7 d6 Y, O. \5 I' mprintf("Drive %c is not removable.\n", getdisk() + 'A'); 8 b/ S5 ?& M) o# J8 a. ?9 }2 K
return 0;
% P* L8 ~# \1 d$ O* o) J7 j} 1 G0 i' j2 Y- e/ D, B

3 L8 T' [" j+ z0 o) W0 R: Q) \# n</FONT>
4 W) k2 m  K( p5 r3 m3 K$ G* t</P>! G; y& a+ |4 W6 A
<P><FONT color=#ff0000>函数名: isatty </FONT>! F# `& f' s8 B7 }" n( I
功 能: 检查设备类型 6 g# Q  z1 s" Z. e& @& R
用 法: int isatty(int handle); . [4 ^0 Q; u) `. X! S
程序例: </P>8 _$ S, ]6 |* T2 F1 n
<P><FONT color=#0000ff>#include <STDIO.H>
' U7 H+ f: Q& }: t$ u: v; D! R9 r#include <IO.H></FONT></P>3 G3 b  I5 f! k% s8 \
<P><FONT color=#0000ff>int main(void) 7 V' Q- [. h, |4 m+ j7 v
{ / m; u1 M4 c! r6 l  k
int handle; </FONT></P>" }$ l) g. O# }
<P><FONT color=#0000ff>handle = fileno(stdprn); ) a9 R8 {, C0 c1 s) }. w0 p# ]: p$ p
if (isatty(handle))
+ s3 o. D$ S5 ]5 B& Yprintf("Handle %d is a device type\n", handle);
. B' R' Y* T, Z# F! t; Gelse
/ O( Y$ m$ W/ u+ M8 oprintf("Handle %d isn't a device type\n", handle);
( x' N% B0 P4 O/ L7 {# Kreturn 0;
4 F* ?* M; [5 ]0 S2 x; M}
" h. n) F- o, |# A0 ]- Q* s7 Q2 r9 u9 ?) k* ]( P
</FONT>: y. a; l$ k# D) m" d( T
</P>
+ b# @. J; s- F' @0 r7 R<P><FONT color=#ff0000>函数名: itoa </FONT>
9 g" P1 S8 A9 ^9 |1 p: e9 L$ ]% a功 能: 把一整数转换为字符串 " w" Q; q% }( {0 i
用 法: char *itoa(int value, char *string, int radix); " D, n5 U" E# r& [$ E- x! `, c
程序例: </P>; n% T! o1 ?" V+ L
<P><FONT color=#0000ff>#include <STDLIB.H>" g; h* l" ?' p% ?% W6 v' U4 E3 s
#include <STDIO.H></FONT></P>
/ h" p" G# M) u0 B7 u4 X$ t<P><FONT color=#0000ff>int main(void)
, f/ q' D- i0 Z3 m{
8 O' @- E+ R9 s% V# e" Gint number = 12345; 8 G( R3 K8 G. N7 h
char string[25]; </FONT></P>
9 @$ S& T6 t* t3 R0 }3 U* e; I<P><FONT color=#0000ff>itoa(number, string, 10); $ ~5 F4 U$ b7 e
printf("integer = %d string = %s\n", number, string); ! {& V5 r1 ~8 J; z$ u2 t3 e
return 0; , |7 A/ ~0 H7 U
} </FONT><FONT color=#0000ff>  b' t# o4 f5 e. m' \# |
</FONT></P>




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