- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(g开头)</FONT></B></FONT></P>
- p. e- W' f$ x
4 ? P* y5 V K- Y* e( O* [6 s6 A' G" D* @- `
<p>1 b! f! o- F y) {) M
< ><FONT color=#ff0000>函数名: gcvt </FONT>
7 q. ~% F, |# W8 b功 能: 把浮点数转换成字符串 7 ?* [ H( j4 u# ?
用 法: char *gcvt(double value, int ndigit, char *buf);
% ~& t, @4 E% R; h: b2 o0 s/ k程序例: </P>
& }$ z0 A; i+ S# X* M* T B< ><FONT color=#0000ff>#include <STDLIB.H>/ m' b! U* `1 v
#include <STDIO.H></FONT></P>
- ]- L% R+ v% |: ?( M< ><FONT color=#0000ff>int main(void) , K8 S' h% n, h; U. o) f& p7 R9 X
{
6 c+ N4 {- P+ Jchar str[25]; * b2 I6 O$ F! x. r( V
double num;
. W. i) P1 j& ^( Jint sig = 5; /* significant digits */ </FONT></P>
. T* S1 g) ~4 Y, a8 [, \) s, q" N; y< ><FONT color=#0000ff>/* a regular number */
! r6 b4 i2 J5 d6 ~4 r) m) \8 c$ nnum = 9.876;
! N0 ~5 O+ V) k! d' L5 g# O$ D4 Hgcvt(num, sig, str); + {) J+ r9 |; D/ p/ |& b9 J! B3 F0 O
printf("string = %s\n", str); </FONT></P>
& Q' v6 V3 u0 H- u< ><FONT color=#0000ff>/* a negative number */
( b% L7 Q k/ Y& l! q. {num = -123.4567;
% @! o$ ]/ I1 X% t" Wgcvt(num, sig, str);
. i( \5 m$ ]3 i$ | V5 h3 aprintf("string = %s\n", str); </FONT></P>
/ J9 ~ ]/ L2 E4 V6 n$ E' u0 V* i# h< ><FONT color=#0000ff>/* scientific notation */
# i2 n5 \" Q1 `5 @" ]- `num = 0.678e5; 5 I- ^" S: I4 W* t% J
gcvt(num, sig, str);
- a+ R; b8 Q8 h7 o8 u! W9 O9 n1 hprintf("string = %s\n", str); </FONT></P>! M+ g6 L/ R5 Q( R0 W
< ><FONT color=#0000ff>return(0); , u# _: t$ `5 f3 J4 o3 u# d$ i
}
$ W$ O0 n1 S6 e' o& M
9 l: x8 w; |1 O% F, [' `. q</FONT>, ~- z0 {3 A1 I" l% `7 A; f0 d; V4 t) F# g
</P>$ @( i! y) m+ o; [
< ><FONT color=#ff0000>函数名: geninterrupt </FONT>7 n1 P* M) D4 j/ A O! X+ r! g
功 能: 产生一个软中断
( n4 @* v2 g& i; @用 法: void geninterrupt(int intr_num); 4 R' u b i: S5 m+ s% b
程序例: </P>6 j: M( [9 H2 \: H/ y. H
< ><FONT color=#0000ff>#include <CONIO.H>5 l1 {7 f3 V3 ~+ k# I4 P% O- \
#include <DOS.H></FONT></P>
5 w8 O, B2 v4 J% m& K< ><FONT color=#0000ff>/* function prototype */ / V1 U9 c. r" \0 k* y( `$ B; Z
void writechar(char ch); </FONT></P>' Z9 x: L7 u3 G6 U" N. L
< ><FONT color=#0000ff>int main(void)
) ^5 c& g7 b z' x8 ^; P$ ]{
2 P! G) n- N. Q! x3 Cclrscr();
. J W/ t+ F( T) Igotoxy(80,25);
8 ]# g E, i* M$ y$ Fwritechar('*');
0 n% F' x2 [3 {& p- ~, S' ]getch();
# K$ ]$ Q- Q: K# l& Y" S0 b- ^return 0;
" J: j1 X' Q9 Q) f} </FONT></P>
- h) k, s4 o9 n! r< ><FONT color=#0000ff>/* ' W# I. L0 V7 `- |8 H2 A0 h
outputs a character at the current cursor
6 ~7 |" @( F/ m. N4 p+ d* f' U. wposition using the video BIOS to avoid the ; {' _* z: m7 H/ A
scrolling of the screen when writing to
' p% T6 Q# D) F: N% | Ylocation (80,25).
6 G$ i% p/ \9 C/ E9 p d0 o*/ </FONT></P>
& Z4 s& h7 l5 `) P< ><FONT color=#0000ff>void writechar(char ch) 7 O$ H1 B; k, M$ f# d4 Y) p
{
% P: Q, [" E G& f# q/ G$ vstruct text_info ti;
% p! H2 V7 ]' j. c/* grab current text settings */ 0 B* m$ n7 t7 Q5 ^
gettextinfo(&ti);
0 T- |9 W1 K/ K3 h/* interrupt 0x10 sub-function 9 */ 0 D3 N' W* j' G; t f+ N5 e, o0 O5 R
_AH = 9;
1 a0 u- q- D1 A/* character to be output */ / @! V5 P8 z$ r
_AL = ch; 1 X. M) B" [5 s, v
_BH = 0; /* video page */ F7 a: h& Y, W2 V5 w5 B( O
_BL = ti.attribute; /* video attribute */
# A" N9 S; Z6 f$ Y+ o_CX = 1; /* repetition factor */
2 K* w! Y0 O; n3 |geninterrupt(0x10); /* output the char */ . J9 V3 p, D4 A, J7 }1 a
} - E4 v& @$ P& Y& C a
</FONT>+ x, s0 y0 v% N" ]+ r0 Y/ l
</P>2 Y+ j/ c" z' h# \
< ><FONT color=#ff0000>函数名: getarccoords </FONT>1 i' {5 F. R& ^0 U j( |& [, i8 l
功 能: 取得最后一次调用arc的坐标
" r/ Z, i. s7 Q3 z用 法: void far getarccoords(struct arccoordstype far *arccoords); 2 t I6 h( @5 F% o( c" M E
程序例: </P> v2 v" f2 b5 [& t, ^8 m
< ><FONT color=#0000ff>#include <GRAPHICS.H>
( y/ \# H: h/ M9 x. l- J#include <STDLIB.H>/ F( j9 q2 Y. a& W
#include <STDIO.H>
7 T; d9 q1 H! i+ F7 A#include <CONIO.H></FONT></P>
6 |' j' U% v9 O/ I- f< ><FONT color=#0000ff>int main(void)
4 y1 ^/ u0 ?, r. w) z{
% F5 E/ d" v" p5 y/* request auto detection */
1 t$ P/ A7 S- p3 aint gdriver = DETECT, gmode, errorcode;
9 p/ M" F1 w4 ~; Y4 A- ]struct arccoordstype arcinfo;
5 X$ ]- G, Z4 J# A M' i4 Zint midx, midy; ! G6 Y+ O$ O$ F% U( v
int stangle = 45, endangle = 270;
. h* D! N6 k8 I; `" Ochar sstr[80], estr[80]; </FONT></P>2 N. e) c N5 a( Y
< ><FONT color=#0000ff>/* initialize graphics and local variables */ 3 K2 n% W$ C/ {
initgraph(&gdriver, &gmode, ""); </FONT></P>. J; z# w4 f9 X# f+ Y" _$ h* m
< ><FONT color=#0000ff>/* read result of initialization */ ' ^5 m8 ?# H2 I+ R
errorcode = graphresult();
1 j. J0 ?/ c% K. f& E3 S/* an error occurred */
* [: X( z2 {, x$ z/ [if (errorcode != grOk)
4 E' p! o# g: E- d- R$ o{ ; {2 c) r9 P5 j' j1 g& T
printf("Graphics error: %s\n",
) b* r+ `7 \4 J; r* D# ~grapherrormsg(errorcode)); # t5 F: E" h5 c9 t/ Z1 b) F+ k
printf(" ress any key to halt:"); ( V( _1 d6 ^2 M( f) ~" k: n; l0 [
getch();
# ~. }: y P i+ g8 f/* terminate with an error code */
1 h4 U& y1 b' k9 ]# Gexit(1); ! J8 E) B( L& [5 C9 K
} </FONT></P>
2 s6 D1 z# I5 L6 \5 ^< ><FONT color=#0000ff>midx = getmaxx() / 2;
4 m2 S W* ~+ V) [) ?- @5 {midy = getmaxy() / 2; </FONT></P>9 l# D k% t6 M/ H& X' P
< ><FONT color=#0000ff>/* draw arc and get coordinates */
3 v- e$ A3 i7 Q. a2 Z* ?setcolor(getmaxcolor()); 4 \- O. ^- {' O' B! P" a
arc(midx, midy, stangle, endangle, 100);
: S! O1 A6 s: K: |3 C7 a; s# ]getarccoords(&arcinfo); </FONT></P>) @; F2 e- B! x6 P6 n/ e' X
< ><FONT color=#0000ff>/* convert arc information into strings */ 1 f) E8 N0 T& [" D1 j
sprintf(sstr, "*- (%d, %d)", / \. y3 A2 a" q# i/ \
arcinfo.xstart, arcinfo.ystart); / h o- s! \$ f C" H* H
sprintf(estr, "*- (%d, %d)",
* Q5 v/ P* s3 q; F7 P4 b$ c. t9 y9 _9 [arcinfo.xend, arcinfo.yend); </FONT></P>, A0 H$ W6 _6 `6 n3 o4 x1 \' C
< ><FONT color=#0000ff>/* output the arc information */ 2 B% p5 u1 `: j2 [2 R
outtextxy(arcinfo.xstart,
K0 a+ c; {5 v J1 rarcinfo.ystart, sstr);
% A1 @, ] \9 M4 Aouttextxy(arcinfo.xend,
! ~8 _' X, `. T' e' [4 h* \arcinfo.yend, estr); </FONT></P>
. T7 F2 S# ?% r" H. Z, ~5 p; i3 E* m, Y< ><FONT color=#0000ff>/* clean up */ 6 \6 Q$ h& q( D; j
getch();
+ t# H9 p P/ H/ E" pclosegraph();
# J! `; h: r- Z' B( ereturn 0; ( u0 E. z' U" b: q6 w
}
$ Q; x( M i' D* E</FONT>
- Q- I1 c- k$ @) Z' u: G4 K
: T, e" w( `9 N</P>
n, h0 G; \: {! j# @5 K) `8 F< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
! L' `8 d2 V, b" H2 O. r d. i# W3 L功 能: 返回当前图形模式的纵横比
% @' b' t/ i% ]3 `+ L用 法: void far getaspectratio(int far *xasp, int far *yasp); / v+ d$ T# l& g9 \ U0 T8 H. V& g
程序例: </P>5 g/ F. B& v3 @* v" Y9 T0 Q5 ?
< ><FONT color=#0000ff>#include <GRAPHICS.H>
9 i+ B1 G$ O3 s; b' }% f% U7 ]#include <STDLIB.H>
# g# |5 q) \! i! b3 i8 Q: t6 l& c) S#include <STDIO.H>4 f$ r6 V5 [# K$ C7 o% w" n& F, R; M
#include <CONIO.H></FONT></P>4 B d x! q( }8 I6 F% Q4 S5 k
< ><FONT color=#0000ff>int main(void)
4 l( m$ o _2 B% _8 w4 @{ ( z6 S" y: q4 h0 p4 n
/* request auto detection */
5 M: c4 j3 P8 i; B4 X8 s, Y5 F hint gdriver = DETECT, gmode, errorcode;
! @7 f! [- J% W! F+ vint xasp, yasp, midx, midy; </FONT></P>
+ O. M* r* }. Z) x7 b< ><FONT color=#0000ff>/* initialize graphics and local variables */ 0 C' g2 x# C' J/ f6 v
initgraph(&gdriver, &gmode, ""); </FONT></P> d: g+ T% e: a
< ><FONT color=#0000ff>/* read result of initialization */ 1 t; d) m. n* M* R7 |% o ? u0 {6 j
errorcode = graphresult(); & g, _3 h' a* E8 \. U! s1 D9 p5 l
/* an error occurred */
0 G% X7 r6 |% O1 qif (errorcode != grOk) 1 R4 @: x. \2 m6 h0 A
{ 6 i/ x$ s' S# r1 Q. i$ ?0 r$ m' n
printf("Graphics error: %s\n", $ W& D8 S, Q% T4 Q
grapherrormsg(errorcode));
1 U( ?7 x7 X( d9 n3 y4 Y8 F* pprintf("Press any key to halt:");
+ R' I$ g7 ?/ l9 pgetch();
6 R+ B3 S' a! A' b8 L/* terminate with an error code */ . m8 y$ T* C$ k, Y7 f0 l) a1 Z
exit(1);
3 r# g' F2 K! r} </FONT></P>1 I! [8 e* P, W# r
<P><FONT color=#0000ff>midx = getmaxx() / 2; / X: t3 W' M. P1 P
midy = getmaxy() / 2;
" r# a' `: {" \& o$ ^. Osetcolor(getmaxcolor()); </FONT></P>
[. U4 ~/ f4 ~$ X<P><FONT color=#0000ff>/* get current aspect ratio settings */
9 \, C, a) \, T! H1 d, w |6 cgetaspectratio(&xasp, &yasp); </FONT></P>
/ o% a \0 U Z, l9 t$ `5 V<P><FONT color=#0000ff>/* draw normal circle */
9 a9 G3 [: Y, Q& u! |( L! Zcircle(midx, midy, 100); ' j1 g6 n: E) |! m! o* ?
getch(); </FONT></P>
" [2 ^9 x& A( X+ W7 ~9 X<P><FONT color=#0000ff>/* draw wide circle */ " h1 _5 W0 @6 a
cleardevice();
' C" { `, d. Z, V) Fsetaspectratio(xasp/2, yasp); 9 Q3 a! p- s2 ^! w' }8 Q3 w
circle(midx, midy, 100); D9 I8 R. c* @$ O3 X
getch(); </FONT></P>
) \, s. n8 O1 k<P><FONT color=#0000ff>/* draw narrow circle */
! Y. X( \4 p' w" }! o0 B( v2 n/ ucleardevice(); ! p: ?& r7 l8 N+ F7 Q1 ^
setaspectratio(xasp, yasp/2);
* X4 ]1 p- \/ E' f1 H" ^circle(midx, midy, 100); </FONT></P>
0 _$ F. y+ K6 R! ?<P><FONT color=#0000ff>/* clean up */ ) x( I5 q- k! D5 G8 Z3 ]
getch();
6 n/ Q Q, @2 Q6 yclosegraph();
$ C9 ~$ i! ?+ w1 F4 W3 ?return 0; 4 o. O0 u" r C- B$ m. ?
}
9 s" y: c& [9 b) D5 L' Z; n</FONT>4 V8 ]' L" ]6 K( [: x( b1 V% s
; d7 Q4 M% g4 H3 ?/ v( O6 A</P>; P* G, z) V, C8 s/ V) ]; S9 U
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
/ }& z- M5 r+ o f功 能: 返回当前背景颜色
" s* }) d# w7 w" f) `- s7 f/ A用 法: int far getbkcolor(void);
M& c6 M: d5 A5 Z6 a, a8 c2 i9 F程序例: </P>
8 ]5 R- I4 s* T+ Z y<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 G( K8 J. _( v/ f#include <STDLIB.H>
2 @4 V! C3 v8 W4 R3 t7 }#include <STRING.H>
; a3 w4 X2 c+ Q5 ]! n+ j#include <STDIO.H>6 Y) u0 f) R0 _$ q
#include <CONIO.H></FONT></P>
6 w! V& K) ?7 `- M1 @+ x0 k1 D2 n<P><FONT color=#0000ff>int main(void)
9 s- L0 d( ~+ a' W{
. R# Y1 d* ?% d# ^) _. c/* request auto detection */
: | Q3 u' ^0 ]: X) Iint gdriver = DETECT, gmode, errorcode; % M# v8 c- |+ ?) b& t: t
int bkcolor, midx, midy;
; s5 J6 j. x4 ^5 lchar bkname[35]; </FONT></P>
; S( Y! V, f# r! y- o* i<P><FONT color=#0000ff>/* initialize graphics and local variables */
& n( v j B) X* Einitgraph(&gdriver, &gmode, ""); </FONT></P>
( W4 E7 ^ ?. m<P><FONT color=#0000ff>/* read result of initialization */ " |# y) N1 c% o$ f
errorcode = graphresult();
' G4 Z4 P; w4 X* Z, C. `, C/* an error occurred */
& s: u6 O) h' V: hif (errorcode != grOk)
- Y6 ^* v* A' L6 I7 Z" O{
: H0 q! b8 n, C- t. ~printf("Graphics error: %s\n", ; i" O A0 ~+ ~( \
grapherrormsg(errorcode)); $ q4 Y3 `/ g% ~( g# ]& w
printf("Press any key to halt:");
: T; \$ i+ m7 I- b, n1 |8 }& ygetch();
: v, L' X. N ~6 f, H/* terminate with an error code */ # V! o% g, y6 ]/ |
exit(1);
; ?, \/ ~# F7 [" V; x% o) U} </FONT></P>8 A4 \# h, J7 w4 k$ j3 [ N+ [
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ P0 V- N; f- B& r, T
midy = getmaxy() / 2;
2 r6 {% |( P( r- [2 L2 x9 isetcolor(getmaxcolor()); </FONT></P>
/ B& I) T9 x5 u* J7 ?5 g' s<P><FONT color=#0000ff>/* for centering text on the display */ + J" e: v8 A5 K8 ^8 ~( E k9 {- q# F
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
6 H2 v- O. B2 v' c; M<P><FONT color=#0000ff>/* get the current background color */ 2 j$ C+ X: v' h+ {. a
bkcolor = getbkcolor(); </FONT></P>
- [, P. h$ y, Q4 R. x<P><FONT color=#0000ff>/* convert color value into a string */ & H$ g8 h2 L* G9 Z) J
itoa(bkcolor, bkname, 10);
: @7 `$ a) C0 a: j7 gstrcat(bkname,
3 _$ L- D; W) x/ P& C3 P" is the current background color."); </FONT></P>
2 c9 u* |+ N0 x/ h: m5 k/ U<P><FONT color=#0000ff>/* display a message */ / D+ V/ A/ v: }/ I7 S2 L
outtextxy(midx, midy, bkname); </FONT></P>) C9 n% M# e0 H, b: d& E0 X7 \7 j
<P><FONT color=#0000ff>/* clean up */
" J M! a% j T I# Igetch();
7 E q: I& X2 S) A+ kclosegraph();
% W, n$ A/ v7 G; p, ~! @; ]- wreturn 0; + L `# y: ? R- e) R! w; i- }
} 5 @# T2 C7 W, S- J- R1 ]2 b
8 B4 F+ e7 k9 ]5 V
</FONT>
. H4 e" z" w, g- q</P>- @( O: f8 Y& T3 ~8 |2 t+ s
<P><FONT color=#ff0000>函数名: getc </FONT>
1 R5 N( R3 J/ D# ?/ S2 J功 能: 从流中取字符
$ g7 W9 s% @- }5 c& [# ~* b$ H& O& z用 法: int getc(FILE *stream); , {+ {0 W& r$ U4 g" Y, ?* |" G
程序例: </P>
* R& j# ~' P! G/ m+ w6 l: ~<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>! u3 ~" {& R# V0 ]8 `1 z
<P><FONT color=#0000ff>int main(void) 5 N) z* v2 B5 S
{
, L/ P, h/ H# achar ch; </FONT></P>. W9 j* {0 _3 u1 a# O. D t
<P><FONT color=#0000ff>printf("Input a character:"); * g2 p8 J/ t6 v* |) h
/* read a character from the
6 h2 t; p* W( ]# H% k1 pstandard input stream */
2 c1 P9 y2 |9 \* H8 q/ X# vch = getc(stdin); 7 @) a& `' T9 H; z
printf("The character input was: '%c'\n", 2 J* a. w& S$ c G; h2 I
ch);
- ?% ~9 h. f, T( nreturn 0; * K. ]* G2 s% p: L/ S) n
}
0 e5 Y. ^0 ?2 [: Q! l% i
' k/ ]) W: n( [9 Z; U$ G, ]</FONT>8 m/ w7 x. e* h5 m. x% \% W" E
</P>
9 X- v! P [8 `$ G6 l$ \7 b+ c1 t<P><FONT color=#ff0000>函数名: getcbrk </FONT>
6 U7 p* |: z( ^功 能: 获取Control_break设置 ( ` T; I* ]8 n, t2 }/ D4 i
用 法: int getcbrk(void);
) N' q( B+ ^+ I; d1 p" O程序例: </P>' X4 g: ?% e# n( @2 [
<P><FONT color=#0000ff>#include <STDIO.H>
! Z: ~6 z, }, c#include <DOS.H></FONT></P>
' B3 z0 j6 T# j* ?<P><FONT color=#0000ff>int main(void) ( G+ N- ^0 W, J1 t f
{
1 q( k1 |1 @ @1 e1 T- aif (getcbrk()) ! W, h/ A7 M1 P# K
printf("Cntrl-brk flag is on\n"); * L2 h4 q6 N1 D. q3 P, a
else
) S+ M( H+ g0 m4 r2 _9 mprintf("Cntrl-brk flag is off\n"); </FONT></P>( t$ s+ r1 Z8 s* C- R* v, p
<P><FONT color=#0000ff>return 0;
E( x1 P6 \& b; d2 L1 [5 \' l0 ]: E} </FONT>7 F2 E: Q: r/ @; T5 D/ r
7 \/ @: a d; e6 S& }; s$ E4 ?
</P>
: z! D8 h3 T' Q1 R) F<P><FONT color=#ff0000>函数名: getch </FONT>
. h0 H- h- [8 g4 f; `: z, d! i) _功 能: 从控制台无回显地取一个字符 3 G: k6 l8 m. H2 ^
用 法: int getch(void);
- B q3 A3 q& Z% ]程序例: </P>, |; U2 h. |7 ~) M
<P><FONT color=#0000ff>#include <STDIO.H>
3 d3 A7 g4 `: `) o0 K0 Q q#include <CONIO.H></FONT></P>
8 a* R. _8 k% \' b0 m# i<P><FONT color=#0000ff>int main(void) 2 T3 m( Y5 D; J' `& X* |9 v
{ ( u5 D/ m) h# d: z) q# M( R6 K! q, h
char ch; </FONT></P>; I# i7 X5 m! t3 a4 M8 J
<P><FONT color=#0000ff>printf("Input a character:");
. M/ y9 U: C/ P; _ch = getche(); 8 D( Y: B0 n0 R% R
printf("\nYou input a '%c'\n", ch); $ @! g D' q. e0 q7 V
return 0;
/ M# D( U7 P3 ^! x/ @, T# n}
8 W+ W1 {! T1 X9 Q7 p! Q: C% M: p+ n$ m# F% o2 u3 e
</FONT></P>* L" K N5 p2 V8 J
<P><FONT color=#ff0000>函数名: getchar </FONT>
5 l& o+ g$ m9 w9 @2 G- `; {功 能: 从stdin流中读字符 $ N) V# u! o8 d5 N# F! u
用 法: int getchar(void);
* L) U+ F- g+ }程序例: </P>: `0 h9 e) m/ F+ N0 C5 T) }: |& h
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
9 s0 @0 r/ ~' x: T7 B6 m<P><FONT color=#0000ff>int main(void) ! {" ~* ~# F9 Z" A7 v# e, T& I
{ , W8 h# M1 N3 L
int c; </FONT></P>" O) ^2 V. _# }7 N0 |+ ?, X `
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
5 {+ X" D" P8 x- o' }/ v; ~% [9 W" ris line buffered; this means it will
* Q; ]1 s# I2 `, D$ J* V( x% n, enot return until you press ENTER. */ </FONT></P># s# \9 f5 N7 v% I- e2 x
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 3 i" ?$ U U5 r: z; m
printf("%c", c); </FONT></P>; q- Q, F3 k7 i* l
<P><FONT color=#0000ff>return 0;
' X2 j) T- \: `}
* \( C( Q5 H+ U8 S: P% G( e; M</FONT>; l+ b1 L2 J6 T
</P>
' J/ W+ S+ D& @$ Z( Y J' `+ J<P><FONT color=#ff0000>函数名: getche </FONT>1 A( x% ?( q# K. J# x+ }8 ~8 D
功 能: 从控制台取字符(带回显)
: N, _/ ^1 w( @9 P s. O( ?用 法: int getche(void); 9 E% j+ l2 D1 P0 Y% ]4 f
程序例: </P>
# m `: r3 o; L. J) ~$ G! ?5 W<P><FONT color=#0000ff>#include <STDIO.H>
$ V- @# M! ]6 a/ e1 ?+ K#include <CONIO.H></FONT></P>
8 \& ]! [: G1 {2 }! J* A<P><FONT color=#0000ff>int main(void)
8 K3 L7 t' B$ q8 @' z% Y' n/ f{
4 k+ o. ]" C5 I3 [char ch; </FONT></P>
4 O; e' y k7 q) U2 ~<P><FONT color=#0000ff>printf("Input a character:"); 9 ]' h! K* b$ ^; k6 q% H# B
ch = getche();
; q+ J) u' \. [, \& P; hprintf("\nYou input a '%c'\n", ch); 5 Y- E# c" d, w. I5 V
return 0; + s9 Z) R9 h0 T1 y% ~4 Q% k: q
}</FONT>
- n7 ?: m0 V- `9 T. A( M
# y# m- ~2 f; q</P>* c% T. x9 r+ w' @
<P><FONT color=#ff0000>函数名: getcolor </FONT>) R. F/ j) l; L6 Y1 W9 A+ J4 H
功 能: 返回当前画线颜色
5 a$ O N* L- {, {用 法: int far getcolor(void); 5 s/ O4 | ~. S* i& n$ J2 a
程序例: </P>! ^- }, Z! w7 X* ~
<P><FONT color=#0000ff>#include <GRAPHICS.H> n" U1 U$ j8 s, J* v
#include <STDLIB.H>5 S! q0 Q9 M5 y% t1 k$ K( m+ j
#include <STRING.H>; e, S( d5 V) w( B2 P/ a
#include <STDIO.H>1 ~: `% p9 A) Y: R" u
#include <CONIO.H></FONT></P>- n- j& l2 T8 }# x' s9 {
<P><FONT color=#0000ff>int main(void)
8 s O% F ~' O( R7 [/ g5 D8 I0 W' ~{ / a' I8 k* B4 U; D2 V. Z
/* request auto detection */
0 u. m X1 ] @int gdriver = DETECT, gmode, errorcode;
' @; H% X& _& gint color, midx, midy;
' M1 w j( p7 C( u; tchar colname[35]; </FONT></P>4 ?9 z5 |4 d6 R& X4 H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 F- a' [% S5 w
initgraph(&gdriver, &gmode, ""); </FONT></P>$ O2 ^% [4 n6 O) l3 Z+ r8 t
<P><FONT color=#0000ff>/* read result of initialization */
* m! `* J: B! ?errorcode = graphresult(); 0 M+ y; u; g# k' _; ?( U( Q
/* an error occurred */ q9 @( J4 d* ], Y7 D1 T
if (errorcode != grOk) * q$ B0 @! l/ Y3 s {4 Z6 _. y7 {
{
3 J) ?* F7 N! |* O5 a2 jprintf("Graphics error: %s\n", " z- I9 h; C; P2 g6 H4 d0 w
grapherrormsg(errorcode));
" A- i! g! T$ X Mprintf("Press any key to halt:");
, E1 S7 h( P9 T. `4 n" U. `$ dgetch();
$ |# ?7 }- k* ?2 n/* terminate with an error code */
, u/ x; I) y# b8 Aexit(1); ! U9 \8 ]1 Z" L9 {! P
} </FONT></P>* s" m8 X& @8 J/ T, T6 [, N
<P><FONT color=#0000ff>midx = getmaxx() / 2; - d, O9 H% S" o- |! Q( h# t
midy = getmaxy() / 2; + o4 k: S! {: c- {1 M
setcolor(getmaxcolor()); </FONT></P>
6 c9 x' g- Y+ G+ }. H5 }6 M<P><FONT color=#0000ff>/* for centering text on the display */ $ r& ]' H: A8 u( {- f1 }
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
- X7 S4 D/ w: V8 S2 ~+ K<P><FONT color=#0000ff>/* get the current drawing color */ % A1 B/ C" A5 \& r0 h
color = getcolor(); </FONT></P>- @8 L+ b; B# B6 Q; E7 j
<P><FONT color=#0000ff>/* convert color value into a string */
1 C* d, V8 a4 Z- t, G1 L/ k2 o) Xitoa(color, colname, 10); 3 ^/ }+ t; u% h" Z; M
strcat(colname, ) |$ C4 h6 s6 V5 B" t/ i% o0 [' T0 a
" is the current drawing color."); </FONT></P>
, q, }* |, g3 c/ J; X5 [; D<P><FONT color=#0000ff>/* display a message */
; n) Q4 H+ |3 louttextxy(midx, midy, colname); </FONT></P>
/ } {& l; N% d0 C7 [0 R<P><FONT color=#0000ff>/* clean up */
9 Z+ b! d& r! f3 M8 P pgetch();
" j1 E a9 ], n2 yclosegraph(); ; B5 x: v+ [! X2 V' S- d
return 0; $ K0 g# O$ i8 k; Y: t9 M
} 8 D7 ~1 @, T/ j
</FONT>6 `7 |/ V3 Y V$ C- Z7 Q& S F
</P>
( Q7 x: E0 l) p& V<P><FONT color=#ff0000>函数名: getcurdir </FONT>* a& ~9 e2 f. C x4 v3 c3 j
功 能: 取指定驱动器的当前目录
: m3 j- o! m+ x/ t4 z; x* n用 法: int getcurdir(int drive, char *direc); # L# Q4 r, t4 |* p% `% Z
程序例: </P>; u: G3 Y+ T; [/ S2 i! x
<P><FONT color=#0000ff>#include <DIR.H>
5 j4 N. R8 Q8 r8 t$ S' U0 F#include <STDIO.H>
1 P/ l- L b/ P- F! H/ ]#include <STRING.H></FONT></P>$ k: ~! D; A9 }& G% r, c
<P><FONT color=#0000ff>char *current_directory(char *path) $ n S6 a) i+ v; A* U+ p! g
{
* S+ o1 B$ F( }, M9 hstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */
8 Y, O( n& i1 zpath[0] = 'A' + getdisk(); /* replace X with current drive letter */
/ X- n2 x% T5 Q, @2 A8 e) h, tgetcurdir(0, path+3); /* fill rest of string with current directory */ ) J. {6 ]4 h8 g N/ m
return(path); 8 U6 E7 u- E7 h
} </FONT></P>* C( j n: j ]) f. I: L2 H" H
<P><FONT color=#0000ff>int main(void) - R0 o3 J+ p/ B9 J h
{ 0 }4 P5 R- {, K2 P3 ]* h; m
char curdir[MAXPATH]; </FONT></P>
8 R6 p7 O ~0 s<P><FONT color=#0000ff>current_directory(curdir); + E7 K: ~1 P/ X1 F1 o( I
printf("The current directory is %s\n", curdir); </FONT></P>
' I" r' |, @8 |% B. ?0 Z/ p7 j" b% K<P><FONT color=#0000ff>return 0;
3 `5 l [) h S6 B}
& ?, F7 Y& d2 u* Q1 U% L# ~. a</FONT>
& \% t4 d0 Z5 w</P>
1 V: \2 o) `# \<P><FONT color=#ff0000>函数名: getcwd </FONT>
5 n6 n' v! q3 s功 能: 取当前工作目录
/ j |2 L4 z X4 c用 法: char *getcwd(char *buf, int n); $ i9 J$ ^0 O9 f6 U% M% S* f" A6 s
程序例: </P># E4 Y; `* m) f# h
<P><FONT color=#0000ff>#include <STDIO.H>8 z2 O9 S1 g# B
#include <DIR.H></FONT></P>' u+ ?: J+ w# w! Y0 J1 ?
<P><FONT color=#0000ff>int main(void) $ r, h) T0 |' K, [4 D
{
! q/ H: I6 R/ i7 [+ Rchar buffer[MAXPATH]; </FONT></P>! E7 @7 K- D6 A$ J& U
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
9 Q g8 k+ B6 D) J) A' s* K% vprintf("The current directory is: %s\n", buffer);
6 \' f# G3 i! Ireturn 0; : k N4 j- w1 j. Z2 n; Q
} </FONT>
! N! y, }" I+ f2 [5 Q/ M. U# G+ u! ~/ C& |
</P>- K' Z( {2 N3 G8 k5 s: |
<P><FONT color=#ff0000>函数名: getdate </FONT>3 k9 Q, w9 R1 E$ o8 F
功 能: 取DOS日期 ^9 Y' W# Y1 |9 f
用 法: void getdate(struct *dateblk); 6 l# `$ p$ [/ m
程序例: </P>/ Z# c! m" R6 Y; ]+ C; ^
<P><FONT color=#0000ff>#include <DOS.H>( x( k7 h2 _3 |4 I9 W: k3 d% A
#include <STDIO.H></FONT></P>
* u! m2 w. e4 Q7 A<P><FONT color=#0000ff>int main(void)
% Y- _- ?! M i0 ~( N/ A# r' x2 B; w{
% C/ N2 j2 R* V5 b% b- Nstruct date d; </FONT></P>
r3 ?" F% P7 ?* o<P><FONT color=#0000ff>getdate(&d);
2 o* P4 C, ]) Z! Y; Tprintf("The current year is: %d\n",
; ^+ K8 S( }; P: n5 bd.da_year); 9 ]% \ l! R7 N( t5 v* m* g' Q
printf("The current day is: %d\n",
$ K6 R7 D9 X# ad.da_day);
5 B; n" u2 P3 s4 W# N! ~; sprintf("The current month is: %d\n",
. @, | X: K$ E- N. @d.da_mon); ' ]0 |+ U9 T/ F& r6 b6 r
return 0; 1 J/ k& d5 }; R4 @* g/ u
}
9 G o* ?# | |- ?9 p</FONT>
4 u1 I& l* J6 K; k. Y4 c8 Q" O</P>
9 R9 q" F7 p1 |( n0 M, G! r: d<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>0 a. x. S$ \, X8 `/ o$ X
功 能: 返回调色板定义结构 ( D C+ Z W. E* S; J1 ~
用 法: struct palettetype *far getdefaultpalette(void);
4 ~2 r# C5 n! K程序例: </P> ^. v6 t& A3 Q& {
<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 L% l- [9 T! u5 j/ f' ^4 `- T" X#include <STDLIB.H>
& q+ k, {+ T8 i& L0 t+ I% C#include <STDIO.H>
$ J( h4 H! P; L- h) l8 p#include <CONIO.H></FONT></P>1 K/ j5 Y4 m2 J4 N
<P><FONT color=#0000ff>int main(void)
5 L3 j# q' P! o, }7 }1 l# e{
4 Z. E) I, `0 {/* request auto detection */ / C1 x% _- _* K. D3 z' Z
int gdriver = DETECT, gmode, errorcode; 8 ]: N( P0 d ^* j; K) C
int i; </FONT></P># [$ f' x, i6 @$ p
<P><FONT color=#0000ff>/* structure for returning palette copy */ 5 j9 Z. l% ?8 C; ]3 t' G
struct palettetype far *pal=(void *) 0; </FONT></P>
@/ }8 ^3 A1 c' d<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ L& r- O' L9 z9 |9 b6 Z7 v! |
initgraph(&gdriver, &gmode, ""); </FONT></P>, Z) e/ p2 F+ q- k. z" y4 H; t
<P><FONT color=#0000ff>/* read result of initialization */ + H' D* [% N- o) a; `6 \/ y
errorcode = graphresult(); ' d; k7 u% V/ E
/* an error occurred */ 4 [$ z# |! `, Q9 E. K7 M" _ `
if (errorcode != grOk)
* g$ S: H3 c% _- u4 B: K: |& A{
" b: q7 _. l( M1 k Lprintf("Graphics error: %s\n",
' a- y* t: z# S! Fgrapherrormsg(errorcode));
* x* n6 {, y4 W" F' Aprintf("Press any key to halt:"); 9 R) \* k- j, x2 T- s4 C
getch(); + I. t/ ~5 {$ D3 w, g
/* terminate with an error code */ 0 l3 n$ R* X: E1 }9 m
exit(1); % Q# ]& d) q6 B; k$ N* e
} </FONT></P>) F0 P: t& b5 a9 Z, `
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>- x" y8 U( g9 f# B3 C* l- w2 D
<P><FONT color=#0000ff>/* return a pointer to the default palette */
7 ^. G! q0 H% Y8 Hpal = getdefaultpalette(); </FONT></P>9 [- a- L% [4 l" A B& t
<P><FONT color=#0000ff>for (i=0; i<16; i++)
$ X2 x$ s& e/ |{ + z" N+ r, }8 _; w: Q& l
printf("colors[%d] = %d\n", i,
& z6 u( K! Z8 {. _pal->colors); 1 `. _ K G1 b! m% B8 E
getch();
9 _% J; `7 F0 H# J4 ]; X} </FONT></P>: |0 F! \3 I9 m3 i- M& k
<P><FONT color=#0000ff>/* clean up */ 2 w! Z3 J4 P. M& r7 K }% N/ o- T
getch(); 2 S: C2 t" t4 f7 V
closegraph(); 8 o4 e U3 l/ V/ E C1 f+ x5 |
return 0; 4 M5 j u( _1 z
}
: o& F( P& X O8 S, S1 ?6 y, w</FONT> J. z# k1 p W; ]5 i" x
</P>
; q8 w- T' ~# `7 Y8 { A: W<P><FONT color=#ff0000>函数名: getdisk </FONT>
( x$ v) O. ]( Q3 _) k. Z功 能: 取当前磁盘驱动器号 % V+ t! s5 r. B* `) \7 R2 | T% Y
用 法: int getdisk(void);
, T5 _; L& _3 W. b. z4 E程序例: </P>
! C( r6 x+ A5 r! o' Q. d' u* `/ x! s<P><FONT color=#0000ff>#include <STDIO.H>3 u( c7 L8 j) I* ?+ z
#include <DIR.H></FONT></P>
+ b( a& a$ V1 I4 U<P><FONT color=#0000ff>int main(void) ' b, G: B' Z& `- J1 K
{
" z# A2 ?" A7 g; A6 e6 e. hint disk; </FONT></P>0 [, W6 F+ m* P3 Q, k7 s
<P><FONT color=#0000ff>disk = getdisk() + 'A';
! Z/ v7 Q7 A3 Z3 u$ d# Vprintf("The current drive is: %c\n",
- H3 L' M# f6 W. @) ldisk); . h& `& B) z$ r% Y7 N4 g8 ^5 K
return 0;
" M3 H( Q4 Q0 Q! _}
g% V2 f: l1 S' \. x0 T
0 V" }5 X+ @8 U }, w( o2 I</FONT>
! M& M; ]: Z' @# |- f8 k</P>" P4 M Y. Z/ m
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
8 F/ }+ i6 a' Y l功 能: 返回指向包含当前图形驱动程序名字的字符串指针 $ R& H6 F: h9 o" F6 E$ C7 u
用 法: char *getdrivename(void); : N1 U" S/ h/ z, A& Z6 a: |
程序例: </P>
; y2 m8 E; m; H5 {" r1 L<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 R" X& d0 x/ {( K9 L#include <STDLIB.H>2 v& E2 c! T( ?9 H T; U6 z/ q
#include <STDIO.H># G# ]+ E$ m+ ]) |* w& J1 J2 E: @) T
#include <CONIO.H></FONT></P> h2 u# ]$ [" @2 f
<P><FONT color=#0000ff>int main(void)
( q! }$ C3 m% u! a; m1 l6 j{
s# p$ B! z% F# L1 |$ S8 l/* request auto detection */
3 S; R7 r' e& R- T/ A. c2 S9 _int gdriver = DETECT, gmode, errorcode; </FONT></P>
" T# R6 B7 p% v' T7 J6 M2 C$ A# e! n<P><FONT color=#0000ff>/* stores the device driver name */ 1 |0 C$ S* M$ I( g
char *drivername; </FONT></P>* y$ m3 S' X3 f m' E
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , h* ?& D. u$ Z2 C/ t/ X6 |
initgraph(&gdriver, &gmode, ""); </FONT></P>% q* q% D7 i, `$ s0 z; `+ e
<P><FONT color=#0000ff>/* read result of initialization */
3 i6 w9 ^* E- R, H+ d6 J8 i0 |errorcode = graphresult();
- e8 \+ {0 D1 ^/* an error occurred */ " _- A9 a A& i) Y
if (errorcode != grOk)
/ {: K$ _5 @3 s( k* Q9 B{
) X+ Q. z$ B8 E9 D6 z# e9 u6 Kprintf("Graphics error: %s\n", ; |" R- f' Q$ j4 U
grapherrormsg(errorcode)); 5 n& I/ c0 `: m" X% r
printf("Press any key to halt:");
- N3 E3 X: Z+ S5 s# y# ^2 Vgetch(); : w5 N, F, _0 V" ?8 ]
/* terminate with an error code */
1 F3 M; O# z( I/ Uexit(1);
6 L9 b6 T4 T+ m5 j7 K% L( R} </FONT></P>7 d: g0 A/ X- b. q: j; m [ g
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>/ M6 K8 S* H% A* }. u2 f
<P><FONT color=#0000ff>/* get name of the device driver in use */
! g" m* _ l7 R. @* a# sdrivername = getdrivername(); </FONT></P>
- w! f0 x6 b- D& ?& E<P><FONT color=#0000ff>/* for centering text on the screen */ b. T: N3 y0 b2 P; _1 b- P. x
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
d! s, n* j. e5 @<P><FONT color=#0000ff>/* output the name of the driver */ 9 |: _) ^( U5 L, ?0 _7 @1 |
outtextxy(getmaxx() / 2, getmaxy() / 2,
0 K5 D- ]3 Y d1 ~- @( \( I% Cdrivername); </FONT></P>
% c6 F! d- h" {/ \# }# _$ e<P><FONT color=#0000ff>/* clean up */ 5 r0 ] [6 T! D1 g. }5 T' ]3 ^
getch(); ) d1 b" O1 v# g# a2 B# c
closegraph(); ; @* t# A1 |$ d7 t+ E/ g
return 0; 0 A- \: o8 R1 w3 O6 v5 s
}
5 J$ S: @0 \9 h</FONT><FONT color=#990000>" \9 r+ _" z; ^8 S: W
</FONT></P>4 h- o4 ]5 X& a! W% S: D
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>' Y( b/ J7 i( y3 e- j
<FONT color=#000000>功 能: 取磁盘传输地址
9 D4 ^8 ]8 v& t4 b8 ]# u用 法: char far *getdta(void);
: O% B6 R; y# N" ?9 i. h程序例: </FONT></FONT></P>
! Z& k3 ?; T# [0 s; j<P><FONT color=#0000ff>#include <DOS.H>2 a5 X2 |& i6 H" K
#include <STDIO.H></FONT></P>
2 z9 z4 E; z% ]% T1 |; W<P><FONT color=#0000ff>int main(void) 3 ? H* j% R1 F
{ # F4 {5 v: ]3 _* x
char far *dta; </FONT></P># D* [- J! N1 Z9 |9 g* z
<P><FONT color=#0000ff>dta = getdta(); + x7 @6 W M6 M/ f( V
printf("The current disk transfer \ ' A0 a0 f8 e2 W$ V) `
address is: %Fp\n", dta);
! o. N+ d2 `2 |/ M/ k% G. Wreturn 0; : H5 b( [, l0 G( C, _: P3 {
} $ V2 ]) q) ?% g4 Q
</FONT><FONT color=#990000>
4 b3 D0 @% }! N$ I7 I0 D& I$ G* \" I, f</FONT></P>
8 X. T+ F( q( N<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>8 }: ^" {3 r0 M3 r9 o1 M
<FONT color=#000000>功 能: 从环境中取字符串
" m- f% @( z) F$ Q用 法: char *getenv(char *envvar); : Y( k0 O0 c( u$ t: B9 z9 ^+ a
程序例: </FONT></FONT></P>* @, i: S. q6 P/ g
<P><FONT color=#0000ff>#include <STDLIB.H>
$ Y( ^, ]4 ?) f9 ?#include <STDIO.H>+ X2 x) p4 i2 f/ p3 O! `
</FONT></P>
+ m. o) b! i# D- _3 E3 r<P><FONT color=#0000ff>int main(void) : {7 U' Y! }2 w3 y& ?( `
{
# F6 f1 ]9 {" n- @char *s; </FONT></P>
: m) J: N& i! D4 \) y; |6 \2 g<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
1 C# f1 E: ^* x9 O. C5 Xprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>6 `( H9 V; n4 ~* @
<P><FONT color=#0000ff>return 0;
6 ? D" H* ?- @* U" s: p4 p4 w8 y+ F} </FONT><FONT color=#990000>$ m3 a# n& F% q* l2 o
6 d) X$ g" V! f# N T8 R3 ~. N
, c6 a/ `3 b! \
</FONT></P>
/ d3 A: \! X3 s. |7 V% z: n<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>: g) Y/ q+ O8 \
功 能: 取文件分配表信息 0 H/ g( ?- k7 `4 }8 c+ M2 M+ I0 L) [
用 法: void getfat(int drive, struct fatinfo *fatblkp);
4 E3 n* y3 ~% K: ~# p d程序例: </P>9 f4 h7 _3 Z3 r" _
<P><FONT color=#0000ff>#include <STDIO.H>
' `: I9 r, s8 Z; z v7 O S#include <DOS.H></FONT></P>! t, `% s7 x3 N0 L7 U
<P><FONT color=#0000ff>int main(void)
6 W4 a$ {6 U+ [( C4 S1 r7 ~7 m- @{ 9 \- [) ^/ \7 G
struct fatinfo diskinfo;
3 }" H& ?) w* @+ Q6 e5 Aint flag = 0; </FONT></P>+ j4 J1 k4 a9 e# h. D/ H
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); : J$ X y5 n) S, M) E! ?( o6 `
getchar(); </FONT></P>( ?( R* B$ ^" b$ e- A2 F B1 ~% s
<P><FONT color=#0000ff>getfat(1, &diskinfo);
w" R( u$ S5 F8 ?6 @! o) p% N/* get drive information */ </FONT></P>- ?8 o, f: o9 A S! }: D# d- }
<P><FONT color=#0000ff>printf("\nDrive A: is ");
$ B) Z! q' M4 W' E# x6 Xswitch((unsigned char) diskinfo.fi_fatid)
& @/ |" b/ d$ o6 `+ i1 N# I; }$ Q{ 5 ?2 f# P3 C: @" e# c
case 0xFD: P$ T/ p6 \7 A9 W, F
printf("360K low density\n"); 5 D% ~) _% M& v0 t U$ C% O2 l3 d
break; </FONT></P># _! [+ s- A$ }- z
<P><FONT color=#0000ff>case 0xF9:
6 M0 s6 r% b! I1 cprintf("1.2 Meg high density\n");
' D) k5 j) v5 a8 u& f& Gbreak; </FONT></P>2 l9 ]; P6 t5 S8 O5 J% Y
<P><FONT color=#0000ff>default: 5 j: ? j' q# I' C, p& U
printf("unformatted\n"); j7 a/ h! u# l' H
flag = 1;
5 G! S, H3 L& j. a, [* z1 k) z6 L} </FONT></P>
I+ H3 d9 f' S5 t3 S<P><FONT color=#0000ff>if (!flag) 0 B. K) K+ C5 _
{ ]. A0 E% b i0 V; M* Q
printf(" sectors per cluster %5d\n",
' x0 r ?2 q, R$ Gdiskinfo.fi_sclus);
2 g( ~, E: |! A: _4 Bprintf(" number of clusters %5d\n", * }' g# P \$ [+ v: p4 M
diskinfo.fi_nclus); 4 B! s) W8 ]0 V0 I: Z! L
printf(" bytes per sector %5d\n", $ X1 P4 M2 H. v+ E! M+ w4 ~
diskinfo.fi_bysec); % X- ^" O' {5 L, m# Q
} </FONT></P>
( C& {6 r- ~9 k* r, D4 N7 E/ a<P><FONT color=#0000ff>return 0; 6 ]) Y; f( z9 q1 k
}
1 @/ c' P5 j c3 r</FONT>5 @: {! y$ v( Q3 e, q$ g( w+ v# e
</P>1 ^& ], i- b$ [6 Q& K
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>% p+ Q# S9 U' \# k* G
功 能: 将用户定义的填充模式拷贝到内存中
6 M* b- O# |& R( q! X3 r, b2 a用 法: void far getfillpattern(char far *upattern);
1 z9 w i, {% Y) {6 q( ?1 i程序例: </P>
* f1 Z+ M+ o- m) p! ~" s5 T5 f<P><FONT color=#0000ff>#include <GRAPHICS.H>9 g. _. L2 @( N: V9 c* L8 W! ^, o
#include <STDLIB.H>
& O9 N: P) F, F' [#include <STDIO.H>
5 @5 P+ G4 Y- S#include <CONIO.H></FONT></P>
K2 W" H( }9 p<P><FONT color=#0000ff>int main(void) + ^2 A. E" J/ s: t. @' h9 e
{
2 e0 D/ u3 t; y1 W5 B! L/* request auto detection */
1 e- P& J2 X8 y$ l2 Jint gdriver = DETECT, gmode, errorcode;
% E. t1 _% {% a3 ]int maxx, maxy; / e1 F, f4 M F- e k
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>8 q$ t( Z" b) {8 W+ q: D( B! o( H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' G8 X& k2 s7 J0 x
initgraph(&gdriver, &gmode, ""); </FONT></P>* ~) Y* b1 W) N! o6 Y# E& w
<P><FONT color=#0000ff>/* read result of initialization */ 9 X& p# @$ B& L% j* _
errorcode = graphresult();
( q# V$ f9 Y+ _" x: ]if (errorcode != grOk) /* an error occurred */ 4 [5 f) }, o" f* Z7 d: q: b" ?
{ + y( R! ~0 e: e0 ?* T+ u, g. L
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ n2 n* S- h! w* s2 {printf("Press any key to halt:"); k, s) v2 B/ X
getch();
, w. N. J" c9 U& u& w9 Sexit(1); /* terminate with an error code */ $ t" |2 x7 X& D2 `9 l+ I( j
} </FONT></P>) E6 n% Y# v) q) S
<P><FONT color=#0000ff>maxx = getmaxx(); 0 u+ m5 h# P5 d# ^8 n3 X9 | J- V$ r
maxy = getmaxy();
" T: ^1 _9 \1 O& b0 P2 lsetcolor(getmaxcolor()); </FONT></P>
/ V- e- q! I. z% a1 ]6 ~' I<P><FONT color=#0000ff>/* select a user defined fill pattern */
1 {4 W B$ `) o& ~/ w Z6 v/ Psetfillpattern(pattern, getmaxcolor()); </FONT></P>7 b6 z* d/ j- ]6 H j
<P><FONT color=#0000ff>/* fill the screen with the pattern */
7 J2 l0 s- B8 y5 ~9 B; nbar(0, 0, maxx, maxy); </FONT></P># T4 r2 O. h( D7 ?0 v
<P><FONT color=#0000ff>getch(); </FONT></P>
1 @' N, m3 Z% g1 G<P><FONT color=#0000ff>/* get the current user defined fill pattern */ ; a+ N: ^) M0 S
getfillpattern(pattern); </FONT></P> f) X1 h6 a! \5 h5 I4 Y5 B
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
T& f2 d) L% C* g- ]pattern[4] -= 1;
0 d T& e" b; _pattern[5] -= 3; : e8 ?6 {$ l z- E7 q5 T! J
pattern[6] += 3;
3 a+ b- @: M5 wpattern[7] -= 4; </FONT></P> n& U( _; `. B( D0 q( m W9 }* w
<P><FONT color=#0000ff>/* select our new pattern */ 3 H: M# Z" W+ p
setfillpattern(pattern, getmaxcolor()); </FONT></P>
/ o2 _& O8 m% e) Z0 g! e! }<P><FONT color=#0000ff>/* fill the screen with the new pattern */ ' w6 N3 h: t) m2 Z* x' j
bar(0, 0, maxx, maxy); </FONT></P>
0 M7 P8 C- ?. O+ L1 q<P><FONT color=#0000ff>/* clean up */
- g0 J" o: ^6 x/ ]6 G( D) S9 `getch(); 0 O! W& C8 h: w V
closegraph(); & K( Z* f# r4 a& L
return 0; ( D0 \% o! s! H7 x$ r' C9 f
} 5 M2 T7 k. s2 Y/ t' Y
</FONT>
1 w2 t2 A9 r/ u& b9 ^: M9 |% r</P>$ V# e: i, R# X( U: ?! z7 [5 k
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
* s1 C8 r, \9 a6 q# V功 能: 取得有关当前填充模式和填充颜色的信息 4 T( B Z, [$ [0 K
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 1 i8 O9 {8 P1 s1 L' v
程序例: </P>
" b5 \9 E" q1 y# P9 \$ W) `<P><FONT color=#0000ff>#include <GRAPHICS.H>7 {4 ~4 M3 _/ H, U8 ^( _ a
#include <STDLIB.H>' p0 m P K3 y; R1 U" ^. o1 j
#include <STDIO.H>: Q9 D8 X& ~. Y, q" |1 Z
#include <CONIO.H></FONT></P>
# i7 T/ n4 R W/ i3 {0 N<P><FONT color=#0000ff>/ the names of the fill styles supported */
F* d u5 a: S% l @6 }8 Q3 cchar *fname[] = { "EMPTY_FILL",
' d$ H+ V: r$ Q" F; j"SOLID_FILL", ; ^: r* \- I# w
"LINE_FILL",
7 E1 Y1 {4 C6 i. I% s" D l# C2 M"LTSLASH_FILL", % |9 {& q% ]% D# e
"SLASH_FILL", 2 B5 Y. r4 `1 d! E2 w3 x
"BKSLASH_FILL", ! I6 H& L( l1 Z# _+ _9 u
"LTBKSLASH_FILL",
; k/ z( o1 w2 y$ {1 I7 E6 }: v"HATCH_FILL",
; ]- [1 p5 R5 {% \8 R"XHATCH_FILL", & [) Y( w3 O2 b. f) M
"INTERLEAVE_FILL",
( S$ f% z3 S1 e! p( E& C, N"WIDE_DOT_FILL",
( \ Y" h$ D+ n( H"CLOSE_DOT_FILL",
?# n9 X( ~, ?5 A! ~% M5 `"USER_FILL" + Y- a M& K2 x5 D' [+ f
}; </FONT></P>
& Z! ?% x9 `7 z( P2 b1 k<P><FONT color=#0000ff>int main(void) " c/ I2 |' A7 j8 p- |2 l
{ ! Q/ Y4 w Q9 q, W/ @: ]
/* request auto detection */
$ v$ @; V/ B- S/ Sint gdriver = DETECT, gmode, errorcode; # a c- ?5 w( N; u; C% L
struct fillsettingstype fillinfo; }, u3 ]$ u) G) L/ C; w1 B* G
int midx, midy; * E' D$ _6 `; J7 A: r8 }) Y
char patstr[40], colstr[40]; </FONT></P>
) n/ {- { | o6 _# P+ t8 o/ w8 d) G<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 ?. ?1 e3 P$ ~( P3 ~. Linitgraph(&gdriver, &gmode, ""); </FONT></P>
$ {2 s( P9 O4 m% O% ?<P><FONT color=#0000ff>/* read result of initialization */ - x+ n* a4 t, i2 U
errorcode = graphresult();
, {1 k" A2 @0 O. gif (errorcode != grOk) /* an error occurred */
. d- B1 z8 l2 G% X{ 2 d! m, a6 A' r6 U. G+ U
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# K7 n( U5 ]1 l1 e$ U1 Kprintf("Press any key to halt:");
# T/ Q% g6 d' R! ^3 ~. V# O; ogetch();
7 Q9 {( J# C3 wexit(1); /* terminate with an error code */ : v- }0 M9 O1 F3 I: @7 U' c
} </FONT></P>
& H5 X# M {1 M Z I<P><FONT color=#0000ff>midx = getmaxx() / 2;
# @: P- |+ ]+ c1 _# o1 {/ w5 ~% Fmidy = getmaxy() / 2; </FONT></P>
5 i8 l; ]/ j' f' F<P><FONT color=#0000ff>/* get information about current fill pattern and color */ + T, Z' w* E+ {5 w; p
getfillsettings(&fillinfo); </FONT></P>
2 P9 S" ^' P. f' q) U$ @<P><FONT color=#0000ff>/* convert fill information into strings */ 1 i# F5 R* [* j
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
0 ~- e. p* i6 Y* n+ lsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
( m8 ]5 D8 n) k; \: B4 W( p/ i<P><FONT color=#0000ff>/* display the information */ 9 A9 b2 S; c: B0 V! o6 g! a# Y7 F9 q( k
settextjustify(CENTER_TEXT, CENTER_TEXT);
. u: y6 g: p" Pouttextxy(midx, midy, patstr);
/ d1 h1 }( ^& Zouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
& h) R" Z" Z- h<P><FONT color=#0000ff>/* clean up */ $ G5 _5 k3 L. N; E) V5 l
getch();
- y( J: [4 J/ K' oclosegraph();
, {, l6 z' Y! w# @) a" l6 M/ Freturn 0; * x% Y/ ~1 j1 A* ?2 N; b( }
}
9 R, N* R) s, I& w</FONT> P, m$ F) \7 J/ N/ B/ u; z
* W; r4 n) |7 K# @- r3 C2 E" O, U</P>" I' v; r4 P* e/ S$ Y) U/ G3 {
<P><FONT color=#ff0000>函数名: getftime </FONT>
. t# a0 c* s3 q! Y5 K( f功 能: 取文件日期和时间
6 b" c. c5 `6 J用 法: int getftime(int handle, struct ftime *ftimep);
" X7 h! r: G* i; C+ G5 v/ c程序例: </P>
6 a! ~: U$ o' N3 t<P><FONT color=#0000ff>#include <STDIO.H>2 D. C2 G+ b. I, @
#include <IO.H></FONT></P>% s M7 q5 |7 y. B% b8 w
<P><FONT color=#0000ff>int main(void) ( g9 \; X0 `8 `5 h' C9 d
{ - P0 ^4 y$ V2 _) F
FILE *stream;
7 x, o6 V5 Y# [3 \& y/ u# kstruct ftime ft; </FONT></P>
' C- P( Q0 S9 j8 ?<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", # s$ j4 d; T' |
"wt")) == NULL) ) [! [* G8 v7 m3 m' g9 S P: f
{ 5 F, d* j& v+ J( b- Q
fprintf(stderr,
6 t6 @ c) c8 V0 l2 l"Cannot open output file.\n");
8 h, Y: b) [1 D5 p+ k7 B- Ureturn 1;
h! M8 C% j8 A" S} : @7 R: K! _+ E. i
getftime(fileno(stream), &ft); 3 }' i: t' M* Y
printf("File time: %u:%u:%u\n",
9 Q$ c8 j! I+ b5 Eft.ft_hour, ft.ft_min, 0 y$ R- E& h2 Z7 Y4 ]/ p
ft.ft_tsec * 2);
" K# O! W# I( `4 b( P Wprintf("File date: %u/%u/%u\n", : H8 }0 L/ L% M+ K
ft.ft_month, ft.ft_day, & J9 U- d* p( h# u& l5 ]. B6 s9 o
ft.ft_year+1980); ( s; I1 m7 K& T
fclose(stream); % ~( g% S& _1 l' }
return 0;
' e$ f' k. l E1 J1 k2 `% l' a+ } f} & o2 h8 T; |9 ]( U S
</FONT>
$ p4 s, x% q; p& ^, i" E% o0 I$ [+ l
</P>* Y$ w% C( N: Q. X) b: D3 ^8 k
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
/ P* h. P5 d: v: E7 j功 能: 返回当前图形模式 * g3 N8 e! b$ j( a' Y9 I9 z' R I
用 法: int far getgraphmode(void);
7 k# d$ K X! c7 K. h程序例: </P>8 H9 A3 v0 F1 @+ x, W. o
<P><FONT color=#0000ff>#include <GRAPHICS.H>% P2 Z8 J4 D4 N
#include <STDLIB.H>
5 l9 t; ]! c% J4 S% C: m* \; I2 R#include <STDIO.H>4 d& w' m, B3 ?$ i; M1 F* E: N
#include <CONIO.H></FONT></P>
1 v& O: u- \ O<P><FONT color=#0000ff>int main(void) ; u. a: v$ w- B! z
{
/ W! J& Z. G! W1 ]* V+ ?/* request auto detection */
R8 c# L; O5 hint gdriver = DETECT, gmode, errorcode; & u8 i8 a) Y" n/ k
int midx, midy, mode;
& k; ]: g! O+ p4 k6 ]char numname[80], modename[80]; </FONT></P>; X& D3 F, V, J; C6 H8 d
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 c' I; U" ?& k5 Q/ z$ j& _; jinitgraph(&gdriver, &gmode, ""); </FONT></P>% I& T% @8 h4 g" D. o
<P><FONT color=#0000ff>/* read result of initialization */
! k' i% v% N# c# yerrorcode = graphresult(); ! @% i' V( F6 n. e2 e' L7 n! c
/* an error occurred */ 1 D# V, O3 G/ {3 N
if (errorcode != grOk) . J+ ~6 V- U; J7 j/ S+ v
{
9 f6 E5 g" o9 S) e8 K( C; r1 ^printf("Graphics error: %s\n", " Y' z# {7 @0 Z4 B0 U3 V
grapherrormsg(errorcode)); * S; F; |" b. S' ]7 u; P/ i
printf("Press any key to halt:");
+ g; D6 F" D9 W" Lgetch(); - B+ Z0 H; e" q0 ~
/* terminate with an error code */
a' t9 I- C7 K1 ]exit(1); " k z2 ? {/ z+ }4 s' D; u8 B, u9 r T8 I
} </FONT></P>
" Y4 t- h7 I' ? I* X<P><FONT color=#0000ff>midx = getmaxx() / 2; ^3 y! W3 u4 |3 P# j A# Q
midy = getmaxy() / 2; </FONT></P>
: z$ q, v1 `$ j. H/ F5 x& g<P><FONT color=#0000ff>/* get mode number and name strings */ 0 @& `( ~" K, Y7 u$ }1 H, z0 x
mode = getgraphmode(); ' A2 [' |0 I( T7 m) m# r
sprintf(numname,
+ ~# q! l% T H( V0 f2 j" ?9 o"%d is the current mode number.",
4 E! ?% c3 {1 f/ Dmode);
7 @ X( ]- c B3 Hsprintf(modename,
* E) e, i: m# a. v- l7 C" Z4 Z"%s is the current graphics mode", 1 p/ K, r- r7 D; F! z
getmodename(mode)); </FONT></P>- i/ l2 Q: s9 _. |2 Y
<P><FONT color=#0000ff>/* display the information */
5 G! V9 e" R3 B+ nsettextjustify(CENTER_TEXT, CENTER_TEXT);
0 [# C8 z; V1 ~5 W6 z6 d1 \outtextxy(midx, midy, numname);
( m+ R( Z/ @" ~0 R. F, N$ zouttextxy(midx, midy+2*textheight("W"),
1 d% [3 [" H. K! imodename); </FONT></P>* D$ \ Z& I& O/ N! ?
<P><FONT color=#0000ff>/* clean up */ 4 I4 W) g- u- b7 N! Y/ _
getch();
# F* W& J. U5 b9 q Xclosegraph(); 8 H2 }& `& Z* h" \. t* h0 G
return 0;
. T4 o+ Z6 ~: B; Y d5 } @} </FONT>3 @1 U+ u0 d. L& B
& E, q# O: J5 J/ Y: f</P>
& R$ v- w5 P! }) P+ Y0 P+ E, _6 y7 T<P><FONT color=#ff0000>函数名: getftime </FONT>+ ~- U# X3 K1 P8 l& H
功 能: 取文件日期和时间
l/ l' W' L* F9 F1 W0 p用 法: int getftime(int handle, struct ftime *ftimep);
) S* C( G3 R6 ^7 ^* z程序例: </P>8 S% [: O7 \ ?$ A0 C9 S/ _ i' ]
<P><FONT color=#0000ff>#include <STDIO.H>
0 l6 `8 @8 Q- A7 G#include <IO.H></FONT></P>
5 ]) C. |$ z/ H, L<P><FONT color=#0000ff>int main(void) 3 Q% l" Y$ f- H5 D; D
{ . ~6 k: r3 d3 `6 S, ?( I
FILE *stream;
8 j4 {$ f$ [" A( C$ o1 E9 {7 J6 hstruct ftime ft; </FONT></P>
1 I4 K" c8 k" j6 V. m<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 4 c' g/ x6 Y/ o, B& X0 U
"wt")) == NULL)
4 t6 D# g& K+ x! t5 j4 P{
2 O6 X' Q4 w; h: Z% ^8 e( { Gfprintf(stderr, y' t' @/ z) _$ y4 o# t9 g, r, _
"Cannot open output file.\n"); ! e: ` ]% F- P: w1 M* m* A- \( n8 d5 y
return 1;
4 x9 M3 b$ `+ k, d& C}
3 a* x1 q1 t& i4 v4 Lgetftime(fileno(stream), &ft);
+ l# ^( H( I0 e! L( R0 yprintf("File time: %u:%u:%u\n", 2 k$ j! V! f+ ~! o
ft.ft_hour, ft.ft_min,
+ [2 a4 X7 J' ?, Rft.ft_tsec * 2); 5 j2 E/ k1 _) M% C
printf("File date: %u/%u/%u\n",
1 y% d1 A4 y- P1 s+ ` Wft.ft_month, ft.ft_day,
8 t# u' u5 B6 V3 E0 Bft.ft_year+1980);
2 v& r1 V# e1 N' N ~fclose(stream);
' g u' s- s4 Qreturn 0; # W/ c3 ?7 ?% l
} </FONT>
# K* a6 x3 ?- { o. m5 u6 }7 N
$ A: k E* H3 U' }: l# O1 i* z/ r$ ^) B! m% q/ K, f2 { C, h
</P>
: x( [9 m2 `. k2 U3 ~# v. R5 ~<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
2 U0 G# t8 G: f功 能: 返回当前图形模式
5 S7 K, I+ G7 F+ u/ d( ?* ?用 法: int far getgraphmode(void); 9 a1 q+ B# M& ~ i
程序例: </P>5 u; L8 S, P4 z* I2 L/ Z
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 u. R4 u. @6 V" W0 Q2 U4 ]5 t" m#include <STDLIB.H>
8 O+ b, r- T" r4 a#include <STDIO.H>
u# O- m$ e, v$ r# f#include <CONIO.H></FONT></P>
6 k! ^4 M& L) B5 `' w+ S<P><FONT color=#0000ff>int main(void)
8 b8 a; T+ B9 K6 ^" o{
, }/ V2 {2 f0 Q; F/ g9 Y' ^/* request auto detection */
/ t# F' l6 U* hint gdriver = DETECT, gmode, errorcode;
, S7 M1 v& |# t; s3 t) L: A* Cint midx, midy, mode; . O( f& Q/ p7 s. L' ?' g/ d3 e
char numname[80], modename[80]; </FONT></P>
" [/ H) i- y+ H<P><FONT color=#0000ff>/* initialize graphics and local variables */ # [, h6 F1 w0 H- Z4 _
initgraph(&gdriver, &gmode, ""); </FONT></P>
' B6 x- L J1 u4 K4 d<P><FONT color=#0000ff>/* read result of initialization */ " m5 S6 W7 [" [7 Y+ G) r8 T$ T
errorcode = graphresult(); 2 l8 D& K/ n. `( z" \2 `! o
/* an error occurred */ 1 @2 U3 \( k: p9 f, O
if (errorcode != grOk)
0 X7 R, n* I3 y6 [{
* K# C$ n- O" f& t, O7 xprintf("Graphics error: %s\n",
9 U, s5 G8 B! a5 Wgrapherrormsg(errorcode));
( E: P* M" ?( U3 n0 l$ \9 g, Gprintf("Press any key to halt:");
2 ]8 p4 ?9 W. e2 e6 @ a5 ]( Zgetch(); # ?. d |7 y9 Q# J0 a6 B
/* terminate with an error code */ & t* z5 y) k3 Q( u2 c; V9 g
exit(1);
+ W( A2 r# q5 K* g6 c} </FONT></P>3 S" j! s0 B0 \; y
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) C; b% t/ Z5 Zmidy = getmaxy() / 2; </FONT></P>8 `% c6 A! k, l- {; @, \3 U. F0 b
<P><FONT color=#0000ff>/* get mode number and name strings */
1 |5 I' O! T8 v% Xmode = getgraphmode();
% m% l8 T$ v& ]5 s [sprintf(numname,
+ Z1 N/ d9 @) o: _"%d is the current mode number.", 6 |* k; ^5 ~4 C8 X
mode); 8 }+ k/ u; L9 t8 D. J" d
sprintf(modename, * A, v' G2 R$ h* ?% A) u
"%s is the current graphics mode",
. A% j3 C \8 i0 |7 }" ?! K/ Ngetmodename(mode)); </FONT></P>
% t$ R/ f, c4 h ^) i4 P. Y H<P><FONT color=#0000ff>/* display the information */
9 r% q$ b* P" [8 z8 V9 c* psettextjustify(CENTER_TEXT, CENTER_TEXT);
: h4 Y t# J" ^; T- d, Youttextxy(midx, midy, numname); 5 V- q' b/ M2 Y6 Y# h
outtextxy(midx, midy+2*textheight("W"), 1 l# B( e9 ?: B( i+ L& G8 m
modename); </FONT></P>1 u2 c3 A" s- c: J
<P><FONT color=#0000ff>/* clean up */ 7 u2 l) u5 A" k1 e7 I
getch();
' r( P6 x M/ [+ M Pclosegraph();
3 T8 I9 c+ ^& D+ n+ r: V5 X0 zreturn 0;
- }: G1 y/ r& g8 a1 e8 I}
4 E! g% b+ J2 j( P! j</FONT>% o5 e& @# b7 }5 A
</P>( I$ L. A1 o8 Z1 \
<P><FONT color=#ff0000>函数名: getimage </FONT>
$ T5 ?$ J' i& Y9 l# G/ G/ ~' z功 能: 将指定区域的一个位图存到主存中 # C; m; j) W6 P3 ]8 [
用 法: void far getimage(int left, int top, int right, int bottom,
) [ \ g3 C9 v; Z F7 Y0 o' v/ Z4 uvoid far *bitmap); & K, n" {8 }6 ~' l/ R
程序例: </P>
8 A2 p4 I( ?) g- z8 C<P><FONT color=#0000ff>#include <GRAPHICS.H>6 c4 n1 s5 y5 w0 N ^
#include <STDLIB.H>7 G! i( G" `; y0 x; ]0 m
#include <STDIO.H>
$ z/ o7 I3 N( t) S: w+ p. h#include <CONIO.H>) Q" h2 K5 Y$ d, Y- O% O
#include <ALLOC.H></FONT></P>
5 Y/ s9 Z2 L* v0 s- P$ i. { }<P><FONT color=#0000ff>void save_screen(void far *buf[4]); ~: h/ a1 \* j9 O
void restore_screen(void far *buf[4]); </FONT></P># b5 Z- h: G' G0 q4 F) H
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>3 W s4 L+ O. y! B% R7 N: S
<P><FONT color=#0000ff>int main(void)
, l3 y- A( u; z3 l* h& }9 D{ 1 C+ ]% d }7 Z4 K5 E
int gdriver=DETECT, gmode, errorcode;
" w; [2 G2 Y5 wvoid far *ptr[4]; </FONT></P>
/ o6 t/ l$ B. z+ i<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ 3 Q, u4 H X9 A+ n1 Z, @2 m; H
initgraph(&gdriver, &gmode, "");
7 G% t* [) @. s7 Q- z! N! |7 uerrorcode = graphresult(); /* check for any errors */ + }' _# ~) t# l5 a
if (errorcode != grOk)
2 o2 q0 Y6 @9 T8 j9 Q% G{ 2 F1 z' l5 W0 w# i9 P2 E+ J' Z# o- P
printf("Graphics error: %s\n", grapherrormsg(errorcode));
; A3 R: q; F3 k% b/ I. Dprintf("Press any key to halt:");
9 \; |" `$ O. A' R* Zgetch(); & Z) E! J6 \/ B- l, b( v2 b' A
exit(1);
+ b+ _+ H: l/ {3 g% p% [} 7 {6 `; _$ C# l9 {
maxx = getmaxx();
2 R7 h& U+ q" h7 f' F. e Vmaxy = getmaxy(); </FONT></P>( _* L; W; U% T0 C/ I/ ?0 r
<P><FONT color=#0000ff>/* draw an image on the screen */ ' |) m$ G; q# U
rectangle(0, 0, maxx, maxy); 8 ?( O' \* N4 K1 u
line(0, 0, maxx, maxy); 2 G: V0 E2 \ l3 X1 J
line(0, maxy, maxx, 0); </FONT></P>
8 u1 z( ^% a% @% ?<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ ' _) t6 \5 P$ j) t( y
getch(); /* pause screen */
6 m. L, B# \6 J! j+ Z- a* ucleardevice(); /* clear screen */ ' C. k8 s: t. ?
restore_screen(ptr); /* restore the screen */
4 ?. |" s$ ]$ ^; Egetch(); /* pause screen */ </FONT></P>% K# @7 J/ Y( f! K$ f* I
<P><FONT color=#0000ff>closegraph(); $ x7 b2 x: ]! Q! q* {5 ?/ Z/ n0 S" A9 V
return 0;
. H( {# T' r$ p} </FONT></P>2 A g% v. h e2 m+ u( s, N4 }
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
; K! i- O* C: r0 @{ 6 u2 `- S2 C5 \/ R+ [- j: t# I
unsigned size; 4 O- y, j4 k: J0 L2 U, O+ Y
int ystart=0, yend, yincr, block; </FONT></P>
% }6 S' b! @! s8 d& z1 Y( w<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
! l9 L m3 o, P+ k) h: P9 Myend = yincr; ( O5 l' W" W' U/ o" H
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>6 j0 Q1 N. O: W4 e& Q$ y4 ^
<P><FONT color=#0000ff>for (block=0; block<=3; block++) : a5 P. K: d" d
{
1 c( P8 V$ Z, E' Y& B, E' H: j- O: r$ Dif ((buf[block] = farmalloc(size)) == NULL) 7 ~5 A4 r7 z9 |2 L5 W; l' l2 W
{ 6 |4 L& d# W) r9 x, d1 e. R
closegraph();
* B% Q% y$ L+ M5 r* mprintf("Error: not enough heap space in save_screen().\n"); 5 \8 ^4 ^0 o6 U7 ?5 M
exit(1);
! V2 ]8 w+ V7 c} </FONT></P>/ R# v- g( k$ v
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); ) V* o9 g: a2 G& T; b6 [5 E% ~) X
ystart = yend + 1; 7 B7 J& S; l. v2 ]: k; Q
yend += yincr + 1;
2 r, O4 E( z5 F, Q} 9 Q' e" D+ C' L5 I# z1 }5 Y( \8 _
} </FONT></P>' \& U1 ^5 z5 }7 v# ~0 w- f7 ^& y
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
" f9 I6 o- f, ^" B{
% g7 U* ^: r4 I1 U5 Q+ junsigned size;
2 I0 N5 C/ d8 J" [# Q7 `int ystart=0, yend, yincr, block; </FONT></P>
9 U' ]3 q" o" l( N, w. H% [3 B<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
. q3 f5 U& S) D hyend = yincr;
4 w0 w3 z) c5 J: g- a2 Hsize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
) D: [4 Z x* }& `. m# w<P><FONT color=#0000ff>for (block=0; block<=3; block++) / ~7 l0 a4 u% y! _: W
{
+ i. q3 K7 F* [( \0 y# `* }if ((buf[block] = farmalloc(size)) == NULL) : W! _4 `* [7 z; m% _
{
+ J' U7 N: O% ~$ Yclosegraph();
* [; E2 G+ y; y/ J1 c3 N8 H# _printf("Error: not enough heap space in save_screen().\n");
, C5 E Q/ C7 F5 ?8 _+ Bexit(1);
7 g; J! Q" z) i# p9 A4 |} </FONT></P>& R: ^( A4 f1 F! Q' E
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); ' q5 I, [* ?* O+ h
ystart = yend + 1; 5 j, }; R$ |- j1 k; m0 U
yend += yincr + 1;
X% A7 W4 m' Q}
7 L% Q, n' X& q9 O6 S4 D} </FONT></P>
% z/ }/ t9 A, x! v0 n<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) : d. q s' _% F
{ L# o+ {9 z) V j7 ~
int ystart=0, yend, yincr, block; </FONT></P>3 d! v, L/ e' s2 r& b
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
7 @/ n- [/ M% m9 O \- Uyend = yincr; </FONT></P>, j+ G" W* f; y/ J1 U4 c: v
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
% N, D1 s. o8 I{
; }0 S4 Y2 \/ E9 u8 N" z4 tputimage(0, ystart, buf[block], COPY_PUT);
: ~8 g; p* b Hfarfree(buf[block]);
: l: X% C( r7 \* H: G" }ystart = yend + 1; 4 {$ W+ W3 J- y/ ?2 F0 W- U: y
yend += yincr + 1;
* e G2 w! K! U$ M} - D. i s: O9 p% y0 C
} </FONT>: @" B& R6 q1 A d9 c
<FONT color=#ff0000>
0 O5 V0 Y4 e8 \& R' f8 x</FONT></P>
2 F, ~% H) s7 W, M7 u. x<P><FONT color=#ff0000>函数名: getlinesettings </FONT>; D. S" W( k; H2 q+ j# `
功 能: 取当前线型、模式和宽度 * f6 [, h3 r0 m8 O' A1 j
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
: d7 E8 G, I( G7 z; V5 D* i R程序例: </P>
1 ]' f+ K9 s0 _0 u+ f<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ Y5 K2 _+ \( e# f#include <STDLIB.H>
! w1 P' X& T+ s, e/ b& C#include <STDIO.H>. z7 r# T R4 S
#include <CONIO.H></FONT></P>
' `$ t- G$ k7 e- M5 S<P><FONT color=#0000ff>/* the names of the line styles supported */ 4 L: A% H* d ~# ?! N
char *lname[] = { "SOLID_LINE",
. D3 R" q; B: |& q7 V' C1 z; m/ R6 S"DOTTED_LINE", ) ~8 @* N! G- F1 y# i: r' x
"CENTER_LINE", 9 j. e9 g: o7 a: l6 @" b
"DASHED_LINE",
5 ?, t* Z% i) ^# Q4 i% K"USERBIT_LINE"
. t2 x* y8 r2 f4 ^% k, t}; </FONT></P>, e+ K, [, O7 T# [! _0 J
<P><FONT color=#0000ff>int main(void)
0 d; J7 g2 f0 f{ 9 H/ r7 x8 y# m
/* request auto detection */ ' v$ Z' }9 |. H( N: ]& {
int gdriver = DETECT, gmode, errorcode; 8 D4 ~5 i5 }# V( Z
struct linesettingstype lineinfo; 2 S: u+ U: C( `' a% e
int midx, midy;
$ S. {) z r, j1 }# pchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>! L- q3 b: S' ~2 d" v! [
<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 @) J: ^2 z7 Tinitgraph(&gdriver, &gmode, ""); </FONT></P>
# K! U3 o- q3 W, i2 `* I<P><FONT color=#0000ff>/* read result of initialization */
^2 Q4 `& x B7 s. S1 }) q Terrorcode = graphresult();
2 p1 ` D* v! Iif (errorcode != grOk) /* an error occurred */
# k+ ~/ {" p- i3 B{
: R+ A; X# d+ ]( H+ `+ vprintf("Graphics error: %s\n", grapherrormsg(errorcode)); - A3 N ~: K1 {' V
printf("Press any key to halt:"); 8 N+ [" G; t" w3 a. Y$ C, [
getch();
i1 Z8 M. U: c! ?3 M; pexit(1); /* terminate with an error code */
: |' r' {9 G! I! g% s3 Y} </FONT></P>+ y$ h) g* c. R; P, P
<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 d. F+ `" i1 t" }2 y' z
midy = getmaxy() / 2; </FONT></P>7 S! O6 g1 _3 u8 k% e
<P><FONT color=#0000ff>/* get information about current line settings */ / r6 |5 z; ~8 X9 ?7 C
getlinesettings(&lineinfo); </FONT></P>
9 I4 r# Q5 m: i<P><FONT color=#0000ff>/* convert line information into strings */
: W0 F# w! V9 U( ?/ A3 Asprintf(lstyle, "%s is the line style.", * A8 O5 x% K+ Y1 P" y
lname[lineinfo.linestyle]); 7 l! f8 t3 r4 i! K
sprintf(lpattern, "0x%X is the user-defined line pattern.", # u g& R4 ?% p0 O) ]
lineinfo.upattern); ) L; t- S2 x6 a# }3 O
sprintf(lwidth, "%d is the line thickness.", 2 y5 o, D3 s8 ^' {' X) u3 e/ `: u: e7 i
lineinfo.thickness); </FONT></P>
! A5 ~( D n/ B9 N: X" D& Q<P><FONT color=#0000ff>/* display the information */
7 l$ q2 R0 \7 o, t" Tsettextjustify(CENTER_TEXT, CENTER_TEXT); ( D/ x; j g% u
outtextxy(midx, midy, lstyle);
. o( K$ q2 q+ h3 n8 T3 |outtextxy(midx, midy+2*textheight("W"), lpattern);
) m: Q* @* r, r5 Y; nouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
, s4 l/ K& u+ V) ]<P><FONT color=#0000ff>/* clean up */
0 B/ r4 S' z/ {' d2 p& Ygetch(); , b5 g' ^/ C: f7 ]
closegraph(); 0 g. c0 i9 x, Y6 |6 Q# i6 O
return 0; 8 ]! f3 c# n& e, o9 Y0 Z# X5 Q' \
} </FONT>* W- R5 W+ v }2 L
|! z; {4 N9 ?" M
</P>
+ S( t* U3 ?6 `<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>
! {5 K0 {3 u. A# o" ^' @功 能: 返回可以传给函数setcolor的最大颜色值 ' |3 [' I( P# b: g+ v3 w( P5 q
用 法: int far getmaxcolor(void); 9 u" h- K( W* k8 H& v
程序例: </P>4 l5 w, Y0 c" S- _+ G3 M$ {
<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 h( z/ K+ F1 Z: b#include <STDLIB.H>
7 N) B4 u/ p3 t) t- s7 h) G( h#include <STDIO.H>
. _$ Q" e7 O( ~; p* P. e#include <CONIO.H></FONT></P>
! C" }7 o% K: c! P7 a<P><FONT color=#0000ff>int main(void) / e+ O- X+ h! X9 c" v
{ ) i8 n5 |# B. j3 f4 o8 t
/* request auto detection */ 2 a/ p8 ?& d& f3 G! p. X3 N
int gdriver = DETECT, gmode, errorcode;
/ z2 x0 n% I; v+ Xint midx, midy;
' m/ L) t2 [+ j% ~) v7 U# Ochar colstr[80]; </FONT></P>: W, g; `9 d" W/ w- S
<P><FONT color=#0000ff>/* initialize graphics and local variables & _2 y% k$ w" Q8 w. q
*/ initgraph(&gdriver, &gmode, ""); </FONT></P>& o8 J3 l5 B; z- }6 |( T
<P><FONT color=#0000ff>/* read result of initialization */
& c( D! ~3 u, G: h& Cerrorcode = graphresult();
+ R* t& R8 h, q* x- k0 |. qif (errorcode != grOk) /* an error occurred */
3 K4 c3 v' K' o1 E4 M7 @{ , b; I' j0 q1 u, F# j
printf("Graphics error: %s\n", grapherrormsg(errorcode));
. E: w9 F& c% r9 Jprintf("Press any key to halt:");
% M8 `: n; }! g4 @& g# o' Ogetch();
( C; @3 F- I' [ H- g4 N7 }exit(1); /* terminate with an error code */ 5 ]" D: D5 A4 y( n& y
} </FONT></P>
5 I! j: h/ H$ d# u3 L<P><FONT color=#0000ff>midx = getmaxx() / 2;
j( y h0 P) B" H, Dmidy = getmaxy() / 2; </FONT></P>
. z( E0 K$ s; Z6 D$ J! E: I<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ 5 Z; o; m+ T. k/ O" g7 T5 W- z* w
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>( T( b5 i- K- Y' R! ~5 ^) [
<P><FONT color=#0000ff>/* display the information */
: @$ v% \- I# `7 Ksettextjustify(CENTER_TEXT, CENTER_TEXT); * E0 ~/ @4 @2 M* J; O
outtextxy(midx, midy, colstr); </FONT></P>" z0 O! _7 H6 P3 v
<P><FONT color=#0000ff>/* clean up */
7 s* O% C3 x3 V8 C* bgetch(); 4 ~. g O! V( t, j$ \- \% j
closegraph();
) r" s: O# j& \return 0; + g3 X/ M) p G* z
} </FONT>2 \" p5 A8 j9 O" F& _& Q
& D( D& L1 p8 }; z% r
) `. a6 {: x" x
</P>$ l: z7 J" @4 l8 A7 Q: @' s) n
<P><FONT color=#ff0000>函数名: getmaxx </FONT>
7 L. M' L9 d% L/ C功 能: 返回屏幕的最大x坐标 # [+ c' T r4 g) }/ p) s; z
用 法: int far getmaxx(void); 7 S/ k3 w1 S; {
程序例: </P>
" H3 n7 h" ]7 k; g# T! E" J9 B<P><FONT color=#0000ff>#include <GRAPHICS.H>6 x1 X3 i6 r) }; x+ ~: }% [5 \
#include <STDLIB.H>
/ K2 m. k+ o9 k, Z3 x; t#include <STDIO.H>
' w% L4 i- k; a4 D. w1 r3 l( a#include <CONIO.H></FONT></P>' C' Z# q. H1 \4 R: p
<P><FONT color=#0000ff>int main(void) + v2 F z3 _; i9 j
{
6 D4 x* P! Y2 N5 x* S/* request auto detection */
% `0 h* W( W0 {( v0 V3 a+ Fint gdriver = DETECT, gmode, errorcode; ' c' f5 o- `$ B% s; k7 V9 t
int midx, midy;
3 D( b* _& j) C1 N1 Wchar xrange[80], yrange[80]; </FONT></P>% [! X; v% ? v" D! H7 i
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; V! V9 x, C* O6 V2 C
initgraph(&gdriver, &gmode, ""); </FONT></P>9 q' o( [7 ?1 u8 {8 L
<P><FONT color=#0000ff>/* read result of initialization */ 8 |% j/ w( e4 ^; G/ i- H- z
errorcode = graphresult();
) R& r/ v6 y: L3 u6 [8 f: dif (errorcode != grOk) /* an error occurred */
) K9 Z* v7 z& G7 ?{ % f: O8 W+ t; F3 V' U& o
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& X$ u- t2 Z( c! M6 Fprintf("Press any key to halt:");
% J/ F! |. e9 a" y) W: G- R1 @* T9 Mgetch();
2 N* N9 \1 `" i; h# j4 L) nexit(1); /* terminate with an error code */
" R: I% O$ B+ K} </FONT></P>
( T5 T5 i$ } ^5 q( W3 F" z: F<P><FONT color=#0000ff>midx = getmaxx() / 2;
9 t8 H. y6 e$ Q0 E1 `midy = getmaxy() / 2; </FONT></P>
9 n6 y, ]2 y# J<P><FONT color=#0000ff>/* convert max resolution values into strings */ + X" g7 ?; f5 K( P
sprintf(xrange, "X values range from 0..%d", getmaxx());
2 [' u( c5 N1 C$ w0 }sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>2 [0 M% e. t( u, a8 _; M
<P><FONT color=#0000ff>/* display the information */ . }3 a* ~' X6 }2 k2 x6 p
settextjustify(CENTER_TEXT, CENTER_TEXT);
6 K3 n! `3 ]* Q& [; f3 mouttextxy(midx, midy, xrange);
5 U- @$ U) v. U6 M3 Nouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>
- e$ t: A$ _9 P" Z<P><FONT color=#0000ff>/* clean up */
& m; g& ^/ {' {$ q3 \+ l' f8 B% Hgetch();
1 a: |' l$ F2 B1 U" e, p* [7 _closegraph(); 5 r. x: s( f$ D+ w" M9 f
return 0;
6 ^4 B* V4 K0 K1 r, i9 G8 x, k}</FONT> ) U9 ?% ?, K* [5 ~- A A, R0 R
/ i$ S/ E& M2 D t9 j# b6 L
</P>; r9 q L6 X0 ~0 u" x( }; m ~
<P><FONT color=#ff0000>函数名: getmaxy </FONT>
" e# g" _5 h6 Z5 |. Q功 能: 返回屏幕的最大y坐标 % C4 C: K9 e$ u9 @
用 法: int far getmaxy(void);
3 q7 Q2 }5 N) @, C& ], q/ \" ]. d3 b程序例: </P>4 ]$ P' R4 A0 ]& P( M
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 j: c# R- I+ c0 H( q/ ~#include <STDLIB.H>
" ?) c9 ]) g' z. o$ v+ ]0 W+ `#include <STDIO.H>7 m* X, s$ V5 n9 l+ F5 Z
#include <CONIO.H></FONT></P>& Y6 K, F7 Q' t3 C
<P><FONT color=#0000ff>int main(void)
* n- D9 @1 s7 L, B Z3 L+ J{ ; c: E8 k' _3 F. t! y
/* request auto detection */ + [$ N0 \7 w- B+ N/ A, o+ a
int gdriver = DETECT, gmode, errorcode; & d% `! s" [0 @3 b5 t
int midx, midy; 5 }" t! b* O9 C, E Q. U
char xrange[80], yrange[80]; </FONT></P>
6 I; h6 d/ g- o, _" L4 N( B2 _<P><FONT color=#0000ff>/* initialize graphics and local variables */
% E. q/ _) m4 F+ W6 }6 b* c9 m# Xinitgraph(&gdriver, &gmode, ""); </FONT></P>
1 D7 ]6 N# a' E& g/ B<P><FONT color=#0000ff>/* read result of initialization */ 1 t- e9 A8 p& ^4 w" l
errorcode = graphresult();
& J5 R9 ^/ o, q) B' _' s1 S: tif (errorcode != grOk) /* an error occurred */ ) N) {' z8 F2 k% s7 V- {/ `3 L/ c
{
+ o: }& g3 b6 t6 {' E8 n8 Iprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 K( K5 k1 i- M6 r
printf("Press any key to halt:"); . ~# ~( O# F X s g4 x0 I9 l" ?% ]
getch(); " ~2 Y2 Q$ Q! V, O% f
exit(1); /* terminate with an error code */ ; m+ ?3 B! ]7 @+ n4 G
} </FONT></P>
& \. W" |4 F4 k8 `: g; q5 ^+ n& _<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 ?2 p' R6 V! |% r' s- v+ [midy = getmaxy() / 2; </FONT></P>5 L$ r* v, H8 x' T' W+ o8 H
<P><FONT color=#0000ff>/* convert max resolution values into strings */ " P5 E# t1 h: _" S
sprintf(xrange, "X values range from 0..%d", getmaxx()); ( Y: C& Q. t* f5 u
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
6 `* y! f) }0 ^/ N5 ~<P><FONT color=#0000ff>/* display the information */
- ^- E7 p- W2 E7 c* J6 isettextjustify(CENTER_TEXT, CENTER_TEXT);
4 R" ~+ k+ Y3 m+ t7 N8 kouttextxy(midx, midy, xrange); / k' |/ s9 ^3 x7 T6 K3 a7 C: b& i& a
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
! z# N3 F i# s+ Z8 z<P><FONT color=#0000ff>/* clean up */
0 w1 d$ V1 U. Z! d8 W. K! c I- hgetch(); 6 I: M# n( c$ |& d
closegraph(); 5 F8 m+ f) h( w! f
return 0; 4 a2 V+ Q' X5 @, B7 P; n! g, t
} </FONT>
3 o4 S3 e) r6 E7 I</P>
! V% F# Y0 g. C' m4 m<P><FONT color=#ff0000>函数名: getmodename </FONT>, H7 i, P$ A- Y* r, b
功 能: 返回含有指定图形模式名的字符串指针 5 ]: v2 u$ C" ?
用 法: char *far getmodename(int mode_name);
1 w/ H) ~# \1 i程序例: </P>: j+ G9 T( W2 [8 H0 }
<P><FONT color=#0000ff>#include <GRAPHICS.H>. Z/ A3 r8 m& ^7 g
#include <STDLIB.H>
3 d/ M3 l/ F# o2 z#include <STDIO.H>) Y/ M- R9 g( e8 p3 M T. R; u
#include <CONIO.H></FONT></P>
; ]4 o$ r, u" s! U- {/ J' t+ {<P><FONT color=#0000ff>int main(void) ' Z3 g% l {+ g- x0 N
{
, y. Z: K" d) O8 B, f0 }/* request autodetection */ 4 ~5 S' |7 i; }: N" \" P* ^: |3 R
int gdriver = DETECT, gmode, errorcode; % {7 p! W# E2 s6 G4 k. [" H
int midx, midy, mode; 5 ?- K, S! m; L: d- a- s' N; C/ G) e
char numname[80], modename[80]; </FONT></P>8 G2 p& i$ A+ c4 R9 E% F; i1 G: I
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 v* y3 V9 J/ a: ^
initgraph(&gdriver, &gmode, ""); </FONT></P>
, J$ o1 f3 s; n<P><FONT color=#0000ff>/* read result of initialization */
) E3 o) o; L( p$ H5 C7 R6 herrorcode = graphresult();
# m4 n9 c$ j) @ qif (errorcode != grOk) /* an error occurred */
- D1 V0 Z/ `8 s4 h{
& R, N6 g2 q2 a! O O- Dprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 v/ T# N; O: R" s6 O
printf("Press any key to halt:");
" ` ?% F, g Y3 E; p& igetch();
9 R- `7 Q$ d+ \. }exit(1); /* terminate with an error code */
* F# d# h' C1 | f& j. N7 T} </FONT></P>+ p3 ]: w( @5 f8 N' @3 B" @1 ~: @
<P><FONT color=#0000ff>midx = getmaxx() / 2; % c( Z) J/ r. l0 H
midy = getmaxy() / 2; </FONT></P>
' ]$ _ ~# M$ i. u<P><FONT color=#0000ff>/* get mode number and name strings */
- e% j9 y9 w: gmode = getgraphmode(); 5 y8 |( q( v: _- [* J4 \+ f' S
sprintf(numname, "%d is the current mode number.", mode); # b7 C K& q) x3 C2 L& k
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>+ X, b/ W7 R+ C0 n& q0 K) N$ t& L- F
<P><FONT color=#0000ff>/* display the information */
5 N3 p) p3 m3 I5 wsettextjustify(CENTER_TEXT, CENTER_TEXT); - b6 O/ ~& `5 w9 a- S" I5 A a5 A
outtextxy(midx, midy, numname); + c# Y7 a- N8 |
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
2 F& x9 j2 y8 c, \1 g* t<P><FONT color=#0000ff>/* clean up */
# f3 s7 W- R, q8 C# D5 ggetch(); ) s$ L% h. P' X e3 C8 o
closegraph();
: u. g- _9 Z! N8 \' P; `( b$ J- @return 0; ; J2 z5 @0 |; f/ I
} </FONT>
0 r8 |1 G$ T6 J2 K7 L6 j( D A' W* K0 Z
</P>
6 Z* a0 o/ k8 l' ?<P><FONT color=#ff0000>函数名: getmoderange</FONT>
" G; x; C9 _8 e. [2 H功 能: 取给定图形驱动程序的模式范围
# `4 a% P& g6 u" b4 S用 法: void far getmoderange(int graphdriver, int far *lomode,
- b' y2 a s4 a5 B8 x5 yint far *himode); 3 r7 [6 u) C+ y9 T' p
程序例: </P> ?- G' U8 g5 X; _5 G \& Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" l# c# g1 A8 P2 ]$ o9 Z- ]& Z#include <STDLIB.H>% D& I& b3 R+ D& v, f& M
#include <STDIO.H>" Z b3 q* L4 ?( I, E$ P8 u7 F
#include <CONIO.H></FONT></P>
2 V* v+ R& _0 w. o<P><FONT color=#0000ff>int main(void) 6 C4 C1 {6 _2 P/ F
{
3 i9 a+ o* Y; X$ J/* request auto detection */ 6 r6 z( [4 l/ T
int gdriver = DETECT, gmode, errorcode;
8 Z2 k; n; R; o: ^- {6 i" x R0 a6 tint midx, midy; ' y7 P& H( b! Z9 a. ?; Y4 r9 Q/ z
int low, high; 8 I* O9 |5 O( `" M0 H
char mrange[80]; </FONT></P>
4 [9 V$ Q/ Q8 v) n<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' g/ p, M: L' y' d# ^ d) N f; `$ \
initgraph(&gdriver, &gmode, ""); </FONT></P>
3 y% P4 M1 W. _: Z I<P><FONT color=#0000ff>/* read result of initialization */
+ F- f. Q( W; X! `. j4 |errorcode = graphresult();
8 {+ _6 i' B- k# o9 ^if (errorcode != grOk) /* an error occurred */ $ n. g9 \' p: c R. B/ k: l# C
{ N8 o0 Q" p3 n. k7 t7 U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / `) i& n9 H6 @- T
printf("Press any key to halt:"); 9 m' H4 g6 b0 P- R% P7 L: F
getch(); # s. j- H& Q) S& T, U' x* U: e, @
exit(1); /* terminate with an error code */
8 X/ z9 S/ |1 p, U9 L0 s5 C5 Y. H} </FONT></P>
9 `* c# k8 G! n: X6 A0 F% ^4 L<P><FONT color=#0000ff>midx = getmaxx() / 2; ! p& {' }9 `8 t$ w, c& e+ w
midy = getmaxy() / 2; </FONT></P>1 M; K: r& i ] B$ l( t7 H
<P><FONT color=#0000ff>/* get the mode range for this driver */ * K, {9 a/ Z* a' I) E: i% Y4 _
getmoderange(gdriver, &low, &high); </FONT></P>/ ]7 G3 G3 a' v5 M
<P><FONT color=#0000ff>/* convert mode range info. into strings */ 9 y/ |, R# U) z) z
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
5 Z6 w4 S7 C5 J/ G3 w<P><FONT color=#0000ff>/* display the information */
/ e7 I# a: K1 l Z' Z8 T1 A: p: msettextjustify(CENTER_TEXT, CENTER_TEXT);
; t7 c6 f# F& P G' T+ ~2 Gouttextxy(midx, midy, mrange); </FONT></P>
9 Q/ q+ U6 j. J: a7 a% z<P><FONT color=#0000ff>/* clean up */
W( Y: A4 W, C6 W+ B, W7 ngetch(); 6 x3 M, ]- N6 o, N# s' V
closegraph();
$ J) D/ z# i/ @( V" l. t3 y Greturn 0; C, J/ m W, D0 Y, c
} % v; d( f' ]5 \( j, D
</FONT>
" O/ @6 \: S S3 [( r- B) S( E</P>
# n5 B/ @4 S& Z7 D: u0 ^6 a<P><FONT color=#ff0000>函数名: getpalette </FONT>5 ^9 \1 Y% m" I/ X8 o2 f; B& I
功 能: 返回有关当前调色板的信息
, M* D% V* B1 E: U/ i+ y& y用 法: void far getpalette(struct palettetype far *palette); 4 `% h0 r' D1 c O% c8 |; i
程序例: </P>$ N) {9 P" b6 T8 ?$ L+ V
<P><FONT color=#0000ff>#include <GRAPHICS.H>9 I S. M3 ?$ m! S4 ?) |( t. G
#include <STDLIB.H>
& R. K, s! x) ?$ p! x# V#include <STDIO.H>
) V3 p; v0 Y0 ]4 T6 J#include <CONIO.H></FONT></P>
5 n6 j1 y- }; Z$ J<P><FONT color=#0000ff>int main(void) : J" Z+ e8 F: s4 g
{ - }: A. v/ {8 M, p
/* request auto detection */
+ T$ | ]; L- M1 }& P, V2 ~. |' `4 V# Uint gdriver = DETECT, gmode, errorcode;
! _1 }, }+ F8 a9 G9 o$ xstruct palettetype pal;
7 x. H0 g3 Q$ ]. f) F; K4 Tchar psize[80], pval[20];
5 k$ S, V3 D- u- b7 tint i, ht;
$ J' R3 h3 b) S3 }0 {6 w$ q" zint y = 10; </FONT></P>. s, b% R, J' j; ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */ + G+ H! Q4 M1 u% G* C
initgraph(&gdriver, &gmode, ""); </FONT></P>
/ t9 S% U% f- y<P><FONT color=#0000ff>/* read result of initialization */
4 v+ f- Z E7 u5 merrorcode = graphresult(); ( r' c1 k1 F8 v9 G
/* an error occurred */ : f6 ] E' T4 }: t# c" y8 Z) x
if (errorcode != grOk) - F# I; `" s. g6 p9 J
{ 4 ^, T; J/ u* ~: P
printf("Graphics error: %s\n",
6 M& P0 r! w, Ngrapherrormsg(errorcode)); * q/ e u$ L# r: q
printf("Press any key to halt:");
. Z0 s* Q- G* v% Egetch();
% r8 K$ g. H& [/* terminate with an error code */ C4 Z2 V; v3 r3 r/ u3 z3 m
exit(1); ( z t1 S6 q: d2 S+ ]
} </FONT></P>
) ^2 k4 C/ m9 U<P><FONT color=#0000ff>/* grab a copy of the palette */ . {% P5 U+ L5 N3 b
getpalette(&pal); </FONT></P>1 I8 N: h5 ]( s }& O
<P><FONT color=#0000ff>/* convert palette info. into strings */ % c- l6 x0 f7 u) J7 M8 q. `
sprintf(psize, "The palette has %d \ 7 V; G' A& c! Y
modifiable entries.", pal.size); </FONT></P>* U# V9 H7 s( w/ r& y! R$ Q
<P><FONT color=#0000ff>/* display the information */
) ~% u4 [" `7 i! W* aouttextxy(0, y, psize); " x( b9 [# A! {
if (pal.size != 0)
' I+ V u% W2 |( j" q{
% Y1 x2 y# S6 uht = textheight("W"); * W/ i/ K% x8 V& Z1 ~
y += 2*ht;
?6 ^, D: o0 F" fouttextxy(0, y, "Here are the current \
. ~* w% x( n, svalues:");
9 j) q+ z9 t/ `y += 2*ht; " W' d1 w2 T6 J
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
n1 h/ s- c, I) Asprintf(pval, 0 U, h9 D* q4 t. t X) g" r; G
"palette[%02d]: 0x%02X", i, 6 U b l, z3 X6 \: k
pal.colors);
% I9 N( o- C; q% P* y% ?0 l3 gouttextxy(0, y, pval);
- a7 z& o0 n4 J @} 3 X b5 N+ N$ m4 h) I% g4 H5 `
} </FONT></P>
+ R( w& D3 c( H E( E o K1 L<P><FONT color=#0000ff>/* clean up */
1 `3 M3 ?. m+ u% I5 Kgetch();
4 ^) `( b4 M& nclosegraph(); </FONT>
' Z! J4 X) n: d: y% T b! h<FONT color=#0000ff>return 0;
# @) o' K: i! t}
8 s; a3 i H0 K# d# `+ M5 {</FONT></P>' Y0 r5 L9 H- P7 B8 [8 U: C6 W
<P><FONT color=#ff0000>函数名: getpass </FONT>1 t) D3 B) s% S
功 能: 读一个口令 8 j. c5 y$ \2 ?6 A6 \: D7 V
用 法: char *getpass(char *prompt);
3 J/ V% Q; D, j. j3 @程序例: </P>4 s G7 {9 U$ q8 c" v: ~4 m% w$ L' j
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P> Z9 ?: K2 S0 c. K3 @; | m, D# `! @2 v
<P><FONT color=#0000ff>int main(void)
/ d/ W* U5 ~( N u4 p1 N{ 1 v; e+ }) ]1 u& _1 E$ e/ s
char *password; </FONT></P>' w- q2 b5 u# }6 j
<P><FONT color=#0000ff>password = getpass("Input a password:");
9 K2 `( D7 N/ lcprintf("The password is: %s\r\n", 3 K# I" [: U+ R
password);
1 T/ [; s: v* ]) i) s( p2 Ureturn 0; 4 o" u! Z" o7 n! G2 V! h1 R! }
} ) L. @# T! @! ]% ^8 L4 a1 ?) V
</FONT>5 O' f4 m4 W% b3 ?& h, t3 W
$ e# N* X& d2 I! y
</P>. t' E- S, S) W) j! Y2 k
<P><FONT color=#ff0000>函数名: getpixel </FONT>/ R7 `3 Z0 X. k' {( Q1 t
功 能: 取得指定像素的颜色
, I- g# ?, M- p用 法: int far getpixel(int x, int y);
2 L. {1 _5 [6 a8 m3 x程序例: </P>- e Y+ P! o9 [
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 ^- R# v0 o- T( t
#include <STDLIB.H>
2 J" C5 E! k" t; u5 a$ }& m# C6 X. D#include <STDIO.H>
4 S* x. F2 l( l, K#include <CONIO.H>
! I# j- g1 @, |% o9 b j/ ^#include <DOS.H></FONT></P>
& I) r" I/ ~" ^3 h8 G<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 / V# k5 X! @+ I" f
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
' S2 ?& T# Z0 b$ H5 @" ~& x<P><FONT color=#0000ff>int main(void) 5 Z# x' A7 P7 }! ~; v) I
{
, s$ h P2 ]# V& o% \ l: n! s9 a" [/* request auto detection */ & X( q' b5 U0 j. R3 g: W* _/ V
int gdriver = DETECT, gmode, errorcode; : W, K0 K( j: e
int i, x, y, color, maxx, maxy,
" F6 _. M! s9 x. Hmaxcolor, seed; </FONT></P>
$ I6 Z0 R0 h3 [4 `<P><FONT color=#0000ff>/* initialize graphics and local variables */
& Q3 `0 }" F- c$ O' |4 sinitgraph(&gdriver, &gmode, ""); </FONT></P>
: {* j5 H `+ H" ~<P><FONT color=#0000ff>/* read result of initialization */ 2 z; G4 e% R9 ]) n! a3 ^# S
errorcode = graphresult();
5 ]' e) ?1 v% m3 ~. p& L1 Z/* an error occurred */ ( Q9 [: M% P; p
if (errorcode != grOk) 3 D! L. [4 b( T4 s) r5 w
{ 6 r6 h/ \+ H$ ^ ^1 l2 ^7 q5 X0 v
printf("Graphics error: %s\n",
, q) ?' \- Z8 _grapherrormsg(errorcode)); # z, u0 P9 u C- W
printf("Press any key to halt:"); - X# }4 |7 ]8 @+ W: x
getch();
. E6 l" f3 X+ [1 t) X3 I3 U/* terminate with an error code */
" z7 I9 E3 r% c7 [% Q" Yexit(1); ; E" ^0 V$ I; H& X6 T! o7 P
} </FONT></P>
0 _, S9 D B5 U<P><FONT color=#0000ff>maxx = getmaxx() + 1; 3 v% R. Y. P: D' z( S2 [" ]2 O
maxy = getmaxy() + 1;
6 x" D2 U# @ T6 ~maxcolor = getmaxcolor() + 1; </FONT></P>9 }/ l6 o& e7 n2 }0 P" x7 P
<P><FONT color=#0000ff>while (!kbhit())
- q/ M5 r% g- M7 J2 @2 b{ ' N. [) u* e% z* Y) O$ ~
/* seed the random number generator */
' Q' {1 `. @+ j" w. q+ f! Yseed = random(32767);
: z9 q# N# E# A. ` Psrand(seed);
% @3 q$ c7 E" z) Q! M1 }: Pfor (i=0; i<PIXEL_COUNT; <br i++)> { $ }1 v9 Y; x2 G9 F" `
x = random(maxx); 5 e6 g8 b& A4 }6 f5 {0 D1 S
y = random(maxy);
# T# u8 t$ b/ j% ycolor = random(maxcolor);
' g/ O( B$ e2 ?( S, \$ Pputpixel(x, y, color); 3 h3 q5 i2 D9 S6 r/ P
} </FONT></P>% `" C( ]* ~- C; X I) R N
<P><FONT color=#0000ff>delay(DELAY_TIME);
# R, g1 Z; d' @: F9 r4 d% h- G3 Wsrand(seed);
, u5 ]. t0 b# I; h K, ufor (i=0; i<PIXEL_COUNT; <br i++)> { # I; p: ?) J, [
x = random(maxx);
1 r$ \3 ^1 X& C; }y = random(maxy);
' O" h8 o' H+ v9 X- Acolor = random(maxcolor); : b5 U7 R) T" a+ X, }
if (color == getpixel)</FONT> </P>
* Z g; L; C& a3 L0 g8 l6 t<P><FONT color=#ff0000>函数名: gets</FONT>
4 R7 k* C4 y/ v7 n8 j( A功 能: 从流中取一字符串
9 N: s+ }: R$ }8 L# j用 法: char *gets(char *string);
$ H% K- c6 T; \2 z程序例: </P>
- v: w2 l9 V3 i$ q( [- U; f<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
0 P& a& [! v1 k5 w<P><FONT color=#0000ff>int main(void)
2 J1 C8 s& E3 \2 b{
* \, ~9 o. R+ V* vchar string[80]; </FONT></P>
1 y1 c3 o3 Q5 e* I) m<P><FONT color=#0000ff>printf("Input a string:"); 0 v$ J* y: O' V2 H' d1 H5 y5 S' y
gets(string); + q. U7 \. O+ v3 A3 x
printf("The string input was: %s\n", / X ^/ H; `+ [; [5 [3 c
string); $ W# r( `: N/ z* \1 J5 T
return 0;
5 `5 w" {- q1 e# `6 y} 5 [% `7 \0 ?8 p/ j: x% M8 {4 Y
4 w4 q8 K# o9 ~8 ?- b% G2 i4 u</FONT></P>% z0 J# l* y/ r' _4 Y, I6 [# W
<P><FONT color=#ff0000>函数名: gettext </FONT>5 G- t2 Y3 l F
功 能: 将文本方式屏幕上的文本拷贝到存储区
( y) K; m/ \/ z0 e# P用 法: int gettext(int left, int top, int right, int bottom, void *destin); , h' T1 X- f# i. ?5 ?
程序例: </P>
7 m# s# e5 q+ j7 u8 b, l) }8 b U<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>- J2 ?) `7 V" q; W( f- T
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>3 `; ]" |! K" G2 j3 w d" t/ l
<P><FONT color=#0000ff>int main(void)
$ O" k5 I$ m) K, c{ - P+ S9 \1 B1 P4 ^
int i;
, p2 q# u/ S7 J) V! r' {. z0 Wclrscr();
/ q7 X9 E- K6 z9 I+ u' K; pfor (i = 0; i <= 20; i++) + M) E, Y( `- _5 w
cprintf("Line #%d\r\n", i); # v: d) ^+ E3 G
gettext(1, 1, 80, 25, buffer);
5 ]. M+ _" c4 E5 c$ f+ jgotoxy(1, 25); + S0 ?% {6 W! k& ]! h
cprintf("Press any key to clear screen...");
- F' y( K, f2 Y- `2 t: Ngetch();
. N9 ^1 `% }* w% Gclrscr();
$ a/ c% T' {: z% w- y6 n2 Agotoxy(1, 25); 6 a+ ~: v# j$ ]6 ^
cprintf("Press any key to restore screen..."); ' {9 P! e/ p' d& Z$ g8 ~( E: r2 |
getch();
3 m: V7 U1 d% N9 A" x- b# vputtext(1, 1, 80, 25, buffer); + k8 q* k8 m7 j9 x5 E
gotoxy(1, 25);
& N1 h: Z5 Y$ |$ E* Z8 Xcprintf("Press any key to quit..."); 3 V/ E, f) F5 ^6 R; f* n+ W9 V
getch();
, @6 r6 w" Z' ?3 j9 rreturn 0; - F- v, X$ x s
} 4 `( H9 t a/ r! Y5 J$ H
</FONT>- ]( f- w- B- p8 U$ P
</P>5 s" r. ^& C1 s( Y$ m
<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
( a+ C% C2 y, P: D# d功 能: 取得文本模式的显示信息
. `9 x+ j0 \5 a' D0 ^9 t9 U用 法: void gettextinfo(struct text_info *inforec);
: I* n, v, E8 P$ D) j& C程序例: </P>
- y1 B2 @. b# s1 N<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>) G7 U; Q# ~& V) E8 E% \1 |
<P><FONT color=#0000ff>int main(void) , q! c& }, C9 I' Y5 M0 B: ]9 D+ V' [
{
: a U7 X& G- ]" P% e6 k+ lstruct text_info ti; 4 c$ p, a, I: e, M2 _+ v" o; Q
gettextinfo(&ti);
; z( j# x1 W: n, U2 I4 fcprintf("window left %2d\r\n",ti.winleft); ; M" I" c |( m$ q' Z; o5 `
cprintf("window top %2d\r\n",ti.wintop); . K- v2 a' C' T3 E/ m0 q; g
cprintf("window right %2d\r\n",ti.winright); # r: m1 @0 h, `/ M% F
cprintf("window bottom %2d\r\n",ti.winbottom); 1 X7 l' d8 B5 o; b: `( x- {) g
cprintf("attribute %2d\r\n",ti.attribute);
0 Q3 q: W" x2 I3 U3 f- v* Jcprintf("normal attribute %2d\r\n",ti.normattr); ! B" q3 K2 w: y/ \# ~
cprintf("current mode %2d\r\n",ti.currmode);
6 C, d. W5 c+ m/ p$ V1 s% L8 k( [cprintf("screen height %2d\r\n",ti.screenheight); 1 o, n4 ]) H4 n3 o" ~# o
cprintf("screen width %2d\r\n",ti.screenwidth);
$ ]' l+ v6 _- rcprintf("current x %2d\r\n",ti.curx); / X* h3 d j$ T: ?
cprintf("current y %2d\r\n",ti.cury); / J( C$ H% R8 J) C: H( O. y/ \) P' Y
return 0;
; B' _( m8 }! T) j- K4 v} 4 A. ?: _- h- Y) L% b3 J- E( C
</FONT>5 {0 t4 T, j6 f' L# m# h) D
</P>+ t: M2 |8 E, l0 i3 t% k, E1 O) Q
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>5 a1 e) _( G, l: T! r( r, ` ^
功 能: 返回有关当前图形文本字体的信息 & d) x& V# R. }. w, z
用 法: void far gettextsettings(struct textsettingstype far *textinfo);
3 t2 N3 j0 N; }* ?5 c9 O2 G程序例: </P>8 k& b% J( N0 ]- R0 k& Q5 k
<P>#include <GRAPHICS.H><FONT color=#0000ff>+ }' k, V/ x. g" H* G/ d" u* ?% f
#include <STDLIB.H>( }' E5 K1 u2 O* j+ |
#include <STDIO.H>
" Z# ?" h, x: l/ Y2 p. p#include <CONIO.H></FONT></P> Z9 g# @5 F: Z! A1 ?1 X6 \ e
<P><FONT color=#0000ff>/* the names of the fonts supported */ # L: c" s% A' @* [
char *font[] = { "DEFAULT_FONT",
: L" L; I- V: {8 n"TRIPLEX_FONT", ' @1 J4 K9 J! m0 X0 D9 ^) M% Q
"SMALL_FONT", / @; K1 _$ M8 `2 D E
"SANS_SERIF_FONT", 1 l% ^6 t P& j3 R6 Z" c
"GOTHIC_FONT" 4 O/ L2 n# {8 M9 n+ O
}; </FONT></P>2 w, H6 n4 T8 q8 S( h% }
<P><FONT color=#0000ff>/* the names of the text directions supported */
! u' n% m+ f! f% Q. p3 `1 B+ r8 Dchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
2 {' H6 ?. @! ]' ?/ ]+ F8 \- D<P><FONT color=#0000ff>/* horizontal text justifications supported */
% D. H* W6 ?' s3 Y0 X3 s( }+ ?char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>
; s; ~4 b; H4 z7 ?5 _3 m<P><FONT color=#0000ff>/* vertical text justifications supported */ / h4 U3 e. |' B& w3 y4 W4 Q
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>/ X% P) I0 O, c9 V& n( s; J/ m
<P><FONT color=#0000ff>int main(void)
: f, E% [$ U1 j{ " g4 ?* i, S4 ~. x. Y8 \. J
/* request auto detection */ & o5 f& G2 L8 |& m# A+ l( B0 U
int gdriver = DETECT, gmode, errorcode; $ F# U9 F% M; b6 s# s
struct textsettingstype textinfo; 2 T* r0 f# I% y- X% n5 k
int midx, midy, ht; / a( e6 ~+ c* ~' Y) A/ o: q
char fontstr[80], dirstr[80], sizestr[80]; ( b& P9 h3 g" u; t
char hjuststr[80], vjuststr[80]; </FONT></P>3 C3 e! ]7 R! [3 H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! V& m" @# k; [
initgraph(&gdriver, &gmode, ""); </FONT></P>
' P. y* ^/ F+ c$ w4 H; w<P><FONT color=#0000ff>/* read result of initialization */
1 ^1 G; v; p) a% r' [errorcode = graphresult(); 9 v: w# N7 e6 B6 i) {
if (errorcode != grOk) /* an error occurred */
3 O$ i6 p, ?0 }5 B+ Y* s7 b{
! W, i, ?" ]: l/ M' j3 B. {$ o# jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " _- s9 c* ^4 p' f, G7 w
printf("Press any key to halt:");
" | X: o3 m1 x2 ?/ Y) Wgetch();
1 \" I( ]6 }" _. v- Rexit(1); /* terminate with an error code */
/ K5 Q& I8 L# D% M- ^( F$ c# }} </FONT></P>
6 A7 n' P8 j6 T! r<P><FONT color=#0000ff>midx = getmaxx() / 2;
; k& `$ `$ O& v8 N s4 o c9 K2 {midy = getmaxy() / 2; </FONT></P>
' `5 K$ O$ `% y: y! }<P><FONT color=#0000ff>/* get information about current text settings */ % N$ z | y; b. H% p
gettextsettings(&textinfo); </FONT></P>1 w! ]* u7 P8 O) i1 W- i8 U
<P><FONT color=#0000ff>/* convert text information into strings */ 4 W0 l' a- X# n9 L. i/ g
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); # A* U% P: M1 q# I) D$ z j
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
. [3 U2 p& e l, Q9 u/ {" i6 hsprintf(sizestr, "%d is the text size.", textinfo.charsize);
; ?9 O0 U. j/ [8 J7 H' }sprintf(hjuststr, "%s is the horizontal justification.", ( L: S& r/ v# W( e' _$ x0 C
hjust[textinfo.horiz]);
% ?# s' D& \( { D0 ~sprintf(vjuststr, "%s is the vertical justification.",
* D9 \% Y+ Z& x8 I, g+ D0 dvjust[textinfo.vert]); </FONT></P>
w" O9 [) j' W( F: \9 R<P><FONT color=#0000ff>/* display the information */ * f0 J( J _) f$ ~" }; ^
ht = textheight("W"); 5 U% d0 O& M! K' } I* @4 @
settextjustify(CENTER_TEXT, CENTER_TEXT); 9 G! g! E1 I: v7 J4 s+ ?! H
outtextxy(midx, midy, fontstr);
! R9 j' H1 G* J1 d U5 l$ qouttextxy(midx, midy+2*ht, dirstr); 9 H( j3 u/ p2 N' ?6 g: L+ F
outtextxy(midx, midy+4*ht, sizestr);
* k0 T2 c& P# ^$ D0 |outtextxy(midx, midy+6*ht, hjuststr); 1 ~2 h( ]6 m& M* s, P; }
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
0 W+ W p, n: v! F8 c8 A% D @9 ?" h<P><FONT color=#0000ff>/* clean up */ 8 p( t# \6 [ b0 h U6 b# _
getch();
( s7 v/ K. }' s0 B; m% ]closegraph();
0 M6 ?! ~9 q; W4 {4 Ireturn 0; : ]; f; `! z. ]6 F! y# {' }/ [ `; L
} </FONT>
T# Z, ]2 c. G2 u% J, u% f</P>3 C, T1 j+ K& f
<P><FONT color=#ff0000>函数名: gettime </FONT>7 p) @' n7 N' X9 K0 A
功 能: 取得系统时间 ' T# O4 C1 ~5 f6 ]6 M8 m L" @% q# x$ q
用 法: void gettime(struct time *timep); ) P6 O# l: f1 Z5 |0 V6 A; u
程序例: </P>
3 _$ O' K {5 |' e<P><FONT color=#0000ff>#include <STDIO.H>4 ], W& {/ m) d. X
#include <DOS.H></FONT></P>* ~* v6 m9 b7 l0 ^0 a4 ^2 F
<P><FONT color=#0000ff>int main(void) 5 l! |4 I P* P* } _) E
{ ' a6 l4 T7 Q5 l+ x2 m& C6 v
struct time t; </FONT></P>
/ E% c- S7 ?0 R, c# ^8 r. O- s5 ?<P><FONT color=#0000ff>gettime(&t); 1 C0 s0 d+ m8 b4 ]9 g1 P
printf("The current time is: %2d:%02d:%02d.%02d\n", : Z4 f/ L' T# \, W9 H
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); 9 ?& o$ z6 g# K7 d4 y
return 0;
2 f$ { {; {9 U1 Y ?" N}
; G9 X- C* ^5 [" ]2 x
1 f0 W( e1 g! S, z! N8 m</FONT>5 M a# x- \) U7 ?- t8 l0 e
</P>
& r% f9 D7 S) J0 {" ~<P><FONT color=#ff0000>函数名: getvect </FONT>
6 U7 J$ ^" _) p9 j' R功 能: 取得中断向量入口
0 g- A* I" Y; b8 o1 w% d用 法: void interrupt(*getvect(int intr_num));
; M( l3 Y8 v0 B, M8 g! i程序例: </P>" r+ `- X: ?! c# T b) B4 c5 y
<P><FONT color=#0000ff>#include <STDIO.H># g% _$ S1 V2 F
#include <DOS.H></FONT></P>! Y& n+ c# r! I* s D
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P> b' Z2 C4 X% `4 j0 H8 Q( W% U
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
" i1 z% a7 t/ Q5 fint looping = 1; </FONT></P>
9 j. @6 \/ L; z! }2 T9 s* v$ _# D<P><FONT color=#0000ff>int main(void) & P4 |+ g- O' Y. u+ P
{
! V0 C* ?. d5 v |0 O# i$ u( K& @puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
\+ O) w' I6 U" n* J+ i+ ~<P><FONT color=#0000ff>/* save the old interrupt */ 7 H5 D( O7 D+ P" j% v
oldfunc = getvect(5); </FONT></P>
8 Z5 |- r0 ?4 t8 ~( y/ x<P><FONT color=#0000ff>/* install interrupt handler */ * d) S; h3 }) v* U
setvect(5,get_out); </FONT></P>
2 r4 M, V: B P, [, g# A/ S8 l% c T<P><FONT color=#0000ff>/* do nothing */ ) ^$ z! E5 y! T! y. J
while (looping); </FONT></P>
. J$ k% {# W, a3 ]" H<P><FONT color=#0000ff>/* restore to original interrupt routine */
3 c2 V) y4 i0 A0 Y, Rsetvect(5,oldfunc); </FONT></P># r0 ]7 d/ w# A! W; |
<P><FONT color=#0000ff>puts("Success");
7 f3 Y6 h& S2 X* T( _$ k& ]6 ?# q6 Ireturn 0;
7 p* [; C _6 f. v3 c a5 y}
& h' C$ k1 @8 dvoid interrupt get_out()
8 Y; Z5 r6 Q% ^( x }9 u8 c+ M3 d v{ ' @% n- O& N0 \5 v; {$ R
looping = 0; /* change global variable to get out of loop */
/ n0 i H& F: k# v5 L; J}
. I* ~5 }, w3 f& u, Q. d</FONT>
1 _0 r" f2 M$ M" [' o</P>
/ _' L2 J4 t2 x/ \/ }9 h$ R4 U<P><FONT color=#ff0000>函数名: getverify </FONT>& H$ G4 d5 x: @( z* Q
功 能: 返回DOS校验标志状态
+ h1 _2 s' N L3 A$ z用 法: int getverify(void);
3 [, s. Z' e$ o% a; }! }程序例: </P>; k2 H' v8 Y9 Y- i$ \3 Q6 P- {
<P><FONT color=#0000ff>#include <STDIO.H>
; h% g/ u" }8 Z2 Y, L! M: I#include <DOS.H></FONT></P> Y' _+ v* u$ U
<P><FONT color=#0000ff>int main(void)
1 z3 ^- B" r4 R* `* r0 J. J{ ' }* }0 z0 \1 H" O( \
if (getverify()) ( w( n( L6 V7 [7 w# e# O6 l
printf("DOS verify flag is on\n"); : n# |! N% R1 ~+ f/ K# }0 Y+ o; z
else & L: F: }2 ~7 y3 G$ a& b
printf("DOS verify flag is off\n");
2 t) W- Z% g: s( areturn 0; * C' M+ g+ k* p1 u
} [9 r/ q" f9 _$ s; d7 a: t: S: U
</FONT></P>
( y% x) D/ D4 }9 x+ n<P><FONT color=#ff0000>函数名: getviewsetting </FONT>' m! p4 G3 W" x, d4 P7 h! ?6 ]
功 能: 返回有关当前视区的信息
! M* ^9 c) `; ?* N用 法: void far getviewsettings(struct viewporttype far *viewport);
) T2 D2 }+ V8 P程序例: </P>
% A6 i. M, F) S# [1 e" o T5 G# u<P><FONT color=#0000ff>#include <GRAPHICS.H>
# g2 X p% C Z" {6 N) o' y4 h#include <STDLIB.H>
" t6 K/ y" a. P8 w; L6 C2 I#include <STDIO.H>- i+ n7 n1 A% K& ]" s+ R o6 c" I
#include <CONIO.H></FONT></P>
& Z% @- a! C$ V& \: [5 l<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>2 y6 Y Z$ {% ~3 Y. ]
<P><FONT color=#0000ff>int main(void) 1 O1 I: l4 W4 S
{
4 t- o. q- Y+ E/* request auto detection */
5 ?4 q, f8 q) g1 Mint gdriver = DETECT, gmode, errorcode; 0 X' I$ T$ Y; K( O' j
struct viewporttype viewinfo; * O4 `+ e) b+ x: G9 y2 z y3 k
int midx, midy, ht; , _% z8 v+ r& U1 R
char topstr[80], botstr[80], clipstr[80]; </FONT></P>% Z2 G5 `% s! u! d6 s: B& X
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ }) b. a3 L0 D; C
initgraph(&gdriver, &gmode, ""); </FONT></P>3 {4 O; @0 c, ]# _6 c8 E
<P><FONT color=#0000ff>/* read result of initialization */ ) C% g; ~0 U5 ?
errorcode = graphresult();
# j# F3 @# I8 Q: `' jif (errorcode != grOk) /* an error occurred */ 5 z/ ^' u" v3 D5 `0 m: `4 N
{ 4 ]( i7 p" {0 ^7 S4 l6 _ Q9 X" g" J* e
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' x5 k( t) C- c: Z: o6 ?
printf("Press any key to halt:");
* I' g- d3 m; @2 p ^getch(); ; A/ F$ P% \4 g" |0 X
exit(1); /* terminate with an error code */ # D0 S7 Y. r( u% x; Y4 M
} </FONT></P>
5 h! M$ {4 ~6 P<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 _2 p4 z _! b" wmidy = getmaxy() / 2; </FONT></P>
6 T Y2 k! Z2 ?. y1 G<P><FONT color=#0000ff>/* get information about current viewport */
; y0 U: _" j( g7 c5 hgetviewsettings(&viewinfo); </FONT></P>
5 O( s8 l5 ?. I9 M3 ]<P><FONT color=#0000ff>/* convert text information into strings */ 8 x" f' I# [9 `
sprintf(topstr, "(%d, %d) is the upper left viewport corner.",
( i2 K4 i: Y. L- Q$ r Y' a; b: Cviewinfo.left, viewinfo.top);
' ^7 w! d8 U& N$ Xsprintf(botstr, "(%d, %d) is the lower right viewport corner.",
$ H2 ]# V+ `3 P+ Tviewinfo.right, viewinfo.bottom);
* P9 ~1 m0 O& c1 r. L7 _2 |6 }1 Tsprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>2 n9 i, t% X% v, x
<P><FONT color=#0000ff>/* display the information */
" G4 ~1 d$ A6 J! X; @6 A/ msettextjustify(CENTER_TEXT, CENTER_TEXT); % s8 L7 l/ e$ `# c; j
ht = textheight("W"); 7 M* n. E6 F$ |6 R7 e, ]
outtextxy(midx, midy, topstr); & [6 b, o1 C+ r( T. p# [- L6 _4 ]
outtextxy(midx, midy+2*ht, botstr); 0 g" V Q3 ?6 v2 ?& y" c
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>$ k% R2 c, K4 y4 m6 R' x* P: r! T
<P><FONT color=#0000ff>/* clean up */
+ N- V- ~# M# d2 t) \& zgetch();
) W. Q% }2 i. q7 R I zclosegraph();
* E) \! N- _* {+ l: i8 h: T A% Greturn 0; ; O9 w' V2 Q) ?
} </FONT>; M1 m( a. l5 Q a; \) T
) _3 o) ]5 B8 u5 i b6 T1 w q& E
</P>
+ I# ^& i4 m: q# L* I P/ n<P><FONT color=#ff0000>函数名: getw </FONT>( f* \2 j U; Q; O. r. ]2 K5 w) O
功 能: 从流中取一整数
% u# i% s6 D& G) ~& \3 o用 法: int getw(FILE *strem); " e( i0 v6 k$ U. l
程序例: </P>
8 H9 `! {" x* g3 _/ e<P><FONT color=#0000ff>#include <STDIO.H>
/ p$ I e- s( a2 Z3 X#include <STDLIB.H></FONT></P>
# Z ?( L0 U/ Y# m+ X: y: Q5 ~' j<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>( Z) t6 o8 E) z7 u
<P><FONT color=#0000ff>int main(void)
; Q* I4 k B& W% X, U2 @{ % ^" g, r6 X" j
FILE *fp;
# c4 \5 `2 ^6 ^int word; </FONT></P>
- V0 K5 B3 o' }" o' G0 b2 d+ K# o<P><FONT color=#0000ff>/* place the word in a file */
3 C4 Q. j' I9 I4 F3 v y& Tfp = fopen(FNAME, "wb");
' Y5 i: F' X* F ?; R& ?if (fp == NULL)
/ N, s4 H" N$ f: `' W% O{ / C; k8 ~( \2 i2 t# `) n0 B
printf("Error opening file %s\n", FNAME); 7 J, G; U0 Q2 E v
exit(1);
: P$ o/ e) y3 T# ?: V} </FONT></P>
( e: h0 V, [* P/ Z* t' Y; p- k<P><FONT color=#0000ff>word = 94; , C* q0 p% q2 `( V, q+ r! d
putw(word,fp); - { m- z3 o" W% ]" R! Y3 T
if (ferror(fp)) 9 X1 r, U2 Z0 g4 t" y" C5 {; y: e8 r! a
printf("Error writing to file\n"); * D/ U' U/ Y5 K
else * ^" F4 W$ {: [7 r u+ |
printf("Successful write\n");
9 s# F$ k# k. A# j) r3 N% Wfclose(fp); </FONT></P>
. L& r; }* s9 V$ I- j7 G<P><FONT color=#0000ff>/* reopen the file */
/ C1 F) h4 r) E+ `" v* S1 gfp = fopen(FNAME, "rb"); 0 K2 l$ ^9 D6 Y* e+ u" P% e
if (fp == NULL) ! l1 g3 `* H; X: X q( ]) A; k
{
Q5 [2 \3 r) f. Iprintf("Error opening file %s\n", FNAME);
. o6 ^* y& Y3 h# c) L% ~7 U; ~exit(1); ) y5 x, c- j; l: m8 w# B! `
} </FONT></P>
$ Y! _" R% W0 o+ J6 S<P><FONT color=#0000ff>/* extract the word */ ! W( o, V B' T( y1 k
word = getw(fp);
! J, u& h2 r* [if (ferror(fp))
( E1 u9 |& J- |# lprintf("Error reading file\n"); * D! w6 v- b* I+ R$ w$ L1 l
else
3 L, p1 o; Y* S3 [printf("Successful read: word = %d\n", word); </FONT></P>9 ~9 L r E2 g1 _! ^( }+ G) U! O
<P><FONT color=#0000ff>/* clean up */
J* T1 [( ~1 y8 r& F$ |fclose(fp); 6 c$ m) w: i/ b# V2 t3 j
unlink(FNAME); </FONT></P>
/ R2 P4 K" j" e+ ?$ r' i: d& c9 G<P><FONT color=#0000ff>return 0;
: k0 x5 K4 i7 ] H8 N, {" k} </FONT>! g& V2 I# i/ z5 A) T( R& f. S' B
. U W$ R C# L
, `! ] b) X2 m1 Q) p0 M d% k4 q5 w</P>& T( @, l: l8 V8 J8 \5 F' Y
<P><FONT color=#ff0000>函数名: getx </FONT>
: e, R9 R% H# t5 X4 W) t功 能: 返回当前图形位置的x坐标
* Y6 M4 y1 S1 b用 法: int far getx(void); ) \3 E1 x) H: s1 j: ~6 `. _- R
程序例: </P>
* t- T$ H2 F' X! X8 X' i! L<P>#include <GRAPHICS.H><FONT color=#0000ff>( C. g$ Y* }4 k( L2 }' P3 M
#include <STDLIB.H>: {. z; F9 F# N& }# z9 \ r. g
#include <STDIO.H>
: A7 a. g0 k2 M5 G- a, [' Y4 c#include <CONIO.H></FONT></P>% }: q) F4 J. K1 t
<P><FONT color=#0000ff>int main(void) 4 T) l& O7 q# G2 }
{ 8 W) v( }+ N ]* |6 `
/* request auto detection */ . w( g4 n; V' q; g" }) v% U: G7 }
int gdriver = DETECT, gmode, errorcode;
3 T# }7 C) T6 q8 ^8 [char msg[80]; </FONT></P>
# l$ O: I' X' ]4 A8 k<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 B2 z) T# f" m2 `
initgraph(&gdriver, &gmode, ""); </FONT></P>3 z. e, X% z4 t
<P><FONT color=#0000ff>/* read result of initialization */ 7 b/ s. |, B/ M; }! c0 y- X( k
errorcode = graphresult();
8 e7 H8 Q8 o) j" ~. S- Eif (errorcode != grOk) /* an error occurred */
D- Y/ E0 J& f9 U' Q{
4 j8 |% y, R8 i9 _ s) Eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! }$ B3 P2 e3 F$ ?! X9 z( \* V6 Hprintf("Press any key to halt:");
1 v' M7 O( V& @/ S: ?getch();
, Z' {! g! D: I4 q9 r$ oexit(1); /* terminate with an error code */ 6 B* d! t. b8 {! A; `8 N% `0 A
} </FONT></P>
G( f7 M1 ?: h, ^9 K \$ [; f ^& m4 }! k<P><FONT color=#0000ff>/* move to the screen center point */
; v. P3 X6 r& s% m$ {moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>/ x" p E/ }' P7 {7 ?6 g
<P><FONT color=#0000ff>/* create a message string */
& H7 R, d4 B- D' S2 d; x9 Msprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
4 ^& {1 K! M& d1 t9 u! D<P><FONT color=#0000ff>/* display the message */
/ W/ N; ?* p0 {# |# O& A' ^outtext(msg); </FONT></P>
) Q$ L% l, ^9 [& D O<P><FONT color=#0000ff>/* clean up */ ' P; D% f( S- R5 w
getch(); 0 F& e" L6 D/ T, x* h
closegraph(); 4 T' ~7 L% q6 r8 c- D2 e
return 0; 6 u2 \! v6 A2 S8 f5 w4 g
} </FONT>
8 q* [# p0 A! o5 g1 u. {$ G& h: |6 i' C! P* s
</P>
6 @: G$ v* B1 a! ~ i! ]<P><FONT color=#ff0000>函数名: gety </FONT>
( P+ t# H' e4 d9 l3 B* f3 Q% z2 Q功 能: 返回当前图形位置的y坐标 / i2 e8 i8 @9 M8 j$ @" B a1 T& J
用 法: int far gety(void);
E# a6 \: @ n* X& r% u程序例: </P>
7 |! x. |: m/ w( p" Z: [1 l0 W<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 W% l% t+ ?( A/ ^5 h p: D#include <STDLIB.H>
% S# L( l( X% a( V% K#include <STDIO.H>
# {8 \3 A) t( m; ^8 P) y* E0 `: P#include <CONIO.H></FONT></P>- J( c0 w/ v$ ~6 A; R- w
<P><FONT color=#0000ff>int main(void) # S# n) J% e0 E" v' i& w# m7 W
{
* H1 J" [- ^0 @# f/ ]: P! Z/* request auto detection */
4 E/ ~0 b1 a4 ^( a5 Tint gdriver = DETECT, gmode, errorcode;
4 N" s3 o j$ {9 }0 Y3 ichar msg[80]; </FONT></P>
6 O: O% P; ]# X& _. f! ^' U& \<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 i* w* q7 `( i; Z' zinitgraph(&gdriver, &gmode, ""); </FONT></P>
: F/ y; ^, o: }) T& m* B<P><FONT color=#0000ff>/* read result of initialization */
5 B' w4 x x/ [; p, l& r1 ^errorcode = graphresult(); $ `* `4 q. H, j1 u1 F2 G. Q3 Y! l8 m
if (errorcode != grOk) /* an error occurred */ ) `' o5 F$ {. O, I1 k$ Y
{ ' v6 _ ^4 M* _6 |" V* d4 K
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ d- n% \4 u# E9 A7 Z! M) ~printf("Press any key to halt:"); 0 V. B- @4 W% H- ]. v P
getch();
1 e6 r1 [6 d, Q3 _3 S# gexit(1); /* terminate with an error code */ : H7 {5 O& D8 a8 s
} </FONT></P>& H0 l$ Y+ s0 ]1 g s! f3 |
<P><FONT color=#0000ff>/* move to the screen center point */ / M! ]9 q0 e2 j
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>5 w" j4 d {" _& j, Y# w
<P><FONT color=#0000ff>/* create a message string */
3 y1 G% {: d) `0 i: A: `& `7 a0 Nsprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
6 g6 k5 u5 x& K$ H& c<P><FONT color=#0000ff>/* display the message */ # h6 v* D6 V, K
outtext(msg); </FONT></P>
: N3 V% |6 `' r<P><FONT color=#0000ff>/* clean up */
4 n1 s2 P% v; J" Wgetch();
% a" I. Q- X5 x3 gclosegraph();
9 D- f. h3 v m. V5 W" m' Ireturn 0; : A9 f0 n! u, K- f6 y9 O1 }
} </FONT>
* @5 |# N) l0 t; @* o) C/ O: g3 K) e: h& r! K2 @
</P>! A6 F, ?# ~( U, ?1 C- M9 Q
<P><FONT color=#ff0000>函数名: gmtime </FONT>
- l$ W, j3 u e& s2 I/ h功 能: 把日期和时间转换为格林尼治标准时间(GMT) ( l1 l$ L$ A1 L; C }1 X; o9 n
用 法: struct tm *gmtime(long *clock);
8 ^7 _& W; A! {8 N& S- R程序例: </P>
& e T' `1 O; ~: F& A* j; T<P>#include <STDIO.H><FONT color=#0000ff>- s4 ]2 T! a2 m# R
#include <STDLIB.H>
8 M) l. B8 U0 n) F; }$ k/ K ^#include <TIME.H>" W0 g* _3 Q' {1 A" x5 n
#include <DOS.H></FONT></P>
, ~( q, J8 c7 N9 s9 ^$ s4 Y<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */
( |" Y! E. l; Q0 }9 pchar *tzstr = "TZ=PST8PDT"; </FONT></P>% M% y% O% Z7 V6 p/ t# W
<P><FONT color=#0000ff>int main(void)
% I) x+ u$ K8 f3 N{
) ]5 c- L5 b( D- l6 r4 {% Stime_t t; : q9 @' y% a( e) g5 ]. _/ m
struct tm *gmt, *area; </FONT></P>
1 a# S: [8 k$ E1 U<P><FONT color=#0000ff>putenv(tzstr);
* I+ P' `- l& b" [9 @, k8 Z$ ktzset(); </FONT></P>, ?7 S- {" q9 }/ Q" M
<P><FONT color=#0000ff>t = time(NULL); 0 _8 l7 d0 d# U6 f$ c$ @
area = localtime(&t);
* w5 h9 b! b; H$ ^1 [2 Mprintf("Local time is: %s", asctime(area));
; v0 J% H9 j; K( l$ r; Rgmt = gmtime(&t);
$ y/ l5 K, R7 Y9 d6 Bprintf("GMT is: %s", asctime(gmt));
) e5 O; v& c3 J7 \2 Qreturn 0; 9 j- m: y+ a, I2 T1 l
} </FONT>3 z5 y% _4 m# P
. R4 M8 x% O; b' e. p4 E6 c) K& e</P>
$ Y# [) r" [7 z! M8 {<P><FONT color=#ff0000>函数名: gotoxy </FONT>
4 H, R4 O0 \# K+ R' x4 N6 \* a! S功 能: 在文本窗口中设置光标 " ~/ k# C( s7 }5 Y
用 法: void gotoxy(int x, int y); ! Y4 k. }) v+ ?4 u) b
程序例: </P>
5 V, x2 X3 g0 }<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>1 B( F/ v2 ^& }1 e% Z7 K1 H: N1 p% U# Y
<P><FONT color=#0000ff>int main(void)
. B/ b5 J/ c/ r" J) F) O{
0 a2 r9 o+ P9 Q" m3 D% J9 oclrscr();
5 U/ v, C+ J' u9 F5 Hgotoxy(35, 12);
0 s" C b; I( }7 p; s$ [cprintf("Hello world");
; R$ D( `! a" T5 F9 E9 tgetch();
8 T- O$ u4 x& K% zreturn 0; 6 p/ m& T9 Y; P
}</FONT>
, M) J0 ^$ V5 {8 d% R f- i9 @4 G! A. K5 j [
</P>4 k: f! s, T& D* ^/ C# Y; c' J/ Z
<P><FONT color=#ff0000>函数名: gotoxy </FONT>
6 M% L5 S' M$ p% M. m功 能: 在文本窗口中设置光标
. E; f& L% r3 P4 I用 法: void gotoxy(int x, int y);
' h& z3 K: M# G9 h! u程序例: </P>
% n) _# p! e1 {0 p<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>/ Y; J) t0 E! v* h4 u( n6 v0 w' e
<P><FONT color=#0000ff>int main(void)
' J/ @# k" j+ ?1 W. p{
& T7 |: D" P: h* L Y. m& ^clrscr(); 9 G" r7 d& a, C* `, _
gotoxy(35, 12);
* u, H o2 q0 i" S. p0 y; rcprintf("Hello world");
: T8 h5 P. c5 u; z" Q0 @getch(); , [; B! d4 u A6 C
return 0;
) ?; U. ^$ _% ?- n) ^0 S( o} & }( d+ n' i3 y* v, i; H i& k( R$ n
</FONT>/ P* ^2 o. P7 q: s
</P> |! i' x7 I; C
<P><FONT color=#ff0000>函数名: graphdefaults </FONT># V, R. y' y9 E; l
功 能: 将所有图形设置复位为它们的缺省值
: T- W3 H$ \7 o+ c, H8 v* b0 D用 法: void far graphdefaults(void);
1 { C: Y) W' M- ]程序例: </P>3 M$ u. | o; A, K
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" x6 B+ t& G; H% v3 a+ R* B. l. ?#include <STDLIB.H>
. s4 O9 {' G) |5 x7 [7 H#include <STDIO.H>
9 D7 V% f W8 K/ \1 l( r#include <CONIO.H></FONT></P>
* R3 a+ E8 _/ e- F<P><FONT color=#0000ff>int main(void)
0 @2 A3 K h* Q0 l+ ^2 \& }' r1 \{
, t) u# N9 O7 E6 `/* request auto detection */ ; j6 |9 S& J1 T3 i E
int gdriver = DETECT, gmode, errorcode; 3 C. B& b- r$ i* q1 L2 ]! V
int maxx, maxy; </FONT></P>
. l) X2 o1 s' p<P><FONT color=#0000ff>/* initialize graphics and local variables */ M9 ]( \. r. A& y" R3 F
initgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
; m- {; F4 b& j+ s. h8 Z<P><FONT color=#0000ff>/* read result of initialization */ 0 A4 |0 h1 h. L& f1 P; Y( j0 d# n
errorcode = graphresult();
3 v$ F) j$ i( h# r. D3 ^if (errorcode != grOk) /* an error occurred */ 4 y, ?) U( Y+ `' J( D
{ 4 J. [9 R0 h- I7 J, J) g" B
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % A$ a+ Y, b7 {# x" y& y
printf("Press any key to halt:");
: [- J* D0 a# g+ x3 ~7 Dgetch(); ( x3 H3 l! T# @* Y2 R. p/ k
exit(1); /* terminate with an error code */
' @/ x4 a% F- A- l% i} </FONT></P>% A# T9 s8 W0 L) B
<P><FONT color=#0000ff>maxx = getmaxx();
- R0 d5 i. C+ ?2 C lmaxy = getmaxy(); </FONT></P>
: d2 l" F& _2 G4 o. L2 f- m<P><FONT color=#0000ff>/* output line with non-default settings */ 5 J' P7 j9 R G: I1 R
setlinestyle(DOTTED_LINE, 0, 3); ) m& w2 _3 @* H* A9 ^' O: k, K7 [
line(0, 0, maxx, maxy);
( ^, e9 u! k) |: W& ^% u7 Y: ~outtextxy(maxx/2, maxy/3, "Before default values are restored.");
1 A- B# L) l2 Z& O( ogetch(); </FONT></P>8 l: |2 F' y5 T+ m5 b" b
<P><FONT color=#0000ff>/* restore default values for everything */ 7 l) T: O# i5 y$ y) H3 L P
graphdefaults(); </FONT></P>
, h {. M- E! r% c8 v; |. A; |3 L<P><FONT color=#0000ff>/* clear the screen */ ; z5 p" m3 S2 r4 ?4 n. }
cleardevice(); </FONT></P>4 n( V, C4 O- h0 w7 q8 ]
<P><FONT color=#0000ff>/* output line with default settings */ / j3 j+ u2 `# {! _
line(0, 0, maxx, maxy);
+ S, P% ?) C; Y/ | jouttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
; J. M" z0 j( u) m8 [4 ^<P><FONT color=#0000ff>/* clean up */
9 A" t1 r' _# X7 p" s% B! }getch(); ! E$ M' l4 ]* E' Q' N' y
closegraph();
. R+ J% J2 N1 }5 C* ~$ jreturn 0; # R( y' G+ F' K3 S4 v0 `! F( U
} ) ^% t5 B8 c) e
</FONT>6 E5 n! s7 B! P
</P>9 M- F* N) _; R& E% m
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>- e: I8 Q+ b4 X/ v7 v
功 能: 返回一个错误信息串的指针
2 @4 [5 ~4 x; _( v用 法: char *far grapherrormsg(int errorcode); 5 ^& t- L2 \2 U/ q0 d, }: r" U4 A. v
程序例: </P>
4 s+ j* t1 P; u2 I/ ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 C0 A$ }6 e6 B! x0 u/ m, M! j# K6 E#include <STDLIB.H>
7 v' I3 E$ J: C#include <STDIO.H>
2 ^0 S* z6 h- [#include <CONIO.H></FONT></P>
' Z" K* k7 ?+ K; t+ k5 X/ e/ |<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
' ^" M6 g# a' l0 [# a6 X0 l<P><FONT color=#0000ff>int main(void) % Y+ J. A/ D: G j1 v$ z
{ 9 z/ \# A' A+ ?# M$ N! ~" l. X
/* FORCE AN ERROR TO OCCUR */ 6 D) M+ E6 o( Y; e) I. F
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>
i4 {+ M, m- w* z<P><FONT color=#0000ff>/* initialize graphics mode */ 9 y* f0 T# a6 Y, A; G$ X
initgraph(&gdriver, &gmode, ""); </FONT></P>
2 P5 v+ T- |2 K1 H6 V<P><FONT color=#0000ff>/* read result of initialization */ & A. m" T& l7 R y } _6 [
errorcode = graphresult(); </FONT></P>& X5 w, i# y; H% y3 U& [6 [5 W
<P><FONT color=#0000ff>/* if an error occurred, then output a */ ( _" c- x8 y1 e6 O
/* descriptive error message. */
, I4 g6 x4 c( V% Iif (errorcode != grOk)
6 ^ C3 Q2 @1 G: n. q/ L, ?{
. `1 p5 y% X. R* d1 Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 O5 M3 Z( K3 ~printf("Press any key to halt:");
4 O: n/ g- A" d9 u/ b& A0 Lgetch(); ( M' `( G3 Q- E) i6 C
exit(1); /* terminate with an error code */ 9 _2 z/ U8 ?; ], l
} </FONT></P>
8 d5 }# F! _4 T: N* I9 ]<P><FONT color=#0000ff>/* draw a line */ 0 p4 N& C! e3 l9 P7 ?3 Y
line(0, 0, getmaxx(), getmaxy()); </FONT></P>( C( I2 b: K- Z9 g$ O" w& t9 ?; F
<P><FONT color=#0000ff>/* clean up */
' W9 i! }1 m# {. {1 Ugetch();
# C2 R' X4 _) A; ~, fclosegraph();
- r! Z3 w3 E) F* d ?4 Oreturn 0; 0 S% J1 }8 ~# Z
}
' O4 m" ?$ @; h4 W$ w</FONT>, U+ }' ], g; N0 C$ c
</P>9 C1 V, w& d/ R) W2 ~
<P><FONT color=#ff0000>函数名: graphresult </FONT># m! E6 n4 ]' d( m
功 能: 返回最后一次不成功的图形操作的错误代码
4 x6 E0 G7 a; ?: K r5 f用 法: int far graphresult(void); : G ~6 e2 j2 m7 Y
程序例: </P>
6 \. C: @1 F& i<P><FONT color=#0000ff>#include <GRAPHICS.H>
* T! d/ k% h' N* }, r1 [& b#include <STDLIB.H>
3 m1 i. D) [6 B/ a; y7 q#include <STDIO.H>
& n0 c5 p ?& ?& s. l# m#include <CONIO.H></FONT></P>) T6 ~* c6 @8 X' W; I9 {5 ^
<P><FONT color=#0000ff>int main(void)
3 S$ ]0 b1 T) {7 ]' k0 w* d+ Z: R{
0 k/ t* j% m `+ {' c9 }3 C/* request auto detection */ : F1 N# T1 C' ^/ t, z
int gdriver = DETECT, gmode, errorcode; </FONT></P>: t1 @: H \$ j7 o1 G. y2 D
<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 t1 w8 P+ w5 ?5 Yinitgraph(&gdriver, &gmode, ""); </FONT></P>
# T& x1 {; V! Y) _1 }9 D; Q# X<P><FONT color=#0000ff>/* read result of initialization */ . k! W* l. L6 W$ d$ V+ M: a
errorcode = graphresult(); </FONT></P>$ t' C1 f. v3 p9 N9 @1 g
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */ ; w: n' U3 ~6 s* T# _
{
" ~8 N: }0 _7 B+ Yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. |3 S: Z; {# N5 m. s' X$ zprintf("Press any key to halt:");
1 Z( o3 m t6 I3 |getch(); ! [+ V% m, u. K( ^* ]' g" w
exit(1); /* terminate with an error code */ ; g0 _( h( A2 z4 \" ]
} </FONT></P>
" T6 V3 {4 T0 f* B* W<P><FONT color=#0000ff>/* draw a line */
; x9 O: ^5 f+ P% N+ d. Nline(0, 0, getmaxx(), getmaxy()); </FONT></P>! E; F- Q# R# R8 B1 h' q, ~/ w
<P><FONT color=#0000ff>/* clean up */ 8 j$ W0 d" D& b# {( F) J! D* g& j
getch();
6 K1 @- F( H% ]2 m6 N* {. Jclosegraph(); ( ~8 B) z. g; @9 P( D
return 0; * I) ^: y% U8 U8 U) ~: u# _
}</FONT> - [2 Z* g4 A6 n, w- m) O+ [
</P>+ ~$ G1 K- Y* I7 i+ g0 l
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> / _: d4 S. {, x" o7 _5 H
功 能: 用户可修改的图形存储区释放函数 / ?8 C2 @# ]+ d/ L0 G
用 法: void far _graphfreemem(void far *ptr, unsigned size);
( U" C( v4 P& M8 A, h# L. Y- ~程序例: </P>
% l- I5 d# Z. p7 \: N+ b$ C<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 s D5 x+ ` S& a* M#include <STDLIB.H>3 c/ F s% q5 f3 C$ K3 @, c+ v) A
#include <STDIO.H>. M3 l: z& `! C7 U A3 }' F
#include <CONIO.H>
) A' I4 V2 k, `' z; G" O#include <ALLOC.H></FONT></P>
0 C$ s4 C8 i# W3 I8 x _9 ~<P><FONT color=#0000ff>int main(void)
; y. x+ P" |3 n; T" I' s{ 7 y/ H& W1 X$ }8 ^: f& u2 i
/* request auto detection */
B: i4 z; y* V6 d% y' g+ T& zint gdriver = DETECT, gmode, errorcode; 8 B( @4 Y5 J6 @8 |' x: d
int midx, midy; </FONT></P>
% q; d7 p6 x1 m9 h+ V<P><FONT color=#0000ff>/* clear the text screen */ 8 \1 ]( n" T3 u4 a4 w! ^
clrscr();
; K3 x7 g& ^1 Y! T/ }7 `printf("Press any key to initialize graphics mode:");
6 o+ e0 M7 |) Qgetch();
/ x! a& I* `9 i- V* H- F1 L1 eclrscr(); </FONT></P>) _* }4 u5 u7 E: C6 m1 L
<P><FONT color=#0000ff>/* initialize graphics and local variables */ : d' I! M0 X9 y' q0 p( J8 {8 A- t* K
initgraph(&gdriver, &gmode, ""); </FONT></P>: d- h5 e5 S- D2 R4 X
<P><FONT color=#0000ff>/* read result of initialization */ 0 J/ O5 [* t8 C% | J
errorcode = graphresult();
9 p! R8 I6 y# E& Q7 q2 tif (errorcode != grOk) /* an error occurred */
( h# v) k. @1 P* v{
3 `& |" a& F- ~, |" J$ Zprintf("Graphics error: %s\n", grapherrormsg(errorcode));
: y5 l g6 U8 K0 P0 Vprintf("Press any key to halt:"); 0 e# |- E, w3 W8 j! E
getch();
5 l1 u# ?. `$ O7 i8 g) Xexit(1); /* terminate with an error code */ & Z$ J7 Q! [" P8 T* r& u: Y% V( D
} </FONT></P>: e- N7 x- O! N+ X$ e
<P><FONT color=#0000ff>midx = getmaxx() / 2;
4 V4 p2 I. D5 H, V% ~3 vmidy = getmaxy() / 2; </FONT></P>0 Y3 ]5 C; g* [ y7 n' i
<P><FONT color=#0000ff>/* display a message */
. R# @& s4 |* z2 r$ u8 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); f- \# R: P$ R( }
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>. |2 P* X' r# U+ r( V1 u
<P><FONT color=#0000ff>/* clean up */
# y" p4 X3 l0 c( d; P8 D" |4 k/ Z! a! {- Cgetch();
7 J! X7 K/ M* |6 l& L& `closegraph(); 1 l, M6 c: C+ {0 J; J i, J
return 0;
. n6 @5 k/ p# @- P5 O6 }- ~} </FONT></P>- `- D0 D9 x; F8 t
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
1 x4 i$ A& H7 E* q" avoid far * far _graphgetmem(unsigned size)
3 X8 a6 P0 j9 J* n' z: X{
& n3 j" i; s* d. s0 ~9 Uprintf("_graphgetmem called to allocate %d bytes.\n", size);
7 e5 n, j1 C3 t9 B+ X+ dprintf("hit any key:");
) z! E0 _1 s0 E4 r) G; @! m9 R" Bgetch(); 9 Z6 o/ ?0 u8 C' C& ~, [
printf("\n"); </FONT></P>
' D Y$ D. c9 t* d' \2 D+ {<P><FONT color=#0000ff>/* allocate memory from far heap */ * e; B5 R' O( m/ G& I
return farmalloc(size);
6 D& Y `) ] e% e# s* s' D} </FONT></P>
/ l' F7 G/ G+ n6 x<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
) _: C, i( c* i# \6 z `" Q4 o, Nvoid far _graphfreemem(void far *ptr, unsigned size)
7 U- S8 f- \ ]& F# t0 V{
7 M9 @1 J& V' j8 R) j0 c' xprintf("_graphfreemem called to free %d bytes.\n", size);
5 x: `: a! ]* d% B) r# z( `+ @printf("hit any key:");
3 _' }) T: m4 `. egetch(); 0 z, s; i4 Q3 m2 Z- u
printf("\n"); </FONT></P>
8 l2 K' c* g" V6 ]0 F9 `1 C) p4 F<P><FONT color=#0000ff>/* free ptr from far heap */
0 Z& }0 `9 c' U: Y" Bfarfree(ptr);
' [+ i4 o: B" W; w' X& w- U9 d} 7 j0 t, k$ g" W
</FONT></P>
3 A# C5 T5 J; m5 c- _<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>% H* N2 _% R$ i
功 能: 用户可修改的图形存储区分配函数
$ E$ G* o1 E% ]用 法: void far *far _graphgetmem(unsigned size);
# ], P3 G& Q- q" U+ J程序例: </P> E& Y" e8 ~, N- Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ A+ ^& V% T$ t$ Q#include <STDLIB.H>/ Y2 C9 ?* Y: A5 l z) E
#include <STDIO.H>6 y3 S, N6 d1 C' a6 {* Z
#include <CONIO.H>8 Q' L* g' ~& Z! e- ^0 p1 l
#include <ALLOC.H></FONT></P>9 W8 Y0 r [) q
<P><FONT color=#0000ff>int main(void) : e) ^! X; C9 c+ t, Q" H% \
{
9 d) f, w. z6 c/* request autodetection */
. w& E! m: ^0 t$ e3 ~int gdriver = DETECT, gmode, errorcode; 1 {3 I# k/ d& U% }- v
int midx, midy; </FONT></P>
4 |) z2 I' K% i1 k! g$ [# ?<P><FONT color=#0000ff>/* clear the text screen */ - [3 e! o( e% x: s
clrscr(); 7 d& d* r F0 R, _
printf("Press any key to initialize graphics mode:"); 9 g3 o. c" q# S0 j, n% A# E0 E" d
getch();
) ?% s0 f+ o% `: [: Fclrscr(); </FONT></P>5 H! t1 t( i3 j& t. m8 z7 F" |
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ ^ i: u8 q* P3 Z( binitgraph(&gdriver, &gmode, ""); </FONT></P>
+ l# V: a4 E# O2 f: \$ n" y0 k5 Y* {<P><FONT color=#0000ff>/* read result of initialization */
Q8 z2 i4 ^- C* M, f9 Oerrorcode = graphresult();
* Y7 s7 a, C$ d) O( V0 }2 g* Uif (errorcode != grOk) /* an error occurred */ 4 b. T, K/ J2 u+ b6 g
{ # R; {" h% l" B; G
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ s$ d+ L6 W0 b+ \9 I( Y4 [+ S" Fprintf("Press any key to halt:"); 7 p4 J' I5 w* n/ T1 t
getch();
, f4 }' S4 Q9 x. Mexit(1); /* terminate with an error code */
$ s, g' z4 V5 S} </FONT></P>" a6 P1 f4 n5 d
<P><FONT color=#0000ff>midx = getmaxx() / 2;
! @1 C) ~$ ^0 o) @4 [2 _midy = getmaxy() / 2; </FONT></P>& ?* w7 D8 Y$ |' G6 X
<P><FONT color=#0000ff>/* display a message */
; b' K9 P: p$ X# o% n+ ssettextjustify(CENTER_TEXT, CENTER_TEXT);
* \- A. E G% Mouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>6 ]- R! J8 M" w' B& j j9 T
<P><FONT color=#0000ff>/* clean up */ / b" F' I9 W; Z6 O1 J, R
getch();
6 n4 F' A' V/ t9 b! tclosegraph();
' G! X' C' d+ mreturn 0;
- h% U% D- |' M5 r! Y+ |} </FONT></P>
7 f6 n! g7 d: K4 n4 A! B<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
! V, _% f1 ]7 U: W9 U: D6 [: d* ~void far * far _graphgetmem(unsigned size) ; \8 v) x" C0 D
{
/ l. \. B# h2 J* d/ T& |& ^printf("_graphgetmem called to allocate %d bytes.\n", size); C+ t6 ]: `7 Z H
printf("hit any key:"); - B% M! C! D0 z6 ^7 ]2 S% c
getch();
* c" T1 j0 h1 G. M6 K/ q! i& {1 Aprintf("\n"); </FONT></P>5 R5 y6 p8 h: v7 ^6 Q: I6 n
<P><FONT color=#0000ff>/* allocate memory from far heap */
8 Q! T1 q5 E! freturn farmalloc(size); & V+ S# d* t+ w `, a- s1 a$ h# S
} </FONT></P>
3 ^; f# p$ E" Q2 z% Y<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ - b- ]+ }$ q) N. k( J. a T( @
void far _graphfreemem(void far *ptr, unsigned size)
% ~1 F, m2 P, H4 g7 n& G; D2 c{
* I J, D# n( {1 Kprintf("_graphfreemem called to free %d bytes.\n", size); # R" n* m( S4 J( J) a
printf("hit any key:");
* U7 A) H4 a. T0 T% I& S" ygetch();
?- |9 p8 f' Uprintf("\n"); </FONT></P>
7 F i' _, r9 y# P6 a' F<P><FONT color=#0000ff>/* free ptr from far heap */
U- h% X; ]+ ]6 u, a8 rfarfree(ptr); ! i1 ~* Q3 C: h9 o0 U
}, O) z7 c+ z& w k2 \; l
</FONT></P> |
zan
|