QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2521|回复: 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>3 p2 q( [' |( T9 `9 p. b7 Q( P

) F5 s4 }. W; A* V8 f$ T
6 H) [) h6 o! P5 l  N<p>( E9 z% N8 }6 z- Y6 U; \: E
<><FONT color=#ff0000>函数名: gcvt </FONT>- R5 h" q7 N; }' i
功 能: 把浮点数转换成字符串 ! _( W* w8 a+ c' X7 I
用 法: char *gcvt(double value, int ndigit, char *buf);
  h* d/ x% ?; p$ \4 ^4 b, A程序例: </P>
) z/ n- M+ Q5 k% f+ A8 C* m<><FONT color=#0000ff>#include <STDLIB.H>
* u: e0 ]( e5 p! {( v1 c( h" y#include <STDIO.H></FONT></P>
, |! K8 H% j) ^<><FONT color=#0000ff>int main(void)
* y5 A9 k. k! E) P- m. ]{ 4 {6 u9 p4 O( ^% |9 Q6 F7 a& c
char str[25];
' |) @+ S$ i  p% ddouble num; ! L" w  k: k3 q  V
int sig = 5; /* significant digits */ </FONT></P>
7 p# b% H" d3 A3 V4 m# ^<><FONT color=#0000ff>/* a regular number */
# h+ |3 r5 {* s+ Bnum = 9.876; 7 E, Y6 P7 H, p7 C# x9 n
gcvt(num, sig, str); 6 x" x. D9 M$ m. _
printf("string = %s\n", str); </FONT></P>. Y# K8 F0 p6 n) [
<><FONT color=#0000ff>/* a negative number */ ; X0 U7 B' l( |( n) e! J5 y- H
num = -123.4567;
4 n% m' d9 @0 r* @9 E1 M: Mgcvt(num, sig, str); 2 c+ W: n% J. H9 l/ t& D8 w
printf("string = %s\n", str); </FONT></P>
! N8 P& d1 a7 |9 d! g7 D<><FONT color=#0000ff>/* scientific notation */ 5 _* f# _$ C- q/ z+ n# y
num = 0.678e5; ' Y! c) {6 H9 b
gcvt(num, sig, str);
1 S4 G: v: C) m# U' N: Yprintf("string = %s\n", str); </FONT></P>0 g7 M! Y( Z, z0 _
<><FONT color=#0000ff>return(0);
3 ^  z& e: t% X) {8 T}
, N( k. s# E" z) _' P. |4 f0 u- C8 _
</FONT>
4 Y2 l1 j0 |$ H0 U! ?</P>+ F$ [+ C( ]& v9 @
<><FONT color=#ff0000>函数名: geninterrupt </FONT>$ e* M! J' n6 e6 K& a$ _
功 能: 产生一个软中断 5 h3 [4 F* w+ I# b  A8 q
用 法: void geninterrupt(int intr_num); * M' l* \0 R6 n* k" s
程序例: </P>) n/ f% v& J& ^5 c0 y- l
<><FONT color=#0000ff>#include <CONIO.H>, O6 ?+ P1 |/ t2 y0 X9 U0 d/ |. l
#include <DOS.H></FONT></P>: E5 K! g# Y9 {% ~
<><FONT color=#0000ff>/* function prototype */
8 D$ V$ B. S7 N6 k' Zvoid writechar(char ch); </FONT></P>
& ^. a0 s1 Q3 Z. i1 c9 N" c) b<><FONT color=#0000ff>int main(void)
: c; t7 L5 S- X  d% C3 g{
& R/ l! g+ h/ D* Z, g, ?clrscr(); # I; S+ ^1 H5 w" U! g
gotoxy(80,25);
: S% I7 E+ @" r8 P0 @# Wwritechar('*');
) b5 j2 z1 Z. J7 Z/ wgetch();
" j2 z/ r7 X0 \( ereturn 0;
) Z* [% F- {0 u, x0 R: b$ I9 d} </FONT></P>
6 A" ]; a) G" p( j. t! g<><FONT color=#0000ff>/* . y0 g* Y6 f  n, h! U$ @9 ^
outputs a character at the current cursor # n) S0 I) I" k
position using the video BIOS to avoid the 1 Z' F) C! ~% ]
scrolling of the screen when writing to 4 {5 p; ~3 B* v# O1 m
location (80,25). ' C, d' i4 L0 f0 A3 n# H$ D2 j8 y
*/ </FONT></P>
6 M3 `3 L4 V; u$ ]4 j. e<><FONT color=#0000ff>void writechar(char ch) : D/ a& r* S' K! `
{ . t' x0 C4 S6 k, k9 X
struct text_info ti;
2 ]" l' n6 K6 ]( M- n- K/* grab current text settings */ / q( b7 t7 T: g" E* O$ O7 e
gettextinfo(&amp;ti);
0 H1 W) x5 v1 Y0 S: b0 h" [/* interrupt 0x10 sub-function 9 */
4 }; Z2 R- Y. L; ?1 z) Y: H_AH = 9;
4 l& i2 s4 z' ^" }' e+ ~/* character to be output */
( m  |* ]8 D( S: h6 x( ~6 n3 h_AL = ch; 6 Q+ R8 Z& h: r) m+ F' B3 a$ x8 g% J
_BH = 0; /* video page */
# |2 o& [% g: s: `  s9 K2 a1 y5 J_BL = ti.attribute; /* video attribute */ ! Q! E0 u: k/ i4 J
_CX = 1; /* repetition factor */
5 l9 Q6 ~) A( a2 Q8 R4 g% a5 Ugeninterrupt(0x10); /* output the char */
, g6 i+ c' P# W8 |}
$ Z6 Z9 t; U$ X# Z</FONT>+ {5 }, ^8 f5 d$ u' Z' v
</P>
: f. A9 x4 w* F; T$ X. H<><FONT color=#ff0000>函数名: getarccoords </FONT>
# D3 Q$ t# z7 Q, X; e功 能: 取得最后一次调用arc的坐标
4 Z. q- \8 n6 f& j$ I/ q6 z用 法: void far getarccoords(struct arccoordstype far *arccoords); $ E' l8 O8 {# C( f
程序例: </P>+ A/ z1 m; z( Q9 d  ]( G0 S- U
<><FONT color=#0000ff>#include <GRAPHICS.H>; q5 z$ ^9 C3 k; V0 M5 H0 B  \; b
#include <STDLIB.H>% i1 n6 p  _# F) x
#include <STDIO.H>7 P2 P0 T) _$ ^5 [% M4 O
#include <CONIO.H></FONT></P>
; t/ ]- |3 p  Z3 Q: I: N5 n# I<><FONT color=#0000ff>int main(void) 1 a( m, c" q6 Z
{
5 x0 H7 e! f. J/* request auto detection */
; k. ]! L/ h0 c; P. m- n+ T* Yint gdriver = DETECT, gmode, errorcode;
/ V+ i1 v% x% astruct arccoordstype arcinfo;
* b* v- b! p0 |: a7 i( pint midx, midy;
  O: I6 s+ _+ ^0 e) A7 C6 N; cint stangle = 45, endangle = 270;
% v1 ^9 a: X; {; i- x, I5 Echar sstr[80], estr[80]; </FONT></P>
- s% C( f/ u6 a$ w! L9 z7 c<><FONT color=#0000ff>/* initialize graphics and local variables */
( J7 @( i% I" E+ O* h1 i  dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) z2 W$ m4 J5 q- }
<><FONT color=#0000ff>/* read result of initialization */ ) _8 R: W. [. G2 E0 Y' V2 L
errorcode = graphresult();
5 O% U* ?' D! A8 p$ U, \/* an error occurred */ ) Z) t  P1 }* o) y$ Y, e( ^
if (errorcode != grOk)
' \+ q  h0 L4 p4 p: D; |& {{
8 l- {9 l+ i" e: U* e# Z* z4 e  U" Bprintf("Graphics error: %s\n",
( p9 F5 I7 U0 t7 p+ B% j! d8 mgrapherrormsg(errorcode));
) B. }% l8 J% ^0 V" @/ Cprintf("ress any key to halt:"); 5 ]/ f$ H* t' k. @/ Y
getch(); % E  H. A/ q+ ]
/* terminate with an error code */ % U  L. @$ B+ O- P' B
exit(1); 1 n! O% G  J8 H9 ]$ w6 O5 k
} </FONT></P>, H) J) H) ?% Q. E. W" l
<><FONT color=#0000ff>midx = getmaxx() / 2; 1 |! `3 L# a: y+ d% }
midy = getmaxy() / 2; </FONT></P>( L0 m4 r* T# g
<><FONT color=#0000ff>/* draw arc and get coordinates */ 3 H% }0 ?; C) }$ W" n4 B; J# t
setcolor(getmaxcolor());
  ~, X. i: l2 C+ karc(midx, midy, stangle, endangle, 100);
+ @0 U) V, i/ I- u0 U1 r5 E8 z5 \getarccoords(&amp;arcinfo); </FONT></P>( Y+ l0 b9 \7 z  C
<><FONT color=#0000ff>/* convert arc information into strings */
6 _1 w6 v+ S/ v+ K; i  E% X/ Lsprintf(sstr, "*- (%d, %d)",
( @9 d7 G; A% I& jarcinfo.xstart, arcinfo.ystart);
/ s8 \, t  q1 v" zsprintf(estr, "*- (%d, %d)",   G1 ]: `' M& Q. W
arcinfo.xend, arcinfo.yend); </FONT></P>) d4 H! ^3 t3 |2 Y. ?3 R  X' J- M
<><FONT color=#0000ff>/* output the arc information */ , c6 x" d% \( O1 R6 a7 |
outtextxy(arcinfo.xstart, " B% L/ v3 x3 ~
arcinfo.ystart, sstr);
( K! [. t" X. Q5 G7 Y0 oouttextxy(arcinfo.xend, * `+ X- P. ~, ?8 P
arcinfo.yend, estr); </FONT></P>5 l) a7 }* R3 z8 }/ S2 ~
<><FONT color=#0000ff>/* clean up */
2 g$ Q. K: y! v( ]' K8 \5 vgetch(); 1 ]5 ~9 `/ l. ^: V/ t
closegraph(); 7 v" J+ J' O+ T; ?5 j" _
return 0;
% J  o$ m* Y( J% d8 U! u/ `} 1 W* B3 a7 |( G% u9 h( k
</FONT>  v: L, |' o6 p' w" B

8 _  X1 a( q( h% \- z</P>  u+ O1 M) c* u' L4 B, _( J
<><FONT color=#ff0000>函数名: getaspectratio </FONT>
# x# _$ j: I9 o2 [功 能: 返回当前图形模式的纵横比 8 m4 a% @* P* o, I; ^. t$ A
用 法: void far getaspectratio(int far *xasp, int far *yasp);
; E/ o) r( k+ O9 B程序例: </P>
7 r; i) e  f+ e2 h. [9 ~' R" A% ]<><FONT color=#0000ff>#include <GRAPHICS.H>
6 H, _* r( O  N, s#include <STDLIB.H>9 B: d  `& u1 |! ^
#include <STDIO.H>- `- c, @3 \5 u" \
#include <CONIO.H></FONT></P>
$ x6 J7 C' j( Y6 c<><FONT color=#0000ff>int main(void)
) i; T' ~+ [# u' I, N$ j{
3 [& a4 C- V1 B/* request auto detection */
% d9 K# s8 ~3 N6 @, f1 @$ `int gdriver = DETECT, gmode, errorcode;
! I9 O" v/ ~% eint xasp, yasp, midx, midy; </FONT></P>) w* P" b' n& y3 u; z+ d0 C: j: w
<><FONT color=#0000ff>/* initialize graphics and local variables */ 2 ]. H; v. s0 p. M- n$ S9 M& Z9 q- {+ ?
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 ?" }* F" ?$ F  t1 v! d
<><FONT color=#0000ff>/* read result of initialization */
% y! n' Y. G8 }1 A8 ^( serrorcode = graphresult(); " K% l5 o  M/ Y$ {
/* an error occurred */ 6 U: M7 u& C0 v  m: R! \# N  \2 K5 b  L0 z
if (errorcode != grOk)
% J- W" k5 w9 \0 K{
8 ?+ `: W8 E* e- A/ Y& {printf("Graphics error: %s\n",
5 p) l9 G6 P9 D8 C) ~) C5 b" j2 A+ ?grapherrormsg(errorcode));
5 ?) b4 I: v( D6 G, N5 P+ Sprintf("Press any key to halt:"); * s5 ~7 ?% W" T, z; w% U" o0 H8 G
getch();
0 W0 r8 `" r8 R# o$ Q$ }/* terminate with an error code */ " K$ o- y9 l+ |
exit(1);
7 j* ?( P1 n# t9 H} </FONT></P>1 d: J- y; ]) c$ ]8 u: o
<P><FONT color=#0000ff>midx = getmaxx() / 2;
; x3 ]* |' ~8 S( x; c+ ^midy = getmaxy() / 2; . K# d3 D3 _! J2 V+ h  k# J# n
setcolor(getmaxcolor()); </FONT></P>
' Z, q/ b# g  S( C" \<P><FONT color=#0000ff>/* get current aspect ratio settings */ ( S* L7 I7 B) i0 v: |, y
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>$ `! q. _# {3 f* X) Y4 ^
<P><FONT color=#0000ff>/* draw normal circle */ ( p% W! q' g3 ]* H6 }. J$ g. r
circle(midx, midy, 100); " _5 Q( |- a1 u$ p" F; B* l
getch(); </FONT></P>4 ?, W/ }  s. n( O; c& ^
<P><FONT color=#0000ff>/* draw wide circle */ % u* Z2 z6 ^7 q9 D
cleardevice();
! L  P0 x5 @% N7 i, B* ?* |6 wsetaspectratio(xasp/2, yasp);
8 R0 L8 `: C& L* g7 fcircle(midx, midy, 100); ) j" N' |& k; D1 \
getch(); </FONT></P>
6 j7 ]3 ]$ r( t4 A8 I8 X+ t<P><FONT color=#0000ff>/* draw narrow circle */ $ k3 f2 T" B) W, Y
cleardevice(); & q6 `( X4 T: P( S! g' m" D# d3 ]
setaspectratio(xasp, yasp/2); 7 J' Z  t3 `% S& [; e5 m/ K
circle(midx, midy, 100); </FONT></P>/ O# q. A2 T6 v4 O6 _  w
<P><FONT color=#0000ff>/* clean up */ : V  `  p9 C6 B9 w& ?
getch(); 2 a2 z( r% Z$ S7 H+ J
closegraph(); ; z1 P" b3 o- k( a' Z  f  j3 K
return 0;
! l6 ?0 F1 D3 n( I; F- F/ M6 v}
! B, o, `2 G* i+ T1 W5 U! g7 h( P</FONT>
$ q: H: q2 P8 n3 a7 X" C& J; I+ h, V& \0 k% w; A
</P>
: r; X2 y1 W& x! y* e! d4 c  w- c<P><FONT color=#ff0000>函数名: getbkcolor </FONT>/ u8 _6 v' ?' V5 ~2 E! a' l$ N
功 能: 返回当前背景颜色 + T0 i; w( n2 j
用 法: int far getbkcolor(void);
! h* o8 J4 L: s& O程序例: </P>+ c; \  R4 f( ?5 m6 _6 @; N
<P><FONT color=#0000ff>#include <GRAPHICS.H>% [8 c( O+ \+ p/ v' W& f8 n1 T
#include <STDLIB.H>0 H0 F* F, H$ _$ `: f% D$ u
#include <STRING.H># `  U1 K9 ]- j+ U6 ~* ~! s
#include <STDIO.H>- T  X9 i% m2 B7 u$ v8 V/ {2 R
#include <CONIO.H></FONT></P>* y3 S$ k5 G, s7 B' b
<P><FONT color=#0000ff>int main(void)
1 E6 F/ ^* j3 j6 M! Z{ 1 _# X; i9 I8 o3 N( f
/* request auto detection */
- a. q% ^! Z+ ]3 q5 Lint gdriver = DETECT, gmode, errorcode;
$ O0 u- q- N; @# P. Dint bkcolor, midx, midy; ( T, M8 [" ?6 Z" U0 U7 I+ z
char bkname[35]; </FONT></P>
1 w8 T9 v0 h! x5 J  W* G6 F7 L<P><FONT color=#0000ff>/* initialize graphics and local variables */
( I  A% I" s# p- p1 c8 D& [% uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ `6 |2 {/ D  s! k- s( {# d
<P><FONT color=#0000ff>/* read result of initialization */
/ R, M/ ^: w( X# j- y$ kerrorcode = graphresult();
3 w; q6 h: O5 u5 y+ s! Y' @/* an error occurred */ ) r8 R: ~" G$ O3 F9 ~
if (errorcode != grOk)
/ A" [! C' K" E/ o# _+ X6 m8 _{ , f5 m, b( C/ a! X* m6 W
printf("Graphics error: %s\n", 4 g( x6 `4 B+ U: q1 P$ O
grapherrormsg(errorcode)); 2 _  L8 k- W* c8 p6 ^9 t
printf("Press any key to halt:");   s7 \3 Y% z" h6 G4 A/ y
getch();
+ f, }7 W- r- O! [/* terminate with an error code */
5 e1 z+ m" @: f$ p: _" Xexit(1);
+ h  V$ \0 V; K1 \8 ~} </FONT></P>
- c8 z+ r  [# f, h<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 [$ F" P/ U* ^/ ]
midy = getmaxy() / 2; 7 O# x: V) f  O2 u$ Q1 j6 S
setcolor(getmaxcolor()); </FONT></P>; ^& Q0 S# n. A2 h  x0 j- O
<P><FONT color=#0000ff>/* for centering text on the display */ ) s- s& j5 s# c3 C, g, f
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>3 d" @- Q& b7 }3 Z% ~( H8 s
<P><FONT color=#0000ff>/* get the current background color */ : Y" y; F( u  f& T+ U- Z% p& K# ?2 t
bkcolor = getbkcolor(); </FONT></P>" V  O+ E& B) M4 s% t
<P><FONT color=#0000ff>/* convert color value into a string */
9 S% v  w  M% titoa(bkcolor, bkname, 10);
/ q  R, L/ A% g; V" U' Pstrcat(bkname, 9 g( u1 Z! U$ @& T
" is the current background color."); </FONT></P>
4 v  u; W' F' I1 K' j* c) j  e<P><FONT color=#0000ff>/* display a message */
) `' u% K( ], Q/ H" _outtextxy(midx, midy, bkname); </FONT></P>" O' {) |/ i5 x' V
<P><FONT color=#0000ff>/* clean up */ 3 U" q* G, j7 W& i9 P
getch();
! A2 d8 E% t) P' [9 rclosegraph();
; F- ?; _+ Y, y9 {6 b; |return 0;
& `7 ]# m7 [. m+ J  }}
4 p/ e6 R2 D  k( o6 a2 X$ ?
' G" u' g% t7 s$ p7 ?# ~</FONT>
& W& y8 c* }* `' |. W4 w</P>
7 k( l7 V7 f4 W; p# R<P><FONT color=#ff0000>函数名: getc </FONT>/ n+ F" A2 U3 u* q1 e5 z
功 能: 从流中取字符
7 W( `# _/ ]. W3 d, c用 法: int getc(FILE *stream); $ ]+ p$ S, D' t; {" G, `3 a
程序例: </P>
' B7 A3 d4 R2 C1 N! A4 _: d( y<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>3 i9 P* T! u* F0 W5 Q0 m7 ^
<P><FONT color=#0000ff>int main(void) - I3 V* D* I: S
{ 8 I" m3 w3 M3 I4 v- Z) c
char ch; </FONT></P>
1 }! Y) b! D( u2 i- S<P><FONT color=#0000ff>printf("Input a character:"); 2 T6 D/ Z; w& |
/* read a character from the ; d  o9 t6 Q  l9 H+ Z: |* j9 p
standard input stream */ ) H( C' P" D# o) M* a; f
ch = getc(stdin);
; K& g7 ?+ A4 b6 S2 mprintf("The character input was: '%c'\n",
; v% e# }$ S$ V  Rch);
5 w' y+ I! t# x. @, ~0 @return 0;
4 c+ U: W6 ]2 u. d7 S/ e( x}
! ~  q7 B% E) ^$ e  D7 X& S! v7 ]3 S
</FONT>% I9 ~; b9 Y3 ~( i7 I, p
</P>! a- x+ L' h1 C. L2 ^3 w5 x+ y
<P><FONT color=#ff0000>函数名: getcbrk </FONT>4 i" u2 H5 D: W$ S" u
功 能: 获取Control_break设置 $ @  n( T2 Y5 b' {9 T5 g1 K6 b8 L
用 法: int getcbrk(void); 7 d5 K( N) a$ _; Q+ T, G+ N
程序例: </P>: x6 D2 F$ w% d6 Z. B, h
<P><FONT color=#0000ff>#include <STDIO.H>2 G' o' h  C$ `# D; `
#include <DOS.H></FONT></P>8 S3 D. ?' |; n6 t1 X! C
<P><FONT color=#0000ff>int main(void) . o6 |7 u3 ~9 T: I& o( }3 F
{
$ J9 h8 v2 U* y* P7 I4 ^% O9 {# gif (getcbrk())
+ ~4 H, e2 ?' Q0 mprintf("Cntrl-brk flag is on\n"); $ l% L. u2 S: N1 Y- h. ~
else
! ^) i) |' P6 s5 Oprintf("Cntrl-brk flag is off\n"); </FONT></P>
; C2 {: r0 C4 i% r, r. b<P><FONT color=#0000ff>return 0; - \5 s1 D8 @3 m
} </FONT>
/ ]& C/ S* s  P1 L7 H8 a0 `) n
" P% y  Y. T, _* L</P>
$ c$ L+ u  g+ S! u; ]$ I9 ?<P><FONT color=#ff0000>函数名: getch </FONT>
* ^/ l6 h! z+ M( K功 能: 从控制台无回显地取一个字符
; Z2 R6 ^( T" ?  X. i6 h用 法: int getch(void);
" O' @- s4 D( }程序例: </P>
+ Z4 K9 x/ o9 H% m<P><FONT color=#0000ff>#include <STDIO.H>- y( h- f" ?) @
#include <CONIO.H></FONT></P>+ G# n, N$ }! R) v8 z' B
<P><FONT color=#0000ff>int main(void)
4 ]( ]8 T4 S3 W{
% ?! U& \; H% B: T$ _( Ichar ch; </FONT></P>
+ D) V* H% R7 v  K<P><FONT color=#0000ff>printf("Input a character:");
7 H* _0 V# b1 B) K# Dch = getche();
1 c; R9 r% M( e' Oprintf("\nYou input a '%c'\n", ch); + y8 m' G# b' s6 z% `/ ~, b
return 0; ' `. J' j, h0 S
}
( N, S( `% U8 y1 P" ^/ r6 J% s# l, t7 g7 r9 R  x
</FONT></P>3 t/ u- a9 _3 q/ Y" f+ J+ l" \
<P><FONT color=#ff0000>函数名: getchar </FONT>
2 Q* W* L2 D( j功 能: 从stdin流中读字符 & |3 F" U% v7 c  a- [5 i  k+ E
用 法: int getchar(void); 7 Y5 D- F" ^, E5 }" V/ ^+ B- d
程序例: </P>  [8 q, V6 A, D
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
; Z1 J$ s. F' Z6 s0 f  a# }<P><FONT color=#0000ff>int main(void)
5 S* ]7 a2 V' L! l7 z8 {{
0 I7 o7 |5 Z* B# aint c; </FONT></P>
. Z2 ]* C. r) L( s) P<P><FONT color=#0000ff>/* Note that getchar reads from stdin and 7 ]9 f" e, g7 J/ T" p+ N1 m1 D
is line buffered; this means it will 8 U: V& }4 W. k' }5 ?6 ^
not return until you press ENTER. */ </FONT></P>- D4 l7 [+ k8 r" B3 F4 C
<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
" `) `! d+ ~2 ?printf("%c", c); </FONT></P>" L0 @" F; d# V7 w& B
<P><FONT color=#0000ff>return 0;
2 v3 u1 l8 c8 J  ^} ' R0 B% t  q  ^
</FONT>+ i/ y3 c1 y7 E, S
</P>
) o) e2 M) w' r6 ]! [9 y0 J<P><FONT color=#ff0000>函数名: getche </FONT>+ a* e7 x6 T; z& Y
功 能: 从控制台取字符(带回显)
; r. _3 u% Q$ k2 O# ~5 k用 法: int getche(void);
% |9 f  ]" H8 G程序例: </P>  s# U) ~# e* L
<P><FONT color=#0000ff>#include <STDIO.H>
4 N1 {- A2 y6 w#include <CONIO.H></FONT></P>
( [/ W$ _  y$ @& T2 Y  @<P><FONT color=#0000ff>int main(void) 3 \( ]; r( Q; W% }; a9 E' a1 ~- U" c
{ 4 d; y8 i" Y( i0 l1 x
char ch; </FONT></P>) f/ T  T8 `4 a2 L
<P><FONT color=#0000ff>printf("Input a character:");
0 N$ o( ]6 \( _4 @ch = getche();
& O* a6 q! R2 U6 c; Z: \7 Uprintf("\nYou input a '%c'\n", ch); # L: p) h; E3 d4 P' w0 y' v6 q
return 0;
( X) s- c% ~! m9 m- }/ ^1 I8 k+ E" H}</FONT> ; m! ?* X6 h6 B8 @
9 F" j: x$ P7 k! P$ G
</P>
- S: `/ V4 @* s- N' y<P><FONT color=#ff0000>函数名: getcolor </FONT>
. g: w, @2 N& ~  Z功 能: 返回当前画线颜色 # Y: z/ ^$ Z6 ~# ^" `
用 法: int far getcolor(void); 8 N) O; k% H. l. C5 J
程序例: </P>0 b% B* N7 u. L  n0 A% @
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 h/ {- d3 E( \9 Q8 Z! M9 U* v#include <STDLIB.H>- l+ E/ c, U1 V2 n( P" p/ C
#include <STRING.H>8 X( x: A6 m1 p: i# W6 a6 U' c% w- G
#include <STDIO.H>  j, O7 d& v. B
#include <CONIO.H></FONT></P>6 D7 h6 V% a. ^" V
<P><FONT color=#0000ff>int main(void) 2 I/ z. P4 h3 S  `5 f8 A
{
+ S5 X0 ^$ H0 G- c# n3 i& U" Z/* request auto detection */
/ {% A6 o; A. ~% kint gdriver = DETECT, gmode, errorcode;
% E' g% Z5 c9 z1 S) `# h+ P' b  C+ Fint color, midx, midy;
; V2 Z% r# k- T- Y; O: E) kchar colname[35]; </FONT></P>
% \6 V, ^  R7 g$ W7 m6 ?" Z& ~% U: U<P><FONT color=#0000ff>/* initialize graphics and local variables */
; k! l* j2 U3 a9 n2 winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
. F) T' k+ b$ O3 }8 r1 f3 l<P><FONT color=#0000ff>/* read result of initialization */
2 g0 k9 g$ M/ w/ O. \6 cerrorcode = graphresult(); ; W& n/ r) u" ^7 p/ y* D
/* an error occurred */ 2 i' K2 ?( H2 W1 z; f- ^
if (errorcode != grOk) " U( s) `8 R- G- Q2 s
{
5 S, k! J2 }! C: \+ X8 }printf("Graphics error: %s\n", 2 X. ?6 z8 h9 @5 ?5 W1 E
grapherrormsg(errorcode)); 7 R4 R4 r) g) j4 L) ^$ s; ~
printf("Press any key to halt:");
4 Z8 {, W$ P7 d' L2 N: ~getch();
, R7 `0 L2 z/ K: ]8 P4 p, j/* terminate with an error code */
1 i( y4 H/ p- G3 W8 uexit(1); 7 D% W6 A, k7 H& y1 A
} </FONT></P>
2 N- p' Q$ w" X: N* E0 \8 v<P><FONT color=#0000ff>midx = getmaxx() / 2; ; ]- Q6 _, g! ~" Y
midy = getmaxy() / 2;
8 @3 |' ]/ M* L) i, L* `setcolor(getmaxcolor()); </FONT></P>. y& N1 N  Z+ w6 A
<P><FONT color=#0000ff>/* for centering text on the display */
8 O# W9 z" F9 n* Ssettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
2 C# \. ]  F8 N0 {; z9 }2 S<P><FONT color=#0000ff>/* get the current drawing color */ 6 K, M" v7 c5 Z" {9 K3 T
color = getcolor(); </FONT></P>1 G' L5 L) C* g' y. J. ?. u
<P><FONT color=#0000ff>/* convert color value into a string */ & v9 F1 h" y! T0 a
itoa(color, colname, 10);
* v  L# a* S7 v3 i- i( ]! bstrcat(colname,
% G6 r" z* T" y; Q$ ~" is the current drawing color."); </FONT></P>
# {" v3 J8 [- ]. G! W$ L<P><FONT color=#0000ff>/* display a message */ + A3 X! }0 A3 e6 q7 n
outtextxy(midx, midy, colname); </FONT></P>
: x" {3 D4 h1 d/ C8 h1 @" g2 V! }<P><FONT color=#0000ff>/* clean up */
4 ]7 D: k7 C8 A  }getch(); $ g% s, I0 V' E4 _7 s) v
closegraph(); 0 B1 J( @7 w, ~( P( z2 |4 Z
return 0;
; L6 d! |/ k9 a}
( e3 U4 o" Y4 [/ b& N' t4 z</FONT>
3 Y( g0 W+ X# d& F8 Z! u</P>
9 `" m" G2 I9 W/ v2 F3 j6 n<P><FONT color=#ff0000>函数名: getcurdir </FONT>3 }: N: \3 F0 x6 a
功 能: 取指定驱动器的当前目录
$ X7 H- s4 l9 H0 [3 C用 法: int getcurdir(int drive, char *direc);
* g2 {" O' ~" ?" d程序例: </P>
% z, w+ `, X( ~# f& l: \2 x<P><FONT color=#0000ff>#include <DIR.H>
+ P  Y% C# U" f: n' }9 I; T#include <STDIO.H>
$ c' a1 R& f! K" r5 V#include <STRING.H></FONT></P>
# M' E' O/ ?& ?+ r" c<P><FONT color=#0000ff>char *current_directory(char *path) 0 @' J2 B8 ~# ^6 X3 s2 o7 d
{ . T1 _9 i; s5 [5 P/ S) X
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
) f, J# S# O: }" q3 o8 f& @path[0] = 'A' + getdisk(); /* replace X with current drive letter */
. c$ l5 }3 o0 |$ f$ bgetcurdir(0, path+3); /* fill rest of string with current directory */
3 D+ p" u: n3 n' }4 l, Nreturn(path); ' X* J  e' D  y, v. T- b
} </FONT></P>
& \9 y. T" a) Z8 N' Q' p/ q9 P<P><FONT color=#0000ff>int main(void)
2 [3 r* S- S3 b9 B: Q" G/ V{
/ L4 A6 ^& J" M' m# e# Xchar curdir[MAXPATH]; </FONT></P>7 h. Z8 G8 q8 h3 Z5 |9 s
<P><FONT color=#0000ff>current_directory(curdir);
* a  G. I! v& H8 J% n0 mprintf("The current directory is %s\n", curdir); </FONT></P>
. q8 h; w2 T0 `" G: ^- \<P><FONT color=#0000ff>return 0; - z" l  K% K& y* G) B. w
} 8 N$ h8 E9 e- W/ u1 {3 _' \
</FONT>
5 a) Q4 c  O5 Z</P>+ }! g. [7 X$ Y! b/ v, _
<P><FONT color=#ff0000>函数名: getcwd </FONT>
, I" e+ H# ]; l, p9 Q* Z& H功 能: 取当前工作目录 $ B- c& m# U/ u( W2 j' x3 R: V
用 法: char *getcwd(char *buf, int n);
8 V* y) |# d4 k) c7 R3 ^! B7 g程序例: </P>
  g) E* o9 `4 h: {6 W<P><FONT color=#0000ff>#include <STDIO.H>
4 I% g2 ~9 z* M9 B$ f" J#include <DIR.H></FONT></P>$ }% Y  I7 g; |5 W% q6 D
<P><FONT color=#0000ff>int main(void)
2 y( r/ ~0 H' X5 W{
* l: ~/ B9 b0 S7 ychar buffer[MAXPATH]; </FONT></P>. X) R) p4 q# Z: g5 S
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); 2 ]/ d5 A4 v: x. R! @# |
printf("The current directory is: %s\n", buffer);
5 z4 U2 i6 [7 Greturn 0; 1 r4 u+ a' K  A0 H
} </FONT>( i, b% V1 w9 o* j8 g! Z4 q

. a1 G. G3 P: s% |% k0 D</P>
' L2 I6 r+ [6 ]# j* m<P><FONT color=#ff0000>函数名: getdate </FONT>0 O" P% {7 m; E  V+ y- L& P# T" f
功 能: 取DOS日期
6 k6 B8 ~" o2 t) L$ @用 法: void getdate(struct *dateblk);
6 O2 v+ G( n. Z程序例: </P>
8 R; R: |- z" y$ b( N/ L- u<P><FONT color=#0000ff>#include <DOS.H>% `2 a# P8 S+ @1 c4 a
#include <STDIO.H></FONT></P>
( C2 ?" _: T9 S6 d2 M3 Q; D<P><FONT color=#0000ff>int main(void)
" f, h4 C2 _% I{
4 ]" X: s+ Y6 \8 ]struct date d; </FONT></P>( E8 M6 ]/ \, N4 ~( }
<P><FONT color=#0000ff>getdate(&amp;d);
) a, y2 i: P2 q- x' ?% fprintf("The current year is: %d\n", # F( z" d' k6 Q- \: k+ ?. b1 `  T0 }
d.da_year);
; I/ S0 i: W* R4 {' \9 X0 Lprintf("The current day is: %d\n",
% u  v! \' ]7 w5 K% cd.da_day); 8 }( Z- \. {) h& J' {  w
printf("The current month is: %d\n",
5 E# \* d7 v, U5 y, }* {d.da_mon);
" |1 s, \/ n! z0 C( X) Yreturn 0;
; w) q- x1 S0 @  X} ' w: P7 m7 V" \/ s& ^
</FONT>
: y" V" Z/ }% a) `8 i/ K3 S/ A</P>2 }- N4 C3 m4 I2 t2 y+ g; A. U
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>4 u8 e( _: b, B0 ~, s7 f( ?& h) m
功 能: 返回调色板定义结构 . t1 N& u/ A: X5 y# Q, R) P0 n
用 法: struct palettetype *far getdefaultpalette(void); 7 s$ i: U* B$ z3 o
程序例: </P>& g6 F' L$ F3 E2 z1 X( [
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! O# N1 k: S1 w! K, \#include <STDLIB.H>
2 g  F: m/ P" d#include <STDIO.H>* |" m1 |1 g- X* z6 _. T
#include <CONIO.H></FONT></P>
% V" t' k3 g: {; [6 F% w- a<P><FONT color=#0000ff>int main(void)
/ e' J  J1 e/ Q# w- O* \{ 5 [/ C" z; `/ k! E
/* request auto detection */ 7 n1 r3 ^+ w2 B% B* \% O
int gdriver = DETECT, gmode, errorcode; ) h8 ^7 A6 A: R" M
int i; </FONT></P>' `! H, Q) @3 L' @; M/ [; m& Z+ o
<P><FONT color=#0000ff>/* structure for returning palette copy */
2 S$ l  e) w3 {" p( Dstruct palettetype far *pal=(void *) 0; </FONT></P>$ ]; q3 ]. a! w0 F! P
<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 \! S, F0 b- x, _$ j9 {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 M0 h* X2 j  e/ z/ g* ^; }<P><FONT color=#0000ff>/* read result of initialization */ 4 B6 W$ d+ v, O) _3 {2 @
errorcode = graphresult();
6 a0 a3 G' f  k7 F' }& w8 Y/* an error occurred */
( Y- q1 h2 o! J9 F. q8 S" Pif (errorcode != grOk) - z$ h9 d+ y! i
{
' I7 c" v; r( P5 u, y, Hprintf("Graphics error: %s\n",
+ D* W/ r% v& Ygrapherrormsg(errorcode));
, e; ]5 m$ F" \/ kprintf("Press any key to halt:"); 0 {, z1 H% w( [( m# H; z
getch(); ( l2 v8 j/ c  _! ~; @. `* ^4 }
/* terminate with an error code */ 9 f- s6 B( H; D1 O
exit(1); ' |6 J! H& D/ T( S0 Z
} </FONT></P>1 q+ d" U/ P$ p" D! Y# n3 ]9 e( x
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>6 a( w; O. z5 G. \. X& b
<P><FONT color=#0000ff>/* return a pointer to the default palette */
$ F1 J0 c- p( p# [pal = getdefaultpalette(); </FONT></P>
! I" ^/ y& e* C, Z8 a& W<P><FONT color=#0000ff>for (i=0; i&lt;16; i++)
$ r1 ~4 b3 v" P6 \{ * [9 Q, q/ |, M4 }6 \+ u$ a% q
printf("colors[%d] = %d\n", i, , v) l; x" z+ P+ {0 A. W
pal-&gt;colors); + T' V2 e* r+ ?+ B5 f5 |
getch();
3 c6 x  x  n  N" p2 N) A5 V} </FONT></P>' x1 S( t/ E6 Q' y
<P><FONT color=#0000ff>/* clean up */
' p$ Y+ K( S- \6 Z1 `6 o8 P6 m' }getch();
$ U2 x# e4 Y+ h+ a+ U- vclosegraph(); . w- X2 Z% y# Y, [9 {" C" m6 h
return 0; : E2 C7 i" [+ ~6 C
} ' ?+ h; O- S, |7 U7 M5 P
</FONT>7 s! \1 L9 U4 h% {* w8 p+ W
</P>+ ~& z+ v8 ~+ z- i5 G4 R
<P><FONT color=#ff0000>函数名: getdisk </FONT>7 b& P* K- Z! V# t+ V' Z3 }/ C5 ]
功 能: 取当前磁盘驱动器号
1 N7 @/ R4 l! k+ W1 |( Q7 T) p) W用 法: int getdisk(void); 0 q% O# z6 Y- \$ _
程序例: </P>
9 k% H% Y- L) S% w( t1 M% C: J<P><FONT color=#0000ff>#include <STDIO.H>3 Y0 q( R; b# P
#include <DIR.H></FONT></P>/ s0 h% E7 y1 G$ f$ L' N
<P><FONT color=#0000ff>int main(void)
# ]" o+ Z4 v! ]5 g/ v{ " F( x& O1 ^% c# p
int disk; </FONT></P>2 v4 |' ^/ H" a, ]7 _1 i+ D" |8 v: R
<P><FONT color=#0000ff>disk = getdisk() + 'A'; " v+ x- I, l& |9 y+ @2 i
printf("The current drive is: %c\n", / ]5 i' K% m, S$ @  A
disk); 8 }# T% i! K& O4 v* [
return 0;
  {' c, i  t9 c# k: d} * i3 q2 D8 D4 A( W7 j3 r
8 s) B: W) R  |' m8 J3 I
</FONT>  x. s: h3 c" A  b* u0 L6 q0 [
</P>3 l  [7 ^% b3 \! z. ^
<P><FONT color=#ff0000>函数名: getdrivername </FONT>8 [; b. I- H5 T* U
功 能: 返回指向包含当前图形驱动程序名字的字符串指针 9 z1 F6 x+ c8 {* L9 _( v
用 法: char *getdrivename(void);
2 M6 T. S* I/ x) }程序例: </P># a& B" `. @/ g# M
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 a& h7 s- B2 |  O  `/ m. A
#include <STDLIB.H>* _$ x8 a! [- m  _: k; |& }, p
#include <STDIO.H>
0 E7 M7 {& S0 J. U+ p+ \- x#include <CONIO.H></FONT></P>) o/ j1 ]! I  r5 V7 l
<P><FONT color=#0000ff>int main(void) 8 T& Y8 Q9 S1 a3 @0 M
{
+ `& x8 X) j/ G. m4 I) l/ I/* request auto detection */
* G1 i  p1 z0 j+ x0 L: F" ]int gdriver = DETECT, gmode, errorcode; </FONT></P>$ H  t4 o* I! H: k1 H8 ]" S3 M
<P><FONT color=#0000ff>/* stores the device driver name */
5 [& H  ]4 }; W! n2 j' Z  [char *drivername; </FONT></P>0 u9 p! T, T/ ^3 y, I* d
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - K9 x% s2 K8 b4 V  h. I, o8 ~
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* X) p( Z* b: X( K, q
<P><FONT color=#0000ff>/* read result of initialization */ / g- n" E" ?/ b' K& q
errorcode = graphresult(); 3 X* Q6 F3 b/ g2 @! o
/* an error occurred */ 6 m  _; |, j. T. s- @9 v: X
if (errorcode != grOk)
, o8 k' h  [3 N! @( E$ [# z3 Q{
9 y7 i) _2 b7 Z0 ]  }9 iprintf("Graphics error: %s\n", $ ~# a0 h7 p- N' A* r2 @8 T
grapherrormsg(errorcode)); # Z3 F# a9 Y% ^0 @9 j1 b1 N
printf("Press any key to halt:"); ! i+ ?# z) y3 D. B+ ~* z4 w; A* i/ M
getch();
& k( v/ m+ ]' K+ @9 k5 ^/* terminate with an error code */ 6 r0 s  `$ ]( f3 m. W5 y/ z
exit(1);
  Y& g. {8 `5 y; w# Q} </FONT></P>
( N" O7 Q; |, H<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
! m; C; w* v$ y' U<P><FONT color=#0000ff>/* get name of the device driver in use */
# x3 f) b. X6 K+ v/ V( pdrivername = getdrivername(); </FONT></P>1 I: g' `( d4 I6 x  ]( }* W' N* [
<P><FONT color=#0000ff>/* for centering text on the screen */ " r% c5 c  a: Z( `* ?' N( B
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>6 V% r, b4 h! w# S$ u2 ]4 }) b0 a
<P><FONT color=#0000ff>/* output the name of the driver */
: U& _: A( m5 Q6 }& R  l  n- uouttextxy(getmaxx() / 2, getmaxy() / 2, ; |, }1 P# N8 b) }
drivername); </FONT></P>
0 P' {* C9 E) N5 x0 e$ ], l<P><FONT color=#0000ff>/* clean up */
  C* C) U) g5 I: x2 F, i- I8 sgetch(); + J8 D4 v7 Y( R( L3 B# w0 y0 f
closegraph(); 1 T3 e, }" y! d1 z3 m5 D$ N
return 0;
' [. l* J8 @" t  E}
' X. |+ N8 n8 ?, t</FONT><FONT color=#990000>
5 I" w5 T4 h, [+ u. d</FONT></P>* y" @2 p" [+ G7 j! y! ~) R$ }7 F
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
# t' T" p0 [6 ^<FONT color=#000000>功 能: 取磁盘传输地址 1 P6 o  _8 z, h* P4 M( g! a, a1 o' Q
用 法: char far *getdta(void);
6 w0 L6 u' T2 C程序例: </FONT></FONT></P>) [1 u) D% Y% m2 u
<P><FONT color=#0000ff>#include <DOS.H>+ P  r3 e/ z/ k+ |) @+ @$ z
#include <STDIO.H></FONT></P>6 w8 e) d& o3 p# y' ?0 d' d
<P><FONT color=#0000ff>int main(void) 5 a; r6 j2 g; h) ^
{
0 a# z9 Z/ c" [) u7 {# k3 ~char far *dta; </FONT></P>
: \/ H' B( I; `, N<P><FONT color=#0000ff>dta = getdta(); % N7 j8 @* d) G' n/ j/ }( l2 ~- ]
printf("The current disk transfer \ 2 B; b2 ?  I3 _3 l' `6 j' ^  v
address is: %Fp\n", dta); 8 Z/ v0 b2 Y0 A6 z7 F5 ~
return 0; * n5 u1 ^( P+ }' n9 a, O8 m
} 1 v1 ]/ G( ~5 u, d- U( {
</FONT><FONT color=#990000>; @2 \  F# h: ?1 G" D
</FONT></P>1 L+ o% b! J2 s9 a3 ~5 n
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
' Q! ?' [) v$ X# X% B<FONT color=#000000>功 能: 从环境中取字符串 7 e# P3 {# ]; t% e" X0 A. R
用 法: char *getenv(char *envvar); : |1 T" R5 f! M$ k
程序例: </FONT></FONT></P>9 {6 b5 A& B5 U; C: R
<P><FONT color=#0000ff>#include <STDLIB.H>
- D) e, U) c+ e$ b5 S#include <STDIO.H>* K$ [* |4 H0 w2 Z! @$ R
</FONT></P>0 E5 S% S& `) J* Z# Z
<P><FONT color=#0000ff>int main(void)
5 ]' x8 q2 a7 [( {{
. k  i2 F, R6 i% Z% Uchar *s; </FONT></P>
3 G  c/ @( c* g- f/ v<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ 2 \$ Q  I2 c/ X( [1 U; V/ W: c
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
( w5 l; T) R7 G, m; ]<P><FONT color=#0000ff>return 0;
# r7 e; k& t3 M1 y4 d2 G, U) Y( c1 p} </FONT><FONT color=#990000># p5 h( L( z5 R% L5 K7 M

: y4 E* D- n- c  |) h6 U% o2 `5 O4 [# t5 i* s+ `3 {( E: B( k0 u
</FONT></P>. @8 V6 e) V3 w) F/ f
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>: z- y0 p& ~5 L6 J) \5 t4 a$ K
功 能: 取文件分配表信息
+ H7 C- |! @: N) C. j用 法: void getfat(int drive, struct fatinfo *fatblkp);
: q, j# [7 K9 _5 U程序例: </P>2 \, O& \8 ?# V3 m% ^4 J. o. \
<P><FONT color=#0000ff>#include <STDIO.H>+ P# |9 C0 m* E* g4 x( p, t
#include <DOS.H></FONT></P>
  G/ f, e1 U  g% B1 y<P><FONT color=#0000ff>int main(void)
, g; L7 n" h. h. V{ ! z* ?) Z+ O; k) Y7 V4 @
struct fatinfo diskinfo;
, z* `" X3 N3 S4 T/ v) ]+ Iint flag = 0; </FONT></P>9 ^/ o3 a( P& s- J+ G0 ]/ P6 x
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); $ d8 X4 R5 J- K
getchar(); </FONT></P>
; k. E( G+ E* J<P><FONT color=#0000ff>getfat(1, &amp;diskinfo); : y; R! M0 h# j7 V# x
/* get drive information */ </FONT></P>
- o1 n  V/ k$ `" j) H* y2 ]<P><FONT color=#0000ff>printf("\nDrive A: is ");
; r: K+ s, k! F8 pswitch((unsigned char) diskinfo.fi_fatid) ) K3 J0 u* V1 n
{
$ `* {7 i7 X8 i/ ~7 K) g0 X4 J9 Z0 qcase 0xFD: ' q" X4 {9 m: P# D7 i$ Z
printf("360K low density\n"); - \, w( Q$ O3 K, w$ D1 f1 j. E3 i4 P
break; </FONT></P>
5 u7 y* g+ w% T0 r1 |( k<P><FONT color=#0000ff>case 0xF9: : ]/ A2 {+ A- a/ d. `7 `3 q
printf("1.2 Meg high density\n"); ' V9 @7 `" R' L$ M
break; </FONT></P>. H& i" z8 J" N
<P><FONT color=#0000ff>default:
( i; j& o+ t8 R$ B4 J+ cprintf("unformatted\n"); # S9 k0 W$ N7 @5 A( u! e/ b; p% i$ m
flag = 1;
' X1 U0 I5 E* I* [} </FONT></P>
! J, Z- n  D- i4 }7 P4 [<P><FONT color=#0000ff>if (!flag) + a2 P2 v0 }4 W) r% W5 Z
{   o) v: Z  N$ b4 J
printf(" sectors per cluster %5d\n", : m' {0 s" |: {# D3 F- W8 H; L
diskinfo.fi_sclus); 1 h: m9 N7 Y( s* m! ~! X
printf(" number of clusters %5d\n",
% |& X8 C$ p" k" K/ |4 U- J8 `diskinfo.fi_nclus); " A; I0 X* R7 }/ _+ ^8 ~% n5 b5 `
printf(" bytes per sector %5d\n", . }+ w! j+ X' h1 k/ F5 ^* j, p
diskinfo.fi_bysec); - [9 j* `& M7 {6 G& L
} </FONT></P>$ S; \4 v4 l1 _: z
<P><FONT color=#0000ff>return 0;
# T. y. w+ X3 Q- u}
# ^7 g0 B! V) d0 I# y$ J) `$ K</FONT>
7 R* I# U; \. ]# |</P>$ A* C: I0 B8 n
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>: A' C- I/ T1 J
功 能: 将用户定义的填充模式拷贝到内存中
: \! l, J; s: E8 S7 Q+ r用 法: void far getfillpattern(char far *upattern); ' i- y1 g; r: c! K8 _0 c5 o  y
程序例: </P>
  Q* x2 J6 G& }7 Z<P><FONT color=#0000ff>#include <GRAPHICS.H>/ I$ E' y3 z5 {/ q3 B4 O. x. d- M
#include <STDLIB.H>9 p! {% e, \* G- S, d7 l
#include <STDIO.H>3 `+ h7 ^$ ~; o% C
#include <CONIO.H></FONT></P>
5 n6 r$ G9 j/ O$ x<P><FONT color=#0000ff>int main(void)
! V+ F  H, P3 _) x{ 8 a7 B* B+ M1 x% C5 ~/ Q6 J
/* request auto detection */
4 B/ F, E3 B* p; j/ D' H0 Aint gdriver = DETECT, gmode, errorcode; 7 g  g( `: \1 o* s6 u& S
int maxx, maxy;
7 }9 j! \  \" X3 vchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>: d+ B0 i. y; l  q
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( _0 ^; F1 r8 f6 J  ]
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 W5 s6 b6 n2 r* s3 t<P><FONT color=#0000ff>/* read result of initialization */
* N/ k7 B. h+ f) S" Q, G1 |errorcode = graphresult(); % B- c- K4 S! C  d
if (errorcode != grOk) /* an error occurred */
2 F7 M) R$ e, s0 N  v3 P( b- I{
' _( t4 B  d; Z1 ]* z4 Q) aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
* N# n: G/ a& F  [2 n* fprintf("Press any key to halt:");
( z- p. i7 j" e! F( k( `getch(); - b; ~1 F: x6 v) T7 P, K- x
exit(1); /* terminate with an error code */
: w& B+ H, m: [4 M. b# Y} </FONT></P>* m5 W/ x! Z' ^0 A" {9 g5 @' L/ l
<P><FONT color=#0000ff>maxx = getmaxx(); ; t/ v' e! h. j
maxy = getmaxy();
/ p4 P9 q* ], u, V4 U0 msetcolor(getmaxcolor()); </FONT></P>, J6 v4 O, t" _' B
<P><FONT color=#0000ff>/* select a user defined fill pattern */ ' F$ R( ]- M7 ]% w- E
setfillpattern(pattern, getmaxcolor()); </FONT></P>
: q+ }2 ]; Q/ t3 _+ `4 C, e<P><FONT color=#0000ff>/* fill the screen with the pattern */ 3 Z4 h7 ]* J5 [2 \: u% T- K
bar(0, 0, maxx, maxy); </FONT></P>
& S; i+ P9 Y" k. M/ f( V<P><FONT color=#0000ff>getch(); </FONT></P>
% l' i6 N; m& e4 j" G<P><FONT color=#0000ff>/* get the current user defined fill pattern */
9 E4 n/ h- G6 J" o* K+ wgetfillpattern(pattern); </FONT></P>% |6 t" c0 g! n* `9 x$ P& w& e
<P><FONT color=#0000ff>/* alter the pattern we grabbed */ 6 a% H4 {/ v% @3 V# v
pattern[4] -= 1; " r  j& a" i& ?, s* F1 _9 v
pattern[5] -= 3;
3 u: k8 f6 u- c4 lpattern[6] += 3; # I1 v3 @2 B  K7 U- P6 I" C+ b+ i
pattern[7] -= 4; </FONT></P>) g2 Q7 f" a' {* E5 [. h" l" K
<P><FONT color=#0000ff>/* select our new pattern */
; R/ o7 I% R) Z; c/ rsetfillpattern(pattern, getmaxcolor()); </FONT></P>
4 u! Q* n* |" N( ^3 u8 o3 _<P><FONT color=#0000ff>/* fill the screen with the new pattern */ % H% Y$ \  S. U! @* R: j/ J7 Z7 r5 Y6 r
bar(0, 0, maxx, maxy); </FONT></P>
7 h& d; C+ z" f& M<P><FONT color=#0000ff>/* clean up */   ~& C7 i9 g$ v  G$ R/ I; j
getch(); 9 M9 p7 ~' ]8 F& @/ Q; h
closegraph();
) w$ a. P# e, i9 v% P, v0 breturn 0;
7 L% W/ G+ O. `$ T+ e}
9 x0 P) A& f; b# h: v4 V1 [</FONT>
6 a" A/ l# Z5 h+ _</P>
5 S8 E7 M# M, I) V) D1 R2 n0 z  X<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
( x0 @; \, H7 z# R! Q7 x7 _功 能: 取得有关当前填充模式和填充颜色的信息 ; q! f0 D7 @. ?9 F, g4 Q8 X
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
% t' ~7 y( \8 F, x5 a8 w& G. L) `程序例: </P>
2 k, C  Q; m" t0 l<P><FONT color=#0000ff>#include <GRAPHICS.H>$ x% W" C1 w! [9 t1 v
#include <STDLIB.H>+ e' Q: G+ A. ~- s. u
#include <STDIO.H>8 n$ d5 J: P4 {: Y
#include <CONIO.H></FONT></P>
5 v! ^0 g. ]0 s" x/ B- u* f5 o- r! d<P><FONT color=#0000ff>/ the names of the fill styles supported */
( f4 ~( \# J- G8 k( jchar *fname[] = { "EMPTY_FILL", " T  z, v2 j( S5 `# Q! }5 t: R3 W
"SOLID_FILL", 3 u2 |% R6 O/ @, ]  r6 F
"LINE_FILL",
9 x% [8 u2 ~) C& Q"LTSLASH_FILL",
4 S. c* G  ^/ S8 S$ Q4 {"SLASH_FILL", 4 b. d8 o% w4 T! B+ W: f
"BKSLASH_FILL", 0 p9 x) l* D  l) L2 r' a1 p
"LTBKSLASH_FILL",
5 w- n& ?" g4 y. ~6 r! P- ~+ U* v"HATCH_FILL",
6 T- ^0 W8 O6 j! n"XHATCH_FILL", " p$ |' {4 [7 f# i7 D% G
"INTERLEAVE_FILL",
8 r  ^; i* X1 C2 i4 D7 ["WIDE_DOT_FILL",
% F' D. }& [5 }  \! {7 g" `"CLOSE_DOT_FILL",
1 Q7 Z" X3 m. q- q"USER_FILL" 9 |9 j9 p3 h: j  l) G
}; </FONT></P>
7 G* ?, Y2 H  x. i# ~+ P<P><FONT color=#0000ff>int main(void)
" M* u. n0 g! D2 ?{ + S7 ]7 K  `9 B- y$ v- c0 p$ t
/* request auto detection */ , N1 Q0 N9 J* h' ~2 a2 \
int gdriver = DETECT, gmode, errorcode; ( A7 A+ K. }) H# _5 y" @" H! V1 r
struct fillsettingstype fillinfo; ( j3 T& w# m( o! `5 G; \
int midx, midy;
! [: ^) O  G' T8 r5 x5 Achar patstr[40], colstr[40]; </FONT></P>
* `. x$ @! O+ W<P><FONT color=#0000ff>/* initialize graphics and local variables */ / i- R- @6 x4 A6 Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" d4 i0 Z3 V* e% v  o<P><FONT color=#0000ff>/* read result of initialization */ # |. }, B) M7 v9 ^" n. [5 n$ K
errorcode = graphresult();
7 y" i6 ~( Y$ z3 Gif (errorcode != grOk) /* an error occurred */ " v% U. S, c$ n' d+ Z/ ?5 e
{
6 W5 o4 \' d( Jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 r  X" P; j- o, B5 q7 a
printf("Press any key to halt:"); / ?+ }; I$ r& o
getch(); 5 [4 K; W! A" ]& U$ Q; ~4 E
exit(1); /* terminate with an error code */ 0 @; C# D4 j$ w( d$ R2 \: k) z
} </FONT></P>: _+ n& H; H& j* z
<P><FONT color=#0000ff>midx = getmaxx() / 2; 1 v* z( E! \% Z- @. q( K# P4 ?
midy = getmaxy() / 2; </FONT></P>8 C- D; A7 n) S! t
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ 5 L' d- [# O& m/ i! M4 }9 e
getfillsettings(&amp;fillinfo); </FONT></P>
: {$ L9 }$ F/ @+ E7 W<P><FONT color=#0000ff>/* convert fill information into strings */ , a. u3 t2 i% Q2 E
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
  ^' A, G+ U& [. Esprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>; n! r: y3 Q1 ~" z
<P><FONT color=#0000ff>/* display the information */ $ s/ n- D4 h; Z2 V
settextjustify(CENTER_TEXT, CENTER_TEXT);
2 E1 w" W* E0 _( m: S# couttextxy(midx, midy, patstr); & N6 W! k" o6 w
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
# ?; ?. g, x1 y5 ^; B" }<P><FONT color=#0000ff>/* clean up */ $ u* f3 ?, {9 l% V
getch(); ; E( P1 I, B' B/ O
closegraph();
' x' d' q: ^) {9 Areturn 0; % |( k$ }5 R& R$ v
}
' h6 o, o* f  W</FONT>: B7 @- n& Q$ v& q0 E/ B( L9 W
9 q, U3 t! ^4 X% Y4 ~2 ]
</P>
  |6 f: D: T3 P% K' e9 @! B<P><FONT color=#ff0000>函数名: getftime </FONT>
( x- I$ s# w3 e! d功 能: 取文件日期和时间
( U7 A- z* |) B用 法: int getftime(int handle, struct ftime *ftimep); " A' n' C1 b. C& c, N
程序例: </P>
& R. }0 m9 @6 X' C<P><FONT color=#0000ff>#include <STDIO.H>
$ M; p' }  l+ N9 C# X* R#include <IO.H></FONT></P>1 m  B: _8 m1 d. g$ g+ L" U' s" f; m; Q
<P><FONT color=#0000ff>int main(void) 4 M& l, `) i6 n7 b4 g; `/ s9 ~, @, A
{ 3 G% j1 s  f+ H: u! _
FILE *stream; 4 l& ~# j, J% C2 V: \) D
struct ftime ft; </FONT></P>: y3 W2 W: e7 r$ `5 G2 U2 e# D6 v
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
5 M3 i" U! t" _2 W# s0 x8 C"wt")) == NULL) ' B5 l: l6 S; A, d& F4 [- H
{
+ c, Q& a7 Q: `5 `fprintf(stderr, . N: W4 R( O$ a6 Z8 N
"Cannot open output file.\n");
- L( a$ h9 G; O4 b% j8 m* w" E' zreturn 1; : |) V; A5 \* O5 S' }  S  ~
} ; p, S# ?8 c9 Q: g3 p' }+ ^" ?: D
getftime(fileno(stream), &amp;ft); ; Q* m+ a2 {% B8 U1 @4 }. ?% o- _
printf("File time: %u:%u:%u\n",
/ S" P3 ]/ t# h$ Y, Z3 Z4 xft.ft_hour, ft.ft_min,
; @" D8 q( b! j- P- P' Tft.ft_tsec * 2);
+ b# A* ?# f1 A4 ?/ }& {0 Gprintf("File date: %u/%u/%u\n", % }# _- _( `/ q  F' O, K
ft.ft_month, ft.ft_day, 1 W0 N4 t  l. `. W" T/ J5 e, Q
ft.ft_year+1980); + `) q& \' E4 P2 S$ {1 w
fclose(stream);
% y" g' V1 L" _0 o: J& Qreturn 0; 5 z" h9 P' r1 M
}
3 S( g! O: d; e) h" ^3 y  ?</FONT>
% s3 C; K0 E8 {+ B* v' h$ |4 B3 w
- U9 Q+ n4 }: O$ q</P>
* v# B: @3 w" }2 e) q<P><FONT color=#ff0000>函数名: getgraphmode </FONT>, E, I: t" h8 p
功 能: 返回当前图形模式 # K! u/ [2 u4 n3 ]% u! V' `$ D
用 法: int far getgraphmode(void); 8 f- [* `4 }  o  r
程序例: </P>! [6 T: q; t8 p" I5 W6 L( f9 G2 e
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, |+ r) n6 _  a' ~: X#include <STDLIB.H>
. ^7 c& a' P( Z+ u+ j, N# g#include <STDIO.H>
) p$ O7 u, Q, n" b# I1 Q9 y$ ]; j#include <CONIO.H></FONT></P>2 I$ `" S0 O5 x
<P><FONT color=#0000ff>int main(void)
. u; w* X5 L, V1 [* N' z7 {& n{
1 y- ?1 o1 h) j: D+ C/* request auto detection */
: \- J8 [+ P& x! [- bint gdriver = DETECT, gmode, errorcode;
/ J( D$ U; J2 _" r. \/ B4 Wint midx, midy, mode; & l$ p# }1 m2 n5 y- b
char numname[80], modename[80]; </FONT></P>
# r( y! E% z" J4 d2 }" _<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ i7 A% H9 t( Y- V/ c: winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) }" Y9 u4 M) M4 X* M8 i2 _5 G<P><FONT color=#0000ff>/* read result of initialization */
) I- }( r. G7 [! oerrorcode = graphresult();
8 p3 V' D: Q% e6 c. u" m9 q/* an error occurred */ 1 y, u; [1 `: [' p4 W
if (errorcode != grOk)
7 c2 J9 y. G9 w+ ]% p9 Q{   R3 w0 @( ^9 w
printf("Graphics error: %s\n",
2 n9 K4 j" O* w6 H$ O- P1 Ggrapherrormsg(errorcode));
  v# Z6 B* m: ?5 c+ Wprintf("Press any key to halt:"); 2 J5 o% k5 I( m2 Y, l6 `6 T: L
getch(); 0 T! f3 v6 t$ n* u
/* terminate with an error code */ : a+ g4 m: L0 F9 s5 J. |/ p
exit(1); 6 }7 m  {0 @' V; e0 z
} </FONT></P>$ ]3 M$ l# L( t; H6 l
<P><FONT color=#0000ff>midx = getmaxx() / 2; + T  ?& D+ \% r8 b. F1 K2 Z7 A6 j
midy = getmaxy() / 2; </FONT></P>: B0 M! u9 R2 I6 `
<P><FONT color=#0000ff>/* get mode number and name strings */ % z' Z6 }  D, n
mode = getgraphmode();
- C: b2 e" R$ Q+ [( Z" E: Nsprintf(numname,
* c: [+ r# ~4 J( r) w: y$ }/ P"%d is the current mode number.", 4 S9 i6 a' ~0 A+ ^( ~& E
mode); 4 E: t3 |) _8 D- w& U# I
sprintf(modename,
: T3 N: s5 [5 n' V+ }) Q  Q"%s is the current graphics mode", / G$ r0 t! _7 _1 B% C. Y! m2 J
getmodename(mode)); </FONT></P>' Z3 I/ J$ F! f: L2 ~
<P><FONT color=#0000ff>/* display the information */ . a7 S* Z3 v1 ^9 J
settextjustify(CENTER_TEXT, CENTER_TEXT); . C1 d, `, G0 x$ q
outtextxy(midx, midy, numname);
8 c" K' O+ y0 v0 o) O5 vouttextxy(midx, midy+2*textheight("W"),
7 P/ m2 O; N8 n6 ^/ p8 Smodename); </FONT></P>
; K% t; I" C$ r. N) f. b  p<P><FONT color=#0000ff>/* clean up */
3 G, n# j) T4 j& w4 `getch(); + E% e3 q! m1 U/ g
closegraph();
: R3 J5 V+ ]6 Hreturn 0;
! t3 X% ?1 B& }4 v: Z# E" M} </FONT>' u3 V6 i) `8 j: O- b
2 x$ H1 [& S# _  W8 B7 C
</P>
) W( u$ x, ~) U  {<P><FONT color=#ff0000>函数名: getftime </FONT>) q9 l8 f# b0 m0 o( K1 H
功 能: 取文件日期和时间
& O( }) ~) W1 ^  b/ C用 法: int getftime(int handle, struct ftime *ftimep);
& A! R5 P- J! Y9 @7 O程序例: </P>
* g! t$ a5 h; `" B) M  Q<P><FONT color=#0000ff>#include <STDIO.H>
$ q. T( Q9 h' }4 ?' y#include <IO.H></FONT></P>  R9 V9 d! |- J
<P><FONT color=#0000ff>int main(void) 1 z& m% i  ^# ~2 q1 h8 M
{ ) ]  h( o, B0 o0 K- V* R
FILE *stream;
! J$ [( L' r! _( M1 e6 e5 \+ u' tstruct ftime ft; </FONT></P>
  B8 g; M9 X* b" h, S<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
$ l; `: T+ P4 U( a* t"wt")) == NULL) . }/ N2 T& Y0 l% c# k
{ 9 l( f- P4 ?+ Q& @. |; m+ C5 z
fprintf(stderr, 8 u) K$ d2 }2 @$ X
"Cannot open output file.\n");   f' F; v9 \" q& O
return 1;
, H# e1 N  o; c4 c' w) H; y# G}
0 M6 B2 V) L; @/ z6 [& ^8 ]9 {getftime(fileno(stream), &amp;ft); 8 K+ {( j6 \0 ^3 l- ?
printf("File time: %u:%u:%u\n", & g7 q' v; c. _# s" T  g; k
ft.ft_hour, ft.ft_min,
- Q5 o  W0 t/ S! yft.ft_tsec * 2);
9 E' W# e* w1 q1 o! vprintf("File date: %u/%u/%u\n",
5 {! E* j  T3 g; ]8 u. Fft.ft_month, ft.ft_day, 4 c4 R7 }2 ?9 u- Q
ft.ft_year+1980);
7 N4 d' b& t$ J* u/ }5 n' Hfclose(stream);
( z, e" p0 _3 U8 }0 C0 }return 0; 9 H2 h8 x/ w0 N
} </FONT>2 H$ y( ~9 C0 }1 S6 {- h
) G' g8 O+ G$ p# X6 n: P

6 D- f) K% F9 b1 w; R</P>
+ i; r( i& v) O  t<P><FONT color=#ff0000>函数名: getgraphmode </FONT>7 i! B2 J: b2 D/ j5 r& g8 X
功 能: 返回当前图形模式
# h8 ?/ S/ p' U- J6 t/ [5 H6 P0 B9 A7 l用 法: int far getgraphmode(void); ' |5 t1 D0 V. I" i
程序例: </P>
  t  w2 p  \! m<P><FONT color=#0000ff>#include <GRAPHICS.H>
. J7 V6 T% @* N+ q) M#include <STDLIB.H>
1 s+ e& U1 m7 a3 K0 f/ ]3 @#include <STDIO.H># k4 Q3 k. r4 Z7 o% g
#include <CONIO.H></FONT></P>. ~3 U( ~, d" O* x; n) k
<P><FONT color=#0000ff>int main(void)
% }2 }5 v+ v, y4 a$ D' d{ ( W3 z7 z. h% A
/* request auto detection */
$ t! H# V' n' N; [) S# ^int gdriver = DETECT, gmode, errorcode;
2 d3 Q' j0 i+ Z  n9 u- Bint midx, midy, mode;
; l" n8 n/ I/ {( |+ [char numname[80], modename[80]; </FONT></P>
! w8 c; W1 l- D- M- m# C3 @. @<P><FONT color=#0000ff>/* initialize graphics and local variables */
: T( f3 i0 o1 A2 l( Q! P0 vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 h6 b0 p0 _3 Z! f
<P><FONT color=#0000ff>/* read result of initialization */ # l3 \4 [6 P8 i! o$ ]' U7 o
errorcode = graphresult();
! r+ l; a0 \  N- w4 t/* an error occurred */
$ M$ \: q3 t! @1 pif (errorcode != grOk) ; Q0 N% L) `, W
{
2 S( U  i8 `7 B/ o$ X" Sprintf("Graphics error: %s\n",
: ^/ e  V+ b. H+ z, Ygrapherrormsg(errorcode)); % |7 `- {! p+ E
printf("Press any key to halt:"); - {& r- Q/ {( g9 V  ?4 Z6 x
getch();
: i* v, N$ i1 ^8 t0 f" y; Y/* terminate with an error code */
1 l* a0 M3 Q# _2 J5 \exit(1);
5 {2 S4 c0 d/ U/ C5 M' m& L} </FONT></P>
3 Q1 Q$ q& `1 w<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 X( Y6 H7 Y3 E3 hmidy = getmaxy() / 2; </FONT></P>
# x, o3 a( O  w; E* \% ~- g* }- @/ F<P><FONT color=#0000ff>/* get mode number and name strings */ / V/ A' R# C: H$ ?- t" D% T" y
mode = getgraphmode();
- e" R8 P" u! m. V. G/ b( wsprintf(numname, * h1 o! o$ q9 H2 A2 A* ^
"%d is the current mode number.", 9 V4 K# Q! A9 L/ x8 D/ ^7 Z3 K
mode); - n, m5 I& b# n8 Q9 G) W+ v
sprintf(modename, ' D" @6 H# }+ j4 P/ a' ?5 K: h
"%s is the current graphics mode", ! Z  F8 C( K3 f! x; m  `, L* [$ g% E
getmodename(mode)); </FONT></P>$ ^1 k7 E8 x6 T' v9 q& }: a5 x
<P><FONT color=#0000ff>/* display the information */ % j' c+ d5 t$ @
settextjustify(CENTER_TEXT, CENTER_TEXT); $ U$ K5 E( l' O: c
outtextxy(midx, midy, numname); 3 }( c. i0 \" }9 B% N: J; R
outtextxy(midx, midy+2*textheight("W"),
8 q% c( O2 ?- K: N: _1 ^modename); </FONT></P>% Z% T) E% k6 D
<P><FONT color=#0000ff>/* clean up */
) d& W) i% j" ugetch();
, F9 G- S0 e* p6 i$ `/ Dclosegraph(); 3 ^9 k* [! S; o, M+ @+ c. b8 x
return 0; ' i7 r) D; ~# U/ [
} & {& I; i" R% }
</FONT>
' l. W# {/ m7 R' A  a0 X( _$ o</P>
5 L' h' G! ~) N9 w<P><FONT color=#ff0000>函数名: getimage </FONT>3 P! M0 {2 r; I/ H& \3 M! e
功 能: 将指定区域的一个位图存到主存中 ( F3 C7 U$ X$ z* I  c
用 法: void far getimage(int left, int top, int right, int bottom,
9 X( i( f6 h# ]& u) Rvoid far *bitmap); # r1 M# a; {" ?6 S: {) l0 r( F
程序例: </P>+ p) y- z2 U% Z- ^. E, ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# U) H9 B1 Y- B8 q#include <STDLIB.H>
; d+ L% R! u& l. t( I#include <STDIO.H>
% T1 `0 k2 v/ _1 h9 l#include <CONIO.H>+ [% Z1 ^4 A0 a! w
#include <ALLOC.H></FONT></P>/ T& y# C# K& y* y* O2 S, S
<P><FONT color=#0000ff>void save_screen(void far *buf[4]); 2 o6 d( _$ v/ z: x( q6 C- [
void restore_screen(void far *buf[4]); </FONT></P># `3 M7 P* a% w" y8 {1 ?
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>: C* M1 B# u+ U; T
<P><FONT color=#0000ff>int main(void) & u8 e9 ~, A1 h
{ 9 m9 K0 P# I/ C4 t6 q' b
int gdriver=DETECT, gmode, errorcode; & e: x( z7 w; \8 i( K$ S- w
void far *ptr[4]; </FONT></P>
0 e9 K8 I. d( p: J* t2 r7 G<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
2 A  F0 ?4 D% q3 xinitgraph(&amp;gdriver, &amp;gmode, "");
1 A- ^* ~5 w8 C3 z- j0 C4 H) Herrorcode = graphresult(); /* check for any errors */ $ j3 r" R: S. \3 k; K6 m. z$ t( H
if (errorcode != grOk) 9 i. t2 l. F$ L" p6 |/ R. O5 ^' M
{ ! S; o, h0 O" a8 E  k2 z0 k9 B; e
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ I6 h/ S# f) i7 xprintf("Press any key to halt:"); + z( t$ [" P( \! K& m2 }
getch(); ' \0 N7 `( D5 n" `  V
exit(1);
& p, Q* q/ o$ y8 c. v# Z. o# z& Z}
% R) ~6 e: G& t8 k/ _maxx = getmaxx();
( P% a+ d6 E  b0 u# W9 Ymaxy = getmaxy(); </FONT></P>
* F) k! t. d, n) k( q$ J6 c3 w<P><FONT color=#0000ff>/* draw an image on the screen */ 2 @  a8 D+ z9 H2 B8 [' f0 C
rectangle(0, 0, maxx, maxy); 5 k. \% u5 L/ q, [
line(0, 0, maxx, maxy);
+ K0 }4 Q8 c/ d. eline(0, maxy, maxx, 0); </FONT></P>* I* |" p5 K. w# h
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ & p$ i, N1 ?5 T/ ~" K
getch(); /* pause screen */ % }0 X* Y8 p9 ?$ z3 J! f4 w5 w
cleardevice(); /* clear screen */
" p7 T( R8 ~5 w- R# frestore_screen(ptr); /* restore the screen */ % j) f# p8 `% P4 `1 M$ ?
getch(); /* pause screen */ </FONT></P>6 s! G- T+ R! l
<P><FONT color=#0000ff>closegraph();
- B' b$ Q* h! E, z' ^return 0;
8 p2 \: x) K/ P- ]& h8 M/ \} </FONT></P>1 q" R9 a0 h" j  Q3 F- k
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) 6 q5 ]! F. b$ ~' |- _; l
{ & d/ F; J+ I, P0 ]1 p/ w" t
unsigned size;
& O5 O  I) r2 d6 K  L8 h5 X5 Jint ystart=0, yend, yincr, block; </FONT></P>
. Z& g! e+ A3 A9 r* W: H7 e$ _<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
6 J# ]& Z* p* R. p% dyend = yincr;
; p' `% |6 Y& p) O2 l9 {7 @size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
& i; b5 S5 e" o<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) % H/ x* c" E( |! s5 r
{
5 |. t- D& U! c: mif ((buf[block] = farmalloc(size)) == NULL) ( A9 I- V- l6 c
{ ; n" r- g' |: L/ _$ N
closegraph();
9 t+ g# G9 i# q, H7 ~* Eprintf("Error: not enough heap space in save_screen().\n"); 7 V$ Z8 w4 c, b, R1 t; E
exit(1);
7 a* y6 \* o, U% F- T/ |1 c} </FONT></P>
" n8 K# h" b- Y" ^( @<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
- Q& L) `2 V; R4 t3 ^ystart = yend + 1; * Z: a" L: L* j  D! p9 r* V! v; U( q
yend += yincr + 1; . w* ]" K* k4 G4 Y$ S4 ?( H
} " M$ c- R- a6 z2 Z# n( J+ M) M
} </FONT></P>, m# W% n; v% _0 _. \
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) ) L5 L3 J* X2 K9 H) U  m2 ?
{
: l4 [- R4 h% L3 ?9 Z; n) O- s$ Punsigned size; " O5 H: [9 o* O* l) @
int ystart=0, yend, yincr, block; </FONT></P>
0 Z  l) F* a! F1 i. x<P><FONT color=#0000ff>yincr = (maxy+1) / 4; / B* e/ n) v* x# Z
yend = yincr; " k/ U+ h9 |5 ~
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>) j- n/ m) g" ]
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
' `; q, S# s' Q8 r% x8 \2 ?{
. M, U( I+ M3 _. e2 u9 q) S4 Cif ((buf[block] = farmalloc(size)) == NULL)
( ]0 @; w/ @+ B: u. S7 g{
3 M2 t1 E) X* k* }! f  P7 U$ q, Zclosegraph(); 9 r! V" b& ?9 _. w2 i& R# b$ a
printf("Error: not enough heap space in save_screen().\n");
) M. r& a, C% r3 j" K/ F- Iexit(1); 3 {$ T- C: b4 C2 I: Q; l
} </FONT></P>- O7 {  X; [6 _, J2 Q/ S9 B1 ~
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); " z4 l7 e- Q2 Z* j/ X  U4 ~
ystart = yend + 1; # d% m) m" e: p7 u" U7 R- h
yend += yincr + 1; 6 k# r% v8 D0 ^& G' @
}
( `% K5 s' z  V  v' u: C5 ]} </FONT></P>
! i0 O# G0 n. `; S! H; T7 p7 k% V<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) # Y1 i# A8 F" N/ I5 B+ W
{ 9 H& L( a  i& x* C7 H
int ystart=0, yend, yincr, block; </FONT></P>' i0 A2 P$ ~' c( p
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
1 I" H- l( N5 N$ s. I* d) A# p, h5 byend = yincr; </FONT></P>
( \8 @; ]8 r% Z6 a  A% e<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) 7 L5 w( A/ ]# i. J: V
{ + M( d: Z1 _4 e
putimage(0, ystart, buf[block], COPY_PUT);
, Y0 |: L. i  D$ L7 D( u# s+ ?5 sfarfree(buf[block]); / c, C, d: \0 ~5 p' b& L, ~
ystart = yend + 1; , d: p- C  R6 S3 i0 }/ [
yend += yincr + 1;
9 X* F: [5 [8 I$ v5 a) }. V} ! o* y4 G; Y  f
} </FONT>- t0 H, Q, r5 a
<FONT color=#ff0000># P1 o0 f8 f1 I1 E- J6 d7 s  o
</FONT></P>
5 |0 s6 F/ T4 q+ L! Q& k! z1 b<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
. i  y! \  x  B* j0 t功 能: 取当前线型、模式和宽度
6 C' t4 T' {2 c% o" v) I5 B2 ^3 L* j用 法: void far getlinesettings(struct linesettingstype far *lininfo): 3 V$ _4 ^3 y0 T; ^4 e* k7 e1 O! J
程序例: </P>
8 B5 s2 `& E, k* l& G& ^<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 r( |( r  E9 L' K5 S1 h0 O#include <STDLIB.H>' ?4 s9 Y0 h) ~# E2 I! \9 b
#include <STDIO.H>
+ [5 m5 y; c2 V* f' c- {: h4 U#include <CONIO.H></FONT></P>4 N# h& m7 R7 l* k: K
<P><FONT color=#0000ff>/* the names of the line styles supported */
- f/ z* ~3 v. A$ W7 j+ w  Wchar *lname[] = { "SOLID_LINE",
  l0 s+ w, J6 n2 K( ]" [/ Y6 S) K"DOTTED_LINE",
0 a# B5 J: W2 A) R"CENTER_LINE",
0 t' e2 h0 V* O- n"DASHED_LINE",
/ p; ^" J& M/ N* q3 M"USERBIT_LINE" " Y" Q& F- P, }$ j9 L
}; </FONT></P>
( z; k/ O/ C5 X5 ]+ }$ Q$ _% V! @, I<P><FONT color=#0000ff>int main(void)
: r$ S0 k1 p7 `5 x9 i% h8 S{
0 p; Q7 J* C8 y7 @/* request auto detection */
. X7 I7 d! g3 V  gint gdriver = DETECT, gmode, errorcode; - z* g  T: X9 Y5 `/ i  ~
struct linesettingstype lineinfo; # Z3 p4 M9 y3 K0 _  j* X7 }: k
int midx, midy;
3 T1 u8 r- f3 |1 ]! ochar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>. X% k9 g# z5 H+ V$ [' O# e! c6 E
<P><FONT color=#0000ff>/* initialize graphics and local variables */   h* x' R, @! i* c5 y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 [, F. k6 I5 [/ {- J6 H' R5 ^<P><FONT color=#0000ff>/* read result of initialization */ 1 \3 X  L9 \, t- }
errorcode = graphresult(); 3 h8 t# g4 ]9 N: W+ _
if (errorcode != grOk) /* an error occurred */ 6 c6 L4 f( D6 b' f* Q4 a  S, ]# l
{
: B7 \$ E  |/ A6 u: o; Uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
+ m9 D+ K9 J" mprintf("Press any key to halt:");
, ^8 G0 j/ L* J% e5 f; lgetch(); $ ^# t' y$ o3 |3 b9 P
exit(1); /* terminate with an error code */
) F* y+ T) l# X} </FONT></P>
7 v  S; f! D5 o# ~* ^<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 @' q4 B+ X' Tmidy = getmaxy() / 2; </FONT></P>
" E& w( d( X5 O/ h5 G* v<P><FONT color=#0000ff>/* get information about current line settings */ 2 Z' B# ?% K% S2 `
getlinesettings(&amp;lineinfo); </FONT></P>+ L* Z3 e2 Q% j! R/ i
<P><FONT color=#0000ff>/* convert line information into strings */
  l  C6 `% s$ Rsprintf(lstyle, "%s is the line style.",
4 I' a4 P* z( r# Glname[lineinfo.linestyle]);
' M3 a% u. Q; }) F6 E% x& s9 osprintf(lpattern, "0x%X is the user-defined line pattern.",
4 I' s% Z6 l4 ]% Ilineinfo.upattern);
* n! V/ r+ P* N7 F! Esprintf(lwidth, "%d is the line thickness.",
! y+ J/ }+ p" C. Y% W% H' llineinfo.thickness); </FONT></P>: e& g5 `% ]6 u9 ^6 b+ K
<P><FONT color=#0000ff>/* display the information */
6 M2 a* {# _9 R/ H  B3 R8 Csettextjustify(CENTER_TEXT, CENTER_TEXT);
. O, i+ K' G# o3 _0 {outtextxy(midx, midy, lstyle);
5 n  ~; ?7 Q0 i9 W: kouttextxy(midx, midy+2*textheight("W"), lpattern); 0 G9 G/ V/ Q% F+ ]8 k! V$ R
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>1 D: h: K  G* G7 R
<P><FONT color=#0000ff>/* clean up */
$ B) E3 ]# ?  g& S6 h9 ggetch();
% {' {$ N; `% r5 K" Z) F# Aclosegraph(); + w$ z9 M4 j7 k. s& Y- S( ?
return 0;
3 c1 {! a" Y, q0 x  M9 L# Z} </FONT>
8 E/ b, y4 a* ?6 q  d" k/ \) E4 L7 Y4 F3 y, t: u
</P>
! C1 C; l  ^/ ~) |6 V6 J8 n3 C<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>$ ~( Z0 h2 Q& `3 i* h5 C& W# f
功 能: 返回可以传给函数setcolor的最大颜色值
* m: ]$ h5 V. Q2 V用 法: int far getmaxcolor(void); / X4 d# `: v" o  Z- ]
程序例: </P>
. t1 R- ]9 W, t/ z8 E: r2 c. P8 {/ O<P><FONT color=#0000ff>#include <GRAPHICS.H>
. z, O- p9 p3 w" o#include <STDLIB.H>" y4 l6 D; q; V1 j; i
#include <STDIO.H># X4 Y; |7 z9 u! j# b, |
#include <CONIO.H></FONT></P>2 o3 P$ T( b6 I1 F: q3 Y8 x
<P><FONT color=#0000ff>int main(void)
( C- I- z! Z0 O# V, \- Z{
. i6 M6 z6 P3 c- j/* request auto detection */ # z8 k  i. _. m1 R
int gdriver = DETECT, gmode, errorcode; 2 b! u! ]( Z' z. x
int midx, midy; ; ^- v# a" P8 y; [8 K$ q/ s
char colstr[80]; </FONT></P>
6 p! U; L# U5 Y# V4 p* K<P><FONT color=#0000ff>/* initialize graphics and local variables
* F: A  J% d6 F9 d' t6 \7 w3 R*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># g5 Q+ h% j5 z' A
<P><FONT color=#0000ff>/* read result of initialization */
& F. I% I& H6 Yerrorcode = graphresult(); , T+ G. m' L3 J' w
if (errorcode != grOk) /* an error occurred */ ' m1 Q. C/ M8 V* w8 F
{
6 }  ?/ j( M, k& \printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 i4 y' J* K/ kprintf("Press any key to halt:");
. o6 n5 P$ Z. Ggetch();
8 h( t4 @2 I6 n  }* Yexit(1); /* terminate with an error code */ 4 `/ `" o4 {, @
} </FONT></P>
* G# M& n; U, o  [% o5 ^<P><FONT color=#0000ff>midx = getmaxx() / 2; + w. p2 V" I1 e# }# \) `1 ]/ t
midy = getmaxy() / 2; </FONT></P>4 w% Y5 ~8 A3 X$ i0 B
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
5 v% E  C+ J. S7 s/ p, Ksprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
$ q; r, q" _* i3 E<P><FONT color=#0000ff>/* display the information */
. B, d9 I) z! gsettextjustify(CENTER_TEXT, CENTER_TEXT);
9 s1 |9 x! J, r9 U1 @8 {outtextxy(midx, midy, colstr); </FONT></P>9 ~& x; \. g+ A7 c/ i/ e; m
<P><FONT color=#0000ff>/* clean up */ 8 D1 Z' p. s% k8 c) o1 h9 z
getch();
8 `' v! T! g8 cclosegraph(); * E% J1 ?  O" V  K# C$ N0 n
return 0;
% X; Z# o, z# _- l} </FONT>$ K# K# m# S; K+ g( q

2 h1 c( M+ a% Y" w0 q6 j2 v' U' h
1 T4 {' W; C. w. ?( S$ C3 }</P>
/ ~9 b( d  }/ k' g5 }<P><FONT color=#ff0000>函数名: getmaxx </FONT>
! |9 C' U! C8 g& A功 能: 返回屏幕的最大x坐标
6 k% _7 U" H: w4 x. M; Y, V用 法: int far getmaxx(void); ' W" n& [3 D" C: P( l# g: X
程序例: </P>
: _3 t+ E, |1 a4 v# a: @5 i8 M<P><FONT color=#0000ff>#include <GRAPHICS.H>4 M) l2 ~5 C- c
#include <STDLIB.H>
# U9 S4 A" A3 t, M! o#include <STDIO.H>
1 t5 h% M7 d& l3 t, b! P" X, u) V#include <CONIO.H></FONT></P>
: q+ l! ~& F. ?, I6 D# V1 R<P><FONT color=#0000ff>int main(void) $ x8 |3 K4 A" b' C2 O
{ - D! t. ~9 G0 M( ~
/* request auto detection */
0 ^. S+ p  C9 g, ^% ^- X2 mint gdriver = DETECT, gmode, errorcode;
$ x, ?) A- V( v- w& _( x. w: yint midx, midy; ' A# }' ]) ?* O& G2 d1 n
char xrange[80], yrange[80]; </FONT></P>
, {$ I- X( W8 i" B<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 K. z& H+ ^5 ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( i) M4 X0 H' G# Y5 ?<P><FONT color=#0000ff>/* read result of initialization */ 1 z5 l. W# @- e0 x6 ^9 B6 d( J: D3 ^: H
errorcode = graphresult();
$ _( ]3 V! R2 x! }( \if (errorcode != grOk) /* an error occurred */
, z+ j8 z2 h. ]/ }& b& j8 o{
) u2 ?7 [4 K, t7 lprintf("Graphics error: %s\n", grapherrormsg(errorcode));
; k% p+ K9 T+ J- \$ [printf("Press any key to halt:"); ! Z" t3 x4 a* j
getch(); , }* ]6 d2 R! V- u# L+ X( g
exit(1); /* terminate with an error code */ - c% c! h; {9 `- e% U9 E- J
} </FONT></P>
, V5 P( k# r- i1 D2 |) u% x<P><FONT color=#0000ff>midx = getmaxx() / 2; ! ?! t. e) _7 b: f0 m5 z
midy = getmaxy() / 2; </FONT></P>
; d: C$ e& u. ^2 P  A<P><FONT color=#0000ff>/* convert max resolution values into strings */
# o) w8 G% Q  S# h; o! W; y# Lsprintf(xrange, "X values range from 0..%d", getmaxx()); " m4 t3 w' D, g2 |+ s+ Y
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>& {3 c# C* Q  W8 ~
<P><FONT color=#0000ff>/* display the information */
( c- f8 \8 A! Q+ j) gsettextjustify(CENTER_TEXT, CENTER_TEXT); 0 z% i: ]! ]0 g; D
outtextxy(midx, midy, xrange); 9 l0 p1 C9 [5 \
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>* f' Y- \' }/ _6 D* v  P7 d
<P><FONT color=#0000ff>/* clean up */ 6 i1 E: B8 ~; b, ^* S3 S: q
getch(); + ?3 x- E/ h# e& w' e& h
closegraph();
/ F/ Q! j3 E" ~6 [  |return 0; * j+ q3 j: Q3 t- l% p# p' o2 U' ?
}</FONT>
/ U9 M, X  S; H7 O/ m/ ~+ n; ?: @
# A# s9 H2 I, i, K+ t</P>
' U6 M  X( i! e( o6 Z) j/ j<P><FONT color=#ff0000>函数名: getmaxy </FONT>
3 j$ @. F/ _, f+ N  M& i功 能: 返回屏幕的最大y坐标 # `4 ]' w: {% N3 b% `( k! c4 f3 l
用 法: int far getmaxy(void);
$ x3 d8 m& U: ~; z' ?- g4 c程序例: </P>
2 p) v( Y" ^" B( u* ?<P><FONT color=#0000ff>#include <GRAPHICS.H>4 i5 p7 B" q$ p: x2 f
#include <STDLIB.H>
. ^# R( e1 ^( d& e+ a- D# K3 C. b#include <STDIO.H>
. v& v" F7 y) }4 b/ f4 g#include <CONIO.H></FONT></P>- M# E" x9 _& W; M5 E" ]9 Y
<P><FONT color=#0000ff>int main(void) ) n- ]) ^  L8 i# `2 M
{   T( K5 p2 S. r
/* request auto detection */ " |9 q% X0 @6 a0 C. i" F
int gdriver = DETECT, gmode, errorcode;
2 ], o1 F& h, H7 K0 j) t$ F) ]% sint midx, midy; . P# s- W( N  @# w8 @
char xrange[80], yrange[80]; </FONT></P>
* T3 I4 E1 Q0 h. V8 I<P><FONT color=#0000ff>/* initialize graphics and local variables */
! {3 \9 T, R" z1 uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 z1 R: ~' ]* K- O+ i9 B6 }<P><FONT color=#0000ff>/* read result of initialization */ : D% b+ p3 J% r  w, o
errorcode = graphresult(); % q* i5 n3 ~2 x" ~6 n* _
if (errorcode != grOk) /* an error occurred */ / X# k2 \& o- @$ M% j
{
% S! l4 X" U) z( `: V$ |% U5 gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 d3 c, e& c: p/ G' uprintf("Press any key to halt:"); 9 p- ]  K: n* Q; U8 k  ~0 ~
getch();
3 {% [+ Z4 |  x9 c. V; \exit(1); /* terminate with an error code */
( s+ ~6 c6 Z. `$ R# s" V) s' d& J} </FONT></P>
5 J# L9 T& |  A5 o- h( k$ h& A<P><FONT color=#0000ff>midx = getmaxx() / 2;
* P, Y0 k7 H5 y, J( N+ h1 I% D7 a( pmidy = getmaxy() / 2; </FONT></P>: \' Y$ Q& I, w) J# G
<P><FONT color=#0000ff>/* convert max resolution values into strings */ 1 |8 b0 _2 i1 H7 ]# A5 a
sprintf(xrange, "X values range from 0..%d", getmaxx());
7 ?3 Z% e* ~: x6 \) Csprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>, k1 G0 e) {3 d5 s# J: Q
<P><FONT color=#0000ff>/* display the information */
; j% u. g6 U# Y; Q" G5 l8 V3 Ssettextjustify(CENTER_TEXT, CENTER_TEXT);
9 D: d3 ?8 u1 f7 ~/ Xouttextxy(midx, midy, xrange);
) C3 j( M9 C8 V& M2 V$ ~! {5 Wouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>4 N/ _. t  r! u# ?/ m1 d
<P><FONT color=#0000ff>/* clean up */ - i7 o* k) F+ h7 h. E( u
getch(); ( h4 u, B8 K0 s# C1 v! C4 z. O
closegraph();
# b3 c+ g$ S; i" ^! U6 j! U0 }return 0;
0 K; T! V; l" W) n( M} </FONT>0 H$ U1 P/ e- @4 r) {2 r' T" p
</P>3 |- r) d! }& g+ D6 e  G
<P><FONT color=#ff0000>函数名: getmodename </FONT>$ e& S7 O) _8 L# a( I# ?! X* O& ~
功 能: 返回含有指定图形模式名的字符串指针 & T% ?) w  Y5 V4 x9 a
用 法: char *far getmodename(int mode_name);
7 \1 ]8 L4 y) R+ f4 `& ^0 q: l程序例: </P>
' P  r# c" W' q<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 R  h& L6 K* O' ~; ~6 n* q#include <STDLIB.H>
9 |0 R8 }4 G: m3 ]. o1 i% a#include <STDIO.H>, Y8 w" u/ v/ A
#include <CONIO.H></FONT></P>- q  [- S9 R6 b! E9 w
<P><FONT color=#0000ff>int main(void) + [( j+ G8 d# A& U, J! H2 g1 M1 {
{
* ]6 L8 P4 B1 |- Z" {: [; C/* request autodetection */
% P2 t, ^  N" u; Mint gdriver = DETECT, gmode, errorcode; + y! p* g) @( `; n0 D8 ]
int midx, midy, mode;
4 B5 {8 Y, U! ^, e+ b9 ]/ F! I" rchar numname[80], modename[80]; </FONT></P>1 ^5 l3 G/ W" Q6 r8 P# x' m
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 J8 ]6 s* l3 y, e: `4 _( B: }% f
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, J# w/ q: u! o# T% G2 u& ^<P><FONT color=#0000ff>/* read result of initialization */
  x' t7 x  z9 a1 merrorcode = graphresult(); $ A% a4 g. _3 }( C' [
if (errorcode != grOk) /* an error occurred */ + V7 Z4 S9 g' P8 ^% ~4 b
{
0 |9 O/ A) h5 k( ?printf("Graphics error: %s\n", grapherrormsg(errorcode));
  H$ q, D" Y4 Q" \5 ?printf("Press any key to halt:"); / y5 q9 r- ?8 x! u2 w$ V9 E. t
getch();
/ r0 q( w; a% e! G! v7 S. Sexit(1); /* terminate with an error code */ 7 r3 E) ]2 l5 Z$ p- J
} </FONT></P>2 _' I' T9 V6 v; T' V; D% D$ V8 x
<P><FONT color=#0000ff>midx = getmaxx() / 2;
: p1 Y* l+ k1 C7 n- Mmidy = getmaxy() / 2; </FONT></P>
) L+ b4 y; s8 }/ q. E- l* }<P><FONT color=#0000ff>/* get mode number and name strings */ ( ]& @7 n% k/ [# p
mode = getgraphmode(); $ o& }$ K# J* \. \1 w
sprintf(numname, "%d is the current mode number.", mode); # K; m& F% ^& {2 p$ }
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
  j4 L9 U. j7 B' d  o. M- m<P><FONT color=#0000ff>/* display the information */ " J6 {" a% B6 Z
settextjustify(CENTER_TEXT, CENTER_TEXT); " H8 Y$ n. B+ n( k' l( h! ?
outtextxy(midx, midy, numname);
; f" v6 p4 G, Q5 R* w7 gouttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
) @5 g0 _5 r3 B" Y% O( j0 I8 E( C<P><FONT color=#0000ff>/* clean up */
) l: S( g+ A* F- y: N" Vgetch(); ' ^# A/ g) p! _" X: ~* z
closegraph();
  T+ |1 A4 |% i7 I" N; {* y; Lreturn 0; 1 V  i  T' b$ X( E: q  u
} </FONT>
. v) H" ?. a" X# c# O+ s. k& n% D7 G, a* U" e2 U& i" ]
</P>
+ B1 }3 q: S2 E' J. `<P><FONT color=#ff0000>函数名: getmoderange</FONT>
6 K5 d6 P- }& {' H功 能: 取给定图形驱动程序的模式范围
; \# c/ a; F, I" {# ?用 法: void far getmoderange(int graphdriver, int far *lomode, / \( q0 Y' C5 v% Q, \
int far *himode); 4 L  v; T$ ?7 ?
程序例: </P>
- k7 {6 T# {: T- k7 a3 ^/ M<P><FONT color=#0000ff>#include <GRAPHICS.H>
* c0 C- `, A* x) j  W+ H& u9 q" Q#include <STDLIB.H>7 z* ~: p0 X5 S" S  F9 ]$ F. \; e. A
#include <STDIO.H>
5 A" N  ?. g8 t, Q* s# X$ M8 k# f#include <CONIO.H></FONT></P>% t8 E2 C2 `0 y+ e% r( }; Q
<P><FONT color=#0000ff>int main(void)
. o* V& @5 l- g9 f. u" M{
- H" r  v- c+ D3 t) }/* request auto detection */ . v% @% g- n: w2 W, R! H
int gdriver = DETECT, gmode, errorcode;
' o$ b8 k4 J4 o& n) z  Y( S% E; \int midx, midy; ( {/ P/ D' t  I. d8 p  p0 C
int low, high;
$ G0 w. @9 p( P0 hchar mrange[80]; </FONT></P>
8 N4 d! X5 f. [, H9 O- F<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! ~6 V" Z0 ]  Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 ^. [! }" e4 \- R<P><FONT color=#0000ff>/* read result of initialization */ 0 @# i: P# O/ [% O4 I7 p
errorcode = graphresult(); 6 x3 h; ~$ O; ?
if (errorcode != grOk) /* an error occurred */
$ @9 J& y& y* g+ k' n{ $ \% B4 b4 K: y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 v% k1 `! b! A: L# y% {
printf("Press any key to halt:"); $ h  @+ |8 _2 z7 ]
getch();   k6 P$ N: C5 b8 M
exit(1); /* terminate with an error code */ + B6 i$ I) \$ L- \; [' ?
} </FONT></P>. K. Z! A2 b# X1 X" k
<P><FONT color=#0000ff>midx = getmaxx() / 2; * |  [, w) k9 y6 w% |( y
midy = getmaxy() / 2; </FONT></P>
- ^/ [' @  r; _: N7 f1 |7 `" L% B<P><FONT color=#0000ff>/* get the mode range for this driver */
* H( K# Z' K/ g* lgetmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
) i- @! ]- Y$ S& q: Q6 X' F<P><FONT color=#0000ff>/* convert mode range info. into strings */
$ i. y2 O5 ]" h6 L. v/ asprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
" r% h; q% O8 U+ x9 A1 J0 _% @<P><FONT color=#0000ff>/* display the information */
- H: X' x; F. m/ O; Isettextjustify(CENTER_TEXT, CENTER_TEXT);
( r7 Y* W, Z5 @& Y, q9 louttextxy(midx, midy, mrange); </FONT></P>
) v* |7 O7 s! H: d9 o, J<P><FONT color=#0000ff>/* clean up */ 1 ]+ n* ^- O5 S# Y% q' e; ]) g
getch();
0 i( q( R+ a3 F8 s  Iclosegraph();
% F. I: r( P/ X! z5 }6 \3 @! t2 t: ~return 0; 8 Q  b8 \2 b$ S' a2 s! [2 Q
} ' T2 D( t, a- C1 \+ d
</FONT>
+ E! J1 ^& V  f- i, Z& z</P>: \( ^; i) ]. v! P, n* z9 Z1 W8 ^
<P><FONT color=#ff0000>函数名: getpalette </FONT>
3 \  a4 B8 E+ t) v功 能: 返回有关当前调色板的信息 , W2 O8 ?/ ]& t0 F  Q# z7 ~6 Y% ?( ?
用 法: void far getpalette(struct palettetype far *palette);
4 y# X0 F/ _. M  `2 m2 }程序例: </P>
  S9 ]: P6 D" H' K<P><FONT color=#0000ff>#include <GRAPHICS.H>& w# P1 F# R: F" i( K
#include <STDLIB.H>
! M  p$ e1 {4 z* h; }, s4 U% @#include <STDIO.H>5 {  p0 o; r8 i) V
#include <CONIO.H></FONT></P>
5 r  I% v) Q0 ~/ b; l<P><FONT color=#0000ff>int main(void) / t. L$ T4 f9 o# |5 Z+ R
{
, P+ J; ^8 h2 x4 ^5 E+ j% h( n- \/* request auto detection */
4 O! {$ N' v, ?9 lint gdriver = DETECT, gmode, errorcode; ) D+ ?; n5 }. z8 ~' c
struct palettetype pal;
  J6 S$ R8 ?0 B) bchar psize[80], pval[20]; 7 a3 k; y3 Z, t" [
int i, ht; . M" U) Q2 I  A* q
int y = 10; </FONT></P>! @6 c5 B" t6 l" o1 V* U& b
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, a' ]3 K0 u9 ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; _9 Q( I& f$ s4 k<P><FONT color=#0000ff>/* read result of initialization */ 1 A, i1 D" b5 Z; }! l7 U
errorcode = graphresult();
5 q/ Z/ o  x* j  `$ }/* an error occurred */
# ?3 k. W9 i# Mif (errorcode != grOk)
, V! A  d# i. n/ P0 s{ . d9 X9 m5 E  h
printf("Graphics error: %s\n",
2 K' @( R9 q4 _/ F2 ?* K) e* lgrapherrormsg(errorcode));
7 B- z- @# @* @0 ~, e/ K# I) bprintf("Press any key to halt:");
6 `6 K/ H5 t" s6 H2 ~6 r, d+ B% b4 Wgetch(); / c  ^% I4 }) ^+ P# Z) ?2 M
/* terminate with an error code */ : v6 Q/ C" n" l; Q
exit(1);
2 ^6 A; x: M. E) A! h- C} </FONT></P>+ S# {+ D. a; O# n8 Z8 |. ?6 N  k
<P><FONT color=#0000ff>/* grab a copy of the palette */ , l1 Y. C! K- K% b' V( d
getpalette(&amp;pal); </FONT></P>
8 H9 `, c/ l. }6 o5 q3 o2 c& N; m<P><FONT color=#0000ff>/* convert palette info. into strings */ 9 n3 O" C/ M' |
sprintf(psize, "The palette has %d \
3 S) y( }: O& ^modifiable entries.", pal.size); </FONT></P>; w, @" s6 a+ @
<P><FONT color=#0000ff>/* display the information */
) J0 g( J7 M2 d# c; eouttextxy(0, y, psize);
+ `! X- f% x( Eif (pal.size != 0) * k' ]" g5 U" h7 n) {' p% p& x
{
3 [* U& U! z2 @5 t% ~/ k! y% m! d$ hht = textheight("W");
7 o3 r, k7 s$ A) U, w) q2 |y += 2*ht; 7 U, a0 V& |+ l
outtextxy(0, y, "Here are the current \
3 u! S/ x! n7 M$ U3 J+ T9 e, Tvalues:");
) ~6 E& B" q! q/ G- Wy += 2*ht; * _, E0 |1 E  R+ E
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { + B/ `( e4 n, i- {% N/ [& s
sprintf(pval, 8 I8 l4 [% c: t& B; `) I
"palette[%02d]: 0x%02X", i,
, w5 }4 u! A3 G, @! |& W0 Mpal.colors); 8 K' \1 @7 {9 z/ e9 z; P) Y( T
outtextxy(0, y, pval); 0 _. `6 m4 q. k1 L7 Q8 P$ k1 m
}
- K- p# y% }- Z& s} </FONT></P>
* A' j* c. o$ ~6 N' W<P><FONT color=#0000ff>/* clean up */ ( m  X% J0 u7 k- O
getch(); ) D2 K& e9 W( Y; [/ X
closegraph(); </FONT>4 Z  o( K5 y0 T, ?& N0 |
<FONT color=#0000ff>return 0;
0 f! d1 k& E# `6 P' t}
: [, A& |& e* H</FONT></P>! [) w3 P) N9 U1 H; t
<P><FONT color=#ff0000>函数名: getpass </FONT>
' h& m6 U7 t# o- @. J功 能: 读一个口令
# D2 h" S* E1 W* h0 ^用 法: char *getpass(char *prompt);
: [' _5 R3 h3 f/ r; V: D程序例: </P>
1 s  M# e3 x& `$ @" e<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
5 S' S3 Q0 |* j. y: q9 N<P><FONT color=#0000ff>int main(void)
+ V8 m, @; m3 S9 H* W1 E: [' E{ ; N- w8 a, L+ {' i# e4 Z: v
char *password; </FONT></P>
% j1 J! ~, O8 Z( U0 k<P><FONT color=#0000ff>password = getpass("Input a password:");
% N6 ^) i! l. v/ x  ~8 ?5 s5 jcprintf("The password is: %s\r\n",
  ^- a0 `5 |  D6 i" cpassword); ) c- c: M" `4 ]: R0 b, J. {
return 0; # r& E" ~' k- i+ f
}   N, ?4 q& L: ~: C/ H; m
</FONT>
, q# ?: ~  u  \7 p% |& h' L5 `" a# `5 q! m0 e' ?/ Z4 |- [
</P>
6 t1 E  A& m6 p5 i1 m<P><FONT color=#ff0000>函数名: getpixel </FONT>3 I" F6 z) \% d  {, |& E% }  M
功 能: 取得指定像素的颜色
+ m) t+ S% i0 \/ N用 法: int far getpixel(int x, int y);
: d( q# B8 f2 l; A- r! s程序例: </P>$ v$ o, I' ?( @, J$ Y
<P><FONT color=#0000ff>#include <GRAPHICS.H>  Y, O& y6 V. ~. ?( u5 J
#include <STDLIB.H>: A1 z/ P* p5 s7 O+ A0 o: J& I
#include <STDIO.H>4 s: p6 A* P1 ^8 c+ |# o1 }
#include <CONIO.H>
. Q* b) O6 |3 ~+ M' C7 I#include <DOS.H></FONT></P>
5 x* J7 z$ D& j7 {  Z<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 / J& w: K& ~) H. }
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
8 Z, P: o) V  z2 d* J7 x1 L9 I- v<P><FONT color=#0000ff>int main(void)
* \1 ^8 ^( e7 u% Y{ ; R5 k  v& q$ H, G8 O$ f
/* request auto detection */ * Y. n7 R3 ~3 a
int gdriver = DETECT, gmode, errorcode;
  N- m- v) q9 c1 R# Wint i, x, y, color, maxx, maxy, / [% a" @, R( {1 R1 |; M
maxcolor, seed; </FONT></P>1 b& T% r4 w0 r6 ?; U" H' [  l
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 Z3 p' ^: u: h1 R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* }: E! G* B, N3 T<P><FONT color=#0000ff>/* read result of initialization */ ! D  v5 |# U" K" a% U+ T
errorcode = graphresult();
2 n+ x( |1 ^* {+ a/* an error occurred */ + d7 Q5 t  O# Y0 [; G
if (errorcode != grOk) . b$ x% V4 T# M1 ^
{
7 c+ |" a; ?( B8 qprintf("Graphics error: %s\n", , u# B1 \- T* O0 f
grapherrormsg(errorcode));
! Z+ v8 l# g) Z3 q4 Uprintf("Press any key to halt:");
% R6 b& {; _. K9 Y6 ]5 Igetch();
. c" O- t& k: i$ C, Z/* terminate with an error code */ 9 G4 h5 G- c) A7 H2 {8 l. v0 u
exit(1); . U2 h! W# G/ l5 K6 a& c- Z0 R
} </FONT></P>
4 h1 V. f, [; J9 E2 Z& \7 }" m- N<P><FONT color=#0000ff>maxx = getmaxx() + 1; 8 [7 a* d' {( ~9 T* n' Z
maxy = getmaxy() + 1;
% f* r& O0 w$ v; x; Tmaxcolor = getmaxcolor() + 1; </FONT></P>
& O1 ~! x9 {* k+ C/ b7 X<P><FONT color=#0000ff>while (!kbhit())
, M/ t* s6 v4 n  h( H+ \{
9 A9 b7 e9 D3 U5 ?& D/ N/* seed the random number generator */
' K: ^7 V) z' H7 b' N" d3 h) Aseed = random(32767); ; j3 Z/ h  l' R
srand(seed); 4 A3 u) f3 R8 s/ x
for (i=0; i<PIXEL_COUNT; <br i++)> { % l  M* k1 c4 r- E% c
x = random(maxx);
7 \/ |6 c5 x/ b! W- Ly = random(maxy);
* L) T& D; R) d6 e: ?5 Ucolor = random(maxcolor);
3 E7 E7 G+ ?1 @, \9 x& M4 |7 U" xputpixel(x, y, color);
, ^$ B+ p* d$ J( j/ k} </FONT></P>
: `; _0 @8 @3 C5 Y  Z* v<P><FONT color=#0000ff>delay(DELAY_TIME);
/ e# E7 j3 W! Rsrand(seed); ! @7 W& d' o/ D
for (i=0; i<PIXEL_COUNT; <br i++)> { , z. t5 n  J% r6 J3 N
x = random(maxx);
, B7 |5 W/ b" J8 b  k7 gy = random(maxy);
/ H$ A: X9 _, d' A+ F; [color = random(maxcolor); . F$ G4 t& Z2 @: d
if (color == getpixel)</FONT> </P>) r; \: D0 G9 N' r* ~5 _
<P><FONT color=#ff0000>函数名: gets</FONT> & M1 E" I9 D9 b/ ?, p9 d
功 能: 从流中取一字符串
6 B. }/ a* U: _8 \+ y+ u, l2 A" \用 法: char *gets(char *string); 3 p- C9 r' Q- s! p+ V* J
程序例: </P>* x! m/ r- v( Q6 I* }
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>8 \% U3 \* ]* H; h( @! V$ L
<P><FONT color=#0000ff>int main(void)
9 m" ^% z' h1 H' q+ V9 v3 M{
8 E% K$ ^* }2 m) E+ dchar string[80]; </FONT></P>
4 Y/ ]; e! J% _+ s, ]0 ^<P><FONT color=#0000ff>printf("Input a string:");
8 K' i) \+ O9 I# I- ^) m, F/ ]gets(string); 2 Y. _9 L7 b1 T7 z: P  F3 j  A
printf("The string input was: %s\n",
# d9 p6 @& b1 t4 v8 r: estring);
  z& u( q" y4 ~return 0; 7 \7 _8 k! ^& v6 m( g- ?
} ' T6 o* B4 O4 Z6 s0 Q  C

: n6 D4 \7 g; h# I9 E</FONT></P>
) q5 Z8 k# ~* x* k! z! J<P><FONT color=#ff0000>函数名: gettext </FONT>. L9 o" F. }: _
功 能: 将文本方式屏幕上的文本拷贝到存储区
& `" S/ U3 P; J. t5 T. L" w用 法: int gettext(int left, int top, int right, int bottom, void *destin);
1 x) Y6 D  k; [2 B" k程序例: </P>- a; s. Z, Y# q
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>9 W; e; v+ [" ?# f
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
* i" F) V( s2 p; M1 M, Y4 _<P><FONT color=#0000ff>int main(void) ( `. `" n4 B1 b% K5 I7 C0 S
{ 6 _) U, p0 f, f  d
int i;
8 Z$ d- x$ z+ m/ k( g9 t: }4 X7 vclrscr(); " L8 z: l& q" O4 r% }3 M" W
for (i = 0; i &lt;= 20; i++)
7 Z3 T. Y( i0 p: ~& lcprintf("Line #%d\r\n", i);
: O2 ~3 x  J. |3 k4 Sgettext(1, 1, 80, 25, buffer);
6 H8 y3 x3 [9 V8 b  ~gotoxy(1, 25);
! R8 Q. q$ R, L# }cprintf("Press any key to clear screen...");
+ C5 i" A2 T5 A2 tgetch();
) L8 D- {9 g& X4 l0 B8 Uclrscr();
/ }7 \" g6 w- P; |1 _gotoxy(1, 25);
3 z5 L1 D2 s8 m6 A0 zcprintf("Press any key to restore screen..."); + g6 }1 {6 }/ B. t% w# s/ ~. s
getch(); ( F* M, A  V. k
puttext(1, 1, 80, 25, buffer);
) ?1 z) J! D3 S9 ggotoxy(1, 25);
6 m" R9 `$ y/ W( B# a- U. Pcprintf("Press any key to quit..."); ' }9 H. l0 @+ k! ^6 j) K
getch(); ( d/ o0 |) f) ]* f6 A1 w
return 0;
! Z/ a$ i! V/ U/ p) |: C; y}
. c; p+ d, r; d, e</FONT>
, N( z+ `# w! I- A+ r</P># t' [' w7 @( o1 O! R; j, ~3 o
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> ) n$ C) S. y9 P. n, |# Q+ Q
功 能: 取得文本模式的显示信息
6 a4 N3 [5 l" e# p* M) K) Q用 法: void gettextinfo(struct text_info *inforec);
' f" Y; p- I9 y程序例: </P>
; C7 o  @. b+ N9 `7 ]<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
# h3 J: ~5 E6 U7 I<P><FONT color=#0000ff>int main(void)
% W5 I& r0 i7 M+ W' z{
* x. {' I& ~) astruct text_info ti;
3 o; ]2 l$ z8 C/ fgettextinfo(&amp;ti);
2 f: O( P/ x& t6 F% \6 wcprintf("window left %2d\r\n",ti.winleft); ) U/ |4 [+ w' c- |
cprintf("window top %2d\r\n",ti.wintop);
, O# ~$ Q* E' L8 l6 Pcprintf("window right %2d\r\n",ti.winright); 4 w" a7 @6 ]! E, J. C
cprintf("window bottom %2d\r\n",ti.winbottom); 4 F5 R* G" p7 V1 o5 ~3 r
cprintf("attribute %2d\r\n",ti.attribute); + \; V5 I: k9 r. u; @# a4 r6 N
cprintf("normal attribute %2d\r\n",ti.normattr); 6 d& s( W6 a- L% v; n( q
cprintf("current mode %2d\r\n",ti.currmode); 9 e& M: t+ X; Q5 r% U
cprintf("screen height %2d\r\n",ti.screenheight);
& A/ X" V! K* x2 `; }! b$ ncprintf("screen width %2d\r\n",ti.screenwidth);
& y# X- D$ H/ G. N  P' ^2 u, ]cprintf("current x %2d\r\n",ti.curx); " L5 k" _0 V) U+ }; n) @
cprintf("current y %2d\r\n",ti.cury); ! B1 v1 B; R) ?" \1 j# C. p
return 0; ) v: w4 D; D* K4 w
}
, [8 s, K5 C2 S0 q' z% M8 A</FONT>8 E5 t% d; u: }+ e( W2 i1 b; u
</P>: p2 k1 i; ?- f9 Q
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
4 }3 e# B& I$ M+ x! x功 能: 返回有关当前图形文本字体的信息 ( }6 c4 O- P0 O* K1 P3 g- A
用 法: void far gettextsettings(struct textsettingstype far *textinfo); / ^* s0 N/ |3 W, M1 K4 y
程序例: </P>
; ~, L) n0 L0 m4 \0 r<P>#include <GRAPHICS.H><FONT color=#0000ff>
  y9 ~: T. _' K0 Y! |( ?( k& Y#include <STDLIB.H>
3 O5 U- @& ^* R2 [( S#include <STDIO.H>1 h& @# [' K# [6 z
#include <CONIO.H></FONT></P>7 J0 b" w+ W7 ~% a0 k: p7 {, p
<P><FONT color=#0000ff>/* the names of the fonts supported */ 1 q# s: \, E, N5 P. y) q& G; U6 |
char *font[] = { "DEFAULT_FONT", # h; Z' J( W& j; O. P& l1 i
"TRIPLEX_FONT", 4 y8 H) B" R! `' c  H
"SMALL_FONT",
0 ?4 @# u8 o% T; b% b' f% {"SANS_SERIF_FONT",
! D+ T- ]1 t+ U! [4 x! n' I"GOTHIC_FONT"
) z  t, |3 Q9 b; a- Q6 R6 x}; </FONT></P>
, z0 y2 I) x+ [' W<P><FONT color=#0000ff>/* the names of the text directions supported */
- w! }! D: Z$ Z' Fchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
4 a. B! h$ W. x% Y% b<P><FONT color=#0000ff>/* horizontal text justifications supported */ + n0 ?1 R! e+ L8 S, x
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
% N' j+ E4 `% X<P><FONT color=#0000ff>/* vertical text justifications supported */
5 U; m7 y% z( u; schar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>% A- m' c/ g. T, R
<P><FONT color=#0000ff>int main(void) ; c: ^) L& P/ K, s1 D
{ * Y0 K4 Z) _4 c: R* T. W
/* request auto detection */
* H' C: o% k& [0 F8 k5 gint gdriver = DETECT, gmode, errorcode; 2 Z; Z) b" v5 m! n# O
struct textsettingstype textinfo; ) u: L9 P, \+ q. m
int midx, midy, ht; 7 @- d* ^2 V8 A
char fontstr[80], dirstr[80], sizestr[80]; - @* G$ c) |# b( x# W
char hjuststr[80], vjuststr[80]; </FONT></P>
3 B; S1 }8 L5 Z* Q<P><FONT color=#0000ff>/* initialize graphics and local variables */
  h! S! W0 q4 Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 g( C" v' J3 _+ Y
<P><FONT color=#0000ff>/* read result of initialization */
$ }# r+ {$ T5 b$ ~3 n, Terrorcode = graphresult(); 1 p; J  D) {9 O4 K) ~$ e$ w
if (errorcode != grOk) /* an error occurred */ 5 ?$ k! v, F$ `0 W7 r1 p
{
: c2 D+ n% q4 l7 f) vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 E1 H/ n9 Q5 ^$ Mprintf("Press any key to halt:");
; ]& k1 Q6 L8 H# C1 {getch();
. j% m% t, C0 r2 L6 Y/ u7 ~/ jexit(1); /* terminate with an error code */ ; W( Y, F# N8 A& h& g
} </FONT></P>
3 Z, M- C* t" f( `" n1 ^! n+ b<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 P% |( o6 m- ~2 n
midy = getmaxy() / 2; </FONT></P>5 M1 z& Z# _, Q+ L0 M/ h0 u
<P><FONT color=#0000ff>/* get information about current text settings */
! o% F4 v. C+ m( L8 W! ^gettextsettings(&amp;textinfo); </FONT></P>; @3 y7 n. e  o; x
<P><FONT color=#0000ff>/* convert text information into strings */ % l! E  ~) f8 O5 O* [5 E+ F
sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
4 ?1 M, \5 k! Q! F5 @0 g  n) _sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
; ]& h& ]+ C; ~sprintf(sizestr, "%d is the text size.", textinfo.charsize); ' t5 x8 p7 _; `# J9 x) G1 z  M
sprintf(hjuststr, "%s is the horizontal justification.", 6 y) T6 z  Q9 B, U, t" L
hjust[textinfo.horiz]);
8 ?: R7 h5 W5 @" a/ usprintf(vjuststr, "%s is the vertical justification.", - i+ k$ Y. y+ z$ F2 f0 F1 o3 J
vjust[textinfo.vert]); </FONT></P>
# F' W# a" m8 r2 \' M<P><FONT color=#0000ff>/* display the information */
# m/ j8 p! G% {% V& L2 Xht = textheight("W"); 4 ~1 R& y, o* S4 K+ u
settextjustify(CENTER_TEXT, CENTER_TEXT);
/ s, k9 \2 @# ]5 q  F% m0 s/ Touttextxy(midx, midy, fontstr); . l6 E; [  Y+ ]8 s$ k6 m
outtextxy(midx, midy+2*ht, dirstr); 1 p; h) ]+ p6 V/ [/ h2 Q6 B
outtextxy(midx, midy+4*ht, sizestr); / e3 Z: `6 B* F, o! y& L- t
outtextxy(midx, midy+6*ht, hjuststr);
0 O. p8 v0 h" G* q9 `( Nouttextxy(midx, midy+8*ht, vjuststr); </FONT></P>- a8 _; b$ l3 s% l) {. T
<P><FONT color=#0000ff>/* clean up */ ! Y4 @. b2 `7 g
getch();
  |; P" n- v$ t3 T0 B9 \closegraph();
/ k7 @/ Z% [2 M  j- Vreturn 0; 4 o9 @  H* I, j5 c6 _
} </FONT>: R4 j4 e$ T6 H' I3 Y' ]& o9 b8 W2 P
</P>; N2 t9 C1 a0 P6 \; p9 E
<P><FONT color=#ff0000>函数名: gettime </FONT>
8 m( ?0 V" g( S! L% j4 Y" z功 能: 取得系统时间
0 r; f6 w" i6 ]用 法: void gettime(struct time *timep); - T% Z$ L, c" i
程序例: </P>
/ l: e" t) ]5 A: y<P><FONT color=#0000ff>#include <STDIO.H>
" s' Z1 _, F! }! m$ f% g6 K0 ^#include <DOS.H></FONT></P># M9 ?: m6 B0 b# R. y; X6 z
<P><FONT color=#0000ff>int main(void)
3 E6 H% f6 I7 d7 b5 b# ~' _{
  R9 {( ]$ V$ ~7 O* nstruct time t; </FONT></P>
! r) b( p- r" Q' c9 Z+ `1 M<P><FONT color=#0000ff>gettime(&amp;t);
% k8 o* ~. |, b) J0 V% e9 mprintf("The current time is: %2d:%02d:%02d.%02d\n",
  c1 Q7 c/ K0 L2 [! G# Ot.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
7 `5 G; Y* Z5 |" b, t$ A* Treturn 0;
" x' f5 ]) p- \* j1 K' z}
* j4 T1 r; B# t- E$ X8 D
+ Z  `/ S" e7 c4 z+ v/ n8 s  n</FONT>8 D8 w3 l" d" f" A; p* b! F& b$ y; m
</P>
( l- j5 _0 b; W<P><FONT color=#ff0000>函数名: getvect </FONT>$ Y$ s6 I! z9 e; _! ^# O* j0 o
功 能: 取得中断向量入口 0 C5 C1 D6 f% J' m* [% q
用 法: void interrupt(*getvect(int intr_num));
- C9 l9 T2 r; @  V5 W+ Q$ f程序例: </P>
4 l! k  ?7 O% j  M+ c  H. M<P><FONT color=#0000ff>#include <STDIO.H>
) M( h4 L- ~; j; N* k& d7 a( h#include <DOS.H></FONT></P># U. m1 G$ r9 f. h
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
+ d/ b8 I2 |, G1 t' l2 m! Y/ h<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */   \/ `; z  t' ~) d$ q- t2 o8 a$ B
int looping = 1; </FONT></P>: [, ]4 f/ f) `/ N, L( M, n
<P><FONT color=#0000ff>int main(void)
6 l( m- ^" M: {; ^; {$ ^/ J{
3 j5 B% I+ \3 \# c" _8 q! Kputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
4 J' ?, z/ o) a9 D# j<P><FONT color=#0000ff>/* save the old interrupt */
# c. P! a2 z: b4 \+ Coldfunc = getvect(5); </FONT></P>1 H0 H) s3 R$ c0 d
<P><FONT color=#0000ff>/* install interrupt handler */
6 W& k! D7 j  e% r3 r. M+ Ksetvect(5,get_out); </FONT></P>0 i! z5 S+ R9 \) T1 }6 w" W
<P><FONT color=#0000ff>/* do nothing */
) x# Z* M8 E' l/ V- S: x  Nwhile (looping); </FONT></P>8 k) k- ^9 D6 u# h+ b5 D# u% M
<P><FONT color=#0000ff>/* restore to original interrupt routine */ ; P' Q" r! _- o
setvect(5,oldfunc); </FONT></P>
" b9 E3 v: j% G% S/ m( j9 Q<P><FONT color=#0000ff>puts("Success");
) O% p3 ?1 V" X; h' O6 preturn 0;
; ]. A. E1 K7 [; [3 H} 0 r+ _. j1 B2 O( X& g, L
void interrupt get_out()
# Y: a) I" |( i{ 7 Y' o( d9 l0 t" t
looping = 0; /* change global variable to get out of loop */
, s' ?$ r: m- Q}
' z' n- P/ g0 t3 T8 N) \" N% `3 y</FONT>$ u9 F2 L4 s9 O9 E- j% X
</P>! i3 a. l( m: e1 d  e7 b" Y
<P><FONT color=#ff0000>函数名: getverify </FONT>9 i7 P% w; @* {
功 能: 返回DOS校验标志状态
2 ]$ H! A* v+ X8 U4 e1 P% a用 法: int getverify(void);
- T* l6 M- b& j0 a! f" \* ^程序例: </P>- E9 |& O3 X  `7 Z; u0 }( W
<P><FONT color=#0000ff>#include <STDIO.H>
/ t/ V, z0 ?  `' r5 G#include <DOS.H></FONT></P>
. \4 x! N! S1 v% g( K7 r<P><FONT color=#0000ff>int main(void) " K+ G9 Y" [! i; B' U( l& X3 i
{ : W! x4 a8 c$ C6 P2 `
if (getverify()) 6 p7 q( _+ q) C1 E
printf("DOS verify flag is on\n"); ) [/ }, \4 K7 `# }- u
else % R9 n" ^  b; a2 h
printf("DOS verify flag is off\n");
' H/ o0 J$ ]1 X" x6 D6 }* ~9 X% Preturn 0;
# c- E2 ]* R( m4 Q3 T" _  W7 D5 p3 z} ; [6 e: M! ]8 v7 H; H( u. @1 ~
</FONT></P>. s) o- V4 Q6 {% i+ a3 j, Q* v% w
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
) ^* r4 I" `/ B功 能: 返回有关当前视区的信息
& ~6 c' Q: t8 z* T& A8 D% ~5 H用 法: void far getviewsettings(struct viewporttype far *viewport); 0 {: Q1 b6 V3 v# t1 s9 b
程序例: </P>
9 P: U5 b, ]* D, u/ i8 U; T<P><FONT color=#0000ff>#include <GRAPHICS.H>
) N( U$ \7 V. ?7 ~. b#include <STDLIB.H>
* W8 X" {! Q/ R6 O#include <STDIO.H>$ P/ v: R1 z8 |0 X; K* B, o
#include <CONIO.H></FONT></P>3 q9 S" ?. x* \3 b$ c! @, |
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
: _3 ?( H/ N! Y: d* M1 w<P><FONT color=#0000ff>int main(void) / I$ C+ K/ g* u* D, i
{ & [2 u7 E4 m3 m2 i5 H' L
/* request auto detection */ 3 H8 e: t- c6 f/ O) F: D- j
int gdriver = DETECT, gmode, errorcode;
7 a0 ?& K! f5 R) B( Y* L6 R- Nstruct viewporttype viewinfo; , w+ u% ^7 |. w5 s
int midx, midy, ht;
2 a9 M& o! Y! V' |; L+ echar topstr[80], botstr[80], clipstr[80]; </FONT></P>  L! v4 W1 q, s$ C# N
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; m% A/ P! s3 u$ g# J" ]( `% ]% z3 @# d
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 M% f+ W) x9 p/ ^8 \) T8 i
<P><FONT color=#0000ff>/* read result of initialization */
' U; ?( j* O) m0 ~* i; M1 rerrorcode = graphresult();   s4 ]2 r8 B" w5 b' ]' @
if (errorcode != grOk) /* an error occurred */
% D. l1 v# e8 ]) L) K5 l9 J. r{ ; z- X8 u; _5 W. H
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 c+ |$ j7 y9 r+ A- g" Z0 T2 uprintf("Press any key to halt:");
! n; c. B1 I; |" W" |getch(); 3 u& a$ I* D0 I% @! U4 F
exit(1); /* terminate with an error code */ ' [/ R3 [7 {4 ~+ u7 d; i
} </FONT></P>3 e8 [# t& x( I1 H; M# j8 c
<P><FONT color=#0000ff>midx = getmaxx() / 2;
# ^3 F! g: ]4 x7 c2 [4 Q& @: M& Kmidy = getmaxy() / 2; </FONT></P>% N3 C, I8 {2 ]( w- Z$ p9 M
<P><FONT color=#0000ff>/* get information about current viewport */ # t! B0 L: v4 F( J4 ^
getviewsettings(&amp;viewinfo); </FONT></P>
' s; ?7 O8 Q2 I7 u# k<P><FONT color=#0000ff>/* convert text information into strings */
, f% b5 s8 m0 p6 vsprintf(topstr, "(%d, %d) is the upper left viewport corner.",
; a2 I+ ], E' U; qviewinfo.left, viewinfo.top); $ D3 n- j" _) Y; ^5 ?3 k: Q
sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
; g" Z0 f1 {6 _( z  @# g  i) zviewinfo.right, viewinfo.bottom);   C3 S& {% L2 ^) }" x: T
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
! i, ]$ Y$ ~3 Z9 I+ U$ ]5 i; q+ m<P><FONT color=#0000ff>/* display the information */ 4 t7 K0 J) u; n  W7 T# j
settextjustify(CENTER_TEXT, CENTER_TEXT); 6 l. x! Y/ R6 h& _8 H
ht = textheight("W"); 1 d/ w7 P8 ]! c% [+ A
outtextxy(midx, midy, topstr); 3 `; r9 ]- ^3 }0 i( y0 N* U% f9 q
outtextxy(midx, midy+2*ht, botstr); 7 T; O2 }, a. C  ~/ w$ ^- r8 K
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>$ i6 ]3 h: `& V7 p1 f7 M0 ?7 }
<P><FONT color=#0000ff>/* clean up */
# g- E. N4 u1 E, `3 [0 v, p& `getch(); , C! F! F- d) D" X
closegraph();
7 \3 H, f7 k+ U6 ~( |6 C$ areturn 0; ' T* t6 r1 \2 b. W4 \6 S
} </FONT>% Z/ y, U" z5 @; j) Q* K

$ V' Q6 l) w% f  U</P>+ s0 `! B3 B, k& T& q
<P><FONT color=#ff0000>函数名: getw </FONT>
3 g! R! q$ \' ]& T" f功 能: 从流中取一整数
  d; m- p% \, r用 法: int getw(FILE *strem); 3 C6 X9 P" S' b0 m' M( x/ Q+ Y
程序例: </P># V) D& I; C# V: B* A4 _7 C; K
<P><FONT color=#0000ff>#include <STDIO.H>$ ]2 L3 ~* ~$ O' R
#include <STDLIB.H></FONT></P>1 P0 H8 K' Q3 ^! p; y
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>2 B1 h! ^0 w* R) k/ i2 i
<P><FONT color=#0000ff>int main(void)
( w0 ?4 Q8 m  a0 ^{
6 `3 t. [6 S5 K3 f+ g" _0 i- bFILE *fp;
! u) g; e5 v; mint word; </FONT></P>" q8 d( E# g/ q+ n
<P><FONT color=#0000ff>/* place the word in a file */ 7 Q$ {8 c4 F( o$ {1 [5 B2 F
fp = fopen(FNAME, "wb");
) C( d8 [! d* I& y4 R; {9 m  [if (fp == NULL)
) ~, T& y- o7 [3 H& [3 F{
  n! ]" x8 J( ~) Oprintf("Error opening file %s\n", FNAME); , k8 T! b8 W; R7 X, p
exit(1);
3 T' A; `  v! i( C# o} </FONT></P>" f3 z  K- ]6 y9 u' a
<P><FONT color=#0000ff>word = 94;
- k7 f. H# s2 Y: @) @9 x+ X! }putw(word,fp); . F- H( i5 t; n$ {
if (ferror(fp))
, k+ Z- [" _. s0 `printf("Error writing to file\n"); ' W2 n. y# F6 o1 U/ s; a
else
" C; M4 v, q& G" q0 {/ c. Cprintf("Successful write\n"); 3 k9 i; ~: H5 {0 \5 O3 {: u' g
fclose(fp); </FONT></P>4 X8 p( i" @3 M" _
<P><FONT color=#0000ff>/* reopen the file */ 7 {" O* Q9 [! o# Q7 |
fp = fopen(FNAME, "rb"); ' h9 `2 T5 c* T; d* `! F) z# w
if (fp == NULL)
3 U  f) v& s" I3 M{
6 @* G2 `" z, R4 f! M7 Eprintf("Error opening file %s\n", FNAME);
5 k8 m/ h( q7 o! _8 G4 B9 N2 pexit(1);
, c5 C) Z% f% g: \2 O3 x3 {} </FONT></P>
. O8 |) X/ i6 q+ e6 F0 I<P><FONT color=#0000ff>/* extract the word */ * d* G+ p, ]# V9 D4 W2 D% ^
word = getw(fp); $ F/ K1 h/ Y* Q! H8 Q4 Y  k* B& ?; y
if (ferror(fp))
7 J0 H, f# [$ T# j+ ?6 hprintf("Error reading file\n");
+ N, N3 ^* ^7 X1 x8 Jelse
: i7 A- x1 ^) Uprintf("Successful read: word = %d\n", word); </FONT></P>
/ k4 @7 z/ p: F* ~# S! R+ z4 m<P><FONT color=#0000ff>/* clean up */
8 q, U# p+ ~+ |7 kfclose(fp);
' A3 L; ^: B9 y+ X0 v( ~unlink(FNAME); </FONT></P>+ @9 n% }# C5 b7 Y
<P><FONT color=#0000ff>return 0; ! Z. v0 q. l% X$ S" v! k
} </FONT>
1 P/ |  U' [! c& G* F6 ^, W  h" P$ t

% K5 L) P, ^7 h</P>
( [  U' L) `. d* |" D<P><FONT color=#ff0000>函数名: getx </FONT>9 }. s  Z  n! D, T/ C$ ?
功 能: 返回当前图形位置的x坐标
" {- E7 [8 ^4 ^7 N! b用 法: int far getx(void);
- U5 N7 N3 t* K  m$ g+ M3 w# S程序例: </P>4 P" H; X* Q. ~, N/ T" N
<P>#include <GRAPHICS.H><FONT color=#0000ff>
( O3 f3 r5 N6 w' G! ~#include <STDLIB.H>
1 i' @& s; f. L- b#include <STDIO.H>
: F1 }' @& A- N, t6 h, H6 C/ m#include <CONIO.H></FONT></P>
/ ^7 F, v! O2 P<P><FONT color=#0000ff>int main(void)
7 ?9 _) b  j- Z9 L" F3 E{
* w6 q4 ~: a; \! e" r/ M- e/* request auto detection */
/ Y% g8 P9 |# T9 Q! X3 E+ r* hint gdriver = DETECT, gmode, errorcode; $ d* P3 a: ^; E2 F- n) d; k. V
char msg[80]; </FONT></P>$ h9 a5 D$ e7 f# H
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, M* E: \% e$ M1 q- ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ y0 h9 {9 X6 w# r; D  v
<P><FONT color=#0000ff>/* read result of initialization */
2 I+ x# @1 O& v! V# B& W. T0 ierrorcode = graphresult(); 8 U: r. z: A. v/ r/ B, z
if (errorcode != grOk) /* an error occurred */
3 h6 Z4 L$ R6 N$ V0 G; c{ : r8 R- h6 A# {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 y0 Q7 s9 \! _printf("Press any key to halt:"); 9 Y6 p- h9 G3 i: n+ R6 t1 i
getch();
# o! j) B; r, L& w% Y" K' w3 Nexit(1); /* terminate with an error code */ - i% m5 z1 I) H$ Z1 i2 N% }
} </FONT></P>, }( b% K' _6 p4 n! c- W$ A9 f
<P><FONT color=#0000ff>/* move to the screen center point */
2 e2 d  I6 h' _& v: amoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
" z' H& W4 H1 [8 J<P><FONT color=#0000ff>/* create a message string */ 9 ], v7 J5 Q8 X0 F9 |, N( T
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>7 T; d) ^. u3 g" v6 \- n. m/ E) C
<P><FONT color=#0000ff>/* display the message */
: g- b0 C3 {$ L# v% U( E' `outtext(msg); </FONT></P>+ A4 n5 O2 x1 m) Z0 u: s$ h$ }$ u4 w5 X* C
<P><FONT color=#0000ff>/* clean up */   ^2 }$ @* f. n! s; [# y6 v
getch();
5 h0 Y8 R3 w! v. P) D% Fclosegraph(); ) n2 W' \* ^3 B2 T) ~
return 0; $ K5 H% {  H5 Y
} </FONT>9 T$ [+ v; k5 [- u- J# ^2 Y
' U1 `0 g9 ?, B" i8 c  y8 }+ J1 |
</P>" Q% A) d, x/ `
<P><FONT color=#ff0000>函数名: gety </FONT>
; ]+ Q6 u4 y; o6 H功 能: 返回当前图形位置的y坐标 . F# i4 f$ f! V
用 法: int far gety(void);
7 x) T9 M$ a& b* E4 _. U, I6 t# f程序例: </P>/ D, L. K/ v* R& _4 v& _+ E
<P><FONT color=#0000ff>#include <GRAPHICS.H>- H' [0 l; ^! v8 Y3 h+ k( B$ |; d
#include <STDLIB.H>
4 I5 s, \3 @$ E. y: s0 {#include <STDIO.H>
$ s1 O& n$ c2 _( X& w: [. y#include <CONIO.H></FONT></P>
) h4 F- Y8 o, D) @* ^5 @<P><FONT color=#0000ff>int main(void)
" H. `8 N8 D+ Z{ 4 |& }6 z/ j  z3 V9 @
/* request auto detection */ : a3 H- S9 U5 |( O7 h: f1 J/ P
int gdriver = DETECT, gmode, errorcode;
; r! i' f: g6 tchar msg[80]; </FONT></P>
+ ], y+ T7 S; G9 \0 |* C<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 D& U$ F2 p; v7 [1 w  K3 V! xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- [) z  k1 Z, C* F
<P><FONT color=#0000ff>/* read result of initialization */
% p; W2 u1 G. c0 L" Cerrorcode = graphresult();
: [( E0 W$ x, N  D" G( e. gif (errorcode != grOk) /* an error occurred */ / F7 L% m7 m- X$ ^+ d* N- r
{ & ^- R3 A: Y0 {4 W# b8 r- d
printf("Graphics error: %s\n", grapherrormsg(errorcode));
' D! }) U) _1 N0 I1 Aprintf("Press any key to halt:");
; v$ [  ~4 ~( C: S8 \getch(); , Y* G" s& A+ N/ J- e: _% T. b
exit(1); /* terminate with an error code */
% X7 m( f6 E7 T7 J} </FONT></P>7 v3 X0 [5 o% C+ M) `: E7 i; @
<P><FONT color=#0000ff>/* move to the screen center point */ # q( [, |9 w" u- }7 g+ B7 r
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P># m3 g& {( j# K' L, Z$ C. o) |
<P><FONT color=#0000ff>/* create a message string */
5 L! y$ }: ?/ n1 j. `4 ?sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>% N! t; |* f2 Y" M4 ]
<P><FONT color=#0000ff>/* display the message */ : i% C/ o1 q. s8 ^
outtext(msg); </FONT></P>( ^2 G3 E$ A0 \2 B5 `! U- T
<P><FONT color=#0000ff>/* clean up */
6 j/ X3 z! H; @! N9 Tgetch(); . ]  S% h% o: ^- D
closegraph();
2 p! D6 i6 K+ s8 I* w$ vreturn 0; % g9 @9 E% Z& M# u/ ^
} </FONT>
& F9 N  g/ f" I
0 M1 p! z1 R  R9 ?* A. P</P>
& C. o! I$ j- p  G( E<P><FONT color=#ff0000>函数名: gmtime </FONT>2 H7 g/ J% f# R" r
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
6 J* k/ N. T' h  k* s1 _8 q0 ]用 法: struct tm *gmtime(long *clock); $ p0 l6 B, i! l) `) E+ i( N
程序例: </P>
9 N& H8 ?8 Q; B5 }+ X<P>#include <STDIO.H><FONT color=#0000ff>
5 g5 ?/ O0 {9 n#include <STDLIB.H>. n! E/ \6 B) |/ o  L+ \
#include <TIME.H>
/ s5 Q* I) U2 d& s1 H#include <DOS.H></FONT></P># A( K- `7 g' o0 S( H
<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
" R; Q9 E" C. ~! k/ M5 m! ]* Q. ]3 zchar *tzstr = "TZ=PST8PDT"; </FONT></P>
& x! [' E' C- d& U! b<P><FONT color=#0000ff>int main(void)
. r/ |4 F7 h9 _( w* p5 ?- `6 n{ 0 e. b  T. a9 M! P
time_t t;
4 Z* j% b, `, Q7 Y6 Estruct tm *gmt, *area; </FONT></P>3 q% |: u5 J8 F1 r2 j1 q
<P><FONT color=#0000ff>putenv(tzstr); ( w- i3 Z- p. O7 M6 m
tzset(); </FONT></P>, p) K2 K3 X% g; Y2 o' z
<P><FONT color=#0000ff>t = time(NULL); 6 E$ {5 m9 a4 E& t
area = localtime(&amp;t);
6 T9 T; d  w6 g4 e, ~2 y+ j, dprintf("Local time is: %s", asctime(area)); * _) H: l1 R- v; l- X0 ?3 s
gmt = gmtime(&amp;t);
8 p% ^9 l! e6 g5 ~5 rprintf("GMT is: %s", asctime(gmt));
3 ?1 p% d% V) T: A+ _return 0;
- W  g# ~% s& V( ?} </FONT>  x. x$ ^# t! y# L# D# \
9 e  M& Z, H$ W
</P>
6 d" C* z2 ]5 Z8 P9 `<P><FONT color=#ff0000>函数名: gotoxy </FONT>
5 P+ E1 w( M9 P9 |# e; ^7 j功 能: 在文本窗口中设置光标
; ^9 u, b7 n4 v% w3 Q8 X8 h用 法: void gotoxy(int x, int y); , O* h" \: i) U/ v: I% J0 g
程序例: </P>4 [+ P. e8 F. h& m, m% \7 C
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
! _0 I+ a! ]) s* K- Q5 J<P><FONT color=#0000ff>int main(void)
3 m1 D" p: l0 e( I; D# E{ " c4 r8 c8 d, @* a& W
clrscr(); ( Y- d$ D% f; u3 b3 C
gotoxy(35, 12); , w/ u& U- y" y0 A' t
cprintf("Hello world");
3 W+ N8 N  S' y( h, x+ p$ }getch(); ( h7 B4 `3 ~6 S" O
return 0; * m% M) z% T; g8 L5 m1 o$ U
}</FONT>
1 ]+ a- a( p- g$ P+ H: w( r' U+ S
</P>4 u( t" L: Y' n: Z& ~( w
<P><FONT color=#ff0000>函数名: gotoxy </FONT>" I1 \6 o7 [& k2 M# P" f' F
功 能: 在文本窗口中设置光标 ' f" S/ r# g9 G4 h; R* q; m
用 法: void gotoxy(int x, int y); 6 O3 B: _. T8 g$ c. E! o! E, J
程序例: </P>7 j+ u! D+ f; H
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
) r$ Y: O7 u4 V' ]# p* [/ \8 M* N% Z<P><FONT color=#0000ff>int main(void) 1 Q, |% p# X+ J8 y3 N+ S
{ 3 d' I+ F* g% C/ b, Y3 A% w  Z
clrscr();
$ m% L7 V/ }- T( vgotoxy(35, 12); ; W9 c7 p  v& v. n: X/ k
cprintf("Hello world"); : f, H+ c/ v9 S/ m5 P, Z) E
getch(); + R6 L: y! H0 C+ j: K
return 0;
8 V  o% p3 Q: D0 ?: ~}
6 L, q" \% R0 S8 Q4 _</FONT>
1 @, E/ f) g- w</P>/ i% `# u# C; Y" _' M& k2 d
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>8 N- r; ~* I% \1 g+ H) G. I; N2 n
功 能: 将所有图形设置复位为它们的缺省值 & j* ~1 P+ n7 d7 Q* A- A
用 法: void far graphdefaults(void);
2 b- d$ z8 p# [$ b7 Z3 w程序例: </P>
, q! a# ]' R5 G# w5 U$ u6 |<P><FONT color=#0000ff>#include <GRAPHICS.H>8 J) j' L, c# Q+ A- W
#include <STDLIB.H>6 W7 s: q1 S- l4 J# k
#include <STDIO.H>% W* G& }' R* n3 C3 Z5 b7 k
#include <CONIO.H></FONT></P>( e2 H2 ]0 t' T2 j
<P><FONT color=#0000ff>int main(void) $ A) h; N7 Q+ `; ?: \
{
2 V( S0 I( y3 M; E9 @; b9 ~  K1 q/* request auto detection */
3 Q- l8 x5 v& g4 o+ Pint gdriver = DETECT, gmode, errorcode; " v2 L0 X2 N. @( @) |5 f6 b
int maxx, maxy; </FONT></P>: L  {  p- J) l4 f& m9 d
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% v6 J" O6 O0 E8 Y( Dinitgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
8 R& ?8 @3 h# Q2 j, I1 I% r: u' [<P><FONT color=#0000ff>/* read result of initialization */ 7 `/ K- |! L( ?5 Q
errorcode = graphresult(); 6 ]) {( N2 z3 C3 E
if (errorcode != grOk) /* an error occurred */ # t; y: v4 ?  w$ M, Q5 F% T$ X
{
8 a0 T1 @3 q: n) y8 H+ F- xprintf("Graphics error: %s\n", grapherrormsg(errorcode));
  X' ^$ ]0 V- q4 j. G6 i+ x* w" N2 cprintf("Press any key to halt:");
# q/ U" ^4 u) Jgetch(); & w% w$ |* n4 J% a" X0 {
exit(1); /* terminate with an error code */
0 R" b2 l6 E; I( ]} </FONT></P>
+ @4 F4 A# T1 h! Z0 Z+ s4 Y5 E<P><FONT color=#0000ff>maxx = getmaxx();
5 M* N" V1 x* lmaxy = getmaxy(); </FONT></P>9 C0 |: d" l$ m. s3 k: ]
<P><FONT color=#0000ff>/* output line with non-default settings */ % a- S3 H9 k" c8 T$ I: o
setlinestyle(DOTTED_LINE, 0, 3);
( [: F/ s0 N! ?3 s( ]line(0, 0, maxx, maxy);
1 S# l) P3 f7 {0 Kouttextxy(maxx/2, maxy/3, "Before default values are restored.");
) R) E* \* H1 S9 {+ ~- H! _& Igetch(); </FONT></P>9 {+ n2 S, o/ j: L* @0 m0 b' F
<P><FONT color=#0000ff>/* restore default values for everything */ ' g* U$ i" E2 B
graphdefaults(); </FONT></P>  N- T5 ^- O6 s9 t! h) b) b
<P><FONT color=#0000ff>/* clear the screen */
: l" @4 S1 d- Y% K3 T( Ncleardevice(); </FONT></P>
, K- c7 j2 ^6 R) W5 F* H3 p1 y<P><FONT color=#0000ff>/* output line with default settings */ " Q7 U* C. u% [* H8 {' M( @! A+ W- P
line(0, 0, maxx, maxy); 0 \' b. i" g2 J0 S: w4 s
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
5 G3 H6 R/ F# w' h+ |8 r  p$ R5 A9 ?<P><FONT color=#0000ff>/* clean up */
8 t0 n( }! \; I+ n" d/ Mgetch();
! I  r/ h+ E8 T1 Vclosegraph();
2 {/ _+ e# l6 N/ _$ l2 z7 C, ~return 0;
4 r$ J# g$ l2 [; n; X/ k} ' x- C7 j+ K7 s2 q
</FONT>- j2 R$ Z0 J% Z9 T* Y1 t
</P>
) I; i: V, `* L$ U) d<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>+ l6 }. f! X* K5 G$ F+ I* r. |
功 能: 返回一个错误信息串的指针 $ [+ J8 F/ b# A, W. R  n
用 法: char *far grapherrormsg(int errorcode);
$ V8 T1 w( m  [+ m) P程序例: </P>
- u2 ~( K) w+ e2 L0 r# S<P><FONT color=#0000ff>#include <GRAPHICS.H>
* w8 H3 |3 m! ~3 H3 v2 Q#include <STDLIB.H>* w/ g1 d2 c. u, o
#include <STDIO.H>
6 B* u8 ]% n7 V7 B. s# S5 k#include <CONIO.H></FONT></P>& v4 j. q$ [& ^/ F
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>3 T* j# r! V% p3 G: K- W+ o
<P><FONT color=#0000ff>int main(void) ( u8 J" G/ \7 C" ~# d& Y
{
3 O4 B* u/ ~+ m* T/* FORCE AN ERROR TO OCCUR */
4 Q' ?( t# Q" C/ Z7 g5 u/ X4 kint gdriver = NONSENSE, gmode, errorcode; </FONT></P>
: B5 d6 a7 }% @, e( l& _<P><FONT color=#0000ff>/* initialize graphics mode */
! w: t5 _: ^$ b# O# B1 U" z" c: hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
. ]* V# W1 E0 g$ i3 ]  }<P><FONT color=#0000ff>/* read result of initialization */
. Q/ P2 ?! E3 `errorcode = graphresult(); </FONT></P>
+ Y, B. C, N2 Q  T  q: u<P><FONT color=#0000ff>/* if an error occurred, then output a */ ( i" f. M7 @0 A) Z% n
/* descriptive error message. */
; R  {/ O! A$ P- I3 H0 `. ?: Hif (errorcode != grOk)
& l0 v2 _3 s& k* `; Z3 ]" I{ 7 V6 K( W9 ]& P( F+ k+ _0 p) B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( @- K% D  n, g" z; Q" gprintf("Press any key to halt:");
6 }) `  e6 g* |$ X. c0 h1 [) Kgetch(); 8 K, W9 m9 Z. i& h/ x" s* I
exit(1); /* terminate with an error code */ $ N0 b8 q' l3 }% T+ n. j
} </FONT></P>7 d; z1 S7 Q) n/ h2 R" W
<P><FONT color=#0000ff>/* draw a line */
+ I  o3 x& {& s: O) J: ?/ {line(0, 0, getmaxx(), getmaxy()); </FONT></P>
$ P% P" R6 \5 A. U/ y- s; c, V<P><FONT color=#0000ff>/* clean up */ ) N6 s+ h- S! A* W4 n+ }; w  B
getch(); ( s2 A6 s0 R/ |1 L6 D3 U4 Z
closegraph();
4 Z4 e6 [9 ?  K' |2 D9 ~8 ~' ireturn 0;
  h* x" @2 U- o( O/ T} 9 r, n+ V3 r& U% M
</FONT>
( B* X; M% z; ~) ~  ?</P>
5 [" @5 e9 o2 X<P><FONT color=#ff0000>函数名: graphresult </FONT>2 c8 z: |- p4 N, x: o
功 能: 返回最后一次不成功的图形操作的错误代码 . l! j$ C8 u0 |# X5 f# O- k
用 法: int far graphresult(void);
+ |3 Y: Z# h0 x' s程序例: </P>9 [- u" Y* Z$ z
<P><FONT color=#0000ff>#include <GRAPHICS.H>& X- B4 @$ N( K+ h
#include <STDLIB.H>
1 Y5 N7 b% z: d: t/ Y/ X#include <STDIO.H>
4 ^5 Y1 w6 t$ c" X4 O& Q#include <CONIO.H></FONT></P>
% m6 e' z" d, E& r8 G+ m: d<P><FONT color=#0000ff>int main(void) 8 Y% a  X/ q7 E/ ?
{ % R  u- F2 r9 f
/* request auto detection */
" c6 D! m  n: q3 @( P8 q9 eint gdriver = DETECT, gmode, errorcode; </FONT></P>
0 N* u* c1 h9 l  c& R& m8 Y' x<P><FONT color=#0000ff>/* initialize graphics and local variables */ - L, l2 R5 c! G- z) G- |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ o" ?5 n' C- d/ \1 b  l- P7 m<P><FONT color=#0000ff>/* read result of initialization */
- Z# P  B  _4 Serrorcode = graphresult(); </FONT></P>
& O/ K% V8 o; v& F, Q0 q- m5 |$ E<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
, V( I) w) g; F2 Z- T7 ~6 |1 o{ , B3 c# r% y; \  p) s4 L
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 u0 a  u' q" R. v! J
printf("Press any key to halt:");
* b8 J" C; z8 u2 |1 {3 O7 Tgetch();
1 `8 l" S9 r# P  d( q  ~exit(1); /* terminate with an error code */
1 f2 ~6 o3 m5 |2 T0 S- V5 E! \} </FONT></P>
3 @/ B, Q% q: L, [<P><FONT color=#0000ff>/* draw a line */ ' X! i/ @' B# V
line(0, 0, getmaxx(), getmaxy()); </FONT></P>* T6 ~% \# }$ v' C1 ?' K
<P><FONT color=#0000ff>/* clean up */ # Q* h7 e$ P  ?1 L" y, G1 w) x1 d
getch();
' E" G- Z- n. a5 L5 z/ qclosegraph(); . @. x" M) c1 N4 {; K3 m! r
return 0; % l9 o8 I5 v! `; x# _  d
}</FONT>
' }+ ~" o4 S/ p% M$ s; s2 V</P>1 j& A8 {2 p4 l2 ^1 |, i, E1 i
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> 0 _9 Q( \  W9 W2 _! w( K
功 能: 用户可修改的图形存储区释放函数
0 t( F( t) {. x9 l9 Z8 F用 法: void far _graphfreemem(void far *ptr, unsigned size);
; S- y, |2 P0 C% m6 H. D3 j7 X4 A程序例: </P>
  E; K3 e+ ^- l' {4 p0 F/ M! r<P><FONT color=#0000ff>#include <GRAPHICS.H>
- p3 n8 y1 O5 {  i: X#include <STDLIB.H>5 Z5 ^' r8 @- \3 C( ]4 ]* j6 p
#include <STDIO.H>
& ^7 [1 F0 Q1 G! M+ U- j1 n#include <CONIO.H>/ l' M6 p- ^# t, P0 ?: F6 z
#include <ALLOC.H></FONT></P>
4 Q. N& z5 P6 e( N6 J) v0 C: a<P><FONT color=#0000ff>int main(void)
( |4 G" M7 |4 Q9 o% x3 g{
( c7 x! b2 Z% U. U' {/ P/ d) B8 K/* request auto detection */
6 @; o9 }1 m2 f1 v( Gint gdriver = DETECT, gmode, errorcode; 0 ~5 M& c  \  u7 `: s9 m
int midx, midy; </FONT></P>3 p: I/ f$ C+ [, ?
<P><FONT color=#0000ff>/* clear the text screen */
2 ~4 u3 X: V# [( [+ d: mclrscr();
6 w2 t0 e) }0 b: E0 B. U$ aprintf("Press any key to initialize graphics mode:"); $ a. }4 t- Q' L/ F7 m
getch();
' h% c" g6 W$ F1 G% ^clrscr(); </FONT></P>/ W+ j$ b& H$ V* A5 ?- V& M4 r
<P><FONT color=#0000ff>/* initialize graphics and local variables */ # g  A* K8 C5 O- \4 o% w$ U, ~
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 U4 ]" c  t4 ?. v; I
<P><FONT color=#0000ff>/* read result of initialization */
; I  [: {3 O0 ^/ l- j7 C7 Serrorcode = graphresult();
* \" g2 T, P1 ?% \if (errorcode != grOk) /* an error occurred */
, j2 A" v( T, F{ " V) u7 f! ?1 `% e; e
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' j. \: ], T: H# D( }
printf("Press any key to halt:"); * T3 [# B2 `3 N( v  H
getch(); 6 r/ T/ ?9 ]8 B
exit(1); /* terminate with an error code */
4 n6 a1 c/ N3 \( q. L+ A} </FONT></P>; P- g4 T+ p/ r7 ?  I/ J% M
<P><FONT color=#0000ff>midx = getmaxx() / 2;
9 {; \5 T" K! C  B: c: c4 ^7 {midy = getmaxy() / 2; </FONT></P>% x, C5 E9 Q  `/ V% m+ Y/ ?" T. N* N
<P><FONT color=#0000ff>/* display a message */
8 c# @7 G# a- {! o1 B+ @settextjustify(CENTER_TEXT, CENTER_TEXT); % A: e  |( R8 K4 ]
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
4 ^$ F+ |0 z4 r; l- M. s<P><FONT color=#0000ff>/* clean up */ + v/ B* l/ x' I* Y
getch();
* J) G* g/ Y- E: ^/ ]3 Z/ Nclosegraph(); " J. f" Y6 U: V! r' s5 l2 F
return 0;
1 h( a- q% ?9 k  K4 G( \$ G} </FONT></P>
7 l5 U" p1 F+ \$ e$ k<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ * X- O! x! v4 {( P, w$ F
void far * far _graphgetmem(unsigned size)
$ ?) l' n8 r" R/ ~{ 2 U& h# N3 \/ M; r/ r
printf("_graphgetmem called to allocate %d bytes.\n", size);
4 e4 o5 f  |5 U% ]printf("hit any key:");   A* C; x: H8 g3 V7 J
getch();
# O8 h- P& W3 O' n$ w& G6 s5 gprintf("\n"); </FONT></P>
; ^+ S/ L1 u* T; Q# E<P><FONT color=#0000ff>/* allocate memory from far heap */ 0 H% U: }( K) g# C1 D
return farmalloc(size); * i& O% L$ H( x* O$ O8 k' F! C3 I
} </FONT></P>/ h8 r' i, v' {7 Y* ~
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
; R# d7 y. v+ T! M$ X) nvoid far _graphfreemem(void far *ptr, unsigned size)
% k  P3 O  X- u9 \/ s; x: ]2 a/ l{
" h# J  Q# ~9 b# C; Uprintf("_graphfreemem called to free %d bytes.\n", size);
- ]7 R- t0 W3 U$ X, B7 T( ?6 G9 H) rprintf("hit any key:"); : {9 P5 I5 I3 ?% w! J1 u& y% z4 Q8 i
getch(); 0 b( A- h% U# h1 D
printf("\n"); </FONT></P>
6 ?8 t0 c1 k6 U/ t<P><FONT color=#0000ff>/* free ptr from far heap */ % G- l0 j6 n- p0 g5 q! Z3 m
farfree(ptr); 2 G. o0 K- G& G$ ]  C' w
}
" x; d# s3 q3 D! M& h6 i</FONT></P>
3 e& W* P4 j; `2 D<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>' _! ~3 P+ e3 D3 [9 }0 Z* {
功 能: 用户可修改的图形存储区分配函数 6 d+ ?7 A* ]7 z1 r2 _
用 法: void far *far _graphgetmem(unsigned size); + K. X/ B  W: R2 \
程序例: </P>
2 n; l1 L8 N2 Z<P><FONT color=#0000ff>#include <GRAPHICS.H>( y5 u  q- B2 Y; W$ [2 Y
#include <STDLIB.H>1 @7 V0 h, J6 a9 y6 @
#include <STDIO.H>( n9 y: h0 i1 W8 ?; Z
#include <CONIO.H>
  s  H; y9 F1 h, G4 `5 |/ s#include <ALLOC.H></FONT></P># }% W+ I% w0 Q$ K, m9 d  O
<P><FONT color=#0000ff>int main(void) $ @2 {3 I5 e! |3 O
{
: e: e& s  M, p, U9 q* f/* request autodetection */
" H/ K! T1 _) {1 g5 p; q) qint gdriver = DETECT, gmode, errorcode; / S: a: {# v+ d/ X; b  G4 W" N) T
int midx, midy; </FONT></P>
' O: F2 ]9 P3 W1 b; ]<P><FONT color=#0000ff>/* clear the text screen */
6 {4 f% [' e9 d$ L6 U0 |clrscr(); 4 a! d' ?4 i) Y! M% ?
printf("Press any key to initialize graphics mode:"); 9 {2 M9 L# J4 o" O
getch();
5 G; q' V& H( E% @. }clrscr(); </FONT></P>
$ s9 Z/ }: F, I+ C* p2 R: ?<P><FONT color=#0000ff>/* initialize graphics and local variables */ & C2 Y$ C# N# Y  T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>& [5 u4 g) ?4 P2 b; u; {1 g4 `
<P><FONT color=#0000ff>/* read result of initialization */ , `9 o( u* P0 U
errorcode = graphresult(); " h: d4 {0 c$ I$ j, C" C: K$ h3 `6 z
if (errorcode != grOk) /* an error occurred */
) _6 E: P* T! D{ 4 M9 Y+ P/ ]5 h7 p: v2 o
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' m3 I1 C1 C+ b  M. Q
printf("Press any key to halt:"); " \2 Y( g1 Z2 c3 N9 A
getch();
. n* P3 q' c. ?. A$ bexit(1); /* terminate with an error code */
, y, i+ |. @, j, H& q} </FONT></P>/ ?4 P" S4 S( W3 E$ P' l- ~3 o
<P><FONT color=#0000ff>midx = getmaxx() / 2; # c9 Y2 s2 M! N$ Y! U
midy = getmaxy() / 2; </FONT></P>, O( J+ q( v; O5 g
<P><FONT color=#0000ff>/* display a message */ " A/ r7 p9 A9 G; ~  e
settextjustify(CENTER_TEXT, CENTER_TEXT); & O  k; A! b, J% a/ Y9 h8 m0 ^+ o7 C, h" ~
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
& J$ Z" M5 n' e# Q2 g<P><FONT color=#0000ff>/* clean up */ 3 u" h4 O5 `! c' s6 d
getch();
8 R' c7 d2 u/ D/ |closegraph();
& m2 B7 s, l* i  ?1 y2 E( |return 0;
: f; ?6 D7 r1 U8 M( F! b} </FONT></P>
* ], ^( i( b! p4 N<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ $ H6 w! s4 g' ?. D6 l1 f( K
void far * far _graphgetmem(unsigned size) * n5 L" _! t) _; g, V, U* ]3 a$ I8 r# M
{
* a( |. N) i% G' t7 N5 @7 \printf("_graphgetmem called to allocate %d bytes.\n", size);
6 r# E$ N8 V/ W' H( c5 wprintf("hit any key:"); * V& M! Q# D5 t5 E7 T4 G7 `
getch(); 3 L! o4 v0 y0 s" c3 \: z
printf("\n"); </FONT></P>7 E- v0 T1 P# H% e3 f( S
<P><FONT color=#0000ff>/* allocate memory from far heap */ + t( c  d* r' J1 o; b
return farmalloc(size);
9 w) T6 x! s7 y& a} </FONT></P>
% x# P. {) r7 a, ~2 l& r: x<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ ) \8 J6 V0 d1 w, h
void far _graphfreemem(void far *ptr, unsigned size)
0 A( Q0 k# X6 p4 c: j. ?8 L{ ) c9 Z, B9 }! G. [7 Q- I7 o6 M; A
printf("_graphfreemem called to free %d bytes.\n", size);
! d, d- c6 K6 C- s. x# }: Z* V6 L7 Pprintf("hit any key:");
0 |9 G: u* o, S: T( I! Y/ Y6 D: N4 }% |getch(); . Q9 x: u/ w4 y3 q/ k
printf("\n"); </FONT></P>' Y' c7 V; }8 p
<P><FONT color=#0000ff>/* free ptr from far heap */
8 F, G9 }+ u% Ufarfree(ptr); / g6 W( V9 d4 s8 l
}3 \% R" j1 P- A! I8 s  F
</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-23 22:51 , Processed in 2.425431 second(s), 51 queries .

回顶部