- 在线时间
- 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>
- ~" L! z) `) ^. X; ~! \3 p$ J2 q" v" b' w$ D3 d1 c* |/ }) e: n
+ F( [( K, Z- k
<p>
7 v; F+ S D- \) p6 D0 m5 V< ><FONT color=#ff0000>函数名: gcvt </FONT>
+ `( x: p5 p9 R: Z& w6 V$ Y功 能: 把浮点数转换成字符串 4 f1 l/ R4 {9 P! E! @
用 法: char *gcvt(double value, int ndigit, char *buf);
9 P, b8 A6 B5 @9 V6 C- B& `4 L% X程序例: </P>
7 S }8 Y. }/ R* k$ M, ^* v% M8 s; o% ^< ><FONT color=#0000ff>#include <STDLIB.H>
( ^3 E$ g' ]3 r' _6 W7 a' z2 r#include <STDIO.H></FONT></P>
3 p: a; J: ]* l! x< ><FONT color=#0000ff>int main(void) " k& F: g4 T) { C ]
{
* Y5 O3 U5 J. `1 V9 z5 Ychar str[25]; " O& f& U5 ], |& {4 z
double num; 9 H$ d9 f0 ~" p8 j. b# p( o! |
int sig = 5; /* significant digits */ </FONT></P>
) k) U& G: X3 L# J! p+ Q( Z- c8 A) A< ><FONT color=#0000ff>/* a regular number */
! E/ z1 r% l) bnum = 9.876; $ o* U; F, @# J, w Z+ S( A1 M
gcvt(num, sig, str);
, n1 s6 K: V' W- i& c1 E7 [) Uprintf("string = %s\n", str); </FONT></P>
; c2 t. p/ r g! g. O, R< ><FONT color=#0000ff>/* a negative number */
& v5 U, c2 w' C/ Tnum = -123.4567;
6 B, C0 b7 s% d! Ugcvt(num, sig, str);
: m) A$ `! u0 a4 c6 wprintf("string = %s\n", str); </FONT></P>+ P# z; ~1 Z4 R7 R6 _4 b& t& \
< ><FONT color=#0000ff>/* scientific notation */ 8 ], Q# l ?5 {; u& b
num = 0.678e5; * l4 L+ `5 H6 `" t9 P6 A. _% t
gcvt(num, sig, str); 2 ?: {1 `; I* k; t& \) S8 I
printf("string = %s\n", str); </FONT></P>8 I1 U2 ]# |# B" H% D; l
< ><FONT color=#0000ff>return(0);
; E- U% l5 \2 @4 @4 {" Z} 4 o# C$ J o7 @( ^1 E3 {5 V
0 H8 t2 `& p( L" f
</FONT>
; j6 F3 N8 t) ~$ P</P>
9 o- h, }! F+ A' n4 ?4 @< ><FONT color=#ff0000>函数名: geninterrupt </FONT>
6 y" D: l+ T4 Z' M8 D% S功 能: 产生一个软中断 # Z$ _, s I) s( g
用 法: void geninterrupt(int intr_num);
! V2 D- ^; H0 Q5 j4 ~5 K, T6 ^程序例: </P>
+ S2 O* ?: q/ I' w+ k, b< ><FONT color=#0000ff>#include <CONIO.H>; d* F" U& F5 N6 q
#include <DOS.H></FONT></P>
% O# ?) G8 ~+ N) p8 r4 U< ><FONT color=#0000ff>/* function prototype */ - c8 K( L; W9 M
void writechar(char ch); </FONT></P>) h7 N, j1 N8 U2 @ I; |
< ><FONT color=#0000ff>int main(void)
0 B1 K3 G+ i; M, d{ & l; k2 {6 f; `- u8 D
clrscr(); 8 z) _6 c, B- q: M5 U
gotoxy(80,25);
) q; x! \" w( t. F1 X5 ]+ \. }writechar('*');
c, P, o6 ?6 u' V5 W* l% A7 Hgetch(); 3 K- a9 v* d p$ V) O
return 0; * Z4 C( ` A2 W7 Z X! G! ]" P
} </FONT></P>; b0 C5 K8 b' ~$ _9 L
< ><FONT color=#0000ff>/*
. F9 Q. k4 b |: o9 b, S: Y, \4 ^outputs a character at the current cursor
7 N) H: m/ y+ @; i7 y% T% O" T; g4 Oposition using the video BIOS to avoid the
/ x+ t, L7 ~' ]9 O. Zscrolling of the screen when writing to
" [6 S3 J& `6 j) H- R* X; O$ j: nlocation (80,25).
8 j' X1 h/ |! ]& ~% v8 ~& \4 l ?*/ </FONT></P>
; H. s& F6 r# f7 ?< ><FONT color=#0000ff>void writechar(char ch) ! h7 Q1 v/ `, t$ ~# m$ D
{
& S9 c% }/ h R* N' sstruct text_info ti;
: A. |, S- N( m/ R) a/* grab current text settings */ , R! {4 c5 I5 w8 }; ]' L
gettextinfo(&ti); 1 l) ~4 x7 g @/ E% O d1 D- T2 e' a
/* interrupt 0x10 sub-function 9 */ 1 d+ y3 r7 v5 r) V7 ]
_AH = 9; ! ^5 t! i7 Q' X# c
/* character to be output */
: C& r/ x/ P) u" o4 x4 {_AL = ch;
9 l6 g9 Z* ~7 l r, __BH = 0; /* video page */
5 [( D9 ]5 [8 U: Z1 h$ ~_BL = ti.attribute; /* video attribute */ : ^4 K: `0 N8 d0 K3 c0 E* x
_CX = 1; /* repetition factor */
+ V* n- j$ v. _) p5 E1 {7 v3 |( ngeninterrupt(0x10); /* output the char */
9 K& y! N+ H% w/ v; f+ w$ C) H}
+ D% D+ a* }8 t! f: {/ b, D- W, R</FONT>. ~. R4 k% }, D' i& D
</P>
7 e1 l& i2 ~# z, T# c< ><FONT color=#ff0000>函数名: getarccoords </FONT>% r, _! |5 a2 l1 B! z
功 能: 取得最后一次调用arc的坐标
8 q$ a4 h% ^0 Y- Y+ e" E用 法: void far getarccoords(struct arccoordstype far *arccoords); + G# |! }8 k7 i/ [/ G% O
程序例: </P>
# o( P* c5 Q: n' R3 t' v< ><FONT color=#0000ff>#include <GRAPHICS.H>0 e. p0 d) h" a* D
#include <STDLIB.H>
/ ?3 Y) @9 L/ i. L/ A* W( f#include <STDIO.H>
6 g6 [3 J" a* R0 [ P) P#include <CONIO.H></FONT></P>4 U4 n8 u+ a) J, t
< ><FONT color=#0000ff>int main(void) ; x1 @ y" d: t$ B l
{
" Y6 ^# d$ h; U% I: U- K: v- i4 U: P/* request auto detection */
' N8 }6 X2 X' ~ N$ {# A$ }6 lint gdriver = DETECT, gmode, errorcode; . c; l* v) N7 J2 o- H" q
struct arccoordstype arcinfo;
3 H# s$ y. c, A! r |! yint midx, midy; + D% W& I% t- H& ]0 W5 s
int stangle = 45, endangle = 270; . D+ c7 x$ ]; V/ x: Y( V$ W- y- ?
char sstr[80], estr[80]; </FONT></P>: v3 ]$ k1 r8 y
< ><FONT color=#0000ff>/* initialize graphics and local variables */
]4 P( Q7 w7 ]4 T4 X" ~# Oinitgraph(&gdriver, &gmode, ""); </FONT></P>: H3 R8 [/ Q2 k/ g
< ><FONT color=#0000ff>/* read result of initialization */ + k/ K! \! K1 W9 ]6 ~; p5 V
errorcode = graphresult(); ) V* X) Q0 X; a \; `- k4 Q% B
/* an error occurred */
2 U+ a2 |& Z4 |0 X/ I/ Yif (errorcode != grOk)
8 {" O+ A2 M, H$ v{
y3 i9 g9 G0 \3 F3 c( ]printf("Graphics error: %s\n",
. V6 J$ c+ g% L$ K; [grapherrormsg(errorcode)); 7 n. y. D$ Z2 C7 D
printf(" ress any key to halt:"); / n: h: q4 D1 E1 `% @" v) N
getch(); 7 O( Q s+ t+ e U3 a6 ^: Y
/* terminate with an error code */ ) d$ M0 q; N! |
exit(1); 0 ?- `9 y. z9 }1 l& Y
} </FONT></P>
V+ S6 ^- j, A- o< ><FONT color=#0000ff>midx = getmaxx() / 2; : a5 G* i- n8 u9 u1 R8 K8 O+ T
midy = getmaxy() / 2; </FONT></P>) s: C. J8 f) W4 T; W6 K
< ><FONT color=#0000ff>/* draw arc and get coordinates */ + J1 ~5 K$ J. `9 X
setcolor(getmaxcolor());
# p% g% X; M$ f4 qarc(midx, midy, stangle, endangle, 100); / C+ _& R Z3 M# [2 R
getarccoords(&arcinfo); </FONT></P>
# L7 y8 M. i7 x" W8 t/ f5 v< ><FONT color=#0000ff>/* convert arc information into strings */ . {/ d' N: ]0 v" |7 w
sprintf(sstr, "*- (%d, %d)",
/ _( D4 L( d7 |8 T7 @arcinfo.xstart, arcinfo.ystart);
8 p. f1 V$ g% H. R0 V, gsprintf(estr, "*- (%d, %d)",
. e% G* J% l+ ]. L4 L' f) warcinfo.xend, arcinfo.yend); </FONT></P>8 C8 I+ n! g2 T5 }' K! E
< ><FONT color=#0000ff>/* output the arc information */ 6 g$ l3 V1 x: b# h
outtextxy(arcinfo.xstart, 3 y- h& J9 {9 R, B! g2 `; P7 M3 I
arcinfo.ystart, sstr); " U2 G! \" l1 ]. s+ z& _* M6 {
outtextxy(arcinfo.xend,
* x. G/ R% T1 L) P: r( Earcinfo.yend, estr); </FONT></P>
! [( ?# N) n' ]& b0 a* x< ><FONT color=#0000ff>/* clean up */
. C b1 h+ t8 I! T6 _3 k: tgetch(); ( J4 N% @/ i9 p8 r& I0 ?% }
closegraph(); 0 |" A+ O# e, l# D0 Z& A
return 0;
1 ?6 K6 x2 P: ]5 G' I3 g} * f& W. Y4 K, o- R% t/ t
</FONT>1 a5 K+ l2 x# U P5 v8 m# R; X
4 r. T7 N7 D) w' ~" _' ?/ K
</P>
7 U7 O! L9 }; C3 M< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
# c4 P9 {1 {# _9 w' n+ I功 能: 返回当前图形模式的纵横比 , C/ [; Y- U2 J4 B" [
用 法: void far getaspectratio(int far *xasp, int far *yasp);
$ ^# R. F' R+ m0 q% t* X! p程序例: </P>
' N% u) w |* @; N% y< ><FONT color=#0000ff>#include <GRAPHICS.H>
# h L8 e1 w) g#include <STDLIB.H>" n, t$ A% J. O4 q6 D6 W
#include <STDIO.H>1 o( f7 U3 n0 L- N
#include <CONIO.H></FONT></P>7 L2 U; k6 @5 A, a$ v# ?' C
< ><FONT color=#0000ff>int main(void)
0 ?7 k( d* L4 {& ?{ ! m& b2 f; Q! r8 q: n( Y( t
/* request auto detection */
4 d/ I% G o$ Jint gdriver = DETECT, gmode, errorcode; 5 I) M3 \6 W3 @
int xasp, yasp, midx, midy; </FONT></P>
: c% C$ s& Y) t$ }, ?% y< ><FONT color=#0000ff>/* initialize graphics and local variables */ ! z' b: z8 N* o- D5 F! S
initgraph(&gdriver, &gmode, ""); </FONT></P>) ^* b$ y9 H1 u7 ~/ X; z
< ><FONT color=#0000ff>/* read result of initialization */
! w p0 ^% v1 P' V/ N' }errorcode = graphresult();
! W ^/ n2 C0 L. }7 J# [/* an error occurred */
% h ?4 J8 @! t4 o- vif (errorcode != grOk) ' @9 o5 q" h% k' Y) n
{ 3 o: A, `+ S( }$ k
printf("Graphics error: %s\n",
. I! a3 S3 b( [+ e# \6 i" I6 jgrapherrormsg(errorcode)); . b7 H; z {9 P2 S7 z
printf("Press any key to halt:"); ; O/ h! W0 l8 u& [
getch(); $ c9 h% P4 P9 i! O" b
/* terminate with an error code */
# H5 s8 e# \& P: A; {# ?0 f: oexit(1);
9 s% e! R0 `% z1 J2 J} </FONT></P>0 P6 M: s$ u6 i$ l* l
<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ t* W) a# p" w- E1 P" imidy = getmaxy() / 2;
+ j. x" d" g4 g/ q$ Fsetcolor(getmaxcolor()); </FONT></P>6 z. o) B% b# f; F
<P><FONT color=#0000ff>/* get current aspect ratio settings */
( [: T" O/ K$ J% f: R$ xgetaspectratio(&xasp, &yasp); </FONT></P> K$ M2 u; j6 R5 ]* Q- A1 f4 ?
<P><FONT color=#0000ff>/* draw normal circle */
& O" q, ]5 V; q" e$ J0 ncircle(midx, midy, 100);
% a2 I" i$ L& o6 g. mgetch(); </FONT></P>- @1 s w# q. y. B. F% u' t( i; J
<P><FONT color=#0000ff>/* draw wide circle */ 3 H" d* t, y& n/ _6 ~# ~
cleardevice(); $ @3 p% m/ ^. }9 v
setaspectratio(xasp/2, yasp); % H/ \- }/ b4 `8 j6 Z' N( K0 g
circle(midx, midy, 100); 3 y( o1 C( U. C) s
getch(); </FONT></P>
0 E$ S) P" G; F<P><FONT color=#0000ff>/* draw narrow circle */ ) y3 b! n; r. @ ]* r( u
cleardevice();
6 O$ R* t6 p) p$ U; z6 i- hsetaspectratio(xasp, yasp/2); ; X( j- D* n0 B! ` q: |$ X
circle(midx, midy, 100); </FONT></P>
( M7 H$ k. A% \6 {/ J' [<P><FONT color=#0000ff>/* clean up */ # f. Z2 f- p& O: a2 w8 |& h' n
getch(); * _) M& v$ [/ A. s
closegraph(); 5 Z) P2 H b& B) q
return 0;
3 S+ Z1 s! f4 w: V- Q: m} 3 C2 h* Y& D+ t/ y1 o1 ]
</FONT>
9 a; |/ K/ G/ n
# M* N0 v( F" f</P>
2 {0 E4 D7 ^9 ]! [<P><FONT color=#ff0000>函数名: getbkcolor </FONT># G3 a7 S. |; s* t
功 能: 返回当前背景颜色 9 a8 E- d1 P, K! r9 B( Q
用 法: int far getbkcolor(void); ; i! u X' R; c1 Q: m/ D
程序例: </P>
. C, A4 F" ?. v- Y" T; K<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 x8 J1 k% L9 Y#include <STDLIB.H>, k) `' S$ R0 v& U
#include <STRING.H>
7 {+ u: I4 P1 e6 \#include <STDIO.H>
* b& l# @% ^" J1 P5 ~. r) M#include <CONIO.H></FONT></P>- L3 r8 t' y, w) Q/ _
<P><FONT color=#0000ff>int main(void) : q& Q+ A. V' m1 c0 Z4 _
{
$ H. h5 {/ r& u# u/* request auto detection */
/ L+ T, J# Q; b& ]4 E3 U3 Bint gdriver = DETECT, gmode, errorcode; 4 K- r' O3 r5 |1 L$ {( }3 z( D
int bkcolor, midx, midy;
3 ]1 z0 q! M: L, _char bkname[35]; </FONT></P>
% I) ]; b$ c" D" U8 |$ }/ X<P><FONT color=#0000ff>/* initialize graphics and local variables */
; ]3 h3 f5 Y r; binitgraph(&gdriver, &gmode, ""); </FONT></P>
$ K: R. n. I. N9 G% K) W% K3 M8 `<P><FONT color=#0000ff>/* read result of initialization */ / J+ L: Q3 X4 z1 x8 m, R
errorcode = graphresult();
* l. ^" b5 Y" e& W/* an error occurred */ 7 w: p" g: p7 q0 s' u! f: V1 C
if (errorcode != grOk) & B3 m3 v0 _/ t' K3 i0 F
{
1 W2 G$ J7 X, P; aprintf("Graphics error: %s\n", ; a, g, z9 E2 c
grapherrormsg(errorcode)); ; w' ~0 c. w0 r: X9 o! y
printf("Press any key to halt:");
3 P$ a) t1 [' lgetch(); ' C6 `6 y. g0 n8 R. z- ?( O1 e) H
/* terminate with an error code */
o3 [7 q; @ \- I0 D" n- j+ p& n: oexit(1);
$ a) g" f# K c) ]' @- y} </FONT></P>$ l+ c# c" J: H
<P><FONT color=#0000ff>midx = getmaxx() / 2; 2 D% ^6 k6 W4 s* x
midy = getmaxy() / 2; 1 a ]% d; {( }# F* D
setcolor(getmaxcolor()); </FONT></P>9 c2 E. p/ Q" u* t" }5 }
<P><FONT color=#0000ff>/* for centering text on the display */ + r- m& I% E4 ^# v7 \2 K, T
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>% S! ?3 l' C" T7 G' R4 ]" o D
<P><FONT color=#0000ff>/* get the current background color */ + w) d% Z8 O) N
bkcolor = getbkcolor(); </FONT></P>: F; |5 h7 Y/ @$ J" f
<P><FONT color=#0000ff>/* convert color value into a string */
8 f. I6 }5 S+ A9 b% k7 Litoa(bkcolor, bkname, 10);
% H2 O9 R: m1 S! N! Xstrcat(bkname, 7 ~$ P& Z2 h2 |. }
" is the current background color."); </FONT></P>
) N" K) K9 q W<P><FONT color=#0000ff>/* display a message */
, d7 \ T9 o- }% u! z7 Couttextxy(midx, midy, bkname); </FONT></P>, W3 @ O) e. |! P4 ~
<P><FONT color=#0000ff>/* clean up */
2 D4 n% u+ e1 igetch(); 6 b; g! N( n+ s
closegraph(); ! `1 K& q: j) H
return 0;
+ z Y, _! k# ]} 7 H" E# D2 J+ b3 k! [: H6 P
! H1 s; m4 g9 E) j, i8 G2 A, n# u</FONT>
+ y( Z4 h& V$ h8 {* M8 p</P>
$ [ C: ]: H8 I. ]<P><FONT color=#ff0000>函数名: getc </FONT>7 q; E& m: F8 O: `& \# A B" F
功 能: 从流中取字符 ; v$ a6 ?) T% l; D
用 法: int getc(FILE *stream);
& b' e/ O; O" N程序例: </P>
& ?! e, O( Z: n3 K/ g* U<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>4 u1 f q/ \4 v& W. I1 j- {
<P><FONT color=#0000ff>int main(void) ; g' _- v i! g, F& R9 ~0 W$ F
{ v1 O. T( Z8 z K a* Z
char ch; </FONT></P>- `- w' w& @# x( Y& K" |$ F2 w4 N. R
<P><FONT color=#0000ff>printf("Input a character:"); - V+ f7 ?. c, e- `
/* read a character from the
1 p2 o5 m$ [/ R0 Fstandard input stream */ - J- A g$ a' U& D
ch = getc(stdin); 9 s3 m f4 G( V3 o* b. S0 }
printf("The character input was: '%c'\n", 5 U. E7 M {& ]$ p7 I
ch); & A( t6 Q9 r# O0 I( S3 H, T" u
return 0; 9 l8 u( T" o9 c/ K
}
9 D% ^' W ]; i' f% H) s
4 B( H* q+ f* {3 f' Q& t- _</FONT>, A; R: D: `3 N2 F# b2 W
</P>7 ^! Q; w# ~* G; _' p, Z/ i1 h
<P><FONT color=#ff0000>函数名: getcbrk </FONT>, D9 M1 s- ?; w
功 能: 获取Control_break设置
( J" @: H, @3 }+ E用 法: int getcbrk(void); & I% i" F, h5 K1 i
程序例: </P>
* d3 m4 j4 L1 Y5 E! A<P><FONT color=#0000ff>#include <STDIO.H>1 d. w+ [% m' g6 N2 K9 b2 U. o
#include <DOS.H></FONT></P>( L6 ]4 L, K* c! y! z
<P><FONT color=#0000ff>int main(void) 0 J# l# j4 b* U# g2 z- x
{
/ `/ y) } ]2 W/ d" lif (getcbrk()) " y/ Y- @/ [9 j1 u0 T) l
printf("Cntrl-brk flag is on\n"); / ?7 p1 ^0 e `
else 2 l# [: {/ g( |+ F* H
printf("Cntrl-brk flag is off\n"); </FONT></P>( D) H' M; z3 x) n( U* E
<P><FONT color=#0000ff>return 0;
- c; ]# c3 M/ B j} </FONT>
! p! f6 `0 d& }9 T7 U* B7 Q$ a1 T- ~9 [
</P>
1 r+ ^- X& J3 _) } U* M2 D<P><FONT color=#ff0000>函数名: getch </FONT>
4 }+ E# m. c3 C4 G$ M功 能: 从控制台无回显地取一个字符 6 ?6 U$ N4 `# Z5 C L5 Z: c
用 法: int getch(void); 8 B5 U. p/ p1 K X( K* @2 d# q
程序例: </P>
+ W' C2 J5 J2 p7 R' \- \4 e<P><FONT color=#0000ff>#include <STDIO.H>" \8 r, ]* W: _$ v" R
#include <CONIO.H></FONT></P>
( {+ W6 q, }/ Z0 q. U, g) F3 _& U! ]6 d<P><FONT color=#0000ff>int main(void) ( y) S* B. ~. t) {8 y
{
# f y- y4 D( e, u) ]# fchar ch; </FONT></P>" {4 o% b, S" i' l% q; w' |, s: w
<P><FONT color=#0000ff>printf("Input a character:"); 2 x0 d. {% n8 C$ w
ch = getche();
* M, H/ i1 N/ `/ Q3 pprintf("\nYou input a '%c'\n", ch); . E+ _0 y1 y9 C; a7 ~6 |0 ?# [
return 0;
6 s* m7 k k1 x8 q7 |1 i2 D}
/ n7 R0 z2 F; {: b: J( A: n; z; [, n" U. ^$ Q+ ~9 c
</FONT></P>$ N6 E: Z6 X7 Y* r1 v
<P><FONT color=#ff0000>函数名: getchar </FONT>
2 n# j/ R: [+ ]功 能: 从stdin流中读字符
2 Y7 h! J4 m% y* h8 O用 法: int getchar(void);
" v" U. |, w: y/ v" T程序例: </P>" g, Q) p2 ~4 M. Q2 P& K- K5 l
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
I) ^9 P1 w/ l7 [<P><FONT color=#0000ff>int main(void)
) d& T8 V$ W, z7 C" P n8 M8 U5 Z% q{
$ e2 _$ L `2 ~# a8 ^- h* Nint c; </FONT></P>
7 O5 S' a3 L! }5 \5 n0 U3 l0 @: Z& i<P><FONT color=#0000ff>/* Note that getchar reads from stdin and / p* s/ @8 X; T- S
is line buffered; this means it will
0 G. x* R% i7 a7 f- Znot return until you press ENTER. */ </FONT></P>7 x4 g! m ^/ J
<P><FONT color=#0000ff>while ((c = getchar()) != '\n') 9 a7 v2 W/ o7 }/ d
printf("%c", c); </FONT></P>% ?8 {$ w3 J$ w
<P><FONT color=#0000ff>return 0;
: V9 p& |3 B: J( Q& D& {3 n}
0 q" ?' o' j0 d, y2 n; A2 O6 i* M</FONT>! _" _) `0 O% _! f. a9 v
</P>
( C, m" X9 r8 d. ?! k<P><FONT color=#ff0000>函数名: getche </FONT>
9 X) \% v! Q1 l: s; [. u9 u9 M `功 能: 从控制台取字符(带回显) + A7 Q9 H+ ?5 c; V' U; S$ C
用 法: int getche(void); & G' M: e4 r6 L
程序例: </P>0 F- \. |: N! G/ n. H! |0 {3 T
<P><FONT color=#0000ff>#include <STDIO.H>1 ~4 g$ n3 }! Y+ Y. h
#include <CONIO.H></FONT></P>" e o0 B% A4 F0 ]: C
<P><FONT color=#0000ff>int main(void) 1 i( R( q% P& h. h6 U5 H
{
7 _9 ? V5 p h+ D7 tchar ch; </FONT></P>
- C B2 P1 d9 y- b4 @+ `) A<P><FONT color=#0000ff>printf("Input a character:"); + g7 U2 K4 }7 t
ch = getche(); + j: b+ f/ S( T2 @1 |2 D
printf("\nYou input a '%c'\n", ch);
. p1 [4 w/ h9 s. M! yreturn 0; $ n/ H. J1 W( \; w" P, S2 t, M: \
}</FONT> ' ~% @3 F V Q4 s# h @: R2 e
. f; @; e% F Q3 B</P>
2 D, e- t4 P. Z, o* g3 x<P><FONT color=#ff0000>函数名: getcolor </FONT>
& F: S( t& L/ p功 能: 返回当前画线颜色 3 W. G# D# ]6 R" S
用 法: int far getcolor(void);
8 r0 n% v7 E9 Q+ y @程序例: </P>
8 B2 ~! H) U' [. T2 G" l. {; Y \<P><FONT color=#0000ff>#include <GRAPHICS.H># M- B% Z; k$ L4 @
#include <STDLIB.H>3 H) F! U |5 ?, @0 c! o
#include <STRING.H>' Y' A; t) e/ V5 L! T0 j. q
#include <STDIO.H>* M) L' p3 C. X* _2 F( S. L
#include <CONIO.H></FONT></P>
( e- w+ f; g& d2 H) I* O<P><FONT color=#0000ff>int main(void) 4 h6 f* y. U* H$ t
{
6 `" ^- i- e8 d. T! U9 N/* request auto detection */ 9 U5 L5 t. F7 D
int gdriver = DETECT, gmode, errorcode;
( D& [7 Q Q) f# W) Lint color, midx, midy; 9 b) Z" ]5 {1 G# P1 L P1 Y
char colname[35]; </FONT></P>
8 K" n, A- J; p<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ u" T! v5 Z& c) H' binitgraph(&gdriver, &gmode, ""); </FONT></P>
8 y! a/ B/ a6 ]2 I) ]; N7 h<P><FONT color=#0000ff>/* read result of initialization */
. {% U; u1 V, Q5 L+ M& Z0 Yerrorcode = graphresult();
* g Y4 I- ]$ Q" X) S c/* an error occurred */
) a5 m. x1 d, X$ }, Fif (errorcode != grOk) 3 e# y& c2 M x" ?: G
{ ; u2 ^ @/ w- o: H
printf("Graphics error: %s\n",
+ g1 ]- _3 J/ {# F" F! wgrapherrormsg(errorcode));
4 L8 L6 c, x. Zprintf("Press any key to halt:"); 0 G% A! p; Q. I& X$ w/ U+ ~) p
getch();
% I8 ]4 i, R \. b/* terminate with an error code */ ) {4 F! l/ S5 L6 _/ r4 G
exit(1); 2 a% M. o) ]6 h" D9 S% g6 q
} </FONT></P>
& F* ^ K9 X) c4 R' C- P<P><FONT color=#0000ff>midx = getmaxx() / 2; ' S8 y' e: g% {; ?$ Z3 N) s
midy = getmaxy() / 2; / e/ g# D6 J0 `
setcolor(getmaxcolor()); </FONT></P>/ t* F( d6 l. d" ]! M* ~# Q6 i
<P><FONT color=#0000ff>/* for centering text on the display */ 6 D. s: R( U. w( I) J/ _
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>8 J B% J4 D1 A
<P><FONT color=#0000ff>/* get the current drawing color */
# z9 D1 ~% L! }' t5 w" O4 Dcolor = getcolor(); </FONT></P>
P) Y; ?2 f& r: T) E; E# t<P><FONT color=#0000ff>/* convert color value into a string */
* H% a' ]0 N2 Witoa(color, colname, 10);
# L6 j# U. W5 H/ `8 @strcat(colname, 7 Y! t6 {8 b& e9 B, g
" is the current drawing color."); </FONT></P>2 z2 X( h" Q2 g9 N
<P><FONT color=#0000ff>/* display a message */ , D- p/ N+ K' ]) v+ @
outtextxy(midx, midy, colname); </FONT></P>) d% Y4 |7 s- F
<P><FONT color=#0000ff>/* clean up */ 5 c) `5 p* I+ j8 A' G
getch(); & u3 Q* _: s6 U+ L( O% g8 _& W
closegraph();
# _( Z. q' `8 P% l% W4 R6 Jreturn 0; ( O. O3 W) q( `4 t- k' Z g. U5 f
} " N9 m+ e! t' ]8 f
</FONT>1 d3 z2 D& p, N) d0 f b
</P>
8 c; _1 Z* s) V<P><FONT color=#ff0000>函数名: getcurdir </FONT>3 h! @( A7 U6 G% ]3 e) Y
功 能: 取指定驱动器的当前目录
0 G. a( A% E8 K( `9 O0 p+ Z用 法: int getcurdir(int drive, char *direc);
4 l5 l0 R' e" K9 R- o程序例: </P>4 k: r8 J4 |5 {2 S! o P/ A
<P><FONT color=#0000ff>#include <DIR.H>6 ?) M+ g- M6 ^( w
#include <STDIO.H>4 p. S9 H# a) z+ r1 X9 S
#include <STRING.H></FONT></P>- I0 | v4 ^6 Z/ @* M7 U. I q
<P><FONT color=#0000ff>char *current_directory(char *path)
! `8 S0 s" S' ?% f, ^1 _1 L{
6 R* Q7 V% z9 J0 G, vstrcpy(path, "X:\\"); /* fill string with form of response: X:\ */ : t/ u0 x( D# Y! r& R+ z7 A
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
& f- W, p6 Q2 _: X! g5 P0 Qgetcurdir(0, path+3); /* fill rest of string with current directory */
, y4 q( j! p+ P' X+ ]return(path); ! o! _( i. Q- M3 f7 X4 M! Q( H' e
} </FONT></P>0 J3 `! `8 J" E% D% T
<P><FONT color=#0000ff>int main(void) 9 M0 h% i& [& E4 Y+ Q" H- v4 V& w$ A2 w1 w
{
3 q1 m8 O6 u( u0 K8 M: H( Wchar curdir[MAXPATH]; </FONT></P>3 M% k& f8 a, B) ^
<P><FONT color=#0000ff>current_directory(curdir); 6 y/ f: c: y1 E1 C( P
printf("The current directory is %s\n", curdir); </FONT></P>
7 L- Y5 X `% G. c' w5 p0 S5 \ A<P><FONT color=#0000ff>return 0; 3 r( G- ~' Y: F8 o7 c
}
! o/ K- _1 W% O" J) ~</FONT>
# w6 v7 j7 H. c* c) h2 D l</P>
- g7 \6 C; M" E; ~5 G<P><FONT color=#ff0000>函数名: getcwd </FONT>. C( F% s' F4 k
功 能: 取当前工作目录 : w9 w' z1 A3 e
用 法: char *getcwd(char *buf, int n);
6 @1 i( [. Z( _( O9 t( {程序例: </P>. U: H9 p% j0 W; P; a
<P><FONT color=#0000ff>#include <STDIO.H>' [( {* Z0 V+ `) {2 V
#include <DIR.H></FONT></P>
! j4 }; v/ Y4 i' d# K<P><FONT color=#0000ff>int main(void) ' W+ W2 G+ @1 s6 Z8 s: A
{ 7 P* c8 q, q( F- ~
char buffer[MAXPATH]; </FONT></P>
5 r1 y: i: A0 C/ d8 d' ]<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); * G/ N% \# [# {$ Z
printf("The current directory is: %s\n", buffer); 7 U5 ]1 X T; l
return 0;
# M3 m: e; S* h) Y5 C/ Y} </FONT>
3 d+ _# [- D, B! _3 A% o9 J+ o8 l$ T: y
</P>
6 m" ]) z% S7 {, E2 v<P><FONT color=#ff0000>函数名: getdate </FONT>
' U, [7 m% P# v; F" B: U" w7 Z功 能: 取DOS日期 % w* S/ l& ~3 K; C+ K y
用 法: void getdate(struct *dateblk); 3 M3 Y' N. u, Y9 B' C. a
程序例: </P>2 T- [3 K3 R ^
<P><FONT color=#0000ff>#include <DOS.H>( k1 P, _* U: v( U9 `/ k6 l
#include <STDIO.H></FONT></P>
0 U8 b' m1 Q" X5 T( d0 u! g<P><FONT color=#0000ff>int main(void) * f) l4 ]* Y* z0 W; V
{
. g/ D9 `: z1 U: r; }; q @struct date d; </FONT></P>
2 {* j) v% p7 {3 d$ H' u<P><FONT color=#0000ff>getdate(&d); ^1 `4 X6 }$ h& I7 u$ u
printf("The current year is: %d\n",
( o* P) q# e* o/ X td.da_year);
V) z* F' o- |' V6 B. iprintf("The current day is: %d\n", ( A& t- D* y# }4 i! ]
d.da_day); ; i. D, D- ~$ E9 J$ R9 x: [- D/ Y' l6 a
printf("The current month is: %d\n",
1 m+ N( @" Z" r7 Dd.da_mon);
) X. E1 W/ J5 A) A! _! ?9 q2 v' Vreturn 0;
0 q4 `/ ^2 G" S1 Q- w; {0 I& s} 7 ^( V5 A! r3 r& g5 B9 t
</FONT>' t5 W2 s8 n& K7 w; C' }
</P>- [4 F8 n1 W5 A5 K
<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>; r3 F0 {" l, J" z2 B* A: ~
功 能: 返回调色板定义结构 ! ^+ z3 L/ p' G" m
用 法: struct palettetype *far getdefaultpalette(void); 1 q" n7 G; G9 @( `
程序例: </P>
( B2 V6 E. C" G6 A4 ^( `<P><FONT color=#0000ff>#include <GRAPHICS.H>5 E( M: _1 k; k, t8 l+ F- J: i! u
#include <STDLIB.H>
, N- s" [6 ?1 o, ~' p! b; B#include <STDIO.H>3 C& K8 G1 O8 z
#include <CONIO.H></FONT></P>
! t9 S3 g; S) k<P><FONT color=#0000ff>int main(void)
( Q. v6 L& M8 i+ ?' e{
: N8 y0 [' i: Z" ^' P0 k/* request auto detection */ 4 k7 `5 P% Y( r* E1 p P
int gdriver = DETECT, gmode, errorcode; % [& [( R' Y& w0 p4 z! m6 T% l+ x3 ?
int i; </FONT></P> u* G& C( P5 z( p$ a0 k7 F
<P><FONT color=#0000ff>/* structure for returning palette copy */
3 F. X- d' o, _/ u0 ostruct palettetype far *pal=(void *) 0; </FONT></P>9 E- S J# \- Y' A7 H+ y/ X
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! ~5 I' u0 z- r" P% a
initgraph(&gdriver, &gmode, ""); </FONT></P>
! U x0 a5 |% N( l7 K<P><FONT color=#0000ff>/* read result of initialization */ # Q$ \/ c7 f4 T# u- J9 \7 A
errorcode = graphresult(); , y6 t5 U7 F+ w% d1 K: z; Y
/* an error occurred */ 1 P' d, t6 R. C3 n9 i
if (errorcode != grOk) ; {6 v- M8 v! f4 X' \
{ ( u) ~- s% l8 y1 b% J
printf("Graphics error: %s\n",
1 U9 P% r! k* z) z7 N6 H7 L `* Ggrapherrormsg(errorcode));
! O! ~- H# g5 y7 bprintf("Press any key to halt:"); p) a" ], X. n" N& {
getch();
$ [' T, l& s% u" n2 h0 U/* terminate with an error code */ % R' Z& E1 w" ]* U C
exit(1); 6 K% |" U: ]- j5 r! W7 V/ F
} </FONT></P>* B% O# d( S3 L/ f$ s6 H6 v4 W; V
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>! L$ z M4 s5 ^5 d0 ?
<P><FONT color=#0000ff>/* return a pointer to the default palette */
/ m9 h6 C, i& O5 @7 `; cpal = getdefaultpalette(); </FONT></P> O C! s( C% R2 s( O, W2 m
<P><FONT color=#0000ff>for (i=0; i<16; i++)
" O, j {! o+ ^4 Q8 M{
5 F. c/ y& S b' Pprintf("colors[%d] = %d\n", i, # _9 H N7 ~! m, t- b$ z
pal->colors);
: N" x7 H/ m( N$ R- p0 r# ugetch();
* d" I2 N% l; Q6 u! G) S7 o8 c, A} </FONT></P>- N( K4 L# k4 P" a) p8 F% {
<P><FONT color=#0000ff>/* clean up */
$ W# W' ]) F" B5 K; wgetch();
& M6 t- ?: X( A9 J* qclosegraph(); 1 L& K, O. H! p9 a0 `9 O
return 0; 5 y$ v5 m7 ]. g" _* X4 x1 g
}
9 d5 F) V" z! m</FONT>; ^& ]& ]1 H; w0 w
</P>
! r; X* r" p: x4 |" g: w4 t<P><FONT color=#ff0000>函数名: getdisk </FONT>& {0 u( ]' S: s8 k# r( c" G. w7 `
功 能: 取当前磁盘驱动器号 & r: S: q% O/ `9 X/ N& X" E7 a
用 法: int getdisk(void);
1 L. H7 w) \7 G8 m5 u; I" I" q程序例: </P>
; U6 F1 P# Q+ W" R<P><FONT color=#0000ff>#include <STDIO.H>
! {* G9 `- S" R& @6 k#include <DIR.H></FONT></P>6 \! P: O9 |7 P! j1 V
<P><FONT color=#0000ff>int main(void)
! r/ p8 ?6 m; ^# u' L* ]3 a{ 7 h2 ~' h; } b+ G
int disk; </FONT></P> L' ~' e7 D" t/ R& y
<P><FONT color=#0000ff>disk = getdisk() + 'A';
( v! g% I9 j0 Q0 M' dprintf("The current drive is: %c\n",
1 K/ {1 j* i7 O i4 `" o+ \5 w$ }disk);
' \5 }% ]3 C! e' V/ Nreturn 0; 1 p8 R0 G- O5 l& D3 o- L5 c
}
$ l* b& ^5 l5 W' ~& [0 O: o
3 ?2 Z, x; H. X8 H</FONT>
9 g' R; t% T) G</P>
8 O3 r! z7 } z/ `<P><FONT color=#ff0000>函数名: getdrivername </FONT>
: ?" u! L- `7 R4 [功 能: 返回指向包含当前图形驱动程序名字的字符串指针 5 J$ \: u+ z, a
用 法: char *getdrivename(void);
[ V; Y) Q- B, M程序例: </P>' j, V$ I: j5 Q$ q" y! M
<P><FONT color=#0000ff>#include <GRAPHICS.H>* a- v" V! s' r+ |
#include <STDLIB.H>) D7 L3 l! m m% u3 H
#include <STDIO.H>
4 D3 ]' s7 K7 S. F, X E+ Z6 J#include <CONIO.H></FONT></P>
8 F! I0 M- C6 f0 H<P><FONT color=#0000ff>int main(void) % r2 _6 l/ ^' D [" V' B7 G
{
9 L2 @6 C( ?& F8 q$ p' l. S" A/* request auto detection */
- V2 X/ w/ i! r* ~int gdriver = DETECT, gmode, errorcode; </FONT></P>0 V' C# T8 {& g5 F Q% r
<P><FONT color=#0000ff>/* stores the device driver name */
! _; n1 ?$ e; B- C& \( {char *drivername; </FONT></P>* X9 ?6 ~3 O6 _$ v
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% g* J/ L t7 Tinitgraph(&gdriver, &gmode, ""); </FONT></P>' W8 T `7 Z, ?- t F% X
<P><FONT color=#0000ff>/* read result of initialization */
$ S( ^4 q& F- c. derrorcode = graphresult();
& ~( I" }. c8 P/ H7 M8 g& h/* an error occurred */
+ d( W/ d' W4 wif (errorcode != grOk) * w- f3 T5 Y C3 l/ D8 e
{
6 J7 n/ ` \ j+ uprintf("Graphics error: %s\n", 3 g6 Z2 z6 D, |" d- Y$ V$ D+ t
grapherrormsg(errorcode));
3 C* B' A2 ? l/ W1 Y4 D+ sprintf("Press any key to halt:");
) p& [7 }+ `6 q& T$ l; hgetch();
2 ]2 }, j/ ^) T8 l, |/* terminate with an error code */
1 [9 O& U) T: B Y- }& Rexit(1);
5 u: y! k$ Q; \' B; l3 s d} </FONT></P>% p F9 I1 X% y* W9 _3 \
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>/ J! m$ W' j/ z1 Q- ~6 q7 f" Z
<P><FONT color=#0000ff>/* get name of the device driver in use */ 2 B I) ]9 C# w H' e& m/ m
drivername = getdrivername(); </FONT></P>* d6 B3 ~5 H# s8 c
<P><FONT color=#0000ff>/* for centering text on the screen */ 8 T) N' q |6 c5 Q1 @: M5 V% i
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>9 l& \1 i% \* V) ?7 z5 r" o
<P><FONT color=#0000ff>/* output the name of the driver */
$ M+ m P) i4 h1 N* Y8 Routtextxy(getmaxx() / 2, getmaxy() / 2, % n$ s2 j1 J9 R% z
drivername); </FONT></P>
1 _ A, c2 x$ D<P><FONT color=#0000ff>/* clean up */ 1 t, a5 t0 P! \5 V" {0 Y5 z- X
getch();
( W7 X0 w! @: r+ C( p2 Z: V0 b, Tclosegraph(); 5 X9 k. s1 d0 u/ h
return 0;
* B4 r- _) Z3 i: Z3 w# ~' N/ h}
# o8 M: h5 b! y/ \' ?* l' O</FONT><FONT color=#990000>
( D, m! a b3 m</FONT></P>
: n$ }! l9 U9 _# }<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>6 z- w' i- e% v
<FONT color=#000000>功 能: 取磁盘传输地址 " \1 Q; z# g3 j' p P
用 法: char far *getdta(void); 3 {/ y. F |9 c; p( q' r+ F
程序例: </FONT></FONT></P>* q L+ u, U" e& m) K
<P><FONT color=#0000ff>#include <DOS.H>
" t# e* s, b+ s( s7 r, ]#include <STDIO.H></FONT></P>8 q7 H5 e( g" c0 G5 W
<P><FONT color=#0000ff>int main(void) / p. H3 t+ G# D. z
{ $ i ]% Z! n' N
char far *dta; </FONT></P>
% s( J1 x& [' @<P><FONT color=#0000ff>dta = getdta(); 3 t" W R0 i9 a e1 N1 {' h% {
printf("The current disk transfer \ 0 i( U. {; V/ \: [7 F- p
address is: %Fp\n", dta);
1 Z7 |( c, @" W" z% Hreturn 0; ' p" C* Y1 T2 E) S( b+ @; P2 L
}
# m$ ^. h0 p# q2 u</FONT><FONT color=#990000>
3 I4 d. r" W s3 U. J4 b</FONT></P>
+ ]# D/ {$ M. \! r" n<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>
* U. |, t- ^% S- M4 ^<FONT color=#000000>功 能: 从环境中取字符串 $ B- l- \2 O. k. |' }
用 法: char *getenv(char *envvar); - V8 [( O2 J- U; I3 Y+ _7 L
程序例: </FONT></FONT></P>
, r+ A. O4 |1 P4 u9 ], d o<P><FONT color=#0000ff>#include <STDLIB.H>
0 z- p; k7 U2 X! S/ t7 Q#include <STDIO.H>- _7 v! k7 @: C+ b! @7 }) l: x3 Q s
</FONT></P>/ E3 x$ c* ~; o, C4 C
<P><FONT color=#0000ff>int main(void)
+ C: R7 {" | N, r{ , V) m* [. R& ~
char *s; </FONT></P>% |6 i$ T# s6 w' J% g a$ x
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
7 w' J' ~8 _. d1 w) Fprintf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>: \$ _' R2 k/ s" Q# d. H. J
<P><FONT color=#0000ff>return 0;
0 `( S5 \ N9 O. [! P- W" O} </FONT><FONT color=#990000>8 Z/ J# D, |$ V) m) K
5 W5 c! k) f" h4 ?, O0 ` u1 V& }/ z' I" m' ^& ]2 q- s1 X
</FONT></P>
0 b8 A# J ^2 c- y9 M1 U# y" j ]<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>
% m4 q9 z x' r* k, X功 能: 取文件分配表信息 7 v: Z$ k# {: l4 j4 i
用 法: void getfat(int drive, struct fatinfo *fatblkp); ) P3 U( g, Y0 H7 {( o: n
程序例: </P>4 W9 \" {1 w' @5 o' H, B8 O+ W4 U
<P><FONT color=#0000ff>#include <STDIO.H>
' U Z1 `" i( m* ]) f) E! P+ H#include <DOS.H></FONT></P>
+ F& u5 h1 V& h<P><FONT color=#0000ff>int main(void)
4 _) \# _, c4 K: z+ X{ . n* u4 D" `. Z, d$ M
struct fatinfo diskinfo;
! o7 ]( G2 @) z! _8 oint flag = 0; </FONT></P>* c: k3 g% C/ |, V2 i+ o
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n");
+ Q+ S j$ y4 s, S+ c7 M) cgetchar(); </FONT></P>
% ^3 n) S; \: M5 T<P><FONT color=#0000ff>getfat(1, &diskinfo);
0 i9 i* U; \- h7 Z/* get drive information */ </FONT></P>
8 H( B( {; ?2 f5 K. O# S& H0 b<P><FONT color=#0000ff>printf("\nDrive A: is ");
1 }( b! x% L+ M# c1 cswitch((unsigned char) diskinfo.fi_fatid)
+ i4 w% B9 T$ H8 V% m2 z% G{
& o- D. d/ t% ^% lcase 0xFD:
" }* A2 R" x& f7 A: k( Dprintf("360K low density\n"); % h3 r+ s [/ J
break; </FONT></P>; U1 V/ Z: q9 ?$ V5 f c3 m
<P><FONT color=#0000ff>case 0xF9:
+ D- i& |; _- P9 g* Pprintf("1.2 Meg high density\n"); 9 ?/ J. w t1 ^% H! b
break; </FONT></P>) u, k4 @$ o5 h0 q/ C c
<P><FONT color=#0000ff>default: 0 w8 v9 y1 k$ V% g2 g1 j
printf("unformatted\n");
; R; p. A# f. R3 V/ w. ^flag = 1; " d& ?1 T* j8 F, H1 O
} </FONT></P>. u8 C6 L2 j) M6 a0 J" R
<P><FONT color=#0000ff>if (!flag)
# Y$ E6 @9 o8 [: [: F0 _{
% ^5 R; y+ g, [/ ~" a( _( T) Bprintf(" sectors per cluster %5d\n", 2 d/ E- n# B3 c& O
diskinfo.fi_sclus);
+ L. D9 C! q7 ^* Kprintf(" number of clusters %5d\n",
s' F9 z5 W, `" f" n, pdiskinfo.fi_nclus); 1 ]# H7 D6 w8 h1 S2 z7 \) `% H
printf(" bytes per sector %5d\n", ( Y- z* T5 `& R
diskinfo.fi_bysec); 2 S: L5 |2 S% u) d' H
} </FONT></P>
4 \4 J8 Z/ H4 v* z6 Y* I<P><FONT color=#0000ff>return 0; 0 R6 e) a$ w) Z& [* C$ A) R7 X
}
& V' j4 _. U& `8 i2 K* x1 ~4 ^</FONT>
0 l* A+ }! t4 l</P>
' d4 t" Y' v: `1 Y<P><FONT color=#ff0000>函数名: getfillpattern </FONT>0 @5 g. s1 o/ {. { ^6 i9 f
功 能: 将用户定义的填充模式拷贝到内存中 0 ]1 S5 G7 r8 C0 e
用 法: void far getfillpattern(char far *upattern);
. r$ |) |( T& e7 G: ^8 }程序例: </P>
% H( d' S5 J. }% Y% f& Y# E6 f<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ }. q& G' b$ s6 l. S3 F, W#include <STDLIB.H>
9 ~6 M; F8 d% A6 C/ z) [) a6 n#include <STDIO.H>
- Y$ r+ G! ~2 R& d U, T#include <CONIO.H></FONT></P>
- ?9 X7 \; C6 I<P><FONT color=#0000ff>int main(void)
7 O) O6 p( P1 l" F# t8 C8 f! _{ 3 m, O H+ c* S0 z6 H+ g# z
/* request auto detection */ 5 r7 @: C) B) z0 E' i
int gdriver = DETECT, gmode, errorcode;
1 L$ g' x; z9 g- zint maxx, maxy; * }3 a* M1 p% ~
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>
7 t) _. X9 H9 x! W<P><FONT color=#0000ff>/* initialize graphics and local variables */ + y; N( v. k, C" c6 J
initgraph(&gdriver, &gmode, ""); </FONT></P>
# e7 u: \, z9 l6 c+ L/ m' |<P><FONT color=#0000ff>/* read result of initialization */ ; ]+ \" s: I! t" f$ ^% g
errorcode = graphresult();
& Z* j* J7 j; j1 c! L$ N* H( i4 n9 H) xif (errorcode != grOk) /* an error occurred */ $ w( `. _* Y: X6 u
{ + ~. E) Y$ a% ~+ i) p
printf("Graphics error: %s\n", grapherrormsg(errorcode)); " h5 j/ D4 O; z/ o
printf("Press any key to halt:"); ( o, E3 X( V# E3 I% p
getch();
& S! X" L# k0 I( j, mexit(1); /* terminate with an error code */ & Y m& S$ Y f# o
} </FONT></P>
1 @0 p5 D# }8 Y" Z! V/ h<P><FONT color=#0000ff>maxx = getmaxx();
7 c3 w- [7 w4 Z4 T; r. S2 Dmaxy = getmaxy();
& O R. r& _7 k( Qsetcolor(getmaxcolor()); </FONT></P>
% G/ v% K d: L<P><FONT color=#0000ff>/* select a user defined fill pattern */ - Y, ]- I! m3 C" Q
setfillpattern(pattern, getmaxcolor()); </FONT></P>0 O$ U- t7 K. ?1 x B$ A
<P><FONT color=#0000ff>/* fill the screen with the pattern */
+ I- ~3 a! D; d7 w; K! zbar(0, 0, maxx, maxy); </FONT></P>
$ z7 B. A% V. F* w" u, i<P><FONT color=#0000ff>getch(); </FONT></P>
& S9 [3 m6 ~- D% @<P><FONT color=#0000ff>/* get the current user defined fill pattern */ 9 n( l& ^' |9 m9 l/ `
getfillpattern(pattern); </FONT></P>8 c+ r6 h' u, H, b6 x
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
: ]3 Q. _0 M& Cpattern[4] -= 1;
2 ~0 }! l2 M: {& Kpattern[5] -= 3;
. P4 E1 ?! y R, W9 opattern[6] += 3; 7 ~0 ]" k! w$ ^# C! }' Y
pattern[7] -= 4; </FONT></P>0 e+ G1 g$ j6 Q
<P><FONT color=#0000ff>/* select our new pattern */ 1 e4 Z/ D/ [: k$ B8 c/ N3 s
setfillpattern(pattern, getmaxcolor()); </FONT></P>
% C% h9 \2 j8 ]1 K" h<P><FONT color=#0000ff>/* fill the screen with the new pattern */ " c% g' M8 w4 o) @: ^
bar(0, 0, maxx, maxy); </FONT></P>
% t. m4 _8 n% P5 T<P><FONT color=#0000ff>/* clean up */
) ~. d* W% j/ ?* kgetch(); 9 N( y' I, k) q& H% K- ^$ r. |
closegraph(); ; N g4 u7 d+ g) a
return 0; 6 ?) x! `- ?5 p( B( @
}
1 g* i- X( p7 E* L1 `- _2 p</FONT>
d/ C P; B3 a7 T+ R S2 r</P>0 j: b& N$ E5 v' \7 i
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
1 f( i8 a% x& b' C' D功 能: 取得有关当前填充模式和填充颜色的信息 8 z+ E8 h% j$ i! Y3 k
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
, M; L" c0 h) K程序例: </P>! o9 [/ B' r7 V9 o, i
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 O' p% X, J. H% e l9 ]
#include <STDLIB.H>3 `+ Q8 S: p+ [( ?
#include <STDIO.H>( {( I9 M8 a5 e' q# r. j" ~$ K
#include <CONIO.H></FONT></P>$ z5 R! ] |6 c5 k
<P><FONT color=#0000ff>/ the names of the fill styles supported */ 0 c0 Z5 I! Z% k- x1 e# {9 K; Z& {
char *fname[] = { "EMPTY_FILL",
$ W( A( E+ R% q4 l# Z' [1 e1 b- H1 E"SOLID_FILL", + O) z A8 r& _. J, S
"LINE_FILL",
% }( p. z$ H! }) C0 E"LTSLASH_FILL",
& I' }/ B% Q( e# I x/ G"SLASH_FILL",
6 s1 O( ]4 c1 A2 x4 c) H"BKSLASH_FILL", 1 U# |9 o0 Z: F) T* R) z
"LTBKSLASH_FILL",
$ X3 f9 a4 j5 e9 s8 K"HATCH_FILL",
1 E$ v0 a6 Z8 J% i- g"XHATCH_FILL", Y" a6 W4 k. M: \5 p, n
"INTERLEAVE_FILL", * M A: P- _+ C
"WIDE_DOT_FILL", 3 k( c6 ^5 s5 E4 o9 }" \
"CLOSE_DOT_FILL", 0 D/ w2 J2 o5 ~
"USER_FILL" 8 I, n# |: A3 |1 d
}; </FONT></P>
: a3 `7 W, ]4 t<P><FONT color=#0000ff>int main(void) . ^1 Y0 a$ P. \
{ 9 j) v7 s( i6 O7 h9 c" H+ U
/* request auto detection */
! b. n. M4 @. \4 L" N' P6 m; c1 Kint gdriver = DETECT, gmode, errorcode;
$ [3 i+ g8 A3 Y! [% y# Jstruct fillsettingstype fillinfo; & y- _6 a0 [; X/ ~/ T, i7 N
int midx, midy;
9 P4 S4 ~; h( w4 ?7 P3 ]: o# k$ \char patstr[40], colstr[40]; </FONT></P>
- H1 w& [0 y* m; r<P><FONT color=#0000ff>/* initialize graphics and local variables */ [1 I8 E+ d3 p P S) M
initgraph(&gdriver, &gmode, ""); </FONT></P>
& j( b9 ?1 U" [/ D3 ~0 w# B, p<P><FONT color=#0000ff>/* read result of initialization */ 4 x* ^% U3 A+ ^4 v1 S+ u
errorcode = graphresult();
* r! b% Y. a6 A# C! L- ^6 s+ \if (errorcode != grOk) /* an error occurred */ , k2 B* l4 B" _/ h/ d
{
; |: U! d. ]: A9 h: l6 Q1 uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
$ B# e$ i* m& {% S' x4 ^, d# m5 u+ Lprintf("Press any key to halt:");
: O% H0 f2 D9 o* Hgetch(); ( P* X3 N. N' ~. d0 J+ t0 L V' U' K
exit(1); /* terminate with an error code */
# z( {. x8 v. k( Z4 q# t} </FONT></P>* q" @9 ?- G. | k
<P><FONT color=#0000ff>midx = getmaxx() / 2; * Q! [" z( \' c3 t
midy = getmaxy() / 2; </FONT></P>
, O( x& o& ~6 T( c3 h<P><FONT color=#0000ff>/* get information about current fill pattern and color */
8 W, g, z/ C/ Y. P, Q+ Bgetfillsettings(&fillinfo); </FONT></P>
2 h5 R* K. S& I2 }" \* q<P><FONT color=#0000ff>/* convert fill information into strings */
, Y/ J$ w$ c7 G. F& Ssprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]); 1 G3 S- a# F' K4 N% Q: v
sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
2 J3 k/ e2 h' o<P><FONT color=#0000ff>/* display the information */
( \/ C C' T1 m8 j6 c9 y: Msettextjustify(CENTER_TEXT, CENTER_TEXT);
' j' u% n4 U: q- R1 e! K2 Y; v& mouttextxy(midx, midy, patstr); }* ?8 n4 y! M6 L# |! r
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
( b; d( V. k6 i; Z5 u<P><FONT color=#0000ff>/* clean up */
9 Q- B, e0 K0 `3 e0 o) Ogetch(); 2 |* L2 p4 E w- {1 p
closegraph(); + K( G' B3 ^. Q% F9 g
return 0;
5 }$ t, [, H9 x}
, g3 E1 w/ `& Z+ {* Y1 z$ L8 k</FONT>
+ n M4 M* F' `% |) W+ J; ?9 n- m
$ @/ m5 ]6 _3 L( h, z. ?- X+ ^/ M</P>' x( D+ ^1 @$ B' w8 X( T
<P><FONT color=#ff0000>函数名: getftime </FONT>- ]& ~" e1 V; w& }
功 能: 取文件日期和时间 , A- O, \/ z% k; w( H' Y
用 法: int getftime(int handle, struct ftime *ftimep);
3 E ?" A) ^. ^程序例: </P>: D3 D& |) T1 A0 j
<P><FONT color=#0000ff>#include <STDIO.H>
0 t! L" M% \7 j" t2 |% v#include <IO.H></FONT></P>& N- |# X$ x' Y6 z; ]7 D2 w: T
<P><FONT color=#0000ff>int main(void)
9 |7 r% a) E4 S# m0 X{
* R J& s+ C( r9 [( ZFILE *stream;
9 I3 T, n$ I3 E# U. qstruct ftime ft; </FONT></P>
7 ~# o3 @' ?/ Q<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
- f- F* n( Q9 u j: c& W"wt")) == NULL) 6 [( ~6 G* g, {
{
+ |' k) S2 ^4 Gfprintf(stderr, 9 O0 a9 \# u. ]3 @7 \* r& ^( t
"Cannot open output file.\n"); ) c$ z5 N: t8 T- {5 m
return 1;
, w/ `+ k9 d0 S, b5 z} ( z7 u9 r5 I+ d0 e2 Q D% A) Z9 J
getftime(fileno(stream), &ft);
" W+ `. k% m U3 M i7 t: o4 ]printf("File time: %u:%u:%u\n", 6 V7 O( w9 ^3 s: s- T
ft.ft_hour, ft.ft_min, & ]+ q7 V3 d) V5 ?
ft.ft_tsec * 2); 1 O% X9 B# u. z% t+ W \
printf("File date: %u/%u/%u\n",
" D7 A. v. R- {/ E/ cft.ft_month, ft.ft_day,
1 y5 j6 D* M, F6 `7 Tft.ft_year+1980); % z; |2 q" S3 r
fclose(stream); 2 q/ k7 b- M) e, r& p
return 0; 9 Z- H3 C* T- O
}
+ _8 Q# z* Y3 F9 h& I</FONT>) V: z: }0 v3 T6 k
2 _/ J" m m9 n6 Y3 W
</P>
2 G- Z; o+ I q5 ~0 ` {2 {<P><FONT color=#ff0000>函数名: getgraphmode </FONT>: H# h ? q5 \; A
功 能: 返回当前图形模式 5 R- Y6 `9 v: p; Z6 a9 x/ |
用 法: int far getgraphmode(void);
3 s& O/ c% A9 Y/ e程序例: </P>
! y* k/ |2 V L. U% n4 D<P><FONT color=#0000ff>#include <GRAPHICS.H>) e( _9 t9 |' O! I0 q ]0 D8 ]+ ^
#include <STDLIB.H>
7 H6 b! _# L0 r' z#include <STDIO.H>0 i4 {) w1 v( b0 d& h
#include <CONIO.H></FONT></P># |) D: F/ ^! J* A+ h: K
<P><FONT color=#0000ff>int main(void)
$ T2 Y: H0 H4 c8 L# [6 _{ * a" I J9 Q* g8 j. s& ^
/* request auto detection */ 6 T! v9 \7 S8 Q& `
int gdriver = DETECT, gmode, errorcode;
% D3 X4 Z" D, s& A. ]4 s9 Kint midx, midy, mode; # E' t9 \) J0 S+ D' E. E) c" r$ V7 S
char numname[80], modename[80]; </FONT></P>) t3 R3 f( k q; p: k
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) R; M# d+ a# z. m
initgraph(&gdriver, &gmode, ""); </FONT></P>
7 F4 ]7 e2 E7 H, a- H8 _<P><FONT color=#0000ff>/* read result of initialization */
( t- A- u5 v2 _+ _! ? kerrorcode = graphresult(); , c5 u# c3 Y* I( a
/* an error occurred */
: m' [* F! N0 ~* l: s0 ?' xif (errorcode != grOk)
! M$ K' Z4 M) Q; p7 t) a. t{
# g2 c1 W( z. Z3 f" t! c: I" jprintf("Graphics error: %s\n",
6 r$ A0 n2 s G$ _grapherrormsg(errorcode)); $ T0 T) T9 ?+ u% Q. |
printf("Press any key to halt:");
3 M& R* T. X( T: d5 U5 c2 b" Y2 x1 {getch();
& |, t8 C5 p/ X/* terminate with an error code */ ' {$ z5 C2 ~3 q
exit(1); ! d$ e* m# D5 L
} </FONT></P># o) g; s4 H ?- {! e
<P><FONT color=#0000ff>midx = getmaxx() / 2;
! q- P5 U% I' b; T' _midy = getmaxy() / 2; </FONT></P>
" ?9 u* `9 Y5 p( m3 [1 x/ U<P><FONT color=#0000ff>/* get mode number and name strings */
$ i1 Z: O/ M! {0 smode = getgraphmode();
4 n, y7 S" X+ ]sprintf(numname,
! v1 D" A# A& K( d: r o"%d is the current mode number.", 0 k: _9 N1 V/ {6 \, h* s4 r, p
mode); 4 h4 X8 r* U3 w) p; u
sprintf(modename, % R* m( z1 }/ [# B/ u# Z; w
"%s is the current graphics mode", : e" ]- S2 m. p* l/ ]5 M
getmodename(mode)); </FONT></P>% m1 @" ^# {7 `2 Q/ W0 w
<P><FONT color=#0000ff>/* display the information */
9 M; H. T3 w3 p; n7 Esettextjustify(CENTER_TEXT, CENTER_TEXT);
8 x4 l9 k9 L1 n5 K, [# E( I7 Youttextxy(midx, midy, numname);
$ A$ l% F a& o- L. Vouttextxy(midx, midy+2*textheight("W"), 2 u) f# e5 o! j1 e9 r t
modename); </FONT></P>" t4 W H# O/ |! `+ o
<P><FONT color=#0000ff>/* clean up */
% N B" c5 J6 Y! p7 E; ~getch();
& N5 f$ V% R: B( _, Q0 aclosegraph();
6 R6 x, K( ?5 }4 J1 ?! @: F Treturn 0;
- }7 G% Q8 a6 l+ s, m( Y} </FONT>
# z8 U& q3 {* _0 e2 ~$ p+ o* }4 P% p/ ^9 H5 H& z1 I
</P>
; V. ?* }- m% k' f7 E<P><FONT color=#ff0000>函数名: getftime </FONT>; ?' z/ L% b+ H
功 能: 取文件日期和时间 7 y1 L6 j" W# y2 o& @6 J
用 法: int getftime(int handle, struct ftime *ftimep); ! d( N( I8 X; z& [7 q( G) }& L
程序例: </P>1 U: O+ c: a" p7 B* ~ O
<P><FONT color=#0000ff>#include <STDIO.H>: Q& j- ~9 y a6 N% j
#include <IO.H></FONT></P>
3 t5 O# [ Z" T* m- U' j<P><FONT color=#0000ff>int main(void)
4 _! l6 O- ]" S5 P9 }{ p2 P0 ^+ L+ }2 X* M
FILE *stream; 9 R; r' M3 Y/ E+ t0 ]& q3 ^( [
struct ftime ft; </FONT></P>
4 [6 \* q4 ]; Z! p+ _<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 7 h: ^) ]+ v q; f1 `" f5 k, y
"wt")) == NULL) & x) h2 n2 m, R
{ 0 H2 A" i6 X% {8 Z: [
fprintf(stderr, ( P5 {7 \# j; ~* F+ V2 R4 l
"Cannot open output file.\n"); 9 F4 {5 Z# ~2 l4 ?4 k' m% ~
return 1;
" w* l4 w2 R3 k1 U z4 t; [' ~}
; J1 e" u1 {* t5 t9 R/ Ugetftime(fileno(stream), &ft);
+ p! U4 ]5 K# {/ y$ P- t7 n8 Lprintf("File time: %u:%u:%u\n", : U w& G9 Z! ^4 r! x. b
ft.ft_hour, ft.ft_min,
# D$ c; Z4 b- c' Ift.ft_tsec * 2);
9 Y& W1 w- O+ g0 t) T( r$ pprintf("File date: %u/%u/%u\n", 5 C8 g/ E! R! F! V+ F/ `) X
ft.ft_month, ft.ft_day, 5 i a! e8 B6 K& o7 s. s' \: W
ft.ft_year+1980);
$ ~& Z6 f) q, t5 A5 F8 k& y7 hfclose(stream); 1 {1 U- c. _; }) j
return 0; ! X0 X1 ?: \8 C
} </FONT>
+ R$ t6 o( u# x; [; H. d' D3 Q- z0 Y0 g2 y
y1 u, U! `8 S. P6 ?* D
</P>! N- V5 s l4 ]5 A+ `
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
* L# V7 M; B3 U c功 能: 返回当前图形模式 , F, d. c3 H# d/ e, v& \. N
用 法: int far getgraphmode(void); + b4 o7 V, l* o
程序例: </P>8 s2 \) B/ g0 _ B& O/ t
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! c7 \0 S' F4 [7 y#include <STDLIB.H>* S7 ]6 ~% T, S5 Y$ m0 p) {
#include <STDIO.H>
+ b: L) b7 \+ `2 @#include <CONIO.H></FONT></P>
6 J# F" [: l; |# P3 Z# [<P><FONT color=#0000ff>int main(void) " V, W9 i- R$ O" D
{
, \; k- e4 Q! Q2 q# V* B4 m/* request auto detection */
- ~* x8 O5 _( | ~5 n: M" ^% }8 E) Iint gdriver = DETECT, gmode, errorcode; / _& D8 h$ H4 ]
int midx, midy, mode; ; J/ Y4 c$ T+ `5 G: [+ \
char numname[80], modename[80]; </FONT></P>
% W/ v( [( ^5 ^) N) D7 X F<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 u& ~; U% { |% X8 Y7 I1 cinitgraph(&gdriver, &gmode, ""); </FONT></P>
1 d% n" l/ M! r' o+ a/ N<P><FONT color=#0000ff>/* read result of initialization */ - a+ Y# l. m2 [& I/ [% S
errorcode = graphresult();
7 T. k9 y6 i: l8 [/ Y/* an error occurred */
9 s9 `: |; T3 h; h5 m+ q1 uif (errorcode != grOk)
$ c+ z* {3 ~- v9 k( l ~/ J6 o! Q6 z{ I" `, |% \( ^* N1 R4 J% Q, y; C
printf("Graphics error: %s\n", ( W8 P+ X. z. @
grapherrormsg(errorcode)); $ j, l2 U$ y5 M. b
printf("Press any key to halt:"); l5 k$ o4 R0 D- F+ J: c% ?' q$ t) D
getch();
$ a$ s \. R) Y. p9 u& k/* terminate with an error code */ % M. T5 @, |3 \) ?6 ~
exit(1);
0 L K5 L9 ^; {} </FONT></P>/ a! @# [6 |& j, I M* v# K; y
<P><FONT color=#0000ff>midx = getmaxx() / 2;
0 o1 u# q7 J* B% r/ amidy = getmaxy() / 2; </FONT></P>8 m- g6 r4 ^2 e; m; v" O" h; n' Q
<P><FONT color=#0000ff>/* get mode number and name strings */ ) ]3 L* g+ N, V! X
mode = getgraphmode(); 6 o p |" B2 K5 ~& Q' t9 i
sprintf(numname,
# ?5 L/ T0 @7 T6 m"%d is the current mode number.",
- c, y n( y1 C$ M0 z0 U' I' ~mode);
7 u" I$ x1 _) m0 @/ R* p1 J4 Csprintf(modename, * G! T! T" n, j
"%s is the current graphics mode",
9 ^; X& m. {2 V$ Zgetmodename(mode)); </FONT></P>
7 V* T5 b% f* Z<P><FONT color=#0000ff>/* display the information */ F+ a# m n+ _9 h
settextjustify(CENTER_TEXT, CENTER_TEXT);
9 I* Q) j( n2 [. h, L$ ]! wouttextxy(midx, midy, numname); ( c7 P k/ n. B4 t( P/ v
outtextxy(midx, midy+2*textheight("W"),
h+ ^7 I& ?% U% p: ?; X, lmodename); </FONT></P>" K, L0 L5 e' a: t& K
<P><FONT color=#0000ff>/* clean up */
! ?# g0 V' b, p$ o4 rgetch(); 5 b# A2 z% k( F/ M+ b# X1 ?
closegraph(); ) C ^3 t2 W" j; i( e: ], M6 A
return 0;
|- k9 a8 v1 y+ V8 F8 }' L}
9 ?: g8 [, s* l. f! [</FONT>2 U: {0 U/ A9 O5 D w6 G
</P>* @/ ^ v$ a6 Y3 c% O1 y
<P><FONT color=#ff0000>函数名: getimage </FONT>1 Y% B, E8 V$ Y. x4 S
功 能: 将指定区域的一个位图存到主存中
) h( _" b0 J" T: ?用 法: void far getimage(int left, int top, int right, int bottom, - u- B/ B. @5 ^: }7 y: k$ S6 c
void far *bitmap); : q z% R; R, W
程序例: </P>
/ c+ k- U0 N1 m, T k' Z K% ^<P><FONT color=#0000ff>#include <GRAPHICS.H>
! C! g3 F2 B: w# e#include <STDLIB.H>2 T7 i% I0 C0 H- E
#include <STDIO.H>
, x$ z" I1 z9 H2 K#include <CONIO.H>0 E, [! E1 h6 M; d3 F6 f" f8 ]/ C
#include <ALLOC.H></FONT></P> e. k" }; f& J8 }
<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
( K- C/ w" l8 c+ [3 Rvoid restore_screen(void far *buf[4]); </FONT></P>
, C+ z! t( ?3 ?3 D, {% {<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>
4 P( g3 P7 [. L! w: z% b4 r; _<P><FONT color=#0000ff>int main(void) # |- X) c& q) [$ G( V1 `- d" R9 a
{
6 i* g* ]% {$ zint gdriver=DETECT, gmode, errorcode; & m7 R$ }( g9 U- t
void far *ptr[4]; </FONT></P>; O- s+ _, K- Y" {$ O+ V+ W
<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
1 y3 P/ Q7 X0 H2 ~. ninitgraph(&gdriver, &gmode, "");
$ p/ n8 D- k# [% Yerrorcode = graphresult(); /* check for any errors */
1 E; B) y5 g: J7 R/ O' [) B2 Uif (errorcode != grOk)
3 q+ S V7 o9 U! Q( x$ @ c{
' j3 p: B% Z% J- ]& Z; h) Aprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 _4 H- N5 I" D" [7 Y" b% `
printf("Press any key to halt:"); 1 X: l8 s9 X# z" ^: _; ~
getch();
- K2 H2 h5 K# R- } f4 Zexit(1);
9 u( n. c1 |2 o. l$ M}
! Y+ @ P; j! @maxx = getmaxx();
+ v* i8 x% `8 `6 ^" X8 Y$ ], [7 G4 h* Xmaxy = getmaxy(); </FONT></P>: _( A! \3 \/ @" F
<P><FONT color=#0000ff>/* draw an image on the screen */ 7 |1 ~9 L1 g7 ~! d4 s
rectangle(0, 0, maxx, maxy); / j7 q: A8 w9 V e- f k% O
line(0, 0, maxx, maxy);
# b% s) x3 p0 I( G& ~line(0, maxy, maxx, 0); </FONT></P>
. Q6 T2 d8 ?3 h0 b3 J<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
, U# w1 q. o; I; {# Agetch(); /* pause screen */
- k- j. d8 p$ Pcleardevice(); /* clear screen */ ' K! D# h1 i) ~/ C- S- d
restore_screen(ptr); /* restore the screen */ ' }; }5 ~! }( {2 l
getch(); /* pause screen */ </FONT></P>3 a9 R8 W F. ]: z( v( v7 h+ ]( n
<P><FONT color=#0000ff>closegraph();
1 m9 w' q1 `5 }- `9 \# t$ D: F' Wreturn 0;
0 ]$ B0 @) _. h, z. ]% O/ v} </FONT></P>& S2 K7 o3 ~2 }* J& G, r
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) - ]5 n$ W, `( F) ?: ~) F
{ & v% Z4 P* I$ a V# ]5 ] }
unsigned size; 6 j: }) w: @6 c4 a: ~3 v- W S* I: ^
int ystart=0, yend, yincr, block; </FONT></P>( s0 m- C4 `/ e' a* T8 |
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
1 t, _1 E/ f3 Q0 p/ tyend = yincr; 8 m& \0 T$ t3 Y
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
X# M! {' E# R7 M. ^' a/ y& y<P><FONT color=#0000ff>for (block=0; block<=3; block++)
/ w; E$ r+ z6 l! l. ~{ a8 P: h) u; k* a, l( w9 [3 I: l
if ((buf[block] = farmalloc(size)) == NULL)
5 {5 @0 m5 o3 n! |8 d; a{ 2 z8 k- R& M" T8 m! x% S L; E% \
closegraph(); + w- ] D/ G+ ]; q6 l+ M
printf("Error: not enough heap space in save_screen().\n");
& O& p! p N4 wexit(1);
; x/ D, h$ p# C} </FONT></P>
2 y2 M* P; h Y0 s# h! P<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
" R% {# {( l0 l+ dystart = yend + 1; & I2 a- O( E/ M$ |( f
yend += yincr + 1; 1 Q# d0 ^3 C& z( z+ t1 Z
}
# w+ f: E6 K9 h$ ?7 k& Y} </FONT></P>
/ r- J% ?5 ~) y* F<P><FONT color=#0000ff>void save_screen(void far *buf[4])
. A; u; D8 m. J' g& R{
! p0 g. N& f2 l) f5 f1 H; ]' Wunsigned size; & Q3 U8 r/ e0 q& q% k& H/ \/ y
int ystart=0, yend, yincr, block; </FONT></P>
) X- p0 M! ~/ w7 K<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
: X* J8 d ?( {, B" R" J, Xyend = yincr;
* p$ Z% S/ L/ u2 d5 K5 u. Q. }size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
2 Q, |* T2 K9 G1 Q4 p3 z7 ~8 e' @<P><FONT color=#0000ff>for (block=0; block<=3; block++) " O1 M* {5 x7 j* ?, u
{ 0 ]7 S7 p; L; }* u2 Y' ]3 w
if ((buf[block] = farmalloc(size)) == NULL) 8 ?; g$ f" O& E$ F3 ^. R! [& A- {0 r" @) }
{ : [- K0 A+ L0 P/ l+ x$ p$ d; j3 x
closegraph();
" E& [) J: W& a% Z7 \printf("Error: not enough heap space in save_screen().\n"); 3 G5 _5 Z" d/ ~% t) d5 q6 y
exit(1);
# b% g3 U% ?" d+ w- b; k} </FONT></P>! y' _9 O2 x2 L4 I
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]); ( k; R/ z* J8 o% s4 T5 t$ S
ystart = yend + 1; 9 \2 Z; f7 j# @2 K/ w( j
yend += yincr + 1;
) n+ ^. T3 r+ n R$ M; l4 W( Y}
9 H* ~' j/ e+ Z8 X% J} </FONT></P>
: ^0 ]# V q$ M+ O<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) ?0 b/ Q$ g% I. ^+ t5 j% C$ f
{
) u, |! S6 y$ T/ X( Jint ystart=0, yend, yincr, block; </FONT></P>5 c4 S4 ^7 M2 c K* T4 ]
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
- ?3 e% t) } u7 ]) ^7 Xyend = yincr; </FONT></P>; S7 r9 G& U% q8 e# U. h$ k
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
' P/ \# M0 q! a4 M. [/ R{ ' F# M! r' ^4 U% W
putimage(0, ystart, buf[block], COPY_PUT); r, F/ s* K, I* H: s
farfree(buf[block]); + ~0 Z& k( g- |( A- O3 N K
ystart = yend + 1; ( Y& e/ b8 B) X6 U8 e: c) h, O
yend += yincr + 1; ! L Z* Q$ N' D! a
} 7 V' [$ I& ~( _; n6 \( J1 _
} </FONT>
$ Q! b% G8 P8 J" o! E5 i- e2 }1 A<FONT color=#ff0000>
: L- E$ l- [" O</FONT></P>9 Y/ E% U0 t! B: E
<P><FONT color=#ff0000>函数名: getlinesettings </FONT>6 Q4 N. A; n9 X, q8 m
功 能: 取当前线型、模式和宽度 ( b0 f' a6 A- K! j. I3 S9 J
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
# r# Y8 F) z+ B9 q% @! `程序例: </P>8 k6 U i7 b) P' c3 T! J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 ^. f& M" S: ^% B9 a#include <STDLIB.H>+ M& Z- C9 ?/ r Q) D
#include <STDIO.H>
- q$ x! y4 ? s! l( i; l#include <CONIO.H></FONT></P>. l. g" `* Q V- O
<P><FONT color=#0000ff>/* the names of the line styles supported */
! M( J, r5 W7 X3 v3 |5 ]$ qchar *lname[] = { "SOLID_LINE",
7 U7 H! G" Z. F2 J/ y* K3 \3 {7 c"DOTTED_LINE", % z4 B, i9 B( I* q8 U1 Q0 h1 i
"CENTER_LINE",
5 A6 ^/ g4 m# _, m+ ^"DASHED_LINE", " `4 L& {% B8 A2 H
"USERBIT_LINE"
* _* z% f% k& z8 f6 F8 v& [}; </FONT></P>. ^( c. d+ n" ~
<P><FONT color=#0000ff>int main(void) , `! e7 j3 g6 u4 }7 b$ i# f
{
4 S7 F, A4 h! s$ | r: ^6 I/* request auto detection */ 5 w: F1 w! S/ ^
int gdriver = DETECT, gmode, errorcode;
( Z* q3 K: N$ }1 d( istruct linesettingstype lineinfo;
' ?! S1 J0 n* i, Bint midx, midy;
( W2 s2 L. |$ U4 O! i1 l% z$ A- ]0 x5 Uchar lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
& X/ Q% g. m$ I6 y" L<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' S" E7 v2 j5 n" n) m1 B. g
initgraph(&gdriver, &gmode, ""); </FONT></P>
, {9 k! Y! z& T3 H8 }. F<P><FONT color=#0000ff>/* read result of initialization */ 1 T$ n* q8 B! P; ~5 {3 D
errorcode = graphresult(); - Q& \. o% L2 k% u0 A* K
if (errorcode != grOk) /* an error occurred */ F& R- Z% S0 e* Q) y2 c6 Q
{
# F4 ^" T, g1 W; V! c) Z. Cprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 a, V7 [' F& E$ yprintf("Press any key to halt:");
6 {, Z, p" F: C. t; bgetch();
2 m3 n3 Z7 |8 f. |9 ~, fexit(1); /* terminate with an error code */ # h9 k5 {. P* f2 d3 M2 H2 i3 Y' d
} </FONT></P>
S9 h3 W" j8 m2 r3 g7 m<P><FONT color=#0000ff>midx = getmaxx() / 2;
- n- p& y, T$ N: C" a3 h3 {# Zmidy = getmaxy() / 2; </FONT></P>
* m; M n A: t: |( L$ ] Y3 ]<P><FONT color=#0000ff>/* get information about current line settings */
5 d4 Q, v1 D0 ?) n- ]8 ?getlinesettings(&lineinfo); </FONT></P>
* Z2 E9 i3 [ _& v1 T( m<P><FONT color=#0000ff>/* convert line information into strings */
5 \% F2 a& x' q5 O5 Y3 N) lsprintf(lstyle, "%s is the line style.", ( y6 \" A9 j% L$ @* w N6 T
lname[lineinfo.linestyle]);
+ y2 }8 `, L8 f" |/ {1 W8 tsprintf(lpattern, "0x%X is the user-defined line pattern.",
$ d3 [. x" A3 e( ulineinfo.upattern);
# J3 Q: Z% |" I4 C! `% w7 osprintf(lwidth, "%d is the line thickness.",
0 R% P) S( }7 L, n1 r% D9 vlineinfo.thickness); </FONT></P>( d; u# f( v& _8 Q7 S: Q7 R
<P><FONT color=#0000ff>/* display the information */ / |% X$ a# H* y) p
settextjustify(CENTER_TEXT, CENTER_TEXT);
) |, W0 Q- z+ \5 _* c2 a' ]outtextxy(midx, midy, lstyle);
' i+ @/ p8 A$ c4 @ `% _3 routtextxy(midx, midy+2*textheight("W"), lpattern);
, p1 O$ p! d4 U, u! {outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
, z! @5 c, r* y<P><FONT color=#0000ff>/* clean up */ ' V2 I: B, k, Z _; q8 K( z9 t# Z2 M
getch(); ' }5 G1 V! s j
closegraph(); . `3 _3 x0 J( O; P7 p
return 0;
4 P) m/ z" H' _( U} </FONT>" h' P* K) m, ^2 S
" K" r$ V4 `4 e# X3 b</P>7 q! |& X; M* q
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT># T. e6 S" e& N3 @% j+ u% {
功 能: 返回可以传给函数setcolor的最大颜色值 . e( t# C( I& ]: ^9 {5 I( u
用 法: int far getmaxcolor(void); 7 a8 W. i+ R4 q( Y4 z
程序例: </P>
% l( U3 {1 e1 X& T* S7 e3 f; p/ F1 b<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 G7 X. T: k/ w#include <STDLIB.H>
' d; Q* W$ i% b/ I5 l: t: J* h! C#include <STDIO.H># a2 r9 O1 M" _% V7 J. f
#include <CONIO.H></FONT></P>& m* A, m# e' z5 j/ w
<P><FONT color=#0000ff>int main(void)
2 G$ k3 r+ v# A{ $ ^* e( |2 @/ i* C. |" S
/* request auto detection */
0 Y4 t" c$ r7 v& h1 q- _; r! vint gdriver = DETECT, gmode, errorcode;
! j0 S I3 g! pint midx, midy; / S3 z! `& v# i+ B
char colstr[80]; </FONT></P>9 i; r8 T9 |6 J0 \
<P><FONT color=#0000ff>/* initialize graphics and local variables - Q; F* ?7 J0 k9 e& Q( @9 F5 L
*/ initgraph(&gdriver, &gmode, ""); </FONT></P>
$ Z; ?/ a5 }, ^ M2 k( R<P><FONT color=#0000ff>/* read result of initialization */
1 }" k' s6 H: l5 A) H/ u+ Serrorcode = graphresult();
/ z7 x1 ~1 J: fif (errorcode != grOk) /* an error occurred */
( n& ]0 T0 D2 ?$ z/ |{ / D+ _# l3 m* E5 W% C
printf("Graphics error: %s\n", grapherrormsg(errorcode));
: Q z0 ?* s/ d* {) v) Gprintf("Press any key to halt:"); 3 W! ?8 E8 ~! n7 S9 v
getch();
; _! M0 r& u4 ]: S2 z2 e w( Nexit(1); /* terminate with an error code */ 3 V; Q0 ]/ z7 i3 |/ `- r( |
} </FONT></P>
y- ]" S8 Z( l0 D<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 v: H7 _4 I! Hmidy = getmaxy() / 2; </FONT></P>* U& G- x1 f8 {
<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
% T6 F# T1 Z. M3 ^$ A9 V% @7 }9 Nsprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
- b4 W) [5 ^7 z# f6 M3 N<P><FONT color=#0000ff>/* display the information */ 4 Q: G/ `/ e$ { h. P# r3 k. h
settextjustify(CENTER_TEXT, CENTER_TEXT);
- g; w) O! Q+ }' l. }; l, {; |outtextxy(midx, midy, colstr); </FONT></P>; s/ F1 G3 `- W# j$ A
<P><FONT color=#0000ff>/* clean up */
' m# ?' K/ p% d& }, W% s) v% Ygetch();
1 w0 t: C# l, x3 K9 Zclosegraph(); : u9 L3 ], |$ j# U' N
return 0;
0 r ?9 @$ ~6 f% }. A1 X} </FONT>
0 P. D+ G4 j) J& j6 q# {
$ A. {+ X3 \- ~9 }' Y% [, \# v3 ]. [, i! O: U
</P>/ w; B9 }9 e4 ]
<P><FONT color=#ff0000>函数名: getmaxx </FONT>( R" a- {! f& W
功 能: 返回屏幕的最大x坐标
7 @( z2 O0 M) Y: r5 G用 法: int far getmaxx(void); 0 S/ T' N% M, E( j: R1 V8 K, h7 i o
程序例: </P>
- ~; I6 x6 ~/ f! l<P><FONT color=#0000ff>#include <GRAPHICS.H>
# v) W% J6 i8 S" }4 W' [& D5 l#include <STDLIB.H>& U, t3 Y( Q8 V
#include <STDIO.H>2 t1 @- c$ C4 m [ t
#include <CONIO.H></FONT></P>! [7 L/ [+ o Z1 j; }& [# f1 x
<P><FONT color=#0000ff>int main(void)
* x$ [+ z) t; x" u: o{ 5 Y2 ^, w+ P2 c, T
/* request auto detection */ # N8 q2 s: Y6 s
int gdriver = DETECT, gmode, errorcode; . s* ^( c) V) `, F
int midx, midy;
) ]* ^0 j8 W) n( X5 ]/ Wchar xrange[80], yrange[80]; </FONT></P>
* Z; P! T: g9 I ?, M3 l<P><FONT color=#0000ff>/* initialize graphics and local variables */ l7 V6 r$ u% p" C/ V' t5 `5 l
initgraph(&gdriver, &gmode, ""); </FONT></P>6 }& i2 K d/ \
<P><FONT color=#0000ff>/* read result of initialization */
p" n o! N! N' Oerrorcode = graphresult();
7 G$ G6 W" M6 ^, B0 Jif (errorcode != grOk) /* an error occurred */ : J. q# O, c9 Y0 W; g6 s) `" I
{ % W) p: `$ ?, I
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 n% c, X$ C+ w: e# z1 ~2 e/ {printf("Press any key to halt:"); ( i4 r t( q/ L1 B$ d( J
getch(); 8 A, }$ T! u3 W+ ]/ _! ~4 P# b) r
exit(1); /* terminate with an error code */ . H& c2 u- R& D( u v0 S c4 R% ]
} </FONT></P>4 f8 X' c0 @7 X) a; g* J
<P><FONT color=#0000ff>midx = getmaxx() / 2; # l& ~/ w& U' H7 n8 f
midy = getmaxy() / 2; </FONT></P>0 @. e' Z4 w# g
<P><FONT color=#0000ff>/* convert max resolution values into strings */ " u1 n3 R) U/ v- ?8 X% y0 J- m. {
sprintf(xrange, "X values range from 0..%d", getmaxx()); % P$ P( f: ? L9 b }
sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P># n% a( y, \' ?2 I3 F' S4 k
<P><FONT color=#0000ff>/* display the information */ 4 j% L; D. {: S F9 \5 Y
settextjustify(CENTER_TEXT, CENTER_TEXT);
* _8 c) G/ X! [9 k3 R/ @% x7 }outtextxy(midx, midy, xrange); 1 n- f+ V% }2 W# u" I# P! A3 @
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>& O2 s' q# b! z9 W" K1 Q- Q
<P><FONT color=#0000ff>/* clean up */ ; g6 k4 X: d# {* J" d+ ~
getch(); 5 q) z: l+ I1 n9 v3 o9 H( W
closegraph(); 4 c5 U8 S6 L6 b2 m: m6 T
return 0;
* w9 V, V; m0 P+ r: {}</FONT>
8 J$ @# K2 j& |) V# t9 i1 J/ U* W- A, I1 j' r- C. S2 \3 l& ]4 c; T& r
</P>! p9 |, w% g" K, p9 j5 H
<P><FONT color=#ff0000>函数名: getmaxy </FONT>
/ u. w; K: e0 K, }) c% f, f功 能: 返回屏幕的最大y坐标 : {: t7 X4 _ [" @; x
用 法: int far getmaxy(void);
/ n5 P+ ]) C& f6 q' Q* F$ R1 J0 N程序例: </P>
' H4 c9 E# [6 C& x& D, f. u<P><FONT color=#0000ff>#include <GRAPHICS.H>/ d* ?, B2 [4 B2 g V' w q, t
#include <STDLIB.H>( H, N$ F4 T7 ]; z+ [. N2 ?
#include <STDIO.H>
' _+ Z/ ^. G) X0 q#include <CONIO.H></FONT></P>$ G, Q6 ^' D) b3 O
<P><FONT color=#0000ff>int main(void)
) |* r+ C! G" |. q" R$ x$ D{
3 X& ?9 O) L P4 t0 V, J" [/* request auto detection */ 0 K; ^1 _7 {/ A* }" n+ @
int gdriver = DETECT, gmode, errorcode;
% f; E% k/ `7 {" T) i/ oint midx, midy;
: p0 w' `7 R3 t5 V7 M: ychar xrange[80], yrange[80]; </FONT></P>( H6 A4 M; M' m3 K( ?8 g4 X- J
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 \& d' j9 P$ ^' p4 O
initgraph(&gdriver, &gmode, ""); </FONT></P>
4 }. h9 g: r s i! N<P><FONT color=#0000ff>/* read result of initialization */ " Z! {1 a' U& F! x- }
errorcode = graphresult(); 3 I8 }, j9 P* U0 q& A
if (errorcode != grOk) /* an error occurred */
) ^7 O, `- J" L{ 7 Y0 Z* U8 n7 {2 L/ d
printf("Graphics error: %s\n", grapherrormsg(errorcode));
" ]1 `; g7 W5 L" H9 [% k+ eprintf("Press any key to halt:"); 2 _/ s0 t+ C) E% y
getch(); ( ?* @! w8 t& B- j8 R. K
exit(1); /* terminate with an error code */ . p7 A7 i# _/ s3 J& A; X p
} </FONT></P>
6 F* E$ O9 \# q/ x4 m& I1 @<P><FONT color=#0000ff>midx = getmaxx() / 2;
0 {, }& u' z( Zmidy = getmaxy() / 2; </FONT></P>
( K) e, k; m- p0 a/ ~<P><FONT color=#0000ff>/* convert max resolution values into strings */
3 \$ I0 f6 A& Esprintf(xrange, "X values range from 0..%d", getmaxx());
! |; X5 E( d, r$ L; k+ jsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
7 X0 v+ ~2 o- I) A- Z" n( u<P><FONT color=#0000ff>/* display the information */ 3 S: {7 ]( N' t1 K# ?3 B
settextjustify(CENTER_TEXT, CENTER_TEXT); . `/ _1 y1 }# K
outtextxy(midx, midy, xrange); 2 B1 T" S' E( _% C
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
1 U5 G9 O' e @" m$ S<P><FONT color=#0000ff>/* clean up */
! M. M' ]6 B; u7 G* o+ j& }# cgetch();
( H2 l+ \5 _/ A. t' T Z) k7 f, t4 Dclosegraph();
! Y2 G+ p f0 F$ q" H3 e1 ireturn 0;
0 Z8 S% s$ W2 Q! r} </FONT>! N% \" m' H5 {) O) g0 D
</P>5 T# e' Q. f' D U$ g: y$ j
<P><FONT color=#ff0000>函数名: getmodename </FONT>
, ~6 }0 i/ e* R- E功 能: 返回含有指定图形模式名的字符串指针 7 s# |: f! A" d; d( t9 ?
用 法: char *far getmodename(int mode_name); 8 W! U" p! {& ^; \5 b. o; k; E) t
程序例: </P>
- k6 @! v7 n& G0 r% P<P><FONT color=#0000ff>#include <GRAPHICS.H>
. q6 P/ p/ R% {5 T! K6 D#include <STDLIB.H>, ], |( I" H; `: f
#include <STDIO.H>
+ c, [" ~. j9 W7 K3 Y# I#include <CONIO.H></FONT></P>
' i X) W+ W1 F% G/ M% e& u/ W/ L<P><FONT color=#0000ff>int main(void) 9 w! p% U1 J% d9 Z7 p- ]1 ?6 m
{ # z2 a9 S$ @2 _
/* request autodetection */
& ?& B& r- C6 q/ m9 O; t6 k8 Gint gdriver = DETECT, gmode, errorcode;
) D! a/ l) g- S: pint midx, midy, mode;
% ?8 D6 ]8 {- Vchar numname[80], modename[80]; </FONT></P>
4 g7 a0 M: [) S& ~<P><FONT color=#0000ff>/* initialize graphics and local variables */
# x! X1 J" Z1 D3 b, w; k. Pinitgraph(&gdriver, &gmode, ""); </FONT></P>8 S+ k& J2 u; Q" X7 ^, G
<P><FONT color=#0000ff>/* read result of initialization */ 0 S" |" {5 r/ v0 h, I2 Y
errorcode = graphresult(); & C$ P) C/ Z& |% }. F! v, t; h
if (errorcode != grOk) /* an error occurred */ & h" P1 X/ A! l5 y0 c) z
{ ! h4 B T- S! z8 p
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # D' V/ I4 e( l+ t- K
printf("Press any key to halt:");
% y) U5 o7 h! q9 l. }& _getch();
, g! v0 ]0 G& K$ ^exit(1); /* terminate with an error code */ 2 J1 O: W. t* l4 ?0 ~* ^) `
} </FONT></P>
5 N. w# Y5 W( f: t<P><FONT color=#0000ff>midx = getmaxx() / 2; 3 N x# e: [) t
midy = getmaxy() / 2; </FONT></P># @& F( K' E, g7 s$ N
<P><FONT color=#0000ff>/* get mode number and name strings */ 7 U+ u/ a9 Z9 b
mode = getgraphmode(); / b5 E$ U& F/ k1 a
sprintf(numname, "%d is the current mode number.", mode);
- b# J1 u( S) gsprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>- e, z$ D; a! n9 q
<P><FONT color=#0000ff>/* display the information */ ; a0 u2 U* N( h
settextjustify(CENTER_TEXT, CENTER_TEXT); 7 h5 N" d- u" F B* v
outtextxy(midx, midy, numname); : S6 u$ L7 t" e: X
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>
+ C7 c0 G" v; J+ X5 M<P><FONT color=#0000ff>/* clean up */ $ b g# a# L7 O1 ^$ d, Z5 t" e
getch();
9 A3 L' P5 P" ]2 \% vclosegraph(); : \# a0 }7 O) `
return 0; - I; a: G4 m1 c: D( [* Z) a
} </FONT>
) m# _6 v) w$ _# J/ s" G3 `# H$ ]' u7 d' Z$ J
</P>1 m0 J& w- ], o# l3 k$ C; h
<P><FONT color=#ff0000>函数名: getmoderange</FONT>
3 }6 A! Y, g: a2 r& }# [9 \2 u功 能: 取给定图形驱动程序的模式范围 ) W* `9 d) M$ g }! J3 M7 c6 f
用 法: void far getmoderange(int graphdriver, int far *lomode, ; L* |2 J' l( T5 {' Z5 U
int far *himode); : b/ T0 y# U! v' ]: M) V2 K
程序例: </P>
$ f6 Q3 w* R f' ]5 {" k<P><FONT color=#0000ff>#include <GRAPHICS.H>3 w9 Q& A% K8 O6 u
#include <STDLIB.H>
3 }$ [+ o* T+ a% W" ^* g+ F9 J#include <STDIO.H>' M" J% W6 U- ^' r) M7 I! j8 |/ V
#include <CONIO.H></FONT></P>
- d( E- m3 w1 D) O# Q<P><FONT color=#0000ff>int main(void) 2 u- L' K9 R( B2 L/ Z
{ $ S4 x M0 e$ N; p
/* request auto detection */
( j, J2 K' H6 \( h, \- `int gdriver = DETECT, gmode, errorcode; $ a3 ]" l% N5 }' D8 g8 e( T3 H
int midx, midy;
) E: v z* @8 H. S3 Eint low, high;
W5 G" I* ]5 L* M; k zchar mrange[80]; </FONT></P>
+ }2 _6 K2 l, Y# k1 v<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 `* h# {, H6 |: D( c! t
initgraph(&gdriver, &gmode, ""); </FONT></P>% W6 ]' x3 F" h' n
<P><FONT color=#0000ff>/* read result of initialization */
* }6 }* Z( p# A, verrorcode = graphresult(); 6 D4 f4 G. X* T" }- f5 q d) R
if (errorcode != grOk) /* an error occurred */ 7 _9 I% K$ F5 l+ K# j
{ 1 ` e T, S6 [7 ~% P- ?. N1 s! {
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 r$ v- [* ]4 c' U$ \
printf("Press any key to halt:");
# r# s! G. | d- U. C/ g5 Z, ~6 agetch(); 1 ^- E+ {2 \4 e
exit(1); /* terminate with an error code */
N O' ^+ T3 j, A& `# w7 \} </FONT></P>& g( V" X- S" y3 f7 ^! ]
<P><FONT color=#0000ff>midx = getmaxx() / 2; ( T5 Z4 ^0 N. ^ u; o
midy = getmaxy() / 2; </FONT></P>/ U8 l H y8 s8 u
<P><FONT color=#0000ff>/* get the mode range for this driver */
+ S# l% z7 m) O- K+ rgetmoderange(gdriver, &low, &high); </FONT></P>/ E- O& F1 c. x( z8 ~
<P><FONT color=#0000ff>/* convert mode range info. into strings */
# v: ~: O2 k! D* D/ K$ nsprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>4 d- f! ^/ [7 ~# _& Y
<P><FONT color=#0000ff>/* display the information */ 0 p) B+ G, b2 @0 h
settextjustify(CENTER_TEXT, CENTER_TEXT); : r" b4 S/ t, S( G- {, W0 e
outtextxy(midx, midy, mrange); </FONT></P>
9 P7 Q/ ]) |6 ?<P><FONT color=#0000ff>/* clean up */
3 N r3 T S5 ]( A! Ogetch(); 6 l! n: K" j9 y" C
closegraph();
/ K% ~1 z6 s2 J4 ?1 ]return 0; ) w1 d: s7 o3 j5 N" ?; A( S E
}
4 V4 w9 E8 A& F</FONT>
3 |8 F/ _7 P; w: M2 J3 O</P>
7 {7 v @3 o$ w" V<P><FONT color=#ff0000>函数名: getpalette </FONT>7 G1 Q; x; @5 \3 D1 [- v: p9 k
功 能: 返回有关当前调色板的信息 # M$ z' p! l# \* k. d
用 法: void far getpalette(struct palettetype far *palette); * N4 o2 o3 J q8 u s5 @, Z
程序例: </P>
1 C* C. U# I: h5 c0 a3 w2 b; Z0 W<P><FONT color=#0000ff>#include <GRAPHICS.H>: s9 [( v# r: J, F7 `8 @, d
#include <STDLIB.H>
( |) Y# m6 A9 J# q7 V5 p#include <STDIO.H>
* A8 ? j9 P4 ?) f#include <CONIO.H></FONT></P>9 Y/ _+ O1 E) r+ ]7 f. Q& s
<P><FONT color=#0000ff>int main(void)
8 B4 |3 J* a# D3 r" e8 `; v! x2 m{
; [0 \+ n5 y5 I2 t2 y$ B/* request auto detection */
5 W4 k- f8 c$ _8 j/ Yint gdriver = DETECT, gmode, errorcode;
$ |$ _, r, _7 ?1 [: ~2 Gstruct palettetype pal;
4 D+ q" N) o% n- T* X9 i8 S) schar psize[80], pval[20];
7 z3 g4 k6 \. H0 f* L0 h4 r+ r/ U# Uint i, ht; + K( _' d6 `: X. p* v7 C' a* Z
int y = 10; </FONT></P>3 P& H+ g0 ?7 A* s R9 J7 l
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , J/ u5 f6 G; I6 ~4 A8 n
initgraph(&gdriver, &gmode, ""); </FONT></P>
b) E) M0 P' V4 O& R' V% c' j<P><FONT color=#0000ff>/* read result of initialization */
; x/ v a3 E7 C2 W# gerrorcode = graphresult(); ( \- q; R: Y- G! e9 H( r
/* an error occurred */ 8 Q/ N- G* x5 f* N
if (errorcode != grOk)
, x/ T0 I+ G. I5 j7 c" n9 P5 i{ 5 f& L! E/ G7 W+ ?/ u( U
printf("Graphics error: %s\n",
3 Q& f: E8 Y/ N; {grapherrormsg(errorcode)); . e+ j8 S6 `5 q0 a
printf("Press any key to halt:");
' I4 Y$ E, H& E, F) ]getch();
& V- M9 l! l- `$ N2 N/* terminate with an error code */
* F! v& \- Q u9 Texit(1);
9 `# i3 |( {: ?. c3 R} </FONT></P>/ I. J' f7 b J
<P><FONT color=#0000ff>/* grab a copy of the palette */ + E5 Z/ p% h! } }; \/ H9 O
getpalette(&pal); </FONT></P>* s) j0 i1 ]) _ r1 K3 W
<P><FONT color=#0000ff>/* convert palette info. into strings */ & u0 U' D! a: J# {! L
sprintf(psize, "The palette has %d \ 3 Y% v1 o$ ?0 _+ f" |* ]
modifiable entries.", pal.size); </FONT></P>
2 u6 _% @. o3 Q/ i, f% l<P><FONT color=#0000ff>/* display the information */
( s5 i6 b" C. ]7 t! v* ?% |8 v3 p* Youttextxy(0, y, psize); 3 H$ n; F; m. S& f' Q
if (pal.size != 0) 5 E5 a" K( z1 D: n& c* I2 g( |
{
8 p2 G0 ?! B% M8 Xht = textheight("W");
# D3 I W S& i* X uy += 2*ht;
$ P2 W& s& W. O- A' Vouttextxy(0, y, "Here are the current \
/ n9 {9 W2 f4 _$ cvalues:");
2 d3 l, x1 J" b- @& e( U4 _% ~# n, x7 Hy += 2*ht; 8 e7 K7 \8 t, m/ Z v
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
# U: e) _# @7 f, g5 v7 P' ^sprintf(pval,
3 v1 A% T! K- G$ n0 g"palette[%02d]: 0x%02X", i,
9 u' i/ a; a! ^- g( H& O! npal.colors);
& w2 [2 M- F# `( Q0 U9 W' c% pouttextxy(0, y, pval);
" z9 p) C5 }$ C4 P- ~% _}
2 o& M, E2 A- x/ P" H o' b+ c1 Z} </FONT></P>3 o, b5 U9 P! n9 V! O
<P><FONT color=#0000ff>/* clean up */ 7 G! D% a, M \7 M( u" k1 d0 K) J
getch();
. K: ~( J ?* `7 z3 {closegraph(); </FONT>
( x% W% S" @- f$ J7 j7 Q& P<FONT color=#0000ff>return 0;
3 [ f1 n$ @5 [# a# E6 d4 i} 9 a( `- V9 Q0 ?* [( v: p% {7 y, I
</FONT></P>8 A6 t' ^' ]! R" R
<P><FONT color=#ff0000>函数名: getpass </FONT>
' {. ?; b& v2 T" n功 能: 读一个口令 " `1 q" z. D5 ]' Q" j
用 法: char *getpass(char *prompt); $ g5 s) |) {% ~2 Z2 o$ p
程序例: </P>
2 |; J5 T$ K/ [$ a( p+ H- ^+ X4 i: U<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>, q0 u0 x9 ]7 _+ N2 b7 @8 j
<P><FONT color=#0000ff>int main(void)
& J: K+ K3 I7 |) }( E' l9 |{ 6 @( W: G8 B7 O- y1 A" {* {
char *password; </FONT></P>
2 U1 P" ?" b9 S) U4 N4 }* b<P><FONT color=#0000ff>password = getpass("Input a password:"); & Z# k/ T' ~& u" z' r9 S# u9 V+ ?
cprintf("The password is: %s\r\n",
4 @3 \5 I# |2 X; Lpassword);
. J7 q" p( @$ v% s$ dreturn 0;
! K; S' W" a) a$ O' P! U} ! P, u/ `8 `1 ?
</FONT>2 ~4 E; ]6 ?% G
0 _; E1 ], m" r1 \$ N* l: ^</P>+ Y; f4 [, Y& I2 R1 p2 N" V2 u
<P><FONT color=#ff0000>函数名: getpixel </FONT>; K0 F. T3 f. r- {) K8 F8 ?
功 能: 取得指定像素的颜色
+ R- |. H8 ?- ~% l; L4 V用 法: int far getpixel(int x, int y); 9 |' D# R; p F6 H$ E h `
程序例: </P>9 P) s" p# ?' g9 e
<P><FONT color=#0000ff>#include <GRAPHICS.H>
' o0 d, r+ ^. z' s2 @#include <STDLIB.H>
4 U$ z$ {; i2 T1 G# ^, P' Z#include <STDIO.H>
d3 T( n, C0 c& ?$ P( M9 A#include <CONIO.H>* p2 E6 M0 w2 p
#include <DOS.H></FONT></P>
; H) y x! \# H! Q6 q+ V<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 & d& f& `. \2 ~: S$ h I' u9 w
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>7 E- G' @9 k1 C3 _, a
<P><FONT color=#0000ff>int main(void) 4 Q9 y1 R5 w: h" K! W
{ # ?6 k; r0 i: P6 X
/* request auto detection */ * i2 N' r( {2 m8 s3 g% H3 y8 Z% E
int gdriver = DETECT, gmode, errorcode; 1 K$ I1 l3 a7 V& X1 k
int i, x, y, color, maxx, maxy,
% {* g& X8 V8 M4 ^! }maxcolor, seed; </FONT></P>
) @8 p3 Y6 M( D+ q- D2 [& h<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 d7 g- v3 e1 q' r! Y" cinitgraph(&gdriver, &gmode, ""); </FONT></P>
! U Q: q' B! L, q* |<P><FONT color=#0000ff>/* read result of initialization */
& w& U1 m1 D: K6 T% }* W4 ~4 verrorcode = graphresult();
+ ?0 S# v% x- o4 C% l" y7 n- o/* an error occurred */ m" |9 c' b, g! i7 g' W3 D! d' I
if (errorcode != grOk)
& }+ S/ J9 S& T# _! x" [{ 9 k( N+ u+ v; i" g: Z
printf("Graphics error: %s\n", % K3 t% Z9 y p5 ?* u
grapherrormsg(errorcode));
$ i$ _& V* k9 }; z' D. Z/ D! N: c9 H3 jprintf("Press any key to halt:"); 2 s$ N, s# H7 o# W
getch();
Q2 g0 d/ E( j, j# u2 P/* terminate with an error code */
- j4 w8 V- z9 V. I9 D+ Dexit(1);
! v) Z4 U3 U% J+ H/ ^! ?} </FONT></P>2 |% L4 h4 }, N) a! T
<P><FONT color=#0000ff>maxx = getmaxx() + 1;
/ n' h0 `6 P; p1 o, @2 w/ p# zmaxy = getmaxy() + 1;
0 R" M2 u/ z* O" ~. [maxcolor = getmaxcolor() + 1; </FONT></P>
0 z# w. I8 Z* C, T( i<P><FONT color=#0000ff>while (!kbhit()) ; W7 m7 M4 G% W5 d2 u
{
4 J" M& H, N( r7 k$ P6 J/* seed the random number generator */ % G7 j5 R& |8 L8 q5 T0 K) N; @
seed = random(32767); * q& ?3 _/ N5 j+ n* v& C$ `9 z
srand(seed);
8 B! \) ^/ h! }8 M& @' F9 |4 cfor (i=0; i<PIXEL_COUNT; <br i++)> { # z! ~% h9 P) F# F/ v1 ~* Z
x = random(maxx);
1 a% Y$ |, p6 E, R! l9 N7 z9 u% u1 vy = random(maxy); 9 _0 W" `# _ a2 I! `6 p
color = random(maxcolor); # L* G, C) u4 J; e$ i& V9 j
putpixel(x, y, color); N8 z9 q. r5 X8 G
} </FONT></P>1 \# K/ P/ _+ I5 m1 l& `1 j
<P><FONT color=#0000ff>delay(DELAY_TIME);
- W, G- i \# x: t% M9 q( ^; dsrand(seed); ; b% J& p6 x6 ^' H% D0 [6 r3 f
for (i=0; i<PIXEL_COUNT; <br i++)> {
! i0 S8 o$ h, w) }5 J7 I# B% w4 ~ Xx = random(maxx);
% {( O; G# w" ^' v6 M o/ s# o9 F1 dy = random(maxy); $ @; A; L$ \3 l3 {! q- g
color = random(maxcolor); - t' b _) {. |! ~1 Q
if (color == getpixel)</FONT> </P>( {2 a& u- X! g. I; E8 F9 a2 M! a# C
<P><FONT color=#ff0000>函数名: gets</FONT> , q7 C- I. W' S$ o
功 能: 从流中取一字符串 / W& W; k& s7 z4 x7 @5 j7 \" Z
用 法: char *gets(char *string);
3 f! N: T) u- z7 c; o9 ^程序例: </P>
4 ?, `' E& N' a5 v: x* O6 W4 X<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>( _) R6 N4 \% r4 s- p% ]
<P><FONT color=#0000ff>int main(void)
* [* E+ {# i* [0 s7 @{
# r5 g) d$ t- _! E% |) Bchar string[80]; </FONT></P>
* G' b: C' ~$ _' \<P><FONT color=#0000ff>printf("Input a string:");
, R h' B8 B L/ r, N, Z+ _gets(string);
; Q# e' A$ v2 W# B4 \printf("The string input was: %s\n",
6 C. E/ o# ?0 R% u& W* z& D9 Istring); - _% A. N2 g) j
return 0; 4 v; U: y1 _2 X/ W. f- ^' W! R
} * s, Q! n! I, A1 p7 |
9 |( n& b! Y) a3 v( ]</FONT></P>
- s: Y( z9 N& A$ ]<P><FONT color=#ff0000>函数名: gettext </FONT>
1 _1 \- e+ J/ G+ q ?4 Q. Y功 能: 将文本方式屏幕上的文本拷贝到存储区
8 s- D" ^) @/ {6 U$ ~! n用 法: int gettext(int left, int top, int right, int bottom, void *destin); / V1 P* t9 o+ F* q' g
程序例: </P>& n6 E8 m1 g' L# z8 t" u" f
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>5 z2 I' j; M+ _7 i( Y. H
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
* a) i/ Z: S, @5 w4 H9 p/ j<P><FONT color=#0000ff>int main(void)
7 E$ y/ [: i, `( \{ 9 U4 v$ L* y H8 W8 h
int i;
! D$ I9 v5 N5 E1 M. m9 wclrscr();
* T- O: K9 X. }: \' f* @! dfor (i = 0; i <= 20; i++) ) s. o# ^6 i, A5 P8 D% [- H% r+ z
cprintf("Line #%d\r\n", i); % x* P( ]9 V6 b
gettext(1, 1, 80, 25, buffer); 7 {" c q! w( C
gotoxy(1, 25);
, w$ s8 @7 y7 ?9 R) b6 v4 }6 Lcprintf("Press any key to clear screen..."); ( m( H: @" S7 W
getch();
' ]) U5 c# d) Q: ~& w( cclrscr();
* i6 D1 _, w% X: _: ]6 Tgotoxy(1, 25); : j( D; E9 `& z" ^0 S( k {3 n Y
cprintf("Press any key to restore screen...");
6 }" D. G2 }8 ]getch(); 2 J+ w X" O" u' @
puttext(1, 1, 80, 25, buffer); % Z: |' A' p( |; g' W4 n! l8 `
gotoxy(1, 25);
4 U1 p' w! J/ ]1 D$ A- ycprintf("Press any key to quit...");
) R7 D+ n* A2 q e0 B+ o' \9 V. b" Cgetch();
& D1 y+ \1 L/ o& Ireturn 0; ; f5 E1 }, r' |9 G. n; r
}
5 ~( A, k3 N$ ]2 s7 c) e) }</FONT>
6 S- U% F4 F8 I( X+ K</P># G5 Y: K( }& c! t9 w2 q
<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
2 V1 o1 x: F1 i" b8 X/ |功 能: 取得文本模式的显示信息
b+ m, ^# V+ \+ u3 n! a E, I# F! k用 法: void gettextinfo(struct text_info *inforec); ( J* a& F9 e# F, {* o+ i; r
程序例: </P>
( w2 N2 q! U2 T/ U3 c8 _<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
2 j8 S; h) E! [. E8 i6 ]<P><FONT color=#0000ff>int main(void) 7 v) k6 J8 U* N" Y1 u
{
- r; ^7 r/ z8 A2 m$ j( ^' S6 Dstruct text_info ti; / b' {1 D; q1 T1 ]
gettextinfo(&ti); 6 U+ v9 |. n: @. q& ]
cprintf("window left %2d\r\n",ti.winleft);
5 U a. x# ~+ s0 |( mcprintf("window top %2d\r\n",ti.wintop);
" |: P" g- p0 E2 t' G4 @9 Kcprintf("window right %2d\r\n",ti.winright);
$ j# o# E" ]: s$ F1 tcprintf("window bottom %2d\r\n",ti.winbottom); - S! I6 `) W& |1 N/ L$ f
cprintf("attribute %2d\r\n",ti.attribute); G- \3 e& Z5 n# J1 ?# j
cprintf("normal attribute %2d\r\n",ti.normattr);
A, m" ^6 @" @2 R" k, e/ Y. Hcprintf("current mode %2d\r\n",ti.currmode); + `) I0 T) p# J, i2 m
cprintf("screen height %2d\r\n",ti.screenheight); 9 U- i& n+ W$ I; h" g, H
cprintf("screen width %2d\r\n",ti.screenwidth);
5 D" ]' W i) @4 |3 Y7 Pcprintf("current x %2d\r\n",ti.curx);
7 S' i: e$ d6 U* S& ^cprintf("current y %2d\r\n",ti.cury);
- D% `' Q- x; O) C6 W; Mreturn 0;
- [7 {) \8 M: a( e5 V& J- S+ m1 ?}
0 C+ o5 y% i* C2 _$ Q$ K</FONT>0 F4 |/ M9 ^% b& M5 h9 D
</P>
8 y$ Y* X! f. ?! @6 }- y+ U<P><FONT color=#ff0000>函数名: gettextsettings </FONT>
) A& I$ c1 Q! A; `功 能: 返回有关当前图形文本字体的信息 $ |) ]$ X( m, n9 P$ e+ J
用 法: void far gettextsettings(struct textsettingstype far *textinfo);
: `6 t# C5 ]: Z" W程序例: </P>
) P K* W: H7 y: Z! i<P>#include <GRAPHICS.H><FONT color=#0000ff>
& a. w1 A2 `; C& V+ K% D#include <STDLIB.H>
! R7 N) t+ q" a& ]7 E0 D#include <STDIO.H>
2 ~' e3 P" D" A( U4 C {#include <CONIO.H></FONT></P>4 C7 m% u" S, q8 o# A5 C
<P><FONT color=#0000ff>/* the names of the fonts supported */ / L! g5 u- p, d) k7 @' E
char *font[] = { "DEFAULT_FONT",
9 a8 Z# D. {. Y' G) E# T5 C1 \7 i"TRIPLEX_FONT", % C3 y8 E% W9 ?, g
"SMALL_FONT", 9 t2 H ~; ?: D4 T
"SANS_SERIF_FONT",
( V$ r8 ^4 O8 Z' M' I5 i"GOTHIC_FONT" ; ^1 y; p; Q( a$ P3 S9 X6 M
}; </FONT></P> Q$ Y' Y' w' r' ~: w }
<P><FONT color=#0000ff>/* the names of the text directions supported */ ! n! n! k. b+ ]5 v2 F
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>
7 V. C( ?, y- g# @. q# u<P><FONT color=#0000ff>/* horizontal text justifications supported */
& z8 @0 i9 U( G9 A D- S" ochar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>- C+ m: m$ n" \; K6 k
<P><FONT color=#0000ff>/* vertical text justifications supported */ ! ?+ B' X4 y Q* h( S' k8 e5 u
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
2 D( |+ P0 N2 {+ h% _, b<P><FONT color=#0000ff>int main(void) / r0 R+ K- d! q+ s% a
{
1 d+ I- A" f1 z! S/* request auto detection */
0 S ^% u6 v0 p) zint gdriver = DETECT, gmode, errorcode; 3 s* {7 Z! d' i+ [, Y4 l
struct textsettingstype textinfo; ( n) l: g2 E: H) @
int midx, midy, ht;
5 k& G# d; \6 Q5 d5 t" U/ Kchar fontstr[80], dirstr[80], sizestr[80]; 4 i) w0 i1 D$ F
char hjuststr[80], vjuststr[80]; </FONT></P># P# P/ j5 f# h/ p4 V+ M
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 z0 d, }- T1 ]9 X/ W+ Z: Z W2 Yinitgraph(&gdriver, &gmode, ""); </FONT></P>$ L6 b8 w4 q1 W f8 Q2 I5 @- m
<P><FONT color=#0000ff>/* read result of initialization */ 0 P4 H8 m9 M4 ?! l1 m
errorcode = graphresult(); ) r5 ]6 e7 Q0 Z0 U! {" a Y
if (errorcode != grOk) /* an error occurred */ # V% k. h1 i5 A" m6 _1 X, E
{ ' u+ S/ G; }. J2 F9 }) U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( ~& T& a" e* P
printf("Press any key to halt:");
) N5 X3 K; H9 w& h. P' I4 fgetch(); 9 o; B) B" p( b7 ^( Z; ~7 t5 z
exit(1); /* terminate with an error code */
( w8 V& a1 Z& [, J1 F! J# E" U& J} </FONT></P>
7 k" I4 [- J s; O<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 j; P9 a/ x: c. d1 C" H# z6 tmidy = getmaxy() / 2; </FONT></P>
3 Q: @4 G' B* c* x<P><FONT color=#0000ff>/* get information about current text settings */ , I2 u6 [( b- {' V) y3 ]. Q# P
gettextsettings(&textinfo); </FONT></P>
# V k; ^7 w2 Z# R& j4 u; m<P><FONT color=#0000ff>/* convert text information into strings */
4 d) H3 Z6 i! N! ksprintf(fontstr, "%s is the text style.", font[textinfo.font]); 9 _6 a( R3 f1 B% H+ [: W
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
/ y) L/ D# D9 c9 s: fsprintf(sizestr, "%d is the text size.", textinfo.charsize);
: t( r6 X* I: D, p; Y' Csprintf(hjuststr, "%s is the horizontal justification.",
7 ?' C( a* D) Q7 ]hjust[textinfo.horiz]);
- I& z, M# d3 z0 q7 d2 C6 p6 gsprintf(vjuststr, "%s is the vertical justification.", 2 I0 z2 G1 _# q+ X6 B! n3 {5 n
vjust[textinfo.vert]); </FONT></P>1 _& n9 w8 H2 O% f. ? X, m; }
<P><FONT color=#0000ff>/* display the information */ ) h% I, k; ?7 d: U G& h! D
ht = textheight("W"); 3 n6 X( H, l8 @/ p. I
settextjustify(CENTER_TEXT, CENTER_TEXT);
# [( x0 B: a, e. |, A7 |2 s+ h& routtextxy(midx, midy, fontstr);
6 T! ~4 j1 x) Z7 M3 Wouttextxy(midx, midy+2*ht, dirstr); $ F$ s; z7 z) ]0 P
outtextxy(midx, midy+4*ht, sizestr); ! e* [1 |, G' }& Z
outtextxy(midx, midy+6*ht, hjuststr);
T2 P j% r" p- B" Q0 Iouttextxy(midx, midy+8*ht, vjuststr); </FONT></P>, }1 o/ h4 ]7 ]' X+ N3 A8 J
<P><FONT color=#0000ff>/* clean up */
/ e% o: i: W- wgetch(); - ^: u! g) u) H: t
closegraph();
) X7 ^$ I4 n( G: greturn 0;
* x' z2 r0 U3 m& B5 j) q} </FONT>
' y7 W$ ^0 r& X0 {</P>" d9 G, w/ F: ?, c8 _5 L
<P><FONT color=#ff0000>函数名: gettime </FONT>
7 O1 ~6 t6 v4 }) b' q x; I功 能: 取得系统时间
1 r, a0 f# |5 f/ p/ E用 法: void gettime(struct time *timep); * Y9 Q) z' R1 I# ~
程序例: </P>: d; U# o& \8 x0 r( k6 C
<P><FONT color=#0000ff>#include <STDIO.H>1 t6 X: e1 l+ a- u$ L
#include <DOS.H></FONT></P>/ o, X+ G! x! j: I& I* [6 P
<P><FONT color=#0000ff>int main(void) ) O3 a- e5 C: [5 K3 ~ g
{ 1 A- d; L, _# ~0 u3 s
struct time t; </FONT></P>; S( O; Y0 {! q# A' r9 t. I9 E% ^1 A
<P><FONT color=#0000ff>gettime(&t);
! z2 [4 B8 T# w( _& m# ]- |printf("The current time is: %2d:%02d:%02d.%02d\n",
- ]. w2 a. y8 l# lt.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); - t" V1 L* E$ q* B: ^
return 0;
: M: ^. U. Y5 ]+ [: r! Y, J; _8 b} 1 m/ I5 Z u0 r) P4 q+ e
. l: S! ?) R; P
</FONT>3 Q2 |8 ~" b& n
</P>
& G8 s, V1 W& i<P><FONT color=#ff0000>函数名: getvect </FONT>
% Q1 y" j7 y" H/ I0 K7 \功 能: 取得中断向量入口 ) c2 n3 K4 p1 |, l* a8 l
用 法: void interrupt(*getvect(int intr_num)); 9 _. u" X, T5 h1 \
程序例: </P>
6 m2 }5 L# S0 g& [9 m! c<P><FONT color=#0000ff>#include <STDIO.H>
+ e# x2 m8 A$ }+ T8 M3 V#include <DOS.H></FONT></P>
3 K2 Y* @0 k2 G; i9 h<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>2 l- x3 M" _& A
<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
& y, W5 _7 C6 n+ }int looping = 1; </FONT></P>
$ h# L# x: C' l' K5 o% w e<P><FONT color=#0000ff>int main(void)
" `% g9 f2 ?7 F/ W. y3 U. `& J{
* r: q8 H: \4 h8 M+ cputs("Press <SHIFT><PRT Sc>to terminate"); </FONT></P># m: |+ P# D7 m- T( ^* W
<P><FONT color=#0000ff>/* save the old interrupt */
8 l& Q9 |( u0 [+ f+ {- U$ |% zoldfunc = getvect(5); </FONT></P>& u' F: T- L$ ~1 G7 \
<P><FONT color=#0000ff>/* install interrupt handler */
6 M' M ]8 D& b7 h" r# Z$ gsetvect(5,get_out); </FONT></P>0 d0 g4 {! v q
<P><FONT color=#0000ff>/* do nothing */
s4 Q+ F- F0 Gwhile (looping); </FONT></P>! w3 s3 m& U, M" @
<P><FONT color=#0000ff>/* restore to original interrupt routine */
1 R" ]" ]: F9 f# _9 o; F L! Dsetvect(5,oldfunc); </FONT></P>
, }% U% l" C; L- A" k# h<P><FONT color=#0000ff>puts("Success"); $ j' T8 [# R8 J% ~0 H
return 0;
! F/ W% `0 u6 O$ {} / n: Z; U, M0 h& F9 P2 D
void interrupt get_out() 3 M* E% ]" Q" Y+ I
{
: W4 I: X. C$ F8 T, glooping = 0; /* change global variable to get out of loop */
6 W$ H) n2 w1 h# O, ^}
. D5 n+ g' [1 j4 W9 m6 }2 X3 {% K</FONT>
$ d( p5 Q, L. x/ G, q& n) G' b</P>5 q5 }/ h7 Y" l, r
<P><FONT color=#ff0000>函数名: getverify </FONT>5 O. ?8 A1 q; f9 H
功 能: 返回DOS校验标志状态
+ L1 |7 `* r9 g0 ] R5 a, z, }用 法: int getverify(void); ) t# W$ B$ D: n: ?+ ?( `7 U: x& e) ~
程序例: </P>
( z9 M) t2 b; h& I7 S9 |0 @6 f' l<P><FONT color=#0000ff>#include <STDIO.H>
4 [7 E9 M* i! L1 K#include <DOS.H></FONT></P>
9 i9 g* ~. f4 P: }5 `3 y% r/ `<P><FONT color=#0000ff>int main(void) ) D% J9 ?. I+ t' }1 |9 r% T# L5 ?
{ 9 N6 E; M. I* w2 Y+ i
if (getverify()) 3 i2 F" T6 `" [3 m$ U
printf("DOS verify flag is on\n"); + e; ^" I! ?( m" @
else
& n, K' _7 Q& P5 p! D" m3 m/ Uprintf("DOS verify flag is off\n");
2 E4 {, x# H7 U$ {! P4 E, \return 0; 6 r4 a- ]% r# Q* G6 u) X4 `
} 4 g8 X# b' h# g5 }% D
</FONT></P>
& S0 K- b1 U) W$ F; G8 U0 c<P><FONT color=#ff0000>函数名: getviewsetting </FONT>0 H4 `6 C; N( Z* z9 r+ t
功 能: 返回有关当前视区的信息 / S" E8 L2 v! z8 z# Y8 ^- d U
用 法: void far getviewsettings(struct viewporttype far *viewport);
, u0 a2 r5 s! {" J$ h" w# a程序例: </P>
! r+ n. a3 n( r: Z1 ?# b<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 K5 ]9 }# O& A5 L+ p9 o#include <STDLIB.H>& j! c+ G2 }5 s
#include <STDIO.H>
1 y7 ?0 q" A& H# K. d#include <CONIO.H></FONT></P>9 W9 t8 O* v7 o
<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>6 y; Q. n- Q! x
<P><FONT color=#0000ff>int main(void)
" o7 ?* D, u$ t X) U{
3 t: p# f: v: }& B/* request auto detection */
( w# ^& w, Y. H/ Hint gdriver = DETECT, gmode, errorcode;
7 n4 j0 f6 R/ ^, e) {struct viewporttype viewinfo; ! P' p4 T/ i2 _; u
int midx, midy, ht; % l7 z3 k; `9 B
char topstr[80], botstr[80], clipstr[80]; </FONT></P>7 ]; g8 P) h0 O5 S3 h: w% c" N
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . {7 s8 f0 W6 N" P
initgraph(&gdriver, &gmode, ""); </FONT></P>
2 T5 ~ y7 Z% y b6 y<P><FONT color=#0000ff>/* read result of initialization */
6 y; }& S3 q4 D4 |; ?errorcode = graphresult(); n1 K1 b( e/ a; O/ D
if (errorcode != grOk) /* an error occurred */ " h. P; N3 w5 k' J9 { ^ E! | f
{
, ^' S. G% ]) `1 c6 ~printf("Graphics error: %s\n", grapherrormsg(errorcode));
: G' h3 I3 n* g0 C$ Aprintf("Press any key to halt:"); . @& ^# v' i, ?( q5 O+ L, l
getch(); $ e* H3 G# h7 E9 P6 b! K* G
exit(1); /* terminate with an error code */
* A% W" \$ A c- N% C} </FONT></P>4 D3 v& ~2 A+ x% F
<P><FONT color=#0000ff>midx = getmaxx() / 2; # W1 F- V* y1 Y' P6 Q8 h4 l
midy = getmaxy() / 2; </FONT></P>1 ^( J' ]) c% Z& U' e# {
<P><FONT color=#0000ff>/* get information about current viewport */ . x5 K2 b5 N5 E" g
getviewsettings(&viewinfo); </FONT></P>
; y3 V( N! B4 S( I, w3 x9 ^7 c<P><FONT color=#0000ff>/* convert text information into strings */
3 R; G7 `2 m+ \8 csprintf(topstr, "(%d, %d) is the upper left viewport corner.", : C! x; z# r0 c' C
viewinfo.left, viewinfo.top);
3 q0 B- W* f" e& W1 Isprintf(botstr, "(%d, %d) is the lower right viewport corner.",
3 o" X, |; h, u8 K( Rviewinfo.right, viewinfo.bottom); $ T) R q. c5 F3 l+ l1 t
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>0 K f' p% a' ]
<P><FONT color=#0000ff>/* display the information */ 6 L5 X* r/ H1 k& x
settextjustify(CENTER_TEXT, CENTER_TEXT);
' R x/ U) \& V; n/ G# D; R# x- pht = textheight("W");
6 u2 o! V8 a) _# e* touttextxy(midx, midy, topstr);
( Z8 z3 k) @( T) d* K; U( ~outtextxy(midx, midy+2*ht, botstr); $ S; K) D/ {$ F* b. F. x
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
+ p& t# }% R! S<P><FONT color=#0000ff>/* clean up */ 2 N" x# @! y3 r) }9 o
getch();
7 K! e+ m( E- l' w1 Mclosegraph();
) L E# W/ n9 _7 l# b; Treturn 0; ( g- `: ~: U; q8 g
} </FONT>& C8 r5 q& I/ Y9 @
; ]/ }" t, ] j1 U, ^4 J5 f
</P>
4 ~8 [) C; ], o5 s6 E6 T<P><FONT color=#ff0000>函数名: getw </FONT>% F2 G8 P3 w6 w! y+ i4 V6 e! Y% L
功 能: 从流中取一整数 / J. Y% e$ H* _: w$ h
用 法: int getw(FILE *strem); 5 f1 L) V; M' L9 x4 a7 [! ~
程序例: </P>
! n& a. Z" ]# r! q Z6 M, ?<P><FONT color=#0000ff>#include <STDIO.H>8 _& x, ?1 g, f7 d
#include <STDLIB.H></FONT></P>+ A6 M; H5 o: s+ J; y0 F8 [( ~
<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>: [( U; k+ q# j
<P><FONT color=#0000ff>int main(void)
6 c7 \2 F$ y; d) e) M# Z4 G{ : V7 `) `- @( C# A6 V
FILE *fp;
( N% D( F0 _5 W8 c7 Lint word; </FONT></P>
) G8 b# O# S% u. W<P><FONT color=#0000ff>/* place the word in a file */ , ?7 i/ T5 A1 z1 ?
fp = fopen(FNAME, "wb"); 1 A U) n8 ~- i6 H. ^7 _
if (fp == NULL) 5 `+ |6 `9 N+ X
{ ' e0 b7 p$ K8 L, u$ G( d
printf("Error opening file %s\n", FNAME);
. `- ?% P# c3 d4 @0 s9 H# Pexit(1);
$ B% a, B$ B2 O8 F0 x} </FONT></P>* b. M/ m5 e: x6 q: {& U
<P><FONT color=#0000ff>word = 94;
4 X# J& o- n: J" Nputw(word,fp); 1 ~+ L& U. }, ?+ M8 U! w
if (ferror(fp)) ; j/ s) a+ @7 @8 R
printf("Error writing to file\n"); . f' |3 i" Z) L5 C
else - Q; c H( x6 U* V' C
printf("Successful write\n");
# D2 |- F& \/ O( Sfclose(fp); </FONT></P>9 V3 d. g! F( D8 n% o% A L
<P><FONT color=#0000ff>/* reopen the file */ 4 y7 P$ v6 B6 F
fp = fopen(FNAME, "rb");
% C& Q$ x# S5 r9 u7 \3 g7 h- b. oif (fp == NULL)
5 ?8 L" n5 j. J) E7 s! ?( j+ o{ / W! V) u+ S& `6 \8 ]
printf("Error opening file %s\n", FNAME); , X( i# b1 D. S
exit(1); ' @: T" J9 q" l& m& M
} </FONT></P>
7 u9 ?* L/ y& l9 Y# Z<P><FONT color=#0000ff>/* extract the word */
( k% C6 i1 m& G0 C8 lword = getw(fp); ' _% b5 J' i4 `+ Q& s) y
if (ferror(fp))
+ b0 U# P! ^/ tprintf("Error reading file\n"); 8 C2 H* A: b7 i( ]; y* a; }! K4 E
else
0 `0 o7 {$ z4 p+ W9 ?# r; Y# dprintf("Successful read: word = %d\n", word); </FONT></P>
6 A! `) _& Q$ L! H& ~<P><FONT color=#0000ff>/* clean up */
, n- ]0 [, @5 u3 ?$ q Sfclose(fp); ( c# P% C+ P3 u7 {. X; h& f2 a$ H+ h
unlink(FNAME); </FONT></P>0 t3 F. h, X! _. z/ G
<P><FONT color=#0000ff>return 0;
: A* N. g6 X Q" {3 F( {} </FONT>" q( m) s. e8 W+ u0 ^- F
: Q- _: ^# ^0 v" v- N: m
4 a4 f, M0 X$ h# i S! a9 H& ^</P>
' Q5 P* d/ k6 P. v; N |<P><FONT color=#ff0000>函数名: getx </FONT>+ W4 u6 I: a5 O5 @, E9 i% r" E' q
功 能: 返回当前图形位置的x坐标 f& ]1 K3 K+ a% B; Q
用 法: int far getx(void); 0 y- z3 D0 t# X" E, \6 Q! W5 B
程序例: </P>) h5 c4 _5 q: r. o0 i' }- R. c
<P>#include <GRAPHICS.H><FONT color=#0000ff>
) X$ X& y& z3 H5 ?; ^: M1 U#include <STDLIB.H>6 r7 O# c. H! b3 f! j/ e0 G
#include <STDIO.H>9 v! N" c( u9 h* K
#include <CONIO.H></FONT></P>
+ ?1 G7 Q' L ~5 Q7 G* ^( u3 s<P><FONT color=#0000ff>int main(void)
/ Y& W& j' p; a9 y2 u. ?# T{ / ^; D' B) O0 c! b( N- \$ e
/* request auto detection */ - k# D/ t' C# P) B" z+ @
int gdriver = DETECT, gmode, errorcode; ; c- A, P! E! G% x
char msg[80]; </FONT></P>
2 D1 G, m5 x7 q9 p" I<P><FONT color=#0000ff>/* initialize graphics and local variables */
# M+ W7 |! h. C+ Rinitgraph(&gdriver, &gmode, ""); </FONT></P>, e' b! |7 |' A! y0 m
<P><FONT color=#0000ff>/* read result of initialization */ . _; @7 _) o' E7 \0 N; h" y" I
errorcode = graphresult(); ; x. X8 T3 h# v
if (errorcode != grOk) /* an error occurred */
& y+ u" L. Y/ e* H: x# u{ 4 P, \) q9 C7 y) G5 |
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % G+ f2 }" Z; c
printf("Press any key to halt:");
8 V1 ~) n' {4 W6 y+ j; Qgetch();
+ Z8 B" {, p# Q/ _* a' Rexit(1); /* terminate with an error code */
+ `# { @( A' @! L( c} </FONT></P>. V! Z7 H u! z' V* k* p1 t
<P><FONT color=#0000ff>/* move to the screen center point */ / n/ b1 e0 J) N0 Y7 S9 ~
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
' @4 `, g3 d3 a; N# R) l<P><FONT color=#0000ff>/* create a message string */ % C' P( g3 N, H+ H& a- W0 E0 G
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>6 H9 ?8 t- ?0 U$ x! U
<P><FONT color=#0000ff>/* display the message */ ; a g( @ C( n6 H3 Z# B- q6 b
outtext(msg); </FONT></P>
, U- K1 D9 q4 E9 A0 o/ L; z<P><FONT color=#0000ff>/* clean up */ & _% i" L1 Q0 \! @0 v r2 h% m' [% L
getch(); . Z# |$ g# w) D) y2 G- y+ Z
closegraph(); {% |3 ~1 e6 x9 ?6 ^
return 0;
, Q# X: S. L8 M} </FONT>
! a6 _, f$ m) B( e# e O: {7 J$ f1 u) _' e# _ f9 ?1 z% _% w
</P>
: N5 g& I" G1 y ~7 t" }& n<P><FONT color=#ff0000>函数名: gety </FONT>( c9 f- x! R+ b
功 能: 返回当前图形位置的y坐标
& {* {7 V4 k1 |用 法: int far gety(void); D' u- {- h+ @ I" x
程序例: </P>
7 W5 X+ C7 g: ~! s7 y4 n<P><FONT color=#0000ff>#include <GRAPHICS.H>& g3 ` B3 F6 ~ L% u. Y3 }
#include <STDLIB.H>
2 q" C3 L1 B* f3 y u#include <STDIO.H>
/ U* x/ N7 G8 J#include <CONIO.H></FONT></P>
" K( s0 M" h; M+ `* {" x<P><FONT color=#0000ff>int main(void)
" }( _: l, Z' n" u8 o- P* k{ , j2 a; A# p8 H$ d
/* request auto detection */
& o6 ^) l* v! S6 U, \int gdriver = DETECT, gmode, errorcode; 7 R* k- N6 i* p+ G% B
char msg[80]; </FONT></P>
7 q' c% ?" T% R; }, `<P><FONT color=#0000ff>/* initialize graphics and local variables */ * D4 g7 K( J8 k! k+ _0 J
initgraph(&gdriver, &gmode, ""); </FONT></P>
0 b) L0 r/ k+ T. |; k$ j# T<P><FONT color=#0000ff>/* read result of initialization */
' }& L; i- ]5 |& W8 cerrorcode = graphresult();
8 G5 ~' h& g$ Q5 gif (errorcode != grOk) /* an error occurred */
' H$ P; U9 \4 ~# F( Q4 D{
$ |. v1 j3 b- a( S" D' cprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" I! _- I8 Y3 k. j8 qprintf("Press any key to halt:");
8 z+ }+ Q2 k; u7 j. [( m5 Wgetch(); 1 ?9 v. e0 B5 J, b2 R4 P% }
exit(1); /* terminate with an error code */ 2 r3 y6 Z" n; I2 j8 o+ K) \ Y
} </FONT></P>
' y/ h& e6 ^; R: R2 B2 Y<P><FONT color=#0000ff>/* move to the screen center point */
0 U7 P* V4 r1 J( O4 Emoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>% |5 l1 L4 J" S5 P+ u5 J1 P D, `
<P><FONT color=#0000ff>/* create a message string */ ! H' _1 V. s" h$ t U! l6 w
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
0 \0 U1 i: K) Q7 X$ d<P><FONT color=#0000ff>/* display the message */ % g& q% O' k/ E; S+ b; P; x
outtext(msg); </FONT></P>
# B N5 U) ?% V, i<P><FONT color=#0000ff>/* clean up */
) |! c: J, H8 wgetch();
! ?* V( l$ C5 e1 ^% J! n- s$ K% x% ~closegraph(); % L s- ~) ~0 R5 A
return 0;
( e6 {7 ?8 a% V6 v# F3 U} </FONT>
7 w( H& ]9 S) I* p. W% P
$ O+ S6 h- P {" B! }) ~$ q# {4 L0 t</P>- Z. C! J& H( C& F/ J/ A) j3 s5 N
<P><FONT color=#ff0000>函数名: gmtime </FONT>
3 a2 F! f1 F. X' C3 p功 能: 把日期和时间转换为格林尼治标准时间(GMT) , r5 v5 z2 v5 p, [& l
用 法: struct tm *gmtime(long *clock); : f# E/ m! N S3 k
程序例: </P>
# \5 ]' _' G6 `+ ]<P>#include <STDIO.H><FONT color=#0000ff>: p# i3 A8 I7 g& |+ H2 c
#include <STDLIB.H>' _+ D U/ J% D
#include <TIME.H>/ H; l5 f0 r. ]9 r* B
#include <DOS.H></FONT></P>
& X$ H; [# J, U- s9 U<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */ $ K# u/ d5 N# a1 C* i6 v* ]
char *tzstr = "TZ=PST8PDT"; </FONT></P>; I" }2 [7 p! V/ l2 ~
<P><FONT color=#0000ff>int main(void)
* j/ f9 i3 I8 G" R6 T: k{
. _* }" Q2 Z4 qtime_t t; 0 G: K' j0 d, L# V0 n
struct tm *gmt, *area; </FONT></P>( w2 a/ q v& {' Y; d
<P><FONT color=#0000ff>putenv(tzstr); 0 }8 F8 @) s* x5 U% a* U& I
tzset(); </FONT></P>" [* a* _; h# F: I
<P><FONT color=#0000ff>t = time(NULL); - M0 e) E5 X) `) W* u# f2 A
area = localtime(&t); 4 {( M( [4 P7 Q. a
printf("Local time is: %s", asctime(area)); 3 {5 K6 c0 y# l9 z& y" H4 r
gmt = gmtime(&t);
) v, D0 u( v! m$ g6 M* D+ Uprintf("GMT is: %s", asctime(gmt)); & e; F3 Z3 X8 e8 k
return 0;
, V* R( K! J6 i* Z6 i# S- l# S} </FONT>
5 Y0 W# `4 z) t1 r
0 E2 c0 b+ D5 V8 M! @/ J</P>
% A2 i% \% X1 F K8 v<P><FONT color=#ff0000>函数名: gotoxy </FONT>
5 G) a$ A8 l% I功 能: 在文本窗口中设置光标 ; u' @$ ~/ i5 A+ B. z
用 法: void gotoxy(int x, int y); 1 b( y0 E- e0 Z9 ?9 G1 r2 y
程序例: </P>3 O" D, V$ R! ~- g0 d* p0 X
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
5 ]% v5 h' N/ ?8 B, ~1 X<P><FONT color=#0000ff>int main(void)
# |! j/ q$ x. d( E" j) M{
2 J7 p+ K$ j+ ^" yclrscr();
2 g& E6 A! ]: R4 kgotoxy(35, 12);
" J, X* |; E# }2 y/ V& J1 G2 U+ k% A% Qcprintf("Hello world");
1 I, N% f/ n7 |. h' y6 `" \getch();
* h; `8 q1 B! wreturn 0; ^" Q I2 R8 m6 v1 D$ N2 r% x
}</FONT>
1 Y; {) U7 a$ h7 j# Y0 m- ^1 V# P$ n
</P>
" b8 f q0 M& s) Y9 h9 D3 a! V<P><FONT color=#ff0000>函数名: gotoxy </FONT>
5 Y! N! r" Z5 y功 能: 在文本窗口中设置光标 / R X+ O( K9 h9 M- @5 y X( c
用 法: void gotoxy(int x, int y); 7 o) r$ O+ c3 N! X# R. A
程序例: </P>
8 A. h& W8 X! ^4 a9 }<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>& k9 O/ Y& m0 Q$ J( X3 O
<P><FONT color=#0000ff>int main(void) : T2 }9 F) Y, F6 _. n- B
{
1 G2 }# D8 |* zclrscr(); + R, L* k) b. R
gotoxy(35, 12); 9 n& Y2 S5 ]% F! i
cprintf("Hello world");
9 k& h/ \- Y5 ?4 W9 e" d+ ^getch();
) H0 `6 ?( R% E& creturn 0; 0 ~9 Y7 D5 V; m- x. y+ D4 h$ ?
} . B3 |5 ]) z3 x/ U' r4 K
</FONT>
' i' W% a$ v$ Q& E1 Y( {. N- o</P>0 o$ D5 m9 L2 ^/ u6 F
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
, A) J; R% }5 j6 t功 能: 将所有图形设置复位为它们的缺省值 ; m" @; F* c' Y. T$ E) A
用 法: void far graphdefaults(void);
3 m1 Q9 ] ]; i" _程序例: </P>8 J2 y3 W& T1 c4 d1 y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* D5 M3 |; e- o+ z$ m* _#include <STDLIB.H>4 }$ X0 u: r0 H( e$ _' M9 [
#include <STDIO.H> }1 N2 }& Q3 v# E2 y( S& y
#include <CONIO.H></FONT></P>! f ?7 t3 _0 v2 c$ G
<P><FONT color=#0000ff>int main(void) + w( y) i( F' l5 N# v3 F
{ , S# S% s3 j7 R8 K% {
/* request auto detection */
1 r \$ E R$ V/ V3 f$ Qint gdriver = DETECT, gmode, errorcode; & ~! f" ^' A/ B) b) J$ M
int maxx, maxy; </FONT></P>
2 h1 o$ w! T' c ~, {" K<P><FONT color=#0000ff>/* initialize graphics and local variables */
, M0 D0 a9 |$ @9 E6 dinitgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
9 p% e- _' L L4 D: J- U6 j<P><FONT color=#0000ff>/* read result of initialization */ $ O F i! ^- q- j' f
errorcode = graphresult(); . S y) e9 D( [ s
if (errorcode != grOk) /* an error occurred */
: y4 s2 a7 d( p9 \{
" [1 B$ H# x5 t# d' N4 i% U$ P- Eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' f, t9 O9 i4 K: Z. ?printf("Press any key to halt:"); * n! _/ O% _1 g7 ~
getch(); 4 B! t: ? R: I* S/ S
exit(1); /* terminate with an error code */ 7 p7 l, O4 u) p" n7 [8 j& K6 O8 \
} </FONT></P>' ?( h; P1 Y0 e) ^$ ?; w
<P><FONT color=#0000ff>maxx = getmaxx(); " ]- X" b: t$ b7 D, @" b
maxy = getmaxy(); </FONT></P>8 Z! ^6 |( U" i
<P><FONT color=#0000ff>/* output line with non-default settings */ ) \1 _6 k3 E2 p9 D0 J, _% T' K5 Z
setlinestyle(DOTTED_LINE, 0, 3); 1 F% C- O! ~5 c: K; a
line(0, 0, maxx, maxy);
5 W1 x% E- }6 Z/ B O N& aouttextxy(maxx/2, maxy/3, "Before default values are restored.");
* \! A, s6 { ?getch(); </FONT></P>
+ N' @$ @7 ? p4 @/ t<P><FONT color=#0000ff>/* restore default values for everything */ ' {# x7 \5 K' ]0 M
graphdefaults(); </FONT></P>2 U+ H g8 ~+ z0 y. H* a
<P><FONT color=#0000ff>/* clear the screen */
2 ~4 Z0 G6 C( N* g# a* |cleardevice(); </FONT></P>
4 G+ N% K% O& A1 _<P><FONT color=#0000ff>/* output line with default settings */
4 R) Y& D1 ]) q+ w C o Y7 ]line(0, 0, maxx, maxy); - Z% D/ w0 s5 s
outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
+ Q# W3 _- Y: `& t$ S<P><FONT color=#0000ff>/* clean up */
4 `8 K" B1 ^2 M7 I8 T% ?getch();
* h) l7 ~- D3 Fclosegraph(); 0 z8 p( ^ E$ f( \2 s
return 0; " M- s! h' j/ { t* U, ^" z
} 0 v( R5 F5 Q/ W5 K
</FONT>
5 K9 L; r6 w; ?$ h6 w4 U</P>
+ L) J3 F' v: o/ @/ z. X/ F, Y<P><FONT color=#ff0000>函数名: grapherrormsg </FONT> U% M- f# _% m$ e; i- x: L% D5 E. q& z
功 能: 返回一个错误信息串的指针
0 u1 ~3 {% r0 A& }( ]+ K' q用 法: char *far grapherrormsg(int errorcode);
0 @2 s) L. I* m/ K2 q程序例: </P>
3 z2 N& n6 G6 B l: x. o" b<P><FONT color=#0000ff>#include <GRAPHICS.H>1 \, m6 a/ o2 x1 m
#include <STDLIB.H>/ `; \- L! F$ _7 }9 _& F
#include <STDIO.H>
2 H3 |( m1 j* T* |#include <CONIO.H></FONT></P>
) B I/ w! Z0 j3 a6 H7 ` u* N<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>: _ B B) T5 T, T1 H
<P><FONT color=#0000ff>int main(void)
( p3 a; j. _" f7 K{ 3 s0 w3 }# _4 `* F- z* C# j
/* FORCE AN ERROR TO OCCUR */ % @; t0 h4 m6 z/ j8 s/ h7 M
int gdriver = NONSENSE, gmode, errorcode; </FONT></P>
. I7 d! Z/ |& c8 b* V<P><FONT color=#0000ff>/* initialize graphics mode */
2 P: E* R/ O* O P: G' Dinitgraph(&gdriver, &gmode, ""); </FONT></P>4 M% l' l. W% u( W( H9 e4 Y1 k
<P><FONT color=#0000ff>/* read result of initialization */
* j' f# @3 r2 U: y' Oerrorcode = graphresult(); </FONT></P>/ a% O( {* @4 D
<P><FONT color=#0000ff>/* if an error occurred, then output a */ : Q5 D. B% Z# V
/* descriptive error message. */
/ M, H( f. H- M: I R/ i3 Jif (errorcode != grOk) 6 W/ `6 J/ ]7 ]8 I
{
" I, ^7 D# v/ hprintf("Graphics error: %s\n", grapherrormsg(errorcode));
/ a( j, I/ B( oprintf("Press any key to halt:"); ; q0 ^0 j- V, F# P; E
getch();
$ n" ^& X1 Y, gexit(1); /* terminate with an error code */
% e G! d0 z; j; A1 v2 z} </FONT></P>
* H; i& b# t( _" b) L" h<P><FONT color=#0000ff>/* draw a line */
0 Y" ^) U" T) y. ?; Vline(0, 0, getmaxx(), getmaxy()); </FONT></P>% e( j. }' `: l9 ^
<P><FONT color=#0000ff>/* clean up */
& z. `, Y/ H* Q* ~2 x" J9 \getch(); % q V2 ], J0 b3 O5 S
closegraph();
4 \! _; w/ K/ H3 i9 u" Xreturn 0; 1 H9 n% x2 `, i
}
4 d- ]% q* b1 b- j</FONT>: d. `$ W- |! F2 Y: S0 p
</P>
* R3 \& u$ A2 y0 `<P><FONT color=#ff0000>函数名: graphresult </FONT>) a! P4 v+ c# R! i% Q) Q% I
功 能: 返回最后一次不成功的图形操作的错误代码
: [5 r: l5 w( `2 j, Q4 V用 法: int far graphresult(void); , R( j- i( z/ i5 G
程序例: </P>* P7 F9 B2 `9 u
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; M& V6 Y; r8 G6 O, o#include <STDLIB.H>
/ B% Z' h* R9 H0 u6 t* Z#include <STDIO.H>3 ~" @% r8 l: \; a& P. K o/ r
#include <CONIO.H></FONT></P>: ^# {/ _' v) K' Q2 C2 R! W
<P><FONT color=#0000ff>int main(void) 3 M+ M9 Y6 r; S# {$ y6 m0 d
{ 8 N- N. i3 ]. M+ @' E
/* request auto detection */ $ g5 ^1 R) e( |
int gdriver = DETECT, gmode, errorcode; </FONT></P>
4 Y" I0 D1 t# z; y- r<P><FONT color=#0000ff>/* initialize graphics and local variables */ " t: i7 ?- m2 {6 I* ?/ a
initgraph(&gdriver, &gmode, ""); </FONT></P>
' b, Z+ L3 x: `) w+ V+ R3 K u<P><FONT color=#0000ff>/* read result of initialization */
" P8 {5 U( Y# e8 J8 Kerrorcode = graphresult(); </FONT></P>4 U* @" k& q8 z
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
) Y. N$ ~; b! k{ ; ?" ~& _4 k& m
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 t1 N! V. i( W$ u! }- |printf("Press any key to halt:"); % e& P5 m O( i% k3 X* ]
getch(); ; G; t: S% w4 A. k7 r
exit(1); /* terminate with an error code */
, F! v+ G# ^1 V1 v3 @' v1 g. b0 R} </FONT></P>
# {; ~6 t3 ?2 E/ j5 g# |/ ~$ Q$ |( W<P><FONT color=#0000ff>/* draw a line */ : o0 ~$ p0 d; H8 `5 O
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
* D& S/ N) T+ s: w. h- E<P><FONT color=#0000ff>/* clean up */
! R, [( m: }; H9 D; e( hgetch();
3 ~3 L& e& [0 s& g% p" y( Wclosegraph();
+ {9 c, D. V4 f/ D3 {# c0 L0 l8 G( Ureturn 0; 8 A' K9 ^, o: d
}</FONT> $ J: ~7 \5 O s
</P>9 ^( J$ l q% C0 I% J
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> 5 `- x( y5 A& W4 o2 M
功 能: 用户可修改的图形存储区释放函数
! K( M& o) p o3 t用 法: void far _graphfreemem(void far *ptr, unsigned size); : u$ s; C R- S- K1 Q
程序例: </P>0 b, n. m; f4 [! X( O
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; ^: l$ |3 `. U% d5 v#include <STDLIB.H>8 G0 D+ h" {; @& J6 X- D+ ~
#include <STDIO.H>
. f0 L( _( M7 K0 j#include <CONIO.H>
; V, k6 Q$ [6 p3 t( ~9 b. p$ ?5 t6 Z#include <ALLOC.H></FONT></P>2 [# f' r; R2 p4 B2 @
<P><FONT color=#0000ff>int main(void) * u2 P3 Z5 r# s( h' V
{
/ b m, Q @/ f: f1 g) C, [+ q/* request auto detection */ 1 E: A* X; B. \; w
int gdriver = DETECT, gmode, errorcode; $ |: d+ {2 ^% q; R8 s( Q7 M: c
int midx, midy; </FONT></P>
: I& [( x. ]/ ?' t F3 U<P><FONT color=#0000ff>/* clear the text screen */ % y' b/ X# A. Y$ _4 ^- C' |
clrscr(); ! Y0 A) V7 I$ |- ~) I, j/ d
printf("Press any key to initialize graphics mode:");
( I8 X1 G+ z% vgetch();
$ P3 H! [" g2 Z% K n% d" z+ \+ Cclrscr(); </FONT></P>
# _9 [9 ?) f0 _. ?" H<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) e5 @) f2 b. x
initgraph(&gdriver, &gmode, ""); </FONT></P>, r* v. b! t- e o, f! ~
<P><FONT color=#0000ff>/* read result of initialization */
& E7 k2 m7 U, k- B( `7 e cerrorcode = graphresult();
: e# g, p. I: F8 N# n6 wif (errorcode != grOk) /* an error occurred */
) F/ ?8 A. f; \5 c8 U1 e{ ) ?3 K' n- c; G% i
printf("Graphics error: %s\n", grapherrormsg(errorcode));
C. e% q& I1 R0 wprintf("Press any key to halt:");
' X8 G# X {5 o. F" pgetch(); 9 }/ M! Y6 ^8 x- M$ Q# a' z
exit(1); /* terminate with an error code */
c" S c+ O" g" \* I) X; C} </FONT></P>4 h# i$ p) b5 d6 [5 q% M$ j
<P><FONT color=#0000ff>midx = getmaxx() / 2; ' E5 M+ p: p& r% \
midy = getmaxy() / 2; </FONT></P>$ G, h0 g) W$ @/ ]
<P><FONT color=#0000ff>/* display a message */
$ D: H0 S' {# s* M4 ^) f8 m6 w k9 gsettextjustify(CENTER_TEXT, CENTER_TEXT);
) V2 r# q n) G$ a0 {2 Z& Jouttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
( h: ?( J; G: T9 i0 ]& ?<P><FONT color=#0000ff>/* clean up */
. O+ ]8 Y# l6 u' ]: agetch();
2 u+ k9 B3 D$ i) B* U7 {, [closegraph();
% S9 `; b: k; g6 u/ _return 0; ) D$ }/ \3 {1 m$ ~3 m# S
} </FONT></P>
5 s0 }+ |% U% u% d# i/ \- A<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ " z0 ^, c+ I# K1 i; l% x; W
void far * far _graphgetmem(unsigned size)
+ C; F$ U) l4 i( x{
5 ^# o1 F: Z! e8 \, U* t% zprintf("_graphgetmem called to allocate %d bytes.\n", size);
: l% n9 D4 N$ A- p% V8 N5 e& R; @printf("hit any key:"); & U( t4 W9 _9 c# b: ^: R" N
getch();
" I- p& I( w2 ` lprintf("\n"); </FONT></P>) j8 n( g! {' Y4 `( G
<P><FONT color=#0000ff>/* allocate memory from far heap */ ; M7 `: x3 Y; z0 r
return farmalloc(size); , ^9 G* N# ~) q; y4 S8 ]" }
} </FONT></P>$ q! s9 C* t3 Z. `1 _ q2 D
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ / P4 W5 i# Z( G% K, S6 L
void far _graphfreemem(void far *ptr, unsigned size)
; Z6 V% d' ]0 }# U( g! F) O1 {2 g{
+ K9 k7 G/ h- U& hprintf("_graphfreemem called to free %d bytes.\n", size); 5 h* @7 o/ E! m7 E5 j" p
printf("hit any key:"); + d5 w, @9 `# h$ h- k U
getch();
1 K; g; w$ m. qprintf("\n"); </FONT></P>
+ }( L" Z4 Q) \6 I: P<P><FONT color=#0000ff>/* free ptr from far heap */
9 D& ]! ~# \2 Q+ G+ i8 Hfarfree(ptr); + M$ E& j0 |3 z7 y
}
' C7 O, z! L3 ^6 O8 s$ A</FONT></P>- {; r& t, t/ u
<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>; g y& U6 a$ D. S( z& p$ A
功 能: 用户可修改的图形存储区分配函数 8 _- U2 a" N, p- d
用 法: void far *far _graphgetmem(unsigned size); + v: R! x( o; X
程序例: </P>
- S% e/ }/ G+ `3 f {3 F* t8 _4 e# R<P><FONT color=#0000ff>#include <GRAPHICS.H>$ B) l! P5 n: e% k# N1 u
#include <STDLIB.H>) o1 Z' Y" E: d+ w
#include <STDIO.H>
8 p) _( }& c- M5 p0 u! s% e& u#include <CONIO.H>
$ e' m% ~. N u. |( H#include <ALLOC.H></FONT></P>
1 h; T1 q# r4 q+ f B2 y' s7 y5 @<P><FONT color=#0000ff>int main(void) # H, N5 C* d$ m& `1 r" Q
{
: [* a2 |; M! r# v6 ]. o/* request autodetection */
4 W: b2 Q( q, z# @8 \% P4 N* a6 b% |$ Hint gdriver = DETECT, gmode, errorcode; ! s- Z$ n9 h7 I1 r3 l; e
int midx, midy; </FONT></P>
8 p) W$ g6 p) w% y& u1 h8 Z<P><FONT color=#0000ff>/* clear the text screen */
; }% D1 N5 k8 `clrscr(); & \' i2 B, W- }9 I
printf("Press any key to initialize graphics mode:");
: p; |( _; Z/ d+ @' ^& ogetch(); 5 u2 [9 R3 Z U
clrscr(); </FONT></P>
! q: P1 G: H! p$ p# [8 I<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ N. v7 X- n$ }7 H7 I0 { Rinitgraph(&gdriver, &gmode, ""); </FONT></P>2 k8 l3 u9 b0 o. C, l D
<P><FONT color=#0000ff>/* read result of initialization */
) d" v- e( y( ?7 | }errorcode = graphresult(); 4 `7 j6 e0 [" |; `5 c5 |1 O
if (errorcode != grOk) /* an error occurred */ % N' t" [1 \2 ~/ V, @5 k" i5 w
{ - R6 ]" V, L) G
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . p( @4 u9 [- @) Y% g9 m& i
printf("Press any key to halt:");
8 X+ _* r7 V! n! l& ]' Lgetch();
7 e, o8 K; Z( X5 @; Mexit(1); /* terminate with an error code */ 5 r: n1 H7 p: }$ l4 u% F" }1 z
} </FONT></P>" I5 x% {/ }' }4 T
<P><FONT color=#0000ff>midx = getmaxx() / 2; * C8 `1 \0 |9 Y& [! U
midy = getmaxy() / 2; </FONT></P>
, q6 e3 V9 Y2 j8 e! x<P><FONT color=#0000ff>/* display a message */ " V0 L& X2 w( P) s4 W& j
settextjustify(CENTER_TEXT, CENTER_TEXT);
8 V2 z0 H9 Q8 Q+ Y, m i. H8 souttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>7 a, A2 z3 R+ i0 W
<P><FONT color=#0000ff>/* clean up */
5 f4 v, U$ x, M- Bgetch(); : n# T% x4 ?1 l7 q* {4 M
closegraph();
# M% f* N8 x7 X8 g! @* mreturn 0; & d# w: Y, e5 A: F
} </FONT></P>
; P" w( A/ t, f; u<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ ; s' z7 h9 T! U4 o( F
void far * far _graphgetmem(unsigned size) ) _( ^* R* m- J8 S$ b7 [: c5 r* q
{
* g1 D; d) N& A. S" \+ c, pprintf("_graphgetmem called to allocate %d bytes.\n", size); ) [3 e! f8 r H& F$ _. c9 S6 e/ h( r9 D
printf("hit any key:"); / D0 n& Q9 e9 r2 M N+ I# ~' _. {& E- J
getch(); . H9 i. j @' H& T2 v/ N6 J
printf("\n"); </FONT></P>! _" U% K5 G* Z5 u" ^
<P><FONT color=#0000ff>/* allocate memory from far heap */ ! _) j8 w& L8 u' i2 b4 K; q
return farmalloc(size);
1 o& j; p$ ]; f% g* a} </FONT></P>
+ Q4 w+ V& {, ]9 o8 U0 I5 u<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
! P) ] N$ \( |' k& ~void far _graphfreemem(void far *ptr, unsigned size) ' X/ o7 Z& e8 d A. d( h4 N" M, j
{ % Z) A% \) H* n
printf("_graphfreemem called to free %d bytes.\n", size);
! H6 p" U' h6 z, kprintf("hit any key:"); ' a, s4 M! N. s# q) V* Z
getch(); 9 @3 G0 z, v' P8 D! k* s
printf("\n"); </FONT></P>
7 i* k: _0 {4 i" K2 H<P><FONT color=#0000ff>/* free ptr from far heap */ / b' H. @' s; {1 _. Z
farfree(ptr);
: q8 C6 |4 Z2 ^; F/ o4 H}
) @5 V! b; D$ H* ? k6 W V6 t</FONT></P> |
zan
|