QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2621|回复: 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>$ h% l6 J; H; Y4 Z1 Z+ @* y) q

9 D/ R! K. j7 B( {% k
, j# J2 K9 Z8 G- P& s3 n<p>
+ `5 z) }  j( g- d<><FONT color=#ff0000>函数名: gcvt </FONT>2 Y* Y2 v: ~4 Z% n
功 能: 把浮点数转换成字符串 ' l8 V; c$ g% u( ~0 i7 o7 O
用 法: char *gcvt(double value, int ndigit, char *buf); 3 {: Q3 I& D, n4 a! L
程序例: </P>5 M  R% u8 h4 u* V5 s* G* R$ a3 H
<><FONT color=#0000ff>#include <STDLIB.H>5 p- ^6 ~0 F: e! t: ^
#include <STDIO.H></FONT></P>
, s( M# F. W8 g- O5 ^: p<><FONT color=#0000ff>int main(void)
- a2 M$ c- D0 i1 N{
0 g: L3 ]3 S8 a( S9 ychar str[25];
/ S/ @) D; }4 k/ kdouble num;
6 Y6 B# c- e" uint sig = 5; /* significant digits */ </FONT></P>
7 A- Y' k% m  v8 g# M- z1 m<><FONT color=#0000ff>/* a regular number */
2 x: T4 Z8 {/ W: @num = 9.876; 7 g/ ], w8 C2 m. f" S8 E* m
gcvt(num, sig, str);
" m& m+ [* E2 f. ^$ nprintf("string = %s\n", str); </FONT></P>
- |5 U" }- h( R% `& y, Z( \1 n; J<><FONT color=#0000ff>/* a negative number */
6 i, o. S9 A# Fnum = -123.4567;
- z( \# B/ ]0 ggcvt(num, sig, str); ' H9 J  L) b: B2 Y3 Y) b
printf("string = %s\n", str); </FONT></P>8 G. }$ H- e7 d0 Y1 O& Z
<><FONT color=#0000ff>/* scientific notation */ . c0 L, O* f; y# b& d; b, C9 ]
num = 0.678e5;
  |- U9 f( F: k! Ogcvt(num, sig, str); ( b; p( o) |% d& {" x$ j. m
printf("string = %s\n", str); </FONT></P>
; t; ~4 c$ c3 x. J8 t" Y9 i3 r$ S1 q<><FONT color=#0000ff>return(0);
4 T4 s8 d% O! a! W' B}
; g* o2 ~7 p0 H% v9 f' ?- q% z* l% Y
</FONT>
7 q) C$ Q! j! D! X! C/ I</P>
0 U- M8 k8 m6 g9 g8 g9 K<><FONT color=#ff0000>函数名: geninterrupt </FONT>0 G2 P0 o( v' u: _( O
功 能: 产生一个软中断 4 L2 G4 N) R, E
用 法: void geninterrupt(int intr_num);
# K/ c; j# u$ }1 i, m程序例: </P>) o" T/ ?& |9 W% u' L! x6 Q8 h
<><FONT color=#0000ff>#include <CONIO.H>: a/ o' o: w& i) b  J- i
#include <DOS.H></FONT></P>
  b: [; _  z: t- }( D  D<><FONT color=#0000ff>/* function prototype */
! X: m3 T8 O1 K% ?' Qvoid writechar(char ch); </FONT></P>7 U: z) T/ y) U
<><FONT color=#0000ff>int main(void) 9 [! }& b4 E/ [3 h
{
; L1 }, S* X; k$ h/ Qclrscr(); # ]- D! W% e3 M7 u4 F  W& |
gotoxy(80,25);
: v- Y4 V4 B- S/ |writechar('*');
9 ^$ ?2 g5 [) _# ~# Q' V7 @getch();
4 B+ \8 p) h: O5 K2 T' k' sreturn 0;
; g+ K. m6 o! a% C. v/ S} </FONT></P>' Z+ P! q# K% |- v/ S% f
<><FONT color=#0000ff>/* . x5 |# d8 |* s! m5 ?, @- Q
outputs a character at the current cursor - n. h/ i0 `+ D8 x+ m1 Q. N
position using the video BIOS to avoid the 6 K# y# e& r; W- j) J9 T
scrolling of the screen when writing to
+ J. R# J% n' C$ @5 ~: b! j( Alocation (80,25). 9 ?2 S9 Y2 e9 W# R
*/ </FONT></P>
% [3 e$ J; k6 b- @1 j3 @+ {2 V<><FONT color=#0000ff>void writechar(char ch)
- l7 U6 \+ u& X8 V7 Q2 u) l2 I. G( n{ ' _5 g. `" e' @4 x' i3 a
struct text_info ti; - Z( C" J4 ?9 a4 {* C
/* grab current text settings */ 3 v# W7 I, r: u9 n# G8 a; P9 j- K
gettextinfo(&amp;ti);
2 |2 H: s( v5 y2 J' c/* interrupt 0x10 sub-function 9 */ 0 ^, U3 k/ ^/ k& |
_AH = 9; , Q% f% |( E9 Y6 s: w
/* character to be output */
4 U# ]; n7 l" ~8 q4 Y$ U9 e) F0 x_AL = ch; ! f% b, Z2 b, i' B
_BH = 0; /* video page */
8 Y4 K0 G+ ]" o, ]" p  {% j_BL = ti.attribute; /* video attribute */ ! D% Y; \# [2 P/ D3 x/ K- y& s4 P
_CX = 1; /* repetition factor */
" L  S- w$ k* {4 S0 rgeninterrupt(0x10); /* output the char */
& c+ c- Y' T  t/ n4 {/ V9 w} . E6 \- Q! Y# v+ {% G  Y/ I
</FONT>; H* n) S9 I) |' i9 U
</P>& P/ O2 b! e2 b' J6 m: a4 X" o
<><FONT color=#ff0000>函数名: getarccoords </FONT>
& ]! _( O- q4 [/ G6 n功 能: 取得最后一次调用arc的坐标 6 U+ y8 K4 z" ]! O- w8 p
用 法: void far getarccoords(struct arccoordstype far *arccoords);
) `6 L! s; C' P/ V7 J! s$ ^. Q程序例: </P>
1 h4 }; w5 L  T<><FONT color=#0000ff>#include <GRAPHICS.H>+ q7 S2 m% I! S
#include <STDLIB.H>
% z$ G1 S/ n( M+ H; v% x# r#include <STDIO.H>- w$ [5 n) f3 ?' R2 R/ Q" S4 @
#include <CONIO.H></FONT></P>1 i/ [, k! d+ y' D+ p
<><FONT color=#0000ff>int main(void)
" Y- x* a4 F+ c, v0 |- U{ ; s- o2 `  n/ Z  M# [( ?
/* request auto detection */ + z  C; D7 x( ~$ w0 F8 m7 u
int gdriver = DETECT, gmode, errorcode; 1 H* S: E; R5 _1 \
struct arccoordstype arcinfo; 3 C4 k# u# ^' M: @1 b9 t
int midx, midy;
' |, R" W( ~8 u9 }4 c( Q4 a5 J% b! f) q3 kint stangle = 45, endangle = 270; 1 k+ Z7 r! o* s# G- q$ W
char sstr[80], estr[80]; </FONT></P>
7 |- z: F; z  b; M6 q  T0 l<><FONT color=#0000ff>/* initialize graphics and local variables */
/ h2 }& |9 G+ F; z' i- Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 q' D! o* H  f6 w; q, N' U' D<><FONT color=#0000ff>/* read result of initialization */ / X& a# }# _7 k' |1 e* [
errorcode = graphresult(); / D, ?8 q* ^7 V. {4 I  B+ f
/* an error occurred */
" o; e/ E$ K7 ]9 F% U; ^  pif (errorcode != grOk)
+ h! Q' I# l; e; p8 R* o8 q3 g1 V, w  K{
' w; ~! k* e0 J; S( {, {& aprintf("Graphics error: %s\n", 8 C2 c" E% o2 f2 `# Z! W
grapherrormsg(errorcode));
1 I% B; Y2 t4 z, [- Hprintf("ress any key to halt:"); 4 ~6 h* v% N& I0 d: }) `7 B
getch();
4 d1 s7 u# I8 O/ W2 H" V; L/* terminate with an error code */
! e, J3 Q3 F5 D; Uexit(1); ) ]3 I( V( s% G- F: R4 c' F, d
} </FONT></P>, o* P6 U8 H! Y
<><FONT color=#0000ff>midx = getmaxx() / 2; - e8 e% p  @  m6 S' |5 i! X" M, u
midy = getmaxy() / 2; </FONT></P>" f+ B5 ]4 l* X5 `
<><FONT color=#0000ff>/* draw arc and get coordinates */
8 E$ w1 Y. W5 j( W! q: nsetcolor(getmaxcolor());   o( P3 b/ ]6 Q7 v$ v$ B
arc(midx, midy, stangle, endangle, 100);
/ W) ?* X/ g  [/ O: Sgetarccoords(&amp;arcinfo); </FONT></P>
6 j+ E1 F* b3 p7 Z& d- a. X9 \<><FONT color=#0000ff>/* convert arc information into strings */ 1 w+ ~# {$ ], Z
sprintf(sstr, "*- (%d, %d)",
: @1 z, _* w" k1 Z) darcinfo.xstart, arcinfo.ystart);
: s! u) r/ i' D( B, F4 y0 qsprintf(estr, "*- (%d, %d)", % c5 x! m4 P( b" f
arcinfo.xend, arcinfo.yend); </FONT></P>* Q3 g, @! F- P2 x" n( R: @, y
<><FONT color=#0000ff>/* output the arc information */ 8 |0 }7 ]4 b$ c
outtextxy(arcinfo.xstart,
/ p3 C  m4 Y/ e+ U& `: varcinfo.ystart, sstr); 1 q) u" H1 s& F7 u
outtextxy(arcinfo.xend,
* ^7 |) ^/ x* Z: X; jarcinfo.yend, estr); </FONT></P>. ]/ K" n( }3 `; T" w5 r: z
<><FONT color=#0000ff>/* clean up */ ' |% y# z3 T7 h+ p
getch(); * _, k/ [7 S% ?" R3 W$ Q$ Y
closegraph();
( B2 j% _/ a/ x$ G3 X: m- T) D% Oreturn 0; " I" f% S- `  _, W7 M9 i* }* w
}
$ n' m- K& i1 F) D# }$ j6 }' A</FONT>
) E1 I0 Y* x% _% S, x
# F% |& g# z& N9 S6 p; J</P>
# e) o+ w, H" S6 T8 o% u' h# ]6 [<><FONT color=#ff0000>函数名: getaspectratio </FONT>
$ |  ?0 R) Z4 t9 s$ g; C# O$ |功 能: 返回当前图形模式的纵横比 " ]* s4 }5 x% c' [. T
用 法: void far getaspectratio(int far *xasp, int far *yasp); ) F2 U/ ~1 l6 D0 ?
程序例: </P>6 O( A1 ^  b5 p! ]" L4 N. I
<><FONT color=#0000ff>#include <GRAPHICS.H>+ I( _- k# S! S' n) k
#include <STDLIB.H>9 S7 D* ^) ]* h, m5 F& H
#include <STDIO.H>
0 `- X0 O; q+ f' o3 D#include <CONIO.H></FONT></P>+ i! |3 `: l4 I: R& n8 j
<><FONT color=#0000ff>int main(void) 7 p, q* A4 r, }& {& B4 q
{
( V0 L! F9 s+ N: y& }/* request auto detection */
- K' [( ~' D) U3 v6 u; d0 xint gdriver = DETECT, gmode, errorcode;
) U" n# l) {, q2 B8 dint xasp, yasp, midx, midy; </FONT></P>
' h( [+ \2 |/ H% v1 g( H1 ]  {<><FONT color=#0000ff>/* initialize graphics and local variables */ 1 ^$ ^  o3 D5 ~* `
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 e1 V* `. o: \7 h5 a; q7 d6 \7 ?
<><FONT color=#0000ff>/* read result of initialization */
7 Y3 P' d& b: w9 cerrorcode = graphresult();
2 K# f' }6 v, s2 P/* an error occurred */
4 C. X) ^' \" e5 m, J1 Xif (errorcode != grOk)
9 @" c7 z4 \5 T+ u! A{
% j% |, Y1 v& i$ }printf("Graphics error: %s\n", 0 ^9 J) [, u- {  K5 W  i
grapherrormsg(errorcode)); 4 R6 d8 j, O9 l3 Y$ q
printf("Press any key to halt:"); $ o& \% |2 D  a+ K$ U; Y
getch();
, ]2 J3 A# k' ]/ A. I6 u/ e/* terminate with an error code */ 2 t0 M1 @5 W! O7 t8 w. a7 S$ r6 S
exit(1); 8 i7 @* l# J0 \! w; a
} </FONT></P>
# p! H3 L- v4 E<P><FONT color=#0000ff>midx = getmaxx() / 2; ' D' U  X# s: x- Z1 B  w, H# F
midy = getmaxy() / 2;
* Z& T. l- ^# w! j3 ~1 hsetcolor(getmaxcolor()); </FONT></P>
& z/ q( }$ E! D/ V% d" @$ k<P><FONT color=#0000ff>/* get current aspect ratio settings */ / |4 k7 a- T% n. H  y
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>$ I: v. o# E4 y! I/ O2 }5 Z! y" L6 d
<P><FONT color=#0000ff>/* draw normal circle */ 8 I) h. L* }* n+ x6 H
circle(midx, midy, 100); 2 e. ^8 B8 [& a$ {5 D' r) p
getch(); </FONT></P>
8 Q! m2 V8 V- N4 b<P><FONT color=#0000ff>/* draw wide circle */
+ K( y  t- ?, u+ |$ \cleardevice();
) B# c& B2 v! m+ a% f* s  Ssetaspectratio(xasp/2, yasp);
1 Q/ E' ~; a. \, K$ S. hcircle(midx, midy, 100); 1 O" p5 d5 C; r# a; ^" Q- ?
getch(); </FONT></P>) O( \! n! O& Y3 g$ o
<P><FONT color=#0000ff>/* draw narrow circle */
" S: I3 p1 w0 Y; X, b8 ^cleardevice();
& e* |( \7 Q. Z2 Z: ysetaspectratio(xasp, yasp/2); * L# B! |) I* b" N( q% m
circle(midx, midy, 100); </FONT></P>
8 m1 j9 x; `: H& {<P><FONT color=#0000ff>/* clean up */ ! m$ C- o# q) Z8 ^
getch();
" T6 ]6 Z# c( I. j  d$ ?( K0 M# qclosegraph();
, @1 ]3 T+ T; T( F; W0 ]  V% hreturn 0; 7 J3 n  d4 W  @
} & W' U7 C2 T3 s7 W
</FONT>7 x6 ?1 p0 ]4 {1 d- D6 A) B! }

4 {: V/ m% c& G8 I6 r4 l* f</P>
2 [5 L2 _) w* M" Y0 C<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
8 W3 K# e/ g% f功 能: 返回当前背景颜色 ; |, q' B. c; l4 b7 F
用 法: int far getbkcolor(void);
( D6 q; I6 l0 [9 ?6 ^+ m6 h程序例: </P>8 E4 P. j( A7 \& W
<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 [/ a3 G$ @+ y( @#include <STDLIB.H>
5 U) w5 q5 C4 i4 X#include <STRING.H>
- o# _, U. I9 q; \# x#include <STDIO.H>$ G9 z2 U9 y7 T+ {
#include <CONIO.H></FONT></P>9 b9 ?4 R( `' T
<P><FONT color=#0000ff>int main(void) 6 O( U, C1 |% Z
{
( B7 u7 t$ ^* y9 ~: C+ K/* request auto detection */
5 R( Q5 r" O' H: B1 ~9 oint gdriver = DETECT, gmode, errorcode;
5 w) A* z1 a0 j" E$ {& Kint bkcolor, midx, midy;
% W8 a8 y) W+ f/ p& y& x9 Qchar bkname[35]; </FONT></P>! {# H2 f( O" p; E  M
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 C5 a2 q, @2 y6 D* ^7 B$ D+ ~initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) \5 O4 D- G4 s0 O<P><FONT color=#0000ff>/* read result of initialization */
% U: m+ M: B5 b8 T6 w4 r# i& u# ]errorcode = graphresult(); 5 Q2 X1 m/ D( X7 C9 w
/* an error occurred */
% R: F' f7 g/ @8 G2 W- z8 E6 ^; Q  }if (errorcode != grOk) 7 o, H4 S3 h  \
{
5 R( P, f5 w, c: e6 A; b& x, h7 j  jprintf("Graphics error: %s\n", % |5 X+ o5 i5 b' r9 o: e/ B# N6 S
grapherrormsg(errorcode)); 1 O3 j+ a  E5 J  p2 m1 h, x/ f" k% Y
printf("Press any key to halt:"); $ A# U2 p0 h% i% [( g4 I' [+ u% k/ ?
getch(); 0 ]: O$ a: b( o4 p4 ~" r& x9 T' i0 {
/* terminate with an error code */ " E" w, R. `) r! \4 `9 w9 W; ?
exit(1); + m. K7 i0 g0 o; L" ^
} </FONT></P>* Z$ ]/ D! w/ v- N; ~8 Y! I% }
<P><FONT color=#0000ff>midx = getmaxx() / 2;   D- b- Y& y# S# w& T& u/ C! k
midy = getmaxy() / 2; 9 m) w6 G* h' A! A6 p% H
setcolor(getmaxcolor()); </FONT></P>
5 W* i# Z- P) }% D5 t; g" W<P><FONT color=#0000ff>/* for centering text on the display */
/ r0 @" I3 i% D; ^: Ksettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
2 Y: m7 w0 n; ?& O( X$ Q( ]<P><FONT color=#0000ff>/* get the current background color */
4 m- s$ j" {9 L! d3 Kbkcolor = getbkcolor(); </FONT></P>' B. m+ v: Q/ e
<P><FONT color=#0000ff>/* convert color value into a string */ ; \# @6 x4 O, X( R8 `
itoa(bkcolor, bkname, 10); ) e7 |+ \# |. z% z( n
strcat(bkname,
3 f( R. U/ ]; z4 E" is the current background color."); </FONT></P>
; _+ k5 V% ]: Z; a5 |- O<P><FONT color=#0000ff>/* display a message */
4 p7 J9 M  w! souttextxy(midx, midy, bkname); </FONT></P>
# C8 i$ D+ F$ n+ E7 v3 r1 ?<P><FONT color=#0000ff>/* clean up */
: R* B, Q- `  Jgetch();
& m2 @* g$ t7 b# B) h* \closegraph(); 7 T/ l8 |& g, ^% i& J7 p( r( Z# k, L
return 0;
: S3 s7 Z# @% }} # M: M2 i- H: B9 c+ g1 _5 \+ `

6 i0 E/ ]' N) n" R5 c</FONT>
% A+ _1 q* V6 U" v  v' s  h8 o: l</P>  E) n+ ?/ `7 d) V4 ?, S: f. q6 ~
<P><FONT color=#ff0000>函数名: getc </FONT>
8 x% t. |% X1 y* R- \; M功 能: 从流中取字符
4 z! C$ _7 r& e9 \' r9 U用 法: int getc(FILE *stream);
+ b3 h" Q, x4 X/ e) q3 B程序例: </P>4 B) y+ v9 U* u$ J0 R3 r
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>3 x/ Y; \) g3 C3 m/ h
<P><FONT color=#0000ff>int main(void)
6 b0 [  V/ _, i. x, ]{ 0 F) `" G! l5 [+ P+ S( G* O! B
char ch; </FONT></P>
0 X$ G. y4 }9 w6 `+ p/ b' y+ x<P><FONT color=#0000ff>printf("Input a character:"); 4 Y' h/ x9 ]9 B; O1 i
/* read a character from the
( H) @4 [  `6 y2 D: qstandard input stream */
8 `; H+ [4 X3 m9 r' g0 cch = getc(stdin);
3 x) W+ H1 A: t. d9 Y. ~- M, R) S2 ]( Cprintf("The character input was: '%c'\n",
+ R( `) D) Y' tch); : [& K; X3 v6 [) _- |7 }* C" n5 q
return 0; , K- h2 E8 ^" O* k1 A% o6 _
}
. e. F% T; a6 T9 Y# T% v
& O* j: |9 ]' L! Q. E. e</FONT>
. b0 G# u$ c4 G+ D( @</P>3 E5 [4 S. L4 n7 l$ e1 o) N# p9 O
<P><FONT color=#ff0000>函数名: getcbrk </FONT>
! s! z, Q0 S9 s0 D功 能: 获取Control_break设置 3 X/ T, u% |" V
用 法: int getcbrk(void);
) ]' B7 ]- e  l6 H: r7 B程序例: </P>
' p3 f/ r: D, E! ^. S' ^<P><FONT color=#0000ff>#include <STDIO.H>
5 o2 n+ A" L" v6 n4 y% I; K#include <DOS.H></FONT></P>2 }1 U1 x" M6 q2 h# u, B, c( R
<P><FONT color=#0000ff>int main(void) 7 t% a  ]5 m; k% M1 _$ T
{ 0 N1 h7 I; }4 K  y2 V& E7 Y
if (getcbrk())
; q3 h& z" T. V  t- Y8 Zprintf("Cntrl-brk flag is on\n");
0 v) @, x! d$ V" ?* Gelse . z$ U. o; [. l
printf("Cntrl-brk flag is off\n"); </FONT></P>
: c) p) x$ g* T( l; @0 d. ^<P><FONT color=#0000ff>return 0; 2 s: }5 H4 ]0 X* G- D
} </FONT>
, l& ]- v/ |) t8 G  |
' x7 Q% _1 E4 f</P>% E! S$ @8 Y9 N- s& v9 [
<P><FONT color=#ff0000>函数名: getch </FONT>; z) P% R* v  Z3 p1 K; _
功 能: 从控制台无回显地取一个字符 . D, [( ]0 u  \# ~3 o8 F
用 法: int getch(void);
) M9 B' f& ~  L: J9 f: `5 d) P% y程序例: </P>
$ T0 k2 h$ T" |# V6 X8 t<P><FONT color=#0000ff>#include <STDIO.H>- }8 M$ D! F3 S9 o+ H! Q( e
#include <CONIO.H></FONT></P>
; W2 C( ^+ j7 u. }0 {  l" o0 S) p<P><FONT color=#0000ff>int main(void)
' [$ v5 A# ^6 l2 p2 `5 B: V! g{
5 N" X$ W6 U/ I0 Ychar ch; </FONT></P>  [3 {; e5 [* F4 H- r* W& i0 Q3 F) k
<P><FONT color=#0000ff>printf("Input a character:"); $ l4 N1 k, M: z3 c0 I
ch = getche();
0 V& q: q; U: w4 cprintf("\nYou input a '%c'\n", ch);
' l5 g6 }: K/ c6 e( Breturn 0; $ [" T" Y! H; O$ i: D) ?% `
}
3 f# t7 ^% D- t) {" ?; b' G  W) F( [
4 J9 {: O0 @6 g: u& L6 A# E/ z</FONT></P>
# q4 z: X: v4 n0 v4 d, ~8 f<P><FONT color=#ff0000>函数名: getchar </FONT>
0 V) t! V5 `' x- s( \2 ]功 能: 从stdin流中读字符
4 m+ I& t6 u" Z4 B$ N# z7 w9 `用 法: int getchar(void);
3 d9 p4 C5 B8 B% W1 M3 Q# l程序例: </P>6 H& T1 K, E+ o: q# _
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>  l1 H9 y4 \+ w# L# m: O! G
<P><FONT color=#0000ff>int main(void) ' B3 n- l, U; t  T  s% m
{
! F/ t, v# R% v) H) t! jint c; </FONT></P>& S) H+ M. N# D
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and 4 V8 Z2 N: Q5 Z6 U& t' B8 L
is line buffered; this means it will ! ?# w) q4 r- B; P) h7 H
not return until you press ENTER. */ </FONT></P>
, z3 \; R! a" I3 _<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 3 p3 r& x8 W7 X5 Q1 d& a' D( T8 W
printf("%c", c); </FONT></P>
% g3 A7 ~" r& W  I2 n: I0 M<P><FONT color=#0000ff>return 0;
1 u2 d! L# h: x3 O}
3 d; \' V' o" [( s4 `</FONT>4 G2 m$ ^: Q) V8 }: f
</P>3 v! }/ |: p: e! s3 a- J; D8 ]
<P><FONT color=#ff0000>函数名: getche </FONT>. J% o) D" T7 ]4 x# o
功 能: 从控制台取字符(带回显) 5 P1 C2 Q6 V8 n  V/ {2 E* z; }: T
用 法: int getche(void);
- n' e& U' P1 }程序例: </P>
) g7 v$ ^" w7 p) ]$ v<P><FONT color=#0000ff>#include <STDIO.H>4 a" o7 P( i  r# ~. L2 r
#include <CONIO.H></FONT></P>
7 _6 V$ [& h7 T<P><FONT color=#0000ff>int main(void)
) t* ?5 I8 f0 R7 z2 `{
. L" l8 W3 W0 X- B/ Dchar ch; </FONT></P>2 p' v. G  }! t6 ^. y
<P><FONT color=#0000ff>printf("Input a character:"); : Q6 a' P3 s4 X
ch = getche(); * z7 b) ^  g# m& s
printf("\nYou input a '%c'\n", ch); # p" ]9 B7 z, u6 W
return 0;
1 D" h# f1 a+ ?! b  u}</FONT> / \* S9 O6 m1 N$ q5 |
* u# o5 A' R. v: R7 h* _
</P>
" p: Y! }$ @: I$ F5 y: p<P><FONT color=#ff0000>函数名: getcolor </FONT>
% ^: B- l' r" F0 G& ^# B% E功 能: 返回当前画线颜色
) U. n. N6 y  p+ p' R( ^用 法: int far getcolor(void); ! {, b* D! V* @/ T# x. ~
程序例: </P>
2 r! o( Q5 p$ }* y" s' q<P><FONT color=#0000ff>#include <GRAPHICS.H>
) N% y& |4 A& d9 q0 w- v#include <STDLIB.H>
/ K/ u; u/ R6 O! U#include <STRING.H>
) n2 f2 B. u& q+ W) {7 M) Z#include <STDIO.H>% j7 K6 @$ Y( e8 \
#include <CONIO.H></FONT></P>
& e& y: V* M& R$ H5 |<P><FONT color=#0000ff>int main(void)
( _. T$ A; r2 S: o1 v6 h% ]{ + e$ j+ P7 [) I$ @0 g- H
/* request auto detection */ / {" s9 C- t) E8 y, `
int gdriver = DETECT, gmode, errorcode; 1 {" P2 ?. h0 n0 r
int color, midx, midy;
+ T" `$ D, I( b9 S2 O1 Xchar colname[35]; </FONT></P>
+ H% E* E  h4 ]. n<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 g: g. `" I6 {$ g, V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 ^" U6 U. S9 X9 O% T5 L<P><FONT color=#0000ff>/* read result of initialization */
; {7 l5 M/ `) L8 terrorcode = graphresult();
# g& K2 Z& V, r/ [3 C/* an error occurred */
8 I* d# {/ a' Y* Cif (errorcode != grOk) & c( Z* c% g$ d
{
1 V: \" f" @0 p9 W# P# U. ?( P; `printf("Graphics error: %s\n",
9 a: a0 W8 s  |5 tgrapherrormsg(errorcode));
# v( c/ B2 S% J3 D; ^" E1 Rprintf("Press any key to halt:");
, b( P6 ~- H4 M0 l. rgetch(); " N4 F; `* e6 e, {
/* terminate with an error code */ ! C0 [6 x% R0 A% u
exit(1); ! T, G) h/ S; t8 {0 U0 k
} </FONT></P>
- V: U$ G( i3 n<P><FONT color=#0000ff>midx = getmaxx() / 2;
& |) l/ ]# p. ~midy = getmaxy() / 2; 2 D) b; R. m2 {+ U' i
setcolor(getmaxcolor()); </FONT></P>) W- L' Q& c3 Z) L
<P><FONT color=#0000ff>/* for centering text on the display */
: ?$ w$ t* a" i/ x+ {8 d) Z+ bsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>& e  j7 ]. `+ y& Q. x* V
<P><FONT color=#0000ff>/* get the current drawing color */
: [, U0 `* m+ e; N! k! W) N, @color = getcolor(); </FONT></P>
6 X8 M+ @' n/ |( P! l<P><FONT color=#0000ff>/* convert color value into a string */ # [; }8 T+ ~% z2 _' j& {! I
itoa(color, colname, 10); : {8 e, E  U) A; Q, \3 ^
strcat(colname, ; V+ F* A+ d1 ]3 m
" is the current drawing color."); </FONT></P>
! ]/ T* R: ]$ A. @# P2 F/ l<P><FONT color=#0000ff>/* display a message */ : s- M. d! l, W3 E. j; L3 c
outtextxy(midx, midy, colname); </FONT></P>
* ?- V' x) F& l+ T% z& \<P><FONT color=#0000ff>/* clean up */
  ~0 [+ ~. X3 H. N5 o7 vgetch();
3 S0 D5 t+ f% Iclosegraph(); : K1 h3 U; I# N; k
return 0;
  @2 z- q  G7 I0 |) G2 n+ T1 b}
" l1 v# o. v( F9 ]7 [4 l& z+ l</FONT>
  d9 w$ d  u* j</P>
7 N9 `  n% k1 P( u6 X, G6 J! v<P><FONT color=#ff0000>函数名: getcurdir </FONT>  e5 l6 _: j0 b' |4 t' e: m
功 能: 取指定驱动器的当前目录
' s2 W6 t, }2 G" G用 法: int getcurdir(int drive, char *direc); 4 t( V( x% W3 ?( u, a
程序例: </P>
' O) B: @  m) J1 S) w<P><FONT color=#0000ff>#include <DIR.H>% X* p4 O) v9 Z! p
#include <STDIO.H>
1 ]9 f% T( W. \#include <STRING.H></FONT></P>
) j1 O3 R: E5 _5 s/ @<P><FONT color=#0000ff>char *current_directory(char *path)
( I  C( M, t3 P+ h! ?  i{
7 c$ t$ `" I: u* X. M& q& Mstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ * r# h) X" X0 e- s! c
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
0 w* S3 T8 b9 @6 n' N$ tgetcurdir(0, path+3); /* fill rest of string with current directory */
$ G0 s9 v0 r4 |% Wreturn(path);
3 B. X% G3 B2 N} </FONT></P>
6 g' `+ @5 q. i( ]4 [. I<P><FONT color=#0000ff>int main(void)
- w' ?: l2 z5 [* C{ 6 t" ^7 m/ y! r
char curdir[MAXPATH]; </FONT></P>4 C8 b7 {2 o4 E& S& C. K0 g
<P><FONT color=#0000ff>current_directory(curdir); " Z' X5 j6 r2 J0 K" T
printf("The current directory is %s\n", curdir); </FONT></P>
% s* g# U% D3 l8 ?<P><FONT color=#0000ff>return 0;
; i6 {3 ?+ k% C5 Q! y$ \; y- k3 |} ! M- p6 L. _% H8 t( O( K
</FONT>- h! r5 r( C* ^1 K3 P
</P>
4 l" Q- W2 Q) l, y& `& n4 n<P><FONT color=#ff0000>函数名: getcwd </FONT>* f. X0 A* h. Y0 Z% F1 E$ j2 ^7 [* `
功 能: 取当前工作目录
( r" n7 F9 S, d! y, V6 p用 法: char *getcwd(char *buf, int n); 9 c" h( ?! b$ V+ P
程序例: </P>
  Z$ s: U' m5 {6 _+ J<P><FONT color=#0000ff>#include <STDIO.H>/ t8 k. p2 J4 u; _2 p
#include <DIR.H></FONT></P>  u# L* }$ ~" U
<P><FONT color=#0000ff>int main(void)
- U- e$ l% r. i' p{ 7 Z& \7 e: @6 G. W( O; i9 @( e
char buffer[MAXPATH]; </FONT></P>0 H6 ]2 L: I6 w; D- e0 p) n
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
0 W5 e; Q1 b7 vprintf("The current directory is: %s\n", buffer);
- g/ ]! u- N& g) S0 f3 _return 0; , R* v0 `" \: i# h5 f
} </FONT>
3 r' b- T, ?  e% N4 l# R5 _4 r# {1 [' H
</P>
. i6 C2 i- [5 A- O  K; _<P><FONT color=#ff0000>函数名: getdate </FONT>
) F  b% n; l- u# Z" h, h功 能: 取DOS日期 ! t0 }7 n' X" g' M; ^$ B- P
用 法: void getdate(struct *dateblk); 1 r  F: q/ e3 ]  B7 L' \. i" r
程序例: </P>
+ C# e& z! t6 R- e2 W<P><FONT color=#0000ff>#include <DOS.H>
. h/ @5 H! t5 \#include <STDIO.H></FONT></P>
1 X! b; {  ]) h2 Q( Z4 {<P><FONT color=#0000ff>int main(void)
$ d7 k% U6 b8 h/ Z* Q{ ) l8 y6 F# p  Q- C* V
struct date d; </FONT></P>
2 ]- k8 K3 K) }  D+ c8 g<P><FONT color=#0000ff>getdate(&amp;d); 2 u; I9 N$ E0 W
printf("The current year is: %d\n", ! Q2 X, L7 D9 H4 I
d.da_year); * ~/ V% y2 g- i9 m) ?9 v  M
printf("The current day is: %d\n", 9 ?' J# B, t! \3 ^3 s$ v
d.da_day); 6 W/ k1 G; D/ A* o+ l+ A( O- ^
printf("The current month is: %d\n", 4 f' R$ j5 W- ?  m. q( c+ T
d.da_mon);
3 g, G3 C( p: v% y! _9 @4 c1 [return 0; 9 ^, q5 j7 j* B9 v' @/ ~
}
7 r0 s9 h, h7 o4 B' u, c9 f6 j</FONT>4 d- Y# V: o! _+ M
</P>
, b: v2 z0 k) O<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>' g: U$ B$ d/ M
功 能: 返回调色板定义结构
. x* c- S3 h  R" H' ^! R: R用 法: struct palettetype *far getdefaultpalette(void); 4 V+ N1 U6 _/ q+ y( ?) }3 q
程序例: </P>
1 C* a' D3 T* {8 k; R$ [, O<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ `1 l/ l; F$ {' X' y#include <STDLIB.H>4 x& ?7 R3 T, a& A! @4 d3 x
#include <STDIO.H>: v" n, ]9 i9 ]/ P, g. k! M
#include <CONIO.H></FONT></P>
6 L9 E' m3 |% g+ U, }0 g3 b9 w9 X<P><FONT color=#0000ff>int main(void) ; v3 W. r7 g) L! p$ Z$ V* O* C
{ % Z; ^  a3 V9 d* i& Q( p
/* request auto detection */   \# Q" l/ q+ C! Z2 O4 G
int gdriver = DETECT, gmode, errorcode; # N: F  n. J, e) }+ r9 p, I
int i; </FONT></P>
7 b+ W+ E! P: T) L3 a; N<P><FONT color=#0000ff>/* structure for returning palette copy */ ; f3 ?1 H$ r) v* u) L2 I
struct palettetype far *pal=(void *) 0; </FONT></P>
' G$ C! W5 b+ i' }<P><FONT color=#0000ff>/* initialize graphics and local variables */
) S( D( K) H/ {$ x6 v; Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 |5 x3 h6 b9 Z, |% j* h( Q4 @<P><FONT color=#0000ff>/* read result of initialization */
( v4 g- m! }, x  q. ~$ Rerrorcode = graphresult(); % B" R6 J, y2 ^" O* g
/* an error occurred */ % v* R3 |; _1 f& d! _8 K! L4 z
if (errorcode != grOk) ( z  Z# q: S. I- \
{
0 f6 [" j) u" T1 X- cprintf("Graphics error: %s\n",
9 ^0 U, X# V% n8 t, J; cgrapherrormsg(errorcode)); 9 e; {# d) W: Z% H1 ^8 ?2 G* _
printf("Press any key to halt:");
) b+ W- x3 B. _  Zgetch(); 9 G: O2 t7 k) D9 {0 G
/* terminate with an error code */
" }) L% e7 h  H; Gexit(1); 1 J4 {2 R+ J  a( C, [6 ?- {8 ^
} </FONT></P>
: t" {7 P! _$ H; C8 [& s<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>& R8 l9 d3 Y$ ~7 O- |
<P><FONT color=#0000ff>/* return a pointer to the default palette */ + ]3 g1 e; i& }7 |6 j
pal = getdefaultpalette(); </FONT></P>
: W. u6 _2 @( {# f/ @3 Z" l<P><FONT color=#0000ff>for (i=0; i&lt;16; i++)
0 `6 N5 S) i% J( j$ l{ 3 K, P& @& N3 z0 j" f9 A/ ~: m
printf("colors[%d] = %d\n", i,
. N) n- u4 H. B" G* w' o! @pal-&gt;colors); ' r3 X6 v8 l! d; p: o+ \6 H- k
getch(); / m5 b9 ^: V4 t, Y% |9 H' y
} </FONT></P>+ ~" Y) ~8 M: [: U! y; U) N2 z7 G% z
<P><FONT color=#0000ff>/* clean up */ $ W, q6 ^) N/ I6 F* P
getch();
0 I  W" w1 D* h: {4 A+ n1 [$ Qclosegraph(); % M( L4 @! V/ M7 P
return 0; 2 s+ f' a# _4 Y
} - G7 t+ r3 P) g! T) e9 q4 A' }$ [
</FONT>+ [+ y" g$ O  t5 o, S4 |& O" S
</P>
% m# g9 v) Q6 h1 g' C* o<P><FONT color=#ff0000>函数名: getdisk </FONT>
- J% q4 O( C) a: A. j& y功 能: 取当前磁盘驱动器号
' A0 b' x( A1 |2 j. l9 z用 法: int getdisk(void);
2 N5 A1 r" W. j2 a+ U. \程序例: </P>
* q0 z( w" R. h  d1 q0 `<P><FONT color=#0000ff>#include <STDIO.H>) [; s) X+ G9 g6 t6 u' x4 S  ?
#include <DIR.H></FONT></P>
( i# k, t0 }  S9 n<P><FONT color=#0000ff>int main(void) * V- r: J2 ~' W7 m
{
9 R" D4 N- ~$ d" o5 R* rint disk; </FONT></P>; F3 _7 i: \) U7 j! l3 V7 m, R
<P><FONT color=#0000ff>disk = getdisk() + 'A'; ( a4 [0 P2 h9 S& T8 A3 G1 [! D
printf("The current drive is: %c\n",
5 `* z1 E8 {/ P; A6 xdisk); * k; _1 e& S; p6 C/ R6 u  _4 h" B
return 0; : S: y! e/ `8 T6 O( r
}
' z- r* t& V, `3 D7 S  d
7 E/ `& M0 |" O8 v7 ]3 t9 |) ]</FONT>; k$ M  X4 k0 a! l$ d
</P>  T3 K$ e$ g# V0 _& Y! y) g. U4 P' I9 n
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
+ w- o; h& |) H2 O/ Z功 能: 返回指向包含当前图形驱动程序名字的字符串指针
4 h' e4 n* d, g$ O! y$ }$ @用 法: char *getdrivename(void); * F0 T3 G$ v! B2 L) h% p0 l
程序例: </P>" T6 n: Z5 ?- p
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ i1 B% J7 `5 C" k* ^#include <STDLIB.H>' t- \% |/ ]0 \( C! \2 F- u+ g0 B
#include <STDIO.H>* T' z& ^3 g' a; F, A2 {
#include <CONIO.H></FONT></P>
( Z6 ?) A/ R$ W<P><FONT color=#0000ff>int main(void)
9 J) J6 I# b6 D: \: H! ]* j5 g{
7 h* X2 |% Q+ R% D. _$ A9 d8 Q) \/* request auto detection */
0 M$ Q. Q( G0 zint gdriver = DETECT, gmode, errorcode; </FONT></P>
0 Y* V9 q8 B/ u: g8 t4 l<P><FONT color=#0000ff>/* stores the device driver name */
/ B, q' z! b: achar *drivername; </FONT></P>4 |# e  w0 o# Y; @6 l1 F
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " s, E/ }% h: _8 ~4 c0 O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 g6 ^0 h0 n! ~
<P><FONT color=#0000ff>/* read result of initialization */ " u- \7 Q) O, _
errorcode = graphresult(); 5 G+ v0 C& F! G/ Y
/* an error occurred */
+ X& l$ W$ |2 x' K+ d, k/ P4 Pif (errorcode != grOk) ) R: @$ U4 N: ^' m
{ $ q/ y# N/ W1 t( l
printf("Graphics error: %s\n", + T' M! N/ M/ A) b+ D
grapherrormsg(errorcode)); ( p& X: G+ s; {* A- T
printf("Press any key to halt:");
5 V! {( m  j2 g6 _6 Xgetch();
' o9 \' e9 l3 i; Q/* terminate with an error code */
8 x5 D' v* \: g. fexit(1);
( p2 i( y& m3 f4 Q( w4 Q8 \2 ~} </FONT></P>
9 f6 `4 R" i$ |# N5 `9 F1 \<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
; ^, P0 A, m7 }; g1 O( B  O<P><FONT color=#0000ff>/* get name of the device driver in use */ / d4 W% h+ e$ }' G3 C
drivername = getdrivername(); </FONT></P># p! J5 D' R4 K' L* D. H
<P><FONT color=#0000ff>/* for centering text on the screen */   e5 s7 j6 r0 N2 z, Y2 I5 c  g
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>5 m  W" j& k2 @5 z3 g. ^
<P><FONT color=#0000ff>/* output the name of the driver */ * G- [" T/ v8 D
outtextxy(getmaxx() / 2, getmaxy() / 2, 5 v/ v' x. F; c1 ]
drivername); </FONT></P>* R7 Z* M. Y* X/ s! ^
<P><FONT color=#0000ff>/* clean up */ 6 n" d$ X9 ^8 b6 b
getch();
) H* Y; ]: X0 z; h* v6 i2 Aclosegraph();
6 R5 s; B6 A3 o0 Hreturn 0;
% m- G6 P# F0 S4 n7 X1 N" K}
& L& i* L% E; ]5 P6 |4 w9 g</FONT><FONT color=#990000>
- W1 ^  \% @4 n! @</FONT></P>5 e( i( f9 s  u
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>
: W: S% A/ B$ h7 v. F  M7 `<FONT color=#000000>功 能: 取磁盘传输地址
" i3 I. Z3 n* b) F# g. ~用 法: char far *getdta(void); : d) @' N1 W5 y
程序例: </FONT></FONT></P>
$ l* J/ g' Y7 K# z<P><FONT color=#0000ff>#include <DOS.H>: o9 U4 p# [+ U) C1 g
#include <STDIO.H></FONT></P>
2 ]: n/ \3 K: Q% @  z<P><FONT color=#0000ff>int main(void)
5 ^' i* a; R' ?+ A2 c: D2 Z" ~, A{ ' Y7 T( y5 ?9 U- ~% `
char far *dta; </FONT></P>: x/ M* j( D0 `" D6 E
<P><FONT color=#0000ff>dta = getdta(); - F! W& m: U8 E* l+ @5 c
printf("The current disk transfer \
( Y! V' j+ e5 L) T. a1 kaddress is: %Fp\n", dta);
  U# m8 G( c& F6 V! l5 D0 areturn 0;
4 G. p' i5 J) }0 o2 m} # \: K$ r4 w: Z8 j) F
</FONT><FONT color=#990000>& h5 e" ]# K8 w  V+ K
</FONT></P>
) R5 a4 E) G# z, ]<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
- h1 `. \, R) ^2 E<FONT color=#000000>功 能: 从环境中取字符串
& M8 g0 S, F- h" ?用 法: char *getenv(char *envvar); & r& a% \. ?$ _& y/ l& t  ^
程序例: </FONT></FONT></P>
7 i# Q5 Y- r: H. B" s# ?" a<P><FONT color=#0000ff>#include <STDLIB.H>, B* h/ A; l. A, V! G. u$ f" h# f
#include <STDIO.H>9 U, N6 q7 V: [5 C
</FONT></P>
& H$ ?% u- w+ `! g! `6 X" @, E<P><FONT color=#0000ff>int main(void)   B% O+ k5 s$ t- L" ?- O
{
# c6 j+ A* ^; |  I0 mchar *s; </FONT></P>% Y6 h: S- {$ o* U
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
: X8 y9 p9 S" F, R7 {printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
- ~" D+ z" d$ h$ U/ @6 d<P><FONT color=#0000ff>return 0; ! A4 e) |5 B; ?6 m" b$ a
} </FONT><FONT color=#990000>
5 u: _, Y5 r, i1 p* ~& P- {$ {
4 l' V2 A0 W5 T, h
2 M/ P( a0 E' \3 P7 H</FONT></P>
3 z0 A: |& C1 J" V6 w0 q2 D<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>9 L* _5 V2 [/ |3 o
功 能: 取文件分配表信息
7 d* e. h0 M  E/ P, Z( ^用 法: void getfat(int drive, struct fatinfo *fatblkp);
' I1 a% Q9 H  W+ Q% z! D# N程序例: </P>6 s$ Y" |9 \1 T, M" v
<P><FONT color=#0000ff>#include <STDIO.H>
+ m3 d) @! `# H/ O#include <DOS.H></FONT></P>
; w  y7 T3 y$ {+ h<P><FONT color=#0000ff>int main(void) " M3 _+ v) y6 ~+ M4 Y: {" q- h6 B
{
( G1 Q) M0 d  rstruct fatinfo diskinfo; / h/ f+ W7 c- P2 l+ j; ?
int flag = 0; </FONT></P>1 A) u) r. A$ a8 {
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
( z/ n6 u& P3 A8 U6 c( h3 x9 agetchar(); </FONT></P>
/ J5 V/ t) Q, i6 l9 ~<P><FONT color=#0000ff>getfat(1, &amp;diskinfo);
' s  B( l& R' t8 p! {; w/* get drive information */ </FONT></P>
7 S. G" A' [4 a<P><FONT color=#0000ff>printf("\nDrive A: is ");
2 O" H' c* _; Uswitch((unsigned char) diskinfo.fi_fatid)
3 f3 Q" p  g  P1 F; D9 u- [' B; _{ 1 a0 Y! y3 |! X% H: M
case 0xFD:
- `/ G( T" Z4 q$ tprintf("360K low density\n");
- f5 [# y, K- _" w' Ybreak; </FONT></P>" G* a; ^; Y. u5 u) Z$ g
<P><FONT color=#0000ff>case 0xF9: 3 O! k' ^1 M' C- t
printf("1.2 Meg high density\n"); , L/ P0 M( w3 j9 o6 H, |& }" U
break; </FONT></P>4 G0 L: T9 C0 L+ _( f
<P><FONT color=#0000ff>default: 1 F5 c& \; B6 G# r3 B( }
printf("unformatted\n");
' V9 w+ d+ ]7 t& N, Kflag = 1; 3 V% c. ]8 v3 z1 R8 ?0 R. c
} </FONT></P>
" ?( p/ r1 U2 R7 B& z/ ~& t6 z<P><FONT color=#0000ff>if (!flag)
" s6 [2 j" Q6 b% A+ G( @{ - C! l- O% h, w
printf(" sectors per cluster %5d\n",
% i/ q  w7 E- L+ rdiskinfo.fi_sclus); % {+ f+ s. h) a$ d8 N) J9 _, V
printf(" number of clusters %5d\n", 2 v0 M$ o% s: f1 p4 R' y
diskinfo.fi_nclus); % k; [/ G9 R4 ~
printf(" bytes per sector %5d\n", * a; C) g5 p( D; U( J
diskinfo.fi_bysec); - m4 s/ \2 h% ^  a% c* U
} </FONT></P>
( H! L, n1 y- [2 u/ V<P><FONT color=#0000ff>return 0;
: v/ A, W9 ^  F} , ~) N$ D! [8 f$ ?9 `& C
</FONT>  W% E, L2 m# S$ Q6 k
</P>8 f5 }+ A, D6 j, H! p" T% Q7 b& K
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>0 d( S' F0 ?% ]$ X, H
功 能: 将用户定义的填充模式拷贝到内存中
1 {2 f0 z- o. t" w2 M用 法: void far getfillpattern(char far *upattern); - [9 f: A9 q- `4 E- q/ a  M. W: D
程序例: </P>8 g. G9 t5 {2 A/ i' _
<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 F# I+ U! D+ D1 F7 v- @#include <STDLIB.H>* l( U, R1 |6 t5 J' Z- m6 j
#include <STDIO.H>
* X: m4 E' q! U1 M1 _+ J#include <CONIO.H></FONT></P>; L0 p" b1 V3 U+ t' N7 G
<P><FONT color=#0000ff>int main(void)
# I( J! B' C9 a9 w% d, F{ 1 C# B" f) ~, y* N; g- d" H$ V
/* request auto detection */ 1 k; \( ^: d- D! w1 O8 n
int gdriver = DETECT, gmode, errorcode;
+ R. s9 T$ k3 y; c1 w1 {7 zint maxx, maxy; * [6 q& I* r6 ?# }  d$ E" A
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>2 p1 J2 g! V% K9 s" ]+ V8 O% [
<P><FONT color=#0000ff>/* initialize graphics and local variables */
( m" f" [+ J, p$ T0 D5 pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 m  G! U! Y. B: p4 c
<P><FONT color=#0000ff>/* read result of initialization */
0 n0 s% |0 L8 a- Z( Werrorcode = graphresult(); ( {2 W  _3 ?  ]9 `$ m
if (errorcode != grOk) /* an error occurred */ * @- k0 p2 z* N9 {
{ 1 N. ~* F" h+ `
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % ~/ B7 i" W$ Q
printf("Press any key to halt:");
& T5 \: G5 ?  E3 Q: Ygetch();
7 O3 _& A9 E% E- ?; Vexit(1); /* terminate with an error code */
9 b' E( K% \6 B9 o% L} </FONT></P>
% J. L5 d2 M# A- k# q<P><FONT color=#0000ff>maxx = getmaxx(); 3 T+ v. P5 C3 y! r6 I) n
maxy = getmaxy(); 3 k: b: t1 g& f; E
setcolor(getmaxcolor()); </FONT></P>& B3 a& `# x7 e% i
<P><FONT color=#0000ff>/* select a user defined fill pattern */ + a/ V8 Z  ^+ I
setfillpattern(pattern, getmaxcolor()); </FONT></P>
- ]7 T* g# S" Z& [. C3 @<P><FONT color=#0000ff>/* fill the screen with the pattern */
! R* n) x4 _2 t# W" a- V; Hbar(0, 0, maxx, maxy); </FONT></P>
1 Z9 I4 O4 Z$ l: s<P><FONT color=#0000ff>getch(); </FONT></P>
" o$ U4 t6 h4 ]! D! n2 V/ L: \<P><FONT color=#0000ff>/* get the current user defined fill pattern */
$ x3 f- b# q2 _' o* g  Z* agetfillpattern(pattern); </FONT></P>
( q$ }: u; o9 F& k* ~% V, y; Z<P><FONT color=#0000ff>/* alter the pattern we grabbed */
2 Z1 @- D1 X/ [) R  Q9 z: Upattern[4] -= 1; : p" y; V# p, ^- @7 Q
pattern[5] -= 3;
+ f" g* ^; h2 C1 Lpattern[6] += 3; 5 T7 Q/ ^7 r$ ?: E% U
pattern[7] -= 4; </FONT></P>
$ _# m: Z0 p. k<P><FONT color=#0000ff>/* select our new pattern */ , Y: b; G* n" O0 K4 i: }4 ^8 e, U: Z$ D
setfillpattern(pattern, getmaxcolor()); </FONT></P>5 q2 R2 F% B2 [- ~7 G, F' p" z; i, E7 @
<P><FONT color=#0000ff>/* fill the screen with the new pattern */
9 a1 C% O- O. P8 L4 }bar(0, 0, maxx, maxy); </FONT></P>; \1 o3 C, D4 u* r
<P><FONT color=#0000ff>/* clean up */
' V4 D+ x& [$ i# t% S3 ~getch();
: R3 M% {, S! D% Rclosegraph(); ( X6 c$ l/ Z! f# t% @) ~
return 0; / Z& s6 U' L* C4 e: T$ Y) I' o% g
} % i3 k6 k" d, R6 \; ~! [
</FONT>: B7 F& f9 [( }2 \
</P>9 v% D5 F% b. H/ C1 s3 x( o
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>: p% k6 V" j2 T8 a- c$ r
功 能: 取得有关当前填充模式和填充颜色的信息 ; H+ o, o* J: L4 V& T, j- Z1 Y
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 6 C. t$ P7 q; R2 k1 I: H1 Y
程序例: </P>
5 W2 |( z6 U' @+ H+ L( \% `2 X<P><FONT color=#0000ff>#include <GRAPHICS.H>
; ]4 L9 @6 n9 U! ~#include <STDLIB.H>
. a# T) i& F' d5 U7 ]#include <STDIO.H>4 v$ d1 N5 h% X$ k9 V
#include <CONIO.H></FONT></P>
% {6 v/ }# Y! n( Z: O- w4 n% r<P><FONT color=#0000ff>/ the names of the fill styles supported */ , a# G; _9 g+ W4 v$ j. ^( G
char *fname[] = { "EMPTY_FILL", $ b  H) y* Z' k, P+ @2 Q
"SOLID_FILL", . T( v. @; I. o! M
"LINE_FILL", 6 L# r* ^' M8 H7 r% y! }& W
"LTSLASH_FILL", ) y, o5 P! N: n4 J8 }8 U/ ~
"SLASH_FILL", - x1 `0 f% }; L# I! m) F( e; @3 o6 P
"BKSLASH_FILL", / b5 c2 E% c  X# a0 [
"LTBKSLASH_FILL", * _& o8 Y+ D6 W) Q
"HATCH_FILL",
% s( w0 P) d' l"XHATCH_FILL",
' r9 ^+ u" L' Q$ o6 e( X' Q% s"INTERLEAVE_FILL",
$ b! l) i  ~+ S% ]$ h+ I"WIDE_DOT_FILL", 0 v/ Q$ }; O# c0 D- u
"CLOSE_DOT_FILL",
) _" m  X  u( i7 V"USER_FILL"
/ B8 ?0 l; @  G: s' Q* `/ V}; </FONT></P>- F" H% g' @: C6 |
<P><FONT color=#0000ff>int main(void)
# D2 T, G; F% `* W2 f. \{ 0 N9 l( x* I( P! \
/* request auto detection */ / D7 O, X: c$ Q. S: ~
int gdriver = DETECT, gmode, errorcode;
2 A6 [+ y* F% b7 fstruct fillsettingstype fillinfo; , P& e2 }+ O5 m- b8 ^# X( B3 k
int midx, midy; , W# i3 Y, t0 Q7 R- P# R. k
char patstr[40], colstr[40]; </FONT></P>
1 I* A# |0 v# R/ }. x* ^<P><FONT color=#0000ff>/* initialize graphics and local variables */
& M2 U+ C% N2 L9 K* oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 I0 A8 j) d0 V6 l! ]3 z<P><FONT color=#0000ff>/* read result of initialization */
, f- d3 C4 w7 O- T0 a5 Kerrorcode = graphresult(); # h+ n2 W% \9 ]2 B8 T! Q
if (errorcode != grOk) /* an error occurred */
$ g* H# X7 G$ b7 R5 T9 o% L{ # S5 _4 D3 ]  k% N( v* X
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + H' v2 A5 p- o0 b2 n
printf("Press any key to halt:"); ' _$ m4 Z' C4 y  z6 o# j
getch();
# ?7 n% P# D3 r, e& H6 L" z( Fexit(1); /* terminate with an error code */
" m+ e  E* r% N" |" K} </FONT></P>
2 [0 j& f* {* X6 f8 j, q<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 ~3 s  Q5 E# O7 J, }2 L" o# S* bmidy = getmaxy() / 2; </FONT></P>
5 d. j- L& V5 @" y: f- W<P><FONT color=#0000ff>/* get information about current fill pattern and color */ % p  |+ \4 A) ^; @, L  e9 `
getfillsettings(&amp;fillinfo); </FONT></P>5 s1 t; H) n3 c3 [" [
<P><FONT color=#0000ff>/* convert fill information into strings */
+ S. d6 l/ }, L# \sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
0 C) K: t$ }  ~! `1 esprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>1 D. y, l% |0 V; b
<P><FONT color=#0000ff>/* display the information */
5 a3 }: ]# F9 U  i9 L6 P" Wsettextjustify(CENTER_TEXT, CENTER_TEXT); : J/ A- ]+ W8 m/ b7 N7 C
outtextxy(midx, midy, patstr); 9 ^# {8 _5 h  P' O
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>8 n% h7 n2 J  ?  V2 t  k
<P><FONT color=#0000ff>/* clean up */ # K7 Y) `; O' o# \& _) H
getch(); & n6 O  E5 F1 {. D( }+ t
closegraph();
4 z2 ?( |; K( Z9 V* a' X8 ]& z5 Q! w) zreturn 0;
2 p6 G/ V1 P! f} 5 y/ @" Y, f6 o- ^$ X7 i, p8 G( f
</FONT>
( P. t) Q. ~) ]
, S7 z/ |7 g- u% m</P>: L- Q/ t; m& q& \. `' }: z5 |8 S
<P><FONT color=#ff0000>函数名: getftime </FONT>
, M1 P7 p2 u( L; a3 x" W! r  y5 Q功 能: 取文件日期和时间
: e3 u% F8 q% X  I% E用 法: int getftime(int handle, struct ftime *ftimep); - T* x9 I" \9 N
程序例: </P>
* i8 R+ |; ]. b  n& \<P><FONT color=#0000ff>#include <STDIO.H>: \7 M" W1 F" B6 C
#include <IO.H></FONT></P>
2 n; [  ?' ]5 K6 c, q<P><FONT color=#0000ff>int main(void) 0 w* S4 Q0 P# y+ u8 D  ?$ k4 n. j
{ ' E7 v/ \0 e# M8 y
FILE *stream;
3 F8 B5 c1 A  G6 Nstruct ftime ft; </FONT></P>
9 W& L- M8 J; Q! W<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", . X/ P5 f. I% P* [- v
"wt")) == NULL)
) U! O# j; h+ D1 ~, m{
4 O" P; ^' W2 J5 s" jfprintf(stderr, 8 k3 ?* {' H/ w0 K, s6 S
"Cannot open output file.\n");
4 G6 B$ _8 w/ ~$ Greturn 1;
4 q4 g* ]  O# Q, _! K1 B+ Z. y} # v* h  F, I; z1 B8 |
getftime(fileno(stream), &amp;ft);
8 W# B: U1 D  b* M! n) e- cprintf("File time: %u:%u:%u\n",
, K' u% E5 z9 E5 l7 F! }ft.ft_hour, ft.ft_min, 3 O' W5 H" V6 V5 L! M  g0 z
ft.ft_tsec * 2); 9 Z, a3 l/ E  |# H& I) G' Y" D) e
printf("File date: %u/%u/%u\n", , j7 x: X3 ^  g/ t  I
ft.ft_month, ft.ft_day, + ~( v, W# b; o3 H
ft.ft_year+1980);
. O+ M7 D1 `2 J5 xfclose(stream);
2 n& E0 t& Y0 sreturn 0;
1 Q, ~) k' g  E}
! i" t& I' B- N8 _2 Q) D& Z  |</FONT>
; W8 D5 l7 W6 U6 j0 B9 j2 M& f/ S$ f# r. {4 O
</P>  Q( P2 V3 B% P) e. a: F4 L
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>9 H6 ]) r+ \  O- F
功 能: 返回当前图形模式 5 O( Y: E1 b( \- X! J! A5 w
用 法: int far getgraphmode(void); 2 i7 S3 a. m) n; P
程序例: </P>1 _; n, I' ~. X% T0 Z, p( F
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" A4 K  z7 @8 o$ Y! D% N/ Q#include <STDLIB.H>3 d: w; [4 d. k  K- R3 {5 ]6 l
#include <STDIO.H>
8 {5 q- n( {8 G) i9 p2 C- Z#include <CONIO.H></FONT></P>
% [4 A) Q7 z. M<P><FONT color=#0000ff>int main(void)
* P; @& A* A* A% O1 k1 q5 z$ d{ 3 E2 s, E$ O2 v
/* request auto detection */ / y4 E* W& h6 E& Z& A8 l
int gdriver = DETECT, gmode, errorcode;
2 m6 w1 G; N+ Y! |int midx, midy, mode; % e, X( y0 G1 o; F& @- F' K
char numname[80], modename[80]; </FONT></P>
' \) h4 e. n+ s" ?8 E<P><FONT color=#0000ff>/* initialize graphics and local variables */
  I6 Y4 U0 ^3 X: Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, W$ X( E! O% q
<P><FONT color=#0000ff>/* read result of initialization */ 3 H) Z) g+ k2 d' N
errorcode = graphresult(); & k. r3 h" ]' f4 f9 F9 ^
/* an error occurred */ 1 n- j" a, V, a. Y8 W5 ^4 f
if (errorcode != grOk)
1 B# l2 D- l0 P  f  p* I/ R{
8 n% o: ?* T& i* jprintf("Graphics error: %s\n", % f: p% ~/ m+ X3 }6 K
grapherrormsg(errorcode));
, W$ V9 T3 J% J, p8 jprintf("Press any key to halt:");
4 K' C# Y9 g5 f8 d) o2 Pgetch();
3 i* L" n; m" d: e! s- [/* terminate with an error code */
8 A& r2 f3 ?5 P) y% a. [7 vexit(1);
- v/ t" A0 h! v* J} </FONT></P>! A( P% F' R" w+ \
<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 B" G% i0 s  g- s- H( F
midy = getmaxy() / 2; </FONT></P>! |. k, X3 H$ t6 N7 ^1 o  y# I7 Q
<P><FONT color=#0000ff>/* get mode number and name strings */
% P1 M7 e4 H  ?1 F! x2 Qmode = getgraphmode();
- |0 e/ Y5 i7 o9 @sprintf(numname,
4 z9 N6 y: L' w* B; |% A& H"%d is the current mode number.",
2 l# [! p: ]- G' u8 Z: y+ cmode);
2 W& Z5 t+ [0 Z9 R0 lsprintf(modename, # Y3 U. j/ y6 a0 F; W$ @4 V7 M
"%s is the current graphics mode", 0 g4 e" _) q/ E# i) s* \) F* f- A
getmodename(mode)); </FONT></P>0 Z: L4 _5 J& j
<P><FONT color=#0000ff>/* display the information */
; U; [0 l/ z. r! j: @settextjustify(CENTER_TEXT, CENTER_TEXT);
7 T, r" n7 m6 j, X$ s) z6 [2 Zouttextxy(midx, midy, numname); 1 K: E, M; l' q, F: X, r7 a
outtextxy(midx, midy+2*textheight("W"), 8 x) G' I! ^+ {! q
modename); </FONT></P>. J, s  ~( |+ ?
<P><FONT color=#0000ff>/* clean up */
3 X* p! M) I7 }# X+ X7 zgetch(); % m& ~- k( z9 \; A
closegraph();
9 P& ^1 u2 Y+ M  u5 mreturn 0;
: V/ q& o2 \. S} </FONT>$ a% b4 j6 t, [& f, S

8 r6 o# L) c5 x</P>
+ N9 U2 ^8 ^2 \1 h8 e<P><FONT color=#ff0000>函数名: getftime </FONT>4 H2 f; R9 L0 r0 l' s
功 能: 取文件日期和时间
" C' s  X3 _  [4 T  ?1 x: O用 法: int getftime(int handle, struct ftime *ftimep);
6 J4 c  o+ j* P! ~* W) e程序例: </P>
% d0 A, F( Y4 Z1 J( v<P><FONT color=#0000ff>#include <STDIO.H>
  R" x  J5 S  s7 _0 A#include <IO.H></FONT></P>7 @5 _, g1 |+ a, h
<P><FONT color=#0000ff>int main(void) 3 K' ^, U& t: v5 P- C) p
{
, k: R" q) I/ `. I$ dFILE *stream; 3 h6 r( B6 D- A, r3 ~' v1 a
struct ftime ft; </FONT></P>
1 S1 t& p$ T9 h2 g+ ~) X# O<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", , }) B) @' E. K, w* K- L0 l; V
"wt")) == NULL)
/ L0 l7 b' I: C1 f5 m. \  U( O) i{ 5 P: f" Z+ }( L
fprintf(stderr, & |( M# y. s! r1 O- D1 J
"Cannot open output file.\n");
1 Z; h; O- l) c2 kreturn 1; / M: A5 I* U- M% ^% |
}
& ]4 ~0 ?/ z- X4 m* L4 Zgetftime(fileno(stream), &amp;ft); 3 P  t$ M# \+ j9 w1 r
printf("File time: %u:%u:%u\n", 0 H8 }9 x6 \: r6 Y% O
ft.ft_hour, ft.ft_min,
4 t' H: H# b" w7 w2 N: N2 kft.ft_tsec * 2); ! ?$ _: U# W7 y
printf("File date: %u/%u/%u\n",
3 S* Q+ A4 g5 Y, V! e+ P2 x0 P' |ft.ft_month, ft.ft_day, % [5 t7 G4 y3 }. k8 P
ft.ft_year+1980);
$ j" ~9 Z# k& n/ s  _' v$ \$ w8 `fclose(stream); $ |2 z( J: J& b: }
return 0;
  `7 w/ j: X, ?$ W, C! N+ f' X! ?} </FONT>  v5 _# W% k2 P7 {. U
, R- w$ ^! a' I( E
- T( i- D8 Z* K' W& `
</P>- V9 h% u$ U4 `$ e* j9 h
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>5 A* {6 e) I4 F5 _7 ~" N4 y
功 能: 返回当前图形模式 $ Z6 G% N5 ^6 R1 x- {0 a
用 法: int far getgraphmode(void);
+ e7 j* g, T* @# P/ E; c- i程序例: </P>
1 W1 U# A2 b* O6 P7 ]' E<P><FONT color=#0000ff>#include <GRAPHICS.H>& w: [. D& G4 _8 O- p/ o+ C3 }
#include <STDLIB.H>7 _/ b- j0 r6 d4 R5 s: s9 [% c1 e
#include <STDIO.H>/ `: j* X2 Z9 ~* |& b
#include <CONIO.H></FONT></P>2 u* a+ ]( e$ ?# S1 z
<P><FONT color=#0000ff>int main(void)
' u* p6 Z, b. U2 r) e{ ! m) B( |" z* m$ y
/* request auto detection */
5 t& h2 {) S7 N% Aint gdriver = DETECT, gmode, errorcode; + F" A7 w7 _. u3 {& ~% h$ O/ G
int midx, midy, mode; * S( a' Y; p) `& Y, r
char numname[80], modename[80]; </FONT></P>3 U: k. N2 p$ i7 J
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" U$ n8 ~* U% e0 Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# I- N+ |' |: U* e& |" f6 G<P><FONT color=#0000ff>/* read result of initialization */
3 w+ V7 x8 y, E* o3 n' derrorcode = graphresult(); 6 g6 X4 ?( y8 n! h. U" v
/* an error occurred */ ! z/ t- T, b& ?% M- Z! s. ?2 m0 C3 u, a
if (errorcode != grOk) 5 z: D4 z+ j6 v2 Z- U
{
( c0 ]; s' k! n3 Zprintf("Graphics error: %s\n", # i$ c! s% y6 G" ^; S  P( i! \
grapherrormsg(errorcode));
3 U9 e! D# `, Uprintf("Press any key to halt:"); " C& o- d$ R9 I! K; w( S
getch();
7 g8 W5 g$ |2 D/* terminate with an error code */ 4 [3 L0 S* [$ a# F2 }
exit(1);
% w+ l$ C) |5 Z3 n. c' a# k} </FONT></P>
. j8 l8 _3 f' ]6 T  f<P><FONT color=#0000ff>midx = getmaxx() / 2; 1 |3 A0 I" n1 [* ~- {1 T9 h
midy = getmaxy() / 2; </FONT></P>
6 k+ J; a! m! _- M! f. X<P><FONT color=#0000ff>/* get mode number and name strings */ 9 l9 x/ C+ F/ n8 L( E
mode = getgraphmode();
4 p- d/ P$ n* ssprintf(numname, : K( S2 n+ g( T9 s- q/ x' i
"%d is the current mode number.",
0 u9 a) F+ D: S  V5 C! Z* fmode);
2 }+ w, j0 |8 w$ Z9 w) P* j% msprintf(modename, / N7 L/ b7 @/ ~6 n+ H
"%s is the current graphics mode",
- N1 q! f- L/ ogetmodename(mode)); </FONT></P>
2 C+ `( i1 J: f- J/ `- z. W<P><FONT color=#0000ff>/* display the information */
* C0 U) G& V0 Lsettextjustify(CENTER_TEXT, CENTER_TEXT); ) Y; W! q0 ?+ I) d# ?3 _: t
outtextxy(midx, midy, numname);
( [$ {2 A. T8 ~$ Pouttextxy(midx, midy+2*textheight("W"), & h1 Q0 W* \$ i; Q$ a
modename); </FONT></P>
2 l/ A. v& i& W# ~' a<P><FONT color=#0000ff>/* clean up */ 1 E" G# h1 }; \& r
getch();
% C+ C- a1 e0 `& }8 x+ wclosegraph(); & ]+ \! P( I8 b$ A
return 0;
: i, y& v% w/ r} 9 d6 n; y: n& z# m
</FONT>
8 w/ c! `% H0 L9 I, W</P>/ a6 q, E, x9 O3 u) s+ s8 X
<P><FONT color=#ff0000>函数名: getimage </FONT>1 ?$ \- t5 g2 {( }) s, G
功 能: 将指定区域的一个位图存到主存中
) b( M; E8 _6 g用 法: void far getimage(int left, int top, int right, int bottom,
6 V; j8 C3 x/ w2 ?, Cvoid far *bitmap); # A" {& r8 P  j' z5 |- \2 H  r1 y
程序例: </P>
$ A4 E# F  W3 S8 Z/ f- ?<P><FONT color=#0000ff>#include <GRAPHICS.H>
' P% m. W) E) w& i0 [7 G#include <STDLIB.H>
) L0 Z5 C) i5 S- B8 A# n#include <STDIO.H>( H; p3 F( ^  B, R/ i# y
#include <CONIO.H>& b# I- k: a" Z1 H2 u8 W6 N
#include <ALLOC.H></FONT></P>
; E& ?$ f' M, I, K% R  i<P><FONT color=#0000ff>void save_screen(void far *buf[4]); " ]8 x, f8 h4 g  g) d% Q5 {
void restore_screen(void far *buf[4]); </FONT></P>
9 J2 q: p5 F  o. O<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>& o3 L; j% A/ [4 `' k+ L
<P><FONT color=#0000ff>int main(void)
) r7 }) ^8 ^/ f$ y# z4 ?' @7 Y{
* B$ [/ E& Z. i, j+ J3 K  kint gdriver=DETECT, gmode, errorcode;
$ }6 p1 a: y, _$ S% Y% J# r* kvoid far *ptr[4]; </FONT></P>, S9 h% t$ R' f* L9 O6 J8 R; e
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ ( y: l! ^1 E  O2 I: @8 m! |$ @6 _
initgraph(&amp;gdriver, &amp;gmode, ""); ' L6 i; w. F; t& a" @
errorcode = graphresult(); /* check for any errors */ % ^. w# o& ~' b- i# I% t* l6 g
if (errorcode != grOk)
. s7 @( ^" v- x{ : \2 C* H5 Q' t! z- j' T
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 D1 V: ?4 ^0 O, z1 K/ t- U# E! o3 K
printf("Press any key to halt:"); ( [5 {6 g7 }: G7 S
getch();
2 v% f' O% S. R. O: D! C' F* Qexit(1); ) \8 `( L3 J% S) L
}
, x& v! X" |' Tmaxx = getmaxx();   ]* d$ q. @' L
maxy = getmaxy(); </FONT></P>3 K8 s$ q% I: ?+ r: a- {
<P><FONT color=#0000ff>/* draw an image on the screen */
4 S4 s  ]" u; s; N6 ]& Rrectangle(0, 0, maxx, maxy); 6 ^' Y3 T! B* C3 h8 J
line(0, 0, maxx, maxy);
7 y; T$ v! z. Y8 S( V3 ?line(0, maxy, maxx, 0); </FONT></P>
, j0 T7 I  f8 ~( a( X<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
( T# _7 h) Y8 c4 A: |+ y2 Xgetch(); /* pause screen */
& d% d3 G( b2 M- wcleardevice(); /* clear screen */
& c6 m* R$ Q) P% ~5 i/ H# qrestore_screen(ptr); /* restore the screen */
! |' @. n* i" X; N3 o; wgetch(); /* pause screen */ </FONT></P>
5 K$ X4 l6 u# l) {4 N( Z5 [<P><FONT color=#0000ff>closegraph(); * k# M  @, _# E) v/ l. f3 C
return 0; / M) E3 l) U* F  o8 |8 a2 ~5 z
} </FONT></P>( ~/ v$ B& }$ V/ F$ S
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
! G+ D9 C' c% r" c{ / s( t. n) V* x8 P" F' R8 x! S
unsigned size;
& Y4 L- c' C1 r! lint ystart=0, yend, yincr, block; </FONT></P>
$ r$ v  Z% [# A2 _2 k- a4 ^<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 6 p* V: N. W; Q1 d4 K
yend = yincr; ; X- k2 e3 d# E& ^7 ^* |* D+ x3 j& l
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>5 Z9 Y- M7 |; b- `5 U3 ^4 T4 x( K
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
8 F1 R6 O. v1 k7 r6 M( {{ % O3 I, G2 K" S; i$ `+ v
if ((buf[block] = farmalloc(size)) == NULL) * W8 y; q+ m3 B( V* o
{
& k1 x  S- n. d9 tclosegraph(); 1 i. |  k# S" h  j; ?& K
printf("Error: not enough heap space in save_screen().\n");
! X$ w1 w8 }+ Y7 K: y7 ]exit(1);
. }( U) `, X8 {% s. v+ I} </FONT></P>
  X2 d4 |8 D/ `6 C) k' E* C. ?# d5 x<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); 5 {( n# k1 k" P
ystart = yend + 1; $ W3 w0 }1 b9 P% i
yend += yincr + 1; 2 k* V. d( j; v5 v! ~$ V! K
}
( ?4 _6 B( [: M( @+ W) ^& W& w} </FONT></P>. X9 f0 u6 y2 @( {4 p
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) & n$ ?- ]9 a  y2 N
{
9 @% D/ W2 m5 D0 O* n6 i" Vunsigned size; # B6 m4 F- V! Z: `
int ystart=0, yend, yincr, block; </FONT></P>2 O$ M2 E5 l! c& M
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; $ j" ^+ a4 z* M- l5 O* R/ ^0 F
yend = yincr;
# U0 P. f6 H5 L- }1 e* Psize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>* v8 R: z, f2 X8 p7 |5 P
<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++)
* ^6 h. V+ o$ Z/ f% U{ + G9 c( o0 a7 D6 i8 h8 Q+ ]
if ((buf[block] = farmalloc(size)) == NULL)   _! P6 x: j: i: _5 l2 B: }
{
( v  ~0 J* {# X9 Pclosegraph(); 8 p: I+ K! U5 U5 I/ f2 M
printf("Error: not enough heap space in save_screen().\n");
+ ?: O  M) L6 H+ Lexit(1);
6 z% D4 Y6 j  U1 i: D} </FONT></P>
4 g, h# i) [+ k4 g1 k% A<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
9 u$ c, v5 ?- iystart = yend + 1;
# f) b7 o- M, E" s% ?5 ryend += yincr + 1; ) P. k- a! F, z) f2 T! _
} 2 k4 z1 g8 s5 o6 K2 c
} </FONT></P>( A& f" P) S7 i1 q
<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) 4 M( l$ ?  w; y( C
{ & y& j) G! @; M. V& m8 H
int ystart=0, yend, yincr, block; </FONT></P>
: R$ a3 l, C. K/ I! J5 ?* t<P><FONT color=#0000ff>yincr = (maxy+1) / 4; " J7 o* h0 [* J( k( j* x: w7 v- v
yend = yincr; </FONT></P>
! W" f9 t0 o2 G3 l& y<P><FONT color=#0000ff>for (block=0; block&lt;=3; block++) , m  n* i# q$ m8 E9 D) f
{ 9 V' N8 B  O% E0 _
putimage(0, ystart, buf[block], COPY_PUT); 1 v0 v6 r& ?. g! H$ D+ F
farfree(buf[block]);
8 k; t+ `1 W* I" S2 j+ |ystart = yend + 1;
$ Z9 _* V3 j( J% j5 o2 oyend += yincr + 1; ; C5 F. H8 x  t8 M: D2 M) [3 C6 h
}
2 N7 }/ p8 \  b} </FONT>$ g3 v7 N' ~) N$ N: n
<FONT color=#ff0000>
- f  X% N9 g( b9 U</FONT></P>
7 H$ E2 {& V8 Y<P><FONT color=#ff0000>函数名: getlinesettings </FONT>* z" g; ~& p: e: a7 Z& `
功 能: 取当前线型、模式和宽度
6 K; X  i9 q' S. q0 Y: Y用 法: void far getlinesettings(struct linesettingstype far *lininfo): $ M2 W1 A7 N7 ~$ |5 p4 ?1 P( Q* l
程序例: </P>" b" [6 r& \1 y  r2 x
<P><FONT color=#0000ff>#include <GRAPHICS.H>& I6 ]4 ]+ b3 D% P) s
#include <STDLIB.H>
4 \7 p/ h4 }( n9 ^: x+ W' V#include <STDIO.H>
" \6 O' J& b1 w: ?- |+ e#include <CONIO.H></FONT></P>: v( b* L1 |# q# W+ i  O" Q( e5 w8 l
<P><FONT color=#0000ff>/* the names of the line styles supported */
1 P, ~, H- F, K4 schar *lname[] = { "SOLID_LINE", " g/ P' J& `+ H4 J+ f
"DOTTED_LINE",
/ n6 v6 g/ r' K( Z"CENTER_LINE", % e) B# z& C. H( O- s# l
"DASHED_LINE", 8 k$ i- i( A: W% X
"USERBIT_LINE" 2 A1 n9 J! K" G9 h4 l8 g: U
}; </FONT></P>
3 S$ r4 X  |. w+ w( `<P><FONT color=#0000ff>int main(void) % A' I  A% A! P' E9 _( L( `: M0 U+ j
{
) h% ], v. Z& A, [" h1 E/* request auto detection */ * W9 o( B1 }% r  e
int gdriver = DETECT, gmode, errorcode; $ j. g, i7 c# [; z7 d& M, K  i
struct linesettingstype lineinfo;
: `* G$ P3 }- S$ i- Nint midx, midy;
8 g$ M& A+ ?+ _, \/ i' V- I+ P4 xchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>5 m( o2 J1 C9 d$ F" n; A
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 {0 P0 f6 w5 S+ j, ~( Y' N% b0 r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% S% P: [. ^$ M<P><FONT color=#0000ff>/* read result of initialization */ 0 k  @. ]3 T3 s( o" C
errorcode = graphresult();
4 }& f# O% Q4 Z, Pif (errorcode != grOk) /* an error occurred */ 8 p, e: K9 b* b0 [% j# A3 u
{ & s: f3 t$ m/ k5 r9 |
printf("Graphics error: %s\n", grapherrormsg(errorcode));
9 e( Z! p5 w* o# ^( q; w9 hprintf("Press any key to halt:");
; ^! M: u5 L, y9 ^: h  O( m7 q  Fgetch(); / l- [3 M& F- S) @/ p4 N/ L  N
exit(1); /* terminate with an error code */
# Y& J2 t* t: j- l} </FONT></P>
' J$ K( l1 d8 i3 t6 s1 n4 W" Y<P><FONT color=#0000ff>midx = getmaxx() / 2; # i% W) _! ]/ q1 i. O& \4 }
midy = getmaxy() / 2; </FONT></P>1 [5 \' ^$ n1 ?9 g
<P><FONT color=#0000ff>/* get information about current line settings */ * F' T) g$ M) \5 G
getlinesettings(&amp;lineinfo); </FONT></P>
2 n, P. m3 L% G4 B<P><FONT color=#0000ff>/* convert line information into strings */ . \( @" i3 X+ a. v. v, {
sprintf(lstyle, "%s is the line style.",
! i; [/ V$ b4 h& Y3 i- }* Mlname[lineinfo.linestyle]);
* @  I0 f. q- m! r& Wsprintf(lpattern, "0x%X is the user-defined line pattern.", " z8 N& I# J. L/ H0 c# g0 e
lineinfo.upattern);
$ _# B0 m: I8 n, [: W& g$ O# Fsprintf(lwidth, "%d is the line thickness.", 5 r3 i% C9 G5 y* s+ j
lineinfo.thickness); </FONT></P>
  h: W) ]! d' B* g<P><FONT color=#0000ff>/* display the information */ % H* @7 s8 p# k1 u. c( w  ]3 P* w! p8 {
settextjustify(CENTER_TEXT, CENTER_TEXT);
& F8 H; B' |! T8 H4 l- W5 Jouttextxy(midx, midy, lstyle); ) K& [, n; e$ `
outtextxy(midx, midy+2*textheight("W"), lpattern); 5 Z/ j/ ^! ~7 t0 d( h
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P># _6 |1 e7 w+ ^; [; @
<P><FONT color=#0000ff>/* clean up */
3 g8 b/ j# R& @getch(); / m" d4 A4 u- a8 I# g
closegraph();
' |4 U! ~3 O  Y; V; V' q, Ereturn 0;
2 v; R% F$ g7 g# E( s} </FONT>2 b: r5 M" V8 F. b2 a7 W6 Q

4 R; _/ I7 k# a/ R</P>
9 Q/ @2 n4 b: C. Q. w<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
/ j: f$ t$ N" n/ F7 g' g功 能: 返回可以传给函数setcolor的最大颜色值 3 x6 |/ w8 R% o% }2 L% g" v8 w# |: P- L
用 法: int far getmaxcolor(void);
( j8 d( C: S( F程序例: </P>
$ Y9 ~, _: j2 Q<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 K% g, E) A" S6 D#include <STDLIB.H>
- j$ ]6 @2 W2 l% u#include <STDIO.H>
' g2 d: h1 @; H7 N: }& B#include <CONIO.H></FONT></P>
* P; V( P" a. U! q9 M9 K/ ?<P><FONT color=#0000ff>int main(void) 7 J0 ^' y+ i3 C+ H# b$ |6 N
{
- D3 `  N/ g: l# h. D/* request auto detection */
) O: e; H7 G" f& |$ hint gdriver = DETECT, gmode, errorcode; 2 K4 J" h, D) }- y7 N3 s- ~
int midx, midy;
5 b+ W& [; M7 Ochar colstr[80]; </FONT></P>; e5 d$ z  ?1 H
<P><FONT color=#0000ff>/* initialize graphics and local variables
9 D  l. t: N8 N; ~0 l*/ initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 R" x; c5 {: f6 N
<P><FONT color=#0000ff>/* read result of initialization */ + W1 L& S5 v) W0 y
errorcode = graphresult();
' _5 l2 R9 T8 M2 U, Gif (errorcode != grOk) /* an error occurred */ 3 }1 ?/ l! _. l& N( x$ {7 u: [
{ 8 T& v* |, u9 @. h. F
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + P# @1 L  C. Q5 t5 R6 ~
printf("Press any key to halt:"); " c. q3 |7 [# }0 K! x& N& N
getch();
8 ~. \9 H( m( F" u7 S3 zexit(1); /* terminate with an error code */
$ ^2 q) u( R; f; P6 y, C. W  {6 T} </FONT></P>0 p+ p) `1 M" W: y# F, b
<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 }! J5 i! V' A6 U4 i
midy = getmaxy() / 2; </FONT></P>8 ~/ I) e. P4 O
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ * X$ |6 ~0 B- e' {# A/ ?) o
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
  U2 I4 g# V( |3 A5 B: N/ z& b$ S- u<P><FONT color=#0000ff>/* display the information */
& R2 {% u$ d+ a) ^. Dsettextjustify(CENTER_TEXT, CENTER_TEXT); , |) `/ ?9 a* D: e- w
outtextxy(midx, midy, colstr); </FONT></P>6 ^8 t$ w7 x0 n! G% \; _; _
<P><FONT color=#0000ff>/* clean up */
& e8 W+ n  ~9 ggetch();
* g* m: q' p" q4 B" P( n8 sclosegraph(); 0 T6 y1 f7 k) J2 @. ]& ?
return 0; ; F4 {$ V2 @5 m+ g2 E$ m, X. `
} </FONT>8 B' q# e" |+ K: j/ [
& R- S9 m# \0 r+ Q6 b4 t1 L
" k, f2 K$ \8 F3 M: {, Q/ `" F
</P>
, S" s* @/ @; m7 s  n0 s" }<P><FONT color=#ff0000>函数名: getmaxx </FONT>
$ U# _1 O5 i* x功 能: 返回屏幕的最大x坐标
' Y8 V& e2 |* i+ C% k; ~用 法: int far getmaxx(void);
) V* E0 g) @7 H, |: [: c0 D; @程序例: </P>
# N" f! b2 S% L" H+ e6 Y<P><FONT color=#0000ff>#include <GRAPHICS.H>* |* b1 m" a( k5 Q
#include <STDLIB.H>
" f) v- K3 p* a/ G#include <STDIO.H>
' U6 k( i  F3 Q% Q# v9 X8 Z- K#include <CONIO.H></FONT></P>4 W4 j, J7 j9 U( Z: o9 P
<P><FONT color=#0000ff>int main(void)
+ V% R0 s) U* R1 |2 t; d( A0 }{ 8 P, n$ W! F3 R; P( b% H: n. C, H
/* request auto detection */
0 X) H9 ?8 X1 C4 [+ R( jint gdriver = DETECT, gmode, errorcode; . b( H8 q3 U! e; J! |6 z+ i) h
int midx, midy;
: I, `9 a$ x, v: ?9 c' Nchar xrange[80], yrange[80]; </FONT></P>
0 e; J1 z% D1 G<P><FONT color=#0000ff>/* initialize graphics and local variables */
, o! n2 R3 P+ O% uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ A1 p. {+ l+ J5 n; u( h6 w' C<P><FONT color=#0000ff>/* read result of initialization */ 1 B1 x8 R: U: y% L: K
errorcode = graphresult(); & y+ l7 a' J$ a8 |# X: `7 n
if (errorcode != grOk) /* an error occurred */ / r/ i. [$ b$ M
{
) N, ]! k8 t: D1 f% wprintf("Graphics error: %s\n", grapherrormsg(errorcode));
3 h3 n! u) M9 p; l: \printf("Press any key to halt:");
2 Q# V( A) Q; N  ^" t. _$ ]getch(); * d! {- V* `; R6 _$ K" E* j  A: Q
exit(1); /* terminate with an error code */ ! J8 _4 D: \' L5 u: c& q0 }9 Y
} </FONT></P>* x% t' ~: J" u- H4 T4 G3 f, _! S
<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 j+ W7 Z7 q4 O# R. i; V( zmidy = getmaxy() / 2; </FONT></P>/ d7 j0 h2 [$ r8 ~: ?
<P><FONT color=#0000ff>/* convert max resolution values into strings */ 5 r& C; m% F9 Q- A* D- L9 R. O0 V
sprintf(xrange, "X values range from 0..%d", getmaxx());
! a: b, [0 g7 x% usprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>; m& X6 _/ o! R, \
<P><FONT color=#0000ff>/* display the information */ & I7 m, o# C$ W& G9 {3 U
settextjustify(CENTER_TEXT, CENTER_TEXT); , m! V" D$ X& v6 J( `$ t; V$ Z
outtextxy(midx, midy, xrange);
. p2 h. X" L7 |" j7 Touttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
7 h% n* `% F9 l) y1 w<P><FONT color=#0000ff>/* clean up */
  q# Q0 H; o; T4 a- I* w2 Ogetch();
6 L8 l* A" v/ i4 u$ iclosegraph(); 5 {. a' t6 K9 R9 E: }, ?
return 0;
; I5 ?8 n: v& `% N$ J; E( z$ s}</FONT>   K! s! D0 ~/ c
9 o. |+ Q' G4 K0 I' B; M
</P>3 w6 P' H3 C0 B" a
<P><FONT color=#ff0000>函数名: getmaxy </FONT>$ M, c2 y  `* O/ C
功 能: 返回屏幕的最大y坐标 2 }" p  k& c  R8 Y
用 法: int far getmaxy(void);
3 G. T4 y+ w$ P0 s/ R程序例: </P>: v" O. h) t1 h" F/ x1 J# ?
<P><FONT color=#0000ff>#include <GRAPHICS.H>2 g" b7 W: I2 ~" |
#include <STDLIB.H>
1 ?* i. f, ~. j#include <STDIO.H>9 P9 B3 ^# S% j
#include <CONIO.H></FONT></P>1 l3 x0 X+ p# p8 n1 K$ U- X: E4 {
<P><FONT color=#0000ff>int main(void) * w& _3 L6 Z4 n) ~
{
! g9 J2 M% T3 [/* request auto detection */
# }, R" g4 c2 F6 [! O2 O6 N4 jint gdriver = DETECT, gmode, errorcode; + s8 c9 Z1 D' ~
int midx, midy; + P( b6 p0 E+ @5 G
char xrange[80], yrange[80]; </FONT></P>8 M! l$ h! I+ R7 k# J
<P><FONT color=#0000ff>/* initialize graphics and local variables */ / o2 E7 |8 \! P1 L: x
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% ?  M" o' N3 c5 p<P><FONT color=#0000ff>/* read result of initialization */
, _9 I, }/ R$ g6 T2 I# herrorcode = graphresult();
/ y( V) Y9 L" f$ mif (errorcode != grOk) /* an error occurred */ 2 {0 N" Q3 P; i) y) y1 l
{
% w6 D% B6 H1 Z; ~printf("Graphics error: %s\n", grapherrormsg(errorcode));
. x, v% U1 \8 T8 L$ N: v' [printf("Press any key to halt:");
% t- }0 A7 G* D5 l3 |8 ^" _6 ugetch();
4 e$ _9 D# ?9 ~0 yexit(1); /* terminate with an error code */
3 s" R3 b3 o2 R7 _( r( W} </FONT></P>
4 K% ^6 k" ~3 W<P><FONT color=#0000ff>midx = getmaxx() / 2; + i5 m0 {) l3 v, `7 O: m
midy = getmaxy() / 2; </FONT></P>
! J% r, c# ~+ L  u  Y/ B5 \8 P<P><FONT color=#0000ff>/* convert max resolution values into strings */ 1 J0 ?8 ~1 f& N  K5 X1 P" J' M
sprintf(xrange, "X values range from 0..%d", getmaxx());
: b: g4 u2 E- r2 csprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
9 }( S) j. f9 s. G<P><FONT color=#0000ff>/* display the information */
. n" k* Q: n7 C7 h7 x5 `settextjustify(CENTER_TEXT, CENTER_TEXT);
; w8 [9 j7 L  [3 m0 o6 y4 _8 w- s5 Uouttextxy(midx, midy, xrange);
8 K6 \/ F( I- R3 youttextxy(midx, midy+textheight("W"), yrange); </FONT></P>* g7 M4 q4 d: d$ p1 v
<P><FONT color=#0000ff>/* clean up */ / @0 c7 @) ~/ |6 b1 l% b* T
getch();
2 f+ J+ ~2 |) {; B9 ^+ U% V. iclosegraph();
  |! u  z1 w) |& wreturn 0; + Y8 S2 f) T. |# k
} </FONT>; p7 H$ @' O1 F6 N" T6 x3 E
</P>
8 ]$ D+ r; h4 s' z<P><FONT color=#ff0000>函数名: getmodename </FONT>+ G, _4 S/ I! ?( C
功 能: 返回含有指定图形模式名的字符串指针
8 m9 i3 @% v+ ?9 `# E2 J用 法: char *far getmodename(int mode_name);
2 U" \1 J# x6 I$ L4 B2 \程序例: </P>4 c& E; j' P+ G+ A' r
<P><FONT color=#0000ff>#include <GRAPHICS.H>' J/ q  L, o, T% ]" x8 B
#include <STDLIB.H>1 U* `! Z  e. w2 t  K" w
#include <STDIO.H>
) P( W9 i" d, |1 M: `#include <CONIO.H></FONT></P>- u% Y4 o6 k5 F, b% }) Q7 w1 X
<P><FONT color=#0000ff>int main(void) % [# G! w7 E/ n, x" a
{ 5 W4 g7 {" A' g+ @1 ?& ~# Y4 G
/* request autodetection */ 3 q0 r( r8 _: f% G5 i8 l
int gdriver = DETECT, gmode, errorcode;
' Q6 M$ p6 l' M& E9 r  Rint midx, midy, mode; ) G# l. A% r& H& s
char numname[80], modename[80]; </FONT></P>
$ ^& G. q$ [) l<P><FONT color=#0000ff>/* initialize graphics and local variables */ . P9 ~$ k+ {& q& p# K
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 `3 V2 X. ?5 o6 O+ s<P><FONT color=#0000ff>/* read result of initialization */ ! q# X7 t7 w7 d" b& \
errorcode = graphresult(); ! j: W+ G! }  q0 W/ [2 @
if (errorcode != grOk) /* an error occurred */
- {$ W: X6 Y  i{ 7 J& C. C& I1 l) Q: t& r. t2 r+ t4 @- u$ K
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * ?3 f) ?/ l9 m% u! t, h+ x2 l$ }, F
printf("Press any key to halt:");
5 i1 ~& k, V) |+ l* J0 s; Agetch(); 3 s$ C. ~% g' D4 z
exit(1); /* terminate with an error code */
5 E! }' M3 I: `/ G% g} </FONT></P>) ]  \- F9 j' o# o# _: K6 u; Y
<P><FONT color=#0000ff>midx = getmaxx() / 2;
* F, y( Q' ?1 f3 Y% c. z" v( smidy = getmaxy() / 2; </FONT></P>9 F! f% _: v! \# V, y
<P><FONT color=#0000ff>/* get mode number and name strings */
. b8 t* Y7 G# Y  x  P9 t$ gmode = getgraphmode();
5 ?$ U) _9 R" H" ~0 Z- P/ Fsprintf(numname, "%d is the current mode number.", mode);
3 z9 z. t" z; Rsprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>" J. ?$ |; V; c; L
<P><FONT color=#0000ff>/* display the information */
2 ?+ {% n9 h" I  f0 ^settextjustify(CENTER_TEXT, CENTER_TEXT);
9 ?$ M2 E6 q8 E; Touttextxy(midx, midy, numname); 7 l/ X! p$ S1 _. J& g8 D( E& F7 m6 S2 }
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>+ e8 ~3 X# A, V# b( F& ~
<P><FONT color=#0000ff>/* clean up */ # [! t' h8 V7 n  c& T+ t+ H
getch(); # G6 ?; F0 C  }. P/ O
closegraph(); - f0 N% i. e  j2 H/ q! O3 Z
return 0; 6 C$ j% _& V' W+ n; L0 M
} </FONT>
- ^! g0 y* {7 ^+ G
% T) p1 ?9 q; e/ y4 l</P>
# O0 N1 Z& s6 r! o8 {- z<P><FONT color=#ff0000>函数名: getmoderange</FONT>
1 [0 S1 p! C+ G功 能: 取给定图形驱动程序的模式范围 , ?( j+ W' \( x
用 法: void far getmoderange(int graphdriver, int far *lomode, - M4 v- {! s# z; b
int far *himode);
2 n. P5 w, t7 [+ S  v# s程序例: </P>/ t, ?% y$ y3 T" Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>) A3 L. @( ?! ]1 p& l1 T
#include <STDLIB.H>
) v% x5 n# {& R0 l6 p% ~( W3 b8 v#include <STDIO.H>/ }# b+ l$ c  E
#include <CONIO.H></FONT></P>
# t3 F' A, b2 J/ X! J8 u/ u. n<P><FONT color=#0000ff>int main(void)
3 x' F( V; Y2 A9 }, y, h+ o. z6 |{ ) t! M( w6 R4 k3 O
/* request auto detection */ / K/ g% _1 y" T% l  k
int gdriver = DETECT, gmode, errorcode;
4 Y# f5 o' N0 X" P. Tint midx, midy; ; B% m# W6 v% @. O+ q5 A" d
int low, high; . a/ ^% I: t* b# B8 D/ @( Y3 ], R/ D
char mrange[80]; </FONT></P>6 e3 b6 E5 k' z$ W  y# r, F
<P><FONT color=#0000ff>/* initialize graphics and local variables */
! {" x/ F( Z  B& ~3 U8 kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  ~. v1 l( A# w, t' e: ^4 I
<P><FONT color=#0000ff>/* read result of initialization */
& V3 m. s2 v7 d; f+ Y& @- Terrorcode = graphresult();
4 `  \, L- m! aif (errorcode != grOk) /* an error occurred */
% q% @6 K/ r$ Q8 j  M# n{
+ r6 q! J! |" N1 Bprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' w0 X$ h; j9 f  ?3 [) X" S4 wprintf("Press any key to halt:");
0 L1 v. q! K# |* @7 c, t1 v: L; \getch(); $ n* m5 Y, b/ r8 H
exit(1); /* terminate with an error code */
) d* `8 V( v6 M9 _5 N} </FONT></P>
" ]% o( c$ H1 h) T; V! @) t( ]& k! S<P><FONT color=#0000ff>midx = getmaxx() / 2; : A& |& L8 \! ?
midy = getmaxy() / 2; </FONT></P>
* X8 C' O. e' k<P><FONT color=#0000ff>/* get the mode range for this driver */ # o! o6 t, m% ~; i7 c
getmoderange(gdriver, &amp;low, &amp;high); </FONT></P>- x( d' T5 _9 w8 I6 ~$ N
<P><FONT color=#0000ff>/* convert mode range info. into strings */
( c  t0 p0 j  Y5 W6 }sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
1 H0 e& F' w' P, `, k! m% M  B8 G<P><FONT color=#0000ff>/* display the information */
& i- W6 W7 {4 s0 psettextjustify(CENTER_TEXT, CENTER_TEXT); . x1 f2 c: _6 d3 X" L  o
outtextxy(midx, midy, mrange); </FONT></P>0 j! p- `) ]8 O
<P><FONT color=#0000ff>/* clean up */
& i6 u& |1 l1 ?5 Ogetch();
+ a7 K- M! G& J8 O- v& F6 \closegraph();
9 S, M6 Y2 C- E# }  l$ Freturn 0; $ @! f/ Y! b' N9 F$ l4 f8 o0 R
}
/ j- V$ c0 K6 r5 v- p' u</FONT>1 B4 H  T; N! A1 B& ]! y& A
</P>3 v: N" _! M! S. ~& R7 D
<P><FONT color=#ff0000>函数名: getpalette </FONT>8 U/ [; N) e* A  [/ ~$ e6 _
功 能: 返回有关当前调色板的信息
  M& p% O$ d2 Y( i8 |2 ^用 法: void far getpalette(struct palettetype far *palette);
9 M6 ?) b! h% Y+ S5 }$ D程序例: </P>
% M* U; A! o5 `% `<P><FONT color=#0000ff>#include <GRAPHICS.H>
( |7 S8 m7 e" `" u8 Q#include <STDLIB.H>7 o0 r9 \: s' ?1 M( C
#include <STDIO.H>8 ]: n9 e$ L  h9 ]9 E% _
#include <CONIO.H></FONT></P>( n1 X, K5 F) N
<P><FONT color=#0000ff>int main(void)
) K) o1 V8 X. k: X* Q$ X* i{
) {! e; \7 ~4 z/* request auto detection */ # v' E& e/ X2 b  M& @4 f* U1 a& P/ E7 K
int gdriver = DETECT, gmode, errorcode;
' _; g3 d; I2 m- j9 L" f$ G1 r" qstruct palettetype pal; ' v; O3 V8 H; p$ G
char psize[80], pval[20]; ! ]# F& u8 R: S2 C0 Q& @
int i, ht; 1 T; }- E, P; ~) `
int y = 10; </FONT></P>6 r  C+ _4 M/ c+ i& I
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' H- v/ W' `2 t  Y' M# kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ |. q* @+ S" r( Z. ?, J<P><FONT color=#0000ff>/* read result of initialization */ / H+ \0 I4 N/ v& h, K) u- s+ X& x8 R
errorcode = graphresult();
3 g( H% t2 U4 b$ E+ ~7 w/* an error occurred */
% N# ^3 Y( t) ~9 n: kif (errorcode != grOk) 5 |' z1 W' S$ }, k
{ 4 D# Q; D% A; [  D; s2 C" n9 i
printf("Graphics error: %s\n",
9 m1 k, v1 {2 `* g) pgrapherrormsg(errorcode));
0 _+ m* x+ _. B9 y- L. Lprintf("Press any key to halt:");
' H9 p- ]. X/ o' fgetch();
  B( M$ q' M! X: r2 D9 N6 h1 H" E! W/* terminate with an error code */ 5 I- f4 j3 ^' u4 i
exit(1);
5 \- R+ P% H8 b  y, ]! b} </FONT></P>
+ ^6 G4 P2 P" `& K1 F<P><FONT color=#0000ff>/* grab a copy of the palette */
* B% \& p* |" _( k. H0 ]- i7 P7 }getpalette(&amp;pal); </FONT></P>
  V% m0 o! C, E7 |3 a$ B<P><FONT color=#0000ff>/* convert palette info. into strings */
" H: X9 F0 U/ |9 U; t: l8 Isprintf(psize, "The palette has %d \ 0 M: W6 T& N" L  s
modifiable entries.", pal.size); </FONT></P>, u: d0 S) B) _. J* B7 Y
<P><FONT color=#0000ff>/* display the information */ % Y6 h  _5 {, J6 l7 p1 r# l
outtextxy(0, y, psize);
; [' m; `5 f9 h6 @5 B1 hif (pal.size != 0) % x* u* i# R9 Z3 O* N5 ?3 x
{ . @0 N! E; Q" I$ k# G; K. }
ht = textheight("W");
9 \7 S2 l- S2 |y += 2*ht; $ _+ o$ i  I; T; X: _
outtextxy(0, y, "Here are the current \ - q- E4 g( ^# _& H0 i0 S
values:");
: V& P8 ]: k. j. ?2 }y += 2*ht; - o3 F3 S+ b1 Y1 d( V
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
: M# e0 y" v" _/ c2 Ssprintf(pval, + l  S% f! _. `  m9 t, M( n( w
"palette[%02d]: 0x%02X", i, ( R; e/ O+ {- Y$ B# w
pal.colors);
$ }4 b+ z7 |3 aouttextxy(0, y, pval);
  `, c6 Z& K7 m0 u} 0 K4 Y: @1 J( o- S& o
} </FONT></P>9 b' Y4 ~/ h( s$ g, f
<P><FONT color=#0000ff>/* clean up */
. R& T9 \: ^* W5 X/ cgetch(); 2 Y& a  z1 L* P6 y
closegraph(); </FONT>2 h; q: j- r8 n/ D7 q
<FONT color=#0000ff>return 0; ( ?7 |* X" {& `% ?/ d( b, U
} & U5 m# W& P9 D
</FONT></P>
' E* U. r& {, T6 |1 |6 D) R9 ^, C<P><FONT color=#ff0000>函数名: getpass </FONT>
( s- S$ R& d4 Z3 d- ]功 能: 读一个口令 , d) b3 E4 @: E4 ~8 s3 k
用 法: char *getpass(char *prompt); : G* u( a; w; {" `2 ?
程序例: </P>
8 G7 i; b9 j; D2 W- d<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>! r' ~  q/ i0 A8 y
<P><FONT color=#0000ff>int main(void) " ^7 V( @+ c  _' |  [0 U5 g
{
. j8 V$ c) e9 Y/ Z+ d7 Y. mchar *password; </FONT></P>: K* F+ x9 Q0 n
<P><FONT color=#0000ff>password = getpass("Input a password:"); 3 X& s4 A0 X; f/ I- L) k
cprintf("The password is: %s\r\n",
; Q! ]5 [& y" {5 hpassword); " r) Y! E8 R% t  Q( a: Q
return 0;
0 @& l5 K+ s2 G6 S/ D8 t3 q" @- t}
6 m) i, U" p2 L" U& }</FONT>
; c5 C7 i, `8 {3 D/ W
! O' k; f1 Q- |4 M# u</P>6 ?* m" J7 q+ X  x' _4 N
<P><FONT color=#ff0000>函数名: getpixel </FONT>
2 t4 I) W" d" M! x功 能: 取得指定像素的颜色
/ m! v! Q# ^% z& Z2 h, {, ^用 法: int far getpixel(int x, int y);
) C/ l( A/ O5 l8 n, Q程序例: </P>) n- w! v+ M8 f  \% d; l! q3 |
<P><FONT color=#0000ff>#include <GRAPHICS.H>. M# q$ q! E# Z  ]$ a5 G
#include <STDLIB.H>$ k! j, D) x( ]. v. J9 b: l
#include <STDIO.H>1 n, G- A( j' y5 Z3 R2 a. P9 z
#include <CONIO.H>
9 T7 D& I/ ]- `3 w#include <DOS.H></FONT></P>8 k7 |* t" P/ {/ ^: V9 Q# `+ e
<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 . u! J. I( g% J. F) a; w$ z
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>) S, I9 [/ \- K; M( _
<P><FONT color=#0000ff>int main(void)
* u3 d1 O6 Q- q, g{ 5 s) E& }- @* q/ k
/* request auto detection */ & [/ j  _) }" @! [
int gdriver = DETECT, gmode, errorcode; 3 ^, V. X, R& q5 a, e: E4 b
int i, x, y, color, maxx, maxy,
! G" M* D! H0 \/ n3 U: Amaxcolor, seed; </FONT></P>3 L1 I7 O  f, O: r" E
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! g! u6 e+ l' Y) [: q# T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' N6 a; Q9 [! Q( ]: B, w<P><FONT color=#0000ff>/* read result of initialization */
3 H/ c* n* T) |+ M1 r( W  }$ gerrorcode = graphresult();
4 ?2 G3 m  o' S& K/ N/* an error occurred */
) ?( E) [9 ^# y# k+ x- Vif (errorcode != grOk) " f- _  U1 c5 y( B4 @3 `6 Z4 {
{ 6 Y# u1 A- X. m" N0 X
printf("Graphics error: %s\n",
0 K* Z8 \4 c) k1 b0 i  y" Qgrapherrormsg(errorcode));
, t4 d4 V1 C  l3 gprintf("Press any key to halt:");
2 t. W7 T' G" t9 e" ^" {getch();
1 T: a( V6 @+ O! t" }; L/* terminate with an error code */ 1 d8 b4 O+ h9 z7 ]
exit(1);
' K7 n6 [6 G  Q} </FONT></P>
9 G) g: w0 M6 F: V- @0 N" N<P><FONT color=#0000ff>maxx = getmaxx() + 1; 7 u7 T3 c! Q; ^7 R, Y
maxy = getmaxy() + 1; ) E7 c$ R9 K. x8 x# Y
maxcolor = getmaxcolor() + 1; </FONT></P>
7 f% I& E  x0 r4 _# _9 o' s+ q+ r<P><FONT color=#0000ff>while (!kbhit()) . t/ {  N9 w! p$ v) r
{
. @# [" {' G% _  P; \, a) ~/* seed the random number generator */ 1 R# ]# R! h' _* `) C* \3 {: Y7 q; B, y
seed = random(32767); 8 ]7 C$ g7 s! T( D8 O2 t4 Z; Q2 f+ W
srand(seed); ! x- H9 X  h+ T
for (i=0; i<PIXEL_COUNT; <br i++)> {
" q: X! S& O& ]3 Z. N- q9 v# {x = random(maxx); / F% s0 ^! F" j1 v6 ]' \( ]( L
y = random(maxy);
6 |/ A1 O3 Q! rcolor = random(maxcolor); / {# W  y* |2 R: k+ r( D& @8 m
putpixel(x, y, color); $ a! l; x. N: X
} </FONT></P>
' G1 b& {, @' M' _<P><FONT color=#0000ff>delay(DELAY_TIME);
% Z5 H6 B6 u) K1 F# h4 gsrand(seed);
5 S! p0 S: J- |9 a3 `for (i=0; i<PIXEL_COUNT; <br i++)> {
$ X# c2 q) H6 jx = random(maxx);
, p0 M2 d, F% M7 m' Dy = random(maxy);
8 y# `) n9 P( q0 p- ocolor = random(maxcolor); . X3 D. ^& H! B  i  ~
if (color == getpixel)</FONT> </P>
# i0 Q0 @% [( y8 }$ }  I7 [- s<P><FONT color=#ff0000>函数名: gets</FONT>
7 y9 z  k. I, u! }- y功 能: 从流中取一字符串
7 x, [9 m1 r8 F9 X用 法: char *gets(char *string); $ g7 I1 n3 K  O- N( S: C& N
程序例: </P>
* R8 p2 X8 `2 ^/ l<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>7 m- E3 c4 P, |& I+ m6 `! ~4 V
<P><FONT color=#0000ff>int main(void) 9 x+ K6 k' f' s& z, Q
{ + b, j4 H7 e! `+ ?9 I5 J7 ]' L  U
char string[80]; </FONT></P>6 J  y$ t! y4 e3 e
<P><FONT color=#0000ff>printf("Input a string:");
: ~7 e9 P1 n4 @' {( {- w+ l: Mgets(string);
# w3 i3 y  A+ f! _9 ?# d0 N! k! Pprintf("The string input was: %s\n",
: x/ [1 x' H0 z: ?string); & v% r+ ~1 [4 u3 H: h) A
return 0; 9 c# F8 s# w3 y/ I6 J, u6 F3 X
} 2 r  I1 O! N" j& G

$ y! h! d+ A( b</FONT></P>
, G7 N" l- B& N7 @6 _' l<P><FONT color=#ff0000>函数名: gettext </FONT>
3 u- z  u( T, V功 能: 将文本方式屏幕上的文本拷贝到存储区
3 P9 V& w1 H  C# q$ }+ ~$ M3 \& z用 法: int gettext(int left, int top, int right, int bottom, void *destin);
% x/ y& x: c  T" J程序例: </P>
5 c- ]( V% J9 A3 x* [0 a. I<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
- F- M) Y, a5 t3 @1 P<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>! s: z( N1 l1 \0 a' W& d  R
<P><FONT color=#0000ff>int main(void)
  v2 E4 E$ B7 w# z$ L  _{
# ]  s" z5 {) F# Jint i;
$ s7 m/ v1 P) y* m5 j+ Rclrscr();
6 T% j/ q& K% @8 H: U( ofor (i = 0; i &lt;= 20; i++)
. ~  t# Q; d& s# kcprintf("Line #%d\r\n", i);
* h* h3 t8 b+ T# \; Ogettext(1, 1, 80, 25, buffer);
0 M, j3 a5 [3 F6 |, r+ Jgotoxy(1, 25); 4 T$ r6 q1 |1 s- m5 z
cprintf("Press any key to clear screen...");
5 q/ c6 I8 X2 @getch();
5 F& j3 b: z* H" kclrscr(); - B+ D' z6 [# G5 e  D
gotoxy(1, 25); ! y! v, f5 J$ R& ^; |
cprintf("Press any key to restore screen..."); + U. y* X5 k  ]" ~! y
getch();
" j  f8 q4 b8 c, g; ~' Dputtext(1, 1, 80, 25, buffer); / S8 p4 t% k8 |' d
gotoxy(1, 25);   @% w" E5 E/ F% t. c
cprintf("Press any key to quit...");
2 I  Q' A* m( T$ C5 E' C0 @. Y) Lgetch(); , [& j+ l/ C2 r, Y) G. ^3 V; Z
return 0; ) C7 m# R& g1 U. v7 q' B
} 6 r2 B: q  n. Z" d% F9 m$ U
</FONT>
+ J' }# g+ q" t, \</P>- `; ^6 U& _4 }- [. P' I! ^% B
<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
/ z! h9 I5 m9 t1 j; w9 Q功 能: 取得文本模式的显示信息
9 {. ^3 {7 \) }, [: O! \# n用 法: void gettextinfo(struct text_info *inforec); + m' q4 B) o. F8 J+ O2 k+ Q: [
程序例: </P>
& y5 B/ K# E) P, _<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>. s. O$ t* |; B
<P><FONT color=#0000ff>int main(void)
( o8 ~$ L: L4 o5 ?{ 2 `( r( p# Q- I1 Z# z
struct text_info ti; ( V! l0 D# w! x) t  t, ?0 k  Y/ J" p
gettextinfo(&amp;ti); 0 Z: l( Y1 |$ ]3 M* [% |! ~
cprintf("window left %2d\r\n",ti.winleft);
" h% Y* a. z6 [1 D8 W2 ccprintf("window top %2d\r\n",ti.wintop);
$ Y" d; j( v# z9 J8 y' M  xcprintf("window right %2d\r\n",ti.winright);
; O" \" g9 r0 Z2 S1 {( l! e* ~cprintf("window bottom %2d\r\n",ti.winbottom); 0 l, I/ z* V" t$ b; k  z
cprintf("attribute %2d\r\n",ti.attribute); + `/ o2 F5 d/ U) U
cprintf("normal attribute %2d\r\n",ti.normattr);
) T6 r$ W" k3 }- V' `! _3 wcprintf("current mode %2d\r\n",ti.currmode);
; r$ t; k* A8 Ycprintf("screen height %2d\r\n",ti.screenheight); 1 z$ J4 M: l: ?8 H- D
cprintf("screen width %2d\r\n",ti.screenwidth);
/ [) D! N: m3 K. {, @" K9 v/ j! jcprintf("current x %2d\r\n",ti.curx); ; U: g% V# m, o5 G/ [) B
cprintf("current y %2d\r\n",ti.cury); 9 h- k7 H$ w" q
return 0;
1 k- B6 @* {& w} - N4 v. o" z/ o7 D* e  i
</FONT>
! ?# J+ Z" |/ I</P>9 V* |7 D5 `  O/ A% u4 Z) u# m
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
1 L( q3 u  P& z9 {7 u功 能: 返回有关当前图形文本字体的信息
" U8 q- u" G6 M* _( Y7 S2 N  C# t用 法: void far gettextsettings(struct textsettingstype far *textinfo); 0 R7 F( S. g+ T0 i  G
程序例: </P>
6 X" z, t( b* n& u3 f0 x! I<P>#include <GRAPHICS.H><FONT color=#0000ff>6 k  ^1 b& t5 T" v: J7 \, z
#include <STDLIB.H>- v4 d3 y' k/ X) O9 J
#include <STDIO.H>
5 m5 h  m1 |- e#include <CONIO.H></FONT></P>
8 X+ B" _* W. t$ z( i$ t<P><FONT color=#0000ff>/* the names of the fonts supported */ " w6 V4 C; I, L0 C8 u. O
char *font[] = { "DEFAULT_FONT", : L$ G2 F1 y5 e. W+ A# Z
"TRIPLEX_FONT",
* H6 }9 L( O3 X( {7 {# x"SMALL_FONT",
2 y' J3 P  Q4 u"SANS_SERIF_FONT", 6 E" K( j+ _' A) [4 [
"GOTHIC_FONT"
% h- z+ u0 l$ g2 I1 |# ~6 u}; </FONT></P>
( _, I# o) M# E! x<P><FONT color=#0000ff>/* the names of the text directions supported */ * u) Q* c$ Y, l& o, t" O$ e  L; ~
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>5 I, ]; d2 O' R2 }- R$ E5 q! p8 S
<P><FONT color=#0000ff>/* horizontal text justifications supported */ / X6 u0 f+ n3 f7 z8 e! z9 k! L
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
9 I1 z# g8 W" ^. b" O7 f3 h( I( y, `# k5 Z<P><FONT color=#0000ff>/* vertical text justifications supported */
9 m% Z9 A( a" L, ]8 |! wchar *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>6 Y' |, X7 z3 `  J3 w/ X
<P><FONT color=#0000ff>int main(void) $ c& j3 q& N) O8 P* K# R9 f
{
8 Q+ z( v& \$ O* }/* request auto detection */ 2 Q) s0 I( E/ X5 p% [6 P. T
int gdriver = DETECT, gmode, errorcode;
: e7 M  W# ~3 D. }& T4 ]" n. Ostruct textsettingstype textinfo;
$ t! D6 e8 k. R, mint midx, midy, ht;
0 \0 ]( l+ F' V* ]char fontstr[80], dirstr[80], sizestr[80];
/ w! a/ F- v3 b! H7 c! Y1 n1 Jchar hjuststr[80], vjuststr[80]; </FONT></P>4 Y, h* S; q7 n! W( @1 j
<P><FONT color=#0000ff>/* initialize graphics and local variables */
. I' {, R! U  W1 Yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 e& w; i1 l+ X) T% Y<P><FONT color=#0000ff>/* read result of initialization */
# ^: k9 H' z2 S. S2 Lerrorcode = graphresult();
9 c$ l0 I5 S8 i- ]! Dif (errorcode != grOk) /* an error occurred */ . `/ P, F) h; ]; k
{
* @( \) z/ y" Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! z' ~5 O! f5 r" n2 k  z6 Cprintf("Press any key to halt:");
; w+ V% ~" B, ^# d' J. Q0 _getch(); ' j+ S: a, p* l  k
exit(1); /* terminate with an error code */
& e) i6 h5 ]6 R& [$ K$ n1 t4 x# ]} </FONT></P>
; e: W8 [! v; i: s. o1 r<P><FONT color=#0000ff>midx = getmaxx() / 2;
( a  O7 u* P+ @/ q9 J2 kmidy = getmaxy() / 2; </FONT></P>
+ s! q% A% n9 ^, l: g<P><FONT color=#0000ff>/* get information about current text settings */ 4 b8 k( x+ H: H% a, Y' _! u
gettextsettings(&amp;textinfo); </FONT></P>
* Z1 b# K# {/ ^( l0 j* ?<P><FONT color=#0000ff>/* convert text information into strings */ * i% t- d2 I: {# j+ A3 @& |
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); # G' u. v. z2 p* b2 }$ p( T' ~
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
) y! _: g- C1 _  J) e( fsprintf(sizestr, "%d is the text size.", textinfo.charsize); 5 u/ j0 a! w: _
sprintf(hjuststr, "%s is the horizontal justification.", , M# j! V6 g2 N' j3 e( F
hjust[textinfo.horiz]); 8 @; a7 m" D$ a  Y* y6 A  f0 M
sprintf(vjuststr, "%s is the vertical justification.",
4 q) r& r9 A' P4 z6 D6 ]) ivjust[textinfo.vert]); </FONT></P>
9 L2 I6 l( B! J+ V# P3 J<P><FONT color=#0000ff>/* display the information */ 8 |3 y7 V/ U, {0 X: h8 G
ht = textheight("W"); # K, j) n4 @! Q" n
settextjustify(CENTER_TEXT, CENTER_TEXT);
+ O! S! ~) B0 y; z% Mouttextxy(midx, midy, fontstr);
  l4 i* n7 \& l2 B3 Iouttextxy(midx, midy+2*ht, dirstr);
* F0 X$ L: z6 C$ G: Y4 ?+ ~) ]0 souttextxy(midx, midy+4*ht, sizestr); ( T6 B  r. w, y/ f4 y& z( U
outtextxy(midx, midy+6*ht, hjuststr); * c! Z2 p, T. y1 Z* K' B& q
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
5 I) Z* c1 n0 h% c- k% z<P><FONT color=#0000ff>/* clean up */ ' Y( U+ _, @) f9 J, U4 A
getch(); # m) f$ O; w: A! F9 y
closegraph(); & s* r: C; j& q+ A' E
return 0; 9 Z* d+ q4 r$ v. X
} </FONT>
. s. d% C+ x+ @/ H2 s8 t: M+ A</P>
: j9 d& t8 Y, v" w& x1 i<P><FONT color=#ff0000>函数名: gettime </FONT>  m( g# I, W6 I/ A
功 能: 取得系统时间
3 |, r8 W% v( D% t, {# I3 y用 法: void gettime(struct time *timep); 9 S( M) m$ K2 N$ A. W2 G% h1 ?4 W
程序例: </P>
- r! c* I0 W" s) X<P><FONT color=#0000ff>#include <STDIO.H>! P1 t) |. v0 f, L  l% Q' c4 d
#include <DOS.H></FONT></P>. n+ p! F/ X+ c+ i7 k7 w& y9 L. @
<P><FONT color=#0000ff>int main(void)
3 n2 ?6 i1 P5 C, p! ]. U$ u5 ]) Q{ / t1 Y- l3 Q' C
struct time t; </FONT></P>* x" t. ?8 m/ p' y0 j( ~; B
<P><FONT color=#0000ff>gettime(&amp;t);
' z9 L& [# G  j: a1 R0 C+ Qprintf("The current time is: %2d:%02d:%02d.%02d\n", , e' w% \- m+ X( E$ P% X) Q8 d4 L
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
0 n+ `0 Z: H* U7 i& }/ M, O# O' sreturn 0;
0 T/ J0 ?. g" _. F) l9 E}
$ J; O1 h1 O9 I1 X2 G) _( I7 z: l/ A' y7 ]; x# N
</FONT>
" Q) r% p. p/ J8 b</P>
0 [; E8 Q9 }, t1 j) r' l; a+ @8 C* g<P><FONT color=#ff0000>函数名: getvect </FONT>+ c  N! l+ t6 i9 D7 z) `
功 能: 取得中断向量入口
, W8 w0 y, P3 k& l& N7 L用 法: void interrupt(*getvect(int intr_num));
- ?% `1 W& z# S7 W: H程序例: </P>! P! U" |. a; ^+ v* M% ^) ^; f0 e% n
<P><FONT color=#0000ff>#include <STDIO.H>
6 f- W$ {/ B" s8 h2 N% u* y- v#include <DOS.H></FONT></P>& a  {+ P  P, Z  \3 l
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
2 W; H+ y* K+ L; L% P<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ * }5 W3 \" E. n$ p4 k! K
int looping = 1; </FONT></P>
& `8 G) ~* a4 i: e6 u. ~5 i- u<P><FONT color=#0000ff>int main(void)
+ P& x1 u# |* S: x' R0 C{
' _8 M& S( A. t  kputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>/ m/ v+ Q6 @! q6 O
<P><FONT color=#0000ff>/* save the old interrupt */ # b  i7 k# z( L9 m( s
oldfunc = getvect(5); </FONT></P>1 V$ i) A; h2 z7 `
<P><FONT color=#0000ff>/* install interrupt handler */
( h1 O3 C/ z, i& nsetvect(5,get_out); </FONT></P>
* T+ \3 J; R0 ~<P><FONT color=#0000ff>/* do nothing */
) E/ e! k& ~1 x4 @2 R% ~# Awhile (looping); </FONT></P>
1 v- v. f8 K8 q3 w& t<P><FONT color=#0000ff>/* restore to original interrupt routine */ 6 B9 O* u8 M% w3 p8 {
setvect(5,oldfunc); </FONT></P>7 K# K: r- O" r
<P><FONT color=#0000ff>puts("Success"); + d  @2 u2 D+ |9 i
return 0;
& x5 P6 O) j; C4 f" \& \}
0 e9 r/ o. \6 O* W: O7 \" q/ G1 _void interrupt get_out()
5 F2 l7 q8 a/ Z* D' Y9 ^# J{
2 _$ A6 [$ d2 _looping = 0; /* change global variable to get out of loop */ 2 S, p) L% e3 m6 N6 _  X) ?  l
}
! P) V4 Z0 p# r</FONT>
  g$ y# e3 j( Q, m1 z3 M; O/ U</P>0 M2 L1 A( ~5 ^+ A% p( m
<P><FONT color=#ff0000>函数名: getverify </FONT>
$ D" Y0 {5 f) B功 能: 返回DOS校验标志状态 1 w0 Z* N3 t, U1 |
用 法: int getverify(void); ; }1 d+ ^. R2 {! \) U6 Y- @/ q
程序例: </P>
, o1 N: I* x6 a4 R! L( V<P><FONT color=#0000ff>#include <STDIO.H>
9 P$ p9 m1 W+ p% G0 |% V$ P( p1 ~#include <DOS.H></FONT></P>; b% E* q8 _8 d) z
<P><FONT color=#0000ff>int main(void)
6 O* _1 P6 t, {{ . }5 J: \! _, F
if (getverify())
; Y! G8 k: n+ U1 A# Pprintf("DOS verify flag is on\n");
0 @  i+ e  ]" Y5 \$ [' }+ melse 5 R. f3 m) H' H0 b9 I. a! p, y6 p
printf("DOS verify flag is off\n");
8 |3 z# G' @6 K1 p& Mreturn 0; : d8 C- H% e4 M" j/ t4 l
}
8 c+ X4 y0 B# z0 J" w1 y</FONT></P>; H* d! h- |0 o/ a1 C
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>* u& ]' h3 T2 v$ A9 T- e/ G
功 能: 返回有关当前视区的信息
2 Q: k9 M- w& Q& U用 法: void far getviewsettings(struct viewporttype far *viewport);
& u( F1 M( T% K/ Q5 a. u程序例: </P>
5 a* K$ ^! h: c. C* V( z* ~# \; _<P><FONT color=#0000ff>#include <GRAPHICS.H>3 J: L: X/ o- a' w7 b, b7 a1 _- B
#include <STDLIB.H>* Y3 o4 }* h7 c
#include <STDIO.H>
% ]+ b! j8 w- F( @) @7 I0 h#include <CONIO.H></FONT></P>: w# d- D& P& t0 i  w
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
1 G1 J- B. \  x, E. G/ r<P><FONT color=#0000ff>int main(void)
% a6 g$ V; f$ {{ ; v' Z" r# K& ?  Y& w
/* request auto detection */ - L9 a9 R/ x% Y
int gdriver = DETECT, gmode, errorcode;
: @" }. }9 t, A9 fstruct viewporttype viewinfo; 5 A3 o+ i; u( m1 |3 s9 T
int midx, midy, ht;
' d- _4 x( i" q; H1 Achar topstr[80], botstr[80], clipstr[80]; </FONT></P># b( ]  c0 x, A2 i
<P><FONT color=#0000ff>/* initialize graphics and local variables */
: V! T/ ^4 K9 H- ?$ tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) J( D6 J7 L; F
<P><FONT color=#0000ff>/* read result of initialization */
4 h; x/ P5 `; C8 Uerrorcode = graphresult(); - u) _" B- U( A2 y1 a" K+ X/ w7 n
if (errorcode != grOk) /* an error occurred */ % w6 t2 g+ T% a, k, D. o  P
{
5 s. ?5 {! z7 x( V5 P; Kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! U3 O/ x& K$ W; C: gprintf("Press any key to halt:");
; f( h$ ~. `9 ~' b5 o* G  Mgetch();
0 O+ o' W5 h( d! H6 F, g: Aexit(1); /* terminate with an error code */
9 O- [. q0 |, Z* x' Z! k7 u, U. Y} </FONT></P>
: o+ d* E' G3 p<P><FONT color=#0000ff>midx = getmaxx() / 2; * M! z& _+ P3 P6 _
midy = getmaxy() / 2; </FONT></P>
6 d  E) b/ z2 \<P><FONT color=#0000ff>/* get information about current viewport */
; r: q4 q" o8 O/ t$ F2 jgetviewsettings(&amp;viewinfo); </FONT></P>& `2 \3 C5 U% ]- ~
<P><FONT color=#0000ff>/* convert text information into strings */
7 r: [: m9 q6 I- ssprintf(topstr, "(%d, %d) is the upper left viewport corner.",
1 h+ o# t. o: T% f4 Zviewinfo.left, viewinfo.top); ) C+ [8 L/ U( E
sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
2 `# N- J0 J3 L. L5 U" \/ z6 W9 iviewinfo.right, viewinfo.bottom);
( ]) E; w- \; C9 ]  U+ n5 |sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>) j& I+ ?) a( D1 {1 o5 r: V
<P><FONT color=#0000ff>/* display the information */ # o7 Z2 v6 a: `$ y
settextjustify(CENTER_TEXT, CENTER_TEXT); 2 I" J5 S" A2 r$ V. k
ht = textheight("W");
1 g6 X$ Y( v9 a4 T  C& @outtextxy(midx, midy, topstr);
5 C' O* \/ z  c, l# ~outtextxy(midx, midy+2*ht, botstr); & i# O& Z8 N6 z7 X/ Q
outtextxy(midx, midy+4*ht, clipstr); </FONT></P># l+ U8 b+ G7 q- r, y& n) {& j
<P><FONT color=#0000ff>/* clean up */
) a. O3 M* M! Wgetch(); 1 u2 |5 k# H! z# O
closegraph(); ) e  ~1 ?4 k  D$ I0 T
return 0; ( I8 I; P( k, z. {' f& V1 A
} </FONT>! k/ B: \; R1 Y+ h8 J: w* m* p
$ ^3 B$ L6 G+ q5 j
</P>
% |) n9 H3 v1 w' k6 R<P><FONT color=#ff0000>函数名: getw </FONT>
# r1 s1 E5 m$ k" h1 A5 N功 能: 从流中取一整数 8 ^/ m4 z, n" ~8 L
用 法: int getw(FILE *strem); 7 n4 G$ s: C6 Z, r2 x% `
程序例: </P>
( z* y/ y/ Z" y2 }9 `  H<P><FONT color=#0000ff>#include <STDIO.H>7 N  l5 c7 v# N8 j4 G
#include <STDLIB.H></FONT></P>
& l/ {& x2 @( R% _' Z<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
  i5 J4 {9 H% y6 s$ Q' _<P><FONT color=#0000ff>int main(void)
/ d# E3 T) f9 I. m" z( M& J4 Q{ - I& l0 X( M8 }: ~* L2 q% D
FILE *fp; 8 m$ j: F' @1 @% z1 C
int word; </FONT></P>
1 v5 w: [  U. D; O2 e<P><FONT color=#0000ff>/* place the word in a file */
/ B. p' U5 }) c; L$ k) l4 bfp = fopen(FNAME, "wb");
0 ]3 \1 A- K; r( h: g! ?if (fp == NULL)
* e& r# x+ m$ Y5 g5 Q5 P{ & N) K7 s! k" {7 Z) y+ q  V# A
printf("Error opening file %s\n", FNAME); , A8 Y7 e) L  o/ W' y
exit(1); / r% y6 d( p  M  D5 @+ _
} </FONT></P>
4 q( ~; l" @/ D<P><FONT color=#0000ff>word = 94;
( ^* V, c: n& B5 nputw(word,fp);
  q$ N2 F$ b' Q0 ]+ b& e3 aif (ferror(fp))
) h- W5 ~/ i! M+ O& Uprintf("Error writing to file\n");
2 {) v/ X5 k! P- ~& lelse
; Q* v% g6 b. g$ H( O& yprintf("Successful write\n"); / E- l4 Z% R- o* }4 {
fclose(fp); </FONT></P>& b, Y/ L; e0 U  Y, u; o7 D+ S0 O
<P><FONT color=#0000ff>/* reopen the file */
8 X3 }& H" Q- Y2 Rfp = fopen(FNAME, "rb");
- ?/ S: I' r' H" X8 R$ o& iif (fp == NULL) ; G/ X$ ]: |0 v5 G" C
{
% C: \' j/ p- gprintf("Error opening file %s\n", FNAME);
& G7 f4 L% T) c# Q5 v0 i3 gexit(1); ! u8 G' S( T" J. j6 G# N* h
} </FONT></P>
& D3 C6 \9 P& K& T8 A8 B<P><FONT color=#0000ff>/* extract the word */
1 t, E% M+ y, f0 ~) H1 Lword = getw(fp);
4 c: C; U0 x7 sif (ferror(fp))
$ y7 Y6 |* p% F, Mprintf("Error reading file\n"); * e1 g/ }9 v& _0 O$ n. R7 |8 q
else : D( w5 S) X6 J' i' d) c
printf("Successful read: word = %d\n", word); </FONT></P>& I6 t, I8 a& ^; a+ }
<P><FONT color=#0000ff>/* clean up */
" v' D! H0 d9 @fclose(fp);
" \! ~+ `4 o3 _unlink(FNAME); </FONT></P>
& L+ p3 j+ n  w& z2 {4 h<P><FONT color=#0000ff>return 0;   E% {/ p1 b; \4 y( \( M5 u, N
} </FONT># N0 D* _: s! D! B# F. H$ K* B

4 Y) v# n( p+ A/ h
, }$ y1 t( n6 m; E</P>
  T) @6 i3 ?- U<P><FONT color=#ff0000>函数名: getx </FONT>0 _; Z8 H9 q6 T. T9 o0 `) f* H4 c
功 能: 返回当前图形位置的x坐标
/ g6 y& o! \9 f% n) a' f用 法: int far getx(void);
0 @6 |3 d) `  e) O+ ^程序例: </P>1 E1 k9 G9 }5 \( _6 X. }$ x
<P>#include <GRAPHICS.H><FONT color=#0000ff>
! y$ l/ y* w9 C) F) `#include <STDLIB.H>
9 o  d# J" r" v$ n8 a' P/ c#include <STDIO.H>
' k3 @( p6 s5 j( k# q% u" o#include <CONIO.H></FONT></P>+ L( f8 A" n9 T  {$ r% v! J1 H
<P><FONT color=#0000ff>int main(void) * h: A! A, w, p& y0 L- R7 d
{
4 F7 x: z3 L9 Y) m8 y# C8 ]/* request auto detection */
* [8 H$ _9 p) Q: P6 d" u/ K0 qint gdriver = DETECT, gmode, errorcode;
% e9 S; T! D8 K- b# r: |char msg[80]; </FONT></P>
5 t" o9 ~  e2 S9 I7 v<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 g$ E" W8 W1 ]& Z7 d( a2 e
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 a) N+ h# Y$ h7 ^- [8 @6 k
<P><FONT color=#0000ff>/* read result of initialization */
3 [/ T1 M+ O. f) G( C+ }, v8 nerrorcode = graphresult(); : B  x- g2 V  `3 {# Y+ S) Z$ H  `3 ~7 N% _
if (errorcode != grOk) /* an error occurred */ % m& c; S! m: w, t
{ & {  K0 N* l: O( N/ e" y7 E' i' T2 f
printf("Graphics error: %s\n", grapherrormsg(errorcode)); , _5 \& ]  O' E9 h2 r) k
printf("Press any key to halt:"); 4 P4 M' X$ T( d, w* K" t( ^* U
getch(); 0 p" C2 _5 V! b" H! \
exit(1); /* terminate with an error code */ ; _5 c! d# d# Z# \6 O
} </FONT></P>/ u8 e* k0 L' r0 f
<P><FONT color=#0000ff>/* move to the screen center point */ 1 I4 |6 Y+ C$ y! y) s9 f5 ]# m6 P% O
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>6 k* D! O6 a  y
<P><FONT color=#0000ff>/* create a message string */ ; O* U4 h. W; o
sprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>4 f  g& \; |, o
<P><FONT color=#0000ff>/* display the message */ - M1 H! c6 i$ ~
outtext(msg); </FONT></P>$ Z2 v* q- `3 {& Q3 i
<P><FONT color=#0000ff>/* clean up */ ' Z" e$ ~( b2 O9 X5 W
getch();
0 S3 d( {7 R: {: P, Cclosegraph();
2 \2 E3 |2 J7 U/ K) A0 ^return 0; 3 O9 X1 s! p4 x# f0 i+ R8 `9 n9 t
} </FONT>
) G+ |0 m- t) G5 a" e$ [
' ]( F# o5 B$ C% _( r/ O5 L# l: w</P>- x. y' ^  i- F' ^; r# f
<P><FONT color=#ff0000>函数名: gety </FONT>1 t- B5 c$ [8 S4 |& @
功 能: 返回当前图形位置的y坐标
# T; x) b, [9 C' x7 P用 法: int far gety(void);
* \( D3 X5 \9 e; L+ Z( u% n! E# g9 x程序例: </P>0 q/ x9 B* f( {; O6 r
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 G" f0 p  `% E+ h( I% t
#include <STDLIB.H>$ d3 l7 ?9 C4 `/ z8 U# }
#include <STDIO.H>* H3 H" m" O/ ~( F5 \0 T
#include <CONIO.H></FONT></P>6 y9 c, R% m0 Z& b- I9 j- u9 x* \& b
<P><FONT color=#0000ff>int main(void)
+ w$ M& j7 a' H1 D{
- I9 G3 j  f9 ]/* request auto detection */
0 N: ^4 t- q3 W" C! ?int gdriver = DETECT, gmode, errorcode;   ^! `; |! F4 a( w5 x' N9 T
char msg[80]; </FONT></P>
' |% O; r  ?' k+ {+ C6 `1 v" D7 u) J) w<P><FONT color=#0000ff>/* initialize graphics and local variables */
" }7 [* K! s; r8 w+ f9 ]0 ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ R2 ?; n& [& \0 g, l3 }
<P><FONT color=#0000ff>/* read result of initialization */ 4 Z" m6 ~; t& N7 q) ^6 o. G
errorcode = graphresult();
  d# Y) B& Z: w. [7 [4 Bif (errorcode != grOk) /* an error occurred */ 0 ~- K) q( _9 D; ~9 A5 G$ o/ s0 }& O3 a
{
! L) _% O7 Q" d7 Q% \7 n9 qprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : D6 g5 L2 p+ |7 t6 s+ |' j% I2 f7 ]
printf("Press any key to halt:");
9 K( N2 a: {  D+ M. [6 @7 C- o% Wgetch();
4 p8 f* q& C5 D% `exit(1); /* terminate with an error code */ 7 s% U$ Q, L6 D" C! a9 C* M9 |
} </FONT></P>% ~- L: s/ ?; W& j
<P><FONT color=#0000ff>/* move to the screen center point */ 7 [# z2 T+ Y' P9 i7 Z1 Z' O' w
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
: L- V1 v( j  b3 {" K9 A0 F: o<P><FONT color=#0000ff>/* create a message string */
+ q! |5 m  u) P, J* R' Z3 Wsprintf(msg, "&lt;-(%d, %d) is the here.", getx(), gety()); </FONT></P>
, l( c* d% U  @<P><FONT color=#0000ff>/* display the message */ % o5 P) ~( r( b& K: r
outtext(msg); </FONT></P>
5 T. D, q0 P, U( V5 a+ R# ?: E+ p<P><FONT color=#0000ff>/* clean up */ * G1 n$ A4 u. T8 `- k5 m- y, }5 U
getch();
- O; g  I) u3 G; zclosegraph(); 3 n9 i5 ~6 f" ?+ ?6 h8 c' E" n
return 0; + A' J% J# B1 s! G% G" S) S2 W& @
} </FONT>- P4 [  t. U' ?7 K# G$ A  T0 Z+ o

) K+ U) @2 j0 V, N1 p! d! p. t</P>
5 {/ W8 `* K' w- H2 @2 l0 O<P><FONT color=#ff0000>函数名: gmtime </FONT>
! y+ n! K2 z! x- k9 f功 能: 把日期和时间转换为格林尼治标准时间(GMT) : B/ [4 r; c( I
用 法: struct tm *gmtime(long *clock); ' a  T) |( C3 o9 [" d5 q
程序例: </P>
* _% H& v  Y0 B9 S" a1 S<P>#include <STDIO.H><FONT color=#0000ff>2 H  |* J, r& e
#include <STDLIB.H>
! t  e$ Z5 S9 W  w#include <TIME.H>! U$ Z; z$ U/ n, s# }( ^
#include <DOS.H></FONT></P>& v  ]0 ^: A' h) Z
<P><FONT color=#0000ff>/* Pacific Standard Time &amp; Daylight Savings */ : m+ w) T1 v& [# P" Z1 Y$ O
char *tzstr = "TZ=PST8PDT"; </FONT></P>
8 y( B/ C# ?3 J2 \<P><FONT color=#0000ff>int main(void) , }5 B7 ?  r$ P7 {3 C- U
{ 1 a' B+ Q' T$ _# y# A
time_t t; : I: g5 ~- h3 q& M! c+ R
struct tm *gmt, *area; </FONT></P>& h( O) o  J  c+ M" ~! m9 p5 h
<P><FONT color=#0000ff>putenv(tzstr);
2 m; s9 e6 c; itzset(); </FONT></P>* j$ I8 o1 {  }4 e/ |1 t
<P><FONT color=#0000ff>t = time(NULL); $ c, @. L" {+ P$ v1 e' B* Q. _' A
area = localtime(&amp;t);
3 i& p( A. n9 f& Xprintf("Local time is: %s", asctime(area)); ; p/ N' K$ r- B- }' q
gmt = gmtime(&amp;t); . F7 E' B* W3 Z4 w8 B6 `9 j% ~( G
printf("GMT is: %s", asctime(gmt)); ; S7 `; U, B1 Z
return 0;
4 z9 V. L! _+ K# W. m} </FONT>$ B: z( n: ?  g9 O; K5 n
" I3 N7 N7 |' e) L8 j9 h9 Q* \
</P>
3 }; ~2 h3 P+ j7 c& G* \1 E4 R<P><FONT color=#ff0000>函数名: gotoxy </FONT>
' o6 h# x; P4 \- S功 能: 在文本窗口中设置光标
+ F$ |9 q( Z7 |用 法: void gotoxy(int x, int y);
$ J6 d. U4 F0 G% T0 s2 R( W程序例: </P>% C) {" ]" h7 [+ K
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>  i# a  w4 x2 z: G1 {/ A5 w
<P><FONT color=#0000ff>int main(void)
! P1 C' @, C0 b8 V4 E{ . \, K/ o( q/ r* S; x- s1 E
clrscr(); $ f* W1 u0 V  L5 x5 B
gotoxy(35, 12);
" {8 C6 u7 z& q& L0 i* s( p2 f, V& Qcprintf("Hello world");
9 H* ]4 i' n( i7 [2 jgetch();
# [1 \3 \. }( x- S. J2 breturn 0;
7 |) j* p! Z3 y, x7 [2 q8 A8 |}</FONT> 0 o. L: ?( _; D& C& z( _3 H
( N6 T0 x& T* e$ Z
</P>' H+ `) E+ [' i+ C5 L7 }
<P><FONT color=#ff0000>函数名: gotoxy </FONT>
1 {% S( i$ A* S! x) q5 t# d) [% U功 能: 在文本窗口中设置光标 / o3 T) [6 }9 d* g8 d
用 法: void gotoxy(int x, int y);
3 Q  E/ o1 r; _程序例: </P>
$ f( W; |# B& P: q3 H, ]<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
, ]# H) D# o' W& G( g<P><FONT color=#0000ff>int main(void)
$ N: X  e% y8 T) V{ & [% V! T6 ]" c# a" j( _: f$ J  }
clrscr(); 1 v7 g/ Q* y2 ]  ^
gotoxy(35, 12);
5 g# z0 d7 w: e! o- ~" T( Xcprintf("Hello world"); + Y! K0 p  r7 f5 m
getch(); % n7 `" U# V/ j
return 0;
6 F! ^7 [6 C" y6 A& x} 6 b) T) h8 ^" {2 W4 ^! D
</FONT>3 y8 t( P( g# M2 {, [- Z
</P>$ C0 A# p4 Y7 C
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
, x1 y$ D; s% r  t功 能: 将所有图形设置复位为它们的缺省值 3 W0 v* @# g9 e5 t, x
用 法: void far graphdefaults(void);
2 S; D' C& q: [- z% L) }5 y程序例: </P>& G, |9 `2 H8 r5 [  g+ P
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ P% [: X7 v, k- T, m* t#include <STDLIB.H>
$ X% C6 n6 p$ A) A) t#include <STDIO.H>
: l- Z9 U3 q- ]! u4 |+ y' Q4 P  {" K$ a#include <CONIO.H></FONT></P>
8 q: }2 ^5 P% n( i3 H9 a: c<P><FONT color=#0000ff>int main(void)
, h! p4 f2 s  s3 G& D" T& c$ l' g{
5 _8 h: D( t$ Z% J7 m/* request auto detection */ 5 p  k. v- t3 H* V1 m  N
int gdriver = DETECT, gmode, errorcode; 1 P( J1 U4 y) j# V  w
int maxx, maxy; </FONT></P>0 A0 c; Y. y0 O8 R: T
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) {, N+ u! @& k+ x& ~
initgraph(&amp;gdriver, &amp;gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>0 v. d$ u" R( S
<P><FONT color=#0000ff>/* read result of initialization */
) x$ W; ]& x+ _: x2 gerrorcode = graphresult(); # |) Y' e3 t! P2 C5 }
if (errorcode != grOk) /* an error occurred */
/ [$ ^% g0 K5 L8 [; a8 T# D: c{ 8 R! g& E/ f% S# \/ \2 `# U/ h5 h
printf("Graphics error: %s\n", grapherrormsg(errorcode));
) O" \( n. G$ h7 B, xprintf("Press any key to halt:"); " ]* y: B# O3 @
getch(); 6 m. [, M# f+ [& p3 ?
exit(1); /* terminate with an error code */ 4 L4 U. Y( l) W& P5 F3 M- C
} </FONT></P>
. o9 i0 c7 j/ T( F( [! z* C5 x<P><FONT color=#0000ff>maxx = getmaxx();
5 f) m5 ]& A; h) X4 T) ?maxy = getmaxy(); </FONT></P>
7 S% C' N$ s/ w, P) W6 S5 h/ U<P><FONT color=#0000ff>/* output line with non-default settings */ : I) b4 v7 i1 `' ]7 D" X- M6 \. ^' C2 ?
setlinestyle(DOTTED_LINE, 0, 3); 0 y! |6 Z- i7 ~0 }. Z  W
line(0, 0, maxx, maxy);
7 b4 P/ y0 S, y1 \, P9 fouttextxy(maxx/2, maxy/3, "Before default values are restored.");
$ p$ t) Z6 o" [( m5 J1 Z0 Ugetch(); </FONT></P>4 X; u& I* y! }, ~, [
<P><FONT color=#0000ff>/* restore default values for everything */ ! f- l8 |1 Z$ O7 G
graphdefaults(); </FONT></P>
+ N! Z' _- W3 e0 |/ h<P><FONT color=#0000ff>/* clear the screen */
3 D, D5 B# S2 B% Q0 f2 r9 Xcleardevice(); </FONT></P>% \3 ?& m3 m2 F- c5 s7 y3 U
<P><FONT color=#0000ff>/* output line with default settings */ 5 i1 j7 c6 f( V4 H
line(0, 0, maxx, maxy); 4 V1 a  Q* I  \& f5 R
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
/ ], w/ s/ _5 N5 F7 p- X  ?0 z6 Z<P><FONT color=#0000ff>/* clean up */ 9 h' T# W, r8 y9 o( b7 i5 Y
getch();
. F  A- ~8 F  _" W8 T. k+ W* |closegraph(); 4 i$ N+ t( P2 v! g
return 0;   X/ ~% [, W" _  N9 T
}
; O1 V- [. G. \$ r( [6 n) ^. W1 O</FONT>
' r/ r4 D# @5 {: h$ [7 Q</P>& S. a. i; ]9 h
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>& ?! ?: h+ j, a4 c+ U
功 能: 返回一个错误信息串的指针
/ n; q4 t: Z* b' j用 法: char *far grapherrormsg(int errorcode);
+ w  \  F6 P! t! {: j4 ?  d* P+ z程序例: </P>
: \+ V1 H# S+ n! T; O* a<P><FONT color=#0000ff>#include <GRAPHICS.H>4 M9 [. h  E6 y2 `
#include <STDLIB.H>
$ g) l' c+ E8 v6 I+ P0 a! }#include <STDIO.H>
: Z# k+ r, u6 J# e#include <CONIO.H></FONT></P>
; \; E* B8 R. H$ O! ], {7 x<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>  e- Q0 \0 i$ n
<P><FONT color=#0000ff>int main(void) : Y6 }! i, s$ Y/ E5 Z4 v! c
{ + @5 {$ i. }1 q3 m; }/ \; ?
/* FORCE AN ERROR TO OCCUR */
5 p: A8 T+ Q% k; p4 Fint gdriver = NONSENSE, gmode, errorcode; </FONT></P>' m0 M2 V( m( [4 m1 ?2 C9 p/ P3 C
<P><FONT color=#0000ff>/* initialize graphics mode */
9 Z' I9 {3 L& S4 H  _8 ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! H5 ]# e  r& |; z<P><FONT color=#0000ff>/* read result of initialization */ 1 h; e" w2 j$ R3 j4 I8 I
errorcode = graphresult(); </FONT></P>2 a+ x4 g7 ~' m4 S% ]
<P><FONT color=#0000ff>/* if an error occurred, then output a */ ' \6 R. ^0 Q# f) t
/* descriptive error message. */ ; @4 {3 l( R$ c
if (errorcode != grOk) : ~; h; x5 F( Z0 z& C( f/ y
{
, B" O: p, l; xprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, ~& y- y9 g( s1 x% qprintf("Press any key to halt:"); 4 E+ C& a: c6 U8 r5 M
getch();
. U/ l; h+ r* q4 V- B. |! s6 sexit(1); /* terminate with an error code */ 3 w3 y: l! j1 j7 C0 s% V
} </FONT></P># y3 X3 l: N& r! x+ i+ y1 K+ v
<P><FONT color=#0000ff>/* draw a line */
8 p6 w/ q. h" a- Nline(0, 0, getmaxx(), getmaxy()); </FONT></P>. @  y7 m* q4 H: G3 D
<P><FONT color=#0000ff>/* clean up */ / B6 T# q! Y8 O. |5 a2 K8 Y
getch();
3 c$ ]% |; c! U- _6 A/ f' L, dclosegraph(); ( g# d6 A$ d# p1 F$ l8 g! [4 I
return 0;   H+ s5 k$ D& S% d! o
}
( a" Z! U& S: G$ ]- ~</FONT>
2 Z2 ~1 S# v; a+ t+ ?) l</P>  z5 w7 M9 W* Z" Z5 [/ D
<P><FONT color=#ff0000>函数名: graphresult </FONT>  g0 ^/ k# w$ Y& U8 N: q1 P
功 能: 返回最后一次不成功的图形操作的错误代码 9 U( D( r4 e2 e
用 法: int far graphresult(void);
) U# M; i4 o9 _' q6 j0 |程序例: </P>- x/ Z) U& s6 a; R
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* K* K; ~1 M- A: i) s#include <STDLIB.H>
1 X9 B0 s9 T6 a8 O#include <STDIO.H>
+ {! r# i& |: }! w#include <CONIO.H></FONT></P>) H3 ]: t3 s; h1 L; E# p. R% R: P+ I
<P><FONT color=#0000ff>int main(void) 0 `1 z  E& w$ E' ^# a! Y" u1 p6 G
{
  E, j& Q. ]' L# N! W/* request auto detection */
& ]: m; H& e5 w# yint gdriver = DETECT, gmode, errorcode; </FONT></P>
. J3 L$ J* i& C' Q2 z<P><FONT color=#0000ff>/* initialize graphics and local variables */
' P5 ^* G" `. d9 `) r7 V5 `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* {/ I+ F$ e( I1 v5 p
<P><FONT color=#0000ff>/* read result of initialization */ " q% ^0 \5 U' B( y: ^" C1 I
errorcode = graphresult(); </FONT></P>% V9 y5 `+ p/ ~* k
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ % D9 {' u4 k' g$ T
{ 3 h% P+ r0 a9 ?9 \6 p. {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 C# e/ u+ ^: p5 o' A- Q1 X" Zprintf("Press any key to halt:"); ; o7 f' k! c3 \' @" _
getch();
3 g9 c: a+ Y8 n) B. ?: ?exit(1); /* terminate with an error code */ ( r+ a, v& j  {1 S2 k9 a; x" I1 m
} </FONT></P>+ J; \( ^- ~  g/ D1 ~
<P><FONT color=#0000ff>/* draw a line */
4 ]! t. s. }" [) Nline(0, 0, getmaxx(), getmaxy()); </FONT></P>
. V- n& l$ z7 x% k( T  N) _+ p& [<P><FONT color=#0000ff>/* clean up */
1 T& t5 D5 ]( n3 c( Jgetch();
$ G# f: r; ]& S  ~& O# sclosegraph();
- V' N. c) M* I* J' d- Zreturn 0; # [& ^& D! p8 X. [1 F! ?5 N0 E
}</FONT> 7 i4 j4 ~3 k  C: |
</P>
. N4 t8 i& n6 l1 P<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> ) @9 k1 P+ S' `! l; x
功 能: 用户可修改的图形存储区释放函数 : W% t9 A$ h: C( M
用 法: void far _graphfreemem(void far *ptr, unsigned size); 9 A+ @( T( E3 o! h7 j* E# o! i2 Q  E
程序例: </P>: ]" B/ c! }2 r: s6 w. X
<P><FONT color=#0000ff>#include <GRAPHICS.H>/ k) M: C. T. V% R7 f5 G. ~& T
#include <STDLIB.H>1 f. y1 Q7 l/ H2 e  \) I
#include <STDIO.H>5 K' F# B2 p3 m7 R! g
#include <CONIO.H>  x7 H  P, G" w1 [% K5 l
#include <ALLOC.H></FONT></P>
+ ?  S" }: Z; y# m& n<P><FONT color=#0000ff>int main(void) 3 B& c- E1 Z+ Y- `7 }& ]
{ ; p. y# [( A/ K- q8 ^2 D
/* request auto detection */
  i( z9 M1 B( a0 E" S( f, a$ wint gdriver = DETECT, gmode, errorcode;
# B$ }+ n) @& a0 b# ^int midx, midy; </FONT></P>
3 V2 ^  W6 V/ @( ]3 R9 n0 n" Z, X<P><FONT color=#0000ff>/* clear the text screen */
7 R; M' ~! s1 l2 W: R9 Uclrscr();
& q- |4 E- E% Q( r- gprintf("Press any key to initialize graphics mode:");
( M# Q7 ?- G' pgetch();
5 E+ Q- l& J# N# O# L0 F' Pclrscr(); </FONT></P>2 j: _1 J. P) v
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% T: _- K1 `# L7 |initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( o5 o& _9 M9 `, H, D<P><FONT color=#0000ff>/* read result of initialization */
- h8 Q9 ]- c/ h  q+ G4 l! p7 ?errorcode = graphresult(); 8 K" x: W$ M5 [" V  m+ J  M
if (errorcode != grOk) /* an error occurred */
: G" M+ @5 ?2 E* \( b! ~% t{ ( n# I9 X) M$ I6 j  C& b/ F
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 A+ Q+ I; b5 ]' t  |printf("Press any key to halt:");
8 @# f5 f0 R2 g3 i/ R2 x- j6 Ugetch();
# x& h& s- o& p6 L7 `  P$ Mexit(1); /* terminate with an error code */ ( w' {; ?0 j7 L1 ^5 w. Y0 Y
} </FONT></P>
8 t$ C8 n; B% u1 g. ?" v5 c0 j8 D  W  d<P><FONT color=#0000ff>midx = getmaxx() / 2; . _6 g4 v8 z* _+ P# p
midy = getmaxy() / 2; </FONT></P>
, b- f, q$ a: B<P><FONT color=#0000ff>/* display a message */
" m0 w3 A& O- @0 b0 y5 ssettextjustify(CENTER_TEXT, CENTER_TEXT);
; A' F4 p2 o6 }) \" Zouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>; N3 [8 I+ l6 o, ~
<P><FONT color=#0000ff>/* clean up */ 9 I8 @8 c7 f* m  W
getch(); ( [3 E$ O4 O/ x, v
closegraph();
; t1 F% b, c6 h7 jreturn 0;
1 M* l: H' I. R# E} </FONT></P>
* p+ f7 \9 @" B" I) a<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
; h% h, U/ ^/ Y. \4 W& Hvoid far * far _graphgetmem(unsigned size)
$ F( z* h. w8 m. j" Y- N{
" Q  S8 u2 u6 f% Mprintf("_graphgetmem called to allocate %d bytes.\n", size); * `1 U3 `: Q4 D( M( `
printf("hit any key:");
9 N) \: H4 v  \7 B* B: Q5 J/ o( ngetch(); # ^1 h& d& n; X7 n" d
printf("\n"); </FONT></P>
$ |5 k' d+ k3 A0 Q# q! M8 K<P><FONT color=#0000ff>/* allocate memory from far heap */ 8 V) m0 V; [/ C( r
return farmalloc(size); - V; b) D. S# \2 G. i8 _
} </FONT></P>
' Q- b/ Z. L. J8 [  w<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
4 c1 b9 V5 M$ E  x8 X6 C* ?, h6 A+ Wvoid far _graphfreemem(void far *ptr, unsigned size) 9 Y1 X( [( m3 h, f' u5 Z1 B
{
" i# D9 ^: {1 Q( J7 h7 uprintf("_graphfreemem called to free %d bytes.\n", size);
+ K5 r3 O; x+ l, Pprintf("hit any key:");
4 u# |" |  [- w9 D7 g8 }getch(); ; c0 D  X' w0 Q; ~% \0 `
printf("\n"); </FONT></P>
5 s+ ?  w0 m- G9 K5 f2 j<P><FONT color=#0000ff>/* free ptr from far heap */ # g# e8 A. O  m6 P! E& a9 X
farfree(ptr);
! k. a" ?! t6 s5 U}
) A. j9 Y6 d, T7 U# m+ ^9 O6 \</FONT></P>/ \0 ]  Z1 J; i8 [0 l; m
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>( H' r- G  X3 h% a
功 能: 用户可修改的图形存储区分配函数
+ V. T3 g/ W  q# p+ r9 @9 z用 法: void far *far _graphgetmem(unsigned size); / {/ y" N. E% ?4 Q1 h# u, G+ I
程序例: </P>6 r4 X0 {$ x6 u7 y
<P><FONT color=#0000ff>#include <GRAPHICS.H>" @, O; X9 |2 S0 y
#include <STDLIB.H>* _0 ~# j( W- a" P; w# L/ L
#include <STDIO.H>: x: h( G! K4 N9 X: H! Z; a; u2 [/ X
#include <CONIO.H>1 O# x* E; s) ^3 _0 n- m% `6 g! ^
#include <ALLOC.H></FONT></P>9 j$ U# p$ C' Q5 [$ y
<P><FONT color=#0000ff>int main(void) : H& A1 V2 ?: U4 U: u
{
2 g2 Q6 @) x7 P3 _/* request autodetection */ * E/ T! l/ G  E" X6 y  {  k
int gdriver = DETECT, gmode, errorcode;
! a6 M7 m6 Q% y. b# f8 b, `int midx, midy; </FONT></P>
5 |* _! M0 p. H4 S3 W, B' u<P><FONT color=#0000ff>/* clear the text screen */ 6 f$ o5 U( K! D- L
clrscr();
- j5 Y/ p/ ?$ l0 _9 l  f) \, S- uprintf("Press any key to initialize graphics mode:"); & D: e6 v0 d# N6 T0 I
getch();
1 r! C+ J8 I# Z/ X+ J4 e; Dclrscr(); </FONT></P>7 i* ~- \! G% ~. ?' V
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , S0 ]' s; f" Q& M- @# h& z6 |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  V  y: ^* C; F+ i
<P><FONT color=#0000ff>/* read result of initialization */
3 X6 ?$ E6 f( {- m% ~* Xerrorcode = graphresult(); ( X. X3 F' V  K
if (errorcode != grOk) /* an error occurred */
: L7 H4 ]- l, M" u5 ]6 T9 h+ S{
! b" v' [/ M0 bprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 G3 i/ ]4 p5 F4 w6 v
printf("Press any key to halt:"); 0 b) W) T4 g1 C, N2 D) M- u/ i
getch(); ; j. Z# Z0 o' X! |
exit(1); /* terminate with an error code */ 9 `3 d- U5 v* e# d1 S
} </FONT></P>
/ k2 d5 r0 O* J+ T<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 V& j0 g# Y/ W2 i4 jmidy = getmaxy() / 2; </FONT></P>
* _  Q* r( O; i: _<P><FONT color=#0000ff>/* display a message */
' f, S" a' n# N) R# Q  f+ }  Lsettextjustify(CENTER_TEXT, CENTER_TEXT);
$ z0 ]+ y# h5 a0 p0 f. Iouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>  y) A. c9 b+ u' J" c) F8 l  F
<P><FONT color=#0000ff>/* clean up */
5 j5 B5 z* p: E& ogetch();
5 m4 A( J$ u6 A3 R" F8 @- @closegraph();
- Y) ?* d; J! ?& z- M4 t; r' Greturn 0; ( d" l/ H; y5 F% n# @; o% p
} </FONT></P>
. D. h7 K0 k, T" U3 M- }' z<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
1 |" o3 V1 H/ P6 F" Uvoid far * far _graphgetmem(unsigned size) & x* t% T1 F( m! k% |
{
7 W  j8 b3 K5 u  v: l* Jprintf("_graphgetmem called to allocate %d bytes.\n", size);
, x; ?! c' _* u" _; k0 gprintf("hit any key:");
0 y; M& r( k( z, H- z2 v: d% x7 _getch();
1 G) T, q; X- ^/ zprintf("\n"); </FONT></P>
" D/ y5 d% c1 |. C. d; p<P><FONT color=#0000ff>/* allocate memory from far heap */
, E7 }  G3 Q5 T  p0 U! b8 Preturn farmalloc(size); ) r0 I) c$ @* j, |& l
} </FONT></P>. u$ T9 `7 @" K- N; w% ~
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ # C3 J+ J, ~  G: Q" i# W7 r
void far _graphfreemem(void far *ptr, unsigned size)
6 J2 j) T7 j3 t; I: ^4 y{
9 O% W6 B* N+ g- H! {printf("_graphfreemem called to free %d bytes.\n", size); 5 a  T* ?4 i* D. E$ e2 D  ~
printf("hit any key:"); ( }9 c2 Z1 Y8 q1 [
getch();
. _( a: d$ D6 U  _( x  l' Jprintf("\n"); </FONT></P>
( Q- ^8 r  {- F<P><FONT color=#0000ff>/* free ptr from far heap */ ' J( S; [7 G3 ]
farfree(ptr); 2 J7 F3 N0 C, J* U+ S
}: A4 O  u7 O& {: x5 h
</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-23 09:40 , Processed in 1.520390 second(s), 51 queries .

回顶部