- 在线时间
- 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>" x& _4 l5 B) P) e/ B
! T' y& v, k6 R; _/ ~5 @
T1 x& s3 L: t$ I6 a
<p>4 d+ ?' l$ b9 e6 O% |4 |" K* ^$ z
< ><FONT color=#ff0000>函数名: gcvt </FONT>/ V1 n+ r& m4 h Q& A4 I
功 能: 把浮点数转换成字符串 7 Z7 p. o0 a, o# n: y3 f& V3 P' {; e
用 法: char *gcvt(double value, int ndigit, char *buf);
/ s: {% K* Y8 p" z程序例: </P>( v. ^5 [; J% Z7 K" m- V( ]
< ><FONT color=#0000ff>#include <STDLIB.H>% b2 d. P% `( g/ q# O' L) e
#include <STDIO.H></FONT></P>3 p/ ^( G+ @2 g% u
< ><FONT color=#0000ff>int main(void)
8 W7 n' y2 Z) i+ T' n2 k* f7 B{ 9 m7 |4 c' ^# x2 {
char str[25];
! i, }9 I9 O3 K8 L* W7 kdouble num;
4 Q; S+ K/ N- ^( ]# Z* m5 [int sig = 5; /* significant digits */ </FONT></P>! V+ g. l; W! h5 s1 V& e( h1 t" m: L
< ><FONT color=#0000ff>/* a regular number */ 4 b% M9 o8 j+ g# k0 Z8 o/ u
num = 9.876;
9 F$ U& L( N) J( V; Ogcvt(num, sig, str); * X) t0 X9 {: ?8 i; f
printf("string = %s\n", str); </FONT></P>
$ L. ?0 k5 h6 m' i9 y; z4 B# ~ O5 D< ><FONT color=#0000ff>/* a negative number */
5 K8 x; j1 D$ ?num = -123.4567;
) h- o8 ~3 E7 k. Q- \/ X0 qgcvt(num, sig, str); 6 s+ w- }$ l, S$ Y$ x- v, C
printf("string = %s\n", str); </FONT></P>% a, \. ?1 @( L# M. B& n5 s: g- ?
< ><FONT color=#0000ff>/* scientific notation */
3 \" _, l1 ~, xnum = 0.678e5;
* g0 j8 [+ u1 i: ygcvt(num, sig, str);
& I# d6 k2 u: l0 `printf("string = %s\n", str); </FONT></P>. g7 }1 v% [5 g9 x; b
< ><FONT color=#0000ff>return(0); V1 J' E" D2 W) W6 f. j9 N$ {
} 5 O9 P: U7 c; d' @5 T- V
- E- ]0 \8 R: D( W! F
</FONT>/ K4 t G. \% Y# Y' q9 `$ b' s
</P>9 h6 z3 D5 t* K" v$ ]5 l
< ><FONT color=#ff0000>函数名: geninterrupt </FONT>
( b, B. m# c- ~; @7 b功 能: 产生一个软中断
7 L' G2 ?1 @% t用 法: void geninterrupt(int intr_num);
# m- K: d, t# R1 ~( a& {程序例: </P>
2 `; r: t( U+ o- [. E9 P< ><FONT color=#0000ff>#include <CONIO.H>
3 c7 N5 f+ f" I" `+ L#include <DOS.H></FONT></P>
5 P( s4 K/ z: Q! Z/ |: O! E< ><FONT color=#0000ff>/* function prototype */
9 z, `+ v0 A- j9 g# d- {6 n7 Lvoid writechar(char ch); </FONT></P>
! `3 T& Q/ k, _- k9 W, [< ><FONT color=#0000ff>int main(void) ! Z& A. o' L7 e( }* l
{ 0 p4 E: M- m4 a! m+ u- a- f
clrscr(); ( u* Y9 x8 k `: Y8 H
gotoxy(80,25); 8 S M+ j& K, c! C
writechar('*'); / S/ ^! Z+ R; o6 m0 R3 S( `
getch(); # ~7 E2 Y8 Z, c/ R/ j
return 0; # D% h h" l7 A2 v2 k. N0 O
} </FONT></P>
1 t- _, \$ z& G' u: f< ><FONT color=#0000ff>/*
. m m; L1 ^7 M: R/ x3 T' A" voutputs a character at the current cursor + q3 T* S9 p$ i
position using the video BIOS to avoid the
$ W4 j% X) \4 H J( l3 I7 ~scrolling of the screen when writing to 1 Z5 x: ?0 [( J7 q v* g' d4 y
location (80,25). , N* x( \3 I8 P p2 [3 z" f4 I) i' n
*/ </FONT></P>
5 V, ~+ G: \2 _/ |< ><FONT color=#0000ff>void writechar(char ch) ; b# F0 B7 |! _4 h: g! k
{ ' x2 w( \0 f( t/ d$ Y
struct text_info ti; # V4 g( j) b) e+ L1 R B7 K7 Q
/* grab current text settings */
& d7 @: ^ h0 t3 _* u& Lgettextinfo(&ti); 5 q; g2 R B5 U, B! @. c% F
/* interrupt 0x10 sub-function 9 */
9 v) }/ F3 S6 |4 B$ `4 l_AH = 9;
& N' S- H: X# j ~/* character to be output */ % ` J3 a+ E5 v$ W* A" O+ F* P
_AL = ch; 3 ], d% q i4 H6 n
_BH = 0; /* video page */
, b0 x* R$ b% v0 m- Z_BL = ti.attribute; /* video attribute */
4 g3 o9 k+ I" ]1 i+ d+ C# B# |2 b_CX = 1; /* repetition factor */ 4 I( S* Z6 C. u/ ~3 P1 d! P
geninterrupt(0x10); /* output the char */ " T* S& x; ?6 Y8 s
} ( q+ w+ ~1 p' x; S& e5 H( Q0 v* I. Y
</FONT>, p. n; D+ b; T4 N- }
</P>
0 X6 n8 f8 O: [< ><FONT color=#ff0000>函数名: getarccoords </FONT>/ L9 M8 Q' w' _& P( Y
功 能: 取得最后一次调用arc的坐标 * Z+ r6 d5 t7 g
用 法: void far getarccoords(struct arccoordstype far *arccoords); 5 S1 P0 b: c! P
程序例: </P>4 u9 W0 q& P) n( g8 Q
< ><FONT color=#0000ff>#include <GRAPHICS.H>5 x6 O5 ]1 l: |5 i3 n6 D$ Y! n3 [
#include <STDLIB.H>. Q( V! n% s; F" u% C$ {
#include <STDIO.H>1 S# ]( y# | B' g, d
#include <CONIO.H></FONT></P>
2 Y% l8 [9 Z' _: ~; k< ><FONT color=#0000ff>int main(void)
/ Z% \2 E7 ~8 \3 o* s& y* i{
; u2 d. ?" j2 C3 i5 A6 A+ [2 |& T/* request auto detection */
' G) R& n( h8 W9 o8 Wint gdriver = DETECT, gmode, errorcode;
! }" d0 A- H' v0 H Bstruct arccoordstype arcinfo;
! G! U- g0 Q/ J O; L% Gint midx, midy; 8 A, y/ x: I e" j. G+ {, Z0 c
int stangle = 45, endangle = 270;
/ y: H/ |2 I& o& b) H9 N- h$ Cchar sstr[80], estr[80]; </FONT></P>3 _, {! z+ M" h" ~' j4 c$ I) g
< ><FONT color=#0000ff>/* initialize graphics and local variables */
9 Z0 m0 u& L* t1 F, rinitgraph(&gdriver, &gmode, ""); </FONT></P>
, B- b s# z1 Y4 ~- u0 C& _< ><FONT color=#0000ff>/* read result of initialization */
: S* Y6 l0 V2 d$ G/ v$ D werrorcode = graphresult();
6 j' _5 _9 C; k1 E$ |3 T2 T U( g/* an error occurred */
0 Q9 j7 X/ R( `* Z% L0 I# Vif (errorcode != grOk) $ u) [8 ]6 T: y* s- p
{
, D/ J" \3 j3 O! I* ]$ z( {# R( Aprintf("Graphics error: %s\n", 1 a$ ]: ]8 r- r ]% E$ A$ @
grapherrormsg(errorcode));
6 I1 ]" y b/ h$ Y! jprintf(" ress any key to halt:"); " B1 T" p( @1 U N# l# i; q$ ?
getch();
' m& \, h- g& w/ c( W/* terminate with an error code */ & z7 V! ?7 j0 V! L7 r4 u1 |/ u
exit(1); ! N1 b9 T6 d! d7 }
} </FONT></P>
1 K# Q# @/ B5 V' u+ K< ><FONT color=#0000ff>midx = getmaxx() / 2; . @ v. [$ {( d0 A
midy = getmaxy() / 2; </FONT></P>( J% N/ e. M2 H
< ><FONT color=#0000ff>/* draw arc and get coordinates */ ! V# s- K4 f2 ^
setcolor(getmaxcolor());
3 k9 Q+ ^3 C I9 Q. A! _2 Qarc(midx, midy, stangle, endangle, 100); ) b+ g* t& Y# L8 w6 d* |
getarccoords(&arcinfo); </FONT></P>
2 y2 t4 c( V# |; ]< ><FONT color=#0000ff>/* convert arc information into strings */ / ?, O; t4 P5 v; \
sprintf(sstr, "*- (%d, %d)", & f9 z$ U1 k6 D0 @, }1 C y2 z
arcinfo.xstart, arcinfo.ystart); * p, J8 t) w! c& C9 C" S0 N1 c
sprintf(estr, "*- (%d, %d)",
9 Z" a) Y* s; l% l! u& Harcinfo.xend, arcinfo.yend); </FONT></P>
/ Q( F2 K& U: w7 n( ?< ><FONT color=#0000ff>/* output the arc information */
# T' A& J, a# F* qouttextxy(arcinfo.xstart,
4 q/ p* D: o0 S5 H# a5 Z& l1 W5 rarcinfo.ystart, sstr); 9 L: ^" w A) d* x2 F' D) U2 ^5 [7 l
outtextxy(arcinfo.xend,
6 u3 U7 \9 Y+ L& x x" |. t. S( `" xarcinfo.yend, estr); </FONT></P>
7 N" O+ }! z9 f8 r8 t9 t< ><FONT color=#0000ff>/* clean up */
6 ^ h4 X7 x. [$ x) `0 j% Agetch();
' O9 b Y) q. W* G" ?closegraph();
& H" U5 d7 c2 f( ]# Xreturn 0;
9 \% G4 |2 t+ H' G& |" D" u" J9 _}
$ o; ~$ I M2 ^9 B</FONT>- a" V S3 n0 q0 e) w* R* _- F/ P0 H: ^
3 U' b" X( f2 ?. i, ]4 I</P>
& L. R5 A. d+ @) I< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
. c6 v& v9 N/ m6 J, {) j功 能: 返回当前图形模式的纵横比 ; U' w# G7 T5 B# L. M6 H# y
用 法: void far getaspectratio(int far *xasp, int far *yasp); $ w7 Q; F3 l0 V
程序例: </P>
: E$ A# a! U% S< ><FONT color=#0000ff>#include <GRAPHICS.H>
: N! h" C2 H4 M# K r/ I) s6 ^4 @#include <STDLIB.H>
' @# d* i; x8 P" X#include <STDIO.H>9 n) ?0 E. B6 L0 ?+ N1 s
#include <CONIO.H></FONT></P>* ^$ s6 ]9 q. P% C: u/ b# t; u9 E
< ><FONT color=#0000ff>int main(void)
# B6 k( ^7 I9 q6 [ l6 t: Y{
9 K8 s; z2 ^! I. r% F) Y! U& t4 l& v/* request auto detection */ / x, I4 W" Y8 M( K& N
int gdriver = DETECT, gmode, errorcode; # _# \% Y" R* `, _: ]- }0 i
int xasp, yasp, midx, midy; </FONT></P>& j u& u) P( Z4 n& q# k
< ><FONT color=#0000ff>/* initialize graphics and local variables */
% z$ ]. W9 t6 M6 R9 t9 k/ d' Ginitgraph(&gdriver, &gmode, ""); </FONT></P>$ @& p4 W( t6 U2 G5 S0 z4 V
< ><FONT color=#0000ff>/* read result of initialization */
- D6 ]8 t8 s- oerrorcode = graphresult(); . J% c) R! y1 `
/* an error occurred */ , z7 U# ~& F+ h! P( R' P6 A; k
if (errorcode != grOk)
8 e1 e- x4 B9 y' R3 w) s k{
8 ]& {. g# n# h5 dprintf("Graphics error: %s\n",
: d2 P" J5 O U0 Y0 |. L; W. Igrapherrormsg(errorcode)); ; v* p" p5 C& S; ]+ C$ n
printf("Press any key to halt:"); . y$ i# ~" x% `7 W1 e" j" n! a
getch();
# J9 C, S5 X. n* E; h1 R, C/* terminate with an error code */ 3 q1 t* W3 e$ x0 K) k% Z
exit(1); 7 a7 p2 Q; C7 f
} </FONT></P>. j, d& d: D3 H. W. L# [, Q. _
<P><FONT color=#0000ff>midx = getmaxx() / 2; ; q( a2 }& Q- X/ o
midy = getmaxy() / 2; & B" `0 _% p+ c9 }
setcolor(getmaxcolor()); </FONT></P>5 r* U9 h' M* y5 I
<P><FONT color=#0000ff>/* get current aspect ratio settings */ " j# d' i- x) R- }5 H A
getaspectratio(&xasp, &yasp); </FONT></P>
( N( x# E; n6 p& g' p/ O2 o4 h0 H<P><FONT color=#0000ff>/* draw normal circle */ " S8 }' H4 h1 J! U
circle(midx, midy, 100); 1 r& P+ E1 p. n/ k& V, R
getch(); </FONT></P>
9 K' F! ^. W7 I8 R$ L0 S& s5 ?: B<P><FONT color=#0000ff>/* draw wide circle */
: A/ p- _8 M1 M" Y. Scleardevice();
' Z! f$ j: N; W% nsetaspectratio(xasp/2, yasp);
6 e& c6 o# u& q8 [circle(midx, midy, 100); , |/ Q- o1 n2 q! ~( a7 Y
getch(); </FONT></P>
! H/ l" C Y+ g; S<P><FONT color=#0000ff>/* draw narrow circle */
8 m( _' Y! ?( H/ p( g, w6 x8 xcleardevice();
8 h7 R9 u0 G6 Q$ S/ vsetaspectratio(xasp, yasp/2);
4 @2 g2 M) H6 y1 Q/ S; k# z) l/ U! ]circle(midx, midy, 100); </FONT></P>. A, ~2 A' r! i) E1 x/ ^0 X
<P><FONT color=#0000ff>/* clean up */
- G' U5 k. O: r; ^6 Ggetch();
9 O7 q: D/ F5 g# _) iclosegraph(); 1 m' v5 l, ^) b* l( }: D3 l
return 0; $ R0 c; l0 X& L
}
/ d7 J6 l8 q5 X# }( U9 U6 E8 x2 r</FONT>
& d% g$ P* w5 p( j6 C: Q2 e$ @6 U4 X. O% Q0 o
</P>
0 O4 M Q9 w3 } l<P><FONT color=#ff0000>函数名: getbkcolor </FONT>: g: X. \& U: D
功 能: 返回当前背景颜色 # V+ H i9 }4 J: D) r8 W2 J8 W; b6 |
用 法: int far getbkcolor(void); 7 E* K; d, z, P" T4 |, t- E
程序例: </P>3 f& \0 }, A4 \9 Y- x
<P><FONT color=#0000ff>#include <GRAPHICS.H>; w* I1 V( Q) X
#include <STDLIB.H>
' X. t* C6 P; i3 m! {" O#include <STRING.H>5 C2 a: K: G3 k! N5 w# l0 x) l
#include <STDIO.H>
6 k# H6 n* v* B9 K6 H#include <CONIO.H></FONT></P>+ i$ `* s" q2 i
<P><FONT color=#0000ff>int main(void) 9 g* `( ~) y$ ?' g2 P4 w
{ , _% X$ t# m6 A
/* request auto detection */
) p, Z- j4 i6 f# lint gdriver = DETECT, gmode, errorcode;
$ q- [: A# |, t7 n* Rint bkcolor, midx, midy;
* j$ S) I8 |$ r- z2 schar bkname[35]; </FONT></P>' `, [9 @9 E9 z) b" R! Y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( C6 D+ I! k) M( d8 l6 C9 J, C
initgraph(&gdriver, &gmode, ""); </FONT></P>
9 n; S0 Y- n( @! Q* Y# r<P><FONT color=#0000ff>/* read result of initialization */ , T' |7 M N( V4 ?' B
errorcode = graphresult(); * S4 N5 x! v" {' Q, X/ I& ~
/* an error occurred */ 0 W; E J4 ?, l' h8 r( ]
if (errorcode != grOk)
0 e! I! x% K V3 P. Q+ _{ " o) x s1 k8 B' G" e, ?9 v
printf("Graphics error: %s\n", 2 X9 z/ l m4 u
grapherrormsg(errorcode)); 2 c0 o! V: m2 Z! E
printf("Press any key to halt:");
2 [: B* u/ h! J9 x7 h7 U2 _getch();
1 d5 _' R+ ~+ B2 y+ z# G! T/* terminate with an error code */
3 Y% k0 `" _; ]% Iexit(1); . f) J) g5 G) E4 w/ w; D. Q) W1 p
} </FONT></P>
' F8 h4 y: @ {* g& C/ z% a2 K<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 y, I1 y- E0 x: nmidy = getmaxy() / 2; 0 k: q, g6 n3 Z* N, W$ u8 p
setcolor(getmaxcolor()); </FONT></P>
/ F: C5 d) f2 ^) |<P><FONT color=#0000ff>/* for centering text on the display */
" D6 v0 I6 j. V; T2 j. wsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
% Z2 ^; D& H( W' O1 x<P><FONT color=#0000ff>/* get the current background color */
" }: J3 u5 Y! K3 Jbkcolor = getbkcolor(); </FONT></P>
( f( F# J! ~. |, d# a<P><FONT color=#0000ff>/* convert color value into a string */ 3 E- c+ X1 W' o: `: U; I0 l1 e
itoa(bkcolor, bkname, 10); 5 ]" X% S% B4 i
strcat(bkname,
0 H% P( D6 \! j( p7 {" is the current background color."); </FONT></P>
, ~6 \/ { F) c<P><FONT color=#0000ff>/* display a message */
" I7 |) c! S5 m+ W2 D# c9 pouttextxy(midx, midy, bkname); </FONT></P>
" V* C4 H8 `) `) \! X<P><FONT color=#0000ff>/* clean up */
# G- G+ g( m8 ]5 b7 @1 tgetch();
; I! b' F _1 `1 nclosegraph();
; h: O' O: k3 h3 y& C0 }return 0; 6 b& j w0 C, b1 b9 I
}
5 p5 G) l( q6 w' {/ p: {& s1 s9 a6 l5 G6 R
</FONT>5 `. I0 ^- T5 E/ T9 S. y
</P>- N/ b3 e$ J M$ g
<P><FONT color=#ff0000>函数名: getc </FONT>- ]- Z. D5 ^$ j
功 能: 从流中取字符 4 l# V9 ?& d/ O
用 法: int getc(FILE *stream);
+ V8 L O8 w/ Y- i/ R/ h程序例: </P>9 M t. {3 Y3 @/ l1 _0 Q
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>7 d4 \7 w; _" x5 `- ?
<P><FONT color=#0000ff>int main(void) 5 w: Q0 o) F% s. d
{ 1 w( R% X/ p5 G8 I; M/ o: o
char ch; </FONT></P>
1 w7 F+ u8 w& S0 S1 \" H<P><FONT color=#0000ff>printf("Input a character:");
# s! O* t7 [. g( v2 d' D% r% v- y/* read a character from the
1 h: M% e# p! @3 p7 N4 E8 Kstandard input stream */ 8 R* Q. L. c0 T/ P: h; e! e
ch = getc(stdin);
6 b! `% `0 W3 kprintf("The character input was: '%c'\n",
5 c3 w$ J2 q2 y$ sch); $ h$ V; y7 [, V5 h x
return 0;
" ~2 D+ A6 h0 f6 l% }7 }} ( p3 J7 ~3 x8 {. K
0 O% W6 q& o, q1 v</FONT>6 n( J5 s/ I8 c- |8 B
</P>- Q0 A: S M# b' j2 ~
<P><FONT color=#ff0000>函数名: getcbrk </FONT>. V& d$ I) I+ Q+ V# n
功 能: 获取Control_break设置
, ?8 v h$ I' Q1 j0 ~' J/ Q用 法: int getcbrk(void); 9 j( b/ h1 R+ B N7 ~9 u1 I# a9 H
程序例: </P>
8 {5 y4 q- M g7 o( W/ x<P><FONT color=#0000ff>#include <STDIO.H>
* Z! h+ t) | W% w) d& [- k: Q \# n; U#include <DOS.H></FONT></P>
, W) x% ]% G! m* X# R1 a<P><FONT color=#0000ff>int main(void) + i: `, m4 A8 L7 X) s$ d$ H
{ 0 K/ g5 h- h( n: x- N4 f
if (getcbrk())
' ?0 A: m* x- O9 H$ L$ c: qprintf("Cntrl-brk flag is on\n");
( t, K2 r! N3 w/ _else
; Z5 r2 D5 u" \6 _printf("Cntrl-brk flag is off\n"); </FONT></P>( g# R3 d' k. T) v
<P><FONT color=#0000ff>return 0;
9 I: I/ m- x* e5 j; P, P6 X- g} </FONT>
6 @$ W# Q! B% g$ w6 q ^( v }
5 {: T4 P/ V; J; A" Z5 \+ J1 q0 u</P>
$ n8 C6 r( H8 o6 Q<P><FONT color=#ff0000>函数名: getch </FONT>; p2 x; n- [# v# P
功 能: 从控制台无回显地取一个字符
- }, M! }; b/ d% U& p用 法: int getch(void); , q' y* x9 H$ g; W# O- f
程序例: </P>* L c7 A4 t' `' V6 D
<P><FONT color=#0000ff>#include <STDIO.H>, v9 p' \* `4 ~! I ^# K# L! d
#include <CONIO.H></FONT></P>4 |+ {- T7 u- u
<P><FONT color=#0000ff>int main(void)
, A" ^: q! q0 ~ M9 p1 I{
+ o. \+ _' j8 ^2 {2 \ ^4 Nchar ch; </FONT></P>
/ z: z4 Y( {& B- Q<P><FONT color=#0000ff>printf("Input a character:");
3 R& w1 F. @, K. Ach = getche(); 8 X o- b, _6 K( u3 x, @
printf("\nYou input a '%c'\n", ch); , d c& @8 N- ]5 f3 p% c
return 0; + l% H0 @; H! q4 a3 P
} % P5 L& [$ N: F
% L! `$ t+ I( J( v# F</FONT></P>, {9 h6 W9 r, _3 ^& u! `
<P><FONT color=#ff0000>函数名: getchar </FONT>" Z1 B! f# ^+ w; q" U
功 能: 从stdin流中读字符
* r. v4 S* U9 U( }! @" |& d3 E& f2 G0 a用 法: int getchar(void); 4 w/ y. g; M$ v: s
程序例: </P> r; Q5 T. @" v& j+ G* {
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
8 y: o, Z: s9 J$ j<P><FONT color=#0000ff>int main(void)
! Z( E+ u- r& l8 o{
7 w) t8 |4 v4 o) oint c; </FONT></P>' A/ W- ?8 B: q$ X" r4 ^4 e; E
<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
$ ]; Z/ e3 i! r6 d M6 Z! Wis line buffered; this means it will
. {. `9 Q' S& d' J! u" F) [not return until you press ENTER. */ </FONT></P>- M/ D P8 E1 A5 M5 i
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 9 ^0 i P: ~, h
printf("%c", c); </FONT></P>
- y! B/ i9 Z; Q$ J<P><FONT color=#0000ff>return 0;
" q0 l, u; v1 O}
! j" q6 z3 W. l</FONT>
% j. B; u; M9 o9 ~# H9 Z</P>
& R3 B" Y2 g# @: O$ @- V<P><FONT color=#ff0000>函数名: getche </FONT>5 S/ \0 B2 a5 h& P' B
功 能: 从控制台取字符(带回显)
. F# E* B2 _* Z9 w9 z" L; I用 法: int getche(void);
0 ^/ ^: U8 U" Y: W5 T程序例: </P>2 n2 r$ s1 i% S
<P><FONT color=#0000ff>#include <STDIO.H> C; S; S& S. T, \% B
#include <CONIO.H></FONT></P>) l- N6 e, I7 Q3 T; ~; y
<P><FONT color=#0000ff>int main(void)
' h' l) x! _5 I$ A9 f: F% ~{ + }! {0 @" Q B' }6 D" F; f* [
char ch; </FONT></P>
( e. t d0 t+ v' ]<P><FONT color=#0000ff>printf("Input a character:"); ; N! \1 Z0 q- y$ O9 L
ch = getche();
0 i: f+ J6 j1 ?5 j, }- _printf("\nYou input a '%c'\n", ch); ( S# ~1 Y( ~- c5 `8 E
return 0;
) d8 J, d/ [" j- P0 b& x}</FONT> / C6 K8 l# S! x/ k' j
7 b5 \ c8 S' T4 x6 Q4 v
</P>' K7 O& x+ l: x1 i
<P><FONT color=#ff0000>函数名: getcolor </FONT>: T% Y, V+ W9 t6 g4 U
功 能: 返回当前画线颜色
$ C3 {0 Z$ l5 Z用 法: int far getcolor(void);
7 |1 l. \& _0 o W0 @程序例: </P>3 d9 p) ~% z2 O2 ^8 j
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* |7 U% R1 _+ p! w#include <STDLIB.H>
8 Q+ N; u/ ]9 X* u# K& q#include <STRING.H>
' N/ V+ F- u* B5 a#include <STDIO.H>
" L1 ?4 g, J8 A k- x#include <CONIO.H></FONT></P>
+ ]/ Y% c0 {4 M! M( w7 B& z7 i$ a<P><FONT color=#0000ff>int main(void)
; K4 G$ N; C$ t6 k{ 0 n: ]% G8 n0 J2 O1 A& V
/* request auto detection */ 4 R6 A. _: J3 ~7 u/ U
int gdriver = DETECT, gmode, errorcode;
3 S8 \# g$ x& t' k! j9 K9 |/ o/ qint color, midx, midy;
/ u- [2 [1 M6 u% y, jchar colname[35]; </FONT></P>
t- j+ a" \4 Q$ M6 x5 g: m5 D<P><FONT color=#0000ff>/* initialize graphics and local variables */ % s7 `. j2 ?1 ]- J
initgraph(&gdriver, &gmode, ""); </FONT></P>4 Q2 [3 M$ B! @/ d+ z" T
<P><FONT color=#0000ff>/* read result of initialization */ 1 R$ l9 W% a" @! X
errorcode = graphresult(); : I: T, |4 y" }; {- K, I- Y5 l
/* an error occurred */
8 v d$ K7 [% z/ eif (errorcode != grOk) + K" [6 i/ f( r) Z
{
3 Q4 k6 v2 c: E/ S# Jprintf("Graphics error: %s\n",
, u! R z6 L X* W) l0 F9 p: \; s+ lgrapherrormsg(errorcode)); ( ?0 Q3 B/ f9 C7 i) l% x6 X
printf("Press any key to halt:"); - U2 Q5 o) m6 ?* v
getch();
* K+ \/ V4 N: O/* terminate with an error code */
4 ~3 z" [/ ?* B Bexit(1); 7 l) n' c8 T" M( ~) H; v# }
} </FONT></P>
7 K- G7 o H; c: S) a2 d y<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 D' c' g4 k. E% Xmidy = getmaxy() / 2; , g! L8 v; R* ~+ I8 _
setcolor(getmaxcolor()); </FONT></P>
. G- ?; @* P# u" }+ n( h' I( D, ?<P><FONT color=#0000ff>/* for centering text on the display */ ! ^, Z. F+ z: ]
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P> g) I% h( m9 v4 O5 d! N9 r# T
<P><FONT color=#0000ff>/* get the current drawing color */ $ ~8 r8 M4 v( u/ w+ x8 C2 L
color = getcolor(); </FONT></P>
: p0 M' x8 }6 x8 d# F+ ^0 l- w: M" I<P><FONT color=#0000ff>/* convert color value into a string */ ( X/ n% i* K! Q
itoa(color, colname, 10); ) }# k. U1 ?) z* h: y5 v( K
strcat(colname, 0 n: A6 U b$ U) x
" is the current drawing color."); </FONT></P>
; m8 {+ T& _8 X3 R! ?<P><FONT color=#0000ff>/* display a message */ ( Z- K( E a5 B* J
outtextxy(midx, midy, colname); </FONT></P>
- ^. p2 F: ~+ s( e0 ~" Z1 {! D<P><FONT color=#0000ff>/* clean up */ % R3 Y. n3 U/ l3 V
getch();
! T7 c8 k0 B u4 z* T; Wclosegraph();
' @4 D$ _5 _' b0 f3 ~* qreturn 0; 0 F8 R* t8 p! L$ X, b9 s; g
} ; J- l/ O1 _) P: v2 X' D+ h
</FONT># b2 Q: y. u$ f# M% r& q5 g
</P>
; O# p! T8 u$ n% ^8 W6 a2 p8 M<P><FONT color=#ff0000>函数名: getcurdir </FONT>
( G9 p9 z$ B& S" b功 能: 取指定驱动器的当前目录 9 V, i6 K$ q( U
用 法: int getcurdir(int drive, char *direc); + W" x& b( z K5 h0 z; N5 D. Y
程序例: </P>' c- b* ]0 K |2 c$ ?, n
<P><FONT color=#0000ff>#include <DIR.H>
+ H3 G2 Y$ ~3 t, I4 |#include <STDIO.H>% G6 B; W6 f7 L/ B g3 E* `# C
#include <STRING.H></FONT></P>. d: J. @( m( j9 E6 Q0 s" Z
<P><FONT color=#0000ff>char *current_directory(char *path)
$ q/ O! T; E* J) t& n{ ' ], o; }7 B& ~; P! E& ^- I8 I
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */ $ O1 S, a2 W# B
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
" ^5 [1 |- C$ ] Lgetcurdir(0, path+3); /* fill rest of string with current directory */
) Y+ F# Q; ?# p' k: preturn(path);
# t2 @- Y5 o$ l+ @/ U} </FONT></P>$ H6 a( Q$ g( J# R) r; v1 e
<P><FONT color=#0000ff>int main(void) . d, v* T0 e& ~ e. @
{ 3 s7 p( y$ Q2 Y2 I5 d
char curdir[MAXPATH]; </FONT></P>) a6 K; _3 s5 E
<P><FONT color=#0000ff>current_directory(curdir);
+ s2 q$ V: \& Q Qprintf("The current directory is %s\n", curdir); </FONT></P>
% k+ ]6 E4 ]0 r! N8 T- }$ M. V1 B<P><FONT color=#0000ff>return 0;
3 v1 T! q9 _8 m0 q( s) h} ( C1 |: }( d( ~1 P" X
</FONT>
, A! i0 J: Y. U! h</P># a) {! T+ O; G I a
<P><FONT color=#ff0000>函数名: getcwd </FONT>
3 s! ]# Z; ~5 p+ m0 b: v" a5 d功 能: 取当前工作目录 6 K# j0 v8 r1 E. X" ^5 h
用 法: char *getcwd(char *buf, int n); 3 X7 a1 |2 a. e, f- b" E
程序例: </P>/ C* Q/ z* K0 T1 W' {
<P><FONT color=#0000ff>#include <STDIO.H>
3 j2 U, h) J0 s#include <DIR.H></FONT></P># }5 w/ w$ D2 n, u" R" e8 n
<P><FONT color=#0000ff>int main(void)
/ _; z8 P& H5 ?/ Z `0 d! S4 \{
0 @3 J) h# z C2 xchar buffer[MAXPATH]; </FONT></P>
9 B5 T* k* Z0 q<P><FONT color=#0000ff>getcwd(buffer, MAXPATH);
1 q0 P0 Z$ j: ^1 aprintf("The current directory is: %s\n", buffer);
# M) M3 \3 N, D0 q! }return 0; 2 t" H! m& ?! [' ^/ |
} </FONT>
- E; _# F% ]" m
3 a2 d$ O/ \, A- Q1 F</P>
6 s g: D' q9 D/ k' T# u<P><FONT color=#ff0000>函数名: getdate </FONT># v& o8 `9 b2 y: t) Y4 m, x
功 能: 取DOS日期
* ]4 X& E: c! j& k+ ]2 [用 法: void getdate(struct *dateblk);
5 g1 x$ F0 }2 U8 W程序例: </P>; [9 O& J, e/ x2 y% i
<P><FONT color=#0000ff>#include <DOS.H>
7 `8 Z( T1 V0 E6 W6 V1 g5 s# {" C4 B. E#include <STDIO.H></FONT></P>
! k8 q) t0 z7 k0 W. u<P><FONT color=#0000ff>int main(void)
- @1 n* R) S6 R @9 _{ 5 u, m# x5 b) u8 y
struct date d; </FONT></P>
: e6 E8 {7 ~1 Z/ Y" v( Z2 {<P><FONT color=#0000ff>getdate(&d); 3 }, s: Q% M0 G! q8 p# P
printf("The current year is: %d\n",
. B5 r) u* ~) N% @- Td.da_year); 7 x5 b) `2 V o. h+ e; m! T; P z
printf("The current day is: %d\n", # r4 W7 f4 Q d7 ^
d.da_day);
& G$ `" U2 G) h! B, a$ gprintf("The current month is: %d\n",
1 q: ]; z; ]/ q ~! [- i- Ed.da_mon); 0 W* C6 \* ?+ R' b! Q
return 0;
* N) j) Y. o3 C$ P7 L* N} 4 j9 P$ Q; B. C8 E
</FONT>
; H4 ]' W+ \5 _</P>
3 N }1 n `% |( i6 z: p+ J<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
# [" `3 u+ F9 f5 [6 P功 能: 返回调色板定义结构 , Q- U7 z' v0 x$ U
用 法: struct palettetype *far getdefaultpalette(void); 3 \6 e3 @ X' a8 N; M0 K
程序例: </P>
8 r7 b, K9 c- I2 b<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ a; {8 d7 @, d( }: T% c3 B#include <STDLIB.H>; l6 G3 ?$ k1 \- _- L! P. {$ y
#include <STDIO.H>1 y7 @% `8 h$ z. e' C
#include <CONIO.H></FONT></P>
+ A1 e4 u* U% k0 p$ S% n) ^<P><FONT color=#0000ff>int main(void) ! G5 M, v+ {$ U. K& [
{ ; J4 I0 }) a) e& o; s
/* request auto detection */
; C; o2 X: i* H9 d9 Lint gdriver = DETECT, gmode, errorcode;
# F0 M4 w' J, r! [3 D0 Q# o1 i2 @int i; </FONT></P>
( [: G& Y) ?& S1 s" ?<P><FONT color=#0000ff>/* structure for returning palette copy */
9 n8 ~/ Z( P9 ^ u! t, estruct palettetype far *pal=(void *) 0; </FONT></P>4 s8 E9 u7 g, `: c8 D I. F( Z
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( C) d, H2 C$ U f; o D! R# |2 L8 K
initgraph(&gdriver, &gmode, ""); </FONT></P>* {" ~' f* w. N4 x3 u
<P><FONT color=#0000ff>/* read result of initialization */ ) y: f" z5 Q; _$ F
errorcode = graphresult(); ; n2 @. r W+ X, o
/* an error occurred */ * j5 i& h2 G& I" ]
if (errorcode != grOk)
( }9 J3 x2 T- H* k% @7 Z8 V{
6 J8 u p7 g0 K1 {3 qprintf("Graphics error: %s\n",
, j b) ~0 o% z! w( X/ Xgrapherrormsg(errorcode)); 3 r5 [5 R( ?8 K) B2 F
printf("Press any key to halt:"); $ }+ u; g" F' o( w w% R$ i
getch(); + x) l! B4 s/ S1 T0 _' Z8 M" ~
/* terminate with an error code */ $ T/ Y5 T" D7 S; R
exit(1); ) i8 k+ G- }# o
} </FONT></P>9 r$ r. a+ [ @: Z4 J' g, h& b$ o
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>. K. O, r& Y' J- f
<P><FONT color=#0000ff>/* return a pointer to the default palette */
. C, {- |1 M- kpal = getdefaultpalette(); </FONT></P>
9 g5 s7 r. B5 ~- O9 o<P><FONT color=#0000ff>for (i=0; i<16; i++)
/ w2 `* o, N6 e8 m{ , x J; K' P6 g$ X T
printf("colors[%d] = %d\n", i, 1 }$ ~5 Y2 o* ^
pal->colors); D B M! k# g7 i
getch(); 3 h) A. Y0 O" @9 O
} </FONT></P>6 |! G4 }+ Q) X6 B& ^
<P><FONT color=#0000ff>/* clean up */
( K" p" k7 \5 M2 Kgetch();
/ m/ J% q& H) B: y4 p/ \closegraph();
5 I% Z/ |- m9 M: o( m4 c! N. Kreturn 0;
( U ]% o2 a4 n} ( I5 g1 Q# i- }, G: X7 ?: L
</FONT>
2 m$ i. q8 e5 H: H1 U# o</P>4 a! |5 m' N% T
<P><FONT color=#ff0000>函数名: getdisk </FONT>2 k, K, ~! b& l7 K' n
功 能: 取当前磁盘驱动器号 8 S# Q; w% L1 v; \
用 法: int getdisk(void);
K5 v! z( X: ?8 L% ?程序例: </P>- ]: w! j$ N& I. A8 C5 b2 H
<P><FONT color=#0000ff>#include <STDIO.H>
1 J. l$ D. @% U6 i#include <DIR.H></FONT></P>
9 `5 t! B+ R) H7 x" a<P><FONT color=#0000ff>int main(void) & U! x1 ^8 @7 ]) c5 A
{
) T- q7 Q( ^& E. R: h9 V4 Mint disk; </FONT></P>' j/ S- ^5 n' w
<P><FONT color=#0000ff>disk = getdisk() + 'A'; ! B7 N' Z8 X9 e- y
printf("The current drive is: %c\n", $ l1 r' ~, w7 a2 f, g
disk);
$ q+ }# x. z" W( areturn 0;
: I6 l3 [! G2 g7 h2 D) ?: h o}
2 R q' u a, ~9 m$ U
/ E* `$ a! y7 w: t</FONT># O9 u o9 E2 w3 }. o" U
</P>0 H- U$ N7 f8 @( ?2 m- ^* l
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
3 A r/ U6 S: l& I- H% Q, E: E功 能: 返回指向包含当前图形驱动程序名字的字符串指针 1 j( u S2 ?/ p) j
用 法: char *getdrivename(void); 5 {% B& v3 Y3 K! S
程序例: </P>9 L. e/ o6 k0 F9 |: h
<P><FONT color=#0000ff>#include <GRAPHICS.H>; [: u2 X u% D4 p
#include <STDLIB.H>
9 R8 h8 r9 p2 r#include <STDIO.H>
9 t+ {6 \8 d! l6 Z e4 h#include <CONIO.H></FONT></P>, ~# o: m0 G+ {/ q( r
<P><FONT color=#0000ff>int main(void)
1 A; q( }3 e' [6 W* M+ x- g( `7 ~{ + F" f0 E3 i+ Z3 q/ A- Z- }$ [- @
/* request auto detection */
( F2 Y. S- }/ d- j t1 _0 D+ K8 ~9 Lint gdriver = DETECT, gmode, errorcode; </FONT></P>
B* C- d0 Q9 {0 [0 Q; _<P><FONT color=#0000ff>/* stores the device driver name */ 9 t6 `9 A. f5 A/ t- }1 x
char *drivername; </FONT></P>
& l" Q+ v6 ^3 _; `<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 e1 a2 y! G9 t2 S
initgraph(&gdriver, &gmode, ""); </FONT></P>
& \9 ]# K, P7 [- ?0 e8 q3 A. M<P><FONT color=#0000ff>/* read result of initialization */ 0 A; H+ _0 k1 g6 A4 x- C
errorcode = graphresult();
. Z8 D0 ?0 T6 B8 n/* an error occurred */ ; t- x @- z2 f8 G
if (errorcode != grOk) ! e4 T3 Z' ~% {3 W* t& R+ D$ D- J
{
! G& d4 f! ~1 N4 P0 T1 A3 J5 }8 tprintf("Graphics error: %s\n",
2 w. { U8 p# ggrapherrormsg(errorcode));
, |' V2 q6 t1 D% | |printf("Press any key to halt:"); 4 g+ w" w( l7 |) X' x3 N
getch();
+ @: Y6 i% I- d `7 t/* terminate with an error code */ ) i+ Y) b+ r5 I/ B) N
exit(1); " P* V7 L5 i. M
} </FONT></P>
1 h- U5 Y2 i6 O$ \' }9 F, M7 K5 S# O<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>' [9 {, d: F. l0 o8 |$ G
<P><FONT color=#0000ff>/* get name of the device driver in use */ ) g" I+ i- r( g4 s
drivername = getdrivername(); </FONT></P>0 G3 c2 b2 t9 E: R( I, p! Q
<P><FONT color=#0000ff>/* for centering text on the screen */ : [" t+ ~+ z9 K
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
) E- x- y# H- h' h9 _1 u$ |3 p<P><FONT color=#0000ff>/* output the name of the driver */ $ Z9 j1 l( G c
outtextxy(getmaxx() / 2, getmaxy() / 2, B% t- b$ q2 O8 Z. F$ d1 S
drivername); </FONT></P>
3 L# ~9 S1 d8 y- c<P><FONT color=#0000ff>/* clean up */ + A. U" M; G5 g, L" |0 L
getch(); % G3 j( o1 ^. S4 _! j2 I
closegraph(); ^, e4 P! @! {) r$ f
return 0;
, ?2 f3 C9 h9 p& h9 ~! `} E) C. L# C( E. E. L
</FONT><FONT color=#990000>
% N' `7 g1 u8 L8 L/ B</FONT></P>2 u2 p+ [, h$ i9 i- {' R4 Z# r
<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>" }7 [" O1 S5 e9 }# F$ s
<FONT color=#000000>功 能: 取磁盘传输地址
7 v& l; |9 m3 P0 P3 w0 M, L( d用 法: char far *getdta(void);
' y$ `* t S5 o1 ~程序例: </FONT></FONT></P>- P9 v( ?7 u9 O+ j
<P><FONT color=#0000ff>#include <DOS.H>
' N2 ]# ?1 _. k#include <STDIO.H></FONT></P> `8 i& z" n. D: q9 ]6 X t! [1 c
<P><FONT color=#0000ff>int main(void) " W5 K8 ^4 k& I& a/ {, p& o
{ 6 ^: L' f. o, t
char far *dta; </FONT></P>: g8 V6 H7 T! H- {5 |+ J
<P><FONT color=#0000ff>dta = getdta();
$ m7 R" N9 ^1 u7 O! r f5 U2 U3 `printf("The current disk transfer \
3 B9 T5 k$ I: Z! raddress is: %Fp\n", dta);
/ w+ y0 r6 |7 [/ e" X/ M* d* c8 a Mreturn 0;
7 @& c) R4 h1 c+ ]9 H; t}
! N/ a: F# l/ ?+ A9 F$ F+ U</FONT><FONT color=#990000>
% S9 N0 e2 u. Z5 M$ x</FONT></P>+ j6 F& K$ Y5 S" \
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
9 k: i2 O' Z2 ~4 {2 ] k" N% _6 c<FONT color=#000000>功 能: 从环境中取字符串 4 |* k$ m3 p% Z' g8 D* a/ q. ]/ E
用 法: char *getenv(char *envvar); / |# X6 k8 N) p2 B
程序例: </FONT></FONT></P>$ N. |! R4 J! `0 u
<P><FONT color=#0000ff>#include <STDLIB.H>8 w7 g; l* f1 P% S5 v
#include <STDIO.H>
3 o* a& U( Q& U</FONT></P>3 O: x _! |: D: a" h) D" e
<P><FONT color=#0000ff>int main(void)
8 C S1 t1 v& ?{ ( G6 m2 o- Y; v" q) P) |( e
char *s; </FONT></P># o5 e Y: w# x9 M+ A
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
+ k- {7 u6 P) g9 G' C6 U" y& ?4 Uprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>( L3 z! R3 f- X7 v& E
<P><FONT color=#0000ff>return 0;
1 s$ F+ F6 _+ h$ x! I5 w} </FONT><FONT color=#990000>
; J% B1 |* }: G) K. |/ g3 z4 M0 _; T# ?- S# @4 k! f$ \+ c
) e( t8 E" d5 \$ M( w n) F- l" Q
</FONT></P>
7 _' C" q* T- f<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>' t1 F8 j& y# }- D5 ~$ v4 c
功 能: 取文件分配表信息
0 n- g* ~' F) l& F R用 法: void getfat(int drive, struct fatinfo *fatblkp);
+ @9 r/ O9 t. O/ S% Q2 Q程序例: </P>/ ~5 h$ k5 [3 |5 a4 X
<P><FONT color=#0000ff>#include <STDIO.H>
9 D$ ~0 w2 X+ }+ Y#include <DOS.H></FONT></P>
6 S W" t. }; v( l% Q<P><FONT color=#0000ff>int main(void) 3 R2 U& m) T* W ] E
{ # X/ ~* \! A. u1 a5 k" x, j
struct fatinfo diskinfo;
+ F" N. d6 n6 T8 g- Jint flag = 0; </FONT></P>
0 \8 A. b" X2 i<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
2 g) p. O3 o3 }5 {5 X0 ^getchar(); </FONT></P>
$ g' N0 b% t7 `6 F; I& t<P><FONT color=#0000ff>getfat(1, &diskinfo);
O" c2 T5 E7 y+ C1 Z/* get drive information */ </FONT></P>5 n6 [8 `# j4 R+ K6 E, l
<P><FONT color=#0000ff>printf("\nDrive A: is "); 7 b2 q0 |. C. E8 \0 ~% i( V
switch((unsigned char) diskinfo.fi_fatid) 7 [- t& j1 X: V0 u: h
{ 8 ?: t- k. }8 c
case 0xFD:
3 o% F4 w" D' ~# { o" O; Lprintf("360K low density\n"); 6 t" h; ]) U2 U
break; </FONT></P>" A' s( P" H+ D1 X! [- J% p, c, l
<P><FONT color=#0000ff>case 0xF9:
( P0 S4 ?! G) |0 r4 P8 e! Lprintf("1.2 Meg high density\n");
; y4 [$ K% w2 T4 u; N7 Z( L1 }6 |( D0 Lbreak; </FONT></P>
" ~# S- b- E$ B( B) g0 \<P><FONT color=#0000ff>default:
+ i. L$ h0 K9 @2 e$ ?5 ^printf("unformatted\n"); ' V* T- e, x% J! C; @2 t' h
flag = 1;
* a5 `( y- z$ s) `8 P} </FONT></P>
! w! z) ?/ L8 X8 M<P><FONT color=#0000ff>if (!flag) 0 Q$ k( n% k3 m2 _2 H5 P4 ^/ G1 i P
{ - }' n# X: `$ L) E9 {
printf(" sectors per cluster %5d\n", : m/ c1 X5 o3 r$ |' x& {* p Q& A
diskinfo.fi_sclus); " d, f+ y7 t8 Z- @5 s
printf(" number of clusters %5d\n", ) I+ k/ v3 s9 F$ n4 v: t
diskinfo.fi_nclus);
/ h- d0 x7 a: F( L# r' ]" d1 l- lprintf(" bytes per sector %5d\n", ' X% k3 H9 ?9 ^
diskinfo.fi_bysec); ( E/ P* @4 z; H9 u* S
} </FONT></P>! d- ^( V% ]# f# ?
<P><FONT color=#0000ff>return 0; + ]4 U- e: r) I I$ W9 \# l
}
* W% v8 l% I D8 \</FONT>, w" g5 b- `6 v' N; a( }1 R
</P>
# f: A1 U! |0 c; Y* s<P><FONT color=#ff0000>函数名: getfillpattern </FONT>) B+ ~5 }; g. z; L( s0 p% O. c
功 能: 将用户定义的填充模式拷贝到内存中 3 H" O! p# Z( E A
用 法: void far getfillpattern(char far *upattern); % r) F/ L5 n2 Z1 g8 P: ?8 H% v
程序例: </P>& F# z# B9 z2 ~4 h
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" v3 o. ~/ R2 d2 i4 L# }* E#include <STDLIB.H>
; q( m# s" ]3 q1 X+ q* Y#include <STDIO.H>8 z' s# v* r, e( A- T4 a
#include <CONIO.H></FONT></P>; Y# B0 E& K& C( t6 q/ G8 P# v
<P><FONT color=#0000ff>int main(void) 9 d/ _% y0 I: y$ y* _9 V
{ ` M$ p6 X" }* |6 C
/* request auto detection */
% h' L- v/ U) X) ?% K+ [int gdriver = DETECT, gmode, errorcode;
8 M2 e9 d, X- u0 f' ?. {; Lint maxx, maxy;
6 t/ w N5 d! R1 c7 d! h8 K5 Mchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
, b+ O& Z/ C @4 h* G. m<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) V$ o z6 w, B K/ W- q( P
initgraph(&gdriver, &gmode, ""); </FONT></P>
& O; n" O: f- |: m0 y; e<P><FONT color=#0000ff>/* read result of initialization */
- }& o: K9 J8 D; I$ }) w$ b" nerrorcode = graphresult();
/ I( H1 y2 j. k7 [# Fif (errorcode != grOk) /* an error occurred */
; r( _' g) }: ^4 P{ 0 K, Y3 I4 G3 n5 _
printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 y2 [+ x0 [+ a7 V3 H( \, E: Y# sprintf("Press any key to halt:"); ) E% f7 b% D( Z
getch();
/ Z: P6 q5 c% }$ T" o) fexit(1); /* terminate with an error code */
, X( F" }# y: I6 E h} </FONT></P># e- ?6 i4 i4 \" b( G; A0 K
<P><FONT color=#0000ff>maxx = getmaxx();
1 \: \5 }$ d3 O% g+ q S& `maxy = getmaxy();
3 H$ G3 E! A$ j( w4 w0 ~setcolor(getmaxcolor()); </FONT></P>5 ?( t( C2 I, l# N0 t" W
<P><FONT color=#0000ff>/* select a user defined fill pattern */
+ @/ k2 |. f2 A9 E i& Q! t2 f) asetfillpattern(pattern, getmaxcolor()); </FONT></P>
* R) G" i3 }- J N% `4 u" @<P><FONT color=#0000ff>/* fill the screen with the pattern */ 7 m4 \# [7 _# v$ Z9 m
bar(0, 0, maxx, maxy); </FONT></P>7 B2 f C9 L. F1 Z% j& z, K
<P><FONT color=#0000ff>getch(); </FONT></P>. l9 x! B' F2 E: u
<P><FONT color=#0000ff>/* get the current user defined fill pattern */ S# X8 S- m. m' n8 E
getfillpattern(pattern); </FONT></P>' h8 k6 f% e/ h- b9 p5 v! k
<P><FONT color=#0000ff>/* alter the pattern we grabbed */ % A# s4 e4 t: n" T* z8 s5 F& Y
pattern[4] -= 1; # [; n, h! s, \7 t' P& {6 C, J
pattern[5] -= 3;
. h+ Y7 A A6 q5 a6 O: xpattern[6] += 3; " q# _4 a2 G1 z( D/ f8 w# c
pattern[7] -= 4; </FONT></P>7 U1 B( _% o$ n( K
<P><FONT color=#0000ff>/* select our new pattern */ - v& Q% V% {" U
setfillpattern(pattern, getmaxcolor()); </FONT></P>1 P/ y. J& V$ Z2 v5 M
<P><FONT color=#0000ff>/* fill the screen with the new pattern */
. U; ^5 y* Y! B2 T& Sbar(0, 0, maxx, maxy); </FONT></P>! P' s' B; L2 ]. O. u- H
<P><FONT color=#0000ff>/* clean up */
) q% j* P! ~6 n) {9 }7 l0 ogetch();
+ d/ Q' E: O Yclosegraph(); 4 _/ y- R# E( V o
return 0; # T% | E) {. |
}
( r1 H9 u! N" ]9 N/ c</FONT>2 M7 ^" P9 M; V4 o( W
</P>
$ [& @: p( V K2 N1 F' X: H7 J<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
/ K% ]6 r; N- ^$ M% |* Y9 G功 能: 取得有关当前填充模式和填充颜色的信息 + c, h- |; b# }% i1 R
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
$ S1 t' `, r/ q程序例: </P>
7 e* t4 }. L& r# G9 ] N<P><FONT color=#0000ff>#include <GRAPHICS.H>( P( m0 W; Z) ~! C n
#include <STDLIB.H>7 Y, W2 Y* J+ B6 Z( A
#include <STDIO.H>2 Y6 y4 l9 q+ S+ b+ k
#include <CONIO.H></FONT></P>
4 m4 }+ y" q* K8 }2 X- j% u<P><FONT color=#0000ff>/ the names of the fill styles supported */
. k# J7 P+ l+ Achar *fname[] = { "EMPTY_FILL", 8 V2 F; C8 @- F3 J! {7 P2 L9 _% p
"SOLID_FILL",
* g. h3 B3 c& L/ f"LINE_FILL", , l8 {! R6 [- F. [. u
"LTSLASH_FILL",
9 N. B' Z! {" w4 ?( `# B8 O"SLASH_FILL",
X* L/ F( @) J"BKSLASH_FILL", ! c. J) H( N0 C1 K* m
"LTBKSLASH_FILL", 9 t; I( B* h4 N7 f
"HATCH_FILL",
" q+ u! v M1 s) X8 y) Y"XHATCH_FILL",
& d3 W% _8 ]+ Q/ R* N5 N9 k) z"INTERLEAVE_FILL", + V" R+ F- L/ l2 N
"WIDE_DOT_FILL", ( L U' Q, J. @& E4 X
"CLOSE_DOT_FILL", ' K4 @% }" D- l+ w u
"USER_FILL" ) c, v7 v) v: I
}; </FONT></P>; j% y, x3 I; e) m# k. `
<P><FONT color=#0000ff>int main(void) 8 ]" S- N; s1 M- m) }1 F: r
{
& L3 n+ w0 j5 Z( t! M/* request auto detection */
- z9 d( a4 W, }& pint gdriver = DETECT, gmode, errorcode;
; q! C I' Z; G8 q; m1 Tstruct fillsettingstype fillinfo; ! R% H1 ~7 O, K3 h* }8 w, \) W" T2 U# Y8 w
int midx, midy;
( n# Y2 X+ z( |, z/ m; W. B1 {4 s+ Qchar patstr[40], colstr[40]; </FONT></P>* i' T! }8 E1 M6 D! a
<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ c/ d- J6 L: Y& I$ I& Einitgraph(&gdriver, &gmode, ""); </FONT></P>
5 }$ {; E6 J1 X8 ~<P><FONT color=#0000ff>/* read result of initialization */
4 H2 t: |0 C1 M' K Oerrorcode = graphresult();
% q8 c, K9 P! e, \7 Wif (errorcode != grOk) /* an error occurred */ , m9 z1 R% S; Z
{ ( o+ }; o; Y6 p7 E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 x+ q: v/ v/ Z9 S$ p" |
printf("Press any key to halt:"); ; O1 ]- r! S. t
getch(); 2 x. \' j# A4 j# V1 Q
exit(1); /* terminate with an error code */
5 l+ O- f6 p6 G$ r& h} </FONT></P>
4 {6 @( B- ^* g2 ^<P><FONT color=#0000ff>midx = getmaxx() / 2; 9 J& N4 y; J6 d7 x: Q" \0 X
midy = getmaxy() / 2; </FONT></P>9 @, b) o% m2 R" U/ d* `! f. B
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ / v' P' O) U8 r0 @5 x/ y3 b3 T1 R1 s
getfillsettings(&fillinfo); </FONT></P>: v" w( h3 V. V
<P><FONT color=#0000ff>/* convert fill information into strings */
, E# R b5 _8 x4 P* x$ K; D- E! _1 dsprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
- i, h2 n6 M) F3 zsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>% U/ o! Z6 q/ b% t- X9 K
<P><FONT color=#0000ff>/* display the information */ ) l. C$ L8 ]# \; D. P+ }
settextjustify(CENTER_TEXT, CENTER_TEXT); 9 P% m+ Z" [2 G/ |/ q$ j
outtextxy(midx, midy, patstr);
: E1 L; }4 E1 n* r0 n( G: Uouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
7 y* B: |% O9 T" Q* ^* r& E6 |<P><FONT color=#0000ff>/* clean up */ ( U' n8 K2 X* z2 `
getch();
, O& B& `4 k$ y% j* e4 S) Qclosegraph(); 4 K0 K9 l# B9 x# P1 c
return 0;
* o) ^' q0 D& G% B5 C% X}
* Z" E8 G8 ~6 w; m9 ]1 W" Z1 [</FONT>
( p& z- `/ F( M" Q" y; A9 D* D5 b# G3 @& D
</P>
. e& K4 [' `* i0 E0 u3 }( \2 h<P><FONT color=#ff0000>函数名: getftime </FONT>4 ~0 o2 F. ^; E$ H
功 能: 取文件日期和时间 , m/ y4 ]/ z( G
用 法: int getftime(int handle, struct ftime *ftimep);
4 t1 l8 Q$ f0 Z7 \8 |6 i. z( [程序例: </P>$ j5 X8 c7 p, S+ F, s* V3 p
<P><FONT color=#0000ff>#include <STDIO.H>
6 ]' O4 e- r/ z, M5 R' n#include <IO.H></FONT></P>! I# P2 v. A7 l0 Z- j
<P><FONT color=#0000ff>int main(void)
4 k6 Y3 y% E' J{
1 X8 \4 N. w; @( u' p7 ]8 rFILE *stream; % t/ |. x& V& H) O
struct ftime ft; </FONT></P>- P1 X- c+ a, I* j8 O/ \
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
, a" b6 V h0 n3 |9 M$ b5 c"wt")) == NULL)
1 \+ ]1 W/ U/ O{
2 G+ X. f! [4 r7 L' g# V, x$ t) m* R% R' _fprintf(stderr,
z4 O. o: @* r- o z" K* `6 Q"Cannot open output file.\n");
: e$ v3 h, i, _) ^3 lreturn 1; . f) j z/ Z4 \- s7 s( g
}
* E% @% a. g) G* Pgetftime(fileno(stream), &ft);
& z/ T& f& m3 u" m$ h% L" ^printf("File time: %u:%u:%u\n", - u5 J, }1 I8 P8 T
ft.ft_hour, ft.ft_min,
* B' {, D: `5 T* `1 @% Sft.ft_tsec * 2); 2 v$ L, m4 Y( o6 |3 v
printf("File date: %u/%u/%u\n", ! x$ t" o$ c7 V3 X2 O" D" i# R; G% u# [
ft.ft_month, ft.ft_day, 2 Y7 ]1 N+ K9 X5 F! @
ft.ft_year+1980);
: D! C+ T X& z, {0 p wfclose(stream);
) D; m* Z- d( {3 c+ |return 0; ' a9 U1 \# a6 m- _6 Z5 p
} 8 L/ Z c1 v2 a1 Z% p
</FONT>
$ x3 q- s; a* S1 |. @
# k5 T4 {+ x9 ~ V9 P i% U, m</P>' c7 [0 Y. z; w! m. v$ `
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>! a2 N! l% Z- G: |7 p3 g. T
功 能: 返回当前图形模式 9 t) t: c& G2 Y% H9 d
用 法: int far getgraphmode(void); . Y, h/ g# Y1 \4 Q3 w, f
程序例: </P>
* v8 x" [+ }. R9 e1 ?<P><FONT color=#0000ff>#include <GRAPHICS.H> C# o% A# }: F3 k" Y2 v" R
#include <STDLIB.H>
, O1 \) m1 Z7 H# R1 z#include <STDIO.H>$ p0 @3 G4 F) |6 @) k
#include <CONIO.H></FONT></P>- u8 d. ]# s' q" @- T9 L
<P><FONT color=#0000ff>int main(void)
# z o$ e I' Y G# p{ 5 }& }4 {4 F; O& |% Z/ L* E
/* request auto detection */
' ~9 L! y' r' e. `8 rint gdriver = DETECT, gmode, errorcode;
: e! y+ V$ u% h! Rint midx, midy, mode; ! b/ t0 Y# y% y$ P4 \
char numname[80], modename[80]; </FONT></P>
0 a1 j3 Q( I; a- K0 |$ w* t<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ L$ s; m& F: F# E' f$ Minitgraph(&gdriver, &gmode, ""); </FONT></P>8 |0 x( {9 h$ p2 K7 B! T
<P><FONT color=#0000ff>/* read result of initialization */ 9 O1 Q& ?# r) ?2 z
errorcode = graphresult();
% z3 d3 N% i6 ]+ N# C/* an error occurred */
; J4 p( @# X1 v, ]8 P7 [: sif (errorcode != grOk)
) A6 j* Z5 R& {- \( H{
4 Y- H; h4 J) u! O& R( [9 a& D yprintf("Graphics error: %s\n", , a! i; f3 l+ c- a9 k3 L
grapherrormsg(errorcode)); 0 S% I, J+ R$ D# h0 _
printf("Press any key to halt:");
* D5 C6 v0 Y9 ?( o0 G0 a3 [getch();
, }* b& l+ y# \+ M' Y9 f; g) i9 o/* terminate with an error code */ " c, u! K: ~7 U$ C
exit(1); ( d! M5 M5 c4 u
} </FONT></P>+ O- r7 Z, ^% A8 o6 }. ]
<P><FONT color=#0000ff>midx = getmaxx() / 2;
. Q# m, v Q4 Z" umidy = getmaxy() / 2; </FONT></P>1 k( d/ g9 S+ i B5 |% v" i8 Q
<P><FONT color=#0000ff>/* get mode number and name strings */
, j3 Q/ H. g6 o9 _mode = getgraphmode();
" S7 E) g4 `( B4 S, ?sprintf(numname,
6 M* ^% t a+ |: r$ P* V$ f# E* s"%d is the current mode number.",
/ N+ m; L3 R, F u; {mode);
6 V! M$ Y: x8 i. dsprintf(modename,
) n ^: B$ f, p% V9 _' B"%s is the current graphics mode", 6 C% W1 E S1 S+ F' m
getmodename(mode)); </FONT></P>* q6 i/ p5 o% h9 x( e4 y% p2 T
<P><FONT color=#0000ff>/* display the information */
6 Q& n2 V, X4 b; u# Xsettextjustify(CENTER_TEXT, CENTER_TEXT); 0 Z6 ~% G6 X. r6 ?! i
outtextxy(midx, midy, numname); $ l0 @' I4 q& \
outtextxy(midx, midy+2*textheight("W"), M8 w$ X, X1 {! J0 c* V
modename); </FONT></P>
/ y$ x& }3 }! z0 D. B3 r<P><FONT color=#0000ff>/* clean up */
. ]3 b; j; |+ S T9 r ugetch();
3 P5 f% l( L9 m; ~: ]7 x# h" |4 }closegraph();
" z! L& e6 t- l) `( R8 rreturn 0;
4 G: s" B( p; J# Y} </FONT>8 w) Y. B* l; Y
- e0 i- s5 x% Z0 k</P>
7 {2 g* p5 L1 Z6 P6 {3 ]# U<P><FONT color=#ff0000>函数名: getftime </FONT># v6 l' D2 { S& g
功 能: 取文件日期和时间
( P8 m- y- \7 @- ^3 n4 l) x9 [$ n' t* m/ p用 法: int getftime(int handle, struct ftime *ftimep);
) Z4 ^, p" Z1 K& O2 f: Q程序例: </P># Y3 L) W% i. B8 K5 h
<P><FONT color=#0000ff>#include <STDIO.H>/ g; B" I" C. z! W6 _7 B
#include <IO.H></FONT></P>2 R0 D9 [( x5 {# O0 L) s" d
<P><FONT color=#0000ff>int main(void) 6 d& N/ o8 {% p. V: T
{ 4 w+ E9 C! N" b1 d3 [
FILE *stream;
* F9 [0 e: Y6 M2 Z6 f: }struct ftime ft; </FONT></P># e0 H5 n. }3 @
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
6 C! z, C' V; x: [8 {' s' g3 _' g8 }; a/ {"wt")) == NULL) ; B* u% ]5 ^% y% W5 O
{ 1 @# p ~2 l+ ~0 s6 `+ }+ m
fprintf(stderr, - c4 `" q$ E! a) g' S
"Cannot open output file.\n"); 3 y+ a! o8 l; |2 P( @
return 1;
9 F8 p, @" H p, Q3 Q- `! h} # d9 ~8 G" ]1 p+ N- U9 i2 f% y# J! T: ?
getftime(fileno(stream), &ft);
) X: \% u S0 i. ]$ \, ]- j# ?printf("File time: %u:%u:%u\n", , n, U5 H: ~& P; M
ft.ft_hour, ft.ft_min, * Q& V* [; H: M
ft.ft_tsec * 2);
: I5 C& X, D3 r8 |- Cprintf("File date: %u/%u/%u\n",
+ h7 N* ?; w9 t) A/ Ift.ft_month, ft.ft_day, 3 h7 o3 }" z& j) g+ t0 D2 K
ft.ft_year+1980);
8 r+ F' n& v; p# A, t W3 Y: Dfclose(stream);
0 Q4 _, _+ `- m+ j _$ Hreturn 0; # Q# D% Y7 f% v0 w) C# U8 y
} </FONT>
/ ?! ~. E( n5 L1 W' r) `( O' x; g) T& q; Q/ D, R
) E9 G7 A& b6 V {
</P>7 i3 B& e0 w. F1 |4 \
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
" l! l! h) Z* B3 q+ i$ \. S% I! v功 能: 返回当前图形模式 ' Q2 N D, G) Q3 d
用 法: int far getgraphmode(void);
2 v; }' a/ N' ~( B# V程序例: </P>, H& s4 |8 F- z# |/ ^8 b
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, e5 C4 i1 D/ q4 `3 U#include <STDLIB.H>
& a% s( O0 ?; N8 h) X#include <STDIO.H>
O" A# \$ q7 |# ]2 ~: y#include <CONIO.H></FONT></P>
2 v' O- g3 ~3 M/ p$ W<P><FONT color=#0000ff>int main(void) 9 p% S+ h3 c0 w' `4 E6 R/ T
{
( _1 E4 y1 u- y# C/* request auto detection */ ' I. R: \* F1 \8 b! ?
int gdriver = DETECT, gmode, errorcode;
v1 b3 T6 W: U5 i: Vint midx, midy, mode;
' E- Z3 w1 q# w5 D! A- c ~char numname[80], modename[80]; </FONT></P>" x4 x) V( H! u# m
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 D1 x) X- o. C" ]6 c
initgraph(&gdriver, &gmode, ""); </FONT></P>
# e4 d3 }$ y0 }% \, l P- t<P><FONT color=#0000ff>/* read result of initialization */
9 f: O3 @1 L$ r+ T2 herrorcode = graphresult();
+ R" {% z5 a; a2 p8 ?1 k; H/* an error occurred */ ( E6 X$ Q1 A6 [! k4 M* I8 b' Y
if (errorcode != grOk) 8 v7 Z, V6 Y. [, }
{ . W9 g# E. Q' a) X1 z! f/ e( ?* c
printf("Graphics error: %s\n",
" [# e& x) A, K7 ?" w# [2 Pgrapherrormsg(errorcode));
6 r% Z- t* A9 R. j, l: mprintf("Press any key to halt:"); ' z4 `% V3 Z4 l9 z4 |
getch();
" i; o+ [0 B2 L p0 e( ~3 Q8 |& ]3 k" M/* terminate with an error code */
- J) J/ s5 A- yexit(1); % F+ H8 x) J0 E6 p% Y8 ^1 P
} </FONT></P>
$ w' c5 r' Q# L<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 q1 b: V! a" e# I Hmidy = getmaxy() / 2; </FONT></P>) P/ a; |% t! m4 h! N
<P><FONT color=#0000ff>/* get mode number and name strings */ 4 }" B+ {5 i S6 c. x- Z
mode = getgraphmode();
6 ]" n" V+ ?4 F( d1 U0 `sprintf(numname, ( X# L7 e0 T* y
"%d is the current mode number.",
9 K( S6 \ O! [. s* rmode); I, `' |7 A: Y4 z" O
sprintf(modename, 9 {( a) g- K8 c, W4 `6 l# O
"%s is the current graphics mode", - d& I/ B9 d* s$ T# ^
getmodename(mode)); </FONT></P>) i: d% p7 @1 x
<P><FONT color=#0000ff>/* display the information */
! R+ \4 X% \( b; ?- @' h" Wsettextjustify(CENTER_TEXT, CENTER_TEXT); ! x! W% {, x# o
outtextxy(midx, midy, numname); 0 ], J; s4 Q) T) z5 @2 H' G: C! O& E
outtextxy(midx, midy+2*textheight("W"), + M- o* w; Y1 p9 g4 p2 Z2 [& [
modename); </FONT></P>; k' ~ f: j |$ P% p5 I
<P><FONT color=#0000ff>/* clean up */
9 l& T0 k3 W( q2 r$ [4 v% J( mgetch(); 2 G+ S, A% g" T9 h+ t
closegraph(); 4 I6 [. u% L4 `3 ?* y M/ z+ Q
return 0; 4 w( r( Y4 ], v4 N6 t R4 n1 j
}
) g$ a8 l0 l: y% M8 w& l</FONT>& |; ?1 B, A7 Z- w- f* }. [
</P>+ w5 D: c! o5 c8 X& j4 P% E7 ~
<P><FONT color=#ff0000>函数名: getimage </FONT>
+ `; _3 d2 ]: }/ u0 Z" H/ I1 b功 能: 将指定区域的一个位图存到主存中
3 Q2 X; a( x& h+ ~( N( J用 法: void far getimage(int left, int top, int right, int bottom,
- c, }7 [/ E/ j( D# t/ G- ~void far *bitmap);
: E% T& k$ F3 s; x5 c程序例: </P>
/ r# Y$ B1 r- X% n S<P><FONT color=#0000ff>#include <GRAPHICS.H>, m- j% ~9 t8 B8 r3 O
#include <STDLIB.H>- l1 D* c6 X6 W+ ^ ?# D# v
#include <STDIO.H>
3 N1 r" {/ W! h$ ]+ y) A5 k#include <CONIO.H>
+ m* l# R. Z3 t8 m+ `) `5 X#include <ALLOC.H></FONT></P>
; V/ R" u1 C7 e M1 G<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
4 x7 L7 P( U" Z; M! o; jvoid restore_screen(void far *buf[4]); </FONT></P># {$ e7 |# J: t! D: ?7 O k, A
<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
5 _6 l* ?6 u( P2 b2 ]; m" A<P><FONT color=#0000ff>int main(void) ( ?7 e8 t- X" ? \9 n; V
{ ; ]- V9 e) H. M
int gdriver=DETECT, gmode, errorcode;
1 w. T- `& K& `) M2 bvoid far *ptr[4]; </FONT></P>" p( P8 G# Y8 U; j1 F
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ ' [, z& Q; C4 r+ ]0 K$ T+ ^2 x
initgraph(&gdriver, &gmode, "");
5 b, e9 u+ q2 O( _6 w" {. eerrorcode = graphresult(); /* check for any errors */
3 F+ Y2 w; Z& xif (errorcode != grOk) 5 C7 c0 |; e) _
{
% h7 F: v9 ?! ]( Nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" ?9 }* S5 F4 Y0 f$ `printf("Press any key to halt:"); . g: Z4 t* g4 @# G+ h! B
getch();
# R* Q1 m( F w& B zexit(1);
% _6 w9 B" f+ X% D4 t/ R} 4 B; V( V' U; N% t# X" }
maxx = getmaxx(); , x1 D1 W: u$ v! c
maxy = getmaxy(); </FONT></P>
8 J3 Z8 P# p: E! u. ~<P><FONT color=#0000ff>/* draw an image on the screen */ & Q% P. u$ y! A2 z
rectangle(0, 0, maxx, maxy); . D m& E/ F; h$ F, X. [) w
line(0, 0, maxx, maxy);
" F. f z8 d+ v# q1 i& Tline(0, maxy, maxx, 0); </FONT></P>
7 }, L* J2 D5 m+ t<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
% k& D5 l( U8 ?" pgetch(); /* pause screen */
7 B0 o- f! w* m! I" qcleardevice(); /* clear screen */ ! j. r8 M* Y! r3 V' p. U% b
restore_screen(ptr); /* restore the screen */ % m3 v& K6 Q2 q
getch(); /* pause screen */ </FONT></P>. p G& _4 p; C: q- O
<P><FONT color=#0000ff>closegraph(); 4 [9 `0 |! h! O& M
return 0; & h" U$ Y+ A& p# \" Y
} </FONT></P>3 E, G8 ~; V1 P9 y) ^
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) + c& ?7 O, b- j' [
{ " d: Q2 l2 J' L2 q
unsigned size;
0 \/ G2 ]1 f3 h+ hint ystart=0, yend, yincr, block; </FONT></P>! j2 l: n _" j: _5 [
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; # I6 r7 C1 K1 ^, g
yend = yincr; ! }+ n: w3 m/ {0 I" B
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>* ], I4 A( f5 F( B
<P><FONT color=#0000ff>for (block=0; block<=3; block++) 5 W# P# \! Y# t
{ ! k" F$ P% E: `) G( K( w/ _
if ((buf[block] = farmalloc(size)) == NULL)
0 T1 d, b5 O& }0 ~/ a{
: w0 G9 H1 O. a8 d/ i& C! fclosegraph(); ! Z& O5 g' L! z1 f
printf("Error: not enough heap space in save_screen().\n"); 4 q! W6 @- [- i. M" m- R
exit(1); ) M" M3 \; ?" M( ~" p7 [8 b
} </FONT></P>; @2 G( T; d& ?; k0 a7 `
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); : e% V, G; N, ^# `' e
ystart = yend + 1; 5 @( Q: C* H: ^3 P0 Q* g" g
yend += yincr + 1;
% F5 E. \, q* }1 v} 6 ^5 k+ ?. |# R" u2 Y
} </FONT></P>/ g: z* S. ]2 V; H- q6 X! H
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) 7 p9 z6 ?2 ~, T; V: V' x
{
5 A. [# m- q4 c tunsigned size;
- N# D1 x6 v. oint ystart=0, yend, yincr, block; </FONT></P># Y. N) K2 |$ }$ {" z& d" p
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
: Y) |/ ? d$ P# ryend = yincr; - p$ _# O( U4 |
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
; ]# [- p! L- m4 B0 V' F' j& V6 B( w<P><FONT color=#0000ff>for (block=0; block<=3; block++) 1 S# ]- k0 U( N
{ ! b! F r9 e% @- ?% T. J# T+ R2 n1 k) W
if ((buf[block] = farmalloc(size)) == NULL) : x! |. v% v6 b5 x
{
$ ?$ X( |* x$ ~: Q, w F! `+ S2 f- ?closegraph(); % Y( @3 s6 W2 {2 F7 E( G
printf("Error: not enough heap space in save_screen().\n");
, T& W) y0 o, ]5 ?! i* A0 C7 qexit(1); - b7 y+ U5 F2 Q& B
} </FONT></P>! S3 B7 r3 |4 W4 }8 K
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
& L* A7 P# w& r; |7 b$ q9 k( T% Nystart = yend + 1;
1 E( K6 u2 B: c) ayend += yincr + 1; ' ?: E1 h+ z! b
} & `8 Q4 x: I4 q3 n+ u: X
} </FONT></P>0 {; P* _* ?6 f) J
<P><FONT color=#0000ff>void restore_screen(void far *buf[4])
% D: Z& o V6 C7 S: u{ 4 \ G2 G9 l( ~: \, C; s
int ystart=0, yend, yincr, block; </FONT></P>. i; e6 a+ @* H2 e8 @7 M: {3 ], O {
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; - ~) t( |* Y. b/ [$ _. P
yend = yincr; </FONT></P>1 D+ x% u+ ~$ Z- x
<P><FONT color=#0000ff>for (block=0; block<=3; block++) 4 P v: | w* D7 t2 I! N* @
{ 9 a2 S, e5 o+ z2 B% e% C1 D0 r2 H
putimage(0, ystart, buf[block], COPY_PUT); 4 ~3 h \# o8 R4 x/ W: a& J
farfree(buf[block]); " f2 z: F a+ \1 l# \
ystart = yend + 1; 2 U' ` s1 w9 ?/ U& B4 I
yend += yincr + 1; # ^) p+ Y7 x6 ?! V6 E7 w
}
x: J; Y6 f6 q$ A8 P4 ~} </FONT>) E4 n0 ~7 J% o
<FONT color=#ff0000>
2 f2 ?& ]9 z5 u$ a1 O% Q</FONT></P>
4 }. M; U8 F# C<P><FONT color=#ff0000>函数名: getlinesettings </FONT>- a/ h. {* C5 Y6 `* Q. P
功 能: 取当前线型、模式和宽度 * L' c' e5 L1 Z: q3 ]7 n/ R
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
( \$ b; T; \, v1 t& B程序例: </P>
3 D/ m# K5 h. x6 A4 ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 |& {* y. d0 [8 X' k }" M#include <STDLIB.H>
0 e7 z+ u4 ]6 A/ V! i#include <STDIO.H>
1 w4 I+ m" o/ U! a( z m#include <CONIO.H></FONT></P>
s9 F; j! u7 f: K$ b. A<P><FONT color=#0000ff>/* the names of the line styles supported */
# e8 E: q5 Z) }. \% Gchar *lname[] = { "SOLID_LINE", 7 ~5 K7 W# w% H7 ]; A9 \/ E: W' q
"DOTTED_LINE",
: c) `& m6 i4 e I- @"CENTER_LINE", 8 r1 e. r% C# X5 _+ [8 X# y/ s
"DASHED_LINE",
' j' r8 y2 _% @$ p8 X"USERBIT_LINE"
4 t, S' o/ }5 W}; </FONT></P>
o4 v8 M3 C. m, O( a) }/ {<P><FONT color=#0000ff>int main(void)
9 }% K8 M& D% ~6 ]1 d6 ^{
: J8 h! \' U; a4 |- i: A; k/* request auto detection */ , S9 ]9 b: D/ h
int gdriver = DETECT, gmode, errorcode;
8 ^3 _2 ?) ^5 V& f* mstruct linesettingstype lineinfo;
. E9 H7 ]$ n+ X1 g$ K+ k2 \int midx, midy; & [. e( h+ c0 W3 }" x& }" \# T) ]7 k
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>, c* M1 G0 |. l" q" C6 v
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - W9 @! P ]( _" _$ z7 Z5 w
initgraph(&gdriver, &gmode, ""); </FONT></P># p; Q$ p u4 J5 P0 }, q: \/ a
<P><FONT color=#0000ff>/* read result of initialization */
" G4 h* h- j+ m! N( |, jerrorcode = graphresult(); 2 V$ b, L% Q* j6 l# N" [9 _
if (errorcode != grOk) /* an error occurred */
! n8 n" d8 M- `, o8 B0 l* i{ " S8 u0 J* G f5 \) h) U( z7 U; g( ^
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( Y' m( u \) N7 h6 L7 D2 T
printf("Press any key to halt:");
6 L7 O8 ~4 E# [# lgetch(); 4 Z# A9 I! ~$ }( ~4 P5 [
exit(1); /* terminate with an error code */
# I/ U+ v% R: a1 V6 Z# S} </FONT></P>
% I$ C8 G/ i; m; K3 f+ ]& a<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 ]- h5 M* `9 W6 p! L& b7 V$ |
midy = getmaxy() / 2; </FONT></P>' @. L2 |/ _0 ^- A4 y. ]0 Y$ Q
<P><FONT color=#0000ff>/* get information about current line settings */
, a# r, ^' j6 g+ H, F- y, L. \* hgetlinesettings(&lineinfo); </FONT></P>1 s6 M6 T' Q" A8 l4 ~
<P><FONT color=#0000ff>/* convert line information into strings */
/ X& V! v9 l! C, {2 Asprintf(lstyle, "%s is the line style.", 7 m: i8 i$ w5 N& N% N
lname[lineinfo.linestyle]);
$ e2 D ^3 k+ }* o s( G4 Ysprintf(lpattern, "0x%X is the user-defined line pattern.",
' K. U; e3 D" J6 _* H0 P+ m' D! Jlineinfo.upattern);
- k# j: I, L; h- j2 b- O) S% [sprintf(lwidth, "%d is the line thickness.", . t+ ^/ J. ~8 ^& v7 ~
lineinfo.thickness); </FONT></P>+ s* n& ^7 ?0 V% Y
<P><FONT color=#0000ff>/* display the information */
i- I, r4 R' S( i) B( Wsettextjustify(CENTER_TEXT, CENTER_TEXT); * Y: J% z2 J( L* m+ }
outtextxy(midx, midy, lstyle); ' n( J2 E% f2 T% ?/ }1 u% V8 b
outtextxy(midx, midy+2*textheight("W"), lpattern);
+ D. ?# P$ |" g8 F4 q+ Jouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>5 U; \' ~% a0 M4 n
<P><FONT color=#0000ff>/* clean up */ 4 C$ Q; g+ P, x6 _ i8 N
getch(); - a9 w! j& G3 i* @/ ~$ s3 X
closegraph();
' K* S- x9 U- y+ z Wreturn 0;
) W3 Z" X% g% g- Z+ X- N/ h} </FONT>; x _$ o% K4 g; I# F- O. X
2 v; [: ]8 {- e l$ C# v
</P> b: |8 q" o5 w' k: U) K* q
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>% B/ n Y3 C! h
功 能: 返回可以传给函数setcolor的最大颜色值 9 x5 Z" Q" Y! s5 g" l- d3 x
用 法: int far getmaxcolor(void);
" B% ^1 Q. @( C! k0 P" z程序例: </P>8 A3 S2 E, J- K3 ?
<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 L4 B0 a" ^ I+ W#include <STDLIB.H>( m4 o" p) S! G" X+ b/ L. j
#include <STDIO.H>
/ p4 `+ X& f" [6 h$ ]1 z' S#include <CONIO.H></FONT></P>
: T" |, f$ Y4 |, r$ p<P><FONT color=#0000ff>int main(void)
) R$ M/ ^1 l$ u x/ h; Q# F{ $ k, n% C( X! J5 P |
/* request auto detection */ 3 A/ E7 U2 {9 e" E1 d& S( |9 O
int gdriver = DETECT, gmode, errorcode;
: r7 [/ ^. [, o+ Mint midx, midy; # k2 q7 L9 M0 ^# s& o
char colstr[80]; </FONT></P>4 u& G# ?+ P1 \
<P><FONT color=#0000ff>/* initialize graphics and local variables - C: w6 S! V0 W
*/ initgraph(&gdriver, &gmode, ""); </FONT></P>
0 @8 v8 N2 x2 |4 z<P><FONT color=#0000ff>/* read result of initialization */ ' h2 Y+ e: U- j
errorcode = graphresult(); 2 g! p; ~% t9 q$ {) l, R
if (errorcode != grOk) /* an error occurred */
5 H# E# J9 b% y& g z- U* A! m0 u{
7 t) x3 I( ]- m* c5 t: @7 @' ?# `printf("Graphics error: %s\n", grapherrormsg(errorcode));
- g: K! D9 n" |* z9 Z% mprintf("Press any key to halt:"); / V8 E. e4 Y; z5 g
getch(); - A$ H Z' d0 a: o
exit(1); /* terminate with an error code */
6 ]9 `6 t# E6 D! H) r5 y' r/ M} </FONT></P>
7 @5 ^" |; k, B- o$ @' h<P><FONT color=#0000ff>midx = getmaxx() / 2; - S. ?9 l$ ~; ?- ] N# }- I" c' N. P+ M
midy = getmaxy() / 2; </FONT></P>* T) ?# O( U# i7 r( X
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
% C6 M* f! e8 [; @sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>5 B- K4 p( \) { t9 c$ e$ B6 I" h
<P><FONT color=#0000ff>/* display the information */
. p$ H) I7 N s, ^settextjustify(CENTER_TEXT, CENTER_TEXT); * w! j/ j' }; o+ H, L
outtextxy(midx, midy, colstr); </FONT></P>+ b/ H0 f& z, G) n
<P><FONT color=#0000ff>/* clean up */
1 B# _ g$ w; i& ^getch(); 0 \( l+ B1 U q2 y
closegraph();
& ~9 D. l: i7 ireturn 0; ) P5 Z* m% D, P% w1 k
} </FONT>4 x7 e; I! q2 }
" }8 G4 i4 ]7 U
2 W9 F x) D% E+ T3 \( c6 Z* e</P>
' K- k* M# b P<P><FONT color=#ff0000>函数名: getmaxx </FONT>
5 I7 {/ n9 K8 F# _功 能: 返回屏幕的最大x坐标 - A7 j1 _$ g; `+ e5 N3 m/ |7 ^- I7 }
用 法: int far getmaxx(void);
& B2 x) r9 V/ f/ z8 o6 s: [8 Z程序例: </P>
1 `( T& _6 q3 W+ w, |<P><FONT color=#0000ff>#include <GRAPHICS.H>
' \. I5 g* C9 i4 R0 Z w9 o#include <STDLIB.H>
8 O! u/ Y: R% }7 _#include <STDIO.H>
+ q1 M. X8 C' W/ n2 N) ?; z#include <CONIO.H></FONT></P>
& U% L3 q& Y: p3 p<P><FONT color=#0000ff>int main(void) 1 G5 ]" [$ X; P: S) b7 l$ h+ a/ q$ y# } }
{ 9 N0 ?! B$ Q$ X
/* request auto detection */ ; q: F! J" m0 h4 H) f# F+ G
int gdriver = DETECT, gmode, errorcode;
( B; [1 g W+ ?! l' o Z9 g8 Yint midx, midy; 3 `- q, j2 u) s: E7 @4 Q
char xrange[80], yrange[80]; </FONT></P>
3 Z+ Q C- s$ c, s1 N6 y/ B<P><FONT color=#0000ff>/* initialize graphics and local variables */ . Q- u; A0 C& }6 I9 x7 n
initgraph(&gdriver, &gmode, ""); </FONT></P>4 Y. v/ |, _& c* I" B3 s
<P><FONT color=#0000ff>/* read result of initialization */ 2 h. q3 I; L) `1 A
errorcode = graphresult();
; V, Q# S* s. g/ C7 O$ M5 Fif (errorcode != grOk) /* an error occurred */
9 z# n' H* _* b2 g% I$ h+ ^{ & N9 N* K, _; m7 T$ E% _- g5 [
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / o3 o1 F. R. O7 C
printf("Press any key to halt:");
# d& {5 F! P) x2 u' D P$ M+ u, dgetch(); / {( S2 ~; U8 N, O2 R1 i" }
exit(1); /* terminate with an error code */ 9 Y9 Y: ]3 x& D( }% @- w- W
} </FONT></P>
& Q9 T( V6 J& \9 F1 m4 J<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 P1 h% b, ^) x1 i9 d/ J7 x7 qmidy = getmaxy() / 2; </FONT></P>+ ?0 S& [& |+ O( e9 D+ O
<P><FONT color=#0000ff>/* convert max resolution values into strings */
, _# F4 h1 P6 x2 w8 F: w# Xsprintf(xrange, "X values range from 0..%d", getmaxx()); 4 I' Q3 O4 `/ ^
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
7 P" j' K( D- V0 C' n<P><FONT color=#0000ff>/* display the information */ 5 F2 ?4 q4 q" N. F" R
settextjustify(CENTER_TEXT, CENTER_TEXT); ; `' }1 y! p; {$ Y) N2 `
outtextxy(midx, midy, xrange);
8 t5 t, F* k+ u/ n( houttextxy(midx, midy+textheight("W"), yrange); </FONT></P>4 m" K/ f# I& j S% m& ~4 n4 n1 s! p
<P><FONT color=#0000ff>/* clean up */ . q3 }+ E0 Q* w: G8 P9 Z
getch(); ( Y& k) ^, u0 a
closegraph();
2 @, t! l1 _) a+ n# Ereturn 0; , G; E3 v2 z, V, p! o
}</FONT>
! S! ]& Q3 h; D2 I' l" l1 a5 F
' J$ K, r( p! T5 d4 K</P>3 O: G" G) k1 u7 z
<P><FONT color=#ff0000>函数名: getmaxy </FONT>* i+ ^6 A' N. h; w6 x7 T
功 能: 返回屏幕的最大y坐标
1 s. M0 H. N- y3 J1 d' X用 法: int far getmaxy(void); 4 l) A; A4 o! V, B7 K# L! ^
程序例: </P># I; M; l( \& [7 c- b
<P><FONT color=#0000ff>#include <GRAPHICS.H>% i8 b, G, S6 x. e7 w6 M
#include <STDLIB.H>
0 t3 p. A, s4 H E$ w, N9 R& U" @#include <STDIO.H>$ l. d* Z, I: |2 X0 ~% C# u' e
#include <CONIO.H></FONT></P>
9 w( [$ [* C- K0 `7 B<P><FONT color=#0000ff>int main(void) & z0 C: ^3 w/ f9 i
{
0 ^3 G9 o; Z! c. U/* request auto detection */
+ e6 b* z, C: B Vint gdriver = DETECT, gmode, errorcode; , s0 g. p& _$ T& Q7 b7 Q
int midx, midy;
% c0 g+ L! K( O" ochar xrange[80], yrange[80]; </FONT></P>
6 C6 Y2 m9 A: s" I' ~ z<P><FONT color=#0000ff>/* initialize graphics and local variables */ q7 k! \; U8 A$ F, r6 x( e
initgraph(&gdriver, &gmode, ""); </FONT></P>
3 P5 E/ z) p3 Z/ V! |/ G2 `<P><FONT color=#0000ff>/* read result of initialization */
' f# e4 K" H) j& merrorcode = graphresult();
! [3 B" Z# w+ U9 M0 Dif (errorcode != grOk) /* an error occurred */ ' j6 J) ~" k. _. b1 U; G
{ # |, F$ ? c' ^, Y. `6 J+ ?
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 F9 D- p1 k2 \& |" c/ l0 \printf("Press any key to halt:");
2 N* z+ ?& O- e; D% k) b, r. wgetch();
2 J4 \( Y7 ?7 f9 u( P) T$ V* |7 Kexit(1); /* terminate with an error code */ 7 u* l# a, J& E% F! h8 p
} </FONT></P># ^0 s0 z9 ^' j4 L' I$ U' }3 ]
<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ Y5 \# W3 b: r& k$ A. J7 Gmidy = getmaxy() / 2; </FONT></P>, F; V" S' j7 i
<P><FONT color=#0000ff>/* convert max resolution values into strings */
! ^2 w1 b8 i! N6 Y( [sprintf(xrange, "X values range from 0..%d", getmaxx());
" Z* H& _- t* lsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>9 L$ T, N& D+ x1 }/ j8 j( u
<P><FONT color=#0000ff>/* display the information */
) `8 b( `0 p4 P/ v8 Msettextjustify(CENTER_TEXT, CENTER_TEXT); ! @/ g% x& x$ O+ l. T6 K: m
outtextxy(midx, midy, xrange);
' p9 T* t4 v% |: M/ A5 b! Z1 Couttextxy(midx, midy+textheight("W"), yrange); </FONT></P>9 F. m& ?: |* d4 k9 \3 }5 I
<P><FONT color=#0000ff>/* clean up */ 0 I; n8 ^( s& x x( h$ Y! E
getch(); , Q! I) h+ u" c, ~4 ^- k$ ]
closegraph();
J" _2 i" R3 `return 0; ' x0 b% b4 R9 Y
} </FONT>1 I7 {. i7 z. |) |, X2 U
</P>. \6 h$ z; o4 E9 z
<P><FONT color=#ff0000>函数名: getmodename </FONT>
- M0 E, }. M' N1 ~7 h% q+ D: E功 能: 返回含有指定图形模式名的字符串指针 ; r5 R6 i9 e8 _5 e; c2 y1 V
用 法: char *far getmodename(int mode_name);
; v1 Z! }- t) {2 Z U% k% Q程序例: </P>
7 o3 |; I& y0 |( Z4 M<P><FONT color=#0000ff>#include <GRAPHICS.H>7 _( p) \0 p9 g5 v
#include <STDLIB.H>
% u# d: M* o; h" d8 w1 _2 h8 V#include <STDIO.H>: l3 d L. q$ T
#include <CONIO.H></FONT></P>/ S# C; `/ v0 P3 g& ?1 z' A
<P><FONT color=#0000ff>int main(void) |7 [2 C% I2 g; H6 k; ?& y
{
S/ Q' P$ S6 r' V8 c5 T7 _/* request autodetection */ & e# w$ |) S8 v" X& x
int gdriver = DETECT, gmode, errorcode;
# w6 F% d3 l4 K2 ?: Z0 s* eint midx, midy, mode;
' i% p6 K' {8 c2 V8 `char numname[80], modename[80]; </FONT></P>
6 o0 @) D) ^6 s$ F3 o1 B5 n/ Q<P><FONT color=#0000ff>/* initialize graphics and local variables */ , `( i/ K, d: l* m
initgraph(&gdriver, &gmode, ""); </FONT></P>
2 c$ {! D8 s. L+ W: G* p+ U<P><FONT color=#0000ff>/* read result of initialization */
6 S8 E7 n2 |: ]# ^) Q2 W Nerrorcode = graphresult();
, y, c. s j3 Y' s. B! g8 h2 X( [if (errorcode != grOk) /* an error occurred */ ; K0 U" h# ^8 [5 P
{ : W; L m: }) y: ~$ K) Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& N3 t7 y' g$ n$ z: \& Lprintf("Press any key to halt:"); 5 R V) ?2 B/ W% F" K, R
getch(); ?% y" {; P' G! H0 q
exit(1); /* terminate with an error code */ 0 y7 d/ t6 T6 N% t
} </FONT></P>
9 G, n; G8 Y; X<P><FONT color=#0000ff>midx = getmaxx() / 2;
* s& x/ [& T, [5 V) `* \& _midy = getmaxy() / 2; </FONT></P>0 N. K4 s* P, I" [
<P><FONT color=#0000ff>/* get mode number and name strings */
# { d+ R2 J9 x: x2 z- zmode = getgraphmode();
* T+ w4 h0 J% r H. E& `sprintf(numname, "%d is the current mode number.", mode); " f# E0 N# U* B
sprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
! ]+ l L/ {. r3 Y: _<P><FONT color=#0000ff>/* display the information */
+ D# o! o4 f9 L$ I ~, x4 osettextjustify(CENTER_TEXT, CENTER_TEXT); + z( j( v3 W) u7 |* f6 L
outtextxy(midx, midy, numname);
% D" D3 x9 g$ h" aouttextxy(midx, midy+2*textheight("W"), modename); </FONT></P>4 Q. e5 X( H" z' d+ {0 c" J
<P><FONT color=#0000ff>/* clean up */ 3 i+ m$ A6 d7 q8 I2 V
getch(); ' m: u1 y5 I/ q7 r
closegraph(); ) q1 y1 L7 Y' P9 l
return 0; ' Q) [6 _8 L) P" Z
} </FONT>
3 g# B6 b8 ^& I4 |' j! @. F. @' F: R+ T9 e! o$ y5 e
</P>
/ G, e. ~9 F- I/ K8 Y$ A$ Q<P><FONT color=#ff0000>函数名: getmoderange</FONT>
. Z+ ?# Z \% B5 \: i1 r% J功 能: 取给定图形驱动程序的模式范围 & S* E) f: Y/ Q6 i4 x+ I
用 法: void far getmoderange(int graphdriver, int far *lomode, 3 M3 M4 Y' u d5 m4 z
int far *himode); 8 @1 Z& [2 B4 ?* k8 _% w% l R
程序例: </P>
' e P' X: _( c9 Y! T/ K<P><FONT color=#0000ff>#include <GRAPHICS.H>8 q7 a, H, D" S7 C$ L U
#include <STDLIB.H>
0 |# ~& v+ X7 f; j9 c2 r#include <STDIO.H>
9 u/ M" M5 p9 X9 K1 y#include <CONIO.H></FONT></P>
( e4 ~+ I( s" m. a9 T" ~<P><FONT color=#0000ff>int main(void) / u$ c* w5 b, }+ k' O& {6 y. T
{
6 M+ P1 N+ D) [/ R# B& \% G/* request auto detection */
6 R4 i1 n* @! E0 C/ }( Mint gdriver = DETECT, gmode, errorcode;
* Y. m2 G$ N4 g( d# N4 uint midx, midy;
6 \8 s9 T6 k( e# n5 kint low, high; 4 S7 Y3 M$ |9 h e" l: c
char mrange[80]; </FONT></P>" l( |% y6 d2 K8 l
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 ?0 `8 `! o/ n. u5 S3 J; F6 K6 Yinitgraph(&gdriver, &gmode, ""); </FONT></P>5 W* y- u% N( N4 [2 ^7 N
<P><FONT color=#0000ff>/* read result of initialization */ 2 z0 o) u/ G) @! G+ L# R8 Q
errorcode = graphresult(); 1 ]' P. c5 t* \, B+ K
if (errorcode != grOk) /* an error occurred */
: J( H8 N' k( V: B( G{ ; o& {! q. d1 _. U" _$ D
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* L. j0 P/ | F Jprintf("Press any key to halt:");
: q0 o! V! ]5 k, {) Y3 sgetch(); 2 `8 H# v0 W- ^- ?9 `( P
exit(1); /* terminate with an error code */
2 H1 V# c7 V) |7 q6 u h- n8 [1 R} </FONT></P>
, a, t, J7 _: c# e+ I9 H1 |<P><FONT color=#0000ff>midx = getmaxx() / 2;
* v3 G* S- a( ~0 j7 o; _midy = getmaxy() / 2; </FONT></P>, b- q2 Z9 T9 W% S2 z
<P><FONT color=#0000ff>/* get the mode range for this driver */ ( [3 T, {4 x% { ?! U7 l0 y& G
getmoderange(gdriver, &low, &high); </FONT></P>
" {0 e" Q4 g$ s' u<P><FONT color=#0000ff>/* convert mode range info. into strings */ $ k2 x: p2 ^* U
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>' w" }4 ~, U$ l, V
<P><FONT color=#0000ff>/* display the information */
9 z. D& r/ c+ a, j9 ksettextjustify(CENTER_TEXT, CENTER_TEXT); 7 i: S$ s6 ^4 w) t: ]
outtextxy(midx, midy, mrange); </FONT></P>8 o5 s/ q1 X6 a3 H; t8 N
<P><FONT color=#0000ff>/* clean up */ 6 f+ b! `/ G2 I% N" U" x2 ]
getch();
0 d+ l3 o D4 p5 c/ h3 l9 m) I6 y# jclosegraph(); + s; W9 _, s0 V; b/ K( @2 R( B: g
return 0;
4 _9 N7 h- v: I6 e$ \# ^} ; G4 B- ?3 \: ]$ p3 J
</FONT>
5 j% \3 q, h+ H1 t- p" ^3 u/ b</P>
! K, e( k& f7 }, q/ s<P><FONT color=#ff0000>函数名: getpalette </FONT>$ Z( ~7 q4 Y. T7 f" k" [5 | K
功 能: 返回有关当前调色板的信息
9 G$ F2 F3 h" @/ X; f& i4 l用 法: void far getpalette(struct palettetype far *palette); 0 b1 s% Z3 d" z0 m" S% Q
程序例: </P>
5 J. G; H* c% N' z! {$ r<P><FONT color=#0000ff>#include <GRAPHICS.H>
) q6 m+ {" J" x, @! E+ P% |/ H' Q#include <STDLIB.H>
) ?- v$ w0 A# m9 }* M0 A#include <STDIO.H>" h# h5 c; Z6 l
#include <CONIO.H></FONT></P>+ I, E N& r- i b% m* I
<P><FONT color=#0000ff>int main(void) + v. M F* O, d# k% ?. y* L
{ + _ `/ p4 X5 }" Z I: a$ Q N
/* request auto detection */
/ |8 b) ?% u' ~# gint gdriver = DETECT, gmode, errorcode; 4 R& {7 g' X1 c6 I3 X
struct palettetype pal;
6 t6 a1 p' g% g5 _ F% R7 ?# c2 Rchar psize[80], pval[20]; ' k1 v9 W5 Z& g8 _
int i, ht;
! U+ g) I3 w* J; r. [( Sint y = 10; </FONT></P>% W5 L, `. h) l" a2 L, V
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - C; C, g8 F- E% P5 a6 f
initgraph(&gdriver, &gmode, ""); </FONT></P>
% }* H* u& o. ~0 s<P><FONT color=#0000ff>/* read result of initialization */ " c) t' Y: Q% @3 b- U
errorcode = graphresult();
! n5 e: y& Q/ F! Y/* an error occurred */ ) f( g7 g2 ]% P; L( T. g' u
if (errorcode != grOk) $ R4 k/ A1 d4 P7 a
{ " D( i/ t. t3 O( r
printf("Graphics error: %s\n", / a0 r7 _- U6 f+ J3 a* a
grapherrormsg(errorcode)); / d9 C. i( m2 c
printf("Press any key to halt:"); 8 ^# V; ?- u3 f# G) }& \& Y
getch(); 7 M0 p0 f2 t/ k# T' Z
/* terminate with an error code */ * \; L, n& T; v; P$ x0 M/ Y
exit(1);
1 s/ p$ N$ D3 G, @* S% }! j} </FONT></P>' T" m& M! A- U+ f- @8 B
<P><FONT color=#0000ff>/* grab a copy of the palette */
) O9 C/ W! q' d6 Ygetpalette(&pal); </FONT></P>
/ C" S3 `! q; s<P><FONT color=#0000ff>/* convert palette info. into strings */ 4 b4 ~5 |" e4 W, p6 y
sprintf(psize, "The palette has %d \ $ C( J6 N- T4 V0 @( Z- n, [" C
modifiable entries.", pal.size); </FONT></P>
' o6 S2 R4 O; [7 ? A4 h<P><FONT color=#0000ff>/* display the information */
" q0 B e# H8 T. ~1 e5 x7 s* oouttextxy(0, y, psize); * V9 O& G U5 D7 g2 X6 h+ a; R
if (pal.size != 0) , B$ y6 [5 Y( V8 i O
{
" T* [, w' x5 Y6 {, Lht = textheight("W");
F( ?" }+ i0 _# d) ny += 2*ht; # e: _+ d2 H/ u. y) R' X0 Y( L* m
outtextxy(0, y, "Here are the current \
. d/ g4 g5 K) h3 E4 a$ ?# ?values:"); 4 e* c( @& P" L4 c7 f1 P( O
y += 2*ht;
4 [ O5 B2 n4 `6 g' }for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> { 8 [) N* _& O, S
sprintf(pval,
8 }5 F9 J8 W2 F* C/ d' X"palette[%02d]: 0x%02X", i,
" a/ e; D' u1 ?# Tpal.colors); 1 w& p% k5 b4 D
outtextxy(0, y, pval);
5 i( D/ y2 C5 t o}
. F. d% V9 g* B6 U- Z} </FONT></P>
% ^$ h7 ^% T6 v M* V6 e. K<P><FONT color=#0000ff>/* clean up */ 1 U' e- r3 w! x7 i
getch(); 4 C% P8 x; z7 i9 R! N
closegraph(); </FONT>
+ ~! @3 I9 I! Q<FONT color=#0000ff>return 0;
2 H7 j; F8 g1 W D, E}
1 P1 r" o+ a$ ?9 D</FONT></P>3 m; ]4 M+ c! Y
<P><FONT color=#ff0000>函数名: getpass </FONT>
' ^- e" U7 E! c功 能: 读一个口令
. \ [7 j% T. x2 W/ v用 法: char *getpass(char *prompt); * i. S! T. A' {8 J* `' k& p
程序例: </P>
3 k; S" g6 ]$ {5 ]4 H+ B6 w<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
. v9 i0 [7 c M7 i: l<P><FONT color=#0000ff>int main(void)
5 L b7 I# a+ }4 z5 p8 W- ?9 r2 A b{ ' I! v0 Q- v! h. k n, k
char *password; </FONT></P>0 G8 I$ F: e3 N7 Z4 p" Z
<P><FONT color=#0000ff>password = getpass("Input a password:");
+ p U; v! g% l8 X0 [) Z1 Y" @* dcprintf("The password is: %s\r\n",
; @) t! z7 y6 Cpassword);
/ i G0 N3 K4 T4 \return 0; 3 p4 I( q0 ~7 D1 g9 |4 `
}
0 {; f; f9 Z/ A, ]</FONT>
% C. I' W, R- Y% D" x0 P9 m1 ?$ |" @# @0 s' F8 N
</P>1 |5 ?) c& [ |& ~/ |2 F
<P><FONT color=#ff0000>函数名: getpixel </FONT>! j8 N4 ?/ b$ j# M9 s
功 能: 取得指定像素的颜色 + X% y+ y& N; ^! [3 r ?
用 法: int far getpixel(int x, int y);
0 t: S3 ~) P# l程序例: </P>
; Y7 T e( Z; L) o$ E1 j<P><FONT color=#0000ff>#include <GRAPHICS.H>
; R' V; B" U( l9 J. n) R' p3 q) F#include <STDLIB.H>8 E- K' k, R, s8 V
#include <STDIO.H>
5 C8 A6 B0 t0 |# J+ @/ d! q1 b#include <CONIO.H>8 x( P5 H$ B( R4 n' x2 p
#include <DOS.H></FONT></P>- o% q9 {( Q2 k$ D
<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 ) a" H: e! w/ o- t/ }) W4 _/ F
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>3 g0 O7 c3 b* f# M; z: ?5 n/ [
<P><FONT color=#0000ff>int main(void) , H( b8 @+ g7 x' i
{
. B s* \, ?& e+ w; w7 p' v: R/* request auto detection */
# O- J6 C, Z! Q! X6 b: xint gdriver = DETECT, gmode, errorcode;
2 N: F3 o# O3 t& |! `4 bint i, x, y, color, maxx, maxy,
) J2 C& |/ ^/ j1 m4 R2 V5 W; h i# Amaxcolor, seed; </FONT></P>
$ l1 i6 w8 t2 N6 N8 D9 J<P><FONT color=#0000ff>/* initialize graphics and local variables */ # K4 F; H4 \" m. Q# z2 k, H
initgraph(&gdriver, &gmode, ""); </FONT></P>; @; `- L5 U$ X( L. B: t$ M
<P><FONT color=#0000ff>/* read result of initialization */ 3 A1 Z4 \& k; [4 s- s! y
errorcode = graphresult();
+ K$ n2 ~( ~! x8 s' y+ ?% }/* an error occurred */
3 V7 ]6 u# H7 T! h5 {& Y9 ~if (errorcode != grOk) 3 n) e0 r3 E+ ^1 W& T% W5 I
{
; y/ d4 r5 e3 W; V6 Cprintf("Graphics error: %s\n",
/ p- Z; W; S" X( Vgrapherrormsg(errorcode)); * ^) e- D5 |& P
printf("Press any key to halt:");
% q9 `3 i! Y' \4 S, @( `5 S8 Jgetch();
2 N' G, r' F- \3 h1 \/* terminate with an error code */ + l8 s; T3 `4 c q; U
exit(1); / D! q e1 L! e$ D
} </FONT></P>
6 j9 ?* g# P& o4 P<P><FONT color=#0000ff>maxx = getmaxx() + 1;
& p4 r. ]/ `; Wmaxy = getmaxy() + 1;
! \& {1 k2 v4 v1 j! x; y/ \maxcolor = getmaxcolor() + 1; </FONT></P>
+ h; k9 D: o. p* f; I<P><FONT color=#0000ff>while (!kbhit())
; T! U* |( E$ s. R. e{ + g5 U E" w( Y4 I9 ?3 r4 \
/* seed the random number generator */ - K% u/ ^* U6 \! l
seed = random(32767);
- @/ u: f% [0 M2 k4 j3 b/ Ssrand(seed);
6 m- d, H7 E7 i, A3 q& Nfor (i=0; i<PIXEL_COUNT; <br i++)> {
. X/ j2 z) y1 _+ Ux = random(maxx); ( P$ |6 K& W, C2 s
y = random(maxy); " O2 a7 Y! [4 x0 t6 g- }, }
color = random(maxcolor); 9 L1 r4 j( a8 A2 p! F& ^
putpixel(x, y, color); ( ^2 K: A' q+ m3 V8 \) C5 m% `2 n
} </FONT></P>0 I; Y" I8 \ _: E
<P><FONT color=#0000ff>delay(DELAY_TIME); ' G% d9 f' m% G; L6 w- J: m: \4 ], W
srand(seed);
r. Q% B/ M% `3 x6 I; ^: Hfor (i=0; i<PIXEL_COUNT; <br i++)> { ; @2 {2 q$ S7 S* P/ Y% y2 a
x = random(maxx); # C4 g2 X) I0 W* {/ Y
y = random(maxy); - u6 w F% a" m, T | z
color = random(maxcolor); ) h( h6 k3 n# h5 W4 X! F
if (color == getpixel)</FONT> </P>; q% G9 b" ?) X1 w L( Z
<P><FONT color=#ff0000>函数名: gets</FONT> / J% { u: a' p( X
功 能: 从流中取一字符串 + p, z$ |3 j) K8 P+ K5 h
用 法: char *gets(char *string); % e* M0 p7 q+ L+ @. N* n
程序例: </P>" G0 N$ |. N- {7 R9 ]
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
- j" W) ?+ M7 d4 B! u6 T p<P><FONT color=#0000ff>int main(void) 9 f; m& `1 G9 L& N1 q+ |1 Z+ A
{
1 V0 U: `; o9 F- l* T( b6 Gchar string[80]; </FONT></P>, p! n2 e: t/ J2 G4 a
<P><FONT color=#0000ff>printf("Input a string:"); : r4 A% ^0 l. i
gets(string);
* Z: M: I4 ^& `" b6 t) H! m8 {printf("The string input was: %s\n",
9 I- N9 z% ]& J. ?2 I1 Qstring);
$ h. y" }5 w0 o3 zreturn 0;
3 c9 n* P, l, g}
; C7 }) X& `* j- t ^/ x0 x/ U8 W5 c$ n; I3 u; T) g
</FONT></P>9 [( V5 I& U" H' B* F
<P><FONT color=#ff0000>函数名: gettext </FONT> a1 \2 N- M0 e2 ?9 Q: ~
功 能: 将文本方式屏幕上的文本拷贝到存储区
- j, V. f+ }& h/ S用 法: int gettext(int left, int top, int right, int bottom, void *destin);
9 Y; b$ n5 C- p8 c程序例: </P>
0 G2 D$ m) P2 ^$ x+ T7 I<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>/ z* A K9 k6 x# _
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
6 y2 ]! U1 D, g4 L6 @0 F3 z$ T7 y<P><FONT color=#0000ff>int main(void)
0 M. w H% a5 T! _{
6 X) G2 c& q4 G% i, Y: Cint i; 0 s1 R9 O; X# a: y4 s
clrscr(); 6 C5 d: R, u$ W7 A/ i- Z
for (i = 0; i <= 20; i++)
/ N8 f6 o. m5 A/ Tcprintf("Line #%d\r\n", i);
" i4 L% e! H- ?+ { tgettext(1, 1, 80, 25, buffer);
5 `: U9 D2 u* i. W9 X N- Agotoxy(1, 25); ; P7 p1 u5 Z% i" N$ j
cprintf("Press any key to clear screen...");
' j" }3 H4 K, ggetch(); ! q. b# Q- H+ I% z
clrscr(); + D4 }' s/ r3 @# x" J% x
gotoxy(1, 25);
B! C& \1 V& K( Hcprintf("Press any key to restore screen...");
0 o) X3 p9 D) ?2 \/ K/ A( Ggetch();
# r6 I& o% W4 d6 ^/ C- _puttext(1, 1, 80, 25, buffer); & S0 M/ L% c% W9 h& E& R. q
gotoxy(1, 25);
' Q) k/ c5 s6 f! [( A/ E+ m/ Kcprintf("Press any key to quit...");
$ c4 y. n n- Z0 Q9 y2 Ugetch();
* r% X0 v4 q( ^) v {return 0; {% f( e' H3 J& H, ?
}
( N. k6 l# C! U/ ]9 G" g* Z</FONT>3 g3 A: S/ n0 s! X5 I
</P>4 P$ Z& H4 S; l+ A% `# Y$ J
<P><FONT color=#ff0000>函数名: gettextinfo</FONT> : Q- @4 Z; n0 }
功 能: 取得文本模式的显示信息 : u# y+ t, ` _/ U
用 法: void gettextinfo(struct text_info *inforec);
( X& P2 @0 [4 Y程序例: </P># T" @1 s$ i9 M9 S7 E
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
* R5 c& }! p5 w( a<P><FONT color=#0000ff>int main(void) * j: \' [. ^: ~0 Q# p
{
& T6 v7 d1 M' \2 K& L. Hstruct text_info ti; 3 @! m+ s p2 ~, U8 a
gettextinfo(&ti); " e! I( b8 E" e
cprintf("window left %2d\r\n",ti.winleft);
; e7 h r8 d8 x0 k1 c* G- {cprintf("window top %2d\r\n",ti.wintop);
* N X0 o% Y( Hcprintf("window right %2d\r\n",ti.winright); $ v* e$ |$ g6 ?+ f
cprintf("window bottom %2d\r\n",ti.winbottom); . G( S* W1 {: b: Q% ]" @. F$ l/ \
cprintf("attribute %2d\r\n",ti.attribute);
" v$ y |$ w% I k0 D j( q8 `* t/ zcprintf("normal attribute %2d\r\n",ti.normattr);
7 @, t6 L8 K9 m2 mcprintf("current mode %2d\r\n",ti.currmode);
* |$ U# R8 D' \: ~1 f/ Pcprintf("screen height %2d\r\n",ti.screenheight);
0 j& q9 z+ f3 ^8 g7 j# wcprintf("screen width %2d\r\n",ti.screenwidth);
- ^1 |8 b$ t5 Y2 O4 p/ E$ Y: H7 @# ?cprintf("current x %2d\r\n",ti.curx); % d& V: ?* C8 J0 f, c+ d' A
cprintf("current y %2d\r\n",ti.cury);
9 u' A! E7 Q* k1 qreturn 0; 2 W0 N4 V9 D* t+ \0 M3 V
} 8 g( {" j1 T' o9 a* D
</FONT>3 q2 S7 K/ c0 r3 S. D8 }6 ~
</P>2 {& @: L1 e% A: k" `2 e# T
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
' L& g9 `6 ?/ @, w功 能: 返回有关当前图形文本字体的信息
3 D9 ?2 B' @( Q( ^% {用 法: void far gettextsettings(struct textsettingstype far *textinfo); ) [, L- i. ~, v" L. }4 f. b% ^
程序例: </P>
6 J. y9 u& _& R# e<P>#include <GRAPHICS.H><FONT color=#0000ff>" ]8 I4 u0 |1 y9 W4 M. K
#include <STDLIB.H>
3 [6 y. Q, c0 e#include <STDIO.H>
& p! z% s" o' l5 Q#include <CONIO.H></FONT></P>3 {: D' _' |" r. F/ `( v& ~0 K) F& e
<P><FONT color=#0000ff>/* the names of the fonts supported */ 3 U2 \8 d: x# H( C
char *font[] = { "DEFAULT_FONT", ( F; S& _7 r e7 |: b
"TRIPLEX_FONT",
: E, n k9 N- ^. P/ p/ G"SMALL_FONT", - o* Y" X) M5 {: a# {+ |& [$ U
"SANS_SERIF_FONT", 4 |% G) W, C, ?$ n
"GOTHIC_FONT"
; b1 m* x. R7 n% A}; </FONT></P>
Q) N6 @0 v- h) `6 B- f<P><FONT color=#0000ff>/* the names of the text directions supported */
4 P9 i# Z- }# A4 F0 I. Z0 g/ jchar *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>* n5 T7 u& G& r& S+ t; C& T
<P><FONT color=#0000ff>/* horizontal text justifications supported */ : G* ]7 h3 u8 b" ^2 v
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>3 h2 Q; Z* Z7 q: [/ u# `
<P><FONT color=#0000ff>/* vertical text justifications supported */ ) ]: C- a6 W& H
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
% v; v' ^# u, A! Y- @) y0 Z1 G<P><FONT color=#0000ff>int main(void)
9 r% O: F8 x4 m) L# h' N+ H! C{ 5 L. ?- ?, n* ~
/* request auto detection */
( @, |2 G/ |$ bint gdriver = DETECT, gmode, errorcode;
3 _2 w( n, K, ^( J2 s3 wstruct textsettingstype textinfo;
! @- r6 M- @" `: @1 @int midx, midy, ht;
7 @6 X! T3 J- k9 p/ Y9 K ^, R8 wchar fontstr[80], dirstr[80], sizestr[80];
: f" {+ I$ H# q# ?3 B" Hchar hjuststr[80], vjuststr[80]; </FONT></P>
# P, {; O: P/ q. [" F' d6 s* q<P><FONT color=#0000ff>/* initialize graphics and local variables */ , @+ E7 P, T1 L1 C- s! o0 G
initgraph(&gdriver, &gmode, ""); </FONT></P>5 a. e' d9 o; V- m8 r* u/ {6 v
<P><FONT color=#0000ff>/* read result of initialization */
. L7 C( _- j) N0 u' u2 `' Q" J+ terrorcode = graphresult(); ! U r7 E# e4 C& y9 T
if (errorcode != grOk) /* an error occurred */ 8 o( _5 s: R. L; p0 i4 R- }8 A4 A8 a
{ " P" m: Y$ a! G. x( F- }2 K0 `
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 i7 o1 @+ B; |printf("Press any key to halt:"); * _5 }9 n; P3 I- E
getch();
7 j1 b' g; i1 cexit(1); /* terminate with an error code */ : v- L( u# {1 O& F
} </FONT></P>
/ m" N% c2 A$ D% m/ P<P><FONT color=#0000ff>midx = getmaxx() / 2;
. ~0 j0 R. I; Tmidy = getmaxy() / 2; </FONT></P>1 }- W- Z9 q/ E3 e# ?! u' U
<P><FONT color=#0000ff>/* get information about current text settings */ 7 G1 X3 c2 z w% L
gettextsettings(&textinfo); </FONT></P>
. g C$ V- Y0 B, M' g! }<P><FONT color=#0000ff>/* convert text information into strings */
8 I3 R; k# Z8 ?1 [% i& q1 b4 K/ Osprintf(fontstr, "%s is the text style.", font[textinfo.font]); 1 ^' J' [/ o J' Z. Y. _
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); ( U5 C$ H# ]4 K G
sprintf(sizestr, "%d is the text size.", textinfo.charsize);
% F) |6 h5 ~. O0 n, Tsprintf(hjuststr, "%s is the horizontal justification.", - G- Z L. T& V0 Y' I
hjust[textinfo.horiz]); 1 G, q4 o7 \5 t& D$ f& X+ z0 v( w; H
sprintf(vjuststr, "%s is the vertical justification.", 1 ], `) S2 [5 Y$ J4 C
vjust[textinfo.vert]); </FONT></P>
/ S; G, Z8 Q: ~2 I! H<P><FONT color=#0000ff>/* display the information */
0 v! x, t i" M6 x+ S- H: Kht = textheight("W");
( I# ]4 P3 v# Z) h+ C% e1 _4 Ysettextjustify(CENTER_TEXT, CENTER_TEXT); & r5 U% |4 q" p% ^( A) O9 |
outtextxy(midx, midy, fontstr);
, }; J' m' B$ \outtextxy(midx, midy+2*ht, dirstr); . h. S0 s; I- C3 G# J* C
outtextxy(midx, midy+4*ht, sizestr); % [- z8 I+ ?# r" V/ B1 h- ~
outtextxy(midx, midy+6*ht, hjuststr); 0 F+ N! a9 Z8 r1 y
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
$ _4 c! L7 y3 c- W. u' Q6 u<P><FONT color=#0000ff>/* clean up */
! h" i1 @9 B, J( }' S+ k! Ygetch();
& q) w0 R, M, y+ x! s9 L. J' `closegraph(); & M, u$ ^6 i4 p
return 0;
# x6 S! @3 u" Y' y3 @% F, }5 p( D} </FONT>
- W; M" n$ y5 F7 t</P>2 J! @7 f p# \- s3 @5 \. R( r
<P><FONT color=#ff0000>函数名: gettime </FONT>. \+ A8 J8 G3 i' Z
功 能: 取得系统时间 * O/ Z, E* ~$ K7 s
用 法: void gettime(struct time *timep); 8 l0 U0 Y- |' \" [5 H$ l7 I: p
程序例: </P>$ d( t9 Y" d U, P
<P><FONT color=#0000ff>#include <STDIO.H>) i) Y8 ^9 [: O) d$ h
#include <DOS.H></FONT></P>
7 L+ _$ Z' p- ?/ k4 K2 D<P><FONT color=#0000ff>int main(void) / I1 p" X" W; ^8 [, i; z- w2 o. H
{ ( g/ D7 W' Z' g+ i" s( a
struct time t; </FONT></P>
& {% c. c0 O- `' ]( _# P<P><FONT color=#0000ff>gettime(&t);
' f6 D9 R4 Z: h& q& M7 L7 E v, Jprintf("The current time is: %2d:%02d:%02d.%02d\n",
7 A7 [' R1 @# I* `/ r. n9 Pt.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); " w4 U5 U( ]+ a6 `
return 0;
: i0 i1 U6 K* R' I& Y) F}
2 p1 K# p* \/ H. F& N, Q# Y5 h# v4 n7 e8 R& `
</FONT>8 C+ y9 I" L, j8 o% p/ M
</P>
$ s0 @; {3 |8 N3 R& C1 K+ d8 H<P><FONT color=#ff0000>函数名: getvect </FONT>1 g4 ~. {3 |, Z0 p4 Y/ E$ D8 d
功 能: 取得中断向量入口
- ^6 O! s. Z1 z1 ^0 e2 b& Z6 _8 X$ m用 法: void interrupt(*getvect(int intr_num)); : ?: `& h3 L1 t3 H: W/ \( `) g
程序例: </P>: X& {! M/ f0 w+ E* j4 d
<P><FONT color=#0000ff>#include <STDIO.H>' _3 m# n. c8 P6 v6 y# E: {% K
#include <DOS.H></FONT></P>/ o7 |& r- U. i1 z% T1 R
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>: w) d5 [0 @. W" \! r3 f: p
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ " b* H; T+ e, h
int looping = 1; </FONT></P>2 v# u1 h S: o" r
<P><FONT color=#0000ff>int main(void) ) F$ Q# Z, L2 z! t0 w6 L1 B
{ . U) s" D5 X1 }% Y
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
9 O4 R: ~0 U# a) {- W7 W<P><FONT color=#0000ff>/* save the old interrupt */ + D# ~8 l3 t/ m7 N/ T
oldfunc = getvect(5); </FONT></P>' l- r6 D8 k: t6 O
<P><FONT color=#0000ff>/* install interrupt handler */ - V- I E% l$ I0 o# v
setvect(5,get_out); </FONT></P>& Q- u$ K: s& @. L: c
<P><FONT color=#0000ff>/* do nothing */ * {1 J4 k2 j. m3 B! G. p; ]5 ?% K
while (looping); </FONT></P> l% O9 j4 i. K; t) U
<P><FONT color=#0000ff>/* restore to original interrupt routine */
- Q; @% [4 g0 x/ ^. bsetvect(5,oldfunc); </FONT></P>( b3 i! t3 W6 o& I+ C
<P><FONT color=#0000ff>puts("Success");
% Z2 @! V: Y7 P3 `return 0; 0 T# |+ w8 |, z0 r) i
}
L% u: A6 u+ Gvoid interrupt get_out() V9 t& l5 I1 w# p. u/ |0 _+ E
{ 5 ]1 t) I9 p6 n' b: h r' A3 d5 y
looping = 0; /* change global variable to get out of loop */
5 m9 @+ B2 s( ~/ ]) e7 K% V} / S" F! A, n* ~2 M
</FONT>
2 y. |, o, m( V" s a9 D5 [</P>; |0 ?6 Y6 x& f3 o5 \2 ^
<P><FONT color=#ff0000>函数名: getverify </FONT>
- g) d6 }' C1 o- o, Z& ~/ j5 ?1 D功 能: 返回DOS校验标志状态
9 r$ ~% Q0 V) i; ]用 法: int getverify(void);
^+ D6 U# C8 z$ X程序例: </P>
% v( {9 u! K Z C% l! m f* Q$ v% p* V<P><FONT color=#0000ff>#include <STDIO.H>
1 v% A2 l: }! A# n0 ]#include <DOS.H></FONT></P>
& F" W4 o# a) L) x4 v<P><FONT color=#0000ff>int main(void) 0 i! q: m6 S1 V; |" F
{ % x1 e) b; n5 \' G
if (getverify()) $ a) \+ z/ u2 U9 Z2 A: F
printf("DOS verify flag is on\n");
4 y: ~+ L; D8 i. qelse
9 S& i7 b$ N- R$ l2 Pprintf("DOS verify flag is off\n"); 9 P1 _ H4 g4 O5 ?) x. h
return 0; 2 C" z$ H! N0 N0 M
}
! f- `8 J" V- A- V</FONT></P>: }* u% Y1 ]3 P3 Z
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>, @/ ^* A q; u+ Y/ p z
功 能: 返回有关当前视区的信息 ' k) {! B# F8 a! U1 D* t
用 法: void far getviewsettings(struct viewporttype far *viewport); 8 z$ q; g4 ?' F8 Y! t& ]) {
程序例: </P>: x9 P8 G/ T+ }. d/ Y' H! z
<P><FONT color=#0000ff>#include <GRAPHICS.H>
& _5 i+ k* ?; |; ~6 h- A#include <STDLIB.H>$ t7 d6 v9 G; S- T1 l
#include <STDIO.H>( u) w+ g$ o: E' I. R2 X
#include <CONIO.H></FONT></P>$ h w( U1 [- L% _" [
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
+ T6 w! s* p! S) |" J4 G& U<P><FONT color=#0000ff>int main(void) 4 u- H9 @* p" `9 b
{ 9 `% s2 b# M$ h- w+ H0 ^0 U) X, N
/* request auto detection */
* ?1 L# t3 L: A7 Oint gdriver = DETECT, gmode, errorcode;
: N% u3 T! w: V" N& Ustruct viewporttype viewinfo;
4 a) z. t# @5 c. Zint midx, midy, ht;
+ }" n3 ~2 [; a# i1 lchar topstr[80], botstr[80], clipstr[80]; </FONT></P>, r! A7 T! F9 {, I
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 b5 {6 W& _5 L/ `% W+ P. winitgraph(&gdriver, &gmode, ""); </FONT></P>
7 x' E# s' z' ^<P><FONT color=#0000ff>/* read result of initialization */ ' N4 ?# y/ S5 @/ p
errorcode = graphresult();
3 H* e! ]3 ~: j. wif (errorcode != grOk) /* an error occurred */
: H! y1 k; V4 M8 \- m# f" _1 d{ 9 O! Y9 G7 [. C( a' A$ I
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* u: a# b4 {/ a' eprintf("Press any key to halt:");
1 C, @; N* C; X4 ~getch();
- A/ y6 J/ V2 a$ rexit(1); /* terminate with an error code */
4 |. S8 Q8 o( `/ ~} </FONT></P>6 X# W8 K/ X, `
<P><FONT color=#0000ff>midx = getmaxx() / 2; - a2 P6 G; w. J* g- @
midy = getmaxy() / 2; </FONT></P>
/ \) G0 ?# _+ L# X+ j<P><FONT color=#0000ff>/* get information about current viewport */
# L6 W* I2 Y$ Dgetviewsettings(&viewinfo); </FONT></P>
4 M, ~ G0 J# L8 w1 e<P><FONT color=#0000ff>/* convert text information into strings */ * j0 \& S( @1 p* {! U1 O
sprintf(topstr, "(%d, %d) is the upper left viewport corner.", 6 v6 i: `" c& ^
viewinfo.left, viewinfo.top);
1 Q" {+ s' F0 Z: O* ~- K$ psprintf(botstr, "(%d, %d) is the lower right viewport corner.",
/ Y! e+ r1 |$ n- |6 Nviewinfo.right, viewinfo.bottom);
4 T8 {' I6 b! X4 Wsprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
; P- Y3 h2 D4 t0 a1 S) P9 o<P><FONT color=#0000ff>/* display the information */
3 l- ~. C( x( h( F: N' w& R7 K. usettextjustify(CENTER_TEXT, CENTER_TEXT); 8 \) m7 }5 `; t. ?, {& P, l4 t# S
ht = textheight("W"); 7 O; l4 m$ a. ~; b3 \7 q+ j" i- n
outtextxy(midx, midy, topstr); - ~) C }0 w- u! `1 r& l, a
outtextxy(midx, midy+2*ht, botstr);
+ ~9 z7 v8 t d$ oouttextxy(midx, midy+4*ht, clipstr); </FONT></P>1 \' U9 Y2 e0 I! m6 r
<P><FONT color=#0000ff>/* clean up */ 3 l# z! f) Y& x+ q5 N v
getch(); 8 s) N8 y; D5 R `. f; f
closegraph(); 1 \4 I N& v' r/ ~. ]. C
return 0; * D; Q: y. G, t, n, t p
} </FONT>$ t9 F" A2 b B8 y; c- q3 ?
- C0 V2 I* q K$ q; D9 ?
</P>3 d7 |1 H7 C7 a2 B5 C( _
<P><FONT color=#ff0000>函数名: getw </FONT>+ S/ c& C A$ ?1 L. N% p
功 能: 从流中取一整数
5 ^) e- p P- l& U, B3 H用 法: int getw(FILE *strem);
7 d& E! \; [+ ~5 Q. ]1 D( R" u程序例: </P>
% R/ F& e/ M2 t+ w' V" U<P><FONT color=#0000ff>#include <STDIO.H> c; q+ q, c( _6 b( K \' p# D
#include <STDLIB.H></FONT></P>
" o3 H* S; B. H4 G<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
& q% y. g! c5 q' D' R* L6 o" h6 I<P><FONT color=#0000ff>int main(void)
( r/ ^" I$ g2 k4 D/ w5 i{
* ^! }) [. ]5 N5 r2 Z: U: RFILE *fp; ! j% G! ~1 i+ A* @7 ~! N1 }# }6 ~& x
int word; </FONT></P># T" t8 r& [( F, z1 m- E- k
<P><FONT color=#0000ff>/* place the word in a file */ 9 J" e- |. J) w' q! s B6 Q
fp = fopen(FNAME, "wb"); . Z$ ~/ a, Z+ i2 d* L! J* n
if (fp == NULL)
! k; W* V8 C" ?{
% N6 S: i: \& ]5 Y5 Qprintf("Error opening file %s\n", FNAME);
7 e- m1 P, H* M8 H+ x5 p( `exit(1);
$ {% A& X+ |) }" s7 h' a} </FONT></P>
9 m+ w; F3 K1 A! r4 [<P><FONT color=#0000ff>word = 94;
7 Q9 f5 v- _! C9 ~putw(word,fp);
) a0 l4 { Y: U: J& Gif (ferror(fp)) 6 i: n' m$ d& D6 l7 O9 F y
printf("Error writing to file\n"); / t$ ?6 E# u0 q! k3 p9 z) K) n7 h" k
else
0 _$ N: Y. A* W9 w* zprintf("Successful write\n"); * z6 e. i; Y( f7 C1 l" O9 t, V: Z
fclose(fp); </FONT></P>7 @3 H, V' N) U' d" d# G2 T7 ]
<P><FONT color=#0000ff>/* reopen the file */ 0 C1 u5 P$ y; P6 r" N
fp = fopen(FNAME, "rb"); ! i l$ Y1 Z" r& @$ G9 O$ T
if (fp == NULL) 3 i1 p) k# }' }2 B
{ & L1 _' c7 C5 N. N& j2 H
printf("Error opening file %s\n", FNAME); ; Y' {, j" F w/ X$ n0 i: g6 J
exit(1); ; L5 c" ?- U4 c v
} </FONT></P>
, B7 K) Z* l' q8 e3 d: x9 |<P><FONT color=#0000ff>/* extract the word */ ) f( \, R/ k# B4 h8 I
word = getw(fp); 5 L" C# J& K" G! A- m" |
if (ferror(fp))
) }9 r5 R. ~, a* R9 L" Vprintf("Error reading file\n");
7 w( u/ c5 @* P* s: Z' Relse 0 e2 G( n9 z1 r! _: k7 w
printf("Successful read: word = %d\n", word); </FONT></P>& x, J+ ]* s! B
<P><FONT color=#0000ff>/* clean up */
$ C2 z I0 v7 L2 g0 Z# w& Sfclose(fp);
; W3 f* I: R+ I# Qunlink(FNAME); </FONT></P>1 J" v" g- O' X: A
<P><FONT color=#0000ff>return 0; # e9 x( P# A5 z* |5 Q7 M% p5 i9 i
} </FONT>$ l$ M* `4 z( J1 v1 d* e: {' l
6 E o4 ^1 ~# \- v) K, ?* i9 _: {/ z0 A" |; S7 b
</P>4 a0 |2 M3 [8 D% U2 Q* L( {0 A
<P><FONT color=#ff0000>函数名: getx </FONT>
! v( p5 l0 x8 P- `# x功 能: 返回当前图形位置的x坐标 8 G0 k; Z) z9 k" ~. W; o+ D/ b1 t$ ]
用 法: int far getx(void); ; u( ^1 P0 K T6 N/ [0 ~/ D1 N5 ]& W
程序例: </P>6 F' A2 ?3 X( R
<P>#include <GRAPHICS.H><FONT color=#0000ff>2 ]- C6 h' P& q q/ \3 B* M. T6 O
#include <STDLIB.H>( p/ `0 f, k ]) c) b% [1 d
#include <STDIO.H>
j! ~4 x3 b! C5 T7 b#include <CONIO.H></FONT></P>
- ]$ ~. E3 ^+ H6 |! c2 }7 H* G<P><FONT color=#0000ff>int main(void)
6 ?$ h m* V/ b! g5 `5 a{ 2 m" L/ l8 A! L( l! ~
/* request auto detection */ 8 m! ~+ h9 D- o# n
int gdriver = DETECT, gmode, errorcode;
' m4 G9 s. Z9 _/ B; e4 o( W) Nchar msg[80]; </FONT></P>8 [# W+ T+ M. E4 ~. R0 H
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 v7 z! P4 q7 K( m3 f$ X
initgraph(&gdriver, &gmode, ""); </FONT></P>% t9 O! M6 t; C Y
<P><FONT color=#0000ff>/* read result of initialization */ 2 m: Y% ?0 c2 R* E" F: v
errorcode = graphresult(); 5 L& s/ H4 C- b, k) `1 Y
if (errorcode != grOk) /* an error occurred */
, G) X/ Z# E; h+ B( _& U{
$ V1 C3 j& p7 V& D7 \' Sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # k, c5 }* A/ \% I5 Z
printf("Press any key to halt:");
/ A6 B( C$ x; R( lgetch();
" }% O" u4 W. M/ Y# wexit(1); /* terminate with an error code */ 9 w c7 E; G* S9 G1 ?: v. O
} </FONT></P>
5 ~2 S. e. z `7 o' R) j<P><FONT color=#0000ff>/* move to the screen center point */
3 d% R5 ]- K! ~moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
- P3 p P0 B; c<P><FONT color=#0000ff>/* create a message string */
# A2 F- B6 g0 E. h6 [sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
% x4 L- B+ o! Z- C<P><FONT color=#0000ff>/* display the message */
# C1 K/ U- T) e! Wouttext(msg); </FONT></P>
2 _8 N" [2 N9 t; J- w3 g% M3 R<P><FONT color=#0000ff>/* clean up */ / v( u j; t1 }7 P) l* o
getch(); - Q& |$ t% { v$ ` M
closegraph(); - x( z( J# c. q8 }5 o) N
return 0;
& K5 \6 M; M. m1 x* o, U} </FONT>1 H/ h( D [0 z8 j# p
# k4 O- M: ]! b( A# r8 a# F</P>$ C; a+ h$ C. W; x
<P><FONT color=#ff0000>函数名: gety </FONT>
" N" O; s6 V' F功 能: 返回当前图形位置的y坐标 3 {+ e' l9 e& R! G
用 法: int far gety(void); B2 L7 ^/ e6 b! h% f$ n' ^/ O
程序例: </P>7 t0 m7 I' P0 O* G! N& Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>% S& k# g! _+ G& [0 y. ^3 `- @
#include <STDLIB.H>. Z. @/ r( m2 A9 Z1 `6 c; p2 c
#include <STDIO.H>6 }/ T" X0 }" m
#include <CONIO.H></FONT></P>* X* V; G5 ^% o, F' R
<P><FONT color=#0000ff>int main(void)
$ O# W+ K2 u" [" r5 C- x$ z% T{ * O- n _) e0 t0 t3 Q
/* request auto detection */ ) F" K7 T3 R9 H! z
int gdriver = DETECT, gmode, errorcode; # r& p+ R3 H" {8 A4 F( C, G/ a
char msg[80]; </FONT></P>
% G6 I3 G5 Y G1 }0 K3 E1 G<P><FONT color=#0000ff>/* initialize graphics and local variables */
& y* G7 F# Z! E" V* zinitgraph(&gdriver, &gmode, ""); </FONT></P>% T3 q9 K2 \* L: f3 z, ~
<P><FONT color=#0000ff>/* read result of initialization */
3 P7 U* ^3 }: [6 a* t8 M$ Yerrorcode = graphresult(); 5 J% S% V9 f: l, l# o3 S8 v
if (errorcode != grOk) /* an error occurred */ + W1 E s0 z e/ T4 M# t! D" B
{ ; F: v0 m' z# L: h8 h2 l$ a9 d$ X
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : c% V" N' F0 D# K) ?
printf("Press any key to halt:");
# v$ ]" G' Z- K" f7 A3 q- V4 D/ L5 N- q& agetch();
& G: ^8 p4 d$ K' i. Zexit(1); /* terminate with an error code */ 9 T# ? Q* i+ i5 M3 K, i
} </FONT></P>/ k8 m5 J; N# s' G
<P><FONT color=#0000ff>/* move to the screen center point */
2 {5 ?2 \; t( x. S! Hmoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
; U6 Y% e1 T" U& m9 @$ }<P><FONT color=#0000ff>/* create a message string */ $ w( J! {- j# h* j' W
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>3 `; b) m7 _( ?, Q
<P><FONT color=#0000ff>/* display the message */
& S1 N1 w6 b6 r( d8 [; ]outtext(msg); </FONT></P>4 q _2 y G8 |5 L# \# i
<P><FONT color=#0000ff>/* clean up */
7 ^! |4 a& t* Q" V$ qgetch();
, _% ?/ C! M5 G* D9 u' Y; _ oclosegraph(); * `* u8 a Z% H; u* n9 |% ^- n
return 0;
+ S& {( N* i4 A# G} </FONT>
$ s# x- f) u1 g% K9 S$ {4 l
2 G3 K z6 M& Y& K* T7 i' `. o</P>/ c. W2 A9 W$ ^7 g
<P><FONT color=#ff0000>函数名: gmtime </FONT>
. n1 z% I. Q( z, f* ]/ {- |' [: y功 能: 把日期和时间转换为格林尼治标准时间(GMT)
7 ~/ k$ @! k" ~2 W用 法: struct tm *gmtime(long *clock);
4 k% Z; k5 `" D程序例: </P>
& I0 d' [" X2 ~ a7 \<P>#include <STDIO.H><FONT color=#0000ff>
3 G! i6 Z8 G) [9 ^# H#include <STDLIB.H>
( B6 X3 i) ]2 s#include <TIME.H>, i% D* o1 g8 A& b, B# e7 o
#include <DOS.H></FONT></P>
" e: H7 t1 G5 m! v/ U<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */ 6 T+ I' c [1 l1 a3 ~
char *tzstr = "TZ=PST8PDT"; </FONT></P>5 X |7 R- a, y0 H! k6 v
<P><FONT color=#0000ff>int main(void)
b* D* N5 a% S2 `( }! D" C{ f1 U8 \3 \) l! S1 s7 w
time_t t; # P3 I- r& ~/ N2 n8 k, B% i
struct tm *gmt, *area; </FONT></P>
% }2 s& S! c+ ]7 h4 b. {<P><FONT color=#0000ff>putenv(tzstr);
* T% r- u- m9 j6 ntzset(); </FONT></P># S; @! r; B4 T" o9 b/ h/ X, } ~ D
<P><FONT color=#0000ff>t = time(NULL);
! l* C/ z. S# s3 garea = localtime(&t); 3 A7 J$ B. L" \3 p/ H4 o
printf("Local time is: %s", asctime(area)); 5 |. F8 j$ C5 Y7 c
gmt = gmtime(&t);
' h: C: Q9 L! }printf("GMT is: %s", asctime(gmt));
: S6 X' J# V% c$ C5 hreturn 0;
1 @# H. D. p4 q a! |4 V} </FONT>3 ~$ @7 `0 ~% B# @
; Q. K9 x) _9 U! N</P>
8 t. ~! d8 h* n' X5 e. R<P><FONT color=#ff0000>函数名: gotoxy </FONT>
" Y0 }" k( P# g% {功 能: 在文本窗口中设置光标 , V3 I/ A4 ]$ k. m" S, {) f1 H4 `
用 法: void gotoxy(int x, int y); : f* Q( r* V. n: O; e7 V) h3 Y
程序例: </P>
4 ?% {7 t' `" L1 R* s% G/ Z<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
* h2 J. Y ?+ Q4 O# b8 }0 N' Z<P><FONT color=#0000ff>int main(void)
, v6 }/ s: q% V5 w{
+ F# E* A% {& _clrscr();
( q7 {' t: _" k) p' _1 L- \* Wgotoxy(35, 12); 8 ]0 @4 R+ L4 X+ B3 c
cprintf("Hello world"); " d- I* X6 e) R1 T4 [
getch(); ( W( ^6 g' B$ T/ P4 j
return 0;
}: K6 ?7 V+ u: D% O5 c% c}</FONT>
' c. o8 I2 G7 c- |: i Y
2 N5 H: |. O6 @) C2 y$ P- W</P>
/ x: j' R# g7 x1 O. c U: N2 m<P><FONT color=#ff0000>函数名: gotoxy </FONT>, t5 {; i, {7 X9 K0 B
功 能: 在文本窗口中设置光标 ! b& r D! n$ u0 q
用 法: void gotoxy(int x, int y);
3 E7 T/ E. t3 o; v: `. V程序例: </P>
! u1 I& `8 r$ |) O/ ^5 o ^% v3 ^<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
5 ]( `" _3 Q# X& T% P5 j. R7 e<P><FONT color=#0000ff>int main(void) 7 r V x+ Z( |) T6 N& K3 `
{
% j; @+ y7 c3 `5 V, M/ S& [clrscr(); : t" V# l+ U0 `* \" Z; E0 V
gotoxy(35, 12);
& q7 O) b& d& X6 E3 F5 V0 n2 H2 ~! ecprintf("Hello world");
0 S2 U+ }* v% S6 Tgetch();
, Z" y$ r% b# treturn 0; - G& G! C3 Z! G8 H' E3 D
} * v- B) W" d! y. D5 Y& Z+ C& P P
</FONT>
) x, U9 }' M7 ~/ U+ M5 q& i</P>6 r# U: r$ @: F0 y* G
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
# ^" O2 N5 ^. T+ \* B! z功 能: 将所有图形设置复位为它们的缺省值
- }7 p; O$ u3 v4 G6 r6 Y: H( A5 |用 法: void far graphdefaults(void); : H3 z6 n% P! D( O* p k
程序例: </P>
( s; _3 g% D! {! y |' A( o# B r<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ K* F4 O% _5 `#include <STDLIB.H>
0 d" l! z0 e3 z8 i#include <STDIO.H>9 @* X% W. R& B+ i- x
#include <CONIO.H></FONT></P>( D. g; ~2 g. M$ o- |9 ~
<P><FONT color=#0000ff>int main(void)
2 g0 U; D& p# y) F! H{ $ J# C) u7 o/ J- g
/* request auto detection */
: h$ Z, g- I7 v6 N$ \; O; Sint gdriver = DETECT, gmode, errorcode; + o9 L& a, S9 g$ p: W8 T2 {/ D
int maxx, maxy; </FONT></P>$ Q% R! f! n% @
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" h9 x6 v% y" J! q. L" ninitgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>& p( C8 P. G' ^& K
<P><FONT color=#0000ff>/* read result of initialization */ % S9 _) g% n1 j
errorcode = graphresult(); ; n: h* c$ H& |' C' ~& v
if (errorcode != grOk) /* an error occurred */ + X4 ^. L+ N& I; T
{ - `9 x0 H; I( n/ e+ O
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ j* i" w" {5 m4 X- N+ Jprintf("Press any key to halt:");
% F9 c. R! {# a$ _# \$ A( pgetch();
1 z7 n5 a# F" q1 m- c' Q; E' ]exit(1); /* terminate with an error code */ : M! S) X9 w2 j w
} </FONT></P>
+ c' d% `9 k2 G( d<P><FONT color=#0000ff>maxx = getmaxx();
* w0 N& J3 x" ]9 d2 @6 z4 a) _) ]maxy = getmaxy(); </FONT></P>
6 t: K4 D2 Z7 j: q/ ]3 N<P><FONT color=#0000ff>/* output line with non-default settings */ $ h, s' j& B! ~( n* F- @
setlinestyle(DOTTED_LINE, 0, 3);
2 r6 e5 E& |3 L0 A$ J9 r5 f% cline(0, 0, maxx, maxy);
+ W# j( B* R! }8 {2 u9 v" M4 H$ youttextxy(maxx/2, maxy/3, "Before default values are restored."); # ]8 i2 L' T$ P! F P8 K; L/ ?9 B7 h
getch(); </FONT></P>. Q* f1 y! g/ m: ^8 D1 I) {* d
<P><FONT color=#0000ff>/* restore default values for everything */
8 m# g) C( D/ Dgraphdefaults(); </FONT></P>5 @0 x; ^+ @4 R
<P><FONT color=#0000ff>/* clear the screen */ ( C- D. J0 E1 L3 o5 t6 X
cleardevice(); </FONT></P>& N' C/ J1 y7 f+ M. u
<P><FONT color=#0000ff>/* output line with default settings */ 3 }, d3 j5 W' @3 h' i
line(0, 0, maxx, maxy); 6 g. z# ^7 @# L0 y( e
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>% @/ i5 K$ J* j% d( P: u% V4 E
<P><FONT color=#0000ff>/* clean up */ $ P4 i6 \4 p2 B& r" l% V
getch(); ' L( ~/ o; z0 ?
closegraph(); 7 e& g% }2 `9 r9 x4 ~% x$ e
return 0; " g3 l' ], d) w+ ~6 C/ R" b
} H3 a6 q) c, |3 S7 @
</FONT>! p/ M% C& S' c U d o) P
</P>. ]. w$ y1 s6 H$ s" ^4 W( P$ P
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>) U& b) w' a4 W' M
功 能: 返回一个错误信息串的指针
' @+ x6 ^; h, Z' Y; @! M1 O( F用 法: char *far grapherrormsg(int errorcode);
: l8 S% @9 W0 R# F程序例: </P># n( _3 x, G. U( G- q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ B* V2 t2 \+ }* ?* G( }#include <STDLIB.H>4 a+ b) B! K/ {$ }5 Q
#include <STDIO.H>
! M" `2 V/ H4 I9 u( ~$ g" k( e#include <CONIO.H></FONT></P>& v3 E9 n/ L# O: j% I& E$ i
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
- _) Z( Q! d* r4 F<P><FONT color=#0000ff>int main(void) 6 V: h$ M2 P' J$ q
{
) R9 }1 m1 \ M2 i( n* a G8 N/* FORCE AN ERROR TO OCCUR */
$ p. s1 V: n6 yint gdriver = NONSENSE, gmode, errorcode; </FONT></P>3 k" h; n8 y. Y, Z! k9 P& D; C
<P><FONT color=#0000ff>/* initialize graphics mode */ ; H2 A( e* j& e- D6 d
initgraph(&gdriver, &gmode, ""); </FONT></P>
4 g. Z! Y l/ l! W3 x<P><FONT color=#0000ff>/* read result of initialization */
' U' y6 A: D. F% P& Werrorcode = graphresult(); </FONT></P>. v: M8 [0 `* z. \, z% f# o; d
<P><FONT color=#0000ff>/* if an error occurred, then output a */ - G3 K7 {' G3 P. q
/* descriptive error message. */ % o/ G, ^* ]! J0 I7 j( h
if (errorcode != grOk)
6 x* L9 K" K: Z( t5 K. ?{ 2 g7 h- J0 L+ Q& g% O" r/ Z, i& W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 T @! K+ o3 A. ~% m8 s
printf("Press any key to halt:"); ( k+ A( g4 m: c4 H0 ?/ D" l: }2 @9 H- T
getch(); . H# S* V8 {' o9 S
exit(1); /* terminate with an error code */
( l* @- _( Y, s; f. E) ?; R} </FONT></P>
% X7 X1 y( p- w2 R6 n<P><FONT color=#0000ff>/* draw a line */
% O4 ?. Z7 ^- @7 R+ L! tline(0, 0, getmaxx(), getmaxy()); </FONT></P>
J* `, T2 E2 n$ u3 Y* `<P><FONT color=#0000ff>/* clean up */
7 k/ V4 t* Q6 h5 g0 P5 cgetch();
' @& A4 B3 \8 @closegraph(); ' @' B; @, Y7 [
return 0; 1 c# F5 u* \' }' U
} 9 H. R- P6 x0 K0 M t
</FONT>
{/ `0 r0 R$ o! V' L7 @</P>' ]1 z2 P9 ?; y( p, W( k" T- z0 e
<P><FONT color=#ff0000>函数名: graphresult </FONT>
' B) X! }- W' O9 W. M/ ?- }$ |功 能: 返回最后一次不成功的图形操作的错误代码
8 L- f' Q0 y& y: r) i用 法: int far graphresult(void);
0 C2 Z! p! j+ V: v1 J Y% S程序例: </P>" `* e, h% w- w* z: {- N
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 b/ i. t G( Y$ L2 U" H: K) Z) {
#include <STDLIB.H>
6 L9 j2 ^' Q* W+ w: |+ Q& ^8 T1 u#include <STDIO.H>
, a; Y1 L- K, q2 e1 c#include <CONIO.H></FONT></P>
# k7 {2 J7 ?" A4 U6 f9 Y1 G<P><FONT color=#0000ff>int main(void)
) K1 X9 N" ]; n{ & U) A6 K& t6 W3 N1 O) L
/* request auto detection */
7 f1 W; x( l; N0 Vint gdriver = DETECT, gmode, errorcode; </FONT></P>
6 W5 u6 l a+ O4 J<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 A: P9 i- `2 l
initgraph(&gdriver, &gmode, ""); </FONT></P>6 ?) d! u- o+ W& l2 ]% o
<P><FONT color=#0000ff>/* read result of initialization */ 4 u" E) q6 r6 `2 Y4 M
errorcode = graphresult(); </FONT></P>* U6 C+ k+ G3 F7 g
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
. a0 T& g1 V& h0 \! }- s/ G3 t{ ) Y1 C7 _# \' P. T% A
printf("Graphics error: %s\n", grapherrormsg(errorcode)); - F8 f- h* ]. C0 [ s) I5 Q
printf("Press any key to halt:"); $ K- M/ p0 C3 Y
getch();
3 Q% h. }8 j0 Z6 w4 y) Lexit(1); /* terminate with an error code */ % K+ g5 e5 Z( _: r/ M1 d
} </FONT></P>& l. h; E5 h. g$ o
<P><FONT color=#0000ff>/* draw a line */ ! o8 m; ?" x, S+ Q$ V4 p
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
* Z7 @ f* V. s1 o; J+ F* K' |<P><FONT color=#0000ff>/* clean up */
; V. l2 s: L3 A" e+ M; \getch(); 1 B# x" j t% h( }
closegraph();
# s1 \7 }6 r: [' q3 ?4 b9 `1 _. creturn 0; |! Q8 w& _1 [' M. \% {# B1 K5 W
}</FONT>
! K; R4 k4 X8 [8 @- }</P>
; f/ f$ W0 b/ @. o9 Z/ \) ^<P><FONT color=#ff0000>函数名: _graphfreemem</FONT>
4 x# ^! S* n! G+ H4 D; n功 能: 用户可修改的图形存储区释放函数 : G& [6 j* K" ], Q; E3 \" J7 d
用 法: void far _graphfreemem(void far *ptr, unsigned size);
/ }9 I& q4 d9 N程序例: </P>
" C& j! K5 s- o4 a; e<P><FONT color=#0000ff>#include <GRAPHICS.H>
) \( _9 t" F. ` h$ x# E#include <STDLIB.H>2 ~4 Z' A! D5 g1 `) f8 Z
#include <STDIO.H>" l/ z C: A, t' h+ k
#include <CONIO.H>0 |: v2 N, k% c# N' i" ~7 @3 D4 {
#include <ALLOC.H></FONT></P>! x& h$ h2 z( @* Y; m
<P><FONT color=#0000ff>int main(void)
9 Q0 V. [2 i1 Q3 u0 G% y9 _8 t0 ]# O{ # l6 u' w* k* s# c( @% x
/* request auto detection */ 1 O/ [7 ^. _1 t" p
int gdriver = DETECT, gmode, errorcode; F! S$ O- z/ E( T4 z; |2 D' {' |
int midx, midy; </FONT></P>/ ^6 k% p) D+ U1 U
<P><FONT color=#0000ff>/* clear the text screen */ 9 s3 M l! u7 }, K* c" G
clrscr(); 3 J2 d9 m% i! k. n
printf("Press any key to initialize graphics mode:");
& ]7 i- M/ P, S3 k# o- l. ygetch(); ; M+ O7 t$ C( \! h- F
clrscr(); </FONT></P>1 B( H0 O3 h; t3 _- \
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( ^0 d2 j+ a! ]. K/ H j% f
initgraph(&gdriver, &gmode, ""); </FONT></P># l, w7 H4 z% Y" }4 w
<P><FONT color=#0000ff>/* read result of initialization */ ; a5 h: ]# A+ m3 N, r! t$ d. y: d
errorcode = graphresult(); , A* \8 E$ d: C4 h
if (errorcode != grOk) /* an error occurred */ 9 G8 i2 v, _0 {; Y8 L5 r3 _( B3 p
{
- [1 V$ B1 x7 Z" N/ o$ j) ~- Lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / k: X1 |' w# V6 Q+ y
printf("Press any key to halt:");
5 [$ M( \1 k* h2 Y& O( W8 `+ y9 ~7 lgetch(); 5 V( ]! m0 Q9 ?; E2 ]
exit(1); /* terminate with an error code */ 6 s% f" l4 j! J, F: b& S
} </FONT></P>9 M3 u" a# O3 ~- y
<P><FONT color=#0000ff>midx = getmaxx() / 2; ; Z6 d+ u7 U- [. E! `
midy = getmaxy() / 2; </FONT></P>. F6 |0 W; t7 ] B1 n# c1 q
<P><FONT color=#0000ff>/* display a message */
' K0 s! }$ j# ^- f! jsettextjustify(CENTER_TEXT, CENTER_TEXT);
' F- a6 q N/ v. gouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
: q4 B9 p3 @; K0 `<P><FONT color=#0000ff>/* clean up */ ; c- K! {2 [: A9 U% f {
getch(); * D1 A' N+ h8 ` H9 Z$ X$ b
closegraph();
! L4 L4 u: Z. A* ^8 V) jreturn 0; 0 D: ]& Q0 n& [* i) ^
} </FONT></P>
. Q8 i. ]* f f0 c<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ ) w( b# F, G# I9 e
void far * far _graphgetmem(unsigned size) ! o/ Y2 ?: ~2 A) t- E& R
{ 2 \+ t9 v" C8 A" K2 }! K* ]% d
printf("_graphgetmem called to allocate %d bytes.\n", size); ' I6 H# Q$ A: h9 H+ ?
printf("hit any key:"); 6 }( [+ \) ?' ^' o; c+ H1 _# p
getch();
* z2 |# y# C. V: }% q- V4 Oprintf("\n"); </FONT></P>: {0 m# R8 m i2 y9 x9 q/ m. y
<P><FONT color=#0000ff>/* allocate memory from far heap */ . C: P7 ~! m4 d% l( y
return farmalloc(size);
: _2 |* s' [. k} </FONT></P>
5 ]" [: c, d2 z+ p9 \<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
; [) b7 O& g7 A. Avoid far _graphfreemem(void far *ptr, unsigned size)
N- x$ J2 L7 _' X{
5 {/ W: z u/ {% C. q, D+ l' ?1 cprintf("_graphfreemem called to free %d bytes.\n", size);
- s3 L) k+ ]3 D# _* g; W3 Z6 Fprintf("hit any key:"); , S( M* ~8 s' ?" ?6 t7 d
getch();
2 H5 t6 R3 W) ]0 e9 G9 {# x( E/ hprintf("\n"); </FONT></P>
1 g* H+ d* \. l2 ?<P><FONT color=#0000ff>/* free ptr from far heap */ : A. B/ B3 J) y5 v3 v+ e; P6 y* v
farfree(ptr); 2 d+ ~, U: Y, z5 W- e9 J
}
2 Z, H! h6 r" T8 z/ a+ M0 I6 W0 f</FONT></P>
1 }7 l- I G1 v) R& q1 x2 l<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>4 _3 V5 ^5 r8 p2 N4 j
功 能: 用户可修改的图形存储区分配函数
. E0 c' r" `' e' m1 _& @用 法: void far *far _graphgetmem(unsigned size); , s' [& s& P( X2 ^/ m& X, S
程序例: </P>
* w1 u6 b* r( G' F5 c9 k<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 ~3 z( P3 ~" x! t7 M#include <STDLIB.H>
@$ L/ S1 g% B: E A#include <STDIO.H>; F7 g9 M" ^- F! I0 v
#include <CONIO.H>8 M6 L9 c. F b2 V; L5 g' C0 f
#include <ALLOC.H></FONT></P>
& `% Y) _5 B& b+ L* O<P><FONT color=#0000ff>int main(void) 9 k; y6 L1 _3 C' v! r
{
' I4 G- E. J% L1 G8 }0 B2 ]/* request autodetection */
# w6 m- l( X( f5 T' Kint gdriver = DETECT, gmode, errorcode; 2 v+ R; C+ v# q
int midx, midy; </FONT></P>
# [. i: V+ {, ^& a; {<P><FONT color=#0000ff>/* clear the text screen */
0 A8 q% {0 L' k5 B* Vclrscr();
+ q8 t) N) |6 `0 C3 A% n8 eprintf("Press any key to initialize graphics mode:");
2 C4 m4 F1 I' e9 ngetch(); . U' c1 o! U3 s8 t6 \3 O1 G
clrscr(); </FONT></P>
" J+ K" M- \, ?6 d, k7 d8 i& G7 P<P><FONT color=#0000ff>/* initialize graphics and local variables */ % C N2 k6 ]- N( Z; G! U) O
initgraph(&gdriver, &gmode, ""); </FONT></P>
! M1 g D; S- @7 t0 v7 q<P><FONT color=#0000ff>/* read result of initialization */ 3 _+ @5 F2 Z: U: |1 Q# J8 L+ ~# C
errorcode = graphresult(); & g# B& Y( }; N! a/ M
if (errorcode != grOk) /* an error occurred */ % A* a5 ]2 r* M& v
{
: w5 o' L6 d, p a4 {0 u: X( ?printf("Graphics error: %s\n", grapherrormsg(errorcode));
& K3 [' C8 _' j8 n+ l/ Yprintf("Press any key to halt:"); / i- d M0 y; A: o) W* H6 _' E
getch(); 5 Z( z2 a: r$ z/ x2 D, U1 ~
exit(1); /* terminate with an error code */ 8 B7 J5 ?. n7 O5 w
} </FONT></P>
2 l6 b% P, Z, W6 ~& |<P><FONT color=#0000ff>midx = getmaxx() / 2; + W( X. h& a5 X2 O1 @: u
midy = getmaxy() / 2; </FONT></P>7 }; }7 c$ b/ M6 J* o0 P0 R
<P><FONT color=#0000ff>/* display a message */
9 {# ^3 x+ H2 l9 U7 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); + F. `, x1 e6 k6 q' Y/ \0 G
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
|& B Q8 H1 S6 R3 y3 k' @3 ]8 x- n<P><FONT color=#0000ff>/* clean up */ ( A* Z1 E R, @$ P0 t& o# o- n, \. o
getch(); $ u/ a7 S; ]" U2 `5 O
closegraph(); / P* H1 l" q T) f2 q
return 0;
3 c: K2 F$ X6 U' m" P3 @} </FONT></P>
7 u, s2 J- F3 _" }2 E<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
& j0 D3 e8 v+ jvoid far * far _graphgetmem(unsigned size)
( z+ n* A0 z g. k{ 9 }# J$ c2 }3 [" @
printf("_graphgetmem called to allocate %d bytes.\n", size);
$ k7 h4 j8 W) Bprintf("hit any key:"); ) D. S% N }( E! B9 h& c( S: t
getch(); . d8 {6 J5 s; I/ D `3 \0 p& E7 e
printf("\n"); </FONT></P>$ p" z. }5 L, _/ n
<P><FONT color=#0000ff>/* allocate memory from far heap */ / i, }4 N- _2 K) L5 e/ Y7 Z- P
return farmalloc(size);
6 D6 K0 I/ z/ j+ l/ [! h$ H} </FONT></P>
% h$ @4 P# @/ }- f( A<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
5 W# ~, V+ O. ovoid far _graphfreemem(void far *ptr, unsigned size) 4 s/ N* n! a* x5 Q% Z
{
# T o t9 q4 a8 g% f* p# J! hprintf("_graphfreemem called to free %d bytes.\n", size); ( ]$ F' B' B+ V% J8 p
printf("hit any key:");
6 e' b# ^0 b* a# g( V; l" V/ _( _getch(); 8 K3 ?+ |; Q- ?8 \
printf("\n"); </FONT></P>4 Y+ r5 V; m- E- h2 e& ?% P4 z$ F
<P><FONT color=#0000ff>/* free ptr from far heap */ 9 e; G, p: N4 A' {9 v) Z
farfree(ptr);
6 D* k t$ P! d% i}1 C: n% k8 R, \4 _- O4 S
</FONT></P> |
zan
|