QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2513|回复: 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>. Q" F' `- I6 |1 ]

7 r1 Q: z' z* K6 Y% a# q- }, Z& r" o  n* g" `+ d
<p>+ N. M9 c; X3 ~, G" t: v
<><FONT color=#ff0000>函数名: gcvt </FONT>& m0 c/ \1 Q# p0 z
功 能: 把浮点数转换成字符串 % F/ p0 W" ?4 Y0 q. D: J" N7 p# A
用 法: char *gcvt(double value, int ndigit, char *buf); ( J) l7 O1 d0 V, _" ]8 z
程序例: </P>
: Q- ]+ U0 z4 z<><FONT color=#0000ff>#include <STDLIB.H>
2 P. a$ \" o- D  {- y+ _* [#include <STDIO.H></FONT></P>
% ]$ j6 }4 Q2 p% I<><FONT color=#0000ff>int main(void)
2 j( ^* J! U9 l# s{ 9 g# _% T" W: p, N4 L& O
char str[25];
' T) k0 S2 _9 w! I) Z, |+ wdouble num; 4 o7 W5 J" |+ J+ H# U% E# z% G
int sig = 5; /* significant digits */ </FONT></P>
9 Y9 {9 Y7 K5 k. F<><FONT color=#0000ff>/* a regular number */
- A* G9 B2 W' c6 \9 {num = 9.876;
* @/ L- Q: G9 Vgcvt(num, sig, str); * y. p' D, |' k  b( M$ W
printf("string = %s\n", str); </FONT></P>
  k7 A+ ^/ }3 w<><FONT color=#0000ff>/* a negative number */ + C$ j1 Z* I9 m* j
num = -123.4567;
9 V: P5 Q4 ?4 {* u0 b. jgcvt(num, sig, str); 8 @+ I$ K5 T( h5 s; d! l% \
printf("string = %s\n", str); </FONT></P>
; Q- h2 M, u% T5 ]0 X; X9 s<><FONT color=#0000ff>/* scientific notation */
' [4 b7 t# u) |$ A  |4 w. Snum = 0.678e5; 9 k" p4 z2 d/ A: ]  j8 `/ R( \$ F
gcvt(num, sig, str);
3 [' h) l8 O5 f9 G$ R7 [& W6 s9 Nprintf("string = %s\n", str); </FONT></P>
" J& S1 `6 s( z+ `$ {; z<><FONT color=#0000ff>return(0);
( [# }/ `' S. Z8 c" k* X} : ]8 O$ s& q, u6 g

- f& ~1 J6 X- M* s</FONT>
5 {( a; [/ @% ~, D1 X, f</P>
/ ]9 O+ a- ^5 M% `<><FONT color=#ff0000>函数名: geninterrupt </FONT>
1 L) V8 ~: B; u' h4 S功 能: 产生一个软中断 3 L% w; K4 s' s+ l
用 法: void geninterrupt(int intr_num); 3 A) K6 C+ {( @0 x5 ?4 [, ~! N
程序例: </P>
1 p$ `# {( Q7 i2 q  k' H1 \$ a<><FONT color=#0000ff>#include <CONIO.H>. O6 l/ S* ~3 W
#include <DOS.H></FONT></P>1 m. ?2 h, ^$ g: J/ A
<><FONT color=#0000ff>/* function prototype */
+ D" e9 ]  ?& l2 @# C2 dvoid writechar(char ch); </FONT></P>0 c9 ?5 |* T  X* |4 ^& X6 L
<><FONT color=#0000ff>int main(void)
/ J1 g1 I  j0 m. [/ M{
2 K- O, ], Q) K. Lclrscr(); ! Q- I( [4 L8 {3 X; n8 l8 v
gotoxy(80,25); 0 @4 n2 N/ A! d+ f: x
writechar('*');
0 e' I9 `8 J  [* S" B+ M+ [getch();
9 ^3 {& U0 K( Q! c# \return 0;
* }+ O9 l" l1 _; F* R: [0 {1 h0 C& P} </FONT></P>
# t( {  E( D* f- }" R<><FONT color=#0000ff>/*
  G; t) a. M7 O. i7 J# Zoutputs a character at the current cursor
% Z- v4 P: Z' O4 C. \position using the video BIOS to avoid the 2 j) k# E+ V7 `3 i
scrolling of the screen when writing to
/ D! d8 V" ?; s* X7 _: tlocation (80,25). 4 V% O) j( I: \% X- j% X
*/ </FONT></P>$ _4 P: |# F! i8 y$ O5 _! g
<><FONT color=#0000ff>void writechar(char ch) & v$ O" R+ S4 L; r
{
% i/ s1 J6 L/ u6 G; d6 jstruct text_info ti;
. t3 ^9 B' u# B9 u2 @# {4 C/* grab current text settings */ + p6 k" p% k' o( k+ p
gettextinfo(&amp;ti);
& \  w4 y& }8 k9 f2 O2 o/* interrupt 0x10 sub-function 9 */ 7 n) Z5 Y; t* Q! c) {
_AH = 9;
$ `; [: U9 X: H" d7 |6 V/* character to be output */
- v2 L& O1 U& c/ J$ T_AL = ch;
! T7 A: K5 U; e, ~4 d_BH = 0; /* video page */ / g1 d. m6 {+ S6 p2 s
_BL = ti.attribute; /* video attribute */ 0 k' X3 O  X9 m8 p4 n
_CX = 1; /* repetition factor */
" s/ f8 p7 o2 f1 tgeninterrupt(0x10); /* output the char */ / C3 j: o3 Z2 M& k, A
}
$ m7 g& l# P9 o, p/ l. O* z</FONT>
  f% R$ w' [: h</P>
) s/ D/ o9 ]' E1 G2 H) r<><FONT color=#ff0000>函数名: getarccoords </FONT>
$ Y" b9 J" `! i; X功 能: 取得最后一次调用arc的坐标
- v& m1 l% ^$ c9 z用 法: void far getarccoords(struct arccoordstype far *arccoords); + h: ^8 N9 a) L( ]! t
程序例: </P>$ ?' o- N+ P2 }0 e+ t* D% R
<><FONT color=#0000ff>#include <GRAPHICS.H>& V8 I/ Y' D0 p9 ]
#include <STDLIB.H>
4 U; m9 J$ v# z& u( s  c#include <STDIO.H>
* i4 h4 q% C! B) \: K#include <CONIO.H></FONT></P>
# z1 t* a9 h( u4 N# @7 J: D<><FONT color=#0000ff>int main(void) 1 w* f9 Q! N1 Q; U5 U
{
% n. V" P2 E' i4 c/* request auto detection */ ! G/ J6 Q/ J  `
int gdriver = DETECT, gmode, errorcode; 0 H& N+ n/ `+ \+ k, d  ?" R0 m0 E
struct arccoordstype arcinfo;
+ t& M. ?; f7 f5 D0 W6 z* Y8 qint midx, midy;
. U& e8 b0 o; N/ gint stangle = 45, endangle = 270;
( @# S- a* C8 o/ ]char sstr[80], estr[80]; </FONT></P>+ ?2 o+ q. z* K7 a
<><FONT color=#0000ff>/* initialize graphics and local variables */ ) Z  v. M; Q  K+ g! w' M4 N1 P8 _
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 m( X$ a3 ^, D' e# I
<><FONT color=#0000ff>/* read result of initialization */ - k, C4 Q& E3 \! I% ~
errorcode = graphresult(); ! j' R& {- ]3 g0 O5 F
/* an error occurred */ % O! r; M2 R2 B" ?6 _3 K8 b" k$ e+ |
if (errorcode != grOk) . w* I2 u* h$ [% m6 K
{ ; J" |- r3 e- b3 T2 a" k+ T
printf("Graphics error: %s\n",
3 d& b; g) O+ N" q% e1 xgrapherrormsg(errorcode));
5 v) J5 U- U. b1 q$ S3 A6 tprintf("ress any key to halt:");
9 p" Q. n/ d2 @$ Q1 Y* ugetch(); * d! g) i3 `$ y2 J
/* terminate with an error code */
  H# R, u- ^5 T- _* {* yexit(1); % a3 B3 _: B% h1 k) T$ U
} </FONT></P>
; y* U9 H6 A2 _7 E* Z3 x<><FONT color=#0000ff>midx = getmaxx() / 2; 6 U7 J  a' S# y/ \
midy = getmaxy() / 2; </FONT></P>3 Z- u5 @; U5 Z' X5 e  L
<><FONT color=#0000ff>/* draw arc and get coordinates */ ( Z( S4 u/ i$ w4 t+ N
setcolor(getmaxcolor());
" n) O6 i0 N0 w2 N- E) aarc(midx, midy, stangle, endangle, 100); 8 A% q/ \% S* `1 k1 d
getarccoords(&amp;arcinfo); </FONT></P>
3 Q1 r7 t& |, P" {. H# O: W. Q4 h<><FONT color=#0000ff>/* convert arc information into strings */
4 [: ~& q0 J2 ^" o4 dsprintf(sstr, "*- (%d, %d)",
$ I; \+ z9 B/ t0 L) T7 u! Narcinfo.xstart, arcinfo.ystart);
+ t. f7 {- ~; I4 B/ ^+ ?7 Psprintf(estr, "*- (%d, %d)",
  F# s! N" @! B% _$ T6 Warcinfo.xend, arcinfo.yend); </FONT></P>4 {9 F" O$ @9 x  n5 W) e
<><FONT color=#0000ff>/* output the arc information */
8 P" S& f/ d  T7 `; o6 C$ Youttextxy(arcinfo.xstart,
  S- ?" }& R& p* S% Harcinfo.ystart, sstr); 0 t# a$ a; S* y1 z. i
outtextxy(arcinfo.xend, 5 Y1 R8 G1 w1 ]) _* ]6 C; d2 D
arcinfo.yend, estr); </FONT></P>
& N  v% B  ], K9 @% y" L" s5 P<><FONT color=#0000ff>/* clean up */
$ V. |1 |" i$ V5 Dgetch();   r  B5 `" I$ P$ t3 z$ ?0 Y
closegraph(); . g# Y' L6 X4 M2 ~9 M2 r' D
return 0;   ^) O9 [# H0 O3 q5 G+ Z2 a3 s
}
5 [0 w9 A( U% n! {4 q</FONT>
! i' Q% i( j! u5 T9 E5 M
5 F% t8 U7 L" C. B( u* l</P>
  p8 g8 n" L9 }<><FONT color=#ff0000>函数名: getaspectratio </FONT>
: Y1 {: Y' B; o6 X! m+ B' c功 能: 返回当前图形模式的纵横比
! x( Z$ F1 P) p0 L用 法: void far getaspectratio(int far *xasp, int far *yasp); , r# ]; s. _- j) w% `
程序例: </P>  ]4 \: Y) P3 I; U
<><FONT color=#0000ff>#include <GRAPHICS.H>& G0 H6 O+ A9 {+ O* V
#include <STDLIB.H># j8 r( @% N. H0 I' N! ~. H1 U4 ]$ T
#include <STDIO.H>
  L; b7 q5 I4 A6 ]#include <CONIO.H></FONT></P>9 N4 b" k3 ]2 ~9 I# y/ a6 E
<><FONT color=#0000ff>int main(void)
" \# P/ I1 ?$ u{ & X2 F/ m: h3 _/ L$ ^( t
/* request auto detection */
! @7 X! N& k2 a: |, ?. E# c# uint gdriver = DETECT, gmode, errorcode;
. G) }2 C% F2 T0 n# Q% _* Z: Cint xasp, yasp, midx, midy; </FONT></P>
4 T3 d# ^; N5 \3 q<><FONT color=#0000ff>/* initialize graphics and local variables */ # k; W5 U' x! Q7 o- y6 W
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. P2 l7 [* q' |7 K5 ]  i
<><FONT color=#0000ff>/* read result of initialization */
' h- c; H+ o9 Herrorcode = graphresult();   H2 b# e9 Z/ N  D) A9 p$ Q
/* an error occurred */
4 i) r8 Z0 l& s& U' Aif (errorcode != grOk) ( {4 _8 O& S$ g: Q3 V
{
: R+ ]' e# D7 e9 I0 e, ^printf("Graphics error: %s\n",
. i# |0 v- i7 ?6 L* @  zgrapherrormsg(errorcode)); , @/ U/ j. g+ e, _6 H, V
printf("Press any key to halt:");
; w' R% g% q; n, Ggetch();
  {+ N" S, y) Y4 t# ~/* terminate with an error code */ ) m/ s- o- M! E
exit(1);
9 t$ D) a& ^. G3 x. Z( c} </FONT></P>1 K& ]; D8 }  ^- f# N& |
<P><FONT color=#0000ff>midx = getmaxx() / 2; ) y  p7 j$ J! L- W
midy = getmaxy() / 2;
1 Q$ q: x2 L: \7 c, o) ?7 J5 t& ]setcolor(getmaxcolor()); </FONT></P>( r4 N% x6 x6 W5 q. T+ |. Z  r
<P><FONT color=#0000ff>/* get current aspect ratio settings */
* {( {9 x+ E+ G6 U4 kgetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
3 _4 [0 l. m# u' T- Y% C<P><FONT color=#0000ff>/* draw normal circle */
8 ?, ?: J$ m) w2 O- Bcircle(midx, midy, 100); " ?8 y7 b) I% k* ^" _+ C" [4 k
getch(); </FONT></P>
  f7 {+ A2 E6 C- `8 r<P><FONT color=#0000ff>/* draw wide circle */
% J* q# Z$ x8 d3 \/ r1 U( O  J% @cleardevice();
0 E( g. A# e% p" isetaspectratio(xasp/2, yasp); ) n  t, {7 l  b3 {' {
circle(midx, midy, 100);
( e6 e8 t$ C# s; M! @* Vgetch(); </FONT></P>- H9 }3 I& k2 t' ]1 F
<P><FONT color=#0000ff>/* draw narrow circle */
. p, i4 `/ N9 ?; c6 P0 Fcleardevice();
. O  b+ i4 N8 C' v& y1 ]setaspectratio(xasp, yasp/2); ( c6 C; k+ M  I: {2 X: X/ c4 E: X
circle(midx, midy, 100); </FONT></P>) X' v( i0 r, ?. N" F' I
<P><FONT color=#0000ff>/* clean up */
/ G2 j! Q! P1 Dgetch(); 5 Q8 |9 _, N* m$ ]* S
closegraph();
" A; }+ x* I: jreturn 0; # p! ?7 \. Y) e0 U$ t0 c" Z
} 6 N$ i2 B0 n) v. n7 [* ~
</FONT>
1 {! l3 I2 R" G; C; f  q7 M0 c
% n" L% L2 k* D( s/ k# W</P>$ F- n7 @6 \5 k& Z% w+ W6 |
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
0 t0 d4 o5 C& V9 Y/ i3 k3 f功 能: 返回当前背景颜色
7 O2 T- G; i8 n2 N用 法: int far getbkcolor(void); * h; v" Q3 A2 ~+ C) X8 b8 w: X3 Z
程序例: </P>
) [. X% z7 f' l3 d$ C- o<P><FONT color=#0000ff>#include <GRAPHICS.H>" |3 g4 ]* Z0 C6 f
#include <STDLIB.H>
4 {* e  \/ t9 n$ _9 B; a#include <STRING.H>- d9 F7 T: v0 l3 U6 I5 f6 c
#include <STDIO.H>7 p1 S% U& z0 _# H" {( U
#include <CONIO.H></FONT></P>
# t5 j& F: |7 O; p: y; j+ K" D' N<P><FONT color=#0000ff>int main(void) 2 i) m5 x; i4 z* x
{ 2 e. H; J% t. z7 x: n
/* request auto detection */ $ \, Y& u  ~# Y5 p% u5 j; k; U
int gdriver = DETECT, gmode, errorcode; 4 i% V0 K' T/ q  r( |/ r8 E4 ]
int bkcolor, midx, midy; ) r* T1 O8 M5 S! {4 n* o1 U* @
char bkname[35]; </FONT></P>
* K* J1 d0 H) }/ L<P><FONT color=#0000ff>/* initialize graphics and local variables */
" ]7 [" h/ |/ O5 v2 [$ Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- f" U. z- }$ [
<P><FONT color=#0000ff>/* read result of initialization */
; ~7 ^3 n8 s3 Lerrorcode = graphresult(); 8 w5 t  G6 D; m& s
/* an error occurred */
2 [" V& e( m4 y) ]; V4 [9 mif (errorcode != grOk) . e4 X3 T- S$ K5 `2 ]- }
{ 3 S2 k# q1 T  H7 g( r$ O
printf("Graphics error: %s\n",
% _8 a. [, v1 I6 O; V- qgrapherrormsg(errorcode));
7 l/ \) U: }" K5 yprintf("Press any key to halt:");
1 `: ?% R8 t9 u% d  v8 Z2 Z2 t8 J% fgetch(); 2 W9 ?( X( x& P$ O
/* terminate with an error code */ # F5 ]9 M" ~' _5 ~* y  x7 Y* D
exit(1); 8 [8 N: V$ d! T
} </FONT></P>
5 G0 h& d% q" b7 c9 W9 y  D<P><FONT color=#0000ff>midx = getmaxx() / 2; ' r6 ?9 s5 a2 D
midy = getmaxy() / 2;
3 Y( G# c0 R! e% c: Zsetcolor(getmaxcolor()); </FONT></P>
6 p" b  v% u- c/ v; D<P><FONT color=#0000ff>/* for centering text on the display */ 6 ]4 ]9 h3 R% T# W' |3 }7 v
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
1 X9 h) f- l$ r* ^<P><FONT color=#0000ff>/* get the current background color */
' `/ {8 d4 X  p. i1 f$ f" gbkcolor = getbkcolor(); </FONT></P>  w+ N' ^5 K( W, a
<P><FONT color=#0000ff>/* convert color value into a string */ ; ^+ [8 P8 u0 Z
itoa(bkcolor, bkname, 10);
# a6 ]. x' Z+ @- z; ~) ~strcat(bkname,
7 x& F9 g# A" Y" is the current background color."); </FONT></P>
5 |" g; T7 _9 `/ e# \1 g% p<P><FONT color=#0000ff>/* display a message */
2 s7 u) R* m5 }4 z8 \1 ^) ^8 u- kouttextxy(midx, midy, bkname); </FONT></P>
$ w( k# n0 J7 ?3 q; Q" Q+ D<P><FONT color=#0000ff>/* clean up */ . u" A* W, [' l! c
getch();
: P& z. [6 ^- J3 Tclosegraph(); 2 m6 ?8 J0 |: {; b# T8 }% F
return 0; % @1 U. x* G9 c4 [* X5 [& k6 {
}
# @' }1 ~- {; x) N: J9 _: f
: l. `( O+ h9 |" I- f' m</FONT>
0 N$ N- M8 M) @. w! d</P>  o8 v5 C3 R( g3 m  ^
<P><FONT color=#ff0000>函数名: getc </FONT>
( g9 H* i& a3 W功 能: 从流中取字符 - g- |5 I  W, {  g
用 法: int getc(FILE *stream); # q0 D4 J+ y) K* R: S' E
程序例: </P>
  d/ r& a8 N* R# P3 C! f<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>$ z& b! C8 K% v1 C
<P><FONT color=#0000ff>int main(void) 1 d2 [  I7 l. H" R9 F
{ ' o* S' E+ ^$ a  Y+ S
char ch; </FONT></P>: h3 p, M" X' U( X% B( _$ I
<P><FONT color=#0000ff>printf("Input a character:"); 2 {8 ?5 J" k; w4 \5 P) r
/* read a character from the
% f. b- q0 c; S" {7 E, @standard input stream */
$ G4 n, R2 L; _" M+ ]ch = getc(stdin);
/ V( [2 X( p: _7 L. W; ?6 aprintf("The character input was: '%c'\n", 6 I7 ?: ~" D' l; _: _4 u
ch);
0 Z, H4 s* C6 Z2 K5 m, `$ V- a" l5 `return 0; " }; R4 _  j9 D# ?5 `
}   n$ r* b0 A( e0 b! {8 X: S

5 K* P/ `+ q- i+ i3 D; o+ y</FONT>. P- i+ M4 w3 \9 G3 X
</P>% J% J) Y/ m2 M5 ]  Q* [
<P><FONT color=#ff0000>函数名: getcbrk </FONT>
& L0 K0 v5 W) b% [' w. N6 [功 能: 获取Control_break设置
( z; v* Y7 X! ^, D3 k# U用 法: int getcbrk(void);
+ o1 H% S; m- I% o" b程序例: </P>
, l3 N) F% T7 L( E- z) N<P><FONT color=#0000ff>#include <STDIO.H>) [; X3 }/ d% U2 M0 T- N
#include <DOS.H></FONT></P>
: T2 G# z) H0 C4 L4 `; f6 V6 q3 `<P><FONT color=#0000ff>int main(void)
7 f- t5 v+ ?% U) V2 c{ $ c+ F/ {; Y; c! T5 R
if (getcbrk()) . I- N% @. n2 c6 T! z( ]5 B
printf("Cntrl-brk flag is on\n");
  O7 E% f# R$ ?! felse # t0 v0 ]" @/ Y5 F+ T  ^1 ?; x) `
printf("Cntrl-brk flag is off\n"); </FONT></P>
2 D5 d0 o& z3 X( z, N: J<P><FONT color=#0000ff>return 0; - v4 I  C8 p, @
} </FONT>
1 K* L* M. j% |# f% t, c( k( E% S, b. J
</P>1 ]- f' t, a: {- `0 y1 E
<P><FONT color=#ff0000>函数名: getch </FONT># Q( G  o5 _! r9 q$ d4 \
功 能: 从控制台无回显地取一个字符
& x' n/ f, @2 \4 l3 ~用 法: int getch(void);
) J, N+ P  [4 d" H程序例: </P>3 y( S1 _# [( D2 |$ ?
<P><FONT color=#0000ff>#include <STDIO.H>& A2 _( J" M# b) I9 }
#include <CONIO.H></FONT></P>
% |0 U2 t$ @* q" T. F, ]<P><FONT color=#0000ff>int main(void)
! e) D: f0 u, v{ ! N$ l; U7 {, A) m" l' W# q
char ch; </FONT></P>! N$ G) r# F1 A2 O: s
<P><FONT color=#0000ff>printf("Input a character:"); ! k8 n4 D) L4 P' Y3 _
ch = getche(); + ]+ o* ^: |& V3 M: @& b  u9 J2 v
printf("\nYou input a '%c'\n", ch); 5 m/ T+ F0 j! _
return 0; - M( i5 d4 O9 |2 W4 N
}
9 Y3 D% j1 T4 j* x3 r& j. N9 J# K; L$ [& _: e6 L3 k
</FONT></P>, C4 A# t3 M* _: E9 z; @% H) P
<P><FONT color=#ff0000>函数名: getchar </FONT>. ~) m/ v- J/ Y! c  F7 B
功 能: 从stdin流中读字符 # M* _8 z+ f. u  `8 a7 X5 L, Q$ X
用 法: int getchar(void);
6 L/ N# q$ x6 g- b# k程序例: </P>. w+ @/ F. R: b$ O
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
* d) q2 K1 B, }( r0 A( f<P><FONT color=#0000ff>int main(void) 8 e4 s1 f7 {$ }- T# C& r$ W( X' S
{ ( b( W  s- [) B3 }; N
int c; </FONT></P>
! f0 K" I' Q  m! {& v5 J<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
# p$ L, y' `6 i9 _( c, Z3 _4 Tis line buffered; this means it will
3 L" B6 ~+ @7 T! V9 r" V" u! Enot return until you press ENTER. */ </FONT></P>
. U! M+ ]& e  F& n<P><FONT color=#0000ff>while ((c = getchar()) != '\n')   d; V; ~! y2 H# J
printf("%c", c); </FONT></P>
) \3 b. q1 g. ]5 _& |<P><FONT color=#0000ff>return 0;
* E# o. Y% h0 Z4 b. K# G}
, R4 R( U  ?9 d) J, M+ P% C( ^</FONT>5 {4 T1 G3 t3 o' f2 [+ w  x
</P>
- t  Z7 [. b7 j: C<P><FONT color=#ff0000>函数名: getche </FONT>) \3 r9 |6 `% R3 X; I! d7 A
功 能: 从控制台取字符(带回显)
+ U5 [: d' j% P用 法: int getche(void);
3 E7 O/ X2 G4 D8 ~程序例: </P>2 y% B4 o7 n& v% X
<P><FONT color=#0000ff>#include <STDIO.H>) a1 C  q; d- Z
#include <CONIO.H></FONT></P>+ b: `+ O. k) ~& p" y8 D* ~; Z
<P><FONT color=#0000ff>int main(void) 0 s; A& [# A- E& Q- m$ h$ w$ m
{ & Y0 H$ ?- ], G
char ch; </FONT></P>
) U' x. q- p4 V" {1 E<P><FONT color=#0000ff>printf("Input a character:"); : Z! H6 {# L1 F0 T1 S: f7 g
ch = getche(); , \8 `) I9 v( i" z
printf("\nYou input a '%c'\n", ch);
0 m9 J6 a' ]; v  p1 c4 zreturn 0;
* {* g' e! B( D( W; G* Q}</FONT>   e. H; e$ A% P0 ]8 d" o# @

. O5 ?9 l. J- H</P>* v& C; x3 |/ Z$ ~
<P><FONT color=#ff0000>函数名: getcolor </FONT>
& ?+ {, L* }/ G功 能: 返回当前画线颜色
$ [- y7 \& U6 v( C* A- g# l! b用 法: int far getcolor(void);
$ X" @7 Q2 n5 `! z程序例: </P>  x" a* I' S8 p- T
<P><FONT color=#0000ff>#include <GRAPHICS.H>4 b" [0 s! w- @  R/ V
#include <STDLIB.H>' Z% u* Z- q6 M2 E2 k' D
#include <STRING.H>
1 w* ?2 u0 p! _. Z9 w# _4 ~0 v' O#include <STDIO.H>
1 D* j. h* O# S% q& s#include <CONIO.H></FONT></P>$ f4 i2 j/ a. }  V, b# t( W% S9 d
<P><FONT color=#0000ff>int main(void)
. `! F+ j! |$ m  z) C" Y+ [{ 0 l" z2 s  D' X; O- n6 Y1 Z
/* request auto detection */
0 o' c. ~5 I% A( {1 X8 aint gdriver = DETECT, gmode, errorcode;   e; V" y- U. j& I! [* K
int color, midx, midy; 2 S# X4 z" o2 n0 B+ m* p+ B
char colname[35]; </FONT></P>$ p! V) Y- F" U
<P><FONT color=#0000ff>/* initialize graphics and local variables */ & c4 ?7 s2 ?0 X9 b
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
. v7 k$ x/ k, S. W- d+ U<P><FONT color=#0000ff>/* read result of initialization */
+ u4 A' U, u% y. J2 b! N- F4 T( uerrorcode = graphresult();
" b+ G3 B3 ^0 ?6 d# F6 X/* an error occurred */
" e, z. [" q' N2 [; D5 V! Tif (errorcode != grOk)
4 y$ J# O8 ~+ \3 [. L5 c' M{
0 A  p9 D; R) H# Q) t; s7 c. Jprintf("Graphics error: %s\n", % |0 n- f* V5 j) h/ N7 o
grapherrormsg(errorcode));
! z+ l; K7 i$ K; Pprintf("Press any key to halt:");
9 k4 L4 B8 X/ M+ I5 C- ygetch(); - c  P% U  l) w1 [. N
/* terminate with an error code */
/ S" y0 l/ f( w# z2 Hexit(1);
; j( h4 D- I) t. b& s# H} </FONT></P>( X5 F/ d) \# e
<P><FONT color=#0000ff>midx = getmaxx() / 2;
( I. p1 Z. b/ e9 umidy = getmaxy() / 2;
: Q& d9 @) P4 V# ]setcolor(getmaxcolor()); </FONT></P>
0 Q: G4 T% f9 r9 R" t! A( m<P><FONT color=#0000ff>/* for centering text on the display */
, e# z* y$ {/ |+ S' Dsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>) Y. z. H7 \2 b4 x" J7 _
<P><FONT color=#0000ff>/* get the current drawing color */
5 O0 s  U. y8 m' t. Gcolor = getcolor(); </FONT></P># H+ X  |8 ~" v
<P><FONT color=#0000ff>/* convert color value into a string */ 0 E: a4 e; Y( v
itoa(color, colname, 10);
% Z/ k+ Q# x: ?2 d5 gstrcat(colname,
* p5 D# |% ?7 M. O" is the current drawing color."); </FONT></P>6 E0 a. l7 i% k3 d; q
<P><FONT color=#0000ff>/* display a message */ 9 c' u8 s8 N) k# @( H
outtextxy(midx, midy, colname); </FONT></P>
2 j7 s5 v$ r# I  e<P><FONT color=#0000ff>/* clean up */
  ^2 T& P+ x$ Wgetch();
2 n: P% t6 m4 z& n  ~6 Pclosegraph();
" _4 h$ f) q  s0 m( e3 }& Y3 Ereturn 0;
) ^! t3 d7 i2 A$ T* Q}
. y8 l' S/ E( A% i( D</FONT>) E% D- l! Z- w' P* @
</P>
0 ~4 I8 s+ @/ a% D0 F<P><FONT color=#ff0000>函数名: getcurdir </FONT># H8 E2 E* y2 b8 x9 w
功 能: 取指定驱动器的当前目录 1 {3 t' V" _* ]1 B
用 法: int getcurdir(int drive, char *direc); ! h% |4 V- O% k
程序例: </P>& {& P$ S( X+ V4 Q& W
<P><FONT color=#0000ff>#include <DIR.H>
. W+ [' T  B. K& D4 @#include <STDIO.H>( V; t) _+ I, a  X) k  q
#include <STRING.H></FONT></P>, o/ |3 ]: b9 H
<P><FONT color=#0000ff>char *current_directory(char *path) 7 G' M; }9 m$ g3 y8 B
{ : `( y; D6 f! N, M/ I+ ]
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
. R. J0 R4 [& P- Q0 h; X$ j$ Y3 zpath[0] = 'A' + getdisk(); /* replace X with current drive letter */ ) ~/ ?3 ?) q* x. U9 ~
getcurdir(0, path+3); /* fill rest of string with current directory */ " L. e% B5 p5 d( J) L
return(path); 6 U# o! [5 a$ L5 _4 T! q
} </FONT></P>
- P+ _6 n: p/ A0 g8 i<P><FONT color=#0000ff>int main(void)
- H! T8 N1 Z7 R- j1 T' r; S{ 1 v$ y+ [4 _0 p$ M) c  @+ T
char curdir[MAXPATH]; </FONT></P>7 s+ y' m& S/ Y0 o0 T
<P><FONT color=#0000ff>current_directory(curdir); , f. q( T" z+ z0 I0 F9 E7 Y
printf("The current directory is %s\n", curdir); </FONT></P>1 Z7 K& ~5 v% a" z' O; D* {1 M
<P><FONT color=#0000ff>return 0;
9 k4 R' n1 r2 p) B} 3 [' K/ e! v0 ?' K% p: [+ f
</FONT>
! W& D- }. R4 T* E</P>5 r9 c0 M; w' c, h
<P><FONT color=#ff0000>函数名: getcwd </FONT>4 v2 Y% {: W( B8 r' N3 y& M8 h$ v* [
功 能: 取当前工作目录 , e$ G9 ]# V* h# I- U
用 法: char *getcwd(char *buf, int n); ; V7 L* c. w! A  A2 ?' y, ^
程序例: </P>" Z/ @/ |) ^7 q
<P><FONT color=#0000ff>#include <STDIO.H>) D) U8 ^6 v4 p/ \8 P6 P  M- V
#include <DIR.H></FONT></P>
- ]: T* u. K1 q6 j, U1 _& Q<P><FONT color=#0000ff>int main(void) & D8 T' _; y; e' I9 O. a# W
{
: F% a& F+ K& r) A  b7 d+ Hchar buffer[MAXPATH]; </FONT></P>$ ?) n" A9 d6 ^7 Y6 i
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
" z. \; f( Z* {3 j+ k$ C" G/ Eprintf("The current directory is: %s\n", buffer);
, [1 I0 b. P$ V5 z6 E+ Hreturn 0;   r+ c9 d, w* z/ P0 X1 [# v5 V2 }
} </FONT>0 [/ X/ U# l+ `! i+ K  G0 k% c
9 G# X' z% G  P# }
</P>$ C9 [: {/ b4 m8 _. O1 K; a8 Z8 w7 N- E
<P><FONT color=#ff0000>函数名: getdate </FONT>
# I+ z: o, O2 s- _功 能: 取DOS日期 4 T5 |! ~3 B. |, R
用 法: void getdate(struct *dateblk); 3 ^7 A9 ^8 e! m7 j: F& y" I- `
程序例: </P>
8 O6 G& o; Y. ^<P><FONT color=#0000ff>#include <DOS.H>& m: a( J) T. D$ V  t
#include <STDIO.H></FONT></P>
# o  l" d: d: F$ ?" b<P><FONT color=#0000ff>int main(void)
+ b, |7 X3 H( k, J{ 7 v% P7 p& t6 o
struct date d; </FONT></P>
, d; L4 n- l) }! C3 _+ f& L; r* n<P><FONT color=#0000ff>getdate(&amp;d);
% z! Q1 X2 c( {% oprintf("The current year is: %d\n", & j* K7 }' C+ P2 H- t
d.da_year);
* t$ B$ Z' R+ X" e* mprintf("The current day is: %d\n", 5 B2 f! `$ k9 w2 @, x% z
d.da_day); 5 ]/ `5 T( I1 J) _7 ~7 E% Z
printf("The current month is: %d\n", ( q8 D4 T9 J2 H
d.da_mon);
: q5 I: I! g$ Hreturn 0; / ?. p) u: v& `) C- i
} 9 Y: t. B( N: p. C5 x
</FONT>
  u5 r. Y4 B) }$ z1 r7 f$ g- U</P>
( t( Y5 W0 ^& l6 d& Q- ~, p% i& e<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>8 e; _( `" k6 ^) v
功 能: 返回调色板定义结构   V. ^8 U! a" k- i1 ?! {) G) W. w& y
用 法: struct palettetype *far getdefaultpalette(void);   A6 d4 P/ Y* f' L$ Q
程序例: </P>2 s, Q  s3 Z/ E3 [
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 Q2 M. b) ]* I: J/ J4 e) |
#include <STDLIB.H>- M4 i6 Z8 W( k6 o
#include <STDIO.H>
: N; a3 g4 b/ {- n& X$ m: F#include <CONIO.H></FONT></P>
2 \' ^" u, g! W<P><FONT color=#0000ff>int main(void) 1 c2 p; u& w% h& U! a8 V! o* p0 P
{ 5 X8 y0 h$ _6 ~5 E7 b% o& p
/* request auto detection */ ' U' d" z- ?& o( G9 ^' s
int gdriver = DETECT, gmode, errorcode; $ R+ K  M7 D0 ~- Q! E" s4 m' d8 c1 l. f
int i; </FONT></P>
+ u3 I4 V6 t" n6 Q; h4 i, X. W<P><FONT color=#0000ff>/* structure for returning palette copy */
& w4 B. V( ?0 M/ h8 x6 q% cstruct palettetype far *pal=(void *) 0; </FONT></P>
9 @1 x, [) V  i# j, C) I: b<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ z7 W8 c$ ^  ^" p5 i) ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 Q9 G0 L( ^3 [+ j# f
<P><FONT color=#0000ff>/* read result of initialization */
4 I* H% _4 e) H3 a* b- O  i1 oerrorcode = graphresult();
# e9 Z: P0 l  t6 H% h/* an error occurred */
0 ?( }. A( M* b# e; Tif (errorcode != grOk)
1 k6 u! z" ^. c# k, Z  O1 L. A{   {. z! f4 O- ?- q5 k
printf("Graphics error: %s\n",
0 E! f) U" j- F9 u/ {5 T5 Z3 H* x5 Tgrapherrormsg(errorcode));
% [2 L4 e! u7 O, h( F( ~  [/ Zprintf("Press any key to halt:"); 1 H' K5 P- Y) O) s" X- d% }* H
getch();
* z9 t0 f3 q+ W' Z6 i: M/ E/* terminate with an error code */
7 {9 Z# j, S. w# Oexit(1);
- s% l' A$ ]4 Q; q3 t* {7 g' I} </FONT></P>
9 s5 P. P) ?# H<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
% Y# `9 S) l# F' c<P><FONT color=#0000ff>/* return a pointer to the default palette */ ' [; N9 g" [" f
pal = getdefaultpalette(); </FONT></P>
5 ]% b5 p# T# q5 T* N8 ]<P><FONT color=#0000ff>for (i=0; i&lt;16; i++)
: w6 h4 |4 {: b" X4 E- G{ 3 x, |; \( G2 n1 X7 n
printf("colors[%d] = %d\n", i,
, y6 X3 n7 }8 b  k3 {pal-&gt;colors); 2 A* R; y3 {% q
getch(); 3 G# U1 d- N/ N' X# F. U
} </FONT></P>. E# H- P# S# C7 f0 K7 _
<P><FONT color=#0000ff>/* clean up */ 1 ^) _4 p* J7 [2 s. y4 K- F7 I; B
getch(); 8 R: I# Y& h5 o: y/ J6 c
closegraph();
3 _7 C# O- U- V2 b; l, T5 G: breturn 0; $ }- K/ k) `+ }. U1 C2 {
}
6 n; M+ |2 o1 V0 B; R  n. M6 F</FONT>
6 o5 S6 P1 y0 T9 v, e! @7 p7 `</P>' A/ v: r! T6 a% q, q# o
<P><FONT color=#ff0000>函数名: getdisk </FONT>* L: P- S1 |0 ~# V! L8 ?2 Y
功 能: 取当前磁盘驱动器号 ' A9 V. q5 y7 N2 P" m8 u$ G9 n
用 法: int getdisk(void);
: D  C) c3 ]) ?8 Z5 ]6 z程序例: </P>
0 e0 {/ J3 R6 r1 P, w<P><FONT color=#0000ff>#include <STDIO.H>
3 u* F3 M( j+ g2 U/ L! u#include <DIR.H></FONT></P>
2 e; q; L1 d9 M) `9 `, r8 |<P><FONT color=#0000ff>int main(void)
% ^+ Q) ?  I4 V" T{ + F9 N8 ]: T/ r/ o( b
int disk; </FONT></P>: i0 }% e9 I1 w: k! m
<P><FONT color=#0000ff>disk = getdisk() + 'A';
: @6 {, {5 f% q; J+ Mprintf("The current drive is: %c\n", ( @% Z. c: r9 R4 [/ O/ _# ^
disk);
/ N0 \: J" L: Y. O4 Jreturn 0; 2 T. e$ r8 q* W6 Q' d. p6 B
} 1 D  d5 d+ R% z* s

/ z7 B( ?6 S: A$ v: c' L</FONT>/ f8 |: X, V% _; U, g
</P>
6 K2 Q4 W4 B1 c# [$ }' C0 d<P><FONT color=#ff0000>函数名: getdrivername </FONT>
4 `2 W4 Y# @- H5 i% \! f功 能: 返回指向包含当前图形驱动程序名字的字符串指针 * e, [+ l; c  S. _! {& `  E
用 法: char *getdrivename(void);
" m7 r, Z! X, Y# n: [程序例: </P>
* E0 B7 Z/ G- D% o0 v* D: i<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 a8 Q  I8 }0 g. I+ K6 f! U# b#include <STDLIB.H>
0 y5 v: f" }+ M, ^#include <STDIO.H>
' r4 R6 _' P7 x: c#include <CONIO.H></FONT></P>
* `# s0 Q9 x+ E8 O' E<P><FONT color=#0000ff>int main(void) , f9 p+ v: m9 ^
{ 0 Q7 r$ h! L; l6 w, E
/* request auto detection */ ) a) M' b- g% n
int gdriver = DETECT, gmode, errorcode; </FONT></P>& Z: q* t# z3 r7 |: Y7 `3 P: B- ?
<P><FONT color=#0000ff>/* stores the device driver name */
, B- W4 R9 W+ Hchar *drivername; </FONT></P>
0 i8 S' {" u$ G<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' g- ]. R; V& s) b; C/ Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># [2 ~( `  F- B3 I
<P><FONT color=#0000ff>/* read result of initialization */ ' P7 r7 }' w+ w" c2 c7 f/ m5 W* e
errorcode = graphresult(); ' X# J! b/ _5 L- Y4 S- ~. e. c$ X
/* an error occurred */ ' [. r  Q. c3 d6 C4 A1 b
if (errorcode != grOk)
7 K  m# g& Q( \/ V{ - B! u; G7 ~( A# G
printf("Graphics error: %s\n", * U' q  z1 V" x, ^7 F" Q
grapherrormsg(errorcode)); + [7 o) p, j9 t9 ]  K% V& _
printf("Press any key to halt:");
! a. a; \9 Y1 h& {6 Z7 Fgetch();
  J# g) `" A: F8 V# v/* terminate with an error code */ 4 K' O3 w3 b' R3 k' b
exit(1);
: b. v6 Y, ~" A* y( `  B, F} </FONT></P>
1 p# ^* @, }( n2 f! j5 ~9 r<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
( O' a3 g  \/ h/ G<P><FONT color=#0000ff>/* get name of the device driver in use */ , r+ ~0 Y- n" t1 H, p
drivername = getdrivername(); </FONT></P>. P. ]4 l: G' f1 ?5 V, f8 ]
<P><FONT color=#0000ff>/* for centering text on the screen */
5 _9 v3 a- D/ h1 B; [! R; `$ Z0 lsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
! c: n% H: x4 _* q3 \& j<P><FONT color=#0000ff>/* output the name of the driver */
; p6 W" s7 H2 y& ^7 \$ j  ]outtextxy(getmaxx() / 2, getmaxy() / 2,
; h* S0 p5 J: z0 f7 T% ~/ ydrivername); </FONT></P>
! _# }# L+ H  H0 R2 r0 w. A" ^, B4 [<P><FONT color=#0000ff>/* clean up */
' f* _6 A  o/ }5 n/ n* ^0 K  `getch(); + M; f2 q! T4 d
closegraph();
. z9 ?; B! R5 M) ~  Ereturn 0;
# R( d% M. L) w$ J. U; T) x} * K; @  o  Q1 f9 z6 g! J
</FONT><FONT color=#990000>  s+ ]6 \/ w; z+ ^1 ~$ n) n
</FONT></P>
" W/ }+ Q0 Y7 T( q" S5 x2 k<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>4 y2 u! L! m; d. x. [& H) Z& D
<FONT color=#000000>功 能: 取磁盘传输地址 7 |& A& a' O; M, q
用 法: char far *getdta(void); ! J3 P, Z% g- A& T
程序例: </FONT></FONT></P>
6 a+ g* i/ P6 P! @* N2 J6 Z! o<P><FONT color=#0000ff>#include <DOS.H>
, i8 ~, u& x8 D! m& b# f. C* L#include <STDIO.H></FONT></P>% S  V, X* s6 Z. V2 X
<P><FONT color=#0000ff>int main(void) ) L) N1 x. R: D
{ # w+ Q! v! Q" z3 M8 N
char far *dta; </FONT></P>
8 I& J  A) A( h$ l: F<P><FONT color=#0000ff>dta = getdta();
0 p" @- [- T1 {; M/ pprintf("The current disk transfer \ ! A# Z1 s6 v1 ^3 e9 j- e* }& B' f. ]# \
address is: %Fp\n", dta);
0 J8 Z' s2 }: {+ e2 q& D+ ureturn 0;
; E2 A0 \& x& _4 U}
5 g5 b! N2 C/ ?$ ?; O( c1 Y2 _8 {! p</FONT><FONT color=#990000>
" w& l4 `0 v  f2 x. e% l</FONT></P>8 h- m  ^; v- r3 U( o& U
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
# |  T  n& @' N" r/ R2 Y; A<FONT color=#000000>功 能: 从环境中取字符串
+ x: B, i/ K5 \- ~4 w5 h用 法: char *getenv(char *envvar);
, X9 r* U6 B8 q5 K$ s程序例: </FONT></FONT></P>2 y: U9 s( g& E/ L8 Z2 r  x
<P><FONT color=#0000ff>#include <STDLIB.H>
' B; d; [/ f2 i3 o#include <STDIO.H>/ e! e1 F) N& w! D" f
</FONT></P>" C4 }2 |0 x3 B2 q
<P><FONT color=#0000ff>int main(void)
5 ?# l+ m  Y% B' @% t2 s{ ! e  b6 ~6 l+ V* P. Z# m. t( [
char *s; </FONT></P>
( O  y' i$ `+ V# C7 \<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ ! ]$ Y, u) {/ Y+ x
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
% a( T( \0 q3 w) ^: n<P><FONT color=#0000ff>return 0;
7 ?) ?" J" N+ o0 i. Z+ t} </FONT><FONT color=#990000>
' H5 p( M) {* [
: I) o2 `, ^( A0 T9 a  @: ^9 o/ }+ u4 a5 T
</FONT></P># {2 z% R$ s& E
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>
( C0 f/ Q! j/ r  [/ o功 能: 取文件分配表信息 * X  f1 j. ~4 J
用 法: void getfat(int drive, struct fatinfo *fatblkp);
: A( u* b' [, D5 F& G6 r0 g程序例: </P>* ^  Q2 H3 J8 h4 p
<P><FONT color=#0000ff>#include <STDIO.H>
8 \1 U% ~9 z. f: W% h) H#include <DOS.H></FONT></P>
% F1 `, l, x; m6 E<P><FONT color=#0000ff>int main(void) " n" Z8 A6 R* c
{ 1 l+ k# j4 K  v1 S6 \3 p3 E
struct fatinfo diskinfo; 1 ?8 V) n; i( }  {" Q% K
int flag = 0; </FONT></P>
: b6 o7 x7 Y6 Z8 c<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); / u$ @1 K, v% U6 w& n7 E7 z
getchar(); </FONT></P>! ?( v! |/ [5 E9 |, f
<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
6 y4 [6 Z: U1 K. Q$ ^. I/* get drive information */ </FONT></P>4 M/ ]* T* ~7 M
<P><FONT color=#0000ff>printf("\nDrive A: is ");
  _. p. H1 H2 C: e' f* v  m7 Hswitch((unsigned char) diskinfo.fi_fatid)
1 d: {7 r' [: y{ # V. J1 @8 B8 q$ j* P' {* D
case 0xFD: . i5 P# D4 @9 v; j
printf("360K low density\n");
, C$ e" [- p9 B! y( ?+ ^& kbreak; </FONT></P>5 s  M' w7 f/ d" |; [- O
<P><FONT color=#0000ff>case 0xF9: % m+ L3 G$ Q+ X2 a3 _( v4 I
printf("1.2 Meg high density\n");
" E5 u4 O8 o" Pbreak; </FONT></P>- g& E' I: w$ v: ]' A/ c
<P><FONT color=#0000ff>default:
/ M$ {0 R4 u  B- rprintf("unformatted\n"); 8 }: L2 \$ }$ _; F- Q! O# q
flag = 1; 3 ~; o" @3 S5 ?' x: b) g$ c# o
} </FONT></P>
; e( U# O/ G* R9 a* j9 C<P><FONT color=#0000ff>if (!flag)
# C3 X9 P) Q% x) \{
6 p$ B# ^% u4 K( \printf(" sectors per cluster %5d\n",
1 Z* ^0 b; s% ^  T! _diskinfo.fi_sclus);
/ L$ \' y* ]$ F& Fprintf(" number of clusters %5d\n", . V( @' \( n, j# S" D
diskinfo.fi_nclus);
( b6 G- `) R7 h$ J& s: V+ `printf(" bytes per sector %5d\n",
3 P) e: u; K7 c& ?/ Kdiskinfo.fi_bysec);
% l! T* T+ E1 d, H% }  Z} </FONT></P>! U$ r0 F6 n) }- @( `( L$ Y
<P><FONT color=#0000ff>return 0;
3 q8 I, Q1 F1 j  {* A' ?# u}
9 p* R9 P8 P$ a" a4 k# |</FONT>
) z5 _0 }9 S+ j1 A, T$ C</P>
! N& I+ S4 z1 b5 {7 g) @' }' {- D<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
9 Q* Q6 x' {7 [* j9 d" Q: L% J5 p功 能: 将用户定义的填充模式拷贝到内存中 7 `  j3 M4 z: y$ s  b. z. v2 |
用 法: void far getfillpattern(char far *upattern); # w: u/ m+ w& N( e3 G8 N1 Z
程序例: </P>
& _1 m; A, \- S* E+ ~<P><FONT color=#0000ff>#include <GRAPHICS.H># v5 @/ [; ^- S  {
#include <STDLIB.H>
; a$ y: a4 i) a) |; C- a; A6 \#include <STDIO.H>" {6 n% i: d3 a9 t1 V
#include <CONIO.H></FONT></P>9 D0 ]/ O) k. m6 w: V# P2 E
<P><FONT color=#0000ff>int main(void) 9 N( Z, P+ t7 X- S8 k
{ 8 n8 \) w# W8 {) ]: U+ o
/* request auto detection */ + j' R! u  U* K7 q0 g
int gdriver = DETECT, gmode, errorcode;
* V7 {9 ^% n/ ^' V9 `int maxx, maxy;
* e+ S5 z; ?+ j# r& H, Ichar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>8 @5 V- l2 \2 q/ H
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' f2 J9 V& c. F# ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* x/ h' h. }- r) C# m5 M/ F<P><FONT color=#0000ff>/* read result of initialization */ & D3 y6 K- s, H& ~' i
errorcode = graphresult();
, S& J, s- P' c4 E3 ~7 [+ qif (errorcode != grOk) /* an error occurred */
' z# b$ t' L& G{ " ]. u; G0 J- h. T
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 F# w/ ]# P6 b- G# S
printf("Press any key to halt:"); - ^3 C/ P* a: m9 i% m7 X
getch();
: Y9 g' x3 ?% B  Pexit(1); /* terminate with an error code */
& D* G- p) U" U7 s; @" X4 G0 }+ g} </FONT></P>% T: d" F' z" Q" _) A
<P><FONT color=#0000ff>maxx = getmaxx(); - G9 v, W$ b) ?: y' W) U. |
maxy = getmaxy();
7 _0 i# |3 }9 q+ j, N1 Hsetcolor(getmaxcolor()); </FONT></P>2 r% E4 R0 v; T
<P><FONT color=#0000ff>/* select a user defined fill pattern */ & o0 R$ `: b9 ^* ^
setfillpattern(pattern, getmaxcolor()); </FONT></P>
; E3 G. a5 Y3 c4 U* w* J<P><FONT color=#0000ff>/* fill the screen with the pattern */ ) _2 v9 O7 l5 P$ w0 p
bar(0, 0, maxx, maxy); </FONT></P>' S$ A8 o$ m7 b! d8 F6 H
<P><FONT color=#0000ff>getch(); </FONT></P>3 F2 U! d" J3 V) r- m; i8 x' d7 F
<P><FONT color=#0000ff>/* get the current user defined fill pattern */
) |. p. E5 R' u7 G% qgetfillpattern(pattern); </FONT></P>; Z) O, Z: ]  A% f# ]+ \6 s
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
" j' z8 L) T8 v  T- ypattern[4] -= 1; : v; G7 o$ ^+ k9 e- ]2 i1 ?. n. w
pattern[5] -= 3; . t3 T8 v3 v$ K" G
pattern[6] += 3;
2 k8 s+ y7 E' f" a2 H/ wpattern[7] -= 4; </FONT></P>
  u; O; V& f/ ?5 A<P><FONT color=#0000ff>/* select our new pattern */ & O6 R$ \" E" K2 j0 h/ ^3 U5 }
setfillpattern(pattern, getmaxcolor()); </FONT></P>
, @1 F& h) d8 a<P><FONT color=#0000ff>/* fill the screen with the new pattern */
1 {. z5 g3 N6 p* S7 `; xbar(0, 0, maxx, maxy); </FONT></P>
4 `5 F) z/ g1 _<P><FONT color=#0000ff>/* clean up */ ! P% q3 w) w: t/ f0 M5 U! u, K
getch(); 8 v0 m) j# }* a' ^5 I8 D
closegraph(); + J3 Y- k4 i/ W% d2 S
return 0;
* T! X' W' W2 y  }" R4 q} - z3 e& Z" f, i1 I
</FONT>4 P$ ~  O* i. B" e2 Y
</P>: j* o: Q. e6 A$ `% P  R9 Q- G2 L
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
8 X- ]% V6 e- N7 e; t功 能: 取得有关当前填充模式和填充颜色的信息
$ K, u  O& e2 `9 z7 ^5 l用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 4 ]# Z: ^- x- W- a' I
程序例: </P>( g$ J& y, h" [9 E% _0 D
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# l% o  x* u7 ]$ a9 o+ T#include <STDLIB.H>
* l  b, G4 D  g! }; [5 T#include <STDIO.H>
4 |0 m4 M! L+ B& K3 O$ e' r1 S$ T#include <CONIO.H></FONT></P>+ k, y# r, S. u5 K
<P><FONT color=#0000ff>/ the names of the fill styles supported */ 7 E( ]' H! V/ a$ Z. ~2 C6 k0 Z
char *fname[] = { "EMPTY_FILL", 3 M  O- a% z1 q1 w6 N4 ~8 l
"SOLID_FILL", - ^3 H4 I, L1 H$ M) f
"LINE_FILL", 2 i) U' s7 b! h
"LTSLASH_FILL",
: ~0 c4 {! |1 [2 F3 x$ r"SLASH_FILL",
  V0 U, N! w4 h! [( j8 n"BKSLASH_FILL", # l9 z, c" N) i6 k( ~$ v! E( J
"LTBKSLASH_FILL", & k# G+ Q" d$ Z- W5 U
"HATCH_FILL",
, h3 H* ?4 m4 D2 ?' @4 K8 P9 {"XHATCH_FILL", 6 l3 b- K' |: e$ |6 K( D
"INTERLEAVE_FILL",
4 Y" `& C; ?- p; l"WIDE_DOT_FILL",
3 I# _# V& }2 h7 j"CLOSE_DOT_FILL", 2 A; d( B2 B+ W9 ?2 ~% N
"USER_FILL" ) a( v0 n- r" i4 N2 P
}; </FONT></P>
( |5 Y6 \' c$ H4 P+ L<P><FONT color=#0000ff>int main(void)
3 g+ b5 q$ J' h, W- x{
1 Z1 p# ~0 w+ C" E6 A/* request auto detection */ , O! w. ^7 v# u- o1 a) ^
int gdriver = DETECT, gmode, errorcode;
: s' I' q. F8 u/ j/ p1 u/ Istruct fillsettingstype fillinfo; * q' c( O- M1 N' i
int midx, midy; 3 f8 Y* ?& V  h7 ~
char patstr[40], colstr[40]; </FONT></P>
3 q1 t& u) [0 T. A: I<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 P- v7 j  M' {, c, Zinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" k! }' [; d; Y4 Z- o+ U) J
<P><FONT color=#0000ff>/* read result of initialization */
/ v& \) a' E9 Lerrorcode = graphresult();
3 D1 ~3 b' i- o& r6 Jif (errorcode != grOk) /* an error occurred */
! @. y, Z4 Y% g) W1 R+ H{ . Q0 ~# u& I1 A. a# t+ ]3 ]! ^
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 `0 B' g* H4 g: Z
printf("Press any key to halt:"); 6 C, I4 I' w4 z
getch(); : S4 M/ t6 h8 u4 J1 g  A: o
exit(1); /* terminate with an error code */
" I8 L, k* p2 {+ j# i& _} </FONT></P>
$ p1 Y5 o5 ]8 S. j<P><FONT color=#0000ff>midx = getmaxx() / 2; 9 t8 `* X% W2 `: V/ T  E2 S- X1 S
midy = getmaxy() / 2; </FONT></P>! ^% H. H, @6 c
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ 2 U6 n: w, L7 ~2 B9 b: K+ u& w
getfillsettings(&amp;fillinfo); </FONT></P>) P7 P( r; @  w9 o& C- j9 l" @
<P><FONT color=#0000ff>/* convert fill information into strings */ + i3 p& r3 B+ Q* g- @3 l, g
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
' `5 T; d3 {3 n. n2 gsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
+ r# @2 |. k. ?1 T: T; @<P><FONT color=#0000ff>/* display the information */
- s* Z: h8 |5 _' s: }' n2 Rsettextjustify(CENTER_TEXT, CENTER_TEXT);
- f0 \2 Q, g- D  qouttextxy(midx, midy, patstr);
9 O! i. n0 D+ B. U/ K' Qouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
9 r- ]) ^3 i) Q) m$ w. Q<P><FONT color=#0000ff>/* clean up */
  \; N/ _, r3 A; Jgetch();
! l8 S% I/ E% R$ T* I- W" Zclosegraph(); / H5 s6 L, h5 \4 r4 U. _0 K& ~. r, H
return 0; & s( f7 m* f+ F/ F1 _' v
} & @8 h6 k. x; l, X; r7 J
</FONT>* z$ C, o" s" W0 j
, Z6 o7 B$ @5 l" `2 r
</P>/ c4 X' S: B- o# J2 O  N9 r9 t
<P><FONT color=#ff0000>函数名: getftime </FONT>9 ^" z5 s" G2 E. G4 v: V
功 能: 取文件日期和时间
* R* I, S$ h: f2 l7 ~( E用 法: int getftime(int handle, struct ftime *ftimep);
% n: B9 ]7 o* D5 K- J& Z6 U- V程序例: </P>6 O1 G% c4 i% Q) f9 b
<P><FONT color=#0000ff>#include <STDIO.H>
, j' `% z6 C0 p* q: D" ]! c#include <IO.H></FONT></P>, q5 }; M/ C( `0 Y) n# Z( p
<P><FONT color=#0000ff>int main(void)
% P# i* m. I8 u{
! j) E2 x; S. KFILE *stream;
2 H0 E# ?: P% E9 P. N2 U8 B- d( ustruct ftime ft; </FONT></P>
+ o! q+ s( t& P0 G% S) d. G<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
; @1 K7 _  V/ s! P8 D"wt")) == NULL) / n* J/ p+ c) g8 U
{
' v% I* N" e5 U# [" Y0 X, y2 Lfprintf(stderr, 2 n0 o) p8 ?% ~+ r. }
"Cannot open output file.\n"); / T% _5 d2 j- a9 o
return 1; , T) |. c) S/ o) H; X
}
3 Z3 `2 _* O# f5 qgetftime(fileno(stream), &amp;ft); 0 d- a$ M9 G* ~8 e9 |. l, t
printf("File time: %u:%u:%u\n",   [! u& S, Q7 h* T1 e4 e. d
ft.ft_hour, ft.ft_min, 6 J+ ]5 _" B) h8 P
ft.ft_tsec * 2); ! x! U! _: w0 e9 p2 y/ a+ p
printf("File date: %u/%u/%u\n",
9 y3 V3 @( ?0 W3 R% R) z  M4 Vft.ft_month, ft.ft_day, : e% ?8 }7 g8 b4 J( r
ft.ft_year+1980); 9 |8 f6 v4 d  l! T5 |
fclose(stream);
5 ~2 _0 l8 f+ ~return 0; ! \* y' Q# B  E- S9 Q
} * n: c  ^' C. ?
</FONT>
6 f% u( \; g* B( k  V! V
- _/ c( p5 ^* g+ I8 F</P>. C4 u* B0 X0 b, d1 i$ @* G
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>; Z4 {2 _, U0 m
功 能: 返回当前图形模式
4 e: d0 N7 _/ z0 K8 i用 法: int far getgraphmode(void); 3 I( _: N; Y; S- R$ M* E
程序例: </P>
1 ?4 x6 M) |: M. x2 v<P><FONT color=#0000ff>#include <GRAPHICS.H>
. z! J" g1 ^4 n8 Q- [' J) s#include <STDLIB.H>5 d  J& J8 V3 f
#include <STDIO.H>3 D. s+ a1 T% V! i. |
#include <CONIO.H></FONT></P>
1 F1 g  ]( x4 Y2 B/ Q# h<P><FONT color=#0000ff>int main(void)
! M& [! G) {7 U! ]0 k+ C{
* n% C9 ^* }+ t& h1 F( F" C/* request auto detection */   M4 c- R; F0 |0 O; d2 X
int gdriver = DETECT, gmode, errorcode;
3 L$ p; z* Y; kint midx, midy, mode;
& i1 \* @+ E( w% A$ k+ m) E" |: b/ s2 Ychar numname[80], modename[80]; </FONT></P>5 E# m: `* e" k6 c
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 H. b4 c4 @2 L1 R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>% }) S* E/ C4 F; P# j+ {
<P><FONT color=#0000ff>/* read result of initialization */ 6 d0 \! x5 Y8 V
errorcode = graphresult(); % ?3 F) c9 c" b1 S
/* an error occurred */
2 T- c8 p6 ]3 m9 X+ x7 Bif (errorcode != grOk) $ A! r! h4 a" V& S" [, O
{
3 C& H9 G8 T" c9 T( E' nprintf("Graphics error: %s\n",
* P. B; M3 {0 @3 T. Igrapherrormsg(errorcode));
! K+ N8 J2 M) r+ ]" o+ Y9 Wprintf("Press any key to halt:");
9 N+ S( w+ u& R8 u+ K* Y2 agetch(); . K4 x$ b+ c/ \# K& X
/* terminate with an error code */ 3 g8 P# S8 m! x) |) f
exit(1); 1 I! L1 q+ }/ r
} </FONT></P>
3 w" m9 N3 s) F* l5 h) _- ]1 u0 Q8 M<P><FONT color=#0000ff>midx = getmaxx() / 2;   Y6 x- F1 t7 b0 w
midy = getmaxy() / 2; </FONT></P>
8 n2 D* I$ k$ o% a+ N$ R<P><FONT color=#0000ff>/* get mode number and name strings */
  \9 i$ v& Q' h0 J* N9 Kmode = getgraphmode(); 0 {$ ?8 z9 F" `0 e- Q
sprintf(numname, 0 b5 m1 ^& t! d6 k* T0 v; Z9 O
"%d is the current mode number.", 1 @+ R+ h+ P- m: g* X' V  q3 Z
mode);
6 d/ U5 s: v" R5 x9 [7 B. csprintf(modename,
! J  A0 o$ p% H) _: `2 H"%s is the current graphics mode",
; G$ V1 e) S! c- _+ F8 kgetmodename(mode)); </FONT></P>- o$ s! Y& Z3 u6 U% |
<P><FONT color=#0000ff>/* display the information */   ~0 O& [9 v1 p& w2 l
settextjustify(CENTER_TEXT, CENTER_TEXT); / N% p8 @7 |3 e0 s( i! v1 Y  F
outtextxy(midx, midy, numname);
8 f; q& o) [4 u  R) Uouttextxy(midx, midy+2*textheight("W"),
! S8 Y0 U: K; Q% a5 Z3 rmodename); </FONT></P>* N2 C2 e( M( s. n$ m# E. T- A4 p' ]
<P><FONT color=#0000ff>/* clean up */ " J. j7 z1 \2 k3 K+ B- `( d. O
getch();
$ I, O! m# p8 Z( ?, K3 Eclosegraph();
: ~1 t9 H/ a3 W6 W. c! rreturn 0;
2 M/ O9 J2 {. g( k! e} </FONT>
( S. Z# P1 J% G, F; t6 O/ g2 H+ `+ d7 n3 P' `# G( i7 M7 V
</P>
2 j1 ]# A: k8 I1 N% B<P><FONT color=#ff0000>函数名: getftime </FONT>- r) k5 j& x/ o5 C. X
功 能: 取文件日期和时间 . s0 h! v& A8 n
用 法: int getftime(int handle, struct ftime *ftimep); , G7 |) e# }' b+ o6 L' ?0 @
程序例: </P>2 w+ `2 S/ X% T+ v4 `' y  w
<P><FONT color=#0000ff>#include <STDIO.H>5 e; [, B& B) Y) Q/ ^8 c/ H4 G3 l
#include <IO.H></FONT></P>9 I( e4 W/ g" B0 o# J6 X
<P><FONT color=#0000ff>int main(void)
2 r. }8 L! I, Y, p( a{
' w0 p7 k! R* ?3 ^+ R7 |" JFILE *stream; # G# P( s: e* L0 V/ P( l) \' P
struct ftime ft; </FONT></P>! d% H) Z+ A- G& [9 b6 z% K) g
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", * ]. E3 Y, P+ G
"wt")) == NULL)
$ I  ~% t( f9 x6 o" o{
; i6 B3 ~7 j( S. I1 }/ N2 Tfprintf(stderr, & G3 u* Y, Q  h* Q  y8 m
"Cannot open output file.\n");   Q1 d7 f* v: W2 O) \# u4 N3 K
return 1; $ r2 q6 b. T* D
} ' Q& K/ E0 ~0 t8 a- E
getftime(fileno(stream), &amp;ft); 9 o3 F' z2 z) c
printf("File time: %u:%u:%u\n",
/ K' \; H$ A3 p' ift.ft_hour, ft.ft_min, / a4 \! H0 E  R9 E4 D1 R, i3 ]) n
ft.ft_tsec * 2); 2 a0 w, Y6 R: v& t6 x" A, Y! ^# G
printf("File date: %u/%u/%u\n",
, |2 Y4 A, c0 d1 S5 m  @5 {- Kft.ft_month, ft.ft_day, % j/ {9 O4 F0 u5 ^
ft.ft_year+1980); " [, y, c5 o& H( D9 F0 J
fclose(stream);
. L% b. ?" {& e2 Dreturn 0;
) ^/ v; c5 q7 R2 y% \) Z} </FONT>
% J  b" l4 z$ M
( {4 _* F$ }8 v+ c  J. I% R
8 Z! w, Q: e; d0 p  T# N( p. o</P>: m) d; H- j5 E% ?
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
% T( I5 d! {# |. u功 能: 返回当前图形模式
" J& u7 y' U; k9 r9 t" ]用 法: int far getgraphmode(void);
& G7 f6 I/ Y9 r0 \+ }' t9 g! w# |程序例: </P>" j& L5 Q! T' d1 }& K
<P><FONT color=#0000ff>#include <GRAPHICS.H># S0 [5 H3 l& ^) K+ d
#include <STDLIB.H>9 c) E" N# y7 q  @
#include <STDIO.H>: q* z( ]) S# S  x" U
#include <CONIO.H></FONT></P>$ r7 a8 w& v( t9 o& H0 D
<P><FONT color=#0000ff>int main(void) 9 _+ G' _" O( e% q. B
{ # e& k& V2 O: n5 [' ^  v( W
/* request auto detection */
: g1 g1 M1 n! e; N" Pint gdriver = DETECT, gmode, errorcode;
& V1 _: q7 k! O7 rint midx, midy, mode; ' U! ]% ~/ A7 l1 `. R( y$ b
char numname[80], modename[80]; </FONT></P>
: C" B! C% v. \* L2 O! P7 K<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ ], I6 F! I* Q4 i" r& p1 h2 V9 U9 w
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- M( p) ~" Z' O+ Y2 X
<P><FONT color=#0000ff>/* read result of initialization */
+ T0 F( C$ f9 ~errorcode = graphresult();
6 G8 M9 c: x3 I- f/* an error occurred */ ' J; Q+ K+ b! w. B+ M! }4 {: m
if (errorcode != grOk)
. u8 b7 q0 `5 s$ Y$ b$ ]{
- r) [' m7 V! N, l. aprintf("Graphics error: %s\n", 4 f, A8 ~0 W' L) R% G
grapherrormsg(errorcode));
% }; R: ~. N: Iprintf("Press any key to halt:");
) [" F7 C9 t1 }) z# a5 w- ]getch(); ) ?$ s4 k" d3 a1 L
/* terminate with an error code */
- I9 e7 Q: n7 H$ ~- C# q9 V4 a0 I2 eexit(1);
5 }9 g- o. s5 Z} </FONT></P>
. u' a& V! u) g& {<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 B$ m* l: t1 K) Tmidy = getmaxy() / 2; </FONT></P>* K- y0 R* }4 o: ~7 b* [/ B
<P><FONT color=#0000ff>/* get mode number and name strings */
. m9 l& w; O* P+ Q4 ?mode = getgraphmode(); 7 U% w( ~' e4 C/ p; _
sprintf(numname, + [! U" j3 h9 n& h6 g* F4 d
"%d is the current mode number.",
* [# g/ z, V: x) Gmode);
8 p$ ^( A* i: j$ v5 a: Wsprintf(modename, ) J) R) j; X+ {
"%s is the current graphics mode",
( L) ?( @5 k3 q" d9 j" P' Qgetmodename(mode)); </FONT></P>. p3 m. A  N! B8 w% m" v0 g% |! e- O
<P><FONT color=#0000ff>/* display the information */
5 q4 i  ]. @) isettextjustify(CENTER_TEXT, CENTER_TEXT); 8 ?$ W9 m8 n1 J6 m4 `) k
outtextxy(midx, midy, numname); ! r  c' d1 U4 ]+ m
outtextxy(midx, midy+2*textheight("W"),
8 a+ h* r7 t) l  E: Fmodename); </FONT></P>
* V+ \5 h* m( }( Y* T' w3 i; S<P><FONT color=#0000ff>/* clean up */
+ F. L; b! n4 ?getch(); # z6 l$ ~# U! _9 P$ B+ D4 l; d6 i
closegraph();
; c. |9 T2 A; c; h$ I# `# D' w5 ereturn 0; - I" _* ]- H7 c5 F( ?" ?" B
}
: e  z0 X" ^3 `% \! ?$ \5 H</FONT># B8 z6 n! a3 M
</P>& z6 U( d/ w2 T" n4 m# J
<P><FONT color=#ff0000>函数名: getimage </FONT>$ F1 V6 ^9 `8 e4 t0 \4 N& r
功 能: 将指定区域的一个位图存到主存中
0 \8 V7 o# {3 B  f/ U3 L- f8 m用 法: void far getimage(int left, int top, int right, int bottom,
) K+ p3 I0 L8 evoid far *bitmap);
+ ^5 j5 F* [  g' l/ H程序例: </P>& _6 _3 k3 P$ r) J7 C  U
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# i6 b$ Z% w& X3 ?8 G' r6 g, j#include <STDLIB.H>5 {$ l6 _  y! y2 @% ?0 {0 y4 }( N
#include <STDIO.H>
2 b* n) l4 j3 H! h! J0 c#include <CONIO.H>
: `, N& D5 M9 F& z- l1 t9 |#include <ALLOC.H></FONT></P>% U7 I3 A; _4 G- X
<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
; N4 n& q$ M  J. F8 @; N- avoid restore_screen(void far *buf[4]); </FONT></P>
: _8 R  F; E% z<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>3 R- b- L) S( v. w+ c
<P><FONT color=#0000ff>int main(void)
$ g5 d, V) r' ?2 K1 m6 i{ 8 r, l  W. i2 X& m: q7 E
int gdriver=DETECT, gmode, errorcode; ) S, ?7 W- [- q; G
void far *ptr[4]; </FONT></P>
3 D* @5 C0 h5 S) [( c" y<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
' \( U, h4 f: D# @; pinitgraph(&amp;gdriver, &amp;gmode, ""); ) c. @8 i# o6 w3 r, C7 k# ]  _
errorcode = graphresult(); /* check for any errors */ 9 z. G0 O  b2 }1 ?: @
if (errorcode != grOk) $ g6 I4 k4 P0 o0 C3 v' X* r
{
  V2 W- A& j) \/ F- N# ~. \) xprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # B0 ]% W9 T, C# g. g% H" b+ V5 h. t" s
printf("Press any key to halt:"); % I0 ]9 t: V% z
getch(); + B; n+ O+ O1 J- n0 b
exit(1);
. T* `- Z1 ~5 O  J}
# e6 s  c, n7 `/ P2 E6 o9 n+ bmaxx = getmaxx();
& _5 f. J' h( Y5 a4 K  K! \maxy = getmaxy(); </FONT></P>( |5 A  J' d+ R; d0 ?  N% r% J$ c
<P><FONT color=#0000ff>/* draw an image on the screen */
, I: J, ~% \5 T2 frectangle(0, 0, maxx, maxy); 2 C& n: x8 G& V; f8 s) _: p' X
line(0, 0, maxx, maxy); - m- S% {+ o8 m# r) e. ~
line(0, maxy, maxx, 0); </FONT></P>
( Y4 |# x9 o9 w8 n<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
- ~& T# b2 C. ^) d3 k; P" C3 Cgetch(); /* pause screen */ 6 ^: k/ C( Q* l
cleardevice(); /* clear screen */ , T4 i# D/ G4 c! q6 S) J
restore_screen(ptr); /* restore the screen */
5 v' ^0 V: J! L9 `8 dgetch(); /* pause screen */ </FONT></P># r8 z% x; G1 k/ M) B
<P><FONT color=#0000ff>closegraph();
! H6 m* a) r: u) P; \% i  sreturn 0; 6 H% n, ~: I% g- b" w6 A
} </FONT></P>, Y1 g3 A& q) [6 n! l8 T. M
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) 4 A/ L8 g* l2 ], x7 m
{ ! K. U9 I2 x9 {& q: y
unsigned size;
7 C- Z/ X6 h$ L4 }$ U. ~+ B4 t6 Oint ystart=0, yend, yincr, block; </FONT></P>. O- F. r! p& [. S$ m) u
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; : a* [$ l2 d/ U3 W3 i
yend = yincr; 1 _0 M8 A4 G6 i- s, h; S- B! ~
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>; u; j8 N1 M6 Q3 h6 c; r% i  t
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
# q' e* r' Q: H{
# o) Z" m& G9 U& K' l: Tif ((buf[block] = farmalloc(size)) == NULL) & i  d, p. E- @  d" B* B& I
{
( D/ u6 P" A: S6 @closegraph();
1 w) O: x: d$ ?; qprintf("Error: not enough heap space in save_screen().\n"); $ i: }1 L- v- M( `% _/ }- ?5 C
exit(1); 2 p1 q! [- l* M9 S! p
} </FONT></P>0 J1 m3 P6 G: f4 h. |7 f; T
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); * [: w/ r+ N9 z9 M1 N: K4 i. `* f
ystart = yend + 1;
% {: g( _  P0 L+ kyend += yincr + 1;   b3 N4 n; S4 p9 j7 P
}
& _% D& F9 g0 G- L} </FONT></P>
* A- C3 z4 X+ ~' ]0 C<P><FONT color=#0000ff>void save_screen(void far *buf[4]) 0 n' l0 w! [4 F1 R8 E
{
8 }+ o6 L( z  A! Z1 v3 Sunsigned size; - }6 o5 W" _( o$ q) J7 Y$ G
int ystart=0, yend, yincr, block; </FONT></P>5 J) u3 ~+ F1 Q' d4 I
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; , N3 K) D8 c1 T, b: n  N" d
yend = yincr;   ?  x8 Q; O. d3 O& J2 j
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>) W0 s! ^* f+ h1 X3 H. K  H7 S. T
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) & N+ }) ?6 e) p) p
{
4 k0 l( m+ O" \4 _* H& \if ((buf[block] = farmalloc(size)) == NULL)
& i6 K% w$ P8 K+ g4 G) i. e{ . Y. h& R& ]) b- C7 W
closegraph(); ! g3 V# S% [+ F# m# g: X; }
printf("Error: not enough heap space in save_screen().\n");
; I# v2 @% j2 k- bexit(1); ; O2 W' i1 y! }( s% L
} </FONT></P>9 N) e8 J- q' T: G
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
6 Q# P1 U+ t! |7 Q* P* q: Gystart = yend + 1;
; z. `8 N3 j1 q2 z8 A7 D6 |yend += yincr + 1;
+ G. S0 M& A# l) @2 k8 h}
7 F+ J7 [3 p# D$ B& i) h4 l/ B& ~} </FONT></P>
3 B- H, J8 `6 t* x$ z# {<P><FONT color=#0000ff>void restore_screen(void far *buf[4])
6 i# l( @: L7 o/ g: c5 [{
1 h6 j" X: X+ B. m9 Y: S- P. ?int ystart=0, yend, yincr, block; </FONT></P>! y7 X' E% M- f- V( g
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
1 b" w) w8 v- o$ Zyend = yincr; </FONT></P>( o' `: v' k. {
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
5 c: [# b2 B- \, c& A* b4 V7 a6 a{
- b8 p1 i' c" V* Q4 e0 b0 bputimage(0, ystart, buf[block], COPY_PUT); ! ~; p6 v' ^: `1 j! b: J
farfree(buf[block]); . _3 p( z( E+ Y0 o$ b+ X
ystart = yend + 1;
# c5 g1 q2 o  Q& tyend += yincr + 1;
9 }) d! {7 L% a! P6 ]" n}
8 J& c" V( d6 R; _. M2 X" I+ l9 c} </FONT>
  A7 D; V  u( ^, Z7 f<FONT color=#ff0000>
0 [7 J. M# i" Z8 s; ], F& d</FONT></P>6 M7 h% J) U+ z& m
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>( e. [5 F9 i* P/ \, n
功 能: 取当前线型、模式和宽度 , W$ _1 s, i: ?2 P' [
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
$ O& e+ s, s* o$ s$ J程序例: </P>
3 z! F7 M7 e0 I; v! l/ u1 i9 H, f<P><FONT color=#0000ff>#include <GRAPHICS.H>) A- t/ v% Q2 y
#include <STDLIB.H>
  j1 n, b) O7 T8 `#include <STDIO.H>
3 M- a/ A4 ?9 f  Y& _2 _2 E' n#include <CONIO.H></FONT></P>- t6 l% S- v& p
<P><FONT color=#0000ff>/* the names of the line styles supported */
" h( w* w4 j, }5 S: a0 Bchar *lname[] = { "SOLID_LINE", , E' O% |  ]7 |  f
"DOTTED_LINE", 8 J1 ~4 O" r# Q
"CENTER_LINE", * f' F# M+ w2 d+ T( }# b! I
"DASHED_LINE", " n  L2 h. C( e: a3 C, _; J7 u
"USERBIT_LINE" * [& k* b/ F/ T6 {- j2 \7 [) C# c
}; </FONT></P>1 Z4 z( ~# F" V8 D- b+ ]/ ^8 A# e  y" r
<P><FONT color=#0000ff>int main(void) ' j5 l2 x( r/ f- H( F9 i
{ " k6 U1 M5 l3 n8 ]" I
/* request auto detection */
6 v5 e5 t3 w  g% Oint gdriver = DETECT, gmode, errorcode;
" z; _" i& R3 I2 N9 Q) ]# Istruct linesettingstype lineinfo;
: [1 n  d9 j- a4 F( ~int midx, midy; $ G3 J' w! c# X! \' R, F/ \; c
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>% D/ |+ g" W2 ?& k, ?! n1 @& e2 ]0 w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' k! q, U* h) B7 [/ b; Z1 minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* M* q* j, i+ K) q+ v- q! b<P><FONT color=#0000ff>/* read result of initialization */
  E1 }9 N0 K  G7 yerrorcode = graphresult(); " ^* C$ }, h& c
if (errorcode != grOk) /* an error occurred */
& f! r1 f% D9 K2 z{ % ~, W. L9 v" K- o0 n
printf("Graphics error: %s\n", grapherrormsg(errorcode));
. `# W, `: b- Rprintf("Press any key to halt:"); $ T. z+ F  B0 K/ y* l
getch();
! d4 n; q& ]8 Eexit(1); /* terminate with an error code */ ! T' u: x0 d4 ~. y6 [. z
} </FONT></P>
' T( |5 q, A, G9 [<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ E$ F+ T, Y7 \" k7 k2 M. |- _! omidy = getmaxy() / 2; </FONT></P>/ q( g& Z  L; s: A5 e
<P><FONT color=#0000ff>/* get information about current line settings */ 4 o8 D. m! D# x% w7 V. n
getlinesettings(&amp;lineinfo); </FONT></P>
' V4 G+ t2 R, t, M! L3 ?8 s- t6 r<P><FONT color=#0000ff>/* convert line information into strings */ ' W+ \) {# J! g
sprintf(lstyle, "%s is the line style.",
& C( ~) ^% {' j: Qlname[lineinfo.linestyle]);
9 U$ j$ @2 j7 \. @; ?sprintf(lpattern, "0x%X is the user-defined line pattern.", + e3 }/ q! V/ F5 @7 U7 `9 L
lineinfo.upattern);
5 l6 K" {' f' |4 i2 Ksprintf(lwidth, "%d is the line thickness.", 6 s/ k0 f0 e9 {5 v! u/ y( L
lineinfo.thickness); </FONT></P>, L* i1 y0 ~$ j7 _, o& v4 Z* b
<P><FONT color=#0000ff>/* display the information */
5 \# C+ K6 J2 K1 m5 tsettextjustify(CENTER_TEXT, CENTER_TEXT); 3 R* L6 z; q8 [+ [0 q  f7 ?: F
outtextxy(midx, midy, lstyle); % |9 Y9 z# H4 Q% Y! K
outtextxy(midx, midy+2*textheight("W"), lpattern); 7 l4 X0 |* M  Q" z+ L
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
( [1 l$ l3 e2 k3 k& }<P><FONT color=#0000ff>/* clean up */
0 R( T8 c2 Z- j$ w$ N' ^getch(); 5 Z2 b. p5 J  D* @6 S  V
closegraph(); ; P7 V+ |0 n( {; F' x7 o
return 0;
9 L2 e6 s3 |, e) l} </FONT>
+ b) o1 }* Q* x9 o) V! _) C9 |8 l1 [/ h. c- u2 _1 U
</P>- A( x' s9 c$ ^
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>% B+ h9 D9 g5 ]' h- ~
功 能: 返回可以传给函数setcolor的最大颜色值 ' U: V' T5 d5 a$ O1 z
用 法: int far getmaxcolor(void);
# @9 H0 {& Z" w4 m9 _程序例: </P>/ U# e9 u$ `' _, V* J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 H& E/ l1 o) a2 G#include <STDLIB.H>, ?7 r8 n7 p3 h4 u! s  s& u
#include <STDIO.H>+ b8 j+ ^+ L9 X4 s9 m2 |
#include <CONIO.H></FONT></P>
# Z# b% P7 r2 ^, q<P><FONT color=#0000ff>int main(void)
  `1 _& x% ^3 A1 X{
, |7 s& y9 \( q9 A/ c/* request auto detection */ % d7 q; C- |0 U4 W( h: N$ N
int gdriver = DETECT, gmode, errorcode;
" h2 q% A, P) v# \( fint midx, midy;
( ?; X, }* R8 schar colstr[80]; </FONT></P># E/ O- J3 Y0 s
<P><FONT color=#0000ff>/* initialize graphics and local variables - t7 L6 w2 p% `( m9 W! w  U
*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! F" V6 H4 G9 x1 F+ Q5 ?<P><FONT color=#0000ff>/* read result of initialization */
8 V- z4 O5 K$ Perrorcode = graphresult(); 4 \3 P& n& U- s
if (errorcode != grOk) /* an error occurred */
3 |2 I& c8 |$ o' S* w% o* v{ . U! m" h4 u/ T; g6 ^
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 ]: O/ z9 |# o
printf("Press any key to halt:");
) s3 @: b2 a1 z: p- J- @getch(); 0 V8 b+ ?* b* u$ w0 n) @; w
exit(1); /* terminate with an error code */ % l8 H+ h: L& L
} </FONT></P>' k1 i! _3 R2 h/ A9 G
<P><FONT color=#0000ff>midx = getmaxx() / 2; 9 X: H$ E8 O8 M
midy = getmaxy() / 2; </FONT></P>
6 s2 Q: q5 @4 ~: ?- a1 i5 |<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ * Y8 d  P/ E6 ~- i- C
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>' f+ m6 a( p4 S! A9 C
<P><FONT color=#0000ff>/* display the information */
; G2 o$ ?! b( |1 m$ tsettextjustify(CENTER_TEXT, CENTER_TEXT);
5 w! k8 O$ ~& R) j1 Souttextxy(midx, midy, colstr); </FONT></P>
( u% b& G% e% ?2 b( D; i<P><FONT color=#0000ff>/* clean up */ * ]: v: \  G: a$ g0 T
getch();
# D4 i0 E3 [# S8 r' J* M7 m* [closegraph(); ! J" G9 B: K. c
return 0; / A0 k4 Z6 V( k8 v
} </FONT>& @! f* I" B  D$ m& o- [# O& N" n
# F6 @# s, ?5 I8 [/ e- {, \
. T8 K; h5 c# H$ l3 d+ t
</P>
/ M; \0 ^! @7 l; a- K- L<P><FONT color=#ff0000>函数名: getmaxx </FONT>8 z) h9 i3 H% J4 U7 {7 N; f7 |- b4 r
功 能: 返回屏幕的最大x坐标
1 h/ r7 [4 a  U' `  p3 O用 法: int far getmaxx(void); ( d7 o$ i& o) k4 Y/ {! D
程序例: </P>; H% G+ C8 G/ _+ _* P# X
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 ]; S0 L. G5 s. \" d4 d5 G1 i- g/ N
#include <STDLIB.H>
1 @; N. l3 e$ Q  ?; x7 c) C#include <STDIO.H>0 ]2 k/ t5 Q" Y, Z! E& ]8 H
#include <CONIO.H></FONT></P>
, [0 S5 i. i' I7 o<P><FONT color=#0000ff>int main(void)
+ T, H3 V  T" j{ $ @' c" V+ S% e1 O6 X7 U: A$ I
/* request auto detection */ : i! t( w8 v, ]' u
int gdriver = DETECT, gmode, errorcode; ' O. {6 L; e7 |
int midx, midy;
0 c7 W% j- D" m) N& g. I8 dchar xrange[80], yrange[80]; </FONT></P>
. d* V0 G* R+ A% u) F  J( n9 S4 s, v<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 |: V- A5 n6 G: K) ^& S$ dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 N4 P$ W! Q; Z6 o" a% h<P><FONT color=#0000ff>/* read result of initialization */
  N: n4 n+ e  aerrorcode = graphresult();
' u$ ]8 }! @5 Q' |/ D; L- jif (errorcode != grOk) /* an error occurred */
( U0 `; k2 B# n$ X* t{ $ D3 W6 k) w/ C% G* ], }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# `# m9 \) ^* U/ Mprintf("Press any key to halt:");
, o- s7 f0 y) B  ?' o( ?3 @getch();
% V3 D% F: D% P3 K4 [) K0 K$ E' Qexit(1); /* terminate with an error code */
0 v! j+ x: Y/ d) Y1 j. q, Y} </FONT></P>' R  H2 N+ l/ i0 w( r8 G, }1 F
<P><FONT color=#0000ff>midx = getmaxx() / 2;
( _- ~( f5 a; i& Kmidy = getmaxy() / 2; </FONT></P>2 o6 n+ l" b: i; }( d6 S) u: w# M  P1 O5 u
<P><FONT color=#0000ff>/* convert max resolution values into strings */
" N. J4 l: a$ Usprintf(xrange, "X values range from 0..%d", getmaxx());
" a" r( n1 y/ K& y7 u7 K3 T9 z) Asprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>! g" j. {( `+ H9 b5 I! `5 K
<P><FONT color=#0000ff>/* display the information */ " }# x2 y6 ~/ w' K$ T
settextjustify(CENTER_TEXT, CENTER_TEXT); ' e5 I* J3 `" ^" j
outtextxy(midx, midy, xrange);
3 F% ~0 I  t( F9 |+ ~) v8 douttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
3 V: |8 |  X! p9 Q* i. i<P><FONT color=#0000ff>/* clean up */
# B$ Q2 U! e7 ggetch(); 1 ?% Y3 T6 t' c) [2 @, d% G
closegraph();
& g5 G1 f" Y' f) greturn 0;
0 c' K* [/ O/ K}</FONT> * M. L# J% T/ E! ^1 E
  _4 w0 U( j9 D( \% E/ p
</P>
  Y0 b$ R' ~0 ~: U- ^<P><FONT color=#ff0000>函数名: getmaxy </FONT>
5 Z4 C& N' r* M& f# x$ V( t1 N功 能: 返回屏幕的最大y坐标 & A" r2 \# s, p: @9 s3 N
用 法: int far getmaxy(void);
4 j6 x1 r( _- A( t9 l' F程序例: </P>
/ J5 Q' h( P7 r9 N7 J; U% _<P><FONT color=#0000ff>#include <GRAPHICS.H>2 f/ u4 h5 }1 s/ C# P- Q, g- I
#include <STDLIB.H>4 T3 ~8 a% d. K% v
#include <STDIO.H>
6 F; P' N( l9 T0 h, F. P#include <CONIO.H></FONT></P>
& o$ P! ~7 _: d2 b% n5 \% m1 w<P><FONT color=#0000ff>int main(void) ! @" ~# [  a5 U8 L( L9 m7 Q* C: J/ A, m
{
: z; Z0 Y2 p- _6 [' H0 @* s# ?/* request auto detection */
% R' j' h7 y7 A4 ^1 [& [int gdriver = DETECT, gmode, errorcode;
% b6 F& @# f) n" Z% R" ~% Fint midx, midy; ; P. G! a$ U6 }. h3 m
char xrange[80], yrange[80]; </FONT></P>+ A2 v; y, Q* D, e
<P><FONT color=#0000ff>/* initialize graphics and local variables */ # \  p- N: f$ x2 E0 s9 ]1 x" {* ^9 f
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 m/ u- d8 q. }( E7 Z: y<P><FONT color=#0000ff>/* read result of initialization */ % n1 B4 {; l. \6 }" C" }
errorcode = graphresult(); ; [; M5 F. a7 K
if (errorcode != grOk) /* an error occurred */ 6 @$ `1 I# N# @- U& i
{
5 c- ~6 g4 s6 e; g) h+ s& q' Z$ E0 tprintf("Graphics error: %s\n", grapherrormsg(errorcode));
) L9 C: l( D8 @0 h9 x3 Sprintf("Press any key to halt:"); 0 J# ?" F2 b: n5 w  t+ ?" B; f! S& H
getch();
! }8 b+ O3 K+ _- n7 L/ xexit(1); /* terminate with an error code */ / `( ^  g( i3 R. G7 D- E8 J& H
} </FONT></P>
7 X) O( ~, ~, n8 d. B<P><FONT color=#0000ff>midx = getmaxx() / 2; , i1 a0 K, W3 d4 j" G7 t1 p* c
midy = getmaxy() / 2; </FONT></P>4 E9 {' A0 y- a9 j" m9 t
<P><FONT color=#0000ff>/* convert max resolution values into strings */ + P% u9 e; z( r- a. L3 J  m; e* j
sprintf(xrange, "X values range from 0..%d", getmaxx());
& v, M. ^4 t1 {sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
  G0 q% g- G2 P" @; v: ?' J/ N7 q$ L<P><FONT color=#0000ff>/* display the information */ 9 M& L/ U) s0 R" V
settextjustify(CENTER_TEXT, CENTER_TEXT); % y6 H- H0 b5 w  Q, ]2 {2 n7 |
outtextxy(midx, midy, xrange); % [, ?7 A* w3 s: [8 D7 L; w. N
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>9 B: o8 [0 G, j3 ~# ^0 X
<P><FONT color=#0000ff>/* clean up */ 7 b/ K, Y# K7 C% v
getch(); 9 q( ?* K' b! s
closegraph();
/ b/ I2 i( H! ^) q0 l( mreturn 0;
( P* q/ F, {, \! q3 A! |1 ?} </FONT>6 j+ ^1 J8 u8 L! y: K
</P>) z  [9 K3 [5 R6 K) j/ s' F) V0 I8 S
<P><FONT color=#ff0000>函数名: getmodename </FONT>
- K+ `7 P3 K! x6 a; n功 能: 返回含有指定图形模式名的字符串指针
! s# u+ w+ h  \2 g用 法: char *far getmodename(int mode_name);
4 ^" A1 P9 u5 V6 A8 D, B5 A" [程序例: </P>/ D- ^' t6 x6 V1 ^; j, P* V
<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 H+ ]6 X! V& H: c7 }6 L#include <STDLIB.H>4 j4 f( \5 |0 w' a
#include <STDIO.H>
0 X9 a% s) ?/ B. A2 p#include <CONIO.H></FONT></P>6 n& V8 H$ w) f: P; _% T
<P><FONT color=#0000ff>int main(void)
3 J  S1 M% b1 q{
& t% ]" n- q* K2 A$ G' e# x( @1 I/* request autodetection */
; Z/ t& ?$ ~. h! |7 `int gdriver = DETECT, gmode, errorcode; , q& k# d$ `+ _. t
int midx, midy, mode;
: a( ?: H2 {  g; hchar numname[80], modename[80]; </FONT></P>
2 U, D8 |& O! g, w( r/ ~<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 k; T* k/ j4 Y4 n: p9 h  q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># x: `) Y, p, i% S8 a  T5 x
<P><FONT color=#0000ff>/* read result of initialization */ 7 ^, Q) B3 x& Z+ F: L
errorcode = graphresult();
. u2 \' U3 S0 |$ O) Lif (errorcode != grOk) /* an error occurred */ * @; ], y4 |- E+ K
{ % r( M5 T  D, ]' y5 ^. u
printf("Graphics error: %s\n", grapherrormsg(errorcode));
, D- R7 R9 @1 z2 \# cprintf("Press any key to halt:");
  Z, W- Z8 ^- b+ hgetch(); 3 ~/ B! h4 O8 d4 D
exit(1); /* terminate with an error code */ ; u4 b# v# K7 j8 O2 K
} </FONT></P>
! o" c( }/ u) Z' D6 E7 N<P><FONT color=#0000ff>midx = getmaxx() / 2; 8 c/ K" ^- \5 r3 p. N' P  y5 W: r
midy = getmaxy() / 2; </FONT></P>
' `- j" d8 N! {  _1 F$ k3 |8 E* H<P><FONT color=#0000ff>/* get mode number and name strings */
8 G; ~8 b9 t. l& Z4 G/ h) Dmode = getgraphmode(); 9 o. s1 Z2 z1 J( `. t7 j3 i8 P
sprintf(numname, "%d is the current mode number.", mode);
. w# U2 H/ \& ~: g# {3 i! asprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
) \4 c/ O# i' F8 ^<P><FONT color=#0000ff>/* display the information */
: a  W, O5 R$ x% Xsettextjustify(CENTER_TEXT, CENTER_TEXT);
2 f# i4 p) W3 i) l6 Zouttextxy(midx, midy, numname);
: U& R" V, x* B# Pouttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
3 H3 U4 V& O0 K$ T; ^/ ~<P><FONT color=#0000ff>/* clean up */
! [$ t: K% l/ ]8 Mgetch();
' S5 W. z( }1 w1 d# Iclosegraph();
  W- W: G! f  G1 ?return 0; 0 f4 H& N+ `# r. Y4 t9 r; P+ ^
} </FONT>
7 b0 W, V0 L6 d3 u0 P0 H  E
6 X3 r0 w: [+ E7 `, C1 s, i</P>
, r( m! o+ C5 R& d2 i<P><FONT color=#ff0000>函数名: getmoderange</FONT> " q5 [& H5 d0 b* D
功 能: 取给定图形驱动程序的模式范围
. ^) K  f3 V7 v7 S; G用 法: void far getmoderange(int graphdriver, int far *lomode,
, Z" o0 H2 S3 i9 kint far *himode); # a3 Q3 G4 i3 D) ?, N9 _% R
程序例: </P># {) t2 {) c9 o3 S
<P><FONT color=#0000ff>#include <GRAPHICS.H>+ [' B* q; \! W
#include <STDLIB.H>7 [: G. H6 m, ?8 r6 v2 q; s" f
#include <STDIO.H>- [' ~" O  q' e* @
#include <CONIO.H></FONT></P>( j' R9 v' [# W( {5 j5 D# o& |
<P><FONT color=#0000ff>int main(void)
5 M- d. @" n5 z# P% \9 x5 F, ~{
) r, p9 t4 D6 l, h. N6 `& ?& Y/* request auto detection */
3 a+ X8 L! T; F/ W7 ~) W% k! tint gdriver = DETECT, gmode, errorcode; # v" w  O$ l, R! P+ _
int midx, midy; 6 M7 w3 G: D) n9 D0 \+ @
int low, high;
; B3 h0 g8 r1 C" l: |" _char mrange[80]; </FONT></P>
: s, ~/ p0 @, v2 [+ M$ C<P><FONT color=#0000ff>/* initialize graphics and local variables */ , d& p& ?) _: {" b: ~
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ w+ _( v% x* [9 I0 ~4 ]<P><FONT color=#0000ff>/* read result of initialization */   _- F  j2 t$ X: ]+ F9 b- S
errorcode = graphresult();
2 _4 T% B2 `) X3 Zif (errorcode != grOk) /* an error occurred */
$ r) s+ j9 ^- \) D$ U1 k{ 2 E  a! |) W1 `
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- u( i# ?/ U+ k; g) K; Aprintf("Press any key to halt:"); 3 O, g+ z2 f, I; m  s4 q$ H
getch(); 8 ]4 p' V" I: f% r% d$ l
exit(1); /* terminate with an error code */ ( n7 z& ]5 C: s7 h( Q% y! f6 _- ^1 a- o
} </FONT></P>( R# m7 `. p% C% L/ R* e( U
<P><FONT color=#0000ff>midx = getmaxx() / 2;
  I8 v% ]1 W( ]6 O0 d5 omidy = getmaxy() / 2; </FONT></P>+ {6 g- V; d$ p8 P) b# M. n
<P><FONT color=#0000ff>/* get the mode range for this driver */ & N% _: D8 O2 j' F
getmoderange(gdriver, &amp;low, &amp;high); </FONT></P>/ L; \9 q7 n& R  Y7 K$ o" P4 @
<P><FONT color=#0000ff>/* convert mode range info. into strings */ . l5 w8 B9 M- l; H( Z1 r  N8 R9 ~- O
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
3 E) q: e, b2 l<P><FONT color=#0000ff>/* display the information */
6 n+ Z, }+ h0 J! _, asettextjustify(CENTER_TEXT, CENTER_TEXT); 0 d$ m/ J( s3 [6 X% T5 g
outtextxy(midx, midy, mrange); </FONT></P>
% K% t, Q, Y! ?% D<P><FONT color=#0000ff>/* clean up */
+ }/ U8 t6 E% Z9 p0 Pgetch();
# g5 Y5 M% n. X7 w' Y" n! R) kclosegraph(); , x- P, f& C+ P6 m
return 0;
0 L8 n4 r1 m8 P# _7 y1 z' T}
! o5 J- s1 Q* ]</FONT>  p/ r, W1 ]. u! v: D8 [
</P>
: l$ p( ?; B( s) u# \' R<P><FONT color=#ff0000>函数名: getpalette </FONT># ?4 _4 I7 U5 F% b; Y
功 能: 返回有关当前调色板的信息 6 B3 g8 N8 ~0 ?' D: ?$ \3 I% v
用 法: void far getpalette(struct palettetype far *palette); ! ~& p& r" ]2 c* j
程序例: </P>
% y  C: e6 I6 s+ Q: j<P><FONT color=#0000ff>#include <GRAPHICS.H>  T3 ^/ z' k8 J! C
#include <STDLIB.H>, F" l9 G+ z% R) d
#include <STDIO.H>
. Q7 h3 |! m" Q# \4 G* }; Z#include <CONIO.H></FONT></P>
! ~! q, `( z, }  `$ {7 b( |<P><FONT color=#0000ff>int main(void) * N- G- M- g4 R* Q8 y
{ 4 a% |. f3 C; Q( y" L9 C- \
/* request auto detection */ ( f4 S  X6 H% _- V" ~
int gdriver = DETECT, gmode, errorcode; ) j. Z9 S1 e4 m# B
struct palettetype pal; 6 K& A" }, L7 g' t" {7 h
char psize[80], pval[20]; 8 Z+ `) f  }7 P$ d* Q, N5 ~9 P  z
int i, ht; 4 a  H/ R% L. n' t% x$ L
int y = 10; </FONT></P>
% h6 E0 d+ p( G7 r$ R, f/ @. W<P><FONT color=#0000ff>/* initialize graphics and local variables */
. ^8 k2 j6 O% Jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 Y( g  L/ Y4 c6 G  o
<P><FONT color=#0000ff>/* read result of initialization */ / U/ X) M' a! p+ f# W' Y5 s
errorcode = graphresult();
+ N& m- e; E/ x1 w( c; a4 P6 G/* an error occurred */ 1 o9 }+ ^6 z0 N9 o
if (errorcode != grOk) * ~* y$ h+ A. i& B4 A
{ 2 I+ x) N  d2 y: Q' F$ T8 f
printf("Graphics error: %s\n",
, {3 E+ I2 L" c; M6 Wgrapherrormsg(errorcode)); # L! O: ^. R8 ?
printf("Press any key to halt:");
* n1 ^9 y+ ^6 E* {getch();
5 K9 p9 b$ @  A" S! V( a9 Y/* terminate with an error code */ : {) o3 i, E: N
exit(1); 2 r+ f+ g5 x1 o3 e+ N. k
} </FONT></P>
2 \" z4 f% O! I; J' d<P><FONT color=#0000ff>/* grab a copy of the palette */ % E7 h# F  \) P5 p
getpalette(&amp;pal); </FONT></P>
( ?+ \  w' M8 n  j( S8 y<P><FONT color=#0000ff>/* convert palette info. into strings */
9 _% w7 l) g6 v+ z6 ]sprintf(psize, "The palette has %d \
& o& O4 M- w0 T9 lmodifiable entries.", pal.size); </FONT></P>4 ~: `5 }& t$ Z! j2 e( u2 J% H
<P><FONT color=#0000ff>/* display the information */
% z0 Z2 v* |. R" R4 Youttextxy(0, y, psize);
4 ], M' p% e, k7 d( d# V# dif (pal.size != 0) ! }! Z1 I! U+ Y, O, L
{ 8 {- P5 D* h- i2 b' \- ^
ht = textheight("W"); * b$ W' _$ V8 w- P
y += 2*ht; - F; b3 M/ I! q2 K& {* O
outtextxy(0, y, "Here are the current \
* h; B- [6 \2 k2 H, ]! q( yvalues:");
* u5 ]& Y" `: qy += 2*ht; ; U% C. X' B! l9 z
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
! J0 p9 T3 n& z; m1 Qsprintf(pval, & N  Z' o' D& O9 f0 B$ Q) U4 L' J
"palette[%02d]: 0x%02X", i, 7 R' V/ ?  Y* ~0 X
pal.colors); 6 R& a9 m. r- z: _: l" \
outtextxy(0, y, pval);
+ q: f& j5 G/ m' U}
: F7 F# B; M2 n, G0 O) M} </FONT></P>
# }3 Z. R) e1 z5 b* N<P><FONT color=#0000ff>/* clean up */   \& ^$ y, a9 L4 e: L  k. z
getch();
( ^7 O& |6 l2 }7 l6 wclosegraph(); </FONT>
& i* X/ F2 t% t2 V<FONT color=#0000ff>return 0;
% j- A$ F. f) X# q0 Y}
7 c2 O) o6 [4 ~$ X' d% z" M! b</FONT></P>2 p; E% z& ^( ~! X" r
<P><FONT color=#ff0000>函数名: getpass </FONT>, I  E( C7 w2 I. V6 V& a
功 能: 读一个口令 * E. q) P/ O- o$ |1 G+ S" o
用 法: char *getpass(char *prompt);
' p4 p7 h1 ^0 s& t2 r# M' m* V程序例: </P>
& \4 {1 V% X+ }8 h7 ]& g<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
: D* e: \+ _/ `! |2 m<P><FONT color=#0000ff>int main(void) 3 a# Y. C/ W2 c
{
3 v1 p1 i. R+ R5 ?6 N& ychar *password; </FONT></P>
6 T5 L8 F! [- b<P><FONT color=#0000ff>password = getpass("Input a password:");
# z+ H+ M' D& z; e+ dcprintf("The password is: %s\r\n",
: |5 W* ~" ~4 a$ ]# t8 N, d6 mpassword);
0 D+ T% g) U6 @6 L% o4 }return 0;
: l. c$ o  H; C5 f& }2 S+ `}
7 ]. v6 a+ y. j: k( i0 i: E, ]</FONT>4 q5 r' @7 `. N/ K
' L! m0 e, S) _& t
</P>$ D( q/ U# M4 U5 `5 E) P  p: \, x
<P><FONT color=#ff0000>函数名: getpixel </FONT>& y' q% G& `! n2 S3 A. G( z( y
功 能: 取得指定像素的颜色 8 D) u2 p. H5 h' V
用 法: int far getpixel(int x, int y); : j- Q+ i; ?: B$ @  E+ Y! I
程序例: </P>' x" A; {* Z1 Z( {& `( d2 n
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# i1 m6 {7 F2 p- I5 X/ R. I#include <STDLIB.H>
0 b& ?6 p+ \4 g4 g. t#include <STDIO.H>2 I5 @$ Z9 v( d
#include <CONIO.H>
4 l( V/ A$ j" ]2 \1 C; I0 l6 P#include <DOS.H></FONT></P>: ?  k2 Y; _' m5 l
<P><FONT color=#0000ff>#define PIXEL_COUNT 1000
" R# ?7 M) k) x3 E# A4 n: t* S#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>/ I. k+ Q& ]8 I. W8 m
<P><FONT color=#0000ff>int main(void)
+ J$ f5 c8 K; [. ~{ : m. Q* s5 c5 ?- Y( \
/* request auto detection */ + q. D- y+ y6 q& |: Z
int gdriver = DETECT, gmode, errorcode;
9 ]8 A( |( W( xint i, x, y, color, maxx, maxy,
: z4 F$ `  F$ p+ Y, Tmaxcolor, seed; </FONT></P>' @2 D+ d% C- c5 M- l" ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# b+ x; e( ^- {: k6 m* Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% \& |7 C5 \. `5 p* a& S- `( D% `<P><FONT color=#0000ff>/* read result of initialization */ ) g0 I, i# W( k
errorcode = graphresult();
, c. Y7 }: o: C$ b. [7 D/* an error occurred */
8 c* T2 ^, {$ ~0 ~/ w9 Pif (errorcode != grOk)
, U2 l- y* c$ I6 N$ I{ % v' @& n4 z" l' ]$ O) l6 l
printf("Graphics error: %s\n", - U, V3 |# Y1 I. H) T7 T4 u5 u$ D
grapherrormsg(errorcode)); ) [* _+ [! U: N, f4 F- ~( x
printf("Press any key to halt:");
- J( c8 g$ w4 n  Igetch();
& k, D6 U  {9 s# H% @: A/* terminate with an error code */ . k1 N9 t, U+ y$ J
exit(1);   a5 c( x' X5 E
} </FONT></P>
, w) b2 [8 S- Z2 ~# J; `5 N<P><FONT color=#0000ff>maxx = getmaxx() + 1;
& I6 r4 {( ?  H, s  f# Gmaxy = getmaxy() + 1;
6 n% ?# N# c# [9 Emaxcolor = getmaxcolor() + 1; </FONT></P>4 K" V8 o3 P" y. D+ X* n! {7 m
<P><FONT color=#0000ff>while (!kbhit())
$ B- L$ a$ B4 j. y- a{
2 x9 f2 b2 R* N# l& J& t/ b# U/* seed the random number generator */ ) \. p8 W" J$ p& x& x6 l# H% B
seed = random(32767); 9 V4 _, t5 V) I2 v5 G+ @* u& Y
srand(seed);
7 E7 N9 v* u5 L% w6 ^for (i=0; i<PIXEL_COUNT; <br i++)> {
7 X4 b  g0 `7 v2 Mx = random(maxx);
, I. a& w% p0 f3 s/ Z1 {6 [( w* a9 Cy = random(maxy); 6 p4 f. [: t' @  j
color = random(maxcolor); 7 D( o* a1 `1 l8 s  d
putpixel(x, y, color);
* g% {* v% |1 l6 @) T+ U6 L' d7 t} </FONT></P>. G: Y, A9 C! o8 R: s  k1 E
<P><FONT color=#0000ff>delay(DELAY_TIME);
" _" Y. Z$ a" c* g+ V/ ]srand(seed); % Y3 }5 ?- H3 {1 L, p% Y
for (i=0; i<PIXEL_COUNT; <br i++)> { 8 u' R& S+ K3 M- z6 Z
x = random(maxx);
! S( r$ U5 E* V9 ey = random(maxy);
& ~7 p+ G% O. ?+ K0 Y  S5 jcolor = random(maxcolor); 1 l( U% C' A$ G! _) z- `6 d6 R
if (color == getpixel)</FONT> </P>
7 H+ j" O* o3 `" M<P><FONT color=#ff0000>函数名: gets</FONT>
; x6 [7 {/ f3 z5 \2 O功 能: 从流中取一字符串 / ?8 G' N) e( A3 d' Z
用 法: char *gets(char *string); - S5 L* }. S& ~& |
程序例: </P>9 S- u( b/ a0 ?  y/ V: l
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>+ z# h& K- r0 O2 C$ z
<P><FONT color=#0000ff>int main(void)
2 R* ~' F( q4 ~2 p: E{
2 h3 a' c9 q2 P& w, |char string[80]; </FONT></P>
6 d5 S+ s: s: l<P><FONT color=#0000ff>printf("Input a string:"); ( z" H$ {. _  R- \$ I% x1 I3 b  c
gets(string);
0 Y  J; q- a/ N  S/ d2 gprintf("The string input was: %s\n",
. k) U9 P' v8 t4 Z8 M2 v; Estring);
- k' s( E+ G6 M# Freturn 0; : W, `' @% ]" o. m' f
} ( ?& c5 i" J5 e, x  `, ]
7 x2 Y4 ?2 e3 U9 w  M: t7 p
</FONT></P>2 |4 o0 Q# [7 T8 C
<P><FONT color=#ff0000>函数名: gettext </FONT>6 [* i! E( H% V: g- O; O
功 能: 将文本方式屏幕上的文本拷贝到存储区 3 K$ c- v$ k  l
用 法: int gettext(int left, int top, int right, int bottom, void *destin);
  V2 q  K( C. n. M; O程序例: </P>" f, N. Y/ e+ v! Y
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
; Y4 `  q0 _9 B, F/ H<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
" r! c  H" N1 ]) J2 ?" _  |; i! ~<P><FONT color=#0000ff>int main(void)
& G. M4 R) H: L. p6 ]6 A{
/ f, t* f; ]  iint i; # E' m$ Q9 g, b1 d  |% v: D: f3 r
clrscr(); , z+ O$ n, Z4 X+ v
for (i = 0; i &lt;= 20; i++) , u) W1 K6 o2 H8 R$ d
cprintf("Line #%d\r\n", i);
) _' z! S: l3 \7 @: I$ g. C; H5 Egettext(1, 1, 80, 25, buffer);
8 @) }! i, D7 {) T3 ^/ v) [% U( Qgotoxy(1, 25); ( y5 v1 r1 \& ^, Q
cprintf("Press any key to clear screen...");
% p- Q0 {$ I* e% O  hgetch();
' C: _# k9 j- E  q& u) }clrscr(); ' K1 c1 H- ~9 l7 |( N$ h* }
gotoxy(1, 25);
: `% B) ~) I: S# X: e4 r: J3 `cprintf("Press any key to restore screen..."); - J* f& Q. K! f; F7 `7 K4 {
getch();
! f7 B+ L" m5 j7 h8 Eputtext(1, 1, 80, 25, buffer); 1 V9 B( Q! |8 f, \8 W0 @
gotoxy(1, 25); * |( |3 Q, W) g$ L, e0 _
cprintf("Press any key to quit..."); : b) X2 Y, @7 c% i2 z& h9 N& D
getch();
( z6 b8 s% ]  s% H2 e5 D3 j# Breturn 0; : I# E9 ?  k) }0 C
}   I: ^/ @4 u% p2 m
</FONT>
! l3 E7 A3 _  ^2 N  {6 w</P>2 i7 t/ W: ^/ F6 S  i1 z$ |" P
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> , F8 a- S5 k$ m
功 能: 取得文本模式的显示信息 $ J6 Q2 U6 y# v/ _1 ?$ K# S; k" y
用 法: void gettextinfo(struct text_info *inforec);
1 g! N$ ~9 D5 \& o程序例: </P>
- m8 z: ~- e: L4 i<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>5 B8 u; ~7 N5 E' o
<P><FONT color=#0000ff>int main(void) ) ?* H! c% Q! A* w* O: ?$ F
{
5 r- ~5 _% ?  l) D. Gstruct text_info ti; 3 C: P8 `  N& \8 M6 _* I
gettextinfo(&amp;ti);
2 e  n3 A4 g3 J! h% l% P' B$ K4 Ocprintf("window left %2d\r\n",ti.winleft); * R1 g0 C$ d% c/ }5 @' {
cprintf("window top %2d\r\n",ti.wintop);
0 V2 g* G) R: d4 l% L3 K/ j. n  bcprintf("window right %2d\r\n",ti.winright); * m7 P# S2 l( [" n1 j" c$ T- t
cprintf("window bottom %2d\r\n",ti.winbottom); 9 X) {1 q$ {) f( h& m- |- O
cprintf("attribute %2d\r\n",ti.attribute);
* U1 @& `( a, ?& s) z" Lcprintf("normal attribute %2d\r\n",ti.normattr);
( H4 J0 b; V% J0 m8 E: R' \cprintf("current mode %2d\r\n",ti.currmode);
% k" a7 A; \+ e( X5 ~+ ecprintf("screen height %2d\r\n",ti.screenheight); 4 G+ O. r- w# p& n2 W
cprintf("screen width %2d\r\n",ti.screenwidth);
1 n6 {8 G) u' K8 {& ]& v3 ~cprintf("current x %2d\r\n",ti.curx);
+ V0 [( {4 q3 D  e* _cprintf("current y %2d\r\n",ti.cury); ! j$ K9 C4 m1 d6 [) T
return 0;
* D/ V7 Y( u& U' o, E} 8 x; E, ?; n- J: b; a
</FONT>  u: r- W. D* M/ K# G5 F/ {
</P>
/ ]6 \! h9 B7 E2 x+ f, _. I4 [<P><FONT color=#ff0000>函数名: gettextsettings </FONT>1 N" O. m; ]7 }3 @9 j% C5 |
功 能: 返回有关当前图形文本字体的信息
- o5 K4 b, [$ L$ x用 法: void far gettextsettings(struct textsettingstype far *textinfo);
5 A  z3 j. m5 h6 S! f6 e% z程序例: </P>
) y0 s9 A' A8 Y. N9 A) D<P>#include <GRAPHICS.H><FONT color=#0000ff>
$ n" A% O/ k8 V2 @1 m* `: w#include <STDLIB.H>
7 L0 D6 O! T( @1 J4 m#include <STDIO.H>
) X: i& }6 \6 G. X/ ~$ T7 `#include <CONIO.H></FONT></P>: s7 \( b' ~& \/ [  O( i
<P><FONT color=#0000ff>/* the names of the fonts supported */
' k3 |, t' f; U, C- achar *font[] = { "DEFAULT_FONT", $ \9 d/ H+ z! y/ }
"TRIPLEX_FONT", " Z! k( x, Y. ], ~5 G% P# Z
"SMALL_FONT", 6 N0 V: b1 Y' ]% V" G) }2 q
"SANS_SERIF_FONT", 3 I( Q# g1 K' ?. H
"GOTHIC_FONT" 2 F+ j9 U7 c2 |1 k: V* R+ L
}; </FONT></P>
1 |( F1 o! g2 |7 e1 F  s4 z* @<P><FONT color=#0000ff>/* the names of the text directions supported */
8 @; N; A+ ^) B4 q6 dchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
$ I0 ]7 T# K4 X+ T2 [1 S: o<P><FONT color=#0000ff>/* horizontal text justifications supported */ # L( @7 E7 D- N$ y+ ~; m
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
( Y* u2 P6 y3 P* ^' w<P><FONT color=#0000ff>/* vertical text justifications supported */ 6 U8 d+ D: A+ G, y- _1 ~+ \
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
% b5 e: @. }/ A, ~) {, F<P><FONT color=#0000ff>int main(void) ; [# @7 |- L7 l- q! T
{
2 m' a, D' I6 v/ r4 }. y/* request auto detection */
+ u1 o$ E- a1 D( y8 J- gint gdriver = DETECT, gmode, errorcode;
# |. O+ r# {" w+ m1 Rstruct textsettingstype textinfo; ! w. a2 P. h- u0 ~( C; v& a
int midx, midy, ht;
' n4 Z8 e8 `  ?# {% e* o( I4 ichar fontstr[80], dirstr[80], sizestr[80];
/ \. _6 k  M# d3 ?- p# A/ ?" C) Zchar hjuststr[80], vjuststr[80]; </FONT></P>0 M8 l( O' ^7 [0 }2 S- j. b+ c+ T( N, [
<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 y! A- e8 Y8 m3 k2 j8 @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( F4 m# S; d, m: w1 b& ]8 Q<P><FONT color=#0000ff>/* read result of initialization */ ( U( R( X, g) o/ V# p) D
errorcode = graphresult();
! r$ h2 V0 }5 S! Kif (errorcode != grOk) /* an error occurred */ + W  x+ g3 Y7 E! W% A+ Z1 A
{
2 k+ {  k( a6 C+ O8 Cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ y# V4 d( z8 J
printf("Press any key to halt:");
) s- l. u; u: N2 C  Z8 g6 Ogetch(); 1 J5 w/ ]# a( Y2 p" f+ l
exit(1); /* terminate with an error code */ 9 G) T5 L' N: W; P
} </FONT></P>
% h5 D1 q/ x5 N1 b<P><FONT color=#0000ff>midx = getmaxx() / 2; . G* Q7 V! `) m# B: L
midy = getmaxy() / 2; </FONT></P>) R! Q1 Z! ?" ?' J5 N( n! U
<P><FONT color=#0000ff>/* get information about current text settings */ 9 y3 n. {2 _8 k8 F
gettextsettings(&amp;textinfo); </FONT></P># E; ^$ z4 |; o- {2 ]0 v  S3 [! G
<P><FONT color=#0000ff>/* convert text information into strings */ # P. h9 S: t" ^4 w( ~) T  ?2 T- H
sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
% }* ^; s6 t; Z8 ?/ N2 G# Nsprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
+ z6 m( Y# m; b/ psprintf(sizestr, "%d is the text size.", textinfo.charsize); + R, t4 z$ X3 ^, ~$ V
sprintf(hjuststr, "%s is the horizontal justification.",
0 d4 E6 `; m% I/ E& g: zhjust[textinfo.horiz]);
& X1 [  x8 H0 F# d+ @& W: l+ M5 W' Nsprintf(vjuststr, "%s is the vertical justification.", / N/ }- |$ u4 b9 L, \* S$ L! j( P
vjust[textinfo.vert]); </FONT></P>
0 q/ g# m0 h5 P+ p$ n1 W<P><FONT color=#0000ff>/* display the information */
2 |2 v4 U2 }) G4 D* J( [ht = textheight("W"); / K$ G1 H- q: \, T
settextjustify(CENTER_TEXT, CENTER_TEXT); 8 ?/ ]/ g5 `. Z
outtextxy(midx, midy, fontstr); 0 [5 a* h% w/ r. T7 _! G
outtextxy(midx, midy+2*ht, dirstr);
# }/ Y6 P6 g$ ?6 U" Xouttextxy(midx, midy+4*ht, sizestr); / v; H( K+ z) B3 M! f
outtextxy(midx, midy+6*ht, hjuststr);
+ j6 l: O3 `. ~1 h" r! c* K  C$ Touttextxy(midx, midy+8*ht, vjuststr); </FONT></P>. I0 Q& t. f) j* J  ~+ R
<P><FONT color=#0000ff>/* clean up */ - D0 l  q8 V' h& g
getch(); " \/ @0 G, p& t6 q8 w! @* j
closegraph();
7 g0 ^2 m2 t' F" B& G/ @! T3 dreturn 0;
4 U  h0 X; n3 n- m# m7 Z3 K} </FONT>/ R) p* s; F9 C
</P>* ^- ]" |; P: o2 m: x' l, }1 @
<P><FONT color=#ff0000>函数名: gettime </FONT>
" z* d" z- Y: c功 能: 取得系统时间 7 E: Q% x3 g- y
用 法: void gettime(struct time *timep); 7 H# D# B/ t/ s  t. l2 q' o. f! L
程序例: </P>+ l4 |) q$ x! F$ b
<P><FONT color=#0000ff>#include <STDIO.H>
' O/ [6 |; p( m/ ^#include <DOS.H></FONT></P>8 Y$ t+ z4 d, K& z" [0 j
<P><FONT color=#0000ff>int main(void) 8 R6 F1 b: I0 C/ S6 v
{
6 i5 {% h  E& e9 b0 d! V- f  ]struct time t; </FONT></P>
* N5 I. d* S% P0 ?, s/ b- j0 w- y<P><FONT color=#0000ff>gettime(&amp;t); + S9 c) @8 D  K9 M# U
printf("The current time is: %2d:%02d:%02d.%02d\n", $ T( P3 m6 n  c. k8 ^( s
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
9 k7 C& s6 t* O. \$ b6 ereturn 0;
0 w( B: w$ ]6 S% @3 u} 6 O0 c6 j- z( t! _1 E" e# H

  [* `: W/ q4 F( |" L( W5 B. j</FONT>
- d& ?( A5 r. t, p</P>: ^% |  ]! b4 Z% `
<P><FONT color=#ff0000>函数名: getvect </FONT>
+ ^& ?) j, ?% C功 能: 取得中断向量入口
1 G: w! ]1 z; n+ t0 C9 n, d用 法: void interrupt(*getvect(int intr_num)); 3 Y1 g$ c, P9 X! T* Z- l
程序例: </P>& C) C: C% Z: Y$ S
<P><FONT color=#0000ff>#include <STDIO.H>
9 O+ n1 h' K+ Q4 D#include <DOS.H></FONT></P>' p9 {  q; z- Z* S4 ]/ R3 S
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>! K& W! w0 n0 w2 }  a( y4 c# E
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ % E6 _8 {/ o/ @+ x! x" C7 s
int looping = 1; </FONT></P>
- n! K% Z. F9 t( v2 ?" V<P><FONT color=#0000ff>int main(void)
/ s. @" ?2 B, d{
' p/ q: |6 k  T% d; xputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>+ \; J5 z0 t& W0 d" Y, H5 F0 H( t
<P><FONT color=#0000ff>/* save the old interrupt */ ! E9 S2 K- J" ^$ B5 I9 R5 [
oldfunc = getvect(5); </FONT></P>
6 v: u* e8 v8 z- U* Y$ G" u<P><FONT color=#0000ff>/* install interrupt handler */ . t! K' ]9 e. N- t% q
setvect(5,get_out); </FONT></P>
1 s2 R$ d2 B2 E: _<P><FONT color=#0000ff>/* do nothing */
: n1 J6 b" S0 ?. F( N$ r7 ewhile (looping); </FONT></P>  D5 v* L1 B5 W1 l6 G
<P><FONT color=#0000ff>/* restore to original interrupt routine */
; _8 J' ?: p% E" x# D: e3 P7 o: Lsetvect(5,oldfunc); </FONT></P>" E+ D6 B1 T* u, `6 x1 @( o
<P><FONT color=#0000ff>puts("Success");
2 u  _) q- P& N' I: U" C# zreturn 0;
  s5 ^1 K0 ?5 o4 W- X% \} : M, T' U5 M# C+ K5 E7 ~
void interrupt get_out() 8 e& Y: p. B" s. ]9 ^* ~7 j
{ ; Z$ p, X6 `% x. f- X4 l
looping = 0; /* change global variable to get out of loop */ ' \. u/ b9 K# x# D, @2 E+ L
} ! j" L( |! R0 u* ], }
</FONT>" k2 _2 N; @1 p
</P>' t1 r7 a% |& T9 A+ k# G
<P><FONT color=#ff0000>函数名: getverify </FONT>" `# {. s& _# B4 U0 N
功 能: 返回DOS校验标志状态
7 C& |) G: G7 w  d% p( c& j用 法: int getverify(void);
$ ^6 p  R7 U( g" Z- r% m程序例: </P>2 C$ D/ c; O( S+ }- [$ L9 `1 ?
<P><FONT color=#0000ff>#include <STDIO.H>
$ {8 o4 r9 v: g9 X, r#include <DOS.H></FONT></P>. x; |( c' d! f$ Q. k2 ~
<P><FONT color=#0000ff>int main(void) 8 k4 G! e5 K9 k" t8 b6 M, w
{ ! Y) `2 r! h' P9 S, A' Z7 b
if (getverify()) 5 q9 H3 T9 W+ N  X+ u
printf("DOS verify flag is on\n");
3 m  t0 Q* E# T. N: Gelse ( i, ?  f% G% G: U7 ]2 B- V" {) \
printf("DOS verify flag is off\n"); 8 i  G: J% ]! g7 l7 g
return 0; 2 n( R2 [+ p6 I# {
} ! Q+ u9 ]: H/ t: Q) P( a
</FONT></P>
5 B; B& [2 t- I2 T( A1 l<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
1 m  B+ r9 E7 U6 P9 |功 能: 返回有关当前视区的信息 5 G6 I# w6 t! S* @  ^- ^8 y. e. P0 q
用 法: void far getviewsettings(struct viewporttype far *viewport);
  c7 q$ x" y6 U! F: ~2 F3 w程序例: </P>
* F- |4 B) E( p% Q5 m: }2 V<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 F- V2 x" U( g  ?8 g$ U#include <STDLIB.H>% _* m3 o2 t: v+ g7 i+ F, k) f
#include <STDIO.H>
: N2 g- R' s5 r/ |2 T7 o#include <CONIO.H></FONT></P>% y, [9 S! M2 Z2 \
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>+ }! Q5 `  z/ ^7 F. e4 @
<P><FONT color=#0000ff>int main(void)
8 M; B, P: v9 P$ W7 ~. G3 g5 }{ . J- R( b* k9 _% ]. `
/* request auto detection */
1 ^0 v1 B  h) F7 Sint gdriver = DETECT, gmode, errorcode; 8 L$ j0 J  x1 g% G
struct viewporttype viewinfo; ( ]2 V& c  l' O+ i
int midx, midy, ht;
' N7 ~) [, _. T/ Z0 G$ F) Q9 bchar topstr[80], botstr[80], clipstr[80]; </FONT></P>
! `1 R% w% n9 [  w* }7 l<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 D6 Y' ?4 f/ v6 Q- D$ n9 O  K& c
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* C* s. {: L( [0 Q0 S- S) f
<P><FONT color=#0000ff>/* read result of initialization */
+ q, c  |* m/ Aerrorcode = graphresult();
9 N5 F- I! H5 q* nif (errorcode != grOk) /* an error occurred */
3 ^* V2 B3 k1 o/ v1 E( |{
4 H+ M. B2 D6 v  O% K; R5 @printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 z3 ?" _. J' e0 K) o' P5 c- Vprintf("Press any key to halt:"); # R2 r2 @4 I8 K% i) K1 i) e
getch();
# c; s: \% q6 P1 ?exit(1); /* terminate with an error code */
( F) w8 t1 n4 E# p" G} </FONT></P>4 c1 J9 Y4 s& C6 R4 w* Y
<P><FONT color=#0000ff>midx = getmaxx() / 2; 9 S8 i1 ~2 o2 J7 k' I% t! R1 |2 @
midy = getmaxy() / 2; </FONT></P>. j8 p2 J9 F: j) N& H- A0 K! J7 s
<P><FONT color=#0000ff>/* get information about current viewport */
% w+ d9 {7 p; F) W' Q! D6 Vgetviewsettings(&amp;viewinfo); </FONT></P>7 W" p3 \$ Z! W) V1 D
<P><FONT color=#0000ff>/* convert text information into strings */
( g# w* W4 `' t& L+ }! T5 Qsprintf(topstr, "(%d, %d) is the upper left viewport corner.", - V% Y& h9 D- b% y
viewinfo.left, viewinfo.top);
, T5 d# T5 p+ ]% bsprintf(botstr, "(%d, %d) is the lower right viewport corner.", / {5 }2 p3 V4 |* x0 T8 M
viewinfo.right, viewinfo.bottom); * h# {: [. q/ [" L- c
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
* S+ X9 W) L+ s) H<P><FONT color=#0000ff>/* display the information */
& q& [, g9 A8 osettextjustify(CENTER_TEXT, CENTER_TEXT);
6 E  h# e3 W/ Y6 q( mht = textheight("W");
, b( e9 l/ X3 k( m+ e2 D3 K. qouttextxy(midx, midy, topstr); : i0 ~( i0 f+ }" ^$ G% v: V; L7 r
outtextxy(midx, midy+2*ht, botstr); , |. @  u. ^5 C
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
( s' o/ p5 K2 u  ], Q<P><FONT color=#0000ff>/* clean up */
+ m5 b4 R& S1 Q% P! c, k1 Jgetch(); " o- l% Y/ N; R1 s* P. S+ V
closegraph();
9 k  j2 N2 @2 Y) g5 b! vreturn 0;
1 Z* }" ^* D4 {/ p# j} </FONT>
2 F- ^% A, U1 R6 o
9 T2 c! p7 I& i! S, l4 P</P>
3 a& G0 p" K3 Z4 S$ T4 U9 ^<P><FONT color=#ff0000>函数名: getw </FONT>
# I- ~: h$ {1 L& ^% L9 K功 能: 从流中取一整数 ! `( U* v9 K+ H* P/ x
用 法: int getw(FILE *strem); 2 B: K9 X* z4 o! P/ [3 ?
程序例: </P>
6 R) |5 Q9 D0 _; X! J<P><FONT color=#0000ff>#include <STDIO.H>
# ^  U# J# z! e  G3 d#include <STDLIB.H></FONT></P>! k" U, w9 B% [+ c$ R0 G; y
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>' l+ }# S6 `, Q2 S3 B7 n
<P><FONT color=#0000ff>int main(void) . u$ G. c* J% }- \0 A
{ 0 U& W1 m8 b! r( u& [
FILE *fp;
3 O% [+ ]7 k; D3 R4 O/ ~int word; </FONT></P>4 ^2 N4 D# s0 G1 u
<P><FONT color=#0000ff>/* place the word in a file */ 5 f$ S# r1 F- Y2 @# ]6 _: \
fp = fopen(FNAME, "wb");
8 ?3 ?2 R$ H- wif (fp == NULL) , t4 G7 Q% e3 c- g& N
{ 8 f/ t" ]" a! f
printf("Error opening file %s\n", FNAME); . U. Z' b  Q$ {6 f
exit(1);
% o, S* M& W1 ?, d, K/ S2 s9 i. u} </FONT></P>4 n: O# G/ b3 K' t( D
<P><FONT color=#0000ff>word = 94;
$ Q3 m/ b  ]' C9 Bputw(word,fp); * W- r: z1 U  L  I
if (ferror(fp)) - {' a1 H7 m/ p. C
printf("Error writing to file\n");
3 r7 w! q! [2 p- B0 |( X' ]" nelse 9 }$ e  D2 }" F$ }0 I9 a
printf("Successful write\n");
6 t& K( m  H1 T' ~1 I7 lfclose(fp); </FONT></P>
! E, ~: ^. O% W) c. G9 C# ]4 G<P><FONT color=#0000ff>/* reopen the file */
" s5 r9 B% k. w4 A5 p( |' R) dfp = fopen(FNAME, "rb");
% y5 D8 k( n  E( V; wif (fp == NULL)
0 {' J# i" ]2 S+ F5 B- ]& G( G- v{ . U7 ?4 ?$ ~  \1 T/ v/ D# b5 J6 l
printf("Error opening file %s\n", FNAME);
8 Q7 y  b) N# y9 O# M: N9 x& Iexit(1); 4 q- c, X& l- s$ [
} </FONT></P>
. N0 ^% D; Y" H/ e: t<P><FONT color=#0000ff>/* extract the word */
$ t  W2 s! y, r7 b- M9 \word = getw(fp); 2 q$ W; h0 v, c+ o# C3 _# p% l" r& K
if (ferror(fp)) 8 B- C+ ?1 _$ W& C
printf("Error reading file\n"); 3 t. |% Z+ P* K, e' I+ P
else " c6 O2 {. r: E9 G! C( ]
printf("Successful read: word = %d\n", word); </FONT></P>2 m& x8 G* o% T
<P><FONT color=#0000ff>/* clean up */ ! R9 O2 h' ~5 t$ T3 n/ H8 u
fclose(fp); 9 w. D# k- m. _
unlink(FNAME); </FONT></P>. P0 |0 S( ]' C. s* u) \
<P><FONT color=#0000ff>return 0; 6 I; K& H8 o. V
} </FONT>
2 M' n/ e9 n( h$ G, B7 W+ y+ N$ |* g+ V8 j! n
3 E7 G) U" x4 L- H' J
</P>: Q- z, W' c. G) y5 b
<P><FONT color=#ff0000>函数名: getx </FONT>
& ]  c' _; E  y- d: ]! b功 能: 返回当前图形位置的x坐标
$ R$ C2 {5 y5 g' P7 M$ \% Q! a用 法: int far getx(void); , Y# n" Y) U8 h8 l' u
程序例: </P>2 v: I# b1 s% U
<P>#include <GRAPHICS.H><FONT color=#0000ff>
: ~0 m6 Y# a, T, G, q* N4 g3 H#include <STDLIB.H>. p" B4 E) {5 m6 B
#include <STDIO.H>
- j2 W2 a( {  p, l. C. s, C#include <CONIO.H></FONT></P>$ x% g- q1 `7 e: H; c& h% o
<P><FONT color=#0000ff>int main(void) ! @3 P9 M: M' I, y. |+ H
{
. P! u' w( T! R) b0 L/* request auto detection */
/ K# A5 d0 n+ i- o1 x  X/ h" X  eint gdriver = DETECT, gmode, errorcode;
2 b) d" @7 z# }char msg[80]; </FONT></P>7 k: B1 o  J4 N  {: W
<P><FONT color=#0000ff>/* initialize graphics and local variables */
- ~8 u0 Q  Q: a5 Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 Z; l; x/ R5 m- c# K  f
<P><FONT color=#0000ff>/* read result of initialization */ & Z! i* u( k4 o  Q" w
errorcode = graphresult(); 2 L; z- a3 c4 P' B
if (errorcode != grOk) /* an error occurred */ * v9 O) s$ b, b8 E
{ 8 K. t6 m) e5 V- Y: s
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 E; v2 g- K6 ]8 h# J5 K
printf("Press any key to halt:");
+ B" I0 I: c- V9 U3 egetch(); " F+ u; P- m0 ^( K( |
exit(1); /* terminate with an error code */
5 M; z5 c, }3 ^$ C} </FONT></P>
! a5 {% \$ v. ^<P><FONT color=#0000ff>/* move to the screen center point */ / h- }5 v7 A' o+ A' O/ T
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>* _+ |9 ]2 s+ m7 }  Q2 e, N
<P><FONT color=#0000ff>/* create a message string */ 9 Y8 m# E) s3 r% p
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>9 u9 J/ Z0 `# Y
<P><FONT color=#0000ff>/* display the message */   T, |2 @0 s9 ]6 C  a( s+ q9 U7 v8 `
outtext(msg); </FONT></P>
* G$ r- W% P; I* _<P><FONT color=#0000ff>/* clean up */ 1 i+ ^- a# D7 J; O2 Y
getch();
) N9 ~0 V/ y- D' p" @- dclosegraph();
. Z' D/ }- e/ }# a/ ^* `return 0;
; u+ }  w# l* K; v' f! r6 A} </FONT>
! n8 ^+ b/ o6 Q# S3 I0 l* s4 z& O
% O4 C- a: N, j: D  f3 s4 m</P>* Y( E" R2 M+ N2 X1 w; @7 f
<P><FONT color=#ff0000>函数名: gety </FONT># ^4 U* |# p1 p6 u- g
功 能: 返回当前图形位置的y坐标 % @# G% X9 h% W
用 法: int far gety(void);
% v: R) p; k, U程序例: </P>) f+ |) R9 \; I  _0 k
<P><FONT color=#0000ff>#include <GRAPHICS.H>2 B: \9 M6 g. E7 \. L
#include <STDLIB.H>
1 p# x& N2 D5 ?6 a, {6 }8 _9 C. R#include <STDIO.H>! D# M+ w" }2 ~* \1 G1 q
#include <CONIO.H></FONT></P>( V) t- ^% F9 i) n9 x& P
<P><FONT color=#0000ff>int main(void)
9 d% Z) X: N7 t4 {( @) Z+ k{ - k! r/ D  c# S2 E2 K/ \/ q  {
/* request auto detection */
( e' @( d$ \/ Y0 j! S6 ~1 Nint gdriver = DETECT, gmode, errorcode; 2 u" V  Z. N0 P) o2 O) G7 H" G4 G0 p  j
char msg[80]; </FONT></P>
- `# P. M3 o8 a  Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
; D3 j/ F) [7 k  Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 @6 J. a  |) i- ]<P><FONT color=#0000ff>/* read result of initialization */
4 q. j# I- ~4 b( Ferrorcode = graphresult();
1 G0 L$ ?& l/ o6 o- s* Y$ Kif (errorcode != grOk) /* an error occurred */
. S# e5 e$ c; s# Z3 A5 A% {{
$ u6 {4 ~3 w# K, z/ z: F9 ^! [printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 d5 C9 a' Z4 F# J: t% q8 tprintf("Press any key to halt:"); ) Z3 D* T$ y* U! J3 P3 g: \7 t7 m. Z
getch();
4 f4 q7 C" t6 t8 i' e; O/ {& wexit(1); /* terminate with an error code */ 5 n- j9 a. g2 S2 v( F& V* Y
} </FONT></P>
6 d. U& h- X5 g1 F( F! G<P><FONT color=#0000ff>/* move to the screen center point */ 9 V* G2 D5 h' t! y
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P># j  M( Y7 Y$ F3 f; T! y6 H
<P><FONT color=#0000ff>/* create a message string */ " b& K1 X3 q, W' O' e
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>1 F1 `* m. _& S3 W4 y! j; I
<P><FONT color=#0000ff>/* display the message */
/ L8 [# d! D8 J' w+ Souttext(msg); </FONT></P>
# N5 X* z3 q/ h3 E0 ]<P><FONT color=#0000ff>/* clean up */ 8 b9 \8 A' ^7 J' V
getch(); + b( `. C1 g2 o) W
closegraph(); 7 G) d, j5 _6 v# B/ r! E
return 0; 0 o* D- e" M" L% J1 Q6 |- c
} </FONT>
! ?5 B  J& m( K# G6 G
  G+ A8 N3 S1 E, L* u- u" X& Y</P>: X& U$ m4 ^. i* M; Z" T' S# \6 P
<P><FONT color=#ff0000>函数名: gmtime </FONT>6 ^' E7 o5 b$ j/ k5 Y( r& ]/ O
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
1 Q! M# O6 l: g5 T8 K* u用 法: struct tm *gmtime(long *clock); % W5 c) u/ K7 c7 i. _" Q
程序例: </P>
. S, c  \: u: Z<P>#include <STDIO.H><FONT color=#0000ff>
, u' q* w* y# @+ Q5 c5 j#include <STDLIB.H>  H8 @8 Y% t' `$ U
#include <TIME.H>% r% }: B' f6 p4 [5 s, e
#include <DOS.H></FONT></P>& [& a# O3 T+ v
<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */ 6 o; N' ]% ^/ e
char *tzstr = "TZ=PST8PDT"; </FONT></P>
9 V6 R" V4 Z. M4 b5 _<P><FONT color=#0000ff>int main(void)
7 b" n% ]  h- m  o/ b- S, b4 R% z{
! W7 Y/ B( ~) E2 X* v. _' V6 Z. \time_t t; * y* \6 p8 K; g: {3 V
struct tm *gmt, *area; </FONT></P>' E% u3 m8 g( \0 ]9 H. e& Q6 \
<P><FONT color=#0000ff>putenv(tzstr); + T3 \; n; C5 E0 j: y0 a1 K
tzset(); </FONT></P>: D% K( _" i, H* @5 @
<P><FONT color=#0000ff>t = time(NULL); 7 \' [- f! V/ ]' b" }5 n
area = localtime(&amp;t);
: E. C- r# u, p- m) q! Aprintf("Local time is: %s", asctime(area)); & `* P: S+ c. F- F
gmt = gmtime(&amp;t);
5 C2 X3 O$ |+ n. n9 s, i$ M. _* D4 {printf("GMT is: %s", asctime(gmt)); 2 ~4 }  P+ S9 \/ I' V
return 0; * U5 s5 q$ i2 X2 \3 l$ I
} </FONT>
! T) |3 A3 q  X8 `; Y5 y" ^4 l
9 y5 z( ~4 j+ O8 @" \</P>; P2 x% c. p  u$ r
<P><FONT color=#ff0000>函数名: gotoxy </FONT>* i- R7 ?( Z" o# L1 k
功 能: 在文本窗口中设置光标
& A) i+ V* d3 j* R6 W用 法: void gotoxy(int x, int y); ' E0 I5 f; z* c8 |; z7 r! q& x
程序例: </P>4 h) o4 S  d* G
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
$ _6 o2 i' T2 e, i* g<P><FONT color=#0000ff>int main(void) ! E2 F. ]! V4 b$ W
{ ) Q6 w$ {: ^: a; K! q! ?
clrscr();
0 U2 G; A3 h6 i7 g' q! r' O, @gotoxy(35, 12);
" g7 N% {* o& b$ E6 q2 Ecprintf("Hello world"); ' i' p! \; l5 x) [( ~; q) k- @
getch();
* I  I/ k3 j2 {1 A" B4 J1 G0 _return 0;
, n& [) n5 j( i}</FONT> " M/ c, e7 C; I2 Y* u$ q" g
' F0 b8 j7 Y3 \4 y. w
</P>
, B0 D/ {- @: y<P><FONT color=#ff0000>函数名: gotoxy </FONT>/ t2 g/ Y1 [9 J6 P
功 能: 在文本窗口中设置光标
1 ]1 F' y, T3 _! N( z. c' O' m用 法: void gotoxy(int x, int y); % [" H& k4 ]3 {. V5 {! L$ d
程序例: </P># H1 ]- w1 {* C, {/ Y, l( L
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
( g: i4 `3 Y8 E8 Y<P><FONT color=#0000ff>int main(void) 4 n8 C0 D8 h5 o- p: {
{   D, m+ G4 B( ?' R( ]' n
clrscr();
$ V# W0 e# i! l3 U% wgotoxy(35, 12);
5 F! r  [- \/ B, U5 t, Zcprintf("Hello world"); ( r; |* l* ~1 Z  |. M. L5 H0 f* W
getch();
  @" k  g) K, ]& e8 w% Preturn 0;
. N. K, M, d+ d% u! R}
5 G( [& q3 \8 U; V" I</FONT>
% c# ?6 V/ f( {% N( l5 z</P># K: t. K. E' x4 }9 A
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>% k8 Z4 C! _. ~( V& B" m$ s
功 能: 将所有图形设置复位为它们的缺省值
4 ]: G% r6 [- V; _  _用 法: void far graphdefaults(void);
. ~5 W9 ^3 G# F/ o- Q) O. _9 s程序例: </P>( A3 z8 _% r5 F4 F2 A, l, U. m
<P><FONT color=#0000ff>#include <GRAPHICS.H>, f7 D& ]" s2 S
#include <STDLIB.H>
' [% ?+ y& G# i1 q+ _  y#include <STDIO.H>% A# Z+ m4 H1 i& s) k
#include <CONIO.H></FONT></P>
* S: q% V  j% B5 v7 O8 h<P><FONT color=#0000ff>int main(void) ' F4 h% L% N! b9 ~) A9 B) i
{ 1 s$ A- |# W) ]4 g
/* request auto detection */
& ?2 o' J0 Y4 q# dint gdriver = DETECT, gmode, errorcode; 1 n0 _1 q$ [* K$ R
int maxx, maxy; </FONT></P>( N+ S: t, I5 J1 d5 H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 L0 M8 Q. Q8 p8 E
initgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
3 b6 ~4 x7 D! [( I) ~' N<P><FONT color=#0000ff>/* read result of initialization */
' g' u# C6 G' X8 ^errorcode = graphresult(); 4 ]8 F2 F: e/ x/ Z
if (errorcode != grOk) /* an error occurred */ ! Z; H) v+ Y& ^+ `7 B
{
2 I/ T9 B7 A% \8 v. `printf("Graphics error: %s\n", grapherrormsg(errorcode));
, }( j) J( D! ?+ F! ]5 z6 @( t( Iprintf("Press any key to halt:");
! ~" Q4 |% \" m7 cgetch(); 7 T8 ^3 Y# u, S0 h6 U; A
exit(1); /* terminate with an error code */   B5 ~0 g' L0 Z
} </FONT></P>2 w  ?) G* N! c! o6 q
<P><FONT color=#0000ff>maxx = getmaxx();
$ b+ P- _& L% x1 t! vmaxy = getmaxy(); </FONT></P>
' X3 s7 q5 Q% k* R9 Q! a<P><FONT color=#0000ff>/* output line with non-default settings */
$ G) Z% N1 W1 x* V- u7 Lsetlinestyle(DOTTED_LINE, 0, 3);
8 _: J9 R! U9 Q1 dline(0, 0, maxx, maxy); 2 G0 h) G  M5 D
outtextxy(maxx/2, maxy/3, "Before default values are restored.");
: D+ z( Q* g3 B0 vgetch(); </FONT></P>1 D6 P2 J  i: b1 T2 n1 N
<P><FONT color=#0000ff>/* restore default values for everything */
, c, A! L0 V" P! c- Zgraphdefaults(); </FONT></P>
/ u7 l1 f7 N) S0 Y( H<P><FONT color=#0000ff>/* clear the screen */
! U" S) N; `$ l" l& zcleardevice(); </FONT></P>8 c5 w" i3 d( q# y. H8 t' E
<P><FONT color=#0000ff>/* output line with default settings */ * i- Y) T2 J3 x( y4 |
line(0, 0, maxx, maxy); ( Y! c! H- @6 E1 M9 p+ J. c" B( x! Z& J
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>' Y" W& F/ {4 m$ h7 I
<P><FONT color=#0000ff>/* clean up */ , L! Y: ^+ y1 I+ w2 \
getch();
# J1 R- O; i) pclosegraph(); ; u2 E  K7 U% m& x8 z* {
return 0; + }0 d6 L3 _% Q$ |/ `
}
+ i, V' N& {# U% _: H</FONT>
. a+ O. B- A2 a& C+ o" I" ^</P>$ Z8 v6 P% j! S  j
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>
  O+ ]2 n& {( f4 M5 u7 y% Z# N功 能: 返回一个错误信息串的指针 " r. ^6 o: e. _6 i
用 法: char *far grapherrormsg(int errorcode); 4 P, [- \0 W( F7 |
程序例: </P>4 B6 A, a( L. |# O2 d
<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 |* k- F2 d9 ~7 b) M( m* ]#include <STDLIB.H>
/ [, w, u8 S$ m- T8 v#include <STDIO.H>
% v; s5 z8 O8 a# j#include <CONIO.H></FONT></P>. \: c" {/ l" R7 X
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>" \% `; u# a+ L: Y! Z" A( _
<P><FONT color=#0000ff>int main(void)
) L  H) P8 J% O$ w7 K{ * c; T0 L  R7 e  G, U* {
/* FORCE AN ERROR TO OCCUR */ 5 s( i. x- x+ s! y; B4 n0 a
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>/ K7 K! m# Z& v# K. m* ^% g
<P><FONT color=#0000ff>/* initialize graphics mode */ + ?* Q& s7 Y& o& }. }6 I, t
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 O* s% A+ @, X+ ]( h# r2 D" T8 f
<P><FONT color=#0000ff>/* read result of initialization */
. a  g, d: [% h: C7 berrorcode = graphresult(); </FONT></P>
( K1 A4 t% }( \. Y<P><FONT color=#0000ff>/* if an error occurred, then output a */
+ L+ w. R. Z7 a/* descriptive error message. */
; e+ @, f8 \5 x9 i0 E; R7 Bif (errorcode != grOk)
( z/ H+ r+ I" w# t{ + ?* s3 A0 r9 `( X- {4 R. h
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 r2 q7 {3 u& T2 v
printf("Press any key to halt:"); . U. a4 {* `) \
getch();
$ V) V! {  V- J- ~" H: Kexit(1); /* terminate with an error code */
" V$ |& I! d1 A7 S- I} </FONT></P>7 S& B- `% ]- j, g6 m6 k+ \
<P><FONT color=#0000ff>/* draw a line */
1 J$ ]' M' v; {& dline(0, 0, getmaxx(), getmaxy()); </FONT></P>
2 T5 `- G8 D( a7 I( r2 d<P><FONT color=#0000ff>/* clean up */
8 _4 I8 s: L8 W% Q3 @8 A! n$ s! ?getch(); $ |( [9 ?5 ^* Q! H% f- `. e4 M
closegraph();
2 {4 U* ]) X$ k4 Y1 V8 Hreturn 0; 4 n6 J& @2 g8 q* t
} 4 s+ [) j- d" q$ A4 T6 d. r( b" ^
</FONT>
3 z- M' ]) P7 q7 \2 U5 D5 m& V1 Z7 g( A# c/ ~</P>
$ M1 Z  d7 Q! e  j0 b( }4 a+ [<P><FONT color=#ff0000>函数名: graphresult </FONT>
1 e7 p( _' i6 y* A  M功 能: 返回最后一次不成功的图形操作的错误代码 ! r$ F3 B4 A* Z7 f9 E
用 法: int far graphresult(void);
* L- o5 C5 h; {$ L- `1 j  z7 r程序例: </P>
, X; C/ i7 p4 y! U& Y1 O<P><FONT color=#0000ff>#include <GRAPHICS.H>9 l9 Q+ V. j' m
#include <STDLIB.H>
" q' s1 g. C3 B3 x#include <STDIO.H>
0 ]* r8 J/ W" Q) V#include <CONIO.H></FONT></P>
; ^. m$ T4 f$ g# F, c<P><FONT color=#0000ff>int main(void)
& J# l& v4 ]; Z5 F{ 7 M5 s$ Q# {$ q- i
/* request auto detection */
4 ~$ n' }; ]( l6 `) Gint gdriver = DETECT, gmode, errorcode; </FONT></P>
0 e6 U+ M% e0 L6 O<P><FONT color=#0000ff>/* initialize graphics and local variables */
! k: q; N( e4 w5 C! o( y9 linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 J6 Z% L! c. n; o; `9 Y# |<P><FONT color=#0000ff>/* read result of initialization */ ! u3 ?/ s& w; w/ C. E
errorcode = graphresult(); </FONT></P>
, W7 X  S( m/ M0 s6 x<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ ! l. k  ]$ A! K1 \
{ 7 j! W8 b/ v7 n6 I: B+ J" U2 Y  @
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& t: F2 r& u& `+ eprintf("Press any key to halt:");
, [6 w; v! j% w2 R0 w2 jgetch();
3 X; v  {/ p7 a6 y4 t* R5 cexit(1); /* terminate with an error code */
) }$ N7 W1 i4 S} </FONT></P>6 X1 K6 L  n$ s# l6 t* K% j8 \
<P><FONT color=#0000ff>/* draw a line */ . N0 g; w+ o5 ~( }
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
/ q4 H$ N, B6 E. c+ V. A<P><FONT color=#0000ff>/* clean up */
+ S/ k# \( Q- f% Y$ l8 ]$ ggetch();
( P8 ]) p, k8 j0 Pclosegraph(); 3 k: t- n7 i7 s5 V6 H0 b
return 0;
0 B; B% S* ]) R2 w0 G}</FONT> 9 S  z3 k: X4 n
</P>3 {) ~" G' [; ~+ v; w* N& u6 c
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT>
" \7 f8 N- d- U) C# J功 能: 用户可修改的图形存储区释放函数
4 L0 p+ u4 J! Y用 法: void far _graphfreemem(void far *ptr, unsigned size);
" K/ H7 b' ^& t: D! {2 C) F( y" c. t3 \9 h程序例: </P>
& i6 F# ~. t9 v<P><FONT color=#0000ff>#include <GRAPHICS.H>9 X2 S& _+ D# F, u
#include <STDLIB.H>
5 p( @" W( Q. N) y7 L; |#include <STDIO.H>
$ Z! ^2 c2 ]* Z$ d& _6 Q5 W) O7 E#include <CONIO.H>
( P9 l! c$ B) b/ R* s, @: p* N#include <ALLOC.H></FONT></P>% a7 [/ E3 [4 @! v& S8 }9 q
<P><FONT color=#0000ff>int main(void)
6 h( R0 ]4 h7 N  j- c6 E{ , p$ r- v% D9 q  ~; d
/* request auto detection */
7 J& y: @. X1 v& Q8 x% Pint gdriver = DETECT, gmode, errorcode;
/ y9 X1 {5 y& k% B- B0 @, v3 Yint midx, midy; </FONT></P>5 q" ^- A  U4 c: ^) q1 ~6 I
<P><FONT color=#0000ff>/* clear the text screen */ 5 L8 ?. X5 k5 R2 D0 J
clrscr(); $ \3 e* E1 q0 \) z
printf("Press any key to initialize graphics mode:");
/ _# G% p1 X/ P( b- X+ ?getch();
& x9 S, D& M: M7 g' ]+ r1 yclrscr(); </FONT></P>
+ y, B3 N) M) o; k7 ]<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; J4 k9 r, y# S! |6 n6 ~
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 d* o: L5 ]; j) \  Y9 I8 d) @( X
<P><FONT color=#0000ff>/* read result of initialization */
1 @( l) n1 W6 i+ Z, _0 qerrorcode = graphresult();
$ ^+ \5 n; Y7 H) Yif (errorcode != grOk) /* an error occurred */
* r0 A" p1 n3 j3 p6 c{ # v3 ], A, `. x; r
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 L$ Q* r% V7 m  _! r* uprintf("Press any key to halt:");
+ G. N! J* J# ]3 a6 t: V: Fgetch();
+ b9 t$ h& C  Dexit(1); /* terminate with an error code */
( P9 N3 v. x  T) p} </FONT></P>
* z! }* d5 H: Z3 ]2 E<P><FONT color=#0000ff>midx = getmaxx() / 2;
) z) r' ?9 E3 ?0 Jmidy = getmaxy() / 2; </FONT></P>
- p  R0 x# U8 I( m' n6 ?; n7 s; W<P><FONT color=#0000ff>/* display a message */ + b$ p' K6 o1 _9 ~. A! h
settextjustify(CENTER_TEXT, CENTER_TEXT); 3 b5 l+ e2 X0 f, H* @. j/ O
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>, a& _- {' ~: ?# D: J$ Y
<P><FONT color=#0000ff>/* clean up */
1 z3 A0 x8 h5 z' e" {1 u9 f2 Y  Xgetch(); $ f8 H5 C/ [! A4 h; U
closegraph(); 9 M/ e, k3 x) A- j. l7 G( n! T4 m% ]
return 0;
  X+ J' Y! i2 q8 E9 {5 F0 u% S3 t} </FONT></P>, {: [- v# j% ~8 G
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ # f# c- I% M0 G( g
void far * far _graphgetmem(unsigned size)
4 y: }$ W% S# p" d$ [- V5 N{
" p0 }6 [2 M/ }4 z; g" ?$ kprintf("_graphgetmem called to allocate %d bytes.\n", size);
' A/ h  l& q9 gprintf("hit any key:"); $ ~% I) l9 s# C0 ?/ k
getch();
# [+ X( H5 U( X+ r6 aprintf("\n"); </FONT></P>( ~  q" o# s1 _
<P><FONT color=#0000ff>/* allocate memory from far heap */ 6 D! x( [/ G/ J9 E6 }3 }' s
return farmalloc(size);
7 f- D- T) D" {. K, x* c5 B} </FONT></P>+ e, u0 ?! A4 O1 O% z: D# T
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
3 l( m3 D) M3 Zvoid far _graphfreemem(void far *ptr, unsigned size) $ Z  s8 b! a8 d
{ 8 O! O. G, y0 f: X* Z& a
printf("_graphfreemem called to free %d bytes.\n", size);
2 i; s; i4 E3 T2 v6 E! M1 f' Cprintf("hit any key:"); ! U! f* z0 Q& K
getch(); ; J  a1 d( s- f$ ]4 [" d
printf("\n"); </FONT></P>: L; W0 w) p, z! B0 H
<P><FONT color=#0000ff>/* free ptr from far heap */
# z( ]1 Y. L0 ~5 r$ C( o/ }% C: tfarfree(ptr);
6 m3 u; }: Y: D# D8 z}
- z: C3 k  R, R- w! I, n$ f</FONT></P>
8 O* e( D9 q# c+ h! `7 m" E- }# s<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>
% g! P2 ~' V1 w1 }( i" }; f功 能: 用户可修改的图形存储区分配函数 ) y! l4 H" o' R, t( q5 C7 \9 A
用 法: void far *far _graphgetmem(unsigned size);
0 p2 s" }0 ~% ~' h程序例: </P>
, f$ R& x& K: Q5 T( K$ w<P><FONT color=#0000ff>#include <GRAPHICS.H>) y$ Y1 I# ?& c& {! v
#include <STDLIB.H>
# f; g8 \* n/ ^6 Z#include <STDIO.H>, E! _. W0 a- y' y$ g
#include <CONIO.H>
" J) w* O! f& i! ]* g#include <ALLOC.H></FONT></P>' t4 q5 t( H2 y" e4 E7 g
<P><FONT color=#0000ff>int main(void)
" G" `+ @7 u6 P& \6 x9 ?! r{
$ D/ R( j2 O/ @. z) P/* request autodetection */ 4 \' K& s- m8 k, g
int gdriver = DETECT, gmode, errorcode;
0 [3 X' |8 v) _int midx, midy; </FONT></P>; R& d! R: b3 W7 v+ [+ v& B; D
<P><FONT color=#0000ff>/* clear the text screen */
6 y9 U" R( U' [  k' D, T2 gclrscr();
1 j" z5 k* ~4 @% @& Wprintf("Press any key to initialize graphics mode:"); " ]! T# `) U/ J  `, J; r3 p
getch();
) V* q" Z4 i$ h3 Y, eclrscr(); </FONT></P>
5 d4 w: ]6 b- z: ~<P><FONT color=#0000ff>/* initialize graphics and local variables */ , G' \; _* {+ t  |: [  Q" V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 W% d8 K' r; V( T% M  ~; l
<P><FONT color=#0000ff>/* read result of initialization */   b+ B/ @* C5 e  y0 q9 L9 Y
errorcode = graphresult();
2 ]- J5 b+ Y6 [: {! N2 O! u' Aif (errorcode != grOk) /* an error occurred */ 1 C' u6 a0 z6 N; N7 s/ o
{ % b( X2 F9 j: V1 B/ S! n5 M
printf("Graphics error: %s\n", grapherrormsg(errorcode)); " C' ~+ s4 ^  R
printf("Press any key to halt:"); 7 p5 Z7 e+ w% u* L
getch(); 0 g  |. h% V; A' ?7 Y
exit(1); /* terminate with an error code */
3 Z1 n* I1 a3 @3 H; F} </FONT></P>
# h6 E# K7 X) E: g* R! o: }' s) l; p<P><FONT color=#0000ff>midx = getmaxx() / 2;
& C  x" t7 `- }+ K1 D! omidy = getmaxy() / 2; </FONT></P>9 r( r5 O! ?$ \
<P><FONT color=#0000ff>/* display a message */
4 b5 S( |% `" W" k2 Bsettextjustify(CENTER_TEXT, CENTER_TEXT);
, p" P% _% v8 X: pouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>, R& j+ r: |# T- _. ^& b; x
<P><FONT color=#0000ff>/* clean up */
; k. W: X* }- a) {" e  H, Ggetch();
' w1 [1 |3 k2 I! U  p' G7 Z6 S. ]closegraph();
: E0 X, x! C$ @% C7 \( I( Ereturn 0;
3 p. K+ Y4 \1 d} </FONT></P>0 ?3 a1 A1 C, @- N$ u
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
" W' O' ~$ |+ \5 I, Uvoid far * far _graphgetmem(unsigned size)
: ]8 V/ A5 o7 z. ]: e{ 4 W+ X" W' t5 u& |9 W! P9 ?5 ~
printf("_graphgetmem called to allocate %d bytes.\n", size);
$ w  x7 @3 b5 b1 p/ `; O" l; `) pprintf("hit any key:");
- _; I% @& L2 M0 e# x! |( agetch();
! S: q- U( d: v) u$ f; ^printf("\n"); </FONT></P>
! l4 L  f- d8 w9 H1 m<P><FONT color=#0000ff>/* allocate memory from far heap */ ( d! V( o4 U+ c5 R- ^0 o0 w
return farmalloc(size); 4 G% r, q3 T0 J, v2 U# U& k1 K; F
} </FONT></P>: @; |. }' M' y* }
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
! h9 t( a- g# N) |+ o! b& i0 {void far _graphfreemem(void far *ptr, unsigned size)
+ s; |9 L$ I5 x) _8 J6 p; f{ + G4 b4 [; ?5 A2 @' Q2 t
printf("_graphfreemem called to free %d bytes.\n", size); 0 _* U! C; R2 Q+ M9 F' a
printf("hit any key:"); % ~4 I' a; q. F! q( Y" T) T
getch();   C1 L( @. t" C9 G& Q" t: |
printf("\n"); </FONT></P>' |- j+ Q3 f' L1 F( }- `! J
<P><FONT color=#0000ff>/* free ptr from far heap */
" a0 }% x, l. d, |( m0 v& K: M1 \farfree(ptr); 1 F, m0 H/ u/ ^& d4 {5 ?3 c- J5 @! y4 O
}0 q- J3 J% ?. _) g6 w+ w
</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 06:15 , Processed in 0.422883 second(s), 52 queries .

回顶部