- 在线时间
- 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>函数大全(g开头)</FONT></B></FONT></P>
; ?! j: W/ M7 L4 \" l
8 v# r& ?% q& h9 `! F3 k
# c$ [4 y- l( D) P4 |3 L1 J0 w<p>
( [7 k3 o9 ?0 z9 U4 r< ><FONT color=#ff0000>函数名: gcvt </FONT>+ r7 w+ z6 u' n% F8 t! z4 ^
功 能: 把浮点数转换成字符串
- C# x: n; d8 g$ R! r7 a用 法: char *gcvt(double value, int ndigit, char *buf); 4 ^" S; h% M# w0 C$ @) i
程序例: </P>, g% f+ I4 s7 i# K0 I! j( x( G5 s
< ><FONT color=#0000ff>#include <STDLIB.H>
/ C" {4 d6 y1 r0 Z' p5 P#include <STDIO.H></FONT></P>
6 r+ C- r( J7 _: j8 Z< ><FONT color=#0000ff>int main(void) 6 W0 m" [& [0 {) [9 X( ?% u z# c: A6 y
{ # e ^( ?3 I/ A: P( d; j
char str[25];
/ G5 v9 L: g5 h( q6 o- Ndouble num;
, X5 a1 W- b, yint sig = 5; /* significant digits */ </FONT></P>% @* w: l; K7 z; x9 A+ {# ~9 i
< ><FONT color=#0000ff>/* a regular number */ 6 E* D- Z q' ^2 q- M6 @2 b
num = 9.876;
3 t; W! Z& i- b) F, Vgcvt(num, sig, str);
; e1 E3 v3 F& o, g2 | ]printf("string = %s\n", str); </FONT></P>
. }; Q! M1 Y: h; D& O< ><FONT color=#0000ff>/* a negative number */
/ i0 U$ ?, F: V P, \+ xnum = -123.4567; 4 `- }' [1 b2 W6 D# B" _
gcvt(num, sig, str);
1 J$ _( j9 _# i" y/ h( ]" F% |5 Z. {printf("string = %s\n", str); </FONT></P>
& F, a+ I1 P. N/ Q: V; H) S/ N< ><FONT color=#0000ff>/* scientific notation */
* G, _. u P" k$ Q' l: a4 |4 Snum = 0.678e5; ) f$ Q' P5 j R ?( b
gcvt(num, sig, str); 4 K# q/ g/ Z" D% U; S0 d, d* n5 i
printf("string = %s\n", str); </FONT></P>9 m9 e; E0 A4 N) a! u' z- Q
< ><FONT color=#0000ff>return(0); $ o) k9 f- U4 Y" a2 s, V
} ! b: ]( W4 C O
+ r6 X! V3 D/ n. `! R</FONT>5 L; H) N: s$ O8 \
</P>
9 @- |0 @" V6 q. j& ?* Y1 B< ><FONT color=#ff0000>函数名: geninterrupt </FONT>- k, Z" R$ r( S* M1 s' G0 `
功 能: 产生一个软中断 " x( x* x, C- }/ X2 q
用 法: void geninterrupt(int intr_num); 5 P1 d }1 P: y7 S5 J
程序例: </P>4 w3 M3 k3 F) X0 ?
< ><FONT color=#0000ff>#include <CONIO.H>
; D7 t; A1 U1 `0 I$ A( s#include <DOS.H></FONT></P>
. \, a# R$ j! R1 r< ><FONT color=#0000ff>/* function prototype */ " {2 n% n6 i. }. G
void writechar(char ch); </FONT></P>
& `/ t2 q* e" D/ [6 n2 ~" ]. U< ><FONT color=#0000ff>int main(void)
1 D% t$ F+ b8 @2 f4 b6 A) O# y; _{
" W9 h- y4 A4 p% F( p: k' fclrscr();
, S; O4 E8 M: s! P9 s# Sgotoxy(80,25); * M( V5 W* C4 t
writechar('*');
$ L; G( c) D* ~( T& i, e6 B0 vgetch(); ) S# p2 z& s4 M, t3 B' e( z$ M1 [
return 0; , w& w5 }- `4 ?7 Q& b
} </FONT></P># h. j, ]* t' ^/ K7 R& z' @
< ><FONT color=#0000ff>/* % C" ~3 l2 _6 S8 Q6 m
outputs a character at the current cursor
3 |" G b# Y* Y# {3 Gposition using the video BIOS to avoid the
x% a- `; D0 q& t) w! u- O1 g( i1 ^! Y% rscrolling of the screen when writing to
. N: J$ ^% p | k3 q! {location (80,25). : R2 P3 s: [' {9 \
*/ </FONT></P>4 e: V6 T; {& V1 J1 e9 `, o
< ><FONT color=#0000ff>void writechar(char ch) 3 j. N! A4 l) d+ q1 ]9 K
{ ) l5 d' O( _( @- U
struct text_info ti; 6 n# M, ?' _ R" E' H: D7 u
/* grab current text settings */ $ M* l* {! a A( _0 \5 [' U, A) v* ^
gettextinfo(&ti); 2 u. E2 N5 Y/ c9 S+ E$ H8 c* I* ]
/* interrupt 0x10 sub-function 9 */
}' b$ i8 j2 l, i" h_AH = 9;
7 ?: t5 V7 d9 [1 `/* character to be output */ . i1 }* u9 \; X8 m; c, a; F, r" n
_AL = ch; 8 q5 N: R* b& g7 X j) |+ ^
_BH = 0; /* video page */ . \ q" u# S" y. E
_BL = ti.attribute; /* video attribute */ 0 G4 k. G2 y8 w5 A" r
_CX = 1; /* repetition factor */
! L% l9 n8 h3 Zgeninterrupt(0x10); /* output the char */ . B5 j1 ?# v$ E" N! ^3 N n
} : z" Z$ V5 f" n, N( ?8 C
</FONT>& P" J3 [ m8 C$ ~
</P>1 z, H- h) Z5 d7 `7 X0 J
< ><FONT color=#ff0000>函数名: getarccoords </FONT>
, H" e' q$ V5 O: \+ `2 x- J4 r7 r5 Z1 {$ v功 能: 取得最后一次调用arc的坐标 " L! [. s6 G% L! T4 z
用 法: void far getarccoords(struct arccoordstype far *arccoords); . P3 G3 a. b4 _" ~4 K
程序例: </P>6 q) D9 T+ a* B- t; Z* ]# c
< ><FONT color=#0000ff>#include <GRAPHICS.H>" _3 ~* s3 W2 r4 ^. `; Y) {/ n( Z
#include <STDLIB.H>( g* r6 u9 t5 @( I4 K
#include <STDIO.H>
- U9 \7 F% ~, u" U4 S#include <CONIO.H></FONT></P># h6 d' i! c" _. G8 r" N, P+ _) K3 w
< ><FONT color=#0000ff>int main(void) " L, A! M. D1 T# B9 B
{ * O, {2 ^$ m( s9 }1 w' A
/* request auto detection */
. e5 o6 e! Q3 p+ H) ]$ Jint gdriver = DETECT, gmode, errorcode;
2 [3 T5 O- K$ P6 }7 Qstruct arccoordstype arcinfo;
g+ H4 Z# A% m. D* dint midx, midy;
3 y5 l3 p) }" gint stangle = 45, endangle = 270; 8 p' m1 N& `% v, v- p0 L2 E
char sstr[80], estr[80]; </FONT></P>) E' O$ G9 p8 {/ N' W- B8 W) h
< ><FONT color=#0000ff>/* initialize graphics and local variables */ ' u9 G" b( `# z/ ~( s
initgraph(&gdriver, &gmode, ""); </FONT></P>+ X" w! ?: w3 k/ I# j% @
< ><FONT color=#0000ff>/* read result of initialization */ + W5 r9 R1 V+ d9 l0 T. M) @3 y
errorcode = graphresult();
' W' a, C) p- d8 `: [% c& M7 @* F* Z/* an error occurred */
) |. X7 N- M' X% b' M( n- |8 Qif (errorcode != grOk) : f- r [# p& e v. w
{
. n7 W8 s# ^% d& p( I" C, Iprintf("Graphics error: %s\n", 1 e8 {6 i& e( O0 g/ z
grapherrormsg(errorcode));
) A0 w2 M( u- C# O4 [) g0 eprintf(" ress any key to halt:"); ! \: m# x# q, A3 P# h
getch(); % H- `3 ^) g- F* c( g) P
/* terminate with an error code */ 8 V, N+ j# P0 k
exit(1); 0 x- J- M' O8 V0 L8 v0 G, Q
} </FONT></P>
+ R5 ^5 O' w, O4 q9 L< ><FONT color=#0000ff>midx = getmaxx() / 2;
" T/ ?% o7 o. }* T3 _midy = getmaxy() / 2; </FONT></P>
/ U4 b! h' ~ y2 y< ><FONT color=#0000ff>/* draw arc and get coordinates */
% {! @3 p& f3 Y% g7 v- ~setcolor(getmaxcolor());
7 Z. Y8 E9 L, p. h3 qarc(midx, midy, stangle, endangle, 100);
' F8 o: H) y; b6 w, ^getarccoords(&arcinfo); </FONT></P>
& P' r4 W- T; B4 }) M& Q3 B< ><FONT color=#0000ff>/* convert arc information into strings */ * o; Y' x9 Q8 L# Y1 H
sprintf(sstr, "*- (%d, %d)", / B: D4 n. z+ P' c& L
arcinfo.xstart, arcinfo.ystart); % O" p9 W3 U Z' S6 c) X
sprintf(estr, "*- (%d, %d)", $ N+ G7 U8 d1 K' L) T- L# m
arcinfo.xend, arcinfo.yend); </FONT></P>
+ J( J! R3 K7 p2 r% x1 S7 b< ><FONT color=#0000ff>/* output the arc information */
) n$ k- V0 g( vouttextxy(arcinfo.xstart, ' i- d- k/ K- O5 i/ _; J" h$ V
arcinfo.ystart, sstr);
( r3 B$ q$ L% p7 p9 N8 I: I; gouttextxy(arcinfo.xend,
' z0 |# `9 L9 f* j8 [arcinfo.yend, estr); </FONT></P>3 D' s' m- l$ ], I: e# F8 k
< ><FONT color=#0000ff>/* clean up */
) I) l- s0 T( e# \$ ]# p, Wgetch();
* j! x- h+ V' e4 O% y8 W& [: pclosegraph(); 7 G2 y& @% u2 p: e6 A4 I! s# x5 K
return 0; D4 g. L$ a, L7 n
}
/ y. Y1 P; ^* l* E3 x# i' b</FONT>. I% a& S# e* T& \
6 I; }' I) n7 t! o7 g3 M8 o. D+ \7 \
</P>
* Q; Z# w+ \% h. q< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
3 i# f) ?6 `) F; A. B' b2 H功 能: 返回当前图形模式的纵横比
- N! Y& k) f6 q用 法: void far getaspectratio(int far *xasp, int far *yasp);
}2 d# f* ?1 x3 W) s" ?程序例: </P>& e* h$ d9 O! C9 R& t
< ><FONT color=#0000ff>#include <GRAPHICS.H>
, C' D) ?% ~. T; l" ?#include <STDLIB.H>& `2 @; Y" N3 ]* [* X
#include <STDIO.H>
5 e1 w0 [; K# G% m7 q* i#include <CONIO.H></FONT></P>
9 T& R$ C: @" N7 k! O. i< ><FONT color=#0000ff>int main(void) # n& R( m! @+ O' \( W
{
. S( @% W4 D8 Y2 H/* request auto detection */ - _: s$ C; W* b) Y1 j' K) h4 t' O
int gdriver = DETECT, gmode, errorcode; 9 W2 X" m. d$ s! g/ |$ z
int xasp, yasp, midx, midy; </FONT></P>' A; ^% n* v3 j4 ~
< ><FONT color=#0000ff>/* initialize graphics and local variables */
e; P4 |9 v) q [initgraph(&gdriver, &gmode, ""); </FONT></P>
l! ]" m/ C' n* K5 c< ><FONT color=#0000ff>/* read result of initialization */
) E8 }" A4 X5 Ierrorcode = graphresult();
) g" j3 x% e. l! k( _& E/* an error occurred */
' Y: L, P1 J3 j, e: j( M3 B. `9 ?* f, E1 Gif (errorcode != grOk) V$ N2 m$ g$ t8 C3 N+ h! l! Y+ W
{
5 C2 B5 [4 I# Vprintf("Graphics error: %s\n", # ~% e0 V! l6 i
grapherrormsg(errorcode));
) W7 ^9 ^5 E0 \9 eprintf("Press any key to halt:");
# }* t7 u& k$ wgetch();
7 V1 q* u) s2 d q7 u f0 w/* terminate with an error code */
4 Z0 k: x5 b1 Rexit(1); . B) l3 I/ `5 v; P$ O
} </FONT></P>
' U- p5 ]) m7 Z3 w1 T& m1 L<P><FONT color=#0000ff>midx = getmaxx() / 2;
- ]+ q" |' j% j7 u4 gmidy = getmaxy() / 2; ( N9 S3 l; `) Y! Y9 W" Q# C& K5 c
setcolor(getmaxcolor()); </FONT></P>% T3 u6 ]6 Q" @' @. A
<P><FONT color=#0000ff>/* get current aspect ratio settings */ ) H* v! l/ [% U: K
getaspectratio(&xasp, &yasp); </FONT></P>0 U* f" y6 ^0 b
<P><FONT color=#0000ff>/* draw normal circle */ & X) s, i. N- v' z* |# j5 W
circle(midx, midy, 100); 8 {; X: S/ o# ]. o2 ]
getch(); </FONT></P>5 p4 s. J% {8 h2 Z. ?+ A
<P><FONT color=#0000ff>/* draw wide circle */ ; \- f, ?+ l/ F8 Y# ?! p6 o: p0 y
cleardevice(); ! P6 D1 L' {! d5 U1 ^8 M
setaspectratio(xasp/2, yasp);
0 [% t7 ?4 M: O [/ @* {, Q6 hcircle(midx, midy, 100);
+ Q1 f# P" ?4 P, o) K/ Ggetch(); </FONT></P>" M D% c3 n) l+ X
<P><FONT color=#0000ff>/* draw narrow circle */
) |! w& D* Q) C; G6 Vcleardevice();
5 d; d' p# j, S; @2 @6 v3 ?setaspectratio(xasp, yasp/2); 5 p8 H6 M7 [0 [" ?' M$ ]1 f
circle(midx, midy, 100); </FONT></P>
1 L- U+ ]. U" C& C<P><FONT color=#0000ff>/* clean up */
- G! \+ k: _7 f# w G3 j( Egetch(); ! f _4 k F/ H6 j u$ O6 Y4 L
closegraph();
. c0 _) w {) }return 0; 5 n, C. m6 Z8 W4 G F! H
} z P! }$ C. }
</FONT>0 p4 [; {! r; ]. c) M* w
7 ]3 c' }1 p. _$ o
</P>/ z6 p% ~! T* m) \* v- i2 @
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>/ a; a6 H4 o- _/ U& n, Q' F
功 能: 返回当前背景颜色
$ E( R6 u: n9 V9 Y6 x1 U; }) t用 法: int far getbkcolor(void);
1 A$ o- r% |1 y1 M# F* q% v- ?程序例: </P>. Q9 ~ p4 n* D' r. V1 {: D) }
<P><FONT color=#0000ff>#include <GRAPHICS.H>% _/ v2 E; g4 z' {
#include <STDLIB.H>
9 e5 q. R. w4 n0 J" b#include <STRING.H>. b% P" i P; Z3 r& D
#include <STDIO.H>
, d' m2 v7 @% v6 O0 W#include <CONIO.H></FONT></P>+ C { V* f: L$ Q; n2 f+ h
<P><FONT color=#0000ff>int main(void)
# M# S; w l6 R) H' Z' e7 V{
0 k3 ~3 P9 i1 U/ m" v7 l9 {4 j/* request auto detection */
- _4 B* {7 q3 p0 Z9 vint gdriver = DETECT, gmode, errorcode;
5 K0 Y$ T* A% L5 S# s& B6 ?/ L" y) z" Zint bkcolor, midx, midy;
$ R" Y" R& a( T5 y! Jchar bkname[35]; </FONT></P>; x3 U; E" o0 e# Y
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 v1 F" f9 Q! |initgraph(&gdriver, &gmode, ""); </FONT></P>
# X* @1 Y' Q/ }/ Q5 ]<P><FONT color=#0000ff>/* read result of initialization */ ; B5 e/ `( }, `7 w
errorcode = graphresult(); & a- R3 n+ A0 [! v# i! O7 S
/* an error occurred */
5 V5 Z: @9 O; `( X/ ~if (errorcode != grOk) ' N8 E; S5 ~0 a% Y) Q- e% u* B
{ ' |8 k1 b% m# S. X0 O; p9 W5 |3 j
printf("Graphics error: %s\n", $ A- h* K9 _" |" D% i: U% I
grapherrormsg(errorcode)); / K7 P5 @$ w! ^& _' b
printf("Press any key to halt:"); 1 j% G! u7 x$ W0 v
getch();
2 M# {, M5 X1 _: u! M8 ~0 G/* terminate with an error code */
0 t7 V p" z' Q- g0 wexit(1); ) r: U% F6 q) n3 }
} </FONT></P>0 j' Y! j, n: t. \# w# A
<P><FONT color=#0000ff>midx = getmaxx() / 2;
! j+ {" @+ }1 s" C* c W, ~. X+ B, ymidy = getmaxy() / 2;
; j+ m% T# `7 o0 g1 u- [' z [- T# jsetcolor(getmaxcolor()); </FONT></P>
$ Z4 @0 u! _ ?7 K<P><FONT color=#0000ff>/* for centering text on the display */
+ E3 h* r1 Y# B! Z, Fsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
' @8 H. D' a) p<P><FONT color=#0000ff>/* get the current background color */ ( D9 N& r) t7 l6 z
bkcolor = getbkcolor(); </FONT></P> y0 X& C# u4 x3 E1 N' [
<P><FONT color=#0000ff>/* convert color value into a string */
) b! u3 z1 L( V' L0 n4 y# I, n7 witoa(bkcolor, bkname, 10);
6 g' r8 `3 s5 }- \2 nstrcat(bkname,
: d. X* o4 Q. S$ m# I7 O" is the current background color."); </FONT></P>4 n; F: b& |1 ?4 B: L
<P><FONT color=#0000ff>/* display a message */
& R7 Z5 s, Q( J0 N! x: {7 i0 Touttextxy(midx, midy, bkname); </FONT></P>4 U1 m1 _! E, K, n: e5 E& L
<P><FONT color=#0000ff>/* clean up */
8 ~% H3 k3 Z9 L! Q9 }( @; Rgetch();
: o9 U/ j1 E% v2 Dclosegraph();
9 q& Z3 j% N- N+ ]$ r& Yreturn 0; ( _9 x. ^* u: m8 T
} 7 k( @2 X' B9 _1 ~3 M
$ o" \& h& D$ f
</FONT>
2 Z7 G; r, c# q% k! u' s</P>
( b8 H7 M5 X7 @, V" r6 D& S R! f<P><FONT color=#ff0000>函数名: getc </FONT>
. d/ U; n: i: q6 n! }功 能: 从流中取字符 " I- N# K3 Y6 v! |9 {
用 法: int getc(FILE *stream);
1 M, q0 G1 _; o7 i程序例: </P>- L' ^) w1 }& r% U, c- r
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>6 s: M# P9 Q* @9 b6 R- e
<P><FONT color=#0000ff>int main(void) 3 d" Z# u: s$ V/ r8 B
{
) b5 S; Q+ L3 S! w, A$ dchar ch; </FONT></P>: d: ~+ Y/ k& _/ L W
<P><FONT color=#0000ff>printf("Input a character:"); 6 [8 M" T* d) M1 m. w8 ]6 D
/* read a character from the
1 l/ N' W7 i+ }8 i: ?standard input stream */
# H( z. ` _# B% ^% L( Z: y( u! Ych = getc(stdin); 1 b6 T& B3 ] i- i: ?& _; O. O0 o
printf("The character input was: '%c'\n",
O G1 e# G) q' P" och);
8 i2 T6 p4 _$ dreturn 0;
D8 i- d, h4 [+ _} * X! e2 i6 T9 _8 |% t# n8 g' D; C
6 L* Z1 _! X: \4 F. O
</FONT>3 [1 r- n$ s0 l' r* _8 n9 N
</P>
+ m: I& Y$ I; o+ K# B. ]# N<P><FONT color=#ff0000>函数名: getcbrk </FONT>
/ l7 T, R% q( \6 d" l' I) j2 s3 F- T功 能: 获取Control_break设置
! n" _+ `+ h1 M用 法: int getcbrk(void); / b K* r+ Y* W8 u9 a3 T4 R3 z1 z
程序例: </P>
7 f2 l0 G$ j3 U9 y, V# r% O<P><FONT color=#0000ff>#include <STDIO.H>( h2 A+ r1 i# V% i
#include <DOS.H></FONT></P>" o5 k# \0 k' ?! Q$ G) O; h! P; K
<P><FONT color=#0000ff>int main(void) ! i. a ~6 x6 P# a5 d
{
! N0 |/ C; k- Q! @% f. r3 e ^" hif (getcbrk()) % X" e- ?0 ]7 v: _2 t6 C+ p
printf("Cntrl-brk flag is on\n");
, ~' s g \0 R1 r8 K# {else 8 N5 X, R& H1 J8 J2 u
printf("Cntrl-brk flag is off\n"); </FONT></P>5 {+ N3 T( ^* I7 T
<P><FONT color=#0000ff>return 0; ( A+ y, f) o# {$ _& {: j: U" U
} </FONT>/ n* T \6 ?2 Y# @4 @ i1 ?
) R& r+ \) a7 H4 v; Q3 L' n# V</P>! B. T2 I3 G' i
<P><FONT color=#ff0000>函数名: getch </FONT>
! Y+ g! Q, [2 l8 e* Z功 能: 从控制台无回显地取一个字符 0 f" Y# Z: z+ z) Y5 L$ v" x
用 法: int getch(void);
' U4 G4 B, l; _" W程序例: </P>: \2 f, T3 {2 {& ?7 y4 X
<P><FONT color=#0000ff>#include <STDIO.H>
& i+ p) k* y* U: c1 v) O1 h |4 Q6 T#include <CONIO.H></FONT></P>* q6 v0 b2 u) I0 b; w
<P><FONT color=#0000ff>int main(void)
+ U2 y0 y9 |. w2 J8 p: F D{ ; v$ e3 o J9 i; C
char ch; </FONT></P>
& T3 l7 H2 c$ H; D. r; [<P><FONT color=#0000ff>printf("Input a character:");
& V3 i1 g/ E: |: _% }! }ch = getche(); s( Q" @; m7 O7 t' F! t- Y" [: O
printf("\nYou input a '%c'\n", ch); # A; h5 u6 B0 v" Q( m/ S
return 0;
$ o$ M& D; \. g" z8 ]' ]}
/ w2 h' T# z0 i3 J! k2 L/ h/ |. ` u: d) s2 E0 q
</FONT></P>
1 U+ S$ o) N+ u0 y<P><FONT color=#ff0000>函数名: getchar </FONT>
1 \' C0 i4 h7 a' v1 f T功 能: 从stdin流中读字符 : p' h7 m1 C7 [8 h! S
用 法: int getchar(void); ' j$ ^. I# T' J
程序例: </P>
& ?$ H" C+ g5 C t. Z' v<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
* }. V) |' i( m<P><FONT color=#0000ff>int main(void)
1 x& f# M9 m- \. Y" y h. R{
+ j: x( U2 e8 ]. b( Gint c; </FONT></P>8 c3 |9 U" c) Q& ]: F6 Q
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
' T2 [' k" P- ~% A: r7 g3 gis line buffered; this means it will
( P5 }4 O# e ]not return until you press ENTER. */ </FONT></P>+ n& W! j. A# O; V6 j
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') - {8 y$ Y" F7 s1 H2 T; ~7 \9 y
printf("%c", c); </FONT></P>6 X: j3 H+ N! x! x- U; a
<P><FONT color=#0000ff>return 0; 7 e6 L8 z3 d7 h9 M
} ; c& _% i- X, l7 e& c' u( n
</FONT>
6 G) G( A* `' r. W8 ?0 l- P; ?, `</P>
) y3 s5 G+ ~; H! [' V- S<P><FONT color=#ff0000>函数名: getche </FONT>
' [& w0 e/ z0 {3 h, e: e1 M* n- {功 能: 从控制台取字符(带回显) d4 J! ?! Y8 P2 D% Z0 e5 P/ B7 Z. Z
用 法: int getche(void); 4 O! c7 P% E F, H2 T9 t Q
程序例: </P>0 z. f7 G3 T" I7 I" v8 k
<P><FONT color=#0000ff>#include <STDIO.H>
Y4 u) ~1 i* `$ N7 d3 ?#include <CONIO.H></FONT></P>
2 v5 v( d( u- | d<P><FONT color=#0000ff>int main(void) , c5 p1 j. I, W4 z3 x+ w" u
{ 0 K7 O0 C' m% o* z f9 \
char ch; </FONT></P>
! g2 r9 S9 P! u* s* c t4 i5 s<P><FONT color=#0000ff>printf("Input a character:");
% _" n+ Z: j6 l+ o" Wch = getche();
! b4 n6 G( L; j- i4 mprintf("\nYou input a '%c'\n", ch);
- @7 J) @( G9 F0 Creturn 0; ' I" j& W2 R, ^6 Y* B* Q
}</FONT>
' \5 w A0 I% Q9 R& K3 b4 R* d. `" R7 {) b8 w2 @$ E3 ^7 s
</P>5 i: O; W4 i4 f$ k! T7 u. z' Y
<P><FONT color=#ff0000>函数名: getcolor </FONT>0 G- M& I, L2 x! H' a
功 能: 返回当前画线颜色
' L' g$ e8 p! w( e* h) B) Q) T用 法: int far getcolor(void); * k; b2 y2 _2 A( K
程序例: </P>% C1 d2 U: V/ a4 H. \4 j
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, ?9 `( ]( c) y: U9 \#include <STDLIB.H>
, E, K+ B1 P; `% c# w#include <STRING.H>9 r+ J8 {3 i, v h, b
#include <STDIO.H>3 j, N! n; V% \: C* f- I0 O
#include <CONIO.H></FONT></P>
+ \5 j( [( r( o* H1 h# F<P><FONT color=#0000ff>int main(void) 3 J3 l4 p- h' d4 ^- `
{
3 t# z( |$ ?5 a) l5 W, W" x/* request auto detection */ , M* }# v' O( [" a5 E- a! t' c4 q
int gdriver = DETECT, gmode, errorcode;
; \( B& x1 f8 l# | wint color, midx, midy; - z6 v8 U2 {4 @) f) U* a% t
char colname[35]; </FONT></P>) L; x" f" D: K3 S3 X& j H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) W5 F e7 ~ i7 M2 v% C
initgraph(&gdriver, &gmode, ""); </FONT></P>( `1 o$ u7 X& F: ^2 Q) W* v! y& x
<P><FONT color=#0000ff>/* read result of initialization */ 6 w( W# b3 _1 e ?3 W: B" W: s
errorcode = graphresult(); [- g7 |5 z" [1 |( t( b: Q7 y" F
/* an error occurred */ 3 ]- R5 |# X) P6 u0 N8 \3 g
if (errorcode != grOk)
: A) w- }4 z- d2 P/ K0 W{ $ v0 e0 L ]7 m+ o) U+ P
printf("Graphics error: %s\n",
7 J2 p, [3 e" y0 s. z! vgrapherrormsg(errorcode));
1 P! ?, V2 C; s1 v: @: _: Dprintf("Press any key to halt:"); 3 W& }& h5 z1 o. g8 C6 K9 R( G. e
getch();
! C. X) {4 I d: N/ O; H# ^/* terminate with an error code */ 0 w! }( H9 K) p8 @8 `$ f
exit(1);
- P0 `% ^: z6 v( B/ f7 N2 x} </FONT></P>/ M/ P: z+ I6 F* N( `
<P><FONT color=#0000ff>midx = getmaxx() / 2; 3 l( w! o6 E5 ?! w
midy = getmaxy() / 2; # F, f) x5 r/ `" X! J
setcolor(getmaxcolor()); </FONT></P>
, \" x" \6 C! a# c; h<P><FONT color=#0000ff>/* for centering text on the display */ ' S j) \6 B/ L& j3 |# M
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
. G( c* f; \) W: a( m<P><FONT color=#0000ff>/* get the current drawing color */ # D* a( W+ l. |! W& m' B
color = getcolor(); </FONT></P>! B/ M& x6 L) R0 c( ]
<P><FONT color=#0000ff>/* convert color value into a string */ - w% q* i5 S4 z7 O5 i
itoa(color, colname, 10); 6 S" q8 c7 j* M/ K. Y
strcat(colname,
2 X7 M1 U7 q2 D" |8 L! e" is the current drawing color."); </FONT></P>
^2 Q4 f" ]! t7 Q" ` M) {<P><FONT color=#0000ff>/* display a message */
/ w1 ]# C' B7 e$ X' Routtextxy(midx, midy, colname); </FONT></P>5 B' w$ t3 C* V/ h
<P><FONT color=#0000ff>/* clean up */ 5 R5 b9 \# D8 S. P B1 C8 v+ v+ h
getch();
9 F3 X$ B6 V: D9 p4 M2 u+ H3 @closegraph(); - ~3 g6 X6 I% `
return 0;
* s, |! c' w: [ v4 K, y: I} % K) M4 q4 {/ T2 V. \$ ]" H* s
</FONT>
' a# Q' p0 P8 o* w5 B</P>7 j# M' u1 H p! z1 V$ k
<P><FONT color=#ff0000>函数名: getcurdir </FONT>
: m3 ?- n; V( \! ]功 能: 取指定驱动器的当前目录
) z. |/ S1 V5 ~用 法: int getcurdir(int drive, char *direc);
: J! m/ r: a* X. C程序例: </P>1 z2 z! g% h) X' j$ p8 w6 n9 Z; a4 ~
<P><FONT color=#0000ff>#include <DIR.H>
' s, c4 v* ?1 O1 M$ n% G* V#include <STDIO.H>/ x5 y4 k2 a, U4 q5 e; C
#include <STRING.H></FONT></P>
5 \8 ?1 j4 f0 v/ I9 i' f<P><FONT color=#0000ff>char *current_directory(char *path) 3 Y, Z- u/ D) x1 {
{
# v, O3 I' `) k; _! T: p8 y! @7 Cstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */
5 e/ z! F2 {, V8 i% [/ g; ^1 Opath[0] = 'A' + getdisk(); /* replace X with current drive letter */
0 n- A3 u2 A$ r* G/ rgetcurdir(0, path+3); /* fill rest of string with current directory */ ' Q. K3 e, u; V, E
return(path);
2 {9 `9 }8 `- c$ N& z& P1 t7 B} </FONT></P>
( B7 R0 }2 n! Z+ P4 M) S1 q) b<P><FONT color=#0000ff>int main(void)
6 A+ a* k$ T' }{
, E1 ?' @1 V/ R3 z& O1 ^char curdir[MAXPATH]; </FONT></P> h5 p$ r; g1 A) V
<P><FONT color=#0000ff>current_directory(curdir);
/ o+ |( u$ f9 s0 d4 ]printf("The current directory is %s\n", curdir); </FONT></P>0 z( k! w0 u% I. {! z8 h- Y
<P><FONT color=#0000ff>return 0; # q# Q* R1 V& [0 V& u3 Z
}
. w1 D$ ^; a+ s6 J</FONT>
( [( g9 J3 E2 d/ a: Y</P>1 t9 ~/ p) U; I b/ m
<P><FONT color=#ff0000>函数名: getcwd </FONT>
1 T9 n, P8 r P9 o& {+ h功 能: 取当前工作目录
8 H7 s) n2 [/ v0 Q: Q0 c9 {# N用 法: char *getcwd(char *buf, int n);
. P* q+ `+ v4 c' ?3 k) Z程序例: </P>7 S0 I; O/ H1 f6 U9 a* ]
<P><FONT color=#0000ff>#include <STDIO.H>
/ j! `' l) `8 p#include <DIR.H></FONT></P>3 g) ^7 l$ E: I, e) g( c0 {6 Y
<P><FONT color=#0000ff>int main(void)
" `0 o* z, A u4 y. Q& \9 o0 l g{ ! Y& g3 O. [* R! N/ ^# N
char buffer[MAXPATH]; </FONT></P>0 p6 I/ p# O: Q3 }$ v
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
' p: K- z+ c7 m) ]printf("The current directory is: %s\n", buffer); & T% d% j, N- n# x' `$ ]
return 0;
1 O1 {( C* Z- X5 `: ~: @) { F6 ^" M} </FONT>
2 h5 j9 b) M+ f
$ L5 s: ^5 S) F2 ^8 T$ w+ ?; R</P>
~$ T0 r6 G' O+ m; h) |3 h# {<P><FONT color=#ff0000>函数名: getdate </FONT>
v7 n6 n' ^4 y( U# `功 能: 取DOS日期 # A, |, q7 P/ {8 q% G* h
用 法: void getdate(struct *dateblk); 7 U$ K+ J; L3 k; V4 b
程序例: </P>- a" v1 n1 N- D
<P><FONT color=#0000ff>#include <DOS.H>
7 X; d6 H3 L2 f" J1 x+ ^#include <STDIO.H></FONT></P>
. U" j* _4 ~- P2 N<P><FONT color=#0000ff>int main(void)
! ?; p- y" ? X- {4 X1 Q{ ( ?! a, ?; [6 J9 Y3 J; A9 A8 ?
struct date d; </FONT></P>
) d A3 f' ?- x9 H6 ^<P><FONT color=#0000ff>getdate(&d); 8 Y8 F/ G1 a" n7 j; F3 A2 |; ?
printf("The current year is: %d\n",
+ I d4 F. {' q; z' R3 N) P& C0 V+ ~d.da_year);
# r/ t; _+ B- aprintf("The current day is: %d\n",
9 I, j- \. O7 B- B$ [5 Q, Rd.da_day); 5 U! D2 v5 o) L1 B# n9 M" ?3 U$ e
printf("The current month is: %d\n", 9 d$ O5 ]0 ^, w @" @. H( _
d.da_mon); & E, w0 v, ] H' B, G% G6 K K2 B
return 0; ; @% ~* Q* m' U. r- U- v, t
}
0 r: {2 E( G4 G! A</FONT>
3 A2 P, G& l1 E) T7 J</P>
: ^" n" K Q8 [; ?+ O9 z<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
3 A) p$ Y5 u- I6 J功 能: 返回调色板定义结构
# L- a. X* {% x- [/ b& X用 法: struct palettetype *far getdefaultpalette(void);
% Q8 @. a7 W/ \! |3 {4 L程序例: </P>$ I4 T# t5 G7 i" c
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ ^/ y0 N0 t9 S( r( i: S#include <STDLIB.H>
3 R H1 H8 R; C, e4 C! o$ W#include <STDIO.H>
1 `3 G, w: b2 r7 y+ E' C* b a# L#include <CONIO.H></FONT></P>
7 f9 U0 o4 g# t<P><FONT color=#0000ff>int main(void) 8 {; o n. ^4 y- V0 V( e3 G$ h3 T
{ " q' B6 c/ C( } h2 ]; b
/* request auto detection */ 1 ~% r. C1 L$ S* `
int gdriver = DETECT, gmode, errorcode;
+ t/ \& i# t4 J3 zint i; </FONT></P>
7 l% M& Y5 ~$ ~8 m2 E4 p3 P: C6 ^1 k<P><FONT color=#0000ff>/* structure for returning palette copy */ 0 X0 I7 i. R* L% u# y
struct palettetype far *pal=(void *) 0; </FONT></P>
" J( ]1 C1 J" n9 J* X<P><FONT color=#0000ff>/* initialize graphics and local variables */
' w2 p" `+ `2 |2 Z# H; Q Iinitgraph(&gdriver, &gmode, ""); </FONT></P>
! ]' p! |# W6 i, R5 s<P><FONT color=#0000ff>/* read result of initialization */
3 c( I" ?- Z4 Z, j% Jerrorcode = graphresult(); : l) J4 {4 g$ G$ W+ v6 V# h' f
/* an error occurred */
% x6 V1 _8 C6 f( [1 {, vif (errorcode != grOk)
) U# k8 D8 N+ g9 t. V{ 8 y7 d( ~. d/ w/ s" _
printf("Graphics error: %s\n",
! B4 x' Z) d0 ^grapherrormsg(errorcode)); % G' a" R) L6 G
printf("Press any key to halt:");
6 [4 e4 i. K+ k: Lgetch();
4 b) R+ H: P" U1 N7 F/* terminate with an error code */ 5 p a7 {, g! O3 X, W
exit(1); 9 o* W, A+ g+ ^. v4 X
} </FONT></P>+ G+ @( U+ c- O3 P( _
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
6 Y) o; e X2 r h* e<P><FONT color=#0000ff>/* return a pointer to the default palette */ ; ?; z8 I% u& {$ |1 W
pal = getdefaultpalette(); </FONT></P>
3 p4 n% F: p+ S' Z1 g7 q! u# N# K<P><FONT color=#0000ff>for (i=0; i<16; i++) ; {* C7 P' L3 ^" U5 d! o7 D! h! x- O2 O
{
6 E1 g$ G2 y% C) s( x/ jprintf("colors[%d] = %d\n", i, / d: o& D, h, S9 C1 p- ^/ o
pal->colors); 2 D! c' P* L0 G/ Q
getch(); 1 f3 b4 u0 @3 N! _
} </FONT></P>( |) C1 B" Q. a, k2 y
<P><FONT color=#0000ff>/* clean up */
/ H! e9 H4 @/ _, d. K r3 Agetch(); ' ~( o" S7 x- {7 t3 \
closegraph();
1 e( G. i0 H: r- W% b9 v* C: `return 0;
# } `8 J3 m$ W0 J# B$ Q4 y} 5 j5 y# ]! N8 A+ z& u
</FONT>
3 L7 K5 o) R: B</P>
5 @0 I/ M7 j8 c2 `( j+ \( i# N+ [4 L<P><FONT color=#ff0000>函数名: getdisk </FONT>' V! w" A4 G& ?* `& t; a0 J
功 能: 取当前磁盘驱动器号
0 [( L2 R5 U5 F2 V5 S1 q用 法: int getdisk(void);
( ~) C' s7 x& ^4 C; z; b程序例: </P>
" y% T& u1 t. L- I<P><FONT color=#0000ff>#include <STDIO.H>
/ S! K0 s9 ^: E#include <DIR.H></FONT></P>% K/ C( j3 }+ G9 Q2 Q9 t
<P><FONT color=#0000ff>int main(void)
# b2 z) @2 c2 o! U; ?/ \) I{ ) h% w& H% l4 u, z
int disk; </FONT></P> \& y1 Q7 P7 e% y+ D3 b# M
<P><FONT color=#0000ff>disk = getdisk() + 'A'; 3 j+ [& s" J; ]
printf("The current drive is: %c\n", ; Y4 {9 C" b. g' d; J9 T" N3 E
disk); $ Q( D" V9 r& q |+ A; S
return 0;
. N, o5 q, u" Q& L) |0 l} 4 [, l2 n% n4 C+ r! K t9 Z9 G
2 k% p. o& D8 r; ~ J$ ]: w
</FONT>
( n* E- c4 F! P+ R; t9 z# L+ `. z</P>
0 |) J: F" W1 d3 c* o$ ^5 S<P><FONT color=#ff0000>函数名: getdrivername </FONT>
6 h; A$ n) a3 N功 能: 返回指向包含当前图形驱动程序名字的字符串指针 ' |5 f3 Q. D( h3 d* D
用 法: char *getdrivename(void); 0 j% f, ^6 E! G
程序例: </P>, D# A0 C$ N7 E) M. L/ j- o
<P><FONT color=#0000ff>#include <GRAPHICS.H>1 }3 i7 c/ y& x3 ~. A
#include <STDLIB.H> s- x, q' Q+ z
#include <STDIO.H>
& z1 B* g" c' ]4 T a9 O; h% [#include <CONIO.H></FONT></P>1 F! b1 M+ w- d
<P><FONT color=#0000ff>int main(void)
6 f, J' o" W- [9 y& I{ 7 f9 y/ F0 {0 K9 E! n
/* request auto detection */
& L; q9 g0 l6 |7 ~& Qint gdriver = DETECT, gmode, errorcode; </FONT></P>4 f( R) ^- j# T. A9 G: h
<P><FONT color=#0000ff>/* stores the device driver name */ + D8 V }/ I8 v6 Z# i/ |5 Z, G
char *drivername; </FONT></P>
! d4 }9 V' W, a2 L, H l6 l<P><FONT color=#0000ff>/* initialize graphics and local variables */ - W9 F W1 N! J" z
initgraph(&gdriver, &gmode, ""); </FONT></P>
$ x/ ~7 `( g: T( p) b4 f% A<P><FONT color=#0000ff>/* read result of initialization */
0 z1 O5 o+ x' U6 V1 Z7 t* [errorcode = graphresult(); 9 p5 p/ b8 ~3 H8 [" Y5 L
/* an error occurred */
4 q! Y8 v, X8 B8 R% ^if (errorcode != grOk) * [2 F# k( i& ~9 p* ]
{
/ d5 c1 `2 |7 vprintf("Graphics error: %s\n", ( \$ d4 j# @" U0 b3 Z% I; z! i9 ^
grapherrormsg(errorcode));
* s$ W! l! M6 {' r6 ?printf("Press any key to halt:");
4 t1 B. p$ P) k, Bgetch(); & u ~, Q1 S2 {% C% Z! D
/* terminate with an error code */
! H$ A$ h1 A; R, pexit(1); $ T+ J! N7 W3 B5 Y
} </FONT></P>4 J0 t1 e: r% j3 g5 ?% n
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>, ~' `% H' c6 i/ y
<P><FONT color=#0000ff>/* get name of the device driver in use */ # W( M0 R/ O/ Y! B- A
drivername = getdrivername(); </FONT></P>0 }- `6 L) X8 q4 q
<P><FONT color=#0000ff>/* for centering text on the screen */
9 b+ k8 Z- c; Bsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
* c/ P- a* D+ L( n# ^<P><FONT color=#0000ff>/* output the name of the driver */
* M1 C1 M0 Q7 u* L8 u, C7 louttextxy(getmaxx() / 2, getmaxy() / 2,
$ s4 x6 h8 i$ a) l5 K5 mdrivername); </FONT></P>7 H5 k* F: z4 G7 `. _# d
<P><FONT color=#0000ff>/* clean up */ ( r m: I: o s8 ]% L$ p, E
getch();
" ?# T2 q% e$ ?) ?" \5 I+ D6 hclosegraph(); Y8 s# T& _2 P0 m1 p1 c9 S
return 0; 8 w: M0 Y4 Z% W. p
} $ Y: C5 H( D3 w
</FONT><FONT color=#990000>- m8 h) P+ a4 R6 Y2 d
</FONT></P>% }& d) S3 q; l* \) W: W; r6 D
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>* V& q" A! H T5 A2 k( x; c
<FONT color=#000000>功 能: 取磁盘传输地址 5 K2 q# g7 n) I* v6 s n% v
用 法: char far *getdta(void);
, z: V. d, Q" {程序例: </FONT></FONT></P>
) y( U! ^# `& \2 Q<P><FONT color=#0000ff>#include <DOS.H>
# t' t' ]8 }/ [& q$ U5 }2 `: k* e#include <STDIO.H></FONT></P>
2 u4 \4 b1 e g2 T7 f<P><FONT color=#0000ff>int main(void)
% X( d) j( k$ B3 Y' g7 D{ 8 ^. H# U \2 d4 U
char far *dta; </FONT></P>
! o7 O$ [% e; s$ y/ Y& W<P><FONT color=#0000ff>dta = getdta();
! r8 T+ m# K5 [printf("The current disk transfer \ 2 X6 M2 H: h$ G2 k3 H
address is: %Fp\n", dta); 3 z- t. k, ?) e% A1 l. l& g
return 0;
, G a+ D% E/ ]) s$ A; U( M$ |} 0 g, w u9 @$ Q
</FONT><FONT color=#990000>6 A- P; v; g5 x. {0 ~! H
</FONT></P>
+ E1 G9 Y) `; _* i7 R<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000> d- @/ ~5 |; c6 Z4 s
<FONT color=#000000>功 能: 从环境中取字符串
. f) M7 f; m* T$ s用 法: char *getenv(char *envvar);
9 r+ N/ V# M, P. V2 E8 j程序例: </FONT></FONT></P>
_1 g! a6 B \6 J1 \- q<P><FONT color=#0000ff>#include <STDLIB.H>/ p- u1 A1 M7 r$ h/ c5 U
#include <STDIO.H>
) K6 q# d# J- n0 g7 V2 a$ `</FONT></P>
. t1 R0 G) H# R' C* M<P><FONT color=#0000ff>int main(void) ! S: b3 n- \4 `$ X) k5 Q
{
s3 [/ [* M$ r& H" ^char *s; </FONT></P>
8 J7 q. Q3 c$ j<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ " c i' V% F% g! p* S2 b( ~9 W9 l6 c
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>6 p4 E8 R6 r7 b7 ~# T# P3 a, C/ m
<P><FONT color=#0000ff>return 0;
! N' j% ?- B3 l! a; x} </FONT><FONT color=#990000>6 ]2 l8 j+ h0 F4 K) i
3 `( H9 w1 a/ ?) E' G) g( ~ u+ T
3 Z( Q# M5 o: E</FONT></P>
" u8 }: l4 G/ h<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>0 s# I* e3 z4 m' I
功 能: 取文件分配表信息 , T4 c6 E' K9 z+ R
用 法: void getfat(int drive, struct fatinfo *fatblkp);
: L& W5 v, t& Z# D$ Z* X, N程序例: </P>( m- D' u8 |1 F$ v
<P><FONT color=#0000ff>#include <STDIO.H>% p+ r! t+ t" P: D& I
#include <DOS.H></FONT></P>
) u# r9 V' h+ K4 E1 K$ h1 D" a<P><FONT color=#0000ff>int main(void) " q+ w7 K/ @, x! ?. T) v) B4 W8 f: M
{ : U! y5 J: K* p' f! q
struct fatinfo diskinfo;
1 W7 `0 E i9 ?7 P3 nint flag = 0; </FONT></P>
# y0 B6 d* A' S" F& H; P) I$ `* O: t<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); & a) g# Q% q# o
getchar(); </FONT></P>: h9 ~1 _# `: ^- N/ k) ]4 {
<P><FONT color=#0000ff>getfat(1, &diskinfo); 3 I$ j+ d* a% {! i& W
/* get drive information */ </FONT></P>
) ]& k$ j M$ a0 {: {! | U6 Q<P><FONT color=#0000ff>printf("\nDrive A: is ");
/ ~ M4 F5 [! E4 u8 B4 C2 V! k$ Lswitch((unsigned char) diskinfo.fi_fatid)
0 i T3 q1 S0 t" g1 k{ 8 _1 G9 o& _+ t) e. j5 m. P
case 0xFD: 3 |! A6 m, }- e' B, Q6 U" e9 ~
printf("360K low density\n"); # ?8 \2 F) S* h F2 H: ^
break; </FONT></P>
7 N) A. Q0 l% F' a1 x% J) k<P><FONT color=#0000ff>case 0xF9: . O7 S/ T. |, V o; V
printf("1.2 Meg high density\n");
- p0 v) K1 Z) @$ ubreak; </FONT></P>
) D% j& c' p) o0 G9 V' x C G* [<P><FONT color=#0000ff>default: + a) X" a9 g0 j: G. A( H
printf("unformatted\n");
: {# ]9 Z2 s- o- Jflag = 1; / O, W0 z- r8 z4 e; g- ^: l
} </FONT></P>- h1 l3 j/ U5 |0 F
<P><FONT color=#0000ff>if (!flag)
7 u3 _ P9 I5 B H{ 5 `5 }* r: r' K: n; c% k& Q
printf(" sectors per cluster %5d\n", ' m% X( f8 n+ S ~: G, g
diskinfo.fi_sclus); H2 S j w- z: k- G+ v
printf(" number of clusters %5d\n",
9 Q0 U* L( N% o/ Adiskinfo.fi_nclus);
( m; v8 m, m' Gprintf(" bytes per sector %5d\n",
2 b3 [& P/ Y8 K: E# e8 M6 Tdiskinfo.fi_bysec);
# m$ X4 s% x( r4 Y# Q& ~+ b/ L} </FONT></P>/ s8 i1 o. S/ U/ A
<P><FONT color=#0000ff>return 0; " F- I: |3 t* y0 r
} / |( \9 S8 s2 d; k- q% ~% t" E
</FONT>1 I0 R* k( g( }/ D
</P>7 M' v% O6 x, P) b$ L7 L
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>1 x! u' O( ^5 b- {5 @) l
功 能: 将用户定义的填充模式拷贝到内存中 $ T) t& e9 T8 k
用 法: void far getfillpattern(char far *upattern);
1 O9 {# K' b6 I( F) l. y程序例: </P>
& a0 H% q C3 E( ~<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 { y. x8 p( f+ c#include <STDLIB.H>( u; U! h1 y, w
#include <STDIO.H>
+ k$ I- P5 F9 l9 u1 z#include <CONIO.H></FONT></P>
) u, E% n5 x0 T6 V<P><FONT color=#0000ff>int main(void) J+ j4 w3 a4 T# J% C) g
{
5 o" o9 A$ p1 w( M. V/* request auto detection */ . p4 n: v9 _7 X( j- D, m! ^
int gdriver = DETECT, gmode, errorcode; * j' L" s I" `
int maxx, maxy; + B" z% m6 r! w8 P
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
2 k& p' w" @2 ^: Z- m<P><FONT color=#0000ff>/* initialize graphics and local variables */ - l1 k$ D0 Q' ?7 p- `9 B" E
initgraph(&gdriver, &gmode, ""); </FONT></P>
' K. C) \3 Z9 Y" n<P><FONT color=#0000ff>/* read result of initialization */ % ]) G) ?' |. e% A# y b
errorcode = graphresult();
: Q1 ~2 f# m a8 C- Z( c% V4 mif (errorcode != grOk) /* an error occurred */
$ o. }: H8 t/ A' j4 M, \{
2 m5 M: S, a: S% Q; p, Y5 sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ Z# Q+ C3 v7 K `
printf("Press any key to halt:"); 2 f. @+ k3 `) z% J
getch();
3 i# S' r7 j. k5 B2 s0 Cexit(1); /* terminate with an error code */ + x; Q: o1 x) e+ d4 d* W
} </FONT></P>1 K3 A: W0 o' y& d* H
<P><FONT color=#0000ff>maxx = getmaxx(); 7 z9 w2 G# b9 S" D4 C
maxy = getmaxy();
9 }$ B" C/ h5 [& jsetcolor(getmaxcolor()); </FONT></P>: n/ b" O2 S. r, {
<P><FONT color=#0000ff>/* select a user defined fill pattern */
8 G- ?. @3 C! V9 Xsetfillpattern(pattern, getmaxcolor()); </FONT></P>
* M. h L7 m0 T, J. K<P><FONT color=#0000ff>/* fill the screen with the pattern */ : A- V- L7 i* \3 r
bar(0, 0, maxx, maxy); </FONT></P>5 p2 M2 X7 e3 T" _6 u! T+ z
<P><FONT color=#0000ff>getch(); </FONT></P>
) b7 S# n* n' n2 i; K5 j# w+ \% J<P><FONT color=#0000ff>/* get the current user defined fill pattern */
1 m) Q/ P" w0 G. W5 g5 S7 Egetfillpattern(pattern); </FONT></P>
) y. S' A; J" y6 z! k" Q<P><FONT color=#0000ff>/* alter the pattern we grabbed */
" v$ _% K: ~ F+ P+ `: l8 hpattern[4] -= 1;
0 x# e: f, v% q+ v7 ]pattern[5] -= 3;
4 C, c2 V. ~) ^# o& G$ B- z1 q# opattern[6] += 3;
8 X' {8 _' x9 C" r) R+ Ipattern[7] -= 4; </FONT></P>
* D. r0 d* q" ?7 f: z1 ^<P><FONT color=#0000ff>/* select our new pattern */
# ]+ {# ^- ^: M& Xsetfillpattern(pattern, getmaxcolor()); </FONT></P>1 z% ?: ]/ u* m" Z3 H
<P><FONT color=#0000ff>/* fill the screen with the new pattern */ * I' d! k- H3 ~, n5 ^! G
bar(0, 0, maxx, maxy); </FONT></P>
9 L* k) @3 R: N- \ A2 h<P><FONT color=#0000ff>/* clean up */
0 |" \1 |! `" o! J; H: Dgetch(); # Z: r& i2 c* W. M# w5 \, R4 ~5 e0 S
closegraph(); , X p! Q/ {. P3 ] u
return 0; 0 c3 y' N8 ^$ _$ _ t
} ; g3 Z: s! D* |
</FONT>
3 c0 L2 c! S ?, J. |4 H: R+ L7 Z</P>
6 a! G$ J# G" ]4 B, p. W<P><FONT color=#ff0000>函数名: getfillsettings </FONT>2 ^2 {. y, C, x) |1 {
功 能: 取得有关当前填充模式和填充颜色的信息
8 W# p$ M5 T* j: W7 Q# q( J用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); # Y# ?- P) g3 M/ z) m& @
程序例: </P>' O" Z3 U8 d; A! F1 Z# c
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 B: [ O! i1 s1 i* g1 p#include <STDLIB.H>
. |3 T2 i& Q. I2 H; n) \/ s#include <STDIO.H>
8 d! q" X! s' W7 [; B#include <CONIO.H></FONT></P>
; t. O9 U* o0 J, ]/ [9 \<P><FONT color=#0000ff>/ the names of the fill styles supported */ " D" f: m" U H$ b# l/ b
char *fname[] = { "EMPTY_FILL", # X; G1 ^7 `+ F6 z% @# ~
"SOLID_FILL",
& v0 {4 j# X& k"LINE_FILL", 2 F8 Q& ^3 @3 r3 @
"LTSLASH_FILL",
* D7 `2 z; x! q/ R"SLASH_FILL",
. l. i# j: ] w# z9 B( l2 w+ I"BKSLASH_FILL",
! M1 I8 I: l5 m! P4 S( d% y"LTBKSLASH_FILL",
( d: j# i% g7 _* X"HATCH_FILL",
% u, {8 z0 X, _! J# V"XHATCH_FILL", 4 K4 [) G5 p0 e$ Z* ~+ {
"INTERLEAVE_FILL", / E) r8 u( ]4 g6 o8 {0 h. P% t
"WIDE_DOT_FILL",
/ }9 b" ~# f, D8 a. S( G"CLOSE_DOT_FILL", 8 {1 A, O7 X4 M
"USER_FILL" ) O3 u( H5 Q2 X" w8 x$ w
}; </FONT></P>
* W2 b5 g K( L3 y+ G6 X8 x<P><FONT color=#0000ff>int main(void)
8 h& D0 R" ~, u @6 T" x8 o{ 8 E! Q2 B! d/ ?/ t- E _+ q# x
/* request auto detection */
2 z( \1 h- S) ~+ g) L* sint gdriver = DETECT, gmode, errorcode; # b( k+ w) U, @: H- ? C
struct fillsettingstype fillinfo; 0 ^: x i" t/ v9 i6 m o
int midx, midy;
]3 I) N' @$ C5 ^# O- @' Fchar patstr[40], colstr[40]; </FONT></P>
6 h' }% }0 g, m' ?: y; `& b<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 F( W1 z8 ]' U# x" N! o% |$ sinitgraph(&gdriver, &gmode, ""); </FONT></P>5 B+ `5 H5 v* T9 P4 y
<P><FONT color=#0000ff>/* read result of initialization */ 5 [; l9 ]. m1 o7 s! {( R0 \1 ]4 m
errorcode = graphresult();
! R4 R4 t# C$ F: D8 ]if (errorcode != grOk) /* an error occurred */
. z" C1 r$ _0 z# [{ 2 m0 z: }7 z: ?# ?9 S- z3 t
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 Y1 y; h6 v* V2 t( Q n s1 k
printf("Press any key to halt:");
# t0 D3 d3 p/ u! q2 B. A7 G; ^9 Vgetch();
3 d, a+ {, S& P, d8 i ~' qexit(1); /* terminate with an error code */ ( W) U! C# f: g( n
} </FONT></P>3 f! \9 q0 S$ I8 W/ n1 J9 r
<P><FONT color=#0000ff>midx = getmaxx() / 2; ) s3 {) C" I* I6 ]0 n J3 D5 Z
midy = getmaxy() / 2; </FONT></P>
! K9 s" j: c( C% b<P><FONT color=#0000ff>/* get information about current fill pattern and color */
+ f% S! b7 L, I* Ugetfillsettings(&fillinfo); </FONT></P>! U& ^( ~$ _; q& r, G+ Y
<P><FONT color=#0000ff>/* convert fill information into strings */
# g7 W& `2 ~3 T! nsprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); 7 X3 ~( q* c& u" n% X4 B1 A
sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
: s! h! s5 t0 z7 W, f<P><FONT color=#0000ff>/* display the information */
( }3 S: {* T H. z0 S" d+ D$ l7 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); + i+ ?; S9 O+ ~0 y( x& J
outtextxy(midx, midy, patstr);
5 ^+ q* ~$ P% Q* ~0 K. Zouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
$ V8 X0 o- t* A<P><FONT color=#0000ff>/* clean up */ % r5 f% k! L7 W6 S+ s6 w3 s' L* C' V
getch();
- z2 @' l# v2 I& U& X+ ^closegraph();
/ p) o8 j3 V5 ?return 0;
+ X% ~+ U0 ?) d2 N} - _: i* ~" \6 E" S6 y
</FONT>1 c5 l7 K0 ~) q, S4 ?
) D; R2 X, C$ Y</P>+ ?) i3 j# K* _/ A& b" {$ V; U
<P><FONT color=#ff0000>函数名: getftime </FONT>) Y- L7 A' |2 R& p
功 能: 取文件日期和时间 ! H7 Y; c, {% m) W8 J i
用 法: int getftime(int handle, struct ftime *ftimep); " _( Q# s! H5 l) ?% D( x
程序例: </P>7 W4 g7 m/ U9 ]+ o, |
<P><FONT color=#0000ff>#include <STDIO.H>
, I) B2 T& b8 F#include <IO.H></FONT></P>
% ^9 L( e% X. g) e/ N" r<P><FONT color=#0000ff>int main(void)
$ O* P, G5 j7 f* |{
5 g9 L) O% h F& C7 g- l% IFILE *stream;
2 s' w' K& y% R7 X Gstruct ftime ft; </FONT></P>5 P5 ?5 a! t1 G# ~6 w
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
, Y: b' C" A' z7 h2 X6 d"wt")) == NULL)
: ]4 g c& d: q; P& K9 U# w{
2 {2 \ j7 N- ~2 bfprintf(stderr,
4 g: V" U, ?# M"Cannot open output file.\n");
C% V# V) D( P- W% ~: areturn 1;
; ?) ?8 k: |' M* f, y ~/ k1 e4 q} 9 t ^4 ?7 `$ q9 q9 |
getftime(fileno(stream), &ft); 3 f% o' x3 X# M$ S1 T
printf("File time: %u:%u:%u\n",
, P& l$ H- v1 V; D) e' u3 wft.ft_hour, ft.ft_min,
! X) [- x9 {7 W$ Z4 ]- lft.ft_tsec * 2); : ^# D; |, \; T( @5 _' K
printf("File date: %u/%u/%u\n",
2 z5 ~* ^. z5 m0 Gft.ft_month, ft.ft_day,
: j5 E$ x( s5 M: j0 kft.ft_year+1980); 7 Q7 ?% ~- V! [. Q. j
fclose(stream); G N/ P& X- B( G1 E6 S9 p
return 0;
u" A6 }; Z; E( B6 J7 y+ j" e0 n} 4 M6 x u. L8 }6 K" D+ O& N
</FONT>/ ]0 }% p) K% T$ J3 i4 m
& A/ ^* t; F5 O, S: F1 M: B</P>
& D9 u% Q" h: @0 ^5 P4 K, c<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
1 Y( b4 m# X. q# M! e功 能: 返回当前图形模式 $ Y7 x H% `$ o; r
用 法: int far getgraphmode(void);
7 e- F5 a. |6 i+ L/ G( g' N) k- v程序例: </P>/ b" {5 `2 i! l, i! \# |7 t
<P><FONT color=#0000ff>#include <GRAPHICS.H># Y* G. Q( @9 I% Q. H
#include <STDLIB.H>0 w( H# s1 o( D3 @9 T3 M
#include <STDIO.H>$ Q# J' a; o) m+ O/ N7 v* `
#include <CONIO.H></FONT></P>' q8 s0 ]: c. f4 C
<P><FONT color=#0000ff>int main(void) . w5 r$ c( d, P' g* \$ t6 T
{
3 h) V: e \+ T/* request auto detection */
f6 @4 l' T) L5 L& bint gdriver = DETECT, gmode, errorcode; 0 l2 Y @7 l; W- q
int midx, midy, mode; & z# M4 F7 T4 h8 A3 K, I4 y
char numname[80], modename[80]; </FONT></P>
: f8 L7 }# j+ Z+ S- ^+ |$ M<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 {) D7 H7 v5 _5 E$ z/ P
initgraph(&gdriver, &gmode, ""); </FONT></P>7 R' i7 M" L0 G' Y5 Q. g' b% h
<P><FONT color=#0000ff>/* read result of initialization */ / W& X1 ?6 `2 `9 e
errorcode = graphresult(); + D- ?; g6 l5 t4 r% W, p8 n3 ?
/* an error occurred */ 3 Z$ p+ ~4 z$ Z5 N$ P0 T
if (errorcode != grOk) * L4 v- a! |7 n2 [4 w5 Z! a; d$ a
{
# {5 y$ c$ K# X: ^% c( J' g' mprintf("Graphics error: %s\n", 3 t# s: t! I6 r4 m* V) c0 A) ]7 k
grapherrormsg(errorcode));
! d, d' s e% p& c" ?2 x4 Hprintf("Press any key to halt:"); 1 J9 c& O# I, G
getch(); 9 C) ^6 U8 @6 ]. |# H, z5 t" V
/* terminate with an error code */ ; V9 x' R# _9 _' Y/ M9 @3 t
exit(1); : }9 ~4 t, H# b( b! }. n2 W
} </FONT></P>
) M6 G6 I h& Z6 u: d7 u. W. @<P><FONT color=#0000ff>midx = getmaxx() / 2; % q# ~4 v; Z) `, H
midy = getmaxy() / 2; </FONT></P>
& V# J a6 M! C( i. l! y<P><FONT color=#0000ff>/* get mode number and name strings */
2 B. r7 i& t- H' B6 cmode = getgraphmode(); ! b0 i* l+ N& C" J2 A$ c
sprintf(numname,
0 z: R8 P) X s: p: U* d"%d is the current mode number.",
. K4 o% g& m4 c0 o" b$ Wmode);
/ z5 D! K" C! `2 V3 w4 Wsprintf(modename, # a# E: M$ F0 z& H
"%s is the current graphics mode",
$ N' P( _7 C4 Tgetmodename(mode)); </FONT></P>
+ A6 Z; s: {( c<P><FONT color=#0000ff>/* display the information */ % |5 R0 U7 k+ g. h+ Q" k
settextjustify(CENTER_TEXT, CENTER_TEXT);
3 ~# b. T2 @' jouttextxy(midx, midy, numname); * _) Y& o' |* ^: Z. s9 p5 R9 a$ j
outtextxy(midx, midy+2*textheight("W"), # ?) f0 |4 f7 E( [5 @9 ?" |
modename); </FONT></P>
9 v" ?/ G( g7 Z0 ~<P><FONT color=#0000ff>/* clean up */
7 M( N8 w. w" A, e8 Z" Ygetch(); % G' f. P, D) ~7 n& {- A8 s
closegraph(); # J% Z% Y/ x- i- u
return 0; # [( D' a" P2 v$ h1 y# p
} </FONT>
( H- ?* X/ a& B1 K- c; m5 H& m
. }" d/ I9 W9 |7 W. B# A$ }</P>' _- I- U+ R" k9 ~8 r- L4 U- F
<P><FONT color=#ff0000>函数名: getftime </FONT>! c6 ]. ~5 v* `6 v; K, ^
功 能: 取文件日期和时间 ' l$ P4 D- A0 ?
用 法: int getftime(int handle, struct ftime *ftimep); 0 H& c5 `7 Y: y6 E! t
程序例: </P>+ N4 L8 w/ [' P$ }
<P><FONT color=#0000ff>#include <STDIO.H>
7 _+ c5 T( \8 q4 m# F7 {( J#include <IO.H></FONT></P>. e9 S) V+ V5 K0 ^" @
<P><FONT color=#0000ff>int main(void) 7 M ? @. H3 _1 z9 l; z
{
; b8 F' k3 M! o, |4 PFILE *stream; & i% P6 l0 h; { [$ k2 }
struct ftime ft; </FONT></P>$ w# X% F: N4 \" |. v3 c z+ `
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
! l: E- a9 |9 j4 }2 j2 C2 R u) m"wt")) == NULL) + l7 o+ o* F& }* `) P' E1 H9 s! j
{
! @+ i( D6 w6 k( a7 p3 P& J0 y c% `fprintf(stderr, * O4 M3 J0 j" |6 @7 W ?
"Cannot open output file.\n"); 1 W" H" X9 x- n: _* P
return 1;
5 l. F O1 d1 H} + c6 o& ]5 r! y8 i
getftime(fileno(stream), &ft);
' A- a4 b# N# g# Z" } K: uprintf("File time: %u:%u:%u\n", * h1 b2 ?' F- g& H
ft.ft_hour, ft.ft_min,
4 Z: |$ c2 w( t" g) J8 Gft.ft_tsec * 2); ; N( Z) \9 e8 A! B5 |! r
printf("File date: %u/%u/%u\n",
Q% F. B& |; X6 X F: Q& Mft.ft_month, ft.ft_day, 6 z* I. |" l$ s9 d
ft.ft_year+1980); 2 k3 m" ?% b. ]% z
fclose(stream);
1 r2 w2 L6 v W& F5 Ireturn 0;
( P I3 ?% e8 G# Y3 c& k} </FONT>
7 k7 y% W \2 y! e
: y0 Z1 j/ A) [9 ^1 o" [* E( n( v
</P>/ q, K) p& }. z' @# a) n/ I
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>9 b8 x7 o% q( X4 M
功 能: 返回当前图形模式 F/ b" d# W; ]- r
用 法: int far getgraphmode(void);
; i e; P* i F. D$ J4 x程序例: </P>* ^. J7 n% A+ p8 \+ a
<P><FONT color=#0000ff>#include <GRAPHICS.H>5 O8 Y2 h5 e; e, [' N) {
#include <STDLIB.H>; t! _6 g8 Q$ e3 z
#include <STDIO.H>
6 ?5 B- {2 T+ u8 G1 S* J#include <CONIO.H></FONT></P>
/ g6 E. l0 \$ o4 ~, Z<P><FONT color=#0000ff>int main(void) " J1 L- O4 V4 F+ k! e
{ a' ~' G, w3 g0 J* Q1 F: R7 q
/* request auto detection */
p# k. B) C3 r3 i: b, ?% v) b. S( ^8 |int gdriver = DETECT, gmode, errorcode; 9 n- Q3 Z9 a: t' k7 Y$ ]/ U
int midx, midy, mode; 7 a9 l1 q0 T+ J5 F! T) E
char numname[80], modename[80]; </FONT></P>: V; b/ h8 [) ]3 W
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 [+ u0 d, C! I8 Q
initgraph(&gdriver, &gmode, ""); </FONT></P> A, c* w$ }6 I U1 V" L( F
<P><FONT color=#0000ff>/* read result of initialization */ ' }2 r B: L" l7 E2 b8 { D
errorcode = graphresult();
b" O# G1 G; {' U2 W8 T. O0 z/* an error occurred */ 8 s# }, f+ o5 H- D9 P) L
if (errorcode != grOk)
9 a3 q$ H" z5 k" r- q# o* o% U{
2 v) K( u" s* x0 p- zprintf("Graphics error: %s\n",
" N6 a, `$ o# S- [9 `grapherrormsg(errorcode));
" [; `( l I( Z P- Hprintf("Press any key to halt:"); # A6 w7 n) _6 a" q. _) X. R) e5 _
getch(); 5 P9 [1 i7 p( B
/* terminate with an error code */
; A4 j- T7 x2 ^- n7 Uexit(1);
& ?# J8 P5 ]0 p! e! ?+ Y} </FONT></P>
5 n0 Y u- o2 H, M( a$ U( F<P><FONT color=#0000ff>midx = getmaxx() / 2; - D5 U9 z; v. U C* k5 B: @1 N
midy = getmaxy() / 2; </FONT></P>
; U# u( ^& k5 \* y<P><FONT color=#0000ff>/* get mode number and name strings */ - z3 {( t* M' i% p2 j* @
mode = getgraphmode(); . y. i$ y, L; u$ K8 O( @
sprintf(numname, , y- R7 S, ]8 o, n9 B
"%d is the current mode number.",
& I4 x! ?; u0 N5 Q D# Qmode);
$ d& d3 z2 |& q- }5 { A7 ^1 bsprintf(modename, ) e$ Y- H% W- C! h& _$ K
"%s is the current graphics mode",
% ?5 v: ~8 m, ^getmodename(mode)); </FONT></P>, y8 r4 k) N. g+ j/ ^
<P><FONT color=#0000ff>/* display the information */ ' u- }: f" K# R! O5 D
settextjustify(CENTER_TEXT, CENTER_TEXT); ; ~6 t( \; Y. r3 n
outtextxy(midx, midy, numname);
. z1 y2 H' d6 Y0 \outtextxy(midx, midy+2*textheight("W"), 1 j5 f4 B5 A3 F# q
modename); </FONT></P>" h; z: R& b6 X% k% {9 M
<P><FONT color=#0000ff>/* clean up */ * N4 ?. p. ^6 h" X+ E$ [
getch();
- W5 \2 C0 i$ ^" C6 r V) c2 Y+ T$ Y. hclosegraph();
* w$ @, H! ?) Z- `& K2 O7 jreturn 0; - M# @7 K+ a ]% N( ` Y9 A: O& F
} 1 D- }( G& J# J- R/ }1 R& \
</FONT>! N8 i- A% \2 E/ y2 R" T
</P>- }$ W5 l# _! Q
<P><FONT color=#ff0000>函数名: getimage </FONT>- J3 Y; p b' O/ N# |
功 能: 将指定区域的一个位图存到主存中 : k, t3 z% C+ J# T) p
用 法: void far getimage(int left, int top, int right, int bottom, % y2 g4 A+ |5 w/ w
void far *bitmap); - `9 _8 H. I% _# n# Q( R& ]
程序例: </P>
+ N5 S# i$ d0 D) c1 ^9 s<P><FONT color=#0000ff>#include <GRAPHICS.H>- C; G6 p5 T9 h7 U2 k# x. h; L
#include <STDLIB.H>9 ~4 N& L6 S# p
#include <STDIO.H>
7 U6 W( p. z0 s1 g& V* x#include <CONIO.H> p$ b" T g6 |& _
#include <ALLOC.H></FONT></P>
" c4 C d( B8 i% I7 F<P><FONT color=#0000ff>void save_screen(void far *buf[4]); / @/ I/ c& E Y0 |
void restore_screen(void far *buf[4]); </FONT></P># v4 |" b# J8 [
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>+ b& Z! I+ ?5 ^) r( }
<P><FONT color=#0000ff>int main(void)
7 ]& t4 s3 N1 }: e w' ]7 ?5 N{
+ x) Y" ~4 r- B Z' y) Xint gdriver=DETECT, gmode, errorcode;
9 h2 l8 R; _7 E( W% H4 } Zvoid far *ptr[4]; </FONT></P>2 ^+ \6 N3 m+ g t2 B, R" g; K+ X8 `
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
6 p& f# K% ~8 W( t3 `- m$ Minitgraph(&gdriver, &gmode, ""); ; _( i0 e. u6 A: B% D4 N- |# ~" T% ]
errorcode = graphresult(); /* check for any errors */ 5 H+ e8 b/ K7 h! O$ e
if (errorcode != grOk)
# G) B: S( a2 z- q% Y{ 2 w% b7 d! l' O# V+ x( i$ Z, B, D
printf("Graphics error: %s\n", grapherrormsg(errorcode));
' U) w$ c& I7 X$ U2 |printf("Press any key to halt:");
/ S, I% W" M" D! O1 ggetch();
. I7 H7 x" k" G5 o! j! m0 {exit(1); # |- ]/ Z/ a% G6 f) b
}
1 q2 |2 o- {. }maxx = getmaxx();
3 j( a; E1 x: a$ ~+ I7 ~0 w1 I3 Lmaxy = getmaxy(); </FONT></P>4 b( I) ?# |2 v) V$ g
<P><FONT color=#0000ff>/* draw an image on the screen */
: Z" \! w% Y% i- Qrectangle(0, 0, maxx, maxy);
& U: T4 W) M: i$ P5 Zline(0, 0, maxx, maxy);
2 e& h6 n0 I7 k1 d9 Q( _+ u/ u1 Jline(0, maxy, maxx, 0); </FONT></P>
- f \5 {+ U. I7 ^) `4 p<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
3 _: q6 v8 B* x9 T% Q! Ugetch(); /* pause screen */ - k* h! `2 S4 N
cleardevice(); /* clear screen */ 3 \$ r; Q2 C5 N& F$ M( c3 a1 s
restore_screen(ptr); /* restore the screen */ 5 i9 T5 {3 F, i2 n, G! w' m
getch(); /* pause screen */ </FONT></P>% i' A; y- O4 n6 ^. ?8 p- e8 a
<P><FONT color=#0000ff>closegraph(); # e2 b5 `+ v- V
return 0;
# U+ y" q% _* q( u- V' @} </FONT></P>
% q5 M0 I* v! s; T2 D; O, d<P><FONT color=#0000ff>void save_screen(void far *buf[4])
9 Q- F- M9 b; x1 F5 U5 I{ : h; l3 d3 M, j1 ~0 _; h
unsigned size; 3 M& S- @6 w7 M2 S; q; X5 t; m
int ystart=0, yend, yincr, block; </FONT></P>1 Q6 R5 T5 G- }
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
' _2 b) b, {' a+ \- k1 byend = yincr;
0 ~) M4 L3 C& g) \0 H+ n9 ysize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>- s# z# @. i/ Y
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
/ z8 `. {) |; k8 V! O3 l. j{
( e/ Q# v, ~% n+ Y, s( ?, wif ((buf[block] = farmalloc(size)) == NULL) 2 `$ c' L) h6 ?5 c
{
; x, A% ?" x2 W& f" jclosegraph(); % Z& g% C% G% S6 M9 c# P
printf("Error: not enough heap space in save_screen().\n"); ( ^; E3 P0 L# u' \2 @9 Y
exit(1); * b3 u1 T1 a+ z( q5 B$ u) R1 J, c
} </FONT></P> u# c. l5 g$ D8 c
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); % V& B# w5 i5 ^5 \2 e% J
ystart = yend + 1;
- E4 O7 ^8 J& Y9 F1 n4 Z; e! Qyend += yincr + 1;
) j' {2 z9 D8 B- C} . t& I: W4 F; s( y! g; m
} </FONT></P>3 b: R& t$ z# ^
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) $ _/ ~, L. u+ z/ q- C
{
A& O4 c! z) y7 y. punsigned size;
; ~) q: B$ p2 f/ T! ]int ystart=0, yend, yincr, block; </FONT></P>0 S3 f" Q4 S+ a2 ]% P
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; . h& G, e& v) \- X0 l, g1 I' w
yend = yincr; 0 G0 R2 N/ d% z k- k; W
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>. j# p0 _9 b# J! M
<P><FONT color=#0000ff>for (block=0; block<=3; block++) , b" x- B' G- ]1 t* \7 }! t
{
% y3 P5 F( v1 n6 ], ~3 F4 D0 vif ((buf[block] = farmalloc(size)) == NULL)
% g- j( N& N9 k$ f{ ; Q. D y* t" ?; a* H6 y
closegraph();
# r: x: c7 ]: o* {8 Mprintf("Error: not enough heap space in save_screen().\n"); 2 C. n8 F# T( q/ c' R2 q) \* K
exit(1); " y- J# H0 k: ~6 q! _: w
} </FONT></P>4 v5 I6 S: ^- ~( A: L( m' o7 n
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
6 d. R# T0 Z+ Yystart = yend + 1;
) z$ ?+ N0 ~) j, f4 j3 T) eyend += yincr + 1; $ C: Q' Y5 v# W) h* y: D
} " ]! C& {* B* A
} </FONT></P>
# j- w0 y* W A) K$ @! ?<P><FONT color=#0000ff>void restore_screen(void far *buf[4])
) b+ s- }" D5 [: S{
q4 [( E a6 t" E( R* ~int ystart=0, yend, yincr, block; </FONT></P># n- u: L! E9 c" |. y3 L! r1 h+ B
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
: X6 p$ ]8 ^+ z) ayend = yincr; </FONT></P>+ `$ E" S1 {+ [6 j! B! b
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
- ~+ A% u- v q" V8 I" j% j" P{
+ f- x. B# _* J# C( ]- pputimage(0, ystart, buf[block], COPY_PUT);
& b9 o/ G& P0 E% c _5 vfarfree(buf[block]);
9 t, w3 W: `. _8 fystart = yend + 1; 9 T7 C/ f' E2 k+ I( u7 S
yend += yincr + 1; 7 E5 i6 I+ @+ E
} 4 w2 ], j6 q3 h+ G4 ]3 I+ R$ P
} </FONT>
7 I; w: d5 c/ l( N$ d8 y+ q<FONT color=#ff0000>& x- p }* @# T1 G; `- d8 u, p
</FONT></P>
2 | J) I0 b8 i& x9 L7 n/ Q<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
+ B5 B3 w% }- {功 能: 取当前线型、模式和宽度
3 E7 c, F+ ?( K+ W用 法: void far getlinesettings(struct linesettingstype far *lininfo):
) c1 }( E q( X: \1 J& [, P程序例: </P>
/ A+ S9 H1 o" i) {% t! r! A! n9 c<P><FONT color=#0000ff>#include <GRAPHICS.H>8 C( F* `' E" h" n
#include <STDLIB.H>
! W1 [3 a! O; T- u4 ^0 m#include <STDIO.H>
8 {& z4 G& D1 ^, c, p* x#include <CONIO.H></FONT></P>2 p) ~: I \8 ]/ i+ I o
<P><FONT color=#0000ff>/* the names of the line styles supported */
* a. \- e4 T( Achar *lname[] = { "SOLID_LINE",
* _% }" Q: b+ ?. v V2 {4 h7 {"DOTTED_LINE", . {# l4 K- g% ?* c
"CENTER_LINE",
: e- Z9 L1 z4 h9 m/ p* p8 G) I' M"DASHED_LINE", 7 C; t# t5 w% D: s; r! f G
"USERBIT_LINE" + H/ Y: F- x7 f( M8 f! r
}; </FONT></P>
7 E, @ z6 `! r" ~; X2 @! m8 E4 }! ?1 m6 |<P><FONT color=#0000ff>int main(void)
3 m$ ^, E. [: O e1 T{
! d3 Q+ s3 A0 ?, Q/* request auto detection */ K" B1 a* |, i7 \
int gdriver = DETECT, gmode, errorcode; 4 X6 R% B, [* q7 b
struct linesettingstype lineinfo; 2 l a5 ~! j" D) ~+ T8 q+ Y; |
int midx, midy; $ E5 l6 d# ]3 y3 }$ V
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
$ Z6 Y! ? b, Z" N& T) a<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 L' M& ]/ y1 E5 H/ b) Winitgraph(&gdriver, &gmode, ""); </FONT></P>& |5 f3 ?3 _, a1 b
<P><FONT color=#0000ff>/* read result of initialization */ 6 T5 N: S0 r( `& s6 [1 A
errorcode = graphresult(); 2 a* R* k& G# V$ V- W; O+ P) C+ H
if (errorcode != grOk) /* an error occurred */
" A) L5 O/ [% i1 ]0 u{ # f- a9 @4 S; g. i9 g; Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ d6 v# X: s/ @! V# e( Qprintf("Press any key to halt:"); % [' t: i: j; ]
getch();
! M! S" X( E* {* W3 O# _2 p1 Y& O. m% ^" |exit(1); /* terminate with an error code */ N- i" y0 z3 X k' j, n; w8 R
} </FONT></P>( A' r0 E* i4 J6 X/ v
<P><FONT color=#0000ff>midx = getmaxx() / 2;
& c6 E T, V2 Z, X" _' n: B# }5 umidy = getmaxy() / 2; </FONT></P>& k; x9 s0 f5 [. l }
<P><FONT color=#0000ff>/* get information about current line settings */ # k# _! e3 U( `' @! j
getlinesettings(&lineinfo); </FONT></P>
4 R% M3 l) u' @8 P<P><FONT color=#0000ff>/* convert line information into strings */ + n, |# Q( Q7 F* z+ V
sprintf(lstyle, "%s is the line style.", 1 W5 l; \% @: x7 Y7 ^4 x
lname[lineinfo.linestyle]);
0 R8 `( _% o; G% z% `sprintf(lpattern, "0x%X is the user-defined line pattern.", 4 M! N6 a/ E# j6 B6 A) n$ B
lineinfo.upattern); ) q; |) W& \- m! H* q2 p ^
sprintf(lwidth, "%d is the line thickness.",
% b6 x4 N! \6 E3 k4 @( q0 i: Tlineinfo.thickness); </FONT></P>, R, M# z& ^" ~# S
<P><FONT color=#0000ff>/* display the information */ 9 C; L: n7 ?( s
settextjustify(CENTER_TEXT, CENTER_TEXT); ' e2 w( T/ m! p; ^
outtextxy(midx, midy, lstyle);
' n) Y; o. j( J' E) h$ pouttextxy(midx, midy+2*textheight("W"), lpattern); & n1 F! w5 P- A, |& \
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>4 r; z5 h5 @& A, z+ h6 E& t/ W
<P><FONT color=#0000ff>/* clean up */ 1 T. D2 Q/ J& J6 d B' {; j
getch(); ( R7 ?& D& _6 M
closegraph();
% t+ e) L3 M& |0 P" L }return 0; + D/ }/ S4 q N9 M8 J& g
} </FONT>* G3 P, @* o( R) t$ z
( T/ D9 V4 B8 R6 M7 o: z3 k- N
</P>* z. `" Y& R& B/ e& B: ]2 V
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>$ ?9 b' `3 I; D# r
功 能: 返回可以传给函数setcolor的最大颜色值 ! Y0 a$ {' s# J
用 法: int far getmaxcolor(void); % F. U, O/ N+ I
程序例: </P>
4 u# w" L" Z# k5 q2 x, e<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 s& [ d3 g3 L( f+ x* J#include <STDLIB.H>( A, V( U. h. A7 ^9 Q" n5 j
#include <STDIO.H>1 w {6 r. _- v3 u) D7 s
#include <CONIO.H></FONT></P>: s, K" O' {8 c- P" C3 Z
<P><FONT color=#0000ff>int main(void) & D' j; u3 X* N9 C
{
! w, x s/ f/ O& R j# {1 {) v/* request auto detection */ , K5 h* O c% ]! N2 n/ D$ K
int gdriver = DETECT, gmode, errorcode; & N( Z. U$ ?- m. a: j
int midx, midy; ) z$ b, a: F. f2 f% E* W: S# Y5 ]
char colstr[80]; </FONT></P>1 S) n: T# `( Q s
<P><FONT color=#0000ff>/* initialize graphics and local variables
0 s6 h5 k$ b' k4 q*/ initgraph(&gdriver, &gmode, ""); </FONT></P>
) o/ E: A" e& K$ q+ Z<P><FONT color=#0000ff>/* read result of initialization */
4 U5 {+ m2 B) Z/ W6 P" j* A( Rerrorcode = graphresult();
: G: w+ D: o8 o, `0 h1 F) eif (errorcode != grOk) /* an error occurred */ ( L- W. C. K1 R3 Y& u; ]
{ 2 e8 P! w5 h! J' U. c2 Z! \# `
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 C3 X1 ^: P, ^' e& C
printf("Press any key to halt:");
% e' R7 g6 D- Q7 w. N8 Kgetch();
" }, @ p% r9 R+ ]* z. I& |* [exit(1); /* terminate with an error code */ 9 N. B1 m5 x. @$ T, s2 w, C. n
} </FONT></P>" m r1 B9 v; a6 _
<P><FONT color=#0000ff>midx = getmaxx() / 2;
; o9 q1 x. x) b$ n# f6 vmidy = getmaxy() / 2; </FONT></P>
7 m6 j$ x' i9 _5 P/ ]: `2 b) T<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ & F, |: U" }$ i/ B/ W
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
G' u4 n/ C$ c2 c. d5 E<P><FONT color=#0000ff>/* display the information */ - \9 x" t( w `* C
settextjustify(CENTER_TEXT, CENTER_TEXT); ( J; K% m; G$ J! o; w9 B
outtextxy(midx, midy, colstr); </FONT></P>
( t- x0 w9 H/ j7 M$ _<P><FONT color=#0000ff>/* clean up */ " E1 }) Q+ W; Z/ v- Q e3 r! j5 M
getch(); 7 p( j* A z. B% g# N$ @2 k
closegraph(); 6 f& i8 j6 E. b. R' D1 V" |
return 0; & ~4 k% w B) ^: @- i2 h
} </FONT># f8 C. k5 B+ g0 I% g8 k" z6 S4 v2 u
% q1 D# E1 M' l8 z F2 p; i
" K6 y8 G, w8 l9 B9 v$ }2 H/ { J% t</P>
$ ^0 S3 D2 ^0 P* S! t3 F<P><FONT color=#ff0000>函数名: getmaxx </FONT>8 P7 N7 M5 i1 V( H( h, J' A& m7 A
功 能: 返回屏幕的最大x坐标
4 b) p- v( l N1 h用 法: int far getmaxx(void); 3 L' }0 {4 X1 [2 W8 c) T
程序例: </P>( j, `2 C$ a5 r8 Z5 D8 V
<P><FONT color=#0000ff>#include <GRAPHICS.H>1 @. {- ?8 W7 y; A, z+ G
#include <STDLIB.H>
: V$ B$ j4 W6 W9 ~8 \#include <STDIO.H>+ \1 M6 |) F8 s z* I$ c) W3 g; \ f
#include <CONIO.H></FONT></P>3 q5 G3 y% F0 u0 z. P+ b9 d
<P><FONT color=#0000ff>int main(void) 4 ?/ \$ h W, ]9 }" X4 E+ X. h
{ - ]6 G3 U* T1 |0 t/ s( l
/* request auto detection */
# N/ X' L& A5 T% x/ Q' z1 Y& d& xint gdriver = DETECT, gmode, errorcode;
1 z* @# b/ H0 r* N9 S+ _8 Xint midx, midy;
5 ?# k9 G! J0 d2 ~. Jchar xrange[80], yrange[80]; </FONT></P>
) z1 ^3 x5 S$ K<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 Y, {; N! s) q! Xinitgraph(&gdriver, &gmode, ""); </FONT></P>2 E9 u. @1 f w/ o. ?' k
<P><FONT color=#0000ff>/* read result of initialization */ % H% T- g; K* c' y# C* c; G
errorcode = graphresult();
2 S1 [6 w' |4 n! Zif (errorcode != grOk) /* an error occurred */
& b, I- F, Q6 l& N{
$ y- m8 r Z8 ~8 {; Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # ^9 V& n% v3 W `7 V
printf("Press any key to halt:"); 9 U5 c; U& w' \2 ]: K$ d
getch();
5 N% v2 z' P6 Bexit(1); /* terminate with an error code */
$ x8 t# I2 k9 l: _' W1 X} </FONT></P>
/ ]% X; s5 T- A6 v/ r* e) E<P><FONT color=#0000ff>midx = getmaxx() / 2;
( l! Q; }9 x0 Kmidy = getmaxy() / 2; </FONT></P># { v0 a3 |! P% t; R7 l
<P><FONT color=#0000ff>/* convert max resolution values into strings */ - b' L/ e! ?+ m9 T# B2 s
sprintf(xrange, "X values range from 0..%d", getmaxx());
5 R! b4 a: e X8 |sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
: U# |" ^& {$ Y, ]<P><FONT color=#0000ff>/* display the information */
& S1 O6 Y* ~+ r$ ?# psettextjustify(CENTER_TEXT, CENTER_TEXT);
/ m9 L& a; J1 U0 U8 S% oouttextxy(midx, midy, xrange);
* `+ r" t3 W a9 Y* `* Bouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>. @: a5 ^/ X: Z/ ^
<P><FONT color=#0000ff>/* clean up */ ; x- b/ |5 U# r2 U
getch(); + K3 c, ^$ F7 u+ m2 L
closegraph(); - ^& F: E$ p+ `8 ], x! \ P1 [
return 0; : I$ m! g, c, g- t& k4 K8 r. Z; w
}</FONT> & D- g4 r& i4 h5 [. _
% {4 ?6 p! w! W1 ~+ }2 P8 _7 K</P>: J6 e1 i; _7 W
<P><FONT color=#ff0000>函数名: getmaxy </FONT>% J" y" f: E/ N7 v& X* I/ @4 k
功 能: 返回屏幕的最大y坐标 + h i* |$ Y3 Z' m, g2 [* q( ~! D
用 法: int far getmaxy(void); / I# l8 h( ?6 t3 F# M
程序例: </P>/ M3 y3 O5 ~2 R: p q
<P><FONT color=#0000ff>#include <GRAPHICS.H>* k; R8 Y- T1 n9 a( h8 Q
#include <STDLIB.H>
1 Z- h, R) N8 ^5 f! r, }1 i: x#include <STDIO.H> ^, B% N& W& }: |
#include <CONIO.H></FONT></P>$ P7 ?1 L1 [; |3 O# m6 ]7 E
<P><FONT color=#0000ff>int main(void) 1 y) |: D2 U$ X2 X* @8 d2 B
{
+ h$ T0 F3 U" ~1 m, b" O% E/ i/* request auto detection */
' r6 [, P( b* b2 ^int gdriver = DETECT, gmode, errorcode;
3 g5 W: C8 O8 cint midx, midy;
" Y* M: n; n$ mchar xrange[80], yrange[80]; </FONT></P>
8 c% H+ e; m J<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 j; X( }- }1 p8 f! D# w; T2 |/ x
initgraph(&gdriver, &gmode, ""); </FONT></P>5 P% l3 k( Q7 A) Q6 Y
<P><FONT color=#0000ff>/* read result of initialization */
& j0 F1 g K/ w: O4 x Gerrorcode = graphresult(); ! S9 D* j2 }- r: O
if (errorcode != grOk) /* an error occurred */ * I' c! w! W, w+ D7 B+ l
{ 9 u( c9 `- ]" m7 A+ E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 x% m' K3 g3 h. y2 d0 B' t1 N
printf("Press any key to halt:"); 2 Q/ R# {+ c. o! v0 x$ o
getch(); - f' Z: g Z+ S6 j; d P
exit(1); /* terminate with an error code */
/ e6 |: Y* C" v, {4 l! f" _- b! k} </FONT></P>9 Q% N0 J% J+ k: Q( Y
<P><FONT color=#0000ff>midx = getmaxx() / 2; ( y$ D4 ?2 T' x W% f6 k6 f' B
midy = getmaxy() / 2; </FONT></P>7 @: F& g8 J' E4 e0 j' |# P* m
<P><FONT color=#0000ff>/* convert max resolution values into strings */ ' `* T) w7 L% G$ k0 _; j8 \
sprintf(xrange, "X values range from 0..%d", getmaxx());
e0 P' Y& M8 V5 {; g3 b0 Esprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>0 ^ C2 N3 R/ C! }" S9 r
<P><FONT color=#0000ff>/* display the information */ 0 J# W( G h6 w6 t5 ~. G \
settextjustify(CENTER_TEXT, CENTER_TEXT); : ^0 o4 L7 d9 Y/ O% E k3 D
outtextxy(midx, midy, xrange); 4 Z6 i! `* k i0 d
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>9 H' R+ ?8 d3 Y7 b7 e' b3 r- u
<P><FONT color=#0000ff>/* clean up */ ' U* z' B9 a7 N0 f# ^" [
getch();
R7 X& T! f5 v! t: e! Eclosegraph(); 9 U. T+ m% F$ r
return 0;
# J' \& E$ d0 _. y} </FONT>
6 {# _ q6 A2 Y3 {</P>/ @9 X2 V- O, R. E
<P><FONT color=#ff0000>函数名: getmodename </FONT>
) ]; I$ E! U0 \* h功 能: 返回含有指定图形模式名的字符串指针 . m c2 I* g/ }" o
用 法: char *far getmodename(int mode_name); $ J6 @0 D, A4 a& Y" W7 V. X
程序例: </P>% V6 a& x, ~. z, }5 P
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* g8 c5 \% s0 }: K# Q, Q#include <STDLIB.H>0 n6 `$ w* B# V2 A3 v
#include <STDIO.H>9 _+ T9 {2 K3 j3 g4 U4 a- A
#include <CONIO.H></FONT></P> l9 H5 G! V4 D* u/ x
<P><FONT color=#0000ff>int main(void) " p4 ]* z) s/ d8 c8 P: u
{
' X! C4 [; I# N0 u( q/* request autodetection */ # J4 @4 ^# D; D/ S0 W1 Q' [
int gdriver = DETECT, gmode, errorcode; . w+ }! D% ~) i) d0 U
int midx, midy, mode; . Y; y. K; f( ~( K. n" @
char numname[80], modename[80]; </FONT></P>
, b5 X }0 u2 W+ m<P><FONT color=#0000ff>/* initialize graphics and local variables */
' }( k2 B; m1 V0 kinitgraph(&gdriver, &gmode, ""); </FONT></P>
( x, N' i% \9 f<P><FONT color=#0000ff>/* read result of initialization */
0 x. }. G: J: ~errorcode = graphresult();
1 E0 C5 p% b% |if (errorcode != grOk) /* an error occurred */
5 s; f2 l% Y8 h{
: h7 o. ^; U9 M5 d( W( u1 uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 ~9 ^, \" U! f( o2 _. K
printf("Press any key to halt:");
, @( t" m) v6 p- n! tgetch();
0 ?+ p4 I- |2 t0 pexit(1); /* terminate with an error code */ " q0 E7 I( G1 e+ D* a
} </FONT></P>
6 Y) }; Q6 k: E$ W) U+ C1 o6 s0 I<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 g7 \4 Z' h6 E" w# R
midy = getmaxy() / 2; </FONT></P>$ V- S& @8 R) ]# H( B, [( Q5 f
<P><FONT color=#0000ff>/* get mode number and name strings */ - n& y$ l8 _' s( m/ a) a% X `5 w
mode = getgraphmode(); 1 t/ D2 {" a/ Y
sprintf(numname, "%d is the current mode number.", mode); & u6 \: W9 X& _2 L+ x! A7 |
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>. ~# c- E5 {. g
<P><FONT color=#0000ff>/* display the information */
_6 T0 T) [8 D5 X& O+ ?settextjustify(CENTER_TEXT, CENTER_TEXT);
- [9 N$ B6 s$ R1 z8 D" e4 Z# Iouttextxy(midx, midy, numname); * d& ~# ]) I k( z5 P1 v6 t9 Q& L
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
$ {" H5 l* `: K7 |2 {) i) B, I4 O<P><FONT color=#0000ff>/* clean up */
; f' @; c9 a" I' z$ w mgetch();
$ x" U' s- f. a8 r- Vclosegraph(); 4 [3 V% Y3 l y) Y6 T$ n: \, _
return 0; % a2 s. M% b4 x' ?+ T
} </FONT>- S+ E) S! I$ u) T+ u% Y
2 i2 x7 {- p; R D! w4 ~! X
</P>
6 V" B. ~, N6 z9 w0 E<P><FONT color=#ff0000>函数名: getmoderange</FONT> - U, Z% W3 |( T9 ~( C
功 能: 取给定图形驱动程序的模式范围
) G. S" b: g- l$ ?+ B用 法: void far getmoderange(int graphdriver, int far *lomode,
" a$ g" G: M4 g& B4 ~# gint far *himode);
, q0 r* X+ ?! h) h/ H! D' b程序例: </P>
, ~9 s5 `" M7 O4 r) b9 q+ N' F<P><FONT color=#0000ff>#include <GRAPHICS.H> G6 o9 s" s. y# A0 H$ W9 }' \
#include <STDLIB.H>/ a. Z5 t/ i' Z
#include <STDIO.H>- M& g9 \& {. @, P% m" q
#include <CONIO.H></FONT></P>6 j( s/ ]+ R* u0 ?' ^. h4 ?* e
<P><FONT color=#0000ff>int main(void) ) e+ A' e$ a* e" Q$ b# I3 q
{ ! D$ A) |+ E( K
/* request auto detection */
1 d! x' j. q# w R8 e- kint gdriver = DETECT, gmode, errorcode; 3 N. \7 v! \7 l) K+ @9 t$ N
int midx, midy; ' e8 |, X; b& W* Y. } Y
int low, high; 0 y) ]& `2 B, N8 N6 }6 u
char mrange[80]; </FONT></P>
$ w% x" h3 K3 ?<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 |' M, }' w5 v0 einitgraph(&gdriver, &gmode, ""); </FONT></P>
! T9 L; V& M7 q9 b4 B K<P><FONT color=#0000ff>/* read result of initialization */
d' |& K s# H; P7 Verrorcode = graphresult();
2 g& A' D6 P: bif (errorcode != grOk) /* an error occurred */ 5 h+ x& l8 f; W
{ , A! w/ g' |' C( s" b8 m3 P$ F
printf("Graphics error: %s\n", grapherrormsg(errorcode));
r( \& J( p: H9 ^; aprintf("Press any key to halt:");
* X3 K. k% @. qgetch();
7 n2 d7 H& e0 l$ @$ i7 [) ? gexit(1); /* terminate with an error code */
& P' L7 W: C9 a1 j! i9 i; q1 i/ H} </FONT></P>) J4 T0 @" o4 \" |
<P><FONT color=#0000ff>midx = getmaxx() / 2;
. L" k. g9 K omidy = getmaxy() / 2; </FONT></P>* M# P( N! x7 ` ~6 p: Z
<P><FONT color=#0000ff>/* get the mode range for this driver */ * }/ g3 a+ ^( _& W4 g
getmoderange(gdriver, &low, &high); </FONT></P>
6 @- d/ ?6 Q# L# q, S<P><FONT color=#0000ff>/* convert mode range info. into strings */ ; Z z. N6 @% \( k; z9 R
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
. j- v* p0 K4 s4 a+ l/ L7 |<P><FONT color=#0000ff>/* display the information */ 8 E M' `7 e9 e7 g( W8 g7 E, B8 p
settextjustify(CENTER_TEXT, CENTER_TEXT);
6 \! D: i2 m9 l1 i# Houttextxy(midx, midy, mrange); </FONT></P>7 l, ] u6 C8 ~! Q5 O
<P><FONT color=#0000ff>/* clean up */
1 c8 J: J% O4 D& L9 ]getch();
# r4 y& y1 O9 Oclosegraph(); ) a+ {) i; S( t( ?* h4 a
return 0; / z% S" u7 f3 @1 r" ^0 N# I
}
, D9 ?% C7 w- S2 h" N" V9 N6 U</FONT>& ]/ V7 L7 W9 ~8 ?6 {% u
</P>
$ d- x( ^ w, `3 R' J* X<P><FONT color=#ff0000>函数名: getpalette </FONT>" `% W1 a! `0 A0 I
功 能: 返回有关当前调色板的信息
% s5 B$ W: N6 I" @2 K用 法: void far getpalette(struct palettetype far *palette);
( G5 v7 g5 X; t程序例: </P>
- J% h4 Z* \0 p' ?* m- C( Q, \<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ e: d$ T1 \4 J# n2 c#include <STDLIB.H>. a; C9 P, ^% P" B, S" _5 V; Q
#include <STDIO.H>
1 }! i8 J6 K; v5 x# o#include <CONIO.H></FONT></P>
+ B: d& y/ {7 {+ P, u1 ` p) F<P><FONT color=#0000ff>int main(void) 9 O, O; D& W' h% w
{
% r1 j8 E7 L% U& l5 h+ p/* request auto detection */
0 Z6 @7 R! X6 F# Q% f; N! w# |" lint gdriver = DETECT, gmode, errorcode; 4 u5 j* s2 i+ h$ G, @2 k/ w
struct palettetype pal;
% x& Y( B3 D' c) m! S8 u1 }) D8 Tchar psize[80], pval[20]; 3 h; X/ O& f7 c" g( A' V6 R
int i, ht;
7 U) t$ v O2 ]& Z) Y* B sint y = 10; </FONT></P>/ n6 P3 m9 M; ^; A8 N0 K) _9 \
<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 p' S& v, c8 X! h+ Sinitgraph(&gdriver, &gmode, ""); </FONT></P>
8 z" @, Z2 W) B: z& D<P><FONT color=#0000ff>/* read result of initialization */ & t# |9 W6 ~" P# D
errorcode = graphresult();
/ O% G. j; L- e: q5 ^% v1 y& f/* an error occurred */ p0 L8 x% K! I3 J; ]0 O
if (errorcode != grOk) 5 T4 [! Z- T* j; U3 o: I! o
{
# M. v! a: a1 Uprintf("Graphics error: %s\n",
$ ?, M7 {# \) pgrapherrormsg(errorcode));
1 }5 R5 b0 R: eprintf("Press any key to halt:"); 1 F0 a" g% T7 |# P" v& _
getch();
8 [# f/ H9 l+ G. K/* terminate with an error code */
5 q; r7 {% n8 y+ g3 V7 a! ]3 yexit(1); 9 c; ]. g# ?% c! `* G* N
} </FONT></P>4 z) W/ T# {9 ^( J( B; z
<P><FONT color=#0000ff>/* grab a copy of the palette */
! S7 \ B" ]% M+ @' H, Rgetpalette(&pal); </FONT></P>
0 P+ O2 x7 X H' k' c: }0 ~+ o<P><FONT color=#0000ff>/* convert palette info. into strings */ 3 B9 M4 k: F! Z' b( H1 v' k
sprintf(psize, "The palette has %d \ 8 f8 K: C% U5 y, f( m( r. x2 x) A
modifiable entries.", pal.size); </FONT></P>
) Z" Q8 Z; {; Z7 ]: v<P><FONT color=#0000ff>/* display the information */
! x0 B5 E! q/ y$ H J$ O- s; gouttextxy(0, y, psize); ( F$ A( Q8 c: y4 v8 I% h
if (pal.size != 0) * c7 I7 d* r K, D
{ & Q9 W: |6 U, D5 ]
ht = textheight("W");
2 k6 b2 f& I2 d+ l4 Ly += 2*ht; * p" n* ^0 d: [ t; t8 D+ D
outtextxy(0, y, "Here are the current \ # T' [- b% ~9 h! p: F+ X
values:");
" r$ N5 ?- C+ z7 K( Hy += 2*ht; " W l- b8 h `8 W9 m6 [4 K
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
, p W, S; v- Xsprintf(pval, 4 ]. q Y- L8 t; j% O9 Q
"palette[%02d]: 0x%02X", i,
# J. J0 \( o1 w8 n- d% r. Ipal.colors);
% E& X5 u, E# ?outtextxy(0, y, pval); # c+ `1 P; u0 _0 A% \' Q" K, H/ y
} 3 U. L3 R1 l0 I& P, S* f
} </FONT></P>
, Z4 z+ i) Z: c+ k: X! b' {<P><FONT color=#0000ff>/* clean up */ $ y8 i* r% l0 y$ p0 M1 l
getch(); + h0 e* S" L/ m; N; i7 i5 Y
closegraph(); </FONT>
) u) l# U/ O: z. b# i<FONT color=#0000ff>return 0;
6 u, _3 D0 [1 W! }- T6 h6 c% ?}
; t' s( E% a6 Y& \- A</FONT></P>
8 r: f6 ^& b# f: s7 `<P><FONT color=#ff0000>函数名: getpass </FONT>
: G1 R' r. Y! i% M8 `, M5 d, |1 |功 能: 读一个口令 6 b1 g- t2 Y l* T0 J6 `
用 法: char *getpass(char *prompt); P! ]2 L; v7 ]" Y- Q1 P- N# t+ @
程序例: </P>' Q/ _6 ]4 M6 c: j& I
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 p# H* ~5 {( \3 f. P% _! v0 T* B9 F
<P><FONT color=#0000ff>int main(void)
2 B) U7 A$ j, ]7 l/ L K; j# j{ 7 `* V2 c" K- v- A
char *password; </FONT></P>* A3 k9 I! A$ Q6 h9 |
<P><FONT color=#0000ff>password = getpass("Input a password:"); 4 x; M5 Z& _* l) _3 `
cprintf("The password is: %s\r\n",
1 J- ?% E7 H. G- B+ C3 Gpassword); * f. h1 x b. k2 {% P- A0 h
return 0;
7 Y3 k z$ M" F# g5 ^' l: C+ L6 Y} 5 U! \- A9 V# E+ O% A
</FONT>& {3 C& I/ [3 Y
# [" e$ P, _4 ]8 o2 h! G</P>
; n* m. h1 k0 Q7 l. r0 { t& U( w<P><FONT color=#ff0000>函数名: getpixel </FONT>) I/ ?2 Q2 H1 h' w, D: f- z
功 能: 取得指定像素的颜色
) _1 F. F. T8 d( v) y! Z用 法: int far getpixel(int x, int y);
2 A; q% ^% L4 `" e程序例: </P>3 L7 E9 b C u& G! Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>, k, \" r7 a3 g) y
#include <STDLIB.H> M; v5 `2 B' p0 K: k
#include <STDIO.H>( c" Z( j* J6 x. |
#include <CONIO.H>3 c% i, d: r# h% F7 Z
#include <DOS.H></FONT></P>
# E7 s n" N: {0 V# v<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 # J& j! V% g9 B$ ~2 H! X
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
4 ]$ K4 G+ e: M% w: c4 O<P><FONT color=#0000ff>int main(void) 1 Y/ x8 `3 \# B- D+ D
{
4 x9 _5 p9 ]+ y: o e3 t% e* ~* H& F/* request auto detection */
) I* m# W$ K4 ]' \3 xint gdriver = DETECT, gmode, errorcode;
/ U1 |3 @$ p+ X1 a) e- I4 Cint i, x, y, color, maxx, maxy,
8 o! m% |$ t* ] m [. x& fmaxcolor, seed; </FONT></P>
! @' e3 q8 h0 d. h3 o3 Y<P><FONT color=#0000ff>/* initialize graphics and local variables */ " m+ {6 p! g: b: g/ M
initgraph(&gdriver, &gmode, ""); </FONT></P>/ ?$ [- o y! W7 X
<P><FONT color=#0000ff>/* read result of initialization */
, D5 t) e9 u3 s! o3 [' p5 {errorcode = graphresult(); 8 q' M% T3 A8 [7 Y9 M7 X$ P. p
/* an error occurred */ # k2 s) u' a1 M8 u1 ?$ l
if (errorcode != grOk) ' U7 V/ z: G; |+ g, Y
{ 9 e& K" k% k" S* n9 t6 p) I
printf("Graphics error: %s\n",
$ e' `) ?4 A1 R# y6 Q% d* ographerrormsg(errorcode)); 8 R5 V3 w; F: I$ d( T, u; h* e
printf("Press any key to halt:");
% N/ ^+ D1 l: N4 ]8 j7 p% igetch();
8 ~( r V; f9 e: _; r; _2 o2 N/* terminate with an error code */ 2 u/ i ?1 Q! f, r, h7 p+ y
exit(1); + N2 w# N$ M! y# e% h; A3 f
} </FONT></P>( Z0 K _% t" Q0 L# Q! L
<P><FONT color=#0000ff>maxx = getmaxx() + 1; 0 V& C; M% r N5 s
maxy = getmaxy() + 1;
2 Y Z5 G4 \- dmaxcolor = getmaxcolor() + 1; </FONT></P>
: ~2 e6 M: J% z: P8 }4 u" l$ |<P><FONT color=#0000ff>while (!kbhit())
9 O6 }0 {8 V: m{ ! F% j7 a; ~0 }/ u
/* seed the random number generator */
. {; f5 e5 W& A* Wseed = random(32767);
. s2 `7 k2 U8 {- G! ^srand(seed);
, \% k( T0 b! Z4 u! E- K" C$ C Dfor (i=0; i<PIXEL_COUNT; <br i++)> {
6 e$ ~( y, K7 A# I6 ~x = random(maxx);
( G* W' u3 D! d( [y = random(maxy); 4 a9 {9 T1 F2 |: O* J+ ~9 e
color = random(maxcolor);
2 {8 {0 O* a5 @, m, j; R7 c- |) @putpixel(x, y, color); ; t- J8 P* @" V5 S
} </FONT></P>
% F6 }# m4 c% N4 o; P* ^ N<P><FONT color=#0000ff>delay(DELAY_TIME);
" }! Q0 ^) v- I7 G) tsrand(seed); / X# P$ F5 U, T/ Q8 c
for (i=0; i<PIXEL_COUNT; <br i++)> { " O5 W! S, [" N, |- V; B
x = random(maxx); 5 o4 F" ~* k( ^5 J U
y = random(maxy);
9 B4 j6 `* ^5 d5 zcolor = random(maxcolor); $ h' ^+ c. J: T' {0 |1 ?
if (color == getpixel)</FONT> </P>
0 Q; u/ D; |3 E2 n<P><FONT color=#ff0000>函数名: gets</FONT> ( E w6 i: ] ~% E
功 能: 从流中取一字符串 . |' i' k: I# E8 `6 [3 }7 g
用 法: char *gets(char *string); 4 y% U" q9 W) t) i, v
程序例: </P>. A. R3 j* p. P' y3 k% v' U4 a) V8 X
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>6 T6 R4 R2 v2 s! O& s
<P><FONT color=#0000ff>int main(void) , b2 u3 t) u) j' s7 @* q
{ 5 H+ f) [2 R, ?( e5 V8 N& S
char string[80]; </FONT></P>0 h, f& A1 }! H4 t5 m9 I6 F
<P><FONT color=#0000ff>printf("Input a string:"); 9 m0 O7 ^% n& ]1 ~& n/ w
gets(string); 1 q" l- ] N' ]% t; q# J# u4 p8 d
printf("The string input was: %s\n", & |; t4 w- G5 f
string);
1 I% J0 |; Q; `8 H' P7 z) qreturn 0; . b! G, A0 k! H+ M& b/ K, Z. F, y6 A
}
: `( R. s* c+ q. }9 m0 a8 ]% f
) J5 l w8 d4 G5 c' A</FONT></P>
/ y9 }3 R/ E B( B& a% q, r<P><FONT color=#ff0000>函数名: gettext </FONT>
^! F0 a; i( m5 ~功 能: 将文本方式屏幕上的文本拷贝到存储区
2 Q4 `) M1 W9 L" |) z- ]用 法: int gettext(int left, int top, int right, int bottom, void *destin); 8 e: M$ i# z j/ A4 \! S1 E
程序例: </P>
: \ y6 r" ?0 @! g% ^$ n<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
' }9 `' J5 L/ ?3 z- U a! R9 B<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
, O5 n* u) v& k, g<P><FONT color=#0000ff>int main(void) - W4 z1 F* U8 [9 X3 Y
{
6 @# f- e, a% t* q( tint i;
8 g+ A2 ~, F" x# E+ L. n% uclrscr();
! U" h* v) l4 ^ V, Gfor (i = 0; i <= 20; i++)
" Q- A6 v% h# e4 u. Vcprintf("Line #%d\r\n", i); . ^: r: r; }( g. \
gettext(1, 1, 80, 25, buffer);
4 _/ p0 m" h0 tgotoxy(1, 25);
/ D: h1 g% D+ \ Y& o- O2 Pcprintf("Press any key to clear screen..."); / V2 D t$ s& `+ F6 X0 Z4 u
getch(); x; I5 V; R8 V$ ~# v" C2 k
clrscr();
% s1 [0 T2 r* S& cgotoxy(1, 25); . N w( M5 R# P: e, T: z
cprintf("Press any key to restore screen..."); $ }$ N) D7 b7 F+ f V! `
getch(); 7 \" d1 P8 k/ H, g- I+ r( k0 v+ f
puttext(1, 1, 80, 25, buffer); 1 t, u' b, s2 E6 @) j6 Z+ O3 A2 j
gotoxy(1, 25);
4 P1 z0 h: x; j3 L! v4 Lcprintf("Press any key to quit...");
7 O) U; o' {) H5 r8 A, kgetch(); ' l# w7 N" @. V* a+ Q- ~- _5 u
return 0;
( p* b; I. Q7 |# p9 y9 x% a} ) U) o) a; b |2 L4 d9 o' ?( Z
</FONT>
' @, I) l( I, k9 ]1 G* j$ R) Y</P>
p \- G+ ?) I/ z2 x<P><FONT color=#ff0000>函数名: gettextinfo</FONT> : o% \) n0 H8 {/ q+ Q5 y( {
功 能: 取得文本模式的显示信息 / f5 }+ |4 O% m1 Y1 t) N
用 法: void gettextinfo(struct text_info *inforec); 2 F; d1 J" H4 K! V9 c7 K
程序例: </P>
& `% R/ @2 |# r; y1 m5 T x1 ~' i<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>& T* |$ H; T6 B1 W' I
<P><FONT color=#0000ff>int main(void) 6 ~4 s* p% @: h6 o1 J2 Y3 \( q8 ~
{ % V Z+ B' l0 J1 P
struct text_info ti; ; X( s- B& a/ T3 k, q
gettextinfo(&ti);
: T- X1 J- Z0 V) Z$ z$ \1 s# tcprintf("window left %2d\r\n",ti.winleft); 2 Q8 Y5 f% S3 y4 \+ w9 m
cprintf("window top %2d\r\n",ti.wintop); 3 S4 i" c [$ W% Z3 k
cprintf("window right %2d\r\n",ti.winright);
) w- u3 r9 E( _. d& J7 Kcprintf("window bottom %2d\r\n",ti.winbottom); * a& k$ u; C+ B6 l( b
cprintf("attribute %2d\r\n",ti.attribute); 6 F; ?/ O/ n% {: \0 B
cprintf("normal attribute %2d\r\n",ti.normattr);
* \. D" W" y1 ^5 @cprintf("current mode %2d\r\n",ti.currmode);
" L4 a3 e% e( D& Ncprintf("screen height %2d\r\n",ti.screenheight); * }* U* \* ~9 e' g$ X
cprintf("screen width %2d\r\n",ti.screenwidth); / t; j/ ^9 f9 ^: K; O, B, e) F! ~
cprintf("current x %2d\r\n",ti.curx);
3 U6 D8 R% u; M! P9 {& fcprintf("current y %2d\r\n",ti.cury); ) m( l) S, Z1 C2 L3 P' T. d, z9 L, {
return 0; 6 Z9 Q" p$ p. ]/ }! A, N1 I) \; u1 `
}
; y5 v1 U: A$ v9 j9 L& @% w</FONT># X3 o; O% r1 f0 c- \ q: e
</P>
3 D7 u [. ~; m# o5 L! [( W, x<P><FONT color=#ff0000>函数名: gettextsettings </FONT>6 ]% p# Z& o3 r/ w
功 能: 返回有关当前图形文本字体的信息 ! H& l$ _! Y6 B( z% T
用 法: void far gettextsettings(struct textsettingstype far *textinfo); ' s! f& \. C6 r+ U0 R
程序例: </P>3 V( R, ^1 G/ O9 B
<P>#include <GRAPHICS.H><FONT color=#0000ff>
4 Q- d& Q! z9 L8 [; Q#include <STDLIB.H>
& ~2 z7 ~- N/ B! \#include <STDIO.H>4 b2 c5 X: R/ M" l
#include <CONIO.H></FONT></P>
`' Q* `: B% J7 U% n' G: A<P><FONT color=#0000ff>/* the names of the fonts supported */ , I2 d1 ]' h s0 o
char *font[] = { "DEFAULT_FONT", . ?" T9 y5 x) V! D3 u' K( {- \
"TRIPLEX_FONT", , e* u b) E4 k0 ^* G E# f
"SMALL_FONT",
& d5 e2 S$ J. ?"SANS_SERIF_FONT",
4 |0 ]7 X0 k" b2 h) \, f# O- X$ I"GOTHIC_FONT" # M7 Y: u* {! ^& |: P
}; </FONT></P>
6 }. A1 M Q& `<P><FONT color=#0000ff>/* the names of the text directions supported */ % v- `/ x. M9 s' q/ X
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
: l) l/ N$ x6 c' y4 F<P><FONT color=#0000ff>/* horizontal text justifications supported */
5 b; G) Z2 F- v2 `& cchar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>6 l0 g9 r" O9 D8 W! H: E* `0 _
<P><FONT color=#0000ff>/* vertical text justifications supported */
* q' j) B$ z0 echar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>: ~5 @4 n1 Y2 O! z" I
<P><FONT color=#0000ff>int main(void)
% j- F+ N% q% E* Y- u{
) A* l; l \& Z' m* ^/* request auto detection */
e+ ~9 ^1 a2 w0 T' c5 c- mint gdriver = DETECT, gmode, errorcode; & c9 u4 j+ n4 A7 O, R
struct textsettingstype textinfo;
7 n' k* i8 D; R: u( R4 I4 eint midx, midy, ht;
) i0 f: e) `# k+ j% b" i3 ]& achar fontstr[80], dirstr[80], sizestr[80]; ; T4 J& g& I7 G+ @7 c" A1 L' J
char hjuststr[80], vjuststr[80]; </FONT></P>
. ]4 Z) z2 K4 d( x2 F<P><FONT color=#0000ff>/* initialize graphics and local variables */
& @* ~# g# q" P' M/ F+ vinitgraph(&gdriver, &gmode, ""); </FONT></P>* t, D) `$ ^. q$ _5 _ G) j
<P><FONT color=#0000ff>/* read result of initialization */ , C# Q2 H: B6 z. Q. `2 M2 `: K9 @
errorcode = graphresult();
- i9 K% W1 ~- S& a( u- V6 Fif (errorcode != grOk) /* an error occurred */
$ b# p3 x* V& `# W% F1 F{
l7 X( g7 i! }9 y( E+ ]7 v9 N9 @+ @printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 b' t1 H5 a# `8 S. H: ~printf("Press any key to halt:"); 0 g* ^- {' _* R+ B' f2 D0 F6 J
getch(); % K' k% N5 |4 j6 J
exit(1); /* terminate with an error code */
" o4 \+ |0 I+ b$ g9 b p} </FONT></P>; v$ r8 F: O0 R+ ~3 w* I* z7 H |
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) f7 v, J. W) \ ymidy = getmaxy() / 2; </FONT></P>
2 i5 Y5 g$ n% `( ]/ T3 v7 g<P><FONT color=#0000ff>/* get information about current text settings */ / D. \3 }8 F3 Y, y$ _( x
gettextsettings(&textinfo); </FONT></P> K- Y9 V- ?) V# g/ y7 D7 c4 ]8 \. T
<P><FONT color=#0000ff>/* convert text information into strings */ % A7 m$ ^5 q n5 `
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); $ D% R1 q: h0 x) ]3 I
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); 9 X& C5 o8 w" j/ b& `% I5 m. c6 l
sprintf(sizestr, "%d is the text size.", textinfo.charsize); 0 L; h+ x* G8 ^
sprintf(hjuststr, "%s is the horizontal justification.",
; b) q I* O4 f% Zhjust[textinfo.horiz]);
0 a( M0 E1 ~) A7 ^: U. T& `4 bsprintf(vjuststr, "%s is the vertical justification.", 3 c6 }) z) g0 S; L7 L, Y
vjust[textinfo.vert]); </FONT></P>: d' V1 j4 ?1 M1 ?
<P><FONT color=#0000ff>/* display the information */ # b8 _6 T1 j$ m0 F
ht = textheight("W");
" f; b& x- B+ k2 o1 e3 Nsettextjustify(CENTER_TEXT, CENTER_TEXT); + @8 V9 Q% c7 P% Z% C5 o
outtextxy(midx, midy, fontstr); ; f% Y2 Y5 u8 {4 j
outtextxy(midx, midy+2*ht, dirstr);
" X5 v) F1 v1 U$ p, \3 |2 M) ~0 Jouttextxy(midx, midy+4*ht, sizestr); 0 h/ I( i1 I+ `5 O
outtextxy(midx, midy+6*ht, hjuststr); . [* h8 n; q. p
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
' B. Y( ~4 G4 e i<P><FONT color=#0000ff>/* clean up */ 3 }! l# J! |, d3 g$ X5 G/ m
getch(); ' {3 r! r) I7 T2 B$ @" `& t
closegraph();
6 B; N6 @% q! Ireturn 0; 8 s m: w3 p3 c2 `5 l f
} </FONT>
; i6 s' q! v4 G' S! `: y2 ~2 p</P>
- L% ^+ A% M( Z: Q# g# }) h<P><FONT color=#ff0000>函数名: gettime </FONT># l) f; W0 a6 r( r% x4 l! z" e
功 能: 取得系统时间 + `/ \9 O: r! y2 r: t' l
用 法: void gettime(struct time *timep);
! A0 W2 p3 T. |. u" |# J1 C程序例: </P>& j" W0 l+ w" y
<P><FONT color=#0000ff>#include <STDIO.H>
3 D# X3 U i0 f# E" G#include <DOS.H></FONT></P>
f5 s, O/ Y/ y8 P7 }$ I W<P><FONT color=#0000ff>int main(void) 7 Y4 n0 P. W, C* H9 P, T
{ $ V6 D5 F9 h6 O9 ^9 v0 }* ?* W
struct time t; </FONT></P>
7 e+ J6 `2 `3 ^; C7 c- O<P><FONT color=#0000ff>gettime(&t);
8 r0 K5 m: \. t. E6 y" Z7 e' m+ Tprintf("The current time is: %2d:%02d:%02d.%02d\n",
+ A: w1 W; u3 a; c! a: rt.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
5 R+ y! z- L1 Q! v. j8 Zreturn 0;
& y. w8 x; e7 n+ [2 C% M}
0 D. N* r! i/ R1 H/ M* r" X8 R3 U3 s5 p( a, {+ r* l4 a, @
</FONT>8 c } a/ E7 ?
</P>2 _; p3 Y# S1 K% n
<P><FONT color=#ff0000>函数名: getvect </FONT>: e5 f. H! r/ N, Y
功 能: 取得中断向量入口
0 n2 H! N6 C8 V' i" K6 l) J0 a用 法: void interrupt(*getvect(int intr_num)); ( t8 h5 Z4 e0 d* G
程序例: </P>
" a, w& D- D& Z( V3 y* J<P><FONT color=#0000ff>#include <STDIO.H>
0 |7 q! p+ k" s8 D- F#include <DOS.H></FONT></P>! W: P/ b. N* `5 a' ]5 s( P
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>' ?1 u' O% o4 B$ J9 _9 r5 Q
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ 0 Q) h9 _9 L0 j; k# @0 r- y
int looping = 1; </FONT></P>
1 E! E+ X% A* j* n+ g8 I0 y7 X<P><FONT color=#0000ff>int main(void) 1 G3 G. I) q% m, _3 V0 D7 E0 N
{ % A3 B ?. |1 g. k, ], i
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>! q+ ~4 k9 O* K" B& K# \
<P><FONT color=#0000ff>/* save the old interrupt */
% t# |: H& M7 K* Noldfunc = getvect(5); </FONT></P>+ q0 R3 _% Q: t9 Y2 v
<P><FONT color=#0000ff>/* install interrupt handler */
" \( f3 Z, S4 A$ F6 m: [& t. osetvect(5,get_out); </FONT></P>8 d+ U0 b, J) ?, T3 K
<P><FONT color=#0000ff>/* do nothing */ / q# z! {, [& P" B: m# I- `% R" _- G
while (looping); </FONT></P>. I# S' o, J9 r5 M' \
<P><FONT color=#0000ff>/* restore to original interrupt routine */ ) p" f% S- J4 u' s8 G- C
setvect(5,oldfunc); </FONT></P>
n1 N5 n% I: s8 `* E<P><FONT color=#0000ff>puts("Success"); . f9 H) ~$ D, X. h9 @- `5 d. u8 C
return 0;
. }3 P1 c. s% g+ X; b* w9 Z4 A: e6 {} 9 a: a0 m4 m, Z" P' |
void interrupt get_out() / n3 g7 t' ]! w9 N- W
{
6 H9 @" w1 l# U T' F$ r8 Zlooping = 0; /* change global variable to get out of loop */
7 l8 j6 d. U, u; B' i3 L1 d}
& n% Y* h3 H1 q0 e# p$ H</FONT>/ J1 Z4 w1 @1 ?- f* @. p3 R/ y4 g- I
</P>
5 s& I8 w% g4 f: T, y<P><FONT color=#ff0000>函数名: getverify </FONT>- b$ v& a/ `/ Z3 ^4 R, e
功 能: 返回DOS校验标志状态
, {" x$ {( F S& `- W1 g1 B$ ?用 法: int getverify(void);
: c% E1 _1 O1 s% }程序例: </P>
9 J1 g! u# X1 ` d<P><FONT color=#0000ff>#include <STDIO.H>
* v( @" s7 C8 m#include <DOS.H></FONT></P>: h# v7 {7 o# P$ A; Q
<P><FONT color=#0000ff>int main(void)
) E7 a* w/ }3 y+ a; _{
1 f5 d8 F, w6 d3 a* Z% m: y( @if (getverify()) % L7 Q5 D" M& ~* G4 J: y/ @
printf("DOS verify flag is on\n");
8 K6 O6 e# { ~1 c" C2 _" Celse
) G* M7 y" s! d& d# Vprintf("DOS verify flag is off\n");
: z7 V( x3 d2 a7 B. y( R0 a% sreturn 0;
# f6 b' ?1 A2 T% r V X F# y) y5 \} 5 X1 W" U; X. s; `8 S; k
</FONT></P># \) A4 S0 n- T6 {- ?
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>, s0 ?- p$ u& E: f! _% R$ U- H- }
功 能: 返回有关当前视区的信息
" B5 \! }" l: V5 s' X. p用 法: void far getviewsettings(struct viewporttype far *viewport); 9 ~& h9 n* O( G% w
程序例: </P> X) o) ?- j$ G% {
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" O! B5 Y: t. w#include <STDLIB.H>( M6 b3 G8 S& }! W# b( F' d8 h
#include <STDIO.H>
4 ?6 H- n0 R0 c#include <CONIO.H></FONT></P>
" N8 e( q3 r- y3 X7 [. o/ i" Q<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
6 \6 Z7 X p9 l0 F; p. q6 f<P><FONT color=#0000ff>int main(void) K0 H2 h4 `" l/ }$ ~0 c
{ ' P; m% @& y: e5 E* f
/* request auto detection */
2 E1 H9 z+ ^' |; Eint gdriver = DETECT, gmode, errorcode;
0 W E5 _: m4 u7 H0 |struct viewporttype viewinfo;
" S& z, I* t& @; E0 s/ J+ zint midx, midy, ht; - U2 n# e! Z5 M/ t6 y: p4 b
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
9 k" ^& h8 ^! v: _: h% C<P><FONT color=#0000ff>/* initialize graphics and local variables */ % ~1 m! j$ t8 j% f% I3 Q" P
initgraph(&gdriver, &gmode, ""); </FONT></P>
; F7 l9 }" _0 a" i1 S. U' q9 v<P><FONT color=#0000ff>/* read result of initialization */
( H, C) o& Q7 t$ f$ i4 N9 cerrorcode = graphresult();
3 ^& I/ q0 A0 T/ \if (errorcode != grOk) /* an error occurred */ k8 h" o {" x2 |6 R" i+ f: d7 g
{ + |& h! F K0 W3 e( H( }* X i y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : P5 o+ ?( k& R8 k% q& M- M
printf("Press any key to halt:");
& k+ [7 W/ b: Fgetch();
$ t' c. E7 m$ C2 Texit(1); /* terminate with an error code */ 4 K P3 B& h, t9 f; s/ t
} </FONT></P># r3 |. S# M0 f: S# t: Q
<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 U4 l' B' x. S! V3 N0 W1 O+ I
midy = getmaxy() / 2; </FONT></P>+ F& R2 Y0 b' N! I# o h; [, ?
<P><FONT color=#0000ff>/* get information about current viewport */ 8 [0 _4 U) ^4 v/ P% L' f
getviewsettings(&viewinfo); </FONT></P>2 O3 \& w3 K3 [6 V
<P><FONT color=#0000ff>/* convert text information into strings */
# q* m* f5 S5 x; B3 y5 J1 rsprintf(topstr, "(%d, %d) is the upper left viewport corner.", & Z- i, R9 _! R8 ?) A5 w
viewinfo.left, viewinfo.top); * w) E- p9 E7 m1 b3 H1 Y
sprintf(botstr, "(%d, %d) is the lower right viewport corner.", 9 X4 b% n8 d5 R- {, F" t3 b
viewinfo.right, viewinfo.bottom);
0 Z/ j2 U! G& `. f7 m, ^9 W% tsprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
. T# e% a4 n5 q' \<P><FONT color=#0000ff>/* display the information */
# ]) N: o1 M: S: A5 d4 K8 J* ssettextjustify(CENTER_TEXT, CENTER_TEXT); 6 z) v8 S) x) `) e7 a& `7 L& {% s
ht = textheight("W");
+ ^2 u7 n8 w% v% s" S, Xouttextxy(midx, midy, topstr); 7 g- `8 ^6 L, X$ K( P
outtextxy(midx, midy+2*ht, botstr); 0 R' S- Y' L5 z }1 F
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>, ]4 ~1 r5 a- W1 F" o, I
<P><FONT color=#0000ff>/* clean up */ " W9 ]) \2 j% M7 j3 H! Q
getch(); + R9 {& E& Y( L) t
closegraph(); % I6 v5 t M4 Q. x8 Y
return 0; , y9 ]7 d# G) e# F2 G# r) p7 T
} </FONT>
( P4 w; q- ^) l/ ?6 f$ F9 [% ]1 z
</P>) P; R- c( Q. C5 j! }7 a: N, B
<P><FONT color=#ff0000>函数名: getw </FONT>5 L$ g8 o. {5 H7 p; ~
功 能: 从流中取一整数 9 `1 Z* Y4 C3 k8 ?, M+ m8 w
用 法: int getw(FILE *strem);
: _3 u7 T( \+ p9 a6 M程序例: </P>
6 Y& F/ |7 T+ l( F, K3 z/ |<P><FONT color=#0000ff>#include <STDIO.H>5 @5 y+ t4 \+ A: X$ t# M8 F
#include <STDLIB.H></FONT></P>; y8 r \1 ]% Z A/ h% G' E1 Y
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>4 m4 B/ a n, e0 V6 n" D
<P><FONT color=#0000ff>int main(void) & ~+ d0 J; g2 s) f& G5 }9 |
{ 3 w4 Z' Z* `- C" h
FILE *fp;
8 T2 s/ i8 g/ x' \4 C+ |) W+ q1 wint word; </FONT></P>
+ Q) Y7 {* L3 x% R<P><FONT color=#0000ff>/* place the word in a file */
P* w2 @7 _( k/ xfp = fopen(FNAME, "wb");
. \( u) T: t! h j6 {3 c, _if (fp == NULL) 1 a6 Z: F6 x+ s# X9 y4 t3 V+ K1 B0 j
{ 0 Y" V. W% a/ q) R& x0 r0 X, K
printf("Error opening file %s\n", FNAME); ) K7 R9 q- w* Q3 b, g$ K8 F
exit(1); ( e* o1 o2 n$ L
} </FONT></P>
; q K( C9 N/ J$ B<P><FONT color=#0000ff>word = 94; ; b' ~0 u# O6 f7 I. k _/ T
putw(word,fp);
- O m f* t2 O' o o# v- Uif (ferror(fp))
; P; D8 g ?& H) jprintf("Error writing to file\n");
% @( o; B { e1 |3 lelse . z+ R/ i; w% t3 `
printf("Successful write\n");
2 b" k2 l- [$ P" p1 g. i0 [fclose(fp); </FONT></P>5 ^3 |0 ^! b$ S1 ^2 o9 @
<P><FONT color=#0000ff>/* reopen the file */
3 T' b. R( z+ n: q/ D. O {fp = fopen(FNAME, "rb");
& d. G" D! K7 f/ lif (fp == NULL)
1 G# A+ ^, b, t% | ?" _{
6 g/ n: k, X+ i8 `4 C0 M, ^printf("Error opening file %s\n", FNAME);
5 ^8 ]4 ^3 u# p: ?exit(1);
, m) C; M, q8 t: K& t} </FONT></P>% N' i4 T% r' ~
<P><FONT color=#0000ff>/* extract the word */
$ p1 k# J# G( s6 D: _word = getw(fp); 8 ^$ k* ^: C+ L/ O( N0 E
if (ferror(fp)) ! h( U3 M4 o5 b3 [
printf("Error reading file\n"); 6 S9 [7 D8 E2 ?
else 6 j0 j! N; T, k4 \ T
printf("Successful read: word = %d\n", word); </FONT></P> {2 `, d( T" T6 Y$ Y7 E1 j7 t
<P><FONT color=#0000ff>/* clean up */ 9 E( ?4 I) r3 _- Z$ h* p7 |) O
fclose(fp); ; |5 s& ^6 V7 P( |+ b* A
unlink(FNAME); </FONT></P>( t" N0 }" r) J: {) n- v
<P><FONT color=#0000ff>return 0;
& b; A: J! q6 H} </FONT>
2 E& p9 q5 K2 T2 M; ?5 P' k% D4 ~
q& J9 `0 ~% E2 L* _/ a6 W
$ H' k9 y9 ]$ e</P>
+ a" F5 E$ A) B3 ]9 g1 U; n<P><FONT color=#ff0000>函数名: getx </FONT>
& i. n$ |) Z' s! {0 g$ ^2 s M功 能: 返回当前图形位置的x坐标 / }9 @, b, l/ h1 A2 g1 t. U
用 法: int far getx(void);
0 Y) S X7 S$ P程序例: </P>2 x1 E7 L8 w( Q) e
<P>#include <GRAPHICS.H><FONT color=#0000ff>
( d. [" I" I" a3 R% i9 i#include <STDLIB.H>% X! }. I1 T& X& j4 p& U9 x* k
#include <STDIO.H>) u# ~% e4 P- ^' x' g& b" L1 X
#include <CONIO.H></FONT></P>
; I& ~) w- g0 h<P><FONT color=#0000ff>int main(void)
9 x2 b2 k$ |- l6 o{ 5 G- H u* O+ t2 |7 L* ~9 x
/* request auto detection */ 9 i C0 g$ v, _" R! b P$ ?
int gdriver = DETECT, gmode, errorcode; 4 U w! M) t/ \8 v; ?* M3 ~5 c
char msg[80]; </FONT></P>
) y$ P. F, F$ G: j<P><FONT color=#0000ff>/* initialize graphics and local variables */ + i3 o, \3 z8 v2 e0 t
initgraph(&gdriver, &gmode, ""); </FONT></P>
7 e0 @: e0 D) ^2 T<P><FONT color=#0000ff>/* read result of initialization */
0 R5 z# q' I+ G1 Z6 Terrorcode = graphresult();
& @: l% ^% s8 _8 Qif (errorcode != grOk) /* an error occurred */ , O$ u& f$ t, S% V
{ 2 F$ Z& Q h X* r2 v" y
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* b% M2 d! Z3 \" X" T3 H: Cprintf("Press any key to halt:"); 1 j- p2 ~. u4 p, a! ]& `
getch(); 4 F0 e' Q% z: z( |3 L
exit(1); /* terminate with an error code */ # l" ^3 q& I. F
} </FONT></P>
4 k' f8 ]$ Q/ V7 P8 Z<P><FONT color=#0000ff>/* move to the screen center point */ " n6 y/ G+ G' n! A) z
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
, q7 y' ^, t1 K6 x* ?# {3 I<P><FONT color=#0000ff>/* create a message string */
" h9 h& p N7 Y) hsprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>( F( i5 g& `8 p. r& Y4 F1 \4 W
<P><FONT color=#0000ff>/* display the message */
0 c/ N7 A$ j. N, w houttext(msg); </FONT></P>4 \# T& B* P% ]2 h
<P><FONT color=#0000ff>/* clean up */ # G" I) b( A v/ w) E5 E
getch();
; e- k }) R" b' d& Hclosegraph();
% O: k) B# M) I4 U0 z D' Lreturn 0; 7 p5 V4 D7 P D0 ?3 }
} </FONT>0 F3 ^$ ~* D5 x' J1 i- j
( r$ D7 C3 Z3 P% W
</P>
+ C) @% b% n" i( n2 b<P><FONT color=#ff0000>函数名: gety </FONT>
0 g" _5 |5 |5 Z功 能: 返回当前图形位置的y坐标 ) X' ]( p; Y$ H2 H. v$ F( H
用 法: int far gety(void);
% V+ d \+ v( @) }4 z程序例: </P>3 v' m3 L$ i) {1 h2 D
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ m; U) P: I: Q$ f* ~0 ]#include <STDLIB.H># k s: E( y1 }. N
#include <STDIO.H>* ^7 b( O) d0 @6 y
#include <CONIO.H></FONT></P>
" \8 z, ?& z- E- Q) ?# i<P><FONT color=#0000ff>int main(void)
* ^. l9 K2 J5 y" k: K* v{
$ g. [+ Z0 z! U% i/* request auto detection */ 6 y: g8 o! ]) q
int gdriver = DETECT, gmode, errorcode; . X) q3 J4 U- w
char msg[80]; </FONT></P>7 W* U/ D5 ?$ c- M% w
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . I0 X5 ]2 h9 `! I8 K1 f5 p
initgraph(&gdriver, &gmode, ""); </FONT></P>! P; B8 I6 q6 q0 l( P- D
<P><FONT color=#0000ff>/* read result of initialization */
8 _ ]- _5 E( a7 i8 N9 ?8 Zerrorcode = graphresult(); ' H. |6 z: a1 I0 `
if (errorcode != grOk) /* an error occurred */
, E7 @, A% t! A: i- d& } |7 U1 C{
% M! S$ F8 s; a, k2 Hprintf("Graphics error: %s\n", grapherrormsg(errorcode)); e% K$ Z2 Y; e& Z( N( e
printf("Press any key to halt:"); + M( z' F$ t0 A i* y
getch(); 0 M) \4 X% w4 ]4 D4 v
exit(1); /* terminate with an error code */
5 l; V7 S; D- I( b! x2 I5 b} </FONT></P>
, B& }! u# k6 P<P><FONT color=#0000ff>/* move to the screen center point */
5 U# }% t& S* w- r! _moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
' o# g) E( s& L$ [<P><FONT color=#0000ff>/* create a message string */ 5 y. Y8 ~/ w, `7 G
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
% l7 |" J+ u8 ?5 w# j<P><FONT color=#0000ff>/* display the message */
! U, M6 \* M& {& S G- d/ Douttext(msg); </FONT></P>
2 y8 H. ~* n0 A<P><FONT color=#0000ff>/* clean up */ 8 b) N' N' Z' A& G
getch(); ) `9 I1 l$ y/ Z( L0 P% t7 d
closegraph(); 0 L5 A, [. }6 c9 m1 u# P
return 0;
$ U$ c. ^5 S; R( I6 N6 x; L} </FONT>1 B' S, ^) N' w: U
3 e2 o) T7 L, z% j
</P>
2 m: D U6 I" n3 H/ F/ S T<P><FONT color=#ff0000>函数名: gmtime </FONT>
0 P1 v& R2 U& M+ y! I+ B功 能: 把日期和时间转换为格林尼治标准时间(GMT)
+ s& ~$ L# v! B# [0 f$ M用 法: struct tm *gmtime(long *clock); 6 a8 u A' p* x
程序例: </P>4 ~& H1 U% K2 G' p, e
<P>#include <STDIO.H><FONT color=#0000ff>7 B7 C5 U4 O2 T3 y/ F& k
#include <STDLIB.H>; f+ U7 n: |$ I1 v
#include <TIME.H>
! A9 Q/ W2 b1 @; t#include <DOS.H></FONT></P>
9 d, S3 I9 m+ x" n6 S) R<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */ & h/ a7 P8 t/ O+ C
char *tzstr = "TZ=PST8PDT"; </FONT></P>0 T! i, s( o7 D0 S, T
<P><FONT color=#0000ff>int main(void) ' Y/ H; L5 b0 W: s
{ ( G0 o5 f1 w% \
time_t t; ' y3 Z2 C0 s& \5 L2 e
struct tm *gmt, *area; </FONT></P>
5 f7 m2 G. _6 z1 [6 t<P><FONT color=#0000ff>putenv(tzstr); 3 }9 ]& L( m: B# z4 B
tzset(); </FONT></P>' A+ @) I. S8 {* q! ~* [
<P><FONT color=#0000ff>t = time(NULL);
7 ~* z: D0 ?3 e3 {) rarea = localtime(&t); 5 p- U" I1 a6 r8 }; Y, m: I
printf("Local time is: %s", asctime(area)); 0 X ^ u9 }- p5 L5 C+ I* \' B
gmt = gmtime(&t);
: A0 P' m) A) j! J9 \% Hprintf("GMT is: %s", asctime(gmt)); : N9 H, N, V5 t2 [$ K; }) Y6 g# }% P4 M
return 0;
' h0 d4 \8 `' i, c6 n; r: w} </FONT>+ _ X0 m9 b# p0 _* f
+ E1 H( c6 K- Y3 O
</P>
9 B# Q. V$ u4 {. _3 N- H7 C5 B<P><FONT color=#ff0000>函数名: gotoxy </FONT>/ \ ]0 K2 z O2 b, h8 l6 ~8 _
功 能: 在文本窗口中设置光标 * n1 N$ [9 }/ l. a! ?( f+ A
用 法: void gotoxy(int x, int y);
: v* B3 k. U; w+ J+ z程序例: </P>
& S8 i" J Q7 t: N% u& a' p- M9 u<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
5 V) g, V; U& D k% ~! s, _<P><FONT color=#0000ff>int main(void)
$ j4 }# R/ C& p. z6 e{
5 o0 Y$ M& b$ ]( k/ L5 Fclrscr(); % ?" p+ \$ v! S k* h6 w+ Y0 `# S; H
gotoxy(35, 12);
6 G% t6 N2 M3 r# a1 ocprintf("Hello world"); : S' l- }8 \2 `3 {. M( H/ w
getch(); & X/ E' G; X$ n
return 0;
3 h1 d/ Y3 V. b0 _; |& V5 o& H5 u}</FONT>
" L: @1 ^, I2 Q5 m$ c2 t' @( g- _& P' H
</P>4 q; ^: p' P" S( f2 z U& d
<P><FONT color=#ff0000>函数名: gotoxy </FONT>
, d Y/ ]; R5 n功 能: 在文本窗口中设置光标 ) w4 q) P2 N+ C3 L
用 法: void gotoxy(int x, int y);
9 `; v) V |; }" |$ q程序例: </P>
& w5 ]9 e8 g/ c<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>2 s( i! q# u) P" g% d# X
<P><FONT color=#0000ff>int main(void) * s- n3 J+ z1 E! N( x; T$ T0 s+ \
{
7 M1 T2 i+ z. o; o# ]- s% |. P2 hclrscr(); : e) e8 T0 M/ t
gotoxy(35, 12);
3 w, `1 [/ u' G1 {& _3 V( Ccprintf("Hello world");
# k4 a, T# `. \$ }getch();
! c% w* M, `$ M( o; E# T' Kreturn 0; ' F' H$ w! i# m+ ]
}
8 X- z; f6 C# S; n' I: I</FONT>
. `! |6 l" Q1 V* q" h</P>. } I0 b9 e9 h. C$ c
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>7 z# K" O: y, X3 Q1 k/ ~% n6 X
功 能: 将所有图形设置复位为它们的缺省值
/ F- m0 g0 ]- g: z/ _用 法: void far graphdefaults(void); ( i' m, l" C# r, ]" u
程序例: </P>
' F0 a8 d5 j1 W3 x" \" G7 u S" J<P><FONT color=#0000ff>#include <GRAPHICS.H># M7 x: l6 S. z4 b4 c7 B
#include <STDLIB.H>
" j5 P0 h% J- Q! z- u, N, f$ R& y$ j#include <STDIO.H>
" @- e! [4 X0 r+ f#include <CONIO.H></FONT></P>
7 ?2 N3 ~4 c% [% l- {& E<P><FONT color=#0000ff>int main(void) / z/ c6 y: d- L) s3 ` ~& L
{
. S k7 ^0 ~" P$ `4 g1 e* ]7 A/* request auto detection */
# P# V }+ K% l% E2 Y4 Tint gdriver = DETECT, gmode, errorcode; / h6 F0 D5 y; z9 s! x1 j' J; b
int maxx, maxy; </FONT></P>
) ?$ L# v: Z8 B7 D, _$ }<P><FONT color=#0000ff>/* initialize graphics and local variables */ - V- Q* d$ {4 J9 W9 c$ T% d
initgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>- y' _! r/ }' k% u" ?* s0 O
<P><FONT color=#0000ff>/* read result of initialization */ % I/ x" l: b4 M- ], v
errorcode = graphresult();
% c1 S5 s8 H4 c8 }2 Fif (errorcode != grOk) /* an error occurred */ 0 _# \ M/ Z% v& W9 W r; i
{ ! F$ b2 J X) {& P' X' N8 n0 U2 a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
' o7 w* s2 {9 \0 \3 nprintf("Press any key to halt:");
6 Y8 c2 U ?. M8 _1 Bgetch();
; i2 Q/ U; L/ [6 Mexit(1); /* terminate with an error code */
+ R' C& v( u; v. d( h+ \: T$ q} </FONT></P>8 Q3 s: K! V+ [; e3 _6 M0 b6 H0 o
<P><FONT color=#0000ff>maxx = getmaxx(); ! M5 c( Y* A" a! t7 E: G; b7 K
maxy = getmaxy(); </FONT></P>5 y. I! }+ Y$ t( O
<P><FONT color=#0000ff>/* output line with non-default settings */ 3 R9 N7 B @) G, `* A
setlinestyle(DOTTED_LINE, 0, 3);
$ R) J0 A& h0 B) R1 ^9 qline(0, 0, maxx, maxy);
( p7 t* R9 g0 D! g: T+ qouttextxy(maxx/2, maxy/3, "Before default values are restored.");
$ E' [0 d8 x/ C! O4 Z& d5 m8 r; Sgetch(); </FONT></P>
+ O( C- E/ @4 r4 I* P3 d<P><FONT color=#0000ff>/* restore default values for everything */ - y$ S3 k# _, u: t8 q( U9 P6 [
graphdefaults(); </FONT></P>
- q* Z7 E/ Z! e0 _0 M<P><FONT color=#0000ff>/* clear the screen */
; [! {& f; y0 {% w. w. Ocleardevice(); </FONT></P>7 e) E3 K. d& @0 L
<P><FONT color=#0000ff>/* output line with default settings */ 5 P6 X" t3 O, y0 d' u$ b' ]1 Y
line(0, 0, maxx, maxy);
1 s5 c3 S% e0 c7 Oouttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
- H. \* p# f# `% f$ U<P><FONT color=#0000ff>/* clean up */ 5 p! w6 W( W% e S! [* J8 \) o
getch(); : ?0 u7 J( e4 w; z2 I, C' d: j
closegraph(); 0 \) ]3 V3 Q% w* i
return 0;
; f p+ B* z1 L9 i} ' Z# t3 p& n8 ^/ C* g5 y3 u7 d+ f* K
</FONT>
$ M& N6 _9 R6 S</P>
; O# ]( T5 G. U% P<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>
- s$ d' `" W3 }/ }5 N/ G8 D5 f5 X$ @功 能: 返回一个错误信息串的指针 ( J) C7 t+ m7 |* B+ z+ G5 d; Y
用 法: char *far grapherrormsg(int errorcode); $ K% L+ T$ D# [# `% ~6 C
程序例: </P>
( _% h. m' d( H" H+ e<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ l9 {( Z. r7 o) g: H#include <STDLIB.H>
* w& N3 o# w( B" \$ b#include <STDIO.H>
) J: e7 p4 n! F; `$ H& X8 M#include <CONIO.H></FONT></P>
; m; @# \- Z9 x) r. v" Z+ {: ^* C<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
% t. r- @, V+ }8 f<P><FONT color=#0000ff>int main(void) & R5 Q; K( L+ c0 @% L' h7 ]4 k
{
0 V0 @: n& C1 C5 W0 k% e! m/* FORCE AN ERROR TO OCCUR */
7 R' u9 O i- n0 Aint gdriver = NONSENSE, gmode, errorcode; </FONT></P>) h/ d" U( w% q6 f) q2 `# {1 x8 f) u
<P><FONT color=#0000ff>/* initialize graphics mode */ # Z1 ]: U+ X! a: ^
initgraph(&gdriver, &gmode, ""); </FONT></P>5 r5 l S q+ R) d
<P><FONT color=#0000ff>/* read result of initialization */ : j& h; p l" e4 `" I' z, g' ]* p& P
errorcode = graphresult(); </FONT></P>
) i+ }+ u: _! O5 |- _. v6 F<P><FONT color=#0000ff>/* if an error occurred, then output a */ ! v7 V7 c. H9 [' e% z
/* descriptive error message. */ 0 i; }& q6 {4 q3 T% k
if (errorcode != grOk) $ m) B' m) T5 [5 A0 S. U1 ?
{
U1 J D: m, R* ~& H2 l5 ^9 f }printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) N# \* E1 b4 g4 Q
printf("Press any key to halt:"); . k& u' e: T2 W' @
getch();
2 Y% B) |9 C7 O v- `; cexit(1); /* terminate with an error code */ 2 p* d+ o6 ]4 j. w
} </FONT></P>- Q5 Y! f0 `/ t* w
<P><FONT color=#0000ff>/* draw a line */ 6 V' I6 f; p# o: l/ j3 Z' r
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
( l6 Z& }$ d7 I: j' A, S0 K" H<P><FONT color=#0000ff>/* clean up */
8 T7 U: |+ ~" z! z# O3 J2 }getch(); 9 a0 g3 x, A4 V* c& f8 M
closegraph(); 8 R4 Z T# b8 h+ M( p7 l! m* U' _
return 0;
6 C; U4 `) \- E# ?$ v0 Q2 W} % A0 }4 L5 Z5 q, p
</FONT>* P( J7 S; ~6 M' @3 ~0 d7 B: N
</P>$ P7 o( C& a) D. S! F, B
<P><FONT color=#ff0000>函数名: graphresult </FONT>
$ s2 w, M; D/ a1 ~0 e$ _2 `功 能: 返回最后一次不成功的图形操作的错误代码 * s+ J; j% V) ^6 w, Z2 I
用 法: int far graphresult(void);
& M6 v! z8 ~3 B5 @8 N程序例: </P>
8 A5 T( K+ z2 A B3 |<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 T' h6 K: C+ J( p, ?& l# ?#include <STDLIB.H>! z6 a9 J( Q% V
#include <STDIO.H>) W* t+ P) e% l# X0 _" W$ y
#include <CONIO.H></FONT></P>
8 N- ]/ m4 v2 M1 ?<P><FONT color=#0000ff>int main(void) - @, D2 r# o a2 U- {
{ 4 K m3 I3 {- I h
/* request auto detection */ 5 B+ x- |3 R* r; O( \
int gdriver = DETECT, gmode, errorcode; </FONT></P>1 A, |2 G3 z2 C. `
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; O5 p- h3 ], o0 d: _+ Z% ~% s* Z7 x
initgraph(&gdriver, &gmode, ""); </FONT></P>
! M: n R7 _0 V- M- b) J<P><FONT color=#0000ff>/* read result of initialization */
, \! l4 g0 Q2 o: o* I2 lerrorcode = graphresult(); </FONT></P>
3 I+ J2 S; ?& ?/ {( m: n2 Y- Z<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ . f( ?# \: S7 t! G
{
( K8 _/ _0 V4 s; V- d! oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ; L$ v4 Q9 r+ l' X! s5 F
printf("Press any key to halt:");
1 ]; v6 x# ?$ C0 g3 J' F: O1 F: l0 d& hgetch();
4 _8 N& E; t6 uexit(1); /* terminate with an error code */
5 A. j2 c. Y% |} </FONT></P>. L* A9 e2 G! \9 W- v* {
<P><FONT color=#0000ff>/* draw a line */
; N' P7 `2 ~5 z& Eline(0, 0, getmaxx(), getmaxy()); </FONT></P>' P! d$ _8 N3 |
<P><FONT color=#0000ff>/* clean up */
8 F/ K2 Z/ f8 J7 sgetch();
! ~$ \! P+ t5 S8 b c9 Nclosegraph(); $ x t2 n! ]$ r% b7 I3 A
return 0;
, X5 U+ |1 }$ g' I0 ~2 c0 p7 h}</FONT> ' y0 T3 l5 i) ?+ J5 C4 n
</P>- d: i% L2 x. n# ?
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> - n# e Z: U T' U. R0 Q4 [, V+ N
功 能: 用户可修改的图形存储区释放函数
! t6 o' L6 H& y/ Q& _2 h用 法: void far _graphfreemem(void far *ptr, unsigned size);
) d2 G# S9 v' v; g程序例: </P>2 J" U f' I' p$ l
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" s( A: M; ~5 l# ~% z#include <STDLIB.H>5 P) R8 O; n: Y1 B* s, r; s
#include <STDIO.H>1 M8 ]" w! `: w: a. g
#include <CONIO.H>2 j1 j$ o7 U% C, J9 ^
#include <ALLOC.H></FONT></P>4 f% X- p& X Q! V# Z; S
<P><FONT color=#0000ff>int main(void) 8 D. u8 x# P) U1 q$ p& A
{
- H S7 E2 h0 Z6 q6 {" \/* request auto detection */
" G/ Z6 D/ a% |7 Z0 U U8 Zint gdriver = DETECT, gmode, errorcode; 2 @" K* P- x# ]+ c w5 ~
int midx, midy; </FONT></P>
. ^ v& I& O' |2 q<P><FONT color=#0000ff>/* clear the text screen */
7 N. H) \* D$ V5 e- Eclrscr();
& _& B- S. g5 `) F- M, w) h7 ?printf("Press any key to initialize graphics mode:"); 5 o' G5 ~* Z, U b8 P% ~
getch(); % }2 X p7 g9 F3 V, g* \
clrscr(); </FONT></P>" r5 x! x1 s2 `1 R
<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 t# c% w6 ~2 ~! l( U v- P1 s" finitgraph(&gdriver, &gmode, ""); </FONT></P>- \& v2 Q! Z' h4 w$ e' [
<P><FONT color=#0000ff>/* read result of initialization */
( X! I. m) K0 ~0 U" L* Derrorcode = graphresult(); - h. \2 i/ q) C' d
if (errorcode != grOk) /* an error occurred */ ) k0 p; _! y5 b" u# W
{
6 L9 n n/ \" {" a/ U0 {. kprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / H- n5 p' m) G
printf("Press any key to halt:"); 9 J j7 F& p, U6 N& @& L! E: v& P( y
getch();
. _1 } W4 d6 G" _3 w1 E' Nexit(1); /* terminate with an error code */ 8 a7 @1 X! c# B
} </FONT></P>& y' c7 q& c) S. C& c
<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 V. z- e4 ~3 N3 v
midy = getmaxy() / 2; </FONT></P>* w: I+ Y8 h3 H% g
<P><FONT color=#0000ff>/* display a message */
( g7 ^$ O, `6 p$ _% [2 Ysettextjustify(CENTER_TEXT, CENTER_TEXT); 5 _" S, x# s6 K E9 N" T
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>7 f. ]# x- m8 H: `! w& H
<P><FONT color=#0000ff>/* clean up */ . j V* f7 M% @
getch(); 4 ^: {5 m3 k% X* Z z* h. t! A: E3 h
closegraph(); 2 E& v( [/ j$ w, }* F+ b% T
return 0; ) Q \9 I2 Q' b. O7 e' t. O4 ?
} </FONT></P> x6 v: y* g/ q; \" {( V
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ 8 C" q Z2 c9 r2 P9 U/ P
void far * far _graphgetmem(unsigned size)
, W8 ^! a2 i. O/ [4 @{
* \# C# z M l! @) Dprintf("_graphgetmem called to allocate %d bytes.\n", size); # r, Q4 ~+ {. R: ?# h0 s, W+ G
printf("hit any key:"); , F* l8 @( X9 B
getch();
0 T* C1 C# a/ A% Y5 g S, W+ qprintf("\n"); </FONT></P>! T+ Z$ K1 u9 `
<P><FONT color=#0000ff>/* allocate memory from far heap */
' a; g; W+ ^$ s5 {return farmalloc(size); . V' a2 m: V5 k% y2 l" k
} </FONT></P>- a+ D; R: k5 b, [1 M( E2 Q
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
: h H& x+ }, O' y0 Wvoid far _graphfreemem(void far *ptr, unsigned size) $ n3 u& ^0 a. z1 `. S( ~5 E
{ 4 N* h6 g8 [! i- E
printf("_graphfreemem called to free %d bytes.\n", size); 2 [" L( Z7 d1 @
printf("hit any key:"); - R Z* Q7 {( a8 U: z7 G5 u4 B
getch(); / Q" ]! c# d7 j ]8 t
printf("\n"); </FONT></P>6 g" O# j/ `( t/ Y; q `
<P><FONT color=#0000ff>/* free ptr from far heap */ 3 f% n) Q! E o x6 S; |- E
farfree(ptr);
' a1 s9 M5 U% @% N+ {3 O* F} 8 e, F/ _3 T: y& F* u% u/ ~/ v
</FONT></P>
; s1 w- c' O- x# u1 F) O<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>
& B Q* B6 _6 C4 Z. d- p/ h: H功 能: 用户可修改的图形存储区分配函数 5 ^& k, z" `& a* l1 e$ x, l
用 法: void far *far _graphgetmem(unsigned size); + M, A* a3 i- k& \ N4 m$ I# h
程序例: </P> p) j& o. D* V9 U9 Q+ g
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ p0 I+ R: W, J4 d; O#include <STDLIB.H>
4 F- ?+ ^ Q, t8 q#include <STDIO.H># \( [: i3 i$ ?2 z
#include <CONIO.H>
, E: `4 ^5 B4 |# V5 w9 G# D#include <ALLOC.H></FONT></P>5 D9 B. s3 ^* |2 L/ d: M( M% j9 L
<P><FONT color=#0000ff>int main(void)
) b' j) [' I4 W5 Z8 j3 }{
' }4 I2 y, k2 E% {2 H0 h7 P/* request autodetection */
9 C5 [6 E& n( I) v0 N7 jint gdriver = DETECT, gmode, errorcode;
+ g/ ^5 J$ B0 v& q" nint midx, midy; </FONT></P>
D8 ` m9 Q7 I<P><FONT color=#0000ff>/* clear the text screen */ & p2 T+ Q; i* h8 g
clrscr();
8 t7 j9 a' ]+ U% wprintf("Press any key to initialize graphics mode:");
% C0 d8 _$ _( F/ E+ bgetch();
" Q: i K( L; A% W- l5 h3 }* Mclrscr(); </FONT></P>
( ]4 R, O, F: z* l) ^, S( G<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 h8 E; Y! K/ B1 F$ c2 p* e5 m* |initgraph(&gdriver, &gmode, ""); </FONT></P>7 L& s c: M& ?* \* o
<P><FONT color=#0000ff>/* read result of initialization */
1 [ g4 n% m cerrorcode = graphresult(); " O) w# x: z" Q7 _
if (errorcode != grOk) /* an error occurred */
) b' ?0 ?! M( s" }{ 7 } |8 G* Z) U3 J; K/ G' @# h
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( x) V, M4 u, G$ E. g$ Z
printf("Press any key to halt:"); ) }/ H4 @( |, @5 ?
getch(); % U0 W% I% y7 z+ k
exit(1); /* terminate with an error code */ / I% h( W* U9 G" d4 o
} </FONT></P>
* v% B: U# e/ H+ y5 l8 h<P><FONT color=#0000ff>midx = getmaxx() / 2; . t4 [1 [1 c' \! Y- Q
midy = getmaxy() / 2; </FONT></P>
1 R: n \ h8 E) O6 E<P><FONT color=#0000ff>/* display a message */ # K. s9 q8 x8 o8 X4 V
settextjustify(CENTER_TEXT, CENTER_TEXT);
1 w b! W4 T: F- M" v: Eouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
% B/ C8 P, O2 |# i/ q: o& i<P><FONT color=#0000ff>/* clean up */ 0 B! B1 h* f3 _2 v: Q, e
getch();
7 x1 ~& c2 Z* |closegraph();
$ S r& F0 O% w5 x1 x# u# vreturn 0;
' {# r+ M5 C- l4 K} </FONT></P>: z4 ?6 J2 U7 S. Y* `9 w2 a+ n
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
1 w' V; a- T+ H8 Tvoid far * far _graphgetmem(unsigned size)
+ L5 G4 T% Q \! L8 u9 }" M{ + D1 @* P/ \0 `4 F3 h7 Q; H
printf("_graphgetmem called to allocate %d bytes.\n", size); I/ C+ e- N) W/ K# X
printf("hit any key:");
" L# q# L- R9 p, y, f, Q6 Y# wgetch(); ' i( ~0 B* r' q2 e; u' c: a
printf("\n"); </FONT></P>6 F# ^5 z& @% L0 _
<P><FONT color=#0000ff>/* allocate memory from far heap */ / x3 |6 t1 v/ G) T
return farmalloc(size);
7 |1 W- Q3 b! e3 K9 A} </FONT></P>- C. p' }) j( @1 |
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
+ E* P4 I- j2 Kvoid far _graphfreemem(void far *ptr, unsigned size) , x( Y; m. _& O. N5 u1 H5 C! o
{ ; }2 j, |% N) D; I
printf("_graphfreemem called to free %d bytes.\n", size);
0 E- ~9 R! T4 }0 Q; d: }, l5 X" ?+ Dprintf("hit any key:");
$ f0 x. ?' z& k4 k& |getch();
3 L& U* R# y* m- aprintf("\n"); </FONT></P>; N& N, }, i, ?- ?. ?! r
<P><FONT color=#0000ff>/* free ptr from far heap */ , A0 o( t( \! ]" P( C; A
farfree(ptr); 9 `) d) A2 }1 R. [) p
}) c- p* b' K1 o9 L( h' G3 Q
</FONT></P> |
zan
|