数学建模社区-数学中国

标题: 函数大全(g开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 03:00
标题: 函数大全(g开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(g开头)</FONT></B></FONT></P>3 t" z, _7 H6 D

) j* o# v" J& X: c: x9 C, c' L, s) g" O$ n
<p>1 l. `2 [% h( Y- k/ @
<><FONT color=#ff0000>函数名: gcvt </FONT>7 \. o3 W: O( n; H
功 能: 把浮点数转换成字符串
: f6 K( R( W. w0 M0 c5 @# n用 法: char *gcvt(double value, int ndigit, char *buf); * D& I8 c7 m) R$ C  G+ p
程序例: </P>- k& N. J; h+ x: \2 Z6 ^( q7 m
<><FONT color=#0000ff>#include <STDLIB.H>7 T4 D* }* X. e" U& Q
#include <STDIO.H></FONT></P>
' K4 j2 L% V: ]<><FONT color=#0000ff>int main(void)   e( ~( U, }" h; |3 _, ]0 v2 {6 g
{ & p  q/ t) d$ N: \6 Q  d. @6 Y
char str[25]; ) ]7 v7 T9 G5 y3 N# t! B, M
double num; " }9 U. u  r( a/ B
int sig = 5; /* significant digits */ </FONT></P>4 I5 O& s; h, A: T! K
<><FONT color=#0000ff>/* a regular number */ + n" R8 }& ]. j
num = 9.876;
+ _3 ^4 R, `) R, a4 [gcvt(num, sig, str);
) C. {. R) {3 c- p$ Y, lprintf("string = %s\n", str); </FONT></P>
$ g  u* w4 i  M" m: Y5 u8 x<><FONT color=#0000ff>/* a negative number */
7 \5 V  Z2 H: E- i7 u% Vnum = -123.4567;
; F- u, l- r: D; V6 Wgcvt(num, sig, str); ! @2 t2 H  a' `
printf("string = %s\n", str); </FONT></P>& j* G* K* V% {5 f! @; {* w
<><FONT color=#0000ff>/* scientific notation */ * X7 E4 f& D1 v6 \3 D
num = 0.678e5; & N) q* S% a( M3 l% z& c; M
gcvt(num, sig, str); 6 t& j1 K& ~, {
printf("string = %s\n", str); </FONT></P>2 N/ U5 _/ k' r; d3 I' N- B
<><FONT color=#0000ff>return(0); / z4 F& P9 r8 n
}
5 O5 S% p+ x1 v. L. O- f
2 B! p& p- ^/ f; e! \/ t</FONT>
6 J1 z6 {! k9 `: S</P>
( K) X) l( V- j4 k9 u- @) F<><FONT color=#ff0000>函数名: geninterrupt </FONT>  P/ l, [, C* P
功 能: 产生一个软中断 - D7 N$ x& o/ V2 b. z
用 法: void geninterrupt(int intr_num); ' l( S& h% E3 ]* L+ J
程序例: </P>' F. [5 {+ Q- ~$ V2 A
<><FONT color=#0000ff>#include <CONIO.H>8 c, P$ c, G/ @& V+ a
#include <DOS.H></FONT></P>, t% J6 z" s+ g# E2 f
<><FONT color=#0000ff>/* function prototype */ + C/ o4 {) z" ]) P0 K5 ]7 O$ Y/ \
void writechar(char ch); </FONT></P># e* X% K6 x8 ]7 q2 n* L9 t* D6 X
<><FONT color=#0000ff>int main(void) ! r" ^1 B$ E  s4 Q- }3 |
{   n0 t" w7 U5 Y
clrscr();
% O, d7 p  r7 [# F# u0 Sgotoxy(80,25); 9 B& ^4 g3 ]5 O9 V
writechar('*'); $ q. e, U& ^6 e, }; l# {0 O- y4 m; a
getch();
. `% t6 }* H2 `return 0; / a2 Z% g% d: \9 ]3 Y2 E- d
} </FONT></P>
0 ?7 w+ W' d1 }<><FONT color=#0000ff>/* " _8 T7 I6 u/ e7 U% I/ @' h
outputs a character at the current cursor
/ L. S6 L. ~4 f0 Dposition using the video BIOS to avoid the ! n; t0 W. j5 b2 m
scrolling of the screen when writing to ( A0 @! `$ a0 ~7 |+ X( U
location (80,25).
9 t; ?2 y2 N* V) w& w. N4 [( [  E: t. ?*/ </FONT></P>
; r, c/ F: z  B+ I9 }/ q<><FONT color=#0000ff>void writechar(char ch)
" G7 ]6 V& _$ _8 w  _1 \9 C{
! H+ G/ F4 K2 e; K, T7 l8 t0 w& o4 {struct text_info ti; " O4 z$ e, Y8 a8 d% n# e
/* grab current text settings */
* R. U" @' v$ A7 qgettextinfo(&amp;ti); * h  h7 I( I2 f. H+ e( D
/* interrupt 0x10 sub-function 9 */ + a2 V/ E% {/ N1 l/ D6 {  b
_AH = 9;
0 u$ ~: X( n3 l3 y% a+ ]0 I/* character to be output */ : l/ P$ v/ ^$ L3 N" A/ R
_AL = ch; # g1 Q) d6 u+ d8 \+ l. v: I
_BH = 0; /* video page */ 5 `( o8 d& H# l( c% S2 ~3 V
_BL = ti.attribute; /* video attribute */
8 t% a3 v. Q' g( s_CX = 1; /* repetition factor */ & v3 N0 A5 n  k; h
geninterrupt(0x10); /* output the char */
/ D3 S- B/ L, d}
# F; w0 Z( r  X</FONT>
% I0 k: g$ _  _</P>( f  ^8 E! m1 P/ Z' Q
<><FONT color=#ff0000>函数名: getarccoords </FONT>2 B. @$ R% z( Y6 [) k
功 能: 取得最后一次调用arc的坐标 7 r# \1 g& E3 Z2 @2 {- _! h5 k4 ?4 v
用 法: void far getarccoords(struct arccoordstype far *arccoords);
/ y6 [4 m6 C9 @9 O5 Z; U程序例: </P>- O' r) ^6 G" g; M- ]7 p( i" E
<><FONT color=#0000ff>#include <GRAPHICS.H>
9 E( f. L* P3 W- i& V* V#include <STDLIB.H>& W3 q  Q% v6 _
#include <STDIO.H>* f  c0 M7 H4 a0 ^. H7 q  t- C6 }1 J+ c
#include <CONIO.H></FONT></P>: h1 }7 ^) G9 G- T. u+ G0 S
<><FONT color=#0000ff>int main(void)
* f* F% E! `. [& j8 [# }{
) ^9 L" e' s! g- I/* request auto detection */
1 }0 M, p  z' q5 o# Y3 oint gdriver = DETECT, gmode, errorcode;
6 b2 P) Y% ~. `, vstruct arccoordstype arcinfo;
3 d( ~3 h) Z$ |$ Y" Tint midx, midy;
% C$ F  t+ \# xint stangle = 45, endangle = 270;
1 @5 O4 l' u# g$ [8 hchar sstr[80], estr[80]; </FONT></P>4 q" I2 K3 Y1 f2 O+ F$ m& h3 f
<><FONT color=#0000ff>/* initialize graphics and local variables */
9 s$ R$ |' `9 ^; }: @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ L8 c) K' |9 R3 T4 r- e8 j/ [<><FONT color=#0000ff>/* read result of initialization */ % v/ A9 {3 \$ _0 H, T6 T, \
errorcode = graphresult(); ; s1 v' h, Z! {( c0 F# P
/* an error occurred */ 3 Q' I1 F7 E- r, P) t% x3 e9 {$ ~+ @
if (errorcode != grOk) " ?: o9 Q( t4 h2 L( {# v
{ % r" b4 C$ r; ~/ Y2 J4 m
printf("Graphics error: %s\n",
9 B/ d* i$ w  _) O5 c% t% b! Rgrapherrormsg(errorcode));
+ s$ z& z; `5 P4 }# oprintf("ress any key to halt:");
$ b; p# S0 p3 {" \+ wgetch();
& Y" |2 a+ m; \, i7 M; B1 ]# U& [/* terminate with an error code */
% J# m) }3 e! Dexit(1);
  ?  H4 v0 C0 o2 O5 P! `1 ?} </FONT></P>
' ^" `3 w" M# X3 |. ^! S<><FONT color=#0000ff>midx = getmaxx() / 2;
8 t# g2 M/ Z- a, v+ e' k6 Jmidy = getmaxy() / 2; </FONT></P>
0 v$ g, u/ j" A" Y' D<><FONT color=#0000ff>/* draw arc and get coordinates */
: L' g2 S3 H9 D8 s0 `setcolor(getmaxcolor()); + u) ^# k6 i" U) U/ X1 K3 q
arc(midx, midy, stangle, endangle, 100); & Z/ B6 S, n3 t# a
getarccoords(&amp;arcinfo); </FONT></P>
4 e& ?/ |- M) b<><FONT color=#0000ff>/* convert arc information into strings */ 7 ?4 I' C4 H; a6 ]
sprintf(sstr, "*- (%d, %d)",
$ l- b0 o; i& ~) iarcinfo.xstart, arcinfo.ystart);
/ I4 |( o- u7 N0 t3 l! usprintf(estr, "*- (%d, %d)", + i6 W7 m7 \* r+ C3 B6 y& N2 N2 I
arcinfo.xend, arcinfo.yend); </FONT></P>
/ c$ F$ S7 x! Q) P( ^* F; I<><FONT color=#0000ff>/* output the arc information */
. ]4 J% I0 E( ?+ S! w/ mouttextxy(arcinfo.xstart,
$ _5 O! H2 P' n4 a1 carcinfo.ystart, sstr);
& }5 m% I6 n+ ?& |, houttextxy(arcinfo.xend, 2 B% H3 j. ?# t3 e' ?$ g
arcinfo.yend, estr); </FONT></P>
; a: I- Z8 S: [* z<><FONT color=#0000ff>/* clean up */ 0 n$ ?+ L. Q# Z2 K: _
getch(); ' v5 i, z  }' `3 s
closegraph();
9 f5 @# |+ b# D2 P' {# kreturn 0; 4 G* M* d8 n/ O- I( z$ E. H
}
8 T" H) [6 }5 l7 ~# G  w; L</FONT>- e. ^, q# q1 N! j
3 x5 Q+ I- `" H3 m
</P>& s+ C6 H, D+ s; I1 L
<><FONT color=#ff0000>函数名: getaspectratio </FONT>5 ^5 n3 _+ b$ X' ^
功 能: 返回当前图形模式的纵横比
1 [6 x0 n$ B$ ?- M' S* G用 法: void far getaspectratio(int far *xasp, int far *yasp);
4 y0 [- n9 P5 k( Z程序例: </P>3 B+ H: z; b8 r  @% h# p' K
<><FONT color=#0000ff>#include <GRAPHICS.H>
4 @- \2 O! v' V$ e' K& n8 \& B! X/ R#include <STDLIB.H>4 {/ \. m' @6 S5 S* n! E
#include <STDIO.H>
# f: Q. t& G$ }4 {% Q- s6 g0 a7 c#include <CONIO.H></FONT></P>
! X- m: D/ C9 R# I0 n3 }  v<><FONT color=#0000ff>int main(void)
" B3 U6 x* x' @4 r{
* S9 _( g- n/ S, o$ t2 O3 [/* request auto detection */
) m7 P5 _+ j) t, E7 b" Z+ Uint gdriver = DETECT, gmode, errorcode; " T" u1 s1 d! R5 I; }
int xasp, yasp, midx, midy; </FONT></P>
  P# v  N9 s* R7 C- k, r4 Y- H$ f<><FONT color=#0000ff>/* initialize graphics and local variables */ 5 R7 H# s  }. P, S4 [
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. c: B6 r; A5 A: |' U1 O. ?" D
<><FONT color=#0000ff>/* read result of initialization */ $ K; P! Y1 A$ y" Z  d$ L
errorcode = graphresult(); * v% g/ q  ]1 s2 \& F( o% j
/* an error occurred */ 5 f- o4 u% {( ]  P% q. ?+ z
if (errorcode != grOk)
7 r* |# M' q0 r: n2 [{
+ [( Y! x  |: N+ w: ^1 J$ f$ Nprintf("Graphics error: %s\n",
4 C' W5 F& W$ r$ G% H/ Agrapherrormsg(errorcode));
- ?* l, \, E+ N+ D# m, ]printf("Press any key to halt:"); 3 l! i9 G5 ~. u& I# ]: O
getch(); 7 [0 {. o( |1 G2 m( {
/* terminate with an error code */ 0 }) o1 e9 F' n5 i
exit(1);
  b6 [# p2 G# I: V4 c. `6 g2 C} </FONT></P>% U+ u8 A2 y* l/ J7 T* V1 {
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ O# m& q9 d2 Q. Y/ j0 h
midy = getmaxy() / 2;
$ d: u; ?# ]' a- S- x2 S0 d1 {$ `setcolor(getmaxcolor()); </FONT></P>
  M4 S+ e9 V5 f% L& }& v4 f: A9 [5 W<P><FONT color=#0000ff>/* get current aspect ratio settings */
- \) T+ b6 ~& j1 p0 ^) [getaspectratio(&amp;xasp, &amp;yasp); </FONT></P># c% e3 x# d/ @9 S" u
<P><FONT color=#0000ff>/* draw normal circle */
/ t0 E0 J3 c9 wcircle(midx, midy, 100); . m( P1 w; |6 k5 K# Q. R9 ]
getch(); </FONT></P>
% m  P0 T/ J9 I7 |2 @0 x<P><FONT color=#0000ff>/* draw wide circle */
/ {8 I. m! R+ ]% hcleardevice();
- m* h4 P: a& Z* K9 X, D/ K9 V% isetaspectratio(xasp/2, yasp); * z  t! y$ M7 ^+ }6 G) x
circle(midx, midy, 100); % h' F' t% E8 B4 G* m( N5 L3 L( J
getch(); </FONT></P>
4 o1 {, B3 ^+ o5 B6 `4 C3 {<P><FONT color=#0000ff>/* draw narrow circle */ ) E% X- \7 I. o$ f
cleardevice(); - b7 U" D! `5 @
setaspectratio(xasp, yasp/2);
8 S5 ^! N  Z* G+ J% Gcircle(midx, midy, 100); </FONT></P>
8 N# X3 v- a& }. o7 m- c3 c<P><FONT color=#0000ff>/* clean up */
/ n5 Q8 S& @9 j& F8 N% m2 Agetch(); - X+ U3 n( s' s9 f% G: d5 D
closegraph();
* Z$ S. q5 E+ g( X# L9 Hreturn 0; - \6 F( [5 \) h% v% d0 e" R
} " o9 M1 y8 s* [, R- ~1 ^# p
</FONT>5 i( b7 G% y: z! v
. |7 w' l# x. L. u0 Q! ]5 j
</P>/ c. ^& U) [! \- x" r9 v8 e7 c
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>, W: D) }# T8 i4 T
功 能: 返回当前背景颜色
5 o& V0 J, d! w' r% P$ u+ k; T用 法: int far getbkcolor(void); * y$ L9 N" x) S9 ^, H8 |
程序例: </P>2 l4 N. o" h+ S; |; g1 G
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ ]& m0 o- a3 w4 x+ N. o& z
#include <STDLIB.H>
' Z! n3 u3 N0 S3 I& v# P#include <STRING.H>
5 y+ n" D) W6 D; J' \#include <STDIO.H>
7 O% o7 b7 B9 @7 B8 J, V8 R" }# v#include <CONIO.H></FONT></P>2 R8 M& ~2 {/ {9 {
<P><FONT color=#0000ff>int main(void) 3 [% Z( k9 U0 i& l+ ?. }
{
9 ?1 [4 l+ B$ P/ B9 v$ I; h/* request auto detection */ " G- r& h, N! t
int gdriver = DETECT, gmode, errorcode;
8 Y) y. w. n) m% U3 ~/ x/ `int bkcolor, midx, midy; 2 Q& ~8 @0 A5 v+ W6 ^8 e
char bkname[35]; </FONT></P>
4 u9 R: m$ ~7 ]% u<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 y7 {9 o0 I  p. b! X4 r0 rinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 R* |& A" @$ s9 x
<P><FONT color=#0000ff>/* read result of initialization */
9 {3 A6 W* u: h% a& @; Nerrorcode = graphresult();
% [- N& E- ^) ~- k/* an error occurred */
( o/ @8 I; e. A3 B+ aif (errorcode != grOk)
# s7 c  I1 E* S* f/ f) ?# K{
3 y4 q- Y) ~$ [0 Z$ s! ~, l4 bprintf("Graphics error: %s\n",
. e. i, [' b6 q5 q( Q$ Fgrapherrormsg(errorcode));
/ ~: N2 y/ G/ B! E4 c8 I: Hprintf("Press any key to halt:"); # ^) P3 C4 T% [
getch();
* r1 w' q4 _/ K$ b9 R$ K$ H4 {/* terminate with an error code */ ; E7 ~; }( c  L; I
exit(1);
& U$ W1 F* z- y8 A, _6 c} </FONT></P>  t% B1 {, K' v' `
<P><FONT color=#0000ff>midx = getmaxx() / 2;
( R2 M  n! r4 s& w$ E5 I! [midy = getmaxy() / 2;
& b/ A: Z8 c. Q; \" J! C" Fsetcolor(getmaxcolor()); </FONT></P>: ~( r! C8 |; u- n  X  |
<P><FONT color=#0000ff>/* for centering text on the display */
( z3 s8 k( f1 R; v5 K. F  `! l! T- Msettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
) r4 R% n7 q* l3 A: \<P><FONT color=#0000ff>/* get the current background color */
$ h2 _$ ^5 I& [bkcolor = getbkcolor(); </FONT></P>! Z3 B+ n) v6 E2 b% u
<P><FONT color=#0000ff>/* convert color value into a string */
; I% {& Z- u, X0 n6 }itoa(bkcolor, bkname, 10); / M+ U( p. z" i# a9 s. r/ Y" u
strcat(bkname, 3 q9 g0 m, ~1 T
" is the current background color."); </FONT></P># M9 ~' s0 M' Z  A
<P><FONT color=#0000ff>/* display a message */ 0 Y# S$ [* l3 B& F0 `
outtextxy(midx, midy, bkname); </FONT></P>
' V  y8 [, o% I' K8 `- r7 y<P><FONT color=#0000ff>/* clean up */
' I$ h, }! v. k& O4 j  S! ]; E- \getch(); 3 r7 a; l! \: p8 f$ ?- T" Y
closegraph();
8 n% M8 P" w  [: a  Kreturn 0; . ~* `1 p& W; s$ M3 {0 z
}
* y: g0 V' u. ]) g8 b- u% G  i, O1 S1 f! {+ b. Y
</FONT>  @6 a4 f$ R/ u- X2 j* I5 m
</P>! @" h* p# j. B( O1 b
<P><FONT color=#ff0000>函数名: getc </FONT>& w+ u: _0 E2 @- m6 e* D
功 能: 从流中取字符 6 o' U4 R7 A9 w4 f
用 法: int getc(FILE *stream); 5 c( f# ~8 x1 K
程序例: </P>" K9 z0 v$ U# v* U: ^3 b
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
. P$ w! Y# G0 ?<P><FONT color=#0000ff>int main(void) 7 s& e- f* E6 u' z" K3 y
{ 8 W1 C, {0 R' S
char ch; </FONT></P>
; f' _2 b, C+ p" E1 U& ~<P><FONT color=#0000ff>printf("Input a character:");
9 U& U- r+ F+ `2 H) q# c/* read a character from the 5 o; f- N; v; f
standard input stream */
9 |& h7 F. [' Jch = getc(stdin); " M) j& S/ c" [" H( l
printf("The character input was: '%c'\n", # w% c$ j5 ^$ [- E& Q: O
ch); 3 x, n( q3 f0 e
return 0; # D4 d6 R6 j# {! m) I
}
* k* R- A. D) e, p8 P' v% V( F+ e5 \$ i. ^1 i+ y7 @2 _
</FONT>  Y5 z& q7 E" G8 N7 X
</P>
. n1 T) X2 J2 w3 @4 i/ d# z<P><FONT color=#ff0000>函数名: getcbrk </FONT>
! h( F9 Z- S) b! T( J# c6 [5 V+ \' S! y功 能: 获取Control_break设置 - S# x1 j# o1 D
用 法: int getcbrk(void);
7 [$ U5 Q& o% q# d% D2 D* W6 d程序例: </P>: Z/ u' z6 N; X3 a
<P><FONT color=#0000ff>#include <STDIO.H>* W7 ^1 i& C0 N, f( ]
#include <DOS.H></FONT></P>
: P( N# J7 r% m' g, Z<P><FONT color=#0000ff>int main(void) , j6 q5 |9 N5 x5 Y6 R; F
{
3 K; Q0 a& Z3 f( y& F( Mif (getcbrk()) * a) A  o. v) T' y; ~$ Z1 W
printf("Cntrl-brk flag is on\n");
1 d2 k; Q! o1 Y2 F) ^else " a( m* J; `  A4 ?( I3 `0 h
printf("Cntrl-brk flag is off\n"); </FONT></P>
/ {9 f2 R- ^( N6 I- g<P><FONT color=#0000ff>return 0;
0 ~3 w+ ?- W/ d, W* _7 r3 z} </FONT>
2 X9 M+ L3 w! b" Q! `+ J" |" F& E, C9 h1 p( D
</P>
8 o  @* z$ m) q+ q# c<P><FONT color=#ff0000>函数名: getch </FONT>( H" M# u" Y+ f4 x& Y- r2 a9 t. l
功 能: 从控制台无回显地取一个字符
/ m0 v* ^+ S) Y; g$ n用 法: int getch(void);
* v. s# r1 n. m程序例: </P>" w& U7 s, i7 ?0 B! ~" p+ g
<P><FONT color=#0000ff>#include <STDIO.H>
: E5 U( b0 T4 y#include <CONIO.H></FONT></P>, l& ^" _8 E  m! R; X
<P><FONT color=#0000ff>int main(void)
* w, \7 _- p: a. A9 n7 ?{
) h+ G+ L- n8 f6 Fchar ch; </FONT></P>
5 W- Y; O0 B( ~, U1 z2 s/ D" q<P><FONT color=#0000ff>printf("Input a character:"); 8 r7 z3 p4 P# l8 U: c
ch = getche();
( T1 b; Z+ v% U' H$ x% u6 S  U: S' g+ p7 Zprintf("\nYou input a '%c'\n", ch); 6 V4 X8 I. a4 {- k4 G3 p& j$ i
return 0;
9 o0 G! O5 w, _& U7 p; D1 ]}
- Q3 N2 N8 `1 m. q/ B* x0 T- K% ^' t  n0 H' J  z  `$ S- i
</FONT></P>& o7 |- B6 a  G5 E9 j% _( z9 `
<P><FONT color=#ff0000>函数名: getchar </FONT>( n0 K6 w# U$ P
功 能: 从stdin流中读字符 5 d' s* `. e; z
用 法: int getchar(void);
+ n4 N6 k* O0 d; Y- f$ B程序例: </P>
0 n8 s. I5 W! @7 v<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>1 b% C; T& P. @; y+ u5 O9 [, `
<P><FONT color=#0000ff>int main(void)
# c. p" N4 [( f$ y{
' `9 x* s2 v! S" E: Dint c; </FONT></P>9 o( r. c( ^" Y1 i1 Q
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
9 P, j: d2 B. p' u8 tis line buffered; this means it will ( R: N5 ]/ J4 w* r$ u
not return until you press ENTER. */ </FONT></P>6 n: |) H8 r/ C1 Y0 t& `
<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
& A$ L( I7 i, t9 h* M7 f8 dprintf("%c", c); </FONT></P>
3 d/ H; D- Q/ H0 C<P><FONT color=#0000ff>return 0; ' {1 I7 C2 C7 s6 \" v- B% U2 z
}
2 G) p1 S! d, C</FONT>
1 F3 T, ]  n+ _</P>, E( u3 O' H1 A+ X6 [8 x
<P><FONT color=#ff0000>函数名: getche </FONT>
% |' w* D) a5 k6 R' v; A9 Y功 能: 从控制台取字符(带回显)
- S; H% _) v, k$ I4 v* M用 法: int getche(void);
5 l' u" R" a$ F' Q5 F$ K程序例: </P>
  }0 [# x3 z0 e+ H6 r8 ^<P><FONT color=#0000ff>#include <STDIO.H>
6 i% U: \& ]$ |( C#include <CONIO.H></FONT></P># q2 Q( P1 t8 C( v1 g$ }& F
<P><FONT color=#0000ff>int main(void) / q" x5 l9 n7 K
{ 9 o; u& P1 z; Q; b' N: i# ~
char ch; </FONT></P>
* k( Q, R  Z/ f( e) M5 d<P><FONT color=#0000ff>printf("Input a character:");
/ q4 c% o$ j' a  N* |ch = getche();
& N  a) H- a$ U* T$ k( Zprintf("\nYou input a '%c'\n", ch); , X7 I# T/ V( W2 _% n- A9 S
return 0; 2 l1 R$ I# V7 C; ]$ h) Z* C/ J1 u
}</FONT> ' \  F  ?' Z7 Y0 H; [1 K

9 a/ _" t% L" \8 }1 N. i" r</P>; [: H8 k2 b) R" g
<P><FONT color=#ff0000>函数名: getcolor </FONT>9 }& W+ N; ^. I) {$ W/ P, `
功 能: 返回当前画线颜色
$ m; V' B1 o$ m+ `. ?4 R用 法: int far getcolor(void);
. q! `4 g  ^4 V- F; S5 E程序例: </P>
$ v, k  f1 N, I/ K! T+ \<P><FONT color=#0000ff>#include <GRAPHICS.H>
! i7 D* v2 a/ E: W% l3 V  B#include <STDLIB.H>
2 x  L4 J- o& V  i#include <STRING.H>
( W" t( V5 @( }( h3 Y7 z2 H6 b, F#include <STDIO.H>
/ Q* a( O* a5 w#include <CONIO.H></FONT></P>% m. f2 l3 Y' ~
<P><FONT color=#0000ff>int main(void) / @6 Q' r- j' Z9 q) {. V
{
0 z6 g- @' Y9 u0 Z- I/* request auto detection */
* o3 N4 z: ?4 z$ \& iint gdriver = DETECT, gmode, errorcode;
) `% [  t. K% x8 a$ bint color, midx, midy; 4 M( G9 O* K1 Z$ K% W) V0 U
char colname[35]; </FONT></P>" ]- J. J9 W/ m2 K/ I! q
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! d! ?1 x( E* j( U: s1 l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ Y9 k0 e0 e: D7 r/ Y
<P><FONT color=#0000ff>/* read result of initialization */ ! ?  U3 f* b- S" t# w2 j, Y# }
errorcode = graphresult();
2 w1 N8 u" i! `* ]7 i) U( x( o/* an error occurred */ 2 \+ \1 w2 I) {: k
if (errorcode != grOk)
2 {  y1 [. g5 ~# u0 [{ 9 @  k6 J9 t- e. {: w2 I
printf("Graphics error: %s\n",
6 v% o* j, B  b, D) [5 ]# f8 Egrapherrormsg(errorcode));
/ \, T& A& p) `! B7 @7 b% Rprintf("Press any key to halt:"); 9 @; n! n7 _1 L, u6 ]
getch();
5 S: ?0 ~# Z% j4 @; D/* terminate with an error code */
2 _) Z# R# j  i! g1 f! s6 jexit(1); # h4 ]  h% [3 J* H2 y' J1 N3 r1 r( K
} </FONT></P>: X  O' b2 r3 T/ q+ ~6 b5 H+ a# {
<P><FONT color=#0000ff>midx = getmaxx() / 2;
4 V. d4 R9 j- \- x" Lmidy = getmaxy() / 2; ! B6 L2 V& K# L" W# C
setcolor(getmaxcolor()); </FONT></P>7 M/ _( z/ f" D  G/ l
<P><FONT color=#0000ff>/* for centering text on the display */
8 Y" s* A2 @! A) ~6 W# W/ E, Wsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>$ e- s2 T7 N2 Z* |" Y
<P><FONT color=#0000ff>/* get the current drawing color */ 3 t4 y) ?8 Q4 w% W* L1 A* ]
color = getcolor(); </FONT></P>& X8 D4 _8 A5 n- B: |6 a* T& {' }+ i: B
<P><FONT color=#0000ff>/* convert color value into a string */
5 i1 o, @+ o6 D' litoa(color, colname, 10); 8 ]9 U- n2 {' v$ o
strcat(colname, ! K2 {$ \/ y, q. x$ |
" is the current drawing color."); </FONT></P>! Y' r; }4 d  Z2 t. {) _/ c  s) i
<P><FONT color=#0000ff>/* display a message */
) p+ a" L3 @3 E6 \) ^3 t+ gouttextxy(midx, midy, colname); </FONT></P>
* ?* a9 o; Z# j0 X3 H- S<P><FONT color=#0000ff>/* clean up */ $ ?- m6 f' N/ r8 q: x$ a7 X
getch();   w# Z3 [* B: A( P1 c8 K+ L7 b
closegraph();
" u; Q0 O3 Y/ \( k6 U+ A, `$ N7 s+ {return 0; 3 m4 y7 o- [% U9 k8 J
}
" Q6 i% {' }# q( t5 \9 e</FONT>6 I) q! `6 |9 W# Y/ r0 ?
</P>. E$ P" t. t* f( q( F7 k
<P><FONT color=#ff0000>函数名: getcurdir </FONT>8 d# a) Y/ e& M3 |5 L. ^
功 能: 取指定驱动器的当前目录
! {) p$ w# d5 ~0 Y3 ]: `) z用 法: int getcurdir(int drive, char *direc);
) f' a) M/ O* w  w8 ~' k$ \程序例: </P>% Y2 x4 A( A! q; H5 \
<P><FONT color=#0000ff>#include <DIR.H>! w* l1 D# }) u
#include <STDIO.H>
! {% ~4 {; ]# M  ]' d4 g- b: y#include <STRING.H></FONT></P>: ~* P) Q1 u  i8 \
<P><FONT color=#0000ff>char *current_directory(char *path)
  ^; _6 X% i4 h" ~/ g{
1 @4 p2 Q5 I0 [$ }& i4 \! xstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ " V0 j2 ^- S& y6 t" `- d
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
/ Q0 p" j& H/ d3 xgetcurdir(0, path+3); /* fill rest of string with current directory */
& I$ h3 C7 P; treturn(path);
+ U+ `# h: q0 y- H' e/ h9 x: u} </FONT></P>0 t; L. t  a: [6 V6 R2 J" @
<P><FONT color=#0000ff>int main(void)
$ D* c" z6 W8 }' Z; d{
2 @4 R9 m% `6 T4 n  dchar curdir[MAXPATH]; </FONT></P>
5 i, `' e1 m6 J0 y+ V<P><FONT color=#0000ff>current_directory(curdir); * |3 }6 @- S2 O1 i- s
printf("The current directory is %s\n", curdir); </FONT></P>
/ q/ s3 z) S% Q7 S1 ]+ N3 X" J6 |<P><FONT color=#0000ff>return 0; / f2 J9 D' c3 g0 d$ }
}
3 N  Z: `* w; [6 i3 v</FONT>
/ J8 q9 K5 `( A7 \3 s' g</P>9 I% N% D. L0 W
<P><FONT color=#ff0000>函数名: getcwd </FONT>" U- }1 t& V: C7 P. x
功 能: 取当前工作目录
* o0 b. g- w. ^8 I+ b: P7 N, u/ ]用 法: char *getcwd(char *buf, int n); / m4 a* G7 s" ^2 m! G# g
程序例: </P>
; m- _  d* O6 P5 k<P><FONT color=#0000ff>#include <STDIO.H>
: g* i' C. r1 ]+ t#include <DIR.H></FONT></P>
( o* H, [1 {* j<P><FONT color=#0000ff>int main(void)
5 f2 [+ \, b1 K+ C  ]' `{
; v/ J$ E  l* ^5 T$ h: N* Nchar buffer[MAXPATH]; </FONT></P>
0 B1 Q: x2 j1 |% e! h, K+ J<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); 8 Q0 c* T! a6 A3 l
printf("The current directory is: %s\n", buffer);
7 `; u) i3 B6 g0 B1 Treturn 0;
6 M' r& J6 |- i} </FONT>
/ X$ D2 k" H# Q2 v9 ?, F
4 C( X. n! m( r; l! z6 M1 t" }' x</P>
" e6 O1 B7 t# Z0 l  i<P><FONT color=#ff0000>函数名: getdate </FONT>
# c! w* J1 [' Y$ o功 能: 取DOS日期 4 e1 s7 M, T! x1 _% x: t, ]
用 法: void getdate(struct *dateblk);
* v/ }3 E. m. s) o# i程序例: </P>" z7 E# V1 J2 z2 {/ z; k
<P><FONT color=#0000ff>#include <DOS.H>
  y  M4 m: s& A3 z# G6 w6 y#include <STDIO.H></FONT></P># d  T  }% G1 B) i2 d' r: q
<P><FONT color=#0000ff>int main(void) ' ~, I. L' z8 O  c5 q: H* F
{ $ f- U+ V1 D) Y1 e
struct date d; </FONT></P>2 y# J: \9 [, @! s
<P><FONT color=#0000ff>getdate(&amp;d);
. ]' L4 f4 B9 d0 c8 sprintf("The current year is: %d\n", 4 Z- r3 V3 ~8 `7 s% K
d.da_year); / P9 ~: S! ~" q8 P8 y7 K3 S
printf("The current day is: %d\n", - |, B4 g5 F; _' k6 h# f1 S
d.da_day);
5 s$ n* b  a3 d6 x& hprintf("The current month is: %d\n",
* \# E- ]4 [; x7 Z( d3 ]d.da_mon); - ^( q3 s& r& L: S% B: ^. K
return 0; % V: p6 O2 N6 Q# W
}
; p% u+ }! w/ N- s</FONT>
8 v/ y* U  c% y4 G8 r* h1 b) R</P>
+ o( E4 h5 O4 Q, D, Q, w<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT># Y' {9 C6 b" X7 ]% d4 G# v. b$ C, R
功 能: 返回调色板定义结构
+ I; L  p4 E1 u8 |  I用 法: struct palettetype *far getdefaultpalette(void); 3 k& f; m# u. P
程序例: </P>
* t8 X0 J$ U3 V4 ]5 z9 ?<P><FONT color=#0000ff>#include <GRAPHICS.H>4 K% G. y& V; x7 o7 Y
#include <STDLIB.H>7 u2 m4 a1 l3 ^7 }4 G0 E2 A% |
#include <STDIO.H>  A& |! T& B! }) F: `# E
#include <CONIO.H></FONT></P>& e& F* d8 [0 F5 k1 H& F
<P><FONT color=#0000ff>int main(void)
2 T0 O, ]& W: L! I0 ~- d; Z; N{ ; C. E4 ]8 z9 f2 p. J" H
/* request auto detection */ " U( W! P, ^. P; W% Y; {
int gdriver = DETECT, gmode, errorcode;
/ H. D4 `6 ~& W* L& Hint i; </FONT></P>" q4 H+ S4 C. g# B( E
<P><FONT color=#0000ff>/* structure for returning palette copy */ : p9 `6 I, {1 }9 X5 Q* i: Q4 T: q
struct palettetype far *pal=(void *) 0; </FONT></P>, P" F) x2 h+ @) Q9 m. Z, `4 S/ v1 \% |
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 d/ V* r& [; }  h  dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
- `7 [) O% M1 E' v<P><FONT color=#0000ff>/* read result of initialization */ . {- N( g0 k: t/ Y2 y
errorcode = graphresult(); 1 U. J- H7 i! E) X, {
/* an error occurred */ 6 L& q* |) y9 n, q! o
if (errorcode != grOk) $ _. R: i; d1 j+ W8 n
{ 8 h9 n: S5 p# n( G
printf("Graphics error: %s\n", 6 @) b& d- O8 D7 i9 \( ]
grapherrormsg(errorcode));
8 g: `- a; K& j: p0 B, I6 y7 Dprintf("Press any key to halt:"); - H2 N1 y! Y, s' w+ C2 V/ a8 I
getch();
! C7 g+ S5 ^. R. h6 A3 r/* terminate with an error code */   r, j  ]2 s/ p; d6 ^
exit(1);
- s/ p/ F; r$ q- H% r} </FONT></P>& [- l/ t" Y: {- [2 X, ~6 z
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>8 |; G  V' a0 G
<P><FONT color=#0000ff>/* return a pointer to the default palette */
: q8 ]! D+ w% ^. H1 ppal = getdefaultpalette(); </FONT></P>5 R& i7 {0 r8 Y! z( z
<P><FONT color=#0000ff>for (i=0; i&lt;16; i++) ! @# J2 b0 P  H+ E: M1 [
{ 1 k4 {# p% b1 w
printf("colors[%d] = %d\n", i,
% T, Y: u  w0 A! [pal-&gt;colors);
6 `; ?0 R& A3 b6 S! r3 Zgetch(); 2 v( W4 |& u2 N
} </FONT></P>
! w  ~, e* \7 `1 }5 F& H<P><FONT color=#0000ff>/* clean up */
+ L( o8 t* n# V2 |getch();
) n9 c8 T2 B: Xclosegraph(); * u; n& D) E0 q5 t9 h" T! \2 N1 a
return 0;
) ^) T  f* j/ n5 D}
0 m' A1 E9 N! E</FONT>, X# Q# H) y8 N' I
</P>
" C- J+ l7 t- F+ _! R0 f<P><FONT color=#ff0000>函数名: getdisk </FONT>
& e* k" X3 Y( `( a0 t: F' b+ p3 q功 能: 取当前磁盘驱动器号 : j8 z6 e; i' ~
用 法: int getdisk(void);
2 A1 o9 o* {1 C程序例: </P># P" X8 p4 A) Q$ ^- m  q2 D
<P><FONT color=#0000ff>#include <STDIO.H>% f* v$ r2 b2 U- m0 k
#include <DIR.H></FONT></P>
  ~$ Q; ^- P" i5 D<P><FONT color=#0000ff>int main(void) ; ^8 `8 u5 F3 |( M! p
{ 0 v% E" W. X+ E9 N$ I" f
int disk; </FONT></P>
. i7 {! T& }1 c( h<P><FONT color=#0000ff>disk = getdisk() + 'A';
0 ?% Q0 c* F* [- @* ~printf("The current drive is: %c\n",
7 M# C" p  z: J  j/ @4 M; c  vdisk); 2 a2 c! \. M" z' ^0 A* ]2 h
return 0;
% f# g7 x9 [9 F} & c7 p5 ]4 |& F# X

) R4 H# `# H8 k</FONT>! F- |  g$ @8 N( v* K6 I
</P>
1 i& y, U6 Y5 {+ Z<P><FONT color=#ff0000>函数名: getdrivername </FONT>& j- r% D1 f! L' G) ~, q
功 能: 返回指向包含当前图形驱动程序名字的字符串指针 & h% e: D5 n6 W. ~' ~  ]
用 法: char *getdrivename(void);
& I, h5 c+ u& _- t8 m) W8 _程序例: </P>5 v% k9 D6 `( j) w
<P><FONT color=#0000ff>#include <GRAPHICS.H>, A  i2 `8 A" I1 o4 ~
#include <STDLIB.H>+ r7 `% S6 P( B0 u
#include <STDIO.H>: A: f( a7 X1 z, Q9 Y
#include <CONIO.H></FONT></P>
- ~, a& H% k) N, g) z7 H% f& t<P><FONT color=#0000ff>int main(void)
( Y5 l" P, h$ \, v. k{ : ~" H! p4 a# m( D
/* request auto detection */ 8 L6 z5 L) R  h1 g; V# e
int gdriver = DETECT, gmode, errorcode; </FONT></P>
3 L6 ]; W- G# V, W9 w- E- q<P><FONT color=#0000ff>/* stores the device driver name */ ) [$ f4 Q" ^' ^4 c/ g6 f- b9 b
char *drivername; </FONT></P>
' G! [9 M1 e' N, `+ k9 |<P><FONT color=#0000ff>/* initialize graphics and local variables */
- j0 f( @( C. ^, Jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 Y& H: r) O$ b' [
<P><FONT color=#0000ff>/* read result of initialization */ , b) G! }" Q5 `
errorcode = graphresult(); 4 G2 p9 X' G; Z3 q9 o4 m. A5 `9 R, h( P
/* an error occurred */ * H# d7 }( a5 u
if (errorcode != grOk) , V) C+ V" \* s0 F9 _$ z" q
{ . U/ s0 b& b- C" S& c  F3 i
printf("Graphics error: %s\n", % N: d0 V' O4 P6 @8 d; E4 C* {
grapherrormsg(errorcode)); $ h5 m  x) j5 o( C0 ~& O
printf("Press any key to halt:"); + I" [6 C  z; K/ K) f2 A
getch();
% l4 B8 e& _. U' z5 F* u9 \: e/* terminate with an error code */ : T/ c  l4 k& S; {3 f! o6 B
exit(1); * {, K6 d& W6 Z5 _
} </FONT></P>$ x5 y. [% @! J$ B6 k/ D
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
4 k# R6 M4 n/ C0 h, h<P><FONT color=#0000ff>/* get name of the device driver in use */ " v8 o* K* T0 x
drivername = getdrivername(); </FONT></P>
' t5 x, F* x$ v0 K4 j<P><FONT color=#0000ff>/* for centering text on the screen */
7 t; S! J# Y$ M3 i: ^8 |6 m0 S2 C1 ]- wsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
4 ]8 R6 R5 |5 G<P><FONT color=#0000ff>/* output the name of the driver */
/ j2 t  w+ q0 ~2 oouttextxy(getmaxx() / 2, getmaxy() / 2,
/ H, X, H8 b' }5 z: e1 R# {# xdrivername); </FONT></P>
) V5 Z/ ?$ t4 d6 M. k<P><FONT color=#0000ff>/* clean up */
9 s5 \4 p$ X4 z2 C, \7 e5 xgetch();
& R! f% y+ O3 U6 B7 X; P& [8 a+ [9 sclosegraph();
1 Z/ A* t+ O' X: S& Q. ?7 Freturn 0;
& H' R0 y6 ^% d5 W, {' w}
, x5 s% h0 U$ @</FONT><FONT color=#990000>
; @- Z) m8 {5 M$ q6 c</FONT></P>
$ s" d" `1 y% f9 q  k1 q$ d<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
2 A+ D% g5 X, m5 r6 E<FONT color=#000000>功 能: 取磁盘传输地址 5 Q! C, h+ ^6 \# g4 I) |+ N: u
用 法: char far *getdta(void); 5 g! P) V8 l9 m6 q
程序例: </FONT></FONT></P>
: v& _, @" E' R<P><FONT color=#0000ff>#include <DOS.H>7 |* I5 i, O9 y$ s
#include <STDIO.H></FONT></P>5 L+ M0 l0 ~# a% Y+ l- m
<P><FONT color=#0000ff>int main(void)
  j' ?8 _& E# G0 [9 X  G{ / ]$ t. e$ o; w  G% J/ ^% d
char far *dta; </FONT></P>
/ D( K9 c+ d# e& r3 y5 |1 L<P><FONT color=#0000ff>dta = getdta();
- U$ v( v/ g/ r  Eprintf("The current disk transfer \ & {0 T% ]% l* J' ^
address is: %Fp\n", dta);
4 V! _1 [3 c. ^9 }. greturn 0; # X' J" s% Q8 ~- Y* O. x
}
& j1 I/ i# L$ V* y</FONT><FONT color=#990000>
1 N$ E3 r' b* Q& T$ m' X6 j/ o</FONT></P>
) n) ]7 g5 \: }1 C4 F0 t# f6 V<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
8 ^- R" K- ]- C) j+ `1 t' i1 E, c% o<FONT color=#000000>功 能: 从环境中取字符串 $ a4 |8 L, J9 ^5 B
用 法: char *getenv(char *envvar); 8 ~: `! T4 Z7 N: D
程序例: </FONT></FONT></P>
) P' N! {) ?& m0 H* a/ h  G<P><FONT color=#0000ff>#include <STDLIB.H># F8 c7 `. K5 V# U9 B( `5 u
#include <STDIO.H>6 `) u3 f% D  O, K
</FONT></P>) b. o/ F/ K0 w  \2 S
<P><FONT color=#0000ff>int main(void)
2 M' f* i7 O* `6 v( W{
0 ~- k* H( V0 X$ y1 Mchar *s; </FONT></P>
6 ?7 k) F% o/ V8 |! _- U2 N<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ # c" V4 u- S4 l4 R1 W9 U- R. B
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>( R% O0 K2 @# v1 B( n' v9 c
<P><FONT color=#0000ff>return 0;
* ?/ R( O" l0 z5 c& L/ p; `2 e} </FONT><FONT color=#990000>
( ?% p' t7 m  d1 [
$ c# k) ]. P% s) A; C) ~! b# Q! o# Y! Y& H( o" Q2 K, |# D( e9 j3 x
</FONT></P>- K$ c, }7 D6 ~9 a
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>' [% f% L+ ^* g1 p# S
功 能: 取文件分配表信息 - n5 h3 L+ ?1 c- \+ P) o
用 法: void getfat(int drive, struct fatinfo *fatblkp); 8 Z, r5 z3 Y' P
程序例: </P>
7 F% T8 G- D, G& i8 p<P><FONT color=#0000ff>#include <STDIO.H>$ N4 s' F5 F* s- k7 {! X( g
#include <DOS.H></FONT></P>
% K* o/ @! A' x7 b/ V, _# S1 v9 y* M( |<P><FONT color=#0000ff>int main(void) % m  _/ `: [' i" h6 S( o
{
* u$ K$ h9 r0 O/ O) _3 G! m- R3 w2 mstruct fatinfo diskinfo; * ^8 U* K; k+ \- K9 n. E' t6 o3 W
int flag = 0; </FONT></P>
& s; L+ A) O/ k: V9 S<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
$ T! }( S% a- w5 ngetchar(); </FONT></P>
$ `2 X9 D: [, L" ~<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
1 @, E& ], W7 l/ w+ x2 o9 Y/* get drive information */ </FONT></P>+ Z" A3 g2 m8 K4 O
<P><FONT color=#0000ff>printf("\nDrive A: is ");
5 }6 I' n7 l/ x6 Gswitch((unsigned char) diskinfo.fi_fatid) 4 C9 m/ ]: g' Q' T4 z) L. f
{
6 _5 U/ B" q1 j: ~3 O( K- K. _case 0xFD:
0 x4 O% l4 ^) A, ]! Tprintf("360K low density\n"); ' K% @  W" V( [8 e4 I
break; </FONT></P>
: i5 @) O5 ~$ H0 d<P><FONT color=#0000ff>case 0xF9: " a5 T) X" Y8 D
printf("1.2 Meg high density\n");
7 Q8 f, B2 s9 d- Fbreak; </FONT></P>: P& {6 I+ r! i8 n" l
<P><FONT color=#0000ff>default:
5 j) {  r4 e2 \; d; y# a# eprintf("unformatted\n"); - R) A5 ]0 a* g8 S' q
flag = 1;
! y5 O* L( ?+ [/ F} </FONT></P>
- `0 @8 D9 w2 Q8 d3 ~+ ]<P><FONT color=#0000ff>if (!flag)
7 A: I# V- t, h1 E% L! b{
2 s* K4 h3 h% c9 C! M. Nprintf(" sectors per cluster %5d\n",
  p6 g& }! ]& c. `4 \) `$ ?. qdiskinfo.fi_sclus); ! N% C* \2 v. g$ W3 N. E
printf(" number of clusters %5d\n", 3 [8 ]# O% r0 [: _+ M( L* y3 S% O
diskinfo.fi_nclus);   B/ q5 ^8 }/ k0 d* P
printf(" bytes per sector %5d\n",   E! b9 q+ `5 [$ d
diskinfo.fi_bysec);
  U: y7 F* ]; \! w$ K+ p7 b} </FONT></P>
: q( b: K# o5 j+ X( x, Y$ h7 o+ [5 {) A<P><FONT color=#0000ff>return 0; 4 _4 l5 m$ ~2 U" M% {* T# e; P1 F6 a
} . H3 B6 g4 K% l; g1 d+ t
</FONT>" t# B1 y7 Z$ R7 l& g
</P>0 R4 e+ }" m4 m% j7 b: i
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>4 h7 @6 ~3 ^- v, @& i
功 能: 将用户定义的填充模式拷贝到内存中
2 e0 q: z" G1 x3 e2 [用 法: void far getfillpattern(char far *upattern); 8 n' G+ |" a5 `, m$ r. a' B# M+ `
程序例: </P>
$ ]' I5 H4 L% @/ l  [<P><FONT color=#0000ff>#include <GRAPHICS.H>7 v; Y# c( v! H
#include <STDLIB.H>, |2 D( w) o( p/ J; l7 e( D
#include <STDIO.H>
7 h  V! c  u% t#include <CONIO.H></FONT></P>
$ K( s. m1 f) f# h<P><FONT color=#0000ff>int main(void)
+ V) p& F6 n; ^0 _. o) `' {9 ?{
* f. z# L! T0 y1 J4 m/* request auto detection */
. E4 y  P$ Z; eint gdriver = DETECT, gmode, errorcode;   ]: g1 E# Z0 [2 m! Z
int maxx, maxy;
# A  f! `( h8 W% J1 Qchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>" N. Y0 b9 t' T: `8 J
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" E- J* }# j5 m! K; P3 ~6 R$ Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 Y' X4 s8 L+ n<P><FONT color=#0000ff>/* read result of initialization */
9 }9 F3 C' e# e9 g. ~: E8 |errorcode = graphresult(); ( U8 t+ v0 [) }" j/ R; L
if (errorcode != grOk) /* an error occurred */
) y% a1 E6 \; i4 t3 {) Q{ 2 N0 j3 ?0 g+ q% v0 }
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 Q4 \' |$ V. T6 B4 @# r
printf("Press any key to halt:");
2 O$ X( ]9 P& j+ D$ agetch(); ) `# b0 A! b5 S0 b+ T( T
exit(1); /* terminate with an error code */ . M$ J( V: I8 R& R/ N
} </FONT></P>
; c( O0 ^3 k2 v<P><FONT color=#0000ff>maxx = getmaxx(); - E0 c) `2 Y7 F, ~1 L) s
maxy = getmaxy(); 7 q/ t/ r1 `! g; n" {: K1 d
setcolor(getmaxcolor()); </FONT></P>
; ]' b+ R9 s. P7 Y9 M% D5 l, \<P><FONT color=#0000ff>/* select a user defined fill pattern */ ! b8 k5 C' w- l: U- X  q
setfillpattern(pattern, getmaxcolor()); </FONT></P>
5 G/ |) y/ ]" |+ A: Y% q<P><FONT color=#0000ff>/* fill the screen with the pattern */ + }8 z1 ]! ~( J* Y/ s4 [; F( w+ W3 c
bar(0, 0, maxx, maxy); </FONT></P>" r& @0 R  o. q1 J
<P><FONT color=#0000ff>getch(); </FONT></P>
# ?/ E8 x( @+ g& P, ~0 ]<P><FONT color=#0000ff>/* get the current user defined fill pattern */
' }0 G! _' U" l0 ?1 w( r, G# wgetfillpattern(pattern); </FONT></P>& n0 @  h4 Y( Y' ~! F4 e! I
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
; T& i0 S5 g, ypattern[4] -= 1;
0 F2 {# x$ J) E' apattern[5] -= 3;   Q, N0 B( j7 i$ h0 P
pattern[6] += 3;
, `9 N9 Y7 V- h8 e" U+ ?5 F' {pattern[7] -= 4; </FONT></P>/ t9 v1 T+ ^5 N8 N+ L; y2 `
<P><FONT color=#0000ff>/* select our new pattern */ ) |' t# |2 f: o# o
setfillpattern(pattern, getmaxcolor()); </FONT></P>8 F' r% ?* I3 }3 b8 q$ w
<P><FONT color=#0000ff>/* fill the screen with the new pattern */
1 u4 H, O) ]) X/ a1 @6 A9 Pbar(0, 0, maxx, maxy); </FONT></P>
! r* J0 a4 _  a6 y7 I4 C8 ^8 }<P><FONT color=#0000ff>/* clean up */ 4 X3 g, G9 C1 I' G
getch();
* L5 D$ J% o$ s1 z/ O( @closegraph(); # o, y3 O$ V; |& \
return 0; 8 L  q( N, ^7 r! w# j/ f
}
' y& ]( t1 F+ q' l</FONT>( \5 B. E' o) F6 X. Y
</P>
* E* W7 ?# T' F, u/ W<P><FONT color=#ff0000>函数名: getfillsettings </FONT>' E2 K: }% \6 B! I# ^
功 能: 取得有关当前填充模式和填充颜色的信息 5 x5 E1 S1 i: V, _9 l, u: y; p) g
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
2 ~5 Z: E5 q$ G) p) `程序例: </P>
$ W  r' H0 H. x, h<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ j3 t; R7 ]- F0 G7 f( B* \9 q6 i#include <STDLIB.H>  T4 G7 ~  m/ B8 W/ o. |
#include <STDIO.H>0 `! c4 B0 F5 f- w4 e5 f, G# G! f
#include <CONIO.H></FONT></P>- R& E0 _0 }8 n. }
<P><FONT color=#0000ff>/ the names of the fill styles supported */ % H/ X; w7 x! n, E, g1 w
char *fname[] = { "EMPTY_FILL", 6 S$ P# _& a$ `( g, T! S& q
"SOLID_FILL", 0 H  y6 C* ]- \& E
"LINE_FILL", # k" O+ c# f' B, h$ b9 o
"LTSLASH_FILL", - V& L1 X# I) `8 s, j5 K+ s" J* n
"SLASH_FILL", 7 N6 A3 k% P0 }
"BKSLASH_FILL",
: @1 t- h! G  F. k  i' B% E"LTBKSLASH_FILL", " t" C8 r1 i% g( ?/ m
"HATCH_FILL",
9 o( R. a# w# w5 L) ~"XHATCH_FILL",
9 G. K7 W+ I; p2 Q# o1 Q"INTERLEAVE_FILL", . Y) R5 `  ?! @" {* c4 m
"WIDE_DOT_FILL",
: }& R$ f% t6 M! v7 w" d1 x"CLOSE_DOT_FILL", " _! j. J, `+ f! m) ^( K
"USER_FILL"
, F6 c  [  \4 S9 B}; </FONT></P>( }8 P3 o; c/ z
<P><FONT color=#0000ff>int main(void) " X' G/ H, l4 @
{ + c2 G* L, y8 g1 a* l. k* Q; g
/* request auto detection */ . B4 z8 p" |& ~7 S
int gdriver = DETECT, gmode, errorcode; * Y1 l4 i- T% n0 B& M
struct fillsettingstype fillinfo; 8 \; y: Y6 V# y
int midx, midy;
# x8 ^( k8 E( O# M/ dchar patstr[40], colstr[40]; </FONT></P>
( ~! X1 c: c$ Z  r& M6 N0 X- h+ B0 y<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 Q: p9 F5 C% T- uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 j* X/ b2 r8 R! ?* f- ^" t) T
<P><FONT color=#0000ff>/* read result of initialization */
9 i( I/ L7 a+ d# [8 E' R0 R) terrorcode = graphresult();   E' M* c# Y; a: }
if (errorcode != grOk) /* an error occurred */
4 c# L5 Y8 N0 k' }3 {7 K" {{
, s( N' C' Y6 T8 w5 _! @printf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 Z- ~! s- I/ h, x# u
printf("Press any key to halt:");
2 S3 D1 T  X7 [getch();
" L: D  F1 \4 m, P; a6 Zexit(1); /* terminate with an error code */
! p. W8 S$ u4 s# ?: \} </FONT></P>
8 C# j  i+ N3 n8 p+ U<P><FONT color=#0000ff>midx = getmaxx() / 2;
, Z0 H# |& s! f3 h% Q6 O4 _8 E  emidy = getmaxy() / 2; </FONT></P>4 _4 x2 O& G% X9 R# J$ P
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ 1 N% s7 C* F% Q$ \: K. l/ P. ~" P
getfillsettings(&amp;fillinfo); </FONT></P>
; f0 z5 Y5 q$ m<P><FONT color=#0000ff>/* convert fill information into strings */
  S  w+ W* ?( N) u' o% Bsprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
8 ?% S. X$ Y( ^7 }: Dsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>  j! R9 {* }- E+ H4 H
<P><FONT color=#0000ff>/* display the information */
# K1 n/ Y7 D/ Z" m1 tsettextjustify(CENTER_TEXT, CENTER_TEXT);
+ D5 V+ _' A/ W5 aouttextxy(midx, midy, patstr); 5 K6 w8 F* h" K6 \
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>1 a4 t( f; d! a  n& k, e0 W$ n
<P><FONT color=#0000ff>/* clean up */ * g6 M/ v2 v2 G( v0 ^' L! A4 b. ~
getch(); % u* ]- l1 t5 A5 G
closegraph(); ( J, r: Q" F( e$ a4 W1 M
return 0;
0 |1 P# P5 w# f* V5 p; e; z0 X' Q}
2 r4 y4 |# n6 P$ O" X/ v) o! i% [</FONT>- a6 W0 k; E7 V( r" D1 _! }5 u7 w) J
* U" Q0 }# W) R1 I) _9 @: Z
</P>
' {4 Z# h4 {. R3 P* N' K4 D<P><FONT color=#ff0000>函数名: getftime </FONT>! I- c# A4 ]  i, Q- v  V, E
功 能: 取文件日期和时间
: R$ E# f" q) W用 法: int getftime(int handle, struct ftime *ftimep); 8 h4 R  a& f; v. z3 s
程序例: </P>, v/ x3 ?+ C0 y7 }! U% C7 _
<P><FONT color=#0000ff>#include <STDIO.H>
0 n) v0 l1 F" }4 L) q. h. d6 ^, Z2 S#include <IO.H></FONT></P>  J5 L; B4 P7 ~5 P0 ]
<P><FONT color=#0000ff>int main(void)
8 s( k3 I, \# F4 y# j. h6 r" j4 K{   b% E" r. d& f
FILE *stream;
( R# H; Z# p( h9 @struct ftime ft; </FONT></P>9 A: a$ I8 u6 V* k$ @
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", & P& U6 }/ Q7 o
"wt")) == NULL)
6 E' N8 C1 C5 N' J{
! B/ a6 f0 d$ b; e" x# V1 Afprintf(stderr, : i) P4 @+ ?3 b7 ~4 y2 l0 t( a
"Cannot open output file.\n"); 5 z+ h7 T; D; a7 C3 _" I
return 1;
( K* c$ [0 b0 @' T4 K+ d}
" T7 x! B& p) E( \+ kgetftime(fileno(stream), &amp;ft); 5 c$ F$ x& F- n9 @$ f5 F
printf("File time: %u:%u:%u\n",
* y/ q3 J8 [2 f9 X0 P( fft.ft_hour, ft.ft_min,
  y$ ?5 P6 D$ y3 ?ft.ft_tsec * 2); $ ]7 b+ K# w, z8 u; G; l8 _
printf("File date: %u/%u/%u\n",
) }, y. {0 v/ f* z8 N2 Cft.ft_month, ft.ft_day, 9 E" z0 A, V# s3 c0 r
ft.ft_year+1980);
) ?% y- {) L- `- k# K$ @fclose(stream);
5 u8 E, h% ]* a1 R7 }5 ~return 0;
9 K* ]+ U7 q0 R9 s9 a} 2 ?- {/ x8 Z( p1 K8 t! q% G! R
</FONT>5 @9 P3 D: ^9 u5 k0 C1 T

6 o) V7 r9 f1 e% H& I* ^. s) `</P>9 R- [# L# T. w. N
<P><FONT color=#ff0000>函数名: getgraphmode </FONT># W  ~+ E; G; s2 I
功 能: 返回当前图形模式
$ ~% W! e7 @4 Z) F9 R/ z用 法: int far getgraphmode(void);
- j3 i; y' L3 Z! T程序例: </P>0 }! f% y" [# W; }0 X: k+ o
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( Z4 I+ e0 w) u! V( i5 M' D8 p#include <STDLIB.H>) `2 G7 f5 B2 s9 v: Q/ }" ?1 K
#include <STDIO.H>
5 W" f) E" K2 ^& o+ }#include <CONIO.H></FONT></P>
7 Y7 A. N+ G3 ?! ~! v' Q% f<P><FONT color=#0000ff>int main(void) ! O6 [$ c8 V5 n
{
3 D# n: s& H+ X: P, _$ ~/* request auto detection */
7 J) a1 h) L! s3 n( Pint gdriver = DETECT, gmode, errorcode; 4 [- P( n$ S( O
int midx, midy, mode; ' @& }# V7 v8 u
char numname[80], modename[80]; </FONT></P>
, ^/ W1 w( p5 K4 t6 c( \- c! P<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ Q. i. k; ~  i# ]5 X& [
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ D; o; \0 v# O5 b0 T<P><FONT color=#0000ff>/* read result of initialization */
# x% |% H* w4 x) |9 ?7 l5 _errorcode = graphresult();
, `3 H% i/ j. L; t' Y/* an error occurred */
) v: A% ?6 a. X& k( b+ l- m3 M! {4 Qif (errorcode != grOk) 2 K3 ^' @. g; w
{
( F5 o4 S8 x, s, kprintf("Graphics error: %s\n", 4 S4 V% e5 g8 ^0 p
grapherrormsg(errorcode));
8 a- H- r7 c% m- `; [# O5 V+ iprintf("Press any key to halt:");
9 X& H% E' d$ b, A+ D% Kgetch();
4 }0 o" a& x4 U+ R4 t6 H+ L/* terminate with an error code */
" V7 D+ |0 j; D* |7 w' Aexit(1); 3 _0 p4 i+ f9 Y$ Q& ~7 P6 s
} </FONT></P>
3 E# Q% J  S3 M0 v$ o$ N/ M% c# u8 o<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 E# v5 C; x8 F/ U2 Qmidy = getmaxy() / 2; </FONT></P>" z3 D+ z) s1 H* q4 p6 T5 @! m
<P><FONT color=#0000ff>/* get mode number and name strings */ % m7 a2 e! b3 T
mode = getgraphmode();
& ]  }7 t4 s3 ]$ W! W9 w! vsprintf(numname, ; i+ I+ z; o5 |/ b- H2 i
"%d is the current mode number.", & _, e: i# |+ N; S5 C: K/ D
mode);
* N: A" A0 n; k/ Y+ J: Vsprintf(modename, " F+ _* V* Y% Z& E2 x; `- x% Y
"%s is the current graphics mode", $ U  Y. i8 f, e  \4 }; a
getmodename(mode)); </FONT></P>
* r1 z9 S9 d8 w- M, f, J. |<P><FONT color=#0000ff>/* display the information */ & V: V6 V; {( c
settextjustify(CENTER_TEXT, CENTER_TEXT);
5 Q6 }- J. @- d4 H$ O% eouttextxy(midx, midy, numname); . G! b' E' K4 \7 R5 e! l0 G
outtextxy(midx, midy+2*textheight("W"), 0 {  W$ Y* c: S  h6 _
modename); </FONT></P>) u1 X+ _& u" M& C
<P><FONT color=#0000ff>/* clean up */
' Y. f; ?+ d' [1 \getch(); % c2 r. m7 {. O4 o- j
closegraph(); ( \" S/ e' O( `& p6 }: O
return 0;
% ]* K3 e! V3 j. p0 G} </FONT>
% X( q0 H7 a4 X6 g% q: J5 k8 P' S
' ]5 s7 F6 i( @( d: o8 }4 G" ?</P>
1 Z/ x* v( }8 F' V( Z& e. r<P><FONT color=#ff0000>函数名: getftime </FONT>7 q& n$ _% x& Z6 d5 ^$ [9 ?
功 能: 取文件日期和时间 8 T$ s8 B( j- j- x- r4 }+ t* v5 y
用 法: int getftime(int handle, struct ftime *ftimep);
& U8 W" M  k# h& B1 [1 t1 ~1 I/ ?程序例: </P>% T) T- z. |, d, X
<P><FONT color=#0000ff>#include <STDIO.H>1 n. k1 L  G9 x& O1 p$ u9 Y
#include <IO.H></FONT></P>% d) j8 i4 ]4 l/ q9 N
<P><FONT color=#0000ff>int main(void) 3 m9 S: q3 ^2 O
{ $ R5 p5 u- z) p% k9 q1 Q) R
FILE *stream; , b) C2 ]+ z5 f0 A
struct ftime ft; </FONT></P>2 H( Z$ c" }: d" U4 ]1 k9 Q+ }
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 4 k. A. Z) @$ C! P
"wt")) == NULL)
5 P0 H4 ?" s; C( p! w  U1 f1 _{
/ R2 |$ y6 \+ P% jfprintf(stderr,
! K$ i* C9 d# O3 V. L"Cannot open output file.\n");
+ K1 d1 k& X/ _9 q, }return 1;
5 g7 z& x( ^  j}
$ }9 j+ x- F# Pgetftime(fileno(stream), &amp;ft); 7 Y7 n; o$ F# e
printf("File time: %u:%u:%u\n",
( N* h5 J) n2 r4 U6 b8 W1 eft.ft_hour, ft.ft_min,
+ ]% R1 W. A& c' _- N* P. w" Jft.ft_tsec * 2);
5 e. b+ y: z- g/ ~8 l: [: @, s6 Dprintf("File date: %u/%u/%u\n",
* Z* `" I4 w. z, uft.ft_month, ft.ft_day, . G1 p* m# R1 B7 ^; r" F3 T. t2 M
ft.ft_year+1980); 1 ~1 _( [+ V& j7 S' K
fclose(stream);
5 \6 S7 x+ ~: h1 e$ sreturn 0; 3 Y% R4 f: C; H. L' N$ G! B2 ]# W
} </FONT>
8 \' K' r$ l8 S  \3 b& o. T
2 N% Q6 R, Q( l9 ~$ i; Z; @- `+ [# L) b5 F, ~8 U7 j1 ?
</P>( X; h6 E# [4 K+ \& q; q
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
  ^) b# M$ _) f0 @5 i( W功 能: 返回当前图形模式
& @7 g- B5 j7 _* p  e用 法: int far getgraphmode(void);
0 @5 M  R7 c8 B  C4 d- p! r* U程序例: </P>
, @, i) \8 I8 ?<P><FONT color=#0000ff>#include <GRAPHICS.H>
& m0 X0 s# |* I% @0 E#include <STDLIB.H>9 y" k) a4 `; q$ D" h
#include <STDIO.H>
7 I  K5 r! C1 H% q#include <CONIO.H></FONT></P>
& p3 ]$ I6 A! s$ |1 y* G+ k<P><FONT color=#0000ff>int main(void)
2 Q- a" u* o  l$ Q% K+ }{ % F/ l" v1 ^" ^. d7 F
/* request auto detection */
/ P. P2 ?# B0 M) X# h' H4 a7 I0 tint gdriver = DETECT, gmode, errorcode; , u2 B. q3 k+ C
int midx, midy, mode; 5 c8 m0 k6 X0 m! d& X' G
char numname[80], modename[80]; </FONT></P>
$ L7 r/ c# y5 i: H( _2 Q! G% Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
; U+ Q% p7 K% Q: h$ V. Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 V0 S; i8 J$ D5 W$ @. C5 {
<P><FONT color=#0000ff>/* read result of initialization */ $ @# O- \. |$ ?* k
errorcode = graphresult();
. x1 \# _0 c: w6 t8 V& p7 A/* an error occurred */ 5 Z" T6 A" d% @' [& f
if (errorcode != grOk)
9 _; F" j6 e' M1 u$ y$ Q{ ! j( {& Z1 N. g8 \1 {
printf("Graphics error: %s\n",
- q  S+ ?7 f& v- s& [* N% ?grapherrormsg(errorcode));   N; G( ?7 K' E5 y9 F
printf("Press any key to halt:"); & o/ v# t. @! g+ i0 l
getch(); ' y* k2 @7 Z4 U5 v4 m; A2 w" W
/* terminate with an error code */
6 X, t4 t6 z2 e1 U7 v( Kexit(1); + U' o& \% N; r, O; r' |: A, R
} </FONT></P>
& X# ~& {& Y6 D; G5 O<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 V, K/ m0 W9 ?! u4 c* amidy = getmaxy() / 2; </FONT></P>
5 c; q6 a. l, u8 x7 |- j# n<P><FONT color=#0000ff>/* get mode number and name strings */   {7 _$ I1 j  n- M4 F; P
mode = getgraphmode();
1 m3 [. a- C2 L4 T. o% E( u3 a: p! bsprintf(numname, % l. [% q; }7 I' q7 c) J$ B
"%d is the current mode number.",
3 C( m" _6 W1 t0 wmode); , I" [  [1 n8 y; J* [3 X& X
sprintf(modename, 2 _* g. J8 ~0 U, o! e. E
"%s is the current graphics mode", 2 k% m" x& S! u2 p9 {6 G
getmodename(mode)); </FONT></P>
/ [' i# S: x9 L; f" f: w' @<P><FONT color=#0000ff>/* display the information */
; K1 T5 J- `, l; s! l$ y) y$ xsettextjustify(CENTER_TEXT, CENTER_TEXT); 3 X3 Q7 P" d* W' v  ?+ m3 d
outtextxy(midx, midy, numname); $ h; Z- {7 q% }. E- G
outtextxy(midx, midy+2*textheight("W"),
+ f/ |, o" `6 t! gmodename); </FONT></P>1 {$ e6 L# a1 N0 |$ _" Y
<P><FONT color=#0000ff>/* clean up */ 6 _& i) |6 p, T' g
getch();
( }- k8 a; ]! d  {# a; P% xclosegraph();
* j9 n" f1 ~7 k# c9 [8 Treturn 0; ! `. _) Q+ s' I  ]
} 7 Y' I; S: m! h: [6 p- T" t
</FONT>
  `2 l+ |. f& q4 _0 j* k</P>5 ]4 |8 ^# A4 G) i, X
<P><FONT color=#ff0000>函数名: getimage </FONT>1 Z4 G! L3 ]6 \( b
功 能: 将指定区域的一个位图存到主存中 0 H5 q0 Q% W8 ]$ @; D/ A/ u
用 法: void far getimage(int left, int top, int right, int bottom, 1 G( ^3 O6 Q* r8 D$ t% s
void far *bitmap);
; E( X. B' ]4 ]$ S程序例: </P># d5 o/ N, |. d2 P1 |" i' S
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  q8 y( Z  y6 u. q- I+ c#include <STDLIB.H>
3 Y3 X. l- x  |8 ~. o7 |/ D0 Y* n#include <STDIO.H>
$ D* n2 @( \3 o2 \0 j4 w#include <CONIO.H>
: n9 v4 [: x7 b! _# A$ J8 r4 U9 L" ^#include <ALLOC.H></FONT></P>0 y4 m6 p3 \$ Z2 A5 m* _; ^
<P><FONT color=#0000ff>void save_screen(void far *buf[4]); " k! O& H9 I8 d3 T6 S, |
void restore_screen(void far *buf[4]); </FONT></P>
4 k3 S. q% D% l<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>! r4 S, H7 q/ b, W4 a
<P><FONT color=#0000ff>int main(void)
$ g+ {1 {7 Q, p  t{ ' G, \: w" t  k5 n' D$ `- |
int gdriver=DETECT, gmode, errorcode;
1 Q, H* j3 b+ e$ Q4 yvoid far *ptr[4]; </FONT></P>
5 ]& F5 F( T6 V* z1 f<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ 9 _) m1 I+ k8 {/ T2 }5 m6 X
initgraph(&amp;gdriver, &amp;gmode, "");   `! H, }  P1 u$ Z8 t: K
errorcode = graphresult(); /* check for any errors */
$ s" z7 s6 ]0 B3 [0 e/ {/ Cif (errorcode != grOk) ! w+ i1 l% S; U8 W$ f
{ # w& J  R* k1 S* O
printf("Graphics error: %s\n", grapherrormsg(errorcode));
. Z$ ]! J$ x4 Y: h( e! C- {printf("Press any key to halt:"); - s6 o. C0 A( \7 b  I
getch();
% j" R6 Y* B3 r0 G, U0 D$ sexit(1);
  V8 p6 V# F4 H% B1 E/ q8 \/ |4 [}
0 [" _" |: a2 s# T% t' u. Cmaxx = getmaxx();
# a: r+ {: h. ^maxy = getmaxy(); </FONT></P>0 E( d3 n3 F  X6 G
<P><FONT color=#0000ff>/* draw an image on the screen */
4 P  J- ^* \5 B/ v1 Mrectangle(0, 0, maxx, maxy); 3 R4 H& T  [- a3 W
line(0, 0, maxx, maxy); 3 k- @# ~' O( ?+ R. M( y. _
line(0, maxy, maxx, 0); </FONT></P>6 k2 Q* Z' x5 B3 k% A4 E
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ 1 y0 U, Y# ^, f6 o# Z# c$ A
getch(); /* pause screen */ - H' L9 L4 X# ^0 g* a
cleardevice(); /* clear screen */
3 I8 O- V+ S/ A) q! mrestore_screen(ptr); /* restore the screen */ 0 |5 M) O. ~) f& ^' V0 q
getch(); /* pause screen */ </FONT></P>
6 P# x( v; T4 k- l. ~<P><FONT color=#0000ff>closegraph(); ! ?/ T5 M; T. U2 F! L& Q' o
return 0;
2 j- j) S3 B$ A! ?0 ]} </FONT></P>
9 P/ [" V" Y: C4 ~<P><FONT color=#0000ff>void save_screen(void far *buf[4]) % s% J, G% k! l
{ 7 [5 C* ]  T( ^
unsigned size;
& n! ]# S5 R5 `( j( w1 I9 b# w% Pint ystart=0, yend, yincr, block; </FONT></P>! Q- J- n. |, x# e) ?+ p) [. k
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
- r  ^' d& r0 A! z  Ryend = yincr; 2 r! h* M- b9 K6 `% ^! Z- \2 z, P) ]0 p
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>; N- X6 B$ M' A! }, L
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) 9 z4 g: q- d! k/ E+ Z
{
. M1 m) r( S: C* Y* U  k) Sif ((buf[block] = farmalloc(size)) == NULL) $ K, C9 v" `- @& {. Z
{
9 P. T0 x, E! M& |$ Zclosegraph(); 3 l# A! [& C8 e! U
printf("Error: not enough heap space in save_screen().\n"); $ E2 n" E" O2 f
exit(1); . r! V. L; N5 Z- K$ f* K5 c& S
} </FONT></P>
- ~- j0 O8 n' }6 @& i1 S7 y3 ^<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
9 `3 U) Z+ a' u' f8 K. `ystart = yend + 1;
( Z0 Q% M# i+ ?3 u* l! cyend += yincr + 1;
$ `, J% Y# L9 u- J2 V: _} ; C3 g0 N- u4 @+ u
} </FONT></P>
* D3 F4 [2 f2 f$ e% J9 l% I<P><FONT color=#0000ff>void save_screen(void far *buf[4])
# z7 j1 n0 j* U{ 7 {8 f% C9 k. ]% E  M. i% K
unsigned size;
) s  O% Z0 B* q+ i0 A# y' Iint ystart=0, yend, yincr, block; </FONT></P>0 @' G. f( S$ \& r0 H0 P# w! Q
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 3 w& I4 B6 H5 n5 }- o7 |
yend = yincr; ! J6 E/ g* l" D0 n  y* s
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>* d( U) Q0 y: u2 W9 Q7 c+ F& m
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
. q3 ]" E. y5 P% g4 j* W{ 1 N  P9 [( b- |' H9 }
if ((buf[block] = farmalloc(size)) == NULL)
% G$ S& C# f! c) L4 ]; q& V; `' M. V{ 6 K% ?. e# w6 W% v* g6 |* H, G
closegraph();
+ h7 _5 {! P: P( Rprintf("Error: not enough heap space in save_screen().\n");
' e, _2 ]6 ?) F' R! k  B/ ^exit(1);
- i' j! D! [! W3 h* K} </FONT></P>$ u3 e  \9 b8 z# r
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
- Y- l- a6 r/ N3 g: S6 _! t/ Aystart = yend + 1;
% v5 C  z4 f4 A' q6 C4 Byend += yincr + 1;
/ f  V+ Z' E6 X7 L} 4 O% ~0 _$ j+ W4 Z, {* `4 k4 d
} </FONT></P>
/ g7 C& Q2 |  Z$ e<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) " ]. M8 w& H  B
{
( p0 `8 p; B$ N4 x. Jint ystart=0, yend, yincr, block; </FONT></P>0 \; U) [# i( g9 ~3 g, g
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 8 z) A% Y9 j1 _* P* p( V
yend = yincr; </FONT></P>3 B. J  H: e2 o9 N8 T6 k
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
8 b9 W% z# O) \, v+ c{
( \4 C5 c. Z0 q: n% `# Vputimage(0, ystart, buf[block], COPY_PUT); / ^2 X, ?1 N( z
farfree(buf[block]);
5 x0 f2 r  B6 v7 _- ~3 e0 g; E4 lystart = yend + 1;
/ f. l, d3 ~2 [9 F; {$ @yend += yincr + 1; + n8 n% E6 x8 y2 X& N: B8 [' F/ `+ d
} ( y, f; C. |% j0 O" l
} </FONT>' g- X0 |2 _, c5 ?- J
<FONT color=#ff0000>, K+ c& {% ^7 I: N4 J; ~. Y8 @
</FONT></P>
5 z  L; Q9 W& Z  |+ G2 U<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
& Z6 k8 o$ H6 W1 B) D* O$ C9 U功 能: 取当前线型、模式和宽度 " L/ T  e6 [$ G4 Q* G3 f/ ]
用 法: void far getlinesettings(struct linesettingstype far *lininfo): 4 `8 \9 K$ J6 `+ V) Q) w
程序例: </P>
- m, I1 g4 R1 X3 {9 o3 i<P><FONT color=#0000ff>#include <GRAPHICS.H>; h( o; M1 ?5 m6 U: ^! \: P
#include <STDLIB.H>
! U# V/ M" p9 u) C2 |' p/ F2 K#include <STDIO.H>) D) C8 J' V/ J( K/ q% X" u
#include <CONIO.H></FONT></P>
9 }$ s$ ?$ E. {<P><FONT color=#0000ff>/* the names of the line styles supported */ 7 [6 Y) m0 D: J  H" s
char *lname[] = { "SOLID_LINE", ' J& {  t2 j$ W; t; n" w, b" N. A
"DOTTED_LINE",
# K  Y0 y: s) ^% h3 E"CENTER_LINE",
& d: V$ ?( J" \8 f"DASHED_LINE", / k, V5 {2 @. W  C  K
"USERBIT_LINE"
/ S  n2 ^5 h* p; [+ j% a4 }" B}; </FONT></P>' S* ^9 R1 I' Z9 g' H
<P><FONT color=#0000ff>int main(void) 3 V: j3 W2 Q8 s
{
& T7 R! P! w  b/* request auto detection */
) X4 P& {9 Z: l/ r0 |( Y  w; |int gdriver = DETECT, gmode, errorcode;
3 g6 v- n0 v% ^  @9 U1 }struct linesettingstype lineinfo;
: _3 C+ i( ^9 x) J: i* Sint midx, midy;
6 N7 z2 T- w8 ?1 Rchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
5 x/ l- h0 k$ P) p/ f% R6 ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
- Y* B0 f" z7 c' Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" P8 x7 D. T3 N) r" ]<P><FONT color=#0000ff>/* read result of initialization */
' e+ e( _8 c- oerrorcode = graphresult();
9 g2 H. D" _: P8 Yif (errorcode != grOk) /* an error occurred */
# Z$ x5 K) j6 v! C  n{
9 n+ w# a7 n  |printf("Graphics error: %s\n", grapherrormsg(errorcode)); % b" ]- C# M) [2 Q! m
printf("Press any key to halt:");
& u6 ?8 v  P$ x3 o- U) g" Sgetch();
! n& M; k2 y/ x$ `, ^' ]exit(1); /* terminate with an error code */
/ E; v& ]$ Q) q  J/ W. U' R. W8 R} </FONT></P>
5 h! z1 I# o% y0 K) R<P><FONT color=#0000ff>midx = getmaxx() / 2;
. h  r5 v  Y% H9 n; @0 amidy = getmaxy() / 2; </FONT></P>" l* O, K' @; Y1 ^( D" r( i
<P><FONT color=#0000ff>/* get information about current line settings */ 5 @1 {* X# b3 T$ p
getlinesettings(&amp;lineinfo); </FONT></P>
. \5 v9 h0 s0 \. L  [<P><FONT color=#0000ff>/* convert line information into strings */ % F( x0 b* ^. a( Y# x1 ^
sprintf(lstyle, "%s is the line style.", % Q  j3 e3 D  y- N$ e1 t5 Q$ t3 t
lname[lineinfo.linestyle]);
% |" [( I$ \3 D" l; Msprintf(lpattern, "0x%X is the user-defined line pattern.", 5 l, [2 H. X2 U" z: j9 U
lineinfo.upattern); + L( r/ l. ]  J% f8 y0 a) k  k
sprintf(lwidth, "%d is the line thickness.",
1 S+ E8 v9 `8 G5 d# Ulineinfo.thickness); </FONT></P>
+ \5 Q( w& ^3 Q: b2 o<P><FONT color=#0000ff>/* display the information */ 9 m$ i( C' W, ?  B; n
settextjustify(CENTER_TEXT, CENTER_TEXT);
. B3 N( L. J$ E) Iouttextxy(midx, midy, lstyle); + @& W: Q) `' b3 P
outtextxy(midx, midy+2*textheight("W"), lpattern); 4 c0 L+ w5 ~) G3 W" ^2 M
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
6 \5 y2 k! f) w7 {& I* p" v. u<P><FONT color=#0000ff>/* clean up */ # c: {. s0 u5 V% j5 q# M
getch(); 1 M- k! S. R$ T) Q+ h3 M# Q
closegraph();
- k; w! E; b2 B1 K- z. Z$ ureturn 0; - x5 c9 D6 W7 x# _3 k9 W6 W
} </FONT>
# J% H. c( u7 Y/ m: H! |! d# C' G' D
</P>
0 X/ H8 o" }; }/ c7 t# B+ K$ Z9 G<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>' f. z6 A0 d4 G7 d
功 能: 返回可以传给函数setcolor的最大颜色值 0 \0 n# d7 H! u3 @- M
用 法: int far getmaxcolor(void); ! P; d$ F- y$ b
程序例: </P>
7 B# i  C+ ]/ x! g( p<P><FONT color=#0000ff>#include <GRAPHICS.H>
' p3 K' a4 |; j#include <STDLIB.H>) `7 T# Q1 N8 C- [8 A1 k4 n
#include <STDIO.H>
5 j9 k4 M3 w: h9 W% D#include <CONIO.H></FONT></P>0 q. E+ v& s* p) `. M
<P><FONT color=#0000ff>int main(void)
& U7 o9 g4 H6 y7 C{
6 t+ n0 F7 O: j4 ]1 l4 a; u% C/* request auto detection */
+ K0 S/ f0 G* j& }& uint gdriver = DETECT, gmode, errorcode;
) H5 m, r- U! hint midx, midy; 8 X" D, @- c3 m" {" Y& W5 l% J
char colstr[80]; </FONT></P>9 D* T  ~6 N0 r3 n4 o
<P><FONT color=#0000ff>/* initialize graphics and local variables
' S# L. Y5 b7 s" Y% J/ a! p*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, O: X. ?# v  ?( j, r5 L: _<P><FONT color=#0000ff>/* read result of initialization */ # x- Y  ?2 [7 T) ^- G
errorcode = graphresult();
- d; R/ o4 J2 t/ J8 Sif (errorcode != grOk) /* an error occurred */
- N- U6 L. y+ [/ f! [$ a! v1 M- i{
- ?, z4 @. Y0 Oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
5 P1 K1 q# x3 d6 ~printf("Press any key to halt:"); , e0 o: U0 U; J/ t, X
getch();
0 r2 Q: z& W3 ~3 r" F% X+ O4 r0 y5 iexit(1); /* terminate with an error code */ ) |( T, _8 [$ c. t9 I
} </FONT></P>
5 @3 @5 K! J% G  v: C4 I' u* V<P><FONT color=#0000ff>midx = getmaxx() / 2;
" e- v% A( y( C- tmidy = getmaxy() / 2; </FONT></P>2 F: j* _# c0 b( O( f8 u. I! R
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
; Y+ `! X' I& F; y9 y! Bsprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
0 V2 C' Z4 }/ |6 ~- i. F<P><FONT color=#0000ff>/* display the information */ ( ]) j. W% ]2 O( {' U6 S; W
settextjustify(CENTER_TEXT, CENTER_TEXT); * z$ \9 p5 a) A( ~$ O" `: S% b
outtextxy(midx, midy, colstr); </FONT></P>* m' W9 T* L0 n
<P><FONT color=#0000ff>/* clean up */
( I: P$ Z/ p9 U2 Z: Y- Ugetch();   f: Q  O0 s- k7 j
closegraph(); * [& h, L) B2 w; }3 [
return 0; ' I% D* O$ G+ f2 K4 k( s7 V. r
} </FONT>+ n3 s! S# b* L2 i* d, p. Z+ j! Y; s
/ z% C- S7 P2 ]2 ]4 p  B8 x

5 q& Q5 M) z4 N( D$ H. q8 g</P>
0 f  ^. C  i* _* E. i<P><FONT color=#ff0000>函数名: getmaxx </FONT>
9 P4 v" t7 i1 |  s0 S功 能: 返回屏幕的最大x坐标
9 c% _# ?9 ?- u7 |. d) I+ m用 法: int far getmaxx(void);
. L% E9 D- {* E; Z; K# v程序例: </P>; Y' z# I; A/ r1 x* L- S: T
<P><FONT color=#0000ff>#include <GRAPHICS.H>2 l& N: M- x! i. i
#include <STDLIB.H>
2 L; \, B" K8 c' x/ g#include <STDIO.H>! b, }' h- g4 d' Y
#include <CONIO.H></FONT></P>
' E! J0 x! a9 w) Q<P><FONT color=#0000ff>int main(void) 9 K8 Q6 E# g& u+ L- f& W* _
{ 7 O, a9 o. d  _" F: v3 b7 l( Y' I4 z
/* request auto detection */ # D6 P% ^9 H' v& e4 O  b
int gdriver = DETECT, gmode, errorcode;
3 S5 e, X8 n- O# Cint midx, midy;
8 t* u- H/ O2 Y  @8 mchar xrange[80], yrange[80]; </FONT></P>
3 C8 Y% q/ w. `8 N9 F- H+ J<P><FONT color=#0000ff>/* initialize graphics and local variables */ " ^+ w; H# I! V* ^6 o/ p$ I& }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) Y( s# o$ @& f" g' K4 ?, S& K<P><FONT color=#0000ff>/* read result of initialization */
2 y( W% ^# k) Qerrorcode = graphresult(); % b8 e2 s" ]$ G3 l# O. N1 h! G
if (errorcode != grOk) /* an error occurred */
* o2 _4 s" @# U& g{ 2 h- B2 P# h6 O" `
printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 t( U$ ?& W- tprintf("Press any key to halt:");
" t$ p  W  |+ a9 \getch();
" J, r6 c& X/ K& N2 w  rexit(1); /* terminate with an error code */
9 i$ \' H5 Q( i5 a8 Q. O$ }} </FONT></P>
5 |1 p1 f* u' z4 ]. ]<P><FONT color=#0000ff>midx = getmaxx() / 2; ) m: g# {9 a4 ?- y/ n( ?
midy = getmaxy() / 2; </FONT></P>( f) |1 m  f" a, z" ^2 Z. q1 G5 S  E
<P><FONT color=#0000ff>/* convert max resolution values into strings */
4 R  k6 n1 S; w" H0 k. N/ \9 [sprintf(xrange, "X values range from 0..%d", getmaxx()); 2 N6 H7 H  n4 Z% D% Y5 Q# p  a
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
9 A8 d: ]9 O4 E1 ~<P><FONT color=#0000ff>/* display the information */ 4 d4 A5 F# {( q
settextjustify(CENTER_TEXT, CENTER_TEXT);
' N8 U7 a, s/ C% R' W$ k; oouttextxy(midx, midy, xrange);
* x& S9 P4 f& K5 D. ^1 iouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
4 s$ O/ F' _, l: E4 a# W<P><FONT color=#0000ff>/* clean up */ $ U3 \6 T. w; e" C5 x
getch(); 5 |; L2 K' W6 `8 b+ ]4 F6 _6 N
closegraph();
5 a: c! x, f5 c. Qreturn 0;
9 l/ R  Y6 ~1 L* \}</FONT>
: [0 r% \6 X$ G$ @+ A% K1 ~/ d. l/ ?) h8 Y4 ^
</P>! h$ i8 J( T: j- V- c  I, R! t9 q
<P><FONT color=#ff0000>函数名: getmaxy </FONT>/ m" z$ a8 ?+ N% V
功 能: 返回屏幕的最大y坐标 , J1 d* ~5 w4 c7 g
用 法: int far getmaxy(void);
% K5 k% Y4 V* b" S% M# m3 l程序例: </P>
1 O' O; r# O. I4 M<P><FONT color=#0000ff>#include <GRAPHICS.H>: E! L' X4 ?# f* [' v3 Z
#include <STDLIB.H>
2 {: E6 M! T4 X. `3 X- m#include <STDIO.H>
1 V9 y4 Y2 D' \( M2 Y#include <CONIO.H></FONT></P>
6 T8 C" ?- x" V' X' v. X. _<P><FONT color=#0000ff>int main(void)
5 H% y# r& H8 ]3 z# x{
7 F/ j/ a: I" {% s3 Z- j: c/* request auto detection */
; c5 ]5 {/ Y$ e# h$ d9 d( F6 z) x2 hint gdriver = DETECT, gmode, errorcode;
: Q) `( O0 O4 z8 J7 L0 W/ j( q2 oint midx, midy;
$ x4 P. r2 {5 [6 a2 ?$ M' Zchar xrange[80], yrange[80]; </FONT></P>
5 C. O$ {9 f- C) q. ]7 f% a<P><FONT color=#0000ff>/* initialize graphics and local variables */
- ^5 w* z/ H+ D, ]: V% }initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  |5 d1 v- Z, C5 G9 R<P><FONT color=#0000ff>/* read result of initialization */
9 h/ w8 g& |" Y/ K1 k+ p6 aerrorcode = graphresult();
5 ]& b  D6 b5 a  \/ Jif (errorcode != grOk) /* an error occurred */
" E$ j3 X: M; f1 v% C{
; x8 t% n1 c' D0 I) fprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 x6 q: C" u3 F8 i7 Fprintf("Press any key to halt:");
: [5 o. M) y  o7 `getch(); % q4 C6 j" O, |. U4 T
exit(1); /* terminate with an error code */ 1 o( |( I" \5 m6 n8 c
} </FONT></P>
- f; z. Z! u) d2 e# d' u3 @<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 a; p/ p, u; I# B7 c1 ^& I& L
midy = getmaxy() / 2; </FONT></P>$ Q$ P/ G0 m' A# D
<P><FONT color=#0000ff>/* convert max resolution values into strings */ 9 e' d3 \- V) B
sprintf(xrange, "X values range from 0..%d", getmaxx()); . A- K- h5 Y0 C
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
" a8 K% o! P- m+ q7 W' g<P><FONT color=#0000ff>/* display the information */
% l$ v) ]% E( Vsettextjustify(CENTER_TEXT, CENTER_TEXT); 9 ?) n" C2 S2 U, X0 B1 W
outtextxy(midx, midy, xrange);
) G; J5 F# }2 g# r; [% aouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
% c" h0 L3 w" C% y# J<P><FONT color=#0000ff>/* clean up */ ! {% B! M: G: H& U5 }5 ^
getch();
9 p4 }4 A8 P% O, E' i7 Qclosegraph(); ) ]8 L8 Q6 g8 k, x' n4 \; r6 B
return 0;
3 }- T* T/ h; l0 o% n} </FONT>
' e; \4 u7 v' G2 o</P>) B+ e: w( R- r; m" L, i
<P><FONT color=#ff0000>函数名: getmodename </FONT>0 D$ W# }5 m& S: }; }+ \- r0 S
功 能: 返回含有指定图形模式名的字符串指针 # p: X) j: h8 L' a
用 法: char *far getmodename(int mode_name);
* c/ P) ^# O! }' }4 v8 W程序例: </P>$ {; g; Q  R% q( L4 a4 b* n
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 X4 t! f$ Z! ]# _- a$ {#include <STDLIB.H>
6 Z1 B$ z7 q8 D#include <STDIO.H>5 s* m* Q# B) n# q; l
#include <CONIO.H></FONT></P>2 M! J, H4 M- ?4 w9 Z# C
<P><FONT color=#0000ff>int main(void) % Z1 h3 @) o/ F$ X$ P+ X6 D- |
{ % g6 Q7 E+ g6 }2 Q& T+ ~
/* request autodetection */
# A& ^1 M" |7 @$ y  I% ]int gdriver = DETECT, gmode, errorcode; 5 i$ t& h* W0 l" v
int midx, midy, mode;
/ H6 d, H8 }6 Achar numname[80], modename[80]; </FONT></P>. j) K8 e3 u! ^) i4 V% J
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 e& T3 Z9 T4 u! i
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" C- }3 K) b" _: ~0 d, t<P><FONT color=#0000ff>/* read result of initialization */ , C% Q" G2 }) m- ~' e2 N
errorcode = graphresult();
" `" ^- z- d+ lif (errorcode != grOk) /* an error occurred */
6 G1 q/ B( I- X+ _4 q3 b{   ^' Y0 F5 T9 }
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' \2 g5 i# z/ M- D, a; T
printf("Press any key to halt:");
! G. ~3 t: s# [4 j9 {getch();
/ U/ @  O% w) b8 ^$ ^/ }& cexit(1); /* terminate with an error code */
+ F$ |, u  @; f} </FONT></P>/ Q# c7 p! t0 b  x
<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 ?. T3 o$ M+ A4 hmidy = getmaxy() / 2; </FONT></P>0 ^4 z3 A) `! b+ _
<P><FONT color=#0000ff>/* get mode number and name strings */ $ G; R3 h; t: M
mode = getgraphmode();
# V& S7 v2 P; ]sprintf(numname, "%d is the current mode number.", mode); ! U/ a) b3 ~; K) g6 v4 \
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>  X2 B( p% e  Z
<P><FONT color=#0000ff>/* display the information */
3 p1 H+ k: ^9 D( ssettextjustify(CENTER_TEXT, CENTER_TEXT); 1 |9 k9 w( C! @% n% e" \. I6 T& z- u
outtextxy(midx, midy, numname);
( B& b2 g$ B: l' c6 Wouttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
  ~  d7 ^5 y) x, h/ k<P><FONT color=#0000ff>/* clean up */ * w0 T; v+ O- R
getch();
5 e, h, O$ b+ D, C: g8 d! e' fclosegraph(); - _( c& l7 }: W4 p( ?
return 0;
) y- z/ G5 K: i7 G% h} </FONT>! V5 I2 S$ n+ Z; A$ R. ^. \
3 L% Y( t, h/ H+ j/ q% D
</P>
9 }* V* V( I. F! G+ B0 \<P><FONT color=#ff0000>函数名: getmoderange</FONT>
' G/ e& P2 `( o5 f8 v  T8 o3 H9 g5 Y功 能: 取给定图形驱动程序的模式范围 ! e3 I9 T! p+ t* D
用 法: void far getmoderange(int graphdriver, int far *lomode,
+ o  f+ j, r7 Zint far *himode); ) @7 v7 r9 @6 Q- R6 w% T( U
程序例: </P>0 H9 b! B) o: @: I9 {) l
<P><FONT color=#0000ff>#include <GRAPHICS.H>+ H0 l6 N  o/ a
#include <STDLIB.H>+ C2 u* G% j0 E& g, n
#include <STDIO.H>0 ^$ d3 K. A+ q, Q7 u% L- U. C
#include <CONIO.H></FONT></P>5 W, q  l5 E4 U
<P><FONT color=#0000ff>int main(void)
. {. P. J$ k) ~" s! T4 e8 E{ * Y" {. I& N3 r9 t
/* request auto detection */ . k2 }( l! |- L5 S! [2 r2 {* O
int gdriver = DETECT, gmode, errorcode;   m! {( e6 P1 g% V1 C$ z
int midx, midy; 7 A1 Z5 {9 B5 D& V9 m7 {
int low, high; 5 K& a: o9 Z, v' t! \
char mrange[80]; </FONT></P>
1 `' u# s8 P+ z( t9 X/ {) _/ f: O4 b<P><FONT color=#0000ff>/* initialize graphics and local variables */
: A' h9 s0 m% t" tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: P5 L  u5 M1 p& N3 `<P><FONT color=#0000ff>/* read result of initialization */ 6 I* w' a8 }# P* f3 m# U
errorcode = graphresult();
# {: p* l! N/ |) y* {8 Kif (errorcode != grOk) /* an error occurred */
3 g' @( _1 a4 x- }  ]: r{
, m2 P; x5 Y/ F7 [& g3 T' Eprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 n9 |% J: \# y6 ~* J
printf("Press any key to halt:");
% S  {; F6 [: c) C, C- qgetch(); ' o8 V, b4 d. R' D7 Y
exit(1); /* terminate with an error code */
/ q6 P3 [  V) `; g4 _9 ]7 ?* D} </FONT></P>
8 ^, g$ \" A6 p. O  e) ]<P><FONT color=#0000ff>midx = getmaxx() / 2; / v$ m, J. h5 J6 Y+ U
midy = getmaxy() / 2; </FONT></P>! r) |& T2 ]& z9 C) {
<P><FONT color=#0000ff>/* get the mode range for this driver */
7 A8 n$ A: i! A7 |2 Bgetmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
- Q, I( M! H# l% i# v1 V<P><FONT color=#0000ff>/* convert mode range info. into strings */
  X' W. j; P$ k1 V% j  C3 vsprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
" @! ~: |& y9 U<P><FONT color=#0000ff>/* display the information */
( _5 \0 J, r% T2 [settextjustify(CENTER_TEXT, CENTER_TEXT);
7 P: ], z- j3 pouttextxy(midx, midy, mrange); </FONT></P>
6 ^3 k, L! k1 O. g' c2 P( X: H<P><FONT color=#0000ff>/* clean up */
* m+ m& [2 H1 |* U; u: Ngetch(); ' T) x: k% Y6 Z
closegraph(); ) r; A6 P  q0 ~$ O- \& X
return 0;   i$ R3 Q% q5 |% ~: o
} 1 d! V, c' a2 O
</FONT>1 [) T& L3 ^+ j- e
</P>
' r( }4 D' w1 u/ N" h5 q1 U<P><FONT color=#ff0000>函数名: getpalette </FONT>7 r4 C  C$ Z! V! u" o* j
功 能: 返回有关当前调色板的信息 7 t- G4 b4 `: |
用 法: void far getpalette(struct palettetype far *palette);
& ~0 e+ U  B2 M# W程序例: </P>
& h5 K- y) c9 r8 ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
" F! H1 h, {9 y+ c# k& s#include <STDLIB.H>
) O( O1 `. n% d#include <STDIO.H>, t. M' K& Q) ]- R* L9 c
#include <CONIO.H></FONT></P>7 O3 X. ~: p  \. {
<P><FONT color=#0000ff>int main(void) 1 ?! x1 Y/ U; q8 ~& M
{
( n0 F1 X4 \9 k# |5 v* E3 R/ a/* request auto detection */
# S% K( U. [+ M6 A7 @% hint gdriver = DETECT, gmode, errorcode; , M) k% @! a4 h- h; H
struct palettetype pal;
8 G/ ~( M- g+ i5 V  achar psize[80], pval[20]; 9 b7 H' Q4 N8 j* k! r; Y
int i, ht;
' Y, Q$ O% j3 s, Wint y = 10; </FONT></P>
' a" `: A9 u4 A" ]<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 p( L4 A6 s" [5 |+ g/ n
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 }( v% b2 o& Z6 x7 w0 ?
<P><FONT color=#0000ff>/* read result of initialization */
6 H8 j- R) H8 j6 ~* Perrorcode = graphresult();
2 B4 g% i7 e" q5 s3 ?& g7 m/* an error occurred */
, n$ V0 o5 M5 w% h3 ]- ]if (errorcode != grOk)
0 C0 A; a3 J: N& l0 I{ : T: \# k# m* p; e+ u
printf("Graphics error: %s\n", - M4 S( B' Y. a/ ~" i7 ~+ q7 K
grapherrormsg(errorcode));
8 F- u9 ?. \; c" Xprintf("Press any key to halt:"); " W, \& Q5 ~; N1 o$ T
getch(); / `- d% b) S- F8 I% s7 V' x
/* terminate with an error code */ . h8 ?' C8 O. Z
exit(1); ; T. g4 G' L4 U! v' {7 u5 ^+ ]" V( T
} </FONT></P>
/ f$ E1 Z) [$ I2 m/ j; ~<P><FONT color=#0000ff>/* grab a copy of the palette */
1 x# ^2 t! ~, e+ R$ u) e, M" igetpalette(&amp;pal); </FONT></P>
+ _7 A( ^! f4 d& r0 G  d<P><FONT color=#0000ff>/* convert palette info. into strings */ 5 L* `* l2 {' m' K
sprintf(psize, "The palette has %d \
' f* u5 Y$ e( G2 A& p" ?$ [8 Q& Amodifiable entries.", pal.size); </FONT></P>
5 w4 @/ |& q! H! I* K( j% {<P><FONT color=#0000ff>/* display the information */
: M' v8 H. o- }3 z7 K  ^% oouttextxy(0, y, psize);
) `8 [% M/ W" @: s8 Bif (pal.size != 0) , h/ p9 U. _7 T1 L) U
{
3 V" g2 J4 F# j" bht = textheight("W");
7 M0 A" ?6 w) sy += 2*ht;
( i8 J& N6 S* m' L3 ^outtextxy(0, y, "Here are the current \
1 e% P6 x6 c0 p. q- Svalues:"); 7 \2 f( J' e! y; j. [2 |
y += 2*ht; 6 S7 a" n/ N2 {' p( h0 z9 B& x3 f; V
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { ) T. f# w4 e% G) J- q; \! B
sprintf(pval,
: W6 ^& b& R/ i7 C8 i+ S7 f5 J"palette[%02d]: 0x%02X", i,   J+ w2 X) ~1 U
pal.colors);
9 Y9 w9 l, t- p+ Gouttextxy(0, y, pval); : L( N5 w+ o& U: Y1 ~+ S
}   a* ~: y2 A3 ^8 ]9 z8 @4 f
} </FONT></P>
' U: |9 n: [* X2 O) s# G<P><FONT color=#0000ff>/* clean up */ ) t; W% _) h9 k1 u2 C5 H: m+ H6 J6 p. }8 l
getch(); 1 }, R& Z" h6 Z) [" c4 k
closegraph(); </FONT>: \0 ~8 t1 Y4 t# _
<FONT color=#0000ff>return 0;
* h6 h5 g6 p* B: u, |+ @& C- ?}
4 h+ L- W6 p. K</FONT></P>
' Y3 m  ^' h7 u5 l4 V# J3 a2 ]. x<P><FONT color=#ff0000>函数名: getpass </FONT>
# }- ?( [+ u2 ~( b3 W* u功 能: 读一个口令 8 u/ {/ l9 u1 Y& D- S+ J
用 法: char *getpass(char *prompt); 8 c7 ^9 r, {1 t
程序例: </P>
+ g& z  R+ I5 o! |<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
$ k) O; b- v: z. S( z% b5 W* w<P><FONT color=#0000ff>int main(void)
5 f6 e5 N6 t1 i( w$ q. @! Y$ z{
* x" E8 }2 E. s4 y3 tchar *password; </FONT></P>
' r. t! R' V0 p( X5 \$ U<P><FONT color=#0000ff>password = getpass("Input a password:"); ' K! Y/ s! C& t
cprintf("The password is: %s\r\n", $ z1 ]: b  m+ ~, |% V* j; ]
password); 7 j1 b* q9 Q3 ~; O2 K, v
return 0;
# K4 a' E  m& t; Y; M}
/ e$ p% L$ l/ D2 o( r2 L7 Y</FONT>+ R4 ~6 h2 N% G3 Y0 x
0 C: U  G0 _! ?) V. I( m6 i
</P>
0 `1 s: ]$ F9 x8 T* E- |+ K<P><FONT color=#ff0000>函数名: getpixel </FONT>
4 d5 g" [- J" i1 M功 能: 取得指定像素的颜色 7 @4 I+ L) `# M7 y/ N
用 法: int far getpixel(int x, int y); $ J9 p$ e1 z! Q" B
程序例: </P>
4 q5 P) h* s; O  {9 R<P><FONT color=#0000ff>#include <GRAPHICS.H>+ I* s% p. u# f
#include <STDLIB.H>
0 S% {( [" C) U' I#include <STDIO.H>/ f, c" Q. L1 V0 {; ]" _
#include <CONIO.H>4 i# r* Q/ A8 B" @1 O
#include <DOS.H></FONT></P>
2 A3 c$ D+ B6 E% ?# N4 H8 ]<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
1 M1 W# x$ K: P#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>5 B8 k6 J, v9 T: O0 b4 A0 V
<P><FONT color=#0000ff>int main(void)
5 L& G2 T; h8 m) D{ ' V  z" [3 F$ o) m+ f  {
/* request auto detection */
# F5 s4 x1 y' |! j) I3 _int gdriver = DETECT, gmode, errorcode; 2 C  m/ U& v2 d" \5 n- |$ e* B
int i, x, y, color, maxx, maxy, 7 ?- W# ?/ {) u' h5 @& C& [4 h" L! o1 D
maxcolor, seed; </FONT></P>
# c/ f" c+ ~; [% ]" \+ o<P><FONT color=#0000ff>/* initialize graphics and local variables */ # [' c) m" Z; a2 w) B1 T, r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* Q1 B: B0 W" c6 M9 q<P><FONT color=#0000ff>/* read result of initialization */
3 L6 w: ^" S" Q6 a3 @2 b5 Kerrorcode = graphresult(); 9 f! h" }: ?- H2 z7 V* x5 p" u9 x
/* an error occurred */
' U0 t3 ?* |! w* Gif (errorcode != grOk)
- y9 @+ _  _" @3 S7 P{
5 W" L6 H1 J# g+ m1 aprintf("Graphics error: %s\n", & u" ], o' Q6 ^% w( ]4 @+ {
grapherrormsg(errorcode)); 3 w$ c* I# c% i! C( j
printf("Press any key to halt:");
8 \) n0 H% N% O6 _0 {8 m) Agetch();
5 j4 l! U, a) \* |/ K  {) g/* terminate with an error code */
' Q5 I: N  l9 I2 w8 o9 Qexit(1); 1 W7 O% R5 V; ^
} </FONT></P>
- l% h3 p7 O# |<P><FONT color=#0000ff>maxx = getmaxx() + 1; , H- p1 j* q( K( s* S: a
maxy = getmaxy() + 1; , ^- i. a! L" @
maxcolor = getmaxcolor() + 1; </FONT></P>
. q" `$ Y5 i: P! j& ^, q<P><FONT color=#0000ff>while (!kbhit()) 7 F+ s. Q% r& V/ m/ v
{
9 P" [! U: t9 p, A8 z+ h; |/* seed the random number generator */ ; N0 j* c: i- w! g9 D6 r# T. F1 C0 I
seed = random(32767);
" C9 u* e2 R" k+ g3 o9 asrand(seed);
! |: B) L; e' e6 G  o4 zfor (i=0; i<PIXEL_COUNT; <br i++)> { 4 H; g5 z( ^2 |  p
x = random(maxx);
$ v3 S3 G9 [9 [0 }y = random(maxy);
6 E0 a) C2 W$ B5 d* jcolor = random(maxcolor); ) e6 ?  _( s+ k. z" `* E# \
putpixel(x, y, color);
' y* M3 r- Z& o$ g} </FONT></P>; Q7 v6 Q* X2 k2 Q
<P><FONT color=#0000ff>delay(DELAY_TIME);
  {7 u; m+ Z7 O* Zsrand(seed); ; ]" x% m  D3 z& w% l
for (i=0; i<PIXEL_COUNT; <br i++)> {
% T. Y9 x$ G4 U. Jx = random(maxx);
$ A1 ?, C' q1 m/ p% L! G! [* U& sy = random(maxy);
& j2 w& W9 J7 Jcolor = random(maxcolor); % A1 k: L% Q0 W. K+ f( M. Y3 i
if (color == getpixel)</FONT> </P>9 o7 r" x7 U8 i, G" H
<P><FONT color=#ff0000>函数名: gets</FONT> 4 _9 ]/ }3 C2 B( B
功 能: 从流中取一字符串
: R1 X- U) l  C- U8 H用 法: char *gets(char *string); 2 d/ T3 q$ ]' q$ g( W( g! i7 T' G+ e% B
程序例: </P>
$ V, S: P3 z' K! q+ ^<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>( `* a; h9 q: ~: J+ s8 r& `
<P><FONT color=#0000ff>int main(void)
8 W  C3 ?9 o0 w# s{
% A6 C2 Y5 K9 Z$ K" A7 A' _9 @char string[80]; </FONT></P>) C, W+ M, k* u4 R9 b, ?
<P><FONT color=#0000ff>printf("Input a string:");
& F9 ^8 L: N( T8 {6 x2 C" Mgets(string);
+ x9 k) f; g1 J! |  k. t' dprintf("The string input was: %s\n",
0 P) ~5 [) D' A+ r% C) a( S1 R3 Astring);
, I$ p" A1 q2 K1 i8 Q& u" Z- |return 0; 8 N& t' c- H* T( I
} 6 |* s4 b. L& |6 f  `0 V9 ~

" e: X( S5 @1 R& X$ v</FONT></P>
" A& c2 J, T' q9 x, A: s/ R<P><FONT color=#ff0000>函数名: gettext </FONT>
1 G! x. d2 W" O6 }/ X& N8 d功 能: 将文本方式屏幕上的文本拷贝到存储区
2 p# j- L5 G% U" ^$ r用 法: int gettext(int left, int top, int right, int bottom, void *destin); 2 r7 P/ B- i% x: P9 ]5 m1 ^3 P( E
程序例: </P>5 W& J, S. {) v) _6 u& K7 {: v  l
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>9 N/ j8 M  M: \/ K3 g' Z
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>0 ^4 S2 y0 n+ r$ C$ J# e. v
<P><FONT color=#0000ff>int main(void) / i* e) z3 G: u, Y- t' ~( d
{ # r8 @4 I& V, \7 u
int i;
! d  d  ^. Z' f6 w1 K, Zclrscr();
* p! \9 S' x5 @7 [& B1 ]for (i = 0; i &lt;= 20; i++) 1 J  [/ Z. J- a& N: A# s6 L
cprintf("Line #%d\r\n", i);
) Z. p, b( R$ _; R* ~; Bgettext(1, 1, 80, 25, buffer); : @, H+ J# t& ]- ^- J
gotoxy(1, 25);
2 l1 s$ e  Y% b" l  ycprintf("Press any key to clear screen...");
0 q% J7 a4 A+ ?+ f3 Ggetch();
# I- I5 e1 Q" g8 D& `1 jclrscr(); , Y3 L9 I& q# W
gotoxy(1, 25);
6 i8 c& I/ w1 {. u- Ncprintf("Press any key to restore screen...");
' J& M% Y, h- F6 Ngetch();
8 _! D3 s2 ~3 o6 |/ n- v$ lputtext(1, 1, 80, 25, buffer); ) v3 H( ?. z( d* O" o
gotoxy(1, 25); ! Q8 _4 Z( m' `, W6 @  h& ^  X6 P$ U
cprintf("Press any key to quit..."); ; v  u* X  }- ~. k. Q6 l' C) w4 Z
getch(); ' A1 _" d9 ^1 {" T* N8 J& F0 B5 e
return 0;
# W( d' d# T# H7 G- [: x9 C5 J} 5 x" _* I( i  l, S- d+ L: ~" [; ]8 q
</FONT>
& |8 d" v' t% R9 K" U0 W# N</P>2 t( i- L6 S1 ?6 p; _
<P><FONT color=#ff0000>函数名: gettextinfo</FONT>   r8 B4 ^9 s$ ^/ A
功 能: 取得文本模式的显示信息 3 j$ t8 r6 @- Q2 U$ V% z
用 法: void gettextinfo(struct text_info *inforec);
2 Y" ?* M( F) w3 |  J% \: n程序例: </P>- M& `' Q/ i2 j7 i5 K
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
  L. }% }% G+ s2 c7 v7 L<P><FONT color=#0000ff>int main(void)
8 u$ P& ]! ~, Z. y{
7 p, j  ~- z( ^9 M& S% I/ i8 A& ~" Vstruct text_info ti; 7 `: i0 E8 S; B( O
gettextinfo(&amp;ti);
- @# c& ~' ]8 ?cprintf("window left %2d\r\n",ti.winleft);
2 Z+ P' X5 J9 ~7 H  ^2 Rcprintf("window top %2d\r\n",ti.wintop);
. x- w  U1 z2 i' jcprintf("window right %2d\r\n",ti.winright); ) p5 P8 t* ~6 p- \& Y
cprintf("window bottom %2d\r\n",ti.winbottom);
' {9 b9 {2 P: x. x9 Rcprintf("attribute %2d\r\n",ti.attribute); $ r* H5 z; H9 Y5 Z; l% I
cprintf("normal attribute %2d\r\n",ti.normattr); 9 D( ?, R* F9 O* [% S, O* h
cprintf("current mode %2d\r\n",ti.currmode);
4 r; d: ~8 m& @, C1 ]cprintf("screen height %2d\r\n",ti.screenheight);
& e1 x# s0 R+ `! g2 Xcprintf("screen width %2d\r\n",ti.screenwidth); 2 S+ n' W3 u0 `4 O2 ^/ h
cprintf("current x %2d\r\n",ti.curx);
9 E. C; y4 R3 Rcprintf("current y %2d\r\n",ti.cury); 4 _* T* R  x  z% \
return 0;
# ]( `! N) m9 T$ G}
% t% j& p# Z* p. o5 P</FONT>
# ?' w7 b- N1 p</P>/ S# i# J# \* l# v# |% J- ~& L
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
) n% v9 [6 d  Z- o: `3 S功 能: 返回有关当前图形文本字体的信息 & B8 ?: @2 b: s; w
用 法: void far gettextsettings(struct textsettingstype far *textinfo); ; H; y4 s* s3 q6 Y
程序例: </P>6 a  d3 B3 s* Q% A$ o: f5 A
<P>#include <GRAPHICS.H><FONT color=#0000ff>
- Q& J# ?; Y5 ~' w#include <STDLIB.H>
6 y0 S( j) F" R9 B#include <STDIO.H>
' `) j! m3 M' X$ J6 w2 W# y#include <CONIO.H></FONT></P>9 _* D4 \* Q: R( v8 ?
<P><FONT color=#0000ff>/* the names of the fonts supported */
3 \# \' Z3 L% M5 \; B; Hchar *font[] = { "DEFAULT_FONT", & K: N  D9 j6 f) L' G) _
"TRIPLEX_FONT",
2 s: \/ u: c2 c4 x" {; j2 k; A* J9 V"SMALL_FONT",
. |; |8 Z0 t, w& [9 I"SANS_SERIF_FONT",
1 _0 V, X4 A% Z% Q9 F) ~. K"GOTHIC_FONT" 0 m; L( y4 ^% k2 N, y2 c
}; </FONT></P>. w) A; _8 w) Y1 S2 }) P6 `
<P><FONT color=#0000ff>/* the names of the text directions supported */
) |* Q/ |' i) ~( \5 {char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>( p' s6 N8 n9 I* [/ G2 a# U
<P><FONT color=#0000ff>/* horizontal text justifications supported */ ) V& I  n0 _7 B0 [! y! @
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>  a9 v8 y1 [. q2 Q  N
<P><FONT color=#0000ff>/* vertical text justifications supported */ 2 I6 u0 q6 b+ D
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
2 z0 l. p2 e3 v* j+ \<P><FONT color=#0000ff>int main(void)
9 L" o1 X! Q  @# f" `7 Q$ u; \{
7 J* U5 \7 O$ ]6 a0 {) e/* request auto detection */
) d! H% T3 k  D# _5 C0 f/ z# ^" s; v* {int gdriver = DETECT, gmode, errorcode;
* M$ V, n6 H1 y( fstruct textsettingstype textinfo; 5 R6 |7 `" r5 X: i& \3 w
int midx, midy, ht;
) w/ r, H& A- Y( l+ J2 fchar fontstr[80], dirstr[80], sizestr[80];
/ D4 D0 w$ V' x6 J' M+ rchar hjuststr[80], vjuststr[80]; </FONT></P>! E9 K  i9 `" N# ^
<P><FONT color=#0000ff>/* initialize graphics and local variables */ / i" c! D9 O5 {
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 T/ N/ P$ `6 H7 b
<P><FONT color=#0000ff>/* read result of initialization */ 4 g$ z) Q- ~9 P& W$ Y& X" K
errorcode = graphresult(); / o; I( m1 H1 k" l8 Q9 _6 H
if (errorcode != grOk) /* an error occurred */
+ Z8 ~, h1 ^( _$ o. f) s{
; q* U4 V2 s  {5 n& cprintf("Graphics error: %s\n", grapherrormsg(errorcode));
; u6 Z, y; ]3 {  j0 h. }+ kprintf("Press any key to halt:");
% r# j2 M, C, k0 u6 @' e9 ~0 k2 igetch(); 7 I+ n! P; i7 n! W$ _! W4 w
exit(1); /* terminate with an error code */ * m% D$ N0 p- }
} </FONT></P>/ t& G2 S2 N: _. M# i4 A
<P><FONT color=#0000ff>midx = getmaxx() / 2; ' u& c4 E# R$ W1 O1 k
midy = getmaxy() / 2; </FONT></P>
; j+ V: f/ o! Y2 a7 _5 o0 b: C<P><FONT color=#0000ff>/* get information about current text settings */ : M6 |1 O$ P6 ~+ t/ \
gettextsettings(&amp;textinfo); </FONT></P>5 b. R% R) F9 F  M4 S' b, I6 r  t
<P><FONT color=#0000ff>/* convert text information into strings */ ) F! h8 ~3 A+ K! B7 F# |* I
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); : Y1 v; m& R- c
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); : }0 [: j1 x+ J$ J* A8 d. Q& O
sprintf(sizestr, "%d is the text size.", textinfo.charsize); 2 Q( x) n7 T4 r; }& W# b( z" v
sprintf(hjuststr, "%s is the horizontal justification.",
6 E) U* k: P9 s3 s2 u( J4 b0 B+ y. xhjust[textinfo.horiz]); & x  D- V" L5 l. s
sprintf(vjuststr, "%s is the vertical justification.",
7 g; f$ [) R2 w: Lvjust[textinfo.vert]); </FONT></P>8 h2 _2 R% F! B" D$ ?( Y
<P><FONT color=#0000ff>/* display the information */
, P$ I0 s& h$ B1 ^8 Lht = textheight("W"); % C5 E- M. |; a' L4 p7 @: ]- X0 A
settextjustify(CENTER_TEXT, CENTER_TEXT); " W& M8 g6 c) g8 a( \4 M- B, D. X1 N
outtextxy(midx, midy, fontstr);
7 J5 K# {$ }. [7 V2 Touttextxy(midx, midy+2*ht, dirstr);
3 I+ R6 p4 p9 @5 t9 ]outtextxy(midx, midy+4*ht, sizestr); 2 L! \, \# k7 ?
outtextxy(midx, midy+6*ht, hjuststr); 6 V/ f$ o  e: c
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>5 U* g- R6 \0 T* \
<P><FONT color=#0000ff>/* clean up */
7 d& @' t4 h' D8 c7 R6 {getch();
- M/ h/ C4 O! n. w# G  U$ Kclosegraph();
5 R- h0 Y& ^# C- C3 treturn 0;
& F* `7 f& O9 m* S$ L1 l& D} </FONT>; I( r" ]- f" S8 f* ~0 `2 w- q2 _+ G
</P>1 e" t" \) G; p
<P><FONT color=#ff0000>函数名: gettime </FONT>% F8 _6 r5 ^, n
功 能: 取得系统时间
$ J4 r1 u: J6 M! Z用 法: void gettime(struct time *timep); , \4 ]+ o% p. A' o: N  C' v" A; f& E
程序例: </P>
6 t( N7 c/ U* l* S# P<P><FONT color=#0000ff>#include <STDIO.H>: h0 G/ q1 u0 _6 ^* _3 \' J% n
#include <DOS.H></FONT></P>
5 T1 @* E& {& H0 M2 r7 ]3 g$ _1 Y* r<P><FONT color=#0000ff>int main(void) . j8 P0 F5 m, T$ f% s; O8 Z
{
. Y7 l* X6 S7 _7 `struct time t; </FONT></P>
; |+ [4 ]$ a9 I* J6 B4 g: L<P><FONT color=#0000ff>gettime(&amp;t);
6 [. n" v% a4 S8 k1 U% |- V. lprintf("The current time is: %2d:%02d:%02d.%02d\n", & g1 x5 G0 ^$ Z, @; j
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
" m+ r, _2 j! a2 }! C, xreturn 0;
' L/ M# d/ P2 |/ B}
4 D- V3 I) \  h$ \+ e' I' ~
1 x+ o8 Z# _3 _3 n$ ?</FONT>. B0 k; J7 Q1 Z! f# o! t; H
</P>
+ e) X, y1 ^! W' s<P><FONT color=#ff0000>函数名: getvect </FONT>0 x9 G* k+ }' Z% X
功 能: 取得中断向量入口 . Y3 e5 p1 l* t' R% Q
用 法: void interrupt(*getvect(int intr_num));   D0 t9 m4 L- U5 B8 |5 q
程序例: </P>6 N/ R. r  p, ]9 `. w# k# i" E+ x0 c
<P><FONT color=#0000ff>#include <STDIO.H>9 j8 C3 H5 }! k$ _( N9 x
#include <DOS.H></FONT></P>& N  r/ x# ^$ V
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
0 W; W9 S( C; \% l<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
7 S  @) a' z7 Y5 qint looping = 1; </FONT></P>! _% Z4 t# `) I1 m
<P><FONT color=#0000ff>int main(void) 7 U0 n: X" ?/ r& E+ S- ~3 [* ^! m
{ 4 R! w; S; z0 B" W/ S1 \6 i
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
: z3 D) v( p* Q! @<P><FONT color=#0000ff>/* save the old interrupt */ " C9 d. I2 i+ ]- ~. o" q
oldfunc = getvect(5); </FONT></P>
* s# `% j2 i$ ]<P><FONT color=#0000ff>/* install interrupt handler */ - a9 H/ V% y% `3 \& q6 K( D& M8 s" d
setvect(5,get_out); </FONT></P>: q; p2 B, x3 L
<P><FONT color=#0000ff>/* do nothing */   l# `8 p  c8 p# w
while (looping); </FONT></P># \9 Q$ G4 a; Z# m  U
<P><FONT color=#0000ff>/* restore to original interrupt routine */ 9 p; Z8 S/ {% a7 P
setvect(5,oldfunc); </FONT></P>, w; ]6 T% x/ j, }# e1 l
<P><FONT color=#0000ff>puts("Success"); : ], ~9 F$ e2 s8 Z
return 0;
: m. R" J# k* d7 ^. K}
* B# g- O+ ?! L' ~* h9 V& [void interrupt get_out()
- b/ a+ ?, q: A{ & j% O1 o& ^  Z7 }& R
looping = 0; /* change global variable to get out of loop */
4 E" u8 l/ Z" K  K3 a* {8 j4 s}
% J1 T# y. o' M3 ~</FONT>& s2 E% d7 v4 {+ _, ^
</P>$ h9 i6 ?! L* a: b" u$ m
<P><FONT color=#ff0000>函数名: getverify </FONT>
' `4 c  T5 ?" M* Z! u功 能: 返回DOS校验标志状态 $ }0 d: K& a  `. ~: @$ @
用 法: int getverify(void);
8 a# n" u5 Z+ @9 v7 u; C6 W程序例: </P>
) j; n+ J6 Z# @$ ?4 b9 ^<P><FONT color=#0000ff>#include <STDIO.H>5 B5 N4 E( j3 w" b2 \
#include <DOS.H></FONT></P>
8 m3 B3 u% B; J4 V; t$ Q/ P<P><FONT color=#0000ff>int main(void) , `  V0 {* ]0 ]4 B* v5 M
{ 5 }4 S9 p8 n& c) p9 D% ^
if (getverify())
& F9 {6 V8 A5 D4 o7 q  }printf("DOS verify flag is on\n"); 7 u3 F' Z8 d2 W, n- U
else
$ J1 C( T. A2 x  p4 Bprintf("DOS verify flag is off\n"); * X5 c0 [$ b4 y7 Y( ?
return 0;
  O$ A, K- k# v" M9 b6 p}
4 w4 R( F7 c# f3 _. ?$ Z</FONT></P>" d7 S. f6 \, K* S. [
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>  ?, m9 Q# {$ \/ u( a7 A% K
功 能: 返回有关当前视区的信息
( N5 q2 p, ]* a9 m7 K用 法: void far getviewsettings(struct viewporttype far *viewport);
+ a* b/ b* T( b/ @' E: q/ M5 a. }! m程序例: </P>9 U7 O, R, S7 p4 }) r
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ {7 ?1 F* _% N& x+ V#include <STDLIB.H>
! n# W2 z6 W: Y4 ^% N#include <STDIO.H>
8 a8 d/ D, R- o) c8 B) f#include <CONIO.H></FONT></P>
0 P3 z- J) D, U: F8 X) S2 ^<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>' x. P$ ?. p$ e  W, c
<P><FONT color=#0000ff>int main(void)
/ o' ^& O! t6 i9 X/ X6 d2 _" v  q. P{ ( ?) ~- p) H9 }4 ^  _
/* request auto detection */ % a- b0 i' Y, \9 n
int gdriver = DETECT, gmode, errorcode; $ ]) A9 b& [7 H4 k7 y8 ^1 X8 `
struct viewporttype viewinfo; / @' a  L1 H0 O( |. x, S" b
int midx, midy, ht;
+ i, f: c% L0 U+ p7 mchar topstr[80], botstr[80], clipstr[80]; </FONT></P>" o* P; ~  ?% J/ w& J4 ?. h# d
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, G) H+ Z2 }3 A: C5 {0 [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 [  ]* A6 F2 A2 E1 B% d0 C7 o
<P><FONT color=#0000ff>/* read result of initialization */ ! y) Y' M/ n  n9 a! \8 J3 `6 d
errorcode = graphresult();
; O: n# C5 V+ o4 Z* x) p$ V3 Bif (errorcode != grOk) /* an error occurred */ 3 Q: f' J* Z6 n, J3 V8 S
{
4 Z3 t  z$ T2 ?: V) i) Wprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ) E, q0 r$ H) t. G
printf("Press any key to halt:"); ' x- h! C& a! ?1 t1 d4 c6 Z# p! O
getch();
; J4 M! c- B' W( B, Rexit(1); /* terminate with an error code */
1 {9 S% h1 Q2 W) O# E- [, o} </FONT></P>7 _7 A' k$ _* z5 b. H# I
<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 H0 w/ {5 X5 d4 M- r4 W) Omidy = getmaxy() / 2; </FONT></P>
* P* R! u) F. x8 b<P><FONT color=#0000ff>/* get information about current viewport */ 6 Z% _5 D" l. }, L" P. I
getviewsettings(&amp;viewinfo); </FONT></P>* x. n3 s. o) N+ t
<P><FONT color=#0000ff>/* convert text information into strings */
" c& q' V) H' r- Rsprintf(topstr, "(%d, %d) is the upper left viewport corner.", ' v2 N9 G$ x, |( B& h& ~& `% P! ], H
viewinfo.left, viewinfo.top); 0 T8 K, s9 O/ j( B: `. n
sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
1 o6 F2 a1 K$ e; Y. v$ }) xviewinfo.right, viewinfo.bottom); 3 P0 ~/ \9 a% Q, T/ N+ o
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
$ U: I: ]& y( k( Q0 |7 s, S0 R1 @<P><FONT color=#0000ff>/* display the information */
+ ?0 n5 I- u. R# [settextjustify(CENTER_TEXT, CENTER_TEXT);
3 y: \9 _# S) I, v9 {9 Z! L3 Rht = textheight("W");   }7 U' T! u: u7 ]
outtextxy(midx, midy, topstr); ' ~9 r3 N+ l4 ^6 [) J8 ]
outtextxy(midx, midy+2*ht, botstr);
! l/ s# P, X/ I% _outtextxy(midx, midy+4*ht, clipstr); </FONT></P>4 p) y/ a. S' P+ z7 \5 f) Y
<P><FONT color=#0000ff>/* clean up */
( V' e+ Z' K3 l; m2 c( L1 ugetch(); 6 c1 o" R- `6 s
closegraph();
" E' W* o6 L' p! g  Q/ E) h0 g. D/ Zreturn 0; 0 X" G* ?1 p# g) G" ]* W
} </FONT>( k: n2 L/ h( i8 L# T7 `9 ^1 `0 U# K

$ D6 M" L+ G: R( I# I/ {4 ?</P>' ?8 c- e: G3 y% T8 }6 @
<P><FONT color=#ff0000>函数名: getw </FONT>
% q' N+ c- i; ^3 Y功 能: 从流中取一整数
5 a: j. B% R  k2 @用 法: int getw(FILE *strem);
$ M4 B# f) g  }3 _- ]& f& E* x程序例: </P>) s! \( k0 ]8 L5 x$ Y( W
<P><FONT color=#0000ff>#include <STDIO.H>
$ m* }5 S" e( F' M& B#include <STDLIB.H></FONT></P>3 x; \2 I/ g: T+ k0 U1 J) J% i, c* G) n
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
% e. _$ ]2 ~+ \<P><FONT color=#0000ff>int main(void)
3 D, ^5 o7 m% p7 b/ T- c{
: m2 g% g. ^+ m. |1 dFILE *fp;
. ?! h) L$ R9 s- j. fint word; </FONT></P>
6 [# u( x8 T/ x% h: Z<P><FONT color=#0000ff>/* place the word in a file */
. l0 @7 D+ n$ _3 u6 ]: k: Xfp = fopen(FNAME, "wb"); 1 ~5 u& c5 n" m: q* x/ `" P& F
if (fp == NULL)
6 f( K7 A4 j+ S) o0 j- u. F/ L; z{ $ m' t0 k6 ^* u! g( T  P0 [
printf("Error opening file %s\n", FNAME); 3 ?  }4 R  H$ v! U* r
exit(1);
  {0 Z/ b- s: B- y( Z+ ?} </FONT></P>0 j( g% L0 T# k" [3 {
<P><FONT color=#0000ff>word = 94;
5 g+ \3 B7 j8 j9 l# Lputw(word,fp);
. q( ~% ]7 G$ h2 Q6 C& K8 V3 fif (ferror(fp)) " q- X- A( A6 l4 S0 n. B- M/ z
printf("Error writing to file\n");
5 X4 q% Z8 M' D( j, t7 belse 5 z7 B2 [8 @% k% x' X
printf("Successful write\n"); ) M/ P! M' N- t8 B) w: I# T
fclose(fp); </FONT></P>7 o' c3 R0 `+ T+ `6 \
<P><FONT color=#0000ff>/* reopen the file */ 2 F3 `/ w. k$ D& e3 V
fp = fopen(FNAME, "rb"); . M3 F1 Y* ?  l9 L8 C5 R
if (fp == NULL)
% b; |7 g$ [% h{
& h9 o2 a! h5 y& @; yprintf("Error opening file %s\n", FNAME);
. J+ M$ H* j$ i* A5 H' E8 pexit(1);
* l- Y9 t' @1 q% ^  K} </FONT></P>4 |3 Y: O6 `2 f1 r6 Q, T% W4 y
<P><FONT color=#0000ff>/* extract the word */ 9 J* q! r0 y& ]: ?# P3 {
word = getw(fp);
) z9 x' J* s9 _if (ferror(fp))
8 o& v5 x3 g  j1 m$ t' W$ \printf("Error reading file\n");
  ~( _% p$ w" Y$ _% Melse $ Q5 `' x1 G/ T  ~
printf("Successful read: word = %d\n", word); </FONT></P>
% h, a* [  v* A* I' s1 w7 k+ o<P><FONT color=#0000ff>/* clean up */
8 J( S7 ^5 P7 _; |$ b/ A* @% ifclose(fp);
, M7 w" P6 F3 p  ~) Vunlink(FNAME); </FONT></P>6 G+ v( I1 z2 H. L: l: g3 _7 J5 Y- n
<P><FONT color=#0000ff>return 0; * U4 N3 S! }( a
} </FONT>2 A! b* d- h2 J1 d

3 L/ {- C* W/ H+ x7 c
# `8 r' Y! l' i; I; I: D3 o( M+ m</P>
. Q3 R9 l( X' v. A$ F6 W8 c; M<P><FONT color=#ff0000>函数名: getx </FONT>2 [. y  p( L/ i
功 能: 返回当前图形位置的x坐标
4 Y& T5 \( A; e5 \. K6 r% E用 法: int far getx(void); 2 |5 C4 W# f2 q! x$ u, G" \
程序例: </P>
( b1 A& l- h7 o5 I& F5 |# ]- N0 d<P>#include <GRAPHICS.H><FONT color=#0000ff>' {9 W2 h1 m2 c% R) h$ I/ u( {5 }
#include <STDLIB.H>
, [4 b5 o: J5 Y( u" H#include <STDIO.H>
0 G. M3 O. q& u  T8 @#include <CONIO.H></FONT></P>
. r; v* L- o4 k* o5 `<P><FONT color=#0000ff>int main(void) 4 a1 O) }. P+ i1 _
{ 9 b+ v6 v+ d) K' k5 W3 p
/* request auto detection */
  P# B7 S* V+ y7 Y! H+ F" gint gdriver = DETECT, gmode, errorcode; % {9 ?" d6 `' ]. }! K/ T, w
char msg[80]; </FONT></P>2 I: B) u! }' p8 L/ v
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! V( k4 ?* n) d
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" u+ [' `. M/ v4 i<P><FONT color=#0000ff>/* read result of initialization */
8 a* T* H( g. N$ m* herrorcode = graphresult();
# f2 W+ u, ~: d3 {9 t7 Cif (errorcode != grOk) /* an error occurred */ 6 T6 q& s; x. s0 f
{ / w8 F4 L+ u" A( g& u1 e; K/ h
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 X; E- a5 f  q# N
printf("Press any key to halt:");
8 p" M, s' |. x* K& b2 c5 D4 ]getch();
' f- e1 `1 m' H5 p# w8 nexit(1); /* terminate with an error code */ 1 v4 ?7 {$ }& U) Z% Z
} </FONT></P>
+ s) g& Y1 ?4 G<P><FONT color=#0000ff>/* move to the screen center point */ , k6 R. ~! r4 ^3 f2 X& h8 \
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>) t( M1 ~$ k- p/ \, }; m5 H
<P><FONT color=#0000ff>/* create a message string */ / j+ t% s3 o4 h: O* H( \
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
) X. c5 \" V7 |3 C8 j<P><FONT color=#0000ff>/* display the message */ 7 [2 [& g- Q2 P0 K
outtext(msg); </FONT></P>
- p( }0 E& `# E% D2 u; A<P><FONT color=#0000ff>/* clean up */
/ Z5 H$ l+ d  ~( ~- e8 S# ugetch(); " n! d# F6 z- l3 O) b9 R
closegraph(); 3 m3 J9 R* _* U; n5 i
return 0; : S) u% o) X' @" O/ i) p  c; E
} </FONT>
( U- u9 \& d0 R$ N  t. X7 M' E; ?2 [' M: s" K
</P>* `0 K* c0 B# a5 Q0 `. P4 c$ Q$ `
<P><FONT color=#ff0000>函数名: gety </FONT>
5 q% I' I9 x: \+ K* W1 D0 H1 K, d功 能: 返回当前图形位置的y坐标 1 e2 K9 |- U. @/ r* f
用 法: int far gety(void); 8 L9 ~0 U3 Y1 P& m3 T* f0 R- ^
程序例: </P>! q1 L5 m8 S( \0 l3 ]  e: L8 A7 o
<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 A2 c/ ]! {3 G) X#include <STDLIB.H>
$ y( ?( Q; {( K#include <STDIO.H>! q: _$ l: [" g4 K+ y, l) h
#include <CONIO.H></FONT></P>
; A# u) R7 J# P0 J) t8 C<P><FONT color=#0000ff>int main(void)
3 M1 ?% c7 X) E0 J. D" r{
! g3 I4 `; o* {* ^5 T2 t/* request auto detection */
4 K) N+ I! _) C" Q0 p% }! y) A$ i, Rint gdriver = DETECT, gmode, errorcode;
% |9 y, \1 W4 C. q% i& uchar msg[80]; </FONT></P>
. c+ Q* a. ~! |+ H9 h) \& R<P><FONT color=#0000ff>/* initialize graphics and local variables */
: ]3 m8 A7 w6 ]- O% iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# R/ |' n" z" S. Z# S' ^# S<P><FONT color=#0000ff>/* read result of initialization */
2 c7 t" l5 z1 r% B4 c2 serrorcode = graphresult();
; d7 f9 y' {/ qif (errorcode != grOk) /* an error occurred */
. A- E( D: K, s4 H  N{ $ b6 P8 V9 V3 T4 H2 D
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 O, t! P6 M. h' R0 Y  c$ v6 vprintf("Press any key to halt:");
+ j( W5 [# x" L* Y3 i8 Wgetch(); : S- _4 b! T2 i/ o3 k0 s8 P3 h: i
exit(1); /* terminate with an error code */
$ D4 J) e3 I1 f7 ?} </FONT></P>2 F$ d. ~1 f: D% p  m2 r
<P><FONT color=#0000ff>/* move to the screen center point */
$ F$ ~- T( M2 imoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
: [5 _4 v. \5 `<P><FONT color=#0000ff>/* create a message string */ 5 f2 C3 C+ V3 Y+ I7 L; e, G, X
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
7 @& n1 D: B9 q* Y! \; @& C<P><FONT color=#0000ff>/* display the message */ 8 X; |! z# O+ u- a" m/ D
outtext(msg); </FONT></P>
* |+ R# h* |$ H4 ]' Z4 x# E9 m<P><FONT color=#0000ff>/* clean up */ 7 u) S8 T, ^8 x9 M
getch();   d0 a; @& y8 T4 K
closegraph(); 6 x1 ~1 V; r5 J% S
return 0;
* Q$ A$ `; X7 @4 ~' S} </FONT>, O* `7 P4 m+ T- ^- _

8 |7 g& }5 E7 k! h! A! t9 X</P>/ S9 {9 c! n, h& S0 x. C
<P><FONT color=#ff0000>函数名: gmtime </FONT>' j* o  B8 O1 t" B
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
  R) `  ?5 ?" |! _+ l1 ~用 法: struct tm *gmtime(long *clock); , ~/ |# M' L2 c
程序例: </P>+ X% ]* |9 a, o2 Z' i
<P>#include <STDIO.H><FONT color=#0000ff>% S+ g; Q4 m" V* J
#include <STDLIB.H>( V* {% k* K, v4 a7 V: c8 A$ V
#include <TIME.H>
4 N7 f! p; q  v! B. k3 A  H9 }#include <DOS.H></FONT></P>
" `; j4 Z6 o& E<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */ 5 U3 |$ @* P9 z
char *tzstr = "TZ=PST8PDT"; </FONT></P>
* i: H+ |$ t' C<P><FONT color=#0000ff>int main(void)
* q. ]; ?( d8 v{ + Z5 T5 ]; F$ c2 w. E" ^) n0 j
time_t t; 7 i/ P* F# [. ^- }( Q- v0 _3 j0 y
struct tm *gmt, *area; </FONT></P>& A  T% @, r( e+ c& ^
<P><FONT color=#0000ff>putenv(tzstr); ( U+ L/ i% k3 C
tzset(); </FONT></P>6 \& Z5 Q$ v8 @5 s
<P><FONT color=#0000ff>t = time(NULL);
, `! |! M/ v$ T; qarea = localtime(&amp;t); # e9 t7 }* Z" }3 I
printf("Local time is: %s", asctime(area)); ! v9 H5 C! r! W; n# [
gmt = gmtime(&amp;t);
* o9 }' d7 t4 h$ f+ _printf("GMT is: %s", asctime(gmt));
1 w3 w7 r: A: mreturn 0; 3 F4 W, t, w4 {$ m- u
} </FONT>2 O. Q+ q  v( p1 _$ V; R
/ v3 g+ M2 a; a9 E
</P>
. E) M7 E3 y( [6 V# ~. f<P><FONT color=#ff0000>函数名: gotoxy </FONT>
) u, A  k5 U% w6 P) p  V功 能: 在文本窗口中设置光标
6 c$ V& l9 ^8 z6 C; A& z+ Y8 y, P用 法: void gotoxy(int x, int y); : \# ~9 M1 M/ K
程序例: </P>
+ C% j  Y0 B9 g* [5 s3 d; G4 w<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
8 l# X) F( w' w! F; J/ `  @+ S1 T<P><FONT color=#0000ff>int main(void) 7 J; {6 ?, ?2 \  }% b# l
{
: J- S9 {( d1 D8 Mclrscr(); . I  N+ w# m/ l* n0 V, q+ p1 ~
gotoxy(35, 12); / N+ [# e2 ?3 r, j- p8 [# l% A
cprintf("Hello world");
- H* r# K, l6 ]getch();
- u0 J/ S0 y( Q# K$ ureturn 0;
/ h" @$ q! U$ F2 K8 K}</FONT> + ?% T, K2 t0 b1 Y; T* \

$ Z# Z" z# ~' K  Q* n</P>
, _8 ]7 V2 L5 `<P><FONT color=#ff0000>函数名: gotoxy </FONT>* U  {/ J, V  D  Y8 m& }. \9 b3 T
功 能: 在文本窗口中设置光标
% G4 V  A4 Y, v( u/ |. S用 法: void gotoxy(int x, int y);
! }; d4 _# ~8 {! S. u5 U程序例: </P>. i" b8 Y" f  o2 d5 m$ x1 _. R( J
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
2 y: u5 W4 E( l! w<P><FONT color=#0000ff>int main(void)
3 x4 Q* j9 C) k' I{ . U. a4 n; o* X( i. R! ^
clrscr(); : e( _2 a) F& ~
gotoxy(35, 12); 4 @2 w! W# G  o, X
cprintf("Hello world"); 7 L, H( a( H) M. ^1 l4 Q# [& _
getch();
( N2 R' |% P! h$ Q8 Q7 G5 y6 preturn 0; * _; C; D  `/ S. n* \
}
7 u' [. `8 K5 X1 [# \</FONT>
) x3 T% ^: b$ U0 C$ M2 U* F( t</P>
' Z0 }+ O( H6 m) u* ]<P><FONT color=#ff0000>函数名: graphdefaults </FONT>3 @  N3 ~0 y2 A3 h& V( C
功 能: 将所有图形设置复位为它们的缺省值 8 H/ d' C+ A" X; s
用 法: void far graphdefaults(void);
# h4 k  Q! P5 K程序例: </P>
. P1 O) D" `. [  `$ O! x2 |<P><FONT color=#0000ff>#include <GRAPHICS.H>2 p% c3 Y: T5 z$ j6 e
#include <STDLIB.H>( ?  U2 M$ c2 F1 p
#include <STDIO.H>; D/ u0 p  s, `
#include <CONIO.H></FONT></P>
+ f" @, C) K6 H# a) G4 n% Q<P><FONT color=#0000ff>int main(void) " I6 m6 P6 a* E% h8 @" N; C
{
. w0 @3 K- `. a6 G, `/* request auto detection */
! W+ l2 P/ B) q1 S- j& N! x4 ]int gdriver = DETECT, gmode, errorcode;
4 t0 B. d: f: U  A* |( [$ Iint maxx, maxy; </FONT></P>+ U5 i7 x6 ~* _0 i1 `' J' B& W8 k+ U
<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 f  O$ ^% e% zinitgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>4 s& |  H+ v4 b% Y! o
<P><FONT color=#0000ff>/* read result of initialization */ : J4 A# U3 j* l- I
errorcode = graphresult();
. V' U( h, _; A* N( @& P1 @* {4 oif (errorcode != grOk) /* an error occurred */
7 n* X9 Y0 b0 ]{
+ @9 N" N) r; d; I/ ?& ]; `printf("Graphics error: %s\n", grapherrormsg(errorcode));
& r5 @3 j# D. P: J# Mprintf("Press any key to halt:"); * k0 R. o9 f, F! X7 ~
getch();
( C" H  j8 A. a$ {* Z) v2 E  Hexit(1); /* terminate with an error code */
/ U8 ^, M: q  i9 g! g, p4 }, Y} </FONT></P>
! U* e0 }& _: R/ A" d9 y<P><FONT color=#0000ff>maxx = getmaxx(); $ E. X/ |9 q( D' i
maxy = getmaxy(); </FONT></P>
+ m5 D7 V* m2 Q& X* R<P><FONT color=#0000ff>/* output line with non-default settings */
3 l! h2 C) P" t+ T3 ^, h) ]$ ysetlinestyle(DOTTED_LINE, 0, 3); 4 h+ m- ?6 n" h
line(0, 0, maxx, maxy);
4 l  [+ e5 ^3 a  Youttextxy(maxx/2, maxy/3, "Before default values are restored."); # W1 ?$ ?( r2 y: Y- M9 e' e
getch(); </FONT></P>
) O& X* a! H% Q: D( Z# r# I<P><FONT color=#0000ff>/* restore default values for everything */ 2 }% o- ]3 y) A! c/ [/ l9 f
graphdefaults(); </FONT></P>
* Y2 P8 z2 q5 @% a<P><FONT color=#0000ff>/* clear the screen */ $ q! b  r1 d7 S0 e: M' w* F
cleardevice(); </FONT></P>+ I) O' w  B# P) U
<P><FONT color=#0000ff>/* output line with default settings */ 3 j" Q% X/ O; Q& p3 F% O
line(0, 0, maxx, maxy); 8 F5 A- N# u6 I" e
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P># k5 N% `% B) M2 w" z
<P><FONT color=#0000ff>/* clean up */ 3 U1 k; E$ @! Q5 a7 D2 w
getch(); 9 [8 A- G0 Y; g9 N1 ^
closegraph();
$ a9 ]+ U5 ^: ~3 freturn 0;
$ _3 z6 N8 y2 c7 q% P}
+ F1 M" I7 v! u: I</FONT>& E5 r6 T1 n, H
</P>
+ u- o/ d% [9 K<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>. `- A9 m% u# N- J
功 能: 返回一个错误信息串的指针
+ V* H. y# }# t% C: J2 b用 法: char *far grapherrormsg(int errorcode);
4 y& f# o& ~& m" i# a; J0 |程序例: </P>
! }9 A6 x" X7 y2 P2 Y0 |<P><FONT color=#0000ff>#include <GRAPHICS.H>6 _9 f; L* b+ f0 j
#include <STDLIB.H>' Z8 ^& ^/ r2 m! `$ s, _
#include <STDIO.H>
" V/ d' P9 T) I! u3 f- D#include <CONIO.H></FONT></P>
" A; }* F; K& b+ a6 W; o<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
3 E& Y* `/ I6 k9 r. L0 [<P><FONT color=#0000ff>int main(void)
( X" |% R8 K+ {3 X/ Z4 ]{
- L+ J' q( u6 M) X7 H* T/* FORCE AN ERROR TO OCCUR */
2 E' Q3 M# ?" C- W6 Z" Iint gdriver = NONSENSE, gmode, errorcode; </FONT></P>1 W# V/ s5 i7 B7 T! S* L+ j  Y- V
<P><FONT color=#0000ff>/* initialize graphics mode */
" w9 T/ k3 s7 _4 w& a9 X3 ~! @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 H# [0 I9 W/ E  L/ l. O/ a' k" ?! o<P><FONT color=#0000ff>/* read result of initialization */ . @% v+ S6 B. _& w# S2 E
errorcode = graphresult(); </FONT></P>
! R0 _" _$ L" U# P1 o: G<P><FONT color=#0000ff>/* if an error occurred, then output a */
* S) P2 L0 Q* ~) Y' L/* descriptive error message. */ 2 Z, w4 ^+ y# L" a% t
if (errorcode != grOk) - ^! E- R+ q( v5 ]% D  q
{
/ f, V: K. ?0 w0 R2 D0 I& v- Eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 ?6 [% t8 b; a( bprintf("Press any key to halt:"); + O0 k7 d; N) @. V8 [( p
getch();
$ Q  o# [- k  Z( sexit(1); /* terminate with an error code */ ! Q  C3 S$ o$ @5 Y/ F0 w& r) S
} </FONT></P>
  Y, A- g9 v. q! q<P><FONT color=#0000ff>/* draw a line */ ! D* E6 X1 l$ _4 i  J! q
line(0, 0, getmaxx(), getmaxy()); </FONT></P>  B+ L* w9 X' t! y  i! m5 R5 }
<P><FONT color=#0000ff>/* clean up */
9 f- s& s# w$ d. O% t' ]! |getch();
2 n) W) T4 F5 O0 t5 u# Y1 tclosegraph(); 5 [) M) b1 V( u& t& e  j) O5 K. E/ h
return 0; # N8 D) Q, B$ B/ L1 w2 h2 ]
} # P0 v2 T5 p) d3 s$ Q. W6 R
</FONT># T0 ]8 W# I( {- |! O" h" D
</P>
1 ?' q/ F$ F/ ?/ `  S: L<P><FONT color=#ff0000>函数名: graphresult </FONT>
+ N, h4 Y2 G. I6 B, V功 能: 返回最后一次不成功的图形操作的错误代码
  d) ]0 w; n% y; x+ e- x! q用 法: int far graphresult(void); / Y) M5 i1 C8 p. y6 d
程序例: </P>. g: z( E" V% }8 u1 B4 I( \5 i
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ M* W; W. i' l5 T$ ]#include <STDLIB.H>9 Z  v/ a- _# ~- D4 b3 g; w
#include <STDIO.H>: r2 H$ V1 U- S4 c' c* v. H, x) j3 I
#include <CONIO.H></FONT></P>* X' p: f: V4 {$ R% H
<P><FONT color=#0000ff>int main(void)
9 t% u) I% P; p* A. x3 n7 b{ & f! z4 J% y- x  N$ ^9 g" j. n
/* request auto detection */ 7 {4 G. X5 p1 t- U' P# O
int gdriver = DETECT, gmode, errorcode; </FONT></P>
$ Y1 U% E: t6 s; I) {: K<P><FONT color=#0000ff>/* initialize graphics and local variables */
( e, n+ K( ^6 [1 S8 @% ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># D0 a# `) ]* f2 [/ }, a
<P><FONT color=#0000ff>/* read result of initialization */
/ [2 D* }7 h5 Y- O/ O/ e& a% Xerrorcode = graphresult(); </FONT></P>
9 [/ a9 c2 v9 j" A8 b0 G' E% E. n" X<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ * n$ B! m4 C) N* d: s- [
{ 3 }5 P% ^  i. m$ |8 W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : w3 O* N& ^6 G
printf("Press any key to halt:");
& i& ?: v" T0 {0 p# T6 s1 r0 pgetch();
9 X+ x' l1 j% Q/ N8 Jexit(1); /* terminate with an error code */
' i6 Z+ u* ^- n} </FONT></P>
- z7 L4 R& M3 @, g3 N<P><FONT color=#0000ff>/* draw a line */
- d* a% I) A4 p" S8 J* P1 U, rline(0, 0, getmaxx(), getmaxy()); </FONT></P>( q+ D4 h: |& n
<P><FONT color=#0000ff>/* clean up */ . L. M. E; P# ?6 K+ ^
getch();
9 B. D/ E8 e  P1 nclosegraph(); , v* V8 H0 Q2 K5 V
return 0; + c8 q* Z/ P/ K
}</FONT> & D% }8 a7 _4 u6 q5 r7 _
</P>0 V5 j6 p% u. N9 I* y
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> * S% x4 z5 m' [
功 能: 用户可修改的图形存储区释放函数 % }: L7 ~6 C9 d4 I
用 法: void far _graphfreemem(void far *ptr, unsigned size); 9 _3 Q; F2 q/ V. C
程序例: </P>& K' B8 ]+ i! G6 W% F* U- C" p
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 J! }) ]+ K8 H( @. g8 l( ^2 Y
#include <STDLIB.H>
+ G- J3 V) V, m% y( Z8 ]#include <STDIO.H>
7 h* E5 \+ e$ |#include <CONIO.H>4 [, k! q2 |9 r9 E( H# i* k
#include <ALLOC.H></FONT></P>! g* C) G; z( N1 K( c
<P><FONT color=#0000ff>int main(void)
" x7 L3 m+ f/ Z) {' l% }) v& H{
2 g9 I! ^9 x2 U  g1 V! _. b/* request auto detection */ ) K* R  F0 n% R# s, _% b( M
int gdriver = DETECT, gmode, errorcode;
7 ~. I( l& Q6 g8 r( H+ j4 eint midx, midy; </FONT></P>
; e$ d& M4 D; E, o& S& u* g0 @( k<P><FONT color=#0000ff>/* clear the text screen */
! K5 q: Z4 H) j1 M; |+ H8 ~) Oclrscr();
) B% [4 F! D1 s2 v. S, pprintf("Press any key to initialize graphics mode:");
# ~' Z5 a3 P' rgetch();   M' b* m: N8 _, N- a
clrscr(); </FONT></P>  O6 k2 V8 W4 X) \, k; c/ [
<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 T' ]1 B0 |, [0 L# xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 P1 y( Q: y4 C* z% v) F
<P><FONT color=#0000ff>/* read result of initialization */ 7 j6 Z: r6 G# U$ e- _
errorcode = graphresult();
, L: z: Q6 H  S7 Aif (errorcode != grOk) /* an error occurred */
; L0 }. v! E1 V, ~7 o{
8 t% B7 P- u: H& z$ _) Vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
% E6 Q8 M' ]- }. q! F( ?' b+ ^& \) Iprintf("Press any key to halt:");
7 j& l; R* c/ Z4 F3 g/ ^getch(); - b" X3 a; c0 a" ^: `2 j: t
exit(1); /* terminate with an error code */
1 v1 Q, X$ r$ @' O$ y& M} </FONT></P>) \  G" j: R- n! n0 Z& k3 u3 g, d
<P><FONT color=#0000ff>midx = getmaxx() / 2; - `) C- G3 O4 `! b+ q
midy = getmaxy() / 2; </FONT></P>
8 J: ~# L' c7 V/ L: x* Q<P><FONT color=#0000ff>/* display a message */
' z- F# i" e% p; H4 Q3 Nsettextjustify(CENTER_TEXT, CENTER_TEXT);
) U: c2 {4 Q, jouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
% j$ a: ~) {  w0 F<P><FONT color=#0000ff>/* clean up */
7 ~2 i' @0 [3 H$ [$ P- J% i; ?getch();
; N5 ?  j& H: g1 s- Aclosegraph(); . ~/ Q9 L( l# P! n# J4 B% a
return 0;
; a$ g* K. ~! u} </FONT></P>
. f8 X. F# i9 U6 H5 ?8 b3 c' h<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ ( C' R- @+ {6 b- [" H$ A! l
void far * far _graphgetmem(unsigned size) & p5 o/ J; l1 t! f% V; a" y" T
{
8 O# n( {8 K2 {3 |printf("_graphgetmem called to allocate %d bytes.\n", size); + P+ Z* x. P  v# y' q: f  {6 T/ t( K
printf("hit any key:"); 4 o7 M- g9 G& L
getch();
6 i  e$ u0 k0 B9 ]printf("\n"); </FONT></P>
* w* R/ f" s; ~% G3 ~  y" N<P><FONT color=#0000ff>/* allocate memory from far heap */
- w* m  j% L) |7 E) rreturn farmalloc(size);
0 O. A* y# r; H% W4 a2 J} </FONT></P>
% \( \4 i  n8 V: P<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
- C1 C# p( ^( Uvoid far _graphfreemem(void far *ptr, unsigned size)
) n5 X, ~* B  f( Z) s2 R* J{   G; |% w5 y" l, @. {1 e" m" ^' f
printf("_graphfreemem called to free %d bytes.\n", size);
& D- B1 a& m, o8 R! ]: Nprintf("hit any key:");
* |. C5 ~. G/ [3 t3 xgetch(); ' `# m+ \8 Y8 e) Q
printf("\n"); </FONT></P>% t% b) J; L' O. W
<P><FONT color=#0000ff>/* free ptr from far heap */ 8 \) [4 |( V( J# |' A/ H
farfree(ptr); 3 M$ D3 V+ j* [8 z9 x
}
7 ~5 V! F$ C6 e6 {8 T</FONT></P>
7 R; p7 [! g  e2 w+ L' R. f+ R<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>5 L% ?: G/ _' X# p" N% g1 N4 J  l
功 能: 用户可修改的图形存储区分配函数 + C+ @/ T& ]) j, }4 v
用 法: void far *far _graphgetmem(unsigned size);
. ]( b. n( ?2 j4 d) U' i程序例: </P>8 f4 U% r' ~  B/ @- Z
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  i% F* s2 Y5 h. T#include <STDLIB.H>1 v! `; `1 \. g, a. i
#include <STDIO.H>
0 Q3 D; p  x' H3 L! `- g! Z#include <CONIO.H>
% Z* ~0 }: _2 N& `* ~#include <ALLOC.H></FONT></P># K* Z6 C# {- R$ J% o7 e
<P><FONT color=#0000ff>int main(void)
  p+ Q$ ?, s  R3 C: N& s{
( [' L5 h. u% T- f) @0 X5 L# }, m9 s/* request autodetection */ 8 _- r4 c0 ~6 x* w
int gdriver = DETECT, gmode, errorcode;
8 r0 e) T* {$ L5 C+ Fint midx, midy; </FONT></P>/ Y7 s( A* h0 N  B4 t7 n1 O
<P><FONT color=#0000ff>/* clear the text screen */ + W8 C, u( B7 c/ u/ e' J1 ?
clrscr(); 0 }: @$ T  U* h6 B
printf("Press any key to initialize graphics mode:"); ) @% u4 F" e1 t0 ]3 q
getch();
3 M( X- ?  p  o7 Z1 n: Y/ rclrscr(); </FONT></P>8 f+ r5 U3 n' f9 `
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 J3 l5 M9 D2 p$ U. e
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 L0 c& x/ m' x" _; o" [% M7 y! u
<P><FONT color=#0000ff>/* read result of initialization */
! h8 K( O& ]/ n6 eerrorcode = graphresult();
$ i5 A* A& Y& Fif (errorcode != grOk) /* an error occurred */   ^8 u8 b. I/ h2 k( V; c
{ % ^, l" o2 g- j
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - p/ y/ S, `2 ~; r6 a
printf("Press any key to halt:");
- y' ?+ Y3 ?) `: J% Ogetch(); ( ^: j3 o' D- O/ m
exit(1); /* terminate with an error code */ % H" Q2 w" a9 @8 u3 ~$ q  q
} </FONT></P>4 }4 |) s7 n: F' r1 T; t$ c# u; @
<P><FONT color=#0000ff>midx = getmaxx() / 2; " ^, T& a1 u  p2 [
midy = getmaxy() / 2; </FONT></P>6 T, j1 W$ m* z5 V8 ^
<P><FONT color=#0000ff>/* display a message */ : r7 M' i2 P" K: l) p
settextjustify(CENTER_TEXT, CENTER_TEXT); # `  V0 b0 Y  G
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
; C3 I  e0 G& G! v7 C5 U: _<P><FONT color=#0000ff>/* clean up */ - [' {/ t3 X% K1 w
getch();
7 U0 ]; [8 ]' B) y( X+ oclosegraph(); . }' F  |( ?# w
return 0;
/ Q) A  f. s/ s* T& q} </FONT></P>
6 a: w3 j% T# D4 z<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
' R. c( w4 e1 U6 W4 ~7 t2 Qvoid far * far _graphgetmem(unsigned size)
& e( P! _$ ?9 B0 Z1 o{
6 @9 }8 j/ [/ n. ^printf("_graphgetmem called to allocate %d bytes.\n", size); 6 c  V* X! q  [+ K1 l+ q7 c
printf("hit any key:");
, w/ i; f% u" }/ E* w6 }getch(); : j  _6 p" d* U: }# j
printf("\n"); </FONT></P>
6 ]5 t3 m, o9 D! b<P><FONT color=#0000ff>/* allocate memory from far heap */
2 F. U9 W0 D* P+ w+ _8 [# {return farmalloc(size);
8 P% A/ N# z  j2 Q% s} </FONT></P>
2 g' {" P1 q& J2 d4 f' L3 W<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ . E3 {. p: ^  T* _5 {4 u
void far _graphfreemem(void far *ptr, unsigned size)
, x9 n0 w( g/ m$ p# I8 l- @3 s9 W{
9 O6 a9 e% r% \2 v1 \  Gprintf("_graphfreemem called to free %d bytes.\n", size);
+ q; Q/ s- q" F: Hprintf("hit any key:"); 1 `( \1 Y) d. _- G
getch(); $ S) Z8 b' ]& H7 i5 G6 I5 [
printf("\n"); </FONT></P>  |6 s& l- m. G. ^. m
<P><FONT color=#0000ff>/* free ptr from far heap */
) v0 ]' H$ l) P8 v# j$ u- _+ E: Wfarfree(ptr);
+ `( n, ^- A. h% A, J0 l}) n) q& V  o  S
</FONT></P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5