- 在线时间
- 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>
! Q! m# U0 h5 _0 ~5 N- G
& P4 x) D" G# q8 Z. ~9 [2 Q" T) t# V+ W5 @
<p>% H$ n& e% l& M! H
< ><FONT color=#ff0000>函数名: gcvt </FONT>
; ~8 {$ E; M8 w功 能: 把浮点数转换成字符串 2 p% W8 V6 Y* d
用 法: char *gcvt(double value, int ndigit, char *buf); $ G: P9 X; L" g; c, A" e1 v, P5 Q
程序例: </P>: u5 u' p- B+ ^3 M
< ><FONT color=#0000ff>#include <STDLIB.H>4 j' E- h8 V( U# b- X9 o$ t
#include <STDIO.H></FONT></P>
8 D2 W7 D6 [2 F8 u8 K3 d< ><FONT color=#0000ff>int main(void) ' C& b9 e9 t( S* @& G
{ ( v2 w* [3 V- l
char str[25]; 2 i8 U) w$ E- q) _
double num;
& T, O9 y/ q5 E7 p+ A' {, kint sig = 5; /* significant digits */ </FONT></P>* B! z* }# v f' L& _
< ><FONT color=#0000ff>/* a regular number */ d5 W- \4 B6 z% A! ?/ }
num = 9.876;
b0 A4 x* r: M# |& A+ L4 vgcvt(num, sig, str); % u2 t! g( v; t8 W, o4 e
printf("string = %s\n", str); </FONT></P>* }9 I( c D" D% E* P" J
< ><FONT color=#0000ff>/* a negative number */ 4 R) N( v: d! N/ Q
num = -123.4567;
) W' W8 L% e) T) ~5 ?/ t, E2 n4 Lgcvt(num, sig, str);
h! y* P( U7 w F" K7 i& Uprintf("string = %s\n", str); </FONT></P>
" Y1 G& {2 r* p" r) L< ><FONT color=#0000ff>/* scientific notation */ + V5 F) m. `0 ]& c, P1 w2 m
num = 0.678e5; G: C6 _/ |$ |6 c4 v. [4 b
gcvt(num, sig, str); 3 R, F) c, o7 _& {+ t
printf("string = %s\n", str); </FONT></P>
7 D/ \6 W7 W9 N5 P x# R< ><FONT color=#0000ff>return(0); 1 I; i# H) }7 C; t3 U
}
% ?0 n) C/ q5 H. Q) ~! W
! M( R& T i# h; P4 P$ |+ ~/ ]</FONT>
" c6 Y$ \/ O! x; l</P>
- o4 X7 F: R7 r* ~< ><FONT color=#ff0000>函数名: geninterrupt </FONT>' y: s" A4 ?+ C, @+ \6 v
功 能: 产生一个软中断 ' P, y- v$ E! M/ i$ o
用 法: void geninterrupt(int intr_num); 3 R9 |( m0 r* a; |7 L' J) ^& i
程序例: </P>9 F* e' X, k+ e0 Y) [9 O
< ><FONT color=#0000ff>#include <CONIO.H>9 M7 a3 u/ k. P3 c0 {/ N
#include <DOS.H></FONT></P>0 B* P3 }$ s% m- X5 E! y
< ><FONT color=#0000ff>/* function prototype */ ! ~3 B* e: y5 `& i
void writechar(char ch); </FONT></P>" A( k0 t, x, ?+ P6 Q( W
< ><FONT color=#0000ff>int main(void) 2 d! Y$ ^6 @9 W1 h6 E6 s
{ 0 H) u! _$ ^2 i& J9 T$ e
clrscr(); 6 t8 M2 N" T: n3 c* X$ T% H; h4 S
gotoxy(80,25);
* I( P& A7 L4 x3 }) |& @. }% V! T8 o) \* Pwritechar('*'); 5 B# l1 n: [( K7 j5 f1 G9 ^
getch();
9 k' T: R/ e+ U/ qreturn 0;
0 } Q" ^3 s! i n8 X* @8 t} </FONT></P>0 f' u4 N( V: i4 y+ I2 l
< ><FONT color=#0000ff>/* 0 i+ w O" f9 I' t! t0 H
outputs a character at the current cursor
5 Y, i4 Y+ ~9 A! E, t9 Y0 }# fposition using the video BIOS to avoid the
6 I4 I! e& r7 |, }scrolling of the screen when writing to 4 V$ ^- M& e5 d% ^: e
location (80,25).
7 @- l% Q3 [& |*/ </FONT></P>
+ I6 p) R4 q. R( u# G7 u< ><FONT color=#0000ff>void writechar(char ch)
c+ X' V" E9 @# v+ {{
7 f# P; j. C' |* q, hstruct text_info ti;
' H8 G$ ^, g/ S; A/ l9 I$ X9 k* _$ i/* grab current text settings */ - P2 b$ h0 d4 f8 d0 H
gettextinfo(&ti); . R! e' L$ L/ I+ Q0 S6 p
/* interrupt 0x10 sub-function 9 */ & o I2 Q+ |* j" E8 t3 }4 x
_AH = 9;
- @* R" u$ a1 y1 Q/ h6 O/* character to be output */ " g j' ~# N& `0 i- u3 f) [
_AL = ch; : U2 k5 |. a8 @; E
_BH = 0; /* video page */
1 F3 `, N6 h7 _, ^3 f_BL = ti.attribute; /* video attribute */
K6 q: g( d/ }6 A4 m_CX = 1; /* repetition factor */
3 ^$ `* A% i2 O5 a# t' n' Vgeninterrupt(0x10); /* output the char */
' W7 I, n, V/ a1 _* O: O6 ^ e. o% y}
: E: @5 b/ P$ R G @1 R, r</FONT>
3 a; e/ s3 ~8 o1 ?</P>+ n; m" ?! P6 a( }$ {& L+ m
< ><FONT color=#ff0000>函数名: getarccoords </FONT>
8 D% s( W6 f) R' o$ Q: e4 T; E功 能: 取得最后一次调用arc的坐标
8 j6 P8 T7 t: h8 T2 H用 法: void far getarccoords(struct arccoordstype far *arccoords);
2 j- T3 r) X, t/ t0 O9 \' g; S程序例: </P>; N# x! S8 {5 l/ W2 W6 c, z% Q
< ><FONT color=#0000ff>#include <GRAPHICS.H>0 S$ s* n2 o5 p/ J. W/ R; a: v b
#include <STDLIB.H>
z- j0 d) d6 |! ^: O: ^1 O, Y#include <STDIO.H>
0 H; I) b M( ~5 @5 I#include <CONIO.H></FONT></P>
3 ^3 N" o7 x; c# ^/ C< ><FONT color=#0000ff>int main(void) & m6 N0 h9 D* |9 @, y; l
{ / b! }. T$ `5 z
/* request auto detection */
1 C1 U) j- S) E3 r. zint gdriver = DETECT, gmode, errorcode;
8 ]) S( @/ m, C$ H+ T' Mstruct arccoordstype arcinfo; # _) m3 x, x( q; J
int midx, midy; W7 D& i! k( ]9 D+ W
int stangle = 45, endangle = 270; 6 e- i5 d* N% l: w3 r1 w* @
char sstr[80], estr[80]; </FONT></P>
5 w A" ^/ y3 @- }8 s, \3 `< ><FONT color=#0000ff>/* initialize graphics and local variables */
9 v7 u; Q$ M; s2 W) Jinitgraph(&gdriver, &gmode, ""); </FONT></P>/ X1 }0 S# X5 |& l0 v* v
< ><FONT color=#0000ff>/* read result of initialization */
: e3 Q! M8 B' Q8 \- Kerrorcode = graphresult();
3 @! N2 |8 Q0 S3 W6 {; `/* an error occurred */
+ _* m1 y0 @* eif (errorcode != grOk)
5 z7 D S& F5 U K5 `2 G{
' I4 @$ }. r$ ~5 t4 Uprintf("Graphics error: %s\n",
/ A/ z9 I& N% M! q# t: [grapherrormsg(errorcode));
5 h( q( s d2 ]( U$ vprintf(" ress any key to halt:"); 7 w! p0 n$ w1 M( E5 R) v) G4 Y
getch();
. l9 {. K% Z1 E! [/* terminate with an error code */ 1 R" a9 W, X0 }! L; V7 d3 {
exit(1); 7 k- \' _ S o
} </FONT></P>
6 J, P' {* z' P< ><FONT color=#0000ff>midx = getmaxx() / 2;
7 ]6 t7 N6 t$ f0 z& H, j& {9 Jmidy = getmaxy() / 2; </FONT></P>+ Z' W/ E% b) j, e7 l
< ><FONT color=#0000ff>/* draw arc and get coordinates */
3 R2 {3 e) K3 J( E% g. k1 isetcolor(getmaxcolor());
2 m2 b/ j' k1 l, _" ~, p9 zarc(midx, midy, stangle, endangle, 100); # c7 S) W y# ]4 u' Y
getarccoords(&arcinfo); </FONT></P>
$ D! ^5 l" j/ v/ f< ><FONT color=#0000ff>/* convert arc information into strings */ ) Z% Q" a: x! @% D+ a5 X9 l' n; W( ?
sprintf(sstr, "*- (%d, %d)", 1 N) s# M, l; r* b( W+ [$ Y. a7 }
arcinfo.xstart, arcinfo.ystart);
e) D7 |& d6 ~sprintf(estr, "*- (%d, %d)", ) [7 L. I3 f# X8 p4 \9 k6 j
arcinfo.xend, arcinfo.yend); </FONT></P>1 S: H3 G+ t' ]( L/ @4 b: J3 b
< ><FONT color=#0000ff>/* output the arc information */ ! T9 z; n0 d& D
outtextxy(arcinfo.xstart, , n% g6 O( w& @2 L
arcinfo.ystart, sstr); $ y. q6 j& K% f0 @: ^
outtextxy(arcinfo.xend,
7 I8 [; S! D3 I. F% O$ Darcinfo.yend, estr); </FONT></P>$ _/ A% V0 N+ X
< ><FONT color=#0000ff>/* clean up */
- J$ X% ~- A, l3 L% [getch();
1 ?: |( M1 m9 i: w' Cclosegraph(); 0 _0 v I, v6 `
return 0;
: j0 N) h) ]2 Y9 C5 P$ i" e} 4 k5 D' D7 |4 f6 [% h! e% c
</FONT>/ M5 }- a# i: x# l7 D6 w
' L& |* v( q1 c7 v5 ^3 J6 b) v</P>
, }) g; K/ S+ }& H< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
. K U# x' Q2 F' I功 能: 返回当前图形模式的纵横比
" C5 ^% ^* _' y用 法: void far getaspectratio(int far *xasp, int far *yasp); ! H$ R1 U% f3 M" O& W$ f( \
程序例: </P>
# _. P7 x! ~( l< ><FONT color=#0000ff>#include <GRAPHICS.H>
5 x4 N1 n( e8 H. @1 {4 w: a#include <STDLIB.H>. P C0 v+ O. x( W+ P% F
#include <STDIO.H>; z' _0 p; u8 R' @( ?/ X5 M' m
#include <CONIO.H></FONT></P>0 f% N! i6 |$ A8 N
< ><FONT color=#0000ff>int main(void)
# I4 b7 S; z1 S: B9 n5 }) W: H7 G{ # L/ [. W, r: h1 `# j/ d5 ~
/* request auto detection */ 1 X' o# V9 o; I1 N3 k: e; o6 L
int gdriver = DETECT, gmode, errorcode; ' ~4 [0 {' T' R0 m# c8 p! `! c) j
int xasp, yasp, midx, midy; </FONT></P>
1 K3 j- c: ?" V6 u; F* _7 e< ><FONT color=#0000ff>/* initialize graphics and local variables */ " s1 R5 t4 e/ a0 D: Q8 Q
initgraph(&gdriver, &gmode, ""); </FONT></P>
& w3 Q% N8 s) O5 B3 }& h< ><FONT color=#0000ff>/* read result of initialization */ 4 ] {8 E O1 ~: x% \- p
errorcode = graphresult(); % x1 d0 [& E/ L
/* an error occurred */
0 n# T% u5 _( G) X A8 g' Sif (errorcode != grOk)
& R) a0 n5 a! L3 Q8 B# r: I2 J{ & Y5 d6 n u, L
printf("Graphics error: %s\n",
# [% q- g; ~6 ^- K% ugrapherrormsg(errorcode)); # J* O4 E4 {1 s- I5 ~
printf("Press any key to halt:"); , s8 g6 l. }8 X. h
getch();
& R8 U! U4 z$ @ O/* terminate with an error code */ , v2 H# M9 L/ m7 W2 |7 ]$ r
exit(1);
6 X1 X& b& j* r# U6 K- j4 K} </FONT></P>6 Q; V: u" s0 @+ C" F3 c
<P><FONT color=#0000ff>midx = getmaxx() / 2; ) Y6 W9 U/ S) Z3 q8 \$ S% W0 ?
midy = getmaxy() / 2;
0 I$ n6 A( @+ m8 dsetcolor(getmaxcolor()); </FONT></P>3 Q3 w! c5 X/ _. N: }: \1 |
<P><FONT color=#0000ff>/* get current aspect ratio settings */
: L9 `2 ~" p6 [* |4 C0 O$ ?4 k9 P$ egetaspectratio(&xasp, &yasp); </FONT></P>
: i. I% e4 f; f; d# S<P><FONT color=#0000ff>/* draw normal circle */ ) S1 J7 e1 f' P; W/ I9 O, _
circle(midx, midy, 100); * }, u9 u+ ^( I' n
getch(); </FONT></P>
) n: o) D& i4 i# ]: m5 Z5 Y% r& P<P><FONT color=#0000ff>/* draw wide circle */ & U% f9 \) C, H% y
cleardevice(); 3 o t; g/ F2 \% x1 h
setaspectratio(xasp/2, yasp);
* @) N2 |. w$ m, I! Bcircle(midx, midy, 100);
7 B$ ?. ?/ z! z; k9 o4 {% cgetch(); </FONT></P>
# W( y' M, I( ^( ~<P><FONT color=#0000ff>/* draw narrow circle */
( }- c7 \- e8 \2 _9 Y0 Ucleardevice();
- d% p( a3 [5 }7 K. p: a7 isetaspectratio(xasp, yasp/2); * X' X6 f2 {( }- W0 Y* ]
circle(midx, midy, 100); </FONT></P>3 v; y- K1 F9 `& A" C4 ]9 P
<P><FONT color=#0000ff>/* clean up */ ' L; ^7 C0 W7 a7 \$ R, T
getch();
' j$ A5 w0 O' \- u& o0 w4 fclosegraph();
7 S1 b; o f" j$ i$ Mreturn 0;
0 @- n- K0 g4 G} . @" I$ ~! }+ r4 _* c- H( U/ E
</FONT>
, K! E- Z5 U. A0 r7 K Y# T) E
* f6 T9 t* L: @1 F* t% o8 g: y</P>$ Q0 d' U/ O, S% ~' p; x; B* d% ^
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
% m8 l6 v4 r" \' `5 H. U功 能: 返回当前背景颜色
$ I' s/ Z4 t: O0 r' s用 法: int far getbkcolor(void);
$ i c! C! d9 `* F7 h( V" u1 p+ D u程序例: </P>
, t& i# w3 a; ^<P><FONT color=#0000ff>#include <GRAPHICS.H>
# V6 V! ?1 I0 H$ I4 m#include <STDLIB.H>% [1 l9 h h. l1 H
#include <STRING.H>6 T) V9 A1 X$ G, R8 s& }3 E
#include <STDIO.H>
% X* s0 k, E. c, d/ H+ {: O#include <CONIO.H></FONT></P>
" _" d; R# ^ D4 t+ @<P><FONT color=#0000ff>int main(void)
+ U9 e5 D/ k- g$ @! z5 A{
3 [) F5 X; F/ r/ y/* request auto detection */
' k A' I( d6 f8 D* n8 g7 lint gdriver = DETECT, gmode, errorcode;
; [" X, c$ R. t, r/ s2 }int bkcolor, midx, midy; 4 L7 v( ^- [ | E( }8 @7 ]7 A
char bkname[35]; </FONT></P>
0 q: k# d6 W, C% B' x2 Q<P><FONT color=#0000ff>/* initialize graphics and local variables */
' W$ P1 Q I' }) X# rinitgraph(&gdriver, &gmode, ""); </FONT></P>+ {% i) Q- F! Y, {
<P><FONT color=#0000ff>/* read result of initialization */ 7 l5 i, H. v$ {+ S! E3 u
errorcode = graphresult(); % j% @) d# b' o$ k4 u, |
/* an error occurred */
7 h2 x: Z" a8 b$ K# X& Hif (errorcode != grOk)
! v( ]+ n. ]5 o" E% \$ h6 k% |{ 9 l8 u7 X) K9 o$ H) }
printf("Graphics error: %s\n",
. o: H8 j0 e7 v0 Igrapherrormsg(errorcode)); $ ]* O6 R. L% y4 G% X' f: U
printf("Press any key to halt:"); 2 n; X6 X; C- G5 m _, q
getch();
9 a; A8 C) K: I- \# i E9 k/* terminate with an error code */
$ c3 K# `: X: z6 i Nexit(1); ; R- z! B6 d0 Y, \. t) t( ?
} </FONT></P>6 i) H8 R- j4 _* J
<P><FONT color=#0000ff>midx = getmaxx() / 2; % a# l0 I! ^; Z! j% |
midy = getmaxy() / 2;
1 l! ^# {2 a. B: M* ]; msetcolor(getmaxcolor()); </FONT></P> ]3 B. n2 [9 [2 V4 K$ w2 P
<P><FONT color=#0000ff>/* for centering text on the display */
$ g, B H5 F) Ksettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
& S7 ]* w$ d( {; z$ m! P0 @. M<P><FONT color=#0000ff>/* get the current background color */
; ^ c: j+ ?8 [! ?bkcolor = getbkcolor(); </FONT></P>
) Z- v% |; Z( U<P><FONT color=#0000ff>/* convert color value into a string */ 0 ~- s- {& h z& N* I; Y3 @- {) n
itoa(bkcolor, bkname, 10); 6 P9 |# A9 I( p% Z, g
strcat(bkname,
3 q2 C$ O4 D' L$ `$ t) h% O5 d' S" is the current background color."); </FONT></P>8 i, Z8 Q8 Z" t& P" _1 K B
<P><FONT color=#0000ff>/* display a message */
1 i0 D% v! v8 E' Couttextxy(midx, midy, bkname); </FONT></P>5 G I! z& {( N9 i- ?9 q
<P><FONT color=#0000ff>/* clean up */ . n+ D# `. P4 V' ^. I: `( W
getch();
1 z: N) `" }! ]7 \' n/ N. ~closegraph();
" M( T( P1 X1 A* x9 \7 H) R( q6 b3 _return 0;
0 r! W9 |: y7 F" Y8 I5 I6 ^} 9 N5 p& q1 ]# H% Z* b+ u
% u' m0 v# n4 |3 \* z+ y
</FONT>
3 s5 ^+ v$ v5 @) o; D; Z7 o</P>" R [- i; z( `
<P><FONT color=#ff0000>函数名: getc </FONT>$ j0 c7 \* P; g
功 能: 从流中取字符 / f1 l( A' p. `! k' A# m: W& y
用 法: int getc(FILE *stream); % O' @2 d8 j r3 g; N
程序例: </P>* `4 O+ P* `% W, p8 T+ D; c
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>1 q3 q& X- f* e1 `# Y1 Q8 C; f9 V
<P><FONT color=#0000ff>int main(void) $ ^+ g, |% C ] H5 c
{
6 g+ \! J4 ]* }- A# \char ch; </FONT></P>) |+ \! [- ` y7 m' P2 p: M0 G9 K
<P><FONT color=#0000ff>printf("Input a character:");
2 c- x7 Y- h; R. M b2 y3 i+ r/* read a character from the 7 @6 L- [ M" C U8 m0 T
standard input stream */
, g! B. H% s& U) Kch = getc(stdin); / O$ T B' T% G$ R0 F
printf("The character input was: '%c'\n", y1 j$ n. F8 c4 e
ch);
' m" | ]) _+ v+ creturn 0; 6 H2 K q: M# r# V, P: K9 a
}
! q4 k7 h8 f C! |4 ^7 w
( e; x+ p) y- X- m8 m( f$ c! S</FONT>
' f0 {4 }, U* S, I</P>
# [: P' j. j$ m$ J/ [* ]' D<P><FONT color=#ff0000>函数名: getcbrk </FONT>
' h, N6 X# L* ?2 s* |功 能: 获取Control_break设置 / A0 v" A0 t" j; Y# l2 O/ y
用 法: int getcbrk(void);
6 x0 r& L( n3 b; g程序例: </P>
/ q8 I9 o; c6 `9 a# k# c<P><FONT color=#0000ff>#include <STDIO.H># x0 m# o, X2 N0 V
#include <DOS.H></FONT></P>
$ u: M6 c- ^+ h9 h+ F<P><FONT color=#0000ff>int main(void)
& O1 K4 @5 u, i/ C{
5 {3 o7 A4 B2 z& `7 hif (getcbrk()) . G& x- C+ J; D9 N! k
printf("Cntrl-brk flag is on\n"); $ c$ z- m4 d2 g5 F
else 2 [0 z- L* T9 r7 p( M! H
printf("Cntrl-brk flag is off\n"); </FONT></P>
% g9 [! Q7 m2 O8 v<P><FONT color=#0000ff>return 0;
) ]2 |4 o3 d) {* `: ]} </FONT>
2 s x: k( }0 T! y) v8 Q* R# X k w" N* f5 s) R, l/ o+ E1 b
</P>9 i0 G7 X \0 O' K3 U/ j; v
<P><FONT color=#ff0000>函数名: getch </FONT>
/ u1 W8 }3 l" j6 z0 b功 能: 从控制台无回显地取一个字符 ; ^& s' f+ Q+ W c7 e: u
用 法: int getch(void); 3 ^* O) K5 f$ u3 c
程序例: </P>* e+ ^& E! ~; j; j0 X2 x
<P><FONT color=#0000ff>#include <STDIO.H>
: I# w3 q* N6 X$ S. {( r, E#include <CONIO.H></FONT></P>
' u: f/ |: v% P1 {& Z9 \* s1 l<P><FONT color=#0000ff>int main(void) 3 s a8 [' P9 y
{
% H: P/ M7 @2 b, D' ?char ch; </FONT></P>
1 H3 _) U6 X$ Q3 e) I( k& b9 i<P><FONT color=#0000ff>printf("Input a character:");
- b( F1 e+ [0 L1 `, Pch = getche(); 5 Y& e$ S6 ]: ]0 t" `. r3 |3 I+ @/ H' @
printf("\nYou input a '%c'\n", ch); % A5 \7 P4 h- g- C$ u: ~. |- }! Z
return 0; ) ^" h% y m+ p- Z
} * y/ U. V$ ~& Y6 L8 V
S- j, _8 |& J: B* \& n7 S0 B</FONT></P>& }( `/ h9 g" X3 X
<P><FONT color=#ff0000>函数名: getchar </FONT>5 P- q7 J4 G6 R, W9 W
功 能: 从stdin流中读字符 : z) s! Q O- Y2 J
用 法: int getchar(void); % h* k2 C" H: a& [
程序例: </P>$ y9 V+ R4 n- b; d' r8 D6 N, o
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>. v1 A; _! A) R6 T7 e% u( G
<P><FONT color=#0000ff>int main(void) 7 a; \* F2 k: I! D, `
{
; E* {- b8 U: n8 l" _" Fint c; </FONT></P>
, f5 o% B8 V8 B2 V+ L5 j<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
, z# ?+ P" Q2 U0 k% Nis line buffered; this means it will
6 {1 u8 V- O( \5 _3 ^$ knot return until you press ENTER. */ </FONT></P>
I' |) ^$ L% q9 I6 I<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
R) R* q `2 Q8 ~: B$ O) G1 Uprintf("%c", c); </FONT></P>
/ x8 w9 O7 \* T% @" q+ d6 E* P& Y* x9 s<P><FONT color=#0000ff>return 0; ) u$ I: W# U# e# T/ W# O
}
7 n9 K" ?6 u/ |% w- N; b+ `</FONT>
3 W1 r1 l% A! q9 x1 e</P>& K: F; s t2 t
<P><FONT color=#ff0000>函数名: getche </FONT>: f! Z' S+ V- R
功 能: 从控制台取字符(带回显) 3 k" H6 `7 d0 m6 t9 g# z& b
用 法: int getche(void);
/ J! @2 P0 m- Q* u1 b7 g程序例: </P>' J- T" W' O) c1 e
<P><FONT color=#0000ff>#include <STDIO.H>
) I, ]; t! V( p- @0 b O( j#include <CONIO.H></FONT></P>
4 I- t! ~$ S2 p# Q/ |+ x, o<P><FONT color=#0000ff>int main(void) T% D& W0 w" o5 a# J
{ ) U6 `* D1 Q1 j3 @4 N+ G0 r# y
char ch; </FONT></P>8 E* x, ?7 i" k. h z6 D
<P><FONT color=#0000ff>printf("Input a character:");
9 L& Y% Q, d# P. F& F5 v, v# S% jch = getche(); 9 b. R% `: _1 [( u1 t
printf("\nYou input a '%c'\n", ch); 6 {0 z# }5 E: u9 R8 n
return 0; 6 e& {6 y$ g# |/ M6 H
}</FONT>
! F" h* R- P& e' j) c1 J0 S0 l
0 }; Z" z9 D1 I</P>" l9 l3 K2 M: w7 k- ?
<P><FONT color=#ff0000>函数名: getcolor </FONT>! {" C9 X& {. c B
功 能: 返回当前画线颜色
L- a7 N% D. {: L r用 法: int far getcolor(void);
4 H- _5 o+ ~" ?* q3 K* N程序例: </P>
" g+ w1 Y2 d! e/ |! r<P><FONT color=#0000ff>#include <GRAPHICS.H>; r9 W" |3 g) s/ J( T
#include <STDLIB.H>) G) b: R4 j% l0 I; e1 k
#include <STRING.H>
% E4 ?; l3 b3 X( R2 ^+ E; g! }; l8 i1 u% @#include <STDIO.H>- U3 ?/ X0 p4 \3 _1 o; z8 `, h
#include <CONIO.H></FONT></P>
5 d( R+ N' i1 @1 }7 c/ b y4 D3 x9 N; w<P><FONT color=#0000ff>int main(void)
" E4 x& v( N- }, E% E- e{
U% G) d, d: ?: ~) k) }3 }/* request auto detection */ 9 h9 g$ a: C* t: e/ z
int gdriver = DETECT, gmode, errorcode; + r( U6 p% T& Y( S
int color, midx, midy; ^# v: ~8 B. C- A9 m) r6 l' @7 j
char colname[35]; </FONT></P>
: l+ \4 i+ y2 k# X* D( k, w) O; [<P><FONT color=#0000ff>/* initialize graphics and local variables */ * s) n, ]: h5 U* L/ a
initgraph(&gdriver, &gmode, ""); </FONT></P>
$ I5 A) n7 T2 k8 x6 g8 V7 \5 j<P><FONT color=#0000ff>/* read result of initialization */
8 a* Z- I3 r3 b1 O. S/ x# o1 perrorcode = graphresult();
9 A) k$ K! Q5 g1 a2 j/* an error occurred */
! s, B& v! Q2 \& g3 z7 Gif (errorcode != grOk)
4 [- X' |' d7 s. D' d) S- l3 f{ 9 ]" a/ Z% I5 R1 C1 S) \1 T
printf("Graphics error: %s\n",
- l( N3 Z9 n: ~9 q% Zgrapherrormsg(errorcode));
, P! J6 @" Y+ [9 T6 t2 Tprintf("Press any key to halt:");
# Q! ^9 }& z! @) @8 N v- K; K9 Ygetch(); . N$ ^4 A1 M% O. w0 U. D
/* terminate with an error code */ ( _1 h9 L+ {$ D8 ]5 P9 K
exit(1); $ Z l/ @3 D- x; }7 |' s
} </FONT></P>
* c; j E7 R! S v<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 g* g5 \3 U, L" y7 V& r. Rmidy = getmaxy() / 2;
/ N$ N* S( h# Z+ j* Ssetcolor(getmaxcolor()); </FONT></P>' y( ^& p) W9 h! Q
<P><FONT color=#0000ff>/* for centering text on the display */
# a0 ?3 y& U2 [2 c% N1 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
R/ D$ s- Y7 d9 W8 Z- L<P><FONT color=#0000ff>/* get the current drawing color */
5 g+ c% W- v7 Rcolor = getcolor(); </FONT></P>
g4 o! ^6 b) H0 k<P><FONT color=#0000ff>/* convert color value into a string */ . G5 H0 ]0 P! {0 @
itoa(color, colname, 10);
" G$ S% q7 U4 f6 C1 u9 G o; _( b) X7 hstrcat(colname, 2 a* n# S1 q8 x, C; u) z
" is the current drawing color."); </FONT></P>
+ ^( e) b: W" g1 ]<P><FONT color=#0000ff>/* display a message */ 1 m/ {" P% h0 X& {/ [1 |8 p
outtextxy(midx, midy, colname); </FONT></P>$ Z0 z0 Q- o8 L$ M; m7 e# X
<P><FONT color=#0000ff>/* clean up */
! C& ~; @/ W$ Kgetch();
) w7 m# a" W; H3 u$ D- g. lclosegraph(); 9 S. s$ {$ _+ _1 o( G+ C
return 0; 7 r9 U6 q5 X2 K( k8 m
} " f, T6 G* ~' y u1 ?; E3 q
</FONT>
6 w- n( C/ s9 W1 X$ l; X8 X z</P>
, ?+ ?. t9 r- m4 Y- J5 i<P><FONT color=#ff0000>函数名: getcurdir </FONT>
- L; a0 S2 {8 n) u2 F: w: V( D功 能: 取指定驱动器的当前目录
+ v! {) y. l+ w6 \用 法: int getcurdir(int drive, char *direc); 2 I* |% u# Z9 i! ~! F/ e
程序例: </P>2 K* j4 Q+ ]* t% w
<P><FONT color=#0000ff>#include <DIR.H>/ I' Z2 }) x, } H9 {
#include <STDIO.H>! F9 @* h5 e$ M- ~ N
#include <STRING.H></FONT></P>
0 A$ A4 ~6 Q" F" h3 m! t! B<P><FONT color=#0000ff>char *current_directory(char *path)
! i- I/ v$ C) Z" g, u* m! l5 a{ - _1 U) I+ t" t s/ @9 G% l m
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
4 o7 t, @% C# zpath[0] = 'A' + getdisk(); /* replace X with current drive letter */
; z: j% T; J2 ` S% ]% l8 T3 b* dgetcurdir(0, path+3); /* fill rest of string with current directory */ 6 E4 }! v* v) F
return(path); 4 M6 |8 l$ X6 P8 W- o4 L
} </FONT></P>5 `1 V" y9 h1 m% z7 G# M
<P><FONT color=#0000ff>int main(void)
r" T: t3 W3 B" f& a{
$ c0 I5 |+ f; zchar curdir[MAXPATH]; </FONT></P>
: w( m, H* t6 C, Z9 p8 W<P><FONT color=#0000ff>current_directory(curdir); 2 G# e8 P# q# D5 O# L* P7 k6 `4 p
printf("The current directory is %s\n", curdir); </FONT></P>! I% C$ r" _0 p3 M4 {9 U
<P><FONT color=#0000ff>return 0;
' T1 G+ W2 L6 Q6 A8 w6 X- e} ! A4 s* a7 c$ |/ f6 F- P9 x
</FONT>
: m/ ^3 J! C5 b5 Q" q3 b$ Y</P>
% \' |9 E9 H v8 k, P<P><FONT color=#ff0000>函数名: getcwd </FONT>- H Q5 l0 ~# p
功 能: 取当前工作目录 0 _3 g* g! T5 ` x" A
用 法: char *getcwd(char *buf, int n); I: H( A G, _& P$ A7 s
程序例: </P>
$ u7 r5 B. u: r7 i<P><FONT color=#0000ff>#include <STDIO.H>
& a/ k$ V% I! d* l' U#include <DIR.H></FONT></P>
2 ]8 }( m% |0 @9 ^5 k<P><FONT color=#0000ff>int main(void)
* O/ ` {% i1 G# o+ p% U2 C{
! @5 B9 l% j7 v+ X* O1 Fchar buffer[MAXPATH]; </FONT></P>- i) z/ h p, Y. O$ V7 n" k* J6 `1 E1 i
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); 8 {- D3 G1 D& t* A
printf("The current directory is: %s\n", buffer);
- _ t+ i. k( p# N- X3 \return 0;
7 I2 D& x" _) r' W8 X7 u} </FONT>
" L& I3 D, X4 f) u( o* m
4 o, c4 Y! j% h</P>
" f% Y; Y% \8 d8 B$ @" ?4 p( P<P><FONT color=#ff0000>函数名: getdate </FONT>" U7 [- T- u3 \. I, e0 f
功 能: 取DOS日期
N2 l2 `* w$ t5 ] g7 c用 法: void getdate(struct *dateblk); + t! B) ] Z. ~% M8 f6 B2 u4 N
程序例: </P>. w% w( W0 \# X; T/ ~9 T! b1 a
<P><FONT color=#0000ff>#include <DOS.H>: C* d, Q/ B- p* e4 r) P8 i
#include <STDIO.H></FONT></P>9 O5 M% F( p* Q" j. }- i1 M0 W8 O
<P><FONT color=#0000ff>int main(void)
: Z* Y5 o) g* N! B2 H7 T{ 6 k! J6 I( W8 m( `3 e7 |% {2 V! V
struct date d; </FONT></P>
2 F% t7 I2 O0 v3 r: X8 G) a<P><FONT color=#0000ff>getdate(&d); & w( O# f4 P/ k
printf("The current year is: %d\n", 1 V/ C1 V8 P0 d! g( z/ e
d.da_year);
4 w7 e/ K* _& c0 |( a( |printf("The current day is: %d\n", " \& ?6 _; f' ] k$ M
d.da_day);
9 ?0 @& v" y* M5 Oprintf("The current month is: %d\n", ) I1 ?$ [2 b% `$ V$ f# J! V
d.da_mon); - k4 | W2 p- W
return 0;
- p, }( P- e! m/ Q g} ' \/ r% i* S( r9 _# }
</FONT>4 x4 s3 |0 l6 ^$ l, ~
</P>
5 S+ Y; A+ x; X( Q" x<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
3 N y% a4 f' D; D$ y7 H% k: V8 j功 能: 返回调色板定义结构
2 }. C; F' l9 |+ r0 x用 法: struct palettetype *far getdefaultpalette(void); , I( ]% a6 z3 Q6 H, U
程序例: </P>
. s7 ]$ z6 H/ {- f. G g: ?- Y# U<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 `6 i2 [1 F: o# X3 {* @: U#include <STDLIB.H>: z" O4 O9 y) D3 F8 {& V
#include <STDIO.H>
: k H' d) ?2 f# K2 D#include <CONIO.H></FONT></P>% E) H) ^+ b) J& i/ k! t$ z# C% g- j+ y- k
<P><FONT color=#0000ff>int main(void)
' c5 ]% W$ d& V3 i3 x{
' q0 o Y1 P% I }0 y9 [4 u% f2 g/* request auto detection */ 3 n* c! y- ]( A) m4 l
int gdriver = DETECT, gmode, errorcode;
" y- U2 q) ?# N! @( Zint i; </FONT></P>/ N9 V. x' @1 E: ?8 }1 Y/ H
<P><FONT color=#0000ff>/* structure for returning palette copy */
7 x# Q9 s. D2 V2 k# p( ?; qstruct palettetype far *pal=(void *) 0; </FONT></P>
* m0 N9 D7 K; L( v9 F! u0 W<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 |# C' U3 G! G0 z7 Z6 o# \3 Ginitgraph(&gdriver, &gmode, ""); </FONT></P>
& Y+ |% ^8 s- e9 n1 l) C3 N<P><FONT color=#0000ff>/* read result of initialization */
3 d+ f: B( d3 Ierrorcode = graphresult();
4 m) ~+ {- T/ {8 e4 ^( p" h/* an error occurred */
) ?7 D- [* t5 M) yif (errorcode != grOk)
. |2 S& l& o) a2 {0 e{ / ]- X# x, V- R) c: \+ X
printf("Graphics error: %s\n",
3 Q4 J7 g8 a( ~3 \grapherrormsg(errorcode)); 0 s" a; H) l2 o8 t' p7 Y @
printf("Press any key to halt:"); / X, ]2 c5 T8 r/ t7 y- H
getch();
; l, B& J, k; e2 [, b/ f/* terminate with an error code */
/ h z3 |4 O7 d! W. e7 Wexit(1); 3 X+ q8 B0 i, _7 o! m
} </FONT></P>
m: s' ^5 B1 X<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>6 u. L( K7 L8 h7 }" H; ]8 k: `
<P><FONT color=#0000ff>/* return a pointer to the default palette */
7 B5 @0 A; k8 K& V% v3 xpal = getdefaultpalette(); </FONT></P>6 D8 H* p( B" o0 L& m
<P><FONT color=#0000ff>for (i=0; i<16; i++) 8 `2 G( F. ^0 f3 b& m' v
{ + P- l, S/ g4 v( M$ l- f" x$ C/ |
printf("colors[%d] = %d\n", i,
; u- [3 d6 r, D1 apal->colors); - q' b* [( Z: }0 |5 P% u% o
getch(); ; ~. d! x3 D1 A( s
} </FONT></P>
5 p1 X {! o0 v. T% C<P><FONT color=#0000ff>/* clean up */ ) O1 q4 c9 \+ L2 n' R( d0 U$ T
getch(); $ o+ D% c4 P9 N& m" y
closegraph(); . ]7 M+ C6 l+ ?( R6 d
return 0;
/ e+ P# c' @( E7 m} * U7 L# W& e$ E$ n3 E
</FONT>0 C/ w( o1 c7 h; m$ V3 g x) \
</P>
: m/ P u3 t% A3 n3 ^<P><FONT color=#ff0000>函数名: getdisk </FONT>3 {6 O( q" C" y1 h1 X: r. U
功 能: 取当前磁盘驱动器号
; T7 A3 F& |2 O- I- z& x: h" _. o用 法: int getdisk(void);
% T' S4 F$ \0 m6 |( W- f" u0 j程序例: </P>
0 ~$ N7 S3 J9 s0 f5 J<P><FONT color=#0000ff>#include <STDIO.H>1 w; |- e% L' X- _! d @
#include <DIR.H></FONT></P>
9 a0 S# u* v: w+ w6 Y8 B9 ?7 {# B<P><FONT color=#0000ff>int main(void) 6 g+ e! a; \2 y/ Y/ C8 {+ z
{
- ]1 j. y" [/ L R/ V$ Gint disk; </FONT></P>6 n- ]" A+ ~4 u: H. C/ E" ~# u
<P><FONT color=#0000ff>disk = getdisk() + 'A';
# D5 i1 @; ?% i( xprintf("The current drive is: %c\n", / X# J7 g7 ]7 l8 A7 X& k5 |
disk);
, ~* w5 @' \$ E1 r) o5 [6 h8 kreturn 0; : I K' e6 ?& |
}
* F, t) G% i" ~% |3 }# w8 R8 u$ i f1 `" ?& q
</FONT>0 _: Z' H! u! h$ G S0 z2 {
</P>
( S# e+ I; ?$ V<P><FONT color=#ff0000>函数名: getdrivername </FONT>
) t. f: G4 f. k B7 T: a) O功 能: 返回指向包含当前图形驱动程序名字的字符串指针
5 h) A1 r8 v; a. Y1 v- x用 法: char *getdrivename(void);
- C$ k a* B" o0 g; n# D程序例: </P>
- A% D7 r. N2 p3 w<P><FONT color=#0000ff>#include <GRAPHICS.H>3 r; C7 ~$ I) [0 u* U
#include <STDLIB.H>, k6 m. r, ^- ]2 H
#include <STDIO.H> w: N; c- ~. J) `2 T V! Q# @: P
#include <CONIO.H></FONT></P>
* ?3 l8 h) Y0 W! v: t- D$ g* z" {<P><FONT color=#0000ff>int main(void) # O% G7 {* o2 Z- i
{
$ {5 N: C- E. A8 O% F/* request auto detection */ , P3 d: ] B2 g. k1 l- o* s% a# S' n q
int gdriver = DETECT, gmode, errorcode; </FONT></P>+ J5 K) \) r9 W
<P><FONT color=#0000ff>/* stores the device driver name */
: r+ V# a! F6 @) Y: c* ]char *drivername; </FONT></P>$ ?1 u3 {( V" ]( ?9 r' L* y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 i1 J6 k" i/ c w# D$ J# I1 T, u
initgraph(&gdriver, &gmode, ""); </FONT></P>
0 s. l Q' q0 t" v3 j1 T. r3 K<P><FONT color=#0000ff>/* read result of initialization */ 9 B. K1 e# j4 ~: y3 _" R
errorcode = graphresult();
3 N X5 q+ I3 P4 o/* an error occurred */ 3 i5 V2 b1 z1 W
if (errorcode != grOk)
2 \! O" \5 D6 a! y# Y7 M{ 3 p" K7 A; M7 H: w- O
printf("Graphics error: %s\n", 5 ]: C6 R# T; {: f
grapherrormsg(errorcode));
; K+ w9 K4 d( U6 y5 ^4 f" v! Yprintf("Press any key to halt:"); ( Z! H- X9 H7 |
getch(); 9 R" f* c0 y2 G/ O) u
/* terminate with an error code */ 2 ~4 N3 D; ]& d
exit(1); 0 J& k" e* h( R5 v
} </FONT></P>. s3 E9 ]: m8 k+ J& v( R" O
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>$ `6 \1 N/ L p; I7 n: u. T
<P><FONT color=#0000ff>/* get name of the device driver in use */ 4 @* G& d: ]+ `2 i) e
drivername = getdrivername(); </FONT></P>2 B( e: f- A' }6 B$ {5 v
<P><FONT color=#0000ff>/* for centering text on the screen */ 8 y2 u. Q) u: D; }4 M0 |
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>- R* G- E$ G4 A# b; i
<P><FONT color=#0000ff>/* output the name of the driver */ ; F; L* Q7 I1 p3 m9 [* e9 P
outtextxy(getmaxx() / 2, getmaxy() / 2,
# Y5 @% z. c3 i; Y( _4 V2 Ndrivername); </FONT></P>5 B/ t E: \2 H9 J- h2 e! Y$ x- c
<P><FONT color=#0000ff>/* clean up */ ; s+ C1 f. K- c* |' i3 m
getch();
4 @" T& |# X1 o) q$ s" Xclosegraph();
( w9 ^8 K: q' vreturn 0; , l5 O1 g: E& ?( a
}
5 ]; Z' r% k9 L</FONT><FONT color=#990000>4 y7 [ X2 [# i$ v- Z$ n+ K
</FONT></P>
% C5 m- n! g4 \* j( w<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>6 K. B: {6 l, o7 h& M0 S
<FONT color=#000000>功 能: 取磁盘传输地址
- u6 f; B6 G& Y& D: I5 |用 法: char far *getdta(void); j7 b! l$ Q1 B! w
程序例: </FONT></FONT></P>0 f7 _: a4 F8 e, N" N2 x) n5 X
<P><FONT color=#0000ff>#include <DOS.H>4 i3 z, f2 K8 O8 {, B4 x
#include <STDIO.H></FONT></P>
5 V6 J) t' _: T& C1 Q<P><FONT color=#0000ff>int main(void) 3 h% D( e5 A$ u) U: X
{
0 A% ~3 c, \8 R& q# |$ g/ Y' }char far *dta; </FONT></P>3 w8 P1 K1 S) s3 ^+ s# C8 d
<P><FONT color=#0000ff>dta = getdta();
! y* o: X; s2 Z: t) }printf("The current disk transfer \ ' n/ n* Y! G' n5 o5 I* ^, q
address is: %Fp\n", dta);
$ o6 R( g1 `5 h* dreturn 0;
* [% m$ R! {; Z" g# R}
6 m- ]$ i/ o1 v</FONT><FONT color=#990000>
3 X. U, d8 j5 n. j0 b' ~</FONT></P># n) u. N0 Y! d
<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>6 o+ d2 G& D. x0 Y* K+ H
<FONT color=#000000>功 能: 从环境中取字符串
. n3 f; E' I& B- P( w用 法: char *getenv(char *envvar); : _5 `! a3 Z5 U) h8 i4 W+ a
程序例: </FONT></FONT></P>
( ?: }5 ]- e4 [$ j<P><FONT color=#0000ff>#include <STDLIB.H>
, O- s! H2 z- h/ a: F#include <STDIO.H>) \* |4 M6 K! z/ g7 ?8 p2 `
</FONT></P>0 Q6 i* p- ^9 D% C, G
<P><FONT color=#0000ff>int main(void)
4 x S! ?! g6 S; m{ ( r$ W/ [! y( q) W- {8 c
char *s; </FONT></P>
4 y* l: u5 Q& S6 I$ j" Q0 x<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */ 6 X1 K, |) ^/ R& P2 N% u0 T# U
printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
$ Q" w7 ]8 B7 V% b/ j<P><FONT color=#0000ff>return 0;
$ k9 O) Q. Q' H& k8 n H3 N3 Z} </FONT><FONT color=#990000>4 W% j6 f& S) |! m9 N: K& L5 Z- k. z
5 A ^3 K4 S3 |2 r+ h/ b) L/ h8 E0 S4 b
; K0 @- \9 O. h. O' L$ P</FONT></P>+ O3 k* K' x/ W/ u& K
<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>5 y. P: ]- \6 h g8 L* Q- d
功 能: 取文件分配表信息
) F- H& j) T) _7 a用 法: void getfat(int drive, struct fatinfo *fatblkp);
$ A" e0 T+ i# p程序例: </P>
! o# ]6 D$ T( Z& w/ w1 ~4 k5 K<P><FONT color=#0000ff>#include <STDIO.H>2 N+ ?, T% k; M+ @# @" N% d
#include <DOS.H></FONT></P>& |8 ?2 [8 _" P& b2 e3 k2 E
<P><FONT color=#0000ff>int main(void)
, _+ G; S/ G& w{ - n2 E) X% c& G0 n/ A
struct fatinfo diskinfo; 0 s. n7 W( s8 i3 r( L# S) g" i
int flag = 0; </FONT></P>$ Z% o. k( T; t+ e" G
<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); 0 n3 y+ D! ?: d8 @! T! T2 ~
getchar(); </FONT></P>
/ p% b" t! O4 F7 X, j- B<P><FONT color=#0000ff>getfat(1, &diskinfo); 2 ]5 k6 E' O- o
/* get drive information */ </FONT></P>
0 {6 c# k, i+ Y<P><FONT color=#0000ff>printf("\nDrive A: is "); 6 @2 h- F/ E ?, @5 v- t# B
switch((unsigned char) diskinfo.fi_fatid) / P) q. H4 E9 x" `
{
- e% K4 r0 m/ W; I7 q4 ]case 0xFD:
$ u- C' H) ?$ E& ]' ?printf("360K low density\n"); ; ^$ P7 N( m+ O2 W" @$ k- g/ a, @
break; </FONT></P>0 {2 ` J$ e6 L6 o8 B5 c
<P><FONT color=#0000ff>case 0xF9:
8 g: H8 X9 V( s+ S0 c Nprintf("1.2 Meg high density\n"); t' R% n5 j0 w* U ?
break; </FONT></P>
8 ]( {7 b' L `/ P# S' H<P><FONT color=#0000ff>default: # X2 b. R' c# \' N' G3 `
printf("unformatted\n"); + J) h" K& r- {( m7 f8 x
flag = 1;
) z5 d- q7 w1 A( p: t- e; T} </FONT></P>, c) M! z2 ~4 c6 u& v0 r# y" A! t
<P><FONT color=#0000ff>if (!flag)
) t; v2 R! |% t. \* A+ f# U{ 7 s' T# v& V! ~* N. O8 P& T W
printf(" sectors per cluster %5d\n",
7 p m Q% S2 N3 [0 [' v3 bdiskinfo.fi_sclus);
+ m% `1 g) k& W/ L8 f! H. K. Z6 }; K* D' f; @printf(" number of clusters %5d\n", ' s6 t' ^* b: p
diskinfo.fi_nclus); & [& C; k' z' F8 A
printf(" bytes per sector %5d\n",
% n! I; `% Z" ~. |1 k: ?5 Z8 w! i5 a" Cdiskinfo.fi_bysec); 5 ?% e, |6 i; b
} </FONT></P>
2 F# j5 G* z! K# _$ s- c<P><FONT color=#0000ff>return 0;
" N1 |+ o1 g& B0 m6 R} 5 Q4 p: {3 Z* e
</FONT>
# N. d% k1 d9 I# ^/ ~3 j" ~+ |8 D</P>
5 k" d' A! ], B3 i* t' W0 |8 e<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
0 s3 d1 r9 b5 s: y( g功 能: 将用户定义的填充模式拷贝到内存中 & W1 n/ [% w' e4 O' Y" J
用 法: void far getfillpattern(char far *upattern); : P. T: p e1 M5 N
程序例: </P>
( R9 o. V" y( P; s% p* c<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 f- f% g; r4 V) ^3 ]#include <STDLIB.H>
9 V9 M% l5 o; z- D#include <STDIO.H>0 }( U+ I* P/ ~$ n
#include <CONIO.H></FONT></P>
& \& g @" D5 o* N/ ^<P><FONT color=#0000ff>int main(void) 8 h" z! y4 A6 {1 |+ a4 W
{ 4 r" l5 r% c3 x+ l" C4 ?- ^
/* request auto detection */
* V4 G& {8 E! o b9 b" \9 fint gdriver = DETECT, gmode, errorcode;
9 y- n1 b/ Z8 V1 ]int maxx, maxy; " `; v0 Q2 e8 R; \ B0 C
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>4 p/ R6 y7 `2 S) S) W% M
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ \1 i1 Q; |. g. I/ i# Oinitgraph(&gdriver, &gmode, ""); </FONT></P>
" _% u) h7 _0 O: o4 F7 f% W<P><FONT color=#0000ff>/* read result of initialization */
. f c# I* Z5 K; s% Derrorcode = graphresult(); ' E( Z" T* n W) M" [, c: z
if (errorcode != grOk) /* an error occurred */ / O# R9 o5 g, h4 i- v! z4 H" R5 B
{
) Y. a. ^9 z/ u- |+ i aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 l* g" I/ _- M' L2 }+ g1 ?printf("Press any key to halt:");
2 l7 J: x; J% C1 v+ dgetch(); 9 J& V9 S% ^0 }) ]
exit(1); /* terminate with an error code */ + {0 i* a& i" F% [+ H9 I: [2 h) }
} </FONT></P>) i, a" m+ q2 b% u( R+ T v" y
<P><FONT color=#0000ff>maxx = getmaxx();
' ?1 Q' w) w3 [maxy = getmaxy();
/ u4 o7 G3 X( g6 L" _ v% P6 i- L- psetcolor(getmaxcolor()); </FONT></P>1 [2 d: _9 w' G. O) V
<P><FONT color=#0000ff>/* select a user defined fill pattern */
: J- B/ {' X4 csetfillpattern(pattern, getmaxcolor()); </FONT></P>$ w0 R) m" T* i: |+ }
<P><FONT color=#0000ff>/* fill the screen with the pattern */
# g, M1 F3 n7 r; x9 Xbar(0, 0, maxx, maxy); </FONT></P>! i2 H9 e/ b W w' i1 N" S# w
<P><FONT color=#0000ff>getch(); </FONT></P>
+ ^3 M0 A5 k2 q# l+ `<P><FONT color=#0000ff>/* get the current user defined fill pattern */ $ G6 |, B# K( J [9 K) E6 G. H4 w
getfillpattern(pattern); </FONT></P>* c6 h8 t$ [- ]) ~5 t/ l& `
<P><FONT color=#0000ff>/* alter the pattern we grabbed */
, u1 N7 R* \) k/ Ppattern[4] -= 1;
& ~5 C5 v# U6 {2 D! rpattern[5] -= 3;
* V* P' z# r) y, w& Bpattern[6] += 3;
! k0 T# Y, M4 G O9 Ppattern[7] -= 4; </FONT></P>
! n) d4 e7 N9 }9 i& Z<P><FONT color=#0000ff>/* select our new pattern */ ( D+ T' l. i) S) C0 m# f& f2 W
setfillpattern(pattern, getmaxcolor()); </FONT></P>
3 `% i% \2 z# O6 [( K# j<P><FONT color=#0000ff>/* fill the screen with the new pattern */ 8 H3 x$ g; Y1 D& G" W
bar(0, 0, maxx, maxy); </FONT></P>
4 J% H7 l8 _& s<P><FONT color=#0000ff>/* clean up */
: p3 O0 G% ]: Z/ Kgetch(); 9 o% O: u& `' ~; y+ G: X; o
closegraph();
, @5 V7 x9 R# p$ ~! e) E) lreturn 0; 0 L. k3 T/ U4 @' J' ?$ ~4 i
} ; r( U- [$ m; b& w
</FONT>
' p2 a8 b3 M/ e0 S" H) E, `</P>
6 T2 Y# i t3 b _" E<P><FONT color=#ff0000>函数名: getfillsettings </FONT>: r) B$ y* j6 G. P, ]
功 能: 取得有关当前填充模式和填充颜色的信息 ) c/ u0 o" U! _ n
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo); 2 D$ J) w" m/ [* ^+ y& e
程序例: </P>$ u4 V' L3 m- y/ w# h5 W0 t' {3 s k
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 H7 E5 }4 z! T* @: Z#include <STDLIB.H>+ q% K# l1 V( A7 o
#include <STDIO.H>
- t! E4 O( B+ ]3 Q#include <CONIO.H></FONT></P>) O; \7 f7 ]9 I
<P><FONT color=#0000ff>/ the names of the fill styles supported */
8 m! X# u, C0 Ichar *fname[] = { "EMPTY_FILL", 4 q5 [/ k G" e! S( G: i2 V
"SOLID_FILL", ; @; ^! L4 e7 D/ J
"LINE_FILL",
& D$ g. O8 }* R"LTSLASH_FILL", 9 q* A# r" b- o* A
"SLASH_FILL", - H* W% K. n% h+ E* J
"BKSLASH_FILL", : `( V# ~4 L1 ~ x, J
"LTBKSLASH_FILL",
! p7 k3 @9 @2 @3 K) Y7 W"HATCH_FILL", 2 e3 e K9 Y G5 h; ~
"XHATCH_FILL",
% @& ~5 h( t1 V4 G( R0 |6 G"INTERLEAVE_FILL",
* z( }& A3 ^6 U( Z"WIDE_DOT_FILL", 2 i* w2 ^. V: `& ` _1 R
"CLOSE_DOT_FILL",
9 p: ^: ]0 g6 q"USER_FILL" , Q8 t' J- m) y w( ^0 @. E
}; </FONT></P>" L" k. w7 D: A1 C8 t
<P><FONT color=#0000ff>int main(void) 3 V# i( [* [/ r3 A# p# J6 a
{
. T G8 U" F( r2 _* t+ h2 v7 m/* request auto detection */
! g: P: M3 j' Fint gdriver = DETECT, gmode, errorcode; " l' k9 L( Q" o* G2 C$ k9 {
struct fillsettingstype fillinfo; " n1 G o( j1 {$ j, n
int midx, midy; $ u' b, n! l" u- p- j+ E/ b
char patstr[40], colstr[40]; </FONT></P>: H6 r* \) K# x# Q ~% R* h
<P><FONT color=#0000ff>/* initialize graphics and local variables */
( R+ P4 u3 K* O" yinitgraph(&gdriver, &gmode, ""); </FONT></P># \4 Z7 Q2 f* P$ c$ ]" U0 W& x7 B
<P><FONT color=#0000ff>/* read result of initialization */
& r4 Y3 ]7 w- o' Jerrorcode = graphresult();
D( f4 l8 N% b+ Q# _! \if (errorcode != grOk) /* an error occurred */
3 h( L; {) f* `8 j{
8 p4 n0 l7 c5 C$ |- \. n3 uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 f/ G9 e0 s6 T" _
printf("Press any key to halt:"); & k( \) a: p3 D X; \' H% `
getch();
9 \8 P3 T. T4 V- ^- cexit(1); /* terminate with an error code */
4 C" \; k. l7 K; g1 N6 V: k} </FONT></P># m+ d* m0 a2 `2 [
<P><FONT color=#0000ff>midx = getmaxx() / 2; ! V G8 O N1 M
midy = getmaxy() / 2; </FONT></P>
/ {: \1 H! I: h6 y" F<P><FONT color=#0000ff>/* get information about current fill pattern and color */
! [7 Z: M& e$ F" z8 rgetfillsettings(&fillinfo); </FONT></P>3 T) l' g" \" z0 H' G
<P><FONT color=#0000ff>/* convert fill information into strings */ % d- w$ S4 D) M6 O2 k
sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
9 a; @- R* E, m' \sprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
* _- S# ^6 _1 `<P><FONT color=#0000ff>/* display the information */
8 g3 ~! D5 I5 ]0 j/ V" t( Fsettextjustify(CENTER_TEXT, CENTER_TEXT);
- g% S. f- y2 q/ o" Wouttextxy(midx, midy, patstr); 0 D7 g$ r) G+ E; ?# u
outtextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
' J6 m9 j K) ?3 w* g- J<P><FONT color=#0000ff>/* clean up */ 7 P0 F) \3 t8 ?& s
getch();
8 J$ C+ z. @7 s2 Tclosegraph(); 8 y& `5 {* N0 _" @" |: N" Q& D, z
return 0;
# j1 \, w+ `* |# ]: s2 k& }. S} 8 }1 X* f7 f J# M$ G( S
</FONT>9 i I# _, E5 e4 s5 ~6 f9 _3 t9 ~% U
% s! b% G+ j+ N# ] W6 o. g
</P>9 G# H$ l$ i, H. K$ m$ B
<P><FONT color=#ff0000>函数名: getftime </FONT>
2 W i2 Z/ R0 x/ ~- y* |+ `功 能: 取文件日期和时间
9 ?- e( k6 x6 w* z( u1 W用 法: int getftime(int handle, struct ftime *ftimep); 5 y- @- l- C) }, b
程序例: </P>, ]0 ?. A9 I+ H
<P><FONT color=#0000ff>#include <STDIO.H>1 K+ _6 \# C( g
#include <IO.H></FONT></P>& ]) f1 w* u, n) f
<P><FONT color=#0000ff>int main(void)
. }( w+ i9 t% s& J0 g! m1 @" _{
' I6 `6 ~4 S& k( zFILE *stream;
o2 }% U! C6 Fstruct ftime ft; </FONT></P>
" m+ x6 n ~! s<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", # @; ]2 m% w; a
"wt")) == NULL) 2 f. j; G! c5 D" W( i6 _
{ 5 Y% O& y; O( ^+ Z' B! D- C
fprintf(stderr, 5 h/ T. Z+ d K7 |) y8 x# A+ W
"Cannot open output file.\n"); / L4 }( k5 f$ l0 {- P
return 1; & T# N( T6 \7 \. _6 d; Y
}
* t/ s! C4 U# B) x9 M5 m" V; a5 Hgetftime(fileno(stream), &ft); 8 Y. n# `- W1 E9 Q& u$ G( V& e( R# i- T
printf("File time: %u:%u:%u\n", $ E3 P0 Y: M# r- s( W/ A5 F" j
ft.ft_hour, ft.ft_min,
: w! `3 i4 U+ t5 nft.ft_tsec * 2);
, ^. T# Q; K* n7 Lprintf("File date: %u/%u/%u\n",
% Z2 k q6 P- t6 Nft.ft_month, ft.ft_day, " _ @! q& z6 R1 Y h @
ft.ft_year+1980); " g% T) Z( Z; G0 N. `5 p
fclose(stream); ; F3 T: m$ E/ k3 D/ {1 r
return 0;
! {0 [. Q+ n' p- V$ R3 i}
( w0 {' q- Z! h0 W5 U- e& m- S: l</FONT>/ R# c& w7 l9 [8 D% |: ~3 }9 {
) ^9 @1 ]8 t: I2 M( K/ g
</P>, d {) L- S# l- d7 a
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
/ }, K" b2 q! R' r, U4 c3 O& c% X功 能: 返回当前图形模式
( o6 ^- C/ n# a/ ^/ E用 法: int far getgraphmode(void); 6 _- D; o. [/ E
程序例: </P>
2 q K" g. M; ] p! d! ]/ I- E<P><FONT color=#0000ff>#include <GRAPHICS.H>8 ~, \' _# q& M+ ?* s9 \
#include <STDLIB.H>( ]6 k: N% l% y. S
#include <STDIO.H>
9 V" l) l# s' l/ H4 J" F$ \9 u#include <CONIO.H></FONT></P>
* F) ?# U0 [$ T% Q<P><FONT color=#0000ff>int main(void) 8 L) R( ?( j# z. e# M7 ?
{ 3 ]0 |2 k! `+ J
/* request auto detection */
4 \. a+ F5 w! b# {! e; oint gdriver = DETECT, gmode, errorcode;
. S+ k) }& |1 t- u7 W5 aint midx, midy, mode;
; u5 O" x$ W* m2 p! Echar numname[80], modename[80]; </FONT></P>- d5 Y! m m7 k
<P><FONT color=#0000ff>/* initialize graphics and local variables */
. Y4 ], N! c* F7 Y3 minitgraph(&gdriver, &gmode, ""); </FONT></P>4 y F- K/ V5 g; Y
<P><FONT color=#0000ff>/* read result of initialization */
# Q, f4 X6 A. G0 o7 l4 c3 q/ Ferrorcode = graphresult();
+ l( d% V1 p5 V( Y. H7 L/* an error occurred */
+ o$ C/ g: Y8 M+ m) f. Y8 Fif (errorcode != grOk) 5 ~* M2 \8 {, V1 A- f
{ ! p; P3 w) P, j4 N# k5 f7 U- I
printf("Graphics error: %s\n",
* M5 [7 c3 s/ l1 L- a+ Mgrapherrormsg(errorcode)); + o. O; G: _: v% d1 f6 r7 X7 o1 `- B3 q
printf("Press any key to halt:"); - _7 [3 O0 {6 h, U- @1 }1 W
getch(); * D! b) v* y! Q W) S
/* terminate with an error code */ g | Y+ N0 N& b F' j$ D
exit(1); . `$ j. S6 K0 V K
} </FONT></P>- R4 L% {; [/ j. i/ l5 l U* [9 f
<P><FONT color=#0000ff>midx = getmaxx() / 2; + v' |5 J7 r( T' e3 n
midy = getmaxy() / 2; </FONT></P>
6 U) q7 U: a8 n% \ d+ p) }/ z<P><FONT color=#0000ff>/* get mode number and name strings */
# L/ }, v I4 |/ k$ B3 C/ emode = getgraphmode();
0 W: \; b, E. F. ^$ tsprintf(numname, ! ?9 W# u) @: M
"%d is the current mode number.",
; k+ A5 ^ S( Imode);
; p. M; s+ G9 L. Xsprintf(modename, 6 ~) e, l5 c. m% H% |$ @
"%s is the current graphics mode",
! L2 h( A- A* W' p5 x& `; B- [getmodename(mode)); </FONT></P>
" G/ H" A1 ?. ?/ S% C6 m7 G- |<P><FONT color=#0000ff>/* display the information */
/ B6 e1 k4 l( p" a1 Z5 Msettextjustify(CENTER_TEXT, CENTER_TEXT);
0 m n6 j1 l/ \outtextxy(midx, midy, numname);
) T2 R; k3 {! f. o$ v) S0 Qouttextxy(midx, midy+2*textheight("W"), ) f$ k3 d: p& ?+ Q. k$ ?' ]
modename); </FONT></P>& k: P$ w* R9 s
<P><FONT color=#0000ff>/* clean up */ 1 r& u, h$ F8 T3 K
getch(); ' S( P& v; L2 C: n3 o
closegraph(); 9 g: m0 N! k' ^) z) Y8 V8 G4 A/ l7 @# i# O
return 0; 7 p7 f4 ^+ P- u* F
} </FONT>, J' x3 |% ~: \8 Z
7 L7 ~: n& g* F+ @# {1 b</P>
4 Z, q1 Q+ r: ` p<P><FONT color=#ff0000>函数名: getftime </FONT>
N9 F5 ?, V' d2 v! O$ E" l功 能: 取文件日期和时间
' I" M) {, [/ k# K用 法: int getftime(int handle, struct ftime *ftimep); . d/ p+ |) c/ {9 D
程序例: </P>' h2 f/ V9 k7 J1 [/ h
<P><FONT color=#0000ff>#include <STDIO.H>
% G: t, x% K8 V6 b#include <IO.H></FONT></P>
( R$ X* H) M0 ]# X5 b- N" c5 y<P><FONT color=#0000ff>int main(void)
5 X0 S* u. V1 n2 \) {; ?/ ~7 r3 q{ 5 [, z8 I0 T7 I, I4 f0 x, J) q
FILE *stream;
( I+ u5 y; p# U$ A, ~; Istruct ftime ft; </FONT></P>- l" U3 ]: [2 s2 {4 o. y
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", ( X f3 X& j( d h& u) s& \; _+ d
"wt")) == NULL)
% j8 A# `3 K8 A) _: P$ L6 l& b5 @9 ]{
* V& E: v5 P1 E2 bfprintf(stderr,
' s- h0 o4 v0 y% K"Cannot open output file.\n"); * v9 c4 A& [4 a7 f+ w1 D/ i
return 1;
5 c$ S' f0 z+ O5 M( d}
6 M B9 I1 j5 T% g, K3 F4 ~$ xgetftime(fileno(stream), &ft);
) B; {3 C5 L" ^' n2 N _printf("File time: %u:%u:%u\n", ! d) N s, T! c- N/ v
ft.ft_hour, ft.ft_min,
! [' w' R0 z, @$ ?; n: P# }- Aft.ft_tsec * 2);
) h! ?+ `8 y1 c0 \, `8 n2 cprintf("File date: %u/%u/%u\n",
- t0 f5 W& O- _, V( h5 M/ Aft.ft_month, ft.ft_day, ' o! N# K4 `/ ~- @, Y2 ?1 \' T+ t
ft.ft_year+1980);
3 H/ g* k4 Z: p& L5 m" \ wfclose(stream);
2 P( K/ P' ~9 ?, Treturn 0; # D! C8 ]* J- g! d* k
} </FONT>7 x& _' X. \; k. D5 m6 h) D
/ ]) M. g( ~2 H$ z; q/ P
& Z* U$ g: x0 W+ \; X</P>) o" n# [0 o3 r$ D4 F. r; S
<P><FONT color=#ff0000>函数名: getgraphmode </FONT>) m; H7 k5 _( `8 Q& M* m( A& m
功 能: 返回当前图形模式 3 i; k8 Y4 _, u
用 法: int far getgraphmode(void);
8 c9 V. Y9 Z/ K, v程序例: </P>
4 M# Z7 |* x7 b4 }/ d<P><FONT color=#0000ff>#include <GRAPHICS.H>
; w9 G4 W% `+ q8 i/ U#include <STDLIB.H>" T# V7 R; h |0 H6 Y
#include <STDIO.H>9 P& d2 v1 {7 o5 l6 D$ g [+ B
#include <CONIO.H></FONT></P>
; c% q. H }7 d0 y& K' s: g<P><FONT color=#0000ff>int main(void) 7 j7 H C X6 B+ E5 |7 D* T
{
6 U; Y6 a, b8 x( I/* request auto detection */
8 M3 C5 I2 `! Q: @/ d& t- a/ }( @int gdriver = DETECT, gmode, errorcode; 6 i1 L. k( a5 W$ E
int midx, midy, mode; 0 Z$ I! q8 S- T. ?
char numname[80], modename[80]; </FONT></P>2 {0 e4 g7 A, P/ J1 y& v
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 P$ @7 O4 R7 A) P! A0 E5 l# Jinitgraph(&gdriver, &gmode, ""); </FONT></P>
& ` |4 k! ^- Y<P><FONT color=#0000ff>/* read result of initialization */
1 X8 o* F& {$ y/ g8 Qerrorcode = graphresult(); 4 J* X" c; T4 Y8 \$ m
/* an error occurred */
) L+ r: I) K3 k" B9 @7 p7 eif (errorcode != grOk)
; P! ]! p, U9 h$ y" S; s1 ~{ $ {! P4 _% I4 v& B
printf("Graphics error: %s\n", / F' x# N# ~" X. c
grapherrormsg(errorcode)); ' F3 j8 ]' l4 G H2 ~
printf("Press any key to halt:"); 1 V3 T; g9 I1 a( ]2 L) B" g, ?
getch();
; J% w. b% B6 B# J# G9 z N0 l! L# S/* terminate with an error code */ ' J: ]. D1 ?5 z) l
exit(1); * {5 Z* Q- K) J6 A I& q& o$ }
} </FONT></P>* Y& P& Q* ^+ h# g- Z' f9 t
<P><FONT color=#0000ff>midx = getmaxx() / 2;
: ^; n. \9 ^& s2 E5 G/ A; `midy = getmaxy() / 2; </FONT></P>; Q; _* c) q$ E3 d
<P><FONT color=#0000ff>/* get mode number and name strings */ ' t; u/ C& f8 y
mode = getgraphmode();
8 C6 J0 @& v q% H O% G' @sprintf(numname, ' L' h7 y, G2 X/ j, B) @
"%d is the current mode number.",
0 q( I9 u# J: dmode); 1 q- x; q# a& v( ?
sprintf(modename, " ?8 G: d" g, J5 P" {1 |# `
"%s is the current graphics mode",
$ l- d; T8 q$ \1 ?getmodename(mode)); </FONT></P>- E/ \# ^3 d0 w" J9 s
<P><FONT color=#0000ff>/* display the information */
* G& l2 I3 i+ l0 R4 G- V5 u. ksettextjustify(CENTER_TEXT, CENTER_TEXT);
, A* f4 E2 _+ u) J2 p6 d' Zouttextxy(midx, midy, numname);
9 Q2 ~! G% v1 T8 K# w/ fouttextxy(midx, midy+2*textheight("W"), 2 ^" e* e% F7 L2 L3 v ?: _
modename); </FONT></P>
5 g. K, o- @) I; _<P><FONT color=#0000ff>/* clean up */
- G* _6 g7 k& x" a- ?5 F1 kgetch();
0 n) z/ X2 b- f) G* l+ Fclosegraph(); ! P6 y* Z/ m4 F# I% Y; T
return 0;
3 T8 x" i, [6 U1 a& _} 4 J& Z- n7 s( I, I3 T% e. I
</FONT>/ ]8 E5 ]8 U$ H% h8 ?
</P>) o! d6 m2 a: b: [% _
<P><FONT color=#ff0000>函数名: getimage </FONT> o" m! a' W) |' J, a% O" E7 n' Y
功 能: 将指定区域的一个位图存到主存中 * S, k3 M' j0 z
用 法: void far getimage(int left, int top, int right, int bottom,
. a+ P. W8 ?( }- o; Q% Y7 g3 gvoid far *bitmap);
- W9 d; e! k6 O S) T程序例: </P>
, P) m0 S0 J G<P><FONT color=#0000ff>#include <GRAPHICS.H>+ k5 @, f; x- b! D7 Q
#include <STDLIB.H>
8 J( g8 L# M: G#include <STDIO.H>
: }, x# l1 K( H5 f7 h: y7 Z' j#include <CONIO.H>: a4 c+ H- y. s- M5 L7 K6 [* ?9 Y
#include <ALLOC.H></FONT></P>
6 J' y. Y# ^, h1 L. w<P><FONT color=#0000ff>void save_screen(void far *buf[4]); 5 e5 d. A4 G4 |4 w, @* r2 `
void restore_screen(void far *buf[4]); </FONT></P>
: z# {8 E$ @% s& l( e<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>8 X( j9 Z' w2 c
<P><FONT color=#0000ff>int main(void) ! S% C9 r" k g2 R' d* C
{
9 s3 y' X) @2 z$ Q3 i, Aint gdriver=DETECT, gmode, errorcode; * g! k: ^. H+ m3 B1 \
void far *ptr[4]; </FONT></P>
% T* C% m, V+ M5 C# [<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */ , P* j( c, H) O+ \: c+ O& `
initgraph(&gdriver, &gmode, ""); # Q3 l, j5 T+ c" L3 q8 c/ I2 x
errorcode = graphresult(); /* check for any errors */
0 q4 D0 o! Z8 ]* x. Xif (errorcode != grOk) ' x0 b" ~- G5 A$ d6 m# n, s# P: G
{ 4 O2 } a9 x$ n- k# N, Y' c$ C
printf("Graphics error: %s\n", grapherrormsg(errorcode));
) i( V9 \/ O% {$ vprintf("Press any key to halt:");
6 R: K/ d0 z6 o9 t! M4 T$ m- j2 S5 Tgetch(); % R1 _% {' j* @' F2 c9 I5 W* G
exit(1);
; {7 J6 Y& r& D& O4 F% C} ; [0 I. u4 A% t: N' T8 G
maxx = getmaxx();
+ ^6 P: L C: s3 ]+ L j! Zmaxy = getmaxy(); </FONT></P>
0 C7 H7 j0 C6 ~8 T8 E% B) R. X<P><FONT color=#0000ff>/* draw an image on the screen */
2 B% Q! J2 H* B' E: Brectangle(0, 0, maxx, maxy); ! C, p) I n' T# a! o
line(0, 0, maxx, maxy);
9 L4 w4 \! j2 c2 G7 @# dline(0, maxy, maxx, 0); </FONT></P> L, c) r% |" C2 f" U9 |
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */
/ Q- t i9 ^! P7 Rgetch(); /* pause screen */
4 \( \5 j" i- e6 A0 }" ^cleardevice(); /* clear screen */
4 _% e& y+ D% A7 Crestore_screen(ptr); /* restore the screen */
1 V) R$ o( [8 Wgetch(); /* pause screen */ </FONT></P>9 U/ D* Z. ^2 ~
<P><FONT color=#0000ff>closegraph();
& d- |( g' z$ j+ T5 ^/ q% Treturn 0;
3 b4 x; p8 C/ W3 k} </FONT></P>
8 X( x; Q% R4 L1 ?" s<P><FONT color=#0000ff>void save_screen(void far *buf[4])
9 d" R2 G* d- y{
& U+ Z1 R$ p+ \/ c) |) E$ Kunsigned size; # F8 J! I7 i. H: z% y3 |; H: n
int ystart=0, yend, yincr, block; </FONT></P>
4 F* `* x+ e/ C/ m- A$ A<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
2 F' x# ?5 U0 }9 @8 H1 ] }yend = yincr; 3 I$ a5 q- v$ ?; t! u1 s
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>* y0 P. ]& i% j5 m j5 v
<P><FONT color=#0000ff>for (block=0; block<=3; block++) - O- q9 ^/ R. }# x3 [+ L
{
9 z" v# n7 y+ D4 ]if ((buf[block] = farmalloc(size)) == NULL)
" \8 _/ J4 W7 r1 L6 g/ a{
! D' w, E' x: }/ Hclosegraph(); 5 k, ]) p5 k O3 p/ R" L/ c
printf("Error: not enough heap space in save_screen().\n"); ; U/ L" V! C' A- R
exit(1);
5 z1 g) e- r1 \1 e8 _) ]} </FONT></P>4 x# W$ e9 _7 K2 J
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
) x& w! {# W, F+ bystart = yend + 1;
7 Q' o5 m' v- c6 M3 Jyend += yincr + 1;
7 L/ \8 }4 T7 a8 f" g7 `- ?}
$ h9 h2 B' V! m( t4 i3 G} </FONT></P># u0 z8 Q I2 Z+ L
<P><FONT color=#0000ff>void save_screen(void far *buf[4]) & ~" X- I; m) W2 L
{
: T' c( O7 q6 g4 T6 }" T4 Y% xunsigned size;
2 g7 ]& ?4 Q7 [- ]5 rint ystart=0, yend, yincr, block; </FONT></P>0 K4 K; ]( O/ t+ Z1 e
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
/ e6 H( U% j4 k: a! w3 _" myend = yincr; 8 c9 l) c) ~% }1 m1 A! { {& u A- m
size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>) o2 W) X, R* Y1 m: B2 u
<P><FONT color=#0000ff>for (block=0; block<=3; block++)
$ w3 @8 |/ b- S* R& P6 y{
6 }+ r( K0 r, S- o7 n! w" N# `if ((buf[block] = farmalloc(size)) == NULL) 7 f, K8 { N4 m4 V2 \2 F
{ ; W& X% M5 C i9 p7 [5 @
closegraph();
! S1 G2 ~* Y9 J. J8 ?printf("Error: not enough heap space in save_screen().\n"); 6 @) d- s+ {6 q- F, B" m. U6 v
exit(1);
# Z9 y4 Q* I( S, Z, x} </FONT></P>
' Q1 g0 x1 {6 v<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
; c( T( t. s n y% Wystart = yend + 1;
$ H0 Z' k2 w( y" ?+ R7 L5 _yend += yincr + 1; 8 |/ n! T9 t. g9 i
}
8 _# c, w7 e j$ ]$ i1 c4 n} </FONT></P>
6 K/ l0 _( T- z5 y @+ d4 w! h<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) 1 j- H% I3 `+ G: ^! z
{ 6 Y. r+ O# L* r" B- F, x- x' _8 C
int ystart=0, yend, yincr, block; </FONT></P>: |* i9 R* n- ~4 f J" n
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; 6 g1 a; b3 D# x( E! k8 [* y/ Z% |' Z
yend = yincr; </FONT></P>8 ^/ A3 y& [3 a0 J2 v
<P><FONT color=#0000ff>for (block=0; block<=3; block++) " h- @, c8 z5 R, s- F9 H$ c3 Q
{
, J2 L( b' `$ m1 T6 ?putimage(0, ystart, buf[block], COPY_PUT); , m" L3 f# f1 W' Z' r6 U& x
farfree(buf[block]);
( C& e2 B7 i2 T, g- r3 J; g+ l0 Kystart = yend + 1; 2 A9 e, v1 ?$ a& M# W$ c8 M* T& [
yend += yincr + 1; * S5 L/ L6 _( N1 @3 c6 p
} 5 B. N/ W8 `7 ?" H! d; ]
} </FONT>4 q, Q: e' l+ H* ^
<FONT color=#ff0000>" _# n# v5 D! S8 k3 N2 }+ ~
</FONT></P>
+ |8 ]) s* E& {( I<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
# s% } F& N& |功 能: 取当前线型、模式和宽度 ; i. M8 \* \: [% Z3 C3 e( ~
用 法: void far getlinesettings(struct linesettingstype far *lininfo):
. T, H* o7 P9 X/ L5 D u* u; [6 D程序例: </P>4 K( H( t! X1 ? U2 j% B; j
<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 P6 \& }/ M. m#include <STDLIB.H>
$ d# X: C. z6 n5 k. {#include <STDIO.H>
* R* F8 h1 u7 k2 e#include <CONIO.H></FONT></P>
: {" {( B8 i& V<P><FONT color=#0000ff>/* the names of the line styles supported */
7 {9 F7 c5 I0 ]& Achar *lname[] = { "SOLID_LINE", 5 v+ H/ d8 `. G4 Y4 b! x! N
"DOTTED_LINE",
) k9 O2 L- g8 U! i. q( {"CENTER_LINE", " w0 o/ J* J4 z* D: S
"DASHED_LINE", $ N7 _8 _# k$ N( b
"USERBIT_LINE" 2 w) J9 E' n5 M; h8 Y/ D; x
}; </FONT></P>
T% ~ d6 s" W9 f: [7 F<P><FONT color=#0000ff>int main(void) / t' t: h0 @7 T F' H# f
{ " K; @/ M4 N6 s! e) V/ v$ q7 U
/* request auto detection */
$ S( a1 Z; B4 e1 E* Z2 Pint gdriver = DETECT, gmode, errorcode; ) m8 e# f4 f: c3 N3 t: `
struct linesettingstype lineinfo; 9 l; U+ ?' t6 [$ O% }
int midx, midy; . B: k% [- i9 K4 n+ p( B
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>
1 ^* t- z3 g m! G9 v<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 J& y0 Z. M5 l
initgraph(&gdriver, &gmode, ""); </FONT></P>
! R; [5 G1 s, g0 J% g& ^. M<P><FONT color=#0000ff>/* read result of initialization */ * y. G- e: _! u; S) `/ d7 Z
errorcode = graphresult(); / [" X" h# j3 [( d9 X* w
if (errorcode != grOk) /* an error occurred */ 9 r6 E5 }# a& D1 i' a; r
{
/ {6 f; ]0 A2 x: D- K. w+ dprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, @9 K! U, y% R& Rprintf("Press any key to halt:");
* j" |" @3 q. Z: _, Ggetch(); , h" c$ C( [. S! J" c) t, f' [
exit(1); /* terminate with an error code */
/ O `; T5 `: r9 }7 o4 E& L} </FONT></P>" C, v4 a2 t, `, W8 `( N- q0 `, k- R
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) q8 r3 y: r( Q- \/ d k1 I, K! \midy = getmaxy() / 2; </FONT></P>
5 _* X0 N& B8 [<P><FONT color=#0000ff>/* get information about current line settings */
- }2 ~7 N9 N7 s4 y+ ]) [. i7 |5 mgetlinesettings(&lineinfo); </FONT></P>8 G$ |: L1 p. Q: k" O
<P><FONT color=#0000ff>/* convert line information into strings */
5 C8 X- `0 e$ }1 Isprintf(lstyle, "%s is the line style.",
8 o, R% ]( I) c; P2 ]% S( ^$ u' alname[lineinfo.linestyle]); 1 ~$ F0 y/ Z# [7 ]$ @3 q4 k
sprintf(lpattern, "0x%X is the user-defined line pattern.",
$ G% d/ X. K; O' d* d, Dlineinfo.upattern); " Y) L6 k+ } R* x
sprintf(lwidth, "%d is the line thickness.",
& `9 V; i8 q) V1 A( ^6 elineinfo.thickness); </FONT></P>6 Q, J9 L( n) g( _# n, D9 N
<P><FONT color=#0000ff>/* display the information */ 9 Z$ x, N5 c6 V$ ^% ?
settextjustify(CENTER_TEXT, CENTER_TEXT);
2 a3 V3 c6 ?) G6 j1 mouttextxy(midx, midy, lstyle);
L/ X; T, z8 I2 [' Y$ P U. uouttextxy(midx, midy+2*textheight("W"), lpattern); . s) l# [! `: P% k4 [6 R5 G8 m5 v
outtextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>- l: x K$ h. L+ `8 L, ^7 Y5 m
<P><FONT color=#0000ff>/* clean up */
( |$ X i4 T- [5 D# O8 Lgetch();
! l% V% x# H$ s& @closegraph();
4 Q" _5 D8 U/ M4 c( ?4 Q7 Creturn 0; + R5 F1 `) s; l
} </FONT>
8 P( c4 e0 ]- `% ^0 ^8 T. l, }3 i( z, b4 J! F
</P> |! d* K \0 v
<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>( K" p8 t- L; r0 v$ J$ M- S+ j
功 能: 返回可以传给函数setcolor的最大颜色值
3 A; j4 y. e( [; `( G% C用 法: int far getmaxcolor(void);
4 S! e3 i- z2 F- M' s: o程序例: </P>
S' E% U l7 T7 K, P) `( d<P><FONT color=#0000ff>#include <GRAPHICS.H>
" t9 M( Q- \5 S3 F" x$ w. S6 o#include <STDLIB.H>' o$ L; w- H1 B/ y
#include <STDIO.H>3 @# z* C8 E2 M* C
#include <CONIO.H></FONT></P>
$ _6 }, ?" O2 `<P><FONT color=#0000ff>int main(void)
- i. L7 b' U% j2 W{ 1 v) p( \ V! h
/* request auto detection */ : s8 L+ M& d, |$ S
int gdriver = DETECT, gmode, errorcode; p+ k: S( h8 }+ @$ l. r
int midx, midy; , h I$ | I6 }8 I+ O7 C: j
char colstr[80]; </FONT></P>
/ W1 O! ?; m; b5 H0 s) c<P><FONT color=#0000ff>/* initialize graphics and local variables 3 a! j+ H' D7 a
*/ initgraph(&gdriver, &gmode, ""); </FONT></P>
% a7 M1 P+ z2 Y4 ]5 W0 V+ m<P><FONT color=#0000ff>/* read result of initialization */ 9 S4 J W2 H) r% z; D' ~7 I
errorcode = graphresult(); $ T$ ^* L7 E# v5 Z% P5 r) p7 l
if (errorcode != grOk) /* an error occurred */
6 C, q; @5 y: @6 r2 c7 \{
5 |) r+ Q5 j1 F/ C( N, b {: sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 d# V$ h1 l; R0 h: v5 Z: K
printf("Press any key to halt:"); + x8 h# ^1 Q' f2 S. G* D
getch(); & x+ M; U) Y! G# j2 @) h( G
exit(1); /* terminate with an error code */ 7 F5 @2 X( g, i1 c/ `; n
} </FONT></P> X5 z2 e* n! x, d4 o s$ f' u7 ~/ {7 L
<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 x( \* M$ | N# q& `& P& Dmidy = getmaxy() / 2; </FONT></P>
- y! R9 U4 ]* N7 w/ @- H) Z4 M<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */ 4 G& N' j, ?* z P1 g
sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>
* m% i! ]2 A; v( q* x8 f, y, a. U# G<P><FONT color=#0000ff>/* display the information */
* ]7 V' x1 c$ e! p: v8 jsettextjustify(CENTER_TEXT, CENTER_TEXT); 7 J1 m6 y: S# A8 f- y7 Z O
outtextxy(midx, midy, colstr); </FONT></P>
9 Q$ j$ R/ G3 I! V6 c5 X4 w5 b<P><FONT color=#0000ff>/* clean up */ 9 z1 X( K- q, g* x
getch();
3 ~ V" H( N2 \+ l2 Q' d+ Uclosegraph(); . I% W# c# j" p' Y8 U
return 0;
% Y$ w# j1 C- {6 K+ d& z' K} </FONT>3 Y6 g) V: q$ z- W* n4 ]
% S& {5 F, Y$ I4 f, z
( t8 w* e# z6 w; q& P/ ^% X7 x
</P>% D5 z, I3 s, S: ^: \! @
<P><FONT color=#ff0000>函数名: getmaxx </FONT>( @+ v% ?, q: @, K$ ~
功 能: 返回屏幕的最大x坐标 5 Y7 k7 U; X4 r
用 法: int far getmaxx(void); 2 w9 M6 `3 c& {/ E. A/ {& j4 ]
程序例: </P>
0 W3 s2 N* v+ _<P><FONT color=#0000ff>#include <GRAPHICS.H>( h* O" ]8 X+ o& T3 A- }9 Y& F
#include <STDLIB.H>
$ O1 v% v9 C6 l' W% v9 @* b#include <STDIO.H>% A5 |# B. @* X! ]
#include <CONIO.H></FONT></P>
3 I) t1 b/ E/ C* A7 @ r) K<P><FONT color=#0000ff>int main(void)
$ w8 r$ r5 _: F' R$ w6 ~/ m3 S{
0 @) L- p! r1 {/ I" \/* request auto detection */ ) G; v# z" Z5 M2 ?$ u9 ^$ v
int gdriver = DETECT, gmode, errorcode; $ Q {* z/ G/ O7 c
int midx, midy; 7 m* d$ N: T7 {4 l b
char xrange[80], yrange[80]; </FONT></P>
: m9 X9 t5 Q9 z( W3 {' G2 X1 Y<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 R: b3 J4 s! a' Q, `* [0 oinitgraph(&gdriver, &gmode, ""); </FONT></P>$ F7 a8 X1 R4 W" @& Q
<P><FONT color=#0000ff>/* read result of initialization */ $ _# l; S! F6 ~. [
errorcode = graphresult();
4 c% @* ?7 g I* p' n, ^7 s8 oif (errorcode != grOk) /* an error occurred */ ; I; e3 k; R" ~! Y( `5 y3 b
{
3 D! C# Q+ D3 l* I) Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ W$ @( Z$ j( ^2 M) I; e3 ^
printf("Press any key to halt:"); # {4 A9 a/ t/ u9 i. b+ k! @
getch(); . P( C# |; h( u2 D# K
exit(1); /* terminate with an error code */
: d: i$ ]% Y ]0 s6 Y} </FONT></P>
# h* G" U5 O# _<P><FONT color=#0000ff>midx = getmaxx() / 2;
* p3 B+ `1 T6 x3 ^. D- L! Tmidy = getmaxy() / 2; </FONT></P>
, I3 V( b# n( |, f3 [ W& f% P: K+ C<P><FONT color=#0000ff>/* convert max resolution values into strings */
, ~. t F! @1 o+ r. Fsprintf(xrange, "X values range from 0..%d", getmaxx());
: M, [/ k# ]# B# m. wsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
: _* [' G" `" g<P><FONT color=#0000ff>/* display the information */ " Z+ j3 G* S1 O" s4 P( b
settextjustify(CENTER_TEXT, CENTER_TEXT);
, Z+ C' v: S' I1 Xouttextxy(midx, midy, xrange); 3 g; W) C* X$ C( g/ B4 g6 x1 T5 G
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>. d. S3 A( d9 |
<P><FONT color=#0000ff>/* clean up */ 8 |& r9 o5 |, N8 a$ z
getch(); 8 I$ X& l" p4 I% m
closegraph(); 9 v8 k) e2 s2 a2 ~" g# B2 C" m6 i' O8 M+ _
return 0;
" a$ t1 b4 {/ T) e; R, I}</FONT>
. J6 g" f: ^ p
* y: X) `7 z# j# Z( N</P>
; K8 `1 x2 t0 x# N) i4 ]<P><FONT color=#ff0000>函数名: getmaxy </FONT>- P8 Z; I- |" b2 E& p2 {
功 能: 返回屏幕的最大y坐标
/ O, y1 y" M& ]2 G8 k用 法: int far getmaxy(void);
& j! O8 I* |7 c% r* ?9 [' _程序例: </P>& D0 J1 e; B$ l" K
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: z7 d& n- _7 G" o+ W% E#include <STDLIB.H> f3 r* w9 j; @. T
#include <STDIO.H>! r/ K+ `0 [( L% c5 b
#include <CONIO.H></FONT></P>$ v/ k, D/ D, `8 @1 M' C
<P><FONT color=#0000ff>int main(void)
. ^+ p$ g& m/ A3 ^% y8 Z4 l{
' b4 o$ w3 Q7 J3 Z$ F9 E& {/* request auto detection */
9 H5 D8 z( u# C/ G3 z1 Rint gdriver = DETECT, gmode, errorcode;
7 i( u2 w& k. e7 vint midx, midy;
3 H- B, B9 y% v$ S) hchar xrange[80], yrange[80]; </FONT></P>
) w1 _9 g( j6 k3 j b' m4 j! u<P><FONT color=#0000ff>/* initialize graphics and local variables */
; o# v/ p7 {- q) `4 g3 ]. l0 @initgraph(&gdriver, &gmode, ""); </FONT></P>0 W: q6 M7 G! c' z: _
<P><FONT color=#0000ff>/* read result of initialization */ * _; W+ R ^# F% q4 v K l
errorcode = graphresult();
5 g+ P+ a+ v' Z7 eif (errorcode != grOk) /* an error occurred */ ) O/ Q5 L! w$ ^! H: x7 a# A( t
{ & A5 H" \! h8 k7 Q) F- |; Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 q. w+ J O' z# r7 `printf("Press any key to halt:"); " o, C/ C* ^- v3 l! z1 d4 S
getch(); $ w: z( L9 l9 }' B
exit(1); /* terminate with an error code */
+ T3 T5 j j& W% w& M} </FONT></P>
8 f$ h5 b" o( B! t5 B: l0 ^/ J4 Q" J<P><FONT color=#0000ff>midx = getmaxx() / 2;
/ x" H: e& a" |. Z' `midy = getmaxy() / 2; </FONT></P># Z9 E! e2 M: \
<P><FONT color=#0000ff>/* convert max resolution values into strings */ $ Q: X9 j2 U6 f% L: W2 u4 P
sprintf(xrange, "X values range from 0..%d", getmaxx());
, _, A2 T" p8 s; P5 S' Dsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
# K/ ?9 o) e2 d: s K<P><FONT color=#0000ff>/* display the information */
$ {) ?3 x9 U4 y; Isettextjustify(CENTER_TEXT, CENTER_TEXT); ; g' ~/ ?* d3 c, g( @+ U W' G
outtextxy(midx, midy, xrange); " ?4 ]+ R; u/ I4 [+ j! w1 h
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
8 ], ]1 C3 e) l/ Q8 `3 n( D<P><FONT color=#0000ff>/* clean up */ |" ?) ?: ^0 g" n
getch();
$ o7 L6 M5 Y& D8 U( Oclosegraph();
- D0 U, b! [" X- areturn 0; ' b5 h6 t, z" I7 J, m
} </FONT> X# E3 P) \+ Z0 x" m6 i) w# {
</P>
! k X2 F& _3 T% e, C<P><FONT color=#ff0000>函数名: getmodename </FONT>7 C) {3 \: d" e k5 B' ?
功 能: 返回含有指定图形模式名的字符串指针 ; O; j$ n. V2 N( g' |. J
用 法: char *far getmodename(int mode_name);
" E {+ x3 j) I1 ?& a- L程序例: </P>
J4 y$ k: G x: w" o$ M) g: o<P><FONT color=#0000ff>#include <GRAPHICS.H>; j, {) t# _8 U9 V
#include <STDLIB.H> ~* g% ^/ P9 V4 z
#include <STDIO.H>
$ a* K3 P4 I" a! e" z0 X8 m% E#include <CONIO.H></FONT></P>( g1 Z3 U0 L& Z$ B5 Q
<P><FONT color=#0000ff>int main(void) 6 a! W! G; e7 z# k- K* R% a
{ / P. B7 S5 R" Z$ O0 O$ q$ y
/* request autodetection */ 1 e+ u0 p P5 O; E& H4 I
int gdriver = DETECT, gmode, errorcode; ! L7 \ E% j$ I `, ^6 C
int midx, midy, mode; 3 t) ?$ c" e. E- W
char numname[80], modename[80]; </FONT></P>7 W* o" G( k, R. o+ I0 b% y/ D8 u1 n
<P><FONT color=#0000ff>/* initialize graphics and local variables */
* n, @7 r, f4 H7 K1 B8 I% Z9 ginitgraph(&gdriver, &gmode, ""); </FONT></P>
0 p8 Q2 d! e4 |1 }<P><FONT color=#0000ff>/* read result of initialization */ , E3 U t8 S6 N: R
errorcode = graphresult();
9 f. o1 k) E* T3 G% Zif (errorcode != grOk) /* an error occurred */
, ?: r0 C! z7 D) @; [{
" W3 I: e1 g9 e& Qprintf("Graphics error: %s\n", grapherrormsg(errorcode));
3 P% Z- o' x/ F2 d. yprintf("Press any key to halt:");
% R! s8 ^( E9 [' n3 i+ Kgetch();
6 U0 G8 U* ]3 N/ @exit(1); /* terminate with an error code */
" O3 I0 [# o. R/ H' j} </FONT></P>
3 i7 p+ S8 z' Y* R* p<P><FONT color=#0000ff>midx = getmaxx() / 2; 4 q4 J" [$ A# g9 t# p
midy = getmaxy() / 2; </FONT></P>' d3 }% b( p6 R2 t3 ]
<P><FONT color=#0000ff>/* get mode number and name strings */ 6 ^- Q) y" Y* {6 f4 g' Q9 J; S
mode = getgraphmode();
/ I4 {7 U- v: R1 G5 L8 T5 F1 Bsprintf(numname, "%d is the current mode number.", mode);
3 E2 y, c' X+ |/ U/ Zsprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>
; U( f- K( [' _$ @" k2 t3 p<P><FONT color=#0000ff>/* display the information */ 7 ?. x* ?0 k9 E; N: q7 F
settextjustify(CENTER_TEXT, CENTER_TEXT); + d+ n/ ]. a, ]8 }5 p7 \9 p2 X
outtextxy(midx, midy, numname); ( L. C4 n' a* I4 d# J* K% j
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>2 Y6 y1 O$ N- L1 }1 b1 m
<P><FONT color=#0000ff>/* clean up */ 6 Q$ f8 }9 C4 v# T6 e2 L4 e' ]' W
getch();
6 {+ w0 Q& ]3 ^( Qclosegraph();
& i* V" L b: U$ u6 ereturn 0; ( x6 _% j' p( g, O' c" l
} </FONT>% [3 B/ h7 @- F/ Q8 i4 P: O2 M, r# S* i
4 g2 X! ?0 _$ H</P>5 t" J2 u6 {6 t0 R& r+ }# _# `! T
<P><FONT color=#ff0000>函数名: getmoderange</FONT>
" A% h8 f; x( I( K9 c6 N% b3 ^6 i功 能: 取给定图形驱动程序的模式范围 ; D# T+ K8 g0 Z6 U! V
用 法: void far getmoderange(int graphdriver, int far *lomode, % g4 P% V0 ]. x1 }" D
int far *himode); . g* y9 d ]6 o
程序例: </P>6 T1 }: U2 Y1 \1 D8 R/ f9 B+ K
<P><FONT color=#0000ff>#include <GRAPHICS.H> z C9 h( X* D; b' d, Z# s( z
#include <STDLIB.H>
7 D+ @ d- [/ g0 O; W4 J1 S0 J#include <STDIO.H>
d4 ]. c' o( `9 X0 [#include <CONIO.H></FONT></P>0 i& @4 m9 z5 s2 E, x' W7 d: [, P
<P><FONT color=#0000ff>int main(void)
' { Z, [+ q8 j5 d7 _{ % }! s7 m: n! a5 r9 C
/* request auto detection */
, t N0 B. z O0 R4 u7 P" X2 Uint gdriver = DETECT, gmode, errorcode;
' d l8 }1 v3 b3 B% Vint midx, midy;
7 M& K- d, i j1 m# H6 l0 r) I% a# iint low, high;
$ R& w+ p: f) j5 qchar mrange[80]; </FONT></P>
; Y; n0 R% O% r! q, h- b<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 d1 J6 I, N3 T/ S1 o! i) g: u& a0 Hinitgraph(&gdriver, &gmode, ""); </FONT></P>. o( `" U5 M g# o* w
<P><FONT color=#0000ff>/* read result of initialization */ 3 |5 o; j: ~; G) b, V/ N! O
errorcode = graphresult();
" S# a0 _5 J0 j9 b* J& T' x! Cif (errorcode != grOk) /* an error occurred */ ; Y* V3 H G1 y7 x# ]% f s+ j
{ - T. e& R1 G* J2 u
printf("Graphics error: %s\n", grapherrormsg(errorcode));
w: b5 U: j8 Wprintf("Press any key to halt:"); ; G4 X0 X3 k3 Y' c/ f
getch(); & ]* O* w5 t5 o
exit(1); /* terminate with an error code */ 9 h6 f1 }0 e5 r" q/ c1 O- ?
} </FONT></P>" P' Y5 `' t# P: B. I$ |
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) r& j3 y: F! smidy = getmaxy() / 2; </FONT></P>3 T% [8 m+ U5 J; G
<P><FONT color=#0000ff>/* get the mode range for this driver */ 0 w' I3 m W t
getmoderange(gdriver, &low, &high); </FONT></P>
3 j& @4 @; m; [( e9 q2 a' w6 b<P><FONT color=#0000ff>/* convert mode range info. into strings */ : d J0 T/ ?; `$ x8 M: R) u, u
sprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>. f. V% |# K- M7 x1 u# W
<P><FONT color=#0000ff>/* display the information */ ! `# E5 V; H5 K( Y p6 N
settextjustify(CENTER_TEXT, CENTER_TEXT);
% h8 K% S. J7 H. g1 e* m* x4 zouttextxy(midx, midy, mrange); </FONT></P>% ^5 F5 v! {: M
<P><FONT color=#0000ff>/* clean up */ 1 {+ O' X2 W/ B( V; T
getch();
$ s+ k5 Q& s$ \7 hclosegraph();
7 D1 v( A+ D. X) }6 ?/ }return 0;
7 u+ }- F+ W- x8 M6 l1 N' l} 4 N( m2 Z& \5 y) T% [7 p$ o
</FONT>
8 A$ }5 o* y0 v: B) ^1 q( f</P>
0 _0 H8 @! ^0 L) }& E<P><FONT color=#ff0000>函数名: getpalette </FONT>
. a$ ?" B3 p d) ?6 o9 E功 能: 返回有关当前调色板的信息
- T0 ~& N, }+ J" F1 h! i用 法: void far getpalette(struct palettetype far *palette);
7 a7 b% c, V' {0 s程序例: </P>
i& c Z, V0 f% Z: g( v<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 o+ ^1 E6 o2 O+ Y( \#include <STDLIB.H> ]- J, s: _; J: a! i7 T, N
#include <STDIO.H>
$ T& g% g4 q2 Q& S) |#include <CONIO.H></FONT></P>
$ u) |$ L: u0 l i<P><FONT color=#0000ff>int main(void) & l3 |+ i7 X. w. i
{
5 j' i0 f0 M' [6 e/* request auto detection */ ( a# a6 @* _0 v
int gdriver = DETECT, gmode, errorcode;
- r4 T4 R0 X* h$ o9 k5 G( x) cstruct palettetype pal; - e3 w9 {! u; Q" S2 {
char psize[80], pval[20]; 7 t4 J _8 \' D9 b6 _# P4 p$ q) N
int i, ht;
; E9 x3 j: ~6 \3 lint y = 10; </FONT></P>
4 ^, W* M" P' h1 Y$ A<P><FONT color=#0000ff>/* initialize graphics and local variables */
& w! l7 T- P1 f! e" \7 O, I" f' m; J8 Hinitgraph(&gdriver, &gmode, ""); </FONT></P>) g( Q" \; t) V2 Y/ k
<P><FONT color=#0000ff>/* read result of initialization */
9 f5 u) ?$ u9 @# |' Serrorcode = graphresult(); ( e2 Q; X0 J j7 B6 X+ R8 y
/* an error occurred */
! [- w5 X0 u# xif (errorcode != grOk)
9 X' Z7 |2 L) A& w4 X. z) Y3 `{ 9 l. X2 L5 @# f; b% d! ~
printf("Graphics error: %s\n",
8 o# s5 s# N8 a5 H8 N( w( s0 Agrapherrormsg(errorcode)); , \% V0 L0 w0 E) w7 O5 f
printf("Press any key to halt:"); ; {! A& D2 }+ X) D) d6 k
getch();
' U( z1 J, L0 q0 m' m/* terminate with an error code */ . i6 t+ [6 \3 u4 b2 B0 R
exit(1); : m2 G! I: Q; G
} </FONT></P>$ R: T7 d3 z4 d" \6 L0 I9 z
<P><FONT color=#0000ff>/* grab a copy of the palette */ 4 ~5 v" I) T7 M4 T5 L/ x
getpalette(&pal); </FONT></P>
6 L, L7 F7 s8 t+ K" C$ [2 q! W; w+ E( R<P><FONT color=#0000ff>/* convert palette info. into strings */ ' P) m, c* \8 \
sprintf(psize, "The palette has %d \ 8 g' V9 S1 W: d! d
modifiable entries.", pal.size); </FONT></P>$ B: a* y" C" J
<P><FONT color=#0000ff>/* display the information */
: _; P4 H% |8 V1 e/ \& T2 n) vouttextxy(0, y, psize);
& ?$ X4 `) h1 v ]: q8 I+ Yif (pal.size != 0)
5 V3 q2 o. O; Z9 o! @) R" Z{
, ^: i! b( p' m0 f- Hht = textheight("W"); 7 C: C! D* C! F& C8 E0 p
y += 2*ht; 0 m" A! w, m" |' C
outtextxy(0, y, "Here are the current \ ' f4 v8 Q) Y6 c$ `
values:");
. w& { G5 }! _# _8 C- r g: j$ l4 `y += 2*ht; ( H% y: ~4 w4 S4 B1 }0 w; Z- B
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
8 O4 O" s* L2 D& |. psprintf(pval, % ~; W; ~; r1 D) T8 Y( t" [
"palette[%02d]: 0x%02X", i,
) S! [1 w4 H7 j$ Xpal.colors); & P" b. b! j B( x8 B& G2 _8 l
outtextxy(0, y, pval);
1 R) m" H" F( ~}
7 @( @) y8 J: g) k# t5 {1 G} </FONT></P>
: ?: e, F" } J( }# M& j7 N7 G<P><FONT color=#0000ff>/* clean up */ ) }3 y% q" G1 E. d
getch(); 7 D% \% ^# R T- ^% i) V6 F
closegraph(); </FONT>
) @6 j# q2 M4 {' o5 w<FONT color=#0000ff>return 0; 4 X1 s: h8 r) f9 n! X9 q# W
} 4 D. j, L# |' q
</FONT></P>
) R5 G! m% _% }7 {<P><FONT color=#ff0000>函数名: getpass </FONT>
# l6 p. s8 V; m/ [3 s, l功 能: 读一个口令 0 h( j0 J ^1 {& s" C. c
用 法: char *getpass(char *prompt); ) q6 ^5 I! s7 ~" x4 K& i$ f$ a, ?
程序例: </P>0 |0 a N/ o4 l, x, w1 U' N9 A
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
3 `4 w0 J. |" b4 E6 f<P><FONT color=#0000ff>int main(void)
6 H7 D5 V) }1 L4 X( w! i{ - t; K* a! y9 A0 w5 s) E* w
char *password; </FONT></P>
5 `+ a& Q) J! S<P><FONT color=#0000ff>password = getpass("Input a password:"); * N3 i2 e m; g! Z) ]0 G: K3 S5 W \
cprintf("The password is: %s\r\n", u* ]# H( a% m4 p
password); & v( D" V0 H! O: n4 B
return 0; ' u- n! r5 q. z
} % b: X, b+ j4 l; n! `+ B+ |
</FONT>
4 b! ?, h0 ~( B6 N! C" @6 j7 ~) Y' W: J+ D |: ~
</P>, F* v! L" k3 Q( ~7 W: p
<P><FONT color=#ff0000>函数名: getpixel </FONT>, y% |7 _8 w l1 u; {
功 能: 取得指定像素的颜色 5 |- E+ F( ^' a9 Q$ B S: k0 ~/ y
用 法: int far getpixel(int x, int y);
$ i* k! ^0 [$ I, H2 o程序例: </P>
- E# g7 l$ {) G9 |+ U! n4 x. }<P><FONT color=#0000ff>#include <GRAPHICS.H>
& |$ |! K6 O) P#include <STDLIB.H>+ v# \. a$ b' B" F$ H! y- v% \
#include <STDIO.H>
+ C7 d9 e/ E; f) u) T#include <CONIO.H>2 U( k7 K9 r% w6 h d8 a
#include <DOS.H></FONT></P>
0 ]9 d" p4 F ]1 p<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 5 \$ x# n s5 V) b) N
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>. o! M: v- O8 g7 C, X3 E
<P><FONT color=#0000ff>int main(void)
4 C7 [6 t" s3 K0 _{
: `$ q }. Y* H8 R; y6 e* W5 l% C0 R/* request auto detection */ ) f9 Z2 Y6 M% d' I! D7 q" q
int gdriver = DETECT, gmode, errorcode; 9 o4 W' d( u- V2 o8 ~
int i, x, y, color, maxx, maxy,
7 w; U" ]9 w4 k- V* }/ ~maxcolor, seed; </FONT></P>
/ E# U- v$ M' a( n<P><FONT color=#0000ff>/* initialize graphics and local variables */ % g1 M+ C' ?+ m) G
initgraph(&gdriver, &gmode, ""); </FONT></P>2 Q3 H; f0 _+ o4 U- b
<P><FONT color=#0000ff>/* read result of initialization */ 2 Q2 I0 {) N ^: l, M% M, O, }# H4 t
errorcode = graphresult(); , P% T8 W' \7 E" l& d% Q) n5 f
/* an error occurred */ * F& V# m9 e+ d
if (errorcode != grOk) 1 R# e! R" i' V3 g3 G1 h. i4 _
{ # y [7 \7 x+ T% ]
printf("Graphics error: %s\n",
' ^7 c2 L: S8 n9 Y( C- u1 \0 Zgrapherrormsg(errorcode));
9 J; i3 e8 a$ D" J1 e& m, Dprintf("Press any key to halt:"); + ~( t* b* h1 l* l- I3 s
getch();
" @9 R4 |& S$ ^5 E: S/* terminate with an error code */
5 c9 k/ s* M& d5 S7 v* w6 z: a/ aexit(1);
* E S& q- g5 K2 x; P) N} </FONT></P>
! E' r0 E& [6 d& |+ D: b<P><FONT color=#0000ff>maxx = getmaxx() + 1;
: H* m$ S; Y/ b' u" L, wmaxy = getmaxy() + 1;
( o; z3 e! T7 q% O7 Gmaxcolor = getmaxcolor() + 1; </FONT></P>- C0 C$ I" i0 m9 @/ z# F
<P><FONT color=#0000ff>while (!kbhit())
) H4 H; j2 j& ]' E{
, ?& L7 J' ]8 |# g5 A* y/* seed the random number generator */ ' V v0 L$ P- i. O1 `
seed = random(32767); {% T" a' B3 M1 x
srand(seed);
4 F+ ~) l: _* Q }for (i=0; i<PIXEL_COUNT; <br i++)> {
6 W$ r1 u- o- d5 @x = random(maxx); / _$ w G- h1 x" R! j" B* C( S0 C
y = random(maxy); * Y& o6 \ G+ G' I
color = random(maxcolor);
; n- O5 R* s, j' Fputpixel(x, y, color); 9 ?8 \" d# `5 G1 v; ~5 N0 D ~
} </FONT></P>
- c" P: m; n) S- n9 o<P><FONT color=#0000ff>delay(DELAY_TIME); ) _+ {1 B# |9 ~
srand(seed); . ]' x2 V$ B# c, R% s4 Q" a
for (i=0; i<PIXEL_COUNT; <br i++)> {
! A3 U$ F2 A. U* ?# r* w( v& G d- Tx = random(maxx); 0 m% j4 e7 J/ x( q( @
y = random(maxy); / Y) E! M7 y6 y/ S5 S2 _) [
color = random(maxcolor);
- H3 L4 Z- m e( F2 R' Bif (color == getpixel)</FONT> </P>
- i7 z' J$ {. d1 T<P><FONT color=#ff0000>函数名: gets</FONT>
, [& p/ O6 B2 h/ F; s: `7 y. t功 能: 从流中取一字符串
( J( E4 e$ N5 ]1 K用 法: char *gets(char *string); / i) T" p) F6 Z# N( @" t6 k
程序例: </P>+ s9 w, o9 k2 } E: j( {. {
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>" B1 ?- Z2 J9 k8 S% [6 G' }
<P><FONT color=#0000ff>int main(void) 9 n' T- s# C, y9 k5 i
{
) n) v4 f5 L/ s! {3 c( wchar string[80]; </FONT></P>6 G, V3 U6 ^2 S
<P><FONT color=#0000ff>printf("Input a string:"); 4 ]8 P( _. L# a+ s
gets(string);
( p- _( o8 ^, z- gprintf("The string input was: %s\n", & p/ G" ]' P6 K( ^& \. D
string); 7 m3 y& N* P8 X$ F; t( J* k
return 0; l) S S( l# x5 ?' P
} 8 \# J/ e' r9 k8 O9 @* c/ A
) h# j$ _/ _, o5 p- W& Y$ Y</FONT></P>
: d7 v, q8 Q' J% b% r! ]" o. ~<P><FONT color=#ff0000>函数名: gettext </FONT>1 ^5 v( B8 x, W1 m* H
功 能: 将文本方式屏幕上的文本拷贝到存储区 & z! V( a) ~! C+ c& B
用 法: int gettext(int left, int top, int right, int bottom, void *destin);
2 D; `# H2 Y& }% T程序例: </P>
6 i* l% Y% h( ^<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>" W' U- v2 K: `/ \. \3 x; z6 o
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>( v. L$ h, H% T2 k
<P><FONT color=#0000ff>int main(void)
. A0 r0 s( V$ H8 m9 r" F% \. g! @{ 9 ?$ C( N) F# y
int i; k( c2 S9 b# y9 h- H
clrscr(); # c" L9 }- j; U" m
for (i = 0; i <= 20; i++) ! p1 v4 V' n9 E) j; b
cprintf("Line #%d\r\n", i); / R& T; o/ }& ~8 L% L. i
gettext(1, 1, 80, 25, buffer); - z9 W% [4 q4 h4 ]8 j% {
gotoxy(1, 25); / D; L, k& G$ F! e; y/ L
cprintf("Press any key to clear screen..."); 2 F4 H2 u& r- U; g1 U' N/ ~
getch(); * u5 u, d& [ F
clrscr();
8 z& [) }2 P) p: Kgotoxy(1, 25); 8 L7 v) Z/ d4 {8 \3 v
cprintf("Press any key to restore screen..."); 2 n3 I1 Y) }" @2 n! T2 H
getch();
, y+ t2 h5 v$ ]- X6 a# J4 D1 Cputtext(1, 1, 80, 25, buffer);
$ X3 @: x4 `; [" f1 xgotoxy(1, 25);
$ P7 ]* ~+ f$ M! q1 r" v, G9 ~' [0 acprintf("Press any key to quit...");
6 Q% \) [7 W, i! `5 v# u/ Y+ Vgetch();
! U: M' j4 D2 ^) R8 `/ ereturn 0;
|# v# E+ a8 a/ s2 I, ^}
, K" J; G6 \& M& [: e3 K</FONT>1 w& E1 }" J+ U& Y
</P>
% G7 Q: ?' p4 l2 J) o/ Z I<P><FONT color=#ff0000>函数名: gettextinfo</FONT>
" q6 K$ V9 c! B9 r3 C功 能: 取得文本模式的显示信息 1 G O- y' Z4 Z$ C" ^; Z7 \
用 法: void gettextinfo(struct text_info *inforec);
6 }( \9 r. T& H* k程序例: </P>
1 w2 T( v1 t' K+ O4 [/ _3 h: C7 D( j<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>. i, {7 p* Q( S1 |$ w* J
<P><FONT color=#0000ff>int main(void)
, ~# f5 R5 U( L' w- _{
* t( N# c A! O$ ]' ]7 h, xstruct text_info ti; / R& A4 u8 i5 O+ }
gettextinfo(&ti);
7 ^0 Y8 {9 M4 \7 ]; }/ dcprintf("window left %2d\r\n",ti.winleft);
- G" p. {/ D- w8 r8 u i: s5 Ycprintf("window top %2d\r\n",ti.wintop);
2 n% L2 R8 V3 zcprintf("window right %2d\r\n",ti.winright);
: @6 ?$ P4 w7 E# y- rcprintf("window bottom %2d\r\n",ti.winbottom);
$ a, C3 E9 f' A z; L3 i* gcprintf("attribute %2d\r\n",ti.attribute);
- f8 K4 o p' E1 s. O1 `( fcprintf("normal attribute %2d\r\n",ti.normattr);
6 ^; H3 ]8 r* f8 H. M+ H' rcprintf("current mode %2d\r\n",ti.currmode);
/ U$ m6 U% H8 Ecprintf("screen height %2d\r\n",ti.screenheight); 9 r. w! A( o$ y$ E6 } d
cprintf("screen width %2d\r\n",ti.screenwidth);
, L. } W- @7 t/ A8 Ocprintf("current x %2d\r\n",ti.curx); : Y. X$ N4 F$ a: K k l' |
cprintf("current y %2d\r\n",ti.cury);
$ z& x. o$ m* X) X2 ^return 0; " `* V r3 Y0 Q8 ^: b
}
/ b; R. w: n! G4 M6 O, q7 `; Q</FONT>6 T0 s# F$ f6 }$ [1 \, g8 T! z
</P>
1 A* W7 ~% u2 x7 X5 C! I<P><FONT color=#ff0000>函数名: gettextsettings </FONT>' }- M; n- y0 g ?$ P3 ?7 S
功 能: 返回有关当前图形文本字体的信息
! M6 |8 k) i& ^8 s0 V2 u a+ G$ s$ K用 法: void far gettextsettings(struct textsettingstype far *textinfo); * ?2 G ]& _* ^
程序例: </P>1 U. R. f& J, O |% E# Y, e
<P>#include <GRAPHICS.H><FONT color=#0000ff>
4 P! A3 V+ k. \' w% M# ~#include <STDLIB.H>
5 r- M3 h) r+ E+ @; q#include <STDIO.H>) C4 I+ ~6 T4 r% q" L+ F ~9 p
#include <CONIO.H></FONT></P>4 Y5 N* r# ^- f6 I, q- D& s
<P><FONT color=#0000ff>/* the names of the fonts supported */
8 P% E$ I5 K/ j, i* t, |: T- W+ d' {char *font[] = { "DEFAULT_FONT",
4 F2 Z& V. O* l# ^"TRIPLEX_FONT", 1 @6 T5 U+ V- m0 S
"SMALL_FONT", + ^/ ?4 v7 V5 \& Z- D6 M
"SANS_SERIF_FONT", ! Y x5 M0 ~2 b5 ~6 q
"GOTHIC_FONT" 7 k6 ?9 F0 [7 D4 t G) u0 j' w# C
}; </FONT></P> ~; X. K2 m8 H/ m
<P><FONT color=#0000ff>/* the names of the text directions supported */ " e _; q& I) m
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>) b( \6 V ]% v; h6 A, n) @
<P><FONT color=#0000ff>/* horizontal text justifications supported */ 7 F& M2 b6 e* x2 C) c
char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P>6 ]) R) z: g' Y7 {5 T3 K
<P><FONT color=#0000ff>/* vertical text justifications supported */ , m" u; t7 k# x0 `
char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>( ~9 f: N! S7 d I1 b4 S( S8 C
<P><FONT color=#0000ff>int main(void)
' o6 h* ?& I; b# O" Z! S{
1 M3 R2 }0 v$ w R/* request auto detection */ 2 d" t. m' i! D* G& y8 Q
int gdriver = DETECT, gmode, errorcode;
+ ~& j1 ^3 H6 Z: V) I0 [# Astruct textsettingstype textinfo;
+ |* g6 P* v) T" ]6 v+ aint midx, midy, ht; ( q( [. @5 s; \' }
char fontstr[80], dirstr[80], sizestr[80];
+ x j. k# Z3 e. X& J& S0 Xchar hjuststr[80], vjuststr[80]; </FONT></P>8 i r8 I: v ]& Q* ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ ]3 o9 _4 V$ O4 K7 x; |
initgraph(&gdriver, &gmode, ""); </FONT></P>- q) A: }$ L* _8 j
<P><FONT color=#0000ff>/* read result of initialization */
. R3 a h, |/ y5 xerrorcode = graphresult();
; \" a- @# c( T9 [ u( y( l7 Wif (errorcode != grOk) /* an error occurred */
6 c/ i4 U b, l4 Q{ . M8 v( x) E4 ?
printf("Graphics error: %s\n", grapherrormsg(errorcode)); , ~+ u. f* a2 C; D! L
printf("Press any key to halt:");
, w6 t9 y7 ]( d+ Sgetch(); + P' U& o& h9 l) q/ y/ J
exit(1); /* terminate with an error code */ 6 a& X0 }$ v; D5 ~* m0 ^7 p
} </FONT></P>
@' q2 v8 ]! F5 \$ b5 `* D<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 G: u; U5 s2 D
midy = getmaxy() / 2; </FONT></P>0 V+ E, r* @2 I8 t! N5 D `7 ^% s# V8 h
<P><FONT color=#0000ff>/* get information about current text settings */
1 j& ]+ _: P% P1 N4 |gettextsettings(&textinfo); </FONT></P>
6 M$ i8 V2 P: n* `4 g6 r3 ~' T<P><FONT color=#0000ff>/* convert text information into strings */ 3 I/ }+ A$ v* r3 E* ^& T; ]
sprintf(fontstr, "%s is the text style.", font[textinfo.font]); 4 N: @0 S# ^* N- a' Z% _3 o) a, c
sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]); 6 _' c1 n" Q8 Y# @
sprintf(sizestr, "%d is the text size.", textinfo.charsize); 6 [1 n: ~2 w' @/ j/ W9 M; @8 r
sprintf(hjuststr, "%s is the horizontal justification.", 4 u; Y" K" r V4 K
hjust[textinfo.horiz]); 4 _3 E4 p- G/ T
sprintf(vjuststr, "%s is the vertical justification.", " l& \9 P2 S' a! B
vjust[textinfo.vert]); </FONT></P>3 V: a/ p* s* G+ j* Z P+ P
<P><FONT color=#0000ff>/* display the information */
1 }) e4 s) V2 u% v$ k# Y4 ]8 Y& pht = textheight("W"); 9 |7 a, o9 T* m# s: X
settextjustify(CENTER_TEXT, CENTER_TEXT);
0 V7 ] A4 ~8 k0 e3 mouttextxy(midx, midy, fontstr); 7 H# t& ~ O6 u+ C) Q( O
outtextxy(midx, midy+2*ht, dirstr);
( W/ r3 ?# h- x) o bouttextxy(midx, midy+4*ht, sizestr);
1 ^' }! v2 \5 P5 o6 ?( J4 Iouttextxy(midx, midy+6*ht, hjuststr); . _5 |8 {, s- Q a0 N
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
' y' I1 y' W) I0 M, |) t<P><FONT color=#0000ff>/* clean up */ 5 x! Z" A0 N- E1 r; d' t! c
getch();
% d% |4 y0 ^/ f P- `7 Tclosegraph();
. L4 t+ g0 S) i' dreturn 0;
2 i. Q- A# u: N. D' {} </FONT>
, h* n; B) t# J6 B: X3 Z4 R& a</P>4 V4 _$ b3 `* D9 A0 {: q, A
<P><FONT color=#ff0000>函数名: gettime </FONT>
5 u) i! }1 I$ J功 能: 取得系统时间 ) @8 i# \' ^1 h2 x' A/ x
用 法: void gettime(struct time *timep); ! E( u% G9 f' D! h% L" I( i
程序例: </P>
) |6 v6 `4 l d4 ~1 F4 E. l3 v% c<P><FONT color=#0000ff>#include <STDIO.H>
+ f8 Q) D( R) Y8 }6 s#include <DOS.H></FONT></P>
9 }0 o: }$ [. v' g! K7 O<P><FONT color=#0000ff>int main(void) 9 R9 P" e! L! g' J1 g# A9 _
{ ! U. C1 S3 }9 ?
struct time t; </FONT></P>! E& G- {4 J- k. }
<P><FONT color=#0000ff>gettime(&t);
) M' y" |6 R$ o! A+ L; t, ~printf("The current time is: %2d:%02d:%02d.%02d\n",
3 L7 w! z# Q% a+ }. |t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); 8 l1 Z- \. r9 Y [0 r' N+ u) V! ]
return 0; * D7 P+ R' \. L1 h: O8 }
}
1 d, G- L9 l$ h5 P; Y$ A, o. m- w1 k: R" J- E8 B8 k
</FONT>5 Y( v, n2 r# N6 t1 c% i4 r; s% W
</P>1 B3 [! w! I/ c6 _# ]9 O
<P><FONT color=#ff0000>函数名: getvect </FONT>3 Y6 r, B" k4 N$ C. M
功 能: 取得中断向量入口 . b+ @9 b+ b$ F7 g! q7 O" A3 f
用 法: void interrupt(*getvect(int intr_num)); * t7 x' V5 {- K! W, Q* l/ B' F
程序例: </P>
0 {0 x9 ]% F8 z9 V; C& m- d5 y<P><FONT color=#0000ff>#include <STDIO.H>
! _6 I! O. B& g, P, x' S7 z% d0 S8 a#include <DOS.H></FONT></P>
& m9 z& x- |0 v<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
) V Z7 q, j. A$ Y* T, {) v; m# x# O<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */ ( S4 ?2 o% w+ Y- v
int looping = 1; </FONT></P>
0 z5 c" Y( K7 C8 F<P><FONT color=#0000ff>int main(void) 5 G; n2 @& c9 R! ]- O& a* C9 G
{ ! _; k: P+ G+ Y& w
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>" S* C- Z1 `. D' r, O# q1 |: F" b
<P><FONT color=#0000ff>/* save the old interrupt */
: i2 r, @! T) M, d. O, Z3 Goldfunc = getvect(5); </FONT></P>! i, |0 b$ U1 |/ f! X0 J: @
<P><FONT color=#0000ff>/* install interrupt handler */ ) S: G( R9 I5 j3 m* C
setvect(5,get_out); </FONT></P>: L2 c9 u* z2 t% {/ |9 j" S8 Z
<P><FONT color=#0000ff>/* do nothing */
) D1 k' c& j( b" g; A. dwhile (looping); </FONT></P>; {# t' }3 S$ k# j3 I2 U( i& [; h" B
<P><FONT color=#0000ff>/* restore to original interrupt routine */
! K E- B! z) Hsetvect(5,oldfunc); </FONT></P>+ [( G' o/ M% ]7 k
<P><FONT color=#0000ff>puts("Success");
$ h3 O0 k& a4 Z3 Z4 ]return 0; 1 X4 k% b' H4 p! F
} ( ?4 v' v/ Y4 b( J9 Y$ Z
void interrupt get_out() : `$ s# n' M7 q o" L
{
6 h7 G2 V, q9 Ulooping = 0; /* change global variable to get out of loop */
1 H) f1 b5 J2 T}
* w: A; d7 ^1 W0 }' D: H+ A T& e</FONT>
' c1 |1 U( X; Z/ i4 I8 g& w</P>
/ l8 X% l: U! S' g: m, W/ O3 S/ f$ q4 ~<P><FONT color=#ff0000>函数名: getverify </FONT>$ h! d; l% r; T- p( p% G
功 能: 返回DOS校验标志状态
: n6 n3 V5 `6 f) H用 法: int getverify(void);
: ^) _5 h" C3 {$ x程序例: </P>, I% Y+ s$ F0 J, [0 f( F
<P><FONT color=#0000ff>#include <STDIO.H>
* N0 ?; z5 {. _5 O& g( o! A#include <DOS.H></FONT></P>) [) x( y' X& e+ O: ?: z( Q% p
<P><FONT color=#0000ff>int main(void)
/ ]$ K6 D/ {7 k4 {1 K{
4 f5 O2 \* E$ w6 {if (getverify()) / U* u' ^) }1 ?
printf("DOS verify flag is on\n"); 7 ^3 d1 J- U7 n/ [* b6 }0 h5 e( T
else 9 W/ p# }4 b0 \# K) @1 N
printf("DOS verify flag is off\n");
* C8 P; l$ J/ C8 O Q9 A* Freturn 0;
' t- u1 `% E. ?' V1 m}
% K/ I1 {0 l( M4 D</FONT></P>
7 T2 a7 @ F" N6 s<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
' B; d; W8 ^1 s }) k0 l6 F' Q功 能: 返回有关当前视区的信息
$ t0 F" l$ X0 {* p4 K X用 法: void far getviewsettings(struct viewporttype far *viewport); 3 H+ d+ I0 b8 n+ P
程序例: </P>
* S3 \4 Y! s/ L N3 O<P><FONT color=#0000ff>#include <GRAPHICS.H>
. \9 g# W: l( I0 G; E#include <STDLIB.H>
! i& _3 ?8 i5 a# R6 K#include <STDIO.H>4 |8 q. a: q* l" l6 c, J+ f; \
#include <CONIO.H></FONT></P>
" c/ ~* U; d* V* A+ Z<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>
9 t1 S' c7 f+ Y8 }<P><FONT color=#0000ff>int main(void) ( v7 z3 i% ^$ n4 ^9 T5 |0 p
{
8 L# a! G) i# C5 [7 G/* request auto detection */
. t/ D3 B! i/ q8 b) Bint gdriver = DETECT, gmode, errorcode;
. `! R& X3 i8 g* t+ ^# }struct viewporttype viewinfo; 4 |4 s$ m$ T6 w/ E
int midx, midy, ht; 8 d0 ?0 W4 y' j* M9 Z% N
char topstr[80], botstr[80], clipstr[80]; </FONT></P>
% C' e0 D, H: D/ M6 U# [2 B7 ~! L<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( d2 B; k R9 D% X, J" D9 u# J
initgraph(&gdriver, &gmode, ""); </FONT></P>
/ `% u8 S# k* c6 C: r. J g<P><FONT color=#0000ff>/* read result of initialization */
+ e& \" L8 h- P6 Z, w6 u( C/ B' cerrorcode = graphresult();
* X6 O/ N A- H! r2 f9 s$ Z8 |if (errorcode != grOk) /* an error occurred */
3 ^) Y' ^) L( n{ # ^/ e8 c# M/ o& A. j
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) Y# j- z( U+ k( T2 G+ D
printf("Press any key to halt:");
+ c/ D" ~3 |4 f) {1 Z" [; E# L$ f" Wgetch();
' O+ ^. v& G1 A; Rexit(1); /* terminate with an error code */
- v4 J& }6 B. ]7 L: q} </FONT></P>' r" @+ ]7 q: D: j
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) m! h, N$ X9 L1 ]: O8 xmidy = getmaxy() / 2; </FONT></P>
, L9 ]. |4 e. F; E6 j<P><FONT color=#0000ff>/* get information about current viewport */
g- C1 k7 j* E& ]getviewsettings(&viewinfo); </FONT></P>
2 _. M4 ]2 C& Y/ P- I) t<P><FONT color=#0000ff>/* convert text information into strings */ : H; ~" |/ z3 ^/ p( W$ v) U
sprintf(topstr, "(%d, %d) is the upper left viewport corner.", " Z5 i. J# [" U+ ?
viewinfo.left, viewinfo.top);
/ `/ T7 n }: U3 ]) H& h6 i1 k1 Ksprintf(botstr, "(%d, %d) is the lower right viewport corner.",
7 C, p: m! E L7 H+ Wviewinfo.right, viewinfo.bottom); M0 L: @6 o1 M: Q4 Y
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>
) w7 U4 N; f6 r5 ]& a7 X3 v# |<P><FONT color=#0000ff>/* display the information */
/ I+ m- k4 D5 T: J* wsettextjustify(CENTER_TEXT, CENTER_TEXT);
$ q* Q7 Q: f1 T. E9 g6 q0 ~9 b% cht = textheight("W");
3 |4 h' Y' I$ m) V* W- Touttextxy(midx, midy, topstr);
6 E4 X# ]1 O! o# a" Kouttextxy(midx, midy+2*ht, botstr); - b: p) Z! r" a2 g8 h* _
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
/ L! t% y6 R4 Q2 U1 L<P><FONT color=#0000ff>/* clean up */ . n/ O% i( d2 ?$ b2 Q
getch(); $ h+ _& b0 u0 u8 y7 ?0 e* `
closegraph(); * p* G8 r5 i6 ^; P; e
return 0; 4 J2 h; f% z/ C" i
} </FONT>$ q9 z; W( J6 V# r( m
! o% y7 u. \$ R- B! Z
</P>2 s, l4 c: R$ f* T1 d; d4 z
<P><FONT color=#ff0000>函数名: getw </FONT>
1 S6 C) H1 e3 p A# Z6 h功 能: 从流中取一整数
4 B3 |( a* R7 K0 w4 e6 ^- n用 法: int getw(FILE *strem);
- u$ A& J- Q" _; B1 C程序例: </P>
* C# g- w6 ?' m: V6 q<P><FONT color=#0000ff>#include <STDIO.H>
4 v% [' s1 p5 F. N5 A; v$ ?#include <STDLIB.H></FONT></P>
}9 p4 E. O9 S* E& ^' ]+ \<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
% h6 m- ]' h) L5 M# m% P% h<P><FONT color=#0000ff>int main(void) ' B9 E; J0 x+ s) s3 ^
{
- j$ L) B; ^5 O8 | W) zFILE *fp; ( P( R" s* Q' y
int word; </FONT></P>
/ W. \% ^; w. r6 ^# i! G1 Q; m' i<P><FONT color=#0000ff>/* place the word in a file */ 8 m7 D/ A2 Z d: T' u
fp = fopen(FNAME, "wb");
3 T! `5 S2 ]" d; m& f! vif (fp == NULL) 2 V& W, b0 L: x; D% C, o) x
{ ) ^4 c6 O. R. N" F/ Y
printf("Error opening file %s\n", FNAME);
. c+ t# ]" o) g6 jexit(1); # E' ]: U: _( ^, p
} </FONT></P>
/ x% ? c ^+ `4 y<P><FONT color=#0000ff>word = 94; 6 t: X: x: O0 ~/ K1 e$ \
putw(word,fp); + F# o# @! ^( \1 y, R2 G$ T
if (ferror(fp))
. Y+ w. q3 e2 F: H0 Zprintf("Error writing to file\n");
6 L* q# F% D0 j' T6 ]% welse
9 O7 e: U8 S2 t/ ~5 q* V ]# Z/ z4 `printf("Successful write\n");
9 `4 l) ]" P( x, ^) ffclose(fp); </FONT></P>. K6 `9 Q4 J7 V
<P><FONT color=#0000ff>/* reopen the file */ 3 b+ I# h- r @
fp = fopen(FNAME, "rb");
6 `8 Z3 |, r3 _) E- L) g- wif (fp == NULL)
0 `* o: y$ ]( x* G{ ) B4 B) s# S- |6 J& h
printf("Error opening file %s\n", FNAME);
# c7 s0 S' c/ \. ?7 R( Bexit(1);
, L! }: {0 B1 G6 R4 r* G} </FONT></P>
) V7 ~+ ^! ]6 Z6 m9 t<P><FONT color=#0000ff>/* extract the word */ 3 q2 j! ~; F9 F, N) y# g
word = getw(fp);
' e2 _/ I; j# ]2 Y" N" c0 nif (ferror(fp)) ! K5 Z) w( |* `: M% |8 ~& M! t
printf("Error reading file\n");
3 v: I' {/ z" L9 x) ^ felse
* }3 S: H% E& c- J2 Y, D8 k% Mprintf("Successful read: word = %d\n", word); </FONT></P>
' R! p5 g5 U4 Q8 `+ u! n, S<P><FONT color=#0000ff>/* clean up */ " e2 H* [: o" h8 u% V7 z! D
fclose(fp);
i, U% U+ J1 d, ~unlink(FNAME); </FONT></P>. L+ E$ `- W2 g: w3 J& l0 [
<P><FONT color=#0000ff>return 0; ) d5 ~7 k9 l- I
} </FONT>) Y7 G" l5 m( g1 L
~$ Q9 D5 d& C5 H
8 m7 x# u2 S( ^1 O1 A</P>; g. h& F* S2 ?* _% ~
<P><FONT color=#ff0000>函数名: getx </FONT>
# \; B3 c6 P o7 ?功 能: 返回当前图形位置的x坐标
4 q r7 C: v- q; f) @ ?用 法: int far getx(void);
0 {( e5 H+ ]) I, C程序例: </P>( W: _8 u1 x7 r# S. t: _
<P>#include <GRAPHICS.H><FONT color=#0000ff>
8 s+ P6 a& c1 a#include <STDLIB.H>
9 S8 _1 l' d/ w. x; F) \/ e B! J- m#include <STDIO.H>! m. S7 R2 \% B7 d# v
#include <CONIO.H></FONT></P>0 i: w% x( K; t9 I, `
<P><FONT color=#0000ff>int main(void)
5 r. T& A" A5 E: q7 p{ : L5 T2 }$ {: t0 ]$ p1 F, e ^
/* request auto detection */ ( g a: @" n1 f$ z
int gdriver = DETECT, gmode, errorcode;
4 p5 Q* E& [5 v; h/ p1 s1 qchar msg[80]; </FONT></P>0 o9 X9 ?2 l6 r' c# ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - G+ I/ r/ ]1 d' C. v P. {! h" m
initgraph(&gdriver, &gmode, ""); </FONT></P>7 T' X7 }5 v( m8 i5 M5 V5 H2 Y p3 _
<P><FONT color=#0000ff>/* read result of initialization */ : o7 Y l' t7 O! f+ O( f
errorcode = graphresult(); " w7 T N: ?& G9 n' H
if (errorcode != grOk) /* an error occurred */
9 o- D" w8 q3 X; ]6 ~{ $ G. n' S. [- D8 u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 D7 E8 f7 c8 Z0 R# N0 \% C
printf("Press any key to halt:"); ; m! Y- G, j" J4 W! O
getch(); 6 [# c0 z. i) z7 c0 z" T; e
exit(1); /* terminate with an error code */ & n" ~; ~/ t, E5 U4 c
} </FONT></P>
; l( r$ Y- l5 \5 t! P* E# m<P><FONT color=#0000ff>/* move to the screen center point */ ! A7 X8 F2 {; D8 z; E
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
! K4 J7 S3 D( P% Q5 W; Z, k% A<P><FONT color=#0000ff>/* create a message string */
{7 T/ F1 F8 z) _5 gsprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>" w/ a5 o" F, u+ a" s8 E. Y5 }
<P><FONT color=#0000ff>/* display the message */ 9 a2 F$ X3 U& e: M& g) x' q* L" s
outtext(msg); </FONT></P>0 U ?! s4 {, `
<P><FONT color=#0000ff>/* clean up */
) k8 s1 W* w6 o: e5 e6 Egetch();
) J/ ~* M# p: e2 B# y( B2 M/ Lclosegraph();
4 h$ q2 W( @- A0 x/ K/ Treturn 0;
3 [/ y( w% ~8 n- }9 }3 w} </FONT>
Z: q( S F, a7 N
8 t' b% {5 R% W" J' m n0 k3 K</P>
7 L" K2 C" m. {2 K<P><FONT color=#ff0000>函数名: gety </FONT>! ^4 b3 A; I6 Y6 v' I
功 能: 返回当前图形位置的y坐标 3 y# p0 ` {/ M
用 法: int far gety(void); ) ?# s p7 O$ E( s' ^
程序例: </P>
. Y& c, i7 q- M1 a) v<P><FONT color=#0000ff>#include <GRAPHICS.H>
( @4 @, L- [, N$ u6 m3 Z#include <STDLIB.H>
' i+ U a- F0 W/ U#include <STDIO.H>* i( f. Y0 ~- R N L) i& i
#include <CONIO.H></FONT></P>9 `" N' m+ T) z6 y) F
<P><FONT color=#0000ff>int main(void)
* u: I% D3 `/ V{
+ ?4 ~( G# s4 B8 r! ]8 Q/* request auto detection */
~0 x0 ~& F8 F5 F6 S+ w3 }+ Pint gdriver = DETECT, gmode, errorcode;
8 m8 u" D' f- {* mchar msg[80]; </FONT></P>7 l0 \6 s" ]1 v
<P><FONT color=#0000ff>/* initialize graphics and local variables */
9 L' V6 o6 c' `7 }0 \initgraph(&gdriver, &gmode, ""); </FONT></P>" a+ E5 \* T- ]# P
<P><FONT color=#0000ff>/* read result of initialization */ : j( a8 m& T3 Y! H0 m
errorcode = graphresult(); : I1 [& ~! `' s% e' Y+ j
if (errorcode != grOk) /* an error occurred */
- o8 r5 C. P8 @, p{
0 T+ l6 V/ ?. f Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
+ m2 X% |! q5 ^' p& l( Nprintf("Press any key to halt:");
( _0 o1 q* N( q, q2 r4 D3 X- c7 Lgetch();
! g3 n+ W! s) |) \* w$ vexit(1); /* terminate with an error code */ 8 f& _+ G6 z7 O" [
} </FONT></P>
7 y9 V( t/ g5 y<P><FONT color=#0000ff>/* move to the screen center point */
, D- k4 ~9 F4 B# t8 E7 [$ smoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>
" w; g6 |4 ?: e7 g<P><FONT color=#0000ff>/* create a message string */
6 o2 s7 T N# [7 nsprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
6 W1 |$ \' V1 m0 _7 ?: {<P><FONT color=#0000ff>/* display the message */
~/ j( b% o! x4 l$ y9 B+ ?outtext(msg); </FONT></P>
4 }0 M1 ^+ q. U: H* f: M<P><FONT color=#0000ff>/* clean up */
p: Y e5 h- N$ O: ?0 A9 }getch(); # R; o: t ], p: Z: r! c8 q
closegraph(); 8 S2 p+ \6 p+ O0 u7 `
return 0; + F& q2 @; @' a2 j) c% z" x
} </FONT>
: l" S( h0 z2 c* z* o0 ]
9 C" U$ u" [! o: V</P>1 K1 a- r0 A- L
<P><FONT color=#ff0000>函数名: gmtime </FONT>4 }& a" P7 _! S: Y: S
功 能: 把日期和时间转换为格林尼治标准时间(GMT)
* D+ _7 z7 z/ d7 r6 A+ K* r用 法: struct tm *gmtime(long *clock);
+ ~3 l' B. ^9 U# n* X8 ~" w Y. v程序例: </P>
6 b0 }% P$ y4 e; Z, t+ J) U6 L<P>#include <STDIO.H><FONT color=#0000ff>
j& i% U" Z3 f: g4 c#include <STDLIB.H>
+ b! A5 e! H- f8 w6 h* f#include <TIME.H>5 t; E% Z$ T+ `
#include <DOS.H></FONT></P>
8 m2 ]& k. [; {% p<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */
) F6 h( i0 b; [. @- Bchar *tzstr = "TZ=PST8PDT"; </FONT></P>
! P: N' k' e, p4 W- k" C2 w<P><FONT color=#0000ff>int main(void) 4 |6 j8 P2 [& w9 S+ f, j$ s) Y" }
{
$ D+ Q; s) w$ @time_t t;
" I: o. `; D! K) H/ Bstruct tm *gmt, *area; </FONT></P># I- `4 e5 O0 S
<P><FONT color=#0000ff>putenv(tzstr); , T$ v, N/ e) g
tzset(); </FONT></P>* w+ j/ R2 b* n% k0 g
<P><FONT color=#0000ff>t = time(NULL);
6 L4 z+ J$ ^7 X# \area = localtime(&t);
/ H# n/ q* Y/ s8 i Mprintf("Local time is: %s", asctime(area)); . V+ H. i, S m8 Z
gmt = gmtime(&t); + V9 Y, E8 `% U9 I
printf("GMT is: %s", asctime(gmt));
( p- {. p* n& {: k: C% e' D1 V9 ereturn 0;
) X5 G, R. K) s! o0 k, y2 b0 J} </FONT>
: C# l! ^8 n: C0 L; I; Y) ?7 m. r) K/ o3 R. c
</P>
! ^, Z$ U7 I5 @6 d<P><FONT color=#ff0000>函数名: gotoxy </FONT>+ [' J0 }* s- Z% j
功 能: 在文本窗口中设置光标
1 B( \% `' h2 {" @0 |# [. w3 t3 k用 法: void gotoxy(int x, int y);
2 p/ ~* a7 x; q/ D1 Z" O! p* a M程序例: </P>! y+ C ]' M4 |' |5 q4 w* L
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
* e: T* t) Y* D# b" H<P><FONT color=#0000ff>int main(void) : b8 r! q& D+ F: R3 c
{ . z* k: D6 Z Z* h1 X
clrscr(); ) {$ B, i0 \: R! n j+ R' e
gotoxy(35, 12); * n: `7 f9 b* q9 q. ] @& L$ q( q" `
cprintf("Hello world"); 8 A( s' W( ^3 h! d$ d
getch();
' C/ S. C0 d9 Y9 b" o4 areturn 0;
( s. W* d+ ?7 ?0 F4 f% ~}</FONT> % @9 C2 `$ O, w; |9 D& X, s. ]. p
- a3 r) m* I6 V# }! _: D3 G) j& N</P>
! _6 b" C0 D. Y- [ y5 H' r+ Q<P><FONT color=#ff0000>函数名: gotoxy </FONT>1 a/ z5 y) P; A% t; [
功 能: 在文本窗口中设置光标
+ q- d0 u/ Q1 l7 V9 h2 x* Z. I0 a用 法: void gotoxy(int x, int y); $ ]+ m5 V& ?/ [% N$ n8 L& r0 B
程序例: </P>2 D B' t9 ]' _ ]1 i
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
0 y- l5 g- N2 @1 v<P><FONT color=#0000ff>int main(void)
+ j) l/ u# p% d9 t{
0 C1 C6 ]* J/ }( D _clrscr(); 9 \; H" ~ }5 j0 K& f/ d0 A9 G
gotoxy(35, 12);
( h$ M7 k! X" s- y8 U6 Y" pcprintf("Hello world"); . w. z& \# f/ R" U5 y
getch(); : _0 h5 e3 q3 A/ E0 j
return 0;
2 Y% K+ T) h# ]) x2 b} & w0 a) m2 b) R T6 e4 `4 V
</FONT>
5 d/ W4 n0 ?# b' i9 i7 ~/ T</P>6 ]% H1 Q X% M4 l' v
<P><FONT color=#ff0000>函数名: graphdefaults </FONT>
$ z" M. d- G' W- l$ x5 N |4 }功 能: 将所有图形设置复位为它们的缺省值
5 W8 l5 k6 @7 X4 C8 b用 法: void far graphdefaults(void); + z1 L3 o& I8 S! n3 A( D
程序例: </P># X+ s/ |# Q m. G; S0 L8 ~* ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>/ A/ C# e% c' i/ R; k; g
#include <STDLIB.H>' L* h. D! Z! `9 V' \: _, `# A8 p
#include <STDIO.H> r9 ?$ F- ^9 s7 E8 f" E; D# e
#include <CONIO.H></FONT></P>6 l" ]+ |0 ~% A1 i& f9 l, J: U
<P><FONT color=#0000ff>int main(void) * g+ o; P1 |# f0 c+ Q# i/ J# e
{ / a+ B) P4 e" V
/* request auto detection */ 5 N. ], z, |, P; E6 ]1 f
int gdriver = DETECT, gmode, errorcode; # u1 {1 e# \+ {2 @
int maxx, maxy; </FONT></P># C7 P3 v& D5 _" G
<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 V* w2 G6 l2 e4 einitgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>) V- P5 p3 U$ ~0 G8 F
<P><FONT color=#0000ff>/* read result of initialization */ ! l8 \. v" Y4 ~0 ~" w- N# S
errorcode = graphresult(); 7 u! C* p. F5 b9 ^
if (errorcode != grOk) /* an error occurred */ u6 J0 ~* i* k! U2 P+ E' e- t+ R' v
{
5 K8 ]+ W) V7 J( gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 y9 D, X9 V% z* p$ U5 K
printf("Press any key to halt:"); * n# E, ^# D( y/ y( K% h# g
getch();
2 _0 ~4 ~8 \: }0 aexit(1); /* terminate with an error code */
|5 d' Y. E1 c} </FONT></P>) h4 o0 j+ ] {" W
<P><FONT color=#0000ff>maxx = getmaxx(); $ O% w2 ~ C! I$ P
maxy = getmaxy(); </FONT></P>
3 v. _' @5 N$ E- B<P><FONT color=#0000ff>/* output line with non-default settings */
9 Q8 W6 m! m* A8 t3 }setlinestyle(DOTTED_LINE, 0, 3); ' k+ t3 [# i2 L1 A" a
line(0, 0, maxx, maxy); & f$ M3 y$ l( U0 _+ i- |' J+ g9 X
outtextxy(maxx/2, maxy/3, "Before default values are restored."); ; c% m+ J; ~# T& x2 _3 z) S6 G6 Z
getch(); </FONT></P> A( L6 G: d' p% Z, T
<P><FONT color=#0000ff>/* restore default values for everything */ " ~( o3 H1 D) b9 ^- ]. P% W
graphdefaults(); </FONT></P>* }1 e+ D, w/ W2 U W+ W: G
<P><FONT color=#0000ff>/* clear the screen */
5 m% @& x+ o2 k2 n! |5 \7 G0 C. Mcleardevice(); </FONT></P>4 G! ]- U9 v' Q [
<P><FONT color=#0000ff>/* output line with default settings */
6 ]2 b1 P. }; e, J/ Xline(0, 0, maxx, maxy);
7 g# x9 C a5 a$ u- couttextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
, O% D1 C* f& ?0 s- Y6 B/ J8 M. G<P><FONT color=#0000ff>/* clean up */
8 p' H4 N0 q, v. Z" y8 d7 o) Igetch();
( i3 L; H% Z0 H" i9 Gclosegraph(); $ t4 B0 V) \9 c( g4 A3 E
return 0; 6 U" W& s L( E A* f4 [' u9 S1 Z8 q
} ) _0 }% n8 R/ S3 a
</FONT>, t4 f6 W8 L g) m2 {, C1 L: @( l
</P>$ P. J5 m# i4 [& J8 q# {. L
<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>/ O1 `* H* N! C7 A% Q
功 能: 返回一个错误信息串的指针 2 N$ Y4 H5 i4 P* ~, c- T( F1 L
用 法: char *far grapherrormsg(int errorcode);
7 w3 `. T0 L5 d- _& C程序例: </P>( Z6 e0 [; m+ S5 x/ D1 x8 S8 t
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ s3 }# p. X1 o( v$ y#include <STDLIB.H>2 |2 E! @4 B9 p. ?$ T
#include <STDIO.H>. Q3 E4 b0 Q/ m) \( X
#include <CONIO.H></FONT></P>0 M& t7 r1 I0 M$ z# P: _
<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>
7 p* L$ O+ E- u, ]8 w* s: M8 {& N* B<P><FONT color=#0000ff>int main(void) # W! O" X2 O! l( ?# J
{ * T2 [0 }+ L/ f' z! m0 |4 ?5 L% O* d
/* FORCE AN ERROR TO OCCUR */
8 ~5 g: ^( y# @! Eint gdriver = NONSENSE, gmode, errorcode; </FONT></P>+ z6 X+ p T2 f' C7 [1 ?4 F3 ^8 e: e! A
<P><FONT color=#0000ff>/* initialize graphics mode */ # x5 S+ ?& L9 \4 ?% P J
initgraph(&gdriver, &gmode, ""); </FONT></P>
& l5 l' f7 L: P" M) _# Y# w; }<P><FONT color=#0000ff>/* read result of initialization */ 5 E" m- ~7 I0 \
errorcode = graphresult(); </FONT></P>3 r# \2 V" X. Y! s& I2 C, `4 @ k: {
<P><FONT color=#0000ff>/* if an error occurred, then output a */
7 p; g ?+ a! G! k+ A0 B/* descriptive error message. */
' r& N0 K4 O' h$ lif (errorcode != grOk) 0 O0 z) E/ l$ b( m2 k3 B& e
{
7 X5 S0 W: t6 H+ hprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ( P; s: P( h% j' _- @! Y
printf("Press any key to halt:"); ! l7 F, q0 p/ X) g& w) _! B3 g
getch();
0 o" k( X$ ~. H" ~+ Nexit(1); /* terminate with an error code */ 7 Z6 c5 h9 ]' z
} </FONT></P>3 W( A0 R0 @; M" C0 M# q
<P><FONT color=#0000ff>/* draw a line */ & s. H# Y/ V: R# z
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
) ^/ ^0 w0 G1 ]) F3 C& A8 ^<P><FONT color=#0000ff>/* clean up */
, E- s1 w- v: g: y0 L- V Ogetch(); * |6 X0 t* u8 `& i7 |1 Y' L6 B
closegraph(); $ b* A {, R) F8 I9 k; W# `& f
return 0; : a0 k! J# o1 X. @% Y: b
}
# I) I& w, B* }0 P6 d</FONT>2 q6 s6 b6 x \4 N% `
</P>3 b- h, s, i. B3 S0 L
<P><FONT color=#ff0000>函数名: graphresult </FONT>
; _* l6 J/ c$ K2 }/ w5 P/ V& I功 能: 返回最后一次不成功的图形操作的错误代码 2 ^4 e( C! W9 K5 U& @' S# n
用 法: int far graphresult(void); 1 g! J5 t8 ~; ~! N
程序例: </P>
8 q* ?% k' F# V9 O9 _, S<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 j5 @5 C! w1 d" f' @, y#include <STDLIB.H>
, R! L. V% ]) D* B( s+ t) Y; |#include <STDIO.H>
) b8 I/ R0 e0 j#include <CONIO.H></FONT></P>
( ?5 Z6 A* E/ A<P><FONT color=#0000ff>int main(void)
( O9 c f. t, c4 j' u/ t6 y{
& U" U6 t6 v$ Q# L; e/* request auto detection */
) @4 [0 X5 c- T {1 A. ^$ R2 m" Lint gdriver = DETECT, gmode, errorcode; </FONT></P>+ [8 e0 N; X% w* E8 g: I4 O- A
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 e0 A$ J9 o: \( f
initgraph(&gdriver, &gmode, ""); </FONT></P>3 W$ ~+ B9 i, T9 c2 G5 A
<P><FONT color=#0000ff>/* read result of initialization */
$ Z& H, }. X/ uerrorcode = graphresult(); </FONT></P>& F! l1 {6 v3 [/ u! i
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
. F* d8 w5 G% D; Y! X# k{
! g( {( R% y) }! d. g/ uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 f/ k1 g; w5 Z0 X; L4 t+ e ^printf("Press any key to halt:"); 3 ]( i" c4 r+ X3 v! @! W4 z \
getch(); ) o; l A8 h" n V; [
exit(1); /* terminate with an error code */
. H" b9 u. g3 t} </FONT></P>5 D5 D5 ?5 p# s& i" C; T
<P><FONT color=#0000ff>/* draw a line */ # S+ _) C1 t$ w6 T1 ^9 E
line(0, 0, getmaxx(), getmaxy()); </FONT></P>! y: a9 y: X. l, w3 N4 i
<P><FONT color=#0000ff>/* clean up */
5 W d P5 j1 F" igetch(); ( D; H) x9 w. f, V$ Y
closegraph(); 1 D1 V6 y- f8 C0 {
return 0; ) X; F: Q- f8 b6 d: v
}</FONT> * f0 g a) w7 q
</P>- m3 v }( d4 P& h, u+ v
<P><FONT color=#ff0000>函数名: _graphfreemem</FONT>
/ X4 E& L! k: a* J M功 能: 用户可修改的图形存储区释放函数 , p1 K* h/ m8 v4 Y+ a/ N( G
用 法: void far _graphfreemem(void far *ptr, unsigned size); ; H! h2 P+ l' S# _
程序例: </P>
# |: X- u7 W+ o$ B4 x<P><FONT color=#0000ff>#include <GRAPHICS.H>+ {: B% N5 k( ]! \; o0 T1 y' z
#include <STDLIB.H>
% N- `# a/ B. v#include <STDIO.H> L9 l3 L5 F7 _4 p* ~3 Q
#include <CONIO.H>
4 O% \. {. x1 a4 M5 H6 [#include <ALLOC.H></FONT></P>; x: \3 U- C7 P! A; x
<P><FONT color=#0000ff>int main(void)
! v {7 O$ y! t4 k; x A{ 9 Z+ v3 ~/ b) z# `2 ]; g
/* request auto detection */ 3 x8 L% r% ]7 d3 b" Y$ i9 |4 ]
int gdriver = DETECT, gmode, errorcode; , ]: F9 ~; Y' b* }( k/ J5 P
int midx, midy; </FONT></P>
) X% [8 m: l/ x/ R3 T7 B. b) |; k<P><FONT color=#0000ff>/* clear the text screen */
$ e, c1 Y7 |+ u: kclrscr();
! d7 l1 S3 m7 I# y p% Eprintf("Press any key to initialize graphics mode:");
! ~- T+ o+ N$ u& B8 Sgetch();
; P+ S8 @: j% ~2 W0 B# H6 A- U$ wclrscr(); </FONT></P>
8 \5 h. J9 D' d* n( Z8 H4 B<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 m) S- O0 d; T' ~" ~- Q2 Minitgraph(&gdriver, &gmode, ""); </FONT></P>
4 j8 k) ] x# W! n4 Q! M<P><FONT color=#0000ff>/* read result of initialization */
1 P+ f; Q' T" Z# U7 X: o" `errorcode = graphresult(); / A, _9 ~# ]- U* r8 v4 i
if (errorcode != grOk) /* an error occurred */
. j* y1 T* Z$ Y9 n5 L8 ]6 k- o3 v{ ( c; v7 s. G6 h
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 s u5 r1 T/ t: v# c
printf("Press any key to halt:"); * h. T8 X0 ] o7 t, l0 d' r
getch(); " _8 ?+ f2 Q; |7 I
exit(1); /* terminate with an error code */ 1 J" P% t1 ~: q# |" P" V
} </FONT></P>. ]6 K/ U7 b! A- R0 \2 I0 a
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ P) i: x! u4 e! _5 s% f; G
midy = getmaxy() / 2; </FONT></P>
- j7 l. x3 B: x) O$ v. `) [: m<P><FONT color=#0000ff>/* display a message */
/ ~- P8 b& {; B4 h" }7 e( P# {settextjustify(CENTER_TEXT, CENTER_TEXT); ( ^, N* V# B) C2 J8 w
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>8 S7 k0 N( d. j B$ D8 R
<P><FONT color=#0000ff>/* clean up */ ) |8 r8 P/ I/ T3 \- j
getch();
0 R+ N* g) x6 d6 Yclosegraph();
' H3 Y4 M2 M% F$ @. Preturn 0; ) z3 k9 f( v5 r
} </FONT></P>
@; M, C5 f1 o5 o; ~' a<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */ ( t; x# a/ d; P& D+ z2 e& r
void far * far _graphgetmem(unsigned size) & r- M9 H) k4 d, [
{ # e( h1 D0 d2 W# R' V Q" d
printf("_graphgetmem called to allocate %d bytes.\n", size);
/ X2 d6 f: b0 A9 c& mprintf("hit any key:"); B# j f% X% X2 n2 s |. s
getch();
. K8 ~) z9 j4 X' Kprintf("\n"); </FONT></P>
" D- w+ v0 {. J; t$ {0 o$ u<P><FONT color=#0000ff>/* allocate memory from far heap */
& L' u0 @/ ~; p$ zreturn farmalloc(size);
. [& ^& ~- e+ g4 L} </FONT></P>4 o: P; j3 v1 D
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ . z! O& Y8 Z4 H+ J4 s
void far _graphfreemem(void far *ptr, unsigned size) & T$ U/ s& L; L& Z0 a+ \2 v
{ & F. d! \# {; n9 e" w
printf("_graphfreemem called to free %d bytes.\n", size); % H% q" x7 X* @0 W% u
printf("hit any key:");
S" G# O4 D+ r+ `getch();
% O1 z: h8 a3 H7 t; |2 Aprintf("\n"); </FONT></P>- O+ R0 _$ ^; o4 a& O& D+ }
<P><FONT color=#0000ff>/* free ptr from far heap */
; g9 b% `+ \' ^0 V' Z8 B7 s2 jfarfree(ptr); 8 c1 M9 {5 \" ]* e4 D+ i
}
/ @$ y) D2 ~0 O8 }: ~</FONT></P>
& t5 Y: y7 i3 X<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>( w1 F$ N' l' @5 }% Y3 ] k
功 能: 用户可修改的图形存储区分配函数
( v0 r. ]8 A" x2 q/ P+ J# [用 法: void far *far _graphgetmem(unsigned size);
% ^% ~# I' w0 J, |1 W; D2 G程序例: </P>
: B" h$ t5 y* h8 r<P><FONT color=#0000ff>#include <GRAPHICS.H>
; e9 P& A1 Y4 @ q#include <STDLIB.H>
; M8 Y t% P) b; |* ^#include <STDIO.H>
+ r! A5 ?% @7 X#include <CONIO.H>
; M7 n2 X& d" \# O F) f9 o2 P#include <ALLOC.H></FONT></P># z9 c( w7 M' z9 _4 I: V( p+ Q
<P><FONT color=#0000ff>int main(void)
2 a+ L. G- \4 Y K{ + H: F3 ]1 T/ g. t' {
/* request autodetection */
9 h2 l, l: _% I+ }0 g4 wint gdriver = DETECT, gmode, errorcode; " Q& b) p" D* N- `7 z
int midx, midy; </FONT></P>' s& V3 \& ^& a5 j# Z4 d
<P><FONT color=#0000ff>/* clear the text screen */
7 P9 k! D2 }9 eclrscr();
% o9 m8 e9 y7 N" F" J8 z: hprintf("Press any key to initialize graphics mode:");
" n u9 T" T1 W, j8 U& Hgetch();
- y( g5 \: \" z( v, wclrscr(); </FONT></P>
F# c; N8 q, Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 T% E' w" H$ n) F. linitgraph(&gdriver, &gmode, ""); </FONT></P>
|; N- b: P2 z1 n/ K<P><FONT color=#0000ff>/* read result of initialization */
5 k. W0 J4 E+ T+ o$ Werrorcode = graphresult();
6 S* q8 Z! \1 l3 B8 V. sif (errorcode != grOk) /* an error occurred */
0 E$ \* G# o4 P3 z, G{
) k. B8 G: B/ u b% R8 mprintf("Graphics error: %s\n", grapherrormsg(errorcode));
* y7 _( Z% X2 | x: S. ?* Qprintf("Press any key to halt:");
" ~# ? n: S# c* A# Y0 i) ?. Egetch(); 2 o7 k# y4 S0 P5 H ^6 a, u; H
exit(1); /* terminate with an error code */
/ V0 l! u/ N _5 U; E J. g& M# E" H* Z} </FONT></P>
: d' q- z% o' A, B+ U<P><FONT color=#0000ff>midx = getmaxx() / 2; : e3 U" Q: b- S
midy = getmaxy() / 2; </FONT></P>
1 G0 V1 n, H: Z V4 p! F<P><FONT color=#0000ff>/* display a message */
0 i2 c; x% Z1 b# ysettextjustify(CENTER_TEXT, CENTER_TEXT);
$ s2 H! \1 k& A# J0 v; souttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
" L q+ Z, j2 { y" |3 g' @) K- j<P><FONT color=#0000ff>/* clean up */
3 F0 b; @, \: U# C% @2 _) r/ E1 dgetch();
) E+ D( r# e) Q" dclosegraph(); ( {6 j$ [. s$ h% Q# V% u
return 0; " M, I5 ^1 H( g' Z2 j7 ~" D
} </FONT></P>4 J% X8 R( Z* X: K
<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
8 ~; ]& J! v6 i# k2 zvoid far * far _graphgetmem(unsigned size)
2 B5 o k, C' s/ d8 V3 y{
* f; R" B: @# ~- t3 [6 F4 qprintf("_graphgetmem called to allocate %d bytes.\n", size); " j9 }1 {1 k7 X# r% f( C
printf("hit any key:"); 0 b+ V- v4 p* W# k: C
getch();
; K; M" C0 _2 ?/ Oprintf("\n"); </FONT></P>
) |, ^1 x9 L( {# _# P<P><FONT color=#0000ff>/* allocate memory from far heap */
) H% \& p8 W0 G3 ~return farmalloc(size);
9 e; Z N( u" u+ M6 i% N} </FONT></P>* @- o) F0 D- X" _" R) O9 G7 `
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
1 h) G9 O0 }4 {2 O$ Vvoid far _graphfreemem(void far *ptr, unsigned size) V; u- c" M& k' L: z7 }
{ 9 [2 F7 i' M2 l, A* B8 Z& X6 Q
printf("_graphfreemem called to free %d bytes.\n", size);
9 _/ `( J! }- T2 T. Q4 u' Zprintf("hit any key:"); 9 G. c8 D8 b J
getch(); " h* @- W+ s/ A$ r+ q( X
printf("\n"); </FONT></P>
7 U8 D& O: |( N<P><FONT color=#0000ff>/* free ptr from far heap */ 6 j1 S7 \5 J5 b2 f0 e3 V
farfree(ptr); + o+ u3 q0 p+ ]8 J/ ]$ T: M
}7 W. W6 `* Q; Y7 y* k. P0 I
</FONT></P> |
zan
|