数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 02:55
标题: 函数大全(s开头)
<><FONT color=#ff0000>函数名: sbrk </FONT>) h6 n) C& p' G8 p8 r0 ~- c
功 能: 改变数据段空间位置
% T6 S9 p; c" J用 法: char *sbrk(int incr);
& S* C% \0 P8 h+ }程序例: </P>
; C- F9 ^/ ?$ J5 D, v$ z/ `<><FONT color=#0000ff>#include <STDIO.H>
  l- r' E$ E3 Q5 g#include <ALLOC.H></FONT></P>
# G( n* k) Q- T" z<><FONT color=#0000ff>int main(void)
$ \6 p8 k2 \% j6 ^5 I8 N{ , l1 _1 n: R  J) G, a( c4 j
printf("Changing allocation with sbrk()\n");   C- w. |6 w9 }/ \/ e% v& c# @" O
printf("Before sbrk() call: %lu bytes free\n", 6 w/ A' a6 F" O# |3 U
(unsigned long) coreleft()); ( b& L' U. Q9 k  r
sbrk(1000);
4 U  c3 W/ G+ Wprintf(" After sbrk() call: %lu bytes free\n", ' {1 \0 M9 u) G: h5 V" ]1 H
(unsigned long) coreleft());
1 }# A1 E! H+ W+ Q& freturn 0; ; H$ Y+ J. x8 D( a; p1 D
}
! _3 o; c9 Y5 P/ Q1 V3 j# s
( U; q9 {% ~9 `! Q' n2 H8 g</FONT></P>
1 `) u/ ?9 \1 q<><FONT color=#ff0000>函数名: scanf </FONT>
$ @8 f/ }6 M1 f功 能: 执行格式化输入
& k- g0 q& p1 `$ ]6 |用 法: int scanf(char *format[,argument,...]); & H7 `; h# \" n2 l
程序例: </P>
' `; d) |; u) t<><FONT color=#0000ff>#include <STDIO.H>
/ Z+ f; H2 H: q* R$ J#include <CONIO.H></FONT></P>
; i1 j$ k( s3 g- h, I<><FONT color=#0000ff>int main(void)
: P# J' n' z. k0 k6 m  R# Q{ ' M$ E! L, g, Y; |9 J8 t# Q
char label[20];
! F% ?7 S% R- I5 Wchar name[20];
( l; C; E# y; A% ^9 ]! e; X# q8 Vint entries = 0;
, e# H- j. J1 l+ G  `( g7 W  [int loop, age;
# Y' g0 V* ^6 ^" Ndouble salary; </FONT></P>
% [6 U) o/ M& P<><FONT color=#0000ff>struct Entry_struct
) i9 Z" g2 x+ s6 n% {{
& o* U5 @& i4 [9 Q2 V1 Z, B4 [4 zchar name[20]; . w$ [9 |$ m2 T% X0 k. H. u! M
int age; 1 L  b6 e, K7 Y6 f) R" I: r5 ]! b
float salary;
/ }; V. v# N" c; W" x( ^} entry[20]; </FONT></P>) V; C% |7 n, R" b
<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
) z. I; J4 t" K0 wprintf("\n\nPlease enter a label for the chart: ");
0 J7 C1 ]) I5 U: X' Cscanf("%20s", label);
8 K3 ]# S7 t) \; M6 I5 |& M6 hfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
; `/ k/ O5 f* r5 c. Y; K4 ^; X$ C<><FONT color=#0000ff>/* Input number of entries as an integer */ + Z/ F" L+ V/ G0 B
printf("How many entries will there be? (less than 20) ");
4 t  b9 ]4 w9 rscanf("%d", &amp;entries);
& t6 n* j! s7 ?8 D3 B9 f! pfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
  k  J$ }  i8 `4 ?. P1 B<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
$ Y7 _# w8 N) Y+ Y. a9 e7 g6 hfor (loop=0;loop<ENTRIES;++LOOP)
6 I. {% l$ t6 \. e8 ~+ X { $ c. J1 i( v9 }6 c& z
printf("Entry %d\n", loop);
6 N2 [/ n, V5 p' ^2 b3 {printf(" Name : ");
7 K+ a+ i* \* Qscanf("%[A-Za-z]", entry[loop].name);
/ U8 U+ s! I2 S# P7 |" cfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>* D2 C) z* y2 K' m7 i* i$ ?. C0 K
<><FONT color=#0000ff>/* input an age as an integer */ ) z% l* I  {# i
printf(" Age : "); % T9 `  ^9 F* j6 C. ~
scanf("%d", &amp;entry[loop].age);
% i2 f0 t5 s& r: U5 l# Nfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
* A" P' q" y, R6 W<><FONT color=#0000ff>/* input a salary as a float */
) l! w6 @' P" w5 S2 r- Yprintf(" Salary : ");
7 v8 X, ]4 F8 c$ f7 Y9 iscanf("%f", &amp;entry[loop].salary);
; i* i- Q3 K: Q& `fflush(stdin); /* flush the input stream in case of bad input */
. \1 M$ U6 a) K8 U6 l2 N} </FONT></P>
! F1 A. X: f1 s<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ ' N* C. [0 C8 i8 g
printf("\nPlease enter your name, age and salary\n"); / E/ g6 b5 j' x% L+ \; \7 v, Z" D
scanf("%20s %d %lf", name, &amp;age, &amp;salary);
5 ~# V1 L6 w% P5 w</FONT></P>/ Y8 O, r4 h+ S3 f+ y
<><FONT color=#0000ff>/* Print out the data that was input */
( t1 l( u+ r1 J4 a& e# u( t* Tprintf("\n\nTable %s\n",label); . e  o8 @+ g$ q5 |
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
) f# ^0 S. F' H  R) I* Zprintf("-----------------------------------------------------\n");
1 E! p, m% c& ?1 |for (loop=0;loop<ENTRIES;++LOOP) ; Z3 {: ]  O6 ~; C0 Y0 M
printf("%4d | %-20s | %5d | %15.2lf\n",
: F4 ]% p. z0 F( v/ floop + 1,
6 ^) Y3 L6 ^" Q) M% {entry[loop].name, + K% J! a+ v$ V0 Q5 o' V; }3 y
entry[loop].age,
# J3 j8 V9 w0 kentry[loop].salary); / e: m# A- n% y: m
printf("-----------------------------------------------------\n");
9 @7 X( n$ T9 F# t" q& f9 zreturn 0;
  U9 B  O" f, {  _- ]}
) o6 b) y+ f+ ^& U7 f</FONT>8 Q. h. P" R. I; V$ ~: n
</P>
# l- M. N4 e7 L0 p$ \4 ?<><FONT color=#ff0000>函数名: searchpath </FONT>
$ o2 `9 p' @7 v8 ]4 `0 q9 ?& r, e功 能: 搜索DOS路径 % Z9 g" y# D' Y* |
用 法: char *searchpath(char *filename); 9 t6 R* D! _1 y5 q5 ^2 [5 E8 d
程序例: </P>! p. D8 \: ?" P
<><FONT color=#0000ff>#include <STDIO.H>
, {6 ?( V2 B/ P" H8 c#include <DIR.H></FONT></P>
- {* m2 F( r' r- q! t# ^8 R1 I<><FONT color=#0000ff>int main(void) # o/ o! f9 s# e4 g$ j' v4 L
{ 3 P. A) E3 m* f
char *p; </FONT></P>" }' L9 a' N) q$ p* |' @7 K$ |! k# I
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer 0 u2 P' [3 m" e8 {
to the path */ 8 s3 c. N5 E. V& e7 {; T# b3 d
p = searchpath("TLINK.EXE"); : ^1 H0 E4 O; g+ C
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>
( r: b& N/ Z+ M. Q<><FONT color=#0000ff>/* Looks for non-existent file */
! C8 x0 B" q7 U9 _7 up = searchpath("NOTEXIST.FIL"); - N- _" l! f* |0 Y6 X3 Q  }- _5 Z
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>6 V, M. |7 O" D. I2 c9 ]
<><FONT color=#0000ff>return 0; $ M; G5 Y1 O6 a1 i6 ]
}
7 f& Y3 H) t: e6 N4 X+ P& S7 k, Q$ X! c1 h
</FONT></P>
1 H0 N6 H- D! K& v1 G<><FONT color=#ff0000>函数名: sector </FONT>
' ^% O, I; w& b8 m% R. s4 k9 L功 能: 画并填充椭圆扇区 4 w+ R& }# L7 R2 b+ d8 j$ G7 I
用 法: void far sector(int x, int y, int stangle, int endangle);
; M3 T# y2 ^& g+ q' r程序例: </P>
6 j; K% C* L+ S* F' {<><FONT color=#0000ff>#include <GRAPHICS.H>% I" C* ]# I3 B7 L
#include <STDLIB.H>& y6 l/ L8 @$ l4 g' I# }7 ^
#include <STDIO.H>
, }  L' V! c+ E3 E5 r, \1 r$ f4 w#include <CONIO.H></FONT></P>/ t4 j( x* X1 V/ m8 M& A8 x
<><FONT color=#0000ff>int main(void)
) Z  Y! N2 H4 Y& m+ y{
+ \, F2 Z0 s2 n! T+ `/* request auto detection */
8 w- }) U: _/ b: j) k" S" ~1 Bint gdriver = DETECT, gmode, errorcode;
+ m# u6 p) K. U+ |. z; O: Lint midx, midy, i; ; _6 R5 Y/ [: }6 @/ E7 A5 e
int stangle = 45, endangle = 135; 8 s7 l' M/ n! d' w2 Q* M
int xrad = 100, yrad = 50; </FONT></P># [% I; a( ~8 ~: W
<><FONT color=#0000ff>/* initialize graphics and local variables */
/ u2 }, [4 N/ E7 N1 P8 b8 minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, q2 Z% q: P6 E/ U6 P: E# L4 `
<><FONT color=#0000ff>/* read result of initialization */
# r% u- z& U# f- K0 M: _errorcode = graphresult(); + f6 X9 _6 j6 d3 h( J1 V
if (errorcode != grOk) /* an error occurred */ + ?8 A7 R2 {# z9 b0 e
{
' }: B* e! P- s8 @. V/ E$ M" Uprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 m5 x7 V9 Z# M  f8 r5 C% b4 {printf("ress any key to halt:");
- i  N6 c2 c% Z! Dgetch();
) Z" i' o$ a& N; z6 A) {exit(1); /* terminate with an error code */
/ v5 h$ I$ q4 X) u, K} </FONT></P>
8 `; O1 y" [1 m  \! t<><FONT color=#0000ff>midx = getmaxx() / 2;
# I) `: {& b6 D9 u' F; F; Omidy = getmaxy() / 2; </FONT></P>2 `6 l& @5 Y9 H
<><FONT color=#0000ff>/* loop through the fill patterns */
* r( T* d4 ?+ f7 O5 Wfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
7 E6 e+ |7 E  @/* set the fill style */
6 h8 K* x+ ~* Esetfillstyle(i, getmaxcolor()); </FONT></P>
0 M  q: U3 O, V$ a8 d4 W<><FONT color=#0000ff>/* draw the sector slice */
" U) W! O. U2 d5 @: usector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>
6 L. O5 ^, p8 O<><FONT color=#0000ff>getch();
" x! R# _) s& H8 D} </FONT></P>7 c6 x! k+ G6 Y4 h% b0 N8 r+ q
<P><FONT color=#0000ff>/* clean up */
* v3 N0 n6 a; i( L+ Qclosegraph();
3 n% W& T7 x" k  {: e; ?8 D* |return 0;
" \$ L! \* j8 `7 `2 G} ; K7 o7 {. g* }' @4 R1 a; M2 w! v
</FONT></P>; ?" {4 B$ [, W% K
<P><FONT color=#ff0000>函数名: segread </FONT>  W6 Z3 }  h0 S
功 能: 读段寄存器值
: g, i! `0 f. o( a) L用 法: void segread(struct SREGS *segtbl); ' H0 `6 X% ^+ |1 n! [
程序例: </P>3 `" \9 R% P& \0 @0 G+ U) P
<P><FONT color=#0000ff>#include <STDIO.H>1 o: }, X) R! y1 J- s; u& k$ d: R
#include <DOS.H></FONT></P>- J* P( X/ v, @# m) ^
<P><FONT color=#0000ff>int main(void)
: L% i  B2 D4 R* x/ L6 P/ |# `: x$ ?9 }{
( ]* Q( C: @* G, Astruct SREGS segs; </FONT></P>
& h' A0 w" u- R<P><FONT color=#0000ff>segread(&amp;segs); : ]2 m+ ?* d2 @8 i, I! I
printf("Current segment register settings\n\n");
3 h$ q6 U& J3 y7 X* j. hprintf("CS: %X DS: %X\n", segs.cs, segs.ds);
, v2 `3 X/ r9 c8 }" Zprintf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>* x2 e" H9 ]8 D8 b
<P><FONT color=#0000ff>return 0; 4 C: y/ A  Z. ~- Z
} </FONT>! b8 b* I/ h0 ]& C5 F* w
& v& |" @. p4 Z. k  ?% G( j; s
</P>; ~+ V2 K2 w) n& \3 O  q
<P><FONT color=#ff0000>函数名: setactivepage </FONT>
& N( A  h+ F/ x0 s功 能: 设置图形输出活动页
( R% i) `, p# ]& e+ `% V# J/ b用 法: void far setactivepage(int pagenum);
* o" k5 G) {+ C, s* W9 r' L9 O9 G1 O程序例: </P>
9 D  C! Y7 n( d0 @<P><FONT color=#0000ff>#include <GRAPHICS.H>
' K( y, i+ B! s- f$ s: g  q#include <STDLIB.H>
1 g$ _% H" ]( J; z$ p+ j#include <STDIO.H>- u) P3 n6 u+ h7 S
#include <CONIO.H></FONT></P>" U/ D# H) y/ {' Q; [/ K
<P><FONT color=#0000ff>int main(void) / M" D) r1 Q8 ]& i
{
5 x3 m! r2 @+ O8 n# Z$ V/* select a driver and mode that supports */
* f& P6 O% t$ q. V/* multiple pages. */
: V# |7 B, V4 r; a: t8 B+ Mint gdriver = EGA, gmode = EGAHI, errorcode; % z& F# q2 t$ C3 [
int x, y, ht; </FONT></P>
" N$ @2 N+ |) E0 p' k<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 M9 R  w! ]2 K
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; ?+ Z9 _7 G( f) d# {<P><FONT color=#0000ff>/* read result of initialization */
# E# ^  Z* S2 l# j; I) j% p, kerrorcode = graphresult(); " u, f0 f) w) E  y+ {7 Q* w
if (errorcode != grOk) /* an error occurred */
# P; e; L2 R) c9 F/ i{ 7 k! j4 T& s" F2 T( y# A
printf("Graphics error: %s\n", grapherrormsg(errorcode));
9 u2 {4 f5 Y& {2 l( Z4 Cprintf("Press any key to halt:"); % A; G, A" I  j$ |/ H* ?" [' p  X
getch();
& Q: M5 f% O. f1 ~. d: p8 [6 yexit(1); /* terminate with an error code */
5 t# z  P  ]7 R7 q8 {( ?, }) V} </FONT></P>
6 F  m! ]0 l# o; S  B<P><FONT color=#0000ff>x = getmaxx() / 2; 7 Q  }1 C4 w. ^$ i4 s; n
y = getmaxy() / 2;
" }0 b1 S: B/ m9 f4 q3 i, p  ?ht = textheight("W"); </FONT></P>( p5 v- c8 f. {0 `
<P><FONT color=#0000ff>/* select the off screen page for drawing */ $ m3 ]& o( a( X
setactivepage(1); </FONT></P>& }5 b4 [; p* I+ m
<P><FONT color=#0000ff>/* draw a line on page #1 */
% G& b; v" g8 ]2 d( ?. G8 V/ o' Bline(0, 0, getmaxx(), getmaxy()); </FONT></P>
+ C* c6 O+ R; y! y, [( p& V<P><FONT color=#0000ff>/* output a message on page #1 */
4 n' F/ ~! ]+ @1 Y) [8 bsettextjustify(CENTER_TEXT, CENTER_TEXT); ! m2 a* ]6 I6 ?8 [8 w& Q: R
outtextxy(x, y, "This is page #1:");
+ z, L; S8 g  p9 v* C, w6 touttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>% v0 Z" a8 z: e1 _4 F7 |1 A
<P><FONT color=#0000ff>/* select drawing to page #0 */
9 p4 l- N  E9 ]0 r4 b$ s8 e. ysetactivepage(0); </FONT></P>- P& B( K: H. u7 ?: \7 y
<P><FONT color=#0000ff>/* output a message on page #0 */
; @$ F/ O- E8 kouttextxy(x, y, "This is page #0."); 1 J  V7 m, \6 \/ W! d
outtextxy(x, y+ht, "Press any key to view page #1:");
8 v! O( ^  o: _% ~0 E' dgetch(); </FONT></P>( V, ~& _5 L0 d! X/ B
<P><FONT color=#0000ff>/* select page #1 as the visible page */ 5 S6 w9 O" c9 o; c- U
setvisualpage(1); </FONT></P>7 y* S& }: X. T
<P><FONT color=#0000ff>/* clean up */ , b# x6 T: Y2 Y
getch();
  R' L" K6 b) hclosegraph();
+ c  C; m* C3 b7 S9 kreturn 0; . Q& x9 ~% h+ [3 Q) l  L
} 6 P. E* J% y# b6 q% |
</FONT>& ?' U0 H7 L5 [- k) W  Q9 v* ?
</P>
3 i/ ~" K' _. ?* [! O/ r<P><FONT color=#ff0000>函数名: setallpallette </FONT>
' Z" e, o  H$ M; Q功 能: 按指定方式改变所有的调色板颜色
- V: n3 ?! q9 ^* @6 x1 p; i8 Y用 法: void far setallpallette(struct palette, far *pallette);
9 T. ?1 c  w  n0 ^: z程序例: </P>! v$ @) _- r7 [: D: d4 S
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ d; @  t6 L. w- v, w6 B* e#include <STDLIB.H>1 V, q0 K7 Q) W  V
#include <STDIO.H>
" z& o9 K$ n8 X9 Y: c#include <CONIO.H></FONT></P>
; y' H) L. e( z6 Y8 ~. Y7 @<P><FONT color=#0000ff>int main(void)
7 |/ e" B5 E' E  Y{   i& @7 O( }: `9 u
/* request auto detection */ % @( ~4 ~0 x6 r( f# Z7 i
int gdriver = DETECT, gmode, errorcode;
$ N$ z0 y$ o4 p! a* D4 ostruct palettetype pal;
, X" L8 C6 D2 E9 Kint color, maxcolor, ht;
: ]5 U8 z) f. T. w* Y. [int y = 10;
. u2 _% K  d8 ]char msg[80]; </FONT></P>
( Y- k8 E. m' ]* K<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 W  w) n& _1 X9 a+ n4 q% xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% r6 K6 m# I& j<P><FONT color=#0000ff>/* read result of initialization */ 4 K; q& s3 Q5 \8 w1 q. k0 |2 D
errorcode = graphresult(); $ W2 ?, |9 L0 s" d* g
if (errorcode != grOk) /* an error occurred */
# g, a8 i9 n  h% n{
8 V* N9 \9 |( bprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . j1 f' n6 ?! {" S+ j9 x
printf("Press any key to halt:");
3 v: Z/ V, N8 a. ~$ U" [( D* pgetch();
! C/ a5 i, F- |7 o4 Fexit(1); /* terminate with an error code */ $ _- G% ?. p( a7 y1 i8 R
} </FONT></P>  H3 J: i6 G0 f3 L- m& A* ~; V
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
$ S& y5 H! H, v0 K- }/ R' bht = 2 * textheight("W"); </FONT></P>
6 s  X3 Y9 ]- |" I8 j8 J0 M<P><FONT color=#0000ff>/* grab a copy of the palette */ . t  g( @/ T5 G& h2 B, T
getpalette(&amp;pal); </FONT></P>% w9 L% _# z2 O- E! V9 f0 A: V
<P><FONT color=#0000ff>/* display the default palette colors */
) d" O/ S8 a7 R, kfor (color=1; color&lt;=maxcolor; color++) ! |2 @. A( {1 a( n
{
. E/ e3 p+ G  ?+ osetcolor(color); 7 T" U. ~7 m! t* C8 Y
sprintf(msg, "Color: %d", color);
8 A6 t. h# X& y7 I& ]7 ]outtextxy(1, y, msg);
3 F% o" ^" T% X/ n4 V) My += ht; & h8 s% a( \( P( X# k5 r: \$ D% F/ F
} </FONT></P>
6 V& t8 K7 Y; b3 c% _<P><FONT color=#0000ff>/* wait for a key */ + q; R8 y3 _/ B
getch(); </FONT></P>
7 m+ g4 {& S! l: }4 s5 x; t<P><FONT color=#0000ff>/* black out the colors one by one */ + H3 f" ], U5 |, @  t; Q
for (color=1; color&lt;=maxcolor; color++)
+ v% ?1 b& z; G{
, n3 r. F. N1 E9 V' ]setpalette(color, BLACK); , G0 r7 a; `. v! G6 ]  Y1 n7 z
getch(); 8 b3 }) H; ~& [) v# R" L7 o
} </FONT></P>  l9 J) x5 u( X& v5 q9 d8 @
<P><FONT color=#0000ff>/* restore the palette colors */
8 S7 `, S. y4 ssetallpalette(&amp;pal); </FONT></P>
! s0 t6 E/ J* U9 o' w5 t<P><FONT color=#0000ff>/* clean up */ & W. k/ l5 K0 Z  P
getch(); 6 k9 {8 `# L7 U" B5 P* e2 ]
closegraph(); ( ?+ ?, p! o# N/ i0 h1 _' {6 t
return 0; & ~# a6 J- q/ H+ }0 C
}
. x& \. q7 i4 I, T
* z: j& O1 \8 i</FONT></P>
1 i; W# j! m' n# Q<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
1 d5 b& V: B; _5 }) @功 能: 设置图形纵横比
  e2 I# F; D3 Z. \+ m0 C用 法: void far setaspectratio(int xasp, int yasp);
& j6 f$ P. ]$ |4 i0 t, |/ C- \程序例: </P>1 d2 m' X* A- V3 o6 H1 J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  }2 [& K0 ^  q2 ~3 [" ]0 q' H#include <STDLIB.H>6 E1 o, `2 N$ E) C; c. f
#include <STDIO.H>1 k9 K8 h* F7 l0 N8 q2 _
#include <CONIO.H></FONT></P>
  O5 t' k$ j0 N0 q0 `' n1 ?( t. J<P><FONT color=#0000ff>int main(void)
4 O& q" ]7 ~1 I1 a) U" Q/ j6 u, Q{
1 Z& k& [" B, ]6 u/* request auto detection */ * s# T7 K1 t: {5 J/ M- s# D5 `. X5 |) Y1 F
int gdriver = DETECT, gmode, errorcode; % O: ~" H) N' M! _" G
int xasp, yasp, midx, midy; </FONT></P>
: R; ?7 f. X  H7 v9 L<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 q% A. i. ?# D& A2 R; A' w2 @
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 F8 M+ s/ w& i<P><FONT color=#0000ff>/* read result of initialization */
& N" k9 F2 x2 [+ Z- a6 [errorcode = graphresult();
! K9 Y% T- t5 c4 L/ q! y7 w) v; s7 \if (errorcode != grOk) /* an error occurred */ $ Z! W& Z! @7 }& v) w6 q
{ , q. R) ^# |. s8 m/ G  A
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 k4 |2 v8 ^2 R) T8 O+ o: p
printf("Press any key to halt:");
/ i' ^2 l; m3 A8 |. W* ygetch();   W2 ~( }. Q' j9 X
exit(1); /* terminate with an error code */
1 _8 ], A6 U& h9 s3 o* g/ \; b} </FONT></P>
1 E: L& k2 v  ~) f- N: q. S; |<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 m. ]! g' D* F# l9 @# ?
midy = getmaxy() / 2; + ]2 D  _: D! B' y7 ]" E' _8 r7 H
setcolor(getmaxcolor()); </FONT></P>: ~$ b$ v/ S/ n: C* N5 u+ \1 y8 s
<P><FONT color=#0000ff>/* get current aspect ratio settings */ : ^' W; n+ _/ B" ?- v) ~' k
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
" S- v0 c( j" ]<P><FONT color=#0000ff>/* draw normal circle */ . B+ j9 i+ L: U
circle(midx, midy, 100); " U7 @. l9 S7 I- z! C# v& u9 ?
getch(); </FONT></P>
6 c# S; B" W1 t: }<P><FONT color=#0000ff>/* claer the screen */
; @9 Y- \  b& c1 i8 ucleardevice(); </FONT></P>
$ {8 p( I" y$ u. F0 \2 `: f<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ 5 R% J/ E" T, ~. w
setaspectratio(xasp/2, yasp);
( A% d# e; }. w+ R  L, Gcircle(midx, midy, 100);
: I) b6 M( Z3 }( c4 [getch(); </FONT></P>' H: L6 A. v4 d, \; |5 w/ a5 V2 W% n
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ , r7 b4 N* e: J! N" {* N
cleardevice(); 0 S& P/ d; v; ^6 A, ?3 K5 h4 ~5 f
setaspectratio(xasp, yasp/2); , \9 o$ u5 Z1 G
circle(midx, midy, 100); </FONT></P>8 Z, B' O- g$ G
<P><FONT color=#0000ff>/* clean up */
- o& w7 R7 N# O; ygetch();
6 e8 e# d$ V, F9 jclosegraph(); * J6 [4 l) N) z
return 0; " M' d' y7 D. t5 s1 x. @1 G( \
}
. U( T! C  I& n# g% T4 h$ S; X4 v</FONT>
, _4 G3 R% @; ]</P>9 c+ h: {# u% ~. j
<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
8 H: k; `! ~, g% A- }  J8 U4 [, C功 能: 用调色板设置当前背景颜色
& o% w: b2 I' G# n! z8 t用 法: void far setbkcolor(int color);
  C5 N* n& k( M2 ~( o, D程序例: </P>
. x- Q" |0 J3 u* i" W8 |  @<P><FONT color=#0000ff>#include <GRAPHICS.H>
& y+ W. W8 O+ _/ p#include <STDLIB.H>
- J6 n" ?' i/ D8 q( }0 O7 J#include <STDIO.H>
/ {- @6 s) ^, f" {#include <CONIO.H></FONT></P>& U4 ?$ t. t0 K) p7 s! Y4 Z' y
<P><FONT color=#0000ff>int main(void) / N9 \7 x" w% B
{
& ~2 m8 s' H, \" j( G$ Z& D/* select a driver and mode that supports */
# U& b) }0 g# D$ g/* multiple background colors. */ 1 Q, _' t' p3 w4 g  B3 \* Q
int gdriver = EGA, gmode = EGAHI, errorcode; $ X: a) j, O1 j3 A1 r+ N) [
int bkcol, maxcolor, x, y; 5 E2 H/ W# _: m, o: k
char msg[80]; </FONT></P>4 d. |/ c) _7 ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */ % ^& c3 K. `; u! S% f7 c* {
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 O/ F" P! @; n% W+ p
<P><FONT color=#0000ff>/* read result of initialization */ % B1 G5 t3 B8 `/ o
errorcode = graphresult(); & r/ K: Z3 v1 L
if (errorcode != grOk) /* an error occurred */
6 p* |1 F( Z3 n{
0 m; f1 s" L# b! z# K5 Uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # H+ H$ O! K2 E% H/ A3 M4 E. ?2 ~3 H
printf("Press any key to halt:"); . b% h3 u9 Q" \5 d& _
getch(); : t0 @4 D0 ~( |. X1 I$ c0 x0 @" h7 N
exit(1); /* terminate with an error code */ 7 _" I. j/ x: U  W
} </FONT></P>/ O% P( _3 K! r
<P><FONT color=#0000ff>/* maximum color index supported */
  E/ _& X4 X2 Y9 S2 Smaxcolor = getmaxcolor(); </FONT></P>, [& _6 B. M; \
<P><FONT color=#0000ff>/* for centering text messages */
& ?) y! N: l* Asettextjustify(CENTER_TEXT, CENTER_TEXT); 4 g* Y1 Y( {  W- f
x = getmaxx() / 2;
+ {6 B( r9 M4 {; Ny = getmaxy() / 2; </FONT></P>4 r' s# \0 A  g; y: v$ u3 r6 v
<P><FONT color=#0000ff>/* loop through the available colors */ 1 d! u, v; p" G7 ]  w
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
0 ], o6 j+ ^. Y1 \2 L{ : o8 l% W0 t+ O
/* clear the screen */
0 ~1 l' f: c' ?, a+ `" c, pcleardevice(); </FONT></P>4 f$ @0 }$ P: z7 W) m. N
<P><FONT color=#0000ff>/* select a new background color */ ; G* y  i$ A1 A* t' y) o3 F, I7 Q$ p
setbkcolor(bkcol); </FONT></P>
/ b! _! s! C6 T2 X) j<P><FONT color=#0000ff>/* output a messsage */
0 e" [1 u5 u1 C' k. D7 a1 aif (bkcol == WHITE) 3 Z% \1 l2 v4 S
setcolor(EGA_BLUE); 6 p& `+ `0 J, o. H2 i1 Q2 E  I
sprintf(msg, "Background color: %d", bkcol);
) }5 k, A( W+ y' o: B7 gouttextxy(x, y, msg); 3 L9 R: i, |& F) Q2 p3 y) Q
getch();   G( p0 x& t$ P; M8 z. S5 x
} </FONT></P>
: ^/ L9 \" l* @3 O; Y. W5 }* g<P><FONT color=#0000ff>/* clean up */ ) f5 [, m4 C, k6 x
closegraph(); $ {3 m, U0 K1 R
return 0;
1 m& x& ~5 r, R} </FONT>9 y5 @1 g9 a* O' Y8 s7 Q4 t- v

# @% M$ K4 |7 Z( @- D& z. j( E" e</P>
* }; f. K  _! d<P><FONT color=#ff0000>函数名: setblock </FONT>
  _4 @0 g+ K+ R/ M+ H& N0 j! I# [功 能: 修改先前已分配的DOS存储段大小
1 N0 H9 K, _8 ]9 C8 A( C2 W用 法: int setblock(int seg, int newsize);
+ n  ~: ~0 N$ W. l8 u程序例: </P>; d% l( S* ]  S2 W. {# k
<P><FONT color=#0000ff>#include <DOS.H>
/ e! R2 b" U& K$ P! v5 M+ j#include <ALLOC.H>
9 \1 ~! X! b% k6 D- ~& ]#include <STDIO.H>
0 H: a3 p6 `  I: U1 e#include <STDLIB.H></FONT></P>5 K* P  X4 J* V% e
<P><FONT color=#0000ff>int main(void) , n  |& w2 x1 ?) }3 j0 j( v  G
{
* U- f2 u: Z' Uunsigned int size, segp;
+ J+ G" t# u' e$ a3 Sint stat; </FONT></P>
. \. Z% j+ k1 n, m! l<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */ ' i) b/ [1 @6 I3 }8 R' G1 n; e
stat = allocmem(size, &amp;segp);
8 C; m* ~  \1 y! M& Pif (stat == -1) . O& k7 x) s2 S; o- T. i/ Z' o
printf("Allocated memory at segment: %X\n", segp); 4 [3 W! d* e8 e
else
6 t4 F" _8 d- C. b% I$ Y. u{
' `8 V9 |) x9 g9 Tprintf("Failed: maximum number of paragraphs available is %d\n", # J+ n% M; z: T1 d/ g; Z% q
stat); 8 \. T; Q0 p. X; C* |7 J$ E/ y
exit(1); 7 O. W' {- d: N* N- ~3 D9 |
} </FONT></P>! o  a5 J; }! l3 l. M+ w3 i2 _
<P><FONT color=#0000ff>stat = setblock(segp, size * 2); : s% K: ~1 E* [8 O! u
if (stat == -1)
2 A7 W; _: q3 f& \- d6 A8 ~  O5 L' _printf("Expanded memory block at segment: %X\n", segp);
( ]7 K+ Z. j& U2 F5 s7 j- pelse ' Y9 ?  E( ~1 S* R( P; R
printf("Failed: maximum number of paragraphs available is %d\n", 2 h7 [) c' W: C  P
stat); </FONT></P>
( c% t) a* ]0 H3 |6 h( k<P><FONT color=#0000ff>freemem(segp); </FONT></P># t8 B- d7 w7 u! S3 e( ~- r: w8 w, `
<P><FONT color=#0000ff>return 0; * Q4 J9 i4 L% w6 |2 |  L* P% x
} 4 S% L3 q& L6 |2 P' D/ t* f
</FONT>( B" r0 _0 h7 l* f  }: K+ q& C* d
</P>
, W! D6 n; m; H5 z; Q<P><FONT color=#ff0000>函数名: setbuf </FONT>) k+ R2 P; {; k; z7 u0 v& y
功 能: 把缓冲区与流相联 % f, o9 U+ |  V4 H  \% P# y. G( H7 @
用 法: void setbuf(FILE *steam, char *buf);
8 p7 e1 _" }4 e) _) W程序例: </P>* {( y' I0 Y2 \7 F0 ^
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>. p: X# L# l& I) n, p/ W& I% q
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ 0 X4 j1 Z" n9 Q/ \
char outbuf[BUFSIZ]; </FONT></P>
5 v' l7 Q4 c7 Q- p<P><FONT color=#0000ff>int main(void) : U: q8 b5 |5 f% y6 o9 n5 x3 b
{ - Z0 G( d  @2 R% C- n9 f+ `. A. J
/* attach a buffer to the standard output stream */
- T- j, H. f9 O0 Y8 G( P, U  nsetbuf(stdout, outbuf); </FONT></P>
! e( l, Z/ {8 {, d* N7 s7 B4 g<P><FONT color=#0000ff>/* put some characters into the buffer */
; s6 n; g, s5 t2 Kputs("This is a test of buffered output.\n\n"); * t) @! n1 `6 q9 _: x
puts("This output will go into outbuf\n"); 8 G0 N3 N! r" \  a' g
puts("and won't appear until the buffer\n");
4 L6 N$ B) Y5 u4 Gputs("fills up or we flush the stream.\n"); </FONT></P>" T. F5 F6 t: y/ d
<P><FONT color=#0000ff>/* flush the output buffer */   L+ I- t1 e* p. l8 v3 n6 W6 K4 d
fflush(stdout); </FONT></P>. t* F+ W5 n, F
<P><FONT color=#0000ff>return 0;
- o) f7 ?7 Y+ e} $ N& \8 i! f, ]5 I
</FONT>. Z$ C% I; {2 o" Q6 Y4 K
</P>
6 _9 }/ _! b# c1 K0 R<P><FONT color=#ff0000>函数名: setcbrk</FONT>
# H) u6 }- E6 p! N功 能: 设置Control-break " k" A/ `' U. ], C
用 法: int setcbrk(int value); $ G: K3 i0 {4 T8 S
程序例: </P>
2 M5 K" H7 ]5 o( }0 s$ f<P><FONT color=#0000ff>#include <DOS.H>
' U2 g4 w4 V5 |8 z' u3 X#include <CONIO.H>
# v) {* f4 I! D#include <STDIO.H></FONT></P>  z' b+ E8 M, X
<P><FONT color=#0000ff>int main(void)
" b/ `; K! n5 c1 z7 A9 d) R( b{
/ |6 u* u1 g1 nint break_flag; </FONT></P>
& U4 u, G) q! J, i<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n"); 5 Z; V( Y" b, l9 H- \. G
printf("Enter 1 to turn control break on\n"); </FONT></P>
/ l2 o* ]& S: U' r<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>' n# |" \$ }: H; V2 H
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>" A' g! O- l: z" X3 D: M
<P><FONT color=#0000ff>if (getcbrk()) ; Y, n# v5 D1 E' L  d( @- \  B
printf("Cntrl-brk flag is on\n"); . p. Q; r5 m0 i: R: U5 T
else
& u2 }; }) ?; f# Mprintf("Cntrl-brk flag is off\n");
1 y" A" F' @' l4 Y, @' ureturn 0;
5 P3 L8 p- {) y$ t- o} ) i# v" i  K1 f% N7 H
7 R+ W! S8 C* v! I) g
</FONT>
! S1 e8 i4 f, A- J+ S( A1 x6 S</P>
$ ~$ i% X( d0 a1 i* \3 w<P><FONT color=#ff0000>函数名: setcolor</FONT> & y8 F. B6 v6 c* y4 Y* y
功 能: 设置当前画线颜色 8 ^* F4 N" y  H- h% s( ?
用 法: void far setcolor(int color);
  i# @8 @! R9 K7 _. C' b  h程序例: </P>! A6 y5 b( F( v; ~1 a+ t7 B
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 p& D$ X$ b4 |4 l; k7 R! X( w
#include <STDLIB.H>5 @) V, D1 ~7 }5 B) W) q' ~) Y# j3 L7 {
#include <STDIO.H>% ~! y! o  K! M4 E9 z
#include <CONIO.H></FONT></P>
, t: [# ?' m* f3 N9 ?0 R3 H<P><FONT color=#0000ff>int main(void)
* y/ h( C2 M* p( i7 d2 Y) B{ 2 C! l; p  K) `5 w" x
/* select a driver and mode that supports */
% ?( e# ~3 E9 w3 B+ ~% s/* multiple drawing colors. */ ! ~( p, q; l# O/ @  m
int gdriver = EGA, gmode = EGAHI, errorcode;
7 G& ?# F* N# Y' _0 x1 G4 }2 E& Aint color, maxcolor, x, y; . M$ N8 D; A# C5 z8 U
char msg[80]; </FONT></P>
. _9 t' K& r4 D0 E# p' Z8 n<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 d. T$ ~. g+ E$ |initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 }' t  J( H3 N2 x2 Y
<P><FONT color=#0000ff>/* read result of initialization */ - A2 y. V  _+ F& n+ o  R" k
errorcode = graphresult();
1 s  p% a# c! M% L2 O9 H7 Mif (errorcode != grOk) /* an error occurred */ . n1 Y( [8 Y. H
{
0 O4 b+ S4 y; y; A1 a9 s6 O3 _printf("Graphics error: %s\n", grapherrormsg(errorcode));
: e. L$ m! [% Mprintf("Press any key to halt:");
) l, F$ W4 ^( M" ^* Vgetch();
; x. Q0 b4 s. a- l7 Z0 ]: T) Eexit(1); /* terminate with an error code */ / G! O8 Z# e7 ?
} </FONT></P>& t! M) K) |0 {8 {: y/ \
<P><FONT color=#0000ff>/* maximum color index supported */ & a5 M' a( `; o$ d' z
maxcolor = getmaxcolor(); </FONT></P>
) }) i- r4 n! @4 I4 o# i<P><FONT color=#0000ff>/* for centering text messages */ ! D: ~4 b) S, z1 x& `* S" ?
settextjustify(CENTER_TEXT, CENTER_TEXT); 7 @" A( H: ~+ G  `
x = getmaxx() / 2;
5 v/ S& {# g) _6 F3 z! Oy = getmaxy() / 2; </FONT></P>9 u( w2 ]+ o( ~7 K  m. Y( c
<P><FONT color=#0000ff>/* loop through the available colors */ ) X; j8 w. L+ Z! a% l  C* }0 B6 Z
for (color=1; color&lt;=maxcolor; color++)
2 k- D+ @  l) Q7 A3 t* l- t{
0 {1 O$ [% d2 l6 f$ |2 P2 I/* clear the screen */ 4 b) r) N! k- ?' p( h
cleardevice(); </FONT></P>
+ j& t7 `+ j8 n$ n<P><FONT color=#0000ff>/* select a new background color */
. A- X1 ~- {; x% I4 d3 s9 t4 i2 d. csetcolor(color); </FONT></P>( g' B6 H6 g7 ], k% {0 K
<P><FONT color=#0000ff>/* output a messsage */ 9 z2 c% D4 R! {: v  U
sprintf(msg, "Color: %d", color); , S/ {4 D; J1 J, w, o% C6 `0 y7 ^
outtextxy(x, y, msg);
0 x- b& S6 W( h0 k& \4 Bgetch();
, ?4 g5 D/ T! u5 w} </FONT></P>
1 Z4 }0 Z0 ]+ Z# I/ M3 d<P><FONT color=#0000ff>/* clean up */
1 w! r- u1 ~: d1 N% Fclosegraph(); 3 X; _3 e& d# ^4 U
return 0; 1 e$ O' G: ^% V  g8 f  r
} + w6 H/ ]8 R. ]0 y8 I
</FONT>
2 f, \6 x" c. K+ t: O8 f</P>
, b, N0 _, v! o% s<P><FONT color=#ff0000>函数名: setdate </FONT>
: G5 _- n6 M! r* x功 能: 设置DOS日期
4 l, l7 z% v5 X, \* H+ R' I用 法: void setdate(struct date *dateblk);
1 K! ?+ `. G! G3 l' r" \程序例: </P>
# }: O! t. _/ g/ z, O8 @<P><FONT color=#0000ff>#include <STDIO.H>
8 m% o) z" W' }  G- ?% {#include <PROCESS.H>
5 e) {9 ^& `1 I#include <DOS.H></FONT></P>
9 L$ j  I4 ]9 u# @8 ]' Y+ {9 H<P><FONT color=#0000ff>int main(void) ) `( I# _' d# L2 k' S; F% m  g% x6 ^
{   S; ?) t  L5 p/ e  r* r& N
struct date reset;
+ X1 F3 F" [/ Q/ }( H6 pstruct date save_date; </FONT></P>: R( {2 \3 a) C, q. y5 `) D- A4 a
<P><FONT color=#0000ff>getdate(&amp;save_date); 7 W' V* i& Y, V2 a3 o4 B
printf("Original date:\n"); ; ?9 _- r$ e9 Z7 o- p7 Z
system("date"); </FONT></P>3 ~4 X9 d) i5 K+ }' F+ r- `
<P><FONT color=#0000ff>reset.da_year = 2001; " f+ U) ]) B  s, Y
reset.da_day = 1; # @% d  \( |7 p) o( Q6 P4 R6 J
reset.da_mon = 1; * @2 s+ [8 \9 t; \5 e
setdate(&amp;reset); </FONT></P>
& B1 Z/ H9 T& j<P><FONT color=#0000ff>printf("Date after setting:\n");
; z; Y3 ~1 H6 ~2 V/ I, dsystem("date"); </FONT></P>
( q. x( Q. K5 j, A. N' M. B+ k<P><FONT color=#0000ff>setdate(&amp;save_date);
2 s; P! H- K- I' t! \printf("Back to original date:\n"); ) d/ y6 g2 d  U3 @7 `2 R
system("date"); </FONT></P>! U7 d5 T; C* s, P: J
<P><FONT color=#0000ff>return 0;
  L, H0 E9 s% |} : X* q9 G% x7 @- e) O( A
</FONT>/ N; t3 |) T, C! Z3 W  _6 R
</P>
* ^  j7 s. M) U& |( t0 h<P><FONT color=#ff0000>函数名: setdisk </FONT>
/ J- q% X; {: F* w& O功 能: 设置当前磁盘驱动器 2 K4 N  V( p' v
用 法: int setdisk(int drive); , h6 B4 Q2 b  d" V7 `$ S( P
程序例: </P>9 M) }2 E! ?4 T# M* {5 ~/ t! z: \
<P><FONT color=#0000ff>#include <STDIO.H>
8 L% Y  U& }( C% O#include <DIR.H></FONT></P>2 }+ A6 n- m; @; }, e) }  @4 t6 V
<P><FONT color=#0000ff>int main(void) 5 H% w4 E6 N4 A8 M% S& W9 o
{
# N! `; F6 P3 A* `- K' nint save, disk, disks; </FONT></P>
& G/ w" X% z9 ]! g& x<P><FONT color=#0000ff>/* save original drive */   w8 w6 L, c; T2 N) r. ?
save = getdisk(); </FONT></P>- s2 h$ ~5 h) K4 q+ s
<P><FONT color=#0000ff>/* print number of logic drives */
9 F. t! r. X8 ~& rdisks = setdisk(save);
' Y6 H! U1 v3 p) s4 X! p) s5 `printf("%d logical drives on the system\n\n", disks); </FONT></P>
! n6 h8 U+ N; c; c<P><FONT color=#0000ff>/* print the drive letters available */
0 w) ]/ X& V" t. Dprintf("Available drives:\n"); 0 [. u# u7 C5 L$ o2 Y" t$ X
for (disk = 0;disk &lt; 26;++disk)
; n9 z2 G0 y1 H+ }, S( e{ $ r; Z, l1 ^1 p, Y0 B
setdisk(disk); 7 S& r) d, A. b) i9 y6 f
if (disk == getdisk()) 8 c! O. W2 ~, D- A: j
printf("%c: drive is available\n", disk + 'a');
1 b) O. j" Q7 V$ z}
( D" l3 J2 T" [- |setdisk(save); </FONT></P>( {& x) I9 C7 q- G
<P><FONT color=#0000ff>return 0; 2 O* I% G  M6 B0 p( F
} </FONT>: t: t# _! n5 H  u

% `& z7 b& |+ n. y1 ^* e, s8 t' G) [</P>
% r8 ^- f' ~, _0 n, e& @' Q5 u: e/ O<P><FONT color=#ff0000>函数名: setdta </FONT>6 p* ?8 b0 L. p- j( [* b
功 能: 设置磁盘传输区地址
0 ]" ~  h* O; E. `. ], n8 l用 法: void setdta(char far *dta); 6 m& B3 g# D6 J- ^% a9 {- l% ?" z
程序例: </P>5 o7 g8 @- ]; h/ w/ H
<P><FONT color=#0000ff>#include <PROCESS.H>: c2 k: d- k: _: y- b
#include <STRING.H>
1 O# s/ _* `, b$ _( `#include <STDIO.H>8 h( h) A+ b6 c* A" ]
#include <DOS.H></FONT></P>; ]* P- r4 v/ [( w# O0 I
<P><FONT color=#0000ff>int main(void)
! S( y: [# R0 j1 O2 D  U: ^) |{
5 ^7 v. [/ {$ \! h* }: i+ Echar line[80], far *save_dta; 0 J. g& B; Z8 @/ F: u' y
char buffer[256] = "SETDTA test!"; 1 p. m) r& O8 [7 k5 S  c
struct fcb blk;
- @& D9 `) }& X1 z( _. Lint result; </FONT></P>
; R4 a/ I* N! J9 }<P><FONT color=#0000ff>/* get new file name from user */
" e( ^; z9 h6 {0 _) l0 j) I; Bprintf("Enter a file name to create:"); * C6 g, p" ]$ r8 K( m3 u
gets(line); </FONT></P>
) V' ^! }' q% e; S0 C9 d9 }<P><FONT color=#0000ff>/* parse the new file name to the dta */
) f8 {$ h+ K8 u' Tparsfnm(line, &amp;blk, 1); * X) m! k- {* N  ]! F
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
# f0 S& [0 B" X/ L& f# d. Y<P><FONT color=#0000ff>/* request DOS services to create file */
" ]5 z# u6 B' c+ Vif (bdosptr(0x16, &amp;blk, 0) == -1)
% i1 _" ]5 F# f  D' S% R# F  h{
5 W! s* K+ e$ hperror("Error creating file"); # z) x# p  u5 M
exit(1);
( j6 n9 y+ O( l} </FONT></P>+ U+ F% f7 g' \, @# [$ O, h
<P><FONT color=#0000ff>/* save old dta and set new dta */   }( b6 |" M: d, V
save_dta = getdta();
8 g& l# K& c3 s: Q* u7 _5 usetdta(buffer); </FONT></P>
" ]% [& x& ^0 V# A; Z/ n7 a, r<P><FONT color=#0000ff>/* write new records */ " K) b. N  P( z$ [' \) F) N
blk.fcb_recsize = 256;
3 W9 @4 F0 L8 S: Z; u- x7 z9 tblk.fcb_random = 0L;
! n! P% _9 {' R3 ?1 r& bresult = randbwr(&amp;blk, 1);
, n" D; r8 I* P1 G9 y; Q0 Bprintf("result = %d\n", result); </FONT></P>
) q( X& u) A& d! w/ H& h+ k<P><FONT color=#0000ff>if (!result)
. T) I; z' S' {  n8 V! ~printf("Write OK\n"); $ j" W, P! R. _5 ], e
else 7 R( C/ M3 x  K8 K
{
, g3 d/ W5 C# t4 m1 Hperror("Disk error");   ]7 v* |& E; D; v6 z. S" r/ A0 H
exit(1); ! l/ O' q. o5 W  r
} </FONT></P>
% E4 S. M4 j5 e7 F<P><FONT color=#0000ff>/* request DOS services to close the file */
% c2 ]" P& R% Z* oif (bdosptr(0x10, &amp;blk, 0) == -1)
0 v) L. F% B: ?) J{
+ k% f4 c$ ~+ V& Z- zperror("Error closing file"); + z4 u5 [/ x# V, \# W1 }! C2 w
exit(1);
& z! e* n. K  Y, a) D7 e} </FONT></P>$ _' X+ _6 w! y- J
<P><FONT color=#0000ff>/* reset the old dta */ # J* x4 o7 j8 s" E+ W
setdta(save_dta); % d( c; C# f$ R& R' @6 X0 ~
return 0; , y9 N+ h8 y: G0 X; t- g7 p+ ~! F; a
}
/ T& [$ L4 H6 c6 c0 [</FONT>
+ k4 E/ L) o1 C3 T0 u</P>
+ ]$ V# j9 B8 H4 B5 Y3 n0 N# b' B0 `<P><FONT color=#ff0000>函数名: setfillpattern </FONT>5 v1 i; v" c& s/ o! n0 P
功 能: 选择用户定义的填充模式
! F- a, ?! @& N8 x; w+ ]+ k用 法: void far setfillpattern(char far *upattern, int color);
+ v& J! k# D+ B9 C5 _程序例: </P>
2 V/ Z& _; t7 b7 I0 L) F<P><FONT color=#0000ff>#include <GRAPHICS.H>+ M  ^$ w8 g& b# M; r$ J
#include <STDLIB.H>1 k1 P' I' q, ~+ k  d8 {
#include <STDIO.H>
/ x+ O# _6 j; s) q; v#include <CONIO.H></FONT></P>
1 p+ Q: e: ~, _6 x( l; G/ n) O$ I<P><FONT color=#0000ff>int main(void)
' a9 C6 H0 M! {' p" u! X! T! b{ $ d& @( E/ ?; ]4 c0 l
/* request auto detection */ % r+ W. }/ {0 Q6 k% Q7 L+ r( Z
int gdriver = DETECT, gmode, errorcode;
# ?3 N- K8 Z& s0 Fint maxx, maxy; </FONT></P>) Z- }. c% c" `2 R& w" M, ?
<P><FONT color=#0000ff>/* a user defined fill pattern */
2 i' V; U% o4 S( J: uchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>4 G6 m- E4 e1 d+ A
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 4 v6 C7 [! c6 V  K0 H- {3 E& g
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) }* k5 e, d& O  `) r8 C. g% R<P><FONT color=#0000ff>/* read result of initialization */ : b, `# k$ l% H) m
errorcode = graphresult();
- J$ L3 ^/ Q; Q& R. Uif (errorcode != grOk) /* an error occurred */ * f/ a0 B& w. g3 H/ c9 x
{ % B3 a! _/ k0 \: a  }, `* H  U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # l4 q/ K4 v: G! w! o
printf("Press any key to halt:"); ; G$ F5 r0 u6 a  n- O
getch();
7 w1 x, J1 k% L* m/ nexit(1); /* terminate with an error code */ * E! c2 u" Q; h  T, y" Z
} </FONT></P>
( q8 `: E9 |7 }, v; J# w, X<P><FONT color=#0000ff>maxx = getmaxx();
0 `% e0 r% c6 r* `2 dmaxy = getmaxy(); & k* H; C. V4 b7 d. O% b  b
setcolor(getmaxcolor()); </FONT></P>
% i) e. f6 G+ W2 Y5 @<P><FONT color=#0000ff>/* select a user defined fill pattern */
5 _/ l3 k5 w, C3 m* I9 t5 Lsetfillpattern(pattern, getmaxcolor()); </FONT></P>- c# d( H9 c; v4 L) k' v+ d
<P><FONT color=#0000ff>/* fill the screen with the pattern */
  d' c# S7 D' ]8 z3 Z2 cbar(0, 0, maxx, maxy); </FONT></P>
# C( Y: j& o7 F6 Z<P><FONT color=#0000ff>/* clean up */ ) g+ S$ p! P5 Q0 W5 s; u6 y
getch(); 4 s1 J7 U0 w: x4 O5 v
closegraph(); , p0 n  H& A6 y8 y4 B
return 0;
5 m6 [8 D0 W$ N+ Q* J  _7 f4 o}
: A' O( g& U- Z! R6 g</FONT>4 \- `5 d+ \6 ~$ j8 T  J; E. O
</P>3 p  R  m  \( Y( ^, m6 ]
<P><FONT color=#ff0000>函数名: setfillstyle </FONT>) H  U# ?( P8 \1 }3 r9 T6 Q
功 能: 设置填充模式和颜色 ! U( M8 @) L( O, B8 W' h
用 法: void far setfillstyle(int pattern, int color); # [0 n( O# r6 y/ F) s' \/ i
程序例: </P>  a* ^( K4 T7 Z+ g
<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 ^. Q2 S6 g) Q8 I- w! C#include <STDLIB.H>
  y+ s: ]" W) K" z2 p#include <STRING.H>
+ g5 m' W9 P8 L5 o, l9 t& ~. H9 v#include <STDIO.H>
3 n. D6 {7 s7 W. C#include <CONIO.H></FONT></P>
+ X% G, E  }. A& E<P><FONT color=#0000ff>/* the names of the fill styles supported */ # u3 F/ s2 d* E; r) Q& E
char *fname[] = { "EMPTY_FILL", # j6 B5 H7 `6 |) @+ L
"SOLID_FILL", 0 }& I+ i/ O2 Z
"LINE_FILL", " y  l& f! b  _
"LTSLASH_FILL", % ^2 b( w2 h: f3 R- N7 q- }2 j( D
"SLASH_FILL", " e) h( C/ n7 D( M$ y
"BKSLASH_FILL", 9 K; G# b; X8 v  }. j6 ]# t) Z, x
"LTBKSLASH_FILL", ( Z$ N$ g# d' L( s8 u+ ?
"HATCH_FILL",
, n6 W+ ~9 l3 a  R$ n& X# e& h& \1 s"XHATCH_FILL",
# D- [0 Q: _9 l# e"INTERLEAVE_FILL", 8 S. |7 Y2 d  E
"WIDE_DOT_FILL",
# p5 F8 `  s2 j" X  g"CLOSE_DOT_FILL",
  d  s* j$ b- r" y' G4 H; b* X"USER_FILL" ! M0 @) ^1 [; I& d
}; </FONT></P>( r4 K, B! R% i
<P><FONT color=#0000ff>int main(void)
. N4 Y( O$ M% w{
% B1 h7 @9 x( o; u4 B- V. ]/* request auto detection */
' t& G# e! o+ aint gdriver = DETECT, gmode, errorcode; 7 J' r' z6 M; y+ q$ u6 k, {* {% M
int style, midx, midy;
1 A( _  z1 \( W$ K. V( g* L; Hchar stylestr[40]; </FONT></P>4 p9 }; u2 u0 i: s
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" u. l1 Y" A1 e' \; E, ^# ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 Z- B7 e6 b3 G) l! c  z9 V9 V
<P><FONT color=#0000ff>/* read result of initialization */
- l0 A. X! T* g2 U4 f4 Kerrorcode = graphresult();
3 _- P+ k/ Q7 v8 X9 t4 O) Uif (errorcode != grOk) /* an error occurred */
) F- X! i/ f, Z4 n) c{ # `# }: A0 F8 d: w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / S$ o5 W% A6 d& W" l; n/ n  g
printf("Press any key to halt:");   u: \- ]2 v; `. i$ K
getch();
, H1 _7 j, V5 J- v, T" |- ^% Aexit(1); /* terminate with an error code */
5 \4 p+ a/ c  q9 p} </FONT></P>
; Z, Z. n8 m6 Q0 S' L<P><FONT color=#0000ff>midx = getmaxx() / 2;   U; i, k) Q. f$ z% K7 x, Z0 r
midy = getmaxy() / 2; </FONT></P># z, P- {: ~7 E, Z$ {& q
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
7 e7 R/ Y: p; j' Z7 B4 W3 I{
# w6 Q3 M. [( P/* select the fill style */
( S: L- {4 h6 K+ a* H1 Dsetfillstyle(style, getmaxcolor()); </FONT></P>) w* X5 J# y" b7 `: N4 u
<P><FONT color=#0000ff>/* convert style into a string */
6 y5 Z# q1 s* B# ]; R5 k& H6 o! A. Tstrcpy(stylestr, fname[style]); </FONT></P>
1 M, W. u9 [4 X/ |<P><FONT color=#0000ff>/* fill a bar */
. o8 B6 T% m. E( Z( x2 P( K& J7 a% |bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
* `9 G, Y5 F7 E  c. M* u<P><FONT color=#0000ff>/* output a message */ 1 ~# C! x# T1 K; e) W: Q
outtextxy(midx, midy, stylestr); </FONT></P>0 u9 w8 h; o! U3 X0 }
<P><FONT color=#0000ff>/* wait for a key */ 1 {# G4 G0 R. }0 G
getch();
' z, S- O! ^) F9 S9 L2 Zcleardevice();
( z3 t2 x' N! v) P+ i5 `; o} </FONT></P>, D/ l$ h  j* y3 t: p2 X( Q. ~. Q/ m
<P><FONT color=#0000ff>/* clean up */ ' G; Z! q  y' `$ Z
getch(); 6 d$ j; v6 F" o+ f. Z% p
closegraph();
6 q1 s3 c9 W. M6 Q! E* Mreturn 0;
- d7 e3 ~: Z3 F1 P1 E0 |4 v} </FONT>. s, ]& N* \  q) [

8 ?5 Z+ `; p" s- E1 S& g</P>
6 k9 Q) o! `  N! U<P><FONT color=#ff0000>函数名: setftime </FONT>
5 {7 A1 I) l" X* O* G, {% M功 能: 设置文件日期和时间
2 `" `6 ?: e% K  X2 h2 o用 法: int setftime(int handle, struct ftime *ftimep); 2 `7 `$ E& L2 R/ L  O1 p) w
程序例: </P>9 h4 R" O$ R' T5 t0 @
<P><FONT color=#0000ff>#include <STDIO.H>
& Z1 A6 c* D/ d  y#include <PROCESS.H>
9 C8 a3 d9 R- J# W: y#include <FCNTL.H>
0 ^& u' _- y- p0 M. l  b- R5 e' V" a#include <IO.H></FONT></P>  N( G7 o5 s8 |3 F$ ~  |  H
<P><FONT color=#0000ff>int main(void)
: {9 ^7 w3 |4 }( K; }& z{ $ J1 n; _+ M7 ^
struct ftime filet;
+ y! y& S9 A/ O" s8 v. `& YFILE *fp; </FONT></P>
9 e. f, _* o& r2 I  P# \% G<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) " l$ p1 c% _: Y6 _
{ & l" K, S2 ~3 P+ ~
perror("Error:"); 7 V) d' D( \/ [0 t# v6 k3 s" N
exit(1);
8 ^+ ^. _, {2 ]: e" O& B' h" w} </FONT></P>
5 }/ K% C+ h' c( \. I<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>2 ]# m" C, A& h) k3 T
<P><FONT color=#0000ff>/* load ftime structure with new time and date */
2 C- |6 `& ^6 x8 wfilet.ft_tsec = 1;
* \, [/ w& i5 \: J$ W1 w2 U8 D: jfilet.ft_min = 1;
8 b! [' i! W7 h2 b" S: yfilet.ft_hour = 1;
$ g$ O# Y" o8 e& E. T6 hfilet.ft_day = 1; 8 L+ m' U# s: Y2 S2 B3 X( w
filet.ft_month = 1; # |. z$ V3 K/ ?' D
filet.ft_year = 21; </FONT></P>) [9 l6 A5 Z( b
<P><FONT color=#0000ff>/* show current directory for time and date */ 6 _' l, o5 f8 S+ o% f  ?% [
system("dir TEST.$$$"); </FONT></P>. E4 y: {: F* h
<P><FONT color=#0000ff>/* change the time and date stamp*/
! Z: d! y5 d" @' H8 T  ysetftime(fileno(fp), &amp;filet); </FONT></P>% @/ S: _/ c4 X0 j* j) g/ q
<P><FONT color=#0000ff>/* close and remove the temporary file */ 1 A8 b/ W  V% z- \8 e; S
fclose(fp); </FONT></P>% y) N. ~0 W4 Q4 a9 h7 u# B! R
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>
; Y! m4 t4 Y4 l6 _, n$ L  S6 v<P><FONT color=#0000ff>unlink("TEST.$$$"); & h" y0 W! N5 k1 ]# C
return 0;
. |8 l) c# l) A9 l2 B0 D8 \7 T# o! M+ F} 1 ]1 {0 H4 X! ^
</FONT>
; h7 d) }6 t1 Y6 B</P>( l" g+ K, }- Y/ s( L/ N, V
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
8 t1 T9 }+ _' c  R; x功 能: 改变内部图形缓冲区的大小
# P& s# Y- U5 S用 法: unsigned far setgraphbufsize(unsigned bufsize);
. @5 p, z; N, A程序例: </P>% q7 b7 E" e- l- p
<P><FONT color=#0000ff>#include <GRAPHICS.H>( E2 ?" e" Q! ]
#include <STDLIB.H>
6 d2 x4 `! N' C: }) c* a4 B5 |$ a#include <STDIO.H>* A1 M3 P  A0 H8 {
#include <CONIO.H></FONT></P>  P2 l3 n+ i5 |$ C
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>
( k& L  R6 o. S) b7 b  o<P><FONT color=#0000ff>int main(void)
$ }$ ?6 F( f; q+ y! e. J3 a% C{ ' i. p; }/ p4 R7 W" ^
/* request auto detection */
6 r. \' N, {! X! sint gdriver = DETECT, gmode, errorcode;
! P+ k4 t5 W% P4 q2 `( b! n" }int x, y, oldsize; / P) X0 ]5 v& _
char msg[80]; </FONT></P>% Y" I: K  m0 B+ E( k8 U9 \
<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ % A/ R5 u7 W) Y* J1 }# M
/* before making a call to initgraph. */ 0 [/ d4 ^! N' B( A/ e& b) E- t
oldsize = setgraphbufsize(BUFSIZE); </FONT></P>
' I4 d0 J& ^; k/ U" t<P><FONT color=#0000ff>/* initialize graphics and local variables */ & @, n+ e" [/ m
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 x! Z* s" \' y# \; E
<P><FONT color=#0000ff>/* read result of initialization */ / Q' q& F5 Y# g, }) y2 ^  n# d
errorcode = graphresult(); $ D) q+ N5 O( O7 Q( T
if (errorcode != grOk) /* an error occurred */ . d$ |8 {( @+ Y4 l$ J
{
" ~1 L/ v; K9 q, z6 r, O2 m9 _printf("Graphics error: %s\n", grapherrormsg(errorcode));
" f- _' ~6 U$ m  m/ B9 ~: mprintf("Press any key to halt:");
) V* Y2 E3 _. y# xgetch(); 4 }: }9 @/ j+ g- ~& w
exit(1); /* terminate with an error code */
1 B  ~# z2 f: g1 x2 S} </FONT></P>5 f5 v6 G0 t! U* c5 B; F  [
<P><FONT color=#0000ff>x = getmaxx() / 2;
7 }; }6 G7 K0 ?& M7 zy = getmaxy() / 2; </FONT></P>2 c9 P( ]% J$ ]2 p
<P><FONT color=#0000ff>/* output some messages */ 0 A7 P) o5 r8 E7 q& l
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
, c' x) y& ]6 X5 V- S- ssettextjustify(CENTER_TEXT, CENTER_TEXT); & a& z& `) ^- w/ n) ?
outtextxy(x, y, msg); - z( n, v; v/ J; |5 B& a1 [8 ]3 v
sprintf(msg, "Old graphics buffer size: %d", oldsize); ) i3 D0 L0 n/ `# H/ ]; t/ K
outtextxy(x, y+textheight("W"), msg); </FONT></P>! R6 E2 G% \9 [
<P><FONT color=#0000ff>/* clean up */ ( U) K9 L2 h" M) J. V8 X% t8 p# ~' `
getch();
& L; x7 N* Z' ]2 a5 d, @. e0 ]* s3 gclosegraph();   f8 n7 V# D% M& L% E& o( i9 @5 n
return 0;
' c6 x( a; F' `0 U} . k, A" K% r: s' G: Q  e  F+ y

2 \+ ?/ ?. n, U* W7 q7 Y
# K: b, t* X. D9 X</FONT></P>% T* h  i4 Y# q" q9 o7 R( ?/ A$ D
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
8 O) e, i2 X4 D2 |功 能: 将系统设置成图形模式且清屏
' H# i9 U  ?0 k6 P7 y  o0 ?用 法: void far setgraphmode(int mode); 6 q* i/ j' R3 d6 H8 u. K0 U/ z0 ^
程序例:
8 V$ q0 f6 }1 M% U/ O; H1 L! _
+ z3 K- k! S3 n- v9 P4 b4 p3 ?+ ^<FONT color=#0000ff>#include <STDLIB.H>2 Z# ^2 x7 E0 z
#include <STDIO.H>
8 J& m& {- O( B( e/ s7 P( q+ I#include <GRAPHICS.H>#include <CONIO.H></FONT></P>9 X6 P6 k" ]% T, K4 p; d
<P><FONT color=#0000ff>int main(void) ) |) ~# t  w( F- O7 x# J. S
{
) h) @: b8 s$ V. B! I% Q6 r! [" d/* request auto detection */ 7 f- C) J0 H) w9 ]9 O* H7 `' A8 s
int gdriver = DETECT, gmode, errorcode; 8 ~* W3 P& y$ n/ |3 ?+ E+ V
int x, y; </FONT></P>
( e/ |" R" B* o3 F; l! o% V- l# S<P><FONT color=#0000ff>/* initialize graphics and local variables */   w& _% u4 {7 h) m. G2 r0 l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, v  |% L9 \: C; R3 h
<P><FONT color=#0000ff>/* read result of initialization */ % d- s7 s) c& i' K% s* E- N: J" j
errorcode = graphresult(); * Q/ l* P9 I6 o* j
if (errorcode != grOk) /* an error occurred */ 7 U( {  m: Z" r
{
2 l! ?/ U0 U- p. lprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! ]6 d, C9 h3 u+ t1 E* a3 Cprintf("Press any key to halt:");
9 I- O1 C) C& j* x, Fgetch(); 7 c& f% I$ f3 q% x4 X$ l% C
exit(1); /* terminate with an error code */ % F9 y6 E7 {5 A. F
} </FONT></P>. \  ?0 A2 {' h* R) X. W! x" t
<P><FONT color=#0000ff>x = getmaxx() / 2; / k! J) t5 l6 V" r3 m4 k( }
y = getmaxy() / 2; </FONT></P>
" F4 A7 M9 t6 ~" K<P><FONT color=#0000ff>/* output a message */ 5 y6 t7 [$ P6 q1 S
settextjustify(CENTER_TEXT, CENTER_TEXT); $ \- Z' r" m  E
outtextxy(x, y, "Press any key to exit graphics:");
& T6 f% I4 }. @5 p4 c1 h* ?getch(); </FONT></P>
7 |7 H2 o) d; ]% \<P><FONT color=#0000ff>/* restore system to text mode */ - m$ n  R! k( C; I3 R7 u
restorecrtmode();
' M) R- p2 e" A6 Z# p/ w6 a" `! uprintf("We're now in text mode.\n"); 0 d  {$ h1 O% Y6 n7 }% F; j2 I( \" }
printf("Press any key to return to graphics mode:"); , Y8 U9 g( h) p* K
getch(); </FONT></P>
0 C8 ]% I- z- P& c( z5 U! |<P><FONT color=#0000ff>/* return to graphics mode */
1 f/ ^4 t3 s& Ksetgraphmode(getgraphmode()); </FONT></P>
4 t" h* O; j+ \: [, y; \<P><FONT color=#0000ff>/* output a message */ ) n; l5 \/ G6 s5 ?
settextjustify(CENTER_TEXT, CENTER_TEXT);
$ p  D; t5 O7 ~. b0 \& youttextxy(x, y, "We're back in graphics mode.");
, G6 C( F! H1 m! A, T0 X; O  nouttextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>
+ P- w- e9 E6 y1 E. H+ y<P><FONT color=#0000ff>/* clean up */
4 j. ]3 b% P( G) M) g% I. M/ rgetch(); 4 k5 B: c# k, E
closegraph();
( }' p8 o* |6 ]8 l* J: o2 }" Wreturn 0; 6 M+ y# f' W  o- f1 k! L
} 8 s5 f8 R  a' W6 i/ h, Q( H

: m# v* R( c, o  i% \$ v8 z3 N  Z6 F. H7 ^4 H
</FONT><FONT color=#ff0000></FONT></P>
/ Z% e4 f; N/ b( x* c' J5 h<P><FONT color=#ff0000>函数名: setjmp </FONT>& C! d# s6 ^1 N$ F7 C, k: H9 f/ j
功 能: 非局部转移
) w7 }& G- Q- T) u- [2 w. E用 法: int setjmp(jmp_buf env); 7 G) e5 ]8 d2 P$ d) z' E
程序例: </P>5 }5 `' W# y" @; A. a; d
<P><FONT color=#0000ff>#include <STDIO.H>
7 X& q# o2 |- ~' f) b9 p#include <PROCESS.H>7 i9 z3 @1 b& v9 A7 u
#include <SETJMP.H></FONT></P>
( S8 [, x" {; I/ `4 [* E<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
# y3 F' y% C2 X  a" S/ W<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>! x* Y9 |8 v$ Z
<P><FONT color=#0000ff>int main(void)
& O% _. @$ ^# Z! O8 r& W{
9 B6 ^- L& P3 @+ x3 z" s7 k6 q5 Oint value; </FONT></P>( E( W/ z6 T: ]( k  c/ I+ z7 P/ \
<P><FONT color=#0000ff>value = setjmp(jumper); 9 R" W+ g" Q# Q/ O* J
if (value != 0)
) l0 X1 u# `8 E7 i, t+ S/ d4 a{ 8 ~3 |- l: V5 f9 k7 U8 \, d4 f& _4 L
printf("Longjmp with value %d\n", value);
- P$ T2 x" b2 |exit(value);
* A; O# V2 N# K, @$ M$ B1 S5 B# [} 5 \: q/ |/ c" g0 x, M8 K
printf("About to call subroutine ... \n");
! @7 X; Y, p2 @& x* T: j4 ~( P" Ksubroutine(); ) C7 D5 `' I) ~( H1 ~
return 0; $ X3 E2 t/ \* _: ^3 F* |0 V
} </FONT></P>
4 i# _8 ?  c/ X<P><FONT color=#0000ff>void subroutine(void) " q+ a8 t2 [! }& k. Y: [
{ 8 h5 H- F# ]* _
longjmp(jumper,1);
$ W& Q: F/ Q' S  S3 b* v# K% v}
# Z+ J3 H3 |  C" o9 s</FONT>( ?% o" ?' l2 _3 ]
</P>; V3 {9 C/ L4 f3 R' _- m
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
. O$ o' X% }4 r) m9 J+ `$ Q. H( w功 能: 设置当前画线宽度和类型
; m9 j; a$ w5 T" [: I用 法: void far setlinestyle(int linestype, unsigned upattern);
7 Q$ Q: Z+ t% m- E程序例: </P>! Y' ]5 _, a0 x8 Z" c& ~2 O1 f6 _
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 X. c. u" q! v9 N% t$ u  S
#include <STDLIB.H>' ~" o. K  Q1 y6 L7 c9 A1 j1 u
#include <STRING.H>1 ^* R. F( J* u
#include <STDIO.H>
8 x  `+ T/ T* ?" t( k9 w#include <CONIO.H></FONT></P>
- X4 O; u7 F" `" x) K<P><FONT color=#0000ff>/* the names of the line styles supported */ . t* a1 b2 j. u7 }% e9 N
char *lname[] = { ; {+ T/ ~3 `/ \* U
"SOLID_LINE",
0 I' J1 C  A8 t% Z. o4 `"DOTTED_LINE",
) U% d0 t5 q" z5 H4 ?! e& \"CENTER_LINE", $ e! b" Y/ H( `' Q5 u% r
"DASHED_LINE", , v" R1 B: V( s) e+ S
"USERBIT_LINE" $ e* N% U7 S  G- I
}; </FONT></P>' q; t; r9 c# {8 m/ z
<P><FONT color=#0000ff>int main(void) ! |$ p- W# y9 C( Z
{
. I; b2 h7 f) P& }! h% W  Z/* request auto detection */ ) o* d3 H: n' `! _
int gdriver = DETECT, gmode, errorcode; </FONT></P>
$ e8 o% V3 W9 G<P><FONT color=#0000ff>int style, midx, midy, userpat; ! U* e5 W+ f* w9 L9 p: X/ j* E
char stylestr[40]; </FONT></P>$ Q+ X0 `9 K# O) I0 d
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 O7 {' W( n' j
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 U5 P2 J4 H( g. Q7 |! q<P><FONT color=#0000ff>/* read result of initialization */ ; Y9 W& E" d* J, S/ ]
errorcode = graphresult();
9 u# g# j8 N, d, v' t' @8 K! c$ w9 Wif (errorcode != grOk) /* an error occurred */ , H1 d7 t% k* F2 C+ \0 F
{
: o  j( n$ X$ Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / G3 ]) Z, ^5 h$ f) O5 @
printf("Press any key to halt:");
6 {  ]5 [6 k, X8 D9 Cgetch(); 2 T* l7 N& P3 j) J- l8 X4 m
exit(1); /* terminate with an error code */ - a9 Y, h& D' O
} </FONT></P>+ Z, Z/ m& y5 l: l7 s, \: H6 w
<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ b! F6 _& }: }" amidy = getmaxy() / 2; </FONT></P>
+ @6 z/ c6 U$ \% `& N; d<P><FONT color=#0000ff>/* a user defined line pattern */ ) Q: R3 k2 ?  c7 q8 F
/* binary: "0000000000000001" */ 9 i0 }& y6 l- K( D; j1 u4 t
userpat = 1; </FONT></P>- d7 ~8 h+ _' d: @7 \
<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
$ E5 X* j/ u6 |{
  }6 ~( `$ u, F9 B. o- ^/* select the line style */
6 u! D6 f' O( rsetlinestyle(style, userpat, 1); </FONT></P>0 s" Y2 e: \* |1 Q$ h! y, l6 x/ x
<P><FONT color=#0000ff>/* convert style into a string */ * c& C5 I) }) i% E9 V% z
strcpy(stylestr, lname[style]); </FONT></P>
4 T. g) _+ F( v% u1 ^<P><FONT color=#0000ff>/* draw a line */
* j" h' p: r4 `& N* U# [& r/ Kline(0, 0, midx-10, midy); </FONT></P>
5 n6 ?1 j  q$ Q/ w& }( u5 F<P><FONT color=#0000ff>/* draw a rectangle */
3 n! W4 m3 [3 L$ F0 y6 j0 Wrectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
) H. Z0 l7 p& W  |7 l0 U<P><FONT color=#0000ff>/* output a message */ - z; L& T) Y9 s) O. M
outtextxy(midx, midy, stylestr); </FONT></P>( c; V9 c3 }0 w. z# h5 O3 q
<P><FONT color=#0000ff>/* wait for a key */ / I) ]" M. U9 G
getch();
+ Y4 I, V# |6 tcleardevice();
" c$ Y% E9 [) N4 j# u! W, N} </FONT></P># Z. l: {: M% m  R8 @
<P><FONT color=#0000ff>/* clean up */ 5 H6 P# j" G! H* @6 c
closegraph();   I: ~, {" f, \. k
return 0;
9 u. L( x$ e7 a: J$ e  \7 f} </FONT>0 x" U; h+ g, c0 X  A9 a& Z

" U' I0 `' ~7 F- f$ _" Q* d/ A8 n$ H- u
</P>: \' Z+ d# U# x
<P><FONT color=#ff0000>函数名: setmem </FONT># L5 u- ~5 v+ T9 ?$ S( T3 v4 y
功 能: 存值到存储区
* d9 }( _: `: h& r* M* {% @用 法: void setmem(void *addr, int len, char value); 2 C+ S2 ]+ w3 b* C, A0 V! Y+ ?
程序例: </P>; z1 w( ^2 l' c8 x+ F3 a# p1 ^: p- E
<P><FONT color=#0000ff>#include <STDIO.H>! z. }2 P$ M! I6 o' U
#include <ALLOC.H>
; i$ f5 w* Q: {# e; M" q#include <MEM.H></FONT></P>
$ y7 D) Y; F: G# M1 X<P><FONT color=#0000ff>int main(void) ) q! D& w6 L6 y9 k6 P. {  w0 A2 p
{ ' [4 r7 X$ f0 j8 K
char *dest; </FONT></P>
4 u3 b' D1 Z$ S/ x4 C) h5 V<P><FONT color=#0000ff>dest = calloc(21, sizeof(char)); , i6 p, O9 N, D0 f( o
setmem(dest, 20, 'c'); 6 d5 C& [! v! `3 y1 t2 S- ]8 c
printf("%s\n", dest); </FONT></P>/ ^# x/ u' O+ j4 W! R
<P><FONT color=#0000ff>return 0; / \# v2 ]4 h( R9 L+ h
} </FONT>
% D3 m9 d# X* ~9 @& L9 y) C( H: Y' l" q! p

" l- I, ?4 O# e# [& \8 t' @</P>
+ t, ^: M5 Z3 @1 X* I7 S" K, d3 O<P><FONT color=#ff0000>函数名: setmode </FONT>
0 y% P: D  }* E# H功 能: 设置打开文件方式
: h  s9 M: @" u" ~用 法: int setmode(int handle, unsigned mode); ) {/ ?. F* N' Z: K* B
程序例: </P>! c& d  s; n& f  h+ ^9 ]0 J
<P><FONT color=#0000ff>#include <STDIO.H>3 P4 R0 `% B- J" I
#include <FCNTL.H>( I/ T& i0 f) z* h" F
#include <IO.H></FONT></P>; `9 J& J) [7 `$ [& h* _! N! B
<P><FONT color=#0000ff>int main(void)
1 m' F+ \5 O, N) {3 \3 `) m0 m; `{ , g: O1 G8 U* a7 y
int result; </FONT></P>
1 }3 S% E& ~% f( A. U' h/ @<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); , T+ O. B  H' n$ x( Y) B
if (result == -1)
4 ]& A  D* F- L- G! D9 @perror("Mode not available\n"); $ l( ~- K6 Y2 Z$ O/ i% b5 X
else 1 K) M% y; G4 W' D1 U9 L. W& u& @* {% p
printf("Mode successfully switched\n");
( }5 F' n- {8 x8 k0 dreturn 0; : P6 l; K6 ~3 A. G7 P
} ) N. ~+ S4 R- ?. M& G$ b! Q
4 U* B3 B# W6 T$ ]
</FONT>! R' Y/ q8 g$ t/ R2 t& Z# g3 u
</P>
: s: A* G) j2 K/ ]; R7 `<P><FONT color=#ff0000>函数名: setpalette </FONT>
) G+ Y/ }' z' E7 w功 能: 改变调色板的颜色 6 d4 F# G/ H5 t  o5 j
用 法: void far setpalette(int index, int actural_color); ) I" E9 B1 F! P) H* o
程序例: </P>
- N' q2 ?" q) b% E' k! X: m<P><FONT color=#0000ff>#include <GRAPHICS.H>) }4 ^% o& P+ t: u8 \
#include <STDLIB.H>/ l  V1 @: |9 b/ x3 A& |3 p; h
#include <STDIO.H>
: E; B  o- R* ~) P: {( t9 a) l#include <CONIO.H></FONT></P>3 `5 Z2 ?! K' u0 e: h
<P><FONT color=#0000ff>int main(void) ) z( F. \/ G& F. a
{ 4 J) @9 d, D2 A2 f5 ~. R* B
/* request auto detection */ 4 t  o  U' {0 z, |4 K7 J" ]) l3 M
int gdriver = DETECT, gmode, errorcode; ( H  b( w2 L/ h- @
int color, maxcolor, ht; % L4 e. @& s$ K
int y = 10; 2 f8 W' M+ h% X5 g' o
char msg[80]; </FONT></P>
2 K$ ^+ t: o, l# b<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 n' F% I5 X2 V! z- z& xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 ^8 s4 f$ _. v" ?8 R* o, @
<P><FONT color=#0000ff>/* read result of initialization */
9 g# G$ k: N$ g- cerrorcode = graphresult(); : b& H8 Y' M4 U: t& V8 l
if (errorcode != grOk) /* an error occurred */ 4 ?4 Q' _; B' a/ \  e" T$ P* B
{ % y3 y/ ?& u9 L& S1 O: P2 O
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % z) B' D% w5 U
printf("Press any key to halt:"); ! ]5 o+ ?' ^4 |: j
getch();
6 N" M0 o2 i1 Pexit(1); /* terminate with an error code */
. |: p( Y2 k0 |  h} </FONT></P>2 L" z& F& c. V0 u' ?/ k
<P><FONT color=#0000ff>maxcolor = getmaxcolor(); ) _5 v% z8 p) j' r7 D+ V
ht = 2 * textheight("W"); </FONT></P>4 ~! O  ?. M4 u- k. h
<P><FONT color=#0000ff>/* display the default colors */ * ~$ C3 y; M- \
for (color=1; color&lt;=maxcolor; color++) 9 p8 X# [" h. u0 `2 z% ~
{
2 |! {/ K% K6 P5 ?* e9 Zsetcolor(color);
. I8 q. }- Q$ d6 {# c# r+ c  nsprintf(msg, "Color: %d", color); & Q. y- d+ a/ A
outtextxy(1, y, msg);
0 N& x2 d# x' ?9 [6 k5 T% h! Ty += ht;
) \) q. ^" G6 [8 K) N, Q} </FONT></P>5 M6 Q1 b, y4 V5 h% y7 M
<P><FONT color=#0000ff>/* wait for a key */ & v6 n' F7 L: i5 @# q
getch(); </FONT></P>
5 i7 f! [3 R( g, N4 ^7 p/ w<P><FONT color=#0000ff>/* black out the colors one by one */
1 g# z/ n4 V' ?; ?( c( V1 i  @for (color=1; color&lt;=maxcolor; color++)
+ l% R6 u5 H+ H% r( W$ N{
7 u. k8 ~! I4 Z! wsetpalette(color, BLACK);
0 O9 x& v8 |: D% ~2 d: m3 B' qgetch();
- X) ^! _$ j! N: {6 i9 i} </FONT></P>
) Y2 n- \# q) }9 u" e9 R1 G, v<P><FONT color=#0000ff>/* clean up */
+ C+ N0 e/ D0 ?% V2 cclosegraph();
5 e6 _* h" o9 i0 Dreturn 0; ) z. ~& C+ K2 L2 }! ^
}
4 d( R3 ~. o. e</FONT>8 W% Z+ y5 M2 j
</P>
2 i& j) t. t& G( C<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>) p; c. X1 U; R7 G) B
功 能: 定义IBM8514图形卡的颜色
5 ]. J' s# l& }% D用 法: void far setrgbpalette(int colornum, int red, int green, int blue); 1 _2 i( m4 v( x: ~# a8 I6 R+ W8 p
程序例: </P>
* R4 b; w& v, W* J/ y1 @) V+ H0 F3 r<P><FONT color=#0000ff>#include <GRAPHICS.H>: w7 q$ W9 ~' G2 n2 b$ w
#include <STDLIB.H>
2 M( }0 U9 \5 ?/ I9 ]9 B! H9 j#include <STDIO.H>/ @( p1 L* }: S3 r& c$ `8 L7 V. P
#include <CONIO.H></FONT></P>
7 j7 M4 b$ i( x4 k<P><FONT color=#0000ff>int main(void)
$ H7 r* p. j2 p5 K{
$ ]* j, X$ ~! o/ B. x5 S' E5 |' H/* select a driver and mode that supports the use */ 0 I; g( _3 N) D  g; H) S
/* of the setrgbpalette function. */ , s! {6 ^6 ~8 ^* e7 L, M7 e: e7 Q
int gdriver = VGA, gmode = VGAHI, errorcode;
4 k2 m: W' X. [! C/ Astruct palettetype pal; ' s6 G* b  G$ r# H
int i, ht, y, xmax; </FONT></P>8 e6 x% T+ _% {% L
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 x0 y* Z+ U8 C$ U
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 E, U; C# [5 o3 k- a/ T<P><FONT color=#0000ff>/* read result of initialization */ , a' W. w  X6 a0 R
errorcode = graphresult();
5 Y% t+ G+ Z$ K9 f, F! N! xif (errorcode != grOk) /* an error occurred */
; u3 x6 b4 o$ h$ ^1 u1 i) T( a{ . e( Z: ]( y3 l9 J! {9 [6 B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 I" y( p6 X) u8 R$ xprintf("Press any key to halt:");
+ a8 ?; F  I8 j$ Tgetch(); 6 d3 U- m& D# G+ p* b1 b
exit(1); /* terminate with an error code */
4 V( V: d/ J6 H1 n: p+ h; K( ?. s$ k} </FONT></P>
5 o; Y6 i- v" X2 e7 X<P><FONT color=#0000ff>/* grab a copy of the palette */ 1 z1 _! y6 E- h. F% j- y
getpalette(&amp;pal); </FONT></P>/ h1 Q( l& |3 @& J! e- f9 ]7 c4 e  t
<P><FONT color=#0000ff>/* create gray scale */
& f/ S1 m) U" e: T/ T7 p0 G3 cfor (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
2 n3 d0 |$ d' J8 g( Q<P><FONT color=#0000ff>/* display the gray scale */ 4 m: V# F. Z  ~/ v. D2 l
ht = getmaxy() / 16; + r$ f4 A8 c7 j
xmax = getmaxx();
& x' _( D" F) E" c3 A$ l6 Zy = 0;
: J+ M0 A7 Y+ @for (i=0; i<PAL.SIZE; <br i++)> {
4 ]0 v3 h( G2 ysetfillstyle(SOLID_FILL, i); - n3 ?8 X- Q9 O1 c% `2 p
bar(0, y, xmax, y+ht);
( q7 ^) i' I9 G2 i0 }y += ht;
7 C7 t( }- r5 u1 a/ W} </FONT></P>. ?$ z7 F1 y* \9 t
<P><FONT color=#0000ff>/* clean up */ 8 w$ b" R6 I; I5 f& J) A
getch();
7 ^) L! T; k; n5 a5 C* S" }closegraph();
- B5 _7 ?8 a# preturn 0;
- e$ t) M& d9 K6 J} 8 P1 k6 l2 G0 t7 t! v1 l- V
</FONT>! F; F' [2 w/ M& q+ ]/ |
3 I8 r! V  n4 w" d/ ^$ C6 q0 m
</P>2 }$ F$ X+ I. w, t
<P><FONT color=#ff0000>函数名: settextjustify </FONT>2 L* _/ a7 s# j# R8 H& c
功 能: 为图形函数设置文本的对齐方式 , M& t- a. X% R; K7 W; e' s
用 法: void far settextjustify(int horiz, int vert);
7 {1 v! r4 _: {/ ^2 G) X$ ^* o程序例: </P>" r* i, D3 C; L" f$ G+ D
<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 c1 x( a0 K: C5 N2 R1 ~#include <STDLIB.H>  _8 F. c8 e! e8 E0 Q0 u
#include <STDIO.H>
% ]5 B% T) o- T. O! p#include <CONIO.H></FONT></P>$ k% x) ]2 h4 ]( @. d& s
<P><FONT color=#0000ff>/* function prototype */
, G2 G: B( Z; M: r9 r8 M5 h+ b0 l$ wvoid xat(int x, int y); </FONT></P>
, p4 O; e" m! V1 y- p/ h7 T# R<P><FONT color=#0000ff>/* horizontal text justification settings */   c" T0 V7 y4 I, |
char *hjust[] = { "LEFT_TEXT",
, o8 B( ~; S/ Z' Z* X0 ?"CENTER_TEXT", 2 |4 W3 `6 @# x; F) ~5 g
"RIGHT_TEXT" & i9 ]2 \: m( e3 L0 t9 ~; J$ a
}; </FONT></P>& P& p4 o4 h- t: e! k% R
<P><FONT color=#0000ff>/* vertical text justification settings */   N6 P% j5 [; H$ b8 [' q& l& [
char *vjust[] = { "LEFT_TEXT",
4 v) E2 w7 E! d; Y/ _2 Q"CENTER_TEXT",
8 r7 A- S, n3 p" ^9 Q1 C' U# m"RIGHT_TEXT" : {" x( E  u+ g( I( u1 n
}; </FONT></P>
4 J! v) G" b- B( Y8 O4 ~" Y<P><FONT color=#0000ff>int main(void) . [) y0 ^8 S; x1 v- K; a% m; R
{ 0 C3 d; g! y6 D+ k5 c
/* request auto detection */ + V3 J" o; N7 {- G
int gdriver = DETECT, gmode, errorcode;
" y( R/ `% ]! ]6 S+ e& e# H( Qint midx, midy, hj, vj;
" A0 y' x% N; E; h  vchar msg[80]; </FONT></P>
: V" X8 t# s% [& G<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 _6 k2 t. e2 f" s8 _1 w
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 m: C& x# e7 \4 V- Y3 t$ _7 \
<P><FONT color=#0000ff>/* read result of initialization */ 6 T& {. e5 B/ x# u
errorcode = graphresult(); " q$ X5 t  f3 e( h5 }; h& X
if (errorcode != grOk) /* an error occurred */
/ S, e2 b" ?- n# z, c! e{
# T  l% `% h$ \* @printf("Graphics error: %s\n", grapherrormsg(errorcode));
) ^+ z( u3 D% L# {2 Jprintf("Press any key to halt:"); 6 q( j. B0 j( [
getch(); 4 l3 b% B* ]/ d& `# j. S
exit(1); /* terminate with an error code */
8 s9 v5 C; z. B5 |! t2 O' y) v" F& t; X} </FONT></P>
8 M9 d; y: u* v9 X3 O2 g. H! x<P><FONT color=#0000ff>midx = getmaxx() / 2;
, @( ~" ^6 v2 L# T4 u' T$ Fmidy = getmaxy() / 2; </FONT></P>
5 Y' ~, k/ k  d& G1 I* {9 ~<P><FONT color=#0000ff>/* loop through text justifications */
0 }: A; I; k1 W, f. Ofor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) 8 W$ v( @% Q: ]% @
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++) ( h9 G% o8 u2 ?* a% I: ~
{ ! _9 F$ l3 f3 J) v. Y
cleardevice();
: V# Q0 I% Q. @4 S6 Z  E7 R/* set the text justification */ & b; K6 Z( o) y! F
settextjustify(hj, vj); </FONT></P>
0 d7 P4 |1 n1 M* D<P><FONT color=#0000ff>/* create a message string */
/ F' j* k  i4 I+ V  O% \7 Esprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
0 Y0 K# h0 M  K8 {; u0 Y- E<P><FONT color=#0000ff>/* create cross hairs on the screen */
. H: A" f; Y0 L0 Lxat(midx, midy); </FONT></P>
! }- i0 y4 a! l1 r- M" C* x2 S: b4 f<P><FONT color=#0000ff>/* output the message */
0 \9 e4 @& C: W2 a' F# @3 J, _, ?, Kouttextxy(midx, midy, msg); * Q1 d! ^/ D: G( |$ a  E+ F# D
getch();
( s" j, n1 [2 u" u} </FONT></P>
# r% h  }# Y! b0 ^  ^<P><FONT color=#0000ff>/* clean up */
% u$ k; c5 i/ c% W$ U+ qclosegraph(); ) h$ I$ w" C0 U" g. F( `$ ]( {
return 0; ( u# }1 d& X& @* ?
} </FONT></P>' W% n8 h' Y5 Z
<P><FONT color=#0000ff>/* draw an "x" at (x, y) */ 7 M2 [( f+ t" |! B9 o0 g6 k
void xat(int x, int y)   a/ W' `) K4 d# d4 j. H4 F
{   F1 D7 B2 }1 {/ b7 M
line(x-4, y, x+4, y); , F+ `/ S* N$ |/ k6 ]
line(x, y-4, x, y+4); - \# b. g  `- n
} </FONT>
) ^  j8 }* d6 J9 o
5 u8 M4 l& f7 Q4 S& _</P>  B; o: l' Z7 U  N2 t
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
# ]$ N& w9 j) k' z- y* E, ]. Y功 能: 为图形输出设置当前的文本属性 * [- q4 a8 w& z2 D+ \! ]
用 法: void far settextstyle (int font, int direction, char size); 9 e, z, T# A! s7 g7 I
程序例: </P>) g' R+ T8 H; ^5 [4 n' \3 Z5 s
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! p6 V- b$ b# d8 ?5 `#include <STDLIB.H>
8 x  h" }6 K* e7 Y#include <STDIO.H># d- u" F, V0 c) G9 Y0 F3 J( i
#include <CONIO.H></FONT></P>$ N# O* [2 |% u0 ]" J$ E, b2 P3 J
<P><FONT color=#0000ff>/* the names of the text styles supported */ - g) b6 T) M* j/ o% j  G+ b
char *fname[] = { "DEFAULT font", - }: Q" ^* J- `% M' |- U9 h
"TRIPLEX font", % _, F% g( b) A1 I
"SMALL font", 3 j* G8 A' T( U) v
"SANS SERIF font",
" @; r7 L' A8 n$ c"GOTHIC font" # X) V+ g/ g( A% n( J% F
}; </FONT></P>
' V% I! K9 H  q; D3 B( z<P><FONT color=#0000ff>int main(void)
: O; s1 P4 H# e, p, e{ ( \/ ]" v* V, C+ p; m
/* request auto detection */
* Z3 b6 W5 u5 T4 x# C3 z% X6 N9 rint gdriver = DETECT, gmode, errorcode; * M" c  q' X  s, v* C- _
int style, midx, midy; # }! A6 e2 s2 M+ y4 [  L
int size = 1; </FONT></P>6 K# Q& ]2 t2 \+ x5 t
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) A% a. F: l0 ]0 }% O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 S. c& B! W8 i5 q. H% r& `<P><FONT color=#0000ff>/* read result of initialization */
6 ^5 ?9 y9 o# ]errorcode = graphresult();   F$ @. B+ E9 G( J6 B
if (errorcode != grOk) /* an error occurred */
3 t+ w% G7 H5 ~2 c{
5 Z+ Q4 X( v- ]0 t+ Jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 8 i& P  ~/ ~+ ^: y
printf("Press any key to halt:"); $ F$ j+ }2 L3 S9 I9 [, X0 A
getch(); 0 I; s9 J1 o: {' r1 m: s+ `* n1 g
exit(1); /* terminate with an error code */ 1 i. P' n0 K$ L  T
} </FONT></P>
, k2 P  i3 d- G' O<P><FONT color=#0000ff>midx = getmaxx() / 2;
: x7 S8 ^# q- X' O" `midy = getmaxy() / 2; </FONT></P>! D( R$ v3 @' @% ^
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
* R- \: a' k: ^  K5 e  G# D2 d; L<P><FONT color=#0000ff>/* loop through the available text styles */ : X9 k; n( ]6 S4 t7 d
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) * S- q) i% O0 @+ i+ M4 l
{
7 `5 c7 j9 y9 i3 Lcleardevice();
5 U0 w: q9 D, }5 h( D* @if (style == TRIPLEX_FONT) , A0 n: M7 C/ p! k* `! A3 P
size = 4; </FONT></P>( {' L  l# [) ^$ J: E5 D
<P><FONT color=#0000ff>/* select the text style */ - U: n, @* S! r4 R* K: H8 ]
settextstyle(style, HORIZ_DIR, size); </FONT></P>& W# K/ r) `4 S9 s  ~) E. @
<P><FONT color=#0000ff>/* output a message */
- s  G0 `* o. v6 Q7 t9 P4 i. N2 A& ?outtextxy(midx, midy, fname[style]);
! _; U; c/ M( w# Ygetch(); + s$ o% u$ @6 ~6 {5 D
} </FONT></P>
( `, z5 K9 }1 Q  Y" l/ g<P><FONT color=#0000ff>/* clean up */
  e. M* l) N4 ~" L  r* Kclosegraph();
- D0 u$ y3 U: g  e" q) I# q/ \return 0;
: m9 v% ]; i+ B0 D' O} 5 W9 Z; ~# z' s/ ?
</FONT>
- I( [' `3 ?& A. Y3 k/ r! L</P>
; P. U2 ~  j* Q; s  I<P><FONT color=#ff0000>函数名: settextstyle </FONT>
; h* C5 D( D; O: N  Q: [功 能: 为图形输出设置当前的文本属性 ' g+ P4 T, n8 W" r
用 法: void far settextstyle (int font, int direction, char size); 3 j* `5 I# o& a( H
程序例: </P>6 j# O9 L  Q! W$ ?4 H$ B( s
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; }. u. e% ?% ~6 S; t#include <STDLIB.H>0 Z' c# c, @! z' E6 _. l
#include <STDIO.H>0 x. D! x6 M$ B, v! e
#include <CONIO.H></FONT></P>" q& R. g  [  ^8 t& C
<P><FONT color=#0000ff>/* the names of the text styles supported */
) i/ q, ~; t9 z+ B% f0 Jchar *fname[] = { "DEFAULT font", 0 H  l9 G" ^" u1 a; ~$ a- w
"TRIPLEX font", : B0 f  `! }+ e& Q5 e
"SMALL font", ( j8 e& z  G* M' w  }3 n
"SANS SERIF font", ( k6 y  G  {* ^$ k- j3 T
"GOTHIC font"
9 k# R5 v0 V4 D}; </FONT></P>
% Q  X+ [, s) M: n" S, S( Y' F<P><FONT color=#0000ff>int main(void) 6 T( e1 F, u% w" S- {# G
{ 8 _# x7 j8 ?" u7 X' O: y0 l
/* request auto detection */
) ~( c: t, i1 q2 l3 oint gdriver = DETECT, gmode, errorcode;
2 |* o2 F# c% h1 s: u/ yint style, midx, midy;
9 M# x3 w0 o4 y& D  I' K+ e* E6 Aint size = 1; </FONT></P>
6 k% y$ w' Y4 o& }' Y" B6 |<P><FONT color=#0000ff>/* initialize graphics and local variables */
& s7 m% k! c! e: ]$ k/ [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 l5 Z: r2 A1 L
<P><FONT color=#0000ff>/* read result of initialization */ : ?: J2 b9 ^2 ?+ b
errorcode = graphresult(); & }' B! c4 m) o' b
if (errorcode != grOk) /* an error occurred */
/ j  T1 X, n" F; x) y+ N{
" D9 f* j' f* r7 y0 h: jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / g9 H/ b' }* l
printf("Press any key to halt:");
" x0 L5 `! V, F8 sgetch(); 2 `8 m4 {- u2 @( g' s( J9 G: J
exit(1); /* terminate with an error code */ / q: f, P! K. D+ P1 d- D4 T
} </FONT></P>
* V0 \6 J. ], b<P><FONT color=#0000ff>midx = getmaxx() / 2;
! s5 t0 q* H+ w% J4 qmidy = getmaxy() / 2; </FONT></P>9 L& I3 i# {4 {% l
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
% o7 i; B0 {& c' M+ f' C. n0 @: g<P><FONT color=#0000ff>/* loop through the available text styles */ 8 B. f7 p2 X: O* U3 \
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
& a+ N: V- Y# u{ ! R. y) o' g0 [, Y3 i( @2 a2 F, B
cleardevice();
5 a' Y; Q, o. D2 wif (style == TRIPLEX_FONT) 2 h% X7 n) i, n, ~1 o: r
size = 4; </FONT></P>
. B  O0 e6 J9 D9 {- X0 c<P><FONT color=#0000ff>/* select the text style */ * U9 O1 c. b3 W0 S( K, ?2 A0 R
settextstyle(style, HORIZ_DIR, size); </FONT></P>% s7 {# M6 x+ {% ]# p# N1 u
<P><FONT color=#0000ff>/* output a message */ ) I  B: Q7 Y: a. p* h1 ]
outtextxy(midx, midy, fname[style]);
1 A# i$ U* j( f5 ?2 t7 wgetch(); ) Y+ L, |5 \- q# ?0 X
} </FONT></P>
! S! A4 s* z' S& ?<P><FONT color=#0000ff>/* clean up */
& v0 O  H9 ?  w( u! G  U2 [closegraph();
- d3 k* E6 r. U2 I+ l/ yreturn 0;
* d' i. Q' [; F% B} </FONT>
8 w5 t) T5 Z( D- ]% K5 x* ^8 U1 {& R8 {; K* w; T
</P>3 w3 s. X! _+ w2 \5 I
<P><FONT color=#ff0000>函数名: settime </FONT># F* m6 J% t! c' x
功 能: 设置系统时间
: i* O5 K& n- W! N$ I8 V用 法: void settime(struct time *timep); ! c+ k) l* R9 P) m- e3 @% P
程序例: </P>. v* \1 u- N! f# r6 d
<P><FONT color=#0000ff>#include <STDIO.H>
5 }* p+ s' D' S7 ]- F  t" x#include <DOS.H></FONT></P>7 G0 J2 k' G: b; q
<P><FONT color=#0000ff>int main(void)
3 _, [: z0 B6 c* ~" q{ ) Z# Z  h5 N& C! }! ^
struct time t; </FONT></P>+ h- e+ X# s  \* e
<P><FONT color=#0000ff>gettime(&amp;t); 7 I! j5 C& k# \4 _0 W/ I) C- I
printf("The current minute is: %d\n", t.ti_min); , k. r0 X0 b- b% L) C4 a1 y
printf("The current hour is: %d\n", t.ti_hour);
/ Z$ X2 Z* I9 N9 I9 s: Nprintf("The current hundredth of a second is: %d\n", t.ti_hund); 9 t: S, H1 i9 [; z7 x
printf("The current second is: %d\n", t.ti_sec); </FONT></P>
! H. b4 c( L* U% O1 d. }<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
3 s; `& A, F1 T' G0 j9 wt.ti_min++;
- h- `" V) x1 J  C! z& c8 }settime(&amp;t); </FONT></P>
7 H; `( y3 l$ h6 i! [# z- f<P><FONT color=#0000ff>return 0; ' V; r) C, Q# E8 Y7 V# G) V
} </FONT>
4 Z. H' u* O6 {, t% R# D# n0 S, j
</P>
, y& x% w0 h" M! h6 B5 K9 M<P><FONT color=#ff0000>函数名: setusercharsize </FONT>2 c# Y# |6 M; ?, A3 s" e1 t: q
功 能: 为矢量字体改变字符宽度和高度 * m! u, A# _! d( [) {$ M; [+ z
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
" f  D2 i7 i+ z# `- f程序例: </P>
) u0 K% T" m" X5 k5 E- F<P><FONT color=#0000ff>#include <GRAPHICS.H>+ G1 d8 q( z2 e  Q+ `/ s, V
#include <STDLIB.H>/ K5 a7 Q. P1 Y1 U8 [9 m& Q- g
#include <STDIO.H>& L) z- E+ W: \9 ?' x
#include <CONIO.H></FONT></P>9 ]9 J5 C. z0 N& v: U9 j
<P><FONT color=#0000ff>int main(void) + ]. g  A) s0 @' d
{ - {" }( i# S, y4 _
/* request autodetection */ 3 W8 n- m. ^) p" U) r* Y
int gdriver = DETECT, gmode, errorcode; </FONT></P>
) X, H1 L" V* T$ R8 Z<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 F5 i$ y/ K/ W6 ?0 o
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: d1 @( ~  a  n( y<P><FONT color=#0000ff>/* read result of initialization */   H% }' I2 Y# G
errorcode = graphresult(); , I4 l) B* B- j- n
if (errorcode != grOk) /* an error occurred */
9 s: V  f/ ~: w( V. F{
3 [9 k3 i; T7 w5 s# gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ! Y2 k6 x& [& ^2 Q6 y2 B
printf("Press any key to halt:");
6 y- ?  R8 ?; A3 B# i1 B* i' p: cgetch(); - j5 J6 R3 L" S+ R/ y, k
exit(1); /* terminate with an error code */ ( u, V# o" P- g7 G8 P! z% s
} </FONT></P>2 ~/ f' [2 j8 {" I
<P><FONT color=#0000ff>/* select a text style */ , `3 [3 i* ?2 A' \( I4 S; a
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>0 i$ n) ]+ n8 N! z" B% N$ {
<P><FONT color=#0000ff>/* move to the text starting position */ ( e9 ^! v3 Q1 P5 D+ ]8 e
moveto(0, getmaxy() / 2); </FONT></P># o/ `. A3 A: _% @
<P><FONT color=#0000ff>/* output some normal text */ " a0 X  c( i5 }0 ~; W9 }* l5 p) t
outtext("Norm "); </FONT></P>
' l: _% y% }) M0 H- |; P<P><FONT color=#0000ff>/* make the text 1/3 the normal width */   N0 R7 w$ ?, @+ `, p. ]
setusercharsize(1, 3, 1, 1);
+ A0 _( Q6 ]1 f! uouttext("Short "); </FONT></P>
6 v8 {% R% ]* g' @. Q2 v- q4 ~<P><FONT color=#0000ff>/* make the text 3 times normal width */ 2 @; I, G9 w) j! N
setusercharsize(3, 1, 1, 1);
" t# P6 @, b0 ^1 d, Q5 Iouttext("Wide"); </FONT></P>& W6 s0 I( Z! x$ f8 p
<P><FONT color=#0000ff>/* clean up */
3 q9 q7 |1 K. _. D2 M" {getch(); & ~- ]1 P; X  h- w$ g% f- I8 V
closegraph(); 1 e9 m0 }) F! R3 ^. e& S4 T+ P
return 0;
2 g8 [4 t* i$ f1 C( Q1 @2 i$ r} </FONT>
8 V/ j' r7 o( y! G0 a</P>- r- H9 n: K+ b( O  h. V
<P><FONT color=#ff0000>函数名: setvbuf </FONT>& B9 o9 e* ~7 l1 N
功 能: 把缓冲区与流相关
) T% Z. `! P/ k* l4 p用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); - I/ W" q9 D6 l2 f
程序例: </P>
- Z; v. \; ^1 t& O# W4 u" K( z<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
- @+ g: [1 Z' K) {  b9 x<P><FONT color=#0000ff>int main(void) 4 U8 `* l' _0 M- Z5 F. R
{ 4 w( h, ]. y( y5 d
FILE *input, *output;
! q/ V5 W5 R' m  I+ o1 vchar bufr[512]; </FONT></P>
% D( k+ J1 @- U" v: \5 T<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
; C9 M, w1 t3 K3 b, [& }output = fopen("file.out", "w"); </FONT></P>1 ?. K, [( G5 d# i, U" _
<P><FONT color=#0000ff>/* set up input stream for minimal disk access, / x, R9 U3 ^; h4 o7 A
using our own character buffer */
6 i# Q1 Q) S+ a) {1 w5 S) D( iif (setvbuf(input, bufr, _IOFBF, 512) != 0) , ]' t. A: n$ \3 R" B7 k
printf("failed to set up buffer for input file\n"); * V+ g! p7 I6 `- h5 Y
else
6 \: q' ^( z4 t' H3 r4 @* jprintf("buffer set up for input file\n"); </FONT></P>
) ]4 Y3 M8 C- G# ~; V4 `+ `0 t" |<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
0 `8 f& v4 ~& Q. s# ^1 f( ~, Xwill be obtained through an indirect call to malloc */ ' `: w% j8 f- u, `" R- A
if (setvbuf(output, NULL, _IOLBF, 132) != 0) & D" X; `  |9 V' v- p$ f! {0 r
printf("failed to set up buffer for output file\n"); 7 v0 ?" g) f+ h- t: c3 v
else
) T4 z# j  b* I+ u4 |printf("buffer set up for output file\n"); </FONT></P>* {* ]: Z; v4 h% S% x; `* Z6 w5 ?
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>( Q2 }) D; K5 I+ c6 J$ t
<P><FONT color=#0000ff>/* close files */
5 M( v! d+ k! Vfclose(input);
7 ^% S1 ?0 f" g0 D# G& r) Jfclose(output); ' O% B5 C: t; `% R
return 0;
; p5 T* H" v/ @8 u7 ~; Y} 8 n" N1 ^- |0 |) ]; [+ P
</FONT>$ `& d. L! E0 q' _  s0 C
- c4 x: T: l- ?0 p& I4 L8 o0 s
</P>; c8 s% K2 w5 J7 K$ O& K, @8 m
<P><FONT color=#ff0000>函数名: setvect </FONT>
/ Y; x; d) W! U) t, u/ F功 能: 设置中断矢量入口   p, y$ \4 |; z
用 法: void setvect(int intr_num, void interrupt(*isr)());
" r* b% B; p* j$ Z  t程序例: </P>1 \6 ~; v/ {) T! p! Q
<P><FONT color=#0000ff>/***NOTE: 9 c9 {2 n, y  T( F' z; k
This is an interrupt service routine. You can NOT compile this * }0 |4 ?2 ]& K
program with Test Stack Overflow turned on and get an executable
; b2 ~* o, Q2 A! q9 G+ ?) ~file which will operate correctly. */ </FONT></P>
+ r- T. G2 `1 @) T! `; \<P><FONT color=#0000ff>#include <STDIO.H>: e8 _' I) X4 M! e; b5 O0 X
#include <DOS.H>
: |! D+ i3 S$ h7 H- t$ @) A0 \/ s#include <CONIO.H></FONT></P>
+ I7 I6 p9 X: ]<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>
9 h4 J! S* Y# n  s; v# |<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>- F2 e6 ?4 s3 u; O" q5 r
<P><FONT color=#0000ff>int count=0; </FONT></P>
/ v2 H6 k3 @: |# B4 m3 n9 I2 M<P><FONT color=#0000ff>void interrupt handler(void) + E. \% U; D+ ~+ z+ \$ n* p
{
8 d9 V2 s0 Y! K/* increase the global counter */ ) f7 U! g0 b) A  @9 ~6 k1 O
count++; </FONT></P>4 i' Z  J, s  m- e* X
<P><FONT color=#0000ff>/* call the old routine */
4 r0 P0 _; H' I: N2 ]/ P3 soldhandler(); : Q) I: z, I0 B
} </FONT></P>
) U7 [/ o; Q& Z" \' U1 [/ s  \  C4 A$ w<P><FONT color=#0000ff>int main(void)
, p  ]8 W$ l  F( i' }, p: z/ t7 U: n{ % r0 U% s+ E( M' o& a4 L* @- u
/* save the old interrupt vector */ ; m3 k! F, F# W/ `3 E" O
oldhandler = getvect(INTR); </FONT></P>$ B3 X: Y. Y5 M+ y( k7 z& F
<P><FONT color=#0000ff>/* install the new interrupt handler */
; b0 E" `8 E, z  D- V; Csetvect(INTR, handler); </FONT></P>
- x* {0 `& w/ t5 W. f( g  }; Z3 Z<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ + v' r& `% k, `1 k7 H* k
while (count &lt; 20)
. ]% p" A5 G5 @- B( t" R+ K4 [printf("count is %d\n",count); </FONT></P>5 z* [, b) [4 Z1 U
<P><FONT color=#0000ff>/* reset the old interrupt handler */ 2 v6 `* ?$ ]& m9 O4 Q( S
setvect(INTR, oldhandler); </FONT></P>
# }9 h" R! \. y: T0 \<P><FONT color=#0000ff>return 0;
5 Z5 S% T6 b5 n! Z2 A/ k- y}
' G/ V1 N8 E. }% T7 K8 @6 T  ?</FONT>
' F: d, y7 m. n</P>. z- J, v; w- E8 T+ K# q
<P><FONT color=#ff0000>函数名: setverify </FONT>
# D1 q! i" z0 |3 }功 能: 设置验证状态 - _  [  x. F7 f8 p( _  s
用 法: void setverify(int value);
! f7 L/ H$ N$ m程序例: </P>1 t* ]1 z* T; N, F( z  C# r; Y
<P><FONT color=#0000ff>#include <STDIO.H>
8 }+ u$ Q* ?/ D/ m( ^#include <CONIO.H>
2 w% @5 O! d( L, K/ D( o#include <DOS.H></FONT></P>
3 e9 S# _: W+ L% B: g<P><FONT color=#0000ff>int main(void)
2 _9 ~$ C. P) W4 ~. {  `; _9 I& b{ 8 S/ k4 J3 z) L! q+ x; Z8 x
int verify_flag; </FONT></P>
  q; b2 u% Z0 V! X<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
* ]: B! B1 `7 N/ ~8 F- n7 Zprintf("Enter 1 to set verify flag on\n"); </FONT></P>
6 Y2 F1 [5 h# V9 @: S<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>
3 a- [# U' _: [6 ?3 V<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>2 ~' Q: S  q$ u% _4 @2 E9 N
<P><FONT color=#0000ff>if (getverify()) ( x; S, S6 K. Y" S
printf("DOS verify flag is on\n"); 7 i2 \0 k5 ?5 D0 c/ F
else
9 k) S% n; c( z& X8 _3 Aprintf("DOS verify flag is off\n"); </FONT></P>
9 Q1 U! b: G4 o  |; d+ S0 ^<P><FONT color=#0000ff>return 0;
3 P+ ^6 C, X. K( J0 }, ]) p}
4 ~) i3 g; q% z) Z1 H4 e: N<FONT color=#ff0000>
& }% h! f8 q- @; z</FONT></FONT></P>
* w5 c& j/ `! s6 k: Z( `; O<P><FONT color=#ff0000>函数名: setviewport </FONT>( P9 V0 m0 i- H* ]  \* s
功 能: 为图形输出设置当前视口 ' q7 {; e+ u# U+ N1 E/ k1 \
用 法: void far setviewport(int left, int top, int right, - I9 U  D9 Z% }4 M
int bottom, int clipflag);   Y$ r# H# @) p
程序例: </P>) I# E) e6 i! y: Z
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 S8 F: l8 N# ?5 @1 D/ ^# ]
#include <STDLIB.H>
. L. b) X! n) f8 I/ Z# s8 N#include <STDIO.H>8 a7 l9 Q/ l% T
#include <CONIO.H></FONT></P>* j" N: ?. c8 @, V$ x2 K  H+ @8 \
<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>8 R1 m$ c  P0 \& U: S% ?  F, T
<P><FONT color=#0000ff>int main(void)
+ I+ O0 D3 c0 j' t: l{
9 q+ [/ _3 O  M/* request auto detection */
2 u3 s" m* X9 J; _. P1 Uint gdriver = DETECT, gmode, errorcode; </FONT></P>
+ Y8 _  x0 p" d1 Z; R3 J<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 ?& \/ C5 `1 g6 H
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 ^( a  J2 o7 I5 r  T% N<P><FONT color=#0000ff>/* read result of initialization */
+ n5 ~3 J$ e. X. @  c0 Gerrorcode = graphresult(); 3 x* e( t3 N2 {; F
if (errorcode != grOk) /* an error occurred */ & k; Q  u5 r0 @5 a& _) t8 \: i: H
{
! u) M! ^0 ~! Y( Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 d$ ?  h3 q0 W* W& hprintf("Press any key to halt:"); - e/ i" ?0 P" T6 G& t
getch(); * ]5 p" A$ }0 l% ~/ T! \0 l
exit(1); /* terminate with an error code */
- r! f0 F  J9 |} </FONT></P>- `4 h2 E. Z' X9 c4 P- o
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>+ V7 S7 Z) R4 a
<P><FONT color=#0000ff>/* message in default full-screen viewport */
/ R* e. Z3 ^+ P  H5 couttextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>+ t9 g' O* N+ H8 b: ]: e
<P><FONT color=#0000ff>/* create a smaller viewport */
1 N, f9 \* a8 {+ b8 Xsetviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
0 [3 v; |6 \/ w2 j<P><FONT color=#0000ff>/* display some text */
7 x: ?; i* v* Z0 ^. E: [5 @outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
4 l3 n6 X5 W2 j3 |' T" p<P><FONT color=#0000ff>/* clean up */
$ Z& S# B( S5 x3 S! Z2 ngetch();
1 E& I  \+ S- k! I3 M0 Iclosegraph();
0 L* m  J6 {9 p2 kreturn 0;
$ [9 Q  S  G$ w( C} " t2 v0 H/ R# G# K$ _5 D# w
</FONT>
+ d7 ~' W  H5 F: h# ~</P>/ [/ E2 P4 l9 p, x  {5 a0 R& D
<P><FONT color=#ff0000>函数名: setvisualpage </FONT>( I& d2 o! j* H1 d1 m' p
功 能: 设置可见图形页号
- Z1 ^$ m. ?8 a) x$ ?用 法: void far setvisualpage(int pagenum); $ I/ r7 d* |. ?7 ?
程序例: </P>
; m$ N2 \6 I& K9 {- U( |7 n<P><FONT color=#0000ff>#include <GRAPHICS.H>% B2 ~3 P  a/ c4 F1 `9 ~+ g9 _7 }
#include <STDLIB.H>
1 G( |  J8 [2 s+ G#include <STDIO.H>3 g, d: Y3 [6 K' V( j  k) S, @9 v
#include <CONIO.H></FONT></P>
; s6 k+ m  r; h" @8 t8 g2 ]5 M5 U<P><FONT color=#0000ff>int main(void) 9 w5 P4 {# g; }
{
; n/ v6 ~1 i/ |/* select a driver and mode that supports */   R* I- \' |+ G& K! z* v
/* multiple pages. */ ! A/ u: S! Z$ U! q% |  ~( w6 k
int gdriver = EGA, gmode = EGAHI, errorcode;   |$ c' `+ z$ ], _
int x, y, ht; </FONT></P>
8 k& t5 O4 s, u, Y* F) U% `<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 M, h% p; k6 t; O2 c: dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: d: I! G+ |# t, G) J<P><FONT color=#0000ff>/* read result of initialization */ 7 n# l+ d; `$ G& K0 r, o2 `
errorcode = graphresult(); 9 S. z4 S1 T4 h6 Q" \
if (errorcode != grOk) /* an error occurred */
8 F2 y8 L& {3 A: d0 E& j1 G! f{ 2 f" h' M' B; q( @1 @
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ! H/ I( \8 y* Q
printf("Press any key to halt:");
. S6 z2 b! d1 N! kgetch(); 8 S, J$ g0 t9 o: V  X
exit(1); /* terminate with an error code */
  `- V8 T7 g; f" j1 ]: j# A} </FONT></P>+ q0 W2 k4 Q, w$ o: S4 f
<P><FONT color=#0000ff>x = getmaxx() / 2; $ ~' V9 W/ S( K1 z! A
y = getmaxy() / 2;
$ L2 A9 ^7 p2 lht = textheight("W"); </FONT></P>
; K% T+ ]" }) g+ t0 O<P><FONT color=#0000ff>/* select the off screen page for drawing */
" y) k1 J5 _9 k: B" {+ W( J/ Ssetactivepage(1); </FONT></P>
' z) [5 I: {) n. Z4 u0 d7 S9 T: ~  n<P><FONT color=#0000ff>/* draw a line on page #1 */
6 B& c: j7 ~/ ?line(0, 0, getmaxx(), getmaxy()); </FONT></P>
7 e  ~3 @4 Z! }. u; [<P><FONT color=#0000ff>/* output a message on page #1 */ : h# ~$ h' Z9 ~# J+ C5 ~7 _4 |5 L0 \$ @
settextjustify(CENTER_TEXT, CENTER_TEXT);
9 m  M$ g- f# Z5 Z! N; b* x) Routtextxy(x, y, "This is page #1:");
0 T1 O- ]; F, C6 g) ]outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
' S/ [, S- S6 V- L. R<P><FONT color=#0000ff>/* select drawing to page #0 */ / R1 C9 G! L" V$ a# v& n, F
setactivepage(0); </FONT></P>+ W8 l% R! I; s! r
<P><FONT color=#0000ff>/* output a message on page #0 */
; N" }( p; Y' e3 Touttextxy(x, y, "This is page #0."); 8 }/ A8 m& v0 V6 ~  x
outtextxy(x, y+ht, "Press any key to view page #1:"); ! Z0 ^' p5 K8 X
getch(); </FONT></P>9 P& I3 d* i( b6 |) j
<P><FONT color=#0000ff>/* select page #1 as the visible page */ 0 y4 t% V* O0 U' B, U
setvisualpage(1); </FONT></P>% P8 H: C5 n" z6 D2 X
<P><FONT color=#0000ff>/* clean up */ 7 Y! `$ Q- G  s6 o) s. d
getch(); 2 t* e: M" j8 s5 e8 q0 R  g5 ~
closegraph(); ' m& e5 d( e$ F: c3 W" y7 l! e
return 0; * T) l" y8 G' }
} </FONT>
* Z; J) k6 s: v0 `
& P( L* E. d& ^7 y7 Q& H</P>8 `0 r) h0 M' a% H" e, s0 _# `; q
<P><FONT color=#ff0000>函数名: setwritemode </FONT>  [7 G( m% J, a
功 能: 设置图形方式下画线的输出模式 , w7 ?% g/ P9 ]/ ^7 I. l* W
用 法: void far setwritemode(int mode);
5 F: W5 [) F0 ]) ~/ ^- q8 X  [4 o程序例: </P>7 B0 J: ^7 x) D  x1 [# H$ Z
<P><FONT color=#0000ff>#include <GRAPHICS.H>* G; H' \8 W7 [3 H9 n
#include <STDLIB.H>
- Y& w6 B! q% \. l3 k#include <STDIO.H>
) B3 m/ T! U7 @/ O#include <CONIO.H></FONT></P>5 G; C* t, n: q" X/ n* d
<P><FONT color=#0000ff>int main() % V& [+ ]" V, U$ W) b0 y
{ 3 q' s' K3 e# ]: I
/* request auto detection */ 6 f- w2 U" X% r
int gdriver = DETECT, gmode, errorcode;
; r1 n, R6 u* s- I( [# [. t) Y1 }int xmax, ymax; </FONT></P>
( r+ k  A- G8 H+ G<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ ^( {& r& G, m+ P+ Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
/ h3 Z0 }$ J- e6 M# ^<P><FONT color=#0000ff>/* read result of initialization */ 7 j4 U: m8 @# `" a+ v* ^6 S
errorcode = graphresult(); 1 a0 x! d& k) R- \$ u
if (errorcode != grOk) /* an error occurred */
7 w" _3 ~9 B7 I' D' v1 z% v) C% p3 A{
& l; V- q, i+ Jprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 R4 R% B, e( D. F" bprintf("Press any key to halt:");
( b  |% l" T& }# _getch(); ( f" |' c, E- |5 u
exit(1); /* terminate with an error code */
+ t5 t9 W6 s0 d8 x# _2 N% N} </FONT></P>
5 W" d9 T" P; L8 x' _6 A1 U<P><FONT color=#0000ff>xmax = getmaxx(); 9 t! c  Z1 h9 y  C  D0 N0 T* X( b
ymax = getmaxy(); </FONT></P>
7 f; F9 K. ?& s1 ^3 N% U  ^/ h<P><FONT color=#0000ff>/* select XOR drawing mode */
  Q+ s* ~# [, C! i* zsetwritemode(XOR_PUT); </FONT></P>% D0 _4 d. [( ]
<P><FONT color=#0000ff>/* draw a line */
6 F( l2 p7 n! b9 S5 ]9 K2 ^line(0, 0, xmax, ymax);
6 k. H6 R3 m8 Wgetch(); </FONT></P>; s9 P6 [( r& f  W# N; S7 t
<P><FONT color=#0000ff>/* erase the line by drawing over it */
9 R6 C7 m' l& v  b, }: l. ?* pline(0, 0, xmax, ymax); 9 C/ I! O# N$ m% v
getch(); </FONT></P>
# n, y4 z$ X8 \+ ~. b<P><FONT color=#0000ff>/* select overwrite drawing mode */ 5 F, g6 ]) R' B' ~4 x4 Y* ?
setwritemode(COPY_PUT); </FONT></P>
: h. |9 `! X* A  y# [' |- N<P><FONT color=#0000ff>/* draw a line */ 9 R+ R+ W, s! c. U7 G
line(0, 0, xmax, ymax); </FONT></P>; P1 [' P4 z/ ]5 u$ Q. R# r
<P><FONT color=#0000ff>/* clean up */
8 L8 n; I# o9 u9 Zgetch();
0 B% R4 H5 {& S3 v& G( [closegraph();
+ A" D! W) X- |$ oreturn 0;
  P* y/ _; H: I7 j8 [( H}
. I3 C! C2 T( O. D5 j. w3 u& G</FONT>  P, `0 r- p& _# `2 L! X1 N. g$ k' t
</P>
7 e: R4 b# G$ ]! Y* [* g  L<P><FONT color=#ff0000>函数名: signal</FONT> # P  A  N' b7 b% K$ q/ f
功 能: 设置某一信号的对应动作
5 m2 U( j. C7 _用 法: int signal(int sig, sigfun fname); 6 e9 @9 g: j+ S1 O7 y
程序例: </P>7 H( e" `( p, c* M9 q
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE,
& i% }! u' E: w/ g+ ^/ p, {catches an integer overflow condition, makes an adjustment
5 F# _6 U3 Y  F, Y0 M/ P+ e6 }to AX register, and returns. This example program MAY cause 9 x" J3 Y, S8 m2 A; a* b: _; v
your computer to crash, and will produce runtime errors 6 F$ e0 q. N4 K. P, c6 l# O( d' q
depending on which memory model is used. ! |' f9 F  n0 ~) k
*/ </FONT></P>
2 k; D+ }& @3 s; t0 d8 z) L<P><FONT color=#0000ff>#pragma inline * @3 x0 K1 i' P/ v6 h' z  U
#include <STDIO.H>
) P% ^# v" _  X' G" i" M* M* R#include <SIGNAL.H></FONT></P>2 ~2 p, X7 A5 c4 f3 f9 J& Y) T
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
) @- `' P4 m" [  R5 F{ 6 V! ~& K- E6 ]1 f2 p
printf("Caught it!\n"); ; k1 Y% S1 Q4 x( g% q, z& s
*(reglist + 8) = 3; /* make return AX = 3 */
4 W$ [, Q3 ]4 l) s} </FONT></P>
9 _9 x2 x4 \, |( m<P><FONT color=#0000ff>int main(void) % b+ J' I! _# g. {6 e9 B
{ . [- n) j2 H/ {) X5 [: A1 ?5 O
signal(SIGFPE, Catcher);
2 D4 S' m- j8 I2 A! Y9 }% |. C0 [7 sasm mov ax,07FFFH /* AX = 32767 */ 4 f1 ?3 O4 ?: F& o" _. x" S. _
asm inc ax /* cause overflow */   m- r( T" A& w0 L) n% O7 b* Z
asm into /* activate handler */ </FONT></P>
" ?/ g2 A& N' I* M, @% }( K$ \<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened,
5 R" f  p6 T6 e  j6 R6 zthere would have been another exception when the next 'into' $ w. I, T, L0 K9 S' r( g
was executed after the 'dec' instruction. */ # h/ p; @& B* G& M
asm dec ax /* no overflow now */ 9 i, b! a4 }! A# h- g. h
asm into /* doesn't activate */
0 [1 j& F' k( areturn 0;
0 o  |2 n7 C/ f5 o( Y  v$ o} # r/ F; Q- }; A' }

5 O' r( I- q. I" k% K7 H) Y
# j% E8 U0 q; ]4 V5 L1 H$ d; |</FONT></P>" H* g( Q/ ?6 k  X. F
<P><FONT color=#ff0000>函数名: sin </FONT>. {) K% w- G; Z  J
功 能: 正弦函数 & l5 F1 l' \0 g
用 法: double sin(double x); ; E$ \  z, h, c% G0 Q
程序例: </P>
8 K" x5 O+ f& s5 s& R<P><FONT color=#0000ff>#include <STDIO.H>
- @& O/ k1 X4 H#include <MATH.H></FONT></P>; U# F6 e- B, }0 O/ i! G2 `5 h, l& h
<P><FONT color=#0000ff>int main(void)
5 A, P( k/ ^7 f$ v{
' e. n  Z' c5 ?double result, x = 0.5; </FONT></P>; Q2 Z& W( r7 _/ s
<P><FONT color=#0000ff>result = sin(x);
& `, \& b$ p  u9 ^: d* O' c+ Vprintf("The sin() of %lf is %lf\n", x, result);
, P3 ~) W' E* d: ]9 X: J( Areturn 0;
* Q7 e* ~& l9 }1 V% I8 I. e7 `}
' S% v; r$ a. o
3 w5 F4 K) C  L& _</FONT></P>. |) v- @! j8 v6 I* ~
<P><FONT color=#ff0000>函数名: sinh </FONT>
  ~) T# X" u" \# H  D2 M功 能: 双曲正弦函数 / H$ o# H# X+ \. j$ ?/ V: z
用 法: double sinh(double x);
5 H0 r0 {# ~5 [" d, s程序例: </P>: E0 E5 p! S) E9 c. c# J
<P><FONT color=#0000ff>#include <STDIO.H>- I4 v' P% X2 Y; ~( ?
#include <MATH.H></FONT></P>9 e% N$ L4 l; A1 s
<P><FONT color=#0000ff>int main(void)
6 x2 E8 D8 g& z{
$ e* f7 g( p& gdouble result, x = 0.5; </FONT></P>
& H( Y. ?9 i9 ~+ f( D$ h% d<P><FONT color=#0000ff>result = sinh(x);
7 u! m. v% K5 Q4 Z" N- M8 aprintf("The hyperbolic sin() of %lf is %lf\n", x, result);
# N; t: c. D& q# D6 H% kreturn 0; 1 a0 W0 N% O5 l- Q( m% M
}
. M* F: G- f3 P2 X5 n
* [; i6 l: h2 v& b8 ~$ s7 L; W  J- J
+ }# z) f+ i; ^. b: m9 t: _  x</FONT></P>
1 o& F  j1 @) B5 N1 P+ a. ^<P><FONT color=#ff0000>函数名: sleep </FONT>
# k1 v, o( F0 g3 m+ y功 能: 执行挂起一段时间 0 G, F. @- N. q: l$ Q
用 法: unsigned sleep(unsigned seconds);
9 k2 \6 j1 B4 J8 |程序例: </P>
' A: |+ r4 g0 e5 M8 m$ P2 V) D<P><FONT color=#0000ff>#include <DOS.H>6 e( a4 W( g% n) K- ~  k
#include <STDIO.H></FONT></P>. f! F5 Z8 r% W* C) i! K  E
<P><FONT color=#0000ff>int main(void)
1 Z. y% Z, H4 `/ R{
+ u3 r  [7 ]/ Q; r% m+ {int i; </FONT></P>7 L% h( k! ?. j/ F; e  {$ t- C: w1 ^1 {
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++) ! ^! A8 A$ Z/ g: y8 y$ n7 |
{
) H: v  V) q! [% o- @5 _printf("Sleeping for %d seconds\n", i);
- o8 Y% p9 a6 A3 {, J. hsleep(i); 5 g0 s; m+ v5 ~" K8 L
}
: ~1 Q2 I) N: A1 q- W7 s/ Ereturn 0; / E) m2 w2 M( w/ @; b6 f- Y
}
  [- q' d7 L0 o% F. q/ C+ s
' S" X2 D' j& T8 t/ \6 O9 `1 O</FONT>
* S, Q! A$ e) y, F- y# y" C9 H! _# F</P>
8 t/ q* H! `6 h/ c$ ~* O<P><FONT color=#ff0000>函数名: sopen </FONT>5 s( S3 L, \! E" e3 ?4 B1 _+ _
功 能: 打开一共享文件
4 B& p5 J& N. H1 ?1 W9 G: F用 法: int sopen(char *pathname, int access, int shflag, int permiss); " i$ l, _$ F8 D: D2 D
程序例: </P>3 B/ u: o% Z/ D8 W0 @- r
<P><FONT color=#0000ff>#include <IO.H>, C: Y3 G& w+ R! _  A8 j: M
#include <FCNTL.H>3 V" a3 g* Y2 t3 E
#include <SYS\STAT.H>
+ E' K  q/ ]6 ^3 k( L/ z4 J  d#include <PROCESS.H>
3 C9 n8 U6 @/ ]- }$ d#include <SHARE.H>
/ Q3 k- _6 z2 r5 A#include <STDIO.H></FONT></P>  K2 o% E5 _% ^9 B8 @2 ]2 k/ w
<P><FONT color=#0000ff>int main(void) 8 w8 S( u7 @  }. t0 }' o: y
{ ) K5 d' F' P+ U" E% o9 A
int handle; . h% G" [; j6 i3 O) D5 g
int status; </FONT></P>
1 }2 G9 u+ @5 }( n( {( P8 e5 _2 t4 Y<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>
' @# e) _. r1 _! G<P><FONT color=#0000ff>if (!handle) 1 t$ G# d, E( D# ~# |) ]
{ & g6 c4 u( ?  z: z7 r" Y! @2 X0 L( w
printf("sopen failed\n");
1 U  h4 {/ K3 cexit(1);
/ [6 t; u9 v( f. }8 y+ i} </FONT></P>% M; S+ p. }; l
<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); 2 @- [4 ^' [# A" k6 z+ Z
if (status == 0)
; u/ ^5 d: T' wprintf("read/write access allowed\n");
8 l4 Z* B2 b# j# aelse * p3 X7 ?. t7 Y# s, ]5 R8 u) ~
printf("read/write access not allowed\n"); </FONT></P>; J, v6 U+ j) F, O" N0 c
<P><FONT color=#0000ff>close(handle);
6 c6 g: L& P0 c" y  S3 ~return 0;
3 c* G0 V/ S3 I8 G} 2 Y8 q. v* S# B/ I1 R# k7 f/ B

/ q* @# _% X$ l</FONT>
" c& T4 f' `; b9 K1 k( u</P>
  }5 q5 R+ d: A" o' `) _( Z<P><FONT color=#ff0000>函数名: sound </FONT>: M! u3 h4 {, L5 h& R; h  l. }- ]
功 能: 以指定频率打开PC扬声器
+ x& r- [7 R" x) M. \) w, W: ?用 法: void sound(unsigned frequency);
* _! X" g( P( C/ [9 q程序例: </P>1 w% b0 Q, c/ M+ p
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds.
+ v. R6 Q5 s' m3 j+ q$ zYour PC may not be able to emit a 7-Hz tone. */ # O" D* j% z1 b8 Y
#include <DOS.H></FONT></P>7 U$ f7 K# m0 S9 Y6 w% ^2 M8 C
<P><FONT color=#0000ff>int main(void)
0 l' H# Q4 w  k. f: G{
1 a, G) g# v& a9 D+ }3 ssound(7); 4 z: Z) _) h, f
delay(10000);
6 I) R1 J. B; ]nosound(); 1 e9 I5 j' g# }% l( F! P
return 0; : j  x4 Z4 F! i$ z6 m( H
} </FONT>
/ s$ t3 a8 v+ T  L( G+ z* `/ R- _$ |1 R" g' [

, d6 U3 c8 v2 S</P>
1 y. ^( I7 ]6 m  Y. c2 [<P><FONT color=#ff0000>函数名: spawnl </FONT>( o0 m5 r! S  [) O$ F0 v1 K- I) F
功 能: 创建并运行子程序
, Y! p. `! C3 E! H9 m% q4 c用 法: int spawnl(int mode, char *pathname, char *arg0, + z9 F# S5 C# n2 g
arg1, ... argn, NULL);
8 _* p, Y4 E/ ^' m0 U8 u程序例: </P>6 ]! i. k" i0 k! y6 a: j
<P><FONT color=#0000ff>#include <PROCESS.H>+ R% d! B; M2 p; C$ C# M9 p
#include <STDIO.H>9 b, F2 _2 {# ~5 M3 A( Z- {
#include <CONIO.H></FONT></P>
7 t. g. X- F+ ?! F<P><FONT color=#0000ff>int main(void) + v$ a6 f' p9 B, w- E% l$ m! ~6 X
{
; Y- v4 k: ?% F- ~  S" z8 d( u" Dint result; </FONT></P>
7 m  o% ?7 b6 n: F: ]- ~' s8 ~- y2 |<P><FONT color=#0000ff>clrscr(); ; U: [% X' I3 y# U) j$ W: n4 N
result = spawnl(P_WAIT, "tcc.exe", NULL);
( [  g( h2 W7 q$ z0 p" u7 |2 oif (result == -1) $ z( [0 W1 E  O  r8 o7 k! V
{
6 a. r" \9 V. ]$ R* I* Bperror("Error from spawnl"); 4 M! [3 {& k4 l% c. ~2 B9 a
exit(1); 9 N' o# E0 k# z/ L
} + C! n' v$ \1 @/ h+ k4 D( a
return 0; $ r3 @: G' j( V1 B) v1 \
}
8 b* X* A& T' A</FONT># R" r! m: @; ~" x3 `6 v0 W
</P>2 q0 ~' w# C: i2 Z3 E
<P><FONT color=#ff0000>函数名: spawnle </FONT>
1 q8 N0 Q7 ~' O8 b  h功 能: 创建并运行子程序
. w% V0 ~' Y6 h1 v7 [2 j用 法: int spawnle(int mode, char *pathname, char *arg0,
2 b: t/ E. I! A8 J' h% E3 Y; Karg1,..., argn, NULL);
$ t9 O: A$ |. p% A: r; H) g3 L: o程序例: </P>
, t* V& ]) `3 x$ \, U$ C4 l$ R' ^<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>
2 z2 b  P2 K3 o1 v  @5 z<P><FONT color=#0000ff>#include <PROCESS.H>2 m/ F/ A- V7 s: F- k
#include <STDIO.H>: i" ?2 k- v7 s  ?
#include <CONIO.H></FONT></P>: j, {, S5 I7 [) X- f2 u. C% l
<P><FONT color=#0000ff>int main(void)   w0 X4 H1 u! ^9 A" Z
{
9 [) J6 e. B/ Eint result; </FONT></P>
  `# y3 d3 z4 w. T7 `5 o. D<P><FONT color=#0000ff>clrscr(); 9 q4 V" O; n$ H5 ~
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
6 @/ a1 P) `  r8 L: [if (result == -1) , i6 M% v! t9 k4 V+ t" O/ s
{
* \% d( a. Z  X6 zperror("Error from spawnle");
! @- K$ ^% E( b( Z8 N7 t% L( wexit(1);
' I/ b# p/ d# W6 m( P}
9 o3 w. ^# I. X  {, M* ~1 [return 0; 5 o. c+ E+ n2 x- _, C! P) C
}
- h" x. M5 S" A8 Y1 G* k- C: P+ I- J8 d
( @5 f  r- T4 u5 w2 [' s; N- |7 V+ O1 ?& p0 [8 x' k: O, c
</FONT></P>: i9 H2 m4 G7 Z2 Z, I
<P><FONT color=#ff0000>函数名: sprintf </FONT>/ X+ B) T4 }9 N$ ]$ F
功 能: 送格式化输出到字符串中 # T% G$ _+ r  z, i
用 法: int sprintf(char *string, char *farmat [,argument,...]);
" \% u' E$ ~, l程序例: </P>
7 R+ z7 L  p1 H+ q4 b8 L<P><FONT color=#0000ff>#include <STDIO.H>
8 F8 _8 Y8 g( |# S8 v; V6 c#include <MATH.H></FONT></P>
. n% }& r. p' |<P><FONT color=#0000ff>int main(void)
7 u8 S; |# r3 t# @{
! g! W8 S; M3 n' A  T- G9 f; x- zchar buffer[80]; </FONT></P>
* b# i* `$ {1 B; O  L<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
! |# ~4 o1 G5 l) L% a  P  Yputs(buffer);
8 f+ d$ A0 V0 u! ?2 Jreturn 0;
9 h/ V6 m4 w1 z6 `9 }} , O- Y: I9 ]. c6 n% F
</FONT>( _) V2 q9 i& p& S* E/ ^/ p. {
</P>
: Y- P6 g( f! ~<P><FONT color=#ff0000>函数名: sqrt </FONT>
# ]+ \0 D' |7 M$ y功 能: 计算平方根   x$ ~2 `+ b: A! h
用 法: double sqrt(double x); & ?8 B# l( P8 v; L) w1 |9 t
程序例: </P>4 H$ i% _5 |8 H  p6 U5 B& Y
<P><FONT color=#0000ff>#include <MATH.H># F6 a/ \5 {2 O1 U
#include <STDIO.H></FONT></P>
2 ]" R5 Y6 e  j" }, D* c<P><FONT color=#0000ff>int main(void)
. Z. Z) b; Q+ f  e/ U{
2 i( F' i! ~$ g! q9 [double x = 4.0, result; </FONT></P>& L( Z* r4 t5 k: E2 @
<P><FONT color=#0000ff>result = sqrt(x);
" ~- }2 ~& ]! cprintf("The square root of %lf is %lf\n", x, result); 3 u9 ~: m4 [, u2 k2 V* w1 v0 G9 I
return 0;
0 J0 q7 U! f5 }5 H3 C: G9 z1 n0 G; M}
" p  }0 C+ C6 i! Z4 V  G. A</FONT></P>0 z5 ?( e, @0 A6 Y% z3 T# G
<P><FONT color=#ff0000>函数名: srand </FONT>1 \; K- l; D( p! V& n
功 能: 初始化随机数发生器 2 i. ~  Y( `+ J( j+ @4 X6 j
用 法: void srand(unsigned seed);
, R9 t/ R: ^' {程序例: </P>
$ f% F) k1 K: ]8 I' P+ I$ L! k<P><FONT color=#0000ff>#include <STDLIB.H>1 J7 J5 ?( N4 t( H) {
#include <STDIO.H>
# d! n! L6 c( F/ `% `#include <TIME.H></FONT></P>- z+ c6 l0 n6 z+ J
<P><FONT color=#0000ff>int main(void) - T1 c, d9 i. K
{ : ~- X, g! Y# T- L
int i;
3 @$ [6 I0 g' I# w9 X5 utime_t t; </FONT></P>
. m. b9 R9 }% c! p5 i<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
! U& S7 \) w* n3 G8 V, Y+ mprintf("Ten random numbers from 0 to 99\n\n");
5 b6 V. i6 X+ }/ R+ Ifor(i=0; i&lt;10; i++)
: @4 V% g! }8 Z5 K  Q: @7 Fprintf("%d\n", rand() % 100);
: K8 \3 x* g6 Vreturn 0; - e7 l$ a  w5 T% H8 @
}   y* `/ t) r- ^0 {# G: B8 [, H0 S
</FONT>2 [" D4 G; p: `' Q  W8 n2 l
</P>
; ~' S7 L9 ]9 o3 t<P><FONT color=#ff0000>函数名: sscanf </FONT>! R1 E/ h/ r6 o0 F1 Y; q
功 能: 执行从字符串中的格式化输入
$ y1 M) ?% z  X用 法: int sscanf(char *string, char *format[,argument,...]); : k2 }0 a, t( t2 f, }/ A+ |, N
程序例: </P>& W3 m/ [3 ~8 s2 L
<P><FONT color=#0000ff>#include <STDIO.H>* u# F+ g  ?4 ]3 }, {1 K  ^) T# {
#include <CONIO.H></FONT></P>' X. {  [# }- |' V' D2 _; _
<P><FONT color=#0000ff>int main(void) 9 j0 \3 g, X( Y& P8 A) R0 s2 f" j
{
  T7 ?+ Y; \- h1 |char label[20]; 9 T- w, T: I+ z
char name[20];
9 [" C0 L$ q3 V9 X  r8 s& E2 Lint entries = 0; & `+ I& R# I2 v
int loop, age;
7 V) U& C9 V# m; A. [  y+ [double salary; </FONT></P>/ V; R$ x% q1 B7 C; J
<P><FONT color=#0000ff>struct Entry_struct - T. }' S. q3 O) Z1 Q" o. X
{ ! v6 a" I+ ~2 W+ V+ W
char name[20];
6 U6 ?. j" N" W( d) Vint age; 5 `9 a3 `$ I1 x4 f4 |& T3 U6 s  F( R% V! |
float salary;
! D8 O% h- D) e0 T} entry[20]; </FONT></P>
5 d' h3 k6 f) f( U  ]$ N& A<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
  H0 o& U9 E% C; e0 f# y& B* b1 Xprintf("\n\nPlease enter a label for the chart: "); ) m/ m0 O- L" T1 t
scanf("%20s", label);
# n5 u5 f  R- Tfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>  C' S5 Z+ L' j& U8 B" A
<P><FONT color=#0000ff>/* Input number of entries as an integer */
1 Q/ w2 k% ~6 g8 ^' N, aprintf("How many entries will there be? (less than 20) ");
; {/ {( B- d% k0 b* E1 B4 N) Rscanf("%d", &amp;entries); . u! g' L" i7 O- k
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>5 o9 Z6 L* W& Y0 _: X' b
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ , J) F( _# }/ T/ R: L! A
for (loop=0;loop<ENTRIES;++LOOP) 8 v# k6 k" H9 w$ J
{
0 N7 ]) l  B, ^. V7 `& Jprintf("Entry %d\n", loop);
  y$ e0 U0 r$ ^& V9 P7 ^printf(" Name : ");
% e2 U, s+ D1 C. Mscanf("%[A-Za-z]", entry[loop].name);
, L( L$ i* p  l6 V: Qfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
9 z# K/ o0 M6 K7 {<P><FONT color=#0000ff>/* input an age as an integer */
( P' t8 D/ D& U8 l( h3 r; `# pprintf(" Age : ");
8 r+ b% N, Q7 W, o% `1 ^  {scanf("%d", &amp;entry[loop].age);
. _! a" T5 g% G$ i" V, J4 D# S# U% Vfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>' C1 q6 m1 S& \" G# \% V
<P><FONT color=#0000ff>/* input a salary as a float */
7 K7 N5 [0 w+ m% u$ J( ~, Rprintf(" Salary : ");
$ a: T9 l9 C# ?+ rscanf("%f", &amp;entry[loop].salary); 4 Y7 \& }  |8 g4 ?( m- u5 ]
fflush(stdin); /* flush the input stream in case of bad input */ ' A- [* [; w2 ^- N' T
} </FONT></P>; x4 b9 h/ I3 [: M7 @' [1 j  N( N; f
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
2 ?$ m0 p2 z0 [printf("\nPlease enter your name, age and salary\n");
' V) c+ t+ A1 {: Cscanf("%20s %d %lf", name, &amp;age, &amp;salary);
% c4 g9 D6 v  H! m</FONT></P>1 h3 @5 x$ @. n: j1 T1 z
<P><FONT color=#0000ff>/* Print out the data that was input */ 4 [; E+ u! s# L$ p
printf("\n\nTable %s\n",label); 3 Q# B& e/ Y9 I. O5 x% K
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
: n& V; {" |- s% N5 Q" w9 Fprintf("-----------------------------------------------------\n"); : z8 D/ K  ?2 ]0 {
for (loop=0;loop<ENTRIES;++LOOP) 8 n. j4 C' r. Z! f+ D
printf("%4d | %-20s | %5d | %15.2lf\n", ; E. S+ k+ I4 |# p5 P
loop + 1,
9 b; W7 I, d* J) s% x/ v5 ?7 A# Jentry[loop].name, - P! g% Z) \# \. b" K& g' f2 J
entry[loop].age,
* ?9 ]  Q4 P% W3 Mentry[loop].salary); ; v. }1 L- A4 T7 O$ a
printf("-----------------------------------------------------\n");
' b& d0 y% x  `3 p3 @return 0;
4 d" I+ R& x# {; Q: x} ! I: b3 Z# R  o5 [# z1 F
6 ]5 ?( ^+ n( d! I+ |4 C; v5 M
</FONT></P>
) L- e4 w! [0 i# t* q& o<P><FONT color=#ff0000>函数名: stat </FONT>
( O" q" ~; _0 x( q4 `3 w% \功 能: 读取打开文件信息 0 N7 c* _. S1 w( P& v
用 法: int stat(char *pathname, struct stat *buff); 5 R* x+ w5 c3 f" R8 ?/ ^' e1 Z" x
程序例: </P>3 V2 m" s0 Z$ g
<P><FONT color=#0000ff>#include <SYS\STAT.H>; v  M5 B& c1 d: O# R5 l. R, L
#include <STDIO.H>5 {) p$ J; O& r; ?' H' e
#include <TIME.H></FONT></P>& k- N  |" A, `$ C: B
<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
( t& \9 L5 {  R4 s+ ?2 c<P><FONT color=#0000ff>int main(void) : q. \! N! h( d; E% ]: h, T$ l+ o" Y2 p
{
; w7 d% M4 o7 W% xstruct stat statbuf;
  `1 Z: C$ |; X. @FILE *stream; </FONT></P>
6 {+ z( d( b, }<P><FONT color=#0000ff>/* open a file for update */
1 L! t$ Z+ j4 I. |% q) W3 u. _if ((stream = fopen(FILENAME, "w+")) == NULL)
; S6 b1 y+ {5 x( [" m. [( h  C{
3 T  x; c- M# H' t& f. X1 @- sfprintf(stderr, "Cannot open output file.\n"); ( t9 t1 U! \3 ^; f9 [" }+ I3 y
return(1);
/ P) T' O) s; A* y8 j: c9 o: A} </FONT></P>
  c9 z: W& [/ k<P><FONT color=#0000ff>/* get information about the file */
' |! r, P' T0 A: }stat(FILENAME, &amp;statbuf); </FONT></P>5 U5 r. \, C0 t: n" C/ `' u: W' `
<P><FONT color=#0000ff>fclose(stream); </FONT></P>( q7 [( J; f; O5 R$ y
<P><FONT color=#0000ff>/* display the information returned */ & I: P9 g4 m  d' d3 ^- T
if (statbuf.st_mode &amp; S_IFCHR)
* Y' ?6 _' b  [+ z  G" Zprintf("Handle refers to a device.\n"); / B8 x# Y4 ^2 o9 z/ F- }2 X- \
if (statbuf.st_mode &amp; S_IFREG) 5 `& T2 k: ?8 N' A
printf("Handle refers to an ordinary file.\n"); . A  F: v7 ]8 E) E4 C1 J; G5 j
if (statbuf.st_mode &amp; S_IREAD)
) N7 g. y+ S' g' b! D7 I( m" T" J& jprintf("User has read permission on file.\n");
, h. W# |$ U* B6 d* A! j4 fif (statbuf.st_mode &amp; S_IWRITE)
1 V4 C# |3 j+ C6 H* k  sprintf("User has write permission on file.\n"); </FONT></P># x% L" S/ K8 T5 c; q
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
4 k+ u7 j2 n; y5 v9 W$ sprintf("Size of file in bytes: %ld\n", statbuf.st_size);
2 `" j& L* ]0 L: |9 o# Lprintf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
: V" U7 P2 o' s. U  Y' Z2 v4 O5 \. Treturn 0;
: N" H9 u5 P$ m4 f}
+ k# o, m' M" G7 \: l- w1 }0 u' C3 \
</FONT>  m& l4 ~  _9 w8 J( h6 Y; K
</P>
4 X/ o( f/ Q, u& Q* g; P9 D+ E<P><FONT color=#ff0000>函数名: _status87 </FONT>" {: E! [9 d- X) `4 E
功 能: 取浮点状态 1 ^* R6 I/ F- O7 J! k8 F' ?
用 法: unsigned int _status87(void); 1 X9 a/ k$ D% |, o
程序例: </P>, m& H3 f; \: ]4 o
<P><FONT color=#0000ff>#include <STDIO.H>; B  Z% e- S+ ^6 x: R
#include <FLOAT.H></FONT></P>
2 Q6 J4 m. ?) F/ M* f, B# h; J' C<P><FONT color=#0000ff>int main(void) - K' J* F( h0 l8 g. j
{
% J. c3 T* [5 G. E# [% N9 _% j. `float x; 9 y2 z9 B  g2 ^$ G
double y = 1.5e-100; </FONT></P>
; U4 {$ u  a4 g1 H<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>3 D  X  E' S% w( F, r' N, B% D
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */ / a6 q0 F. }% c+ g
y = x; </FONT></P>, p' M5 @' d5 ~( O
<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
( [: ?* j0 ~5 G8 M- rreturn 0;
6 J* R( U$ v$ W$ j; Y7 I/ e}
4 x1 H+ J9 C% t) j/ @+ w4 }2 j8 {</FONT>( o1 }1 |: v8 b, r! T5 r
</P>( b) i+ u4 ]7 t2 _$ _+ V
<P><FONT color=#ff0000>函数名: stime </FONT>
: F1 T3 s) ]4 A% U) x& F功 能: 设置时间
9 K/ Q; |% p+ E/ ^5 I+ e  K1 Z5 L用 法: int stime(long *tp);
2 W# L! j/ G3 j7 S1 ~( a程序例: </P>
8 V7 L8 P, A4 m+ k7 j% @% `+ O6 k<P><FONT color=#0000ff>#include <STDIO.H>
' ^, i9 @& ]1 A#include <TIME.H>
0 S* J' D6 p( Z" Y5 o#include <DOS.H></FONT></P>4 Q3 _: ]5 M' j
<P><FONT color=#0000ff>int main(void)   N. |* ^" n8 f
{
  o4 u) [* H7 l" l6 dtime_t t; : u7 k- e+ f+ L1 p
struct tm *area; </FONT></P>
1 C8 D6 k: I  ~: b! i3 B<P><FONT color=#0000ff>t = time(NULL);
! B, a% h7 x. ]1 H- f5 Larea = localtime(&amp;t);
# K% \& p" h& m, e( h( ^printf("Number of seconds since 1/1/1970 is: %ld\n", t); $ ~$ _9 J3 {& _
printf("Local time is: %s", asctime(area)); </FONT></P>% J% D4 v' m8 o
<P><FONT color=#0000ff>t++;
* h, ?/ X, G/ C/ K4 Karea = localtime(&amp;t); 7 w( d; W. K& G, M, M  \; i# }+ ~
printf("Add a second: %s", asctime(area)); </FONT></P>1 s3 l5 H' z' k/ X+ C# [/ W
<P><FONT color=#0000ff>t += 60; . T' X6 m; q. k/ i1 F) I" X
area = localtime(&amp;t);
; a9 r) P1 l; _- A9 rprintf("Add a minute: %s", asctime(area)); </FONT></P>) G! _3 A& B" _* z/ z- o$ n
<P><FONT color=#0000ff>t += 3600; 9 T8 z0 K$ U, d
area = localtime(&amp;t); 8 w8 ^1 p# k& [7 J" Q0 A
printf("Add an hour: %s", asctime(area)); </FONT></P>% N( v7 E9 n" w0 f6 w- |2 b' c
<P><FONT color=#0000ff>t += 86400L; ; F- l4 O: ~/ w$ F
area = localtime(&amp;t);
$ _$ C( ~; e  n+ ^$ h& z: Oprintf("Add a day: %s", asctime(area)); </FONT></P>; {, Z" n$ m" T' K) C8 [% r
<P><FONT color=#0000ff>t += 2592000L;
' a; X, B0 m* a6 C+ W' Y8 Darea = localtime(&amp;t); % c; r5 }  w+ @$ j* g4 W8 ^
printf("Add a month: %s", asctime(area)); </FONT></P>
1 {3 t0 n/ F$ U  j<P><FONT color=#0000ff>t += 31536000L;
2 R- R" Q  L6 n+ q5 G7 Narea = localtime(&amp;t);
' I0 w+ r2 {3 n# tprintf("Add a year: %s", asctime(area)); ) ~- Z9 i0 j& v: W, \. D8 S
return 0;
% g6 q( ?: d6 S' b# j" |4 P( G1 S} </FONT>
+ i+ Z: A+ g2 {* M9 X- E" H7 S& q& f2 j, I. \

7 ^. f# |( F' X</P>
  j! n$ k( y7 A; B<P><FONT color=#ff0000>函数名: stpcpy </FONT>
& [* P3 d) G4 g+ ~/ f功 能: 拷贝一个字符串到另一个
/ q. k+ ?7 X( s/ p& u7 X8 c* a0 a& T用 法: char *stpcpy(char *destin, char *source);
, A- Y7 N& I1 W9 y程序例: </P>
, F3 X& T! S3 I9 q<P><FONT color=#0000ff>#include <STDIO.H>
8 n% Q. J  r% W  O* c9 S#include <STRING.H></FONT></P>$ m3 q! |/ |. v, V3 F& I
<P><FONT color=#0000ff>int main(void)
, Y) j: v* t  i3 [- W{
/ m- T, r9 P0 |char string[10]; ) i8 ?/ u0 a' v6 c, w1 q' P' P
char *str1 = "abcdefghi"; </FONT></P># v( t* r! A; Z3 k
<P><FONT color=#0000ff>stpcpy(string, str1); 0 \5 E; E9 A& Y
printf("%s\n", string); * N1 p# D1 ?: E$ w6 k+ M+ N! s% f
return 0; 4 X8 d, ~  |& s5 K4 M$ t
}
4 \; d& x" ^# x$ b
' w' `4 v/ v' Y: w</FONT>
- I* a3 Z9 P/ Q7 N1 O7 [/ X+ H" W1 v* X</P>. |+ B. d/ Q7 [% i' Y
<P><FONT color=#ff0000>函数名: strcat </FONT>
* ?0 \% Q2 U6 s功 能: 字符串拼接函数 ) K- w4 G; T) U5 g; d# E6 J1 Z" l
用 法: char *strcat(char *destin, char *source);
& G3 P" p6 z* M4 ^4 r5 s程序例: </P>9 {/ S: U! O7 i; l  R( [
<P><FONT color=#0000ff>#include <STRING.H>8 C1 P  v8 F. S  o9 G3 K  s) T# {: q
#include <STDIO.H></FONT></P>
- M* X6 T& @* ~4 L, c( v( G3 b<P><FONT color=#0000ff>int main(void)
5 W& f. q3 u1 q& ?: U. _, g{ + z4 l* g7 N0 d+ m% p/ {
char destination[25];
7 f1 J2 p/ O$ `. V0 xchar *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>0 b4 _& D+ ]" u2 ?" {& S
<P><FONT color=#0000ff>strcpy(destination, Borland);
8 u1 b5 L; Q- w. p, u3 ]4 Gstrcat(destination, blank); 3 f& U0 s! \* r0 S( P9 Q; {
strcat(destination, c); </FONT></P>
' K: [7 x# r- x- D9 M, q<P><FONT color=#0000ff>printf("%s\n", destination); 0 T  a+ r8 P; }
return 0; / b6 A; w' u8 B9 q2 p. ~9 m
}
' F# _; T- E( B: [2 C+ N) l( x: `5 w5 ?) e, R( h
</FONT><FONT color=#ff0000>
- b+ q# g/ ?: A4 B9 Y0 N! x: G+ g</FONT></P>' d7 t2 m; _" P/ ]( D' D; _( S
<P><FONT color=#ff0000>函数名: strchr </FONT>
, m# e! |0 U. |: a2 M8 {0 h功 能: 在一个串中查找给定字符的第一个匹配之处\
6 X) ?7 Y: K& [! Z/ w用 法: char *strchr(char *str, char c); & ^- ^( n9 `5 V1 ^
程序例: </P>- G$ {' E% [' Y8 ]" G) Z( g$ A+ x
<P><FONT color=#0000ff>#include <STRING.H>4 Z" v* m( B* Y8 {
#include <STDIO.H></FONT></P>
$ |8 j! m1 Q& M! z7 M) e9 ?! b<P><FONT color=#0000ff>int main(void)
9 Y/ i) Z8 V# c{ ) I6 w, C( W' ^! R, [! t
char string[15]; ! n( L3 _  h7 ?
char *ptr, c = 'r'; </FONT></P>
$ \8 c  e+ }! n4 U0 S, g6 O<P><FONT color=#0000ff>strcpy(string, "This is a string");
+ A. A% o2 v. I$ r# qptr = strchr(string, c);
4 M2 Z5 p  X5 L- ?8 c/ Kif (ptr) 1 f$ @; L$ g0 Y) b
printf("The character %c is at position: %d\n", c, ptr-string); ' c4 n9 i; K% B- t# k( X/ t7 P* E
else 1 F4 h  M; m1 S1 s
printf("The character was not found\n");
. p( u9 m5 Y! L) o: nreturn 0; % I- a- B' l6 ^4 t
}
! L+ ~, T6 k, m7 A0 z) ?/ c</FONT>
6 g. i5 @$ a2 Z8 o1 S& F1 D3 ?. }/ a1 m  ~9 r4 c
</P>
# c% M' e6 e7 E8 v; E<P><FONT color=#ff0000>函数名: strcmp</FONT> 0 ^! G, o9 Z7 c4 `
功 能: 串比较 ' t$ F: t1 N5 C. `- {1 C  j9 g) s
用 法: int strcmp(char *str1, char *str2);
$ A$ w! b9 e# n# d+ G: a7 A程序例: </P>
/ k. O8 Q6 u+ p/ e' |% I" U7 R) k4 a<P><FONT color=#0000ff>#include <STRING.H>
, z$ }& D/ I" h/ H. x, b#include <STDIO.H></FONT></P>% u, \1 H  X2 u  |9 b/ H
<P><FONT color=#0000ff>int main(void) # I# d7 L( X, I( l9 e# ?
{ " L! H  d$ t& s# N# }7 m% m: q
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; , i3 m  F; r) y" e! Z
int ptr; </FONT></P>6 M: ?5 z7 o. X" j; B7 j9 v
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1); 6 C5 L: \5 o0 Z/ q1 o/ ~
if (ptr &gt; 0) 0 J7 ~8 M( `- s3 Z( h1 t
printf("buffer 2 is greater than buffer 1\n");
) F2 \3 B0 u+ ^$ |- A- m! Welse $ m7 O: E* i4 p% m: K
printf("buffer 2 is less than buffer 1\n"); </FONT></P>' \( Z$ C) a! w- F1 |) p4 w
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
' Z/ g* j6 [0 O" k2 eif (ptr &gt; 0) 3 W) g4 b) n$ E( d' x
printf("buffer 2 is greater than buffer 3\n"); & i# }2 v9 V/ Z/ m- T
else
  Y; |/ o9 ?2 T7 r% a" [( i7 Bprintf("buffer 2 is less than buffer 3\n"); </FONT></P>
- @$ T! s+ @" y* q, J7 b, N<P><FONT color=#0000ff>return 0; % [; f" H. x! Q  M: p# R
}
+ }+ I6 v0 e- y
, p6 z* f  O3 R1 C$ @8 ^) H
* P2 w" @0 _3 @. J</FONT></P>
6 w6 Z- {, c5 }$ V<P><FONT color=#ff0000>函数名: strncmpi </FONT>. U4 H: R% x! O9 d& w4 C# O+ `
功 能: 将一个串中的一部分与另一个串比较, 不管大小写 + z0 [) S  B: j0 \! j* L
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); 4 D5 @3 l9 f: `# b; W/ @) {: w: ]
程序例: </P>
* g. D" `5 w, [<P><FONT color=#0000ff>#include <STRING.H>
8 \# e4 b( r1 ]. v4 s8 |3 b#include <STDIO.H></FONT></P>
" [8 b' V" V5 L0 s  f( K* p8 J<P><FONT color=#0000ff>int main(void) % _: P$ c1 k" v; H
{ 9 F" A0 U3 [6 D; Z1 D
char *buf1 = "BBB", *buf2 = "bbb";
" d" v& p* O. bint ptr; </FONT></P>( y- z/ e9 T/ H* f  ]- ]' W
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>$ v4 x/ @% i+ |' L1 S' F" d( M9 T
<P><FONT color=#0000ff>if (ptr &gt; 0) ( J1 S) n, [5 h% b! [/ T2 }+ J; X
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>4 X$ p  j0 y' P) v- H% {0 C
<P><FONT color=#0000ff>if (ptr &lt; 0)
- c4 |+ P, R; yprintf("buffer 2 is less than buffer 1\n"); </FONT></P>1 N- V6 v; Y* \  J  }" z
<P><FONT color=#0000ff>if (ptr == 0) - w3 O! G' X+ q* g: `. {% u: a
printf("buffer 2 equals buffer 1\n"); </FONT></P>: i: v% U' ?( A) z- i) f
<P><FONT color=#0000ff>return 0;
# \5 x! O* X3 {' k} 5 ~/ n% }0 X  V
4 P; q# }3 h9 ^& U+ [2 F, N7 A6 w
</FONT>
/ I- R1 y6 h' D( m7 j& O6 \8 c  ?</P>
- L3 s4 N/ |3 i* d- d2 d4 Y<P><FONT color=#ff0000>函数名: strcpy </FONT>
  a$ `; t+ Z2 \' D7 C1 ?0 X+ X功 能: 串拷贝
% v; R0 D, F/ e  D- Z8 J& x用 法: char *strcpy(char *str1, char *str2);
3 `. g% H" g3 Y& ^: N! a程序例: </P>
8 @+ Z/ b1 e$ U<P><FONT color=#0000ff>#include <STDIO.H>- [/ `  p* ~5 v6 j' Z" I( C
#include <STRING.H></FONT></P>
& G  \; A& w- u9 c+ M<P><FONT color=#0000ff>int main(void)
) _9 H% s0 b& s: a{
+ {+ D; |; a& d2 t& j0 L& Z" l3 jchar string[10]; $ u0 j! ~4 E, M% u
char *str1 = "abcdefghi"; </FONT></P>
9 P( W+ O0 F6 B<P><FONT color=#0000ff>strcpy(string, str1); : \- v! K/ S0 U' F' A
printf("%s\n", string); - U9 w! {5 e0 a- ~; U2 g1 o
return 0;
6 @! O  ^) f6 z- z" q. W! x  Z} ! H! n9 m! o  r5 _  W7 r  q; y
</FONT>
, F6 [4 R1 W) V1 s6 J+ I4 ^8 e$ i) d1 ^& ?; p
</P>
7 V! H- b( H6 H; Y4 @" }" j% [6 h<P><FONT color=#ff0000>函数名: strcspn </FONT>
* F+ L8 S: h; L5 [3 ^& U功 能: 在串中查找第一个给定字符集内容的段
' `( p3 X, _% T. _2 Q( O( V. i用 法: int strcspn(char *str1, char *str2);
6 e6 V) M: q5 ], x6 N程序例: </P>
* i, H3 K0 u" K- C/ J  a<P><FONT color=#0000ff>#include <STDIO.H>
# R# }: `. }8 b6 {! ^#include <STRING.H>
4 T  S9 K2 P3 B# W#include <ALLOC.H></FONT></P>2 B/ h% \& O6 @8 A
<P><FONT color=#0000ff>int main(void) $ N# z1 a& y5 M/ L. h
{ ( `- e7 {5 P" {& L( r9 {- x
char *string1 = "1234567890";
8 v3 k0 w; Y" i5 _char *string2 = "747DC8"; 1 j, q* H# r. }; W
int length; </FONT></P>* h' ?! w0 `3 L% n9 }2 d5 q
<P><FONT color=#0000ff>length = strcspn(string1, string2);
/ X; t$ Y) S' Mprintf("Character where strings intersect is at position %d\n", length); </FONT></P>
0 P# M4 P- |# O- ^' q<P><FONT color=#0000ff>return 0; 5 J5 n$ @) \# h: z
} 5 B, P1 g9 q8 L4 b4 w1 v
</FONT>1 Z2 K1 r8 y% S: {: ^

" W6 M( S+ K1 n6 {- N4 h6 x</P>
# I+ {. \  Z' l1 L<P><FONT color=#ff0000>函数名: strdup </FONT>
# r* U4 [( t+ x! v9 z" F. v" |功 能: 将串拷贝到新建的位置处 : g$ g& C7 e3 K% q0 N" h$ G
用 法: char *strdup(char *str);
/ {* C( P1 b  k% Z3 D4 O1 ?0 W程序例: </P>5 }) O, x& h8 d" w2 X  j1 [7 H4 t! x
<P><FONT color=#0000ff>#include <STDIO.H>
) Q3 s; \) @/ Y: b8 D#include <STRING.H>
" x$ ^+ b. ?8 d2 E, p8 G#include <ALLOC.H></FONT></P>
3 g/ d  i" F5 k( o2 I<P><FONT color=#0000ff>int main(void)
( w- w1 A* R- K{ 8 o8 r, _9 o  \
char *dup_str, *string = "abcde"; </FONT></P>
- A* y, v! r' Z: n<P><FONT color=#0000ff>dup_str = strdup(string);
0 v; H' R8 \6 g  z# i, ~2 kprintf("%s\n", dup_str);
: C+ [# h8 }1 j( G# `& x7 ?free(dup_str); </FONT></P>% p) v2 P- u. q1 z/ S1 l# o1 M
<P><FONT color=#0000ff>return 0; - G7 k+ Y2 d% E/ _9 w
} . \0 ^/ }4 T" F- Q
: t. f9 k) j. F* s8 \7 K
</FONT>
2 Y* _5 F, x) x</P>
  o( N8 T) b8 n8 o) W! Q<P><FONT color=#ff0000>函数名: stricmp </FONT>" f' b7 k. b6 a: c$ Y4 V
功 能: 以大小写不敏感方式比较两个串
  ~4 r5 d6 t7 \6 f6 b用 法: int stricmp(char *str1, char *str2);
% k& X7 q( A; U; o! K程序例: </P>
! k9 n3 ~; _8 ?2 [3 P2 Q/ w  _$ a<P><FONT color=#0000ff>#include <STRING.H>
8 o1 e$ G$ A4 Y$ w- N, B#include <STDIO.H></FONT></P>+ y5 s9 W: b* z& l/ f
<P><FONT color=#0000ff>int main(void)
- ?4 S9 t' Z/ q/ I{ : D% }, _5 U/ h) p
char *buf1 = "BBB", *buf2 = "bbb"; - E: h0 V- j  a4 ~! `3 E: A  s
int ptr; </FONT></P>  V% _) [( s$ \& I- x, i$ j
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>/ n" ^  H% D' n) m, R9 G) }; y' v
<P><FONT color=#0000ff>if (ptr &gt; 0) 8 V: @: N# _3 j0 U8 J0 V5 _
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
0 B4 Z$ [% U9 U) t# {! X* v<P><FONT color=#0000ff>if (ptr &lt; 0) - A) ?& @. ^+ ]/ [
printf("buffer 2 is less than buffer 1\n"); </FONT></P>4 l, q: \8 j1 a! ~: R
<P><FONT color=#0000ff>if (ptr == 0)
, j  {: X$ R# O3 |printf("buffer 2 equals buffer 1\n"); </FONT></P>  a  v7 i8 ^% E
<P><FONT color=#0000ff>return 0; $ U9 B' w/ a3 z/ f+ _( F% |
}
& T! _, f% c& ^1 w  D/ d9 P</FONT>: g: N3 o% Q1 X
</P>5 V3 J: T8 f: z  w) @/ N2 [- d! f
<P><FONT color=#ff0000>函数名: strerror </FONT>
$ E9 S2 W1 @7 B( c6 c" I& u功 能: 返回指向错误信息字符串的指针 . m+ }( m; M! I' W" z" h$ E! Q
用 法: char *strerror(int errnum);
; P* }  B, A( N$ N0 ^& F程序例: </P>: H6 I/ Q) V% q' }
<P><FONT color=#0000ff>#include <STDIO.H>
+ \3 C1 U0 d3 A) l#include <ERRNO.H></FONT></P>8 t! W2 R, ^6 m2 Z) ~. i
<P><FONT color=#0000ff>int main(void)
' G& J/ D" E$ z# m: y# a" ^{
$ J+ F1 W: T2 I; w6 U- Xchar *buffer;
$ g- H! o- ?6 ]0 G+ _- S) Cbuffer = strerror(errno);
) f" q* `, I, W0 a! ^printf("Error: %s\n", buffer);
. P0 m3 m' H1 }return 0; + k, h' S% X% c, v
}
. z/ ?, y, h. k& y' ~! a) z1 g4 @
</FONT>. v% K2 P2 e3 K, n; u/ j
</P>
/ O+ U8 \, o# T# |( ~<P><FONT color=#ff0000>函数名: strcmpi </FONT>% j2 K/ q; ?8 f7 M% ~
功 能: 将一个串与另一个比较, 不管大小写 7 D* A$ @  G( k0 L! I3 _
用 法: int strcmpi(char *str1, char *str2);
3 h4 a# P4 l8 S! d* U1 o9 Y程序例: </P>
' @; z5 Y7 n0 V<P><FONT color=#0000ff>#include <STRING.H>2 P) Y3 H0 O4 |. S
#include <STDIO.H></FONT></P>
% c( ?: O) P8 H+ ~9 k& k<P><FONT color=#0000ff>int main(void) - n( L1 W% T6 z4 }) c1 A; ]
{ * k5 q' E; u1 n) m! |
char *buf1 = "BBB", *buf2 = "bbb";
( b7 i! l1 ~" W: iint ptr; </FONT></P>& u) H! L, ^0 q" C
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>7 \6 {5 r* I$ o- m
<P><FONT color=#0000ff>if (ptr &gt; 0) : D2 s0 j  ]' q% k3 G7 \
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>! r" t: C" f. H& [# P
<P><FONT color=#0000ff>if (ptr &lt; 0) ! z/ q" l# S; i  E
printf("buffer 2 is less than buffer 1\n"); </FONT></P>- z1 m1 `3 N, b8 q  ~. {
<P><FONT color=#0000ff>if (ptr == 0) ( D% J' {/ H/ U' g  ]' F+ f
printf("buffer 2 equals buffer 1\n"); </FONT></P>
( F) r/ t) R9 i4 `5 @" x<P><FONT color=#0000ff>return 0;
( y  o# P* E: {  c, N}
3 g" b& ^( m+ ]</FONT>
+ I' M$ w2 Z# q" \( A' }8 i
0 n( I$ d9 S2 C</P>
0 \, Q- }7 s7 y$ Q9 L( J( e<P><FONT color=#ff0000>函数名: strncmp </FONT>: l- w; G5 M0 f/ X6 R
功 能: 串比较
7 W. z4 @! z  B用 法: int strncmp(char *str1, char *str2, int maxlen);   C! ^4 T! x5 Q8 D& f5 u: F# y
程序例: </P>
6 e+ r: A. J) ?; y; Y2 [" s0 `2 Y<P><FONT color=#0000ff>#include <STRING.H>) J' @4 B; C( e- P( {
#include <STDIO.H></FONT></P>
+ w' w' d5 B. i3 w<P><FONT color=#0000ff>int main(void) </FONT></P>
5 ~; V1 P5 j7 z  x' a( u, J( o<P><FONT color=#0000ff>{   f# w2 B' N. m+ g6 o
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
9 B/ P. z- D' i5 cint ptr; </FONT></P>. [$ X1 L& F, m+ l2 |
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
* o- c! i5 q% ~if (ptr &gt; 0)
' j6 t  f0 H/ \5 N9 [printf("buffer 2 is greater than buffer 1\n");
0 {' I% _( f2 _" v" d: Pelse ( v# Q& m' Q2 z( d8 B
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
$ `1 v% A, ]3 U- z6 j' |4 w<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3); $ I  a& G0 G# M
if (ptr &gt; 0) 2 Y- h& j9 h  J5 ~: z* v1 C/ Y
printf("buffer 2 is greater than buffer 3\n"); $ |3 y8 Q. G( I, _! D
else
, J( s+ Q% ^  x8 e; J( I8 vprintf("buffer 2 is less than buffer 3\n"); </FONT></P>6 z! ^/ L' r& h& o% G
<P><FONT color=#0000ff>return(0);
) }3 W! F. G, O+ o7 X! g} - C! M: ]& T/ p4 |
8 \) d6 a% w1 g! e! [
</FONT></P>
6 R) |! r7 u8 _$ ]* E$ ]  S<P><FONT color=#ff0000>函数名: strncmpi </FONT>+ o$ L. H9 h  _
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
) ~+ q3 x- |5 L. w; Y2 I4 X0 K# j用 法: int strncmpi(char *str1, char *str2); 8 o5 l, [; k/ l
程序例: </P>1 Q+ U, ?7 a- E3 V3 c; {
<P><FONT color=#0000ff>#include <STRING.H>
" ]$ d8 A! c4 T2 W+ M#include <STDIO.H></FONT></P>4 ?4 J& N1 E( G
<P><FONT color=#0000ff>int main(void) / @( ^, N* {2 E6 ]% x( }
{ 7 W. w% l& o3 \4 s7 b/ w) ?
char *buf1 = "BBBccc", *buf2 = "bbbccc";
" q7 O4 g. w4 Z+ S7 ^* Cint ptr; </FONT></P>
( i8 [5 B9 P: X8 R! m<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>" O, _) X7 j5 F. J3 A5 @& p* N- P
<P><FONT color=#0000ff>if (ptr &gt; 0) 5 }5 i5 N7 Q( H/ ^" X) N- m
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
* |0 f9 t; A  ^' u% S<P><FONT color=#0000ff>if (ptr &lt; 0)
( [) j7 x( b3 o8 U% r! W/ _% Hprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
; O! C. X$ C( ]( v<P><FONT color=#0000ff>if (ptr == 0) 4 V/ [% @( n1 ]/ U
printf("buffer 2 equals buffer 1\n"); </FONT></P>; E* ]" ^3 j) \' F* ~7 n: {5 K
<P><FONT color=#0000ff>return 0; </FONT>
- T& z- b! L! p& q' Y1 e8 e}
# F: o4 R* i9 x
) g) B4 o" g1 Z2 X; O; o& }; {</P>
  h8 Q$ o) G& h8 a3 u$ u<P><FONT color=#ff0000>函数名: strncpy </FONT>" }4 T+ ]9 N0 h" h: ?- p
功 能: 串拷贝
. F8 `7 B9 i# Z( x- s用 法: char *strncpy(char *destin, char *source, int maxlen);
0 d* J* M8 _7 Y* [0 e" w& j. c* a9 f程序例: </P>
! ]3 f2 m6 E" g& K8 [$ w0 n<P><FONT color=#0000ff>#include <STDIO.H>
, S/ f2 X) \$ r1 B" r- O#include <STRING.H></FONT></P>6 E5 P/ h1 f: V& q- k6 @
<P><FONT color=#0000ff>int main(void) + q0 T9 J5 R, W3 V1 k
{
( S$ k; R7 h, e( ?, j- A# M) cchar string[10];
- e( W) `' |) X- e8 T9 v( d  zchar *str1 = "abcdefghi"; </FONT></P>6 l, o5 s6 `0 w0 O" n7 A6 P1 j3 D
<P><FONT color=#0000ff>strncpy(string, str1, 3); 7 L) Q7 t$ k, h; l8 V1 A. b
string[3] = '\0'; % a" t2 V2 l. T0 U) h
printf("%s\n", string); : e+ I+ U- \. T0 }. U% C. q& \- D1 J
return 0;
" i  W$ z! w# ^' o# K* }} 2 D# V# e9 a- O
</FONT>2 S  h" m, E3 E' A! T: b
</P>1 _+ B  h8 P* H; l: M# V, {$ b
<P><FONT color=#ff0000>函数名: strnicmp </FONT>3 ~; {4 r4 B2 R9 q
功 能: 不注重大小写地比较两个串 ) y3 R5 [, d6 ^4 J; o
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
; w; x. p2 T! W) k* K+ w3 N9 P程序例: </P>
7 e  K, l0 c4 j% i9 b<P><FONT color=#0000ff>#include <STRING.H># E/ x  d3 X8 n. u
#include <STDIO.H></FONT></P>
* m# l  [2 }# d3 d/ J/ M% U- f<P><FONT color=#0000ff>int main(void)
* `: N; k" e3 U3 L9 [, {4 t; U0 _{ 0 N3 {; D2 D8 {& }& M8 K
char *buf1 = "BBBccc", *buf2 = "bbbccc";
( s' a  H, _* J6 z# F! I# ~; E5 Sint ptr; </FONT></P>
% j$ s' X' o+ F6 @<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>- p/ V! F, q' |) H
<P><FONT color=#0000ff>if (ptr &gt; 0)
# E  r  `! u- W/ x* [$ E4 ^+ {printf("buffer 2 is greater than buffer 1\n"); </FONT></P>$ P5 Z- z/ e' A( S
<P><FONT color=#0000ff>if (ptr &lt; 0) # X  P. y$ f2 F1 h
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
  ]7 K7 K+ s8 k5 l8 l* ]; @8 {<P><FONT color=#0000ff>if (ptr == 0) * _0 v# x8 a* f2 P: ~+ _8 @
printf("buffer 2 equals buffer 1\n"); </FONT></P>
  z/ X( e3 \4 W! l<P><FONT color=#0000ff>return 0;   q% \) E7 C" t
}
, L" @2 q: Z, s  \
7 |4 i" z& c8 J3 ~" W</FONT>
+ k' Y7 t2 K5 y</P>+ {5 F, q1 O* `$ F0 b
<P><FONT color=#ff0000>函数名: strnset </FONT>
/ e9 j, E% F/ R6 k0 L功 能: 将一个串中的所有字符都设为指定字符 - }8 [1 o5 F) I& [8 Q6 V8 f
用 法: char *strnset(char *str, char ch, unsigned n); " ]6 `7 P3 J* W: y. J( V
程序例: </P>
+ z( T- L- b( b( m<P><FONT color=#0000ff>#include <STDIO.H>
. ~& A9 r2 F( Q* a0 C" N: u$ o. d#include <STRING.H></FONT></P>* _! ?/ k  t3 o8 Y
<P><FONT color=#0000ff>int main(void) & N7 |2 k/ i, y. D# s  f$ Z/ c
{ 9 ]' x/ [( W9 j3 L' E7 B. O& \2 p
char *string = "abcdefghijklmnopqrstuvwxyz"; : D$ R! G9 |- z  d4 K! A
char letter = 'x'; </FONT></P>! J) D9 R8 y; ~% Y, B' V
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string); % w8 ?/ c  R$ Z! D9 b6 o! f
strnset(string, letter, 13); " |2 Z: ]& S! E; t
printf("string after strnset: %s\n", string); </FONT></P>
3 {6 R% r6 D2 W2 x6 s9 B0 H- y<P><FONT color=#0000ff>return 0;
4 P  T  Q1 C7 v2 ]3 v# U}
* H, r' f( U+ o( k7 O/ Q! b</FONT>
% j% a) d- D8 ~/ ?: h0 i5 I</P>+ W- x  E# P. e1 [
<P><FONT color=#ff0000>函数名: strpbrk </FONT>/ ~) E" x8 A$ }4 e: F8 W: O
功 能: 在串中查找给定字符集中的字符 8 P& C2 u# \! u5 S' i& C
用 法: char *strpbrk(char *str1, char *str2);
4 ]( X& F$ k" |" B  T  Q7 H程序例: </P>) m7 h7 M" f: m
<P><FONT color=#0000ff>#include <STDIO.H>- f4 S0 k! S$ s: J3 p$ _6 m! H
#include <STRING.H></FONT></P>/ ?; E" h1 Y; T9 K
<P><FONT color=#0000ff>int main(void)
* B+ j2 L: Y4 Y: V, N, Q{ 2 q+ T! o  T# B/ b* \% Z0 J! w
char *string1 = "abcdefghijklmnopqrstuvwxyz"; ! E/ E2 u& h# n2 f# o
char *string2 = "onm"; 8 p7 Q' a1 M2 [8 m3 p8 ^7 Y
char *ptr; </FONT></P>
) R% k, u& [, q7 k  i3 b0 I( D<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>- G. N' b/ l; W. l( H8 h( U* ~
<P><FONT color=#0000ff>if (ptr)
3 A' x) B0 x1 q1 d* ]printf("strpbrk found first character: %c\n", *ptr); 1 \9 O$ O! v2 T2 b' P' b5 h
else
8 P% Q  U$ Q/ F3 X/ J0 k# Cprintf("strpbrk didn't find character in set\n"); </FONT></P>
+ [* ]9 ^4 c  a' \<P><FONT color=#0000ff>return 0;
4 `. w& d0 {3 N0 a} 0 k4 ]  p0 P; Q2 L
6 f# ~5 N5 K4 F1 s& Z: J6 c, t
</FONT>
3 P# T, y9 d# D! V</P>
) ^7 t1 ~( ^3 ~! I' T<P><FONT color=#ff0000>函数名: strrchr </FONT>+ G0 L, z& J% Y( L: b
功 能: 在串中查找指定字符的最后一个出现
2 I3 }) V8 V3 ]# r3 L用 法: char *strrchr(char *str, char c);
" Z) A' b) u; F1 C9 H- s% u程序例: </P>
  b5 c6 k% M' n$ [6 h<P><FONT color=#0000ff>#include <STRING.H>
( p( E  O/ |' U#include <STDIO.H></FONT></P>  W. R( w; p- `# |
<P><FONT color=#0000ff>int main(void) 6 W' [) l$ X. D5 S
{ 6 P6 N5 R3 f& X
char string[15];
  D9 W  B+ P" ichar *ptr, c = 'r'; </FONT></P>8 }0 s, U- p! A2 a* l" L3 p+ P% `$ \
<P><FONT color=#0000ff>strcpy(string, "This is a string"); 9 w& A& U, r; V) s4 N) c  `  S
ptr = strrchr(string, c); 6 d9 a$ U6 p! z
if (ptr) ' s# \8 f; ?' |
printf("The character %c is at position: %d\n", c, ptr-string);
# q; u6 }* i2 \else
+ k. N/ L) P: X% Q) Jprintf("The character was not found\n"); : l( G' ]5 a  k0 P
return 0;
3 v# V1 n% j2 P1 l} </FONT>9 X" r, a/ n2 g$ i

/ F: k5 i: o7 x' {7 @4 `1 g
4 f1 V* t- d# G' U# ~; y</P>
1 B3 Y( X( U! E2 k2 A6 L* b<P><FONT color=#ff0000>函数名: strrev </FONT>" _# B& `5 V3 Y& v
功 能: 串倒转
- m2 }+ T" u- C8 P8 j, ~/ z$ H5 _用 法: char *strrev(char *str);
$ V, r7 Y6 M" s+ m程序例: </P>
( N* [7 f5 H* D, E7 `  Y' ^4 r<P><FONT color=#0000ff>#include <STRING.H>
6 J( x) \$ d6 o" l7 J- a- G  J# @#include <STDIO.H></FONT></P>* d* T' Y# e: k; D* R  F
<P><FONT color=#0000ff>int main(void) 6 N9 }: w$ p& m1 r7 g
{
! _) j! Z# e9 \1 j; N! H+ `$ {char *forward = "string"; </FONT></P>
. i- H5 u- m& X: `2 T/ @5 ], U<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
1 w  x4 I, u3 z0 x# L3 }; _strrev(forward);
3 r! b  r9 V# |# Nprintf("After strrev(): %s\n", forward);
: o$ K& f6 L" Z$ Q3 b3 jreturn 0;
: u2 \$ J* g2 H" ^% g} </FONT>: F" P& w5 R3 s/ a2 a2 X
</P>) O2 A: c( N1 C& z  \3 w' u! @
<P><FONT color=#ff0000>函数名: strset </FONT>
2 ^+ m4 W5 b+ M3 w4 B( k4 u功 能: 将一个串中的所有字符都设为指定字符   U' I: {: b$ B) K. T  S; q" }
用 法: char *strset(char *str, char c);
; R4 |/ N% ?0 I2 W3 C: K: _" P程序例: </P>( _/ X+ h1 W" f: f% M) x3 |
<P><FONT color=#0000ff>#include <STDIO.H>
. V& G2 G" D! v: B' `" l% s; h7 @4 W#include <STRING.H></FONT></P>
+ `' g7 t0 M" L<P><FONT color=#0000ff>int main(void) " P4 _. y3 o1 \6 m7 T7 ]6 a
{ 7 ^: ~' }% `9 ^
char string[10] = "123456789"; 7 X3 n- F+ l6 R7 i$ f
char symbol = 'c'; </FONT></P>
4 ~9 @3 b* f$ u+ k7 P, s% w0 z<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
" u& @' k" m* Y! ^. y1 ?& d7 \strset(string, symbol); ; v! O. z& l3 S1 e8 N# `, }- M
printf("After strset(): %s\n", string); ) v# @7 p, Y+ Z
return 0;
* k' x  c, [( H  N1 l}
' s9 ]+ F5 P1 U( p) ~
$ ?% {+ w$ v8 @% b" d. t5 J</FONT>' n0 b3 h* i6 f2 B
</P>8 I5 b$ z% O! I! Q% I2 A
<P><FONT color=#ff0000>函数名: strspn </FONT>4 a& P! i$ o7 E7 s/ N) N3 E
功 能: 在串中查找指定字符集的子集的第一次出现 " _  Y. l: x( w& p+ W$ Z
用 法: int strspn(char *str1, char *str2);
0 C7 E2 H% i" f2 W7 }程序例: </P>
+ P/ _) m! X% o" f<P><FONT color=#0000ff>#include <STDIO.H>
: T  m' x3 I' \1 X+ _/ F#include <STRING.H>
) B/ Q- _* C- n& a6 R! [! L#include <ALLOC.H></FONT></P>
# Q2 Q- g4 ~- h2 w" L: L<P><FONT color=#0000ff>int main(void) ; O& q  \) e! s1 x( l
{
$ Y0 \/ ]' @% V$ k, I( j0 b" vchar *string1 = "1234567890";
) }: Y) x! Z8 m  P( kchar *string2 = "123DC8";
6 q% H3 U7 Q& g! Fint length; </FONT></P>9 o1 L; b* I; T$ p0 m0 L" H
<P><FONT color=#0000ff>length = strspn(string1, string2);
, Z  y4 x8 t  wprintf("Character where strings differ is at position %d\n", length);
5 q  f, s# x! p* R) w5 I, }return 0; ! B1 N6 ^7 K% p7 M  Y
}
$ J' Q+ a8 F& l. [6 y( F</FONT>
5 Q7 }, Z/ x" s" [  W4 n</P>
2 ^6 u) p/ n& v: A<P><FONT color=#ff0000>函数名: strstr </FONT>( j3 X' Q/ {, i% h* u. ]7 A
功 能: 在串中查找指定字符串的第一次出现
: ?; o& d0 j! n用 法: char *strstr(char *str1, char *str2); * w; ?3 ^  F# l& o- Q
程序例: </P>0 @- s$ A7 e* N
<P><FONT color=#0000ff>#include <STDIO.H>
9 X; O6 N  h& Z! a#include <STRING.H></FONT></P>
9 s- v9 u/ @& p- [$ ^4 d<P><FONT color=#0000ff>int main(void) 7 T# U2 l# C& X/ I9 R
{
4 g1 q  i1 f5 p6 q0 p6 b" D4 l# dchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>
( h! B- M' w  J5 y7 @$ X0 n<P><FONT color=#0000ff>ptr = strstr(str1, str2);
$ W, ^% p) g7 M/ @3 W2 l; ~printf("The substring is: %s\n", ptr);
. M" m. e- v0 V7 ureturn 0;
  G' W. R3 p6 e7 g/ }$ Y! P} </FONT>, [" }1 T" o- L3 u% X+ W6 D* m  a/ I2 ~
6 `  a" s( {8 Z- l6 C% F' e3 t0 {
</P>$ a+ W; a3 R9 w, F* b. q: f
<P><FONT color=#ff0000>函数名: strtod </FONT>
7 I( x- \6 [0 I+ K7 H& X功 能: 将字符串转换为double型值
, P- y7 C( |: L用 法: double strtod(char *str, char **endptr); * ]+ l7 B/ X6 A9 a0 e9 s) p
程序例: </P>! u$ n, z" n6 h& r* E
<P><FONT color=#0000ff>#include <STDIO.H>8 L+ p9 q3 i$ B2 g4 A( U
#include <STDLIB.H></FONT></P># `+ U# P; t% X9 z& k. P+ Y/ x
<P><FONT color=#0000ff>int main(void) ( e6 h( ]: g; s& c  C8 M
{
4 m8 j4 a( p8 x0 h" ~1 Pchar input[80], *endptr; 0 Y( n2 _# ]. }! }2 m
double value; </FONT></P>
7 K- `% M% s( P) B<P><FONT color=#0000ff>printf("Enter a floating point number:");
+ ^. \: r  e+ sgets(input); & [2 {( @9 q/ i% J2 \5 F& x
value = strtod(input, &amp;endptr); 9 X; l0 z6 e2 G1 F  Q7 K3 W5 t% F- @8 B
printf("The string is %s the number is %lf\n", input, value); ) }8 n' N; J# n7 H
return 0; - A% h3 h+ F! c+ s+ S
} 3 B4 e0 ~9 t: F$ g, }4 i1 j4 V- X) Q
</FONT>, O% ]& R( z# L7 |! Y" ~' J

, |7 l8 I. C9 }2 `& ~) `8 o; n5 V</P>
/ e" c' a# \6 ~<P><FONT color=#ff0000>函数名: strtok </FONT>/ F: y2 q/ Y* p
功 能: 查找由在第二个串中指定的分界符分隔开的单词
# G' y9 C6 H: j1 a! p用 法: char *strtok(char *str1, char *str2);
  ?" u8 w# Z1 _" w# b程序例: </P>
0 ~( i+ X' `5 q+ A3 c<P><FONT color=#0000ff>#include <STRING.H>' W) b  i+ [) a3 T! y( K" O6 ]
#include <STDIO.H></FONT></P>
/ Y) G( q8 @( a<P><FONT color=#0000ff>int main(void) ( I; E# d6 H, ~& |) _
{
; p9 U5 `# G! E& ?. f' q7 [char input[16] = "abc,d"; & u8 x. O# ?! }& q. N6 {
char *p; </FONT></P>  J0 S0 s$ h6 N- w5 q# P; h& ^
<P><FONT color=#0000ff>/* strtok places a NULL terminator . c; I5 Y$ V" _; V- z
in front of the token, if found */
) Y9 i* H5 H! M' O4 ap = strtok(input, ","); % N- h; F( L1 f0 y9 D1 l$ i
if (p) printf("%s\n", p); </FONT></P>
. k$ H1 s, U3 [: u* k# l0 ^<P><FONT color=#0000ff>/* A second call to strtok using a NULL # |8 U$ i# l- s# c' o
as the first parameter returns a pointer
/ ]4 C+ t9 e9 k/ S8 oto the character following the token */
- @$ ^0 Z( |4 P5 ]1 c* J! J  rp = strtok(NULL, ","); $ b' B1 j$ o! L  g1 ?) i* X
if (p) printf("%s\n", p); % U( t- S# p9 |) N$ b0 x
return 0;
' N' A7 f: |# x* Z7 Q/ E; Y} + L; u& \! w$ c) Z
4 F  T# `& s' u% B+ B/ Y) \. a8 ?

+ [, I+ {, Q9 i5 Q2 @3 x$ r</FONT></P>
7 d: \4 g3 h* v0 _( a/ e<P><FONT color=#ff0000>函数名: strtol </FONT>; Z, X0 h4 S. r( B8 j3 P: Z+ `/ W
功 能: 将串转换为长整数
. o: V) e6 {' |用 法: long strtol(char *str, char **endptr, int base); 4 }2 Z- p% m6 _4 r; C6 C- q
程序例: </P>
7 C$ m) Z& t" h& y<P><FONT color=#0000ff>#include <STDLIB.H>
' h) \9 @; f3 L  D% B( _- c#include <STDIO.H></FONT></P>
/ y& T) h" S& X0 d5 W<P><FONT color=#0000ff>int main(void)
) z; c) ~: u  T& q9 N8 d{ $ ^+ H" m, ?  H! L
char *string = "87654321", *endptr;
" w3 O7 l: R" E+ [: z4 Xlong lnumber; </FONT></P>+ r# _. b0 W8 R# s
<P><FONT color=#0000ff>/* strtol converts string to long integer */ - p' f9 h% I' M5 A# o
lnumber = strtol(string, &amp;endptr, 10); 5 @. @- _, L& }+ j* K
printf("string = %s long = %ld\n", string, lnumber); </FONT></P>
# p5 j$ i( F8 _0 D. C2 T<P><FONT color=#0000ff>return 0;
' g3 I- l  _9 U0 P: ~} </FONT>
% A2 r% j  @8 F" F</P>
3 A( X, i, j# }<P><FONT color=#ff0000>函数名: strupr </FONT>) |0 \- J# ]- r/ o8 T
功 能: 将串中的小写字母转换为大写字母
2 F2 n/ W  g) Y# M# f; N用 法: char *strupr(char *str); 7 ^9 L' H7 u- t" f
程序例: </P>6 J! j6 f7 `% m& ?0 c4 D: M0 d1 `3 \
<P><FONT color=#0000ff>#include <STDIO.H>
/ C! \& M  x, Y3 Z. f#include <STRING.H></FONT></P>- e% S1 \0 k% z7 t) A* ]
<P><FONT color=#0000ff>int main(void)
8 K$ i6 [7 ]8 D{ ) M. N( a  D9 u% G
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
( ?. D! m* T! }<P><FONT color=#0000ff>/* converts string to upper case characters */ + z9 V& F5 X4 E. G. o: s) U6 x
ptr = strupr(string);
* K! l) {) h# k# R) c5 Bprintf("%s\n", ptr); , D& I: F* o6 C
return 0; / w9 }0 f7 v: }4 i0 w% a% I
} & w) j$ B3 B4 a, L4 j
" F2 l" b0 M6 }3 Y, J& g: H
</FONT>0 w& a, k% p3 L$ a4 N. ^) [
</P>
  {* ~* n# `* c<P><FONT color=#ff0000>函数名: swab </FONT>
8 i% l, ]7 E; m1 f功 能: 交换字节 * R) b6 s" n8 F/ ]) }
用 法: void swab (char *from, char *to, int nbytes); 2 E( w" `/ z) y% p3 Q% t- L
程序例: </P>
4 J' v8 m* u- E; g: f, u<P><FONT color=#0000ff>#include <STDLIB.H>6 \! o  ^0 g, f9 V0 F+ z
#include <STDIO.H>
! \; j# r! |3 _* D! Y#include <STRING.H></FONT></P>9 O4 F0 L9 W, `+ `: p1 f; m
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; , S$ r+ Y1 v, U* Z; A1 _
char target[15]; </FONT></P>
+ a  {, R" X& L: i<P><FONT color=#0000ff>int main(void)
/ k- x& x8 }  _* v{ 9 w) _2 r, t" L; b4 C
swab(source, target, strlen(source));
4 q7 @8 ?/ l0 q: B" k2 p: x. dprintf("This is target: %s\n", target);
% u+ n  D8 [! J, x$ Q6 W* areturn 0; & @% ~( O8 j4 ?
} 3 i, w. }$ G7 S. D( Z' c3 k8 G7 @$ ]' G
</FONT>9 o# c- `: r) W

/ K* I4 v; L# A</P>! X! J* W& r- `/ l+ p+ `  D
<P><FONT color=#ff0000>函数名: system </FONT>0 I0 l/ _- F4 F7 B
功 能: 发出一个DOS命令 / L/ @7 h! d+ ~6 Q& w+ m" a: y  d
用 法: int system(char *command);
6 ]0 o  `* Z. V程序例: </P>7 t% j0 M$ d4 F* v' a+ T5 d' ~
<P><FONT color=#0000ff>#include <STDLIB.H>
# T3 l: |- Z; Q$ ~5 X6 A#include <STDIO.H></FONT></P>% d+ z) M: V$ P& T" y3 r5 a
<P><FONT color=#0000ff>int main(void)
; b$ M+ }5 P/ U0 R- M{ ; T* L% q* [6 l- S" N5 o: a0 \! d  W5 i
printf("About to spawn command.com and run a DOS command\n");
$ \( F  r; h' c; s  h. Isystem("dir");
; c; j' A. I1 G: d/ Creturn 0;
5 h( k/ _! |. t2 ]& A1 n} </FONT></P>




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