QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2515|回复: 0
打印 上一主题 下一主题

函数大全(g开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:00 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(g开头)</FONT></B></FONT></P>
; w7 ~, r0 ?8 ]: b
7 L& o. `  m9 B, E, A# r1 e
: g4 U+ q0 H  J5 `  C<p>; q* D) q% ?. J  W( ^, n
<><FONT color=#ff0000>函数名: gcvt </FONT>
. G1 ^5 n& Y1 Q& i) ~+ Z& i; H' J. B  b功 能: 把浮点数转换成字符串 + E6 F% x# J9 G  t+ N% `0 l" X
用 法: char *gcvt(double value, int ndigit, char *buf); 7 ]" [4 J' u4 F% b
程序例: </P>$ P$ g! }9 d$ V
<><FONT color=#0000ff>#include <STDLIB.H>
8 A; S6 h, @$ I9 e! z#include <STDIO.H></FONT></P>
, T- E* d& y- T6 a, V( L  Q<><FONT color=#0000ff>int main(void)
( f. p) [/ ]3 m* s; f{
7 \' I; e6 \5 `& q* Nchar str[25]; 9 w, y, ?/ u* K$ f% T+ T
double num; 1 F0 i/ ?% X! z6 L5 U
int sig = 5; /* significant digits */ </FONT></P>
& o5 g% k  U2 q<><FONT color=#0000ff>/* a regular number */ ( c3 }. V5 t& F+ e9 @" c
num = 9.876;
3 n2 {4 G' L% \; [gcvt(num, sig, str);
; C: {+ M& P8 J- T9 W$ Kprintf("string = %s\n", str); </FONT></P>* w/ Z$ p$ {- Y" i  _. t! ^9 r
<><FONT color=#0000ff>/* a negative number */
: X6 ~/ r( F* a5 p; z6 Fnum = -123.4567; 1 p' {; f+ \% `
gcvt(num, sig, str);   U9 H* v9 i+ F; M7 D; D
printf("string = %s\n", str); </FONT></P>0 J% v6 i8 m1 I$ r  M# [" n
<><FONT color=#0000ff>/* scientific notation */ ' O1 y) V) [* w- ]
num = 0.678e5; 5 D/ t1 a1 v$ D7 u0 ~9 C1 k4 [& G3 Y1 {
gcvt(num, sig, str);
3 E& D" r/ B. n7 m) xprintf("string = %s\n", str); </FONT></P>
. A/ S* x3 N" G7 P  `$ l# o3 ?<><FONT color=#0000ff>return(0); $ C. D4 z, c, g1 e$ ]
} 0 R! ]6 |: K  A8 V! E
3 \( Z- u4 J# d, _/ F& X8 y
</FONT>
  r! b4 {! m& A8 b" D</P>! M1 a& q& p% p
<><FONT color=#ff0000>函数名: geninterrupt </FONT>" d! _/ ~$ G2 s' E( _
功 能: 产生一个软中断 4 ~  S$ W; t% H; @# |: H% E( p
用 法: void geninterrupt(int intr_num); 5 c) o1 h$ P8 ^2 k
程序例: </P>
  u% R1 J+ b3 ^7 i<><FONT color=#0000ff>#include <CONIO.H>3 J3 ^2 y& b) _6 D$ P
#include <DOS.H></FONT></P>
$ \. H2 d! p( c( |  c. Q<><FONT color=#0000ff>/* function prototype */
; ~1 Q; c: G" V% g6 Uvoid writechar(char ch); </FONT></P>' z( P7 C7 h6 [" V+ k, E& ]+ a
<><FONT color=#0000ff>int main(void)
& z0 z7 n/ v; X{ : o9 z+ t( N% {8 u1 k/ p
clrscr(); 2 E6 }4 c" U3 Y$ t8 j! ?7 w7 k. X
gotoxy(80,25);
+ F5 P/ `* L/ ], z; V" ?' ^& vwritechar('*'); + G9 _- x- n, u- o
getch(); 9 P9 b9 j0 p, A, K# l$ E
return 0;
' j# i  H  q+ N, A} </FONT></P>
% t! n$ E, L) h& t( Q( q<><FONT color=#0000ff>/* 3 c! v+ w0 W$ W& b  J
outputs a character at the current cursor
/ l' X8 r  G0 r% g5 U; Pposition using the video BIOS to avoid the
: |5 f; G5 q8 U) }$ I. C7 Vscrolling of the screen when writing to
* [; X+ t( `  Blocation (80,25).
9 [3 p' U, o7 \, r*/ </FONT></P>) W! B/ ]! I; R; m1 j1 k& `& K
<><FONT color=#0000ff>void writechar(char ch) * ?# Z. m6 [( P" Y
{
- ~7 A, L2 K7 Z3 j- Vstruct text_info ti; : b5 h% k: f- L4 d% ?7 o- {
/* grab current text settings */
# k8 i" @' b& U0 k6 j" s% k( F% M) Ggettextinfo(&amp;ti);
/ u. u; [; [/ k! a6 A& g# R/* interrupt 0x10 sub-function 9 */
% s* c: r4 O7 a9 ]# T_AH = 9; 9 B* e& J& R2 G# O- _
/* character to be output */
( f7 h/ ]0 ?/ H: u0 {9 k_AL = ch; + F- u; G* L2 ]$ \4 E. d
_BH = 0; /* video page */ $ f! S! J0 \3 t; e
_BL = ti.attribute; /* video attribute */
" d2 O& N+ Z4 e, M! M_CX = 1; /* repetition factor */ : D- j% C7 _1 g" U% [
geninterrupt(0x10); /* output the char */ % b7 e0 ]; V6 d5 h2 }1 `( ^
} ! I! W0 e1 o' k4 t  r! M0 T9 |
</FONT>2 W1 I/ T! F+ H# r, C, t
</P>: K7 J# U$ ]$ R, R4 U  G2 m
<><FONT color=#ff0000>函数名: getarccoords </FONT>/ _$ r3 j7 j% z) T! \1 I: Y9 p# j
功 能: 取得最后一次调用arc的坐标 3 y6 g; Y& d( c1 Z7 f- G- c5 r& q. o
用 法: void far getarccoords(struct arccoordstype far *arccoords); / v* R3 ^# [9 P6 z
程序例: </P>
& Z$ t7 g/ @  q' _<><FONT color=#0000ff>#include <GRAPHICS.H>
, s7 d3 d$ r% ]; k2 b/ R#include <STDLIB.H>( |4 [$ y( C+ ?+ f/ f& J
#include <STDIO.H>7 s9 t& C3 f! X) O5 g+ F
#include <CONIO.H></FONT></P>5 I# B1 o/ C9 x3 K
<><FONT color=#0000ff>int main(void) . T) w* b8 o9 K2 k. I
{ + u( Z8 U  W6 @
/* request auto detection */ , k0 k" A9 s) X
int gdriver = DETECT, gmode, errorcode;
: V: u  S  p+ ], P, U  s; W0 P: r+ Cstruct arccoordstype arcinfo;
! F+ X" {' I- h' f- m6 c% Sint midx, midy; . Z& t- Q  A# n6 G
int stangle = 45, endangle = 270;
6 w' z& ]6 T, O  Hchar sstr[80], estr[80]; </FONT></P>6 f) s/ ]/ J2 v7 A
<><FONT color=#0000ff>/* initialize graphics and local variables */
/ {$ f9 i3 s- L" t3 Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 S4 M: d' ]+ C0 K* G7 L; q
<><FONT color=#0000ff>/* read result of initialization */
( ~+ P& s$ K4 o( M1 M6 @* herrorcode = graphresult(); " o+ v5 n# B( [5 {) k& s: r
/* an error occurred */
7 f# v8 s$ E* N) d! _% v1 hif (errorcode != grOk) 2 a5 D1 N6 s/ I1 V. u( b
{
* f8 V5 e2 ^$ s& e1 Vprintf("Graphics error: %s\n",
( O1 `3 m5 ]+ N* c- f0 ngrapherrormsg(errorcode)); - a# c. C+ h8 X
printf("ress any key to halt:");
  \2 A, J. {5 c1 G4 w& m' R: f5 @getch(); 3 B2 [4 d7 e$ ]. W/ U
/* terminate with an error code */
1 z  [6 R3 r) Z2 |9 M! Q! ^exit(1); " r$ V$ I! B8 X  d
} </FONT></P>
. O; k! [: o7 ~+ V<><FONT color=#0000ff>midx = getmaxx() / 2; % |* p, f* [4 E/ O, p
midy = getmaxy() / 2; </FONT></P>
( J% S, ?3 H* i" |<><FONT color=#0000ff>/* draw arc and get coordinates */
# Z# a! |% v( A) z1 H2 osetcolor(getmaxcolor()); $ s$ h, z, ]0 n$ _6 ?: ]' S9 \/ B
arc(midx, midy, stangle, endangle, 100);
! U! p5 A  _9 @( X6 Ngetarccoords(&amp;arcinfo); </FONT></P>6 _! l/ A" i" ~, r' P; ^. G8 }4 N
<><FONT color=#0000ff>/* convert arc information into strings */
# ^4 `7 h% B  _sprintf(sstr, "*- (%d, %d)", " w" g5 x2 f& }/ ~8 W
arcinfo.xstart, arcinfo.ystart);
* u; |" S; [( M. ysprintf(estr, "*- (%d, %d)", * j% b8 a' J& D
arcinfo.xend, arcinfo.yend); </FONT></P>
' n2 L) e, L8 E2 I<><FONT color=#0000ff>/* output the arc information */ 9 X. p: C& B" g* F8 p! C9 |- k
outtextxy(arcinfo.xstart, 9 y6 x/ K, f2 C: y" m) l0 m
arcinfo.ystart, sstr); 5 @- ?, R+ b# H* D0 s+ I3 B
outtextxy(arcinfo.xend,
3 O/ [' @2 o5 Earcinfo.yend, estr); </FONT></P>) ~; a* `' v( `  _1 O; ?( Q1 Q7 Z
<><FONT color=#0000ff>/* clean up */ 1 {; ^; G2 v% C' W1 |
getch(); 9 `7 `( X8 P+ c1 L4 C
closegraph(); , S2 U. }' q! |8 G0 _; t
return 0; 9 a" o8 m* U% Q3 ^5 `
} 6 r, J5 @6 t+ C3 o
</FONT>
/ m+ x1 g; M' @; [$ {- |+ z* t
; \4 p! b' Z  j</P>+ e. n) G& q" @- Y$ ?6 f
<><FONT color=#ff0000>函数名: getaspectratio </FONT>
5 ?& c* \. S# h* `3 ?功 能: 返回当前图形模式的纵横比
1 o- Z. |! Y0 D8 R  Y# }* i用 法: void far getaspectratio(int far *xasp, int far *yasp); ) h5 y$ i) z  \$ p4 _
程序例: </P>1 A$ Z  H* ^8 U9 Q- ]5 z
<><FONT color=#0000ff>#include <GRAPHICS.H>
; z" x# B0 f# {. _- V$ Q) z& G#include <STDLIB.H>
1 v4 G5 y" Z% `) [. e#include <STDIO.H>
) Q# A+ ]$ ]. W9 z% N' F  G#include <CONIO.H></FONT></P>
, D& G; W: L5 \) c8 E1 x: e<><FONT color=#0000ff>int main(void)
" g( }: p( L5 J. f{ 7 y  J% X$ d1 Z; W- }
/* request auto detection */   [$ m) G: K  ?7 x# {$ D' R
int gdriver = DETECT, gmode, errorcode;
3 c, {8 N" A0 T/ T* Vint xasp, yasp, midx, midy; </FONT></P>5 s/ T% _8 i9 s- e; `$ Q3 ^
<><FONT color=#0000ff>/* initialize graphics and local variables */
& |7 k- p, H! W, N! e( i% j$ f: {% kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 |' [+ x2 t% M/ w  |; x' F2 Z3 o<><FONT color=#0000ff>/* read result of initialization */
& b" ?+ m. I+ r) r* g: b( H! ]: Verrorcode = graphresult(); & d) V) z0 x1 j, T; \
/* an error occurred */
  j. \3 O. \, |# F0 T: o# K9 fif (errorcode != grOk)
! u4 r5 e3 y1 O) u, ]( i{ - }0 h, ~% W( Q, m" S
printf("Graphics error: %s\n",
- d1 j% Q; }( b+ vgrapherrormsg(errorcode)); ( v" ^" T0 q. C) Y" k* {
printf("Press any key to halt:");
" w& I, S. m& }- K9 j; wgetch();
. P0 ~" g: u7 T- {. x7 E/* terminate with an error code */ * W0 b9 I3 [& u
exit(1); ) z* T7 X5 g2 u; @
} </FONT></P>
, @' l) }/ ?8 q0 ], [, T" L<P><FONT color=#0000ff>midx = getmaxx() / 2;
% i: |! D' F# D9 emidy = getmaxy() / 2;
: C/ K* H4 \3 m- J: I; T/ B, Csetcolor(getmaxcolor()); </FONT></P>
7 v/ ^9 A( D, ?( p% {) V<P><FONT color=#0000ff>/* get current aspect ratio settings */
5 o8 u0 d  Y9 B- @getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
5 F2 s6 x; X) K<P><FONT color=#0000ff>/* draw normal circle */ . K( K% S% T+ s- {  o( h
circle(midx, midy, 100); ' ^  n, n' s0 E) z- l+ J/ x; A
getch(); </FONT></P>
5 A* E3 c& J' p& ~<P><FONT color=#0000ff>/* draw wide circle */
) b+ l9 M0 p) g* a( P- pcleardevice();
: S! ~& w: X2 V' I# _1 s+ dsetaspectratio(xasp/2, yasp); 2 _2 O7 L0 N/ Z6 |, z
circle(midx, midy, 100);
  O0 ?. U, T! bgetch(); </FONT></P>
7 U" X: K8 {& i, x" h# }<P><FONT color=#0000ff>/* draw narrow circle */
& j* A: Q! V& i& Acleardevice(); 6 H# R" c& U- p4 Q; b- l
setaspectratio(xasp, yasp/2);
$ f( P. e6 u7 h5 i# ecircle(midx, midy, 100); </FONT></P>" F8 l! D  L+ I: T
<P><FONT color=#0000ff>/* clean up */ 9 j  x( ^' z. R( J$ n
getch();
0 l# Q0 f( ~2 a0 ]closegraph(); , B( A: u( G5 k
return 0; - z  L6 B4 D9 O8 `
} ) w& N6 f$ u6 Y/ a7 I
</FONT>
" Z3 L* ^& x  a2 Y1 e& A1 ^! i& [- K5 G# a2 V
</P>  r0 H+ H( a. W# v/ p
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>. C, }- m1 L9 \4 ^7 H  F4 z
功 能: 返回当前背景颜色 , w0 H& J# F3 M( A! S  [
用 法: int far getbkcolor(void);
" X, m/ Q" i1 v+ ]% A; g. t. v, v: L程序例: </P>9 j: }- y" B4 F$ F; d: t4 O) x% q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
% U3 p  [& o! a& ], J7 [* V#include <STDLIB.H>
4 A! y) O( ^9 e2 o2 |# g#include <STRING.H>  L1 g% ?3 t  P$ D+ \$ S
#include <STDIO.H>, m* @4 e) F0 L5 a
#include <CONIO.H></FONT></P>
, X" u$ o& }! a# g<P><FONT color=#0000ff>int main(void) 8 X! k. I' ]- p' p' A  l5 V
{
2 ]$ C" A  L7 S$ o0 Z! f& o/* request auto detection */
6 ^; P1 H9 [% r" V2 w* qint gdriver = DETECT, gmode, errorcode;
5 G& V0 j; o( n/ c% n; `& G, d4 _int bkcolor, midx, midy; : m* _, N5 D% ?) e9 _) G# t
char bkname[35]; </FONT></P># d0 P  ]7 n% p3 E  d
<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 p  i, C; n9 h/ rinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 r1 n7 ^6 d1 f8 e
<P><FONT color=#0000ff>/* read result of initialization */ # J/ z) k1 ]% z% V$ K$ R
errorcode = graphresult();
" Y2 ^. [/ G" `( H/* an error occurred */ $ d2 ^% C7 b& {& `: t
if (errorcode != grOk)
; Y2 M8 b* o) t) m, q1 u0 ~{ 1 e6 g6 V- E6 b$ p1 ]. ^
printf("Graphics error: %s\n", 4 ]5 m  J& p0 [/ I4 @' D9 |6 X
grapherrormsg(errorcode));
2 H& ~: s' U5 C2 J; mprintf("Press any key to halt:"); ( c7 g8 B: \3 }; u! ]8 p# Q
getch(); $ P4 O+ s: W9 [( X5 h& @1 U% H
/* terminate with an error code */
0 l% x0 O: j2 {8 D4 C' L. jexit(1);
2 S; h( E2 M, o} </FONT></P>
& b9 @6 M+ o& }9 t<P><FONT color=#0000ff>midx = getmaxx() / 2;
9 B2 K4 r" |( {3 K3 g* b5 Y: k7 \2 S- Mmidy = getmaxy() / 2;
7 j6 C. G% t& ~2 M6 E5 h  s6 P* z$ msetcolor(getmaxcolor()); </FONT></P>6 P& `) \2 F, f% M
<P><FONT color=#0000ff>/* for centering text on the display */ . t7 q% `' R3 X) `2 @7 _
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>6 r6 x3 w# m$ f; y! Y5 x
<P><FONT color=#0000ff>/* get the current background color */ 5 [; K' t% I  z1 g
bkcolor = getbkcolor(); </FONT></P>
  Y, b3 {2 q) S3 [. j' g4 R% l<P><FONT color=#0000ff>/* convert color value into a string */
9 g/ k# e" ]! {0 Z1 G# ?1 eitoa(bkcolor, bkname, 10);
# i( b8 J1 k4 d1 m7 ustrcat(bkname, 4 h0 S- ]- u3 T9 U# m
" is the current background color."); </FONT></P>
4 E' @$ [% b0 v& w2 Q$ G! O<P><FONT color=#0000ff>/* display a message */
. H9 }& }- r0 l2 `9 eouttextxy(midx, midy, bkname); </FONT></P>  C* m3 W3 r+ N4 _+ ~
<P><FONT color=#0000ff>/* clean up */ . X  C6 l( h& j4 V. }$ e$ `
getch();
. m5 X1 P% [  _- R* M1 a+ i0 x3 B8 kclosegraph(); . W' ?4 i; d$ q! R
return 0; $ G1 @: F, X) r6 p
}
- Y( k' p; i6 z& @$ Z$ u. O$ L: I7 i6 g& I4 f, i
</FONT>4 n; ]& a5 S* E/ A1 K6 E
</P>
. l0 K9 M6 j% J5 D# ~, f, ^( S<P><FONT color=#ff0000>函数名: getc </FONT>
) v5 V9 |0 E9 h/ Q5 r功 能: 从流中取字符 4 K0 b3 `7 |* g+ B2 H5 B! A) }
用 法: int getc(FILE *stream);
& U! i' S  s+ R, ~! y5 y2 v程序例: </P>. B" v. n" A  z% H/ V8 D/ C' D
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>/ Q. i: m1 ?& T; E1 ^4 H
<P><FONT color=#0000ff>int main(void) . v* I8 A( W# W7 I2 _( u
{ 8 I* w5 W9 ]3 R4 V/ a6 }
char ch; </FONT></P>8 B$ ?0 o4 ~% H4 S; [8 [
<P><FONT color=#0000ff>printf("Input a character:");
- n( K+ z* c2 v2 l' `& F8 f/* read a character from the 8 ]; p* i+ W6 o! |- k& T) S- \
standard input stream */
8 }( b1 V  c' B5 |* L0 g# Q$ \ch = getc(stdin);
- {+ [5 E% e3 K- f4 P& y$ V8 H2 Dprintf("The character input was: '%c'\n", : t; O9 a/ I# C
ch);
3 N- W7 `- I9 P7 H3 n* b% [3 rreturn 0; 9 z, i8 C% N( i" [4 c
} ; R- Z1 W0 ?) s9 l0 [6 [1 {, r

) l' _- ^$ h# |) W</FONT>- h1 w& p7 ^. D' s( W
</P>
4 i( F+ t5 T$ ~5 a<P><FONT color=#ff0000>函数名: getcbrk </FONT>
; F, m, S+ ]4 F3 ]- O功 能: 获取Control_break设置 : X+ a3 a6 H6 M1 L5 C
用 法: int getcbrk(void); 6 t0 V* @0 Z! e  ~& d5 f
程序例: </P>3 C, I0 \9 W3 {8 R4 H1 ~+ k# X
<P><FONT color=#0000ff>#include <STDIO.H>. s+ v7 h( r# e! i+ z" P
#include <DOS.H></FONT></P>
. h3 N- z8 S1 v% v) Q2 @+ k# O, z<P><FONT color=#0000ff>int main(void) 4 J. Z3 s+ H0 N5 F1 Z, z
{
$ v9 i1 E5 m' @if (getcbrk())
: m2 I0 q/ b1 h2 eprintf("Cntrl-brk flag is on\n"); " c3 R3 T% u- B( t/ C% F
else
+ Q: K/ r9 q1 \2 e# v0 B$ E9 y8 Gprintf("Cntrl-brk flag is off\n"); </FONT></P>- T' E/ m3 r) p; {% c: S7 {& |
<P><FONT color=#0000ff>return 0; 1 h$ E1 G2 z, T$ B& x$ r3 Y
} </FONT>+ R; f5 ~- Z5 T4 b4 z/ E, q
5 Y# O4 P7 t6 b' j4 H" J4 m' d
</P>
& g7 E( C% r6 V<P><FONT color=#ff0000>函数名: getch </FONT>" C; q2 |8 H3 \; I$ I' F6 z
功 能: 从控制台无回显地取一个字符 % j! C# G1 {% e6 Z8 k
用 法: int getch(void); $ T0 C. G: i! R& o7 j. y9 V
程序例: </P>
' Y+ ?% C4 O( S% V$ }<P><FONT color=#0000ff>#include <STDIO.H>  r1 _2 r6 c1 W9 g& h
#include <CONIO.H></FONT></P>$ _  F1 S$ m3 t/ Y: |
<P><FONT color=#0000ff>int main(void) . Z" j! U( a5 e/ ~  k* s9 [1 a+ d; }: ^* u
{ * k1 Q9 _. O) a7 v" z6 ~& }
char ch; </FONT></P>' O# ]- I( D1 ~9 [7 }8 k$ y
<P><FONT color=#0000ff>printf("Input a character:"); + J, l" q& X- d6 [8 P
ch = getche(); : z8 ]. Q# P& v: R3 I
printf("\nYou input a '%c'\n", ch);
* R, w) A& S  L# I' n2 Sreturn 0;
: c1 M& J2 L4 W9 F} 5 z- v+ M$ p/ |" \
2 Q4 X4 i6 [8 q- D" n+ z2 R* E
</FONT></P>, T$ F1 h, H9 Y" H& e3 \
<P><FONT color=#ff0000>函数名: getchar </FONT>
5 j; C, u* S4 e% A' G6 m功 能: 从stdin流中读字符 - b( f/ N( q6 P% Y$ N
用 法: int getchar(void);
8 `2 {) T7 U6 |程序例: </P>
; Z) `  i- o$ z# M& ^<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>' b2 {! \& h: S* J
<P><FONT color=#0000ff>int main(void) 3 _9 k8 O* Q' b! _$ d4 {7 `
{
/ Z3 i$ u' i. U$ V, F2 Yint c; </FONT></P>
5 E7 k5 X/ ]  l6 e1 G<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
8 q- x' r) d0 I: Z% Gis line buffered; this means it will ' ]' L9 }; E2 W6 A0 C4 X+ b9 I
not return until you press ENTER. */ </FONT></P>( j& s$ a3 v6 G: n7 ]9 B
<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
% G6 |( h8 d5 w9 Cprintf("%c", c); </FONT></P>
# ?' g" Z0 j6 h<P><FONT color=#0000ff>return 0;
" i2 T6 I& m$ r" o. |: I/ {4 [}
% v3 w: ?" z- M  s; S</FONT>! k7 {1 d0 U/ p
</P>
# T( d# Y' t8 F  m) T<P><FONT color=#ff0000>函数名: getche </FONT>
1 h: e5 d. G- _6 b( Q, G8 J4 y& A功 能: 从控制台取字符(带回显)
2 m! C8 f4 D8 x, g( Q9 Z8 r用 法: int getche(void); & j0 a2 a- c1 i
程序例: </P>
: ]& D1 V( h/ L. T" x9 k<P><FONT color=#0000ff>#include <STDIO.H>
/ s. P( n1 C7 F5 U/ @2 R7 R: y" {#include <CONIO.H></FONT></P>+ i5 {& R. g5 l# H2 ^
<P><FONT color=#0000ff>int main(void) 4 `  w( a# _; H  x, B& o
{
+ b+ E' A" [+ o; X1 D; Z( o+ ychar ch; </FONT></P>& b' T1 _5 Y1 V, _
<P><FONT color=#0000ff>printf("Input a character:"); % O1 B: D" \' g; A% z4 }! s
ch = getche(); 9 {7 r- I- S4 q) q+ h, I" E1 u
printf("\nYou input a '%c'\n", ch);
6 H4 c3 \. q, d1 P% q$ C% Treturn 0; " Z7 F3 S; h% q: x4 e5 `
}</FONT>
, x9 q+ X- U. U! Q9 [% m, \7 I* k$ Z* c
</P>3 \& L4 i7 [1 }
<P><FONT color=#ff0000>函数名: getcolor </FONT>& ]+ I; d" B( [8 J
功 能: 返回当前画线颜色 " o- f# P. z! J* h/ \
用 法: int far getcolor(void); 0 c2 e* F' \( Z4 d: o" Z
程序例: </P>; q/ Z8 c  ]1 o8 M. D7 E
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# Y* x0 x3 d( l2 j#include <STDLIB.H>
: ~6 h1 I* N( ]. x2 [' y% ]#include <STRING.H>
/ `& n2 g8 |8 L- {% N! d#include <STDIO.H>7 O7 _: u' E' L, C2 @
#include <CONIO.H></FONT></P>
' s% F0 Q. T  ~8 _; p; C<P><FONT color=#0000ff>int main(void) . F- o! X' r* H
{ 0 Y+ f) ~, Y7 j/ }
/* request auto detection */ + |& x& }( e1 u4 U
int gdriver = DETECT, gmode, errorcode; % l" O2 G1 D2 l; Y# s
int color, midx, midy; * c7 ]0 }; z: n7 p% E6 _$ T
char colname[35]; </FONT></P>
% M; e; Q& f9 A( Z! S' [<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! z) O3 v" d: g: R$ W: d
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 F. E3 P# R4 c$ T1 z- H6 E, j" x$ a
<P><FONT color=#0000ff>/* read result of initialization */
4 s- i: |+ W& _9 Y% T$ _errorcode = graphresult();
8 ?4 |) y) U; S) b# C/ J/* an error occurred */
4 h+ D' M" Y0 x6 eif (errorcode != grOk) + c% e8 E' N& ~7 d' H) t' y8 ]/ Z
{   v$ N* e+ ?& t8 o2 E( b
printf("Graphics error: %s\n", * Y: T# Z5 [. Q1 F0 z- s
grapherrormsg(errorcode));
9 N. _& [9 z3 i* W1 Q2 wprintf("Press any key to halt:"); % w& B+ F. e3 Q# ^# X, G
getch(); 1 u+ J2 n3 l, \& G' Y( V
/* terminate with an error code */
9 K' j) {/ ?4 ^3 fexit(1);
, C4 D0 O! i( C  B  d} </FONT></P>9 K1 L+ x# S1 v
<P><FONT color=#0000ff>midx = getmaxx() / 2;
$ v$ c( @1 O4 y9 u+ ?! s, Lmidy = getmaxy() / 2;   H) B/ Z3 F& ]8 f# |' X
setcolor(getmaxcolor()); </FONT></P>% Y5 ^% k; k) F/ y+ ?# m3 p
<P><FONT color=#0000ff>/* for centering text on the display */ ) N. I+ K/ w5 z8 M8 Z
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
9 G0 g" i, {. V% O/ N<P><FONT color=#0000ff>/* get the current drawing color */ & E: Y; h7 n7 R8 @5 f
color = getcolor(); </FONT></P>
' W7 L+ b" @* h# i5 [<P><FONT color=#0000ff>/* convert color value into a string */ $ R3 F# j& A8 `# B" z
itoa(color, colname, 10); ) W0 H2 _, x$ i; I5 l- N
strcat(colname,
. m/ D# u0 y: z/ L$ I* P# D" is the current drawing color."); </FONT></P>7 p$ j4 r, k; s& B
<P><FONT color=#0000ff>/* display a message */ 8 F9 p) U' c2 c# w% ~
outtextxy(midx, midy, colname); </FONT></P>, b& n! m$ Y+ U) T1 W, A& S& c$ J  K
<P><FONT color=#0000ff>/* clean up */
0 C$ X7 A" _. P. ~getch();
' e, n- D. S/ n$ i) g6 [" x1 Nclosegraph(); / n# ~1 I7 a" @+ r4 }4 T
return 0; 5 ~8 O! v. Z" \+ o, Q3 v+ \
} ! c9 x7 e5 V+ Q, {1 F
</FONT>
, ^5 J/ {$ W9 w! x* e1 F" `7 M7 O+ q4 L* f</P>
# M& m6 t0 Z! K6 _& U6 h<P><FONT color=#ff0000>函数名: getcurdir </FONT>
/ q2 N9 @4 m- H6 S: L, g/ G功 能: 取指定驱动器的当前目录
# h7 v0 |- P0 V$ O$ L, f; t用 法: int getcurdir(int drive, char *direc); 8 Z) j, \" l/ l0 M; {3 P
程序例: </P>( s7 D! w' F" O* Q/ X4 q) b6 {
<P><FONT color=#0000ff>#include <DIR.H>! }9 V2 G! `6 }# Q
#include <STDIO.H>
6 J" s" E& f* Q0 c8 H#include <STRING.H></FONT></P>
9 `5 J3 m  m! x- j0 d<P><FONT color=#0000ff>char *current_directory(char *path) + p, l8 A! t  C) ]' ]5 y' q
{ 7 C- y  C' C( o
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
5 V3 m8 E' L" @! q. ~; f* Hpath[0] = 'A' + getdisk(); /* replace X with current drive letter */
" f# ~2 U  B: C: z  l% Ogetcurdir(0, path+3); /* fill rest of string with current directory */ - @0 l- A$ F8 P7 P4 c! T
return(path); ; c/ z# m0 @% n& R( z0 \& X
} </FONT></P>/ d- p# t7 J& x1 C' n
<P><FONT color=#0000ff>int main(void) $ `  V( F* g9 x0 P+ m
{
3 t- `! p6 U* D/ [3 I, ]char curdir[MAXPATH]; </FONT></P>) }$ i% h/ A+ Y( S9 R9 j4 t
<P><FONT color=#0000ff>current_directory(curdir);
' ~2 n. @( s$ K+ uprintf("The current directory is %s\n", curdir); </FONT></P>( O5 ^* L3 g7 y
<P><FONT color=#0000ff>return 0; 5 [" @9 M4 H+ q, Q) h6 B' Y# A
} $ h8 G0 Y/ p# p5 `3 j$ H. s
</FONT>3 d. S2 N8 J$ a  k6 w- v0 ?% {( Q
</P>
! e  L7 C4 s# ~+ [, o; b. t<P><FONT color=#ff0000>函数名: getcwd </FONT>, L8 q+ q# H3 A* a& T7 }9 Y  C
功 能: 取当前工作目录
$ F  e' b2 [# R( R用 法: char *getcwd(char *buf, int n); * Y& x6 ^) w$ s1 y" c$ G
程序例: </P>
" `) K' B+ j( b# g: o% P  V5 r<P><FONT color=#0000ff>#include <STDIO.H>
0 h1 P* R  _" @, Y4 U5 y. C& Z#include <DIR.H></FONT></P>9 d5 j1 J' a- j9 C
<P><FONT color=#0000ff>int main(void) " w" q# k. i& X! u" @$ n
{ & B5 ?* U2 V6 d+ i# W( [
char buffer[MAXPATH]; </FONT></P>( G/ g$ N  Q/ Q- D4 j. q0 U" I
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); 3 r) U. G" }! p1 l; e$ l2 l
printf("The current directory is: %s\n", buffer); ; X! o* x8 G' C) U. a% N- J8 a+ @& l
return 0; 4 p9 e1 `3 C+ a/ h0 P, f7 S1 ?% X/ h7 g
} </FONT>
5 i. y. K" z( n) m/ O8 p' @7 T" |9 Q% `+ s1 o
</P>
, F; m9 S9 `$ y5 X6 P5 n<P><FONT color=#ff0000>函数名: getdate </FONT># E: Q! O1 T! j6 N
功 能: 取DOS日期 , s" [  i/ C  \# g4 n
用 法: void getdate(struct *dateblk); 8 n( U- n% p1 Q6 l3 W  D
程序例: </P>3 h/ Z7 x  c% P' }. h
<P><FONT color=#0000ff>#include <DOS.H>
1 l4 T- z# W4 W  s- V" t#include <STDIO.H></FONT></P>" E" k+ d  _$ |3 X6 |: |& H* \5 f
<P><FONT color=#0000ff>int main(void) ; t  N0 ?3 t7 f7 ~
{
! c2 g% H2 x& m$ D1 s* y2 `struct date d; </FONT></P>
& c- u" p& H/ {5 |<P><FONT color=#0000ff>getdate(&amp;d); , u( [$ y5 Q* f( N) t- S) w
printf("The current year is: %d\n",
% |* K- t; [2 L$ z/ ~' S4 O! }d.da_year);
  m5 M6 ~! |0 C2 }; m- Q8 X: U* wprintf("The current day is: %d\n",
9 X2 n0 B0 O, V) c0 Z* V( |7 Ed.da_day);
# q9 R+ r* P" L) xprintf("The current month is: %d\n", " h; x* u+ x% e4 s
d.da_mon);
# \, O" J9 h. u5 l  Kreturn 0;
+ ]: C- V5 ~& g0 j}
8 y' Y/ V+ h- f! o% k2 C</FONT>
8 o/ ?5 }' K' _</P>0 X& J5 e7 g2 f3 E" ^
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>1 I1 Q& f- W, ^/ T4 X& |
功 能: 返回调色板定义结构 * C# n, O0 I; a; S  C$ P
用 法: struct palettetype *far getdefaultpalette(void);
4 p; F/ Y4 R% [' ~' {4 [" u程序例: </P>
& M# h# |1 S1 X- i; L2 p, s<P><FONT color=#0000ff>#include <GRAPHICS.H>8 G$ n) |' w% H& J, }, d
#include <STDLIB.H>& m" K4 ?; H( s$ f1 o$ l
#include <STDIO.H>
) r8 Z  y8 `0 e1 n3 a8 W- O#include <CONIO.H></FONT></P>
. b9 |- f5 x  }7 r: o8 |- a) g) L<P><FONT color=#0000ff>int main(void)
3 c1 D5 P7 i. A{ $ A( G( B5 n( }% S* V* ?
/* request auto detection */ 7 T7 ^$ A$ s9 ^7 v1 f4 @
int gdriver = DETECT, gmode, errorcode;
% ~% x5 y% E( aint i; </FONT></P>
% k! v6 q- H! {+ Q8 T* B! p<P><FONT color=#0000ff>/* structure for returning palette copy */ 2 b& t/ q5 z: j1 Z% h) z
struct palettetype far *pal=(void *) 0; </FONT></P>
2 w: R8 y2 _5 W& c6 W0 e0 |<P><FONT color=#0000ff>/* initialize graphics and local variables */ - N, S+ J' x) z2 N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 h. ]: _- X, b. g0 e  u2 k! Z<P><FONT color=#0000ff>/* read result of initialization */ + X: J; v5 V. W' n/ N3 r1 a- K& q2 C
errorcode = graphresult();
, y3 W# H5 c9 E/ g3 N/* an error occurred */
8 J" \7 U0 \. i# @) B/ g! i& |4 Fif (errorcode != grOk) 8 I$ _0 f/ m/ g- P' e4 O3 ~$ h
{ 9 X# m! f9 n, g$ u+ U( z
printf("Graphics error: %s\n", $ \. X* ~% W) P3 v
grapherrormsg(errorcode)); 1 @. R) s% c; R3 W$ |. k: U$ ]8 ?
printf("Press any key to halt:"); ' I5 h- a1 a7 L2 p
getch();
$ f5 I5 |# s  s' ^/* terminate with an error code */ 0 n. W; u. w- Y7 v/ X
exit(1);
: S% M! _4 K  g- a* p( ~+ ?% z- ~} </FONT></P>
8 {$ D; V9 w3 L4 E& z, Z<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>/ H. m& a/ Q0 {1 W! o" v6 B/ u
<P><FONT color=#0000ff>/* return a pointer to the default palette */
3 X$ F' v  T9 G; n8 x0 f  m3 jpal = getdefaultpalette(); </FONT></P>. d1 X; E: d+ N" k- ~
<P><FONT color=#0000ff>for (i=0; i&lt;16; i++)
1 u) {4 x2 s1 c0 F{ " h5 @* w: j5 q2 D$ d1 S4 G
printf("colors[%d] = %d\n", i, 1 h+ ]1 p% p7 H; F/ J
pal-&gt;colors); / `  y/ t2 m1 k6 q+ ^. {# F1 r
getch(); " s  z* E% y: l, e: }8 S7 r6 O" b
} </FONT></P>, e! K3 p0 j# v. P3 m5 [- Y0 w- k
<P><FONT color=#0000ff>/* clean up */ * [4 x4 I! S" {  L
getch(); ! X. `: e- v* w2 U+ Z: M3 p( c
closegraph(); 3 `8 ^7 l0 p2 ~& |# o. B' Z
return 0;
1 L3 {/ d+ Y9 S6 A! b$ R}
& V: |% e9 R2 n' d) y</FONT>
/ N9 c8 S- {# o3 q* a</P>
/ B2 m. F1 |  ~1 ]<P><FONT color=#ff0000>函数名: getdisk </FONT>! d8 P/ C# q7 o8 M0 y; y$ C
功 能: 取当前磁盘驱动器号
( Y4 G# d0 E& I' W7 [用 法: int getdisk(void); ! c5 J) I+ C. U/ F8 v$ Z: p
程序例: </P>( t: S/ d1 Q4 R0 M9 d! T
<P><FONT color=#0000ff>#include <STDIO.H>
4 H7 D6 N/ P1 N& E+ s" {* Q, C#include <DIR.H></FONT></P>0 j: D- b% l+ g' Q$ X3 b
<P><FONT color=#0000ff>int main(void)
% W3 ?" G0 C5 m# \# o{ 6 a9 B, q, }' E0 t9 }* o
int disk; </FONT></P>
9 E& |' Z9 o( F, C; @<P><FONT color=#0000ff>disk = getdisk() + 'A';
7 Y1 B4 X; a. ~% e( Tprintf("The current drive is: %c\n",
& s+ ]0 m2 k+ f9 I# mdisk);
5 n3 ^8 Y1 J2 Q. A6 J- treturn 0;
. b/ h' ^5 R6 v. o  f  C} 8 e% B0 _8 {" [9 t* M! D

' b. g% T! X. S( {* f</FONT>
% ~& v7 M0 l, {# U</P>
1 c* l! n, v. L  g8 ~$ K- b! T<P><FONT color=#ff0000>函数名: getdrivername </FONT>
, j. [0 V  ^5 w& ?( ?; W+ }4 F3 m功 能: 返回指向包含当前图形驱动程序名字的字符串指针 * {& G+ u8 y1 t" u; z/ o% a
用 法: char *getdrivename(void); ) n6 t- Y0 H2 _9 F$ e
程序例: </P>* y& u4 \* [) ~" k2 x
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 {8 S2 N- q) C2 C0 h+ D#include <STDLIB.H>
. w8 v/ z( M/ `#include <STDIO.H>
  ~2 a! R  V* P& [% A# C#include <CONIO.H></FONT></P>) E! _% a4 J/ o6 u2 X  \
<P><FONT color=#0000ff>int main(void)
8 X" @& C/ O; b1 j" S{ ' d1 X5 A" q7 R! C
/* request auto detection */ 4 Z# E6 g: u/ b% g
int gdriver = DETECT, gmode, errorcode; </FONT></P>
/ ?$ |  [9 d" L! s) t4 k<P><FONT color=#0000ff>/* stores the device driver name */ , \; x% {, b; ]2 w7 H
char *drivername; </FONT></P>
+ B- \: ]( a( p+ {& U<P><FONT color=#0000ff>/* initialize graphics and local variables */
& G9 m# f8 ^% w3 K* Uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 h! A$ C/ R. c! i/ r  U4 W0 z7 @: T
<P><FONT color=#0000ff>/* read result of initialization */ + W% c( U) V0 {6 i
errorcode = graphresult(); , S' t7 T  H4 N' A* Q7 O
/* an error occurred */ / H: ^; q$ h+ U/ Q. p
if (errorcode != grOk) % f9 e" |/ p( L+ o# u0 U7 n
{ * z0 S2 @9 a! w, `( s/ g5 N$ T# E
printf("Graphics error: %s\n",
4 p# ]# J4 B/ J7 _+ {9 ographerrormsg(errorcode)); ( G6 k- f" W! |9 G5 [4 O5 @% f
printf("Press any key to halt:"); 3 ]2 q5 R: ^0 I8 [! A
getch(); / @6 J" f' c1 Y4 m/ c0 T
/* terminate with an error code */
7 k! i8 R7 l4 q2 h4 }exit(1);
; v; J/ E: n& C% L} </FONT></P># p2 ^+ I  x( r) F( B# w
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
; z) a% p! @) o9 I* q+ u$ i<P><FONT color=#0000ff>/* get name of the device driver in use */
8 d/ D( ~' i( r0 l( ^! |drivername = getdrivername(); </FONT></P>
8 }9 K& K! {1 V, ^<P><FONT color=#0000ff>/* for centering text on the screen */ % u& b( v. n/ m( Z% }, z3 O
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
3 C  C# l. q; y<P><FONT color=#0000ff>/* output the name of the driver */ 5 Y% t& s3 U" P* a0 Q5 J' J
outtextxy(getmaxx() / 2, getmaxy() / 2,
) I3 _7 h$ Q. B; S) G* xdrivername); </FONT></P>. l, T4 g  H) b- M, n1 V8 B: c6 p5 a( I
<P><FONT color=#0000ff>/* clean up */ % W( u% t3 D& x: D5 h
getch();
0 F- U7 R5 M: ~2 j: {8 Eclosegraph();
# H8 n9 F- `5 y1 A* wreturn 0;
8 d: m+ ]$ [9 ~) _7 L/ [}
# A, b- ^- ], P. ~2 p; R, h1 Y</FONT><FONT color=#990000>
3 o" s1 H! y( d; a9 y$ ^</FONT></P>5 ]/ ?1 X0 g/ h# ]; N/ h! w
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
! E: C: q* B1 f<FONT color=#000000>功 能: 取磁盘传输地址 " B* N8 y' w/ e
用 法: char far *getdta(void); 5 u9 T* M" ]8 E
程序例: </FONT></FONT></P>
: b1 a- f2 v2 j& }0 M<P><FONT color=#0000ff>#include <DOS.H>
. Q6 H5 u( N" ]# w3 K, H#include <STDIO.H></FONT></P>
( L  `8 U$ P. ~; F5 `1 x0 D2 p# Q<P><FONT color=#0000ff>int main(void)
+ x5 ~9 b& a- p" z; H0 N7 V{ 0 e. j/ B+ M1 p) q
char far *dta; </FONT></P>3 \0 B# k' p, i6 C, g
<P><FONT color=#0000ff>dta = getdta();
- J) X0 x( v! F/ n8 J; s% [printf("The current disk transfer \ ! ]7 o  D( F1 J
address is: %Fp\n", dta);
: `! ]" ?& d! V+ q2 C6 nreturn 0;
7 T" B9 S- ^) V, B+ g3 X2 H8 j  O5 Z} + D# K. b9 h8 Y3 A, |
</FONT><FONT color=#990000>
' B# Z; {3 _7 ~6 u8 S8 O</FONT></P>; D: `6 V( J( K1 C) }1 O1 I
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>" ^& k/ b1 h$ Y
<FONT color=#000000>功 能: 从环境中取字符串 ( }% s& U" \# t0 n
用 法: char *getenv(char *envvar);
0 i3 g( H9 S6 L4 Y  n7 h$ ^程序例: </FONT></FONT></P>
! V; o0 s; I; i0 }. P+ }) ^<P><FONT color=#0000ff>#include <STDLIB.H>
, n5 T1 o& |! u+ A$ }#include <STDIO.H>4 ?4 F: e3 `' R2 n/ Y1 _0 V3 y
</FONT></P>% D. A* J( H/ P, E: o
<P><FONT color=#0000ff>int main(void)
( ~: V  ^% ^% u2 I( Q9 t. y{
; _# S7 e8 a- w6 ~, pchar *s; </FONT></P>
0 w% r5 `/ I& d8 L: H<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
! Q' n0 s- g% G2 qprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>$ {# W; c3 t, A6 r
<P><FONT color=#0000ff>return 0;
4 b* J7 ^/ D" x4 S" ]5 _2 a} </FONT><FONT color=#990000>: e) r7 [: \1 k6 G3 `! O% o
1 z1 s7 o: p7 J) N. L

4 L+ ^( Z8 ?$ C8 B9 q1 A. \, o</FONT></P>+ x& U; x5 g" h: ^1 k
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>
& u# g; F6 h  F7 K& I' o! O, k0 p功 能: 取文件分配表信息 5 B3 Y' c' L/ q
用 法: void getfat(int drive, struct fatinfo *fatblkp); 6 l! ]4 I4 F4 D( W3 R" Y" n: T: Y7 I
程序例: </P>  r% X) h2 B6 b/ z2 B4 D
<P><FONT color=#0000ff>#include <STDIO.H>
" V% i6 e$ }3 @9 a. i0 T0 c#include <DOS.H></FONT></P>  n1 @9 k! p4 b+ E' t% [
<P><FONT color=#0000ff>int main(void) , W2 c# q' n# w
{ ! Y6 i# A8 l& ~+ M) f0 S
struct fatinfo diskinfo; . U1 X9 w  x* A3 {. Z& ]& m/ y
int flag = 0; </FONT></P>
" T6 V" T+ g& s7 [<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
# w: _, V& s( u; R: d3 j& y- Qgetchar(); </FONT></P>
" g) O- k' Z, ^. T" b4 b/ J2 z<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
" Y  t0 W: ]( J* h5 O/* get drive information */ </FONT></P>- \! O  s& ]# U7 o# S
<P><FONT color=#0000ff>printf("\nDrive A: is "); . p- ]/ [( y5 \) [! \7 M7 J
switch((unsigned char) diskinfo.fi_fatid) ) h! p; v4 n7 c. n4 l4 e
{ 5 a1 Y! Y+ x3 W! c5 W0 X
case 0xFD:
  J1 k- j; n" e% \printf("360K low density\n");
! D3 K7 z3 d% n8 |# N9 tbreak; </FONT></P>
2 b/ C8 Q8 m5 v8 ~2 |% z<P><FONT color=#0000ff>case 0xF9:
& K2 U( _6 u* {2 d1 ?  Iprintf("1.2 Meg high density\n"); ( _* n$ G7 Z# B* O
break; </FONT></P>
" {+ r7 B  ~$ o4 k  t<P><FONT color=#0000ff>default: 0 {  s6 U9 S6 y$ R& l
printf("unformatted\n"); 5 J' t0 ~% }6 M# a3 L
flag = 1; 9 o( T; J4 L/ M- B8 }
} </FONT></P>, a* W' s1 @' E% j  a4 Y0 r
<P><FONT color=#0000ff>if (!flag) # _6 l4 l; ^0 [5 g' [- V
{   _# Q8 E5 J3 d6 S
printf(" sectors per cluster %5d\n",
) g4 |# t4 @7 D- vdiskinfo.fi_sclus);
8 z* X' s# }9 I1 [5 ?7 qprintf(" number of clusters %5d\n", 7 @9 c& O5 x, _* L" b, z
diskinfo.fi_nclus);
. R2 X; H0 c, y$ b& f$ j9 H# Rprintf(" bytes per sector %5d\n",
& k" t$ r7 N# t1 rdiskinfo.fi_bysec);
+ V4 t$ Q2 Q- @6 j: w} </FONT></P>
5 ~1 A1 m3 V2 \+ Y# ^  P6 G8 ?8 \1 y<P><FONT color=#0000ff>return 0;
; d0 z2 y9 L& A3 d- ?} " H# f3 b0 y, U9 @
</FONT>
& L8 _- n, b: J6 {* s7 I2 E5 i</P>6 o% G# t8 x3 W0 U' h% E  _' U
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
: g$ [9 q+ J; j功 能: 将用户定义的填充模式拷贝到内存中
+ N! n* i; T+ m, x用 法: void far getfillpattern(char far *upattern); ; k0 J7 O& ?* o  H' m* t
程序例: </P>7 S3 h  S" d! a! S
<P><FONT color=#0000ff>#include <GRAPHICS.H>: E4 P6 ~0 R8 I# g/ X. O7 @
#include <STDLIB.H>
7 l& F6 n& u2 W& O- \#include <STDIO.H>
, P  s2 V# r1 w0 t3 \! H#include <CONIO.H></FONT></P>+ {; T% e1 H  @! l- [/ [% v6 l
<P><FONT color=#0000ff>int main(void)
1 n; h3 m& d7 u! F{
; H/ E$ L0 B! Y8 j3 K1 H1 V/* request auto detection */ * Y: u# R1 b: T8 i2 s2 ]3 H1 _/ C* T
int gdriver = DETECT, gmode, errorcode; 9 d6 N& t# ]4 o9 r& f! N, |7 E( [8 I
int maxx, maxy; - u0 d/ D& I  \$ ^5 K, S- Z% M& S
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>0 {" M5 f( p0 d* M- b; H# y
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" k) J4 C* m* I4 _* binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  X; H) k& q. P% p8 z1 I<P><FONT color=#0000ff>/* read result of initialization */ ( W3 n; v2 B, x
errorcode = graphresult(); / V, B3 |8 ]" |1 H! v
if (errorcode != grOk) /* an error occurred */ 4 S- s, p6 k2 g3 w% A5 e
{ - ^2 p' ?. `% N' h( _: a: I$ D! h
printf("Graphics error: %s\n", grapherrormsg(errorcode));
% K; y/ w  s6 y! u) \printf("Press any key to halt:");   r+ U& K$ g; ^2 C, B4 u
getch();
# c5 t5 b2 U! N- a4 b& J7 oexit(1); /* terminate with an error code */
) L  _9 J0 L% K; ^* d9 I3 G} </FONT></P>7 O. N: Q- i5 H7 O( J% S  m
<P><FONT color=#0000ff>maxx = getmaxx();
4 F9 T, ^3 k" S8 c, `, o, y) F6 R. J+ Umaxy = getmaxy();
8 j9 ~7 Z3 _( e2 S1 Ssetcolor(getmaxcolor()); </FONT></P>
( w  `7 k' D6 W. }- D<P><FONT color=#0000ff>/* select a user defined fill pattern */
9 z, c, e& p1 ^4 I1 i6 osetfillpattern(pattern, getmaxcolor()); </FONT></P>
; H9 w: V! m% V8 e6 l. \<P><FONT color=#0000ff>/* fill the screen with the pattern */
- g4 I: w# W. Ibar(0, 0, maxx, maxy); </FONT></P>, E0 |8 L  \2 w( ?5 m. U! a
<P><FONT color=#0000ff>getch(); </FONT></P>
" `$ n, u  q6 y1 B2 s9 T" L<P><FONT color=#0000ff>/* get the current user defined fill pattern */ 5 [: [7 G3 z, j4 c1 `. F
getfillpattern(pattern); </FONT></P>7 Y7 I8 m! M$ v( P" u
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
! l% }$ e, |, I& Z/ z4 ~pattern[4] -= 1; 1 I9 ?9 l; @: J8 T# ?2 r# }  V
pattern[5] -= 3;
: t3 Q; B& U/ Q- ]) ]pattern[6] += 3; . x4 K$ v# L" N) ^' ]# N( a& _5 B
pattern[7] -= 4; </FONT></P>
. e  d6 v! `, K<P><FONT color=#0000ff>/* select our new pattern */   v8 K' r* W+ p7 x
setfillpattern(pattern, getmaxcolor()); </FONT></P>+ y5 G- j, C4 O4 l
<P><FONT color=#0000ff>/* fill the screen with the new pattern */ & \4 B7 e) w# u2 H* ~. B* T- e
bar(0, 0, maxx, maxy); </FONT></P>
& i4 }) P, E. T2 ^* ?" N% ~<P><FONT color=#0000ff>/* clean up */ & G" `% B% @# N+ y6 Y, I( b3 R/ m
getch();
+ N% t: c; ]! ]" Z% Aclosegraph(); ! x- ^* R" F8 ?) o; h) `: ~9 L, i
return 0;
7 V( v& q9 w6 _}
1 O/ o7 d: G' Z7 q, g" W7 a+ Q</FONT>
  J+ {$ Y% H7 _2 j; E</P>
6 f  H( }; w: P: E% Q5 t, e  k( \8 U<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
7 U% s- K9 q5 P; S" V, ?$ A; f功 能: 取得有关当前填充模式和填充颜色的信息
8 g6 _; H% Q) _$ Q. z3 Y! f用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
! U1 ?( w5 S1 V2 R( c" s( T程序例: </P>
& ]% ^' d/ `% I$ _7 S) \<P><FONT color=#0000ff>#include <GRAPHICS.H>
' U! B# E5 V# Z#include <STDLIB.H>
/ s$ S0 F* W7 u: v  X#include <STDIO.H>
. {. e' b$ S5 `- F" H3 |' ]#include <CONIO.H></FONT></P>3 F+ O; l  H- v# B* `: c3 G
<P><FONT color=#0000ff>/ the names of the fill styles supported */
  t: F0 p7 h- ]7 m3 G0 B/ }( ~char *fname[] = { "EMPTY_FILL",
- U$ ]( z2 Z. k"SOLID_FILL",
) P% i4 K5 A; h% U" s" A"LINE_FILL", * g& D; @; T* G  \' h' d+ `: W- X
"LTSLASH_FILL", ' g$ g0 U6 c, U( X& Q, G
"SLASH_FILL", ' K/ c1 F- U/ ~7 p/ x
"BKSLASH_FILL",
+ k+ x( F4 j, L( O"LTBKSLASH_FILL", ' \5 Q6 J, B1 H6 {
"HATCH_FILL",
" O( ?* S5 t: h/ B' l"XHATCH_FILL", + S: a" ?+ B0 G3 L. }
"INTERLEAVE_FILL",
+ o% x1 m6 f# ^5 t( e"WIDE_DOT_FILL", , H, `) H4 g3 j& ~/ h
"CLOSE_DOT_FILL", 7 n. a# J8 Y; `. p$ i
"USER_FILL"
' d9 [. \% T& R$ H) }4 i1 Q# ^}; </FONT></P>$ `6 y" A  d. W. \& M8 W, k8 y, @
<P><FONT color=#0000ff>int main(void)
; l" `. X9 x# j* F5 t{
2 Y# g( f4 O5 F" a# M4 J! q/* request auto detection */ 4 o: z1 {: ]% x, r+ G3 `- D, X
int gdriver = DETECT, gmode, errorcode;
  V8 }8 R- i, pstruct fillsettingstype fillinfo; # y8 o2 o' K' n; d* l) n
int midx, midy; & c  i" p1 Z3 T: Z) U# L. e
char patstr[40], colstr[40]; </FONT></P>+ k8 P# e, r, F6 F3 g: N) f8 Q0 j
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , `! D6 J, Y  w  s& n
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 F2 `, D! \0 v0 I2 M! ^$ N9 V
<P><FONT color=#0000ff>/* read result of initialization */ 2 L( ]: E9 m" I6 D# y0 b
errorcode = graphresult();
; ?' D: g" e  E3 p. c: L$ A4 _if (errorcode != grOk) /* an error occurred */ 5 y" j. l) |& d, n9 m( W
{
" A- T8 ~5 k) o. M3 C: sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . h. |0 O) S/ C2 _& N7 A
printf("Press any key to halt:");
# |& [% ~2 G. J1 N  \' ?getch();
  K  d3 o' {& E/ R3 Q! i  oexit(1); /* terminate with an error code */ , V$ g. y4 P0 E+ ~8 \( K
} </FONT></P>- H" n; F7 h2 @1 c' j: N
<P><FONT color=#0000ff>midx = getmaxx() / 2; 3 q6 P! N' N) t; |+ d
midy = getmaxy() / 2; </FONT></P>
0 W, ?2 n& i5 Q$ I9 _& ^# ^<P><FONT color=#0000ff>/* get information about current fill pattern and color */
0 B6 N1 z- W  g7 ^5 A  p9 Cgetfillsettings(&amp;fillinfo); </FONT></P>
! ?  @" I8 D7 M) a$ q<P><FONT color=#0000ff>/* convert fill information into strings */
0 ?3 M# Q- q! c  B" F1 [sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
3 Z8 H- N0 b& k6 ~! w/ Tsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
, [5 h9 Q+ B- i3 i$ @<P><FONT color=#0000ff>/* display the information */ : [- d) G, }! P0 J
settextjustify(CENTER_TEXT, CENTER_TEXT); + o( h* D+ I  u8 t+ f& ?
outtextxy(midx, midy, patstr);
6 r7 Y+ T8 n) k, ?! `. `5 R2 iouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
; G1 ^7 R! f) a  G% ]* x5 n4 ?( q<P><FONT color=#0000ff>/* clean up */ / V: N. U* S/ P& h4 T# {
getch();
! ^9 B. S/ V: E! Rclosegraph(); 5 u! ]0 M1 a2 U' I$ W. |- B
return 0;
# [  X" S% H3 D7 f} . b; c# l: s+ _) T6 e+ L! x/ P& i7 Q
</FONT>
( S9 F2 [6 V% Z0 T3 t9 y! i7 I" `( o0 w$ M9 l
</P>
8 u. \3 m4 a+ R; e+ N7 E<P><FONT color=#ff0000>函数名: getftime </FONT>2 o) S+ o3 H- G2 |# ^3 n
功 能: 取文件日期和时间
  |- L1 _3 K) d4 `$ k0 R, a# V用 法: int getftime(int handle, struct ftime *ftimep);
# k. P- M9 W& K程序例: </P>+ m7 P* j2 a& O+ `$ U
<P><FONT color=#0000ff>#include <STDIO.H>
6 y$ `* ?5 [0 `#include <IO.H></FONT></P>. T7 N9 R( I' p1 p6 b
<P><FONT color=#0000ff>int main(void) ; E, k  \: E+ L
{ 1 I' l! O: D& ?# o6 D
FILE *stream;
2 }; ~$ l- ]- O% S/ Qstruct ftime ft; </FONT></P>
9 [7 ?* Z7 T- d; C<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 8 I2 ~0 p( c( O$ w1 ~
"wt")) == NULL) 5 s! n' P# h: z' a; ~/ ~2 O
{ : ^6 g8 k. c  \! K5 S+ `$ z, P7 T
fprintf(stderr,
* M. d' n( n) T7 H. L"Cannot open output file.\n");
% X  P7 D' u  T6 V2 treturn 1;
+ x) R$ d6 N, e6 W0 K- q) g}
' {1 E5 I! l5 E' s9 p! o" Egetftime(fileno(stream), &amp;ft); 4 v. N% M& [3 L" `/ N6 j
printf("File time: %u:%u:%u\n",
. Q" C3 S1 Q3 J7 o, vft.ft_hour, ft.ft_min,
4 K( F" s: O; E2 @ft.ft_tsec * 2);
& t7 N  N( K9 hprintf("File date: %u/%u/%u\n", $ y4 `; `% W, G/ g
ft.ft_month, ft.ft_day, & ~; d9 y5 q7 D
ft.ft_year+1980);
- D# f% F' R, R) ^2 ^fclose(stream); ' M% m! m( [) u( B; ~! |5 k5 G
return 0;
) N  N% e* {; c5 b7 P2 l/ X}
9 |) @; I& {- K7 F# O</FONT>3 f& _& x( g; R0 a8 ?9 T

$ M0 ]) s- o+ m$ ?0 p2 g! q8 q% t</P>/ g2 e/ p. r% w: [% Z
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>' H* b6 e$ H% f
功 能: 返回当前图形模式 ; J* D$ h/ ~) P* u. L, p
用 法: int far getgraphmode(void); 3 e4 W2 F5 g! u+ d& \& q
程序例: </P>0 S: v5 E8 Z4 o1 \
<P><FONT color=#0000ff>#include <GRAPHICS.H>' K4 Z* R% S+ o- E2 M8 z# ?, l3 M% \
#include <STDLIB.H>* U8 I4 C8 j  W2 m, _: a1 w
#include <STDIO.H>
- p) U" _; L# b& ?+ E; t8 h; f#include <CONIO.H></FONT></P>& v/ E, f/ Y% m# W4 v& Y
<P><FONT color=#0000ff>int main(void)
6 S. L6 J0 j( V+ N9 t% R{ 2 ?, Q% b) L! E0 {! l- Q  g$ p
/* request auto detection */
) S4 R. A) }( S& Eint gdriver = DETECT, gmode, errorcode; , h  \, }* V0 F+ T; w# W- m
int midx, midy, mode; % c+ A% o# `: @" K; V
char numname[80], modename[80]; </FONT></P>8 D3 J5 f( j$ ]$ }; }
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& j8 N4 `: Z$ h8 einitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># n: g: ^6 h+ t; j8 M
<P><FONT color=#0000ff>/* read result of initialization */ ) t5 J8 k* }8 Z: @% S' R
errorcode = graphresult();
2 _* @+ L, g/ H* r0 c5 P, m/* an error occurred */ . z$ i6 G; e* R+ V3 Q! D/ o) C% h
if (errorcode != grOk) ' Y6 U" X3 Q! |' u6 Z3 @
{ * V8 e$ o8 e* Z
printf("Graphics error: %s\n", ) n, a/ _0 l7 o; \! G- u: c1 Q
grapherrormsg(errorcode));
3 L  X& M% Q5 f  E+ C, vprintf("Press any key to halt:"); % ~, W$ ?" B4 r) A6 d
getch();
; }- `4 R4 h% e/* terminate with an error code */
1 i: H$ x: a) G* N' k) ?6 |% |exit(1);
' W3 Z2 Z$ v% f0 q9 e} </FONT></P>
: e% k; I7 [2 u8 r! y( P5 U1 F* S<P><FONT color=#0000ff>midx = getmaxx() / 2; $ Y- ?% |4 b& w; D. B. o
midy = getmaxy() / 2; </FONT></P>
5 |" w9 |0 e6 G4 S8 t: X<P><FONT color=#0000ff>/* get mode number and name strings */ . u$ u9 E% k6 S& A9 S/ Z/ Z
mode = getgraphmode(); ! i& W. j7 ^, a/ _
sprintf(numname, . H& }9 C4 k, J
"%d is the current mode number.",
' W6 c. J/ K: `, i) C* Zmode);
6 \0 z; q0 Z, Csprintf(modename, 4 s/ Y2 Y  ?9 p
"%s is the current graphics mode",
/ z/ X- [! u7 G: P' K* ngetmodename(mode)); </FONT></P>9 A1 B5 I* c" {) D4 c) \
<P><FONT color=#0000ff>/* display the information */
8 }' W* L. y% usettextjustify(CENTER_TEXT, CENTER_TEXT);
: ]$ N  h  r! V/ b  P- W( ~* ]outtextxy(midx, midy, numname);
, I' \# B" e( x7 v4 Pouttextxy(midx, midy+2*textheight("W"),
, y4 R7 A4 ~, A: X9 X" c1 Q3 Amodename); </FONT></P>
' A9 U7 G! z- _+ T<P><FONT color=#0000ff>/* clean up */
+ C& g. M. D9 }- Z+ K9 z# p4 \getch(); 2 t. q3 f" y7 \. [
closegraph(); , J9 _, q7 J6 F! g0 \
return 0; / A0 C( t4 f" G( J3 H
} </FONT>& c  }8 L* O& t: B! M3 A4 b5 w; k

' s- s# w1 @) Q</P># `) f! R5 E7 o0 k( C
<P><FONT color=#ff0000>函数名: getftime </FONT>0 m7 J/ G( ^' p5 v5 K
功 能: 取文件日期和时间
7 T/ Q( o3 f3 D. Q" H* J$ y用 法: int getftime(int handle, struct ftime *ftimep); ) a; Z* H7 D5 ~$ @5 ~- o
程序例: </P>
( r- e3 h9 \. {<P><FONT color=#0000ff>#include <STDIO.H>  H5 C9 [! J0 S6 Y, ], I6 P6 J7 d
#include <IO.H></FONT></P>
) Q: ?( B3 o: a! t) A<P><FONT color=#0000ff>int main(void)
, E9 N" `4 U6 b# Z{ + c% f' N) F; u3 y* ^( j7 D
FILE *stream; " c; u$ S  d1 n9 C
struct ftime ft; </FONT></P>( N1 R" i3 b2 D( d! n: [$ i. [
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
* d0 C3 N3 f. X- h"wt")) == NULL) / \7 N( }0 k. p4 Q' @
{ ! A; p5 I# d; P0 D% I" Q* d. [$ f
fprintf(stderr, 6 _9 l) S6 ^" D# o
"Cannot open output file.\n"); 8 b$ q; d( M2 \- o- y$ }# A7 a
return 1;
& |0 d  C: G* j}
4 U; k6 T4 j8 egetftime(fileno(stream), &amp;ft); . E! z: U7 c4 e: E) e# ^3 z  s- @
printf("File time: %u:%u:%u\n", & z6 _# Z# R& i
ft.ft_hour, ft.ft_min, + e* W1 k, U/ I: a$ z: `
ft.ft_tsec * 2);
3 n% v/ c4 z$ z- Q6 Cprintf("File date: %u/%u/%u\n", ' Z- l6 x8 S* u
ft.ft_month, ft.ft_day,
$ w  u! e8 N/ n8 C7 @$ hft.ft_year+1980); 0 ~, h$ ~2 F& y9 f. R, {
fclose(stream); # ]0 E8 @$ a/ u0 o8 l- P
return 0; ) A4 \7 Q0 y# b  v6 G$ _
} </FONT>
; L* i5 P/ Y$ x9 n( C" n  T7 B+ l8 T# Y/ `  n

) x% X8 b, q3 R, p</P>
0 L; w# j. H4 g, L) S; [1 a! n; o<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
( }! r# T$ d% ?9 R7 o/ Q; ?: y' y功 能: 返回当前图形模式
- n& U2 y: m8 a0 w" |0 t用 法: int far getgraphmode(void);
7 g# a. n: ?8 X0 q8 x2 ~/ B: U: p$ K程序例: </P>
' }) b4 Y  k' U6 C- K6 u# U3 p6 E2 L<P><FONT color=#0000ff>#include <GRAPHICS.H>8 X, j, O8 j$ @1 b# ?) V/ D5 ^
#include <STDLIB.H>
2 b& w* j4 H$ r( l# G  c( m#include <STDIO.H>* e4 K1 n, J) p2 [/ D
#include <CONIO.H></FONT></P>
* ?3 z0 T' o9 m<P><FONT color=#0000ff>int main(void)
* d' h9 k% `) j3 D& ], I6 ]{
& |9 v* \" b/ H' ?+ W/* request auto detection */ 2 d# m" J, h& L9 e. R' Y) c
int gdriver = DETECT, gmode, errorcode; ( b! ^" g% t. F
int midx, midy, mode;
, i. E5 `* ^. \8 u  h3 S4 mchar numname[80], modename[80]; </FONT></P>
8 y' }% j; j7 z0 o1 y# F<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 @' X" @$ j7 y1 Z6 z5 B% x
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( R* a) a( n$ f" u2 _: J! M, v
<P><FONT color=#0000ff>/* read result of initialization */
5 f7 [3 L. E& Rerrorcode = graphresult(); . ~" C3 X, V3 U3 n! y; R/ E1 ?
/* an error occurred */
3 a4 a4 s, W0 W5 E$ S. n% pif (errorcode != grOk)
8 p' F7 p' p& m2 p7 L4 J8 e/ w9 T{
2 \! U3 \9 p8 U8 p; cprintf("Graphics error: %s\n",
0 j; [, S' A" |+ {$ Ggrapherrormsg(errorcode)); $ \+ R/ r( X1 B% ~* C+ m
printf("Press any key to halt:");
  v  P" {, l. _5 e/ }) R9 ?getch(); $ J" W% n$ Q, l. Z  [$ S1 U5 \
/* terminate with an error code */ & B: B6 p1 y3 `: Q
exit(1);
( @; i2 ~6 Y, y9 I} </FONT></P>$ o8 C4 F  R) v2 O' P
<P><FONT color=#0000ff>midx = getmaxx() / 2; * t3 W8 o8 f" X& e
midy = getmaxy() / 2; </FONT></P>6 O" j# W5 s. z+ X
<P><FONT color=#0000ff>/* get mode number and name strings */
/ D) P& W* n5 [2 |$ ~% m" @& Ymode = getgraphmode();
3 B1 t, F) s9 m  m$ Xsprintf(numname, ' w( f2 _+ l% u$ ?/ w1 g
"%d is the current mode number.", $ X8 z, L5 s; s0 l/ K7 l) c
mode);
8 l2 {, ~/ T$ a7 fsprintf(modename,
1 }; V: h7 P$ Q: \% Y4 {6 ]" X% ?0 j"%s is the current graphics mode",
- V0 c* T* o& i& r6 G. V" ~getmodename(mode)); </FONT></P>9 S/ c% v/ o8 N, y/ M/ X, Y
<P><FONT color=#0000ff>/* display the information */ ! f, p  ~, V( f; C4 N
settextjustify(CENTER_TEXT, CENTER_TEXT); % v: K* [. E  F5 ?
outtextxy(midx, midy, numname);
9 u' Q2 O$ I. d) }8 v9 |' _7 zouttextxy(midx, midy+2*textheight("W"),
3 j% G" `+ \  Z. \& L/ T5 Nmodename); </FONT></P>5 I+ O" @3 B. F
<P><FONT color=#0000ff>/* clean up */
! e' c/ @1 f7 o* M  N2 Jgetch();
: o) Y3 F& D7 I- A7 wclosegraph();
7 i: x2 O  V3 ?" q/ [  g& r% xreturn 0; # x4 Z2 O, a0 g, X
}
; o1 m9 H# ]6 D, r& @" x2 M</FONT>
8 K' E2 d3 N2 _: K5 d</P># j# A: c' G2 J+ J# _
<P><FONT color=#ff0000>函数名: getimage </FONT>3 W: \. k* H, p& O& u) G" I
功 能: 将指定区域的一个位图存到主存中
9 P1 G  |$ ]- c. g2 x用 法: void far getimage(int left, int top, int right, int bottom,
2 A8 B* I& L* H& G( p; C3 Uvoid far *bitmap);
4 ^' Y1 k* q2 J4 b8 H  W% K程序例: </P>+ R2 ^/ r! L; p& f' c, M( M
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! F, i" b: n8 G+ ]& a$ a#include <STDLIB.H>+ b* r0 m- T7 h1 J
#include <STDIO.H>' Q. R5 |. M  |6 ^; H' ~
#include <CONIO.H>" W% |: T* t* f2 R/ x8 f, ?2 Z4 n
#include <ALLOC.H></FONT></P>
: d( w$ U9 k% K' h<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
) m6 e) Y( l$ B- r! r  yvoid restore_screen(void far *buf[4]); </FONT></P>/ D1 o( F6 _% x1 ]" N$ B
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
% C! O9 k. V, p4 z3 _<P><FONT color=#0000ff>int main(void)
2 A/ c) B: R! U& q{ 6 V8 S8 N/ M% l5 }/ j/ E( X
int gdriver=DETECT, gmode, errorcode;
$ C' Z) Z2 v# g6 l! R) v( Hvoid far *ptr[4]; </FONT></P>0 s& @9 ~- G, t: @! b# }
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ ' r, g( |- l( b
initgraph(&amp;gdriver, &amp;gmode, ""); 4 b0 f) g3 @+ S! C5 M
errorcode = graphresult(); /* check for any errors */ - F( y7 t) z( q( {
if (errorcode != grOk)
  i) ^6 U1 Y, \% T8 z: |{
( w9 Z! j6 r; X1 [4 K7 Fprintf("Graphics error: %s\n", grapherrormsg(errorcode));
: A, v% y0 R' [! k4 @printf("Press any key to halt:");
+ H) `2 o( l& x3 w( ~getch(); , _+ w% t4 r; h
exit(1); ! p+ Y9 U3 p6 W' o1 S& m) O/ h4 V% }
} & Y8 f  X' @7 I
maxx = getmaxx(); # D: m* _6 J+ `0 W4 l
maxy = getmaxy(); </FONT></P>
5 d( k% I) X2 L* N; S4 r/ {<P><FONT color=#0000ff>/* draw an image on the screen */ , X/ I1 k. V1 Q; X4 a: A. Y
rectangle(0, 0, maxx, maxy);
* B+ ]: d* L6 dline(0, 0, maxx, maxy); ! P4 y0 R7 i5 D7 f8 r
line(0, maxy, maxx, 0); </FONT></P>
& g1 j! q5 h9 n5 K<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ # U% |0 S# f6 s# V
getch(); /* pause screen */
- q' X( b! W' _/ @cleardevice(); /* clear screen */ 8 F: \, v& |. X& Z
restore_screen(ptr); /* restore the screen */
2 W7 N; _# s: _' A3 ugetch(); /* pause screen */ </FONT></P>( F# w6 S+ |2 c  H; d" W
<P><FONT color=#0000ff>closegraph(); 2 s: }& h% @3 L( Q( w5 E' y
return 0;
9 K+ O2 A2 m- e5 I1 w# }% ~} </FONT></P>
: O4 `. ^8 ~% I% r1 y0 v. i<P><FONT color=#0000ff>void save_screen(void far *buf[4]) . u8 H4 d! ?8 Z0 i
{
  u; T  \+ `/ j! P4 Dunsigned size;
* P2 [6 h5 ^$ Z6 E2 G$ H1 X- Xint ystart=0, yend, yincr, block; </FONT></P>
" T! G( P8 r9 M5 a<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 7 g. \3 b# Q' U. @0 K1 g3 X% F
yend = yincr; ( |7 L- Z( v* {8 q+ X& R% N; c
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
0 g6 L  P% i7 W# q/ ^7 C9 I<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) ) |/ `1 a1 l9 E+ A  W# q3 l
{ 3 D" }3 L" \, ^& }8 h9 L2 L
if ((buf[block] = farmalloc(size)) == NULL)   |) K& {* ?0 ~% i9 P
{
3 W: _8 {* T9 ~4 B( hclosegraph();
' ?- b- W' }( ~' ]$ W" T# hprintf("Error: not enough heap space in save_screen().\n"); ; O: e: d1 F3 P% K6 g
exit(1);
; C$ O' A- I4 \; h! Z7 U9 H} </FONT></P>- s- s; r. y- `3 E6 B
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); # J/ U  t/ b1 X
ystart = yend + 1;
- |# E1 g+ Q* z2 R" fyend += yincr + 1;
: V: L1 y4 n1 f; Z. l( B0 i( R. z}
$ z1 o% [, m, o2 Z* @# P: p/ s} </FONT></P>+ Q  ]5 ]% D2 Y$ e4 p6 r
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
) G$ K  ?' F: G+ y- [! l0 e{ % F" o) R4 _1 o% n% v
unsigned size; ' w- p8 {& E0 r% `" L! Q- d2 I( F- S
int ystart=0, yend, yincr, block; </FONT></P>" Q! v! H8 r2 T& g; x8 Q
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
9 `; k( i2 I. `5 Wyend = yincr; ; b" T: [  ^+ Z  F% S, R
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
% O. q8 z- J2 }' ~# O* |" K( |<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
7 F( c; y) {2 ?2 d% h4 J6 l{ ( h0 [, L, W7 _: r- Z% }8 S* a
if ((buf[block] = farmalloc(size)) == NULL)   |$ Q7 ~& @- j3 G% S: K0 k% `; q. i+ ]
{
0 s+ q7 B" i2 ]- j) kclosegraph(); ) @' r5 J0 o) J( M. T
printf("Error: not enough heap space in save_screen().\n");
! O6 M4 y* R# e" T- ]6 iexit(1); 6 `4 U. h6 N' f! H( r
} </FONT></P>
1 o: o2 x+ _# {% g9 f* N5 s. ^7 g<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
5 l- K/ g1 a7 v# @ystart = yend + 1; " @# l' j0 D$ B
yend += yincr + 1;
* b( C% Z8 E: ~4 s3 x}
2 s1 k# X2 k5 f; [} </FONT></P>7 o/ t: E6 R+ H* M
<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) 8 C! e( L% l4 k! w
{ , G$ e' u6 H- k, ^! w1 N) L
int ystart=0, yend, yincr, block; </FONT></P>
# _1 P0 l, ?  B! \8 R<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
" Q& J* q1 N# v; [, P( vyend = yincr; </FONT></P>
' A* L  p  Q( ^<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
, V( w0 p$ i& Y3 C+ B' `' @{
, y- y6 w& `8 s. [* t6 sputimage(0, ystart, buf[block], COPY_PUT); 3 R( K& Q) \* Y* q
farfree(buf[block]); 2 N; Y8 N7 K2 G) z' I. ^* H
ystart = yend + 1;
5 v5 t, b3 Q# f1 f5 g- hyend += yincr + 1; ; @. ^$ @2 \+ Z2 A$ R5 O
}
, f; T4 J2 Q8 I$ m1 T1 v# Y} </FONT>
: P, |- q' X& r4 X<FONT color=#ff0000>
1 r1 y7 v" {" E( ^</FONT></P>$ ?1 _9 A8 r# P! \
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
5 E" B# h2 S. d) d! @1 o; f功 能: 取当前线型、模式和宽度
9 O& J1 B3 j( O% z7 C用 法: void far getlinesettings(struct linesettingstype far *lininfo): ' j+ p# Q# z6 o, N7 f. c. d
程序例: </P>
0 V& w3 e8 x) g) z. l+ B  q, q<P><FONT color=#0000ff>#include <GRAPHICS.H>; z/ m: K- H. Z/ X# O( a) C
#include <STDLIB.H>
# t% O! R( t# N1 M#include <STDIO.H>+ `. k  r" `6 s5 W0 j: r8 d
#include <CONIO.H></FONT></P>
" Z9 f' }8 ?5 F<P><FONT color=#0000ff>/* the names of the line styles supported */ ! x% v$ x! f5 E& U/ S$ J
char *lname[] = { "SOLID_LINE",
2 f6 d' N, Y6 M( D% Y6 @"DOTTED_LINE", - x; a0 D- K5 _# T/ a6 Y. a6 z8 b
"CENTER_LINE",
: f) I3 o9 n) |% q, ~2 j. x"DASHED_LINE",
/ I! O% [% o  K5 }"USERBIT_LINE"   p9 q# c8 S( v" V6 E4 |
}; </FONT></P>" U0 s9 N" J/ w$ ^" n+ d! }
<P><FONT color=#0000ff>int main(void)
- A4 p: u/ E# W, ?2 d{ , |5 D' G- t0 L/ `+ `: h9 u7 r% w
/* request auto detection */ ; Z3 ^: H+ I* q8 Y
int gdriver = DETECT, gmode, errorcode;
0 J( U3 Z! W- T/ C2 Tstruct linesettingstype lineinfo;
- V" S- l# ^1 |8 h/ m- E/ K$ ~& Oint midx, midy; ! [- A" e/ H/ L0 O% K
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
0 C2 D9 N7 W% P- n. V<P><FONT color=#0000ff>/* initialize graphics and local variables */ , R3 b2 m" B* n% D6 W/ D8 P" Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' `% y( S4 Z: L; h! @1 ?) Q% f$ [
<P><FONT color=#0000ff>/* read result of initialization */
; G" a  i9 ?4 [5 Nerrorcode = graphresult();
4 I% k7 R. Z, l4 xif (errorcode != grOk) /* an error occurred */ ) h" m$ b. }! w7 B
{
/ D$ J6 W' g7 R6 X/ A8 p0 s! d  Aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! j8 i7 }  v+ q1 d" [printf("Press any key to halt:"); ! J; r7 @: q/ K7 G
getch(); ; x; [( Y# ?9 \' Z6 Z
exit(1); /* terminate with an error code */   p9 D8 {- y$ k# D; e
} </FONT></P>
; F- r' j# [6 k2 ?5 M<P><FONT color=#0000ff>midx = getmaxx() / 2; $ M0 {& G, Y+ A8 t
midy = getmaxy() / 2; </FONT></P>( w$ K) W) q- Z1 m* d7 p: X7 m
<P><FONT color=#0000ff>/* get information about current line settings */
- o( z8 B. |% s" W% ^; B& c8 Rgetlinesettings(&amp;lineinfo); </FONT></P>
! u! n3 @: ]" z$ k2 ?<P><FONT color=#0000ff>/* convert line information into strings */
: {& `7 l. L9 g: d1 lsprintf(lstyle, "%s is the line style.", + _) Z8 _3 Q, c, j3 M
lname[lineinfo.linestyle]); $ f* T4 P9 I9 a: C) [0 k7 \5 @
sprintf(lpattern, "0x%X is the user-defined line pattern.",
: Z- H8 [/ P7 m7 G& Rlineinfo.upattern); 3 w$ X' |" ~+ Y$ h  I
sprintf(lwidth, "%d is the line thickness.",   E& n; B8 r$ Z5 B+ M% ~
lineinfo.thickness); </FONT></P>
% U9 O9 Z! |3 V- B<P><FONT color=#0000ff>/* display the information */
! D" k$ u0 P. H1 j& A$ m) csettextjustify(CENTER_TEXT, CENTER_TEXT);
' p& N3 n- Z3 `/ p4 }outtextxy(midx, midy, lstyle); / S& X, R. [" @; e2 Q
outtextxy(midx, midy+2*textheight("W"), lpattern);
$ O% P' }9 d3 i* S: Oouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
  ^4 B* S' {9 Y: P<P><FONT color=#0000ff>/* clean up */
5 u% B; V' ]  K4 Ogetch(); # r+ p6 b) i$ e% E7 ]0 ?
closegraph();
$ s) n8 d8 j! f0 X' G1 w/ K4 |return 0; ) g0 G- ~8 _& n$ g
} </FONT>7 X3 A+ x1 W( e2 }& ?

+ S+ e* {& Y$ |& y1 `/ q</P>
) F: i* ^* V" Z* H& D" c4 G<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
6 K  L+ W2 J- V& Z8 b1 R0 b功 能: 返回可以传给函数setcolor的最大颜色值 : q/ ?. J0 Y. Q: j' i
用 法: int far getmaxcolor(void);
8 F* r7 p. r1 Y程序例: </P>
; t, o; {+ q; ~. {2 k% z; D, e<P><FONT color=#0000ff>#include <GRAPHICS.H>% J5 ?8 m" p+ I* b/ t4 l* `' u
#include <STDLIB.H>
2 B% k$ W% g. H& `6 ]0 F$ b0 ]#include <STDIO.H>
/ m: D$ v. V9 ]+ ]  q#include <CONIO.H></FONT></P>
  z7 w: l  `2 ^3 E! B3 m6 c<P><FONT color=#0000ff>int main(void)
3 t. S" @8 J& C! M& k3 Z{ + o+ ]6 X- o0 S& e7 K, e
/* request auto detection */
8 m$ w, a$ @6 Tint gdriver = DETECT, gmode, errorcode; % a- q0 J) Y" }! I1 B$ I' I3 p
int midx, midy; & n. a- j' h+ e# c
char colstr[80]; </FONT></P>. O9 Y  [8 s$ n5 L6 L
<P><FONT color=#0000ff>/* initialize graphics and local variables
5 i! o* g. O* C# W, l' v0 X+ I*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; W: K/ s) T' q
<P><FONT color=#0000ff>/* read result of initialization */ . ?  ~3 u- S3 K2 m
errorcode = graphresult(); 3 u( N! c( n/ @% f' P
if (errorcode != grOk) /* an error occurred */ 2 x4 N! U0 H- L& Z
{
6 Y+ q8 c$ E: ^printf("Graphics error: %s\n", grapherrormsg(errorcode)); % x/ K7 T) Q# u$ W# X! o
printf("Press any key to halt:"); 5 }3 @; d1 |0 h: S- N- ?) Z; ]
getch();
' G) t% b, F) Q; P9 Q9 fexit(1); /* terminate with an error code */ + C$ T/ S4 n9 i9 Z! I
} </FONT></P>
! Q; I* C+ J5 j& d, I% Y<P><FONT color=#0000ff>midx = getmaxx() / 2; / ], v. h/ o! |! {; \: H
midy = getmaxy() / 2; </FONT></P>
4 W' ]/ Y. h( L<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
1 k* F9 M. Q) f  S2 ^sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>6 S; d/ y1 P) \, |) o. ]
<P><FONT color=#0000ff>/* display the information */ 6 O4 _2 C. r  _4 C
settextjustify(CENTER_TEXT, CENTER_TEXT); 0 `9 C( H' l) E' c& D# ~
outtextxy(midx, midy, colstr); </FONT></P>
2 r3 a/ ?' w2 y, v<P><FONT color=#0000ff>/* clean up */
9 \! f  `9 [) K6 h+ Q* N- x3 Kgetch();
  N% s& B, r8 f# Tclosegraph();
9 R3 j) r& Q" X3 G8 ]return 0;
: U, Y, H+ d7 x7 v  w, g9 O} </FONT>. ?" b! [/ Y3 ]7 W! P# j0 H
( o& U4 z9 S" e$ w" v9 ?7 U

: S0 o9 N- ?7 n0 R5 m</P>
! P5 `1 r! l' f5 p, v; ~# e1 e! A+ s0 Z<P><FONT color=#ff0000>函数名: getmaxx </FONT>
5 M0 s6 A* i/ Y  x/ {6 {功 能: 返回屏幕的最大x坐标 8 |1 M. C. W: Y9 a2 V; @+ ~6 R
用 法: int far getmaxx(void);
, ]# R+ g5 H$ G: `2 J: C# w程序例: </P>3 ^$ G9 o; z, D# i5 B
<P><FONT color=#0000ff>#include <GRAPHICS.H>9 Y) c* Y4 u% e5 r) d( `: E
#include <STDLIB.H>
5 D) [* @8 H/ u0 M. ^2 |3 y#include <STDIO.H>3 J7 W# h. o7 E
#include <CONIO.H></FONT></P>
4 p+ n# z$ T$ B% i- J* A<P><FONT color=#0000ff>int main(void)
: s$ e* I( ]8 B: P  C" F- A{
2 t, E8 `# i+ B  Q$ t4 e0 H/* request auto detection */
/ z8 \" h) m5 \! Y1 H3 Xint gdriver = DETECT, gmode, errorcode;
/ G7 z$ `4 w% k/ }7 nint midx, midy;
4 S; E( ^# j( Lchar xrange[80], yrange[80]; </FONT></P>$ j+ p9 D6 G& s- r
<P><FONT color=#0000ff>/* initialize graphics and local variables */
! H- O4 }) m6 @: E8 u8 y9 p0 Zinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 v% d) i7 K% J2 o/ n( h
<P><FONT color=#0000ff>/* read result of initialization */ 9 S+ G9 ?( O0 D' r
errorcode = graphresult();
" V4 S) L5 l: H5 ^8 I/ Y* m# wif (errorcode != grOk) /* an error occurred */
( h: P' \& P* l6 a* f) W, w{ ; A5 g3 I1 p) k$ E" `3 J
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - m0 K7 t% \6 @; ]* R0 ?( Z* V
printf("Press any key to halt:");
& F4 V0 r" C3 t3 O4 p6 ~; |3 ogetch();
7 @! `% s0 \: q+ v, wexit(1); /* terminate with an error code */
1 v4 o$ n" O* y2 u; `% A5 d} </FONT></P>
! M7 h9 e& J0 _0 A2 L<P><FONT color=#0000ff>midx = getmaxx() / 2; ; @( a1 F& p* V
midy = getmaxy() / 2; </FONT></P>9 k" D7 T' i# K7 ?" _2 _
<P><FONT color=#0000ff>/* convert max resolution values into strings */
4 e0 L) D6 O1 C- y+ V$ ~5 \* _  osprintf(xrange, "X values range from 0..%d", getmaxx());   Z) F' g& e0 J" S0 X3 g4 b
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
' p5 Z% M" ^' @9 v( o<P><FONT color=#0000ff>/* display the information */   t6 ~. Z* V1 |7 Q' a5 c
settextjustify(CENTER_TEXT, CENTER_TEXT); * [4 P& I8 }$ X$ }  z
outtextxy(midx, midy, xrange);
6 G# [: z& f+ o+ r# g$ @! d" I7 U  pouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
+ C$ N* [- V5 n9 S+ t* U9 _7 \<P><FONT color=#0000ff>/* clean up */ $ H' J; A4 t2 E& |$ g9 U
getch(); 7 Q4 c& w, \3 |% P6 E- q
closegraph(); / R! G, L' @1 k# y! L# j. |
return 0; $ ]) v. k# n2 K) ?  B7 Y
}</FONT>
7 p2 D1 Q) f5 B% `' O/ T* x4 V* Z) s1 u& `
</P>% Q6 z3 F0 X. C5 o3 z  G. C
<P><FONT color=#ff0000>函数名: getmaxy </FONT>
3 }. ?4 K. ~% R功 能: 返回屏幕的最大y坐标 & u& o, Z( Z. p. N8 y7 Y
用 法: int far getmaxy(void); - T- N7 V4 [% s' v* s1 G  _+ N
程序例: </P>
: N4 G( P; ^6 Z' u. H! Q* h<P><FONT color=#0000ff>#include <GRAPHICS.H>- B) A( r8 \4 Z) [
#include <STDLIB.H>. }" Q9 }- b" n8 t
#include <STDIO.H>
- ~; S# n7 g) n) V. n# }#include <CONIO.H></FONT></P>
# ]# D6 h; R( G0 c<P><FONT color=#0000ff>int main(void) + k6 ^6 q# B1 _& M: {2 y7 X
{   X9 d! m! h; R, t8 j$ `
/* request auto detection */
* u" n! Z& S1 F2 n! X8 pint gdriver = DETECT, gmode, errorcode; . b* ~* o3 G) _  G& I3 ~; W
int midx, midy; # E. |7 _! j' M  D- C* X- @
char xrange[80], yrange[80]; </FONT></P># m/ }% Z* x( F/ ^! H- @' E
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# S0 i# `9 j6 X9 \& F. T! G) Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ ]; J% C3 E. s1 h<P><FONT color=#0000ff>/* read result of initialization */
/ J, V  y2 V$ t9 U8 n7 a0 F2 o5 [errorcode = graphresult();
- }0 E- F' D& `* L  p, Kif (errorcode != grOk) /* an error occurred */
' h" P/ b9 t" H0 `8 v" g5 z: _{
  e3 C  d5 J* Z! `2 {/ Y+ cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 p0 c0 j5 e( }& g: u$ S
printf("Press any key to halt:"); 4 }; ^( V9 g- j' Y+ x8 s6 [
getch();
. o! u. [% d& ^  rexit(1); /* terminate with an error code */
5 a5 B8 s+ K1 p8 f} </FONT></P>
. A# S( b1 Q% ~" G: I2 N% u<P><FONT color=#0000ff>midx = getmaxx() / 2; * p7 k. |4 J- U9 T( G+ V; {
midy = getmaxy() / 2; </FONT></P>4 y- ^8 ~' _0 z  m
<P><FONT color=#0000ff>/* convert max resolution values into strings */ / e& ?2 J6 E) j. a! j+ L4 M
sprintf(xrange, "X values range from 0..%d", getmaxx());
! g$ R% A; I$ }8 M9 L9 o2 Esprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
/ t) e) p  i" R6 {$ }; `$ Y<P><FONT color=#0000ff>/* display the information */
+ X, b, m8 G2 s# psettextjustify(CENTER_TEXT, CENTER_TEXT); ' m5 I4 P/ O6 H) {
outtextxy(midx, midy, xrange);
: M) S; f* h4 \' Houttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
4 K! G! B: U  {- ^1 u  H/ P<P><FONT color=#0000ff>/* clean up */ 6 h# [" l1 z- T% ]8 ~; g
getch();
4 [. T- y& C- F$ Rclosegraph(); ! _+ [: c4 l4 `5 ~% Y+ q
return 0;
. m- Q- r" A; S9 b. j# C3 |} </FONT>
: @, f: `+ n/ ~: J3 }3 h! N9 R  J</P>
' a- {, Z3 j$ N; x6 g8 x1 Q* t<P><FONT color=#ff0000>函数名: getmodename </FONT>
6 C% T! i' V1 ?功 能: 返回含有指定图形模式名的字符串指针 2 m6 g. v  ^1 F3 F) m1 s
用 法: char *far getmodename(int mode_name);
( d" |1 m6 z; d$ Z* U7 T$ f" S程序例: </P>
( ^7 c6 P. P! v1 J; B<P><FONT color=#0000ff>#include <GRAPHICS.H>. W! [* q# f3 N5 T. J2 S( f
#include <STDLIB.H>
. ]7 E8 ]; ]2 x2 d5 c#include <STDIO.H>
5 G9 ?) v1 {8 y7 F# P! ?) E#include <CONIO.H></FONT></P>- U9 @+ k, h9 \
<P><FONT color=#0000ff>int main(void)
6 N, @" ~4 E& Z& \{
9 I0 l) H4 E3 k( G5 G- t* |8 U/* request autodetection */ % A" T4 o* p" `9 M9 T0 H0 |
int gdriver = DETECT, gmode, errorcode;
' d2 ?3 g# x5 P0 A7 I/ cint midx, midy, mode; ' K) X' ?0 z6 I  P# e5 D- u: r( q
char numname[80], modename[80]; </FONT></P>
3 y! H6 X' T! F<P><FONT color=#0000ff>/* initialize graphics and local variables */
( i, A! B- P, M- ^% ]2 finitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>% m# O! Z, B2 ?4 c! s0 L+ {9 o- x
<P><FONT color=#0000ff>/* read result of initialization */ : [/ A0 [* A0 v! D5 @
errorcode = graphresult();
% z0 o2 m. q/ m4 e8 zif (errorcode != grOk) /* an error occurred */
6 N+ q( x7 Q- [3 H{ ) ]- u) L% v4 C9 l) n
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 h4 r+ ?9 r9 O# s9 w' i2 T+ H
printf("Press any key to halt:"); 8 d9 T7 j0 h5 K; G1 L) \1 }9 T" }
getch();
- N2 B% u: ~* Nexit(1); /* terminate with an error code */ , \' [" _7 m/ X( ^# w7 O6 G
} </FONT></P>
: X: I8 b& |. t6 q' l<P><FONT color=#0000ff>midx = getmaxx() / 2; ( O1 d( M+ d# g0 |2 c" V
midy = getmaxy() / 2; </FONT></P>3 y, }1 ~2 _1 M! e; l
<P><FONT color=#0000ff>/* get mode number and name strings */
- v5 S( W5 m- ^. t5 F& l9 q& wmode = getgraphmode(); ) U+ r  B. @3 l- H
sprintf(numname, "%d is the current mode number.", mode);
  T' |/ Z6 `6 }' m6 jsprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
* \+ v' `9 d/ l" q- F<P><FONT color=#0000ff>/* display the information */ 9 Q; t5 w2 N* y% E" A
settextjustify(CENTER_TEXT, CENTER_TEXT);
% L8 F( K8 g! g* {outtextxy(midx, midy, numname);
5 W! I( @& c8 X1 c1 s' L* Youttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
2 D/ j( C. D+ B, a  b+ c7 A$ q, K9 v<P><FONT color=#0000ff>/* clean up */
( v8 T( I% B; W8 u7 kgetch(); * |# c0 t3 R  _: u' D- O
closegraph();
9 J$ \# s" k2 \return 0; * u; j" b" F; d- ?% v+ u
} </FONT>
0 I& [+ B3 J2 x: K" y% {6 g4 ]5 S+ z. ^" E2 a
</P>
) L9 K% B' m& P5 P; i8 a<P><FONT color=#ff0000>函数名: getmoderange</FONT>
# S# P1 j5 _( |# u" {+ ^; y- H$ J功 能: 取给定图形驱动程序的模式范围 0 C! H7 Q  \2 h. j% R
用 法: void far getmoderange(int graphdriver, int far *lomode,
& F0 I# a" f' Kint far *himode); * e0 J# y- f  c
程序例: </P>. W; _  g, y- A( @, E6 m9 }
<P><FONT color=#0000ff>#include <GRAPHICS.H>% z8 G2 q* c* h7 e+ N
#include <STDLIB.H>
$ t+ C! K7 l: N0 f+ [  k#include <STDIO.H>' T6 @# a! C3 I: G3 F
#include <CONIO.H></FONT></P>
! ?; J, F3 m# [& I: l<P><FONT color=#0000ff>int main(void) - L8 b! _9 O0 I$ M# `2 J0 \3 f
{ " o, M2 i' N- l/ N
/* request auto detection */
) y" n$ _" |/ {6 ^' h. Aint gdriver = DETECT, gmode, errorcode; 8 Q! S; q- }7 @$ M' F) M
int midx, midy;
( X# M5 [% L6 d" O* j" mint low, high;
& ?( k0 K, T3 `5 a) ]9 kchar mrange[80]; </FONT></P>$ d  N8 U4 P7 b- Z1 v$ s6 {4 W! I
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' Y) Z# }- S4 Y  [* pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 d! I+ q6 ~3 [9 D+ C<P><FONT color=#0000ff>/* read result of initialization */
9 y' f% g. _6 i2 \4 F" H& Z( Jerrorcode = graphresult(); # ~8 d1 e7 B# p1 A* H3 d( v/ q
if (errorcode != grOk) /* an error occurred */
8 o# C4 Z2 R' }6 p{ * h4 O! k3 D& w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 ]4 m7 q  M8 d, T
printf("Press any key to halt:");
: ]' x7 U: p' ^3 F: R( x) ^, Zgetch();
% m% b. ]7 l8 X5 S% \( M4 f) _4 Wexit(1); /* terminate with an error code */ % ~7 n. P0 l5 \: r
} </FONT></P>
% s/ N3 @9 Q( m- v6 D# f* @<P><FONT color=#0000ff>midx = getmaxx() / 2; + ^( S+ Z9 V5 J" Z9 M+ P; i: V
midy = getmaxy() / 2; </FONT></P>
! O' K. U" P$ W<P><FONT color=#0000ff>/* get the mode range for this driver */
1 J9 e* Z/ d* p; k- |$ X8 l: Hgetmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
$ H# U0 I) K+ O<P><FONT color=#0000ff>/* convert mode range info. into strings */
- Z6 R0 R) S+ n/ f, k: E2 |7 usprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>% Z+ g! Z- V2 B$ ]+ J" O; w) N4 l
<P><FONT color=#0000ff>/* display the information */
9 `) y4 e: z% a* b# d# asettextjustify(CENTER_TEXT, CENTER_TEXT); ; J" S( S. t- c$ ]( ~6 J; E; |
outtextxy(midx, midy, mrange); </FONT></P>
/ y" W! p4 |+ a) T. P<P><FONT color=#0000ff>/* clean up */
# L7 h2 v8 ?. j: P( Mgetch(); 9 b9 N) x; N  y0 P
closegraph();
9 E) u$ j6 q( `: areturn 0;
; X9 z8 |/ x& h$ P3 ?3 U} # U* C5 R7 v& S5 P4 j0 V) Q
</FONT>
, t0 J" x- r4 \5 o, B0 E</P>
( {& _* U9 `2 h! f<P><FONT color=#ff0000>函数名: getpalette </FONT>
7 U( Y, M# _& f7 o2 c3 T& L功 能: 返回有关当前调色板的信息 1 y7 I0 N: a7 ~1 s. v  q6 b! n/ C5 i
用 法: void far getpalette(struct palettetype far *palette); ) I& f2 s4 M0 h1 t" M) V
程序例: </P>
; ^5 W% j5 A" ^7 v) f<P><FONT color=#0000ff>#include <GRAPHICS.H>* x1 T. `- a  T* @
#include <STDLIB.H>6 @) }: Q) T5 G5 e" h5 O3 j
#include <STDIO.H>6 S/ ]4 G7 C# w* @& c5 n
#include <CONIO.H></FONT></P>
: y8 [6 T& o  c9 _<P><FONT color=#0000ff>int main(void) 9 P+ |/ Z) u) G* B. A
{
$ D0 k) o7 Q" c* L) x/* request auto detection */
1 G+ {7 }" \& J) _& `int gdriver = DETECT, gmode, errorcode;
1 h+ I2 T, q( F. Ustruct palettetype pal; ( F# p# T% W' f; O+ X; u6 ^
char psize[80], pval[20];
5 @0 B: T; i& aint i, ht; 9 P4 w7 z7 ]8 u
int y = 10; </FONT></P>
. ?: d" K# N9 w: j& Y<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 K7 p1 g; i/ z8 a. g5 ^: h
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ F) w: y6 [$ H$ R: Y; ?2 C
<P><FONT color=#0000ff>/* read result of initialization */ 5 n+ ]% D) A+ d0 u5 |- S
errorcode = graphresult(); " {* B$ P8 z) ^2 Y# P$ ^. `
/* an error occurred */
3 P8 i# K$ y' c4 jif (errorcode != grOk) 5 i  ^# R) E2 j1 J# ?. w9 g6 d' _
{
/ P9 u0 |6 ?; U4 Uprintf("Graphics error: %s\n",
  D! z( U3 ?9 wgrapherrormsg(errorcode)); ! B- D3 z7 b  c8 L2 Y# @1 H
printf("Press any key to halt:"); ; F) g/ g3 {( [! `
getch();
9 F: E- h" d$ c; t3 V$ }3 O. d% `/* terminate with an error code */ 6 q, M1 U' U0 ~0 J$ J- B1 v
exit(1); ' C/ L* w) y6 a0 t- T
} </FONT></P>  C- G$ |4 B" Z* [
<P><FONT color=#0000ff>/* grab a copy of the palette */
  U# u* W; y! u" mgetpalette(&amp;pal); </FONT></P>
1 Q# u5 t* E- v! t) H1 Q<P><FONT color=#0000ff>/* convert palette info. into strings */ 4 j% o  [, }' v+ ]
sprintf(psize, "The palette has %d \ 5 E: S% h5 p6 |, y
modifiable entries.", pal.size); </FONT></P>
2 v# d- k% V; K# B<P><FONT color=#0000ff>/* display the information */ / E& S% G* g- I  c: F1 X: a
outtextxy(0, y, psize);
. a2 A; O  C3 cif (pal.size != 0)
' f; F" L8 S. N8 c* d/ L{ ) I7 ?% @8 k  w3 g# H7 w2 e
ht = textheight("W"); # v" @5 ?: @, P' U& g. T8 ~- d
y += 2*ht; * S2 p0 {6 p# n( E( Y2 ^+ Z& [9 G
outtextxy(0, y, "Here are the current \
0 {3 p0 ]  X, U4 {  Q/ qvalues:"); 2 Z% b$ j5 k' `5 Q2 e
y += 2*ht; . O  ^6 q% J9 F$ l0 k, e
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { & W1 C  W, D2 R- w
sprintf(pval,
% b9 a! d0 T) S( N"palette[%02d]: 0x%02X", i, 7 _4 `% @4 }7 Z) B  _3 [8 ?
pal.colors);
" V* T5 Z( }5 Houttextxy(0, y, pval);
! a& G; q; |& J: }8 M2 \5 Q% v# r/ }}
; p; O+ J9 `% k} </FONT></P>
5 g! {, M/ m) n  A<P><FONT color=#0000ff>/* clean up */
5 u0 a) s8 {# a# i! H$ V, Tgetch(); & g1 ~) H" o6 n! L# B$ g2 t1 E
closegraph(); </FONT>- d' j, ~  c+ W( R  v
<FONT color=#0000ff>return 0;
1 o1 @2 O7 C/ _1 ]' ~3 b} 1 o0 v, ]" u! y; N" v% a* |
</FONT></P>
( x( t/ Z: V2 i) n<P><FONT color=#ff0000>函数名: getpass </FONT>
8 X5 \( X0 {! E功 能: 读一个口令
/ R% m2 j6 o. L, [. e' o用 法: char *getpass(char *prompt);
& o, P( M3 [* ?- S4 i程序例: </P>
; [. Y4 L+ i1 t9 \/ [& N& }<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
/ P# M# e8 R% A+ g' i4 X5 m: {<P><FONT color=#0000ff>int main(void)
0 Q$ W( y  S+ |# j: K4 o( }( U{
6 |  r) e1 O# Y, I; c; T5 ychar *password; </FONT></P>, _/ I/ d2 [4 Z
<P><FONT color=#0000ff>password = getpass("Input a password:"); 5 Y# X" s3 {  H, Z7 ]- b
cprintf("The password is: %s\r\n", , `8 U$ T% F$ ]$ x% k' v9 F' f* e
password); % O# _' k" v6 v8 N
return 0; 6 f! `! i( T! u3 |; N
} 4 f7 V! K+ F2 d" @9 k
</FONT>
5 i4 Q8 h7 h5 T2 `
/ z- t1 C3 t: Q. ^1 f$ s</P>4 y7 n$ V- F, y. ~8 O8 U
<P><FONT color=#ff0000>函数名: getpixel </FONT>
3 Q3 K5 }* }8 _+ u- d, O5 O功 能: 取得指定像素的颜色
: o; G: Q1 j) d用 法: int far getpixel(int x, int y); ) H" o4 l' N$ p% [
程序例: </P>3 H% h6 d* ?4 o# a* {' ?
<P><FONT color=#0000ff>#include <GRAPHICS.H>( N7 V" ^8 d2 F; _/ a2 H+ R
#include <STDLIB.H>
. ~4 c, I4 ?5 D& [% v#include <STDIO.H>/ q; w5 L' g" q# l7 |
#include <CONIO.H>
( j* s' X4 s+ d" c#include <DOS.H></FONT></P>
- Q& U# W) A. {0 v<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
* v7 H" u: r% K! b% Z7 \8 C+ p#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>* i, X9 y6 s- l0 j0 l/ W: A" |
<P><FONT color=#0000ff>int main(void)
: n( ]: E8 |/ _& ^{
3 n. l# n  s1 M4 c9 |/* request auto detection */ 0 b4 B- B0 v5 ]4 p8 C
int gdriver = DETECT, gmode, errorcode; + j) j3 S6 A+ d" V/ v" l9 S- C0 U
int i, x, y, color, maxx, maxy, 2 M* M& o) @' [# N
maxcolor, seed; </FONT></P>, l5 }0 y  L7 }2 m+ Y! [# X  X
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& R/ I. S3 O% P7 \! A$ `6 W! |: _initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 M+ z1 a' |: y7 C' ^) p<P><FONT color=#0000ff>/* read result of initialization */ * H+ R* d  _% r* L7 |- X
errorcode = graphresult();   w; B0 k5 \/ v, _  o4 S) G& |
/* an error occurred */ , R0 l) x! i+ k
if (errorcode != grOk)
" {# y4 m6 ?) Z2 j2 d9 P; Y{ * D5 \/ d& q. e! E% k# l% s& Y
printf("Graphics error: %s\n",
/ C' X9 k* `6 n' Rgrapherrormsg(errorcode)); 8 A+ D0 `7 H+ k
printf("Press any key to halt:");
2 b0 L6 X# {6 K+ S$ N& I* B/ ^getch();
+ Z4 }2 s$ K) F; P1 i5 c/* terminate with an error code */ 8 y$ d4 @9 {5 U, s3 b) e  t
exit(1); 0 w6 U2 D& ]" m% p2 I% T# m. r) h# F
} </FONT></P>. N; V, n/ C$ S( F! C. h
<P><FONT color=#0000ff>maxx = getmaxx() + 1; - R& b: F$ P" k, ?) n
maxy = getmaxy() + 1; , g5 [& T6 q' {
maxcolor = getmaxcolor() + 1; </FONT></P># L( r9 Z# `* O/ u/ f2 m
<P><FONT color=#0000ff>while (!kbhit())
3 F+ j1 F2 I% ]! G{
: r- t8 i& ?( d" z- P- L- `- @/* seed the random number generator */
6 o( V1 n9 {+ ]  i8 hseed = random(32767);
$ U8 i# `9 a7 X+ fsrand(seed); ! U7 T9 P' X  p" w* D) t( V4 g! D
for (i=0; i<PIXEL_COUNT; <br i++)> { / y9 Z' i# d) \
x = random(maxx); $ s+ c) H, Q2 ?" i
y = random(maxy); . f! ^, z8 d) A
color = random(maxcolor);
$ Z! {: X- a$ p& |. D& A9 D9 }9 wputpixel(x, y, color);
6 Y+ e  J/ p8 _; Q, M( n} </FONT></P>5 K. X7 E" S' s7 I6 G( z
<P><FONT color=#0000ff>delay(DELAY_TIME);   {' @! [3 b& l/ g: t( v
srand(seed); ) b$ c+ u4 \9 v( p; S& ?
for (i=0; i<PIXEL_COUNT; <br i++)> {
5 K3 j5 i3 U3 Z/ N; ex = random(maxx);
6 p) X4 b; Q( u3 D. Ry = random(maxy); 5 O; r6 \& }  D" \4 ~9 ?5 \
color = random(maxcolor); + I& J9 }4 @, p+ t  {/ Q" ?' s/ q
if (color == getpixel)</FONT> </P>
1 o% t- c8 G7 u# T4 r4 }<P><FONT color=#ff0000>函数名: gets</FONT> . h4 C& L1 Q4 d  `' }* i% k! o
功 能: 从流中取一字符串 , i5 D1 `% F, e4 a- x7 H
用 法: char *gets(char *string);
* W7 @% n! d8 b$ b* E程序例: </P>* L5 G4 a9 `% [
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>5 _; @. w2 a6 U$ O( Y5 N
<P><FONT color=#0000ff>int main(void)
2 D( J. z  F- D{ " h$ p. t6 f* _/ r5 s1 @0 ~) Q
char string[80]; </FONT></P>
5 x0 `; O, v2 [<P><FONT color=#0000ff>printf("Input a string:");
' j$ z# ]% {! t: dgets(string);
, ^6 a) z6 n5 ?4 s8 u6 p( jprintf("The string input was: %s\n", & \: o# z( I6 k  L
string); 6 C  ^6 S: P+ M' |2 h0 F
return 0; # _8 I, |; [) `4 Y' N
}
# b+ M6 U$ T; E( ]  O( ]! y/ {; v. s+ x1 o6 J% W! C/ a
</FONT></P>$ U- U: O& y0 G$ w1 O2 t
<P><FONT color=#ff0000>函数名: gettext </FONT>
3 z- N2 H. ]$ ~! |8 c功 能: 将文本方式屏幕上的文本拷贝到存储区
& m. e2 ]/ K! S& D- z( X* l2 g用 法: int gettext(int left, int top, int right, int bottom, void *destin);
+ C# r+ v# E4 O1 h程序例: </P>0 E0 v' @& i6 {$ {
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
" ]( e& E7 `6 \5 r; K<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
" F8 S0 K/ |' U- E  W* \% Z" R; ^<P><FONT color=#0000ff>int main(void) 0 x7 C( |) K" J. j3 q; L
{
$ z" D( |" L; l1 U' n5 U% h  rint i;
# L, c1 C  ^! f7 H) M. Z+ Pclrscr(); " z# v3 y9 g0 l5 P5 z6 j
for (i = 0; i &lt;= 20; i++)
  c$ T' I$ K' T) n, ccprintf("Line #%d\r\n", i); 8 z% U: N0 D; v: U7 }6 C# Q8 N3 H: c! W
gettext(1, 1, 80, 25, buffer); , _) q) t- U' S3 L8 j8 x1 }
gotoxy(1, 25);
7 {, y% y" V( g- a# w$ ?cprintf("Press any key to clear screen...");
& F  r; t# ?- Y% Mgetch();
0 B$ S- E" S1 ^clrscr();
, W* {7 x# O3 x: \4 ngotoxy(1, 25); 5 o& L8 n5 O* ?$ D4 b; ^- o/ c
cprintf("Press any key to restore screen..."); ( Y3 r/ g4 t, D* V
getch(); 2 I& O6 I7 B/ X. i
puttext(1, 1, 80, 25, buffer);
, {* \  H4 {2 A! e. y" {gotoxy(1, 25);
; j% b9 f. O3 X% ^8 O/ Vcprintf("Press any key to quit...");
% B4 D, c3 ?) a- z* ], bgetch();
0 f/ O; D8 |5 x5 N7 @return 0; 6 O- l( `! k4 I: [. x$ i: F7 d3 [
}
! L/ o3 n5 U0 e+ q+ E" ^0 Q</FONT>/ ?5 c+ m- n% B( w7 h6 Z4 Z
</P>
: z1 U% s, ~, c+ }- ^3 j& @<P><FONT color=#ff0000>函数名: gettextinfo</FONT> * @3 B- R3 f! |2 q0 ~
功 能: 取得文本模式的显示信息
$ F+ k, D; z' e: W  H. }用 法: void gettextinfo(struct text_info *inforec);
" f  k  q: Q/ {1 @& R  L' o, |程序例: </P>
& ]9 S% c& C( Z9 W# i7 ]- P<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>! P& j4 t) \2 i/ ~
<P><FONT color=#0000ff>int main(void)
, j1 V* ?" Q3 U* m# U  _$ n{ % u7 `( k& {. c6 A) Z( Q: M
struct text_info ti;
" n# O  k7 Q8 [# C% r1 I/ W+ Wgettextinfo(&amp;ti);
- [8 J& R& V7 Z/ z# hcprintf("window left %2d\r\n",ti.winleft); . n7 e' O) u) T; J5 e- L9 v, {
cprintf("window top %2d\r\n",ti.wintop); & M2 p/ S) {2 _9 P2 N* e0 ]  ]
cprintf("window right %2d\r\n",ti.winright);
# E0 _# ~3 m  b) I' rcprintf("window bottom %2d\r\n",ti.winbottom);
7 s% {6 J# Y  \5 o+ V) @cprintf("attribute %2d\r\n",ti.attribute);
3 O. f/ s" i& [# ccprintf("normal attribute %2d\r\n",ti.normattr);
5 L6 R2 d# A. n- j3 q% `" E* Ncprintf("current mode %2d\r\n",ti.currmode);
- C/ f* r9 J9 f1 icprintf("screen height %2d\r\n",ti.screenheight); 8 ~+ ~4 R3 f. o( I- c: U( k3 A, r
cprintf("screen width %2d\r\n",ti.screenwidth);
4 Y- I- z: N% W- A3 a" E1 a% S: q% Ncprintf("current x %2d\r\n",ti.curx); 3 H. g' H: c+ a7 q
cprintf("current y %2d\r\n",ti.cury); % ?6 R0 n1 I& j* C' i0 ~' n
return 0; ( c0 }% n8 S; `- m
} , ?2 s# l% v) X. i5 }% U; {3 r' z
</FONT>
: Y9 r# g6 _! ~0 r</P>
% S+ D: B2 }8 |8 G3 M" C3 X<P><FONT color=#ff0000>函数名: gettextsettings </FONT>* y- L* Y) ]5 _4 J* @
功 能: 返回有关当前图形文本字体的信息 ! ?- x1 V- b. c0 v" `! n
用 法: void far gettextsettings(struct textsettingstype far *textinfo); " a% w1 ?) F- d5 z; \
程序例: </P>1 [0 l9 w+ b# ]
<P>#include <GRAPHICS.H><FONT color=#0000ff>
) J3 F# `( C" ~* R4 s#include <STDLIB.H>
* S7 x% L$ J4 e7 Y7 T. Q#include <STDIO.H>
. r+ H! u  n9 R* x8 v#include <CONIO.H></FONT></P>
0 g- R  x$ h9 [8 W/ z5 a<P><FONT color=#0000ff>/* the names of the fonts supported */ & P4 R! z9 Y& _) Y$ s! q5 G
char *font[] = { "DEFAULT_FONT", ) ?/ R2 G( h: o1 a, J; Y
"TRIPLEX_FONT",
" h% i& P# i5 i& ]"SMALL_FONT", 3 s4 Z/ B4 o* G7 c2 V: [$ w
"SANS_SERIF_FONT",
6 u* J7 n# H& l. V& T( D"GOTHIC_FONT" 2 Z! m' K0 L5 _0 p+ N4 ?* N: B5 q( p# B
}; </FONT></P>! q- c' ~5 ?" `. C% W. c
<P><FONT color=#0000ff>/* the names of the text directions supported */
# A" S, s4 h+ v+ x0 kchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>! B+ d1 Z/ K7 @  A" G% q
<P><FONT color=#0000ff>/* horizontal text justifications supported */
2 J; {: G7 j* [, ^% Dchar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
$ T0 w+ k& F/ P+ h' k- q0 I<P><FONT color=#0000ff>/* vertical text justifications supported */ ' @. N+ ^6 M) S( v
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>$ s- y. c. }/ f- Q
<P><FONT color=#0000ff>int main(void)
! b: r. h$ M+ k1 i! O% Y{ . F1 p& s' u& T; A. ]  I2 \# y  t2 d
/* request auto detection */
, |0 |! G& e, D: ?( J& |int gdriver = DETECT, gmode, errorcode;
' W: I4 [1 k1 Q' Z& o' W/ Astruct textsettingstype textinfo; 6 r; q+ F$ s! {4 M5 L
int midx, midy, ht;
! I0 q; g$ W* Qchar fontstr[80], dirstr[80], sizestr[80]; 4 Y. C9 E+ L" S) X" t# z3 V. V% i
char hjuststr[80], vjuststr[80]; </FONT></P>
  ?+ p. k5 b8 O- \9 [8 x( O<P><FONT color=#0000ff>/* initialize graphics and local variables */ - A" _3 Q+ I0 l9 x/ r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' _% p* L% H& N# T" J8 _9 W! y
<P><FONT color=#0000ff>/* read result of initialization */
6 Y/ a# f$ C( t8 C1 u5 Xerrorcode = graphresult(); 5 K; D! C4 L( Q' ?; O  _, s
if (errorcode != grOk) /* an error occurred */
( `3 Q; Q8 g$ R# {8 l: p& \8 J{
9 m; l* }+ _) y6 Eprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " E6 q9 x0 ~3 Y( \+ |
printf("Press any key to halt:");
' O; @3 y2 o2 z' lgetch(); , ]. Y" n7 Y% S8 S  J
exit(1); /* terminate with an error code */
! U( j' l& n- E. o- D6 Y. z( @} </FONT></P>$ R4 S2 g( L6 \1 B
<P><FONT color=#0000ff>midx = getmaxx() / 2; : m, o/ ^/ a2 V1 v7 x
midy = getmaxy() / 2; </FONT></P>+ T2 t) x, a4 V9 i) J! n
<P><FONT color=#0000ff>/* get information about current text settings */ * \4 S, k# T5 c& S
gettextsettings(&amp;textinfo); </FONT></P>
6 b; Z% t5 {* z3 e8 E<P><FONT color=#0000ff>/* convert text information into strings */
4 b3 Z5 y+ }% Esprintf(fontstr, "%s is the text style.", font[textinfo.font]); / d% A" F6 ?: k7 R* N: M; v
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
: h" ], X  Q% Csprintf(sizestr, "%d is the text size.", textinfo.charsize); ( ~2 r. I( u& c. [; o2 W
sprintf(hjuststr, "%s is the horizontal justification.",
$ p8 z2 }; S1 C: t. x& Nhjust[textinfo.horiz]); " X$ @( o  y0 C; S% v
sprintf(vjuststr, "%s is the vertical justification.", 3 B9 P& Z8 ~  w0 O; r4 k. J
vjust[textinfo.vert]); </FONT></P>% v2 K9 Q8 L- `
<P><FONT color=#0000ff>/* display the information */ + ]4 p& J1 P: Y
ht = textheight("W");
& \2 i3 l' S5 k1 ksettextjustify(CENTER_TEXT, CENTER_TEXT); 0 q) C3 m9 a6 P9 n% E  ?' H
outtextxy(midx, midy, fontstr);
5 v8 ?0 C! B9 x, douttextxy(midx, midy+2*ht, dirstr); & q2 p4 _+ Y. }6 m, X  A
outtextxy(midx, midy+4*ht, sizestr); , W. X! K* g" _! f3 _3 b. J
outtextxy(midx, midy+6*ht, hjuststr); 5 p& e/ t% `1 x* [
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
6 H: `: t8 h5 ?) a8 n<P><FONT color=#0000ff>/* clean up */
; q) M2 G! H2 ?6 [8 \) Z  b- n# a8 Sgetch(); 5 }# o5 y* w6 b7 U! L8 q/ b+ H
closegraph(); " }7 u$ L9 L+ N+ p' _
return 0;
$ B* `) F# ^: t2 M! n- h} </FONT>* b' _7 L% U* Z, N
</P>" x" L0 u6 p3 ]6 o( T( i7 V
<P><FONT color=#ff0000>函数名: gettime </FONT>! a+ p/ M: |5 Y$ e: r5 {8 M" W7 \
功 能: 取得系统时间 4 O4 Y0 Z( ]) \0 K
用 法: void gettime(struct time *timep);
9 P6 Z& G! B) m0 e3 ]2 k" L程序例: </P>
' Q! u% j4 F) f+ `4 k9 n<P><FONT color=#0000ff>#include <STDIO.H>
& l  T5 v; \1 X0 v#include <DOS.H></FONT></P>) V# c5 @9 k9 \3 p
<P><FONT color=#0000ff>int main(void) " S3 G( w5 ?& @4 _5 k' |' o; x% v
{ 0 E7 D- _  K1 S9 f9 o5 J
struct time t; </FONT></P>( r5 p: b) h8 ^6 Y5 D
<P><FONT color=#0000ff>gettime(&amp;t); - h4 x$ }) ]) n* D  T- E
printf("The current time is: %2d:%02d:%02d.%02d\n", 3 M* w; P0 s* K, V; y: |
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); . P& x1 z5 Z" e1 ?( L
return 0; / T  R  g% l1 T; G% }. E
} ' b' T( A4 M2 z, Z4 V
) H+ U$ ^# Z" s/ r
</FONT>
) B( W& i* Y: v. ~/ H" k$ J</P>
0 m7 ~" F8 k' Y7 G2 Q<P><FONT color=#ff0000>函数名: getvect </FONT>% l, g. Z1 Z, ^9 E5 j3 F
功 能: 取得中断向量入口
" {8 y- W( t) M6 F* q; i' U用 法: void interrupt(*getvect(int intr_num));
& y! F$ v4 E/ t) e8 U: W程序例: </P>
$ G% I- S" ~! b# z) j9 Q0 e<P><FONT color=#0000ff>#include <STDIO.H>
; {( ~, ^3 m6 {/ p. Q#include <DOS.H></FONT></P>3 w; _3 r6 J9 X4 l. V
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>- N, D- |: e+ K8 a* w  l
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ ( G# }& n" H6 ]' U2 ~
int looping = 1; </FONT></P>7 j% `, v5 g: j
<P><FONT color=#0000ff>int main(void)
! r& |6 V$ h  R3 S{
' v8 C+ V# t  i1 Mputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>+ B( c0 R0 G) _4 J1 _$ h* |( b
<P><FONT color=#0000ff>/* save the old interrupt */
5 p1 q/ x) [6 A3 ~4 W$ b  x  Roldfunc = getvect(5); </FONT></P>
0 d6 U6 x, _, Z! X) W<P><FONT color=#0000ff>/* install interrupt handler */
( Z7 R; ^, J2 x0 F; x6 isetvect(5,get_out); </FONT></P>
6 m- `% S" L' b<P><FONT color=#0000ff>/* do nothing */   X  j) L  B+ l: \- g' i
while (looping); </FONT></P>
. _0 o' l8 I7 M7 |. R: o<P><FONT color=#0000ff>/* restore to original interrupt routine */
/ }. d' h. P* w8 T) R5 lsetvect(5,oldfunc); </FONT></P>
* E& Y( N3 Y, o( v8 A7 A( H0 q* f<P><FONT color=#0000ff>puts("Success"); 5 I  t' X- b& M8 x) S; d! P, @1 E* A
return 0; $ h4 d7 S# i& m2 }
} 1 t- r: v4 Y6 e( F- P6 ]) e
void interrupt get_out()
: X9 j/ ^4 T+ e0 R1 g0 g: j{ 7 B, l1 [  }2 H, O% q* j
looping = 0; /* change global variable to get out of loop */
$ K( Y* r# a7 x. l* ~2 s} % N4 X1 b4 t! [
</FONT>/ g+ c& m! \) N: B; }2 p5 p
</P>
8 z. X/ C9 K1 U9 K3 l<P><FONT color=#ff0000>函数名: getverify </FONT>
- g# d/ {! h( n. W6 V4 Z1 _功 能: 返回DOS校验标志状态 * D4 e( F/ K( v  P# p( k8 J. t
用 法: int getverify(void);
7 l. t; z& [$ Z: F5 f程序例: </P>
/ x1 ?7 r8 o3 z<P><FONT color=#0000ff>#include <STDIO.H>; Z0 S; `" Z4 ^& Z; Z- J: j+ s
#include <DOS.H></FONT></P>" X3 p% b1 r7 _: x
<P><FONT color=#0000ff>int main(void)
( Y" t) c6 J. M{ 8 C$ b3 X6 Q, V0 _
if (getverify()) 9 R( U( Z  D! D9 ]3 W2 i4 ^0 U+ Z
printf("DOS verify flag is on\n"); 3 V1 W4 D% X8 d6 b
else 1 e" W" N7 m" [& l- G
printf("DOS verify flag is off\n");
7 h0 P/ l- Z( Z3 p; zreturn 0;
1 _4 R6 B1 Y! Z} - i. `) v' ?, g6 r* w
</FONT></P>
7 d4 Z7 ~+ w! I6 r2 j0 o: q<P><FONT color=#ff0000>函数名: getviewsetting </FONT># n* @, B/ F% o
功 能: 返回有关当前视区的信息
2 ^; l4 R* x  ?+ n4 M3 V用 法: void far getviewsettings(struct viewporttype far *viewport);
7 _- k9 O9 m8 d' {- G  ], E" k; ]! F程序例: </P>
, ?( z  C" Y0 u' i<P><FONT color=#0000ff>#include <GRAPHICS.H>. s5 J& t8 u* Z. X! E+ @- G
#include <STDLIB.H>
2 c" p, }* v. ?3 D#include <STDIO.H>5 J  X4 T2 @8 X) Y( N7 g
#include <CONIO.H></FONT></P>6 u: U* o+ @- b3 y' C
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>, Y4 b7 |1 S7 U' g7 m% c
<P><FONT color=#0000ff>int main(void)
" ?. }3 y; u1 h{ 1 n% ~( M$ g9 ?
/* request auto detection */
7 n5 x* @/ A  f* K7 B8 f0 Z$ aint gdriver = DETECT, gmode, errorcode; 0 ]; ~3 v: U$ b
struct viewporttype viewinfo; , `1 t# d2 |$ W' C$ k
int midx, midy, ht; 3 F5 O* z) @( \: ~+ c
char topstr[80], botstr[80], clipstr[80]; </FONT></P>1 q& K# v4 ~5 ~1 \2 U) N0 H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 N+ M: h1 t9 b8 A) h& ~1 G
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  J4 G8 {0 \5 C- J2 O/ e' @! q<P><FONT color=#0000ff>/* read result of initialization */ 0 @. g3 ]9 z* n' p6 E& j; e
errorcode = graphresult();
6 x) C& D" g( Q; K( zif (errorcode != grOk) /* an error occurred */ " C5 y; H) ^0 a; ~
{
0 b& `8 p8 p9 I3 g/ i) Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 r( ^6 I6 D& L" W" xprintf("Press any key to halt:"); 1 J6 H; y/ V) G. B% g
getch();
) y/ I+ k. [$ wexit(1); /* terminate with an error code */
6 f; a  ~9 d# ]7 F1 M- V% Y1 n} </FONT></P>$ S0 K2 ?. Z1 {8 ?
<P><FONT color=#0000ff>midx = getmaxx() / 2;
$ Q2 k7 u& z1 o- b1 vmidy = getmaxy() / 2; </FONT></P>
* n  U: q& F9 T( c; T) r2 d<P><FONT color=#0000ff>/* get information about current viewport */
- t0 {# @6 j$ }& B, Cgetviewsettings(&amp;viewinfo); </FONT></P>: e& V( }$ w$ P
<P><FONT color=#0000ff>/* convert text information into strings */ 0 L+ V( ^9 i( V& e* Y
sprintf(topstr, "(%d, %d) is the upper left viewport corner.", + U1 ^7 @5 S! h" @5 E
viewinfo.left, viewinfo.top); 5 W0 q( K; J5 W+ u. t
sprintf(botstr, "(%d, %d) is the lower right viewport corner.", . D  q5 z' }' S8 J0 L. P+ B4 @
viewinfo.right, viewinfo.bottom); 5 c/ K: `& L3 j7 v
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>% f7 ~8 G  b+ ~( F* z9 `
<P><FONT color=#0000ff>/* display the information */
# I) f7 Z" d+ ?  v! rsettextjustify(CENTER_TEXT, CENTER_TEXT);
6 F& J, Y9 r' l0 m; vht = textheight("W");
- a6 g8 p% {5 ^% b6 Routtextxy(midx, midy, topstr);
, R! I# {/ ?9 o+ a" {5 n: ~outtextxy(midx, midy+2*ht, botstr);
9 i8 z  d8 ~1 F. houttextxy(midx, midy+4*ht, clipstr); </FONT></P>+ u: G# N" M! V  B
<P><FONT color=#0000ff>/* clean up */ $ C7 b1 d7 T" M& \7 o
getch(); . }  {, Q1 ~3 _3 i
closegraph(); 7 Z" F# G2 q4 [" o1 i! t% _
return 0;
) i# ^+ O  c  B% X; \! `} </FONT>
4 v6 A9 |! h. A+ @. W
4 ?8 w; @+ B: j# G; O) f</P>
; d2 _% X  }) F9 W& v0 E* K<P><FONT color=#ff0000>函数名: getw </FONT>' _0 V0 Y% _" w: t# ?9 v, j3 Z
功 能: 从流中取一整数 6 r) J8 u- B. _' u- A  |8 {2 u
用 法: int getw(FILE *strem); * @- f% k8 \6 G# v' j3 u
程序例: </P>
3 F/ z. z/ X4 p% Y/ R0 z<P><FONT color=#0000ff>#include <STDIO.H>- V* n# S- y+ I
#include <STDLIB.H></FONT></P>0 S( D2 L3 J  y- d
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>1 h4 |. Z+ A7 `# z/ s8 D; O
<P><FONT color=#0000ff>int main(void) ) u9 m, e- M/ T5 ]) }8 k3 |* w2 q9 b
{
/ L% Y/ w2 V- E- a  f4 M' xFILE *fp;
) i+ m2 k* c6 N* Q$ e5 L1 Lint word; </FONT></P>1 u5 P# Y9 Z7 |" H6 s: T' e
<P><FONT color=#0000ff>/* place the word in a file */
. q! K5 s" b' Y6 z, `- C3 c  Xfp = fopen(FNAME, "wb");
6 J, J( \, C  ?" N+ jif (fp == NULL) 9 n% S- I1 Q" c
{ 3 y0 q- ~% U1 B) I- {  r
printf("Error opening file %s\n", FNAME);
  }$ t% f, v9 s- i  Uexit(1);
8 M% G' i2 ]  p& g) s$ ]# s& P} </FONT></P>
- Z4 w1 J+ i3 k' W4 u<P><FONT color=#0000ff>word = 94;
1 w5 x8 C8 l3 p% S- jputw(word,fp); 1 c  ~( ]. ~0 i: ]2 `& o
if (ferror(fp))
# p  H* \" I' F( I  o/ C# p+ I. Bprintf("Error writing to file\n");
% H1 B- |0 x1 T( ^  Oelse
# n. o' J. x; bprintf("Successful write\n"); 4 w! Z0 M' H/ D2 T
fclose(fp); </FONT></P>. T$ @: L/ q3 X0 `2 |; \
<P><FONT color=#0000ff>/* reopen the file */ 5 J8 t5 N! m; ^9 a1 T, Q4 [2 Z
fp = fopen(FNAME, "rb");
; u) C/ c3 J% C6 ]if (fp == NULL)
2 y8 O, I5 ?+ {{
" e0 J, Q1 v) j! n! Yprintf("Error opening file %s\n", FNAME); - h' @- n+ }8 w+ W( d
exit(1);
2 r) T3 @7 o3 L3 z2 U} </FONT></P>
$ ?: r9 _" Z9 q+ ~% U+ C( h! O, j<P><FONT color=#0000ff>/* extract the word */
+ W$ L% U8 A0 m! W: A# b; z: @* fword = getw(fp); ' {' C$ `, }4 J8 D) v9 [
if (ferror(fp))
# i; K1 Y( z; M$ h/ f2 ?printf("Error reading file\n"); # [3 d( c( o) W. U  [8 \
else
3 l) A3 Q6 H# C9 i, gprintf("Successful read: word = %d\n", word); </FONT></P>' g% F' z' a6 i. Y2 H1 N
<P><FONT color=#0000ff>/* clean up */
7 Z( V9 D- q" M' q/ {9 Efclose(fp); 6 @$ \7 X& @+ O
unlink(FNAME); </FONT></P>
  J$ p4 c( d' y  G% L7 ~<P><FONT color=#0000ff>return 0; 6 z" S3 S+ R0 A% C! g. T" x- f
} </FONT>- U# w) ]7 w; o% _
5 \& h) M2 T3 y* a, H

7 L$ [0 ~0 O9 L$ S6 I+ e</P>
2 }3 @9 U+ y- {/ x! A; `<P><FONT color=#ff0000>函数名: getx </FONT>8 j& l1 d2 l) ], n! i6 n! v
功 能: 返回当前图形位置的x坐标
/ @% b. N, _4 K0 t5 h9 ?用 法: int far getx(void);
: V0 c& y6 [# p# I程序例: </P>
4 U6 K3 e& l9 d' A<P>#include <GRAPHICS.H><FONT color=#0000ff>9 e& a* c0 H9 m) Z( V. N/ |
#include <STDLIB.H>: Z# s1 U# z. @! h4 m9 C
#include <STDIO.H>* ]/ _5 t1 o, V. o$ A, c7 C. C( _' b
#include <CONIO.H></FONT></P>+ R# C# y- D" Q7 b1 G* k
<P><FONT color=#0000ff>int main(void) * j$ T, @9 W8 c$ l% ]1 Z0 w9 r
{ 6 T" f8 \6 x- S* Y  m9 y/ |
/* request auto detection */
" d3 A& }6 a* T7 s  i9 qint gdriver = DETECT, gmode, errorcode; . R' t4 C$ l9 @9 Z" P# x
char msg[80]; </FONT></P>
( W5 H0 ?1 v) B# Z8 T4 v  f: z<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ r  K% {/ |) o2 ^initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
& R7 ]8 _/ S/ _+ e, {$ P* e7 p<P><FONT color=#0000ff>/* read result of initialization */
7 c5 G4 G: j) C6 ]6 xerrorcode = graphresult(); 4 ~+ q; `' w2 U. p* ]
if (errorcode != grOk) /* an error occurred */
5 }1 j0 W) ~) k: p; \+ |{ $ D$ ~: z2 G6 O& k
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # ?7 I% Z7 X: H, _3 X% B( r) a4 g) a
printf("Press any key to halt:");
5 w9 S% F7 U2 t/ @. Z* xgetch();
; l  C& N: p& [8 R! v4 W# z0 uexit(1); /* terminate with an error code */
+ C0 x$ q# W" }% @7 M' \1 l} </FONT></P>
; C! T0 N" ?' N8 K: E2 Z<P><FONT color=#0000ff>/* move to the screen center point */
0 X) S: M) f4 E2 X% H8 Qmoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>4 `0 [3 `, M: ?; {
<P><FONT color=#0000ff>/* create a message string */
2 ]3 m' ?8 d: l0 P3 A1 T0 l! Hsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>8 m" g- f) W* @- |  }; |5 W
<P><FONT color=#0000ff>/* display the message */
8 Y3 U. o$ C1 ^, t/ Louttext(msg); </FONT></P>
- q" l& Y9 R0 ~1 u2 h6 ~/ \<P><FONT color=#0000ff>/* clean up */
8 y9 H: d: G3 c$ y6 B/ ~getch();
/ `& j4 |# R  d$ _closegraph();
# Y- E2 r3 n: I( q' G; C; q1 @' hreturn 0; " w7 D( v9 ~/ @, [
} </FONT>( p* _+ L+ {9 |
& s7 @8 @5 U: x
</P>
  @* X+ T6 `+ X# I) W<P><FONT color=#ff0000>函数名: gety </FONT>4 w% l( J" |$ D5 t& U: n$ {
功 能: 返回当前图形位置的y坐标 , C& P/ q' l8 ^  t7 G! s, [
用 法: int far gety(void); 7 l& ]: }$ y* u+ @6 d
程序例: </P>
7 I9 a( [$ q& A3 [  w. D<P><FONT color=#0000ff>#include <GRAPHICS.H>0 q; V) K* w* w( N* ^
#include <STDLIB.H>1 {2 ]' N, ?. `  L7 m
#include <STDIO.H>0 g& S6 ?6 D( a8 Y- l
#include <CONIO.H></FONT></P>
1 i% g$ I: f9 H6 R3 E9 n3 E( k<P><FONT color=#0000ff>int main(void) / D' {: P  F) I! T
{
" f; F! m4 ~. B" N* b/* request auto detection */ ; B, y+ N( Q: ?$ t# b
int gdriver = DETECT, gmode, errorcode;
+ |+ A, z2 b5 P6 T6 vchar msg[80]; </FONT></P>
4 b5 [& V; j- I  _) E<P><FONT color=#0000ff>/* initialize graphics and local variables */ " Q3 W' E5 l0 F7 P, s
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ W1 }- Z! X0 z5 n<P><FONT color=#0000ff>/* read result of initialization */
% n6 [/ v# z* [; _errorcode = graphresult();
$ {! i6 I7 T- m8 I8 kif (errorcode != grOk) /* an error occurred */ 1 X. c" i% r& x5 V  r
{
  K: P9 x8 j& Q9 `9 D# {printf("Graphics error: %s\n", grapherrormsg(errorcode));   x" ~+ W* r0 ?. u
printf("Press any key to halt:");
6 w' u2 E. ~" m6 ngetch();
9 G1 U  }3 K. e& n; _( E# I% yexit(1); /* terminate with an error code */
1 L. L+ b' U/ k) _: [} </FONT></P>4 D* e5 }/ J% k8 ?# l( s
<P><FONT color=#0000ff>/* move to the screen center point */   x9 P/ u0 Z! d: {3 t, \+ P
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>' A, v" E2 a& w% X
<P><FONT color=#0000ff>/* create a message string */ " _0 s7 |' o* g0 }
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
8 b8 s: E5 ?2 i; ]: j4 ?  `/ ~, Y<P><FONT color=#0000ff>/* display the message */ " ?; Q3 y3 C; z. H7 U" |5 _, Z
outtext(msg); </FONT></P>
, X) g( u# U8 m0 m+ w4 C  T4 Q<P><FONT color=#0000ff>/* clean up */
2 X7 Q4 O$ n4 _6 |3 V/ B: [  e2 p7 hgetch();
) _" w+ K3 \. o0 p* w( Q$ Q7 Eclosegraph(); ) s1 \9 _4 ]1 D' @$ i! l9 P) _
return 0;
( a' W8 \/ r! l: E9 o} </FONT>, d. s6 h/ n* @7 U$ F

- Y3 W  n2 X8 g- L! F. `) t</P>
* q  \4 t6 W% S<P><FONT color=#ff0000>函数名: gmtime </FONT>
7 u4 e  L+ I0 o" K: o; t功 能: 把日期和时间转换为格林尼治标准时间(GMT) & c! i3 r4 f2 g2 J/ A
用 法: struct tm *gmtime(long *clock);
7 o& x9 q: B$ N  h4 X' ~程序例: </P>
, ]5 X) v9 \3 i7 [<P>#include <STDIO.H><FONT color=#0000ff>( }. Q6 l8 t. F4 F: E( z1 g8 X/ a
#include <STDLIB.H>
8 q% ~$ V4 e% }3 u" r1 _# `#include <TIME.H>
% ^8 S9 X. F) t2 C0 H, y#include <DOS.H></FONT></P>/ @8 U: K! c4 m% [; ~
<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
: z- Q/ f4 w1 ?! \; Hchar *tzstr = "TZ=PST8PDT"; </FONT></P>" k/ {% p* u' w. H* Q$ D1 N4 k  y* S
<P><FONT color=#0000ff>int main(void) # M- Y8 T7 d% U+ W
{
4 S+ I- r7 S  l+ |0 \time_t t; 9 C* t  r1 j+ u3 `5 W( e- Z
struct tm *gmt, *area; </FONT></P>
- a' Z- z9 l/ p% ^0 p4 j% p9 p<P><FONT color=#0000ff>putenv(tzstr); " k7 J- {' Y2 D( u. Y" p8 V1 c7 w! Q
tzset(); </FONT></P>0 C3 u8 J4 p" ^3 v7 x3 d1 Y2 I- c% {
<P><FONT color=#0000ff>t = time(NULL);
! ^% H' F3 D  t% C0 varea = localtime(&amp;t); * w. _3 S$ b9 A5 a
printf("Local time is: %s", asctime(area)); $ h$ a3 M! ^  }1 D
gmt = gmtime(&amp;t);
5 l% S) R3 Z- {3 s! R( Wprintf("GMT is: %s", asctime(gmt));
8 D. n$ @" d: }$ i& Freturn 0;
' p3 O: r1 F8 s8 M* h. ~6 d& z} </FONT>
4 x! W$ e' _# I, G* P+ K- Z; H: N; s7 I
</P>
( \( O6 L8 X6 k7 p: A5 C5 w' [<P><FONT color=#ff0000>函数名: gotoxy </FONT>$ B% C+ a. e  f7 i: M6 B0 X, P
功 能: 在文本窗口中设置光标 0 l* u$ m# g* n
用 法: void gotoxy(int x, int y);
0 n9 A% @  O/ o: H程序例: </P>& s2 q. s# o, e
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
2 i+ J# _# F4 I  G8 r& O* M: J<P><FONT color=#0000ff>int main(void)
0 X, N  Y+ ~* O' Q! Y{
( W' K/ C0 J( W3 |5 n9 n  @6 iclrscr();
: T; {% `7 u+ J8 L. S8 egotoxy(35, 12); 9 v$ p2 K( y' m$ o; `# `! v
cprintf("Hello world");
2 n  V) T$ j3 G$ e% Q6 p& k- x, E4 _getch();
/ h* }' ]; j% [return 0;
& R! T, f- _0 Q% w+ ]}</FONT> & j1 R0 e! a6 J" U
2 z8 K& ]! U: P" A6 T
</P>3 I7 |2 x' n$ ]: k- Y9 H7 X! r
<P><FONT color=#ff0000>函数名: gotoxy </FONT>
. y4 S2 _* n% A7 V+ h8 v功 能: 在文本窗口中设置光标
: K, h: M/ _8 y# g1 s用 法: void gotoxy(int x, int y); : S& y, P1 C# |7 N* }. Y" U5 s. k
程序例: </P>! @7 I  ]5 g9 P6 J* x
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
0 s9 F: e! Z& N<P><FONT color=#0000ff>int main(void) & j/ l& d4 Z5 [9 Q: I3 W' T7 U
{
5 I3 R5 o+ J! O/ u  [  tclrscr();
' R8 S/ {) l5 e8 @gotoxy(35, 12);
) ?8 x7 x+ ^& W3 M$ @cprintf("Hello world");
. ^: W2 u9 K- b- \0 Xgetch(); ! ~  h5 ^4 f0 M' V  l" Q+ ~3 v6 o
return 0; - ^; y7 J+ ^) m
} " o' @# N) {5 l+ J5 D
</FONT>
$ Z& b8 j2 m( T# n0 \/ a/ x</P>
# {3 {9 e6 E! N<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
) L" E* K' M9 n' [5 X功 能: 将所有图形设置复位为它们的缺省值
# h9 c% S: {6 N/ {) _用 法: void far graphdefaults(void);
8 ~/ u7 D- v/ L" c5 z程序例: </P>
6 f* P& V9 u) `! c<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 ]2 u: i- e. v5 ?' ~# S#include <STDLIB.H>: ?- _. @3 z: [. r" z
#include <STDIO.H>
, p" h  p- r& c8 @6 x! E+ s- c! J#include <CONIO.H></FONT></P>
' q' _" C6 K; Y1 b, f+ n4 e<P><FONT color=#0000ff>int main(void) 3 w' g. p$ q( V' N- `
{
7 G" P% ?+ w, A0 l/ C/ R/* request auto detection */ ( `7 F0 }" E- `1 E0 v$ B
int gdriver = DETECT, gmode, errorcode; 0 I# s2 x- U( \
int maxx, maxy; </FONT></P>
6 V' ^; Y# h7 n0 G<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 N/ ?) X8 m  t; k4 hinitgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
! x: ~$ w9 l" K! ]" P0 t0 Y<P><FONT color=#0000ff>/* read result of initialization */ 9 G- ]9 W1 w7 n0 Z2 P
errorcode = graphresult();
+ U7 G, `9 y& u/ B3 S9 gif (errorcode != grOk) /* an error occurred */
* p: P5 |( B5 a$ |{ ! N; L& x1 w0 i* N
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ Z, ^$ @2 {0 B* n' {- lprintf("Press any key to halt:"); * F, H* l- b# V; |
getch();
0 z. f0 r2 _0 ]4 xexit(1); /* terminate with an error code */ ' t) h3 i+ V1 ?* W6 }- q
} </FONT></P>3 H. g' t9 ^' l/ w
<P><FONT color=#0000ff>maxx = getmaxx();
6 D1 |* G1 P+ C3 U6 X7 Ymaxy = getmaxy(); </FONT></P>
- _0 j7 R" o0 E) L<P><FONT color=#0000ff>/* output line with non-default settings */
1 i3 @! x1 q5 p" \" I2 E  Isetlinestyle(DOTTED_LINE, 0, 3); 3 m5 q; B; \' P2 F  j
line(0, 0, maxx, maxy);
1 y* m, }2 g0 }5 R; N, v; K7 N& oouttextxy(maxx/2, maxy/3, "Before default values are restored."); / M/ {6 ]. B* f$ o( f
getch(); </FONT></P>
1 c" u: _* Q; _9 v  Z6 w<P><FONT color=#0000ff>/* restore default values for everything */
' I: F/ J1 K0 o9 d; @5 b! @# }graphdefaults(); </FONT></P>% t4 Z6 f8 I) F, c
<P><FONT color=#0000ff>/* clear the screen */
$ u. k- {7 I: }1 x8 b; x: A  N# a: Gcleardevice(); </FONT></P>4 R$ u" w& A9 s- X: u
<P><FONT color=#0000ff>/* output line with default settings */ % b( n1 E7 p) m
line(0, 0, maxx, maxy);
2 f5 V0 p8 R" w) u0 fouttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>, O5 n1 r( \! z2 C! N9 |3 _2 n" }
<P><FONT color=#0000ff>/* clean up */
, \! K/ F% |; @) S* {getch();
2 z0 W6 s1 }* |" c0 ^closegraph();
8 h& b0 b! A2 ]+ {return 0;
  W6 F3 `$ M5 F8 J} 7 H6 |! m1 b% ?$ c: x
</FONT>
, v) _; M' }7 Z2 ~! e</P>* d( W4 d* L% o
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>
/ c: q* i; D) s: @功 能: 返回一个错误信息串的指针
2 x5 ?* u. p7 d" J1 d1 {用 法: char *far grapherrormsg(int errorcode); ) p9 W" Z6 K1 d8 |
程序例: </P>2 P% y% ]! U, n9 j* E& L2 W$ d
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: ]6 [0 T# W% T' B#include <STDLIB.H>+ M/ A. |+ K# v
#include <STDIO.H>; v6 Y: c& {2 W+ h; W  L
#include <CONIO.H></FONT></P>, B- V% E! m( ^
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>, c- V$ M9 P2 ?7 w3 w
<P><FONT color=#0000ff>int main(void) 1 ~) W' |8 u8 {' e5 M
{ : \( _  v: R0 B/ [, R6 a
/* FORCE AN ERROR TO OCCUR */ + a) m0 m! d  }7 ?6 J  U
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>
; s! P: V7 d% s1 M<P><FONT color=#0000ff>/* initialize graphics mode */
& f% H& I. c8 s- t& ^initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 `# s/ f/ \1 y% V5 i
<P><FONT color=#0000ff>/* read result of initialization */ * t+ O& C4 J' }: s3 T2 v' o
errorcode = graphresult(); </FONT></P>
4 E- {7 @5 g0 ]6 F- J  w, z# |<P><FONT color=#0000ff>/* if an error occurred, then output a */ ) B8 n& A  O! ]- \4 _* D
/* descriptive error message. */ ' A4 q: m- D! N) L
if (errorcode != grOk)
8 v4 v" a- T8 I3 s; `, D# C{
' U- u& K% h# g, j; Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 d! s* c9 O% |% H
printf("Press any key to halt:");
6 D0 {- C- L: Xgetch();
$ N) A7 F  [% q; E& w& hexit(1); /* terminate with an error code */ : D9 u! [8 ~* u" H9 G) z3 ?
} </FONT></P>( i, B6 K6 I3 }# P5 J1 e' a
<P><FONT color=#0000ff>/* draw a line */
  l- S% h, U: |line(0, 0, getmaxx(), getmaxy()); </FONT></P>
+ ]3 B; y) H1 @/ e1 W0 O' z<P><FONT color=#0000ff>/* clean up */
. K4 d* e! Y# G9 P4 V* b# E- ggetch();
2 i5 n; J. F  b( f9 u" M: qclosegraph();
- ~( t/ `0 Z  {( \9 mreturn 0;   y  i8 h8 v3 r) O+ z3 i  }
}
& Q! |4 w1 Z) V/ S' j" B: k2 X( r2 W& P8 s</FONT>% ^- `$ v( j/ L/ G1 ~  R
</P>
: A1 Y( B; \5 D: ?0 ~6 p<P><FONT color=#ff0000>函数名: graphresult </FONT>: n5 h5 \& R  q. C% C" X; j0 }  V% a$ \- b
功 能: 返回最后一次不成功的图形操作的错误代码
1 r2 v5 Q; q; F" z$ _; F7 v& I, [用 法: int far graphresult(void);
5 J" r& h8 f; a0 `% \9 Z1 Q6 z& r程序例: </P>
3 }$ u- Z7 S1 G6 y# B<P><FONT color=#0000ff>#include <GRAPHICS.H>. ?. O7 X( z" c' N( R$ p$ i
#include <STDLIB.H>
8 a6 ]$ q& Z- _3 m7 k#include <STDIO.H>/ Z$ n( }# W3 ?9 K. t! k# ]
#include <CONIO.H></FONT></P>2 M6 v/ E  h; x' L( V1 h& @
<P><FONT color=#0000ff>int main(void) " [* o1 v  f" G( `- l3 D3 a3 R# ]5 [9 }
{
/ \+ @' |4 B5 i+ X+ m/* request auto detection */
- j& f5 T' g2 v) Q2 W, O( Zint gdriver = DETECT, gmode, errorcode; </FONT></P>' j2 g, c9 n. u. C4 o/ |% x
<P><FONT color=#0000ff>/* initialize graphics and local variables */   X( q. }$ |# M5 M, F) t
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; _. a: V" s+ q2 z' |$ V4 t% m
<P><FONT color=#0000ff>/* read result of initialization */
" b" \7 S1 k1 Q7 }9 ^- i5 |8 xerrorcode = graphresult(); </FONT></P>
/ ^/ `& L: I4 r) |<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
! D4 b$ F& K: n{
4 q- @4 G/ a8 q' c* Aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" `) ~) ?& q6 Hprintf("Press any key to halt:");   |, r4 h3 W6 v( w4 J' \3 L( z/ `7 O9 p
getch(); / [) z4 p( q$ m, B+ }1 B4 u" A
exit(1); /* terminate with an error code */
7 \, C7 x2 N& F} </FONT></P>& ~0 o* j* C/ N2 }2 ^% ?
<P><FONT color=#0000ff>/* draw a line */
) ]: g- J$ p7 j- ~- xline(0, 0, getmaxx(), getmaxy()); </FONT></P>9 I+ g$ u1 e# O1 C( @& a6 _# v
<P><FONT color=#0000ff>/* clean up */
% J1 d% Y! G* u* egetch();
+ _, M2 \! b1 Pclosegraph();
/ f5 O" K9 p. g# breturn 0; ' q' i8 Y3 E& x; x
}</FONT>
' m8 w  n$ g3 u1 W3 S0 N( n, m3 y</P>2 Z+ |$ F1 ?4 c# p" e
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> / A; l' c. j: c1 o
功 能: 用户可修改的图形存储区释放函数 3 o$ e, J4 k" G( u, M
用 法: void far _graphfreemem(void far *ptr, unsigned size);
% a! a, T& F' ]" _程序例: </P>/ [6 `  o5 t3 j- N
<P><FONT color=#0000ff>#include <GRAPHICS.H>/ g, K7 S0 l! v: k0 |
#include <STDLIB.H>9 t, S: s% `, C4 a
#include <STDIO.H># d" o6 m$ n' Z5 N& l" e2 q
#include <CONIO.H>& m! U3 c% @' g1 ?" G' n
#include <ALLOC.H></FONT></P>
/ k0 D2 A1 \9 {<P><FONT color=#0000ff>int main(void) " g! z3 e; Z/ T0 t( I1 K1 A3 n
{
- x5 m( G7 s% ~- Z( r7 N/* request auto detection */
: ]2 l( h8 w& S" o7 Z: tint gdriver = DETECT, gmode, errorcode;
1 _- U8 ]6 l$ y  n% o$ `8 G" Zint midx, midy; </FONT></P>0 F% M! I  e/ A  p9 ~; [7 B
<P><FONT color=#0000ff>/* clear the text screen */ ! D3 t7 T; Y8 q' B" H: H
clrscr();
; F( m2 l. R" ~, L6 xprintf("Press any key to initialize graphics mode:"); # r. Q6 F* L: Y& _
getch();
; I$ ~5 r1 X$ i& c5 T* iclrscr(); </FONT></P>
5 T7 l" E3 I& J$ @& a5 g: r  F<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; `' ?1 v- I7 R6 ?, A6 K, X
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! H' }+ b6 F# d7 m7 f5 }<P><FONT color=#0000ff>/* read result of initialization */
  s4 R& h1 ~1 u' eerrorcode = graphresult();
8 L2 Q. m& S& N# s; x1 ?if (errorcode != grOk) /* an error occurred */ 5 j2 `* O# h/ ^% T) [6 |" I
{ " f( g$ o5 B6 c
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 }0 ^0 `. E- _; ]! k' Eprintf("Press any key to halt:"); 5 C  K' Q$ S! e; R
getch();
: h- H9 @* ^; ]& u  Z% e; G2 x  V- Hexit(1); /* terminate with an error code */
6 w1 O9 ]/ I# t2 p} </FONT></P>  g+ T$ ]) W/ O4 W4 P0 Y/ T
<P><FONT color=#0000ff>midx = getmaxx() / 2; & R& n/ c8 J% ]1 a8 `$ Z( K
midy = getmaxy() / 2; </FONT></P>
4 @  [& }9 K1 G2 W, E<P><FONT color=#0000ff>/* display a message */
3 k: |+ C2 A8 g  o. Msettextjustify(CENTER_TEXT, CENTER_TEXT);
$ T, V, q7 a4 Y" ^7 Iouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>! O- m8 h& S+ p3 K5 k  i
<P><FONT color=#0000ff>/* clean up */
% z' x) z! ^8 k9 Dgetch(); % J; k. v+ _5 c1 ]) V+ X
closegraph(); 6 N5 j0 M/ B5 q; v3 B. N% m
return 0;
6 r7 W" o- a3 j7 x; m0 u} </FONT></P>
8 U  t: m' S/ Q4 o* e6 V<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ 9 a1 c& P  _. o! F" d/ w8 U
void far * far _graphgetmem(unsigned size) 3 ?% T4 d; ]4 y6 I9 |( b" w3 O8 h+ j
{
+ K5 {& H! A1 bprintf("_graphgetmem called to allocate %d bytes.\n", size);
+ W3 x0 c0 A1 H; r. o' ~( G; tprintf("hit any key:"); # H! u# I5 Q  O7 c; b# y: T
getch(); - a: W- k. y6 g# `* I
printf("\n"); </FONT></P>
6 M% `; D2 H6 _<P><FONT color=#0000ff>/* allocate memory from far heap */ 4 g9 S8 S' d% [* D& O
return farmalloc(size); . c* k6 [6 K8 J( D5 H
} </FONT></P>( w1 q* j+ x5 X3 Q5 P# D/ Z
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ " _, y$ z/ L" d) v
void far _graphfreemem(void far *ptr, unsigned size) + i& ~+ @2 b$ l# s1 R: c
{ & L6 z: d2 @% i7 q2 y9 T
printf("_graphfreemem called to free %d bytes.\n", size);
3 l2 K' J1 g% z( qprintf("hit any key:");
: ?2 Q' r0 t) Egetch();
4 l4 l, _6 H% G- [printf("\n"); </FONT></P>' s! Y5 Q) N; G% A1 Z; n
<P><FONT color=#0000ff>/* free ptr from far heap */ 3 b( `- W, \, U* M# B. s1 w4 ], u8 j6 b
farfree(ptr);
( T6 Y& V7 L) v3 W}
" z9 S2 P/ J% M: m) V" o</FONT></P>' J, f! |7 Y% w7 |
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>
/ n) V- L) \% ~* q& A* B+ P功 能: 用户可修改的图形存储区分配函数
2 K' `  ~1 G8 O5 T+ r用 法: void far *far _graphgetmem(unsigned size);
3 d' |8 I6 W3 h  |程序例: </P>; y% r6 Z9 w, H
<P><FONT color=#0000ff>#include <GRAPHICS.H>* ^9 L; f$ ?# s) L
#include <STDLIB.H>
$ k5 O. O) F# i' x4 y* b( _$ {#include <STDIO.H>
3 b) r; M( g9 p  L/ G, Q# X: u, N& U) z#include <CONIO.H>
$ R1 x7 R3 r3 s) w, N# M#include <ALLOC.H></FONT></P>
+ G- p% T, ~$ o& I3 f<P><FONT color=#0000ff>int main(void) 6 x& i0 x: g* l
{ 5 U' Y- a- v; N
/* request autodetection */
( e0 N: t1 z% s+ @% P8 Cint gdriver = DETECT, gmode, errorcode;
6 I5 L0 `4 r; s6 jint midx, midy; </FONT></P>
1 @3 U5 o# N- z' [<P><FONT color=#0000ff>/* clear the text screen */ 5 Q% f+ E. T4 ]$ D
clrscr();
& l1 G3 _7 L8 b  R" q& l: r+ Mprintf("Press any key to initialize graphics mode:");
5 _) }6 H* ]& O& w. B, L3 Fgetch();
5 z; G' B, ], Fclrscr(); </FONT></P>& W! @% S' ~8 |% ?% v: G# W
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, u9 S+ S( [, w+ Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 w. T8 z# s" b<P><FONT color=#0000ff>/* read result of initialization */
! B# D6 P5 Q# d$ E/ U& Rerrorcode = graphresult();
  o) `+ V$ I4 N4 ^1 F; Dif (errorcode != grOk) /* an error occurred */
( B/ T2 h# s9 H  c' |" k4 q' t{
6 d  j' L( S: Z) Aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
) h- }7 V/ S" T0 O* K- f) Z3 D, b* {printf("Press any key to halt:");
/ c5 u1 i5 W- G# Lgetch(); * t& o. y6 D9 `: n5 @+ R; d! l
exit(1); /* terminate with an error code */ , p8 Z2 b  ~7 \7 d; j( v% A, R
} </FONT></P>
7 ^' X7 W0 V. W7 y& Y: ^; J/ C<P><FONT color=#0000ff>midx = getmaxx() / 2;
' Q0 G# g& A2 x6 m& a0 Mmidy = getmaxy() / 2; </FONT></P>" T. v/ ^0 O/ J& Y3 M1 W* B; u/ R
<P><FONT color=#0000ff>/* display a message */
$ B6 j+ f. v4 @/ b3 asettextjustify(CENTER_TEXT, CENTER_TEXT); " r6 T3 k# Z4 v$ @
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
- @3 f- N' m% O2 D0 r6 D3 a* L<P><FONT color=#0000ff>/* clean up */
9 N* c$ K- w) g7 f2 i" tgetch(); & R2 }  H& l6 W3 h
closegraph(); . }# {$ w; `; z# n
return 0;
3 l' F3 l7 }0 [$ o  g} </FONT></P>9 d$ j$ W0 U" [
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
, K8 y1 S# W# q% bvoid far * far _graphgetmem(unsigned size)
. k6 `7 j; N' D# O# w{
0 V0 Z: e( q1 v9 I4 m7 Cprintf("_graphgetmem called to allocate %d bytes.\n", size);
$ U' u. g/ q- t( D0 s- b1 m# A. tprintf("hit any key:");
5 S9 g& E3 F+ l7 }& Y4 Zgetch();
9 f* a' |" w- ?( I" k& j! Pprintf("\n"); </FONT></P>
  Q! g! U2 E+ v) K<P><FONT color=#0000ff>/* allocate memory from far heap */ # }& A  _* W6 _( a) H
return farmalloc(size); $ Q3 [" n* o, m5 _" y8 ]
} </FONT></P>
+ ~) r& |- @! U# P6 C<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
4 X; R. @, X/ S$ tvoid far _graphfreemem(void far *ptr, unsigned size) ; b  A0 `/ P6 U. i
{
; J" j8 w) f9 O* l" M) P/ gprintf("_graphfreemem called to free %d bytes.\n", size);
8 u: f1 q. V1 I6 Y- E) r) Bprintf("hit any key:");
- X: [* W* k# Q% Ugetch();
+ l+ j' l8 u* ?* _! X" }printf("\n"); </FONT></P>* f6 B2 a- @  f' W1 X7 C9 l: g
<P><FONT color=#0000ff>/* free ptr from far heap */
$ k; ~0 S1 q4 f$ Z) C1 @- U+ Kfarfree(ptr);
& n1 q) b6 _8 {2 Q4 X}
: q6 d8 \2 ~7 p4 n, t0 F</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-20 09:56 , Processed in 0.673766 second(s), 52 queries .

回顶部