- 在线时间
- 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>* w( S t- I4 S9 w1 {0 K+ M: T
3 Q9 L/ ^' R( J( g7 C
$ p2 g0 s/ \# t. ?8 x<p>0 k6 z) h7 |/ n+ f% @! e! L( R1 f
< ><FONT color=#ff0000>函数名: gcvt </FONT>% Q. \- _+ h" V0 M+ k4 t2 f7 n/ j3 Y
功 能: 把浮点数转换成字符串
# ~( s3 Z; l; U% d0 ~用 法: char *gcvt(double value, int ndigit, char *buf);
2 K, E# M# g7 C! t! o0 C程序例: </P>( }( J# y2 r# @6 ]5 K, T
< ><FONT color=#0000ff>#include <STDLIB.H>
9 C* ^- s/ l4 |. {3 J( a1 q8 l- J#include <STDIO.H></FONT></P>
* G. w3 `5 |& R< ><FONT color=#0000ff>int main(void) : ~% l8 c0 ~$ R8 m) e( Y9 @
{ 4 V. d- @0 \* b7 v3 ?9 `/ I* O+ o
char str[25]; - g4 }. r, e( B8 G |0 r- e$ c/ ~
double num;
8 o+ f& ?* R- g# sint sig = 5; /* significant digits */ </FONT></P>
! f2 }. K1 ^: j< ><FONT color=#0000ff>/* a regular number */
3 X0 y) j% B& xnum = 9.876; 0 \0 }# w8 F8 Y1 R6 ~' E8 T2 H4 H
gcvt(num, sig, str);
: l! ~# }3 Q8 V4 {# f4 Fprintf("string = %s\n", str); </FONT></P>
3 l* A6 H8 H; I- G< ><FONT color=#0000ff>/* a negative number */
: J- z) L6 b v% ^4 Q( Rnum = -123.4567;
4 y% `# `+ j0 q# a! Ngcvt(num, sig, str);
3 B8 s4 A* p! ? L, Kprintf("string = %s\n", str); </FONT></P>
9 Y4 i5 y& E6 ` u# }< ><FONT color=#0000ff>/* scientific notation */ 8 b+ w- d5 n1 k! s
num = 0.678e5; U# A: w3 }6 i: R
gcvt(num, sig, str);
8 j2 }& R; }' q: Q# H: d, tprintf("string = %s\n", str); </FONT></P>- |( T; O, T1 W5 r+ v; O- t* w4 i
< ><FONT color=#0000ff>return(0); 0 @' Q( _" `$ R& E) {
} $ B, [( h# R" v; s3 K
9 H7 v, c: `* g& [; B. X</FONT>
( N; _$ y8 A/ `5 ~/ s* |) w</P>
# p" d" I5 ^: P< ><FONT color=#ff0000>函数名: geninterrupt </FONT>
: P' n2 }9 l+ _1 a* ?功 能: 产生一个软中断
/ y) X- R% Z2 ~8 L用 法: void geninterrupt(int intr_num);
. _1 n' y" r7 v2 U程序例: </P>
. l; Y7 l3 V7 t5 ?& K' t< ><FONT color=#0000ff>#include <CONIO.H>! `* G* n" M9 @2 K+ a2 H. b$ h
#include <DOS.H></FONT></P>
. J2 y+ J, \1 X! g' K0 {< ><FONT color=#0000ff>/* function prototype */ 9 o# |1 r( O2 N4 {( J! a
void writechar(char ch); </FONT></P>1 Y& `8 S, {$ ^6 H
< ><FONT color=#0000ff>int main(void) 9 q8 V8 C! V0 u3 u$ d
{ , `1 U# O" [# [ M" f, M8 d. K
clrscr(); 4 q6 F& Y# M- C. v! w* i0 |' C; _
gotoxy(80,25);
! b& y$ \) i& B1 w! h `& ywritechar('*');
# G& |6 s" s' x% s3 H( Agetch(); 6 c* z' l! \, i" U
return 0; 9 O3 [ M% c* w( |9 x& b
} </FONT></P>, R$ a- y t N( h. l9 F+ o$ S
< ><FONT color=#0000ff>/* ! b! v" P. a3 T' \+ I
outputs a character at the current cursor 7 @4 Z6 Z$ U. K/ }$ X: V
position using the video BIOS to avoid the
+ u5 j2 |, k9 F: V5 o) _& lscrolling of the screen when writing to
" \! |' W& ~0 a8 Q6 Llocation (80,25). 2 X" v( n p6 }* n* h
*/ </FONT></P>3 Y: u) Q4 q8 [
< ><FONT color=#0000ff>void writechar(char ch)
$ j7 T7 T- c, p. M- O{ . b5 e" ?& }8 H8 G F0 Z
struct text_info ti;
5 S# ^1 u6 E" V4 E0 u- O/* grab current text settings */ - W8 r" h% z9 h
gettextinfo(&ti); 3 P" l" l/ O {3 V# d
/* interrupt 0x10 sub-function 9 */
. W3 [! z1 u. ?_AH = 9;
6 r/ ~7 e- `( l/* character to be output */
6 H1 W, }. Y4 n2 e_AL = ch;
- W$ n: t& M( J' d_BH = 0; /* video page */
0 P7 {/ i& {, k; o/ D_BL = ti.attribute; /* video attribute */ A( `0 _( _$ `1 {+ \
_CX = 1; /* repetition factor */
4 I+ I, {) \% M* f" {, U7 Ygeninterrupt(0x10); /* output the char */
" c: r. I/ ]3 m( @0 O+ V} 0 `) e* T- z: ~ ]- A2 V
</FONT>
; M: D1 ?& V$ \3 u/ }1 U</P>% A+ j/ ~4 M3 U4 I% |2 W$ l
< ><FONT color=#ff0000>函数名: getarccoords </FONT>* r. L! J; A$ `! f/ G$ H' ^
功 能: 取得最后一次调用arc的坐标 / F1 c @9 V3 v7 n/ v' C- }
用 法: void far getarccoords(struct arccoordstype far *arccoords);
6 v" D) q W' A1 l+ B: l程序例: </P>* d" j h0 B4 ~! Y- W# }% M4 I/ [% H
< ><FONT color=#0000ff>#include <GRAPHICS.H>+ W0 g/ X/ G0 j2 H4 V% `
#include <STDLIB.H>
$ P. i6 i& @& ?) F- x#include <STDIO.H>
( \! P$ s; s0 U5 Q2 a2 }#include <CONIO.H></FONT></P>" e; j: y9 C3 G' q1 ~7 m
< ><FONT color=#0000ff>int main(void)
8 M4 ~: F- y: ~. s: D4 a! z{
7 j2 G2 _! _: }5 @& k5 r1 q/* request auto detection */ & x+ D) K! }6 s) q7 b
int gdriver = DETECT, gmode, errorcode;
9 H4 j) s- } C# w* gstruct arccoordstype arcinfo;
% G- l/ `0 `) n9 V( ]! H- d+ }int midx, midy;
7 P; i; P8 q& aint stangle = 45, endangle = 270; + V( A: f0 w% l( b
char sstr[80], estr[80]; </FONT></P>, z) y J9 Z2 o- x7 B9 J, @4 [+ J
< ><FONT color=#0000ff>/* initialize graphics and local variables */ / U9 U1 C" Z2 J7 w: y! i5 L4 f4 x
initgraph(&gdriver, &gmode, ""); </FONT></P>
6 t7 V, @( C' j" A4 R' {< ><FONT color=#0000ff>/* read result of initialization */ 8 n8 f! W, ?, b- h; \3 A3 w
errorcode = graphresult(); " Q& ^$ z9 ^$ h# N5 F7 c' {
/* an error occurred */
K' d& _/ X2 @' W7 w5 U: Tif (errorcode != grOk) 9 T/ g/ B; r3 ?6 u3 v8 Q% Q- {
{ 7 S$ {" N: ~ b/ s, Q
printf("Graphics error: %s\n", ' | h" J6 v( K: m& w5 T: V
grapherrormsg(errorcode));
8 Z6 v" F8 Q: B8 H4 [$ w* ~printf(" ress any key to halt:");
# B4 U, i, P3 N, Ygetch(); $ X* v* w H, n2 R
/* terminate with an error code */ * v! t/ H# t: n3 v& ~$ _2 |; f$ t
exit(1); 1 h' B3 H5 \* W6 U8 x' p# y
} </FONT></P>) w. y/ m6 E3 O9 Y" O& N
< ><FONT color=#0000ff>midx = getmaxx() / 2; " {6 C6 @6 {+ }" c1 j& h; Z+ _
midy = getmaxy() / 2; </FONT></P>
" u1 d0 N' k( \< ><FONT color=#0000ff>/* draw arc and get coordinates */
7 ~" Q2 l* E8 a8 |8 _& hsetcolor(getmaxcolor()); + j6 V! _/ u! A |, u. p( T+ W. T
arc(midx, midy, stangle, endangle, 100); ) L. @, Z3 @6 l; W1 g$ F
getarccoords(&arcinfo); </FONT></P>
9 q3 |& t$ _0 {< ><FONT color=#0000ff>/* convert arc information into strings */
4 N) h! c2 M3 Z& ^& S! z" g! J2 Jsprintf(sstr, "*- (%d, %d)", 3 N! G" o j6 G" |! ~
arcinfo.xstart, arcinfo.ystart); * S% [7 E! z8 P: M& J( P0 [, o3 J
sprintf(estr, "*- (%d, %d)",
: [: }3 G1 W+ c0 Aarcinfo.xend, arcinfo.yend); </FONT></P>
4 s% Y' U7 D, T/ M$ ~< ><FONT color=#0000ff>/* output the arc information */ ( N) N0 t: b G, d" z. Y
outtextxy(arcinfo.xstart, # C+ s/ f& _' v) H* y! @ y4 C
arcinfo.ystart, sstr);
, l9 G: l1 _3 X: E+ ?! douttextxy(arcinfo.xend,
# E% o3 }* ]: `% Garcinfo.yend, estr); </FONT></P>
2 E, d) w+ B G1 r5 l9 S< ><FONT color=#0000ff>/* clean up */
0 A% [0 M; K& A) z3 O% Vgetch(); ' V4 i t3 a6 [/ c
closegraph(); : t6 ~; S1 z1 x+ @3 o! v
return 0; % |8 d+ T0 o2 x
}
8 B, l+ d# Q8 @</FONT>
7 y" _: E! F9 c8 S1 u5 e; m" D0 A! r- U2 k$ F; Y3 J
</P>6 J8 N! q( l! q5 R1 a# T4 R
< ><FONT color=#ff0000>函数名: getaspectratio </FONT>
9 ]$ z8 b: ]& D, c4 i# }功 能: 返回当前图形模式的纵横比 2 X# r$ k$ p+ S- O; ~
用 法: void far getaspectratio(int far *xasp, int far *yasp); ; Q6 \% i% Z2 h: z, i, G
程序例: </P>+ U& l5 ]% w, Q6 T! s7 K, u
< ><FONT color=#0000ff>#include <GRAPHICS.H>' @/ V" W+ f/ H* }" c
#include <STDLIB.H>- g2 g5 s/ b- `+ ]+ F
#include <STDIO.H>
8 o5 L* C( i h+ s j#include <CONIO.H></FONT></P>
4 Y; a8 v( u1 F, s< ><FONT color=#0000ff>int main(void) + X2 |$ m6 x& C
{
5 [( M0 y6 o! K |6 K4 i) Y" X" U/* request auto detection */
: F1 _) t2 R* ]- Yint gdriver = DETECT, gmode, errorcode; 9 U" U' R% c$ ~" \8 z9 ~
int xasp, yasp, midx, midy; </FONT></P>
' c# k7 H& M: ?# ~& |) B< ><FONT color=#0000ff>/* initialize graphics and local variables */
. c- P0 _0 n8 z% C |initgraph(&gdriver, &gmode, ""); </FONT></P>5 k% V" h( N# c: [. V% I0 N8 t
< ><FONT color=#0000ff>/* read result of initialization */ 6 Q5 T3 C% O; u) ^" w7 U* Q
errorcode = graphresult(); & W. P0 C }: L; R8 [9 [
/* an error occurred */
( i; L s/ c( U1 ]5 }) k& s cif (errorcode != grOk) 1 {8 V. ?9 q" ^+ ]+ T
{
m- _9 H: O8 ?1 {3 _9 Jprintf("Graphics error: %s\n", 6 P8 ]. W3 K: a: `
grapherrormsg(errorcode)); . E+ _5 v7 Q) E; A9 y
printf("Press any key to halt:"); 4 N8 G6 T6 I5 g) h/ z5 Q
getch(); $ z2 g$ W) a" H6 m9 e( w+ ^
/* terminate with an error code */ # }9 Y$ @- N+ H7 ]. [3 P" B# ?5 G' W
exit(1); - Q, |* [9 f) k8 k J1 Y p% k
} </FONT></P>
6 B, k6 e7 [: C( o. F6 n1 q<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 L1 b4 C% F6 Z1 z; o7 p- G: vmidy = getmaxy() / 2;
3 I& O0 U* e( Q) q$ [setcolor(getmaxcolor()); </FONT></P>) ?: t1 w1 V& V2 T
<P><FONT color=#0000ff>/* get current aspect ratio settings */ ! ^+ Y" ?- {, u
getaspectratio(&xasp, &yasp); </FONT></P>
+ {" _4 z$ G0 n. n<P><FONT color=#0000ff>/* draw normal circle */
, N- e, s3 \% s' v ~( Y' |circle(midx, midy, 100);
* v& v& n5 A2 S; s: Rgetch(); </FONT></P>! Y' v/ ? |! o. _, N" u8 j
<P><FONT color=#0000ff>/* draw wide circle */ ' |: c9 l4 f9 {; |4 \1 B
cleardevice();
: \0 w5 u) \9 v. y# Vsetaspectratio(xasp/2, yasp);
. d) B1 Q, N. P. M! Ccircle(midx, midy, 100);
" p$ s2 v3 `$ Wgetch(); </FONT></P>
" a) f/ j6 M2 `- {% G5 F<P><FONT color=#0000ff>/* draw narrow circle */
2 K$ w- {( c& m6 ~! scleardevice();
9 U3 _& v1 t. ~0 l" ]" m0 i6 ysetaspectratio(xasp, yasp/2); $ l1 G$ ]6 V6 k8 [3 Q2 ]
circle(midx, midy, 100); </FONT></P>
- Z( N# ?% H. g, f: n# D<P><FONT color=#0000ff>/* clean up */
1 O1 E" ` C4 M9 ]" Kgetch(); , ]) w! }% D0 T$ k! E2 }" b4 W
closegraph(); ! T3 K1 t6 k, m( b/ [
return 0;
! Y$ O$ \% s* k0 A. H} 6 h* R( b. A h( ?
</FONT>
6 y! R' P% h( T- u+ O1 R
# p) w% n% R5 `4 o* \# r4 Y. ]</P>4 n" c8 m/ z; d* t
<P><FONT color=#ff0000>函数名: getbkcolor </FONT>
+ e U" \% L, Q功 能: 返回当前背景颜色
, k, k6 y" m8 b) f用 法: int far getbkcolor(void);
- r; \ E$ }* w$ |) P3 o5 `/ X程序例: </P>
% g+ J$ T- p, R8 _: i% w<P><FONT color=#0000ff>#include <GRAPHICS.H>! q0 x+ w$ N: Q( l
#include <STDLIB.H>
) M7 O! F4 G3 L& h' {) f" l! Q# T#include <STRING.H>
8 d. |% Y( }) V# a* t7 A8 {#include <STDIO.H>
* l1 t" s& t9 e: c _$ ? w4 Y! P( t6 P#include <CONIO.H></FONT></P>* [8 n$ y; m8 q9 {
<P><FONT color=#0000ff>int main(void)
) b K) h S, [6 A, N) Q Y{
+ J6 Z8 [- x8 S0 v/ s0 d6 o$ `& }/* request auto detection */ 8 ]" i6 Z/ Q1 M3 ]+ P- V
int gdriver = DETECT, gmode, errorcode; ' @/ g1 e! F9 R6 F' J9 Z% x
int bkcolor, midx, midy; " S ]8 Z% d- n/ c& U' U2 c
char bkname[35]; </FONT></P>, _8 Q* W Y6 f. J+ a) C
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! C) |) s8 |" s* Y
initgraph(&gdriver, &gmode, ""); </FONT></P>
" z1 P: V( H* D2 G<P><FONT color=#0000ff>/* read result of initialization */ . s0 z1 j0 C) G6 ^
errorcode = graphresult();
: h" L/ f- t5 N) J/* an error occurred */
* Y. t* T/ f+ ?5 M6 z# Pif (errorcode != grOk) % R( F% z& U- _( V( E
{ 6 A: @9 S3 W" n, `1 K; S0 G
printf("Graphics error: %s\n", + ~2 V$ I& B! p. Y& k
grapherrormsg(errorcode)); : H; d5 L$ W% k5 I
printf("Press any key to halt:");
6 ^5 F2 j7 D5 W) Ogetch();
1 b l8 m4 K3 u7 I) h2 c: n/* terminate with an error code */ , y7 R: M* S% Z* A, b! K
exit(1);
. k) S. y3 ?5 D- x! ^6 q* n} </FONT></P>
, E1 c* A7 R! J* p5 F; f/ q1 Z<P><FONT color=#0000ff>midx = getmaxx() / 2;
4 o! H# k: L+ @; T3 ~midy = getmaxy() / 2;
1 K3 [. @9 M6 |7 Dsetcolor(getmaxcolor()); </FONT></P>+ J$ y4 e# K% @# H8 F6 X# ]( h
<P><FONT color=#0000ff>/* for centering text on the display */
# C- n( }2 l1 x6 Asettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
/ z8 s6 R" S: @" Y- p<P><FONT color=#0000ff>/* get the current background color */ 4 W1 f+ @1 Q5 }8 [& @- d; w
bkcolor = getbkcolor(); </FONT></P>5 r& l# ?/ y* A7 |7 o
<P><FONT color=#0000ff>/* convert color value into a string */
& M! @0 v: K% X: a* _itoa(bkcolor, bkname, 10); 9 h& S) @* ?' @( g+ P! I m3 B* ^/ Q
strcat(bkname,
1 W) l! u) Y2 S5 C9 `8 x" is the current background color."); </FONT></P>$ J& p9 y. D8 W& ~; c/ y
<P><FONT color=#0000ff>/* display a message */ " p# @7 L+ _; Z b1 @# x
outtextxy(midx, midy, bkname); </FONT></P>4 o8 a4 _! l" | F) i0 o
<P><FONT color=#0000ff>/* clean up */
8 H0 b- O: D3 b0 W; d, U; Kgetch(); ) r2 H7 a6 ^; `4 C8 y* E9 ]+ J
closegraph(); # X2 _. s) q+ D+ d- s
return 0;
4 x M: z: w+ U, S6 z d}
v4 R3 z8 ?% O8 s" n
, Z0 x) f' g. |7 o. n) o- z5 p</FONT>. u% A( d2 B% i: L
</P> c" v/ G D: v0 g }2 f/ ?3 Q
<P><FONT color=#ff0000>函数名: getc </FONT>
, J7 }) w T9 R8 @功 能: 从流中取字符 & w% ?0 p. O+ ^
用 法: int getc(FILE *stream); $ o- q2 d( I% j C% F5 E" u1 V+ q
程序例: </P>- ]5 ]; j5 I$ ]: O9 U
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
( m. h- I$ e; I! U<P><FONT color=#0000ff>int main(void) |) q. m: i" j4 X0 }. e* c( c
{ U& z4 `) w2 W2 O$ \$ N3 Z B
char ch; </FONT></P>
6 v& d L: F4 M M& T0 ?<P><FONT color=#0000ff>printf("Input a character:"); - P/ K" `; E _1 k, E1 |' ?
/* read a character from the
- T4 x9 `5 f3 K/ H9 p4 ~' qstandard input stream */ 2 M% N4 a6 f$ V* G8 x5 t+ Z7 I
ch = getc(stdin);
\5 |4 G' a0 z# b9 a8 u7 N7 V" y3 Hprintf("The character input was: '%c'\n", ! y3 y- n4 U) r# O
ch);
4 X7 C7 P) t- |, zreturn 0; [ j) f, z1 ]
}
6 u S: a: |, {; B3 l+ G0 q4 [* N' |# k' g' D& X" y" w; d4 C
</FONT>
- I+ M1 b O% g% X</P>6 x6 [% D4 n' p d% x& j% G
<P><FONT color=#ff0000>函数名: getcbrk </FONT>9 k* z6 ^9 o; f; z. z5 t
功 能: 获取Control_break设置 & A" _7 ~. y; }
用 法: int getcbrk(void);
7 r3 V4 |' P- F: \9 m* }. {# _* [程序例: </P>; C; a. q1 r0 D' e1 ?' `- G9 d! `
<P><FONT color=#0000ff>#include <STDIO.H>) t; u& w, v" c p; B) k% J
#include <DOS.H></FONT></P>1 V" ~( ?) n4 x0 w$ }2 A
<P><FONT color=#0000ff>int main(void)
; t N+ J7 y( {9 ?2 f{ ( }4 P, m4 _7 [+ b* Q; s: K
if (getcbrk()) 7 J4 _) X' @8 Q) p" p
printf("Cntrl-brk flag is on\n"); 2 g: z) T# p0 c% s) l
else % \! d5 W7 ^% H8 u
printf("Cntrl-brk flag is off\n"); </FONT></P>
2 s4 ~7 m6 g$ g: w6 A$ ~: I<P><FONT color=#0000ff>return 0;
. B3 `8 x! }6 [# x$ {} </FONT>- h( T# k8 Q$ {8 E" U& ?+ J
U: C( g7 u0 O3 s& s9 X</P>, H5 i# w! r5 d* U# z
<P><FONT color=#ff0000>函数名: getch </FONT>+ o( I+ }& S: I: ]
功 能: 从控制台无回显地取一个字符
. a, S P. }! R1 |: s用 法: int getch(void); ) s- Z Y" q( p" o& v
程序例: </P>
t' B3 }' a9 d8 A- U3 ]+ v* @<P><FONT color=#0000ff>#include <STDIO.H>
* I2 K# N7 ?0 l% ?. b8 y#include <CONIO.H></FONT></P>. P& l" I0 e' I- O
<P><FONT color=#0000ff>int main(void) - X0 n) t4 b0 x: I# S6 b9 V
{
- B0 e" h' v7 S, r1 x- N l7 q6 dchar ch; </FONT></P>( Q& l( ^4 ]3 G- S
<P><FONT color=#0000ff>printf("Input a character:"); , z1 o9 y( h v1 Y# S6 v! A4 P
ch = getche(); m, P8 K/ ?. W p" o& O
printf("\nYou input a '%c'\n", ch);
5 O9 y, b2 J; c( j# }7 rreturn 0; 5 ^( \& Q. v; f# G( a% T; D* O' ~
} ; |8 F- Y) i/ e# |9 y) v
8 [ M/ ^4 F/ a: o& F</FONT></P>2 ^4 c% q% T8 R. m1 x. K
<P><FONT color=#ff0000>函数名: getchar </FONT># C8 J3 y5 v+ O/ }! e5 y. ]4 _% ]
功 能: 从stdin流中读字符
: X2 a/ ^/ w# W! [ C; a6 z用 法: int getchar(void);
3 C) D/ ^! X" L) E a9 F5 R, U, V4 U程序例: </P>; t Y: d W; n/ G
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
% B& U7 r3 G# x. [! ^<P><FONT color=#0000ff>int main(void)
5 S$ [' y2 X$ i) W* ?( T1 |! I, |{ 5 H# |" O `5 ?* i. m
int c; </FONT></P>
- y+ e! O# b; n4 E6 \<P><FONT color=#0000ff>/* Note that getchar reads from stdin and
w @# p, h" `1 I. H1 w/ dis line buffered; this means it will
9 s$ a% F0 K. U$ [not return until you press ENTER. */ </FONT></P>. _$ R* U/ f6 U: v" d) w
<P><FONT color=#0000ff>while ((c = getchar()) != '\n')
+ L+ g0 g+ g8 H5 Xprintf("%c", c); </FONT></P>6 a, B' n# A1 @6 U
<P><FONT color=#0000ff>return 0;
% X$ A, a% z7 Q6 j}
3 Y g% Y: @7 e9 n& L</FONT>" g8 v3 x, Y5 d5 O
</P>
8 W) C: X+ M- o<P><FONT color=#ff0000>函数名: getche </FONT>
; D. F! f D1 a( u* d功 能: 从控制台取字符(带回显) ) d. n4 {8 K$ ^6 G& q0 N
用 法: int getche(void);
3 | r" O0 F% |( E7 _! \* \程序例: </P>* Q4 |; B" n- k
<P><FONT color=#0000ff>#include <STDIO.H>0 Z. z* o1 Y; g0 R, `) w
#include <CONIO.H></FONT></P>
% f, q/ l, _2 l9 k1 s) q/ h8 B3 T. y<P><FONT color=#0000ff>int main(void) 2 w3 E& t7 l. X
{
1 A! v& R' L0 a4 zchar ch; </FONT></P>0 p" i0 |; c2 _) S$ U* S% X% g
<P><FONT color=#0000ff>printf("Input a character:"); . Z0 u7 w4 V0 G/ g# G
ch = getche();
0 O9 O5 s5 ]. n7 |: d3 a) Wprintf("\nYou input a '%c'\n", ch);
! o1 T* c2 x0 Preturn 0; + g$ s8 G' m5 C2 S
}</FONT> P' }8 Y6 S l' M4 T& [
* w& V3 J0 F+ f
</P>
( y9 e l2 |& e4 J<P><FONT color=#ff0000>函数名: getcolor </FONT>$ |: t8 Y% s1 |
功 能: 返回当前画线颜色
- G7 A5 X1 B6 `% z% Z用 法: int far getcolor(void); $ K8 Y5 J, y+ Z2 R* F$ C
程序例: </P>
. H+ N2 d) g( Q- ^% j6 X<P><FONT color=#0000ff>#include <GRAPHICS.H>
" W+ {* c3 T- \7 ]) U& V#include <STDLIB.H>
+ b1 c; v0 `8 S; D: q#include <STRING.H>
: X8 b2 h7 C' t. U/ W' |#include <STDIO.H>3 }7 `* x% ~+ @4 q
#include <CONIO.H></FONT></P>
% u% L- z2 H' l6 p* V* @+ M<P><FONT color=#0000ff>int main(void)
1 M# m1 o: k# ~) h8 B{
: E: Y" o3 k$ M9 u+ L @4 }. @/* request auto detection */ ' t* |$ b0 J+ j( q+ g8 F9 G) b
int gdriver = DETECT, gmode, errorcode; % D" }) b4 j* {* m
int color, midx, midy;
: @) h) E( s) M( c+ `char colname[35]; </FONT></P>. J8 }% v; r; a8 t
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& s, Q# _0 U. M: w, finitgraph(&gdriver, &gmode, ""); </FONT></P>
' s: _) m! o. S; q. f; N. J<P><FONT color=#0000ff>/* read result of initialization */ 3 u, `6 [. O# x4 }2 U
errorcode = graphresult();
- v/ U, {2 ^: J5 k9 N/* an error occurred */ 8 R$ F( ~+ y& U( d( F( E. Q1 W5 P
if (errorcode != grOk) ) w& F8 n, x# o8 l1 U1 t6 p# Y. o
{ ! i* D: U& w* Y
printf("Graphics error: %s\n",
0 R: e/ Y% M) k6 X8 y$ |grapherrormsg(errorcode)); ' \6 U3 N, Q2 W% T/ E) H8 v6 i W
printf("Press any key to halt:"); 0 c# V6 B2 ]1 z
getch();
+ F- T- c2 _$ f$ R1 f5 f3 ?/* terminate with an error code */
d( G# n- l6 R$ k4 \exit(1);
. a7 n4 D6 y6 e1 X} </FONT></P>- K/ o! V2 x6 @% d' \9 f
<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 R' l, J. g/ E9 }% D6 imidy = getmaxy() / 2; % Y8 f) `$ [; Z6 `! ?
setcolor(getmaxcolor()); </FONT></P>" _5 ~( I+ R' O' l" v
<P><FONT color=#0000ff>/* for centering text on the display */
/ l, w. Y: P; F1 ~( C7 D( t4 Ssettextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>! @& |% \$ z0 Y* W" x A
<P><FONT color=#0000ff>/* get the current drawing color */
) X- ~8 S# a+ Y- E8 H: `; kcolor = getcolor(); </FONT></P>
' K6 c" c3 V2 l( y<P><FONT color=#0000ff>/* convert color value into a string */ . X, B! l$ l( z/ i! ^; V
itoa(color, colname, 10);
, J/ W' c9 ~( a: Z! f I0 Gstrcat(colname, - y3 R/ Y1 s# ~% o
" is the current drawing color."); </FONT></P>
* `' U: H6 D; {7 T. g; r<P><FONT color=#0000ff>/* display a message */ , x* @' |3 C% N: R& ?7 p) Y
outtextxy(midx, midy, colname); </FONT></P>
* j' b' s4 Z: ~' o$ q* ?- [8 g<P><FONT color=#0000ff>/* clean up */
8 i. A: l2 p" `/ W' a" E- Q8 h8 S3 ]getch(); A3 g* Z1 O/ }; U$ R4 E
closegraph(); 4 W: T# n2 A4 }
return 0; / E: S4 o* _# L/ b. z; K
} + s. h9 j/ e# j
</FONT>' J% ]4 e3 D$ A3 L
</P># ^+ g4 c7 h( @1 f! b o
<P><FONT color=#ff0000>函数名: getcurdir </FONT>
( g J& }( w9 G$ {) w6 i功 能: 取指定驱动器的当前目录 6 R' w0 X; Z ?, m5 L% Q3 d
用 法: int getcurdir(int drive, char *direc); % i7 Q( h8 V) y F- V6 j
程序例: </P>
- G& f/ F7 g8 X( {& W1 \<P><FONT color=#0000ff>#include <DIR.H>% i& I e- l- @' F" A
#include <STDIO.H>
: `+ r2 v9 |7 F! T: r6 `$ l#include <STRING.H></FONT></P>. m. w# w; u ^/ K% F, X# t8 k* q
<P><FONT color=#0000ff>char *current_directory(char *path)
! J1 w1 |2 v, m: D6 K; I9 \{ 8 Q( ]6 l6 N) t2 L9 x; ~
strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
! A, [) y3 d) Y7 {path[0] = 'A' + getdisk(); /* replace X with current drive letter */ 2 i! b$ Y6 j0 j
getcurdir(0, path+3); /* fill rest of string with current directory */
' L0 [+ g0 c1 T A7 d; Ureturn(path);
$ a! W# ^+ @& f* u6 \% N} </FONT></P>
7 K$ H. r) d" b2 Y3 ?( h<P><FONT color=#0000ff>int main(void)
8 F/ M1 @6 g3 i' m+ o{ + e1 O- L2 y& R6 T L
char curdir[MAXPATH]; </FONT></P>9 i S- R* B U0 n& T6 S9 r
<P><FONT color=#0000ff>current_directory(curdir);
2 w, s* I# ~- U8 ^9 Q. F& I1 [printf("The current directory is %s\n", curdir); </FONT></P>0 u: _( ?0 Y7 h: `- J
<P><FONT color=#0000ff>return 0;
{# Z# }* F/ e, P}
" ]/ ?9 x3 f V% H# J! m</FONT>% K8 T. O" F+ X1 A; j
</P>3 d' d6 ~+ g7 `/ n, _% g! h
<P><FONT color=#ff0000>函数名: getcwd </FONT>' I( ?' w! e" s" i$ `9 p7 U! V0 P
功 能: 取当前工作目录
3 p" D9 B% j1 f8 \3 d4 `( q8 `, y Z用 法: char *getcwd(char *buf, int n);
& t7 j7 b5 o' [2 o程序例: </P>1 _/ m* O9 {% W0 D
<P><FONT color=#0000ff>#include <STDIO.H>
0 L" G: i5 ?& |2 @& B#include <DIR.H></FONT></P>5 [! F( m7 I& z5 Z: ?, D ?
<P><FONT color=#0000ff>int main(void) # @+ b2 M( t) d/ E
{
9 Z$ X0 k! s/ r& v/ l- R% Ychar buffer[MAXPATH]; </FONT></P>( f) P- a5 K9 M9 i: n9 A& C
<P><FONT color=#0000ff>getcwd(buffer, MAXPATH); ; T, A/ A& N; l2 l4 [6 ?( b( U* C
printf("The current directory is: %s\n", buffer); 2 f7 h% j# h7 a" h. B7 h
return 0; 6 j- v7 x. c9 p( x
} </FONT>1 O, ^) Y0 x; i3 F: O+ q) f1 t
' S; M0 t2 ?& c+ N$ x7 J
</P>
3 _0 c2 o* Z4 `2 n4 p<P><FONT color=#ff0000>函数名: getdate </FONT>
" ^5 A9 g7 o" E+ c$ y功 能: 取DOS日期
, c9 o$ g2 V8 z& J+ n$ e用 法: void getdate(struct *dateblk); 3 X) n1 {: F7 ~$ b( i1 V
程序例: </P>' i' T5 A+ K' [$ L+ {
<P><FONT color=#0000ff>#include <DOS.H> N9 x" V# ^7 F) i, g2 u
#include <STDIO.H></FONT></P>
% Q5 ?& _: u: D4 b+ \/ l. h<P><FONT color=#0000ff>int main(void) `3 l% D8 p" Q9 T/ p; \: L
{ ( T: H/ u* D( [& W1 F; P
struct date d; </FONT></P>
7 [0 O+ {, E0 G8 J) l' d( N<P><FONT color=#0000ff>getdate(&d);
( b" |. w. u6 y. vprintf("The current year is: %d\n", 8 a! x G9 K- t$ N# h( f E1 g
d.da_year); ) q9 U! {2 O$ i1 _. K
printf("The current day is: %d\n", " J! r& _; S+ G! z3 x- A' C
d.da_day); * W Z/ k$ A: H A
printf("The current month is: %d\n", . H- O- _7 O" u- s3 J! e& e% ^
d.da_mon); ! C/ { `/ M# s& B9 Y
return 0; - P( g# U& T; W8 C& z
} # [, ]7 b/ s6 A# O5 S
</FONT>
4 `( ?$ t, Q( u* h7 g</P>
3 I8 q$ y5 i3 ]3 ~8 Y- r<P><FONT color=#ff0000>函数名: getdefaultpalette </FONT>
9 v' o4 u2 b6 M: _* t% `功 能: 返回调色板定义结构 ) C% }. Y s1 @, |- e- q. f+ `
用 法: struct palettetype *far getdefaultpalette(void);
/ r$ S$ t" P& P+ K. I程序例: </P>
' b. s. A) l% K5 i4 k<P><FONT color=#0000ff>#include <GRAPHICS.H>7 u& I/ q a6 R1 ^4 p+ ?
#include <STDLIB.H>8 B$ z9 I! q; \3 e
#include <STDIO.H># ^* r$ o8 j, O; P
#include <CONIO.H></FONT></P>+ h6 `8 H( M8 A4 z3 X* h& D
<P><FONT color=#0000ff>int main(void)
O2 p5 c6 |" P3 q# H{ 9 o& t1 `; d' B" B( L3 v
/* request auto detection */
$ Y) b$ ^3 ] S' z( `" \( e3 ^int gdriver = DETECT, gmode, errorcode;
" b0 Z. z6 I, O, \/ }4 J' _* Jint i; </FONT></P>' Z) F+ U8 v- X: ]
<P><FONT color=#0000ff>/* structure for returning palette copy */ 4 u& M3 E; {2 s3 W$ }9 e
struct palettetype far *pal=(void *) 0; </FONT></P>
Z4 h, j# O7 \( B V2 _<P><FONT color=#0000ff>/* initialize graphics and local variables */ & v! f5 A( ?; _- R3 C/ C7 J
initgraph(&gdriver, &gmode, ""); </FONT></P>9 K! u) T- Y7 \6 e- K
<P><FONT color=#0000ff>/* read result of initialization */
3 y& O+ T/ }8 |* Cerrorcode = graphresult();
4 s: C. i( A7 K& w) B8 a/* an error occurred */ 6 S1 L; ^" s& Y( Q! b
if (errorcode != grOk) : ]& c% {7 }- ], f
{
6 w( z% y- t0 r: \printf("Graphics error: %s\n", ' d! |2 p; p6 o3 M4 U* K# N. u
grapherrormsg(errorcode)); / |& O) O' [+ D* A
printf("Press any key to halt:"); 3 Z5 K3 X* u" `3 M. Q$ S$ K
getch();
6 S- X0 X. Q/ a, f2 {! l' U/ A/* terminate with an error code */ 6 _: b6 M, ]0 [. }1 ]; O3 I. S$ e
exit(1); ) b2 x' l" G) |* X$ |) y+ a$ h: l
} </FONT></P>' n5 t) s a) G$ g) G3 Y$ u2 N2 Y
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
; ?6 j8 h0 t, a; C: k<P><FONT color=#0000ff>/* return a pointer to the default palette */
: A" R- k q# O2 W6 v& d3 T( Fpal = getdefaultpalette(); </FONT></P>0 |3 O$ f0 A+ T9 L; n6 `6 J9 j$ o- X
<P><FONT color=#0000ff>for (i=0; i<16; i++)
9 a) E+ K% H. n{ $ [( S5 u( W2 {* N6 U$ |/ _$ k. x
printf("colors[%d] = %d\n", i, / w7 U3 I, @+ i+ t8 Q1 _
pal->colors);
) q( ^0 q8 Y/ M& ngetch(); $ j) _' C V" c- X& b8 G
} </FONT></P>% u7 S$ ~% C: S( [
<P><FONT color=#0000ff>/* clean up */ % @# ]0 p9 E5 Y# f
getch();
5 P# m8 ^" K7 j4 y! uclosegraph();
$ D% b0 N! q, p# U2 N& {return 0;
6 f" ]+ m7 Y6 w} 0 {6 l6 w1 \6 ~( c9 T
</FONT>
8 s! u. c8 x; a9 M; }4 C5 r</P>+ P- B( g7 z, t5 I0 B/ h7 y
<P><FONT color=#ff0000>函数名: getdisk </FONT>% U* x* x- q; ]4 }- m
功 能: 取当前磁盘驱动器号
7 C' U% }) V$ ?9 Z8 }用 法: int getdisk(void); 8 ?( T0 i2 b7 l+ S. l
程序例: </P>; Z) K6 ~* W1 D( @( [* [" i
<P><FONT color=#0000ff>#include <STDIO.H>
! \$ U! {2 t7 U% h#include <DIR.H></FONT></P>
: ?" _5 _) R: ]$ e<P><FONT color=#0000ff>int main(void)
" U! Y$ p+ q, p% U, h{
+ _, U& C+ y) z4 X6 y1 @2 M: Lint disk; </FONT></P>
; q0 R8 R, z8 P; Z% @/ H<P><FONT color=#0000ff>disk = getdisk() + 'A';
; L; `5 O1 f" r$ b$ `. S4 eprintf("The current drive is: %c\n",
, L$ u" a% A8 s) t: P' B( g. Ldisk);
1 W" ~4 g) ]/ T. T( oreturn 0;
! B. L5 H( n1 w4 G}
; h4 [! |2 G# ]
( L A! I( s8 r& R- e% ^# Z. v</FONT>5 ~- U* ~( F: i3 b1 }
</P>) D W; I; }2 V6 w# D- }
<P><FONT color=#ff0000>函数名: getdrivername </FONT>
: K6 r( d+ I4 v+ P功 能: 返回指向包含当前图形驱动程序名字的字符串指针
8 I Z) B7 \& D; v用 法: char *getdrivename(void);
1 L% [( N' @5 W/ }: t6 Z程序例: </P>9 g; ^# R; M& B
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 d- b4 F7 n2 u9 Y6 V1 P7 d
#include <STDLIB.H>
% v7 O/ x' ^/ W- J#include <STDIO.H>
: ~4 Z5 h# t* g#include <CONIO.H></FONT></P>9 d+ W! x7 F( a3 t9 M6 [; r4 g1 @7 _
<P><FONT color=#0000ff>int main(void) & T# m# G1 a! s' \8 q6 `9 v* S# W
{
' A8 c/ T0 Y6 n+ ]/* request auto detection */
: `& Z D2 m7 s0 S2 Y, f$ m% E! N; hint gdriver = DETECT, gmode, errorcode; </FONT></P>- @! N% I1 q% ]7 S3 M- |9 |
<P><FONT color=#0000ff>/* stores the device driver name */ + }9 X8 r- T" S5 o3 P& g. J
char *drivername; </FONT></P>0 j7 c7 M) N7 i+ V$ r1 @
<P><FONT color=#0000ff>/* initialize graphics and local variables */
B$ |9 V( L8 U# h( \, uinitgraph(&gdriver, &gmode, ""); </FONT></P>
% `- `1 O3 B6 {$ _" W6 w# J, y<P><FONT color=#0000ff>/* read result of initialization */ * y* z3 T" D3 H$ R
errorcode = graphresult();
5 q9 c( u/ y' n/* an error occurred */
/ t3 u0 ^3 k/ K2 L6 gif (errorcode != grOk) + `5 D2 R% t. `7 y, {/ _6 P9 H
{
$ K$ X6 w0 T7 f" q( vprintf("Graphics error: %s\n", $ ~! P( L8 Y6 }( ?7 U l
grapherrormsg(errorcode)); 8 q5 M8 }) _( C( C B) o$ B+ u
printf("Press any key to halt:"); 2 p y1 ]: D) l' U
getch(); $ o. S9 j$ I) _! S. ?4 Q0 q
/* terminate with an error code */
6 z/ h* t1 L3 V3 X2 n" U n7 _; Qexit(1);
+ P4 A% [/ q) A; R} </FONT></P>2 p% }% r5 l4 O2 h
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>' |8 r6 q" C$ U; E. ^8 j' j
<P><FONT color=#0000ff>/* get name of the device driver in use */ 6 N. c- I( z8 K/ k" E
drivername = getdrivername(); </FONT></P>
; t: k6 r8 q4 C' p6 M<P><FONT color=#0000ff>/* for centering text on the screen */ 8 z+ m: n. _% |" N* Z' K
settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P># m2 Y( @ w9 i+ c
<P><FONT color=#0000ff>/* output the name of the driver */ 2 p' _2 C1 V. w, ?4 a" e
outtextxy(getmaxx() / 2, getmaxy() / 2,
0 j8 F8 V/ N* l( y7 p0 Ddrivername); </FONT></P>
7 Y% M' w, R. E$ T/ a, E" ?<P><FONT color=#0000ff>/* clean up */ 8 o# U: }# p3 P2 {8 K d1 F
getch(); 9 m1 Q) ^* E! x
closegraph();
( U% d( w9 y* s" f n: D2 Jreturn 0; ! }* [9 b5 K! C; j
} 9 O$ K0 A0 L0 [+ Z) }& k
</FONT><FONT color=#990000>
! J% W4 Y) n% e5 H! C</FONT></P>
/ Y% [1 N! d- O<P><FONT color=#ff0000>函数名: getdta </FONT><FONT color=#990000>- |5 ?+ L# T' z2 n% Q/ J% R
<FONT color=#000000>功 能: 取磁盘传输地址 7 [$ P9 l( i3 F7 l6 f, C
用 法: char far *getdta(void);
! ], L, x% V0 ~! {5 }程序例: </FONT></FONT></P>2 V: O: \# w4 `" [4 |* c
<P><FONT color=#0000ff>#include <DOS.H>
o ]4 {+ b6 f6 _/ g5 K#include <STDIO.H></FONT></P>; l( \: Z% q( J
<P><FONT color=#0000ff>int main(void) 3 ?: `4 M$ T0 F) R+ J! K
{ t" R" i, Z1 l8 Z0 I+ Q
char far *dta; </FONT></P> K$ U3 f+ S+ w7 H! F+ x* h5 s, z
<P><FONT color=#0000ff>dta = getdta(); 3 U6 }! L# k$ N6 |0 X. h
printf("The current disk transfer \ / p( ]5 D* I$ f P2 f
address is: %Fp\n", dta);
8 I* P8 l+ _9 O* h' z8 Breturn 0;
/ U; `: z( W* V: x, m5 Z- h1 o+ X/ _. K} ; @: Z0 C8 t; C0 h" R
</FONT><FONT color=#990000>& \+ `! {3 Z4 p; ]
</FONT></P>
, k1 u( K% e4 X8 q* C; ]; o<P><FONT color=#ff0000>函数名: getenv </FONT><FONT color=#990000>( N9 u9 a2 \* S* |3 s
<FONT color=#000000>功 能: 从环境中取字符串
* x0 s+ B! `5 o- X* S% g用 法: char *getenv(char *envvar);
! A: Z$ n( Q- j; a* M: P! f- [程序例: </FONT></FONT></P>
W% o6 z- \. S) X8 [2 @/ }* P<P><FONT color=#0000ff>#include <STDLIB.H>
2 ^' x0 B# l5 o ^4 b( t7 c4 y#include <STDIO.H>
5 u+ g" B1 q4 g</FONT></P>/ o2 M/ k8 v: T% m4 o
<P><FONT color=#0000ff>int main(void)
( _) s! a' p+ @2 Z{ : u# Z1 }& k! E- [. K2 V
char *s; </FONT></P># T& @/ \7 ~) s" K U( R/ n
<P><FONT color=#0000ff>s=getenv("COMSPEC"); /* get the comspec environment parameter */
& `' h6 Y# g$ }9 S Q+ `printf("Command processor: %s\n",s); /* display comspec parameter */ </FONT></P>
# k: h2 E$ h7 ~' g<P><FONT color=#0000ff>return 0; 2 t% T' ]( M: N
} </FONT><FONT color=#990000>
2 Y& ]" F4 o! U, Q3 A! l
2 h6 s$ F, c8 r1 e8 V- d# o+ W6 P6 I- n6 H
</FONT></P>
) n" v; D2 G; W* y% [<P><FONT color=#ff0000>函数名: getfat, getfatd </FONT>2 ]# {) l( @3 d' d. }0 R
功 能: 取文件分配表信息 7 u( E4 U* f4 ?* Q6 n) L& U; k
用 法: void getfat(int drive, struct fatinfo *fatblkp);
2 ^2 F( r2 f: o* R' ^* {6 d( L程序例: </P>
3 B e# d2 S( e4 N1 M+ Q$ m: w<P><FONT color=#0000ff>#include <STDIO.H>
/ Y& D; W) z" s( g# O$ p! t#include <DOS.H></FONT></P>. X/ x5 h! Y0 [2 g0 ]0 h0 T) C
<P><FONT color=#0000ff>int main(void)
/ }3 N% ^% ^- ~ s6 V8 i4 [& D{
9 m8 p6 s0 w! F1 q# H3 Z; V- |struct fatinfo diskinfo;
# U# S/ Z: m0 e$ \; Wint flag = 0; </FONT></P>
% ^+ d+ v8 h" K0 x& j- T1 k8 K! j<P><FONT color=#0000ff>printf("Please insert disk in drive A\n"); 9 ]: t. X. j# F" N6 B5 n
getchar(); </FONT></P>
X# A5 _0 E) f y" W<P><FONT color=#0000ff>getfat(1, &diskinfo);
4 T* P# w* w% z+ R y3 J/ `/* get drive information */ </FONT></P>+ t6 I* J/ s' Z8 L# _+ k w
<P><FONT color=#0000ff>printf("\nDrive A: is "); \- m# p+ Y/ f4 ]: B8 L
switch((unsigned char) diskinfo.fi_fatid) 1 m8 d! z2 d& t0 l
{
+ M- O" J" x& o5 `case 0xFD:
& B: p( {- u0 X; P6 _printf("360K low density\n"); : m' g7 p1 Y% H$ O9 Q2 t/ j$ R
break; </FONT></P>6 z& h8 P0 b; D; J$ Q
<P><FONT color=#0000ff>case 0xF9:
& X1 j) j1 F, }0 vprintf("1.2 Meg high density\n");
% j# ` ?! n& {# F6 ^break; </FONT></P>
; g: W" h# I# ~( B. z<P><FONT color=#0000ff>default:
, \3 ^2 N9 s i8 ?+ b4 [) r' Iprintf("unformatted\n"); - N/ \9 p! u1 u$ D" w f% r
flag = 1;
/ ^* Z0 h; ]8 [4 c7 o( p: Q* L} </FONT></P>
3 r3 a: M7 l; [' m e<P><FONT color=#0000ff>if (!flag) 1 a% A a0 u- F2 c2 }
{
" F) S5 C& S C1 Q' {printf(" sectors per cluster %5d\n", $ ~) \4 {8 c/ W& E2 x, I5 v
diskinfo.fi_sclus); + @6 t% v0 O$ B2 k' r
printf(" number of clusters %5d\n",
$ k+ k4 J, \3 D4 f( \- o1 jdiskinfo.fi_nclus);
" v* [4 p- ^+ I3 P/ xprintf(" bytes per sector %5d\n", ( j: Q' W) U$ N! o
diskinfo.fi_bysec); - d6 T* h) f- L6 I& j% y
} </FONT></P>
1 m2 l N4 h1 N+ y<P><FONT color=#0000ff>return 0; + M. \- N" C0 Y6 w, a+ {1 K
} 5 Z2 W. Z- X( t7 A" d# K
</FONT>, f5 h5 F1 R' H& E# j4 l/ Y
</P>0 t9 ]/ ?" m4 M
<P><FONT color=#ff0000>函数名: getfillpattern </FONT>
% R# i8 U3 p D/ p( ]功 能: 将用户定义的填充模式拷贝到内存中
; K6 E: h. y. { s/ m6 @9 h6 h用 法: void far getfillpattern(char far *upattern);
4 U4 p+ Z" v/ `0 ]# H2 O1 a+ ?程序例: </P>
6 `; K8 K1 T5 }$ L6 a/ F<P><FONT color=#0000ff>#include <GRAPHICS.H>7 g5 }6 X# G1 V0 ]; H* A% |
#include <STDLIB.H>
) p* J( ?/ K8 x) J/ R& E% b% H#include <STDIO.H>( }( F3 P+ N. X% @. @
#include <CONIO.H></FONT></P>1 C+ b; `" v* P9 W
<P><FONT color=#0000ff>int main(void) ; |$ a L1 ]; U2 ^% T( w6 v
{ ! r8 q0 V# l) k0 I& X) L+ s; p! e& g/ r
/* request auto detection */ : D% S8 D7 W; m5 @
int gdriver = DETECT, gmode, errorcode; * D: s% Q0 o; n' C. m
int maxx, maxy; 2 D1 V _) a+ a8 n# j. e0 l, u" z. h
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04}; </FONT></P>- `" m Y6 O8 s' o
<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 q8 L- k/ U- W+ s1 d7 M0 H9 Cinitgraph(&gdriver, &gmode, ""); </FONT></P>
3 ~% H# M3 N1 q! Y1 G9 l<P><FONT color=#0000ff>/* read result of initialization */
4 S3 C9 \, r- E' ]# d/ H0 j" herrorcode = graphresult(); ; Y; v" L6 i/ t: h9 `
if (errorcode != grOk) /* an error occurred */
6 j. T8 _( F9 q- s( M) \ H- ^{
# _1 S8 I, Y+ y$ F' r5 Wprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, F m* n# x6 g @, Y* d# o( X# Pprintf("Press any key to halt:");
7 Q* T. J5 @8 f' P: U5 `' h1 wgetch(); : t$ J; d6 B$ |
exit(1); /* terminate with an error code */
+ [, Q2 p* k' W1 Z4 f( _} </FONT></P>& O" L8 s$ j# L0 [9 [( o
<P><FONT color=#0000ff>maxx = getmaxx();
! e7 P) x3 U: J& [# A+ dmaxy = getmaxy(); / B' U$ W% `4 X, K
setcolor(getmaxcolor()); </FONT></P>
! Z" ] m/ C5 I; @& ^- ~9 y3 `' ?<P><FONT color=#0000ff>/* select a user defined fill pattern */
" R, ^. J* T1 z3 bsetfillpattern(pattern, getmaxcolor()); </FONT></P>
- t% |( }5 P+ e; L3 I+ W4 E5 D<P><FONT color=#0000ff>/* fill the screen with the pattern */ 1 V& Q3 b0 a% v2 P# k
bar(0, 0, maxx, maxy); </FONT></P>2 f1 S1 E" e& ~
<P><FONT color=#0000ff>getch(); </FONT></P>. I x1 L! K3 {; r
<P><FONT color=#0000ff>/* get the current user defined fill pattern */ 2 N# U/ k }0 p
getfillpattern(pattern); </FONT></P>
& q9 D. O9 _1 G; C- h j<P><FONT color=#0000ff>/* alter the pattern we grabbed */
" {6 e; U. C5 k% j2 ppattern[4] -= 1;
G: {5 H$ E- `. J* h4 z+ z' o* Cpattern[5] -= 3; % W/ y4 N" d" L7 _( x" D0 |: z9 I
pattern[6] += 3; . Q3 {( i! j! |% l
pattern[7] -= 4; </FONT></P>
( l: }2 ^1 D0 N8 b# E<P><FONT color=#0000ff>/* select our new pattern */ : J' y b- k' \/ z4 _
setfillpattern(pattern, getmaxcolor()); </FONT></P>. h0 e2 I6 h6 ~7 \
<P><FONT color=#0000ff>/* fill the screen with the new pattern */ * c! E& x. k+ ~% _
bar(0, 0, maxx, maxy); </FONT></P>
2 r; N# v; x+ I/ [<P><FONT color=#0000ff>/* clean up */
" U0 g" e! ?5 P. H! ^getch();
; z7 x9 t' ^( f2 b. eclosegraph(); # k) l3 q6 u6 _$ \! S! `# m! D& `. E. ^. L
return 0; ( W3 }8 J) B# ~' b* j$ J6 y/ _
} 8 d [' G( v% c) v
</FONT>
$ R% H: W2 L& I7 g( t {</P>7 O7 _9 j4 ~, [9 p7 F, x
<P><FONT color=#ff0000>函数名: getfillsettings </FONT>
. z8 k: ?4 T, V! k8 U& P功 能: 取得有关当前填充模式和填充颜色的信息 - x# O2 l( E4 d9 u
用 法: void far getfillsettings(struct fillsettingstype far *fillinfo);
3 \0 t/ O E5 K! j; f, G程序例: </P>( [. {6 B# H2 ^2 r+ c8 ~
<P><FONT color=#0000ff>#include <GRAPHICS.H># ~, C2 R' v9 \( |' l
#include <STDLIB.H>
) a3 [3 z W( P0 T# h3 Z0 X" \#include <STDIO.H>
+ L" m E1 B0 ?, O#include <CONIO.H></FONT></P>
" s7 a6 _4 T( f4 V w0 T( i<P><FONT color=#0000ff>/ the names of the fill styles supported */
5 l$ N* T2 |5 j0 x) j: o$ ]char *fname[] = { "EMPTY_FILL",
0 J5 j: m3 Z* W1 }3 B1 \"SOLID_FILL", 5 T. c% s* ~5 P+ x; g; F
"LINE_FILL",
8 s1 C+ ?% |1 p7 ]7 A) i; s"LTSLASH_FILL",
& o4 \# c+ k( ^6 [2 k"SLASH_FILL", ) b- I6 r2 e8 ]9 D V* f
"BKSLASH_FILL", . I8 Z% T1 @* Y" Z
"LTBKSLASH_FILL",
4 G9 T2 y: @ o, [! c"HATCH_FILL",
" d, B! G! t3 Z7 A+ j"XHATCH_FILL", % ^ d3 z; k! q1 v
"INTERLEAVE_FILL", 1 d y1 R" }/ w, X
"WIDE_DOT_FILL",
$ M8 L$ `6 @4 q( T1 `"CLOSE_DOT_FILL", ' G8 ?2 C8 z1 r* q
"USER_FILL" 8 L8 m! g) m) b* E. `" R9 @
}; </FONT></P>
& ^6 P* Y5 A5 O, i ~; I B<P><FONT color=#0000ff>int main(void)
7 Q; o" N2 T3 B, g6 X) z0 h{ S% K+ V7 e: w
/* request auto detection */
) R$ l4 ^: [. X: {9 { I3 g" Eint gdriver = DETECT, gmode, errorcode;
6 R- z" o# W: m* w( kstruct fillsettingstype fillinfo;
9 Z! C3 t/ s+ T+ aint midx, midy; " h% v: `4 U, S# J S( F' `! k
char patstr[40], colstr[40]; </FONT></P>7 Z1 g* n7 u4 d6 Z3 ?0 j! a
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ c9 J9 o; c: Winitgraph(&gdriver, &gmode, ""); </FONT></P>
6 B* Z0 h5 m; k0 D1 \: ~& Z! S<P><FONT color=#0000ff>/* read result of initialization */
" J0 r- A4 O( L+ P+ P3 {- Kerrorcode = graphresult(); - U% r, s+ \0 L9 i+ X2 w; @7 e
if (errorcode != grOk) /* an error occurred */ & ]" Y) F) V# n: J
{
- t7 A! n7 I+ S) oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 d9 [% g- t. R; \1 i; H* V5 l" sprintf("Press any key to halt:"); " O* J2 M2 y3 ^- }3 g* s
getch();
6 ^0 r% b+ G& M! z g/ rexit(1); /* terminate with an error code */
% a2 c& E5 r1 y1 N5 C0 q; m} </FONT></P>, @, \! p d. s! t
<P><FONT color=#0000ff>midx = getmaxx() / 2; * j/ G4 G, {# f* j V) p
midy = getmaxy() / 2; </FONT></P> @5 Z1 i% B4 W* J
<P><FONT color=#0000ff>/* get information about current fill pattern and color */ , m: Y3 ^. J% e5 p* U
getfillsettings(&fillinfo); </FONT></P>) I+ T3 C1 X# q# _4 @9 ^" l) q, V
<P><FONT color=#0000ff>/* convert fill information into strings */
# R2 e. p5 w% ysprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
/ f& |1 o6 W/ N% J3 Rsprintf(colstr, "%d is the fill color.", fillinfo.color); </FONT></P>
3 ]2 a/ A2 m% k& ^$ n/ V<P><FONT color=#0000ff>/* display the information */
+ k- Q; Z2 u, P' T& r# ?, N+ nsettextjustify(CENTER_TEXT, CENTER_TEXT); 1 N* _" i4 I6 Q& q
outtextxy(midx, midy, patstr);
1 `$ i7 _* A: o4 x5 Kouttextxy(midx, midy+2*textheight("W"), colstr); </FONT></P>
7 h; t+ O; l; D5 V0 i- C0 g<P><FONT color=#0000ff>/* clean up */
! R/ I+ @: s& K5 h( W/ [getch(); / \3 G- y) S- x" H: V- U, Y
closegraph(); 2 N: [2 X3 g$ d" L
return 0;
- s9 V; x( I/ w4 H5 T}
) l/ T d1 g! m7 G</FONT>) B" [9 U9 ~. y/ w+ @6 `
! n8 P% ?- d; f9 ^, E
</P>0 q* G$ v- k/ q, D% p' K. n
<P><FONT color=#ff0000>函数名: getftime </FONT>( |6 n) {( o3 Q+ G7 h
功 能: 取文件日期和时间
5 H1 K) e) e1 g( A用 法: int getftime(int handle, struct ftime *ftimep);
, x+ {- M" `" I5 H程序例: </P>
5 T6 c- v, _" W3 j6 W<P><FONT color=#0000ff>#include <STDIO.H>
! {" D. f) z; i% ]6 [/ M2 M#include <IO.H></FONT></P>3 |9 x& {! j8 C; M, U/ x$ _: Q9 D
<P><FONT color=#0000ff>int main(void)
+ _- k( A* Y4 w# e% r% p+ ?( J{
+ k+ Y% y0 s% R& O% bFILE *stream; . p5 t) L: I4 X/ v. D$ m7 F
struct ftime ft; </FONT></P>. J8 g& w" Y5 }( j* C
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$",
" a; A* L3 ?6 o/ {; }"wt")) == NULL) 4 ]: N6 S( e8 `+ E
{
0 k* D" U8 H, nfprintf(stderr, : `* I" K2 |+ c7 k1 U' c$ V
"Cannot open output file.\n");
) H" D; D, R" Xreturn 1; & }& n3 Q0 R9 {$ m2 g6 A) q( i, b
}
( F& j& B# b: ~getftime(fileno(stream), &ft); ( n0 Z7 ^' b+ U t3 `2 X; G( |
printf("File time: %u:%u:%u\n",
/ m& z6 R1 P2 @; }5 Xft.ft_hour, ft.ft_min, / E" w0 J7 y( K1 J( i$ ^$ a. F3 l
ft.ft_tsec * 2);
4 [& `/ y* N" E9 v- @5 z$ Lprintf("File date: %u/%u/%u\n",
/ h0 }5 p1 k2 j" g6 N8 |ft.ft_month, ft.ft_day,
$ `1 f8 C3 y hft.ft_year+1980); * u8 p U: q: \% p& S& @
fclose(stream); 5 J. `7 |6 X/ v% x
return 0;
* V( p- u' _5 K3 O} # v6 S7 K% ?9 Q$ t
</FONT>" K; ?: n$ v2 `; S
& b' {+ f8 q! q) U$ |4 x' Z$ E3 d</P>
9 |' r+ [9 @& g<P><FONT color=#ff0000>函数名: getgraphmode </FONT>2 X) n! v( K' e C
功 能: 返回当前图形模式 . [8 P6 W5 ~6 [, F* b. c
用 法: int far getgraphmode(void);
: ?; C6 V; r c+ ~' }! B) U# t程序例: </P>
S- @7 t! q k$ ]$ s<P><FONT color=#0000ff>#include <GRAPHICS.H>
# h# \6 }: V7 N9 Z. s$ i#include <STDLIB.H>
- ~) C6 \8 \7 _, J$ k#include <STDIO.H>
: s' W5 [& \6 h9 a8 A#include <CONIO.H></FONT></P>' \# u D( i3 f) Q7 L2 d
<P><FONT color=#0000ff>int main(void)
' Y. Y* P) D* ]) y' I6 I{ . i% y& i. t: V7 P1 U
/* request auto detection */ 2 M( h' S2 C1 O/ A2 c' h% Z
int gdriver = DETECT, gmode, errorcode; 9 u/ z9 ^4 L0 V- r) z$ d
int midx, midy, mode;
" c6 T6 n. L4 |. T8 a& \/ t+ m, Lchar numname[80], modename[80]; </FONT></P>
( {7 a. k" ~3 w( A<P><FONT color=#0000ff>/* initialize graphics and local variables */
, O f: W2 [7 x- ^8 \/ h! c6 Zinitgraph(&gdriver, &gmode, ""); </FONT></P> |" e% H0 t! S
<P><FONT color=#0000ff>/* read result of initialization */ 2 T* I. {2 l' T! a7 C' o% q; P. h
errorcode = graphresult();
_" d. g1 k K( h) D" o1 c/* an error occurred */ 2 e) l7 e# ^; w" E
if (errorcode != grOk)
0 G; t1 `2 b+ [' R. ]* l% j w. w{ 0 m1 R3 ` S: ~# o/ n7 p; ?: G2 t: {! H
printf("Graphics error: %s\n",
7 L$ D j. a a+ Ygrapherrormsg(errorcode));
/ q5 ?% u* M7 g: T0 ]3 B8 Tprintf("Press any key to halt:");
. Z7 S" g$ @* p# l( x- y( |getch();
5 A) D) b- B" P3 A; ] t! t/* terminate with an error code */
1 Y) f( j0 |/ E7 q4 Aexit(1); : M( |4 r8 ^# T1 D# @9 y
} </FONT></P>6 L, o2 \" ]" V0 n
<P><FONT color=#0000ff>midx = getmaxx() / 2;
, P: k7 H. }; K: Cmidy = getmaxy() / 2; </FONT></P>
& ~4 p& M6 L* y" ^0 r<P><FONT color=#0000ff>/* get mode number and name strings */
& ~ f4 w/ q2 ?6 H! J- J& c: ymode = getgraphmode(); 1 c% ]8 B% Y- G- O
sprintf(numname, 0 d+ {5 \ B2 x' y7 X* ~- _, Z- G) I, ]
"%d is the current mode number.", : d( o, Q; q! U1 n
mode); % m C) |$ }: m7 @# b; p
sprintf(modename,
! S2 C7 c/ [( {& ]"%s is the current graphics mode",
3 v6 k5 z; Y) J6 ~$ n+ b& ygetmodename(mode)); </FONT></P>
' e' \4 t3 }% k' Y' t9 B/ X0 i<P><FONT color=#0000ff>/* display the information */
1 M2 U0 z$ s2 k; D$ o5 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); 6 w- h+ b' R9 D4 }- T: ^
outtextxy(midx, midy, numname); O' o) h) i8 H- h
outtextxy(midx, midy+2*textheight("W"), + u3 M& d0 N2 n
modename); </FONT></P>4 a) g5 ?7 G2 q0 |
<P><FONT color=#0000ff>/* clean up */
4 g# q) a! f; d. x" ]. E* lgetch();
t& c6 x8 n- z0 h2 Wclosegraph();
1 d( N8 ?( V. hreturn 0; / \+ C- ?* ?% y3 C S8 K+ z }
} </FONT>
4 h& t: X" i( y0 U5 n7 Q' R9 v5 h! p+ d4 O" L. Q( m
</P>! ?4 V) k* v0 C" s6 S9 L& o
<P><FONT color=#ff0000>函数名: getftime </FONT>' J9 Y7 g0 L! j$ ?3 W
功 能: 取文件日期和时间 C' e: U4 |% T! ^2 l" K; ]& g" I; T
用 法: int getftime(int handle, struct ftime *ftimep);
0 X9 {0 [+ n8 Q! U2 A# @' t. x程序例: </P>
' n! }; j- b7 S( A Z3 Y x9 c+ I<P><FONT color=#0000ff>#include <STDIO.H>( E7 p& I [$ v4 p: k& r
#include <IO.H></FONT></P>7 _- J) b$ A1 |9 X. i
<P><FONT color=#0000ff>int main(void) ; g) a3 Q$ k0 d1 N: Z V w. r! Q
{
" i7 R( V1 M7 b% s }8 h9 `% cFILE *stream; 2 A2 I0 [6 ~# ?4 p
struct ftime ft; </FONT></P>- {. k) s% Q/ [, z9 i* C) e
<P><FONT color=#0000ff>if ((stream = fopen("TEST.$$$", 5 m9 C3 [) j/ m% S ^& Z' |5 {$ ?
"wt")) == NULL) 2 ~* I& @1 a% U( @: D1 }; s
{ ! G( @0 U) @5 r ~1 w
fprintf(stderr, ) I! a" e; ~, Z
"Cannot open output file.\n");
! C3 t* t- W* {1 h- Yreturn 1;
$ l" X5 [5 M4 |. @2 o' G) C2 K}
; H; k6 ]* r& ^7 \1 p) ]getftime(fileno(stream), &ft);
1 }6 p6 n" ]# r1 ~- c9 ]! gprintf("File time: %u:%u:%u\n", ! E0 d' s& ~2 D9 a6 p) n2 ]' Y' j
ft.ft_hour, ft.ft_min,
/ b6 Z7 ^6 F5 k% Z! r! Uft.ft_tsec * 2); ! [: o8 {9 F, S
printf("File date: %u/%u/%u\n", 7 }+ p) X, e1 R- A" g5 h
ft.ft_month, ft.ft_day, / Q4 H- Q, |! G! x/ U }+ v
ft.ft_year+1980); * i" ?( G, |- ]7 Z5 }/ S: C
fclose(stream); 1 d9 o. Q. S# E% }# `( D) ~9 }
return 0;
5 Z0 e% _: r$ e0 [' u} </FONT>
; k/ m" h3 g+ E2 z' Z E* m1 |! W4 q& g3 s1 _2 j
- b( w9 q d& b7 G8 f( s: B
</P>
9 X! Z8 I; B3 M$ X<P><FONT color=#ff0000>函数名: getgraphmode </FONT>
- E* X0 ?- F" [( L功 能: 返回当前图形模式 : m( i2 g4 L" \( o! D% W- [
用 法: int far getgraphmode(void); 9 ~* I& A! S* W$ t; D
程序例: </P>
+ n: N% o9 p" K) L; ?4 F( }. O0 S/ ?' I<P><FONT color=#0000ff>#include <GRAPHICS.H>! \! S/ }) y' g0 X- X; k
#include <STDLIB.H>
4 W3 b q0 K9 b$ J5 [9 N1 ]" v0 z#include <STDIO.H>
3 U( q& L7 K, z& n; a#include <CONIO.H></FONT></P>
* ]6 b3 R$ }) m$ g: e) q- O<P><FONT color=#0000ff>int main(void) - ^" @' A( f/ D: u1 P7 d$ T1 j
{
, T" c# a* t$ S- M( Y/* request auto detection */
! V$ O& H( j! Yint gdriver = DETECT, gmode, errorcode;
& |2 J- }$ W2 aint midx, midy, mode;
% o, d& _2 {+ y" L O+ Q7 Rchar numname[80], modename[80]; </FONT></P>
1 G; }, T. R( w) w2 U6 O<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 V. |$ o0 U1 Y1 Ginitgraph(&gdriver, &gmode, ""); </FONT></P>, [; b' L) }) |( n0 P
<P><FONT color=#0000ff>/* read result of initialization */
/ K6 S0 t- N2 F' f7 oerrorcode = graphresult();
: A6 D$ p9 H& k/ M/* an error occurred */ 6 \: u5 c6 E" k( z5 O- f4 x
if (errorcode != grOk) 2 S) }0 l# J! ~; v! v
{
1 g7 G% }5 L7 zprintf("Graphics error: %s\n", % @3 V# J2 ]5 S
grapherrormsg(errorcode));
( y/ ~' T; r, y$ y* Fprintf("Press any key to halt:"); & U/ M5 u" r$ k: o& V) z, N+ R( e
getch();
2 o- W; r: d# K4 b0 l/* terminate with an error code */
4 {( y1 W" V% a% d1 R: l5 B9 V; Kexit(1); 8 A$ q9 A2 |2 D+ ^; b
} </FONT></P>$ C$ {1 b4 t0 W7 G6 `1 Z& t1 q
<P><FONT color=#0000ff>midx = getmaxx() / 2;
, C7 n4 ^1 s% s! s% ~midy = getmaxy() / 2; </FONT></P>, `! j3 C" A5 k7 x9 C- Q) \
<P><FONT color=#0000ff>/* get mode number and name strings */
- O3 d' _. o) |' N. T5 mmode = getgraphmode();
2 O% p3 A% [3 K2 k4 q _sprintf(numname, 0 b0 ~$ G' u0 d
"%d is the current mode number.", 8 l+ b& O- I; A4 G( P: F: A5 B+ _! J
mode); ) H9 t9 }- E4 m [) @
sprintf(modename,
$ S8 k* k. @8 o6 C2 Y8 \; `4 N+ A" s"%s is the current graphics mode", : M U1 @" f+ j+ g. P
getmodename(mode)); </FONT></P>6 H8 r( ^1 ^% C7 W5 j2 [ _
<P><FONT color=#0000ff>/* display the information */
$ x5 E" o ]- P# V! R% H* G/ Zsettextjustify(CENTER_TEXT, CENTER_TEXT);
: V) q/ ?* p! r/ p; mouttextxy(midx, midy, numname);
( \: x' m' @6 x" Eouttextxy(midx, midy+2*textheight("W"), u1 B0 |% c; s1 w
modename); </FONT></P>7 [8 q T4 W7 w0 r5 \- O8 l
<P><FONT color=#0000ff>/* clean up */ 2 |0 k* C2 c8 A! [
getch(); 2 n$ u9 W3 |0 F5 o
closegraph();
4 a5 O* [; C( Y9 {9 A' z3 Breturn 0; " h8 G8 e! O% n: @% n4 `
} 4 \; Q4 d; b: Q) b0 v7 m$ y
</FONT>
( R5 @' |: K* y: A7 H</P>7 ?( E# L/ E1 ~8 H' t
<P><FONT color=#ff0000>函数名: getimage </FONT># n1 W0 O8 Y* d8 I, t
功 能: 将指定区域的一个位图存到主存中
; _9 @! ?+ B* T0 _4 L5 G# k# m用 法: void far getimage(int left, int top, int right, int bottom, ( ?$ K2 |9 y+ A# }' T8 J
void far *bitmap);
) U0 a- N W k1 i4 a, v4 r% k; l程序例: </P>
, P" d; O6 ?$ D, N' K {<P><FONT color=#0000ff>#include <GRAPHICS.H>1 S. l8 u. p+ [8 t( z
#include <STDLIB.H>5 W& n2 Q& u0 m7 ~, L9 v3 Y
#include <STDIO.H>/ i5 y5 K) Q c: ^; c- r
#include <CONIO.H>7 a) |" ~/ v$ t k
#include <ALLOC.H></FONT></P>
6 P0 N: n' y5 y+ l$ o; C% ]5 m& ~<P><FONT color=#0000ff>void save_screen(void far *buf[4]);
* |3 z, ~ N8 Q) I: \6 V. vvoid restore_screen(void far *buf[4]); </FONT></P>
^% _- g: P1 F' B<P><FONT color=#0000ff>int maxx, maxy; </FONT></P>9 p; L: N& \3 @' |! V2 y8 N. u
<P><FONT color=#0000ff>int main(void)
& V6 x3 E0 R9 U+ v{
5 l! A r& N9 Xint gdriver=DETECT, gmode, errorcode;
, k3 q; q- G+ Q" ?( m4 a$ E. F4 rvoid far *ptr[4]; </FONT></P>
" X T, }2 C- l5 I( M' `' Z; c4 A<P><FONT color=#0000ff>/* auto-detect the graphics driver and mode */
" e9 Q9 j$ S8 qinitgraph(&gdriver, &gmode, ""); : f1 ~9 J" P1 y% |* ~5 ~ b
errorcode = graphresult(); /* check for any errors */ . X" _- _" g2 m/ v) Z4 f
if (errorcode != grOk) 9 m8 g& C. g2 T' ^' v* Y
{ 4 r' j2 |( b2 w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); : t9 ?9 J- [1 S& Z( Y5 o0 ?
printf("Press any key to halt:");
+ h# B/ a& d3 [- V# V7 S- qgetch();
L8 W+ |( y8 b. gexit(1); ' R- g- [% P9 y
} , H$ ]9 E( D0 f8 [5 D9 X
maxx = getmaxx(); , l' ?& p$ ^6 w! e
maxy = getmaxy(); </FONT></P>
* Q1 t( j ?7 h( s! A+ Y<P><FONT color=#0000ff>/* draw an image on the screen */ ! X5 q* m" a) Y, H
rectangle(0, 0, maxx, maxy); ! x% c, Q; x( i O
line(0, 0, maxx, maxy); 4 f* \* ~0 ? a! _. j- |9 X* H! @
line(0, maxy, maxx, 0); </FONT></P>) i# S6 u5 A) ~1 K
<P><FONT color=#0000ff>save_screen(ptr); /* save the current screen */ . g( ?* t% \; r! ^" v/ h4 H. u- u
getch(); /* pause screen */ " ?* I3 J# r) u- W$ H3 m8 s
cleardevice(); /* clear screen */
+ \5 b2 X8 D* S Frestore_screen(ptr); /* restore the screen */ 7 \4 i9 L' @) H/ x
getch(); /* pause screen */ </FONT></P>+ e) o) q' u$ O6 m9 \! p( X
<P><FONT color=#0000ff>closegraph();
3 X7 m4 t$ C& {0 }1 p" r( ~' ireturn 0;
* {* Y, M# A4 v, U} </FONT></P>
$ H6 K( I4 P& u# b: l- _<P><FONT color=#0000ff>void save_screen(void far *buf[4]) 7 l8 ~, k" p+ g k' A0 n3 s
{ : w! P4 w$ h* Q, {
unsigned size;
; ?* {4 q: i" o& c! pint ystart=0, yend, yincr, block; </FONT></P>
1 J, Y$ F2 B) y7 T8 D- `<P><FONT color=#0000ff>yincr = (maxy+1) / 4; , j& s% S2 B' {% p, m
yend = yincr;
# v* h: J- J% d$ u' Z F% K5 ksize = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>
) w7 v& e. e$ }3 u# Y0 g9 t<P><FONT color=#0000ff>for (block=0; block<=3; block++)
- y. g8 l/ [) z; Z{ 4 V( a$ P* u V: I- g
if ((buf[block] = farmalloc(size)) == NULL) # \# p5 E6 T4 L0 T2 q
{
5 K9 M" M- N/ Vclosegraph();
; Y8 M# k- f5 P4 I( qprintf("Error: not enough heap space in save_screen().\n");
) C3 h8 t) e& U* g. z) L# ^exit(1); % M7 }, b3 U q* k5 l: L
} </FONT></P>
- A. ~$ C2 s9 a! j% X$ ^, I<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
" ] J+ x3 V2 x8 g$ kystart = yend + 1;
* k! u2 M$ k* Hyend += yincr + 1;
# |9 u) c$ A6 M2 H* v& L} $ b% D$ K2 @; h* K! `4 c5 w5 s
} </FONT></P>8 m# a$ q5 y( [( t7 q
<P><FONT color=#0000ff>void save_screen(void far *buf[4])
1 s: | k* E4 O5 A9 P! S' ~{
, r$ ?- _; S2 u. t/ x- W) Ounsigned size; * Q: d( r0 Q" U1 f# @3 v% n$ Z
int ystart=0, yend, yincr, block; </FONT></P>& a9 E1 Z. m8 v; o6 ` A
<P><FONT color=#0000ff>yincr = (maxy+1) / 4;
, z/ Y _# ?8 vyend = yincr;
" ?8 `' P9 U; r/ }size = imagesize(0, ystart, maxx, yend); /* get byte size of image */ </FONT></P>- i/ |3 K e" r% s+ z' R' g
<P><FONT color=#0000ff>for (block=0; block<=3; block++) / e( l% D* \7 @+ h4 }+ g* i" Z: m) [
{
L! H+ [& M4 P3 Z, Vif ((buf[block] = farmalloc(size)) == NULL) % K1 b2 I2 c! v( Q$ M; g9 F3 m
{ $ F$ Q' e* N) e2 q8 Z# i6 D6 u& l
closegraph();
. m5 V+ ~) `, h1 W6 Mprintf("Error: not enough heap space in save_screen().\n"); X9 l3 D \# ~9 O/ |) U @, j& Y' V
exit(1); ) T4 a, i+ n: f
} </FONT></P>7 G0 G" G" |* m& S% l/ h2 _! H
<P><FONT color=#0000ff>getimage(0, ystart, maxx, yend, buf[block]);
8 ^9 e% ]# k! eystart = yend + 1; - { |/ S4 e% t$ h2 m. Q
yend += yincr + 1;
7 d+ i4 S) [) N" O}
. X7 L2 \' `/ a! ^: u} </FONT></P>
; Z% D" B- o! t<P><FONT color=#0000ff>void restore_screen(void far *buf[4]) ( j3 H' p+ O5 M+ }
{ 0 t- H' \2 } A: o& X, M; _
int ystart=0, yend, yincr, block; </FONT></P>/ Y0 c$ n- m* l7 d {0 n
<P><FONT color=#0000ff>yincr = (maxy+1) / 4; [& J$ M( p! x, U: W
yend = yincr; </FONT></P>
, i% y7 }! }/ i7 Q4 |6 U0 G3 b<P><FONT color=#0000ff>for (block=0; block<=3; block++) ( c' J4 o o5 ~
{ # J& c7 k) \- O8 f: j0 V
putimage(0, ystart, buf[block], COPY_PUT);
( V, B _! u6 x# N, U7 ^farfree(buf[block]); " W. _# H! n& m4 e
ystart = yend + 1;
( g5 f2 U% r( b- t8 Z# byend += yincr + 1;
' S: _, ?/ H0 X+ Y} 9 E) \5 l; }; \- ]( D9 A
} </FONT>
3 z# B. W7 I1 Y# H* h<FONT color=#ff0000>
6 a% Z- Q: E! k" d" g</FONT></P>
& o' t3 V# m5 `, L<P><FONT color=#ff0000>函数名: getlinesettings </FONT>
& D6 q& D4 Z! s2 C! b6 _功 能: 取当前线型、模式和宽度
7 l3 x% H! f4 A3 `0 d' n用 法: void far getlinesettings(struct linesettingstype far *lininfo):
3 `# `, D R$ Y4 g' d程序例: </P>. j* `3 O& _! s
<P><FONT color=#0000ff>#include <GRAPHICS.H>
y, b0 B! f! T4 p#include <STDLIB.H>
, s6 K; I0 a" Y3 V#include <STDIO.H>
% J, p8 ]7 U5 d4 j. X#include <CONIO.H></FONT></P>
5 ]& W+ V9 A+ n' M<P><FONT color=#0000ff>/* the names of the line styles supported */ - i/ f* b$ s- h
char *lname[] = { "SOLID_LINE",
% g, m7 y3 F- S6 }( c% W"DOTTED_LINE",
" I# [& E( ]/ J"CENTER_LINE",
- }; G2 c$ X* E( j8 E& G) Y8 E"DASHED_LINE",
3 V2 w, h; k5 k- J3 f2 h"USERBIT_LINE" 2 {& ~% F! O: R0 s$ G
}; </FONT></P>- M8 T) ^+ A" V7 f4 E
<P><FONT color=#0000ff>int main(void)
* i& j5 g& G& \1 y{
$ F8 ]! g+ J0 c1 v- N/ S' K/* request auto detection */ 2 l3 A) F4 `9 L( u7 S1 S
int gdriver = DETECT, gmode, errorcode; * K: c& t# s# Q# }) P8 x
struct linesettingstype lineinfo;
( C {8 X3 A* U; w- ], Oint midx, midy; " L3 c/ O& Q& Q8 e2 g% E
char lstyle[80], lpattern[80], lwidth[80]; </FONT></P>4 S, e0 w& \- l$ P
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 o$ B+ E4 {. v/ A; v c5 Winitgraph(&gdriver, &gmode, ""); </FONT></P>- G$ w8 N s# I
<P><FONT color=#0000ff>/* read result of initialization */
' h$ ^) G( }/ ?0 |) e/ o3 A8 oerrorcode = graphresult();
& M! O* S& o. `, h2 z2 cif (errorcode != grOk) /* an error occurred */
3 S6 m/ V) Q( x6 v( a1 g{
0 X; f( o, k9 }: Q u/ Qprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 `/ n; Q, e# S5 m4 w+ I) f8 `8 c
printf("Press any key to halt:");
/ h6 n! @. w% G0 y* M& f+ _/ tgetch(); # z+ I9 n# n4 L0 n; R
exit(1); /* terminate with an error code */ # f: o; W$ x* P5 H) Z
} </FONT></P>* C( O/ t* a! g$ y- }- {* C
<P><FONT color=#0000ff>midx = getmaxx() / 2; ' Z# q% }5 e1 i s3 Z; `0 X
midy = getmaxy() / 2; </FONT></P>" S. T- k$ K, J
<P><FONT color=#0000ff>/* get information about current line settings */ - `( l: B- V' v: i' C
getlinesettings(&lineinfo); </FONT></P>
% s* K* L2 p7 m1 B7 p<P><FONT color=#0000ff>/* convert line information into strings */ , i6 u0 C, x/ A$ K# u7 G
sprintf(lstyle, "%s is the line style.", 1 `) a0 O+ j! m
lname[lineinfo.linestyle]); 2 K+ o+ a8 u& t$ i4 J$ D( _2 }
sprintf(lpattern, "0x%X is the user-defined line pattern.", $ [& G3 O h }) G3 `
lineinfo.upattern); 9 o$ H3 x: U. o
sprintf(lwidth, "%d is the line thickness.",
1 b: F$ ^- P0 j$ ?; `lineinfo.thickness); </FONT></P>; k1 X) j( h( h4 `. l& y
<P><FONT color=#0000ff>/* display the information */
$ I4 l" B8 {: Nsettextjustify(CENTER_TEXT, CENTER_TEXT);
. v# v A% @: Y$ k+ R7 aouttextxy(midx, midy, lstyle); 0 L! c, M9 b2 t0 a1 s
outtextxy(midx, midy+2*textheight("W"), lpattern);
3 z. x) q9 O9 b3 o6 N' Zouttextxy(midx, midy+4*textheight("W"), lwidth); </FONT></P>
q! R1 _3 g$ S<P><FONT color=#0000ff>/* clean up */
1 \% b1 v6 E$ g5 n, E$ dgetch(); " `' A/ Y) h9 D$ b o
closegraph();
. W C( F* p, |2 oreturn 0;
7 B0 Q' ]2 p# i* |* h4 z} </FONT>7 D3 { n& W! |( o
1 u" X5 B- F0 v8 t5 r" \
</P>
$ u- i8 U0 V4 @3 n7 d<P><FONT color=#ff0000>函数名: getmaxcolor </FONT>9 y" J( p* G0 e8 Q2 \* ?$ N
功 能: 返回可以传给函数setcolor的最大颜色值
+ Y* F# y# A) a% l用 法: int far getmaxcolor(void);
3 P, ~7 N7 P- W6 H9 \程序例: </P>
8 ]( ]9 G6 }, ?) P2 k5 j( V+ C<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ ^& r0 w, J g) k8 B#include <STDLIB.H>$ n7 C `, e: s1 s9 g1 \0 B
#include <STDIO.H>
5 W4 F5 r9 F9 p# J& O" T. F#include <CONIO.H></FONT></P>
& x2 j) Y0 v$ ^/ Q9 x<P><FONT color=#0000ff>int main(void)
5 K+ d: F7 D! n1 Z{ 0 n( m! x1 f2 g; R& P0 f" V$ M
/* request auto detection */ . b$ Z5 u5 F. K
int gdriver = DETECT, gmode, errorcode;
& T5 e3 [ t _int midx, midy;
; q# \; E$ {, _( @char colstr[80]; </FONT></P>. J! K Y, w" U& e4 S! X
<P><FONT color=#0000ff>/* initialize graphics and local variables
' V4 U& e) \5 q: e- G5 K3 c0 A! G*/ initgraph(&gdriver, &gmode, ""); </FONT></P>
3 }0 g0 l1 z3 N: D1 m' U1 i<P><FONT color=#0000ff>/* read result of initialization */ " z/ O5 q9 t2 X4 L* v; I: c
errorcode = graphresult(); ! J8 ^# [& ]! f9 x8 l0 O
if (errorcode != grOk) /* an error occurred */
: b) I6 c# ?6 m( e{
: O! }- U; P( j \! E2 qprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 N5 q/ c( j9 }! cprintf("Press any key to halt:");
3 R* j. K+ J* `, J/ Igetch(); ( S/ T8 d1 P5 o* V- n( Z
exit(1); /* terminate with an error code */
0 d8 d1 F9 i( N* h/ e$ @7 M2 K} </FONT></P>
; |* ]3 W3 W; j<P><FONT color=#0000ff>midx = getmaxx() / 2;
- } M- Y, z! rmidy = getmaxy() / 2; </FONT></P>
' L, M2 }) A2 _. M0 J- P<P><FONT color=#0000ff>/* grab the color info. and convert it to a string */
4 j0 p* c5 B8 Gsprintf(colstr, "This mode supports colors 0..%d", getmaxcolor()); </FONT></P>8 Q; K( s) V$ a" ^. F! R+ s
<P><FONT color=#0000ff>/* display the information */
. k" ^2 |- S( `# \& msettextjustify(CENTER_TEXT, CENTER_TEXT);
2 S9 d4 G' \; I: W* i! B9 @0 |3 I; nouttextxy(midx, midy, colstr); </FONT></P>
; ^* ?9 e0 k( Y: c- {<P><FONT color=#0000ff>/* clean up */ 9 k9 ?/ Z( s8 d* x
getch(); + f) G8 e$ T4 d. K
closegraph(); # Y8 L0 G9 k9 S2 A+ u
return 0; 5 \3 `7 _3 {6 D8 B. @4 r
} </FONT>6 U: k6 v! ~* U
& u, ^0 w* q4 m8 ?0 Y, }+ \' f j: s! p3 n* G6 `# {1 ~
</P>* s" `$ V# \4 F9 |0 w) w
<P><FONT color=#ff0000>函数名: getmaxx </FONT>
- L. x+ x8 T3 f功 能: 返回屏幕的最大x坐标 5 {1 M/ F& ~* \' M, E3 V0 O
用 法: int far getmaxx(void); $ U8 U, k. `6 L; J6 ?
程序例: </P>2 n# a4 `. T$ F# o0 U
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ \7 q: R/ I) w5 Y, B* O#include <STDLIB.H>
' v. x' v" B& `4 n' j#include <STDIO.H>
6 i7 r1 v; D: I. T#include <CONIO.H></FONT></P>
" [ ?1 j# G3 b5 Z<P><FONT color=#0000ff>int main(void) : f/ r9 o, E3 I+ }" l: X! b
{
& c; i# k$ _9 a1 R# F6 m* }# n, p/* request auto detection */
. k3 |% Q7 Y; n" L% k0 `. Kint gdriver = DETECT, gmode, errorcode; " B) z' J% r: S
int midx, midy; + M8 D% S% R% x0 d2 P, G9 F
char xrange[80], yrange[80]; </FONT></P>- [. S- h4 u# ?* B% n7 K7 u& s
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; t3 X1 @8 h: f/ n! [1 M9 p: z6 oinitgraph(&gdriver, &gmode, ""); </FONT></P>( E6 w$ n3 ~) O9 I0 U" a
<P><FONT color=#0000ff>/* read result of initialization */
, i) c ~. z: x# x$ Berrorcode = graphresult(); 4 J( `7 Q; y$ a! B0 [. z. w
if (errorcode != grOk) /* an error occurred */ 3 t/ n: \" N+ F( f
{
0 s) |2 f$ ?. C5 H8 i+ gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 R) x0 }, W/ C. I, N
printf("Press any key to halt:");
0 P v& [( @' }8 L* z- jgetch();
. }: r0 K* v' Sexit(1); /* terminate with an error code */
. X: W9 D+ L8 h6 C$ {$ x! y} </FONT></P>
0 Y6 m- @5 d" M% z<P><FONT color=#0000ff>midx = getmaxx() / 2; ) |1 X$ y, V0 w* m8 u3 @, j: p `! A4 E
midy = getmaxy() / 2; </FONT></P>+ W0 v) F" f1 p' D* o* M# Q4 `% l
<P><FONT color=#0000ff>/* convert max resolution values into strings */
# f) P1 `1 I0 o( Zsprintf(xrange, "X values range from 0..%d", getmaxx());
8 y- u2 r% N* K) y5 `- `sprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>
! D# b& a) F p<P><FONT color=#0000ff>/* display the information */
- D* }- {9 |& O: u8 ^) e; x$ fsettextjustify(CENTER_TEXT, CENTER_TEXT);
7 l& E+ q9 ?9 Y! C$ mouttextxy(midx, midy, xrange); . t8 m5 O7 ] L5 c$ P5 |
outtextxy(midx, midy+textheight("W"), yrange); </FONT></P>
" G& d- W, N) m* h9 ]* x<P><FONT color=#0000ff>/* clean up */
- b3 {" z, a, ~2 W3 Dgetch();
# J3 Y; G: G: {6 a2 Zclosegraph();
# E: {! e9 R# W: Y. Qreturn 0;
* J( D9 @9 _6 w- G, i/ d1 V1 E5 e& e}</FONT> 7 g- V) T4 l G4 F( d
8 k& t* i& u( ^+ L4 f" |
</P>
) H1 L4 z7 A: _0 f8 U1 T9 g" o<P><FONT color=#ff0000>函数名: getmaxy </FONT>' s' e8 \& |/ X' _3 s7 n, e9 u5 l
功 能: 返回屏幕的最大y坐标
7 g F$ m( q6 b用 法: int far getmaxy(void); $ k5 X7 l9 m4 Y% o5 `' B+ A/ N
程序例: </P>+ J8 o1 I0 Q- S& R
<P><FONT color=#0000ff>#include <GRAPHICS.H>) }6 g- s* D# k9 `1 v8 @
#include <STDLIB.H>4 ^+ y, [* c0 C/ O$ b6 [7 @7 s
#include <STDIO.H> K9 j; R- z9 Y9 A
#include <CONIO.H></FONT></P>
/ c0 V2 D* Y; V7 i4 M2 Q<P><FONT color=#0000ff>int main(void) 3 Z" F. k) o+ W- p F
{
: l8 f6 a# \/ e/* request auto detection */ 4 N- O2 P+ w4 { {( B
int gdriver = DETECT, gmode, errorcode;
5 k5 d' }0 G) v4 p. i A; Jint midx, midy;
! k& e- o: H, g7 X: hchar xrange[80], yrange[80]; </FONT></P>
4 O9 I7 f6 S% a c. s<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 {) V2 j/ c6 e
initgraph(&gdriver, &gmode, ""); </FONT></P>
% {' Z' l4 i9 h! K, t$ x ?' O; d1 ?<P><FONT color=#0000ff>/* read result of initialization */
4 d% r- N5 P) {/ ]3 _+ nerrorcode = graphresult();
u$ f% g7 |% P; M, mif (errorcode != grOk) /* an error occurred */
- a! ~6 `6 C5 X# ?' R' G{ S6 r& y8 ^3 T/ ~
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( }+ ?0 J" n Y$ d1 [ h: W& a( n9 ~2 V
printf("Press any key to halt:");
4 P; _+ K/ F% a0 ^6 sgetch();
7 W) y3 F) ^& W8 G. E5 J/ G- j7 mexit(1); /* terminate with an error code */ # S2 O: C7 k- j, T6 ~
} </FONT></P>' h5 A9 S/ @, g( N8 E, h
<P><FONT color=#0000ff>midx = getmaxx() / 2;
0 J; I# S# ^/ X" hmidy = getmaxy() / 2; </FONT></P>
9 M* o) n9 S j# M# E9 x% ]3 F<P><FONT color=#0000ff>/* convert max resolution values into strings */ ' x! _/ b; L" v' h* t3 Z4 u
sprintf(xrange, "X values range from 0..%d", getmaxx());
b; {1 L* g2 w2 U: wsprintf(yrange, "Y values range from 0..%d", getmaxy()); </FONT></P>" q% v) f; b( _" J+ X( _
<P><FONT color=#0000ff>/* display the information */
' k* e/ z- X* Z/ ?% ^% r% \settextjustify(CENTER_TEXT, CENTER_TEXT);
) O2 M' f2 S5 i) r( D9 G; ^3 zouttextxy(midx, midy, xrange);
2 v+ `4 g3 B s! V6 Pouttextxy(midx, midy+textheight("W"), yrange); </FONT></P>, b; {1 e0 P8 w M* G+ e8 `
<P><FONT color=#0000ff>/* clean up */ ! H/ c6 O/ f( ]3 w3 V) L* h$ T
getch(); 6 |* K; d4 h4 @8 _0 V
closegraph();
6 }4 u% b6 u. Z! s5 C; J0 xreturn 0; + a& o" S8 [. P( o. O: R. u
} </FONT>
6 c- F" e9 z) d' A& c( H</P>. V2 E% T* x( C4 y, n( X9 p
<P><FONT color=#ff0000>函数名: getmodename </FONT>
/ |/ T* r8 v5 M! d8 u功 能: 返回含有指定图形模式名的字符串指针 0 B) _9 ^& T& ]/ ^ j5 V
用 法: char *far getmodename(int mode_name);
' d/ S- A- K8 H3 E程序例: </P>
* R* n+ [6 l# {# ]+ n \<P><FONT color=#0000ff>#include <GRAPHICS.H>5 i& `: x" Z( \" s3 e! I1 v
#include <STDLIB.H>/ c* Q5 g, v* h( Y
#include <STDIO.H>- V4 F0 U& V) c0 U( F; O
#include <CONIO.H></FONT></P>
3 n$ q1 u6 Z* \<P><FONT color=#0000ff>int main(void) 3 F6 l3 X! R; T8 x3 f
{ ; e' H0 z3 }8 J
/* request autodetection */
$ G' s" S' N6 Q0 N% d" @- \int gdriver = DETECT, gmode, errorcode; 4 [0 I6 ~0 `5 S2 s' F) B
int midx, midy, mode;
8 b' X$ O: ?; G! echar numname[80], modename[80]; </FONT></P>
" W2 ]8 g6 d# j' W( a- b<P><FONT color=#0000ff>/* initialize graphics and local variables */
! Z, U( e/ Y( D: P9 Finitgraph(&gdriver, &gmode, ""); </FONT></P>
! e( F6 C3 o8 j4 |. b7 o! z<P><FONT color=#0000ff>/* read result of initialization */
6 F- E, Z" l$ U3 P$ @' F: Zerrorcode = graphresult();
$ P7 R) ]4 q; `6 j7 }2 Y# U: }, Rif (errorcode != grOk) /* an error occurred */
: R% i8 y4 S3 ?2 |# M/ I{
6 u* [) X E, T! f6 v4 g5 Oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
# o& s5 U/ B( w% J. D! Rprintf("Press any key to halt:"); ! W# l" _. b7 X5 @1 n
getch(); 3 D1 \9 M+ M* U; o0 {2 o2 ~
exit(1); /* terminate with an error code */
4 [( m) i, M2 q} </FONT></P>' D( ~4 ?; u* l, m" t8 Z3 U
<P><FONT color=#0000ff>midx = getmaxx() / 2; - W% j" Q: N* R9 s; O
midy = getmaxy() / 2; </FONT></P>
6 a& D9 W- l# D0 v3 T, }<P><FONT color=#0000ff>/* get mode number and name strings */
% ~, a. D r }/ umode = getgraphmode();
7 x) k3 G( ]( g9 _sprintf(numname, "%d is the current mode number.", mode);
) r% Q+ `" l" c, L9 Wsprintf(modename, "%s is the current graphics mode.", getmodename(mode)); </FONT></P>: }1 f" e! |1 K6 F, ?3 ~9 e* ~
<P><FONT color=#0000ff>/* display the information */
/ G F: G1 M5 d3 ^) A" U3 P _$ Hsettextjustify(CENTER_TEXT, CENTER_TEXT); 1 G6 A0 C' x7 {* Z% i- A) N: R1 l e
outtextxy(midx, midy, numname); # }+ x& m# G6 W& J! `+ i+ @1 o
outtextxy(midx, midy+2*textheight("W"), modename); </FONT></P>7 S4 e( ]4 z: h# b- B3 k
<P><FONT color=#0000ff>/* clean up */
5 c& @: E( m9 u* {6 n4 g0 S- Ugetch();
3 @# x$ T( P7 q, M2 p6 `closegraph();
% q5 A( x. d# [. r7 D& c( Qreturn 0; 0 o8 ~* s1 r2 k1 d% W/ L
} </FONT>
9 v9 d5 q+ q0 Y o" Y7 x% Y% ]/ _- Z9 e% z1 M: Q( @) Y
</P>5 X V4 R w- H% T+ P2 b$ A
<P><FONT color=#ff0000>函数名: getmoderange</FONT>
( t; Z* M. F( T( R. v/ B功 能: 取给定图形驱动程序的模式范围 ; s( h/ Q" Y P
用 法: void far getmoderange(int graphdriver, int far *lomode,
6 f& q% O+ T) z) D1 F* n$ }$ @int far *himode); ) B8 I( D6 i( D6 `/ v7 Q; R
程序例: </P> V0 J Q' L5 E0 D
<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 v% O( Q6 m/ l: b! C$ M- p( h9 I( d#include <STDLIB.H>
& C4 n; I; h% L) @' e0 p2 J% U#include <STDIO.H>" P( c( p) g+ o) K( ?! A
#include <CONIO.H></FONT></P>9 X2 T" _+ h$ b# ?! y0 l c
<P><FONT color=#0000ff>int main(void) / q+ U9 w) N8 t( G7 s
{ # x8 [3 P% D0 m4 ~1 x
/* request auto detection */ a, U) k) O! \) C
int gdriver = DETECT, gmode, errorcode; 5 E9 h3 e$ g! T: D _1 ]: ~3 \
int midx, midy;
) q) r: @5 D- tint low, high; 9 [, u2 ?6 G4 e/ V; \3 D
char mrange[80]; </FONT></P>
, H6 o+ D5 u9 m, i<P><FONT color=#0000ff>/* initialize graphics and local variables */ % U5 \4 V" z, u* F& p4 }
initgraph(&gdriver, &gmode, ""); </FONT></P>$ S' s* T O' W2 {
<P><FONT color=#0000ff>/* read result of initialization */
2 T+ `( x7 J& G5 u2 o0 Xerrorcode = graphresult();
2 a3 L8 y9 W* [# h- r& W- T. yif (errorcode != grOk) /* an error occurred */
; S; f5 r4 H2 J{ 1 |( g- t% s: I& O
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' g9 K0 f5 x0 V" e7 I2 C
printf("Press any key to halt:"); 0 ~* f/ E; F; U& W. H6 O/ K
getch(); 0 h7 j5 C7 @/ D# |# {
exit(1); /* terminate with an error code */
0 e2 B. H9 j& s3 C& E6 y2 [5 y7 F} </FONT></P>6 [0 e* Z9 m g W- `
<P><FONT color=#0000ff>midx = getmaxx() / 2; ; F8 g1 M* J; L( w1 D
midy = getmaxy() / 2; </FONT></P>
& H" a7 {) l; H+ F/ h<P><FONT color=#0000ff>/* get the mode range for this driver */ ; E y. p! |' }) P0 g+ U
getmoderange(gdriver, &low, &high); </FONT></P>' w: r6 k. ?5 K: N7 Y! p
<P><FONT color=#0000ff>/* convert mode range info. into strings */
2 _- N- F q/ q4 ssprintf(mrange, "This driver supports modes %d..%d", low, high); </FONT></P>
+ O4 w# p7 _5 c. {3 j<P><FONT color=#0000ff>/* display the information */ 6 w x9 n/ F& n8 U4 U8 w
settextjustify(CENTER_TEXT, CENTER_TEXT);
, W0 E9 Y# d! y( x0 k) routtextxy(midx, midy, mrange); </FONT></P>" x* F# R6 H) N2 A+ j# m
<P><FONT color=#0000ff>/* clean up */
) h( ~- h+ J& n% e* J" s. \# V: `, Vgetch(); 0 B p, O+ i6 N q% N: v }
closegraph(); # [( P9 `; b \8 R8 e" p1 @
return 0; 8 |. E/ H. E! d4 u
} % J4 v/ S9 G$ ?7 K. Y5 j% Z8 [
</FONT>
! m* Q9 M! y6 v+ h4 I</P>( s) j6 J! l$ }6 O0 G
<P><FONT color=#ff0000>函数名: getpalette </FONT>' h! ^% p5 S' I: l1 K1 r% _4 Z
功 能: 返回有关当前调色板的信息
9 {2 Q7 C1 m( j6 ?% h用 法: void far getpalette(struct palettetype far *palette); 1 V- h- r4 U3 D- ~ P% C. Q
程序例: </P>% F6 c; ?5 G7 B- w$ `% D
<P><FONT color=#0000ff>#include <GRAPHICS.H>' E, {$ F+ Y3 G" d# z& f
#include <STDLIB.H>
0 t x5 ^$ O9 c/ V#include <STDIO.H>
$ u7 Y2 X# s' B& l! o#include <CONIO.H></FONT></P>- Y* p, S! E6 B2 M9 p$ M; `
<P><FONT color=#0000ff>int main(void) * a( Z2 g( H1 O* m$ Q. F: r+ D
{
5 B- {, K# e& L, g3 i* Q7 ~; g/* request auto detection */
6 ?7 k2 v; F& f$ g& L" j0 G: Dint gdriver = DETECT, gmode, errorcode; ! x. i" R/ }. O% J' s. N
struct palettetype pal; : G2 T: G' y5 a% a
char psize[80], pval[20]; / O* g, Y( L( C! o9 t
int i, ht;
3 h! O! O1 y, M s( `int y = 10; </FONT></P>3 @$ p+ }2 E7 m% S
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& K, X2 U4 F; k- f& W! O6 ]5 V6 o Z( Yinitgraph(&gdriver, &gmode, ""); </FONT></P>
% n, \( a m$ r7 B<P><FONT color=#0000ff>/* read result of initialization */ # h( r. t' x4 f* s
errorcode = graphresult(); " V; Q0 ?" S& _$ k7 l% |/ a1 H
/* an error occurred */ 9 q* q- Q% S/ W' m8 `- h! L* ]
if (errorcode != grOk)
9 ]6 Y2 Y" I& |2 L6 O3 \% S7 {{ / e1 N/ V: }' z* C! ^& L' w
printf("Graphics error: %s\n", 6 q H6 W2 _6 o: o5 Q3 h, }
grapherrormsg(errorcode)); 7 j# |) z" ~ c
printf("Press any key to halt:"); % M: N4 X3 c/ S1 T2 J
getch();
6 r$ A- }- e: M' ?+ b- u/* terminate with an error code */ / [9 P+ q8 ^: g0 ?- K
exit(1); & a" n% l7 N6 z: o
} </FONT></P>2 V5 e6 I6 U, }
<P><FONT color=#0000ff>/* grab a copy of the palette */ 8 b$ f2 v" z7 B9 w0 J+ J
getpalette(&pal); </FONT></P>/ {5 `: M/ o: ]. h7 m# r0 D
<P><FONT color=#0000ff>/* convert palette info. into strings */ 9 n/ z/ y: @5 Q" ]8 k' i/ h2 y
sprintf(psize, "The palette has %d \
3 a# W4 q9 c5 m, _! Q$ nmodifiable entries.", pal.size); </FONT></P>+ @# o- Y7 e0 b
<P><FONT color=#0000ff>/* display the information */ " {8 n1 b8 ~9 v3 d& W9 D" y3 m
outtextxy(0, y, psize); $ l0 _) ?3 _6 N' N, s0 `1 B
if (pal.size != 0)
. }: H0 a: J4 X* N4 D{ * j9 K# w( J3 S1 n
ht = textheight("W");
" m5 \# T1 S0 p6 n by += 2*ht; 9 H7 l. d4 C) m% J0 o
outtextxy(0, y, "Here are the current \
! V% e. {5 K4 t7 _/ M* t. bvalues:"); / A$ B9 M8 S/ x c
y += 2*ht; 1 d& X& S4 {$ K* U# q
for (i=0; i<PAL.SIZE; <br i++, y+="ht)"> {
2 e i$ N" c: I5 E/ {sprintf(pval, |& L4 y5 X# f( t Y% c( c, b
"palette[%02d]: 0x%02X", i,
0 A( x7 s6 V2 A$ Vpal.colors); . }9 x/ b* o) @0 a: K; b7 G- o$ Z
outtextxy(0, y, pval);
( R1 T7 Y9 T3 E; S" N7 n3 n) V2 \}
$ r7 C; q" w9 A' J% S K} </FONT></P>
2 _# u( b L- ]<P><FONT color=#0000ff>/* clean up */
5 f/ M! j& m# ~getch(); 5 S1 _0 X/ j4 w# J) V
closegraph(); </FONT>
+ k5 D& I& F1 E: d<FONT color=#0000ff>return 0;
5 U& O( Q+ [# W- e; Q} " A4 K) e8 M% J. b% N& }
</FONT></P>
8 \* { ?4 p% P, C9 O i<P><FONT color=#ff0000>函数名: getpass </FONT>
2 n6 ?4 ^* h. v/ p: I5 }功 能: 读一个口令 ! O; [3 C4 F; b0 @: t. j/ L% i, n
用 法: char *getpass(char *prompt);
; p% Z: h/ k- F% m4 z8 F程序例: </P>; g3 l! A: |+ @8 \# y
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
6 W0 o$ h+ N4 }1 Q; L<P><FONT color=#0000ff>int main(void) 2 y0 z, P( t# ] l
{
3 u$ f4 M# o- L( m7 u3 tchar *password; </FONT></P>
: M) u- k8 r9 v; b1 a! \<P><FONT color=#0000ff>password = getpass("Input a password:"); ( J% @) [! I9 n, @0 o+ \; r' P
cprintf("The password is: %s\r\n", 1 @& G; t$ D* a& H" h/ H& I
password);
+ v7 }$ e2 G* m, Ureturn 0; + Y& [* r" l. B( v' P
} 3 U# w4 S$ M' u; n7 x
</FONT>5 o: g2 J, m a3 V
/ O! F7 S0 H/ a$ i7 S
</P>2 Y: k, v* ?( Q5 v- Y! U8 r
<P><FONT color=#ff0000>函数名: getpixel </FONT>9 o/ m: r4 z! D! H [
功 能: 取得指定像素的颜色
- F7 U2 m* C2 o+ x4 ?: j用 法: int far getpixel(int x, int y); ( P2 P* @8 c3 {) _( R
程序例: </P>
. Q: n! |, Q1 A+ Y! _$ a# ~& R! U<P><FONT color=#0000ff>#include <GRAPHICS.H> p9 }1 |( S6 Q5 w/ q4 i
#include <STDLIB.H>0 l6 V( f9 j* ?8 U1 d& {: P9 S
#include <STDIO.H>$ l9 `: w) k. C/ T% a2 y
#include <CONIO.H># | `' @2 q+ S- s5 E8 s9 u4 ]6 `
#include <DOS.H></FONT></P>
, x* Y$ F0 @( z. a$ D% [8 z<P><FONT color=#0000ff>#define PIXEL_COUNT 1000 2 l+ o0 B" N2 I: L
#define DELAY_TIME 100 /* in milliseconds */ </FONT></P>
0 ?+ d5 Y/ }9 o( U1 I<P><FONT color=#0000ff>int main(void) ( W$ L! l0 H0 Y# `# K
{ ! Y/ O5 p- ~+ _$ @% |
/* request auto detection */
0 y5 n: m5 |) yint gdriver = DETECT, gmode, errorcode; ( Z( }) y1 X, T$ D4 _
int i, x, y, color, maxx, maxy, . u1 f3 c+ s: S" Y; l; d% {) W; n
maxcolor, seed; </FONT></P>
: z' Y0 R5 u4 b: q3 @<P><FONT color=#0000ff>/* initialize graphics and local variables */ , c! ?# b* | [. O! @4 q
initgraph(&gdriver, &gmode, ""); </FONT></P>
3 R7 L7 p8 |5 w3 p! e4 o3 O. E6 K( Q<P><FONT color=#0000ff>/* read result of initialization */
4 b' z( s( v6 ~1 Aerrorcode = graphresult(); 9 g( T2 a- W. _* F3 ]% K& Y/ `! j
/* an error occurred */
& c1 p: O, D+ o7 M) S$ zif (errorcode != grOk) 3 O [- a% V/ i6 w* n% k# t
{ $ O( `0 e. h+ C5 s9 B1 y! Q* l& r
printf("Graphics error: %s\n", . x/ l$ `4 \$ |$ T
grapherrormsg(errorcode)); : K/ k' d9 N9 ~* D; @1 B# ^8 l
printf("Press any key to halt:");
' ]/ o8 E+ f2 z' q! u( I' {getch();
& A8 s2 s# \' @# f$ ~1 F/* terminate with an error code */
1 x3 ?0 B) p6 R4 r' w Q2 F% X$ _exit(1); / B+ `- C F, Q* Q
} </FONT></P>
, Q; T: X2 E; ~& v<P><FONT color=#0000ff>maxx = getmaxx() + 1;
- k% t, ^1 a, P$ Z8 x& |0 V$ xmaxy = getmaxy() + 1;
+ t& [0 w) s7 M7 wmaxcolor = getmaxcolor() + 1; </FONT></P>) L/ J Q& i m! V" E6 y1 v% f
<P><FONT color=#0000ff>while (!kbhit())
$ r! `' f6 N! t- u{
9 Y* @0 f' |* C; A k/* seed the random number generator */ 9 W$ l/ ^5 {; x) ~) X
seed = random(32767);
9 |9 Z: }* P$ M8 Y/ l( hsrand(seed);
$ E1 s! \: a1 O' \5 X% q1 A t, Zfor (i=0; i<PIXEL_COUNT; <br i++)> { - G* S; A" Y! k4 H* t" Z6 u9 L
x = random(maxx); " @( G6 `8 I1 n# j3 U; K, h$ n
y = random(maxy); K9 L& N8 E9 D& t4 R
color = random(maxcolor); W: f+ M) [4 z+ _9 I; q2 {9 u
putpixel(x, y, color);
3 ?! ?* @2 l* E, t) V} </FONT></P>- `( D/ W1 ~, d! V( X
<P><FONT color=#0000ff>delay(DELAY_TIME);
! L6 A6 P# e% M% o4 @) U, ssrand(seed);
1 U' `( _- D$ [% O: F3 n9 rfor (i=0; i<PIXEL_COUNT; <br i++)> { $ Q& [) b2 z* I% Q. c0 [
x = random(maxx);
6 A; m% g6 G9 T9 X. [y = random(maxy);
1 T" `! |; x. N2 q: A- h9 Ncolor = random(maxcolor); ' h8 Q. y' y3 a5 a" n$ K. T
if (color == getpixel)</FONT> </P>. \3 f6 O6 H( Y% h& P; t
<P><FONT color=#ff0000>函数名: gets</FONT> % a5 j' c% `7 s2 ?; g" ]6 q
功 能: 从流中取一字符串
7 P, T b' A2 \: X' }' V8 x用 法: char *gets(char *string);
0 D" n) s- W$ o程序例: </P>
. h- b( A& w$ k( ~- P! p; X<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
6 I$ ~- f6 z1 B7 v<P><FONT color=#0000ff>int main(void) t, g( h- s& b' x: ?
{ - r6 W. G# I* }* H8 Y) A+ v* J- c
char string[80]; </FONT></P>; x+ ?6 l1 y8 q9 _6 H5 G" p
<P><FONT color=#0000ff>printf("Input a string:"); ; O) N Z# x$ O) J
gets(string); - R. @8 p' G0 ~: i- a; f) P& f5 t ~( |
printf("The string input was: %s\n", 4 i! @- `- e8 c T
string); # i A: C, N. U4 j
return 0; 2 ]+ W: E4 W4 @
} ]& J& g8 {) w' {- n8 k# O
1 r- a' T/ v2 Y</FONT></P>
7 C! j" _+ r# V' m3 x5 @<P><FONT color=#ff0000>函数名: gettext </FONT>
% m$ y5 p, Y% ]功 能: 将文本方式屏幕上的文本拷贝到存储区 3 j" W) y- ^: [
用 法: int gettext(int left, int top, int right, int bottom, void *destin);
0 S+ W: }; i5 ^; L程序例: </P>
- O; {7 E7 q: l) c1 u4 @/ Z4 @% H<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>0 a0 v4 c' ^' u, D; S: x& x
<P><FONT color=#0000ff>char buffer[4096]; </FONT></P>
! C; e1 w7 u* x$ U. x+ I! n6 \<P><FONT color=#0000ff>int main(void)
: Y0 u0 Q, L- w2 M$ n{
- m. }4 c. d& l8 Wint i; d! @/ x# ?- f! ~1 w8 P1 H
clrscr(); / v* G8 }* l' g& `7 f2 e% `/ c
for (i = 0; i <= 20; i++)
- |0 J/ e; s A! g3 V" N3 fcprintf("Line #%d\r\n", i);
. C% v6 B$ X o0 Vgettext(1, 1, 80, 25, buffer); # a D T- F1 l! I
gotoxy(1, 25);
$ Y, C6 B/ S8 A# P/ q$ `cprintf("Press any key to clear screen..."); * y5 s" u/ ]) r- d* ~" K
getch();
! o. G/ I5 V* O" ~clrscr(); 8 S+ ?. \; x& C$ W1 M+ B% c! c
gotoxy(1, 25); $ ~: r) r; P$ H9 q
cprintf("Press any key to restore screen..."); 6 Z% ^5 `; ?' V% [1 K, f
getch(); + f) ^5 }8 s8 H# | \
puttext(1, 1, 80, 25, buffer);
' u; ]' `! J& i& hgotoxy(1, 25);
: b% g# b2 X7 N& ]( ?+ t3 o* W7 Wcprintf("Press any key to quit...");
' J8 D+ }9 u: T+ `& v' \getch(); 4 R- N% D0 W' }" G& h1 w+ ~9 |& g
return 0;
2 K" t0 R8 K$ C+ C" {- Q3 X$ R$ t1 z} ; U" S' Z1 Z& [
</FONT>, V2 ?" x/ ^9 X8 u3 Y# `$ u4 ` Q
</P>
3 E+ G4 }4 d0 T( ~/ B1 ?8 _6 ~- p<P><FONT color=#ff0000>函数名: gettextinfo</FONT> - R1 r6 d+ Z. ^3 o7 B$ D; @+ U
功 能: 取得文本模式的显示信息
7 t1 X+ t& M7 {/ N! E3 N+ V用 法: void gettextinfo(struct text_info *inforec);
6 N9 {4 m2 M/ K: W5 m9 l, c0 _程序例: </P>; F5 l- e2 R( o% X+ T: T q
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
J1 ^! d: x* Z<P><FONT color=#0000ff>int main(void)
2 ~6 b8 x' m' u4 a1 s. W{ 3 Y( m0 t3 B( K+ L
struct text_info ti;
2 C) |# `5 B. A6 }: Mgettextinfo(&ti); # [; f# z( i e( B) i) W. L) ^
cprintf("window left %2d\r\n",ti.winleft); + ~. e) Z2 R* j' a0 e
cprintf("window top %2d\r\n",ti.wintop); . c6 u! A$ C8 q: a2 \
cprintf("window right %2d\r\n",ti.winright); $ T0 W( N- |' D% r
cprintf("window bottom %2d\r\n",ti.winbottom);
7 q% P6 _ K' u. b4 }* L$ |! [cprintf("attribute %2d\r\n",ti.attribute); 1 G0 {6 E2 j1 |1 M7 W- i0 L
cprintf("normal attribute %2d\r\n",ti.normattr);
" F3 T0 H( F3 L0 f" a" l* ucprintf("current mode %2d\r\n",ti.currmode);
& p* M* r* s+ D) F# S: P3 pcprintf("screen height %2d\r\n",ti.screenheight);
& m7 ^! Q8 [- Ccprintf("screen width %2d\r\n",ti.screenwidth); 0 Y1 V1 h, B( t- u' M: K' A' B1 K
cprintf("current x %2d\r\n",ti.curx); / R N' T, q4 C
cprintf("current y %2d\r\n",ti.cury); " @$ `) A0 H! j$ z5 d
return 0;
; H4 F! o3 u6 H' y9 s) o} 5 C$ M9 t, y# ^6 j2 M7 W
</FONT>7 t9 E6 } m- R$ t/ {/ ~
</P>, t1 s; ?1 ]1 d# G& m! g
<P><FONT color=#ff0000>函数名: gettextsettings </FONT>. P0 z2 a6 [& H3 I/ |: ?8 w
功 能: 返回有关当前图形文本字体的信息
4 {6 [& ]! @8 w用 法: void far gettextsettings(struct textsettingstype far *textinfo);
4 a/ S9 J& u& R) [程序例: </P>( n0 q2 F" |( h9 C; G
<P>#include <GRAPHICS.H><FONT color=#0000ff>
- j$ a* L* n/ g( M% t#include <STDLIB.H>5 M* P8 ~4 p; c4 B! g
#include <STDIO.H>2 E& l( Q, O" D1 A
#include <CONIO.H></FONT></P>- c- @+ A+ r6 Y" b) u0 E
<P><FONT color=#0000ff>/* the names of the fonts supported */
2 q' ~* p0 ]: Ychar *font[] = { "DEFAULT_FONT",
4 n* B0 b! M1 h+ g8 v, r' T"TRIPLEX_FONT",
% ~+ }# h/ P w+ p"SMALL_FONT",
; r) |: O5 Y( f- W. ~5 l"SANS_SERIF_FONT", 0 \. c& U/ y3 \/ K
"GOTHIC_FONT" / `9 O* e8 v. J ]+ U$ z: B* @
}; </FONT></P>
0 ]0 Z8 ]4 J3 S<P><FONT color=#0000ff>/* the names of the text directions supported */ - C- w) \- g& S3 |
char *dir[] = { "HORIZ_DIR", "VERT_DIR" }; </FONT></P>; A% [" h& f1 i C8 v7 i
<P><FONT color=#0000ff>/* horizontal text justifications supported */
7 Q/ @7 y! {) U$ y& x4 dchar *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" }; </FONT></P># j* w( Y7 L% {/ t9 Y
<P><FONT color=#0000ff>/* vertical text justifications supported */
- e, A/ E0 \: M, R0 @char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" }; </FONT></P>
- P8 O. m8 D& X, q' k; R3 g<P><FONT color=#0000ff>int main(void) 6 F m% @+ \' [& B
{ 1 ~' T1 K8 t8 o5 ]4 m
/* request auto detection */
3 Q" b( ~2 U/ O! t9 s- {int gdriver = DETECT, gmode, errorcode;
/ l2 O: q+ H" A- A6 Ystruct textsettingstype textinfo;
: c7 K( s, q: v( @$ S" F- n, H8 Z1 U4 _/ Tint midx, midy, ht; , M; D. P$ q6 W1 P3 ]$ J' D
char fontstr[80], dirstr[80], sizestr[80]; & `. r8 |0 q# C c" r1 ~9 p# ]
char hjuststr[80], vjuststr[80]; </FONT></P>
; v; ?: F( D4 d. Q: m* k<P><FONT color=#0000ff>/* initialize graphics and local variables */
. d; g: C! S1 t+ \; l. ^. kinitgraph(&gdriver, &gmode, ""); </FONT></P>8 b8 F8 V. \/ i4 V
<P><FONT color=#0000ff>/* read result of initialization */ * t( C5 G6 Y9 K ` }. W
errorcode = graphresult();
5 j9 O6 `9 |& c# T3 P: R) q. a, kif (errorcode != grOk) /* an error occurred */
2 _, g, j( ?, T- d6 g{
9 a+ }% f' p+ W( K, Zprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 G0 B* V3 ]8 m/ ?7 ]printf("Press any key to halt:");
% M# m- B# ?6 x Y1 j" A; `9 Igetch();
) F% m* w$ k2 Sexit(1); /* terminate with an error code */
; P4 G J7 ]5 U: r( ?} </FONT></P>1 G2 }2 {& O/ @
<P><FONT color=#0000ff>midx = getmaxx() / 2;
) T( {/ L9 h( F' xmidy = getmaxy() / 2; </FONT></P>
) r! E9 B4 Z: S+ e/ }: L G& Z<P><FONT color=#0000ff>/* get information about current text settings */ 5 }) ^( C% q4 K* m7 O- z5 ]
gettextsettings(&textinfo); </FONT></P>
0 Q* f V$ x4 q<P><FONT color=#0000ff>/* convert text information into strings */ , s7 h: q1 v& W0 [) h) ?! T
sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
+ a* z1 F' @5 r' a0 J$ F) z9 f& lsprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
4 N( D/ r+ O6 E) W* b% e5 hsprintf(sizestr, "%d is the text size.", textinfo.charsize); , i; l, m3 q) y4 `! n! L$ j" e
sprintf(hjuststr, "%s is the horizontal justification.", G! K: w& ~8 N- t" y3 M. E4 K
hjust[textinfo.horiz]);
- f2 P8 `! Z" E" Csprintf(vjuststr, "%s is the vertical justification.", : ^* M8 r2 _$ G; p9 Y
vjust[textinfo.vert]); </FONT></P>
) ?* U) ~* l& r# q<P><FONT color=#0000ff>/* display the information */
4 @0 F: e u, qht = textheight("W");
; r( O/ \7 \, @* |. Y; fsettextjustify(CENTER_TEXT, CENTER_TEXT);
N( N4 }) N' m; K8 o1 Pouttextxy(midx, midy, fontstr);
' y/ {) |% d: W; Couttextxy(midx, midy+2*ht, dirstr);
! }* B9 e; [- K& X a- |, Q+ Louttextxy(midx, midy+4*ht, sizestr);
9 }$ X% E# Q5 n) B/ ^* u( xouttextxy(midx, midy+6*ht, hjuststr); 6 O+ F! a) W8 o* {* w
outtextxy(midx, midy+8*ht, vjuststr); </FONT></P>
; }) K3 j5 t% ~/ y- K. K) d. Z<P><FONT color=#0000ff>/* clean up */ & B- ^) f9 D) I0 L- i% Z% Y4 Y) x' ]7 y! Q
getch();
, K/ ^, d: N) O8 ?( Wclosegraph(); 8 I5 A/ C3 H# u) x; f; n3 l+ b
return 0;
2 f. G: E: ~5 B4 \: B2 @} </FONT>: q5 d. D9 Y# a' E. y% K4 {
</P>
6 A: F" Q5 k! F, e, `+ s/ v<P><FONT color=#ff0000>函数名: gettime </FONT>+ ~6 @2 z% j& x1 f* y \* m
功 能: 取得系统时间
4 j2 [( _+ e1 U$ d3 ^$ X7 j用 法: void gettime(struct time *timep);
* g7 e2 _3 V% A( r0 v( [程序例: </P>
* }. h$ ?+ y+ {0 @# R<P><FONT color=#0000ff>#include <STDIO.H>
V2 S0 d# M g7 G$ l#include <DOS.H></FONT></P>
' ~: _3 ?6 \- A: K) H1 P! h<P><FONT color=#0000ff>int main(void) ! G" D0 K, X+ y( w4 M
{ 3 m" q. t7 L- {5 w2 v
struct time t; </FONT></P>
& ?. Z" A9 Y# h- G<P><FONT color=#0000ff>gettime(&t); 4 u) Y7 S( j" U+ A% O* v
printf("The current time is: %2d:%02d:%02d.%02d\n", 1 Z5 C7 k& r/ L% L6 S* N
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund); # ?+ k. j2 T0 q3 _
return 0; # @; R# j' @: F" H; y. H. p3 I( g
}
- F$ P+ d1 j, V& A! |/ H
4 m. e5 m& g1 [* ^ c. L</FONT>
! ?) N6 S0 v: s9 w* h</P>" t7 \" S/ T6 Y# W1 k& K/ |
<P><FONT color=#ff0000>函数名: getvect </FONT>
! J d+ }7 X" H; e) ^ q/ b) R功 能: 取得中断向量入口
# ?* {7 k5 \ ?) {0 L- @用 法: void interrupt(*getvect(int intr_num)); * u7 a% e2 y' \% J8 V" c; b
程序例: </P>
( a- [9 W, E2 n$ b<P><FONT color=#0000ff>#include <STDIO.H>3 i# j: H) i! d& W* q2 k; X: h( U
#include <DOS.H></FONT></P>) x3 W, t# `! D; R/ C
<P><FONT color=#0000ff>void interrupt get_out(); /* interrupt prototype */ </FONT></P>
* O7 A, m; q H# Q2 x3 D<P><FONT color=#0000ff>void interrupt (*oldfunc)(); /* interrupt function pointer */
$ }; V3 M2 U# Xint looping = 1; </FONT></P>4 w& I9 n8 Q ^. j
<P><FONT color=#0000ff>int main(void) % V0 D# R9 Y9 r; S3 S. p5 a8 i7 c
{ " T' Z5 D( f/ s) i
puts("Press <SHIFT><PRT Sc>to terminate"); </FONT></P>
" S4 F/ G( s: F6 E2 g W<P><FONT color=#0000ff>/* save the old interrupt */
* H8 z8 W! u' w% Uoldfunc = getvect(5); </FONT></P>
' \4 @9 }/ J7 S1 s1 l4 a<P><FONT color=#0000ff>/* install interrupt handler */ 2 V7 k1 J: x9 f1 w& G* Q
setvect(5,get_out); </FONT></P>
6 q5 Y9 E; W! | a+ u7 r/ a X<P><FONT color=#0000ff>/* do nothing */
- ~3 D0 D# ~+ J, b9 r3 _while (looping); </FONT></P>
; I6 e( b- O! y' Y' J! Z8 Z<P><FONT color=#0000ff>/* restore to original interrupt routine */ 9 m! n" L. W, j @
setvect(5,oldfunc); </FONT></P>
3 p, A g! p' }# K<P><FONT color=#0000ff>puts("Success"); # x2 k0 F' @( @6 s# v6 u* a, r
return 0; 7 n0 R9 H' R6 ]. h: O- M1 f( |
} - S3 `: Q; t% T' p+ I [0 l3 M
void interrupt get_out()
- k/ }9 V- q8 I- a: [$ @{ ' C0 X4 P5 I! O7 d1 }
looping = 0; /* change global variable to get out of loop */
# p7 s" z- [# G, C/ H3 ~( }! g}
0 g; O( u2 f2 t6 a0 A' E</FONT>
) g8 U0 S$ m% d# I9 ~</P>
# E+ O" L9 V. s3 N+ B<P><FONT color=#ff0000>函数名: getverify </FONT>( K8 @- r, t. n% L, c
功 能: 返回DOS校验标志状态
; {7 N6 a, `0 J" c8 P用 法: int getverify(void); ' D. A8 V. c( v& }$ y# X' N; d
程序例: </P>7 G9 L; ?; R5 B Y0 d; w
<P><FONT color=#0000ff>#include <STDIO.H>( k- W3 N$ L. H
#include <DOS.H></FONT></P>9 O8 P8 ~% o# e: |5 k
<P><FONT color=#0000ff>int main(void)
" G) h7 @$ s: o& B{
/ R* \6 C& Y5 g: L+ ?( ]if (getverify()) 2 E3 e/ {# E& s. K) e6 Y
printf("DOS verify flag is on\n");
& \+ u" r0 q$ V( f. x \else
" D- K5 \* B( l+ x. o! [( z# a" uprintf("DOS verify flag is off\n");
" q( S' h# M" ]# }# ~$ c* Ureturn 0;
8 Z5 z+ |* E" c3 | G( W} 5 G$ q+ l- K" K1 K+ a* l7 C
</FONT></P>* } N( B5 g7 n' i0 T9 u, O
<P><FONT color=#ff0000>函数名: getviewsetting </FONT>
: Y/ \, S% y! V( K" {/ m v: V8 @$ F功 能: 返回有关当前视区的信息 4 A! W |+ @: Z
用 法: void far getviewsettings(struct viewporttype far *viewport);
0 E8 S4 t( ~1 h" i" `/ z }) ]程序例: </P>
. R! [" ~2 M6 b* D8 R5 R<P><FONT color=#0000ff>#include <GRAPHICS.H>6 G0 Q1 }' w* ^2 `1 |5 y5 X; U
#include <STDLIB.H>
5 t) B# Y5 i# L# V5 K4 C7 v#include <STDIO.H>, I9 t) p3 {8 _3 d6 ~
#include <CONIO.H></FONT></P>
, N7 V9 ?5 N) x8 X X% x7 V<P><FONT color=#0000ff>char *clip[] = { "OFF", "ON" }; </FONT></P>0 K% o/ f$ C) W7 a5 K# |) k+ }( {
<P><FONT color=#0000ff>int main(void) / R: A. _7 }# ]( n
{ ' d. k" X1 _! n- T3 A
/* request auto detection */
% T2 L `. S- I, c1 tint gdriver = DETECT, gmode, errorcode;
: _' d! y5 |3 k8 n! x4 Y& f3 k+ [# Xstruct viewporttype viewinfo; - ?8 _+ u6 l& l. f' V' ^0 ^* \
int midx, midy, ht;
6 F& f7 ^6 l( I2 z: [char topstr[80], botstr[80], clipstr[80]; </FONT></P>% d( J* [( M) K# }3 M7 Y
<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 F0 p1 _; [* a. [9 winitgraph(&gdriver, &gmode, ""); </FONT></P>
1 O3 h0 w+ V( [" p' O H( Y) i. j2 F<P><FONT color=#0000ff>/* read result of initialization */
( ?6 _: X l- B! k# c% Eerrorcode = graphresult(); ; k/ g. G h. d1 K/ W U
if (errorcode != grOk) /* an error occurred */
9 o. M. U! J$ V( m/ s{
# H) x: T' A sprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 T- u' K* D" ]9 o7 Gprintf("Press any key to halt:"); ! I$ W! u% ^& H7 J# d
getch(); , h @$ W. X+ B8 u; L# q( m
exit(1); /* terminate with an error code */ ( o/ u8 {! c' r' `* ~
} </FONT></P>
1 _- B8 C3 x! M<P><FONT color=#0000ff>midx = getmaxx() / 2; " J, u7 ]) b9 c0 h8 ^
midy = getmaxy() / 2; </FONT></P>
, Z; g1 F8 ]& Q9 R8 o<P><FONT color=#0000ff>/* get information about current viewport */
* U. t6 U+ t, Y6 dgetviewsettings(&viewinfo); </FONT></P>
8 r9 M I) {. |0 F' U<P><FONT color=#0000ff>/* convert text information into strings */ # Q% U% S3 N# f* g5 Q5 ~+ D+ p
sprintf(topstr, "(%d, %d) is the upper left viewport corner.", / ?6 j% V" @2 l: Y
viewinfo.left, viewinfo.top); ~" p% u# b6 W" o* L+ _9 u
sprintf(botstr, "(%d, %d) is the lower right viewport corner.", 8 }9 a3 {( D+ Z- Y* K" V
viewinfo.right, viewinfo.bottom); - q: g( u( y% i2 U! g7 R' p* k+ a7 J
sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]); </FONT></P>) K' o/ Y4 @% M2 V( D) A9 U
<P><FONT color=#0000ff>/* display the information */ 4 S9 u. M, Y% C- s
settextjustify(CENTER_TEXT, CENTER_TEXT); 9 I) s: V% a" d- W9 `" w! X
ht = textheight("W"); * w/ y8 Z- ^2 Q! n9 e9 l
outtextxy(midx, midy, topstr);
: |9 E0 p$ O& F: n3 ]/ r& couttextxy(midx, midy+2*ht, botstr); Z' {1 a+ }* y
outtextxy(midx, midy+4*ht, clipstr); </FONT></P>
: F' o2 d. @7 Y$ K/ T: t<P><FONT color=#0000ff>/* clean up */ * |; @; _- T4 E* Y
getch();
' q% M8 Q. j- T4 u0 Rclosegraph();
+ K, n/ N7 `+ b2 i* N8 y" Nreturn 0;
/ f8 I( o' U& i M} </FONT>8 `6 v( F8 G3 l
3 W! D" r9 k ^2 U- h2 r( G
</P>
% y' D* J; X; S" L<P><FONT color=#ff0000>函数名: getw </FONT>
' {, r( N* l% B, H功 能: 从流中取一整数 ; B% x4 v" |& S: y" C
用 法: int getw(FILE *strem); " a, [) J! C+ j r; E
程序例: </P>1 x. g+ T$ K _. Y; w- p
<P><FONT color=#0000ff>#include <STDIO.H>7 S2 \5 p: o1 K& ~
#include <STDLIB.H></FONT></P>
+ p/ W V: H5 I$ K, v, Q: q* L<P><FONT color=#0000ff>#define FNAME "test.$$$" </FONT></P>
$ z$ o1 q" t3 ^9 c<P><FONT color=#0000ff>int main(void)
- P6 h4 {# |% ~1 e; }{
0 Q/ _5 w. V& o0 X" vFILE *fp; 8 ?* ]/ D6 Q, _0 e! r
int word; </FONT></P>9 g' h0 J$ r5 E
<P><FONT color=#0000ff>/* place the word in a file */
% J1 C0 s/ `) A* i: J% O5 [fp = fopen(FNAME, "wb");
% Z2 K% W9 p- F$ h3 \8 ]if (fp == NULL) ( h# l2 K3 {- l5 S1 U5 w& U
{ & N1 a& H* u; E' W
printf("Error opening file %s\n", FNAME);
2 q% J+ D8 x' d* n0 Texit(1);
2 _( ~& q' _ ^- K} </FONT></P>
x5 I6 A9 @6 o<P><FONT color=#0000ff>word = 94;
' y. X. {4 P" U2 r: v: f3 aputw(word,fp);
- i8 X% B, k5 [2 W+ u0 pif (ferror(fp)) $ l1 T! D( u3 M4 B
printf("Error writing to file\n"); : O" J2 p, Y% f
else + F; h! u8 q0 C/ U$ v
printf("Successful write\n");
9 P( i+ z; \/ q8 d& ^4 ]0 c { afclose(fp); </FONT></P>! _# `5 k E4 C7 s5 x$ z5 j
<P><FONT color=#0000ff>/* reopen the file */ ' T- ^ B% G4 W2 P
fp = fopen(FNAME, "rb");
$ q' M, `( v% j+ a9 Aif (fp == NULL) : d2 ~5 `, e# y* h8 `( y
{
7 r7 t7 q j v: U( vprintf("Error opening file %s\n", FNAME); 6 w0 y$ U4 j* x5 o# }/ y
exit(1); & j$ ]; i5 s/ A
} </FONT></P>: p& c9 S& m" F2 O" J, v! [: @7 E
<P><FONT color=#0000ff>/* extract the word */
3 q2 T# s7 O+ Y1 w2 v8 fword = getw(fp); / i8 o" s" m0 A! ?& z
if (ferror(fp)) ' z2 G3 o2 q3 Y" L3 Y1 M
printf("Error reading file\n");
. Q) R/ _/ M) }# welse 0 i5 r2 U- m0 j; N
printf("Successful read: word = %d\n", word); </FONT></P>( E$ F! T3 F& i5 F8 W1 [, O7 L
<P><FONT color=#0000ff>/* clean up */ . P4 G8 t9 h3 T" {0 N) c- w
fclose(fp); & E6 V2 S" A7 c1 T& P# h, ?
unlink(FNAME); </FONT></P>" }, N s. n+ H3 ^, C2 \
<P><FONT color=#0000ff>return 0; 6 G: D; b: n$ R7 W3 ~: L3 e$ G
} </FONT>
8 r2 }# j& M) t) ^* B
- j1 z7 k: B. j$ ?8 `/ F0 v8 X8 n
1 C6 l% Q2 ~# t</P>' H5 l4 |8 {& J
<P><FONT color=#ff0000>函数名: getx </FONT>3 Z1 Y8 R2 r7 P% ~% z5 E
功 能: 返回当前图形位置的x坐标
* K$ j& u6 u8 P. m+ P8 c用 法: int far getx(void);
% p5 A9 ?) M+ ~程序例: </P>0 c8 l) |# _4 C' u9 q3 F
<P>#include <GRAPHICS.H><FONT color=#0000ff>
; V% o$ V2 h5 p \( j5 C6 g#include <STDLIB.H>0 I* B6 N8 v" ]+ P! o. i
#include <STDIO.H>. h4 H. H, }/ W1 v4 E( b N
#include <CONIO.H></FONT></P>" N8 z6 H$ \, v2 L% |* e# s7 L& t
<P><FONT color=#0000ff>int main(void)
7 S2 E' Z2 L( g* P{ 6 @7 o7 |* ]8 m% [1 F+ U
/* request auto detection */ % C+ I( w# l' m" l
int gdriver = DETECT, gmode, errorcode; 1 K1 Z# h% |: N2 K
char msg[80]; </FONT></P>
! ]1 [- |! ~( s" t3 O<P><FONT color=#0000ff>/* initialize graphics and local variables */
* s5 F7 T1 n8 t5 w8 P' W1 @" ginitgraph(&gdriver, &gmode, ""); </FONT></P>
7 Y" r- F; \. F& r% [) e0 K* y<P><FONT color=#0000ff>/* read result of initialization */ 5 E" h+ h6 @+ {
errorcode = graphresult();
0 U* d! ~, d. ?& I' i8 Q5 H/ Bif (errorcode != grOk) /* an error occurred */
) i2 i- s0 y! m; ?* q) C: E+ i{ 5 S7 C9 [$ j) y* y. q W4 q
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 g! ]+ F2 ^0 Z9 f9 M
printf("Press any key to halt:"); ) l. p# n6 v1 {- z3 U/ b+ {. |
getch(); ! @3 S3 h+ \" \
exit(1); /* terminate with an error code */
3 y% ?2 ?+ ~$ w! S& u- ^; r} </FONT></P>! T! h A5 Y9 o( u( n% Q9 k
<P><FONT color=#0000ff>/* move to the screen center point */ 0 b7 O) t6 I4 P3 w
moveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>2 l' r) _2 n+ P1 t/ K; I$ s
<P><FONT color=#0000ff>/* create a message string */ " e" R9 m. X9 p: I3 K% e' K: }
sprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>( |& o; k2 V- ~- |
<P><FONT color=#0000ff>/* display the message */ ( i4 t3 T7 ~3 H
outtext(msg); </FONT></P># I z1 V" M+ M5 |! C8 e
<P><FONT color=#0000ff>/* clean up */
3 F8 o/ p) j9 ogetch();
1 c# ]' ]9 j. F' z! vclosegraph(); # A# }1 [' d: u1 d2 s9 D+ T
return 0; 6 R$ k. Z( M) o* s* C
} </FONT>
+ A( N# M! p, y5 \: {
7 O+ W6 t7 F/ G4 H</P>( A: F: f# {5 B8 g) G* K
<P><FONT color=#ff0000>函数名: gety </FONT>
) {7 P! Y& }6 ]1 r8 O0 d) c: A功 能: 返回当前图形位置的y坐标
; p4 c8 A& F6 s9 y用 法: int far gety(void);
y( A/ N& [# m+ `程序例: </P>' B8 e$ n, z5 X) {/ A. i' G
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; u! ?9 E: p$ l( P#include <STDLIB.H>* K( w. y7 ^+ n; G. G
#include <STDIO.H>
/ l" S7 B1 p: [2 C#include <CONIO.H></FONT></P>
' X; P$ J% C" U% \; S& H<P><FONT color=#0000ff>int main(void) 3 b) U; ` \: D
{
; G+ G8 \$ `; u/* request auto detection */ # F% }0 C2 U: z; K: Q+ `7 V
int gdriver = DETECT, gmode, errorcode; & o0 C) o6 L% @# m: ]6 H
char msg[80]; </FONT></P>
. t3 K& s, m" f+ X8 v& }# Q% f<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! m$ W) V! f% @! J) ?
initgraph(&gdriver, &gmode, ""); </FONT></P>" f7 E2 C& }) {( Q# e Q
<P><FONT color=#0000ff>/* read result of initialization */ ^# \" K/ Y* s" r2 {
errorcode = graphresult();
+ Q# ?2 O6 R d" v" }4 vif (errorcode != grOk) /* an error occurred */ $ O o; l! [4 r" I0 Q' C' i
{ ! e* x; m5 _# H8 [
printf("Graphics error: %s\n", grapherrormsg(errorcode));
, f+ ~6 |8 }5 d+ wprintf("Press any key to halt:"); . r* u# \4 D( W$ j
getch();
- t4 S6 F+ g" W/ T% y" |exit(1); /* terminate with an error code */
/ u) I$ N1 m% L) c t} </FONT></P>
# _; E* L3 X& U<P><FONT color=#0000ff>/* move to the screen center point */
" m# o8 e6 o4 a9 P: dmoveto(getmaxx() / 2, getmaxy() / 2); </FONT></P>/ J4 S. E. c) {6 t6 Y
<P><FONT color=#0000ff>/* create a message string */
9 D/ D% b: O2 i8 R& Asprintf(msg, "<-(%d, %d) is the here.", getx(), gety()); </FONT></P>
2 _5 \0 z, y3 N9 G<P><FONT color=#0000ff>/* display the message */ / J+ z7 _3 \ V1 M o% p* S
outtext(msg); </FONT></P>7 j& E1 o$ x; e( s0 o. a
<P><FONT color=#0000ff>/* clean up */ 5 ~$ n, _. \2 L3 f, e- _
getch(); 6 S) z8 e) T3 _. _2 W
closegraph();
v0 D$ u) X+ C, N Mreturn 0; 4 f; ?( S a; Z6 N
} </FONT>
) U* m" ~6 E& r% v# E/ _* l8 ]8 W d4 O
</P>5 b! K# v$ b) q6 ]7 @
<P><FONT color=#ff0000>函数名: gmtime </FONT>
8 i. K3 i& d2 o8 y- J s功 能: 把日期和时间转换为格林尼治标准时间(GMT)
; j# |8 h& U) ?, A6 u2 ?用 法: struct tm *gmtime(long *clock); ; @0 [" c% A6 J8 P9 e$ L0 p8 ]
程序例: </P>
0 w4 u. c# n' }8 X! ^<P>#include <STDIO.H><FONT color=#0000ff>
& h' T: t7 z# d#include <STDLIB.H>
8 _$ v D$ o$ d `#include <TIME.H>
7 j, K0 r9 J2 |5 ?#include <DOS.H></FONT></P>
. S8 ^) H- u8 {) {6 A<P><FONT color=#0000ff>/* Pacific Standard Time & Daylight Savings */ 4 }% f. G* U: [& Q
char *tzstr = "TZ=PST8PDT"; </FONT></P>
& e! c3 N9 ^+ C+ N* V( {<P><FONT color=#0000ff>int main(void) 7 K8 O3 y, g% r0 _" z/ v# X$ i
{ ! `6 g, @% Y! [$ I" Q) Z w
time_t t;
/ E( o, o9 g& |* J7 t2 Estruct tm *gmt, *area; </FONT></P>/ ?; h2 a& B% J
<P><FONT color=#0000ff>putenv(tzstr);
4 m, ^6 r2 X$ V9 w& ?7 \9 Wtzset(); </FONT></P>: |8 I N3 D N/ n( }
<P><FONT color=#0000ff>t = time(NULL);
5 f, p3 {; w9 u& w+ n8 ]0 S* m$ garea = localtime(&t);
) l+ o$ y0 ^$ r; a* [printf("Local time is: %s", asctime(area));
% l: \2 }7 {4 _" Y' ]gmt = gmtime(&t);
z% B, K% T( v! D2 v& y8 Xprintf("GMT is: %s", asctime(gmt)); * W( g& W5 s) V# \+ V( m, Q
return 0;
6 [ [# G h" |/ Y7 j} </FONT>
H$ u# q, C; `1 ?
2 d p* i" K# R: K! j</P>/ Q# l8 h' H% e8 _! \+ X
<P><FONT color=#ff0000>函数名: gotoxy </FONT># J4 u- {1 M/ W3 q; K
功 能: 在文本窗口中设置光标 : y( m) ]5 X d+ `# d8 v2 X6 S k" v
用 法: void gotoxy(int x, int y); / L7 X2 c! j8 E$ L4 d; o6 b9 S' E
程序例: </P>9 m+ D+ G- b- R! f3 Q( N
<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>. M J# B1 l2 J# r2 b: ?# u' W
<P><FONT color=#0000ff>int main(void)
' v* \5 ~5 z% z: v) d{ & z2 d9 S9 V0 F5 b J: t
clrscr();
. A: `' t* {' {4 b |& G+ m: Ngotoxy(35, 12); / R; h2 C& y4 S* F$ b
cprintf("Hello world"); / `9 e3 K) w; [, m, c- J
getch(); - D6 W5 P% I) z& ]1 K5 ?
return 0; 8 ~0 u# n5 q' n6 o- ^3 h
}</FONT>
3 C0 S# F- X X; v0 H3 }
0 O( J% S& v. N1 j</P>6 K. t1 Y0 z' _% F% C) P( |9 S
<P><FONT color=#ff0000>函数名: gotoxy </FONT>. y+ w! G3 X. e* S
功 能: 在文本窗口中设置光标 * o) c' o4 A4 v Z* Q
用 法: void gotoxy(int x, int y); 9 g% F9 K8 J6 ]" L$ p1 m
程序例: </P>
0 Y4 X7 h( W5 A- [, m, K) n<P><FONT color=#0000ff>#include <CONIO.H></FONT></P>
! W+ P7 y1 `# l! T+ H6 ?: R<P><FONT color=#0000ff>int main(void)
; n7 e8 |$ e% b* O6 {{
- N; m% e- s/ H/ ?clrscr(); 8 ^; z/ R$ V F) d5 E
gotoxy(35, 12); 5 f }1 R+ C4 R7 H
cprintf("Hello world");
' s5 y. w; G1 j6 ?getch();
) x) o) ^6 ^9 nreturn 0;
' G- [) j: l7 a}
8 l4 ]7 y2 l; m- q</FONT>
( P$ M: `- g# z7 E8 X</P>
: V- U# _" u- R( E+ b2 l<P><FONT color=#ff0000>函数名: graphdefaults </FONT>+ l ^" L2 N c" a
功 能: 将所有图形设置复位为它们的缺省值
1 i( F9 O) P) R# e6 T6 w7 Z用 法: void far graphdefaults(void);
/ A" `5 ]+ Q4 B/ o: v程序例: </P>) H8 p( K1 }+ Y7 W
<P><FONT color=#0000ff>#include <GRAPHICS.H>
. [* j2 M' `6 K, _% x1 X) b2 _: l8 y4 ?#include <STDLIB.H># S4 f' @: p \# [$ ] ]" _
#include <STDIO.H>
9 a Q! J1 ?6 R0 [* ~5 U#include <CONIO.H></FONT></P>
9 ]8 t$ z+ ~/ I3 b0 v- L<P><FONT color=#0000ff>int main(void) % F; k5 w3 z- O; G. R
{ 6 ]) n4 x0 Y! i
/* request auto detection */
& Z" }, B+ ?$ |$ [7 Jint gdriver = DETECT, gmode, errorcode; 6 i* d0 `* K& W o* s
int maxx, maxy; </FONT></P>8 O9 D+ y& @+ q$ v1 Y i) K6 I
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 F% m+ V) o# B4 W; u% }2 G- Yinitgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi"); </FONT></P>
$ q6 T/ e! v' f) L1 i& v* e<P><FONT color=#0000ff>/* read result of initialization */ * @' r# `" I7 y/ U) U4 u% ^% d
errorcode = graphresult(); 7 i+ w% y; c+ H. }/ ]
if (errorcode != grOk) /* an error occurred */
0 s3 H1 w2 K" y F* ?{
) w0 X2 L$ G4 \ y0 Nprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ( r1 e! F, W9 Y+ Y( A% j, X
printf("Press any key to halt:"); / N+ \ }, R& I. |5 V' I6 ~9 Z
getch();
' R5 {* b1 _- f8 ^exit(1); /* terminate with an error code */
5 e; H8 c# d$ R1 R8 h' ^7 L} </FONT></P>4 e3 z# O N' |( R: |; x3 h
<P><FONT color=#0000ff>maxx = getmaxx();
' h8 T: E0 |( Wmaxy = getmaxy(); </FONT></P>0 x1 O/ `3 s( E% M
<P><FONT color=#0000ff>/* output line with non-default settings */ 3 a6 H: Z: U h1 k8 Y9 t% ~
setlinestyle(DOTTED_LINE, 0, 3);
& Q8 I) B0 r j3 U. ]2 [8 S7 x$ Lline(0, 0, maxx, maxy); ' _6 k! t: I- H7 h6 R
outtextxy(maxx/2, maxy/3, "Before default values are restored."); 1 K" s% {' Q* G3 J1 P' t/ M
getch(); </FONT></P>/ a( b& F, E/ M, Q" ^5 z9 y
<P><FONT color=#0000ff>/* restore default values for everything */ , f. v% J: |+ b. G# O n$ J/ v
graphdefaults(); </FONT></P>8 k$ m' q# Y4 d a# g
<P><FONT color=#0000ff>/* clear the screen */
& j3 x* F- J4 y( Rcleardevice(); </FONT></P>
+ u l% ?/ N; O" w- g% d8 x: [<P><FONT color=#0000ff>/* output line with default settings */ 9 J+ _/ U4 ]. W* R8 T
line(0, 0, maxx, maxy);
, K1 A9 v N7 L- {outtextxy(maxx/2, maxy/3, "After restoring default values."); </FONT></P>
/ m1 P' o+ G& s<P><FONT color=#0000ff>/* clean up */ + N7 g6 {! j) X5 {9 x, ]/ ?5 Q
getch();
! x# E. ^2 A, C, {8 u( O5 Mclosegraph();
]3 A1 Y' r7 R$ n& b" j! ?return 0;
4 A8 f* q* @- v7 U. F} 9 B& P/ |0 K* J" A. T# O c7 L
</FONT>/ J B1 v9 P" R7 ?7 S, R
</P>
/ |) M& |" k# y6 V<P><FONT color=#ff0000>函数名: grapherrormsg </FONT>9 K9 s3 d6 r/ @
功 能: 返回一个错误信息串的指针 Z5 |8 S, y! A! L1 l
用 法: char *far grapherrormsg(int errorcode); ; g& c1 [4 w/ B/ A+ |, g
程序例: </P>
9 h# ~, @3 @1 X+ \<P><FONT color=#0000ff>#include <GRAPHICS.H>4 y3 m' b5 y4 q N
#include <STDLIB.H>
1 k( P0 R( G$ \% ~#include <STDIO.H>
. I) D. v& {/ X& D9 U; ]#include <CONIO.H></FONT></P>
4 ]7 }% y4 t9 Q' `- t9 z<P><FONT color=#0000ff>#define NONSENSE -50 </FONT></P>9 K. Z) G# C* T& |( k! k
<P><FONT color=#0000ff>int main(void) . y% { v2 W2 B, B6 t
{
* w0 j0 c% N# B/ M: o# J$ @/* FORCE AN ERROR TO OCCUR */
4 `9 C0 d( F8 [+ d' j8 B' }int gdriver = NONSENSE, gmode, errorcode; </FONT></P>
! G: d* k' o# J9 j<P><FONT color=#0000ff>/* initialize graphics mode */
# ]7 d6 O r' U2 w( N+ _5 a+ G; Uinitgraph(&gdriver, &gmode, ""); </FONT></P>
) U7 G& ~/ d+ x& a% F+ A c! n<P><FONT color=#0000ff>/* read result of initialization */
- Q- O4 o1 F$ herrorcode = graphresult(); </FONT></P>
6 x6 I h9 C1 N# e- y/ `7 _2 n( h<P><FONT color=#0000ff>/* if an error occurred, then output a */
2 |# O" t6 x9 m/* descriptive error message. */ 2 c, c$ U8 S9 `6 h$ X( ]
if (errorcode != grOk)
+ k: f' a F" ^% y{
! f z* X, C$ J, {& q* w+ cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 Z- E3 A7 C1 w$ i) E; R% q: e
printf("Press any key to halt:");
`' q7 a% W/ }. B7 e q9 mgetch(); . [+ I' L" q2 `
exit(1); /* terminate with an error code */ 2 z; X# S5 Y+ D) r
} </FONT></P>
: b$ N; n4 E8 [/ D<P><FONT color=#0000ff>/* draw a line */
3 U1 F; l' E( j5 gline(0, 0, getmaxx(), getmaxy()); </FONT></P>1 c% |# Y4 h) y' `
<P><FONT color=#0000ff>/* clean up */
, w B" z/ n& w# B- j. F# _getch();
" O5 b5 D) i3 T" U4 M$ R# J8 e0 Aclosegraph(); # v5 F2 u, o1 Q+ S( s" f$ M. c
return 0;
; B8 e D. Q& u3 E" o! r} 5 J+ D6 b* Z" a L$ w
</FONT>
1 E4 ]- F8 N( M3 `</P>. s- X8 ]' B; G: E) }- c5 \
<P><FONT color=#ff0000>函数名: graphresult </FONT>
4 i( r* j2 K! W; \' O6 a功 能: 返回最后一次不成功的图形操作的错误代码 ; {% U$ Q+ v8 o7 Q R
用 法: int far graphresult(void); o! h* r! g0 u4 p5 J
程序例: </P>
6 S& [$ Z. E& ]% h# L<P><FONT color=#0000ff>#include <GRAPHICS.H>( K3 {+ y) ?+ v- M/ p# _6 I2 d
#include <STDLIB.H>
' L7 h! B" O# \& |5 M6 o! i% S# D#include <STDIO.H>
) d, L; E$ q3 H#include <CONIO.H></FONT></P>
: {2 o' ?4 q, W( k. J6 ~6 O<P><FONT color=#0000ff>int main(void) . f. O F; O7 H6 t
{
6 i. G" k, P4 g: f1 K. A/* request auto detection */
3 {: v" ?+ {1 Bint gdriver = DETECT, gmode, errorcode; </FONT></P>8 n8 `: W+ ?' g' L; }7 N
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 B; j2 t- b7 P# M l( y% Y
initgraph(&gdriver, &gmode, ""); </FONT></P>
$ _) w* B1 f/ u<P><FONT color=#0000ff>/* read result of initialization */ - N0 i' u) F1 _ F% W
errorcode = graphresult(); </FONT></P>7 u3 y2 F# K' }; ^
<P><FONT color=#0000ff>if (errorcode != grOk) /* an error occurred */
5 J. T) q) W" E+ I- e{
) @6 C9 G' R) E+ Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' `! {5 V4 D& Z* Hprintf("Press any key to halt:");
% t' m3 D3 H5 b+ h& L5 d6 q6 T2 kgetch();
% w# x+ h& y6 v" _/ U& V4 s" o+ x6 Cexit(1); /* terminate with an error code */
$ X7 ?0 S$ T) \. C6 Q} </FONT></P>
+ l8 A a/ o r& o9 r* P<P><FONT color=#0000ff>/* draw a line */ 5 [. D0 x4 m3 m+ R1 E6 z) ~" i
line(0, 0, getmaxx(), getmaxy()); </FONT></P># u) y% j$ \& K% {. `/ G. s e1 [
<P><FONT color=#0000ff>/* clean up */ 6 D, L6 u# M$ i4 U7 B$ I) v, v
getch(); * v$ B0 S, k7 |- _6 m! o
closegraph();
" H4 M1 K3 L: i @1 jreturn 0; & Q5 i" y( w% I8 a0 E
}</FONT>
' H. A8 L) t1 M* x! Q</P>
+ V/ Z3 w6 d1 N8 H& G. b- Q<P><FONT color=#ff0000>函数名: _graphfreemem</FONT> $ x8 U9 G, E$ \, [; U
功 能: 用户可修改的图形存储区释放函数 & g; l! _$ x! B2 w1 }7 c8 P* }% {
用 法: void far _graphfreemem(void far *ptr, unsigned size);
. f% P( O' `+ l) r程序例: </P>6 f% a' [$ l# J$ j$ `
<P><FONT color=#0000ff>#include <GRAPHICS.H>
- N$ @& R" F- L/ u S#include <STDLIB.H> N! M8 ?4 A) n ]5 ]
#include <STDIO.H>2 l9 H% U/ `& F" y
#include <CONIO.H>
9 @ v; `9 T; j6 ^6 c#include <ALLOC.H></FONT></P>
. K) e) F2 H) Y& K, y: M<P><FONT color=#0000ff>int main(void)
0 g, t2 Y# c$ U{ 2 P1 N3 I& |7 b- ?
/* request auto detection */ : t) {; U; R$ {' }" N9 N7 d5 y5 O4 f
int gdriver = DETECT, gmode, errorcode;
' W7 I7 r8 A; A7 |" K- g' A1 Y' \int midx, midy; </FONT></P>2 I& U& _8 H# W) w& W; f/ g6 D( u
<P><FONT color=#0000ff>/* clear the text screen */
" ~$ D5 Y3 ~" }) Q0 @% pclrscr();
+ y; `6 ]" q- X5 p4 P& \9 a( t$ Gprintf("Press any key to initialize graphics mode:");
+ r) M9 I. j2 v+ p- d* r+ Q0 pgetch(); " _4 m$ y) {# B$ V( c' c2 G$ ^
clrscr(); </FONT></P>
4 G+ F5 {& }# Z% E2 R<P><FONT color=#0000ff>/* initialize graphics and local variables */ # ?/ W% Q0 `+ M8 b
initgraph(&gdriver, &gmode, ""); </FONT></P>
7 L$ z& Y1 I" r4 U8 \# H<P><FONT color=#0000ff>/* read result of initialization */
8 D' s% |7 m2 ~0 cerrorcode = graphresult();
3 h, \' i( v1 R- k2 {$ L! O5 _, Hif (errorcode != grOk) /* an error occurred */
o/ S: v9 B& N6 k& j# k& u3 w{ 8 V3 [; F; Z' p
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) f) H- }2 w4 V
printf("Press any key to halt:"); . J% x `+ ?: P8 u/ W7 X
getch(); $ }* p! n5 ~" k& i
exit(1); /* terminate with an error code */ * H$ p' ~4 k7 V: V# J& j& d
} </FONT></P>& p; B9 N9 E8 k' E" d5 ?
<P><FONT color=#0000ff>midx = getmaxx() / 2; " F9 M, Z& J8 z! F+ g
midy = getmaxy() / 2; </FONT></P> T; v: T' Q2 k5 u2 m$ e6 z+ t
<P><FONT color=#0000ff>/* display a message */
/ g- {. ~9 F, _# Z) Q# @settextjustify(CENTER_TEXT, CENTER_TEXT);
& e2 U ~9 O- ~! x- }0 ?( |* touttextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>
; u2 ?6 {- W- V2 K5 N( f4 X<P><FONT color=#0000ff>/* clean up */
) T: @: }0 Q! h. @4 tgetch(); 0 n$ G( Q' @; U. O: r' _
closegraph(); 3 R& V8 ~ N2 D" s
return 0;
$ K+ j8 V$ S5 l7 P8 o4 s3 g1 s$ | |9 s} </FONT></P>
! t* ]0 a7 Z: h<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
- b/ @, T- X1 E& d3 u; D$ J+ Q4 v( F1 Zvoid far * far _graphgetmem(unsigned size) ( |, f9 a/ y$ y* t# S
{
U. ]; ~8 Y# `4 Yprintf("_graphgetmem called to allocate %d bytes.\n", size);
. ~. o8 t! ^( ~% F) rprintf("hit any key:");
) |1 h5 p4 y {9 Wgetch();
8 M5 Z- W4 |" \/ Aprintf("\n"); </FONT></P>
: J/ {( J7 o! w; s. G* W$ `* T<P><FONT color=#0000ff>/* allocate memory from far heap */ & {- z' A6 |9 S% @ [9 _# s1 o
return farmalloc(size);
/ V. l1 c# S, b$ {/ ^} </FONT></P>
5 a& V4 a; R1 \- t1 H% n2 [<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */
. g( U+ P% q2 j r& bvoid far _graphfreemem(void far *ptr, unsigned size) 3 \6 |+ }/ [5 K* m
{
+ u( z. M0 b5 t: ]' d2 ~2 p; f: Gprintf("_graphfreemem called to free %d bytes.\n", size);
. Q* D2 {0 B" \% k, M+ yprintf("hit any key:"); * E8 h- l& R9 L/ O! a4 ~
getch();
- o+ k: G+ g5 @8 [: o9 D3 {printf("\n"); </FONT></P>2 B1 J; w$ d$ N
<P><FONT color=#0000ff>/* free ptr from far heap */ ) e8 c7 ~+ U$ B6 d3 o g6 S7 {
farfree(ptr); 8 S( O, l* R4 f2 X: g8 g! n
}
9 B/ N7 a+ m- ?' r* y: |</FONT></P>
& G5 t ~: p t! g9 z) y1 n- v- Z<P><FONT color=#ff0000>函数名: _graphgetmem </FONT>
' {; ?, {4 |6 x& @: d+ s5 A功 能: 用户可修改的图形存储区分配函数
O' w% n# k0 V+ Z; h2 w3 l用 法: void far *far _graphgetmem(unsigned size); ( s" P9 m. Z5 m% e9 Z1 ~
程序例: </P>
0 I+ Q# r# s1 A! S<P><FONT color=#0000ff>#include <GRAPHICS.H>
* Y$ Q/ Q$ ?. ^5 c; S. s( i#include <STDLIB.H>
) t$ c/ g w. U( q8 ?4 ^#include <STDIO.H>% g% E' T* j/ C: V9 N6 L7 z
#include <CONIO.H>: d: i$ [$ \' e7 a
#include <ALLOC.H></FONT></P>
6 B5 H9 e0 U9 G* h- H h<P><FONT color=#0000ff>int main(void) ! j: J) K# U W( u& Q/ `
{
+ d: N6 f, A( o9 _" U9 u/* request autodetection */ 6 f) ^, G! {3 f' Q# H* W* Q% }; C
int gdriver = DETECT, gmode, errorcode; 0 T7 Z# \ N8 g- ]3 s) R+ A
int midx, midy; </FONT></P>
% [2 x2 S4 G5 N" H/ U' Q: q( ~+ b<P><FONT color=#0000ff>/* clear the text screen */
9 n: |. z1 B3 t. y, w; vclrscr();
' r7 |7 m( N' v! Bprintf("Press any key to initialize graphics mode:"); ! b1 Q+ J& [6 k
getch(); / ]+ `6 a" ~$ L4 Z* s
clrscr(); </FONT></P>
( G5 r/ ^5 M3 ^+ E0 W% \6 ^! P<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 s% C; d1 m, M/ o
initgraph(&gdriver, &gmode, ""); </FONT></P>0 ~5 L7 w( l4 L3 D8 @6 |
<P><FONT color=#0000ff>/* read result of initialization */ : [* J3 o5 b) l; {9 J$ M* T# m
errorcode = graphresult(); ) s' j# C4 Q1 l
if (errorcode != grOk) /* an error occurred */
& n, Q6 g+ k! r6 w4 j+ y8 }3 z{
, j Y! [4 B% W0 ]% Oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 H" Q3 p8 _$ ], A4 L
printf("Press any key to halt:"); 8 \% Z! e8 \5 l
getch(); 1 Q" f& S0 M6 W8 @ V7 `
exit(1); /* terminate with an error code */ * O w) S/ |7 E/ A: R9 ~, ~
} </FONT></P>8 s- [' B( [1 s! n4 e, S
<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 M' H$ D) Q- b+ x; ]0 @2 m }
midy = getmaxy() / 2; </FONT></P>- n. P" }: G* f' C
<P><FONT color=#0000ff>/* display a message */
1 h$ P6 B" {. r* G D- osettextjustify(CENTER_TEXT, CENTER_TEXT); % S- \) l; k3 k: z: O
outtextxy(midx, midy, "Press any key to exit graphics mode:"); </FONT></P>: i6 G* O0 {( I4 B8 q, I4 e
<P><FONT color=#0000ff>/* clean up */
4 \. q4 Z4 e# T8 R& j9 egetch();
! @# ]7 f; @# Uclosegraph();
+ p3 j9 T6 Y9 @return 0;
5 P# s6 L+ a1 \: o W% h} </FONT></P>
- q& v/ H. f0 N<P><FONT color=#0000ff>/* called by the graphics kernel to allocate memory */
1 Y6 e8 s1 \1 k; u0 wvoid far * far _graphgetmem(unsigned size)
4 j' p B( I' x# F7 O9 n{
9 `! h' P0 u9 g. y+ t4 f7 Oprintf("_graphgetmem called to allocate %d bytes.\n", size);
+ j# h' L& \/ G5 X# Z5 T" kprintf("hit any key:"); 2 y# |, r9 G4 x
getch();
~! K" W. n) }" Fprintf("\n"); </FONT></P>
' a/ @% v7 |* L. d7 S1 I<P><FONT color=#0000ff>/* allocate memory from far heap */ - b0 }+ b0 v% L" i. ]% r
return farmalloc(size);
$ D7 v) C- b- p* F$ |; ^} </FONT></P>9 T2 _5 l* X) a* U, o7 ~
<P><FONT color=#0000ff>/* called by the graphics kernel to free memory */ ) b8 b6 |3 n' s8 `
void far _graphfreemem(void far *ptr, unsigned size)
/ [: y" v0 Z1 O' F/ s( z- j{
, k V" Y4 J/ H. V2 m/ sprintf("_graphfreemem called to free %d bytes.\n", size);
! v2 W- Y& E( C! M A0 W% Bprintf("hit any key:");
7 N7 w" h) x$ Mgetch(); # F* @! t1 Y. @3 @
printf("\n"); </FONT></P>2 M7 [$ Q9 a. e5 \/ S2 B4 ~
<P><FONT color=#0000ff>/* free ptr from far heap */ 5 Y& A0 s, L$ d* d2 J; t
farfree(ptr); 2 A$ I" ?8 H5 m
}
# G; p8 \- a3 L7 C. d1 ^; [1 u$ S; `</FONT></P> |
zan
|