QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |正序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>$ r, c7 ?( O- X& S
功 能: 改变数据段空间位置 % o! P4 Y( L) K8 j/ `& H2 i
用 法: char *sbrk(int incr);
, \* J) F; J  y$ F& A/ a0 c程序例: </P>
4 |1 S( n* m$ n5 Y3 T7 [9 W& x<><FONT color=#0000ff>#include <STDIO.H>
7 @4 F: d( G. J5 D#include <ALLOC.H></FONT></P>
% l/ f; v# `7 q8 Y<><FONT color=#0000ff>int main(void) & A2 R, z1 R3 X' @6 P
{
& [1 O6 D8 l" z% \# g# e  @" Rprintf("Changing allocation with sbrk()\n");
/ v9 @# L+ G7 t5 I- i- f/ Cprintf("Before sbrk() call: %lu bytes free\n",
$ n+ f$ M% i. E$ F& V/ r(unsigned long) coreleft());
  D( `0 A* @, S) X0 W. j/ Ysbrk(1000); ( X4 O  M1 x2 u. f, s5 \# \
printf(" After sbrk() call: %lu bytes free\n",
% @5 ?8 o/ u+ x3 [" I(unsigned long) coreleft()); " w) Y: V7 \5 `. X  l7 M9 r
return 0; 1 }8 y1 O! M% _- `* Y
}
7 X+ X% \5 C, i# O( g* T  E7 T" [  ?- A% y1 l) B) c* w
</FONT></P>6 c$ F! S7 z" W+ R3 i, m* N9 C
<><FONT color=#ff0000>函数名: scanf </FONT>
& S; y7 B' f5 s% r2 ^功 能: 执行格式化输入 . P* m! `9 s$ \7 z/ n8 V9 t3 d
用 法: int scanf(char *format[,argument,...]);
5 r7 _( R# W  F& \' W8 Y程序例: </P>5 D1 m. s+ k5 U7 X
<><FONT color=#0000ff>#include <STDIO.H>! {' q, _9 |  h: b) J
#include <CONIO.H></FONT></P>
' j) |6 K5 @  s' {/ g<><FONT color=#0000ff>int main(void)
# P' d9 }- X  i) F8 b{
; d! y  F, ?% qchar label[20];
9 c( P0 g) \# t) j+ v4 Bchar name[20];
  p2 Y8 P7 N& {% \. V2 i/ ^: ~) jint entries = 0;
5 P0 E/ |. o, R4 tint loop, age; % e- T7 x9 k; p  o) i
double salary; </FONT></P>  _$ l5 d- c# _3 x" ^
<><FONT color=#0000ff>struct Entry_struct
' [0 o* c7 @' z& F{
( F. P2 c* E9 g6 t) ?; Bchar name[20]; " r: r+ W+ k# ~) ?. t1 u5 ]
int age;
8 y8 t# b! d6 v: @9 N* Xfloat salary;
8 S: O, w# }4 t8 q. E/ \6 w4 y} entry[20]; </FONT></P>0 Y2 I2 ^5 j$ y! L: u5 O/ X6 }
<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ 7 B! n) D' M( U% r5 [8 _
printf("\n\nPlease enter a label for the chart: "); 3 J* c0 _9 A( z3 G
scanf("%20s", label);
$ F, @+ U; W6 f% k. Wfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
2 a4 X1 D# x2 ^. t4 l0 s<><FONT color=#0000ff>/* Input number of entries as an integer */
) N0 u8 D" B. X! Z: Z5 H: s. K  N8 Lprintf("How many entries will there be? (less than 20) ");
  U% b. R- S/ K- u% v6 ~scanf("%d", &amp;entries);
, K2 R( A% Z: }$ P" N: ffflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
0 D; D) {2 k8 U3 H- ~<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ ! v* }( f& a* ]8 Z: U5 |+ y* L
for (loop=0;loop<ENTRIES;++LOOP)
; P5 \/ T; F6 L { ( n: e' Z9 b8 T9 }: P7 |
printf("Entry %d\n", loop); ( V/ p; K5 E# M3 [
printf(" Name : ");
5 ]$ g+ V. i/ I9 p( U5 mscanf("%[A-Za-z]", entry[loop].name);
( ?8 h6 l! }# Efflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
5 Q# \1 n  C) h3 {# ~<><FONT color=#0000ff>/* input an age as an integer */ 5 V0 @5 P% L/ K/ A9 p
printf(" Age : ");
0 T1 ~- Q: O& b& Y! J$ tscanf("%d", &amp;entry[loop].age);
  r2 h  V# [* k2 G* L3 `' lfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
% l- u% _3 Z, r7 {<><FONT color=#0000ff>/* input a salary as a float */
  }  a) `. _4 G; l  t: S0 sprintf(" Salary : ");
$ P& ?$ T2 j4 y9 ~! _$ n& d, dscanf("%f", &amp;entry[loop].salary);
# M0 k3 Y4 b* e9 _3 n! u) ]fflush(stdin); /* flush the input stream in case of bad input */
( e- X; ^" E4 `0 d7 |} </FONT></P>
, F( G- O" k/ G1 k' \<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
' r% Q$ q- u- R. j1 D+ w) O! Uprintf("\nPlease enter your name, age and salary\n");
- X2 t* _# P+ l! Qscanf("%20s %d %lf", name, &amp;age, &amp;salary); 7 E$ [3 s# f! [6 S
</FONT></P>4 N6 M; w. j9 k3 q: O; E: r
<><FONT color=#0000ff>/* Print out the data that was input */
1 e5 I9 i* p! \9 e/ S' o0 M# Sprintf("\n\nTable %s\n",label); # t$ k6 g. @6 w. I- ^0 J
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); 5 \: L: D9 B5 r$ E% G
printf("-----------------------------------------------------\n"); # s" x% ?1 ~- m6 i" g1 _
for (loop=0;loop<ENTRIES;++LOOP)
0 M0 n7 y2 y2 }  k' V7 p printf("%4d | %-20s | %5d | %15.2lf\n", ! N) T9 K" w0 I- o2 M
loop + 1,
: T8 [  B2 {" |" C! yentry[loop].name,
! Y4 L! H) ?0 Yentry[loop].age,
) Q, O# U1 j; V: E. S" p% Y* i/ f8 r/ {entry[loop].salary); 9 d; H! o  `! Y2 u, v- v6 l
printf("-----------------------------------------------------\n");
, P" }; D6 v0 d$ S  R0 `9 Areturn 0; " g/ n" K4 q( X- K
} 0 N, P4 l) I2 g2 c9 V1 x
</FONT>$ j( N2 j9 k4 E# Z" h: {
</P>9 A: J4 `) \' B# d* e
<><FONT color=#ff0000>函数名: searchpath </FONT>
! u( ^* o. C7 U) N0 \! r! g功 能: 搜索DOS路径 0 f' Z6 V, e# X' `
用 法: char *searchpath(char *filename);
. O2 b6 v7 Q! V程序例: </P>
0 C7 b* [* ^1 T* Q7 s3 [9 x- n+ W% f<><FONT color=#0000ff>#include <STDIO.H>; j5 G& j" T2 E+ L$ w
#include <DIR.H></FONT></P>5 B. v; [" K% l: _3 O
<><FONT color=#0000ff>int main(void)
0 s9 V7 U+ Y- C, P; C9 ?7 I3 c{ ( a: e; B. p/ D, t- B
char *p; </FONT></P>6 Q0 j) l% o% }( a1 D$ i: B. m) \0 ~6 f
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
7 K' Q" a2 Y6 b+ L( L( A- B0 r6 Hto the path */ * r' S  T: t/ ?$ q
p = searchpath("TLINK.EXE");
9 C2 L8 e3 d8 P$ gprintf("Search for TLINK.EXE : %s\n", p); </FONT></P>
' ]. \1 y4 w5 K& ]3 e8 B( Z7 K3 J<><FONT color=#0000ff>/* Looks for non-existent file */ " ^8 e- x) Z2 M/ l
p = searchpath("NOTEXIST.FIL");
$ f9 N( {0 j" m6 Zprintf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>% g- K" e' S( E. h7 u5 E$ D7 q
<><FONT color=#0000ff>return 0;
! [' |) u% l' F" h8 b} + }: b0 y  N% }8 R
2 M# J/ D& g+ r4 @* y7 o, w; o' c. L
</FONT></P>% e# a+ U5 j8 v  D
<><FONT color=#ff0000>函数名: sector </FONT>
4 b2 P5 Q) K2 O, Y' x功 能: 画并填充椭圆扇区
+ n7 A4 h8 l( w# v/ w. X3 U3 q用 法: void far sector(int x, int y, int stangle, int endangle);
7 \, ^8 \- U8 h) X6 Y2 o程序例: </P>
9 [$ s$ k+ T8 f* j+ H<><FONT color=#0000ff>#include <GRAPHICS.H>
( {, A; _; N/ T2 d. W( F#include <STDLIB.H>
5 T6 T, C0 |* _, |& w9 n#include <STDIO.H>
) r1 V7 i8 i4 `+ s/ V* S; M#include <CONIO.H></FONT></P>6 X2 K+ Z) c1 ^7 D& \
<><FONT color=#0000ff>int main(void) 4 m1 z2 c' k1 ~& O
{
( }! B6 r3 O4 M: @& X3 Q6 V, g& Y7 T7 B/* request auto detection */
5 j7 {5 b! f" B$ S, uint gdriver = DETECT, gmode, errorcode;
7 j# |' V  C% D6 N  I: Qint midx, midy, i; 2 G: j) a: y) b, `( L, w) L5 p$ v
int stangle = 45, endangle = 135; / `& s' G# k8 x/ l) G2 |
int xrad = 100, yrad = 50; </FONT></P>
: {) M$ r* G4 k& M5 L) G<><FONT color=#0000ff>/* initialize graphics and local variables */
3 I  t: Q% F. W2 Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' f, @2 ~+ x3 b; f- q* _! \( s- A<><FONT color=#0000ff>/* read result of initialization */ 7 Q9 H) v- [, l  s, m  {
errorcode = graphresult();
! T9 z2 Z! D2 }' X: R: Cif (errorcode != grOk) /* an error occurred */
$ s2 y) H7 P' s{ 2 i8 T; s  B0 ?4 Y  w( w7 R
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; e2 v4 u( u, x
printf("ress any key to halt:");
8 K6 l; {0 t8 e5 ~8 J7 ~, N1 K: Hgetch(); 1 d- f# }1 V! V
exit(1); /* terminate with an error code */ * Q2 i4 g! t) _* Z; V
} </FONT></P>
: F% a- H; S: t% ^<><FONT color=#0000ff>midx = getmaxx() / 2;
- t& o' C! h6 n2 }' S! Tmidy = getmaxy() / 2; </FONT></P>
* Y0 }9 h. G4 D, t<><FONT color=#0000ff>/* loop through the fill patterns */ $ Q/ O1 |) Y* ~
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 6 u) M/ S) W9 Q0 d6 s6 b& h- Q
/* set the fill style */
4 g% O: R. q2 j, e) Y: K+ Jsetfillstyle(i, getmaxcolor()); </FONT></P>0 p/ ~( o' x+ t" T# j- b; C
<><FONT color=#0000ff>/* draw the sector slice */ 1 t  p! h$ [  c% B8 _
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>. h+ B3 X; A8 C. T6 G, X
<><FONT color=#0000ff>getch(); / \5 V" r! \& O% j6 Q
} </FONT></P>  O# e* M/ T( P8 A- a) S2 ?, k3 ^
<P><FONT color=#0000ff>/* clean up */
5 |# P, s" ^0 z6 D3 v- `closegraph();
5 W- q9 G$ W# ?3 p5 creturn 0; ' Y- ~# X6 Q$ B8 a0 m+ Z" e
} ! s5 ~6 ?( O8 g5 y6 E
</FONT></P>
$ T: v! m7 X0 X' o8 h<P><FONT color=#ff0000>函数名: segread </FONT>: l5 u3 C- |( D6 o  j
功 能: 读段寄存器值
/ l2 A$ D) g+ g' O& d' r$ s8 J' x0 T用 法: void segread(struct SREGS *segtbl);
; q4 d+ I+ Y3 ?. ]* r5 h程序例: </P>
2 o$ _1 }! ~% R/ a  v! ^<P><FONT color=#0000ff>#include <STDIO.H>
( J; Z, L0 h+ C7 a% B#include <DOS.H></FONT></P>+ v  [8 W. c# v
<P><FONT color=#0000ff>int main(void) ( Y! y& `$ K  j1 H
{
- P+ J1 V* V7 kstruct SREGS segs; </FONT></P>* n6 S$ ~3 V" O
<P><FONT color=#0000ff>segread(&amp;segs);
4 X0 t1 L: P5 i% o- Nprintf("Current segment register settings\n\n");
8 g7 m" d6 i7 v  M! s; fprintf("CS: %X DS: %X\n", segs.cs, segs.ds); " q& H% t# e4 z' ~- d' S+ H' ^% H
printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>1 Q% G7 L0 e6 w1 Z' f0 L& F" S
<P><FONT color=#0000ff>return 0;
( p0 Z7 {4 ?& A9 V} </FONT>
5 j; V9 `2 u- l5 g) L
% @4 I8 r9 k! H' a+ R, I, u. G</P>
, G+ P+ K8 T2 r: g8 n<P><FONT color=#ff0000>函数名: setactivepage </FONT>% w7 h" y  r4 ^% l" o; w% G2 }
功 能: 设置图形输出活动页
" \2 r9 k5 G* i% W7 x( a. z用 法: void far setactivepage(int pagenum);
8 C# u/ x. ^6 R; D! ?程序例: </P>2 i/ C* @6 J0 _# b; Z+ N
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  R  L+ {% z$ ~- G* g7 x. I5 P#include <STDLIB.H>
5 J! x) i4 @$ r8 v  Y#include <STDIO.H>1 e# \- f# f7 Q1 q4 m- U. U5 b
#include <CONIO.H></FONT></P>
8 T- A# S7 F$ \; f6 v" g/ i# G<P><FONT color=#0000ff>int main(void) ' @) x! @* Y5 V! X
{ 5 C  ^- Y# m  l' r
/* select a driver and mode that supports */
$ g0 I) t1 f* @/* multiple pages. */ + k& ]- L5 Z+ ?9 }3 c: U
int gdriver = EGA, gmode = EGAHI, errorcode;
6 S7 ?! \8 H" M1 ]4 g( qint x, y, ht; </FONT></P>
, S8 b- S& h% u9 U2 S  B& A<P><FONT color=#0000ff>/* initialize graphics and local variables */
: m0 P9 z4 \% O5 _8 t5 ]& Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 W3 j5 X2 n9 u& I- _
<P><FONT color=#0000ff>/* read result of initialization */
8 a/ n7 K# Z, _errorcode = graphresult(); / s/ P2 v3 a9 e" j+ z  y# Q
if (errorcode != grOk) /* an error occurred */
4 @, p8 j8 I% K- z- B6 S{ 9 e+ I; x8 ~$ [8 }7 s% h" k$ Z+ q
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % I  q+ w5 r8 m$ }) n
printf("Press any key to halt:");
; @* H/ j2 d+ k+ [$ Wgetch(); 5 N. ]5 ]8 Y) ~# f- E
exit(1); /* terminate with an error code */
; H7 I# z; \5 w} </FONT></P>
: f6 f0 b" q2 n1 H0 D<P><FONT color=#0000ff>x = getmaxx() / 2;
. p) {- v, }) Q, n# H% gy = getmaxy() / 2;
2 m* I% ?% E* G2 r/ y4 W3 pht = textheight("W"); </FONT></P>( b1 t+ F9 Z" G2 A3 O' ~
<P><FONT color=#0000ff>/* select the off screen page for drawing */ : o+ C/ E# Y% g/ ^+ l1 M) Z( p
setactivepage(1); </FONT></P>" W! K+ o, w! k8 g
<P><FONT color=#0000ff>/* draw a line on page #1 */ - e* i. a+ ^  M* H( |
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
& N* q, x1 |9 |6 w; e<P><FONT color=#0000ff>/* output a message on page #1 */ ; s8 T* H3 K6 B% z$ \  K, E& d
settextjustify(CENTER_TEXT, CENTER_TEXT);
: d  b1 O  t# uouttextxy(x, y, "This is page #1:");
+ M) p' l0 V5 X1 @, F* louttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
5 E1 X: f  {( v4 O' @1 D<P><FONT color=#0000ff>/* select drawing to page #0 */ 9 f  i' L+ u# ?
setactivepage(0); </FONT></P>: _4 }0 p; z9 ^+ t; W5 X( S7 s7 S
<P><FONT color=#0000ff>/* output a message on page #0 */
7 f8 ?1 C* Z& d0 c7 ]& I2 ?outtextxy(x, y, "This is page #0.");
, |  h( e) x1 |# {/ d8 \outtextxy(x, y+ht, "Press any key to view page #1:"); 2 x8 D" _: L0 q3 p3 z6 U0 ]+ g
getch(); </FONT></P>
% m! ~, ]- u' b- J' g' R- F<P><FONT color=#0000ff>/* select page #1 as the visible page */
3 m: t5 Y6 T& G2 bsetvisualpage(1); </FONT></P>
4 l% o! l6 E0 W<P><FONT color=#0000ff>/* clean up */ - s. \5 f. ]' J" `
getch(); % \/ b5 m. j( ~1 |5 G( S
closegraph(); ' d, K. p& P/ e6 E
return 0; # W  S5 n: Z+ B2 a
} % V0 n/ |. \+ Q, T" D& V
</FONT>
, J; Q! ~0 p7 T- v$ A  k7 |( i</P>& l) \" F3 O/ @) N
<P><FONT color=#ff0000>函数名: setallpallette </FONT>4 d/ W- v/ V" s6 F
功 能: 按指定方式改变所有的调色板颜色
+ V; Y  p, ~9 b# U, T! G3 e用 法: void far setallpallette(struct palette, far *pallette);
; h/ e; C3 ]$ @( n& g. A2 B程序例: </P>
9 a  x6 d9 W5 `! y: X<P><FONT color=#0000ff>#include <GRAPHICS.H>
) C; T$ c3 x+ E- O  A' g; x/ z1 j#include <STDLIB.H>/ M& `+ A8 Q& `: G. [9 `& U+ t* [
#include <STDIO.H>+ |! x& Z! W' Y& [
#include <CONIO.H></FONT></P>7 k: n. ~/ U5 |  ^; h, H& m2 d
<P><FONT color=#0000ff>int main(void) 6 a& O0 O9 P2 r9 I3 f8 q! y% j
{ 8 _2 R; \2 I6 q0 P& k3 L: O
/* request auto detection */ % {; Z+ }' h5 ?  h( L
int gdriver = DETECT, gmode, errorcode; + B+ \) \/ O2 t- G- v/ J. z
struct palettetype pal; 0 }( n8 }; ^4 o( C* s
int color, maxcolor, ht;
( \* C! x. v1 q4 ]( ?7 Lint y = 10;
! g' [2 k$ J8 w6 R& Q5 Qchar msg[80]; </FONT></P>
! l6 [# |" c. G' M4 P3 c2 s- B, Q, [<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 h$ Q6 z0 T4 _; s3 jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># |  e% Y% c, g( U  k
<P><FONT color=#0000ff>/* read result of initialization */ $ q' v1 d. U% g, i* N" ~6 q, @
errorcode = graphresult();
' l6 P" A, }9 s. qif (errorcode != grOk) /* an error occurred */
! _) F$ W) q( R4 |% a) M{   f, @; x, b0 \& T5 k
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 |+ x/ z6 l; y+ b9 ]/ Vprintf("Press any key to halt:");
( s7 a8 ]  g$ G! e9 h" fgetch();
) \# G' W& d& `" M* y0 Qexit(1); /* terminate with an error code */
, m7 Y$ s! H8 N. I' ^& r. E} </FONT></P>$ V. M% P1 O/ W" h: W4 m' |
<P><FONT color=#0000ff>maxcolor = getmaxcolor(); / ]' z9 c- K6 M* B" I  ~
ht = 2 * textheight("W"); </FONT></P>1 k: _+ R( v. p" H& c, p3 b
<P><FONT color=#0000ff>/* grab a copy of the palette */
9 O3 _5 i# F1 ?3 ygetpalette(&amp;pal); </FONT></P>
1 j" I: s; [# b<P><FONT color=#0000ff>/* display the default palette colors */
1 Z3 q  C3 I1 X2 z1 n  y+ a7 G7 Bfor (color=1; color&lt;=maxcolor; color++)
; V4 o/ F( z& h{
9 d& P& I- X4 o+ M4 gsetcolor(color);
2 ~8 q; `8 U! w8 {( Ksprintf(msg, "Color: %d", color);
; T" B7 e8 z9 C+ c* ~! \+ Qouttextxy(1, y, msg); " A2 O' c  k( h' L& z$ T% k
y += ht;
. j1 H. w" y* W$ `* w0 v6 C} </FONT></P>
. T$ a8 }$ ~3 ~1 ^6 d<P><FONT color=#0000ff>/* wait for a key */ $ h5 J' s% M1 c
getch(); </FONT></P>
' e+ x% }* v' c& d<P><FONT color=#0000ff>/* black out the colors one by one */
# c, H8 D% T0 P. Q. [6 ~/ ?. Dfor (color=1; color&lt;=maxcolor; color++)
, S" B& n7 y! I  V: _+ P" v{ 6 ^$ V7 N( @: ?4 t, F& @
setpalette(color, BLACK); " `5 F5 V: L( l0 v
getch(); & j# X6 C5 ]* H0 Q# E4 a8 b
} </FONT></P>8 K4 O6 W1 c* G% B
<P><FONT color=#0000ff>/* restore the palette colors */
/ C: u" Z; Z5 T4 O0 S( ]setallpalette(&amp;pal); </FONT></P>( V0 w* H! g! @
<P><FONT color=#0000ff>/* clean up */ ' {. c0 J- V! O, y0 b
getch(); ( @: W1 o* I$ _7 K/ v$ [0 @  a
closegraph(); . _' w8 Y+ N) h: e8 Y! e
return 0; 0 E- U  H9 S) V, |& Q
} ! P" _4 l1 P6 ^& G+ f

/ h9 F6 e  E% U</FONT></P>
+ o( X; d! G: c9 R<P><FONT color=#ff0000>函数名: setaspectratio </FONT>1 X2 p3 z$ k$ T# b
功 能: 设置图形纵横比 $ K5 C5 P: @( @$ h8 S+ }8 s
用 法: void far setaspectratio(int xasp, int yasp);
: p! W/ m. s) l/ v程序例: </P>
4 x3 r* A7 O. |- |) O<P><FONT color=#0000ff>#include <GRAPHICS.H>" }! l7 \0 R  g4 e; _5 A; B1 S
#include <STDLIB.H>
- C% x2 l/ C" c1 v#include <STDIO.H>
( `" g/ r7 B# A* c' i, t8 d( c#include <CONIO.H></FONT></P>& d4 u: r* h! D0 K
<P><FONT color=#0000ff>int main(void) # J( [" v1 V' h3 ~
{ 2 Z) w4 _4 y+ z1 u
/* request auto detection */
% d/ O( w" i8 c  L  n& w+ Cint gdriver = DETECT, gmode, errorcode;
: h8 D  D/ b* Q% Z+ m( Wint xasp, yasp, midx, midy; </FONT></P>
2 J9 q0 c- U2 g6 n$ x, V5 D<P><FONT color=#0000ff>/* initialize graphics and local variables */
: E5 U% g, |: t, ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# Y8 q) n" l* [. N! _7 T<P><FONT color=#0000ff>/* read result of initialization */ 3 K. j, }+ I8 y0 u+ }
errorcode = graphresult(); 0 ^  S, |* H% l  R, c9 O. `
if (errorcode != grOk) /* an error occurred */ $ V& H( d* \$ n
{
! I- r# i  u  F1 `5 Fprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 [0 B: I8 Q) H$ \6 k9 E
printf("Press any key to halt:");
( z- a( G% s' ~getch();
! u% X/ g: S, M: g: }4 \. n- _0 Oexit(1); /* terminate with an error code */
% ~0 S/ K4 P2 T# |; @} </FONT></P>' S- o; w" t+ i  V* h4 O
<P><FONT color=#0000ff>midx = getmaxx() / 2;
. V4 Z0 i1 {& E% N$ {  Imidy = getmaxy() / 2; " R2 z. \) R& M4 y
setcolor(getmaxcolor()); </FONT></P>
/ [( ^2 q$ l8 C2 y, i' K<P><FONT color=#0000ff>/* get current aspect ratio settings */
6 n  R$ S4 |  u! L3 C1 Vgetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>; r0 z( [. e  P  z, |# w& W" d6 d
<P><FONT color=#0000ff>/* draw normal circle */ 4 U3 b8 h! p7 h; T
circle(midx, midy, 100); : d/ k! ]4 _7 h1 y2 b& `
getch(); </FONT></P>% v& O4 H3 s" `  M" Q5 A1 r0 Q$ l, N
<P><FONT color=#0000ff>/* claer the screen */ 9 n; z6 `; _% X
cleardevice(); </FONT></P>
, P( ~( j( q: p2 M<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ & {7 r# k8 {9 q4 F
setaspectratio(xasp/2, yasp);
% F3 ~3 z' v: @: ~circle(midx, midy, 100); ( `+ }% R1 J7 t) _  ~9 ^4 V
getch(); </FONT></P>  s3 `# R* `% L$ P7 s
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
: ~% J+ \0 P! E! D" S6 Ccleardevice();
# }  }! [3 r6 R7 Z/ z* Zsetaspectratio(xasp, yasp/2); ' K* [: l' R5 z5 ?( E
circle(midx, midy, 100); </FONT></P>
9 ~7 g5 o5 r: f" |" _( k. i- a: E<P><FONT color=#0000ff>/* clean up */
" `* `/ `1 K+ Bgetch();
- C! Q" ]! V/ Z. [( c/ n( ?closegraph(); 1 q& N4 x: G1 O& T8 a8 W, ?- a6 s
return 0;
! D' n' m* F$ m+ Q  l8 E! `, Y) I! t+ Q}
3 [6 J9 L) p: [& ]# j4 h</FONT>% s+ H6 _3 T1 z8 {, e/ R
</P>3 c( n$ X/ S% H3 N4 G3 [' o$ E0 }
<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
* m# _+ x8 V; V- C* W1 K  t* ^功 能: 用调色板设置当前背景颜色
) K7 P6 F2 _4 r& E用 法: void far setbkcolor(int color); - R8 C% \0 ^7 Z
程序例: </P>8 q- Y% Q9 z" d+ r( ?2 I7 y7 F8 Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; K! k- `3 [" @/ |  Y#include <STDLIB.H>
" n9 C( g! Q$ b/ {6 A#include <STDIO.H>
0 d2 ~% z, A6 Q( y" o7 \#include <CONIO.H></FONT></P>3 s$ c# b7 Y! e9 S" K+ o
<P><FONT color=#0000ff>int main(void)
& u; h7 V) ]7 a# B8 P) {, S. E7 `2 [{
; c8 N* t- [; l- o/ c# l/ N/* select a driver and mode that supports */
: J6 }, G+ _- ?5 Z/* multiple background colors. */
: |1 t- _& L* g2 ?; U) Zint gdriver = EGA, gmode = EGAHI, errorcode;
) h$ J4 n5 t$ [! lint bkcol, maxcolor, x, y;
' I! n: `, d( R/ H4 ~# Ochar msg[80]; </FONT></P>
7 _' I, X: O7 Q. G9 S) M0 t<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 R( x! j# o- Q& r6 E. f) Z
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 _2 D( }, f; {" J0 Q( Z3 m7 m# Y
<P><FONT color=#0000ff>/* read result of initialization */ & q+ a/ U3 f8 h  c; A' I$ F
errorcode = graphresult();
. L6 x: i- v) b8 ?( w0 c( Q7 r. ^' Vif (errorcode != grOk) /* an error occurred */ + R- U& b) U9 k6 D. r0 Z: r
{ ; R+ }; M& v0 j
printf("Graphics error: %s\n", grapherrormsg(errorcode)); " u6 j* i2 [# N- x$ Y# c" D
printf("Press any key to halt:");
* ~* t# p1 k, }8 @getch(); ( U9 M6 Q4 ~4 @& V7 h$ Z! @
exit(1); /* terminate with an error code */
% j0 p7 O9 x" r5 z$ s6 _2 K} </FONT></P>
/ G# ^! c$ s; a, r. i' u) b<P><FONT color=#0000ff>/* maximum color index supported */   x' U7 u$ U$ x6 x. e: f9 @
maxcolor = getmaxcolor(); </FONT></P>
5 ^& U& O4 j, \: c, M4 t9 O1 x<P><FONT color=#0000ff>/* for centering text messages */ & u" I8 r: C/ n. G3 ?& C
settextjustify(CENTER_TEXT, CENTER_TEXT);
0 k  N1 @* q0 {: \, q( Mx = getmaxx() / 2; ( c2 j. |$ f$ C7 P
y = getmaxy() / 2; </FONT></P>) C; l6 I" c! \% L1 }
<P><FONT color=#0000ff>/* loop through the available colors */ . b, r. K$ ~6 e% z4 E% F
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
) ?$ Y& o1 P$ W5 o' x7 o( B, K{ 2 \0 K) i6 K5 F2 }! J! e* H* k
/* clear the screen */ 7 }/ [: T" y. T4 m! k: [
cleardevice(); </FONT></P>
0 n5 D$ l: ~2 B- ?) U<P><FONT color=#0000ff>/* select a new background color */
+ P, B/ t/ R# j; e. `. esetbkcolor(bkcol); </FONT></P>) O' R5 w8 f  Z' @. F& n
<P><FONT color=#0000ff>/* output a messsage */
' {$ I& P1 H. F" H$ ?0 W2 o$ I+ M7 Jif (bkcol == WHITE) 7 ^3 ]7 l% l  D
setcolor(EGA_BLUE); # }0 o" o" b3 T# M! A# u
sprintf(msg, "Background color: %d", bkcol); 2 J/ G) I% ]0 F# j5 I
outtextxy(x, y, msg); * P- @2 m+ c0 q, m  @
getch(); 0 l1 ]) J! F0 p% ]7 A0 l1 ]6 ~
} </FONT></P>
, o$ E  L# F8 {<P><FONT color=#0000ff>/* clean up */ 7 N5 G. b, T; E! G: ^. M$ G
closegraph();
- p9 n2 i$ }1 treturn 0; . y# ^. A$ ~7 x/ g
} </FONT>. z: F: ?* ?0 H5 ~: `
, {! c/ _% P6 c: x2 Q0 A& m
</P>
( J$ m  t: Q- l# u4 ]; U' g<P><FONT color=#ff0000>函数名: setblock </FONT>
: L+ H! D  a# {$ }3 O! r. q4 X功 能: 修改先前已分配的DOS存储段大小 8 M: n2 _( Z8 O" a( O
用 法: int setblock(int seg, int newsize);
! o1 s/ X; @7 _  y/ U: S+ H$ K程序例: </P>; E/ J! ]/ S" `. M* ^$ {# |
<P><FONT color=#0000ff>#include <DOS.H>
. u; D$ {4 K/ Y- z) k& s#include <ALLOC.H>7 l4 Y6 K6 b9 m  O3 [' l) m; F
#include <STDIO.H>
* ?; E/ o" K+ z: U#include <STDLIB.H></FONT></P>3 g0 W: M8 `8 Q8 ?
<P><FONT color=#0000ff>int main(void) + p# Y) D4 _3 ?; J% ~2 O0 o
{ 5 E2 m4 x) r( w9 o  D% b% q" Z+ P
unsigned int size, segp;
# g) Q7 x' v  |# M* k+ cint stat; </FONT></P>, T0 [: H/ h1 d+ a4 d/ _! J5 L5 [
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
+ a! c! Z* i0 x! nstat = allocmem(size, &amp;segp);
0 o3 }0 s0 v# S0 A4 sif (stat == -1) 5 S1 o, x* `2 S5 k
printf("Allocated memory at segment: %X\n", segp); * F0 W: Z1 g6 s6 ^4 W9 K! T
else
* f2 ^2 F( P: Q5 d( y9 T{ / R: b/ v, M" l" E6 t' H7 F
printf("Failed: maximum number of paragraphs available is %d\n", 2 f/ p" u7 E* {7 x- H
stat);
3 g4 Q  y, a% M  h" o. iexit(1); % H- X" a! `' R
} </FONT></P>
" F* ~. u3 u% Z2 K0 ^<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
+ E  c+ U' ~" J- f) I0 r3 Vif (stat == -1) $ I: J; x; n+ q# Z9 J
printf("Expanded memory block at segment: %X\n", segp);
1 Y/ l: `$ F9 C5 P9 B" G% {else $ E: s* y7 C; e0 g' J- T
printf("Failed: maximum number of paragraphs available is %d\n", / |5 z5 ~* |4 Y/ ?' P
stat); </FONT></P># z1 R4 E$ n/ x
<P><FONT color=#0000ff>freemem(segp); </FONT></P>* d( O8 ^8 O' a5 c
<P><FONT color=#0000ff>return 0; # q4 l, V: `1 d  m/ M
}
6 M1 Y2 ?7 P, q, U* k% J/ e: z0 a</FONT>
+ E2 C& ~5 U6 i( h+ o1 w</P>
# m2 b% I/ @) L' k  e<P><FONT color=#ff0000>函数名: setbuf </FONT>+ d" s! [6 n' H% G, Z4 F' g
功 能: 把缓冲区与流相联
# m: E0 G# ]5 l$ j/ _3 X8 ^用 法: void setbuf(FILE *steam, char *buf);
: E" k! {, J6 x5 C1 J程序例: </P>
6 [" u8 k6 `* f1 x& q, I<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
! }8 p3 n2 a1 x4 V<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */   I/ E4 |! t/ G6 B" q
char outbuf[BUFSIZ]; </FONT></P>; S" M6 H! M* g+ @
<P><FONT color=#0000ff>int main(void)
/ @- n8 G" F, {) z) g% K+ Y; t- X0 h{ 4 E0 @+ |* H5 X# M
/* attach a buffer to the standard output stream */ 9 ]+ F: l2 H- a% d+ a
setbuf(stdout, outbuf); </FONT></P>
1 A; G0 e# P, [* `, W' U<P><FONT color=#0000ff>/* put some characters into the buffer */
0 x" g' ^$ \+ u  `puts("This is a test of buffered output.\n\n"); 7 `' l* c) }# j! N1 w
puts("This output will go into outbuf\n"); 6 ^: ?3 l, E" D0 n$ g: q4 x
puts("and won't appear until the buffer\n"); 8 U* j" d% P; h, o, L6 v& H$ Z2 Y
puts("fills up or we flush the stream.\n"); </FONT></P>! g" F+ k5 W& g8 T% B0 h
<P><FONT color=#0000ff>/* flush the output buffer */
0 E1 s4 t3 B7 t5 mfflush(stdout); </FONT></P>
  @- w; g9 h2 D- t8 ?7 o6 d# p<P><FONT color=#0000ff>return 0;
; ^+ a4 d1 r: o8 f}
- l8 g4 O! A( @; ~; a; P3 g. P</FONT>
0 H- V: B2 v2 P4 r% r</P>
2 F% l" r# h" U# q: Y8 V<P><FONT color=#ff0000>函数名: setcbrk</FONT>
' h* V+ l1 Q  q- K% t$ c+ D功 能: 设置Control-break
1 D4 f6 ?# D- r2 |+ |用 法: int setcbrk(int value);
1 M7 ]. Y% |% I; c  P5 q- b程序例: </P>2 y( k: O8 b. z9 s$ C( g
<P><FONT color=#0000ff>#include <DOS.H>
. `3 p7 a2 U  z$ R9 B3 e; G* `! j#include <CONIO.H>9 ]5 c1 a+ B5 i& k( ?% s
#include <STDIO.H></FONT></P>
, j% D7 m) r. n9 G$ J0 E<P><FONT color=#0000ff>int main(void)
5 {" ]( P) V1 b3 q0 _{
/ X6 D! r, k% w0 f$ i( K& Bint break_flag; </FONT></P>
( g. s' j5 P, G6 |! x+ _<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n"); , N: U8 u0 u0 k3 w
printf("Enter 1 to turn control break on\n"); </FONT></P>5 H2 I1 R) Q1 j' ^! x
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>- m9 P: j5 c2 ]0 u& @; ^/ {
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
1 P: E) U% R1 n( v9 {<P><FONT color=#0000ff>if (getcbrk()) ( J" T) l* X2 L! N9 S3 c% W
printf("Cntrl-brk flag is on\n");
* l1 \$ j) f$ ?& c( pelse : D7 l6 _6 X( Y& L. P0 b
printf("Cntrl-brk flag is off\n"); $ j, {5 \. d6 P# E! I8 |# k
return 0; ' c2 H0 @0 N0 k* s- j
}
- P9 w; |, Y1 h6 M4 W' x! r1 w3 M  @" S% e
</FONT>
4 N* h# D  J# O! a& K  e</P>
; z% I" v) t  `/ l- z+ Z<P><FONT color=#ff0000>函数名: setcolor</FONT>
- D! E( w; o; g功 能: 设置当前画线颜色 ( }5 Y& ?7 W; ~3 |0 e
用 法: void far setcolor(int color);
& t3 v$ f4 A6 u' P, ~' j0 I程序例: </P>6 N+ H" \0 A5 y" ?+ N
<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ }) p! \9 W4 r1 z  S! q' M8 D#include <STDLIB.H>
) G; y3 _( b+ P" w#include <STDIO.H>
' k: Z0 G0 O* F- _" w/ v/ a#include <CONIO.H></FONT></P>
" `7 K. V. x/ p7 _# x7 z% I8 ^<P><FONT color=#0000ff>int main(void) 4 w4 y% Z' `) V6 H" t
{ 4 l/ S5 s! I9 Q! E% O
/* select a driver and mode that supports */
4 U5 j  ]3 j6 J& F- J/* multiple drawing colors. */
8 m9 z) t; K! }% S! S+ u+ l$ Z& Kint gdriver = EGA, gmode = EGAHI, errorcode; 5 i: p0 G8 @* |6 b& f
int color, maxcolor, x, y; . k( W1 G1 K3 P0 ~" k# `' V' l
char msg[80]; </FONT></P>- G# x, b1 ~, d4 e% V; z: N+ y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ F& }  k$ \7 }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># e/ Q: \5 F2 |9 {
<P><FONT color=#0000ff>/* read result of initialization */ 4 q( K1 G1 Q& u" ?! {
errorcode = graphresult();
6 m" A8 p* Q: a& @5 j* bif (errorcode != grOk) /* an error occurred */ 1 i4 X6 s% p4 I0 a8 m
{ % i1 h# \; X5 C% n5 s, w  W
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ y8 [7 P4 z# g( d! f$ yprintf("Press any key to halt:");
+ C* v' f( \7 T8 Z: X! Qgetch(); ; C" h9 H8 S: Z: a
exit(1); /* terminate with an error code */
6 I0 }' z: \! q& g; M& p* @9 E} </FONT></P>
* I! d# _; ~. P' G; S<P><FONT color=#0000ff>/* maximum color index supported */ % T0 X& l# V1 c" N
maxcolor = getmaxcolor(); </FONT></P>
  H/ y6 P2 |) Z9 C$ i: r$ j<P><FONT color=#0000ff>/* for centering text messages */ : z% L7 w" D: m' B( K2 f
settextjustify(CENTER_TEXT, CENTER_TEXT);
: y& o  i! \5 P3 Gx = getmaxx() / 2; 1 ~4 x+ A. h  x, }/ I1 u( A4 f) t
y = getmaxy() / 2; </FONT></P>6 m2 ^' r* U7 e& D1 s0 ^
<P><FONT color=#0000ff>/* loop through the available colors */
' D8 a2 k2 i5 }) @: m$ F5 dfor (color=1; color&lt;=maxcolor; color++)
# Q) g: i9 @6 l1 N* z* L3 U) i{
3 o- P( g# Y* D8 ?# I/* clear the screen */ * j, i1 \0 C1 K8 K2 O% K
cleardevice(); </FONT></P>
, o8 {5 J4 n3 G: i<P><FONT color=#0000ff>/* select a new background color */
$ S  Y: c- {7 fsetcolor(color); </FONT></P>
4 E, w5 R  ?4 L3 W0 F# r<P><FONT color=#0000ff>/* output a messsage */ 6 ]* l# `7 |+ [! T9 W. f2 f
sprintf(msg, "Color: %d", color);
; C8 l2 s  |4 c2 g5 ^outtextxy(x, y, msg); ' m# z$ G8 R$ T' m; c2 w5 k3 \) K
getch();
4 f2 I( K. _/ @: l% C$ I, r} </FONT></P>  M( G5 Q. P  \& K, C
<P><FONT color=#0000ff>/* clean up */ , r. q3 F8 m) v, M6 w8 N
closegraph();
/ R& l8 k2 @4 W# d, f$ H+ E) wreturn 0;
7 x) c" N: Q# X. i* Q} & r  ^. ?1 M9 z( d, m8 {# c0 Y3 u
</FONT>
4 v+ F& g! l" I</P>, f1 I! R7 `2 {" g
<P><FONT color=#ff0000>函数名: setdate </FONT>/ Q7 R8 p/ R3 P- m
功 能: 设置DOS日期
1 e: S+ q( D. T# }6 Y用 法: void setdate(struct date *dateblk);
* q' H( L& K* F4 e程序例: </P>
0 N; \* A. R1 d: K, W6 V) O5 X<P><FONT color=#0000ff>#include <STDIO.H>" u8 @+ f# S, W. D% ^" b
#include <PROCESS.H>5 u/ ]% T1 Z3 B' [7 w
#include <DOS.H></FONT></P>1 c& ?" r3 ]# d- S& f) K$ G- `- o
<P><FONT color=#0000ff>int main(void)
) P' A# T2 S4 J5 S5 g5 E{
8 @" I, g# R9 q6 \/ c9 y) Hstruct date reset; 0 f" o7 r: o+ N" C; s. S% V% I
struct date save_date; </FONT></P>
9 b1 w  i* ~& S9 V( `5 n+ R$ i<P><FONT color=#0000ff>getdate(&amp;save_date);
" V, T' o. I* A* z% d) X, R; {printf("Original date:\n");
' N2 a$ A4 F* Y+ X; J8 O9 hsystem("date"); </FONT></P>
0 A5 C! ^7 w7 p5 ^& N<P><FONT color=#0000ff>reset.da_year = 2001; $ v" o9 z$ `& S
reset.da_day = 1; 3 Y* D! J2 ?* m3 M
reset.da_mon = 1;
/ ~: e& O+ _3 Rsetdate(&amp;reset); </FONT></P>5 L$ |) M. |# b% M
<P><FONT color=#0000ff>printf("Date after setting:\n"); ; q" |& N; Y2 P1 Q9 K, A9 p* i2 v
system("date"); </FONT></P>
1 B3 [3 a" R: d  i<P><FONT color=#0000ff>setdate(&amp;save_date); % t: z, v" |' B5 f6 y- n
printf("Back to original date:\n"); : B9 W( Q( \4 D2 I0 K$ @7 o. U
system("date"); </FONT></P>
9 ?9 j9 J; ]0 `4 h4 Q4 n2 S; M' i<P><FONT color=#0000ff>return 0;
0 v( |# ?8 }$ n} 7 d: D: N) a4 j4 y; a
</FONT>; |; h1 \  x! q/ d
</P>
# l: R0 c* \. v4 c<P><FONT color=#ff0000>函数名: setdisk </FONT>3 e" C6 F. y  V2 o
功 能: 设置当前磁盘驱动器 ; O( W8 @  d( a) ~% X
用 法: int setdisk(int drive); 7 @  ^3 D0 A2 P5 ]6 [$ V
程序例: </P>
9 @3 z& `' L# f# }<P><FONT color=#0000ff>#include <STDIO.H>
  L5 @; a8 t+ ]9 B0 U/ R( j$ r#include <DIR.H></FONT></P>
2 A, f) o2 b6 p6 j5 I0 S0 f<P><FONT color=#0000ff>int main(void)
- J/ O7 f8 d" P: Y6 |! O! A6 t{ + n: T/ i3 O/ M. T6 X
int save, disk, disks; </FONT></P>
/ [6 ?; T: _" W8 j1 g) k  @% J5 g<P><FONT color=#0000ff>/* save original drive */ ' m; J7 q# R3 G
save = getdisk(); </FONT></P>
% F& N8 l6 r$ n5 g: ]<P><FONT color=#0000ff>/* print number of logic drives */
" v" o/ e# \5 k0 V/ Vdisks = setdisk(save); / u* M/ l* B- G; ^& L6 S
printf("%d logical drives on the system\n\n", disks); </FONT></P># C, V- Z1 c6 K
<P><FONT color=#0000ff>/* print the drive letters available */
, K+ u8 b8 M5 n% [6 m, f" l5 m+ Kprintf("Available drives:\n");
% ?, ~$ D* b( A5 Sfor (disk = 0;disk &lt; 26;++disk)
( W9 q, x# u1 D" x3 \{
* j& z( G. x5 \$ Q, g" F& g6 @* Usetdisk(disk); 5 G3 o( n+ X' W: t9 P; C
if (disk == getdisk())
% \9 Z, S; L& H* \3 k5 g1 L3 sprintf("%c: drive is available\n", disk + 'a'); * u3 K, s$ q, d2 ?- P2 p4 h. n
} 0 `: [5 p; i8 L
setdisk(save); </FONT></P>! i2 T3 W9 J( g+ F
<P><FONT color=#0000ff>return 0;
1 d. B" |5 D5 p3 J} </FONT>
, n; C; R7 A" {  x4 r' z8 k2 F0 `
# m; C( l6 y2 L# Q5 M3 V. N</P># f/ z) Q6 a# w
<P><FONT color=#ff0000>函数名: setdta </FONT>
" R3 f3 E* G& ?功 能: 设置磁盘传输区地址 " E6 ^0 |8 U) F5 w! f
用 法: void setdta(char far *dta); 6 M" N9 `0 a- U1 n9 P3 g4 U6 _
程序例: </P>
1 i! z4 _& O* m0 H* ^/ C<P><FONT color=#0000ff>#include <PROCESS.H>8 A! o" Y+ u1 |: m0 h" N
#include <STRING.H>
+ ]/ X+ U8 T/ G6 h2 Q#include <STDIO.H>
$ h. U# @2 |6 {4 z; b7 V#include <DOS.H></FONT></P>. `7 x; R1 ^' G2 T
<P><FONT color=#0000ff>int main(void) 7 v. O" B* I4 u
{ % [& }; Y8 L; E( o% A' ]
char line[80], far *save_dta; # ^( L( ^5 g  ]
char buffer[256] = "SETDTA test!";
. |5 j. x! s; y6 m0 N; S& m: Estruct fcb blk; 2 a" _& B+ a9 x
int result; </FONT></P>- r  O8 \( T# m  H, d8 P8 H) x
<P><FONT color=#0000ff>/* get new file name from user */ # Z" z' N' l: k* T6 E! ~% z4 T4 G
printf("Enter a file name to create:");
( a& X8 t& [9 L3 |gets(line); </FONT></P>, L1 j! [0 \! V( l; v
<P><FONT color=#0000ff>/* parse the new file name to the dta */
, l2 w% O. g+ F, ^parsfnm(line, &amp;blk, 1);
/ z3 k  t5 S: ^2 L& W* ~: vprintf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
) M# v1 T! v& `9 n  [  U0 j. Q5 f2 K<P><FONT color=#0000ff>/* request DOS services to create file */   D2 ^# I2 U/ K$ V- a
if (bdosptr(0x16, &amp;blk, 0) == -1) 8 W/ J+ `+ x: T1 h: }
{ 9 k" P6 f6 F  X- ~/ {& c/ k
perror("Error creating file"); % o* F' N. Z: ~# d5 b9 X
exit(1); / h$ R: H" m& T" t
} </FONT></P>
) z0 S9 I, y( p3 X/ {<P><FONT color=#0000ff>/* save old dta and set new dta */
! Q7 y+ R, q  D6 Q% x. S$ Bsave_dta = getdta();
4 ~$ z* G" H- S. Esetdta(buffer); </FONT></P>
4 b2 h" p. l0 q% u' h3 g$ j/ F( G$ R<P><FONT color=#0000ff>/* write new records */
; ]& ], Q3 y& Q  m0 @blk.fcb_recsize = 256; ( |" Q8 a0 O& n1 W5 J$ \
blk.fcb_random = 0L; 8 v8 b8 ]9 k& C  x; F' p) S
result = randbwr(&amp;blk, 1); 3 v. ^) F+ k1 `' o
printf("result = %d\n", result); </FONT></P>
2 D, ?& Y% T% @% C# G* [- V5 x9 @<P><FONT color=#0000ff>if (!result) 2 N, F- Y2 |* t4 Q, F
printf("Write OK\n"); 1 J5 Z3 i/ T, R$ _) m, w
else ( C4 s7 @/ @! j: N! E/ c4 x6 q  e
{
3 q0 s, Q+ a4 G( z4 M' Aperror("Disk error");
- d: L3 ?; [' z1 x: bexit(1);
3 U% Z( p$ ^  F} </FONT></P>
" j# }6 C! V2 @8 N" j* a$ [) z<P><FONT color=#0000ff>/* request DOS services to close the file */
0 {3 e, l1 [, `1 s8 Cif (bdosptr(0x10, &amp;blk, 0) == -1)
6 M9 G8 Y) r) A$ [' ]7 g{
& \4 X& ]7 q8 D) r* j9 tperror("Error closing file"); " n9 z. ^% c# B6 O' `, S9 U
exit(1); 5 u9 H' n# F1 E5 ]3 u
} </FONT></P>+ U, E) k. g( O  {2 q
<P><FONT color=#0000ff>/* reset the old dta */ $ `7 y& N, w$ E7 c# k8 p
setdta(save_dta); ! M: b& X4 T* I
return 0;
% I* f9 V( s: T1 A6 G# `; I( D( n- y} 5 n  y3 ^$ U5 M) ^/ ]
</FONT>. N- o* E, B6 C7 e
</P>5 F2 i6 O  n5 c1 @* _2 [
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
6 Z  `% z7 y6 o$ r功 能: 选择用户定义的填充模式
! ~2 B9 n5 x  @" Q8 K9 j用 法: void far setfillpattern(char far *upattern, int color); 1 M9 W$ O9 g) }3 i
程序例: </P>
+ c& H# F2 m& d% y* ~<P><FONT color=#0000ff>#include <GRAPHICS.H>9 d9 q( j$ N4 O# v
#include <STDLIB.H>( O: H6 s+ R: _0 U1 l( {
#include <STDIO.H>
- {4 _$ P% U& H( S( r8 {( D#include <CONIO.H></FONT></P>3 t1 }+ {7 [4 p
<P><FONT color=#0000ff>int main(void) 4 a7 X& ]) `) y7 e& Z: X
{ 1 K/ y; U6 z: ]+ K, ~
/* request auto detection */ 5 I; T1 l5 X6 O2 m* x8 G) @/ f
int gdriver = DETECT, gmode, errorcode;
8 f! D& y/ q, @int maxx, maxy; </FONT></P>* k1 t; W. a4 D: Q
<P><FONT color=#0000ff>/* a user defined fill pattern */ 1 j5 Y" i+ L2 o; b* U1 A
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>" E# S( s: I6 X9 w/ V" t' X: y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ _. k9 Z8 i, O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; u& c7 n1 \8 M/ ~, \0 v/ a
<P><FONT color=#0000ff>/* read result of initialization */
& q% J0 q- g, f( u1 f4 ferrorcode = graphresult(); 4 L, }7 F) p, X9 Z8 N1 b# @
if (errorcode != grOk) /* an error occurred */ - f# a+ X$ r6 e1 [
{ ) V* \% f7 m' E4 x9 d- T/ K
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 S6 N0 J$ f9 i- |
printf("Press any key to halt:");
  F: a8 Z" L8 X! fgetch(); . Z* s( v' p( E: _& z! o
exit(1); /* terminate with an error code */   C4 J. H- u3 O% ?* z( N
} </FONT></P>
% T3 Z2 _' j& f! R4 F/ @! Y<P><FONT color=#0000ff>maxx = getmaxx(); # N$ |+ r4 A# D  I+ ^4 ]# [: e
maxy = getmaxy(); & l/ s1 u+ _3 Z+ L
setcolor(getmaxcolor()); </FONT></P>
  E6 E1 S/ a& V- i' E<P><FONT color=#0000ff>/* select a user defined fill pattern */ " z9 y6 H' ]8 R5 A  F
setfillpattern(pattern, getmaxcolor()); </FONT></P>6 ?. w' C9 w0 e7 ^
<P><FONT color=#0000ff>/* fill the screen with the pattern */
! g, a$ @2 H4 ]6 i' M4 jbar(0, 0, maxx, maxy); </FONT></P>) i! l1 ~/ [8 f
<P><FONT color=#0000ff>/* clean up */
) N3 |* J0 h: I5 w" Cgetch();
; |; l/ L, |' m* w* dclosegraph();
" c: G( r/ b8 j9 Q' L3 G, Y5 breturn 0;
" y* e; f( }4 r( `: y} ! i9 H. G' L( h: h- s- b5 g
</FONT>" g" {2 m4 H" {
</P>8 G# V* e! _$ o* ]7 D
<P><FONT color=#ff0000>函数名: setfillstyle </FONT>* w: _" T% I2 H! n: Z
功 能: 设置填充模式和颜色
3 ~& {- a9 n8 f9 ?/ o用 法: void far setfillstyle(int pattern, int color); * N& {6 g5 f8 Q) K6 X' w
程序例: </P>0 j2 D  S1 b9 F$ w
<P><FONT color=#0000ff>#include <GRAPHICS.H>
  W: k: F/ a4 f3 E, A$ d/ D/ K#include <STDLIB.H>
0 J, r3 e' m8 T+ Q+ N6 F#include <STRING.H>
* b0 E8 i% `1 w# U% E. g0 v; G#include <STDIO.H>0 k# k% L% B" Y4 r# s
#include <CONIO.H></FONT></P>
0 U2 {# \1 E5 {3 m" v2 p<P><FONT color=#0000ff>/* the names of the fill styles supported */
9 |$ ?6 [" ]' L4 H7 zchar *fname[] = { "EMPTY_FILL", + C& \8 z  {" N/ k1 }# l/ t  u
"SOLID_FILL", ! M+ d( I. M- y$ x5 V6 ~
"LINE_FILL", $ [* a4 P* Z* N# j
"LTSLASH_FILL",
- S6 o6 Y$ K( ^7 @* ?7 U"SLASH_FILL",
! T& i3 i* b0 J3 S, g% b"BKSLASH_FILL", # \/ V$ p+ I/ s) \! _
"LTBKSLASH_FILL",
) L% b. c! F) {) ~  ?! o"HATCH_FILL", 4 s4 Z  R" U" d6 M) k& M- C
"XHATCH_FILL",   c% m3 @9 S% m
"INTERLEAVE_FILL",
$ N- r' ]/ {, V0 s2 ^7 t7 X6 l"WIDE_DOT_FILL",
2 A; u; U2 G+ l5 @" w"CLOSE_DOT_FILL", 6 d5 ~* ?3 X  u! x6 I; J( d6 g
"USER_FILL"
) r6 z, l& u) D% k) v, U}; </FONT></P>$ B) Q8 W& p( J
<P><FONT color=#0000ff>int main(void) 7 u( g# N" ^# a) d1 ^4 g. }
{
# W) q. I; h" M) ^8 ]! ]$ b, I" O/* request auto detection */
4 x$ m8 w" c2 J) ?( Mint gdriver = DETECT, gmode, errorcode;   H7 u! _7 J5 {6 q7 y
int style, midx, midy;
; G' w" a7 q$ y: E# l+ ?8 {char stylestr[40]; </FONT></P>5 s! L2 D4 q& k7 J5 l  e
<P><FONT color=#0000ff>/* initialize graphics and local variables */ : r0 e$ Z: u) N" V4 t. E$ l5 r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 {1 m1 |, ~$ G4 i7 F$ p$ K<P><FONT color=#0000ff>/* read result of initialization */
, s6 s( p, _* U; Gerrorcode = graphresult();
5 Z, v! t6 f, s4 p$ u$ w( a3 @$ [if (errorcode != grOk) /* an error occurred */
3 @5 U6 @  S0 q* }) {2 w# _: \{
6 h, w* B% e3 |printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 K" r9 G$ Z" c, w
printf("Press any key to halt:");
# C: j7 P7 R- @5 W- zgetch(); * F+ F- u$ w- q. h
exit(1); /* terminate with an error code */ 0 v5 T, r2 M% M3 Q6 _6 p
} </FONT></P>6 _( W6 P+ i5 F4 d
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ s  o4 r9 A5 |
midy = getmaxy() / 2; </FONT></P>7 T- t2 }* h& `7 s. R) s  m! s
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) 7 ?2 b! a2 B6 w. k. A
{
4 z% Z% X3 o2 Q; ?& f5 o/* select the fill style */
3 V" D% g8 X8 y. Csetfillstyle(style, getmaxcolor()); </FONT></P>
8 Y; x$ [+ V/ }# l& O<P><FONT color=#0000ff>/* convert style into a string */ ! S% a/ n6 x# u( f
strcpy(stylestr, fname[style]); </FONT></P>% X2 h, _0 U# g
<P><FONT color=#0000ff>/* fill a bar */
5 K! P& Z& [: T, Gbar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
1 V& \. c& P7 x; a. K<P><FONT color=#0000ff>/* output a message */
) R! O, x- I/ M! kouttextxy(midx, midy, stylestr); </FONT></P>& n1 s2 P. `0 K3 @" b; P+ f, @
<P><FONT color=#0000ff>/* wait for a key */ 6 c/ c  ]5 I+ h& p
getch(); " a2 O! D1 |4 z. S8 S9 q
cleardevice(); ) B5 e1 V( U( _9 K: N$ B- S
} </FONT></P>
* E0 `$ z" v+ J" a4 r) d( x<P><FONT color=#0000ff>/* clean up */
  c% f1 O& @7 Mgetch();
0 j9 g% X# ]+ Z/ I' vclosegraph();
9 a0 C+ }4 t$ O, D' I& Rreturn 0;
" [7 m' M4 V, `" G5 m: F0 h} </FONT>
) Z0 v/ ?7 V; P! P
1 e6 ^, Y; C# n</P>; p) S2 Q+ I* o; d
<P><FONT color=#ff0000>函数名: setftime </FONT>
3 _0 U/ e" K% u2 O+ Z& E0 O功 能: 设置文件日期和时间
8 i  |4 }2 J  A" b用 法: int setftime(int handle, struct ftime *ftimep); . Y, _2 n& [. v( C$ @
程序例: </P>. G6 U+ l' K) U  a, I5 l
<P><FONT color=#0000ff>#include <STDIO.H>1 A6 N6 ^: V  Y! U4 ~2 N7 B: [
#include <PROCESS.H>5 V2 \/ G% \3 x& D+ X+ D; Z6 G4 Z3 o
#include <FCNTL.H>
  e5 [- {7 {" u+ `8 ^# y: G#include <IO.H></FONT></P>; }2 {; N! y8 H5 T% p
<P><FONT color=#0000ff>int main(void)
; V2 K+ ?9 l% g4 ?$ d{
1 |* I5 \+ n8 r, U* lstruct ftime filet; 0 `& J- l& T. r% t
FILE *fp; </FONT></P>
0 w+ \2 b% k0 E; I+ k6 m$ ]5 I<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL)
$ `& {4 T4 S3 ~0 W. I* s/ b{
2 O- ^6 y* f, }" C' A1 M. k/ Xperror("Error:"); , {$ z- `8 ]) |: |4 ~
exit(1); ' W5 \+ I) _7 R6 G4 s
} </FONT></P>
8 z" ]/ O$ X& E9 I<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>  g. R9 z  v: W# y
<P><FONT color=#0000ff>/* load ftime structure with new time and date */ ; w! y6 J1 A. @5 k% F; z' ^' z9 ^# g
filet.ft_tsec = 1; ( s& I. N* D) v9 k$ ], C
filet.ft_min = 1; 0 G  u$ u1 c% e; N$ j9 [0 t
filet.ft_hour = 1;
# k4 G( P( Y; y: ^1 lfilet.ft_day = 1;
+ K$ t% l' l3 s. @+ kfilet.ft_month = 1; 1 r# K" v9 r: c
filet.ft_year = 21; </FONT></P>! t" f% b# L/ x3 w6 e6 _& q
<P><FONT color=#0000ff>/* show current directory for time and date */ 3 q5 w* y  f1 w+ \0 r
system("dir TEST.$$$"); </FONT></P>
7 V+ e6 L: ~  Z+ p. ~<P><FONT color=#0000ff>/* change the time and date stamp*/ , [/ b1 s9 S8 L( i) [$ B: [0 z
setftime(fileno(fp), &amp;filet); </FONT></P>: l  O! i! E+ \4 V: z
<P><FONT color=#0000ff>/* close and remove the temporary file */ ( I* f: n4 Q. `) Y
fclose(fp); </FONT></P>
0 P) V$ T2 Y+ @- T7 M$ a( {<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>- H6 q  e2 g" U9 X4 W: ~
<P><FONT color=#0000ff>unlink("TEST.$$$");
% w. R6 [" a& C9 W) [% Qreturn 0; : D5 \. z" n. C0 N5 Q8 t2 i1 h. Z
}
3 h+ l: T3 \) r% s0 R, P% ~( w! Y</FONT>- Y6 v5 B5 q6 q) Y& w" b
</P>2 B* g  B% _8 M) X, ~+ m
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>6 V" H. ~, m% C* {+ F; x
功 能: 改变内部图形缓冲区的大小 1 v5 k# _/ n, l
用 法: unsigned far setgraphbufsize(unsigned bufsize);
: b2 k3 C! v; S: |; M' r程序例: </P>! f$ o. @7 w# T& O$ C5 ^) n
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; J" j/ p/ _" y$ `2 W#include <STDLIB.H>9 k. j$ D( J, N% |6 c
#include <STDIO.H>
/ h- `' F- Y' F, L( i#include <CONIO.H></FONT></P>- `5 p* b, o- W: u
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>. m" }6 C( O* F. h
<P><FONT color=#0000ff>int main(void) $ H5 s# d& L! B3 D5 a
{ ; @7 R- L/ ?8 X7 |0 b0 }5 a$ w
/* request auto detection */ % t) j: J. x4 \, \, \$ C
int gdriver = DETECT, gmode, errorcode; . G1 ~. W" I$ P! A
int x, y, oldsize;
7 Q' `/ A# _" k% M. F) l9 zchar msg[80]; </FONT></P>
8 Q3 d) \' j  p<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ 7 C1 w3 K+ `" B: ]8 K& }
/* before making a call to initgraph. */ 9 {+ y, X, r& g/ D: W# E
oldsize = setgraphbufsize(BUFSIZE); </FONT></P>, K' i) y! c  L  R, C
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! q" A0 P' p# z3 z% b- I
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  Q- R8 o8 n! J& [3 z4 \' K: e<P><FONT color=#0000ff>/* read result of initialization */ + h, C% w6 w% |6 t8 @1 M8 N: X
errorcode = graphresult(); " p- J: n( A! d
if (errorcode != grOk) /* an error occurred */ + `, @1 G- J7 }0 v4 Y; ~
{
; a0 Q9 A: v2 I% ?& H* Yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
$ Z+ o. K& p# R' Y$ |* Eprintf("Press any key to halt:");
1 [* t7 Y# `8 Ugetch(); 8 d# l* j& _. U# s0 A. [' ?  i
exit(1); /* terminate with an error code */ 3 M: K9 r+ \5 W' m. y
} </FONT></P>
0 m. w5 H) |5 p9 l4 z<P><FONT color=#0000ff>x = getmaxx() / 2;
9 m  \( k* r+ i  v, X3 iy = getmaxy() / 2; </FONT></P>; N& @3 U/ ^! g2 {0 P. e1 w% a
<P><FONT color=#0000ff>/* output some messages */
! \+ @" G( U% S) Tsprintf(msg, "Graphics buffer size: %d", BUFSIZE);
' Q. ~5 _* ~, Y2 fsettextjustify(CENTER_TEXT, CENTER_TEXT); - Z9 F% L; U, j; I( E1 s
outtextxy(x, y, msg);
  U$ {1 H8 g  @: H! s* asprintf(msg, "Old graphics buffer size: %d", oldsize); / C: X5 @5 A' ?+ i# \; d
outtextxy(x, y+textheight("W"), msg); </FONT></P>
3 t- a' N0 U" e- n# P3 S( I<P><FONT color=#0000ff>/* clean up */ , Z% H- z5 B: i  o3 @# v
getch();
6 m- r# f( O/ F9 Q* yclosegraph();
6 G; r3 I1 y" freturn 0; 8 k! H6 X* h$ T) E/ \
}
1 }8 ~. O: O) Y. z0 G4 _6 ^1 b2 {( N* v4 V7 K' L2 m5 h2 `
: r" j: G% |. o$ w# c& U  L
</FONT></P>0 p' d+ D2 \; X3 q! X& G
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
  H* p1 f' ^0 i3 D. n功 能: 将系统设置成图形模式且清屏 , V6 ?$ P7 C  Z$ i; ^/ h
用 法: void far setgraphmode(int mode);
9 d( A% @" L' H程序例: 3 ]- U( q" s$ p9 g; C
) j, a$ i# H0 j7 V  x, P8 D" I
<FONT color=#0000ff>#include <STDLIB.H>
% A" D2 G/ |1 e4 Z#include <STDIO.H>
+ H9 `* _5 y% [- _5 Q#include <GRAPHICS.H>#include <CONIO.H></FONT></P>7 |$ L) Q4 F' d' L! i
<P><FONT color=#0000ff>int main(void)
+ j! a8 A( `* G% ^/ p# b+ o% `" Y4 R{ 1 G/ _, E9 F0 W6 e# }! w3 |# l
/* request auto detection */
% [3 z& a8 L# W3 L  tint gdriver = DETECT, gmode, errorcode; 7 Y/ F( h4 {* A( _3 I( u9 r' m! @6 ~
int x, y; </FONT></P>
" _# Q$ h! t! s6 i' n<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 s& y$ w. `+ ^  m
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 _2 \# y* U, N' ]/ m5 |' `" _% p' M" {
<P><FONT color=#0000ff>/* read result of initialization */
1 l: L, i6 S% m4 ~  K! {errorcode = graphresult(); ( V" R" d' e0 J! ~- r! ]
if (errorcode != grOk) /* an error occurred */
( c3 \! K. g. p{ 5 t1 r. j2 Q3 f3 i) i5 [
printf("Graphics error: %s\n", grapherrormsg(errorcode));
$ t+ Q. o) K3 d) E/ hprintf("Press any key to halt:"); ! C- m) Q/ ~* I% \
getch(); / Z6 ]- V! m9 d) j) C
exit(1); /* terminate with an error code */
" N) [) F5 n; g} </FONT></P>
8 Q4 w# a. i1 u# _$ i9 |, g<P><FONT color=#0000ff>x = getmaxx() / 2; 6 F" X$ v0 \& X. a8 T7 C
y = getmaxy() / 2; </FONT></P>
2 |# x- M! M2 x) Q/ e( p. i; S<P><FONT color=#0000ff>/* output a message */ 0 O2 h% o4 L( W- v
settextjustify(CENTER_TEXT, CENTER_TEXT); 5 [9 D' k! F- n+ E. ?3 p
outtextxy(x, y, "Press any key to exit graphics:");   u5 D/ r. b% ^$ S/ v
getch(); </FONT></P>
: ~, s$ s9 G& X<P><FONT color=#0000ff>/* restore system to text mode */ ; |% z2 v( O1 m8 f8 H' j; o
restorecrtmode();
/ E# l/ w& K" B. s" [. hprintf("We're now in text mode.\n"); 0 k8 V7 I9 R: t* O: L4 M
printf("Press any key to return to graphics mode:");
. ^9 v5 H$ V2 p) t! f- G: R% xgetch(); </FONT></P>2 R% g& H# U" L9 f9 b, s1 u
<P><FONT color=#0000ff>/* return to graphics mode */ 5 [" r3 O& ]- g8 m# @+ _" J) E; k
setgraphmode(getgraphmode()); </FONT></P>
8 d+ D& J. t; W: `<P><FONT color=#0000ff>/* output a message */
1 P0 g0 W1 C9 xsettextjustify(CENTER_TEXT, CENTER_TEXT);
( ]! u# Y! y, I+ D5 h9 ~8 t7 ?outtextxy(x, y, "We're back in graphics mode."); * A, s" c1 g0 e
outtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>
6 }1 f+ ^% K% a8 l% h<P><FONT color=#0000ff>/* clean up */
5 f* s5 Q; |' M1 P  Egetch(); & i5 c  i+ ~# S7 f% z5 I
closegraph();
$ n5 c1 J' B- freturn 0; " K  Z# n* e, Y# |! J+ H: b( \# y
}
" v0 u8 P  t( V- S0 O" O. q8 X6 X! F7 G1 c, z

' u+ h8 Q; f4 T0 V( \/ I</FONT><FONT color=#ff0000></FONT></P>
4 Z) m( z; ~7 u' f<P><FONT color=#ff0000>函数名: setjmp </FONT>( n% j9 {8 v( E' I% V5 N
功 能: 非局部转移 * n; T9 O- L& Y
用 法: int setjmp(jmp_buf env);
  [. K& e) E/ j+ [6 F程序例: </P>1 l7 m. B6 B& j. d! l$ K( U
<P><FONT color=#0000ff>#include <STDIO.H>
; z# N1 ?$ C4 j" ^  _#include <PROCESS.H>
, D. B) V. e7 Y1 O8 I#include <SETJMP.H></FONT></P>8 r$ v1 }/ u$ a: L! d  M
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
' D5 |' P+ ]2 M" S: z7 G<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>
0 v+ Z: H  s, ~4 C4 J<P><FONT color=#0000ff>int main(void)
% w* E0 D) ^- Y. k/ ]8 t$ e8 w5 N{ 4 X# m% U, u0 g- {: b
int value; </FONT></P>& Z( U9 `- M% T3 i) h
<P><FONT color=#0000ff>value = setjmp(jumper);
1 M$ U* t7 T" T) V$ Sif (value != 0) ) C  T5 W# a8 r; Y' o: K
{
8 x' r& e* \! _* Vprintf("Longjmp with value %d\n", value);
' ^+ v& p& }5 N3 W6 }exit(value);
2 P. u0 F7 J- a4 H' T; a/ K' }} & X3 p; F, W8 ^$ L( j* f3 {
printf("About to call subroutine ... \n");
9 k$ A4 S, s4 |$ B! o' F4 g0 gsubroutine();
! t  J$ V" j" J5 M" S2 c$ _2 x7 Greturn 0;
) |3 H9 H9 [3 k7 R2 A} </FONT></P>+ X7 D* ~4 Y0 p' E8 o0 s3 q
<P><FONT color=#0000ff>void subroutine(void)
  {" V4 E2 u5 d5 }7 |& v{
: C8 P3 T/ z! g- k1 I9 `longjmp(jumper,1);
3 ]8 [3 u0 S$ K  E& P. a0 W7 ]}
" ^% P* k; O: M</FONT>
, D# V4 O* q' O4 Z</P>
' S2 O& b4 w9 ^( P/ R* c<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
* S" u! Y$ U) m功 能: 设置当前画线宽度和类型
( h6 F9 m( Q2 q) {用 法: void far setlinestyle(int linestype, unsigned upattern); ( S0 Z$ F+ C) t) c6 w
程序例: </P>4 y8 i6 F4 _) Y. z( S* a
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; s! F& b0 o, G4 V) [2 G#include <STDLIB.H>8 F( L$ h/ U, I
#include <STRING.H>3 W3 Y, z' b. O9 t) l
#include <STDIO.H>' G- F7 Y3 O' L; ^. s# o; q
#include <CONIO.H></FONT></P>
$ a) I% i7 s4 F% j/ T0 A4 }<P><FONT color=#0000ff>/* the names of the line styles supported */ 7 P, P" W: l% c9 n$ Y* ^2 a
char *lname[] = {
& @$ P  k" V# L9 _0 }3 ]% X7 v"SOLID_LINE", 9 X3 m" Q0 _+ Q1 k# E
"DOTTED_LINE", , t  `/ ^- k4 s' Y8 w
"CENTER_LINE", 3 L! W7 @/ k0 R( b, p/ e! i1 q
"DASHED_LINE",
0 M# u9 [' L' N/ ~"USERBIT_LINE" * _$ u1 k' j9 Q% Y0 V8 i
}; </FONT></P>
/ c7 g- w7 g! g. D<P><FONT color=#0000ff>int main(void) % H; ~* s' R% j/ Z% m9 V; V4 g
{   d0 a9 ?* x" Z- O$ \6 S- f9 u$ {
/* request auto detection */ * _7 y" k1 y9 j( |3 j& n; N" ^
int gdriver = DETECT, gmode, errorcode; </FONT></P>
- U& Y5 V  A) G& _<P><FONT color=#0000ff>int style, midx, midy, userpat;
. u) x: D4 M- |( |0 C+ hchar stylestr[40]; </FONT></P>/ [# Q$ J* `  R' i
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 P! H; X% @6 y5 G9 \7 m1 }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* r0 S' N$ g: T& j
<P><FONT color=#0000ff>/* read result of initialization */ 0 c8 K9 X% i$ q2 i+ ~, m
errorcode = graphresult();
) B$ Y: C' R  J+ bif (errorcode != grOk) /* an error occurred */
' A) y, ?$ o6 ~  q7 [5 @! e{
& q0 R+ l0 b* Kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! n. N, u/ d9 w) P* a7 ^) @printf("Press any key to halt:");
3 a8 C. U# E1 b0 O3 Egetch();
2 e& e8 y# g3 g: Q: p  q6 W2 G, l, Eexit(1); /* terminate with an error code */
. f! T, E7 `/ ~6 X} </FONT></P>
7 D0 f* c. m8 ?3 V+ ]<P><FONT color=#0000ff>midx = getmaxx() / 2;   B% j" b: b$ m
midy = getmaxy() / 2; </FONT></P>
: q$ O( u, Q3 g9 \0 ~3 A; e  x( ~( R<P><FONT color=#0000ff>/* a user defined line pattern */ 4 Q3 D+ V1 J# p: Z" e
/* binary: "0000000000000001" */
7 q* L* ?3 I3 r- I! Q% }7 e* w4 X; quserpat = 1; </FONT></P>
; g$ V" v- f" U0 p9 B<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
% I, c9 y$ [% {( D: m8 {2 U% P) F{
; f- A1 Z7 h$ S/* select the line style */ ; X5 Y' j  T$ g; z5 O) k# f! j1 \3 X
setlinestyle(style, userpat, 1); </FONT></P>7 G; d# S8 e7 `5 t6 _7 G
<P><FONT color=#0000ff>/* convert style into a string */ $ r3 |9 L) M: s. X0 N; J4 x7 [
strcpy(stylestr, lname[style]); </FONT></P>
3 x4 X) I3 d! O5 Z3 ^<P><FONT color=#0000ff>/* draw a line */
3 M4 r# Z: k: P+ ~4 a5 I7 dline(0, 0, midx-10, midy); </FONT></P>, h/ p1 ?2 x2 R1 _8 b# |3 w
<P><FONT color=#0000ff>/* draw a rectangle */
8 O  H- x! P, Y: k' grectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
) ^6 K* U. ^$ k$ }<P><FONT color=#0000ff>/* output a message */ , C, l1 d: o0 }' M
outtextxy(midx, midy, stylestr); </FONT></P>
8 g: f- x2 h  C<P><FONT color=#0000ff>/* wait for a key */ , m7 Y* L9 [' x' i, C  B! F' V$ b
getch(); & u( d4 Q% y6 Q7 f) b
cleardevice(); ) [" |% m8 O; L* r; D1 o
} </FONT></P>
! M6 K- p7 ^) v2 Z; Y7 d3 n<P><FONT color=#0000ff>/* clean up */
, ~9 x! W4 C9 X' Dclosegraph(); + O6 K9 \/ b6 X
return 0;
; X% T+ ^8 X) i% \( I- s; y} </FONT>
9 M0 s9 i! r. Q' p, }2 _+ Z$ w" y7 |
. T! f) p4 @" y% o; T- L4 M8 e3 U. H; B" |! L7 n3 l
</P>
8 O1 M* f* \% w" v  M9 {<P><FONT color=#ff0000>函数名: setmem </FONT>
4 {. M! Y5 Q3 S. m) Z; ~5 h1 y" z功 能: 存值到存储区 , X& N* `  E# a- b$ B
用 法: void setmem(void *addr, int len, char value);
5 m# x2 C4 A. g2 N4 v$ z程序例: </P>5 A. s5 W4 [" J' r
<P><FONT color=#0000ff>#include <STDIO.H>
* `, d. m) t6 g- s8 R( J4 `8 H#include <ALLOC.H># z2 ]! X( K- p: `9 M# l8 C! }" b
#include <MEM.H></FONT></P>1 a+ W6 O1 c  m3 o0 M
<P><FONT color=#0000ff>int main(void) + b; G. |9 f' P
{
, [; ?" ]1 U3 L- |) X) Kchar *dest; </FONT></P>
! g; I8 J5 H9 `! d<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
  N0 E* u% ^: [! N. t& }4 Bsetmem(dest, 20, 'c'); 5 s- y) J' g" V3 m
printf("%s\n", dest); </FONT></P>
( U# K9 }' O! q1 R/ y<P><FONT color=#0000ff>return 0; ' v- [5 `; F% I; a9 H6 S
} </FONT>
# x- I$ w% h9 y0 J. Q  N9 Z
2 S( `; D, S! N! e( z% ~% d/ H8 O, V% ]% p( F
</P>
; Q' L3 T' K6 F# l& L! d) h<P><FONT color=#ff0000>函数名: setmode </FONT>
" E( b0 A( Q1 L功 能: 设置打开文件方式 : f2 {$ ^" l: [9 r; h) v
用 法: int setmode(int handle, unsigned mode);
1 t' j0 P0 N0 |+ j程序例: </P># Q1 V( O  }+ l: p
<P><FONT color=#0000ff>#include <STDIO.H>3 f/ i. M7 I! g% m% _' D# s; z
#include <FCNTL.H>/ V- G- M* d% `1 z
#include <IO.H></FONT></P>, u# t) K, V+ I) ]/ I) e3 J
<P><FONT color=#0000ff>int main(void)
# `8 Y  V) g9 O3 W{ 3 S& [9 N' E" {; t1 G6 ?
int result; </FONT></P>
4 n# z/ M" z) ~<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
& H3 T. R+ `' t( ?# J! \# d5 Dif (result == -1)
6 u: C8 T  c! u. I2 Aperror("Mode not available\n");
, _, M! F/ k: O+ Velse % R( Z: m7 s7 g5 F, z7 `
printf("Mode successfully switched\n");
# i; e$ l; k/ g; ~9 r2 nreturn 0;
1 m8 ~0 C* E( B1 G% a}
0 [8 W3 c# ]% E
. o3 E  Y) T2 F; p% d$ Q5 l( H8 P% i</FONT>
' I5 X  y0 i/ N</P>9 f4 r& F6 i9 ^5 O+ T( I. x: P
<P><FONT color=#ff0000>函数名: setpalette </FONT>/ A  q3 ]. H/ K+ H5 O3 |. l' S' x
功 能: 改变调色板的颜色 5 M4 m; c/ C- A- e8 o! s. w
用 法: void far setpalette(int index, int actural_color); . N9 q3 p! n0 R5 a+ y
程序例: </P>
4 l/ B- `; }( m2 m( g9 {- ^# t7 L<P><FONT color=#0000ff>#include <GRAPHICS.H>3 z: O/ s4 j! W
#include <STDLIB.H>6 j' T: p' q* N2 c. z- H) N
#include <STDIO.H>0 t; u4 Z- G4 n, N: B
#include <CONIO.H></FONT></P>
! ?/ E- c9 W$ m5 Q  i3 K<P><FONT color=#0000ff>int main(void)
9 D* h4 H$ h- E+ x1 r$ i3 F; T  j{ 6 x- Z% R; J1 j) j, L% o& j# N
/* request auto detection */ ) G* s8 r9 W  }% \! @
int gdriver = DETECT, gmode, errorcode; + e% b# o( i- f1 K9 O5 E8 ^- D" n
int color, maxcolor, ht; " I: C; u! u1 \0 M. f: a
int y = 10;   B0 ?6 X& ^; @$ `- {& q4 n/ C
char msg[80]; </FONT></P>
0 m+ i+ I% g% P8 {& q<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' x' z$ l$ l6 w9 j
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
. X/ l2 Q* Y2 e& Q9 I, Q<P><FONT color=#0000ff>/* read result of initialization */
9 `1 D3 V. ]8 b* [3 G9 r9 ^errorcode = graphresult();
4 m+ s; h% r/ [3 M1 L' S3 a) n. _8 tif (errorcode != grOk) /* an error occurred */
3 L8 L* r; g8 j- x{ ; h3 }* s6 f+ Y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * o) {' J2 a/ E2 N/ G
printf("Press any key to halt:"); " T8 O2 D& t5 j: g
getch();
0 T5 h# }8 F# _$ Bexit(1); /* terminate with an error code */ ' j% P$ W6 [5 q! ?6 d/ N$ A6 K! V% e
} </FONT></P>
/ b) ~: Q2 ?6 [/ F<P><FONT color=#0000ff>maxcolor = getmaxcolor();
2 ?6 x3 i1 K* l, G% xht = 2 * textheight("W"); </FONT></P>
( C# f# {4 N4 G% |9 r<P><FONT color=#0000ff>/* display the default colors */ 8 V7 w8 c) ]1 L" M. @& N
for (color=1; color&lt;=maxcolor; color++)
, @/ I( {- @9 S& U9 p& M3 G& ]{ : p+ S7 l. S, M% a" N. P1 y
setcolor(color); % C7 ^6 y/ q# ~0 D1 }, {
sprintf(msg, "Color: %d", color); 7 R7 S0 l* p0 ~
outtextxy(1, y, msg); 8 B+ u- ?3 m5 f  I
y += ht; ( c1 n5 k/ ?& ^
} </FONT></P>
: ^( b8 E/ v6 d+ D<P><FONT color=#0000ff>/* wait for a key */ 0 H+ Y% Z/ p7 y# B# h# m+ b5 n
getch(); </FONT></P>& E: ~% Z! w" c% A
<P><FONT color=#0000ff>/* black out the colors one by one */
! p$ Y* S# V3 Tfor (color=1; color&lt;=maxcolor; color++)
, `/ |; K0 i* Z( L( d3 H{
6 f1 M; W* J3 D0 gsetpalette(color, BLACK); 3 h" l6 b0 M/ q6 m
getch();
6 ~: F$ i0 \0 z0 T" Y} </FONT></P>
: c% _. ?0 x/ J; N" _<P><FONT color=#0000ff>/* clean up */
; x9 S9 H0 o9 {& p' g, oclosegraph();
6 Z: o; L. ^8 r; q4 T& O2 Preturn 0; * ~0 h4 i* Q  D4 ~/ B, X8 @+ e5 W
} / N6 m- j8 C' d$ A! P0 p* K6 x
</FONT>
5 Q4 X0 Y" k1 g! B( ~+ t/ H, _</P>6 o0 i* s, l6 t6 P9 f
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
% q, i! `" l2 @! K功 能: 定义IBM8514图形卡的颜色
+ a! Q! l! k; X( \( m, j6 g/ l  |; x用 法: void far setrgbpalette(int colornum, int red, int green, int blue); 0 q$ H) ~* A$ I
程序例: </P>. T1 Z+ r5 u, V5 S" x  w4 l1 v
<P><FONT color=#0000ff>#include <GRAPHICS.H>
& m: V8 g) B$ s  \/ L#include <STDLIB.H>6 K! K1 E/ N/ j; y; O9 i1 ~, H
#include <STDIO.H>2 Y8 N6 v' n9 E$ E* W6 A) N7 D5 @9 Y
#include <CONIO.H></FONT></P>
- I2 A  A# `( ^: U5 W: ^1 F<P><FONT color=#0000ff>int main(void)
( s* q  T  E" t- G% v{ ! `7 K$ ?; J: w) ^- l
/* select a driver and mode that supports the use */ 8 v4 M' k0 L1 ^, H
/* of the setrgbpalette function. */
2 m3 H# Q, E) A! I. T0 d2 cint gdriver = VGA, gmode = VGAHI, errorcode;
. p2 K. g* l/ A4 ]  C2 S( Xstruct palettetype pal;
; E5 a  ?$ K. k3 t, [3 qint i, ht, y, xmax; </FONT></P>
) q) L2 H$ U8 r3 o<P><FONT color=#0000ff>/* initialize graphics and local variables */
% M8 i1 [8 U) a9 ?7 L* l8 {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ M# D! z' g5 {3 N/ r/ n: h
<P><FONT color=#0000ff>/* read result of initialization */
( d8 D6 ]9 y2 t+ I8 merrorcode = graphresult();
8 I5 }3 f, s. V8 w8 |9 Lif (errorcode != grOk) /* an error occurred */
% J" ?8 s: [" L' x9 q3 F0 h{ 8 L* V8 Z+ X1 x5 M$ o3 N
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ ?8 G2 s( ]& wprintf("Press any key to halt:"); * G/ a+ O5 ~! l! p7 ^3 j& B
getch(); " q. ]5 ?9 v5 H, J
exit(1); /* terminate with an error code */ 5 m# |: s+ a+ c0 p
} </FONT></P>
$ `+ Q5 S; A# u1 g4 Y9 W<P><FONT color=#0000ff>/* grab a copy of the palette */
! X" S1 Q6 \$ e9 ?getpalette(&amp;pal); </FONT></P>, z# q& V" ?. `. z* v
<P><FONT color=#0000ff>/* create gray scale */
) q/ |: |* \2 r4 j1 _- Hfor (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
9 B% G# ~2 Q' O4 h<P><FONT color=#0000ff>/* display the gray scale */
# h6 O  H* u$ [- N0 aht = getmaxy() / 16;
. A; @; F* d: a; U9 _' exmax = getmaxx();
9 E$ z: v9 N7 S6 d. z3 Gy = 0; 9 [$ v' v; X; {* h5 m" Y/ y
for (i=0; i<PAL.SIZE; <br i++)> { 0 z/ A) ?1 m3 `" B6 l
setfillstyle(SOLID_FILL, i); 9 f* A6 O, c: Y% Q0 H* ]' u
bar(0, y, xmax, y+ht); $ y/ D9 r0 W" m0 z- r' ?
y += ht; : J8 A; V* T6 A0 g% v5 P
} </FONT></P>
* i# W: x, l+ y; v6 c<P><FONT color=#0000ff>/* clean up */
# n( K) I1 A1 g5 O/ p0 ]! w& {getch(); " X# d5 e# {/ \" `8 d
closegraph();
7 G- U. y6 ?. i6 \0 P  a$ jreturn 0;
; h2 ~& ?7 X8 u& B) M( o" c} ( X' e! G( N2 S* m7 z, c3 s% Y4 {
</FONT>
$ M# l  r4 d; g% q5 D4 |5 i6 t' f  P/ V5 j
</P>4 U2 w9 Y7 S! t% I* o
<P><FONT color=#ff0000>函数名: settextjustify </FONT>
6 Z( f! g2 V  Z( V+ X& V) X" j. H功 能: 为图形函数设置文本的对齐方式
# L. L) i+ t  r% H9 ~7 j3 [# [4 ]用 法: void far settextjustify(int horiz, int vert);
3 R8 O( T  Z. _+ H* @程序例: </P>! A( m6 B. Z4 W& t' W
<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 P, r8 t% u+ g6 K$ ^0 n#include <STDLIB.H>
8 y( r; I# U; [2 E1 C#include <STDIO.H>
/ _: ^) K% X' E#include <CONIO.H></FONT></P>
: Q& u' F! _+ V/ m<P><FONT color=#0000ff>/* function prototype */
; I! |5 n" g5 F, p4 x" P$ R! ^5 uvoid xat(int x, int y); </FONT></P>
: y- u; V/ R0 K" k) q<P><FONT color=#0000ff>/* horizontal text justification settings */ + D) ^$ _* ?4 }) s
char *hjust[] = { "LEFT_TEXT", 7 |/ U  i* z! p: Q$ o% V' i: u* L8 e
"CENTER_TEXT",
  C; m; n' E7 X3 l5 S"RIGHT_TEXT"
/ k# b& i8 Q' R% }}; </FONT></P>( U, c0 C2 ~  q( W3 q
<P><FONT color=#0000ff>/* vertical text justification settings */
5 j+ P* ]" {$ B' p/ M" ~8 T: S0 dchar *vjust[] = { "LEFT_TEXT",
5 Z8 `2 R. z! j9 Q) P"CENTER_TEXT", + Z: `3 U! v8 a
"RIGHT_TEXT" + U  H: t, h7 S9 A4 f
}; </FONT></P>6 i5 Y4 ]* X* a# @/ W& c" F
<P><FONT color=#0000ff>int main(void)
* {: [1 @" n! _{
! E& v& [4 r. v1 X% U/* request auto detection */ + \. ]3 w& F/ k: `0 l: N- c
int gdriver = DETECT, gmode, errorcode;
" }* ^- A* p, c; j. K5 p  l5 d0 ]int midx, midy, hj, vj; - `: e, P- \3 p8 {
char msg[80]; </FONT></P>" c* a. z' X: `# I7 ^
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, P7 d( C5 v- pinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ v  g" I1 I! S4 n' r6 \% M
<P><FONT color=#0000ff>/* read result of initialization */ 8 K- R5 \/ ^8 C% _. U
errorcode = graphresult(); . ~8 c5 h! _9 o5 Q
if (errorcode != grOk) /* an error occurred */
, x( ^" |: L) g6 B) H" u{ + o9 N+ U  H* \" r3 p: C, A
printf("Graphics error: %s\n", grapherrormsg(errorcode));
2 s; I5 O; p! @: \* x4 Q, X8 l4 t& dprintf("Press any key to halt:"); " ^0 I5 L) q# G) C+ |  i- W) ^
getch(); & X0 W6 o' L2 A
exit(1); /* terminate with an error code */
. Y# Z$ ], q' j: ^4 u8 \5 t5 |1 J} </FONT></P>
2 @- z9 x7 k; {7 A/ X. M<P><FONT color=#0000ff>midx = getmaxx() / 2; + T/ y, Y8 c! h1 ?
midy = getmaxy() / 2; </FONT></P>  e; {# {+ T# N5 v% {  o* }2 m
<P><FONT color=#0000ff>/* loop through text justifications */ 0 t3 F' @" y$ w/ g) @  _" X4 _& p
for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
7 ?9 i7 V* B% Y. d* v$ ]( c) Kfor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)   S8 C! a" i. H* F4 J- h7 q' t" F# I
{
& u* E: C2 g- a* |4 d- _( a+ i/ kcleardevice(); 8 d6 Y& A, C, C0 o# e$ U+ e
/* set the text justification */
% r5 ~( `+ M, I2 {4 Jsettextjustify(hj, vj); </FONT></P>$ z2 t  P  |. O
<P><FONT color=#0000ff>/* create a message string */
' L/ C' H4 s; f# P7 J  d/ u/ r. |7 `sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
5 Q8 C, C" _8 L% N<P><FONT color=#0000ff>/* create cross hairs on the screen */
5 m- x* ~8 z% Z  v( N2 N" [: ?xat(midx, midy); </FONT></P>
$ Z8 K0 u. U* I/ ?  Z<P><FONT color=#0000ff>/* output the message */
3 ]8 q( U7 i! v6 }! H# youttextxy(midx, midy, msg);
; @  o  O+ Q6 f" x# M* Jgetch(); 3 v% d) ]% g8 l
} </FONT></P>
! o; g& s  v4 i<P><FONT color=#0000ff>/* clean up */ : N. h8 K" n6 B
closegraph();
9 J& Z! q  w) H; i" q) e) h# ?return 0; & J: U  s: C; H% o9 a
} </FONT></P>
( g8 ~& H8 H9 T- x$ Z" S<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
3 d7 @4 X8 B9 M* N, ?* s) S2 evoid xat(int x, int y) 4 D0 e, U* J/ H% l+ x3 u, f
{   i& ?- e( Y, f8 ~$ X9 W
line(x-4, y, x+4, y); ' L9 ~3 L0 _$ t- s
line(x, y-4, x, y+4);
* @5 ?* s4 R1 z7 b} </FONT>! U# n: v. m' |  X

6 q1 _0 J' I9 C  ?' x2 S</P>' v5 M4 P0 [0 H, D4 O* z
<P><FONT color=#ff0000>函数名: settextstyle </FONT>( p% f' c/ u: |; \. I
功 能: 为图形输出设置当前的文本属性
' H+ m) z& s, s1 a* D+ V用 法: void far settextstyle (int font, int direction, char size);
4 c  I1 E/ R% `. ~$ v. ]程序例: </P>4 M! i/ F8 o$ H0 c# a5 j4 J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* J% W) b8 ]1 ~7 D#include <STDLIB.H>
( C, T3 k; q$ H& s3 w: ?#include <STDIO.H>& h0 ?3 B( K; ]2 c! ^6 l. ?
#include <CONIO.H></FONT></P>
/ c5 G' [9 [  L- k" z! R<P><FONT color=#0000ff>/* the names of the text styles supported */ , d5 }* \% {+ p
char *fname[] = { "DEFAULT font",
( y3 V+ y; u4 g& c5 s/ C"TRIPLEX font",
9 x% F9 \! f; W! }"SMALL font",
, y; v& R- x7 K% S& V"SANS SERIF font", / v: ]: C# {$ S" D1 e/ b
"GOTHIC font"
" B3 }- q+ P* X}; </FONT></P>0 Y$ q$ e: N0 J/ B- K" L1 K  n
<P><FONT color=#0000ff>int main(void) / h5 S, _. d. t# Q" Q; n
{ / `( T1 D, r( r0 D3 [) J! z9 s
/* request auto detection */ ; c! C. ~: y+ M' [; L! F! |% X
int gdriver = DETECT, gmode, errorcode;
: z2 L, G5 u2 r  Yint style, midx, midy; ' u- W* r8 w9 ]! m3 |! c  y
int size = 1; </FONT></P>
' n$ ^' }, L' o7 C) r<P><FONT color=#0000ff>/* initialize graphics and local variables */
& r) n7 h% f1 zinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 A' @8 c4 G" ~# b& Q
<P><FONT color=#0000ff>/* read result of initialization */
: i# u* R$ c4 K" {$ h! c+ Gerrorcode = graphresult(); / V& t1 L3 B+ i" g) O5 @
if (errorcode != grOk) /* an error occurred */
. U* }* w0 }) B' }4 ?( S% z' o1 Q: C{
8 `8 y+ X+ Z/ _" C3 Gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * {. \, ^, ^( G: V' F* ~
printf("Press any key to halt:"); $ u( u" ?2 |/ o9 |' c
getch();
$ u  t. X5 Z7 Z9 Zexit(1); /* terminate with an error code */
5 H. L. Q% M8 l: k} </FONT></P>
  ^5 s9 ~& V. h$ O; ?- K6 `; M<P><FONT color=#0000ff>midx = getmaxx() / 2; * [4 F, _6 ~% e4 s; B9 g( h3 o
midy = getmaxy() / 2; </FONT></P>! w. a- T' J  g+ t) L! w
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>; S2 \& G& ]6 J
<P><FONT color=#0000ff>/* loop through the available text styles */ ' J8 L( J3 l9 s/ Q; z. k( @
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) % G1 z: f/ u4 i9 ]( U; x
{
* G+ F- a/ J% y7 ^& ^cleardevice(); : j+ z( K- c; i' {2 V
if (style == TRIPLEX_FONT) / K+ M! k, u7 P5 X# D% k) y; j
size = 4; </FONT></P>
7 N& K2 f; N7 x) D7 O0 w8 O<P><FONT color=#0000ff>/* select the text style */ " {' U* t) [, ?
settextstyle(style, HORIZ_DIR, size); </FONT></P>; w$ q, _! _) f2 T5 F# c
<P><FONT color=#0000ff>/* output a message */ 6 c, v( X8 I* t  i, E  b
outtextxy(midx, midy, fname[style]); $ L) m. O/ ]) C% o
getch();
& x  i! W. D* U- t} </FONT></P>
+ Q6 [6 j( E% M1 c+ n, w9 p" w, o<P><FONT color=#0000ff>/* clean up */
8 E: x" k1 O* u; pclosegraph();
2 A" ~  F- p! L2 I( Q) X- xreturn 0;
$ _5 Z9 `. o; Q2 b}
: M4 k: s! @/ A( I" x</FONT>0 {! B3 Z6 Q. b8 u6 z% w8 h9 c1 t
</P>
# ]/ G1 \+ n0 C: b<P><FONT color=#ff0000>函数名: settextstyle </FONT>
: E* K2 D) `/ F' c( |$ I( g功 能: 为图形输出设置当前的文本属性
8 [1 `7 i  e& b$ {3 L& [9 G' {用 法: void far settextstyle (int font, int direction, char size);
4 G# O; r% \/ T- o2 |程序例: </P>
3 H& I& L; @* Q<P><FONT color=#0000ff>#include <GRAPHICS.H>
" E" t: s( K( k4 N9 D, b' I: t#include <STDLIB.H>
7 }+ e) F0 O5 i# r" v+ O9 e' P8 e4 G#include <STDIO.H>& x' Y) O; I$ O
#include <CONIO.H></FONT></P>
" Y1 c' X5 g2 J  U<P><FONT color=#0000ff>/* the names of the text styles supported */
* Q4 o+ y6 w( N/ S& j; [char *fname[] = { "DEFAULT font",
- r0 ^/ ]; }. x' h. Q. ^; f/ H"TRIPLEX font",
* I- `, r- s8 \0 y, d"SMALL font",
' O; Z7 D$ M; \5 C7 H) A+ a"SANS SERIF font",
8 d4 k$ D( }4 A6 B"GOTHIC font"
* f( O7 Z5 h5 O; z6 e8 i- Q}; </FONT></P>9 J& j+ V+ M2 ~
<P><FONT color=#0000ff>int main(void) ) Q' ~& d0 c; L9 L/ b! z# y, h( Q
{ ( N6 q7 D7 \* a1 g
/* request auto detection */ 0 ^; Q4 P0 S: @/ t
int gdriver = DETECT, gmode, errorcode;
* |$ G2 t2 _% P  sint style, midx, midy;
! ~; E3 g1 ^/ p4 {int size = 1; </FONT></P>  U1 @0 s7 w$ T8 l
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) n% ]" @8 B, O1 B# }0 Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 K! Z  b! {; B' m<P><FONT color=#0000ff>/* read result of initialization */
, Z  G5 h4 O5 P4 h, l( C( zerrorcode = graphresult(); 3 Z% r6 b) s: O
if (errorcode != grOk) /* an error occurred */ 1 F1 m" }5 J+ S
{
4 S1 P( O' J% j: ^# T. d4 N1 Q% cprintf("Graphics error: %s\n", grapherrormsg(errorcode));
3 [0 E+ f0 `8 s6 ?+ Z% f5 B: wprintf("Press any key to halt:");
& n! T, ]0 n! V6 e$ o* ^! h/ qgetch(); ; W! M$ W* d0 @5 r( x: Z6 d' U, z
exit(1); /* terminate with an error code */
1 Q# k1 n0 b: L9 A} </FONT></P>
# o' M) d" v1 d( {, E<P><FONT color=#0000ff>midx = getmaxx() / 2;
. ?* y& o  c& J3 J! E1 S- s' Q% smidy = getmaxy() / 2; </FONT></P>
2 S1 A$ t  @/ h) Z<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
8 v% M1 Y! C5 r( \0 l- l4 V<P><FONT color=#0000ff>/* loop through the available text styles */
2 l( a* H) `" r7 F; v% Ofor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
8 x9 y$ W2 l, b1 {2 `{ 3 J; ]- W, o7 D/ b
cleardevice(); ) p# @; C9 {( \+ H7 [+ N/ U
if (style == TRIPLEX_FONT) 2 Q* z* z& I$ o7 ~
size = 4; </FONT></P>
% W3 ?$ S3 A8 \. O9 i/ S9 P% x' a3 p<P><FONT color=#0000ff>/* select the text style */ 0 n) t* ?" e; N& E6 M4 P% P$ Z
settextstyle(style, HORIZ_DIR, size); </FONT></P>
  _; H9 G; E9 |6 |  e* q<P><FONT color=#0000ff>/* output a message */ ! K# f" E3 a# A- i5 v* X
outtextxy(midx, midy, fname[style]); 0 k% G; L$ F% Q2 j
getch();
/ W* B( l3 @$ H5 A8 H5 E! ?} </FONT></P>
, n, o: {8 I/ P<P><FONT color=#0000ff>/* clean up */
3 _5 m" ?) a& {# {1 J; qclosegraph();
1 N, G' `6 s& I5 X0 k% m5 mreturn 0; " r$ T" p7 T2 c  |6 j  ^
} </FONT>
3 m6 [4 G/ v' l$ O* |
" ]# B7 r/ M0 p</P>
& w( {% \2 n0 Q" t$ t. F<P><FONT color=#ff0000>函数名: settime </FONT>1 Y  D* A  a/ t+ f+ a4 W5 g& c& [0 a
功 能: 设置系统时间 ; Z/ s1 e9 ^. g
用 法: void settime(struct time *timep); 5 ~' x, ?9 |1 {( O2 h! K" V
程序例: </P>
7 r! O; W0 G% j# |" J& n( X# R<P><FONT color=#0000ff>#include <STDIO.H># t2 L* u# }7 ^9 N  @" q! O0 L
#include <DOS.H></FONT></P>" D; B: [' h& m5 r
<P><FONT color=#0000ff>int main(void) . M3 r0 d6 I* H: n
{ & q$ U; H& p: z! B" M
struct time t; </FONT></P>
# ^; I" Y0 P/ m8 C<P><FONT color=#0000ff>gettime(&amp;t);
* [5 O/ l% x0 J: A! \printf("The current minute is: %d\n", t.ti_min); 5 Q) B( s: `+ P
printf("The current hour is: %d\n", t.ti_hour); + {# _9 j4 }4 L  Y$ j2 H/ q0 ?# N6 B# G
printf("The current hundredth of a second is: %d\n", t.ti_hund);
- b& ^8 \) Z( V9 |8 @! B! Cprintf("The current second is: %d\n", t.ti_sec); </FONT></P># W+ Z! A- v+ K# j6 s
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */ 1 L) A7 t% h4 {$ R3 }
t.ti_min++;
0 O9 m; W5 I) M7 Nsettime(&amp;t); </FONT></P>$ X7 k1 a+ \! x, _
<P><FONT color=#0000ff>return 0;
0 F- ]9 x0 e1 W  O5 _( w} </FONT>- Z$ o& {+ r4 U7 S1 v+ M2 \8 _

, j7 k+ `/ W. j1 L6 ~  X7 s+ s</P>
2 t6 o0 A# T3 k- `<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
, b' E: J1 j1 Q) R1 N7 x功 能: 为矢量字体改变字符宽度和高度 $ w! e  i$ T* f, Y% L# i
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
% h! g2 y5 Y+ L% }$ f9 N. s程序例: </P>
8 |! c; R: E- @* f2 a$ R( w9 ?<P><FONT color=#0000ff>#include <GRAPHICS.H>
3 C& b5 p& }" B5 q( m; c" c! `#include <STDLIB.H>
0 c# R! m$ D* ^% P+ [#include <STDIO.H>
) S9 C' c! v4 N- `/ I#include <CONIO.H></FONT></P>" w+ S: t3 _! P! m1 X8 o# R
<P><FONT color=#0000ff>int main(void) ! ^; r) R, p7 @$ N% d7 t" @
{
) C8 C" \3 P/ l. |) W/* request autodetection */
3 L' ^5 G! T/ H5 Uint gdriver = DETECT, gmode, errorcode; </FONT></P>
& e6 c, K) g/ T) V<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; G" v1 o; J; P% G
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 j# s. Q/ |; P4 A  r2 A
<P><FONT color=#0000ff>/* read result of initialization */
, c  r9 t6 z' _/ x3 aerrorcode = graphresult(); ( e. F( [+ J7 a# `5 W
if (errorcode != grOk) /* an error occurred */
) R/ U5 B" `. d) \8 Z# @{
, n! L: ^" l7 ~/ `8 [' Dprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * [6 S! j) X  J8 z
printf("Press any key to halt:"); % L7 c3 q5 Y) E
getch();
$ ~6 n) y- }+ c8 J6 G* h+ e$ Mexit(1); /* terminate with an error code */ 8 H) s6 C* @: Y, m0 h- K  r
} </FONT></P>
1 L$ w% C8 X" x6 r! W) j* X<P><FONT color=#0000ff>/* select a text style */ 4 V+ R2 t* g4 ~6 Q$ L# ^* ~
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>$ F) f. Q0 D6 ~6 g( u$ {
<P><FONT color=#0000ff>/* move to the text starting position */ ( t- R% J$ k3 \, b
moveto(0, getmaxy() / 2); </FONT></P>( ]: @# i; V  M2 w) A
<P><FONT color=#0000ff>/* output some normal text */ + m. @: `4 M* _% O0 [& N4 A4 F. G
outtext("Norm "); </FONT></P>
! \9 E& |6 S- n4 L/ b<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ 0 R( n3 ^9 Q" R
setusercharsize(1, 3, 1, 1); . D+ m$ i0 Y7 Y* ~: r2 G0 g4 i2 ]% V
outtext("Short "); </FONT></P>- d: m5 c* E/ |7 s
<P><FONT color=#0000ff>/* make the text 3 times normal width */
7 `2 a' K5 H" usetusercharsize(3, 1, 1, 1); ; ^$ k) B5 _. \3 e2 J, y
outtext("Wide"); </FONT></P>
5 i$ G4 R; a, |4 J1 s5 L<P><FONT color=#0000ff>/* clean up */ $ T  s' a" K3 o6 o8 ~
getch();
" c' |0 y( I" w9 \0 D$ S/ {closegraph(); . |" b0 S  o& \1 b" c
return 0; . g  x% Q0 A4 p! t' I- k
} </FONT>
" T/ f* z: D2 E) _</P>7 f4 @6 w# p* O6 q" \
<P><FONT color=#ff0000>函数名: setvbuf </FONT>" Y* s. e5 n4 `- s4 z% {
功 能: 把缓冲区与流相关 - y. ^# L, D$ f2 F5 U
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
4 H! k( q) a+ X/ J2 ]+ n程序例: </P>4 x2 F) z" X+ i2 O5 x5 V: O: @- O
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
8 I6 C1 Q1 E$ b4 |/ o<P><FONT color=#0000ff>int main(void) 1 B( O$ ?$ k! M- G0 b5 c
{ 1 [1 a. D8 J' \. h$ Z8 L
FILE *input, *output; 0 R' T8 E* i6 G& w1 {( w
char bufr[512]; </FONT></P>
6 T3 \4 U6 {" _<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
# H) Y3 e/ c* x+ Q) X7 E  boutput = fopen("file.out", "w"); </FONT></P>% S9 z# t; V) o4 k
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,
5 _* M0 D, B0 z. `! Xusing our own character buffer */ 0 F1 N8 N$ N; B, Y" A9 ~* c% E/ Q, O
if (setvbuf(input, bufr, _IOFBF, 512) != 0) 1 f2 S1 w! X( Q2 ~, U1 N/ w
printf("failed to set up buffer for input file\n"); 3 g) e  [, w" `& T  a6 E
else 5 u1 A' Z1 c( }" G. b; n# c
printf("buffer set up for input file\n"); </FONT></P>
0 t5 }. a- H# l4 s$ ?/ r9 f, j6 k<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
$ g* p* H- a; }/ m3 n( ]' O: D# [will be obtained through an indirect call to malloc */
! k/ ?9 }% J- G8 T' xif (setvbuf(output, NULL, _IOLBF, 132) != 0) & l6 q7 y; R4 {. y6 d+ ^( J  ^  w
printf("failed to set up buffer for output file\n"); / z" v, L+ L+ l# r. W
else
' ?5 R' n" e9 Xprintf("buffer set up for output file\n"); </FONT></P>5 h5 d# X( [+ E, @" k0 o
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
" x, z$ W5 C7 x4 G# K4 L% k<P><FONT color=#0000ff>/* close files */
+ j0 w( j  L  `/ Y6 z1 Y) ]fclose(input);
% i! N7 [) ^, Sfclose(output); & l7 u: A* y" s
return 0;
1 ~( Z8 V/ ]4 B3 q& p+ l& Q}
5 J& G/ B' {5 {% F# |& Y9 Y</FONT>
0 {0 O% ~" y( g5 J8 X
* s+ V- Y. _% j" G  A  {: i</P>/ R$ z$ k5 k& o! b. }7 {- |- {
<P><FONT color=#ff0000>函数名: setvect </FONT>) y" d' K; n2 p, ]/ D* h
功 能: 设置中断矢量入口 0 {1 S: [1 Q+ g1 S. {3 g
用 法: void setvect(int intr_num, void interrupt(*isr)());
7 ~* Y) U8 a) [: E& o程序例: </P>
& |* x; g' n' ?# C2 h+ o( i( S<P><FONT color=#0000ff>/***NOTE: % Y( d2 v# l! r5 o7 \
This is an interrupt service routine. You can NOT compile this 0 _2 h4 {$ G! e, P, T% O, Q) r
program with Test Stack Overflow turned on and get an executable % S" A" ]; `# j
file which will operate correctly. */ </FONT></P>
" z9 @) T5 `$ b" O( w<P><FONT color=#0000ff>#include <STDIO.H>
5 C  R1 ]$ L& d#include <DOS.H>6 v' V1 D3 T; e
#include <CONIO.H></FONT></P>; V# o4 T$ b. V% A: V. {0 O
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>9 b  ]" b' W2 K3 M
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>$ }& L. E  `! f. v( d4 l4 {0 G
<P><FONT color=#0000ff>int count=0; </FONT></P>
' p1 C; p1 M; b7 D+ R4 c<P><FONT color=#0000ff>void interrupt handler(void)
9 Y7 `3 @/ T2 P( F. H{ . C1 \) {2 x& M  z% C
/* increase the global counter */
- I' u+ G* u1 \$ j  Ucount++; </FONT></P>
. M1 p% e+ ?4 A% N9 y( n<P><FONT color=#0000ff>/* call the old routine */ 3 \$ V( a1 I* z& ~7 X
oldhandler();
5 M8 ^8 o' b  i$ ]! x} </FONT></P># F% E/ V  R8 u" T0 q
<P><FONT color=#0000ff>int main(void) 7 L9 j" i: U+ j8 K
{
8 M" X9 N( z( A" W/ O, S/* save the old interrupt vector */
. }3 ^& }/ I  aoldhandler = getvect(INTR); </FONT></P>
4 E: B4 F- v+ j: {5 j<P><FONT color=#0000ff>/* install the new interrupt handler */ 5 N, ~+ b- U. M2 l1 e
setvect(INTR, handler); </FONT></P>5 z0 y: ?  q, _, f) }, B, K( i
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
, L8 C" \9 N0 k* @/ N4 Cwhile (count &lt; 20) ) G7 ?$ c# \1 U6 J% {( |4 c: h
printf("count is %d\n",count); </FONT></P>6 R$ ?7 X8 l8 P% y8 l
<P><FONT color=#0000ff>/* reset the old interrupt handler */
, g& U4 ~1 L. X0 bsetvect(INTR, oldhandler); </FONT></P>% ]1 f5 D# r3 M
<P><FONT color=#0000ff>return 0;
- L0 a6 J' j9 S& M}
9 v+ l; i4 ~  a/ _7 b- Z3 r</FONT>
2 M" j4 j7 ]2 ~% v2 q( c</P>" @  H5 Q) d1 c# ]) O# f" X0 ~6 l
<P><FONT color=#ff0000>函数名: setverify </FONT>1 l& F* O! r9 J4 H8 L) e
功 能: 设置验证状态 $ s1 V4 P$ s" \0 w- g+ X  l
用 法: void setverify(int value); ( E2 l6 ?3 a& f4 B; V! B
程序例: </P>4 B/ u8 h5 p; I4 I3 R4 d) P: E
<P><FONT color=#0000ff>#include <STDIO.H>- {6 h9 e3 U: y5 a2 _2 ~
#include <CONIO.H>% e, g8 ~$ f; q
#include <DOS.H></FONT></P>* [4 c8 u" }4 c) L0 {3 U* a1 h8 N( p
<P><FONT color=#0000ff>int main(void) 6 [1 b1 u: _2 ^0 i# ~
{
& N5 W5 m0 c: Y/ E8 H' r, xint verify_flag; </FONT></P>
9 D3 f% o! p3 ?3 Q' S0 _  e<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); 1 \+ f" l0 P5 j) M- |0 o
printf("Enter 1 to set verify flag on\n"); </FONT></P>
% S3 U) L' t4 R/ c( @<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>+ |, J* P, X8 a- r* x# i! F
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>
9 [4 o+ n; c6 e<P><FONT color=#0000ff>if (getverify()) ) Y) X0 m- o; |# B- N
printf("DOS verify flag is on\n");
: D. U" k4 j* q% V$ a6 Eelse , v0 |4 ~- G7 n5 P4 `; a/ S' b
printf("DOS verify flag is off\n"); </FONT></P>. v' H7 e! u/ u: J: @5 Q0 x/ o* s
<P><FONT color=#0000ff>return 0;
2 I$ }0 \& j; T}
+ ]7 l8 e3 E, v: l2 M) ~0 L<FONT color=#ff0000>
  Q3 [5 U- Z( |# Z' B# R1 l</FONT></FONT></P>
: p. C0 Q( J' G) y: m0 z, H<P><FONT color=#ff0000>函数名: setviewport </FONT>" k1 s& p4 U' {% @% R: T/ j
功 能: 为图形输出设置当前视口
& y, S# v, t# X% @( r6 ~用 法: void far setviewport(int left, int top, int right, % B( X8 v4 I. F+ D- q+ o7 u
int bottom, int clipflag);
4 x4 R0 ]8 f- G1 p) {  k程序例: </P>; S6 U9 K. Q, ?- T. g
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" @/ F! |. F" B- ^/ j#include <STDLIB.H>
# v+ K0 L/ N/ R2 q#include <STDIO.H>) Q# o8 M8 z, m  F0 J% v" R  s
#include <CONIO.H></FONT></P>3 ?9 n$ o" J2 f+ Y
<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
0 y+ U& V" v" U$ j! T" @) T<P><FONT color=#0000ff>int main(void)
- ~: g; h) `1 }7 V. p& y{
4 `& V& z. F# S! |* X" M/* request auto detection */
0 M( Z. H" ^) [8 l( |int gdriver = DETECT, gmode, errorcode; </FONT></P>' b$ p# n& w( F; A
<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 r/ q0 Z6 Z/ [* _initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 }9 d2 R+ E- E: Y) u( p
<P><FONT color=#0000ff>/* read result of initialization */
) \. O: ^  E3 T5 @1 |0 o5 }% perrorcode = graphresult();
0 D7 @& p4 B& l% rif (errorcode != grOk) /* an error occurred */ + L9 S. P" x" r2 f, S
{
7 M' M" m7 b3 v( T6 m4 ], _. iprintf("Graphics error: %s\n", grapherrormsg(errorcode));
8 E% D) U. y% g/ Qprintf("Press any key to halt:"); & a+ X, [9 a' r, O7 l9 i
getch();
" @$ k8 b9 N2 Z1 pexit(1); /* terminate with an error code */
2 l2 L- V& `1 |" @} </FONT></P>
  F, V9 M/ u) v8 e( J<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
9 z1 y& {" N' ?' A2 g. }& y<P><FONT color=#0000ff>/* message in default full-screen viewport */ 4 x; L% N+ Y9 F* T8 m) _& X
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>2 c* x+ c1 F) u; ~! l
<P><FONT color=#0000ff>/* create a smaller viewport */
1 _% t$ Z% Z" A3 `; ?setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
4 S  P' s+ m7 D1 p0 H6 F$ f<P><FONT color=#0000ff>/* display some text */
" n5 z# a- e6 A7 G5 o* i, Qouttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>3 o! f2 B# u. K: l" j: C
<P><FONT color=#0000ff>/* clean up */ 9 u" \# m4 u: g: _& P& \
getch(); ; F4 ^7 R" i; l0 w, V
closegraph(); 4 c$ e! W% `1 ~1 _/ E7 L
return 0; ! a$ m5 z7 ^9 p' M& f
} 8 ?/ H7 G* d" {
</FONT>! J$ I& g% @3 C2 i5 U- W1 S5 c3 O, N: G
</P>. y- m7 F2 t' |4 T2 z* i
<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
  E4 o  d: z- s0 }$ j功 能: 设置可见图形页号
; C$ O4 X6 w- [0 q. \% p用 法: void far setvisualpage(int pagenum); + {* p! }8 w; `
程序例: </P>; T  s: v2 D* Y
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: W, W3 q$ o1 ?& U9 _; L. P' Z#include <STDLIB.H>
5 E8 m) Z# A" G( Z#include <STDIO.H>
) x- [/ r& Q; e* b#include <CONIO.H></FONT></P>, m1 y; {' C& w% P2 A
<P><FONT color=#0000ff>int main(void) ) n2 ?, i' \( g( J5 }2 |# b8 v
{
/ T9 ?( ]" y) m$ @9 \/* select a driver and mode that supports */ $ x) j9 S4 o* X7 q, E' Z# F" t; a
/* multiple pages. */ : }; X' y1 \9 X! e: _, t
int gdriver = EGA, gmode = EGAHI, errorcode; + @; B( R7 M6 z
int x, y, ht; </FONT></P>
& B+ x1 h: l- j0 p7 i' F( s3 }( E<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 b+ Z( V) U; O( ?4 p  T+ einitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 |9 L. e  N0 O+ G! B/ w. s) g
<P><FONT color=#0000ff>/* read result of initialization */
( ]1 I: r! M/ b: U+ J6 m9 \errorcode = graphresult(); # b7 q& ~' _/ B  u
if (errorcode != grOk) /* an error occurred */ ) q( P* t, o. C' Q8 E+ H
{
  H" t0 t. ~- k9 q1 qprintf("Graphics error: %s\n", grapherrormsg(errorcode));
2 K3 P" u/ W, p+ E$ _5 Vprintf("Press any key to halt:");
, C/ |0 ?1 W) R* pgetch();
8 F: J' a8 \: u# f% b% A; Hexit(1); /* terminate with an error code */
' L9 t% u2 k- O& R! E5 {5 a} </FONT></P>
: ^! m) b" V% w$ D0 x* z3 Q<P><FONT color=#0000ff>x = getmaxx() / 2;
! `+ h! D/ U7 p) y# Ey = getmaxy() / 2; / k: N8 f& d* t4 @( u$ l
ht = textheight("W"); </FONT></P>% l# ?1 p) `+ g" P' |
<P><FONT color=#0000ff>/* select the off screen page for drawing */
5 m" u1 Z/ L, L! K# E# ]0 u. J& Zsetactivepage(1); </FONT></P>$ g/ E. {  o( ^! \! M
<P><FONT color=#0000ff>/* draw a line on page #1 */ 9 E( O( ~7 @  [/ D" @
line(0, 0, getmaxx(), getmaxy()); </FONT></P>! A6 H! B' @& C9 i5 l3 J
<P><FONT color=#0000ff>/* output a message on page #1 */ & M5 I* z" T% I
settextjustify(CENTER_TEXT, CENTER_TEXT); 6 q+ t, X8 c" @) J0 v2 k( w
outtextxy(x, y, "This is page #1:");
6 w" P7 j4 B5 \. E) a/ Kouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
) j+ P1 h# ]. ]& q! M<P><FONT color=#0000ff>/* select drawing to page #0 */ ! L, ~0 W* d" U2 q/ w: [) R
setactivepage(0); </FONT></P>$ H, B5 S4 O+ u# P/ O
<P><FONT color=#0000ff>/* output a message on page #0 */ ) U1 ?4 A  o' ~# b3 y
outtextxy(x, y, "This is page #0."); 1 M7 T' K. |1 b3 B& ?  F$ Q' W1 {/ b
outtextxy(x, y+ht, "Press any key to view page #1:");
1 v6 `0 V  ?  [& ~  N, ]getch(); </FONT></P>
$ y! {+ i) A9 B% W$ W% m$ u/ U  n1 Z; o<P><FONT color=#0000ff>/* select page #1 as the visible page */ ! ^; K& M* R' D  S
setvisualpage(1); </FONT></P>
+ w; f, G' d- C<P><FONT color=#0000ff>/* clean up */
3 F0 g3 A4 N6 ?4 h/ ~5 i5 m1 E$ Ngetch();
: J0 |, l# J) b. \- qclosegraph();
$ g) h) K: A* H. Vreturn 0;
; `& }$ A6 Z0 R} </FONT>: M0 z  o# j( P" @* a, Q( X# ?" M

, y) L3 f2 O( Y7 j) g9 }</P>7 U" h, f# B7 N/ @8 l  w8 z7 M1 w
<P><FONT color=#ff0000>函数名: setwritemode </FONT>) u0 F$ M' [* b9 L6 ^
功 能: 设置图形方式下画线的输出模式 * h) q7 o4 J) {. i7 `; P
用 法: void far setwritemode(int mode); 7 [" s# Y3 w; k! T, E) r5 k# T
程序例: </P>
& {8 x+ x+ @) C<P><FONT color=#0000ff>#include <GRAPHICS.H>
& {9 o, ^+ ~& G#include <STDLIB.H>4 I7 n( W& I6 G. J
#include <STDIO.H>1 n3 l8 h/ ]& [1 G
#include <CONIO.H></FONT></P>, h2 s; X2 ^% u2 O- i) f$ D3 V( {
<P><FONT color=#0000ff>int main()
) ]8 S0 v' I5 x+ S; i. N{
: `. Z9 H$ ~4 r& |/* request auto detection */
) L. {: R+ @( `/ }* u. z" Bint gdriver = DETECT, gmode, errorcode; & C0 Q7 N  n8 a3 r
int xmax, ymax; </FONT></P>4 C" u2 ?. o% Y& F- s9 L/ m
<P><FONT color=#0000ff>/* initialize graphics and local variables */ + C! |- y; r2 x$ {8 u) g4 e
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 Y% A. a- A6 O4 a7 r- Z! s" U<P><FONT color=#0000ff>/* read result of initialization */ 7 [. v7 C5 b5 Y
errorcode = graphresult(); 1 j$ y; |  U. K6 v# p5 ^
if (errorcode != grOk) /* an error occurred */ 2 ~" w; [$ {8 |6 f# x# c
{
! D  E, b* v) W. u. Dprintf("Graphics error: %s\n", grapherrormsg(errorcode));
' }8 `& |; C( w1 @/ o/ G5 gprintf("Press any key to halt:"); 5 _7 I! z- ~" T+ N- U
getch();
4 Q% M3 C9 s6 ~1 B/ Y. ?exit(1); /* terminate with an error code */
* l/ Z+ j1 F  G. {) r. g} </FONT></P>+ H1 i, q2 l" L: t. N
<P><FONT color=#0000ff>xmax = getmaxx(); . D0 r0 U& _! Y1 V* h) C
ymax = getmaxy(); </FONT></P>
1 y3 n! Y$ D$ h<P><FONT color=#0000ff>/* select XOR drawing mode */
- L, W, v+ u# m1 H7 N' e8 b/ q1 _setwritemode(XOR_PUT); </FONT></P>
# s! b  ?! ~  b; p+ g9 X$ [<P><FONT color=#0000ff>/* draw a line */
$ {3 t" `0 W, K5 Z" _3 hline(0, 0, xmax, ymax);
! A* x/ c6 b' W) G% Sgetch(); </FONT></P>6 Y8 q! Z; z& p. ^! [1 {
<P><FONT color=#0000ff>/* erase the line by drawing over it */ , O$ `, G# d/ z- L
line(0, 0, xmax, ymax);
+ Z  I1 ]( K+ A; G& O% zgetch(); </FONT></P>! u% c6 Y' C4 j7 P) R. p( {
<P><FONT color=#0000ff>/* select overwrite drawing mode */
4 \( F, {% P: \! Q. I( Asetwritemode(COPY_PUT); </FONT></P>+ K, `# D+ x) X/ }
<P><FONT color=#0000ff>/* draw a line */
$ C/ Q4 A* Q7 n3 u! Pline(0, 0, xmax, ymax); </FONT></P>
/ b* v% R4 D$ b- w" g1 k<P><FONT color=#0000ff>/* clean up */ " {' E& S( Z. S/ f! o5 m' b
getch();   }2 g4 s7 ^1 V3 M0 r- @: f
closegraph(); 6 I" w+ P! ]; L$ o$ Y; U
return 0;
* z8 [- [* W" F% U: F( q}
' }2 \8 l' V4 L8 ]; g# ?</FONT>3 o7 \( r8 X% q' R
</P>5 a4 d; S" v  j5 d
<P><FONT color=#ff0000>函数名: signal</FONT> / }( U1 e- H: P% _7 E
功 能: 设置某一信号的对应动作 : {6 J. r5 |1 X, S/ C  K
用 法: int signal(int sig, sigfun fname); % ]- k- |$ w9 L7 f" _9 o1 d) F
程序例: </P>
+ e3 M. G7 H" \" E2 E<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE,
4 W" O1 U! `" o3 d. _catches an integer overflow condition, makes an adjustment ! H' P' a2 q/ @$ h
to AX register, and returns. This example program MAY cause 3 f& z9 q9 ^1 m( @6 y
your computer to crash, and will produce runtime errors
9 P: s& i7 P* `) w8 E" ndepending on which memory model is used. " s* j, H8 o4 D  r: J" T
*/ </FONT></P>9 M( ~4 X% q4 p% v6 B) l
<P><FONT color=#0000ff>#pragma inline - c6 Y& a3 s- v, ]% h* i
#include <STDIO.H>
- Y6 Q) M$ F3 F; `' z5 [2 }7 R/ a#include <SIGNAL.H></FONT></P>) q$ I# H7 w; q, w
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
5 p) L( q/ q$ u0 W; @{
6 L8 n/ e0 z! s$ U% x) c- D4 }printf("Caught it!\n"); * ?- I5 e% j0 W" u! d0 [3 e% H
*(reglist + 8) = 3; /* make return AX = 3 */
- t- ]& m3 ^/ {3 x4 Q} </FONT></P>9 m: s! `& h& N. Z) S/ o
<P><FONT color=#0000ff>int main(void) & L, S9 Z& k: M; T# E
{ ) A6 a- I% c3 I- r
signal(SIGFPE, Catcher); ' g1 A. r. T4 C# `8 h8 l( \
asm mov ax,07FFFH /* AX = 32767 */ 3 O' [7 i. B6 S* a$ i% q; }
asm inc ax /* cause overflow */
( V2 F& c. `: U0 z) a& G& kasm into /* activate handler */ </FONT></P>) J% s, c8 q- j1 ]
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened,
" C# u% X  Q+ H; w, Wthere would have been another exception when the next 'into'
0 j% w* `$ [2 ]( Ywas executed after the 'dec' instruction. */
0 Q4 A; R; N0 b6 Y2 ?asm dec ax /* no overflow now */ 5 x, `' j) Z: M7 @
asm into /* doesn't activate */
2 R7 [# r" C, _' G5 Jreturn 0; 5 A& `* r% `; s; {2 I( h8 S
} & P' Q; K* [, N+ H- a
/ m& s$ H5 p# g

# a( {" `+ T7 d5 l/ p7 O9 U( T9 X</FONT></P>' ]* V# v# u. H: _/ k1 S1 _
<P><FONT color=#ff0000>函数名: sin </FONT>% `. M/ M; e( }4 X: T+ u! l+ b
功 能: 正弦函数
+ Y+ y  f# @+ c$ p6 ?用 法: double sin(double x);
/ j$ [- u6 C, @2 E( e* }程序例: </P>
, b. i0 K: I, m6 ^<P><FONT color=#0000ff>#include <STDIO.H>5 v9 l0 q0 A2 D3 q3 W8 h
#include <MATH.H></FONT></P>
# p# X  M1 E7 ~3 j$ s<P><FONT color=#0000ff>int main(void)
9 G+ N2 \; U: c: c7 s% ^4 b{
0 G" V/ V- C' C; B0 {double result, x = 0.5; </FONT></P>: C* d1 O( M) ]* d) H
<P><FONT color=#0000ff>result = sin(x);
! u' A5 o# ]4 Q$ iprintf("The sin() of %lf is %lf\n", x, result); . r1 I, X/ j( J
return 0; ! p+ [2 h- M4 |/ }, I; M# k- w" i
} % X0 z, Q* o7 K9 z- Z& [" X

" R; q( ^: u7 j# Q* K' X6 o</FONT></P>
# x' s& W4 f% X6 d. A3 u- |<P><FONT color=#ff0000>函数名: sinh </FONT>
" y: B% z, d& D0 d功 能: 双曲正弦函数
  ?# m% e1 b' y( d. l. n用 法: double sinh(double x);
- C9 I# g1 K- q4 k程序例: </P>
; v. Z, G* W8 m2 [7 S/ T) N3 f<P><FONT color=#0000ff>#include <STDIO.H>
, O( O3 I& p$ \, g( G#include <MATH.H></FONT></P>
, s4 P9 v/ z) D# m7 d<P><FONT color=#0000ff>int main(void) - u1 R' N# k0 `5 }8 s; v
{ " x8 C3 d6 H$ `( m3 A3 t5 x
double result, x = 0.5; </FONT></P>% f4 c: L* P0 L7 @) o
<P><FONT color=#0000ff>result = sinh(x); * u2 q8 o- Z' m" l
printf("The hyperbolic sin() of %lf is %lf\n", x, result);
- V4 L: e) \- `& J" ?return 0;   ?) ], A0 W& c& n
} 2 N" w, m0 B8 }/ S' [- n

7 p4 {9 {( J4 [) S& B, F% ?5 X+ b) c
</FONT></P>1 ?2 e6 @. L& U9 X9 y5 x$ P  x
<P><FONT color=#ff0000>函数名: sleep </FONT>9 d# S9 B! Q0 r
功 能: 执行挂起一段时间 1 z4 h, D$ j3 Z& c
用 法: unsigned sleep(unsigned seconds);
( P( o  w0 T  p9 k1 o程序例: </P>! S+ x. z9 a+ a: y2 s
<P><FONT color=#0000ff>#include <DOS.H>+ D# U. ~5 a+ f+ s* A& l
#include <STDIO.H></FONT></P>
6 I6 M( a3 _  f; c" \5 a/ }; ^8 E( Z<P><FONT color=#0000ff>int main(void)
% R, l$ s- }+ V8 L# M( Z{ + Y. h. L/ C$ n
int i; </FONT></P>+ n3 X5 s* U  v2 I* X* F* U
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
2 @0 u7 x0 Z1 Z" N  `{ " Q' l. O4 }! j: G" m
printf("Sleeping for %d seconds\n", i);
8 l. Z: R% `- q' t' `sleep(i); ) q0 d) K, q: x5 E1 N
} , v  @' w( }1 c. Q) |' e2 f7 U
return 0; 9 g2 D6 R' D& E/ b/ _7 R! e* `1 ~
}
3 b5 `2 H# b5 \/ m' G
6 w) j8 P. B. A; g4 f  }" n% N</FONT>8 G7 d+ Z/ T' M
</P>8 c: I6 Y6 D& U' f' |0 J# ]6 i% Z$ f
<P><FONT color=#ff0000>函数名: sopen </FONT>8 G, y7 A& V$ S
功 能: 打开一共享文件 " u; k  G; l4 a* z( @( p
用 法: int sopen(char *pathname, int access, int shflag, int permiss); + x, N8 {7 w0 l1 y! S2 t( A
程序例: </P>
' `5 p. z# s( x# k  Z<P><FONT color=#0000ff>#include <IO.H>+ ^! ~2 |" T4 J2 x3 P, ^* H
#include <FCNTL.H>4 C( }/ z/ _5 }2 s. J/ y" A6 N
#include <SYS\STAT.H>! z7 W, M& R2 o& v
#include <PROCESS.H>, J$ Q& b; O$ v1 t+ ^
#include <SHARE.H>( K8 G' S- @  I- Y
#include <STDIO.H></FONT></P># M6 C2 Y$ I& {- ~" t, t
<P><FONT color=#0000ff>int main(void)
0 n6 J9 W) k% G! S  h{ 2 `7 E/ ?! {6 _' w1 \) B3 Z& K+ Z9 W0 d
int handle; 4 n& F, H, o" x9 o. K0 Q" F- Y3 |
int status; </FONT></P>
6 B8 p6 M/ P$ e; ^3 e: I9 {<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>' W. W% F3 K/ m, H- z7 ?0 ?
<P><FONT color=#0000ff>if (!handle) 4 \  ^7 \5 ?: v) Z+ {
{
; ^+ @3 B  y/ w8 f; A/ v' R! g% f( \printf("sopen failed\n");
8 C! U* R( m& d& _- A: x" Rexit(1); + I  Q9 I5 r; X
} </FONT></P>
: I& X# e& T. r# l" m+ l<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
0 u7 A& t9 y1 W" q3 q  \* [if (status == 0)
5 S' ]+ J3 r3 I* X: `/ Kprintf("read/write access allowed\n");
4 v8 d6 ]6 {+ c/ b( [9 p# helse 9 Z. i/ p/ E. d3 x
printf("read/write access not allowed\n"); </FONT></P>
; i( B9 ^1 q! k  l. I. @" J<P><FONT color=#0000ff>close(handle); 5 C" A% e- ]* J3 J# s# A
return 0;
8 m5 J% @7 q7 ?" S}
5 B7 O$ X  X8 x7 O: b- r* z
, f7 V9 z) z4 E8 ?# C</FONT>
) i5 r, f* T2 f; o9 S</P>
# a8 {& V; _- o7 k) Y, C<P><FONT color=#ff0000>函数名: sound </FONT>
+ H" M: d# q5 [  H4 A功 能: 以指定频率打开PC扬声器
; s4 q/ {0 _/ Y9 M5 @用 法: void sound(unsigned frequency);
5 {6 M7 \3 }# W% a  K程序例: </P>
& L$ y( a* V/ }<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. % G' ]$ R) @) e1 u  |2 L& E
Your PC may not be able to emit a 7-Hz tone. */
; U$ ^9 X; o+ a& }3 p#include <DOS.H></FONT></P>
/ }4 B* u7 z4 ]- X/ d" R<P><FONT color=#0000ff>int main(void) * z/ t7 b& L/ t; l" h& |- V. J
{ / `9 p; _1 \/ H' O, B, d
sound(7);
7 X0 Q4 V/ I% Idelay(10000); 7 j  L) u; O( @! {. ?$ [9 j; x
nosound(); ' A% o2 h3 i4 J: }
return 0;
2 \' @2 G6 J( c4 S. y& C7 }4 M} </FONT>
  s# E$ Q! r8 D: V  G  `+ \, o: p3 Q* n, V6 `

$ m7 R; s* B% Q( `) L4 ^</P>
: K4 i" S1 Z6 C" Y' A<P><FONT color=#ff0000>函数名: spawnl </FONT>
4 v5 I) u0 Z* @9 p/ K, ?0 E功 能: 创建并运行子程序 ) W. I2 K  }2 _0 W
用 法: int spawnl(int mode, char *pathname, char *arg0,
( y9 V: [; Y# ^, t; r; i! a6 oarg1, ... argn, NULL);
* U: z! E) o, I( ~1 `( ^0 u程序例: </P>% k& O1 g+ W" L& o. ~
<P><FONT color=#0000ff>#include <PROCESS.H>
1 p. g+ q& q# \+ `0 u#include <STDIO.H>
+ u+ s) L2 d- p6 l; ^0 N#include <CONIO.H></FONT></P>. K- U, g* F1 v# [! Q' m& E
<P><FONT color=#0000ff>int main(void) 8 `5 h9 \: j1 M  U
{
3 V. c+ V* C; y: y* n8 o8 [8 dint result; </FONT></P>
- i7 f4 s) Q" I' n5 u+ R7 X2 M<P><FONT color=#0000ff>clrscr(); # G9 _' B7 ?/ m+ k& a2 z6 q4 Z
result = spawnl(P_WAIT, "tcc.exe", NULL); " v4 b  L) K/ a) s9 W
if (result == -1)
9 u5 T+ D* f! b; m{ 4 n- F% U  ]+ I4 J- P! L4 v
perror("Error from spawnl"); 9 o: `6 c# l  f& p, a
exit(1);
+ S# l5 D, d- }1 f  I5 y! a} , G# @/ ~6 b4 d; O. A: r
return 0;
9 b9 E: j2 S# l$ q8 n1 Y3 c}
# Y" j0 i% S* a$ t</FONT>
/ L6 y6 l( k; w# p" `  }</P># `9 N6 W2 l3 _4 U, j/ x
<P><FONT color=#ff0000>函数名: spawnle </FONT>
0 p( H  ~: E1 F8 W' h功 能: 创建并运行子程序
3 E  l% C/ F0 {+ i用 法: int spawnle(int mode, char *pathname, char *arg0, ' O. ]7 M  U# G" s- j, Z
arg1,..., argn, NULL);
& M" k1 z4 F3 c+ K! Z程序例: </P>
- M0 `, M7 F3 `6 a; w<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>  d/ H7 @# C5 ?
<P><FONT color=#0000ff>#include <PROCESS.H>
; Q, x+ \6 |& ^! H: w2 P#include <STDIO.H>, x2 E. x( i2 m4 n1 Y( Q. i( I
#include <CONIO.H></FONT></P>! \  A) p7 E# C5 q" p+ j+ b
<P><FONT color=#0000ff>int main(void) # Z1 x% K7 B% ?3 M9 S; p4 m4 @
{
+ r! U8 `- i5 R2 G* f- Wint result; </FONT></P>
% |3 Q& Q) t9 u9 b<P><FONT color=#0000ff>clrscr();
' {: j, U9 j! Z' l& s1 Hresult = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
' n6 a' l( y: F9 |3 }& ?8 Mif (result == -1) ( C# B( c4 w1 f6 y% O5 \& g
{ + z5 Y7 p3 b9 x1 ~% T
perror("Error from spawnle");
* s1 P% R7 \) L' x3 U: G% Vexit(1); 6 J5 @! {; ?7 L0 {* O; S
} 1 }& D) n) ]* Y! s9 N! c6 _! s/ H/ N
return 0; 0 Q5 ]. @7 z* w9 h4 J& b% Q
}
# ~, M) {) i" Z. D' f$ x
9 p. F. K( l4 u) q. r$ x  u, d0 |
</FONT></P>  o1 d0 I& L4 u- _4 w
<P><FONT color=#ff0000>函数名: sprintf </FONT>2 W- n/ G- H$ o1 J! V: Q7 J4 [: G
功 能: 送格式化输出到字符串中 9 y/ z1 t! D; ]5 Y, K
用 法: int sprintf(char *string, char *farmat [,argument,...]); 8 m, z: H- y3 N2 t; P. i
程序例: </P>
7 F; x- k5 Q- b: L; K<P><FONT color=#0000ff>#include <STDIO.H>2 s9 u3 V% n8 K) O! v
#include <MATH.H></FONT></P>
- U- j$ `. v" i6 L<P><FONT color=#0000ff>int main(void) 2 k3 ~' G. m  h; K
{
$ W/ n: F  Y3 u% Jchar buffer[80]; </FONT></P>5 B0 Z1 h# k' J9 r% x
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); " h& _, y1 l) e
puts(buffer); : `* ~% ~, a9 r- r" d
return 0;
+ D: Y( W* X+ w+ ~1 c3 |* @}
( `$ w: P) v) s1 t0 r( P! e! t</FONT>4 \7 R4 d  P* @6 J
</P>
1 T4 D$ f: |* S( T' }5 S& {" v<P><FONT color=#ff0000>函数名: sqrt </FONT>0 q3 f& Q# Y4 K4 z6 z$ x! \' n
功 能: 计算平方根 3 \9 T6 Z6 D9 R6 a1 O  h0 ?
用 法: double sqrt(double x);
& `4 J& E: o' w2 u( b程序例: </P>
7 y) U3 j2 f0 S9 L: [1 p  d' }<P><FONT color=#0000ff>#include <MATH.H>
" g1 h' ^  A3 ~8 i+ K) r1 t7 `0 _#include <STDIO.H></FONT></P># W4 s9 U2 k9 c1 g, ?( m9 o
<P><FONT color=#0000ff>int main(void) % m4 o- o1 y9 s7 ^
{ , m$ Y8 k: d* ~& M3 [
double x = 4.0, result; </FONT></P>* M! U4 J, U1 w& p3 |9 i+ o7 R
<P><FONT color=#0000ff>result = sqrt(x); * Z" S& z0 h0 S5 T! m
printf("The square root of %lf is %lf\n", x, result); , t: |$ y0 z. k! V$ v
return 0; ! }5 \, u) x: r& w) H& M+ N/ r; w8 }
} # e/ B: \: w; k2 U
</FONT></P>
7 s" D% H6 A: K' c<P><FONT color=#ff0000>函数名: srand </FONT>3 j/ n% f( R5 M5 `' p3 v
功 能: 初始化随机数发生器
1 r$ m. s3 m6 |用 法: void srand(unsigned seed);
; I( D  p% y5 F4 s5 @程序例: </P>6 U1 a8 H% q; _. }2 m
<P><FONT color=#0000ff>#include <STDLIB.H>
( b7 U' ?3 Y! L! ]& \% [#include <STDIO.H>
& B1 J( W6 [: I#include <TIME.H></FONT></P>
2 D& h5 s' n  ~# g# [4 e<P><FONT color=#0000ff>int main(void) + l: E7 q2 X8 i1 h0 j
{ 9 ^* I) P5 ?! e0 v1 c% }, @' m: s
int i; 8 q+ N( a. f& G2 j
time_t t; </FONT></P>
% t" v' U8 p* e- T<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
5 m: I' ~9 r0 [7 b- Uprintf("Ten random numbers from 0 to 99\n\n");
5 c" y! B/ w. z7 c& K; P$ [& Hfor(i=0; i&lt;10; i++)
9 M' a' p7 C+ u7 fprintf("%d\n", rand() % 100);
3 F9 {( R) I, ^& Yreturn 0; 0 s6 m$ N4 S/ D9 e6 L' B" V
} 7 u1 m3 I5 D. `3 y1 W
</FONT>* E7 d! T- z) w( ^1 o6 o' Y
</P>
: K2 s" z9 a7 Z<P><FONT color=#ff0000>函数名: sscanf </FONT>8 K% ^/ a" U3 P: J7 N1 B: r
功 能: 执行从字符串中的格式化输入 8 c1 q% R2 g- O  c' L
用 法: int sscanf(char *string, char *format[,argument,...]);
. ~# S  }: I# m2 L程序例: </P>
% q7 N' }# X8 O( T% e4 y; Q<P><FONT color=#0000ff>#include <STDIO.H>+ v% w6 Z* G: ^  N) L
#include <CONIO.H></FONT></P>. G' t9 l+ L8 F( Y, t( q
<P><FONT color=#0000ff>int main(void)
  `" ?* g/ Y1 y{
% D: H+ C$ P8 _1 }; i9 u, [' Dchar label[20];
+ F3 J" i+ v0 u8 q# hchar name[20];
/ [7 h) {+ @4 W% k% w/ n) D  }int entries = 0;
( r, A* t9 q  x& [int loop, age;
- [; ?6 K1 ]) G1 t' y$ z, _1 Udouble salary; </FONT></P>5 m* i9 G& Z. `+ g# }, I5 K9 Z
<P><FONT color=#0000ff>struct Entry_struct
) k7 j5 Q. k6 o: i$ |2 }, I4 r0 N{
% m' a: n# t, d! |0 [! B  `char name[20];
3 T' R) n9 T; h' O& p2 y: f! s+ Uint age; # S* S, d# a: |% y& K
float salary;
" ^. B2 O" o5 @' Q8 i; l} entry[20]; </FONT></P>- a% n' N/ Y4 n# }, [/ q6 c( u
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
  F/ K; v7 [, M. s7 Pprintf("\n\nPlease enter a label for the chart: "); # x  d- I* f7 z/ p3 ]* C' C
scanf("%20s", label);
, a% ^9 [# [4 }( j9 w1 a- K( m" Wfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
. |6 U2 U5 N  T* v<P><FONT color=#0000ff>/* Input number of entries as an integer */ 9 `" t; K. `( T: n6 `
printf("How many entries will there be? (less than 20) "); : d4 Q' {3 s! t, P- `; m7 `8 L
scanf("%d", &amp;entries);
' w( I$ I4 o1 R  z' Kfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>4 S1 K2 a8 x$ E$ y* Y
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ , j; [0 s6 z* k9 |4 w
for (loop=0;loop<ENTRIES;++LOOP)
6 q: b; `, i& y# c' z {
8 |5 o$ S. R! J4 S) x5 A% fprintf("Entry %d\n", loop);
# a9 w) ^' T+ y  @. Q0 C$ Eprintf(" Name : ");
" b, J% `1 R. I4 Y5 A5 S2 Oscanf("%[A-Za-z]", entry[loop].name); & D/ x( H8 `' h- K& I3 m
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>0 [' x9 w% a0 \. b! Y
<P><FONT color=#0000ff>/* input an age as an integer */ ( ]  V1 a- t. Z+ @
printf(" Age : ");
2 t* }# b% Y8 c2 D4 hscanf("%d", &amp;entry[loop].age);
3 B0 `9 R9 Z2 k/ c  _fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>; p8 j0 b8 f$ M/ L  Q; j
<P><FONT color=#0000ff>/* input a salary as a float */ ) {8 O. J2 S( g2 l6 W
printf(" Salary : "); 1 K7 c# _. {9 {- g
scanf("%f", &amp;entry[loop].salary);
5 Y) Y: b; Y2 k1 ^; P# e1 ~: [fflush(stdin); /* flush the input stream in case of bad input */ / k, `9 X2 X" F4 \) ~/ w& O
} </FONT></P>6 ]+ ~0 y; K9 d& J+ f" |4 {' k
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
; Q+ q( f9 d' O; v; A" ]printf("\nPlease enter your name, age and salary\n");
/ o4 y- I! V* y* y% m) r$ yscanf("%20s %d %lf", name, &amp;age, &amp;salary); * F' Y) z5 j% q" f
</FONT></P>+ k/ D/ d1 b8 t" u; `' y
<P><FONT color=#0000ff>/* Print out the data that was input */ 8 i' {9 D) J8 a7 {3 p
printf("\n\nTable %s\n",label);
( f8 [* Q5 X5 f! A7 L* j/ r& T7 oprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary); % N2 z7 i3 T8 K  M9 c$ S$ L
printf("-----------------------------------------------------\n"); 9 \5 y3 p; ^8 k$ _* P5 }+ {& v# R
for (loop=0;loop<ENTRIES;++LOOP)
$ ^- c$ c' d" F# L+ ?. o printf("%4d | %-20s | %5d | %15.2lf\n", 2 l8 g/ j' O8 I# i: [* K
loop + 1,
- B0 p7 a8 @9 N, z1 B3 I9 U2 Tentry[loop].name,
/ a( K) Y0 y: i# K; j0 V" Gentry[loop].age,
# X4 S) G1 d" }* b/ B. mentry[loop].salary);
* z8 `8 E! D2 U% v0 g8 B6 }printf("-----------------------------------------------------\n");
' m" _( j: Q9 k1 v, Hreturn 0; ' x- `3 m3 u, [7 O7 o
} + [8 G  f: f* H- y4 {, I8 p
3 w- @9 L2 W3 A5 m
</FONT></P>
6 U+ p; y7 c1 F<P><FONT color=#ff0000>函数名: stat </FONT>; ^6 B% _! |6 ^9 Q' P& Y9 B6 U
功 能: 读取打开文件信息
3 o( u- C; A  a. p' p4 l* U7 g% V! Q用 法: int stat(char *pathname, struct stat *buff); ( Z- |" E7 \, t5 j6 |
程序例: </P>4 u# a7 U& V* y( c" q0 @
<P><FONT color=#0000ff>#include <SYS\STAT.H>. P+ \1 K/ @' I/ ?
#include <STDIO.H>; |3 B: Q$ W+ b! t' K
#include <TIME.H></FONT></P>
: r1 ^& ]% E6 j4 H- b1 W( t<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>9 D- G1 _/ D( D% g0 J7 ~
<P><FONT color=#0000ff>int main(void)
& O, Y0 X9 @2 f/ I+ Q3 n/ v( V5 N{ : B, }' R4 T7 ?( ]
struct stat statbuf; 0 @% m  G5 I$ R! r; h
FILE *stream; </FONT></P>8 G5 ^0 \8 G( V- u' h, j+ a
<P><FONT color=#0000ff>/* open a file for update */ 8 m0 ^. O3 ~4 e  }8 m# ]  N
if ((stream = fopen(FILENAME, "w+")) == NULL)
. ~6 Q) T; Q! e4 i  K{
9 ?  c( b* f- M! v, Afprintf(stderr, "Cannot open output file.\n"); $ N4 i6 d; Y) y) F" [: e1 z; }
return(1); - [5 u+ r" }, X; t/ M
} </FONT></P>2 L+ }' y! v% E8 g4 X
<P><FONT color=#0000ff>/* get information about the file */
. V+ E  c! `+ r# F4 p6 `stat(FILENAME, &amp;statbuf); </FONT></P>. [: ?$ B0 Z7 k
<P><FONT color=#0000ff>fclose(stream); </FONT></P>
" A& z: ?! ]+ P* x# L9 u<P><FONT color=#0000ff>/* display the information returned */ $ c# a6 ]% P9 a$ m7 f5 P
if (statbuf.st_mode &amp; S_IFCHR) 7 G$ g) Z, B) T: R9 r( Y
printf("Handle refers to a device.\n"); 3 i6 \8 r, x: u# [  V
if (statbuf.st_mode &amp; S_IFREG) 5 Y. P: Q% P" Y0 d1 ~
printf("Handle refers to an ordinary file.\n"); . \% ^% k% A8 u4 [, u( J  U! s% P
if (statbuf.st_mode &amp; S_IREAD) - f3 Q# b, g2 q$ B: f
printf("User has read permission on file.\n");
3 H3 \3 l- n+ O* Z# zif (statbuf.st_mode &amp; S_IWRITE)
5 g8 k5 X4 r4 V# X2 Iprintf("User has write permission on file.\n"); </FONT></P># G) ?1 I! D+ |
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
/ Y) @; a" G6 p; e: Q  Bprintf("Size of file in bytes: %ld\n", statbuf.st_size); ' b0 n$ m3 ~0 h( `' X) M
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime)); ! Z! K: Q: J! p2 [: h& k% K
return 0; 5 D6 [7 a# H% f3 x- V& p+ m
} 0 A7 H& w& D; ~# `

4 ^4 K4 L! L0 ^1 J* U7 i) S</FONT>
  ~7 t* _2 w5 J, k/ }" W, z</P>
; F' y$ @' x3 U. u& ?& }& v<P><FONT color=#ff0000>函数名: _status87 </FONT>
9 h" h1 M2 w  w. y9 n( E. i功 能: 取浮点状态 8 T7 k1 y0 p* a
用 法: unsigned int _status87(void); 8 v! L$ |& f* M0 U; z6 b& R
程序例: </P>
0 [3 H5 n. `) p/ b' C: y<P><FONT color=#0000ff>#include <STDIO.H>* _6 v0 G3 Z  `- M" r
#include <FLOAT.H></FONT></P>) Q9 ^) x0 V$ p
<P><FONT color=#0000ff>int main(void) * r4 q. Y0 I  n2 W
{ 0 j1 s+ k+ M& ^2 j8 Z! y2 C0 Y, q
float x; 9 L3 q6 [* M4 n7 A# I9 K
double y = 1.5e-100; </FONT></P>
: r4 H* M7 {8 F" }<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
  e0 r: d! ]/ A( x2 [" |3 S- P' W+ @<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */ 6 U8 Z1 \' u  o0 T$ h- R% D( H
y = x; </FONT></P>! h) q, o  F: c. |( }# J2 i
<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87()); ! B* z' q: R# N9 u  K$ O- v
return 0;
, W7 h* P, o2 X. Y; j} % {5 w4 l0 ?; W$ G( T* d! X
</FONT>0 Q, b/ G8 e7 F2 F8 r% o
</P>
% ^% o+ n2 C/ O  X3 l2 u9 D<P><FONT color=#ff0000>函数名: stime </FONT>0 P, B5 @- [6 c: g- [; C# X7 v
功 能: 设置时间
4 S5 Y+ f" t" f1 W用 法: int stime(long *tp); 9 U/ N) W9 h5 e. j  [) J4 E
程序例: </P>+ D. K: q( E  A
<P><FONT color=#0000ff>#include <STDIO.H>1 r" w5 D3 `: V/ M$ ]6 z
#include <TIME.H>
7 _7 d- q8 }- j% V* t#include <DOS.H></FONT></P>. n* i) \4 W3 o& _: N
<P><FONT color=#0000ff>int main(void) 2 V5 q7 m. [. h- ~. Y. z
{ 5 M% w0 P( Z: K8 A$ H
time_t t;
0 f4 R! P& x6 p! V5 c3 v, mstruct tm *area; </FONT></P>
* O) U/ A; O2 B6 F; \<P><FONT color=#0000ff>t = time(NULL);
, q" n& b" l% E1 Warea = localtime(&amp;t);
% |* {( P6 x4 ]( j2 W: rprintf("Number of seconds since 1/1/1970 is: %ld\n", t);
+ `! I/ a) z, p1 n# c. qprintf("Local time is: %s", asctime(area)); </FONT></P>
/ r% V3 [5 O+ W<P><FONT color=#0000ff>t++;
" |0 I: B9 B/ `- o; z: p. V2 Warea = localtime(&amp;t); 2 e( K9 X( C1 T# t
printf("Add a second: %s", asctime(area)); </FONT></P>
4 B- O1 a$ l. J9 m  k<P><FONT color=#0000ff>t += 60; / C% p1 h2 y4 t
area = localtime(&amp;t);
1 y" t% d2 n' n* [printf("Add a minute: %s", asctime(area)); </FONT></P>' N8 I0 p2 N- `$ @/ I
<P><FONT color=#0000ff>t += 3600; ' i4 A4 {# O/ }& Y: G% O
area = localtime(&amp;t);
. b$ A) D0 a1 _  g+ I/ \printf("Add an hour: %s", asctime(area)); </FONT></P>1 X$ i7 ]* U& f7 J& N. A
<P><FONT color=#0000ff>t += 86400L;
( X7 D$ ^! ]; |/ xarea = localtime(&amp;t); 9 H# f7 f# J6 h& b% o+ T$ C
printf("Add a day: %s", asctime(area)); </FONT></P>* e' Z, v( ~2 \& P1 F% S0 w, o
<P><FONT color=#0000ff>t += 2592000L;
4 m4 ~5 K) |8 i: V- s' Warea = localtime(&amp;t);
9 G8 X  R# s6 f7 Z1 oprintf("Add a month: %s", asctime(area)); </FONT></P>0 p1 f- Y+ U  J
<P><FONT color=#0000ff>t += 31536000L; + X, e, n$ n( M3 L" S5 `. J
area = localtime(&amp;t);
: K9 l6 f1 U: Z0 I7 D- yprintf("Add a year: %s", asctime(area));
1 k" z. V/ N9 e0 p% S6 h3 {; }" [4 xreturn 0;
; g4 e0 A& z! w/ r, ]* K1 W) S} </FONT># `5 `+ S  X9 O7 P5 z5 B4 L! E
. t' p5 c: o( ]/ W* v0 v# y
6 u, f, D: T" S4 h2 l+ r
</P>
! l$ u" N8 N4 [7 p5 U0 K/ [* u<P><FONT color=#ff0000>函数名: stpcpy </FONT>9 G4 t- Y. b, ?1 R' T. w; b% d
功 能: 拷贝一个字符串到另一个
, x$ {# R: E, [8 q; N用 法: char *stpcpy(char *destin, char *source);
- C2 y4 [3 X2 F, Y& [程序例: </P>  g3 s' x5 w4 x
<P><FONT color=#0000ff>#include <STDIO.H>
* ^. `$ {( H; m7 I#include <STRING.H></FONT></P>; A6 X( s: O/ j; d% ~
<P><FONT color=#0000ff>int main(void) * o5 ~7 h' |5 k: X
{
! s6 @4 j  l% x+ _1 }; z8 Wchar string[10]; 3 ~' H+ d; \( {
char *str1 = "abcdefghi"; </FONT></P>
/ B1 W' ~4 U7 v9 ]<P><FONT color=#0000ff>stpcpy(string, str1); 4 c, w* r4 I8 I) K
printf("%s\n", string); : R+ \9 y! n. F9 P5 W. t  o/ ^: ]) Z
return 0;
$ [  N  x5 n, E8 V} $ K: e5 j+ N- I& O
2 u) ^# x$ v" B' _: D0 ^+ N0 x
</FONT>$ C# X5 w  M% O
</P>+ s3 h' `  C9 L0 ^0 ~
<P><FONT color=#ff0000>函数名: strcat </FONT>
; L; j7 x9 U5 [1 u% O功 能: 字符串拼接函数 - ]5 M+ n8 e8 P% F( ]2 n  s
用 法: char *strcat(char *destin, char *source);
+ a5 e" K3 v  N5 w; E程序例: </P>
: H% U( q! @, g( f/ |: B. e8 j<P><FONT color=#0000ff>#include <STRING.H>
* ~: w4 q; }% I5 _#include <STDIO.H></FONT></P>
& I# X  b! M, H+ U( d<P><FONT color=#0000ff>int main(void) & v1 V% X4 l6 j) o1 _3 ?! w
{ ; e9 X9 F2 j1 \/ x( b
char destination[25]; 6 o+ l1 A7 k) l' i3 W5 @
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
/ ^5 r* N! Y# `* i9 g+ {+ F1 \. U/ N<P><FONT color=#0000ff>strcpy(destination, Borland); - C% ~* A2 }  [+ I
strcat(destination, blank); ) @" I: \: F" `& K
strcat(destination, c); </FONT></P>
# S# Z6 O% E# x- Z' Q<P><FONT color=#0000ff>printf("%s\n", destination);
: z7 C# M& V) H; }1 ?* ^return 0; & \: X- n6 x6 U; V
} ) l- z: }# y8 U3 K. G
2 t% N1 D2 r7 R
</FONT><FONT color=#ff0000>
6 Q% ~- a! m& I- ~) N3 e2 w. X0 a</FONT></P>3 t/ O4 |5 E  a- ^
<P><FONT color=#ff0000>函数名: strchr </FONT>
" e. ?# N& }4 W* y" M, B0 \功 能: 在一个串中查找给定字符的第一个匹配之处\ / {" H  n" M5 {* T
用 法: char *strchr(char *str, char c); % P5 @+ h$ G% O+ G& [+ m( g  }
程序例: </P>
6 j6 p2 t5 j, T( Y) J! `5 {<P><FONT color=#0000ff>#include <STRING.H>- }2 ^' q4 M! L/ c  q6 d! l
#include <STDIO.H></FONT></P>
& _, A# j$ H5 g  f3 [  W<P><FONT color=#0000ff>int main(void)
; @$ Z; e  U2 u! D+ `( Q{
! |. C" m+ W+ K, Hchar string[15];
1 ^$ d/ c5 f5 O, j- C7 Achar *ptr, c = 'r'; </FONT></P>  u% o2 b8 b# @+ ]4 _
<P><FONT color=#0000ff>strcpy(string, "This is a string"); + X4 K4 s6 r' L6 D8 \) L! O! N* ^
ptr = strchr(string, c); 7 ?1 U5 j2 q2 x- m
if (ptr)
: {* [) K# w) L4 j# Eprintf("The character %c is at position: %d\n", c, ptr-string); 9 ]! _8 b3 e( `# F3 G0 |
else 8 i; J$ @5 X! w' u0 i- |
printf("The character was not found\n"); - X5 u) ~3 v, l! P! b- L# T
return 0; / P, E% {* @# f& `
}
# ?; Z0 C% B1 y' ]</FONT>+ C. X5 G/ c9 {  b( o- M. {' A2 T
) i3 x9 ~' C; X3 X
</P>- ~* @; L" Z* R  [$ U/ D
<P><FONT color=#ff0000>函数名: strcmp</FONT>
1 d9 V) Q/ j* P9 f3 ^" g功 能: 串比较
# n% a$ ^! h" D& \: E' C% E用 法: int strcmp(char *str1, char *str2);   \' T! i1 j* K/ {( V9 f
程序例: </P>
: G0 B7 C4 S% f; a) C, ~1 h<P><FONT color=#0000ff>#include <STRING.H>2 n1 b: k+ ^! \5 J. R
#include <STDIO.H></FONT></P>+ _, a) T, \+ w; s6 z
<P><FONT color=#0000ff>int main(void)
: ?. h, S8 q. U( e% m3 }{
% u$ i. _5 x# ~- {9 V* M4 Lchar *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
; J1 |, z: x' {/ Q) Vint ptr; </FONT></P>
5 ~! B, }8 C% z# n7 H' @7 B<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
) I: R) F* [7 z2 d' R2 E  v1 [if (ptr &gt; 0)
& ^4 ]% u2 H6 Sprintf("buffer 2 is greater than buffer 1\n"); $ A. p+ F& l8 C  V8 ]' [, s/ A
else
. b. P4 u7 P& k" R# v1 |; w1 Aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>2 t9 {3 f4 o( M) O0 v  z
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
5 t! Q% y6 |3 t) O  qif (ptr &gt; 0) 4 w0 C9 R( V0 y$ B, u
printf("buffer 2 is greater than buffer 3\n"); ! d& ~; L  X- y% S+ [+ ]( L- [
else
2 t5 a# O" I7 `+ gprintf("buffer 2 is less than buffer 3\n"); </FONT></P>
; o& N; U, d" V- s# x<P><FONT color=#0000ff>return 0; $ E& X/ f' E: h! k; o- u8 c; |
}
5 K- o, ?8 C& I1 x5 I) K$ E! p' }+ E9 V/ @" w
$ A3 D4 A' v1 P6 C, Y3 H! f" b) \: j/ T
</FONT></P>
! t. Z! j! r9 k9 Q<P><FONT color=#ff0000>函数名: strncmpi </FONT>
4 u  c  `9 U. C( X$ i# L功 能: 将一个串中的一部分与另一个串比较, 不管大小写
1 K% y" {0 K' j6 Q用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
  {6 B+ C8 S0 w% f5 L# j) B程序例: </P>! A6 P. ?( A1 h# o7 D9 ?
<P><FONT color=#0000ff>#include <STRING.H>
  j4 Y8 }" F2 H#include <STDIO.H></FONT></P># [6 H: l2 r; p, _
<P><FONT color=#0000ff>int main(void)
$ e+ q. N- m6 d; O" l' p* G  P{ ; v9 r- K. \  u8 J; |
char *buf1 = "BBB", *buf2 = "bbb";
0 J, O8 R# X1 `int ptr; </FONT></P>
3 b' e# e" x9 T<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>) ?8 D, w) W* Q
<P><FONT color=#0000ff>if (ptr &gt; 0) - W) @& E5 j+ ?
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
, Y$ G" t) V5 x$ d7 \) E, P/ G<P><FONT color=#0000ff>if (ptr &lt; 0)
# f8 O0 T7 V7 K- L  g% Aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>; g6 t$ l+ I" m! D- r5 t
<P><FONT color=#0000ff>if (ptr == 0)
8 X9 M0 v: ]0 o2 _4 K: k( H; tprintf("buffer 2 equals buffer 1\n"); </FONT></P># C  C5 f3 Q& E$ Q
<P><FONT color=#0000ff>return 0; 9 j3 T3 N, w2 |7 ~4 x
}
. P. G; I( B2 {; s; |8 K# O+ L, A1 s
</FONT>' ?$ {6 K! s( P7 @6 h% G7 r
</P>. p3 z( d9 [2 ]4 v8 O0 ~& B2 y
<P><FONT color=#ff0000>函数名: strcpy </FONT>; l/ R! g1 u- K" i- A- E7 C0 R: G# @
功 能: 串拷贝 ) W4 `( Q% J( P* \: R
用 法: char *strcpy(char *str1, char *str2);
  V+ O2 G8 c: k8 X( N程序例: </P>
" l. z% ^+ ~" E2 J. ~. A<P><FONT color=#0000ff>#include <STDIO.H>6 j4 d; S, H! M. r% p" s/ ?
#include <STRING.H></FONT></P>0 E  z, t, S4 C$ e. }' J
<P><FONT color=#0000ff>int main(void)
3 g) D1 U( J8 c2 [$ j  p& b6 A; M4 g{ ( N/ T" U% P: C" L6 @: }
char string[10]; 4 F2 p6 u' n+ q) I
char *str1 = "abcdefghi"; </FONT></P>7 q* T! K" X! O% D
<P><FONT color=#0000ff>strcpy(string, str1);
( ?( [5 Z2 ?2 s) v4 F3 y  Yprintf("%s\n", string); 8 g2 r; X) x3 Y  U5 l
return 0; 7 @; ^6 K$ V* \5 }' x/ B5 O
} ; H1 q; O! E9 k4 {
</FONT>
2 q$ K6 t! B0 P( d  Y. |( f. v9 {  h! `0 d
</P>: Z) Z9 v7 j9 a# y$ z9 t" t
<P><FONT color=#ff0000>函数名: strcspn </FONT>) S5 e; K8 I8 k
功 能: 在串中查找第一个给定字符集内容的段
( |" Z3 e! Z* D8 S$ D  C4 G用 法: int strcspn(char *str1, char *str2);
: A6 p* M. ~; g9 X  A) e+ v程序例: </P>7 ?; A, N! l( @) d$ m7 `
<P><FONT color=#0000ff>#include <STDIO.H>
7 F  c4 J; p: i- L9 z8 E' f#include <STRING.H>
' m6 E. I9 Q% A- J& x/ W#include <ALLOC.H></FONT></P>
: p! F: E! h- _$ B<P><FONT color=#0000ff>int main(void)
1 `$ y/ _: x& r4 ?9 B8 K{ & x! r2 b7 B9 A% A6 n; Z. a
char *string1 = "1234567890";   D- M: O1 Y' `, L
char *string2 = "747DC8";
9 Z3 O, ?  {% f0 M+ C" S9 T! oint length; </FONT></P>
. P9 R( z$ k" S; J  a<P><FONT color=#0000ff>length = strcspn(string1, string2);
7 q$ D; M3 w7 ^printf("Character where strings intersect is at position %d\n", length); </FONT></P>
2 }9 v* i5 y, k+ i: x/ a) b' v! Q7 T  m<P><FONT color=#0000ff>return 0; 1 J$ |" m" D7 P2 S# e; g0 w% }1 Y
}
- ~" D" I, }( P# ]/ Z" G5 p) g. j& \</FONT>; K& T" a8 r, [* r

7 |1 t! I6 Y7 B' z$ u- J</P>
' @0 m; I1 H4 |$ s<P><FONT color=#ff0000>函数名: strdup </FONT>
& c+ Z" f8 M: V8 P+ J功 能: 将串拷贝到新建的位置处
9 y: ]! m4 c' c) V0 n- A用 法: char *strdup(char *str); / }# i' p3 ^8 J" _" U4 x
程序例: </P>* l3 u6 w3 @4 u. u9 ?' Q' y0 L! f
<P><FONT color=#0000ff>#include <STDIO.H>
3 E" B6 }9 D( L9 e; B2 M/ y#include <STRING.H>
# y( G0 J* l: |7 r9 v4 S2 P#include <ALLOC.H></FONT></P>
/ A1 s5 j, O& S# L) Z  P- N<P><FONT color=#0000ff>int main(void)
1 |% _1 \0 K4 S  J6 o; l6 n{ $ m9 _- d4 Z/ R7 A% ?9 M
char *dup_str, *string = "abcde"; </FONT></P>+ s9 q" m: H. O! f# _
<P><FONT color=#0000ff>dup_str = strdup(string); " {  u% x! y. k) `/ X
printf("%s\n", dup_str);
) A; S& M  b4 ?; O. p; C; h* ]! I) Dfree(dup_str); </FONT></P>& g2 z5 i) `' [' q& Z
<P><FONT color=#0000ff>return 0; " t) [6 c  |; L3 n) Y
} $ @5 }. v* \; _

3 l$ r& h4 ^0 \+ p</FONT>
9 ~2 t) Q* y3 K3 e) F</P>
$ t* L2 j4 |7 @/ K  g<P><FONT color=#ff0000>函数名: stricmp </FONT>
" v& n  p, _, c% B5 G: D功 能: 以大小写不敏感方式比较两个串
. |  V3 C; D. E0 L( i- \用 法: int stricmp(char *str1, char *str2); 9 A+ D2 Y; O" p" g, I; m
程序例: </P>
, D2 z2 i, [- C+ d3 ]: u9 Z0 A% I<P><FONT color=#0000ff>#include <STRING.H>) i4 Y/ q2 {2 }
#include <STDIO.H></FONT></P>
4 Z+ b/ d* d6 J, ^# M1 o<P><FONT color=#0000ff>int main(void) $ U5 ]: m; w% f# X
{ 5 }3 c! B0 w2 ~0 k! b
char *buf1 = "BBB", *buf2 = "bbb";
( z) e, S' z1 {2 S! V/ Pint ptr; </FONT></P>
: O5 E0 z0 O+ `# G3 O! f<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
" b/ u7 g' E7 p2 V$ L" i$ [, d% K<P><FONT color=#0000ff>if (ptr &gt; 0) 4 {* r: I+ m4 a
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>0 X; X, [, i, g# X$ z0 l! @
<P><FONT color=#0000ff>if (ptr &lt; 0) " k, h7 C$ V' m: K! y
printf("buffer 2 is less than buffer 1\n"); </FONT></P>0 c- S! O2 S. t' L
<P><FONT color=#0000ff>if (ptr == 0) * q* n* g9 h! M; g
printf("buffer 2 equals buffer 1\n"); </FONT></P>
0 l0 f% J. a' Q! A! L! W! j+ G% `# {<P><FONT color=#0000ff>return 0; 2 A$ {& V6 v+ T: ]( z' ]/ Q
}
2 @' o/ J5 S( e4 K( V* N: }</FONT>
* E6 g% Y0 ]. I: b: o; H6 B: x</P># M/ {7 q: y" d& z  g
<P><FONT color=#ff0000>函数名: strerror </FONT>
$ }4 H/ C' o1 ?功 能: 返回指向错误信息字符串的指针
; b! [. m; G0 h1 K/ x用 法: char *strerror(int errnum);
! k; \1 s* a- e: F9 s: H: {7 M2 v程序例: </P>
: W0 [5 g9 X5 J# K* q/ R<P><FONT color=#0000ff>#include <STDIO.H>3 B8 z8 M7 z; @/ d6 k, d
#include <ERRNO.H></FONT></P>& g3 f6 K* ^. i$ \! R
<P><FONT color=#0000ff>int main(void) ; o9 [  X0 R  }% C. I( v
{ & A( G% Q) y7 v( f
char *buffer; # J1 H. s8 P9 J, m0 t
buffer = strerror(errno);
8 I- }4 g. [4 j; U  Z/ ?printf("Error: %s\n", buffer); : B4 w% O& H( Q' J$ v4 g4 o
return 0;
% H; h6 K0 s! d& j& ]: F}
5 b! K8 D  B. ^/ J4 t2 C8 v: J8 t$ n7 P, v: r% ]
</FONT>5 C& J6 `) \8 q# n1 m; [
</P>% K6 E  v: E: F1 o4 h# c
<P><FONT color=#ff0000>函数名: strcmpi </FONT>- X" ~3 w" G: v' I& M/ p
功 能: 将一个串与另一个比较, 不管大小写 - S( U/ U+ b, d" d- V
用 法: int strcmpi(char *str1, char *str2);
5 j7 {% }" X+ }+ h程序例: </P>
0 I) Z% C8 X. M/ p<P><FONT color=#0000ff>#include <STRING.H>
9 N9 r' V4 f' A0 Y  _. l3 D; W#include <STDIO.H></FONT></P>
& A3 \" F7 l7 a3 f<P><FONT color=#0000ff>int main(void)
: ~2 U; S3 T/ e, z' r{ ; V+ M1 Y4 s/ ]" M
char *buf1 = "BBB", *buf2 = "bbb";
) A% Z+ T4 F3 }, ~) xint ptr; </FONT></P>
+ K8 x6 g) m; R8 W<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
' [8 ?* Z; v8 `; X% l7 b<P><FONT color=#0000ff>if (ptr &gt; 0)
# Z2 b5 w: O/ _4 bprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
) b; E5 D4 n' I* C# b<P><FONT color=#0000ff>if (ptr &lt; 0)
8 K% S# u# e" G6 ?printf("buffer 2 is less than buffer 1\n"); </FONT></P>
- p2 u" S) |" ?2 A$ ?* g<P><FONT color=#0000ff>if (ptr == 0) - }: `& B# b5 }
printf("buffer 2 equals buffer 1\n"); </FONT></P>
! n7 m4 P  F- E<P><FONT color=#0000ff>return 0;
- I& m2 U2 ~) u7 F6 I/ Q}   Y. _% G* n3 L
</FONT>
3 F3 z* n4 S4 e0 u$ o! U2 h2 \6 h) j# G" J6 b4 u4 x$ L% _9 D
</P>
5 O% t, X+ b7 K<P><FONT color=#ff0000>函数名: strncmp </FONT>
% d$ f* C0 p  c/ o功 能: 串比较 ' f$ Q& W2 }4 O" p, y
用 法: int strncmp(char *str1, char *str2, int maxlen);
$ x9 W% Z* b( i  r( ~1 V: U* _" ]程序例: </P>: Q6 |6 t7 h% ?. H( @" e
<P><FONT color=#0000ff>#include <STRING.H>
' o: X$ ^! s- G: b: D$ z+ [+ I5 u#include <STDIO.H></FONT></P>' q* T3 }0 Q5 }- F. \
<P><FONT color=#0000ff>int main(void) </FONT></P>! K2 h" K: ?! \  _$ a; X7 z6 W( }1 c
<P><FONT color=#0000ff>{
$ N0 j) W% b8 g6 O% B4 i+ d7 Tchar *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
2 p+ T5 @! f  ~- Y2 H( F: Q. oint ptr; </FONT></P>, K2 {" H3 @, K2 c9 z5 Q) x+ k. [( c
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3); 8 C1 r" w: t. T" I& p8 n  f" L
if (ptr &gt; 0)
6 x3 x! t% h$ Z1 k2 uprintf("buffer 2 is greater than buffer 1\n"); ; t5 A# @4 \3 X1 A6 e
else ; C) X; A% U; M. {9 G& b0 m
printf("buffer 2 is less than buffer 1\n"); </FONT></P>( A4 z4 L% \0 ?$ _. l# n
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
, @9 b  G/ s; T- d1 F) iif (ptr &gt; 0) + }* a, M) o8 R' c% w. M  U2 X
printf("buffer 2 is greater than buffer 3\n"); ; @, {' v  ]: y3 ?
else # |% D2 C  j4 }) e$ v
printf("buffer 2 is less than buffer 3\n"); </FONT></P>2 {" b7 L/ N; Q# l' o
<P><FONT color=#0000ff>return(0); ! r% S$ R7 ?/ M3 M: L- q1 V
} " {) T; c# ]5 {9 m+ m, U2 u
' R/ x7 T, X* G8 |# h$ ~) E
</FONT></P>* L% Y+ i/ M7 P9 H) q4 ?
<P><FONT color=#ff0000>函数名: strncmpi </FONT>. D9 g/ O8 Y7 _* V
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
( W# O) m3 G' p" f用 法: int strncmpi(char *str1, char *str2); ! U3 D+ C, v% k  J
程序例: </P>4 O# W# r4 _, _9 {% n1 [, P' c
<P><FONT color=#0000ff>#include <STRING.H>
) o& Z$ p# c3 g: D+ Y0 p#include <STDIO.H></FONT></P>& m$ r+ B6 z* m+ [0 z
<P><FONT color=#0000ff>int main(void) + K6 n- ?( p& e( D
{ $ X- C$ X) d- p! p* B$ z7 x" B( P$ K
char *buf1 = "BBBccc", *buf2 = "bbbccc";
1 B* R# ]* w  P* @! O4 a; G. \5 x  lint ptr; </FONT></P>& N: p* t8 W: G  W! b
<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>
$ v3 |4 B+ A* t9 T6 G0 h' x<P><FONT color=#0000ff>if (ptr &gt; 0) 7 m& ^) D' j- p% ?& T; b+ \
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>! V- k, ?9 m% |; w7 T. C5 W+ H- _
<P><FONT color=#0000ff>if (ptr &lt; 0)
0 M5 ?* s0 h, o, [& Lprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
; d5 h3 C* l( x/ ]# ^<P><FONT color=#0000ff>if (ptr == 0)
3 }/ f; g- s9 A2 pprintf("buffer 2 equals buffer 1\n"); </FONT></P>4 K' I* c; q: i2 l* f) X) T: x
<P><FONT color=#0000ff>return 0; </FONT>
- Z" C4 q* }- m* n, v* T+ |( {* j}
* U9 S' c  _% u9 @8 Z- \9 [
, ]- r/ U- ?# a! D</P>
3 |. b) c8 g% a- p  R- H* Y8 D4 b<P><FONT color=#ff0000>函数名: strncpy </FONT>
8 J7 p, M+ G# W/ F0 w; [* v功 能: 串拷贝 $ B! W, q4 \+ Z* ^( j* v0 x& o
用 法: char *strncpy(char *destin, char *source, int maxlen); : t2 H% b0 W. t, m. v
程序例: </P>
. V' P; Z6 C: C/ D<P><FONT color=#0000ff>#include <STDIO.H>
6 S8 c: }- h' V; B$ y+ B#include <STRING.H></FONT></P>
6 t5 R; h* Y1 y$ |) b% A<P><FONT color=#0000ff>int main(void)
0 I# M+ @; e" S) ?+ L$ |# Q{
. t4 B& Z$ E, a& A! nchar string[10]; 9 P6 y' r. w+ @, \+ r1 R. V# n
char *str1 = "abcdefghi"; </FONT></P>( i. m8 Y- ?9 [! x
<P><FONT color=#0000ff>strncpy(string, str1, 3);
: F' v) A4 ?! |- ]- `string[3] = '\0';
7 ^0 @/ H* h5 T6 B* K! c1 t/ p$ mprintf("%s\n", string); * X$ u/ I: k4 G+ e6 W
return 0;
) ]8 d# s. y; [1 n. y}
0 t) V  v+ i  I% L5 P- w</FONT>
- \. j% A6 S- ~# c5 j  [</P>
* R8 c5 Z2 |" G  ?<P><FONT color=#ff0000>函数名: strnicmp </FONT>
8 o! `. O9 C* z1 l9 |, _功 能: 不注重大小写地比较两个串
8 X8 T1 @# E8 ]* j; g1 O用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); ' `. _" V' Z' w) b
程序例: </P>: V' A! N, p& i6 b
<P><FONT color=#0000ff>#include <STRING.H>
% ?. j) s' W. e9 }( ?#include <STDIO.H></FONT></P>3 m3 w& u3 R( s( ?4 w; F! F
<P><FONT color=#0000ff>int main(void) # Y1 r0 {6 y: K
{
; L$ O1 g. S! h3 f0 E0 Cchar *buf1 = "BBBccc", *buf2 = "bbbccc";
2 e0 Y+ p8 ~* y: Mint ptr; </FONT></P>0 i$ ?" I5 d! Y
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
) @4 B* z% f+ I( d! h2 ^1 [<P><FONT color=#0000ff>if (ptr &gt; 0)
8 ]5 f% M1 J! r; wprintf("buffer 2 is greater than buffer 1\n"); </FONT></P># f6 K$ g, N& b5 M' x) i% z' u
<P><FONT color=#0000ff>if (ptr &lt; 0) " J* j+ u0 H. |1 g
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
& f0 c# F, u+ O6 a<P><FONT color=#0000ff>if (ptr == 0)
4 |; u0 D; i' c) v- o! Bprintf("buffer 2 equals buffer 1\n"); </FONT></P>: u$ [4 U8 `' q$ W" q4 ~
<P><FONT color=#0000ff>return 0; / p+ ?3 |- \: ~. E/ G" b
}
- k+ h8 B6 L2 l" ~
" o$ i2 O$ H. {7 r</FONT>
; \" M2 o  n3 v% n; N6 C7 J</P>/ i2 a( C) G2 I7 D4 p$ }" E- r
<P><FONT color=#ff0000>函数名: strnset </FONT>
+ o7 x# b0 \/ ^8 J, w功 能: 将一个串中的所有字符都设为指定字符 ' W, P! ~) b) [  f8 I7 P! W6 L6 s
用 法: char *strnset(char *str, char ch, unsigned n); 3 S- y  F! X, q/ ]( N
程序例: </P>, O4 _& i# Q6 i6 \# h  T! m* Z
<P><FONT color=#0000ff>#include <STDIO.H>
5 L- ~0 V4 F; B: }#include <STRING.H></FONT></P>, ]/ n& v# m( X. |
<P><FONT color=#0000ff>int main(void)
$ k; G. w2 ^) I, ^$ `+ q$ F{ & m% l1 ]" Z! _" X5 R
char *string = "abcdefghijklmnopqrstuvwxyz";
& r, @+ V* p  o6 _; Schar letter = 'x'; </FONT></P>3 ~1 g& E: n0 U0 H) U6 ~
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string); . N( \. p! G6 s
strnset(string, letter, 13); 4 O; y8 j4 ]& A' O
printf("string after strnset: %s\n", string); </FONT></P>
1 P& y* D- n/ j5 l0 R* n<P><FONT color=#0000ff>return 0;
, a) e' f. I8 f/ J% G}
% |# f# Y3 R& Z7 i+ G</FONT>
) N; l2 E- z- b</P>' l. }# i' Q: \# H& |4 P
<P><FONT color=#ff0000>函数名: strpbrk </FONT>
6 T" a% l/ m; U$ A, U功 能: 在串中查找给定字符集中的字符
* L" a, B9 y! C; d用 法: char *strpbrk(char *str1, char *str2);
7 `) ?% ^& S) e7 L  n2 e3 z* Q4 B9 C程序例: </P>+ r+ L3 P' k& i6 `
<P><FONT color=#0000ff>#include <STDIO.H>/ O, O" A# T+ g" ]2 `( F/ b
#include <STRING.H></FONT></P>
$ j7 y' g; @$ t+ K3 [<P><FONT color=#0000ff>int main(void) ( ?1 H. l, A0 u& J& b
{
3 b- L& h4 |! dchar *string1 = "abcdefghijklmnopqrstuvwxyz";
2 j% Q) L8 F5 D2 H+ w8 ?4 pchar *string2 = "onm";
; q8 |) k/ O, [char *ptr; </FONT></P>. s( O* w% N! b4 L- t. ?
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>5 q0 @! h! l- Z/ h. b: S! I
<P><FONT color=#0000ff>if (ptr) + o2 J; v4 {# o% A6 W/ t
printf("strpbrk found first character: %c\n", *ptr); * X7 ~$ X) Q' |  |  Y! N7 e: a
else 1 L# [7 I4 f  Z
printf("strpbrk didn't find character in set\n"); </FONT></P>
& X9 O8 |1 z# |$ N- Y" D, Z<P><FONT color=#0000ff>return 0; 4 e8 E) t/ K, c2 u, p+ L
} 9 z! a, ]2 a! O6 n
' L' G! r8 I2 w% X8 I+ z1 b7 u
</FONT>. a8 J, r  q9 b5 [- O; ^3 `  m/ c
</P>" q4 Q; b% [: |$ M* E. |
<P><FONT color=#ff0000>函数名: strrchr </FONT>
6 ?. T$ n& D- ~5 b功 能: 在串中查找指定字符的最后一个出现
* G' K* @  x& }/ a5 ]) q. ^0 N用 法: char *strrchr(char *str, char c); 5 l, K( |' o$ Q
程序例: </P>( A6 {1 [7 p3 }4 x* ~' u  E, n
<P><FONT color=#0000ff>#include <STRING.H>0 y, |0 Y7 u  g* E' L) f6 X
#include <STDIO.H></FONT></P>
1 O; c& [$ r  W- i" h<P><FONT color=#0000ff>int main(void) # r- Y2 p8 \" Y% J) p6 W
{
( k3 y- X/ c$ m. R3 W  k2 n) [char string[15];
1 G# k& h  q% c9 W4 y* W# V0 jchar *ptr, c = 'r'; </FONT></P>- S/ \: l2 `$ m. [8 ?
<P><FONT color=#0000ff>strcpy(string, "This is a string");
' G" V/ H0 w4 r6 r! z& F- B- Gptr = strrchr(string, c);
/ Z/ o- [2 i/ o" fif (ptr) 7 D2 @9 w' P) G
printf("The character %c is at position: %d\n", c, ptr-string); 9 Z/ y+ w! a" ?9 c, i6 r
else # o; I7 m8 v5 @5 q3 ~
printf("The character was not found\n");
4 p% A, Z. z5 n$ \* }! f2 J* Areturn 0;
$ F& Q" [. u2 c9 Z! p: ^8 z; T} </FONT>
- G7 c, Z8 o( Y/ g- x2 H' [/ P% y  d% U/ e

* j* K7 o4 B" F" ~+ D1 C</P>
, G; N; t0 R4 B5 J2 C3 j6 d# P2 C<P><FONT color=#ff0000>函数名: strrev </FONT>
* O4 s- Q: e! c* D功 能: 串倒转 ' b% {0 X# K" W5 l3 U$ ^8 x
用 法: char *strrev(char *str); / m  C0 q- M( j! E8 U" L5 x+ f
程序例: </P>
4 @" u, Z% e) d. a<P><FONT color=#0000ff>#include <STRING.H>
5 z2 r& c  F  l# ~#include <STDIO.H></FONT></P>9 q- c9 W; y. D3 d
<P><FONT color=#0000ff>int main(void) ' y! g  }! V; m( M/ q  F
{ , X( ?% X2 n  w
char *forward = "string"; </FONT></P>
, b8 y/ h+ z* O# Y. f<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
, Z/ q- U" D& Z7 p6 o3 k  Ustrrev(forward);
3 w* V" |" [/ g) H3 T6 |printf("After strrev(): %s\n", forward);
' H5 A: Q  h$ }) j! B) E4 Ereturn 0; 0 Y/ N1 j% U' }3 g1 L+ i+ i  I1 h
} </FONT>7 R6 N* {' u; D$ ^/ M/ P! N
</P>
2 b7 t+ z/ t8 G4 e3 u+ @<P><FONT color=#ff0000>函数名: strset </FONT>4 L. {/ t% g; h: k, {; X& W0 W  A) j
功 能: 将一个串中的所有字符都设为指定字符 1 l/ v# @6 {7 j- ~" W
用 法: char *strset(char *str, char c); * L7 c  b6 L6 V
程序例: </P>* C6 N$ _& e5 |2 p; p8 a2 A/ _
<P><FONT color=#0000ff>#include <STDIO.H>- H* B0 D$ v/ M0 S- e" S* m
#include <STRING.H></FONT></P>
4 A2 s" ]9 b& U+ g  w0 f% l  }<P><FONT color=#0000ff>int main(void)
( D  r) M' C2 H1 s; I; Y  ^* C. b{ 5 |+ E( z5 a* c: k  |/ [
char string[10] = "123456789";
9 i% o! W, K3 A  }2 Ychar symbol = 'c'; </FONT></P>
: L, x9 E# ^+ S: [2 ^4 Y<P><FONT color=#0000ff>printf("Before strset(): %s\n", string); 2 ~, y4 A) ]7 h: Z. b9 Q
strset(string, symbol);
' C' p+ v8 k) d3 r( z- dprintf("After strset(): %s\n", string);
# @- o. v' b) j, G, t. breturn 0;
3 ~5 S- z7 `) v3 g0 ~: J: u, v1 o} : f9 O) g2 }% S8 B

* X# m6 F" ~" E5 P4 K: R</FONT>
; Y. }7 w7 a  K: l4 {1 |</P>
" v# J2 f6 B- K4 E' F1 @- k& a9 z<P><FONT color=#ff0000>函数名: strspn </FONT>' H: \. U; Y* G+ D% r9 v
功 能: 在串中查找指定字符集的子集的第一次出现
7 H# }+ |! m5 {3 {& h# t用 法: int strspn(char *str1, char *str2);
6 A5 A% [4 i$ ?( ?程序例: </P>; l/ u) Q) Q- U: d4 x
<P><FONT color=#0000ff>#include <STDIO.H>  N6 Q# s" }, s
#include <STRING.H>- Y" e& u, ^9 i& A/ Q; y$ U
#include <ALLOC.H></FONT></P>  ~3 u! w9 g8 a/ J) G
<P><FONT color=#0000ff>int main(void)
9 T! a+ ]7 w7 v( ?{
: O7 }/ J% M; R! I2 tchar *string1 = "1234567890"; ! d) A" K$ s5 v% m. n' X
char *string2 = "123DC8";
# k7 v0 x* T4 eint length; </FONT></P>
+ }/ w' c+ v: e$ L* X; J- ^6 }<P><FONT color=#0000ff>length = strspn(string1, string2); ( {- q; J5 t7 y- Y! {; _: }
printf("Character where strings differ is at position %d\n", length); + o8 c0 h2 H0 l1 B% S8 D
return 0;
# a+ l/ J$ h: I0 N1 `}
( N6 @' o- M" X6 o- A3 \</FONT>
1 S" ?" d' q! J  M* B</P>
! u  v  X% [# I; t. C<P><FONT color=#ff0000>函数名: strstr </FONT>
/ n1 X1 e: j% g, j" V* a功 能: 在串中查找指定字符串的第一次出现 # r$ M0 M4 B4 H* ]0 l6 u
用 法: char *strstr(char *str1, char *str2); ( c; I1 H# {* Z) T0 |9 y3 ~
程序例: </P>* g& ?6 z" I9 V+ v# Y
<P><FONT color=#0000ff>#include <STDIO.H>/ R, \2 `5 z  o/ a8 O+ X( p- k
#include <STRING.H></FONT></P>
, u2 W7 Y. D5 v1 n<P><FONT color=#0000ff>int main(void) ! @/ V$ ]  d8 \$ ^& s3 D
{ ; o% E, N/ A0 c' l9 R
char *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>1 h+ V. e5 o4 n$ L
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
& X6 Y* p7 h6 ]. ?5 tprintf("The substring is: %s\n", ptr); 9 D/ K, e1 F9 Y1 o; Z
return 0; 4 {+ x' E/ ], ^  I0 i" S3 Z
} </FONT>% o7 M: z# ?# b+ G

! G0 s& T7 Q. E$ l  D</P>
$ j8 n; z3 P8 Q4 ~4 L# D; ~<P><FONT color=#ff0000>函数名: strtod </FONT>
* o( J( P; w8 W0 }! Z功 能: 将字符串转换为double型值 7 Z0 H  D  J% q" k; Z0 z) O3 Z) a
用 法: double strtod(char *str, char **endptr); . X  f4 a3 W1 y: O* k3 |
程序例: </P>
' l3 `7 C6 X! i- x1 M4 Y<P><FONT color=#0000ff>#include <STDIO.H>; t  N) r$ N1 D4 I
#include <STDLIB.H></FONT></P>
- t9 h: X9 Z" \5 W5 w7 a7 J7 _# x<P><FONT color=#0000ff>int main(void) ' s+ u+ Q6 D/ s7 w
{
, A. s! a) J4 E' A! ^char input[80], *endptr; 8 V! }% E9 b/ k2 i& X! X
double value; </FONT></P>2 |5 S! n: E9 V) R' [% u5 w" U
<P><FONT color=#0000ff>printf("Enter a floating point number:");
* V9 Y+ @) W; V  d2 f9 f! Igets(input);
0 d6 |5 A" Z( Y4 T+ Q9 ovalue = strtod(input, &amp;endptr); - K7 ?& C; U7 s' W% c
printf("The string is %s the number is %lf\n", input, value);
4 I6 {" N# Q; R  O$ d* \return 0; , Y3 Y0 y+ @3 Z) O  f- [
} 9 y1 n2 f* O6 N2 Q0 \# A. [  t
</FONT>8 {4 |2 m0 n: |) ^5 w

- x  H1 R8 E0 z# ]: N  m</P>: j9 {6 O2 P* M, P; B8 z
<P><FONT color=#ff0000>函数名: strtok </FONT>
8 U3 g; H& i. N! f- D: p功 能: 查找由在第二个串中指定的分界符分隔开的单词 ( O$ h/ F' A7 u
用 法: char *strtok(char *str1, char *str2);
5 p9 L: K. F% X' h程序例: </P>6 M% K  O+ e" C& [
<P><FONT color=#0000ff>#include <STRING.H>
9 K" _1 q6 e$ r#include <STDIO.H></FONT></P>! t$ n; y0 a' L! T3 M2 I$ A
<P><FONT color=#0000ff>int main(void)
4 _3 R6 r/ W% n5 q{ 9 a# n) i$ S( I: z/ J( E. t" h0 {* P5 Y
char input[16] = "abc,d";
/ S' \0 r. m! _, K" L0 X+ S2 ychar *p; </FONT></P>
0 \6 G, j8 R( W8 z$ Z" u& s* O<P><FONT color=#0000ff>/* strtok places a NULL terminator # b3 _$ e. l: L3 [. b& F+ ?
in front of the token, if found */
. z! P1 g% l) D3 m0 b0 z: I1 q8 Kp = strtok(input, ",");
* {6 _4 [5 i+ M4 I2 Q, v( T( A! Vif (p) printf("%s\n", p); </FONT></P>4 [( \. T  m; i% w8 L8 F* U
<P><FONT color=#0000ff>/* A second call to strtok using a NULL 8 v1 b# H7 f3 z, H! I/ z8 c. `
as the first parameter returns a pointer
3 b$ ~( O+ N* B- [% kto the character following the token */
1 w5 D0 i6 y3 np = strtok(NULL, ",");
1 a9 k4 x5 @; Y: T1 ~if (p) printf("%s\n", p);
1 F# x; N9 ^9 yreturn 0; $ _+ Y5 @' Q. h, f* k
} + q* p) H! y. [4 V4 [% ^

4 i) ^* r8 E/ l4 M/ I( Y7 `1 i6 A, B2 A) B0 g0 k
</FONT></P>9 {, Q. ~7 l7 Q1 U# L; y
<P><FONT color=#ff0000>函数名: strtol </FONT>! t) }9 `. @$ s% Z( P
功 能: 将串转换为长整数 ; G) U" {% W! X5 _8 y) B& N3 |
用 法: long strtol(char *str, char **endptr, int base); 5 h5 \! s# X7 Y! Z7 h
程序例: </P>( p& e) E$ u4 C. |  H  c# H
<P><FONT color=#0000ff>#include <STDLIB.H>3 r8 @% a$ O9 H% q2 ?6 d2 E
#include <STDIO.H></FONT></P>
$ F8 O5 v' S; y; D<P><FONT color=#0000ff>int main(void) 6 [0 \: ?5 N5 X& v) s
{
# R/ C" z+ y/ O2 z0 Wchar *string = "87654321", *endptr;
2 u# y& Z$ d$ ylong lnumber; </FONT></P>
4 g) x' J" w0 ], S7 U7 H<P><FONT color=#0000ff>/* strtol converts string to long integer */ . {6 o# H% A1 c
lnumber = strtol(string, &amp;endptr, 10);
0 V4 l. K9 e& v/ q0 i+ }printf("string = %s long = %ld\n", string, lnumber); </FONT></P>
  J' S; d& @; J& @3 Z<P><FONT color=#0000ff>return 0; ) W4 a5 \9 B& I  X, L# o* P$ b8 E  p
} </FONT>
5 Z5 C8 L6 _% U3 m$ R</P>% H: ]& h, Z5 f" Y- _
<P><FONT color=#ff0000>函数名: strupr </FONT>
1 q/ V: \) B% N8 o+ ^功 能: 将串中的小写字母转换为大写字母
0 e9 l( L* m6 I; |0 f% K用 法: char *strupr(char *str); / L9 W% H# n/ z
程序例: </P>, Y. _# [+ b' o% `" [8 P
<P><FONT color=#0000ff>#include <STDIO.H>
0 k# S2 P7 m, m) C2 @#include <STRING.H></FONT></P>1 j/ [7 h; h3 S% F9 [3 F
<P><FONT color=#0000ff>int main(void) - {" O- d' l2 X4 F3 H2 `3 x' B
{ , V: f' |4 v* O# f& q8 F: M' w. e
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>& F+ q4 C9 ]) S5 o- I6 U
<P><FONT color=#0000ff>/* converts string to upper case characters */ 4 _# X; \  p+ E2 l: s1 h) Y( a
ptr = strupr(string);
5 r5 t) U4 k+ E# V$ ~* ~! ~2 J( v+ Sprintf("%s\n", ptr); 2 y4 k  L9 M2 |4 W: d% u
return 0; # U! s" V) j' M9 T* X" n& W
}
1 H( z$ R4 F9 T& ?) q5 Z) s$ Z% i+ Z$ j( w" U" X
</FONT>" O: ]- S8 Q7 y9 S2 s# U, Z- Q  t9 u
</P>7 S( c0 y& F! z8 d! j4 V) _, ^# U$ W
<P><FONT color=#ff0000>函数名: swab </FONT>
+ @4 M: |# |! S/ J3 ~8 o# J9 R功 能: 交换字节 $ Y: e9 N1 |) ^4 O7 [% q- B# T
用 法: void swab (char *from, char *to, int nbytes);
+ g# g3 R% W( S2 E' P6 x/ V6 m程序例: </P>, Y- v" M3 i7 a5 G% ?# P
<P><FONT color=#0000ff>#include <STDLIB.H>
* @/ m- V0 w" c+ u. j, o#include <STDIO.H>; L- l5 \/ r+ [2 H
#include <STRING.H></FONT></P>6 K7 y/ [5 i/ I5 W& T+ n" S
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; 8 ~, N+ B6 u1 E2 S5 S3 t4 ~
char target[15]; </FONT></P>
+ U7 _( ~! z! p1 O' ]6 U3 l. a<P><FONT color=#0000ff>int main(void)
. P5 v- ]; }  Z: R+ b5 Z{ & c7 Z* e" i0 J; d6 c3 W
swab(source, target, strlen(source));
% C) \9 J. w" F; R" Y' Xprintf("This is target: %s\n", target);
5 a% C5 x5 U, V. ]return 0;
& a' j7 l( S. ?8 [}   q9 z6 W! Z: L; ^* @4 T
</FONT>
, |: J2 o- n- }) M8 Q4 A6 ?  ^4 `+ q
0 v1 e3 P3 r, B' J</P>) }  b% B8 F) x
<P><FONT color=#ff0000>函数名: system </FONT>
( X. q: c$ A0 o! B% Q6 n功 能: 发出一个DOS命令 " ^$ H8 M- W7 e
用 法: int system(char *command); 0 M* @+ w, ~9 t2 [# m; _% ]
程序例: </P>
5 U: r# r) Q8 `( V<P><FONT color=#0000ff>#include <STDLIB.H>* g. S' `; u# N' Y& g
#include <STDIO.H></FONT></P>! c' w/ @' U- F, c9 y; [
<P><FONT color=#0000ff>int main(void)
* G* |$ Z. _0 o. H5 E{
" \& M& h0 W  F) ]printf("About to spawn command.com and run a DOS command\n"); 7 r* v; L3 N7 q" H) H. c
system("dir"); : l1 k0 w& D0 L* B
return 0;
, d8 j, f+ |7 J- g) {+ G! @+ }} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-6-11 14:51 , Processed in 0.498364 second(s), 52 queries .

回顶部