QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2547|回复: 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>
( K% I9 a7 P% ~% Y& d5 Z8 b$ c/ q# M0 ~2 M' J7 [

) V( F$ Y% T/ U" P7 Q<p>
7 t) d, S# z+ H3 n# N8 T$ r; f2 w<><FONT color=#ff0000>函数名: gcvt </FONT>
- x: m; q; J; _, _1 L功 能: 把浮点数转换成字符串
4 Q0 `4 U: \; d" d9 S6 O/ L! ~用 法: char *gcvt(double value, int ndigit, char *buf);
/ N3 w2 p; y2 w6 U程序例: </P>" r& u( ]9 l3 ?5 R$ w! f
<><FONT color=#0000ff>#include <STDLIB.H>
% \8 l! G& M3 M7 J0 {# ^#include <STDIO.H></FONT></P>
9 r3 e$ E4 F! v8 j' v<><FONT color=#0000ff>int main(void)
# A0 S* d! j0 W5 @$ W/ e{ 1 F# r2 P( i) @- a- ^+ ^
char str[25]; 5 [  n# {1 F, A# f5 l; G* M
double num; " a' \/ a" a! |* F- [
int sig = 5; /* significant digits */ </FONT></P>
5 F* f$ J+ i+ e, x3 m) P<><FONT color=#0000ff>/* a regular number */ - P+ c+ ^8 D0 s1 {/ |
num = 9.876;
2 M! E  i8 O* _gcvt(num, sig, str); & t. p0 t8 \+ T% P6 }/ W( w( R
printf("string = %s\n", str); </FONT></P>) S! T6 b7 D& X9 M
<><FONT color=#0000ff>/* a negative number */
4 G9 h* X  R( i  J. cnum = -123.4567; . C) H" g+ B! F8 X6 Z  W( E
gcvt(num, sig, str);
/ w0 m& B0 R0 C, F: zprintf("string = %s\n", str); </FONT></P>' S1 Q8 a8 b# G! d0 B. O
<><FONT color=#0000ff>/* scientific notation */
) W# d" \; [) K3 e$ q% k/ Rnum = 0.678e5; 7 \: Y' G4 s; {0 m; p1 _9 _6 ~
gcvt(num, sig, str); 6 A  Y' ?- R, Z4 U/ W" U9 m
printf("string = %s\n", str); </FONT></P>( J7 x( ?! K( I
<><FONT color=#0000ff>return(0);
0 w1 u$ t# V" p8 ^} ) ]# D( _( I. w. z1 L
0 k1 n4 d% _1 Y! F
</FONT>
# X% N: @9 u% X$ d  b</P>
: X7 K: `# L8 o2 l( G<><FONT color=#ff0000>函数名: geninterrupt </FONT>  K0 G* W0 J8 l( G7 z1 y
功 能: 产生一个软中断 + W2 }# S0 r1 D; B5 S+ O) A
用 法: void geninterrupt(int intr_num);
5 B' B' s( ?1 r程序例: </P>1 N; a( ~& L, f, N
<><FONT color=#0000ff>#include <CONIO.H>
1 |7 w8 m/ a1 D# t7 {#include <DOS.H></FONT></P>) p$ O/ p4 F2 A" s. ?. c) a+ @
<><FONT color=#0000ff>/* function prototype */
* ]4 J% U, W; V1 E! i  Z. Vvoid writechar(char ch); </FONT></P>, ^9 B9 j2 r2 `- J0 F- }' L  t
<><FONT color=#0000ff>int main(void)
7 z5 z  w) q1 l8 c4 i{ - U& _+ u2 a/ ]' T" |
clrscr(); ! R$ Q/ C% F% S  Y
gotoxy(80,25); 0 H9 ~) s# O- ^, I! o- Q  K
writechar('*'); 7 F: P, D3 z. W& w. k+ u4 I
getch();
3 ], _3 r3 J) |/ T% T& Sreturn 0; : t" M  J  p) J. O1 u
} </FONT></P>
+ t8 \" A7 \: K$ z<><FONT color=#0000ff>/*
. G7 ?' f/ E& x, @! q! zoutputs a character at the current cursor 3 b5 @# _0 I5 z8 B# H, c2 f+ _
position using the video BIOS to avoid the
7 D! E+ v6 C1 w% cscrolling of the screen when writing to : H, ~9 d6 D0 m, [4 ~- f$ ]0 F# S
location (80,25).
+ p  u- A8 |. Q+ z/ r*/ </FONT></P>
* P, H% X  S  g<><FONT color=#0000ff>void writechar(char ch) - u6 y: j6 ~9 T
{ 6 I4 r1 \  Q% p( J9 W
struct text_info ti;
9 b4 c% R: l  n+ o. d/* grab current text settings */ - m: j8 J6 i0 E0 }% `/ `- `8 P8 b2 K
gettextinfo(&amp;ti); 9 T( L' N+ X3 H4 |+ G' A
/* interrupt 0x10 sub-function 9 */
' Y' E- q- N7 _1 a& @_AH = 9;
1 ]+ b2 n+ M1 a/ r$ t0 Q& V! y# ~7 R- t/* character to be output */
! t- h) ?- C. h1 k8 a! G2 X_AL = ch; ( A3 `7 z) W$ K3 o" Y
_BH = 0; /* video page */
) H' E2 w' \3 l5 F_BL = ti.attribute; /* video attribute */
4 P% Z2 w) {4 k  C_CX = 1; /* repetition factor */
/ d) n: t/ L" e4 L4 {geninterrupt(0x10); /* output the char */ 7 S3 i0 A: [3 D* E$ ]
}
5 m; L0 V* _- K0 @5 r9 {</FONT>* e- t$ [) k1 P; M: m
</P>' O. j# F" P) B! m3 t% w( w
<><FONT color=#ff0000>函数名: getarccoords </FONT>6 {+ m9 d' A2 \* O
功 能: 取得最后一次调用arc的坐标
5 h6 z; R) U3 ]! ]- B) z9 p6 z用 法: void far getarccoords(struct arccoordstype far *arccoords); 2 H0 l, h4 c# h7 ^
程序例: </P>
- ^* \4 F" X7 ~<><FONT color=#0000ff>#include <GRAPHICS.H>8 z% z/ r$ Q0 r  u; M
#include <STDLIB.H>" e$ v3 L4 h! D2 C- F
#include <STDIO.H>. V* |1 B2 b' J8 @3 E4 p. F
#include <CONIO.H></FONT></P>7 @' S! I5 j5 _3 B
<><FONT color=#0000ff>int main(void) - e; w# T# {# C% l- y- f, ?
{
, X) \; E$ ~' v; T- I' n2 N9 d/* request auto detection */
6 S; s2 a- Q5 H& n7 S8 nint gdriver = DETECT, gmode, errorcode;
% f# I/ o4 E- t* c- Q9 Wstruct arccoordstype arcinfo; + v1 _  I+ ~1 N, X: F. v
int midx, midy;
' T" y% o! K. Y, c9 _& X3 Fint stangle = 45, endangle = 270;
9 b7 n" q; k  X( W: P! s' n( {" ?char sstr[80], estr[80]; </FONT></P>0 V& R+ r% s  v4 h2 c* [( u6 A
<><FONT color=#0000ff>/* initialize graphics and local variables */
6 ~% i  @3 E( s( ]) Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ O; y9 v% i5 p: a
<><FONT color=#0000ff>/* read result of initialization */
4 J/ C; t. I$ B2 {; m0 y# G" S; c% c" yerrorcode = graphresult(); 0 g/ P0 n+ x$ h! {  ^( U3 |
/* an error occurred */ ; T$ w  S2 C! o$ U
if (errorcode != grOk) . I" L$ Q- K9 y+ w# F
{ 7 w% O/ Z9 G# E6 H0 }% p' ~) i
printf("Graphics error: %s\n", ) D/ P1 R1 @* T: B$ `) q7 K
grapherrormsg(errorcode)); + a: c3 k  t" r* B
printf("ress any key to halt:");
- H$ g1 ]) U: m! \7 |/ ~* G' cgetch();
4 v9 Z, V+ P' t+ y4 Q/* terminate with an error code */ ; _( s0 ~, g9 S& B8 J& p
exit(1); ) v( g5 H4 c# B2 K9 E# A
} </FONT></P>( J6 L8 X6 U# D8 P# @/ J
<><FONT color=#0000ff>midx = getmaxx() / 2; % ?" t3 R& q5 _* p
midy = getmaxy() / 2; </FONT></P>
5 F- q& m$ p( Z, c: k& h<><FONT color=#0000ff>/* draw arc and get coordinates */ $ W8 e) @6 m2 A
setcolor(getmaxcolor());
$ x, [7 M5 u+ [9 Q8 y+ V. l/ f0 Narc(midx, midy, stangle, endangle, 100);
, k$ u  Y. {. K3 S% o, D3 xgetarccoords(&amp;arcinfo); </FONT></P>4 N* v' L3 m! x+ Y$ }" B
<><FONT color=#0000ff>/* convert arc information into strings */
. z0 `4 d/ k+ \. a/ |+ ~sprintf(sstr, "*- (%d, %d)", % B1 N% O* v( }+ Y. T  S
arcinfo.xstart, arcinfo.ystart); . [; E" E/ U, E4 q; h- }6 p
sprintf(estr, "*- (%d, %d)",
% I- g( o, n. ]; D, Narcinfo.xend, arcinfo.yend); </FONT></P>
7 P, p0 c/ w; ?6 l- m<><FONT color=#0000ff>/* output the arc information */ $ w0 x+ G, {( R( }0 c, v
outtextxy(arcinfo.xstart,
! \+ f  L5 K- u. ?- u8 r7 Z' Carcinfo.ystart, sstr);
* j$ B: G! }8 g, Y) Qouttextxy(arcinfo.xend, : g# L' p" \5 s" K
arcinfo.yend, estr); </FONT></P>
: _$ _6 L0 C4 u( h* ~<><FONT color=#0000ff>/* clean up */ 2 H8 V/ N9 @) @& U- z# r
getch(); 5 [7 L$ J- A$ M0 Y* C. g  e
closegraph(); ) k# B! ?0 V) e$ @4 U- g
return 0; 8 T8 E4 V% ~! w1 e  I9 R
} ' `5 r0 S: r; m  S0 [* y8 I: i
</FONT>6 g* ]; D* `1 U8 I  a" e' E# w

( J1 m$ O: S* Q% x; b</P>
  d# Y; a6 O2 d$ G<><FONT color=#ff0000>函数名: getaspectratio </FONT>
$ X8 e3 N3 }! X* y% T0 s) J3 s: c功 能: 返回当前图形模式的纵横比 / N! v+ z7 G3 h. g/ N7 i0 {
用 法: void far getaspectratio(int far *xasp, int far *yasp); / V; {  d- k& I
程序例: </P>% J! `" o: y9 U$ t4 O
<><FONT color=#0000ff>#include <GRAPHICS.H>4 }! r2 I0 n$ U  x) j! K' m; S7 ?
#include <STDLIB.H>' P6 V2 k# H1 C) @4 {8 b/ a+ F
#include <STDIO.H>
) @2 J( u, {1 [+ m; k. H#include <CONIO.H></FONT></P>
3 p* g* ^7 [+ Q<><FONT color=#0000ff>int main(void) : Y/ w" \& Z* E4 G( a7 a+ e
{ , x$ y9 O9 k: _+ k
/* request auto detection */ . V- s5 z) m, b
int gdriver = DETECT, gmode, errorcode;
% M7 o; b+ S# N* ^. iint xasp, yasp, midx, midy; </FONT></P>
+ p: P9 ~# |* x9 |4 @<><FONT color=#0000ff>/* initialize graphics and local variables */ 3 g4 ^7 m5 b& y$ [- z2 |9 B
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 c2 o* E# H' O1 Z6 u: q! y# F1 `<><FONT color=#0000ff>/* read result of initialization */ ( Z1 F; M5 s6 d+ ^- m1 Y1 v
errorcode = graphresult();
+ v2 E. L. A/ V) d  A+ k/* an error occurred */ ; O$ u* P8 \. g* G3 \6 x
if (errorcode != grOk) ' ~; g% ]# @  Z. C0 T
{
+ u8 x) \1 O9 K0 b% v6 xprintf("Graphics error: %s\n",
5 a5 S# Q: J+ s3 _$ `8 lgrapherrormsg(errorcode));
; L& W! ]5 G6 j9 Z  W; yprintf("Press any key to halt:"); 6 K' [( R0 V7 a
getch(); 9 v: ]0 n; X+ `; N$ A
/* terminate with an error code */ 2 x. y! T2 h* p9 r/ V; ?: \
exit(1); ! y+ l# v# z+ A8 |7 K; o5 E
} </FONT></P>. Z$ d- C1 _0 m& D% G' M: i
<P><FONT color=#0000ff>midx = getmaxx() / 2; : M! O9 K9 U; G+ b3 e( d: T/ R7 [: v
midy = getmaxy() / 2;
* v4 h4 C% o- X" `setcolor(getmaxcolor()); </FONT></P>
' f9 f5 t3 q# @% k: u0 ^! x<P><FONT color=#0000ff>/* get current aspect ratio settings */
7 F* w- f; k; s: m  k2 p# f2 Mgetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
/ u% S1 ~  b* M! G8 h) k) u' }/ k<P><FONT color=#0000ff>/* draw normal circle */
1 d7 t- S2 t, g* xcircle(midx, midy, 100); ) Y* r% ~2 Y& T5 A4 B
getch(); </FONT></P>6 X3 e6 ]- J) w  k, H
<P><FONT color=#0000ff>/* draw wide circle */
. P, `# r* l* N  [# `cleardevice(); + K) o- Z) \1 \9 l: ^$ }: ?5 t/ P
setaspectratio(xasp/2, yasp); 0 M4 H9 Q% ]' k( g% S: ^0 L) D
circle(midx, midy, 100);
6 u+ w0 s& g  zgetch(); </FONT></P>
' y6 F  e! a# l( L$ P& ^<P><FONT color=#0000ff>/* draw narrow circle */ 3 x  k9 k1 \$ I5 b
cleardevice(); 3 m" _/ w* I  g3 b: f# S4 z/ b
setaspectratio(xasp, yasp/2);
1 f- [" H' s- C/ e. f+ y, Zcircle(midx, midy, 100); </FONT></P>
, R$ F$ w+ S1 U. ?; X7 J- b) P<P><FONT color=#0000ff>/* clean up */ 0 ~8 X8 {' f( b# ^6 \
getch(); " X4 E, T4 Z+ m6 ^! G' [/ @3 z3 k7 z
closegraph(); ) M' w9 g& C8 w
return 0;
: T. Y1 n- H" a$ N$ j; H' r} - I$ k" d$ D" M+ D
</FONT>8 P" {+ Q! h& u# r, S

) a$ ]; a5 v( J- _0 J# _) M</P>
+ J7 E. A- \( J7 _<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
  Y# ~( J! [4 ?5 p3 o功 能: 返回当前背景颜色 + w! ]7 @$ r& q  i0 ~9 Q
用 法: int far getbkcolor(void); $ n5 X5 m1 W; Z* N0 z* b
程序例: </P>
- {0 h4 A3 J! k4 W* ^+ |<P><FONT color=#0000ff>#include <GRAPHICS.H>* C2 R; {$ k# v0 ]& J8 h) A4 f
#include <STDLIB.H>
( X8 ~% h; T# B" S# W4 g4 K#include <STRING.H>+ R+ w/ z0 h# @1 _6 D
#include <STDIO.H>
! q) g4 x1 ~" O9 b#include <CONIO.H></FONT></P>
9 F$ f! }2 z2 D% }<P><FONT color=#0000ff>int main(void) + T1 B7 p* z) C9 X5 e/ r
{
# K. w; h7 w9 J/* request auto detection */ 3 t$ G  i* R" \) f
int gdriver = DETECT, gmode, errorcode; & Q/ Z1 c' V7 j! ~" p, z
int bkcolor, midx, midy;
) v. }" y  x' b6 Ychar bkname[35]; </FONT></P>
7 \8 s8 Q7 @! {( \! \0 {: s( q6 k: t<P><FONT color=#0000ff>/* initialize graphics and local variables */
, D4 {; l' a. k+ u) |- I; cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 V% W- h( S$ W0 T: T) n9 _. [: U<P><FONT color=#0000ff>/* read result of initialization */ - s9 @0 `" t* @+ U
errorcode = graphresult(); 6 v3 ~6 ]  j. \, i  |
/* an error occurred */
  u4 W) U& f8 mif (errorcode != grOk)
0 ^1 w" a- }, Y{ - s3 c8 k4 m0 j$ i4 ~
printf("Graphics error: %s\n",
# U  U% X9 Y0 v* v6 Jgrapherrormsg(errorcode));
3 Z- z0 D, U( z0 `printf("Press any key to halt:");
% F( c" G* Q8 c" x# ygetch(); 5 w, N/ r+ B  z
/* terminate with an error code */
/ V, k2 N( M1 x& l& v0 Vexit(1);
0 s; a5 G. U* ]} </FONT></P>' ?" p& W" h/ a
<P><FONT color=#0000ff>midx = getmaxx() / 2; 8 X) b! N( @. f' O2 `4 Y  c
midy = getmaxy() / 2; # i1 Z7 s$ p7 u+ e9 z
setcolor(getmaxcolor()); </FONT></P>
0 o( v2 o( j6 |  l6 x8 b<P><FONT color=#0000ff>/* for centering text on the display */ * i& M, r8 ?) A
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
" Z" ], Y7 \) y<P><FONT color=#0000ff>/* get the current background color */
+ Q3 N7 u6 T" Qbkcolor = getbkcolor(); </FONT></P>
/ ~+ z# d8 p3 W7 C0 Z, L<P><FONT color=#0000ff>/* convert color value into a string */ + ^' ^8 z' ~; Q3 O0 v  T/ o
itoa(bkcolor, bkname, 10);
; d4 U3 G6 r6 n0 `3 C/ kstrcat(bkname,
; ]# f1 L: q3 V5 z" is the current background color."); </FONT></P>% |4 J1 \/ N( z( p' ~& Q
<P><FONT color=#0000ff>/* display a message */
- o# C; d, x% C& Iouttextxy(midx, midy, bkname); </FONT></P>
( S9 N6 k9 C' i. |4 ]<P><FONT color=#0000ff>/* clean up */ 0 u' c" I4 U' A: p/ I' d( }: |
getch(); ! P3 F( G% M* c# X$ s& d" T
closegraph();
. Y) n( m. ]9 T& U+ ?  j5 }return 0; ! X1 f. r9 ^7 ]* v# x6 x/ W" z1 s
}
' s7 e# @0 J! d1 L3 h0 e2 I7 [4 p$ }0 ^; Y& t. A0 w+ t" K. Q& @
</FONT>
3 O7 ]4 z: Q4 q! t7 H</P>& i6 c: ^3 y$ x: E8 y2 o! g
<P><FONT color=#ff0000>函数名: getc </FONT>6 A- B* c8 B$ w" ]* O+ G
功 能: 从流中取字符
3 A4 h! {5 ^! K5 h+ p1 L2 \用 法: int getc(FILE *stream); - s3 B8 r0 w" a9 z& e
程序例: </P>/ y5 T9 r2 D$ B) ]0 T% f
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
$ }( T3 l- E6 Q<P><FONT color=#0000ff>int main(void)
' V0 K( h. J$ \5 y{
7 t! z$ y+ F& j! L) kchar ch; </FONT></P>
0 z% z# s$ k  B: M! V<P><FONT color=#0000ff>printf("Input a character:");
/ [. X( V- s& n0 G1 Z/* read a character from the . N1 l( w! Q$ ]; m- e$ w5 D4 F
standard input stream */
4 `& p! }5 y$ mch = getc(stdin); ( H5 h& }- L& t8 m
printf("The character input was: '%c'\n", - K! e* |; ?% b4 ]  Z; T* b
ch);
! r  t6 L' w6 creturn 0; 7 Y) X) i; l6 q9 ~
}
3 _' E+ v- P4 }, J0 r0 {/ P2 a  ~5 z% ^- U; M2 P9 g& S2 a
</FONT>
6 e3 x" ~# s3 T  c</P>
* k' S% `+ u# H( M! }6 J2 z3 M3 g2 l; H8 t<P><FONT color=#ff0000>函数名: getcbrk </FONT>
' X) d! N. }. L9 m5 a功 能: 获取Control_break设置 ) K) q  u7 U) Y" F
用 法: int getcbrk(void);
  c; S+ I" e9 q5 @程序例: </P>) x9 L4 y8 r) Z( s0 M6 D
<P><FONT color=#0000ff>#include <STDIO.H>3 h7 a( }; j1 T6 _" Z; M7 h* k7 s0 m
#include <DOS.H></FONT></P>
, z3 n5 o. _/ N+ m$ K$ |<P><FONT color=#0000ff>int main(void)
" o7 v/ o5 p  h  {* S/ u  M- {{
) s* n0 A& M+ C1 eif (getcbrk()) 8 W# W! u7 P! m/ _
printf("Cntrl-brk flag is on\n");
+ S: R3 F5 S4 `$ _) Y5 p" }+ Q# D9 velse 3 C/ p; R& M  @( z% {
printf("Cntrl-brk flag is off\n"); </FONT></P>/ j2 n; z" l" e5 p& P, n
<P><FONT color=#0000ff>return 0; 5 K& j+ A2 ~6 S8 q) U4 r) |
} </FONT>0 ~6 _; n& s* ?) n/ X

4 p- H3 z4 J% I& ^8 D( w3 q, J</P>
9 m7 K1 U2 H9 a, _5 D# ?<P><FONT color=#ff0000>函数名: getch </FONT>% D  V) A3 C* t. k/ O; j7 _
功 能: 从控制台无回显地取一个字符 5 _  p' [& D: J$ Z) N$ @, t( Z* t
用 法: int getch(void); - h1 N# K, t6 p4 U1 o1 u: a$ W
程序例: </P>% `% H. E/ D% v) L" ]3 C% I2 b
<P><FONT color=#0000ff>#include <STDIO.H>
5 X* x( k- C6 S#include <CONIO.H></FONT></P>
9 p2 [" y4 {! e1 K* J<P><FONT color=#0000ff>int main(void)
0 J1 }* z* l8 ~" R1 K{
2 ^6 A% V' b9 m1 N" f* I9 f3 Y$ ychar ch; </FONT></P>
0 H# @. q! ^0 o$ `' e<P><FONT color=#0000ff>printf("Input a character:"); % M- P2 o7 W( c8 P) |. @* h7 x
ch = getche();
; y' A9 w+ `# Mprintf("\nYou input a '%c'\n", ch);
% z- S8 @+ R. a- h  K! V  Treturn 0;
# g- z; _3 ]& M6 k}
7 ]# ~" ~* w3 l, O# t6 o4 P
- ]$ Z( u9 t0 g' O: m</FONT></P>
" }; f0 a4 M* l/ C: Y. r, o0 Z<P><FONT color=#ff0000>函数名: getchar </FONT>
2 C, @2 G% f+ Q  @1 Y( r功 能: 从stdin流中读字符 / x  A& D) o! s* w3 _2 x" ~
用 法: int getchar(void);
6 t" W) [1 }4 @程序例: </P>
0 C0 t1 I" Z5 [0 d2 @<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>1 n' F4 J: a8 @7 Q' f) h
<P><FONT color=#0000ff>int main(void)
+ Q) R! i6 C7 e3 A{ ; Y3 p1 v/ n5 W1 W5 r2 y
int c; </FONT></P>
5 w, y2 _: Y2 }  e<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
" p7 d3 K$ I- jis line buffered; this means it will ; p: ~5 U. |5 E3 @2 O
not return until you press ENTER. */ </FONT></P>% J0 ~5 o  R1 \. J  L' a
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 8 O8 N: T5 K7 i/ x( f% ?
printf("%c", c); </FONT></P>
. Y" w# N, c( w- B% j7 A( w<P><FONT color=#0000ff>return 0; * P+ ]# g8 ^* P' J8 U! f
} , f+ M4 r5 p* E. K9 y
</FONT>6 _5 f8 X) \5 G+ b3 {$ u% R- R
</P>
7 x$ b, u3 A& v, N<P><FONT color=#ff0000>函数名: getche </FONT>
8 I( D, v% J  F功 能: 从控制台取字符(带回显)
. Q, a' O* o0 b: W% j用 法: int getche(void); 1 O2 n* R; l+ k' _
程序例: </P>
+ [2 }) ?1 t; ^( ^<P><FONT color=#0000ff>#include <STDIO.H>4 ]6 M4 q# L5 S2 I6 N% f
#include <CONIO.H></FONT></P>
2 w* K, ]0 {9 j7 v3 I% t8 t3 C<P><FONT color=#0000ff>int main(void)
" ^4 x+ L4 K/ G9 l, s{ & l8 a* t! m% {
char ch; </FONT></P>) F) x# G  C' N( C5 _: R, p$ Z
<P><FONT color=#0000ff>printf("Input a character:");
' f$ E! p! \2 n' S/ ^. Och = getche();
! u' [3 n* r: V; aprintf("\nYou input a '%c'\n", ch); 5 h0 O- {8 I; u
return 0;
# q4 U9 l7 M( D% d3 ~! q5 A2 }5 e}</FONT> - M# w3 {0 Z+ i: G5 ]* c
8 ^' Z3 L, l0 H2 o* x; C" L5 S0 O; v
</P>
* A, Z- ~% p1 O, H<P><FONT color=#ff0000>函数名: getcolor </FONT>: r- m; ]: }  p7 e! j
功 能: 返回当前画线颜色
/ J! o! Q2 K* Y. W用 法: int far getcolor(void); 2 H" ~* j6 _! n. w6 b7 M& V
程序例: </P>
5 k4 U9 m  F$ g/ j<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 t0 C5 X* e/ ?  ~#include <STDLIB.H>7 V" ?% K* J$ q" h' _3 H! {  I
#include <STRING.H>
- ^! r3 X9 \- S' H$ B- ?8 _#include <STDIO.H>6 e! ?# z: [- ^6 _% H8 c
#include <CONIO.H></FONT></P>
  T) {# v. l" ~' K! m6 Z& e<P><FONT color=#0000ff>int main(void)
' P. g) }3 y! @5 W# p{ - D5 J7 v9 Z  T$ m- t/ ]
/* request auto detection */ 4 D/ Q+ Z( o2 {) A' p- {
int gdriver = DETECT, gmode, errorcode;
# ]6 @$ ?+ W! y- U/ Q: m% h; Z, ^; Lint color, midx, midy;
' I9 w) |7 S  p; V1 Achar colname[35]; </FONT></P>/ y. \/ e$ y8 }' H% ~1 K
<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 D1 A& o3 Y  h- @5 B0 Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' ?2 X/ e% s% k6 N
<P><FONT color=#0000ff>/* read result of initialization */ 7 x# r: q% ~2 _# E% g; W. S
errorcode = graphresult(); ' z4 Q, r" q, m
/* an error occurred */ 5 I/ J+ J9 H3 X- s
if (errorcode != grOk)
6 @1 L  y( H: X" c- W{ , Q  W9 m0 z& }; H
printf("Graphics error: %s\n",
5 J$ K* f' m+ e0 ugrapherrormsg(errorcode));
! y- o+ e% O0 c* Eprintf("Press any key to halt:");
6 [# S* x; S- j  b. q% G# R2 a- ]: dgetch(); - E: a7 W  E- f5 m0 b2 J* ]  c5 |
/* terminate with an error code */ ( G& t( z/ d  V9 G& d8 m0 U& x
exit(1);
. r% U2 U$ I+ W! }$ X} </FONT></P>" J2 C/ R" z& \2 y3 u
<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 L1 y- g0 R6 G' x
midy = getmaxy() / 2;
8 ^8 S* ~  v$ ?6 s4 }- D# \setcolor(getmaxcolor()); </FONT></P>
1 j$ O0 h/ c; W% O  Q6 ?/ H9 Y( W<P><FONT color=#0000ff>/* for centering text on the display */
! }) x/ u5 z5 b0 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>: S4 u6 M4 V, B! l4 W1 c
<P><FONT color=#0000ff>/* get the current drawing color */
3 c9 V" y$ q. j3 U( w( d% Jcolor = getcolor(); </FONT></P>
. _5 P6 |! ?+ D4 O3 {- o1 A<P><FONT color=#0000ff>/* convert color value into a string */
( X: S" h. @. @0 \itoa(color, colname, 10);
; s* L( o( ?: b. M/ H( c5 x- S% ~strcat(colname, - P; h3 i) y4 Q( N5 g
" is the current drawing color."); </FONT></P>
; H3 Y" S+ M+ K; t* A% k<P><FONT color=#0000ff>/* display a message */
  j! T1 X, g; b) F) @% I; }$ T% souttextxy(midx, midy, colname); </FONT></P>! a- e. V6 d+ d( W& `/ t: W
<P><FONT color=#0000ff>/* clean up */
- I9 \- g; ^8 |7 E7 Qgetch(); + o  a& X4 I5 L# y
closegraph(); * G1 z# q! s4 P
return 0; / j* K: @- W3 N. `2 q$ k( [
}
' z0 C( e# M! r</FONT># J4 p! _% m5 ^6 q8 p: d1 ]
</P>, a, [# L9 C( h. ]
<P><FONT color=#ff0000>函数名: getcurdir </FONT>$ n# |: H7 T& \" r  m4 J7 G
功 能: 取指定驱动器的当前目录
7 ]  m5 j% c, B! Y# I8 w& m用 法: int getcurdir(int drive, char *direc); $ W* R5 v# ]: v2 m% X; {! ?
程序例: </P>
. G- j! q: ?; `# D<P><FONT color=#0000ff>#include <DIR.H>7 G" l& Z# V! u! t
#include <STDIO.H>" ?; `, @( |# p: [
#include <STRING.H></FONT></P>
* R4 J# }1 }- P% Y5 s0 h' C+ [<P><FONT color=#0000ff>char *current_directory(char *path) " V2 }* i3 d7 P& ]
{ 0 i, S& Q$ ^4 a( i$ s  T
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ 2 C. b0 y7 f0 A* c; s
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
+ n: m0 X8 y8 a/ Q6 n$ Q+ f8 _getcurdir(0, path+3); /* fill rest of string with current directory */ 8 v! N- [& q( i* ~# Q0 c
return(path); 1 ^/ ^/ [9 p- c  N1 \& [. [
} </FONT></P>
; u" [- s1 |0 r7 D2 z+ f- u<P><FONT color=#0000ff>int main(void) ) w' t( t7 [* q) e4 E( C
{
! z7 N1 P( j9 Hchar curdir[MAXPATH]; </FONT></P>
+ I! \3 ~- _! t9 {<P><FONT color=#0000ff>current_directory(curdir); 5 E8 F5 G& R1 c! Q
printf("The current directory is %s\n", curdir); </FONT></P>7 [+ i2 K+ S" |9 B' b( [
<P><FONT color=#0000ff>return 0; 0 S; f) C* u; I- @$ q; J+ C4 d
}   Z5 X6 ]* p+ {* Z" R: M
</FONT>+ I8 Q; Q( r9 F; H' B9 F0 h8 K
</P>
+ e2 k. K: J$ o% h' C<P><FONT color=#ff0000>函数名: getcwd </FONT>, a. i7 w% r9 O5 `
功 能: 取当前工作目录
5 h$ T; [% ^1 \' ~8 F用 法: char *getcwd(char *buf, int n);
4 ~0 s5 i* a' H0 P7 L1 I( ~程序例: </P>
3 z+ [2 }8 }+ K5 b8 i<P><FONT color=#0000ff>#include <STDIO.H>9 t1 u- v' G4 p" C) V- E" P
#include <DIR.H></FONT></P>
- k( Q8 |. ?5 X, T4 T; b; U2 T<P><FONT color=#0000ff>int main(void) 0 c7 Y: L, J$ H/ `4 U; |) g% h7 E3 d
{
& w" B; j( @0 B( d8 S8 @( lchar buffer[MAXPATH]; </FONT></P>
: m6 r: b( w' c& D( g<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); : ^" ^* |: X3 x: w! B
printf("The current directory is: %s\n", buffer); : I4 j, _! |- m" o
return 0;
5 J3 v' u7 z2 Q0 n9 W8 }, Z9 v4 Z} </FONT>  x  L7 p5 J/ E! C7 X8 ]# a) U
5 H) l8 v- ^: P( j, B9 v! z6 [+ O
</P>9 e+ U. L! r0 c
<P><FONT color=#ff0000>函数名: getdate </FONT>: H, a& i6 E5 e
功 能: 取DOS日期 2 ?3 H% k& u2 a- _3 r- C- \; p9 s4 D
用 法: void getdate(struct *dateblk); ' f. ]5 i% x* }2 X% o
程序例: </P>
0 {: {* F/ R( k3 K, c! x) b- V- E<P><FONT color=#0000ff>#include <DOS.H>3 O6 t4 t, }8 A9 P
#include <STDIO.H></FONT></P>
# f. }2 D4 s+ }6 y# a& n9 V( d7 D<P><FONT color=#0000ff>int main(void) : [9 O* H% z1 Z4 Y+ p; ?+ v# l; G' |
{ $ h1 C) w5 W5 S
struct date d; </FONT></P>/ V) r6 J5 m% F5 R% {5 w5 U
<P><FONT color=#0000ff>getdate(&amp;d); & _' H; L1 I  }( D
printf("The current year is: %d\n", , P& F; _2 S; m2 \3 @
d.da_year);
, x+ ?; _( a6 @, N% _+ fprintf("The current day is: %d\n",
+ E" T! X6 k% id.da_day);
. H9 [" b8 O5 v' nprintf("The current month is: %d\n", - s( i( k7 _- q% v
d.da_mon);
2 X, {; s6 [* C3 d: J% Y$ Kreturn 0; ; k0 h  u; f% g5 C2 A3 V- m& q$ V# i2 N
}
8 Q& ?. J) a) E" I" ^</FONT>: e$ k7 ?- _" O$ o. R& a2 R9 E
</P>7 J2 u9 S: J' w+ Q4 s
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
2 J  h0 z; J# Z+ ]0 G功 能: 返回调色板定义结构
: O: z$ H. e& }' L3 c0 K用 法: struct palettetype *far getdefaultpalette(void);
" b  ?$ T! w# _/ B5 v' K7 M程序例: </P>
% ]9 @  S/ u. U- U2 L<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 i4 h* w: c. }#include <STDLIB.H>/ q( W' E% V% U) s9 i. v- K
#include <STDIO.H>$ ~5 B( f& P, |* R1 I0 |' O
#include <CONIO.H></FONT></P>
) y6 j- h6 D: X<P><FONT color=#0000ff>int main(void)
( e9 J/ p$ P! S% e, i{ 7 U% t' f/ A! G" b* Z
/* request auto detection */
2 @* w8 O- g* y" c2 Oint gdriver = DETECT, gmode, errorcode;
$ v; z2 q! l4 s  K  |( @int i; </FONT></P>
% ~5 i# o; ?# W. M3 ?4 z/ X<P><FONT color=#0000ff>/* structure for returning palette copy */ ( u: M- @9 S' V
struct palettetype far *pal=(void *) 0; </FONT></P>7 f/ H; A/ k2 |
<P><FONT color=#0000ff>/* initialize graphics and local variables */ * n2 w- F' x8 y( G
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ I( V) @7 b' T* h3 e<P><FONT color=#0000ff>/* read result of initialization */
0 G4 t% M+ r) @" F+ a( m$ Y1 Ferrorcode = graphresult(); : b/ q1 v2 n- U4 G
/* an error occurred */ # Z; F" N9 H$ X
if (errorcode != grOk)
% F6 Z7 @1 C4 o8 _! }& F{ . {3 n- h0 l" O9 n
printf("Graphics error: %s\n", ) k+ Y4 ?1 x' s- K% g
grapherrormsg(errorcode));
( K6 u  o) D" [printf("Press any key to halt:"); 8 e$ o  i  {; \, T9 `
getch(); 3 o  r' h7 P: h4 U( A3 j
/* terminate with an error code */ ( o) A& d( X; o
exit(1);
% Z6 D8 I6 G# S4 x$ M: n! S0 H} </FONT></P>0 b# s2 Y: J. _) `1 g/ K8 B1 ~
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
) Y% @/ I3 p  n9 E6 e  h<P><FONT color=#0000ff>/* return a pointer to the default palette */ , b' C' I! H9 t) S1 ^; o
pal = getdefaultpalette(); </FONT></P>0 J; w3 @9 A2 v
<P><FONT color=#0000ff>for (i=0; i&lt;16; i++)
* V; N/ n9 |+ P8 _* a{ / A! J7 M# a3 Q
printf("colors[%d] = %d\n", i,
( L. m1 h* d8 upal-&gt;colors);   G, R( I1 J, w) R6 c$ b
getch();
& ~1 w' u; Y8 e9 F6 ~; _} </FONT></P>
* i* N' A8 \: Y9 V% o) O# O<P><FONT color=#0000ff>/* clean up */ 2 c4 n; \  G4 s) P% B8 l" M7 X
getch(); 7 E$ U" ]4 _9 G% U
closegraph();
5 v) k1 P8 w! a) u% lreturn 0; 2 |5 |* r; ]% V! Y0 U: w. ]
}
3 a4 d' a4 ]- ^- i- c</FONT>
# d( x8 m; g5 k7 |6 f5 w  @! [</P>
' e0 n% l# }0 |<P><FONT color=#ff0000>函数名: getdisk </FONT>
6 F$ U3 F9 [! [+ z功 能: 取当前磁盘驱动器号 0 \/ d% X/ r% f
用 法: int getdisk(void); 2 r( e) J1 q# u( H4 S( Q
程序例: </P>' ?  D$ b' C8 A3 t& V5 t8 b7 c- e
<P><FONT color=#0000ff>#include <STDIO.H>
. z& V$ ~0 c" l: y# f# z#include <DIR.H></FONT></P>
# D0 O- V, x) e- p* N<P><FONT color=#0000ff>int main(void) * T) l& A: ^$ q: W
{
% B6 \  N% i4 gint disk; </FONT></P>
  s0 h* L0 ]  w, A<P><FONT color=#0000ff>disk = getdisk() + 'A';
' R6 G: U6 e' J/ H9 o) Gprintf("The current drive is: %c\n",
0 P% b. l# M8 Z' s: i5 n4 W2 {8 o8 Idisk); " g) y& s) L; @0 Q3 T7 ~
return 0;
4 M" j) F! l) I) @  C}
) |& [; z$ P0 g! E1 h
( J. d/ }. X2 d. D</FONT>2 b6 v. y' m" k6 }; H4 T
</P>) I. P  d2 U4 F- i! B: z+ X) z
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
$ P  J$ m0 m+ |+ P( n功 能: 返回指向包含当前图形驱动程序名字的字符串指针
' s' U, Q9 G$ k1 k用 法: char *getdrivename(void); 1 b) A* b2 {6 o4 L) h" G7 l& V
程序例: </P>: Z' C# b/ _/ I) G- u* }- p
<P><FONT color=#0000ff>#include <GRAPHICS.H>% \8 @1 t& m/ b! j+ T, [
#include <STDLIB.H>$ h! R$ ?: t! j4 l
#include <STDIO.H>4 W5 j5 |1 _) w# ?
#include <CONIO.H></FONT></P>  i7 t/ [  Z' w. \" u
<P><FONT color=#0000ff>int main(void) 8 i% W  F9 M7 X4 a+ u! S
{ 5 @, Q! N0 s# z: z5 Q7 b4 n/ D
/* request auto detection */ 9 ?# G  b% ~- I( `& R$ `
int gdriver = DETECT, gmode, errorcode; </FONT></P>( l; z2 W( |( O6 R! q$ N
<P><FONT color=#0000ff>/* stores the device driver name */ / u: z' j/ f1 e3 k
char *drivername; </FONT></P>
- g: X/ E! o" r& h: ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
, W; n6 t" ?. o  Ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ Q- J4 B1 O. o/ w2 a0 t. ~; T
<P><FONT color=#0000ff>/* read result of initialization */
" t" M) Y2 v4 R6 berrorcode = graphresult();
) S: O1 b% k  U5 a/ V/* an error occurred */
: n5 c  ?/ k; N2 [& g$ J* wif (errorcode != grOk) : M( B6 o: P2 w8 i0 _
{ 8 D4 Z; a2 T1 `
printf("Graphics error: %s\n",
% j' b: u2 O! |% E2 Wgrapherrormsg(errorcode)); 4 d0 i, R6 k. d6 H& p
printf("Press any key to halt:"); 1 Z* q* {0 V. ?( u! ?
getch(); 8 L" m7 M: {5 M
/* terminate with an error code */ 1 g: T1 f' D# X& Z
exit(1);   u* s. @  v5 V" ]
} </FONT></P>3 C# w$ w  k9 r1 Z
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>3 R2 \# T0 B% O( N6 E! Z% W
<P><FONT color=#0000ff>/* get name of the device driver in use */ ' ~- j( v  n, I1 }
drivername = getdrivername(); </FONT></P>
: z  P1 @2 F  L<P><FONT color=#0000ff>/* for centering text on the screen */ & u- x' B. f* t. r/ b
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
4 Q/ f& }1 X, g<P><FONT color=#0000ff>/* output the name of the driver */
" d$ q) Q3 g" y( {3 c$ n  e$ R2 e/ iouttextxy(getmaxx() / 2, getmaxy() / 2, + Y1 z% O" S, R* w5 Q
drivername); </FONT></P>
1 w$ S4 h' T# s. D- o<P><FONT color=#0000ff>/* clean up */ : j4 s% ]$ ^: y4 ^
getch();
/ V# f0 f2 t, _8 c- r+ Oclosegraph(); 6 G8 ?1 k: R5 Q8 v
return 0;
* n- V% F/ i2 h1 o4 I: G8 ~: o}
& @0 p% {! l: k. w3 H0 i, z</FONT><FONT color=#990000>( J4 G9 {, _& p9 `. `
</FONT></P>
# \& r2 c! K5 S3 t) V<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>" R% _- N1 Q4 O/ J' e! C3 [0 C
<FONT color=#000000>功 能: 取磁盘传输地址
: l: D) W' G* I0 Q/ y" ~用 法: char far *getdta(void); ) @& H, Y2 A! i$ o
程序例: </FONT></FONT></P>
* w8 M2 f9 r1 P3 Z/ H6 S1 L<P><FONT color=#0000ff>#include <DOS.H>
0 X3 G( o# ^6 I: g! N% z7 @#include <STDIO.H></FONT></P>
3 `5 d  F7 R4 Y<P><FONT color=#0000ff>int main(void) $ s) v- C# o4 J; f. p9 |
{ . l  X( ]/ h' K
char far *dta; </FONT></P># A2 D+ p0 ~3 p
<P><FONT color=#0000ff>dta = getdta(); % f2 \$ R! B8 I6 [3 |6 ?: a
printf("The current disk transfer \ 3 a* Q- B  p) e1 `
address is: %Fp\n", dta);
  \* f4 d. Q; i; v* R0 preturn 0;
* \2 b4 J5 }6 E6 H& z4 ^: ^4 |}
' s! w/ \# E- i  f1 h</FONT><FONT color=#990000>
& d1 {0 f! y! v# D$ ]# u</FONT></P>6 t5 x! b" D! h) t9 L/ ?6 {1 N4 i
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>( m" u$ t: {: M, \# I/ X, R# P" Z
<FONT color=#000000>功 能: 从环境中取字符串 6 ~" O6 p4 F8 ^9 s6 j1 S2 b2 C
用 法: char *getenv(char *envvar); : U4 P, D) O/ p8 \% j; Z
程序例: </FONT></FONT></P>- K9 B, I6 \. k/ _
<P><FONT color=#0000ff>#include <STDLIB.H>! p- J% L2 h# M! b! P
#include <STDIO.H>, O* H. k: w# ^) @6 ?3 X) l" Q
</FONT></P>
: }7 D; b& G: `/ r) L<P><FONT color=#0000ff>int main(void) ( e, K: H" ^4 C9 }/ }% q
{
* H! O  g' I9 U3 C9 ]6 ~. j. ^char *s; </FONT></P>
+ e8 ]! Q8 W, |. m: @' u<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
) L9 E* a' l0 x: Lprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>- p* Y2 G& e  ?+ F1 d. W
<P><FONT color=#0000ff>return 0; 4 g0 H; |& A4 o
} </FONT><FONT color=#990000>4 V: U, d; t7 I8 p- T# V+ }
4 F, n0 T" B. O
  G! N6 U4 p; }- o; S
</FONT></P>
& P! b" F8 z7 W/ J<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>2 w9 c1 n* }0 u4 j; \' C
功 能: 取文件分配表信息
- i* }+ l- x# j" t: L" q用 法: void getfat(int drive, struct fatinfo *fatblkp);
3 |$ [% N9 A$ c# R9 Q. B程序例: </P>
$ J( L+ h& R- _/ P7 n<P><FONT color=#0000ff>#include <STDIO.H>" f5 k0 V0 b: \' b; D; v2 m
#include <DOS.H></FONT></P>
$ k1 i; M3 ^! V- u# D# }! `<P><FONT color=#0000ff>int main(void)
1 c9 {4 e7 m& |- Z2 H: r5 L{
* ]& `+ B8 @8 N: z+ I0 hstruct fatinfo diskinfo;
3 q0 s  c% f: Z9 ^8 iint flag = 0; </FONT></P>6 }, J* j5 g6 ?) \2 w: v$ I7 v. V! k
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); : R( W& z5 ^6 B. t! ~
getchar(); </FONT></P>5 w6 X5 L( j; K6 t
<P><FONT color=#0000ff>getfat(1, &amp;diskinfo); 0 L6 x' k5 g1 G1 x. W  U' {, \
/* get drive information */ </FONT></P>
8 N5 g* ?( X4 p; U+ e& `2 ?' C<P><FONT color=#0000ff>printf("\nDrive A: is ");
# }3 V! X, U: R& y, }6 t1 ?switch((unsigned char) diskinfo.fi_fatid) % i1 o5 n1 ~1 q9 V* W' k/ E2 U; I
{ : I$ i* `! ]& }5 B2 x
case 0xFD:
2 S& e5 O. s8 Z; \6 Y9 O: p4 ^% ^printf("360K low density\n"); & J9 V; A9 D8 Y
break; </FONT></P>& U( b5 }( k/ T- m  ^6 L
<P><FONT color=#0000ff>case 0xF9:
! R5 ~, m# R5 J! ^& Jprintf("1.2 Meg high density\n");
2 W( L1 N& Y4 I8 g, _$ ?, rbreak; </FONT></P>
. r3 z) D2 ~1 T# x" A+ i8 R# m7 N<P><FONT color=#0000ff>default: 8 U0 n, X& \5 T" C& p9 N# y
printf("unformatted\n");
" `6 y5 H3 d1 |0 n0 ]1 Yflag = 1;
- ~* Q& X. D2 F, e0 y( x' n4 V} </FONT></P>
4 k# P: z- J0 J<P><FONT color=#0000ff>if (!flag)
+ g; U7 |* Z7 d) |% ^- m) k5 W/ }, C{
3 t0 Z# c- B* kprintf(" sectors per cluster %5d\n",
/ E: H, V( r5 s- p) Pdiskinfo.fi_sclus);
1 N7 m5 j6 J! _/ J5 X. c; N1 L* eprintf(" number of clusters %5d\n",
1 C5 f/ J" \( u9 q+ V/ ?8 |diskinfo.fi_nclus);
+ ^3 J! F2 J: r6 Sprintf(" bytes per sector %5d\n",   H7 d) B; n$ J2 @& X5 j( q
diskinfo.fi_bysec); # K# t" O0 k+ K) g8 s+ n
} </FONT></P>/ e* W8 M0 ?0 z# _
<P><FONT color=#0000ff>return 0; $ y5 \: Y8 L* J5 |! M8 A5 p4 ?
} 3 C9 n- Z. @7 C" m& R9 {
</FONT>
# P7 T$ I+ _5 h% \/ K- p& _4 {: ?</P>
- O/ P% w( }8 R<P><FONT color=#ff0000>函数名: getfillpattern </FONT>( S( Q. T1 c" ^; J; s
功 能: 将用户定义的填充模式拷贝到内存中
+ @( }8 z3 ~# g& p2 \用 法: void far getfillpattern(char far *upattern);
) w! i8 B3 C9 d4 w: h  J程序例: </P>7 ]# N  {- a/ @% u
<P><FONT color=#0000ff>#include <GRAPHICS.H>! B2 W, G, u; L
#include <STDLIB.H># K4 ]( A. x" R  L) o6 n* O
#include <STDIO.H>
9 Y3 C. [3 r; P1 B$ H#include <CONIO.H></FONT></P>
  |! q8 V+ q+ Z- d6 L<P><FONT color=#0000ff>int main(void)
7 H& J) r2 G; ]" S: s" m" t% ~{ ; \) f7 [9 `! m- {. b
/* request auto detection */
8 R, y, h  I' i( P. D5 l; E+ a" Wint gdriver = DETECT, gmode, errorcode; * G) [" u$ M8 J
int maxx, maxy; 8 h: n2 ^' h2 o' C/ U- R- m
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>' Q2 n  a  L& }% t  c0 S$ T0 l
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 y9 S+ F4 R( X6 ^
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ Y& W# Y% ]+ u; B. ^7 q<P><FONT color=#0000ff>/* read result of initialization */ . y0 _) _1 Z6 g; g; W
errorcode = graphresult();
# T; o5 `8 }3 i6 i, Aif (errorcode != grOk) /* an error occurred */
1 t# W+ d2 t7 A  c* @+ ^" \! d{
! a% a6 S" H% |; {, Z5 h7 `printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 S  v. g# i* p+ }+ V9 rprintf("Press any key to halt:");
# V3 l  |6 u6 h/ J1 sgetch(); * c: q7 C0 H; a4 B  Y
exit(1); /* terminate with an error code */ " ~/ I1 j2 ]0 c& x3 q
} </FONT></P>/ l% ]" w1 w7 N3 R: N( E: a0 i
<P><FONT color=#0000ff>maxx = getmaxx(); 4 v1 K+ W# g! i1 J) a
maxy = getmaxy(); % }5 P6 t% T3 f& \. a1 L2 Q) N
setcolor(getmaxcolor()); </FONT></P>
6 z! H) R9 r$ |, w/ D<P><FONT color=#0000ff>/* select a user defined fill pattern */ . c/ V9 b4 l1 B  M6 r6 V0 @1 |
setfillpattern(pattern, getmaxcolor()); </FONT></P>9 o/ Z2 O' X" J! d& G
<P><FONT color=#0000ff>/* fill the screen with the pattern */ / ~0 M" ^  s* v& d! B- _
bar(0, 0, maxx, maxy); </FONT></P>" m1 x) m# b1 P  C2 J6 y" O4 @. F
<P><FONT color=#0000ff>getch(); </FONT></P># s8 f# f3 f3 _1 V  X4 E6 a
<P><FONT color=#0000ff>/* get the current user defined fill pattern */ & [  d( E1 V4 k
getfillpattern(pattern); </FONT></P>, _7 W8 {. f' P5 d3 L
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
' m8 P% `2 w/ C8 Bpattern[4] -= 1;
1 i9 h' C- ?; e9 Z) vpattern[5] -= 3;
5 t+ W/ h1 z$ v$ l& H7 f% u$ G; Y+ zpattern[6] += 3;
$ B! t/ c8 n& spattern[7] -= 4; </FONT></P>
( j8 O1 @2 y! H<P><FONT color=#0000ff>/* select our new pattern */ 7 o% g! v2 Z# {+ n/ t  Z# Z
setfillpattern(pattern, getmaxcolor()); </FONT></P>
( ^/ g0 P+ |+ ?6 U5 T- Y<P><FONT color=#0000ff>/* fill the screen with the new pattern */
" d. p1 ?* S; E% pbar(0, 0, maxx, maxy); </FONT></P>
  S# Q. q* {( w" }/ |. h7 H5 `1 @& V<P><FONT color=#0000ff>/* clean up */ 3 G8 o0 x" r4 l$ o' W. @9 u0 ?
getch();
9 Y+ u( A, ^1 h, T  @* Hclosegraph();
6 X/ `  w* ], |$ e4 qreturn 0; # h$ J7 y* a8 y- R* d
} # X" X' A' R3 v5 S- b8 u( ?
</FONT>& o5 u( p; f1 U- w  [+ ^' \5 V
</P>
/ u; K" F; z8 m& b' B- |<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
+ q+ E0 ?, T, r% n0 `8 S$ X功 能: 取得有关当前填充模式和填充颜色的信息 * K) W4 I' a% ?0 {" u
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 0 n/ o, m, I, C& {+ V
程序例: </P>
7 @1 R8 e2 _: v6 {. q<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 l! X- _" |' M- V  E#include <STDLIB.H>
% S, f& L& d; x+ @6 u#include <STDIO.H>
1 f! J0 C% z6 S3 S$ C# y#include <CONIO.H></FONT></P>3 g- o) ?: N. V  O
<P><FONT color=#0000ff>/ the names of the fill styles supported */ 9 p; n+ d' P/ M  m+ b
char *fname[] = { "EMPTY_FILL", - W3 E3 k* C/ V# t) \, ?0 _, T; W
"SOLID_FILL",
8 a0 p" Y- B5 w) `  n"LINE_FILL",
+ T2 G- Q* A% S( n1 R8 I. I% [4 @"LTSLASH_FILL",
% S0 U) C7 L: b. s: Z7 Q"SLASH_FILL",
4 B' Z  ^. G/ `1 [7 z8 B' J4 \% P"BKSLASH_FILL", 1 i/ S+ x3 M1 |. f/ f& Y
"LTBKSLASH_FILL",
2 N0 Q5 Y! C% R" j& Q; U"HATCH_FILL",
( T- U( c# p. C( [  u$ ?; R"XHATCH_FILL",   u3 I; W& d/ ^- x' T+ j/ d6 [# z
"INTERLEAVE_FILL", ! R. N. y" M+ z* J2 |: R! z
"WIDE_DOT_FILL", ' S0 P5 E5 E, o# I
"CLOSE_DOT_FILL",
  w: W: U  p# K) s1 S5 K/ _0 B0 ?"USER_FILL"
2 u- M! \0 e" G8 _}; </FONT></P>
7 V+ Z/ ^( ]/ f<P><FONT color=#0000ff>int main(void) / P* ^- n* R# X
{ 8 y) k, i, S' K2 s, g  S
/* request auto detection */
" u1 z2 a% G# k  F! v7 ~int gdriver = DETECT, gmode, errorcode;
! Y# d# [$ g- S- M" fstruct fillsettingstype fillinfo; * }0 P1 E/ B# W" u1 `8 {
int midx, midy; 7 ?: P5 ?2 ]% o; O% b
char patstr[40], colstr[40]; </FONT></P>
  Y6 H2 Z- E6 o! ^<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ w  K0 K7 A! |5 Z0 Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 E% a5 H1 \. i3 U2 f<P><FONT color=#0000ff>/* read result of initialization */ 1 g- K1 W8 O! x, V
errorcode = graphresult();
4 O6 F2 }# Y! `3 j+ jif (errorcode != grOk) /* an error occurred */
& u: s- d2 O8 d: m8 O% Z- W- e- A{ ' Q/ w, _, w) b) u
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- s- ?' {, v  u  j- ~printf("Press any key to halt:"); 5 h# b& ?! ^6 `9 t% \7 w. g* u
getch(); % g6 g5 ]- V5 O( ?* ?9 X
exit(1); /* terminate with an error code */ . {- x% O0 p& R0 `! k) I. o5 I
} </FONT></P>
& [. a0 O9 T4 A$ W$ S<P><FONT color=#0000ff>midx = getmaxx() / 2;
' P% x: |5 x" f, }/ S9 V6 |midy = getmaxy() / 2; </FONT></P>
3 }9 z9 g/ s! G7 _# O  t<P><FONT color=#0000ff>/* get information about current fill pattern and color */ ' k6 ^( \0 s% x7 ^4 e
getfillsettings(&amp;fillinfo); </FONT></P>' q% ]) n$ q' j* M3 G
<P><FONT color=#0000ff>/* convert fill information into strings */
% [& M; g9 t2 ]: u/ e( [( ^+ X+ Hsprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); 9 ~; z' Y+ U0 y5 ]) Y  ^$ d+ n6 _
sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
7 o, M# }# X9 V' L7 V' W/ T  L<P><FONT color=#0000ff>/* display the information */ ; \$ ]! X9 p+ R! }
settextjustify(CENTER_TEXT, CENTER_TEXT);
7 T! l2 q5 }: E7 V8 ?$ n1 douttextxy(midx, midy, patstr);
$ t' g5 g7 }3 e  m/ p9 qouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
# }" E- D$ ^0 e3 j" T<P><FONT color=#0000ff>/* clean up */ ! Z! @' v% g! F; g. c
getch();
  @9 D) q3 k3 u7 k/ @' M* Uclosegraph(); ; Y; W6 ]$ k# F+ O+ D
return 0;
3 Z3 u6 [. t  ~8 O$ Y& u8 X' b8 S  y}
! y! c. P9 Y# M. |</FONT>
6 `9 F  I: {: B( H$ `* s! |7 I2 {0 c4 h" c# e! X" V* M
</P>
7 E  l* G, K! `<P><FONT color=#ff0000>函数名: getftime </FONT>* _9 V6 e# Q+ h; ^5 u6 K( p5 D
功 能: 取文件日期和时间
# V& e/ X" B& q$ ^0 y/ A用 法: int getftime(int handle, struct ftime *ftimep); 5 ^1 ]7 p# f$ j) H& ?$ V
程序例: </P>
: z* \, m7 |  P  L& ?, h<P><FONT color=#0000ff>#include <STDIO.H>' X+ Q2 K: E: q! {
#include <IO.H></FONT></P>1 [2 j' Q% u& q1 |$ I
<P><FONT color=#0000ff>int main(void) 7 E" i1 b: L3 t. }6 T9 Q$ }, r& V
{ 2 j; ]3 J6 _" e, F  Q* Q
FILE *stream; ( E. i! p9 i0 `  v8 R% u( E
struct ftime ft; </FONT></P>4 G6 |1 R% R# E" A6 F
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
. m3 ]. C( R$ K3 P2 C' J/ R"wt")) == NULL) * H# T: B4 s. U
{
# H1 U! `: O! y, `' gfprintf(stderr, ( [* l% c- _- ]5 n  r8 S% `( f, N
"Cannot open output file.\n");
+ [, H# X+ h, T+ i) Creturn 1;
  k; u0 _4 k' ^5 Q% S}
3 s' E/ n6 Y* e- Ugetftime(fileno(stream), &amp;ft);
4 ~( X& J( w8 |. `printf("File time: %u:%u:%u\n",
* f+ ]& U' m5 M* e' lft.ft_hour, ft.ft_min,
9 J" g( e% |: @, x6 Yft.ft_tsec * 2); 9 k8 X1 X' ?; ^$ v6 o0 l
printf("File date: %u/%u/%u\n",
, W& W. |  H5 z6 u7 J0 z, I1 tft.ft_month, ft.ft_day, 8 b: _/ ^! M& R  r, R' k, Y4 E% ^
ft.ft_year+1980);
  ~. p" f: X+ D: r/ bfclose(stream); " o% `* ]1 C! i( M1 C
return 0;
! t9 F/ z2 l' i6 b0 A& X8 m' j}
6 _8 l3 `# a4 U4 d6 T$ ?% V</FONT>
3 k) e5 Z$ m) d6 J8 ~- X5 r; B7 J* U' P
</P>
. c2 p2 y" J. n9 E& N<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
) t2 ^: z& T  A' J% V功 能: 返回当前图形模式
5 I1 a* o  k! A3 v. C+ E用 法: int far getgraphmode(void); + `9 {. m4 f7 G6 Y) D3 A" [
程序例: </P>
. ~0 n* A' }7 U9 X) @% A! E<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ `7 H6 G( X3 @% F#include <STDLIB.H>
, |" u4 r' H( f1 A#include <STDIO.H>( h3 g5 }5 c4 ^( H
#include <CONIO.H></FONT></P>3 ?6 V7 E  O6 U9 b: l! M
<P><FONT color=#0000ff>int main(void)
  g2 X; t- A; E  l+ Z" l! N. ]) Q{
9 N2 ~3 o6 p6 `- ?: t) m' ~/* request auto detection */ 6 \9 Z5 S/ O8 R8 W* D7 F
int gdriver = DETECT, gmode, errorcode; $ y1 ]" K8 L; x& B' E3 Z
int midx, midy, mode;
  L5 _2 Z9 ^& dchar numname[80], modename[80]; </FONT></P>9 n6 G: L- I) d8 w2 R, d  Y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , _4 m7 u' T9 Q% D
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 j6 D( E  r% z' |% \3 i
<P><FONT color=#0000ff>/* read result of initialization */ 0 V/ Z! ?; n1 {. i+ }
errorcode = graphresult();
" d7 }8 v1 F9 A& I) V/* an error occurred */
+ B3 w6 P# d: J; s3 G: T( Wif (errorcode != grOk)
! e& e& }4 d: b/ K) b, n- v{ 9 ]$ n. ^. V6 N6 H8 n4 V
printf("Graphics error: %s\n",
( ~) T0 j7 M% f' Egrapherrormsg(errorcode));
2 E# j8 N6 q( B2 N# ~* vprintf("Press any key to halt:");
+ l6 \9 k, ~0 hgetch(); 0 ]! @# I/ Y( g2 G* W
/* terminate with an error code */
. s) k* ~8 z7 i8 Jexit(1);
8 p4 C6 U4 `- m8 d  }$ ]} </FONT></P>& Z0 Z; j2 b& r4 g
<P><FONT color=#0000ff>midx = getmaxx() / 2; % j! i3 Y6 U( P! h+ p6 a: y% l
midy = getmaxy() / 2; </FONT></P>  `% P  u- Y" [7 b, Q
<P><FONT color=#0000ff>/* get mode number and name strings */
1 {* E7 {6 D! x) Q0 R6 q2 ~# ?mode = getgraphmode(); + ^; @! g/ J$ _1 D" F/ v& z( o
sprintf(numname,
4 i7 h! [. H% O) k. p7 I( O"%d is the current mode number.", . f# C+ Y: r" p" B
mode); 7 d( C0 K2 c. g. a3 A& z0 I
sprintf(modename,
5 {! G; B; {4 n% k"%s is the current graphics mode", ) _0 f: R5 d+ o& J
getmodename(mode)); </FONT></P>
! U# P5 j2 c, _0 n<P><FONT color=#0000ff>/* display the information */
+ }' Y4 v8 `% dsettextjustify(CENTER_TEXT, CENTER_TEXT); ( x* W- _* @3 u- r: }/ g
outtextxy(midx, midy, numname); ! X: h7 ]; \. s, Q1 `. e( V5 C
outtextxy(midx, midy+2*textheight("W"),
2 m+ B7 U: i0 d* L0 jmodename); </FONT></P>8 h5 E0 U$ j5 j& c2 @2 V
<P><FONT color=#0000ff>/* clean up */
& }  T' C$ H- t1 Igetch();
+ ^$ O$ e7 C/ U9 r" K9 ~( fclosegraph(); 0 N3 C+ K9 ]! D* E: Q- ~$ o6 h
return 0; / u. K2 O: q  `# m8 K9 v
} </FONT>5 k+ Q8 P) X2 C4 n- ^
9 D' j1 |1 n) @' E7 p) ?6 o- n
</P>
5 K1 ?* p2 {* G1 e% J* t<P><FONT color=#ff0000>函数名: getftime </FONT>; y3 d( y+ y/ p5 F+ D' ]
功 能: 取文件日期和时间 ; b( e8 g% K- T: Y: K9 i
用 法: int getftime(int handle, struct ftime *ftimep); 1 }( d- |( y9 U1 n- b, {2 y6 h2 N/ n
程序例: </P>
6 v" z  h' U' o, Y2 G4 I<P><FONT color=#0000ff>#include <STDIO.H>; o  {) V3 ~" n8 ^& h2 k, @9 X
#include <IO.H></FONT></P>
$ |+ e) u9 i+ s, t<P><FONT color=#0000ff>int main(void) 0 G; {, K! p1 J" F# N8 ^
{ $ l( c1 h' ~1 j' q8 D
FILE *stream;
! ?+ p/ |  m2 C5 w3 O) @struct ftime ft; </FONT></P>& t7 F2 w2 p6 t$ P( m
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
+ R+ b9 v0 ~( u4 I"wt")) == NULL)
9 g" \+ r$ P- L. M* v$ Z5 [( C* x) M{
! s, O( w8 b& O" d7 ^  o) H* s  T7 cfprintf(stderr, 7 v% _7 i& n$ @
"Cannot open output file.\n"); ' ]! n; I$ ]1 r! I
return 1; $ w. X1 g" J6 {
}
' a9 h; t$ z. }; N9 ?" D0 zgetftime(fileno(stream), &amp;ft);
9 I, F, M& d6 j  g4 }1 Gprintf("File time: %u:%u:%u\n", * l3 B8 |( ^% z
ft.ft_hour, ft.ft_min, 5 y! ]# d. w7 [" Z1 G  X- s
ft.ft_tsec * 2); 2 {4 S0 j% z7 o  L1 g: s7 l: A
printf("File date: %u/%u/%u\n",
2 U3 I9 |9 g: fft.ft_month, ft.ft_day, $ c. c8 B4 J0 }1 C9 b
ft.ft_year+1980);   a- L1 ?3 z6 H
fclose(stream); & F2 e2 q; e  C/ O  o1 ^4 g
return 0; 6 T" \( f: ^; h6 G
} </FONT>: ?- s6 Q& g" q: Y+ c& C

7 j3 N) k. G* X, H; E
6 X" p: N" p9 ]' S& [, Q</P>
+ g! d9 w8 C& \+ \6 e<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
" r  k0 E# g) w& h功 能: 返回当前图形模式
9 L  G6 f, D" [1 c9 w用 法: int far getgraphmode(void); 1 Q. K& z5 f6 W$ `! R5 m9 V1 i
程序例: </P>' B2 c% d) N3 p, `
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  G8 ^5 K# w' |5 B6 C# G#include <STDLIB.H>. `# ^# _2 y" p+ ^% a
#include <STDIO.H>
9 s, h' D' T: [$ j' D% X#include <CONIO.H></FONT></P>
8 u9 }. {( Y7 a7 e' d- r<P><FONT color=#0000ff>int main(void)
, w' `/ J5 b6 @$ u{
; [  n0 ?7 {2 o) a# `6 i2 D: ~/* request auto detection */ ) N; ^  }3 h! l& L& u) }
int gdriver = DETECT, gmode, errorcode;
& [. l  J% U& R. L8 c0 N. ^0 Y' Aint midx, midy, mode; * b  |/ B( T6 i+ j
char numname[80], modename[80]; </FONT></P>$ C6 t. e' v9 @* X: B5 Q
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# O, |$ C! g" b6 v1 Rinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ W. k) f3 O; K+ O* n+ T8 x5 X<P><FONT color=#0000ff>/* read result of initialization */
& D* y8 ~6 {1 r" j% Z4 e! perrorcode = graphresult();
% j  y  o! K6 ~) i' c4 a$ A. N7 J1 @/* an error occurred */
  ?% ~, D. P8 E- P2 Sif (errorcode != grOk)
7 h, r8 ~) ?( U) }{
) |7 I5 c2 r% O+ X. ^) Oprintf("Graphics error: %s\n", / o4 S2 |2 B2 K, c8 L
grapherrormsg(errorcode));
7 u. M* ?2 H1 M# V" @* u: h5 L7 dprintf("Press any key to halt:");
, ?5 y" r0 q( h+ ^2 z. ~6 y) cgetch(); ; v. R8 {9 y1 p  |' S
/* terminate with an error code */ ' o/ q5 Q7 W4 e
exit(1);
; i9 B+ y2 y9 {1 y} </FONT></P>/ G( B" R' p1 `0 c7 h9 I/ G3 W6 p
<P><FONT color=#0000ff>midx = getmaxx() / 2;
" J6 G  P4 ^/ e8 Y+ O! V5 Cmidy = getmaxy() / 2; </FONT></P>8 x$ p/ a: e8 B8 z
<P><FONT color=#0000ff>/* get mode number and name strings */
$ F1 H! B! Y6 K) H" [+ Q9 ^' Rmode = getgraphmode();
2 @' R6 i+ u5 J; l' C- p+ B6 Bsprintf(numname,
5 p8 P6 P  y( Z"%d is the current mode number.",
3 f# l6 P& v6 k9 h& a9 h# q* pmode); % p" E6 z( }  U$ U" E* C
sprintf(modename,
7 \1 r! j) s) D"%s is the current graphics mode",
; i. r  O% w' f* Agetmodename(mode)); </FONT></P>5 O6 z# T3 Q! D9 I- Q
<P><FONT color=#0000ff>/* display the information */ 4 D$ w% ], G- m$ p- Z
settextjustify(CENTER_TEXT, CENTER_TEXT); 2 G* Z, H7 m; _% x  P
outtextxy(midx, midy, numname);
; J5 q/ z: P8 O! Q6 {% ?4 Nouttextxy(midx, midy+2*textheight("W"), $ A# I) L* C' r" i3 l
modename); </FONT></P>; L: c$ h9 O2 D  {" P5 J# ^4 [
<P><FONT color=#0000ff>/* clean up */ ! t/ z9 `* n' k: Q# T" A
getch();
" V& ?$ l2 y4 C4 Mclosegraph();
' p9 [5 S. l0 T; P2 h$ B3 d4 A0 Hreturn 0; 5 p  B& B/ Z1 q- o" S# g0 w
} 2 G# O; G  j( D5 B' x
</FONT>' F- K: R- @  q* W- S; C( O9 M# b
</P>% _, ?9 N, f$ U  r5 u
<P><FONT color=#ff0000>函数名: getimage </FONT>3 w2 J( b1 y4 V8 Y6 P
功 能: 将指定区域的一个位图存到主存中 ' M9 Z  G% h$ K2 `% @
用 法: void far getimage(int left, int top, int right, int bottom, ! P' b. h( O) @; I, C/ ]9 \
void far *bitmap);
( Y2 o% N" z4 U5 D2 X: Z+ p程序例: </P>" Z; t2 y' y- X8 S3 ~
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" A. N2 L  N) j! w  h#include <STDLIB.H>% d7 s# r  f( s5 d! X& e3 }
#include <STDIO.H>
8 L! I- z, C3 j; `* ]#include <CONIO.H>
& C- ]  e7 b4 t" S/ n4 u$ U#include <ALLOC.H></FONT></P>
: V) E  `, [+ c" g4 f<P><FONT color=#0000ff>void save_screen(void far *buf[4]); 2 L# w4 U" g& ?2 R5 m
void restore_screen(void far *buf[4]); </FONT></P>
1 k& g# M) U1 S) H$ \<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
. e+ s& F) S  P) ^<P><FONT color=#0000ff>int main(void)
  K: ?! U7 E3 U" C9 u* i{ * T" O$ g6 P# {1 J
int gdriver=DETECT, gmode, errorcode; ( V: @1 a5 G- S
void far *ptr[4]; </FONT></P>
& |1 }) l1 r0 O, V. }5 g+ g<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
4 F% L$ [7 b5 P+ B4 pinitgraph(&amp;gdriver, &amp;gmode, ""); / C3 H0 C" E2 W2 |# m9 Z
errorcode = graphresult(); /* check for any errors */
! U0 M7 P, L* R8 n- B, G5 [- Sif (errorcode != grOk)
  m5 k, y  b" @' J0 j4 X! m{ " h* W* Q, s; j" q/ }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# @1 q1 x' Y0 ~) \3 }% g6 vprintf("Press any key to halt:");
& ^$ I9 k" f2 K7 I  Sgetch(); 2 ^; x7 d' `" j2 c
exit(1);
, O8 W5 w( n( j5 e}
: G# y9 l1 }/ U( W4 K6 n$ B! Kmaxx = getmaxx(); - d% ^: ]4 C( O* L- I
maxy = getmaxy(); </FONT></P>
! {$ o7 }" l6 j# Q* ~8 S+ A<P><FONT color=#0000ff>/* draw an image on the screen */ 9 C& g  [. i$ z7 K0 s
rectangle(0, 0, maxx, maxy); & J  ^% s7 h. f% k5 |
line(0, 0, maxx, maxy);
! o% ~3 h( Y6 n" f# H/ rline(0, maxy, maxx, 0); </FONT></P>
9 g5 |! l4 d7 S4 v<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ - }3 C) l# C- X1 i
getch(); /* pause screen */ 2 E% j* ]. Z; E0 L5 b, [
cleardevice(); /* clear screen */
" U- |6 w$ K% V7 R& V" _& V8 h% O1 Erestore_screen(ptr); /* restore the screen */ / Y3 ^5 F  u, ]# B
getch(); /* pause screen */ </FONT></P>; G# n4 b0 S& c! _
<P><FONT color=#0000ff>closegraph(); % z8 _% q! U; [" w
return 0; % d1 N! W) X5 C# |) W
} </FONT></P>1 f/ r4 Q: z" ?' m+ g3 J: s! g
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) , \. C$ N) r. Q8 k) W* D2 G
{
- B3 m- E+ o) m( N) q1 Zunsigned size;
" Q( n6 ^' G) _4 _int ystart=0, yend, yincr, block; </FONT></P>' t1 ]% S0 X& J, @/ W# D* C
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 8 @4 U6 `9 x8 g  O7 S% J
yend = yincr;
1 ?- {! X0 e. ~/ i+ isize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
& S3 y4 q- o% \( F: N- V$ Y+ W<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
, y$ c% E/ q" _( X  w6 S0 i& {& V{ ; s- N) z' ]& x$ i+ l( f
if ((buf[block] = farmalloc(size)) == NULL) / B; |4 E5 |% e0 b0 \
{
. ^% Y0 N9 n( w: m/ W0 n) cclosegraph(); # m3 Y8 \5 L+ _3 z" p/ l
printf("Error: not enough heap space in save_screen().\n");
( z8 Y( @2 y4 C; C5 g, j0 mexit(1); 7 T( G# g( Q. C$ t$ g
} </FONT></P>! E" K( y) z+ l& o7 @
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); / T# n6 Y  Q0 {4 \7 G+ Y% U
ystart = yend + 1; 8 v7 O: u& h# @/ }8 D
yend += yincr + 1; 9 l* f/ m" Y# {7 q
}
% U0 s( Q. j$ z0 ^: \* H} </FONT></P>; @. L( w! d" g
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) , w" A: M4 E% M3 F
{
( W) e- U9 H' Xunsigned size;
5 a% O1 r' _* Mint ystart=0, yend, yincr, block; </FONT></P>% B9 z0 c* _* D  C# }
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
) M* H! q) u# |5 k6 E; W# g5 o: vyend = yincr; + V  v3 Z. Y' T$ s2 g* j3 F) B  Y
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
- ^! F3 N: C8 E/ A# ]- q& |<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)   u) V1 [* ]( K
{
5 V& G, z5 r2 p9 fif ((buf[block] = farmalloc(size)) == NULL)
6 O% K2 v) q+ c. \{
) K" J/ D+ T3 a4 @7 G% Bclosegraph(); . k- n! Y0 C4 K3 i7 V
printf("Error: not enough heap space in save_screen().\n");
  ~7 U: a5 @4 A$ g; nexit(1); $ u1 M$ q' i: `- c9 a
} </FONT></P>
& y2 _& c* I( v  J  K% h  ~<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); 5 V" G' o2 g% ~* d+ j% q
ystart = yend + 1; $ t+ p1 m! Q- ~" v6 j
yend += yincr + 1;
. A" Y/ b* r$ H$ d9 K4 m3 [} # T7 l5 ?2 ]. Y7 @0 N
} </FONT></P># C" J" B3 Z% O* i1 s
<P><FONT color=#0000ff>void restore_screen(void far *buf[4])
# q- F1 \7 b8 B3 F, Y' h{ 3 P! \6 s6 q" D: i
int ystart=0, yend, yincr, block; </FONT></P>* O: m+ ?" }4 P8 R3 s; J% t4 z
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; , h' }' O6 r4 }' Y5 B* |
yend = yincr; </FONT></P>
$ b& B; Y) V3 L  N* Q<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) 6 {/ F7 W% O$ L' d/ O
{
% Q  C, i2 K, K" X! B5 R7 u/ ]putimage(0, ystart, buf[block], COPY_PUT);
- I" i, c8 @1 m. |4 K1 \  Dfarfree(buf[block]); 0 X+ O0 y' p; w) d
ystart = yend + 1;
+ W* k; K+ x( c0 ^. cyend += yincr + 1; $ q! A3 g2 i, B0 X& o6 _5 B
}
" w1 s0 ~+ I: X1 ]  u- z% ?} </FONT>
" D; B" E4 y# a6 w3 B  P! f<FONT color=#ff0000>
( B- Q7 }& s$ X</FONT></P>$ R8 V# H3 p  j5 o7 u7 G
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>+ z/ e4 b3 ?+ y/ P  v6 P5 ^
功 能: 取当前线型、模式和宽度
, `$ u, p: A$ p. J2 H' [: ?& `用 法: void far getlinesettings(struct linesettingstype far *lininfo): 4 n$ n* O( ]  M! z/ @. ]
程序例: </P>; m# c/ q/ p) ?+ C
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: x6 p- i1 K9 q) ^9 j#include <STDLIB.H>$ G% I9 f: ^5 g' }: _1 k' [9 Z/ F" Z4 H
#include <STDIO.H>' C8 W/ s0 d: u- W
#include <CONIO.H></FONT></P>+ |2 z$ v/ E+ L" s
<P><FONT color=#0000ff>/* the names of the line styles supported */ ; `2 X# P, r3 a* Y' X
char *lname[] = { "SOLID_LINE",
* p0 L7 ?( i3 ]% i, h' O" L"DOTTED_LINE",
+ b. N- f  U9 y( w8 d* @% M2 o' S"CENTER_LINE",
0 T+ t' h$ N. y2 J9 }- n"DASHED_LINE", 0 O! @3 O" a9 s. O2 c
"USERBIT_LINE" # r$ i) L  ]4 ?! E; o
}; </FONT></P>- R5 G1 X3 ^1 v' y$ P. H0 y
<P><FONT color=#0000ff>int main(void) ! W  }0 g6 ^0 `
{
' `; ?3 Y3 {& N/* request auto detection */
: s3 J' p. n& \# H" X8 xint gdriver = DETECT, gmode, errorcode;
1 u+ j0 b! j' j# ?, _% Vstruct linesettingstype lineinfo;
  x2 ?; a7 {: i* Pint midx, midy;
1 t' h; L, H* w( zchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
: M- {6 J( X( u: }: W- C<P><FONT color=#0000ff>/* initialize graphics and local variables */
# a$ H3 Z/ t- I# q3 hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) S# }3 p+ F6 m' w5 n
<P><FONT color=#0000ff>/* read result of initialization */
5 ]# U7 p; z* W4 k: j1 T9 S1 r* Cerrorcode = graphresult();
2 h; j  z% I. K, m  M% |if (errorcode != grOk) /* an error occurred */
4 f* P$ h' i' u{ * v; n1 A" L% P+ y8 u, R- N
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 R7 k$ o- t, L
printf("Press any key to halt:");
, _6 _0 z5 G3 [: zgetch(); * l+ Q' X/ y/ i
exit(1); /* terminate with an error code */
$ a. O% d. E2 e} </FONT></P>
: e1 r. T2 h  W2 l# o<P><FONT color=#0000ff>midx = getmaxx() / 2; - W; R- M# I  p0 c0 E
midy = getmaxy() / 2; </FONT></P>
1 r  h/ T' M3 v; o<P><FONT color=#0000ff>/* get information about current line settings */
% h* @7 ~4 y. o2 Sgetlinesettings(&amp;lineinfo); </FONT></P>% h) b' q" N0 m1 G! B, `
<P><FONT color=#0000ff>/* convert line information into strings */
5 ]4 E& C% W0 x* [sprintf(lstyle, "%s is the line style.", ( A9 T" u' V% s' h5 @
lname[lineinfo.linestyle]);
% n+ Y; Q" f5 l. R) isprintf(lpattern, "0x%X is the user-defined line pattern.",
9 D! a. |+ `9 t, _9 a: Blineinfo.upattern);
+ W) ?" ^2 `% h9 i" Q% V+ Z- hsprintf(lwidth, "%d is the line thickness.", 5 H8 t$ ]! H, g& T+ C3 O8 l# T7 E+ u
lineinfo.thickness); </FONT></P>: O9 {: l9 n' @# p+ G0 J
<P><FONT color=#0000ff>/* display the information */
+ J2 r3 x; P! @! o( E4 ?settextjustify(CENTER_TEXT, CENTER_TEXT); $ A; j* B' N6 u; E+ h9 J- x
outtextxy(midx, midy, lstyle);
# Y- ~% j4 j  q* kouttextxy(midx, midy+2*textheight("W"), lpattern); : Q* O$ ]; _' B- L* `6 z
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
! l) n& `" C$ N# ]<P><FONT color=#0000ff>/* clean up */ , g7 G$ g  S7 F$ P
getch();
' h+ \) r1 c; G7 zclosegraph(); : d" [% B2 i9 P* }
return 0;
  S4 s1 Y% Z  _/ d  B} </FONT>
' W! J- v9 ]- V* E7 T0 }
" N4 K9 C& Q( {+ j3 [, g</P>
9 g9 @9 T% B9 S( c<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
7 C0 l, O6 ?% p; ^功 能: 返回可以传给函数setcolor的最大颜色值
* O, @3 d2 s1 I, U; v% T/ r/ @用 法: int far getmaxcolor(void);
5 p& ^7 a  f) V0 `6 K程序例: </P>
7 s/ I: _# {. g6 k- x' K<P><FONT color=#0000ff>#include <GRAPHICS.H>
% j; S' x/ {' g+ n; ~7 g#include <STDLIB.H>
& J9 b5 L. y% S* n. x# h#include <STDIO.H>
+ i6 A1 j; w9 P#include <CONIO.H></FONT></P>* ]/ G% Y& K) S
<P><FONT color=#0000ff>int main(void)
( _4 Y" q1 R7 i: i* V: q! i{
/ [( W# ]2 D# O/ r: @/* request auto detection */
6 r2 q' s( B$ R5 V/ Rint gdriver = DETECT, gmode, errorcode;
" i! ~7 g$ c8 c- K6 W! B4 T3 |int midx, midy; + V5 z$ n, k$ f1 j! ?8 d
char colstr[80]; </FONT></P>$ j: D1 w, {9 o! F! {* ?# ?
<P><FONT color=#0000ff>/* initialize graphics and local variables * @+ q8 v2 Q& U# [  U
*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 i& [( i2 Y) i* p) o! g
<P><FONT color=#0000ff>/* read result of initialization */
& l1 @  I  R/ ^& Cerrorcode = graphresult(); + q; m1 G* a4 z9 y4 s. J
if (errorcode != grOk) /* an error occurred */ , {0 Y! \2 r2 x# D" \; V, P
{
; i) _3 @* V/ A* j- y5 Nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
5 v9 j5 g( Q7 d* ~! r! B. _9 Bprintf("Press any key to halt:");
3 @  i" ~5 R% qgetch(); * `  y. w3 e8 b) R2 z
exit(1); /* terminate with an error code */
& R% _5 n- l. W# c1 u7 l9 B} </FONT></P>6 K- k  G9 P' g* n( Z, `; v
<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 ]! b: C+ q- O4 C, D
midy = getmaxy() / 2; </FONT></P>
- k6 T$ A/ l. ^  D1 d8 X0 Z<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ ; D) o/ p# C: d) X" y/ b
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
1 A/ R  T0 y& N* ?0 `<P><FONT color=#0000ff>/* display the information */
9 f3 Q) o! y& j* D2 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); 1 Y2 V( ^0 C+ Z0 K, H
outtextxy(midx, midy, colstr); </FONT></P>
  p: g7 X5 G1 T; s0 h: m1 O<P><FONT color=#0000ff>/* clean up */
7 \- j: C% [# [/ y8 bgetch(); * M- V6 _* m; y4 R5 c0 W( \- Q
closegraph(); % G# s9 h( J1 D2 `" e3 G
return 0;
+ {4 F% ^. _. P% a} </FONT>
% x2 L0 f1 D7 N3 y, d8 X" X% s+ J7 H8 w& h" t8 U$ {
+ G  Y) I& F& P4 q2 \; k+ T
</P>
. V! j% l  Z0 A9 e+ n3 z, e0 X<P><FONT color=#ff0000>函数名: getmaxx </FONT>
8 S- H" k8 s4 i3 h功 能: 返回屏幕的最大x坐标
) b) \! V  a5 ?! W. W用 法: int far getmaxx(void); - I' K1 A- b7 [- V/ E
程序例: </P>! e  j' ]6 R9 l' |
<P><FONT color=#0000ff>#include <GRAPHICS.H>! Y  |, u6 ?& K6 \$ p' t! f7 Z
#include <STDLIB.H># n+ H" b# r$ N% d
#include <STDIO.H>1 K  i% a& n- E( j& h9 ^; Q
#include <CONIO.H></FONT></P>5 I' g3 j, o4 J6 t
<P><FONT color=#0000ff>int main(void) 7 k! v! D2 q. c4 G5 Y
{
& d, q6 D  M$ r; r4 s9 k/* request auto detection */
. _; L* L, G# p" Rint gdriver = DETECT, gmode, errorcode; 0 v$ ?9 m, P7 ]) Q
int midx, midy;
( A) b: G! E8 R# Y  ]char xrange[80], yrange[80]; </FONT></P>6 W# H; U4 m. l7 V& O/ V
<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 Y, J- d8 H) }  y2 Q  c+ Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ }+ W$ X& p. i<P><FONT color=#0000ff>/* read result of initialization */
9 r& b$ W" Z/ U  Z7 Werrorcode = graphresult(); 6 I: Q3 r3 s" j6 w
if (errorcode != grOk) /* an error occurred */ # g1 x8 J& C% e
{
% J/ }+ t4 W% Y$ {% p& A7 r' @printf("Graphics error: %s\n", grapherrormsg(errorcode)); % K. I" k9 r, Q8 T
printf("Press any key to halt:"); - Z" ]2 t7 T. s4 a- M) f: I
getch(); # H) X! f% U2 L* c* t8 ]
exit(1); /* terminate with an error code */
/ F4 r) I: B! G/ E* {} </FONT></P>4 B3 _7 v" j& Y; f1 T
<P><FONT color=#0000ff>midx = getmaxx() / 2; 3 L3 E- @2 R* q, j) n
midy = getmaxy() / 2; </FONT></P>
( ?+ ?+ z: r7 a' H9 z<P><FONT color=#0000ff>/* convert max resolution values into strings */ 0 o7 }5 M$ ?( ]* W  Y4 c! \) o
sprintf(xrange, "X values range from 0..%d", getmaxx());
; a9 {' }. p5 t& Bsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>0 ]: l' [2 i- x7 J+ A) f7 t" S& y
<P><FONT color=#0000ff>/* display the information */ ' B# Q8 `, j  C% Y* F: X" E
settextjustify(CENTER_TEXT, CENTER_TEXT);
/ H  L2 t/ y+ Pouttextxy(midx, midy, xrange); 0 u7 L/ L' ~1 s
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>  T9 U+ e8 ^/ m7 k
<P><FONT color=#0000ff>/* clean up */ & `5 H5 f, ]* c9 C1 w+ [, C: ~
getch();
1 d. A3 q& I4 T4 I+ U3 Fclosegraph();
9 I: v9 t; m* d% n5 h) nreturn 0;
+ ^" B" @9 C; N4 n4 q}</FONT>
2 P. y% _/ ]* s0 X/ k$ r: D$ d/ @6 N4 W! _( V0 O& }
</P>8 _. m. b; s0 `, b
<P><FONT color=#ff0000>函数名: getmaxy </FONT>3 `" U  J2 X  X; g" a2 Y
功 能: 返回屏幕的最大y坐标
3 Z# d7 T5 N5 j) ^6 t8 G用 法: int far getmaxy(void); " x# k! o! r" U' H3 N# [# ~
程序例: </P>' a8 w3 H6 c" o1 X! `, X9 Y
<P><FONT color=#0000ff>#include <GRAPHICS.H>2 B7 e2 W! l* r0 Q  w& v$ z2 y
#include <STDLIB.H>/ T/ U1 v$ d* T* s# ?3 ]
#include <STDIO.H>- u8 }$ D! U. X- @# b
#include <CONIO.H></FONT></P>
* P+ o% [1 X( d- A# y<P><FONT color=#0000ff>int main(void) 1 ?# j1 N$ M% }" B/ H, I  k" s* \
{ 6 Q% s+ `- w) f6 ], L6 k$ t
/* request auto detection */
6 a) C. r" q( m# o2 Mint gdriver = DETECT, gmode, errorcode; : K/ B" b. u: _
int midx, midy;
! m5 T! g, Z& Z3 @7 u8 P5 ]char xrange[80], yrange[80]; </FONT></P>
+ ]  I0 G  G) A5 |<P><FONT color=#0000ff>/* initialize graphics and local variables */
. n. A4 N1 c8 [& i* I4 H3 F# g7 sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ y" {- D9 A5 X<P><FONT color=#0000ff>/* read result of initialization */
/ p  @/ N. d: I: L$ verrorcode = graphresult();
; g  s. v% q; B4 p  Sif (errorcode != grOk) /* an error occurred */
" Q. w* q" E( Z3 X9 n) N( U4 r{ . C, w' Q/ N5 w9 O( A8 u. B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 H& K" S4 W% w1 qprintf("Press any key to halt:");
& _- g. w: s# v- E0 z( Q. [4 Bgetch(); ( r! ?$ @; z. i) W, I
exit(1); /* terminate with an error code */ 8 D/ L) L3 }% i8 j: U+ h; J0 n
} </FONT></P>
- K- |( i/ A  \# |5 P# y<P><FONT color=#0000ff>midx = getmaxx() / 2; / M3 E9 }& o7 N- s" O" L
midy = getmaxy() / 2; </FONT></P>* [2 t1 M& n9 I  r( i
<P><FONT color=#0000ff>/* convert max resolution values into strings */
' d! G% T: G" }0 Asprintf(xrange, "X values range from 0..%d", getmaxx()); 4 k( y6 C5 d: I: {: X
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>( m. a. a. |7 z9 a  U  N( |- i
<P><FONT color=#0000ff>/* display the information */ . f3 j0 J: p2 H* s2 x/ K$ g8 }
settextjustify(CENTER_TEXT, CENTER_TEXT);
2 o- |' N8 l0 h6 P0 houttextxy(midx, midy, xrange); 3 t+ m4 j8 o5 q
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
$ Z$ r& Q* n% ~5 p<P><FONT color=#0000ff>/* clean up */ : q: J3 J; }9 t1 h
getch(); 9 T" B6 A4 ]! ~) ~  s% n6 E
closegraph(); 3 {3 s7 ?0 X8 b9 F
return 0; ' m6 G3 g7 L1 c! P1 y7 g
} </FONT>$ p0 o; N, ]6 z
</P>
2 Q' \1 x& d& T6 j7 R( i1 R5 }<P><FONT color=#ff0000>函数名: getmodename </FONT>/ u, F1 C) @  r( L) I
功 能: 返回含有指定图形模式名的字符串指针
( D+ f) U4 g" P# O2 J) i: N用 法: char *far getmodename(int mode_name);
' ~: o- `% a4 I+ L# @0 c程序例: </P>, H' u6 J- o5 j; U! r
<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 j7 u* ~2 c5 S0 s! ~: G6 ^#include <STDLIB.H>3 C( P: W5 D& ^3 Z/ q. S( Z; f9 e
#include <STDIO.H>
4 b# q5 q5 ~, Z4 X#include <CONIO.H></FONT></P>
6 ^0 B. w+ E4 G' E. Y5 w4 n<P><FONT color=#0000ff>int main(void) 9 ]2 ?) G5 S5 R4 j6 L) ^
{
: v; X4 O5 o7 Z. k/* request autodetection */
5 ^  W# ~' c- h1 Zint gdriver = DETECT, gmode, errorcode; + `8 J  w( p0 S% m
int midx, midy, mode;
6 q; I( ~4 l* Gchar numname[80], modename[80]; </FONT></P>
  I" B+ l$ }0 N: ~<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 W, j# y9 L) @! |" Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# V7 e" v0 y; P) [( x% L6 H6 @<P><FONT color=#0000ff>/* read result of initialization */ % }( w( a! b' Z! E. n: ~  f
errorcode = graphresult(); 1 l' R+ z6 l# `- j# ]( n' C! d- C& M
if (errorcode != grOk) /* an error occurred */ 8 a. c3 }* R+ ], \$ W* `0 M7 m- h
{ ' g! M) ^* [- F3 ^5 C9 I
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' F% s  O( U  _4 Q% {
printf("Press any key to halt:"); + X6 A7 H8 n' K  J" c" E& }* y
getch();
. S6 p- y$ S# D$ Bexit(1); /* terminate with an error code */ 1 g$ e7 D: y* D$ b
} </FONT></P>
1 w+ Z( e6 A3 _1 k* ]% x<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 Z8 z4 I" q: Z6 u- j. T6 O- t( e1 Zmidy = getmaxy() / 2; </FONT></P>, I  G6 \& {1 w- c; ^# Z
<P><FONT color=#0000ff>/* get mode number and name strings */
- C$ K& Z' x( {1 Bmode = getgraphmode();
; c  T4 {7 ?- p: i6 Gsprintf(numname, "%d is the current mode number.", mode); . T& p; S. B# v/ ?! e2 A
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
1 y) R7 j. f! P; y1 Z! J<P><FONT color=#0000ff>/* display the information */ % ]" ]. E* O1 y, Y
settextjustify(CENTER_TEXT, CENTER_TEXT); % X/ _/ j9 H' J* e6 |5 k+ o2 f
outtextxy(midx, midy, numname); 5 P8 @1 N3 l9 }# T$ Z" f
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>" d! J+ i" N: S# v* J* L; D
<P><FONT color=#0000ff>/* clean up */
" s- Q, r* {; L: m, t! C  M. agetch(); ' A$ |( @" o% J/ P* T) I2 x5 I
closegraph(); / |% g1 M. D* t2 B1 O' a6 }. y
return 0;
- k$ h$ |  m8 j, n; U1 a7 w} </FONT>
) @# w( x7 H0 m( D; E1 w1 c
& E- b8 r, o7 _( i</P>1 S: R" n0 h% q  {/ I7 H3 Z1 b) p
<P><FONT color=#ff0000>函数名: getmoderange</FONT> " j0 n3 V3 s- A) H; u$ B/ ~. J" n: G2 P
功 能: 取给定图形驱动程序的模式范围
% K7 n; @: ?' p3 a用 法: void far getmoderange(int graphdriver, int far *lomode,
& l8 k0 l+ ?: @$ z* oint far *himode); - U$ i% u, l+ a7 _0 N% r
程序例: </P>8 f, l6 o, `% i! y: s' a
<P><FONT color=#0000ff>#include <GRAPHICS.H>5 l/ K; }4 p" ~& ?1 |
#include <STDLIB.H>
$ s- X4 a1 n9 H: X#include <STDIO.H>
5 [# x; M+ h1 K9 Y- A) t4 [; ?2 s2 k#include <CONIO.H></FONT></P>
% a" ^1 C0 r% X9 t8 J<P><FONT color=#0000ff>int main(void) 5 L0 g0 S/ L( u* I0 @
{
9 w1 h2 K* D$ s9 v' ^/* request auto detection */ 9 ]* {0 i  \; ?9 J
int gdriver = DETECT, gmode, errorcode; " s# U" X) t6 i1 D: w: D
int midx, midy;
/ {+ a  j$ P  R$ pint low, high;
4 {/ J- P1 M; Dchar mrange[80]; </FONT></P>
7 H" R+ P0 w7 |1 c<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 i+ r% c% [# F/ x3 w* V3 \  S+ D
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 u( _  F) _' }. p& r1 R" B- }* {/ {* f& w<P><FONT color=#0000ff>/* read result of initialization */
( N9 {5 Z. s" Berrorcode = graphresult();
9 u( ^  d/ h' ~9 }8 c& \8 Jif (errorcode != grOk) /* an error occurred */ 3 ]$ x1 U- p0 G3 W% }3 l
{ ; a; e# g4 Z' X3 N5 h
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 w- j* U9 N' ^& c, O" Iprintf("Press any key to halt:"); 8 p7 s, v1 a0 j
getch(); ! A/ l% r' t. s$ p
exit(1); /* terminate with an error code */
' d; Q- k( A: Z} </FONT></P>3 }1 Q( J" }& N, a: o4 @  o
<P><FONT color=#0000ff>midx = getmaxx() / 2; 9 D. s& h5 x9 G& i% V
midy = getmaxy() / 2; </FONT></P>$ e" m" A8 [- j; F9 @% c, w
<P><FONT color=#0000ff>/* get the mode range for this driver */
# Y3 S; W( H4 d" Ygetmoderange(gdriver, &amp;low, &amp;high); </FONT></P>
8 C! Q/ n1 k) P8 S$ f7 t<P><FONT color=#0000ff>/* convert mode range info. into strings */
. e  k. A1 a5 osprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
. x: C1 |# g/ W% z2 N<P><FONT color=#0000ff>/* display the information */
0 U7 `8 ^8 |$ {' ?: j5 J1 R" msettextjustify(CENTER_TEXT, CENTER_TEXT); 0 n7 `/ ]: l0 N7 ]- a. o
outtextxy(midx, midy, mrange); </FONT></P>" o5 x$ E1 o( u7 ]
<P><FONT color=#0000ff>/* clean up */
2 x$ L" L# r% M$ |6 V- C5 M  zgetch(); 5 s/ @4 G, y* [1 x9 X
closegraph();
3 r* @' K0 N) [/ Preturn 0; . u& E2 ]) @; y9 g, s
}
" z7 W4 M. m5 T% ?4 N</FONT>% p# {' n2 o0 w) k; ?
</P>
. W1 \0 P7 p$ E; A& s$ Y/ E# H<P><FONT color=#ff0000>函数名: getpalette </FONT>
8 U8 b+ n1 b8 A9 R4 ?功 能: 返回有关当前调色板的信息
9 ~* g+ l0 V8 J& l3 @6 O用 法: void far getpalette(struct palettetype far *palette); 2 I4 j0 @5 b4 K! `8 F! n5 o
程序例: </P>4 _' u; \/ O3 J
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 v* `) g1 z! _6 I# u2 u0 F
#include <STDLIB.H>
8 l  ]# Y/ m8 ]#include <STDIO.H>
+ e8 j/ w. R+ u! }% i#include <CONIO.H></FONT></P>
+ }* a, l4 G. f, d8 k2 g5 E. C<P><FONT color=#0000ff>int main(void) 3 n  Q3 `$ Z. C* ^6 U& c
{ ; E' V6 K' `% a4 F( k
/* request auto detection */
% x" ^4 D+ ^$ I" z9 t; }( k! Y7 aint gdriver = DETECT, gmode, errorcode;
" E2 T: u$ T1 {/ E4 a# }struct palettetype pal;
7 S5 _1 S) F3 X& M6 }char psize[80], pval[20]; * b1 {5 u2 L7 Z
int i, ht; " {8 c( {& E& f  N* }3 k( k; d! S& R
int y = 10; </FONT></P>
. \+ }: Q8 a1 x<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 P( S& ~4 R6 Y7 N) W  u5 s0 ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>' {  y  z  d9 K- ~, k
<P><FONT color=#0000ff>/* read result of initialization */ ( r; D2 i, v; |& V- e
errorcode = graphresult(); ( H& ^  }  g7 B0 w% l
/* an error occurred */ $ g$ m+ J. i$ X# _
if (errorcode != grOk) : P. `1 q1 N" m6 u. W4 ~( S" r! V
{ & W% m: a2 a# h' S! M+ U
printf("Graphics error: %s\n",
8 s0 b# A6 i8 h4 mgrapherrormsg(errorcode));
; }0 m) t% h6 Gprintf("Press any key to halt:"); % _: X  m. R3 z
getch(); 1 o( ~9 r6 m* D1 e' l
/* terminate with an error code */ - l7 u8 H; N% j8 A# I
exit(1);
2 x$ w3 e/ y, ?+ i6 b. n} </FONT></P>
4 H7 q0 W* v& f. I" R' ~4 s( a<P><FONT color=#0000ff>/* grab a copy of the palette */ ) `7 n4 D8 B3 S( B, o. v
getpalette(&amp;pal); </FONT></P>
# W  P8 ~% E. f( A' n. v<P><FONT color=#0000ff>/* convert palette info. into strings */   C4 E7 g& D- S& C4 A
sprintf(psize, "The palette has %d \ ( H" C) H7 X1 @9 o; s
modifiable entries.", pal.size); </FONT></P>
. y) o8 T% V% D4 I7 M# Y+ W' ~<P><FONT color=#0000ff>/* display the information */ 0 l, E* h# L. N
outtextxy(0, y, psize); ; w# c( m: T# r( J
if (pal.size != 0) 0 d" ?; N. Z( [$ [+ |. l, s$ n
{
9 s( ?0 G; Z4 N+ Y8 t+ D1 L8 M: eht = textheight("W");
3 z" F7 m) ?7 v. J( uy += 2*ht; ( ?( R4 D7 Y4 V& d0 [
outtextxy(0, y, "Here are the current \
+ y6 ?2 w  v# i1 `2 k% Fvalues:");
: r9 N+ X$ a; c/ jy += 2*ht;
, h' J* U, Q1 tfor (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
  \9 l* W2 ?' ~" o8 Lsprintf(pval, . d' ?1 {0 [# w# {8 H0 A1 ?
"palette[%02d]: 0x%02X", i, 4 G- O0 d: C: a. c9 D
pal.colors); 7 F' k, I: W( F* o
outtextxy(0, y, pval); ! {  I/ r1 p; h! q: H/ K
}
, e/ k0 y/ s5 v* p* M( N} </FONT></P># z. O1 s; u6 e/ |$ y
<P><FONT color=#0000ff>/* clean up */ ' U; G6 N( F5 F" }( b6 V
getch();
( i' g/ ]1 K/ @6 M4 _+ Zclosegraph(); </FONT>
3 g! Z* l  Q( c) a<FONT color=#0000ff>return 0;
, Z; a8 E' N. e# B: E5 ]& `6 {} # v) G' I, F- P" W8 ?. p$ h6 b/ c
</FONT></P>7 c" r& u+ b5 D! U' Q
<P><FONT color=#ff0000>函数名: getpass </FONT>
' n: l5 \7 u9 S  d7 G( a功 能: 读一个口令 6 `1 Z, J+ v+ }. Q& h/ u) F$ O9 f
用 法: char *getpass(char *prompt);
) G6 ?, s& @% |, D程序例: </P>% ?! Z3 r2 p3 q3 E6 s4 z
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>4 a6 z: ~9 K& [
<P><FONT color=#0000ff>int main(void) ( Z7 {- K1 Q  a% @
{ % @3 r) a% G6 ~% P$ ^4 N% r/ P* T
char *password; </FONT></P>
5 U8 w2 s% d4 T3 V' v<P><FONT color=#0000ff>password = getpass("Input a password:");   o9 m8 q3 [, J; r; K* Y- n
cprintf("The password is: %s\r\n",
8 k3 a; N3 t' J- g- Opassword); 5 M5 F- m0 M; l- w2 x
return 0;
$ d6 y6 \4 e- q; ]* c8 I4 V9 U}
6 d. s9 G8 y9 P5 a</FONT>
- C0 m. q/ J2 h7 ?$ y' q# W' ~8 w: f$ B) {
</P>
  k6 ?4 M6 r& q<P><FONT color=#ff0000>函数名: getpixel </FONT>0 z5 ?4 r1 R3 G& }7 |
功 能: 取得指定像素的颜色 / t/ f! O5 P# w7 ?6 G
用 法: int far getpixel(int x, int y);
3 x, C5 x* p- T7 a# j- |程序例: </P>
; d7 K) H# u& C& K& _/ d<P><FONT color=#0000ff>#include <GRAPHICS.H>3 Q/ @5 V; z9 Z+ a3 u( e
#include <STDLIB.H>: L9 t  X/ a$ E+ u; I5 k
#include <STDIO.H>
" g/ \% n5 e3 U; h* D+ x. x; P9 G#include <CONIO.H>
/ d( y' Z. \8 S8 z" K#include <DOS.H></FONT></P>6 j; k* `! b) a# c) ]1 j
<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
# z+ \) c7 O, S5 T2 A; b#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>6 _! \% x; a& @- M3 J7 s$ p
<P><FONT color=#0000ff>int main(void) * V. c" q8 O+ e1 w. H- r9 b
{ - g+ x- J8 T. n
/* request auto detection */
3 A+ a" U7 r- S. A9 rint gdriver = DETECT, gmode, errorcode; 2 y5 J% ?- J9 I: x9 g0 J
int i, x, y, color, maxx, maxy, 1 D  T: k, c+ w8 [3 |* p6 ?: F1 z
maxcolor, seed; </FONT></P>
8 v# \# d& m" F5 |<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 n4 l4 o0 B$ b$ B; M. cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 p' ^6 u$ R- o. a( D0 Q<P><FONT color=#0000ff>/* read result of initialization */ * Z% I; l  W' s; Q
errorcode = graphresult();
$ u2 _# f  F( X9 P6 e* x/* an error occurred */
. K. K+ {' y3 j, k! j2 O: z8 uif (errorcode != grOk) 5 _5 R& t% h, g' B! f) p3 o1 L4 u
{
3 {8 L8 e. W3 U' ~6 _printf("Graphics error: %s\n", 6 Y. V% d7 x. M; I; _/ o- ~, P
grapherrormsg(errorcode));
0 Q# ~7 u9 c& o6 jprintf("Press any key to halt:"); ! g/ e! K! ?5 d/ e: p
getch(); ! g; X- l0 W, H! Q. Y  H3 c
/* terminate with an error code */
6 D" E" r" ?0 R. ^$ J- V% Oexit(1); 6 Z  c/ p+ \6 x4 ]* w
} </FONT></P>+ p! K' Y8 g) ?" w
<P><FONT color=#0000ff>maxx = getmaxx() + 1;
0 l( z0 i# i# Vmaxy = getmaxy() + 1; 7 I5 \) z& C1 e& {  j$ P
maxcolor = getmaxcolor() + 1; </FONT></P>" L+ P3 C# w% n% G5 p9 L* @
<P><FONT color=#0000ff>while (!kbhit())
" e- f3 V! }: }* ~1 K$ q{ " w4 ]9 Y2 u( Q: y8 f
/* seed the random number generator */ 2 r( u) d# _+ Z) o/ P8 K( A9 H1 L( {
seed = random(32767);
7 H: H$ |( ~/ ?. m9 j) R. U" q* Q8 `4 wsrand(seed); 7 @* f9 c# `/ K) Q
for (i=0; i<PIXEL_COUNT; <br i++)> { ( A+ l8 F/ W. T% W6 P" H2 w' i
x = random(maxx); 6 B! D+ S) u3 M+ j) @
y = random(maxy);
3 K. g, W- W7 |: d" i. _color = random(maxcolor);
1 V" N( C9 N8 U" ]+ y2 I* }. @) ^putpixel(x, y, color);
2 {$ z, L1 ]5 v" O% G" U; ?2 N} </FONT></P>4 s  A, ^4 O+ O8 r" R3 |, S  I
<P><FONT color=#0000ff>delay(DELAY_TIME);
" A0 l1 V9 \8 e. Q  }' n2 N! p* ysrand(seed); " O& V1 q/ r" |- f/ A& N  D- c
for (i=0; i<PIXEL_COUNT; <br i++)> { 2 I# C" ?/ h; q* ~
x = random(maxx); / w; b. N6 {# \! l1 ^
y = random(maxy);
7 m+ @( v- l0 Fcolor = random(maxcolor);
& _! A0 H2 w! xif (color == getpixel)</FONT> </P>
/ ^5 I1 {- P9 P+ O8 J5 a+ c' m<P><FONT color=#ff0000>函数名: gets</FONT> 1 M- q8 z, b9 h: r; U
功 能: 从流中取一字符串 & P; h$ _; G6 ]
用 法: char *gets(char *string); # ?4 q1 Q6 Y5 b9 ?* E% `# O
程序例: </P>9 q4 N8 n8 s  F' H( T; k0 m
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
& W  z$ [0 V: k<P><FONT color=#0000ff>int main(void) 3 p0 r1 q8 d# h  b) O. C$ Y+ ~# c
{ 2 Y7 `, u) V$ s1 Y& w- }$ ]4 ?7 Q
char string[80]; </FONT></P>* B% K; d% k) p* Y0 J. v: ]
<P><FONT color=#0000ff>printf("Input a string:");
3 Z& p' [& O; p7 H4 [9 `. Q9 e  [gets(string);
3 r( A6 Q, Y# p9 z8 g7 `printf("The string input was: %s\n", . W! {3 `) \/ C7 i
string);
" [" |8 C; p4 i- Ireturn 0;
; O1 q3 K: |) U( W2 {2 H3 A} 0 n5 _+ [5 Y0 _  ~2 t2 v3 w- [' S
5 U* K7 u) U" m6 W% t
</FONT></P>
4 [, O  D9 f; H/ c! ~<P><FONT color=#ff0000>函数名: gettext </FONT>% C& K2 q0 S- y. J" m: Q$ p
功 能: 将文本方式屏幕上的文本拷贝到存储区 - A# J& n) Q  A
用 法: int gettext(int left, int top, int right, int bottom, void *destin); 6 B* n$ m% B! k: K
程序例: </P>
, a3 W/ d. Z/ L" }. |<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>7 c8 u" M4 K/ ]: Q
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
6 {- e% r/ C: N* x4 Y$ A4 @<P><FONT color=#0000ff>int main(void) 2 D& g) S3 i: a3 b+ D
{
9 D4 l, ~3 s7 c% Oint i; . {3 o5 @7 f; S3 A4 c' |! P: M9 O7 Y
clrscr();
' N- A$ z+ w$ w1 N% d7 ^* xfor (i = 0; i &lt;= 20; i++) : ]4 M+ f; m. V' j! N& H# T# {
cprintf("Line #%d\r\n", i);
, w5 r1 y! g" P. M; `0 Ogettext(1, 1, 80, 25, buffer);
  t3 u/ Q) T" \gotoxy(1, 25);
9 b7 p% D! c! P/ P: B& j. Mcprintf("Press any key to clear screen...");
2 t9 x; y9 x# Rgetch(); & W0 S, X8 @6 e) e! K9 ]
clrscr(); * _6 F# L3 @& J8 Q, {
gotoxy(1, 25); $ Q: y2 E6 z- J1 [  s0 h
cprintf("Press any key to restore screen..."); , y7 n- O, X& k6 d' O
getch();
6 k* L# O5 O8 V& J3 W) sputtext(1, 1, 80, 25, buffer);
+ |% {3 D+ p6 \7 {0 W1 j' @gotoxy(1, 25);
, i  |6 t" l9 Z+ c& n0 l& f( }cprintf("Press any key to quit...");
7 n7 K/ [, ]( |0 _3 H1 D1 pgetch();
, Y" ^: X& u& Y% K5 l3 d/ O3 Jreturn 0; ' K8 ?- }, B& Q% k3 o9 M$ `2 C
}
3 Q# O! d0 O+ o</FONT>1 w* R- N6 i" H2 w9 e9 R0 o
</P>  L5 ?+ F1 o" a3 h
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> 2 K3 B; j5 C5 P: ]
功 能: 取得文本模式的显示信息 8 {6 Y5 A. _) v$ ~& E( j: [
用 法: void gettextinfo(struct text_info *inforec);   v" o/ q! S1 w6 D4 V
程序例: </P>( H4 k$ I8 }  e2 U  T  ]0 c
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
7 B; r3 _8 `3 R  `9 D* X<P><FONT color=#0000ff>int main(void)
" y2 f% L0 y1 g" o. L{
* U7 b- G' b' Q4 r+ |: ]struct text_info ti; ) V; i& H! s/ J: j7 G$ R/ e; J
gettextinfo(&amp;ti);
  I! k, h; J8 a: z% dcprintf("window left %2d\r\n",ti.winleft);
& n8 A: ]& q; y" y$ u3 hcprintf("window top %2d\r\n",ti.wintop); 7 i- n6 g, g. o, u- L% J/ D- Q
cprintf("window right %2d\r\n",ti.winright); + x8 J3 D" o+ e) j
cprintf("window bottom %2d\r\n",ti.winbottom); * Q% B1 I& @" I4 o* v# O
cprintf("attribute %2d\r\n",ti.attribute);
6 k' o) [' n/ C# R6 xcprintf("normal attribute %2d\r\n",ti.normattr);
; H9 w) K& }9 ccprintf("current mode %2d\r\n",ti.currmode);
8 R+ M; r+ N3 s6 A1 B  Tcprintf("screen height %2d\r\n",ti.screenheight);
$ o& x  [3 a; V: D! V7 b+ {+ ucprintf("screen width %2d\r\n",ti.screenwidth); : Y9 [+ }0 ~% U8 G( Q3 _2 @  \3 Q& I
cprintf("current x %2d\r\n",ti.curx);
2 Q% J/ V* A9 Dcprintf("current y %2d\r\n",ti.cury); : J  T: X0 C; B8 `$ v
return 0;
& A" h2 o. ?/ v7 u6 Z8 U$ l3 X6 s1 Y9 q% J} $ x4 i! t8 q8 i& G
</FONT>, b3 j5 K% i+ [0 N0 [' _9 Y8 R
</P>
$ j7 I5 [6 @; X4 s6 {6 m  `<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
6 D, U( p+ z5 {' m. {& w) h功 能: 返回有关当前图形文本字体的信息 ) s3 \+ V' I# L0 w+ I0 K
用 法: void far gettextsettings(struct textsettingstype far *textinfo);
9 W# h! f7 e- O2 S. }9 W程序例: </P>% H6 c2 E( O% V" Z
<P>#include <GRAPHICS.H><FONT color=#0000ff>: l$ a" @  C" F8 ?$ v, N# V
#include <STDLIB.H>/ I- O- n  Q# i# l5 [/ }' ^2 @
#include <STDIO.H>
% ~  w0 P8 ^' {+ r5 N#include <CONIO.H></FONT></P>
/ O% a/ j% ~/ u; n<P><FONT color=#0000ff>/* the names of the fonts supported */ ' h) o/ q4 U6 n. c
char *font[] = { "DEFAULT_FONT",   p) @2 U  U7 ]; l( x9 G+ q, ]1 h
"TRIPLEX_FONT", 0 U0 h8 c' r% s; V1 L( i# _
"SMALL_FONT", 8 p$ ^7 ~0 H7 `  \* A9 ~/ U! P
"SANS_SERIF_FONT",
3 ^! Q& c4 m* l. ?+ Q"GOTHIC_FONT" 2 c9 ~$ U7 B6 Y+ W
}; </FONT></P>
) c" d; y/ w- C1 G% `<P><FONT color=#0000ff>/* the names of the text directions supported */ 5 `: v9 X3 F6 A+ z% S
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>. _+ ~* c0 r6 {: y5 i& I
<P><FONT color=#0000ff>/* horizontal text justifications supported */
/ T; r- ^6 z; x; Z/ S3 Q  ychar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
  q. z* `8 e2 C# ?' t! A- V<P><FONT color=#0000ff>/* vertical text justifications supported */
, G8 L. @% G  dchar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
3 C6 t3 O; u4 R5 ]<P><FONT color=#0000ff>int main(void)
6 h( l9 C7 v* m3 V* V/ }& j! x4 [, W{
: N" z+ s$ l- G/* request auto detection */
" f* `3 k2 d* d# Tint gdriver = DETECT, gmode, errorcode;
! C, ]; {3 q' p7 R$ d- Y1 ~struct textsettingstype textinfo; ' X  G, v3 {8 b, o
int midx, midy, ht; 1 _4 o) K& g* C/ U, P3 a8 r" b
char fontstr[80], dirstr[80], sizestr[80];
7 D& o8 D0 [) f' u$ I& ]char hjuststr[80], vjuststr[80]; </FONT></P>2 J& q% {' [+ x6 Q% E. g$ f8 W, n3 k/ f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
( b; P* c( i" ?/ Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! p" N+ @1 d" h3 R% m<P><FONT color=#0000ff>/* read result of initialization */ : v1 g$ r+ Q- Q* P( o: ~
errorcode = graphresult();
& _# W# ]% g, z; j% Z( H# Yif (errorcode != grOk) /* an error occurred */
4 [$ \! P" C% Q* V{ 2 X( {# x  }$ x# E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( f1 R/ o% P  t8 V: W
printf("Press any key to halt:"); 4 u+ \" w+ [( T2 D+ j1 X
getch();
  y0 z& U) J/ iexit(1); /* terminate with an error code */
( z+ U7 k6 X% l" B0 F} </FONT></P>$ l- @; M) N# Y0 M3 t( y. R
<P><FONT color=#0000ff>midx = getmaxx() / 2; : R4 u; X6 B- J
midy = getmaxy() / 2; </FONT></P>' g/ K6 H; i( \: z: }
<P><FONT color=#0000ff>/* get information about current text settings */ : g+ `3 v% r! U, i
gettextsettings(&amp;textinfo); </FONT></P>
* o# l7 p* H+ `# @2 B! m9 H$ X<P><FONT color=#0000ff>/* convert text information into strings */ - ^: H: H8 H6 d' H' z5 f
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); 7 l, O% z, W. S+ O
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
$ f# Q/ g  N* o4 a1 @: Q# _sprintf(sizestr, "%d is the text size.", textinfo.charsize);
7 w& N7 L" T3 I4 |% J* w& zsprintf(hjuststr, "%s is the horizontal justification.", 1 {8 A. Q2 E6 r: G. I9 y
hjust[textinfo.horiz]);
1 B; Y+ `; h9 K$ S. ^+ Asprintf(vjuststr, "%s is the vertical justification.", - f9 l' b5 l/ g$ d: H
vjust[textinfo.vert]); </FONT></P>
6 I; e; A; c2 ?+ d2 Q# |( P0 ^<P><FONT color=#0000ff>/* display the information */ 8 m1 r/ e3 v4 E. ?1 S, U
ht = textheight("W"); 3 k) h# `# G1 x" H5 Z$ L
settextjustify(CENTER_TEXT, CENTER_TEXT);
9 t9 P! n/ z+ }9 x6 u- houttextxy(midx, midy, fontstr); % |# g+ L! G9 m( b' p
outtextxy(midx, midy+2*ht, dirstr);
' p. D6 W0 \5 z$ gouttextxy(midx, midy+4*ht, sizestr);   D& k1 y9 m6 ~' O: A; G0 N3 I
outtextxy(midx, midy+6*ht, hjuststr); ' h5 a& J4 N% t" T9 ^
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
9 ]$ W1 ]1 W; ^* g+ t<P><FONT color=#0000ff>/* clean up */
( \$ P+ P$ t* I  ^getch(); 4 a1 L9 a! z  E9 {* u; |0 E8 V6 Y
closegraph(); ! z8 q) \; _* b& I
return 0; ; g) F+ m: \- i1 X% K* k4 c4 ^
} </FONT>
+ M8 ~' v: o4 F; ~6 n</P>
% g/ k) I; C" c" m  W8 o$ t<P><FONT color=#ff0000>函数名: gettime </FONT>8 @  P6 s. b6 ~4 W
功 能: 取得系统时间
. m& D! u) B  N& X& u用 法: void gettime(struct time *timep);
  g! b/ [4 J! U程序例: </P>/ s" @9 J5 G8 b/ U
<P><FONT color=#0000ff>#include <STDIO.H>$ V- P# l7 P1 \) l
#include <DOS.H></FONT></P>
: U3 x; k" c, g! P) t- L<P><FONT color=#0000ff>int main(void)
9 C- T1 J) G  n  }{ + w' {% T, Q& y) s+ s1 p3 Y3 Z( a5 \
struct time t; </FONT></P>
. s' i8 K0 f+ ^  H: W<P><FONT color=#0000ff>gettime(&amp;t); " s, @! r- o- u+ t( A( S
printf("The current time is: %2d:%02d:%02d.%02d\n",
8 L7 B. g. w- Ct.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
) j  s& y, C; N4 yreturn 0;
# v0 y* W) d0 q  @} 9 |6 }; D$ ]3 g" a- ]+ @9 |, w

1 K) p/ s% t6 q9 D, n2 z: o' U2 f</FONT>
# U" s  P1 \' A! k8 I</P>
$ t! {/ o% C6 x: B<P><FONT color=#ff0000>函数名: getvect </FONT>
( @0 W. G  R( C9 f功 能: 取得中断向量入口 1 Z0 u9 u' o2 o5 L# A% s, w
用 法: void interrupt(*getvect(int intr_num));
( p$ k  \) p# w- j9 ^$ K- [程序例: </P>
. C4 x% `7 I) \  z<P><FONT color=#0000ff>#include <STDIO.H>
5 \* A  M2 q: D2 u2 g9 a: _, e#include <DOS.H></FONT></P>
" a' c  \% v9 }+ r2 w2 e. G<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
% a% E- h- q2 W" O/ q<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ ) c: H7 s8 r1 r. C2 u
int looping = 1; </FONT></P>
* ~6 d$ t7 O1 J" r<P><FONT color=#0000ff>int main(void)
& v/ e5 G* A. U{ ) E3 @$ v6 S) w. d
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>& j% }9 v5 c# K: x, ]4 I# }$ }
<P><FONT color=#0000ff>/* save the old interrupt */ . [! L  x$ s" `  ?# W% O1 ~
oldfunc = getvect(5); </FONT></P>
" N' r1 U/ S( \<P><FONT color=#0000ff>/* install interrupt handler */ # W1 w" ?$ v  U; W  A$ G
setvect(5,get_out); </FONT></P>
/ s7 ?+ V5 V5 Y, v7 e<P><FONT color=#0000ff>/* do nothing */
  f0 o( l, T1 @- Uwhile (looping); </FONT></P>) X$ I; S; [8 a
<P><FONT color=#0000ff>/* restore to original interrupt routine */
: \" u  W# J/ G& d' X- @2 H) F/ \setvect(5,oldfunc); </FONT></P>
" X7 a/ e) v$ e: v! X9 B+ O# }<P><FONT color=#0000ff>puts("Success"); 6 V6 T1 x  A) i( Q
return 0; 5 a6 R+ {9 n! G' s. L8 j, C/ l
}
# o! B9 t. {3 |, \' [$ Evoid interrupt get_out() : f; j+ @2 H/ D
{
( u" |8 z  s( G/ L# {  X$ u4 {looping = 0; /* change global variable to get out of loop */
' E# T- b5 x/ w5 n} # N" b, {' K" s6 m1 x+ ?; _+ M
</FONT>5 _3 L  \6 V% w' ]0 _
</P>! x% O+ ]# r9 R9 ~8 q- V
<P><FONT color=#ff0000>函数名: getverify </FONT>' g  W. O/ {8 L/ j8 ?3 b
功 能: 返回DOS校验标志状态 2 i3 J8 U+ u- Z/ ^
用 法: int getverify(void);
/ L" j, b( Y0 e/ k2 X程序例: </P>* q  o/ |. ?8 y: B( l+ R8 N* {
<P><FONT color=#0000ff>#include <STDIO.H>% r( G" ^5 z! J6 r2 R7 m
#include <DOS.H></FONT></P>
7 v/ O4 ]" l' m& K% Y9 G<P><FONT color=#0000ff>int main(void)
- b2 y- l; b* T) ~. {{ 3 O% \  |  R4 G# {5 y% V
if (getverify())
* y, q2 l; i9 Z$ r- Hprintf("DOS verify flag is on\n"); 6 Q# a$ s2 L5 r2 ?) _& _' [
else
8 C5 A. K5 d: ~printf("DOS verify flag is off\n"); 5 C4 [# D: u- Z5 K
return 0; 7 @4 T4 H) o& z
} 7 s+ ]1 b. }  b
</FONT></P>0 [5 ]8 |5 Z- Q
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
, Z. ~. ?& i7 j1 D+ ]& `7 M) c' c( G功 能: 返回有关当前视区的信息 ( ~, w; q/ ~: M1 @, [' ?
用 法: void far getviewsettings(struct viewporttype far *viewport);
1 l- F% L- D5 a8 X, e, f- ]9 x$ g  w程序例: </P>
7 _; }" f3 X1 j/ f: b8 U4 I) ^- x9 n<P><FONT color=#0000ff>#include <GRAPHICS.H>. n5 Y% o- h/ R3 j4 {% r  F5 W6 O7 a" x
#include <STDLIB.H>9 y' s2 w4 n* K$ C5 Y
#include <STDIO.H>& O; v( y5 q3 y' A  Z
#include <CONIO.H></FONT></P>: f- t3 \4 @/ d: \$ L9 x3 p# h$ M& v
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
6 {; l0 G; s. ~! u- j<P><FONT color=#0000ff>int main(void)
: ~6 d; N4 D# e9 P, |{ # t- ?- I) c  J6 }' f9 L! Z
/* request auto detection */
. s' Y) a; K0 z2 k& iint gdriver = DETECT, gmode, errorcode;
/ K0 T% J- u( z5 q4 a# Mstruct viewporttype viewinfo; . K/ o9 G6 w1 |# O6 Q' Y
int midx, midy, ht; 4 @1 L2 s% }% _6 L6 J4 [1 J6 K. W
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
0 L0 D7 }0 f% f& c; L3 w- U, Q. l<P><FONT color=#0000ff>/* initialize graphics and local variables */
) J2 D2 O. c* [7 vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, o: {$ n+ c* P- w6 Q) Q  w<P><FONT color=#0000ff>/* read result of initialization */ 6 C0 \% o5 F, s* Q7 S4 [' a% R
errorcode = graphresult();
! U! M/ V! }! z3 S( Y$ m9 Mif (errorcode != grOk) /* an error occurred */
( G# w7 R' i, m, b9 Y- v1 x{
/ K9 U7 s9 r/ H; W! U3 uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' l% Z8 d: E7 L$ A" ]" x0 D; }' d
printf("Press any key to halt:");
: R7 q$ m7 f' z% mgetch(); , k& i6 L) N; M4 `) ^  P
exit(1); /* terminate with an error code */
7 [" M/ W6 u( q; w5 T} </FONT></P>) L) c/ G% Z" R3 ?3 i
<P><FONT color=#0000ff>midx = getmaxx() / 2; & d* }- B" ]* R" w; n7 I! K
midy = getmaxy() / 2; </FONT></P>% X. W5 _; C, R" r* P. Q- w, @
<P><FONT color=#0000ff>/* get information about current viewport */ 8 ]- Z% M  f" P7 y
getviewsettings(&amp;viewinfo); </FONT></P>
. V6 b6 W9 t8 @2 S7 Z<P><FONT color=#0000ff>/* convert text information into strings */
& D8 C7 D/ U9 l9 I. Ksprintf(topstr, "(%d, %d) is the upper left viewport corner.",
: _8 M; K* V# d9 Mviewinfo.left, viewinfo.top); 8 ?) p) t3 W( o9 D7 J6 n
sprintf(botstr, "(%d, %d) is the lower right viewport corner.", 9 Z, M, B5 S# z3 }
viewinfo.right, viewinfo.bottom);
' a6 q( o5 r  g3 W" Ysprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>0 e5 W% H- [# f) j1 ?( ?
<P><FONT color=#0000ff>/* display the information */ ) C3 N! [/ M; C" w1 y
settextjustify(CENTER_TEXT, CENTER_TEXT); 4 n! U- i/ m! _7 E$ A! W/ g
ht = textheight("W"); * v7 o0 J5 |; j& \# S7 v2 b
outtextxy(midx, midy, topstr);
$ z( c4 z- h" o% k% N% ?/ M. Gouttextxy(midx, midy+2*ht, botstr);
7 @2 ]% y6 n8 I: {' n1 P: e4 Pouttextxy(midx, midy+4*ht, clipstr); </FONT></P>
6 Q6 ^) c% M6 a- U" d<P><FONT color=#0000ff>/* clean up */ " ~1 l( R# f* M2 @: @" M
getch(); % B& S+ T2 g$ ?$ s, p
closegraph(); 2 ^( _1 X4 d% y# I
return 0;   I! Q8 u/ d% k9 @+ ^
} </FONT>
5 ~, k) S! G% P! a5 }" J% D6 v; B5 W0 J- e9 a7 G
</P>
6 n3 @0 _/ i) b  k9 |4 A/ z4 w<P><FONT color=#ff0000>函数名: getw </FONT>7 v: W5 U" ~/ B
功 能: 从流中取一整数 & r: ]9 ?5 r9 ]" j5 @/ s
用 法: int getw(FILE *strem);
- o& n3 B: p& c+ S& E程序例: </P>7 d; ~- n6 v; U* v& y1 t2 j( s
<P><FONT color=#0000ff>#include <STDIO.H># _8 U; i4 l: M2 ?( V- q
#include <STDLIB.H></FONT></P>
" k5 {+ T1 _. ]$ ~! A; j<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
" c) Z7 T/ C, F( }% v$ C9 N$ z1 J<P><FONT color=#0000ff>int main(void) ( M- y' b* H6 v% W$ d3 Y8 p
{ - h! e1 I9 O# T6 @# V: X! I9 `
FILE *fp; * S) T- \! Q% }0 n
int word; </FONT></P>6 |6 B/ Z- F, o/ Z
<P><FONT color=#0000ff>/* place the word in a file */
8 g% \$ y  Z3 I0 k8 s6 w, ufp = fopen(FNAME, "wb"); & t$ K4 q9 e3 B# z9 Y3 w7 X0 h) V
if (fp == NULL)
9 \- L. |- e/ W5 Z{
: @& X% N7 x4 k! p" p# ^" i4 M3 t: I2 d- Yprintf("Error opening file %s\n", FNAME);
* f: [& s6 b- X7 Z5 s  fexit(1);   u2 i/ X$ U$ L" H( s- p
} </FONT></P>; F/ X+ c$ n* K
<P><FONT color=#0000ff>word = 94;
9 S6 G5 k2 l# H) l+ r# z& G$ mputw(word,fp); 7 f3 v& X- k9 B, S4 s7 R% ~
if (ferror(fp))
: H2 A. O$ J: q  f' `# b' O0 K+ Qprintf("Error writing to file\n");
1 t" S/ D. a$ ]" i; m) X$ `+ N4 Uelse
  ?# o# `+ [  Dprintf("Successful write\n");
- x) a; \8 i. ?" S. ]8 M8 i: Sfclose(fp); </FONT></P>
7 K' H6 C5 X& S5 p& X; c+ O<P><FONT color=#0000ff>/* reopen the file */
1 T9 f( e/ a4 {7 i5 |fp = fopen(FNAME, "rb"); + ]4 ?" o  @( e6 [2 Q- u- ?
if (fp == NULL) , X) W& n: M1 {3 w; _8 p, ~
{
9 t7 Y; U+ T- K' m# dprintf("Error opening file %s\n", FNAME);
! j' k, _+ ]7 _6 m6 n+ texit(1);
& K2 M: ~+ x3 \" P) F+ R" H} </FONT></P>5 G  S+ m( M3 j" G! g- }, K
<P><FONT color=#0000ff>/* extract the word */ 9 [  _8 O1 w. G6 y: |% g
word = getw(fp);
: f2 {+ R& X' C( Nif (ferror(fp)) , v( ?8 g, G: `+ a  `
printf("Error reading file\n");
4 ], T4 W# F+ P; @7 N" R! Telse * j4 O  x5 h% }% e6 _! a. o5 a
printf("Successful read: word = %d\n", word); </FONT></P>
3 D, Q% z) U  `  N; t2 J. N6 W<P><FONT color=#0000ff>/* clean up */
4 C7 |7 X( }, Z( b0 C# r3 x' h; ]- Sfclose(fp); 5 w5 ]9 R8 U. L# A9 T% I% ?9 b) `
unlink(FNAME); </FONT></P>3 e( z. M7 z7 I% M
<P><FONT color=#0000ff>return 0;   I: K) T+ D5 n% ?
} </FONT>
% f0 S0 n1 P+ E6 r, i5 i/ v0 R+ L* P3 K, U" i: P8 c5 H

7 E& E: Z9 [' n: K% {. c</P>
) i# D8 Q' _; h<P><FONT color=#ff0000>函数名: getx </FONT>7 z0 E% {( B9 G, i: u0 D/ }5 v
功 能: 返回当前图形位置的x坐标 1 L- h, D# c, L
用 法: int far getx(void);
1 _; w/ a5 O- J) y程序例: </P>
( s9 P3 p* u- ?7 ^<P>#include <GRAPHICS.H><FONT color=#0000ff>/ F. T4 S5 [0 t- {, e. ^
#include <STDLIB.H>
' S( Q' E3 f) L1 @( `4 B# Z3 \#include <STDIO.H>' A5 j6 S1 e- X# C8 h
#include <CONIO.H></FONT></P>
& F, ^+ T. B! O  q9 u<P><FONT color=#0000ff>int main(void)
& V3 V* T2 C, G4 X) ]4 _  b{ . U0 o9 Y1 y( K
/* request auto detection */ 7 k, v3 }6 A. ?* S; k
int gdriver = DETECT, gmode, errorcode;
8 G8 }0 M* |2 P& X8 Achar msg[80]; </FONT></P>
! ~' h6 X6 x$ r7 d+ H<P><FONT color=#0000ff>/* initialize graphics and local variables */
, Y0 M+ q# t9 S# binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 D/ Z8 k& W0 L1 R4 \/ e8 h
<P><FONT color=#0000ff>/* read result of initialization */ 9 @  |$ {6 ^: Z5 d! L" g
errorcode = graphresult();
+ ]; _0 [& n  j* n, h% [/ f2 m& cif (errorcode != grOk) /* an error occurred */ ' A6 `+ ?) T( D, b4 R% Q3 H& l
{
' s* D6 A' ]: C- N9 c3 eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 \  k% S: K( ?- Iprintf("Press any key to halt:"); : G% M) e0 e& g- X- y  T1 M3 t
getch();
5 K) I+ f6 L) g( Hexit(1); /* terminate with an error code */
3 k1 c" L9 w! d% L} </FONT></P>) n  r- T1 A' [; {  L! S
<P><FONT color=#0000ff>/* move to the screen center point */ ) l0 T4 f- i( z* I
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>$ K: o0 A8 ], G: d
<P><FONT color=#0000ff>/* create a message string */
( l6 F( s" o0 \& @+ F2 P5 ^sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>0 Q! p2 M: {0 V; ], v( Z/ _
<P><FONT color=#0000ff>/* display the message */
( I* A" {" `1 [4 i% G- r% touttext(msg); </FONT></P>
7 v% M# h* l& b/ {" q7 q4 f<P><FONT color=#0000ff>/* clean up */ 3 j2 Y! X: Q$ ]3 G7 P2 Z4 ?
getch();   X/ _. o: @. v7 t
closegraph();
" _( l! x; c1 m. j: i$ W; s/ Sreturn 0;
- B5 ?; P% O5 g0 w. T& w3 x} </FONT>
1 A1 h( y7 U9 m' h2 L
5 g% b$ L1 q9 a2 P$ X  {</P>" f9 ^6 d3 Z, ]$ [1 c
<P><FONT color=#ff0000>函数名: gety </FONT>3 [  G8 \& |7 d" }, w. K  |
功 能: 返回当前图形位置的y坐标
6 q6 }! l- s3 o. o$ M7 z用 法: int far gety(void);
( t" n' |/ f, D. f" ?程序例: </P>
% G" \/ `* B3 |8 p<P><FONT color=#0000ff>#include <GRAPHICS.H>5 y/ Q& d2 {9 v9 N4 v- o3 X
#include <STDLIB.H>
& l0 f  V( L, v5 U! c& J: d( o#include <STDIO.H>5 ]! f3 Q  D) |/ u  r9 r* Y6 J
#include <CONIO.H></FONT></P>+ R# p2 p0 V% N$ O1 m' u
<P><FONT color=#0000ff>int main(void)
* Q5 o  a, h, t8 Y- D{ 1 w$ _2 k: G6 P$ t' ]
/* request auto detection */
- ]3 d0 t6 c: z; a: U! uint gdriver = DETECT, gmode, errorcode; ! A! ~1 k9 e; d4 F9 ]
char msg[80]; </FONT></P>9 ]! c/ }# o5 R$ _' _! r: z7 ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */
: t% b% G  \! G* `$ ~9 ^2 u0 A! Kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ K+ y# k6 H/ K# K9 h# k) }# J1 ^3 v
<P><FONT color=#0000ff>/* read result of initialization */
4 _, X3 d9 J( V0 Gerrorcode = graphresult();
+ c5 r6 t6 R" W+ oif (errorcode != grOk) /* an error occurred */ & G' F! x7 D1 ?! e7 p
{
  p" `: p" d7 C$ b& T/ cprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' |9 ~( e0 b/ Q$ O  [( v5 Pprintf("Press any key to halt:");
9 j. \; {( Z! [/ Z3 Sgetch(); ; @3 j( x3 t5 O# d3 h1 S
exit(1); /* terminate with an error code */ ) }3 x8 ?: c6 U& T
} </FONT></P># j3 g7 Y7 X, F3 U3 j! B
<P><FONT color=#0000ff>/* move to the screen center point */ ' I$ W1 v( P* b0 E9 [
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
- O8 }% B; W! z" P" z' }. d<P><FONT color=#0000ff>/* create a message string */ 2 w& ^7 V0 I1 n
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
3 Y; p0 B  K; p7 K<P><FONT color=#0000ff>/* display the message */ % s4 Q; ]0 v+ I" w
outtext(msg); </FONT></P>4 x" _+ {( f' h9 A2 a
<P><FONT color=#0000ff>/* clean up */
% C1 ]5 _2 l0 K( c! f0 |getch();
. Y6 n0 u' E- D- aclosegraph(); 6 e8 I# N3 f) I4 k7 e) N" k1 D- }
return 0;
1 W" D% U9 M/ {- n4 F} </FONT>
" D5 N. B) D3 c9 |& b; N9 T( u3 c
% `* [& t. H0 w2 k5 l. ]</P>7 I) w( q. P! a8 B9 }
<P><FONT color=#ff0000>函数名: gmtime </FONT>
" ?; l* o' W) S5 K功 能: 把日期和时间转换为格林尼治标准时间(GMT) ' V6 I! k/ h9 a9 _" c) [8 @: C
用 法: struct tm *gmtime(long *clock); 0 F0 M# E9 b( q- S' ?
程序例: </P>
4 n8 N8 i. S) R<P>#include <STDIO.H><FONT color=#0000ff>$ S! G% `9 X9 q6 B& ~  [9 @* A1 B
#include <STDLIB.H># J$ T1 [! @8 B1 m' U
#include <TIME.H>. e6 A( ]( ~8 X1 _: R8 f4 l9 x
#include <DOS.H></FONT></P>
; g  S% U3 U1 u* R7 Y+ g<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */
% t9 {3 p* O( l  fchar *tzstr = "TZ=PST8PDT"; </FONT></P>
0 S  C4 O' v5 L. U<P><FONT color=#0000ff>int main(void) 8 ]% d3 Q, E4 @0 O% E' p4 _
{
7 [) g/ K' e5 {0 b! ztime_t t; 2 n& }5 C# x6 a0 @3 a$ w
struct tm *gmt, *area; </FONT></P>7 }$ a  W# M" d% o' S/ Q
<P><FONT color=#0000ff>putenv(tzstr); - s: H2 X* P& X1 N
tzset(); </FONT></P>
9 C% v# x7 R4 m' T& r* X<P><FONT color=#0000ff>t = time(NULL); 1 u# R' ~( x4 J* M% |
area = localtime(&amp;t); * V- N7 @% X# o- A' V) Y* @
printf("Local time is: %s", asctime(area));
$ o- e4 E) f3 M+ i2 Ugmt = gmtime(&amp;t); 1 N+ N& \1 k: U1 ]/ Y
printf("GMT is: %s", asctime(gmt));
8 O/ k. E! I2 h5 |* freturn 0; ( M5 Q$ K) ]. a  f4 k5 X6 _
} </FONT>
! F" J/ B& H4 S5 U0 o. g
* D1 i5 Y& Q, S$ |2 K( z' V</P>
3 c9 @, u7 z- q( k" `/ R% [<P><FONT color=#ff0000>函数名: gotoxy </FONT>/ Q* a9 D2 ]: }% ]8 D
功 能: 在文本窗口中设置光标
1 G; L. C7 n9 k! `9 u% r用 法: void gotoxy(int x, int y);
0 b% r* J7 x. s, m% i9 C6 ?程序例: </P>9 K# X9 J) ^8 \  `
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
1 K+ ~  J3 j9 a* M( M<P><FONT color=#0000ff>int main(void)
' R. ]/ Q4 z' ]{ % o3 g- b2 T7 K' Y
clrscr();
# {5 i" t) w* a7 r! E' sgotoxy(35, 12);   A) B: i5 w* H" G& I6 ~
cprintf("Hello world"); . M5 ?) E! M1 `! }/ s! n7 E% d$ @
getch(); , b2 o! u* g7 s9 ?0 K7 d% x5 [
return 0;
: I. j- J( j* K}</FONT> ' V* o2 o. c( m) v- c9 q3 Q
% U' e7 s- s, S# u
</P>
& O) k# k' l1 }- z0 X<P><FONT color=#ff0000>函数名: gotoxy </FONT># ]' g; T% z* D
功 能: 在文本窗口中设置光标 $ n) u: ?. o, q; W: Z0 L
用 法: void gotoxy(int x, int y); - w. O0 B& p5 v3 c; c
程序例: </P># z. v6 m  z7 T" u. y
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>; e. S  O# C6 u" @2 a9 x
<P><FONT color=#0000ff>int main(void)
" {+ s  `. ?# q0 P/ j{   T, }* L- l6 `5 k
clrscr();
$ N/ ~3 F5 m9 O  Rgotoxy(35, 12);
5 k1 |0 E* {8 E7 Z% Xcprintf("Hello world"); 0 v& a# ^3 E4 d" r1 A6 w
getch(); 4 \& `5 R5 d" H' g+ f0 y4 `: _  Z8 u
return 0; ( c6 I$ \0 A1 d& J* F) M4 K
} + F* t) I- T5 t& K% q
</FONT>& l- B0 A( A  _; C
</P>
, u: R( _& K2 ~0 x9 z<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
+ d5 y' O$ O3 U; m  i+ M8 |功 能: 将所有图形设置复位为它们的缺省值
3 Q3 N9 [0 w) j1 Z: h用 法: void far graphdefaults(void); 1 U, e, c6 M% V0 l% _3 i
程序例: </P>
* {" L. a7 E- ?+ M<P><FONT color=#0000ff>#include <GRAPHICS.H>9 b  V; A- [+ {4 ?! ]
#include <STDLIB.H>
: c& j4 s& N) b1 N* \#include <STDIO.H>  Q& [8 H& h, q: N4 m
#include <CONIO.H></FONT></P>0 b8 z! K0 X5 o" Z$ l
<P><FONT color=#0000ff>int main(void)
/ l3 m/ [$ @- e, j! \{ # g6 `! L8 }+ a$ ]
/* request auto detection */ ) x: m$ j" |8 Y& k- F
int gdriver = DETECT, gmode, errorcode;
, x( f/ W! O6 }int maxx, maxy; </FONT></P>/ u8 Q6 w5 X- Q& L
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 m  k, q0 ^, g1 }9 q- N
initgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
) ?7 T8 ^( t" o" a8 z5 {<P><FONT color=#0000ff>/* read result of initialization */
4 `9 v/ D" a1 p& z" X# Yerrorcode = graphresult();
3 H7 b1 n; I! @; k7 N9 @! zif (errorcode != grOk) /* an error occurred */ % k3 ~* y" M5 h: t& _7 u
{ $ R2 ^) C, R3 k8 R
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( t* x, o# [. f6 r
printf("Press any key to halt:");
( }2 }5 |5 u% T% J' s5 Kgetch(); & T  J; O3 ]# {, T) H
exit(1); /* terminate with an error code */
( b$ g- p3 W' ~! N. D} </FONT></P>
6 a4 D7 T; m$ y! A: o6 ~<P><FONT color=#0000ff>maxx = getmaxx(); ! z0 `$ a  _. l- ^- A4 O3 A( o
maxy = getmaxy(); </FONT></P>/ z! r2 N/ W! ]! `& r) @+ e0 |) A( B$ |
<P><FONT color=#0000ff>/* output line with non-default settings */ 9 ^; z* v( a& p* O0 n+ u* ^9 F* ?
setlinestyle(DOTTED_LINE, 0, 3);
; ?$ N# K) z8 I& J5 g5 s- Kline(0, 0, maxx, maxy);
- |: w. v. g  }3 Jouttextxy(maxx/2, maxy/3, "Before default values are restored.");
3 ^5 q5 E" `" W+ A7 [getch(); </FONT></P>
/ k# J9 g4 H, R  ]  o<P><FONT color=#0000ff>/* restore default values for everything */ / Y; X2 }+ j2 t
graphdefaults(); </FONT></P>
1 H/ A" O: s$ p# r0 {2 ]7 Q  Q: G<P><FONT color=#0000ff>/* clear the screen */
! C7 A& e% V: r8 U% s- Bcleardevice(); </FONT></P>% B" r. X, n9 b  W9 c
<P><FONT color=#0000ff>/* output line with default settings */ . u& i# B. a- j2 O2 [& B! M
line(0, 0, maxx, maxy);
& u! w  W9 @" k7 d1 s% vouttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
) g+ k( F6 l. L$ W<P><FONT color=#0000ff>/* clean up */ ( z5 j- R+ y* W/ B3 G9 e! \
getch(); 9 `0 u% g$ `+ d1 B2 U
closegraph(); % c  e2 e2 I* Y+ x) T- K6 H7 |4 x$ m
return 0; 8 T: F2 m: O/ E- S6 U. N: A
}
$ _8 e$ g/ b  O0 i; x</FONT>
' e: q; c/ i8 s# |! M# ^</P>
1 T! H2 S8 ]0 Z7 |2 K<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>
! P9 J, E9 C$ a! E) g, y1 Q功 能: 返回一个错误信息串的指针
4 ]% J/ u( e0 g7 j用 法: char *far grapherrormsg(int errorcode);
$ m9 l* C- d4 i# U程序例: </P>1 p+ Z, |6 [" Q, T9 N3 b1 M0 P. P2 }
<P><FONT color=#0000ff>#include <GRAPHICS.H>: u8 [, b; V# f1 z6 X+ r
#include <STDLIB.H>) n' J0 j$ I9 J# [& u) |" S
#include <STDIO.H>
: P% J) w! d& C7 P) L: \4 X0 M9 y; V#include <CONIO.H></FONT></P>
, o+ t- q/ @- d<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>/ q# ?7 ^! m) X( j6 G& Y
<P><FONT color=#0000ff>int main(void) 8 \2 V- G* |- K- p  X) h
{ : @% a3 W  \* `, T
/* FORCE AN ERROR TO OCCUR */ ; l- Q5 O- b0 r9 k/ l& G
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>" W* @( F% l; I7 O7 m) {
<P><FONT color=#0000ff>/* initialize graphics mode */
3 G) ?" d+ f4 L0 h- `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  B& b9 ^9 t8 h* n% k% p3 S, y
<P><FONT color=#0000ff>/* read result of initialization */ # P, B- [) ]5 N4 M$ ~4 e( t
errorcode = graphresult(); </FONT></P>! T$ |* Z; y0 h
<P><FONT color=#0000ff>/* if an error occurred, then output a */ 6 x- G1 ?; C9 G
/* descriptive error message. */   z* i& W5 N" |( r
if (errorcode != grOk) & Z0 ]. l/ G& P5 Y/ M  C9 b9 e# S
{   F$ Y# q) T: y# R8 o- l
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % z- P* t) H/ |0 M
printf("Press any key to halt:");
: j2 _/ y% F' `9 tgetch();
+ f1 c: l# R# ~: C$ \exit(1); /* terminate with an error code */ 0 }% L2 _; b. U# Q3 q0 Q, |1 k
} </FONT></P>
; a& x6 E5 S. G5 [- b: E7 Z" F<P><FONT color=#0000ff>/* draw a line */
' E4 V+ p8 s" L" k9 K) w; v- oline(0, 0, getmaxx(), getmaxy()); </FONT></P>+ H- m- {5 V% Q& V! a; h; q
<P><FONT color=#0000ff>/* clean up */
  Z/ A" M; J: {$ g% bgetch();
* s$ u% H" j$ X' |1 r3 Rclosegraph(); ' k/ L- V$ y2 S  ^1 e, m
return 0; 5 z- T# \7 T6 o
} % ^" W$ N0 q' ~0 K
</FONT>
! j! L4 d) E. w0 d</P>
4 N5 y" w6 G2 d. w: J<P><FONT color=#ff0000>函数名: graphresult </FONT>, }0 I$ M0 }% [& B) U! {  ]5 V0 Q
功 能: 返回最后一次不成功的图形操作的错误代码 8 C/ t3 K/ `+ f' C$ }2 B$ f2 O
用 法: int far graphresult(void);
$ C6 z& f. `; S( A$ T  O8 A: z程序例: </P>- e: w6 W) l* i
<P><FONT color=#0000ff>#include <GRAPHICS.H>* M5 ]( y- `0 T5 ]# n; d" q" Q3 N% E
#include <STDLIB.H>
5 h7 g! g1 Q% y* V1 i# s' t4 s#include <STDIO.H>
* \3 r# M- J( U% c+ l#include <CONIO.H></FONT></P>
8 ~0 x: d- y3 L<P><FONT color=#0000ff>int main(void)
! ^8 K: `6 `7 B- K1 l8 |! e* f{
) Y/ q: p$ J2 w- P6 r- S" O) @/* request auto detection */
; |5 s, b% X7 Qint gdriver = DETECT, gmode, errorcode; </FONT></P>
; [! v) G+ H6 H7 A0 _# u<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 z( G! _+ q) Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) q: L' ]. [% `6 _/ f
<P><FONT color=#0000ff>/* read result of initialization */ * X7 Z/ l) f3 l) A7 K/ v
errorcode = graphresult(); </FONT></P>' ?. k; g$ j% B  n
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
& ^  [  b8 ^9 v$ H{
1 K8 D) N% T9 b1 W8 O6 w+ [printf("Graphics error: %s\n", grapherrormsg(errorcode));
& z% \- j* W( M: q% Yprintf("Press any key to halt:"); * E6 R6 b0 U, Q; P7 Q$ q5 ?
getch();
4 @. j4 @. i) o& W8 ]. uexit(1); /* terminate with an error code */ 9 h) O, j9 _9 ^
} </FONT></P>! K# `- ~) o) r$ O" H- ^5 d
<P><FONT color=#0000ff>/* draw a line */
+ @, N5 M; K8 O/ {4 ~# M4 gline(0, 0, getmaxx(), getmaxy()); </FONT></P>
6 i) K9 U+ X* e* u4 {3 L% ^5 H9 Y$ k<P><FONT color=#0000ff>/* clean up */ ) \, A6 E/ A' p  U8 S' q' O; o7 N* ~
getch();
; G( v: x  x; v7 f; ]1 ?& eclosegraph(); & B  h" L& @' `- v2 h/ @" [6 Q# u
return 0; 5 w6 u% R3 r1 X1 r! J+ t0 x
}</FONT>
9 f9 c- G0 p7 D4 l5 X</P>
! u& N6 r3 b" S<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> ) {$ q1 |- k) C5 k4 j
功 能: 用户可修改的图形存储区释放函数 " A: M* u+ G: ?
用 法: void far _graphfreemem(void far *ptr, unsigned size);
8 F+ @; h, o* y. B8 m9 ?程序例: </P>0 M- u, `6 U; s! o. ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>- t) [2 ]5 W% x( x4 Y6 c
#include <STDLIB.H>
1 \; B: Z, ^) t* t3 w! ]#include <STDIO.H>) F6 n8 ~0 g; ~1 J) Y. P# Z# X
#include <CONIO.H>
% h$ K1 Z" z6 u* w. r#include <ALLOC.H></FONT></P>; F9 `+ O) [( V; e# T7 F
<P><FONT color=#0000ff>int main(void) 3 C  r* y, f7 _4 @6 G, [9 T) n+ j
{ " {3 O/ c: r6 p& t' P/ ^
/* request auto detection */ + O$ N& R/ m. _+ d( u, ^
int gdriver = DETECT, gmode, errorcode; * t$ X- k# s% E+ Z
int midx, midy; </FONT></P>
7 |/ A" h, ]: W9 M# }  m, ^<P><FONT color=#0000ff>/* clear the text screen */ # @4 J; d- y0 s  t2 F: @9 @0 c6 t
clrscr();
4 d/ `, ?( I" m# J& Uprintf("Press any key to initialize graphics mode:"); 7 z$ g+ Z0 J  K
getch(); 7 r. [; ?* X& W) }* S/ O
clrscr(); </FONT></P>
3 B2 C: E) w& a1 |# @/ r<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 t. j$ N) @1 m% O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># N! R( n: G- P) z1 P; K" H
<P><FONT color=#0000ff>/* read result of initialization */
9 P0 S2 I' V) p/ S0 [- Y- l0 @errorcode = graphresult();
3 t* j! \: Q$ }) `/ _& Rif (errorcode != grOk) /* an error occurred */ 6 z* V* B: q5 `  c# H  j/ V$ E5 d# L8 B
{
: B5 l& H+ y) V7 A- zprintf("Graphics error: %s\n", grapherrormsg(errorcode));
( N" {$ [9 C  M: I, n$ y' P1 Aprintf("Press any key to halt:");
# g2 w( _9 |$ E* rgetch(); 7 c9 W. \0 u3 U
exit(1); /* terminate with an error code */ & a" N) o- `! ^
} </FONT></P>
/ k9 e1 _' t7 {" t<P><FONT color=#0000ff>midx = getmaxx() / 2;
6 ?+ C% o  g% e2 I; `7 Smidy = getmaxy() / 2; </FONT></P>
" x: U9 t  M$ x/ F<P><FONT color=#0000ff>/* display a message */
% N- a! U' Y6 n$ Zsettextjustify(CENTER_TEXT, CENTER_TEXT); $ L7 D4 V$ a7 s3 u) v
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
, b) z; C- w' X  ~' @<P><FONT color=#0000ff>/* clean up */ : l$ U' n4 \4 n, b' h: ^3 k
getch();
5 q7 R  D/ v/ o/ {6 ?closegraph(); # _# G+ D6 E) [2 Y
return 0;
5 \) A7 x7 S3 f' C2 x0 _2 l} </FONT></P>2 g! ]9 V: a# z* `9 s
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ 1 `% b* T7 ?$ H9 E+ Z9 k6 u$ [
void far * far _graphgetmem(unsigned size)
/ ~# q% a* @' b7 ?" {1 z+ w. B( Q3 L{
6 N( Q" q9 e$ Uprintf("_graphgetmem called to allocate %d bytes.\n", size);
0 ^, T4 R+ z! {; m( U7 aprintf("hit any key:"); ; |* c  W- [9 U1 l, T/ b; q
getch();
. F( q( J4 Z8 Wprintf("\n"); </FONT></P>( c6 E2 n$ ?1 L
<P><FONT color=#0000ff>/* allocate memory from far heap */
  f- k( p, }  Jreturn farmalloc(size); , b* I+ O& X; C& P
} </FONT></P>
: A  T! d  Z# L0 j+ l1 A* u& N) s# o2 B<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
' w3 ^$ I1 _1 {+ s2 m8 Q" s2 zvoid far _graphfreemem(void far *ptr, unsigned size)
( g2 ?3 ~2 d- v. J+ t$ j  S{
( ]$ r6 K# R7 c1 c& F4 Zprintf("_graphfreemem called to free %d bytes.\n", size);
! o, o0 ?" X4 O1 X. L! fprintf("hit any key:");
4 O0 J* J" F  U9 `getch(); % Q/ D: S( D1 a5 ?0 ^* \  q
printf("\n"); </FONT></P>7 _6 W$ o8 m- ^
<P><FONT color=#0000ff>/* free ptr from far heap */
  a% B7 S- G' E9 ifarfree(ptr);
) i& D6 ^; L6 {1 ?# v3 G  A} ) U0 f; u4 n7 U/ C
</FONT></P>! b* O! d% D( H# O
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>; u" d4 g. K( n  D6 K2 F
功 能: 用户可修改的图形存储区分配函数
7 j5 W" ?  m9 j9 w5 p9 h2 x# Z用 法: void far *far _graphgetmem(unsigned size);
7 S9 L8 S" E$ H1 H程序例: </P>, r  b2 H' h1 ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ Q) |0 {4 e  G6 h( i0 A, m#include <STDLIB.H>
) y" \9 \, k; M/ _#include <STDIO.H>
. N0 U! n; U' T# k# v% v#include <CONIO.H>
3 d0 B6 @) ^0 K" ]" k- `# H, r#include <ALLOC.H></FONT></P>, h; e" q7 t: ~% Q7 r1 p  b% l
<P><FONT color=#0000ff>int main(void) 0 F% a" J+ b% M5 ^. d+ ?8 K! v' j
{ * y4 w  j3 x7 |. H$ w
/* request autodetection */
# ~" R1 {/ q* w# kint gdriver = DETECT, gmode, errorcode;
/ M  E4 S4 v! e* L9 c0 |int midx, midy; </FONT></P>9 i$ ]: d% m; i  _9 h) O% |
<P><FONT color=#0000ff>/* clear the text screen */
& P; x" z  f7 y# c' s7 d+ B1 Vclrscr(); 1 E- }! b. y+ t  w) P1 f- y
printf("Press any key to initialize graphics mode:");
1 W3 ^# D9 ^$ J+ u; H' c  U, _getch();
! f% g6 i; \! g7 |( U0 ^$ ^clrscr(); </FONT></P>4 A% g+ e; \. N6 U$ w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" L0 @( S" [8 sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' {( q% A# T3 }4 Z7 @8 |<P><FONT color=#0000ff>/* read result of initialization */
: ~  ~( l- B* Verrorcode = graphresult();
  S% M& b1 R7 h; Mif (errorcode != grOk) /* an error occurred */ 8 R: j1 O: W2 J8 I; Q
{
8 O/ S! {& f$ w9 K+ Yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
- c6 y8 _/ U" e4 _printf("Press any key to halt:"); % x" U) |( p% A4 K
getch(); " h9 ?4 h" S& _% Z: y
exit(1); /* terminate with an error code */ - X0 B6 Y4 C2 }$ z' {0 z
} </FONT></P>
7 ~2 b( G" z1 s. @) S<P><FONT color=#0000ff>midx = getmaxx() / 2;
/ u' D& z( @) V& \- b6 J) }+ u) @& ?# rmidy = getmaxy() / 2; </FONT></P>: F( T& \  \' I3 o
<P><FONT color=#0000ff>/* display a message */ 5 y8 P. e' U4 C: G; M+ H% x
settextjustify(CENTER_TEXT, CENTER_TEXT);
  z7 t- C( I. Z9 W0 l$ `0 O3 Louttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>& z* ^) g/ z0 c
<P><FONT color=#0000ff>/* clean up */ ! Z, d( v3 Y: X. y7 e) ?8 T
getch();
; z; r. O: J0 Y- u2 [+ gclosegraph();
  Q3 f0 i' Q" ~; jreturn 0; ( X2 @% Y: o4 n9 t! q% l6 [
} </FONT></P>
4 ]( x- L% P2 R+ X<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ ' s7 D) l- ]+ `, d; Z& O
void far * far _graphgetmem(unsigned size)
* m, f0 l, E6 E1 p% m- [3 q{
7 q$ c. Z! A9 X- R) L. ]# x) [printf("_graphgetmem called to allocate %d bytes.\n", size); 0 X. B5 u) ~  O+ m
printf("hit any key:");
. `9 D8 `) X& V8 ?. egetch(); ) S$ }1 D* X: i- L, x& ?
printf("\n"); </FONT></P>/ b2 T. W  d3 H* `
<P><FONT color=#0000ff>/* allocate memory from far heap */ # K( ?* @: \* t! V8 Z: B- U4 O
return farmalloc(size); , t- i! o1 K5 |5 n/ ]5 t- u# Q
} </FONT></P>% a. x  |- Y1 o' `* T& p$ p/ n
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
/ H- j# f* L9 d/ z" K3 g0 X2 I5 nvoid far _graphfreemem(void far *ptr, unsigned size) % L1 p% \' ?1 T! o- Z0 e
{ 9 `! b4 u( D+ j' H; P% d. ?8 v9 D
printf("_graphfreemem called to free %d bytes.\n", size); 0 n  T6 y! Q$ x8 l$ V3 y
printf("hit any key:"); 3 [. Z9 H: x. R0 Q
getch(); ) i( d. y  a8 S1 E% ?+ S
printf("\n"); </FONT></P>, |$ [( J1 b: G/ p
<P><FONT color=#0000ff>/* free ptr from far heap */ 6 c# P" Q/ {- |$ f
farfree(ptr); + P0 l7 M; {, n
}
& T9 g; H- p$ J6 y" m; 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-6-12 04:40 , Processed in 0.699341 second(s), 51 queries .

回顶部