数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:00
标题: 函数大全(g开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(g开头)</FONT></B></FONT></P>
2 V) \* |$ q- M7 s: b/ u4 I
+ d+ s% A8 W) P3 t- J% [# L) Z( _  f+ W3 X- x- A1 I
<p>* y; i' T) L5 m1 T0 b. d
<><FONT color=#ff0000>函数名: gcvt </FONT>
2 k, B9 \/ i4 X( G, Y& k功 能: 把浮点数转换成字符串
/ y* C+ z, v5 G1 I用 法: char *gcvt(double value, int ndigit, char *buf); 0 R6 p! [* }4 g( j  U( N# s
程序例: </P>9 v8 K8 [7 ?9 n# z& X2 m* X$ I
<><FONT color=#0000ff>#include <STDLIB.H>4 [, _3 A. x4 z2 B& @7 c9 p, h2 g" M3 b* @
#include <STDIO.H></FONT></P>
( M- T  z. Q, W0 b! }<><FONT color=#0000ff>int main(void) 0 v3 a$ ]+ T  J6 h; @3 m2 B3 R
{
1 o( S, d: a" h+ E- ]  _% Lchar str[25];
; Z$ A' \: j  a* zdouble num;
! f: v( b7 S" x  Fint sig = 5; /* significant digits */ </FONT></P>
8 n4 c$ l8 h; @+ Q/ R. N7 j! f<><FONT color=#0000ff>/* a regular number */ # n; C2 ^- ]0 L: G% H
num = 9.876;
  I; O9 ]! c. Y  G7 G" agcvt(num, sig, str);
) p! _: J* x9 w6 r& Uprintf("string = %s\n", str); </FONT></P>
' ~- U+ C3 p( A. `<><FONT color=#0000ff>/* a negative number */ . _8 Z7 p& n) W/ a; C
num = -123.4567;
! W: f% S. r5 ^4 y4 qgcvt(num, sig, str); / z" P5 O4 t5 L% Q" H. V
printf("string = %s\n", str); </FONT></P>
& ^; k2 i2 S# T8 m1 D5 g<><FONT color=#0000ff>/* scientific notation */ + Y: R4 ^7 S  D* y4 u
num = 0.678e5;
4 P& z. |+ f5 S& B  e. P* |7 [- P7 ngcvt(num, sig, str);
0 a* M4 V2 ?& Uprintf("string = %s\n", str); </FONT></P>: i- S5 J' ?2 M7 {$ \
<><FONT color=#0000ff>return(0); 7 M) g  _( E" F1 P* t. d: O
} : X# C  w2 n( `7 n, U

+ V( Q7 A. X9 Z, A</FONT>
* q; p& ~9 Z+ M</P>
' }$ ~4 V# h/ i1 u$ n<><FONT color=#ff0000>函数名: geninterrupt </FONT>, }( L$ E: z& D" H2 G
功 能: 产生一个软中断
+ o6 j& I) e/ v0 d用 法: void geninterrupt(int intr_num);
/ Y8 V+ T8 k0 y5 }3 r, R程序例: </P>& Y- L; m; K* G
<><FONT color=#0000ff>#include <CONIO.H>
) s  {4 }. h% V3 }+ R  y8 i6 U#include <DOS.H></FONT></P>2 o& E) v9 s5 |; f0 b& p7 a! I6 d
<><FONT color=#0000ff>/* function prototype */
1 ^, e% l9 L9 a. Y+ f: ^& Tvoid writechar(char ch); </FONT></P>6 a! L' i0 \; h7 f) l3 R1 H+ D
<><FONT color=#0000ff>int main(void)
4 R3 ^- {; M- Y/ c$ d+ d{
0 L0 \' z  x8 O+ cclrscr(); % s2 v% l! C+ Z6 w- R
gotoxy(80,25); / a! Y$ p) R, n. x7 O' A  t
writechar('*'); & d, C6 t1 s. M0 h& m; X
getch(); + g' R- {0 s; E3 H7 W/ I
return 0; 5 r5 l& A% h8 L. E
} </FONT></P>
3 V1 w: d8 x' v9 Z<><FONT color=#0000ff>/*
6 o0 z( K( J5 e; v  doutputs a character at the current cursor
, X) j1 E# {0 ^2 zposition using the video BIOS to avoid the * E1 G+ r- C. |+ U
scrolling of the screen when writing to
6 Z* z8 K& T# S" c- q, o  l" Llocation (80,25). & [- J; @- |) g# q; B9 b
*/ </FONT></P>
+ ]' j$ K$ X3 n/ t! x1 @<><FONT color=#0000ff>void writechar(char ch) 9 q3 o" j  U4 S% j# |
{ 7 t% B8 P5 u5 ?( {, @0 G; u2 o
struct text_info ti;
- P: ^' x, o8 J/* grab current text settings */
8 ^3 P  [" W( r- z1 x4 |gettextinfo(&amp;ti);
% t& u4 k1 f5 s; f( n/* interrupt 0x10 sub-function 9 */
, m, k9 F3 L& o0 D_AH = 9; " w1 m/ P: X- _: a2 r
/* character to be output */ & n* J$ B$ T% a4 |
_AL = ch;
) z& d6 t# n( y- x" |. J_BH = 0; /* video page */ ) D- \# q* Y! N& s. ?# u
_BL = ti.attribute; /* video attribute */
' ?3 _4 K6 ~5 j& M* a1 W0 q. b_CX = 1; /* repetition factor */ * r) _9 H+ \; `
geninterrupt(0x10); /* output the char */ 3 @7 x5 d5 b# f# u# a3 q
} 3 A- A1 o' ?- c
</FONT>
* F8 K7 s( N2 n0 n. I</P>
2 k3 K7 R( Q2 S+ w7 v<><FONT color=#ff0000>函数名: getarccoords </FONT>
. q  U" E$ L( W+ w: \功 能: 取得最后一次调用arc的坐标 % B$ t( |# [0 i$ H/ p8 A. h
用 法: void far getarccoords(struct arccoordstype far *arccoords); 9 \6 m: G3 C/ o
程序例: </P>
# n/ U/ S% [8 p3 H6 I& d. I" E  z<><FONT color=#0000ff>#include <GRAPHICS.H>
3 X* B+ ?  |& g/ r& x- _#include <STDLIB.H>! [1 d, ?' {, S7 S7 N
#include <STDIO.H>+ m: E7 V# ^3 l8 C' k! C6 I
#include <CONIO.H></FONT></P>
1 L& H% E# x1 f6 v+ Q# H<><FONT color=#0000ff>int main(void) 2 |# ?; ]" P& V
{ 8 z4 o+ ?' v, V0 _% m
/* request auto detection */
- N) a$ F$ G: j7 R& Iint gdriver = DETECT, gmode, errorcode;
6 @. C% D# a7 ?6 ?: Q3 Ostruct arccoordstype arcinfo; ; F5 N7 f+ I) B& Z- ^
int midx, midy;
% Y. T9 R, S6 s- j: Y1 hint stangle = 45, endangle = 270;
5 y# x* V+ w) zchar sstr[80], estr[80]; </FONT></P>
4 w, y- M: H; c9 o0 S# v; \<><FONT color=#0000ff>/* initialize graphics and local variables */ 3 Q6 z9 Z0 j, ]: L. r& C$ H1 H
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( y+ c, m' V% o
<><FONT color=#0000ff>/* read result of initialization */ $ K0 q6 t$ O' R0 @( V! }
errorcode = graphresult();
: M# T# |. p2 X1 q  ?3 j/* an error occurred */
: S+ v: a( v6 Q: I4 }9 t" Bif (errorcode != grOk)
% M$ L9 M  e: w. S" i( ?4 O" Y{
  S. I8 A9 _' ?( V. q- v: Jprintf("Graphics error: %s\n",
6 H& C" |( O# @grapherrormsg(errorcode)); 0 z& k) C& K6 l, a- g0 i% H& w$ P
printf("ress any key to halt:"); + T( E) h9 j3 O5 g
getch();
4 x# t/ o" A7 l/* terminate with an error code */ + T. q  x1 I/ r
exit(1);
- y$ [) y3 g+ a9 j' x+ Q} </FONT></P>
/ {# r" x4 G# b) W<><FONT color=#0000ff>midx = getmaxx() / 2; 0 {" k9 `8 n9 d% j6 j3 F, }
midy = getmaxy() / 2; </FONT></P>
2 l. `/ C- w* V0 Y9 l<><FONT color=#0000ff>/* draw arc and get coordinates */
8 f: t4 n8 L, r/ ]( C6 ^setcolor(getmaxcolor());
' a# F; w/ D" M% narc(midx, midy, stangle, endangle, 100);
$ f" b" m! D4 L, agetarccoords(&amp;arcinfo); </FONT></P>
( E; l# a7 G8 o9 V5 B. Z! ]<><FONT color=#0000ff>/* convert arc information into strings */
: h# w, \9 t. n. {) C  x3 k+ \5 n+ esprintf(sstr, "*- (%d, %d)",
' V& I* t" [- G9 Sarcinfo.xstart, arcinfo.ystart); : g! ~' \$ g4 I% w  m
sprintf(estr, "*- (%d, %d)", ) }0 _7 ]1 W* w5 N7 S
arcinfo.xend, arcinfo.yend); </FONT></P>
6 |: q( T& ]. ?2 ~; i4 j<><FONT color=#0000ff>/* output the arc information */ 7 R, b) v9 g" B
outtextxy(arcinfo.xstart, " {# c/ z: V$ V' y
arcinfo.ystart, sstr);
% d0 e8 |  B+ y" w* G0 routtextxy(arcinfo.xend,
) P, M, T* d, G& V* Z# Q  z, aarcinfo.yend, estr); </FONT></P>
) z% P4 U" H  q# v1 S<><FONT color=#0000ff>/* clean up */
: D% t& G/ M' P3 Bgetch(); $ W5 n7 _. `0 N7 M' v2 d, O' `
closegraph(); 8 S  l# b* u/ m( ]6 p9 j; ~. i
return 0; ( _$ P% Y4 @: l+ M" U2 I; a
} ' Z2 C! M/ b4 h4 O4 M  `
</FONT>
6 P; F5 C0 ]) ]- |& D7 c( k$ _5 J$ H
( z& @. d$ Q- L) m# d7 D</P>+ L, C3 d* n! T; u8 O' {
<><FONT color=#ff0000>函数名: getaspectratio </FONT># R( W+ @( E: V  z" z2 g0 k$ q
功 能: 返回当前图形模式的纵横比 / D) I# \; `8 K
用 法: void far getaspectratio(int far *xasp, int far *yasp); - D  p8 `' l9 }9 m
程序例: </P>& T+ p6 c- H: [* U& L
<><FONT color=#0000ff>#include <GRAPHICS.H>
: L$ X: o9 I9 B, h/ @0 \#include <STDLIB.H>( {9 ]! F/ t7 O
#include <STDIO.H>
+ a  J$ v6 |3 t8 f#include <CONIO.H></FONT></P>1 k: t1 u( t0 G, \) \. h
<><FONT color=#0000ff>int main(void)
, Z$ R1 t5 a8 W9 y8 ?8 C2 m* }{
5 s, ]3 ]8 A: ]& t/* request auto detection */
4 T' \7 Q3 \: _& xint gdriver = DETECT, gmode, errorcode;
/ C$ a# `' X8 s/ W3 Qint xasp, yasp, midx, midy; </FONT></P>+ @! ~( u( j* t  I
<><FONT color=#0000ff>/* initialize graphics and local variables */
+ }; b9 B! s" m$ S- L2 z' s( }initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 S- ]0 O' J8 j! p  {  ^
<><FONT color=#0000ff>/* read result of initialization */ / W8 z) z: z5 G* e
errorcode = graphresult(); % O6 ~) o& c+ @. `
/* an error occurred */
6 l" ~) Z9 {- Z$ r, H9 g: h$ nif (errorcode != grOk)
% j8 E9 C& K. [8 L. K5 v{ 5 M, q+ u5 h: ]
printf("Graphics error: %s\n", 4 L( c+ e! C; K0 X
grapherrormsg(errorcode));
6 {# R3 p  d4 _# B/ ~; H% q, wprintf("Press any key to halt:");   M2 U) j+ @6 O, g3 x# d
getch(); - S- V# S9 y. Q
/* terminate with an error code */ . B/ @" H! v& }9 b
exit(1); 5 a8 M# Y& X% B! _. c
} </FONT></P>
' t% Q, J$ L, q3 f<P><FONT color=#0000ff>midx = getmaxx() / 2; # F9 C: |: n0 Q8 z
midy = getmaxy() / 2;
% I, K2 d! B: _* n% t: e; k9 R$ u6 E5 hsetcolor(getmaxcolor()); </FONT></P># E& D9 K+ _9 c" i+ r
<P><FONT color=#0000ff>/* get current aspect ratio settings */
; ?8 a6 g1 L9 b" Sgetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>0 v, e5 V) y0 m0 j$ l% _
<P><FONT color=#0000ff>/* draw normal circle */
7 \! U1 Q/ S8 u7 ]) ^circle(midx, midy, 100); ( o/ w1 h2 y4 o$ q4 w) w
getch(); </FONT></P>4 R* u+ i2 @( I# m  Z* c
<P><FONT color=#0000ff>/* draw wide circle */ * x3 Y! P2 v3 ?3 l# C
cleardevice();
9 R, c' U3 ]$ L& b8 \, v0 \1 r1 Dsetaspectratio(xasp/2, yasp); / N4 Q6 K0 l5 G6 i0 M% ?% K: B
circle(midx, midy, 100); 5 G% F. p5 o- Y# g1 e# F
getch(); </FONT></P>
1 M6 e' J( n* ]2 Y; ]/ w<P><FONT color=#0000ff>/* draw narrow circle */
- v3 ^) [- ^& r* t3 o' @cleardevice(); " l. \4 U) f% j4 t+ D& L
setaspectratio(xasp, yasp/2);
6 A) M8 J3 t  `circle(midx, midy, 100); </FONT></P>: o$ _' W* x2 C: w9 T
<P><FONT color=#0000ff>/* clean up */ & |8 s1 H& s% \
getch(); 1 S! J- g. R! i$ a& U
closegraph(); 6 x) c+ V1 f& b8 C% K7 }" O
return 0; * L, [  p* g; f
} 7 j9 C4 K& i4 i
</FONT>
, S" h/ T8 L  b. `
6 a& K! ]7 E) }: K( \, h</P>3 s0 V; W2 l0 k  B5 `
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>9 w# j7 D0 ^9 A' v
功 能: 返回当前背景颜色   C6 ?; x$ t5 P* F; J" _+ ^
用 法: int far getbkcolor(void); + l  ]* I8 q3 Z1 k5 i
程序例: </P>; k0 i0 l( g; ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>! a2 b" {6 j: u
#include <STDLIB.H>7 U. }# ~: a- z0 Q- t3 I0 ]2 g
#include <STRING.H>- D: c) J  ?# w9 \9 d. r9 R
#include <STDIO.H>! c5 Q7 u$ P5 a2 Q
#include <CONIO.H></FONT></P>" A! r$ `" r! x7 g* a2 u
<P><FONT color=#0000ff>int main(void)
% A$ F3 ^9 y' c4 P/ }/ j{
  B; q; P% Z8 h3 C( J2 ?5 k! ~/* request auto detection */ . W; k- D, i- M
int gdriver = DETECT, gmode, errorcode;
9 P& E, Q; {9 s" q9 kint bkcolor, midx, midy; % c. f5 U9 i( z  W
char bkname[35]; </FONT></P>
" p( |. z( W, H5 {: W: S5 T<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 m* }2 q% C3 c3 D3 e# ^/ K9 ^5 yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 j0 Y* V. |$ W/ e<P><FONT color=#0000ff>/* read result of initialization */ 3 u6 L$ V6 N3 k% F$ {5 ?
errorcode = graphresult();
9 P8 m( K, r" l) K* O1 w8 h4 t* z/* an error occurred */ 8 L  z7 f! O4 g( x7 h
if (errorcode != grOk) 7 Q$ f% O# W! f$ Q# o7 o
{
' o* g2 |. G* R/ ~' e+ z# @0 W' Sprintf("Graphics error: %s\n", ' e- p( `, o0 {. W4 z
grapherrormsg(errorcode)); ( w( P* q6 x, D2 C
printf("Press any key to halt:");
: ?2 C4 [- o: T  `6 i, ggetch(); 1 H& p! _# [9 Y4 j8 M
/* terminate with an error code */
3 H& z' G% t6 G, B+ nexit(1);
4 g6 J& l2 h  B6 @4 k} </FONT></P>
& P" J/ {% k$ {9 b  X<P><FONT color=#0000ff>midx = getmaxx() / 2; - W3 F1 N; b0 {5 H/ V4 R! y
midy = getmaxy() / 2;
  u" _& K  F/ T! E, C. J3 Osetcolor(getmaxcolor()); </FONT></P>2 c9 I8 ?# I( g; l4 H3 Y3 N- N9 T
<P><FONT color=#0000ff>/* for centering text on the display */
) m8 y9 W+ T6 n" Q4 N% vsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>( p+ j; n5 z6 T3 |% b5 Y
<P><FONT color=#0000ff>/* get the current background color */
$ ^6 j  o( _9 l3 i$ n$ k2 Z* Wbkcolor = getbkcolor(); </FONT></P>
& u" r+ w. N" d8 d6 {<P><FONT color=#0000ff>/* convert color value into a string */ 4 |$ C- l) ]* }7 h
itoa(bkcolor, bkname, 10); 6 p1 J& m' P( [  i5 M
strcat(bkname, * q8 O9 S0 a6 w' n  L) J! i
" is the current background color."); </FONT></P>
7 c! C; D3 c/ |6 F3 K<P><FONT color=#0000ff>/* display a message */ 1 Z1 i- V  _# H) N6 y9 Y
outtextxy(midx, midy, bkname); </FONT></P>
+ N. W" f6 q; e9 k* ~<P><FONT color=#0000ff>/* clean up */ 1 C. G% H# J, u: Z
getch(); + [) x/ b# |. Y, p, K
closegraph(); $ t0 v9 p8 b, ]/ U3 e) W
return 0;
! o$ B% {8 D, I4 ]}
  v7 Z! V- i& M! H8 X
; h7 E4 Z1 a. B- F. X! i' z</FONT>5 K) J4 x! D* Y1 ~, g; P$ o
</P>
2 N" R% a: x; M, E* B<P><FONT color=#ff0000>函数名: getc </FONT>; G; F$ h3 P  d; q
功 能: 从流中取字符
- t" t% U  |$ m( ?8 j2 P/ l: x( K) u用 法: int getc(FILE *stream);
; c1 @4 V8 k* Y' ]程序例: </P>
' V" d2 \1 C4 K4 G" O+ Y: U<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
6 r& J# s1 e2 G5 `<P><FONT color=#0000ff>int main(void)
, r6 D7 M9 C' |' j3 r- q{
4 R3 j3 X1 W5 g+ g! ^char ch; </FONT></P>
8 P. Y3 X; A) p. n  l. k- X' y5 q! n& X! x<P><FONT color=#0000ff>printf("Input a character:"); ) c  R; B  C# n( E$ b) M
/* read a character from the
" H0 }* x7 h' @1 I, Gstandard input stream */
0 v; E$ o3 J5 q- Hch = getc(stdin);
( e+ s( f+ z7 I/ m: u7 B/ \/ ^+ Yprintf("The character input was: '%c'\n", 5 R7 e" T7 j! j
ch);
0 K) g2 ~7 ~; p& T4 R2 v2 Xreturn 0;
- p  q  l7 b: }+ }" Q}
  w' Z3 x9 s" H' E. [( ?& |: a+ X% `) }! A# p; c
</FONT>
' T7 H  ^' q7 w! `3 _% @</P>8 l4 |) w( c: P
<P><FONT color=#ff0000>函数名: getcbrk </FONT>
1 r& a& y% n' `& D/ R1 G6 Z功 能: 获取Control_break设置
, u) @; O2 p4 X3 n2 Z  D' k用 法: int getcbrk(void); & f7 }7 v+ z/ {) y3 d" W; N: O5 J+ q
程序例: </P>
! I; l* e$ ?( ]4 G) i% y. W<P><FONT color=#0000ff>#include <STDIO.H>
9 I! U3 p- q- t1 A  h#include <DOS.H></FONT></P>, b! b2 r' V& F+ ^) X
<P><FONT color=#0000ff>int main(void) ' t8 `9 Z" V+ x; W
{
8 v0 j; s# ~7 g7 i3 z& L& Fif (getcbrk()) 0 M8 V: |% J1 q! f0 r
printf("Cntrl-brk flag is on\n"); . r: l  w! e4 L8 N
else
+ r8 P& o4 O/ vprintf("Cntrl-brk flag is off\n"); </FONT></P>6 Q* r3 q8 y1 J# I
<P><FONT color=#0000ff>return 0; 3 \' d2 o2 \1 j* K! C) _9 \
} </FONT>1 B& ^9 [& g) |0 T! x+ H
4 c1 O9 c6 R9 e3 ?9 D
</P>$ d6 \; b1 r! s: a) f
<P><FONT color=#ff0000>函数名: getch </FONT>& ]7 H3 c6 T- h; y
功 能: 从控制台无回显地取一个字符 : k# p( B$ [/ i/ o( r/ m
用 法: int getch(void); 7 y' E4 j1 q5 j3 M. A
程序例: </P>" |; z' V% _- p) ?1 h& j$ S
<P><FONT color=#0000ff>#include <STDIO.H>0 a1 K9 O; p' Z% {7 U
#include <CONIO.H></FONT></P>
$ \. f9 T9 f6 L8 |9 o) v# m<P><FONT color=#0000ff>int main(void)
: H3 a. A/ X+ a/ g% n9 {$ L{
- ~1 x/ p& I/ N5 T5 @* W+ a  Mchar ch; </FONT></P>5 ~: Y. W$ N2 K. F
<P><FONT color=#0000ff>printf("Input a character:");
$ p' ^  ~  V5 v/ f# y& O- a* g, gch = getche(); 7 @' c: |3 L" b0 {; q: t6 l- x
printf("\nYou input a '%c'\n", ch);
8 }9 f: A2 ^- ^. W; wreturn 0;
) n6 W5 j1 ^; \: A/ o}
. B3 U# c& B7 x! L. ]
( U, f/ w+ h6 z4 Y3 o</FONT></P>
; O/ t, f$ b6 J# D/ v/ o; {0 I* t<P><FONT color=#ff0000>函数名: getchar </FONT>( L8 @1 y* O- Y) Y# p
功 能: 从stdin流中读字符 * K) Q* o$ q8 h9 M+ m
用 法: int getchar(void); ' V* w: Y5 k( G! ?3 y2 `
程序例: </P>8 U: `9 j2 n& S+ O
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>4 [$ k4 b6 X9 z! {
<P><FONT color=#0000ff>int main(void)
/ D0 H/ O1 v. a{
2 G3 r  g4 [9 dint c; </FONT></P># m+ ]9 I$ W+ g7 K' N% @
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and ; Q  [( Q; a, [0 e  c' J0 ~3 o5 p
is line buffered; this means it will - H0 V+ W: a# c0 T3 e2 M
not return until you press ENTER. */ </FONT></P>" f/ N$ v5 u/ r% o0 ]& ?3 ~/ l6 B+ b
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') % y- w8 F! `0 D3 x( |
printf("%c", c); </FONT></P>
& J# L, p8 ?0 [) B$ E" E$ }8 }, X: Y<P><FONT color=#0000ff>return 0;
0 z, m1 h  J& c  q: a- V}
1 c* o( m/ G) z</FONT>& X1 ]* L  ~) ~7 X& J7 U3 J9 M
</P>+ \( m1 o  F  _  H5 W
<P><FONT color=#ff0000>函数名: getche </FONT>
/ `  h* U/ I% C! R  v' b* ^功 能: 从控制台取字符(带回显)
" ?1 Y3 w% |' u' y; T. y用 法: int getche(void);
& \# R$ W, O/ G2 m# A/ E程序例: </P>
0 e4 }9 J" |. J  _( o6 N1 q<P><FONT color=#0000ff>#include <STDIO.H>1 r8 }( M, [+ x' T: j
#include <CONIO.H></FONT></P>
! f( K& E. W* k- y<P><FONT color=#0000ff>int main(void) / {; W- x/ k9 {0 l) a; v+ I. z
{
+ @3 o" P7 I# C2 s5 dchar ch; </FONT></P>  R$ y% s  e: D2 O
<P><FONT color=#0000ff>printf("Input a character:"); $ x9 P& |5 f/ m- `) X2 G, ^
ch = getche(); 7 R- Q5 K6 x$ y4 O! z1 H/ ?2 D
printf("\nYou input a '%c'\n", ch); # P3 M5 e) d) D) S3 G" S7 |% D' \
return 0;
/ {, g9 U" ~8 I% C( f}</FONT>
/ o# h" W2 ~, d9 v' R' [; \' A& v# ?( Y
</P>
# O. Z( |  H1 q<P><FONT color=#ff0000>函数名: getcolor </FONT>
+ L6 P' }+ S! R6 ~: t( d/ F功 能: 返回当前画线颜色
  A1 B% l7 b9 n" N, ?6 K0 r用 法: int far getcolor(void); " B% W; R4 |: B  C( }0 f
程序例: </P>, K" {9 o2 }+ ~( J3 V; b8 Y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 I& k7 g& q7 x- E5 n( \#include <STDLIB.H>( P! [: X: @/ l9 o2 ]
#include <STRING.H>
$ V7 {' r! B; D0 c#include <STDIO.H>
  k+ M0 H+ ~( j5 s+ n3 ?#include <CONIO.H></FONT></P>5 i8 j0 x6 x( T5 A( B
<P><FONT color=#0000ff>int main(void)
! M: R3 H4 `6 y4 b& R/ P, S( `& K{ 3 d+ M# j; z/ y, K
/* request auto detection */ $ ?1 B) {7 M4 E$ K
int gdriver = DETECT, gmode, errorcode; " c9 ~( a! D6 t3 f3 M! L
int color, midx, midy; ; _) g( ]* Q2 e7 b) l- y" g6 t
char colname[35]; </FONT></P>9 C( B" C% o$ T* s6 R6 {! K
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " a5 N) d' x3 v7 V& p
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  g# m" q2 n7 c3 @# b) M<P><FONT color=#0000ff>/* read result of initialization */ ; G' d- V1 V' F9 ~. m8 C
errorcode = graphresult(); ' k# j; }$ ~3 ^. o1 Q. n
/* an error occurred */
$ N3 [/ M/ Y) \- g8 p6 Mif (errorcode != grOk) 4 M  W5 w" N1 n, K8 n; t% J
{ 1 L. x; O( d3 \; R( Y
printf("Graphics error: %s\n",   H8 N4 Z, Z, _" Q$ R2 o3 v
grapherrormsg(errorcode));
1 A) e, {+ e7 O2 B5 m, e+ a5 lprintf("Press any key to halt:");
8 p0 \8 k6 C$ [, m. Z: O5 Kgetch();
1 i- @4 P* N6 a, f. d/* terminate with an error code */ ! t; }; z' {$ j; F
exit(1);
. |+ ^, T# E3 Z; S" s} </FONT></P>( f; {4 w# F8 Z  s7 l* O7 u
<P><FONT color=#0000ff>midx = getmaxx() / 2; - o8 S4 ]; T8 j* p
midy = getmaxy() / 2;
7 B4 }1 Y4 Z6 ]' w% ^3 T0 J2 jsetcolor(getmaxcolor()); </FONT></P>
( x4 R$ X, G# g  q; T3 @! w<P><FONT color=#0000ff>/* for centering text on the display */ 0 _; ]  f' Z8 W: }- Y0 G* c, D
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>! v/ Q8 l' _" B9 d# E4 U% d8 M4 p
<P><FONT color=#0000ff>/* get the current drawing color */ 6 z( E; r% K+ L9 x8 {
color = getcolor(); </FONT></P>
! v9 \$ C7 \* v9 c3 A) {# k4 y<P><FONT color=#0000ff>/* convert color value into a string */ - \7 l' Z' R! x# J! s& F# {
itoa(color, colname, 10);
# w# K: m  V) d3 @strcat(colname,
  M& E0 ]9 R/ _0 D7 d4 M. U' ], D: W. m" is the current drawing color."); </FONT></P>
! ?% Z0 o! Y- P; n<P><FONT color=#0000ff>/* display a message */
& w. E2 X9 Z1 H2 J0 aouttextxy(midx, midy, colname); </FONT></P>0 [7 ]6 p3 l: A3 O
<P><FONT color=#0000ff>/* clean up */
6 Y" C. t+ U. tgetch();
5 a% `, b6 e  T7 H2 [closegraph();
5 ]% z+ @7 q9 Q, ?$ k* _return 0; ' u9 ]/ {2 C* N% o/ f
} . w8 `, K" g2 W' A2 }' V4 X
</FONT>( v0 g' b9 Z. Y& E
</P>: `; E  T0 n! V8 \, G
<P><FONT color=#ff0000>函数名: getcurdir </FONT>
0 a! e2 C+ Q0 o5 D* D功 能: 取指定驱动器的当前目录
! c$ _5 D0 b* V1 B用 法: int getcurdir(int drive, char *direc);
/ D% a' |1 M9 h0 P2 r程序例: </P>
& v) z  a% i7 \- t<P><FONT color=#0000ff>#include <DIR.H>1 |: C3 e& D( L; D0 l  S
#include <STDIO.H>$ J( Q+ g. u/ e; ~4 y
#include <STRING.H></FONT></P>' m6 m1 |5 A. d; G
<P><FONT color=#0000ff>char *current_directory(char *path)
' d  p) p$ B8 F, B- x{
, n( i& ^5 T, [( p, Y7 N% kstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ 2 q; A, Y% r9 F9 b7 m
path[0] = 'A' + getdisk(); /* replace X with current drive letter */ 8 P: j) Y) b" F& l( s
getcurdir(0, path+3); /* fill rest of string with current directory */
) a3 R' }2 _! p6 B- q! Vreturn(path); 3 G$ o* e8 n1 ~% ^
} </FONT></P>
* t) c+ x/ n1 N- f% b8 b5 g<P><FONT color=#0000ff>int main(void)
# s0 j: p! Q3 N. U{ + d& ^& |6 V, @! I. a& h, q
char curdir[MAXPATH]; </FONT></P>
, B  _  ?( q: ^* _% w<P><FONT color=#0000ff>current_directory(curdir);
6 G0 o2 `$ ^0 t0 u1 z5 iprintf("The current directory is %s\n", curdir); </FONT></P>
) }& q! e0 G1 X<P><FONT color=#0000ff>return 0;
- K3 `; O4 {7 a: e}   w- p- l* ?5 q6 S" J7 y1 D, u+ [9 q
</FONT>8 e8 c- S1 ~! v9 H2 W: {9 a
</P>/ {" B7 n! `2 T: q/ C
<P><FONT color=#ff0000>函数名: getcwd </FONT>
( U0 o$ l4 x" M. ]. `. Q功 能: 取当前工作目录 , x. M7 q- M& k5 V3 G* w) i6 a- M6 ?
用 法: char *getcwd(char *buf, int n);
5 P5 C" E* Z9 d0 l) M9 s程序例: </P>$ j0 w3 ^0 `" v
<P><FONT color=#0000ff>#include <STDIO.H>
6 `8 K; J: Z8 R. B6 i+ B' R0 V5 _#include <DIR.H></FONT></P># W- Y6 q4 x8 ]. y+ V1 b( ~! K' W, ?
<P><FONT color=#0000ff>int main(void)
& G/ `" a% ~/ l1 ?, S0 }{ 0 G$ {3 x. Z( [! @0 V8 ~
char buffer[MAXPATH]; </FONT></P>! P$ B" n8 N9 D( k
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
: ?. v9 M% e; ]* N. R6 vprintf("The current directory is: %s\n", buffer); ' L1 y: M; c% \8 b3 k/ y
return 0;
3 @7 k9 p5 A3 p0 C0 ~} </FONT>
) k/ r0 q, @: ]3 o9 Q: O# V+ O4 `2 y3 h: K6 k2 y
</P>
7 H  [* V8 z3 G<P><FONT color=#ff0000>函数名: getdate </FONT>
- X( P+ ^0 B+ C$ a; ?0 y4 G功 能: 取DOS日期
6 z0 T' V# K. v; v; N% a. |0 b% \用 法: void getdate(struct *dateblk); $ C- i0 o; Z( n7 G1 P
程序例: </P>5 z# Z2 ^; y' s
<P><FONT color=#0000ff>#include <DOS.H>; |7 a* Z) I0 A- w
#include <STDIO.H></FONT></P>. P' Y9 T4 I- b
<P><FONT color=#0000ff>int main(void) , W7 o3 ~2 K% j
{
, S- y2 u: f  dstruct date d; </FONT></P>) }8 S+ V; a, b- r
<P><FONT color=#0000ff>getdate(&amp;d);
$ l- x  b# s" G# q- ^/ H) E) X1 tprintf("The current year is: %d\n", : I/ M$ `# ^/ d5 J2 U( x! d
d.da_year); $ ~6 @  ^2 z' R7 O. D
printf("The current day is: %d\n",
4 f" M. h$ v5 Cd.da_day);
" w  D" r" i$ p0 xprintf("The current month is: %d\n",
$ F7 ]# d+ u# z+ d+ ad.da_mon);
8 a: L! v; B! jreturn 0; . T1 o- x$ x" z3 s3 v+ f
}
+ a% i* x5 D2 f. N4 [</FONT>) V6 I9 C# \: W& I3 |+ m2 _% F
</P>3 z) Y1 s1 ]6 e4 Q8 G  z  a
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>. R7 N% \" w. {; A, Y
功 能: 返回调色板定义结构 * z1 J7 B0 W& R( y9 C
用 法: struct palettetype *far getdefaultpalette(void);
: E7 `1 m  L' ^: Y- J* r; K1 T; E程序例: </P>  w+ `' Z5 x! G; {$ x! V# q  U
<P><FONT color=#0000ff>#include <GRAPHICS.H>, p5 \4 b9 o$ k  H( `% X9 D
#include <STDLIB.H>
1 I- e# u3 U8 d0 p& b5 o#include <STDIO.H>, j" r0 G! |6 |! F, J
#include <CONIO.H></FONT></P>- h# I- v% {3 {0 z+ m# [
<P><FONT color=#0000ff>int main(void) ' Z& b/ ^, m; G) g8 i5 p) M
{
- M& [* S+ e5 E2 l. z/* request auto detection */
. v1 c7 a' p# Hint gdriver = DETECT, gmode, errorcode;
/ Y7 k, M& t/ G$ Zint i; </FONT></P>5 x2 K+ }' J! I* ?- ^" q+ q
<P><FONT color=#0000ff>/* structure for returning palette copy */ ) F% R$ x4 }7 e8 m
struct palettetype far *pal=(void *) 0; </FONT></P>6 @+ w3 V+ w5 x8 x
<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 G7 ^: s3 v5 o+ E: k* I. w1 C, jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 t1 @; B; z4 x" K9 _% r% \
<P><FONT color=#0000ff>/* read result of initialization */
1 R& L5 _% G% ]9 P& _# ierrorcode = graphresult(); , n& H& [* a3 H2 s* K
/* an error occurred */
8 @# n" M, g2 S: Z2 b9 y' u% r: N  Bif (errorcode != grOk) 0 s9 S+ _& h6 j
{ 1 Q+ z; S( J# U- T* O1 t
printf("Graphics error: %s\n",
' o0 K9 ~! }2 {0 a& igrapherrormsg(errorcode)); % H, v& T: e, T& Q- O- ~5 M
printf("Press any key to halt:");
0 i' ~  R+ Y" C7 A( hgetch(); 4 W$ \- y  Q9 V0 X9 ^  n" E
/* terminate with an error code */ $ s9 C1 u4 ?0 Z! S- ]  o
exit(1);
' B# W9 C( ]' z0 }/ X} </FONT></P># f1 k( j( `  J' n" ]% S
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>9 M3 c' l! u. {2 a  ?3 s
<P><FONT color=#0000ff>/* return a pointer to the default palette */ 7 n+ n; t- U0 N4 {
pal = getdefaultpalette(); </FONT></P>0 \, z% |  L6 C& ]0 z
<P><FONT color=#0000ff>for (i=0; i&lt;16; i++) " X0 f0 R7 d7 ?. C* o; D6 h
{ : V1 Z  t, w. o& X
printf("colors[%d] = %d\n", i, 1 A. v* D) d/ U8 N
pal-&gt;colors); & ?, V$ m" h' s
getch();
5 t' n" _/ W9 ?+ ]' {( R3 a6 Q3 o} </FONT></P>" b" B: N/ t$ n2 s/ B4 x
<P><FONT color=#0000ff>/* clean up */
/ z% S$ K, B, E* D* B% ]2 }getch(); 1 l+ I$ x4 y- P3 w5 V8 C* J
closegraph();
2 |$ r. t2 \6 I4 r! H4 l9 r: ]return 0;
3 d/ F4 b0 y7 |2 o) ~: ]: D} 7 l+ @8 k3 v- J
</FONT>7 F9 r+ ~0 u) H3 j  }
</P>! F2 l5 k; k! L6 w6 `5 }7 O: Q
<P><FONT color=#ff0000>函数名: getdisk </FONT>
) K9 h$ F2 R% G; o6 i* L功 能: 取当前磁盘驱动器号 ( M9 b5 j9 N5 y# f$ H3 g! F
用 法: int getdisk(void);
" B- y' `8 `& M$ W' D9 }程序例: </P>
9 Z$ o* @  E* g6 ~1 @/ ]/ J+ Q<P><FONT color=#0000ff>#include <STDIO.H>, [: @4 ~3 Z" L7 j' @
#include <DIR.H></FONT></P>
6 y+ s7 S( R( O0 z% S<P><FONT color=#0000ff>int main(void) 4 c& g& G' \7 _4 H4 l9 v
{
; x0 N. C- `5 e" d5 ~int disk; </FONT></P>& a  W4 W3 u3 a! [
<P><FONT color=#0000ff>disk = getdisk() + 'A';
$ o. d: `( l3 L/ k) `$ e0 Y6 gprintf("The current drive is: %c\n",
; c' H: K# W3 s5 k5 T5 y  ddisk); & y# m7 F' Z3 `+ c6 t0 ?4 @9 p6 }2 f
return 0; ; p1 d# N4 m$ b: O( N( v+ w5 m
}
5 v' y1 L7 g. N% s4 ]0 I% p1 d6 ~  Z+ b2 |7 x
</FONT>9 W: ]% u+ L1 Z
</P>
* N1 [: [* H- ]6 M9 i" a<P><FONT color=#ff0000>函数名: getdrivername </FONT>
) H7 x2 R0 }+ e  k% l) s# v: z功 能: 返回指向包含当前图形驱动程序名字的字符串指针 & U% }% @. c/ U, j" S
用 法: char *getdrivename(void); , ]* A7 v/ |4 _. x8 Z6 E
程序例: </P>$ d) B; x" i4 A) ~" e
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 J/ [( {, d" j5 c7 v$ X  O#include <STDLIB.H>
; O* v1 ?4 ~! S  W- w6 }: x- x#include <STDIO.H>3 n- T! P4 C9 _, ~
#include <CONIO.H></FONT></P>
) o% Q- O' ]- r7 Z* V: {6 |. h. t! p9 b<P><FONT color=#0000ff>int main(void)   Y8 E2 v/ D) |* O$ W4 m5 D7 y
{
7 f0 t1 K( W3 k' B. b/* request auto detection */ 2 P8 q; C& O  z* z% g& Y
int gdriver = DETECT, gmode, errorcode; </FONT></P>* }& H4 n! o& e  D0 c8 z
<P><FONT color=#0000ff>/* stores the device driver name */ 7 _  l) {- K; {3 n: E) p
char *drivername; </FONT></P># `1 }/ {7 N. k' k( x
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ O3 w) q7 o) ^. Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ Q5 l+ g* _0 Q3 Q* ]
<P><FONT color=#0000ff>/* read result of initialization */ . m  x+ F5 b. x8 M9 Q0 M( n( f- ]9 _
errorcode = graphresult(); - v+ h# d. A! ]' O
/* an error occurred */ 4 a& D8 g9 H/ h4 O* ^% p! u
if (errorcode != grOk)
$ ^. D# |: Y  {9 b! U) a8 K* a! T{ ' F& \7 n* {$ m( B1 E; i2 C
printf("Graphics error: %s\n",
  U9 O1 G, |+ k# ~grapherrormsg(errorcode));
$ P+ o( r# T/ F2 l$ s) b; o/ Xprintf("Press any key to halt:"); 1 o- ?& E( Z. y7 F. t# z
getch(); . K4 p  T* H/ J! k: R
/* terminate with an error code */
) }; v; ^# K8 I$ c- Mexit(1);
- R; [9 k2 s) e4 ^% x( @} </FONT></P>
) V4 B# d% h* D* c  W8 ?2 n5 K<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
6 q7 U% y5 d& ]) B4 I& w# i6 x<P><FONT color=#0000ff>/* get name of the device driver in use */
8 {0 y; S* P, O5 B' \drivername = getdrivername(); </FONT></P>5 F" _1 a9 _8 D2 m# N
<P><FONT color=#0000ff>/* for centering text on the screen */ * }% f5 _# c7 L2 d' H$ R! b5 F
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>; J. _% i# ?! C$ N: c# C) I1 z
<P><FONT color=#0000ff>/* output the name of the driver */
: v, z3 t1 S; }3 Eouttextxy(getmaxx() / 2, getmaxy() / 2, % }3 ?& H& d& p8 M7 |
drivername); </FONT></P>
, r/ P: Y! t" a1 [/ m$ _7 F7 x<P><FONT color=#0000ff>/* clean up */ : ?. E  A& Z3 @) t
getch(); 5 ]; J/ ~2 t3 @% j3 a' V' }
closegraph();
) B( b; @5 H2 S% c6 {return 0; ; N! H6 u% {$ A2 N% j$ ~* M
}   u+ w0 f8 {1 V" N" ]! L$ }
</FONT><FONT color=#990000>
- }) Q4 b: Z) z3 h, |6 ~2 f/ N</FONT></P>
8 i7 D2 y- `5 c" C" T0 z<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>5 a  f, B4 j, K: @
<FONT color=#000000>功 能: 取磁盘传输地址 3 f$ ~7 D1 k: N- U
用 法: char far *getdta(void);
. q. q1 t# u  L( j7 s程序例: </FONT></FONT></P>; B9 s/ J/ l8 `5 Q) w) p% `
<P><FONT color=#0000ff>#include <DOS.H>
3 ~3 ~: A. }% K1 F- H) U2 w#include <STDIO.H></FONT></P>
8 [0 z, r3 ~0 Y8 y; I+ d& d0 m<P><FONT color=#0000ff>int main(void) 0 @% H0 T! A2 J  Z% L0 x
{ " E4 b$ J. y3 S% i- {" N1 v
char far *dta; </FONT></P>
4 ?( h8 V) y/ E4 {5 Q<P><FONT color=#0000ff>dta = getdta();
4 \' m( K' d! F% F& Aprintf("The current disk transfer \ $ c" w- U) o7 P0 K
address is: %Fp\n", dta);
, d/ l* {& a  V, e& w9 ~5 Preturn 0; # l5 Y) }( R: l! w, y
} 1 ^1 P% [" A' d4 C# T& C
</FONT><FONT color=#990000>' q  i# i! q+ Y" r# C. n
</FONT></P>/ S  p1 l2 B; c; D! K6 E) L
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
% L! f0 v! Q. L  }, v<FONT color=#000000>功 能: 从环境中取字符串 : P" k1 Z4 R  {" K6 Q/ `1 n
用 法: char *getenv(char *envvar); + j5 G4 F$ w" j& e4 ~/ `" q
程序例: </FONT></FONT></P>
" b; k. m+ [* \% h4 ^5 J- c<P><FONT color=#0000ff>#include <STDLIB.H>. r$ R9 ], t, Z$ g; `* e0 P
#include <STDIO.H>
: g0 N+ e' Q/ {0 R- e+ Z</FONT></P>
9 M9 @" @; G- y. l" G( M0 G( v<P><FONT color=#0000ff>int main(void)
2 |2 Y/ q% R# j% b0 L, A{ " U- d. C: z/ q! b6 ?
char *s; </FONT></P>1 x( Z3 E* h, @2 v  _, j, _
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
1 e% B# s& K# mprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>+ [1 v/ S( s7 l; Z8 N
<P><FONT color=#0000ff>return 0; ! z: U0 Y) ^: P$ M: G
} </FONT><FONT color=#990000>
* N* T% u9 ?! D% I+ ^
2 f! \  C. F7 x) D. ^& n9 ~& |1 D9 F& f0 r
</FONT></P>
3 w# P+ R3 A4 v" V* V/ j) p# F9 k<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>, g) t3 @7 N; ?+ B4 O& m. r
功 能: 取文件分配表信息
) D: u. A3 n' P2 {% W" f用 法: void getfat(int drive, struct fatinfo *fatblkp); 6 H/ ?% T/ R% `* }; ^7 f$ m. {/ X
程序例: </P>
* {1 \) s+ w2 }- }( f, O1 v+ T. A! K<P><FONT color=#0000ff>#include <STDIO.H>6 B+ O2 P( l5 t+ j! ?, @
#include <DOS.H></FONT></P>
$ |1 ]6 ~6 g* D: V$ ~% M% N' y+ m<P><FONT color=#0000ff>int main(void) 3 G- e, v8 f( `/ w8 \' T7 c
{ 0 j* l% P& t2 K, c: u4 r
struct fatinfo diskinfo;
, I! r: I- ]  A4 r' R" H2 N. \int flag = 0; </FONT></P>
$ |2 B/ f6 r/ D$ A, q% Q<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
) x3 g, B& }9 c! r. e+ U5 qgetchar(); </FONT></P>
0 G1 w. B/ L) b! I' }8 ]<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
' l7 V7 n/ Z$ _0 ~# z/* get drive information */ </FONT></P>0 o4 q: z# `; k% L
<P><FONT color=#0000ff>printf("\nDrive A: is ");
& j+ A0 i3 [) t& w- Zswitch((unsigned char) diskinfo.fi_fatid)
: r* w! w5 D6 O{
/ b/ ^5 ^( I) ]case 0xFD: ! o# S# R7 Q2 o% E. M; `, V
printf("360K low density\n");
% I/ P7 O8 q' p' ~2 a' q/ rbreak; </FONT></P>/ o4 ]* C6 R, y. |, K5 d
<P><FONT color=#0000ff>case 0xF9: , D9 m: C) d( u( {5 E8 v
printf("1.2 Meg high density\n"); ! V6 P) g4 O  }/ m
break; </FONT></P>
: A" I- l; @) ^& [) u2 l<P><FONT color=#0000ff>default: % _  V+ q2 k' e4 B$ ]- f3 v
printf("unformatted\n"); ! {" Z$ Z3 @! e! h3 K. ]
flag = 1;
, v) R$ Z" O, w# c9 X} </FONT></P>1 f% b, Y- R+ y2 Y/ ?1 E9 `8 j  f
<P><FONT color=#0000ff>if (!flag)
" B. q/ i- ]3 {& |1 K1 H6 x2 Y{ 7 _7 o% t! Q; z4 K$ X6 |+ M
printf(" sectors per cluster %5d\n", / ?3 S8 N/ k( G; y& w
diskinfo.fi_sclus);
1 W! V% W1 F" ?& z" j+ z/ q- G/ Kprintf(" number of clusters %5d\n",
4 i3 i% T( T3 o- S9 @5 B% jdiskinfo.fi_nclus); 6 N; }2 V5 i4 o- p, |5 Q
printf(" bytes per sector %5d\n",   Z& E0 V" u/ H& Z8 g% V2 `
diskinfo.fi_bysec); 8 I& M' e9 D  V4 a% v! I& K
} </FONT></P>, c$ x. `' j% A: a; u
<P><FONT color=#0000ff>return 0; " L  p! v2 W' w( {1 Z/ _) b
} $ J' a5 v0 b! ]
</FONT>6 n6 ~, @+ R: f: V, @6 @3 ]- U2 a* N
</P>
: O9 U8 |( ^- ?) \<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
* n( v1 P. E0 G. ]0 }% m功 能: 将用户定义的填充模式拷贝到内存中 8 L0 R, d+ R( H3 j5 n0 ~
用 法: void far getfillpattern(char far *upattern);
, ~% A* l' F+ ~6 B9 F程序例: </P>4 A) N4 [4 ?( l5 G7 ~+ s$ l; \) V
<P><FONT color=#0000ff>#include <GRAPHICS.H>
' G( O9 B5 E, W) Z9 U#include <STDLIB.H>9 D! I" S8 n# V( P9 e& L- v" T/ _
#include <STDIO.H>
4 P: S; b$ i' o#include <CONIO.H></FONT></P>, S; u! `/ a: S7 Z/ Y7 `3 v! @+ T
<P><FONT color=#0000ff>int main(void)
; }6 P* b* R# J' k+ o{
' [$ q% k/ z/ Z) S! d- [" s/* request auto detection */
) M" M* ]3 [+ G# Xint gdriver = DETECT, gmode, errorcode; : ]& x' Y, \* X. y/ P3 Z
int maxx, maxy; - c. N. L8 w+ |3 H& u# ~
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
, B1 o0 e& R6 C! i<P><FONT color=#0000ff>/* initialize graphics and local variables */ . S4 c5 x3 f- O3 V( B/ p
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. X0 L  R  r: w- X* ?3 ?
<P><FONT color=#0000ff>/* read result of initialization */ : t3 M  A& M: S7 \# T( {
errorcode = graphresult();
3 v( K: F' u1 kif (errorcode != grOk) /* an error occurred */
( I# {; z$ s8 \{ . M' Y9 C6 A+ @' z  g
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : c$ F' N" n3 [7 K. d
printf("Press any key to halt:"); 5 c; B5 W* \; x, A' u8 U
getch(); 2 q" p: O& }+ M8 L) K" \
exit(1); /* terminate with an error code */
$ I3 l2 D7 k9 \! S# L1 y- C* F} </FONT></P>
  N; ^. J. F1 ^3 y; F( k5 q" l5 f<P><FONT color=#0000ff>maxx = getmaxx();
/ x7 ^: [$ [4 h! Pmaxy = getmaxy();
) C: `1 J1 c( B5 \7 hsetcolor(getmaxcolor()); </FONT></P>, V+ q$ Q- F  b/ Q7 k
<P><FONT color=#0000ff>/* select a user defined fill pattern */ ' O$ ?+ \7 T3 f0 @9 X+ j
setfillpattern(pattern, getmaxcolor()); </FONT></P>6 r2 X) g$ N/ e8 _7 `
<P><FONT color=#0000ff>/* fill the screen with the pattern */   o3 S' ^  K" j$ S
bar(0, 0, maxx, maxy); </FONT></P>
$ s" C9 s# A. b/ ^9 o<P><FONT color=#0000ff>getch(); </FONT></P>9 s; [2 f; @  c
<P><FONT color=#0000ff>/* get the current user defined fill pattern */
9 `$ l0 R  _7 r5 R/ R1 o/ A5 ggetfillpattern(pattern); </FONT></P>
4 C& w0 h8 V; M$ a- D/ `<P><FONT color=#0000ff>/* alter the pattern we grabbed */
+ I1 I) J4 X/ bpattern[4] -= 1; , g2 \0 x( n# T0 o4 S
pattern[5] -= 3;
( Q4 X+ ]8 o9 P) }, R8 i; apattern[6] += 3; 7 h9 M4 q! A( K- C
pattern[7] -= 4; </FONT></P>1 I) u2 Q+ ^" M6 W- P
<P><FONT color=#0000ff>/* select our new pattern */
/ p7 i6 ^. m, Nsetfillpattern(pattern, getmaxcolor()); </FONT></P>3 W+ w; W3 V. k7 F8 U0 B
<P><FONT color=#0000ff>/* fill the screen with the new pattern */
' |2 I" l* B) ubar(0, 0, maxx, maxy); </FONT></P>+ h; N. O/ f  y: }7 K4 f" E1 Z
<P><FONT color=#0000ff>/* clean up */
; ~# L* ?5 v! t. ^  mgetch();
: ^9 W. Z! B6 N9 O# m$ Tclosegraph();
2 j& S! w% J! E4 E' Q, Treturn 0; + @3 k; f' k$ Z0 S9 I$ I
}
8 U3 l1 J7 B3 f; z4 q</FONT>: P4 h6 H5 h2 d6 X3 h
</P>
' r6 ^; `5 G3 `* Q! a7 `2 ^5 T<P><FONT color=#ff0000>函数名: getfillsettings </FONT>* Q  X8 Y4 x! ]! f2 v6 |5 A: n
功 能: 取得有关当前填充模式和填充颜色的信息
6 A) K# Q" F. @4 P* n7 M) M用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); + P" g# a7 S; X) a9 s. a% x
程序例: </P>
' {. G% H6 z, R2 G<P><FONT color=#0000ff>#include <GRAPHICS.H>
( @, S  A6 T) Z$ h& p5 g1 Y#include <STDLIB.H>
2 C5 p- O8 m; g9 s. z: L4 I: a: K/ V#include <STDIO.H>6 ?* g  Z* b5 L! f$ D! x
#include <CONIO.H></FONT></P>
0 x+ q* b/ Z- v9 d6 G" D<P><FONT color=#0000ff>/ the names of the fill styles supported */
; m" Y! ]: I3 y) [& zchar *fname[] = { "EMPTY_FILL", 1 L8 V% R3 P5 V* ~
"SOLID_FILL",
  j: t: J" g7 |' g/ i"LINE_FILL",
. _# F! R9 W2 y- `"LTSLASH_FILL", & ]. T1 `, u% X
"SLASH_FILL", 3 I! u% z2 \" C& Y$ _8 u& N3 k
"BKSLASH_FILL",
' g; W" T, H/ ?6 o- B/ J& I' Q"LTBKSLASH_FILL", . S7 ^0 @+ J1 R, {! [) R. u4 W9 Q/ X
"HATCH_FILL",
' ]% ^) |  S  ]% F2 j"XHATCH_FILL",
( z% D' c: r) ?0 q. k$ C"INTERLEAVE_FILL", 4 ]/ e: h; m  X
"WIDE_DOT_FILL",
/ j9 u, H6 g$ q"CLOSE_DOT_FILL",
: E" p5 G' N  D! {$ [1 z"USER_FILL" * q1 N* J: F- g- y) Q
}; </FONT></P>
- o5 f% s/ {0 p0 j) i; N) j<P><FONT color=#0000ff>int main(void)
, h5 a5 H! B' H/ s, f7 K{ 4 T% c  ]+ m2 `' `
/* request auto detection */ , Y8 Q6 H7 H& M& j% N  \# d& ?
int gdriver = DETECT, gmode, errorcode; 4 [. k" a: I7 j. b
struct fillsettingstype fillinfo; # D' T) r0 q/ {
int midx, midy; 7 A8 e5 x4 {" {* _) W- Q
char patstr[40], colstr[40]; </FONT></P>
; m; C+ }# @1 ^<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 D' P" p8 P: t" d7 j
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# r5 S# a# K5 t! F* n5 b) J/ X<P><FONT color=#0000ff>/* read result of initialization */
! O4 E# ]$ K4 q  Y* N4 m* c$ z  qerrorcode = graphresult(); : L8 V6 o# @4 E' F0 {: i
if (errorcode != grOk) /* an error occurred */
$ I! V) Z' M: B( \$ F9 i6 a$ S, t- [{
# {& k& w. }% \0 d/ Q2 u: q) x! Iprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 L0 D, @4 Z5 j6 Zprintf("Press any key to halt:"); 4 \& ?) u( d/ B( t
getch();
2 J6 K) `$ b: v8 d* |! Hexit(1); /* terminate with an error code */
# O5 ^, z8 v1 h4 c} </FONT></P>
% p+ W3 k0 S# w9 |& V- p<P><FONT color=#0000ff>midx = getmaxx() / 2; " L1 k" a+ [; Y: J
midy = getmaxy() / 2; </FONT></P>, y6 \. B& j2 J$ y. o; L. \* B
<P><FONT color=#0000ff>/* get information about current fill pattern and color */
9 C1 E- P4 h; Cgetfillsettings(&amp;fillinfo); </FONT></P>$ C/ p9 d# P2 I  P. O. B
<P><FONT color=#0000ff>/* convert fill information into strings */
2 e6 D* B4 j0 {+ ]  j3 p2 psprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); ) p% U" t! i+ v" d
sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
, ^% u$ K2 x8 k! z+ X/ g9 D$ D. t<P><FONT color=#0000ff>/* display the information */ $ F% n0 x. K. `" O$ D4 U6 E
settextjustify(CENTER_TEXT, CENTER_TEXT);
1 y8 _# V$ Y; {, j7 u4 p& Pouttextxy(midx, midy, patstr); 0 M2 c& p8 m5 a8 c$ S* Y5 A
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>; Z! T1 H) G2 }7 A
<P><FONT color=#0000ff>/* clean up */
, N6 ^' A& G5 V! }getch();
! J- I1 o# q  V! lclosegraph();
* u+ j. q" J4 ^8 F* [6 kreturn 0;
0 \, r8 L/ J$ ?* _% P9 y3 Z  `4 L} ; y3 d3 O4 j' v0 t
</FONT>
  ^! t* e0 |7 q5 U7 l/ C/ l! g; C" M; i
</P>
2 x$ X1 s) d5 `9 H8 b: c<P><FONT color=#ff0000>函数名: getftime </FONT>
7 [! G$ x* Z' {3 {+ @功 能: 取文件日期和时间 0 N8 }9 S! h, Z6 O
用 法: int getftime(int handle, struct ftime *ftimep); 9 [; o7 |% C  i' ~5 A# z9 Z
程序例: </P>1 o2 G, G& x( Z  ]9 A6 f
<P><FONT color=#0000ff>#include <STDIO.H>- J! \9 p( `0 T; ]! i* k
#include <IO.H></FONT></P>
" I: ?) {+ _) v2 p* H4 |* r/ g" H<P><FONT color=#0000ff>int main(void)
/ {1 ^& Z: Z+ Q. T; x" h! [" W7 ]{ 8 W5 S2 l+ e6 E4 L! u2 F: ]2 l# V
FILE *stream;
$ H. r: ^. _( H# Kstruct ftime ft; </FONT></P>
0 C4 @: j7 H6 |- ^# g0 r+ T$ _2 G<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
- [; a9 j. Y: x0 `4 ~4 x. i"wt")) == NULL)
# d/ \' @( j8 V9 k$ \: X  X" G) w{
. a* A. s0 M, i4 G0 ]2 I% Mfprintf(stderr,   @" G) b0 \5 V& t  ?' g6 B$ Q
"Cannot open output file.\n");
; T; M( T7 a2 z; g( P0 ?return 1;
4 K, g7 U; L3 S$ ]: {} * h" G8 M  r$ n; ~' r
getftime(fileno(stream), &amp;ft); ) v- b& q; A3 G
printf("File time: %u:%u:%u\n",
, R$ Z  Z. b. u' m2 sft.ft_hour, ft.ft_min,
# H: [  o# z! F9 Bft.ft_tsec * 2);
# W( J( n% q' @- L) yprintf("File date: %u/%u/%u\n", 5 h) u" _. f' y8 o6 {
ft.ft_month, ft.ft_day, 8 j2 a3 e& J& S8 @( S7 w
ft.ft_year+1980); , ]; J, @) i$ P* H& e/ v" `1 e! w
fclose(stream); ! d1 f% z/ a1 ?2 _" O" v4 w" g
return 0; 7 p8 @! T' J/ \7 |( Q4 ]
} + i0 t; F0 W& n2 j
</FONT>
: A1 L0 e2 E3 L* V0 E7 C+ }1 [6 D5 Q5 b% r$ C& Y3 X: D) [
</P>
# q8 S; y1 S9 E0 G0 Y5 O<P><FONT color=#ff0000>函数名: getgraphmode </FONT>! i' H0 B. y4 R- Q( M; w5 q
功 能: 返回当前图形模式 ' `0 [$ T* a% Z8 c
用 法: int far getgraphmode(void); 7 B( D2 q6 M# S) h3 @1 V' q: B
程序例: </P>
# R, `8 J: b# G) C8 \4 m; z7 Q<P><FONT color=#0000ff>#include <GRAPHICS.H>% k  I; s4 O0 A) Y
#include <STDLIB.H>' S& W1 G7 y9 C, F6 C" R  a
#include <STDIO.H>8 v0 c' ?/ N% c
#include <CONIO.H></FONT></P>
; s  V9 e" |$ _( D* i<P><FONT color=#0000ff>int main(void) # a# x5 W* K0 `) u/ x
{ ' u* I' f3 p8 v1 q, X
/* request auto detection */
* }+ H$ L/ b3 \: t1 A/ bint gdriver = DETECT, gmode, errorcode;
" S0 D4 F. e- q& i5 f9 V9 t3 Hint midx, midy, mode;
+ w% \; E: ~8 `  L" ?( kchar numname[80], modename[80]; </FONT></P>
( Q9 l. K( b5 D1 D5 R- m8 a! a' z" f<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ L$ x" F$ v6 S+ N0 L1 J  minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; N9 P4 V0 E" u. }  m
<P><FONT color=#0000ff>/* read result of initialization */
4 S2 m5 s4 o1 u: `& xerrorcode = graphresult();
, q6 v  g3 w# T5 L( N3 s; Q/* an error occurred */ ' ?. a/ I$ j8 g# O; D9 g' L1 u
if (errorcode != grOk) 2 C" W: o- Y6 I9 q% E1 A
{
+ E3 L0 E0 o: [- b7 e7 t% t* tprintf("Graphics error: %s\n",
( Y& U$ I) p+ W/ F8 s; L( O/ tgrapherrormsg(errorcode)); $ @9 n: `/ V0 O  I
printf("Press any key to halt:"); ! o" H, `9 l9 {# @6 N9 @
getch(); " s* V$ x+ E. M
/* terminate with an error code */
3 p1 ^- q! o+ x! @exit(1);
- d6 b! m# m7 U+ c3 q+ ?} </FONT></P>- p  @. \5 n+ u
<P><FONT color=#0000ff>midx = getmaxx() / 2;
: l( \3 Q( G- i( w  T+ E+ U" Wmidy = getmaxy() / 2; </FONT></P>
" w/ |) h; L* Z6 Z<P><FONT color=#0000ff>/* get mode number and name strings */
4 s* j- b0 }; j0 z4 ?mode = getgraphmode(); 0 n3 s! X; H+ N, h3 L7 @& H. w
sprintf(numname,
$ X5 J7 `" h# O' {  Y"%d is the current mode number.", ; X! R! S: C, x/ F8 [
mode); / h! x( X+ w5 u8 W+ Q6 V
sprintf(modename,
+ f1 u3 v. J1 P& y% C"%s is the current graphics mode", 3 w. d& a& o. r) P
getmodename(mode)); </FONT></P>
  Z' K9 n& g- M% D% k: Q<P><FONT color=#0000ff>/* display the information */
+ u4 X+ ^, }. {  Usettextjustify(CENTER_TEXT, CENTER_TEXT);
# a. }6 r2 \3 O* Y2 V# nouttextxy(midx, midy, numname);
% k) A, v" `0 T+ D' h3 U$ X- ?outtextxy(midx, midy+2*textheight("W"), . }5 [+ H+ N: O- Y  l* w, q2 W/ [
modename); </FONT></P># s7 v! |% j7 o) T' B
<P><FONT color=#0000ff>/* clean up */ $ z8 R$ s6 y0 e* `# N1 {4 }
getch();
$ Y* D0 l5 B0 H" }/ nclosegraph();
" Q# m! V# ]) |& ^return 0;
3 V9 h3 K. s. y3 S! [} </FONT>
, U' f5 Z: J/ r. [5 O  p
" ^9 ~' j# ?) s. J1 D</P>
( b' v- h! Z- \/ L2 i  y<P><FONT color=#ff0000>函数名: getftime </FONT>, R8 s+ b% |/ L4 }9 b  j* e
功 能: 取文件日期和时间
. t% L1 s5 a% A2 D& Y. S" m用 法: int getftime(int handle, struct ftime *ftimep); & I$ G* R) @( [; v
程序例: </P>
! [& H! s4 j8 m2 _8 c9 K<P><FONT color=#0000ff>#include <STDIO.H>  M& u7 ?5 m1 N
#include <IO.H></FONT></P>
$ s- q! @, ?" o) @; U<P><FONT color=#0000ff>int main(void) 9 [" L( `1 w/ j
{ 1 \2 c; Y: c! t5 Z3 A  Z+ v
FILE *stream; 4 V" u4 p- ]2 `3 b  v
struct ftime ft; </FONT></P>
/ O6 c- G, j# g' V<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
$ ^0 O" `) V  r"wt")) == NULL) " M* r* z( n6 `8 z% @" z
{
# I9 T1 T" u  U5 wfprintf(stderr, 3 |' ?; R& h+ g  ^& c
"Cannot open output file.\n"); 3 A/ l2 t% _* H
return 1; ' I2 ~. i) u' k* r0 `% y0 C: z
} 9 p7 [- O& w2 n& ?; w; ?' C: L2 S
getftime(fileno(stream), &amp;ft);
" A. @: k7 u9 p% nprintf("File time: %u:%u:%u\n", & s5 B, }- V- g) [8 ]
ft.ft_hour, ft.ft_min,
  a& q3 S  x% fft.ft_tsec * 2);
  ^& q- K" m2 ~4 Gprintf("File date: %u/%u/%u\n",
6 `) U, k2 S) N: v0 sft.ft_month, ft.ft_day, 8 H" ^" k; g1 ]; A! n* ~4 c6 q
ft.ft_year+1980); # z% }- ?: U2 H, t
fclose(stream);
6 b7 p' Z# |6 F5 w$ s$ D: Mreturn 0;
) r4 W$ E  ?& e$ Y. O" M2 u} </FONT>3 B' @- v8 g) j) v7 ]
. {/ Z  j7 C8 ~' ?; ~: n
' Y/ C7 r3 d6 @) S2 o0 E
</P>! I4 N* }, z; O( p$ g. X
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>( y7 t  p! g0 ]! I3 A/ c
功 能: 返回当前图形模式
0 J4 m7 A+ I9 V' }) N# S用 法: int far getgraphmode(void);
/ a; F  @# C7 ^, W程序例: </P>! o5 `. M7 Q' j* u
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ J2 U" a; R7 r0 a  t% V1 ?#include <STDLIB.H>" m- R4 L) K# K! Q
#include <STDIO.H>. `" r! @! W0 d" Z  I7 z% `& X4 p4 g
#include <CONIO.H></FONT></P>  i7 `! t. }. E' y3 R
<P><FONT color=#0000ff>int main(void)
0 c1 D* j2 t% _7 F{
) u9 N7 `+ R$ L' c1 B/* request auto detection */
7 {( u- g: s, t% mint gdriver = DETECT, gmode, errorcode; 9 n. v& }1 @! e/ j0 h
int midx, midy, mode;
& `$ O; m. w; {, lchar numname[80], modename[80]; </FONT></P>8 r/ D. a" y- `3 {- [7 f" N
<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ q# o' c! i" e0 [, z$ q8 Finitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- i8 o( \8 W3 c4 S: t
<P><FONT color=#0000ff>/* read result of initialization */
3 t- F- \) s, F/ q2 a; @! qerrorcode = graphresult();
1 M! C. P; P2 Y( Q/* an error occurred */
. `( a" R$ v5 k, eif (errorcode != grOk)
7 U4 \+ i: K7 j. J) M2 e: d1 W{
, h; K! Q* T) v8 u  [printf("Graphics error: %s\n", ; |, @5 e4 ]; a! o. _+ ^; [
grapherrormsg(errorcode));
2 i6 A8 M8 X$ @printf("Press any key to halt:"); 2 P5 \* u$ A" z  P1 a7 D
getch(); ' L; s, B2 Q$ M+ ]( Y. J7 Z, o) i; i: e
/* terminate with an error code */ : ^& P) |2 C! ]! n2 A
exit(1);
( f6 ^" Z; e9 T/ {4 H7 [: y} </FONT></P>
$ L1 [$ l1 }# N3 @<P><FONT color=#0000ff>midx = getmaxx() / 2;
! X' V& K# k! e4 Xmidy = getmaxy() / 2; </FONT></P>; F# {9 |4 U5 }1 v
<P><FONT color=#0000ff>/* get mode number and name strings */
8 c$ M7 h6 |( p  v6 l1 {- l2 ~mode = getgraphmode(); 9 ]- u5 T4 q4 n) z* x+ ^& A
sprintf(numname,
+ t* L, a5 j; `% Q"%d is the current mode number.",
+ m) G' E2 w; ?; C. a: Dmode); 6 z) D/ Z; g7 t, m
sprintf(modename,
- l0 w/ E- o, O) ^+ u- j2 z; `"%s is the current graphics mode",
6 `6 _3 |: v# g* V! pgetmodename(mode)); </FONT></P>& _2 B  ?/ I" j0 s5 n& H
<P><FONT color=#0000ff>/* display the information */ - o8 ^& K6 F( Q3 T6 O
settextjustify(CENTER_TEXT, CENTER_TEXT); 3 o2 n5 C& B7 t1 c7 b8 \8 S4 [
outtextxy(midx, midy, numname);
5 B; I' R% k* q8 l! T& Touttextxy(midx, midy+2*textheight("W"),
+ d5 N: I; r5 S( m3 Amodename); </FONT></P>. C: U8 C* W/ q' ~# \
<P><FONT color=#0000ff>/* clean up */
* ~( s8 h& X0 @) K7 I5 B, `getch(); ( t6 n  ^( J5 F+ Z4 V4 }
closegraph();
* D; q) R: [- {" j/ S5 Ureturn 0;
- w  S4 @7 z* ^! ^# x1 ^: Z. |8 I} ) ?  M/ w3 b9 L& P: X* M  {! g
</FONT>8 f' b  r, ]% C) d
</P>
# k- }4 s% a+ {% u4 V! u4 I% \<P><FONT color=#ff0000>函数名: getimage </FONT>$ q1 K3 ]# D0 f* P! n2 n; L
功 能: 将指定区域的一个位图存到主存中
4 ^" ~, a+ v# x1 P6 O# S用 法: void far getimage(int left, int top, int right, int bottom,
. v( R# R. E% a+ [* j6 Q' v9 Zvoid far *bitmap);
0 |8 u# i* Y, h- N程序例: </P>
# b, ]- R8 c2 t<P><FONT color=#0000ff>#include <GRAPHICS.H>
; e; h, U3 l7 S1 W8 G! f! S#include <STDLIB.H>+ x" h& I4 H/ q+ h5 J2 Q6 X. B
#include <STDIO.H>
3 _8 P0 z) g* ]% w6 v9 [/ G; \/ d#include <CONIO.H>
% o+ o6 }% `( @: E  N" ~% B#include <ALLOC.H></FONT></P>
: U4 s* W8 _* N5 o. k<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
" @' d' N# ^- i( Fvoid restore_screen(void far *buf[4]); </FONT></P>+ B8 B+ z9 r0 q1 Q( q8 ~$ _6 b: D
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
! M& x5 X  z9 X6 F2 a- x<P><FONT color=#0000ff>int main(void)
* _6 O. E% W9 d9 r7 s{   B* e' E3 C, n4 m5 N. {
int gdriver=DETECT, gmode, errorcode;
2 `1 d% |" }* B! L6 ^$ lvoid far *ptr[4]; </FONT></P>+ P, W" L3 I0 @  d8 D
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ % c3 s) h$ B0 u
initgraph(&amp;gdriver, &amp;gmode, "");
+ g: @7 L+ B' M" @& G+ m, merrorcode = graphresult(); /* check for any errors */
/ B9 ?- d7 Z- }5 E' E5 ^if (errorcode != grOk)
- ~* T+ }/ a6 s) h' @8 y" d{   J: g( D. W3 `7 H) i. |
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + l8 x3 A4 W4 C) S, R, S! v! i  N8 B
printf("Press any key to halt:");
( t$ W5 c" m: `; ]9 Wgetch(); " g- C- \0 |" d4 T# [3 t4 n
exit(1); 9 R3 [8 k- O9 [0 k# l& z$ i
} ( m9 Q4 e" V6 M+ n, W$ e
maxx = getmaxx(); + U3 @" {& z$ N9 @. L
maxy = getmaxy(); </FONT></P>/ c  D. i& i4 R# d) Q
<P><FONT color=#0000ff>/* draw an image on the screen */ " F! z, Z8 C( N
rectangle(0, 0, maxx, maxy); - [* _1 j: M) x# P
line(0, 0, maxx, maxy); ; j/ i0 `1 X) v" J
line(0, maxy, maxx, 0); </FONT></P>$ h) _7 N0 I( L
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ , V9 n# o9 n& r6 L
getch(); /* pause screen */ ) m0 B( @) ]) P3 q4 z3 ]; ?1 ~4 F1 L
cleardevice(); /* clear screen */
" D8 ~9 `* ^( H/ `restore_screen(ptr); /* restore the screen */ ) t* p  Q" _# O8 `, N" {
getch(); /* pause screen */ </FONT></P>
7 F6 @; X4 ^- M( ]3 B1 s<P><FONT color=#0000ff>closegraph();
' q2 n2 s  s0 kreturn 0;
( s) A5 V! {0 v9 x0 [} </FONT></P>
) j* x4 O. |' y+ Y/ _: G<P><FONT color=#0000ff>void save_screen(void far *buf[4])
6 X! y) E, o! y/ R- T8 j{ 7 V/ Z" e/ t- a: u+ }  i* O
unsigned size;
4 t2 e2 D8 L$ U9 Qint ystart=0, yend, yincr, block; </FONT></P>2 G8 t6 M5 L" h& E2 t, J
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
  W7 h$ s* U$ G# d& a) l: o3 D6 eyend = yincr; 5 h4 v7 ]# I& j) X" ^
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
5 l# j, d' n" V8 }  x$ D8 O<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) ; y6 g5 m9 o/ Q# O; l8 p
{
: H/ B6 p: w2 ^* Tif ((buf[block] = farmalloc(size)) == NULL)
7 z& f, a6 C) E- Z" b% i{ 7 X' Q( ^4 B7 D7 K
closegraph();
/ e' H7 ~4 @+ B0 Hprintf("Error: not enough heap space in save_screen().\n"); 6 n6 p0 W* _; \& M0 P# l
exit(1); 6 S: N! [% \+ `8 A7 K8 Y0 M  Y
} </FONT></P>
! {$ ~) r3 I$ ]! y. L# S+ i<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); * S1 o2 J( `! T; j+ j0 A  E( I
ystart = yend + 1;
5 {# c* z5 B% X# ^9 z* w( iyend += yincr + 1; 8 g4 t2 a4 ?3 b. g  Y6 F
}
. o- H0 s) T6 O. C} </FONT></P>9 ]% R$ _% A) `  c
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
% D3 K/ I; f! w3 x$ D/ {' H6 d) P2 D{
( _: g9 u: F& }& h( gunsigned size;   u! _! v: P( w, S
int ystart=0, yend, yincr, block; </FONT></P>. q- @+ r& z; L6 N; }
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
* e* \% V% L7 {6 W, N1 B" O1 Tyend = yincr;
* s8 b& e0 @+ b  I# asize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>* z5 a$ _7 Q8 J" ^! f
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)   \' y; I; w7 e+ q  b8 p+ P
{ * m( c; q5 l( p5 M2 F
if ((buf[block] = farmalloc(size)) == NULL)
' p8 |  x! s9 E" g& W; o! b8 y{
) \0 p1 y4 N4 Nclosegraph(); 0 P3 i  v0 W6 q% Z0 \2 E
printf("Error: not enough heap space in save_screen().\n"); 4 p( G2 d; v% w
exit(1); 4 x: [5 s5 c" l1 s5 e5 h* s
} </FONT></P>( I+ n' U$ \9 t3 \) O
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); - M/ S) b3 T& l, l( w1 ~. Y# m
ystart = yend + 1;
* H5 K; A, ?3 a; l* B7 `2 _yend += yincr + 1; 9 F. j0 k  Q$ j8 c, h
} 1 T( t. y( C2 }1 Q3 n* q3 n( ]  \
} </FONT></P>2 F& Z: f6 p* T% P5 B
<P><FONT color=#0000ff>void restore_screen(void far *buf[4])
8 S, y6 |: h, P{ 2 {9 Y* u( f# O# D% t
int ystart=0, yend, yincr, block; </FONT></P>- c  c2 I& \3 e( T# H
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 4 k9 `0 Y3 ]7 {7 s# J3 l: U7 A$ }
yend = yincr; </FONT></P>
( E) T- f$ d0 m4 n  _0 D+ o4 n<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) 3 t: n; O$ g+ ]( S2 [$ O
{
4 f# v: d: V2 q2 @, C4 Gputimage(0, ystart, buf[block], COPY_PUT);
2 c/ [2 J2 S: B( F! k0 Kfarfree(buf[block]); ( ]9 V( J+ z2 C5 H3 q' _5 z
ystart = yend + 1; 3 L/ @$ {7 X2 w$ s4 n% `( z0 i$ \% S
yend += yincr + 1; ! _/ d/ l7 _% m# f$ {- |* w' s
} / e8 j; Q; F& i" M/ e! W: V
} </FONT>
, g. F& ~' `) b( t' {7 L# ]<FONT color=#ff0000>8 y- ^* X0 s' m, i: u1 a
</FONT></P>+ X  g4 c/ C9 v, n& u9 Y: z' i
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
  T, l  U) e5 }6 P功 能: 取当前线型、模式和宽度 . s6 S  O; v2 N5 L
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
3 b. I) D4 H# t' n; j. P程序例: </P>
0 T8 O/ B5 P$ x5 @: _! n( x" E$ K2 W<P><FONT color=#0000ff>#include <GRAPHICS.H>
, q' Y: w( g; s8 d: x' ^#include <STDLIB.H>& p. A& T( X3 {* r/ `4 W4 @9 E
#include <STDIO.H>
6 Z; ]( F: \8 ?" a! u2 n#include <CONIO.H></FONT></P>5 J! z4 W* S' I; f' Y
<P><FONT color=#0000ff>/* the names of the line styles supported */
# }5 P8 ]1 U6 B2 i" @char *lname[] = { "SOLID_LINE", 1 _: F8 ~1 u* T2 X
"DOTTED_LINE",
" Y' b+ c  F7 L/ j8 I"CENTER_LINE", 2 H9 U, T. q( }2 j: I4 M" c
"DASHED_LINE", 5 ~: M$ H/ H) }  y& L( Z) |
"USERBIT_LINE"
' b8 u2 x2 {$ y" ?1 d}; </FONT></P>0 x( t$ d9 M; e* F% J
<P><FONT color=#0000ff>int main(void) 2 Y' V& q3 {" {7 j
{
" i0 m, o* o2 q' z; d; @/* request auto detection */
6 h6 b4 _2 W" I- d6 ?int gdriver = DETECT, gmode, errorcode; " n* Q9 V+ r/ C& j- r# Y) n
struct linesettingstype lineinfo;
  h- E) p0 f6 Y3 h+ c2 X- h7 Fint midx, midy;
7 y6 @# N# X1 [0 wchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>7 r/ p* I& [6 K  |$ N9 p
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 Q5 {- ]- h; A, G2 s; e2 ]; Z( M
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, l* I" C# B/ H3 h! b
<P><FONT color=#0000ff>/* read result of initialization */ . H) R+ A' g9 D# |' |
errorcode = graphresult();
* Z0 a/ c2 S# \1 N2 l8 |0 uif (errorcode != grOk) /* an error occurred */
% D* O* o7 D. u6 j' Y2 F{
# Y# O" M8 O# o/ S1 i* z9 gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ! g( b, z2 T5 i: q
printf("Press any key to halt:");   e4 D3 i! l' V8 R3 ?
getch();
6 W# w* N. C/ A# }# {& A, I% aexit(1); /* terminate with an error code */
% z1 d" o2 W7 |} </FONT></P>" z' _3 {$ u( b& _
<P><FONT color=#0000ff>midx = getmaxx() / 2; ' N4 {2 e. E; S6 l( w2 S8 S: Q
midy = getmaxy() / 2; </FONT></P>. u' l& Q9 _- f. ]+ @, G
<P><FONT color=#0000ff>/* get information about current line settings */
2 b* L" l4 h0 ^- j9 R( [% o6 zgetlinesettings(&amp;lineinfo); </FONT></P>" Z- h2 K5 X* n& C9 C* ~
<P><FONT color=#0000ff>/* convert line information into strings */ 9 J( V; C/ |5 ^5 w5 o
sprintf(lstyle, "%s is the line style.",
. y7 t& y4 g; T' L2 ~  qlname[lineinfo.linestyle]); : d$ Y' Q- @& o! d& D" \# j
sprintf(lpattern, "0x%X is the user-defined line pattern.",
" v" ~% R' x4 D( G% ], z7 `* F9 Hlineinfo.upattern);
6 c. H: p1 u9 E# k5 zsprintf(lwidth, "%d is the line thickness.", & O/ p5 M7 K) L/ k- G* y# I
lineinfo.thickness); </FONT></P>
1 f' Y, j/ ]: G<P><FONT color=#0000ff>/* display the information */ ; }5 R: P5 c) W3 V1 J2 A7 d
settextjustify(CENTER_TEXT, CENTER_TEXT);
* _1 j2 S/ I: a) nouttextxy(midx, midy, lstyle);
8 ^" a, o) R% \/ c1 `" {! b/ Youttextxy(midx, midy+2*textheight("W"), lpattern); 4 F- W, N; E9 \# T1 u/ f! e$ ?' A5 |
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
! d* v3 B9 `7 {$ g, H<P><FONT color=#0000ff>/* clean up */ - D& C2 Q# B6 o: }6 G
getch();
: c( O! H) k% ^7 Z3 Z1 Nclosegraph();
; ]9 S2 Q$ Q8 f1 ~. Z0 sreturn 0;
$ i. c" H$ e, C  C6 L} </FONT>
+ r& Y+ o# u4 |1 N5 u6 B! D
  g! U2 S$ |- D</P>
$ f# x- I0 m& Y; _8 t* r<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
. D- @8 x2 `/ c0 y& n  c& x8 Q# @% \功 能: 返回可以传给函数setcolor的最大颜色值 " _( {0 S( q  h1 j8 Q& @+ q
用 法: int far getmaxcolor(void);
& q8 g8 M4 R& [4 D1 q2 p* {+ T/ }% Y程序例: </P>
% Z7 g) }5 o1 _/ P<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 A+ W6 w: w3 c#include <STDLIB.H>
& |% I6 \7 q9 C, ~* ^#include <STDIO.H>
: o0 P. M# A$ O% B#include <CONIO.H></FONT></P>
+ B4 l* s9 v3 G<P><FONT color=#0000ff>int main(void)   }: m6 F4 |/ D- s, i
{ 9 ]" y8 [- n8 S4 i9 e! @. [
/* request auto detection */
- j$ R8 B- i' |int gdriver = DETECT, gmode, errorcode;
/ E$ N  h; ?$ u, A! H1 c. Rint midx, midy; 3 \1 U9 f) p* _# [0 t, T9 c
char colstr[80]; </FONT></P>& d4 o- V0 f* m0 z8 m
<P><FONT color=#0000ff>/* initialize graphics and local variables 9 m- H0 H' M5 K% j0 w% `6 G
*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; X- A7 e/ _- Q3 J+ r* B<P><FONT color=#0000ff>/* read result of initialization */ $ O# p( H7 P9 v6 e! J1 u
errorcode = graphresult();
- P/ T/ ^  Y, \  u: n0 q3 }: Mif (errorcode != grOk) /* an error occurred */ 0 }4 Y" Y" y5 O" ~2 D# o
{
6 V& }8 f# ?, J7 R& Wprintf("Graphics error: %s\n", grapherrormsg(errorcode));
1 W0 W- M6 i$ z( K6 w0 j8 j4 mprintf("Press any key to halt:"); 5 M6 `# O9 g6 o' _, X
getch(); % g% X' g% z( Q0 W
exit(1); /* terminate with an error code */ % i0 ?- R) B, }' g
} </FONT></P>: O. k: }: q  R: Q9 T# ?; C
<P><FONT color=#0000ff>midx = getmaxx() / 2;
* @& k/ H4 M$ C- X2 c+ \midy = getmaxy() / 2; </FONT></P>
/ U0 B1 ]; ?/ r0 T- t7 y<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ 8 ^5 V7 `9 I! o6 j8 U
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>/ V% s* j- B- f4 T- a# M: n- ]% a
<P><FONT color=#0000ff>/* display the information */ ) u" [4 R$ k+ u$ L% R5 i
settextjustify(CENTER_TEXT, CENTER_TEXT);
5 d; a& g# Q' j/ P) E! A# q7 pouttextxy(midx, midy, colstr); </FONT></P>1 n. z  j# o, d( _4 N9 [
<P><FONT color=#0000ff>/* clean up */ 2 R7 D( d% H8 R) ]) K* [+ _
getch(); 6 H5 a& l: |2 s  b
closegraph();   h* S9 T7 j3 M3 V
return 0; $ x/ f6 V; r2 X( L' g
} </FONT>! K0 F2 }9 ?3 J1 I7 Z- I

. s- p  N. q. U% B3 b; ~) m; t5 f8 Q5 v% D. F( g7 o2 d4 }
</P>
$ Y  L! m! e) X, Z# {3 {+ T' D1 ~* i<P><FONT color=#ff0000>函数名: getmaxx </FONT>$ P! J5 c2 q# o* C/ Z' h, d+ r
功 能: 返回屏幕的最大x坐标
) _9 p, d6 B6 g7 B6 V9 D用 法: int far getmaxx(void);
; [5 k5 y9 Y- G; x程序例: </P>( A! X) Z( B- V/ i. ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( o- m* r% b  i& {( W#include <STDLIB.H>
$ B/ V3 i+ s7 }" |9 s7 d( [6 d$ G#include <STDIO.H>; t- j- p) k8 f4 E% R- f7 b
#include <CONIO.H></FONT></P>
, @4 s# i; N: T8 ^( R! v) I$ Y<P><FONT color=#0000ff>int main(void)
) _! `4 f1 J9 ^$ O. b{
8 j- X# p: w5 I7 p! {8 I- d/* request auto detection */
  D  \" S+ e; r$ x- i3 G" }# p+ Zint gdriver = DETECT, gmode, errorcode;
) a9 k4 w3 w: M# p1 y7 B  i4 i  k+ \int midx, midy;
# H# b/ }. |' r; n% R8 Xchar xrange[80], yrange[80]; </FONT></P>
( N- B8 S2 u" e<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 Y7 K$ h* _: c8 @
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  G' T( @, q! a# u! B% k9 H8 s. j
<P><FONT color=#0000ff>/* read result of initialization */
' a7 n' D6 [6 @2 T6 |9 b7 Rerrorcode = graphresult();
3 c3 s6 @0 i8 Y' z0 g% ?, O2 c% oif (errorcode != grOk) /* an error occurred */
6 V( F: i/ Z$ a, F2 |$ f{ , Q& w+ P. n5 e' q8 [& t
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ j( D9 ]" [* }+ M( p* vprintf("Press any key to halt:");
- _% v) X' ]: L. Y/ f' \, hgetch();
/ b* W7 @+ X/ b3 f& @, b4 eexit(1); /* terminate with an error code */ ; A+ v6 x: a* C! A% [& {
} </FONT></P>) r0 o0 b; g3 n# F
<P><FONT color=#0000ff>midx = getmaxx() / 2;
4 y2 E: n: q) D# {8 |midy = getmaxy() / 2; </FONT></P>  d! x0 F+ S# R% ^1 `
<P><FONT color=#0000ff>/* convert max resolution values into strings */
* z/ @1 n/ f5 M. fsprintf(xrange, "X values range from 0..%d", getmaxx()); ' A0 Y, n  o0 l$ N; j1 N5 M$ M
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
! D" K# N4 g/ \$ L+ S7 _<P><FONT color=#0000ff>/* display the information */ ) ~; B" f9 a0 ~' S/ L. a" X' K
settextjustify(CENTER_TEXT, CENTER_TEXT);
. U' y  Z, V" H" F; Vouttextxy(midx, midy, xrange);
6 C: B" x' i$ y8 `/ Xouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
9 H; I  X( Z4 r$ U  V<P><FONT color=#0000ff>/* clean up */
8 H  h( i, I# t9 J, f2 Ggetch();
. R- w% F- p; v& O8 Z0 `# e* P0 Xclosegraph(); 3 m2 f, [9 S8 Y! d
return 0; ( v- H, P6 w" \' m: Y2 S3 O
}</FONT>
$ s" j4 r/ \( T1 x) q. `+ p. w9 R
</P>
5 p, W1 Y! J. B, j" j, S% U( e<P><FONT color=#ff0000>函数名: getmaxy </FONT>2 j1 R9 t7 P' w4 b- }- H
功 能: 返回屏幕的最大y坐标   i8 g2 [- W, ~7 i# \' L& L$ ~  ^
用 法: int far getmaxy(void); 9 g% [8 n6 F1 E- e
程序例: </P>
7 d# F/ U% K+ N7 m: L5 `<P><FONT color=#0000ff>#include <GRAPHICS.H>
" o  x1 ~. K6 j4 ]#include <STDLIB.H>
6 r9 M4 k. ^( l# W# l+ v0 u#include <STDIO.H>* J! @8 p3 `. s9 B5 u2 s" B0 H
#include <CONIO.H></FONT></P>4 l& z! U% i3 h, S% @! b/ a" Z7 q) U3 X7 n
<P><FONT color=#0000ff>int main(void)
5 w6 w8 x* k0 Z6 b7 c' w) s{ 8 g4 t3 q1 E" n
/* request auto detection */
6 h. k1 t8 X$ C6 qint gdriver = DETECT, gmode, errorcode;
* j) \* I2 `5 }+ cint midx, midy;
" [& `7 E* |- ]* N# ^/ Ochar xrange[80], yrange[80]; </FONT></P>3 H8 ?9 Z/ k$ u+ i- q) E
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 S! t  H( W# U, }/ a- v4 O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) m; d% u  m4 `. h5 `
<P><FONT color=#0000ff>/* read result of initialization */
5 v! z' ], C$ L- Terrorcode = graphresult(); , U+ d9 z: \7 y
if (errorcode != grOk) /* an error occurred */
0 W( C, E2 w5 ~) e{
5 G, F2 H  @3 G! iprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * @  [) N, I# d
printf("Press any key to halt:");   T) h$ J% ?2 D+ K6 l
getch(); : K  I1 b( V/ |* ?, Y
exit(1); /* terminate with an error code */
1 p$ T" c  F" H, c, N$ ?} </FONT></P>
+ j4 E/ D0 E6 E- L& C& L, e: H* q<P><FONT color=#0000ff>midx = getmaxx() / 2;
( H3 B3 V! c8 Q: j4 O1 ~midy = getmaxy() / 2; </FONT></P>
% P% ~7 s4 o& V  i6 e<P><FONT color=#0000ff>/* convert max resolution values into strings */ 7 \! a8 l7 j6 b$ t
sprintf(xrange, "X values range from 0..%d", getmaxx()); - g* @* _- A6 k, O. T9 Y" Q
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>: u* {) Z, O: @' k
<P><FONT color=#0000ff>/* display the information */ $ v5 Q/ i5 P( `
settextjustify(CENTER_TEXT, CENTER_TEXT); ( H* j2 b$ Q2 U' u
outtextxy(midx, midy, xrange); 2 s7 M4 n+ \' d8 R6 O$ N6 \9 f9 p
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
, z, s4 A! p& B' x8 V<P><FONT color=#0000ff>/* clean up */
$ u7 r! p$ d# \8 ogetch();
0 n. a$ y/ b+ s* {( Wclosegraph(); ) g3 R8 {+ E* |- O+ `1 e: A- z; O
return 0;
8 T0 I- H7 a5 |( y9 s; @! V: O, {} </FONT>4 ~  g; y1 P  Y0 ~* }8 v
</P>3 w$ m. ]6 _/ _" m( B# w
<P><FONT color=#ff0000>函数名: getmodename </FONT>
; H2 F. W* \) l* C6 r4 @5 c+ N: x! h功 能: 返回含有指定图形模式名的字符串指针
" ~2 c' C8 s8 W. R用 法: char *far getmodename(int mode_name); 7 ?, ?$ R" v4 U7 a( ]
程序例: </P># M4 n, K# L( o0 r  K6 D
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* P7 T, h0 ]( I' f" z; R#include <STDLIB.H>+ n, @8 ~' W1 j  J  S- f
#include <STDIO.H>& q3 O0 A; k# ~( B8 a& ?/ L
#include <CONIO.H></FONT></P>
6 h# B# R6 v8 O& t) ?# {<P><FONT color=#0000ff>int main(void)
5 {4 o7 Y- @8 y  }{ # M, W! x; Z! Q9 q' {1 m  s8 f
/* request autodetection */ , h; |/ Q) O, c0 R& k. u
int gdriver = DETECT, gmode, errorcode; & W' D2 a! D% z/ X4 S7 W5 a. y2 P
int midx, midy, mode;
4 A6 k& Y8 V. m( y- kchar numname[80], modename[80]; </FONT></P>
* I6 }& J6 ~9 O$ F% I6 e<P><FONT color=#0000ff>/* initialize graphics and local variables */
' b7 l' O; K+ N2 t( Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 `9 o) A: W- D- @: x. C<P><FONT color=#0000ff>/* read result of initialization */
6 K! D- Q! Q) h1 `  C5 \/ H$ Zerrorcode = graphresult();
6 E, }6 u8 l* e+ [& Aif (errorcode != grOk) /* an error occurred */
8 m% O0 {1 `. n% T6 U& {/ |# l{
# Z8 K( t/ |1 O2 ]$ o* x) T9 U6 Z- kprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 J/ D5 S8 K) B1 F9 k! _
printf("Press any key to halt:");
1 I1 t0 T3 b/ E+ Q& @getch(); " }4 ?9 Y+ U* d, t* f" H6 P
exit(1); /* terminate with an error code */ - q8 ^2 v/ |7 K; g
} </FONT></P>
$ s, c' @7 t- \, A# _) S<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 X# d& y% v" S8 W+ bmidy = getmaxy() / 2; </FONT></P>
1 m. Y9 S3 M7 Q0 F' `4 L3 Z9 k<P><FONT color=#0000ff>/* get mode number and name strings */
% Z& X8 ^, Q& p: F# U4 dmode = getgraphmode(); ; }1 n. u. S* ~4 n' V: m8 U7 \
sprintf(numname, "%d is the current mode number.", mode);
5 ?6 i6 X( ~7 ^9 esprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
7 f9 l. I! {& u. s+ K3 r3 }<P><FONT color=#0000ff>/* display the information */
/ u$ n; n2 F2 w: N+ Q: Ksettextjustify(CENTER_TEXT, CENTER_TEXT);
$ K: A& L: e3 `. X! K5 `; L! Q/ douttextxy(midx, midy, numname); # o9 A% \' q/ k8 s+ `* ~
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>& X- k! R% M+ {4 e0 R8 P2 z
<P><FONT color=#0000ff>/* clean up */
; n, o1 O( H) |6 `; ~8 f! Y' \getch(); ) @: z8 J% ?# s6 A6 r
closegraph(); 4 k& v9 n( k9 K: `$ t4 [. v! h
return 0;
/ ^3 d( t/ ^& F/ t& z} </FONT>
. u# |9 q* Z& g# B
  G$ g- w* ]7 T. L</P>" M  y3 t& C2 K5 e! C: Y! l
<P><FONT color=#ff0000>函数名: getmoderange</FONT> " |4 Q5 a6 D: Z7 s% D8 e6 R
功 能: 取给定图形驱动程序的模式范围
% [- @2 _8 v5 N7 U  S4 M: U用 法: void far getmoderange(int graphdriver, int far *lomode, - x: m& c6 h* X( q
int far *himode);
4 z9 n1 f8 d2 |) D  r/ ^4 b程序例: </P>! C" W0 K$ {" p. a
<P><FONT color=#0000ff>#include <GRAPHICS.H>& ~) E. }; g3 z. b0 Y* q. K& N4 _. f9 b
#include <STDLIB.H>; Y6 \9 D& w4 L. [; R
#include <STDIO.H>
) g5 D. Z+ _" G* h- H% i# W! N+ A) m#include <CONIO.H></FONT></P># n) @0 X) b; a# Y
<P><FONT color=#0000ff>int main(void) $ R1 |% b0 |( Y
{ . S6 `) e& l/ O! |# M
/* request auto detection */ - ]# a( f5 H- F+ T3 P: |
int gdriver = DETECT, gmode, errorcode; , K+ ]/ G4 s* B+ {: c% \
int midx, midy; 8 a- `; D$ D7 Z1 n, y, I# [
int low, high;
* |* I/ j; t- l7 _char mrange[80]; </FONT></P>
6 ~+ x( Y  G9 _! _: [) C<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 ~- i8 c9 w' ~% u( [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>% |+ r  I: s7 g  q" S  S
<P><FONT color=#0000ff>/* read result of initialization */ 6 z& C4 H2 C* }) I7 {  ^& {& \
errorcode = graphresult();
: G3 ?1 S  M# n6 L9 Bif (errorcode != grOk) /* an error occurred */
7 i) k; L1 _* D, A& K6 J) l6 Z$ j6 T{ 0 U' \. B3 o) e. g3 @$ u, B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
" S. h2 r/ o& ~& I0 |4 pprintf("Press any key to halt:");
8 f+ V# Q( V& igetch(); 4 J, H# o8 D7 D& w$ J1 a% _
exit(1); /* terminate with an error code */ # I- h7 f6 N# l
} </FONT></P>
8 y0 v: U' {8 w0 o<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 W: s3 L1 U/ v9 }% L( Smidy = getmaxy() / 2; </FONT></P>
2 {& h+ H5 I( g/ L/ Y, D' C, h- \7 d- ]<P><FONT color=#0000ff>/* get the mode range for this driver */ 7 T% {( z' r5 _  p1 [
getmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
- T2 P  ~% s& R! |# d<P><FONT color=#0000ff>/* convert mode range info. into strings */
7 V( _1 f; g3 W; `3 b, K/ \sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>/ u8 G7 Z, l0 I- `$ {  C! t& P" N8 p
<P><FONT color=#0000ff>/* display the information */   V% `: K% }: K! r, B
settextjustify(CENTER_TEXT, CENTER_TEXT); - l4 |8 Z3 t+ S+ K. @5 J
outtextxy(midx, midy, mrange); </FONT></P>
# `7 G0 d6 H, C$ ?<P><FONT color=#0000ff>/* clean up */ / `* h7 c$ F8 K9 p# ~/ m0 \+ h: }
getch(); " P9 L3 M: B; t" p/ Y* Q
closegraph();
% O6 Q6 j4 x2 E( U- y% d" [return 0; * ~5 v8 c& E+ i7 m" d
} 7 e- X5 i, Y4 S' p2 o* A
</FONT>
+ i& @0 O% V1 F$ `4 M( L</P>7 I9 ^5 e! k- Y8 u! \0 H" ^* n. ]
<P><FONT color=#ff0000>函数名: getpalette </FONT>
; u/ z# E- g: c4 ?/ ^功 能: 返回有关当前调色板的信息 5 r3 f! {& J1 V% t
用 法: void far getpalette(struct palettetype far *palette);
$ _5 N$ E0 b, ?" G5 H; s; {程序例: </P>
" _2 O: j. }/ A; Q. ~<P><FONT color=#0000ff>#include <GRAPHICS.H>0 S# v. ^2 F, E' p5 w, m
#include <STDLIB.H>
4 v. Z% t: a  y. r4 p5 F#include <STDIO.H>, @5 B- s/ w* K. z$ ]2 e+ O
#include <CONIO.H></FONT></P>
8 B7 D: S1 H6 Y# P8 N& I<P><FONT color=#0000ff>int main(void)
* s' A' Y8 ~1 \+ ~8 x{
: J8 d$ F9 K0 D. j- Q3 K9 p2 J1 W/ M& u/* request auto detection */
: R3 x+ S! F; y8 [; n' ?int gdriver = DETECT, gmode, errorcode;
5 a8 ~# V8 [( E+ f* J* p9 Fstruct palettetype pal; / q8 K  K9 A" K( _
char psize[80], pval[20];
( `) S3 Z: R+ p" ]: f. r- C! Aint i, ht;
  i* {' u3 s* l  T& U* u" xint y = 10; </FONT></P>
- R! h# d5 l/ r<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ k0 T9 F( ~& i+ ?! O5 g8 N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 V' E! l/ d: L  U/ C8 i& S<P><FONT color=#0000ff>/* read result of initialization */ * {) k6 b1 F4 y. ^
errorcode = graphresult();
* C' x0 p! E$ E0 u2 X/* an error occurred */ / ^$ t3 V* ]9 o! \7 l$ ~, I
if (errorcode != grOk)
# p/ c' d) a: \- s{ , `& x. d# i2 A' g  e) o" u0 y
printf("Graphics error: %s\n", ) b8 w3 V  d: X3 s
grapherrormsg(errorcode));
& n2 Y( k: {% y, }& ?2 ~printf("Press any key to halt:"); 4 d3 n+ J9 C, f& _) O
getch();
! B- A5 j' S7 {( Q: g  b' Y/* terminate with an error code */ , h/ I- E- S2 ?; Q
exit(1); + j  r3 X: q) ~6 l1 o8 Y- j8 q9 i4 m
} </FONT></P>, Q: ?8 U# y; k' ]% ~- m
<P><FONT color=#0000ff>/* grab a copy of the palette */ . \" g1 U5 V; A) Q  r) h
getpalette(&amp;pal); </FONT></P>  ]0 E7 e4 y! u. h* |
<P><FONT color=#0000ff>/* convert palette info. into strings */
# O' _$ e& W- q0 A0 k" a# l4 H9 ksprintf(psize, "The palette has %d \ . w. ?) d- v; [+ [  f- c
modifiable entries.", pal.size); </FONT></P>
( h# s. T6 z" p+ a/ K* I<P><FONT color=#0000ff>/* display the information */ / _0 K; o3 _% [5 q4 L6 l
outtextxy(0, y, psize); ! @( \- y* _; U6 j+ x) f1 B: \6 ~
if (pal.size != 0)
* ?6 H/ P- h) \3 M{
3 n$ t3 z* X9 mht = textheight("W"); ) Z$ Z# g+ K& E# i& D" X0 u7 P3 j5 T
y += 2*ht; . y. D( p3 n4 b0 |. x, ]5 `
outtextxy(0, y, "Here are the current \
# X* h4 M9 [$ g/ y# z" Svalues:"); + ]7 P( `) `1 m8 \# O
y += 2*ht; # j0 t& _3 H5 P( w) P
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { 6 D. i* N- d* b
sprintf(pval,
4 d3 e! U- x& q2 b. E"palette[%02d]: 0x%02X", i, " o$ v7 U+ j0 o8 R/ T
pal.colors); 3 ?( b1 d5 a  ~
outtextxy(0, y, pval);
0 U0 y& Q. p; T$ [; n8 g1 c} ) g/ K* A6 a+ L) l
} </FONT></P>
1 U% E- H+ U0 E" c" P<P><FONT color=#0000ff>/* clean up */ " c7 N. K  E3 |4 I
getch();
  f- u* \& F: f# ~! `closegraph(); </FONT>
8 k' I; h0 \9 c/ \6 M  @<FONT color=#0000ff>return 0;
$ }& o& d8 @: a6 Y/ m} 2 k' p. b% \0 r! Y
</FONT></P>
# b6 s0 ?# k7 S<P><FONT color=#ff0000>函数名: getpass </FONT>- l; |# `+ I% i/ Q7 A
功 能: 读一个口令 3 k5 C% l5 l  K. X7 _( S. l
用 法: char *getpass(char *prompt); ' T$ F+ Q( p/ e
程序例: </P>
/ ]/ M* w& a3 g9 W% j<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>/ v  H6 _4 ?' T2 `* m: a, _* i
<P><FONT color=#0000ff>int main(void)
8 t9 {3 _7 T: ~$ D+ }* p- f{ 8 J& w7 A2 _) A; L7 h
char *password; </FONT></P>
! p5 x+ j: b0 _! s/ R7 p/ b  z<P><FONT color=#0000ff>password = getpass("Input a password:"); - z7 ^% E  s- T4 L) Q5 o' \8 f
cprintf("The password is: %s\r\n",
5 n3 e/ w# x+ D5 l) Hpassword);
2 `8 v: B  P. }4 Treturn 0; # r% Y/ S4 n9 c, p* B, c8 H
}
- E8 H# q7 M& l  k4 }% V</FONT>; G4 r/ z& r$ s
9 Y$ h6 f& Z4 o$ R% ~( y  M2 ?
</P>  D3 p+ B% L0 c9 u! g6 x
<P><FONT color=#ff0000>函数名: getpixel </FONT>' M) s: L' Y% z
功 能: 取得指定像素的颜色
* e$ h+ Y1 w+ t& Z, }用 法: int far getpixel(int x, int y); ) \/ d3 N3 L8 I# G
程序例: </P>% U% h; [# T# ~' S# b! ?2 L5 d; U
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* u( _- P+ K7 U- q& s. W#include <STDLIB.H>. F* B! Q# i4 m3 E3 N3 L6 C" d5 h
#include <STDIO.H>0 W3 t4 d/ v' L$ o
#include <CONIO.H># R  R1 k/ v$ i9 p# f2 b6 _
#include <DOS.H></FONT></P>
+ Y4 }% K/ F- E# b" g  b! b<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 4 C1 C% {' E& f5 m
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
4 e$ D% u& |! a  C<P><FONT color=#0000ff>int main(void) % r6 G3 Q- T( \: `/ K$ ?: ~
{ 2 v' D$ D& _: Y) B1 U
/* request auto detection */
! U  Y5 x2 p1 e( Bint gdriver = DETECT, gmode, errorcode; 5 ?( K9 K2 J8 Y6 t
int i, x, y, color, maxx, maxy,
5 q6 ^6 J2 G# T4 M! E: Jmaxcolor, seed; </FONT></P>
3 k7 \- M2 Q7 O2 T* l" ^<P><FONT color=#0000ff>/* initialize graphics and local variables */ . C- U( }$ T6 Y, B% P, Q- q. X/ O2 w
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ h, ~7 [+ y% F% `! L<P><FONT color=#0000ff>/* read result of initialization */ $ H# D+ q  N2 A4 }
errorcode = graphresult(); - _) j" h/ e  ^$ P# D1 U* ?$ R* v6 L
/* an error occurred */ . J6 F% M6 \' H; |! p# \
if (errorcode != grOk) 7 f/ N0 Q( j$ v1 ^/ A7 C) X8 ]
{ 9 l! A' w6 `( B* m
printf("Graphics error: %s\n", / t$ @& @9 Q2 w5 r$ i" U
grapherrormsg(errorcode)); 3 O* R+ w0 x- J* Y& q
printf("Press any key to halt:"); 0 d2 ^" a" ~/ a2 L8 J6 A2 R. V* g$ d0 @
getch();
2 V' k( \6 ^1 A( d# d# S/* terminate with an error code */ 2 Y5 g* w) g* e7 Z! x( v/ h
exit(1); $ C. u" [5 H' ^& G
} </FONT></P>  {7 D2 ^4 A8 X! T% d1 [
<P><FONT color=#0000ff>maxx = getmaxx() + 1;
3 ^- f' |# _. L3 j$ r, g% Amaxy = getmaxy() + 1;
3 x8 U6 H3 e; e$ ]3 Lmaxcolor = getmaxcolor() + 1; </FONT></P>2 L6 v! ]1 H, v7 l# L: Q; ?; c! b) W* ?
<P><FONT color=#0000ff>while (!kbhit())
4 v# ~0 ], }8 m# b{
9 T2 }5 m8 N7 Z/ _/* seed the random number generator */
' Q5 Z7 m* V3 ?5 ?6 mseed = random(32767);
9 D9 l7 _! X! B0 Vsrand(seed);
3 Y& I+ I6 v/ T# B% @* e: y/ ~for (i=0; i<PIXEL_COUNT; <br i++)> {
# w6 d% T# \- [) r4 h( ^x = random(maxx);
8 F( c0 G  U0 u$ G; d1 [y = random(maxy); 0 [9 D( q; V; L% ?# P4 V8 o" N
color = random(maxcolor);
7 p% J' D, Q0 z' Q! s) @* Q6 K  ?putpixel(x, y, color); 7 i/ e  M0 t6 w2 I9 S
} </FONT></P>% N- V- ?9 n0 I, m  K' D: ~, e1 E
<P><FONT color=#0000ff>delay(DELAY_TIME); 9 M5 @( m0 v: X: D$ [
srand(seed); 4 ^0 U2 U) \% ]/ N3 N
for (i=0; i<PIXEL_COUNT; <br i++)> { 1 S% B7 O: ~" u2 e
x = random(maxx);
& c8 R/ x- i% @# X2 s8 n5 Jy = random(maxy);
* J! Z; \9 f5 z* _# gcolor = random(maxcolor); # o. C. D- |9 J  \7 Q; M! D
if (color == getpixel)</FONT> </P>% A) u$ A3 c4 S3 R+ ]) o/ r
<P><FONT color=#ff0000>函数名: gets</FONT> 1 e* Y7 r3 y: D7 Y( q/ V
功 能: 从流中取一字符串 $ \+ x3 w$ m- B) e5 X
用 法: char *gets(char *string);
5 `' S: X+ b" ~8 T% s程序例: </P>
) C4 b/ E$ {5 p( T<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
: S7 Y) a) K7 ^$ U! O. L<P><FONT color=#0000ff>int main(void)
/ r9 t( J$ _" n7 i2 Z{
* ?7 _5 N7 [; z2 ~) l% hchar string[80]; </FONT></P>
4 C. V( F7 V& O' m<P><FONT color=#0000ff>printf("Input a string:"); 3 b4 k% k$ o! G& C
gets(string);
( w8 @. E' i. O7 w& fprintf("The string input was: %s\n", 1 e) W6 I+ R; \7 j
string); 3 _" {7 m) ]$ Y2 g* g
return 0; 8 F, s9 ~  N( V: X+ q+ h( i
} ) U) W0 b. L. J( s7 K

- h; B  l4 y, C4 T* W& ?</FONT></P>
8 o; v$ F# H$ H& G4 W<P><FONT color=#ff0000>函数名: gettext </FONT>
: X' P8 ^0 W, H功 能: 将文本方式屏幕上的文本拷贝到存储区
" U9 A: [6 M: |8 L4 X' p1 i用 法: int gettext(int left, int top, int right, int bottom, void *destin); # D: m" O: z) o4 z" d, \
程序例: </P>" u5 x. C+ b/ w5 D  E4 a; u
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>" t4 W8 Q* ?: @% n0 w% A
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
9 `- _. n8 ~* `4 T7 S6 Z! N) e<P><FONT color=#0000ff>int main(void)
& |9 E7 ]' ?$ F% K( T{
) P; `9 P9 T% D; ]int i;
$ V4 c( O) `1 J: v( L& jclrscr();
' _" [2 B. B. Y  o/ n) |7 n, xfor (i = 0; i &lt;= 20; i++) 6 [1 y/ e. J) z; u
cprintf("Line #%d\r\n", i);
  m5 I8 v3 e% V( ?' Hgettext(1, 1, 80, 25, buffer);
. W8 w+ R' |6 t7 z1 E2 j$ igotoxy(1, 25); 9 x, e$ F! s0 h) s1 O
cprintf("Press any key to clear screen...");
8 h" b' y8 S/ L8 y( Qgetch();
: [7 N0 ~  o- u% M; {4 z, wclrscr(); 2 \+ a7 X& U' m5 J6 _  L
gotoxy(1, 25);
- l5 g- o( b* r0 U% Z1 I2 Q6 hcprintf("Press any key to restore screen..."); 1 q6 w' z7 P7 Q9 v, O
getch();
5 G. h- J3 U8 I. L3 {puttext(1, 1, 80, 25, buffer); 4 R9 M3 T% F+ Y! j0 G
gotoxy(1, 25);
; i  Y2 L- p9 ^$ B# Dcprintf("Press any key to quit..."); * v- t* ~9 n9 C5 ^
getch(); % J  Y0 a# U) ]8 c. E! l3 K' n
return 0; 1 l8 T3 v4 ]5 i+ Q, ^
} % Y) i3 t6 U" J% R+ F, F1 R
</FONT>
( Q5 I8 B0 S6 [9 ^; Z</P>+ ~$ v: R! R5 ?# C0 u
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> + h& v$ l9 `" y. a* n: n
功 能: 取得文本模式的显示信息
- B5 m1 `& X  ]# Z6 a* q- N用 法: void gettextinfo(struct text_info *inforec);
- E) U+ M' G$ b$ p程序例: </P>: ?+ u( h% L- U+ g# |6 e4 A
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
) P3 {* w5 s) v# U+ |4 H, k<P><FONT color=#0000ff>int main(void) 9 G1 b$ j2 ]. Y( @
{
4 W6 s* z6 A; v/ r: Y( X& p2 lstruct text_info ti; 6 n' w( Q. }3 b, E' O+ s+ Y" u7 U
gettextinfo(&amp;ti);
3 N! K6 i' \4 c. m" Z" M/ U+ }cprintf("window left %2d\r\n",ti.winleft); ; ?3 o5 l: G- G  K9 F
cprintf("window top %2d\r\n",ti.wintop);
8 Y' [) u! \* ~% p1 ?4 mcprintf("window right %2d\r\n",ti.winright); * y0 F7 a; O# n1 z9 Q8 B3 [1 o- a2 r
cprintf("window bottom %2d\r\n",ti.winbottom); ; u% p( `4 |$ R  e- P
cprintf("attribute %2d\r\n",ti.attribute); . Y7 y' H0 z4 H! X9 L
cprintf("normal attribute %2d\r\n",ti.normattr); 2 A' L! D. f3 P* v2 d
cprintf("current mode %2d\r\n",ti.currmode);
+ E0 x! J- G. I- Z& b6 y: Ycprintf("screen height %2d\r\n",ti.screenheight); # g4 b3 ?! ?9 |2 T9 R7 x
cprintf("screen width %2d\r\n",ti.screenwidth); 9 r( e& R. Y  _( X) _9 P6 w
cprintf("current x %2d\r\n",ti.curx);
% U* \" V7 Y4 Ocprintf("current y %2d\r\n",ti.cury);
) |+ {' p0 `. L! b, J3 D; L3 Lreturn 0;
" J) q5 q) Q2 o7 s$ G4 A% N} 3 V& i* H6 s# l4 S
</FONT>
) V; N  x* J4 P# p% Z! Z. A</P>4 B  u1 Y+ u( T' X1 z) E2 f4 U
<P><FONT color=#ff0000>函数名: gettextsettings </FONT># S. c8 Z! y6 {2 u/ v: t+ F
功 能: 返回有关当前图形文本字体的信息
/ ~$ l# ~0 G& [/ G用 法: void far gettextsettings(struct textsettingstype far *textinfo);
: B5 b2 J% {0 {' ]# S$ Y% x3 B0 W# w程序例: </P>0 i9 }2 l1 t& Q) d
<P>#include <GRAPHICS.H><FONT color=#0000ff>! @5 v4 T8 Y# `5 ]7 a
#include <STDLIB.H>
3 J2 {" d$ }  Q1 Y#include <STDIO.H>
1 ^2 b4 a" z9 D+ t#include <CONIO.H></FONT></P>
! Z. F; r/ I  X3 W' n) F<P><FONT color=#0000ff>/* the names of the fonts supported */ % Q' R4 M7 [" F3 V0 R. a
char *font[] = { "DEFAULT_FONT",
+ s0 t1 o1 ~, v"TRIPLEX_FONT",
: M% f3 m: ~  ^+ w7 k" p"SMALL_FONT", 3 u4 [  W' b0 e) x. W9 X
"SANS_SERIF_FONT",
  [5 a. `% ~& z"GOTHIC_FONT"
( x4 Z* x9 T3 {}; </FONT></P>5 w* J# i' G9 R( U, |, }$ `+ d% w4 ]
<P><FONT color=#0000ff>/* the names of the text directions supported */ 4 O9 L  Q) c% Q
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>& x' t) D: m: i/ C
<P><FONT color=#0000ff>/* horizontal text justifications supported */ . a" Z5 e( u/ j! F; \% s, G8 ~
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
2 s$ i4 Z! I1 o<P><FONT color=#0000ff>/* vertical text justifications supported */
0 w8 s0 m  |7 K. T9 B% Fchar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
8 c8 p3 K3 L" U+ J! z" K( a7 D<P><FONT color=#0000ff>int main(void) 8 o/ ], e4 ^, N4 R" V
{
" K# N6 S( M6 G2 w3 d/* request auto detection */
) ?* Q+ w4 a2 ]8 Lint gdriver = DETECT, gmode, errorcode; + s+ Z+ H; B+ P% @. u5 X6 x
struct textsettingstype textinfo;
4 L) n/ N: D& b# Z. T& E% d' Bint midx, midy, ht;
4 N1 x1 [! K3 Y1 ~4 x6 @char fontstr[80], dirstr[80], sizestr[80]; 1 q% Y1 P  I+ J* N- Z
char hjuststr[80], vjuststr[80]; </FONT></P>% S+ D. M. |1 D) H: X) e
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; w/ |; s; k' a6 X2 c7 q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  j5 x2 ?% {1 X2 {
<P><FONT color=#0000ff>/* read result of initialization */
! w% p/ y6 \7 t! _0 V1 {errorcode = graphresult();
* y# i; X, |4 a7 @2 v4 Xif (errorcode != grOk) /* an error occurred */
) l% R4 j8 U/ Z. O1 h( l{
: r+ X( z4 o! M: [4 U" X) a* ~printf("Graphics error: %s\n", grapherrormsg(errorcode));
% g' ~# [* h% x, dprintf("Press any key to halt:"); . l$ G" s4 c  b
getch(); # [7 b0 p6 o) Z2 s
exit(1); /* terminate with an error code */
& K1 c9 X- y/ q, ?, n} </FONT></P>' W3 o1 L: {+ h1 [' d7 i8 ]* z
<P><FONT color=#0000ff>midx = getmaxx() / 2; 4 w* d" {# _1 j8 s- U
midy = getmaxy() / 2; </FONT></P>
2 H$ f$ b" g% u% W- f: Y8 `<P><FONT color=#0000ff>/* get information about current text settings */
% H4 \5 j. y% \/ d4 c% egettextsettings(&amp;textinfo); </FONT></P>
% h# m' h9 L- V' g<P><FONT color=#0000ff>/* convert text information into strings */ 3 S0 n; V! G4 V" @- [
sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
- O$ p% A/ \. e- m6 N, `7 Csprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); ( e8 F3 u, H8 L0 o) V7 t4 a! ^2 }
sprintf(sizestr, "%d is the text size.", textinfo.charsize);
: |7 I" [& v. C6 Dsprintf(hjuststr, "%s is the horizontal justification.", % d. Y1 T! k8 Z, y+ H
hjust[textinfo.horiz]);   [: M( K' E( b' ?1 p% l7 n
sprintf(vjuststr, "%s is the vertical justification.",
! V! b1 [5 F( n  d- D, K' lvjust[textinfo.vert]); </FONT></P>! Y9 }) \4 I: \/ v
<P><FONT color=#0000ff>/* display the information */ 7 }5 Z: F$ e9 F8 f  x5 s. |
ht = textheight("W"); ; I4 c- P# k( ~& q2 e. X4 d9 v
settextjustify(CENTER_TEXT, CENTER_TEXT);
; q' I2 I0 q+ q& S7 kouttextxy(midx, midy, fontstr); 7 P5 h% f3 U8 t/ R+ t
outtextxy(midx, midy+2*ht, dirstr);
6 l. z% H8 x9 x7 [- x# T3 f' Bouttextxy(midx, midy+4*ht, sizestr);   I# ]( E0 @6 m* n7 p
outtextxy(midx, midy+6*ht, hjuststr); * B3 I2 W( h4 \! v8 l, \
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>- i* M6 m+ R/ ]! Y
<P><FONT color=#0000ff>/* clean up */
/ S3 ^* ?1 Z7 M! V0 }! cgetch();
  ]2 B- V' q* j& q1 e' `# Wclosegraph(); ( y* Y4 M1 Q: X% h. B" Q/ ]; [' s
return 0; 6 S- z9 }- N% ?. Q
} </FONT>
, `) k+ P# I9 L& s) t</P>
) y8 T# ?! S* r  e& A<P><FONT color=#ff0000>函数名: gettime </FONT>
9 L8 w$ Z7 d5 L功 能: 取得系统时间 # O/ H& ?; Y- a- l, y
用 法: void gettime(struct time *timep);
1 J6 R; r* C2 I6 w" j9 ^6 g9 ^程序例: </P>% K6 B0 k# _1 o4 k+ {6 \" W) z  r
<P><FONT color=#0000ff>#include <STDIO.H>* `5 j; m+ b' Z8 H$ s$ a
#include <DOS.H></FONT></P>
" y; f. |  l. @$ z* O4 G3 C<P><FONT color=#0000ff>int main(void) / h0 \0 M! B, X+ c, I# V
{
  U" R$ C- G: X1 R: H4 M# Z" kstruct time t; </FONT></P>
( w0 f4 r- _  q& N; V0 N/ X<P><FONT color=#0000ff>gettime(&amp;t); 6 r' h$ x8 c4 T9 X" C
printf("The current time is: %2d:%02d:%02d.%02d\n", * j# n( j# ~9 p' x* m6 S7 Y0 \; f
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
, |8 X( e" N: m  q4 H- K) Jreturn 0; : v$ k: Y- c$ @  F* n; x5 Q
}
* G, N3 H5 N. _
! j. j5 ]' _0 x# A. y1 B7 G& L</FONT>% E: k3 D" i: J$ T5 `
</P>8 J7 n1 {  A; U/ ?. @
<P><FONT color=#ff0000>函数名: getvect </FONT>: z& x6 ?! J8 ~! t8 A0 t  f
功 能: 取得中断向量入口 0 y1 N) P. Q8 M7 h+ `& `  A
用 法: void interrupt(*getvect(int intr_num));
/ E. t5 Q, M( k3 P  Y. V9 c( H程序例: </P>
* s+ S% I& j+ |2 ]/ o; q' N<P><FONT color=#0000ff>#include <STDIO.H>
0 w1 e3 Q; q9 Y* N. X#include <DOS.H></FONT></P>* h6 Q. ^: y; ^5 t4 i
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>" s4 a$ w: w; X4 n8 d
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ 5 H. y  X4 R2 Z# d5 I* |
int looping = 1; </FONT></P>
% A4 F( S0 E& q: x# l% Z6 q<P><FONT color=#0000ff>int main(void) 7 e) O/ w7 i! p9 n
{
+ ]( u6 ]: c  @& }" B" e: u8 bputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>! l7 K  h. F4 l
<P><FONT color=#0000ff>/* save the old interrupt */
  g6 k% D4 Z7 {: g2 `oldfunc = getvect(5); </FONT></P>6 e# j# q8 T1 R; R7 o  C. i
<P><FONT color=#0000ff>/* install interrupt handler */ + `4 r% T; `! p- q  c
setvect(5,get_out); </FONT></P>
" K/ P; _9 E( I3 p<P><FONT color=#0000ff>/* do nothing */
: w$ p6 S/ Z, _while (looping); </FONT></P>- ]) k! N6 p! P6 `# a9 t8 ?. I. v
<P><FONT color=#0000ff>/* restore to original interrupt routine */
' g% N- W/ q2 j) U" K. msetvect(5,oldfunc); </FONT></P>
. z' X& g" p4 ?: N1 z<P><FONT color=#0000ff>puts("Success");
& }8 L. t( n( nreturn 0;
( S; `8 C7 F! z# U  ]) u6 o5 Q}
" t+ w1 y/ `5 v3 Vvoid interrupt get_out() 5 \! f  @; D1 N" Z
{
, M3 {' S5 }/ l  W" t+ j3 Klooping = 0; /* change global variable to get out of loop */ 6 z' ]" O3 i+ ~( A
}
& L! c! M4 u% U( |4 v</FONT>! r7 B" ]" f1 u0 [9 Z9 b% @
</P>
" G/ a5 W8 O$ k<P><FONT color=#ff0000>函数名: getverify </FONT>
! b" e2 @) X1 ~+ U, y功 能: 返回DOS校验标志状态 $ _; z& W% I. N2 [
用 法: int getverify(void); 8 [' q' H) S5 A! }: ]
程序例: </P>+ v* _5 y0 r2 c3 U5 U9 }
<P><FONT color=#0000ff>#include <STDIO.H>& |, f% @2 o( |- n/ Z( U
#include <DOS.H></FONT></P># j" _$ h. o4 X; t% }( s" a( J
<P><FONT color=#0000ff>int main(void)
6 p8 {/ j% ?1 l3 ?2 o1 |: f: ~{ ! j; q: ]: ~9 U$ O
if (getverify())
! b6 @3 F# u  k* z4 dprintf("DOS verify flag is on\n");
1 p9 j, S3 |( `- V( g6 e$ z# melse
: e: p: z; O( S) I+ N9 M  Bprintf("DOS verify flag is off\n");
3 k' A! R. `6 y% U* m& X2 C  Greturn 0; 6 F( j0 L7 P' G$ J$ x
}
* A* J, H. S  r2 a3 _3 H</FONT></P>
' K% H& h- X* l$ V, e6 Y7 C<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
! Y( K& O. E2 D: G. f功 能: 返回有关当前视区的信息 5 h- ?4 W: D) W" M+ i) p
用 法: void far getviewsettings(struct viewporttype far *viewport); ; @) ^& W( H& j
程序例: </P>! H) c' o1 @5 r. q4 q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 i- x; {& k' Y* f3 f#include <STDLIB.H>6 t2 _% d, I8 c- X! `- a" q: k$ p* f4 @
#include <STDIO.H>
% f% }$ }- Y: {% T" }& |+ j0 r, \; C#include <CONIO.H></FONT></P>9 o7 ~! m) p. y
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
& ^) d+ L$ h8 g8 \8 c) p9 k$ n<P><FONT color=#0000ff>int main(void) - A# n: Y" h5 k* z7 {8 z0 X. j
{
9 S. s. P; ~& n* n' r9 W' Y9 g/* request auto detection */
7 r0 \2 g- p% \) A  `int gdriver = DETECT, gmode, errorcode;
1 j4 ]/ ]8 C# J' u( X6 Ystruct viewporttype viewinfo;
# R( _- F8 ]- N& @) t% w. g9 Cint midx, midy, ht; 1 B7 F, e, B5 ^9 K* T% R
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
% I; X! ^* Z: @; p<P><FONT color=#0000ff>/* initialize graphics and local variables */
) H% g+ l4 W! A, Ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! g+ Z4 b; O, Z8 R# h
<P><FONT color=#0000ff>/* read result of initialization */
5 L9 l$ l6 J0 e$ w% yerrorcode = graphresult();
( c3 G5 ~" \* n  M* g! iif (errorcode != grOk) /* an error occurred */ 8 K3 h- U' D2 m5 r! s8 M. @
{ ; {7 c# k3 _8 @3 g- l+ `
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ {7 ]" H5 K/ P9 ^: B2 U: Uprintf("Press any key to halt:");
: s# u. Y- q' _- D: bgetch(); 5 T$ e1 m( d  B* _" N9 v. u
exit(1); /* terminate with an error code */ # ^) `( G+ q8 C! {% _) e
} </FONT></P>7 x1 Q. h2 j& v
<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 F, a: {$ i4 J+ r9 M' I5 qmidy = getmaxy() / 2; </FONT></P>; Q' R# C! d( w9 c4 D0 J
<P><FONT color=#0000ff>/* get information about current viewport */ ! J7 e9 r5 o% {8 Z7 \2 Q4 P# u: N
getviewsettings(&amp;viewinfo); </FONT></P>" m$ @2 n, W) k% B. t
<P><FONT color=#0000ff>/* convert text information into strings */ , S% }6 h3 s  L
sprintf(topstr, "(%d, %d) is the upper left viewport corner.", ' g' m$ p: W2 y  Y
viewinfo.left, viewinfo.top); 1 G/ h. g, r2 g: G( j* U( L
sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
; K* t* w. h% y+ w! Xviewinfo.right, viewinfo.bottom); 9 k1 z* p* e- Z1 E8 Y+ o& z
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>$ T0 c/ K) q0 @8 e
<P><FONT color=#0000ff>/* display the information */ 3 }7 _, A* {  ]5 W
settextjustify(CENTER_TEXT, CENTER_TEXT); 7 K/ V) }! |' ]* Z2 m% J- P# r
ht = textheight("W");
+ v# ~* M2 U* |$ ?outtextxy(midx, midy, topstr);
3 l( X+ @3 j& {outtextxy(midx, midy+2*ht, botstr); : I, e8 a' a) h; z" M6 }- {5 m3 U9 u
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
- Q6 ]  G, c; a6 r5 K<P><FONT color=#0000ff>/* clean up */
: k- M. q$ S' a; D3 h$ s$ Hgetch();
2 ], [  B$ K2 y# M5 Y, `7 _closegraph(); 5 k5 p, [1 {0 v
return 0;
) y: [. J, A) U} </FONT>0 W: u* v5 l! O' X

. K0 J5 _- r, H) A) y$ v% b</P>
4 e& ^! {8 M; L4 w' [( [<P><FONT color=#ff0000>函数名: getw </FONT>* Z2 O2 a/ j" _$ X* Z! o
功 能: 从流中取一整数
: V+ `) d& C8 [- w用 法: int getw(FILE *strem); 5 @% X" k6 k" ~) u! o
程序例: </P>/ I% j( W8 [/ T/ N4 ]1 j" I2 S
<P><FONT color=#0000ff>#include <STDIO.H>+ C/ r3 F+ |, Z+ M' \
#include <STDLIB.H></FONT></P>
2 W; f4 |# O$ o2 Z5 ]<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
% Q3 G8 g  k- Z1 L7 }" _<P><FONT color=#0000ff>int main(void) 3 A! E: J; s+ ^' t1 B0 }( m
{ % X+ S- H! V) j
FILE *fp; 8 r' H- _4 s# j6 q
int word; </FONT></P>
( J4 E! c1 K9 o) Q1 f( [! j5 g* f0 I<P><FONT color=#0000ff>/* place the word in a file */
; F  o5 ^" w" Yfp = fopen(FNAME, "wb");
6 _1 Y5 w3 k0 a  F  s" Hif (fp == NULL) : }+ D3 `0 n2 ~1 }' a
{ 5 X% E- v6 {0 k
printf("Error opening file %s\n", FNAME);
8 b/ {& s) e2 ^1 Zexit(1); : W& I4 `) y  O* Z5 N0 O! Y5 c' E
} </FONT></P>
# }) U! Y; X" d( N6 T3 Q9 E<P><FONT color=#0000ff>word = 94;
" ^/ C4 u0 N) B+ j. p  `putw(word,fp);
- K. ~' ]$ R% {/ |7 Qif (ferror(fp))
) a: L; m7 @, N1 I0 wprintf("Error writing to file\n");
, E5 C/ u9 \  u% p: Z* [else
" ?8 v* ~/ f3 ~, N+ N, @# O8 _printf("Successful write\n");
+ F1 N7 K" n$ k. t$ d( Y8 ~$ mfclose(fp); </FONT></P>
  F! y. M" X) x  s<P><FONT color=#0000ff>/* reopen the file */
# `! H4 Q0 j1 q$ u8 C# bfp = fopen(FNAME, "rb"); 9 X5 u6 T  y5 v5 G* R+ h& m
if (fp == NULL) 2 B) l  w& H: ~5 F0 b
{
: q; H) P8 A% \9 ]& lprintf("Error opening file %s\n", FNAME); ! t! x/ b$ R3 U+ B  ~5 d) ^9 M3 x
exit(1);
2 `6 _& z- t. G4 c} </FONT></P>0 j( X1 b7 {% m6 v
<P><FONT color=#0000ff>/* extract the word */ 7 e. x8 z# M6 X. A' \
word = getw(fp);
0 A9 T. M6 ~: d. ?if (ferror(fp)) 8 M4 }  o: R  y* R- b9 }& f  T+ P" B
printf("Error reading file\n"); . W' M3 Z  o5 e/ {
else ' E6 r* y; n  c# s9 W$ n
printf("Successful read: word = %d\n", word); </FONT></P>% A& y& O, O; Y9 `- Q
<P><FONT color=#0000ff>/* clean up */ ( r6 ]2 e0 ~* T7 J( N: F
fclose(fp); 2 Q! T: {& D& N; @7 H
unlink(FNAME); </FONT></P>
) y9 C+ C! ]: }: j0 E0 I<P><FONT color=#0000ff>return 0; 2 N5 m" r, U: M$ n; G
} </FONT>
/ ~; u! v1 _! e* p
/ p. C4 A2 G) r8 d) [+ y
- f! g1 {2 S/ Z</P>* r* U, T, `7 X5 `1 s* c) u
<P><FONT color=#ff0000>函数名: getx </FONT>+ h2 F: A4 z3 f( O
功 能: 返回当前图形位置的x坐标 ) }" e* O3 ]8 \( H! O
用 法: int far getx(void);
2 D2 a. g: B! L/ ^3 s& y1 u& C程序例: </P>3 y) E: O: X6 l& l$ J
<P>#include <GRAPHICS.H><FONT color=#0000ff>+ b1 x( q5 o# {: Z, O  f5 }4 e* k
#include <STDLIB.H>
; Y4 U& Q6 k1 r" l. ?#include <STDIO.H>
7 _, b& M/ j, c# n7 b! G4 }: c#include <CONIO.H></FONT></P>+ v% T6 x1 w  \* K. ~
<P><FONT color=#0000ff>int main(void) 7 Y( [  m' I' }5 K: z2 Y* y2 u
{ ; x/ _# R+ D# m3 t: B4 C, @
/* request auto detection */
- y: s/ J  X# g9 v* H+ Aint gdriver = DETECT, gmode, errorcode;
+ R# M0 s1 o& {% Y0 [, E/ {4 x' ichar msg[80]; </FONT></P>. ~  i( ~& B0 J3 G% R4 r+ t
<P><FONT color=#0000ff>/* initialize graphics and local variables */
  }7 E: e- M% _/ H, q/ @% Rinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 t+ Q% `4 d5 w
<P><FONT color=#0000ff>/* read result of initialization */ 0 O, x4 r! {, R
errorcode = graphresult();
2 l' A. B2 H+ C4 j5 g2 {4 v' hif (errorcode != grOk) /* an error occurred */ . t& e; R  P0 {* u& T5 `# j
{
0 o5 Z  I, j& f, G) T: Dprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" b( c3 [: \& O% U/ {printf("Press any key to halt:"); , b+ f% \/ i3 d3 {5 S9 _) G" A+ b
getch();
7 H+ R+ [3 ~8 \exit(1); /* terminate with an error code */
1 C9 w! W7 ?8 l7 o) A} </FONT></P>8 m' p1 a" G+ d8 m  M, l# I
<P><FONT color=#0000ff>/* move to the screen center point */
5 J5 C+ T$ h" }& k2 J9 x. q  Smoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
! t% i# L9 I/ K  G<P><FONT color=#0000ff>/* create a message string */ : S* s9 o* f$ \# _% X' J: Z
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
: m- `0 U# K- t( P8 N6 I- H<P><FONT color=#0000ff>/* display the message */ 4 m$ U3 o( d/ u; u3 ^3 k
outtext(msg); </FONT></P>1 d  o( `# h" I; m9 P9 U/ e. u; n
<P><FONT color=#0000ff>/* clean up */
: G$ m5 M/ N  I( ^$ c* K. X$ mgetch();
! B% p, q5 A% U  w, o: eclosegraph();
9 Q- f8 h9 v$ \# nreturn 0; 4 p' t  d! W* I" Z! ?. \* n
} </FONT>* S5 G/ X! `  ]1 P5 V' E' z0 m) q5 ~0 _- y
% m2 G' ^- e0 `) n. s) v# j
</P>
/ X4 g- X! f1 e8 \<P><FONT color=#ff0000>函数名: gety </FONT>- V: q4 X3 }' e  E* c- S  L
功 能: 返回当前图形位置的y坐标
$ L5 f, Z' T) x3 I! l, j用 法: int far gety(void);
8 c$ z& `: D" l( e9 I程序例: </P>8 K& R5 N2 P, w6 g$ @$ s7 P/ ]* c
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 U; S& e* s) G& \, M#include <STDLIB.H>2 T" v  D; y# X- J" Q+ q' F: I
#include <STDIO.H>
- w8 ~5 A; c" w$ }& T& z& `#include <CONIO.H></FONT></P>
' D0 H/ ^0 U# U7 B$ i2 f& d<P><FONT color=#0000ff>int main(void)   {! u3 V8 _( [% P( Y
{
/ X1 p: q9 \4 {/* request auto detection */ 4 l) [1 m. l9 g+ b) H* u
int gdriver = DETECT, gmode, errorcode;
6 u! E4 I4 K/ M4 jchar msg[80]; </FONT></P>) @: u( W9 Y: L# ^$ M1 @
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " X% e$ ^3 ?& ~) ]! v: a6 K
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( B0 q/ v/ ]" N; Y& o
<P><FONT color=#0000ff>/* read result of initialization */
! e5 }- ^5 Q) S9 y! U% Werrorcode = graphresult(); 9 o( c& U( t/ w( ~
if (errorcode != grOk) /* an error occurred */ 1 `! X) R: _" C4 F9 ^/ \* G# W0 `
{   J$ ]" {7 t1 S* b  u& E( P
printf("Graphics error: %s\n", grapherrormsg(errorcode));
" v7 n* Z4 F7 n8 gprintf("Press any key to halt:");
1 C" s- h+ l  W# p: y. K" ogetch(); ' C. w2 F8 B* g
exit(1); /* terminate with an error code */   `4 v: a. r9 v8 |' z' g/ ]; T% l# e0 N
} </FONT></P>
$ l2 V$ F& i9 o6 S" x" N3 \<P><FONT color=#0000ff>/* move to the screen center point */
% F- f$ x7 |: F8 B' q- hmoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
+ h$ |$ {! d' X: ^1 l* ~<P><FONT color=#0000ff>/* create a message string */
$ ?- l3 G: g/ ~% wsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
0 E# r2 C4 ~( B<P><FONT color=#0000ff>/* display the message */ # j) y; x+ {& c# o& ?( x" w5 r
outtext(msg); </FONT></P>
1 L2 S! F/ ^; j! n7 f; X' x<P><FONT color=#0000ff>/* clean up */
, H6 Z+ G; N1 Y4 @getch(); / Z3 ^- V) h5 l& }. p) @" h
closegraph();
; [4 t8 p, h* V# P4 Lreturn 0;
* c. D) ]2 \8 ~9 q+ j  U  t$ F} </FONT>- n- T8 ^& O# P/ {% w- j- e4 @

: i$ ]; e. O8 `- z& T</P>
9 @4 I$ j( @" s<P><FONT color=#ff0000>函数名: gmtime </FONT>
$ i6 O4 u& R% o# O, }功 能: 把日期和时间转换为格林尼治标准时间(GMT)
1 U7 G! k3 V9 q/ @4 {/ `4 m用 法: struct tm *gmtime(long *clock);
, O' s+ \! B$ F8 Y+ I程序例: </P>: l+ {% d0 o' ~; @6 ^
<P>#include <STDIO.H><FONT color=#0000ff>
. P- P, l0 b( D3 X6 }4 r#include <STDLIB.H>, |! R7 W4 H: z6 B5 J$ D7 e& u
#include <TIME.H>
/ ^: W6 B. ?' L9 q; @7 I#include <DOS.H></FONT></P>
9 x5 d: w  s( u8 A& A<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
' g4 B& W/ ^. Bchar *tzstr = "TZ=PST8PDT"; </FONT></P>
3 I" g0 u/ H' d# J- H! U7 E; H<P><FONT color=#0000ff>int main(void)   V, [9 }7 _5 b. O, j  s3 t
{
1 ?9 \" p: ~, A: B4 h6 Htime_t t; * G7 _3 [+ P1 t2 E4 y4 M* h: q
struct tm *gmt, *area; </FONT></P>
8 Q- N' g) y  t; ^<P><FONT color=#0000ff>putenv(tzstr); ( B- T, H1 d' C' J) p0 Y1 u6 t
tzset(); </FONT></P>
" j2 @+ t5 e* ?' D+ H<P><FONT color=#0000ff>t = time(NULL);
9 n6 h/ h. c& n. a) ~9 {area = localtime(&amp;t);
" C1 b  O# m, y+ m. W1 ^printf("Local time is: %s", asctime(area)); 2 Q; Q: f' p* k
gmt = gmtime(&amp;t); - U# q  t) o2 d
printf("GMT is: %s", asctime(gmt)); 4 r  T+ r8 q" [9 H: g3 v
return 0;
) Q1 b& {" S2 b} </FONT>
* Q* L: e0 Z1 J4 H2 I. J: p) B- e% M: ~2 x" o9 V2 W; U
</P>
, H8 N- Z% Y3 |& j<P><FONT color=#ff0000>函数名: gotoxy </FONT>
3 Y5 L( s2 x9 Y功 能: 在文本窗口中设置光标
; _/ Z% Q- d2 h8 h/ P7 R" G( P& I用 法: void gotoxy(int x, int y); 2 g0 J: R4 `# z, t2 [$ n6 Y/ D  H2 U2 V
程序例: </P>. r% \: s% y& ?/ k2 O
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
" R6 C! n2 S, T; R) u<P><FONT color=#0000ff>int main(void) 0 ~/ @0 |0 |; R, O' m. V
{
7 o3 L3 D. r* c9 ]8 b% S" |clrscr();
) B' G4 j: z" C8 X* F" ]gotoxy(35, 12);
* h  d, Q0 H7 O' p/ Q, ucprintf("Hello world"); 6 Z# b( W% X7 L( x$ l7 q
getch(); " Y0 |; g& h# G. G
return 0;
6 m1 }2 E( T# |5 |1 D}</FONT> 6 d/ Q6 g8 v7 M+ a* k$ d

( p. a, j' H. ^! h</P>
$ a1 K' X& h( D$ y$ {1 D. z6 Y! N<P><FONT color=#ff0000>函数名: gotoxy </FONT>0 m7 R- H$ F: s) ^- E. l
功 能: 在文本窗口中设置光标 8 ^0 P. P" A# }2 d2 ], N% M
用 法: void gotoxy(int x, int y); 4 q8 d1 w2 h& h' r1 R: V/ X
程序例: </P>1 B8 F5 T1 A" T8 M$ f5 Y2 ]0 P7 \0 t
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>* m& `+ `- W. G6 L- g3 P5 e
<P><FONT color=#0000ff>int main(void)
9 r) X; A  R: K! q9 }5 T2 R8 t& ~% @{
* K. {, s% D7 Qclrscr(); + U4 j1 W$ I1 g* }5 w0 x
gotoxy(35, 12); ( g& l9 u1 u3 E: K- \3 g! {' _
cprintf("Hello world"); 7 Q% h  K% U  _$ n* N; T
getch();
, G% F( j5 [8 q0 P- K' ~# `# sreturn 0;
6 v# ^. T" X4 y! }+ c2 C}
; `4 g  N% W7 e$ X* F+ G</FONT>* f( m( D! B) B  Z- \' \9 c  X
</P>: |- o3 A0 i* B; \& W( J' A6 G: I
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
8 m1 |) \# D0 I  b/ [! d5 o; q. `' ]功 能: 将所有图形设置复位为它们的缺省值 - Z( O# W6 f9 @3 k/ z8 m+ f
用 法: void far graphdefaults(void);
6 a- W7 h/ `! r- Y1 `+ |2 t  L程序例: </P>
8 |' v& l. P2 C5 {- q# b# o. l<P><FONT color=#0000ff>#include <GRAPHICS.H>* b/ P: m/ l. Q4 }% r" `$ L
#include <STDLIB.H>
% z0 P( d  O6 {# P( ]; e6 K#include <STDIO.H>
% }$ r: |" @. A0 q( O1 z* j4 @: u#include <CONIO.H></FONT></P>
- {2 [3 H9 ]* \8 l7 @<P><FONT color=#0000ff>int main(void) + K1 W) U5 z' w# J9 a) g- g  D
{
/ P; ]0 J; k: T/ p5 L/* request auto detection */ " G3 Y9 B! @3 P
int gdriver = DETECT, gmode, errorcode;
( Q: U$ B6 [- h1 U5 L& D1 b# F' nint maxx, maxy; </FONT></P>2 [( a0 k0 S* Y3 a! ]# N% _
<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 U0 v& J7 T6 i6 f9 e( C' Qinitgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>2 V+ t& O* [9 j% h9 }
<P><FONT color=#0000ff>/* read result of initialization */
& z3 Y& P, O- K) h0 R# s8 F* R- Y4 Serrorcode = graphresult(); 4 i- }6 U1 b5 m; S0 x! @' z
if (errorcode != grOk) /* an error occurred */ 4 P8 d. G/ i" V' ^9 y$ M  Q. h
{
" g' ^3 C" O! |4 P, x" p$ _printf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 N, \2 m+ C- [* Z0 h# q
printf("Press any key to halt:"); 3 l3 N2 s, {' j/ g7 e* {0 T
getch();
! l3 ?2 _0 [! R& K$ H" c+ }$ Y; Dexit(1); /* terminate with an error code */
8 x$ E9 I0 x' Y( L} </FONT></P>) Y+ e% w; e* }1 C. @% O. }8 C
<P><FONT color=#0000ff>maxx = getmaxx();
3 s. d! c7 ?, p9 zmaxy = getmaxy(); </FONT></P>" U( B( B9 L2 L4 }  D3 B9 w
<P><FONT color=#0000ff>/* output line with non-default settings */
0 n9 X3 K6 H4 {$ \' Zsetlinestyle(DOTTED_LINE, 0, 3);
# G" g* Y! x. jline(0, 0, maxx, maxy); $ Q: E$ \* I9 a8 h+ b4 W# S
outtextxy(maxx/2, maxy/3, "Before default values are restored.");
2 x$ ?/ v, }$ {, L/ \( |getch(); </FONT></P>
& g- {2 @, g! ]' @<P><FONT color=#0000ff>/* restore default values for everything */
4 c" {1 j4 V& E$ Q5 F8 b' Rgraphdefaults(); </FONT></P>
3 h4 |" Y' @1 t7 Z$ H; B<P><FONT color=#0000ff>/* clear the screen */
2 _: V# x! V' F; H* Kcleardevice(); </FONT></P>7 O9 c1 `; B; m3 L% U1 e1 N; y
<P><FONT color=#0000ff>/* output line with default settings */ 6 z. L6 [4 q1 |4 b
line(0, 0, maxx, maxy);
' r6 _6 X" U+ n; q( oouttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
, f! O% ~$ ~7 A( I4 k2 f* Z<P><FONT color=#0000ff>/* clean up */
- L& ~6 G! G2 \( n* q8 Y. ?5 xgetch();
% q4 C' @5 l! x& V, J5 N& ^6 iclosegraph();
5 |- q' o  q- ]return 0; % E/ y8 Z0 c8 S
}
/ c% c2 V  g% ]; X! j</FONT>2 z' m8 M* I; F3 D2 S5 r' @7 t- N/ E
</P>9 p* Y& A) [/ |3 e5 Y: u
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>, d/ v/ p% Y' @* ]* `8 L
功 能: 返回一个错误信息串的指针
+ c7 S4 z) u' O9 d& F- N, k用 法: char *far grapherrormsg(int errorcode);
4 |( Q9 p+ i6 s- K- Y* U3 o程序例: </P>
$ g6 l. N& G( A* V<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 i+ P3 v& u# k7 ~! w0 F#include <STDLIB.H>) n" L6 W$ f8 s, D" X3 @
#include <STDIO.H>
  T" }  H5 w4 \5 ~9 n- z7 g#include <CONIO.H></FONT></P>
$ v# T* n/ l% w8 ~+ l8 {<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
9 {, j0 j& o& s! i+ V8 j: B# e' d3 ^<P><FONT color=#0000ff>int main(void)
( \8 \0 }6 ]' W{
$ l" P* u9 F8 R4 N5 j3 {  K2 ~% B/* FORCE AN ERROR TO OCCUR */
8 S: ]; u2 t3 y# pint gdriver = NONSENSE, gmode, errorcode; </FONT></P>1 q) ]1 Q2 P- U* `
<P><FONT color=#0000ff>/* initialize graphics mode */
3 `- z, K) d9 X- [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># Y& ]2 k0 L+ _& H# I8 t( T5 j, f
<P><FONT color=#0000ff>/* read result of initialization */ ' Z, u1 \+ b: I2 w, b4 W9 R
errorcode = graphresult(); </FONT></P>
5 s" ]: n0 _2 D. I% s& U" i" z  l<P><FONT color=#0000ff>/* if an error occurred, then output a */
6 I. K7 T& C- K* r! G2 [, k% n- I/* descriptive error message. */
: C% Q' U; I" I2 J; W0 s* i: I+ V( Kif (errorcode != grOk)
" d$ _; u- Z( v+ _{ / E, E. `6 |9 W: H
printf("Graphics error: %s\n", grapherrormsg(errorcode));   a; s! f6 C* d6 M8 Q) K
printf("Press any key to halt:");
6 n9 E6 w; d7 z. ^5 t1 Ygetch(); 2 p4 N+ d! g8 U. x2 ~! N* I4 \* w" f
exit(1); /* terminate with an error code */ ; {1 T3 ^& H3 l
} </FONT></P>
) J! k5 R0 g- t& s<P><FONT color=#0000ff>/* draw a line */
1 Y: F/ @# ^" s! ?' Y+ }8 @  Wline(0, 0, getmaxx(), getmaxy()); </FONT></P>" I* N; _6 N( b  r2 _. t- o
<P><FONT color=#0000ff>/* clean up */ , {+ p2 s& L1 n; ]7 t
getch();
8 w' O. S8 P& R& yclosegraph();   O8 w; V8 Z/ \/ C7 @& j2 x0 S
return 0; 4 ]" c6 z6 A; a( b. W
} ) l% Q. v4 m- a+ _' J: A
</FONT>
; D( Q1 E8 a( d$ p9 j3 {- g8 g</P>
$ E8 e3 l' Y* d. X7 ], M! M: C( y<P><FONT color=#ff0000>函数名: graphresult </FONT>0 D+ {+ S; f. W
功 能: 返回最后一次不成功的图形操作的错误代码 3 w4 `1 u7 a) y. s; M5 L
用 法: int far graphresult(void); # M2 l6 Z( Q6 B" D9 h" M$ w
程序例: </P># x! T% H2 `. V
<P><FONT color=#0000ff>#include <GRAPHICS.H>/ B5 j0 [" I7 x+ {
#include <STDLIB.H>, G% z& H- ]- d% b/ P  A( v4 n
#include <STDIO.H>
0 y  n- i, Q6 p1 K  V* I#include <CONIO.H></FONT></P>  ]5 j; X8 N* b. G. c; r
<P><FONT color=#0000ff>int main(void) / Z8 z7 n0 m+ V, i1 V! H6 [
{
! U  `. d& x2 W& V; Z6 r4 F1 u/* request auto detection */
/ n5 _7 ~- C, O' Kint gdriver = DETECT, gmode, errorcode; </FONT></P>
% A4 o$ k" H/ R9 ~, m( o7 q<P><FONT color=#0000ff>/* initialize graphics and local variables */ - t# u* j( s9 h4 O; t' z1 T; S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 A- o. A5 T8 M0 R% E( H<P><FONT color=#0000ff>/* read result of initialization */ 9 W6 N4 q* o) h, P
errorcode = graphresult(); </FONT></P>1 ^: G6 l% _+ g9 R3 j+ Q* H
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ 3 e6 m# B4 d5 `8 b' I' W  v
{ ) _% _8 a  t6 I) G- W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) Z6 m5 r$ j( ~8 ?
printf("Press any key to halt:");
7 y1 e' m9 c5 K/ [! Q, U" jgetch();
7 U/ T2 }8 U2 Y- iexit(1); /* terminate with an error code */
: y* e2 n) y; w3 O} </FONT></P>8 K1 s. T- f7 e* c6 ]
<P><FONT color=#0000ff>/* draw a line */
9 B2 {; L/ t& k+ Mline(0, 0, getmaxx(), getmaxy()); </FONT></P>
  @* M, ^/ n% j& ?1 E  ]( X2 R! ^' j; c<P><FONT color=#0000ff>/* clean up */ ) R) Q+ ~6 }8 j. Y6 U3 F
getch();
4 S5 X7 c# X% ~! ~closegraph(); : f+ N& t; P% w) x
return 0; . a) U5 f! Y" Z9 L0 l
}</FONT> 5 {2 u- c8 M/ s1 s! q
</P>% P' \6 X4 D) n
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> + P1 n: Y9 e5 {. X: ?
功 能: 用户可修改的图形存储区释放函数
  `6 B/ F, F6 Y6 T7 L9 h用 法: void far _graphfreemem(void far *ptr, unsigned size); , Q( E; N! H" j- X% R1 A. W  C+ J3 V
程序例: </P>2 f3 N' R7 q) o* z
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 ^8 Q5 o% e6 W0 F) F+ W
#include <STDLIB.H>- W$ k. u9 [1 j6 w# K' F
#include <STDIO.H>
* [$ I( x$ P# Y" K# }4 V#include <CONIO.H>+ e/ d. _9 \" o8 V; E
#include <ALLOC.H></FONT></P>; L) Z8 ?5 `1 O
<P><FONT color=#0000ff>int main(void) 1 X$ y. @. X/ X  q( A; ~& N
{
* u3 O# Q& M: s. s) j/ n7 p/* request auto detection */
) u9 z  T# B% Z2 n- t2 U2 p3 w! uint gdriver = DETECT, gmode, errorcode;
) {# ~4 w1 p6 L8 `  Wint midx, midy; </FONT></P># f! v  m) p9 |
<P><FONT color=#0000ff>/* clear the text screen */
+ }% k, i, j4 gclrscr();
) l0 e! a1 }( _* t0 L2 Z8 G9 eprintf("Press any key to initialize graphics mode:");
/ z1 S% P6 S- a6 P  p9 I+ Rgetch();
! j% r8 g! c' V6 fclrscr(); </FONT></P>  G4 `  R: C( J7 p0 f) X* E
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) Z' d! |# E& O1 b- \) l- d; {! H0 R/ Z
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># _! ^. C' S/ U
<P><FONT color=#0000ff>/* read result of initialization */
% l0 \* X% \' qerrorcode = graphresult();
8 L; u% G" }4 i' V7 b4 U( h, a5 Wif (errorcode != grOk) /* an error occurred */
, R. Z! s( [  |9 ?{ ' i9 u; E; v0 b" r: [
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 ^+ o2 H: T! bprintf("Press any key to halt:");
+ n0 i# l0 s% E. Ygetch();
' x, Z0 ]1 _/ gexit(1); /* terminate with an error code */ $ g+ A9 w7 l& S0 @( w6 A
} </FONT></P>+ ]4 d( z5 [/ ?8 a
<P><FONT color=#0000ff>midx = getmaxx() / 2; % |) `& ~! G+ f
midy = getmaxy() / 2; </FONT></P>
. D" W2 z, D1 C% h8 v+ S0 E* o. R<P><FONT color=#0000ff>/* display a message */ 5 |! j( U& _  j8 x
settextjustify(CENTER_TEXT, CENTER_TEXT);   v- a1 Z3 u, b" W, r& D7 }$ a
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
9 n- K; W; d& Y<P><FONT color=#0000ff>/* clean up */
2 a' |8 `, M, _7 W6 N1 t) egetch(); 9 I; A; g9 h4 Z( D- x# ^
closegraph();
+ \; v% O2 e! u/ q$ Z7 Ureturn 0; / [( G8 Y8 i- n) {2 d% U' v" t
} </FONT></P>
/ @* `! z: B9 W) h<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ % [4 C+ b, P2 ]' \' V. `
void far * far _graphgetmem(unsigned size) 3 i: {9 V2 e3 q. V. Q
{ ' t) b+ r  R- K7 o8 R
printf("_graphgetmem called to allocate %d bytes.\n", size);
4 J6 J1 `. P/ Z) V- @% wprintf("hit any key:"); " ]$ \+ v: J4 e( x0 z/ i0 n% K
getch();
; A' P0 R% W& d) qprintf("\n"); </FONT></P>
8 u& J7 ^$ M9 y, U% p5 R( i, i& W<P><FONT color=#0000ff>/* allocate memory from far heap */ : f$ _& t2 G' [
return farmalloc(size);
) J+ _5 V4 \: s} </FONT></P>  a* X# t5 P( r) n1 y7 c
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ 6 D9 m  Z7 }1 i/ n! u' O% B, N
void far _graphfreemem(void far *ptr, unsigned size) 7 n6 `9 W$ ?( }. k; ^0 ]; O, M
{ . J8 z0 D$ F3 A" O) d2 u# g/ ^
printf("_graphfreemem called to free %d bytes.\n", size); 2 S9 X+ X  s5 L% r' X3 c# Y
printf("hit any key:"); $ [" Z2 b* Z, R1 a, j
getch();
/ E, x- Z  I+ v7 X# m' Dprintf("\n"); </FONT></P>
8 H! `: i! _) W' f  G' L+ @<P><FONT color=#0000ff>/* free ptr from far heap */ 8 i! r8 ~' B- h( {/ h
farfree(ptr);
0 a. N, m) l$ d2 l}
9 s+ @  G% c1 {; _+ m* M) ?</FONT></P>$ Q/ P3 |) \, w6 _2 d8 X
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>0 w* B$ B2 B" g9 R; O  m3 I
功 能: 用户可修改的图形存储区分配函数
0 [' I; }7 y' t' J: T& N# Z6 N用 法: void far *far _graphgetmem(unsigned size);
; @+ k; d2 {; Y, o( i: `+ u程序例: </P>
" n* ^9 @1 m* z  S<P><FONT color=#0000ff>#include <GRAPHICS.H>4 B4 l6 A/ E9 L2 J
#include <STDLIB.H>; g5 b: y" {$ Q" u
#include <STDIO.H>- D8 g. C9 z; d+ E
#include <CONIO.H>4 i. t; ?' J3 P2 j
#include <ALLOC.H></FONT></P>& R% v8 u* }( G1 l3 B  S7 k
<P><FONT color=#0000ff>int main(void) 1 R5 j. z, e7 t* [
{ 6 k9 [* v) O" [/ c3 K
/* request autodetection */
* W, I: O6 V0 U% }+ @9 S. yint gdriver = DETECT, gmode, errorcode;
7 }9 ~0 H( Z3 e; a4 I+ Y3 xint midx, midy; </FONT></P>
9 d) S/ X* s7 d4 m<P><FONT color=#0000ff>/* clear the text screen */ 6 c, z0 P2 K4 M: r3 E- d
clrscr();
7 {( f. P3 B# v6 O) t7 w6 e$ Oprintf("Press any key to initialize graphics mode:");
' u& t+ L* W! s) I& d9 Egetch();
# _: O* @- l) c9 A1 jclrscr(); </FONT></P>
0 ?# x" I8 b% |! c# }; a$ M$ r<P><FONT color=#0000ff>/* initialize graphics and local variables */
# k7 k: k2 B! e! O8 w0 _: R# Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ i% O8 z, o3 \
<P><FONT color=#0000ff>/* read result of initialization */
- K: a/ d  m3 p( ?' F' _errorcode = graphresult(); ; D9 a5 q, D5 V) P7 a! H
if (errorcode != grOk) /* an error occurred */
' z4 k5 ^4 X. @+ p3 ]6 r6 u{ / u3 G8 z+ Q# ~' D3 E. J7 {7 w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + @# A, H& M8 [' f% s
printf("Press any key to halt:"); ) \: g2 D( v* I$ G
getch(); 0 L- q% v% B3 ?
exit(1); /* terminate with an error code */ 7 q' d$ |- H/ I+ ~$ x0 k
} </FONT></P>
' U; X1 {+ m! T1 d, o# @* _5 G<P><FONT color=#0000ff>midx = getmaxx() / 2; . x! U" a/ M+ G3 ~. v- ?
midy = getmaxy() / 2; </FONT></P>
, n: n5 C  m* t7 X; j7 |; W<P><FONT color=#0000ff>/* display a message */ 2 \3 ~* U) C. F6 i
settextjustify(CENTER_TEXT, CENTER_TEXT); : N, v* F* M6 Z  K; }3 ~9 Q
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>) {# J( Q' M4 Z- \, c6 w- W" k5 G
<P><FONT color=#0000ff>/* clean up */
5 p6 w& f3 [/ _! m. e& Dgetch();
, p: ]& V/ n8 l( Iclosegraph(); ; Q9 [4 H4 Q$ }3 `& W, R, y* F
return 0; % v! j: \( F: A$ z) u- g+ e
} </FONT></P>
+ w* h: K8 I4 L9 d% s1 m, ~<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */   n! X. B2 `) H* w) [
void far * far _graphgetmem(unsigned size)
3 g8 j  N' D# e( q2 F: K{
. |& s% W: R# k& q( U0 Bprintf("_graphgetmem called to allocate %d bytes.\n", size);
9 O4 n, \% o& jprintf("hit any key:"); * b0 x  @) m0 l  N- e& p8 t
getch(); 1 h# j- _, o# O0 F2 z6 Z& O0 T& B
printf("\n"); </FONT></P>
% ^$ u* v5 [. r  S, H* J! n2 p. ^; a9 G<P><FONT color=#0000ff>/* allocate memory from far heap */
7 _2 M7 S% Y& ^6 ]4 M# {, mreturn farmalloc(size);
1 K3 r! y6 ?/ Z' H} </FONT></P>
9 k7 a; ?) u! \. g# \' U! v, _<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
( X* n+ \; D9 Xvoid far _graphfreemem(void far *ptr, unsigned size)
, C, D8 n( T8 q9 f1 s' I{
5 _7 e( M# |" ~& e; dprintf("_graphfreemem called to free %d bytes.\n", size); & ]3 ^0 z4 j, x
printf("hit any key:");
% W' P" r! u: O3 ~getch();
* u3 N4 W; ~2 j  d. _printf("\n"); </FONT></P>' U+ q4 v: H1 L1 }7 b* y
<P><FONT color=#0000ff>/* free ptr from far heap */
, G- l, ~: w1 J  Kfarfree(ptr); ; y- o% S* E1 S' s! E, o2 I8 K
}
# }/ B) B1 x/ q- c, g' }</FONT></P>




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