- 在线时间
- 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>! s; v* K* i6 K ^
< align=left><FONT color=#ff0000>函数名: imagesize</FONT> / N* g+ b! B$ Z, J# R# k9 |
功 能: 返回保存位图像所需的字节数
2 E/ J- Y( L& n! L9 ~' D用 法: unsigned far imagesize(int left, int top, int right, int bottom); ( ~! F& C5 Z3 g0 E* M: v
程序例: </P>
5 n- ?( @! F4 `! T* |. j* }< ><FONT color=#0000ff>#include <GRAPHICS.H>
6 q& W1 v7 L' {# e2 V#include <STDLIB.H>
1 }- z1 W" I9 ^, [( m& O#include <STDIO.H>
' x! Q6 o2 t: n; m; L# s#include <CONIO.H></FONT></P>* a- a, M i+ g* y
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>' t h; q+ a) ~8 Y
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>0 P8 \" I: U+ y& f+ D
< ><FONT color=#0000ff>int main(void) 1 C8 ]; S6 e; Z
{
2 W7 i% m/ w# ?8 x" [% S. V/* request autodetection */
, X" K- h% i: r% qint gdriver = DETECT, gmode, errorcode;
3 Z9 m5 c* K5 J5 Mvoid *arrow; 0 X: Q. {- `' _" S- ]) o
int x, y, maxx;
0 X' v% M0 s5 dunsigned int size; </FONT></P>
9 ~, c) m5 n4 J1 h( p9 v1 E< ><FONT color=#0000ff>/* initialize graphics and local variables */
6 Q# u0 L) T9 k s9 G% J- u" Kinitgraph(&gdriver, &gmode, ""); </FONT></P>9 A' t+ d8 ]7 }3 G$ d
< ><FONT color=#0000ff>/* read result of initialization */ & y7 d4 }+ Y, ]/ \/ K
errorcode = graphresult(); % Q9 S: J: p( ^
if (errorcode != grOk) /* an error occurred */ + v8 D8 f9 |8 ^# ^8 m
{ / ]2 r4 {. a6 P6 H
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) I! |: D) s& D/ z; w! @& R
printf(" ress any key to halt:"); % O! U; Y; E+ S7 w# J
getch();
; o$ J Z* d1 R# O* z K! Kexit(1); /* terminate with an error code */
* @* P X0 [8 `/ ?- E! _} </FONT></P>2 o. W" U9 `( F& s6 n1 x2 H
< ><FONT color=#0000ff>maxx = getmaxx();
& x1 ^/ t+ P5 M: Fx = 0;
, G( ~( E9 o' Q. Dy = getmaxy() / 2; </FONT></P>
& o7 v- ?9 H7 F- d< ><FONT color=#0000ff>/* draw the image to be grabbed */ j/ p, r$ \7 I8 j. f
draw_arrow(x, y); </FONT></P>* S+ c$ m* @* O8 R% f! @% N% U& t) b
< ><FONT color=#0000ff>/* calculate the size of the image */
! s, Q- | d8 H- G, _2 R4 Gsize = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>" ]; j, m) m. S( {/ a
< ><FONT color=#0000ff>/* allocate memory to hold the image */
$ J4 i3 U! t S' \$ earrow = malloc(size); </FONT></P>/ j: G7 L) c4 F7 u, N
< ><FONT color=#0000ff>/* grab the image */
6 M! k% D6 G! I* R1 r% w/ Ogetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>
! ~" I/ |) L: z- r7 J< ><FONT color=#0000ff>/* repeat until a key is pressed */ 5 j7 _) g& \: B7 D: n
while (!kbhit())
% t0 [& B& E/ A{
5 S- L1 n( J* r: c' J/* erase old image */
/ L$ P4 Z. Z( v+ W1 u! hputimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
4 _7 R. @1 n- |% z< ><FONT color=#0000ff>x += ARROW_SIZE; . n; _, T. t- v
if (x >= maxx)
+ M2 h5 E$ Z" C+ ?3 ax = 0; </FONT></P>
1 @- P: f2 }; u, R1 F< ><FONT color=#0000ff>/* plot new image */
7 _8 x+ F6 W. [3 o, W+ P3 q4 fputimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
% O1 @5 z3 V# x: z} </FONT></P>
" E& m5 z+ w! I< ><FONT color=#0000ff>/* clean up */
& @$ U7 j2 b9 A) y& M0 Afree(arrow); * n$ @ t6 i/ ~& D$ ]$ R9 ^6 D' c
closegraph(); 3 ~( w/ x$ I7 u5 Z* G2 T
return 0;
6 f" \- V0 I6 O2 ]2 H3 K3 a$ C* R} </FONT></P>
5 o: `) F9 ]/ W' L7 K* o0 h< ><FONT color=#0000ff>void draw_arrow(int x, int y)
$ [( ]$ i% s2 G' j0 O{
+ O# A8 ?/ j s% @) G1 N. i- Z/* draw an arrow on the screen */ ( Z2 M8 g/ A- j
moveto(x, y);
. a& { D5 r- F9 h, c6 [linerel(4*ARROW_SIZE, 0); ! K& T3 p0 z7 S8 u+ N$ ]1 o/ x3 K
linerel(-2*ARROW_SIZE, -1*ARROW_SIZE); , t7 D, c; |* j( k3 Q
linerel(0, 2*ARROW_SIZE);
# f" J( p v* u U1 P. x+ ~linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
# g, S5 w3 J4 l# X8 D9 t) r}
) z8 k! k$ c7 S* p W8 x8 E/ r. S: Y2 e) g0 ]& b
/ K6 z# G: k/ m9 [
</FONT></P>
/ u; @. B x+ A' } u- F4 c< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff> }+ J, \# W1 T/ a# {' a& v
<FONT color=#000000>功 能: 初始化图形系统 & o( @: u$ W% Y4 ^ P8 ^: e' J
用 法: void far initgraph(int far *graphdriver, int far *graphmode,
+ Y+ |1 ?- t1 ?char far *pathtodriver);
p# e1 a+ d0 G6 k! O0 M程序例: </FONT></FONT></P>& A% ?3 E6 d7 b g
< ><FONT color=#0000ff>#include <GRAPHICS.H>
$ G2 L7 U0 i6 T" U#include <STDLIB.H>
7 n& f M8 S( L; m9 ~#include <STDIO.H>
u) C+ u7 x. y! q. l#include <CONIO.H></FONT></P>% M' _8 Y( `9 W" K! V7 ^, _3 O
< ><FONT color=#0000ff>int main(void)
# W5 x, I6 Q* t- _{
F9 r4 a& \1 D0 f; k! k/* request auto detection */
$ |8 H% x7 U: \5 `: F$ Sint gdriver = DETECT, gmode, errorcode; </FONT></P>" i& U2 _& }, P' [: L* ~
< ><FONT color=#0000ff>/* initialize graphics mode */ 0 x# J3 N8 M5 m# `, D! j
initgraph(&gdriver, &gmode, ""); </FONT></P>9 i) V! f8 z, {$ ?4 L
< ><FONT color=#0000ff>/* read result of initialization */ + ?+ P6 O5 m2 }" M
errorcode = graphresult(); </FONT></P>
' M3 e" W. l" ?; f: |% `< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ ! D2 q" K% W, \2 q3 k* X' l! |
{
1 r0 D# Z, g# B1 xprintf("Graphics error: %s\n", grapherrormsg(errorcode));
1 j0 c- d6 V7 m# o5 K0 xprintf(" ress any key to halt:"); 0 s; q% Q) @0 W4 a. |5 j* w& h9 w3 ^
getch(); 5 @* h8 q5 i5 [2 ^( k# n5 H
exit(1); /* return with error code */ . r9 `4 F$ G* S1 h' V" P: w) H0 ~
} </FONT></P>2 U' U. h1 G, {7 C+ s$ p
< ><FONT color=#0000ff>/* draw a line */
; ^7 R& L, w0 |' F& hline(0, 0, getmaxx(), getmaxy()); </FONT></P>8 e& G! s' b4 e) `4 ?
< ><FONT color=#0000ff>/* clean up */
, q' R+ F0 p3 n) j( I; q8 sgetch(); 4 a9 C" ^/ S1 V8 M& t% I# E
closegraph();
5 }1 V3 M. L4 v5 ?8 C" hreturn 0;
4 |0 Q: u6 Z" q} </FONT>
+ U/ t2 X, `0 x/ x9 V6 k4 R+ \4 m' I; W5 r9 \
</P>
* r' X3 P6 b4 l6 k, s' R< ><FONT color=#ff0000>函数名: inport </FONT>
8 U2 X8 I# I3 v5 w8 @) V功 能: 从硬件端口中输入
" @- {) Q' K0 L4 d( K. e0 L用 法: int inp(int protid);
' {) I9 k# v: f7 s9 c, ]程序例: </P>! x/ D4 \$ y) T( `3 J
< ><FONT color=#0000ff>#include <STDIO.H>
" \/ }4 i3 d7 u# _( b2 `#include <DOS.H></FONT></P>! j: m2 ]! z/ N# a; o, y1 G5 L
<P><FONT color=#0000ff>int main(void)
- ^: o& Y7 _: @{
4 }' k" `0 P2 [+ l% aint result; , |: |* L' N( \8 ]. E1 r. F
int port = 0; /* serial port 0 */ </FONT></P>! s/ e; f0 o, \' T3 q; Y( V
<P><FONT color=#0000ff>result = inport(port); 4 S2 L5 {4 e% f" V
printf("Word read from port %d = 0x%X\n", port, result);
9 C4 }/ U, N$ \5 a6 _/ a4 T4 z" creturn 0; ; G/ g$ n/ c9 e7 a) J1 t, j
}
4 u |# Y4 P' M- J, d& z# p+ g: G! c; g4 u+ `5 o& L7 U( f
</FONT></P>$ @7 l& u! k3 z7 D( w: P" K
<P><FONT color=#ff0000>函数名: insline </FONT>
; k5 U/ Q, N( F1 F: h# L# m功 能: 在文本窗口中插入一个空行 + v( G" x/ y& w' K/ B
用 法: void insline(void); / n8 r$ r$ w$ X- |
程序例: </P>
: N0 u5 o% m+ S4 {, z2 l0 h<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
1 k2 J7 }8 W! D( y: I2 k<P><FONT color=#0000ff>int main(void) 1 x9 Z- d% ~% g. N: N9 a# s
{
& X, r" u: O9 J% p5 m' M% cclrscr();
" l; H( M/ ]5 j3 W9 z0 x6 I" a: E- ?cprintf("INSLINE inserts an empty line in the text window\r\n");
+ l( S) g+ L8 x$ R7 j% W1 h. Pcprintf("at the cursor position using the current text\r\n");
/ P( R0 H! c9 o+ j9 \4 j2 M% E. Acprintf("background color. All lines below the empty one\r\n");
4 C, N9 t0 t5 L7 l/ [cprintf("move down one line and the bottom line scrolls\r\n");
; Y$ m, `8 g1 O# u& |7 [1 ~, `. _cprintf("off the bottom of the window.\r\n");
9 `# }7 M6 R/ ^8 x: q0 x- Z4 o8 ocprintf("\r\nPress any key to continue:");
; t( H- u2 V# y! ?% _: q8 Y" w7 p9 @- ~- kgotoxy(1, 3);
" }2 \0 n7 A1 c9 q, Q% B. _9 ?) rgetch();
6 X$ A; m J- A9 x, r" Oinsline();
. p: t; x- \. S$ S: w1 Vgetch();
7 l. F8 M$ k5 C8 E1 p1 q8 J' F. @return 0; : K& i, X; c7 l; O# W; K/ o: Z
}
. [. C6 D1 J# O" v</FONT>' s7 ]5 b0 p Z% q d: L3 D
/ z6 l( P5 I9 [- [- N/ g
</P>4 x* k+ ?9 b5 l( _2 N+ M
<P><FONT color=#ff0000>函数名: installuserdriver </FONT>' u- q9 H- h& M3 I" n4 B$ l
功 能: 安装设备驱动程序到BGI设备驱动程序表中
) V! b4 k5 }& q3 k! I用 法: int far installuserdriver(char far *name, int (*detect)(void));
! k* C/ o6 J% ^% a/ K1 _- ]* ~程序例: </P>
$ O6 E) s5 h$ O* v2 B<P><FONT color=#0000ff>#include <GRAPHICS.H>
" X0 |" y. {3 N6 f7 P, J#include <STDLIB.H>
' U/ q# u) [. O0 m2 H' c( z#include <STDIO.H>
9 W' s8 C, i) n) h# a, }! v#include <CONIO.H></FONT></P> }/ Z. y6 G3 l
<P><FONT color=#0000ff>/* function prototypes */ & B5 v+ V6 B! J- G$ e
int huge detectEGA(void); ' `0 l9 ^: a& w9 r, E
void checkerrors(void); </FONT></P>! Y: { P$ r* Q% n/ ?2 A+ V; A$ O
<P><FONT color=#0000ff>int main(void)
* ?7 E( o8 K! v3 W. ?0 g{
8 Y& I, F' X! k7 Y3 n- K2 Vint gdriver, gmode; </FONT></P>
( A5 i* w0 i8 J0 }3 ~. X* z<P><FONT color=#0000ff>/* install a user written device driver */ $ y# Z6 q2 }( f% r+ b: h) [; y
gdriver = installuserdriver("EGA", detectEGA); </FONT></P>
6 K7 O3 A! S8 S: j9 e- t( s<P><FONT color=#0000ff>/* must force use of detection routine */
& p6 Z A9 l7 Vgdriver = DETECT; </FONT></P>
0 L' Y3 N& l: X+ y# j<P><FONT color=#0000ff>/* check for any installation errors */
+ C+ Z. r( a S( s* ~ ], y6 Ncheckerrors(); </FONT></P>2 |5 E/ O3 F3 O3 M
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; N5 Y5 h! r& D1 n' ]
initgraph(&gdriver, &gmode, ""); </FONT></P>& x, m, L% Z- w. Q; ?
<P><FONT color=#0000ff>/* check for any initialization errors */
; y2 v4 k2 _- C) O$ {checkerrors(); </FONT></P>
$ M5 L" a7 g1 e9 `<P><FONT color=#0000ff>/* draw a line */
- Q1 v- S! G) U( i! F: c- i) Eline(0, 0, getmaxx(), getmaxy()); </FONT></P>9 i D+ ^4 b( Y. s# [
<P><FONT color=#0000ff>/* clean up */ 3 V+ Z" i; i/ `# ]: v
getch(); ) t+ [1 d. M# R" h4 r3 V
closegraph(); 9 V @+ j1 H7 N Y$ o
return 0; 1 @& ^3 X9 _. l: x$ j4 P5 d
} </FONT></P>$ p, ?' {4 O7 {$ Y. A
<P><FONT color=#0000ff>/* detects EGA or VGA cards */
9 t: Z! W0 ^: O% f5 v; ?; `int huge detectEGA(void)
& G2 j" C9 }0 Y; {. x b2 [: j{
! D1 i9 A: M, @+ D0 V/ aint driver, mode, sugmode = 0; </FONT></P>
6 u& [; n/ ?) i, D<P><FONT color=#0000ff>detectgraph(&driver, &mode);
) k4 Z/ j0 ]& H8 ]! Qif ((driver == EGA) || (driver == VGA)) * z# A" H( N* }
/* return suggested video mode number */
' V) ]" R7 v+ D0 x5 Kreturn sugmode; ; x) p w6 j" {( Z* s- f$ M/ b
else ! L" @% I4 I U/ X, v5 W
/* return an error code */
/ ?3 h* f7 u& {( Nreturn grError; , k& T# U* J* Y: X' y2 R% j+ {0 k
} </FONT></P>
1 g3 i$ s7 r/ ~( }' V<P><FONT color=#0000ff>/* check for and report any graphics errors */
# G1 ~7 l* l* m2 v% Lvoid checkerrors(void)
+ J- \) V' m% z6 C7 z{
" ~$ A+ E6 I2 b9 x9 ]9 Lint errorcode; </FONT></P>
7 A: x, B% M5 P& ?2 `/ C<P><FONT color=#0000ff>/* read result of last graphics operation */
) @* s* [, ^0 `% zerrorcode = graphresult(); 5 A* N. J) T; Y: o+ a6 H$ L( k
if (errorcode != grOk)
1 F( W( d1 c1 m1 }9 m: O{
l. w( N3 z1 O( u& g8 Q2 l3 R+ A2 Zprintf("Graphics error: %s\n", grapherrormsg(errorcode));
9 w8 {# c8 v3 k( w) e5 Y; Q$ r% Sprintf("Press any key to halt:"); % U, \* c" q4 R5 f% r, F, A
getch(); u0 z% J+ U& S* K* o6 \6 `" \- h) @, X
exit(1); ~; P5 l% V! b6 }. n
}
, ~; h! u) @- E0 X: W; X- u; j# f3 [} </FONT></P>9 b+ x7 f/ G3 I) N& U% s8 j, d
<P><FONT color=#ff0000>函数名: installuserfont </FONT>
, h) o4 J1 {3 ?" ?6 X% \6 w功 能: 安装未嵌入BGI系统的字体文件(CHR) 6 y o% d5 ]% Y# p: w
用 法: int far installuserfont(char far *name); . b! t$ r4 A6 H/ `
程序例: </P>: m; r- ]+ g8 W/ M, }0 F: W& O* U$ h5 a
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 P, m8 r+ v9 v2 H3 d: S! v; S _#include <STDLIB.H>
5 @% X$ g: D. ]. G [" Z1 q2 @5 H#include <STDIO.H>4 a6 I3 Q5 s( E6 D
#include <CONIO.H></FONT></P>2 s. d$ J8 B- f2 {. L: I
<P><FONT color=#0000ff>/* function prototype */
% v! C$ s8 W% c/ @: ~* `void checkerrors(void); </FONT></P>
2 G* i) |& G9 R: j$ c0 B5 |! I$ E<P><FONT color=#0000ff>int main(void)
& \" D; e4 E- R' e$ H: A{
3 {5 ]- Z4 h2 S9 s4 l$ S& b/* request auto detection */ 8 ?# ]1 D* m& ^
int gdriver = DETECT, gmode;
# t# V2 I; M2 \( o- Zint userfont; , A2 k( F* ^+ y9 P+ _3 }" h
int midx, midy; </FONT></P>
# _4 d$ j, u" U5 m' s<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 k( v5 B x* M+ c' P! y Qinitgraph(&gdriver, &gmode, ""); </FONT></P>: ~9 k# `& P5 o: H, z: b5 w
<P><FONT color=#0000ff>midx = getmaxx() / 2;
* K2 }6 V5 ^* I' l0 q. amidy = getmaxy() / 2; </FONT></P>% a) L2 E! u* S' d. T
<P><FONT color=#0000ff>/* check for any initialization errors */ ( d4 f% c& B$ f" R
checkerrors(); </FONT></P>0 [% W4 n4 \. G
<P><FONT color=#0000ff>/* install a user defined font file */ " }; ]: x# e t2 w. ]. D( v
userfont = installuserfont("USER.CHR"); </FONT></P>
+ i: d6 @! g- i l8 N<P><FONT color=#0000ff>/* check for any installation errors */
" w& O& w! C* v3 \2 i5 V; O2 Zcheckerrors(); </FONT></P>* \* r: ]; Z. }% U' {
<P><FONT color=#0000ff>/* select the user font */
5 ^ O/ U/ r( v( u- Xsettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
. M0 l3 w W; E4 d; j; u<P><FONT color=#0000ff>/* output some text */ + E, Q1 u: c5 L) K) n
outtextxy(midx, midy, "Testing!"); </FONT></P>
+ \) p0 H: x6 C0 B. V1 B7 V<P><FONT color=#0000ff>/* clean up */ ; B0 g) N: n- S1 q
getch();
$ m @+ t/ k- H9 K, {( }& f0 ?closegraph(); . s# e- X* M. h# F
return 0; 9 M' g5 W' _9 D) m+ Z% N! k/ T
} </FONT></P>
7 { {' f( ]- @% }& S<P><FONT color=#0000ff>/* check for and report any graphics errors */ 1 g- G" [& Y. W
void checkerrors(void)
: C. g3 r, h# v/ e G{ 8 D7 R }0 ^: H& o' y5 f8 N0 I i3 r
int errorcode; </FONT></P>
+ ~6 N+ c! F( k# C1 |<P><FONT color=#0000ff>/* read result of last graphics operation */
& R- D) k/ N; }5 d% s1 h1 Q, J5 O1 ?errorcode = graphresult(); $ C' M- Q# j6 y4 |/ M5 x: d
if (errorcode != grOk)
. T- O* \0 F! M* u4 s; ~{ ! y: n: ~6 z8 u$ l* G& Q8 N
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 e4 C3 [) ~- w7 Kprintf("Press any key to halt:"); ( N7 c" ?2 i/ L6 \+ K
getch(); * r1 q+ D( n8 J. D. | {
exit(1);
! j2 }3 R( d6 @+ F' o* J+ h8 b$ |4 d} 9 D+ ^8 I+ Z- L: a: x- u6 y8 A1 |3 {
} </FONT>" G d. i2 L, j1 E! l2 B
' a8 J8 d- H. ^% o, v9 m1 V
0 @1 w' c ?$ A% w# U1 F
</P>
% a6 G& a( }; V6 Q" `3 P1 x<P><FONT color=#ff0000>函数名: int86 </FONT>/ W5 _, _" t" s$ }) b! g
功 能: 通用8086软中断接口
# m: w! g4 d( o8 b! E7 `用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
& e4 S- q+ Q, s! _# \" w, s程序例: </P>
& g( G& {8 u4 V6 Y. U% x+ i<P><FONT color=#0000ff>#include <STDIO.H>
7 B3 W, R) U( P9 r# d" s#include <CONIO.H>% l: k6 O- I4 [9 [$ ]
#include <DOS.H></FONT></P>
8 h1 \( c% o7 e<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P> C7 a( R' x+ C8 D2 o5 p& L
<P><FONT color=#0000ff>void movetoxy(int x, int y)
g" |7 V& y& U3 N3 v/ U, |{ 7 c* p" c6 t$ `( h; C' w7 ?
union REGS regs; </FONT></P>$ j. n5 N) h" e4 L
<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
" @" {1 v" ~( {/ b* d2 iregs.h.dh = y;
4 d$ A, |' d# }: {regs.h.dl = x; ! r8 B1 @$ @$ a2 R; {9 f
regs.h.bh = 0; /* video page 0 */ ! ~+ K5 w% _% A0 h
int86(VIDEO, ®s, ®s); : X f6 o" }1 z9 F y
} </FONT></P>
- G _9 |1 |4 [0 G$ D5 R: F) b<P><FONT color=#0000ff>int main(void)
[( [6 f3 k; `: }6 i+ A" Z" H{ 6 X- _* Y+ ^6 L+ y
clrscr(); ! ]& B5 u1 {* l, z2 r
movetoxy(35, 10);
7 ^9 Q$ u" H( }7 f" b% zprintf("Hello\n"); 5 Q1 R2 m/ {# X: H9 u$ `
return 0; 9 X. ^6 l0 f3 |$ \5 Q5 M0 s
} </FONT>
6 v/ t9 a }+ q) f# M5 H% T" {- a6 H/ C/ e2 S" F
</P>- x! l. c, u2 M' x/ [
<P><FONT color=#ff0000>函数名: int86x </FONT>0 Q. Z3 y0 E7 g E: ]' f6 }8 c, |
功 能: 通用8086软中断接口
0 Q9 V' i( f/ |; p9 s用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
0 a( z6 y, I8 P% n* Z8 Ostruct SREGS *segregs);
% N6 j( O9 l" ~1 ^6 I, j程序例: </P>
* Z; v) [+ w. A0 U: e# q$ i3 l4 [<P><FONT color=#0000ff>#include <DOS.H>
$ H% u8 v+ z( K, l#include <PROCESS.H>( l7 H3 o9 M1 K% c2 [5 N5 g
#include <STDIO.H></FONT></P>
4 W9 `4 I/ W% I( O<P><FONT color=#0000ff>int main(void)
! t/ _7 z6 L ?7 R4 m* ?, K$ Z{
~. o1 o6 U$ q o) Y2 f* ~char filename[80];
# y6 l/ r- I1 f$ P9 cunion REGS inregs, outregs;
7 b' N; |7 t& xstruct SREGS segregs; </FONT></P>
9 u6 n3 Q9 j; W) H* y) S<P><FONT color=#0000ff>printf("Enter filename: "); & v- {+ V; | Y8 @4 }( b& p7 P4 c
gets(filename);
0 Z8 U8 _' q2 [ ginregs.h.ah = 0x43;
) C0 {( @. H( @# V8 \5 V; N2 Zinregs.h.al = 0x21;
7 M! L0 X% |6 j0 \/ Ninregs.x.dx = FP_OFF(filename);
0 s" W# S3 h8 Y T. s8 t6 Dsegregs.ds = FP_SEG(filename); & G( i/ B+ M# d! j) r7 F# L
int86x(0x21, &inregs, &outregs, &segregs); ~: U+ M* R8 V. K' [# P
printf("File attribute: %X\n", outregs.x.cx);
$ d0 v( h8 s4 D) c; R) S" \7 D/ Treturn 0;
; [7 o" J$ [ J5 c8 {! O}
+ Y/ [1 |+ q; R8 z4 [% j2 {( Q
% M$ G6 h6 H, }/ ?</FONT>/ D3 K3 d, \- `6 G
</P>
- S3 x3 a/ o/ M1 I9 c* @<P><FONT color=#ff0000>函数名: intdos </FONT>
6 I3 O2 @5 ]. A! {# m- ]0 U功 能: 通用DOS接口 3 S7 \3 y u9 W$ @# G
用 法: int intdos(union REGS *inregs, union REGS *outregs); 7 t5 L0 C3 o4 K+ b$ x9 S+ j
程序例: </P>+ V# K3 r' P* I. i5 x
<P><FONT color=#0000ff>#include <STDIO.H>
+ Q) D5 p9 Q& I! L6 h6 o#include <DOS.H></FONT></P>! A& ^. ?) `4 b7 b2 ^
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
' s, B9 W5 L6 Tint delete_file(char near *filename)
! a: q; |0 Y& V8 J. h{ 7 r* u2 [1 t& y# U+ g, A1 i
union REGS regs;
9 R( x, G; z% v5 O7 a, |int ret; # ]( {. p. c) R0 H0 X
regs.h.ah = 0x41; /* delete file */ s( R% s/ h2 H) I" b5 I
regs.x.dx = (unsigned) filename; 2 M; J8 E( u- ]! P8 M' Y
ret = intdos(®s, ®s); </FONT></P>1 c1 L: b; R) u4 k( W! T
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
0 M0 w) h. K, z" G. u8 Treturn(regs.x.cflag ? ret : 0); : Y2 \- M6 {( _- ^/ A
} </FONT></P>
% h) Z9 ]# U7 p3 [& g' p<P><FONT color=#0000ff>int main(void)
e/ ]7 {$ a& Z% p{
6 }1 O$ U! ?' Y" C; z. V2 @int err;
: B9 B: o( J5 X; V zerr = delete_file("NOTEXIST.$$$"); 3 _' [; L5 B& G' z; q# t X
if (!err)
% D$ T9 k; q y# [printf("Able to delete NOTEXIST.$$$\n");
I$ `: u3 [* B8 c' celse
3 d4 F @. T2 R1 R* C `printf("Not Able to delete NOTEXIST.$$$\n"); $ U, B1 s' v; h/ x- h7 Y% S3 D% C
return 0; - I, _8 x! p' ?9 \7 q% H
}
3 p& N1 m4 b% m2 R! o' a
9 _3 [% T, O5 X$ W</FONT>: O( _9 |/ C- ], _/ Y: a) f
</P>" ~) {% l# C2 G8 h, f; y* O
<P><FONT color=#ff0000>函数名: intdosx </FONT>- I% f* X# d$ H R
功 能: 通用DOS中断接口
( m' n- [4 j0 H& I8 D3 s用 法: int intdosx(union REGS *inregs, union REGS *outregs,
- q5 e8 x6 T8 {6 D# r/ m# v4 qstruct SREGS *segregs);
+ X6 P+ u% E) P3 S& ~: I0 H* n程序例: </P>; m. D9 U. ?- a Y6 Q3 A
<P><FONT color=#0000ff>#include <STDIO.H>: L3 Q( E9 A. O
#include <DOS.H></FONT></P>4 V! ^% c% \4 i* X7 i8 n |, S
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 7 c( R _. Z* f. U" R/ b
int delete_file(char far *filename)
, g9 z% Z, e; r! X, z$ u4 K{ 7 x ?7 k3 P8 @4 A
union REGS regs; struct SREGS sregs;
& {6 x8 a; k; }) b8 {: o) jint ret;
. s; |8 i: M" T+ wregs.h.ah = 0x41; /* delete file */
n' F, _* u/ a2 S" Z/ Yregs.x.dx = FP_OFF(filename); ) y/ ]0 G7 F5 ] S+ |
sregs.ds = FP_SEG(filename);
! Z6 N$ f) P4 N0 j: g0 _% j A0 gret = intdosx(®s, ®s, &sregs); </FONT></P>4 c4 D/ d ?; j( U6 q$ g
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
9 F) d% d, h" J" f; ^& dreturn(regs.x.cflag ? ret : 0);
. [: ]; ~* {# {$ ]) F1 r} </FONT></P>5 e2 u4 Y7 c( d0 j3 y; a
<P><FONT color=#0000ff>int main(void) 7 w4 G4 B7 \2 Q
{
* O; W8 {$ ^( e E7 pint err; ) y2 }. ?7 c6 l( I
err = delete_file("NOTEXIST.$$$"); 6 |4 z5 X3 [$ @0 i* P1 a/ l/ e
if (!err) ' }& ^0 y5 D- ?- [" k) n9 k
printf("Able to delete NOTEXIST.$$$\n"); + V6 N1 b$ n( D( { p
else
4 M5 \2 E6 X6 k+ X* | @0 qprintf("Not Able to delete NOTEXIST.$$$\n");
9 S) p6 V* l$ p' ?0 P+ N. R6 freturn 0; 9 W( O# \: A$ Q4 l: }+ H ]
} ; E) k' h' p6 x" t( y
</FONT>
7 g; ~" s$ K6 A( K( `5 _</P>
+ d- r, n' {4 n/ l<P><FONT color=#ff0000>函数名: intr </FONT>& f4 z8 _6 s2 j
功 能: 改变软中断接口 6 f! I) d8 J5 e: Y* F
用 法: void intr(int intr_num, struct REGPACK *preg); & Y; c& f9 N3 B2 a0 y' E1 s. \
程序例: </P>
! k& O D8 |1 e7 I& Z5 N<P><FONT color=#0000ff>#include <STDIO.H>( B1 v" j, f" q
#include <STRING.H>" G9 J% H4 E; ?. b1 R$ r
#include <DIR.H>. k9 @$ _4 `* q3 R
#include <DOS.H></FONT></P>
3 K, [6 r, u2 _<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>9 M4 g. n5 \9 o3 b. h! G$ D
<P><FONT color=#0000ff>int main(void)
: Y+ Z' q7 l3 o! S2 ]' a{
7 @" T1 S, n: Z4 w& G8 jchar directory[80]; : C% P7 n1 f2 E8 I" n1 \) u6 n1 ]
struct REGPACK reg; </FONT></P>5 n* q' ~2 f2 S+ {3 w9 @$ w' n# R
<P><FONT color=#0000ff>printf("Enter directory to change t ");
9 Y, U- q$ E+ N2 R1 ~gets(directory);
( x `4 E; Y. S) |9 C5 g. Sreg.r_ax = 0x3B << 8; /* shift 3Bh into AH */ % l/ L& z3 q7 G% q5 r. l
reg.r_dx = FP_OFF(directory); 1 e( |3 w2 _ C5 r7 O3 d* H4 o
reg.r_ds = FP_SEG(directory);
$ W+ _7 P6 ?% |. d# aintr(0x21, ®);
% j' x* [4 M# D4 Qif (reg.r_flags & CF)
$ N. S( u7 d! Aprintf("Directory change failed\n"); ) c& T( e; B! L* T! R3 Q" g4 ~
getcwd(directory, 80); 3 T4 c$ G) L. ?+ Z( S) e" p
printf("The current directory is: %s\n", directory); 4 [3 M F* h V" ~2 E9 f& l- X, f
return 0;
, i9 i: B( e/ S( e} # m6 O/ ?/ t5 Q, g
</FONT>4 Z% v( y7 L& d9 t# M3 c( ^
</P>0 u+ ^( p% V, r( J8 y9 b8 @
<P><FONT color=#ff0000>函数名: ioctl </FONT>4 X1 \- }2 o! y/ `- K$ ~/ U9 y
功 能: 控制I/O设备 + V9 M4 U- e" h* V
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
% T8 q% l( E$ P程序例: </P>1 N* I- M- a' _3 p+ A
<P><FONT color=#0000ff>#include <STDIO.H>
. `6 N4 l/ E) R: {#include <DIR.H>
3 M/ v) s" `0 ]% X+ z#include <IO.H></FONT></P>! [* }) Q6 h$ _3 z% l3 a; x Z# W
<P><FONT color=#0000ff>int main(void) " J4 G* W! o8 h$ {. x
{
9 h" O' T( I4 A. L- nint stat; </FONT></P>
3 b9 F: i. d9 a<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */
1 ^0 J! V! ~) X9 ?0 [- ostat = ioctl(0, 8, 0, 0);
: f# q) [. O9 m1 S) j6 L7 v8 \if (!stat)
( S8 P! u' H! c/ o. c1 oprintf("Drive %c is removable.\n", getdisk() + 'A');
9 Y8 p3 l, D7 y( eelse + e. M& H) @" M- E# \+ T' H0 k
printf("Drive %c is not removable.\n", getdisk() + 'A'); 0 U+ R; I& t9 j2 o% K% [
return 0;
. {& H- V% z* c, R6 d: S& @}
" Y8 L6 T, t4 X% T6 t. q, q$ f
" O8 K% A) ^6 Z7 D- _; {5 o6 C</FONT>
. r: p( m6 l/ v C</P>
3 L0 _+ o+ f& u$ e<P><FONT color=#ff0000>函数名: isatty </FONT>
( q7 A4 j+ U, x' X/ @1 H功 能: 检查设备类型
8 R" X1 o9 T0 j2 T. Y( X用 法: int isatty(int handle);
$ p# u2 T8 ~( M: v0 V# P# Y9 P$ C程序例: </P>
4 {2 q$ i3 r/ S% g6 S<P><FONT color=#0000ff>#include <STDIO.H>
' {' ]& j! h1 J0 Q#include <IO.H></FONT></P>
1 l# }8 [9 h1 x4 g3 q<P><FONT color=#0000ff>int main(void)
9 L; q2 o$ P* ?! e2 I{
' L9 b4 P8 R& _ R2 H% oint handle; </FONT></P># ^. ]/ U K& q- A4 z
<P><FONT color=#0000ff>handle = fileno(stdprn); ( ?( y# F0 C6 U, f* W/ C9 F
if (isatty(handle)) 8 a3 Y" q6 a9 V+ M7 O* Q: |
printf("Handle %d is a device type\n", handle);
: V8 x, Z! X+ m# M/ Uelse ; x# a% M# u+ `5 D1 f e: a% h# E
printf("Handle %d isn't a device type\n", handle);
/ A- C9 C3 C$ e8 Xreturn 0;
Q4 X/ L+ h$ e& x}
( J! ]! Y, X2 a% G0 b" u; w5 t; k- i: C, D# \5 w: C4 W$ h9 _
</FONT>* L: [4 B l/ R8 W
</P>' A5 i) [" D a6 a9 P. F' Y
<P><FONT color=#ff0000>函数名: itoa </FONT>
2 m0 X" N, n- q" N" E; ?功 能: 把一整数转换为字符串
( W) t$ Z; K; S3 v" r5 L" ]* r用 法: char *itoa(int value, char *string, int radix);
8 ]* V* [" r8 h# v9 \' J; E程序例: </P># _8 g1 u3 `- K. _% g, J# D
<P><FONT color=#0000ff>#include <STDLIB.H>4 K% T7 ]1 ?8 `+ A* F4 c7 y
#include <STDIO.H></FONT></P>2 C( Y( P3 h. ]
<P><FONT color=#0000ff>int main(void)
) }/ w3 Z/ c& H: S{
; c% ?4 c N: ^8 |3 hint number = 12345;
! `# s1 v0 G8 |' [, zchar string[25]; </FONT></P>3 |) [% k- {/ P$ R4 w* O
<P><FONT color=#0000ff>itoa(number, string, 10); 3 o: a' R, v$ o# k# C& w
printf("integer = %d string = %s\n", number, string); & D3 {; `. R/ N; i0 k
return 0; 8 f: P1 M6 s e
} </FONT><FONT color=#0000ff>
) J- u1 l1 _8 B2 g</FONT></P> |
zan
|