- 在线时间
- 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>
9 [! d/ v% i0 ^1 @: B# F2 R< align=left><FONT color=#ff0000>函数名: imagesize</FONT> . z& y$ F% f! O b
功 能: 返回保存位图像所需的字节数 ' N. v/ Q( j' {3 F
用 法: unsigned far imagesize(int left, int top, int right, int bottom); $ G$ n9 ^: y& W
程序例: </P>
4 G2 \2 S" I& E8 _3 Z; e8 f; g< ><FONT color=#0000ff>#include <GRAPHICS.H>: n6 \& e3 Q( O w. i1 C6 C
#include <STDLIB.H>, H5 \6 L* x8 ^$ \: N: v4 J
#include <STDIO.H>
\: s r) U* F/ a7 r) H9 l#include <CONIO.H></FONT></P>
5 o8 \6 O3 h+ {- j' x, P< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>0 ~$ ]3 E9 X X( a P* l
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>, B2 b/ a1 u' {6 T9 r- N. m
< ><FONT color=#0000ff>int main(void) - I# \! u3 K* k, D
{ : W. }( W# R+ e" j
/* request autodetection */ 5 Z- E$ N. [; @: q, j
int gdriver = DETECT, gmode, errorcode;
- Z4 l8 X: D' B& Yvoid *arrow;
) f2 c# S g4 w/ aint x, y, maxx; , C1 i( A: _8 r5 I7 {1 ^5 }
unsigned int size; </FONT></P>9 S N/ p( |0 B0 o
< ><FONT color=#0000ff>/* initialize graphics and local variables */ & I9 d c" m+ l' e. Q' i
initgraph(&gdriver, &gmode, ""); </FONT></P>
3 Z/ \+ p/ `+ L0 q e6 U< ><FONT color=#0000ff>/* read result of initialization */
( B+ b, H0 m0 V, H8 W8 C P$ O( t. verrorcode = graphresult();
! [6 d: v0 f: a6 Oif (errorcode != grOk) /* an error occurred */
# h( c: |% {4 x; }- F{
) c3 b: W0 l- _& A# c' Z, kprintf("Graphics error: %s\n", grapherrormsg(errorcode)); I0 y U. x# u; s A
printf(" ress any key to halt:");
) T" L# C$ H2 Sgetch(); * d3 D5 w B; ?! f& R0 c
exit(1); /* terminate with an error code */
0 x$ J0 K# B- X+ T2 T% k} </FONT></P>3 X. U+ m, ]5 l2 t, \8 Y
< ><FONT color=#0000ff>maxx = getmaxx(); $ r& c4 g" g, ?1 M, }
x = 0; 5 h3 O" i9 O t/ c
y = getmaxy() / 2; </FONT></P>) y( V9 T, `& \5 u0 k. z2 e$ P
< ><FONT color=#0000ff>/* draw the image to be grabbed */
& \! w1 X" R5 D: V: ~. o$ x8 D/ ydraw_arrow(x, y); </FONT></P> a2 q9 B$ S2 i. v
< ><FONT color=#0000ff>/* calculate the size of the image */
) ?: y( k. T; F- `size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>8 A" J* j' _- R& h3 T8 Q) N
< ><FONT color=#0000ff>/* allocate memory to hold the image */ 5 q' _7 B, m8 j
arrow = malloc(size); </FONT></P>: n' S6 ]# U/ n( [1 z$ Q0 {
< ><FONT color=#0000ff>/* grab the image */ . z1 U" l6 C- n& {& Q) u2 j9 d
getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>3 E5 S2 b9 Z% e, V# v
< ><FONT color=#0000ff>/* repeat until a key is pressed */
$ {: Y* |4 |1 O4 v: i4 qwhile (!kbhit())
6 V5 q- w5 @# V _& Z) g9 o{
$ ~4 X, A- i" y# ]9 Z4 n; ^/* erase old image */
' v+ f7 z1 a; H2 z/ \" Aputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
! E- S' I% D: d6 o< ><FONT color=#0000ff>x += ARROW_SIZE; ' Z* `1 E8 Z9 H, l
if (x >= maxx) & p& O1 ]) ]8 Y3 V4 C s
x = 0; </FONT></P>+ _% C1 S4 D+ i! @5 l1 y( q1 z
< ><FONT color=#0000ff>/* plot new image */
, ]. o' w6 Y: J+ [' G$ R5 E! {putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); " }9 d; x4 e* ]
} </FONT></P>! f7 z; n) S+ E _
< ><FONT color=#0000ff>/* clean up */
( D# ~4 I( p4 ?. [ X: u' k- k* Z! Gfree(arrow); 4 x# J# p! F) x- N6 @9 P5 |
closegraph(); 9 H, d% g3 X1 ^; U7 N
return 0;
) d; _* u- G5 d1 K} </FONT></P>
, y& T u9 L9 w" F4 u( a% q& c< ><FONT color=#0000ff>void draw_arrow(int x, int y) / v' g6 E3 R! }, l8 N2 j% P- f4 U
{
' g3 x8 N: M1 { X( ~0 s' L% y/* draw an arrow on the screen */ 2 @4 B* a3 E6 k( w# W2 M! m0 c* u& W
moveto(x, y); h& ^( d# E$ K, @- m
linerel(4*ARROW_SIZE, 0); 9 I% K+ d( y5 u7 U d+ @# ?
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
5 B( i* ~6 G, Flinerel(0, 2*ARROW_SIZE);
) D7 J! q# w/ T$ p% B, J/ S. Z7 Glinerel(2*ARROW_SIZE, -1*ARROW_SIZE); 7 [) t) q, \1 U6 W; Y% V( D- J* ^
}
' r; i6 _* F) S( N& X
1 l( X6 w4 S7 C) p2 o: @4 K! V$ ?1 \% M$ i/ v8 ~: S
</FONT></P>( {+ n2 A9 K; T6 i7 m# i8 G
< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
7 z3 L9 [' C2 ?( l" C. x! p<FONT color=#000000>功 能: 初始化图形系统 $ m! E5 H: Q$ H4 `2 r( ^
用 法: void far initgraph(int far *graphdriver, int far *graphmode,
1 B5 i2 C8 e7 @7 x1 G# Q$ l# a7 Cchar far *pathtodriver);
' l5 `0 N4 u5 Q. e `程序例: </FONT></FONT></P>* U5 I8 M0 V( d
< ><FONT color=#0000ff>#include <GRAPHICS.H>! X9 l- d4 T. s. P# G5 O- C0 F% t9 g
#include <STDLIB.H> t" @$ L# O& s8 J
#include <STDIO.H>
' g+ W" d8 q. P1 x" Q' v, W#include <CONIO.H></FONT></P>
; k# D; N }2 i! ^& {< ><FONT color=#0000ff>int main(void)
* \% j4 U; T+ y0 r7 L{ & ?1 f8 }/ K7 g F' K3 R
/* request auto detection */
7 z/ b* ^5 r6 O& F' dint gdriver = DETECT, gmode, errorcode; </FONT></P>0 i- g c: M9 H* P4 t0 Z7 X& k
< ><FONT color=#0000ff>/* initialize graphics mode */
' I2 c4 L$ d. x; M9 iinitgraph(&gdriver, &gmode, ""); </FONT></P>
* \* ~, s3 B# V( V: t/ M% R1 X, C, ^< ><FONT color=#0000ff>/* read result of initialization */ $ S- w( K. C+ F" D
errorcode = graphresult(); </FONT></P>; F# G0 h+ _* Y0 B! ~8 f* D
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ ; C! m1 d9 n+ Y
{
) Y/ D% L: D0 \$ h5 l( q5 \printf("Graphics error: %s\n", grapherrormsg(errorcode));
) g# y6 h, P& j: b" G. u6 u' Z6 [' wprintf(" ress any key to halt:"); 4 ?( A1 ~- R* R4 b0 Q: q& \+ |
getch();
5 K: A3 |/ k% V+ }exit(1); /* return with error code */ + u( H7 R: Y+ ]" x% ?( B
} </FONT></P>$ Q( Y' M# J9 K( [$ v# Q
< ><FONT color=#0000ff>/* draw a line */
+ J/ ~8 j- V2 Q; Aline(0, 0, getmaxx(), getmaxy()); </FONT></P>- ?9 \7 Z- `9 m4 h6 Y( ?; n3 C' i
< ><FONT color=#0000ff>/* clean up */
2 l Z3 @0 ^% _getch();
! g" y$ s4 O1 b$ oclosegraph(); ! R8 H( U9 l. C
return 0;
2 z1 v3 U/ I1 B6 L( b7 T: B1 U} </FONT>
& {* g5 v/ @1 v8 {, y8 z* ^* d; _
0 ?6 ~( Y8 O5 k' v3 U+ o7 j</P>
: i* O# ~8 Z, ?, g& @< ><FONT color=#ff0000>函数名: inport </FONT>
& \% |; x4 o7 d5 p功 能: 从硬件端口中输入
) W7 \8 ^% o5 s2 X* X! j! p f3 j用 法: int inp(int protid); # ~! _7 \; g0 l0 H# H/ L2 R, i
程序例: </P>2 u/ v1 C Z1 W, G" B. R+ X1 u9 M: d$ H
< ><FONT color=#0000ff>#include <STDIO.H>
# @7 ?6 { t- ?1 Z#include <DOS.H></FONT></P># n- @; k: Z! F( Y( {" |
<P><FONT color=#0000ff>int main(void) $ [( q" O/ r% E3 [( G, `
{ ) C1 j8 g9 Y; R1 ?4 _. j& H
int result;
; o! g- D/ p6 J# P3 s8 k7 Mint port = 0; /* serial port 0 */ </FONT></P>2 n/ F; w2 ~+ y( T' R- ]! g
<P><FONT color=#0000ff>result = inport(port);
/ c4 R# v4 k) C4 `; F9 f7 Wprintf("Word read from port %d = 0x%X\n", port, result);
" d S1 E$ {6 _+ H7 w! sreturn 0;
# r" Q1 ^) J; o! ^/ c6 a} 4 v6 k: P: |$ J7 N4 m
" t& u* [ ~% o' D! ?
</FONT></P>
. G8 D7 P( s1 L7 w+ L" I8 t<P><FONT color=#ff0000>函数名: insline </FONT>& h6 y' B s1 C. K; l
功 能: 在文本窗口中插入一个空行 + W/ F6 R d* r7 b
用 法: void insline(void); + V1 P* V- H( ^& E$ m) J4 P2 W7 G" s
程序例: </P>" G! z. F7 j1 j8 o+ u" W
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
, D0 u' Z& C* m0 y0 R2 O- ~+ f+ b<P><FONT color=#0000ff>int main(void)
" x% L! [. \0 B7 B{
; b$ B7 V8 c- x4 H! b! Rclrscr();
! j( w. `- h( h9 D# ~$ |. Ecprintf("INSLINE inserts an empty line in the text window\r\n"); ! ] s; V) D' W
cprintf("at the cursor position using the current text\r\n"); " k+ T; d, H# a7 a+ q
cprintf("background color. All lines below the empty one\r\n");
! F. \: u6 z. j4 N* H8 wcprintf("move down one line and the bottom line scrolls\r\n");
; k7 o: x: h; p1 ]cprintf("off the bottom of the window.\r\n"); 8 C5 R2 H0 W- w3 F" u
cprintf("\r\nPress any key to continue:"); : s A. Q" q- g% ?$ n# l) {5 b
gotoxy(1, 3); 8 K3 {1 ]# R# ~
getch();
o- B: m: D; P9 \" c! Kinsline();
) M1 f6 ^" C0 R0 Jgetch();
0 l- _/ s. \" u# c g Hreturn 0;
4 D, g1 o" R( p}
* _( W& J) ~1 f. o* s% @</FONT>, i, R9 C, D9 P9 a* z7 a5 z w
& G( o; V2 ~0 r: C" J G( _
</P>! v2 q: q% K1 B) J
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
' y* P+ K1 m) s# o+ Q功 能: 安装设备驱动程序到BGI设备驱动程序表中 ; H( o+ t2 r, n5 G; @
用 法: int far installuserdriver(char far *name, int (*detect)(void)); ) x" s7 h! P3 r' ?) w
程序例: </P>
8 D) q/ t$ W0 e! S<P><FONT color=#0000ff>#include <GRAPHICS.H>6 K" k- Y( l6 ^. U+ Q7 z
#include <STDLIB.H>
/ K: m9 I2 w6 o#include <STDIO.H>
( n( e% H2 m1 o/ M2 N. l$ K#include <CONIO.H></FONT></P>$ r( K& Z. p. r# q
<P><FONT color=#0000ff>/* function prototypes */ 7 M4 S1 c3 P( R% J( y
int huge detectEGA(void); 9 f3 `; [9 E4 k- t! H. o
void checkerrors(void); </FONT></P>
: U) L* E. R! P+ k4 b. K9 J<P><FONT color=#0000ff>int main(void)
2 u& \! U$ m5 y5 [5 _{
) x* R8 d3 t X% w, _int gdriver, gmode; </FONT></P>
6 q! I$ M0 C4 t7 G8 Z1 S5 B<P><FONT color=#0000ff>/* install a user written device driver */
G- b* r8 K3 v1 Y( y4 f8 ^( F4 xgdriver = installuserdriver("EGA", detectEGA); </FONT></P>+ |% c& O. H+ T/ `! b5 f" u
<P><FONT color=#0000ff>/* must force use of detection routine */ , [1 k9 h0 k$ e r
gdriver = DETECT; </FONT></P>9 m% P- O6 e+ \
<P><FONT color=#0000ff>/* check for any installation errors */ U& Z- f( U3 _ P
checkerrors(); </FONT></P>
0 i: `3 N0 S `3 u4 i3 `& ^0 P<P><FONT color=#0000ff>/* initialize graphics and local variables */ % q+ n) Z! Z9 S) C7 _
initgraph(&gdriver, &gmode, ""); </FONT></P>' J, q' o( J+ b$ i0 O0 B1 C
<P><FONT color=#0000ff>/* check for any initialization errors */ " M) d5 h( i, X: z/ J
checkerrors(); </FONT></P>* z4 G% c% v# j* ^. R. D0 R
<P><FONT color=#0000ff>/* draw a line */ R5 G, w7 a" X- v6 G1 k- I0 f
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
" `) I7 ~% o( \: C$ j<P><FONT color=#0000ff>/* clean up */ ! V% q: g* [- a2 ^
getch();
/ W( ?6 {, z7 u& p4 \" tclosegraph(); 0 F- D& c% ~$ U; _7 p X l- l$ D
return 0;
0 h) _% _% Z6 p; C( q1 t. y1 a} </FONT></P>
8 ^- d0 g* W/ u& y5 {<P><FONT color=#0000ff>/* detects EGA or VGA cards */ 4 [ x+ c; ~- G+ Z6 k
int huge detectEGA(void) ) H7 X+ ~) y$ z( }; ~) k& E. q
{
; G9 Y: ]: N& Q. fint driver, mode, sugmode = 0; </FONT></P>% b' }% E& ^) P! [* J, q) a
<P><FONT color=#0000ff>detectgraph(&driver, &mode);
" H3 {* z$ _" `7 Sif ((driver == EGA) || (driver == VGA))
* U; O0 U6 b% l/* return suggested video mode number */
1 ~5 F. C0 ?. `return sugmode;
- R H* Z' u ]else ' ]- `0 J( j3 G. ^: y
/* return an error code */ 7 w3 S( ?+ U! ~4 t+ V: _9 U
return grError; 9 v8 y; y1 [% d3 c4 [
} </FONT></P>
' _5 i1 |. Q, n" F) M<P><FONT color=#0000ff>/* check for and report any graphics errors */
- C; \' w7 U5 C( b( qvoid checkerrors(void)
- Y0 a+ L- i8 W$ o9 {9 ~{
- l* k, E1 y* M# R- ~- t" Pint errorcode; </FONT></P>
' m. n+ O' ]. X) r& u: D. t<P><FONT color=#0000ff>/* read result of last graphics operation */
; H- L: N; f: L% J- T& Yerrorcode = graphresult();
+ C% P* W' `# L- qif (errorcode != grOk)
5 C1 z, s% `, ~6 n/ ~{ 2 i M) e8 c0 {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
" Q1 }7 H, ]0 h$ ~printf("Press any key to halt:"); $ x. C- u7 B) ^& d2 c/ w4 U
getch();
- }* L1 [% r9 X- m' ^2 g; aexit(1); : m9 O# q7 U+ A$ v! O
} % O* D6 D2 g, e, ^& n8 {
} </FONT></P>
& |* A/ j5 ~6 k2 v7 ^3 I9 ?<P><FONT color=#ff0000>函数名: installuserfont </FONT>
9 @* k. E# {4 r功 能: 安装未嵌入BGI系统的字体文件(CHR) ! I7 L# [0 N [) w0 ?
用 法: int far installuserfont(char far *name);
, B9 e" }0 E/ n9 H$ y) f程序例: </P>/ c9 T3 m) \. Q7 O% Z$ s
<P><FONT color=#0000ff>#include <GRAPHICS.H>2 ~/ D! d4 u2 j1 K
#include <STDLIB.H>& N( ~$ r8 L2 Q( P6 u* H; o
#include <STDIO.H>
9 B \/ ~3 P! {" g#include <CONIO.H></FONT></P>
5 G$ t+ @, e# u1 [. |3 o<P><FONT color=#0000ff>/* function prototype */
- Z0 Z/ v! i& i9 Q* o5 `4 W* [void checkerrors(void); </FONT></P>
' |% b" q; d' }* q<P><FONT color=#0000ff>int main(void) , i/ z4 J/ a" ^% g2 u3 _7 c# o
{
5 i+ `" h" O0 N# h( w- ]' B/* request auto detection */
/ P$ V) K& o/ D; O) Nint gdriver = DETECT, gmode;
p2 q8 E, D- g f j6 x/ Q9 e* i; xint userfont; ) r$ m6 A6 h: Y* A1 \9 T
int midx, midy; </FONT></P>
( ^% Y Y# n6 T1 `<P><FONT color=#0000ff>/* initialize graphics and local variables */ : B0 s* {, m4 ]& \8 C
initgraph(&gdriver, &gmode, ""); </FONT></P>6 _3 h" {7 l; m( D( Y! ]8 q
<P><FONT color=#0000ff>midx = getmaxx() / 2;
, c+ P0 X& C( U5 {4 m7 omidy = getmaxy() / 2; </FONT></P>
6 h& w* D6 ^5 E9 K3 {<P><FONT color=#0000ff>/* check for any initialization errors */
. K5 r4 S" ]+ ]0 D0 p! L e; rcheckerrors(); </FONT></P>
7 A a0 d( ]0 t; o* e+ Y2 ~; u<P><FONT color=#0000ff>/* install a user defined font file */ 9 M' k% ~4 ?7 t4 S$ E# Z
userfont = installuserfont("USER.CHR"); </FONT></P>$ a1 U1 q1 e( X/ `# K
<P><FONT color=#0000ff>/* check for any installation errors */ , D/ l* V+ C" s" n+ L2 Y3 f
checkerrors(); </FONT></P>/ f6 R Y1 Y' \; L$ E7 X
<P><FONT color=#0000ff>/* select the user font */
5 E% _5 m. o1 c0 R; q Lsettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
: J3 M" k8 M" B<P><FONT color=#0000ff>/* output some text */ 7 q. e5 {% i. C7 W8 Q, F% ~" H3 \
outtextxy(midx, midy, "Testing!"); </FONT></P>9 g- o9 e C" c% Z
<P><FONT color=#0000ff>/* clean up */
% u( h! P7 b4 n& H8 E" Igetch();
`, X9 \7 P9 z5 p% ?! u( W% _/ Kclosegraph(); 9 `& O( ?! X7 g% P/ O* C- n
return 0;
3 {4 `1 a- p* {5 c0 y2 [} </FONT></P>
7 o- b1 p, \$ Y( q<P><FONT color=#0000ff>/* check for and report any graphics errors */
7 x2 L5 d3 v. y( }8 _void checkerrors(void)
1 N2 ~4 j4 p+ q+ C, q9 x- J{ a( u4 ?6 |8 ~' ?! k8 d, L
int errorcode; </FONT></P>
9 e4 X# }3 C0 ~4 E, p# Z<P><FONT color=#0000ff>/* read result of last graphics operation */
; O+ M# |% ~% L3 Gerrorcode = graphresult(); ( E8 P4 A% m" h; p- l
if (errorcode != grOk) ' s0 E& z# X( _4 H
{
+ H, x$ m! p% \" V- z3 t0 ?1 Jprintf("Graphics error: %s\n", grapherrormsg(errorcode));
* _9 o4 k3 D. d! c- i# a h: u" yprintf("Press any key to halt:"); * ~1 g) C {2 N+ h9 D& K2 O& W
getch(); * C- \4 W: F) Z
exit(1);
. \/ q/ v8 L) k) c, G} # D3 r# z1 f6 e: C, R4 y' `3 w- o
} </FONT>
k$ {4 p4 I0 ^* _: k; [. z0 i
% J( e, X! W; u" K/ C5 c
) w$ z" z# I$ Q& d% ]</P>( `7 k/ H/ B/ k6 A1 \ w
<P><FONT color=#ff0000>函数名: int86 </FONT>% [: _: R! I8 h9 p
功 能: 通用8086软中断接口 1 o. a" Y6 G1 j
用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs); + R; j' f' J; f, z! q* K
程序例: </P>
9 U p2 l# a3 b( h+ C8 S<P><FONT color=#0000ff>#include <STDIO.H>
3 l6 g- v6 @! Z1 c# E$ {#include <CONIO.H>
% Z6 m; X+ e/ }8 c7 v! S& R! ]+ ]#include <DOS.H></FONT></P>
, k; J1 b9 ]: t0 {<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>
8 t- a- L {3 j: M! u<P><FONT color=#0000ff>void movetoxy(int x, int y)
! {% K a+ L1 P7 s/ ~: P{ ' l. \, v: C; u6 Y1 O+ c7 t
union REGS regs; </FONT></P>& ]2 E! l2 q* Z( t
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
7 u6 {) |, L" ? Kregs.h.dh = y; / Z) h7 w+ x! {( i3 Z& o# k7 J
regs.h.dl = x; / w( v2 X7 ^/ C. \
regs.h.bh = 0; /* video page 0 */ 3 z& h! {0 E/ A
int86(VIDEO, ®s, ®s); 1 ? g. w5 m6 `
} </FONT></P>
. J) x6 y8 F8 o: R B8 o7 D<P><FONT color=#0000ff>int main(void)
' y. b3 u5 @. Y{
0 r: a: Q4 ]0 C( }8 yclrscr();
3 D# ?& N( \& f+ q# V8 _% ]movetoxy(35, 10);
1 \& I7 l5 o L8 iprintf("Hello\n"); 9 l6 O0 t# g& m$ i# _ t
return 0;
& c- t) v) v6 c+ B% r, [2 D, O( l) c+ w} </FONT>5 v. X9 d o! Q# o
; H, U9 d" ?9 B' n: x
</P>7 P, v8 D% b0 M! g
<P><FONT color=#ff0000>函数名: int86x </FONT>
: s( l0 z$ Z2 z6 y: N0 e! b功 能: 通用8086软中断接口 " c3 D, ~( O1 u8 \+ d
用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
2 Z5 |* _! x4 p% H9 C3 e. E/ Ustruct SREGS *segregs); / G' O& o. }" R+ z) ]* z3 H1 N- w& o
程序例: </P>5 C5 b. M3 G! X+ U
<P><FONT color=#0000ff>#include <DOS.H>
. y: e8 A7 ~* t* D#include <PROCESS.H>) W5 W2 A' t; u
#include <STDIO.H></FONT></P>
$ w8 z' d, g* j. M4 H/ a$ F! g<P><FONT color=#0000ff>int main(void) ) B# F: d |8 v; P, z
{
# m$ q" w/ s# g5 B7 j2 dchar filename[80];
" }# D/ L6 W6 Q0 W3 qunion REGS inregs, outregs;
, o" ?/ V+ a7 j" Hstruct SREGS segregs; </FONT></P>9 P- j) S1 ^; B( h; d+ b8 Z
<P><FONT color=#0000ff>printf("Enter filename: ");
; r' r B/ D4 bgets(filename);
# y1 I( T# {/ J+ I: v: y1 Q# tinregs.h.ah = 0x43;
" ? p+ E3 O1 h5 V* \inregs.h.al = 0x21;
3 m: ^, O0 A# M/ g# W( [inregs.x.dx = FP_OFF(filename);
' C/ ?; o8 ]' asegregs.ds = FP_SEG(filename);
4 R. R: s; J, s: Y( oint86x(0x21, &inregs, &outregs, &segregs); + I$ N: C- c! m$ `- U
printf("File attribute: %X\n", outregs.x.cx); , J2 r- Q! g7 P4 a7 z2 Q
return 0;
/ L* x( _& y7 P# @* N} * U# I- g4 A" n5 [: J. k
4 |- o% b/ ?. R- J* f. S
</FONT>( M" L1 X; t& m: o
</P>/ k4 D! A) c) u1 e4 k' a
<P><FONT color=#ff0000>函数名: intdos </FONT>! ^, l6 W7 _ f1 a1 s* z/ r
功 能: 通用DOS接口
& c1 ?! s: o) p3 B+ j- Y用 法: int intdos(union REGS *inregs, union REGS *outregs); 1 t x5 b6 {& T4 l
程序例: </P>- q, J' ^* S# G2 m; O- p' G+ T
<P><FONT color=#0000ff>#include <STDIO.H>
. r4 N# Q* ^0 O! S#include <DOS.H></FONT></P>
6 ~/ A5 F4 M# G2 P<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ ; O% Q2 s6 l# W
int delete_file(char near *filename)
; H% J, c- W S{ . @& Y* I: D+ r+ \. h0 G
union REGS regs; * B, O# k/ R; V3 P
int ret; 5 H% ?8 S: p& E6 A4 \7 T
regs.h.ah = 0x41; /* delete file */ 3 Q2 Z9 ? f9 S: I6 ~2 K# ]$ n j
regs.x.dx = (unsigned) filename; , N- S. d, u/ }1 ^
ret = intdos(®s, ®s); </FONT></P>
- C3 |9 P M5 N9 P+ A7 q* |% x$ q<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
* S4 F3 `+ R& P. M: V* kreturn(regs.x.cflag ? ret : 0); 7 V/ [/ r2 n! }9 j& J- g
} </FONT></P>
1 M6 ?; p) z) k5 G, z% L<P><FONT color=#0000ff>int main(void) 6 }* p6 E* r$ h1 q) {
{
; ?, A) P6 D) E& H6 \- xint err; # R3 e" i g( R0 W. [- p7 x
err = delete_file("NOTEXIST.$$$"); a7 R! z$ t) {* ^2 c
if (!err) 3 p1 b7 O2 b5 P# K
printf("Able to delete NOTEXIST.$$$\n");
. |3 F8 e# G7 m( ?! S$ L celse
! g7 q' | U6 E' Y, u0 T! G; O1 Yprintf("Not Able to delete NOTEXIST.$$$\n"); ! \% ?$ @( a1 k2 v6 R0 n
return 0;
j2 X; b! ?7 `+ k) t$ A/ ^4 o}
g! r3 `9 k9 U- z! C% z- B4 D/ R; M7 F0 _3 o
</FONT>& \* W) k& u6 x6 J- p8 i* G5 T
</P>
3 J9 ]7 Y9 s# l# L<P><FONT color=#ff0000>函数名: intdosx </FONT>
' k/ w& p0 C* {' c6 b3 g) S功 能: 通用DOS中断接口 ' f l# `3 R; d6 n, B1 i# Q3 ]
用 法: int intdosx(union REGS *inregs, union REGS *outregs,
( |& k( F# B$ b' q' K9 Cstruct SREGS *segregs);
. `; A2 n2 D5 H5 A. s/ i2 X程序例: </P>
, ?) A8 a- `% D1 x9 r. p- L+ i; `- `+ P<P><FONT color=#0000ff>#include <STDIO.H>
. Y" M" k! l9 S# q3 u% ?#include <DOS.H></FONT></P>9 _6 e1 H/ O2 Y: T) p: m% f5 ]
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
# @0 `6 [5 M4 Eint delete_file(char far *filename)
. {# t- G$ s8 A{
9 T# c6 M8 q! Punion REGS regs; struct SREGS sregs; 6 o( E" r* D M
int ret;
" y$ q5 L- C- @, m2 F0 Sregs.h.ah = 0x41; /* delete file */
, s0 z+ g" [) |% k `7 z% W2 u; ^regs.x.dx = FP_OFF(filename);
! t/ L( w# O0 L2 N' ^1 @* }* h8 z; ~( Rsregs.ds = FP_SEG(filename);
5 @# h q' o4 R: }# N7 D; Iret = intdosx(®s, ®s, &sregs); </FONT></P>
3 i9 {& t+ r z: x9 E, K z0 d<P><FONT color=#0000ff>/* if carry flag is set, there was an error */ - T! z/ t, N) q7 O) l/ q7 c. K
return(regs.x.cflag ? ret : 0); & F: Z& a6 s: R0 q* }; D' o$ g8 @
} </FONT></P>
! }" w; ?3 y: Z* p2 U<P><FONT color=#0000ff>int main(void) ; G7 P. T9 A% x! g+ j% C
{
" B9 r" Y! I( r5 d9 O7 jint err;
6 k; J, {- X* U6 `3 s; X y# Gerr = delete_file("NOTEXIST.$$$"); ' D8 g7 K1 I z# }$ e+ |
if (!err)
+ t2 R( a# m! f' f5 r' z8 cprintf("Able to delete NOTEXIST.$$$\n");
1 E+ O; w6 G0 k- J& K5 D0 X4 ]else : [( J) t& [$ G7 o* m
printf("Not Able to delete NOTEXIST.$$$\n"); 0 G0 X9 m3 R- D. F
return 0;
/ n# @1 p9 f0 z. C# f7 V) T}
5 ?/ u7 A& Z h& v$ a</FONT>
: G/ {/ b1 l4 d& V</P>7 S4 r7 z; ]% J6 {
<P><FONT color=#ff0000>函数名: intr </FONT>* T( n) t# i/ ] {
功 能: 改变软中断接口 1 U- \- {3 `. y5 i5 i3 g
用 法: void intr(int intr_num, struct REGPACK *preg);
: G" F, q9 R5 N/ x0 h& v- c7 p5 w8 m程序例: </P>! N. S- a) X: u- |* W) [4 {
<P><FONT color=#0000ff>#include <STDIO.H>
% M8 p) v5 I3 M0 `8 W, n* T#include <STRING.H> Q; j( W4 V2 i+ Z. x7 y) X
#include <DIR.H>: \* E& r$ n B/ K6 `& U
#include <DOS.H></FONT></P>( c3 e g0 z2 _3 F3 [
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
j! I/ y0 n, T0 j+ H N0 m<P><FONT color=#0000ff>int main(void) 4 n! X! ]+ S) J4 ]8 u& r6 S
{ $ b- C9 V/ J% H/ _/ l- l' \- p- Y
char directory[80];
( @) A8 n. B) b/ h4 M1 @struct REGPACK reg; </FONT></P>3 h! b0 z1 a5 R* ?* j
<P><FONT color=#0000ff>printf("Enter directory to change t "); 4 X3 _! {, A$ r3 T2 O; g
gets(directory);
; K$ U- p8 R/ }( \reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
2 z/ \* r9 `9 o7 a/ m, A- lreg.r_dx = FP_OFF(directory); # q; h R5 R+ d" R7 B* R$ s- O& V
reg.r_ds = FP_SEG(directory);
# ?; X% i% o5 E" G s. vintr(0x21, ®); / K7 B. I! {; x0 p6 O& n. R
if (reg.r_flags & CF) 2 F3 ], | T! C. U. D S9 p
printf("Directory change failed\n");
5 Z. n0 M8 O( F, M: s. tgetcwd(directory, 80);
; U. z# R" d: T3 bprintf("The current directory is: %s\n", directory);
4 b8 p4 ]' Q% e& J$ e7 V& ^; wreturn 0;
9 t% A! U) o; r! H9 |4 t}
0 T5 ~4 G; h& \* N/ K</FONT>
5 M7 X/ H0 R1 {</P>
9 j9 B7 ]2 e! j- N<P><FONT color=#ff0000>函数名: ioctl </FONT> [: L t& i: j9 i
功 能: 控制I/O设备
+ h3 d. g# X* }( y) J- U用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
# i5 N7 m6 T7 q4 R6 q. R程序例: </P>5 x( E+ B4 h$ b; c
<P><FONT color=#0000ff>#include <STDIO.H>- x. P& ^7 S2 s* [/ G) O4 X
#include <DIR.H>
2 y) Z9 }! M- c- c9 X; L#include <IO.H></FONT></P>! a( Z% Z5 V3 b" k. L8 n2 S
<P><FONT color=#0000ff>int main(void) ( @/ m, j* S$ q5 I4 g
{ 8 t4 }8 _: L2 } J4 N5 f
int stat; </FONT></P>
+ ^* k! J- s3 @, z! b: l<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
! _4 W! U; U& d5 z6 v9 _5 B4 xstat = ioctl(0, 8, 0, 0);
( u% I. D. @: O9 S2 [* u) Dif (!stat)
9 O8 j+ ]" t4 _ i: c/ {. i) Eprintf("Drive %c is removable.\n", getdisk() + 'A');
& v Z2 z7 K( @- v0 [# X4 N+ `4 zelse % |7 r( H. h8 p" O) l% T
printf("Drive %c is not removable.\n", getdisk() + 'A');
0 t/ Q% X4 Y6 p0 hreturn 0;
$ x' R6 e; n3 E. B3 w5 c7 R, A} 1 {/ r& B9 ^3 K- R( M6 G. z
8 U, D/ p$ c8 j% F/ _, R
</FONT>
0 \& q0 o, \) W( [* C</P>
; h% e; U$ ?* @# d) D+ u<P><FONT color=#ff0000>函数名: isatty </FONT>
/ c: J5 J+ J" ~( l9 m6 Z功 能: 检查设备类型 4 [( A% Q# g F2 r* l( p
用 法: int isatty(int handle);
) Q4 J% _8 p2 e. t程序例: </P>$ h% P4 c8 R& L7 E, X
<P><FONT color=#0000ff>#include <STDIO.H>
s- r6 ^2 V: U+ B! j% g6 u#include <IO.H></FONT></P>: J. ^2 ^" @% }; @9 U
<P><FONT color=#0000ff>int main(void)
! U4 F) }% K/ A, F; x2 B{
% \9 _8 l! m Q4 g" T% Z2 `int handle; </FONT></P>
, I) B) }+ p1 C/ C, n6 F/ K<P><FONT color=#0000ff>handle = fileno(stdprn); & ?8 C2 J9 B# p! w6 {
if (isatty(handle))
5 p1 \( |1 b- @& a: ~2 Hprintf("Handle %d is a device type\n", handle);
) I$ u: `5 I6 e$ J3 B# T) p9 p! Belse % m1 X+ C: P6 O* ]. P* Z& d3 y1 T/ x
printf("Handle %d isn't a device type\n", handle); 0 a- _3 ]8 J: t# ]9 {2 r9 b; X
return 0;
9 I% c5 |9 G; S9 l) ?8 F- j} % B) _5 J Q2 n
+ z) Q. d f- J/ r( S v/ x
</FONT>
' k$ @4 @/ }, [1 z0 M</P>5 ^* ?1 I8 d+ S8 z
<P><FONT color=#ff0000>函数名: itoa </FONT>
9 J" c! E+ {% X3 M( b1 J7 k6 p功 能: 把一整数转换为字符串
( a% z3 p+ N& U8 E( @用 法: char *itoa(int value, char *string, int radix); & M7 S* Y* r% H
程序例: </P>4 c2 f4 y3 l2 I e
<P><FONT color=#0000ff>#include <STDLIB.H>
; A9 J( B& M3 \#include <STDIO.H></FONT></P>
* q8 I! F9 h9 U) G6 c/ e3 {2 @<P><FONT color=#0000ff>int main(void)
6 |6 M2 O9 g+ u. r7 C9 P, o6 g{ & n2 ]& m, U) i5 ~4 M6 {% ^( X
int number = 12345; . ^) Z, h. k1 I! h4 @
char string[25]; </FONT></P>
/ n) l& ?7 x% K6 r. A3 o<P><FONT color=#0000ff>itoa(number, string, 10);
/ E4 L& D0 W7 r; s' ?# }9 M0 {) mprintf("integer = %d string = %s\n", number, string); + n% d" N" L6 P+ p) j( i
return 0;
$ B8 Z% i: V/ l} </FONT><FONT color=#0000ff>
3 x" |" A8 {* w6 S N</FONT></P> |
zan
|