QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2369|回复: 0
打印 上一主题 下一主题

函数大全(i开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:59 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>' h7 I- Y" b4 h3 X
< align=left><FONT color=#ff0000>函数名: imagesize</FONT> ; y8 @- ~- Y* ?5 i- d2 P
功 能: 返回保存位图像所需的字节数
& g3 @/ H6 N# u" t1 U; O: p  c用 法: unsigned far imagesize(int left, int top, int right, int bottom); 4 {" v6 E8 [( K  M3 M% C$ T
程序例: </P>
' @, s9 l' ~8 Z9 U5 N- b; f<><FONT color=#0000ff>#include <GRAPHICS.H>
  D7 }/ }& q/ s7 `#include <STDLIB.H>! h) Z- T* j/ x; y' I4 h- P& \
#include <STDIO.H>
( t) w' K2 N0 Z" S#include <CONIO.H></FONT></P>3 T& v$ i2 V) L8 Q
<><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
, w* a5 r, c" o: U. d8 \0 d<><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>
7 J: {! a, p8 z* M<><FONT color=#0000ff>int main(void)
/ p3 d- L- B: E, g% q{
) e- B$ {6 K9 A( N) E) L/* request autodetection */ , n' F/ ?6 c% e3 @
int gdriver = DETECT, gmode, errorcode;
5 Y' B8 Z3 K. L3 x5 C" uvoid *arrow;
" ?# [) S5 k$ Tint x, y, maxx; * ]& y: n) H( V6 ~( C
unsigned int size; </FONT></P>
# ~" K3 n+ F+ F* {7 k; m<><FONT color=#0000ff>/* initialize graphics and local variables */
- Q$ V1 i9 N+ ^0 l! ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; F. r7 m) ^# d  p  D# }; |# Z9 H5 t<><FONT color=#0000ff>/* read result of initialization */
1 P* g% F- ~, D; eerrorcode = graphresult();
4 O' ]3 ]. @" l1 K* ^" G( kif (errorcode != grOk) /* an error occurred */ * z9 m6 V6 F/ a: q( s5 A
{
% A' C  R7 _, D( Lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ W8 [3 l8 ~% v+ O1 v# b0 C
printf("ress any key to halt:"); 2 n) t; `' U  m1 B! E5 c
getch(); , `5 J' `; G- [& U
exit(1); /* terminate with an error code */ * B6 b1 K# S& P4 B# s
} </FONT></P>$ v0 S& a8 [: a3 s5 @. @
<><FONT color=#0000ff>maxx = getmaxx();
* ?: z! \$ r" E: t$ [; n+ fx = 0;
" T: U: f# h1 h! ]4 ly = getmaxy() / 2; </FONT></P>
0 u9 o& P8 f0 _<><FONT color=#0000ff>/* draw the image to be grabbed */ $ ^) F7 a  W- P: A$ C
draw_arrow(x, y); </FONT></P>
! b/ X& g0 p$ J! G% r1 I<><FONT color=#0000ff>/* calculate the size of the image */
  u: A5 c& y6 u1 @+ s9 Zsize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>+ L) O+ c2 j- @: b/ M
<><FONT color=#0000ff>/* allocate memory to hold the image */
2 ]/ n3 l9 d  R  karrow = malloc(size); </FONT></P>
; x* \( Z$ `8 s% I6 L<><FONT color=#0000ff>/* grab the image */
- I8 A; O. l7 [2 o5 [getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>; x0 S* K/ D# I( v/ j
<><FONT color=#0000ff>/* repeat until a key is pressed */
1 g/ \( j7 n: ~) Y6 O5 j7 u! ~while (!kbhit())
: K: u, ?% L0 C0 l3 y' {{
7 J9 f4 z0 ]( D* ?/* erase old image */
6 ]9 y8 A3 Y0 J2 F% O) Y& R! gputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>, R0 o+ A. n: a1 O0 x$ M
<><FONT color=#0000ff>x += ARROW_SIZE; 5 ?! }1 r4 t# }/ L1 N/ ]" H
if (x &gt;= maxx) 3 U- ?5 h& h; b7 ?3 E
x = 0; </FONT></P>
$ y, ]5 ~3 m" G( c<><FONT color=#0000ff>/* plot new image */
) |2 g# ^- l! @4 a* ^! H* c2 sputimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
* \) _& u5 n  U1 h} </FONT></P>
. D2 [; X& W( ?7 n5 \<><FONT color=#0000ff>/* clean up */ $ y! b4 }% U7 S4 ?/ u
free(arrow);
( ?9 c  Y+ u' I" t. @closegraph(); 3 |' q9 J: Y: B6 `" K
return 0;
1 `  i) u/ N9 A) g} </FONT></P>
, H2 m5 E: x4 a1 L0 V% b6 \<><FONT color=#0000ff>void draw_arrow(int x, int y)
' ~2 F! ~; P# D/ J' P( p- ^( I! y{ * K& {, F2 m& c' N
/* draw an arrow on the screen */ # k* m" N: n' D5 m% ?  d
moveto(x, y);
' t! K: _9 x4 _1 J$ flinerel(4*ARROW_SIZE, 0); 4 h# `/ i8 ^" k7 ]) y$ p3 F
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
" K# s5 ?, `+ i1 X: f# k* O6 b& glinerel(0, 2*ARROW_SIZE); / F- }' h( _! r
linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
0 u, W. ~# O, d9 O# f}
' i' Z0 \9 e$ G: e9 }: o3 [6 _7 F3 n; z' d

) s$ B6 w2 n: X8 r! M. o</FONT></P>9 ^; P( J) l: o( Z9 R% G/ N  F0 A
<><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>0 v9 b, j) w' Z: i) t  W$ {0 P
<FONT color=#000000>功 能: 初始化图形系统 3 e+ _5 d- r) D1 o% @
用 法: void far initgraph(int far *graphdriver, int far *graphmode,
: d8 a8 u9 _  {char far *pathtodriver);
0 K; K0 C% o7 y7 E. f/ {4 X( Z程序例: </FONT></FONT></P>
+ h% C9 C" q3 q- z<><FONT color=#0000ff>#include <GRAPHICS.H>9 W' ]& M) v1 c' W
#include <STDLIB.H>
4 F4 f% j. F9 X5 z#include <STDIO.H>
+ ?" B# k: t0 `# t8 {3 e1 Y#include <CONIO.H></FONT></P>2 S7 w4 B& Y. L3 o
<><FONT color=#0000ff>int main(void) ) J3 l) R% }6 U9 J+ ]
{
' s5 Z, u* C$ p: ], I/* request auto detection */ : W0 v% _1 _9 ~' V6 f
int gdriver = DETECT, gmode, errorcode; </FONT></P>* F# x6 P7 Y7 y; t/ b5 ^: I3 o
<><FONT color=#0000ff>/* initialize graphics mode */
& ^$ Q6 I* F# p) g& j6 t3 M- x7 E3 `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# p6 G; F$ g! X2 K4 S# O! y- ]" \<><FONT color=#0000ff>/* read result of initialization */
6 K3 }; ?2 ^+ E  O! Yerrorcode = graphresult(); </FONT></P>( M0 n) @2 P7 S) [
<><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ : i2 \1 f' M! w( p" f- G
{ 7 C, g' z* q& R* {( J0 T
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - T4 e; q" z8 T
printf("ress any key to halt:"); ) Y/ O8 b- ]+ V3 X4 x) J; y
getch(); / a8 t/ P% K7 u" b, a
exit(1); /* return with error code */
' T; a& y1 a3 ?. N# a& p+ ^1 a} </FONT></P>
4 T2 V) K7 N. a" e. D<><FONT color=#0000ff>/* draw a line */
. `# y1 E; D7 r# C4 p! l; nline(0, 0, getmaxx(), getmaxy()); </FONT></P>
/ I3 _9 J: B6 }' N<><FONT color=#0000ff>/* clean up */
6 |. g* E* r; y  U* j5 ^6 L- Cgetch(); " D) `4 h7 e9 R* k
closegraph(); 5 O& W: l; `4 Y" p
return 0; $ Q2 `( d$ p) G$ c# S
} </FONT>. I; Q0 F- Y% m' G
- [5 v! B: O  g+ V7 T/ J1 B, L) X/ s: k
</P>' ^% i$ \: C: P4 V) [( [4 a$ v
<><FONT color=#ff0000>函数名: inport </FONT>* L  O; T& I$ k  K" J
功 能: 从硬件端口中输入
, ]2 K- `- S) B) h% d用 法: int inp(int protid);
6 a7 V+ y6 `. Q( m, J程序例: </P>: ^* n# S5 A' r2 n
<><FONT color=#0000ff>#include <STDIO.H>5 S. N* ^. `. R4 {3 ?3 r* m
#include <DOS.H></FONT></P>
5 N& J5 S& E6 u1 b# o<P><FONT color=#0000ff>int main(void)
- o& \- v4 L% A0 s{ 2 S5 f+ ?+ U/ j
int result; . ]3 B, S) E8 h& }6 Y
int port = 0; /* serial port 0 */ </FONT></P>1 O/ I5 h# `* t
<P><FONT color=#0000ff>result = inport(port);
" E) f- U5 s- g! s% Cprintf("Word read from port %d = 0x%X\n", port, result);
  ~! K9 P. O* c4 E/ |/ ^' ]return 0; . n4 ^9 Y& _, r. x* y5 b
}
" d! E$ O" N: c; ]  T7 w; p. t* s) p: U" U% s* Z
</FONT></P>
5 p6 [  X$ v4 S9 s2 _0 K<P><FONT color=#ff0000>函数名: insline </FONT>0 Y' x9 `2 `$ o: u
功 能: 在文本窗口中插入一个空行 7 Z* U7 {9 q6 ?2 k+ h3 F4 ^" a
用 法: void insline(void); ( t( |6 M' j+ q; i+ X# Z* U
程序例: </P>% a% x9 W3 ~& d3 F! w
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
! X3 }- u4 Q8 K<P><FONT color=#0000ff>int main(void)
8 Q0 H3 N  z5 |3 _1 W- B7 f{
; R+ `7 ^4 d6 ~$ S; T& fclrscr();
- n) T  G3 o" o/ `# mcprintf("INSLINE inserts an empty line in the text window\r\n");
" a1 F. I5 \' x9 xcprintf("at the cursor position using the current text\r\n");
1 K( u6 q/ n1 F& t& hcprintf("background color. All lines below the empty one\r\n"); . ^7 D: @8 ^* p' t
cprintf("move down one line and the bottom line scrolls\r\n"); # R' W+ W. j9 U
cprintf("off the bottom of the window.\r\n"); 3 D, L: y8 J  V2 `
cprintf("\r\nPress any key to continue:"); + Y; T* j! e, x3 k+ q6 U& ]
gotoxy(1, 3); ( G/ j, O& ?8 r% t$ d( v
getch();
! a: A8 ?1 M& @( {/ t  b5 {/ f- d: a" }insline();
2 r+ V" I! C) X. p/ I0 Q* A0 xgetch(); ! d( ]) l; B" R4 R  Y" ~
return 0;
, [# b3 h3 i: r. z} ' e# s7 |% W+ @
</FONT>
2 \- v* R# a: P
# \& a, r# S! n: G. p0 T, i</P>$ X' ]* C% N: S% {7 q: G
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
& y' C+ x- n2 r  R功 能: 安装设备驱动程序到BGI设备驱动程序表中 ' i8 h! {- H: S  n; n
用 法: int far installuserdriver(char far *name, int (*detect)(void)); 2 @* j: l$ |! E8 c
程序例: </P>; |% i+ x, Y  Q- ], t( B, B; u, r
<P><FONT color=#0000ff>#include <GRAPHICS.H>4 A  i& y7 Z' }; ^/ ~% _. Z
#include <STDLIB.H>: v- b; ]5 R5 d4 @' P
#include <STDIO.H>/ F3 p# t' e3 M
#include <CONIO.H></FONT></P>
4 Q7 s$ l' [; L  L+ z9 T<P><FONT color=#0000ff>/* function prototypes */
( Z+ J  L/ w  O- pint huge detectEGA(void); ) g0 x% J. s! @' O# V. t- i) {
void checkerrors(void); </FONT></P>
/ ]8 D, D6 X+ h; _9 \6 V<P><FONT color=#0000ff>int main(void)
9 q* U6 e. P5 P8 g$ d3 Y, J8 \9 r/ g3 H{ 6 @4 n( I0 d) p/ U2 m) V8 {; f7 r
int gdriver, gmode; </FONT></P>& c& M+ t* \: E: v) I! ?0 m
<P><FONT color=#0000ff>/* install a user written device driver */ / J: a) R: @6 ?
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
0 ~) @( O& w! D7 I7 @$ ?<P><FONT color=#0000ff>/* must force use of detection routine */
, Z: [- d/ U" p8 v5 Jgdriver = DETECT; </FONT></P>
& m3 j( g; h# b( l0 s<P><FONT color=#0000ff>/* check for any installation errors */
9 r0 Z( h7 W) K! n6 `. `. z0 l* s' bcheckerrors(); </FONT></P>$ v: F; k4 G: U( M* H
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; a' ^' A9 D4 u. K2 d0 C9 Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ ]3 [& y- C- K# z( e<P><FONT color=#0000ff>/* check for any initialization errors */ + m* F! @% S$ `& i4 D
checkerrors(); </FONT></P>
" q8 j! ~! l) h% @6 ?3 x8 G, F<P><FONT color=#0000ff>/* draw a line */ 0 M6 x+ z& u$ a' f! A' b* b# J
line(0, 0, getmaxx(), getmaxy()); </FONT></P>: Z( ?! Q- u" z6 X4 A) V- b
<P><FONT color=#0000ff>/* clean up */
. \) c$ e* T4 M8 x, egetch();
6 [; U# @( `2 K+ O7 _0 r( E6 C" Tclosegraph(); ' f: B) }/ ~8 w- E! h0 t& e. Y0 l+ |
return 0;
2 l" d8 \1 X4 i9 |  |) }8 `/ |} </FONT></P>
- f: I2 m* c$ ?( t. T0 T<P><FONT color=#0000ff>/* detects EGA or VGA cards */
9 }- `3 v9 ?! p; b* lint huge detectEGA(void)
+ o" B+ b* X! V{ , `' ?) d' Q. Q% q
int driver, mode, sugmode = 0; </FONT></P>( j- J+ w8 c( Z2 S( h" _6 p
<P><FONT color=#0000ff>detectgraph(&amp;driver, &amp;mode);   f# R) I: ^3 Q4 `  Z+ X
if ((driver == EGA) || (driver == VGA)) ' \$ A& [8 U+ K. Y/ W% H
/* return suggested video mode number */
( _( m6 E. U9 A+ t4 s" j7 areturn sugmode;
+ {3 e( Q9 F6 S4 q9 lelse
5 [" s4 J2 J& f8 ?$ D- M% C  G/* return an error code */ , Y. x( Y) O/ E$ }( W+ J- N9 D
return grError; % o3 o9 |4 t4 A# i) F. J
} </FONT></P>
5 C$ W, w# m0 V8 v* O: z<P><FONT color=#0000ff>/* check for and report any graphics errors */ - F. q6 b7 p/ B: n' t
void checkerrors(void)
. o+ Q" E$ `4 B5 w1 ?{
2 d0 j% a( q& m* x" ?1 zint errorcode; </FONT></P>
- b- x- a0 Q& B8 R2 r6 [4 {! r& {  }<P><FONT color=#0000ff>/* read result of last graphics operation */
) U% t& \( d. p) Kerrorcode = graphresult(); + g: P. |+ L1 M8 _6 x- {3 [
if (errorcode != grOk) 8 a" Y6 Z6 M# _# I/ b. B
{
4 `& d+ ]) M+ t: n; D# wprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " @4 M- g& A3 [
printf("Press any key to halt:");
0 r4 p4 N3 V$ Cgetch();
+ A7 g0 Y, E/ S# R6 Z: ^exit(1);
/ D% D& R3 @0 o7 o0 _2 [  e} 5 ~5 j) u1 s  E+ d
} </FONT></P>; f! O  ?& @9 m) i7 z. e
<P><FONT color=#ff0000>函数名: installuserfont </FONT>; _" T1 f0 P9 q! @  Y( `3 j
功 能: 安装未嵌入BGI系统的字体文件(CHR) 8 N1 R/ z* V/ k5 B& r
用 法: int far installuserfont(char far *name); + m. w. p" E1 s& e+ m
程序例: </P>
9 k2 j( W4 h# M. t9 k<P><FONT color=#0000ff>#include <GRAPHICS.H>& S# c' B+ J: F- F
#include <STDLIB.H>
/ p) C# e' U5 b) _7 q#include <STDIO.H>
/ p: \, u& l  \5 a' A" D  g; x#include <CONIO.H></FONT></P>- N+ F; l4 C' U# N
<P><FONT color=#0000ff>/* function prototype */ ! V0 T( X7 K. h. J
void checkerrors(void); </FONT></P>* m5 b) C) P0 g3 a1 t; }9 k
<P><FONT color=#0000ff>int main(void) % P8 ~0 C) v6 {1 ?# p% d
{
8 Q, c$ s; }5 W' N* _/* request auto detection */
7 b5 P5 T, _$ B0 h2 `- Rint gdriver = DETECT, gmode; $ }% i7 M% V0 I6 I  g! q& b! G
int userfont; % c+ @- T3 g9 l' F' \3 L+ Q* O
int midx, midy; </FONT></P>  X: s1 N+ r. D) B; |) w5 `
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" }& j4 x4 f6 Ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* z1 B: A: J. i<P><FONT color=#0000ff>midx = getmaxx() / 2;
( C* z( Z1 S) Smidy = getmaxy() / 2; </FONT></P>" a" p) i) S. a1 ~" _
<P><FONT color=#0000ff>/* check for any initialization errors */ - N! K' o1 B) n5 W6 r6 T- h
checkerrors(); </FONT></P>
" I( R" Z' C: E4 e. ^5 F8 J( T<P><FONT color=#0000ff>/* install a user defined font file */
. P& Q; \+ W0 @; k4 Q1 luserfont = installuserfont("USER.CHR"); </FONT></P>
8 p, m& K9 x& f1 c8 }6 K: o+ t- ~<P><FONT color=#0000ff>/* check for any installation errors */ ( h9 _* N5 N  @8 d7 \
checkerrors(); </FONT></P>  S6 A$ N/ I9 `& x# u2 g
<P><FONT color=#0000ff>/* select the user font */ + _7 G; T6 j- O8 N& B* e
settextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
+ t( `' \! H) @+ I+ C! t<P><FONT color=#0000ff>/* output some text */
( }+ W8 m8 `' B* {; h/ k0 Eouttextxy(midx, midy, "Testing!"); </FONT></P>
" Z6 W7 H9 {5 x<P><FONT color=#0000ff>/* clean up */
# Z' Q) C* D" V; \getch();
: |; Q. ^+ g7 Tclosegraph();
8 \. |. A+ l* p, m. F% g3 Z* Ureturn 0;
5 d) v; e, A! m% {} </FONT></P>
6 h8 e0 {' L4 z+ i<P><FONT color=#0000ff>/* check for and report any graphics errors */
  m  C4 h# s( M9 ]( g, R+ Avoid checkerrors(void)
: ?0 {. F2 j  s& a# ]& N{
  ]; H$ `! U; V) ?2 V! |0 jint errorcode; </FONT></P>
3 O- p( R* _8 ]" v9 u<P><FONT color=#0000ff>/* read result of last graphics operation */
( f( p! g: t1 c4 T# P* kerrorcode = graphresult();
" k- \: h/ H  V, M' @4 vif (errorcode != grOk)
) P3 S: G) [3 L{ , m4 w2 V9 m/ M" H2 S
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 L5 W* |8 q- J4 e9 c  x. Pprintf("Press any key to halt:"); 3 ~0 g8 l! C; u. X" m
getch();
8 e" n% t8 Q  Y3 eexit(1); - t3 H/ Q. b5 s7 ^
}
( H5 ~; U% [' K6 Z" t} </FONT>" `% ^+ R% o& J# s
/ Q' L9 K  i/ J

8 U' l# ~: f: [: u1 E9 M( A3 i0 F</P>& o  g# `7 b, D7 N
<P><FONT color=#ff0000>函数名: int86 </FONT>, D' X6 m7 n  i
功 能: 通用8086软中断接口
0 B3 V. p/ H$ s2 o; i0 `用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); . `, C$ v) s# s6 Q1 n* x$ r% A7 V- z
程序例: </P>
" Z- k$ B& C+ b9 a# P<P><FONT color=#0000ff>#include <STDIO.H>
- e; K. r4 B, M3 s8 V/ V#include <CONIO.H>
3 y$ h- Q6 Y2 C" `; c#include <DOS.H></FONT></P>
7 ^6 J- c& h) E- [6 N0 S& s<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
; d9 [" T: n( z  g<P><FONT color=#0000ff>void movetoxy(int x, int y)
' ]/ M& A! c& c3 `7 g# h  G{ : A" v2 j3 a9 A5 [& Y5 ^- J
union REGS regs; </FONT></P>
: K" b1 S8 P8 Y<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
: [! g7 l/ `9 v# x; D' b: uregs.h.dh = y; 7 @  k8 L3 \' a. v
regs.h.dl = x;
; i1 H4 t- {: F$ A& Hregs.h.bh = 0; /* video page 0 */
9 G( P! F" d  M0 q& ^. u+ M) hint86(VIDEO, &reg;s, &reg;s);
3 A6 M+ I8 @1 m0 p/ G. N" e1 A} </FONT></P>
, G' d  h) Z6 C& Y, y! F  r2 `" H<P><FONT color=#0000ff>int main(void)
5 Y; r7 _; k5 x' B- N( ~$ K{
. G5 R0 B/ l# l0 X  k6 jclrscr(); & ]0 {( {. W8 T. x, a
movetoxy(35, 10); 2 h  e* J+ O* m% M) b6 c/ Y3 m  \
printf("Hello\n"); & B! h5 V* [7 U- T# \+ `
return 0;
/ U5 Y! U% M" l7 {, _% Y} </FONT>; r' X& j8 S% K0 [; B6 Q

4 r3 K+ r0 c" ^3 k; P$ X</P>5 T0 K$ b6 {7 ]5 S; t5 a$ `
<P><FONT color=#ff0000>函数名: int86x </FONT>
* @6 V, M$ W: t3 x* W$ e4 y& W功 能: 通用8086软中断接口 : ?4 H: m9 E; @% R4 _) l8 m
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, 3 m* P* H5 x+ ]; d' m: e* L2 d
struct SREGS *segregs); / A: j& A  n# C8 c
程序例: </P>
6 ^8 j6 ~0 Q6 ]. |<P><FONT color=#0000ff>#include <DOS.H>
7 e2 Y. w" h+ k( F3 B, O' f: n#include <PROCESS.H>
/ u6 w6 v" M5 M- w+ Q; [2 S3 D#include <STDIO.H></FONT></P>+ I  V- A0 ^$ t1 o, `
<P><FONT color=#0000ff>int main(void)
6 x$ {) }) W( p. |" L) Z7 i# Q& h{ 8 N7 u8 {, E9 j# s& V7 B
char filename[80];
/ w/ p1 a' Z7 n; H. D1 v- |union REGS inregs, outregs;
& i% [+ U2 O: H: u2 R- D7 mstruct SREGS segregs; </FONT></P>
" J4 _5 Q: E( F9 D8 [5 L% |0 E0 O- Q<P><FONT color=#0000ff>printf("Enter filename: ");
1 b/ e: N5 F) N; H. I+ \1 Z; hgets(filename); 1 h& [! a4 ?. N) y1 ^% I
inregs.h.ah = 0x43;
, L( ^( e( f) G4 t; Pinregs.h.al = 0x21; / k  j8 Z7 B! }- V) r
inregs.x.dx = FP_OFF(filename); 5 n. V: M' g: {" }  _% K  |/ W4 _
segregs.ds = FP_SEG(filename);
. v+ }+ O5 N# N- dint86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs); ) C+ V6 r  F) V2 G
printf("File attribute: %X\n", outregs.x.cx); " y* @  M2 \, T0 c: A, t% b
return 0;
  ~& L2 C  w; \, y} - x7 S. d1 z3 G
+ T. f% I& B3 M, N: B
</FONT>
/ B( a" D7 |0 g; n</P>, E1 v5 o$ K$ ^6 t7 V
<P><FONT color=#ff0000>函数名: intdos </FONT>
9 I' Y/ d$ F) t. m功 能: 通用DOS接口
# \; ]9 ^7 r- e3 N  `用 法: int intdos(union REGS *inregs, union REGS *outregs); ; k+ ]& ~% a* T3 t8 V
程序例: </P>
- w7 Q: V( I9 r: Q<P><FONT color=#0000ff>#include <STDIO.H>
+ l0 J1 c, d5 H" f7 O3 |. h#include <DOS.H></FONT></P>
& Z6 m" T9 n2 m0 Y, A0 j3 e<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 7 K! `+ W2 V  W9 O
int delete_file(char near *filename) 9 x7 F& I. b5 p2 h
{ ' o0 V( e! A2 I# [/ ]6 ^7 |
union REGS regs; ( c3 |( {; l* x: S2 l
int ret; ) j/ _5 ?7 a* w& `
regs.h.ah = 0x41; /* delete file */
% c" |" ?  ^! w4 T3 fregs.x.dx = (unsigned) filename;
8 }$ _% j- ~4 u+ R9 m  ^ret = intdos(&reg;s, &reg;s); </FONT></P>
0 b: y7 W6 i: c) G<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
+ I+ R4 X; k: J. ?( Lreturn(regs.x.cflag ? ret : 0);
/ y: k; k6 R/ u* @, D4 B- f5 X: Q} </FONT></P>7 d: I8 y) ?5 p6 s3 Y2 K
<P><FONT color=#0000ff>int main(void) + M7 E8 ?) {% H: t: o9 T, T; s
{ : @. n/ y9 d4 B) H! E2 y2 V
int err; 1 U/ |# N& `  d+ q/ G( ]( G3 v# k' ]
err = delete_file("NOTEXIST.$$$");
% q( O# e; g" i; Zif (!err) * }6 W: @* F. m* Y6 f! I
printf("Able to delete NOTEXIST.$$$\n");
# b  w1 K6 C9 W8 yelse
. f' {3 r! w! b8 v# X* e9 wprintf("Not Able to delete NOTEXIST.$$$\n"); : {; W: l2 }; g) `
return 0;
, u8 \' o5 V  d}
7 r. c: B) l, _8 K7 O9 b
  C3 ], @1 s$ E4 F: m% X</FONT>
, s" W) S, ]6 z( u" L. v</P>& R( h1 G" J& w; W0 U9 O9 Y
<P><FONT color=#ff0000>函数名: intdosx </FONT>  H0 _. }4 n, e& C
功 能: 通用DOS中断接口 - w: q3 {, g0 O" F9 x
用 法: int intdosx(union REGS *inregs, union REGS *outregs, - X! H. F* p) q+ L/ R7 e
struct SREGS *segregs);
6 g4 w$ a9 H" ?. c程序例: </P>5 N- Z: y1 v9 ?& R$ @8 e
<P><FONT color=#0000ff>#include <STDIO.H>
8 m% g0 k! v2 ?' q6 H* S#include <DOS.H></FONT></P>1 D1 p9 ~5 m1 O$ m) ?
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
1 O* Z- h( v$ kint delete_file(char far *filename) # z' C4 i$ Z- e# A! S3 ^
{
. d) G# T: C$ l0 d/ U; lunion REGS regs; struct SREGS sregs;
0 p$ e, X2 ~. q3 M* F/ J- Iint ret; & ^7 w% g. p' \" B
regs.h.ah = 0x41; /* delete file */
, p/ U( Q3 p- @$ k" o1 u0 d/ M7 lregs.x.dx = FP_OFF(filename); 9 X9 x* H% T# U8 X
sregs.ds = FP_SEG(filename);
3 P' d& ?9 }& b3 P& {( \( P) q( aret = intdosx(&reg;s, &reg;s, &amp;sregs); </FONT></P>" h# o5 |# ?; ?: [: A3 `( q' M
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
6 _% i; z* c/ |6 n" ?1 ^, Dreturn(regs.x.cflag ? ret : 0);
4 s; g  X$ _- u: K& `+ S} </FONT></P>
0 y; Q% C9 H+ W3 i! g6 Y- _  c<P><FONT color=#0000ff>int main(void)
& _8 k9 y8 x2 i# h+ r8 ]; x7 t# [{
& D/ Z1 {8 B2 `% J7 x2 i  Aint err;
. y! m0 r' u: Eerr = delete_file("NOTEXIST.$$$"); # I5 }; Y! n- }! Z: ^0 F
if (!err) 4 g( a+ H* }' I" A
printf("Able to delete NOTEXIST.$$$\n"); 4 N( r3 f2 M0 ?; S; f. T
else 1 n/ Q) Z- `( v2 C5 ?- q: G
printf("Not Able to delete NOTEXIST.$$$\n");
0 ]( E" V$ I) `# y( B4 y3 Preturn 0;
8 v- c1 U2 D% ]! ]7 O" A, |}
- c: e+ G2 h. C, Y</FONT>' g: w0 _6 R1 I, {* k
</P>0 h' O* F8 n( r* ]% G" n! V
<P><FONT color=#ff0000>函数名: intr </FONT>
0 C* K; M/ s: _, G0 [功 能: 改变软中断接口
8 t  `" [5 U/ O4 D- p用 法: void intr(int intr_num, struct REGPACK *preg);
0 a- p, ]( u* `8 F4 n  a* A5 w% B程序例: </P>
6 I3 d+ ~6 ], [# o$ A5 m% O<P><FONT color=#0000ff>#include <STDIO.H>9 E$ n* X: a* {6 a  F
#include <STRING.H>
' V1 y* e) s! I( \, K+ u#include <DIR.H>
+ U& Y! {- Z5 i. @; |3 `, U/ Y#include <DOS.H></FONT></P>" Y( M2 Z& C" a
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
- y) s% T9 E! B  e% o& H. B<P><FONT color=#0000ff>int main(void)
; i, c+ v' @: T! @) ^{
6 k! s4 n" i) ~! W* ~2 w- v7 b6 Qchar directory[80]; ! I  ?! d" S% l% [3 t
struct REGPACK reg; </FONT></P>
+ P, B$ l0 N) i! F  W4 Z5 \$ `' Q  {7 j9 V<P><FONT color=#0000ff>printf("Enter directory to change t ");
8 ^4 Q7 }  [. Jgets(directory);
& S) o$ L! D( q! N. o8 nreg.r_ax = 0x3B &lt;&lt; 8; /* shift 3Bh into AH */ , z1 ]  p( V5 i+ n( S
reg.r_dx = FP_OFF(directory);
( x) X3 ~# i/ wreg.r_ds = FP_SEG(directory); - Z7 T' t& g# l/ k0 N
intr(0x21, &reg;);
1 g! |+ H; E' ~# B& nif (reg.r_flags &amp; CF)   {. M2 C! U8 V$ x
printf("Directory change failed\n");
$ v8 \( D( t/ I4 R5 ygetcwd(directory, 80);
  K1 ]  Q$ c* W( c/ Hprintf("The current directory is: %s\n", directory);
1 i" I4 K! T* F0 l' qreturn 0;
/ M" Y# Q  Z6 p; K9 B}
. z5 j3 z- \0 _/ @</FONT>
; ~6 o! n( @& A</P>
  t- _1 _4 G& \5 e: J9 {<P><FONT color=#ff0000>函数名: ioctl </FONT>+ n1 ~, C" c* T# z
功 能: 控制I/O设备 6 ~; w. }, {" r( Y
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); ( `. j3 v# q7 C+ V# |1 M
程序例: </P>6 }- @8 ~) G+ H* N% P
<P><FONT color=#0000ff>#include <STDIO.H>. P' i) b7 J  x
#include <DIR.H>5 w. L9 n& E2 w/ u: @, I$ ~
#include <IO.H></FONT></P>
/ N) D; x% J( L<P><FONT color=#0000ff>int main(void)
: X' m5 H$ N& k* y{ 8 F6 T9 j" D* v5 P
int stat; </FONT></P>) O5 K5 ]/ o" ?& f: A
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
3 ?) |$ x2 b& g8 _8 D/ U  jstat = ioctl(0, 8, 0, 0);
+ F) F  ^1 a; \- i" sif (!stat) 1 B- ^* g0 {8 G* c# R4 @
printf("Drive %c is removable.\n", getdisk() + 'A');
6 p0 T) p7 E% D+ ^else
& D/ U) ~! A; Q: z" O/ Lprintf("Drive %c is not removable.\n", getdisk() + 'A'); 0 b6 J8 O2 u; }: x# H
return 0;
& `; e! ?5 }; i1 Z  a}
) d9 ?5 W! Y9 m/ C. ^2 X7 M
5 ?; `6 x/ [1 o: j3 }2 v</FONT>/ g0 `/ _7 |+ e% n9 f& z- b4 \
</P>
3 S0 `" v6 C5 Z<P><FONT color=#ff0000>函数名: isatty </FONT>* h+ o4 ^9 F  X, P: I
功 能: 检查设备类型 " C& O$ Y0 Q. R& x
用 法: int isatty(int handle); ! `! \3 |* q/ F8 H
程序例: </P>0 M/ l. X2 x+ p+ J9 K! a
<P><FONT color=#0000ff>#include <STDIO.H>6 w$ p' T: F, p4 E% `" u
#include <IO.H></FONT></P>' [% d& i- R+ b  [9 P. I$ o2 h% v
<P><FONT color=#0000ff>int main(void) 4 n/ C2 \( {/ z  Y+ r
{ $ z1 [5 r! D+ U! f$ _, `
int handle; </FONT></P>9 l( T4 \" m! [1 S/ ^9 i  x5 @  V
<P><FONT color=#0000ff>handle = fileno(stdprn);   I% W" T* Q' B7 S2 X6 {
if (isatty(handle)) 6 k% f& q  E9 b  n# T
printf("Handle %d is a device type\n", handle); ' T/ V; w$ m7 Q" `: n" X
else
( {# n' k) y1 Pprintf("Handle %d isn't a device type\n", handle); & W5 @4 K7 {( f7 b2 u4 a% h
return 0; + u) e$ [: j$ |& ~
}
1 O1 F5 a; q! ?3 C$ b6 y$ F2 j. O$ V; P1 }! n
</FONT>
4 z  @' v1 f1 j* T. G$ g/ i8 K" a/ @; L  F</P>' V" `( ]" S9 ]6 C8 x/ p
<P><FONT color=#ff0000>函数名: itoa </FONT>
, K1 {7 S3 P1 o1 x- f! q功 能: 把一整数转换为字符串 6 a. z8 }8 X' `; Y
用 法: char *itoa(int value, char *string, int radix);
5 D  H: W( G% f: t/ K' @程序例: </P>
' G( Q1 d+ e" {) I+ ^! q  R<P><FONT color=#0000ff>#include <STDLIB.H>9 z% M# a# y+ O( n6 m
#include <STDIO.H></FONT></P>
1 _; K4 U( L1 l<P><FONT color=#0000ff>int main(void) % H: k# p9 K: E! s
{
+ M, F0 V- Q% @3 l9 h5 dint number = 12345;
) `5 ~- d( L* K5 F* G9 t; Pchar string[25]; </FONT></P>
& E# d1 \( _+ Z<P><FONT color=#0000ff>itoa(number, string, 10); & p8 V, o6 K, I1 T1 F. T
printf("integer = %d string = %s\n", number, string);
. b# Z% Y; o) ereturn 0; : C# P: ]' g# h# Y' ~2 n) b% Y
} </FONT><FONT color=#0000ff>
+ x6 q, B1 P' v' H, F</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-7-21 02:52 , Processed in 0.568820 second(s), 52 queries .

回顶部