- 在线时间
- 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>
8 e+ `$ Q1 ~ A. E( k( |< align=left><FONT color=#ff0000>函数名: imagesize</FONT> $ M3 T* d5 J1 i1 |8 ~7 V
功 能: 返回保存位图像所需的字节数 # ]. w0 H r) e1 q' d4 F3 R
用 法: unsigned far imagesize(int left, int top, int right, int bottom);
/ L& d9 l# Q% s5 a! w程序例: </P>
) i$ G& w- p/ A. N) B# n4 `1 q< ><FONT color=#0000ff>#include <GRAPHICS.H>7 L |4 j, @1 x
#include <STDLIB.H>2 D6 V" a% U( ^5 A2 q6 l8 S
#include <STDIO.H>
& k# q% I: J5 J# q2 m! y6 O- N#include <CONIO.H></FONT></P>" L# ]1 Z! ?2 g7 Y
< ><FONT color=#0000ff>#define ARROW_SIZE 10 </FONT></P>" T3 _7 M8 ?8 a9 b) H
< ><FONT color=#0000ff>void draw_arrow(int x, int y); </FONT></P>) s; }) _- M2 | v: i8 l8 H9 N5 B
< ><FONT color=#0000ff>int main(void)
( _& u+ @7 R0 d3 W{ ! s, N/ s. m4 d& B% X2 s8 a
/* request autodetection */ 4 d/ f# B" j' F* T! i3 A1 Q
int gdriver = DETECT, gmode, errorcode;
2 V) o T/ z& Z' N7 h( Y8 O6 A. Uvoid *arrow;
" y8 E$ o9 \0 W2 Z" a; B# D7 Y0 Rint x, y, maxx; / v, s4 f5 k7 h3 V! |
unsigned int size; </FONT></P>
" a7 ~3 B8 A4 w7 b< ><FONT color=#0000ff>/* initialize graphics and local variables */ / b- D3 y [8 K7 ^4 m: w8 q+ A7 W
initgraph(&gdriver, &gmode, ""); </FONT></P>5 X7 o0 ~1 ?* y) t T0 \0 m
< ><FONT color=#0000ff>/* read result of initialization */ 2 Y- ?3 ?6 F- o% U: a4 e, V' ?
errorcode = graphresult();
' q v9 C& H+ l4 J9 Fif (errorcode != grOk) /* an error occurred */ : [5 d* \) x8 W5 m
{ " \. a; {1 G* I% C
printf("Graphics error: %s\n", grapherrormsg(errorcode)); " x+ A& T3 T3 Y. w9 v! g
printf(" ress any key to halt:");
; X$ j4 z: D0 f9 xgetch(); 3 F P) p# i. q8 V$ w4 t" B
exit(1); /* terminate with an error code */
* K. f- D2 Q+ l9 ^$ z* r} </FONT></P>) H" Q& k& {+ e" o6 P2 b
< ><FONT color=#0000ff>maxx = getmaxx(); ( ~% q* M7 F3 J8 K$ ]& O
x = 0; 6 Q* D. s+ R- F6 O& e2 s4 m7 v
y = getmaxy() / 2; </FONT></P>
. E% b, _& |1 z5 C< ><FONT color=#0000ff>/* draw the image to be grabbed */
) S+ t9 _6 S& h, H5 Idraw_arrow(x, y); </FONT></P>
5 V- I2 B, J I) O$ F0 w; Z< ><FONT color=#0000ff>/* calculate the size of the image */ ! D/ S9 C( S& D( ?& A" k
size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); </FONT></P>3 `$ m8 H1 Q: E$ z+ N2 }
< ><FONT color=#0000ff>/* allocate memory to hold the image */
( ?9 p' `- L5 v4 Karrow = malloc(size); </FONT></P>8 c& v& Y2 S+ y3 R* |, U0 z$ @2 Z" {
< ><FONT color=#0000ff>/* grab the image */
; X! {# L7 N3 N8 `) vgetimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); </FONT></P>2 ^+ G5 U S3 z* S; o* q
< ><FONT color=#0000ff>/* repeat until a key is pressed */
8 \, ?$ m A) K3 Xwhile (!kbhit())
\6 N7 ]: W$ R% M" | `{ 5 ]; `9 U2 U: K7 c2 L% s; ]# T
/* erase old image */ 7 W# q1 e( Z/ h6 c' ]3 }' k. x
putimage(x, y-ARROW_SIZE, arrow, XOR_PUT); </FONT></P>
7 q7 C8 A, X/ o+ x; X; U< ><FONT color=#0000ff>x += ARROW_SIZE; * V, v* r0 i1 }9 f) S6 h
if (x >= maxx)
) n6 [' t, Z P3 [; P- m6 N* Xx = 0; </FONT></P>5 z2 Z- }% p9 q- i5 A( q
< ><FONT color=#0000ff>/* plot new image */
( E9 |0 h9 @( d; T9 yputimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
8 \5 O# o5 x j} </FONT></P>
% g5 \+ R. I! a% ^7 w( Y" w< ><FONT color=#0000ff>/* clean up */ 6 H) q7 o2 k# Y7 a+ o+ c6 s* @
free(arrow);
" B2 L9 {8 j& Y. X5 l6 ~8 I/ nclosegraph();
9 m( o; Q% O4 N" j, |3 h% areturn 0;
- d' ?* D! b' Q} </FONT></P>
# @, L Y. \% ?- z4 E" w+ h< ><FONT color=#0000ff>void draw_arrow(int x, int y) & Z$ m. p& C" N- I6 Q+ ]1 k Y( s
{ 9 u6 ^ o7 ?! @# T
/* draw an arrow on the screen */ # V, X& n9 n7 B$ O% n% ^% J% r" e
moveto(x, y); 6 ], c( V- ?0 \/ a! `0 @$ F
linerel(4*ARROW_SIZE, 0);
6 k( P `+ Y s5 G0 ?6 s4 x5 v& Elinerel(-2*ARROW_SIZE, -1*ARROW_SIZE); Z) N" |* D( @$ r
linerel(0, 2*ARROW_SIZE); - ]! O2 G% i" V- _9 U
linerel(2*ARROW_SIZE, -1*ARROW_SIZE); ) Q% N }# m" }5 h9 E/ e* j
} * y/ F9 U/ X; U0 Y8 O, `1 Q
h* z" v7 H- e5 S v
/ o" v% \" q' R( H, A</FONT></P>- S$ g' n; r6 ?: U: \' t) K
< ><FONT color=#ff0000>函数名: initgraph </FONT><FONT color=#0000ff>
1 g' t. s# o ?3 y7 t. O<FONT color=#000000>功 能: 初始化图形系统
- d& e# c/ [$ C用 法: void far initgraph(int far *graphdriver, int far *graphmode,
8 k$ p/ B5 o; ^5 N' J' ^1 z2 Lchar far *pathtodriver); - \9 [3 e& r! u! J
程序例: </FONT></FONT></P>
6 u' G4 U" H: x3 T< ><FONT color=#0000ff>#include <GRAPHICS.H>
/ F" i$ U2 @0 N6 a* p0 u#include <STDLIB.H>/ v( a) E9 e* `+ U1 [
#include <STDIO.H>& G" e1 z5 q; R0 m2 }
#include <CONIO.H></FONT></P>* Q+ V- E# ^3 W/ k! H3 ~
< ><FONT color=#0000ff>int main(void) ( [5 x; F9 d/ {: v. C' g8 W" v
{
. F/ y: B8 ~: p/* request auto detection */
3 [# ~3 L2 @ e( Yint gdriver = DETECT, gmode, errorcode; </FONT></P>
8 @/ B% ]% j" p: d8 L/ {" D: k1 x< ><FONT color=#0000ff>/* initialize graphics mode */
/ i9 [6 [1 }% _3 vinitgraph(&gdriver, &gmode, ""); </FONT></P>
3 @6 ~/ I# P2 l< ><FONT color=#0000ff>/* read result of initialization */ / V# K: u+ o8 C4 V) Y' |
errorcode = graphresult(); </FONT></P>! J0 b7 j$ Z& o( o0 n1 z
< ><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ & ]% ]& N1 @8 U; I3 x
{
5 Q1 S/ S a- W# `) N3 Kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
# j0 `% ]$ E: D1 {9 k( ]printf(" ress any key to halt:");
. S7 h+ `7 v- n" Sgetch();
! M1 F+ ?; C4 y H" \6 K- x1 rexit(1); /* return with error code */
6 [" b+ Q2 \0 D; y! ^* Q# D) k( Y} </FONT></P>2 I2 j4 ~2 o* C$ k
< ><FONT color=#0000ff>/* draw a line */ * c) N+ Y, W# \! N6 B* @" Y
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
% N# D; p( Z6 A" e% e< ><FONT color=#0000ff>/* clean up */
( F5 V3 G# l2 h; sgetch(); 6 i H7 P* s0 J3 ]- m
closegraph(); ) i+ C, q4 j; h/ l3 a8 D
return 0;
- [0 [* G6 g9 N H3 f% C} </FONT>
7 e6 g6 g, Z4 l \5 y9 C2 K3 }; z6 O9 X0 }8 g$ s; J
</P>! {0 K' ]6 A) T6 E; A5 G0 h6 Q' X; \
< ><FONT color=#ff0000>函数名: inport </FONT>
0 }- f- C" [. j) k9 u功 能: 从硬件端口中输入 9 p; `$ z# {# V! n! C ~3 x
用 法: int inp(int protid);
3 g b% L5 ^* c$ L9 ?( i) T h程序例: </P>
4 L0 s% E# L) a< ><FONT color=#0000ff>#include <STDIO.H>: }6 W Y8 @- v
#include <DOS.H></FONT></P>
7 y3 }4 Y9 }# I ~* |5 {<P><FONT color=#0000ff>int main(void)
/ Y4 ^( \" U' s9 K$ n; `{
& R- _5 q$ ^0 ~/ T; m2 D! L( x6 pint result;
- a/ c; b6 {& s4 H, E, T Kint port = 0; /* serial port 0 */ </FONT></P>
9 C) t. w) u, P3 U' b<P><FONT color=#0000ff>result = inport(port); 5 c4 C% e7 t7 u! T+ g' k$ F+ [
printf("Word read from port %d = 0x%X\n", port, result); 8 Z. `) E& z5 _/ S( x
return 0;
6 B; {! l1 C, ]. p}
2 T6 e) n0 t6 s9 P) P V+ R0 L6 G1 Z) ]
</FONT></P>
3 o; Z0 K" x* _* @2 a2 o; L<P><FONT color=#ff0000>函数名: insline </FONT>3 ?: L/ u- u7 |0 `* G' m
功 能: 在文本窗口中插入一个空行
3 O0 `" l7 f% e: G# v7 f2 H- H用 法: void insline(void);
! `$ Z" l6 j4 n/ i4 Y程序例: </P>+ u' E% S' {# e. A
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 O" L0 V; Q4 N
<P><FONT color=#0000ff>int main(void) " |# R, C) F. T ~7 h; [
{
. D3 C$ }2 |% yclrscr(); 4 {; z( H- Z1 D2 J0 [* i8 W g' W
cprintf("INSLINE inserts an empty line in the text window\r\n"); ?, N0 x$ T. C& j+ @( G2 X3 [
cprintf("at the cursor position using the current text\r\n"); 6 f) ~7 j0 O- k9 ^: P0 W3 d% W
cprintf("background color. All lines below the empty one\r\n"); 5 i9 K- L) e$ Q. u
cprintf("move down one line and the bottom line scrolls\r\n"); & P, C6 P' `6 }3 a! N# o9 \
cprintf("off the bottom of the window.\r\n");
0 X/ f7 l9 W& P M6 z5 _& c+ P) [cprintf("\r\nPress any key to continue:"); # P( m( w: u# S* O
gotoxy(1, 3);
) u: E' @. @- g7 [getch(); 0 M- g- Y) D* ^- ]
insline(); z( c" k/ |% m; B1 O
getch();
9 t' x3 E# `* @# _* \2 ereturn 0; ( _3 y; Z) ~" J/ _ [3 U- \8 G5 f/ x
} 0 \5 p C U! s" H: p
</FONT>( W' K- T7 `0 Q6 x/ D, g, @, Z. B
, o: Y$ f0 v% g2 _" i
</P>
, a( A8 {/ ?) h2 ?" y4 v<P><FONT color=#ff0000>函数名: installuserdriver </FONT>
& }3 a" K. f$ I1 h9 Y1 V功 能: 安装设备驱动程序到BGI设备驱动程序表中
( k& D4 C$ ^2 h2 G9 w用 法: int far installuserdriver(char far *name, int (*detect)(void));
# P+ _9 c& Y: r+ G7 [程序例: </P>
: \0 B4 n/ P4 ]2 V<P><FONT color=#0000ff>#include <GRAPHICS.H>; q% z5 U, H0 T( w B/ T4 c& W% v% D
#include <STDLIB.H>
' a: O2 o; w- s% K8 X" \" _#include <STDIO.H>/ }+ i: o) r% C0 W7 r
#include <CONIO.H></FONT></P>4 l( M. y( O* Y9 l
<P><FONT color=#0000ff>/* function prototypes */
, U# M' E* ~ f' y6 c% k* P4 ]int huge detectEGA(void); 9 R$ u m* w; b
void checkerrors(void); </FONT></P>0 J' p6 B- G# E8 H" f; B3 j
<P><FONT color=#0000ff>int main(void)
* k' w) M3 a" ?8 q{
: h. G( F9 Y$ \2 A- x" Z- M3 }int gdriver, gmode; </FONT></P>- K9 _7 Y4 [2 x" e+ L
<P><FONT color=#0000ff>/* install a user written device driver */
3 u5 x' c5 R( d3 w! Y. ]* `; K: fgdriver = installuserdriver("EGA", detectEGA); </FONT></P>
, b& U6 `* ]" g4 g<P><FONT color=#0000ff>/* must force use of detection routine */
7 Y8 m! ` w) I9 @1 Z& |gdriver = DETECT; </FONT></P>. v+ p7 v, N3 m2 o) ]& h3 I
<P><FONT color=#0000ff>/* check for any installation errors */ 7 J0 z% L$ q0 ?, S9 v# d
checkerrors(); </FONT></P>! T4 |1 v2 Y8 u
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% ^& y( b9 W4 ^2 p( V7 U4 }initgraph(&gdriver, &gmode, ""); </FONT></P>
4 E- B3 M- r4 J* Y<P><FONT color=#0000ff>/* check for any initialization errors */
2 v/ `9 r% L9 [$ _checkerrors(); </FONT></P>
1 R5 X' t* x1 U4 h G+ u/ ]+ D5 B<P><FONT color=#0000ff>/* draw a line */
/ b: N. h- W9 l. I h% F# {$ Lline(0, 0, getmaxx(), getmaxy()); </FONT></P>
. u0 u2 p5 q. `& t% n" z- K; @* t' ?<P><FONT color=#0000ff>/* clean up */ 4 W$ h% _% b5 j% J8 H" |$ Z
getch();
0 p9 I3 k9 V/ z6 y3 S9 Lclosegraph(); 6 X" r) R) A8 ?& ^: d5 U0 a
return 0;
_3 H) k3 s- F' u6 p} </FONT></P>0 C- n; ?5 y) Q& E" s8 j }& F
<P><FONT color=#0000ff>/* detects EGA or VGA cards */
" K9 C% s9 u( M, W7 g! z/ i0 lint huge detectEGA(void) ; |% S0 w U& h6 k9 L/ N
{
+ f) ]& R1 X# _+ q6 {1 P( ?& Kint driver, mode, sugmode = 0; </FONT></P>" G4 F. p3 R4 @+ n
<P><FONT color=#0000ff>detectgraph(&driver, &mode);
9 O1 [5 E1 `2 M4 q; s* Iif ((driver == EGA) || (driver == VGA))
2 f; I( G# }+ Q+ G) a& I/* return suggested video mode number */ " q, e' J {# O# @. K
return sugmode;
% H1 c9 o1 W7 H' m; l) g: s/ [else
6 x: c3 B! v: z( L/* return an error code */ 3 \9 k! h* Z, a U9 Q
return grError; 9 _% k- T6 b. F$ x3 X5 B
} </FONT></P>
* H( o$ g8 s0 y7 t/ b<P><FONT color=#0000ff>/* check for and report any graphics errors */ H" m5 K7 M" U/ l
void checkerrors(void) ' q( y( W! D9 m/ F
{ M' F' j; m. P9 s3 {
int errorcode; </FONT></P>
. F5 n# G3 S7 N1 s<P><FONT color=#0000ff>/* read result of last graphics operation */
, y7 w( L3 @" |* Z, Terrorcode = graphresult(); - T" {: J$ P0 x5 n' I
if (errorcode != grOk)
" z3 s0 y7 Y, S, Z* a H; M& A{ " y" r+ c2 U# ?3 S$ a0 v8 j
printf("Graphics error: %s\n", grapherrormsg(errorcode)); , k' |2 `- G* v& T* G0 X
printf("Press any key to halt:");
' }8 g, ^0 H+ M6 j9 W* O- O; mgetch(); % F6 a/ b- T, R- J1 p) w) F* J
exit(1);
& ~ @) @' c- p' D6 _}
4 {. Z8 ~9 a& d' c& E} </FONT></P>
1 [" z( W S3 O<P><FONT color=#ff0000>函数名: installuserfont </FONT>
/ m, C% C% p( ~7 K' y功 能: 安装未嵌入BGI系统的字体文件(CHR)
; I; {& b8 p$ n+ Q6 I用 法: int far installuserfont(char far *name);
) d- y- ?) K! |( J. ^# n程序例: </P>
& ~3 T4 N( y: j0 Q# Y<P><FONT color=#0000ff>#include <GRAPHICS.H>; Q2 u4 |. g$ O3 W# D
#include <STDLIB.H>) b$ y' {' I& O0 k
#include <STDIO.H>
6 n* q9 d4 \9 r A6 D- U3 g#include <CONIO.H></FONT></P>
" c' [! x7 H/ W+ d/ A. I2 z& j% w<P><FONT color=#0000ff>/* function prototype */
C9 z, Y9 | A9 H& s0 d( E7 U2 Bvoid checkerrors(void); </FONT></P>- W& ^5 V+ \1 w, x# v) O6 p% F
<P><FONT color=#0000ff>int main(void) 2 ^* h# z7 ]; Y
{ , u7 Q c( M1 C+ Y) Q0 g6 M6 `% B
/* request auto detection */ + q2 |& X8 D; ?
int gdriver = DETECT, gmode; 9 u8 `7 \6 u. T( S
int userfont; 7 K, X, G! o' A3 u p$ S
int midx, midy; </FONT></P>
2 H* r# D2 g; a D4 ]" W d" P<P><FONT color=#0000ff>/* initialize graphics and local variables */
# b. i; x1 n7 i) b$ K) Binitgraph(&gdriver, &gmode, ""); </FONT></P>) g) u, r2 ^) q% k
<P><FONT color=#0000ff>midx = getmaxx() / 2;
/ J% `7 Q- l2 l- V) v5 kmidy = getmaxy() / 2; </FONT></P>: E. T4 y) w0 p4 s
<P><FONT color=#0000ff>/* check for any initialization errors */ 8 W; l; m/ w# K- z A
checkerrors(); </FONT></P>
. g: C2 V& g8 g/ w8 e# z5 c<P><FONT color=#0000ff>/* install a user defined font file */ # q( h3 k# `7 R2 x0 t0 ?
userfont = installuserfont("USER.CHR"); </FONT></P>
+ G4 s) j% \- t- k6 e1 j<P><FONT color=#0000ff>/* check for any installation errors */ , i6 i8 C' z! q( H' ^4 G- ^+ Z J, F
checkerrors(); </FONT></P>7 N: c- r& |+ j, \+ ?/ v& m
<P><FONT color=#0000ff>/* select the user font */
1 d3 x+ P# Y8 s% h2 p) v* A. Usettextstyle(userfont, HORIZ_DIR, 4); </FONT></P>
$ M* Y5 \* Y" p) I4 T; ]# }2 J<P><FONT color=#0000ff>/* output some text */ ' J5 ^) M- q, z1 [7 S! `# M7 C
outtextxy(midx, midy, "Testing!"); </FONT></P>
+ A' ~2 N, e$ ] N9 h' N# ]% s, X<P><FONT color=#0000ff>/* clean up */
5 Y8 J5 J8 V; S# z* a3 ]4 Fgetch();
7 K0 e6 E# e1 e) x1 [5 r( eclosegraph(); ( r1 o0 M& e, H* k
return 0; ; l7 Q* R/ v" \4 S+ D
} </FONT></P>
0 b1 [# r/ K/ ?<P><FONT color=#0000ff>/* check for and report any graphics errors */
3 N7 u& O/ R; _7 `) u1 s$ Wvoid checkerrors(void) 7 b" q' e8 M8 e/ e
{ 1 m6 `4 B: i# q. d; ~& V, H3 D
int errorcode; </FONT></P>" O# z' }) r* w3 k# r! @
<P><FONT color=#0000ff>/* read result of last graphics operation */
2 f$ r% t1 }0 H3 X0 Lerrorcode = graphresult(); 0 w( a. T" T3 X( [
if (errorcode != grOk)
5 v7 k* w" Z" V8 B! c- g' C( B{ 6 j& V; X% z# c2 [/ p" K
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / Y; `5 W' R& z5 N
printf("Press any key to halt:"); * m4 M1 J# F, A3 d
getch(); e& j4 r4 }# b0 p9 f5 }$ Y9 A
exit(1);
* A' H; p9 k! _1 s} # p6 ~$ A6 ], t
} </FONT>
1 O: x2 r& ^' o
6 z9 V* D+ i5 o+ y/ k: T! B' j; h1 I& o7 z. @& p2 s
</P>9 L$ V$ J, |6 R8 q+ h9 I
<P><FONT color=#ff0000>函数名: int86 </FONT>
' c$ \4 A0 m$ w4 I7 g功 能: 通用8086软中断接口
7 E! S1 @7 j3 Z用 法: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
7 y! F/ d; I; c4 U4 C' Z程序例: </P>0 w# s. t7 {; g, d+ f( A# K
<P><FONT color=#0000ff>#include <STDIO.H>; g0 p$ t) y8 W( a1 H0 F2 a
#include <CONIO.H>
% r6 q2 w, @4 u- E* Y# W/ E$ n#include <DOS.H></FONT></P>
& D& d: p1 D y5 [2 m5 G<P><FONT color=#0000ff>#define VIDEO 0x10 </FONT></P>) E% k+ P/ N( ?7 Y2 T* R
<P><FONT color=#0000ff>void movetoxy(int x, int y)
7 _7 ~8 B( H' H% R{
6 o. p& d0 Q! m4 U( G4 Nunion REGS regs; </FONT></P>
: @$ |) u! e6 ?- r<P><FONT color=#0000ff>regs.h.ah = 2; /* set cursor postion */
3 J, w+ {/ ]+ H. M/ O4 t2 j1 sregs.h.dh = y; 8 k% q: A# K7 b* I3 p ~; @
regs.h.dl = x; " R/ K) l0 W) P: K9 Y. F
regs.h.bh = 0; /* video page 0 */ 3 _/ h5 g1 E# j' N/ w
int86(VIDEO, ®s, ®s); , B$ e9 V. a* @/ g" A
} </FONT></P>& `0 j! x( `7 q
<P><FONT color=#0000ff>int main(void)
! S; v0 b* |1 D7 \{ ! h' ^6 P5 q0 ^
clrscr();
1 I8 P% ^4 c+ |: \movetoxy(35, 10);
/ E+ w* |4 E: @8 eprintf("Hello\n"); & o& X9 r7 ~, L% s4 B
return 0;
- M$ u1 e0 @6 w1 G} </FONT>
( t" J: F8 I9 O: H- H
, o3 R! n, A9 ?/ K# E, f</P>' @/ k5 L" Q9 d9 q
<P><FONT color=#ff0000>函数名: int86x </FONT>
3 N5 E) y; | r1 k2 E& e, n功 能: 通用8086软中断接口
^/ g* o* o3 ~4 B6 }用 法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
7 r9 c0 V$ K; P' K- Xstruct SREGS *segregs); . r6 q- i! n/ g& B7 x! f
程序例: </P>8 x5 z) b: D7 G; k+ o' ]; p
<P><FONT color=#0000ff>#include <DOS.H>, R) z6 E2 G j3 D
#include <PROCESS.H>7 t4 m5 x/ T2 m. U
#include <STDIO.H></FONT></P>
, k: g/ d7 j; S1 f+ T" U( @" j) @* b1 P<P><FONT color=#0000ff>int main(void) - b% l8 c+ u* _, }; U. Z
{
4 m7 z9 r" i4 n8 x) G6 y7 Uchar filename[80];
6 d2 p+ G: v t5 L& ?; b6 Hunion REGS inregs, outregs; , O, m5 Z/ Y2 a* O9 J3 b- W
struct SREGS segregs; </FONT></P>* _5 F7 T P* |; y
<P><FONT color=#0000ff>printf("Enter filename: "); 8 J3 o) L6 i6 b; {. P( }
gets(filename); - r& B( A" U2 {5 `
inregs.h.ah = 0x43;
' k8 q+ F6 B5 R# u/ Hinregs.h.al = 0x21;
, s( I5 s) d6 [' Ninregs.x.dx = FP_OFF(filename); 5 C4 X, [: S6 M7 M! \
segregs.ds = FP_SEG(filename); , ?% @" g) {; s m1 I" x5 h" N
int86x(0x21, &inregs, &outregs, &segregs);
H D5 W) N: v0 xprintf("File attribute: %X\n", outregs.x.cx); ' L- r' o/ U% ~+ A7 v; m
return 0;
. J- \4 V$ L5 L: y1 ~' E4 F}
% _0 ~8 J7 u. T' i/ e9 j+ |% d8 }- w8 w
</FONT>9 ?. n% ?3 s( d L1 w) e0 N
</P>
, M8 @: ]' A# U, P9 t+ x( P6 u% v<P><FONT color=#ff0000>函数名: intdos </FONT>
! L6 a4 O8 g7 v4 `2 x+ C功 能: 通用DOS接口 . t+ o, c2 V2 ~( N
用 法: int intdos(union REGS *inregs, union REGS *outregs);
0 G; ]8 Z. B+ B! p: E: A程序例: </P>! T F1 b) u, |5 x# g1 w
<P><FONT color=#0000ff>#include <STDIO.H>
3 E+ X: ^0 _4 h4 y7 r#include <DOS.H></FONT></P>
7 H5 v' j8 m$ g* {! J0 ~' g, z+ `<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */ 8 P8 c" `, V$ r/ H
int delete_file(char near *filename) ' J' P9 L& T# ~! P, G0 T
{ ! `# ]. {# y, [, [) @
union REGS regs; . |4 |3 N k3 ]" ^( k# B* N
int ret; 0 S) E5 ~9 `/ T. a @. |
regs.h.ah = 0x41; /* delete file */ 4 d0 J! s- U- ]) J
regs.x.dx = (unsigned) filename; . V$ n+ F! @' F* ?1 y
ret = intdos(®s, ®s); </FONT></P>
. u" J+ }; a$ C( W<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
! J/ C: B2 T7 l) g5 f# u8 zreturn(regs.x.cflag ? ret : 0);
" q+ b/ r0 L# q( f9 D} </FONT></P>, H1 j% C0 ?6 B) q! I# z
<P><FONT color=#0000ff>int main(void) ' j: p' _( M) n! f
{ / W+ w7 A9 [. X/ V+ T A" B
int err; ; T# G4 l0 _# F. u1 Q
err = delete_file("NOTEXIST.$$$"); * D- a1 x5 ^* s, S" ]4 x
if (!err) , }* I, J! R. d: \ ?5 ?
printf("Able to delete NOTEXIST.$$$\n");
, C' S+ ^6 ~& C% {' ^9 [+ i% V1 x( Aelse ! L, j2 x6 j, m- L9 ^5 E
printf("Not Able to delete NOTEXIST.$$$\n"); & d5 }" C5 o9 }4 h
return 0; * D! D% O v3 L9 g3 t' Z- ~ R
}
5 I& w( ~$ |" l& k3 x
+ ^4 O5 ?% m% w- `</FONT>
: D7 t1 o1 K0 O* v t6 t% w</P>
4 e! m* |* v' F2 G<P><FONT color=#ff0000>函数名: intdosx </FONT>! M( |9 ]1 {4 n7 G( Z- F D( o. I
功 能: 通用DOS中断接口
- @8 t1 l/ G- r( m r1 F用 法: int intdosx(union REGS *inregs, union REGS *outregs,
) ?$ r6 { f5 c# H6 }; Vstruct SREGS *segregs);
, s. T B) Z& t0 e h, l程序例: </P>
" _, _; F3 {: E) I+ ?# h! N<P><FONT color=#0000ff>#include <STDIO.H>! g" m/ S x) V7 Q
#include <DOS.H></FONT></P>$ R' T) _3 E' j _4 t5 {& S
<P><FONT color=#0000ff>/* deletes file name; returns 0 on success, nonzero on failure */
5 ~3 v- R7 ?" nint delete_file(char far *filename) 8 k5 r" E/ ]$ ~/ ~& {
{
$ {1 x( B+ U! v7 {$ s2 A% |% qunion REGS regs; struct SREGS sregs;
1 e( c+ s2 k# _int ret;
4 E" `! @2 c+ e* Mregs.h.ah = 0x41; /* delete file */ $ D, a; I+ m) V; d/ V( J9 }
regs.x.dx = FP_OFF(filename);
( M7 W( L0 w i& k B" }; r2 L7 Xsregs.ds = FP_SEG(filename);
4 L; s+ u# q5 @ret = intdosx(®s, ®s, &sregs); </FONT></P>8 n, ^4 {: m+ ?5 e
<P><FONT color=#0000ff>/* if carry flag is set, there was an error */
) j/ r3 W/ `; F1 Preturn(regs.x.cflag ? ret : 0);
/ n+ n+ J7 q2 n. V0 p6 F} </FONT></P>
; L x" x0 i1 K6 f<P><FONT color=#0000ff>int main(void) / a5 m& y5 S& L3 h. x9 w
{ 5 O |) B3 _- G; k: Z- `9 k
int err; ; f1 \ Z' M) M' Y9 `3 Q
err = delete_file("NOTEXIST.$$$"); # a7 Q' {7 y- X& Z$ R: O
if (!err)
& v) Q/ H D, Z+ b+ V* `6 Cprintf("Able to delete NOTEXIST.$$$\n"); ( z% |: _' @* l
else
, q; l( \. m- j. g1 fprintf("Not Able to delete NOTEXIST.$$$\n"); : H, q* K" v; P; ?' X
return 0;
/ I% Q6 R& ?- h* h. C} ) Y7 K2 ?. n; C9 `
</FONT>
! I2 J8 i* z7 X* U" o0 T</P>! ~! K5 J! Y$ q5 Y7 c
<P><FONT color=#ff0000>函数名: intr </FONT>
) R! s, m C Z功 能: 改变软中断接口 . q5 `; R& q/ z6 o( e: V
用 法: void intr(int intr_num, struct REGPACK *preg); 8 }( U5 l6 t$ x
程序例: </P>
: ^: o+ r0 |" J: s: J, f! k, l! d<P><FONT color=#0000ff>#include <STDIO.H>' q+ m3 X. S' N7 m0 `3 Q( D: _
#include <STRING.H>
' q& A' @1 G9 x2 w/ \7 s2 f#include <DIR.H>
! h7 Y! u. K3 z$ d. t5 }#include <DOS.H></FONT></P>: `+ z. v5 z4 u& E% k: M D! d
<P><FONT color=#0000ff>#define CF 1 /* Carry flag */ </FONT></P>
0 ]4 D2 e! S3 m% w. s<P><FONT color=#0000ff>int main(void) # L/ H. `; h' @# u2 ^9 b# `
{ & s7 V5 _& U* q
char directory[80];
p# U. W8 c( S; ` N: l3 nstruct REGPACK reg; </FONT></P>; F5 L: B7 D* ~: V
<P><FONT color=#0000ff>printf("Enter directory to change t "); * c0 r7 X+ B# m- W" j) M; q
gets(directory);
" e4 J! |% z% c* ^. ]) zreg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
~8 U/ u! I2 e' Z8 R9 dreg.r_dx = FP_OFF(directory); , j2 N6 u7 a& y& @9 m* k
reg.r_ds = FP_SEG(directory);
" b0 T3 j/ A3 Q# ~. y, v2 C, Q# }intr(0x21, ®); $ I8 e, ^$ O3 v( u4 m
if (reg.r_flags & CF) / q1 ?* E! h2 S" c
printf("Directory change failed\n"); # q; h$ W3 b$ t
getcwd(directory, 80); 3 t- z/ |' A, ?5 u5 R% S0 r
printf("The current directory is: %s\n", directory);
0 D3 ]9 o0 Q# }3 w9 dreturn 0; # Z3 x2 Q1 z0 H1 q
}
3 u$ x$ ^; ?7 ?4 e. @2 I1 L</FONT>
% J, Z/ S# s2 i: X1 E</P>
0 p% z; D! l" G, ^, s* [/ F3 Z<P><FONT color=#ff0000>函数名: ioctl </FONT>* c# W0 ]% q" B/ r
功 能: 控制I/O设备 , @2 G8 U1 F9 r0 m# h! G
用 法: int ioctl(int handle, int cmd[,int *argdx, int argcx]); 5 H! w& O( o; o, Z
程序例: </P>
9 _! X4 Z0 _1 u: X<P><FONT color=#0000ff>#include <STDIO.H>8 R& a+ X# P Y4 ^) ~4 m
#include <DIR.H>
- A4 D( d" s' u# r. r' H#include <IO.H></FONT></P>. f' @! q$ }- x1 E6 f+ z! B
<P><FONT color=#0000ff>int main(void)
6 }" a7 o$ G9 q9 S6 H/ W) e3 j* O{
6 x! ]' X4 X+ Bint stat; </FONT></P>* Y; e$ g- R) \' w+ M! P1 S
<P><FONT color=#0000ff>/* use func 8 to determine if the default drive is removable */ 3 ?7 S9 ]( |8 P% U& I! \% `
stat = ioctl(0, 8, 0, 0); , f0 I" l$ e4 D5 y* X& `$ s
if (!stat) % q( m6 a" z# B- n( _% w: b
printf("Drive %c is removable.\n", getdisk() + 'A');
7 M T9 O7 _. _else
0 w: a. y1 m3 Q& c) A- Fprintf("Drive %c is not removable.\n", getdisk() + 'A');
+ ~2 R3 B& y$ e- b" i/ l: }return 0;
8 t3 Z8 g3 H# N, M% [6 @; k} ) q9 ^+ e, p" I4 C+ I
$ t' T& \% j6 U6 j# l
</FONT>' z* v! W) g. q
</P>) N: ^* d8 S; R0 U9 O! H8 F
<P><FONT color=#ff0000>函数名: isatty </FONT>
6 I0 e- r5 x9 t0 ~, C功 能: 检查设备类型
7 ?% p: w8 M2 H用 法: int isatty(int handle);
) b1 G* P2 [8 U& W3 I程序例: </P>
" a- l2 w0 W0 h* `% @<P><FONT color=#0000ff>#include <STDIO.H>
: J' H& x, B9 ]0 E \% \#include <IO.H></FONT></P>
, N+ s7 W0 w# s<P><FONT color=#0000ff>int main(void)
a$ M4 O% l7 [; A3 Z5 \{ 5 B4 ]+ R/ e( i. C* \
int handle; </FONT></P>/ \" i0 j/ ^1 `$ U- M
<P><FONT color=#0000ff>handle = fileno(stdprn); ) |( ^4 l \) P1 j- ]9 `
if (isatty(handle))
2 N, ^( _( z0 O: {. vprintf("Handle %d is a device type\n", handle); z5 A8 d! \: Y: k
else ; ?0 I# Y$ Y C* j
printf("Handle %d isn't a device type\n", handle); " S' A u' l. o
return 0;
% s- r8 [0 ^5 ^ _+ Q, ^' Z( b} 8 v' E% j3 K+ j, q* C
: ~) ^: |) N2 n/ J+ D Q' x</FONT>
- c6 G' O: M; u- C; O) P</P>$ p4 r( L g8 `" y
<P><FONT color=#ff0000>函数名: itoa </FONT>6 g* l. q* b3 i1 z# R0 ~8 f7 T( e6 }1 t
功 能: 把一整数转换为字符串
* T- [/ S6 M# A) X; q3 X6 y用 法: char *itoa(int value, char *string, int radix);
# v$ h$ t0 y* w( x程序例: </P># R, L" ~* k2 u X( Q& D
<P><FONT color=#0000ff>#include <STDLIB.H>( P# z g5 g# ^1 [3 N
#include <STDIO.H></FONT></P> x' \* @& _4 j) x) B- z
<P><FONT color=#0000ff>int main(void)
3 ^/ S+ L( U# {{
' r! R. ?9 e% }int number = 12345;
5 H; w9 u$ K' V' nchar string[25]; </FONT></P>
5 y j B {9 g5 c0 h<P><FONT color=#0000ff>itoa(number, string, 10); 9 F/ u$ H; i7 _% R( W
printf("integer = %d string = %s\n", number, string); 0 u7 j6 n4 a3 K; X" {. f
return 0; 5 T0 ~2 @9 q. U M* H z& [
} </FONT><FONT color=#0000ff>/ {( z0 }1 w! d/ Z3 ]
</FONT></P> |
zan
|