QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2620|回复: 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>
+ Y% l8 N9 v# x  X4 {+ O
! ^7 m, X" w( j" T! `* A7 f- F9 X0 L$ e6 X0 T
<p>3 S* P) t$ O( N) }: y
<><FONT color=#ff0000>函数名: gcvt </FONT>
  |) X) U0 Z% ]* p功 能: 把浮点数转换成字符串
0 |+ b. w# P3 W: N4 y# f用 法: char *gcvt(double value, int ndigit, char *buf);
+ Z8 w7 h) n: q; }程序例: </P>
8 w: Z2 S5 O. u  l' B1 {<><FONT color=#0000ff>#include <STDLIB.H>: n, J5 r+ F* d# {
#include <STDIO.H></FONT></P>
3 Q) k+ `7 Y2 G, @; t: X1 @# g<><FONT color=#0000ff>int main(void) 1 h2 t, \! Q$ Y/ Z# g4 A5 v
{
# }) q) h! v$ H6 H7 Rchar str[25]; 1 U6 j+ z8 G4 ^  @& n1 }) V
double num;
( S7 J) u; Y& C. B# Wint sig = 5; /* significant digits */ </FONT></P>0 t9 u+ ?8 N+ `4 `7 b
<><FONT color=#0000ff>/* a regular number */
+ {" f! e, r  [, vnum = 9.876;
7 |% J4 ~, W; q; t- B8 ygcvt(num, sig, str); ; c% h! {! k0 M2 J# U) E
printf("string = %s\n", str); </FONT></P>8 t" Y' E- l+ s' D
<><FONT color=#0000ff>/* a negative number */
. o7 T; Y8 ^2 l) o7 n: n7 [) u' d$ Mnum = -123.4567; . w& |9 l" U) \/ L7 {+ b- P
gcvt(num, sig, str); 0 C! C9 P, A: j5 ]
printf("string = %s\n", str); </FONT></P>
2 _" d. T0 L4 Z! b3 p9 t<><FONT color=#0000ff>/* scientific notation */
0 s5 _% c6 V7 ]$ I  {6 Anum = 0.678e5;
4 [. E0 g4 G$ @+ hgcvt(num, sig, str);
" `) k' @) }7 t  `printf("string = %s\n", str); </FONT></P>
7 }0 x7 W' j1 I! ?$ h<><FONT color=#0000ff>return(0); ; [; l/ ?! C4 h9 |! b; ^
} ; x. i" Z$ _1 T- K. U
/ S- V3 c* M" W, s  G( b# y
</FONT>
( u# N& `" Q- g# [6 K8 W; Q3 V: t$ v# r</P>
! g3 a3 \! q3 m8 e) g<><FONT color=#ff0000>函数名: geninterrupt </FONT>
. j- O! \7 y: W# H7 J% q0 K功 能: 产生一个软中断 7 q& [  q, x# u* I9 f. ?
用 法: void geninterrupt(int intr_num); % T$ D9 o# H: q+ X( Q- @" n, w
程序例: </P>
& Y/ z* u5 [2 Y+ b( A4 J( i1 o' Y<><FONT color=#0000ff>#include <CONIO.H>2 \6 z# Q5 k+ x! c1 i" x5 e
#include <DOS.H></FONT></P>
* j/ k' ~5 Y( Y. m5 X- p<><FONT color=#0000ff>/* function prototype */
9 l& y% P* c( V) Avoid writechar(char ch); </FONT></P>
; Q, K1 _! b" }3 F' D" O2 ^<><FONT color=#0000ff>int main(void) 0 Z3 }( s0 D! d$ J/ G/ N3 e
{
4 V1 O: z/ @# S- P9 Dclrscr(); ( L6 \0 Z8 m* J% d+ M  W) F
gotoxy(80,25); ' J7 }& f+ e) a& v3 u! a0 o0 b' V9 i
writechar('*'); - x9 p, y' Z7 w% J4 V! n8 {6 \/ E
getch();
# k' A6 [: W1 J3 q- r' P; S3 [return 0;
( e3 E+ S& b: Y} </FONT></P>0 \* D* N% n6 s+ m# r- Z, D
<><FONT color=#0000ff>/*
$ q/ U7 ^3 ]# F) G! X( x" Joutputs a character at the current cursor
* k: ?1 t) F5 _% l. C& O- vposition using the video BIOS to avoid the
# f  l4 f3 D  W0 x' cscrolling of the screen when writing to
1 [# [; ~8 D( glocation (80,25). 9 x0 n/ o1 n* G% r( ~
*/ </FONT></P>
& E, S6 H; p) T" \+ s9 _* j7 e' W9 I<><FONT color=#0000ff>void writechar(char ch) * G  A0 D1 Z8 c8 N4 n6 q
{ - M8 i, }$ e% e2 B- f
struct text_info ti;
. v$ I* V# T) j% z% Y/* grab current text settings */ 0 _% j2 |$ w4 L# l. G5 z& z; @
gettextinfo(&amp;ti); " e  ]9 R/ @9 k- i# p1 o) x' f
/* interrupt 0x10 sub-function 9 */
/ L9 F" D$ w0 @_AH = 9;
) |: \- ?, E8 r  [$ C: B/* character to be output */
# ?! }1 _, \/ C+ ?- y_AL = ch;
5 b  F4 f( E& f, T_BH = 0; /* video page */ / w' y% c  c$ c3 b  K2 \5 @, H
_BL = ti.attribute; /* video attribute */ $ i5 V; u- E$ v% D+ Z' X: F
_CX = 1; /* repetition factor */ 4 F% r6 T5 n) x  i
geninterrupt(0x10); /* output the char */ ! @3 b# }* @+ U0 a. I& n
} $ P% `3 g7 H+ C; D
</FONT>: b( H5 b' L2 }
</P>
5 P* g0 k1 N& A2 |4 x<><FONT color=#ff0000>函数名: getarccoords </FONT>/ D2 S, p) \3 M5 A( r; R0 S$ q5 O
功 能: 取得最后一次调用arc的坐标
- ^- V; F* z: w7 K- T用 法: void far getarccoords(struct arccoordstype far *arccoords); , w1 o1 w1 Z' G1 x9 y; A1 x" v( f
程序例: </P>2 e0 [5 _. u/ v# g: A
<><FONT color=#0000ff>#include <GRAPHICS.H>
5 Y% y/ b6 z2 Q: Z  E5 Z  q#include <STDLIB.H>
- k* w- ]  m" q1 j! U/ z- f8 M8 p#include <STDIO.H># d9 G5 ]0 q) t2 T' h: A
#include <CONIO.H></FONT></P>
& c( x( t3 C, K& u1 h<><FONT color=#0000ff>int main(void)
, G/ _1 W" H( ?2 y( h# G{
' W) J/ |4 M% G* T" s/* request auto detection */ 3 m; O3 G( h9 D: Y# k3 v
int gdriver = DETECT, gmode, errorcode;
6 K# n: J7 o  X8 R4 B( \/ lstruct arccoordstype arcinfo;
' \. q8 E! _4 s5 C$ p& Qint midx, midy;
, x1 e% e+ R9 X2 z: \8 B$ {6 b! |int stangle = 45, endangle = 270; ! H! k; L& {( _9 o4 p! P: x
char sstr[80], estr[80]; </FONT></P>
! h; U! {& h; d  B' O8 r5 R5 L<><FONT color=#0000ff>/* initialize graphics and local variables */ ) @* k6 w- X" D
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ @# N2 u8 z  Z4 P& B& i
<><FONT color=#0000ff>/* read result of initialization */
6 W' E6 q9 F" k! `6 werrorcode = graphresult();
1 V6 q6 t; U5 [0 S5 M8 r/* an error occurred */ , Y  x8 g, u/ I% a% z  h. h
if (errorcode != grOk) ; C5 C7 D( G8 X; F( s
{ , _2 F2 e" T4 B! f' U1 b6 ?+ `  ]
printf("Graphics error: %s\n",
! J; N& Z: C+ w3 w4 n8 hgrapherrormsg(errorcode)); ! T* D1 @4 Y' ]! Y! U( S& \2 ~3 S
printf("ress any key to halt:"); / \- k- ]  u0 @/ X  p" h
getch();
* T6 G4 G( \( F0 T- C8 s; T/* terminate with an error code */
9 @! R3 S8 e* s. U7 M( K, _8 O1 Uexit(1);
- V8 |0 y. M' M- U} </FONT></P>" K# o' ^6 C2 N# H; {2 R
<><FONT color=#0000ff>midx = getmaxx() / 2; - r- L! |+ h( d) a& G
midy = getmaxy() / 2; </FONT></P>8 {6 i* X6 `0 T# D2 ]
<><FONT color=#0000ff>/* draw arc and get coordinates */ + g+ W  r9 C0 r/ b0 j. E; _, s
setcolor(getmaxcolor());
4 D+ H, e/ L  iarc(midx, midy, stangle, endangle, 100);   f" D) N4 E+ k+ i$ b7 m1 k  b
getarccoords(&amp;arcinfo); </FONT></P>
! t, v9 ]. N# I1 Z<><FONT color=#0000ff>/* convert arc information into strings */
# Z1 y; E2 b: D4 G. ^6 ^. vsprintf(sstr, "*- (%d, %d)",
! Y- ~+ l" N; ?. [, p* Zarcinfo.xstart, arcinfo.ystart);
6 X3 _( X0 Z( A3 `5 _sprintf(estr, "*- (%d, %d)", - m( h. o. b, K7 u# f
arcinfo.xend, arcinfo.yend); </FONT></P>* v& q  j: K+ \' q- N( N8 P
<><FONT color=#0000ff>/* output the arc information */ 8 \' d1 k/ T- ]" M- l& ?
outtextxy(arcinfo.xstart, # m% U' |' \5 ^- u
arcinfo.ystart, sstr); # R& r8 s+ y- ^$ P4 F
outtextxy(arcinfo.xend, 8 [" E+ s% t  u  m% s
arcinfo.yend, estr); </FONT></P>) Z4 e) k& m1 W5 j+ ]" [
<><FONT color=#0000ff>/* clean up */
# a9 J$ W$ g5 c; p8 j+ {getch(); ' |' u8 h4 e4 y2 g. Z6 V' a, f
closegraph();
. ~& w7 N& _: Wreturn 0;
; e0 ?7 k; T; ~6 ], D} - `2 }; m( o( u$ {( [0 h
</FONT>. L/ I: Q+ P: S! P% a4 A5 g
7 V! w4 _5 B4 M. z( _, c2 U
</P>
3 X" O8 y& W* }4 J* r- |1 ~<><FONT color=#ff0000>函数名: getaspectratio </FONT>
  }6 S- M# N  Q) B功 能: 返回当前图形模式的纵横比
" v9 {* Q2 f! V7 y用 法: void far getaspectratio(int far *xasp, int far *yasp);
* J, ^4 p6 k% \9 `0 D' L! U程序例: </P>
3 \7 v+ Y) }4 x( y8 f+ e<><FONT color=#0000ff>#include <GRAPHICS.H>
: Y& D8 A! L; Q/ c/ C3 q#include <STDLIB.H>5 x  |* V/ W" F3 Y' w
#include <STDIO.H>7 I" }7 g( A" n5 b" {
#include <CONIO.H></FONT></P>: X/ d" ]3 t4 i0 d
<><FONT color=#0000ff>int main(void)
# c2 h" Q* K! v2 |" X5 `% c{
5 G# e' [+ H9 [% `- N/* request auto detection */
+ X5 s4 `* h# Q- L' b# I- F% pint gdriver = DETECT, gmode, errorcode;
. p% v' n% x, N" n% E; Sint xasp, yasp, midx, midy; </FONT></P>
2 Z# N4 v0 v! U* I. `7 z<><FONT color=#0000ff>/* initialize graphics and local variables */ " V7 r0 M+ R, y* b$ J
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ E. c+ J# M# ]3 _<><FONT color=#0000ff>/* read result of initialization */ * D5 U( J# b/ d/ S; U7 I
errorcode = graphresult();
; w; O# P" n, ]$ A7 i" y/* an error occurred */
3 x( ^8 x) W: I5 @; b4 Kif (errorcode != grOk)   E& j% m, F: E/ s
{
5 X/ B4 A  i. L& o; M1 Tprintf("Graphics error: %s\n",
* g5 F, m5 |- D0 I% a& lgrapherrormsg(errorcode)); . S, Q0 c( Q. O8 ?
printf("Press any key to halt:"); ' V* q4 n( m$ K
getch(); $ Q/ L! S. _+ d) {; w3 @- C4 g1 z
/* terminate with an error code */
) L& h. u9 Q8 _3 m2 r9 iexit(1); % l& Y2 K  U- a
} </FONT></P>
" U8 s$ T, X  Q3 C: q$ V<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 D5 e! ~) i0 q7 {midy = getmaxy() / 2;
0 @: ?2 Z4 A: q- f) p7 _* g/ Usetcolor(getmaxcolor()); </FONT></P>6 }( A& @! ]& ~; {7 ]- w
<P><FONT color=#0000ff>/* get current aspect ratio settings */
5 j" j2 t5 \" egetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
7 A. F2 m) j: \: W<P><FONT color=#0000ff>/* draw normal circle */
) o" ]9 m& ^+ q( @& a9 wcircle(midx, midy, 100); 9 x2 ?7 z1 R- t& v1 D0 y; B
getch(); </FONT></P>) W, Q  @# `  u7 z! C) P
<P><FONT color=#0000ff>/* draw wide circle */ 4 B& J* E; n$ o) f+ g" v
cleardevice(); * r; L' q* ^- J* W% `
setaspectratio(xasp/2, yasp); 1 c$ M' r& Y* _; Y" T2 Q% m* W
circle(midx, midy, 100); 9 y& @3 i# i) @8 O
getch(); </FONT></P>1 K8 C- k- p3 x, {9 [
<P><FONT color=#0000ff>/* draw narrow circle */ 3 |( A0 b4 f5 n: ~# F3 p$ X
cleardevice();
5 o& a' U* t$ G: O% N) L* j2 |setaspectratio(xasp, yasp/2);
6 W5 d( p) l8 g2 \4 V1 \8 y- [$ Fcircle(midx, midy, 100); </FONT></P>% J6 z: y' V7 n2 d
<P><FONT color=#0000ff>/* clean up */ . f5 L, w/ M; o' Q+ B
getch(); 3 d3 R4 e. a- ^. y5 c
closegraph(); " g( E+ u2 e$ L, R
return 0;
& W9 [) H' K0 u0 H) @( d' K7 ~} " ]% I2 I, z6 n( v
</FONT>
! W3 s% b% A, I0 {# X  H) F0 x( k1 Z, v: t, e, e" G+ M
</P>
8 w1 i$ S! {! [7 a/ _3 A) x* S<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
! s' v# {# l+ A8 n  ]& u功 能: 返回当前背景颜色
4 w# O, ]2 v8 x/ N0 u, [5 K" }用 法: int far getbkcolor(void); & m4 t* H) o: r
程序例: </P>
# F3 F% q" ^/ T  t1 t6 ~, s/ C- a<P><FONT color=#0000ff>#include <GRAPHICS.H>- K" o6 e% V* b
#include <STDLIB.H>" K% ^% Y9 e- e* J
#include <STRING.H>
: M! Y  R* C4 O; O- [0 f/ F#include <STDIO.H>
- I4 q6 A- l5 P3 ]#include <CONIO.H></FONT></P>
  o% n* s0 y! s% z& H& M<P><FONT color=#0000ff>int main(void)
% b# h4 H6 I& E$ G{ 8 ], W& p6 O; Q* \5 B4 G$ e7 U7 n" ], l9 e
/* request auto detection */
7 t# U& z* q2 f! w4 \. C1 Uint gdriver = DETECT, gmode, errorcode; & |( k1 ^, }. X' v2 E/ t
int bkcolor, midx, midy;
8 N  F6 X5 F! Tchar bkname[35]; </FONT></P>
6 X, I7 q. S# I1 y' {3 d6 V<P><FONT color=#0000ff>/* initialize graphics and local variables */
  C4 F5 c7 Z4 Z2 c( g/ H) p6 z+ @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
- M& e8 v5 C/ U& p9 E' k<P><FONT color=#0000ff>/* read result of initialization */ 5 G# Y7 \( S' v2 T# p" N$ I
errorcode = graphresult(); 3 O/ f3 w2 i  S0 P0 P7 j) V
/* an error occurred */ % b$ p* K9 O9 B
if (errorcode != grOk)
" ?3 w# R$ p" ~$ q{
8 m) a1 `! ~3 R; u: x4 L2 k/ y+ lprintf("Graphics error: %s\n", 0 v7 s" E* A+ @& M' J; X, l
grapherrormsg(errorcode));
. M; H( h3 J( i7 ?, e: _0 Tprintf("Press any key to halt:"); 9 Y% m6 M  x5 b& R3 C% ], z
getch();
' z* O( O* _1 [6 r: t1 V' u2 b+ I/* terminate with an error code */
6 p/ s/ F. `$ \) Aexit(1); : d3 N  L+ l0 V
} </FONT></P>
. O: T) C# y5 T4 _4 v* ^6 g5 F- s<P><FONT color=#0000ff>midx = getmaxx() / 2;
! q3 E$ |: l2 ^4 f1 I6 h& Hmidy = getmaxy() / 2;
/ b; i; i* e/ i9 ~setcolor(getmaxcolor()); </FONT></P>' T! T3 x2 t5 L1 X! I
<P><FONT color=#0000ff>/* for centering text on the display */
' D; G9 \7 S: _: f& {* Nsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
8 T+ G. y; l; ~6 ?2 k3 C<P><FONT color=#0000ff>/* get the current background color */ 0 {2 B4 K# Y* k% J: M0 C  l8 _
bkcolor = getbkcolor(); </FONT></P>
4 y7 F0 b4 t) U( I  u<P><FONT color=#0000ff>/* convert color value into a string */ 5 M6 |1 k3 }+ j2 t
itoa(bkcolor, bkname, 10);
) ?2 h5 Y' I0 {" ~1 m7 jstrcat(bkname, 6 z  G* X; e* H/ C# ^2 B
" is the current background color."); </FONT></P>: e; F6 X7 ~9 J) {" g+ K
<P><FONT color=#0000ff>/* display a message */ 3 N7 k3 @3 p3 N6 J% Q, E) {/ }* e( \
outtextxy(midx, midy, bkname); </FONT></P>; t% C$ N' R/ J8 m* Z
<P><FONT color=#0000ff>/* clean up */
' q+ W6 j: U2 ?/ d$ l. P/ mgetch(); % N  d0 v* y% W3 U! G
closegraph();
# ~9 H1 c: v) C; r3 R$ Y! s& @return 0;
: T9 n; p; \" @0 U& w}
# ]. t; R1 T, O/ }+ E
, ^) u5 g) a$ u# e3 u2 s</FONT>
2 L" @$ \9 u- \</P>
; v$ e  R; e: s/ v! q/ X<P><FONT color=#ff0000>函数名: getc </FONT>: P1 E" q; ?( |
功 能: 从流中取字符
, P8 P( Y! i4 A用 法: int getc(FILE *stream);
- X- t. o2 U8 F/ P程序例: </P>- s' Y7 D" n* F7 [3 C
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>" j6 V* c/ T# B( j
<P><FONT color=#0000ff>int main(void) $ I$ z; [) l6 }9 ?" |  q
{
! B- a, B' ~* ^" Ichar ch; </FONT></P>
; {5 n( Z3 p: z! l! ^, O+ d<P><FONT color=#0000ff>printf("Input a character:"); ' F: c# J0 e2 q+ t+ e
/* read a character from the 1 K) o2 ^* j. X$ Q
standard input stream */
2 g+ L7 H5 [1 j, p% y* ^' f, a& \ch = getc(stdin); ; s" `" r( j" U! o$ Q2 R
printf("The character input was: '%c'\n", % h. s+ R; T- Q/ v/ d: H# T
ch); & n+ S  w' E, @( {
return 0; ! Q" x. O- ^+ I8 l
}
& ~2 P. ^4 s9 B+ t1 _6 E$ h; D( H  M
  Q3 f0 `+ q' S# x6 ~: x</FONT>/ q$ d- o) l* x8 o+ o
</P>1 G5 V* o" a& D7 O1 y$ [0 c1 X8 l
<P><FONT color=#ff0000>函数名: getcbrk </FONT>
& ], b- c' q' g+ G功 能: 获取Control_break设置   M( o5 U" l+ r6 Z, ^- q5 }
用 法: int getcbrk(void);
! V  Z- H( L1 c# f) E程序例: </P>
: S) a3 b1 ^$ j$ B<P><FONT color=#0000ff>#include <STDIO.H>
) k# g! `3 b- P- M- U, I( Z' g#include <DOS.H></FONT></P>/ Y% h# O! E0 h, \
<P><FONT color=#0000ff>int main(void) / ^: U' N0 u! @# p
{
' ~6 O: a# g% D5 h( e+ \if (getcbrk()) , {1 ?% P6 ^/ [9 U2 D; V0 ]4 }
printf("Cntrl-brk flag is on\n");
! i% T/ A( t* {; Q, q. ?7 h# Jelse 4 w* I. r7 Q, _; s- A* D
printf("Cntrl-brk flag is off\n"); </FONT></P>
% @2 b$ q/ P' ?' p: @1 C<P><FONT color=#0000ff>return 0; ' T4 D) B& Z' R1 b9 w1 O0 n
} </FONT>  C$ C: e: y" S* p5 ]6 |: \

, ^3 M1 x. K2 t- H6 h</P>
( ]0 m# ~6 i) G6 V, Q8 ]) @<P><FONT color=#ff0000>函数名: getch </FONT>. I" B* s+ P" o1 q4 }
功 能: 从控制台无回显地取一个字符
' j  [6 f5 e- y7 p用 法: int getch(void); 9 w- J- l3 J4 o4 S
程序例: </P>  r+ x0 ~5 |3 q  y5 [
<P><FONT color=#0000ff>#include <STDIO.H>5 f* X+ S) Y3 C$ G1 Q' R( h  ^
#include <CONIO.H></FONT></P>9 x! g/ l5 \) P  C) T# X7 `$ q
<P><FONT color=#0000ff>int main(void)
& ^$ G6 U' U1 }% x{   r! Y# K3 S" ^' k
char ch; </FONT></P>
* g. Y9 T+ P% F4 n<P><FONT color=#0000ff>printf("Input a character:"); , X4 _3 ~5 Z' c$ P8 t  x
ch = getche();
9 u6 F) z' @. t2 R9 ?3 `8 Nprintf("\nYou input a '%c'\n", ch);
8 c# W4 c% E/ u0 L' Kreturn 0;
6 ?! t0 L1 r8 n* O# U" V}
4 s1 i6 F9 \9 b5 Z, p5 q0 x0 B& K+ U# X1 G- K+ [
</FONT></P>
+ ]1 F: [5 B) I# z5 f<P><FONT color=#ff0000>函数名: getchar </FONT>: s& B* ^4 H! w! R
功 能: 从stdin流中读字符
. C( R% u, w: \$ O用 法: int getchar(void);
. a# H2 _, Q6 r8 V! U5 S6 A: S  j0 T程序例: </P>" [7 n, n  }) U. r" ~: Z8 |
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
0 \9 ]5 v0 r$ c+ y' Y& E<P><FONT color=#0000ff>int main(void)
/ P1 W0 |3 u/ w3 M6 Z# g{ - D8 ]" T& n8 C- I; A5 Z/ u" C
int c; </FONT></P>0 k7 J5 \6 A4 x2 z& R. L
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
8 n" {6 m5 K! o6 Y& dis line buffered; this means it will % g5 ?1 M' t! x
not return until you press ENTER. */ </FONT></P>) w+ o- M$ v' x7 W7 a/ x* M* r
<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
( [; f+ I4 m# H; Iprintf("%c", c); </FONT></P>; y/ }, w4 w. S" A
<P><FONT color=#0000ff>return 0;
& o, w# O1 G9 [6 K3 c7 n% k: Y} 3 z' `% U7 ?- S8 l  z6 |
</FONT>
' n+ x0 m  Y: z8 T7 y1 d</P>
& a7 B5 K0 R, X. _7 P# m. D% o* ]3 ^& R" U<P><FONT color=#ff0000>函数名: getche </FONT>  d; ?8 w+ }0 i! N9 L
功 能: 从控制台取字符(带回显)
; _/ d% @6 F( G% g: d用 法: int getche(void); 0 e1 }- ?& K# Y% {5 ~
程序例: </P>
, N+ R. t8 R& r) z4 r- Z/ l/ X' p<P><FONT color=#0000ff>#include <STDIO.H>; i5 k1 u8 m+ k8 ]5 A  X
#include <CONIO.H></FONT></P>
. ~; T  F3 X5 Y  @# b1 ]8 I<P><FONT color=#0000ff>int main(void)
6 Y& _' `4 X; O5 p# ]/ v{
# n% t4 W- n9 k% j! P9 H9 B: Pchar ch; </FONT></P>
& U) A  g6 o8 _<P><FONT color=#0000ff>printf("Input a character:"); , K& B' |. e  }( x4 t
ch = getche(); 0 @# ?0 u, l3 a" i$ }9 M
printf("\nYou input a '%c'\n", ch); 4 L( `4 h2 t# Z( o+ |
return 0;
2 T! h/ ?7 l1 Z1 X3 `3 q, S}</FONT> & a5 C5 L% u1 \! }( v9 @% S
  b. f. ], j6 E  }
</P>
4 G, `  f; K, n1 d. g<P><FONT color=#ff0000>函数名: getcolor </FONT>
# \9 \* V- f$ L/ P2 c功 能: 返回当前画线颜色
& ]6 k$ H. ~' N) V5 J( s用 法: int far getcolor(void); 6 C6 L* u9 G- @
程序例: </P>
1 U3 g: L: i5 [. @# S<P><FONT color=#0000ff>#include <GRAPHICS.H>6 Q* K. v2 M7 y  q" i6 @
#include <STDLIB.H>
5 m) v- J# n, j% R! L2 O& T" r#include <STRING.H>: C( A- i# R; a. z4 G( _9 {
#include <STDIO.H>
+ `6 n& V% e$ Z; J#include <CONIO.H></FONT></P>" J  a( h, l% [3 q; a  P
<P><FONT color=#0000ff>int main(void)
+ J6 h* ?+ A1 N3 I; `' U  }{
: @* f. p0 [' M0 O5 {/* request auto detection */ - D9 H. e+ C; K) L: D, V
int gdriver = DETECT, gmode, errorcode; 4 F2 @# s' R* `" U1 O, x3 l
int color, midx, midy;
6 E% y% q: R* V9 _$ mchar colname[35]; </FONT></P>
' x8 |$ @2 N* H. V<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 h3 g0 x' b3 g, f, F
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 B$ N7 D- S( c+ B% x
<P><FONT color=#0000ff>/* read result of initialization */
% F. z  V7 Y9 _errorcode = graphresult(); 1 m6 c# @+ p$ Z1 a- U
/* an error occurred */ ' X" b  M) ~, c8 [, c9 C/ O
if (errorcode != grOk)
, W1 Y) T( A' a- x1 I. K/ f{ 5 p6 w' m9 `' q9 O2 T
printf("Graphics error: %s\n", 9 W# j6 W2 t+ s# x2 l/ K* {) H5 x
grapherrormsg(errorcode)); 4 I# u+ v* g% ~" b2 r  ^8 [, t
printf("Press any key to halt:");
" [& F8 G" k$ l( U+ s* S* wgetch();
, y+ \( }# H0 O/* terminate with an error code */
( M& U1 P) {/ Z1 Pexit(1);
  e- J3 _  C# p6 t7 b" b} </FONT></P>4 B0 B" G' v$ a7 R
<P><FONT color=#0000ff>midx = getmaxx() / 2; % k3 L: u& I* C  O4 o+ g
midy = getmaxy() / 2; - t. O6 H6 y0 o. |
setcolor(getmaxcolor()); </FONT></P>1 ]2 l# _7 \4 r
<P><FONT color=#0000ff>/* for centering text on the display */ 2 ^; F7 L* s8 V0 n% I- p
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
' E# m2 d  J2 x9 J<P><FONT color=#0000ff>/* get the current drawing color */ 3 f) u) O2 g) z2 P' e5 \
color = getcolor(); </FONT></P>9 L8 Q, r! W/ M$ l+ s$ z  C/ C" \  J
<P><FONT color=#0000ff>/* convert color value into a string */ + _( A& K0 O" q8 B3 t' Q
itoa(color, colname, 10);
* i9 }, m0 A4 H, Dstrcat(colname, * |- Y0 b/ P$ ~- _. \
" is the current drawing color."); </FONT></P>
0 P5 o  S3 I6 ]3 |<P><FONT color=#0000ff>/* display a message */ ( y) ^/ U8 u8 u* `
outtextxy(midx, midy, colname); </FONT></P>
7 a8 a' K# B8 U! P<P><FONT color=#0000ff>/* clean up */
( i/ A: w2 ^' G" i' d# egetch();
( K; l! M8 M$ K5 w) Uclosegraph(); ' y5 {& e9 e) Z/ x: @" v
return 0; ) S' _# i- {7 S5 l
}
1 k, l5 i  d, H7 x; j</FONT>
* p# y, b+ C( D* f$ O$ o</P>2 ], O$ J) {, C! D' j  l
<P><FONT color=#ff0000>函数名: getcurdir </FONT>+ s% q2 a: M# \' |& N/ [
功 能: 取指定驱动器的当前目录 : k, a8 Z5 S$ Z6 k5 R
用 法: int getcurdir(int drive, char *direc);
* t: \/ {  p4 U& X3 H  F5 B- j' b- E9 }程序例: </P>2 I- A/ Z2 U# v  [
<P><FONT color=#0000ff>#include <DIR.H>
7 M1 t' {$ z6 q) i6 ^* V: q% }#include <STDIO.H>$ f5 P; X/ \, Y4 s1 s9 p/ b
#include <STRING.H></FONT></P>' x+ E* B' O2 V, U7 u; ?3 F* G
<P><FONT color=#0000ff>char *current_directory(char *path) 4 u; |3 i; n0 a" |- p
{
' j# l' B9 A# f& Astrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ - s7 o$ ?0 s/ ^2 ^* ?
path[0] = 'A' + getdisk(); /* replace X with current drive letter */ / q/ Z- u) W: ?( r, |
getcurdir(0, path+3); /* fill rest of string with current directory */
" f% A# l+ R/ T0 Areturn(path); 6 v6 u* S. h- l7 W! o
} </FONT></P>4 w3 |: q9 m; ~) I$ g. r3 k8 V
<P><FONT color=#0000ff>int main(void)
1 @6 |) y+ Q2 r1 Y{
- a9 {* R% T4 a* u6 u( s: Wchar curdir[MAXPATH]; </FONT></P>
+ o2 p# D: A" W5 r7 _3 R& a<P><FONT color=#0000ff>current_directory(curdir); $ C* T. g5 u) P
printf("The current directory is %s\n", curdir); </FONT></P>; @9 }( x. b1 N
<P><FONT color=#0000ff>return 0;
2 q1 z; J5 e% h9 F}
0 o$ B! L/ J9 I8 r% E</FONT>3 S+ u7 l' P* r0 g3 d4 g
</P>9 I" ^2 ~4 M! X, ~+ K* E, s6 R: S
<P><FONT color=#ff0000>函数名: getcwd </FONT>3 ~9 Q2 |& q( ]$ m
功 能: 取当前工作目录
6 o+ Y9 H  L4 O2 N7 g6 G% B用 法: char *getcwd(char *buf, int n); " S7 V/ h, h5 a1 p& Z
程序例: </P>+ a- B6 f' M  T6 d' n( ^- X
<P><FONT color=#0000ff>#include <STDIO.H>
' Q8 u& @, x6 J4 \+ F9 t#include <DIR.H></FONT></P>* m3 J. p; x& M) G1 v! U
<P><FONT color=#0000ff>int main(void)
" R; e7 Y! l7 t' e, J{
3 H1 a+ y' P5 D9 |9 e; N: B5 ]char buffer[MAXPATH]; </FONT></P>
2 g2 ?% R! Q3 r' b* r3 E5 h% t8 z<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); # o& L) g0 P9 ^  ^
printf("The current directory is: %s\n", buffer); & B- J0 W; E) b" o" x
return 0; + V& I. u7 Q0 x  @( d% f5 f
} </FONT>
! O+ D2 i3 b. i5 k' u2 h* q3 U! g% D) \) F, e+ n9 O
</P>
4 a3 c$ [. S* F8 L) T<P><FONT color=#ff0000>函数名: getdate </FONT>9 ]% Q  |9 H: H  z3 Q6 i
功 能: 取DOS日期 * T  G  r; }- d& G: H
用 法: void getdate(struct *dateblk);
* z5 C0 U" ~. M# n程序例: </P>  z$ J( o! t& P0 K3 {8 o
<P><FONT color=#0000ff>#include <DOS.H>, k. p& B# E3 }' u
#include <STDIO.H></FONT></P>/ {6 P2 W/ O7 d+ H, m9 P0 W: t
<P><FONT color=#0000ff>int main(void) ! c& p# S+ _" ]. c0 C$ Z
{ - h+ p; ~3 v2 ?- [
struct date d; </FONT></P>
8 n6 ]; s0 d/ h, q<P><FONT color=#0000ff>getdate(&amp;d);
9 C7 b1 N5 W8 }% _2 ]printf("The current year is: %d\n", - j5 Q4 N0 F0 j$ n0 O4 r. {3 T
d.da_year); * Z4 i  ]' W) T3 d1 Y
printf("The current day is: %d\n",
1 u# ~( o1 {: {! Ed.da_day);
, r2 K8 K* E2 Y1 T( S# I; I7 E/ Qprintf("The current month is: %d\n", 9 @. N; [- f9 S, z- W
d.da_mon);
% f% h/ r4 Y# e  Kreturn 0;
4 i( f# N1 y; T& U) J/ Z" R. Y}
" X' I/ A3 |9 `/ L, r& v# A5 j</FONT>3 `; Z# R8 F, v2 }+ h- G
</P>  }8 j* k, b7 n1 c( X" \
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>- d: B+ C1 O) C' W! }
功 能: 返回调色板定义结构 $ [7 J% a5 f+ L! R3 y
用 法: struct palettetype *far getdefaultpalette(void);
8 ?7 ]: M( |$ Y0 z1 ]7 i+ k) [程序例: </P>1 r+ I3 t0 E1 s  r" q8 V: D& @
<P><FONT color=#0000ff>#include <GRAPHICS.H>: n3 c+ P% d' R8 @! T
#include <STDLIB.H>( x& Q. X% q2 \: m* p" J5 m
#include <STDIO.H>$ d& ^6 T" [5 ^$ t
#include <CONIO.H></FONT></P>5 x9 ]5 Q* u7 s8 f% v! B9 r9 U
<P><FONT color=#0000ff>int main(void) 5 K7 o" ]5 C5 B  a8 t, F
{
- x6 F" ~+ B) V$ ]* ^! _% J4 ?/* request auto detection */ : `4 J5 Y$ Y, o: A
int gdriver = DETECT, gmode, errorcode;
9 I/ t1 f$ O9 F, w4 Z5 {+ uint i; </FONT></P>
: J7 x8 }  x! `: l1 S( k! M<P><FONT color=#0000ff>/* structure for returning palette copy */
0 ?; x7 b3 \9 }7 w1 m; vstruct palettetype far *pal=(void *) 0; </FONT></P>
* t9 ]% k% u9 ^7 }+ ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 a3 g. v3 f; z4 W  Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>& D& v% g' G$ p. g+ g6 m# P
<P><FONT color=#0000ff>/* read result of initialization */
) C# @" R, G" Z( O& y; Oerrorcode = graphresult();
; A8 y+ i' d, f$ |2 r$ j/* an error occurred */
3 f3 v' d! R+ d  \if (errorcode != grOk) # z4 r* i6 R5 ]4 O4 P* E
{ " W1 k/ W" G) |
printf("Graphics error: %s\n",
  i/ t- w  @6 O' J" xgrapherrormsg(errorcode)); , Z; p  f% Z' _% G4 v  i
printf("Press any key to halt:");
& r! f' v7 r( X5 ugetch();
7 P. W* t* _' B) w/* terminate with an error code */ 8 p: a" S" t$ @+ x7 |
exit(1);
. q9 o% c$ f  _5 U, E} </FONT></P>8 }- f5 Z! x" F
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
$ E9 V& V& P. |. ~+ k) g<P><FONT color=#0000ff>/* return a pointer to the default palette */
6 [% u/ |0 Q% p0 Cpal = getdefaultpalette(); </FONT></P>1 X4 p: P* x4 Z/ v$ B
<P><FONT color=#0000ff>for (i=0; i&lt;16; i++) 8 s4 ?0 x+ _4 t
{
3 C/ N4 c7 G* [# X0 `8 ]printf("colors[%d] = %d\n", i,
! o, l9 X) o, ^& P+ Tpal-&gt;colors); ' P# W6 j5 R# ^
getch(); $ o+ i& D5 L# B  P
} </FONT></P>( @0 \6 x% u8 \7 [# w7 ?
<P><FONT color=#0000ff>/* clean up */
0 Q2 l# ?6 q  W3 s3 ggetch();
* T+ w0 G: F* n) z) V( w+ Y% F" pclosegraph();
( y+ W3 c+ @: Ireturn 0; ! d3 X8 o% O- e) e4 Y2 d
} ' e) k: e3 K# u- u2 C
</FONT>
# ?6 o" l2 S+ Y</P>
/ S2 U0 u. h& y+ H8 c% o7 h* w4 V<P><FONT color=#ff0000>函数名: getdisk </FONT>7 t4 d7 z' h9 D5 e0 p
功 能: 取当前磁盘驱动器号
4 J' F: ^4 {9 `% c用 法: int getdisk(void); % ]$ F: f! ]% `) @) j% ~4 y
程序例: </P>$ w2 c( ^5 I& H
<P><FONT color=#0000ff>#include <STDIO.H>/ f: D/ I- w/ I  |' ~- z
#include <DIR.H></FONT></P>/ v3 ^: S* v* k6 X
<P><FONT color=#0000ff>int main(void) 6 S# j' P0 [: G6 L
{ ( h8 Z+ p- u& T8 `8 M
int disk; </FONT></P>
+ L3 [9 I6 M6 l8 A; s<P><FONT color=#0000ff>disk = getdisk() + 'A'; 2 r% {7 v2 c7 e/ |. N
printf("The current drive is: %c\n", 6 J7 H. K: y6 B9 n
disk);
* [* e" t0 w/ S) s4 N- }return 0; & Q5 k2 L  }  B, f/ b; l
}
& `1 Z6 S1 J2 r
% X! c- e# ~5 e7 b  x</FONT># B& p2 \0 Q2 V! s
</P>
) L. F2 j: V" R<P><FONT color=#ff0000>函数名: getdrivername </FONT>
) u9 D$ i5 x+ z) V9 S5 H- w; p功 能: 返回指向包含当前图形驱动程序名字的字符串指针 5 @; a8 u' p; X
用 法: char *getdrivename(void);
7 |9 b5 C4 {& J4 `8 t程序例: </P>( m7 s4 |+ a4 m0 W! K0 _0 l6 x5 }: R- v
<P><FONT color=#0000ff>#include <GRAPHICS.H>
% t& B4 ?  X8 n  W/ Y; o#include <STDLIB.H>
# E0 g, i9 c! \# I! O#include <STDIO.H>
8 J+ H6 A$ o6 R8 q  y; h+ V# ]! U#include <CONIO.H></FONT></P>3 w/ k( T9 `3 w+ j' x4 e
<P><FONT color=#0000ff>int main(void) : E3 T  z9 n* j9 P2 ]
{ ( q4 Q, E6 j$ {6 t  j+ P- C( \' ~: N
/* request auto detection */
- i3 i3 \0 \" h) C/ w- y: lint gdriver = DETECT, gmode, errorcode; </FONT></P>7 d4 p' F  C) U1 N
<P><FONT color=#0000ff>/* stores the device driver name */
, u' U" u) `1 F: b9 g/ t3 \char *drivername; </FONT></P>
4 a+ E0 o1 `6 R: s+ i<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 p' p+ I. ^0 K: F2 C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>: Q# b8 L/ d; G. s6 a* c
<P><FONT color=#0000ff>/* read result of initialization */ ( ?* L' C# q  W: x# \- i0 Y
errorcode = graphresult();
/ C5 p0 J3 j- Q- s, f, q6 \- k/* an error occurred */
  H: |4 m$ q. P& dif (errorcode != grOk)
" K  E& m  s. @- ^$ ^5 m{
3 ]5 R- c& E5 m6 [" O# yprintf("Graphics error: %s\n",
% ^2 ~6 @! i2 S. r  @( z# cgrapherrormsg(errorcode));
8 |. [+ f& a$ o  s8 A5 n* o1 bprintf("Press any key to halt:"); 3 A& S4 ^6 X: m! z
getch();
8 r% v/ w9 p$ A8 @" h/* terminate with an error code */ / y/ z2 E* g% E& _
exit(1);
0 f( z6 y# |( `1 `( {& E" A} </FONT></P>, r4 N* E" P/ ?7 M0 m7 W. \* E- `) P& w
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>3 ]& u& r4 \+ [6 _4 g
<P><FONT color=#0000ff>/* get name of the device driver in use */ , C2 R+ v6 C; g& y1 A
drivername = getdrivername(); </FONT></P>
4 i- V$ F2 Z& x' r  {8 q<P><FONT color=#0000ff>/* for centering text on the screen */ , a. H. g+ }: x7 x" |  H. A
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
% |! X* v# X1 k7 m5 @<P><FONT color=#0000ff>/* output the name of the driver */
- }) I/ g# I) m( o/ uouttextxy(getmaxx() / 2, getmaxy() / 2,
# Z9 J/ K2 Y! L* P& m0 Bdrivername); </FONT></P>
4 C4 X" @8 W. W+ d' h& l+ [<P><FONT color=#0000ff>/* clean up */
3 v; ]/ B& k- o' C& Tgetch();
, Y* G9 O4 }$ ~7 a) m1 sclosegraph(); 0 }/ |3 M( Y% v7 E7 D
return 0; ! t5 u% C7 O% G/ r6 o& b
}
5 m) |& {: e8 U% e</FONT><FONT color=#990000>$ r8 g2 h. W! A/ c
</FONT></P>
. E3 r' e' ]) V/ y<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
+ q3 @$ ~4 r/ ~& v  P( F2 M<FONT color=#000000>功 能: 取磁盘传输地址 - h" _0 j% K. c1 m1 c
用 法: char far *getdta(void); 5 {+ Q( x* q( s" _( |+ _
程序例: </FONT></FONT></P>
8 _: l( Y( l3 u! ]<P><FONT color=#0000ff>#include <DOS.H>
& u3 l5 A: R7 \/ c- L5 J9 d) y#include <STDIO.H></FONT></P>
( o# }, E( \/ B7 U  [( u<P><FONT color=#0000ff>int main(void) ) j* U. A% i0 C7 F6 ]/ z: ^& k
{ - W7 R. P- a# f# f3 c2 B
char far *dta; </FONT></P>
9 Q1 R8 f& ^9 v: Q<P><FONT color=#0000ff>dta = getdta();
5 H; n# ?) s" \; [! |& L) @printf("The current disk transfer \
8 ~0 ~$ K! _- z- L- T7 kaddress is: %Fp\n", dta); / ]; y# H* J7 @3 N1 \# [  q
return 0; 2 t4 ^; a% k  r' Z% p4 R
}
! X( f2 M" P( {3 t& Q" t" _7 L</FONT><FONT color=#990000>
/ c" I: b$ I# L9 P' O</FONT></P>& x2 _7 ?7 _3 W7 G& Y8 r. M
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>( O) P( S* ~4 ~1 ~
<FONT color=#000000>功 能: 从环境中取字符串 * m# y1 t, ^: S/ H2 n  y) Q
用 法: char *getenv(char *envvar); & d9 z. @( Z3 o
程序例: </FONT></FONT></P>* i2 l5 ^6 b7 F0 W) K; b
<P><FONT color=#0000ff>#include <STDLIB.H>3 F) h( Z# K9 ^2 _: Z
#include <STDIO.H>, x' v# `% H9 r
</FONT></P>
) Q5 W0 z+ L: t- @% R<P><FONT color=#0000ff>int main(void)
2 S! i% |5 I: C9 ]6 T" S1 U5 }) |{
3 r# r1 j, @0 H3 Nchar *s; </FONT></P>, a. l2 b8 j  F$ F9 H8 X
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ / Z" s& {* s5 M6 X; S7 s
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>. w: M2 R& ~, _! |1 a$ H7 Z
<P><FONT color=#0000ff>return 0;   {+ T6 a3 T8 @# s  T$ d7 v
} </FONT><FONT color=#990000>3 ^3 q1 {* X6 @2 `4 D' d
2 w6 ]7 z. s8 N+ O" X5 S. b' K

# u! r# Z( h9 e1 X% O. T: p# @</FONT></P>
: U) K8 u# w+ a* d, t<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>
8 Z" l& ^; w3 ?  k. g0 Z4 b) H功 能: 取文件分配表信息 / N1 b0 f2 S" A2 `# P: v5 @! X0 j6 T
用 法: void getfat(int drive, struct fatinfo *fatblkp);
# |, K" G# U9 D, C程序例: </P>9 N% g; S* x$ _
<P><FONT color=#0000ff>#include <STDIO.H>
3 w" X* C9 N; ~! O! |2 Z#include <DOS.H></FONT></P>
" }9 k* y6 w3 \<P><FONT color=#0000ff>int main(void)
" E0 B3 @' @& j3 v9 Z8 i9 E" }{
& R: _5 A/ h  I  W9 A, E( Bstruct fatinfo diskinfo;
2 R! _9 b1 k9 d  g! Fint flag = 0; </FONT></P>
- T% O6 e( D) g8 b<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); % P" g+ w" m  A; |
getchar(); </FONT></P>' h6 O7 W$ Q% _- C: c- W* x, {" i% M
<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
' E# R) t; q7 i% d0 ?3 ~, Y/* get drive information */ </FONT></P>& j9 ~" W- p/ N" A: [$ g
<P><FONT color=#0000ff>printf("\nDrive A: is "); 5 h& T) l* {" q( g* {' B
switch((unsigned char) diskinfo.fi_fatid) 3 h  Z: _) E/ y, Z, y. j% ], w
{ ) X6 b! q9 {- K
case 0xFD:
5 d" q' p' e7 q( l9 J1 n6 iprintf("360K low density\n"); ( a# J# H" U; B7 t( Y8 q
break; </FONT></P>
, e1 x  E3 \; p: E* Z' J<P><FONT color=#0000ff>case 0xF9:
/ l# `! g$ t0 _* j: ?) J8 i$ X* ~" X4 Jprintf("1.2 Meg high density\n"); % r+ `3 A, P# A" {5 o
break; </FONT></P>
3 @- f( s- p% G1 x<P><FONT color=#0000ff>default: & o* @3 D; k# T' U
printf("unformatted\n"); . F& o7 O& G1 E' y
flag = 1; / B* R3 D0 A+ n1 }8 ^
} </FONT></P>& F4 L5 j2 h0 e, D9 m  L( x
<P><FONT color=#0000ff>if (!flag)
% l* A1 D& ]5 H( r1 v{
. _+ M" r* I8 Q5 R1 kprintf(" sectors per cluster %5d\n",
* K+ R: c, _8 ?0 i$ wdiskinfo.fi_sclus); # C$ a2 ^! r3 o- F& g6 U: K
printf(" number of clusters %5d\n",
5 Y( g" ?2 g6 cdiskinfo.fi_nclus); * H! Q. I/ d3 [' [& j" K; ?
printf(" bytes per sector %5d\n",
, b2 h# z9 k9 r; v" Y3 }9 y, fdiskinfo.fi_bysec);
) p7 P7 w. n! j2 d} </FONT></P>
; T, u. |  ^5 B<P><FONT color=#0000ff>return 0;
+ ?* E4 W% C$ C2 {5 Y/ ]}
- U! M% o3 l# I& E3 t$ d" |</FONT>* `8 g4 P* P( b6 q0 S7 j& T
</P>. T0 @% \, T% w% z4 K' G
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
9 F+ j$ s( c, Z功 能: 将用户定义的填充模式拷贝到内存中
8 z4 C( n' s+ `1 V- [3 Y; u! p用 法: void far getfillpattern(char far *upattern);
& D# _0 n8 R* x8 I6 j' T程序例: </P>! Y* R9 u( }( i) r$ w* ~  \
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; ^/ X( N+ Z; }6 {4 X) z#include <STDLIB.H>; m& s: S4 S0 x& z5 T
#include <STDIO.H>: I& S/ L! h1 V4 \2 x$ {& o6 @; G
#include <CONIO.H></FONT></P>2 d, O: t; S% n6 Q6 V5 E, W  p' a1 n
<P><FONT color=#0000ff>int main(void) 0 f+ S, c0 E/ g: B3 f0 D3 {
{
2 \8 b/ m: Q' o5 L3 U/* request auto detection */ 5 |7 w% Y1 S+ A9 s; Q
int gdriver = DETECT, gmode, errorcode; , Z% j4 x4 d$ }3 \: t5 b
int maxx, maxy;
5 ?0 x/ J* f" F$ Mchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
; X7 B* j1 n$ C( t<P><FONT color=#0000ff>/* initialize graphics and local variables */   u# g& s$ ]5 \8 f, \; a
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! f% S5 s* m  R( O: A8 _$ J<P><FONT color=#0000ff>/* read result of initialization */ % r$ y( L  H* H0 D
errorcode = graphresult(); & J* O! e2 \% n) [) J
if (errorcode != grOk) /* an error occurred */
0 \7 B5 R4 c6 z# A1 ~+ ~{
+ a1 w+ J( h5 D! ~: Pprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 @9 ?" L7 a& K6 d
printf("Press any key to halt:");
8 Q9 h& v( k8 A: I7 K/ A7 d) H, N! vgetch();
) t* n, j# `' f! ^8 k; Xexit(1); /* terminate with an error code */ ( s' v* _0 s2 d2 S) T" r* s
} </FONT></P>+ i4 F- ~- `) {+ p7 e
<P><FONT color=#0000ff>maxx = getmaxx(); ) t+ x1 L$ e, l& q  s4 ?& B% R
maxy = getmaxy();
* D1 {2 D" L) zsetcolor(getmaxcolor()); </FONT></P>
( ~: \- B% I" F* u6 l' y<P><FONT color=#0000ff>/* select a user defined fill pattern */
1 u0 E8 e' W- v! H/ b7 ssetfillpattern(pattern, getmaxcolor()); </FONT></P>) x  B2 i) R8 T0 D( e6 ]* W7 S
<P><FONT color=#0000ff>/* fill the screen with the pattern */
5 I/ E2 p5 k+ I! f- L$ z4 F; ubar(0, 0, maxx, maxy); </FONT></P>
, f  p0 D/ F( x+ `: {; X8 F<P><FONT color=#0000ff>getch(); </FONT></P>6 ]7 ~( |. _2 t9 i% n  r# A/ y
<P><FONT color=#0000ff>/* get the current user defined fill pattern */
+ h0 l( f* k, p9 zgetfillpattern(pattern); </FONT></P>8 P# M  P; ^* V! l- I9 [* _
<P><FONT color=#0000ff>/* alter the pattern we grabbed */ ; ~- T9 m8 N5 p- c& ?8 x
pattern[4] -= 1;
$ [# p" w, S8 B. {, I0 Mpattern[5] -= 3; * j; `9 ^6 k: E6 g1 }2 Y4 S
pattern[6] += 3;
. e3 K8 N  {1 {3 D" Npattern[7] -= 4; </FONT></P>
6 N% Q) P, @1 N7 C<P><FONT color=#0000ff>/* select our new pattern */ ; n, x! ]5 D/ M8 P  ^8 D
setfillpattern(pattern, getmaxcolor()); </FONT></P>
8 T4 b5 p0 B; _4 C) e<P><FONT color=#0000ff>/* fill the screen with the new pattern */ * o, @& L" S/ u! c
bar(0, 0, maxx, maxy); </FONT></P>  h% ]: x2 W8 {( n8 _7 h
<P><FONT color=#0000ff>/* clean up */ + }' ?4 ~. z2 W% E
getch();
& U6 p; V' a  jclosegraph();
0 D+ p8 d# T! h+ B5 n! |6 k* }2 `return 0;
* l+ Y$ r* }% {9 d3 G}
+ b) a7 X2 d8 _6 v8 t3 y6 U& Q</FONT>
7 ]) o; o( d! M9 P+ M$ a7 {* P</P>
6 A! T5 P( U: y8 W<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
+ u& k5 d7 B* I- I2 ?功 能: 取得有关当前填充模式和填充颜色的信息
$ G/ @' I$ ]1 o) I: k  X& _4 Y$ }用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); - x4 A" z' v2 d6 z
程序例: </P>/ h( @1 }" ^  m5 X3 E
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ X2 d1 g$ j0 |; ^! w" g: F#include <STDLIB.H>
9 g9 L* ^' i* T. C#include <STDIO.H>
7 T  Z. m6 H4 V8 r#include <CONIO.H></FONT></P>
* W9 y9 t( K) z  J, p1 o6 v<P><FONT color=#0000ff>/ the names of the fill styles supported */ ' H: |# @2 H& g& l8 U- u
char *fname[] = { "EMPTY_FILL",
5 s  A/ E) T( J/ j( h  T2 z"SOLID_FILL",
% d( r( a' p  f2 ]' C"LINE_FILL", & o+ q5 z( T2 D
"LTSLASH_FILL",
% O. S" U/ r* n5 u% U2 B* i"SLASH_FILL",   [3 t% Z* @# B
"BKSLASH_FILL", 6 ^4 T, y$ V2 H
"LTBKSLASH_FILL",
& d4 P1 }; e& `# `3 c"HATCH_FILL",
, c) w. |, G" ?. {"XHATCH_FILL",
( g' j, b" ^6 [2 p; N"INTERLEAVE_FILL",   I6 c& i* [8 I( O4 ~" I$ I
"WIDE_DOT_FILL", " H, e" y: j2 @/ t  Z
"CLOSE_DOT_FILL",
: s$ d4 l: d9 ^"USER_FILL" 3 `) z  O9 d. Z: v
}; </FONT></P>3 n) c. N2 f! Y+ q& t( b; r& D. H3 f
<P><FONT color=#0000ff>int main(void)
' d, y! T$ k9 s, E; l3 G{
  ]: u* Z+ Q. I% s- Y2 F  E/* request auto detection */ 5 {4 Z3 r1 Q0 f6 V( J, e- y; Q
int gdriver = DETECT, gmode, errorcode;
1 S: G( p( q' l8 x: xstruct fillsettingstype fillinfo;
6 O4 c# n& _0 H( q8 X( ?int midx, midy; 5 u9 y% O2 `' Z" v: V
char patstr[40], colstr[40]; </FONT></P>
' m$ H7 V. U3 l7 ^<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 m3 y! @  j6 H2 A7 C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, Z& l' ]; Q: ?0 Q
<P><FONT color=#0000ff>/* read result of initialization */
' Z' {5 k- c% M/ ierrorcode = graphresult(); 3 F; G- b; Z+ z
if (errorcode != grOk) /* an error occurred */ / F) G4 p, }% T: q& [4 @6 A! O
{
$ u/ v3 V7 ]3 l& Y. pprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 l: v$ q( S7 {7 T
printf("Press any key to halt:");
, C% l8 _1 ~' J3 U0 R; l3 p, f6 Lgetch(); - B, ~$ S6 q& V! ~5 W- W$ a
exit(1); /* terminate with an error code */ & Q/ e' [" G3 d
} </FONT></P>
; ~% D, ^* ^0 R" z1 o5 m<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 E4 M/ M. e; V! I) imidy = getmaxy() / 2; </FONT></P>
4 G& x: c) t# b& ?6 S<P><FONT color=#0000ff>/* get information about current fill pattern and color */ 9 ^  v) b( K2 U
getfillsettings(&amp;fillinfo); </FONT></P>5 V4 k) [5 S% ]& ~' j6 P, H
<P><FONT color=#0000ff>/* convert fill information into strings */ ; p9 _4 S4 b! v  G( W
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); * w; `' j) {3 W& C6 N, S# m
sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>; N" x7 t0 ~' o! a
<P><FONT color=#0000ff>/* display the information */
$ V3 V1 P7 I) X5 a" [/ Rsettextjustify(CENTER_TEXT, CENTER_TEXT);
, }# t) |! z: n9 h( ~outtextxy(midx, midy, patstr);
& ?+ x, e. _! H+ ]/ e2 uouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
1 w: w: A% T& r1 p+ s9 G1 H<P><FONT color=#0000ff>/* clean up */
6 S  W, D! K* g  {$ o# a$ ]9 Vgetch();
; H% _$ |5 e. v  F& {" S4 sclosegraph(); ) ~- V) o6 y4 z/ Y0 z
return 0; 6 e7 T& s7 a9 e" V2 P
}
4 ^: M( g( e$ b2 j</FONT>
6 D5 C' k1 T; ~7 z
5 {4 g# }, i% y3 _( g</P>: K" _& y) t; E$ l7 \; f, X; g9 a
<P><FONT color=#ff0000>函数名: getftime </FONT>' u9 ^) x% g# m' o
功 能: 取文件日期和时间 6 z0 f% \, ~8 U" d0 Z; p# J+ W
用 法: int getftime(int handle, struct ftime *ftimep); , J  K' K# R7 @+ v9 w( k" ]7 X
程序例: </P>
8 G/ H2 u6 c# s0 L" K0 |7 _0 Y<P><FONT color=#0000ff>#include <STDIO.H>
8 A) D8 B1 v- L* {9 _#include <IO.H></FONT></P>% ^% p8 M+ p. j( S
<P><FONT color=#0000ff>int main(void)
$ v' `* l- q" a) a{
9 @2 ]) {. S- H& u8 a3 G% s  aFILE *stream;
3 @$ A+ I( k2 ?+ g, wstruct ftime ft; </FONT></P>0 t, k9 T: m6 }# |7 R7 J
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
) J$ ]$ r. z: ?2 D% x& o2 J* Q3 K"wt")) == NULL)
/ D7 k, h( L; s2 h# v{
: N6 Q4 P- k% q' o/ W) m& rfprintf(stderr, - \% c! ?  j: t$ Y* D+ W) Y
"Cannot open output file.\n"); ' N3 a: }, o9 w+ X( z' i. g
return 1;
6 w; Z/ i/ r8 s} : k5 a6 c! R/ z! h( ~
getftime(fileno(stream), &amp;ft);
4 ?7 Z( @2 _; k5 G, `2 ?3 K+ g4 Kprintf("File time: %u:%u:%u\n", % S! X2 g; s, Q6 w
ft.ft_hour, ft.ft_min, ( i8 |6 g  s9 |! S
ft.ft_tsec * 2);
& B7 C6 I. r+ K3 x, O# ^. ~5 L9 vprintf("File date: %u/%u/%u\n",
! D' n$ i' q' @ft.ft_month, ft.ft_day,
# K; X/ B2 z. P0 _ft.ft_year+1980);
( O* u7 Q. T/ F  q( ?fclose(stream);
6 d2 O( B/ ]0 {) O4 treturn 0; + H( E; d# ?1 `$ O
}
& v9 i2 X& O4 _7 ]</FONT>8 W. q8 `+ n( W$ _

! ^% @7 c- H$ ]2 A6 J1 i9 j</P>
' D& I0 u) Z. u<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
; s5 d1 @' `" \. }% E' r功 能: 返回当前图形模式 3 {$ G5 O$ N  P9 v8 c
用 法: int far getgraphmode(void); 9 N3 W6 G& X! m' A7 [
程序例: </P>
7 q; ]: i8 Y9 C/ v0 w* }/ Q<P><FONT color=#0000ff>#include <GRAPHICS.H>
) P! X( x8 @! r! q+ m2 m#include <STDLIB.H>: e- a/ s/ p' p+ {" j. e. P. A
#include <STDIO.H>
3 n' g: ?& O) \#include <CONIO.H></FONT></P>0 _( i5 h. K5 ~0 e: x0 Q- @
<P><FONT color=#0000ff>int main(void)
3 n4 H3 J5 v) f, J& b! ]0 l  Z{
! k! A6 y$ w  T8 d: l/* request auto detection */
/ I2 J6 M0 g7 w; d9 Oint gdriver = DETECT, gmode, errorcode;
" S$ h6 H; T6 @: @* aint midx, midy, mode; 6 n" m! P; W' {# c3 j
char numname[80], modename[80]; </FONT></P>
" S- E! V2 O/ D& P6 z" T) B<P><FONT color=#0000ff>/* initialize graphics and local variables */
: d" r" p4 }6 e- J; X* @5 Kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, q5 @4 d( p9 R' R/ f% Q" y* T
<P><FONT color=#0000ff>/* read result of initialization */
3 ^( X0 M( J2 B# m/ Q% p1 i" werrorcode = graphresult(); 5 \0 e8 V( A. }7 N1 e
/* an error occurred */ ' t1 L# K8 B4 |2 q
if (errorcode != grOk) . z$ D6 F& o4 i  T: U* l
{ - A  X# M$ M1 g2 E. C
printf("Graphics error: %s\n",
9 q& y9 S6 O1 y# ~$ E! n  e1 ?grapherrormsg(errorcode));
9 p5 [3 W* W% c: `/ Qprintf("Press any key to halt:");
1 L7 m4 E5 q4 \. k. vgetch();
! p( c& s  ^2 A7 ]/* terminate with an error code */
  g3 v5 W! L  D; H4 G' Pexit(1); 3 v3 D$ D4 s6 v1 j; r  [. u
} </FONT></P>
5 r! S. d$ k4 w& z; U" a7 K<P><FONT color=#0000ff>midx = getmaxx() / 2; 4 z, T- k; ~! K) Q! z: ~
midy = getmaxy() / 2; </FONT></P>2 m# N5 U' I, U
<P><FONT color=#0000ff>/* get mode number and name strings */
: ]2 r  [2 [) Vmode = getgraphmode();
$ t; u5 j! f, W$ f3 dsprintf(numname, * H+ w' M0 a6 P& S3 n9 m6 X2 j# ]
"%d is the current mode number.", 7 F* }* Q( o1 L& K  z
mode); , ]' N8 C: \( T8 |. E
sprintf(modename,
$ v7 y* E5 L( z( }5 a" u$ N"%s is the current graphics mode", - A6 f. P( G' J1 @9 Z
getmodename(mode)); </FONT></P>7 P" c* D$ P# M) H/ i
<P><FONT color=#0000ff>/* display the information */ 1 z+ w+ s( s8 q' _6 U
settextjustify(CENTER_TEXT, CENTER_TEXT); $ i4 D8 w% \9 {6 S2 H
outtextxy(midx, midy, numname);
$ {6 X# Z7 t6 s9 k% Qouttextxy(midx, midy+2*textheight("W"),
9 u& \. e/ D7 n6 smodename); </FONT></P>
# `- d+ {* t# r  i0 u3 x<P><FONT color=#0000ff>/* clean up */
2 x' ?  g$ x% Z  S* o5 \6 Ogetch();
4 [! u& V0 e( Y+ K- d2 cclosegraph();
+ q4 M7 s; c( s! F5 F9 h( Treturn 0; 4 v- R! s2 d3 |' X( G8 B5 k
} </FONT>
' j& l2 [: r1 [3 I; w# v
1 t* y; F& z, _" f& w6 }</P>8 d* H6 s4 c& Q
<P><FONT color=#ff0000>函数名: getftime </FONT>
( F0 m/ a- I" }4 R0 z功 能: 取文件日期和时间
: K1 c  ^& E5 E* W& u# O. T/ f/ @用 法: int getftime(int handle, struct ftime *ftimep);
; I. e; E; S* F" J7 L程序例: </P>
) T8 L' o% r1 O' f! ~2 t2 [<P><FONT color=#0000ff>#include <STDIO.H>
6 R8 s5 K1 y- [0 a#include <IO.H></FONT></P>
' S* J' S8 o- q4 A# j: p* `; o<P><FONT color=#0000ff>int main(void) / c6 Q9 ]) u0 v% n
{
& {. o; U, }& kFILE *stream; 8 @) h& N4 T2 P
struct ftime ft; </FONT></P>3 F2 p2 j1 X1 Z# d% G
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
$ k( ~4 {/ e; j6 B"wt")) == NULL) : K1 C) j0 @4 p
{ 3 I5 k6 k) J+ _# E9 \, C! T
fprintf(stderr, 8 n5 P8 U. y; E6 o* K% p4 ]5 p; X
"Cannot open output file.\n"); ' E0 Y/ `* D  r& a
return 1;
! t* D3 u/ e) ^8 X9 G" o}
( @: L+ ^. b. {1 O" J+ @getftime(fileno(stream), &amp;ft); 5 S5 N  W5 J( |- O9 d
printf("File time: %u:%u:%u\n", - k! z' @5 l4 a! H) X0 d& J
ft.ft_hour, ft.ft_min,
" V  w: k2 ]  U9 j( U& R2 k' Kft.ft_tsec * 2); & O% r: k5 q$ h% K4 U
printf("File date: %u/%u/%u\n", 3 ~9 ]5 C+ Q$ v3 Y
ft.ft_month, ft.ft_day, # K- R- ]0 e7 s: E% O# ]7 {( A
ft.ft_year+1980);
6 |/ w4 g/ k, G8 n4 gfclose(stream); 5 v5 K3 g) q* A
return 0;
( {5 E" c  J8 p# v- \* t  ?) W} </FONT>7 L9 d, W$ @4 Q* h

7 V% ]! W4 x  b9 s# ^
) ^9 r0 T1 J% E7 |8 f9 h- ^* t# d* o</P>
- z* g" }7 Q+ u0 T5 M6 Z+ ?* o/ ]<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
& `0 d2 J/ t1 \" Y/ U功 能: 返回当前图形模式
2 j, s/ W- z/ Y9 K0 ~! s: z用 法: int far getgraphmode(void);
$ Z+ }4 e  f, g  F8 e, N6 X8 B程序例: </P>
; N3 S2 Q3 U' Z% I7 M<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 Z* U* k3 H: W/ c+ d# y$ u  W#include <STDLIB.H>
. _( m5 n+ ?+ w2 M( H5 ?- d#include <STDIO.H>& Z, Z2 @) Y+ z( w- k- [
#include <CONIO.H></FONT></P>; S, f, @# P; `) }8 P1 c
<P><FONT color=#0000ff>int main(void)   ?" ^2 ^2 \6 L8 f4 A  _
{ / w+ h5 _0 R/ ~# l$ L
/* request auto detection */
" I/ i3 x' Y5 ?int gdriver = DETECT, gmode, errorcode;
6 D0 W1 i; b3 E0 r" pint midx, midy, mode;
# l" Y$ }' C3 v- N5 t: schar numname[80], modename[80]; </FONT></P>
) ~$ J7 b  A0 x7 U<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ ]9 _" O, A% Tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 y  r0 e8 a3 |) W3 H9 N$ A
<P><FONT color=#0000ff>/* read result of initialization */
% m% I& g5 c4 ^' Aerrorcode = graphresult();
) X3 `. D- l( w4 B, ]* I. M/* an error occurred */ & C5 J4 a& I6 Z0 Y2 G4 B& u, n
if (errorcode != grOk)
  L! K, y& Y1 C; {4 L{ 0 m) R& `, |1 T/ \
printf("Graphics error: %s\n", ( w7 q/ K6 g) V3 C
grapherrormsg(errorcode));
9 B( \* x/ G$ ~: u9 Iprintf("Press any key to halt:"); & n, u7 u7 F: C$ J% N
getch();
$ w1 H1 t) ?7 Z* h9 ], |4 F/* terminate with an error code */ 4 {9 _5 f$ H5 O! K/ K& i
exit(1);
4 c# Y1 E' x6 v} </FONT></P>
2 h) R* h: ?. c- I<P><FONT color=#0000ff>midx = getmaxx() / 2;
' s9 R8 V$ [$ [: x% p/ K$ A7 imidy = getmaxy() / 2; </FONT></P>
, ^# f  z: m5 N4 B* p9 o0 \$ \2 z( `<P><FONT color=#0000ff>/* get mode number and name strings */ - ^" ~  ~: K: B1 C/ n7 b8 u
mode = getgraphmode(); , s2 `+ S8 t6 a- V
sprintf(numname, $ y. i9 O% m8 O3 j8 q
"%d is the current mode number.", ) i( [3 b$ |+ K# g5 ]' v
mode);
1 x5 B' @" W- @/ Csprintf(modename,
5 ?9 }& X( X1 o% o# U% D# k! P"%s is the current graphics mode", 0 \. p  o8 f' T4 P9 q+ H
getmodename(mode)); </FONT></P>& E' Q( y7 Z% [) }* s: ]
<P><FONT color=#0000ff>/* display the information */ " q: P  ^" b" t: T* d" M7 D" ^8 k
settextjustify(CENTER_TEXT, CENTER_TEXT); ! v9 W, z* T/ [5 n& s( W! V
outtextxy(midx, midy, numname); , v9 y4 I9 G5 ]( D
outtextxy(midx, midy+2*textheight("W"),
) B, d2 m1 o4 K9 `$ smodename); </FONT></P>( f5 r, q  R% j
<P><FONT color=#0000ff>/* clean up */ 9 P/ d+ C$ B( M, {% ^, S0 K
getch();
& z: P1 M+ r# w7 W5 c  hclosegraph(); $ p: H0 c* Y7 D% [9 F* y+ b+ W
return 0; 9 ^+ @* {6 e) n
} 5 v# a+ L5 ]( l4 I2 F6 L7 H, B
</FONT>
! D3 @1 m9 i2 |1 T1 v/ }</P>
- o) I! N5 x6 E* S8 ~( p<P><FONT color=#ff0000>函数名: getimage </FONT>
0 d! {7 [' R- {功 能: 将指定区域的一个位图存到主存中 , W: |7 D( M8 H  S5 ]3 a7 T2 D8 A
用 法: void far getimage(int left, int top, int right, int bottom, / N! |  ^. _  z
void far *bitmap);
  K2 |* ~, |# y9 f) [程序例: </P>( B. \, ~$ C3 s/ O! M
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( Y  E8 i8 Z% h  E#include <STDLIB.H>
7 Y  M6 ~$ _  |% J, E9 R* H4 i#include <STDIO.H>
! W9 [( X- Q; D* C2 p5 j$ Z, l3 Z#include <CONIO.H>
% j/ j% h7 S4 W' A5 G" o8 J#include <ALLOC.H></FONT></P>0 j- ?$ M  d/ F) o( u% m
<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
% e5 ?5 g1 b7 I9 U4 X& evoid restore_screen(void far *buf[4]); </FONT></P>
0 R* F4 r2 t( _/ S8 i0 n4 k# l6 h<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>9 D" M+ d2 j; x- f, \. D+ g; _
<P><FONT color=#0000ff>int main(void)
/ a  ^$ W: y: P6 R$ B% n& n{ 7 }) y* A5 i/ ^+ A: r2 H
int gdriver=DETECT, gmode, errorcode; # I6 Z+ _$ _* D  Y
void far *ptr[4]; </FONT></P>5 s" y  d* C4 B/ M. D
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
' ^: w" C+ d+ [5 Linitgraph(&amp;gdriver, &amp;gmode, "");
. {, h: ]+ m/ s6 L! B3 Uerrorcode = graphresult(); /* check for any errors */ 8 Q9 G2 @$ d0 G0 J; F8 y6 c. `
if (errorcode != grOk)
6 [- C5 c: A$ N8 q! q# l/ ?{ % i. i( f4 J, w. `+ E* Y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # ^, j6 k8 _6 ^$ O2 }' g( R1 L% i# m2 Z7 a
printf("Press any key to halt:");
# H' z" ]# ~7 R4 h  O# \: n. V4 }getch(); / i$ e6 v4 c# h7 z' E+ }6 R# p2 i5 j
exit(1); 3 R* [) z* A% A! O/ T5 }
}
5 ^+ z) v# y2 ]$ F9 ^maxx = getmaxx(); / C) _+ M' [7 s
maxy = getmaxy(); </FONT></P>: b0 Y% |. W: P: n
<P><FONT color=#0000ff>/* draw an image on the screen */
: j( D# Q1 `. O2 J; C* G( qrectangle(0, 0, maxx, maxy);
5 s% k: g, _/ Y. ~2 q( g8 M/ J8 jline(0, 0, maxx, maxy);
* x5 K: W( F( h' V! d" G2 D5 Z4 ^line(0, maxy, maxx, 0); </FONT></P>" h  d* _8 y! E' k8 B) e( D* L
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
+ C. _  _0 X2 \; h! I& c, agetch(); /* pause screen */ : a% Q, \2 e' i% G3 B
cleardevice(); /* clear screen */ ' t$ E. J) m9 l& R# ]( t  K7 d
restore_screen(ptr); /* restore the screen */ % Y, T7 f) j6 w5 C/ j
getch(); /* pause screen */ </FONT></P>
* e: P% \; l+ p3 n5 ?# s" o<P><FONT color=#0000ff>closegraph(); & F1 l' ~) [( m$ w: T
return 0; ( X4 z( V$ |' l  a) R' Z9 h$ W
} </FONT></P>
& {1 T+ k! X2 @* U: `<P><FONT color=#0000ff>void save_screen(void far *buf[4]) ) q. p) L. F; O% ]' _
{ ' H) c: x& W/ ]/ Q2 R
unsigned size; 3 U+ Q& p& C* c; D3 n
int ystart=0, yend, yincr, block; </FONT></P>; {; Z7 [9 z6 j* C. R
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
8 z/ L* E2 M9 l, e$ r5 qyend = yincr; ) y) i  J5 @6 [6 y5 y
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
& K8 w5 d* J2 x4 ?$ _2 V. C<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
0 P3 s5 B9 D% O- o! t& N{ % g/ E5 V: ]3 G
if ((buf[block] = farmalloc(size)) == NULL)
7 N& j+ b4 n# U+ X) ]{ * r; Z4 E2 V2 ^% k1 }7 ]
closegraph();
- i3 N+ l/ z! o! B/ ?printf("Error: not enough heap space in save_screen().\n");
3 G' s) B: _+ [6 U/ ^exit(1);
9 [4 ^* s3 v" Y+ I} </FONT></P>
0 H  m" W, w! W, E+ _) T% Y& [% N<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); # u" G9 B( u4 h* }) c
ystart = yend + 1;
+ `7 q( F  \, }- T! tyend += yincr + 1;
% j$ [, ?; y; J$ c, c} ' j; b' J/ R8 r- ]8 ?% @
} </FONT></P>
5 O5 w. h- t! z; U" q9 ?<P><FONT color=#0000ff>void save_screen(void far *buf[4]) , |/ p. m; y+ t% C1 D. u" x
{ ; K2 x% e( P% K: h8 @& m, N
unsigned size; & f/ i8 a( x( u  ^* A
int ystart=0, yend, yincr, block; </FONT></P>' \( E% h3 _& d6 ^0 Q1 l) Y
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
( b% Q( P- q( e5 A) kyend = yincr; 5 q8 ^! x+ M& O% o
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
2 P. ]3 u& R4 w  i  R! G9 R/ g<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
) K; L3 `. O8 [8 I8 k{
& C2 W9 I  M5 {" k5 Kif ((buf[block] = farmalloc(size)) == NULL) 4 z' f# j# t1 `6 W
{ 3 K8 b- N% Y0 q3 i4 ~
closegraph(); 1 j- u6 p0 Q' H3 Y& }0 G4 W
printf("Error: not enough heap space in save_screen().\n"); & c+ N4 N# W8 K) g# ~2 A
exit(1); 3 H' X( {( N# W4 J  e) {; I  x& j9 i
} </FONT></P>6 I" Y# l$ g# c" ^+ N, V  F* {4 j" F
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
: z) G1 l& m5 a( t8 {% n# n2 Q1 \ystart = yend + 1;
! ~) a: W% ^2 ~1 xyend += yincr + 1; , V% X1 p7 v$ e; W2 c
} % l! T# D5 d. O: ?# P
} </FONT></P>
, d! I+ j* w# w  c* S<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) % \. C% z) \$ l9 D8 ]2 m
{
% u3 Z1 t. b5 U- Pint ystart=0, yend, yincr, block; </FONT></P>
) A" C! a# q2 [8 S' ?7 k<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
# @: X2 W6 E( H5 u9 p  I1 Ryend = yincr; </FONT></P>
3 K& u' f# D1 Y( \( P! N3 G<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
; h$ H  Z: Z  ?5 b8 X" ?4 j{ 7 O$ J5 r1 I2 W& e( [7 O
putimage(0, ystart, buf[block], COPY_PUT);
; G; @) l* P! Rfarfree(buf[block]); 3 [! Z6 M" `) U. z
ystart = yend + 1;
* d/ u' P* {( ?  tyend += yincr + 1; : o' B* p* w2 y! o6 I. G
} / W! P! N, K' y( I& n! T) h
} </FONT>. O6 }" _- y! t. r/ s) V3 E* ~
<FONT color=#ff0000>
2 |1 T6 @. }/ y</FONT></P>8 M: P3 d5 ^3 _% j  r- D
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
$ Z. r# |! D6 t' s. u( e功 能: 取当前线型、模式和宽度
1 ?! D2 d! A4 r: C5 E7 y+ v" U& o, q用 法: void far getlinesettings(struct linesettingstype far *lininfo): 5 ?$ m! x! I  c1 A) s) \: F
程序例: </P>% [8 i# F* O8 G) K2 S+ N# B
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" d- ^  Y! r3 B0 S$ c, m* ~6 `#include <STDLIB.H>
! p/ P& u  a5 |& K& M9 @% D7 O#include <STDIO.H>& I; _% H0 e$ v; _0 q
#include <CONIO.H></FONT></P>
2 f% @- b; [8 ~" W<P><FONT color=#0000ff>/* the names of the line styles supported */
9 A4 Z& M* q/ b1 o) D& h2 G& ichar *lname[] = { "SOLID_LINE", . H  n/ \( }% _+ ]
"DOTTED_LINE", ( w# T1 J( m% [) c
"CENTER_LINE", 9 R& s; B1 t4 Y$ e' ~
"DASHED_LINE",
$ C4 s: D4 y* c  N"USERBIT_LINE" & u- @0 G# y0 m3 c
}; </FONT></P>
( V7 o! l  i/ ?& ^$ T* n* b<P><FONT color=#0000ff>int main(void)
7 K/ J- w* l& C' b( R{
# P4 Z; u' n- A3 p) t. l/* request auto detection */ / r' i- {- s0 \. L; W
int gdriver = DETECT, gmode, errorcode;
0 p6 {3 w: X; t6 zstruct linesettingstype lineinfo; " k) H5 _* F  }) D  p- C$ I% J
int midx, midy; 1 A; J& K! F1 m( H: `
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
$ f4 I# c8 w1 w<P><FONT color=#0000ff>/* initialize graphics and local variables */
! f* X0 i8 {. {0 A6 Uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 F# I' K$ F$ A; Q; n$ e0 |<P><FONT color=#0000ff>/* read result of initialization */
1 k& \) ~3 o0 Merrorcode = graphresult(); ; O& z* ~7 |1 W& @3 E+ L  L" s. J
if (errorcode != grOk) /* an error occurred */
5 W. d5 H8 X4 R- `{ $ O+ L. L9 S/ a$ _; }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 d. a' o6 I- z9 p$ K; ~; \printf("Press any key to halt:"); , X9 q% G& s, z# z7 E- ^" n
getch();
" F6 G- _& q) ]) A# _exit(1); /* terminate with an error code */
6 i1 x7 _: J* m! h/ d} </FONT></P>
  F) q1 I' N, O1 [% H' c, R7 L<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 W. B; @( j6 j, f5 C: t
midy = getmaxy() / 2; </FONT></P>
' |" ?% y5 h3 O2 R. T- C<P><FONT color=#0000ff>/* get information about current line settings */   k2 y3 X1 q: w1 g
getlinesettings(&amp;lineinfo); </FONT></P>
" y, Z7 a: a1 g+ }) d<P><FONT color=#0000ff>/* convert line information into strings */
$ D; V/ g5 D8 E3 q$ i3 }( ]sprintf(lstyle, "%s is the line style.", 8 f" w1 B0 `- W9 B! K
lname[lineinfo.linestyle]); # x+ ^  u, B) l& D: v. T
sprintf(lpattern, "0x%X is the user-defined line pattern.",
; l! ?1 x; a! S, Z- |& P' \lineinfo.upattern);
4 o" |( Z7 P+ k' f7 @, L' Y# Q5 rsprintf(lwidth, "%d is the line thickness.", 5 o  Q/ a* h( ]8 a, Y$ r/ O
lineinfo.thickness); </FONT></P>5 n3 m' m- ]6 A% h) @( L3 X
<P><FONT color=#0000ff>/* display the information */
- ^( b: M; b3 x2 Z0 ^- g. |6 \2 Ysettextjustify(CENTER_TEXT, CENTER_TEXT); 7 u% b9 S. K! E
outtextxy(midx, midy, lstyle); ! I5 K  z0 ?( V4 @9 X% N
outtextxy(midx, midy+2*textheight("W"), lpattern); 5 p, `1 v; b1 |' \6 m' Z2 z
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
, J' q( }  n7 P+ g. }& w<P><FONT color=#0000ff>/* clean up */ : m& `. @# f: y) ^* E/ ~- v" e
getch(); ; F* k6 g5 O8 K2 M2 {( A7 q& K
closegraph();
: P0 Y. [" f0 ]" g$ G! _8 [! yreturn 0; 4 q! J: {0 t  I, p5 b, ?( I' J* @) z
} </FONT>4 r4 S# [/ b5 A  y, A

2 k7 V& G% k& X; W5 Y( M9 Y</P>) _0 L! Y4 ]" Z0 G" t% D, e! T
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
) }+ ^& [1 \6 d& ^, D功 能: 返回可以传给函数setcolor的最大颜色值 7 ~  C. L! K, K( Q, p- l
用 法: int far getmaxcolor(void);
6 O: g' c1 h% h4 I- v程序例: </P>
4 U: L; x0 Y% Y<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 b: R# C3 J: O" C, k#include <STDLIB.H>7 T8 s$ H: D! H- Z6 L4 d
#include <STDIO.H>2 G/ P# e% \) I+ r2 c7 K
#include <CONIO.H></FONT></P>9 M6 G1 k& U: p4 d; _
<P><FONT color=#0000ff>int main(void) 3 c, ?% w  ?% J' ~" Y
{ ; D3 P& N* t% A2 B* F% k- l
/* request auto detection */ ' \* I1 Y, Z& P. K2 _7 W
int gdriver = DETECT, gmode, errorcode;
! @: C! ?) @# R$ L4 m: o$ n8 A  jint midx, midy;
; z5 }( @4 t" w1 O, l4 b- _char colstr[80]; </FONT></P>
  i6 ^0 x; c, S4 w- e7 y$ @, n- F<P><FONT color=#0000ff>/* initialize graphics and local variables # v* v% x$ D! M, O
*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. C1 T2 v+ F; q1 N
<P><FONT color=#0000ff>/* read result of initialization */ " f- D, Y7 B1 t$ S/ v
errorcode = graphresult(); 9 R5 S. s; [) C( s5 y
if (errorcode != grOk) /* an error occurred */ + F1 X* M( j: c
{
: V: _" [" e2 X$ wprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . j& Y( `4 n2 ^; _- \/ w# A
printf("Press any key to halt:"); ( s+ g, [6 H% x. @8 ]3 B+ |: `, L
getch();
  p5 s/ f: `2 l1 Sexit(1); /* terminate with an error code */
) m9 F+ j7 s+ P: L! N$ A} </FONT></P>" p8 V- h7 d2 `; }& x$ T/ X, W
<P><FONT color=#0000ff>midx = getmaxx() / 2;
$ a' n- G0 u' I6 Pmidy = getmaxy() / 2; </FONT></P>
; `( I' E$ y4 N4 r1 c1 B<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
9 Q7 v$ M; I, E$ \8 H+ l0 \2 q- j4 Vsprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>9 T; T4 }: U, T- f8 T
<P><FONT color=#0000ff>/* display the information */
+ }6 }3 x" N* ~8 Zsettextjustify(CENTER_TEXT, CENTER_TEXT);
; [; j1 f$ p) j9 Z( couttextxy(midx, midy, colstr); </FONT></P>. H; ]( N" G; O9 F5 P% i
<P><FONT color=#0000ff>/* clean up */ " E6 E. u7 Z7 ~$ B
getch(); 7 \. E4 @, G( c
closegraph();
& u7 F5 U0 A& K7 j. g* Ereturn 0; $ m8 W" h. L) U0 Z( x
} </FONT>; E" G& u) ?: R$ g, W  R
+ S+ x' L# r& A/ A

! m% C- T; l' ^3 `+ R& v: C7 ]</P>* v8 e8 \8 I. L* p! f
<P><FONT color=#ff0000>函数名: getmaxx </FONT># K# c. [4 V0 G% g1 }" J
功 能: 返回屏幕的最大x坐标
9 G3 [& v: P  A4 S, L4 @用 法: int far getmaxx(void); : H7 J- `, U4 j7 ?4 h; V. u2 A( S
程序例: </P># D0 _) b0 @; [) O* x- y9 [5 @
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 O* _, Q2 j  h3 ~# N
#include <STDLIB.H>' f, f2 Q! O( l+ ]) y
#include <STDIO.H>. l$ h" q: o$ a( j
#include <CONIO.H></FONT></P>
& S0 v8 j4 }% U& m. h. [<P><FONT color=#0000ff>int main(void) 5 i) B3 m+ \+ j6 ^7 E# r
{ 3 u0 V; w' `. P. k
/* request auto detection */
2 z# i  D9 a: e0 ^( N% Q$ |% Qint gdriver = DETECT, gmode, errorcode;
! k6 S. C. X2 D" U( ]! b% \! w3 n* @int midx, midy; ( m  G, L7 H* K$ q7 V- f
char xrange[80], yrange[80]; </FONT></P>
' t0 j3 h# M5 D<P><FONT color=#0000ff>/* initialize graphics and local variables */ / W3 S) |" l9 o+ o* W/ D' o8 |& \* g% Q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ N7 n0 a7 A! \3 R1 V$ G. U
<P><FONT color=#0000ff>/* read result of initialization */
3 V% z: L' o9 s) W/ x2 |% Verrorcode = graphresult();
5 F' ?* q2 K# Q& o6 a) ^% iif (errorcode != grOk) /* an error occurred */
$ M( O  @9 Y5 d9 @{
5 v0 v5 `: A# Z( n" ~1 Vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 }: U  ]" N9 Mprintf("Press any key to halt:");
. k1 s2 i: \  b8 wgetch();
5 k$ [2 C2 j# ?- Y  i$ cexit(1); /* terminate with an error code */
# p+ H: h1 e4 Z' r; S7 Z} </FONT></P>
+ ^( G/ g! O' J( a, t: K<P><FONT color=#0000ff>midx = getmaxx() / 2;
) ^9 R( r# S, jmidy = getmaxy() / 2; </FONT></P>. K1 z( b8 G9 n( w5 o6 U
<P><FONT color=#0000ff>/* convert max resolution values into strings */ 4 P  K; S! h7 k7 _
sprintf(xrange, "X values range from 0..%d", getmaxx()); 3 s/ f1 q( X/ }/ _9 f
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>( I, c  Y; L# P5 W8 d4 j: }9 x
<P><FONT color=#0000ff>/* display the information */
0 U0 v+ s0 `0 i/ [settextjustify(CENTER_TEXT, CENTER_TEXT);
: r- g$ W1 x) m% m+ routtextxy(midx, midy, xrange);
" _) T" P. s/ q3 Y: couttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
+ Z+ c- n. w0 `; Y- v<P><FONT color=#0000ff>/* clean up */ " s1 f. M/ ~7 [1 |  i
getch();
/ y) W# f$ ~" F' f$ A9 f- D4 Nclosegraph(); 3 I+ b# l0 |+ p# _7 p) w9 i
return 0; 8 N6 |" _8 g* K# Q
}</FONT>
1 a4 K$ o2 O0 s4 B# W. i
( q5 `2 y) j3 ?, f4 J</P>( f# W/ Q6 x8 N2 e. M
<P><FONT color=#ff0000>函数名: getmaxy </FONT>
, H$ I% x" J/ Q5 w& l6 b! G功 能: 返回屏幕的最大y坐标
& ]0 g- l& o2 o$ j9 T/ C1 p1 R用 法: int far getmaxy(void);
+ P- H. M. v. L7 y* d/ C程序例: </P>
! U0 }3 K4 S5 c. O! I6 A3 v" f3 b<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 \3 S5 H8 ^+ W/ L. J5 g/ j#include <STDLIB.H>
8 ?4 c$ U* ?2 u  G6 p: C#include <STDIO.H>
* G$ s" H! }$ ?& X; f# j( {#include <CONIO.H></FONT></P>
0 t! m$ t0 Y: _+ r" O<P><FONT color=#0000ff>int main(void)
2 k- R8 X$ _& E) t* v& s, z# B  j{
, ~3 y# x# F' p/* request auto detection */
1 t! C1 B5 K/ ?int gdriver = DETECT, gmode, errorcode; # B( }; t! o: l
int midx, midy; ) m' ]+ z$ u5 a3 i8 ~
char xrange[80], yrange[80]; </FONT></P>
; n$ W1 o# l5 R: v5 o5 l; _<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 t' z* Z* Z: dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# B& i+ G! X# W: i" f" r: o<P><FONT color=#0000ff>/* read result of initialization */ / N; Y4 F1 _/ v! z( _7 ?
errorcode = graphresult();
8 T8 _8 c& H: a0 \/ t2 }2 C% o$ yif (errorcode != grOk) /* an error occurred */ - a4 r/ a2 i& a" b/ {. i
{   k0 [, W. }. Q/ q6 }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
; Z7 f1 @, J: v6 |  ]0 }2 ^6 Qprintf("Press any key to halt:");
9 l8 Q# c2 l3 B( L, q, ?& fgetch();
2 A4 g9 S) a+ U  R# ?) @exit(1); /* terminate with an error code */
1 e3 d+ n0 H) |} </FONT></P>" i( {; f. W1 K. r4 B: q" |2 o
<P><FONT color=#0000ff>midx = getmaxx() / 2;
/ p1 y4 Z0 w0 M  K3 U+ Tmidy = getmaxy() / 2; </FONT></P>
) ]& I" n; O" Y$ q6 v8 s. |  Y<P><FONT color=#0000ff>/* convert max resolution values into strings */ 2 I- p$ h/ }$ i  c. C
sprintf(xrange, "X values range from 0..%d", getmaxx());
; z( [7 Q/ S: Q8 ~  H/ g- psprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
1 }, k3 t, N* V0 ]' P2 e0 V<P><FONT color=#0000ff>/* display the information */
: [- a, Z7 d6 o, z# Y* W7 [/ Isettextjustify(CENTER_TEXT, CENTER_TEXT);
" p5 Q/ H1 t/ x: X, c: h- n. d, {outtextxy(midx, midy, xrange);
+ {& _, n! L/ F7 G3 x. m3 ~* aouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>% h* @. ]4 ]& \6 |* W* A/ V1 Z  l4 D
<P><FONT color=#0000ff>/* clean up */ 5 l: [8 H. y0 ]; a0 T/ P
getch();
& ^: o; n+ W& }  [6 t( f* ^closegraph();
; P; v  U1 G& I' ireturn 0; . Q6 S" U/ V  _! B9 I
} </FONT>4 v8 H" t" x/ ~' W2 j. [- l
</P>
5 @4 Y" F4 q( t3 |( A1 w/ F% t<P><FONT color=#ff0000>函数名: getmodename </FONT>
& P0 \: _1 a; e- n9 ~功 能: 返回含有指定图形模式名的字符串指针
9 v5 p' w2 @- u0 C5 t) K用 法: char *far getmodename(int mode_name);
* v5 ]0 E% L, O4 ^" t程序例: </P>: ]9 G; P- F* [: S5 ~. D* F
<P><FONT color=#0000ff>#include <GRAPHICS.H>+ R4 K- x, i1 J. ]& Z1 Q
#include <STDLIB.H>3 q# ?& f' X5 s/ S2 l$ h
#include <STDIO.H>3 M  u5 X1 n* A  o
#include <CONIO.H></FONT></P>( r- h( T! X2 j
<P><FONT color=#0000ff>int main(void)
% C' s: M! F0 [! [. u6 X3 T{
+ p% p9 \, |  y. R/* request autodetection */
* j6 R! M& {( K2 Q8 v- B: ?3 oint gdriver = DETECT, gmode, errorcode;
- j# c( ?! ~' a+ I5 {0 |int midx, midy, mode;
3 O7 X7 X8 J, ~$ Mchar numname[80], modename[80]; </FONT></P>8 A1 e5 [4 w! R+ {1 D
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 q+ E2 C! u5 h9 j4 B% l" N  Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 P, `/ \, V2 ^; _' i
<P><FONT color=#0000ff>/* read result of initialization */ " V3 _0 J% U! z7 g  {" d$ h( f* f
errorcode = graphresult();
$ |& y% P6 A* f1 S$ S+ e$ I) Bif (errorcode != grOk) /* an error occurred */ / Z) i* P( q" [: p. D3 k
{
6 w5 f( z. v5 vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 E" K/ S% f3 I& ]5 mprintf("Press any key to halt:");
( |- _4 Q$ v, ^: U- N6 Mgetch();
! d* q, @( O  t0 D6 `, c6 _exit(1); /* terminate with an error code */ 9 m0 t# _# W: x+ k# [4 }" i
} </FONT></P>( ~; x) R6 T* B# K
<P><FONT color=#0000ff>midx = getmaxx() / 2; - C$ _' b: w% M3 g. Q; X; i. r
midy = getmaxy() / 2; </FONT></P>( \) ^. B; ]7 ]  j" p0 q
<P><FONT color=#0000ff>/* get mode number and name strings */ " i( @+ N4 |# K
mode = getgraphmode(); * |2 O/ P. A; I) G, ^: m2 T
sprintf(numname, "%d is the current mode number.", mode);
( P0 ]6 a+ u0 Q. r2 z  R' f/ osprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>& a0 {) n2 m9 j& h2 R
<P><FONT color=#0000ff>/* display the information */
2 v* U7 z) ]) O& {' P, D* C8 S, asettextjustify(CENTER_TEXT, CENTER_TEXT);
( z0 [5 O8 d  D: \0 M. Louttextxy(midx, midy, numname);
+ x: ?$ Y2 h0 z5 s, T, K( ~! Vouttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
9 ^0 k4 C- D- C9 f  w/ D- n<P><FONT color=#0000ff>/* clean up */
5 v' L3 V/ x/ ^5 E9 }getch(); $ w) A; F) ^) B8 [
closegraph();
6 B3 x2 @( V3 U4 t0 p2 I% I1 Kreturn 0;
$ `- Q4 P4 w9 o! \2 c} </FONT>
8 I( F% y. u# G% D0 x! A2 F1 L+ G( }" D7 s: c9 ]) s6 W
</P>6 f& I: u; [  e7 ]1 a  o
<P><FONT color=#ff0000>函数名: getmoderange</FONT> 3 }- K) _: F2 ]( e
功 能: 取给定图形驱动程序的模式范围 3 L. y  y% W# _
用 法: void far getmoderange(int graphdriver, int far *lomode, 9 L% w( F$ k6 _% u, X3 M
int far *himode);
! g9 b( j8 x- ~- X3 {8 |程序例: </P>4 o' J  R5 k2 a, n1 P  I/ ?) e
<P><FONT color=#0000ff>#include <GRAPHICS.H># H  G4 W5 |/ c# b  B
#include <STDLIB.H>
2 i% w4 D  r" b+ c#include <STDIO.H>
* r/ v$ H+ t2 D( t#include <CONIO.H></FONT></P>! B, q) c9 [% {/ j. l9 G
<P><FONT color=#0000ff>int main(void) 5 m7 Q/ l; e5 Z7 M% }9 \
{
  @, ?; p4 l: g2 z$ k; p( v, V, K/* request auto detection */ 9 f. c; T( Y, _* L, U7 l% s" y1 k
int gdriver = DETECT, gmode, errorcode;
6 V+ y" ~  K( C0 q9 f$ {int midx, midy;
: d' U3 R# v" [; `  rint low, high;
5 T6 D6 }: Y" _6 ^& c9 cchar mrange[80]; </FONT></P>% P1 m# d% z' }1 w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 Z2 ^' D1 O6 m- J* E4 Oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" j/ d; U2 u" I8 Q4 s<P><FONT color=#0000ff>/* read result of initialization */
) ?; D+ F' r3 Y4 ?$ W0 R& Ierrorcode = graphresult();
  r* X1 L3 v( p2 Dif (errorcode != grOk) /* an error occurred */ * `1 N$ ^  H+ d8 E9 _
{ ' T/ L* Y0 R; t
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % A. w# Q0 ?2 I- G+ t
printf("Press any key to halt:"); # T# ?. ]. c) k
getch(); # i" _4 `) c# A- s7 p: Y& }
exit(1); /* terminate with an error code */ ( c- }7 k, ~, V
} </FONT></P>
) r6 C) w2 V8 l5 u- @: `+ n<P><FONT color=#0000ff>midx = getmaxx() / 2; # m% `6 r4 }3 j* S! J
midy = getmaxy() / 2; </FONT></P>- H- c5 f2 y  u  b
<P><FONT color=#0000ff>/* get the mode range for this driver */ ( y8 }: A( @: u' H  g# C
getmoderange(gdriver, &amp;low, &amp;high); </FONT></P>, v5 w7 I" w2 s0 e0 G
<P><FONT color=#0000ff>/* convert mode range info. into strings */
) U; i; D- y$ X6 jsprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
2 c6 ^6 p; v6 d' f<P><FONT color=#0000ff>/* display the information */ ! j+ p/ |1 s$ b
settextjustify(CENTER_TEXT, CENTER_TEXT); " o" H5 j! \( @. ~/ P& c# Z
outtextxy(midx, midy, mrange); </FONT></P>4 l( d8 H. J: n1 [' A6 _9 z
<P><FONT color=#0000ff>/* clean up */
( V  I: X) `; n7 C, D+ r+ g9 Egetch(); $ u, w4 A2 A! L; t# b. [: z
closegraph(); ; f2 ?8 N* L5 Z1 Y  Y6 S
return 0;
* H6 ]2 P# ~6 k! {' `} 5 T4 l1 _' J; G
</FONT>
' d( n0 o9 z2 K) P' _, C  @( O</P>, S) B% Z; q+ c4 P$ w
<P><FONT color=#ff0000>函数名: getpalette </FONT>
5 p) M: n; x% S% r0 }- _4 [8 [: j功 能: 返回有关当前调色板的信息
: c6 O1 K3 s% ?, B. Y用 法: void far getpalette(struct palettetype far *palette);
8 ~4 E; \( s2 u2 p3 X$ E# g& D$ o$ k程序例: </P>! h2 r0 z6 u+ J  B
<P><FONT color=#0000ff>#include <GRAPHICS.H>4 h5 i6 S! R2 g( ~- W# d
#include <STDLIB.H>
7 o1 g) x7 }5 h2 L, s#include <STDIO.H>
. f, I8 u* B" W9 d#include <CONIO.H></FONT></P>: p3 P! M) X. J5 k8 ^
<P><FONT color=#0000ff>int main(void)
6 E6 W5 R" M1 t" i0 l! F. @{
, D+ u8 }  L4 n/* request auto detection */ ! K" o( j7 K+ a
int gdriver = DETECT, gmode, errorcode;
4 |+ Z  K5 w: l$ P$ Y6 a1 Dstruct palettetype pal;
5 x5 t) x* w( S$ o) L. e7 P2 rchar psize[80], pval[20]; ' T1 q" S4 {6 F: w
int i, ht;
4 Q- U0 Z( x& P% qint y = 10; </FONT></P>
+ O: Q7 O; a& [$ W2 J! y. k<P><FONT color=#0000ff>/* initialize graphics and local variables */   a: [: v& u9 ?6 L
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% {0 O1 p0 d7 s<P><FONT color=#0000ff>/* read result of initialization */ # {- M3 s$ s' P  M
errorcode = graphresult(); 0 a' i+ I% v. m4 P6 v- S6 U
/* an error occurred */ & M9 a$ d0 z. L& y1 t
if (errorcode != grOk) 7 i. d9 \0 R( _4 M
{ 2 C9 ]$ _" l4 ^5 K' b& D; r
printf("Graphics error: %s\n", 4 l1 Y4 Y% e; C7 _
grapherrormsg(errorcode)); : G- T: d3 D; ~4 N. ^7 ?& Y
printf("Press any key to halt:"); & T# a' w* B6 u9 g" M
getch(); , |0 A  F& w- ^0 E0 n
/* terminate with an error code */
, I1 u1 Z! G+ qexit(1); + l4 ^% {2 P4 N. n8 j$ s. \1 l
} </FONT></P>2 f  Y8 g6 I* k% }% H
<P><FONT color=#0000ff>/* grab a copy of the palette */
! W; t1 F0 u0 d; D0 K* ?$ P5 T8 U9 kgetpalette(&amp;pal); </FONT></P>& Z! L7 t' H- U" K
<P><FONT color=#0000ff>/* convert palette info. into strings */ * E5 R, P! A$ B! L
sprintf(psize, "The palette has %d \ * R5 R( W" i, e$ p, g" N4 q
modifiable entries.", pal.size); </FONT></P>' R! b- C: X8 J+ v
<P><FONT color=#0000ff>/* display the information */
% o# u( O* Z7 A3 b# o4 `, q( N$ }outtextxy(0, y, psize);   j2 B3 w9 O  _5 A- L. v# D9 ^
if (pal.size != 0) ) a7 a! y$ s, ?
{
/ r2 M. }: w" E/ X5 kht = textheight("W");
/ i/ b8 B: d0 c- Z, Z2 J* Z& ly += 2*ht;
0 L/ o% u* u, ]) fouttextxy(0, y, "Here are the current \ . d% R* B/ p6 b+ v: K; d2 _' R
values:"); ' H& j& h( ~2 X- y& g0 u6 f
y += 2*ht; 5 R, `/ _1 [  ]$ \( r1 m7 ~
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { % F$ a, D) `+ }4 t$ C
sprintf(pval,
& @5 g# n7 V9 B) y( v7 y"palette[%02d]: 0x%02X", i,
0 m/ D0 e/ ^$ g$ X7 E* ?, _pal.colors); ! m- A6 j2 d$ Q. A
outtextxy(0, y, pval);
& p; f9 ^. a- E5 e3 x} , U- l# F( i, @/ L5 J
} </FONT></P>1 m3 P: J. W0 K! n9 T. h1 M0 \! N
<P><FONT color=#0000ff>/* clean up */
7 W5 V9 m6 X* \/ Z9 r- J5 l6 fgetch();
; d! h! E. A3 w& H! m3 ?$ K8 Gclosegraph(); </FONT>; E) M6 ~1 j( e! t
<FONT color=#0000ff>return 0; $ R- v) m" }9 r  s2 G) r0 O
} : O8 _! n4 C7 r) ~6 K- }
</FONT></P>/ T9 z9 ~7 L" h+ O0 _4 R
<P><FONT color=#ff0000>函数名: getpass </FONT>
4 ?- d& I+ v) R' W0 H功 能: 读一个口令
5 S  C/ p9 j9 q7 y# ~8 @用 法: char *getpass(char *prompt); 9 Y6 H; `% f! d" E
程序例: </P>
; ~  \2 ~! V% N% e; p7 K6 @+ d<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
4 Q" r6 H+ O( P/ }6 t<P><FONT color=#0000ff>int main(void) 0 }+ n* q7 D& g' ?- e" b
{ 5 F! _. n% I3 e8 ?8 e) j+ c
char *password; </FONT></P>0 r% D" H. }- J" m2 ^
<P><FONT color=#0000ff>password = getpass("Input a password:"); 4 I8 |4 ~1 x5 _4 |2 L
cprintf("The password is: %s\r\n", 3 Z" q4 c% ^7 |" p
password);
$ \3 e4 t( [# ~' @( Y! ereturn 0;
8 n7 `, G! T" c* b) e- }}
1 g6 r7 I% f9 D( f</FONT>& W" I+ B# _0 p8 M- i0 X% p' }

# s  s3 {) t4 Q</P>2 u, a5 M: S8 ]% {* W" ]& v
<P><FONT color=#ff0000>函数名: getpixel </FONT>
2 S. G' L# L. q/ y( N8 l+ u功 能: 取得指定像素的颜色
+ F# ~+ Z0 U* X6 |* E3 K用 法: int far getpixel(int x, int y); ! `  u) X" i8 \2 X* s. p
程序例: </P>% [: O, m; B# B# y- q, m
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  K- G) |6 Z) i3 ?# M2 q; }#include <STDLIB.H>% {/ h: {# b, e+ u4 n5 ?5 j
#include <STDIO.H>
% L. |) j4 f+ y5 ]6 t#include <CONIO.H>8 R! A1 Z, v& d: m0 \/ w5 z. E1 s
#include <DOS.H></FONT></P>
. p4 X. n6 b2 p/ \3 B) y  D$ D<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 % r9 q$ }+ R) Y
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
7 `6 g; o' C( _; I- u<P><FONT color=#0000ff>int main(void) ' q9 e1 h; L: V/ p
{
$ n$ s  ^' i- \* x- F/* request auto detection */ + T; v, @3 @/ t1 }
int gdriver = DETECT, gmode, errorcode; + [( `- d- }1 N9 H. [
int i, x, y, color, maxx, maxy,
( C7 ~( s5 \; rmaxcolor, seed; </FONT></P>' d0 t. z; o0 ~
<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 c! ?8 Y7 S: q7 o' qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( l2 \3 D  w% B: ~
<P><FONT color=#0000ff>/* read result of initialization */
9 @4 v" e5 [/ A/ k1 t3 U3 l; ierrorcode = graphresult();
+ m9 J* m- A( X% V  l/ c/ V/* an error occurred */
8 ?/ v6 Y" g% H3 jif (errorcode != grOk)   e8 [, F- @1 e! R+ m& X) X
{
2 R: ^5 y& W- A: [9 t% _8 [printf("Graphics error: %s\n",
: O" L' ?$ G) Z+ r. X. G* egrapherrormsg(errorcode));
  r7 r9 y2 j$ v! iprintf("Press any key to halt:");
0 l% \( G0 f' i  `# jgetch();
* m7 y0 R; r! O: _9 T8 M8 c. L0 o% [/* terminate with an error code */
4 B6 T$ B5 O# u7 h; {! vexit(1); 7 P/ s& x/ L2 A+ F
} </FONT></P>
: _  V( j5 Y2 Q$ Q% F0 ~5 O. V<P><FONT color=#0000ff>maxx = getmaxx() + 1;
$ o5 O1 X8 d( `, c  l9 ~maxy = getmaxy() + 1; 2 ]! ~' X1 W! l' Z
maxcolor = getmaxcolor() + 1; </FONT></P>
7 |) z6 b8 t8 Z% p! ~<P><FONT color=#0000ff>while (!kbhit())
7 @+ _/ Q' b( k8 |6 g/ e{ 2 @- W3 K% _: a8 {+ L: k* _0 M% W
/* seed the random number generator */ 8 q* j% B! t1 X5 H* d. S8 N& }0 U1 ~+ G) |
seed = random(32767);
  N& j4 l) V) ]8 G! z' csrand(seed);
! k5 y6 _7 W8 E; x7 A9 \for (i=0; i<PIXEL_COUNT; <br i++)> { : I5 n2 E3 Q& a# X+ a6 V& U
x = random(maxx);
8 R; [7 r* {; j+ _! }y = random(maxy);
$ {' Y$ C/ z; W1 jcolor = random(maxcolor);
# V: S% s! i0 L6 m1 b' g* r. qputpixel(x, y, color); 6 U5 T. i) Y4 e. C3 e
} </FONT></P>( k1 x% v1 {' w/ G8 [
<P><FONT color=#0000ff>delay(DELAY_TIME);
# @. N$ w1 {. I7 r/ }- [, Rsrand(seed); , T' D% O$ \& `
for (i=0; i<PIXEL_COUNT; <br i++)> { 7 a! }6 M! U: X9 b- e
x = random(maxx);
" N) i$ P6 ^; ?+ Oy = random(maxy);
9 S2 t  ^% d& f/ }# _color = random(maxcolor);
  U( _+ q0 _7 V* L$ Z4 m' x( Uif (color == getpixel)</FONT> </P>
2 Z+ E# t, X. p& P! ?8 |<P><FONT color=#ff0000>函数名: gets</FONT>
3 Y: g0 E$ M; [/ P- N- ]功 能: 从流中取一字符串 " B: Y3 ?5 q% [' S# w+ V7 u1 f9 [
用 法: char *gets(char *string); - U+ D6 c5 }5 C, @7 O
程序例: </P>+ \1 m" w+ Y& {( K
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>6 \0 l3 C# u9 m* H- n5 Q9 ]! @9 E
<P><FONT color=#0000ff>int main(void)
" S( j1 S! u& @' _8 A/ M{ ! Z# S0 B. {6 {% i) L
char string[80]; </FONT></P>: K! Z8 l8 P- K7 p5 f3 W% y# ?" g
<P><FONT color=#0000ff>printf("Input a string:"); 6 T2 N- _7 t2 S" P& u9 ]% B6 j. t8 \
gets(string);
0 r0 x% }9 a0 q: D3 _: W4 Gprintf("The string input was: %s\n",
2 {. O, q# A! d$ w6 |8 S* Cstring);
, F0 c& W: A: ?6 j1 d0 Sreturn 0;
- c7 J+ g- p0 {% l! K& ?}
1 {8 L- l7 ^/ [" y9 W6 r0 n0 W3 ?& Z( r1 b" G# H
</FONT></P>
- j& O/ Q# P8 r7 ]: W<P><FONT color=#ff0000>函数名: gettext </FONT>
/ J) m% D) O/ P: J6 u* Z功 能: 将文本方式屏幕上的文本拷贝到存储区
. Q* i6 j2 w- H( r+ E0 k3 O用 法: int gettext(int left, int top, int right, int bottom, void *destin); * V1 d" c) l) B5 A* m
程序例: </P>
. U# g0 c, K5 H* W* A% c<P><FONT color=#0000ff>#include <CONIO.H></FONT></P># ?* {% {- I' j4 m$ q. I
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
! }  ~1 ?9 g- b% F6 h4 L' I$ Z<P><FONT color=#0000ff>int main(void) ) z1 b+ Z. |7 _% M! Z& R
{ ; D" K% J5 O5 f5 ?+ w- q0 f. g
int i; ( w" v& s- X0 Q/ l
clrscr();
) A1 q4 x% w2 ^5 r9 n( [& kfor (i = 0; i &lt;= 20; i++)
9 C' ]9 b3 e  |" Ocprintf("Line #%d\r\n", i); & z  e7 q- Y! _2 C/ o
gettext(1, 1, 80, 25, buffer);
9 f6 M. C9 k* k0 a- ?4 pgotoxy(1, 25);
9 ^: B% o3 B# c- w  T+ ^/ Y1 Wcprintf("Press any key to clear screen...");
' ]* S& n# R  ^% s3 @getch();
5 n1 D6 [/ Z$ W* g8 _6 aclrscr(); * H5 f/ |( _% L
gotoxy(1, 25); $ Q5 i6 h9 |& D+ W7 q. F8 Q/ Y
cprintf("Press any key to restore screen..."); ) e) r+ s- X  L6 ^- i4 a/ h
getch(); ! c2 T/ r* i/ @) Y, b. o
puttext(1, 1, 80, 25, buffer);
* q7 l7 C, |) {& S1 R# P) Lgotoxy(1, 25);
2 K9 {9 R8 e0 ^6 U& C) ?5 Xcprintf("Press any key to quit...");
4 t7 v2 |  d/ d7 W' p8 o+ Tgetch(); 7 D' \7 u2 G8 g7 Y0 [# V2 w6 J
return 0; 7 j' ]2 }1 X9 ?$ ^" x% }* ?
}
% Q8 e' u% M0 J1 d2 T</FONT>( p+ Q) |" u* a
</P>
- t( K* m- p) D4 l( b- w<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
; y9 J% C, b7 [9 k! p; j功 能: 取得文本模式的显示信息 ( B0 S( A; m/ l8 j% R+ Q4 F
用 法: void gettextinfo(struct text_info *inforec);
, O& c1 S8 m, \4 ~4 q程序例: </P>: n/ |% L0 }8 ~3 V
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
& P! A6 y. W) d' j# A<P><FONT color=#0000ff>int main(void)
" y) j5 }2 w1 p1 ~# w$ O" V- F# @{
! }6 z' h7 M* {  D; L. Gstruct text_info ti;
. s  l8 ?% f3 W- j4 F3 Sgettextinfo(&amp;ti); % l& d- i5 R! A; `3 E
cprintf("window left %2d\r\n",ti.winleft); 0 T9 T$ t- U/ h* ]9 i
cprintf("window top %2d\r\n",ti.wintop);
3 M0 A' n/ h4 zcprintf("window right %2d\r\n",ti.winright); 4 Y, }/ V* y$ B: o+ D. _' N( L
cprintf("window bottom %2d\r\n",ti.winbottom); % B$ C) I/ E& |$ U& N5 ?( @
cprintf("attribute %2d\r\n",ti.attribute); * v- p9 \0 ~7 X' _3 }$ s$ i
cprintf("normal attribute %2d\r\n",ti.normattr); 7 n9 [2 }% C+ Z1 g6 P
cprintf("current mode %2d\r\n",ti.currmode);
/ P- r1 ]4 ?* ?$ W& ?+ Ycprintf("screen height %2d\r\n",ti.screenheight); 5 ]- i4 ^# N- b: l& {( P3 C$ i5 Y) P
cprintf("screen width %2d\r\n",ti.screenwidth); . o$ R1 K8 e( j4 {: l# `9 k
cprintf("current x %2d\r\n",ti.curx); 7 W/ G: y! d7 B" K; e
cprintf("current y %2d\r\n",ti.cury); / L1 v  p- q  r5 ~$ b
return 0;
9 ^1 L' ?. z- `: V: V# s1 H* Q}
: c0 U) q) _) C$ s9 D</FONT>4 m' I1 S" x9 U0 o
</P>' }! U; H- c+ C  x' C1 r
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>  R( u" Z% o+ x. y8 P. L
功 能: 返回有关当前图形文本字体的信息 9 K; Q  m. W! S6 r
用 法: void far gettextsettings(struct textsettingstype far *textinfo); ; [, u3 I6 d9 }0 H. Y9 f! ]
程序例: </P>7 e: |1 }( G( |. O
<P>#include <GRAPHICS.H><FONT color=#0000ff>
; z  V$ c+ L+ j' M# e#include <STDLIB.H>
" \% `  C: I! R9 {) v2 \7 e7 r1 u#include <STDIO.H>
9 F4 O5 d8 E; O+ ^6 r* H#include <CONIO.H></FONT></P>* E8 P0 b% B$ C3 P* i! J2 {
<P><FONT color=#0000ff>/* the names of the fonts supported */
4 D, c0 M# u* i, i* ?7 o' C% ^char *font[] = { "DEFAULT_FONT",
5 [1 R8 T0 i# C+ k; z"TRIPLEX_FONT", ) x. z. f2 c& t. v
"SMALL_FONT", + V) _4 i0 B2 u8 ^! ?
"SANS_SERIF_FONT",
3 j$ ]# X5 T( H2 K4 J/ b: x0 B"GOTHIC_FONT"
* ?, m- P1 V) O}; </FONT></P>  U0 \7 i6 [5 ^& ]$ |
<P><FONT color=#0000ff>/* the names of the text directions supported */
" N' z% d  d. N: `) o- Wchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
. w, F1 \5 l5 d" [: W( P  ]<P><FONT color=#0000ff>/* horizontal text justifications supported */
$ A: E4 H; G  D  tchar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>0 a9 V/ U7 x5 U% z; X
<P><FONT color=#0000ff>/* vertical text justifications supported */
2 q" B( g* f& @8 Xchar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
# [) G$ T' f$ D  `5 a<P><FONT color=#0000ff>int main(void) ) ]$ W1 U6 T" z% G
{ 8 J+ Y4 j5 s* T% R
/* request auto detection */
8 y' ]/ }3 Y& _int gdriver = DETECT, gmode, errorcode; % U/ E! [2 z$ n. d6 `3 m  i
struct textsettingstype textinfo; 6 N) Q7 ]5 Y, V. [6 F8 I! d9 U
int midx, midy, ht; 9 V  X  U# b, o% @& o
char fontstr[80], dirstr[80], sizestr[80];
! {/ Z: L: C' ^7 a0 Y: ]  {$ schar hjuststr[80], vjuststr[80]; </FONT></P>
% o6 O# J. j! @0 a- A  ^6 p1 F, l<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 H/ Q  }6 o- M! \% yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' ^# N1 O' Y3 y8 R, |7 z' m, u
<P><FONT color=#0000ff>/* read result of initialization */ ' h9 P6 L8 L3 y1 L  N
errorcode = graphresult();
- E) N+ `. P, T3 Wif (errorcode != grOk) /* an error occurred */
- Q; \$ Z' \# R6 \( D{ ; t7 q% x; p! e2 {& N! N0 a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
: W$ \+ m$ n5 n" lprintf("Press any key to halt:"); 8 N5 g, |  ^  m+ v
getch(); & Y, i8 G* U% P+ s/ h$ K8 \, J
exit(1); /* terminate with an error code */ * Q! y* J; Y0 S2 {$ ]
} </FONT></P>
: \' H7 x" f* h# k% T<P><FONT color=#0000ff>midx = getmaxx() / 2;
; T  A. f$ d# @# \2 @1 T1 Xmidy = getmaxy() / 2; </FONT></P>
2 J1 Z8 w' v# w& b1 E<P><FONT color=#0000ff>/* get information about current text settings */ ! S0 w" z) E# m& m2 r" N0 J9 C) o
gettextsettings(&amp;textinfo); </FONT></P># y# h. ~3 f. X" L% N/ u
<P><FONT color=#0000ff>/* convert text information into strings */
& ?, A( N: v' B! lsprintf(fontstr, "%s is the text style.", font[textinfo.font]);
. G; z2 n, `0 Y3 V4 ]" U% u/ _sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
! }* D6 R5 \$ f, B/ O' F5 P, ?/ [( ~! osprintf(sizestr, "%d is the text size.", textinfo.charsize);
4 g. y, d1 ]# R) g7 D8 @3 h/ D, k; d% gsprintf(hjuststr, "%s is the horizontal justification.", 2 T( m* ~, B' w8 E: C; R  P
hjust[textinfo.horiz]); # s- a1 e& J$ R' a/ G, L4 @( m3 G
sprintf(vjuststr, "%s is the vertical justification.",
1 {5 m& O+ ^+ Nvjust[textinfo.vert]); </FONT></P>4 @, [3 S- ^' l; J* H
<P><FONT color=#0000ff>/* display the information */ 4 T7 B3 n# N# i  o" L
ht = textheight("W");
4 c' v0 l" y- B( dsettextjustify(CENTER_TEXT, CENTER_TEXT); , u8 q8 s0 ]- V. W
outtextxy(midx, midy, fontstr);
3 w- u& T/ u; h# souttextxy(midx, midy+2*ht, dirstr);
4 ^, v( R8 I7 C& ?0 mouttextxy(midx, midy+4*ht, sizestr); 9 Y5 ?3 g" N& B9 n% [  ^
outtextxy(midx, midy+6*ht, hjuststr);
5 k8 f$ |* A2 I' gouttextxy(midx, midy+8*ht, vjuststr); </FONT></P>
! b9 e2 Q. `, s7 A<P><FONT color=#0000ff>/* clean up */ . Q/ \! c1 _) L5 j, D
getch(); 3 Z: ~8 T; T& P- A( ?
closegraph(); 9 Y$ \- J9 }& G% W
return 0;
9 `% \; E* @* M* ^3 C$ w} </FONT>/ u. u% U) P: o. l
</P>2 t1 e: @# I/ X: j7 p  O
<P><FONT color=#ff0000>函数名: gettime </FONT>
) x* v& w: Z8 i; `3 \/ w功 能: 取得系统时间 ; O& s. F* l; z( l% r
用 法: void gettime(struct time *timep); * m7 O7 l8 z5 Z) v1 q
程序例: </P>! V2 q' h9 P9 ^8 u7 T% j: U1 l
<P><FONT color=#0000ff>#include <STDIO.H>  B$ X" m8 R; E7 @! f
#include <DOS.H></FONT></P>
& z5 d1 J; O6 Z, b<P><FONT color=#0000ff>int main(void)
3 @. ~4 x2 X7 A7 u: z  R{
3 d, q( \: t0 j( ^- p. O) Estruct time t; </FONT></P>
1 l3 M$ L+ x! s; }0 C7 j<P><FONT color=#0000ff>gettime(&amp;t);
( e6 L' c2 L- Pprintf("The current time is: %2d:%02d:%02d.%02d\n",
4 x7 {  u; n* \" qt.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
! \+ I: Y! s  @- Y7 u; ~4 Mreturn 0; 8 v5 O3 e, p, n0 @7 J% \* {2 Q
}
) u; j. k* w3 z- C# ]7 Q8 c4 w& h4 ~$ r" D
</FONT>" F' f. L" v% }- \2 T( t- ^
</P>
8 O0 Y7 d# t0 h' t# k<P><FONT color=#ff0000>函数名: getvect </FONT>+ U9 n" A: }: m1 n
功 能: 取得中断向量入口
* d1 G7 n! _# O0 a用 法: void interrupt(*getvect(int intr_num)); 1 X1 |. ]8 Q: D+ `7 V+ @2 N
程序例: </P>
  Y) V, B, _2 Y' y& |9 ~<P><FONT color=#0000ff>#include <STDIO.H>$ b% F# ?. t! \4 I! B
#include <DOS.H></FONT></P>2 F# U9 c4 I+ Y/ v, |  j
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>+ y1 r7 V  \' `- K
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ 0 m5 w0 ?; z0 f' C0 D. [
int looping = 1; </FONT></P>% w4 V2 n+ _7 `3 t. }
<P><FONT color=#0000ff>int main(void) . l, y" r* Z( B/ L
{ ; A) w: j. Y/ E
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
( r+ I3 |  n0 x% j8 p5 {. @, F<P><FONT color=#0000ff>/* save the old interrupt */ $ z7 D- t1 B4 _8 D8 s7 a3 R7 O& R
oldfunc = getvect(5); </FONT></P>  D: G- c' F4 m( U) p
<P><FONT color=#0000ff>/* install interrupt handler */ + P3 F! H& Q- m) [
setvect(5,get_out); </FONT></P>
; u* p8 T# u5 Q8 p<P><FONT color=#0000ff>/* do nothing */ ( t3 B, Z. ~3 B* K) \
while (looping); </FONT></P>8 t7 Z3 @' I7 f% B# c
<P><FONT color=#0000ff>/* restore to original interrupt routine */ ( [5 @. Y2 W8 |
setvect(5,oldfunc); </FONT></P>4 A# Y, ^) I" [$ b
<P><FONT color=#0000ff>puts("Success"); # y! B" ?4 |6 C6 |: S/ }# `
return 0;
( l4 m: ?6 y+ f+ R( g  n0 q} " K+ o5 Y1 @0 M* _5 e, N% ^( S
void interrupt get_out()
# x5 I* x/ x5 L{ ! J4 R% A9 V  ?% Y8 w
looping = 0; /* change global variable to get out of loop */ $ Z! Y5 J* x2 |- |3 @% @
}
) G1 U: X* Q! {. ]7 C; Q9 E0 m+ t</FONT>
+ g2 O5 \8 _+ c2 d! B</P>: ^1 S7 M2 X5 }5 o( i
<P><FONT color=#ff0000>函数名: getverify </FONT>
' m+ q- R0 v' P- K功 能: 返回DOS校验标志状态
! m/ Y! J4 B( d7 H用 法: int getverify(void);
. Y* p( i8 ~  P3 R& J- g, g4 E程序例: </P>5 w7 e6 P( d2 c& z" G* g
<P><FONT color=#0000ff>#include <STDIO.H>
  O! S# l7 |; |#include <DOS.H></FONT></P>6 t1 N0 [1 d% s& j) K
<P><FONT color=#0000ff>int main(void) " {1 j) t8 V6 M5 C( e0 }
{
. p: i2 y4 D( g5 `7 f$ gif (getverify()) 3 K- A6 D5 K. ?2 v  v8 c
printf("DOS verify flag is on\n");
4 q. m% f" q; t& h6 Telse / [. Z; g( G! r' K4 G, e! q; W
printf("DOS verify flag is off\n"); - x* b5 k: W& |3 Q+ t( y5 _2 m
return 0;
' c! W) x8 s' K4 g2 z8 D$ t( t}
% F. W$ \, V. N9 N</FONT></P>
9 u" p# ~3 u1 t) o7 l<P><FONT color=#ff0000>函数名: getviewsetting </FONT>1 N2 p2 u2 Q8 k7 l4 v
功 能: 返回有关当前视区的信息
! ]' }* F4 v( b+ v* G7 K) }用 法: void far getviewsettings(struct viewporttype far *viewport); 4 f# E5 W9 C. h
程序例: </P>
$ ]: S/ M# ]$ y. P<P><FONT color=#0000ff>#include <GRAPHICS.H>
% N7 e$ T# f* V: N#include <STDLIB.H>
* l+ U+ T" @1 B- N! {#include <STDIO.H>
2 x& h0 ~/ c) `* v#include <CONIO.H></FONT></P>
1 P. E2 h  v" E<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
/ \7 }/ P( {4 B, I7 ]; ~% D6 V<P><FONT color=#0000ff>int main(void)
9 g5 G2 h% x* d{ 8 ~$ ?( s2 [) S# I" d! |5 a! m: h
/* request auto detection */
. x9 q0 y# s, g( c3 b- Tint gdriver = DETECT, gmode, errorcode; 5 B- ]. f8 g! }: K
struct viewporttype viewinfo;
9 v9 H; Z) B2 C$ r0 p, g( Mint midx, midy, ht; 2 W( ]2 |) C$ h! f' D+ ]
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
. P8 y6 F* ]+ n<P><FONT color=#0000ff>/* initialize graphics and local variables */ - u+ N/ s5 s1 a( C1 y3 ^
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 l, u. @- e: H2 y8 _
<P><FONT color=#0000ff>/* read result of initialization */ 9 x9 i0 B' d; A8 g- I; r, z( a
errorcode = graphresult();
- s' t3 h7 C% S' g* bif (errorcode != grOk) /* an error occurred */
# _; n9 G" @0 W{ . p! \% i- G, E* M: g5 r
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ |" M4 W8 B/ \4 _3 Zprintf("Press any key to halt:");
: ?0 q+ w/ h  c3 |getch();
1 V( ]6 V9 s6 m# l& w- yexit(1); /* terminate with an error code */ 2 w6 w9 J+ V5 G# g* W( L
} </FONT></P>3 u# k, j* q/ G" V
<P><FONT color=#0000ff>midx = getmaxx() / 2;
! @+ W: l' G' Q0 k. _1 o% dmidy = getmaxy() / 2; </FONT></P>
& L# R/ H7 a7 ]8 G/ |" n<P><FONT color=#0000ff>/* get information about current viewport */
8 k( S- U& [( bgetviewsettings(&amp;viewinfo); </FONT></P>
' Z( Z) D5 f, q' E; Q! K/ b<P><FONT color=#0000ff>/* convert text information into strings */
0 Q6 ^+ W: _; S& K8 z. D3 i& Usprintf(topstr, "(%d, %d) is the upper left viewport corner.", 2 U( Z( u% d' {
viewinfo.left, viewinfo.top);
9 R$ f% O/ ]0 ~sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
( x% ~& `: C  A& M5 Uviewinfo.right, viewinfo.bottom);
( I2 {: s) O1 z# ~) h2 D5 W. x. j$ s$ `sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>5 @' a: s" {' \+ Z. e% B% u
<P><FONT color=#0000ff>/* display the information */
1 V$ l/ p7 U# g; x$ f) n% T  P0 T' Ssettextjustify(CENTER_TEXT, CENTER_TEXT);
; _0 B6 f1 `* J8 e8 k; Qht = textheight("W"); ) g2 e, W' g! U6 w% @
outtextxy(midx, midy, topstr);
" W% j5 d5 L% ?6 I; I  K6 X, kouttextxy(midx, midy+2*ht, botstr); ' ]2 z" G, K2 j; O& l1 N7 b% b, a
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
  c" R" z8 ^6 U" w. M<P><FONT color=#0000ff>/* clean up */ # e- e, F' d9 {. Q
getch(); : Z% x8 j; d) X4 E1 F
closegraph();
' R$ {# i5 D; w7 r, @$ rreturn 0;
3 q" m% |( R0 o, D5 Z! _; p} </FONT>8 |) `% }) }9 j# d5 E6 {8 i
7 w8 W  [0 H: d( ~2 B) E6 _
</P>
, P; i0 ]3 D- C+ n; d<P><FONT color=#ff0000>函数名: getw </FONT>+ H. \7 W6 v" c- R2 [, K
功 能: 从流中取一整数 8 }; h6 A! b  M$ w( V( `
用 法: int getw(FILE *strem);
7 }4 d! C5 C* P. x3 \: k- F0 T, S; M/ i6 K程序例: </P>
* y4 q7 x  M+ l: c% b% q<P><FONT color=#0000ff>#include <STDIO.H>
8 |# u3 _& Z% j- ^2 s- \4 o. ]5 D& x1 c#include <STDLIB.H></FONT></P>
* S# y3 ^  M( P/ _/ [' ]<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>7 I2 D) |$ k% k6 i
<P><FONT color=#0000ff>int main(void) 0 I, r2 ~( f/ C+ W3 P
{ 2 g5 s5 {3 |3 U. z8 ?. P" C
FILE *fp; ; H) t, b5 K3 L" N2 i9 z: D! V
int word; </FONT></P>
* N& H  `' o6 ]3 p  B<P><FONT color=#0000ff>/* place the word in a file */
- L( y$ n5 \! F% ?fp = fopen(FNAME, "wb"); , F9 C- ~9 F4 p( @! n0 ~- q" U+ W. p, T
if (fp == NULL) # y. @( w4 |! V; H* S+ w
{ , m: I( O3 d0 ]
printf("Error opening file %s\n", FNAME);
7 L' b) T( O2 m9 c/ Y. L9 eexit(1);
2 l7 K4 d' x# m& {( k} </FONT></P>
( A# j4 r5 t5 w; o$ V6 A! F/ z8 B! [<P><FONT color=#0000ff>word = 94;
6 T) H# N" F$ J6 s( {% F/ Qputw(word,fp);
! j1 d+ a0 U4 h6 Aif (ferror(fp))
6 c% w" q6 F; Eprintf("Error writing to file\n");
5 @5 q! d+ Y- Z* y- Telse 8 G- i# {/ l2 I: A2 j  W
printf("Successful write\n");
4 U6 V; {: T4 N/ d9 v* W3 tfclose(fp); </FONT></P>$ q  J) ?/ m7 D" C* ^$ c% u
<P><FONT color=#0000ff>/* reopen the file */ ; |, S) P! B& Y
fp = fopen(FNAME, "rb"); : U3 y7 S: j, q9 V8 S! m& C
if (fp == NULL)
/ P& Z# E/ b  \( [" B' y; X{
# l6 p( @6 ?, p! m' y! Lprintf("Error opening file %s\n", FNAME); : C" o' R; d. M' G
exit(1);
; h0 I- C) p4 _- g# d3 a5 ]+ n} </FONT></P>
; G5 o. c2 \0 u8 X<P><FONT color=#0000ff>/* extract the word */
& b* y, t8 ~8 C& M& I0 v6 Rword = getw(fp);
0 t9 D% u. W: C& @; tif (ferror(fp))
. D, r& c7 O. p5 E0 S& iprintf("Error reading file\n"); " V5 k$ {) A$ x5 ^
else
* D. Z. d& U# o1 |8 ]printf("Successful read: word = %d\n", word); </FONT></P>
/ C5 h' w: M! P& }5 k& D0 W<P><FONT color=#0000ff>/* clean up */
, D2 g6 N" k" b$ Efclose(fp);
2 A8 p8 H3 N% y* ounlink(FNAME); </FONT></P>2 D0 J) t9 b6 |, O" R
<P><FONT color=#0000ff>return 0; 9 Q7 I5 W4 M2 R$ I
} </FONT>
) `3 t! p/ o2 T, d; {- y& O; G' a' _  I: y# \7 O! z# M' P

+ E8 X2 M. M* }/ V: }- A  ~3 O- C</P>
3 ]! ?8 S# Z3 m- `' e5 `1 l: \' D<P><FONT color=#ff0000>函数名: getx </FONT>6 l) f: I: j* h% Q9 `, D1 `
功 能: 返回当前图形位置的x坐标 0 L2 U0 }* P/ n; m7 f
用 法: int far getx(void); " C6 W. e: Z3 z1 r
程序例: </P>
& f, E" e9 ]' Z( h( L* E<P>#include <GRAPHICS.H><FONT color=#0000ff>+ T$ d- L. p( N: _/ H
#include <STDLIB.H>
4 X5 P# F$ G7 H#include <STDIO.H>
2 U* N; Z  H8 d$ H1 i( |4 l#include <CONIO.H></FONT></P>
2 {2 D# v) V- f" A/ l! h<P><FONT color=#0000ff>int main(void) 7 v4 u; s+ a1 A' p! z1 E9 G/ m
{
, i+ C1 D4 F/ R! p; v: v/* request auto detection */ 0 N- `. j; \9 n8 \
int gdriver = DETECT, gmode, errorcode; 8 ^( c* D' @2 ~( j% }. h
char msg[80]; </FONT></P>
2 X3 v7 D- H' m( m5 h' d<P><FONT color=#0000ff>/* initialize graphics and local variables */
) G0 N, d7 n* ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" O+ y# d! |* L  A) Q9 u<P><FONT color=#0000ff>/* read result of initialization */ 3 z8 Q  A' L! H# J% x" M; E
errorcode = graphresult(); + f# y" E. @0 ~  Q6 g1 k& Q
if (errorcode != grOk) /* an error occurred */
9 U, @3 r$ _' `{ # g- K/ p7 D  E' m
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 }! d" n  E7 V* h( F- Nprintf("Press any key to halt:"); $ @" {% A1 c. l, _) f3 M$ D
getch();
. f1 A$ X" J1 m7 z4 nexit(1); /* terminate with an error code */
9 ?# @0 C9 X  S" L} </FONT></P>( Z5 ]' @/ f5 v7 z% r( u
<P><FONT color=#0000ff>/* move to the screen center point */ / R2 D7 w: g, q# J3 R% O
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
) j3 ?6 j+ n! e) U# i5 l% k<P><FONT color=#0000ff>/* create a message string */
9 K) f, A2 V) F- R$ V! Qsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>1 M9 A) o4 b4 ]) r. Y
<P><FONT color=#0000ff>/* display the message */ 3 W8 r' G' g( T$ h; m+ s
outtext(msg); </FONT></P>
9 i0 _) L' ^, I- n<P><FONT color=#0000ff>/* clean up */ ' o! U. l# L5 I, D
getch();
& Z% h: q" |( N1 P: sclosegraph();
' P" J5 e% U( p# qreturn 0;
2 ^- P3 d$ b8 m7 x} </FONT>4 b  A8 C) @) K- e1 J& D! H. g
) m+ t2 D+ l2 i  h( _
</P>
4 E& F/ g9 `- [& c% r<P><FONT color=#ff0000>函数名: gety </FONT>" \* @. N' D- n8 Q
功 能: 返回当前图形位置的y坐标
5 @0 v' w% A* R" c0 H用 法: int far gety(void);
# C+ g0 l' r/ a# s+ Y程序例: </P>
3 k  b) k$ r3 Z1 K6 Q<P><FONT color=#0000ff>#include <GRAPHICS.H>! v0 N. Q4 K" N* g" M9 }0 H4 u* b
#include <STDLIB.H>
0 B- `: x3 ^8 i) l- u" k#include <STDIO.H>; d; }2 g9 O4 S( ~6 J. u
#include <CONIO.H></FONT></P>
: V$ A5 e3 _: M  {# g+ p<P><FONT color=#0000ff>int main(void) % t5 W2 B! l4 C
{
/ g6 V5 i* k, X5 m9 @. ^+ l/* request auto detection */
3 x. g! T7 y2 S$ H2 gint gdriver = DETECT, gmode, errorcode;
; ~1 i- z- m; q* cchar msg[80]; </FONT></P>
8 M( J2 O  ~) H8 D9 h2 D1 I+ O6 ?<P><FONT color=#0000ff>/* initialize graphics and local variables */ , c- _2 h: @( m+ A/ f3 y* R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 r- Q. e( G) t! n9 q
<P><FONT color=#0000ff>/* read result of initialization */ ; ?: f' E5 `, R9 ^& n4 u7 T
errorcode = graphresult();
0 u0 \5 O0 ?! w; j5 G6 N# T, p: ?! T; P$ W$ tif (errorcode != grOk) /* an error occurred */
: z, G. g# r9 B, \; `{ % w; t2 O* P* z2 i3 b6 M2 @) i
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 `  O/ w0 C2 t* G$ E  Dprintf("Press any key to halt:");
8 [6 x( c1 U2 T  m) w# xgetch();
# K" u& b( [; H, A% j! v; Pexit(1); /* terminate with an error code */
/ k+ k! g2 L- a  y) r8 O} </FONT></P>
1 H: c. ?, A% m* _; h<P><FONT color=#0000ff>/* move to the screen center point */
  O1 G, E, Z9 l6 Y: S) cmoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
6 e( Y7 z3 R  g1 y, }<P><FONT color=#0000ff>/* create a message string */
/ o2 O2 s, p/ v6 R$ gsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>0 \7 ~; Y1 G$ x6 H
<P><FONT color=#0000ff>/* display the message */ ) a, A6 [2 T5 d( {* n
outtext(msg); </FONT></P>
! m9 A) ~$ ?/ E( a: P/ k<P><FONT color=#0000ff>/* clean up */
$ e) h- L  q8 E5 ?! b  {getch();   {* N. J8 w' o% g4 Q$ Z' ~. d
closegraph(); 4 A: Y' C9 X. t& r1 a
return 0; , W! ^/ d  A2 g7 V
} </FONT>  m* a2 I: Q( x( C

( h" l% b+ _! Q5 l* k5 \2 ~) i( y</P>3 V8 z, d# |9 U
<P><FONT color=#ff0000>函数名: gmtime </FONT>
4 z; _2 o& _: W/ F1 W功 能: 把日期和时间转换为格林尼治标准时间(GMT) 6 e+ ^( r  i" ~4 B: X6 {
用 法: struct tm *gmtime(long *clock);
+ S4 r$ y# p/ z# x  j程序例: </P>1 u. x, z4 O  z1 w) B# y
<P>#include <STDIO.H><FONT color=#0000ff>
+ b. E! {0 D3 M' [# l" U8 t#include <STDLIB.H>0 u  b5 ]( u% P# j% J
#include <TIME.H>$ Y) T7 u3 D6 e+ I% M5 y2 w
#include <DOS.H></FONT></P>0 V3 j# O( j- S
<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
  n0 x+ c$ B8 S6 W+ Jchar *tzstr = "TZ=PST8PDT"; </FONT></P>
9 h& z" y5 C' P+ j+ w( j! p<P><FONT color=#0000ff>int main(void) * O3 {/ p. R/ b
{
) I/ p; k( }3 _9 u$ ~$ J& Q; L) ctime_t t;
$ [8 v# u6 H' L+ Bstruct tm *gmt, *area; </FONT></P>
0 `% I- _: `  a4 H) O<P><FONT color=#0000ff>putenv(tzstr);
3 |" \; e* W: ~; |9 p5 g" x: ^tzset(); </FONT></P>/ @/ X1 ]0 V% n3 s" I1 b
<P><FONT color=#0000ff>t = time(NULL); / }) ?* @$ Q- ^. |7 d2 s
area = localtime(&amp;t);
/ t* J9 |) J, X7 u6 k. F9 A4 W+ Hprintf("Local time is: %s", asctime(area)); , n1 c+ Y6 [  H8 D
gmt = gmtime(&amp;t); ' y9 T: {6 c* A! i
printf("GMT is: %s", asctime(gmt));
$ K, g1 x, d/ i* x2 c/ nreturn 0;
. R6 ~/ u% m) [0 N} </FONT>3 d5 L, K- [9 [# R4 x
* b( b6 C0 [$ r, M/ c( D
</P>3 H6 G' B# \( m- L4 E
<P><FONT color=#ff0000>函数名: gotoxy </FONT>) d$ g  o& ~( r% {
功 能: 在文本窗口中设置光标
9 |) j. W' o! `" U6 |; S用 法: void gotoxy(int x, int y);
# J. D0 z3 `. ^; N程序例: </P>
& e4 D! j5 S* i5 q<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
2 v4 \4 K9 S( v$ @<P><FONT color=#0000ff>int main(void)
# r' V4 k# y9 Z  E! r) H  @{ & M8 z8 i$ K1 U- W7 {% u% q% {
clrscr();
$ I6 E( u. b5 K! hgotoxy(35, 12);
# K) G/ {& V$ r; g: p; Mcprintf("Hello world");
7 k( A# d. B. u( A  N7 egetch(); & O5 Q9 u# s: l+ ~& y$ s( ?
return 0;
3 ^9 q1 \* M- A# J5 }}</FONT> 8 Y  L$ p6 t! J. \( Q) ?

3 Y5 h# p9 i4 C! H3 @% |</P>
$ l& P, O& T# \, [8 s9 ]* r& V$ s<P><FONT color=#ff0000>函数名: gotoxy </FONT>
: L( n2 c6 _2 @0 ^7 J4 J$ g功 能: 在文本窗口中设置光标 , E; j% }! g1 G% o, _; s/ ~+ h
用 法: void gotoxy(int x, int y);
. b4 R( i& [, H- X程序例: </P>
, w/ c. M* m; w- m1 X" Q& }<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>$ E+ B& {3 M3 e% L; g4 y) s( E' P& l
<P><FONT color=#0000ff>int main(void) % }# c/ @. H& U! r
{ $ K5 J/ I( H! X( }+ o
clrscr(); % H2 w: A7 c( G$ s) D
gotoxy(35, 12);
8 E8 U2 @4 C& X0 j7 f( Mcprintf("Hello world");
/ X* d& ]" I7 \+ ?4 w5 I! x1 ggetch(); 6 Y5 o  `9 [6 J
return 0;   ?0 h7 X1 l6 R, f' A9 G
}
0 x; Q" Q' r0 O2 ]- J9 |8 t! R</FONT>/ B4 l. B/ k8 A
</P>
/ \: o- |) g! i<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
) {4 W5 L" ~5 c功 能: 将所有图形设置复位为它们的缺省值 ; O  U5 t; V4 N) I6 N6 v/ D* \
用 法: void far graphdefaults(void);
6 i' ^5 x$ @2 W& j/ Y5 J程序例: </P>
  V9 w" M! r* u7 s<P><FONT color=#0000ff>#include <GRAPHICS.H>' C& _# o' s( f' n6 A  A
#include <STDLIB.H>
; z0 |3 A& j/ J8 [#include <STDIO.H>
5 i5 l5 Y- Z9 z#include <CONIO.H></FONT></P>
. T% b, n% W+ {9 }<P><FONT color=#0000ff>int main(void) ) B, h8 s7 G* F+ k- [, v
{
1 M3 i! ]. P. ~6 G" S0 a. k/* request auto detection */ : h2 J, ?; \4 R
int gdriver = DETECT, gmode, errorcode;
/ p& F$ |- D1 |int maxx, maxy; </FONT></P>$ e; s1 [; P$ |6 Z, I
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , Q% d# A: T( k
initgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
3 `( [& P% n$ ?<P><FONT color=#0000ff>/* read result of initialization */ ' \/ s) o  I; {+ z: x5 a
errorcode = graphresult();
& x( P+ J% Z; Gif (errorcode != grOk) /* an error occurred */
+ s4 t7 R. s6 ]{
" P+ E/ Y* J5 H* Z. z, v8 r& Zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " E0 e* ?0 S. P3 D# Y: q
printf("Press any key to halt:"); 6 I& _' @) t( z! Q1 l+ {
getch(); 6 Z& C2 E0 {8 ?3 e- J9 I( ]
exit(1); /* terminate with an error code */ 4 w' b! E+ m* P+ a4 v( L
} </FONT></P>4 x" I/ ~3 ?6 I: I0 b
<P><FONT color=#0000ff>maxx = getmaxx(); + [/ u& \, e/ F9 h! B' F# J0 K% H) t
maxy = getmaxy(); </FONT></P>
0 n3 a; `- w6 [" E0 E9 d<P><FONT color=#0000ff>/* output line with non-default settings */
# F. e0 u. ~5 A% d6 Psetlinestyle(DOTTED_LINE, 0, 3); ) D5 K1 J/ R: M4 z6 ~4 l
line(0, 0, maxx, maxy);
  t* L* c% v& q: F2 youttextxy(maxx/2, maxy/3, "Before default values are restored.");
( D+ M9 L# b6 ~, i% H  l& Sgetch(); </FONT></P>
+ ?% q2 t, w9 ~  r4 q$ M7 [/ A* b<P><FONT color=#0000ff>/* restore default values for everything */ . x3 t$ Z0 I/ i& S7 C
graphdefaults(); </FONT></P>' r  P( o6 D3 b' l3 v; c4 q
<P><FONT color=#0000ff>/* clear the screen */ $ e4 l; d+ w/ u$ B" U8 l
cleardevice(); </FONT></P>9 m& k1 m; s  I4 x9 o. r3 F
<P><FONT color=#0000ff>/* output line with default settings */ & m3 A( o6 X+ ]) I( f
line(0, 0, maxx, maxy); , ?. ?4 v- Z" H/ M, z0 T' ~. L
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
7 ?7 m! {4 L" i<P><FONT color=#0000ff>/* clean up */ 1 j- ^  P% H+ U5 ~* D4 ]
getch();
( N  R. U1 d: E# Xclosegraph();
0 O: c" T' L* G- W) D: Greturn 0;
7 p3 U. N) b) r, x0 a& a}
! t  ?$ y# r2 U8 a4 U$ o</FONT>( H% v5 Y" p8 ?3 p8 }; z
</P>
( ~2 ~$ d) J# {$ ^- \<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>7 c8 g9 ?$ S' P5 ?
功 能: 返回一个错误信息串的指针
, _9 d6 D8 i' _5 @用 法: char *far grapherrormsg(int errorcode);
2 Y' ]5 ^% b) ?* V4 h% {3 G程序例: </P>
- G. W" H( J9 U) k1 [$ u9 R! {<P><FONT color=#0000ff>#include <GRAPHICS.H>$ n, U" E! X: c0 ^
#include <STDLIB.H>, N" i* W8 O( t0 E7 n7 E% u" ?
#include <STDIO.H>
1 r/ \; c5 L5 t, T2 U#include <CONIO.H></FONT></P>3 `: T" ^* ^7 w* j* U2 g
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
8 ~% K& j- }$ i# j7 z7 _<P><FONT color=#0000ff>int main(void)
7 ]8 d' @) v1 x- [- T1 G{
( s; B: d! T# c' Y& h' J/* FORCE AN ERROR TO OCCUR */
/ J1 J: s( T+ j( P2 G  uint gdriver = NONSENSE, gmode, errorcode; </FONT></P># q  f1 p$ A2 B! `
<P><FONT color=#0000ff>/* initialize graphics mode */ ( H- y3 a0 |8 O; W, w% u* E- _
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ ~8 o0 L0 J* Q7 u) n( i# K
<P><FONT color=#0000ff>/* read result of initialization */ 9 p% P# B3 ?$ ~# @  R# j' {5 X8 X
errorcode = graphresult(); </FONT></P>
8 }! f7 O* Y) R/ o& x. Z* }<P><FONT color=#0000ff>/* if an error occurred, then output a */ 3 ^  O7 A/ Q0 M5 l- L3 Q! G0 I8 P/ ~
/* descriptive error message. */
' J# V/ ]! c2 F! Y6 O$ R+ Z3 hif (errorcode != grOk)
* a8 q$ T, Y/ v7 o- j3 X{ % p7 y: z4 A+ ^) \1 Q8 T9 E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; \/ n4 I0 l" p" O7 H( ^2 e8 N
printf("Press any key to halt:");
2 k/ i1 Q- a" Y0 L% L* ]$ @getch();
! l: F6 B' w* K" F' eexit(1); /* terminate with an error code */ ( K) b. _! V5 m$ g0 u
} </FONT></P>: f- R% K4 k' c; \2 j  }
<P><FONT color=#0000ff>/* draw a line */ 1 R, T/ A' c5 }( o. d) r; e
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
) m5 J* ^. Y0 `1 W' q<P><FONT color=#0000ff>/* clean up */
3 G7 \  C! n- T5 N% O' Ogetch();
" X  u* \9 \- v  U7 X0 [closegraph(); 6 I+ h# K, l( U
return 0;
% Z, B) P+ j, f' t}
7 E, }( v! {0 _# p* z</FONT>
1 r" i1 H3 ~) q</P>
3 _6 l; k) U4 ]- r" R8 r<P><FONT color=#ff0000>函数名: graphresult </FONT>* I$ m/ c& }# j, K/ m, Q$ S3 J
功 能: 返回最后一次不成功的图形操作的错误代码 $ U; k$ h% k1 A" z
用 法: int far graphresult(void);
8 b  y& k8 O" ?. }程序例: </P>
0 G& u% f, w% Y3 n3 \& j1 k# r<P><FONT color=#0000ff>#include <GRAPHICS.H>
! S- `, D/ W7 k3 ~# ?4 b, w#include <STDLIB.H># |* C+ k7 Q6 E" q0 ]! }, h
#include <STDIO.H>8 T! E) C0 ?1 o3 I6 [6 k
#include <CONIO.H></FONT></P>& Q+ q$ e! [5 |! K0 g4 w& R: S
<P><FONT color=#0000ff>int main(void) : l" {- M4 z5 t* F, W" e' p
{ / x$ A* k2 X7 i0 o: z1 }1 P4 e
/* request auto detection */
" n. G  n3 Q/ Vint gdriver = DETECT, gmode, errorcode; </FONT></P>7 e. a) W+ n0 h! Z. ?1 y; g
<P><FONT color=#0000ff>/* initialize graphics and local variables */ : L3 E) V4 V# p! O! d9 l% j1 |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 @, Z/ q  \3 g2 z' i<P><FONT color=#0000ff>/* read result of initialization */
& z$ @. N" ~0 E/ L  d: \2 n7 Qerrorcode = graphresult(); </FONT></P>
; I! t" D$ M2 H5 r5 V2 A# K. N<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
1 d7 D, O* h' q- l$ z% o5 Z{
7 Z: x/ X, d# @4 Z6 c8 fprintf("Graphics error: %s\n", grapherrormsg(errorcode));
  Q6 m, F& w: p1 D  p( Yprintf("Press any key to halt:"); 2 ~  H5 P" M. I6 {. v
getch();
" p) Q. U: v; T1 [exit(1); /* terminate with an error code */   A3 z4 O* V/ b. n) @6 c5 K5 o( U
} </FONT></P>
# U5 V4 S  A( V) W% A9 L" `<P><FONT color=#0000ff>/* draw a line */ 8 \& h2 h* |1 j5 X' {" E# {* y
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
6 Q% c7 x' ~9 j% }0 b% F. @' ]<P><FONT color=#0000ff>/* clean up */ ( h) G* H- n+ R5 \# p* M
getch();
$ X6 R3 v0 b: L' W8 kclosegraph(); 9 Y, w( t" F: L' b) `: C' V0 e6 \
return 0;
- c" ?2 |, t, Q+ ~" d" a8 ~}</FONT> : }1 q& ^+ _' W2 G( c& @, M, z
</P>& R; _1 N9 p; i" f  `
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> 3 _, g" k. K0 r4 p. ?5 G
功 能: 用户可修改的图形存储区释放函数 * k" t& X# Q/ I( ^' h  d
用 法: void far _graphfreemem(void far *ptr, unsigned size);
+ I, I2 o9 f! G. E+ {9 U# f: A程序例: </P>1 x; j- X8 U8 ?4 H
<P><FONT color=#0000ff>#include <GRAPHICS.H>' I3 B' n% W! E
#include <STDLIB.H>
/ K! \! `2 Q: r: r#include <STDIO.H>3 }' D# A' B9 D5 \; {( p
#include <CONIO.H>/ }& C) U- g) X  f6 ^
#include <ALLOC.H></FONT></P>; L$ g$ [! l5 ]" i, f& E: _
<P><FONT color=#0000ff>int main(void) 4 U# w) {4 _3 y7 h- n  r- ]
{
" q/ {/ w& D- w5 ?  V# o$ E/* request auto detection */ 8 |1 \+ g. Q& R. a+ n
int gdriver = DETECT, gmode, errorcode; ' e! o, C# i7 y  K
int midx, midy; </FONT></P>" O) _1 q( L! ?& Q) V
<P><FONT color=#0000ff>/* clear the text screen */ 5 y2 \. h  H: p3 f( A: s
clrscr(); % ?! Y( l. U$ E) `, y
printf("Press any key to initialize graphics mode:");
: M0 [  g$ M3 x* n" H! _9 Vgetch(); * O$ X, z  o! q' }; _6 z
clrscr(); </FONT></P>3 Z  }7 s; R6 t: i9 Q2 I) D
<P><FONT color=#0000ff>/* initialize graphics and local variables */
: T8 ?! Q6 |3 i) d  einitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 y. [% U  L! G0 G<P><FONT color=#0000ff>/* read result of initialization */ 4 v, q% u1 |2 b/ l- O
errorcode = graphresult(); & h, M+ m& Y1 s( T6 X1 ]% \
if (errorcode != grOk) /* an error occurred */ / x2 w! r+ O, E& [
{ ( M# o7 z* ?/ s. K6 D
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& x. F  \% d/ ^- J6 r1 I+ _- |# hprintf("Press any key to halt:");
( ^/ m( I4 r1 z8 r& q& ^getch();
5 F& ]- n0 o$ ]( b& G. b: qexit(1); /* terminate with an error code */   L. ?* G, u  o- E
} </FONT></P>4 Y9 A, l# ~% D8 k7 Q0 h' Y& Y6 M9 _
<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 G1 W# B2 A9 q& V4 Tmidy = getmaxy() / 2; </FONT></P>0 @' N7 n+ G( k/ y: X( ~' h
<P><FONT color=#0000ff>/* display a message */
- V% ^8 {' n/ h( P% H) ksettextjustify(CENTER_TEXT, CENTER_TEXT);
; B# M/ P0 s1 Y+ d/ Nouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
1 m" m( |7 A% n3 u$ o9 L& Y  |) |<P><FONT color=#0000ff>/* clean up */ & r* b4 `0 T. ^! ^4 j( {
getch(); " u- p: Y- w& C6 {3 b2 w- J7 x- Q+ D
closegraph(); + [6 z! L  _: v( |
return 0; # ]0 S# v, p' H! F: D; S
} </FONT></P>4 X! D2 r0 U* A$ o8 |' ?
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ # P. d/ P8 C: t7 S
void far * far _graphgetmem(unsigned size) 2 s' y) v. K+ v
{
- u! N5 }+ M1 o) Uprintf("_graphgetmem called to allocate %d bytes.\n", size);
1 @* f9 p/ ^+ [8 x+ Xprintf("hit any key:");
* y5 m; d, g" k+ ?0 V% d. ^getch();
% @' u" E# ^$ [printf("\n"); </FONT></P>9 r" T& O- D+ I2 ]& s' o4 Q/ M
<P><FONT color=#0000ff>/* allocate memory from far heap */ $ r- k( a' ^  g+ u. T2 h  U/ R) v
return farmalloc(size); 1 l; U6 M$ B- v5 G& O
} </FONT></P>
8 a- M+ ?$ ]& F7 s& j- b1 F<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ " J) `( O4 h5 y# ^7 |8 W, `$ f" j
void far _graphfreemem(void far *ptr, unsigned size)
. K) M# ?' d( ^8 t) X( f{ 0 z$ w, y/ h: t" M8 x+ g
printf("_graphfreemem called to free %d bytes.\n", size); % u3 V# L+ @* W& C3 ^, \4 L4 R
printf("hit any key:");
% Q1 c4 m2 j; q# b- J6 [( jgetch(); 0 @3 l* V7 Q+ l( I
printf("\n"); </FONT></P>
# q. ^4 I. _9 t& T4 |<P><FONT color=#0000ff>/* free ptr from far heap */ 0 O% k3 q! _$ n" p  S  V6 n+ s0 C+ P( T
farfree(ptr);
, b( `0 Q3 D/ o} & h6 |% |4 _0 V. W. s3 T
</FONT></P>
4 `" b1 b4 J2 g$ m<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>
  q, E( C- O. D" f# u5 y功 能: 用户可修改的图形存储区分配函数
/ d$ E& @# U) E% u/ _用 法: void far *far _graphgetmem(unsigned size); ' z6 F1 Q8 `8 g2 z
程序例: </P>0 e; l% J8 H  f" u
<P><FONT color=#0000ff>#include <GRAPHICS.H>, Z& T" _: P4 \3 Y7 p
#include <STDLIB.H>) V6 i/ H1 E, v( j  Y3 d2 v
#include <STDIO.H>
, s; i+ Y9 l8 g/ _  b. q, f#include <CONIO.H>0 T1 ^5 h: L" }+ @3 q5 }% U
#include <ALLOC.H></FONT></P>
( k1 A5 e0 q& _$ A. L6 o% R<P><FONT color=#0000ff>int main(void)
7 D3 \! Y  o- \2 \4 W# C5 H{
9 h8 V+ |5 b' A1 K* ~/* request autodetection */ 7 ?3 R. V; m% Q
int gdriver = DETECT, gmode, errorcode; % E! ^7 Z$ V% y6 h
int midx, midy; </FONT></P>
8 q7 N/ e* l/ h8 ]- Z<P><FONT color=#0000ff>/* clear the text screen */
: r: [, f6 ]! \0 e; i* `clrscr();
7 {# k. v/ ?7 Zprintf("Press any key to initialize graphics mode:"); . K/ {' B% Z( q3 v, W
getch();
9 p8 s; z$ @$ n7 M7 h9 O6 uclrscr(); </FONT></P>' {7 }4 C( T5 p- t* T/ Q
<P><FONT color=#0000ff>/* initialize graphics and local variables */
( u* a/ t, \$ @( X" D5 j5 Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ K4 ]3 z- N5 _2 q4 R6 a# L3 s+ Y4 L<P><FONT color=#0000ff>/* read result of initialization */ % t2 }/ u: K. p0 f
errorcode = graphresult();
2 K6 W" @0 S5 Q# Jif (errorcode != grOk) /* an error occurred */
6 e: v2 x, y6 P* p{
! G- C( o0 T& _  p4 x5 mprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' H7 [! a  P. u6 }+ m& q- z7 T
printf("Press any key to halt:"); * {4 ~2 O7 |4 @
getch(); # b6 n% r9 p) y( [# k" M
exit(1); /* terminate with an error code */ ) p% {' ^. n" J' d! ]
} </FONT></P>
0 h4 z6 I  n. U<P><FONT color=#0000ff>midx = getmaxx() / 2; ' _& J# Z; m' l% X
midy = getmaxy() / 2; </FONT></P>
1 \; j' q" W+ ?: Y5 N<P><FONT color=#0000ff>/* display a message */ # E0 ]; F, V5 _% s5 C9 [6 a6 j; [7 m
settextjustify(CENTER_TEXT, CENTER_TEXT); ; c( y0 Z' Y- `5 i, y) _: }$ f
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
1 j6 M- z+ t2 d  ^. @, P$ x; V<P><FONT color=#0000ff>/* clean up */ & o5 j4 R; \8 I- m4 S
getch(); 6 c  B! W" j6 ?: S; J  ~/ x, h$ x
closegraph(); / k2 n' H. }& O1 F  Y: B0 _
return 0;
& r% ?+ P& _8 m3 |7 ?} </FONT></P>
& U4 E( j( Q" @+ s- y6 a/ Z<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
$ J, E3 Q# B( K  W1 d* l2 M3 e. W5 lvoid far * far _graphgetmem(unsigned size) * Y' ]- S% R+ J9 X* W6 Z5 U/ z. X
{
7 W) a, l* l2 b0 x/ |printf("_graphgetmem called to allocate %d bytes.\n", size);
: `4 k1 [/ [4 n1 F+ H' Q, eprintf("hit any key:");
$ S+ T' \6 }7 R' g) X; pgetch(); 6 Q, y4 [: A" [/ u, s$ M0 d) d! L
printf("\n"); </FONT></P>
! X& c; Q7 N9 F/ a& o/ j<P><FONT color=#0000ff>/* allocate memory from far heap */
* F/ `( k" Q$ ireturn farmalloc(size);
  ^( n1 o$ }/ n, g} </FONT></P>8 a' ^% B' n5 K  f4 _" `6 |9 H
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
* w; l: S- P: y0 qvoid far _graphfreemem(void far *ptr, unsigned size) 3 c3 g; T- o# `) k& R
{
" z$ c. U& O. l7 bprintf("_graphfreemem called to free %d bytes.\n", size); $ c. N$ f9 C! |' n. Z, ]9 L* W
printf("hit any key:"); 2 B) f$ ^+ d6 b# |1 K4 [
getch(); ; R( A/ y. l1 C' ?0 _$ P
printf("\n"); </FONT></P>
! Q. C; R/ I% U# k: L; I) `- p<P><FONT color=#0000ff>/* free ptr from far heap */ , m2 [. M; L6 ?  s+ s; K# h1 i) S
farfree(ptr);
+ X6 S# {! g! ]* i}* o) x5 N0 S5 R: X
</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-10-23 08:01 , Processed in 3.620621 second(s), 51 queries .

回顶部