QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2961|回复: 0
打印 上一主题 下一主题

函数大全(s开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>
9 ~8 g% J. Q$ ]  ^. v6 ?9 U' J功 能: 改变数据段空间位置
1 u- I; I/ Z. A. o1 y用 法: char *sbrk(int incr); % E4 f- I- k& T8 P) D. f: u
程序例: </P>
" l# C, A6 D& G2 U2 q<><FONT color=#0000ff>#include <STDIO.H>* x2 z/ w7 c( q0 j2 }, Y
#include <ALLOC.H></FONT></P>+ m+ P8 y  G) x/ Q
<><FONT color=#0000ff>int main(void)
  ^: r& q2 j2 j( E3 P# L7 p{
. K8 t$ z# L! `, a: Sprintf("Changing allocation with sbrk()\n");
, [6 r4 b7 B( j/ b! o  u/ |printf("Before sbrk() call: %lu bytes free\n",
( E7 `7 w, ]( E0 [, x# V4 p2 @(unsigned long) coreleft()); . _7 H( w. F5 U5 Z' @5 R- |  e
sbrk(1000);
; \% N6 F# I( f" Hprintf(" After sbrk() call: %lu bytes free\n", . [) Z, I  B! U: A0 G
(unsigned long) coreleft()); ; U! a6 l! {7 p& M% j. c% x
return 0;
) h6 S' q* `9 ]) }% t7 Q) O3 W* J}
7 F. }* y( L5 K: [+ I3 Z' V% e
9 z6 @2 C" c( P; J" @! u</FONT></P>+ x5 k; A: U  N& m$ Y1 d
<><FONT color=#ff0000>函数名: scanf </FONT>  X4 Z4 B0 `) B; J' h( x1 M! v
功 能: 执行格式化输入   e, x; U$ z2 r# g
用 法: int scanf(char *format[,argument,...]);
  E' A4 I, L" [' C/ Z8 W* _& E程序例: </P>
5 P4 v4 @  U( K# c0 s0 @  s<><FONT color=#0000ff>#include <STDIO.H>
& U" T% l' h( l* K$ U2 Q#include <CONIO.H></FONT></P>- n* c' ^3 S9 z. G. w, Y
<><FONT color=#0000ff>int main(void) $ D& c4 f* M, d6 B
{ 2 X. W. Z9 L! Y. V) r
char label[20];
9 @8 |* |& W  V4 B" q5 pchar name[20];
, ?! l* g, m% a- Aint entries = 0;
/ ]6 o& _) |4 b6 r* L9 gint loop, age;
; y9 H% h% [% [# vdouble salary; </FONT></P>7 [2 F. }: M9 d% X+ i- y
<><FONT color=#0000ff>struct Entry_struct 5 c$ Y+ P# R6 q& r9 _/ p
{
/ K" L- }3 `8 q; |- d- ychar name[20];
2 V/ A* H% ^! e( ~  k5 Rint age;   x: I2 r' `) X0 q+ a; F( s
float salary;
* D& P# z: Y, s) l/ E} entry[20]; </FONT></P>
3 T: Q2 J$ A( E! w<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
. f1 X; i! v0 Q/ u) bprintf("\n\nPlease enter a label for the chart: "); 2 a2 N( R% B0 s. B, P* I9 m8 D
scanf("%20s", label);
% w* y# c- J0 L1 afflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>5 g+ v$ w. X) |5 j/ y1 \: ~# l
<><FONT color=#0000ff>/* Input number of entries as an integer */ ) p5 ]7 e4 l0 A5 L6 O
printf("How many entries will there be? (less than 20) ");
5 g3 x0 O) h1 e, a: Wscanf("%d", &amp;entries);
( U1 E4 \* _' b% }! y/ j. tfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>$ z( j) k' w+ g8 x+ N
<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
- @! d) b) y& Z  o7 c# [0 |for (loop=0;loop<ENTRIES;++LOOP) & c7 j( D8 E) j' T
{
- m. c, B  W; A+ A# @  G) ^printf("Entry %d\n", loop); 9 _% A& `, q6 K/ Q
printf(" Name : "); 3 i; ~5 s) l! i
scanf("%[A-Za-z]", entry[loop].name);
% A3 X. d) V, I1 ^0 C4 r) bfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>+ `, s# O/ R9 D9 d7 d' {
<><FONT color=#0000ff>/* input an age as an integer */
& K& p6 B' m/ h5 cprintf(" Age : ");
1 U  j% ?+ F2 g9 K& H& u$ gscanf("%d", &amp;entry[loop].age);
0 e* |. r9 k* b2 a) Ffflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>2 k, N$ B+ R: ~
<><FONT color=#0000ff>/* input a salary as a float */
8 |9 i2 O, M. A& E: yprintf(" Salary : "); 5 h* L+ |8 Q3 |3 n) S! E% z
scanf("%f", &amp;entry[loop].salary); ( v1 l2 C- b- K7 J" Y
fflush(stdin); /* flush the input stream in case of bad input */
$ Z( X( M* O( m% z; p3 K  d} </FONT></P>9 N9 _" `/ w5 n2 C! A
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ , H9 C* @. a, E  J& C" o7 @
printf("\nPlease enter your name, age and salary\n"); ' }) m) B: a3 Y4 u/ [
scanf("%20s %d %lf", name, &amp;age, &amp;salary); 5 N$ v7 t, h2 w/ |# s
</FONT></P>
2 }/ S+ G3 S& R+ o: i<><FONT color=#0000ff>/* Print out the data that was input */ , u0 o, }! p8 E/ C" k* g# h# @& A, v
printf("\n\nTable %s\n",label); 8 Z8 P$ p! E. x
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); ! \8 S7 j0 D  l+ r* {
printf("-----------------------------------------------------\n");
1 S& N( X3 _: I: U+ t5 ]& pfor (loop=0;loop<ENTRIES;++LOOP)
  d$ [1 e/ E$ |/ s* B printf("%4d | %-20s | %5d | %15.2lf\n", 0 ^4 o% I3 p0 @( w1 c! M
loop + 1, 5 a5 J3 }' N) o, l5 N* c+ t
entry[loop].name, # H  O7 G* C' C& Z
entry[loop].age, 9 k6 w9 V2 i4 X0 u' S
entry[loop].salary); ) _* x* D4 s1 p+ B( Z
printf("-----------------------------------------------------\n");
2 Y$ _8 _3 g6 z7 N& v, H4 ^return 0; + M# [4 y# H  Q6 I4 W: H* ~
}
! H, y0 X2 T9 H" E</FONT>1 @% I8 H% y& ^' q' F. n. _0 W. g
</P>
* [$ [( K: O; u$ C<><FONT color=#ff0000>函数名: searchpath </FONT>8 o4 V" X2 e: |- Q9 X* I
功 能: 搜索DOS路径 9 O7 |; h& I% r( u8 A- n! W$ J6 `
用 法: char *searchpath(char *filename);
9 S4 U1 `/ u  U/ L9 X! b程序例: </P>
% C" q* i! T, i. n- M/ k<><FONT color=#0000ff>#include <STDIO.H>  z7 [4 H0 F/ z% n; m! R* r
#include <DIR.H></FONT></P>
# `& s8 _- f( `' O" l<><FONT color=#0000ff>int main(void) ) x# ^1 R: y& }) U, ]: |9 f
{ / d- ]# E! w; u1 W( q
char *p; </FONT></P>  }+ c" y0 s8 q$ s  ~0 E6 W
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer . E9 M! v: t& g' d+ u( \
to the path */ 0 i) d, o" U# R: c- Q
p = searchpath("TLINK.EXE");
3 Q5 M3 g  o* {! Iprintf("Search for TLINK.EXE : %s\n", p); </FONT></P># s4 ], g, x8 c% {2 q
<><FONT color=#0000ff>/* Looks for non-existent file */
. }, F' a* f0 L: H  }% N; q( sp = searchpath("NOTEXIST.FIL"); 9 l, T. _2 q% M) z) ]
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>3 W% O( ^0 m, g+ d6 E( L1 R
<><FONT color=#0000ff>return 0; : q( x1 P! `* P# [( L0 x$ B/ X. k6 W
}
* X3 I# ]5 }  M% w1 Y( n# |: `0 T  k" n" j
</FONT></P>
# h8 G- s8 X3 p& \<><FONT color=#ff0000>函数名: sector </FONT>
- t# t' l# b% B" l7 y5 U0 i/ t' p功 能: 画并填充椭圆扇区 $ ~6 B, {0 n2 e- a
用 法: void far sector(int x, int y, int stangle, int endangle);
2 I% x2 H4 Y. Y, c9 `' V程序例: </P>
# N, g) J2 |6 ]0 s7 W" `+ e<><FONT color=#0000ff>#include <GRAPHICS.H>' k; Y, F# I: t! P9 f; ~! o
#include <STDLIB.H>
# b$ g/ q# j( {# x$ w#include <STDIO.H>
: G& ]3 S2 X( v- }$ p#include <CONIO.H></FONT></P>  q+ u5 d) Y, ^: Y
<><FONT color=#0000ff>int main(void)
; ~8 G1 W3 W: z: k/ D8 d4 ^{
2 }3 d% o& e: S7 \9 n+ r/ z/* request auto detection */ : a% v& Z9 x% N% k8 l
int gdriver = DETECT, gmode, errorcode;
4 m2 J% g# {7 ~! Qint midx, midy, i; # O. `$ s3 \2 U/ N# I0 x
int stangle = 45, endangle = 135; / v# [- P4 \4 _
int xrad = 100, yrad = 50; </FONT></P>$ E+ Y, }: Z% q+ R8 B0 a
<><FONT color=#0000ff>/* initialize graphics and local variables */
, T8 R% m$ J8 Q- J8 Winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- B: b# F8 ~/ e1 y# X' j+ l) u2 [% m
<><FONT color=#0000ff>/* read result of initialization */ , j$ `0 e" _% ~" W, ^  _3 A' S
errorcode = graphresult();
" P, w: n1 |1 L) S6 R, N5 Jif (errorcode != grOk) /* an error occurred */ 5 j* z" S8 q' z: Q
{
4 V) J6 l# @' Q" i  C& lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' T5 r' v! g4 T
printf("ress any key to halt:"); 9 i# V$ F9 |8 S2 p: I
getch();
. u: E- ?  e5 w2 Sexit(1); /* terminate with an error code */ ( W7 U0 H7 [! |3 X  |4 @0 z
} </FONT></P>4 y: U$ q/ a  k- E0 Z% b9 `4 H6 E
<><FONT color=#0000ff>midx = getmaxx() / 2;
+ H+ |( E7 V& N, v" Imidy = getmaxy() / 2; </FONT></P>0 {) T* x1 C2 c! R
<><FONT color=#0000ff>/* loop through the fill patterns */
" o6 y9 S/ ]8 i: x8 }1 D6 t7 c" Lfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
9 d+ z' q7 D3 o0 _" p" ?/* set the fill style */
) X- Y9 C# s0 p* o8 h" w/ d# d$ G, ~1 l% [setfillstyle(i, getmaxcolor()); </FONT></P>: {: T6 G3 ~" U9 ^" F7 B& G+ R
<><FONT color=#0000ff>/* draw the sector slice */ * h! h7 a: F& m& z' x1 X
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>  w' d- v$ S3 B9 `- c9 h
<><FONT color=#0000ff>getch(); * _: n7 x7 s" }  V' Q; X
} </FONT></P>
1 c2 Q: y7 N2 {+ E# y<P><FONT color=#0000ff>/* clean up */
( o, E4 Z% j0 E! }0 m  Uclosegraph();
5 h4 t/ i7 D- U! q. K. vreturn 0;
8 J! m9 J0 w( v, V* O}
, k/ |$ i/ x$ s  v  w$ K: R</FONT></P>+ z2 N, b* m9 [3 O  ]* D6 g
<P><FONT color=#ff0000>函数名: segread </FONT># q! ?9 o4 \" h' L3 d/ u
功 能: 读段寄存器值
8 E# d6 ?  }7 q3 F% z- }2 i: V用 法: void segread(struct SREGS *segtbl); 2 I' ?5 Y4 ]8 p) L8 q: w
程序例: </P>
2 y4 h, E+ `* C2 j, W<P><FONT color=#0000ff>#include <STDIO.H>
% W9 i6 d1 r5 ^9 w- n#include <DOS.H></FONT></P>4 t; G+ f* o. \% S! ?
<P><FONT color=#0000ff>int main(void) 7 u0 d0 W5 Q( C) B0 t4 x! l
{ $ h5 i+ \% r/ \( p* F
struct SREGS segs; </FONT></P>& ~% i: Q/ q4 w! F' g  e
<P><FONT color=#0000ff>segread(&amp;segs); , _; n* U5 M! G7 Y1 b3 i
printf("Current segment register settings\n\n");
3 S5 ]/ f0 i# wprintf("CS: %X DS: %X\n", segs.cs, segs.ds);
7 z( D1 X+ L( B4 iprintf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
' Y- L, X1 q+ s" Z- [7 E<P><FONT color=#0000ff>return 0;
- B5 w) w9 Z4 W- M1 r7 P) {% ]} </FONT>" \% T8 H# t, r2 S& Q
/ u* P! m8 |+ T( r# @$ W/ K$ ^
</P>
# ?+ ?6 R9 ?  S9 ], B. }' U# ?7 V<P><FONT color=#ff0000>函数名: setactivepage </FONT>& d- l; d) m) F/ V; O
功 能: 设置图形输出活动页
+ O2 G* ?6 u: A; ~2 g用 法: void far setactivepage(int pagenum);
" s6 a; {- K' N: c程序例: </P>
2 d3 A, H( p0 u4 S  S6 W<P><FONT color=#0000ff>#include <GRAPHICS.H>- \4 s: q$ z2 K6 r) z' `4 R: x) v
#include <STDLIB.H>
9 t- f6 o" t% E1 W#include <STDIO.H>
3 s$ S7 A0 g- |/ ?) L#include <CONIO.H></FONT></P>
8 A& z' i8 P0 q0 e! f. `! C$ I- z<P><FONT color=#0000ff>int main(void)
7 H8 N- g) Q, v( {5 B9 H{
) }+ q0 ?* B) v5 V. V% _" B7 h/* select a driver and mode that supports */
) ]1 V, m- S( k1 U5 ~/* multiple pages. */
! |- N8 |+ s# s3 p# aint gdriver = EGA, gmode = EGAHI, errorcode; 0 b) C7 i! s" P0 z. k  Y
int x, y, ht; </FONT></P>
! y: T& Y& y4 y5 x<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 V4 i" `' D: V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) k' y1 B6 Y* N8 B9 K! f<P><FONT color=#0000ff>/* read result of initialization */ 2 p# p  f. U' t9 f: _2 ]0 ?/ R
errorcode = graphresult(); * M% m( U8 u) h  _8 k+ T/ g
if (errorcode != grOk) /* an error occurred */ " \' ^$ E4 z% P/ Z! y% V7 G
{ 6 O* C( J- b: c$ o' w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / Q, x/ e# ]# z
printf("Press any key to halt:"); ; k0 q. ]  ~$ H) q* h
getch(); 1 U1 j9 [3 m- H0 ]9 b# X# G8 j
exit(1); /* terminate with an error code */
0 N7 ^7 P3 k2 a8 \} </FONT></P>
4 L! a) W5 Z% n% x2 P% c2 [' ^<P><FONT color=#0000ff>x = getmaxx() / 2; 9 Y6 g  o4 Q2 Q2 g3 H: B- {
y = getmaxy() / 2;   w3 E. f% X4 |5 `+ a3 g0 x
ht = textheight("W"); </FONT></P>
1 M1 I+ t/ N2 O- n) m3 ]<P><FONT color=#0000ff>/* select the off screen page for drawing */
, v( \/ @. ~; P  M, \setactivepage(1); </FONT></P>* P0 A# O9 `. u9 u/ _" ^$ j
<P><FONT color=#0000ff>/* draw a line on page #1 */ ( g; F4 s& a# q5 j3 H( S
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
4 R6 X  r% E6 |- l3 ^6 b/ L<P><FONT color=#0000ff>/* output a message on page #1 */ . r/ P. ]! L6 U# Z" T8 T
settextjustify(CENTER_TEXT, CENTER_TEXT);
& B  I: ^) ]+ M; o( x; o, Fouttextxy(x, y, "This is page #1:"); 5 ?2 p6 r0 T0 I+ t, x* L( {
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>3 d4 w( W: {( n5 N* A/ D
<P><FONT color=#0000ff>/* select drawing to page #0 */ 6 a- @8 [  a. \- Q& P8 z" y
setactivepage(0); </FONT></P>$ G3 I' X# H: C3 z5 n
<P><FONT color=#0000ff>/* output a message on page #0 */ 8 I% A' o! ]7 o0 p
outtextxy(x, y, "This is page #0.");
! N0 A) d2 B# `* touttextxy(x, y+ht, "Press any key to view page #1:"); 0 A" V8 ^7 u5 V
getch(); </FONT></P>. v% }6 f* \! U' k2 [
<P><FONT color=#0000ff>/* select page #1 as the visible page */
& d; e  \  |: u3 U& ~$ N3 wsetvisualpage(1); </FONT></P># d0 H. p' ~7 i$ l
<P><FONT color=#0000ff>/* clean up */
% I4 S( ?2 v: [getch(); : x  {7 G. I$ c4 `9 z2 S) I) u
closegraph();
/ ]7 d  I3 x* I/ Q+ v+ p; rreturn 0; % x. I$ p; f+ a
} , G" H) n& t1 g8 c( p2 W$ G+ r
</FONT>
8 a/ k, _4 g# H. `" }</P>* l( h* R. ^3 a4 C, u
<P><FONT color=#ff0000>函数名: setallpallette </FONT>9 D$ t# ]$ Z" B7 i( f+ X" n
功 能: 按指定方式改变所有的调色板颜色
: I  ^; t. m7 e1 d3 Q2 G用 法: void far setallpallette(struct palette, far *pallette);
) s$ H, h! D2 h2 u$ G程序例: </P>9 ~, A: T) i- f9 D
<P><FONT color=#0000ff>#include <GRAPHICS.H>( ~  W, _3 g! F) K! Z6 t
#include <STDLIB.H>
- A$ N  y3 h1 L/ u' f; b$ R#include <STDIO.H>
, q' }8 V, s3 @5 F: G5 r#include <CONIO.H></FONT></P>) e+ G3 J+ ~* F( _
<P><FONT color=#0000ff>int main(void) 0 B+ |1 x% }! V! Z
{
5 N2 C5 e$ b2 U0 P! i! y1 }/* request auto detection */
& q2 X& z6 }* Pint gdriver = DETECT, gmode, errorcode; " r0 i' V) Z7 ^
struct palettetype pal; + h. L( f2 Y" t6 \% p. y5 a5 E0 W4 f
int color, maxcolor, ht;
" m" B% n  i& H2 z/ a' Z. W% Oint y = 10;
9 K; q6 s+ l2 L- Ychar msg[80]; </FONT></P>
& `; j: J" R8 p0 G6 U<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 u9 O, ]; n$ [' o3 n' T! ~) K2 Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* v0 Q4 }9 L! Y4 F$ X% \<P><FONT color=#0000ff>/* read result of initialization */ ; M# [7 m2 S9 @. r) J8 m9 O1 Z
errorcode = graphresult(); 0 E6 H* f/ N3 _- q
if (errorcode != grOk) /* an error occurred */
2 w$ i# W: H, Y! I0 J( k: r# b{ + I) p" [7 i3 x
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 q, a" I: P1 _* y% }: ^4 e+ fprintf("Press any key to halt:");
" y9 a7 x1 v* M+ r2 rgetch();
1 B, E) ]: T2 j6 w- Pexit(1); /* terminate with an error code */
( Y, c, m( W' p/ x9 s6 {} </FONT></P>
6 V* ]$ f/ H9 p2 A! t<P><FONT color=#0000ff>maxcolor = getmaxcolor(); / d+ c# J6 U4 u* l
ht = 2 * textheight("W"); </FONT></P>/ Y( [- R3 R; M/ J. H
<P><FONT color=#0000ff>/* grab a copy of the palette */ 3 q3 a, X6 N( W0 F$ M5 x$ u
getpalette(&amp;pal); </FONT></P>
" ]( F$ e' k3 W<P><FONT color=#0000ff>/* display the default palette colors */
! j0 R6 t! A) t: q% Rfor (color=1; color&lt;=maxcolor; color++)
" u) A% N: n  E- G; m2 M9 c{ & E7 ?  `& O- k& h9 Z
setcolor(color); 0 I( p- p+ O- z3 q7 m6 s3 d
sprintf(msg, "Color: %d", color); 5 e+ W  C( `) Q
outtextxy(1, y, msg); # g0 M* y$ U- X9 M4 w9 e) S; E
y += ht; ( d* S5 o  M. r/ K; w' H
} </FONT></P>
$ Q' C; j, g( k3 [: Y) J: \<P><FONT color=#0000ff>/* wait for a key */
1 W" B  i8 B. b; l# G2 Fgetch(); </FONT></P>
+ Y( }2 ?. y2 m9 m0 \<P><FONT color=#0000ff>/* black out the colors one by one */
2 l, Y) L5 H0 O* E/ S  C# a6 }for (color=1; color&lt;=maxcolor; color++)
2 c9 s# R1 A; F! A/ @* m# U- a{ 3 M" l5 f" h  o& O' [7 Y
setpalette(color, BLACK);
( l9 J3 G' A$ N* ^getch();
+ [% c4 n7 q* y2 U: a9 B% V} </FONT></P>' y; f8 R# s1 r5 y, {# ?
<P><FONT color=#0000ff>/* restore the palette colors */
! G# b  G- U1 H: U6 `  E) Bsetallpalette(&amp;pal); </FONT></P>+ [8 I. o5 k" }& ?) y5 [* p
<P><FONT color=#0000ff>/* clean up */
: t1 `# N4 P3 h# F' h! E) {5 Xgetch();
- R6 V$ `/ s! @) L4 A  [closegraph();
9 i6 ~& T9 p- l" u1 ?return 0; 1 M# ~) k* V1 }! A; I/ s
}   z4 }) T9 }1 K: D
, q' v1 {% j/ [6 ~! t, A8 P: i
</FONT></P>
5 t( t+ j6 x3 d# t' Z<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
5 i$ A1 Q' s4 E4 V, `$ N+ f# t! I功 能: 设置图形纵横比
8 L' H2 X8 B9 d4 G用 法: void far setaspectratio(int xasp, int yasp); ; ?$ F+ ^0 z# n0 r) b/ b- l* p
程序例: </P>: j2 H! Z8 ~- ~; z7 ~" a9 Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>. ^2 o7 [# T3 G. ~
#include <STDLIB.H>
( ]% |. V1 y* O$ L" ^#include <STDIO.H>, G' p  _1 x4 A/ f6 X7 k/ {
#include <CONIO.H></FONT></P>
5 R4 H3 g0 @7 \3 s6 h4 K% ?: H<P><FONT color=#0000ff>int main(void) 3 |% q3 {8 |) L% \
{ ( Z' W. U5 T+ X# V  p0 T  [7 P: d
/* request auto detection */ , P' T9 O5 E9 B! ~+ c1 B
int gdriver = DETECT, gmode, errorcode; - V+ ]4 s  d- J  B
int xasp, yasp, midx, midy; </FONT></P>
, x  [* O7 ^$ q% E" e2 ?6 z<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 K% i+ N; V- |  B5 {# W) Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 m* X6 \* c2 [% ]6 u
<P><FONT color=#0000ff>/* read result of initialization */ . n& A0 D3 W* C, M1 B  ?: i$ I
errorcode = graphresult();
! k/ u8 ~2 I; c9 S$ mif (errorcode != grOk) /* an error occurred */
0 \" ?% d$ _$ \. f& [{
( @- m, i5 @' o) l4 j! _6 D) c! yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
# ~$ |0 l/ h# {( Jprintf("Press any key to halt:"); * Y4 p9 Z& e  e  U
getch();
* n4 O/ ]" m+ d! U1 kexit(1); /* terminate with an error code */
1 q* P; r! b/ A4 S  a& D} </FONT></P>
/ P$ u8 I8 x* l: e2 a9 n9 M4 {<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 _5 k# G1 {$ S. P. r2 Umidy = getmaxy() / 2;
) n" _0 y4 m: V0 p3 Z& n  psetcolor(getmaxcolor()); </FONT></P>
: i/ x4 n, w/ T0 h5 t9 C; X( e4 K<P><FONT color=#0000ff>/* get current aspect ratio settings */ 6 G! K6 T" Q; o( B. e! g
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
' k) H' }3 T& {' L9 K/ r<P><FONT color=#0000ff>/* draw normal circle */ . w- V$ f; b: B2 d3 V
circle(midx, midy, 100);
8 p. ~+ e9 L  D0 s* L9 e/ wgetch(); </FONT></P>
. L  R& N( x' |$ H<P><FONT color=#0000ff>/* claer the screen */ 6 ^/ d7 ]8 |& Q- v$ b
cleardevice(); </FONT></P>
9 E/ C% x2 |9 ~' [- F<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */
9 J: E7 J! {9 S  J3 d: _4 f/ Q1 fsetaspectratio(xasp/2, yasp);
3 d8 V2 T( i) d1 p9 m& ^" Z) Tcircle(midx, midy, 100); ; |7 j$ [' j0 U" B
getch(); </FONT></P>
) ^; m( G5 s$ o- X' I! I6 x<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
4 O- C6 V; Q, f9 Ycleardevice();
1 b; o  t/ V1 nsetaspectratio(xasp, yasp/2); $ a! I' G7 M( A+ k! x7 Q
circle(midx, midy, 100); </FONT></P># @# |& R8 p$ _, ?, P
<P><FONT color=#0000ff>/* clean up */ - B3 T( r+ k; l# K8 J' t& S
getch();
9 j/ ]- j( [* y5 L: kclosegraph();
1 U( ^$ C' V5 A# |( v- K, }* b2 Creturn 0;
. Q$ J: i7 w$ s# t" [2 Q, ?" x- A}
! O# j! i8 b3 V) q2 ^</FONT>
& z0 O/ V! ?5 J$ j+ m" @1 |* p</P>
' d/ Z  F$ G) j1 |<P><FONT color=#ff0000>函数名: setbkcolor </FONT>  W1 u" G" ?& k* z- ?9 m3 P4 P  k
功 能: 用调色板设置当前背景颜色
; a5 k6 Z: W  E9 @" R3 ~用 法: void far setbkcolor(int color); # R0 ]9 D6 F/ a' l5 ~3 q
程序例: </P>
8 G: Y, g0 ?# V" P8 b! k<P><FONT color=#0000ff>#include <GRAPHICS.H>- X4 A) v5 o5 T. t
#include <STDLIB.H>9 M& O' S, V* t9 W( U
#include <STDIO.H>
1 m5 H( j0 R3 l#include <CONIO.H></FONT></P>
0 B- y* X* N4 b, K9 [; I<P><FONT color=#0000ff>int main(void) / t5 w# N8 x% |
{
8 D7 T/ Z0 ~7 {/* select a driver and mode that supports */
- o% ?6 p; t* d; ^+ r9 F/* multiple background colors. */
* _" t$ z, v. z: S/ rint gdriver = EGA, gmode = EGAHI, errorcode; , I$ _2 \, \1 B
int bkcol, maxcolor, x, y; 1 M4 t& y, D3 g4 i! S5 G
char msg[80]; </FONT></P>! j  o7 d# j8 J% C
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 ]; H* R# K: q+ p1 i
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! u0 X- {( O; r7 e; D9 n
<P><FONT color=#0000ff>/* read result of initialization */
+ H! D; G7 |8 c9 T0 ~! _errorcode = graphresult();
9 l& O3 i# E" ?6 g, eif (errorcode != grOk) /* an error occurred */ , V- t9 s6 _! [4 `
{ 5 s* a6 t+ g$ Y5 X) l
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 c% `6 t( N* H/ x
printf("Press any key to halt:"); 0 m( T" W9 g# n+ R7 {
getch();
- U* L1 g$ I  t, W7 i- ?0 iexit(1); /* terminate with an error code */
: P( A8 Q6 h: R! O' Z' ^, Y( R5 m; T- S} </FONT></P>
: l1 B* V' e9 a" `5 L. s<P><FONT color=#0000ff>/* maximum color index supported */ . w/ d& ?' y1 o0 D) E: x
maxcolor = getmaxcolor(); </FONT></P>) t5 K& h$ L2 R. G5 K
<P><FONT color=#0000ff>/* for centering text messages */
0 E( H8 D% I; H6 isettextjustify(CENTER_TEXT, CENTER_TEXT); . b7 x& s: Z8 c4 o' i
x = getmaxx() / 2; - |0 ^$ U- [( Q' u1 }
y = getmaxy() / 2; </FONT></P>1 e; x8 V' b1 n- |+ E/ n# l0 b; \% Y
<P><FONT color=#0000ff>/* loop through the available colors */
8 u9 q8 |2 W4 ]. Dfor (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
5 F! {3 J$ I& B{
8 J! H- b) B4 D: b( v/* clear the screen */ % Z0 R8 e7 I, I+ E. z6 c
cleardevice(); </FONT></P>
; ?+ P+ K2 F6 S/ C6 ?, U5 @# |<P><FONT color=#0000ff>/* select a new background color */ 6 S% u$ f. \+ x+ c
setbkcolor(bkcol); </FONT></P>
3 C  D  V: P) ^; e, O<P><FONT color=#0000ff>/* output a messsage */
6 s, R2 `+ `4 u# z6 A1 {if (bkcol == WHITE)
+ T" P9 Q* t+ K7 Q  Gsetcolor(EGA_BLUE);
" M# j! ^, N2 [1 N" Q; Jsprintf(msg, "Background color: %d", bkcol); ' D. d& X9 q: l: C
outtextxy(x, y, msg);
, o9 d. \: x/ L! U8 Tgetch();
1 ~+ E2 J- @% ], @6 g/ M8 d! {} </FONT></P>$ _9 f" o  S/ _, [; e  D* j* T2 }
<P><FONT color=#0000ff>/* clean up */
/ @# _* u6 ^! W6 u0 o; E5 ~closegraph(); 2 q4 u/ L6 V7 q, ^4 Z& }& B  W( A
return 0; ) K6 F: _3 w# C; W
} </FONT>( Z9 i# x4 \3 f% L) U4 _: s
' m3 a( U" z7 _0 X7 V& k  G
</P>
' @2 K* x2 x' F3 e3 G<P><FONT color=#ff0000>函数名: setblock </FONT>  {2 r  J5 \% P3 k3 H8 C; X
功 能: 修改先前已分配的DOS存储段大小
0 _9 N" [* D1 C. s" B3 M" X! ~用 法: int setblock(int seg, int newsize);
, Z+ M9 R- R" J- e  t  i程序例: </P>
6 }, v& N, I- r) i' j6 j2 x<P><FONT color=#0000ff>#include <DOS.H>
$ k, Z5 y) X8 F1 ]/ [#include <ALLOC.H>- }5 B; H! F* h- U" E! k
#include <STDIO.H>+ \# g& t5 A, m, j: b3 {7 Z
#include <STDLIB.H></FONT></P>  Q$ n# V9 B& q/ _1 W: I
<P><FONT color=#0000ff>int main(void) 6 n& K2 ^8 J& x) U2 c( O
{
0 p0 Y- [/ o+ b5 K2 {6 l+ z( Uunsigned int size, segp; 2 [6 r$ x8 @9 a/ Z, S0 M% Y! r5 i7 {* O
int stat; </FONT></P>
; g# I- w! _1 X4 I; ]<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */ / m0 C1 d2 e- N# f) C+ s
stat = allocmem(size, &amp;segp); 8 d5 w, v5 n. b4 F' }7 `
if (stat == -1) & S$ y/ H5 Z/ k! X8 X: O6 K
printf("Allocated memory at segment: %X\n", segp);
* L' m# N1 s, j+ Oelse 3 t6 t4 Q% G2 y; c
{
; L8 f7 f0 v5 dprintf("Failed: maximum number of paragraphs available is %d\n", ; \3 ^; z8 p8 @% f4 P* C; a
stat);
+ @% q$ p* L. aexit(1); ' |/ l! {0 Y/ B8 |
} </FONT></P>
: S* `3 n; w2 m6 Q<P><FONT color=#0000ff>stat = setblock(segp, size * 2); $ b2 c  f( A/ {- R$ |- Y: z
if (stat == -1) 0 n9 ~, [6 w" ?
printf("Expanded memory block at segment: %X\n", segp);
: t; p8 f1 W! n: S- [$ M( o; Z4 ?else
$ v4 r+ O' @( l! x) Y/ t2 ]printf("Failed: maximum number of paragraphs available is %d\n",
7 E1 e- S! ~$ a% `! f$ s: astat); </FONT></P>
" m) @5 e" x1 ]9 V: a5 O<P><FONT color=#0000ff>freemem(segp); </FONT></P>- N# n( b/ a% T
<P><FONT color=#0000ff>return 0; # N# _. n/ e9 t$ _& M( `
}
* ?2 ]4 \/ n2 f5 X5 Y$ D! Z</FONT>1 P$ [4 g7 m( R1 S" Z/ D3 X' W
</P>
) s+ O7 x4 A  R  a<P><FONT color=#ff0000>函数名: setbuf </FONT>
# C3 i* y' {/ G! `, e8 \功 能: 把缓冲区与流相联 * X1 n$ G% X2 C: g) d
用 法: void setbuf(FILE *steam, char *buf);
- h. a9 m4 k% b8 x程序例: </P>
4 q' o7 u$ ~4 a/ Z( A8 L( M<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>( T# [# Z* O3 e
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ 4 t+ p& J2 X' ^* F' k. E0 `
char outbuf[BUFSIZ]; </FONT></P>2 L* O/ M9 p! {2 x* U; D
<P><FONT color=#0000ff>int main(void) 5 M. n0 N0 E8 c
{ + M0 m2 M. N. N; R
/* attach a buffer to the standard output stream */ ) U1 c* |4 f/ N: S7 b. N# T: f/ Z
setbuf(stdout, outbuf); </FONT></P>" g' A! M9 N4 \; T
<P><FONT color=#0000ff>/* put some characters into the buffer */ + a$ w6 U6 q3 @1 }5 G( M
puts("This is a test of buffered output.\n\n"); ( k  S! j* ]% C
puts("This output will go into outbuf\n"); ( p/ p, Z% M5 X% N, G1 _
puts("and won't appear until the buffer\n"); 5 V  o# S& J- L# [; a+ _* ]' t, I
puts("fills up or we flush the stream.\n"); </FONT></P>
7 u  b; [3 j& E<P><FONT color=#0000ff>/* flush the output buffer */ * ^# K0 j. r7 Q: @9 @/ M! p& b9 k
fflush(stdout); </FONT></P>
: |, K+ w, h- y8 [$ `/ r; q+ P' Y3 M9 u<P><FONT color=#0000ff>return 0;
3 `/ j* E' Z1 P: z3 d0 A} 0 f' |1 M9 ~5 k9 w6 E2 l
</FONT>
( B' h1 c0 l4 Q: M) [</P>: p+ g/ O" r8 j7 T# S) z
<P><FONT color=#ff0000>函数名: setcbrk</FONT>
; X3 F9 A" U% @' J0 r- i2 u功 能: 设置Control-break 3 O# Y1 a6 _, A* i, ~' F/ W
用 法: int setcbrk(int value); 5 g2 x. }, f) Z9 a% r
程序例: </P>
: q  O5 J# M# i<P><FONT color=#0000ff>#include <DOS.H>
) [# J% ?6 ^3 `. u0 g* m2 b' c#include <CONIO.H>& b& \/ h  K, b  w$ a4 q5 \0 a5 \
#include <STDIO.H></FONT></P>
1 Z% u$ r7 h/ H. ~. z<P><FONT color=#0000ff>int main(void) ; _  M4 f; L9 B# N. E
{
# y$ T3 e1 O: \. O/ }int break_flag; </FONT></P>
  r1 p2 a9 }( F4 _<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
" e4 j6 D$ |1 Rprintf("Enter 1 to turn control break on\n"); </FONT></P>6 j) @* F8 c: t, o. {8 I
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>2 ^' x- \, o' F* D
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>$ {+ [4 P( m. |1 J" k! f
<P><FONT color=#0000ff>if (getcbrk()) 4 \$ c: b% ]  S6 l
printf("Cntrl-brk flag is on\n"); + }/ h( l5 h. C, ^. H6 u
else
2 i4 _% _$ h; v: ^printf("Cntrl-brk flag is off\n"); ! q5 a" `, i9 w; z1 i3 S
return 0;
5 i8 M! ]! @7 D6 o2 Y8 I! g- S} 4 p1 n2 H$ h; d' u( W  I6 ~
5 o! X" g! X$ g' d2 {) [/ J! T
</FONT>3 n' z( U- J9 u+ _
</P>; L% l' ^3 m* H" i, ]2 }( F
<P><FONT color=#ff0000>函数名: setcolor</FONT> 9 ~# ^$ u# t# P& G8 r$ n
功 能: 设置当前画线颜色
7 h' G5 y& `+ g$ y! y: z" P用 法: void far setcolor(int color); * |% A5 t. E- N% t3 E
程序例: </P>' S1 D+ U- `) q9 B5 b
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 X  V" r8 R, Q- U% Y; B0 z#include <STDLIB.H>: p  ^. x/ D, [
#include <STDIO.H>! p) _; v8 P- g. {% R
#include <CONIO.H></FONT></P>* E* L. \; |! K9 S3 D0 R, L
<P><FONT color=#0000ff>int main(void)
. K+ W% {2 z: F8 U1 X& [) A{
% D; ?/ H/ n+ R( s' n/* select a driver and mode that supports */
/ s- L& {. \( w9 T/* multiple drawing colors. */
) |0 y0 y4 s- r2 ]- S4 f. I( S# v5 Y# [int gdriver = EGA, gmode = EGAHI, errorcode; 4 G/ A- z+ b5 q5 G" L1 z
int color, maxcolor, x, y; 4 T: [' h+ n! O) Y- c$ n/ C
char msg[80]; </FONT></P>4 X6 @# U( m! V/ o! H+ l9 s! F
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " W, j8 c. L% T+ m
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" C' j% n0 R; v! s" b- |8 x<P><FONT color=#0000ff>/* read result of initialization */ $ W$ P# @; v6 |  N8 S
errorcode = graphresult();
, H( C0 q7 f0 _& v! C: ?5 gif (errorcode != grOk) /* an error occurred */ : v, T5 b' M, z, s
{
! T' y7 G/ }& d' [6 e4 t/ \printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' a8 q/ ]+ {3 U' ^6 a5 L1 [
printf("Press any key to halt:");
& l. Z& V$ m7 X  P% z% y& Lgetch(); % ^9 B% M% b* Y; y0 Y% s
exit(1); /* terminate with an error code */
' N# ^' K* N1 K2 V& [} </FONT></P>
) e4 V; b6 p( f- Z6 o2 m<P><FONT color=#0000ff>/* maximum color index supported */ + L3 ?1 ~5 M( C
maxcolor = getmaxcolor(); </FONT></P>
, F$ ?$ I/ n) L6 ?  e3 e<P><FONT color=#0000ff>/* for centering text messages */
4 W5 _) n8 N! h% M3 I: B+ E# jsettextjustify(CENTER_TEXT, CENTER_TEXT);
4 r7 ~: }" S0 p7 Ex = getmaxx() / 2; : p1 \% R  e; x' W, Z  ]  k1 O- ?
y = getmaxy() / 2; </FONT></P>
4 T3 P) n. h- ]$ M<P><FONT color=#0000ff>/* loop through the available colors */
* g2 q" n% r- M: |for (color=1; color&lt;=maxcolor; color++)
- X7 f+ G8 L# I3 d{
/ s7 h3 i3 h$ A( N& W/* clear the screen */
# q  k& U4 n/ g5 n0 u& icleardevice(); </FONT></P>% A, C3 T- p7 `) ?
<P><FONT color=#0000ff>/* select a new background color */ 7 M9 j" D  I& s* ^8 q3 t5 _* Y
setcolor(color); </FONT></P>
* Y! |) O! N) {# J+ R' d' t<P><FONT color=#0000ff>/* output a messsage */
* B! ^7 u, F* B' P$ j5 t6 Qsprintf(msg, "Color: %d", color); $ a) q/ N. v1 ~7 D
outtextxy(x, y, msg);
) O5 v" C9 Y& g$ K& K' i  ^: _3 Pgetch(); 3 i) f: N" P, ~# s2 g' N3 [
} </FONT></P>
/ g* [# X, g% b( b<P><FONT color=#0000ff>/* clean up */ $ q0 c  B, m5 A: }7 K0 w* x
closegraph();
6 \4 k6 \* B/ X* V8 b! V" Y( Yreturn 0; " }' ?; `# c2 \" l$ }" c& t7 C
}
7 Q3 n6 S8 |+ r</FONT>
4 H# {6 }/ b# C$ u</P>9 @' L. @5 a( c& y4 i( P! t
<P><FONT color=#ff0000>函数名: setdate </FONT>
6 F: V  k* a# h功 能: 设置DOS日期
; U4 c9 M; D* t9 J& V2 k- K用 法: void setdate(struct date *dateblk);
3 K( G' E! i  A1 l6 W程序例: </P>
# c+ f% k. }! h2 M: @3 x% U; q# ^<P><FONT color=#0000ff>#include <STDIO.H>
: k. g: t0 |3 Z/ N#include <PROCESS.H>
3 F+ T! V4 b; @5 K& i2 q4 l#include <DOS.H></FONT></P>
  a* E: w; P2 w# z<P><FONT color=#0000ff>int main(void) 9 v" {, i) B6 v2 D- X  h# I
{ ; u( b) s0 ~  I
struct date reset; ' Y. Y% W0 W; v
struct date save_date; </FONT></P>+ v* b& o! D* D
<P><FONT color=#0000ff>getdate(&amp;save_date);
2 q: y# l. y5 q5 mprintf("Original date:\n");
7 [0 f$ T; A; D+ J9 Fsystem("date"); </FONT></P>
# z5 x; f6 F: _' l<P><FONT color=#0000ff>reset.da_year = 2001;
$ I# u$ P% Q" ~- d9 Q) ]reset.da_day = 1; , I( i! P2 F0 y" u
reset.da_mon = 1; " u9 P% Y9 e5 j1 x
setdate(&amp;reset); </FONT></P>; B% B# q& ]1 S" \, A& K% I$ ?% i
<P><FONT color=#0000ff>printf("Date after setting:\n");
! J7 C" \- T; [0 I9 c! ^system("date"); </FONT></P>* k* P/ E1 E! v* B8 Q! f
<P><FONT color=#0000ff>setdate(&amp;save_date);
7 l+ ~1 Y7 X( U6 X8 r, h$ A& @' Bprintf("Back to original date:\n");
6 [' H, T( R- S8 d6 n) U: Ysystem("date"); </FONT></P>
) p, b4 b4 F1 |0 z# H: [/ I<P><FONT color=#0000ff>return 0; 6 g3 L+ Q( u, ^- s1 }8 g$ c! B/ Y
}
2 o! Z+ L% E% E</FONT>" j3 `; X  S% W# u" i0 x
</P>
9 K1 j( u2 ]/ ^6 {% F6 x( }<P><FONT color=#ff0000>函数名: setdisk </FONT>
+ f, j5 f: Z: j* S功 能: 设置当前磁盘驱动器
! P5 q/ c3 m5 ^. q; W) ?用 法: int setdisk(int drive);
& G; y4 U. x+ k# B) {程序例: </P>" `. d5 m7 [5 j' [5 Q
<P><FONT color=#0000ff>#include <STDIO.H>  n/ @6 k6 [4 T6 V1 b# q
#include <DIR.H></FONT></P>
0 `7 V" G& Y) R$ i  U9 u1 v<P><FONT color=#0000ff>int main(void) 8 j1 p! ^& k. v4 c4 c! l- F
{
3 ^. {& s  i) Y4 Dint save, disk, disks; </FONT></P>' {8 u; j2 B  }+ g: ]
<P><FONT color=#0000ff>/* save original drive */ ; M9 F7 x: X$ _
save = getdisk(); </FONT></P>$ c6 {2 x0 \8 \1 W( M7 V, j5 F
<P><FONT color=#0000ff>/* print number of logic drives */
8 U% J5 I- W2 [- L3 m+ Q6 u; vdisks = setdisk(save);
" |  v$ a& C& x2 t6 Dprintf("%d logical drives on the system\n\n", disks); </FONT></P>! S6 d0 g4 [- x6 B) F$ L' F: @
<P><FONT color=#0000ff>/* print the drive letters available */ & A" L; @6 j5 ?) ~6 ~8 ^
printf("Available drives:\n"); . p3 }( K- q0 v, |$ }* d
for (disk = 0;disk &lt; 26;++disk) 3 q) h0 D# v2 {4 w: ]5 [2 @
{
. w) A- G  R) q/ Y5 l! Lsetdisk(disk); ' ]8 }( s, f; {' K& U. H/ L
if (disk == getdisk()) 9 u' h4 h1 x5 y9 g5 B  I
printf("%c: drive is available\n", disk + 'a'); " F& C; l' d3 m7 \5 a% s7 b2 n
} # d  l0 m3 a5 v3 {' M
setdisk(save); </FONT></P>: l# W: u2 L" f$ w+ P. j
<P><FONT color=#0000ff>return 0;
, j6 A& o% v) s  c" p% I} </FONT>
$ b# p8 X! Z" h$ W) g5 l: q& a0 \% {! M) f+ D& ]. P& W: c
</P>
& Q/ \8 p- M4 a. D) P3 f<P><FONT color=#ff0000>函数名: setdta </FONT>& w- m3 Q) G$ K- O
功 能: 设置磁盘传输区地址 ( \4 A! A' ~0 G# _, S
用 法: void setdta(char far *dta); 6 o0 o. j0 f+ x# z0 m# k8 p+ ^
程序例: </P>
* d! o8 e6 L% ]+ h# H8 R# Q<P><FONT color=#0000ff>#include <PROCESS.H>
% L! T! q5 K* I. ~, ?#include <STRING.H>2 D' q  L5 |9 C4 a9 F
#include <STDIO.H>& U1 f  n$ ~& U" W- n( [+ E
#include <DOS.H></FONT></P>( @3 t+ h$ O) x# K. X9 R" p5 X4 N
<P><FONT color=#0000ff>int main(void)   ^9 ]  j# N. ~5 p- d% L- [
{
/ `' r2 U" S$ I+ F7 zchar line[80], far *save_dta; + z+ r* n1 J  b  J$ i
char buffer[256] = "SETDTA test!";
$ k' r! y$ K# V9 P' H0 @4 S6 ?struct fcb blk;
' v1 t/ T$ C* V/ g; C. ]int result; </FONT></P>
$ }/ H8 _* a; }& Z1 j7 M( J<P><FONT color=#0000ff>/* get new file name from user */ ' G+ p0 t, S9 @6 m& I
printf("Enter a file name to create:"); + o: D$ {  R8 ]9 {
gets(line); </FONT></P>
& R6 e  w6 Z* _7 L1 b<P><FONT color=#0000ff>/* parse the new file name to the dta */ ( b$ g; k; y+ j
parsfnm(line, &amp;blk, 1);
; z2 }2 \! f9 `# Qprintf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>. k7 E2 O! R, k
<P><FONT color=#0000ff>/* request DOS services to create file */
+ m9 W( s5 y. F0 qif (bdosptr(0x16, &amp;blk, 0) == -1) - ?" G+ T& [2 i
{ " x' B1 F- v8 d8 ]/ s
perror("Error creating file"); : i- H" `% M8 R6 P" N' e, a4 @& `
exit(1);
/ ~* F8 m( Q' [} </FONT></P>9 i: a1 b/ X0 }6 C. n; ~
<P><FONT color=#0000ff>/* save old dta and set new dta */
6 \2 f: V" A& Isave_dta = getdta();   D& K. G4 s9 C6 `" H
setdta(buffer); </FONT></P>% j9 h5 @0 L& F8 \" a
<P><FONT color=#0000ff>/* write new records */ % }! t2 [0 R0 o" x
blk.fcb_recsize = 256;
2 B5 A$ j7 V9 j+ f1 Mblk.fcb_random = 0L; - S" `7 B2 z3 |# l' d3 d
result = randbwr(&amp;blk, 1); ! y: i; I0 m' J% I
printf("result = %d\n", result); </FONT></P>- P. P# r! ~: ]& v+ w6 x& n
<P><FONT color=#0000ff>if (!result)
) X) D) H$ ], i. G7 M3 vprintf("Write OK\n");
; r$ Y- R) ^7 k. Pelse   z! J6 X6 e: O
{ : {0 H8 G) n4 v6 C5 ^" `% F
perror("Disk error");
, p2 |6 X6 ]; f; i8 bexit(1);
* E8 g# @1 a* l0 |} </FONT></P>  k" A9 i* ^& w* _  o0 Y8 p+ y- z. Y" `
<P><FONT color=#0000ff>/* request DOS services to close the file */ ' S5 s7 v) E; C/ D0 x" Z
if (bdosptr(0x10, &amp;blk, 0) == -1) " ~' [2 v1 B6 K  F7 g
{
. l# f+ _! m+ ^5 C' m% Z6 `4 pperror("Error closing file"); ) `1 M5 Z; R4 h
exit(1); & o  b8 D5 |' a4 e
} </FONT></P>% G1 b7 @0 `& }. o: X  R* L
<P><FONT color=#0000ff>/* reset the old dta */ % i8 J8 q2 a5 R) i8 {6 {3 v, z
setdta(save_dta);
: o. q5 @) E- p; J( t' T, yreturn 0;
0 X4 l$ O& A: \& d}
1 E, T+ k7 |! f# E</FONT>
, E6 O1 P4 a* Z& S$ L# _5 L</P>& @" H4 V. M9 b; ~* g
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>+ _" C" a3 p9 Q6 x0 j2 d0 s; n  J
功 能: 选择用户定义的填充模式 # ^8 Z: k- F8 T' G, K9 P+ G' `
用 法: void far setfillpattern(char far *upattern, int color); % O* C7 U$ ~- o+ g9 W$ y
程序例: </P>& v/ \- p9 U0 A) r5 [2 ^, ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 K! y- ~, O1 e+ v
#include <STDLIB.H>
, \+ M6 U  l. U% N/ s#include <STDIO.H>2 l4 @  T# C' C; q- v
#include <CONIO.H></FONT></P>
8 k# B2 n" I$ `2 ~) H<P><FONT color=#0000ff>int main(void)
/ l% @( r  B/ S) a{
% F& n3 O' _; }/* request auto detection */ 4 K0 J: c& A0 |3 `
int gdriver = DETECT, gmode, errorcode; / a! i; p2 c7 W3 ~7 b
int maxx, maxy; </FONT></P>9 f, r" A% _2 m' {
<P><FONT color=#0000ff>/* a user defined fill pattern */ % W1 ~, l/ ?6 Z- U/ r9 E! t
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P># u& Q1 [7 f) e: [) V* H7 t  n# m2 S
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 E3 A/ d' j9 l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. b1 U2 L6 T& w1 i$ f  o
<P><FONT color=#0000ff>/* read result of initialization */ $ p2 ~3 s6 a$ T- M6 y$ |  w
errorcode = graphresult(); ) G* f) p' A" ^& w/ F! h
if (errorcode != grOk) /* an error occurred */ ) i4 d8 h( Z: P- U3 I
{ / X7 [3 P& U+ X5 j" k  ]
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 y/ y$ m5 r: F2 l& F
printf("Press any key to halt:");
+ |/ U6 }% j5 x" M: n; Cgetch(); . |8 I3 `3 v; Q" I7 I
exit(1); /* terminate with an error code */ ' ~5 t+ w; {  ^' _
} </FONT></P>
0 r2 F5 y+ x3 V* A! h<P><FONT color=#0000ff>maxx = getmaxx(); ) M# d  C9 w3 W2 P' [
maxy = getmaxy();
6 Y8 Z1 u+ ?' g) m3 o7 N$ {# {setcolor(getmaxcolor()); </FONT></P>5 @  f1 U& w6 G2 n; ]! @' S
<P><FONT color=#0000ff>/* select a user defined fill pattern */ 8 y+ I! Q* }9 d0 h
setfillpattern(pattern, getmaxcolor()); </FONT></P>
- u; S& u' F+ ?: R2 Q8 ~<P><FONT color=#0000ff>/* fill the screen with the pattern */
" U& u7 C- T4 }  K( ?$ s4 wbar(0, 0, maxx, maxy); </FONT></P>
% M- q* h: h! p; e<P><FONT color=#0000ff>/* clean up */ " q. e5 H7 @7 m4 k, Z( l
getch();
7 Y' U' A" J' tclosegraph();
$ p7 @, v! k6 P3 Jreturn 0; 4 f9 o* W8 l% F, |  a
} % a0 P4 P2 z5 {- [
</FONT>) f4 K: L5 D; W- J
</P>
1 Y  w! h* V7 `$ I) @8 S- n% U<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
8 H/ ]! O6 N; a3 v  ?  Z功 能: 设置填充模式和颜色 9 J$ m4 C$ ~# g0 K& ]
用 法: void far setfillstyle(int pattern, int color);
; C, v# l; O" l5 ]程序例: </P>
5 S( O: x9 d" o4 k0 R<P><FONT color=#0000ff>#include <GRAPHICS.H>5 h5 P7 q# {+ F- r
#include <STDLIB.H>$ X! L- p9 Q& l# F
#include <STRING.H>
7 u- m% P# \  y8 e6 Q#include <STDIO.H>
- s) @* q& h* j#include <CONIO.H></FONT></P>
6 \- _* ]- \, n- t$ ?" c; R<P><FONT color=#0000ff>/* the names of the fill styles supported */ ( _6 V. n2 [  q* Q* {
char *fname[] = { "EMPTY_FILL",
) e) {4 n; @( e) Z8 D/ M"SOLID_FILL",
2 B7 ]& |7 ]! h5 B1 K"LINE_FILL", ( n1 O1 V2 m  ~& n6 q
"LTSLASH_FILL", 7 _; f8 c6 ^$ C+ O0 `- ?7 [- ?
"SLASH_FILL", - A3 q/ N% z' Z. a$ H
"BKSLASH_FILL", ; y' f& N6 d1 s# z  N
"LTBKSLASH_FILL", 3 k* ?5 M- D+ n9 h7 ^
"HATCH_FILL", # i5 W& O' d& s5 F
"XHATCH_FILL",
0 y7 z% `0 r* }5 C+ w  y. K& o# h" Z"INTERLEAVE_FILL", 0 |3 Q- W& M  b4 q# G, F6 z
"WIDE_DOT_FILL", & @, x, ~% {& U# }9 h# p1 \7 B
"CLOSE_DOT_FILL", 8 f- T+ j& g: L4 P, L& o# R
"USER_FILL"
9 L  x; d) q) y; C}; </FONT></P>
3 |/ e$ J/ h! e, e& z<P><FONT color=#0000ff>int main(void) + ^% j. L9 F* p# G, D  X3 ^
{
3 d3 D" b+ J; D, ~! {: ^9 B/* request auto detection */ $ v4 {' [/ Q' n7 ~0 L
int gdriver = DETECT, gmode, errorcode; ! c5 ]& ^, N% g+ h7 T
int style, midx, midy;
% X& U: p7 y) R4 B( @char stylestr[40]; </FONT></P>
, }2 B2 k7 t/ @& R3 }; w<P><FONT color=#0000ff>/* initialize graphics and local variables */ * |0 z* x: D! i: X, @/ N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" X/ ^  ?: c5 H' y
<P><FONT color=#0000ff>/* read result of initialization */
% R) m- o( O5 T8 Kerrorcode = graphresult();
+ V3 x$ I& L+ O0 x$ fif (errorcode != grOk) /* an error occurred */
- K+ r4 @% w7 m7 V+ y8 E{
2 _; o+ K/ u% b' @8 x( nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
$ C, y. O# t0 d9 M& mprintf("Press any key to halt:");
3 Q5 ?: l9 R5 n: ~' K8 u& R6 Bgetch(); + |: t5 T& i- a& g+ P
exit(1); /* terminate with an error code */ ( Y- ~, ^& x3 U( y$ F
} </FONT></P>
! S) Z2 x  |  L% o2 N% U3 X7 n<P><FONT color=#0000ff>midx = getmaxx() / 2;
% B- J+ D% M5 R/ B6 gmidy = getmaxy() / 2; </FONT></P>+ \0 Z& @8 n# ?& f
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
3 J9 O" T% q5 T2 K4 e{
) N# s) f( V5 h/* select the fill style */
; K8 e" s, m, X$ X( qsetfillstyle(style, getmaxcolor()); </FONT></P>
0 X" n) C; T; |6 q, M/ b<P><FONT color=#0000ff>/* convert style into a string */ 1 a# ?( W: B6 Y
strcpy(stylestr, fname[style]); </FONT></P>
% @; J* Y% X0 Q5 S$ i% p<P><FONT color=#0000ff>/* fill a bar */
' b  B) c0 s8 u, }: Bbar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>) k! E. Q4 v" ^3 Z
<P><FONT color=#0000ff>/* output a message */
4 z; f" l/ e6 v7 C7 youttextxy(midx, midy, stylestr); </FONT></P>
4 p) v. r  H2 [4 {6 l) `0 i( C<P><FONT color=#0000ff>/* wait for a key */   ?: A# d) ^4 w& s
getch(); . z# p8 @% R# J$ j
cleardevice();
; i) }7 l2 n5 i0 j0 Q4 A} </FONT></P>
. M" p- g4 w+ ?/ Y$ e<P><FONT color=#0000ff>/* clean up */ 3 V5 c7 \  {1 S0 U, ]
getch();
0 z- M! M' T6 Z+ ]% xclosegraph(); ) p* h% N8 z  O& h: a( t2 M( u; C
return 0;   Y7 O; _' n7 E% u. l$ a1 Z
} </FONT>
" \/ r5 ]/ {# r. ~9 d0 y6 z( `, l7 d$ D( p/ K8 v
</P>: s9 C+ r. k2 v5 c$ x! L
<P><FONT color=#ff0000>函数名: setftime </FONT>! T! p& V* ]( b  a* k
功 能: 设置文件日期和时间
8 }  q1 q. r5 ~8 j# J/ p# ^7 n: b用 法: int setftime(int handle, struct ftime *ftimep);
5 P2 T1 l- J8 l" t6 t程序例: </P>+ k: _2 |, K( g  c7 a$ g+ [* h. _
<P><FONT color=#0000ff>#include <STDIO.H>
( r# c! b6 W8 h+ K' m#include <PROCESS.H>
* n0 G, y  h( Y1 }/ `# m#include <FCNTL.H>" _) m( S" V3 I  b. Q8 F+ X
#include <IO.H></FONT></P>6 z& M! U6 A1 V- s0 b
<P><FONT color=#0000ff>int main(void) 2 a( e- _# L8 z" B
{ 6 J/ x/ k# B+ @) B9 f
struct ftime filet; / T0 P) ~9 O1 `
FILE *fp; </FONT></P>
( T+ L' `2 H7 f( ]" C% H3 ]" I<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) : v% R& X5 q8 e! h$ }$ _
{
. c0 G7 E- }  T2 p% l7 Iperror("Error:"); 1 u! ~: S0 _/ h. ?. k# P7 d6 q, J
exit(1);
8 x3 F0 V1 {( g; U' v} </FONT></P>
( |" |) Q: y; r8 u# W/ p<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>5 D5 X- u4 g% M; g0 i! p3 P
<P><FONT color=#0000ff>/* load ftime structure with new time and date */ ! l  A, h0 a6 R" s
filet.ft_tsec = 1;
/ |2 z( t: e# u% Z2 nfilet.ft_min = 1; ) N8 d: o- m) K
filet.ft_hour = 1; 7 R* Z9 N- r  Q% A) {1 h* T8 x
filet.ft_day = 1;
/ O2 `) o* c6 a( z+ w( S! u! g1 V0 ufilet.ft_month = 1;
8 b& d1 u  W) ^9 t0 h3 Hfilet.ft_year = 21; </FONT></P>0 T# i: E# T" k2 T/ t3 e" Q
<P><FONT color=#0000ff>/* show current directory for time and date */ ! t4 R4 V  r$ f. W) P$ H, ^
system("dir TEST.$$$"); </FONT></P>
* m; e( W+ W) k- S: R( q<P><FONT color=#0000ff>/* change the time and date stamp*/
& [3 @" |4 h- Q- K! \6 Nsetftime(fileno(fp), &amp;filet); </FONT></P>- S/ \" K2 t1 [% d: f5 i3 f
<P><FONT color=#0000ff>/* close and remove the temporary file */ " B& @3 Q& v8 u8 y2 e4 Z7 q
fclose(fp); </FONT></P>
$ k7 p8 ?, N, V7 {+ u/ A<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>
! ^1 A9 W  b: e! P# t<P><FONT color=#0000ff>unlink("TEST.$$$");
. I! N- i# z: x( D8 P2 n7 Creturn 0; 7 P: @, c7 u$ u# j
}
5 p( G. ^1 d; |2 q+ n# b</FONT>
/ {+ n% X8 w4 L( \% d0 f</P>8 W8 c3 Q5 S' A% C$ g8 `
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
* \3 A% Q9 [- N* a4 s6 F% Z6 |3 G功 能: 改变内部图形缓冲区的大小 9 A  R2 |5 F: |% r, S
用 法: unsigned far setgraphbufsize(unsigned bufsize); " L+ S2 \( }/ b7 m9 o7 ]8 v7 K
程序例: </P>9 o/ p& p5 ?2 H( Q! J
<P><FONT color=#0000ff>#include <GRAPHICS.H>5 M: C. X: E# K, Q
#include <STDLIB.H>0 Z. ~5 w" g2 [* b$ [+ y
#include <STDIO.H>
3 G1 N- {. _8 }8 `  J& O#include <CONIO.H></FONT></P>
+ d$ a4 h9 o) s1 d% m1 t+ N<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>, c- `% |; n$ ]6 Z
<P><FONT color=#0000ff>int main(void)
' m- j: ], p6 c6 t; g{ - m0 z9 d  O' Q+ Y! ~" E
/* request auto detection */
* U" q% ~* F/ U! ]3 s) T4 h0 x" Jint gdriver = DETECT, gmode, errorcode; 4 S/ V* Z5 [+ w) v; }% j( P9 f8 Y
int x, y, oldsize;
/ ^- Y* M' P. }4 }( W1 Bchar msg[80]; </FONT></P>
9 B( \) Y1 X. W0 E0 M3 K4 p9 D! |<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ $ a! p0 z0 Y* T( e' I) O) G
/* before making a call to initgraph. */
' |) e' H8 d: ]$ ~" N5 W' `oldsize = setgraphbufsize(BUFSIZE); </FONT></P>% n, g$ D+ C7 d. V5 A
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 v6 s1 A8 E/ ^4 D5 q  Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 C3 K( I' }* ?) Q
<P><FONT color=#0000ff>/* read result of initialization */
3 w! H- M2 ?  ~( gerrorcode = graphresult(); . L! N$ R, t& U9 ]# ]0 y2 \+ _
if (errorcode != grOk) /* an error occurred */ 9 x' Y# D" H& M6 X& y4 s+ B, A' J2 G8 P
{ & T9 M5 y% U- N: B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
8 u$ C& u( q( W9 O: y( hprintf("Press any key to halt:"); 6 ~* N7 @- g  t: ]3 }8 U
getch();
) a$ E) G  v9 `+ `+ n* x( Hexit(1); /* terminate with an error code */ 0 `' j0 w* o: Y9 W
} </FONT></P>' y2 G( I' L  c4 h. @
<P><FONT color=#0000ff>x = getmaxx() / 2;
  W+ s/ {. _$ v$ m; ey = getmaxy() / 2; </FONT></P>
; z: a5 x. N4 K, U' X<P><FONT color=#0000ff>/* output some messages */ / [6 V8 F& [5 I" @2 ?7 G4 h* K
sprintf(msg, "Graphics buffer size: %d", BUFSIZE); # t. k9 [- W  C% v1 g3 p; b, O% ~' K
settextjustify(CENTER_TEXT, CENTER_TEXT); 6 c# m! m% [5 c
outtextxy(x, y, msg);
! x6 L* |. E  ~& Q' W: ^8 Psprintf(msg, "Old graphics buffer size: %d", oldsize);
; V! c% o$ F$ B4 B' ^6 Nouttextxy(x, y+textheight("W"), msg); </FONT></P>6 L( X: h+ u$ t: d
<P><FONT color=#0000ff>/* clean up */ 3 j# J$ ~5 W, h! O
getch();
) Y1 {  V. m- S4 }: p4 Oclosegraph();
1 t6 D' u- j$ h8 a( S, L2 q+ Freturn 0; ' s4 R1 e8 [) G3 @5 ~
} 9 J% @' V1 B% q) z
! e; c' u5 r( V1 ?* k% Y& h4 q

% |4 g' S7 u2 p/ `8 z</FONT></P>  a7 `5 U: A9 f/ C2 z( R
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>6 H3 {" |4 u% b- W- V; z; K$ Y3 m
功 能: 将系统设置成图形模式且清屏 ( g2 Z+ J/ K3 m4 b) E; k# q
用 法: void far setgraphmode(int mode); . Q, n; p+ F  k) f0 h' X& i
程序例:
/ [8 F- I8 O8 r1 ^" I. z; l
( {: e/ v4 B  C* S, H& C- w<FONT color=#0000ff>#include <STDLIB.H>6 q. {2 b; ?) c7 c* d9 |
#include <STDIO.H>
1 L- ?5 l! N% C#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
, X& g4 w% K1 x( Z7 h, p<P><FONT color=#0000ff>int main(void)
7 j3 Y6 z) {# k2 P; O& x9 U{ 4 O7 Z0 x  ^2 F( v0 g" c2 n# ?
/* request auto detection */
- [) e( A9 q: J5 rint gdriver = DETECT, gmode, errorcode;
8 \: n/ k/ q$ N' ]( ^# c& zint x, y; </FONT></P>1 n. L! G$ t3 F, I$ D6 @0 j# X7 T
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; n6 i6 ~& P/ c# n4 j5 \9 uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, S5 S$ S, {- v+ R" l<P><FONT color=#0000ff>/* read result of initialization */
2 y, q2 \' p# T2 O# Z7 o; Lerrorcode = graphresult(); * j- h$ ?+ E: B+ p
if (errorcode != grOk) /* an error occurred */
  U, I: g% V  L) Q{ 1 G' I7 E2 b# [' Z2 I0 @! j
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 \6 B3 ]! e' ?/ y! D: z
printf("Press any key to halt:"); 8 I, {8 x0 n/ y: H3 a8 A7 ]
getch(); % K: z5 R/ W9 B$ C: Y: b+ k
exit(1); /* terminate with an error code */
5 f: N; m8 c; F1 {& w) b! O} </FONT></P>/ ?7 V8 ^/ k) b) @- t/ s
<P><FONT color=#0000ff>x = getmaxx() / 2;
: w- z  H2 [- K0 Y8 |; [, p3 Q5 _# ?y = getmaxy() / 2; </FONT></P># y( T! n- k6 A* y) ~; ]
<P><FONT color=#0000ff>/* output a message */ 5 P9 d% V" l6 m* _% c- L
settextjustify(CENTER_TEXT, CENTER_TEXT); ( Y1 A' }) Y7 f# U
outtextxy(x, y, "Press any key to exit graphics:"); , h- d) r7 G6 K* Y
getch(); </FONT></P>( r( D$ L" r) r; s7 A7 X
<P><FONT color=#0000ff>/* restore system to text mode */
7 D4 o* S. H2 a' n. i" g  L; qrestorecrtmode();
7 @. G# g9 x$ g1 }5 bprintf("We're now in text mode.\n"); # |. e+ T. n4 E7 W5 B. a7 K! s
printf("Press any key to return to graphics mode:"); + ?# d& r# \- A
getch(); </FONT></P>
, J& K  e# T/ Z1 Z/ f) i<P><FONT color=#0000ff>/* return to graphics mode */ ! x$ Z2 h% q" C) q2 l: k
setgraphmode(getgraphmode()); </FONT></P>/ ^  c  v2 }# \( ~
<P><FONT color=#0000ff>/* output a message */   s& V. q- s8 _( N' `$ X; x
settextjustify(CENTER_TEXT, CENTER_TEXT); 1 j4 e; m& a6 p: u) L
outtextxy(x, y, "We're back in graphics mode."); 1 m) }9 a" M* G- b. H1 h& N
outtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>1 v2 `/ |  G+ K* V( v6 L
<P><FONT color=#0000ff>/* clean up */ ) w+ h: s  U2 A/ w8 E8 l
getch();
! z0 f. {' h" P' i' _closegraph(); 9 T: d# ^) a' T; V; ]
return 0; % q3 @! j: w$ W5 r
}
+ T7 p* K* ^' I5 r* _" `/ e3 d1 g. E
5 ]- }0 b1 ^. ?" e% ^) f
</FONT><FONT color=#ff0000></FONT></P>* S& k/ ]' N$ O& H1 r- J
<P><FONT color=#ff0000>函数名: setjmp </FONT>7 \& b. z- n4 H2 R! D
功 能: 非局部转移
( |- i! g7 p' D  {用 法: int setjmp(jmp_buf env); - s; m7 H  C+ i# N* D/ d
程序例: </P>
1 I, O* N! U0 h<P><FONT color=#0000ff>#include <STDIO.H>9 Y5 j- j' J# `* g
#include <PROCESS.H>2 U, P, N4 k& }: H4 `- D
#include <SETJMP.H></FONT></P>
, \1 x; ~4 n- ]5 n% J# d0 D<P><FONT color=#0000ff>void subroutine(void); </FONT></P>  k# [8 w+ j% G, v: Z7 r9 F7 K
<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>
1 M: q3 J% W2 n! z<P><FONT color=#0000ff>int main(void)
1 |. V- j9 v  x{ ( Z6 m" A# |( w& i& L$ m; `6 P
int value; </FONT></P>
) R% s7 z' `, p$ k# H<P><FONT color=#0000ff>value = setjmp(jumper); + d0 N" }0 e+ h& y! x5 ]# D2 N6 E0 @
if (value != 0)
% J9 J  Q2 B/ S! v+ |; r  h& R{ " s3 a! [3 Y( f1 V
printf("Longjmp with value %d\n", value);
! q" G, J7 S7 o6 m1 F8 mexit(value);
0 O& ~/ h* H; w% a: X0 N! l}
& \: p( i" T2 A' |! C# W/ cprintf("About to call subroutine ... \n");
/ U" d5 l6 F# F# N1 S) ksubroutine();
9 t( x7 w& [4 i) Z8 Freturn 0;
4 F( U) F# L) j& n" X$ e3 E- V} </FONT></P>- \5 d  k4 Y; Y. k" @
<P><FONT color=#0000ff>void subroutine(void)
. Q0 h) \- K" {3 n  x{ $ {! G# _/ m. l
longjmp(jumper,1);
6 E# K/ r% \7 g% j$ s0 ~% c: @4 ?3 |} - r1 G- I$ k( Z+ T  ?  P. c, E
</FONT>
+ p' s7 D/ T3 l, j" L</P>5 Z: Z; |7 b) e5 T; j8 ?
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
9 E3 @8 }$ N% `% ~) W功 能: 设置当前画线宽度和类型 $ U, \4 n# C2 j7 A6 L7 D+ ~
用 法: void far setlinestyle(int linestype, unsigned upattern); 5 I4 E, c1 r! s+ U7 R5 S, o8 H
程序例: </P>
  z3 @: v; x7 d; a" X0 g% u( ~2 G7 k<P><FONT color=#0000ff>#include <GRAPHICS.H>; K0 e' Y# ~# J, M3 S6 Q+ A# W
#include <STDLIB.H>; z2 x5 C2 P( L' v8 h
#include <STRING.H>
* f' u( o8 E- m, j' }8 Z( A8 N#include <STDIO.H>
* X3 {% l% z4 S: e6 ^& Q5 r#include <CONIO.H></FONT></P>
. q; H! v$ ]. n) G2 w7 d1 q$ ]<P><FONT color=#0000ff>/* the names of the line styles supported */
/ ~. K6 I& D8 N) Kchar *lname[] = {
, n  ~+ S3 \% T4 ~! j"SOLID_LINE", 9 F. {+ h+ T% u2 R' Y
"DOTTED_LINE", 5 T! t9 }3 \3 w6 f& f5 [- Y
"CENTER_LINE",
8 R1 c% l0 h0 b( \  T"DASHED_LINE",
$ R0 {6 u% @, ^; |* U7 h) L"USERBIT_LINE" 0 V" _3 |1 Q) L
}; </FONT></P>
+ ~/ n% w* h6 x1 g" f<P><FONT color=#0000ff>int main(void) 4 H( T5 V* D& [8 g1 p* v" t
{ + u% v, V% ], a! Z2 A4 Z8 O* u
/* request auto detection */ 6 ^2 L4 h$ F' y2 F5 l0 O
int gdriver = DETECT, gmode, errorcode; </FONT></P>
" `/ R% X: V. d0 y7 }) p<P><FONT color=#0000ff>int style, midx, midy, userpat;
8 J- W8 a/ [* c) I7 Mchar stylestr[40]; </FONT></P>5 m: `- i* t. a3 o/ L6 X" e
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 Q& ]7 [$ ]  x$ O  S  Y( ?
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ G4 @2 e* P# E
<P><FONT color=#0000ff>/* read result of initialization */
  p! b- I3 k. r' Qerrorcode = graphresult();
0 a4 r& [: S2 k/ c8 Kif (errorcode != grOk) /* an error occurred */
6 F9 z% v& P2 N{
3 t! I+ ^! b6 W: n. Oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 ~, u1 q- O7 ^% _0 B' z2 d
printf("Press any key to halt:");
+ q8 ~( W  ^7 j/ U( q3 Rgetch();
% N1 c$ @- V5 {# P/ ~0 A- i( Aexit(1); /* terminate with an error code */
/ b6 t9 ?1 B3 ^7 h} </FONT></P>
. i8 K" u1 T: Z, ^/ c8 A<P><FONT color=#0000ff>midx = getmaxx() / 2; ! p: w( P$ H" Z  Z% e( p, W* q
midy = getmaxy() / 2; </FONT></P>
* f# E- g- N. v, X& L& p  K<P><FONT color=#0000ff>/* a user defined line pattern */
; ?# Q# d7 g8 Y/* binary: "0000000000000001" */
( o) r8 L* w3 _4 `userpat = 1; </FONT></P>
$ C1 q3 E4 `3 H+ B/ q<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
7 Q- ^3 o- ~0 ?* T# k4 `{
. ]5 @# X1 k* K9 E9 u7 L/* select the line style */
9 r7 J' ~8 A$ ^2 K  Esetlinestyle(style, userpat, 1); </FONT></P>
) b  c2 p7 m( n+ x3 {<P><FONT color=#0000ff>/* convert style into a string */
* z3 I4 G2 R( G, P1 k6 i% D, ?strcpy(stylestr, lname[style]); </FONT></P>+ O4 a! G6 L  O( P! S
<P><FONT color=#0000ff>/* draw a line */
+ J8 ?  O0 F5 g9 W8 @8 R9 j$ gline(0, 0, midx-10, midy); </FONT></P>
6 ?) T, P& v* O4 v$ Y6 b; Q<P><FONT color=#0000ff>/* draw a rectangle */
9 S2 s% x: o, G  k4 d0 C2 krectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
( x$ F" }2 r1 g" G<P><FONT color=#0000ff>/* output a message */ 0 o! ?' j: X2 n; u, z" k0 {  d
outtextxy(midx, midy, stylestr); </FONT></P>
  x* R# b" _) p5 [<P><FONT color=#0000ff>/* wait for a key */
+ A7 f  P' j  q  j; B, T: {getch(); ! |1 }: U: S; k: Z# C
cleardevice(); ! P$ b6 W/ n. O! m* @
} </FONT></P>) B; u$ O% l  `7 R' m3 P
<P><FONT color=#0000ff>/* clean up */
' K8 N' h6 Y  k- Y4 {, k1 m$ Hclosegraph(); 9 s- ], ?: |/ i- _% y
return 0; 5 O) S* d7 N- ?, R0 @
} </FONT>
. `  _; Y5 C1 \$ n. E5 n( O9 m6 d
3 n, y$ i; P1 l; ^. s/ |* {9 M/ s% _
</P>
0 u9 g' a! F, I6 M, ?<P><FONT color=#ff0000>函数名: setmem </FONT>
& B2 ^# v+ o/ }  {- w* N9 N功 能: 存值到存储区
3 i8 W2 e. K3 g6 G$ [用 法: void setmem(void *addr, int len, char value); ) g: A' }* U& ]7 A8 L4 i% k
程序例: </P>6 G0 P) a; }6 f" O
<P><FONT color=#0000ff>#include <STDIO.H>7 U2 s& M1 o* l
#include <ALLOC.H>* p7 f8 E( j3 ?& S$ M
#include <MEM.H></FONT></P>( Q6 D6 e( I! R
<P><FONT color=#0000ff>int main(void)
4 I  P: d8 g6 }1 Q! ]& e{
; s! p7 j% `' B2 ]# B- U! Echar *dest; </FONT></P>
/ }1 q' ]$ p# Z2 u9 F2 j* J2 U<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
9 p6 J) U4 D9 _3 [4 hsetmem(dest, 20, 'c'); ' `3 B8 {- @$ @. l
printf("%s\n", dest); </FONT></P>
& E" i9 u$ ~: \: x1 U<P><FONT color=#0000ff>return 0; ( E1 j) Z$ G. \, X
} </FONT>4 C/ C/ V$ l: E# o

$ `* x  ^2 ^, L2 X) y4 v5 j
; |- ]* H1 i/ M</P>4 T$ V# H3 X$ f- q, {5 h
<P><FONT color=#ff0000>函数名: setmode </FONT>
2 o! b1 P: V. U# V3 [' @功 能: 设置打开文件方式
3 E: C. X( Q3 w& y用 法: int setmode(int handle, unsigned mode);
9 ^+ Y4 C3 X8 A1 Q& E5 @" D7 G程序例: </P>% Y/ F6 |! n( Z5 Z
<P><FONT color=#0000ff>#include <STDIO.H>
; r  s- z% K0 {4 o2 D#include <FCNTL.H>
( F+ g2 t  T8 L/ {2 i1 J#include <IO.H></FONT></P>
0 ?2 R, i5 r. o0 z% ?" L<P><FONT color=#0000ff>int main(void)
8 r5 Y8 [* o8 i3 |& z6 d! [* H4 O{ . w( u+ e# l9 C" f& c$ w; u, L
int result; </FONT></P>! ?; i/ n$ t6 X9 C4 B8 ^1 K
<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
9 f: X, J1 U( a5 n: Uif (result == -1) * Q. B! w  P1 @( M$ x+ j
perror("Mode not available\n"); $ ~. S& }5 W1 G0 A
else + ?3 n% l$ k$ }" U: N: q2 L9 u
printf("Mode successfully switched\n");
3 |; Y) u- c. l* G/ Ireturn 0; ' O3 I+ r; r2 t+ o) L
} / Q' N2 S6 R4 K' Y! W  {

; q* A/ ^5 f! A# l9 |</FONT>
$ |& E$ J! A4 {! M3 q</P>! x" |* o1 w" N' i% q
<P><FONT color=#ff0000>函数名: setpalette </FONT>5 q. R& Y3 `2 z# b) J
功 能: 改变调色板的颜色 * f0 t* |  D# c2 s9 {1 A$ C
用 法: void far setpalette(int index, int actural_color);   w1 w3 ^' k! _' [! p$ S' w, Z' ]
程序例: </P>5 R3 \; P& \3 f# p3 m
<P><FONT color=#0000ff>#include <GRAPHICS.H>: P* A7 V1 d+ e, w3 v
#include <STDLIB.H>1 e6 Q: @0 [7 ^7 K. K4 F& }3 k
#include <STDIO.H>
  H! J# Q5 J0 u/ q9 s) _#include <CONIO.H></FONT></P>
) `; \' |! s" K7 C% N5 ?6 s<P><FONT color=#0000ff>int main(void)
8 v: [! h, F! A; T$ j{ : D" M9 t/ \( ?+ C" l# n
/* request auto detection */
1 I8 i' D9 z& N/ {% h& \2 \3 gint gdriver = DETECT, gmode, errorcode;
' Z/ J: `3 o4 q8 J- Rint color, maxcolor, ht;
6 W) X/ ~# B! E1 Nint y = 10; 6 F" }& V  [2 E
char msg[80]; </FONT></P>1 i0 n# b* O: K( M6 `) O
<P><FONT color=#0000ff>/* initialize graphics and local variables */
; ~# m% g  }* einitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% a1 r" t% a3 y) x" M7 D# E, B<P><FONT color=#0000ff>/* read result of initialization */
- {' U/ n% b+ r: n( nerrorcode = graphresult(); / p0 i/ b* m" }) J3 \: k. L5 E3 n, R
if (errorcode != grOk) /* an error occurred */
8 B, ^* o! C9 \{
; U. |% B* F  o& C: F% uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' D) H6 M& Q! [9 [printf("Press any key to halt:");   a* u1 B' k: W/ v
getch(); # b0 N6 f% J- G, R
exit(1); /* terminate with an error code */
- H4 P- ?7 \5 [7 |) P  {} </FONT></P>) `8 k0 a& e" P2 J# {
<P><FONT color=#0000ff>maxcolor = getmaxcolor(); 8 j, o8 C* u9 ~- S  z; B" T! r
ht = 2 * textheight("W"); </FONT></P>
6 U2 r5 D8 w6 B( ~: D) T* z<P><FONT color=#0000ff>/* display the default colors */ ; D7 O9 q$ \3 R* }& N
for (color=1; color&lt;=maxcolor; color++) 8 a4 p- N1 ^% j; q
{
0 T$ n" @) G* ], e8 Q: ?  x5 ~setcolor(color);
8 u1 F' O5 o- X% [' D  ysprintf(msg, "Color: %d", color); " {0 i6 h8 P7 V% M
outtextxy(1, y, msg);
4 B$ I$ B' K$ x+ ty += ht; ' L# N7 [% ~! ~0 f) U& a
} </FONT></P>) D# ?3 F* G8 A: F# C1 [
<P><FONT color=#0000ff>/* wait for a key */
/ ^2 `5 ?7 n5 @4 K( j# Q: z6 u( ^: ygetch(); </FONT></P>
: C% j  t  F6 `5 t$ _<P><FONT color=#0000ff>/* black out the colors one by one */
9 Q" v, K' H/ p6 z% ^: yfor (color=1; color&lt;=maxcolor; color++) 1 g% h. j1 {5 I  g; V/ b+ T
{ * X3 o$ t- a% I& q" o; [
setpalette(color, BLACK); 9 v) M' a0 T; d' {; q
getch();
4 r# P0 b! \- L4 |4 V4 |+ k" `} </FONT></P>! e9 O; k: s, V. ]
<P><FONT color=#0000ff>/* clean up */
$ s9 b9 J; j' v9 {, H! b9 T: sclosegraph();
* v& t$ q3 j( w3 j! ~9 Ureturn 0;
7 q* a+ X) j0 b8 S! Z} + y  t" A2 s5 k' S9 O
</FONT>. @  f! ]8 |: Z  x$ ]
</P>$ }! H8 z) d; V& }7 {/ L# B
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
: Q& ]7 g- N, z: M1 n* m功 能: 定义IBM8514图形卡的颜色
" ^4 _! f9 q. j3 A# D6 ^用 法: void far setrgbpalette(int colornum, int red, int green, int blue); : N, x8 |. B5 w
程序例: </P>
  A: t) \) d+ V% _<P><FONT color=#0000ff>#include <GRAPHICS.H>- I% W/ [6 i5 J7 b
#include <STDLIB.H>
; c0 e4 O$ G% q4 z#include <STDIO.H>
0 s) R, `4 s( B5 w8 z" I  }7 Y  U#include <CONIO.H></FONT></P>$ e3 p- K% @# H0 z, t& ^
<P><FONT color=#0000ff>int main(void)
  M3 O: g0 u& g6 `" U" j; W{
* T( w! l8 T0 D" f1 E/* select a driver and mode that supports the use */ # o1 ?! p' q! E/ t
/* of the setrgbpalette function. */ ' B7 T/ I, [- K" ?+ c% b
int gdriver = VGA, gmode = VGAHI, errorcode;
5 t) b& a' b! Y1 V, zstruct palettetype pal;
! j  M) H8 }8 {/ ?. ^/ z* [0 fint i, ht, y, xmax; </FONT></P>
- Q( H& g5 Q6 D<P><FONT color=#0000ff>/* initialize graphics and local variables */
# C8 o+ f8 ~' w9 S, C- Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># M, [$ K. f6 e
<P><FONT color=#0000ff>/* read result of initialization */
0 v9 t, b. D  d. xerrorcode = graphresult(); % Q8 m$ J4 G  Y- D. g
if (errorcode != grOk) /* an error occurred */
2 z3 _+ K% v  y; u: _2 k+ E{ ; [4 p" \2 v, v- I" z. s
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 [- G) @) _3 M7 O) n7 x% J6 l( nprintf("Press any key to halt:");
: V& {: I9 \' V2 I0 x$ ngetch(); 6 T% L$ L& V0 A2 ~
exit(1); /* terminate with an error code */
, w# J" I" {5 _. C- ]} </FONT></P>
/ |$ }' b2 i" D, u<P><FONT color=#0000ff>/* grab a copy of the palette */
/ p1 Q2 ^6 C, G0 Mgetpalette(&amp;pal); </FONT></P>
9 z( X6 Y5 P+ V<P><FONT color=#0000ff>/* create gray scale */
3 q6 R9 B# w3 W8 _2 Gfor (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
- X! }1 h3 K" B2 D% E# e9 z1 l<P><FONT color=#0000ff>/* display the gray scale */ ! M- l9 i2 C$ S3 q+ J3 Y
ht = getmaxy() / 16;   u  E# g3 P0 J
xmax = getmaxx();
& z0 Z, m* v' N3 Dy = 0;
! Y6 c! r. t2 J+ Hfor (i=0; i<PAL.SIZE; <br i++)> {
9 B! @8 v# x  I/ fsetfillstyle(SOLID_FILL, i);
7 ]8 U0 F, O6 e; O4 o2 E7 Mbar(0, y, xmax, y+ht); ) r8 V1 e( r1 \6 [
y += ht;
: q/ Q+ ?( |' r+ v} </FONT></P>
" D3 p7 J! r8 t" L7 x# e4 q. q<P><FONT color=#0000ff>/* clean up */
8 N# b5 |% S+ q$ o, T2 Mgetch(); ) U1 H9 D0 I* b" [0 a( D' h- Y
closegraph(); 2 W- ^3 r0 N6 l, z
return 0; - R$ w% ~; k* A8 Q- b# u
}
* o- q+ k/ i6 _/ r</FONT>% Q& R& W+ Y- {. L4 w
7 m3 N$ l+ P; h7 R5 N
</P>
5 l1 F# D/ t5 O& ]<P><FONT color=#ff0000>函数名: settextjustify </FONT>
3 ~. I- D5 U4 P' I7 @功 能: 为图形函数设置文本的对齐方式 : v, l$ G/ o: c! [5 }9 }: {, B
用 法: void far settextjustify(int horiz, int vert); , R9 j1 R7 {+ E+ H0 X& P* T$ Y
程序例: </P>  V. l+ |% s4 r, Y$ g, Z
<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 Z& Y" f! q) d7 a8 K  v3 M#include <STDLIB.H>
, H9 Q- Y* m4 r9 U8 K- N1 }#include <STDIO.H>
6 M0 Q4 `: |8 O% S+ d- V#include <CONIO.H></FONT></P>
& I- O1 Q. ?, ~7 _  z8 m5 ~<P><FONT color=#0000ff>/* function prototype */
; P4 H6 N' }& o4 J' R. fvoid xat(int x, int y); </FONT></P>
  k1 z% S6 E" ~& s7 `5 d  _<P><FONT color=#0000ff>/* horizontal text justification settings */
) q/ Z6 {9 `7 J1 W' W  }* fchar *hjust[] = { "LEFT_TEXT", : n2 x' g7 m" g4 X4 v) u
"CENTER_TEXT",
8 d. }4 f) j- i* f/ u2 v5 j4 r"RIGHT_TEXT"
2 z0 m0 K6 t! K( K# S, ?! g}; </FONT></P>2 i0 t' A; ^9 i! d; Z
<P><FONT color=#0000ff>/* vertical text justification settings */
2 z* c6 F8 e" P# xchar *vjust[] = { "LEFT_TEXT",
5 y3 o: r- o1 E+ ~+ x"CENTER_TEXT", , {2 {9 k- A& ^$ i; B% }
"RIGHT_TEXT" ( D- }& P+ W0 R6 x" _
}; </FONT></P>
# ?) K) ?; b1 @! p6 u  J. n<P><FONT color=#0000ff>int main(void) 6 @, X( C. v& R% A5 ]" T; h9 K
{
9 Y! C$ S# b' Y) w/* request auto detection */
& l1 y1 [& W$ Z7 wint gdriver = DETECT, gmode, errorcode;
/ w* ?. O# ^1 bint midx, midy, hj, vj; / c% m5 H9 i) ?( Y; u
char msg[80]; </FONT></P>
9 g4 b. ]9 x# ?5 @: J<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 |- |. \) |" A7 A' Q5 q+ Pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># J& C3 U8 G) Z) g5 ^) ^
<P><FONT color=#0000ff>/* read result of initialization */
; z+ ^3 C' P- |8 Ferrorcode = graphresult();
) g# |+ J  [6 N  K' R, d% ^if (errorcode != grOk) /* an error occurred */ ; K/ m) H: r% a: K+ X
{
6 G$ }1 g5 Y; u2 W* ~printf("Graphics error: %s\n", grapherrormsg(errorcode));   e, P5 x" h/ L6 K) [
printf("Press any key to halt:"); " ?3 c  |- X2 H% Q  h; E% K
getch(); 3 [4 y; u( y7 z3 G. n& B
exit(1); /* terminate with an error code */
& O9 U$ K9 g# _! _1 _} </FONT></P>
! [1 M1 g8 m3 g<P><FONT color=#0000ff>midx = getmaxx() / 2;
! w" h$ m. u; h" O4 W9 Vmidy = getmaxy() / 2; </FONT></P>( z) [" L8 q& E0 I( \9 [
<P><FONT color=#0000ff>/* loop through text justifications */ ; w( d: g9 [% R% X; F( [: b' {! Q
for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
. S$ |- Y8 u- Nfor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++) 4 L, o7 m6 g6 P3 C- R! A
{ . m% ^# c1 _1 v1 Q
cleardevice(); . F/ r$ u$ p# C/ G! D3 `
/* set the text justification */ 5 y+ n( M" P, B& z
settextjustify(hj, vj); </FONT></P>
( r) K# z' A! Z/ x0 i, \) ^0 C5 }<P><FONT color=#0000ff>/* create a message string */
6 V' t  e) M) D6 j7 a$ {5 Nsprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>6 F9 S& |' e1 T: N
<P><FONT color=#0000ff>/* create cross hairs on the screen */
6 [- {  e- t9 |7 g( Uxat(midx, midy); </FONT></P># L; f' f, F( H; z! ?4 ^" ]
<P><FONT color=#0000ff>/* output the message */ ' z1 `, j/ |% Q. j! u# m
outtextxy(midx, midy, msg);
, z4 q& N7 a3 U+ ]0 ]getch(); $ ]4 {, t0 J3 S2 I0 `/ H4 t
} </FONT></P>
8 z6 z9 j+ h8 k<P><FONT color=#0000ff>/* clean up */ 8 ~4 i# u1 s: m3 Y
closegraph();
0 U& {# \8 H" m0 Q7 Hreturn 0; . t* c- N4 J4 D  e. f
} </FONT></P>
" T" L5 o0 v( @' _' I5 N. q<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
& ?4 t- t- d+ K% q+ E1 y. S+ ivoid xat(int x, int y) * d* m/ I$ P6 F1 R$ W  q# t
{ 8 k( U$ y* S. k
line(x-4, y, x+4, y);
/ m# b) I8 u% T" qline(x, y-4, x, y+4);
$ _. t( r. @4 u} </FONT>0 Y6 }& b0 Y) f, G
2 q$ a% X2 N) ?1 J7 ^
</P>
" l1 G9 y% Y" i* Y  W7 q<P><FONT color=#ff0000>函数名: settextstyle </FONT>
& I/ G1 D' b! S功 能: 为图形输出设置当前的文本属性 / B# {& u$ `; ]# U; g
用 法: void far settextstyle (int font, int direction, char size);
5 m/ F* v& F* y- M# E程序例: </P>- S* I, p  H! B2 m, m/ o6 k% h. D
<P><FONT color=#0000ff>#include <GRAPHICS.H>  h/ ]/ s3 p+ @9 t
#include <STDLIB.H>
' U0 X. C% x& Q( u" M/ g6 G#include <STDIO.H>$ c  q, \6 S  l8 \# ^4 |; `+ r
#include <CONIO.H></FONT></P>
5 }% w& u/ z( |; a2 D<P><FONT color=#0000ff>/* the names of the text styles supported */ 8 o: u$ j" y0 s  ?) y. B
char *fname[] = { "DEFAULT font", % }7 b. r: ?) X* d. C( w
"TRIPLEX font", 6 m6 U* H( Q/ y" ~
"SMALL font",
) J2 F' F# R" N# D- K& H! z"SANS SERIF font",
% e" }) j. d* \0 l. c! ?7 M"GOTHIC font"
/ }8 X- B4 ^- @( I. ?}; </FONT></P>
  X4 s. t# B" k  P( e9 m<P><FONT color=#0000ff>int main(void)
  p# K, L$ L* j; J2 `2 Z. S. [4 w{
1 O* K& j! Z# b8 e5 r0 h1 E2 {/* request auto detection */
) l* H- s, X  c* V5 D7 ^* Q0 aint gdriver = DETECT, gmode, errorcode; ' X& S$ ?0 d0 N) Y; r; U& X" M$ B
int style, midx, midy; & }& ^2 O' b, }- A
int size = 1; </FONT></P>
1 z4 D: G" b, i0 O( [7 t0 f% z<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 i" E" Y! X& [4 k! }* q% ~, ?initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 l( {' j( q# b, {0 o3 y<P><FONT color=#0000ff>/* read result of initialization */ ; n; s' [- q; M1 E2 e) G
errorcode = graphresult(); / Z, R- T, i, [8 f. {/ M! y
if (errorcode != grOk) /* an error occurred */ " m! ^1 i! d) u. G5 o
{ % p9 |" d+ q8 e+ W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; ~, L+ F9 M3 q, s2 f$ K
printf("Press any key to halt:");
9 q& I6 P" x1 v9 @5 J) Zgetch();
' v3 ?2 t% U& N  A" {$ s4 Dexit(1); /* terminate with an error code */ / `5 p! o0 F' Y% [
} </FONT></P>
8 l+ U9 ~3 K; V3 y9 g<P><FONT color=#0000ff>midx = getmaxx() / 2;
6 J& R5 I2 M4 e1 v4 V# I. Pmidy = getmaxy() / 2; </FONT></P>
' J8 k7 O  B8 @/ H6 o% \% o<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>) D( h, E3 d: J& n, ~# }# U
<P><FONT color=#0000ff>/* loop through the available text styles */ 1 F) A% l# k+ E0 n. x. P. U0 E
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 9 M5 }6 R  h9 O& p
{
% ]$ U& p& k- D) z2 Mcleardevice();
" {: D4 d1 s- I. ^2 vif (style == TRIPLEX_FONT)
6 U9 x+ h2 ?3 Q: _5 E5 Ksize = 4; </FONT></P># J5 r8 {2 q$ i+ P8 C2 D- P
<P><FONT color=#0000ff>/* select the text style */
+ g: n+ N* s# ]+ \& `settextstyle(style, HORIZ_DIR, size); </FONT></P>0 z" a" T4 w; H( H1 }
<P><FONT color=#0000ff>/* output a message */ 8 L1 z) k! w$ E
outtextxy(midx, midy, fname[style]); 2 L9 A& f" N$ M3 L  I
getch(); 9 B+ u+ R$ `' \) M
} </FONT></P>- s7 g9 Q6 ]0 d
<P><FONT color=#0000ff>/* clean up */ ' X! j" ^; p! O0 F
closegraph(); ( ~3 ?6 ~) a+ ~; X! R, P1 B
return 0; # `0 V1 V  S2 q% F. I- }7 Z5 D
}
  t. I* I& d& ]5 @7 Z6 |0 r1 ~0 M1 r</FONT>9 d3 V! y  A6 ^7 f0 o! H8 Q+ b
</P>
7 b$ ^1 W; @0 m<P><FONT color=#ff0000>函数名: settextstyle </FONT>
% z- I$ m7 i1 H功 能: 为图形输出设置当前的文本属性
' Z% O" w2 C9 k) y& N8 i/ T用 法: void far settextstyle (int font, int direction, char size);
8 X: g5 ?2 C* F7 I程序例: </P>
) o* Q6 ^' t6 X/ W. d; |+ V<P><FONT color=#0000ff>#include <GRAPHICS.H>, F& G) O0 w5 u* J, K
#include <STDLIB.H>
4 B( ~% a- H: e. a" y3 }: B( o#include <STDIO.H>
$ G* `/ [# a- w#include <CONIO.H></FONT></P>
& O+ v9 O) h/ ?9 h. H1 }<P><FONT color=#0000ff>/* the names of the text styles supported */
+ p8 v2 A9 m. t& i" G) T7 `: kchar *fname[] = { "DEFAULT font",
' E. c# N2 l1 C1 E1 S# c, p"TRIPLEX font",   M7 c9 K( n$ a# L4 X0 A: [  o; E/ R
"SMALL font", 3 t2 u1 m# I! F# b: M7 c  e7 a/ l% _
"SANS SERIF font",
) A# }8 ~. C: `' M9 V! Z"GOTHIC font" # V/ R& o" e& h
}; </FONT></P>
& g+ S% i: U9 n# |' ~<P><FONT color=#0000ff>int main(void)
) z* ~3 g! S5 F% y+ q/ H5 R% J& ~{
' E! K8 u# Q- \2 u/* request auto detection */ # p! I% u9 K' A4 d( Z9 r
int gdriver = DETECT, gmode, errorcode; * X: r. I  P7 o
int style, midx, midy; % j  f( r. k5 f" |/ ~; n
int size = 1; </FONT></P>
- }) t0 `; y8 T& [5 e$ d- K<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 N, Z3 [9 h5 y1 P) S* Q. ?
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 B6 Q! r% M( ^) X
<P><FONT color=#0000ff>/* read result of initialization */ 5 C# g5 y1 M  Y3 x! T
errorcode = graphresult();
- i5 T4 x- z$ v9 v1 ]$ O$ aif (errorcode != grOk) /* an error occurred */
- |4 A5 y8 v0 U" v{ 9 l) B, j6 N/ H/ g, I$ K' a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* @6 b3 x% C8 @+ N) o/ x5 kprintf("Press any key to halt:");
# i8 W' r" n- I, ogetch();
9 D2 p' d% O8 O, U7 ^exit(1); /* terminate with an error code */ # e$ s2 C( y+ A+ J# }5 o
} </FONT></P>/ _. x7 g! B5 N$ ~8 _" a/ H" b
<P><FONT color=#0000ff>midx = getmaxx() / 2;
, `& L6 U  p/ o0 }7 cmidy = getmaxy() / 2; </FONT></P>) T1 l2 T, A0 u8 u
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>. H3 g) ?& ~$ Z9 U( r
<P><FONT color=#0000ff>/* loop through the available text styles */
4 l' k4 g$ l! }+ |for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) ( N5 k, ^' O7 ], J8 D8 m
{ # D9 I- z8 D. \9 b, r5 K# t. J
cleardevice();
  ?1 v9 z( h! J6 c) V- ~if (style == TRIPLEX_FONT) 5 o4 s5 V; w  P* f* }9 _  s
size = 4; </FONT></P>
) M3 c3 \! K8 S1 k<P><FONT color=#0000ff>/* select the text style */ ! |' Q, k4 S! B* ]) A( S9 z$ O
settextstyle(style, HORIZ_DIR, size); </FONT></P>
  c8 a5 O* V" s" H<P><FONT color=#0000ff>/* output a message */
7 m. w  ^! u1 v0 o5 d2 \- iouttextxy(midx, midy, fname[style]); # r2 N. Q$ }6 C
getch();
- u  U* {& s' b  z} </FONT></P>
+ w! w( y0 w, n& e<P><FONT color=#0000ff>/* clean up */ % e7 B: {* y& L
closegraph();
' i8 S4 }! F# kreturn 0;
5 ?) v6 p6 c7 ^" T/ ?7 e; L! b! H} </FONT>9 c6 X0 q; ]  d! S  ?/ j- U
0 }  U5 e8 M/ Q! }( \% E* a
</P>
& k  p- ?7 D! I! V% E9 o3 s<P><FONT color=#ff0000>函数名: settime </FONT>$ P. P6 a9 [+ U( W1 T' ?) y
功 能: 设置系统时间 : Q: f4 w. [+ u. K' f0 u9 N' e
用 法: void settime(struct time *timep);
. e* H/ Y) \3 n1 }  r! l程序例: </P>
) q0 P- r( M9 H9 h/ I) Q/ ^<P><FONT color=#0000ff>#include <STDIO.H>8 n" Z! r1 e( l; f( C9 i' P
#include <DOS.H></FONT></P>
6 q1 H; _6 y$ l( {; j* a<P><FONT color=#0000ff>int main(void) 3 g0 e" e' P! |
{ ! f, {$ |' g" n. f6 D/ |5 c/ u) ]
struct time t; </FONT></P>
& L: ]2 j" D; g% v( o  S<P><FONT color=#0000ff>gettime(&amp;t);
5 c) R* k& B' }printf("The current minute is: %d\n", t.ti_min);
7 j; c6 L6 E; W) B* c% m( [- k+ mprintf("The current hour is: %d\n", t.ti_hour);
+ g0 a- Z7 f% V# C6 @3 |printf("The current hundredth of a second is: %d\n", t.ti_hund); . E! r1 {& l0 b4 \
printf("The current second is: %d\n", t.ti_sec); </FONT></P>% f: ^: a* ~3 H, U5 [$ K& k& o
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */ 6 S' z8 x! }* Z6 ?( F& a+ y
t.ti_min++; 9 W& M" B- u6 K. o1 v
settime(&amp;t); </FONT></P>
, W, z8 O+ G' M9 ]3 I<P><FONT color=#0000ff>return 0;
, L. J9 `8 P5 G6 |. |' o' }" t4 \} </FONT>
2 z* H6 C4 m% Z; }, M7 h
9 D! @# q3 m) h% x% E</P>
  }/ F! J" b  m+ J. M<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
/ a' R# V1 u% w% i) Y' ]功 能: 为矢量字体改变字符宽度和高度
9 \# N7 V" Y" N6 N' J用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
3 Y! [/ F, i/ [5 ]7 S程序例: </P>/ @) G4 y" O. L  h. ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>; y5 m. }. H5 [: o
#include <STDLIB.H>* E; ^" f0 D8 N  y# b2 U1 Q: _
#include <STDIO.H>
+ F) ]" D* j8 Q8 F7 I5 d2 K#include <CONIO.H></FONT></P>
! y: k" }1 ^2 }% @4 V9 p/ v<P><FONT color=#0000ff>int main(void)
+ M' A6 A" T. V: @3 V# a% N- c1 k, H{ 9 m+ ]  Q7 b( |% c& s0 k4 K
/* request autodetection */ ) N9 |& c2 Q& U9 d
int gdriver = DETECT, gmode, errorcode; </FONT></P>4 u2 f- F, }& I# M; [2 V' y# M% g
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 |3 X& H# @# P) v$ v2 C! h
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># z$ o9 L, M; Z! B; x4 _
<P><FONT color=#0000ff>/* read result of initialization */ + u( d& g, h0 f$ k, D; X
errorcode = graphresult();
8 Z8 B' y% |- L! mif (errorcode != grOk) /* an error occurred */
$ A& |; P, w& K8 @{ + k* F) u/ I4 l
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 F# m5 g* ~8 n; Q. h8 v+ q
printf("Press any key to halt:");
9 G. d* ?: Y' S) N2 ?getch(); " S5 B; {! O4 C' }- T6 r5 e
exit(1); /* terminate with an error code */ ! X1 P! I1 P4 U1 f! y
} </FONT></P>
+ J3 U9 z# d5 E& F<P><FONT color=#0000ff>/* select a text style */
$ ?5 ]* b& k% v) M% C) Nsettextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
/ {  R1 c( C8 N' B- n<P><FONT color=#0000ff>/* move to the text starting position */ ! }6 N9 [+ r* `4 q8 V, I4 }6 w
moveto(0, getmaxy() / 2); </FONT></P>
, q5 r$ W2 {: n' M: O$ D<P><FONT color=#0000ff>/* output some normal text */ , x8 p4 u# ^& K/ `6 q2 T1 k4 b
outtext("Norm "); </FONT></P>
0 ?- m, A3 ]7 b: t% J7 U<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ + J4 G- T0 Q3 p, T3 [: `
setusercharsize(1, 3, 1, 1); ! U7 @$ Y6 I) `0 g( R3 F
outtext("Short "); </FONT></P>
: E; i" k& j2 x! Y0 Y5 Q7 [; k<P><FONT color=#0000ff>/* make the text 3 times normal width */ ; ]; G: Y* j9 @4 Y: I
setusercharsize(3, 1, 1, 1); # s' {0 a1 ~! }# V7 {' Z3 F
outtext("Wide"); </FONT></P># n: s$ n9 A& H* z% M* s! d- @  ~
<P><FONT color=#0000ff>/* clean up */
  i: ], J9 `6 U$ Jgetch(); 7 e) p/ x+ R7 v: M; z: `, Z
closegraph(); # j# s& V" e; E: v* e
return 0; + Z5 ^" M- l) u& C6 t
} </FONT>1 h5 K7 m* D' L& ]6 D. C6 _+ |
</P>
# u- K! \! g' o1 H% g" q<P><FONT color=#ff0000>函数名: setvbuf </FONT>3 r, K0 K! t! k+ D, r9 v% R- b
功 能: 把缓冲区与流相关 * j6 p9 M  M+ N7 A6 S5 f
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); % Q$ N5 S" ]. _: }; u* M5 c' c& F6 ?
程序例: </P>
% E2 t. u* t' c, c( [6 ]0 I" }. l<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
2 q5 X% Z5 z# `+ h3 e% Q<P><FONT color=#0000ff>int main(void) 1 k1 L8 i: h$ U+ a2 I& n
{ " i- n" R! Q$ p  z4 J( a
FILE *input, *output;
, X- C8 J, C" z5 Q9 ^char bufr[512]; </FONT></P>
0 r8 n$ X$ u6 H) Q/ T% m1 ^<P><FONT color=#0000ff>input = fopen("file.in", "r+b"); : A% B" f; C9 J) k5 z. p6 v
output = fopen("file.out", "w"); </FONT></P>+ B- p' o* X5 s2 v1 K
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,
7 V3 x$ r5 ]7 x; p6 I/ C6 ^2 v& wusing our own character buffer */ . m" R6 P* k; X. g; D% w0 h
if (setvbuf(input, bufr, _IOFBF, 512) != 0)
6 W4 ]- [" M& i) [' k/ dprintf("failed to set up buffer for input file\n"); 0 y& Z2 O- n" s' j  ~3 U( M
else
8 p, O( @  x9 Q9 Eprintf("buffer set up for input file\n"); </FONT></P>! w4 U* C7 W) D2 d5 a" G6 j
<P><FONT color=#0000ff>/* set up output stream for line buffering using space that   I  K) U) f. r
will be obtained through an indirect call to malloc */ 9 r: I, g$ R" ?  S: o( s
if (setvbuf(output, NULL, _IOLBF, 132) != 0)
, r  w- O9 v% q& ]6 vprintf("failed to set up buffer for output file\n");
) H( p* c( Q" qelse 5 _: s  h0 x5 z" U% s
printf("buffer set up for output file\n"); </FONT></P>
4 n  y" j" n9 e<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>8 f* c) v9 b) `' s- q- m* T# v# V* Q
<P><FONT color=#0000ff>/* close files */ $ |- n4 G! W  J- u0 R/ v; z
fclose(input); 3 }4 E( Q& V2 o2 A# M# L) W
fclose(output);
8 p8 T, C3 D! `1 t; @return 0; 2 J1 D* e+ m) b/ t
}
: p- N( Y( C9 V</FONT>
4 i: C/ h, X0 S* U, a/ O$ S
# v1 c1 ^0 G% ^" H: B/ A+ E+ `, T</P>0 q: n* q" [$ p6 n% r$ H7 _
<P><FONT color=#ff0000>函数名: setvect </FONT>
6 D% a2 w- @0 c3 M/ F2 r功 能: 设置中断矢量入口 : y- y( ?  y1 m: H0 y' V
用 法: void setvect(int intr_num, void interrupt(*isr)()); 7 u; \2 ?6 s1 ^3 m0 [
程序例: </P>
: G$ b1 t' h& S$ Y<P><FONT color=#0000ff>/***NOTE: 2 e# Y/ P4 K: _7 I2 H6 F
This is an interrupt service routine. You can NOT compile this   _# E- J( p7 S/ i) _
program with Test Stack Overflow turned on and get an executable / \# L. z' K6 e+ W: K9 m) o2 z
file which will operate correctly. */ </FONT></P>
2 G. `' o$ I, U3 `+ [3 C( `<P><FONT color=#0000ff>#include <STDIO.H>% o# z+ E  V  V! m
#include <DOS.H>1 a) f2 ?& L, O/ }" R+ Z$ r% R
#include <CONIO.H></FONT></P>
$ W) Y- p4 Q& W1 t- s8 Q% k<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>3 y. S( P  c) u! g
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>6 a) W( B. X0 t+ {+ H$ n
<P><FONT color=#0000ff>int count=0; </FONT></P>
: V3 Z; V3 w% X<P><FONT color=#0000ff>void interrupt handler(void)
- w, ~" V; d! q7 ~- _: \{ 5 R3 Q4 C- z$ @# L1 |" Q$ e
/* increase the global counter */
5 I/ X) H* @5 V( Q, j$ h1 P& R8 Gcount++; </FONT></P>9 \& P$ ?8 e( q
<P><FONT color=#0000ff>/* call the old routine */ 6 q, \' P5 r+ R4 A
oldhandler();   f) f1 ?# [$ U! @+ @' Y3 I" ~
} </FONT></P>; ~" c& r0 U/ J$ B9 D
<P><FONT color=#0000ff>int main(void)
/ n3 V" Y0 d2 I4 S/ |9 y& ]{ 8 x. Y- X  P7 W  W
/* save the old interrupt vector */ $ Y6 u2 N# Z* V+ N
oldhandler = getvect(INTR); </FONT></P>5 H7 [9 {) q$ ?$ W
<P><FONT color=#0000ff>/* install the new interrupt handler */
8 q9 g& _  X$ X4 _setvect(INTR, handler); </FONT></P>& f5 a2 \# b" t' ]5 t
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 0 j, B" g$ I7 {, r: S
while (count &lt; 20)
6 E% ^$ L, W' j9 Oprintf("count is %d\n",count); </FONT></P>) Q) }% w0 u  y
<P><FONT color=#0000ff>/* reset the old interrupt handler */
  Y  K0 P! i, z; {setvect(INTR, oldhandler); </FONT></P>
) L3 b2 b/ \$ Z7 {. R, `<P><FONT color=#0000ff>return 0; 9 P* Q( v$ P  a* @2 j/ [
}
9 o5 y" R# g/ q</FONT>! D1 k0 C  x: X' d& n0 M
</P>
1 n+ P' r  E% U% \<P><FONT color=#ff0000>函数名: setverify </FONT>
5 V# V4 C8 D, j- a$ J, H功 能: 设置验证状态 , A% C; `4 S4 I- T
用 法: void setverify(int value);
2 p, M  O1 q6 F7 W" D程序例: </P>
6 B7 Q' V: q$ P. M; Z' d3 l  T<P><FONT color=#0000ff>#include <STDIO.H>
, g: \* ?. v2 T8 \" h0 v#include <CONIO.H>" m) u# |! t) R
#include <DOS.H></FONT></P>
, o, W0 Q: X. Q; O<P><FONT color=#0000ff>int main(void) 9 u% L& G+ H3 c  R1 n
{ . m7 Q- L7 B/ v) p3 V
int verify_flag; </FONT></P># t3 _1 B( A3 a6 \4 G
<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); 6 f7 K0 r. L" a/ G0 P% z
printf("Enter 1 to set verify flag on\n"); </FONT></P>5 R4 p. N) r+ p0 O0 e
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>! w# W* N5 U8 h* K( z
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>" s# v4 Q! }+ Z- K6 T7 W
<P><FONT color=#0000ff>if (getverify()) 3 b7 c( a1 i7 F( X* M
printf("DOS verify flag is on\n");
% T7 i3 l! R% Nelse
4 c4 P5 J7 ^2 E% o) ]$ Iprintf("DOS verify flag is off\n"); </FONT></P>
+ \; G6 \: H4 n& H' X  n0 H<P><FONT color=#0000ff>return 0;
& u/ {' P6 l3 u/ @2 Z9 a  _}
" s" ]: W6 r5 ]! ?, [) A4 D<FONT color=#ff0000>
6 ~( e. z7 P& d</FONT></FONT></P>
2 B3 i& U* g+ P9 b$ o5 c) r<P><FONT color=#ff0000>函数名: setviewport </FONT>+ x+ g! f, e" c  p
功 能: 为图形输出设置当前视口 3 f3 G* s1 E5 X0 _- B3 h
用 法: void far setviewport(int left, int top, int right, # h' ]! |: m8 n9 Q/ J( l
int bottom, int clipflag);
/ @, s) c7 O2 {' K8 v" E+ O2 E7 @程序例: </P>6 _4 ], K1 H# @- `- |8 Y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, j' n1 A% V: r* Q. B#include <STDLIB.H>+ [* V. g/ w9 y( f' ]- b
#include <STDIO.H>
: H( N/ P6 ?& k4 q' \7 O#include <CONIO.H></FONT></P>
& O8 A3 m2 s1 k8 |) i+ n( b+ ~. N<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
8 E" A& }6 K7 p) v. \6 A<P><FONT color=#0000ff>int main(void)
+ S; N( U+ U% H2 t{ + b, ^3 @) n9 H. e# D" i& e
/* request auto detection */
) V2 J! U4 @" w3 Q& @. {7 {4 a/ Jint gdriver = DETECT, gmode, errorcode; </FONT></P>
2 @3 P+ g- N% S9 B' o  t& w4 B. J& h<P><FONT color=#0000ff>/* initialize graphics and local variables */
: x* g, f6 _& x9 |- B  pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! ?. f, B) N( o$ V- n& u. ~7 a4 I
<P><FONT color=#0000ff>/* read result of initialization */
; ]6 B: N. s! q' D' Nerrorcode = graphresult(); ) T) O6 T3 K) K, D( o9 c1 q# x7 j
if (errorcode != grOk) /* an error occurred */
" u" E4 V: f( I: F1 B; A2 H5 e0 r{ & a6 C% m4 j& a/ v7 k
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( _  v7 ^9 |' r! S6 Uprintf("Press any key to halt:"); 4 H% h) }7 s/ [6 @3 @
getch(); 6 a# X, u  I% x6 o% I- M
exit(1); /* terminate with an error code */ 6 g  _; R: B0 k% P3 |1 s
} </FONT></P>
" }8 T& q6 g8 M4 [9 ]9 ?<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
2 g( r4 R" ~! @<P><FONT color=#0000ff>/* message in default full-screen viewport */ ' h1 i9 H* v" w3 T+ [& q* {' g) _
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>6 U! J, {& E3 P" k2 z1 s
<P><FONT color=#0000ff>/* create a smaller viewport */ # g+ q4 G; v5 p5 \
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
$ E' U8 i) a% G<P><FONT color=#0000ff>/* display some text */
6 y" A+ W( r, I/ i! Eouttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
; f% A$ y- D1 Z1 W' X* J3 j<P><FONT color=#0000ff>/* clean up */
3 V6 h5 F2 M  @2 @7 Y. A4 Egetch();
7 W' X( Z3 D2 C  d% P2 w- Uclosegraph(); 9 |( s1 d! Y% Y$ t4 z
return 0; . R; {5 y) ]$ P% h5 n
}
4 p6 w; L8 G& T% S</FONT>+ S8 B+ U3 B+ q) N7 m5 Q2 F2 ^
</P>
) h* U8 w0 W* X. v5 q. R5 o<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
* \' L; e5 M  `; `1 f3 H功 能: 设置可见图形页号
& O1 J9 F' ?4 c: u4 C, j用 法: void far setvisualpage(int pagenum);
7 r. i8 C+ z3 _程序例: </P>
2 }; d  R$ J; d- n7 b4 `$ ]5 \<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 ^/ R% Y$ C4 m0 L6 z6 N#include <STDLIB.H>; _! w3 s1 G$ W
#include <STDIO.H>
. @  X, r" S0 E+ N1 H: X$ f#include <CONIO.H></FONT></P>2 ?; X3 _# E& V# i! Z
<P><FONT color=#0000ff>int main(void) ! G. q1 @- V3 ^  @8 |8 V
{
( B( ]. @! z! k1 f- G$ ~5 x0 ^/* select a driver and mode that supports */ ' R- h, L- v6 m+ n& N1 o9 l
/* multiple pages. */
+ S8 ]" j4 [$ N% q  R5 Jint gdriver = EGA, gmode = EGAHI, errorcode;
  t/ L3 v" ?! A" s- Kint x, y, ht; </FONT></P>- K% P, J, W0 S7 j  a7 D" `
<P><FONT color=#0000ff>/* initialize graphics and local variables */
  o& t8 T' H" g4 Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 A" q( Q* t7 f. c+ ]$ e. X
<P><FONT color=#0000ff>/* read result of initialization */
) c2 i1 N9 x  @5 ^. }errorcode = graphresult();
/ l( X" N. u5 T) F+ h7 dif (errorcode != grOk) /* an error occurred */ + Z1 Y# ]9 R0 q8 z: w
{
; R7 y, n$ p& Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' e1 W7 R5 j; O1 k- A- q" s
printf("Press any key to halt:"); 6 {* E4 p4 P+ K. `# ]/ _+ H
getch(); 2 B9 |3 T, \5 V% _0 m" O
exit(1); /* terminate with an error code */
, m& ?7 w; Z1 z5 b2 V9 }} </FONT></P>
5 O. X' d, Z4 a0 R<P><FONT color=#0000ff>x = getmaxx() / 2; 9 L3 r' c9 p0 Y7 E) R
y = getmaxy() / 2;
# w$ @* m5 _4 I  V$ I0 s$ k9 \* kht = textheight("W"); </FONT></P>8 S& k; C% i5 v! z9 U" f& m, y# F
<P><FONT color=#0000ff>/* select the off screen page for drawing */ , N0 d, \2 y! v4 {# `" y
setactivepage(1); </FONT></P>
* p/ k$ ~  L: k* ^4 h' Y<P><FONT color=#0000ff>/* draw a line on page #1 */ * h1 t! n5 J) l7 J; ]0 G* m: o# ^
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
* e7 ?8 N' H+ W+ e& E2 M3 h<P><FONT color=#0000ff>/* output a message on page #1 */
$ n$ T6 n: e  F$ p0 X' W* Nsettextjustify(CENTER_TEXT, CENTER_TEXT); ! E# }  v+ Q# h8 Y$ w
outtextxy(x, y, "This is page #1:");
1 `/ i6 z! Y" Zouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
3 @) J! j1 Q- }& W8 e/ B<P><FONT color=#0000ff>/* select drawing to page #0 */
! S8 N/ X0 W! Z8 f5 v3 Esetactivepage(0); </FONT></P>, ]$ G4 P; \% I7 H; }
<P><FONT color=#0000ff>/* output a message on page #0 */
: `3 P! u- M& u& `outtextxy(x, y, "This is page #0."); ) I. W  S& M( _; n3 U. A
outtextxy(x, y+ht, "Press any key to view page #1:"); ) T$ ?. b/ `+ y  v5 E) v6 ?
getch(); </FONT></P>3 W2 K/ d, T; P, d- [0 Q+ Z7 q$ J( A/ U
<P><FONT color=#0000ff>/* select page #1 as the visible page */ * I" k9 a; ]6 c( v. e
setvisualpage(1); </FONT></P>7 f# F/ r) U1 X4 R# h$ B6 U
<P><FONT color=#0000ff>/* clean up */
1 M( B) p7 e/ ?! Dgetch(); 3 n6 g1 o) _3 L! X6 i7 P
closegraph();
7 _% v/ q5 w/ I  [& F: Mreturn 0;
- u2 F3 \3 Q# u& I" h* y! l. K} </FONT>' Y. r+ ?% j2 W; n9 L

$ M; w0 |0 M8 m5 G# E* W</P>0 U! V& L1 K3 h+ z6 }* r
<P><FONT color=#ff0000>函数名: setwritemode </FONT>8 E3 q* ]9 I+ e9 x6 @
功 能: 设置图形方式下画线的输出模式
0 y( ^/ V4 ^$ D7 w, ^用 法: void far setwritemode(int mode); ; F0 \' `5 R$ h
程序例: </P>
9 B  T: d: @2 c4 E<P><FONT color=#0000ff>#include <GRAPHICS.H>
( V# s' V' |6 B- c7 D9 u#include <STDLIB.H>5 C( S; a: v1 T) _5 B8 t: Q( |1 G
#include <STDIO.H>
5 i! P; ^! k! @% o5 x) B- D& g- H#include <CONIO.H></FONT></P>
( q  d  j4 ~( o" A% a% _9 L<P><FONT color=#0000ff>int main()
: |( g9 E, O/ Z$ w; p{ $ P: k: z" U6 @; U' N( w+ d. N
/* request auto detection */
# H8 d1 S* e" @+ U+ q) eint gdriver = DETECT, gmode, errorcode;
' `; U/ D+ {. y  Kint xmax, ymax; </FONT></P>; B3 X; M  E& I2 g4 E
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" a; }# b$ P) c. ?initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ W$ f! l0 f! ~  W! j0 s# F<P><FONT color=#0000ff>/* read result of initialization */
9 L% B1 b: H0 m% ?/ Eerrorcode = graphresult(); + M& h$ @( B! h( ~8 A6 v
if (errorcode != grOk) /* an error occurred */ 4 r. D0 f# O9 Y
{
) L7 F- Y3 P7 O: B0 Kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
7 c& [  C7 Z  X" C9 G$ e% Z$ Cprintf("Press any key to halt:"); $ b0 Z' v& F; B
getch();
$ n. g+ u  ]  {2 pexit(1); /* terminate with an error code */ 9 w2 u1 Y. a( H" R9 u5 U4 S
} </FONT></P>
( W2 K  P+ E3 n; e3 r<P><FONT color=#0000ff>xmax = getmaxx(); ' t/ }/ G6 j- K. Z" M
ymax = getmaxy(); </FONT></P>3 W. |6 `+ s+ ^
<P><FONT color=#0000ff>/* select XOR drawing mode */
( Y1 I8 P/ C5 i+ vsetwritemode(XOR_PUT); </FONT></P>
6 U$ L" |2 @5 }: w( U<P><FONT color=#0000ff>/* draw a line */
% s$ e3 I+ o9 k. {4 y6 I, ^line(0, 0, xmax, ymax); 0 m8 t% i5 f$ y; [* ~( ?# |  [  C
getch(); </FONT></P>3 [' f6 \  c5 T% z) y
<P><FONT color=#0000ff>/* erase the line by drawing over it */
; \6 l5 A( C+ y; D8 H5 F% ~; D' |4 hline(0, 0, xmax, ymax); 7 b8 ?& b; L3 a& @: `* a5 C
getch(); </FONT></P>
0 o- p6 c0 }- b, V$ O, u$ X( e<P><FONT color=#0000ff>/* select overwrite drawing mode */
- t$ G" P! S% Osetwritemode(COPY_PUT); </FONT></P>3 F- Z2 R$ l; X& ~8 }+ Q
<P><FONT color=#0000ff>/* draw a line */
. v8 r4 Y* \0 q* K( \line(0, 0, xmax, ymax); </FONT></P>
# q9 @! H3 d! X* C; J4 s) I<P><FONT color=#0000ff>/* clean up */ ' J7 _; `2 n# }1 N7 h1 y
getch(); # Y3 |) r% s& m1 m$ ^8 j' U3 {  l  y
closegraph(); * i# p/ f' `. f* S4 A7 K
return 0;   R$ `: S* ^# N4 h4 P
}
- R. S- c6 }3 N</FONT>' l/ P8 Y+ n5 a" s1 o5 O; s1 x
</P>: D" T- ^) m  m& }5 }& [4 T2 a2 M7 h
<P><FONT color=#ff0000>函数名: signal</FONT>
. D' U& N1 P$ L) A功 能: 设置某一信号的对应动作
1 m2 \+ [  v) J用 法: int signal(int sig, sigfun fname);
0 y! ]: k/ i/ t3 v: ~: B8 k; F程序例: </P>
1 H) W0 ~7 l" y<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, 9 C$ |: @  k* r( V3 F2 R3 i% z' Z" C
catches an integer overflow condition, makes an adjustment " E  \, @/ \% |
to AX register, and returns. This example program MAY cause * J$ I. q) ^  |$ Q
your computer to crash, and will produce runtime errors
8 n- `& o0 x* U5 [! Kdepending on which memory model is used. 3 C' \1 A3 |5 V4 N8 \. e
*/ </FONT></P>, n5 |# p- q. M- c
<P><FONT color=#0000ff>#pragma inline 0 u& L* {, f6 P& d6 Q! ?4 g
#include <STDIO.H>
- J! w# y/ ^2 a/ S) N1 p# ^#include <SIGNAL.H></FONT></P>/ s( g! L9 S% U& C# b- {  N* I( v
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
' d6 q6 t9 r' g; u% t: P  s{ ( ~5 l( q; {- a4 Y1 j
printf("Caught it!\n");
7 ^6 ]) Z& k0 S9 y! g/ K*(reglist + 8) = 3; /* make return AX = 3 */
* c: j% E! R# |) A2 m} </FONT></P>3 I% K+ G! Q5 Q
<P><FONT color=#0000ff>int main(void)
+ F) M+ W4 @9 B1 S; J. u/ O* B6 V{
8 z! f1 D6 J0 o. T; G7 Psignal(SIGFPE, Catcher);
4 v) K6 J  x, f9 R. b& a! oasm mov ax,07FFFH /* AX = 32767 */
1 P4 f3 F4 \: P( casm inc ax /* cause overflow */
! Y0 Q1 `/ j' V$ s) Y9 Uasm into /* activate handler */ </FONT></P>' h* B- a2 Y3 s: `' T8 V
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened,
$ _' e% g3 F, B( vthere would have been another exception when the next 'into'
5 |5 ~2 J* u4 j' u: I6 _: v0 c9 dwas executed after the 'dec' instruction. */ ( t- L/ ^: d: J* M/ x+ F& z
asm dec ax /* no overflow now */ ' n; g! K6 ]' s5 Q  O
asm into /* doesn't activate */
3 @9 A2 \$ q# m" M+ D; I/ I% b- Wreturn 0; ) F! _$ f: ]( c2 `# o; |% o
} # @; v: S: l4 s6 q! U0 l
9 @6 j$ J+ x! d# R9 }6 C6 F
0 z4 t) k! G6 N) O
</FONT></P>
( o5 T' U3 ?/ `6 w  o8 m2 V<P><FONT color=#ff0000>函数名: sin </FONT>, m1 c3 X/ \& F! ?6 Z$ m
功 能: 正弦函数 : R' U( k6 l: F* L$ L/ }! B# w
用 法: double sin(double x);
4 @4 L! X4 Q  A& f" }/ y程序例: </P>  h7 b! f' \2 e
<P><FONT color=#0000ff>#include <STDIO.H>
8 u; o. p. h5 O; ?. o#include <MATH.H></FONT></P>
1 |$ Y, W7 c& @% V3 m% S' S<P><FONT color=#0000ff>int main(void)
* T/ [" Q+ C# H% X1 y. M& W{ 3 S7 o0 A' v4 r5 O8 o
double result, x = 0.5; </FONT></P>
9 U: s9 h* _) o0 K9 M<P><FONT color=#0000ff>result = sin(x); 9 y9 D, l$ c5 y% Q6 Y1 @2 `
printf("The sin() of %lf is %lf\n", x, result);
5 E" B9 z2 ^) G1 u$ e7 ^return 0;
2 k0 Z3 h5 X& R2 B}
% {" s8 M7 H* b' z. r, l& `
3 k4 i9 d  L# Z6 x4 n% i, j; U</FONT></P>" {; l) W0 Q& V% f- m# U) f
<P><FONT color=#ff0000>函数名: sinh </FONT>
# p  O) N4 J; b5 O1 k% i+ d功 能: 双曲正弦函数 ) _! Y9 j9 h8 m$ X* G0 k+ P8 O
用 法: double sinh(double x); . }) U) r  P4 }4 }9 \
程序例: </P>* b2 P- I( T- S( F
<P><FONT color=#0000ff>#include <STDIO.H>, {; z! ?$ D6 j4 B6 J( E) j
#include <MATH.H></FONT></P>- E: g( u! w( Z1 @( T/ p0 w, x
<P><FONT color=#0000ff>int main(void)
9 v/ Y/ V" r# W" K7 ^8 b- g: `0 T{
/ N, r& x# Z* c. s& q! Hdouble result, x = 0.5; </FONT></P>0 b7 v* L  Y2 N9 }! _; t' u% T& ~; ], R
<P><FONT color=#0000ff>result = sinh(x); " `* ~$ {3 U( I- k: Z$ \
printf("The hyperbolic sin() of %lf is %lf\n", x, result);
1 y# x3 T9 {6 ~& u! U7 B/ l4 treturn 0; ! I" `! N$ S6 t, n9 J. P
}
( B3 _$ l1 ^/ I/ B3 q
4 R! Y! g+ P3 q2 `
/ v, \& y' X! e, B8 r3 R) e</FONT></P>- a! U" C. D! d: \# r
<P><FONT color=#ff0000>函数名: sleep </FONT># @- j* w: h' U$ \# H4 i+ U
功 能: 执行挂起一段时间 " `" ~6 |' e( n+ @, k
用 法: unsigned sleep(unsigned seconds);
1 P' v9 Q- V, Z3 [6 J; U程序例: </P>
$ {- g5 w, k% S, l<P><FONT color=#0000ff>#include <DOS.H>! B) R1 _. m1 d2 a
#include <STDIO.H></FONT></P>6 {& h0 `1 }. [9 v  |& e
<P><FONT color=#0000ff>int main(void) 5 Q9 |& V. ?8 s4 z' o! X
{
- x" P  V2 I* M& v  P2 V2 B. Sint i; </FONT></P>
+ E  P1 V' i7 G2 ~<P><FONT color=#0000ff>for (i=1; i&lt;5; i++) 5 k/ \6 h6 c+ U! g8 C. {# J+ U3 s0 t
{ / r9 L; y; X  H0 n2 F2 Y! ^1 J1 }( X
printf("Sleeping for %d seconds\n", i); 5 e3 u! `& C1 q4 g- O
sleep(i);
- P3 u* D  X0 q/ E. v) D}
5 G8 Q3 x7 Y! L8 f6 z5 ^return 0; . f: z1 @8 T7 g
}
; G- ~' E9 |8 Y5 k* E: W7 |: I8 u
</FONT>8 ^  _) H% Q) s
</P>
. B: l  X9 h8 r2 v4 o<P><FONT color=#ff0000>函数名: sopen </FONT>
& N) E$ @" L0 R: A$ ]: W功 能: 打开一共享文件 . [+ q1 I: d5 y- k0 U7 I
用 法: int sopen(char *pathname, int access, int shflag, int permiss);
& _6 M& g, [9 q程序例: </P>. w* M2 `6 ~8 c
<P><FONT color=#0000ff>#include <IO.H>' o/ J$ o, ^% ?: k' Y; j
#include <FCNTL.H>6 F7 a/ S: d( _5 {1 @& w( Y& v, n
#include <SYS\STAT.H>
" \! i6 h# d; x: y& W#include <PROCESS.H>
; j  M6 n3 Z% j, h& H#include <SHARE.H>6 K/ o  Z& ?# b4 I# F
#include <STDIO.H></FONT></P>
* g+ K) Y6 l5 B8 y8 V<P><FONT color=#0000ff>int main(void) ! k% f2 U/ P9 K# Q8 t7 `1 n5 L9 q
{ 4 F2 y9 o+ h9 c8 B: P
int handle;
% T# N9 d( y/ C/ z3 d7 m: a5 `  kint status; </FONT></P>: ^7 }# D; R7 \
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>) }9 T0 G; h* O
<P><FONT color=#0000ff>if (!handle) # C; B* `( ^% n# e
{
) c. R, \" @8 ^6 [printf("sopen failed\n");
7 R5 X6 x# u1 x" f) _$ X6 `/ jexit(1);
; \- p) O" S6 [4 I0 J" @) l% Z} </FONT></P>
. R5 j- g2 d9 Q6 b/ M<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
5 x5 ?& n/ |  k5 Q. y) kif (status == 0)
% K, C3 v# S7 f* F* O( Aprintf("read/write access allowed\n");
/ j- K; p* n; p( c, z1 M+ {' selse 9 I4 \" H9 m0 l; a: a
printf("read/write access not allowed\n"); </FONT></P>! G/ D# d( j- M$ m, Q9 V
<P><FONT color=#0000ff>close(handle);
3 o. {* ^5 X2 m; Y  t- L* Wreturn 0;
  y  o# P: O  m}
- h9 r4 @2 Y, W, f) C2 G) |! h2 t
3 |0 r: ~% P. ~- W5 [* z</FONT>
) M4 a% Z* N* }/ y) V8 D7 X</P>
" |: V, N) N2 g% H$ l" Y<P><FONT color=#ff0000>函数名: sound </FONT>
* u. Y9 C) N3 ]9 L; w  [% ~, l功 能: 以指定频率打开PC扬声器
: b! J5 {+ r5 ?. z用 法: void sound(unsigned frequency); 5 U& n7 r$ \, R5 V* e
程序例: </P>
7 y+ K6 D$ t# J) w- D# }& _<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. * O) s: Y9 X; a5 X( `  W
Your PC may not be able to emit a 7-Hz tone. */ : d/ E, P9 w$ {* }6 g" q; r
#include <DOS.H></FONT></P>( k) y# K6 I% a4 U6 F3 i" D% B1 F/ T
<P><FONT color=#0000ff>int main(void) ; t( E2 a* s5 k* j) x: [
{
; Z6 z- L8 b2 @: ]sound(7);
! `6 u8 D2 U# x; J6 H9 g$ ndelay(10000);
1 K1 z" p$ H8 s( K% Anosound(); / w3 ], ]- j  @' E* h
return 0;
1 Y( x& @8 f7 Q6 j/ ?2 {} </FONT>
, `4 F$ B, S  G$ Y, s& P3 W  b' B; P

% R' {. \& B* F: a</P>
7 h8 B* U) }- c0 f1 _& L+ a<P><FONT color=#ff0000>函数名: spawnl </FONT>
  e1 I- K3 ]: W$ f. i功 能: 创建并运行子程序 ; f( f* L; h$ ]# A: D
用 法: int spawnl(int mode, char *pathname, char *arg0, . X( M) E, x: L2 n; i* C# B2 f$ }
arg1, ... argn, NULL); 1 N" V! }" {4 b9 b: u& m
程序例: </P>
' H8 b& E, N4 T0 o& O" j5 M4 k<P><FONT color=#0000ff>#include <PROCESS.H>$ D" g. Z7 ^! s) H8 E
#include <STDIO.H>* d& u3 v. Z# g# Y( c) a
#include <CONIO.H></FONT></P>
& I. }: N2 d4 d<P><FONT color=#0000ff>int main(void) 0 i: k# \) x: R# b9 W( u
{
, E- U; N$ F* s: M1 V9 u  _0 hint result; </FONT></P>1 E1 Q* f/ F- Z4 \
<P><FONT color=#0000ff>clrscr(); & \* I) F  B. f, g6 R$ v
result = spawnl(P_WAIT, "tcc.exe", NULL); ; V- w7 W6 {' o
if (result == -1) 1 W5 Z4 g/ z8 E+ a% I( j  p' M
{
6 j; |- Q, p8 B, l4 E4 ^perror("Error from spawnl");
: N3 @/ L2 ?" Y/ A2 c  `& Z0 [exit(1); # ^2 K# Z: ]# B, M. m9 i
}
! F7 G4 q+ x  g. jreturn 0;
1 N$ y5 j; p  Y0 C. A3 _% u} " N5 u1 [& o9 h
</FONT>' [+ l5 h* `& T0 P/ `$ C
</P># J) I( o. D9 ]5 B5 S
<P><FONT color=#ff0000>函数名: spawnle </FONT># T/ H. I8 y4 }/ v0 U
功 能: 创建并运行子程序
. M$ D) h4 g- h& f1 m3 Z- [用 法: int spawnle(int mode, char *pathname, char *arg0,
$ u9 E2 i  M( B& K5 Z/ h5 warg1,..., argn, NULL);
" c* f% i6 a6 f) k程序例: </P>8 o0 l1 Q& [$ B" ?/ q+ ]8 U# s. O
<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>
0 @) ^+ u1 \1 W3 M<P><FONT color=#0000ff>#include <PROCESS.H>
- _  Z, V& o8 @' {3 [  F#include <STDIO.H>. F6 ^' N3 C$ K3 C# P
#include <CONIO.H></FONT></P>
7 o- n/ g% W! @/ j<P><FONT color=#0000ff>int main(void)
, T! |6 G& `. {6 C  J{ 2 h8 y; H0 I8 ?) Z3 p* I( I
int result; </FONT></P>
% B: a* a( y  Y% j( t<P><FONT color=#0000ff>clrscr(); % p$ l+ `7 V; o+ H( b  p/ P
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
2 X! |2 K4 `* M; cif (result == -1)
4 L& \, ?8 \) h2 A, D% D{ . i& \, v- ^% b4 C; C
perror("Error from spawnle");
% O7 g, i' t9 a( mexit(1);
( @4 B$ K0 Z  z, p0 j/ l}
/ w/ J. P; g+ D+ W( Greturn 0; 3 W6 D# h3 P6 ?2 P$ L
} ' g1 T2 k, q, s, ~
5 |+ q% s, U) v! c# I/ f9 ^9 |: P

0 d" r$ ]6 Z% h# ^. o</FONT></P>
# X/ ~3 b; Z2 R; R7 d8 t; ^2 O<P><FONT color=#ff0000>函数名: sprintf </FONT>" \2 p7 A: e; V0 V$ a3 y% S5 n+ D
功 能: 送格式化输出到字符串中
9 p4 V! J$ a/ l: u; b( y用 法: int sprintf(char *string, char *farmat [,argument,...]); 3 h! G% h0 A3 R
程序例: </P>
) \. L. r* `, n<P><FONT color=#0000ff>#include <STDIO.H>
# p1 Q% T  C; O+ C6 Y#include <MATH.H></FONT></P>
5 Q2 |' u- X; u/ W8 K1 M& P<P><FONT color=#0000ff>int main(void)
* b/ E: c0 V7 L6 r6 a{
4 T: i# Q. T) \. Z$ tchar buffer[80]; </FONT></P>/ g/ F3 y+ d- m4 k6 J" r
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
; \8 w) h/ x0 E$ k: H. [puts(buffer);
, w# _! g9 E  b; j: O7 E6 X! e- ireturn 0; " H8 U; Z) r( _, N' T
}
1 Z4 C, R6 C3 {$ F2 J: r$ w</FONT>
% }+ Y# ^" k, F: j: Q8 {</P>
: C" @' r1 Y# Z* @5 a8 Z" y& a3 d+ X<P><FONT color=#ff0000>函数名: sqrt </FONT># g) S# ?/ ]. L' }9 I4 ]7 ~* G$ n2 n
功 能: 计算平方根 3 W( q" O+ ]2 {7 d
用 法: double sqrt(double x);
/ J: i* P7 t4 j' x: l程序例: </P>1 Z  G- P' ^! z. z
<P><FONT color=#0000ff>#include <MATH.H>0 |. L& ], P( V
#include <STDIO.H></FONT></P>
5 k( r2 j( B4 ]; Q0 }<P><FONT color=#0000ff>int main(void)
- {9 O: n6 e  n3 t$ B% @' i9 l{ ' z* R0 K, h  s; D
double x = 4.0, result; </FONT></P>8 C" ?+ W! y  T0 [) ?
<P><FONT color=#0000ff>result = sqrt(x);
0 P; D9 X; L4 i8 e) g) `% N. ?! pprintf("The square root of %lf is %lf\n", x, result); + G2 {4 @5 h9 a1 z% F
return 0;
9 i# ]- }4 w5 T- D+ s}
: _2 b9 g1 p( f( H! D</FONT></P>, y% O1 X5 U2 G: |% G
<P><FONT color=#ff0000>函数名: srand </FONT>
8 G8 z2 z6 K: ]0 e: t+ e+ u+ U功 能: 初始化随机数发生器
, t' o" ]+ C8 ?& p用 法: void srand(unsigned seed); $ N+ _1 X) |: j
程序例: </P>: A: Z9 N2 l9 @5 d3 c
<P><FONT color=#0000ff>#include <STDLIB.H>
# }5 f) Y5 @. y- e# C* `) o9 C#include <STDIO.H>3 I( W. z5 y. G2 _; q! @% ~! R
#include <TIME.H></FONT></P>( U) t6 K, H5 u" v' C" J+ D
<P><FONT color=#0000ff>int main(void)
6 `5 P1 Q( d) B6 \% n5 q{ ' ~0 ^8 ~7 y" Q% R/ S8 W
int i;
" N: M+ f6 _8 D# o( ktime_t t; </FONT></P>7 n4 F2 G! O+ j
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
$ w8 x- a# n) [+ C2 B/ V9 kprintf("Ten random numbers from 0 to 99\n\n");
5 S- [/ E. M; u  i) a. s# Bfor(i=0; i&lt;10; i++)
0 Z* C$ s# H7 o3 f0 H4 u. Aprintf("%d\n", rand() % 100);
% D+ O( p  ?- G* M6 Q7 |return 0;
8 z9 W% U5 b6 |# H( V7 b0 L} ' J6 y2 Q& D( }7 _$ l7 v) y# z
</FONT>5 @- C6 r$ L5 f) C  ^( m
</P>- v5 E! ^9 F: [) u
<P><FONT color=#ff0000>函数名: sscanf </FONT>
/ B* @2 ?  @% |4 \9 n功 能: 执行从字符串中的格式化输入
: H& W/ k, I9 `2 _6 F用 法: int sscanf(char *string, char *format[,argument,...]);
. G2 Q+ x, f! X7 @) L- ^3 B% Z程序例: </P>/ D! ?. w% W/ Z* w/ o
<P><FONT color=#0000ff>#include <STDIO.H>
) G$ C, v9 l$ C8 c- Y5 @#include <CONIO.H></FONT></P>
- T0 ~1 a" S6 j* S  o5 y<P><FONT color=#0000ff>int main(void)
! x$ v/ O6 ^& i8 w1 b" i{
8 U2 d/ j# j$ hchar label[20]; - H5 r3 T5 a& _# u. q
char name[20];
  T7 k1 B" A6 o& @0 h; s$ dint entries = 0;
! y1 H" _0 X; p: x. S0 ]7 @int loop, age;
, k* n# ^8 ]3 T( i" ^# x# ydouble salary; </FONT></P>1 m0 B9 |& R; N9 A! b& ^$ m
<P><FONT color=#0000ff>struct Entry_struct
: Y8 ~  z' k" W6 H, i4 q, u{
% v( h+ e  K$ vchar name[20];
: L+ p; H! [$ e) v7 tint age;
  w, B& i7 S  t1 t/ d) j) wfloat salary; # {: _0 V% Z/ H, ]7 I
} entry[20]; </FONT></P>/ `. S+ t* Q, N% W7 H! _
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ 8 |: O- N0 b. e2 [# }4 M  R
printf("\n\nPlease enter a label for the chart: ");
- o4 n8 a* P& S1 ], ?scanf("%20s", label);
5 Q: R# b7 B4 |2 t& H) Mfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
! E/ H" B5 I- \  A" _+ W. J<P><FONT color=#0000ff>/* Input number of entries as an integer */
4 i; l. G0 M( E& R- b8 r! rprintf("How many entries will there be? (less than 20) ");
5 v1 |" ]* M% _( P: [scanf("%d", &amp;entries); + u3 ^) J4 V# x/ c( j) k: W
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>/ P2 L& ]3 ^  ^3 }/ w0 q7 ^
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ % ~. E+ H/ o3 G; |( o
for (loop=0;loop<ENTRIES;++LOOP) / _' u" |, a- o" M
{
+ D, T8 e% d! Q' D9 _3 v1 Sprintf("Entry %d\n", loop); # X: V( P* ]+ v4 r& g
printf(" Name : "); 4 o# y, P$ ?9 \6 s
scanf("%[A-Za-z]", entry[loop].name);
1 V+ S$ R% W( M3 }fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>8 q- R4 b3 T6 l0 t
<P><FONT color=#0000ff>/* input an age as an integer */ , L! z( D- e4 g: K9 u: X& N
printf(" Age : "); - M, |' ]) k/ g/ K) b4 q. m
scanf("%d", &amp;entry[loop].age); 3 g( I) _( y% N( W0 i2 m
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>+ B6 t2 Z2 e* a
<P><FONT color=#0000ff>/* input a salary as a float */ , ^" ]7 w/ R6 m; L# t, F4 M
printf(" Salary : "); 6 B% x8 M, m( p, n; t% s
scanf("%f", &amp;entry[loop].salary);
* r" i5 b0 J! |4 c  ifflush(stdin); /* flush the input stream in case of bad input */
/ ~* u: T+ E' {5 q, y0 f2 s& p. [/ C} </FONT></P>
& Q, ^2 [7 G/ w! ]4 ^& Q7 T! T<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ + ~$ B4 K8 G. b  |" Z
printf("\nPlease enter your name, age and salary\n"); . c: ~7 f1 w$ W% c" H5 G
scanf("%20s %d %lf", name, &amp;age, &amp;salary); $ ^" |( |# e% j" s1 O' r
</FONT></P>' S+ |5 Z- ^5 y: }0 E; Y
<P><FONT color=#0000ff>/* Print out the data that was input */ 9 H# a. k: I  Z7 R; b
printf("\n\nTable %s\n",label); # g/ U( W! Q: ^0 w& q7 ~
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
: g4 J* j5 N! Kprintf("-----------------------------------------------------\n");
) j- p6 K4 j0 Ofor (loop=0;loop<ENTRIES;++LOOP) - C/ z6 Y0 u5 @6 N% q2 M/ f
printf("%4d | %-20s | %5d | %15.2lf\n",
+ [3 g1 x  S8 Oloop + 1, ' P: v% d3 B; k- P$ y3 m
entry[loop].name, + U; E  ]$ \; ^# S, l7 C
entry[loop].age,
* p+ |/ Q! G9 Y2 m1 K; N3 T4 E6 zentry[loop].salary);
$ t1 r- t+ W( X, R' y( rprintf("-----------------------------------------------------\n");
6 h+ c) k) o7 X0 I7 @return 0;
) I! Q* I! Q9 J4 k. \# _}
- V, I. Z; y0 I  f7 `2 N
/ n. f9 [$ r' x! ~</FONT></P>
. p' u0 A1 f4 \* }<P><FONT color=#ff0000>函数名: stat </FONT>) Y3 I- e, q% p! K4 A- R
功 能: 读取打开文件信息 ; ]. V; p) c% C  z! b" a( E
用 法: int stat(char *pathname, struct stat *buff); 4 v6 H2 N$ y) ]& ^
程序例: </P>
; D1 S5 {) }  \<P><FONT color=#0000ff>#include <SYS\STAT.H>( W! i* }1 ]4 @- K) M: ^
#include <STDIO.H>
: @4 C6 D' o5 L3 J3 O) w#include <TIME.H></FONT></P>
7 q3 }' `( v1 S" n7 E<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
! C, G9 p4 Z+ W/ s<P><FONT color=#0000ff>int main(void) - `% ~1 d8 `% x9 C/ L$ ?/ ?
{ ' E: R% S3 F( l
struct stat statbuf; " [" E8 j1 u7 u
FILE *stream; </FONT></P>5 _! q8 w) _# _, n" n6 V, U
<P><FONT color=#0000ff>/* open a file for update */ & O: n# z0 w0 Z5 _8 y% @" P: V. P
if ((stream = fopen(FILENAME, "w+")) == NULL) * p$ X9 \& N2 G7 W- v  r$ P0 G% {
{ . z& i3 W. z9 i" C& O
fprintf(stderr, "Cannot open output file.\n"); 1 q' L. y2 O& x2 u  P: Z; V' h
return(1); , R' O$ X% m, @; N5 S4 \
} </FONT></P>
5 G( d  i# Q0 f8 W4 ^0 Y. j! Y<P><FONT color=#0000ff>/* get information about the file */
" J  m6 @0 d* @+ b. q0 Hstat(FILENAME, &amp;statbuf); </FONT></P>
# a: T7 C5 f, D7 y- A- L$ X<P><FONT color=#0000ff>fclose(stream); </FONT></P>4 v% U/ V8 s- g& l2 I
<P><FONT color=#0000ff>/* display the information returned */ ; w, g. r4 J: o: p: e, h( A( F
if (statbuf.st_mode &amp; S_IFCHR) " {  y) r8 R  f/ I
printf("Handle refers to a device.\n");
+ |; x7 [. X' v; xif (statbuf.st_mode &amp; S_IFREG)
. b* J) d' }; x$ Yprintf("Handle refers to an ordinary file.\n");
  h+ K, u6 O# ~6 F9 cif (statbuf.st_mode &amp; S_IREAD) 6 P2 Z8 z( n0 q6 t9 v, a7 K. n
printf("User has read permission on file.\n"); ; Z! s" ?2 S( G! a
if (statbuf.st_mode &amp; S_IWRITE) $ L  T0 U& j4 }2 p, i
printf("User has write permission on file.\n"); </FONT></P>
' h2 }+ B5 [# e. E0 O: I<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); 5 n2 v! c) ]1 q9 o3 A
printf("Size of file in bytes: %ld\n", statbuf.st_size);
, z$ H- O2 A! Y+ ?3 o% u$ M- \printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
' K/ j5 d0 z, ?9 Xreturn 0;
/ f) L3 t) Y8 {2 P) y2 u} 8 K6 `- ~$ c; I6 T' ]
  w# h; S; j: `  u( @, D
</FONT>
: u2 R$ E) ?0 \</P>
. K. [) v9 p/ ]* m. ?8 Q( B) g<P><FONT color=#ff0000>函数名: _status87 </FONT>
" {' b5 s7 w$ K! I+ L" [功 能: 取浮点状态
. }5 }: t! r# s! ]  \+ \& ^用 法: unsigned int _status87(void); 5 m+ Q9 {; w5 j" T% i
程序例: </P>( y8 w7 K9 j; [
<P><FONT color=#0000ff>#include <STDIO.H>- l* l! b1 {- m" p7 j5 R# x6 n6 v
#include <FLOAT.H></FONT></P>
, k1 ?# A7 w! A$ |9 S2 \, v<P><FONT color=#0000ff>int main(void)
, X, @: G: b3 D{
/ U2 Y, h) r. J! k* V  J% p" b/ Kfloat x;
6 m  g- X) c- ^, o  |7 _double y = 1.5e-100; </FONT></P>/ t6 z) X9 Z6 k$ j' w" G: Z6 ]1 D$ _
<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
' H3 S( q' h  ]/ n* `" b<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
' J2 o" Z* D. ^" |y = x; </FONT></P>- }7 }- Z4 ^- z( z9 p) J5 R. N3 J
<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87()); . u6 I; f% \3 i8 S0 b0 W  N
return 0; 0 S) B9 Q0 z) J! x; z
} ( d& N' [$ X7 V! V
</FONT>
0 [7 j- h6 T( ?; G4 h$ o4 M% F7 w</P>
$ v( U  j8 w/ G* z8 {  K- X<P><FONT color=#ff0000>函数名: stime </FONT>
+ v+ r9 V2 O7 W) L  G1 v功 能: 设置时间
. U8 B! {3 E( A- \+ N- z0 ?用 法: int stime(long *tp);
7 K0 B* [& s% p- U9 P& ~3 |程序例: </P>
$ k4 A& L/ f* b9 h<P><FONT color=#0000ff>#include <STDIO.H>5 R1 X: k: |" h+ T
#include <TIME.H>+ y8 b7 M0 P' [0 i$ W8 h8 V4 Z4 _
#include <DOS.H></FONT></P>
" q9 |* D0 }3 [; d2 ?+ l' Q: k! G& u<P><FONT color=#0000ff>int main(void) / [& E6 y0 l/ j/ Y! C
{
4 h& R7 q6 q+ F6 L+ z$ ttime_t t; - t2 h% {) w: U# O* b
struct tm *area; </FONT></P>
& A' ]* b( D4 m7 I4 |9 B<P><FONT color=#0000ff>t = time(NULL);
% _# R+ D8 z3 farea = localtime(&amp;t); 7 |3 I3 C2 e; F5 o0 Q5 ?
printf("Number of seconds since 1/1/1970 is: %ld\n", t); 1 N8 L: h7 D5 ?( _+ x0 c
printf("Local time is: %s", asctime(area)); </FONT></P>
/ t+ r' ^$ K. E* v<P><FONT color=#0000ff>t++;
2 e$ I, U* c8 n8 E+ D6 c: ^. r9 Narea = localtime(&amp;t);
( s( h! F7 U; Cprintf("Add a second: %s", asctime(area)); </FONT></P>0 R1 k2 Q* W% k8 N+ r0 Z0 a* J
<P><FONT color=#0000ff>t += 60; 3 j* i  w# y6 d: P* s# r
area = localtime(&amp;t);
  F6 p0 q$ j( @" N& N# F; jprintf("Add a minute: %s", asctime(area)); </FONT></P>* B! \$ H& @4 X  q
<P><FONT color=#0000ff>t += 3600;
% Z1 j2 ~" S4 f; T& Q  p; T* Rarea = localtime(&amp;t); ' c6 a0 B2 z* k! Q
printf("Add an hour: %s", asctime(area)); </FONT></P>' t+ `2 y1 d2 f! I: |
<P><FONT color=#0000ff>t += 86400L;
3 d# W+ ~) @. Xarea = localtime(&amp;t);
& _& c" j  x1 V- e, I4 cprintf("Add a day: %s", asctime(area)); </FONT></P>5 o5 L) j' z( i/ O3 N9 ?
<P><FONT color=#0000ff>t += 2592000L;
5 R# x1 g! k3 p1 a8 L4 qarea = localtime(&amp;t);
- F: ?" _: \7 G8 @' P4 wprintf("Add a month: %s", asctime(area)); </FONT></P>0 L) }" \" q! V7 s9 }, g
<P><FONT color=#0000ff>t += 31536000L;
: S1 G/ T: D+ w8 A8 @6 Iarea = localtime(&amp;t); 9 m! _& t, O8 F3 f
printf("Add a year: %s", asctime(area));
! }9 J: v  a* P* f4 w+ ^return 0;
7 G% X! p. C/ C  `2 t) R) C0 a2 C; {. e! G} </FONT>4 T' B2 B2 |8 h$ ^- v7 a  f- Q  J' f
" r0 O: x3 _8 G4 p3 K7 G  B
4 w: j9 `9 w/ d* \
</P>
& O8 e0 z( N1 V1 u1 b+ U) D<P><FONT color=#ff0000>函数名: stpcpy </FONT>4 d+ m: h; m0 N: `+ s3 z
功 能: 拷贝一个字符串到另一个
# t; O9 Y; s+ p8 p/ z用 法: char *stpcpy(char *destin, char *source);
6 R& V# ^2 P! x. N0 [' a程序例: </P>
# q! e$ ]. _: f  K# n<P><FONT color=#0000ff>#include <STDIO.H>6 ]5 _7 V- U% Q/ `% R
#include <STRING.H></FONT></P>
& N+ j8 @% H5 u2 T2 h<P><FONT color=#0000ff>int main(void) ( t! p9 {2 k4 Y. J1 \( ~8 P& j7 `. i
{ * ]4 K  {" v: j/ P. V: w9 g
char string[10]; 6 T0 f0 j! K' \" q5 X+ ]
char *str1 = "abcdefghi"; </FONT></P>
2 P  M4 S" `8 I4 f2 K9 J<P><FONT color=#0000ff>stpcpy(string, str1);
- ~9 ?6 f8 o2 r" B8 ?% _printf("%s\n", string);
7 ?  }0 K) B& v- {8 y4 Ereturn 0;
: V+ n, P+ S" ~% s! x. R}
4 c3 L& T$ K+ ?: k' {, d
. i6 {7 [) u9 D& i! d</FONT>7 J7 E/ [4 ^- ^" `% `- U) F) `
</P>
5 \4 _7 R) {+ a8 W' V) u" `<P><FONT color=#ff0000>函数名: strcat </FONT>. z3 ?) [. ?3 H' T
功 能: 字符串拼接函数
: R% E/ R' m" @% L7 ], K# V用 法: char *strcat(char *destin, char *source); / f6 p/ Z+ `- g
程序例: </P>
+ r, W' ~7 h5 m# g" A0 e<P><FONT color=#0000ff>#include <STRING.H>
8 ?+ k& i( \) T) ?/ G/ w#include <STDIO.H></FONT></P>, X, f! e4 v8 f# ]# d# L- t
<P><FONT color=#0000ff>int main(void) 6 S2 v' m' b/ i5 E  Z. T# g# K& `
{
( {6 y6 j  e; qchar destination[25];
3 E3 Q/ G: C7 H1 X! E4 w; g" ~* k; Uchar *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
8 x+ z7 ^, T6 M" m<P><FONT color=#0000ff>strcpy(destination, Borland);
5 Y# ?: B! [, gstrcat(destination, blank); ) u( X5 @9 X3 c$ a* I
strcat(destination, c); </FONT></P>
) ?. C2 ~9 @6 ]  Q  }<P><FONT color=#0000ff>printf("%s\n", destination); # b* o& v0 H5 v0 W: p: S& L3 {
return 0; / l/ s$ l. N  q& k3 n. _( D
}
5 _0 M; E" R6 G* T! ?, E% ~8 c  @1 p7 V9 o* ~& e0 @
</FONT><FONT color=#ff0000>
! Y  K$ [' Q) x2 m% u. F</FONT></P>
' E  c# S8 L, K0 _) Y<P><FONT color=#ff0000>函数名: strchr </FONT>+ {) i+ c! m; K* r$ J
功 能: 在一个串中查找给定字符的第一个匹配之处\ 1 q2 r- I. |9 c9 ~/ `" h4 n
用 法: char *strchr(char *str, char c);
& J/ v0 n0 ~1 K0 E: N程序例: </P>; V$ _% R* R' B3 M' S  M
<P><FONT color=#0000ff>#include <STRING.H>  S; E1 `9 e0 G9 l" }4 `- s$ j: s
#include <STDIO.H></FONT></P>7 m/ I8 l4 w& f; E* @! `5 J
<P><FONT color=#0000ff>int main(void) 1 B! P* S% N4 g: z6 O3 s, M7 ]" F
{ , R( ^- m% ^2 L+ a& W% _9 U
char string[15]; 1 T6 z% d: @$ p! D
char *ptr, c = 'r'; </FONT></P>
+ {) S% ?7 ^( G, \2 f; x<P><FONT color=#0000ff>strcpy(string, "This is a string"); ! y* a- k+ H# R' z6 U
ptr = strchr(string, c);
. t1 o8 z5 |: dif (ptr) ; e$ V# o+ ~4 h( o% @; [
printf("The character %c is at position: %d\n", c, ptr-string); + ]$ y1 a; D; R
else
  y& R! p( E" X/ _printf("The character was not found\n"); * ]; t+ Z: g- t# {- h
return 0;
4 t0 f  F" x# X' D. d+ J}
) @2 ]5 r* m" f8 b</FONT>0 a8 I1 N7 w( n* t: g9 S
& g8 ?9 Z7 P' G1 e
</P>4 L/ g' E1 K  w) {! l
<P><FONT color=#ff0000>函数名: strcmp</FONT> : T$ `7 k& P' T  f' L
功 能: 串比较
) R/ T" |  |9 B6 f4 T用 法: int strcmp(char *str1, char *str2);
' I8 M9 F) g8 M+ z' o  q程序例: </P>& I" B; a/ m- i: u
<P><FONT color=#0000ff>#include <STRING.H>
8 r, S3 p/ F* f& w2 z#include <STDIO.H></FONT></P>
) g$ i# j& l1 O' y8 B* ^2 O9 A<P><FONT color=#0000ff>int main(void)
' V: y: |* r- s# a8 `4 z. A{
# S8 ^6 a$ L6 _8 lchar *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; # }3 K" q! U- o- c8 e( d
int ptr; </FONT></P>  s1 U, `  a- z! j' G
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1); 8 q- t+ {+ |, {8 O
if (ptr &gt; 0)
# B- y" a6 k7 ], Sprintf("buffer 2 is greater than buffer 1\n"); ) N# z/ [, o) Q9 B
else
- N, H9 D- J- g5 y) C% n: F9 \9 b, qprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
% P  }+ Z! X( d8 `6 I) h: k<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
# m; _( O" q3 A7 Vif (ptr &gt; 0) 1 a' z' e% q2 n8 g2 m
printf("buffer 2 is greater than buffer 3\n");
$ Y) V  `/ V0 y$ X8 ]else 5 g4 e% J+ i& h! `( M" n
printf("buffer 2 is less than buffer 3\n"); </FONT></P>8 \2 w7 w/ N& V7 I
<P><FONT color=#0000ff>return 0;
+ a4 c  X+ `; T; B}
8 J9 A9 o* F* _/ t. f9 p
3 d$ M3 G; e' x3 i! p( F" |$ Y: H2 {6 R% t
</FONT></P>* R, n& \: X  U% L  d
<P><FONT color=#ff0000>函数名: strncmpi </FONT>
: i1 g/ l+ Y8 t/ ~8 Y功 能: 将一个串中的一部分与另一个串比较, 不管大小写
3 e% z% H* W0 G  g) P用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); : l) X! I- R4 ]& R. u% K9 }
程序例: </P>
: ?8 j. D. T3 D$ ~: B' e<P><FONT color=#0000ff>#include <STRING.H>4 ^. n' E  U/ D1 N2 A! T) m
#include <STDIO.H></FONT></P>
, u2 _! q4 o# F<P><FONT color=#0000ff>int main(void) 6 d- F- {# ~2 Y( b# R5 x& G
{ 4 o0 M" \3 q# X+ l7 U
char *buf1 = "BBB", *buf2 = "bbb";
. H; E8 J) t0 s! r- M8 k; iint ptr; </FONT></P>
! P) B1 ]% b3 H3 r- d6 T<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>& p' o( p/ b3 @  O5 ?1 `  B
<P><FONT color=#0000ff>if (ptr &gt; 0)
, U( H. ]+ L5 N0 @- Oprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
* q# ^# R. X' Z3 ]<P><FONT color=#0000ff>if (ptr &lt; 0) . G/ m2 S- w3 @" ?
printf("buffer 2 is less than buffer 1\n"); </FONT></P>- t8 \7 O, D. Y* r  m
<P><FONT color=#0000ff>if (ptr == 0)
7 b8 n5 ?4 ?1 b$ a6 vprintf("buffer 2 equals buffer 1\n"); </FONT></P>
$ E9 l( d, D4 F! P<P><FONT color=#0000ff>return 0; ' H7 Q$ |. i7 m
}
5 K7 @9 b- X3 {) G2 a, H
% s9 Y& x  D, a, N: J! v4 B; Q3 T</FONT>
4 ]; u, s, {$ d% J! ~% m</P>
2 r$ ~# j' z! }0 H<P><FONT color=#ff0000>函数名: strcpy </FONT>0 r. s, K+ M0 }( x. d1 n
功 能: 串拷贝
  j1 @+ E: g* o, B6 b8 ?用 法: char *strcpy(char *str1, char *str2); # A/ x) X; \2 e; j4 r
程序例: </P>
4 E6 s5 p6 N% d3 Z5 n<P><FONT color=#0000ff>#include <STDIO.H>% c2 l6 R- A5 {8 u! r) o
#include <STRING.H></FONT></P>
) Q* W; ?9 ^% d% P! [1 `* u7 V<P><FONT color=#0000ff>int main(void)
  ~1 L: R. m( R{
+ O$ J/ D/ t* r' A# ]& Y1 jchar string[10]; ' I5 V4 s1 ?7 x7 U: }( Z
char *str1 = "abcdefghi"; </FONT></P>
, ~: ~. F) F! |  |0 e# d' j# S<P><FONT color=#0000ff>strcpy(string, str1);
+ I7 u" D6 }( I& I' j& b# V1 |, `7 tprintf("%s\n", string); ; T  S3 @+ ]$ I
return 0; 3 p2 O1 ]$ Q3 t, {! Y* _
}
. r8 a% W; c% V; @- }% f- C! {* B: R</FONT># O5 k6 V4 h+ Y7 d6 z7 Y

: f+ ^/ f& G6 e4 G4 f8 n</P>
3 Y' p, @0 @& @0 n- d: H, `, e<P><FONT color=#ff0000>函数名: strcspn </FONT>
" g  m) C' m$ u  y功 能: 在串中查找第一个给定字符集内容的段 * M8 [( }$ D0 O. o; p- h, m
用 法: int strcspn(char *str1, char *str2); ; s; O& G! f* ?; j. R0 j# Z- V- Q
程序例: </P>' u8 f% |. k+ q$ U1 [5 x
<P><FONT color=#0000ff>#include <STDIO.H>
: P$ o4 [7 a! v+ Z+ J: ?#include <STRING.H>/ m7 [/ w' d2 l  a( h4 h
#include <ALLOC.H></FONT></P>
! E5 @. g. D5 N1 b( V& Q<P><FONT color=#0000ff>int main(void)
9 |# \4 Z6 y! \0 t, J- F& g& P1 x, z{ 6 \; R) Z2 p- D, q3 f  M2 u
char *string1 = "1234567890"; 7 e6 N( N1 i- v* }) M. K* B
char *string2 = "747DC8";
; d# D+ Z1 ~3 V6 Wint length; </FONT></P>4 X) r& G: {# B* P8 E% N+ ^! j
<P><FONT color=#0000ff>length = strcspn(string1, string2); 7 q# w: M3 G* ]2 \0 Z; s
printf("Character where strings intersect is at position %d\n", length); </FONT></P>0 i+ ?5 f. A+ }6 G( F/ W7 P  V
<P><FONT color=#0000ff>return 0;
3 ?) C" G7 q, \8 M$ A* A+ S5 Y}
( }, C. E+ s: S</FONT>
0 u3 J- L/ Y2 H; I  f# ?# m
) o7 Y7 H7 T4 N9 W$ P' L# K* S</P>
8 A' k  t9 d3 g: p1 U<P><FONT color=#ff0000>函数名: strdup </FONT>
! L: c2 {0 E$ A7 k, W4 w功 能: 将串拷贝到新建的位置处 - ]! _* {! _. X" w# @& Y. Q
用 法: char *strdup(char *str);
9 i8 J) R2 a, s& ~! |$ B程序例: </P>  P# }( G; I% n7 C6 o
<P><FONT color=#0000ff>#include <STDIO.H>5 m& `2 y( e9 ]5 ^, W/ l
#include <STRING.H>
7 w7 M# I; \& B#include <ALLOC.H></FONT></P>
0 V2 t/ V+ A: R& D) x$ a, @3 [<P><FONT color=#0000ff>int main(void) - L- s- M; Y4 |, c* @
{
0 ~$ x* c3 L. Q7 n' R) M) Echar *dup_str, *string = "abcde"; </FONT></P>5 K4 [% A' i1 W
<P><FONT color=#0000ff>dup_str = strdup(string);
0 Y* I& w; C7 r7 Xprintf("%s\n", dup_str);
1 I$ ^( g8 W: ~2 ?  B" mfree(dup_str); </FONT></P>
' ^! b  X: ^2 H. u4 {/ K9 ]% H<P><FONT color=#0000ff>return 0;
, N) M" r4 Z; F4 \2 Q: ~- N6 B} 2 f1 O- h; d# o, g/ g$ _' w

, B* `+ f, A: T) w, X</FONT>
2 R7 a. l; X  Z1 Z3 T6 E</P>
# T/ j& P) w+ N8 ]<P><FONT color=#ff0000>函数名: stricmp </FONT>
  W+ l7 c" O/ K6 s功 能: 以大小写不敏感方式比较两个串   G2 N5 A7 {2 Y1 s0 L7 k# W
用 法: int stricmp(char *str1, char *str2); * m+ g7 }, i$ T
程序例: </P>
8 B' g& {* V5 E. C+ F<P><FONT color=#0000ff>#include <STRING.H>
% l9 n6 z* E0 ~6 I3 E#include <STDIO.H></FONT></P>+ `5 j" U; u) D4 U! V* }! H+ J. a
<P><FONT color=#0000ff>int main(void)
/ `7 H( Y9 J# a( {2 K' {{
0 r* w/ i: a! L9 |. achar *buf1 = "BBB", *buf2 = "bbb"; ) v+ {  P- y; z; p- ~  e1 m8 C
int ptr; </FONT></P>2 p' K) f4 o: g- y  @
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
1 {7 i1 i3 W0 j  _! J" y0 e<P><FONT color=#0000ff>if (ptr &gt; 0)
6 b  Y% d( r7 y% v8 P+ hprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
  n* Z, q7 j9 N<P><FONT color=#0000ff>if (ptr &lt; 0)
( d0 s  Y6 k, ^" c. qprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
9 g$ ?% j% q! Q2 K6 Z& k<P><FONT color=#0000ff>if (ptr == 0)   w6 l* ?2 [& U' S9 j5 T
printf("buffer 2 equals buffer 1\n"); </FONT></P>! M+ Z- I  w, E" x- Z
<P><FONT color=#0000ff>return 0;
- k* o( p. F# {: w% K0 {* b2 I( r}
- L  t/ n  `6 \( D; e</FONT># _" T; s# j9 E3 ]- d4 R- M
</P>) W  E& X' I* e0 O% g
<P><FONT color=#ff0000>函数名: strerror </FONT>. V7 y6 H6 N+ c% \2 j  R
功 能: 返回指向错误信息字符串的指针
7 R. p3 @! _* j" c* E用 法: char *strerror(int errnum); 4 V7 ^+ k8 S) _- A
程序例: </P>% N2 v9 h# @: _# o* F" e. C
<P><FONT color=#0000ff>#include <STDIO.H>; u% w  c, N+ I; J' |6 i8 \; w3 E
#include <ERRNO.H></FONT></P>
& c! |$ d3 ~$ U# d; ?* ^; G<P><FONT color=#0000ff>int main(void) % v: E8 G8 w& Q
{ 8 s1 D1 f) R. Q) ?8 w! q) U+ l: q
char *buffer;
6 H* S1 ?1 P, I! U- o& v1 h0 Hbuffer = strerror(errno);
8 \/ g: {# z' p8 Rprintf("Error: %s\n", buffer); 5 `+ T( _' J* w9 k% l
return 0;
7 H3 P9 H1 M+ F# X8 G1 ?) S. I  v}
/ y4 C- p; Y& g, s4 Y. {! b& m& l
</FONT>
0 i% y9 b, u2 G2 f( @</P>. H- w: r0 _& g- Z+ D( V" G
<P><FONT color=#ff0000>函数名: strcmpi </FONT>* E9 K0 ]3 [& ^
功 能: 将一个串与另一个比较, 不管大小写
  p5 H( K- T0 G. M9 R) T% g8 x9 p- l用 法: int strcmpi(char *str1, char *str2);
5 E/ A, k/ Q2 a程序例: </P>+ h2 M4 D( `9 n
<P><FONT color=#0000ff>#include <STRING.H>* m$ v, x, E& P) e
#include <STDIO.H></FONT></P>
6 T6 I4 H5 Y+ i1 J<P><FONT color=#0000ff>int main(void)
7 X# |- s1 [/ K9 y) z8 q{ ) c. Q5 l1 K9 b2 D3 [
char *buf1 = "BBB", *buf2 = "bbb"; 5 F, i4 i  D9 P' O, _
int ptr; </FONT></P>
" f% v2 ^: M$ |& N6 x* h: x! [<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>) H! z! p2 Y# p0 K* Z1 m
<P><FONT color=#0000ff>if (ptr &gt; 0)
$ T6 s& d/ u2 a" T  Zprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
6 A. {/ L5 ]- Q7 H<P><FONT color=#0000ff>if (ptr &lt; 0)
) |) ^$ O8 q: D: x  P) Q5 aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
2 D" P" \9 i. E' U. w5 Y; e<P><FONT color=#0000ff>if (ptr == 0)
2 Q" K) d- ]# @! |: ^# z  O  \/ K. ^' tprintf("buffer 2 equals buffer 1\n"); </FONT></P>6 k, O2 ?* Y0 G2 W6 `" i' |+ p3 L
<P><FONT color=#0000ff>return 0; ! ]0 V8 Q* e+ f$ K4 H" f% ?8 W) E' E
}
, G) V4 u* R! t+ X1 ~9 e! H" x9 U9 S</FONT>/ ]6 |8 x) h1 k
- W# c' k$ f% I- O# n- r- m# u
</P>7 A+ b1 d; {& D% x, P% g. b6 B
<P><FONT color=#ff0000>函数名: strncmp </FONT>9 ~4 M  _5 ?; v/ K- o
功 能: 串比较
- K; c! m$ W& o6 I7 b用 法: int strncmp(char *str1, char *str2, int maxlen);
4 W  ]7 ?5 d6 [& E2 P0 ^  O4 T" ^- v程序例: </P>, {& L( o" ?2 V+ m- p
<P><FONT color=#0000ff>#include <STRING.H>3 j; f7 q; m6 a- J6 g- `
#include <STDIO.H></FONT></P>. h- [& y5 J/ [/ t: |" A
<P><FONT color=#0000ff>int main(void) </FONT></P>
8 @0 e& b. c. a/ B<P><FONT color=#0000ff>{
) z+ S9 `0 F+ O  {char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc"; - |% b# u( h6 W7 v( Y; i7 f4 C
int ptr; </FONT></P>
1 y3 X2 u( ^, @8 U2 ^& Z+ I$ \<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
, G+ _$ c9 ]' a, d7 o0 sif (ptr &gt; 0)
) |: E& H% c# I' r% ]" @( ~% E9 j, @printf("buffer 2 is greater than buffer 1\n"); ' K& [; a# h" ?' ~: M' O) x8 o  I
else
8 @: E: e- Y' y0 V* Z7 g$ O  Fprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
  h) ^# w' f9 p6 N6 B* P<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
5 s- V. u. g. y2 b3 ^* T. Xif (ptr &gt; 0)
" a. j) f/ g; i+ r7 R6 jprintf("buffer 2 is greater than buffer 3\n");   E8 E# }5 Y# s: N9 S3 Z, {& g5 l
else 1 ~) Y. @7 p8 F- ^/ `3 q! `
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
. g& W/ f) c) P1 |! s! l7 Z5 @<P><FONT color=#0000ff>return(0);
: l5 K4 g, w1 z' R} $ X) Y) L' E5 A( N( e7 a4 ?
) L- t% J* P3 p2 w
</FONT></P>1 O7 B1 f- Y# d1 s
<P><FONT color=#ff0000>函数名: strncmpi </FONT>
5 K' w- \  \* c: L0 k' H. C9 X, `2 q! `功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
3 ]1 {* i8 m  T! {( M5 E用 法: int strncmpi(char *str1, char *str2); + C: n$ g& g" D
程序例: </P>0 |- o, Y5 A2 v+ Z1 Y
<P><FONT color=#0000ff>#include <STRING.H>
) Y* @& Z1 x# M# Y$ s6 @1 x+ n#include <STDIO.H></FONT></P>
% @6 p, A. I/ Z* {+ r) `' T<P><FONT color=#0000ff>int main(void)
9 l4 L( F% r# b/ H  U{
5 q/ j3 G4 ^8 V! T1 t; y9 Tchar *buf1 = "BBBccc", *buf2 = "bbbccc";
- M& t+ v8 T, n" S2 |) T. `; _" Yint ptr; </FONT></P>7 D/ m- ?& w$ @8 [1 M4 X1 o* X  j
<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>1 a! j4 d; z) O5 y  `! J2 N
<P><FONT color=#0000ff>if (ptr &gt; 0)
" w& ]6 L- `- c8 Y# K# X( l  n9 \: Gprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
: R4 x/ Y  J! X3 s( \5 j<P><FONT color=#0000ff>if (ptr &lt; 0) 6 G# ?  \7 j& G4 V
printf("buffer 2 is less than buffer 1\n"); </FONT></P>9 v7 `. K9 k) O) k
<P><FONT color=#0000ff>if (ptr == 0) 6 U/ `6 l/ R9 w  q
printf("buffer 2 equals buffer 1\n"); </FONT></P>
! b2 r) v$ z$ b<P><FONT color=#0000ff>return 0; </FONT>1 k$ M' n6 x1 E- T' v4 G
}
# n; I! p4 v" Q9 [4 f% T& m
* f  Q7 ?/ Y! A4 M</P>3 _2 |( {0 t; j' p" n: n0 Q
<P><FONT color=#ff0000>函数名: strncpy </FONT>
, b  ~! u$ d9 J2 C3 `) I, z8 D功 能: 串拷贝
+ L! m, b0 `* o2 v8 ]: [用 法: char *strncpy(char *destin, char *source, int maxlen); : W4 G$ l1 D8 b7 z2 Q: o2 K
程序例: </P>
# e: b' n, G8 J4 B* n) Z3 k1 r<P><FONT color=#0000ff>#include <STDIO.H>
% ^* @1 ]; {- h0 Q* @% I#include <STRING.H></FONT></P>
5 T0 p: b; z6 B/ `& o3 {<P><FONT color=#0000ff>int main(void) % M' i4 j0 R8 g" S. G
{ ! C) b& U/ N1 q/ R/ @
char string[10];
% i1 Q" P9 O) n# c2 k# H4 Cchar *str1 = "abcdefghi"; </FONT></P>5 o' J6 l# U& x% j4 j  Y) a; ~
<P><FONT color=#0000ff>strncpy(string, str1, 3); / o8 O( K7 P+ x" C: _! Q
string[3] = '\0'; % S' Q8 ~% C* N  }
printf("%s\n", string);
3 L+ j, ?4 U  freturn 0;
2 |. B3 _$ n/ H  L}
- @/ L+ b+ B5 q' j3 w, E( @</FONT>
; G; h0 u9 C. `8 C</P>
% r/ S% p- F9 i7 t+ Q$ N/ o<P><FONT color=#ff0000>函数名: strnicmp </FONT>
& [3 _$ w8 s; o; k0 w, S+ h功 能: 不注重大小写地比较两个串 ' E1 N3 U' e! Z) T2 N4 D
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); 0 a' R, u$ T" t" K" L0 G& ^$ `) Y9 v+ x
程序例: </P>
9 y8 N, d( p" P) W1 u<P><FONT color=#0000ff>#include <STRING.H>
- c$ v) ~* }8 ^8 W#include <STDIO.H></FONT></P>
! w/ T" A% ~8 [% p( q  L<P><FONT color=#0000ff>int main(void)
( Y, L& i4 A  w. t& b{ 7 ?+ A# a/ N6 L& C& G/ E/ z
char *buf1 = "BBBccc", *buf2 = "bbbccc"; * F& ~$ X* _# d9 W& D/ ?3 F6 M
int ptr; </FONT></P>
" `* t2 r" O+ o  E* W: @0 X8 I+ J. X! o<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
! C% ?4 D; D( ?. R; p9 C1 e<P><FONT color=#0000ff>if (ptr &gt; 0)
/ b$ o4 \2 N/ a- m5 Hprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
6 Y/ }, o( }3 h& [" Y  B3 u# c<P><FONT color=#0000ff>if (ptr &lt; 0) * Y  I3 d3 [5 g$ B( s( }
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
+ b' r- W! o7 `- H<P><FONT color=#0000ff>if (ptr == 0)
; M, G$ H1 o. j' }printf("buffer 2 equals buffer 1\n"); </FONT></P>
3 R) T* g( x( A1 r# ~: G6 a<P><FONT color=#0000ff>return 0; 8 Y$ ^' E( y9 O! w. w9 D: A! W  h
}
# C* z1 W; g0 i% M
1 `( N) }" p9 v% i</FONT>
, e9 g# l* b, U/ K' s! Q</P>
& H4 `* s9 _+ Z: n+ Q5 t7 R<P><FONT color=#ff0000>函数名: strnset </FONT>8 B( u& O# P- Q3 A$ `
功 能: 将一个串中的所有字符都设为指定字符
" h+ g+ V! K. N9 W用 法: char *strnset(char *str, char ch, unsigned n);
% i. D6 j2 j& p3 K2 ]程序例: </P>
, Z7 o! ]8 \: a5 _<P><FONT color=#0000ff>#include <STDIO.H>- c" x, a( ^  w/ K1 U9 y
#include <STRING.H></FONT></P>
* B2 I8 Y1 `* b& [" A+ d' x<P><FONT color=#0000ff>int main(void) . B( ~4 r; L/ O, y, \4 `! X
{ 9 a% X# t& Z/ h' U9 |" [
char *string = "abcdefghijklmnopqrstuvwxyz"; & z0 ^) F! B9 [% `6 e
char letter = 'x'; </FONT></P>
& [3 r. d! h2 r% t# d( S; y<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
/ C7 i! b9 c4 P* Kstrnset(string, letter, 13); ) w( X9 P0 {/ u; S
printf("string after strnset: %s\n", string); </FONT></P>0 P& P3 H8 _! Q; v9 S
<P><FONT color=#0000ff>return 0;
! R. Q4 x$ X/ J8 C} * H; z3 k9 O' x5 p
</FONT>
2 U9 t6 }' N# H</P>
  p5 |  B2 Q* N; ]2 o0 v$ D9 j<P><FONT color=#ff0000>函数名: strpbrk </FONT>2 f( |- H, R4 d/ |! a
功 能: 在串中查找给定字符集中的字符 3 G/ t: V- e: {) \+ _; `0 i1 d" y! V; ]
用 法: char *strpbrk(char *str1, char *str2);
. `; t5 b! Z2 J/ S! F6 a程序例: </P>
. S2 c, z+ x4 i. _3 w3 L<P><FONT color=#0000ff>#include <STDIO.H>
$ N4 D. H1 H# z/ N/ P! k6 r#include <STRING.H></FONT></P>+ v' C' N; {" ~5 m+ i
<P><FONT color=#0000ff>int main(void) ' ^& p1 a4 M$ _
{
% J& n! {5 @1 _3 d; schar *string1 = "abcdefghijklmnopqrstuvwxyz";
" z; C, g# E; |% d# J/ fchar *string2 = "onm";
; ~9 @1 t. U. E6 ~+ w" tchar *ptr; </FONT></P>
5 u# c( m$ b2 t6 }% A( R! x; z9 e8 L<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
) B& y2 e& H5 [: G<P><FONT color=#0000ff>if (ptr)
" e' |! f( c" ?& d' h' c7 Lprintf("strpbrk found first character: %c\n", *ptr); " e6 \4 ~& e" j  k6 @6 ?
else 5 l9 e) i" ]8 I# G* b
printf("strpbrk didn't find character in set\n"); </FONT></P>. L2 e3 k3 |/ F. ]; a% o
<P><FONT color=#0000ff>return 0; - I" ^( ^+ b2 W' O4 G1 Q8 i% {* R
} 5 C1 l& k: e$ l% ?- K

9 y8 O# q& n; c( [9 x3 U2 z' M7 Z</FONT>8 D$ b6 E: b: @/ {* G
</P># Z, o7 z# N9 C9 _
<P><FONT color=#ff0000>函数名: strrchr </FONT>
2 ~( [; _8 _  }3 v' S3 g功 能: 在串中查找指定字符的最后一个出现
- y: {  D! k  u0 h8 y1 _) i% U用 法: char *strrchr(char *str, char c);
9 j  S0 I: N/ c, ]程序例: </P>6 _$ b/ S  P9 k  m5 u# ~: ^
<P><FONT color=#0000ff>#include <STRING.H>( _8 O2 a& x' G1 q0 x; k# x4 _$ h
#include <STDIO.H></FONT></P>( C  T/ J! ?' H4 f
<P><FONT color=#0000ff>int main(void)
* [# g5 k: i5 |+ o, Q1 f; R7 D{
$ y. j0 ], V( n4 jchar string[15];
9 O2 f* z) t. p4 R$ W7 Ochar *ptr, c = 'r'; </FONT></P>/ h0 f6 G5 m) m. X# f  l
<P><FONT color=#0000ff>strcpy(string, "This is a string"); 1 H. F4 C. _) v$ D5 R6 i
ptr = strrchr(string, c);
) t- X* R& i: h$ i* Bif (ptr)
7 `. ?# m2 E. z4 P# H- n* Iprintf("The character %c is at position: %d\n", c, ptr-string);
1 t: ?* [9 i) R" @8 x3 selse ( W) A& i3 R4 O1 x) d, H& ]- s
printf("The character was not found\n");
1 {9 ~6 F- W) @2 ~. sreturn 0;
* ?# ?% Y& l) @- F! S} </FONT>2 `& @) B, l7 q' `1 C. ]3 E

/ G( i) U9 Z  ?
- D& I8 X/ s% T! X4 w</P>4 H' u1 E* R9 c7 c& Q* ^7 R; X* \
<P><FONT color=#ff0000>函数名: strrev </FONT>. w) `; B( P; a- e# L
功 能: 串倒转   S( H1 p* N3 }" V
用 法: char *strrev(char *str);
  a0 Z+ A5 Y& W程序例: </P>
9 S& x, b5 X4 _  p4 k<P><FONT color=#0000ff>#include <STRING.H>
- H3 P- U6 Y- J#include <STDIO.H></FONT></P>
! o' L. f4 K8 E. P6 Q4 T6 P<P><FONT color=#0000ff>int main(void)
/ \0 Y! k5 A$ h  C{ 5 u; }/ q7 W  d0 ]" R
char *forward = "string"; </FONT></P>
. e" \; r4 N. @( z! H<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
, r' k& M, U( }9 U0 ]% T% U7 G! ~  v9 rstrrev(forward);
7 t4 ~/ V4 E; r# Qprintf("After strrev(): %s\n", forward);
- Q! k: h7 t+ c  ]* Hreturn 0;
5 j4 I& p/ s4 C% Q( F: P2 H( Q. f! Q9 l} </FONT>4 f( c( i7 q+ g$ Z8 w& S# M) T- }
</P>7 L6 M# ^' `2 ~* t1 v
<P><FONT color=#ff0000>函数名: strset </FONT>
5 R) t6 x: b" Q' @" t: ]功 能: 将一个串中的所有字符都设为指定字符
" ?3 Y6 H& P* ^+ [用 法: char *strset(char *str, char c);
# J- K1 w8 x  n( R2 M程序例: </P>
# e; C7 O9 U8 }2 y<P><FONT color=#0000ff>#include <STDIO.H>/ H/ T0 r" ~+ H; |4 I+ X+ D+ t
#include <STRING.H></FONT></P>
! t" o, W, f! P% s<P><FONT color=#0000ff>int main(void) ( g4 b! Z- C5 v
{
' `0 s) o0 F  ]. m+ f8 |' g( N0 Zchar string[10] = "123456789";
4 ?, G- ^+ d7 C/ F! A. Bchar symbol = 'c'; </FONT></P>
9 i$ x+ o2 o& h" c: Y; L<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
6 ?& P; v  U, g/ n' @* X$ M5 istrset(string, symbol);
; u3 _3 y/ q8 r+ q8 O$ A2 Y$ C2 Xprintf("After strset(): %s\n", string);
3 D" [; x: z5 a( `3 E- v5 F9 i* xreturn 0;
0 M6 M% L) w) ~  _+ u+ o  o- Y5 q}
% P9 U7 W: x8 t# }+ s8 F
. [; M% q( q1 Y  R; M/ G+ K8 u1 |</FONT>9 M' p* B1 Z& ~" [" j# x
</P>2 f7 ]6 B4 H, D! U+ e
<P><FONT color=#ff0000>函数名: strspn </FONT>
( |* x: \' H4 K2 _% `( u功 能: 在串中查找指定字符集的子集的第一次出现   i! [7 u- m% C  v- E' j9 H/ u
用 法: int strspn(char *str1, char *str2); ) d% t0 W1 }# q: _0 d
程序例: </P>
/ E9 ~6 t2 d4 y- P4 [) j! _<P><FONT color=#0000ff>#include <STDIO.H>  l1 D3 G* h  p; _4 C/ a$ `+ Y
#include <STRING.H>5 m4 a5 Y; x4 u7 z( h
#include <ALLOC.H></FONT></P>
3 P% B, I- Z/ z' Y$ a; d7 \9 w<P><FONT color=#0000ff>int main(void)   ~& @3 A  l$ I$ R
{
5 Q% u7 k* m6 l2 Mchar *string1 = "1234567890";
8 l  s* a% G/ t1 Zchar *string2 = "123DC8"; ; n$ H) t" S& `# |7 F! n& R5 x, \! L
int length; </FONT></P>
$ `- Z; d* S2 J# c1 ]7 x<P><FONT color=#0000ff>length = strspn(string1, string2); 5 \% T; {' ?+ ^; b
printf("Character where strings differ is at position %d\n", length);   A& `0 d/ E; M5 U2 s
return 0; 3 l% B" @, N' f3 R4 i5 F
} ' m/ c: A7 X% z
</FONT>, z# r* k& }2 k/ c8 ~
</P>9 U& I$ n: S. k
<P><FONT color=#ff0000>函数名: strstr </FONT>) k0 i. {3 g' t- ?
功 能: 在串中查找指定字符串的第一次出现 - O. `0 l, W- a2 ~
用 法: char *strstr(char *str1, char *str2);   S9 j, F" y: V1 k# k: s0 J
程序例: </P>% J+ ^! b& O, Y4 _5 a  Z
<P><FONT color=#0000ff>#include <STDIO.H>: p) ^0 t4 y# s" n
#include <STRING.H></FONT></P>
. P$ c( m8 i: M<P><FONT color=#0000ff>int main(void) 4 T. F; M" g$ G( D7 ]8 q4 [, @
{
1 x2 L- M9 Z' v0 Vchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>1 ~( O3 x! C* h
<P><FONT color=#0000ff>ptr = strstr(str1, str2); 6 T0 y% M- r# Y6 t4 A# |' {- _# m/ N
printf("The substring is: %s\n", ptr);
; M' ~+ P  Y& M. R6 c' Areturn 0; 2 v0 u/ t) k- @' k1 ^9 m7 L
} </FONT>
- d( r' p3 M8 x/ @
  X( z% H% M- x9 N</P>
' K) ~( [9 w7 K0 n9 E) X<P><FONT color=#ff0000>函数名: strtod </FONT>; N  D* y, b. T
功 能: 将字符串转换为double型值 5 l: z& `* K8 j  K% ~/ Q0 }/ u
用 法: double strtod(char *str, char **endptr);
2 c+ M' K) [* m3 q程序例: </P>
3 y5 ~$ K6 s( F* X. P8 F<P><FONT color=#0000ff>#include <STDIO.H>9 W: v, @. W0 i
#include <STDLIB.H></FONT></P>
# q  q) X; T4 H- N# t<P><FONT color=#0000ff>int main(void)
! s$ \8 w- H! c3 z% [{ # M& j5 ]0 l; Y3 n9 S
char input[80], *endptr;
+ `) e( I* Z' Y( Y- Odouble value; </FONT></P>
) f& w8 M! p) {- v. J; Q<P><FONT color=#0000ff>printf("Enter a floating point number:");
  h  ?: y1 H/ v) I% w/ |gets(input); / v0 ~+ u% r8 h7 i% F
value = strtod(input, &amp;endptr);
) q- \9 U- Y4 Wprintf("The string is %s the number is %lf\n", input, value); 5 b/ v4 Y. ?; \, m6 O; b
return 0; # T% f: @. z+ ]+ T* X. w
}   @' w3 J5 t  w! ~
</FONT>
; V3 c, {& u) `0 f
" }' {8 [! r4 J1 w/ l4 k3 j</P>
7 c/ H3 _( d- z0 F. ^. ~<P><FONT color=#ff0000>函数名: strtok </FONT>
# X5 ^: f% }8 I! H" w+ q$ M& F/ y功 能: 查找由在第二个串中指定的分界符分隔开的单词 / Y8 s- Q% ?" Z
用 法: char *strtok(char *str1, char *str2);
; r+ Q# a$ i" F; N程序例: </P>
  W* _  G4 s5 o8 s* |<P><FONT color=#0000ff>#include <STRING.H>' b! T, Y7 F& z9 d3 ~6 ~
#include <STDIO.H></FONT></P>8 F# S1 A+ p3 A7 @) F
<P><FONT color=#0000ff>int main(void)
+ m4 a: I% h) Y) E9 I. ]{ : j0 H* H9 F0 ]. h2 M5 A
char input[16] = "abc,d"; 7 k+ G+ V9 F) D
char *p; </FONT></P>
5 x9 B& @6 M0 w9 Z% `) ^# w<P><FONT color=#0000ff>/* strtok places a NULL terminator 9 L( A3 c9 R5 q  C9 B6 F1 _0 ?
in front of the token, if found */ 2 u/ s# \/ A5 w. R5 w. j+ j' y! [' f
p = strtok(input, ","); 2 u) j4 C; ?9 L% s
if (p) printf("%s\n", p); </FONT></P>( G5 U9 G2 |0 ^3 {
<P><FONT color=#0000ff>/* A second call to strtok using a NULL ; e. v, B0 I9 {% W
as the first parameter returns a pointer 3 F! D% d; Q' y& B4 v# k+ `) a
to the character following the token */ 8 d' }0 ?" |2 ^) h
p = strtok(NULL, ","); 5 s2 x6 a* b! A9 C6 h# m
if (p) printf("%s\n", p); 0 V5 O* D! ?1 E3 s
return 0; 4 W/ p/ H# f# N; {3 k( Y! t. E
}
1 d) e7 B( y+ j& f8 Z' I4 {
, j) z) h4 _- v) p3 V7 U' I. |# y7 O& C7 d( A* Q5 h1 @
</FONT></P>) g& l3 H( a; i0 m* s6 u7 n
<P><FONT color=#ff0000>函数名: strtol </FONT>
) w/ Y/ X* \4 `/ }& X功 能: 将串转换为长整数
( p$ _; f' }/ H$ K; P用 法: long strtol(char *str, char **endptr, int base);
* b! _! m1 X* q1 o* L程序例: </P>! l5 O) }( R  i  E* u  d/ r3 n
<P><FONT color=#0000ff>#include <STDLIB.H>1 s8 `( m5 X5 |6 H3 l+ Y! J, ]
#include <STDIO.H></FONT></P>
& ~+ j: I/ y( p  u" i<P><FONT color=#0000ff>int main(void) & `4 W) c' O8 H1 c( m3 r
{ 0 e5 u0 C, r* D. t' a; u' P
char *string = "87654321", *endptr;
! H1 A- F0 Z  {) jlong lnumber; </FONT></P>
6 K; ^; ^, C% C  {: ]<P><FONT color=#0000ff>/* strtol converts string to long integer */ 5 F. g6 ~% \+ {; |8 W' d! }
lnumber = strtol(string, &amp;endptr, 10);
0 a) o/ J  p3 x( C( eprintf("string = %s long = %ld\n", string, lnumber); </FONT></P>
2 g8 i- v/ X7 B% s! w<P><FONT color=#0000ff>return 0; ; O' ^3 I) J2 |( v
} </FONT>
. m9 Z- x# ]/ |6 d2 p- S( k8 \" r</P>
7 t0 \6 K$ h+ B# H6 ~: O% V# X7 _<P><FONT color=#ff0000>函数名: strupr </FONT>
: G% p! |! N2 F# D) A8 W功 能: 将串中的小写字母转换为大写字母 ( ^1 X7 T9 A8 g$ l5 \
用 法: char *strupr(char *str);
" u' x9 c- D0 S1 R8 J6 c5 {# x程序例: </P>2 k+ w/ X; e! w
<P><FONT color=#0000ff>#include <STDIO.H>
9 K" t1 T9 h& V3 K6 [2 r4 `' A/ |#include <STRING.H></FONT></P>
5 B$ ]' K  T" C! v2 ]<P><FONT color=#0000ff>int main(void) ( |9 ^; I8 p% @- [/ R! b( \
{ # g, a0 e9 k! ?# K1 ~) s
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
. @2 q6 }5 ^) e9 m<P><FONT color=#0000ff>/* converts string to upper case characters */
. _% a2 L& b9 [" i7 Hptr = strupr(string); ; P% t& q% c7 T
printf("%s\n", ptr); - L1 b( T5 e1 Q& f( I( z- C) Q+ b7 q
return 0;
. ?2 R2 V: g4 |0 c} ) J$ Y1 \. p- a9 u* m: S7 G  O
5 s3 @% ?* p7 I  W; j9 S* y
</FONT>% v' I6 j; z. j$ a! {
</P>, [, P% q+ u( e* U) c1 q2 z" }
<P><FONT color=#ff0000>函数名: swab </FONT>  p* q1 w3 S8 S. A1 V5 k
功 能: 交换字节 - C+ x( w0 z* I) v2 O' g6 W
用 法: void swab (char *from, char *to, int nbytes);
/ q1 F* v) t% r0 c程序例: </P>8 \$ F4 A" ^, h9 c1 |5 \
<P><FONT color=#0000ff>#include <STDLIB.H>5 ^9 X, w6 d* x3 k- H- z# b
#include <STDIO.H>
8 p; d+ f2 w( c& u#include <STRING.H></FONT></P>4 N. C- n" r, o
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
% ~& w$ q) q0 T2 k3 H0 jchar target[15]; </FONT></P>
3 R  P, B6 i8 ~* S3 E<P><FONT color=#0000ff>int main(void)
# h+ K7 e6 [( D8 }4 Q0 q{
6 ^  Y: X0 O8 e! M' T6 ^5 s' ^swab(source, target, strlen(source)); * ?5 F1 N1 k- V. ^
printf("This is target: %s\n", target);
$ M9 f; ]9 b) F$ N4 R$ X5 v) ]' yreturn 0; ' U5 K7 W) ]* Q4 q6 K
}
& b. U5 ?1 u* l& x( C& i</FONT>, ?$ s- t% m4 y' m: L) {) {6 }7 I; U
  Y. K) |/ B; Q5 G6 W, D
</P>" w/ r$ P! }- l3 ?9 e
<P><FONT color=#ff0000>函数名: system </FONT>6 ^; B0 ]* S$ c! J- Y2 X
功 能: 发出一个DOS命令
! [( k5 }* t  ^5 h用 法: int system(char *command);
2 P. h# r+ I: h8 _4 D2 h) g程序例: </P>
& L6 a' p" N# \1 {+ ]0 w5 a9 h( C6 g<P><FONT color=#0000ff>#include <STDLIB.H>  M; l- @5 v4 _) W6 Q5 s5 d
#include <STDIO.H></FONT></P>' c/ @; n5 [- L1 Q0 N
<P><FONT color=#0000ff>int main(void)
# t7 J1 I4 X& n8 t{
8 A. g9 ^8 ]1 [: Z: {' ]printf("About to spawn command.com and run a DOS command\n"); 6 P2 U! X, y! c2 L" c
system("dir");
1 a1 t) b2 G- }. treturn 0; 0 W/ P3 [' J1 V% ~9 t. v, M
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

关于我们| 联系我们| 诚征英才| 对外合作| 产品服务| QQ

手机版|Archiver| |繁體中文 手机客户端  

蒙公网安备 15010502000194号

Powered by Discuz! X2.5   © 2001-2013 数学建模网-数学中国 ( 蒙ICP备14002410号-3 蒙BBS备-0002号 )     论坛法律顾问:王兆丰

GMT+8, 2026-4-20 13:31 , Processed in 0.554651 second(s), 51 queries .

回顶部