- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(i开头)</FONT></B></FONT></P>
1 B* j* n. j d" i9 T% r< align=left><FONT color=#ff0000>函数名: imagesize</FONT>
& T: K: n: [, V功 能: 返回保存位图像所需的字节数 $ m/ ~/ t* b) h6 Q- `' t( u' I: [
用 法: unsigned far imagesize(int left, int top, int right, int bottom); , y" z0 l8 c) q7 E5 P
程序例: </P>
% v# B4 s6 P9 C5 ?< ><FONT color=#0000ff>#include <GRAPHICS.H>
/ ]/ a$ c- Z4 |+ i, F/ T& f#include <STDLIB.H>; G6 c# J5 s" @8 U" h# [
#include <STDIO.H># e+ y( C4 o& E$ d
#include <CONIO.H></FONT></P>7 f# i/ V; N4 G2 ]6 B9 ~( ]
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>
! b; ?- @4 U R5 I" u< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>
- t! X' C+ h/ D+ _$ s+ n< ><FONT color=#0000ff>int main(void) 3 U% K4 @7 Z a& ]% ^- W, r7 p6 l; v8 k
{ 5 K+ H2 `* P/ @4 H( k0 ]" L
/* request autodetection */
" R( c8 Q7 y- u% fint gdriver = DETECT, gmode, errorcode;
_6 D( ]. y# w0 H9 p0 yvoid *arrow; " D1 {( f% Q. w$ s
int x, y, maxx; 6 v l8 b+ {. S5 V s; ^, Y- q; u
unsigned int size; </FONT></P>7 g, H, E+ M+ u9 g
< ><FONT color=#0000ff>/* initialize graphics and local variables */ 2 b3 ^# q% K. _, H( p
initgraph(&gdriver, &gmode, ""); </FONT></P>
% f3 d: [( P. [: q< ><FONT color=#0000ff>/* read result of initialization */ b( q# c+ P J4 O: O! N
errorcode = graphresult();
6 Z" I* i4 I, e/ Z: iif (errorcode != grOk) /* an error occurred */
1 o" h6 U& N+ l+ K, I% y{ ' i9 Z9 ]6 k3 ]3 b# F) D
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 d: s; A- m( U0 k4 t# Z
printf(" ress any key to halt:"); ) v. w( n8 w: S7 D4 o0 O' x
getch(); 4 v" M' R! u$ H2 I
exit(1); /* terminate with an error code */ - O& F+ |2 @1 Z9 s
} </FONT></P>- `' }/ ^5 Y( l( ^! Z+ a9 O
< ><FONT color=#0000ff>maxx = getmaxx();
( f, c( P# G! c- u; ^$ ~1 dx = 0; - F5 K; A0 Q+ b1 M
y = getmaxy() / 2; </FONT></P>$ z8 U8 @( |/ U3 D0 ]& L
< ><FONT color=#0000ff>/* draw the image to be grabbed */
5 j1 @' P' u% ?# c( H; p4 j2 udraw_arrow(x, y); </FONT></P>
5 B# Q% D& N# T# `, k< ><FONT color=#0000ff>/* calculate the size of the image */
" f& m3 w7 ^+ c% ]2 E5 c+ [ R; p. asize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>
2 n$ X# b @/ ]9 L/ J< ><FONT color=#0000ff>/* allocate memory to hold the image */ 1 V3 I+ A& Y0 H; {3 c* y [
arrow = malloc(size); </FONT></P>! P" Y& h, C) `1 k: I
< ><FONT color=#0000ff>/* grab the image */
! S K, v5 ?3 O) V, Pgetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>, i3 U: o" A% K4 m3 |" `
< ><FONT color=#0000ff>/* repeat until a key is pressed */
& y' s5 K5 _: `1 g0 ~- Y, V; Cwhile (!kbhit())
8 v8 z6 q& z" \+ W2 \) k{
) \4 ]! p- w$ `2 q) K/* erase old image */ ' L" _" X" m$ n: w+ C" G
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
2 `7 }9 a# v/ N- c7 j5 N1 V< ><FONT color=#0000ff>x += ARROW_SIZE; ! J3 q; D5 j7 v( S& q
if (x >= maxx)
' [4 l* S9 j6 F6 X; w0 U9 @x = 0; </FONT></P>& \- V- Q# B3 A& |- x" s
< ><FONT color=#0000ff>/* plot new image */ - h, N, d& F& G; T9 h% K
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); # F- {! N, j. w% J! Q! {3 ^
} </FONT></P>
, X. B' O: _$ b< ><FONT color=#0000ff>/* clean up */
1 G& h3 _3 ?9 n, Y9 w7 m2 |7 ufree(arrow); $ n* q2 g. L6 ^' ]$ O
closegraph();
: j% {) w. c$ o7 Z% _( greturn 0; ! X" b" M, q) P1 j7 Q% m3 W( A
} </FONT></P>; N' O; I1 N1 j; X/ w0 A
< ><FONT color=#0000ff>void draw_arrow(int x, int y) ! V7 x6 H7 l3 J+ h
{
& o: W9 L7 v+ E4 \7 C5 f' V/* draw an arrow on the screen */
, [1 X$ B# W8 H2 C+ ]; nmoveto(x, y);
' q6 z/ r8 @' glinerel(4*ARROW_SIZE, 0);
! u: ?- E9 f. S6 ]$ clinerel(-2*ARROW_SIZE, -1*ARROW_SIZE); , k6 _2 q' a5 K) s6 y
linerel(0, 2*ARROW_SIZE); o4 B8 b8 e1 H) a
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); 2 {6 T4 ~/ v4 } ^8 W! N5 c
}
: z( Y8 e" P* l. @. p0 G0 A8 ^& K. `
& X5 s, v6 R6 }* c# @! Z! f</FONT></P>
0 m7 p% |4 n& q< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
% Y' o: l* }8 M6 P<FONT color=#000000>功 能: 初始化图形系统
7 s- {5 ~: W0 O& r; j4 R- K用 法: void far initgraph(int far *graphdriver, int far *graphmode,
0 ]. r. e$ V* E8 [3 v* F+ echar far *pathtodriver); / J9 p* A) K$ L/ O/ A- S5 F( |" e
程序例: </FONT></FONT></P>
t, O) Z/ L+ v1 {+ _< ><FONT color=#0000ff>#include <GRAPHICS.H>% Q8 Y- L7 H5 F: [; n* @
#include <STDLIB.H>
9 c9 ^# d: ]; { `7 E& p5 {2 ]#include <STDIO.H>4 r6 }) W- I8 K! ?& F
#include <CONIO.H></FONT></P>
& }; Y2 R0 O; `: W1 R7 ^1 s< ><FONT color=#0000ff>int main(void) ) f$ D: S j* i- Z
{
+ m$ ]8 K" T7 f0 _! k/* request auto detection */
7 U& \1 ?6 [+ T7 G3 }$ B' gint gdriver = DETECT, gmode, errorcode; </FONT></P>5 ]% D3 j4 r: a1 L* E: ?
< ><FONT color=#0000ff>/* initialize graphics mode */
6 ~2 n& ~& {8 ]8 z7 h7 ], cinitgraph(&gdriver, &gmode, ""); </FONT></P>( _0 J' C* B, G u2 t
< ><FONT color=#0000ff>/* read result of initialization */ ( Z; e ?4 x" K, n/ V$ |
errorcode = graphresult(); </FONT></P>- l" f/ } q# U9 ]
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ * K6 A. H/ z3 n& p' q& g$ d
{
* Y4 k0 j* c* \' F" Q# S; ?' rprintf("Graphics error: %s\n", grapherrormsg(errorcode)); - O4 U/ }4 S3 ]% R& U# J- O
printf(" ress any key to halt:"); k* V- H9 m& l: r
getch();
+ A2 ?: V; j. M8 j& e! x( X/ b) M2 Aexit(1); /* return with error code */
! O4 S9 |- z/ W' x} </FONT></P>
8 e% Q" M7 a* _7 ~5 K$ A< ><FONT color=#0000ff>/* draw a line */ ! q- N8 A2 l4 e! c# ^/ s
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
: X, R' u$ }& n' A' O< ><FONT color=#0000ff>/* clean up */
) q, f1 V# Y) X9 F. t3 |getch(); : M5 T- H. E; a+ q5 K6 U1 |0 e
closegraph(); & v5 f( N/ K! C, m7 X: C# c6 k
return 0;
1 j& ?6 A# Y& P W- ~% E" M# ~} </FONT>) d( O+ J2 V8 }2 \' Q! o9 w, e
3 b5 Q2 p Y+ e, p/ Z/ }6 l K</P>
% P% U. [9 o+ m3 {1 o9 C< ><FONT color=#ff0000>函数名: inport </FONT>
1 ^" n' Z% v- ~8 l) o9 ?6 Y+ e功 能: 从硬件端口中输入
+ h; M# b0 z: m, u用 法: int inp(int protid); * J* W3 @3 A7 H/ f8 r
程序例: </P>
5 K! S! P9 S0 I& V+ X< ><FONT color=#0000ff>#include <STDIO.H>
3 h+ d6 @& g# h' Q9 f: y#include <DOS.H></FONT></P>
( d& k" V( o/ }& K7 J, q0 _0 P) C<P><FONT color=#0000ff>int main(void)
9 {7 }# `% f" T7 Y; ~3 w{ 5 V2 ^5 i* O9 X/ C5 J$ L( M8 ]" D
int result; ^+ q' I9 W$ s3 [
int port = 0; /* serial port 0 */ </FONT></P>
4 U8 p l5 y1 R1 i: A# {<P><FONT color=#0000ff>result = inport(port);
9 Z- X3 Q$ G7 k, }& f, O2 Uprintf("Word read from port %d = 0x%X\n", port, result); 0 u! Y! h$ Z% g- d9 E, k: q* {1 `1 E
return 0;
% y' y5 @7 {- Z: E% G. O3 s} 6 ]* i$ v" u5 c' q. M' f/ Z" J4 ~
% a, w- O/ |- Y1 A
</FONT></P>
: o3 x% O, [ P% w9 m/ V d<P><FONT color=#ff0000>函数名: insline </FONT>
- c D* o8 X- ?. j ~; d1 B; @: Z功 能: 在文本窗口中插入一个空行
* J6 C. Q( I# Q+ J1 b用 法: void insline(void); 2 m# g3 d; F! x$ _: r& f4 H
程序例: </P>
' a. z; N- J3 l' d- j2 Q7 h) M<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
7 g) o. q1 H# I<P><FONT color=#0000ff>int main(void) ( A4 z" Z$ v; k% F. F, Q2 z" Z
{
" T; q( ]1 F, T" W7 eclrscr();
* m$ w Q }4 fcprintf("INSLINE inserts an empty line in the text window\r\n"); ; d1 G. R; W ^/ V- h$ a0 H/ [3 _4 v* Y
cprintf("at the cursor position using the current text\r\n"); c7 O2 f5 K7 l; t
cprintf("background color. All lines below the empty one\r\n");
+ |9 c9 ~1 i9 @4 H3 Kcprintf("move down one line and the bottom line scrolls\r\n"); / Q Y( |7 p" s
cprintf("off the bottom of the window.\r\n"); j% m1 r1 m3 n2 R* u0 }- X0 {8 i
cprintf("\r\nPress any key to continue:");
2 b! {5 ?, U. D s# Agotoxy(1, 3); ( v( g6 T7 C; e& k. z; v: I" k( a7 u; Y
getch();
' K" T3 ~0 d6 \% n A3 Rinsline();
: l( M" s: K( p, Sgetch();
+ S% N( J6 h% p/ @% d3 j3 E% Sreturn 0;
$ |, Q; O0 ^" @ Z6 k}
4 q6 _9 e0 p `7 D$ ?3 b</FONT>. P v' d! d) a6 P& B7 A& }
- n, X. ?& k9 @</P>
7 K; r* `% B! l1 J P! Z<P><FONT color=#ff0000>函数名: installuserdriver </FONT>3 f3 T7 V0 W" v7 d/ |
功 能: 安装设备驱动程序到BGI设备驱动程序表中 / B. g% e8 E- ^( z. X
用 法: int far installuserdriver(char far *name, int (*detect)(void)); + N/ J' d1 L& M- _2 x
程序例: </P> x+ c: w' ? i1 o4 U
<P><FONT color=#0000ff>#include <GRAPHICS.H>6 Q9 m( }2 ?1 L2 I: {
#include <STDLIB.H>
: m+ m1 `" C, L1 T' M9 ^4 x#include <STDIO.H>
7 W4 C7 a/ S' ^6 ^+ E. E#include <CONIO.H></FONT></P>
: R1 r: ?6 m% _<P><FONT color=#0000ff>/* function prototypes */
4 c, L0 t# N9 W* ]/ B/ v" Q& sint huge detectEGA(void);
4 e9 [. b1 z" q, Ovoid checkerrors(void); </FONT></P>: a M3 T( d: U0 F. G! m/ F
<P><FONT color=#0000ff>int main(void) & @+ p7 ^$ q7 q' ?* M& `% D
{ . {' j# Y* }: ?; v
int gdriver, gmode; </FONT></P>) E) _+ w- T% e7 U0 D5 V
<P><FONT color=#0000ff>/* install a user written device driver */
. t' W1 C; z% D( j0 Vgdriver = installuserdriver("EGA", detectEGA); </FONT></P>1 _) A' `3 s2 j% F7 l: V7 m( y0 \
<P><FONT color=#0000ff>/* must force use of detection routine */
8 i/ x, o6 |4 N0 T4 D5 E$ l! q- b9 `gdriver = DETECT; </FONT></P>
4 S# F. D# {5 G. ^<P><FONT color=#0000ff>/* check for any installation errors */
4 Z& j' V; _! @; q% g! _* ycheckerrors(); </FONT></P>3 l, B! G: q' C( a) B7 f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ u- q3 {. f: h9 G9 [$ _initgraph(&gdriver, &gmode, ""); </FONT></P>0 b2 O: ^, x2 j+ x
<P><FONT color=#0000ff>/* check for any initialization errors */
, Q# l0 c. u- s0 ?checkerrors(); </FONT></P>
" G. S# o$ S% w8 f0 x<P><FONT color=#0000ff>/* draw a line */
* k: A7 c& ?* M/ v1 Iline(0, 0, getmaxx(), getmaxy()); </FONT></P>" o! E7 |+ h2 e, O5 ]
<P><FONT color=#0000ff>/* clean up */ ( \$ i9 ^; N3 ^7 p, t) G
getch(); 9 e4 A% F) T# `2 I) ]! c" J0 j
closegraph();
) S; }3 B/ f& t3 I& kreturn 0; 2 Q @+ h1 i% p
} </FONT></P>7 ?: B8 x& h1 ]8 F. h4 C x# Z( h
<P><FONT color=#0000ff>/* detects EGA or VGA cards */ $ A- x! o/ R- G6 d" U/ B
int huge detectEGA(void)
# C' |3 r9 W6 v- j{
; R6 n7 g0 l+ @int driver, mode, sugmode = 0; </FONT></P>
/ X5 K/ W7 f, t O9 H8 Q) h<P><FONT color=#0000ff>detectgraph(&driver, &mode);
6 y$ }$ t( }3 N& D: q; N1 zif ((driver == EGA) || (driver == VGA))
- a& Q$ m' U. P; `0 A# o0 U' l/ `/* return suggested video mode number */
7 G; O% K7 `3 a( K. ^, Hreturn sugmode;
* R3 D' `8 \( velse : h8 {) E$ s1 j7 u/ T* O
/* return an error code */
# V, D! V8 @2 Y8 d" S7 sreturn grError; ( ?$ A& s, W2 l I- n
} </FONT></P>
# c7 t* G8 _! A9 n. }3 @<P><FONT color=#0000ff>/* check for and report any graphics errors */
. w6 U0 d d- c+ \" evoid checkerrors(void)
$ _( G& G I& q" M3 W: s{
, L3 K; N. J4 ~, W# r5 w/ f' g% Tint errorcode; </FONT></P>- R( K7 ]3 d4 R C2 o- G8 b
<P><FONT color=#0000ff>/* read result of last graphics operation */
T, p' }3 l& h2 u' Jerrorcode = graphresult();
0 }7 N6 k+ n% w: V3 T2 u; @if (errorcode != grOk)
, T# t# o6 U# ]$ u5 A: L) b; B8 U{ 8 N+ x" D' O& M
printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 f2 r" l0 ~* v5 tprintf("Press any key to halt:");
; L( o+ ^3 A3 ~* Mgetch();
; W4 i' Z, Z) l. J! M+ L' cexit(1);
1 s/ r! _( }# d0 m# j" r' V1 C2 p}
3 ]7 f# A5 ~0 z} </FONT></P>
& K% n! x. ~4 ]$ y* H3 T<P><FONT color=#ff0000>函数名: installuserfont </FONT>
4 {; X9 Q/ H7 l# ?功 能: 安装未嵌入BGI系统的字体文件(CHR)
7 a* z! ?1 D4 o5 d' H) p用 法: int far installuserfont(char far *name); . j* e. W- ^/ Q7 p
程序例: </P>
: \7 I; Q! ^ j; M<P><FONT color=#0000ff>#include <GRAPHICS.H>
" @; v0 B- q; m9 `#include <STDLIB.H>; I, W/ R7 C! u0 Y
#include <STDIO.H>- U! Q# E+ f) y0 H( J- Y2 B9 P
#include <CONIO.H></FONT></P>- a: ]0 P i7 S* f1 U) W9 u
<P><FONT color=#0000ff>/* function prototype */ / r Q/ g4 X0 O6 @ U# {
void checkerrors(void); </FONT></P>
! H8 f1 h/ I: c4 }5 E<P><FONT color=#0000ff>int main(void) $ \( q$ e' w5 ^+ y* o" b) R
{
8 e( x ~5 D6 F* k2 r; t1 Q: F8 Q" \/* request auto detection */ 9 m7 h3 v0 p$ j. D) q# d( \
int gdriver = DETECT, gmode; 1 @: f; w Q1 C% S/ H" z
int userfont; * \4 Y0 i( s/ p: H
int midx, midy; </FONT></P>; o, w. l' H. n' E6 l. a
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 N$ a3 C( h# C! o9 Binitgraph(&gdriver, &gmode, ""); </FONT></P>
: }" I/ K5 v% K1 B<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 J+ N( Z" ?. smidy = getmaxy() / 2; </FONT></P>
+ k- t! B. R! T<P><FONT color=#0000ff>/* check for any initialization errors */ 3 ?, I+ X. t/ p& P
checkerrors(); </FONT></P>, _- S4 ~/ G& X6 d
<P><FONT color=#0000ff>/* install a user defined font file */
! x6 m+ e" H# F: ~4 Y) Vuserfont = installuserfont("USER.CHR"); </FONT></P>7 P6 n7 C, R, F2 H, G& q7 I( i
<P><FONT color=#0000ff>/* check for any installation errors */ `9 K `% _5 T4 Q: R) z' p- B
checkerrors(); </FONT></P>
( d6 A Y& f' ?<P><FONT color=#0000ff>/* select the user font */
9 C5 g u: A8 h% g! Isettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
- C7 N2 s6 Q7 f0 d$ @<P><FONT color=#0000ff>/* output some text */
7 M y9 m/ E6 j6 H# s' r$ ^outtextxy(midx, midy, "Testing!"); </FONT></P>
3 O) @! h( K F }; ?" f' F4 z! H<P><FONT color=#0000ff>/* clean up */
9 w: Z) k5 y& B' d$ |getch();
1 g* w4 J4 Q$ A3 E# nclosegraph(); & M' T+ B0 k; \: I3 @9 f
return 0; / v i a: j9 u! E: r
} </FONT></P>
2 }( y) w% r4 Q+ \<P><FONT color=#0000ff>/* check for and report any graphics errors */ u! A3 i- {: {9 T; N
void checkerrors(void)
& ]/ S0 C9 j4 Y# q Y$ U/ ~{ p: v9 R' `+ v0 H* L; ]
int errorcode; </FONT></P>- L" G6 @) u: y0 w5 {7 q
<P><FONT color=#0000ff>/* read result of last graphics operation */
0 M' q" x6 a5 k3 t- ]errorcode = graphresult();
' [- ?- N. j# Sif (errorcode != grOk)
3 k# D: [3 M6 X5 p5 ?{ ; v5 L; v4 g) [$ q8 W$ u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 ^* L* |1 Z. X8 X% E
printf("Press any key to halt:"); Y) X8 ~" {' m5 r; ^8 U
getch();
" Z. [% C9 s4 hexit(1);
( A0 M7 i5 j: ^. E7 b z+ O, U} % z# K9 s8 q' q; i l5 Z; I
} </FONT>3 X2 x. u- J( x+ [; r1 _
. C; l$ t6 ^# Z" N$ A. v0 k
1 @% a1 ~; g5 L) T8 b. }, e( V( t* X</P>! J5 |% ^+ ]' s
<P><FONT color=#ff0000>函数名: int86 </FONT>- o5 a/ X1 o' g1 _8 o7 v
功 能: 通用8086软中断接口
: {# n9 s4 S# h2 L- l5 G5 x3 t用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
% v, {1 W" e6 W7 T. @' J程序例: </P>6 A1 |: E1 {' |& o7 T) a
<P><FONT color=#0000ff>#include <STDIO.H>
$ _ I; z* j3 l8 W1 E& ^#include <CONIO.H>
6 X! E/ P* N/ x- P$ J#include <DOS.H></FONT></P>
3 ?' h1 O8 }# R& r1 C/ L5 D( U4 b<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
& A! F3 I! V. q* B<P><FONT color=#0000ff>void movetoxy(int x, int y)
0 @" `4 q1 L$ X/ i8 q U3 ]9 O{ $ ~" \. X: ]8 w: [3 H
union REGS regs; </FONT></P>" \$ T: K0 \4 S
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */ - X4 Y) Q( [; |' ?4 N3 g% w; \# K
regs.h.dh = y; ( h& @6 `* i1 Q
regs.h.dl = x; 6 b7 | d! y8 C1 A. o) _
regs.h.bh = 0; /* video page 0 */
) T/ O+ S0 \" N- J/ s7 rint86(VIDEO, ®s, ®s); 7 j+ `4 b' ^# U" F+ F$ ~" N
} </FONT></P>
) v2 R/ M. m) q7 H6 g) \; V' t<P><FONT color=#0000ff>int main(void) + b5 L( m; X3 P1 c9 G: z
{ 1 V4 T# b1 g; _( X7 Y
clrscr(); ; h9 [# v7 o j a1 u7 {2 B" h# _
movetoxy(35, 10); , m$ g s D7 ~7 | j* b% ?% q& f) n4 ?
printf("Hello\n"); 8 D! F& ~ ]! N6 N
return 0; 0 {; ~0 V, e( ]- [3 {
} </FONT>
5 f0 Y9 B; J- [3 q. F9 @. o% e' |* c3 _& j8 g% s
</P>) \% Q3 v3 U% r2 w) L
<P><FONT color=#ff0000>函数名: int86x </FONT>
, Z6 D* e7 J4 w+ r5 @功 能: 通用8086软中断接口 & C4 Y) N3 j0 L* G' n& D0 x
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
f2 n, X# ~. b9 Y* u8 m" o4 Zstruct SREGS *segregs); ) l( h* H5 ^1 f9 S
程序例: </P>
4 Y6 }5 C* f7 Q/ h" |4 A<P><FONT color=#0000ff>#include <DOS.H>
1 f+ v, Y& l$ x1 G; x7 `* e#include <PROCESS.H>
: j, U0 F Y- H9 D' S0 d#include <STDIO.H></FONT></P>2 |4 g; G1 J) S: y
<P><FONT color=#0000ff>int main(void)
- R }" W; A+ S+ N{ 9 \. b( l9 c& R
char filename[80];
1 ?$ p: {2 D" @& g" D$ _union REGS inregs, outregs; H$ _2 M+ a) ^( P' Y' V
struct SREGS segregs; </FONT></P>
# a/ ^. m& W6 ^, T<P><FONT color=#0000ff>printf("Enter filename: ");
4 i, W' }: N# ^$ kgets(filename);
, f+ k1 ?- p2 _! |inregs.h.ah = 0x43;
$ ?% e# N; W% K3 C" V2 Jinregs.h.al = 0x21; ) y6 x9 l: b9 f. e5 i& A i2 I
inregs.x.dx = FP_OFF(filename);
: q0 L9 O% c$ b# K5 q1 M" x6 ?segregs.ds = FP_SEG(filename);
) A; U' g% f- c4 ?7 [" D1 |int86x(0x21, &inregs, &outregs, &segregs);
- C7 n- i+ {; Z" eprintf("File attribute: %X\n", outregs.x.cx); ' Q, o4 u9 E" ^9 p- z
return 0; : Z1 i" R; t T* H" o
} 6 Y& E, A$ l/ Z) V. A# z
$ [2 k4 R# [% p- K. f</FONT>$ W& T. b- ?1 z' S5 M& M% p
</P># F; l: C1 K3 J2 G
<P><FONT color=#ff0000>函数名: intdos </FONT>
- K3 E8 |/ w" [& T功 能: 通用DOS接口 ( L; \( h7 f, B. ~+ _# R. r
用 法: int intdos(union REGS *inregs, union REGS *outregs); ) H6 V6 Z9 d3 n! E' j( r* l
程序例: </P>
, I6 h- Q% H7 B2 d" V<P><FONT color=#0000ff>#include <STDIO.H>
- t4 @+ o) @1 l, U# p @#include <DOS.H></FONT></P> e; _+ ?5 y7 @6 V X
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
' y5 q) x' @$ {8 t3 ?int delete_file(char near *filename)
: R/ ?+ b0 m: A1 F6 R/ {6 e) Q2 w6 F{ 1 _- Q# r' Y2 n" H2 m J
union REGS regs; 6 W; n; _6 E3 x! G6 V6 n$ c6 O2 q
int ret;
8 p0 ]. I# ~7 tregs.h.ah = 0x41; /* delete file */
: l( s) o: y8 bregs.x.dx = (unsigned) filename;
! L& V( G' C9 C5 y5 Nret = intdos(®s, ®s); </FONT></P>8 ~/ c' s& i& X& I9 l: o3 e
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ 1 m8 X+ H. I$ v0 y p. D# t
return(regs.x.cflag ? ret : 0); X2 Q& N- u' ^. ]5 h1 V: g: R
} </FONT></P>2 g5 W2 g: _0 s U6 A& N% k( L _
<P><FONT color=#0000ff>int main(void) 4 e I& o9 z, T# Z; ?. n Q
{ $ ^7 O% u1 Z' Y7 ~5 Z
int err;
+ g; s, M$ }- Yerr = delete_file("NOTEXIST.$$$");
; O5 K$ I0 n k6 O1 gif (!err) ) }' y* ]! Y+ ?+ u
printf("Able to delete NOTEXIST.$$$\n"); $ q+ X6 |% a2 t \' f2 q! a1 Z% X
else 9 D$ ^$ e" I' s- M' f0 Q# f& }
printf("Not Able to delete NOTEXIST.$$$\n"); # B @, e% R1 G2 t$ s. O
return 0;
2 l6 |+ x _" _$ g% E} # G6 \# p9 B# F8 D7 r, c- ?4 D
; x3 j' R% P$ r, f! N: R</FONT>, x* E) M8 e9 r" {3 M3 d
</P>
! H& X4 V5 O3 U- s<P><FONT color=#ff0000>函数名: intdosx </FONT>7 b" i8 D9 r0 t% c
功 能: 通用DOS中断接口
" T& R! q1 |. Y用 法: int intdosx(union REGS *inregs, union REGS *outregs, 3 E c- f0 G4 D: Q
struct SREGS *segregs); : c& E9 ^7 u) v
程序例: </P>
4 ]6 |0 Y) d; }1 n \<P><FONT color=#0000ff>#include <STDIO.H>
/ S; m9 \0 f+ V& C3 a#include <DOS.H></FONT></P>
d* ]5 X+ |$ q" }: Y0 n4 f<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 6 H0 F. J9 \+ e
int delete_file(char far *filename) 9 E5 S" M8 Q6 e0 [6 M( ?5 W! S! P
{
' a1 Q7 z5 Q8 {; }3 P6 R* xunion REGS regs; struct SREGS sregs; ! [' q H4 r0 |6 p) ?
int ret;
, k' A/ i% `9 p! H' G4 R* A. E( [regs.h.ah = 0x41; /* delete file */ 3 k. o B3 v+ m
regs.x.dx = FP_OFF(filename);
/ m4 C1 `1 l; n2 Z& G! g3 ^* zsregs.ds = FP_SEG(filename); / ^7 ~7 G/ t8 d
ret = intdosx(®s, ®s, &sregs); </FONT></P>
1 n/ h; ?/ }& V) f1 x' Z4 J<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ . |5 T+ e: z6 N R* o1 }* d
return(regs.x.cflag ? ret : 0); - x9 J# K- ]- J+ s2 Q3 n- O
} </FONT></P>
# Y0 D; I& l9 N2 O- P<P><FONT color=#0000ff>int main(void) 3 ^& {, ]9 q4 N# s$ d( k
{ * D Y, f* U6 q/ V5 X% b
int err; ) s" o( y1 M- q( C4 \) Y6 n
err = delete_file("NOTEXIST.$$$"); , e* W, n. O! v8 X, a9 p i
if (!err) 9 g/ ~- G# j0 J T
printf("Able to delete NOTEXIST.$$$\n"); ( c5 J8 f3 N" d, D
else ' D; p' t# L- N `# G+ e
printf("Not Able to delete NOTEXIST.$$$\n");
, p- a; ]# ]: [, M J/ y* G5 V+ l% areturn 0; ! h8 {5 }# o/ A7 {& G. ]; F, [! X
}
% N' @0 U9 U6 r0 }7 x8 \; l7 @</FONT>
4 J+ ?1 z6 N6 W% l& P6 N/ W3 {</P>- s/ d3 y1 A. N; Q
<P><FONT color=#ff0000>函数名: intr </FONT>; k% @' E" ?6 M: y/ I0 ]+ ], A
功 能: 改变软中断接口 * l( b' p3 T+ O3 Y2 T
用 法: void intr(int intr_num, struct REGPACK *preg);
0 p! v) m L3 B3 A9 a/ |程序例: </P>( j1 y" A* E- E. _! J: Q) }
<P><FONT color=#0000ff>#include <STDIO.H>
' S3 B$ m6 J! T; P! B8 W5 P8 S9 W3 M#include <STRING.H>
% P+ v/ G. O& h5 Z: `/ A: J#include <DIR.H>0 \4 i9 h. }& F
#include <DOS.H></FONT></P>4 f; @) ?# P. p5 g& |) J
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
) X O @3 _/ l1 L% m, {* c<P><FONT color=#0000ff>int main(void)
3 ?+ r% `! W( Q" W/ a{ $ A8 k' U; q# ~7 Z
char directory[80]; 6 G/ B; B, }: p
struct REGPACK reg; </FONT></P>
/ G. U' |6 c' Q4 T }4 a% M<P><FONT color=#0000ff>printf("Enter directory to change t ");
$ l/ c0 K' B, lgets(directory);
5 \ [- f) `5 ~; P+ x, p! dreg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
6 U" F6 {/ D! Y) M6 ?5 J0 qreg.r_dx = FP_OFF(directory); 8 O b- \9 k% h, \/ k% w& d
reg.r_ds = FP_SEG(directory); 9 p, u( ]& U7 O* b( V! o
intr(0x21, ®); 0 ]! ~$ c* k: W3 ]9 `! O$ @, N
if (reg.r_flags & CF)
" `4 T% f* @1 t# Z2 Vprintf("Directory change failed\n"); : K* F3 ?8 x$ b0 i
getcwd(directory, 80); % s) @2 T1 q1 x- l
printf("The current directory is: %s\n", directory); 8 M, b) R7 P' g- N1 O
return 0; 6 l1 a {1 M( L/ d: w
}
; I3 g- w, f( U. ]$ d) N</FONT>
& f6 s. n7 T& ^/ _. e</P>
6 v5 f; k% F" s2 S8 Z<P><FONT color=#ff0000>函数名: ioctl </FONT>. C7 R; |) L. ^
功 能: 控制I/O设备 " Y3 x# d% z' V' \& z/ B0 S; G
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
$ H, D; h( A0 C; x4 L% J程序例: </P>
, e; ?# [! {$ X4 w& ?4 D. H<P><FONT color=#0000ff>#include <STDIO.H>
! \+ ^0 u6 Y% ^/ R#include <DIR.H> |+ H$ N% H; T7 X
#include <IO.H></FONT></P>
2 ?. s9 Q0 |* O9 m<P><FONT color=#0000ff>int main(void)
( S1 L9 _+ f4 h6 [{ 8 X' x4 v+ m ^# W; f' S
int stat; </FONT></P>
$ E9 X0 K- |1 d- ]5 r7 w<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
3 ^2 |% S1 B1 U- I5 Ystat = ioctl(0, 8, 0, 0); 0 h' V: F0 w* [% Y& y. {8 ~9 ^
if (!stat)
: x! Y* l l3 G% aprintf("Drive %c is removable.\n", getdisk() + 'A');
& d. \) Q+ t+ Q* R3 o* x" b$ `else $ d7 y4 z: C; T
printf("Drive %c is not removable.\n", getdisk() + 'A');
9 h/ H- ]: u9 L0 K% ^return 0; ! j v g* T5 T
}
; S4 I0 E. o( ~6 C$ @0 L- b7 p" e+ P- V' j$ {# a; R8 {' Z) p
</FONT>/ z% X: X# w9 F: k( L
</P>7 [" h& j" b- {0 R; R6 N
<P><FONT color=#ff0000>函数名: isatty </FONT>
& Y$ ^. W2 B) b9 L, |功 能: 检查设备类型 6 X) M; T* \" P* G/ Y. M- I0 h N
用 法: int isatty(int handle); 9 L" J9 T3 N4 G5 W; S! ]
程序例: </P>
0 }1 Z5 T: ^6 X( S( O# C; s<P><FONT color=#0000ff>#include <STDIO.H>
1 d) q# }1 }6 w) K; U: `#include <IO.H></FONT></P>9 m4 T! a* `; v& G4 [
<P><FONT color=#0000ff>int main(void)
0 [6 c2 @5 H+ _5 d- H' K% H{ ; p. N {, }0 m2 g2 D
int handle; </FONT></P>* S2 l2 e [3 g7 d1 T2 }3 C4 H
<P><FONT color=#0000ff>handle = fileno(stdprn); , B! z/ E9 ^7 |$ [
if (isatty(handle)) , v& R* V) r5 Y0 _+ s
printf("Handle %d is a device type\n", handle);
/ N( ?/ n9 X9 V& w: X- u% g% `else . ^/ C1 H% p n x! g
printf("Handle %d isn't a device type\n", handle);
/ t" Y0 T c4 F0 Freturn 0; 4 s8 x, _& s, D/ D
} ( n. V c/ Z+ v3 ?# n9 S5 ]
$ e: |2 X" z1 M' _0 V" u, V
</FONT># ^9 n5 f2 n, |3 a. p: L# s! V
</P>
) @& ]; i) t# C<P><FONT color=#ff0000>函数名: itoa </FONT>
* s( A5 v# h6 c6 n4 v% P6 B功 能: 把一整数转换为字符串 9 c( T& z: R* m1 Z2 v
用 法: char *itoa(int value, char *string, int radix); * f4 \7 \: l" w3 f7 R/ h5 l+ N' v [
程序例: </P>
. `6 b$ E# R) m- y<P><FONT color=#0000ff>#include <STDLIB.H>
3 d9 h0 S9 ~, T#include <STDIO.H></FONT></P>( ^: S- u( N, h/ P: k' U6 n6 A
<P><FONT color=#0000ff>int main(void) ! w: C1 F3 k1 R9 M' ?
{
, @- q: _# ^. k+ C& Vint number = 12345;
; f+ R. H f9 A3 b/ }8 Z; |char string[25]; </FONT></P>- |: ^/ j5 A) w& K( X$ X: {) F
<P><FONT color=#0000ff>itoa(number, string, 10); 5 }4 i4 d- O" |( K
printf("integer = %d string = %s\n", number, string);
" O* z" f0 U) U& ureturn 0; 9 u) N1 c& Y1 t8 Q% H" a" I! v
} </FONT><FONT color=#0000ff>: [& {/ K3 S+ O3 r( A3 G' \
</FONT></P> |
zan
|