数学建模社区-数学中国

标题: 函数大全(s开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 02:55
标题: 函数大全(s开头)
<><FONT color=#ff0000>函数名: sbrk </FONT>
9 M/ Z, g% y. E- @7 Z) y1 S5 [功 能: 改变数据段空间位置
+ y, |" d, _+ j用 法: char *sbrk(int incr); + t7 ?- f8 R9 a2 O6 M  C. Q! u& H( \
程序例: </P>
- c5 z; n* V: n4 y5 {% v  @% r<><FONT color=#0000ff>#include <STDIO.H>
% e* L8 A9 S& F' k#include <ALLOC.H></FONT></P>0 `* P, s) W  M7 e7 U
<><FONT color=#0000ff>int main(void)
0 s; L& S7 q  F{ 6 e9 d9 {" ^& g, F  m# R/ E
printf("Changing allocation with sbrk()\n");
! n4 o( U: \! g9 |& v9 s  wprintf("Before sbrk() call: %lu bytes free\n",
1 \/ v; Z) L2 y2 N2 A9 o(unsigned long) coreleft());
% i" P: ~1 @, ?3 a% Osbrk(1000);
+ g  m; \/ \. N" D( N, ]printf(" After sbrk() call: %lu bytes free\n",
: U! k- l7 j6 f8 I8 q  ?* J(unsigned long) coreleft());
: l/ s: K  m( c" m0 {return 0; , y, X( Q! S% _# f
} ' g0 `) ~- e. o7 |- p& Y; g
. F  |2 _1 x  N' d, c5 j
</FONT></P>
; @; o; A" O/ e<><FONT color=#ff0000>函数名: scanf </FONT>4 \1 f+ D0 q6 [
功 能: 执行格式化输入 / l$ |4 f0 A: W2 _6 w
用 法: int scanf(char *format[,argument,...]); , i; f4 _4 D9 K( ^4 u  Q2 o
程序例: </P>2 c  B4 X" a1 L2 ~' V9 N" _4 _
<><FONT color=#0000ff>#include <STDIO.H>& b5 S4 h& K- u, t  {4 p! J" \
#include <CONIO.H></FONT></P>* i! _( D4 m3 Q7 C4 P& l  |* `# k9 h& S
<><FONT color=#0000ff>int main(void) 6 n  n7 [" m3 l/ f4 o. ^0 ?; E
{ : c# h2 g4 ], D7 n7 n8 o" }8 `
char label[20];
0 n% m# ^7 C, Z# uchar name[20];
8 G) k) j4 g6 K1 n/ [int entries = 0; 3 n- Y- I+ ]) c. l, i8 _, d: M
int loop, age;
+ m$ p8 b1 u# wdouble salary; </FONT></P>
  j5 ^$ v; [& |+ n8 A  p; s9 X<><FONT color=#0000ff>struct Entry_struct
( `3 f9 `3 }% B" H{ / ?. h& q! `! h
char name[20]; & K7 M- ?& ?9 R' C
int age;
3 Y6 A9 \- o8 s: {6 e! o# Efloat salary; 6 N8 J1 w, p% K6 m
} entry[20]; </FONT></P>
  ^$ r9 I  H, N' ^2 R, `6 Q1 u<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
6 M( W3 @0 O* yprintf("\n\nPlease enter a label for the chart: "); 0 M1 G  P4 N2 t: W7 G' h2 h
scanf("%20s", label);
2 c3 E" U! a' R7 H% ^& zfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>0 n4 x/ L, u* J
<><FONT color=#0000ff>/* Input number of entries as an integer */
' l7 L7 E" ~5 o) yprintf("How many entries will there be? (less than 20) ");
/ L$ R. R' K& X8 R+ ?% ascanf("%d", &amp;entries);
6 Q9 u/ J5 S3 p# O# B/ @; X/ Mfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
8 ]$ |) k6 A& b6 `$ v4 Q' e<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ & N; g4 P& i5 S. m" x& ]1 H' W' }. m
for (loop=0;loop<ENTRIES;++LOOP)   S; s$ O( w# W7 k$ X1 O! i
{
# Q2 F6 E5 O! w2 |2 l6 l& [printf("Entry %d\n", loop);
! I% _$ J1 A1 |. ~+ C* r8 lprintf(" Name : "); / x; c. C3 M  P" `) Z, P
scanf("%[A-Za-z]", entry[loop].name); 7 I( \' c% g" l6 ]
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
3 m, E& w, F5 s, \<><FONT color=#0000ff>/* input an age as an integer */ $ x4 f9 F8 p) p4 Q% [; a
printf(" Age : ");
1 F. Q) [: F7 [0 h* pscanf("%d", &amp;entry[loop].age);
6 f! \  K( e6 Q6 ~# Q& qfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>, t, ~1 g! H( a- y4 n' x- `1 Q
<><FONT color=#0000ff>/* input a salary as a float */ $ f0 c# k: R% P
printf(" Salary : ");
( X" H6 V( k3 I# \% v+ J  m) J' g3 P3 xscanf("%f", &amp;entry[loop].salary);
. q! S8 ]5 G9 X* R) j: Mfflush(stdin); /* flush the input stream in case of bad input */ - `- A, f  y- y! D
} </FONT></P>, g$ c- X9 E) b* [
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
3 G, \  |% {1 U( Q2 d, mprintf("\nPlease enter your name, age and salary\n");
$ k  I4 A: X" P' }- \. F1 fscanf("%20s %d %lf", name, &amp;age, &amp;salary); ' E1 K9 M: R, e
</FONT></P>
: L& Z! U8 g" m) ]3 K4 O<><FONT color=#0000ff>/* Print out the data that was input */ ; r: T& D+ f: w6 Y1 m$ a
printf("\n\nTable %s\n",label);
8 ^" b- l( X0 J& ]. nprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary); ! C9 M2 O' ?5 d9 |
printf("-----------------------------------------------------\n");
# a1 e, H0 q1 {$ l* R1 Hfor (loop=0;loop<ENTRIES;++LOOP) " K* F8 P1 T  ^3 ?6 X
printf("%4d | %-20s | %5d | %15.2lf\n",
7 D7 d' B7 O4 n- Zloop + 1,
$ U  ~4 k$ m% {- {& d; P$ gentry[loop].name,   ^- p7 Z1 E; Q- r4 O: A# F- Z# v5 e
entry[loop].age, 0 C( a8 y3 y2 m6 a1 j# _, i/ H
entry[loop].salary);
$ j* B$ w* G: C! S/ U0 E, Uprintf("-----------------------------------------------------\n");
" Z9 g6 V3 T! e5 Y! Oreturn 0; 5 D( _+ D8 I7 }
}
- G) Q- p  S! G3 z</FONT>4 ~- u  C4 {% M) `; I# q& M  C
</P>
* k% h/ h$ F, ], g<><FONT color=#ff0000>函数名: searchpath </FONT>
- E# q8 }1 V" s7 P: q1 G! J; S功 能: 搜索DOS路径 % g( i: y2 N% o  W. K& Z% P
用 法: char *searchpath(char *filename);
3 }) H& Z. V2 ]+ R1 K程序例: </P>8 G( e2 D9 g7 V8 Z1 u6 D9 z
<><FONT color=#0000ff>#include <STDIO.H>
& k9 u* o* z! ~( U+ G#include <DIR.H></FONT></P>1 M# O8 v. L% R
<><FONT color=#0000ff>int main(void) 5 g( Z, M0 h% w$ Y
{
* y+ n9 o) n( ^9 |& }char *p; </FONT></P>) ~. U* E6 e9 `/ {
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
8 F( Y9 j$ _+ \2 l4 p! v, fto the path */ , v2 ~9 L2 i/ u3 M
p = searchpath("TLINK.EXE"); ( d- U0 m6 e2 D! d( p& f& E
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>
. r4 a: u& g( _7 A" B3 X; S<><FONT color=#0000ff>/* Looks for non-existent file */ . d6 s- r7 m$ P4 L! c6 A3 R( F
p = searchpath("NOTEXIST.FIL"); * w8 I! G; X/ Z" j( |
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>
5 `: k- n# h% S8 `3 n$ c<><FONT color=#0000ff>return 0;
, O, J2 O2 ]! o( J' g' [} " B7 N1 F& b% F$ [# M
- v$ }* x& Q3 r. C
</FONT></P>
: D# [# G; \+ `6 j<><FONT color=#ff0000>函数名: sector </FONT>
/ y9 I3 V# C5 M& x$ L功 能: 画并填充椭圆扇区
1 k+ I' B% O3 l4 S/ B0 j+ w1 y用 法: void far sector(int x, int y, int stangle, int endangle);
# ~6 v. v8 ~1 t程序例: </P>
) z; N( @4 @: N+ X4 _; R3 A<><FONT color=#0000ff>#include <GRAPHICS.H>
; R2 M( s6 ]0 K# [#include <STDLIB.H>
9 ], ~4 L, f) A+ J5 F. a#include <STDIO.H>" A2 W  ~# k5 s" P5 N& U
#include <CONIO.H></FONT></P>
- n" {: v# E& ^: Q<><FONT color=#0000ff>int main(void)
6 t, i' z* f+ {8 s7 s7 v{ 9 K' f7 c! [7 d: g+ D3 g2 W
/* request auto detection */   P- k) k, |, s* X7 }
int gdriver = DETECT, gmode, errorcode; . }9 @% s3 ^5 m0 }$ a$ ]$ d! n
int midx, midy, i; " O" d# E3 k5 l) O  h: N" v. L
int stangle = 45, endangle = 135; ! ^5 p( m4 _4 @2 m2 z- d' d2 [
int xrad = 100, yrad = 50; </FONT></P>+ Y1 ^) A/ Q0 Z0 g8 m& h
<><FONT color=#0000ff>/* initialize graphics and local variables */ ; ?! ]* Z5 ]% P/ [: H& j, r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 f1 @. {/ A2 G: g<><FONT color=#0000ff>/* read result of initialization */ ' @) d* t3 w7 F9 X" c! a
errorcode = graphresult(); ; D. k; f6 k3 v8 x) L% R
if (errorcode != grOk) /* an error occurred */
; k3 _: l9 b. `" m% P1 M- k- }{ 9 y; J+ k7 R5 P; d2 O2 W" ^# u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # ?4 w, _9 L$ X6 v6 U0 w
printf("ress any key to halt:"); 4 h& R. S+ }+ D
getch(); # G; a9 o, ?) o
exit(1); /* terminate with an error code */ & V4 u7 b& k! K- N3 i$ f# z
} </FONT></P>
4 ^0 U, @* Z: ]; H% W2 |: T; q% D6 n<><FONT color=#0000ff>midx = getmaxx() / 2;
( j# ~2 @0 G; O1 z  P- b7 Amidy = getmaxy() / 2; </FONT></P>
- S' M$ A$ F5 D% ?5 P4 C7 V<><FONT color=#0000ff>/* loop through the fill patterns */
% x/ L: J# b. f6 jfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ) N- J& G# h# l* S
/* set the fill style */ : B1 z# V' y+ F
setfillstyle(i, getmaxcolor()); </FONT></P>3 G  y7 Q! Y7 e# O+ n& [1 l
<><FONT color=#0000ff>/* draw the sector slice */
1 R8 S0 W; N: c6 D5 ]5 Usector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P># o$ D, M& @8 |3 I, k( }
<><FONT color=#0000ff>getch(); 7 Q6 e: t' \& N; J* r$ I; V' I1 e/ ?
} </FONT></P>
) H* U: ?- r1 X" a+ f6 H7 K<P><FONT color=#0000ff>/* clean up */   `2 j% W9 T: G: a* R( H% ]9 l
closegraph(); ' [& M2 S; j) R
return 0;
3 @) t! H% k' Q" [$ o} 5 e9 o1 L1 a* r! t# q0 N0 Z
</FONT></P>7 g/ @. y5 W: ~; ~+ O
<P><FONT color=#ff0000>函数名: segread </FONT>, w! O. ~- z* n' D  u+ O2 J$ p; r
功 能: 读段寄存器值
% S; o1 `! K2 \, r用 法: void segread(struct SREGS *segtbl);
3 I4 d0 W1 |" `9 U5 |# Q; ~程序例: </P>
9 D: P6 f! Z) u8 [/ N8 ]<P><FONT color=#0000ff>#include <STDIO.H>
5 w' L1 P3 z9 a: y& K5 @#include <DOS.H></FONT></P>
2 |. j0 F! o; E7 e$ ?# H<P><FONT color=#0000ff>int main(void)
% `, u7 J% t9 j) j% H1 e! w" `{
' p( b; t# c% n3 d+ P4 Z$ k& istruct SREGS segs; </FONT></P>
$ ]' z3 ]$ Z: `0 T<P><FONT color=#0000ff>segread(&amp;segs); 4 G# h% O  N0 \' u2 L5 t
printf("Current segment register settings\n\n");
' `7 A" f  P1 a: y# j2 ^% ^8 n! vprintf("CS: %X DS: %X\n", segs.cs, segs.ds); ' A6 D; m+ r' \4 o5 S$ H# Z1 V
printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>% S$ C# F" o/ S
<P><FONT color=#0000ff>return 0;
% r7 X) f3 [1 z0 N} </FONT>
- \6 n" n0 R6 I
; e0 O  ~' i  q2 g</P>1 ~, b2 V/ I3 t) r& `
<P><FONT color=#ff0000>函数名: setactivepage </FONT>6 t! ^1 y! q# M( n, [+ @
功 能: 设置图形输出活动页
' F) s2 ~" c1 s1 }/ h% D$ L+ a用 法: void far setactivepage(int pagenum); 2 i) F4 l5 `) u; R1 g
程序例: </P>
/ F! c: C6 p9 }: h" y<P><FONT color=#0000ff>#include <GRAPHICS.H>0 l9 }; K" c5 \# E( p( a
#include <STDLIB.H>
, d/ f4 [1 W6 _; R" _#include <STDIO.H>
5 i8 z9 n9 n( C' ?3 S" [/ b#include <CONIO.H></FONT></P>
' {& H0 U9 B+ [, P# p<P><FONT color=#0000ff>int main(void) 0 U6 i- ]* s: g/ m
{
/ L6 w2 ]0 x: |/* select a driver and mode that supports */
. k# e9 j' W7 P/* multiple pages. */
: K) Z8 v7 E+ M1 _$ N% Aint gdriver = EGA, gmode = EGAHI, errorcode;
  U6 |1 j  B) d0 m6 `0 J6 sint x, y, ht; </FONT></P># `" g/ |( T: i9 r, _
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 v  \5 p: Q: R4 f. g
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ K0 f) }& |( g* v& I& d( Y2 D+ v
<P><FONT color=#0000ff>/* read result of initialization */
; a0 V9 e7 N: l5 b1 u2 `errorcode = graphresult(); " M) U9 A, y1 O$ {; c' q1 p
if (errorcode != grOk) /* an error occurred */ 1 m" [0 |4 y) s8 X8 W, [
{
6 t; y$ @2 {- j# p, w) N3 ~# Bprintf("Graphics error: %s\n", grapherrormsg(errorcode));
, Y9 b5 x$ \% n& I: Jprintf("Press any key to halt:");
8 f& C: }8 T; y/ ^* M1 f* Pgetch(); + N% _9 j# o3 _( i8 [# }: U
exit(1); /* terminate with an error code */
+ x" L# Y) g  h} </FONT></P>
! ^2 Q  R* C% e4 X<P><FONT color=#0000ff>x = getmaxx() / 2;
0 u1 b  {1 q7 Q# ?' Cy = getmaxy() / 2;
* X, B' c7 E  O3 C7 ^ht = textheight("W"); </FONT></P>& z6 E' ?# t6 V7 ^; Y
<P><FONT color=#0000ff>/* select the off screen page for drawing */ 2 e. \6 ]6 E' b5 P+ u
setactivepage(1); </FONT></P>  Z2 e( C. d" F0 C$ i% ?9 H+ n
<P><FONT color=#0000ff>/* draw a line on page #1 */ % x, Y, R- L6 R# h. z- g
line(0, 0, getmaxx(), getmaxy()); </FONT></P>+ a7 ^+ Z4 C+ S0 s+ ^& Z
<P><FONT color=#0000ff>/* output a message on page #1 */
/ f9 m- B1 N4 c/ h1 E, U  B( A3 ?settextjustify(CENTER_TEXT, CENTER_TEXT); 9 K; _: q$ }  }: K
outtextxy(x, y, "This is page #1:");
5 V7 X( h" l2 |5 M  f& P8 K& xouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>4 [: q8 |% r. u
<P><FONT color=#0000ff>/* select drawing to page #0 */ 1 b4 m$ \" a$ @+ `% [7 S
setactivepage(0); </FONT></P>  c( d' `& F: N( q
<P><FONT color=#0000ff>/* output a message on page #0 */ / S8 K! u* @9 {( M4 l8 O
outtextxy(x, y, "This is page #0."); 0 b8 G9 b; G8 D  h
outtextxy(x, y+ht, "Press any key to view page #1:"); % n4 G3 I8 r- N/ V7 _5 H
getch(); </FONT></P>
0 L0 Q# z  c1 t/ H- f( k+ ~, x<P><FONT color=#0000ff>/* select page #1 as the visible page */
# P( v% r# f% i+ Y7 h/ Qsetvisualpage(1); </FONT></P>: e% t! f0 `/ o
<P><FONT color=#0000ff>/* clean up */ 7 T+ |8 O2 x% k) E" t  W- Z+ q: g9 @
getch(); - ^. V0 V1 \: _; y$ e" i
closegraph(); . ?; ~5 `! g7 ^+ d9 }8 y
return 0;
) U* H& p( }6 B# A9 Z}
/ F$ r- S, U" Q* {$ k5 X" u6 j4 q</FONT>
& s1 ]! i! Y; @7 v: C  t</P>
' }# J( l& U( {( C+ p0 A3 x% N3 ~<P><FONT color=#ff0000>函数名: setallpallette </FONT>/ g7 |. a+ j& }% f! D" X
功 能: 按指定方式改变所有的调色板颜色 . o$ O# r% o* B0 B) ~
用 法: void far setallpallette(struct palette, far *pallette);
" N0 ]" v- ~# d+ Y程序例: </P>( z* Q; I/ _- a& S* }; f& g& a; E
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  }3 Q$ u8 Y/ d#include <STDLIB.H>
  i: }- Q1 O" `$ b8 C$ v. _; f: F#include <STDIO.H>2 r% b) {, w2 E0 R5 R2 \; D. _8 z
#include <CONIO.H></FONT></P>
: u0 D; o% B2 ?; O# W& w3 W<P><FONT color=#0000ff>int main(void)
* y6 Y9 J3 |$ ^( u+ g' u{
9 |* r8 F+ Y+ E8 I/* request auto detection */ ! J5 ^9 e) S7 k9 O
int gdriver = DETECT, gmode, errorcode; 3 m0 b- Y2 P4 H) v, U+ T, [
struct palettetype pal;
, A; d6 t& t& ~, X6 iint color, maxcolor, ht;
' h+ v0 w" z/ l+ Tint y = 10;   x. K3 ~1 c' t4 O! y5 I
char msg[80]; </FONT></P>: }! v7 b# W% D9 M, o& Z
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 E/ S# C! ]; n+ w& D- {, [) `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! z7 b$ S4 K* m7 R- {& |8 ^  v
<P><FONT color=#0000ff>/* read result of initialization */
/ x9 r0 r' \  v2 ierrorcode = graphresult(); 8 s& j/ y9 t9 i: b
if (errorcode != grOk) /* an error occurred */
+ L4 n  w8 O$ z{ 5 ?) w$ z# k* h) ^! }) \
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; C& p/ ^. J8 M  x7 [8 z
printf("Press any key to halt:");
8 h$ g8 j! X& k& C: x, @getch(); 3 U# |) q' k- Z: v& [1 |0 b/ ]* B
exit(1); /* terminate with an error code */ ; s- Z0 W, _' U% a2 N+ B
} </FONT></P>
6 u; }9 D. [" ~/ G9 \1 X) R<P><FONT color=#0000ff>maxcolor = getmaxcolor();
8 F; T& P2 S% R3 ^8 V' qht = 2 * textheight("W"); </FONT></P>" i  r) W8 X, x
<P><FONT color=#0000ff>/* grab a copy of the palette */
1 r0 M+ u6 {2 l: Dgetpalette(&amp;pal); </FONT></P>
9 h' }; L7 _, A& s: C<P><FONT color=#0000ff>/* display the default palette colors */
9 R- W. q/ {9 J8 W( dfor (color=1; color&lt;=maxcolor; color++) 9 Y: c5 k3 K$ w3 T( t: G6 Y
{ 1 X" P) ^3 E! h: ~/ Q8 i
setcolor(color); 2 p# e% n( H7 r2 _5 W
sprintf(msg, "Color: %d", color); 9 y) y$ I$ @- W6 k
outtextxy(1, y, msg);
: R* x# G/ J- {7 Ky += ht;
6 I: C/ d7 e- L2 |6 i  |} </FONT></P>
3 d. ^0 r7 a9 P- H; M* i<P><FONT color=#0000ff>/* wait for a key */
% F$ s( m5 g4 b! ]- [getch(); </FONT></P>
: h/ x2 ^  L/ l5 j<P><FONT color=#0000ff>/* black out the colors one by one */
4 W3 d$ v8 k) k% J* W, ifor (color=1; color&lt;=maxcolor; color++) 8 O. `+ p* m9 |8 N
{ - y% [8 o8 ^! |. b: T
setpalette(color, BLACK);
: S3 A. ]9 H' V4 D1 L! f* jgetch(); * @& N) B" p' T+ F3 R/ I  v- d
} </FONT></P>
- _% m3 k5 G: e3 g8 }<P><FONT color=#0000ff>/* restore the palette colors */
/ J0 M# w9 `/ e" q: ^  D/ dsetallpalette(&amp;pal); </FONT></P>
( i0 ]. X5 @2 A6 p3 a. E3 e<P><FONT color=#0000ff>/* clean up */
% _/ f% @2 \" Y* K  Pgetch();
: T, J* r: z2 I2 W/ yclosegraph(); & a; f$ L! o: ~$ K: f0 W7 j9 c
return 0;
' _1 ^0 w& L, X# e% J} ' I; s5 t1 J8 Z$ a0 G
/ ^' l3 k" H- m
</FONT></P>% a9 t( e; v4 n" q: D$ \
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
( ^# S5 ]$ n) e1 k8 u功 能: 设置图形纵横比 7 W& g6 {9 b% M
用 法: void far setaspectratio(int xasp, int yasp); - y- O8 R; x9 ^% a
程序例: </P>
0 T7 O/ {& l) H7 U/ r<P><FONT color=#0000ff>#include <GRAPHICS.H>  v/ d2 p3 h! b4 w
#include <STDLIB.H>* d& B( s2 w" q0 P. E( I4 m, Z
#include <STDIO.H>* q7 ~# q1 I1 _: s+ h
#include <CONIO.H></FONT></P>2 \' J) N+ Q( A& N# a; N+ |
<P><FONT color=#0000ff>int main(void)
  ?7 X! I8 D: O( l/ }# r8 K{ * I* h. t7 R0 i9 ?( `! v; ?
/* request auto detection */ % J8 |" |( C' V- u, j- }( J6 w
int gdriver = DETECT, gmode, errorcode;
; X3 b2 G* H! W1 A9 F. Lint xasp, yasp, midx, midy; </FONT></P>3 D3 j) [- t6 _' D: Z; k4 t" G
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% V" r" ?; U& `$ C- L* zinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 B8 C1 Y) J( ?; E
<P><FONT color=#0000ff>/* read result of initialization */ 1 d( W! D3 x: o0 d$ v: G  N
errorcode = graphresult(); 6 ~7 E7 ?" u1 W8 y! `0 P4 G
if (errorcode != grOk) /* an error occurred */ 0 v2 `, [- J6 f5 a2 y% p
{
8 q+ g/ T" Y' Yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
) x3 U. k" |# [, M5 ?9 ~8 Dprintf("Press any key to halt:");
: r# a' O6 t6 N" Z" q( ~% F0 pgetch(); ; N4 P& L5 Z+ {! O; b
exit(1); /* terminate with an error code */ $ g+ h7 M1 t" h; d
} </FONT></P># b: N% @; w  N6 k6 u: |  f0 i8 N
<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 n# a; @& [: L3 q- A
midy = getmaxy() / 2; 1 j9 P0 k0 w! W( y+ l" u0 r
setcolor(getmaxcolor()); </FONT></P>% a1 p+ N( {+ i- C
<P><FONT color=#0000ff>/* get current aspect ratio settings */
4 R% z; S' @* I! |6 L: pgetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>9 x9 p- H# n7 d. I( B
<P><FONT color=#0000ff>/* draw normal circle */
3 X- }: }& H4 E* ^circle(midx, midy, 100); / `) \. b2 q0 t3 @3 x
getch(); </FONT></P>
2 I( K4 O5 r& X<P><FONT color=#0000ff>/* claer the screen */
; T; a1 W! j+ @9 u/ Dcleardevice(); </FONT></P># W1 V9 n7 B8 k& O+ q3 v
<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ / W$ w5 ^  a" H1 o
setaspectratio(xasp/2, yasp); ( V7 M% P2 b% i. L7 O% q+ D
circle(midx, midy, 100);
1 ~5 z/ r- e$ R; Y7 @$ v/ t% ~getch(); </FONT></P>$ k% T, N4 [7 Q& A% G. X6 B
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
- e1 g9 E( X4 y) b. ecleardevice();
6 T) j- r% ]; i- r* ysetaspectratio(xasp, yasp/2); ) O; Q* H* H5 m; B4 O
circle(midx, midy, 100); </FONT></P>6 d+ d3 o, N$ ]. [+ ^" x
<P><FONT color=#0000ff>/* clean up */
# x+ Q6 w2 Z# q, P! n# Q( Ggetch(); ; D0 {, W; s* z7 n
closegraph(); % F# W  U5 Y' r5 n7 `  I; p
return 0; " |% z4 H, C) s1 o
}
, S8 C$ N9 @6 H/ [</FONT>
8 Q8 r* p5 ]1 Z8 }3 V</P>
- D4 m9 Z+ ?& a2 R' Q/ z<P><FONT color=#ff0000>函数名: setbkcolor </FONT>% t1 C$ x$ f" C: c! c
功 能: 用调色板设置当前背景颜色 % A& v! l0 x7 L- {% z8 W
用 法: void far setbkcolor(int color);
$ I- F) X  A( M! Z8 Q) W程序例: </P>: p8 P$ b: ]3 R* c; ^  i
<P><FONT color=#0000ff>#include <GRAPHICS.H>
. A! z- h3 D8 e7 z#include <STDLIB.H>
, |4 |4 {7 a2 E. @3 g) k+ F0 |; E#include <STDIO.H>, e6 o5 _  _4 ?; a9 d+ f* u
#include <CONIO.H></FONT></P>
5 p$ q' p+ y1 x! s& G! {' h3 v<P><FONT color=#0000ff>int main(void)
- Y6 t% L: J, L, A3 ^! L$ {{
5 R0 t3 O' F* d* i6 K- O/* select a driver and mode that supports */
: U" N2 o& n( M1 m; D% Z/* multiple background colors. */ - f. A5 {5 u1 G' _, Q
int gdriver = EGA, gmode = EGAHI, errorcode;
/ _& o3 U( R" y' Aint bkcol, maxcolor, x, y;
% c- [7 Y& f2 {8 F$ ]4 ~1 {( T) Vchar msg[80]; </FONT></P>
: v% ]6 _' m0 z<P><FONT color=#0000ff>/* initialize graphics and local variables */
  P, {( I, r- G1 G# N2 c5 d1 Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 {8 b/ |; r" K* g5 ?$ ~, G+ _<P><FONT color=#0000ff>/* read result of initialization */ % g/ b; X( L2 J* [0 g. ~5 u0 X# N
errorcode = graphresult(); ) ^7 |. _: g  p) o9 ~9 q; B. J
if (errorcode != grOk) /* an error occurred */
1 u2 p/ [. A" x7 _- S6 ~{ : z! d: `, }' Y6 b7 A& r
printf("Graphics error: %s\n", grapherrormsg(errorcode));
. ]1 k* I- E/ c8 ?printf("Press any key to halt:");
% |6 `5 a; p9 u" ?# s9 Q0 xgetch();
- O9 i9 v" L. `0 Z% w) H  [exit(1); /* terminate with an error code */ 2 h3 s  d3 D" {" _$ Q: A/ \0 x
} </FONT></P>8 h. F3 R& }7 e  t5 X3 E
<P><FONT color=#0000ff>/* maximum color index supported */ 9 z: |0 i( ?% S9 O
maxcolor = getmaxcolor(); </FONT></P>
. A( O& q2 T9 {1 h6 q<P><FONT color=#0000ff>/* for centering text messages */ 7 Y/ ]. M4 t# W, y
settextjustify(CENTER_TEXT, CENTER_TEXT); 4 S. _% I, ?9 D
x = getmaxx() / 2;
0 f4 K4 L, u$ h$ Y7 J" ]' M$ Iy = getmaxy() / 2; </FONT></P>- S* ~0 w5 A- F' B0 X) [. Y7 l, P8 K
<P><FONT color=#0000ff>/* loop through the available colors */ 0 d2 g  a! }: V. B/ x9 r( G- B
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) : p5 s) }- i- [8 n8 K- }/ o
{ , y; `) J7 \) Y( x
/* clear the screen */ ; {4 N& o# R1 I+ q( L
cleardevice(); </FONT></P>
2 L5 W+ Z. Z0 a2 T' K<P><FONT color=#0000ff>/* select a new background color */ 4 w- D* F2 I4 X3 b6 Q5 F
setbkcolor(bkcol); </FONT></P>
7 {+ ^) O. \& s' q3 {6 ]* e<P><FONT color=#0000ff>/* output a messsage */ % n2 Z; W4 r: z
if (bkcol == WHITE) : h( Q" h" P6 m
setcolor(EGA_BLUE); # Q6 q3 |9 M1 r# r1 N* {
sprintf(msg, "Background color: %d", bkcol);
( [- `, ?6 N$ x2 S1 E9 V( N+ Jouttextxy(x, y, msg);
+ |1 D3 ]; P/ {0 W( H' w) ?2 qgetch();
8 [9 J3 A3 l9 i8 v3 z- P0 y} </FONT></P>
' k4 T+ C2 @) v3 S$ {. H5 t<P><FONT color=#0000ff>/* clean up */
* S1 F9 \7 y! c9 t" v1 x- w$ uclosegraph(); " \* [! T. U% V4 m5 R# @6 C
return 0;
; E# B/ y8 q5 c} </FONT>) e: Z  R) L5 R+ |$ D* N/ K, S9 ?! y' d

4 n0 ]# ^9 W( F2 V</P>
6 s/ w0 t0 y( y! d7 v<P><FONT color=#ff0000>函数名: setblock </FONT>
4 f+ F) W8 H9 z+ m% N+ X( j8 H功 能: 修改先前已分配的DOS存储段大小 + F) [8 a1 ?; K% W# |+ s8 ?6 G
用 法: int setblock(int seg, int newsize);
7 j' ~# j! b0 t+ X( y8 p程序例: </P>& f" P3 w; p2 U2 ~
<P><FONT color=#0000ff>#include <DOS.H>
. s  w9 R$ C2 ~6 v8 _9 ~1 p3 a: B#include <ALLOC.H>: t" A3 ~3 o( b2 \; Z
#include <STDIO.H>0 i2 E* }6 q% w2 S) V' f$ P
#include <STDLIB.H></FONT></P>
  V+ M) ^: E6 g: r5 k<P><FONT color=#0000ff>int main(void) # ?# D$ @1 P7 r, l5 f
{
2 J0 F2 z! h: O0 O% g# m; b. Sunsigned int size, segp;
' a" \" j2 u( k1 S% gint stat; </FONT></P>3 w7 M" h2 o' U3 n
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
# L. {5 A3 E0 _3 o1 rstat = allocmem(size, &amp;segp); - h7 J, u! u- V  p
if (stat == -1)
1 L7 M2 U& }; h' R1 k6 Rprintf("Allocated memory at segment: %X\n", segp);
: ^- F; |. ^- ~; R. N/ O4 Welse
# x" }; @0 v  \{ , I1 u3 W+ r3 j6 f3 ~9 T3 d
printf("Failed: maximum number of paragraphs available is %d\n", 3 i7 x# P" ]; l4 F' w! Z
stat);
$ d7 H; Y* y- _" Z2 Uexit(1); ; p- W" o7 J1 ~# L+ u- l
} </FONT></P>, Z0 L) V+ _2 M' o2 w& N
<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
& j/ j7 G5 V2 m) Q0 ^if (stat == -1)
! b- {7 H6 }) v8 cprintf("Expanded memory block at segment: %X\n", segp);
/ S/ m' K% H# l4 p  a* Aelse 9 p6 d  b) P3 g: _5 D
printf("Failed: maximum number of paragraphs available is %d\n", ; v; l# C, @& |- @6 K
stat); </FONT></P>
; x$ l2 i3 d$ t3 ?7 |# g' k. s6 E<P><FONT color=#0000ff>freemem(segp); </FONT></P>
( {( V/ }" k' e% y& \1 Q# o1 S<P><FONT color=#0000ff>return 0; ) [9 N9 J9 N8 U, Y5 [, @# z  R1 `7 i
}
, [; b& H0 O6 s# G</FONT>
; _1 \# q" ]6 S6 N4 R</P>
0 @0 V5 G$ d& {! _<P><FONT color=#ff0000>函数名: setbuf </FONT>
. C3 {1 W- y( w: |( u# Z. Q功 能: 把缓冲区与流相联
% t! t3 C8 J$ K用 法: void setbuf(FILE *steam, char *buf); ) X1 T( Q6 G3 U) v; \  K1 C
程序例: </P>
( C# a/ q9 ^/ r7 y! \$ `<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>, A6 ], R  a. ~9 F& n6 }
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ / W# G( e! @8 ~& r5 |
char outbuf[BUFSIZ]; </FONT></P>% t. {& r. M/ v& Z6 {% Q% M
<P><FONT color=#0000ff>int main(void)
  |8 t+ n; e5 ]* U{ ! Z$ Y1 c5 x7 s/ I7 @) k: V8 D
/* attach a buffer to the standard output stream */
/ l% w9 J. `% G# k8 g# fsetbuf(stdout, outbuf); </FONT></P>
, y/ v, _& w6 e3 C  Y<P><FONT color=#0000ff>/* put some characters into the buffer */ / h( w: i/ |6 @8 o4 v2 e
puts("This is a test of buffered output.\n\n");
. b" Q4 r, \" B3 ?* bputs("This output will go into outbuf\n"); % y. D( K* m! e
puts("and won't appear until the buffer\n");
( [  {) U  |# }% Dputs("fills up or we flush the stream.\n"); </FONT></P>
6 V5 w$ d8 P: ?0 f; [0 l/ p<P><FONT color=#0000ff>/* flush the output buffer */ 5 |: D$ F2 ^7 {! P$ ]5 N" P
fflush(stdout); </FONT></P>. i9 W% P; m. Q; Q
<P><FONT color=#0000ff>return 0;
2 V( T8 u5 Q, x}
9 J/ j6 B4 _1 {8 F</FONT>! H4 l. J, N! n1 d
</P># h) K. w0 M& m; X- n9 {
<P><FONT color=#ff0000>函数名: setcbrk</FONT> 9 `: H, K6 H2 I, W9 }9 s& X$ b
功 能: 设置Control-break
/ V0 y; H# B: V7 J+ d1 U用 法: int setcbrk(int value);
  A; v4 v" I. S0 _- r+ f/ d# @程序例: </P>
# o/ d$ ?+ V' M<P><FONT color=#0000ff>#include <DOS.H>
6 S4 p' v& H; Z6 ], s! [#include <CONIO.H>
4 I! z: Q3 {$ ?1 m#include <STDIO.H></FONT></P>
" o$ O& c0 F! ~5 e2 F) s; Y; c<P><FONT color=#0000ff>int main(void) * O0 w0 @# ?( T/ S6 B9 W$ w- n* n1 s7 |
{ # Z$ c6 I5 ~% A& N. g4 A# Q. x
int break_flag; </FONT></P>! m  g& j5 d" b$ L
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
4 }5 I7 P  h- A  _$ Nprintf("Enter 1 to turn control break on\n"); </FONT></P>
7 ^% q; L7 G. R$ L) k9 n<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>" d; }6 V2 z6 ~0 R8 D
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
3 C8 b# I$ i* G) b<P><FONT color=#0000ff>if (getcbrk())
* p6 D4 h7 w% m$ }/ p8 |+ Qprintf("Cntrl-brk flag is on\n");
0 M) b8 X! `' e6 ]+ X) aelse
7 c8 m' J9 a2 |8 s% O1 Uprintf("Cntrl-brk flag is off\n"); ' g+ Y" n* B1 d. ~, }7 ?1 u
return 0; . E9 N3 |/ b9 w+ j
}
" @6 g# W' R/ M6 z7 B. r- W" q" v! c5 Q6 ^2 m2 w  J5 b% l/ f
</FONT>
& v% Q$ X; W' S; Y</P>0 t: i3 \2 D$ F
<P><FONT color=#ff0000>函数名: setcolor</FONT> ) T5 W% m" J+ B3 Y; C2 U, \
功 能: 设置当前画线颜色
- y6 [+ y$ s: M用 法: void far setcolor(int color); * C2 L* t% q. g5 e3 Z& k9 _
程序例: </P>8 }# q$ f2 ]% r+ `" _: ~
<P><FONT color=#0000ff>#include <GRAPHICS.H>* j& ?3 v- y1 S* C; p
#include <STDLIB.H># c. a' X% h$ v0 D
#include <STDIO.H>
1 ?- L( V" ?5 y; E/ f& x$ P#include <CONIO.H></FONT></P>
1 I$ P* J- q) c) w8 W<P><FONT color=#0000ff>int main(void) ( x$ y% l+ j( e
{ " C: g' t9 Z4 B9 ]
/* select a driver and mode that supports */ * T# Q8 |9 E1 @1 }2 G
/* multiple drawing colors. */
. v& q+ K  V7 N- Jint gdriver = EGA, gmode = EGAHI, errorcode;
! c/ V' J: Y9 l/ b8 s. H* |& {int color, maxcolor, x, y;   g+ A2 _% l# z$ ^, e
char msg[80]; </FONT></P>
2 ]; v; O$ n/ K, u<P><FONT color=#0000ff>/* initialize graphics and local variables */
& C2 ?2 K# Q" [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. c4 O" r+ Q! I, k( b
<P><FONT color=#0000ff>/* read result of initialization */ ) u# t4 L" K; U6 f  v
errorcode = graphresult(); + A) W* G. w* B
if (errorcode != grOk) /* an error occurred */   m( Z9 o; E$ B3 K) l
{
# c' u) U' C4 Qprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 |# G+ J/ A8 z+ @* k1 i9 k
printf("Press any key to halt:");
8 `! b. o+ m- \0 R/ K. ~getch(); $ A" I6 U  T1 x5 \; |/ M5 T
exit(1); /* terminate with an error code */
% o% F3 E& L4 F: G} </FONT></P>3 s: F1 j  N. w" j0 B5 n% r
<P><FONT color=#0000ff>/* maximum color index supported */
: q8 R) M$ `2 S; ]maxcolor = getmaxcolor(); </FONT></P>; `$ Z# P1 T* x4 {; Y2 o, g* \- |! S
<P><FONT color=#0000ff>/* for centering text messages */ 9 H* d) p* {: u' V1 ]
settextjustify(CENTER_TEXT, CENTER_TEXT);
) v; }$ j4 A" f6 {& x" F2 ux = getmaxx() / 2; 0 {+ K9 X0 ?! J7 ?. B( u+ d
y = getmaxy() / 2; </FONT></P>
* u- E: F6 [' k: m& Z8 O/ J2 r<P><FONT color=#0000ff>/* loop through the available colors */
8 v. a4 x: l' M7 Qfor (color=1; color&lt;=maxcolor; color++)
- U4 b! q/ `' E! [{ - `) G, \# j, S
/* clear the screen */
. B+ {  j. r+ x1 |0 F/ ]7 ^cleardevice(); </FONT></P>6 C! T) d! _- v9 x2 {; e( v
<P><FONT color=#0000ff>/* select a new background color */
! X* q7 b: p. W/ X3 S( ?setcolor(color); </FONT></P>+ c- P" M$ ~7 ]+ Y4 ^8 N/ h( ?1 }
<P><FONT color=#0000ff>/* output a messsage */
7 H* b6 O& k% E$ \7 z2 Q. jsprintf(msg, "Color: %d", color); 1 o, C& F0 K& O* n. S# y. o
outtextxy(x, y, msg);
: Y( Q# D$ R8 w6 Ygetch(); 9 z7 C5 s' k+ c- a+ O
} </FONT></P>
& b( D% ~; r6 @0 C8 D<P><FONT color=#0000ff>/* clean up */
3 q+ b' B8 q8 [% Q. Tclosegraph();
# P$ g3 [# G% r) s3 T( dreturn 0;
+ b; `8 H; z- j/ r  E}
7 J; y% `. ]  E</FONT>
- I6 g9 b- L5 M3 `0 A6 Y</P>
2 P1 b# _8 r2 z+ V7 S2 E* v0 a<P><FONT color=#ff0000>函数名: setdate </FONT>
& c  n9 s0 }0 j, _4 G2 N功 能: 设置DOS日期 $ d* N2 J: c: g' o
用 法: void setdate(struct date *dateblk);
) V) r6 Z$ v& |! ^( @程序例: </P>* E4 }6 q# V( U% M$ _2 ^, p
<P><FONT color=#0000ff>#include <STDIO.H>/ n: X5 k( @6 v- x0 {+ y
#include <PROCESS.H>
! B* B  J  X8 y  k  s3 P! e#include <DOS.H></FONT></P>$ ], N2 f2 r6 z% b" s( H
<P><FONT color=#0000ff>int main(void)
7 j7 v  m5 B# O2 o2 Y, `5 N+ o6 U{ ! W; F& ^3 T8 Y$ G2 i
struct date reset; 4 p/ [: C2 [# i9 m4 }
struct date save_date; </FONT></P>
" [& t/ ?+ _; I' X/ a* s<P><FONT color=#0000ff>getdate(&amp;save_date);
3 F1 n2 b" Y6 ?6 c7 E% u( L1 s5 Mprintf("Original date:\n");
- K! S7 @8 J& ?system("date"); </FONT></P>3 Q0 D  V/ P9 ~
<P><FONT color=#0000ff>reset.da_year = 2001;
2 A- W5 Z6 u: [2 t9 J4 M9 Preset.da_day = 1;
. \9 u6 P6 A5 k5 @9 n3 |6 sreset.da_mon = 1;
3 p% J* Y! K) m/ zsetdate(&amp;reset); </FONT></P>
7 {& t) m1 ~9 }5 g( ], _! ]" j4 z<P><FONT color=#0000ff>printf("Date after setting:\n");
! O8 `- f0 F$ X9 a, Msystem("date"); </FONT></P>
9 @5 W% z- b# `<P><FONT color=#0000ff>setdate(&amp;save_date); & S# o0 S! j; C6 h
printf("Back to original date:\n");
' j2 q  N3 n1 {1 @( {: O' Osystem("date"); </FONT></P>
3 U  t! @& h) {  U( F8 p  h/ g<P><FONT color=#0000ff>return 0; % u' L9 c# Y5 @6 A! a  `+ f# H
} # b7 ?0 t" b( q& ^& R7 H+ ^& M
</FONT>: d4 P$ b4 B) r" D# D/ U
</P>% Y; ^3 P" I2 Z1 F1 P
<P><FONT color=#ff0000>函数名: setdisk </FONT>% k0 Z% g: q) v( U& y: H
功 能: 设置当前磁盘驱动器
; \2 r' J, ?. g. w: d用 法: int setdisk(int drive); . V* _# D( x7 H5 ^5 v' Y
程序例: </P>
- O2 k" Q6 {5 t<P><FONT color=#0000ff>#include <STDIO.H>
1 n- }  `6 q' R* j  w#include <DIR.H></FONT></P>
+ W8 {& `4 |/ R" B$ J<P><FONT color=#0000ff>int main(void)
( N! h+ k* k1 Z4 d; p; |{
$ t& O2 `" A- w, _1 s) c" |8 r) c5 ~int save, disk, disks; </FONT></P>
8 ?+ B% M$ i0 p<P><FONT color=#0000ff>/* save original drive */
" v; ~; @) y7 j8 d  V# h/ q9 i2 asave = getdisk(); </FONT></P>
: R9 E5 M, m" j$ S<P><FONT color=#0000ff>/* print number of logic drives */ 3 |0 q+ d( q, {
disks = setdisk(save); $ ~- c1 O& h  b# ^' Z
printf("%d logical drives on the system\n\n", disks); </FONT></P>" u$ m$ X& P- w8 E
<P><FONT color=#0000ff>/* print the drive letters available */
% q+ d( f6 h& ^! L$ ?- P# hprintf("Available drives:\n");
" u& H3 l" Y" ~- C+ Tfor (disk = 0;disk &lt; 26;++disk) 0 T9 ?2 A2 P" @5 [; f3 }
{
( ~1 b/ R( r$ g1 M4 R: |/ [setdisk(disk);
) u& r9 p  T: U3 C. qif (disk == getdisk()) / L+ e- K+ `0 M/ o. k* p
printf("%c: drive is available\n", disk + 'a');
1 z4 ?2 ~. H6 E4 u( t' D}
4 F1 ~$ f# O& t6 |' z2 tsetdisk(save); </FONT></P>
+ |: R4 r6 i% k$ x<P><FONT color=#0000ff>return 0;
1 T3 `2 S1 {& N3 m} </FONT>: _% U. H" }0 B

+ |. V7 Q8 F# j</P>
* w' t% h$ s% K7 \8 {8 T8 l$ x4 D% d<P><FONT color=#ff0000>函数名: setdta </FONT>
& ^% f9 s1 s* m. E" `# D6 L功 能: 设置磁盘传输区地址 7 M+ M: i& O* y0 i
用 法: void setdta(char far *dta);
1 U! u, o$ u1 |  ^3 q程序例: </P>
% o1 b) ^6 v8 q9 e' Y9 K/ k' K<P><FONT color=#0000ff>#include <PROCESS.H>4 n6 {) r/ j" V1 h4 `' ~, K
#include <STRING.H>
& ]: I: d6 Y2 n( Q9 \. X#include <STDIO.H>
: j" m/ M! @/ b/ O- V& y, g#include <DOS.H></FONT></P>
7 Z% A2 ^+ K3 I) R<P><FONT color=#0000ff>int main(void)
4 t4 Y, M, i4 M3 \7 A( R{
( D6 T) J. T3 y% M9 e1 Ychar line[80], far *save_dta; 5 s+ W& G4 T- F3 I5 U
char buffer[256] = "SETDTA test!"; ! u* J, L( n# x( e
struct fcb blk; $ J# z* l5 c* O: J
int result; </FONT></P>
  P0 I) b  E6 D4 g  H! A. J" Y<P><FONT color=#0000ff>/* get new file name from user */
: g: q3 b: |$ ^% K1 m2 e. S; Mprintf("Enter a file name to create:");
2 M6 r2 ]' b+ M: B: Ngets(line); </FONT></P>5 a2 ?' a3 I; |3 M
<P><FONT color=#0000ff>/* parse the new file name to the dta */ , [1 g! v& n2 H7 ^% Z/ K
parsfnm(line, &amp;blk, 1); ; D% p, M2 X9 m" m
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
7 M$ h" R3 l% _+ N# q' o<P><FONT color=#0000ff>/* request DOS services to create file */
6 P9 Q+ ?: `) A/ a; r( M6 Y" B5 dif (bdosptr(0x16, &amp;blk, 0) == -1)
. u( `) d1 {9 h/ e, F{
) f4 |2 G- I* }perror("Error creating file");
& d3 w6 n6 e- Zexit(1);
. P3 H. B' V4 L' I( u2 V  `  t} </FONT></P>. e: V# c& C4 H% [+ z' g+ [
<P><FONT color=#0000ff>/* save old dta and set new dta */
" ]& R) m) a: u  R( @* y  }4 nsave_dta = getdta(); : `2 ?$ }# [  O8 c6 Y8 f$ {
setdta(buffer); </FONT></P>
" i' o% @3 t! w( Y) Q5 M4 ~<P><FONT color=#0000ff>/* write new records */ : Z- P8 X$ ?3 k$ x$ b6 d; Y
blk.fcb_recsize = 256; 4 h& g# `, B( i# N- r
blk.fcb_random = 0L; * M& \. C( e. O. B, B
result = randbwr(&amp;blk, 1); : l5 e4 h& O4 `- }/ D# }, b  j9 c
printf("result = %d\n", result); </FONT></P>
, a, d2 `( @( Q<P><FONT color=#0000ff>if (!result) 0 K, c( l/ L5 x7 U) t
printf("Write OK\n");
9 k! F% @. H( Q% _else " O! _$ P) r. |6 }2 U* M# I
{ ( {( n# w  r/ A) @3 m
perror("Disk error");
2 y$ C+ w) j9 \0 w& {- L9 ~exit(1);
8 H4 s! k; M0 [% Z+ L} </FONT></P>7 ^% Q+ ^* I$ |! E0 P$ l" i) e
<P><FONT color=#0000ff>/* request DOS services to close the file */
* p3 h1 a' ]& B+ X$ z; D4 o( C2 Rif (bdosptr(0x10, &amp;blk, 0) == -1) " F9 ~# C- F. P. P8 X
{ % e: Z- U" L1 e: E  S0 f
perror("Error closing file");
$ H( d- `8 h  S8 I. R, a2 Zexit(1);
* c/ |; W0 x* Q+ I0 Y4 v} </FONT></P>4 i1 Z2 Q; B' [9 s8 J
<P><FONT color=#0000ff>/* reset the old dta */ , k  k3 b" U5 j" v3 R: _
setdta(save_dta);
/ F5 `9 W3 M6 Z6 c' hreturn 0;
( s  j4 \. ~: x' v" ?5 Z2 L}
. ?' n/ t6 R) F& [</FONT>
: b3 i6 {1 l; B$ O4 P6 q; z</P>! Z' {% g2 ]8 }
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
$ o4 [) j6 [6 O* D- T6 m功 能: 选择用户定义的填充模式
+ `8 X  h1 b; w! @; L' [用 法: void far setfillpattern(char far *upattern, int color); ; W8 g, `- ^* @- V" s
程序例: </P>
( B0 ~; o9 k+ B, [<P><FONT color=#0000ff>#include <GRAPHICS.H>5 w& o$ i* h* Y7 E, {# r4 X* T
#include <STDLIB.H>' |* [4 q% V& u% o2 v& r
#include <STDIO.H>8 h# ^! B  d- ^7 Z4 s. n. A
#include <CONIO.H></FONT></P>
8 ]% g, Y5 T* }7 R- ]# X<P><FONT color=#0000ff>int main(void) ) r% T7 T2 B! ?! n# V
{ 4 v6 h9 q4 {4 N- h
/* request auto detection */ 2 [/ _( c) j* `1 B0 d4 I
int gdriver = DETECT, gmode, errorcode;
( q/ \8 Z4 G% B: `1 yint maxx, maxy; </FONT></P>: Z5 F. K% v: r% `$ A8 ?+ \) {
<P><FONT color=#0000ff>/* a user defined fill pattern */ 6 C. q5 l$ e! n/ Q
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>, K* o" F0 f/ P2 u0 X( }$ b$ w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 {0 ]1 B- P4 c5 a' Z: |8 U& s3 t, K. winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 k) k) S- L% e( a7 o: o
<P><FONT color=#0000ff>/* read result of initialization */
4 y+ L  Q, y- Q) T% E/ Qerrorcode = graphresult(); 6 T9 u, @) D( Z! A/ R9 d$ I
if (errorcode != grOk) /* an error occurred */
: Z- f6 s4 k/ Y# @7 E5 `; p{
  j6 i+ r1 N1 w3 Z) D( Nprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 t4 y) P. L; T& k
printf("Press any key to halt:"); ; V5 q. p6 w4 V% R0 s5 a: [
getch();
& a9 j+ y& a* o# N& u0 Gexit(1); /* terminate with an error code */
# H4 B' U. z$ n/ ]/ q  `} </FONT></P>/ J  p0 }. R6 h' G$ {- l" V
<P><FONT color=#0000ff>maxx = getmaxx();
2 n# R8 e7 y1 Fmaxy = getmaxy(); 1 @$ {+ S$ m( `" B) n
setcolor(getmaxcolor()); </FONT></P>  Q1 A8 {2 t. a; O; l
<P><FONT color=#0000ff>/* select a user defined fill pattern */
$ u4 X! @: l( D) ^( Xsetfillpattern(pattern, getmaxcolor()); </FONT></P>
" K, H( d7 q6 J, d, W3 }<P><FONT color=#0000ff>/* fill the screen with the pattern */ " H" e0 n6 P! m+ n+ F' s; l6 t
bar(0, 0, maxx, maxy); </FONT></P>0 w! R/ B$ l6 D
<P><FONT color=#0000ff>/* clean up */
5 ?6 z8 C* `& f4 `) sgetch(); 3 `" T: {4 W/ S7 g8 k
closegraph();
$ y, b( L: u5 i8 |3 N  c. }. ^return 0;
3 z$ `- q" T, {, @! v! z}
! e& s: T# n9 e- Q5 u% C" e' I</FONT>
% d6 g: m# C. D</P># o' E& L1 c0 P/ e
<P><FONT color=#ff0000>函数名: setfillstyle </FONT>- N6 H, z% x+ @0 Z
功 能: 设置填充模式和颜色 ! m3 c/ |  z& b( O* y" c1 w4 z
用 法: void far setfillstyle(int pattern, int color); & {% _# o  M) q7 q* E& l
程序例: </P>3 a1 n) n8 b$ W  u' x
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 P% f- A  A3 g. x" r
#include <STDLIB.H>1 W; o/ U1 y9 S; D6 x  {% J
#include <STRING.H>
6 ?7 m0 e1 ?0 E4 b! h2 d#include <STDIO.H>
$ {' |) b& r/ ], T3 b% \: x#include <CONIO.H></FONT></P>( a& ?. g  |  `
<P><FONT color=#0000ff>/* the names of the fill styles supported */
3 C$ k9 A/ `  ?2 T7 x; ]* Mchar *fname[] = { "EMPTY_FILL",
. \; y3 u5 K4 {% q. P"SOLID_FILL",
( j- q0 D0 F, X( g- t$ X"LINE_FILL",
" X' ]  ]7 w, H# D"LTSLASH_FILL", 2 q' f* L  j  `
"SLASH_FILL",
) K% c% l7 t: O3 u% f2 a5 |. h"BKSLASH_FILL", 3 P1 w" u  ?3 m; X& F# ]; m
"LTBKSLASH_FILL", 6 A& I, q3 r; f' x
"HATCH_FILL", ; t, }( s; I$ K2 V' ^
"XHATCH_FILL",
5 |9 [# H! |& f7 y"INTERLEAVE_FILL",
  S/ t3 {1 b8 i  }" n  z! O" T"WIDE_DOT_FILL",
2 o/ j6 K) ~" B"CLOSE_DOT_FILL", ; t# x$ K* i" H! r- ]
"USER_FILL"   G! _& E  d" {5 B7 q7 |
}; </FONT></P>
! |/ A# Q1 I5 H! o<P><FONT color=#0000ff>int main(void) & |% R8 Q) C0 p+ T
{ 8 z1 s3 s9 j  [9 m3 `
/* request auto detection */
" u! V* e1 s$ \/ `3 o! z* Xint gdriver = DETECT, gmode, errorcode; # x% T4 Y1 J2 t- q
int style, midx, midy;
; @4 O+ Z8 J4 q& ~; M3 @4 achar stylestr[40]; </FONT></P>2 T/ b, t9 o6 ^" l4 P# x
<P><FONT color=#0000ff>/* initialize graphics and local variables */ & D% m- b1 |/ ~* {5 h, |2 F
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 Y! e4 W1 ^- a6 y  s: a5 B" y<P><FONT color=#0000ff>/* read result of initialization */ % \9 z8 v7 S3 N4 i8 `, L
errorcode = graphresult(); * G8 g7 K$ k" i7 H( ~- d2 I
if (errorcode != grOk) /* an error occurred */
1 c7 ~9 J( O0 M& d$ r, {8 A2 q$ N{
  O! S# Q0 \. |2 Y7 V8 [* j0 zprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' B1 R% O7 l1 u) R, i' _" Qprintf("Press any key to halt:");
  `4 i8 P* u' O, O) _getch(); . \- C* i5 s- q+ E3 M6 _& m9 m
exit(1); /* terminate with an error code */
3 J6 q4 f3 F8 P. q} </FONT></P>9 ?& @$ z/ l( \  Z
<P><FONT color=#0000ff>midx = getmaxx() / 2; , @) m3 O+ D5 n1 ^' S
midy = getmaxy() / 2; </FONT></P>, ?6 G) E. [: P1 C
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
2 F. j2 F& D. o% |: m; |; X{
2 _- v1 u3 D. C+ H' v% H# d3 S/* select the fill style */ 1 m  ~/ v' }0 Z" M
setfillstyle(style, getmaxcolor()); </FONT></P>
- A5 W" g# w+ n<P><FONT color=#0000ff>/* convert style into a string */ 2 n$ \, [% N( s- ]& [) ?
strcpy(stylestr, fname[style]); </FONT></P>
/ i  c2 e( H: q2 T3 M4 C' |<P><FONT color=#0000ff>/* fill a bar */ ; c$ T( S8 C3 w$ A: O3 T
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
2 P  N: Q$ h! F( A, C<P><FONT color=#0000ff>/* output a message */ + b; K6 [8 ]0 X
outtextxy(midx, midy, stylestr); </FONT></P>& Y; I# ^6 V' R. U. @& W1 f
<P><FONT color=#0000ff>/* wait for a key */
: T7 X6 g4 l6 n5 b, z, h5 k  Pgetch();
" d- |, ?( n( A9 x$ zcleardevice(); # M8 N; R; b3 V7 S7 [
} </FONT></P>: R, i: f4 A7 K' c8 P, F
<P><FONT color=#0000ff>/* clean up */ / V3 J& }7 X% B# |8 Y( h
getch(); 0 u9 ~. _2 D6 |9 S1 C  A1 L* p
closegraph();
2 Q! i0 B: ^/ J+ D. Ureturn 0;
5 G0 y4 a! c2 B% \; b( N0 B} </FONT>
' y! |8 n6 c# n) ]/ x+ e7 F; h- s* Z6 M8 q/ w% \9 [
</P>' c. W0 I4 E' D. }0 }
<P><FONT color=#ff0000>函数名: setftime </FONT>
2 c2 `' P0 \+ n( p4 q功 能: 设置文件日期和时间 3 G7 e+ P+ e( l! A, a0 b
用 法: int setftime(int handle, struct ftime *ftimep);
) c3 t$ {+ ]' P3 k( S3 m" q4 u9 v) z程序例: </P>/ m6 A5 }( d  V& ~5 ~6 M
<P><FONT color=#0000ff>#include <STDIO.H>
3 F  I5 J; Z6 t$ q, O/ ~#include <PROCESS.H>6 a' Q, o( |( w$ v; X  Y/ y4 S
#include <FCNTL.H>
5 M, R! L( f, t, r  l/ }! |#include <IO.H></FONT></P>
: ]' ]& t! F, ~0 q<P><FONT color=#0000ff>int main(void)
/ T; q4 b7 c1 q" a' Y! j: K{
- T) }" `" X( ~2 a- qstruct ftime filet; 4 X: L" R) d- A. K
FILE *fp; </FONT></P>- f% F* O5 X' P0 p3 k. J9 Z! W; D
<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) $ `7 @  s8 e, q% T
{
0 O% i6 m" W' D! x# {7 S& @) q$ jperror("Error:"); 3 x! a  v) S" p1 ^4 P
exit(1);
% A" R) y3 k/ k* o( v* s( x# V} </FONT></P>
# Q% R8 d0 F$ V  t9 f<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>; F9 S% |! x% `; S* a3 v
<P><FONT color=#0000ff>/* load ftime structure with new time and date */ 0 c2 k7 j: m- J% }1 [0 T, |  H: ^; y( g, E
filet.ft_tsec = 1;
7 z3 U$ E6 @" @  @' Mfilet.ft_min = 1; 1 g; ^$ C* l! q" D
filet.ft_hour = 1;
7 f5 b8 u- x: E, R% m6 c% R4 efilet.ft_day = 1;
" X! A/ Y) D0 y0 Q3 \filet.ft_month = 1;
$ r' }% K! F' mfilet.ft_year = 21; </FONT></P>
2 t9 t5 j! p. X" S$ K8 Z8 W<P><FONT color=#0000ff>/* show current directory for time and date */ $ S5 O" J( t1 [; @6 B+ R
system("dir TEST.$$$"); </FONT></P># ^1 N2 V! t4 s, ?
<P><FONT color=#0000ff>/* change the time and date stamp*/ / [# z( v. m0 f" b$ t& a. G  t
setftime(fileno(fp), &amp;filet); </FONT></P>" k% v. }% c5 r% @
<P><FONT color=#0000ff>/* close and remove the temporary file */
$ e7 U! V$ N" U& Yfclose(fp); </FONT></P>5 Q# S# H6 H5 c4 y! W$ n( ^
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>) J2 F: V" O4 {3 u2 C# N9 |
<P><FONT color=#0000ff>unlink("TEST.$$$");
( O& l# }6 I: d$ @return 0; . g0 c( l- W6 ]: v! J: D. {5 h& s/ j
}
/ y  B8 }0 w. _0 ~  I. C</FONT>$ Q8 L2 \# V0 D
</P>
8 F8 P+ k8 t! O6 R) f<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
7 i, z& j. {# w功 能: 改变内部图形缓冲区的大小 $ g: v, P: S, n. ?
用 法: unsigned far setgraphbufsize(unsigned bufsize);
; }# y9 U% m/ A1 j, i9 `程序例: </P>2 g% ^! U8 V7 h) f: ^6 @! R, P' J0 P
<P><FONT color=#0000ff>#include <GRAPHICS.H>( x1 N* v4 ]4 q, M" @
#include <STDLIB.H>( n. L2 O; _. _9 k: I# _" Q7 n
#include <STDIO.H>1 k! U6 f6 Y0 @9 x/ [7 u: G
#include <CONIO.H></FONT></P>
' Z( o7 J7 [0 R" p& e# e<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>+ N& Y6 c& Q" Q
<P><FONT color=#0000ff>int main(void)
% v# N2 |! O, k{
# V# B; c3 R+ h5 v) S( P/* request auto detection */ 3 A3 i$ T& ]7 d5 V
int gdriver = DETECT, gmode, errorcode; " T2 y- J" f- h1 p1 L
int x, y, oldsize;   w  K( C! r/ l, C7 |4 x7 w1 O3 ?3 ?
char msg[80]; </FONT></P>
5 U' ~; K: k* ^$ M<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ 6 \' [. o2 l. ]3 m! s# S$ ^
/* before making a call to initgraph. */
* v% @3 a# W0 ]oldsize = setgraphbufsize(BUFSIZE); </FONT></P>
, D; N* J: b& m<P><FONT color=#0000ff>/* initialize graphics and local variables */ * w- I7 r$ @5 ?$ P1 O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, f+ P2 D/ z+ Q# U<P><FONT color=#0000ff>/* read result of initialization */
9 F& t0 g( l( l3 O; f8 w6 G  cerrorcode = graphresult(); 6 Y1 [9 L5 {  F0 m
if (errorcode != grOk) /* an error occurred */ 5 N/ P9 ]9 l* ~. b" M4 B
{ 7 k$ O' w. `; }( J1 @
printf("Graphics error: %s\n", grapherrormsg(errorcode));
! h) X  p& a. I: \3 ~9 d+ Yprintf("Press any key to halt:");
. ]$ d* @0 s- J2 ^$ V, |0 }getch(); * e$ h, S" J0 K
exit(1); /* terminate with an error code */
- ^8 B" t. G+ I! M  r( u0 Z} </FONT></P>
/ F/ b: {3 i/ I* P! p5 i* m2 L/ `- U<P><FONT color=#0000ff>x = getmaxx() / 2; 0 Y) C+ F2 |, B6 j" o: V
y = getmaxy() / 2; </FONT></P>( G5 f: H; N, b0 ~! u
<P><FONT color=#0000ff>/* output some messages */ % \/ C7 U: d2 |- d5 M  T
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
' ]$ I* \9 Y, u. v, R; Zsettextjustify(CENTER_TEXT, CENTER_TEXT);
4 q* I1 C; x0 [; ~' n* |outtextxy(x, y, msg); . l, g9 Q# \% C2 u1 W6 z) a9 q+ _' e
sprintf(msg, "Old graphics buffer size: %d", oldsize); / p' F7 `" G7 A
outtextxy(x, y+textheight("W"), msg); </FONT></P>- t  \7 w/ c* f9 Z3 \) V3 o
<P><FONT color=#0000ff>/* clean up */
7 r& ^  P0 p6 lgetch(); + j# g' z' Z8 u7 M8 r, ]% s5 n. F! {
closegraph();
- D3 P* Q: H  q$ g- qreturn 0; 7 r: y5 w0 z0 y7 D1 _
} * }2 v2 E2 F$ }: P' {& Q

% S/ T3 h5 \2 A7 a9 T9 S5 _+ @6 j
</FONT></P>
/ U+ `" M( g- q! @& v3 S. U7 k; C<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
/ p+ E& t8 ]6 h( E) U7 U功 能: 将系统设置成图形模式且清屏
4 L3 M+ R: ^' \# x& y用 法: void far setgraphmode(int mode);
1 c! s9 v% r7 j9 m4 r; C- s程序例: # ^+ `4 V" i9 k1 E9 c
; a7 d- F9 V. e1 X
<FONT color=#0000ff>#include <STDLIB.H>
( Q% j$ L9 \0 ]- u; y* z; {' ]7 I#include <STDIO.H>
2 B4 |1 t' _+ [6 w; I#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
0 y& l/ x9 P7 p& f; U# y6 P<P><FONT color=#0000ff>int main(void)
& w+ b& U' ]. f" E{
5 M- {# b! p1 _0 m( \/* request auto detection */
% q5 p5 A: ^) ?' Hint gdriver = DETECT, gmode, errorcode;
7 B) @& d6 K' A" n% ^int x, y; </FONT></P>* `6 }1 ?+ L7 q  e' A4 C' w# f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
! k0 G7 z  v; D4 I" {8 e% ]- Tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 m& S3 k6 {. g3 h% {  H<P><FONT color=#0000ff>/* read result of initialization */ ; m! a, k3 K: J% ?2 C
errorcode = graphresult(); 4 y6 E9 N- Q; I8 T' @$ A
if (errorcode != grOk) /* an error occurred */   O6 @; E+ C1 Z  @
{   [2 x: f0 b# |8 d4 k- G9 |2 @- l
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 E: v& n5 z. {  E
printf("Press any key to halt:"); ! E( G! I5 |4 h! Y
getch(); ) p4 b4 f* ?; N( l4 R/ i" \" P6 N
exit(1); /* terminate with an error code */
8 A6 e9 u3 A3 O- ^4 E. q) [/ Y} </FONT></P>
: ]1 E" ?7 W* S$ R6 b<P><FONT color=#0000ff>x = getmaxx() / 2; 7 q1 c  q$ a; f; K
y = getmaxy() / 2; </FONT></P>
$ v! f$ |0 C8 f" O) _<P><FONT color=#0000ff>/* output a message */
! Q7 u1 H1 b% N% |1 xsettextjustify(CENTER_TEXT, CENTER_TEXT);
! W6 h; a0 c. ^5 ]: ]2 souttextxy(x, y, "Press any key to exit graphics:"); 7 X. D: a0 ?& N6 `6 U, T5 q
getch(); </FONT></P>
  G7 W5 ^% m# q* _7 u<P><FONT color=#0000ff>/* restore system to text mode */
9 B) i  e" K: Y. R4 Qrestorecrtmode();
! d( d* ^6 M: H2 W& pprintf("We're now in text mode.\n"); ; Y  L  P2 S+ y2 I* T
printf("Press any key to return to graphics mode:");
) Q# n5 |6 f3 m) ^3 `getch(); </FONT></P>$ f9 `  R$ Q1 r9 A. K+ X$ J
<P><FONT color=#0000ff>/* return to graphics mode */
) E: o9 L0 |* E" F3 `. D/ Csetgraphmode(getgraphmode()); </FONT></P># C6 |+ q* {0 z# l( X3 k( p+ ]+ Q
<P><FONT color=#0000ff>/* output a message */ * O' d4 H& B9 b
settextjustify(CENTER_TEXT, CENTER_TEXT); % p4 Q% W! s. {& R1 o
outtextxy(x, y, "We're back in graphics mode.");
# }5 J- c: p, [" Louttextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>1 H: d' h" B, Z
<P><FONT color=#0000ff>/* clean up */
+ O. `3 l% O) F! }8 v% |getch();
4 {5 s5 a( }" Nclosegraph();
3 `# S% `( q1 Jreturn 0;
5 b' s# ~; u* P2 ?}
, P. Y  N# A* j) }0 h$ h$ }6 G" b5 f- [4 O  ^7 G+ E+ d! [
& K' S2 Q+ i3 A6 H4 A# R3 J" g
</FONT><FONT color=#ff0000></FONT></P>- z5 \  ~0 P5 Z9 `8 i" M5 d
<P><FONT color=#ff0000>函数名: setjmp </FONT>
2 z9 U, O* `: A功 能: 非局部转移 8 G" t6 ?* _; k  D- i
用 法: int setjmp(jmp_buf env);
3 \9 z0 b# M. f# X* M& A! P6 Z9 u程序例: </P>- `8 D& I! A$ P0 }  D
<P><FONT color=#0000ff>#include <STDIO.H>
6 ]/ b( ~7 j' a1 O: V#include <PROCESS.H>
- o. e. R8 Z6 ^- P) j#include <SETJMP.H></FONT></P>. q+ N2 U7 [& z
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>' A! S8 m) ?( L+ @0 }
<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>
! ~7 V  A  D' ~% R7 i) y<P><FONT color=#0000ff>int main(void)
! w+ Y; _; Q% ?$ w8 X! N' E' r{
3 @" X' |, |' R: ^int value; </FONT></P>3 W- v( `' O" ?- J* j
<P><FONT color=#0000ff>value = setjmp(jumper); 4 C/ F, S4 U5 [2 |, V0 X/ F4 m1 r: W
if (value != 0)
5 L( s+ T" ?0 I. @. g9 V, f{
! ]; N) A$ Y, Wprintf("Longjmp with value %d\n", value); $ k2 `- U4 P  |- _
exit(value);
, b/ `1 c" U! k0 _! P# U6 k} % N8 K* b+ S3 @
printf("About to call subroutine ... \n"); * h/ A! q/ Z6 t: h# u
subroutine();
4 R; ~4 M6 E7 Q% dreturn 0;
5 l" k7 N- N) n/ i4 ]} </FONT></P>
- X8 W  Z/ T1 P2 J. _5 a2 @<P><FONT color=#0000ff>void subroutine(void)
9 h' H/ a5 h$ _0 [4 a( Z! y- x{
5 R+ c. @6 s% n- x" Clongjmp(jumper,1);
9 j9 z, P, q( U} 9 ?( Y/ Q7 D/ o$ Q7 q
</FONT>
7 G* }6 T1 J3 T. c0 k+ T! P  a</P>
+ h2 A2 ?0 G4 G$ K7 q/ p2 g3 C# u<P><FONT color=#ff0000>函数名: setlinestyle </FONT>7 E3 e! @: L! `9 l5 \
功 能: 设置当前画线宽度和类型 # B0 \8 O* m! W7 E* K# n
用 法: void far setlinestyle(int linestype, unsigned upattern);
. y, E5 b- X$ X) f程序例: </P>
+ ~* F2 y9 b1 p, B7 M" J<P><FONT color=#0000ff>#include <GRAPHICS.H>4 v+ H, x/ C  z
#include <STDLIB.H>
% S% C" k2 r( B! e! k5 i: @+ F) i#include <STRING.H>; J- o6 f( Z$ d3 i. E1 P
#include <STDIO.H>
" T2 F3 @0 Z8 D#include <CONIO.H></FONT></P>9 O1 x! y2 W( I9 H2 V% Q( _
<P><FONT color=#0000ff>/* the names of the line styles supported */
/ j2 q. I+ M" p' ^( Cchar *lname[] = { % M+ [7 B# L0 f: G: f8 Q6 w: q1 k( x
"SOLID_LINE", ( h8 ?  C* C& q% C; L
"DOTTED_LINE", % U$ G, C9 ?  V6 ?9 V7 G
"CENTER_LINE", + Z; @( X" h6 y$ S+ L7 p
"DASHED_LINE",
0 y3 a3 P, d8 m. F! C# y6 k; {"USERBIT_LINE"
" A$ E7 E8 ^% m}; </FONT></P>. w( F8 e: w1 q. d
<P><FONT color=#0000ff>int main(void)
7 c5 Q' T' q: C{
) s4 s0 R3 e9 [, L/* request auto detection */ 5 C0 s; v: d" }8 B& t, t1 J' a
int gdriver = DETECT, gmode, errorcode; </FONT></P>
+ G( a: S: Q4 `3 w! v<P><FONT color=#0000ff>int style, midx, midy, userpat; , P( r5 G; n* r7 D( ~& ^6 w
char stylestr[40]; </FONT></P>  X% p7 z+ K, O# J3 Q- z& E
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% w; R' `- x; x1 N- s( ~0 R3 Oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
- O8 Z1 _2 d2 M<P><FONT color=#0000ff>/* read result of initialization */ " U5 R# b  C& t! i1 Y* B1 X
errorcode = graphresult(); , x/ o; a) X5 p& a- \
if (errorcode != grOk) /* an error occurred */
/ o  |* u: z2 Z6 r$ X{ ' g  g# U- L8 x, k& i
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 v4 u* Q# C9 H' M# y; [
printf("Press any key to halt:");
/ I8 E/ }  p; v0 X1 F. [: l! Bgetch(); 7 R% a4 [: ]) ]5 x% q+ h% x
exit(1); /* terminate with an error code */
2 _" F. Q5 I9 B9 \# r} </FONT></P>
& ?# ~7 f! v+ i0 M" ?! I1 E( j<P><FONT color=#0000ff>midx = getmaxx() / 2; 0 k' X$ D1 k$ m& P5 \
midy = getmaxy() / 2; </FONT></P>( @. H' E& W& i6 N, r( q
<P><FONT color=#0000ff>/* a user defined line pattern */ * h0 E& X0 F6 }  w( N
/* binary: "0000000000000001" */ ! v, j$ D$ v  l" X0 `1 ^
userpat = 1; </FONT></P>5 O; y$ i& j' a0 C
<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
/ _# x, q7 Y3 l; R& R{
1 u% ^& e, V$ Q. Y/* select the line style */
/ W/ W1 I" i0 @/ fsetlinestyle(style, userpat, 1); </FONT></P>4 f% B. B" s- j* J2 G2 s3 |+ z8 A/ |
<P><FONT color=#0000ff>/* convert style into a string */
7 z# B7 a* O, _1 Q" E4 Istrcpy(stylestr, lname[style]); </FONT></P>
0 }1 C; T7 K7 `; A7 `<P><FONT color=#0000ff>/* draw a line */ 8 z! o& @3 m, X& B8 g3 B0 W) O' ^
line(0, 0, midx-10, midy); </FONT></P>
' I- e& d1 q' ~* H<P><FONT color=#0000ff>/* draw a rectangle */ - I* T! I% T8 H& z
rectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
# W5 b6 A* |# i3 A# D( m: f<P><FONT color=#0000ff>/* output a message */ 8 O' K" k4 j3 Q: F
outtextxy(midx, midy, stylestr); </FONT></P>
  g( B4 K) x4 b3 F4 x<P><FONT color=#0000ff>/* wait for a key */
' a: c4 O! S1 [& V3 B/ h9 Tgetch(); . S) a4 G0 j) t) p
cleardevice(); & d: H4 V4 x) M
} </FONT></P>
6 S1 G+ v2 _+ {, J<P><FONT color=#0000ff>/* clean up */
! V, `: V: U' ]- yclosegraph();
0 \) o( C3 I! v! Q( S3 E$ [$ m) r# P+ mreturn 0; ; d. f0 b) A+ a
} </FONT>" E( w) Z! T4 M4 D7 \
2 o0 Y. N0 D! B) X* g0 o, w

3 O6 \9 w' ^' K" x% f9 R</P>8 `( R: p- ~1 k. {( T  L8 N- H
<P><FONT color=#ff0000>函数名: setmem </FONT>% H4 g/ q7 j$ k
功 能: 存值到存储区
0 i& h( @- v, w! \$ {用 法: void setmem(void *addr, int len, char value);
+ v5 Y9 a. `9 i2 p: W  _. U  ^5 X程序例: </P>0 ^% n! L4 e. W: b2 h4 T8 h
<P><FONT color=#0000ff>#include <STDIO.H>. S5 g& o* g* @5 H
#include <ALLOC.H>
+ ~6 G1 {: s+ o" \2 j, ]#include <MEM.H></FONT></P>
4 @& a* N& n6 M4 t3 H<P><FONT color=#0000ff>int main(void)
  x- K- D$ T" `/ g' W% x{
* I6 o; T+ @6 Y9 u1 }8 N- _char *dest; </FONT></P>3 i5 _: A3 i9 X, O9 X
<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
- K  \* |' ?. e# ]3 {setmem(dest, 20, 'c');
! z: }5 H+ w  j: Fprintf("%s\n", dest); </FONT></P>
1 G9 F1 V* ^1 f9 E: F# ~9 C<P><FONT color=#0000ff>return 0;
2 C9 p# {1 A: F4 _5 Y" v} </FONT>) O* w; P$ y0 E6 X" S
' r4 ~6 B4 B; e2 ?; D$ ]; Y

4 {; V+ I" H0 I: a  \</P>
% K. m; a3 q8 ~<P><FONT color=#ff0000>函数名: setmode </FONT>+ w* F8 `! p0 Q' I. x
功 能: 设置打开文件方式
8 n% Z. d$ {. }3 ]! Y用 法: int setmode(int handle, unsigned mode);
% ^, x$ Y: a2 j程序例: </P>
- E) k- e. Q0 m# W6 e<P><FONT color=#0000ff>#include <STDIO.H>6 i0 E" J1 j( x5 c- r
#include <FCNTL.H>
. R! ^) i$ n! a4 ~2 t#include <IO.H></FONT></P>1 s" G  U2 `% H; p  j
<P><FONT color=#0000ff>int main(void) ; Y( W$ ?7 Q6 _
{
+ A/ S8 f4 ~6 yint result; </FONT></P>
8 V7 B+ e0 e$ }<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); & ~; w) ?+ \! M# w
if (result == -1) 0 ~7 u. `  J- k% a
perror("Mode not available\n"); # r% Q6 G# e) {6 a- M2 x
else 4 g( q6 S, }0 Z
printf("Mode successfully switched\n");
" t! [  v0 a* F  ^" Areturn 0;
. i1 X, X& p' i: t& }- c} 3 k2 \$ o! P3 ?) z

6 B3 C. X5 F7 N7 V' D</FONT>8 z# q$ _( q' S6 O1 B. Q+ W
</P>
* D5 G: u2 ?$ b- }  m<P><FONT color=#ff0000>函数名: setpalette </FONT>' f& h1 W+ }( C3 F
功 能: 改变调色板的颜色 : @! y/ O9 m/ w2 {! y* t- H
用 法: void far setpalette(int index, int actural_color); + M5 L  G- |  ~3 r7 A, V2 I
程序例: </P>- h$ J! W4 X$ c* U; `; m% v
<P><FONT color=#0000ff>#include <GRAPHICS.H>
' w& V& r6 v  c( ?#include <STDLIB.H>
& z$ y: h7 v& T9 {5 k1 N#include <STDIO.H>
5 C: P9 X3 ?2 J#include <CONIO.H></FONT></P>
* C: K2 c1 i2 ^) ^; ^4 v<P><FONT color=#0000ff>int main(void)
1 n  s. F6 q- N{
4 [+ K0 m8 h# A( c/ Y+ B9 M9 y7 T8 B/* request auto detection */
9 {0 s4 l) g' c: Gint gdriver = DETECT, gmode, errorcode; 0 Y- k0 X4 W" ^! o" t( p
int color, maxcolor, ht; & p  q" i/ j% Q0 E/ Z1 k
int y = 10;
* J% Q+ h& b, d3 c. P) Achar msg[80]; </FONT></P>
/ Z' F6 X+ r) D$ z" ~# W* b+ X4 [<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 M+ O0 Q& [; U& @$ n8 H5 c7 S+ L
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" X. _3 v( H+ |  Q" D
<P><FONT color=#0000ff>/* read result of initialization */
. L/ a2 ~6 I# F+ m! l2 ^4 Serrorcode = graphresult(); " F, \" T9 S% ~. I
if (errorcode != grOk) /* an error occurred */
2 X# B% k' I6 R{
/ x7 R. @& b! W5 eprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 X) ]* z1 ]: @, b+ F  d* H# c1 `1 \  W
printf("Press any key to halt:");
3 y1 ~' H3 ?. U! ]getch();
, i3 ^6 Q. Z! E8 B" f2 oexit(1); /* terminate with an error code */
) |5 g8 ^' M6 y! f" S. ]: ^6 U) B! v" e} </FONT></P>6 i: a2 {, p+ a/ y! v$ B
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
5 U5 _% h6 O+ C* G, l& B0 eht = 2 * textheight("W"); </FONT></P>4 b" g# ~4 Z; l+ V% w
<P><FONT color=#0000ff>/* display the default colors */
6 N# u$ _3 H0 \for (color=1; color&lt;=maxcolor; color++)
, V: X( T7 c7 h3 U{
% E& S+ \! l8 l" C& E/ usetcolor(color);
1 {3 m* m, }  q* y0 _/ o. Ysprintf(msg, "Color: %d", color); : i/ U) F7 m+ {( w" r) ^
outtextxy(1, y, msg);
* \/ ^% N2 o- Z) {2 m8 E" {9 ky += ht; , W7 Y# k1 o" U
} </FONT></P>6 _5 o: r0 d# ]2 A- r6 P! Q
<P><FONT color=#0000ff>/* wait for a key */ . @8 T/ H' Q0 S, h
getch(); </FONT></P>$ N& z% r% J& ^
<P><FONT color=#0000ff>/* black out the colors one by one */   b3 ^  o" Q+ }" T8 F
for (color=1; color&lt;=maxcolor; color++) $ E# K. K$ c7 b4 p) I8 X9 N6 J, f
{ / T2 p0 i: f2 Y$ O# K0 ~4 f
setpalette(color, BLACK); - G" G; }5 I7 j
getch();
: _: b0 h* J1 e' a7 F4 D% N} </FONT></P>3 p- z' C+ x1 z$ ?4 `9 E/ x
<P><FONT color=#0000ff>/* clean up */
  t, O  z4 U6 z( ~% Bclosegraph();
9 S+ Y5 n/ s; |, t( T" Q% d( lreturn 0; $ H) D) s8 s. D, v
} 7 i" \+ l' n& `8 P' ^/ H
</FONT>
9 z+ u2 J5 r$ k* ?2 x</P>
8 j, }$ E4 j% w: n<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>! Z& K7 T0 T/ ?( i2 Y4 s
功 能: 定义IBM8514图形卡的颜色
1 t; ?, u+ y0 Y& d  t4 ?2 N& g用 法: void far setrgbpalette(int colornum, int red, int green, int blue); 1 n& T: r1 P+ l, d) x  c% _
程序例: </P>
# g: @9 y# V0 F. w% g<P><FONT color=#0000ff>#include <GRAPHICS.H>  e0 _, L+ q% D
#include <STDLIB.H>$ o4 i" v3 z2 D6 R6 y
#include <STDIO.H>
# |$ c9 C$ c2 ~( T' m; N#include <CONIO.H></FONT></P>
8 N5 k. Z1 s5 x7 ?4 _6 C<P><FONT color=#0000ff>int main(void) / g$ B, p$ p; n2 F$ v( w+ W
{ ( c/ k- t0 w& A- Q  l  f7 |! F
/* select a driver and mode that supports the use */
% b5 B- p! y+ T5 q# W/* of the setrgbpalette function. */
3 R4 D/ m- j* Mint gdriver = VGA, gmode = VGAHI, errorcode; & k. u& B$ h1 ]  b
struct palettetype pal; & L" T( C3 w3 a0 N  ^7 t0 A
int i, ht, y, xmax; </FONT></P>
) j' M& j- H: r+ i$ z<P><FONT color=#0000ff>/* initialize graphics and local variables */
& R$ Q9 ?% |! Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. x( t7 q% H, E# L3 ?
<P><FONT color=#0000ff>/* read result of initialization */ 7 {$ H/ @3 W% ^' I# I: C
errorcode = graphresult(); , V- h" x( j% ~
if (errorcode != grOk) /* an error occurred */
: n4 K" Z+ O% v: y/ `9 n{ 5 {/ X( H+ I4 C7 Z+ B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- D$ N& `9 g) N+ O4 P9 F- s3 t) X& {printf("Press any key to halt:"); ) K2 a( J7 q# x
getch();
! [. s7 K# |+ _6 Hexit(1); /* terminate with an error code */ / M& c& t% [- E. K
} </FONT></P>5 h- @: x+ l& ^* Y9 }6 f. c
<P><FONT color=#0000ff>/* grab a copy of the palette */
9 q2 E; W$ C5 Qgetpalette(&amp;pal); </FONT></P>
! [: B+ b9 U% t( |<P><FONT color=#0000ff>/* create gray scale */ , ?+ d. m9 ^$ F5 ~
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
% e! r" ]! O& ~- S$ }; V<P><FONT color=#0000ff>/* display the gray scale */
5 N) b, k* b, c# v& j; Ght = getmaxy() / 16; " R2 E; v$ v( t% F. S( U
xmax = getmaxx();
' A2 j6 I5 \) W3 t$ `, Ay = 0; ; ]% D- p% S* n& ?% i7 Q- z  U6 Q' m
for (i=0; i<PAL.SIZE; <br i++)> {
! w% s5 ~& X% H( }% fsetfillstyle(SOLID_FILL, i); : |- s" c/ @% D. t0 r3 O6 d
bar(0, y, xmax, y+ht); ) M! }2 |; u- J. Q* E( l
y += ht;
( n" ]* U5 m8 e0 N} </FONT></P>
) z7 E" z8 M$ ~<P><FONT color=#0000ff>/* clean up */ ( @, M3 Z9 Z* V: N( n
getch();
* t! D; R8 K6 M3 m" [  I. D- m9 cclosegraph();
% I; b  F  J% r, c1 \/ u! I$ Ereturn 0; : g, g3 D; V6 `) ~% i( A- p
}
) C3 G" K7 O  n5 ~- X6 G$ }</FONT>" {/ @& i) {% h

4 L1 K; I! v. v7 Z5 b5 p% ^) f</P>$ b4 H/ j2 ]1 h* z
<P><FONT color=#ff0000>函数名: settextjustify </FONT>  }* `) F" f" o4 h
功 能: 为图形函数设置文本的对齐方式 * e1 Z( }& y& v: w8 z+ e# T
用 法: void far settextjustify(int horiz, int vert); 0 y2 W. T- h9 J4 p* r2 M
程序例: </P>
& D8 X( Z/ g2 [, q! r# ^<P><FONT color=#0000ff>#include <GRAPHICS.H>
, Q( L5 W4 i. U3 `, e! U#include <STDLIB.H>% t5 H$ P  Y& I4 C  p. ~& p) R4 M
#include <STDIO.H>' X6 l, o0 {" O
#include <CONIO.H></FONT></P>
. u+ _# N4 z3 M) M8 C' i" K<P><FONT color=#0000ff>/* function prototype */ $ Q" ~$ x+ x) i) S
void xat(int x, int y); </FONT></P>
4 D  Q. m/ [2 q) I% O  X<P><FONT color=#0000ff>/* horizontal text justification settings */ : s: b" c4 Z& P/ S* d& L6 J5 Q: Y
char *hjust[] = { "LEFT_TEXT",
/ B! M& t6 }, `1 a' J, _"CENTER_TEXT",
; X) w' i% D, X8 v"RIGHT_TEXT"
: Z; K2 j1 F) y+ Q* j  m, T}; </FONT></P>+ j4 s) b: P7 S, e5 v2 l
<P><FONT color=#0000ff>/* vertical text justification settings */ 4 c0 c  W- u  O, o$ C; L) k- `
char *vjust[] = { "LEFT_TEXT",   n7 {) V* V: Y# e2 w
"CENTER_TEXT", 6 B/ i6 ]* M$ d6 M+ r6 ^7 \
"RIGHT_TEXT" 6 @3 ^: o" I- ]5 a" M0 I+ `" \
}; </FONT></P>- b$ C4 j9 p8 |' n$ j$ |
<P><FONT color=#0000ff>int main(void) ) a" H8 l) f: N6 L' M
{ . ~; q1 q2 L( R
/* request auto detection */
0 a7 q+ p$ q" q$ D' d; O1 W" Xint gdriver = DETECT, gmode, errorcode; * }/ R& [( f/ ]4 e
int midx, midy, hj, vj;
0 A9 n( ^5 O: k  b* zchar msg[80]; </FONT></P>& z8 s1 C. Y$ u7 w& j
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 z$ l) t& B. f3 G
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 ~5 S2 k6 y* ?' f; ~% G( h<P><FONT color=#0000ff>/* read result of initialization */
' f8 O/ F- r8 ]3 o- Berrorcode = graphresult();
: J* i2 S4 J+ G; ~! n) F% A9 \0 Oif (errorcode != grOk) /* an error occurred */
0 b8 u: p2 q+ P{ * k6 V- {5 X1 t! d4 x5 Q9 V1 t
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& h0 r% i8 W5 j3 o6 I9 n: Gprintf("Press any key to halt:");
. e) r5 b: u* h; z  _* g2 s4 c4 Lgetch(); . u0 K* r7 }- z; K
exit(1); /* terminate with an error code */
4 U4 M6 D+ {' j# {} </FONT></P>  x  j9 T# N0 t1 v" j
<P><FONT color=#0000ff>midx = getmaxx() / 2;
2 z9 B# F: S* Smidy = getmaxy() / 2; </FONT></P>( B% J" ~8 U5 y% A$ Z: l
<P><FONT color=#0000ff>/* loop through text justifications */ " l3 `% ^+ G# J( ~% k4 w5 ^* _
for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) / Q! V5 m& P  ^/ j) _$ E
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
/ Z5 o: a% [2 }, [0 J{
, s) v% z5 Q( T) lcleardevice();
! i  X9 {& ]% k, P/* set the text justification */
- F2 y3 Y6 n4 g& rsettextjustify(hj, vj); </FONT></P>
' |1 Q" A" m" l<P><FONT color=#0000ff>/* create a message string */
; ]( ^  \0 a: {$ \7 k4 Bsprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
0 H) n/ x) q  Y4 ^<P><FONT color=#0000ff>/* create cross hairs on the screen */ 3 h" S; M  t+ E( _9 B
xat(midx, midy); </FONT></P>
7 Q$ K0 r# |, m9 s/ C  \<P><FONT color=#0000ff>/* output the message */
. X* k" [1 B4 \! vouttextxy(midx, midy, msg);
8 E. r% K% r0 S% T6 [2 j" E& j' X( bgetch();
& [7 j2 {% p" Z" [# Y5 W9 Y: L5 s} </FONT></P>
; v% @7 I; f- w' h: S6 I0 r<P><FONT color=#0000ff>/* clean up */
; G, J# D% ~" p: |' C/ Rclosegraph(); 9 X2 z  x- p$ c5 ]6 U
return 0;
, [- X" R, k3 Z} </FONT></P>
4 d3 x3 D: r# p5 T3 z- n<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
# r; W% m! w5 z2 Cvoid xat(int x, int y)
. E7 E1 x6 A! H) f% x{
1 B4 q7 S, D7 S! ?line(x-4, y, x+4, y);
8 _% Q0 t4 [7 M2 Cline(x, y-4, x, y+4);
' O- z2 X) b0 I) ]% [0 T  V} </FONT>* [3 Q+ v7 [5 q6 |+ ?

+ D* o9 g5 H) I9 i</P>
5 _" X! ?3 A! c! R# M! V" Y+ _* }<P><FONT color=#ff0000>函数名: settextstyle </FONT>' e4 y6 Z# i& ]+ E! ?0 {; i4 X2 n
功 能: 为图形输出设置当前的文本属性 - d: t. w4 P/ P) a* J4 Q
用 法: void far settextstyle (int font, int direction, char size); ' w: H% x& t8 t- C6 X! E  P& t# o
程序例: </P>
, c. D5 d) m: O) _  O<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 b$ E# ]# Z% G! n" A! i! O! F#include <STDLIB.H>. l1 V: H3 z: j, T4 A. `. o$ p
#include <STDIO.H>! L$ g7 N* A8 u1 \4 u/ ^
#include <CONIO.H></FONT></P>
3 t/ z+ ^% I$ l" N) A, O  C$ @2 x$ x<P><FONT color=#0000ff>/* the names of the text styles supported */
' y9 l7 T5 a( ~' y2 ^5 @char *fname[] = { "DEFAULT font", " G9 w' m) R' Z2 M( c& J
"TRIPLEX font", 5 I8 N- L  c! Y- _; Q, }
"SMALL font",
7 T  ~- y5 y6 O$ c2 z" ^9 Y"SANS SERIF font",
* [- i* a; C& J3 l( v8 t# [/ ?"GOTHIC font" 2 @  W  D. \/ z# `' @
}; </FONT></P>
$ X- A: R# o: @' e; B0 q<P><FONT color=#0000ff>int main(void)
! u3 G) u& L! y* p( n8 C2 \2 q/ _{
3 q& U4 o( _/ K* X" n- m/* request auto detection */ ' q( i& H' g* w" [& ]. P' U. s
int gdriver = DETECT, gmode, errorcode;
/ z5 D0 {& Q0 b  Dint style, midx, midy; $ H$ T% @+ c* @
int size = 1; </FONT></P># ^2 m6 O3 V3 L7 r. w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 e7 f- Z8 G3 U) Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 z( h% R, `& j& a
<P><FONT color=#0000ff>/* read result of initialization */
8 B( D5 Y4 M, T2 m, uerrorcode = graphresult(); . U2 h+ p8 v5 n+ x3 ]% W% l
if (errorcode != grOk) /* an error occurred */
# b3 u5 I: u5 g  p# w: L{   X. |5 y& s1 E2 W3 E' M
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( o8 I$ N$ {! l
printf("Press any key to halt:"); 9 U7 V, R2 Z- G; L! ]8 j$ J& c% p
getch();
3 M3 J  I1 ^" lexit(1); /* terminate with an error code */ 6 }/ G% e+ {# q2 C) G/ V
} </FONT></P>
: M6 t" a& {1 R8 d) R% [1 u<P><FONT color=#0000ff>midx = getmaxx() / 2; : D9 n' Z2 T- I" \3 [5 k
midy = getmaxy() / 2; </FONT></P>
6 {) ~) V( T* y8 {) S- S<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
! g" H( N% p/ [<P><FONT color=#0000ff>/* loop through the available text styles */
) p# B  l* T+ |9 S5 Q/ ofor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) - \# {8 X8 Z6 g4 g
{
, @  t! E, M( s$ r+ xcleardevice(); , x" Y% v4 W6 e
if (style == TRIPLEX_FONT)
( [/ L- c+ v# g! Osize = 4; </FONT></P>- U5 v! ^1 `; W5 ?* M, t' H
<P><FONT color=#0000ff>/* select the text style */ % ]" Q5 L8 r( Y( v4 k6 c$ R0 J8 K# I
settextstyle(style, HORIZ_DIR, size); </FONT></P>
3 b! X7 ~+ }& c  Q4 i0 h* V<P><FONT color=#0000ff>/* output a message */
" o6 M+ `! R1 Bouttextxy(midx, midy, fname[style]);
1 t6 q. a7 [. v6 q7 D$ [3 Hgetch();
2 f7 j) Z; \$ D5 c+ j} </FONT></P># U( A2 j4 \9 ^
<P><FONT color=#0000ff>/* clean up */ ; V, g6 S& S3 w3 l& Q% J; ~
closegraph(); " m# C6 S3 n* q7 a$ z1 O
return 0;
0 z" R1 J7 {1 w+ }1 H}
! |; Q2 t( Y' {; Y</FONT>: Q5 e3 q1 B, V  O
</P>2 X9 h% C! q5 ^* I9 |
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
7 s% ]9 @/ n/ x8 h+ |& h功 能: 为图形输出设置当前的文本属性 # b  R; R/ |5 K7 v2 H. n8 U
用 法: void far settextstyle (int font, int direction, char size);
* ]5 U+ T3 T" f7 s* f1 J程序例: </P>- u$ k2 u( P( [. P
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ e  \6 b- ~5 I9 _& a
#include <STDLIB.H>
: t, d5 z3 ^# l% b1 Z  u3 M. v#include <STDIO.H>
# j& i7 i+ A. r- H) Y4 Z#include <CONIO.H></FONT></P>' j6 @, j  j5 G# F, T) L* x
<P><FONT color=#0000ff>/* the names of the text styles supported */
* \6 W) D! R8 S, m2 Y5 E* {char *fname[] = { "DEFAULT font", ' l3 X* f& C! y% a3 ]: G
"TRIPLEX font", 3 b5 d5 m$ b3 V; K, R
"SMALL font",
: B" M6 m& M( ]& n  g+ X"SANS SERIF font", & H' c6 ]* w0 u5 P8 U& t2 r
"GOTHIC font" 3 s5 S( p$ z2 Q. K% q+ O
}; </FONT></P>
4 _  c0 I* g$ ^) W. Z<P><FONT color=#0000ff>int main(void) 0 e- d" A: i; \9 a0 e% i9 L  R, O
{ 7 m5 O) {$ X) Y9 l
/* request auto detection */ , V1 K: A7 Q. F, P
int gdriver = DETECT, gmode, errorcode; 2 I% d$ X! Q' P9 Y6 m2 I( s8 k% W
int style, midx, midy;
3 I1 x4 e. Q" P5 ]- }int size = 1; </FONT></P>
, P+ k, n+ x5 @3 D. ~<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ F' S' f' e* B8 n1 l; }initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; C: I4 e8 L) I<P><FONT color=#0000ff>/* read result of initialization */
7 |5 u0 G* z( X4 [: Perrorcode = graphresult(); ' \7 B& N0 c8 m4 _( l
if (errorcode != grOk) /* an error occurred */ 2 u4 [, ]4 n- W' n% K
{
* H# k9 e0 b- V  ?6 [! F: Hprintf("Graphics error: %s\n", grapherrormsg(errorcode));   j* J3 I5 ]3 a8 L  O% `* U5 C: S
printf("Press any key to halt:"); $ e/ l5 d% c* a; i6 p* V
getch(); % |% T* m* j* G9 w
exit(1); /* terminate with an error code */
. ~* \0 s! d0 q, v; n} </FONT></P>0 @8 l9 {2 c. J* ~2 X' R5 U, K
<P><FONT color=#0000ff>midx = getmaxx() / 2; 6 a0 s5 N' K# S) s2 B5 w* _9 |
midy = getmaxy() / 2; </FONT></P>
/ z# U) m8 |6 c7 C( w<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
$ y  _1 k8 k" j) d, A<P><FONT color=#0000ff>/* loop through the available text styles */
4 F# m  `! ^& yfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) + p- h+ O* V2 |. n; O+ A( U7 g
{ " I  P0 n6 y9 I6 a0 x' D
cleardevice(); 8 B8 d- r! G. q" [+ |
if (style == TRIPLEX_FONT) 3 O2 Y; d, X' y
size = 4; </FONT></P>1 L! _) V& @# F2 Z1 H5 x
<P><FONT color=#0000ff>/* select the text style */
! ^/ j( Y9 m" P: t1 Gsettextstyle(style, HORIZ_DIR, size); </FONT></P>
% s+ f' D/ S/ i6 O<P><FONT color=#0000ff>/* output a message */
7 n1 _3 {9 l$ Uouttextxy(midx, midy, fname[style]);
/ }3 `! F! m& d; tgetch();
: s8 Z* x7 G( ]3 V- W} </FONT></P>4 f# B* z: Z# y, A4 _3 C: W3 b
<P><FONT color=#0000ff>/* clean up */
5 K$ ]' z: ?2 g/ z. Z3 Q* `6 Eclosegraph(); $ x: J! {, X7 Q1 ?4 _# S9 l
return 0;
: \4 s; S9 z+ f8 Z} </FONT>* H" q6 j2 F: o" j' C' z" Q

' [5 ^' r; u% ?" h. E) Y9 U</P>& f  Z# {7 c& F+ P" ?0 }' A3 {
<P><FONT color=#ff0000>函数名: settime </FONT>
0 C' l' J5 h. h/ b' }7 h% Y功 能: 设置系统时间
  s# g* Q' J0 Q+ O2 `5 ~, N用 法: void settime(struct time *timep); : g8 r4 j# D9 h
程序例: </P>
- C, i( r+ ^& G+ b/ x& s. Y9 l4 q<P><FONT color=#0000ff>#include <STDIO.H>
4 |0 f) ^8 S( G#include <DOS.H></FONT></P>& a7 [1 m4 P/ J0 ?9 h, P
<P><FONT color=#0000ff>int main(void)
! z, i9 K) y$ K0 \) \5 w: _' f' X{ # r: M! Y* h+ i
struct time t; </FONT></P>* L2 N! L* f! u* I- d4 v  X1 I3 T1 S
<P><FONT color=#0000ff>gettime(&amp;t);
8 J) I- Y0 @+ o1 E9 {( |printf("The current minute is: %d\n", t.ti_min);
1 I' G7 k; F- Y0 kprintf("The current hour is: %d\n", t.ti_hour);
3 f. |, w7 b' j+ R( g5 D2 Kprintf("The current hundredth of a second is: %d\n", t.ti_hund);
! V  A  m: `+ w- U& C0 ^printf("The current second is: %d\n", t.ti_sec); </FONT></P>$ ?7 m9 x; n4 T# ]! p; l
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
5 L/ O0 D& b$ w, ?$ a+ s- C& Ht.ti_min++; 8 a" u5 Y6 C- y
settime(&amp;t); </FONT></P>
& {5 b2 X3 c3 k4 I# z7 u<P><FONT color=#0000ff>return 0; ! o1 U, M( K! T1 E; |" Q% I# H
} </FONT>
2 u0 Z2 x0 s' h; [% z  F, a+ x1 h' g) p: h1 U, \/ ]) [
</P>3 L0 T9 _2 \5 v3 o
<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
' d2 h; j8 p% L功 能: 为矢量字体改变字符宽度和高度
9 w5 Z4 J. F; J# _/ n用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
9 K( o" Y7 C' G) L( U程序例: </P>5 L' g5 j5 |' q* M: @" c
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 r; `. E& i1 \# ^' W( g
#include <STDLIB.H>; [  _" N1 L! ^$ x1 j2 S
#include <STDIO.H>
  ^2 N/ U0 v$ |+ K: x' f, U6 W2 w#include <CONIO.H></FONT></P>
- y8 ^& A+ A( M5 V<P><FONT color=#0000ff>int main(void)
2 M" G; u2 u3 Z. r2 M{
' I8 b4 |' e! n) ]; p/* request autodetection */
" A0 p& ?$ L. ]3 S4 kint gdriver = DETECT, gmode, errorcode; </FONT></P>$ [1 p8 J2 |( H8 b) E
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' |9 L( q( P. i; n9 A( V2 s3 iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( N0 L5 t4 r4 ?2 n: E6 ?, @7 ^<P><FONT color=#0000ff>/* read result of initialization */ : T0 s) r; L9 D( d# o3 r; ^
errorcode = graphresult();
4 e9 Y2 f3 E: f, t, qif (errorcode != grOk) /* an error occurred */
& K/ {! `7 p% ~* j2 Z{
1 G0 _7 n2 z) e+ I, hprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 j- Q4 ^3 L6 w. w  ]
printf("Press any key to halt:"); 2 N- b8 |; Z0 M- D8 b$ K
getch();
( g+ g" ^6 [* Uexit(1); /* terminate with an error code */ & M" h5 c; p5 a2 S9 e" B7 e
} </FONT></P>
( E6 }% k% E: I2 h2 J<P><FONT color=#0000ff>/* select a text style */
. d' n# R) u: ~4 G# E" Z1 o) L5 t4 \settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
7 h* z( O  i2 T; P9 {! l9 r; J- e9 c<P><FONT color=#0000ff>/* move to the text starting position */ " O! t# D" e( d) K! ~
moveto(0, getmaxy() / 2); </FONT></P>) [+ q6 x! U1 G" S
<P><FONT color=#0000ff>/* output some normal text */
8 H: p" w; v. x% [9 Fouttext("Norm "); </FONT></P>
0 v( f5 h& i; @: n<P><FONT color=#0000ff>/* make the text 1/3 the normal width */   p& C. n7 U3 E& W
setusercharsize(1, 3, 1, 1);
& \8 f( a# U0 r# y- u% Bouttext("Short "); </FONT></P>
6 q* E( b& t7 d7 z" l' [<P><FONT color=#0000ff>/* make the text 3 times normal width */
  C4 c5 q" \1 D7 e' P5 \8 Rsetusercharsize(3, 1, 1, 1);
! _  ]% O4 P- \9 z! o+ _: Jouttext("Wide"); </FONT></P>) x# V0 Z# H; v0 J1 `
<P><FONT color=#0000ff>/* clean up */ ( @# G2 Q4 Q/ C# ^. z8 m% S
getch(); ) Q. ?% a# q3 X: r" K
closegraph();
6 D8 [) D- g; Z5 l4 Y# G. e5 W; freturn 0; ) F8 z, W4 \; K) Z+ g! s8 Y% z% s
} </FONT>4 B- M1 @1 N5 l$ G+ @
</P>
/ E8 N: Z+ s0 C# T, _<P><FONT color=#ff0000>函数名: setvbuf </FONT>1 I8 ]1 L5 @+ u9 x( X" S
功 能: 把缓冲区与流相关
# x" j6 p( e, y用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
' q4 x& X" t& r# O$ }" H程序例: </P>
1 P: \! |7 {1 s" n! B) O+ S2 |<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>$ X! ]- j6 J# H" ]; L0 y0 f
<P><FONT color=#0000ff>int main(void) ' s9 D( G7 G5 I
{   C5 L% @1 a9 p6 m2 A
FILE *input, *output; 2 {6 \3 g3 \- J9 F0 g- v
char bufr[512]; </FONT></P>
5 I" n( Y  t3 c* W; e<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
3 D, f: J; J. R3 T/ J# D" ^& joutput = fopen("file.out", "w"); </FONT></P>4 E. E! ~+ n4 K9 k! v2 U: M7 c
<P><FONT color=#0000ff>/* set up input stream for minimal disk access, ' m' v5 T1 E7 u% }
using our own character buffer */
% g9 T4 Z$ U% r3 C7 J& Nif (setvbuf(input, bufr, _IOFBF, 512) != 0)
( v! V* Z" ^; }2 y* bprintf("failed to set up buffer for input file\n"); $ a. a% u" {( Y4 K5 ]( ~: r: U
else
: q: |+ {; \5 ^1 y! B$ j9 eprintf("buffer set up for input file\n"); </FONT></P>
2 k% O; z/ \5 z/ W. y/ `<P><FONT color=#0000ff>/* set up output stream for line buffering using space that ' t. T: s# [% I# X1 D$ }5 w
will be obtained through an indirect call to malloc */
! _5 b, e: w5 mif (setvbuf(output, NULL, _IOLBF, 132) != 0)
" L+ B+ g- m3 ^+ Hprintf("failed to set up buffer for output file\n"); . \. m) ~  J9 Q: S
else
1 U8 D  q3 M$ |  `$ Bprintf("buffer set up for output file\n"); </FONT></P>. G, R5 S) G: l8 `  e  v$ F9 ]# L1 _+ J
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
; @% R  u! ]0 }5 h+ Q<P><FONT color=#0000ff>/* close files */
6 P* G0 t8 n' ?$ B3 R2 ufclose(input);
. u5 M; c) k7 Q9 O+ B  |% Xfclose(output);
% [0 K7 {0 L! ^/ N* T5 |& m# L- freturn 0;
8 H9 V6 \2 z6 t9 P# a  R} 8 @* [" q: P2 B/ p+ T
</FONT>
; Y, O& W% x/ c) V( S% r4 s* ]$ ]7 q8 G% M: n
</P>
9 Y  {# w: ~7 z8 }  u  ^% O<P><FONT color=#ff0000>函数名: setvect </FONT>
, D/ W1 g  p& p% F功 能: 设置中断矢量入口 ) f: j, m6 C! E0 \  }
用 法: void setvect(int intr_num, void interrupt(*isr)());
$ M, v4 ]+ P+ t* ?* m/ V" k: r8 x程序例: </P>, w- y2 Q3 g" _/ Y
<P><FONT color=#0000ff>/***NOTE: ( q9 Y" _' A6 K& U7 P  H4 K
This is an interrupt service routine. You can NOT compile this 1 c3 ~! [! V2 r
program with Test Stack Overflow turned on and get an executable
7 P# ]( x( e6 T$ I0 `0 ufile which will operate correctly. */ </FONT></P>
# l# f8 j" x$ G0 ]4 H& O9 `5 }$ n<P><FONT color=#0000ff>#include <STDIO.H>4 \' h0 S1 V6 K6 {- K! J
#include <DOS.H>0 w% A7 [* \) Y6 _! W+ M, P
#include <CONIO.H></FONT></P>" y7 j  X$ K! s1 Y1 f6 G6 P# G
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>* W, W' _& U9 ?' I  a7 o9 N  f8 y
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>. }+ S" d3 h4 _0 C- P( A+ V" i
<P><FONT color=#0000ff>int count=0; </FONT></P>& k" R) |$ j, v, p' X" |
<P><FONT color=#0000ff>void interrupt handler(void)
% D- v. m; s+ Z0 _% t7 B0 W+ Z, o' a9 l{
' Y' D1 ~: ]5 h# j0 l" S/* increase the global counter */ $ e0 M, }7 e+ y( F  i: ?
count++; </FONT></P>: }+ {5 C6 ?, A
<P><FONT color=#0000ff>/* call the old routine */   g; j3 H( A& a$ |
oldhandler(); # ]6 V' {7 _& B3 q$ X1 ?
} </FONT></P>
) C6 ^8 ~0 A* i# T9 a) s& {- V  s<P><FONT color=#0000ff>int main(void)
" l# ~1 Q3 a- J" c$ T{ . G% V% H# O0 ]* D+ N' @
/* save the old interrupt vector */ 5 j3 T" M$ Z) z
oldhandler = getvect(INTR); </FONT></P>
9 Q3 O" o2 j" ?2 ~<P><FONT color=#0000ff>/* install the new interrupt handler */
" W7 ?% r4 l- ^: W8 Vsetvect(INTR, handler); </FONT></P>
/ G* f8 s* D  A6 i' d: c<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
5 U+ T1 [. |6 x- ]  p3 K- fwhile (count &lt; 20)   Z! p4 o# I/ H4 }0 k7 a" m6 f& s
printf("count is %d\n",count); </FONT></P>
" }3 v) b- B, E/ Q( L, M<P><FONT color=#0000ff>/* reset the old interrupt handler */
0 Q9 k: Q& D  g! o7 G' I; {2 Ysetvect(INTR, oldhandler); </FONT></P>
* {, Y( ]* y, v# S<P><FONT color=#0000ff>return 0;
) C$ ^* l% k8 ?' z}
. o1 Q" O  }1 t* {1 T2 u( d</FONT>4 N, b% I$ a1 A
</P>
  v+ d; D: W4 U" E. d<P><FONT color=#ff0000>函数名: setverify </FONT>
+ O1 Q. [) ]; p. y9 d+ u. S功 能: 设置验证状态
" ~  `) B- O! @; ]% q; L% f! N用 法: void setverify(int value); ' U& z9 W3 k2 B0 \- L/ t* K: p, N
程序例: </P>  l  `! ]. B2 {
<P><FONT color=#0000ff>#include <STDIO.H>
! m2 `6 Y- K* Y- P0 d3 y7 R#include <CONIO.H>
5 i1 C  T! V. e#include <DOS.H></FONT></P>
. f& E8 H* y  B( U1 J<P><FONT color=#0000ff>int main(void) ) w# I. V" d7 ^. \
{ 9 ?$ l' Z: c; B+ {: r, o6 O: f
int verify_flag; </FONT></P>
8 x. b, x" p% |4 b5 @' m! D<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); " @2 ]7 ~" u" x- w* B  v; ~
printf("Enter 1 to set verify flag on\n"); </FONT></P>
4 T; J( P& a* [$ `$ n, W! A- A<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>) ?- D5 S$ D% ?9 K# F  _% |9 u& o
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>/ Y+ I1 V$ J; ?; }9 h4 R% f! a& F
<P><FONT color=#0000ff>if (getverify()) + n, Y$ r, u( v0 \
printf("DOS verify flag is on\n"); ( q2 C6 j  k0 K. L% z  K
else 1 F$ K  U% N2 d
printf("DOS verify flag is off\n"); </FONT></P>! ~6 U/ z5 F/ D$ k. _
<P><FONT color=#0000ff>return 0;
5 F7 m9 k1 ]9 P5 L5 J3 v: M}
* p- Z2 |/ d1 a5 [" |<FONT color=#ff0000>
' J- J$ ]5 [. m+ b* a5 m</FONT></FONT></P>
4 L9 t% D3 t. z( T1 {<P><FONT color=#ff0000>函数名: setviewport </FONT># e( i  ?0 u4 H. ?1 M
功 能: 为图形输出设置当前视口 : [$ \4 O3 W2 C. X# `$ s& j
用 法: void far setviewport(int left, int top, int right,
3 V; u2 s# P6 F! U  `int bottom, int clipflag);
2 p# r. Z' X" K' I% u程序例: </P>
3 x  j! i# i& ]3 S. N+ z9 d4 _, u<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 z, x6 {* H  t7 i" ~$ n#include <STDLIB.H>
$ J) H% W$ q9 I- h#include <STDIO.H>
, b# T2 j  j6 e' c2 Q- D" P4 Y& b#include <CONIO.H></FONT></P>
8 H! Q* T3 y3 t6 _/ x$ Q4 U- Q<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
  e- R1 L: C# a2 b: X$ F5 L<P><FONT color=#0000ff>int main(void)
8 \: V6 i) R5 d4 V{
3 W* u9 t8 P" k5 ~* |/* request auto detection */
4 p: s5 n. f: b/ yint gdriver = DETECT, gmode, errorcode; </FONT></P>* t; z8 d/ D3 _& z0 p9 F' O  c
<P><FONT color=#0000ff>/* initialize graphics and local variables */ / @( i/ [) O  I* d2 @
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ o( Y: E- |9 n0 `<P><FONT color=#0000ff>/* read result of initialization */ # a+ b% w2 g+ o" W8 y1 G
errorcode = graphresult();
# c9 B3 w% B/ O( x; e( y, xif (errorcode != grOk) /* an error occurred */ 7 K+ a2 b" s" x: L8 \$ v8 L1 v
{
& y: Q; k/ H% m" n" z2 [8 nprintf("Graphics error: %s\n", grapherrormsg(errorcode)); % G% M" n" o( ~  F
printf("Press any key to halt:"); # K4 R% t# M4 v& L% i! K7 a
getch(); 4 R% h. L5 l4 F7 o* }+ L, R9 ^  Z2 x( Z
exit(1); /* terminate with an error code */ $ n% u: E" N- W; a, r4 e
} </FONT></P>+ s: O  }0 o/ t8 L) B
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>$ U) }# U; E6 d& `9 L
<P><FONT color=#0000ff>/* message in default full-screen viewport */
5 w/ P. n+ `3 _7 x4 j# A! Touttextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
; B+ D6 u' J" r1 ~3 B  @7 K<P><FONT color=#0000ff>/* create a smaller viewport */   E8 w5 q5 P" B4 m
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
+ U+ H, F- N7 Q% l<P><FONT color=#0000ff>/* display some text */ 3 m4 n' {# h# W& P9 r8 F3 \
outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
; h! Z3 p! W% b" V<P><FONT color=#0000ff>/* clean up */
: T) m+ o  w0 N' K" R' mgetch(); % C8 O, @7 p1 A  v" o& P
closegraph();
+ t* @9 d! d- Ireturn 0; . @7 w* t$ j5 b: Z  |" i
}
3 g( i0 R' r2 w' n9 d</FONT>8 h  g& i# `/ Y$ ]9 u
</P>
- z, \8 B: m" t2 C$ u<P><FONT color=#ff0000>函数名: setvisualpage </FONT>  c% _6 ?) K% \" F' M; x
功 能: 设置可见图形页号
9 @5 ~; x6 }. X3 B' n用 法: void far setvisualpage(int pagenum); $ g* l1 {( {- d* {  w3 k
程序例: </P>
( a% B, v6 A% J7 B" i<P><FONT color=#0000ff>#include <GRAPHICS.H>: g/ o4 J) D4 y: v! L
#include <STDLIB.H>
" d. P7 Z& W' z2 d#include <STDIO.H>8 _# \! ]* F' M4 l& z
#include <CONIO.H></FONT></P>
- F8 u( `% R" ?+ ]0 K7 G<P><FONT color=#0000ff>int main(void) 6 p# q9 g0 V0 P) [
{
; _% S$ g4 L  G. E/* select a driver and mode that supports */
1 x( e& r- ?% Z$ m* ~& P9 }  R: W/* multiple pages. */ 3 y7 D6 [* A5 C7 {  e1 w; C
int gdriver = EGA, gmode = EGAHI, errorcode; 5 ~  J4 l" a6 x3 i% [2 T9 ^( z1 H' }( m
int x, y, ht; </FONT></P>
. W$ P  F9 S  ?  x0 \<P><FONT color=#0000ff>/* initialize graphics and local variables */
; _8 @3 n# v6 h4 @- H- w: ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>& ]) E6 q) L( |  G
<P><FONT color=#0000ff>/* read result of initialization */ 8 c8 A% C, T- r  C
errorcode = graphresult();
6 j5 ?. Z  a1 lif (errorcode != grOk) /* an error occurred */ / [( p+ O3 I+ b2 g& s% c$ |) m
{
$ L2 R5 @2 J1 z, aprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " w7 F& Q1 Y0 `, p6 p
printf("Press any key to halt:"); ; D2 v6 G) u0 v8 s! K
getch(); $ m( H( P& r: i5 T5 s& u
exit(1); /* terminate with an error code */
$ D# s8 u7 G1 e( W} </FONT></P>0 v( y2 C9 S6 |& O" S( K. e
<P><FONT color=#0000ff>x = getmaxx() / 2;
( q  W1 P" j  E+ Xy = getmaxy() / 2;
  V; {* B# x$ _4 n- Wht = textheight("W"); </FONT></P>8 ]4 |/ z3 |$ ?) Q. Y2 i4 U  i
<P><FONT color=#0000ff>/* select the off screen page for drawing */
, w3 V) H$ r) w* g- Csetactivepage(1); </FONT></P>
2 @/ B4 g, _' n$ b5 j" T, {( Y<P><FONT color=#0000ff>/* draw a line on page #1 */ ) M* U! r8 U& X" z, D1 D  y
line(0, 0, getmaxx(), getmaxy()); </FONT></P>0 p8 I; M5 b# u
<P><FONT color=#0000ff>/* output a message on page #1 */
2 B" o- z- E1 b- ^! ^" @" L" Dsettextjustify(CENTER_TEXT, CENTER_TEXT);
" N. \! e+ Y. ?5 l6 Youttextxy(x, y, "This is page #1:");
4 m+ u% d5 d5 Qouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>6 ~% ^) u, l7 W6 p5 J6 {4 O
<P><FONT color=#0000ff>/* select drawing to page #0 */
) C* @" Z0 X7 c: y# ^$ U5 d5 ~: z2 Hsetactivepage(0); </FONT></P>& L1 Q9 P+ m1 ]# A0 C
<P><FONT color=#0000ff>/* output a message on page #0 */
+ I$ P  M$ X: q# Louttextxy(x, y, "This is page #0."); " @. O, T( D& X/ B  T& \( h. A
outtextxy(x, y+ht, "Press any key to view page #1:"); 0 I) c  {, t$ q& w
getch(); </FONT></P>0 k2 O; o6 O: v/ z: F1 S3 B
<P><FONT color=#0000ff>/* select page #1 as the visible page */
  s: @! p  R7 Tsetvisualpage(1); </FONT></P>1 ^1 {* x* @1 Y4 q4 [/ o- V
<P><FONT color=#0000ff>/* clean up */ 1 S/ u; ]0 K* Q' I5 B$ f6 Q$ ?
getch();
# @1 m1 v2 k  I- J! Q" ~+ Aclosegraph(); ) U. O4 Y- U* T1 x5 b/ s
return 0;
2 O0 H+ B3 g' U* }} </FONT>; y  s4 X" `) Q- H6 D. p2 ?5 L" Z' M  `

, V: o. y* y/ z6 A! V1 Y3 Z' n</P>
& O/ Y' y8 B( X8 H) E<P><FONT color=#ff0000>函数名: setwritemode </FONT>
( E  a! E, k* U9 H, E功 能: 设置图形方式下画线的输出模式 2 N! p, z) f. v3 m
用 法: void far setwritemode(int mode);
) M1 m  @, j- z8 N  O6 Q  \程序例: </P>( P- v" f5 N2 i8 U8 {
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ [  J3 p5 e9 c#include <STDLIB.H>
7 Q5 U6 s9 v" I! {+ o3 {- n  q#include <STDIO.H>0 e( i( ?5 j9 O  ]8 z
#include <CONIO.H></FONT></P>6 c- d% A7 {3 U* Z/ i' W- e: z" N
<P><FONT color=#0000ff>int main() # o5 A) g3 S8 @
{ ! y5 a: M  A- Q: j; ~* ?
/* request auto detection */
3 J0 [4 Q5 j3 t* Sint gdriver = DETECT, gmode, errorcode;
- J7 ]2 s5 E5 A9 E6 ]" @int xmax, ymax; </FONT></P>! P1 F0 p, A5 k2 B- \4 B
<P><FONT color=#0000ff>/* initialize graphics and local variables */ # [# N/ M# E( ~' D) g/ p3 c% S7 B
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 p# H, X$ f, _( E1 a3 f+ M<P><FONT color=#0000ff>/* read result of initialization */ ( l5 S  |% t7 _& R* s
errorcode = graphresult();
; D. C3 \: v1 G" z( Pif (errorcode != grOk) /* an error occurred */
* H6 U9 x7 h% b7 u2 H3 g{
4 p) y6 I3 B; U- F1 q. r/ Cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ! c/ o# o# C7 F- C9 Y: T
printf("Press any key to halt:");
- r3 U4 W8 e0 m0 r( E2 }getch(); 3 s$ _" E# @9 K9 b; n
exit(1); /* terminate with an error code */ 0 v5 y9 S* J, B8 `, \$ ~3 o! z
} </FONT></P>
/ c& W; E# z: {<P><FONT color=#0000ff>xmax = getmaxx();
- z* P' R" X4 `  s/ c' ?4 Gymax = getmaxy(); </FONT></P>
* f7 p9 g5 n" V7 t9 ]4 q3 M<P><FONT color=#0000ff>/* select XOR drawing mode */ 5 h1 N! |4 d' n  L
setwritemode(XOR_PUT); </FONT></P>
0 O7 `9 b. ~4 z0 `1 |8 ?<P><FONT color=#0000ff>/* draw a line */
' Q) I: \* O- O; @  |line(0, 0, xmax, ymax); ! |* `3 r5 P, \  I5 f9 \+ U( K- {. {* ~
getch(); </FONT></P>: e8 n; W) u1 B8 \
<P><FONT color=#0000ff>/* erase the line by drawing over it */   o2 J: [4 U; n5 ^, T0 M
line(0, 0, xmax, ymax);
+ c5 i- i5 Y, B( ~) Mgetch(); </FONT></P>7 T# F$ H5 w/ F% ^# S5 @5 F: h$ f
<P><FONT color=#0000ff>/* select overwrite drawing mode */ " a1 p; C0 w% |; ]
setwritemode(COPY_PUT); </FONT></P>, `, o3 B# m; o$ `! q
<P><FONT color=#0000ff>/* draw a line */
3 N9 G4 n; ^. F$ b2 Z  r1 g7 C7 [" Xline(0, 0, xmax, ymax); </FONT></P>8 |  B- \4 w9 p# q2 B' T9 a
<P><FONT color=#0000ff>/* clean up */ " `7 ?, e+ g7 f5 F) Y, P: i1 k
getch(); . e+ t8 S+ }8 q; K) }" T4 c
closegraph();
# J& p& Q: [. {4 G& J2 yreturn 0; / N% u+ x: a, F* |# {# @
}
7 c( K4 M$ z" p% i/ ]% G" a</FONT>9 |# B! N( u* X9 a) v
</P>
. b3 L+ r7 O5 H! t+ A<P><FONT color=#ff0000>函数名: signal</FONT>
% P3 f$ F' c' @5 O8 Y' Q9 ~! V功 能: 设置某一信号的对应动作
2 \, |3 S5 g* v) w9 `+ L用 法: int signal(int sig, sigfun fname);
6 R8 c9 Y6 }2 \) o程序例: </P>
' K- h0 E7 f+ K/ E" U3 g<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, % F1 {- F' j( c" G$ X
catches an integer overflow condition, makes an adjustment # j0 Y2 P: v3 j, h% J( @: Z
to AX register, and returns. This example program MAY cause
' h' M7 ?8 j! L- v- Dyour computer to crash, and will produce runtime errors
/ [" D+ ^$ |* r3 r: I$ qdepending on which memory model is used.
! N; v# k; t/ Q; M- B* o*/ </FONT></P>9 Y1 {) O/ P3 N' ^
<P><FONT color=#0000ff>#pragma inline ; U# w. ]; z. E
#include <STDIO.H>+ N: m8 c. Q* w7 f6 E: i# l% F
#include <SIGNAL.H></FONT></P>
. h' s9 W  p0 f<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
. w/ C# g; o: P& l+ a{
& c* l8 {% _$ T/ E" ~' Yprintf("Caught it!\n");
" M8 ^# Y; f3 l* ]4 I( }+ ^- y3 T*(reglist + 8) = 3; /* make return AX = 3 */
5 y9 T9 G" p9 Z2 g} </FONT></P>
. n6 Y) _) O+ Y1 w<P><FONT color=#0000ff>int main(void)
* E; u! r. |# _4 g) d) m{   B7 p6 U; h% o
signal(SIGFPE, Catcher); ; K8 E( w2 M8 t( q; F. y. w- Y$ x8 ~
asm mov ax,07FFFH /* AX = 32767 */ & i4 n" g* b# b4 I4 k
asm inc ax /* cause overflow */
1 h- j4 B$ m9 M& a' h5 ?asm into /* activate handler */ </FONT></P>/ H* [2 \! |0 ?# K+ s5 @$ y. {6 O
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, 7 Z' q. }; f3 c6 K) m7 S
there would have been another exception when the next 'into'
! G( ?9 _: B1 nwas executed after the 'dec' instruction. */
" a( Y4 z/ d- i2 Casm dec ax /* no overflow now */ % p" H1 I8 i/ z* F& j" [
asm into /* doesn't activate */ 3 g& _* d# |4 a" V" }2 ?
return 0;
2 Q3 c2 E, |6 N8 s( G}
( D( H, L2 J$ u* m! j+ j$ J: `
" `' f- h. u. E- B( {* ?
. v& s, A/ C  q' ]7 H! E/ R</FONT></P>
' R: n, a, Y% X5 t; V# e& \<P><FONT color=#ff0000>函数名: sin </FONT>
4 E5 A. ^8 v( W7 K0 B/ y4 }3 |功 能: 正弦函数 " ~: L$ C, z% Z$ w
用 法: double sin(double x);
* O: T9 s8 ^/ S; [( \/ }8 Z程序例: </P>
8 _4 F4 l2 b% W" P  r) f0 \<P><FONT color=#0000ff>#include <STDIO.H>7 Q; y  Y; Q. f0 |+ `- S: T
#include <MATH.H></FONT></P>
; t: v/ \, e7 Z<P><FONT color=#0000ff>int main(void)
4 h3 ]0 }$ B7 ?; \, R: W% d9 @{ : ~1 S* g( k. ]/ O& }3 q& _! b
double result, x = 0.5; </FONT></P>
. B4 d: e% s% t. Y- d4 d( `<P><FONT color=#0000ff>result = sin(x); ; K, e- ?9 p4 h/ s  N
printf("The sin() of %lf is %lf\n", x, result);
9 b2 B6 n4 m/ c& S. {, Z3 \return 0;
7 L: U. d" f& T7 b} & B+ P( h8 U8 k  x  D) N+ ]( H: K
1 P; E4 X6 \( f* T$ g
</FONT></P>
% ], h  u% V, c( a+ E- d" q5 f0 A<P><FONT color=#ff0000>函数名: sinh </FONT>
; s5 R6 o/ I# @, X" q功 能: 双曲正弦函数
+ s  Q$ {% s# V用 法: double sinh(double x);
1 j+ `  I# r, o$ _. h2 {+ w2 N程序例: </P>4 |5 N4 U+ X" _  }
<P><FONT color=#0000ff>#include <STDIO.H>
6 S. g& y1 }8 D; {#include <MATH.H></FONT></P>4 K: o2 S& e( g; o0 Y, Y* E' S
<P><FONT color=#0000ff>int main(void)
4 T& _6 N1 m& z& [{
$ Q6 b  v: L4 H5 W9 E. Odouble result, x = 0.5; </FONT></P>
" f1 j8 r0 _1 P) W<P><FONT color=#0000ff>result = sinh(x);
- N4 X( {: x; ~5 {, oprintf("The hyperbolic sin() of %lf is %lf\n", x, result); - C, x2 r9 ~3 t% Z. r
return 0; * J3 i( L7 J+ ~. C
}
: y  ]) U* q' m/ Z% h" a, X2 O. r
8 t  o+ J9 N9 `0 a0 m: q; O6 a1 F6 Q) ^
</FONT></P>
9 E* ]6 R# A6 y) u4 [2 c<P><FONT color=#ff0000>函数名: sleep </FONT>
, k9 E, u2 k7 n; t8 |6 x功 能: 执行挂起一段时间 + q$ T0 x5 B' A) e# c, S1 J
用 法: unsigned sleep(unsigned seconds); * T3 E4 G! v$ q* D/ E
程序例: </P>
. B0 O2 e+ C; y% ?4 U7 x' F) U$ Y<P><FONT color=#0000ff>#include <DOS.H>
7 v8 u3 L& P, l#include <STDIO.H></FONT></P>
- M% x: R  c6 c& \9 ~4 i<P><FONT color=#0000ff>int main(void) 7 |3 a3 r& w- ?9 X6 [+ r0 l
{ + E" \. K! I: R1 T/ p3 W
int i; </FONT></P>9 T# Q0 `* ~/ n3 i8 q" G
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
: u5 Y/ J2 Y  F. L+ d6 |8 ~{ * z0 O/ D6 U4 c0 L! W. ~
printf("Sleeping for %d seconds\n", i); 1 ?% O% `. C! I* W% Z
sleep(i); - b  w% U' @, N) g
}
' k6 H+ T0 t3 @return 0; % l+ [* i3 x# }. e( A! D  t
} # w- [3 V! [3 I* |# O

- o- W& x5 `- W) k/ B</FONT>
, q. l5 h; c  J0 N. ?: D' n</P>
- s: v8 T0 ?, \7 e5 ?<P><FONT color=#ff0000>函数名: sopen </FONT>. j3 n% b0 b( B  G
功 能: 打开一共享文件
" p# k# ^4 ^- q  m; A) i7 X用 法: int sopen(char *pathname, int access, int shflag, int permiss);   s* `' K5 q* f, Y3 L* B
程序例: </P>, T" |, E) W8 Y1 `3 ~6 B  R
<P><FONT color=#0000ff>#include <IO.H>; O# z  v! P: L8 Y
#include <FCNTL.H>, M6 E, f5 a3 r+ n# t1 S7 l( C! S
#include <SYS\STAT.H>
  s1 F3 v  U9 A. B#include <PROCESS.H>; f8 L# D6 t* [- y: c; y
#include <SHARE.H>+ f- x+ [. t) f' R
#include <STDIO.H></FONT></P>  t2 e( U2 q. v! t& i/ R5 v% O
<P><FONT color=#0000ff>int main(void) 2 C  q& p% l. v1 D1 U1 U0 ?0 }
{
# z) p9 h8 C" pint handle;
3 c* y9 E( p8 t; vint status; </FONT></P>! F) H2 m" K! c1 F! t1 l
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>8 F! ~6 o) n6 f6 U% Y) Q# k" x
<P><FONT color=#0000ff>if (!handle)
$ i, @" P- x) U, S) c& O0 D) _{ # l' t1 _6 u8 _( [+ t6 _0 j5 q
printf("sopen failed\n");
2 M8 I, o8 Q* W. g5 n3 sexit(1);
9 t3 ?5 ^' }& x  F9 z} </FONT></P>
6 A* V$ F: x! f  q. m  g3 T<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
" ~+ n2 F4 w: [% \* M7 |if (status == 0)
( ~" j1 z/ O9 _2 d3 l) x9 }printf("read/write access allowed\n");
$ F( L7 q' @0 \" d" P& b, zelse
+ H% f0 z. p! O4 M! [+ u) n9 bprintf("read/write access not allowed\n"); </FONT></P>0 z2 E& L& X" @4 C
<P><FONT color=#0000ff>close(handle); # X( N2 K/ A+ ^9 G+ v
return 0;
+ {2 a! R2 _2 Q3 c! s* j  e}
( K6 T" M# C9 U" b1 r, b
+ y( {% V5 w8 E. D% X</FONT>3 L0 G$ {1 u! ]$ q
</P>9 Z6 O2 m% U7 L% J2 r
<P><FONT color=#ff0000>函数名: sound </FONT>
3 P* E- h+ ^7 X: F6 f功 能: 以指定频率打开PC扬声器
" V- E. ~1 N2 X8 e用 法: void sound(unsigned frequency);
3 ~6 B4 E8 ?5 r+ P7 Q! v程序例: </P>
7 u% l8 Z+ x9 t/ m( s<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. % Q# a, O/ o  i  w2 G0 N- w
Your PC may not be able to emit a 7-Hz tone. */
% k9 o/ |. x2 `' a0 E% |; P3 V& c  h9 U#include <DOS.H></FONT></P>
# y. X6 ~9 f2 W, j% t, i# Y) E7 Z; e<P><FONT color=#0000ff>int main(void)
/ d- w) s& c0 m+ d  p: I{ 1 E+ l+ A0 ?$ }# P2 S( x, s+ I! X9 N4 v
sound(7);
/ P- I* c' Y. {/ A% {/ Tdelay(10000); " v7 ^4 Y, i! N/ k2 s. L
nosound(); 8 |! j0 S# f9 Y, O: v- Y& Q9 @
return 0; + f  E. T# f8 [* m
} </FONT>
- R2 m$ ?" W, }- `& s
( j6 e4 N) v! V' D$ ]7 h6 T$ v7 d; \( Y) G
</P>
" |% ]( U/ L0 ?, q4 C" T<P><FONT color=#ff0000>函数名: spawnl </FONT>
/ ^: @& a0 R8 d$ a  k, I) U/ r功 能: 创建并运行子程序
8 I7 @5 n9 f2 F! P2 P: O# a用 法: int spawnl(int mode, char *pathname, char *arg0,
3 x; s' w: o% T' Larg1, ... argn, NULL);
* c; H  N& g! V+ v) h6 r' h程序例: </P>) ]6 d" U7 D5 K3 @4 [- M7 v# u
<P><FONT color=#0000ff>#include <PROCESS.H>8 q1 V4 a% C3 q& h
#include <STDIO.H>: g* ^. N9 C5 B. x
#include <CONIO.H></FONT></P>5 R9 }4 Y1 `6 }
<P><FONT color=#0000ff>int main(void) $ L' m+ t* Z( G5 _
{ 1 p, O' E- L# F2 x& p* s3 W
int result; </FONT></P>
$ a% [( N  {$ A<P><FONT color=#0000ff>clrscr();
( T( V' P0 ]; |8 p* [/ F: k2 Vresult = spawnl(P_WAIT, "tcc.exe", NULL);
" E6 ~5 [8 [( A& }# ]  c) Hif (result == -1)
: w: P8 D( K  e4 g. C8 V{
; O% r( O  z$ a% U7 f. \* Cperror("Error from spawnl"); : u8 _4 j5 `6 z6 [6 @& B
exit(1); 6 Y* s, r6 W4 @+ P; U
} ) |! Y, z2 `' d5 L4 h' H# @
return 0;
* Y- D  _# I' ~- h# s}
: ~! ]0 v; _9 g! `& {! Z</FONT>
: W. X- j- K0 L' j</P>: \9 _! E/ ?0 T, K# a
<P><FONT color=#ff0000>函数名: spawnle </FONT>, S( s4 Z+ k' e: d! |  {. r0 z
功 能: 创建并运行子程序
/ T9 j( _% M9 w; J0 F; b" e1 _用 法: int spawnle(int mode, char *pathname, char *arg0, . ?- A/ t, E3 s/ u2 u
arg1,..., argn, NULL); 2 ~6 ]* K2 b1 G
程序例: </P>
" R9 o! ^7 e6 v8 a$ u9 j4 M<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>" `/ r, C- V" {' J& z) Y$ V
<P><FONT color=#0000ff>#include <PROCESS.H>
. J% E( f, _6 w" s+ N8 ]#include <STDIO.H>
( B# n& P$ A* M5 }; e3 g#include <CONIO.H></FONT></P>8 b9 ^& Y& e8 x% b( `
<P><FONT color=#0000ff>int main(void)
6 X+ Q- E5 `4 r+ T; V{
0 [' B1 u, t" u/ Zint result; </FONT></P>0 o: J8 e: M! |: D
<P><FONT color=#0000ff>clrscr(); % Z0 y3 y* u: d9 C! E
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
) P6 L8 ^1 w+ O% g/ kif (result == -1) & t  L3 g6 g9 v6 f, {# X) U
{ ; {% V, q; Z+ l5 r: K! s3 T
perror("Error from spawnle");
# W0 P7 E9 M0 I6 {4 Cexit(1);
( V; {& e& S4 G$ _}
3 o' v3 v8 B. T7 Rreturn 0; ' G- R+ q, H9 N" h1 O4 h0 K+ e! N
} ' Y+ v7 C2 m/ Z7 ]; _9 f0 J
# u: w8 P$ y7 K, b7 ?

" x% d% t& J0 n' H' D/ Z</FONT></P>2 u8 O, A. }0 S. N
<P><FONT color=#ff0000>函数名: sprintf </FONT>
" `. z% x& S2 ?4 @2 \功 能: 送格式化输出到字符串中
: x5 G" l) n  v: U8 n$ R用 法: int sprintf(char *string, char *farmat [,argument,...]);
# j8 P; |" o0 H程序例: </P>4 x* H/ W" U# }1 [0 ?
<P><FONT color=#0000ff>#include <STDIO.H>7 L# o3 g- G/ {1 K. K* B9 t6 _
#include <MATH.H></FONT></P>
. J! e* C  a5 |<P><FONT color=#0000ff>int main(void) / ?: l7 O( f6 d  g- ^5 d8 H3 W
{
  {3 h7 d/ ]# T* z. H  W4 u: w5 bchar buffer[80]; </FONT></P>4 r, e. b" f" z7 \3 u5 N$ E4 H8 w+ k
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); 8 E! [/ \6 H2 J( L2 w+ I& O
puts(buffer); ; {; O. |5 w2 o: ]- t: o! `
return 0; ! W5 T- n( u9 E& J; p) W: w
} + L# @0 L7 Y, e! x
</FONT>2 u/ H; ]6 N- q- h
</P>0 R' ?, T/ o6 T7 d9 w
<P><FONT color=#ff0000>函数名: sqrt </FONT>
- y/ S4 S6 E) j1 S' O功 能: 计算平方根 , J) e% E8 H2 G% a
用 法: double sqrt(double x);
( d2 c& {9 P  a+ R; s程序例: </P>
# m" I: ~5 O" l% J/ }% |5 @<P><FONT color=#0000ff>#include <MATH.H>7 E9 N/ N4 z+ `1 Y0 X
#include <STDIO.H></FONT></P>  C5 G( y" }5 g7 n" X1 s2 u5 ^
<P><FONT color=#0000ff>int main(void) % i7 K: X' z0 N
{ 9 D# `% R+ s3 E! S2 ^8 S5 j0 B# `
double x = 4.0, result; </FONT></P>2 I4 k+ p) [5 [
<P><FONT color=#0000ff>result = sqrt(x); $ K1 `2 N) [: C4 }$ b
printf("The square root of %lf is %lf\n", x, result); . j! B6 y4 Z. [) P' c9 b. R3 r! [
return 0;
. n  y5 V! p5 h$ [} . t& \: T- [3 {% [
</FONT></P>3 R, o$ B* l( m: `  U
<P><FONT color=#ff0000>函数名: srand </FONT>  {' A& N) p+ v
功 能: 初始化随机数发生器 6 c# j1 d8 m$ S' A
用 法: void srand(unsigned seed);
" t3 s6 h& c/ e9 M! y. [* W) J  E程序例: </P>
- P1 V1 _! N% q/ l8 S; E& l  X<P><FONT color=#0000ff>#include <STDLIB.H>
( U) B- |! l! R+ v#include <STDIO.H>- k! {4 n  h7 [7 }# O2 y2 u
#include <TIME.H></FONT></P>
% X  m2 H+ G0 h& i  _4 r<P><FONT color=#0000ff>int main(void) - j- I# ~- X$ B8 D- a
{
  |# _9 }  \5 g* cint i;
, Y) ~: b& u# @time_t t; </FONT></P>. F+ Z% I. D* X" e9 k0 D
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t)); . i$ N3 }) |" N' ]3 [6 E) |" F( `
printf("Ten random numbers from 0 to 99\n\n"); 3 I$ z7 J* x! `* r; ]; b
for(i=0; i&lt;10; i++) 5 Y1 r0 ^/ d) n! `1 Y9 c% \/ g& }
printf("%d\n", rand() % 100); 1 n( C* h6 ]  a7 Z
return 0; 0 f) w- ]$ ?- {  |1 ^6 ]" R3 g
}
* r8 v+ b/ v7 E</FONT>9 M! J) @( j( a6 X
</P>
, U: p5 f' N% A$ X" C: d<P><FONT color=#ff0000>函数名: sscanf </FONT>; s( b: M1 i4 m5 w2 }" ~/ H( Y9 D% W6 p
功 能: 执行从字符串中的格式化输入 : m" ?, G0 h, X( N; g8 j
用 法: int sscanf(char *string, char *format[,argument,...]); ! P) [- y9 `, j* `$ Y/ U' w
程序例: </P># V1 _$ b3 J- G6 n) e+ j& P
<P><FONT color=#0000ff>#include <STDIO.H>
$ h8 v; F& ^7 D7 m/ `- n$ E#include <CONIO.H></FONT></P>1 L" p6 J% s  A3 Z
<P><FONT color=#0000ff>int main(void) 0 ]- T8 V$ R# L' o( ?1 w) z
{   f2 I% @# v  }% ?
char label[20]; , C/ w# H' \8 X. T% w: W  o
char name[20]; & |. D$ C0 }+ c2 N/ q" ^1 W
int entries = 0;
8 Q! L9 j3 X9 U! ^0 ~int loop, age; / |, E6 ~3 w) }. I6 Y3 `
double salary; </FONT></P>% U* @+ L# A5 I4 C, `( l
<P><FONT color=#0000ff>struct Entry_struct
& w& e, F' a7 `{
" d- ?1 C2 }1 Qchar name[20];
, ^! o# d  ]9 }. {8 s# Tint age;
' _7 m. ^5 o* `0 X% ~float salary; ( z1 Y4 P3 O3 k4 X7 S) J
} entry[20]; </FONT></P>
9 j& `7 u9 ?8 O9 Q3 j<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
5 U; c8 C9 z/ F  D" S% Nprintf("\n\nPlease enter a label for the chart: "); ! f% }9 g9 _& c1 h; {$ L! L
scanf("%20s", label);
8 c( Z* n3 b# p# Sfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>4 [0 P. Q3 H- c& r" a1 y
<P><FONT color=#0000ff>/* Input number of entries as an integer */ - a3 M! d6 L& p- H$ I, v
printf("How many entries will there be? (less than 20) "); ) L/ ?: E  a4 y8 F5 d0 [
scanf("%d", &amp;entries);
7 D4 M1 f/ C; ^$ l4 mfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
0 k" ]/ S+ k3 J' O<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ * C+ z0 `, n6 ?! W, s0 Y! F* I1 f
for (loop=0;loop<ENTRIES;++LOOP)
3 p/ a' N) Y% S/ M { ! ^: ?$ s8 f, p
printf("Entry %d\n", loop); 4 V' ^" \' r- e* U+ @1 ]! b6 w7 B
printf(" Name : ");
) D1 j3 U  T2 m# Rscanf("%[A-Za-z]", entry[loop].name); * v( T0 Y  z$ S6 I$ ~
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>/ j( w! r+ ]/ z! ]( N
<P><FONT color=#0000ff>/* input an age as an integer */ 7 w5 J2 X. z5 H7 X5 \, l1 D- m. R
printf(" Age : ");
$ j6 N) f" p3 N3 p4 {& a, B7 Fscanf("%d", &amp;entry[loop].age); 0 @' I$ I- b# X7 r  b' j' ]
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>8 a$ X% ^9 Y. T. i! I7 r
<P><FONT color=#0000ff>/* input a salary as a float */
1 w/ w' l! n8 |  H( H  uprintf(" Salary : "); ' n5 t4 L. Y: Q$ W% l/ R
scanf("%f", &amp;entry[loop].salary);
* o. h) w3 t. h/ L* B8 F% Z- W9 xfflush(stdin); /* flush the input stream in case of bad input */
& C; W- x  g  F- D8 P} </FONT></P>+ C8 |/ |( s& [) @
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
3 o. Y& S& a: _4 s6 mprintf("\nPlease enter your name, age and salary\n");
' w2 O1 T, T6 {4 b, D4 Rscanf("%20s %d %lf", name, &amp;age, &amp;salary); 3 P6 g$ b7 B  `/ D' D3 a( m
</FONT></P>
0 j& E; I4 _$ y2 S! c<P><FONT color=#0000ff>/* Print out the data that was input */
. j  n; c) B. @8 {/ v* Xprintf("\n\nTable %s\n",label); & e. K4 V# Q; O
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); 1 N# c" |' G$ |+ W& g2 s& `7 j
printf("-----------------------------------------------------\n"); ' l' w3 `2 ]( K* y: j. }6 M1 x% {
for (loop=0;loop<ENTRIES;++LOOP) % X& \+ T+ T7 t" X
printf("%4d | %-20s | %5d | %15.2lf\n",
7 |/ w  s  L$ }( H  X2 Qloop + 1, ; {7 T% Q  D3 I
entry[loop].name,
) z0 z" t' c( P4 B* G4 Z) kentry[loop].age, . c4 w$ e! S8 z- l4 K1 {% I
entry[loop].salary);
/ l0 _* B3 {9 U4 N5 ^, gprintf("-----------------------------------------------------\n"); 3 [8 T* i$ o" Q2 `2 q
return 0; , w0 P3 m* j9 C, y9 j& P
}
: E# L* z1 \" y" h
; x; [4 }+ w8 q</FONT></P>) b0 a- J" b5 v2 }& e6 @
<P><FONT color=#ff0000>函数名: stat </FONT># V" I; z2 U/ M8 i/ [
功 能: 读取打开文件信息
  t" x" I  x* {5 D: P9 O4 |& @用 法: int stat(char *pathname, struct stat *buff);
( K: A" ^8 q0 B* j  E程序例: </P>2 z0 Q0 ?3 i- I9 D, R) Q" J# o; ~
<P><FONT color=#0000ff>#include <SYS\STAT.H>+ n' y( h4 `/ u$ C8 {5 e3 k/ P
#include <STDIO.H>
+ I8 c& L! I' M4 |3 p) I/ `; Y% g#include <TIME.H></FONT></P>
+ g; b# o$ H+ g- z4 ~" o<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
; h# e  g; x3 ?# U& [# W<P><FONT color=#0000ff>int main(void)
  r* M# ^/ \4 c( C& ]& _{ 0 @- Q% f" H, v5 D% w
struct stat statbuf;
/ i, a# S; ^4 t1 c7 W5 rFILE *stream; </FONT></P>
. J: H" S$ x/ s<P><FONT color=#0000ff>/* open a file for update */ , G' c' I4 V4 ]
if ((stream = fopen(FILENAME, "w+")) == NULL)
6 ~2 ^: D( z; {9 f9 ?{ 1 Q6 b. m% Y9 V8 U5 ], O2 v
fprintf(stderr, "Cannot open output file.\n"); 5 `- t% \1 U$ V( n" X* S* @# W' C
return(1); & ~+ _# v9 u. T! q* X  D
} </FONT></P>
* h8 M) u& S& c, `% j<P><FONT color=#0000ff>/* get information about the file */
) O2 b$ q* F9 B8 ?8 ystat(FILENAME, &amp;statbuf); </FONT></P>
$ }/ C/ H! {3 L. Z: Y<P><FONT color=#0000ff>fclose(stream); </FONT></P>4 K: e2 ]9 x6 y
<P><FONT color=#0000ff>/* display the information returned */
2 i/ j& u: ?3 l6 B* V! N) G, W1 H& h1 Lif (statbuf.st_mode &amp; S_IFCHR) 7 o2 |( l* V+ f' J4 k; C' r: x
printf("Handle refers to a device.\n");
8 G( [; Q" X! i1 Lif (statbuf.st_mode &amp; S_IFREG)   ]$ z4 S% j" I' M
printf("Handle refers to an ordinary file.\n"); 3 a; K, E* v) g  `/ L. J/ R
if (statbuf.st_mode &amp; S_IREAD) 4 H' U1 @: h# F
printf("User has read permission on file.\n");
4 Z  U: F/ |  M3 [5 bif (statbuf.st_mode &amp; S_IWRITE) ) V* G9 D5 |1 o0 ?( ?
printf("User has write permission on file.\n"); </FONT></P>
6 H8 ]; @! V' @2 S. D<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
; j3 ]$ w# W0 N9 ]% D9 kprintf("Size of file in bytes: %ld\n", statbuf.st_size); - V+ q$ h* N# q/ S! n
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
+ |& w3 A" c/ Zreturn 0; 0 q  K! o: c# I; O3 W. P
}
7 Z, k2 L) v4 k1 r
, G; H3 o, d2 O3 _</FONT>! n5 P, f: Q+ x6 Z) g; j$ V. O' G
</P>
8 ~* v, t3 p" T; @# Q<P><FONT color=#ff0000>函数名: _status87 </FONT>  c& a6 b% V, j* k3 z
功 能: 取浮点状态 " x& f% _* l; K  y" k# T. j( ~
用 法: unsigned int _status87(void);
! C2 i  g4 ~1 r" a& ~程序例: </P>
5 R8 z# L2 ^5 E: q" J! ~<P><FONT color=#0000ff>#include <STDIO.H>
6 ?5 p2 I" y) L& N) V5 k2 h#include <FLOAT.H></FONT></P>
- t. o4 X6 q) L5 z; N<P><FONT color=#0000ff>int main(void)
+ ?$ M6 r  f& U& {1 R{ - ?, c% A3 C1 w: j8 n6 r) Q, C
float x; * _- a# Z- q4 W
double y = 1.5e-100; </FONT></P>+ X* T% w+ h) `9 R; K6 r
<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>$ F. c' E$ E. W+ O
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */ # Y+ S' d- N! ]) U5 A# m1 p9 M- _0 ]1 x
y = x; </FONT></P>
# }( x3 ?. f; d3 `* I# R  K<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87()); 9 }( m& w, O! B! n( M( H
return 0;   u5 Y2 O4 {. `4 e! V9 O- S
}
( P5 W. ]. g8 P% O- U</FONT>5 |8 ~/ w  l" \6 o
</P>
( Z( L: }4 L* |! ~6 `6 [8 P- P, J<P><FONT color=#ff0000>函数名: stime </FONT>4 K# `5 R$ l5 L* @8 ^
功 能: 设置时间 5 ^( c* x6 p7 |. v
用 法: int stime(long *tp);
7 S% E6 o2 }4 s程序例: </P>
3 b: e5 g" H9 a- }" N! @# M<P><FONT color=#0000ff>#include <STDIO.H>% d! m6 G4 o4 f# }$ ?
#include <TIME.H>! {. b9 _8 T8 T2 F1 ~
#include <DOS.H></FONT></P>  X* P  F! X2 }* ]
<P><FONT color=#0000ff>int main(void)
0 W1 b& l( p5 E' f{ 1 r7 i0 g6 c# Q  M6 ]4 a& ]( P0 L
time_t t; ( S5 h6 N& y; W6 y  e7 d
struct tm *area; </FONT></P>+ K4 m: p- j% m4 ]5 W# x2 Q
<P><FONT color=#0000ff>t = time(NULL);
3 [  \1 c( {; J8 j4 H- Harea = localtime(&amp;t);
! i6 _% g4 I7 Fprintf("Number of seconds since 1/1/1970 is: %ld\n", t);
1 q" j% V9 a* r1 mprintf("Local time is: %s", asctime(area)); </FONT></P>
. t+ a2 k; q* }$ d" S<P><FONT color=#0000ff>t++;
4 k9 N3 ^' Q/ r. D0 x" \" x9 \area = localtime(&amp;t); 9 }! G* C( W5 B: E
printf("Add a second: %s", asctime(area)); </FONT></P>. J6 O; H6 p  ^! D6 U6 J7 G
<P><FONT color=#0000ff>t += 60; , K' {8 V/ g( \
area = localtime(&amp;t); 7 k1 O! \0 I8 G2 B
printf("Add a minute: %s", asctime(area)); </FONT></P>
2 Y- J! A2 E3 s# F<P><FONT color=#0000ff>t += 3600;
- g; }( H8 `3 F. B4 larea = localtime(&amp;t); ) ]- r2 H5 u- K/ t, Q- V2 R
printf("Add an hour: %s", asctime(area)); </FONT></P>  H% }0 |7 R2 @6 C$ n2 }  k! t8 _! w. l
<P><FONT color=#0000ff>t += 86400L;
+ G" r  V' F) s0 g+ {area = localtime(&amp;t); : P% Q/ ~  _( I  V; x
printf("Add a day: %s", asctime(area)); </FONT></P>
0 ^  q4 y8 F/ @: w9 T9 _( ]<P><FONT color=#0000ff>t += 2592000L; ; M; W. {$ t* c! l! S1 B9 y( |
area = localtime(&amp;t); ! h0 R8 v. @5 |/ v, r- o* t
printf("Add a month: %s", asctime(area)); </FONT></P>
! V2 i4 P3 Y3 ?7 w% z<P><FONT color=#0000ff>t += 31536000L;
( `9 \. a( E: S4 p! {( G* Warea = localtime(&amp;t); ' M3 |/ z7 {2 g& W3 N, C9 ]2 i3 C
printf("Add a year: %s", asctime(area));
1 G0 j) n6 ]4 w# [- l8 E4 yreturn 0; # c0 ~9 b4 a2 T
} </FONT>9 ~5 e: y. [/ Q" \

# w; Q. L" N- K+ N9 D& t% h! V& u1 p8 V8 ~0 A
</P>
9 O4 `! I" G4 F* Z3 Y+ B6 P<P><FONT color=#ff0000>函数名: stpcpy </FONT>
$ R3 y  i4 C& y6 r* @功 能: 拷贝一个字符串到另一个
7 N/ n/ Z; a" {$ R. P8 Z# H用 法: char *stpcpy(char *destin, char *source);   T, y7 i$ F; ~
程序例: </P>
8 o! [% I$ w. ]: _2 w+ f, c<P><FONT color=#0000ff>#include <STDIO.H>
$ w+ A. z0 S( G( i% M#include <STRING.H></FONT></P>
3 k0 m+ J6 Y1 S6 u. n6 P# `8 x<P><FONT color=#0000ff>int main(void) % d% H) ?3 A$ b* }+ Z4 l1 l
{
/ v$ m1 R9 l! _  \( Bchar string[10]; 5 O+ W! {" y8 f1 m8 [
char *str1 = "abcdefghi"; </FONT></P>
8 V3 K$ ^- g$ E; n<P><FONT color=#0000ff>stpcpy(string, str1);
0 W% e8 G( B3 m- c) I1 M, J& a/ eprintf("%s\n", string); 4 n4 |; C# a) s# h
return 0; + v4 @9 ?% ]. W- u
} 5 T; x/ D& Q/ }5 f* ?, |

- w& t7 e$ _9 n! i+ N& a8 l7 N</FONT>
% k: R1 n/ o+ T0 D% a6 {; b4 |7 y</P>
+ b- `3 U% W1 j+ x7 `; o2 o/ q<P><FONT color=#ff0000>函数名: strcat </FONT>
1 v3 U% I, v$ `/ e# Z+ R' B功 能: 字符串拼接函数
) J, l5 V, G6 J' `用 法: char *strcat(char *destin, char *source);
0 S/ B, h" |7 g: o程序例: </P>
2 I# l, b2 v* b2 |7 K/ {! o! ]<P><FONT color=#0000ff>#include <STRING.H>2 i4 {8 n* I# s; L; b1 p7 G
#include <STDIO.H></FONT></P>7 ?1 m4 b* `6 y# c* D* x
<P><FONT color=#0000ff>int main(void) 1 Q: f& {& S  y/ P) }
{ $ m3 J" {1 m( e
char destination[25];
7 C7 r4 ~- C8 N+ B/ x- j$ i2 `char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>- H) b' y* K, Q# ?) u% ^# A
<P><FONT color=#0000ff>strcpy(destination, Borland); 6 p$ U$ A6 G- z3 S* W5 }, x, t/ t
strcat(destination, blank);
  G6 z5 B$ F9 a" R7 B, `strcat(destination, c); </FONT></P>3 n1 o, F+ d) y
<P><FONT color=#0000ff>printf("%s\n", destination);
0 ?" u: @) }1 b* u/ n2 dreturn 0;
& V: h; o2 f% x( y; ?; x} % C4 T" f$ A  G8 X9 N! @
6 r5 A3 `5 K7 S0 d# l2 i4 @
</FONT><FONT color=#ff0000>
5 j/ `# q" I8 P! q: ~</FONT></P>
3 s9 b# |. Z+ i% B/ V. l# R3 \<P><FONT color=#ff0000>函数名: strchr </FONT>
# D" h; V/ |& }8 \- p+ w( e功 能: 在一个串中查找给定字符的第一个匹配之处\
- f2 T( m& A& R, i用 法: char *strchr(char *str, char c); 6 J" v6 _' f( }" Z) G! S
程序例: </P>+ i2 T( D; y( G' m+ X+ N4 c+ h
<P><FONT color=#0000ff>#include <STRING.H>
2 S' |# g- n' W3 N#include <STDIO.H></FONT></P>, s2 _$ D% r6 E/ z6 q$ V
<P><FONT color=#0000ff>int main(void) - b5 n- h' O# h% B( V  b# W" }
{
$ q; u, P, ~# \& c4 l& _char string[15]; $ j8 P9 b6 L3 T6 J; l  n! A7 o% f7 A
char *ptr, c = 'r'; </FONT></P>! Q! R7 _; @  |0 H
<P><FONT color=#0000ff>strcpy(string, "This is a string");
- Q  u' {& U5 L+ rptr = strchr(string, c); ( P; t4 F  C. C2 w. j3 h
if (ptr)
2 f- A: n0 b- U4 t5 Cprintf("The character %c is at position: %d\n", c, ptr-string); 0 g- z+ O" {% T' {
else 0 o6 F$ G) k) Q
printf("The character was not found\n");
# f) O) q, T3 S& [6 K, ireturn 0;
/ G) [' p  v! Z8 u$ x. w& n} 9 X- I4 P" F+ B2 k  h" n
</FONT>
3 \9 b. d: K7 i1 K# e% F& J& p4 N2 B: [* s4 x3 g3 V
</P>
0 w' N) ^3 U' [5 q$ a4 c5 H<P><FONT color=#ff0000>函数名: strcmp</FONT>
) m0 S& n& M/ v6 d- l1 X( R功 能: 串比较
4 Z4 z0 R: o1 B8 h用 法: int strcmp(char *str1, char *str2);
0 k1 w* k. v$ f" y* C2 N) Y程序例: </P>
, |5 y0 }/ g" d: y( ?8 H<P><FONT color=#0000ff>#include <STRING.H>
% R. y5 h/ f4 t" O* g" ^! M1 u: M#include <STDIO.H></FONT></P>
) |3 P8 t1 _- C; C( J# V<P><FONT color=#0000ff>int main(void) . [& M( ]; o6 k; l& q# P$ i
{ / ?$ _/ a: D1 L/ O
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
: D% d& I7 m: F) Fint ptr; </FONT></P>
- Y" [! N+ o9 k' ?! ~8 m  l" I8 ~; ?<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1); ) f+ S/ l: I- K6 M3 k; |
if (ptr &gt; 0) 9 e+ S. r/ r8 t; Q) s+ V: C
printf("buffer 2 is greater than buffer 1\n"); 3 h3 c$ e) j) N
else
' b" U/ h0 g; |  n1 B( k% Kprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
- U9 `  |: i1 G* O<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
- V/ j5 m! a* f" ~if (ptr &gt; 0) - M' G* e4 l" T% C5 X5 `
printf("buffer 2 is greater than buffer 3\n"); , F$ y+ u8 O4 [. H
else " i* O: k+ l, p" y. ]
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
1 K2 w3 Y, r8 i7 A$ k7 d3 `<P><FONT color=#0000ff>return 0;
0 X0 X# s: z5 o3 b/ P+ X" i  X8 ~0 R} 0 I; [: B. U# {+ J! E2 X5 D

( M2 Q) l! d7 @9 R$ p# H- _2 v. n/ p! w9 l
</FONT></P>
! y3 ~1 q. z+ N- u+ Z<P><FONT color=#ff0000>函数名: strncmpi </FONT>
2 D9 ?8 v$ G- A$ f2 a功 能: 将一个串中的一部分与另一个串比较, 不管大小写
  @* t' v8 T. |4 @1 C# R; E: T用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
! S3 t$ ^5 d7 f* ?" D5 v- x( F& v程序例: </P>- r" @) s- B$ h3 [/ I
<P><FONT color=#0000ff>#include <STRING.H>
! Q( F, |1 T4 r% W2 f( _4 W#include <STDIO.H></FONT></P>" q& c0 p! W2 e9 x1 O
<P><FONT color=#0000ff>int main(void) 5 p9 M! S. S5 u3 V
{
3 k- N& i7 `8 F+ f! Q; xchar *buf1 = "BBB", *buf2 = "bbb"; . r; l* J! h8 s9 `+ }7 r* c
int ptr; </FONT></P>
& F2 r3 W' k" a2 M2 J<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>; ~- M4 Q+ r2 Z' P7 P7 K& B
<P><FONT color=#0000ff>if (ptr &gt; 0) 9 M. n8 J( C' x; H6 ^& ^2 }
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
) R5 z2 O& ?4 j. k<P><FONT color=#0000ff>if (ptr &lt; 0) ! h8 s0 t4 q( O- M) R
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
5 {  A; b9 F9 d5 n6 l<P><FONT color=#0000ff>if (ptr == 0)
8 h: J$ c6 ?3 f. t" Rprintf("buffer 2 equals buffer 1\n"); </FONT></P>8 I5 Q: r% D  Y
<P><FONT color=#0000ff>return 0; 4 E1 W" t# D& |2 V( z9 ~' {
} + x8 u  p: R: Q$ }: G: g: s

" u" E3 f) y+ b* a5 S8 p- w  c</FONT>( Y8 ]7 w; M- q1 J9 I
</P>) Z' D$ z8 t! v; o" c3 _* j) X
<P><FONT color=#ff0000>函数名: strcpy </FONT>: K. C9 f; F) Q9 I
功 能: 串拷贝 . O0 ~9 I. m! P& {/ H  [
用 法: char *strcpy(char *str1, char *str2);
2 Z! A9 _" e! F程序例: </P>1 n& s) G2 {4 z# \
<P><FONT color=#0000ff>#include <STDIO.H>
/ a: A9 J) {. |& G( q8 B( E8 u#include <STRING.H></FONT></P>, ^; W7 r5 F; {& S6 e5 I6 E
<P><FONT color=#0000ff>int main(void) * v; T4 c' W* d0 V5 G1 F6 o1 J. Z( ?
{
( \8 t& d2 Y, M# tchar string[10]; $ w2 t" U- T" {, i- K% P% w% J
char *str1 = "abcdefghi"; </FONT></P>
/ Q: ~5 b  g8 ]% i+ k" i& t<P><FONT color=#0000ff>strcpy(string, str1);
7 ]8 v$ I" `6 j6 Q$ r* Sprintf("%s\n", string); : \  J; z# Y+ x7 |8 X2 U8 N
return 0;
, ~5 A. ~- o0 F7 D1 ^: p; A} + }4 w% \4 t7 V6 O' c( I5 l% {/ Z$ V4 C
</FONT>
) K9 n+ J8 i$ e% }( @7 l1 L* D
! q- P4 b. T) w, E</P># E* t. f. A& [/ k: w
<P><FONT color=#ff0000>函数名: strcspn </FONT>
6 u* t$ g( l! S6 e. N5 A功 能: 在串中查找第一个给定字符集内容的段
7 c0 }. y( W# w4 {" n2 [/ r用 法: int strcspn(char *str1, char *str2);
9 c& U* }8 u$ T4 u8 J程序例: </P>
% g( }; D/ ~% Y$ c* A+ F4 n* a<P><FONT color=#0000ff>#include <STDIO.H>8 \% d9 I) K/ N6 D# ^- L
#include <STRING.H>
! X7 T& s+ D& u9 Q0 ]: x#include <ALLOC.H></FONT></P>
! W5 g$ h0 h- s  ]" t2 m3 ~<P><FONT color=#0000ff>int main(void)
. T7 t3 h; A" k{
1 s# S- c4 n1 Z' ?char *string1 = "1234567890"; 0 h! X& a+ n" C9 N4 v6 v
char *string2 = "747DC8";
8 t  L% a5 ^& [1 K/ J0 Sint length; </FONT></P>+ ]' @7 I! A2 |+ p# U
<P><FONT color=#0000ff>length = strcspn(string1, string2); " Q0 S% }* r8 t6 p
printf("Character where strings intersect is at position %d\n", length); </FONT></P>
( z5 f* t, G, Z8 t8 f  R; K<P><FONT color=#0000ff>return 0; ; z0 W7 Y2 L* p& N4 S$ ^6 Z9 ?
}
% I" l" b8 N; k- |4 x" x5 S</FONT>
9 M8 l! \# }3 t* P3 q( }5 C+ }+ e2 D/ X8 c6 {) S3 D9 U
</P>" g, H' j1 _- I3 z2 k  K2 |/ |& x
<P><FONT color=#ff0000>函数名: strdup </FONT>' m9 e, X, m; L2 y  P! m2 }- x
功 能: 将串拷贝到新建的位置处 . _$ z  Y& ^! ]
用 法: char *strdup(char *str);
3 u" J: g& _! l程序例: </P>" O5 Q7 G: t- Y0 l' _( G" B
<P><FONT color=#0000ff>#include <STDIO.H>
3 v, V, G6 ^2 r7 E. w+ ^#include <STRING.H>
5 D0 U" q$ C! t#include <ALLOC.H></FONT></P>4 V8 Y. o) N" `0 S4 b
<P><FONT color=#0000ff>int main(void) : m" {8 N7 z. H3 N
{
9 M+ Z) D) n& x; Lchar *dup_str, *string = "abcde"; </FONT></P>
9 i: C' V! P# A; N* T4 X* T9 u1 }# m<P><FONT color=#0000ff>dup_str = strdup(string); 9 k! }1 P' {9 v- s8 \; o
printf("%s\n", dup_str);
7 `* Z5 E6 L% B4 P$ i+ Sfree(dup_str); </FONT></P>! Z# T  N; W* [) g3 |/ S# ?* l7 @% q
<P><FONT color=#0000ff>return 0; 0 E# Q0 i# a3 H# ^! l& ?
}
* _: Y- Y9 R; D) }7 S/ H7 B- a, t$ [4 r* d, z
</FONT>, a" y& p7 m" ]+ z$ |9 W; C
</P>8 z6 ^* o+ d! m% c$ ?3 @
<P><FONT color=#ff0000>函数名: stricmp </FONT>; T1 x$ j/ j3 H. e1 S- r
功 能: 以大小写不敏感方式比较两个串
# o+ j: S6 D: e& p. K用 法: int stricmp(char *str1, char *str2); 4 r) Q2 a' O/ {2 q/ F3 s. P( `
程序例: </P>
$ z) L1 [( d- c5 o& B  z- y<P><FONT color=#0000ff>#include <STRING.H>2 B: g0 H* J) e3 Z# p' q# e1 s' Y) o
#include <STDIO.H></FONT></P>
" `) h4 M  i; B7 Q4 W<P><FONT color=#0000ff>int main(void) : P- I5 Z$ l# J- z! W5 W
{ * |) ^3 K! j7 C  n' Y6 G
char *buf1 = "BBB", *buf2 = "bbb"; - v/ q4 p# U) z3 q, l0 t; M2 P5 F
int ptr; </FONT></P>, @$ Y0 {1 |4 k& S
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>* D$ b' P& X* k( J% s6 l% \; r8 |
<P><FONT color=#0000ff>if (ptr &gt; 0)
0 d/ Q( l! ?! M2 e" K) _2 b. Qprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>' N/ b4 _% g* ?2 B, V2 F1 ^1 d
<P><FONT color=#0000ff>if (ptr &lt; 0)
, a" i# ^& H6 p, pprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
1 K2 I2 q& w! G7 R) |( W<P><FONT color=#0000ff>if (ptr == 0)
! p- Z# D4 @, `/ ~9 A1 ^# Oprintf("buffer 2 equals buffer 1\n"); </FONT></P>7 p/ Z0 K5 K2 u5 e1 X
<P><FONT color=#0000ff>return 0;
! D: o/ q" T) p6 C- b} , t" y1 _( ~/ X! I* W
</FONT>9 U1 _- v5 j3 }- V1 p0 a* s
</P>
2 ^; I' j6 \# z2 |, d6 X<P><FONT color=#ff0000>函数名: strerror </FONT>
2 m, o) j2 l( t! u+ @功 能: 返回指向错误信息字符串的指针
6 ]0 z% f- B6 r' v& r) j1 l用 法: char *strerror(int errnum);
1 ]( i% I% `$ ^6 ]程序例: </P>& g- r+ k9 K% R! R6 \
<P><FONT color=#0000ff>#include <STDIO.H>$ ~3 Z6 {- _+ r0 k# X
#include <ERRNO.H></FONT></P>
- U  k# Z  M" }; ^: m% }<P><FONT color=#0000ff>int main(void)
3 X  N1 Q) @+ F6 {# L{ $ g  E/ W3 Y2 s
char *buffer; / a; V& C/ f5 I4 Z# v& I0 J+ _
buffer = strerror(errno);
& ?+ R) p/ a$ i3 {printf("Error: %s\n", buffer);
  Z% P6 _# H' q5 ]return 0; / m$ e- t% K" r! u; H2 y
} 6 r% B7 s( W/ [( ?( P5 |; f

& t  F& T5 V& F5 f' o4 f! C</FONT>/ ]& `$ W& u9 j
</P>! j/ u- N8 G1 B, |
<P><FONT color=#ff0000>函数名: strcmpi </FONT>! N1 o! C7 M9 V# n
功 能: 将一个串与另一个比较, 不管大小写
) I: c, K. R8 }4 _用 法: int strcmpi(char *str1, char *str2); / [: w; V  a6 B! S" z2 y
程序例: </P>& s- |5 f0 x4 z# J5 u- M: R
<P><FONT color=#0000ff>#include <STRING.H>
( P% ^8 j1 O, c#include <STDIO.H></FONT></P>
) \' d+ S/ P) A/ R) ]<P><FONT color=#0000ff>int main(void)
/ ], C% X: d( @, s2 G{ ! r8 G+ _' e' Y6 C% U! {
char *buf1 = "BBB", *buf2 = "bbb"; + Z4 {" l( o) O0 `" t
int ptr; </FONT></P>
* J- v' y, K% P, g) ^<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
* g3 s: e" ]8 e% L<P><FONT color=#0000ff>if (ptr &gt; 0) ) }. _, [- |/ K5 Y, a" [* l8 W( v
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>6 M# l: @& s/ ~  x. G: o
<P><FONT color=#0000ff>if (ptr &lt; 0) - v9 K% r* m1 @' j1 V6 N0 q
printf("buffer 2 is less than buffer 1\n"); </FONT></P>3 D0 @9 z& o. Z: G* r) ?4 U; d
<P><FONT color=#0000ff>if (ptr == 0) 9 I2 P% p' ~# D) C
printf("buffer 2 equals buffer 1\n"); </FONT></P>% G( ^& i8 J; ]* z. t
<P><FONT color=#0000ff>return 0;
) [7 b8 m8 q( ~: H0 _} ! I! j0 E# {% O% ^7 o& r; U
</FONT>
8 ^$ t- V! n) i; i9 G2 K
8 V2 A$ Z3 E9 ?$ i& b</P>
& R' E0 G' C" R! x1 O<P><FONT color=#ff0000>函数名: strncmp </FONT>$ t/ S0 ~* @2 }! m' D* `* Q& x
功 能: 串比较
! W1 y9 x0 h3 f- v3 t9 Y7 z用 法: int strncmp(char *str1, char *str2, int maxlen);   ^8 i2 _1 e# j( |3 n& n
程序例: </P>$ `% ]' G: |( x0 j5 x0 D
<P><FONT color=#0000ff>#include <STRING.H>
( J- I/ X* y2 X0 l( `! `#include <STDIO.H></FONT></P># C0 k/ @1 D# L' V0 ?1 |; E
<P><FONT color=#0000ff>int main(void) </FONT></P>
! y/ m+ j0 J/ [: R' _& t) [<P><FONT color=#0000ff>{ 7 U# l6 N  [* f/ W  F: ]; d
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc"; $ L; _7 ~1 z7 i  l' A$ ^
int ptr; </FONT></P>
) q( ?4 L; m' ~: A6 k& L9 Q5 D$ p; }<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
6 G5 `" P; ?# u2 G/ uif (ptr &gt; 0)
8 o3 z, c8 i& ^printf("buffer 2 is greater than buffer 1\n"); : k! x. x4 K7 q- U- `  _7 v
else
8 ?- p; d( B8 [2 F+ Hprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
" K, e" D- u7 w8 P0 q9 R<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3); : A3 i, R# P+ ^9 f- h. {
if (ptr &gt; 0)
1 }9 C: t! F, l0 H* gprintf("buffer 2 is greater than buffer 3\n"); $ c0 h' G6 n; _* O6 Z; `
else
5 [# g8 ]! b" @. S' y* U$ e) Gprintf("buffer 2 is less than buffer 3\n"); </FONT></P>7 o+ b% \# t0 e9 M) u  N
<P><FONT color=#0000ff>return(0); 6 j" G$ h% l/ g; X5 M- ?' h
} 7 q( C7 M- c$ p2 b8 m+ z) t
3 P/ A' B& K& [, _7 m& a: {% ]
</FONT></P>( v. R  Q# c3 I! a
<P><FONT color=#ff0000>函数名: strncmpi </FONT>  s9 J- ]8 j1 F& ]! A$ v/ c  S+ G
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 ) l# y8 }+ `( X0 L
用 法: int strncmpi(char *str1, char *str2); 2 ?1 @$ C- N: [' ~/ b" D% `
程序例: </P>( t! E  z7 O& l5 x
<P><FONT color=#0000ff>#include <STRING.H>
! ~1 J' g, w& }: @; }) \  \) h#include <STDIO.H></FONT></P>4 D4 A. e3 M+ Q* u! |
<P><FONT color=#0000ff>int main(void)   X. K0 y% C9 Z# L9 h
{ 6 _- a5 J+ @" X* m
char *buf1 = "BBBccc", *buf2 = "bbbccc";
0 I+ |2 w- E" Iint ptr; </FONT></P>
$ {; _3 R# n. @$ \! l% ]<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>
3 c: l. i  \6 H! r<P><FONT color=#0000ff>if (ptr &gt; 0)
& `9 m/ A2 }* A, c$ J1 S5 Qprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
4 Q, Y* k9 x! G) C0 d<P><FONT color=#0000ff>if (ptr &lt; 0)   ~- H6 N+ J- _5 F% o
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
  u- S+ Q: v9 X* b<P><FONT color=#0000ff>if (ptr == 0)
  q5 r; a- U9 e4 c$ e2 Wprintf("buffer 2 equals buffer 1\n"); </FONT></P>
$ c: t' f6 C" h; [* X0 |+ ^<P><FONT color=#0000ff>return 0; </FONT>
( u" ]  O$ r0 n$ m! Z+ C5 e} ; h4 q  u; {& r) J/ F

* r1 Z& q. W' i6 e1 X5 Z</P>1 H* `, A- h5 y
<P><FONT color=#ff0000>函数名: strncpy </FONT>) k2 ]: s( j! `5 a" q4 e
功 能: 串拷贝
! T+ X5 x" a9 m" L1 q0 v用 法: char *strncpy(char *destin, char *source, int maxlen);
7 s" w2 E+ W# ?- p程序例: </P>3 q3 d& [3 {: L' F' q. S
<P><FONT color=#0000ff>#include <STDIO.H>
* d: d- f) Y+ F#include <STRING.H></FONT></P>
# o3 h1 [, y# `9 a6 J<P><FONT color=#0000ff>int main(void)
) H  Q0 H7 E$ E& |. K' V{
+ [& X8 F8 [8 s. D0 ^. rchar string[10]; . H/ C) R% X  H/ A* I
char *str1 = "abcdefghi"; </FONT></P>; M* ~- o+ f. k# q; t. e  w% Y3 _) w
<P><FONT color=#0000ff>strncpy(string, str1, 3);
; h7 L$ Y3 x9 x/ fstring[3] = '\0'; 0 _- h& s0 h# T/ n1 @
printf("%s\n", string);
0 g9 E, \  G4 d: X% K, hreturn 0;
) m& ~# t; X. G; s- X}
6 D: P* U1 K/ p' T0 x, a</FONT>
* V0 S/ F  U9 g</P>
5 m6 U, ]. J4 \<P><FONT color=#ff0000>函数名: strnicmp </FONT>1 e' }# r" y" Z
功 能: 不注重大小写地比较两个串
$ y- v. M3 ^1 n1 i) y! j用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
. k7 }- `& R5 n+ k' [5 o% I& B3 k程序例: </P>
) c( A; }/ G/ r2 p7 x2 l3 P1 G, z<P><FONT color=#0000ff>#include <STRING.H>
" r6 B8 B. B, q, ]3 p" x1 }9 J#include <STDIO.H></FONT></P>- v/ j$ b% j5 ~1 _0 Z$ G6 U- T
<P><FONT color=#0000ff>int main(void) 6 G& s$ p/ R: o
{
1 f% F" }; O' achar *buf1 = "BBBccc", *buf2 = "bbbccc";
! @' l) g& o) Pint ptr; </FONT></P>0 W+ w6 Y- k( d' ]9 i: v& ?
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>: W9 D! l: k  c/ d
<P><FONT color=#0000ff>if (ptr &gt; 0)
+ e7 r, U3 m) `0 w* `9 j$ P+ Dprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
, x  Z/ e. e6 m: U1 K- z<P><FONT color=#0000ff>if (ptr &lt; 0)
1 P, ]" l# ]9 S& a$ @* Hprintf("buffer 2 is less than buffer 1\n"); </FONT></P>- m: ]: W9 t; \+ R. Y7 @. a) b
<P><FONT color=#0000ff>if (ptr == 0) 3 R# W) j3 V. S& ?2 N1 Y
printf("buffer 2 equals buffer 1\n"); </FONT></P>6 v6 v0 j* F& ~7 G6 E. w
<P><FONT color=#0000ff>return 0; ! t4 A3 l: R3 R+ d6 ]2 a. v. {# L
} 9 {; G$ c% o5 [$ e, l. F' [  r, O3 p
! t7 t* s+ K) e0 |& b4 `! \7 x
</FONT>
3 S/ r) ?- \' Q% u2 f/ `8 A</P>0 n& d6 D5 B9 P6 [; b
<P><FONT color=#ff0000>函数名: strnset </FONT>
6 c9 c$ I* Q2 I7 B1 J* [- w功 能: 将一个串中的所有字符都设为指定字符 0 {4 q% R) N, J/ A: x0 ?
用 法: char *strnset(char *str, char ch, unsigned n);
0 O9 K, t# g. g$ n程序例: </P>
  g6 [' n8 B, N<P><FONT color=#0000ff>#include <STDIO.H>5 c7 C4 ?# ?  A& [
#include <STRING.H></FONT></P>
+ }( k( d( ^: a<P><FONT color=#0000ff>int main(void) . M, X, _& H, m# e& o
{
" C& @) D1 G! l$ K) Z$ ochar *string = "abcdefghijklmnopqrstuvwxyz";
: y* _& t) C0 H) Fchar letter = 'x'; </FONT></P>; Z& @* t! f" V* m9 B
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
/ `" x/ z) D, p: F- ?  \strnset(string, letter, 13); + {& H( f2 H# [8 T- ^$ ?: l
printf("string after strnset: %s\n", string); </FONT></P>
* D% h, v( @9 b# n+ h<P><FONT color=#0000ff>return 0;
1 O$ A0 D; s" O! @) ^5 L2 b. |}
+ u& X' x- j! t</FONT>9 K% ~# t' t/ [. R  z4 D6 b* f
</P>) C( J! X& X/ W% Y1 u1 i5 l
<P><FONT color=#ff0000>函数名: strpbrk </FONT>! x  Z. E# ?. f  Q) X
功 能: 在串中查找给定字符集中的字符 ( _9 }1 \# M4 C2 f
用 法: char *strpbrk(char *str1, char *str2);
2 \+ B' S0 J( u3 e1 C! f程序例: </P>
0 A1 I5 {1 g9 ?9 L<P><FONT color=#0000ff>#include <STDIO.H>8 C$ T  v8 f4 p# `# T- k2 a2 u
#include <STRING.H></FONT></P>
& ~7 `1 D" M) _  U- ^  I$ W<P><FONT color=#0000ff>int main(void)
; y) K( P3 Y% H{ ( a9 b5 h6 z# z( a4 R1 v
char *string1 = "abcdefghijklmnopqrstuvwxyz";
7 D$ Z* k9 _- W' Echar *string2 = "onm"; 8 R9 j. y$ P: Z8 U8 Q8 c. v0 j$ q- ?
char *ptr; </FONT></P>1 G+ B2 J1 z0 w. c- q
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>0 M  N9 b) @5 y) v
<P><FONT color=#0000ff>if (ptr)
/ J) y: }8 @& X" dprintf("strpbrk found first character: %c\n", *ptr);
' x' K' T  Q* @$ Welse 8 v! [8 k& C* U$ |
printf("strpbrk didn't find character in set\n"); </FONT></P>
) [3 t6 N/ Z. W* y<P><FONT color=#0000ff>return 0;
1 N* l6 L% @% Q0 w$ B) n1 o/ n}
- o! T& m- X3 Q* x5 S& y' c  c3 a% w
</FONT>6 `, X/ Q# ~9 M/ |5 c
</P>
& _2 e6 q5 z5 p7 E% j* T- Z( {6 _9 @<P><FONT color=#ff0000>函数名: strrchr </FONT>4 L+ b. q: f; H2 _1 \
功 能: 在串中查找指定字符的最后一个出现 + k9 z, w# P! v/ H9 B  V4 V& k
用 法: char *strrchr(char *str, char c);
6 I) U/ c# Y- [( _3 A程序例: </P>$ J: Y% h+ A8 g/ B% [
<P><FONT color=#0000ff>#include <STRING.H>
  ?. ~' K. W* T. f#include <STDIO.H></FONT></P>
; S" a/ P4 U; M0 Z4 V7 X: A* k<P><FONT color=#0000ff>int main(void) 8 }& s9 N4 S) q: q' u# K
{ 8 ^" s1 w& R2 m5 u7 R. X( g- Y
char string[15]; 2 E$ ^6 G: d, u+ A9 @
char *ptr, c = 'r'; </FONT></P>
$ {& {, y' c, ~# K# b1 s* g9 \+ m# ~<P><FONT color=#0000ff>strcpy(string, "This is a string");
- ]) B% N+ {3 o$ e! R; F' Fptr = strrchr(string, c); 7 W6 x2 V1 Y6 N4 Z# b2 F/ d
if (ptr) 7 A8 q' Y& m: ?5 {( b+ G$ u5 ~
printf("The character %c is at position: %d\n", c, ptr-string);
9 U& {& l) k: \( R$ t6 V8 delse
/ E  E7 ^5 H2 xprintf("The character was not found\n");
+ n! n9 J1 J8 V0 E7 @return 0;
1 B& S  ~& F" C) I* ^- R% |9 \# Z} </FONT>
. U, }+ @4 S. F% C1 e2 J- Y9 f4 f. ]6 K% D  c

5 @9 R. i3 J' G" ]2 H; H! r3 l, N</P>6 v. S! I4 Y* P; C6 Z
<P><FONT color=#ff0000>函数名: strrev </FONT>8 q# X" f. H8 x* `. r6 [
功 能: 串倒转
% x1 z6 `5 w# k  G7 ^, ^  B) ?用 法: char *strrev(char *str);
: S6 _3 Q# @" A8 n2 b程序例: </P>$ k! d7 C1 c4 K! I1 ]. [
<P><FONT color=#0000ff>#include <STRING.H>9 p4 F6 @; z2 }7 E# s9 @+ b
#include <STDIO.H></FONT></P>
) t9 [: g0 }" q6 P4 V' j& ~5 }7 J<P><FONT color=#0000ff>int main(void)
) K0 A: j) l- d4 A  R+ n5 s9 W: \: H{ . d0 p" f# |. t( G, O
char *forward = "string"; </FONT></P>
* b# n- |. x. I7 I- R# \% c<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
+ k2 \  F& |9 {/ ?) h  p: Wstrrev(forward); $ Q/ [; a. W5 W. i& \8 D
printf("After strrev(): %s\n", forward); + K& C% M5 {: T8 X
return 0;
7 `" v" f( r7 i+ ]1 B1 d, a# Z} </FONT>' I6 G  H* B# z# C, Z5 @3 w
</P>( J# G% q* [2 ~' o2 q: e  ]
<P><FONT color=#ff0000>函数名: strset </FONT>
. u. n; u8 u; j! s: E- Z4 \) Y功 能: 将一个串中的所有字符都设为指定字符 9 k1 Y4 X- k$ O/ r! O
用 法: char *strset(char *str, char c);
( Q4 B/ C9 X( V1 {% q( C! C  [3 u& r9 J程序例: </P>
$ X; U# U+ d; F5 P& w4 j0 j<P><FONT color=#0000ff>#include <STDIO.H>) @, B0 P# E; f4 W0 U' A
#include <STRING.H></FONT></P>
- M7 q' S$ D- w% E& v* z% q- n( D+ s<P><FONT color=#0000ff>int main(void)
- b0 O+ B+ y$ h, w: N3 M9 F' I{ ( G5 c- V0 p3 i  u9 E7 s
char string[10] = "123456789";
7 |: V/ s- r7 a" U& \' u8 Wchar symbol = 'c'; </FONT></P>
3 x# c6 x" T5 R% n<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);   c7 G0 C2 u) T3 i
strset(string, symbol); ! j+ D8 G, Q. L/ d& f: `' B
printf("After strset(): %s\n", string);
1 d' C0 f8 I( V( m7 `return 0; ( {5 n6 k$ q  X! V! [' v: u+ E
}
/ Y5 E7 f8 \2 x- [) N, [1 B2 ]0 P) |
) `( c, E, ]; q: }  G</FONT>
0 ]& E" p' x1 s' ~- w$ m% [, S5 a0 w</P>
$ k+ W# j# @5 S6 y0 Y<P><FONT color=#ff0000>函数名: strspn </FONT>
( o  q+ ^, O+ \& }. a! M功 能: 在串中查找指定字符集的子集的第一次出现
6 i: b1 ~2 S) o: |6 ?用 法: int strspn(char *str1, char *str2);
2 H. o0 H0 Z) l$ n程序例: </P>" W- Z( A+ V6 {3 |! C8 c: n( _) b
<P><FONT color=#0000ff>#include <STDIO.H>
+ E) h9 d$ N0 w" _& \2 b/ c1 H- c#include <STRING.H>
- E& m$ A8 r- D- w) K) m#include <ALLOC.H></FONT></P>
4 L1 k' V9 R: \) N+ m<P><FONT color=#0000ff>int main(void) & b& |* U  K# C
{
3 `6 W! [. E$ a/ H0 xchar *string1 = "1234567890";
  w, x( B2 t( F" wchar *string2 = "123DC8"; ' u2 e+ j& `; G: H
int length; </FONT></P>
! r5 o! Q1 H! Z* w7 p<P><FONT color=#0000ff>length = strspn(string1, string2);
8 v3 I$ f, Q* O6 W6 L1 ~printf("Character where strings differ is at position %d\n", length);
! L9 o5 F: j# v7 [4 G# V" Lreturn 0;
9 `. q4 G' Z' O) }* U# X} + m# J9 ]+ G; ~+ [9 H: `
</FONT>2 a" _9 e/ a6 x5 f6 j
</P>9 O. x% A- C; _3 q
<P><FONT color=#ff0000>函数名: strstr </FONT>
2 a* W) ?. \5 I; r2 ~功 能: 在串中查找指定字符串的第一次出现
+ D- H- ^8 ]; M& v用 法: char *strstr(char *str1, char *str2);
0 j# x* E3 R7 a1 f程序例: </P>
2 e1 a4 s6 i# x# t2 L<P><FONT color=#0000ff>#include <STDIO.H>
2 w, O  j' V8 y8 N#include <STRING.H></FONT></P>
* u! _0 X. T# X4 @  ?$ ?2 M<P><FONT color=#0000ff>int main(void) " h+ E& V' Y! X2 X) x
{
2 ~2 V  q) K! Z+ fchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>" h- `  c5 R( K0 j3 C2 K
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
1 H7 ^( p# \  N* ~% L/ p+ Qprintf("The substring is: %s\n", ptr); 9 R) e, C/ k% Q0 C8 Q1 c8 R, q& g
return 0;
. S1 B6 c: t0 T3 s) K1 M} </FONT>/ n# `# Z  u7 b- }, m9 U2 E/ W- J

9 e% h% M; k/ [6 N</P>
3 h3 A( s" Q, E7 T) A% P( U. O7 q<P><FONT color=#ff0000>函数名: strtod </FONT>
4 Q7 m. Q$ E+ P/ w功 能: 将字符串转换为double型值
+ S; o% e& s6 y2 N2 B* \: E用 法: double strtod(char *str, char **endptr);
3 S' B+ N" e4 |% O- d& c2 D程序例: </P># s* Y' J2 @* g1 y, H, z! ]  [
<P><FONT color=#0000ff>#include <STDIO.H>) `! f. d/ j( S. [2 ~
#include <STDLIB.H></FONT></P>5 {) O0 }; a8 r
<P><FONT color=#0000ff>int main(void)
4 K/ i6 y1 x! G, \9 q- g{ 1 Y/ S2 y( I$ \, g" |( g# Z
char input[80], *endptr; % K' b+ K- H( P( a+ ]5 d
double value; </FONT></P>( b2 L4 C$ E4 ?% x" y( x5 i8 u
<P><FONT color=#0000ff>printf("Enter a floating point number:");
' O2 G- ]" L2 L- n- T' Pgets(input); 3 q! Z" t# f- _5 o+ L& J
value = strtod(input, &amp;endptr); , F1 |% Y5 Y* b5 K
printf("The string is %s the number is %lf\n", input, value); ) D: |8 S3 g- f9 T- @
return 0;
; [1 h/ J) }$ \( v: ~" b. g, w4 x}
! V% T8 ?) H9 M: w* T5 n9 _</FONT>* Z: M& v2 y5 W0 n- [2 U
# D2 ^5 ^0 p8 H4 h6 ?% r1 g; u
</P>
  |6 D0 i0 h; n- j, P<P><FONT color=#ff0000>函数名: strtok </FONT>0 W& w1 D& l8 a- Q/ @3 Q
功 能: 查找由在第二个串中指定的分界符分隔开的单词
& r5 E! w% [5 f: j0 J用 法: char *strtok(char *str1, char *str2);
8 ~3 |: C# N6 r+ h$ W) c程序例: </P>
( v$ U# n+ R7 ^, }9 C- l<P><FONT color=#0000ff>#include <STRING.H>
/ j. S) k+ g( m; @0 z$ u#include <STDIO.H></FONT></P>
& Z% D( m5 A6 c4 h<P><FONT color=#0000ff>int main(void) # V; E; j) b% u- U
{
  T( g' U0 B% e! }0 D$ P' |+ d8 Echar input[16] = "abc,d";
. S* H8 y2 V- {char *p; </FONT></P>. H# S$ o  y4 k& O9 M9 d/ J/ X
<P><FONT color=#0000ff>/* strtok places a NULL terminator
' g1 ]/ a# \3 p2 ^5 X5 s$ I' Min front of the token, if found */ 5 y6 q8 D+ D9 x4 T' U
p = strtok(input, ","); " f: z* s% c: B' [$ `0 H2 E- M
if (p) printf("%s\n", p); </FONT></P>
! U# F" m; [( y' b: H0 Q( H<P><FONT color=#0000ff>/* A second call to strtok using a NULL
8 s) g5 A8 `8 Uas the first parameter returns a pointer   r7 G: O: @3 {" A5 Q4 i( {
to the character following the token */ # X" H# n3 v8 y' l# ~; A
p = strtok(NULL, ","); ) Z: D# I  c* Y+ r
if (p) printf("%s\n", p); . o& ~$ t5 s1 J# _
return 0; " o% q% O: S9 |: |
} / {+ e8 i' K" X  {  F0 S

  N* k0 N% s1 x7 F: e+ y4 T7 l" z- p: Z! G$ z9 Q
</FONT></P>7 F1 |1 v  Y! N* X8 G( k$ e) W
<P><FONT color=#ff0000>函数名: strtol </FONT>
  w8 }, H- {7 Q" }功 能: 将串转换为长整数   O4 A* S5 m1 s+ Z. G  z& i. ?
用 法: long strtol(char *str, char **endptr, int base); ( _0 m1 n9 J5 L. v  n0 v5 W
程序例: </P>
" e6 L* g6 [% O8 i7 v" Q5 C! s" b<P><FONT color=#0000ff>#include <STDLIB.H>9 y8 \6 m9 Q% n
#include <STDIO.H></FONT></P>
7 _6 r4 L3 C: J, X7 m<P><FONT color=#0000ff>int main(void) ' v) P+ c' K2 a: j( m: W! j# s7 u
{
' D' _: f, _4 T# k/ n" m; [" Mchar *string = "87654321", *endptr; 3 L* e" a3 n8 M! E% Z2 ?
long lnumber; </FONT></P>; z- r! _  x! u' U& q
<P><FONT color=#0000ff>/* strtol converts string to long integer */ / R% w+ u) p( k' S7 o# G8 w0 ^
lnumber = strtol(string, &amp;endptr, 10);
  W2 p1 H# l$ p- a$ Eprintf("string = %s long = %ld\n", string, lnumber); </FONT></P>
( q3 w# B0 H, m) v& p4 r7 b<P><FONT color=#0000ff>return 0;   y6 I5 N( u5 |* f3 R2 \" K
} </FONT>
% l" E; j4 e" h0 \" H1 f' j5 R</P>
- V7 c! U' j( e3 L* ?& v<P><FONT color=#ff0000>函数名: strupr </FONT>2 b7 t5 _; F- Z4 R2 ?" S& |4 S
功 能: 将串中的小写字母转换为大写字母
4 H4 P% Z# ~; a# l% }3 |( O7 J2 }& A用 法: char *strupr(char *str);
8 u: H. \3 \! U3 t& k4 s4 k3 u程序例: </P>
9 E" i8 _% Y/ _1 C( v<P><FONT color=#0000ff>#include <STDIO.H>
. s. I# W- P" H+ ?#include <STRING.H></FONT></P>; x: D* Q; D- R6 s) G+ R3 h
<P><FONT color=#0000ff>int main(void)
; B) c- R2 i: S5 o{
1 T1 H# G& v5 f( G& x7 Q% schar *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
" a. @5 I' s! a2 \! u6 K<P><FONT color=#0000ff>/* converts string to upper case characters */ # b/ ^* g* i8 I1 y: @
ptr = strupr(string); 1 R9 i8 g  M* _6 ?$ Z; @/ J3 A# B
printf("%s\n", ptr);
6 p- k6 p* Y  ?: s$ W* greturn 0;
: k8 W) p' V/ |5 A, J- `* v} + u5 F0 x+ m4 q2 f0 @8 U/ M$ K- Z
" W, t3 Y7 [: u5 x
</FONT>" a0 t# y* M' d' E$ I
</P>
: ?! e" A, p/ M. v<P><FONT color=#ff0000>函数名: swab </FONT>/ c, a! K7 v" Y# s$ D
功 能: 交换字节 * j. y+ [: a' }; |- ?* b, r% g
用 法: void swab (char *from, char *to, int nbytes);
4 K/ ~% ~1 _1 g" \) H程序例: </P>" n9 n6 I2 Q) A. c6 \
<P><FONT color=#0000ff>#include <STDLIB.H>% {# q- I' Q5 [
#include <STDIO.H>
9 @8 Y; r: y7 A, R#include <STRING.H></FONT></P>
) P* @& Y3 }5 X$ w4 y6 V9 G<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
1 I8 y3 D- M: e$ x. m# K# Fchar target[15]; </FONT></P>
- z! q5 a% P8 K<P><FONT color=#0000ff>int main(void)
  ~+ |+ E0 G, ~" N& c& n) J: C{
7 s8 u  v  e- L  E' _' Yswab(source, target, strlen(source)); 2 E" R( _7 {+ H
printf("This is target: %s\n", target); * Y1 }. G3 c. g) ?
return 0; % c% @0 y: O& P) p( Q+ Q8 ~; N
} ) c4 Y' t( E1 X0 b& f  [
</FONT>  l! m+ G' g6 C" F- }
7 F9 c5 T/ Y# P' y( G8 R) F3 |
</P>
: a! i) F4 H: ~. f<P><FONT color=#ff0000>函数名: system </FONT>
7 d, O: X3 G3 B3 d  z7 a功 能: 发出一个DOS命令
8 R% F5 Z' n% d用 法: int system(char *command);
5 x8 `! c  O+ @" a5 Q程序例: </P>% p7 }) [9 w7 s  @9 F! ?1 g; e
<P><FONT color=#0000ff>#include <STDLIB.H>
0 \' m  E! S6 b1 g4 B. O#include <STDIO.H></FONT></P>
! t/ e( ^/ |9 ^, C$ l8 y7 v- V6 c# H<P><FONT color=#0000ff>int main(void) ! a, q% J% y& s6 \5 K1 @! x0 N
{
( l& B& J: j+ A  D+ A% Eprintf("About to spawn command.com and run a DOS command\n"); ; f. S8 f' S3 {/ g
system("dir");
% g  z4 ?4 p1 y: \! ?return 0;
# ~: a/ G: z. t; _} </FONT></P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5