QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2356|回复: 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>
/ L: A$ M5 M0 {( W< align=left><FONT color=#ff0000>函数名: imagesize</FONT> . J+ c- o2 L# O5 x  `. ^7 j
功 能: 返回保存位图像所需的字节数
( [% b! @2 ~3 C5 v' s* P$ e9 C用 法: unsigned far imagesize(int left, int top, int right, int bottom); / J# M( @8 Y4 h
程序例: </P>
3 m% @2 A$ D3 Y<><FONT color=#0000ff>#include <GRAPHICS.H>
, L8 k7 L2 G% X2 x  `8 N# E# r#include <STDLIB.H>
+ v& B* s" \6 ^  {6 ^#include <STDIO.H>
0 d7 r, J1 j- S- J; g1 A#include <CONIO.H></FONT></P>. h( `$ c3 v) p
<><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
$ l+ R1 H" ]6 n3 K. ]7 M, J<><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>5 P( o+ J( ]. N
<><FONT color=#0000ff>int main(void) 7 }2 t! C: c* _
{
; M$ H; o( L  @7 W/* request autodetection */
' R/ _( R5 ~; c9 m" k8 bint gdriver = DETECT, gmode, errorcode; + y5 M( C2 D, T) o* K; h+ X" D/ M
void *arrow; + Q( k# `* r3 L' g# M
int x, y, maxx;
7 {/ c7 j$ h+ S: @: ~5 J3 }unsigned int size; </FONT></P>
1 g$ X0 o' x4 O0 u0 B9 Z<><FONT color=#0000ff>/* initialize graphics and local variables */ % x' [- T! T; J% V: J" q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 y# |* i5 R6 W8 Y( l7 r$ O4 h
<><FONT color=#0000ff>/* read result of initialization */
8 i0 G* h( ]3 I+ berrorcode = graphresult();   V4 ]& O8 M* ~
if (errorcode != grOk) /* an error occurred */
# \$ M/ K! E+ p. }. ~{ 8 A9 |8 i5 i# Y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / ^. u/ ~4 p) F( D
printf("ress any key to halt:");
! l, T3 V- a3 H; t, J9 x+ p1 fgetch(); * T! ~- g: ~, R* m+ \7 ^2 {
exit(1); /* terminate with an error code */
: }% X0 A; x+ f, }& c" X} </FONT></P>9 L" L' v& W, B2 m3 A8 ?0 g# D
<><FONT color=#0000ff>maxx = getmaxx();
+ o( x$ o. k5 }" U3 E* Gx = 0;
$ n# g: }* H( ]- V8 u5 I, c/ r' }y = getmaxy() / 2; </FONT></P>
- S8 a+ O( I8 Y2 k  P, K<><FONT color=#0000ff>/* draw the image to be grabbed */ # z. I* L* Y+ X
draw_arrow(x, y); </FONT></P>
7 E! }; M0 c  ~  I* v9 b/ B+ d<><FONT color=#0000ff>/* calculate the size of the image */ 9 B* O5 j5 T5 q- e# d# A
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>* b7 }/ p, e3 e! C, x# g' \1 e/ r
<><FONT color=#0000ff>/* allocate memory to hold the image */ ' V, V  f* x! q8 f: E
arrow = malloc(size); </FONT></P>7 B& N$ o" l& l7 q" r3 `; I, y0 x
<><FONT color=#0000ff>/* grab the image */ 5 P# Q) m; V7 i0 P" X& k
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>+ W2 Z. Q9 S. K+ v6 @$ y7 l# h
<><FONT color=#0000ff>/* repeat until a key is pressed */ % R& G7 _8 o/ A# ?' f1 I; E
while (!kbhit()) " _' Z( f7 }; _0 x. G4 Q! Q
{ 8 i0 [2 |8 j3 B0 r
/* erase old image */
7 |" N8 `5 I9 d: |, E6 O3 cputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
* q' Q$ ]3 E# D: p<><FONT color=#0000ff>x += ARROW_SIZE; 1 t$ _: G  Q' J9 v2 Y, `' t
if (x &gt;= maxx) 3 i) D5 e0 G  ]* K- p+ ]
x = 0; </FONT></P>
1 |- a" f. N4 ?- C/ B$ O<><FONT color=#0000ff>/* plot new image */
- \2 i6 j6 k% fputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); , D" g& s. E3 c3 n3 h) J5 ^
} </FONT></P>! ]$ d% T0 _3 _' ~
<><FONT color=#0000ff>/* clean up */ 7 E- ?8 [/ d8 o+ j% z' j! o
free(arrow); 8 q' u9 W- S# V; q9 i) Z! g8 C) h
closegraph(); * i/ f/ R$ W! @8 F4 G% P0 ~9 B
return 0; + B" o# M; R0 V" R- j8 w
} </FONT></P>7 u/ \/ {; O* h+ v
<><FONT color=#0000ff>void draw_arrow(int x, int y)
' L! M( \( ]$ o  M2 C% C{
7 k9 @7 i( ~5 Q) ]2 K% J* I/* draw an arrow on the screen */
5 y; N, v! a; V* ]' amoveto(x, y);
2 p4 x% v, n9 l7 T0 g( slinerel(4*ARROW_SIZE, 0); . k8 R* t2 j: H7 |6 A7 H
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); 6 @4 t' N2 D2 I+ {& a" F6 D
linerel(0, 2*ARROW_SIZE); 0 @' I! ?! ~0 w5 a- n" T" `+ ]
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 3 `$ R8 j9 F! p* d3 g" X
} 6 q# M$ q3 z9 Q

' \+ U2 B. N" U& w# `3 ]/ ]0 Y3 o! e0 h, q: w. t3 I
</FONT></P>) T( w  d/ `# ^# j( r/ U
<><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>1 _: W7 s( X2 \) T2 z4 |
<FONT color=#000000>功 能: 初始化图形系统 * ?( Q, J% e8 g; m2 D
用 法: void far initgraph(int far *graphdriver, int far *graphmode, & T2 ~: J2 [4 _  l
char far *pathtodriver);
7 M) ]! r& l. S程序例: </FONT></FONT></P>) j8 y( b4 D! w" |4 \9 h
<><FONT color=#0000ff>#include <GRAPHICS.H>+ Z2 ^8 X2 ~: `) y3 [
#include <STDLIB.H># H1 ^. j0 k" u
#include <STDIO.H>
' c: r. W# A6 ^; y#include <CONIO.H></FONT></P>
, i0 {3 j7 u( ^4 e3 V<><FONT color=#0000ff>int main(void)
# [! n5 b0 v8 f- g" x{
8 r# p, B( I" d8 I+ o" X/* request auto detection */ $ I3 x. r) R5 r' I# \% w' |" E8 t
int gdriver = DETECT, gmode, errorcode; </FONT></P>: Q* M; K% A. Z' X
<><FONT color=#0000ff>/* initialize graphics mode */ : G' D5 ^" y. ~- ~% u
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
& z4 J* R0 s7 k$ {<><FONT color=#0000ff>/* read result of initialization */
  ]8 E+ b# o' C% |8 J* R8 }. xerrorcode = graphresult(); </FONT></P>: x5 h* [8 {; d$ G
<><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
& i6 h5 i% U/ p0 K9 q{ 5 {5 X$ G5 N& d9 F! H  \- p( z
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + W9 D9 R8 ~: ~) d& K" B9 T/ _7 \" K
printf("ress any key to halt:");
% ^+ g" b7 v( _& G$ [getch();
+ |' x# U5 T) g3 n" }( V: ^& _exit(1); /* return with error code */
5 q$ U" i" Z. W1 c* x. U} </FONT></P>
2 N7 D0 M5 U9 S( L<><FONT color=#0000ff>/* draw a line */
# G3 u, B& Q" E( `! e1 B7 t0 Bline(0, 0, getmaxx(), getmaxy()); </FONT></P>  t& `& t7 V: {, @
<><FONT color=#0000ff>/* clean up */ 7 _/ }( u" s4 K/ P4 K) b3 M) s! U
getch(); : c# E/ q, Y" c* x% ]
closegraph(); " F4 h* N2 C9 J! U3 Z6 V& e+ j
return 0;
: h& I$ X$ t( N0 S' _} </FONT>8 `. P8 j* w8 j/ |) J8 A

5 U" _2 F/ e8 P& f  c) y</P>
+ {% ~( {7 k9 u8 u" P, S3 i<><FONT color=#ff0000>函数名: inport </FONT>& I0 f5 j: |' F  t8 N3 V: q5 h* I
功 能: 从硬件端口中输入
( q# h! t' v8 f$ H) L( k用 法: int inp(int protid);
# d9 x% a4 L. p. S" J9 K8 {& [! p程序例: </P>: r' Z# M- n* Q$ M$ J1 {* L5 D
<><FONT color=#0000ff>#include <STDIO.H>2 A3 X1 J7 T3 Z' }
#include <DOS.H></FONT></P>
' {1 s7 n- ^: e: L- M2 Y<P><FONT color=#0000ff>int main(void)
* @& g, o2 v  v& P) P% \{
2 A! |; I; G* w+ h. Oint result;
3 M/ Z, I( v! B. R4 E4 ]int port = 0; /* serial port 0 */ </FONT></P>
/ D( ^$ P6 |, M: k0 \% G. R<P><FONT color=#0000ff>result = inport(port); % [; Y! o: Z- C2 X& Y3 w
printf("Word read from port %d = 0x%X\n", port, result);
, `" F, a# ~4 p) Q& K6 Vreturn 0;
5 j8 c' \" B! c* L$ v$ f3 d} 9 {9 h, u7 R9 d: j( A$ S
4 s2 D% s" O* _3 ^3 s& ~4 D) z8 M! ?
</FONT></P>
+ ]4 v3 \- y" l4 k% y0 H1 j6 C<P><FONT color=#ff0000>函数名: insline </FONT>0 k8 d; M% m/ o( W
功 能: 在文本窗口中插入一个空行
0 e4 f. [3 ^- Z. E( C  g% z5 D用 法: void insline(void);
* n/ X- F% ?0 C* `7 \" i" T& q程序例: </P>
3 l4 I8 k6 L4 t$ K  _& U  F: K<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
% E$ \# k: S/ m4 x% z1 G5 U, V) ]<P><FONT color=#0000ff>int main(void) * U7 _. z4 B& r0 L* o/ ^' J
{
' u& i% a, {# H" k/ [5 E1 Jclrscr();
9 f* v* {# X$ F' g3 R. k9 R# `cprintf("INSLINE inserts an empty line in the text window\r\n"); : q6 Z- Z2 |. S% t0 l8 s
cprintf("at the cursor position using the current text\r\n"); # [- a% R% ]5 f5 `" ~8 l
cprintf("background color. All lines below the empty one\r\n"); : D% l) l( o2 j" L4 u% n
cprintf("move down one line and the bottom line scrolls\r\n");
. \% k; P, U2 Z/ X0 A, ucprintf("off the bottom of the window.\r\n"); 3 k5 K" g0 e. [  P+ Y/ p+ a1 K) F
cprintf("\r\nPress any key to continue:"); ( y1 X. a: }; }  ?1 M3 L
gotoxy(1, 3); - s1 Y* g6 s' B
getch(); 6 b( R! n3 ^$ z' J
insline(); 2 y3 A  U/ k5 u; g
getch(); : M- w4 A( k4 g+ d" t/ e  Q0 ?
return 0;
8 t' Z. v. \5 u7 q, C7 w( t7 |}
# x$ s4 V4 \- s1 C</FONT>
* ]' _1 T) g$ l. o& r" w2 Y
  N; S* J- h" K</P>
, y* c% K5 B) ~" Q<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
  I: i7 Q: X" L; t, n功 能: 安装设备驱动程序到BGI设备驱动程序表中
: ]' y, E" j) ]( T& b# `用 法: int far installuserdriver(char far *name, int (*detect)(void));
' }% {  D' H, j1 B5 t程序例: </P>% Z; x  m: Y/ q% y
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ J+ n+ H9 d! |( R  h+ g% {
#include <STDLIB.H>
& F$ X6 d' C, Y; b, Z2 `9 F) f#include <STDIO.H>) L5 s* d3 {& A8 a. W0 w
#include <CONIO.H></FONT></P>
/ ~& R! a( S5 k, f; Y5 t<P><FONT color=#0000ff>/* function prototypes */ 9 f, ~% C- L# [% b9 G7 j
int huge detectEGA(void);
2 V' w5 Y, B; \* d8 wvoid checkerrors(void); </FONT></P>
" a; k7 f; d: H1 B! K, t" S<P><FONT color=#0000ff>int main(void)
: o0 k' m: {# a, X* m, d9 J/ D{
; ?9 t- ]* v8 ~! I: @int gdriver, gmode; </FONT></P>" o' l# G' o/ Z6 S4 @" T: F# l
<P><FONT color=#0000ff>/* install a user written device driver */ # A6 V) f3 H* [
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
7 `8 X' _' M, g8 Y3 k& Q<P><FONT color=#0000ff>/* must force use of detection routine */ 9 p& i0 f) E/ u5 c
gdriver = DETECT; </FONT></P>3 r& J8 v: _! T+ y, G) p, h
<P><FONT color=#0000ff>/* check for any installation errors */ ) ^; h* ?9 R( r8 M% c
checkerrors(); </FONT></P>) w2 Q! r' h8 b  u9 G- W9 T* w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, K# u1 d* M8 pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% B: x0 T! x" W3 E, N! j2 l<P><FONT color=#0000ff>/* check for any initialization errors */
5 P4 F! O* t5 f% Ccheckerrors(); </FONT></P>$ ~% ~7 }' u7 M( Q# K0 ^. S! w: U$ r7 X
<P><FONT color=#0000ff>/* draw a line */
, X, d* [$ ]* ~/ W8 A+ y3 Qline(0, 0, getmaxx(), getmaxy()); </FONT></P># c4 y' Y+ a5 x+ S4 z8 ~
<P><FONT color=#0000ff>/* clean up */ ! B1 |/ s( _# w: m- A7 |
getch(); 0 O5 e& l" B1 @; S# z5 T
closegraph();
2 I6 n) G! s6 O, d+ D' g, C: Areturn 0; . X' M1 i3 e# u6 N
} </FONT></P>
/ a8 p" m0 _' r- m0 F& b9 `7 g<P><FONT color=#0000ff>/* detects EGA or VGA cards */
6 H1 |$ A1 i6 Y# Y% Mint huge detectEGA(void)
$ f% f5 d7 W' Z8 v{ 0 v# `) O0 _3 x+ y% [
int driver, mode, sugmode = 0; </FONT></P>
) x; m# b; k- @& a5 @( ]$ H: ?<P><FONT color=#0000ff>detectgraph(&amp;driver, &amp;mode);
  g; ?) w; P* P" X  nif ((driver == EGA) || (driver == VGA)) $ b- I+ b1 v' o2 p5 ]
/* return suggested video mode number */
' c" [$ e8 }- Lreturn sugmode; 8 D' b+ D3 y, c& [' T3 Y2 t7 ~  l
else 5 T0 @) I2 K& p2 ?3 B. o
/* return an error code */ " G' P) u7 h# b" z5 f( P6 W2 [
return grError;
; A# `0 n: j  U' S: q5 Q} </FONT></P>
- U1 [2 ]8 U: I! O+ E) R5 {9 ?* ^<P><FONT color=#0000ff>/* check for and report any graphics errors */
0 r, @) [+ E# t+ n. ^void checkerrors(void) 7 A# D' z7 D6 ?7 R# Q0 X& A
{ 2 S5 b. a3 z' c
int errorcode; </FONT></P>
; j! M3 Z* K( o( a, l<P><FONT color=#0000ff>/* read result of last graphics operation */
" R! P  f- u8 q+ e- e9 werrorcode = graphresult();
/ p' U3 C; O. ?if (errorcode != grOk) ! {. s* Q7 x/ l8 [- o2 J
{ 6 P/ s' i6 G. u/ u3 N
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ |$ f9 ~; Z, k: i3 n3 N! }printf("Press any key to halt:"); " w& s9 L9 C3 w3 ]* _. F
getch(); 6 T* e" M3 F* g* F
exit(1);
% ?( C7 y! m" n: K. g0 @9 x; A7 h} " t5 {: g5 |/ l2 q3 x. C; N
} </FONT></P>
# d$ t1 x" B% O7 s/ Q8 E. ~* f3 m<P><FONT color=#ff0000>函数名: installuserfont </FONT>6 X6 q8 Z, H) c' q& o
功 能: 安装未嵌入BGI系统的字体文件(CHR) 6 W6 Y* R, L2 ^
用 法: int far installuserfont(char far *name); + L& E, E( q5 `1 f  Q' [- F
程序例: </P>
) L9 ~3 A7 Q# p. G1 R<P><FONT color=#0000ff>#include <GRAPHICS.H>: a6 ]) h7 [: q( k( D
#include <STDLIB.H>
7 j# _) \$ p0 T( q; f#include <STDIO.H>2 e9 ^# A( ^) V- A( [
#include <CONIO.H></FONT></P>& ?* B. J. Y/ b
<P><FONT color=#0000ff>/* function prototype */ ! y; G2 a  G+ D4 Z
void checkerrors(void); </FONT></P>9 u2 S* B: n/ z! U. v! W5 M' E
<P><FONT color=#0000ff>int main(void) # U9 G6 }! R) l# w' _$ m+ W
{
% u- p( w9 |4 P# j/* request auto detection */
/ `) ~4 G( p+ M0 z- ]int gdriver = DETECT, gmode;
$ X% T6 R9 N6 h3 Z- q% J2 e- nint userfont; + w; R  f7 r, A7 u
int midx, midy; </FONT></P>7 \) r: i9 r- U, H6 W
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# k5 ]0 S/ w/ yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) i4 J" C! K/ `8 m, q<P><FONT color=#0000ff>midx = getmaxx() / 2;
$ d7 S$ |' e: m" p, Y" H2 _midy = getmaxy() / 2; </FONT></P>
, H: y9 U8 o7 E6 C<P><FONT color=#0000ff>/* check for any initialization errors */ - D5 d' ]4 g$ L) Q+ }3 }
checkerrors(); </FONT></P>
* b1 {8 K, t! H8 }8 h/ G1 B<P><FONT color=#0000ff>/* install a user defined font file */
8 r0 s. _' t- T' yuserfont = installuserfont("USER.CHR"); </FONT></P>
% J4 d8 v- C4 g<P><FONT color=#0000ff>/* check for any installation errors */   C1 u& V% C, Y! V6 N* p
checkerrors(); </FONT></P>2 g! @! X& n3 @$ P( e: s( F) ]8 K
<P><FONT color=#0000ff>/* select the user font */
! e, G, e+ s" N, ^( M8 Vsettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>" p; `9 g% M5 i) C4 a
<P><FONT color=#0000ff>/* output some text */ - P6 j5 Q' q' q0 I+ I! o) d
outtextxy(midx, midy, "Testing!"); </FONT></P>
! `8 J" F  e  o9 T<P><FONT color=#0000ff>/* clean up */ + S$ H$ z- f$ l! z+ V
getch(); + F" t' E& G6 T: \; ~6 M% ^
closegraph(); / N: f6 ?" l5 r6 Q) R7 I
return 0;
" \' b, L/ j" ~0 ^} </FONT></P>& [6 N2 }5 g2 ]6 `* {/ q8 v
<P><FONT color=#0000ff>/* check for and report any graphics errors */ 8 u7 v5 w  u+ Z& i1 L4 f
void checkerrors(void) 1 g; [/ b0 k: Z4 @3 C
{ % K0 b! ]' l3 r& s- t
int errorcode; </FONT></P>
/ G5 [7 D% ~: X. D, v/ v. R<P><FONT color=#0000ff>/* read result of last graphics operation */ - K+ j& W0 ?  c* f
errorcode = graphresult(); 5 T# d% b& \( V. M
if (errorcode != grOk)
6 ?: ]% k  C: e# a  d{
7 K- o/ e' O; o5 i! jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ O8 o$ }: e  c2 ?
printf("Press any key to halt:");
& {7 X8 ?2 j; t, _' P( o2 vgetch();
, E" |/ b; w. C2 p6 N, A9 w- Zexit(1);
6 M8 W5 B( v; N+ O: W  ^} ( m: z! z% N% X( P! `5 w
} </FONT>
, u) F7 p6 J* o1 }( y% |7 D3 z" X& v* R+ T# L6 v# E5 b
" m3 g3 x4 q( ~+ t
</P>3 Q2 N8 U3 u# {3 |4 s% p. h
<P><FONT color=#ff0000>函数名: int86 </FONT>
$ T2 ]  e/ l: o+ @功 能: 通用8086软中断接口
: D  g0 h8 R8 i2 U7 ^  @( n3 L用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); / J- k& j" g7 m  ?; f- ]# ^, k) x
程序例: </P>* p7 Y. b* N, u. `4 G" b
<P><FONT color=#0000ff>#include <STDIO.H>" L/ r9 S" R3 H+ x+ `2 A( l! g
#include <CONIO.H>
9 P  a) d+ ~3 Y9 a( b& G#include <DOS.H></FONT></P>
$ A3 g* p! [: u/ L. V# {' j+ }7 |<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
! ?9 @7 r& }6 q. [; ~<P><FONT color=#0000ff>void movetoxy(int x, int y)
3 C3 k( T1 \$ Q  n3 U. R{ $ D$ y3 c" c. s, G6 Q  [: h
union REGS regs; </FONT></P>$ i: u6 D; K, d* w' {5 o
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */ ) ^4 ^7 u, k& ]4 R; @; H2 p: H
regs.h.dh = y; " s8 ^+ G7 E$ n8 }
regs.h.dl = x; + M( u( Y2 T* |  `) ]! o+ z  x8 o
regs.h.bh = 0; /* video page 0 */ & a. p$ [+ M( v+ c% P2 E+ p
int86(VIDEO, &reg;s, &reg;s);
, W# p/ u6 s! y! f  D  M: ], V  L} </FONT></P>
+ i) u$ ?; h$ s3 s( z<P><FONT color=#0000ff>int main(void) 3 K! E$ W: w6 Q" ^# R3 j' V
{ 4 `0 E1 s0 f* b3 W+ ]- W
clrscr();   z( Z: f2 F9 J, g9 e- T
movetoxy(35, 10);   o9 k6 B1 l. z& m, k8 a
printf("Hello\n"); 5 q2 _. J  P5 q2 s9 l
return 0; " T# i8 I9 Z) [2 o- I# _/ d
} </FONT>
, P6 C( M  p  G! N" H2 D
, f8 b/ q, ?& @4 B- b* \9 }! R/ G</P>
  S3 E/ v% J0 [; \2 f! p7 l<P><FONT color=#ff0000>函数名: int86x </FONT>1 w) Y2 _+ |: G5 w1 @4 k4 D
功 能: 通用8086软中断接口 # M1 P* U* h$ w. J/ t8 y
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, & ?- ]+ J. ^" r* F. [( f
struct SREGS *segregs); ' K9 B4 j5 ~4 I5 O6 K% U+ E; P
程序例: </P>6 o7 ]4 @  C1 @3 b  B
<P><FONT color=#0000ff>#include <DOS.H>* j% Z7 k& C7 c+ p" z
#include <PROCESS.H>& B# b7 A& X+ R* y
#include <STDIO.H></FONT></P>, o  l; U3 A: G. [2 {& h5 Q
<P><FONT color=#0000ff>int main(void)
' k9 l* O) X" {6 ^{ * E; P9 y  ]& m; n1 [3 J. ?
char filename[80];
1 ^: i/ S- Q* S& i- s# O8 z- Xunion REGS inregs, outregs;
: J' m# j3 Y3 V& G+ a( ?; o& J. Cstruct SREGS segregs; </FONT></P>
  O7 E2 Z4 d& q<P><FONT color=#0000ff>printf("Enter filename: ");
2 q4 N0 J! j! ^4 }gets(filename);
/ h1 E" k- O0 g% i# t6 _2 cinregs.h.ah = 0x43; - M  Q1 M) G: M
inregs.h.al = 0x21; 9 z+ |9 W; q7 F( ?  n& d' O  y& D
inregs.x.dx = FP_OFF(filename);
+ S& G6 y: O9 T8 G% Nsegregs.ds = FP_SEG(filename); , T. E( A4 M. i- Q
int86x(0x21, &amp;inregs, &amp;outregs, &amp;segregs); / \6 h2 k4 t# Q: D1 }
printf("File attribute: %X\n", outregs.x.cx); 2 J* Y5 X, w4 k
return 0;
3 a2 N8 `' a' K# F8 _+ j} ' z6 U- G# o+ l* n( s' m1 d
) T7 y, t1 d4 v, N/ m
</FONT>
# Y+ ~  @& A1 G</P>
( _2 q7 {" J9 Z! I' C<P><FONT color=#ff0000>函数名: intdos </FONT>
$ w6 W$ Y% x" r功 能: 通用DOS接口 ) b4 \. j3 U7 F/ B5 p
用 法: int intdos(union REGS *inregs, union REGS *outregs); 9 h& F& v6 V6 v0 H
程序例: </P>
* V% T1 L% {1 h: G<P><FONT color=#0000ff>#include <STDIO.H>3 k4 [8 u0 K( ^. ]
#include <DOS.H></FONT></P>
' m% z! |& d& v! ^' y<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ : C, c+ A& _% a
int delete_file(char near *filename)
: ?7 S- \( |7 J{ % H$ u9 f! A3 d. g; ?: {+ ?6 _+ O7 ^
union REGS regs; ; m  w9 _3 c/ t: A! j$ s
int ret; 5 ]( B" ^) [) O+ N; O
regs.h.ah = 0x41; /* delete file */
0 p* E1 @( p0 O6 cregs.x.dx = (unsigned) filename;
: s0 W' I* i; Q( E, Oret = intdos(&reg;s, &reg;s); </FONT></P>/ _6 m# o% V0 U' a2 ^' ~; r& Z
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
2 t) g3 @( ^. b1 B3 Y1 mreturn(regs.x.cflag ? ret : 0);
1 w/ T! D5 \; D; f} </FONT></P>
/ n, |/ y' j  L2 ]/ p: u<P><FONT color=#0000ff>int main(void)
7 ~1 J! k; [% \0 e7 c1 h6 I: `{ & x( o/ K+ Z4 v# ]$ T' h# E: w5 ?
int err; 2 J7 U  ^) e; e& @2 ?( Q! a( o
err = delete_file("NOTEXIST.$$$");
; e: a5 g% E- wif (!err)
8 G2 s; p# [5 R6 e/ Tprintf("Able to delete NOTEXIST.$$$\n");
7 H$ M) E" t& I: D2 z7 Ielse
# w, s6 r* P2 U- b: Q% Iprintf("Not Able to delete NOTEXIST.$$$\n");
, f# V. t1 L$ Oreturn 0; , O& B/ q- E! ~# B
} 8 A  x! o3 A9 k
) |. {3 i8 I7 r9 p; k2 K: S- i
</FONT>7 g0 a- {" [- B
</P>% O& S4 E0 s  G
<P><FONT color=#ff0000>函数名: intdosx </FONT>
) q+ Q! x1 I+ l3 ~5 u9 o功 能: 通用DOS中断接口 9 P8 l8 ?: q- i/ |: C
用 法: int intdosx(union REGS *inregs, union REGS *outregs, 0 P8 |1 ]7 L7 U( ?
struct SREGS *segregs);
6 C) [7 B' I7 }) h程序例: </P>
2 v" d1 {) q8 D# }. L$ H2 p<P><FONT color=#0000ff>#include <STDIO.H>
( \; D( m; Z! G$ F#include <DOS.H></FONT></P>( W5 a) {4 M& V" Y$ g/ [2 y
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
! R0 S' j1 S4 d4 r$ g( O3 Q. }int delete_file(char far *filename) ; V5 Z/ V% T5 t& ?$ I3 q. h9 l1 e1 L
{ . e# w* S& T6 S& O+ o) P
union REGS regs; struct SREGS sregs;
0 v. b- g2 m3 y9 p; J( {3 U8 [int ret;
) R. d4 E: Q; U" iregs.h.ah = 0x41; /* delete file */ 6 W6 @/ z- F& R6 O, P0 b
regs.x.dx = FP_OFF(filename);
2 E( k/ ?- x; b/ B: ?0 osregs.ds = FP_SEG(filename); 7 B9 n% w. N: t3 s: h! |
ret = intdosx(&reg;s, &reg;s, &amp;sregs); </FONT></P>
& |  r! s5 y' @0 |  E<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ 1 V! j( \) I; t# l" l& p& H' l
return(regs.x.cflag ? ret : 0);
& J9 @; `3 c8 z! z} </FONT></P>
) w8 p0 x; f) G, o  D5 T<P><FONT color=#0000ff>int main(void)
1 ~: s# q% ]! W{ 3 I" I) a* g6 [, _0 G# X
int err; - U& a: f5 x2 G9 j4 N& h
err = delete_file("NOTEXIST.$$$"); " _5 c! w5 G) L
if (!err) 5 f9 b9 R) o9 v8 t$ n
printf("Able to delete NOTEXIST.$$$\n");
! z1 L$ N) d* G, t  uelse 1 i" J/ U; i! n! i: h
printf("Not Able to delete NOTEXIST.$$$\n"); % I- Z, K2 h2 F* V
return 0; 8 ?- u1 S/ b) M8 g2 I
}
6 N! X! n% y/ U% W2 ?5 [% M" J</FONT>% p+ y  {/ V0 I: j
</P>
. _9 ~7 S/ T: d- m+ `/ i$ B<P><FONT color=#ff0000>函数名: intr </FONT>
  A4 n! d: J$ N- \& e& e8 ?功 能: 改变软中断接口 9 A! S# M# b' }7 v
用 法: void intr(int intr_num, struct REGPACK *preg);
! c) a- q7 {/ `3 I* y% X* W程序例: </P>, x2 D; P: Z- X- [+ c
<P><FONT color=#0000ff>#include <STDIO.H>$ L! V/ y3 `. L. f. ^" J: c9 k
#include <STRING.H># o/ Y/ `( L* A# A2 \5 K7 E$ y
#include <DIR.H># F# X% z1 \2 w1 e" y& u
#include <DOS.H></FONT></P>8 `/ N( F0 t" j# Q
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>3 B2 G. h+ x3 [* ^7 @
<P><FONT color=#0000ff>int main(void)
, \/ S4 g" ^. E# X$ b3 c2 Z{
# L) q9 A) @0 `3 L6 Wchar directory[80];
; [) ?) H- ~. V" n4 Cstruct REGPACK reg; </FONT></P>
8 {9 \( U- E3 {9 l9 M0 Z- j3 Z<P><FONT color=#0000ff>printf("Enter directory to change t ");
* ]3 i- n/ O8 |( e8 Y8 Ngets(directory); 9 _9 Y8 ?$ k( B; {; ^0 L
reg.r_ax = 0x3B &lt;&lt; 8; /* shift 3Bh into AH */
4 [6 _6 w! l8 ~& Areg.r_dx = FP_OFF(directory);
5 g5 g, U) c9 H! W5 b( R( preg.r_ds = FP_SEG(directory); : r( e, N( l9 D6 a! M) J
intr(0x21, &reg;);
* D$ v1 @$ i& Nif (reg.r_flags &amp; CF)
: ]2 @/ R4 v1 jprintf("Directory change failed\n");
9 g6 t* N1 p! L2 F% Cgetcwd(directory, 80); % \: j5 x& E: ]9 P' x
printf("The current directory is: %s\n", directory);
% l, d  k7 b, D' o8 h: nreturn 0;
0 s6 k& ]% n) ^  S' D}
2 x0 M; U% |1 B! N9 Q4 b5 A4 }</FONT>
! o7 d0 q3 D7 m+ Y</P>. R% |# W$ f, e8 o$ `! u- t( ]7 o
<P><FONT color=#ff0000>函数名: ioctl </FONT>
$ F7 `1 s$ ^# M: o; _$ e  g* Z功 能: 控制I/O设备
6 S) [9 {" H3 O% @. {用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); 2 I* N1 e8 L4 }6 x
程序例: </P>* `) v2 k& P& D: A& S4 _
<P><FONT color=#0000ff>#include <STDIO.H>7 P! L" h- }# j- Z/ P4 y8 _3 ?% \
#include <DIR.H>, ~- N3 Z4 d; c
#include <IO.H></FONT></P>6 U# I6 B) T# M, t# R$ E) h& @
<P><FONT color=#0000ff>int main(void)
2 n) C% J, f0 U( _4 g{ : f! q1 j" O# M) h6 }' ]) m5 V! X
int stat; </FONT></P>0 `8 y2 m$ }7 f  v  }+ z
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ ( f* `/ b/ s5 n8 y" \
stat = ioctl(0, 8, 0, 0);
' m3 g0 t, v. i3 e5 nif (!stat)
$ e# t, }0 L* M8 W" _) aprintf("Drive %c is removable.\n", getdisk() + 'A');
7 K( r/ v# W7 L: m; l1 delse
/ a5 p) \0 j  m5 O+ N3 @( yprintf("Drive %c is not removable.\n", getdisk() + 'A');
6 a/ J7 }) N" B) breturn 0; $ ?  A5 R/ e& K( r
} : _% m/ P  K' J: ^3 K

& ^5 K7 j) h8 i& }! [</FONT>: k3 ]+ S' _8 h  w1 G6 x
</P>
& n) t, e) D  q# o+ q$ a) `) k* D<P><FONT color=#ff0000>函数名: isatty </FONT>
" U# l8 _( ?: K3 w功 能: 检查设备类型
1 U6 `8 u* C6 t用 法: int isatty(int handle); 5 W: U* x. C+ t. _7 `6 X" ~
程序例: </P>" t! S" m% t' I, Y& }
<P><FONT color=#0000ff>#include <STDIO.H>5 K- i9 u. U4 [2 s, b- `
#include <IO.H></FONT></P>
- V: b7 o8 `9 x" j$ N0 n- ?# u: u' p  E<P><FONT color=#0000ff>int main(void)
: K. ~$ J: `! t8 i/ J7 E{ ( x5 G; k6 t! M, Q
int handle; </FONT></P>
# V; `6 l8 S  v2 j<P><FONT color=#0000ff>handle = fileno(stdprn); , j- g) H! E3 S6 I
if (isatty(handle))
6 l* |7 |: ^% C) Rprintf("Handle %d is a device type\n", handle);
9 ~5 y$ B2 |: {9 X4 I9 d  Zelse   s8 V1 R$ B, {- z* O5 G( y! s
printf("Handle %d isn't a device type\n", handle); ; b) s6 h. r0 f: p
return 0;
& O! O% K1 s- P9 a+ C, A6 _# f}
- ]$ N3 }3 o; r- b. d8 O& a* D8 m) ?1 O: c
</FONT>
5 h2 l: m: j7 u' [2 K( f3 \</P>
8 C, M. t. f. L. r5 o<P><FONT color=#ff0000>函数名: itoa </FONT>7 ?5 I% U+ w8 l
功 能: 把一整数转换为字符串 " F! W# Z1 g  J' U. {
用 法: char *itoa(int value, char *string, int radix);
, Q  a, m0 p  e9 d( R程序例: </P># `: ?7 S8 k% Y3 |% Y
<P><FONT color=#0000ff>#include <STDLIB.H>
# t& i) y% b: Q" t. ~3 r#include <STDIO.H></FONT></P>
3 o; R4 T* C' Z" h4 N  j9 w& B9 V- T6 l<P><FONT color=#0000ff>int main(void) 4 T! U) J" }& a+ M- d
{ 3 c+ ]( U" x( q, D1 \$ C7 C
int number = 12345; + ~* G2 X4 x4 f" Y" F9 M' }3 X
char string[25]; </FONT></P>
1 p$ e4 H- E5 f2 {<P><FONT color=#0000ff>itoa(number, string, 10);
; p, g& j0 }& L1 ~! ~printf("integer = %d string = %s\n", number, string);
/ N$ r# \- T5 o7 B/ ~) D1 k& Zreturn 0;
6 z9 R2 @$ G+ I, P5 G' |} </FONT><FONT color=#0000ff>
* x  D! U$ o; O0 ^+ [2 {</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-6-13 02:00 , Processed in 0.332025 second(s), 52 queries .

回顶部