QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2562|回复: 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>
0 o1 C0 O( M5 G1 D( e
3 B! }' f! B) R' V* w5 l- y
  h- a- s; E- J  S% T; C# s<p>
# b. l9 p9 r; Y0 N" t* B<><FONT color=#ff0000>函数名: gcvt </FONT>  [! E: b: T9 C
功 能: 把浮点数转换成字符串 6 d7 S7 C, R( i8 T
用 法: char *gcvt(double value, int ndigit, char *buf);
! p, E* _% V# x4 v7 ~6 T程序例: </P>
% e+ A( j# ^! f2 A<><FONT color=#0000ff>#include <STDLIB.H>
/ C7 C. L4 q$ `3 b4 F# @( Q% `8 v#include <STDIO.H></FONT></P>
$ \& b3 A, |* z# S3 e+ d* A<><FONT color=#0000ff>int main(void)
- u) }2 _5 {1 b/ U{
& e% D; q4 }; ^char str[25];
! G; A8 o# ]/ C- a3 E, ddouble num;
* \! q" V$ Z$ z# {int sig = 5; /* significant digits */ </FONT></P>
  m  K0 a: g. {" z% X<><FONT color=#0000ff>/* a regular number */
7 m: k- Z% f  `, m: q% C. R# pnum = 9.876; ( Y: Q3 m$ w$ k
gcvt(num, sig, str); ( |$ s/ J0 j- Q+ c+ T% p
printf("string = %s\n", str); </FONT></P>
! F4 [, a$ T+ b! C: x! E! X( p<><FONT color=#0000ff>/* a negative number */
/ |, I: x4 q8 Z8 c3 d6 \; Xnum = -123.4567;
' K$ h& V% I) Q% }4 U# W! \gcvt(num, sig, str); : ]' ?( f' P2 I; J' |
printf("string = %s\n", str); </FONT></P>0 J% b, @) O. G8 B2 I) _5 ~) ]
<><FONT color=#0000ff>/* scientific notation */
; G; w" F) m5 O0 ~& D5 hnum = 0.678e5; 4 l' b, d+ G( [
gcvt(num, sig, str); / h" d5 K2 [- h3 I9 a6 p
printf("string = %s\n", str); </FONT></P>
3 ~1 z$ B! U. H5 ?/ L' ]- h7 ^<><FONT color=#0000ff>return(0); . n9 Y3 A; S7 q: D* l: Y
}
# A7 h% f$ N$ z; r' |# x
+ @7 R+ K6 M1 l9 d; @' I- n$ p</FONT>6 f) y; z/ q# [' }4 i" h6 y8 D
</P>
) k; R! ^# [( @$ e$ L9 z<><FONT color=#ff0000>函数名: geninterrupt </FONT>
3 R! h1 S# g8 ]7 U3 R# D, @* w功 能: 产生一个软中断
- S$ I3 R/ D! f6 h4 q  Q; h/ Z- |用 法: void geninterrupt(int intr_num);
. ^' F& `4 _: u/ @: u程序例: </P>/ B! C% O4 c4 [/ @# n
<><FONT color=#0000ff>#include <CONIO.H>
% L3 p) b1 X* @9 B1 t% ]#include <DOS.H></FONT></P>: {' m# ]- w' k/ N
<><FONT color=#0000ff>/* function prototype */
1 d' t, v6 y; R5 w. e1 Evoid writechar(char ch); </FONT></P>, q: _) g( _7 }7 e
<><FONT color=#0000ff>int main(void) + p$ O$ |! p3 ^1 |) M
{
: c) g: w# U/ aclrscr(); # c5 a& `+ g8 Q$ {' U4 R
gotoxy(80,25); ( V2 F7 Q/ P) u) d( Y
writechar('*');   S0 o8 B' h( W4 D  H" K9 k8 b
getch(); % \& N0 B. t- p
return 0;
- ~; Z5 d* X% h7 P} </FONT></P>0 ^5 p/ S9 T, {4 v- C  F0 p0 u' a
<><FONT color=#0000ff>/* 3 K  y0 }/ @7 {$ }7 y$ J
outputs a character at the current cursor
# _) ]$ \( B1 _position using the video BIOS to avoid the
5 r, ]) y% a" p' Z' x( Fscrolling of the screen when writing to 3 E+ T6 m, K/ e, `3 K' p
location (80,25).
& R9 v3 g' o( q0 O3 h6 s/ J*/ </FONT></P>( o2 s$ \1 m) a
<><FONT color=#0000ff>void writechar(char ch) % r+ u9 O! P) O2 ^- u) D
{
8 R: W& ^2 v) S) o  w0 e% Gstruct text_info ti; 2 q& q$ M7 m1 `* A
/* grab current text settings */
" [/ n! s, Q9 r6 Pgettextinfo(&amp;ti);
8 w. g3 s( T. H( ]/* interrupt 0x10 sub-function 9 */
  G8 {) m/ r9 @1 a( p3 J3 j_AH = 9; ; E8 {; a) {& x" v) W
/* character to be output */
# a  E1 \% G: s9 ~: S$ K_AL = ch;
0 }) @/ E& j; i& p& o_BH = 0; /* video page */
! ?0 K( |9 k" O7 p; [6 o3 M) t4 m_BL = ti.attribute; /* video attribute */ # F! l' q8 q5 Q; p
_CX = 1; /* repetition factor */ ' d0 F& C7 J+ S& w8 i+ S% j( f
geninterrupt(0x10); /* output the char */ 6 I. G3 S' W8 D. y8 W
}   [8 _, [* e3 u& p5 K- f
</FONT>
" {% Y& S0 |. S* ~' \. D</P>
4 z% X/ I' }/ x/ ~5 m7 X8 n0 o% R/ ~<><FONT color=#ff0000>函数名: getarccoords </FONT>
- `0 k  Z$ n% F功 能: 取得最后一次调用arc的坐标   J! F9 r- l1 B( Z6 F4 D
用 法: void far getarccoords(struct arccoordstype far *arccoords);
, n& w) `/ U% _; i: _. S; k% n程序例: </P>9 p* r% f1 V, C* \/ D* @
<><FONT color=#0000ff>#include <GRAPHICS.H>
. [) m. l% W# g! z) n#include <STDLIB.H>
3 u; `/ ]5 ^. O8 \#include <STDIO.H>
& h- s( y$ T2 h" @. a; M#include <CONIO.H></FONT></P>
* C% _, [# k7 E5 ?8 ?: H<><FONT color=#0000ff>int main(void) $ N0 j  a; r) r3 X+ ~
{
) I' [/ i3 b' Z0 [  x4 \/* request auto detection */
; `+ x5 j2 _. L& ~: Fint gdriver = DETECT, gmode, errorcode; , U$ |; `. d# G
struct arccoordstype arcinfo;
6 n5 K/ k  a5 ]' U6 G* Eint midx, midy;
2 z* f6 K7 O( C( \& }int stangle = 45, endangle = 270; 3 |! L% O. h; ]1 e( d& i6 Q' R
char sstr[80], estr[80]; </FONT></P>+ j5 F* y# b+ Y  x" `
<><FONT color=#0000ff>/* initialize graphics and local variables */
+ K3 C4 x- i$ e1 P+ y1 t  f2 n' pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  L7 n' h  M2 k4 R  I0 ^3 Y<><FONT color=#0000ff>/* read result of initialization */ & B% Z5 N" ^, r
errorcode = graphresult(); % ^- {5 m& U% D8 p6 F: S3 l1 T; h
/* an error occurred */
0 @# d' A9 m6 j; Yif (errorcode != grOk) & D3 a" E1 ]- q: {8 H! L
{
1 U. V1 Q7 }# uprintf("Graphics error: %s\n", 2 c" C' x. C8 @4 D5 N/ y
grapherrormsg(errorcode)); # t% a. Z! }) R1 u. N! ]: z: P) M
printf("ress any key to halt:"); : {3 }8 V" R! D/ g1 T$ p6 ?' H
getch(); - k9 `8 w1 {" l6 ~8 r1 s( [0 w  o
/* terminate with an error code */ ) o6 R* \2 r: y: g6 j
exit(1); + S* g! T! r1 q( I1 i" P( P$ f" v
} </FONT></P>( i  d1 u$ d1 q6 M4 J3 l3 E% h
<><FONT color=#0000ff>midx = getmaxx() / 2;
& I9 ^( }1 W  ]& lmidy = getmaxy() / 2; </FONT></P>
8 v  [" N+ X  C7 n- E<><FONT color=#0000ff>/* draw arc and get coordinates */
4 Z# a5 x4 L; T5 o8 ysetcolor(getmaxcolor()); $ X" A7 O- w! E  l/ H' a4 F% I
arc(midx, midy, stangle, endangle, 100);
/ ?& Y6 i9 e& F6 Wgetarccoords(&amp;arcinfo); </FONT></P>
% o9 g" c, i6 j8 a6 a$ ?<><FONT color=#0000ff>/* convert arc information into strings */
% J- p$ s6 G8 h" g2 gsprintf(sstr, "*- (%d, %d)",
6 A* c7 H9 q6 x4 Zarcinfo.xstart, arcinfo.ystart);
! E  E( }* b7 U3 ysprintf(estr, "*- (%d, %d)",
6 i& `7 p: z; q$ A1 S6 w2 v- warcinfo.xend, arcinfo.yend); </FONT></P>
) s) {; l! d+ ~4 x1 |$ `<><FONT color=#0000ff>/* output the arc information */
( z, t* S% z2 n' Gouttextxy(arcinfo.xstart,
2 C4 I" \$ O2 _  uarcinfo.ystart, sstr); ! ], `# B) M  {; x; W$ h
outtextxy(arcinfo.xend, ; S) q* t) E& g# `4 {
arcinfo.yend, estr); </FONT></P>9 G" D5 ~$ O- c9 H, ~, |
<><FONT color=#0000ff>/* clean up */
- J* Y$ D, M, I2 ngetch(); 8 R: t: m: F/ ]7 F/ _
closegraph();
4 M5 J- Z! Y; g3 `return 0;
, c! L7 R6 ^  o" F5 ]}
! [2 r3 Z% N* }0 m/ t1 i4 P4 \! Q, V</FONT>; k: @1 ^5 s0 s% w3 ?" F  |

) _# _5 O* w$ ^4 [</P>
  }3 c* f2 S1 G" z<><FONT color=#ff0000>函数名: getaspectratio </FONT>+ J9 [- Z9 C+ ^" M- L2 j9 }
功 能: 返回当前图形模式的纵横比 % @+ Q4 z& o' L' g, d+ y; T
用 法: void far getaspectratio(int far *xasp, int far *yasp); 7 h' U0 h1 Z: w6 R4 s2 B8 g
程序例: </P>
2 n6 J% U' }" y8 }<><FONT color=#0000ff>#include <GRAPHICS.H>- m. X- ]1 C0 H5 E, f
#include <STDLIB.H>
' p# U& ]8 |: E/ `) b5 x+ X, u: M#include <STDIO.H>$ [5 G4 ?0 A0 d& Q$ I  W2 V
#include <CONIO.H></FONT></P>
' g; n  z5 }( B" R<><FONT color=#0000ff>int main(void)
- u* l2 F! e# r{ , r; V5 B- P% F0 F+ f- }
/* request auto detection */ % |# h" t$ z& c9 W- ]) ]! h
int gdriver = DETECT, gmode, errorcode;
6 j* S* y' H7 E& x8 rint xasp, yasp, midx, midy; </FONT></P>5 k( L3 \% {* B) m2 c
<><FONT color=#0000ff>/* initialize graphics and local variables */
" W! G; x0 Z- i, Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( _" I& s" ~8 @<><FONT color=#0000ff>/* read result of initialization */
& f8 b; S$ H6 R( H. p) D/ Lerrorcode = graphresult(); 9 P4 V! A0 Q" I; b- O& H) t4 t
/* an error occurred */
5 Q. u. v* `' z. |/ X+ E) ]if (errorcode != grOk)
" \6 ^# A& u4 m* O2 M% H+ e6 w0 I1 k{ . Z, c- B. @/ v( @" ~3 K
printf("Graphics error: %s\n",
3 Q+ Z3 i% l0 o8 L* ngrapherrormsg(errorcode)); " h) D/ w6 T7 x; D5 ^
printf("Press any key to halt:"); 9 ~0 o  t  q( s
getch(); ' A, _% X+ @9 R& J" {  Y: a
/* terminate with an error code */ ! Z" `# |5 [" t  v
exit(1); ! f! ]; Z% D$ {0 t7 r
} </FONT></P>
0 T. X: D. ]- |& d<P><FONT color=#0000ff>midx = getmaxx() / 2;
, b! W9 m; P% B7 a/ ^" Wmidy = getmaxy() / 2; . F+ H9 Y/ y( ^2 d: W
setcolor(getmaxcolor()); </FONT></P>
3 J3 @6 {, {% J6 }8 E5 m% k) U2 }<P><FONT color=#0000ff>/* get current aspect ratio settings */
) v. O( Y# i  I  {/ H8 K' Q) ogetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
1 r7 i& M  s) Y6 ^" ~0 c<P><FONT color=#0000ff>/* draw normal circle */ # a# l6 i' K0 n  e3 y# Q6 h& F  Z
circle(midx, midy, 100); . a7 l( T8 A! A5 Q1 E, [
getch(); </FONT></P>
5 D6 m! B# h+ d+ b* E<P><FONT color=#0000ff>/* draw wide circle */
7 ~8 G; w  q( c6 U1 wcleardevice();
, r0 H3 p* x7 R* h) \9 esetaspectratio(xasp/2, yasp); ' W3 ]. `# p8 c  e8 S( b& V
circle(midx, midy, 100); 5 Y9 w( Z0 C! T* s8 W$ Y
getch(); </FONT></P>* C" o" w6 h& R; D" T' W4 O
<P><FONT color=#0000ff>/* draw narrow circle */ ' F+ L: `  s1 O& [* K6 W) M
cleardevice();
: F" K: b+ l; X+ l! Fsetaspectratio(xasp, yasp/2);
4 M& K' e1 O9 ycircle(midx, midy, 100); </FONT></P>
% r" A8 u) _. H' @5 k<P><FONT color=#0000ff>/* clean up */
  C) w9 H+ d" q( C! c3 pgetch(); * P  e8 e3 P7 j$ P
closegraph(); - _$ C: j) `: I" x1 f( u4 F
return 0; ! z7 w2 T! t+ Z. f
}
$ O6 ~( ~+ t( u2 m. ^7 d! O% ^</FONT>, x2 y) P7 [1 X$ X' E( ?

- Y# R  J: F- t. v& Y3 Z2 w9 d</P>
3 ?# S; ^- Z! @: o" e<P><FONT color=#ff0000>函数名: getbkcolor </FONT>% z4 @6 m: L5 v5 c0 x. h
功 能: 返回当前背景颜色 7 ]7 z. j( T4 J3 k5 d
用 法: int far getbkcolor(void);
6 G) ?  G' L6 X& V, e$ A程序例: </P>
) F" `/ u  g/ |# @0 p% g/ J8 x<P><FONT color=#0000ff>#include <GRAPHICS.H>
( H4 q8 o: K  z; U7 G1 y#include <STDLIB.H>$ o/ H7 a- z  k5 K+ E% b. n
#include <STRING.H>  Y/ d! ~0 }! v5 V5 \1 v% c
#include <STDIO.H>4 x' O) Q) B# H' Q
#include <CONIO.H></FONT></P>; F( f: u3 _& b; a) U& y* s
<P><FONT color=#0000ff>int main(void)
# _' j* l& i7 G" ^# M: L6 c6 t{ ! m5 W5 e# \. e8 a8 z
/* request auto detection */ 1 k& S4 M  u4 t7 i, z
int gdriver = DETECT, gmode, errorcode;
# Z, h, Z9 A% A1 P" _int bkcolor, midx, midy; ' L; p. C1 [5 ]+ c; G/ T
char bkname[35]; </FONT></P>) R( d5 ^1 u  C- F
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' k5 A  b+ m8 }/ `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 s8 ]" [* U9 R7 b; @<P><FONT color=#0000ff>/* read result of initialization */
& X" [$ A5 l9 b7 `7 Q5 Jerrorcode = graphresult(); $ y% n8 B" n' _) u4 l' \2 p
/* an error occurred */
8 m( P) |0 ?' C/ Z  i' V+ Z5 Yif (errorcode != grOk)
$ F8 i6 A" e  R* ]; W* N{
2 g# P( h& r! C+ B/ F/ u; Mprintf("Graphics error: %s\n", 2 D9 N9 ~$ b% ]  h
grapherrormsg(errorcode)); " c, i* T4 V$ l# \# W
printf("Press any key to halt:");
! s/ }( a7 z5 S) {+ n% G" Xgetch(); / S* u$ g9 S0 h1 e" |
/* terminate with an error code */
4 n! ?2 E1 J/ y. H/ Z* L6 N2 D& I6 eexit(1);
; q2 y( N5 X9 Q1 f. ~+ L} </FONT></P>3 e) g- v3 K3 w
<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 M) b0 M# v/ Q$ ?+ ]/ }" s8 Xmidy = getmaxy() / 2; " I9 g8 A& r' m) C1 l- j" c
setcolor(getmaxcolor()); </FONT></P>
2 D4 i$ \& D4 i! C0 T% a7 U<P><FONT color=#0000ff>/* for centering text on the display */
4 v3 E" r9 H) c( t. y- `. W0 U# N, dsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>; H8 p3 B- z6 J; W, ]  w. U
<P><FONT color=#0000ff>/* get the current background color */
# n6 `6 Y7 p* z; x2 x" k1 Zbkcolor = getbkcolor(); </FONT></P>$ q$ Y5 G! x5 t0 w" y8 c5 `9 T
<P><FONT color=#0000ff>/* convert color value into a string */
8 ]! v; \: N! i, Oitoa(bkcolor, bkname, 10);
/ ~' l6 m. D7 ?/ [/ a, a* Rstrcat(bkname,   a0 K2 p$ H) ^
" is the current background color."); </FONT></P>
7 @7 O0 O2 ]4 N+ v; ^<P><FONT color=#0000ff>/* display a message */
& s- D9 z3 \, `7 Touttextxy(midx, midy, bkname); </FONT></P>
  J! E* j8 q7 y- a, f" ~<P><FONT color=#0000ff>/* clean up */
  k) t& a7 d) m- S+ m* l2 ?' vgetch(); ) t5 P. d* E) n0 H2 H
closegraph();
' i0 T9 |7 R! a/ K* Nreturn 0;
& E; G3 v$ n3 R8 G1 d4 {$ g+ L& T} , E* N  A2 W. @" u5 |- b

0 ]2 G3 A7 L7 A. L7 O$ |; o# r</FONT>* e, Z2 Q' I0 m$ {) O/ U* j
</P>; {4 I+ @% r$ R$ p, R$ r
<P><FONT color=#ff0000>函数名: getc </FONT>& w2 ]7 K* N5 _
功 能: 从流中取字符 6 M: K, d2 `' v- S: U
用 法: int getc(FILE *stream); * j& V3 Y% V/ @" t
程序例: </P>
$ T: o: `0 n( \7 V<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>- B0 U/ q2 `1 N7 V% F" N
<P><FONT color=#0000ff>int main(void) . A& J8 n% {1 W1 _4 J
{ / H; Z$ E0 H( p) A9 }5 M
char ch; </FONT></P>3 i1 K. \$ d( x  `
<P><FONT color=#0000ff>printf("Input a character:");
+ a! G$ @$ l) W3 [9 _9 X0 h/* read a character from the
( k) T( f8 }1 N% v# z. Q' L, estandard input stream */ / H) o. g* ?* |  @+ P0 L
ch = getc(stdin); + L/ b$ X# R7 C) j7 i* A
printf("The character input was: '%c'\n", * y: W' z2 y5 b  q
ch); * i9 I) V, A8 z% c+ c6 e( A  H
return 0; 6 c3 N# C% S7 ~, f
} $ t2 L! Y9 t  d; a

+ u  {8 K1 y; w1 q' k$ w/ z</FONT>
7 j5 F  v& t5 d* w4 [$ L</P>1 C0 r+ ~9 ]) T! ?4 B
<P><FONT color=#ff0000>函数名: getcbrk </FONT>
# `& X) s" }7 g4 u: Z# @功 能: 获取Control_break设置 2 C6 p, d, {4 N, T+ F6 R3 k
用 法: int getcbrk(void); 9 `9 k8 I0 D9 \9 {; b; {  y) S
程序例: </P>% O, ?4 `+ @8 U1 d
<P><FONT color=#0000ff>#include <STDIO.H>
4 R& i+ a# [' l1 p+ {" B#include <DOS.H></FONT></P>' `' j; B5 x7 r6 U( ]
<P><FONT color=#0000ff>int main(void)
/ o1 y- Q7 f' M5 `& V- S* X{
# L6 V; X- P4 N4 q) g+ kif (getcbrk())
2 f) Y9 ^" f  Z+ oprintf("Cntrl-brk flag is on\n");
+ k& L  @  s, t# l0 Z  `else $ \" D* E. I3 {2 @+ P; t0 k' J
printf("Cntrl-brk flag is off\n"); </FONT></P>1 h! l/ y) n$ F
<P><FONT color=#0000ff>return 0; 3 Z) t: f* B& D/ t2 c6 [, C
} </FONT>
2 P" d4 m& h3 A0 N9 A# A4 ]2 s6 F0 E+ a1 T
</P>
# b, x: ^$ ?4 o' }. p<P><FONT color=#ff0000>函数名: getch </FONT>
% }% M3 E2 n% b4 w5 Y5 Y功 能: 从控制台无回显地取一个字符
  J& t4 x, O6 [7 |' \% P: `用 法: int getch(void); 4 _+ X/ u; d9 [/ [5 ]
程序例: </P>
: y4 l. Y" f/ [<P><FONT color=#0000ff>#include <STDIO.H>
9 a3 [6 L' d7 @/ T#include <CONIO.H></FONT></P>7 \8 h4 e' ]& i5 I5 j1 T
<P><FONT color=#0000ff>int main(void) " A/ r7 n+ I, h" m  Y3 n6 `
{
; s, |, ~6 j1 b2 n; x) h" `4 \4 T1 ichar ch; </FONT></P>4 z: N% N; E) c& q3 Q
<P><FONT color=#0000ff>printf("Input a character:");
" T- A+ t9 |% q6 S# i1 m+ fch = getche();
5 T3 Y1 D/ @  ^- F1 c, oprintf("\nYou input a '%c'\n", ch); $ C, b3 q* [" b7 j
return 0; 8 d3 X+ e9 b# J+ Z! }+ @
} ; {  a1 k! k; p0 I, r! Z: b

# F1 p! q8 I8 J; z! H: ?</FONT></P>
8 X5 Y0 ?1 U2 j+ A  `" B; P% r# ?4 ^: {<P><FONT color=#ff0000>函数名: getchar </FONT>! e  s7 G* i) P
功 能: 从stdin流中读字符 3 i0 T4 n; T0 v. p/ q
用 法: int getchar(void);
& y+ K$ T- t- q: ]3 i" E6 d程序例: </P>
' P# F8 @* j2 b& c) R8 z1 H2 O3 ~<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>- ?+ G7 y/ L( p, v4 O
<P><FONT color=#0000ff>int main(void) 5 m6 B9 s9 v8 }8 U# u) t, b
{
0 p# {: g. j) m5 \. C7 s* R6 G. x  ?int c; </FONT></P>
- I. M) o* E! g( Z<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
* V, `: F& O5 ]6 w$ M8 p+ _is line buffered; this means it will   k9 w1 |- G" t2 F  S( P
not return until you press ENTER. */ </FONT></P>4 p1 C! `6 y7 Q0 A+ f# X+ Q- \
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') $ R( E8 ^% e9 r7 b: K
printf("%c", c); </FONT></P>5 C* q4 b, `0 S1 n7 \& b; S
<P><FONT color=#0000ff>return 0; ( I. l/ s' [. X
}
+ i5 C: |! j" L& F% v- W</FONT>% _: h4 u) M& X3 e2 ~3 F; U
</P>
: Z/ H! k9 x" `) i) l<P><FONT color=#ff0000>函数名: getche </FONT>0 ?; d. R9 p* d$ h. F( p
功 能: 从控制台取字符(带回显)
" U. u% c  h. u1 @0 z# d5 C用 法: int getche(void);
) J; u; f' S6 X$ `8 v程序例: </P>
3 W0 O9 Z1 y8 v* I$ F' S$ L<P><FONT color=#0000ff>#include <STDIO.H>
8 M" L& @3 y1 o0 ~9 s8 r#include <CONIO.H></FONT></P>
1 ?9 ?! {. P6 K- }/ Y<P><FONT color=#0000ff>int main(void)   a* u* C3 X1 b) C
{ + z6 \9 {" h* I4 @: ^$ r5 }2 M& o. N
char ch; </FONT></P>: L) R) @1 b' `" x5 m! L* U
<P><FONT color=#0000ff>printf("Input a character:"); : {+ t( _& m* C8 g1 u7 T
ch = getche();
& T  e( A( d, Dprintf("\nYou input a '%c'\n", ch);
8 ^& g- x( j2 c( p- X% R, Hreturn 0; % a1 e3 T* u+ |
}</FONT> ( R5 [9 p" L* F! N
, l$ T% t- I6 }* z* b: K7 S
</P>
4 O( U+ i7 n( R4 v8 A2 q  q<P><FONT color=#ff0000>函数名: getcolor </FONT>- k) J( V# j& H7 z. D! ~
功 能: 返回当前画线颜色
. M0 P7 d4 {9 p) C! M7 c用 法: int far getcolor(void);
# Y( x9 d3 `5 x8 N. m2 O$ Z; E程序例: </P>
1 y6 O0 i9 b: ?  Q/ B<P><FONT color=#0000ff>#include <GRAPHICS.H>2 F) |7 J3 y, j7 c) }- A
#include <STDLIB.H>
! z6 h; E, v/ D2 b#include <STRING.H>- s- b5 W9 R8 o- e
#include <STDIO.H>
9 a1 ^+ z9 H+ M#include <CONIO.H></FONT></P>$ Y5 q+ a! k; W( D% T  C$ @
<P><FONT color=#0000ff>int main(void)
) P* o5 i9 f2 C' b0 t  q+ v{
% E( t3 b4 L% w' K# J5 x( H/* request auto detection */ * ]  p  X; c6 V) y: t
int gdriver = DETECT, gmode, errorcode; : M; s* A2 N% x0 J. V( y
int color, midx, midy; 4 k  R6 y; a  r
char colname[35]; </FONT></P># Z/ k1 @: n' M" H8 p
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! q! A9 d5 x4 r  @" w
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 ~+ S, z$ D. p7 ]7 y$ N- S! B, W<P><FONT color=#0000ff>/* read result of initialization */
# V4 N+ [1 w! V9 x4 Werrorcode = graphresult(); * Q% P: M7 ?' |4 y% f- _
/* an error occurred */ " c4 g! m; n1 b, [- b
if (errorcode != grOk)
/ W3 w% q2 J) @5 ?0 d{
* X& x8 {; N9 B6 Z' u) D- p  v( _printf("Graphics error: %s\n",
8 y4 T4 M7 e$ c; E" \grapherrormsg(errorcode)); ( M$ [! \' L9 F4 [- A4 k/ g
printf("Press any key to halt:"); 2 J# M' b9 N6 _  f
getch(); , r8 N' ~  J: L5 L: [3 M* H/ n
/* terminate with an error code */
5 N$ P0 t; \' W3 Q3 I; ?8 a8 xexit(1); $ p! J; V, f$ c* J* n1 }. m
} </FONT></P>
" |3 i0 L& M6 q2 s% X4 X) n1 G<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ G' Z( J/ B' Y* u1 z- T# Kmidy = getmaxy() / 2; ! m0 e$ A( d8 C6 M" g& P/ S
setcolor(getmaxcolor()); </FONT></P>
7 p4 r9 l7 j9 \<P><FONT color=#0000ff>/* for centering text on the display */
+ ^) O0 k' m2 N4 n0 D% e) ]$ ]% vsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>6 B9 `$ V9 M" E! `: @- Q9 f
<P><FONT color=#0000ff>/* get the current drawing color */ # K: i5 r6 d, ?0 j7 Y7 [
color = getcolor(); </FONT></P>
" z/ Q4 s  ]0 V4 F: v<P><FONT color=#0000ff>/* convert color value into a string */
# _& d# @0 T# ]% ~! Litoa(color, colname, 10); & d* e- n. c) ~  q, i5 i: ~
strcat(colname,
1 p  ?1 Y1 c) l  {) b; }1 [" is the current drawing color."); </FONT></P>
7 v# f8 L6 Q# A4 }! ], i<P><FONT color=#0000ff>/* display a message */
9 \3 i4 B6 B* K6 G3 Douttextxy(midx, midy, colname); </FONT></P>7 C% H/ n  a# X. I
<P><FONT color=#0000ff>/* clean up */ 8 e' l! y4 r$ c% w( @
getch(); $ Q4 A. I0 k$ Q$ x- ]  H
closegraph(); 4 y3 k# c5 h7 l) q
return 0; ) l2 k  Y* G. h3 g. ]
}
; f/ S0 N+ I2 I- }6 W& }</FONT>
7 n1 ]: w$ V5 f/ _. e</P>
: A* R" @+ J5 t1 ]<P><FONT color=#ff0000>函数名: getcurdir </FONT>
" K2 f1 x  W5 o" a功 能: 取指定驱动器的当前目录 1 i# N4 L6 P) Y3 M, I' g, ^. R+ m
用 法: int getcurdir(int drive, char *direc);
9 I& g' \; _& t7 b% ~# |" [程序例: </P>
$ }  M& t. \: E' @2 n<P><FONT color=#0000ff>#include <DIR.H>
/ ~* F& d" h0 z1 w" Q#include <STDIO.H>
8 p, X9 S: n0 e, T8 N#include <STRING.H></FONT></P>; |- x4 A- R; {
<P><FONT color=#0000ff>char *current_directory(char *path)
2 R& @" Z7 [( a0 X: m: d1 p{
+ }- x$ h, r+ cstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */
8 R1 J* G' b7 \1 ?1 e, c; Spath[0] = 'A' + getdisk(); /* replace X with current drive letter */
; t) y6 E5 n8 @  E; O. y3 O7 Igetcurdir(0, path+3); /* fill rest of string with current directory */
: k! K& D7 `9 |2 ^' b; C0 Greturn(path); $ W5 k6 L0 E* j( D9 k4 [6 t
} </FONT></P>) h) C4 }) I/ Q& y" n% P3 ]
<P><FONT color=#0000ff>int main(void)
6 s6 M5 [  }- N8 q# j4 h{
$ A- F' ^* d' Y5 Z- n1 ~( }$ Pchar curdir[MAXPATH]; </FONT></P>
6 L' U5 [6 U7 U<P><FONT color=#0000ff>current_directory(curdir);   U: N- a. L6 D. F
printf("The current directory is %s\n", curdir); </FONT></P>
# q' S1 ?' y. U1 Z0 S<P><FONT color=#0000ff>return 0; ( C3 H4 C* X$ J+ N
} 5 y. U2 i+ p$ C; d- Q+ e( |% ]
</FONT>
: p0 H7 f  ]* a& n2 h# n</P>
% p9 r) b5 n. s  U, K. D9 v9 a<P><FONT color=#ff0000>函数名: getcwd </FONT>
5 v; v* \! s- I) K- n" z功 能: 取当前工作目录 ! j. a! M# c: _0 l( |) `. r
用 法: char *getcwd(char *buf, int n);
$ r; d/ `- D# n$ D2 p8 J程序例: </P>
  y: |! G2 {2 [+ X! }* c<P><FONT color=#0000ff>#include <STDIO.H>
* L6 G1 X% Q3 H1 q#include <DIR.H></FONT></P>4 K) j6 _: m: t& k
<P><FONT color=#0000ff>int main(void) . \' T) q8 V& C7 g9 B
{ 9 g3 c: M4 t! K6 m
char buffer[MAXPATH]; </FONT></P>
/ M+ t: Z8 Z/ |<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);   P% P5 ?% P8 a3 P. b( s
printf("The current directory is: %s\n", buffer);
1 l: `" T+ l" l' f* Z6 Dreturn 0;
( y0 \: a" w% }} </FONT>- K$ S5 W# f  k6 e3 b
8 p, g. S. u% M# B' G9 z0 ]
</P>: P3 a5 T! r/ X  Y( g7 h
<P><FONT color=#ff0000>函数名: getdate </FONT>
/ d. p0 `' S1 P: W5 ^功 能: 取DOS日期
; ?- T$ ?) \$ {; y用 法: void getdate(struct *dateblk);
" _; C1 i, [2 J8 r( f程序例: </P>9 X& B- K! P0 O) h3 y
<P><FONT color=#0000ff>#include <DOS.H>4 I6 N9 c. e5 r6 U: E+ O% e* _. d4 w
#include <STDIO.H></FONT></P>& ^8 Y7 [0 `% N# B7 k
<P><FONT color=#0000ff>int main(void) 7 v* C2 W/ _+ @
{ / D, k) B, _2 Q
struct date d; </FONT></P>+ ^% _' @( `" n5 ^6 |* U
<P><FONT color=#0000ff>getdate(&amp;d);
2 h0 G  Q3 t! S" Q7 gprintf("The current year is: %d\n",
' A2 a1 e6 o. Z' S4 l" Jd.da_year);
! e8 }. R0 g* w! i) ^& b- x  Yprintf("The current day is: %d\n", : D0 E, Q  s7 u7 z- x" {/ q9 O
d.da_day);
, B) K* l" L2 ]5 X6 w7 w& q) `( `printf("The current month is: %d\n",
0 S, Y* T, V* ~/ k/ F  ~d.da_mon);
; V7 J8 Q3 o' p( a9 y: q0 sreturn 0;   s6 I; ~) H, F0 L1 b- b( S! p
} 5 G( {9 o; l' @% N# G
</FONT>
9 `. m1 F7 U9 L5 o</P>% ~# F2 H8 m0 Q' E2 f
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>( E5 R" ^8 g1 D7 h+ L/ S# {; {  o* ]
功 能: 返回调色板定义结构
  X0 ?0 d/ E6 ?用 法: struct palettetype *far getdefaultpalette(void);
' l( N; O0 C) b4 t程序例: </P>4 K3 I. i$ [( k% O( n9 N
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ v( T; I) {9 |  J) j#include <STDLIB.H>
8 X7 D1 N$ i" l0 `4 w$ |#include <STDIO.H>1 E% ^( n6 V, W- a) h- [
#include <CONIO.H></FONT></P>$ e& ?$ c! ^# \+ a# m5 U  k
<P><FONT color=#0000ff>int main(void)
8 G) w( a  p$ j4 S4 X{ % g1 K5 Y( ~5 w6 [2 H. {7 U
/* request auto detection */ ) N$ }5 [9 F% }! w
int gdriver = DETECT, gmode, errorcode; " ^% r1 N( E  ]
int i; </FONT></P>
8 S: L1 N+ \& B7 P! A; V<P><FONT color=#0000ff>/* structure for returning palette copy */ % p' ]8 t1 c4 ^
struct palettetype far *pal=(void *) 0; </FONT></P>
2 _: t  F  h* {+ i% Z8 L" _2 ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
( \7 I4 Q& X; B2 E/ H7 W8 q1 @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 m1 O" V0 D1 j% R' R
<P><FONT color=#0000ff>/* read result of initialization */
  Z+ s+ V# Y9 merrorcode = graphresult(); ' ?; O8 I1 ~5 {4 b  Y$ I: v
/* an error occurred */ 6 N& [  H+ U6 N* g
if (errorcode != grOk) 3 K9 p& ^- y. E3 ~0 k! b
{ 9 F$ E: G6 ^: h# U7 k- o
printf("Graphics error: %s\n", : M: L5 ?6 i$ J* d2 y3 w
grapherrormsg(errorcode));
" |; s7 {  ~) v$ y' rprintf("Press any key to halt:");
: K5 y8 B+ \( y0 w0 Wgetch();
' C1 U! t" C4 S" T/* terminate with an error code */
9 m1 n/ O+ P  ~* jexit(1);
7 e9 Y2 i- M1 i7 l/ k} </FONT></P>
- x* \/ t) x9 r8 w<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>' m( M' k! K1 _
<P><FONT color=#0000ff>/* return a pointer to the default palette */
# ^& Q% U! ]1 @' C# |% V# fpal = getdefaultpalette(); </FONT></P>
6 ]$ ~8 E, x& C6 r! Z+ M<P><FONT color=#0000ff>for (i=0; i&lt;16; i++) + Q4 \0 s% Q/ h
{
3 [( P# h3 D0 l, a. {2 P( gprintf("colors[%d] = %d\n", i, 1 q$ @- ~: x' w1 L+ n; [
pal-&gt;colors);
, `& T3 I1 J& D* G1 v# h$ V* [getch();
' g- k1 \% h' l* W9 b} </FONT></P>
0 b: h! m8 \( N4 H  ^8 G<P><FONT color=#0000ff>/* clean up */ $ Y- m. _5 p/ G9 R( S: W
getch();
  Y' o, o/ a. m7 l5 vclosegraph();
2 Z1 E' {: c- U0 p3 }- greturn 0; $ n+ s2 z  y/ f) H7 V- `
}
# f7 Y8 n* d' J% O( a8 s1 w: V! H</FONT># X2 P7 u% ]7 ^* V8 U
</P># ^  _+ n0 z, u
<P><FONT color=#ff0000>函数名: getdisk </FONT>( m. X& G! {. U! j/ O
功 能: 取当前磁盘驱动器号 6 i6 k$ G8 f) J5 r" k
用 法: int getdisk(void); ' D8 u3 v$ V6 r7 ^
程序例: </P>
9 x# m, u8 \# y/ {4 d0 F5 j7 c<P><FONT color=#0000ff>#include <STDIO.H>0 e) r$ Z: g2 u2 _' }
#include <DIR.H></FONT></P>: U3 z6 P& L3 ^8 F: `/ u
<P><FONT color=#0000ff>int main(void) / F+ I6 C* l! v1 {8 ~
{
" v: r% K0 j0 B6 a7 K7 n/ Mint disk; </FONT></P>1 }4 }3 ^- i: S  q0 c. L  U
<P><FONT color=#0000ff>disk = getdisk() + 'A';
& w  k* p8 u) L* c) S7 g! gprintf("The current drive is: %c\n",
- W7 S7 Z9 G4 {  s8 o4 idisk); # P1 H# F0 ~0 c. x' x0 p
return 0; ) U) Q, e. w' @0 c7 X" }4 _* g
} : i4 I$ Y0 F8 ~; s% d

! V# K+ H0 i" y* ]</FONT>
5 u! P4 @2 H* |& M</P>5 K5 e5 o! z- e- Y# i# O
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
1 l) u/ b  L9 M  U/ C( I. [功 能: 返回指向包含当前图形驱动程序名字的字符串指针 % U+ @4 }) T. C& \
用 法: char *getdrivename(void);
% F) I, m% B8 r0 V& X% u程序例: </P>8 k. Z7 T$ B& a8 y% S
<P><FONT color=#0000ff>#include <GRAPHICS.H>% ]5 h; b( m* M: D  {. F. c
#include <STDLIB.H>; m3 {% {  @6 s# G& @7 W
#include <STDIO.H>& C! ~8 o  b; @! \! @; q
#include <CONIO.H></FONT></P>- l) ^3 W( D9 I
<P><FONT color=#0000ff>int main(void) 0 H; G) N9 I7 f7 L4 @+ u2 J
{
+ q  h$ E9 o# V* M, |7 p1 T$ z/* request auto detection */ 7 z" [, N; K. I& q
int gdriver = DETECT, gmode, errorcode; </FONT></P>
! R7 f7 u4 Z8 [$ J( J5 s4 X<P><FONT color=#0000ff>/* stores the device driver name */ $ ?8 l. I1 A0 l: Q4 R! y  s/ B
char *drivername; </FONT></P>$ G$ }$ Q, ~: R# |3 K
<P><FONT color=#0000ff>/* initialize graphics and local variables */ * S3 d4 C% Y: ]; Q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 b/ Y3 I9 @/ t<P><FONT color=#0000ff>/* read result of initialization */
" V) G# b. L) R: H! z9 d, s% Berrorcode = graphresult();
# M$ b, ~) l) L" X+ Y/* an error occurred */
3 P$ z, l" g; K- T( ~% wif (errorcode != grOk) ( h& X4 q8 G# F( o$ C* T
{
) @9 b0 S4 v! ~printf("Graphics error: %s\n",
4 i; g- j0 d. n# d' `% R+ cgrapherrormsg(errorcode));
0 R$ m8 E% ^$ t7 F5 Aprintf("Press any key to halt:"); * y8 ^5 M, C. Z/ H+ s; w# a7 J: {
getch();
2 T/ Z8 Y9 ~; D. E. o8 M/* terminate with an error code */ ) i* B) Z. l( U7 |+ `, o& Q
exit(1); 9 \! V3 K. x" v- E  M$ O
} </FONT></P>$ J& w" @+ F4 I- y
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>4 L1 }4 f" o/ `/ W  _
<P><FONT color=#0000ff>/* get name of the device driver in use */
: i2 N& l" A4 e: C6 U$ Rdrivername = getdrivername(); </FONT></P>
7 L& r2 @- v; u" ]( e- ]! F6 g. p<P><FONT color=#0000ff>/* for centering text on the screen */
( J4 Z+ Q$ [9 J3 u& p0 L/ I# R# @settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
8 r& N- U, T! b$ U( B: ]<P><FONT color=#0000ff>/* output the name of the driver */ 9 _' g+ S6 }& i
outtextxy(getmaxx() / 2, getmaxy() / 2, 1 U3 y5 y% A. R# z$ L
drivername); </FONT></P>! ^, W8 D0 K/ [* g: C
<P><FONT color=#0000ff>/* clean up */ 3 a/ C& J# C% E! Z  ^. X
getch(); # w0 v1 @& |3 K0 Y
closegraph();
6 K9 C% T1 A" N" P- Yreturn 0; ' v$ s: P+ S; m4 u
}
) E( t+ E; @$ ~0 i8 i: C% k</FONT><FONT color=#990000>
) R- ^6 L5 P) M+ v. V" ?</FONT></P>" r' R8 k( M; `, N) P4 e2 t
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>; v0 `8 N- n3 c2 N( u8 e+ o
<FONT color=#000000>功 能: 取磁盘传输地址 - S! ^% N: E7 A1 ^/ n1 y
用 法: char far *getdta(void); 7 T& |& c) x* n7 K
程序例: </FONT></FONT></P>0 i8 V) n( l, P; N/ Y: q+ z  V
<P><FONT color=#0000ff>#include <DOS.H>7 [0 n: z0 V3 |( t3 l% U
#include <STDIO.H></FONT></P>
& ^  i" C! c( S: B5 R  h# S<P><FONT color=#0000ff>int main(void) . V% m* ?8 y, Y3 W: C. M
{ 7 Q# _5 F4 v  x& z% q# ?
char far *dta; </FONT></P>
8 y6 a' z* s- F- I<P><FONT color=#0000ff>dta = getdta(); 1 l$ s& e2 }. P8 x0 c6 {- j  s
printf("The current disk transfer \ 8 \( I! U5 a6 n: i
address is: %Fp\n", dta); ' B8 L+ p# X; s; \3 y
return 0; / ?4 X1 m% Y1 _) w
} 4 B/ ~. ]  S7 N! r
</FONT><FONT color=#990000>
  x  N9 ~4 p5 I* ~</FONT></P>" e- k  C! R" V0 z
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
) x7 P/ v0 g3 y; Z$ T# S<FONT color=#000000>功 能: 从环境中取字符串
% t- V9 U- p" D4 X; r2 {用 法: char *getenv(char *envvar);
6 R' R7 J( }9 k; {% a, N8 `8 x6 A程序例: </FONT></FONT></P>1 o  e7 p8 }, H( v& W8 a
<P><FONT color=#0000ff>#include <STDLIB.H>
+ V% l; K! _/ j- }! }1 |7 m#include <STDIO.H>
# u3 I9 L1 I' x" f# j0 N" E</FONT></P>2 _, o' p0 Y8 i) R2 r
<P><FONT color=#0000ff>int main(void)
$ l: Y( v6 E$ p/ w/ u  [8 y{
% Z; e6 s1 H- n7 ychar *s; </FONT></P>
, z( O3 [: k; [; {3 {<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ * }( p: a8 l2 R/ m; X6 K
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
( g! n- t" f. V& a<P><FONT color=#0000ff>return 0;
6 v( m0 q9 B! ?* w. Z1 e$ ~3 q} </FONT><FONT color=#990000>
7 {! s0 k, j% \% n7 {) Z1 h* c9 M5 Y
* \* _* W, h3 y+ j7 A- F, ~
</FONT></P>% F8 [+ d/ q+ p5 Q3 e. k
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>
# p  u# j: i* t; [功 能: 取文件分配表信息 ) P4 r$ `( p, t+ b
用 法: void getfat(int drive, struct fatinfo *fatblkp);
+ O) I) \" n0 l+ z& @程序例: </P>
  j. q6 Y9 I" Q. b' k& K<P><FONT color=#0000ff>#include <STDIO.H>3 c4 F/ E; X3 p" ?- i2 G2 R
#include <DOS.H></FONT></P>
8 P1 T& z! _2 V9 i<P><FONT color=#0000ff>int main(void) 8 G. H- U$ u+ f' d' ?
{
* T' D0 i' ^/ a& F) n+ S0 {: _struct fatinfo diskinfo; 2 @/ X. U" n2 c, Z
int flag = 0; </FONT></P>9 @( P6 [' v* J/ O9 i: q
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
6 X  u# N2 k7 g2 p6 f, f( mgetchar(); </FONT></P>7 o6 s2 b# B5 w+ m
<P><FONT color=#0000ff>getfat(1, &amp;diskinfo); 8 h9 F! w1 y- K: s: I3 |% I; ]
/* get drive information */ </FONT></P>
4 ^2 T& F: K4 A) |1 {/ }<P><FONT color=#0000ff>printf("\nDrive A: is ");
' e9 {; y/ _8 D9 _5 F7 Jswitch((unsigned char) diskinfo.fi_fatid) + m$ g' ?& K  L8 @5 m
{ ! e0 I6 N7 j! E. O
case 0xFD: ( t( Q2 V. z6 ~' w; V
printf("360K low density\n");
3 j5 S' T- ], @break; </FONT></P>! B" i& J: V+ \1 w
<P><FONT color=#0000ff>case 0xF9:
. E7 b# G8 N+ `+ f, p' Eprintf("1.2 Meg high density\n");
) g7 {2 R3 T/ l4 W1 a+ E5 Kbreak; </FONT></P>9 U/ [, g" K( H( ^$ s
<P><FONT color=#0000ff>default:
" C3 t' P, h" v3 j( {printf("unformatted\n"); 2 d5 b0 g8 [0 X
flag = 1;
4 f1 ?' W# ?6 _8 H" w0 u7 M} </FONT></P>% v% [+ J0 q: t; h
<P><FONT color=#0000ff>if (!flag)
2 a& U0 r$ Z) T" R{
* l5 g' O) ?+ U& z1 gprintf(" sectors per cluster %5d\n", / ]/ R* W, e4 Z! m7 [
diskinfo.fi_sclus);
# U# W6 S9 L. t6 i" r* l# l& kprintf(" number of clusters %5d\n",
0 T& ~* J" H$ v4 H. e" }7 @1 ]diskinfo.fi_nclus); . n9 y& m  O5 d! C. d
printf(" bytes per sector %5d\n",
+ u. e' M# D/ v+ Cdiskinfo.fi_bysec); 4 z; N1 X$ G# q! [, [
} </FONT></P>
0 p1 A3 x2 B$ e! Z; G<P><FONT color=#0000ff>return 0;
# b$ W4 y) ~8 Y} 5 v. `0 [& x0 S6 j* l& k$ B+ X
</FONT># ]- Y! B. c& k! y4 t: t
</P>% r5 J4 R# X9 i  O* D: C
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>/ A4 }  m% }. u5 \6 T5 Z
功 能: 将用户定义的填充模式拷贝到内存中
3 F& b" X! E# @( @0 H/ g用 法: void far getfillpattern(char far *upattern);
4 C# M) z) v- ]# V% H% H. o程序例: </P># t- J3 q- ?# f  F8 {
<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 G( T, \; k6 n- O, N- Z) J. p$ A( j#include <STDLIB.H>
. d8 V6 h) I4 Z# ]; Y#include <STDIO.H>
0 p6 T5 h2 a5 Q9 ^. P  Y! q#include <CONIO.H></FONT></P>( v9 F: B# D- U
<P><FONT color=#0000ff>int main(void)
0 A1 Z9 X- V% D{ 0 q/ Q9 c4 i) _9 |  @; B
/* request auto detection */
5 t6 e, r/ E$ b1 v+ e5 g6 J0 q, ^int gdriver = DETECT, gmode, errorcode;   ~3 |- {4 ]1 W3 Y8 Y
int maxx, maxy;
% s) f- [7 Y& U( k2 lchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
8 u! c" J; S" I. {* a& W<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ r/ |4 J& M1 C0 |7 Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 ~1 Q) N% M* s8 a<P><FONT color=#0000ff>/* read result of initialization */ * v  o( S$ f6 S
errorcode = graphresult();
9 A1 z4 F/ P7 [) o3 e/ c# Pif (errorcode != grOk) /* an error occurred */
$ B, C1 ~$ w5 v; w{
" D$ _8 e' M! i0 g$ Uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); + V6 k: r8 m% ]2 t
printf("Press any key to halt:");
. b. i, |4 `) q8 q- M" {getch(); , l2 Z* J) H- p1 M
exit(1); /* terminate with an error code */ 7 o- ]  P- N2 ^2 K- n, F
} </FONT></P>$ L4 W' ^4 {' g& |8 F
<P><FONT color=#0000ff>maxx = getmaxx(); ' @5 Q) L) L) I- v# b1 ]4 A
maxy = getmaxy(); 9 }4 O: R) S8 I- P% X2 b/ d5 M
setcolor(getmaxcolor()); </FONT></P>7 D3 S/ V" |0 r, X; c
<P><FONT color=#0000ff>/* select a user defined fill pattern */
6 ]6 T. f4 s, o/ Dsetfillpattern(pattern, getmaxcolor()); </FONT></P>! f/ \% V# S9 e. ~: b
<P><FONT color=#0000ff>/* fill the screen with the pattern */ 7 ?8 M$ _5 ]0 M9 ?( z, Q
bar(0, 0, maxx, maxy); </FONT></P>1 b+ D4 l- b- G
<P><FONT color=#0000ff>getch(); </FONT></P>/ `9 N! B+ ?: r$ U; |8 S; S
<P><FONT color=#0000ff>/* get the current user defined fill pattern */ $ h) C5 m* y6 u6 ?2 B# _
getfillpattern(pattern); </FONT></P>) C: \5 Y$ j7 ^- J6 s  E
<P><FONT color=#0000ff>/* alter the pattern we grabbed */ 5 x0 y. H2 S: i3 l6 }, Y" U  G1 ~8 y
pattern[4] -= 1;
& k9 H+ L, g3 ?6 r+ Q5 h5 Opattern[5] -= 3; . Z+ ]" q, e; }( L: ^! T" q
pattern[6] += 3; 3 ?1 w( q$ a  l! R0 o; W0 W
pattern[7] -= 4; </FONT></P>! t7 ]8 _4 v9 O# {8 k- M
<P><FONT color=#0000ff>/* select our new pattern */ 4 x, m4 D2 q$ ]. G: L- r  G8 O+ C; X
setfillpattern(pattern, getmaxcolor()); </FONT></P>  h0 r& e# R: l0 ^5 t5 v
<P><FONT color=#0000ff>/* fill the screen with the new pattern */ 2 Q; R; a* a2 L, b+ M! R
bar(0, 0, maxx, maxy); </FONT></P>
1 i, d. T. W* q$ C<P><FONT color=#0000ff>/* clean up */ 5 t! F) T4 P% A/ K
getch();
9 D7 w8 L" z; V! G9 Hclosegraph(); 9 u5 [% }8 P/ V4 F/ [1 j8 s* R
return 0; 8 u1 }) l$ \  C; A; h
}
- p- o1 j+ c( e1 g4 ^2 j& K5 R</FONT>
! i& T5 l3 q' G! f3 ?- I9 N</P>- ]$ U2 x( |9 |$ H+ u8 o6 E" I/ m
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
  T0 v/ r* o6 ]6 {( _功 能: 取得有关当前填充模式和填充颜色的信息 / J( A. d! k/ \- y3 g
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
5 Y0 U9 m  |& \程序例: </P>
! l+ y0 m7 ~2 R) m<P><FONT color=#0000ff>#include <GRAPHICS.H>: A" Y+ _( O) J/ d+ u, G' I
#include <STDLIB.H>
0 a& R0 \. I$ l% P#include <STDIO.H>7 z: R- Q' L8 K* m: w) W
#include <CONIO.H></FONT></P>- P9 C# o5 v# \9 G0 w* Q: ?
<P><FONT color=#0000ff>/ the names of the fill styles supported */ ( L  u* L: H8 T8 c& O: r% `
char *fname[] = { "EMPTY_FILL", . K8 A8 `3 W5 u  t- ^, c: {
"SOLID_FILL", 3 r( O% d, M: }- b
"LINE_FILL",
7 Y0 Q7 t1 u8 ?# L( H"LTSLASH_FILL", 6 Z0 n. l9 E) m5 f( Z
"SLASH_FILL",
" o$ i" a( \& u+ v"BKSLASH_FILL", 9 o; L7 r) [9 L3 `/ t
"LTBKSLASH_FILL",   U, Z3 }4 ^3 X- h7 ^. T6 n6 T0 i9 ~- k
"HATCH_FILL",
% r- p! K0 a$ ^. H9 [5 y) s; C( o"XHATCH_FILL", % s- r* l" g4 ], [2 ^! W$ }
"INTERLEAVE_FILL",
" q) ]/ G4 \% \" y  U"WIDE_DOT_FILL",
/ ]8 d, C2 ]: m"CLOSE_DOT_FILL",
8 b' {! ]: O. _. H"USER_FILL"
! h# V  r8 V. D. {}; </FONT></P>& I( ^' v  y6 e4 f, E% m
<P><FONT color=#0000ff>int main(void) 2 n0 _( j0 T0 g7 N* f
{ ! \8 {# m3 f# P6 u! Z
/* request auto detection */
& S  ~! ?# W, }! k0 V, {int gdriver = DETECT, gmode, errorcode; $ N6 w3 w, L7 B+ N6 V4 P1 e
struct fillsettingstype fillinfo; 3 Z, P" }/ _! }- H+ A
int midx, midy; ; c* Y: ]( g5 R
char patstr[40], colstr[40]; </FONT></P>
- \- {/ k* a+ ^+ w6 Y5 U<P><FONT color=#0000ff>/* initialize graphics and local variables */ " ?3 }1 D* Y: c' A
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 B  L% E* M; [  X0 L<P><FONT color=#0000ff>/* read result of initialization */
8 l3 T8 F- }1 W+ k, d: U; gerrorcode = graphresult(); 0 t7 r$ V% U- {
if (errorcode != grOk) /* an error occurred */
( I+ Q, u2 I5 \{
" X  w4 O9 ~- j( q# D  E0 V9 L8 b3 Bprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' V6 I( B$ Q/ k* K+ f9 F3 Bprintf("Press any key to halt:");
: f5 N* r8 G( H$ n6 ^getch();
+ D5 B: {8 E+ q/ O" B5 `% vexit(1); /* terminate with an error code */
3 |9 ~# R# F* g* j} </FONT></P>
) d; C3 d1 Z) s7 U# `4 ^# L1 r<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 }) Z! ]: |  x: }midy = getmaxy() / 2; </FONT></P>" @& D9 R* ]( J. J# w+ c: i
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ 4 ]; ^: N  e; ~# i( K
getfillsettings(&amp;fillinfo); </FONT></P>1 Y2 S, N+ l2 z/ k6 s9 B* P
<P><FONT color=#0000ff>/* convert fill information into strings */
4 D, j2 V6 |* P2 r$ f% ysprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
1 n1 {4 V7 }/ K! Usprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>0 S9 x) r+ G! j8 ^: @  V* j+ c2 A  o
<P><FONT color=#0000ff>/* display the information */
) g9 |  F: S- bsettextjustify(CENTER_TEXT, CENTER_TEXT);
5 b/ ^+ A1 [3 {6 Nouttextxy(midx, midy, patstr);
( |/ b6 U- h: Z/ W/ iouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
: }( \4 A# v! x$ K6 ^<P><FONT color=#0000ff>/* clean up */
, V5 h5 d8 V- ygetch();
4 P; ], |  J! U& u/ R. c  a& aclosegraph(); 4 j1 ^6 x" }0 U0 [3 q' M
return 0; " Q% s/ W) s- [- B+ }: E
}
+ Q4 g/ B( m( A' \: o</FONT>
: s0 z0 g- a; ~' ^
4 w4 d, G* U! u" Z* X2 {</P>
; _2 g% M% W( u; F( o1 G; ~- ^<P><FONT color=#ff0000>函数名: getftime </FONT>, S7 F+ I9 r! m8 j- f, G
功 能: 取文件日期和时间
1 H# |9 w8 M, T% A用 法: int getftime(int handle, struct ftime *ftimep);
% J  H; k( s( Z7 [; u' O程序例: </P>
' p6 W/ [' n1 M$ h& _6 D6 h<P><FONT color=#0000ff>#include <STDIO.H>% Y; `* A; A' {& y# k/ A
#include <IO.H></FONT></P>
1 g( i+ T' z7 G: p5 q<P><FONT color=#0000ff>int main(void) 2 H# l  g) N6 T$ i' [  q+ m
{ " ?! p0 Z# C, _3 a* j- c- C* u
FILE *stream;
# \) M) N$ Y: {struct ftime ft; </FONT></P>/ l! D* |% {/ ?. \: T
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", + J8 v: [+ O4 m/ o  H: i
"wt")) == NULL) 0 U2 A4 V+ w3 I6 C( p+ t. ^4 Z) B; I
{ % v5 G3 l% E- l# ^: Z$ C
fprintf(stderr,
6 G- b3 v) R7 E0 O"Cannot open output file.\n"); - `  n; }5 O' b3 k+ M9 [8 X' g
return 1;
& b$ ^4 ?: c7 }8 O2 h! I6 v} 1 q4 x4 X% U% Y9 ?+ e1 U7 ~' w) d. \
getftime(fileno(stream), &amp;ft);
+ [/ Q' V3 y% {* |4 ~printf("File time: %u:%u:%u\n", 9 Z1 u3 i3 s9 B! W- y8 f
ft.ft_hour, ft.ft_min,
6 y1 I  W! T5 C& sft.ft_tsec * 2);
/ i& p4 g9 i) I& n% q4 Iprintf("File date: %u/%u/%u\n",
* U, R* E: a( x/ xft.ft_month, ft.ft_day,
) [) }3 e( R- d  v+ N8 w* Zft.ft_year+1980); $ o8 ^$ N3 X4 K
fclose(stream);
' F  K& C3 @2 X' j, j$ Qreturn 0; ' d+ V5 P2 W  j. [/ ]8 K2 B& x' [
} $ Y/ y$ b5 f/ W3 \
</FONT>3 ~* K6 c" R5 C% T; I
6 R/ F* |! w' z7 s! z
</P>
5 r# V* a+ ]- Q0 J) {7 t7 O<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
/ k% @! R' v# \' g9 y. b功 能: 返回当前图形模式
4 x7 @+ |8 x, a4 Z用 法: int far getgraphmode(void);
% r3 ]; B: S! O& _* @% ?; N7 F程序例: </P>
; r0 V. A) X% R0 Q7 A2 G<P><FONT color=#0000ff>#include <GRAPHICS.H>6 x0 H* T# q) D2 f
#include <STDLIB.H>
" y* J2 c8 ]4 m8 f0 o( }+ n#include <STDIO.H>$ p9 i2 x" B4 E* R0 j6 k: F
#include <CONIO.H></FONT></P>5 Y: a, Z1 M& _: b* j; D9 @. Q
<P><FONT color=#0000ff>int main(void)
# ~* s0 \( ]- A) B  L{ - O- m: f( W3 L! e3 j8 D% N5 Y2 n# o
/* request auto detection */ 2 ^0 m  y/ b! Y( b! ?
int gdriver = DETECT, gmode, errorcode;
; ~5 x0 j. |$ g0 w; m- Qint midx, midy, mode;
2 T0 U3 ?0 Y+ Rchar numname[80], modename[80]; </FONT></P>
, p0 @6 Y( U) a1 J0 c<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 u. e" {. F% M8 v3 x
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 _3 ?. c6 i: P  z6 E2 C<P><FONT color=#0000ff>/* read result of initialization */
4 C) t2 q. O  U) O' Lerrorcode = graphresult();
8 {! a! o& F& B% I/* an error occurred */
: {# x: A+ ?1 m5 P  y; q: jif (errorcode != grOk)
; P9 k. R2 e8 n' b0 S' m: b{
' s8 ~& O+ [, |1 Kprintf("Graphics error: %s\n", 8 ^  Z! }7 \( L; R! Z9 D( l8 `
grapherrormsg(errorcode));
" `  k( C8 J3 O& b1 a2 {printf("Press any key to halt:"); + l/ ]6 x4 @: {$ P( z
getch(); 8 U4 [6 T0 S, H1 [8 E: {
/* terminate with an error code */ + ^' C7 b+ \1 o7 ^8 w# O
exit(1); 6 q! ?* g9 e  Q7 A7 \8 _* r
} </FONT></P>
$ ]4 n& H; m/ j: _: P<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 l9 K9 G1 R: I5 g2 Q
midy = getmaxy() / 2; </FONT></P>% X4 [: W/ @7 f) D7 }( L
<P><FONT color=#0000ff>/* get mode number and name strings */ : Z* A) v7 |4 M6 B6 D+ o$ M
mode = getgraphmode();
4 A% w) m  A/ O. f  Q1 ksprintf(numname,
- F" ?9 R  b1 \6 f"%d is the current mode number.",
+ W6 H1 s9 ^* n8 |mode);
% i. I% |/ j$ K: l2 ~: s9 ksprintf(modename,
  d/ \( N% }/ w1 Z, }2 T- p- p"%s is the current graphics mode", 4 M3 H; ]( ], e3 n) f' F
getmodename(mode)); </FONT></P>/ [# E: ?9 e1 Y- g
<P><FONT color=#0000ff>/* display the information */
, n; `( ]! o! Q! e/ Csettextjustify(CENTER_TEXT, CENTER_TEXT); : A" o- ~, U3 S2 I
outtextxy(midx, midy, numname); . W$ T9 a6 L7 C$ ^7 [' w7 y
outtextxy(midx, midy+2*textheight("W"), ) R/ V" r9 K; u
modename); </FONT></P>
: W, |( s: S, i5 G<P><FONT color=#0000ff>/* clean up */ . Z5 Z7 |/ O( C
getch();   A$ x7 }+ p0 a7 y, Q% Z0 u
closegraph();
. o  a! }- y& ?; ~return 0;
. }. _- k+ |5 f6 C} </FONT>
- v6 W, V. K. s5 w- x! a' n9 {( H" B0 e' g5 @
</P>( |1 R* I5 A0 r) G6 z
<P><FONT color=#ff0000>函数名: getftime </FONT>
+ N- a/ ~* }( D3 v7 O7 ?' }功 能: 取文件日期和时间
$ L9 d' u/ Q9 q用 法: int getftime(int handle, struct ftime *ftimep); & G% ^# N- G) F$ m. P
程序例: </P>2 S) n  f- \! v  @7 m* g
<P><FONT color=#0000ff>#include <STDIO.H>
/ R) d* s! R& f- Q& I: q#include <IO.H></FONT></P>
5 [  M2 ?+ p8 w6 b3 m<P><FONT color=#0000ff>int main(void)
! U4 \" O% m" @& c{
' T( n" ]8 o/ R; N+ C" D( rFILE *stream;
; V, _- T9 S1 z0 s3 _) k( [8 _struct ftime ft; </FONT></P>
& Y! b) w2 ~1 y: G6 Y: F& i<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", , A- K. X  z0 H: q3 g
"wt")) == NULL)
" R/ t" F2 T/ @* M{
# m9 u' w! |- F/ I( z0 p, u* i  ~4 tfprintf(stderr, . @$ C$ K+ e8 Q$ i9 ?3 m# X! k- o
"Cannot open output file.\n");
; p+ X* j  u$ S0 vreturn 1; 5 n- }( \% Y1 m( k' V8 V7 a6 `
} & R0 b1 E3 b+ X5 O% V. Q  |% K/ d) B
getftime(fileno(stream), &amp;ft);
9 O$ J8 s, f9 E' e2 ], ~: O& I5 Tprintf("File time: %u:%u:%u\n",
& y* e3 Q" V4 b3 t% qft.ft_hour, ft.ft_min,
) S5 J& I4 K3 @ft.ft_tsec * 2); 0 D  v# f6 @* ]: ~8 b; ]+ d
printf("File date: %u/%u/%u\n",
$ J# I) T6 n) v0 `% {0 o8 `3 Vft.ft_month, ft.ft_day,
. F' q, |9 `4 Mft.ft_year+1980);
6 N. A2 T3 Y( M* p" m  x) O" ?* qfclose(stream);
" Y! H; c& G8 q7 w9 Q$ e2 [8 Ereturn 0;
$ r! w2 B: E1 g, ]} </FONT>
& B5 W) ^! y  O% Q# b7 J
0 m. q  t& F; }" c7 S, V6 C4 h. L$ X! ^6 t7 y& f: j
</P>
9 E6 p8 V6 H/ ~+ ?' V$ y<P><FONT color=#ff0000>函数名: getgraphmode </FONT>$ o( @( Q3 z; z+ y' r# N- K0 Q9 v
功 能: 返回当前图形模式
% R* K- {) v6 Z1 K! M; H用 法: int far getgraphmode(void); 2 Z$ C2 \8 ~( j  ^2 J3 m+ v4 d- }
程序例: </P>) r+ ]8 X% D- W/ Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( n( F" c+ b% V; y* h8 n#include <STDLIB.H>$ e9 q6 F! Z7 B5 ?- m- d! I$ s. j
#include <STDIO.H>
+ D- W( R2 P( @7 E. y#include <CONIO.H></FONT></P>- X7 z  l* V* m" j& q6 D' m
<P><FONT color=#0000ff>int main(void) 7 J# h4 x6 p# |. x
{ , R/ K7 [8 l/ u9 O; D; W6 l! q# K
/* request auto detection */
# R2 n9 X, h0 V7 s$ D& e1 f5 Vint gdriver = DETECT, gmode, errorcode;
4 g4 D: r% v& I' nint midx, midy, mode;
. `) y. G& R' s* e4 S: ~char numname[80], modename[80]; </FONT></P>4 D& m3 g/ ~9 W( ^+ x. J& U
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 e' G" q3 P. L) q6 l+ \' T! X8 |3 qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 D9 ?" r5 U5 i' o
<P><FONT color=#0000ff>/* read result of initialization */
5 m+ k  B& m! s8 w$ O# \errorcode = graphresult(); ' `6 G7 r. l" G3 x6 o8 F% Y
/* an error occurred */ ; k$ \! `9 j4 b* K* y, x) e
if (errorcode != grOk)
: I, L# @1 T& h{
  `. R: k4 @8 T4 Lprintf("Graphics error: %s\n", 2 N; X* a, d6 D; t0 O
grapherrormsg(errorcode)); ) k+ E! \* {* M, A' Z( i
printf("Press any key to halt:"); $ L  v* N  y$ [3 H
getch();
% H( r6 e/ T* I" N% j/* terminate with an error code */
- F6 Q  b) n9 ?8 `5 w5 ]exit(1); / {* |2 X+ f/ {5 j# P7 u, A
} </FONT></P>: L+ F* [& f( L$ d
<P><FONT color=#0000ff>midx = getmaxx() / 2; - }) K- C( d+ d
midy = getmaxy() / 2; </FONT></P>
' h6 u& h0 O2 E1 V<P><FONT color=#0000ff>/* get mode number and name strings */
2 V( o$ D' P" ?& Vmode = getgraphmode();
4 @  y: F, ^  M4 E) H+ k. i% Bsprintf(numname,
# A6 A# J& Q% G" O) P  W, B"%d is the current mode number.", % k3 a4 \. [7 @! {0 h
mode);
) Y1 Z; M2 ]6 O- @, x4 J2 rsprintf(modename,
  }3 W8 J' e& q- N+ ^. w/ U"%s is the current graphics mode",
& D5 a" z  v2 kgetmodename(mode)); </FONT></P>
, H2 g, j! C7 T& R7 q<P><FONT color=#0000ff>/* display the information */
1 U; G$ y+ q+ M9 G- r4 W- ~5 _settextjustify(CENTER_TEXT, CENTER_TEXT);
, B4 ]) ?. _) H% Vouttextxy(midx, midy, numname);
7 V2 x$ H7 Y$ x2 ~" Aouttextxy(midx, midy+2*textheight("W"), 5 I; G/ I- A, n3 V, Q# ?
modename); </FONT></P>
1 }# }; k2 v4 J" f7 t<P><FONT color=#0000ff>/* clean up */ 1 z: a9 |1 V1 a! |
getch();   d* i4 s1 V& `5 A! i
closegraph();
+ |& Z3 b5 I4 P7 r' q- ~return 0; . G; o4 d6 j2 V7 y- l
}
0 l6 S4 c# n' q8 B) C; o</FONT>+ @; o+ G2 q+ [7 P2 ~8 c% z
</P>
+ `9 ^' j) b# q- K: p<P><FONT color=#ff0000>函数名: getimage </FONT>
+ |0 Y' E/ j3 Y2 }7 f9 q功 能: 将指定区域的一个位图存到主存中
# m/ U; u( y( H8 v; x$ L用 法: void far getimage(int left, int top, int right, int bottom,
- O( {5 J- N' w4 rvoid far *bitmap);
% c6 |' ]: q5 P! q% E程序例: </P>
1 Q; l7 Y  O* x" F<P><FONT color=#0000ff>#include <GRAPHICS.H>
; Q! @1 [, ]5 r3 x7 U! N#include <STDLIB.H>
8 h, b- s" F9 ^#include <STDIO.H>- o& L9 X/ Z; {% k2 i3 I, ]" x
#include <CONIO.H>
, n" X  d! k5 O: P3 z' b#include <ALLOC.H></FONT></P>& O! {- G5 n7 a7 P3 u2 A* K
<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
# r; A3 @7 U7 v3 L7 |void restore_screen(void far *buf[4]); </FONT></P>
; {  `3 h! a0 @$ ?3 Y<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
! ?6 F6 Q, Z( o1 J! S& G<P><FONT color=#0000ff>int main(void) 2 [: [$ P1 B3 h
{ - p( [* R" o: U- {
int gdriver=DETECT, gmode, errorcode; 1 |+ }. }" t( R" M3 U- c$ H% w
void far *ptr[4]; </FONT></P>
) L5 M6 S( [! [! _7 J  R<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ , I- M4 s4 B! [3 K' ~' T; Y
initgraph(&amp;gdriver, &amp;gmode, ""); 6 C( v2 D+ K; E8 ~0 C3 G3 C
errorcode = graphresult(); /* check for any errors */
! W6 S6 u' e1 ^if (errorcode != grOk) * p2 G2 `! D& O2 `8 S4 q
{ / f6 t+ E% N8 @
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 B3 H* \4 X" f" Qprintf("Press any key to halt:"); % L$ f" t# s, n
getch();
5 D/ ^* M  N9 A' Cexit(1); ) Q6 I& q2 K. Q- W
}
* |6 [! B. g) q7 K% L2 r) xmaxx = getmaxx();
- U8 O% M0 Y& A' k2 jmaxy = getmaxy(); </FONT></P>2 e3 U* J7 m1 M7 ?/ F% M
<P><FONT color=#0000ff>/* draw an image on the screen */
3 G. p' H# B" `/ @  r( b! {rectangle(0, 0, maxx, maxy); 6 Z0 L9 R- c4 ]) i
line(0, 0, maxx, maxy); 0 P3 V0 W0 T- X$ b5 U# t# d
line(0, maxy, maxx, 0); </FONT></P>* t0 e) g: N; C8 v
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
) G8 v: b/ A  {2 \1 I  dgetch(); /* pause screen */ ; E8 F( [$ K0 L! z/ m* a
cleardevice(); /* clear screen */ 3 l/ [' J: C/ ~  L' e; [
restore_screen(ptr); /* restore the screen */
7 Q; o  L/ j2 \$ Vgetch(); /* pause screen */ </FONT></P>
2 e2 b9 q' n* q( o& A<P><FONT color=#0000ff>closegraph();   B( \& Z- z, \  _0 l% H7 O' G
return 0; 7 k8 U- Y* R2 z! v' m0 b3 k
} </FONT></P>4 _9 h( K# J3 b& @* y0 C1 E
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
6 r4 V" I2 g" U+ l# S2 s6 ~{ ) F0 S! W" A7 H7 ?2 t& @( X
unsigned size;
3 P8 C9 N$ }+ C  T3 [( Y+ mint ystart=0, yend, yincr, block; </FONT></P>0 P& N; M3 L% W: z
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; % ?4 l6 J: H( ?4 C3 T/ `
yend = yincr;
  r+ d* v7 t2 ?) S% g- Fsize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
+ V& u  S) z" R3 T<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) ) l7 J% f4 }6 s* M. e
{
6 J1 b: Z& R1 o1 O' y1 ~) jif ((buf[block] = farmalloc(size)) == NULL) ( |; L  C9 n6 s2 _2 d5 \
{ # V( q' U2 f5 i+ d/ w
closegraph();
- s1 G* F* ]4 _4 tprintf("Error: not enough heap space in save_screen().\n");
* \* W& i0 }& i( `5 x& ]exit(1); , f8 G3 ]$ t" V2 T8 [
} </FONT></P>& U6 |  n0 U3 D' ?
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
9 J/ P6 J6 ?% O+ Y4 C' q2 ^ystart = yend + 1;
: k3 E4 n' L9 s' o3 ~5 Z9 }  Dyend += yincr + 1;
2 }! Z0 R& g$ \' _} $ G$ A8 E2 e7 t1 n. M' t( H7 q
} </FONT></P>
0 |0 G8 `2 Q2 T% p<P><FONT color=#0000ff>void save_screen(void far *buf[4])
# D* o$ r& @% f4 y{ 1 @! r) |/ X1 V9 v/ w
unsigned size;
' [3 W: i0 g/ u$ {8 E' c( G" {int ystart=0, yend, yincr, block; </FONT></P>' T* P% f: N9 Y0 P3 A" Z* j) Z" Y
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 0 s7 a* ^4 r6 i0 N# D+ b# `8 K
yend = yincr;
) ^( P, K: M( O. q- q! Zsize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
; ?% H2 J8 u$ d+ L: Q<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
2 J; ]. i+ x5 l- U; g; @{
3 K; T- p6 o( wif ((buf[block] = farmalloc(size)) == NULL) # f( V0 j; w" W) |& r
{
2 E8 ?1 s8 P" s: b4 U, ]8 F; |closegraph();
" h9 H+ C* N9 x8 B  hprintf("Error: not enough heap space in save_screen().\n");
4 c5 C. s' X0 y3 n  [- Mexit(1);
  g8 `0 ?' A  V8 I, \} </FONT></P>8 q: N1 O& n( ?; G2 Q
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); ; p( _# a& [& I
ystart = yend + 1; 6 y# O/ J* {) I$ O
yend += yincr + 1; + R/ D3 F8 y: E  c& [& y
}
! n" N7 X4 N* P8 Z- Y0 G1 ?3 x  M2 C} </FONT></P>1 N+ b: I# o2 ^
<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) 2 ^- a! S  _' y
{
/ q5 m" e: a2 M) l4 uint ystart=0, yend, yincr, block; </FONT></P>
5 D5 @, C0 l+ c- U+ \1 @; C1 j<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
$ u% N3 i, `# S* D* n) Uyend = yincr; </FONT></P>
% T7 E  m( z" e3 h<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
& S; E0 l$ u% ~+ J6 [' l3 W) @0 C{ % H4 L9 `' c- M: x0 n- C$ {2 {
putimage(0, ystart, buf[block], COPY_PUT);
, h- \1 }2 U7 n- a. o; o0 q: H; @4 Cfarfree(buf[block]);
. D0 l" Q* J, g* W) lystart = yend + 1; 9 J% o% L7 w! M$ F1 X
yend += yincr + 1;
7 A1 i. u# E0 g$ p5 I% s} ! c$ U/ |# A# L' ^. ~2 Y
} </FONT>
5 A6 g; u& w8 L, m3 A9 q$ z7 `<FONT color=#ff0000>- Z! s0 L) C" Z1 D! O
</FONT></P>
* X4 n1 N: W9 D/ t8 B<P><FONT color=#ff0000>函数名: getlinesettings </FONT>/ g) H6 N1 ^  b( _: ~* f6 [
功 能: 取当前线型、模式和宽度 5 l* j+ h8 Z9 z: m
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
; B6 ?9 f: e: v3 d  Y3 V程序例: </P>! h' {+ L3 L, E" ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! `, J* \3 [6 z#include <STDLIB.H>
- V3 o5 @, X. v. X#include <STDIO.H>
5 B, r. @3 s4 p- m. N3 m) p#include <CONIO.H></FONT></P>
" j! k( l3 p. P9 B/ \8 y) Q( M1 P<P><FONT color=#0000ff>/* the names of the line styles supported */
3 F* F! J8 w7 ^4 e6 w) e0 tchar *lname[] = { "SOLID_LINE", 1 c6 U! _) o4 c/ U& V
"DOTTED_LINE", , u8 b: {  X2 C  B  ^& y
"CENTER_LINE", " E) W1 Z6 b9 I4 D1 {' y
"DASHED_LINE",
# m# j" i0 u- }4 H"USERBIT_LINE" $ q# r5 X6 O) J# `3 R; A" @& U# w
}; </FONT></P>
4 H% L) R4 j# ^<P><FONT color=#0000ff>int main(void)
) O! m' g/ [+ {# w: t, {{
. ^% m+ s8 l, N/* request auto detection */
9 d. f$ h5 g7 }. l4 g4 rint gdriver = DETECT, gmode, errorcode; $ z1 \1 G1 N8 ?+ N3 t9 X
struct linesettingstype lineinfo; , T8 r7 o; |% e2 f2 \  {1 j" c
int midx, midy;
- M& G) w: U: N9 Fchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>; e4 {- y, B  O- v) r) T- O& S
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 b3 E3 {# |% hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) H: v& X2 e; M: N# h
<P><FONT color=#0000ff>/* read result of initialization */
/ K% A+ t+ p1 N4 N% g7 Zerrorcode = graphresult(); 1 M# E, e! b" K' r0 P8 N
if (errorcode != grOk) /* an error occurred */
, k$ K3 [5 Y# N8 U4 ^{ * y" ?9 p7 v6 F) B; r
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 [! R  \5 z1 j) H  k7 {printf("Press any key to halt:"); 2 M& U/ {6 m; a$ n* E1 k6 Y# y1 S
getch(); . V7 ]2 J# G& H' v$ C, \
exit(1); /* terminate with an error code */
! q. Z0 a+ r( q$ \} </FONT></P>; ^: w1 a% F. S9 ~! v
<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 x+ L- Z. |! o, T% i) O
midy = getmaxy() / 2; </FONT></P>
$ j' a+ I4 ]* r2 c( s<P><FONT color=#0000ff>/* get information about current line settings */
( ]0 @# K1 ?$ b! v2 b/ Y( ]( _% ]getlinesettings(&amp;lineinfo); </FONT></P>
& F$ k9 O8 H& `  O, Y0 M<P><FONT color=#0000ff>/* convert line information into strings */ 6 B( G  t  S" l* Q- l0 G
sprintf(lstyle, "%s is the line style.", 8 X1 a" F0 E8 x- Z3 W# S0 [
lname[lineinfo.linestyle]); & v! w# x( Y& u
sprintf(lpattern, "0x%X is the user-defined line pattern.", 7 R; c4 d6 l* }. D1 F, I' p1 g
lineinfo.upattern); 5 P" W1 j# G( O6 y; V: ^( t
sprintf(lwidth, "%d is the line thickness.",
8 T5 R& y1 ~7 v/ l% Ylineinfo.thickness); </FONT></P>$ l* S. b$ [- o2 @7 A& D* d( R3 @
<P><FONT color=#0000ff>/* display the information */ 3 z6 q) O9 |( n! A
settextjustify(CENTER_TEXT, CENTER_TEXT);
% @) C  d/ S5 P1 ^1 J! g; f4 g+ e6 pouttextxy(midx, midy, lstyle);
7 z8 h, z# D  ~8 @outtextxy(midx, midy+2*textheight("W"), lpattern);
8 R( o" D' T6 U6 t6 uouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>% X: W7 Z, F, X" N9 k; H/ _7 w
<P><FONT color=#0000ff>/* clean up */ * J1 `" I$ B, ~( K# v+ a: N+ d+ X+ f2 d
getch(); 9 g- }! j* |4 V) e+ \$ y. ~) U# X
closegraph(); * a" a5 q! k1 h0 S. G& ~
return 0; * P- ^/ D# Y2 `, ?
} </FONT>
- b" p1 ?; O7 I1 g" p+ i# E) ~: J- p
5 H* G0 Q# [# J4 n0 G4 e</P>
6 n; W% L- ?' {  G" L2 {1 D<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>( k9 e. a1 M) I1 {
功 能: 返回可以传给函数setcolor的最大颜色值 9 \( z$ P& O8 B1 c3 N, [/ E
用 法: int far getmaxcolor(void); . c6 J1 ?. p# C2 k7 q/ k; F/ L
程序例: </P>3 e* l- ~# V* I7 ]% M
<P><FONT color=#0000ff>#include <GRAPHICS.H>- e4 s1 Q  V; |& X* E# y
#include <STDLIB.H>$ D$ K" j( R1 t7 b3 r4 {
#include <STDIO.H>
" ?5 M1 y" s8 n$ H#include <CONIO.H></FONT></P>2 X+ N" z: g) }- _
<P><FONT color=#0000ff>int main(void)
' b% G, N0 h2 f9 o{
6 q/ a. p& _4 W! h/* request auto detection */ / h. ?. A' {- M- l" c- A! N- w
int gdriver = DETECT, gmode, errorcode; . g! c* ^6 u3 T/ v3 r
int midx, midy;
* P$ H& m, D" N* h' k3 xchar colstr[80]; </FONT></P>
# R6 L" r1 U1 Q6 i- G" ?<P><FONT color=#0000ff>/* initialize graphics and local variables : P4 t3 ^& ?- B3 A
*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 U" Y! ]2 h( h7 i
<P><FONT color=#0000ff>/* read result of initialization */ 1 U# l* |( z1 U' [  k- U5 z
errorcode = graphresult();
% N; W; z* `- c# O6 rif (errorcode != grOk) /* an error occurred */
6 n& m) x& `3 ~9 v$ ~{ " d+ Z1 `0 P4 w0 f- I
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 m+ s6 G/ s2 y8 ]- `  l$ J4 J0 ?2 O
printf("Press any key to halt:");
6 ~; s# t, f8 X% u! V6 Xgetch(); 7 o$ `8 t% B, s# Y# {
exit(1); /* terminate with an error code */ " ?' e) e4 s2 |* r! j2 X0 n3 F
} </FONT></P>. p/ F$ q2 F" x8 ?) W8 `
<P><FONT color=#0000ff>midx = getmaxx() / 2; ; s: ?1 \2 C/ b3 W) {9 Z
midy = getmaxy() / 2; </FONT></P>4 Q1 V* H* d' E6 u
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
/ B. C5 b2 F3 W/ r& P+ p9 u2 `sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>5 c0 N; _1 o$ m( Z
<P><FONT color=#0000ff>/* display the information */
& r  O" s% t$ h6 s$ E4 V4 _settextjustify(CENTER_TEXT, CENTER_TEXT); 8 L! H" i5 h% @
outtextxy(midx, midy, colstr); </FONT></P>
* h0 h# p$ z! G9 ^6 F8 ^<P><FONT color=#0000ff>/* clean up */
# y1 [0 W5 K7 W) k% u' Y" C' vgetch(); 2 x& Q, d7 g+ O
closegraph();
  M4 U' X- [$ R1 @return 0;
1 T/ f8 q% f5 w9 C" d1 V9 \} </FONT>
0 n8 K0 @4 t: v: ~' h9 x* y
) @; B, o; @( X: u, a5 d' e& T- s1 \5 A; k
</P>, E+ ]  k/ t2 {& x$ A
<P><FONT color=#ff0000>函数名: getmaxx </FONT>
  a+ `1 m' Q0 P功 能: 返回屏幕的最大x坐标 : ^6 {: r) `$ @' n
用 法: int far getmaxx(void);
; q" G2 i/ F0 g( A6 Q( f程序例: </P>
: |- R! m; l+ o: o9 Z<P><FONT color=#0000ff>#include <GRAPHICS.H>4 s5 r* M8 R1 `, ?- m
#include <STDLIB.H>! ~) ~4 W- K, z. j) F7 ?, G
#include <STDIO.H>( l" r- w* f! B- E4 V: f
#include <CONIO.H></FONT></P>, M7 h4 i* D4 M7 v( A
<P><FONT color=#0000ff>int main(void) ! P3 W* f* F' A( i/ A0 v8 Z
{ 6 f$ l# W  L/ |! {; N- v
/* request auto detection */
5 j/ C% ~2 l9 l( N+ hint gdriver = DETECT, gmode, errorcode;
2 i: p7 K9 z( Z6 v/ Dint midx, midy;
+ {' M' D5 P! I  Z" b; bchar xrange[80], yrange[80]; </FONT></P>
7 J% W* I" X2 ]7 L5 O<P><FONT color=#0000ff>/* initialize graphics and local variables */ , E8 R2 F  z4 Y  F5 \* Q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 [' U1 u. g( P- _& N' F: H<P><FONT color=#0000ff>/* read result of initialization */
' e- |" T8 h% I5 @& i; J4 f7 zerrorcode = graphresult(); ! D* x5 ?& [7 H$ F$ l* s; ^# P
if (errorcode != grOk) /* an error occurred */ 9 f% G+ K6 ?8 t% S! b% d
{ 1 f3 h8 P8 j# l6 ?  N/ ?( m
printf("Graphics error: %s\n", grapherrormsg(errorcode));
9 v0 _. Y% @& Dprintf("Press any key to halt:"); 7 f7 n9 x4 k3 Z' f  Q% ~$ {
getch(); # v% _1 N# j2 r. x4 @' i
exit(1); /* terminate with an error code */ 4 \3 \2 Y4 U% u) N5 D4 J: s" s
} </FONT></P>
# m7 C5 h- a/ P/ d5 ?" s/ Y<P><FONT color=#0000ff>midx = getmaxx() / 2;
# w8 l: O4 y% o. q- Z' Umidy = getmaxy() / 2; </FONT></P>+ s# b1 \! m3 O1 {- i1 V
<P><FONT color=#0000ff>/* convert max resolution values into strings */
: b$ u5 C# K2 g* ^. dsprintf(xrange, "X values range from 0..%d", getmaxx()); % z% w" U0 b$ q  W' G& i0 x
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>8 ^/ D7 Z  I% t" e5 ~
<P><FONT color=#0000ff>/* display the information */
6 L7 Y9 u  m* Y; ?8 F5 @" Esettextjustify(CENTER_TEXT, CENTER_TEXT);
% {* P7 h  v  Youttextxy(midx, midy, xrange);
- h6 U( z$ @& L+ Gouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
& n+ M) Q$ U# g, b  g<P><FONT color=#0000ff>/* clean up */
2 O) v) p8 `* z% E( z. |( L9 w5 ggetch(); ) l0 ?" l/ _2 o" Z* ]) A& L
closegraph(); ) e5 k( Z4 k1 h8 n1 g) h* b9 v
return 0; 5 @; p: ]7 i1 i) f) M6 g5 {+ y
}</FONT>
! P0 c6 [6 T/ ?9 y' X( V
  r0 O( \6 v7 |) |. M; _</P>
1 |: ?9 H! [$ ]6 I; k<P><FONT color=#ff0000>函数名: getmaxy </FONT>5 Z( ^; F2 n/ ^
功 能: 返回屏幕的最大y坐标
2 b6 M- e( o* [  D( d8 D& u6 B% n用 法: int far getmaxy(void); , _' d" `1 J6 ^  x' J0 D# ]
程序例: </P>
# W6 H$ R! c) S) x<P><FONT color=#0000ff>#include <GRAPHICS.H>( P4 u, e# C8 [5 s9 K2 L5 n" L
#include <STDLIB.H>7 u* g+ m& `1 [  O4 m' O: d
#include <STDIO.H>
! f. W9 M9 C9 y+ n8 ]& N5 C#include <CONIO.H></FONT></P>
. S7 ^1 D2 @8 Y<P><FONT color=#0000ff>int main(void) 5 _4 R  e. s0 }+ t% v2 c
{ 9 _; `# W6 w* T5 P- `7 ?6 t  V
/* request auto detection */
/ j6 Z2 v5 J* m: Wint gdriver = DETECT, gmode, errorcode;
! e2 E; x. X- ^% ^int midx, midy;
5 G; L& T* ?8 Zchar xrange[80], yrange[80]; </FONT></P>( @- M; }) I6 ?3 J! Y% H- d% @
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - _; ~+ k* P1 B. x  z. o: E  o
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ Q( u& Y( E! _& I" n5 ]<P><FONT color=#0000ff>/* read result of initialization */
. Q3 y- k/ ?  M! _; t; `6 perrorcode = graphresult();
& V# s+ ]$ V' X- o8 C! _* Lif (errorcode != grOk) /* an error occurred */ , U: V1 X+ H1 O2 y$ o
{   D, V6 s, A+ O- o" P+ G; t$ Y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % p, d" E9 m, J- f; S
printf("Press any key to halt:"); ! m; J/ W' G/ y8 `; ]7 t
getch();
1 s- f3 r6 d  I) ?0 D- [- l$ `exit(1); /* terminate with an error code */ 4 A% |( u1 c: q* L7 v. w8 B6 K2 F( ]1 v
} </FONT></P>4 m0 S' v. U) w* w
<P><FONT color=#0000ff>midx = getmaxx() / 2; , O: w+ C4 b/ F2 \% X
midy = getmaxy() / 2; </FONT></P>- y2 ^, C' F9 Z" p9 u% m+ F  K
<P><FONT color=#0000ff>/* convert max resolution values into strings */
0 @" M9 g* f9 q3 E: m# M9 Lsprintf(xrange, "X values range from 0..%d", getmaxx());
8 a0 |- J/ I6 Q& W7 n0 q+ Osprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>: ?) C5 p- ~1 X" v  r/ r
<P><FONT color=#0000ff>/* display the information */ ; L% @% Q6 @- Z7 K6 h5 y
settextjustify(CENTER_TEXT, CENTER_TEXT);
( a- x9 w, S! X6 G" Vouttextxy(midx, midy, xrange); 4 |3 p- {. m8 N5 b& z
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>% e: A! L8 W7 y; y: J4 y; ]
<P><FONT color=#0000ff>/* clean up */
/ e# \8 X% @  A2 q8 ?/ R) ?! d1 cgetch();
' S6 _' m) q; I" aclosegraph(); ' M0 T4 R" ^2 ~9 `
return 0;
8 a& z7 i4 s# h& O3 H! t} </FONT>
, b5 N/ ]3 q- T</P>
! v! u1 ~$ q* X" ]7 ]<P><FONT color=#ff0000>函数名: getmodename </FONT>
7 f. S% i2 }& A$ o# m功 能: 返回含有指定图形模式名的字符串指针
3 T/ }, ?5 Q5 A* M8 o; B& I用 法: char *far getmodename(int mode_name);
6 L- l$ x2 s$ T. O程序例: </P>
! v+ T/ D7 ^2 D& u2 Y+ H  b<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ L1 k" E2 y3 W7 D% A#include <STDLIB.H>
  I+ }$ Z5 t6 _5 ]#include <STDIO.H>
- y4 S; ~5 T9 I5 R#include <CONIO.H></FONT></P>
- ~% k. M$ x3 x( m<P><FONT color=#0000ff>int main(void) 3 |( H( d& p/ y  X* I0 a
{ 4 U& W4 l) J  C
/* request autodetection */
6 \1 _6 @: H( T0 z. Hint gdriver = DETECT, gmode, errorcode; : p5 ~' h' T( n; p
int midx, midy, mode;   X* S& {2 b" z# s% V+ T
char numname[80], modename[80]; </FONT></P>+ k; K3 O" L# F2 @  f$ B. W
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; @$ S: e$ a& H" S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 v( |" w  {1 a9 E: E6 G* e
<P><FONT color=#0000ff>/* read result of initialization */ 0 k/ v. y, A9 p3 k8 R# K
errorcode = graphresult();
2 t  N" W, u# s8 i6 Zif (errorcode != grOk) /* an error occurred */ / k4 G1 c& x0 h: r' X. ]
{ $ Z! n0 U: H' t2 }* h7 N9 f
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; N' G* c6 S# ]. U* e% R# `
printf("Press any key to halt:"); ( L8 P) k2 h1 W: B! R! X+ l5 B/ r4 G
getch();
# i* Y# Z& Z) w7 g' B/ t% u, Vexit(1); /* terminate with an error code */ * S5 Q" C3 h+ |! T' K
} </FONT></P>
" u0 s( u* X/ @! k1 g4 @<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 D6 C% B+ D( |0 i& I+ j- K8 t
midy = getmaxy() / 2; </FONT></P>: N& E+ Z3 W% M5 z/ v% w
<P><FONT color=#0000ff>/* get mode number and name strings */
4 `' _, A: f+ l% `mode = getgraphmode();
! n9 q" M, n' \% osprintf(numname, "%d is the current mode number.", mode); 5 ?6 o: O' L( h2 ^" }# v/ t
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
% c4 ]7 Q/ s0 S# h; E7 b/ A* J<P><FONT color=#0000ff>/* display the information */
# }/ M: o2 g  W* Csettextjustify(CENTER_TEXT, CENTER_TEXT);
; \% j  }9 X$ c: v( ]outtextxy(midx, midy, numname);
( ]- T- ?" {* \+ I1 \outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>6 L+ \  w' h& i8 Z( J/ T$ P) M
<P><FONT color=#0000ff>/* clean up */
  ]) O9 i3 P* `getch(); ; n" x' p6 Y3 o9 z+ ~6 Y' H
closegraph(); * E2 C# ], _% D3 ^
return 0;
! _! U2 v/ C6 O2 Z) p# t9 i' t) d} </FONT>8 _( K3 u8 S7 B0 C

6 {  [( y4 K2 R</P>
4 ?$ L" \! X# ]$ T% f8 R5 n<P><FONT color=#ff0000>函数名: getmoderange</FONT>
6 H. k+ D+ C0 z0 |! F功 能: 取给定图形驱动程序的模式范围 $ L4 N7 k' }: t8 |# D4 a3 ?
用 法: void far getmoderange(int graphdriver, int far *lomode,   W! t5 N" @% [( s( d- ?
int far *himode); , `2 z# K6 D( c  K% L
程序例: </P>
' G4 N3 ^* V' _; E+ o3 f<P><FONT color=#0000ff>#include <GRAPHICS.H>
' U4 c2 ?( J3 D$ b4 w#include <STDLIB.H>
2 o4 E& b0 q1 p0 v! ~+ y#include <STDIO.H>
- y; T1 s# P. M( `7 }, m#include <CONIO.H></FONT></P>- z# U. e  b7 C! a
<P><FONT color=#0000ff>int main(void)
9 x" A+ j. w4 V2 @% `5 k2 D{ " M0 n/ \5 F# m/ k5 {
/* request auto detection */ 6 E7 M8 ]% W' O9 r8 h
int gdriver = DETECT, gmode, errorcode;   U3 _1 f  P: e" a0 `6 I$ a
int midx, midy; 3 i( d% r+ A7 F5 i; O/ J
int low, high;
6 r! t! f2 `( mchar mrange[80]; </FONT></P>: |+ x0 W- p; ^" i
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , C1 G  \/ i7 j$ d5 i
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 ~0 i5 Z" t8 M" p+ V; M
<P><FONT color=#0000ff>/* read result of initialization */
. S! Q% v4 O$ ^! [: E" ]5 yerrorcode = graphresult(); ' ~7 J& V( c$ H& A% }* i( W
if (errorcode != grOk) /* an error occurred */
- [! A( _) t! e0 s$ B/ c8 f( y{
, U9 K: A  V& D$ ^printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 [. r# ^8 y+ x6 w3 T5 y
printf("Press any key to halt:");
) h" O% e# f, x) z, B; D  pgetch(); / g( ^& N; y7 y. |& a
exit(1); /* terminate with an error code */
2 M2 E6 O: R, [6 S! O} </FONT></P>4 Z; f: a* t: K
<P><FONT color=#0000ff>midx = getmaxx() / 2; # T/ i. T' D) [( s  f
midy = getmaxy() / 2; </FONT></P>' ?1 A# N: K/ [. m: {
<P><FONT color=#0000ff>/* get the mode range for this driver */ ; F& a* ~% P$ z2 M8 M, b; B
getmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
0 |* i- n: P9 P  ^% Z: F<P><FONT color=#0000ff>/* convert mode range info. into strings */ % O9 O/ r- ^! \1 ]
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>2 L% {) I# r: i- J; L; p
<P><FONT color=#0000ff>/* display the information */ , O1 V* G2 N* c: i
settextjustify(CENTER_TEXT, CENTER_TEXT);
5 j- e* u$ W, _# X+ ~4 p# couttextxy(midx, midy, mrange); </FONT></P>1 J& z+ S- t9 }8 d* n
<P><FONT color=#0000ff>/* clean up */
" l+ k7 C' E9 Tgetch();
- \1 H" Q# a" t' `closegraph();
6 a& A, ]7 K/ K' j2 _  yreturn 0; * D" P$ \9 V1 C4 f2 Q
} + _5 {+ r9 ]$ R/ m2 j% G
</FONT>$ ?; O7 |* R# u) o: A6 o; C+ J2 n5 M7 u
</P>
, g: L- I. Z+ d# U% Y4 m<P><FONT color=#ff0000>函数名: getpalette </FONT>& y5 `; ]3 `( X, I
功 能: 返回有关当前调色板的信息
, D7 F8 x5 {5 ~) E/ J用 法: void far getpalette(struct palettetype far *palette);
. K* {9 Z/ }# `  Z# ^程序例: </P>
1 u( s: G8 l2 m<P><FONT color=#0000ff>#include <GRAPHICS.H>; |6 D/ R( L( W! }# s5 |
#include <STDLIB.H>( [4 p* E) G" t3 N5 T9 _, [
#include <STDIO.H>" y2 j. T% c/ \$ W
#include <CONIO.H></FONT></P>7 e& {! F: ~7 g: e$ `
<P><FONT color=#0000ff>int main(void)
3 F  y2 k2 Q  H6 U* }{ : P2 _' q* s4 `
/* request auto detection */ : @# L0 m: f) ^5 `% l
int gdriver = DETECT, gmode, errorcode;
: K+ L! ]# L4 g1 Y, m7 C" B' A: f( nstruct palettetype pal; % Y0 _, n& _% o: b! p
char psize[80], pval[20];
9 R* e5 ?; q; Rint i, ht;
5 W* h! I: [0 a6 I* xint y = 10; </FONT></P>$ j# J9 U% a3 h: K$ `5 v: @3 V" u; @
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; e) ?$ P* w" l4 P( V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 M% g9 i+ v$ _* I1 l$ u- M
<P><FONT color=#0000ff>/* read result of initialization */ 8 Y' m) U- o. E: [# d) Q( i
errorcode = graphresult(); & O$ l5 q+ ^4 \4 g  w' h( X
/* an error occurred */
2 k2 o! [, a. S3 [" k6 jif (errorcode != grOk)
4 I3 C# _, \1 I{
# {6 ~; ^+ I7 `, V7 C7 lprintf("Graphics error: %s\n", 2 W% H+ \. D6 f$ d: ~- g
grapherrormsg(errorcode));
) L3 U/ L; S9 Z  X0 dprintf("Press any key to halt:"); 6 r  H; v! v. u( G. y
getch(); , N9 A; l! L( @
/* terminate with an error code */
6 e- B0 y7 I, v) nexit(1); # R7 }# u$ u3 G  e) X
} </FONT></P>% \$ Q& ~) ~! ?2 [$ l
<P><FONT color=#0000ff>/* grab a copy of the palette */ - |9 R6 s! S2 _4 A! k; b% c
getpalette(&amp;pal); </FONT></P>
9 X' m5 K7 {$ d- P1 K<P><FONT color=#0000ff>/* convert palette info. into strings */
. h8 ]7 h1 u, X1 `sprintf(psize, "The palette has %d \
7 q0 E' n& f$ d& Amodifiable entries.", pal.size); </FONT></P>
9 I8 j, P* [/ a* O<P><FONT color=#0000ff>/* display the information */
; Q" ]9 [6 G* j& ~8 p$ V/ @# C- vouttextxy(0, y, psize);
1 O  O9 Y. [  h4 \. d' qif (pal.size != 0) ! h& X' z& i3 S4 |
{ ) f6 _7 p  _4 y& H# S: N. K* A
ht = textheight("W"); 0 ^4 @- c# j* B) p
y += 2*ht;
$ x3 S+ e8 e5 s! ~& B* Routtextxy(0, y, "Here are the current \
' E2 ]7 y! d* w+ l' @# z) Uvalues:"); & M& h, ^/ A" P3 W2 B' m" ?8 V6 R8 C
y += 2*ht;
$ A  V: [" h( o- u$ f) f8 G! d0 {for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { , a0 {1 K- A) X
sprintf(pval,
7 Z$ w& H4 C" S"palette[%02d]: 0x%02X", i, 0 a1 M! g. d) k- V) k( r6 b; r
pal.colors); 5 q; n; K4 s) y. g
outtextxy(0, y, pval); ; r4 D3 ?: m3 c
} + P6 d# ?, L8 i2 i- ^
} </FONT></P>$ M2 ?% d  \* w  [
<P><FONT color=#0000ff>/* clean up */
/ s, d3 h* e( d, O9 P! V# x: e7 Vgetch();
! o# M4 Z" c" ^: D% ^/ K, X# I) iclosegraph(); </FONT>! U/ ]7 b& T' m, T7 x
<FONT color=#0000ff>return 0;
: ~' J3 l. u$ \( B- T/ I}
" J0 Z+ E& [: V. s+ @" U</FONT></P>/ [  F* v( v4 u; X* e+ A8 a
<P><FONT color=#ff0000>函数名: getpass </FONT>% J% X& Q+ Q' u0 y! F! e. W
功 能: 读一个口令 ' }8 I  J& [1 y# N2 U$ S5 Q  @. s
用 法: char *getpass(char *prompt); + h" e1 }0 E  d+ P! w# U
程序例: </P>9 u" Y% W( e- \  v  X) [2 _, @7 u
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>: ^8 I' P" @2 s% i; U! N
<P><FONT color=#0000ff>int main(void) # l- T1 o7 ]" c- [9 Q* o- V; W
{
& l* Z! e4 T4 i7 ~6 @! Ichar *password; </FONT></P>) }9 m: @6 B! N( }# h
<P><FONT color=#0000ff>password = getpass("Input a password:"); ! t) L3 N. U1 x6 \* e
cprintf("The password is: %s\r\n",
! r; R2 `+ s) m0 bpassword); . {* U" X& l3 W) p) m
return 0;
0 o0 u1 S+ o7 j0 A3 y} . B3 P4 U' X7 {" L5 h" }
</FONT>, u5 z. G! r/ z2 B, G
. d5 z* v6 b5 t6 S! A" B
</P>$ ^. o5 l; ~* c
<P><FONT color=#ff0000>函数名: getpixel </FONT>
8 D! s# W! R6 R' y: C2 b5 s功 能: 取得指定像素的颜色   ?+ H, b$ V( C$ V
用 法: int far getpixel(int x, int y);
$ L# j+ V3 U" ^/ Y9 r1 }  E& v' P/ A程序例: </P>
1 y# B1 k# l& ?! U4 l) E<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 P3 q; b) N2 Y( c0 [#include <STDLIB.H>* J( U+ u) {, E
#include <STDIO.H>7 v* S& w$ J1 I: b9 j. _5 |
#include <CONIO.H>
; }. T  H- b9 Y$ C9 r, X# D#include <DOS.H></FONT></P>
. f: h: I4 I# X, L) [+ o/ {<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
. x. p, X4 {8 N- t( S8 ^- R#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>. s+ g: J+ f; b) D8 G& B
<P><FONT color=#0000ff>int main(void)
- K7 J5 W) I) f: }: b, z# u5 H{
0 C- @" T6 |0 O/* request auto detection */
4 J% w  ]2 O* bint gdriver = DETECT, gmode, errorcode;
' w* C$ `5 Z  x2 q- j$ A/ }int i, x, y, color, maxx, maxy,
2 s3 e+ Z4 `. o% \9 [1 Imaxcolor, seed; </FONT></P>
- Z; N8 L2 _$ E$ |<P><FONT color=#0000ff>/* initialize graphics and local variables */ * c- j9 I% n: G+ H8 U' o/ W
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; N6 F( v' @3 c. Z. d1 @- }. R<P><FONT color=#0000ff>/* read result of initialization */
4 `7 ?$ Q5 y( Q7 ~errorcode = graphresult(); 1 v/ @( h& R6 K3 u
/* an error occurred */ $ x7 ~8 O9 @: W, o* G4 `/ [
if (errorcode != grOk) $ e: t6 P6 z. R  N4 o
{ ' Q8 A$ i2 F1 ^( T) Q+ W9 @
printf("Graphics error: %s\n",
5 c+ c2 D7 g. s  j' ~0 Dgrapherrormsg(errorcode));
/ o6 m# e5 Z0 l% `3 U8 bprintf("Press any key to halt:");
, z# ~8 i7 F8 l' Bgetch(); / G6 V/ m0 [0 B
/* terminate with an error code */ 5 F: E0 Z9 K- U9 y) q- @
exit(1);
1 i* c0 v+ f, M' x* g! p} </FONT></P>  u2 ?2 m9 {/ H9 p5 O6 w
<P><FONT color=#0000ff>maxx = getmaxx() + 1;
1 `5 X8 d* Z! [- Q8 A" M. j( Kmaxy = getmaxy() + 1; % a- l5 j1 V, x  l1 d  Y
maxcolor = getmaxcolor() + 1; </FONT></P>
4 p/ J" [& E# b<P><FONT color=#0000ff>while (!kbhit()) . @: s  V$ W+ _
{
7 V3 z) L% {7 l7 Z9 j/* seed the random number generator */ % R2 |1 k8 ^' R, w
seed = random(32767); ' v9 x) R9 o$ `% S2 X: u* n( T9 e
srand(seed);
! x( A& Q! z8 Jfor (i=0; i<PIXEL_COUNT; <br i++)> {
1 Q9 G- \2 y$ K+ t( R" n6 Nx = random(maxx);
5 U" k( c; `6 v# Z0 G8 L0 xy = random(maxy); + N4 L4 G, Q7 l: h/ L) c+ v
color = random(maxcolor); . A8 f6 B7 C8 A2 r
putpixel(x, y, color);
9 M( p/ l4 H/ P8 u4 T} </FONT></P>
( I: y* }5 t& j+ W5 A$ J$ Z<P><FONT color=#0000ff>delay(DELAY_TIME);
0 E/ J; s1 H! ^2 C3 m1 M1 Fsrand(seed);
: I& \, z( ^# Y' dfor (i=0; i<PIXEL_COUNT; <br i++)> { ' q$ S) m+ W, g6 A$ H) A/ l7 x: l
x = random(maxx); + t0 }6 Q5 T: l$ A, K. y
y = random(maxy); * V7 e1 }4 I% c6 D- E
color = random(maxcolor); ! F" B3 ?. Q- S
if (color == getpixel)</FONT> </P>
" O; `- [; i$ k<P><FONT color=#ff0000>函数名: gets</FONT> / B; w& K0 ?% d+ D) C# k- T
功 能: 从流中取一字符串
( U. I- S. F" {& s. [0 O用 法: char *gets(char *string);
( S1 j& ~; b( ~3 x( w程序例: </P>
- }- }& @* ]  M! r" q4 i3 E" h<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
1 P7 T  k# g0 Y% T/ ~8 {) x<P><FONT color=#0000ff>int main(void) 8 y3 t9 z3 |) B3 t8 y6 A
{
; ^' C8 r) y0 ~, p( [/ I9 Wchar string[80]; </FONT></P>" o3 q! m- }, d$ Z/ i  U% u) L# y
<P><FONT color=#0000ff>printf("Input a string:"); ! E7 w; l7 E+ R
gets(string); $ J% _2 R0 @/ c' m6 e
printf("The string input was: %s\n", ; \* R7 S$ {9 a" [5 r( C6 `
string);
/ H4 I0 x8 f: }. R/ m: o/ Creturn 0; ! v: D$ J. J0 h  E6 D
}
" n, B  {* N+ i2 h7 l# w8 r# A
3 @7 e! s2 G; ]3 l* \! L4 A</FONT></P>
2 |: ?6 W" ^5 Q<P><FONT color=#ff0000>函数名: gettext </FONT>
+ _9 f6 C, E- }. u) H功 能: 将文本方式屏幕上的文本拷贝到存储区
+ D( X- w. F2 ?+ I用 法: int gettext(int left, int top, int right, int bottom, void *destin); % H' G3 P: H' S, j1 o
程序例: </P>
9 V: _' I0 e, h9 G<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
% Q/ D5 ~7 l2 ?. j, ^/ k<P><FONT color=#0000ff>char buffer[4096]; </FONT></P># b. w4 h. Q. r, B- F
<P><FONT color=#0000ff>int main(void) ' B# k6 q9 S4 Q) H, \* t: g" Y
{
8 D# \6 x: M& H6 }) e4 w( z, Vint i; ) j9 D2 f6 u, r- D
clrscr(); " U2 a8 Y, p* g
for (i = 0; i &lt;= 20; i++)
1 |4 K8 v! \' Z9 u$ icprintf("Line #%d\r\n", i); # G% n3 T; C$ y" r
gettext(1, 1, 80, 25, buffer);
7 k7 I9 m5 ]( y; N  O, A( J9 igotoxy(1, 25); 6 f$ q9 b' u6 s% `! F5 q! F
cprintf("Press any key to clear screen...");
, I/ o8 a, U2 Dgetch();
/ H6 f9 \4 P0 i! Oclrscr();
2 B+ ~' k, o. j- ?% A; s. Wgotoxy(1, 25); 7 ^7 z1 U! L" i6 g+ y( R/ W- d
cprintf("Press any key to restore screen...");
8 }' q: \: `( x( Jgetch();
- _; g; h5 d( o! _5 t. Mputtext(1, 1, 80, 25, buffer); / _. w" H' n5 Y: J7 m
gotoxy(1, 25); 9 l0 a, _' S4 E  @/ D+ H. e3 q
cprintf("Press any key to quit...");
) K0 K* V; h$ t! u) P1 ^1 bgetch(); 1 `% }) K5 z( O0 X9 p* v3 E- h
return 0; ( ~) M0 w" i) a+ L
} ; d" ?8 @  X; _3 N
</FONT>
+ n; e+ W" W3 b0 {0 _! [</P>; N& j. b; v2 }% y: K5 Y! Z, B$ F
<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
9 \) G- w' u+ K7 B功 能: 取得文本模式的显示信息 $ o3 K+ K4 l4 o. u* A4 f! z
用 法: void gettextinfo(struct text_info *inforec); ( o; \% y& Z* w) N- W+ ]
程序例: </P>
# y! A7 ]7 K$ h2 |<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
0 L5 q$ I6 X2 c& J  y3 N3 n% P<P><FONT color=#0000ff>int main(void)
( Q3 u& h* }: k: H; c2 a{
( i) D+ n( @9 wstruct text_info ti;
) e  t5 j' s, Bgettextinfo(&amp;ti);
6 F9 Y; ^+ ]$ S1 e8 ecprintf("window left %2d\r\n",ti.winleft);
. s% P; v  H+ q- B8 X" I- }. vcprintf("window top %2d\r\n",ti.wintop); - Z8 W, O( G, L0 R5 l0 Q
cprintf("window right %2d\r\n",ti.winright);
$ `* e' s9 ^2 w+ S7 Ecprintf("window bottom %2d\r\n",ti.winbottom);
' l' k7 \2 B9 {5 n; h7 w; pcprintf("attribute %2d\r\n",ti.attribute); # m9 q5 ^# l) M5 s
cprintf("normal attribute %2d\r\n",ti.normattr); 1 o! S+ Z6 I* R" L0 r
cprintf("current mode %2d\r\n",ti.currmode);
) @5 T( y; `/ L& C4 Rcprintf("screen height %2d\r\n",ti.screenheight);
0 D0 f% \. T7 @( C% ocprintf("screen width %2d\r\n",ti.screenwidth);
$ }; {1 Q" b1 j7 Ecprintf("current x %2d\r\n",ti.curx); 5 C1 P( k& s; u$ w: g+ b, c
cprintf("current y %2d\r\n",ti.cury);
0 y+ }0 E) |" I3 [5 F5 sreturn 0;
& N* V1 `% h. j' K7 d8 @+ m* S- M1 q} ) c1 h- f" F& V! }0 a  r* Z
</FONT>2 Y, q- K% g; M9 d) v+ h% l& N5 E
</P>
8 C  D9 k* e8 t9 _/ [; ?7 F- E2 M<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
4 S/ B' h# m. s6 E  i  @6 m9 c功 能: 返回有关当前图形文本字体的信息
" f; t/ A' q& _1 J# k用 法: void far gettextsettings(struct textsettingstype far *textinfo); / @6 h& A. p, T) V; N9 k! V
程序例: </P>" z" G" p; w& P8 R
<P>#include <GRAPHICS.H><FONT color=#0000ff>8 Q, _) {  j4 W- X! h3 G* Y3 U& [. u
#include <STDLIB.H>
( Z- Q7 f- `8 A' c) P#include <STDIO.H>
) h6 c) A+ ^/ m6 W+ g6 G) B  ?#include <CONIO.H></FONT></P>
: s- _; D+ p$ w+ g<P><FONT color=#0000ff>/* the names of the fonts supported */
0 p  v( F: _+ u7 Wchar *font[] = { "DEFAULT_FONT", ) [# H/ c! W. t: U
"TRIPLEX_FONT", 9 }7 h% ]1 B. P$ @5 n: m" [
"SMALL_FONT", # t+ G( O. l( Z/ T4 [
"SANS_SERIF_FONT",
8 v0 s! Q. X+ f"GOTHIC_FONT"
7 U( |  n  R! ?/ v# D2 M( V+ A}; </FONT></P>
- j# y# f: {" \/ S4 X/ O6 R6 `<P><FONT color=#0000ff>/* the names of the text directions supported */ 8 ]* b; W9 {4 G% p' i4 g, _: A
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
! A0 L+ p' }  T3 J<P><FONT color=#0000ff>/* horizontal text justifications supported */
4 V* x# e- O) Jchar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>7 ?, `! }9 d# A% l, P( v
<P><FONT color=#0000ff>/* vertical text justifications supported */ ' B7 C# U1 u% r5 E2 Z
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>8 y0 ~9 c5 }7 q. _* ~. i
<P><FONT color=#0000ff>int main(void)
2 ?# ?- O" d5 O. u( u{
# }1 o( j# S6 _; f/ P8 O4 V# j/ ^1 P/* request auto detection */   n! ^: i+ Y8 W& O9 X
int gdriver = DETECT, gmode, errorcode; ; H1 v" B6 H6 j' C" [5 B7 z4 P
struct textsettingstype textinfo;
8 M  [% L) M% ?3 a7 xint midx, midy, ht;
1 p8 W* r& z$ V+ K! S1 f1 wchar fontstr[80], dirstr[80], sizestr[80];
9 v; N4 x6 C6 N, R; |char hjuststr[80], vjuststr[80]; </FONT></P>4 K1 z  V) `9 ?0 t  c1 S
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 \0 s* x. u; P) M
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ U4 v$ M8 G& l: U0 e8 `<P><FONT color=#0000ff>/* read result of initialization */
* r$ ^3 S( R* @7 U$ berrorcode = graphresult();
2 o$ \. X8 R7 U! p" F: C" Dif (errorcode != grOk) /* an error occurred */ ! G3 _9 I" I1 I
{
4 [4 p3 F( {3 T1 l2 N# t4 l8 pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
9 U* d- |9 P% w$ C" l" Z; }printf("Press any key to halt:");
0 p' w! s9 ~# P) fgetch();
* G: W9 J; F$ h( eexit(1); /* terminate with an error code */ , y3 U% E& k" }+ R& R6 N) S2 _' E$ O
} </FONT></P>; ~9 {& N- D" t) G1 S: X  n
<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 t" B3 s5 o3 E" s1 }$ Y# j; A/ Qmidy = getmaxy() / 2; </FONT></P>" x2 r+ @# r9 c3 k& P3 i
<P><FONT color=#0000ff>/* get information about current text settings */ 2 f9 U! M- z4 i5 [% P- L
gettextsettings(&amp;textinfo); </FONT></P>- U$ q' o+ s3 D5 \1 D& w* Y
<P><FONT color=#0000ff>/* convert text information into strings */
$ U; R+ F9 E& G- t: Csprintf(fontstr, "%s is the text style.", font[textinfo.font]);
' C/ V6 [5 N3 ^6 H$ A# W$ R9 @sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); ; h3 i0 h$ V- ~& n0 F
sprintf(sizestr, "%d is the text size.", textinfo.charsize);
( y$ X0 v: r, Csprintf(hjuststr, "%s is the horizontal justification.",
8 Z1 ~2 H% \3 Zhjust[textinfo.horiz]); 7 G' X( ?- o) s) n- w* b" c
sprintf(vjuststr, "%s is the vertical justification.",
  u0 a+ {, D4 E' a" o1 J  |vjust[textinfo.vert]); </FONT></P>+ Z1 w& C+ I; a- ~* B
<P><FONT color=#0000ff>/* display the information */ / e% `# x* h( }3 K% J
ht = textheight("W");
0 K4 r7 A# l$ ssettextjustify(CENTER_TEXT, CENTER_TEXT);
9 X5 V( @  s4 Z, @outtextxy(midx, midy, fontstr); : C5 G  {; Q% U; V9 @
outtextxy(midx, midy+2*ht, dirstr);
+ O4 J, I0 h( }2 i6 J, [& Aouttextxy(midx, midy+4*ht, sizestr); : f2 _( T% Q- a7 {
outtextxy(midx, midy+6*ht, hjuststr); : B! V+ c! E+ Y8 P5 n
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
% V$ f& {% F1 @/ H9 r<P><FONT color=#0000ff>/* clean up */ 9 O( A$ L/ _( t& V/ ?8 T
getch();
) @9 `6 D- d& e( I6 G# `5 Lclosegraph();
. [3 w# X1 v3 T! Y( i3 \2 Q# m8 z& Xreturn 0;
- S. S. ?, c& f' c+ T3 `1 t} </FONT>
/ x- j) V, P+ I1 u8 d</P>
0 a/ ~% i6 ^4 n( c$ l<P><FONT color=#ff0000>函数名: gettime </FONT>. p$ z( w6 K# B( y4 M9 y, C  `
功 能: 取得系统时间 ! L& Y6 S" q  ?0 d' Y: Y/ F
用 法: void gettime(struct time *timep);
" J% j/ e  t0 X; y, j: P' C8 b. d程序例: </P>
& s' z7 L3 d4 U8 E1 l/ n1 @<P><FONT color=#0000ff>#include <STDIO.H>, p! t6 X9 ^7 R+ ?
#include <DOS.H></FONT></P>/ m- V: D, w  K, @
<P><FONT color=#0000ff>int main(void) ( [: d1 l6 t7 ^
{
0 C, y) o8 A) C9 p; i$ Mstruct time t; </FONT></P>
6 j. |5 c. |; U/ a1 ]<P><FONT color=#0000ff>gettime(&amp;t);
  `. @0 h6 d& Y+ ^' }+ `printf("The current time is: %2d:%02d:%02d.%02d\n", ( ^/ n6 A/ x2 r  T
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
  o; U) v, X+ o: T7 sreturn 0; $ f5 O9 Z8 N) h0 Z; T8 V
} 7 I/ i" L8 e0 Z% B4 K. m

! f. P- x% E' |# k1 t) D$ _</FONT>
" g& Z- @- p+ p9 c</P>
0 P3 ?1 Q8 x% O. e<P><FONT color=#ff0000>函数名: getvect </FONT>2 @# X" J* L: h! M6 c# Y; D! ]
功 能: 取得中断向量入口
$ G6 h: a. e7 D2 W/ m' K用 法: void interrupt(*getvect(int intr_num)); . A; b7 ]) u! n2 U
程序例: </P>
: J  C* i1 b/ d# ?5 R<P><FONT color=#0000ff>#include <STDIO.H>8 F0 B1 C6 z  Y  C3 Y
#include <DOS.H></FONT></P>5 P$ X: n0 q1 M3 Z
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
6 z8 S) N. ]' a5 i; z<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
9 S3 {2 {3 K7 m  d( ^( ^6 q; vint looping = 1; </FONT></P>
, ^6 S% O+ ?* [" `2 w; |<P><FONT color=#0000ff>int main(void) 6 E  Y. \  F. a$ G% ^) a
{
; L! H- v1 b) q) j& d  Mputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
  W7 r  d9 `% h( y+ `% Y0 ^<P><FONT color=#0000ff>/* save the old interrupt */   m; j1 W5 S* q2 ?5 ?
oldfunc = getvect(5); </FONT></P>
( S1 p7 @! I- A<P><FONT color=#0000ff>/* install interrupt handler */ & c% m% ]- a! e5 p" `9 f
setvect(5,get_out); </FONT></P>
; ]* W: x5 c1 J+ `, P( {<P><FONT color=#0000ff>/* do nothing */ 9 N/ I% X" e# D& `
while (looping); </FONT></P>
8 u) M  J% |  Y9 N/ o; ~8 k4 m<P><FONT color=#0000ff>/* restore to original interrupt routine */ ' S5 p7 v; g0 M/ B" t* D/ f
setvect(5,oldfunc); </FONT></P>6 G0 W4 P: r$ Q6 q
<P><FONT color=#0000ff>puts("Success"); * }, N5 {1 t" M8 R9 A0 ^8 [
return 0; & m  i5 W2 g( _9 F3 e3 m0 s
} / ^2 |6 X/ v. i9 ^  L
void interrupt get_out() ) O* f2 c1 {% s
{ + D4 {% T6 H6 G( t; `
looping = 0; /* change global variable to get out of loop */
. W$ F8 ?% P7 M7 F7 A3 V% R} ! |% v  d) _  u/ y3 B
</FONT>+ X% J9 n. o$ |$ F- S0 k
</P>
5 e- C- N2 ?2 h8 K% m<P><FONT color=#ff0000>函数名: getverify </FONT>
' S' |# d. Q& k' Y: O$ ?7 K功 能: 返回DOS校验标志状态
9 l+ S1 D4 S+ P. k& z) I5 V用 法: int getverify(void); 9 v. b  g( M( I# G# B' q4 X
程序例: </P>
! H$ P( F* D0 E8 o( a<P><FONT color=#0000ff>#include <STDIO.H>
$ b7 ^3 m$ r) F8 q/ t$ B$ j#include <DOS.H></FONT></P>
3 R% f! F2 p: Z9 j: d2 {! c<P><FONT color=#0000ff>int main(void) : E" f5 b6 L! i# c3 s& q
{ , @3 U& w. P  [' Y0 a3 V$ o
if (getverify())
/ G& V# k( y( }# Nprintf("DOS verify flag is on\n"); 3 f: g, M" g/ y/ d; ]3 S  m8 P
else
' U) m) A4 m& gprintf("DOS verify flag is off\n");
  Z# }$ G4 ?/ S* I; l) d0 ^return 0;
- u- }: o: ~1 ^  Q}
. O" i7 N6 b' p! _, \! }" x! i- H</FONT></P>" j9 S$ g- l! u/ v3 V
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>4 m6 w  T, G1 E2 G! Q5 G
功 能: 返回有关当前视区的信息 # Z3 U2 U( v9 U6 z* [- j
用 法: void far getviewsettings(struct viewporttype far *viewport);
3 {1 B" R& J/ X/ D" @% T程序例: </P>
' b  f8 w. ~: G- r9 K  X<P><FONT color=#0000ff>#include <GRAPHICS.H>/ N/ H' i4 z, ]5 w
#include <STDLIB.H>7 E9 r4 S8 v, H6 n0 m$ A
#include <STDIO.H>; r+ q! @6 N# T% q
#include <CONIO.H></FONT></P>
. B* w- T/ ]7 M7 C' O/ ?<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
* U0 z* H$ X, q! c<P><FONT color=#0000ff>int main(void)
" i" p* ^: T! _3 B9 a{
7 ~, B! e' I3 b/ C6 \( j/* request auto detection */
. W2 \. y' v/ G* ?int gdriver = DETECT, gmode, errorcode; 1 i" ?4 i* o' s8 ^7 K9 b9 H+ J. d- o
struct viewporttype viewinfo; 2 a: r% ^: c, t
int midx, midy, ht; 1 `. A, }; j% W! s$ D( d
char topstr[80], botstr[80], clipstr[80]; </FONT></P>7 \( d! o, i0 s, v9 }
<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 }) I* c. d/ G, finitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' D8 X$ v" x5 ?5 L, S7 `9 ]- g4 }; u; f
<P><FONT color=#0000ff>/* read result of initialization */ 4 T4 ~1 _; `2 U; O5 G6 j: r8 R
errorcode = graphresult(); 9 J" {( }- g) X
if (errorcode != grOk) /* an error occurred */
/ C5 z' ?. z' e) U! ~{ 1 _" F! k8 |" Q2 Y+ n
printf("Graphics error: %s\n", grapherrormsg(errorcode)); & K0 k1 }0 Y5 a( I* d) E) _$ a! K- @9 B
printf("Press any key to halt:"); & {# |: P* y8 o4 i8 E
getch(); " b# z4 d9 J' k
exit(1); /* terminate with an error code */
& c! B# A( d- N" l} </FONT></P>8 i/ v# w0 ]5 h  u& c# Y& X
<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 l6 s" o# V# `$ N, d7 X* O2 xmidy = getmaxy() / 2; </FONT></P>: D' K7 L1 V% |
<P><FONT color=#0000ff>/* get information about current viewport */ % [0 `4 ~& \3 c9 m3 e* Z) Z
getviewsettings(&amp;viewinfo); </FONT></P>
9 I, ^4 Y/ Y6 R# U<P><FONT color=#0000ff>/* convert text information into strings */
8 q2 g: Z' A9 E$ j# G. N5 Qsprintf(topstr, "(%d, %d) is the upper left viewport corner.", ! ?0 `1 f# @; L5 x8 k* u
viewinfo.left, viewinfo.top);
9 i$ v* ?: k- vsprintf(botstr, "(%d, %d) is the lower right viewport corner.",
% _: J- a7 O0 V$ N9 w4 wviewinfo.right, viewinfo.bottom);
) E* w2 I! _' Wsprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
6 J: q" Z: o1 D7 ?<P><FONT color=#0000ff>/* display the information */
: s9 a& _9 w$ I( W' L3 I' Vsettextjustify(CENTER_TEXT, CENTER_TEXT); * G9 D2 I4 I9 w1 a6 Q
ht = textheight("W"); $ I8 [6 X  W. \, e
outtextxy(midx, midy, topstr); . N+ ~5 a8 ]4 {, b
outtextxy(midx, midy+2*ht, botstr); $ J4 ^6 ~. e- E* @
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>) N+ ?5 @2 G  P. g
<P><FONT color=#0000ff>/* clean up */ 1 W8 \$ G8 H: @" F  s
getch(); # n( g2 j- ^4 `# s& @
closegraph();
- @# e$ O$ E4 Xreturn 0; 1 x' |) |) r2 y5 b# [
} </FONT>
7 v3 I* B& h, \- E: _$ `
- A$ ?: n6 i' q+ {. O</P>
2 S! \% [2 F: Y) Q" a- M% b<P><FONT color=#ff0000>函数名: getw </FONT>$ E$ y1 O7 z* m
功 能: 从流中取一整数
9 C- ~, r9 K3 N  ?1 h7 o9 r用 法: int getw(FILE *strem); 1 b- s8 v% L6 H6 Z( }' V, D+ M# x
程序例: </P>7 V/ G/ Z! F6 O! y7 ]
<P><FONT color=#0000ff>#include <STDIO.H>: {, J7 J" c  P% p- t3 D& b8 o
#include <STDLIB.H></FONT></P>
6 N  b" m" r5 ]2 h$ b/ n<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
* z9 I7 ?. }/ G$ E<P><FONT color=#0000ff>int main(void) * f6 U0 _" T/ h; h. {
{
% O! A0 I; r: \9 ^* X+ HFILE *fp; % J& |8 _4 F' E" S1 o3 Y
int word; </FONT></P>
. M9 H+ ~: [$ [0 w6 Q( L: Z: j<P><FONT color=#0000ff>/* place the word in a file */ ' K5 \2 r6 u* S& j+ w$ h# o
fp = fopen(FNAME, "wb");
# _' t' Y; a3 O' X# m+ aif (fp == NULL) 0 {# b4 N7 r2 P8 u$ [6 v( P3 P! \
{
; P$ p7 t3 ?; h3 m# A1 Y$ mprintf("Error opening file %s\n", FNAME); & w2 Q7 d' b& N; a+ J6 L: N' j
exit(1); $ M- e' [5 h, k1 }' l- x
} </FONT></P>1 R. d$ y* [1 v1 t
<P><FONT color=#0000ff>word = 94;
2 G) ^, v# s! l, o: s& `9 oputw(word,fp); $ d$ B* {% ^& @2 u& @& b0 e
if (ferror(fp))
& A- C$ |$ h, d; G: @( @printf("Error writing to file\n");
, {* D" v. i  G0 y0 {1 \- ]- E5 Gelse + a9 @# @3 Z' K
printf("Successful write\n"); 5 ]; p/ b- o/ U7 E( ]' d3 O
fclose(fp); </FONT></P>
9 g- Z9 E# ^% Y$ h) ?<P><FONT color=#0000ff>/* reopen the file */ 7 E( x8 V  [7 }! n: k: E
fp = fopen(FNAME, "rb"); 3 Q; j0 e/ ~$ z; }
if (fp == NULL)
7 v9 F  F* j6 V& J- E0 Y{
$ d# g: g/ c+ {6 {9 ~printf("Error opening file %s\n", FNAME); 1 t& B; a3 m' e$ r- G. ~4 A
exit(1); 5 }/ }8 q  D8 P3 G+ @' a# p
} </FONT></P>
4 y3 `& h9 X7 ?4 F$ v) d0 @3 H<P><FONT color=#0000ff>/* extract the word */
. B1 m( G: i) |2 N: P5 jword = getw(fp); 6 s8 u, c8 m) o' r# T# G/ q; u
if (ferror(fp)) + ?) V; r: C( e+ S2 ?7 `  E3 k
printf("Error reading file\n"); ' N+ T7 L6 @/ x. A. C' U, w
else
* R# x2 j3 w3 Qprintf("Successful read: word = %d\n", word); </FONT></P>
. K9 e. x/ C- z, q' N) A: S& H<P><FONT color=#0000ff>/* clean up */ : \& Q0 p2 T+ ^. o
fclose(fp); & |# O4 p- X; h& H$ P
unlink(FNAME); </FONT></P>
4 o% g8 T; F( i& ]& ~<P><FONT color=#0000ff>return 0; 3 L( l  ?4 P3 F% s# u  v# b
} </FONT>, g+ N9 F$ l, v7 o5 @# D7 b# @. Z0 A

! t; t$ F! t" l1 {6 Z$ p0 u
) E- [8 E/ u* g3 B( k) ^</P>
/ |* l5 k  z4 N  A<P><FONT color=#ff0000>函数名: getx </FONT>: W) a& e3 O1 `# B3 [2 I! z
功 能: 返回当前图形位置的x坐标 ' W5 _" r$ `2 q% a- C1 u% f
用 法: int far getx(void); 0 F+ O8 ~  i0 |
程序例: </P>- n2 c- S" f; }+ Q5 l- u( k0 u) ]
<P>#include <GRAPHICS.H><FONT color=#0000ff>8 p$ F9 f$ M" B- w
#include <STDLIB.H>
6 K% X$ C9 t/ h1 L' U5 S" k" F; ~#include <STDIO.H>
# C* {( s7 o* J4 x$ x' k#include <CONIO.H></FONT></P>: P6 i2 g/ M9 C* Z# h2 `
<P><FONT color=#0000ff>int main(void)
& @- [4 }( q/ Z{
1 v0 A4 y( }4 C) |+ r9 C4 T& Q/* request auto detection */
: _8 _8 V# j" V7 H- F. ?int gdriver = DETECT, gmode, errorcode;
5 q6 y" g) s* B# Vchar msg[80]; </FONT></P>7 a# o" G, P0 d8 L% x1 R' M) ^
<P><FONT color=#0000ff>/* initialize graphics and local variables */ % K4 G& a! o2 D5 s6 C3 J$ V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; P9 _) w  g, {; B$ H<P><FONT color=#0000ff>/* read result of initialization */
) a$ }# ^( E1 [3 Qerrorcode = graphresult();
7 w2 m7 \6 G0 E% p! Z- Q# c% Q& I# pif (errorcode != grOk) /* an error occurred */ " J% y* F* m1 [$ J
{
4 a( p) V: z3 [/ C* t7 mprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 i) w! g% L# W% f: x# w- M4 Hprintf("Press any key to halt:"); * s# h+ U# ~* l
getch();
' ?) I0 d& t- y. @exit(1); /* terminate with an error code */
/ V( o, X) h* G2 J/ G4 J3 @' L} </FONT></P>5 N3 ^% M$ D, N! u
<P><FONT color=#0000ff>/* move to the screen center point */
, y$ `# i3 j+ o$ amoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>* }9 r+ B3 `+ h& i: D4 `! Z$ Z
<P><FONT color=#0000ff>/* create a message string */ $ a+ k3 }* i' Q
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>" ]7 {( P5 K% p. }' `
<P><FONT color=#0000ff>/* display the message */
  r) e  F: i' T7 F* d$ f9 Touttext(msg); </FONT></P>
9 D5 `* K$ B! o# m. Q<P><FONT color=#0000ff>/* clean up */ . P, D7 X/ k  _6 A$ a/ [
getch(); 1 f7 l( X- F: C
closegraph(); 3 v$ A' I. n9 q& J  Q+ X
return 0;
) o! V4 n& E  C4 @" A4 b, ~$ E* S} </FONT>7 U! m+ ]" d7 ~+ Q3 Z) U' Y

& D( r8 U! L+ A2 f</P>
' ]& M# U( h5 Y( H<P><FONT color=#ff0000>函数名: gety </FONT>, l" P' T' F6 N5 o3 \$ ^; S* C
功 能: 返回当前图形位置的y坐标 " B% \" B* N+ G6 v6 R+ W( Y
用 法: int far gety(void); 8 |* ^* ?6 K4 e) t+ [- Y7 A
程序例: </P>2 b& m8 R, ?- S/ r% o
<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 h- k! s; B: _/ V# b#include <STDLIB.H>, k# f* ~- O8 x& [) ]
#include <STDIO.H>- |' h% u: W/ k# D- @
#include <CONIO.H></FONT></P>. ]! V% G# I- V5 s
<P><FONT color=#0000ff>int main(void) ) \* k& ^% y. r; M  T
{ ) }' @+ `8 V, e
/* request auto detection */ ) f+ z% c  @- _( ]; I7 A% Q
int gdriver = DETECT, gmode, errorcode;
6 N( Q; f# E$ W0 x7 a9 ]' cchar msg[80]; </FONT></P>9 h, A6 L$ @* j
<P><FONT color=#0000ff>/* initialize graphics and local variables */ & }: k$ ?( a5 }3 S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' u) x# i. W: f- x' |/ p+ E1 J
<P><FONT color=#0000ff>/* read result of initialization */
6 l( ?! [: H# c" xerrorcode = graphresult();
4 Z! Y% p* h, i  G  @1 I0 kif (errorcode != grOk) /* an error occurred */ 0 k* v2 U" r5 v' g4 P
{
* p9 j9 Z" \5 `7 q6 A7 H& f4 `! oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 t6 F( k. e" q- a% U8 P
printf("Press any key to halt:"); ; p- Q& S% b5 t& I2 p
getch();
3 k1 `7 E6 [' i( Sexit(1); /* terminate with an error code */
  z) d  D. T& \} </FONT></P>
* o+ o) \/ N+ I' h) D<P><FONT color=#0000ff>/* move to the screen center point */ , W, q: R- o4 c; s6 q1 {$ n7 l
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>0 J- S# B# a' `% W. B- t
<P><FONT color=#0000ff>/* create a message string */
$ X% @0 ^9 F! U8 C2 _4 Bsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>4 n" ?* u* u1 T2 Q
<P><FONT color=#0000ff>/* display the message */ * Z; l: C5 H2 w
outtext(msg); </FONT></P>
3 ?! O) |( C0 t0 @5 @9 q( g; [<P><FONT color=#0000ff>/* clean up */ : l: g0 O( ~& W3 _2 t
getch();
+ @& o; I' `2 p. w% [+ eclosegraph();
; {; W. b' r* a( L) Greturn 0;
6 ~4 h+ ]1 f# y" r  }8 `$ i2 S/ {$ Z} </FONT>
/ _- O2 h% k7 O! J/ p- [( `/ X, g& T2 ^& L' _9 o$ r
</P>
0 i, z6 g& |$ c) Z, t$ K<P><FONT color=#ff0000>函数名: gmtime </FONT>- q4 D" |, b  T" }% t6 o$ k
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
  ]/ J3 u- D& {5 k: l( D8 v用 法: struct tm *gmtime(long *clock);
/ ]( r# y6 V& b( r程序例: </P>
/ X3 W, ~, {1 f2 L! U$ m<P>#include <STDIO.H><FONT color=#0000ff>2 [# |8 f- e" l4 X, J  G
#include <STDLIB.H>
1 f) J4 Q# `0 ~#include <TIME.H>
/ ]' @+ }% \, V+ \$ e+ a4 s#include <DOS.H></FONT></P>
. t' M8 E' d8 t5 v1 ~4 M1 O<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
# Z6 k' ]* A* N& ?7 Dchar *tzstr = "TZ=PST8PDT"; </FONT></P>
4 ]& u+ T2 f/ W4 Q7 O9 p8 h8 a<P><FONT color=#0000ff>int main(void) 6 w; Z) r* E) b$ a- B
{
3 h; w8 [5 N/ v( e) ltime_t t; , N0 J! `! G' j4 C6 k
struct tm *gmt, *area; </FONT></P>
6 |, F- F  ^/ ]+ q# L0 r3 T3 g<P><FONT color=#0000ff>putenv(tzstr);
2 N/ C. D; l& Z+ L5 b' ?4 Utzset(); </FONT></P>6 A8 \2 x$ B5 Z4 Q  L2 X/ O
<P><FONT color=#0000ff>t = time(NULL);
* v. D$ ]9 _. ^$ i* T6 S, Larea = localtime(&amp;t);
+ N$ S7 k3 k# S4 Qprintf("Local time is: %s", asctime(area));
. m1 |& c7 h$ }8 g; m9 cgmt = gmtime(&amp;t); / I/ [% M, g7 Z
printf("GMT is: %s", asctime(gmt));
- p9 o% S/ E( {9 x  I. _5 `return 0; , X& [; |% T: \: k: t) h5 d
} </FONT>4 G- j& H5 T- C0 b; M% m

  g" M8 x; a+ k9 r! o% j% s1 |: c</P>
+ D4 g& t0 w3 |3 r5 O9 ~/ Y<P><FONT color=#ff0000>函数名: gotoxy </FONT>( q9 e* x7 j! D2 p
功 能: 在文本窗口中设置光标
1 l8 J2 @- W* w用 法: void gotoxy(int x, int y); ! X$ S5 A) n1 W8 b. X/ o3 O
程序例: </P>
# ]  H+ a4 q7 q1 {( U: n<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>" a- _8 s$ e- w6 L& _# T
<P><FONT color=#0000ff>int main(void)
3 [% C/ \+ A# Z& R! W4 K{
& ]3 C* E0 G8 ^3 w2 L4 Wclrscr();
4 O; Q# o( j# Y4 Mgotoxy(35, 12); : v' C' g) S$ I/ l. H
cprintf("Hello world");
8 q/ ]9 i1 U# d! V1 o2 e8 ^' E, q8 Hgetch(); 0 B- K) j# B0 ~5 n
return 0; 2 g+ N5 R9 o0 N/ a
}</FONT> - c$ O5 c& O$ R4 b! b8 b9 q

7 [9 ~5 j" G2 I( _, u' r$ u</P>
% s: b  E  y: P- K' y<P><FONT color=#ff0000>函数名: gotoxy </FONT>
4 H$ h; N, X/ H) V: {7 L! o功 能: 在文本窗口中设置光标 7 @: ^, Q& B' d7 z( \
用 法: void gotoxy(int x, int y);
% `& y5 `, a; A$ R程序例: </P>, U- Q; k, W; B3 q( n+ H, U
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
) j5 \9 G2 Q4 q0 n<P><FONT color=#0000ff>int main(void)   e2 \8 [* I7 P  H# O2 q+ p9 }. E
{
3 ?7 v+ H; u3 z5 r; L& O" o8 U. T  Nclrscr(); " p/ g0 ?8 @8 ^: P: B/ k+ [5 z
gotoxy(35, 12);
2 Q7 P; W# q2 ]: a8 f, G" Gcprintf("Hello world");
; w' j6 H3 `4 l* |) ~8 P+ Bgetch();
$ V$ y6 d, l" ^6 H% Z3 V' wreturn 0;
6 I, q0 X3 h: D# E( F4 p} 7 a6 O. ^" N5 B
</FONT>. R" J7 P) \6 e, d$ x" v2 T
</P>
1 l1 R; |( o3 q5 r8 {4 f<P><FONT color=#ff0000>函数名: graphdefaults </FONT>, `4 d: ~" h' H9 m* U- J0 K) `1 k
功 能: 将所有图形设置复位为它们的缺省值 2 Q, w) X4 G" j" Q' U1 @3 K1 M
用 法: void far graphdefaults(void);
" X) h& [# h) N. x程序例: </P>
( X' L6 [% z; e# ^6 ^. z% t. U- P<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 I: A/ s$ K! {# Y' H& I) y4 V; y#include <STDLIB.H>% g  m* c0 t) g; v
#include <STDIO.H>( P$ S: u3 f+ p8 u
#include <CONIO.H></FONT></P>, b& f. L* g' x3 x5 B, @% [# ], P5 B
<P><FONT color=#0000ff>int main(void)
3 R' e4 o0 t$ {: S' A{ 4 H6 V6 U- S# G$ d) ]  H* P7 D
/* request auto detection */
/ o, }" h2 z# d8 i' N5 xint gdriver = DETECT, gmode, errorcode;
4 B4 P+ E3 G7 |6 @- D8 uint maxx, maxy; </FONT></P>( f4 c9 P, C& s9 \) y
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' T% V3 c/ b  m7 _7 tinitgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>" }. L: k; k  _  u
<P><FONT color=#0000ff>/* read result of initialization */
; I; w" N$ c# x. {; x/ b$ Y+ kerrorcode = graphresult(); ! d  H- B7 O" C% [) q3 u& i
if (errorcode != grOk) /* an error occurred */ 9 A1 s, t4 \4 p9 I- E; v
{
7 v: \& L1 O. D3 @# K6 W- e2 i6 Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 D- }- R+ V' {" Cprintf("Press any key to halt:"); # m4 U* b2 n9 Q3 B( k6 V
getch();
9 M. q% N* g9 a7 L' Z; f# v6 b: Uexit(1); /* terminate with an error code */ - C: S% c; `- Z; W! h- n1 ]
} </FONT></P>
' S( F7 ~: P3 f# ?" S- A* x/ h* M3 M2 V<P><FONT color=#0000ff>maxx = getmaxx(); 3 A1 i4 _# z; `" w& G! V
maxy = getmaxy(); </FONT></P>/ X' T7 G: \  S! e: F, Q
<P><FONT color=#0000ff>/* output line with non-default settings */
+ h; p3 f/ `; b% V/ K$ esetlinestyle(DOTTED_LINE, 0, 3);
5 g0 c* y3 b& S- Z6 rline(0, 0, maxx, maxy); $ y& o" \  N4 l' X8 n- l& N4 g
outtextxy(maxx/2, maxy/3, "Before default values are restored.");
0 e# Y, J7 I8 [% F* m) ]4 zgetch(); </FONT></P>
5 K+ r0 Q) G, N4 A4 n5 r: A1 X<P><FONT color=#0000ff>/* restore default values for everything */
5 b+ \7 H( a2 z9 zgraphdefaults(); </FONT></P>, j$ S% y- ?9 P4 ?2 m
<P><FONT color=#0000ff>/* clear the screen */
# \0 A+ b2 y9 Tcleardevice(); </FONT></P>
# b- g, \8 D9 _- n; w- d<P><FONT color=#0000ff>/* output line with default settings */
6 {& D0 y  f# {5 ]# jline(0, 0, maxx, maxy);
$ q" K5 |* A2 n7 I" ~* J0 [* Routtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
1 Q& r7 A0 Q9 }. c  H  N<P><FONT color=#0000ff>/* clean up */
6 [- |4 ^7 c4 X: @' V& b: Wgetch(); 5 i: S$ \$ q$ Z  f, h- \
closegraph();
) ^. i: o0 C  u, M: u) mreturn 0;
0 {  N0 N$ v: @0 \% Z5 M6 @}
% @5 {9 B# D$ `. d$ ]) z</FONT>
# s  a9 L$ p, y; \) J: S</P># r( h5 G2 }* k( Z- j
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>
0 i, \$ ?$ P4 W. f5 |, M功 能: 返回一个错误信息串的指针
$ n. ^# ]/ U/ C$ H( l5 O4 n用 法: char *far grapherrormsg(int errorcode); - s  t7 V, ]1 n6 U- V
程序例: </P>
4 a( `5 N- G3 Y7 j# {* b<P><FONT color=#0000ff>#include <GRAPHICS.H>
& i8 S# U$ \+ z* L2 [#include <STDLIB.H>
7 H' G; O& y) S" G( ]1 V#include <STDIO.H>
5 ]) f, x. R) ^$ p) V7 ~. b8 F( ?6 N#include <CONIO.H></FONT></P>
8 R0 V2 e" ?. W- v<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>9 s4 v5 {9 k) V  R4 X' W1 E. x, x+ z
<P><FONT color=#0000ff>int main(void)
) E0 @# l$ c( f{
. M; e, k- B9 k% o/* FORCE AN ERROR TO OCCUR */ 1 x1 F6 s2 z/ o5 R  I( O
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>, a* S4 r6 `- _5 v9 c, @/ C5 F- P
<P><FONT color=#0000ff>/* initialize graphics mode */
* _( e" A/ a1 _. B8 u, J& jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; n$ Z* i; M( |1 F# e<P><FONT color=#0000ff>/* read result of initialization */
" n! V9 U, `/ v" Uerrorcode = graphresult(); </FONT></P>" h8 G: h, \, j, I* g
<P><FONT color=#0000ff>/* if an error occurred, then output a */
. B2 z) S- Y- d) j7 u/* descriptive error message. */ " f2 L" q( ^& Q& _# D
if (errorcode != grOk)
5 g) q1 o  w8 W/ H# F3 G{
% j# z+ U& i% q/ W1 B+ a+ Y9 {printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 R7 R& D5 M5 Y. wprintf("Press any key to halt:");
/ K, t1 z4 j4 E8 [8 k' U. p# Ygetch();
2 Z, O# S7 M4 ^exit(1); /* terminate with an error code */ ' v% ]8 k5 T( ^3 V
} </FONT></P>- U% S/ K+ K: a! V" C7 Q8 z
<P><FONT color=#0000ff>/* draw a line */ , w0 X4 e6 b; i; B4 p* {6 V
line(0, 0, getmaxx(), getmaxy()); </FONT></P>- V1 ~$ y2 F, \. M
<P><FONT color=#0000ff>/* clean up */ ; h5 n& W7 _9 k$ X' X  M
getch();
4 l: h: r' \& u# X" J, mclosegraph(); / ?1 H, U0 J  n+ X
return 0;
- E; V* N0 }  {8 z} # ~3 O2 h+ t6 }
</FONT>  {$ l( M+ J3 t& o9 g$ c  ~4 U
</P>
- {, w  E) O0 _9 K. @<P><FONT color=#ff0000>函数名: graphresult </FONT>  F2 _  ?  r9 |9 W0 l9 v& [/ m
功 能: 返回最后一次不成功的图形操作的错误代码 : y, j% P' D% @1 A1 A+ d& p* z
用 法: int far graphresult(void);
* f% `" m+ f6 E/ P9 |5 e: f4 B程序例: </P>! z% a7 s; C7 l' Z- b7 q; t
<P><FONT color=#0000ff>#include <GRAPHICS.H>; Y+ w8 f/ s2 ^, a
#include <STDLIB.H>
8 T. ^" c' u: C( E* g* k#include <STDIO.H>! T6 A" U& Y, ^7 A3 z
#include <CONIO.H></FONT></P>
" R0 o2 j" [: N7 E& s7 L- F<P><FONT color=#0000ff>int main(void)
( B$ w, I2 E& {, M* q{
+ T& R5 O! B, U6 i5 b/* request auto detection */ + W3 S+ s& ^3 A  l
int gdriver = DETECT, gmode, errorcode; </FONT></P>
( u) e: z0 _9 _2 B<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 {/ s5 Q$ a& N. M; Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 F  F& m: @2 \& G* U* a4 I
<P><FONT color=#0000ff>/* read result of initialization */
: }  z' n% @5 h5 ?9 a1 J8 K5 Nerrorcode = graphresult(); </FONT></P>
0 f7 P/ y# L3 D" D; y2 ~<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ ! Z4 d( {* H0 w3 s: N/ K/ V( c
{ 3 K' \. `) e) |8 Q9 k" v' \
printf("Graphics error: %s\n", grapherrormsg(errorcode));
2 |$ _3 @& [' U* h5 W7 d# t) mprintf("Press any key to halt:");
! c# F3 S7 i; T, L' l/ f. _getch(); & F/ v* [, Z# B8 u( V/ a8 g+ q7 C
exit(1); /* terminate with an error code */ 0 x% S: V% Y" ~3 V/ {
} </FONT></P>
, f: v$ t  r' Z<P><FONT color=#0000ff>/* draw a line */ " n2 b7 w0 V$ W3 F/ J
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
4 L9 p! u4 X# {0 ^* F* n<P><FONT color=#0000ff>/* clean up */
# H. q( h' `; B, Y$ egetch();
" U" g3 [4 r' H  y6 ~closegraph();
* V9 x- D8 O  K9 o, z5 P. b5 Preturn 0; ; l- S2 H3 ^; r" p, E) L- [) T5 k
}</FONT> + h; h% z- B1 x: Y
</P>
) l3 w. }/ j: v1 H( v<P><FONT color=#ff0000>函数名: _graphfreemem</FONT>
0 j; ^: s5 [4 O' n8 K功 能: 用户可修改的图形存储区释放函数 0 P1 p4 ^% z# o- t- ~
用 法: void far _graphfreemem(void far *ptr, unsigned size);
$ S% r; @* t  Q7 o7 t$ R程序例: </P>
$ h3 ~6 n0 F3 k/ v- V8 G: |2 V2 A<P><FONT color=#0000ff>#include <GRAPHICS.H>
; W' Q4 [1 q% ]8 k. L#include <STDLIB.H>
, ~6 O) u1 G' y#include <STDIO.H>6 [6 |6 D& Y. \$ L
#include <CONIO.H>
) D% S" x6 f1 t- |( K5 w#include <ALLOC.H></FONT></P>
1 t, I3 y1 L/ C# m2 J<P><FONT color=#0000ff>int main(void)
4 t1 c( y0 [* g' Q{
" s* Q0 O# C; M, ~7 r9 ~- h/* request auto detection */ 8 r2 M' d0 w. L! W7 T
int gdriver = DETECT, gmode, errorcode;
, z1 V3 U+ y4 H$ Q! @! qint midx, midy; </FONT></P>
% C& V0 h# i+ r/ h+ X, P<P><FONT color=#0000ff>/* clear the text screen */ 2 p, v' y9 c. ?+ Q* @7 }
clrscr(); & |( a9 X0 w9 ^" `8 {! J4 k
printf("Press any key to initialize graphics mode:");
/ L+ n- V( A+ M' r2 N% ?getch(); . |* ~+ i% ?& V* ?) p
clrscr(); </FONT></P>4 V$ q# B+ q' G$ r0 s& b! u) V
<P><FONT color=#0000ff>/* initialize graphics and local variables */
  v8 [; k( ^0 l  {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>% p8 [3 v4 ^$ W$ l3 ~) N% {
<P><FONT color=#0000ff>/* read result of initialization */ 0 p) b# C* Q9 l; I3 h
errorcode = graphresult(); * G8 d2 y7 K& u9 W. V" v1 J  V3 l- V
if (errorcode != grOk) /* an error occurred */
% w4 T9 n5 Y% A6 G: y: d+ c{ * ]/ l7 F' e. p* h
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( }$ J& H: k1 x2 o: Fprintf("Press any key to halt:"); - H6 e8 M% U  V+ l2 y  h+ \& B
getch(); & `, D4 @+ \# e+ {. ]. @, S" }
exit(1); /* terminate with an error code */ 9 s* w! ]4 r) e7 \! _5 Z0 |
} </FONT></P>& k! W! |! d: Q6 h/ K( g1 _6 g, ?
<P><FONT color=#0000ff>midx = getmaxx() / 2;
' ^# u# @) H$ }6 i; ?1 Omidy = getmaxy() / 2; </FONT></P>* a) [+ I. s) }& U
<P><FONT color=#0000ff>/* display a message */
5 q6 }4 Q* D2 A. n3 L+ Isettextjustify(CENTER_TEXT, CENTER_TEXT);
# \. S. p! j/ k: F( S' Vouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
, k: q0 C, o/ O. i( }6 Q+ f<P><FONT color=#0000ff>/* clean up */ 2 ?+ t. _# M/ @
getch();
5 ^7 D, z7 A2 c/ O$ Zclosegraph();
+ ~3 O* _2 o$ U$ J& k9 wreturn 0;
5 Y2 B: O  p2 E! S) H! y+ _} </FONT></P>: o& v. ]8 x- R
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
9 _' q9 M" x% q# h  i! u0 Ivoid far * far _graphgetmem(unsigned size)
: C6 M" Y. b/ n) a! i! \% i  h{ ! D" |! Q) a' [( g& S
printf("_graphgetmem called to allocate %d bytes.\n", size); ) h% c* u0 S- y! d5 A8 O+ ~* }
printf("hit any key:");
# p3 \1 f+ G* }* S8 ~getch(); / X5 a; H9 W- }) k: I: S
printf("\n"); </FONT></P>
# m2 z4 W4 E$ z3 C2 b$ L<P><FONT color=#0000ff>/* allocate memory from far heap */
, b# P- D5 J- greturn farmalloc(size); 2 i+ h+ _8 d& b, a) J  B, p6 N; I7 A
} </FONT></P>
; a0 D- R# m: a6 p; S2 H0 |<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ 4 k6 _6 ]  J9 d
void far _graphfreemem(void far *ptr, unsigned size) 3 o" {5 u+ O2 j% H
{
8 y* k2 r2 M6 n( k3 J# G5 nprintf("_graphfreemem called to free %d bytes.\n", size); # c+ h! l! p3 J, w% r
printf("hit any key:");
8 R' g6 U& I' Bgetch();
* f# l- T' }# \5 K, Lprintf("\n"); </FONT></P>8 d* e9 P0 {4 s1 W. X
<P><FONT color=#0000ff>/* free ptr from far heap */ 6 \  |+ Y& {4 J0 |2 f% H7 D
farfree(ptr); " p+ b! N4 f& j+ P5 T# _/ a. q
}
$ T, J  |' E1 }</FONT></P>
; G7 ^7 K* R' ?( x% I; t" i<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>% c8 v8 f0 X, R+ a- B
功 能: 用户可修改的图形存储区分配函数
, A/ y3 P4 C% s% y4 k用 法: void far *far _graphgetmem(unsigned size); 1 @9 _9 ?/ ?; O+ r" r8 }2 \2 a* I
程序例: </P>
6 N5 J0 T$ v( s& m; }* {2 @( e( v9 }<P><FONT color=#0000ff>#include <GRAPHICS.H>, J/ I% ?. v/ [5 K6 ?2 c* A
#include <STDLIB.H>4 F6 n6 ^6 @, {
#include <STDIO.H>
; l: \( U4 t8 k3 O( u- g) h#include <CONIO.H>4 \; M) z% n4 r9 E* T! A
#include <ALLOC.H></FONT></P>5 x+ C& E& Q; v" a+ C4 f
<P><FONT color=#0000ff>int main(void)   T6 d% }( ^# \4 J' v4 H
{ . b1 o- X" M5 l3 A5 }) I1 p( K
/* request autodetection */
: e  W$ z' ?$ o% f4 l8 Z' kint gdriver = DETECT, gmode, errorcode;
- B9 O/ i4 ?9 ?" h. nint midx, midy; </FONT></P>
6 [, X& k3 e' y' N/ s/ V<P><FONT color=#0000ff>/* clear the text screen */
# d% w* q9 g) V1 Vclrscr();
( y  v, A8 u4 M6 r' V8 K" Yprintf("Press any key to initialize graphics mode:"); : f. m4 H- K6 {; }* c
getch();
: G* y* D: D$ _' x1 Gclrscr(); </FONT></P>: b9 w0 t7 G& @0 o4 \
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 \1 J2 B7 `3 d* o: I
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' d5 M1 y8 P) @4 u* N3 e# ~5 B<P><FONT color=#0000ff>/* read result of initialization */
: s% c4 L" }# P2 j. Qerrorcode = graphresult();
- E% \  K% N; m& c% I4 u( Lif (errorcode != grOk) /* an error occurred */ ( y; g$ t" h, I/ A
{ 1 v: g) |. O4 ^
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 c2 P5 ]! @. t( j( K: z  i3 l
printf("Press any key to halt:");
" q& t: G8 q2 c' A/ R# }getch();   R% L8 v8 n; x! }2 N0 ^9 `: Y
exit(1); /* terminate with an error code */ ' y/ O* z8 N/ n
} </FONT></P>
9 f& h& l1 u  e8 {$ `0 z<P><FONT color=#0000ff>midx = getmaxx() / 2; ! D! _$ X3 S' h6 h1 f
midy = getmaxy() / 2; </FONT></P>4 D0 I; X1 l! r9 \1 r7 ]; u; F; ^
<P><FONT color=#0000ff>/* display a message */ 9 L) e8 D; L9 w. G2 D
settextjustify(CENTER_TEXT, CENTER_TEXT);
, u/ e$ e6 u1 ?! M; n3 |3 Bouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>/ |9 s. D/ o* i8 C  n6 E5 Y7 K* U. p
<P><FONT color=#0000ff>/* clean up */ 3 l5 _; O8 s0 o7 v
getch(); ) I2 g6 \5 k9 Q- [) O1 E
closegraph(); 8 }8 U; M9 \, z( A6 k! f+ X7 H6 U) G
return 0; 8 ?) X7 n" j) B9 I5 }8 _
} </FONT></P>3 {1 Z9 {9 r1 ^% {1 o2 ]) k  v
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
6 l5 M# @) F% jvoid far * far _graphgetmem(unsigned size) 8 }8 A( f6 `4 Z! L' s
{ 9 E4 H& L# G! I& J; h! x
printf("_graphgetmem called to allocate %d bytes.\n", size);
, a7 K0 e- P7 `; G$ l7 h* Eprintf("hit any key:");
, C1 g& j: ^' J3 }; Bgetch(); ; ^9 |( S2 u) z9 i5 G, S
printf("\n"); </FONT></P>
% p6 G' o. |+ Z6 P, D<P><FONT color=#0000ff>/* allocate memory from far heap */
( M! ^! [+ U5 f( W$ O% {1 freturn farmalloc(size); 7 f7 W1 b7 T! l- _: E9 l
} </FONT></P>" Q: P: p- l% p  I9 F) p! T& q, Q' c
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
! H4 A: g8 A+ P; `2 U2 T( qvoid far _graphfreemem(void far *ptr, unsigned size) / e4 @) R6 q9 T
{ 7 t$ H% j. [- \8 H0 E! A
printf("_graphfreemem called to free %d bytes.\n", size);
/ r: ^/ U% O3 Y  vprintf("hit any key:"); 9 \: U3 v" Y+ t9 R
getch();
, s1 C: m2 k/ g& q7 Fprintf("\n"); </FONT></P>
! m0 H! a' g# T' q% Z- T<P><FONT color=#0000ff>/* free ptr from far heap */ * t  [! n- Z2 w  F  X) j$ ]% n
farfree(ptr);
$ A5 v8 \  M) S+ P! f}
) k' e' v# p% _$ w- c" [, `</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-7-21 01:38 , Processed in 1.101432 second(s), 51 queries .

回顶部