QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>, o0 I$ j9 v, N9 U4 `
功 能: 改变数据段空间位置 & _9 \7 M2 s; N
用 法: char *sbrk(int incr); * x6 P+ E  r- o+ M5 l
程序例: </P>
$ H* E- V( ]4 R! Z5 O: \<><FONT color=#0000ff>#include <STDIO.H>
, W) A1 b3 ?+ g6 A#include <ALLOC.H></FONT></P>* ?0 Y1 _4 ~" @4 s, w, D
<><FONT color=#0000ff>int main(void) " j5 `" Y! \% }. Q6 S  W( q; E
{
6 f2 R' x6 \2 I* r2 s  V3 _printf("Changing allocation with sbrk()\n");
) @+ O" N2 _$ B; z# y  xprintf("Before sbrk() call: %lu bytes free\n", ; j! F" o4 W, Z) Q: B
(unsigned long) coreleft()); / ?; I$ W  ]# D& Y( [
sbrk(1000);
! F: v$ `" @# t5 G7 H* H9 d; Xprintf(" After sbrk() call: %lu bytes free\n",
, u% F# I( H9 g  u(unsigned long) coreleft());
( p- p2 l1 ^1 t: i4 t" W" Dreturn 0;
/ M! X/ m+ c0 v; V- F( X% ]6 q0 U} 8 ?4 e+ C* w& A: K$ E/ [1 o
' X0 o8 J- B# s1 t2 e
</FONT></P>& p8 m+ o9 z1 \0 @! C6 c( w
<><FONT color=#ff0000>函数名: scanf </FONT>
" s9 O/ Z* l3 Y, @$ a! Q8 G' o功 能: 执行格式化输入 8 ]+ K/ j. J8 {5 S
用 法: int scanf(char *format[,argument,...]);
: @3 Y% k$ \! l( c程序例: </P>3 B( q$ o; j; J5 A5 R7 ^2 S# U4 H
<><FONT color=#0000ff>#include <STDIO.H>* n+ W! u+ Z8 k* Z6 T" }& L/ r
#include <CONIO.H></FONT></P>
6 J0 _" Z; s' ?% {7 J9 n, v<><FONT color=#0000ff>int main(void)
6 r, z8 r  F* z7 H! k{
4 |, A8 w$ G2 G  O$ Y8 n5 rchar label[20]; 7 B$ W* K; |5 y7 y
char name[20]; , y! W% I" c+ a- r! `
int entries = 0; ) d2 c! M, s: W
int loop, age;
( Z3 k! ?5 s9 [, vdouble salary; </FONT></P>
% D- @. _# l' X+ @4 w. }; z8 E<><FONT color=#0000ff>struct Entry_struct 7 i* i# g  y9 V$ j3 p
{
/ a0 e# {  S. M& r' O  Z: W$ lchar name[20];
- @$ G$ H) A% {1 Y1 B2 `( i4 }int age; , O# E6 J. H+ l6 G
float salary; ! Q4 f) w6 M7 S. ~
} entry[20]; </FONT></P>5 M( K  s" I; m: Y
<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ & e7 f" N# ~& `' T, A* {& {2 h
printf("\n\nPlease enter a label for the chart: ");
% t- _  q- u0 w" cscanf("%20s", label);
, Z' e: O' Q9 J/ bfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
3 O1 W& p5 L; E$ z+ `: T, f<><FONT color=#0000ff>/* Input number of entries as an integer */ ' y! e, D) t6 B( T# Q
printf("How many entries will there be? (less than 20) ");
: ]# ?9 a4 W" q5 N6 Zscanf("%d", &amp;entries);
9 o4 p& E: s3 D) \2 R/ Pfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
' N+ \" `4 \# w0 I<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
& G2 }7 l: d& l: `8 G) Z' M$ N* dfor (loop=0;loop<ENTRIES;++LOOP)
7 F' B: a% i+ u! V  S, V- J8 r0 }5 p { + R/ i$ R, d7 V" }
printf("Entry %d\n", loop); - Y' a4 V3 T4 I2 f2 w
printf(" Name : "); / U, t$ n7 j# ~
scanf("%[A-Za-z]", entry[loop].name);
. M4 q, y7 u" q) e5 J% wfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>" a& T6 R4 F+ w4 o( M2 a5 S
<><FONT color=#0000ff>/* input an age as an integer */
$ V- S+ E- O7 O3 v6 ^! B3 A; [% Y4 g# eprintf(" Age : "); ( ?. I# s! ?3 n. R; Q
scanf("%d", &amp;entry[loop].age); 5 a/ p7 l7 f) O7 I
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
) U; ~- y+ y/ I; Y+ S5 t<><FONT color=#0000ff>/* input a salary as a float */
+ g5 _* Y$ }. _; dprintf(" Salary : "); ! p0 l8 j$ a2 Z; o# e
scanf("%f", &amp;entry[loop].salary);
" [8 m: F- o: Q0 P& ^- _( x4 S- Bfflush(stdin); /* flush the input stream in case of bad input */
* G/ m6 O5 C1 e" T$ ?: z} </FONT></P>/ z" ^. z) y2 s& Y% o! T  n5 C
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ # _) v0 y$ w7 f% q
printf("\nPlease enter your name, age and salary\n");
+ o! D& U0 g5 ?+ o8 {1 P7 Lscanf("%20s %d %lf", name, &amp;age, &amp;salary);
/ J  J1 _6 O+ K. ?</FONT></P>
$ q$ r" e- M3 E" E! v1 Q4 x5 q<><FONT color=#0000ff>/* Print out the data that was input */
$ o2 P0 u0 q) W. F: d+ s* Oprintf("\n\nTable %s\n",label);
! [$ z$ n8 m3 h* r% eprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
) p6 t6 }4 P1 l& I2 Q- I5 C/ |5 f0 tprintf("-----------------------------------------------------\n");
3 L. n. K* p+ f) p% Efor (loop=0;loop<ENTRIES;++LOOP)
* ~9 ]) T9 b8 f; d printf("%4d | %-20s | %5d | %15.2lf\n",
( j, h, ^) t% K3 [. eloop + 1, ( F8 Q; U9 a6 ?1 f
entry[loop].name,
$ o& i( t+ D+ m0 [4 \$ o  ?entry[loop].age, 7 j( }4 U  z+ j
entry[loop].salary); / D6 T6 r- [# d# }: z1 W% n
printf("-----------------------------------------------------\n");
( u, |: E" |3 D6 Q6 Dreturn 0; $ d: Q( C& T& O: Q
} ' V# Z8 I! W3 P; o' Q
</FONT>
4 y+ R% e/ Y. g, S& q</P>. T8 ^0 U  A; @" L. B  G, S2 O6 Y
<><FONT color=#ff0000>函数名: searchpath </FONT>9 p2 Y% g1 o" d( w1 j9 \( S
功 能: 搜索DOS路径
" H2 q/ g+ L- \* }, e  ^7 G用 法: char *searchpath(char *filename);
0 r% M, I9 G. R  W1 G程序例: </P>
6 Y8 ?/ S4 r- ?, t, z( u# G5 q: F7 H<><FONT color=#0000ff>#include <STDIO.H>$ e$ ~, O" ~- S6 I; }7 Y" l; m
#include <DIR.H></FONT></P>& }8 p$ c2 G! J3 \) G0 k
<><FONT color=#0000ff>int main(void) " q  g4 w" A& D, q, B
{ ) L( F1 g% L- P/ D9 d& f. F2 m
char *p; </FONT></P>
6 z! e5 V+ |' _! E<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer $ W% `, H: a0 }0 g7 m
to the path */ ' U/ v8 B- n3 N- \* U# w6 @
p = searchpath("TLINK.EXE");
8 u" p: D6 \: q  a7 Yprintf("Search for TLINK.EXE : %s\n", p); </FONT></P>
9 B2 H$ X' M4 {! i<><FONT color=#0000ff>/* Looks for non-existent file */
8 C+ O1 U, C% `& Xp = searchpath("NOTEXIST.FIL");
' f: \5 Q/ j  f4 [7 @4 Nprintf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>/ k& K9 C# M3 H: G% x" ~; j% Z4 T" m1 i
<><FONT color=#0000ff>return 0; * P  |1 C4 V( @" L4 {( `9 Q
} ( d. c7 q# D+ B1 p* y2 A( O

7 q0 R+ D$ o( m8 G1 p</FONT></P>, l* a+ x- O+ T1 Q$ z+ W8 m7 L# d) L
<><FONT color=#ff0000>函数名: sector </FONT>7 o2 s; ]- B4 X3 f3 n7 a
功 能: 画并填充椭圆扇区
, H8 H4 ~/ \. x. k6 E6 c用 法: void far sector(int x, int y, int stangle, int endangle); & g0 \" S' z4 Q9 I
程序例: </P>7 k6 ]3 ~5 q6 j; m
<><FONT color=#0000ff>#include <GRAPHICS.H># k- x. k3 V1 ~6 s6 S0 _# g7 n
#include <STDLIB.H>
0 k* u# [9 k( F: u% b/ ~3 q& o#include <STDIO.H>
) Y9 R6 [% z9 `3 j#include <CONIO.H></FONT></P>
5 v3 @7 f9 [# Y2 ]1 y/ J* a4 i<><FONT color=#0000ff>int main(void) - Q) I7 b2 @5 z4 i) {1 m6 L
{ ( h9 k9 A9 }. u' R' w
/* request auto detection */
* O: u( g' }/ b+ L8 Gint gdriver = DETECT, gmode, errorcode;
: U9 ^1 a# x& g6 Bint midx, midy, i; 8 \9 C9 G3 R9 p+ g% {6 n
int stangle = 45, endangle = 135; 3 ]+ N5 I% e1 ]. D
int xrad = 100, yrad = 50; </FONT></P>. n) d* e0 G# G6 F3 f0 @
<><FONT color=#0000ff>/* initialize graphics and local variables */
' D; n' |% N5 l& q1 N- @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 H; z3 T! M& ^
<><FONT color=#0000ff>/* read result of initialization */ ! F/ F, i& I% ?
errorcode = graphresult(); . t; A+ r8 b- }; T) z. g9 x: S
if (errorcode != grOk) /* an error occurred */
) {6 Y7 Y' l  V: A* ~, |{
- a8 }2 ]( Q6 pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
/ T5 \# e" @" _8 Zprintf("ress any key to halt:"); 9 X# t2 ?" y) h0 _
getch(); ; }8 m% D/ n; M! N
exit(1); /* terminate with an error code */
" Q  f5 o" v0 L! p0 s} </FONT></P>" C# _4 _5 O7 H8 L6 x  z3 I/ a
<><FONT color=#0000ff>midx = getmaxx() / 2; ) g" G( D* p& ?
midy = getmaxy() / 2; </FONT></P>
8 U9 |3 u  w; F) {" R% ^9 ^<><FONT color=#0000ff>/* loop through the fill patterns */
" G/ E, s8 G9 w% J1 Bfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 1 Y3 G1 ~5 U  P9 X8 G1 n
/* set the fill style */
, Y- x/ m9 E# Ysetfillstyle(i, getmaxcolor()); </FONT></P>+ r# d' w+ \5 g) F
<><FONT color=#0000ff>/* draw the sector slice */ 7 Q/ g1 c# Q  [  D& ^- g' j
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>2 ]$ J+ O- m0 s" Q" ]
<><FONT color=#0000ff>getch(); / u8 h) |/ F) }; {' N: z
} </FONT></P>
3 `. w- D1 N, V, p0 j3 a<P><FONT color=#0000ff>/* clean up */
$ p' J4 P- A# _! h" wclosegraph();
) S( \3 Q+ H+ \return 0;   I9 X2 d6 o* x3 H! G; u, Y) q
} 5 A5 X# H; T( E- O" C
</FONT></P>
0 @- t$ Q6 K& A" n<P><FONT color=#ff0000>函数名: segread </FONT>
0 S5 ~% Z0 O/ X( r- T- I- g功 能: 读段寄存器值
& P5 l- [% p2 ^* H2 b用 法: void segread(struct SREGS *segtbl);
& F5 i0 w' H/ I1 @5 \8 G程序例: </P>2 N' ^' l& Q4 G! L! c  c
<P><FONT color=#0000ff>#include <STDIO.H>
" D: g8 ?2 j3 _( u#include <DOS.H></FONT></P>" V4 j, i8 R4 }% m2 h
<P><FONT color=#0000ff>int main(void) " U, z/ ^5 L+ A- E0 m; s! |9 |% ?
{ 3 \; F. n9 b- ?9 n& r
struct SREGS segs; </FONT></P>7 m7 ]2 U9 P* Q- H- x
<P><FONT color=#0000ff>segread(&amp;segs);
2 N# f' X9 b) sprintf("Current segment register settings\n\n");
- U4 Y+ P! W7 Uprintf("CS: %X DS: %X\n", segs.cs, segs.ds); ; c& f% u3 n2 L) w
printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>* a9 G  }/ L- f& z
<P><FONT color=#0000ff>return 0; 7 [8 ^  H( z) P5 C2 [2 ?/ E$ I
} </FONT>
8 y4 U) V7 P8 R9 R, ]+ a
& T$ V& R2 P$ h0 H</P>8 u( e2 W$ ?7 D/ p& W
<P><FONT color=#ff0000>函数名: setactivepage </FONT>
0 i- b0 t$ L6 [7 N8 ~$ o- `' @8 y' w功 能: 设置图形输出活动页 + s8 i/ R; {" p7 w6 q
用 法: void far setactivepage(int pagenum); - o) E2 j2 p+ y+ P0 K+ E- X
程序例: </P>
1 y* P, B7 d) C3 b: \2 y<P><FONT color=#0000ff>#include <GRAPHICS.H>
& q" f" F/ V* z5 \' z$ O#include <STDLIB.H>
/ O- h/ u6 J  ]#include <STDIO.H>8 d7 r; P/ `( j3 \/ o! S5 h$ S5 n. _
#include <CONIO.H></FONT></P>+ r1 f- S# e2 e. t. O  K8 u" \  p
<P><FONT color=#0000ff>int main(void) 7 j9 D/ q1 M+ @4 S
{ # c" g+ s4 Q9 ^( j
/* select a driver and mode that supports */
9 K7 i. D2 Y5 O/ j. `4 \/* multiple pages. */
. X: G3 C2 m7 Z3 C( R3 T* gint gdriver = EGA, gmode = EGAHI, errorcode; + d% r: J. \' @
int x, y, ht; </FONT></P>3 C- G8 L, p9 x4 ~4 r/ c
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ! U' ]: l6 u8 L( e& Z# s# S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 A( Z2 b+ |) \, B  g
<P><FONT color=#0000ff>/* read result of initialization */ 2 e8 _* C/ r. v' r* k0 ]
errorcode = graphresult();   O6 u1 F, D# i+ S) i6 \0 I
if (errorcode != grOk) /* an error occurred */ 1 j' I' S0 h8 }  f) _
{ 0 ?7 m8 c  U8 P7 w* c' W: ^- }
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 s" B' k) l2 A- ?1 W- ?* I
printf("Press any key to halt:"); 7 P8 Y0 k0 M2 n) z0 b
getch(); 1 E1 Q% h: w% p: R( M$ H. w
exit(1); /* terminate with an error code */
+ i8 l2 w3 M" Y} </FONT></P># i5 j' V% i7 m& K, H) b1 F
<P><FONT color=#0000ff>x = getmaxx() / 2;
# u0 F* q4 E! j8 e3 E% sy = getmaxy() / 2;
! }' S0 z1 s" yht = textheight("W"); </FONT></P>% [' S% e1 u  T
<P><FONT color=#0000ff>/* select the off screen page for drawing */ ! ~7 `1 ~1 J/ U) [& `: c' J
setactivepage(1); </FONT></P>
5 E$ o& t/ P# Q6 O$ D4 r<P><FONT color=#0000ff>/* draw a line on page #1 */
8 e) y) N5 Y1 j4 t- g2 gline(0, 0, getmaxx(), getmaxy()); </FONT></P>
4 T4 Y0 S/ ~3 T  B6 R; W+ G0 F! I<P><FONT color=#0000ff>/* output a message on page #1 */
/ \5 J- W  X+ ^7 }$ Q9 isettextjustify(CENTER_TEXT, CENTER_TEXT); 9 o/ U8 n9 W1 j0 N1 q# f  r; p
outtextxy(x, y, "This is page #1:"); 2 z  ~0 k0 O" C. b$ Y. j
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
0 r9 B8 O2 b6 D5 j<P><FONT color=#0000ff>/* select drawing to page #0 */
4 N0 i6 S7 @' `  ~/ b! y* Q; }setactivepage(0); </FONT></P>
# e8 z" |- T) ]& @+ b  l! f<P><FONT color=#0000ff>/* output a message on page #0 */ 8 g% F1 ~+ _. k$ n- s1 @
outtextxy(x, y, "This is page #0.");
9 K8 P  C& ^- _outtextxy(x, y+ht, "Press any key to view page #1:");
1 P4 g. G4 X! |8 sgetch(); </FONT></P>0 c' t- Z* S+ ?6 ~9 p5 p/ ]+ s
<P><FONT color=#0000ff>/* select page #1 as the visible page */ " d- L* G% k( {
setvisualpage(1); </FONT></P>
# l  n3 ~& A; s$ h7 k<P><FONT color=#0000ff>/* clean up */
6 L6 M: k3 ]  D  Fgetch();
% ~) y7 m3 ?  n9 x  G  H8 d0 N! oclosegraph(); ( S  D) ~4 _+ Z1 o- N
return 0; - ^" t9 M) Q# D8 h
}
2 A9 A! G  P8 B2 q+ M</FONT>
; I6 J& _- B4 X- m</P>
3 Y' E$ _  R) C<P><FONT color=#ff0000>函数名: setallpallette </FONT>2 o( I# U: K& l$ a
功 能: 按指定方式改变所有的调色板颜色 . n) A$ Y: }+ Z- M! e
用 法: void far setallpallette(struct palette, far *pallette);
& b% S+ p$ v' S程序例: </P>
8 B. w# w( P6 S0 A+ h<P><FONT color=#0000ff>#include <GRAPHICS.H>6 ~3 R" O+ i# l) }3 Q( m0 f% \
#include <STDLIB.H>3 ?: {4 O" G; z' n4 R& D# o
#include <STDIO.H>
& `; @7 r$ ~3 C9 m& M/ V, z#include <CONIO.H></FONT></P>) h- @- I5 o* y2 Q
<P><FONT color=#0000ff>int main(void)
7 n* _- U, V8 l6 o! v$ R! T{ & {3 l/ x! M# c% C- [6 H/ b
/* request auto detection */
6 Q7 l( K0 b5 K7 l; u% x8 f4 Sint gdriver = DETECT, gmode, errorcode; " @% |6 Y1 s1 ~+ }
struct palettetype pal; 3 n6 W7 F2 M! y! W2 U6 V: O
int color, maxcolor, ht;
! g& j2 B5 o% r0 ^, n. f& Uint y = 10; 5 G: `  W7 ]  L9 ~4 c4 V% j  ~1 Q
char msg[80]; </FONT></P>  r& m" E# v+ n% X  D
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ {* L" ]; N  M9 Z( B. Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ P7 J) W' h; l& H: w" {. F: G
<P><FONT color=#0000ff>/* read result of initialization */ & e5 G8 s, G* |' @
errorcode = graphresult();
1 {6 O3 G. M; v, `: Rif (errorcode != grOk) /* an error occurred */
( ^/ H* A: V+ j7 D$ [{ & L( w4 w* ^% q( s2 R7 \4 O( [  \
printf("Graphics error: %s\n", grapherrormsg(errorcode));
# ^+ @5 J8 [3 n9 e& Z* b4 Oprintf("Press any key to halt:"); ) y6 X( T7 F. M& l3 y7 D
getch();
. R) A  P3 Y- {, e$ `9 K8 \4 lexit(1); /* terminate with an error code */
0 B8 F! V. T0 x: r} </FONT></P>/ F; L& v+ |4 f
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
2 W8 \% a' Y- \ht = 2 * textheight("W"); </FONT></P>
4 ~1 A- a2 L" \/ Y) n4 B; z<P><FONT color=#0000ff>/* grab a copy of the palette */
5 a% l3 \, y3 u0 a1 f) h2 dgetpalette(&amp;pal); </FONT></P>0 F4 i6 ~) L; W7 w. q
<P><FONT color=#0000ff>/* display the default palette colors */ . T, V, }- ?* H, O% U$ i- f
for (color=1; color&lt;=maxcolor; color++)
$ k' L& p: q* ^& W; C5 R5 s{
+ V0 s7 f4 G' S6 q" T$ q" x2 Bsetcolor(color);
& r: ^' D$ [: C# V5 isprintf(msg, "Color: %d", color);
/ u- ^5 @) ^# m7 d$ houttextxy(1, y, msg);
1 |8 _0 k  ?9 @7 I1 t5 m- `# j3 p0 `y += ht; " a, h% I4 z* c- Z! t6 w6 P+ ^
} </FONT></P>) Q. a. X& u. ~
<P><FONT color=#0000ff>/* wait for a key */ 0 x0 D8 {. {! S3 b
getch(); </FONT></P>5 A  B% n' I: R1 p
<P><FONT color=#0000ff>/* black out the colors one by one */ + e' ^, q2 P- Q) w+ \/ g0 w
for (color=1; color&lt;=maxcolor; color++)
5 T: m2 ^3 v9 V2 Q{
  V" U, N. e0 H- zsetpalette(color, BLACK);
  R9 R6 t0 ]$ c9 ~% Ogetch(); * Y7 \: d8 N+ s0 q/ _$ r
} </FONT></P>
4 }% c9 _4 ]# _/ ^! u. W1 e9 F/ S<P><FONT color=#0000ff>/* restore the palette colors */ 4 |$ }4 }( c5 W2 K- F3 J! {" |
setallpalette(&amp;pal); </FONT></P>, n' Q$ `. `% z
<P><FONT color=#0000ff>/* clean up */ % \& t$ M3 i7 p) k# T7 [
getch();
* R% q  {) N  s8 h; U8 r+ t: C6 Hclosegraph();
$ y+ K7 f+ h2 r# Wreturn 0; 0 S5 A9 M7 l& H6 z: H9 j; A
}
, H3 t6 S' v. K" e$ m' n& G$ r4 Y8 t/ j8 s# u
</FONT></P>* X0 F$ M9 V+ i5 K1 d( S
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
& W) O9 |- _. A: G+ k! [( l功 能: 设置图形纵横比 " q) \) D( u# g% I! H: Y& ~3 V2 O
用 法: void far setaspectratio(int xasp, int yasp); # i% g1 Q+ N; T+ N1 @, T
程序例: </P>% Y" ~4 X' `5 @
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! B1 S( z1 ~' w, {5 A+ z( a+ R#include <STDLIB.H>
" Q: [7 V1 ^+ r! v#include <STDIO.H>
& ?- S/ o! r$ e! F* D. h#include <CONIO.H></FONT></P>
' a. b$ j8 E  u9 z" Q+ X7 q<P><FONT color=#0000ff>int main(void)
- ?) S% u' s5 ]' G! H{ 7 u. t( u8 _" Q; O0 O& }
/* request auto detection */ $ a8 Z/ f6 b. \+ O
int gdriver = DETECT, gmode, errorcode; # Q$ c3 q9 H: e  Z" R
int xasp, yasp, midx, midy; </FONT></P>5 I1 r6 H$ |0 r6 S: k% w/ F
<P><FONT color=#0000ff>/* initialize graphics and local variables */
! z% s9 v) j! r2 ?& F  B: {" ?+ f+ Ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 R) t8 W: F1 h) s
<P><FONT color=#0000ff>/* read result of initialization */
/ v2 G: |9 ?! G  S0 s5 Rerrorcode = graphresult(); 0 k6 w) h4 D# l% E0 U
if (errorcode != grOk) /* an error occurred */ - B# r1 n3 O1 L( z
{
4 p7 w( y3 V( w! j3 E) h: gprintf("Graphics error: %s\n", grapherrormsg(errorcode)); , e1 u; W7 S/ o6 [1 e, C% w' ?
printf("Press any key to halt:");
5 h6 `; J0 ]! E0 wgetch();
, V0 U% c4 }& y4 M, jexit(1); /* terminate with an error code */ 9 s. a/ f' c! v% {& w+ G' u1 r
} </FONT></P>
) n: P! r5 j4 Z& V<P><FONT color=#0000ff>midx = getmaxx() / 2; 2 @' N1 ^+ x- g  F
midy = getmaxy() / 2;
5 X, q! l, w: }2 [setcolor(getmaxcolor()); </FONT></P>$ Z/ a* K8 V% I
<P><FONT color=#0000ff>/* get current aspect ratio settings */
! p1 ^  X# M* ?' r/ D% ?getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>) L) G1 g' C" B* g; a5 c& }
<P><FONT color=#0000ff>/* draw normal circle */
2 i% q/ _6 p' s5 ocircle(midx, midy, 100); $ x: U# A. R8 {) k: z
getch(); </FONT></P>. [5 d  E9 a; N, T4 {, m. D$ @& ?
<P><FONT color=#0000ff>/* claer the screen */ / \3 f/ }8 O9 I( I
cleardevice(); </FONT></P>) Y- g  x9 h- x* ?' }$ y9 U) |; G
<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */
, {  c% _4 B9 j2 ^( @; Bsetaspectratio(xasp/2, yasp);
+ d* z" [( e! {+ C7 x  `circle(midx, midy, 100); 8 v( c. R( ^( x: c4 }4 G# _
getch(); </FONT></P>
. h% }: ?! c# r! B<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ ( z, u: l- t" q6 f3 s
cleardevice();
+ Y3 X+ {4 ?6 Fsetaspectratio(xasp, yasp/2);
! q" K( a" l2 X  `4 T0 `" g% Tcircle(midx, midy, 100); </FONT></P>1 m* c7 {) ^' [' z0 }2 l. `3 m
<P><FONT color=#0000ff>/* clean up */ * D. `- k" A% ^) j- m
getch();
+ E1 o) l) y$ {+ Z9 X& ?6 `closegraph(); 8 y# J' {' U# o7 h& N4 ?
return 0;
- w2 _% x) [# h1 z2 j$ D} 5 N5 }) d9 ]+ T# d
</FONT># Q+ H" X! W3 e. O  R, Q
</P>
$ D; G! {% w0 w$ w<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
" K7 G0 P- W" _+ j# a* u" w功 能: 用调色板设置当前背景颜色
8 r* A" `" ]8 X# V4 [, |4 M$ L& [2 s用 法: void far setbkcolor(int color);
+ L. S" D  L7 ]% _7 Y; Y- A程序例: </P>9 Y& T: C3 T% l$ i
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; z# t8 i! o9 @( ?#include <STDLIB.H>  y) o2 Z8 M! w& U& f7 R( X
#include <STDIO.H>
% _0 x, @, y2 Q# p( ~  B& M#include <CONIO.H></FONT></P>
7 z3 {- x5 h& H1 L6 H/ g<P><FONT color=#0000ff>int main(void) 9 ]% X' S! [; _$ i& T! |8 ?
{ + A8 P4 s( w) Z3 W7 o' X2 j1 t
/* select a driver and mode that supports */
; i7 l+ X3 P: p7 U( T; d/* multiple background colors. */
" Q; J2 p. e. ^( O$ T# Lint gdriver = EGA, gmode = EGAHI, errorcode;
0 V$ Z: {+ B7 m5 h4 @& p8 wint bkcol, maxcolor, x, y; ' o7 D9 }# |& ]2 {* ^+ R0 w4 n
char msg[80]; </FONT></P>
0 z3 O: }7 e) M& S# q* e; D  ^<P><FONT color=#0000ff>/* initialize graphics and local variables */ + C+ ?7 Y5 O4 e
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) E5 i$ s, @* d' K# L& t
<P><FONT color=#0000ff>/* read result of initialization */
. j, x, E6 y; a4 qerrorcode = graphresult();
2 i) w/ i5 ^1 Lif (errorcode != grOk) /* an error occurred */
5 g. q7 c# r: x$ }+ i7 G) n" S{ # f3 t* V$ h0 p' F8 g) c4 S4 T
printf("Graphics error: %s\n", grapherrormsg(errorcode));
2 ]0 A  h2 p" h3 dprintf("Press any key to halt:"); * q0 {7 w! r& e- y
getch(); 1 i( g* N/ I8 }+ Z. a6 t, X* J
exit(1); /* terminate with an error code */
' v0 j( u0 e' T# u$ p} </FONT></P>
, I6 V9 y; T# Z& w- o1 F( I<P><FONT color=#0000ff>/* maximum color index supported */
  ?8 V7 U4 {2 W; ^4 w  nmaxcolor = getmaxcolor(); </FONT></P>( S- u( b: t8 Q" q
<P><FONT color=#0000ff>/* for centering text messages */
" X! r% u: }9 B; D! ]: e( ^" Zsettextjustify(CENTER_TEXT, CENTER_TEXT);
0 S! A9 c/ b4 R+ R4 m- _x = getmaxx() / 2; 2 X4 u9 \% ~! F3 b2 {
y = getmaxy() / 2; </FONT></P>' v2 V) \* [, M
<P><FONT color=#0000ff>/* loop through the available colors */ 4 I6 I6 Y4 J6 u; o8 m' L) p
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) / V+ i! ^+ d7 s, `; I7 T
{ 3 e* g& {0 K4 S* d0 X/ ]& @
/* clear the screen */   {0 ^4 N0 x/ c% t5 L) ~, U
cleardevice(); </FONT></P>
% v: F0 r5 ^3 i6 w<P><FONT color=#0000ff>/* select a new background color */
" k6 u0 m, r, O5 [setbkcolor(bkcol); </FONT></P>- a( t) U: K5 ?4 D; |
<P><FONT color=#0000ff>/* output a messsage */ / [( G: b1 [# L0 A( ^
if (bkcol == WHITE) 1 r1 w2 E' c% e3 G5 X
setcolor(EGA_BLUE);
, D8 G$ h. c# A5 |sprintf(msg, "Background color: %d", bkcol); 9 g+ p; U+ C0 s# x( h& O
outtextxy(x, y, msg); 0 L4 }- A; ~$ q8 R8 Z" |4 {0 O7 [
getch();
6 S! A* k8 V$ \7 m} </FONT></P>
# }+ ~, E' I1 z& W<P><FONT color=#0000ff>/* clean up */
: O* q, ]; v7 p6 Rclosegraph();
( a6 E  m" k  P) k: p" q/ Y3 Qreturn 0; & V6 ?& \: y7 r. \  k
} </FONT>
4 c" f  v; }, |) Z; T) `
. d% {7 L- f* c  e0 J</P>
0 c& Z- g4 y1 v* f; O4 S' B" I4 X. J<P><FONT color=#ff0000>函数名: setblock </FONT>7 q0 D& c& ?6 o: k& e6 Q
功 能: 修改先前已分配的DOS存储段大小   f. G1 g. O7 w+ r  y, |
用 法: int setblock(int seg, int newsize);
/ L3 G( ~3 }" T9 v1 d+ d. O程序例: </P>" S6 y; o) H6 r- A7 b
<P><FONT color=#0000ff>#include <DOS.H>$ w; r, q, `& H+ ?  |
#include <ALLOC.H>
4 j) ^( o3 Q4 T#include <STDIO.H>* [  G2 w# N# M, S. n) R$ @* V
#include <STDLIB.H></FONT></P>
, y7 ^5 s2 ^) ?+ h3 s: k<P><FONT color=#0000ff>int main(void)
: ]; v7 L5 z0 b8 f2 R+ v5 A{ 2 v& J2 L# f' C- H$ Y( q) w8 q
unsigned int size, segp;
2 Y1 l. O. o* T# B" Pint stat; </FONT></P>/ X) I- Y2 k" s
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
, ]7 p: j. ~) g, p$ j& p* jstat = allocmem(size, &amp;segp);
2 v" o$ @3 l$ P" I+ t6 Nif (stat == -1)
! @$ B; D" L# S( V( ~+ j! }; ~. k+ gprintf("Allocated memory at segment: %X\n", segp);
: o, C7 a' G4 }; f4 y/ belse 7 L% P' h! N; P: b9 B' a
{
) d5 P: O/ T# C, eprintf("Failed: maximum number of paragraphs available is %d\n", $ b$ m3 y' P  @7 i7 G. M1 t+ I
stat); 1 k. [, l  h( {
exit(1); ; v" A7 i0 d5 R* F% ]1 l
} </FONT></P>$ Y/ l# T1 o5 n5 b& J
<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
- b1 A$ g, p, k8 `% R! Mif (stat == -1)
0 ?% v- u/ j& u7 b" B8 C# hprintf("Expanded memory block at segment: %X\n", segp); 9 ]4 T  G7 }( M. _+ C! O0 r& z
else 1 R6 H2 z  ^; _' D
printf("Failed: maximum number of paragraphs available is %d\n",
+ U  C* Q6 Y+ r( V4 t7 K8 |- Jstat); </FONT></P>; L- }2 V: C) `
<P><FONT color=#0000ff>freemem(segp); </FONT></P>: }; [$ q$ Y; A
<P><FONT color=#0000ff>return 0; . E/ N. ^, _$ G0 F7 r+ d3 H: B
}
/ l7 i' Y7 a" h$ s8 ~; m4 k</FONT>$ L! D0 L0 l. o+ J; u
</P>* @7 p- R6 W. I) o
<P><FONT color=#ff0000>函数名: setbuf </FONT>
  R' e4 @- `( U- J6 J功 能: 把缓冲区与流相联
' p! a1 P; p' d) [% V4 L用 法: void setbuf(FILE *steam, char *buf); 1 Z$ u3 _! R2 u8 P" M% v( U
程序例: </P>; n* x9 n. W/ R2 S6 [$ G
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
" Q, y. [( j, p<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */
1 U, c0 s7 S+ J; F* K1 w" Gchar outbuf[BUFSIZ]; </FONT></P>
: a) |* W8 J8 b! T8 B<P><FONT color=#0000ff>int main(void) & R% W9 X, F+ S
{ : j% _* E! I( z+ O  a& S
/* attach a buffer to the standard output stream */
( V! u+ c. e( ?setbuf(stdout, outbuf); </FONT></P>
6 V. j/ a; E9 H<P><FONT color=#0000ff>/* put some characters into the buffer */
! s) S0 ]5 v+ D  b- }; Eputs("This is a test of buffered output.\n\n");
6 ?1 V! x% Z7 @( U3 Z9 Kputs("This output will go into outbuf\n");
4 m. E# u/ c1 p/ Pputs("and won't appear until the buffer\n"); . I' ?# A( l: _) Q: V0 c
puts("fills up or we flush the stream.\n"); </FONT></P>% M, H, A2 Z/ K. W" n8 N0 i
<P><FONT color=#0000ff>/* flush the output buffer */ * [% f, h; P" i: L  v1 P6 i
fflush(stdout); </FONT></P>
& s! A% S8 a! y1 _( z" z<P><FONT color=#0000ff>return 0;
* ~( ^& ^- [( v5 u9 V. `& Q& Z}
0 C, H) O1 x6 K& y7 M# G% E</FONT>
2 o$ K) J. F  j  M/ \+ R- ?</P>5 A% m, m  j5 b$ Y( |$ s
<P><FONT color=#ff0000>函数名: setcbrk</FONT> 5 M' u; e: I8 [1 z+ X. ?# ~
功 能: 设置Control-break 7 W5 y" O% i; z
用 法: int setcbrk(int value);
0 K' G& j! w! d1 n程序例: </P>4 h* D2 K3 u, E. n: h/ S
<P><FONT color=#0000ff>#include <DOS.H>* r. `( E; V. h
#include <CONIO.H>" g' p# D  z4 e. O2 s
#include <STDIO.H></FONT></P>
" {1 k4 I8 M/ p1 v  l<P><FONT color=#0000ff>int main(void) , T4 Y+ }9 h7 }9 o3 }; o; _( X
{ 7 s, V5 O9 R6 |0 _2 p. x  G
int break_flag; </FONT></P>7 r2 ?. Q5 K- Y5 U6 U7 O4 _2 d3 F
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
: `7 @' V  g! @4 cprintf("Enter 1 to turn control break on\n"); </FONT></P>9 ?- s) U1 |# S4 {* s" p  g
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>
% T$ q/ i% y/ {0 l3 H: f<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
( O* T% J; `8 u; `<P><FONT color=#0000ff>if (getcbrk())
- \  }+ X( C5 Y4 i4 ?% Cprintf("Cntrl-brk flag is on\n");
  ?4 D" `* X8 Z( G) Melse
! k7 s* L; o! Y1 X- Jprintf("Cntrl-brk flag is off\n"); 5 J3 s6 z0 C$ K, R5 h7 H6 A
return 0;
2 k6 n/ z! f' U, x}
! r: F$ n) t& l! n6 j/ P& T9 o6 R7 H' l' @6 E- R4 ~
</FONT>) |) x2 S2 \; f& h+ d4 R' n  Z% q
</P>
  _  o( W9 o7 n<P><FONT color=#ff0000>函数名: setcolor</FONT>
3 V8 A9 p* L/ S, A; I1 g# F( ]功 能: 设置当前画线颜色 5 \8 T* i4 [7 q, ?/ i
用 法: void far setcolor(int color);
& y! q4 Q. C5 A7 b: B+ i2 ]1 W程序例: </P>8 {6 G# n9 M# J9 b9 E* i, c7 x
<P><FONT color=#0000ff>#include <GRAPHICS.H>: e' X. ~) \4 k5 w; p
#include <STDLIB.H>4 O. f+ _) H9 `8 D/ s
#include <STDIO.H>4 D9 V" c: L3 q2 u' \( e" Y  ]6 N
#include <CONIO.H></FONT></P>
5 J7 N6 v# }  R2 B: ?$ I9 I' ?<P><FONT color=#0000ff>int main(void)
) e' c6 W6 ^( @6 H{ : c, E( D" h; {2 F
/* select a driver and mode that supports */ " ?4 E. f9 `0 I% ?8 `# F5 }6 v/ G3 H7 f
/* multiple drawing colors. */
; C1 q# Z9 U/ p% l5 vint gdriver = EGA, gmode = EGAHI, errorcode;
7 x: j/ z% C& v' W8 P  j5 h  jint color, maxcolor, x, y; 4 y4 E( I3 s* g5 P3 l5 [' A* f! A5 T
char msg[80]; </FONT></P>
2 E2 T. E! s8 t/ V<P><FONT color=#0000ff>/* initialize graphics and local variables */
; n5 @! L, l, m7 w4 T3 o' l0 U' ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 G4 S3 s+ Y. u<P><FONT color=#0000ff>/* read result of initialization */
9 T; k% g2 e" @% j6 q; cerrorcode = graphresult(); 7 P% E9 O1 l8 s2 ?3 G7 y$ v3 @
if (errorcode != grOk) /* an error occurred */
$ b% `- ?. l' R  i8 Q{
4 Y# g! p6 r9 R7 ^( b1 P* t$ Tprintf("Graphics error: %s\n", grapherrormsg(errorcode));
- I  s+ x6 a; H( \' F; W1 yprintf("Press any key to halt:");
' a6 X/ [% g# E  ggetch(); 8 o6 y2 Z: A$ k/ v
exit(1); /* terminate with an error code */
7 ]4 @7 t$ ?" h; i( Y# ~  u} </FONT></P>/ F. s! S5 G+ Z! w# p$ W
<P><FONT color=#0000ff>/* maximum color index supported */
2 m* U# x' ^7 j. B4 v% Vmaxcolor = getmaxcolor(); </FONT></P>
. ~6 Y& j8 B4 l5 r4 S<P><FONT color=#0000ff>/* for centering text messages */
. I0 q, [% |9 Psettextjustify(CENTER_TEXT, CENTER_TEXT);
8 S# }& N6 `' S8 I6 ux = getmaxx() / 2; * N1 ^6 j8 ~# R( U/ l: F
y = getmaxy() / 2; </FONT></P>
/ |' G) T5 S2 R  R( f* K$ O- i, j5 Q2 c<P><FONT color=#0000ff>/* loop through the available colors */ 7 O0 P/ T' y4 ~. F4 Q. w0 G
for (color=1; color&lt;=maxcolor; color++)
5 g/ F4 M: y/ I# R2 `0 Z) j{ % K" v% p. N4 H" Z1 G# T# s3 z
/* clear the screen */
7 y/ e' [0 C) F& Q' s9 @+ J8 {2 L5 icleardevice(); </FONT></P>' Y( j  k3 k4 \; \
<P><FONT color=#0000ff>/* select a new background color */
7 y$ m" A* b  M5 \; usetcolor(color); </FONT></P>
- N+ K% H$ @" `! Q8 |  n<P><FONT color=#0000ff>/* output a messsage */
9 {) m3 j6 n% G/ O0 n1 Rsprintf(msg, "Color: %d", color);
: c& T6 I, W: c( houttextxy(x, y, msg);
& f& I$ s* F( f1 ]getch();
# i( c# |+ W$ q& z! l} </FONT></P>; v* C8 f  a/ g3 ~& H& t0 ^
<P><FONT color=#0000ff>/* clean up */ 3 i4 o4 x6 U' Z/ ]* C3 Y( i. S
closegraph();
0 j2 U! U" H+ M" I, g: E0 Xreturn 0; / s& \7 P9 _6 T; ]- h
} : X# X9 {$ l- }0 l
</FONT>
  X1 i/ h1 S* e# b</P>  q& o- x8 D+ M% C. _! d7 r
<P><FONT color=#ff0000>函数名: setdate </FONT>  s. ?' ]5 l. J- f
功 能: 设置DOS日期
+ V: i4 e% b( {0 X8 x, y用 法: void setdate(struct date *dateblk); ) ]& \- [$ O4 Y5 o+ O  Y/ {
程序例: </P>* m. t& R- O+ G$ r; F
<P><FONT color=#0000ff>#include <STDIO.H>
2 b1 w! ^% j* j9 Y; S#include <PROCESS.H># B1 ~  U5 F6 U- }* P% D
#include <DOS.H></FONT></P>( ?% ]% `* a6 E. t& t/ o+ S
<P><FONT color=#0000ff>int main(void)
' ^) @0 B8 ?& B2 Z; y{
2 l2 Z5 R) `5 A$ o% `5 Fstruct date reset;
/ r9 B% Q+ b) F- f. Ustruct date save_date; </FONT></P>& m6 N, I: a8 d* a( b1 c" O& j+ h
<P><FONT color=#0000ff>getdate(&amp;save_date);
$ {$ j3 [0 t8 _! p7 [& Zprintf("Original date:\n"); ) B3 b& G# \( ?$ l1 \
system("date"); </FONT></P>8 Y% H; N" D+ q. ^
<P><FONT color=#0000ff>reset.da_year = 2001; 4 Y+ a1 I2 {% t+ B" [& ~
reset.da_day = 1; ) o; @1 W* }- W$ w4 K( A6 ^
reset.da_mon = 1; . m: t  ]* U) {" n2 `
setdate(&amp;reset); </FONT></P>
, x# ^6 K! C% B<P><FONT color=#0000ff>printf("Date after setting:\n");
+ m$ I; r/ b9 l  Bsystem("date"); </FONT></P>( q6 `+ x+ A/ r( O( x/ z2 x' n
<P><FONT color=#0000ff>setdate(&amp;save_date); 9 p# L% U0 S0 Q4 f
printf("Back to original date:\n");
0 Q0 y: f9 }7 U: M! r/ Fsystem("date"); </FONT></P>7 _% N: l; ~: _0 M# _
<P><FONT color=#0000ff>return 0; 3 h  o* e8 G) Y: {
} ) L! m( E) w1 N& T7 a
</FONT>, Q, ^, n4 K) X8 x
</P>1 J- D7 H7 p8 M
<P><FONT color=#ff0000>函数名: setdisk </FONT>
- ~2 J  ], e" h功 能: 设置当前磁盘驱动器 . g; c* [  G% c) s: ]
用 法: int setdisk(int drive); " X  x2 P/ h' b' c- \- I. O
程序例: </P>1 P+ B, x, w+ L
<P><FONT color=#0000ff>#include <STDIO.H>7 _2 n8 X* o& X
#include <DIR.H></FONT></P>
( \6 P6 g" L% y" O- ^' t3 C/ S9 a+ q: M<P><FONT color=#0000ff>int main(void) / `+ }& }8 c2 ^9 L4 P4 B7 M& ~
{
; |% w- C) O7 P$ w5 Q5 _int save, disk, disks; </FONT></P>
, _5 M7 \) r9 h+ Z1 K' k<P><FONT color=#0000ff>/* save original drive */ 0 R" i5 \; T6 @( a  O# i- W
save = getdisk(); </FONT></P>
9 |# M, U" v" D9 b" }1 W<P><FONT color=#0000ff>/* print number of logic drives */ 1 B( J& b8 l! y0 K7 A/ Y3 Y3 i5 \
disks = setdisk(save); , g! J8 I% T& H0 I3 g8 P" Y
printf("%d logical drives on the system\n\n", disks); </FONT></P>( L, u: ?4 P: j& j, R
<P><FONT color=#0000ff>/* print the drive letters available */
1 u0 X6 V5 |2 v9 p6 Mprintf("Available drives:\n");
; P; ?3 Y, |, T9 M7 s  M: ?. Xfor (disk = 0;disk &lt; 26;++disk) 4 U/ t; a# J3 v
{ * T+ {0 \0 e3 n2 G
setdisk(disk); 1 i. D: o* w0 a% c
if (disk == getdisk()) , ^7 \; e& ^' J$ n- K
printf("%c: drive is available\n", disk + 'a'); 1 m5 p) h8 M3 f# f9 H% Y
} & }6 b/ i) a1 P# p
setdisk(save); </FONT></P>
( K7 r1 V+ j% j<P><FONT color=#0000ff>return 0;
5 ~/ F& T  {1 R" H8 l0 b} </FONT>
, b! B/ c5 v0 F0 D, b5 K) b% r" f4 r
</P>: s, Y* \4 f' d$ P0 G
<P><FONT color=#ff0000>函数名: setdta </FONT>
; _) F; h1 x4 g, h# j" c5 b4 C) S功 能: 设置磁盘传输区地址 * v" z$ k. ^" G3 l9 f
用 法: void setdta(char far *dta); & v, B( J, m6 j6 }; x
程序例: </P>
+ R# A: ]) N/ o- G+ G$ A<P><FONT color=#0000ff>#include <PROCESS.H>
6 Q6 x4 A. |, K/ H& _% t' e#include <STRING.H>
5 E4 o! t4 J  @+ _& N* z1 |, R- Y/ N#include <STDIO.H>
+ A( X2 d% X5 D: _#include <DOS.H></FONT></P>" t4 P$ `0 A3 K* f3 D, ~- j
<P><FONT color=#0000ff>int main(void)
# G+ z+ k$ F3 \1 A{
; a/ G; h6 B3 G6 `- Rchar line[80], far *save_dta; 7 P3 I0 `8 J3 f
char buffer[256] = "SETDTA test!"; 9 w; R' Y" a4 n' L% D
struct fcb blk;
" O: j: r# R8 x3 r5 ?0 i+ ?int result; </FONT></P>9 }9 W. K& D4 O
<P><FONT color=#0000ff>/* get new file name from user */
0 n* V- Y$ J' T6 |* }printf("Enter a file name to create:"); % R' H$ N# c! A8 y: R9 X
gets(line); </FONT></P>$ W* A  G% K# T2 {6 F$ x1 S  J6 |
<P><FONT color=#0000ff>/* parse the new file name to the dta */
! g2 F( k9 G+ Q5 Y- {' R, G& jparsfnm(line, &amp;blk, 1); 2 u. D7 b# }0 z2 k
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
6 M+ L; I1 ^( r  V4 f6 H  }  ~<P><FONT color=#0000ff>/* request DOS services to create file */ 4 D% u/ t6 Q( t6 W+ e7 w' v
if (bdosptr(0x16, &amp;blk, 0) == -1)
0 @$ G; r, t- ?  H. C8 V/ R3 f{
# O: h1 ?1 u. ^! S2 t; N) M! nperror("Error creating file");
$ v* ]! ?$ S% o9 Kexit(1);
: y3 E. q6 _! S+ ]& l} </FONT></P>, h* Y2 ^: c  D% X" A
<P><FONT color=#0000ff>/* save old dta and set new dta */
0 c* D+ |- f  k9 m: ?save_dta = getdta();
  h6 D2 e, @* Q2 G" W" Jsetdta(buffer); </FONT></P>$ [: a2 F: Y7 G7 A% w3 d% m
<P><FONT color=#0000ff>/* write new records */ . n* E9 }4 E) |. G
blk.fcb_recsize = 256;
6 A9 R# k0 g- R$ Fblk.fcb_random = 0L; ) H* S9 Q+ q: P
result = randbwr(&amp;blk, 1); ' h3 z3 \2 i/ i# U7 }. A7 \
printf("result = %d\n", result); </FONT></P>7 d, Y3 Y' A6 S1 ^+ f# K( {
<P><FONT color=#0000ff>if (!result)
# h9 O9 D9 ^% a/ ], U9 e( Tprintf("Write OK\n"); " W- |4 A9 R( m% s! J
else * l+ [/ C; g4 Q7 g' l
{
9 f5 h7 P$ R' x) W3 r( ~0 X: Xperror("Disk error"); 7 {$ q! O0 N& b+ d2 ]7 x
exit(1);
; d' s" l- s: O6 L" Y9 _' R} </FONT></P>
5 w( B+ u* g& q0 {<P><FONT color=#0000ff>/* request DOS services to close the file */
1 p6 V9 [1 l; C# l7 mif (bdosptr(0x10, &amp;blk, 0) == -1)
' t3 y4 ?! V5 H{ + w9 p/ t$ C/ F6 H
perror("Error closing file"); 6 Y& Y! d  ^( J7 a, O% n& m
exit(1);
8 m1 ^" W/ m; l# \4 g$ h} </FONT></P>& o* |' ~6 p7 x. d  H7 {* G2 L  t! ]
<P><FONT color=#0000ff>/* reset the old dta */ : w$ W# l" _9 D  f8 F' j. ?
setdta(save_dta);
7 X# V: K* Q" q8 k, W4 jreturn 0; - i5 |% p( W$ n
}
2 K0 @6 Y' _# }</FONT>! J% v: k  L7 F% s% B
</P>
: p4 B+ ?/ f' z) B& y5 i<P><FONT color=#ff0000>函数名: setfillpattern </FONT>( ~( z' K: ?4 d0 F2 h, X5 h
功 能: 选择用户定义的填充模式 % |% }3 H) N. p, n& I% E
用 法: void far setfillpattern(char far *upattern, int color); 3 B7 Y8 R, I5 l6 ?7 {
程序例: </P>
% `, X0 a1 ^" l% b$ p- K8 V<P><FONT color=#0000ff>#include <GRAPHICS.H>$ v& X  G. @9 ^8 x
#include <STDLIB.H>; l) z$ E% c* W  F6 `
#include <STDIO.H>+ B7 f/ [0 ^: [
#include <CONIO.H></FONT></P>$ E2 ^; ^( C$ G& G, N$ N9 N& u% L
<P><FONT color=#0000ff>int main(void)
0 ?" Q+ e( Z$ x! x7 G{ : f/ W8 m" n8 ^4 R, {
/* request auto detection */
3 v+ G1 I) F1 J3 Iint gdriver = DETECT, gmode, errorcode; $ ~1 o! Q8 a- g/ [8 O
int maxx, maxy; </FONT></P>1 [8 o/ p0 G7 O& m" x2 m
<P><FONT color=#0000ff>/* a user defined fill pattern */
6 b) I! t8 |+ H& Nchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>
& U; X! k: e- v/ J+ B  F" o<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( u2 ~% T* k; O4 v6 S; Q. t$ E- H
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
2 H# r& e( G( m+ o$ P3 g4 E<P><FONT color=#0000ff>/* read result of initialization */   N3 g, \7 e9 @! W
errorcode = graphresult();
+ t/ t* d% O3 b- z: I! Aif (errorcode != grOk) /* an error occurred */ 6 S! d5 \# Z) Q( P' m7 K
{
& f3 Q' l. [+ N5 A3 u$ oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); , m0 W5 j2 s7 R! x
printf("Press any key to halt:");
9 Q3 v3 B3 L9 G- \- g: J; D8 ]% }( ]getch();
* H' J2 L# J- t! c2 ^' Vexit(1); /* terminate with an error code */ 5 O/ T' S- |" R  a
} </FONT></P>
3 v  M, K9 g& T* Z<P><FONT color=#0000ff>maxx = getmaxx();
3 e; U# I# a) K* u* ?maxy = getmaxy(); $ ~3 M" q: s0 N: ?$ T- r( C0 O6 k
setcolor(getmaxcolor()); </FONT></P>
4 l( v/ S3 U; l6 S<P><FONT color=#0000ff>/* select a user defined fill pattern */ ) v8 G) ]9 h4 h1 ?  ~9 W* c
setfillpattern(pattern, getmaxcolor()); </FONT></P>
4 d0 X$ v1 u% b<P><FONT color=#0000ff>/* fill the screen with the pattern */
6 E" I' o+ j  M: Dbar(0, 0, maxx, maxy); </FONT></P>: `) [6 \& t7 |- q9 a  X4 b
<P><FONT color=#0000ff>/* clean up */
9 f0 Y% R" d( p' ugetch(); % U8 j* T  ~# y3 ?5 b7 [9 h
closegraph(); ) Q4 W% L' K, _, u. {/ S& m
return 0;
  S) S; \& `# z- K0 U2 j}
; h' |6 J* L3 I, V1 F1 W</FONT>
9 _- O3 @1 d+ Y4 A</P>
- T+ i5 D8 v" p/ s<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
5 r% b/ R& q, F功 能: 设置填充模式和颜色
% \. H: ]% m) o) K9 }用 法: void far setfillstyle(int pattern, int color); - h! p0 n, u# I1 ]- k1 E* e: P; c
程序例: </P>
3 Z. z3 g; W4 o6 e  d9 J<P><FONT color=#0000ff>#include <GRAPHICS.H>
( Z! }9 A. ~) ]7 J1 n#include <STDLIB.H>
: w6 t1 t% o; g0 ~* M#include <STRING.H>5 u" J2 R2 i9 R  c8 }! f
#include <STDIO.H>
5 {! ~( P4 t$ [; s/ [: i) w#include <CONIO.H></FONT></P>
( v' h7 v& ~2 z6 [: t4 a6 _<P><FONT color=#0000ff>/* the names of the fill styles supported */ " |& f0 {/ D. ]' ]1 k* U9 s
char *fname[] = { "EMPTY_FILL",
1 B, v7 ~) N5 h! _"SOLID_FILL",
$ i, r) }! P4 C3 T1 K( |" l"LINE_FILL",
7 m) c; U8 m' G, B3 [( \4 h! f"LTSLASH_FILL", 2 A3 x; P& G$ y* L
"SLASH_FILL",
1 @8 T+ ~/ B0 I) ^6 x  r"BKSLASH_FILL", ) K9 \& s) t  \% i) i9 ^/ ?
"LTBKSLASH_FILL",
4 ~1 ?; S  l* ~8 X9 x3 _3 ]' A"HATCH_FILL", - S* x1 g$ E3 q3 O3 X  i
"XHATCH_FILL", % f$ U5 c* D1 a' a% R
"INTERLEAVE_FILL", ; C2 N6 I& [* ]& J- G. D+ ?
"WIDE_DOT_FILL", 5 t6 ^8 R! ~: B# |1 G! B
"CLOSE_DOT_FILL", # r6 g1 S) o8 v  M3 h; _
"USER_FILL"   \+ d) i' c) f  B5 q) {
}; </FONT></P>6 U4 s3 ]7 ?( E4 o
<P><FONT color=#0000ff>int main(void) - \& m1 H8 t9 e: A7 p7 T
{
1 v2 o$ r& c; L9 Y& \# K/* request auto detection */
6 e/ I) a1 J! j: t9 K1 h" I9 a& Kint gdriver = DETECT, gmode, errorcode;
6 }, C6 Q9 @# c. P0 Vint style, midx, midy; 9 Q4 d' @& {7 x1 z4 n
char stylestr[40]; </FONT></P>
5 {( `* _3 y7 w; S4 u- n<P><FONT color=#0000ff>/* initialize graphics and local variables */
, A: k+ M& n2 C1 P0 Oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# I" R: y8 l7 N# K6 ]7 n<P><FONT color=#0000ff>/* read result of initialization */
$ G4 s" s  X. Uerrorcode = graphresult();
7 {9 R( \" R. x( u& u# Kif (errorcode != grOk) /* an error occurred */ 3 k8 d* W! l: c
{ $ C0 h) E, O" G% O. ?
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 7 x- v# A3 v8 v& [3 E9 ^6 d$ C& \
printf("Press any key to halt:");
) A- i) n: C! K$ Z0 f- s3 A) ]# Sgetch();
1 Y2 s& A8 c' f8 X; [& _  W. Bexit(1); /* terminate with an error code */ 8 _. P3 A" Z$ ~$ u& Y; h. |* q
} </FONT></P>
  c- U3 k% V6 x& b6 Z! T<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 m9 o4 f* l% V/ \; ]midy = getmaxy() / 2; </FONT></P>
+ y9 I; c, L5 `<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) 7 m1 ~; n% ?3 R
{
( |; X# c4 I4 c6 [( A/* select the fill style */   v+ F; N5 F5 ^% w7 a
setfillstyle(style, getmaxcolor()); </FONT></P>1 J$ Y- `8 z% |2 E5 c" I
<P><FONT color=#0000ff>/* convert style into a string */
% {: v% K1 M( d7 D& p* g" l6 lstrcpy(stylestr, fname[style]); </FONT></P># x+ t. l6 W9 M  b6 n6 ^7 }
<P><FONT color=#0000ff>/* fill a bar */ 9 W& H3 ~7 |1 [- r. B; v' R+ X0 I3 {
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
0 V# O6 c% M1 Y7 _2 B, {+ h<P><FONT color=#0000ff>/* output a message */ 7 g& w. v* N! g( R) i3 r
outtextxy(midx, midy, stylestr); </FONT></P>
% j" }" S/ ~; z/ @<P><FONT color=#0000ff>/* wait for a key */
' Z' ~7 ~$ _" X4 t! n7 X2 zgetch();
1 z  B: n/ H: T3 C5 ~4 {cleardevice(); ' z) l3 d9 [) [$ g( _
} </FONT></P>
  y' S/ a( i; j2 D9 o<P><FONT color=#0000ff>/* clean up */ ; q* ]+ O- ^* v& e) R2 w$ B1 Y4 R* g
getch();
) l8 ?2 d8 ~+ ]$ D+ Rclosegraph(); + j7 Z1 U3 i( D9 {6 U
return 0;
7 f4 Q. ?) k' B; }+ Y0 v2 v} </FONT>
2 J& {2 s' z( r! K0 V1 m) b/ P9 s) r" `6 V5 a3 l- R, x+ R
</P>3 O& h4 d0 r5 ]: G
<P><FONT color=#ff0000>函数名: setftime </FONT>' Q- u+ l% x" [. {7 O4 o0 A+ n
功 能: 设置文件日期和时间 + y( o8 ~3 @, a- Q. O
用 法: int setftime(int handle, struct ftime *ftimep); ' K* P3 }6 R& V4 M$ U
程序例: </P>
( {8 ]4 l4 `* O" @# e2 O" \+ h<P><FONT color=#0000ff>#include <STDIO.H>+ T' g" q1 Q; J( ]! @: V
#include <PROCESS.H>: ^/ O  Z4 d* J6 |( F1 E; d1 r
#include <FCNTL.H>
& C7 F- x2 J3 }4 K# ^- f! Y#include <IO.H></FONT></P>. W! C& G2 M' E7 O; \  G
<P><FONT color=#0000ff>int main(void)
* z9 {+ y  }5 M: g2 ^8 ]- ]{ 8 B- B6 x+ c8 @$ j* x3 X9 ?' y
struct ftime filet; ! h3 B7 M( F" a3 o4 ~
FILE *fp; </FONT></P>
- j, H+ q6 e2 r' c<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) 2 ^7 j! x4 w7 i% n+ Z! @
{ * n. a- D! p, Q3 E  f; X  }! h
perror("Error:");
. h8 a0 X. y+ R6 vexit(1);   C1 A$ o. I( i6 K3 A4 X
} </FONT></P>4 M6 L3 X1 |( [1 B+ Y
<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>
2 h. J( n" [7 ^3 v. \1 E. B3 W<P><FONT color=#0000ff>/* load ftime structure with new time and date */
* H( ]$ s7 [( _( c: @" J; `filet.ft_tsec = 1; 1 ~+ q; d& l: D6 \/ L# Q
filet.ft_min = 1; , x/ B6 L" ?/ [8 Q' {( y0 m' j
filet.ft_hour = 1; ) U$ {0 ]' V! k" D3 l
filet.ft_day = 1; 3 ~$ _9 g4 w) Z% G- `) _8 _
filet.ft_month = 1;
, u% H/ w5 q4 o9 R% }filet.ft_year = 21; </FONT></P>& A5 G, I, X3 A- q$ w+ i
<P><FONT color=#0000ff>/* show current directory for time and date */
1 d" I& l: t$ V0 f/ Msystem("dir TEST.$$$"); </FONT></P>' q2 E1 L, W  G& n
<P><FONT color=#0000ff>/* change the time and date stamp*/
  c& p4 p- o  `! qsetftime(fileno(fp), &amp;filet); </FONT></P>
+ O2 K* [4 t2 `7 B4 r; t<P><FONT color=#0000ff>/* close and remove the temporary file */ ( I8 z7 B& t3 ]4 V/ h8 F
fclose(fp); </FONT></P>
# `; l/ v& w- K* |9 Z<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>+ O: J  f! c9 [$ z& ?3 B
<P><FONT color=#0000ff>unlink("TEST.$$$");
& e7 _/ o3 i3 Treturn 0;
, a! T  @2 w+ x2 H" Q0 D2 ]}
, x0 Q1 T( n9 u0 {6 L7 L</FONT>! H6 U. z% ~, G( Z
</P>, P# l" P8 }! y$ ~
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>/ b* c, f1 k5 m7 D
功 能: 改变内部图形缓冲区的大小
+ ~% s/ M2 W; l  j; G1 f& q  I4 F用 法: unsigned far setgraphbufsize(unsigned bufsize); * |. ]# i2 ~- Q2 J2 t
程序例: </P>
' |3 w) n/ M) R4 m<P><FONT color=#0000ff>#include <GRAPHICS.H>8 ^1 K4 H) N9 O/ g- C
#include <STDLIB.H># v% F1 S% f: f) j  r/ Y4 D
#include <STDIO.H>9 h8 b2 m- Y! {% t, U
#include <CONIO.H></FONT></P>1 O$ M7 }5 H/ X7 N' H6 X
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>
* w& u" A" d# Y9 ~<P><FONT color=#0000ff>int main(void) ' M( [% S" R. Z5 X( D& Z
{ & f+ y' U* r) T' y
/* request auto detection */ , `" N7 Q7 l2 w7 O% c
int gdriver = DETECT, gmode, errorcode;
$ F; b, N! n, M+ j/ G! hint x, y, oldsize;   ~& a# w' y3 y5 A5 ?
char msg[80]; </FONT></P>3 L; G/ G) S2 G! L  ~" V
<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
" C+ Z- D" J2 z4 M1 I/* before making a call to initgraph. */ 5 `: u/ E- b2 {0 b( X" y0 M
oldsize = setgraphbufsize(BUFSIZE); </FONT></P>' s+ n7 a/ B# O6 W. \
<P><FONT color=#0000ff>/* initialize graphics and local variables */ / v9 e0 o3 v. y; P! d
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) l6 ?- ?2 x8 i+ ^+ u
<P><FONT color=#0000ff>/* read result of initialization */ - X3 m0 D  j1 K6 e( f8 _. y3 p5 D& f
errorcode = graphresult(); " m" _: J0 b3 k) W! N
if (errorcode != grOk) /* an error occurred */
) [: J& c- n' n& R, d3 T7 n& J{
& X6 t+ g8 x+ g. Cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ; f: w7 w* G% o7 V# B! H& w7 _& R# P
printf("Press any key to halt:");
, j% u  a# X$ {$ ~$ e5 {4 C' egetch();
1 h2 X1 w5 t8 D& x3 @: Q2 e; V( c0 ^exit(1); /* terminate with an error code */ ! s! ?) e2 ~7 |: V* h4 A
} </FONT></P>/ j% b6 a; D2 v3 S) B% S
<P><FONT color=#0000ff>x = getmaxx() / 2;
  V* M& H: D; ]1 Jy = getmaxy() / 2; </FONT></P>3 B) }1 ~% P! Q
<P><FONT color=#0000ff>/* output some messages */ 1 ^, H% s4 c- u, G, ^* E6 X; b
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
9 c) G6 k5 q5 B/ [0 wsettextjustify(CENTER_TEXT, CENTER_TEXT); % n- M; r$ z2 U
outtextxy(x, y, msg);
. F" q2 X8 h" x. A5 j8 r1 esprintf(msg, "Old graphics buffer size: %d", oldsize); # W% V  Q" B# E- V
outtextxy(x, y+textheight("W"), msg); </FONT></P>
+ z$ O7 w! y! r3 d<P><FONT color=#0000ff>/* clean up */ : `& N6 [0 {- C8 n, E% y
getch();
) @+ a5 W4 ~1 O6 {6 x3 f2 }* Yclosegraph();
/ d  j# K5 d4 s1 @  vreturn 0; 1 L! H! N7 o3 a5 c0 }% M# p
}
) c. W1 L% U5 b2 n8 f/ |" Y% f% w/ N
7 ^- X. F- p2 i3 d  t4 w# c
</FONT></P>4 v% R. `/ i9 P
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>, y3 W9 E. ~1 Q% t. {" C
功 能: 将系统设置成图形模式且清屏
; w( e8 f  v  t. T8 Z5 s用 法: void far setgraphmode(int mode); 0 w: H9 p& g  E' [; Q6 o
程序例: / C1 V" x; z+ ^0 N: _8 U$ u$ @
& p; Q  t! w6 L4 h/ ^9 K1 m
<FONT color=#0000ff>#include <STDLIB.H>
4 I1 g8 H3 D/ |2 j2 P% c#include <STDIO.H>( n( I! ^$ p$ X# J0 @
#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
7 Z8 J, |% j2 E<P><FONT color=#0000ff>int main(void)
8 W( s0 W0 [/ e, M: ~) s+ Z{ 5 I, d2 V7 ^! e% p
/* request auto detection */
$ C4 W3 ~& M; `6 g( G/ tint gdriver = DETECT, gmode, errorcode;
0 }) {0 d9 V5 T3 Wint x, y; </FONT></P>2 }3 v* _- K' k5 M3 Z
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , k+ R* c) Q+ a3 h, C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ Z4 C. m2 G; {& x" u' m- F
<P><FONT color=#0000ff>/* read result of initialization */ 3 [2 I) t8 _" K
errorcode = graphresult();
5 U( I4 L) v7 Wif (errorcode != grOk) /* an error occurred */ & }; n2 X) W1 _) j% K. u# k
{ ( x$ K7 I+ P  {3 B, M) [
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * l5 Z4 y% M$ }5 ~  i
printf("Press any key to halt:");
, }  c2 J8 Q9 Mgetch(); 9 \9 u" W5 D2 }5 a* C) D9 V
exit(1); /* terminate with an error code */
9 y  {" S9 ?5 R0 E  O} </FONT></P>
% Q2 u# U6 x3 T0 E( q1 J<P><FONT color=#0000ff>x = getmaxx() / 2; . v$ ?, u* j7 Z# ?% A+ o/ z
y = getmaxy() / 2; </FONT></P>
3 V0 \- J, N/ B0 U<P><FONT color=#0000ff>/* output a message */
: e; i% C4 }* e3 I6 wsettextjustify(CENTER_TEXT, CENTER_TEXT); 2 }0 [% z/ U: c% X5 L
outtextxy(x, y, "Press any key to exit graphics:"); ( B6 G& t" c3 @. o; f* h
getch(); </FONT></P>: @1 M7 l" V8 O1 f: ?* m8 O
<P><FONT color=#0000ff>/* restore system to text mode */ ) i% K) P% `/ _$ _7 ?! E4 `1 ?/ V
restorecrtmode();
7 C) W1 q/ n6 S7 f9 E1 T/ ?! R+ u& m; wprintf("We're now in text mode.\n"); 6 _  g  [9 Q1 w+ M  u* X! C+ @+ s3 Y
printf("Press any key to return to graphics mode:");
) n$ l$ W- D! ^5 c& Q* R2 y# \getch(); </FONT></P>4 \- ~7 S1 Q0 p* f
<P><FONT color=#0000ff>/* return to graphics mode */
' Z; e3 d+ ]* k5 ]setgraphmode(getgraphmode()); </FONT></P>
' h  p, F' y, N: U: y3 Q<P><FONT color=#0000ff>/* output a message */
0 @& Z- \/ }+ L+ f3 ~/ ~3 s. psettextjustify(CENTER_TEXT, CENTER_TEXT); " A9 N( v' u5 J2 X9 U) b7 @
outtextxy(x, y, "We're back in graphics mode.");
8 R. m; n/ W; k: N7 Q9 I* L9 Routtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>
# w0 v  Z* X( {# f! R& K3 f  o, @<P><FONT color=#0000ff>/* clean up */
: j5 J/ Y: c9 T; l8 p9 D$ Egetch();
; U$ W2 i$ H3 f, u+ U/ T0 _) W4 _% \closegraph();
, {$ o; d, r+ T' |return 0; $ ]& ]0 p6 _7 _+ Y7 ]
}
# X, j% Y- }; A* P& o- Z/ e0 W
# E3 C' _3 r. t2 L! ~# g( v5 S0 K! Y' o8 J& l
</FONT><FONT color=#ff0000></FONT></P>
. H8 H* f  S/ U; v<P><FONT color=#ff0000>函数名: setjmp </FONT>
% A: v2 o+ b1 @0 b4 k/ }2 c功 能: 非局部转移 * ^) _4 H  D# m4 c, }' P
用 法: int setjmp(jmp_buf env); 7 I0 t. B: ]# P
程序例: </P>0 ?: H2 |  R/ W/ ?/ c- C3 D
<P><FONT color=#0000ff>#include <STDIO.H>
# q2 C* f/ S8 O#include <PROCESS.H>
" P1 P) @5 y) \7 C#include <SETJMP.H></FONT></P>" }) J4 O2 d8 L* `$ s, Q$ N2 _
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
* a" M, w; a. r4 q' m8 \9 ?<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>% F5 R6 l  N+ A' Z. v/ Y7 @& c
<P><FONT color=#0000ff>int main(void) * \4 @. O  E6 D6 U. S' ^5 l  J0 e
{
; Z+ R$ M# E2 g5 \4 C. Oint value; </FONT></P>* F' ^' N7 V( R( U0 z
<P><FONT color=#0000ff>value = setjmp(jumper);
- G' [2 e( k2 F. m6 I# X# Lif (value != 0)
5 I5 x  o) w0 H+ ]  c9 s$ e{ 7 Y* |. A4 b. v4 @* b
printf("Longjmp with value %d\n", value);
6 \9 a9 R6 {, o1 Lexit(value);
* Q$ m+ s- o$ ~% W}
7 Q1 w8 I. P$ T7 p  ?. Cprintf("About to call subroutine ... \n"); ! R/ e* A" R& S2 _# v
subroutine(); / k2 W  c$ K3 B! f. `
return 0; / `3 ]) P0 K, \8 Z- o
} </FONT></P>
- E! p) M( f/ D% k<P><FONT color=#0000ff>void subroutine(void)
- y. l1 K0 A8 u) k) T- D  n{ ) C# O0 p0 R5 t3 m+ w5 k; Y, Y
longjmp(jumper,1); $ [4 E) c7 }5 t) j
} : ^' o8 ^/ U, C  u
</FONT>
0 _, X0 M2 c: \" Y  O</P>5 R; M% Z. M0 a/ n7 B
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
' x4 q; T) D0 Y0 k, ^/ @9 J6 C, E* D功 能: 设置当前画线宽度和类型 * k1 c- H+ I. y2 s5 Z  g2 G. B
用 法: void far setlinestyle(int linestype, unsigned upattern);
* @/ d  A: m" H/ \) |: M- W程序例: </P>' F+ d! A( D) c) C
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! P6 G3 V  o/ @) y) J#include <STDLIB.H>
3 M( X% r7 M7 \7 l; @# ?#include <STRING.H>
* T; P1 N7 ?8 p3 a  y$ [#include <STDIO.H>
1 V/ ?% b; F+ {3 y8 x+ y8 k#include <CONIO.H></FONT></P>& K: _  D, g/ m  U9 F
<P><FONT color=#0000ff>/* the names of the line styles supported */ ' a2 L* Q8 \. T
char *lname[] = { - N; b2 R2 O+ W8 X2 b% X: j
"SOLID_LINE",
' E( T! Q$ [; [0 ?( z& G0 Q"DOTTED_LINE",
& P# p  s4 U/ O. t* B1 V9 {* d2 ?"CENTER_LINE",
. y' z- ~2 `/ }* B"DASHED_LINE",
7 D! |- N5 z& T, L. G"USERBIT_LINE" " ?* _! \# e$ d$ N2 r1 k
}; </FONT></P>3 j- L2 J5 G3 z" s
<P><FONT color=#0000ff>int main(void)
& u, W; i8 Y3 m( @/ ?; w: H/ o{
! v! t, r+ t4 x0 ]% E( K0 P/* request auto detection */   d$ w6 @3 I! B, J' B; g$ v
int gdriver = DETECT, gmode, errorcode; </FONT></P>
7 _8 ~6 \7 T: z& X3 I5 |! F  t3 S<P><FONT color=#0000ff>int style, midx, midy, userpat; ) {2 |4 i5 z) \' j+ q( A
char stylestr[40]; </FONT></P>
# k' ]" c9 y" q+ g<P><FONT color=#0000ff>/* initialize graphics and local variables */
* k6 n; D% d8 {0 Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" d1 _! F$ j0 R- B
<P><FONT color=#0000ff>/* read result of initialization */
3 w& t( s- W5 _4 ~0 aerrorcode = graphresult(); ) S( d6 A' k% k' b# p1 l
if (errorcode != grOk) /* an error occurred */ " H; j* t% O& x; [. D9 i0 l
{
: Z' E; ?+ q, ]# Z" g. \printf("Graphics error: %s\n", grapherrormsg(errorcode)); " o' i% w' q4 o3 n
printf("Press any key to halt:"); 8 L8 u. p( r% e  x% {- y& [
getch();
5 m2 b7 R) d8 X( H. B$ g$ jexit(1); /* terminate with an error code */ 0 \2 Y! k+ T  O2 X) I7 J
} </FONT></P>
! \5 A) X7 U' O3 x6 G8 v: K8 Z5 ~1 S<P><FONT color=#0000ff>midx = getmaxx() / 2;
( X9 r/ G$ y8 Q- ~midy = getmaxy() / 2; </FONT></P>. @, T5 T. v8 d
<P><FONT color=#0000ff>/* a user defined line pattern */ + |, |% d+ \9 _" d- L
/* binary: "0000000000000001" */ + \# z+ }& Q5 N2 V6 @* r
userpat = 1; </FONT></P>
% Y% q6 P& E4 W8 Y3 g<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++) : C% q( H) @) _+ a4 x' w# Z
{ 5 r% m+ q4 t: W1 G, s; f
/* select the line style */ * ^; v/ ~1 y2 Z. E
setlinestyle(style, userpat, 1); </FONT></P>8 B/ I% n  T* @/ D# N, {
<P><FONT color=#0000ff>/* convert style into a string */
- n" d% w8 h, x6 Z; c% l, jstrcpy(stylestr, lname[style]); </FONT></P>
1 a+ Q; Z% q8 A, d<P><FONT color=#0000ff>/* draw a line */
! n& p" A# e# V0 y# G8 A8 Oline(0, 0, midx-10, midy); </FONT></P>
, g. E. d) Z' t8 R/ j- p9 g<P><FONT color=#0000ff>/* draw a rectangle */
; b7 l2 ]$ W7 z4 {( n8 e9 \rectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>: G- J5 ^" N8 ^+ q: f$ m+ K
<P><FONT color=#0000ff>/* output a message */ - L* A" H# p; V) {( a% n
outtextxy(midx, midy, stylestr); </FONT></P>5 X- M  g5 I5 a' f* a. N
<P><FONT color=#0000ff>/* wait for a key */ . C/ x7 X3 W3 u4 F+ ^, a
getch(); ( j$ N- h! z* C/ d$ b7 _
cleardevice();
$ i# n3 y) k" e/ n+ Q. j7 T} </FONT></P>5 c0 N6 t! j8 G7 Q! S+ W
<P><FONT color=#0000ff>/* clean up */
- }' g. Z) j* G! E( nclosegraph();
" w! V" Z$ A' }9 L/ ireturn 0; 8 @3 |6 `5 W! p9 O/ ^
} </FONT>
$ v+ Y6 a( W+ ^, r9 K2 X. D5 q4 |% C: d
7 ]9 r2 l% D- S! @; B" b* a
</P>
$ ^* e. f& W$ H" y- `0 T8 t<P><FONT color=#ff0000>函数名: setmem </FONT>2 a8 J1 {7 j- @6 L7 H1 f& H" |
功 能: 存值到存储区
) S7 Z# u* Y' i# o: [9 l- R, H用 法: void setmem(void *addr, int len, char value);
0 J. L  G! u8 k8 {1 B6 q- N% \程序例: </P>! k6 k# D# b' v( x4 R1 q
<P><FONT color=#0000ff>#include <STDIO.H>1 f, V- U8 I  C/ S
#include <ALLOC.H>
# g$ p, F) p. ^  R$ \, x#include <MEM.H></FONT></P>; [3 _! J1 j! b" N, F/ a
<P><FONT color=#0000ff>int main(void)
1 ]" g% W3 e3 c) w* g{
' E1 ?3 R) E! W) m/ Ychar *dest; </FONT></P>
! r; h0 D+ ^" O& N<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
/ ~7 F7 A9 u0 z6 [setmem(dest, 20, 'c'); ! ^# b' P" [. j' \
printf("%s\n", dest); </FONT></P>' m/ M* a" K0 R* n! y
<P><FONT color=#0000ff>return 0;
# x! R3 Q( |, R: H- ?} </FONT># f8 E7 y* ?5 n9 m! Q
& @% D2 ?* S8 D$ |" `

/ }$ I4 u; g! A  T: D7 s</P>
; q/ W. Z$ L$ ^8 C1 M& d/ q4 }<P><FONT color=#ff0000>函数名: setmode </FONT>6 L, o2 }* h+ I8 \, z8 L
功 能: 设置打开文件方式 ) f! a9 W1 a& n! L! ?
用 法: int setmode(int handle, unsigned mode); 3 R# E7 L" \) s: d1 I0 J
程序例: </P>
/ n6 ~5 P# ?: F" i% v- X8 t) y<P><FONT color=#0000ff>#include <STDIO.H>& l8 f/ A2 [, g$ K. m
#include <FCNTL.H>
( J1 |5 x; u' C7 [% t* [2 }#include <IO.H></FONT></P>
. v: `/ q; m8 d" _& C, j- n<P><FONT color=#0000ff>int main(void) / n9 M4 O* K4 T" J8 D4 F1 I4 M5 L+ L
{ ) f% r0 M/ P4 m$ f) E0 {
int result; </FONT></P>* Q# ~8 X2 E2 K, N) F4 Z) D$ N
<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
" ]3 U2 a, u: F+ p2 S$ Kif (result == -1) + Y3 D- C. z! \7 n1 z
perror("Mode not available\n"); # B# Y* e! N' q. U  j: a1 q
else & U/ ]. C( i. z6 q* d) d: V: u
printf("Mode successfully switched\n");
* S9 ]8 ~2 s2 _7 \7 Breturn 0;
* w0 T! N. U4 @- [  a" K0 S}
2 n- W( J) \6 ~; I$ }6 Q
6 A+ Z! _# ?" _2 W0 N</FONT>
$ p0 z# i9 |5 [/ R+ M</P>
: R4 M7 X4 S+ v* \<P><FONT color=#ff0000>函数名: setpalette </FONT>
6 S8 s1 h( h* J7 @, I- W, j功 能: 改变调色板的颜色 " D7 t$ N* g* L& Z9 Y4 q8 f( ~, Z! t
用 法: void far setpalette(int index, int actural_color);
! q' g) C; b3 U% {程序例: </P>
2 N1 q6 }3 O8 W<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 K4 b) v  i& b% M' q! h' t7 y6 K1 f5 u#include <STDLIB.H>6 u# P8 n1 a% h1 Q" N, u7 T
#include <STDIO.H>: i3 c3 @/ S" W( Z2 E  {+ N+ L( k! w
#include <CONIO.H></FONT></P>; [3 H' p' C! x
<P><FONT color=#0000ff>int main(void) 7 l2 X2 k. Z. _+ b1 X
{ & Z" M% D  ~  o  k
/* request auto detection */ / k, V9 v2 ~: m0 S
int gdriver = DETECT, gmode, errorcode; $ ]% ~0 `% U7 t, G
int color, maxcolor, ht;
# T9 \$ Y& j) P& Xint y = 10;
& w: t/ _. }" \4 V8 gchar msg[80]; </FONT></P>2 d, n$ K& h: g, j$ Z: b* u
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . E7 g$ ^, [, l3 G: i8 a
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 z* g; u6 j7 d/ d1 T<P><FONT color=#0000ff>/* read result of initialization */
: ~/ p# j- p  W" Z3 Q! Aerrorcode = graphresult();   q6 S9 i/ U. q9 b
if (errorcode != grOk) /* an error occurred */
4 E4 w+ V; ~  g2 T6 C+ J; ~{
8 x9 B, m4 W5 m' A3 \$ [printf("Graphics error: %s\n", grapherrormsg(errorcode)); / z0 }! Z1 w: \6 l/ X! g5 I
printf("Press any key to halt:"); 2 q1 }$ q: Q1 S5 R& v1 \
getch();
& i* T8 B8 i& i0 I1 }' _exit(1); /* terminate with an error code */ * }' A- L  n" d4 E& y
} </FONT></P>
; H( G# C2 \5 O+ u  {: k$ @<P><FONT color=#0000ff>maxcolor = getmaxcolor(); 6 Q! N- E8 n( ]7 q. p
ht = 2 * textheight("W"); </FONT></P>
8 @+ s2 M+ d5 E! c<P><FONT color=#0000ff>/* display the default colors */
2 N* t( {! ~! I6 k  u6 Jfor (color=1; color&lt;=maxcolor; color++) 7 B! c4 g* W- ]) C% M5 F" J
{
8 w! L+ U+ B( f* t7 S" v8 Isetcolor(color); 8 w6 i1 s( D# i2 o9 C
sprintf(msg, "Color: %d", color); 0 p* f4 m4 }9 D! M' l' ^
outtextxy(1, y, msg); " R+ R4 r8 @  k7 x0 l
y += ht; 7 P: l* W& M- z! b2 h# H5 R
} </FONT></P># e, [7 Y/ V6 {8 Y* p4 V: F
<P><FONT color=#0000ff>/* wait for a key */ : o) ?" _- t  L5 e+ u' n$ ^
getch(); </FONT></P>( y- J2 Y( j1 ^8 s: X) _
<P><FONT color=#0000ff>/* black out the colors one by one */
# U6 Z* X% Z) r" p) \for (color=1; color&lt;=maxcolor; color++) 9 }$ H) d! T1 r  j7 ^
{
9 R/ C. n9 @2 \' }3 vsetpalette(color, BLACK); 2 z" U3 d1 {/ r/ c% w
getch();
& W6 v( a2 k3 W7 E7 q: Z& J, P1 P; m} </FONT></P>
; j6 e- E: G$ i% e" i: _( J<P><FONT color=#0000ff>/* clean up */ % u. K; N2 {6 p6 P
closegraph();
. x! e1 `( B+ {return 0; , E4 g/ m( n1 X0 i  V
} 8 ?9 F  P1 f0 L0 k6 e7 ]# B+ t
</FONT>5 B6 L4 M  {5 C- X
</P>9 d$ J4 n7 T, l; }
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>: u8 }5 A* C2 s8 S+ a! V5 A! ?
功 能: 定义IBM8514图形卡的颜色
# J! [: J" z) G用 法: void far setrgbpalette(int colornum, int red, int green, int blue); # W  k1 l& f- j+ T2 z' R
程序例: </P>5 I0 Y, b5 A# o
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* D8 r" D$ c- r8 \  y- E3 M! c#include <STDLIB.H>) f: o5 e: f2 d0 f  k
#include <STDIO.H>
; a! F  L9 e# j  u3 d$ A! K9 C* [#include <CONIO.H></FONT></P>4 m. m$ j- [! c# K' E
<P><FONT color=#0000ff>int main(void)
$ n1 S9 U  s9 O& s. l{ - u0 K  _$ u* f: M! `: n9 V
/* select a driver and mode that supports the use */
' N! k5 R8 f% ^7 U/* of the setrgbpalette function. */ : M1 d( g8 ^3 p7 d+ g! \. O0 }
int gdriver = VGA, gmode = VGAHI, errorcode; 3 y, A! c0 \8 }# n( o0 [" J$ z
struct palettetype pal;
: U( W, {" z/ k, B# U7 K. ^, Gint i, ht, y, xmax; </FONT></P>+ h7 O: @0 U& x
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 v0 M/ D( R  Z0 ^! n+ c7 Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>4 V+ K; r; f  J  B# S3 y$ V$ s
<P><FONT color=#0000ff>/* read result of initialization */
( {3 S& s( I, Oerrorcode = graphresult();
3 p3 {1 ]! J& f) l' {if (errorcode != grOk) /* an error occurred */
7 X1 M5 j, v- ]5 W0 a$ a, S7 t+ d{ / f4 l& r2 E/ r, b
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 A5 l3 H  d6 ]printf("Press any key to halt:");
: |: \; }" q8 S4 @" ~& G& Igetch(); ) e& Y4 F" z- t* R9 K# E0 |7 y( Z
exit(1); /* terminate with an error code */   ^( F0 ]. O. N! J8 @) L  }
} </FONT></P>
5 h& D7 x! T- M1 M% o<P><FONT color=#0000ff>/* grab a copy of the palette */   |  |# \+ t( L1 V
getpalette(&amp;pal); </FONT></P>
5 I9 w/ L) h- d$ L7 b8 z& C7 ^<P><FONT color=#0000ff>/* create gray scale */   J# ^, p9 u" T
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
/ x2 H" {) |* X& S<P><FONT color=#0000ff>/* display the gray scale */
9 I9 p2 j2 }: h3 c) ~/ s+ rht = getmaxy() / 16; % L8 p: L. F% d+ {+ a) X
xmax = getmaxx(); ! e* C5 Z; |' b
y = 0;
% S3 I+ A" ]# r# e0 lfor (i=0; i<PAL.SIZE; <br i++)> { ; m: S1 S% T, k) p7 h
setfillstyle(SOLID_FILL, i); / z  B$ X" l4 o4 g
bar(0, y, xmax, y+ht);
3 {- |& q  X( T& m* j' W( r$ Sy += ht;
" Y$ S* o4 s1 W: T* l} </FONT></P>
$ B& L) A1 F8 P. o! K<P><FONT color=#0000ff>/* clean up */ ' t0 Q* a$ [# W- D6 g" K& u
getch(); : k/ Y9 c" T* E1 F/ w% r! Q
closegraph();
, L. N5 x. r$ D9 jreturn 0;
; B2 `" e9 h: P8 F5 o0 ~- k, V} ! d( T& C5 G8 e  J
</FONT>
! u* E$ w9 d8 w5 i
8 S  L' a8 \. ]8 m' l# U' \" x0 t</P>
; m$ ^# O5 }. I! T" C: Q<P><FONT color=#ff0000>函数名: settextjustify </FONT>& i* n  x$ C/ w! B/ z& z; W# T
功 能: 为图形函数设置文本的对齐方式 ( q. q7 l# m7 q: |/ l  v9 u" ?6 w
用 法: void far settextjustify(int horiz, int vert); $ t/ ~" ?9 [$ M6 B6 Q& j- X
程序例: </P>
# g  B8 A& B& ?# ?6 s<P><FONT color=#0000ff>#include <GRAPHICS.H>% ~; j# \! k" @: P* ^  r% t
#include <STDLIB.H>
5 I; f7 n3 O  ]6 I( l#include <STDIO.H>
. ^. e) I, I0 K#include <CONIO.H></FONT></P>7 K0 T  w( G. @' B3 j
<P><FONT color=#0000ff>/* function prototype */ - u: }, S5 w& t6 o' {% a0 ?+ N, n
void xat(int x, int y); </FONT></P>3 A( `+ b: R' ~0 r/ G
<P><FONT color=#0000ff>/* horizontal text justification settings */
. C% P+ X4 `/ hchar *hjust[] = { "LEFT_TEXT",
0 S7 N- ^3 M& z$ `, y% {) Q& E' t" F"CENTER_TEXT", . ], [6 J( |$ r  D) L" J
"RIGHT_TEXT"
4 F% w6 C3 \2 A+ s}; </FONT></P>4 Z6 O: T1 T- K, d. D
<P><FONT color=#0000ff>/* vertical text justification settings */
7 S7 o/ V* l4 Ychar *vjust[] = { "LEFT_TEXT", , N/ \  d- _: p! _( S( Z
"CENTER_TEXT",
) T  X% y) H8 w# L- O"RIGHT_TEXT" + Q2 x. J3 e! t9 A6 `4 W* e
}; </FONT></P>1 N1 f6 s4 V0 |8 R6 Z4 Z. B3 [
<P><FONT color=#0000ff>int main(void) / w/ j! ?! W4 P4 G
{ $ ~0 J! z. ^' D* A% P5 a; a
/* request auto detection */ ! u4 L" k% }% |; e6 L+ c
int gdriver = DETECT, gmode, errorcode; + N/ N" |, N. V. B- ], p: r
int midx, midy, hj, vj;
) d- k2 d: S1 D" E9 c7 o& Kchar msg[80]; </FONT></P>; t6 u5 f8 P" B( x% R! Q; b
<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ N, B. D- x' B* a- ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( `4 o+ c) S# O0 A$ x/ A! ~<P><FONT color=#0000ff>/* read result of initialization */ 0 _- L4 ?# @/ i
errorcode = graphresult(); 3 A4 _/ }  G! N+ [' o
if (errorcode != grOk) /* an error occurred */ 6 h3 h; `& c. v% U: |% v
{ & g) S! v: U& @+ C+ y
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& Y! F2 ?* `3 u8 v) J& ]8 Kprintf("Press any key to halt:");
" |3 v4 o0 ]! i# w, k) zgetch(); 3 d! Z+ @0 ]) l1 P& q' N
exit(1); /* terminate with an error code */ 4 w0 c/ p: c+ j: k- {5 @
} </FONT></P>8 `1 n4 \! L, O; E
<P><FONT color=#0000ff>midx = getmaxx() / 2;
  f* i# j; U" \9 f( h. t0 k& v. nmidy = getmaxy() / 2; </FONT></P>
$ N5 u  v' I* k<P><FONT color=#0000ff>/* loop through text justifications */
- f8 A/ {0 ?. J" F- ^3 ofor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
* s  w$ \  f# q7 N$ q' ?& L8 Gfor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
3 t% `& K' z! o: G6 G8 }' n; q3 E{
4 f8 r5 E7 i/ E  u& J1 I0 mcleardevice();
" a0 F2 ?  Z  _; X. y% z9 n% y/* set the text justification */ " }! n* a, t7 h) ~5 x5 b
settextjustify(hj, vj); </FONT></P>
& N+ `2 }1 [" p; n' w<P><FONT color=#0000ff>/* create a message string */ + q- K  K, N8 i6 ^5 H; p
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>. ~8 S4 V) |. g3 ^1 J: n; c/ ?
<P><FONT color=#0000ff>/* create cross hairs on the screen */ % n& Y/ e. N7 L# S. @
xat(midx, midy); </FONT></P>
4 Q, r3 s  p! H7 M/ U<P><FONT color=#0000ff>/* output the message */ 5 U4 u% O6 q1 V, m( I& y* A
outtextxy(midx, midy, msg); % l7 O9 Y% R# |" Z9 P
getch(); 9 {  c2 I% Y5 m* N$ v( S/ V' g, g- N
} </FONT></P>
/ v  T9 y0 G& f<P><FONT color=#0000ff>/* clean up */ ! @1 w7 U( K/ G+ r, }9 A
closegraph();
- s$ c: C1 Q( C5 ]; c8 v3 s9 ereturn 0; . z3 n7 ]$ \! u: m" w" E- O  z
} </FONT></P>
! \7 k* x3 W6 N4 q* K$ b<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
/ ?3 V9 ~* O# r" X$ @: Q6 \void xat(int x, int y)
; F$ Q; S, u" J% j: a{
9 R/ N, ]8 ^% {3 D( }5 Lline(x-4, y, x+4, y); 9 O( x/ ]7 m' z8 Y" _4 V
line(x, y-4, x, y+4);
$ c0 m+ c! v. W3 V( D} </FONT>$ p: O$ u% k' z% }4 y

: ^6 ?3 j' B( o! }+ t7 n; H' ~% l</P>
7 Y0 U" a0 j, o: x; \+ D' Y<P><FONT color=#ff0000>函数名: settextstyle </FONT>
& M; K9 x1 o! k$ b5 g0 [& t$ ^. B功 能: 为图形输出设置当前的文本属性
' @/ z& D# q( d  Y; X7 B用 法: void far settextstyle (int font, int direction, char size); ( \9 y3 W- x7 _9 E' d
程序例: </P>/ h8 q; x) w! g* J  W% e
<P><FONT color=#0000ff>#include <GRAPHICS.H>. x" g* o4 L) |/ H" k; {
#include <STDLIB.H>
& K# L$ L' C9 F8 s: f' j$ u5 O#include <STDIO.H>
6 b3 S& |9 W( z3 X+ \$ H#include <CONIO.H></FONT></P>% \7 Y) P; p. k
<P><FONT color=#0000ff>/* the names of the text styles supported */
/ H5 m) ?* Y- Z; U$ ^7 N, lchar *fname[] = { "DEFAULT font",
+ U% p* _, ?* ~6 z# U"TRIPLEX font",
. L4 m1 u# B0 O6 k"SMALL font",
9 [6 H# x( o6 ^# y) U* p"SANS SERIF font", 5 p: H  y  k  M7 t
"GOTHIC font" - S0 r/ d: F* d0 V
}; </FONT></P>
3 H; l' @7 t) }% n0 V4 P, p<P><FONT color=#0000ff>int main(void) 1 I2 S. z3 ]! L1 l
{
% j$ l# _. Y- H+ V9 M/* request auto detection */
. z9 H# g# H! K+ L% B/ M' |int gdriver = DETECT, gmode, errorcode; $ k5 w* K. K/ ~' o+ u% Q
int style, midx, midy;
" K8 y- o8 f' q1 \/ T: [int size = 1; </FONT></P>. g" w9 [: e8 k1 }
<P><FONT color=#0000ff>/* initialize graphics and local variables */
. p( e. w  C0 D/ J; i; @/ ^initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 x# P! d2 @+ ]. U2 b% p2 Z+ _* R
<P><FONT color=#0000ff>/* read result of initialization */
( }2 {6 U  A/ U5 u! Zerrorcode = graphresult();
/ s5 m5 J+ o9 O! @6 H7 cif (errorcode != grOk) /* an error occurred */ 3 Y( X  j8 }- d
{ 4 [/ p  v  w/ S3 \& w: c
printf("Graphics error: %s\n", grapherrormsg(errorcode));
2 @! c2 ?& q, h+ `# k# Iprintf("Press any key to halt:");
, |: E. W6 z: W: @/ N5 Z4 Y2 k+ I, V  Ogetch();
9 j- o1 S. c% I1 j, Cexit(1); /* terminate with an error code */ 8 U9 X- y$ l# l! |5 @- d
} </FONT></P>! @2 y, V% M( c
<P><FONT color=#0000ff>midx = getmaxx() / 2;
3 B' `/ Q% F9 |5 g* Gmidy = getmaxy() / 2; </FONT></P>/ ~' [8 v2 e- {% Z8 ~% Z, X. y
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
; Y% A9 g, ?1 c8 H<P><FONT color=#0000ff>/* loop through the available text styles */
. M1 S$ v" c$ H0 `for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
. S5 W* ]6 J2 Z0 A% w) w- V{ 3 N$ o5 a2 J% a% R! [" j. Y# V! _
cleardevice();
- l, ^) f4 S2 \  Pif (style == TRIPLEX_FONT)
; u  Y4 j+ h) G. g" wsize = 4; </FONT></P>
7 `8 W' B, @; v<P><FONT color=#0000ff>/* select the text style */
4 l! {, g) E) W6 W, `0 W7 ~settextstyle(style, HORIZ_DIR, size); </FONT></P>
7 S5 X( T9 M% J" s' @6 q<P><FONT color=#0000ff>/* output a message */   z! B8 x& G  I1 V7 m
outtextxy(midx, midy, fname[style]); 7 K, q3 `2 Y* F) B+ Z" ~
getch(); & q% P/ Y" z$ O% h8 J
} </FONT></P>
, x. P0 D3 c8 z0 q* l<P><FONT color=#0000ff>/* clean up */
. ]' l4 P5 ^4 p; [$ Y3 hclosegraph(); - ?9 f! |/ T, g1 J0 g2 K& V, R
return 0; 7 q5 {% _2 X5 R" ]$ H* l
} 7 U- ^( E, @6 X
</FONT>
9 W* r  }+ ^# @$ f" E; S; h: Q, ^/ o</P>* M; I' K& Z6 S2 s2 H7 _1 n
<P><FONT color=#ff0000>函数名: settextstyle </FONT>' G- T0 v* W: S+ X5 x5 o6 H  r5 M/ x
功 能: 为图形输出设置当前的文本属性
, ?% c* i; C" `) l用 法: void far settextstyle (int font, int direction, char size); 6 K0 `# Z8 k$ s
程序例: </P>1 }4 j4 _+ m6 `* e% D3 S% [) y- s
<P><FONT color=#0000ff>#include <GRAPHICS.H># W5 d- T' G( |, y, j+ u% ]* q" f( g
#include <STDLIB.H>* N- l- @: r5 A
#include <STDIO.H>9 J) Y. v" H# J5 z  v
#include <CONIO.H></FONT></P>
+ J" A  x, J4 b<P><FONT color=#0000ff>/* the names of the text styles supported */
& j$ l  Q4 A+ xchar *fname[] = { "DEFAULT font",
7 q- m: g- l: V0 ]4 h( g+ \"TRIPLEX font", 5 J0 H, f2 f8 t) \$ u1 V
"SMALL font",
( Y$ u4 ^# M0 S5 Y; n"SANS SERIF font",
7 F3 S7 [/ M+ V. J+ ]9 S"GOTHIC font"
0 K% b: r% G" N6 Q# [}; </FONT></P>
( p1 Q7 o# |9 h4 Z& }1 A' S<P><FONT color=#0000ff>int main(void) 8 b2 \* q( V( J! ~& e" t2 T& {
{
- s- n8 j0 P$ ~2 D* z/* request auto detection */ 7 z$ s' {' k4 t
int gdriver = DETECT, gmode, errorcode; 7 o4 y7 Q, v9 T& }
int style, midx, midy; 5 K1 T/ O" b  @( P- z
int size = 1; </FONT></P>0 a* X, X) v7 \$ Y
<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 k) ^  c& d1 Y! a$ V% g1 S$ ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% G/ Z& Q8 Q3 `1 s<P><FONT color=#0000ff>/* read result of initialization */ ; b+ K9 i; q* @( q# ?, S0 z3 Q6 M
errorcode = graphresult(); $ t0 x/ Y( u. N
if (errorcode != grOk) /* an error occurred */
/ r' {0 x  [8 n& C" Z" s% O" k{ 3 ]" ?  {" x( t; |
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 o6 k' J5 C" l# [
printf("Press any key to halt:"); * V. J5 i. n3 k) a9 I  }0 w
getch(); ! ?$ J* ~2 C. f$ E8 p9 G! y
exit(1); /* terminate with an error code */ ! G) |% j4 h2 Y* f) E# H
} </FONT></P>
7 M0 O! ~% a/ [" N<P><FONT color=#0000ff>midx = getmaxx() / 2; " c, r3 P/ Q5 _& c6 o
midy = getmaxy() / 2; </FONT></P>
, O0 k8 ?" d$ I% t0 l, a<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>! s. m' N) y+ |* U0 \( }5 ?) V" G) m
<P><FONT color=#0000ff>/* loop through the available text styles */ 6 ^. ~: V+ B, c; F
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
) a7 p) }: K  F4 U, @* C{ 0 s9 r' A; ?% X# e' s" C5 F$ V6 E
cleardevice();
* f0 ?2 D2 e* D. L& H/ z" a7 M* bif (style == TRIPLEX_FONT)
' M5 G- h% K" k1 N8 wsize = 4; </FONT></P>) A9 X. M* x* d5 `
<P><FONT color=#0000ff>/* select the text style */ 6 ]& R5 |" M& z1 G6 D
settextstyle(style, HORIZ_DIR, size); </FONT></P>
8 j  o. f% Q4 t. a<P><FONT color=#0000ff>/* output a message */
; Z' X) P7 E- E# @$ ^outtextxy(midx, midy, fname[style]);
, ^7 @5 ?, p1 T( N' j+ a- Agetch(); 4 l6 P, B7 [9 y& o  @
} </FONT></P>' c& D+ s, l2 J1 r* C- z/ R. t9 A( r
<P><FONT color=#0000ff>/* clean up */
& ]- [' @+ x1 w* Z9 v! @4 mclosegraph();
8 i! e( h' f2 s% M% e( X4 d# Rreturn 0; 5 K" \- W: t+ G  r# [( q% y5 t- S
} </FONT>
7 H: [, ^* \  @6 C
: ?) ]: O2 m; [$ o+ b</P>* ?& V! ^. o3 y, Y. b( Y: Y; }
<P><FONT color=#ff0000>函数名: settime </FONT>/ \* j; a# |, O) e% G9 |- K7 o
功 能: 设置系统时间
$ @, t' n4 d3 \: T' _1 t* O2 A, E用 法: void settime(struct time *timep); ' C6 c1 r( @! o" H* v! l
程序例: </P>
8 z4 L& }% t" @/ i6 d<P><FONT color=#0000ff>#include <STDIO.H>4 H8 H0 F5 A) r# B, a( \
#include <DOS.H></FONT></P>/ h  m9 O  B# c  H
<P><FONT color=#0000ff>int main(void)
2 ?3 Q, q% J6 Z' _& e{
; ?& o! b6 \- _4 hstruct time t; </FONT></P>4 s8 o- R, e4 C- H4 s; ^
<P><FONT color=#0000ff>gettime(&amp;t); 0 j( r" F% X4 ?, G) U4 K
printf("The current minute is: %d\n", t.ti_min); : L7 h' ~5 H9 y9 ?/ u, B$ c
printf("The current hour is: %d\n", t.ti_hour);
+ r5 f+ M3 l. {- W0 }printf("The current hundredth of a second is: %d\n", t.ti_hund); # u+ Y4 u2 f& C4 Z8 L+ h( a
printf("The current second is: %d\n", t.ti_sec); </FONT></P>$ L8 c- I& a% i+ X5 W
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
/ M7 y2 A1 n. r/ ~t.ti_min++;
# |+ r2 ?+ B6 Y; h$ Z; T$ psettime(&amp;t); </FONT></P>4 o! I/ F: v0 u
<P><FONT color=#0000ff>return 0; 8 ~4 L& n/ S  f/ b9 W$ W: A
} </FONT>
" \0 p! Q' ?0 Z% s) k2 ?) C9 v$ b" j8 K2 g* l/ n9 }
</P>  p2 K% P1 a+ i  n; f- R
<P><FONT color=#ff0000>函数名: setusercharsize </FONT>/ U' z2 A6 v% Y6 P
功 能: 为矢量字体改变字符宽度和高度
' b9 s) Y3 Q! U! L2 w: M! E) h用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
" e/ }+ ?# T9 @  j/ D  S程序例: </P>
* b* D0 X# L5 U0 e  G% M' e<P><FONT color=#0000ff>#include <GRAPHICS.H>& ?1 r1 X; R$ o( ~/ Y
#include <STDLIB.H>6 n* B* F; Z. a# o; x( g
#include <STDIO.H>
; u9 L4 |4 Y, p3 ]8 g#include <CONIO.H></FONT></P>% f6 |* B$ C8 ?& x7 G5 u9 Y# F, [
<P><FONT color=#0000ff>int main(void) . l- D  h9 w; }- S' \
{ % y+ u* |5 t" T
/* request autodetection */
- Q6 d5 }4 l% R6 ?8 Yint gdriver = DETECT, gmode, errorcode; </FONT></P>& w/ a: A3 f& S. P+ K
<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 I0 |3 h) f) G- b+ t# Oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% h' `& W+ q' t7 g0 s3 B<P><FONT color=#0000ff>/* read result of initialization */ , @1 O. @5 |& G! A& o! U# l: ~+ S
errorcode = graphresult(); 7 Y8 T' T" p+ w+ K; D
if (errorcode != grOk) /* an error occurred */
' `# e# j. ]. V  ?5 e- E' d+ z{ . U; s' l) G' J9 L# N5 I9 Z7 E$ M
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ F0 ?( G5 ~" S* i6 @8 \: _printf("Press any key to halt:");
$ p6 q  S' ]7 [! r+ Jgetch(); , Y& e  k2 j1 n) d# @" p
exit(1); /* terminate with an error code */
( C2 b, W5 J- k' A0 K} </FONT></P>
3 |! \  U# _) j6 H0 Z8 E<P><FONT color=#0000ff>/* select a text style */
9 a# _- ~1 {0 {" G' Msettextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
2 w& [  L/ n8 _<P><FONT color=#0000ff>/* move to the text starting position */ 1 G. G: n$ C$ c
moveto(0, getmaxy() / 2); </FONT></P>8 ?8 y) F$ r% a8 N
<P><FONT color=#0000ff>/* output some normal text */ - n) v6 s/ g; ?
outtext("Norm "); </FONT></P>  }! E: R' s* i5 i$ S$ l, C" M
<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ $ p5 t, a( `/ X- V
setusercharsize(1, 3, 1, 1);
* K- O! |2 u* @3 q- kouttext("Short "); </FONT></P>
; U, v( q0 }5 J5 x5 d! }<P><FONT color=#0000ff>/* make the text 3 times normal width */ ; [9 C+ B& E, R* Y* _" K' r4 a4 ]4 v
setusercharsize(3, 1, 1, 1); - o$ T9 s1 U' d
outtext("Wide"); </FONT></P>/ L3 q7 D, y. c- B6 ?8 G" A- O
<P><FONT color=#0000ff>/* clean up */ % Y$ X4 [# b5 ^7 h
getch();
) ~& F$ B- I4 r2 Y, P& m9 Sclosegraph();
' ]8 p% ~+ I" G( O, ireturn 0;
7 x/ I7 V+ i4 U! L; w  c} </FONT>
# ]- Z& j9 n8 V- ~+ b0 ^; t' e0 l& U</P>3 W9 B& a$ x/ ^  N1 \
<P><FONT color=#ff0000>函数名: setvbuf </FONT>
+ A  w. e) C, p) D功 能: 把缓冲区与流相关 . j+ R# x0 o9 a
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
  T( k- C1 @' Z3 Y1 ?程序例: </P>
* U+ P. T( @' D5 |( V5 Q& t$ }<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
6 A; E4 w% o/ U  f<P><FONT color=#0000ff>int main(void) $ Z1 E* ]/ r  H2 X9 C- o
{ # S# o4 I" e. ]& T! r, @5 j$ g/ u7 X) U
FILE *input, *output; " v- H* \% o; ^; r$ c5 j) Q  \! Q
char bufr[512]; </FONT></P>  K4 E# ]) m! t
<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
* b0 `4 c0 w0 M9 h) W9 k& {output = fopen("file.out", "w"); </FONT></P>' p) }$ l. {. ]8 B
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,
# Q7 a3 L, }) U1 f. |( Qusing our own character buffer */
, ^/ D( h" {: Vif (setvbuf(input, bufr, _IOFBF, 512) != 0)
$ c' t* @" _# X7 Nprintf("failed to set up buffer for input file\n");
  g: {' B1 F) D" p, S" oelse
$ l0 o" d% J" i: R7 N- }printf("buffer set up for input file\n"); </FONT></P>
- \- i/ j) M- v! z) e1 K5 F/ |<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
* u( A/ B/ E0 P5 Ewill be obtained through an indirect call to malloc */
$ S3 U# G8 v; z) W: G- ]! }1 K9 w! bif (setvbuf(output, NULL, _IOLBF, 132) != 0)
5 Y# Y3 O6 F2 _. [8 cprintf("failed to set up buffer for output file\n");
( X3 P7 K- q6 ?else
; C% C! w2 l9 |, @4 }printf("buffer set up for output file\n"); </FONT></P>
: X0 \( p% {, `: E( p<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>4 A9 s( _6 _) s) w" u
<P><FONT color=#0000ff>/* close files */ : A" J: J6 Z$ `) P0 T) v4 K
fclose(input);
: V: `. L# U" \7 r% W+ C# v( nfclose(output);
/ R- z, l! o/ `* [( D, X# Creturn 0;
" r, V/ a( Y( m" @}
- v% k( S9 Q9 P+ N7 b" @</FONT>. g& ]' a: Y! J) k/ |5 ]% h

' ^% C, z' v$ J7 I</P>
2 c& M) Z- E1 J1 o+ Q<P><FONT color=#ff0000>函数名: setvect </FONT>* ?( {- {3 Z; L& d9 b  H
功 能: 设置中断矢量入口
+ f, J- ]0 B9 C' A用 法: void setvect(int intr_num, void interrupt(*isr)()); 4 I. \; p- H2 \' E5 J5 ?
程序例: </P>6 g/ H7 g9 N0 Y
<P><FONT color=#0000ff>/***NOTE:
) n% b: h" A& V3 y2 C6 N7 u1 XThis is an interrupt service routine. You can NOT compile this
0 w, t0 Q: L' W0 y( A% u7 Yprogram with Test Stack Overflow turned on and get an executable
- @* Q7 ]1 A. a3 |8 y$ Wfile which will operate correctly. */ </FONT></P>- v; h, W9 {1 u8 z4 J3 i. z# l! }
<P><FONT color=#0000ff>#include <STDIO.H>( a+ E. p6 s* D
#include <DOS.H>
) I1 v$ e+ K* t( y. _#include <CONIO.H></FONT></P>" T, J5 Z, c0 ]$ s7 Q8 w9 @
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>
) N) ~' k9 K8 e5 `" L% E) v<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
$ N* |0 V4 ]" u$ V* M<P><FONT color=#0000ff>int count=0; </FONT></P>; V; _2 V9 |$ f  H; Q3 P3 D; v
<P><FONT color=#0000ff>void interrupt handler(void)
. O5 Z/ |6 j6 ~{
4 A0 h7 A- A; k# w. M1 Q/* increase the global counter */ * }; [7 \0 x3 H
count++; </FONT></P>; ^+ K9 _9 j3 i: R  c
<P><FONT color=#0000ff>/* call the old routine */
8 e8 e5 O# X4 J+ ]* L2 doldhandler(); + h4 w9 e9 t5 O, X
} </FONT></P>
) }* J* D$ t7 l" Z/ ~; ^6 u+ `# q<P><FONT color=#0000ff>int main(void) : Y+ ~4 l- f, Q' ^5 A' H, Z
{
: `: R* K7 _3 ?+ k/* save the old interrupt vector */
+ m  S& }$ z$ H$ O) r6 r: }0 B- |+ K. [oldhandler = getvect(INTR); </FONT></P>
" [; E' |8 {/ f6 p. ^( D+ S, ?<P><FONT color=#0000ff>/* install the new interrupt handler */
* |; j: E) z# J* C( Q% t9 ?, Jsetvect(INTR, handler); </FONT></P>0 N; J, s, K! [
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 1 n  u) D2 T0 Z  H5 S; f
while (count &lt; 20) * Y) j& }" {6 P3 K
printf("count is %d\n",count); </FONT></P>2 Y& a7 r& d- n" ~* [- i0 J+ N
<P><FONT color=#0000ff>/* reset the old interrupt handler */ ; M7 o+ d# e4 e" b( c
setvect(INTR, oldhandler); </FONT></P>
- u; m4 i# |' E; j1 ], ~<P><FONT color=#0000ff>return 0; 7 |% f( u, v0 w
} $ C( n4 @. L$ S) M+ o9 l# P$ j
</FONT>% w% q+ e% [  b  C' l; Z9 L
</P>: Y: k% ]% \" q$ o. h. k  F
<P><FONT color=#ff0000>函数名: setverify </FONT>  R" d) N& @; @, }: ]% r& b
功 能: 设置验证状态 ( D+ j  t- b) A8 f
用 法: void setverify(int value); ; ^+ H/ ?& M* G: q
程序例: </P>4 C' H3 m) z) O2 j' p
<P><FONT color=#0000ff>#include <STDIO.H>) F+ r9 s# V0 B1 }
#include <CONIO.H>
' m* \3 G4 z, j#include <DOS.H></FONT></P>' J4 n5 ?  K3 Y
<P><FONT color=#0000ff>int main(void)
# w* z5 Q- Z, U# W( f{
% P1 U% [  G0 |int verify_flag; </FONT></P>
0 ?# u, X: F# ^1 d% {<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
$ [) W' l* o4 g- F5 {! tprintf("Enter 1 to set verify flag on\n"); </FONT></P>
) M% M2 J3 j7 {! M, a<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>6 @$ a/ y$ {5 G# m* v! t2 B% t) l
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>: d% f. F. D! z$ x- @
<P><FONT color=#0000ff>if (getverify())
, |" W; E) a5 kprintf("DOS verify flag is on\n"); # Q) H* Z# S0 ~9 d+ o) e
else / h: n- \/ l: U- [* P. }# H8 m# N
printf("DOS verify flag is off\n"); </FONT></P>
- Q- g& e0 d3 q1 v<P><FONT color=#0000ff>return 0;
9 q- K6 }0 n: Z. d} # h. s, \7 y+ [* E
<FONT color=#ff0000>/ ?. A) a- M% U
</FONT></FONT></P>
# p1 \+ C. j- L5 R  {2 h! H<P><FONT color=#ff0000>函数名: setviewport </FONT>
: A# D  ?" g% z7 h! T( L0 i+ }  A功 能: 为图形输出设置当前视口
, s* g& u" ~9 }5 Z# ~+ b用 法: void far setviewport(int left, int top, int right,
4 s# {) \( Q1 ]int bottom, int clipflag);
1 ]/ N# Y8 m' F3 p0 W) {, P程序例: </P>
: P, t6 b8 p$ |& D9 d  T<P><FONT color=#0000ff>#include <GRAPHICS.H>
8 `8 ?7 e3 f4 y& u' S' C7 W#include <STDLIB.H>
3 V  Y- v8 X5 N- X2 R* i9 i#include <STDIO.H>
- v( j; H& F. D; m0 \#include <CONIO.H></FONT></P>5 p0 n) g% f+ D9 ~3 T
<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
+ x4 Y4 `/ K9 V# C) `<P><FONT color=#0000ff>int main(void) $ T4 t$ G; x1 X6 ~
{
. k$ k1 L! d/ b- w5 t) I/* request auto detection */ + R1 G+ @- O  Q8 t& j
int gdriver = DETECT, gmode, errorcode; </FONT></P>
4 Q) }- c, P- ?2 Q* K<P><FONT color=#0000ff>/* initialize graphics and local variables */ % N, l% |% _+ t8 n9 Q/ n  Z
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  F9 |) s2 T& p& Q! P3 n, J) P4 M$ o
<P><FONT color=#0000ff>/* read result of initialization */
5 W. ~0 b& w2 q3 Y6 e4 serrorcode = graphresult(); : s" R9 ]" t& t2 k, V/ t
if (errorcode != grOk) /* an error occurred */ ( a4 |! F( n; E0 u" `
{ ( y; ?0 [* C* A" v! F) U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); $ g4 I5 E6 v; S8 M: s
printf("Press any key to halt:"); 2 U# d5 f) i8 Y' e
getch(); & h6 V4 X. W- M4 ~
exit(1); /* terminate with an error code */ " Q* {3 t9 `# g1 r
} </FONT></P>; k- g6 z  F, q6 f/ i; ~$ _: F1 |! E
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P># J1 p( X/ R# r/ w, @3 m5 q
<P><FONT color=#0000ff>/* message in default full-screen viewport */
& Z# U! z0 m/ D+ L; y3 v! g7 |4 Gouttextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>1 B6 w+ v4 P: X9 z
<P><FONT color=#0000ff>/* create a smaller viewport */ ' L# ?8 w* L5 a# l) P8 B
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
7 o8 \* n# V; }, [, m<P><FONT color=#0000ff>/* display some text */ 7 D/ k: d3 Z$ U8 N3 p
outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>7 E0 W8 ?% _. E3 A6 j& @! g1 Y
<P><FONT color=#0000ff>/* clean up */
, l# s, G: X6 ]) H: G0 egetch();
. \# V0 o; e6 {' }; Mclosegraph();
; r9 p, X  `# k2 c3 a) N5 I% K1 yreturn 0; % y1 t& k- r9 e
} 3 C( Q$ ~! k; a, c2 M' b9 s. E
</FONT>
- Z- s, h! l! L( Q5 k6 S/ q  c</P>
! u0 D% A* n4 ?' O/ E! J<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
, V8 Q, Q. c4 n4 p4 u+ C- u功 能: 设置可见图形页号 % a. i# u* `( e3 j: U( e5 X5 r  x
用 法: void far setvisualpage(int pagenum);
/ [) w9 u; G% `程序例: </P>
9 H8 B. c3 I3 t, F7 l<P><FONT color=#0000ff>#include <GRAPHICS.H>$ I  p8 k; m! H8 {. s$ I# M1 U7 J
#include <STDLIB.H>
5 h2 G* e* V  g#include <STDIO.H>
$ C9 Q, {: b: D#include <CONIO.H></FONT></P>& M0 g, t- f& G. E' f* D  @8 z
<P><FONT color=#0000ff>int main(void) $ y3 H$ @* G; P
{ 8 m2 u' G. ~( O9 V! X
/* select a driver and mode that supports */ : J1 ]% k: Z  J* k* W
/* multiple pages. */ # S5 _7 Y/ H+ J- ^9 w6 D/ s
int gdriver = EGA, gmode = EGAHI, errorcode;
% V! `, Y/ S2 ~" wint x, y, ht; </FONT></P>
7 g& \3 ~8 B. X& P! t<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 O9 q6 o- g) ^. ?$ [4 c0 q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ j$ O4 ]" F0 g$ ^( F) U" d
<P><FONT color=#0000ff>/* read result of initialization */
) O7 p0 C8 `4 @( x/ F1 G" z; R9 xerrorcode = graphresult(); 4 l4 I0 B; @  T7 i! J* Z' p8 }
if (errorcode != grOk) /* an error occurred */ 1 J) g9 y' J0 H! L
{
- b/ L+ K1 C& a+ C# W" Zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' h8 X2 w! _- g+ j3 O
printf("Press any key to halt:"); # j  x7 m6 w+ ?2 ^
getch();
, S) j% u% Z8 s6 H+ L; |1 Sexit(1); /* terminate with an error code */
% w- B6 ]3 F$ d} </FONT></P>* W4 l" V3 A. t+ i+ p4 _
<P><FONT color=#0000ff>x = getmaxx() / 2;
! `$ M/ n5 R1 u2 I" i: uy = getmaxy() / 2;
& P& ?* M* O2 R; g' V& kht = textheight("W"); </FONT></P>
1 c+ Q* t% M, q0 h- n<P><FONT color=#0000ff>/* select the off screen page for drawing */ , A" A; ]4 A+ i- [
setactivepage(1); </FONT></P>
; O+ b' W; Y3 {<P><FONT color=#0000ff>/* draw a line on page #1 */
1 {! G4 I1 j: Vline(0, 0, getmaxx(), getmaxy()); </FONT></P>3 {: q, \7 _5 u, ~0 W1 v: k# ~
<P><FONT color=#0000ff>/* output a message on page #1 */
1 t( Q6 L9 x* W# y/ hsettextjustify(CENTER_TEXT, CENTER_TEXT); * y+ U9 t0 P' u
outtextxy(x, y, "This is page #1:"); + f0 j  i" R2 S) I, u, B
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
" W& v# x6 n* m! o<P><FONT color=#0000ff>/* select drawing to page #0 */
  E+ B' \: [- {9 L. Gsetactivepage(0); </FONT></P>! v3 S) |2 X; ~% |8 O
<P><FONT color=#0000ff>/* output a message on page #0 */ ' n( G0 z6 }" }& z8 Z8 T8 B; U
outtextxy(x, y, "This is page #0.");
, y# x" n5 l+ X6 M' v# Youttextxy(x, y+ht, "Press any key to view page #1:"); ( n. m! C7 z' _9 F4 @
getch(); </FONT></P>, n  F9 ?+ c7 V5 V' g) T
<P><FONT color=#0000ff>/* select page #1 as the visible page */
& g  j9 I' y4 s/ gsetvisualpage(1); </FONT></P>+ P$ e, P" h0 q: w' C
<P><FONT color=#0000ff>/* clean up */
6 n1 e/ w/ X% z' Z6 a6 Xgetch(); 6 u% M( q+ y+ g# _' X
closegraph(); 2 O+ Q! ~) x+ X4 u/ {$ {; t3 r
return 0;
# B- e6 _8 ]5 p: ^1 t# C. c} </FONT>0 J! X5 I0 N6 M- H4 U: h' V

& u! ?9 p& J* a3 Y6 O</P>
! Q" M6 p1 t- U& C3 _<P><FONT color=#ff0000>函数名: setwritemode </FONT>
4 P# s. t9 `" S7 \! S功 能: 设置图形方式下画线的输出模式 # @# \' f4 ]+ Q- N2 M
用 法: void far setwritemode(int mode);
# f6 v6 F2 q1 l, \程序例: </P>
# I' O0 Z! |4 {+ P<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 k' k' M" H0 m0 H) t4 x4 B#include <STDLIB.H>% ^' |# e5 v% f+ ]
#include <STDIO.H>; s. m! D3 M1 `% r, o
#include <CONIO.H></FONT></P>
3 I1 ?7 [0 ~- M4 _<P><FONT color=#0000ff>int main() * G  t' P, J1 M9 m5 P" s
{
  i: [$ W1 f$ z% e5 Y, \. m/* request auto detection */
* }' R! x% b+ S4 p1 U5 h/ P- Mint gdriver = DETECT, gmode, errorcode;
; _- ?6 k6 y( R% S/ E( i: e( W( qint xmax, ymax; </FONT></P>
. U5 {' Y% V: Z! a  ^0 i; i<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( `( P. ^( d6 N4 V/ |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 Y  |1 o- ^4 P3 R" L% G<P><FONT color=#0000ff>/* read result of initialization */
2 ?9 n- ~' }) P! }* `2 c8 @* }errorcode = graphresult(); 5 D' n. w0 o3 g0 h
if (errorcode != grOk) /* an error occurred */
, l0 H* ?1 \, X! K+ h. v4 f% w- C{ : E6 x) Q2 @% E% s) r. ]
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 S# T0 I3 h. M- K0 M: Z7 N
printf("Press any key to halt:");
! ?9 A$ \, W" W% Z" K" o6 Y/ t7 A, Ygetch();
4 o& R6 Z- ^( m0 i* w0 V% Bexit(1); /* terminate with an error code */ ' m! b0 [; u* x9 e
} </FONT></P>
- w8 {$ j% G7 L5 L' e1 V  p<P><FONT color=#0000ff>xmax = getmaxx();
- f2 z. Q) V7 j$ O" |ymax = getmaxy(); </FONT></P>
0 W$ o7 r; \5 C" r) r' x<P><FONT color=#0000ff>/* select XOR drawing mode */
1 j3 c9 r# f  ?3 K2 wsetwritemode(XOR_PUT); </FONT></P>
: E& A* Y( O4 `<P><FONT color=#0000ff>/* draw a line */
7 B) g% @3 y! @: o. K4 Q& Rline(0, 0, xmax, ymax); & H# X' E$ A# I7 y
getch(); </FONT></P>
7 U- }" E5 }& r2 }& _6 w$ F1 y  B<P><FONT color=#0000ff>/* erase the line by drawing over it */ # p& }1 K8 ]' H% r4 R7 u
line(0, 0, xmax, ymax); : B* e+ U9 x* h' ?; B0 J3 i+ G( P
getch(); </FONT></P>. J" v% O# \; f7 \& Y; r3 J; N
<P><FONT color=#0000ff>/* select overwrite drawing mode */ 0 N  v" M9 P# G' s. B
setwritemode(COPY_PUT); </FONT></P>
" C: J( U* h% f: x<P><FONT color=#0000ff>/* draw a line */
) O3 P- k0 K* \) l  [9 [line(0, 0, xmax, ymax); </FONT></P>
- J6 }2 r8 w" p+ \7 r1 d7 u<P><FONT color=#0000ff>/* clean up */
  g& D  s  p; G+ ^/ `0 Dgetch();
* o  f- q. Y$ u: i# @closegraph(); 2 _6 n) C- |; X
return 0;
0 R9 a/ M5 W4 v( K' ?9 J}
1 }, I6 ^& b% P# N/ [</FONT>
' S' W" ]" c. d, X* ^0 j</P>
) K8 @4 M. }0 _3 J2 g<P><FONT color=#ff0000>函数名: signal</FONT>
0 r- j/ C/ ]8 n4 Z功 能: 设置某一信号的对应动作 9 ?# D/ ~$ `# q  }1 b/ e" b. p
用 法: int signal(int sig, sigfun fname);
0 k, N  }- ^4 I' }+ G程序例: </P>2 V9 ]& ?' X. w- o& K
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE,
0 u1 p5 r7 _( I: }catches an integer overflow condition, makes an adjustment + s+ k# Z+ S2 o" S
to AX register, and returns. This example program MAY cause 7 a$ h  t: }" h& o! X. @( L
your computer to crash, and will produce runtime errors 9 A+ j  W( j+ k1 z7 N& `
depending on which memory model is used. ) \0 W7 E$ {4 U" |
*/ </FONT></P>
3 H6 o1 i5 Y4 l+ s<P><FONT color=#0000ff>#pragma inline / M/ p( i) B; E$ i: {
#include <STDIO.H>
+ L% E8 y5 s- C3 x# [- F5 J#include <SIGNAL.H></FONT></P>
6 L3 C( B  V# V$ [<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist) % [% T1 A: R2 p3 P5 u; ]2 Y& B
{
' s- b1 |( |& i) r: k6 cprintf("Caught it!\n"); 6 g& J; v$ K- {) D5 ]& F/ s& V
*(reglist + 8) = 3; /* make return AX = 3 */
$ U4 b+ H1 s7 }9 @! J$ A& U' q} </FONT></P>
. Z. J! O4 Q* P! N# @- W+ Q<P><FONT color=#0000ff>int main(void)
* z" Y/ t4 N. g7 w! ~% ^{
. _2 q, e! v" e2 P4 z+ ^( V6 esignal(SIGFPE, Catcher); , G2 E( `0 p: O# ^) V
asm mov ax,07FFFH /* AX = 32767 */
1 `7 P" d: w, f; X6 B- Nasm inc ax /* cause overflow */
8 w1 F- }  t9 \asm into /* activate handler */ </FONT></P>
& E1 h: B& W) M- h4 h<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, ) G- T8 y! ?' Z! q% r6 ]! n
there would have been another exception when the next 'into' ( I/ M/ v; H2 J: g# d
was executed after the 'dec' instruction. */
3 j4 l; a9 @" A9 C, P+ `) y2 o& rasm dec ax /* no overflow now */ + S5 q8 Z5 t; l  G# T
asm into /* doesn't activate */
7 Z4 ~. r( Y/ c# N$ a' }return 0;
& z$ J* C2 A3 [+ l! {1 P6 f4 z# S} : {) O5 I! O( G1 Z

( m* x3 l1 L) s& w% [" |6 S
+ ~5 J; g! X2 P! ]</FONT></P>
9 b0 Q/ C5 h9 a<P><FONT color=#ff0000>函数名: sin </FONT>
7 {/ S# Y' R  c: P- M- H功 能: 正弦函数
& ~* _% a: S* }9 I( \用 法: double sin(double x);
* E. I4 ]9 J' u+ Q/ K程序例: </P>$ W8 I* [" j  B( ~
<P><FONT color=#0000ff>#include <STDIO.H># C6 k; d0 P* q
#include <MATH.H></FONT></P>
9 _: `: B, \8 l! f<P><FONT color=#0000ff>int main(void)
8 d1 I) ?" O5 g{ * q3 l% t' I( X
double result, x = 0.5; </FONT></P>! g6 o7 [; G2 f+ D5 n
<P><FONT color=#0000ff>result = sin(x);
4 L5 o9 f' U% r4 S/ z* zprintf("The sin() of %lf is %lf\n", x, result);
( e( B8 X$ z% g. \2 [2 H; breturn 0;
* c, b' R, r: V  F- a} + f) H) x$ ^3 ^2 f  F
! L" _+ f) ?( k5 V, G& ^0 }
</FONT></P>+ r, s, J$ H2 l, R% p& U9 U6 E2 B2 U
<P><FONT color=#ff0000>函数名: sinh </FONT>9 M, n4 c7 b5 E( o( w6 l
功 能: 双曲正弦函数
% H4 i5 Y& |2 e( {; m( S. V6 r+ T用 法: double sinh(double x); ) X, {$ |8 o) ?9 c5 D6 @7 d( }6 y
程序例: </P>7 X' B2 x: K! D# B; a3 a; y, F
<P><FONT color=#0000ff>#include <STDIO.H>! J  P( Y: T0 S9 }& E
#include <MATH.H></FONT></P>
" Y* R5 q( T7 Q  s+ q9 ?" f0 p<P><FONT color=#0000ff>int main(void)
" e2 E* k2 J0 T% g{ & Z8 [) X9 {$ Y* J
double result, x = 0.5; </FONT></P>
5 E& i9 l4 q) U# M% y- Z2 `<P><FONT color=#0000ff>result = sinh(x); 4 X- z' }$ d2 p2 l7 Z8 [
printf("The hyperbolic sin() of %lf is %lf\n", x, result); 7 a/ K; c5 o! ^" M
return 0; " U7 F# B' Q, Q8 }9 W- t* k" {5 T, I
}
( ?; k! W% J+ ~, {. ?
' s+ J" Y* X: V! n  W  [' I+ Z# w. z) m
</FONT></P>1 n& k/ p* r3 A' X% h; X
<P><FONT color=#ff0000>函数名: sleep </FONT>
+ C  b" `  L. L( u功 能: 执行挂起一段时间
4 w/ P" H4 `# w7 \用 法: unsigned sleep(unsigned seconds);
4 p' d4 C* n) y" F0 R程序例: </P>2 @9 Y/ Z9 b( Y$ `
<P><FONT color=#0000ff>#include <DOS.H>
- n1 u3 w5 \7 b9 J9 h#include <STDIO.H></FONT></P>
0 w& k) x7 q% C<P><FONT color=#0000ff>int main(void)
1 X& v0 a, {" f  Y) t{
+ k* s* h4 {# V/ |* |) mint i; </FONT></P>& `+ }- {! P, G. M! L! _0 H
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++) ; G6 ?1 _( t0 e  a0 \: U6 Z3 U
{ / e. j5 t* E  ]1 g( a- [8 Q; m
printf("Sleeping for %d seconds\n", i); - A% s) z" _' a% M
sleep(i);
& C5 u" C6 o& [}
2 ]6 _; h  v0 M' D; ]( w/ @return 0;
* K) l# O( i0 O+ C9 g} 0 |7 B0 k7 O3 A4 S

) T; N4 _; ?+ y$ R" R</FONT>$ s; o9 E8 ^' R: _/ u+ @
</P>
7 ]9 `2 E  l4 V$ L: n<P><FONT color=#ff0000>函数名: sopen </FONT>
( ?. f# a: I# w* H功 能: 打开一共享文件 % `* @) u6 d- c" D5 \+ b5 t
用 法: int sopen(char *pathname, int access, int shflag, int permiss); - K* m7 W9 C. h! c, C3 s: @. W
程序例: </P>
; P* l% b) i  T% {1 \) o1 o<P><FONT color=#0000ff>#include <IO.H>
, N+ K0 w! i1 ~3 |  ~, u- H#include <FCNTL.H>3 E: u, Y1 D# h
#include <SYS\STAT.H>
# a# }" A: N; Z2 r% l#include <PROCESS.H>  ?/ q' I' m- b
#include <SHARE.H>6 u& o" |, r# \9 t5 L2 w  v3 p
#include <STDIO.H></FONT></P>
0 `5 Z3 }3 M, q; f8 G% x<P><FONT color=#0000ff>int main(void)
9 r; y- g% O/ k{
0 S" y  ]$ u! p5 h" cint handle;
8 y; h" O4 P8 U+ O% A( Xint status; </FONT></P>
/ K: w7 g+ _' w<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>
8 z7 @( ]: H# d6 ~<P><FONT color=#0000ff>if (!handle) + p2 y4 a! l( V4 A! J9 g+ u
{
1 c4 s+ y( C# z1 tprintf("sopen failed\n"); + C0 t$ o0 }. [( K
exit(1); 0 y# Y5 d9 R- v+ h9 }* H
} </FONT></P>2 u0 h- j& S- \7 Q8 X* F
<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); 5 F7 t* U$ `5 [$ r# A
if (status == 0)
( o0 o0 g6 |4 h3 sprintf("read/write access allowed\n"); " x  K: y$ y4 u! \/ v( k
else
' F& S! m; R9 g5 Aprintf("read/write access not allowed\n"); </FONT></P>
6 \) G0 s* g' p% v; I<P><FONT color=#0000ff>close(handle);
# J/ @. [/ R; y" F( Y1 h0 M# a, greturn 0; $ J) n+ o6 T1 D. D6 p4 Z/ @
}
* s5 }. H4 U7 C9 b
! D% Q0 I/ j$ S! |4 S2 \  l</FONT>: f( }" Y, Q8 J0 z* m7 `
</P>
' ~+ @$ [5 R7 n4 u1 r, x<P><FONT color=#ff0000>函数名: sound </FONT>
1 u6 x* Y( q; T, A6 J! Z6 b功 能: 以指定频率打开PC扬声器
' V3 r2 d: b; Y/ s& ^3 r6 o; c用 法: void sound(unsigned frequency);
8 A1 i! [1 O0 d" Q! C程序例: </P>
1 `0 n6 \) E# X$ J) v) n' U9 k<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds.
* L2 s  l: c6 v% A2 s9 l3 s) \  FYour PC may not be able to emit a 7-Hz tone. */ - }8 s( L; v" f2 p1 L. E% L
#include <DOS.H></FONT></P>8 ~6 D  W4 `2 n+ |
<P><FONT color=#0000ff>int main(void)
0 j- V$ G; }: A6 E- {{
/ B7 P$ A. t9 vsound(7);
( S/ N  d% ?: g& o( c5 mdelay(10000); 0 ~  e" H7 L7 l
nosound();
! e4 J" M# a0 N* K1 J% E8 yreturn 0;
- O2 v' X4 F( s, X9 r} </FONT>
7 h8 I3 d  B3 F2 L6 X8 K  {5 v5 s+ `
6 g6 f% [, F5 V" S' i
</P>/ w6 Y$ Q- i" s5 I* ~. U
<P><FONT color=#ff0000>函数名: spawnl </FONT>& b# o# k4 W$ B. l6 d: _
功 能: 创建并运行子程序 . E! ^( }+ p- `5 `1 t" l% P" G
用 法: int spawnl(int mode, char *pathname, char *arg0, & T* Z& B: U( _( |9 Z
arg1, ... argn, NULL);
* \& v9 J8 w) h+ w/ V! V程序例: </P>* Y1 \$ Q* I5 Z$ A$ ~/ O+ ~
<P><FONT color=#0000ff>#include <PROCESS.H>
  T) {+ }+ t. R" [; L" T#include <STDIO.H>: O! k( M$ j- u% u5 H" C. m1 [
#include <CONIO.H></FONT></P>
' U* N  @% ^' v8 Z) S<P><FONT color=#0000ff>int main(void) $ }% A+ W  E" ]- ]" c" b% @
{ ; n' |5 y8 E3 T
int result; </FONT></P>, Z* T9 m9 c' s$ L
<P><FONT color=#0000ff>clrscr(); . o) O4 R6 S- h; h
result = spawnl(P_WAIT, "tcc.exe", NULL); 3 r3 c, G. h8 O5 r$ d6 \( a
if (result == -1)
' Z: ]$ r( b' c; i{
/ i, e) u/ }% O0 t* h4 ^perror("Error from spawnl");
: b/ Y9 D( P- Y( Sexit(1);
6 Y9 H3 T0 Z* q3 |# r8 z( k2 g! G} ( @' G6 ?; ], J5 e. g6 v7 u
return 0;
$ x3 h/ x, t* P: C}
& P0 X9 u% t1 I7 q% ]</FONT>$ ^6 y8 O0 W. U' I+ f8 U4 D4 W
</P>
0 q( X4 m  J' b0 U$ v) |$ o<P><FONT color=#ff0000>函数名: spawnle </FONT>
3 y  ?0 l+ j- [: v9 K功 能: 创建并运行子程序
. e6 o$ u# z+ I+ z. ~" p用 法: int spawnle(int mode, char *pathname, char *arg0,
& X5 m, l  n4 H; H4 q5 qarg1,..., argn, NULL);
, U4 |. W1 C, ^7 ^2 L0 s程序例: </P>2 a/ w& A* S5 q, Q* P% S* v; Z4 `: O4 a
<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>( E1 |$ h- O( T. |2 z! \
<P><FONT color=#0000ff>#include <PROCESS.H>
3 C' Z. W# q" G4 E# {/ T#include <STDIO.H>
0 J8 S4 |( O$ X" V#include <CONIO.H></FONT></P>4 b0 o$ p2 Y6 t  Y$ s
<P><FONT color=#0000ff>int main(void)
' h% ^0 \& z" y7 x4 v9 k* N: F6 b% P{ 3 H2 U- p' H% M6 ?
int result; </FONT></P>3 f; A# k. P1 y& ?3 F2 Y
<P><FONT color=#0000ff>clrscr(); & Y% x6 O! t- ~  V$ L8 |( _# e; L6 m5 \
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL); ' }* w/ r8 s: i$ r5 X' g' ]. d( a
if (result == -1)
" c! f. G2 z. z2 M9 U+ f* q# P{
! q+ ~5 M  b8 ^* {- b! i" d: a' zperror("Error from spawnle");
/ \& M; A; q6 r, F: q# E/ L$ j8 d4 f0 Uexit(1);
5 C2 P1 M8 p6 O}
* u/ B5 _: Y) W+ c' a% Mreturn 0; : _# F+ s# L0 G" c  q8 b
}
, Y; g. y' i" p" H, x
+ t( f+ g; O. A
7 z+ |7 i8 A* k" D4 L; g/ x</FONT></P>
; e2 S3 q+ ?2 m* a<P><FONT color=#ff0000>函数名: sprintf </FONT>, v0 S5 o" |6 d1 s# `* i$ c
功 能: 送格式化输出到字符串中
+ {/ T) r4 v; ~1 @2 }7 d( L9 R用 法: int sprintf(char *string, char *farmat [,argument,...]);
4 O, j' {7 M, p- F( M1 H程序例: </P>
" i. R! ~7 {( q8 O<P><FONT color=#0000ff>#include <STDIO.H>
1 [0 J! P& X4 \( e#include <MATH.H></FONT></P>
$ }- y; H& y: E0 e1 L: k+ a<P><FONT color=#0000ff>int main(void) 6 ]6 ]# U$ _( V3 j7 ~' l
{ & E& B1 e4 q3 n, u" {' G# f7 |! k8 k
char buffer[80]; </FONT></P>
% T  S2 d% K+ I5 [' V+ ^3 x; m<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); ! ]4 e! Y" \# Z, M8 c
puts(buffer);
) z/ W& p2 P2 K" Hreturn 0; 9 `7 L: q. V: {6 K
} ' o9 X" k, U. P9 [% r5 X) M
</FONT>
# ~- J2 Y4 c( O- `8 g0 T</P>$ H" q8 G( u0 k" k% i- w7 m
<P><FONT color=#ff0000>函数名: sqrt </FONT>
; i, r. h9 k$ s/ q& ?功 能: 计算平方根 + x3 U* [6 S+ j9 O+ p7 H5 l* O
用 法: double sqrt(double x);
$ B5 P) A5 o- E  C& U4 M程序例: </P>2 f, S+ _: }3 c3 {6 a' I
<P><FONT color=#0000ff>#include <MATH.H>
/ R/ O. p6 J4 W$ v#include <STDIO.H></FONT></P>
8 S7 I- T9 w9 D$ H! H<P><FONT color=#0000ff>int main(void) 4 E& J5 l6 D# n
{ & D/ \/ [, V2 C2 c
double x = 4.0, result; </FONT></P>3 Q0 C& _/ E1 M  q. j
<P><FONT color=#0000ff>result = sqrt(x); % J* V/ b8 a7 |' u
printf("The square root of %lf is %lf\n", x, result); ; F4 f7 f( S, T& @- X0 R
return 0;
7 g% I2 `$ }# p3 y4 D: |) C! @7 b} 8 G: }# Q7 M/ Q) M$ x0 @- ?
</FONT></P>
1 X2 c% D  O, C<P><FONT color=#ff0000>函数名: srand </FONT>
6 Q  B, u3 m: O+ f) G* _: }功 能: 初始化随机数发生器
1 B2 N3 W7 z6 e6 d) S用 法: void srand(unsigned seed);
5 r" b6 O: q6 l程序例: </P>$ w) t/ D( W0 t+ s+ j
<P><FONT color=#0000ff>#include <STDLIB.H>8 O6 e6 ^0 f& A1 ^  `1 ^
#include <STDIO.H>6 @6 {% w3 J0 |, }% B
#include <TIME.H></FONT></P>
  q! T9 S# w5 f<P><FONT color=#0000ff>int main(void) ( ~( G; o6 V" q7 [6 o( O2 \  \
{ : q  ~( P( `( J9 ?' e
int i; " g7 E$ c) @" y+ l/ h; G3 }
time_t t; </FONT></P>6 L5 I. U' n" S3 ~" W0 x6 M
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t)); 6 \4 F1 O! r) \' N+ x
printf("Ten random numbers from 0 to 99\n\n");
3 u; D7 K+ a; T0 u1 l) Sfor(i=0; i&lt;10; i++) 3 Q' e* x  o$ m# p0 t4 j
printf("%d\n", rand() % 100); - H; k! V0 G# `+ i" Z
return 0;
8 r3 |3 U" G2 H3 ], g: E& `}
& Q$ ]. h$ X7 D# o</FONT>4 U6 F# N2 k- _1 n- p6 e
</P>$ ~; e4 T/ @# }, c6 l) Z
<P><FONT color=#ff0000>函数名: sscanf </FONT>
: B; ^! I. P6 U  Y功 能: 执行从字符串中的格式化输入 0 B; U! H1 y) A; ?
用 法: int sscanf(char *string, char *format[,argument,...]);
) ~0 T% A% u2 q7 c5 ?; s9 e* J程序例: </P>5 x8 u3 z2 P! G% w& H- a2 ]  e8 u
<P><FONT color=#0000ff>#include <STDIO.H>
& f8 x( f6 m5 G8 w#include <CONIO.H></FONT></P>' {2 N, S  m' m) Y, k( L- w5 K7 M
<P><FONT color=#0000ff>int main(void)
3 W5 x" o* l! G* ^{
3 w4 g& [0 {5 u' d& \char label[20];
: Y  f9 \/ ?' s: T7 Q/ i( Kchar name[20]; * o+ {; L$ Y1 H
int entries = 0;
* i" q& E% J! v% q) \9 ?int loop, age; # C( M9 u2 t; ?) L/ j3 S) w, f1 Y
double salary; </FONT></P>5 r: O% R: n) c% `( ~" X+ H% g1 o- Y7 n$ q
<P><FONT color=#0000ff>struct Entry_struct + v1 U% x5 t! [( l2 X. s
{
# _7 I2 M4 U2 ?; k2 O) a7 X- xchar name[20];
, V6 \8 [# |4 O2 O) t! T1 d2 W$ Fint age;
- F' [0 S" |) T( R) j6 x8 B) jfloat salary;
! C; v/ g# _  Q5 c6 L} entry[20]; </FONT></P>
  l% k: F' D! x<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ , @+ J9 v  C0 E. |& Y
printf("\n\nPlease enter a label for the chart: "); ( k$ I$ q0 U% \
scanf("%20s", label); 3 B8 N- [( n2 H8 ^1 B
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>. A  H9 a0 Z, ~; U6 E8 X  D
<P><FONT color=#0000ff>/* Input number of entries as an integer */
  j: G3 d/ K: `* O. Gprintf("How many entries will there be? (less than 20) ");
/ }( v; g; ^; u6 \: P4 o6 T" @scanf("%d", &amp;entries);   Z9 r2 A! E. O: R8 e% P. z' G
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>* C8 D/ Q& K4 [  G- {) K
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
7 s& x) f' G3 cfor (loop=0;loop<ENTRIES;++LOOP)
, H2 c7 v) t/ w& e/ B: [: Y. L {
7 Y; N; _  n  N- @printf("Entry %d\n", loop); ' _' J7 C# P0 L! M- @
printf(" Name : "); 7 l  g7 [8 m2 s. a
scanf("%[A-Za-z]", entry[loop].name); & E* Q2 U2 T  {4 ^' l
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
. W+ z% q6 I: E0 n<P><FONT color=#0000ff>/* input an age as an integer */ 9 [  Z: H: V* T/ P2 `4 [$ D: [
printf(" Age : ");
! O: W3 J5 M  c- n2 bscanf("%d", &amp;entry[loop].age);
1 V! J3 n7 Q; i/ P. Q" g+ W8 Y$ Zfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>3 t$ R/ P2 h) d% [* I0 }# r
<P><FONT color=#0000ff>/* input a salary as a float */
, R0 T2 m" _$ {printf(" Salary : ");
0 z9 h- {: j  u8 |4 I! Qscanf("%f", &amp;entry[loop].salary);
# P# W, I- f' [fflush(stdin); /* flush the input stream in case of bad input */
) [9 n9 M, _5 Z: [- ]4 f} </FONT></P>
$ T' K, _4 H5 ]/ q. q; {<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ " R  o9 F( h6 E/ g3 l
printf("\nPlease enter your name, age and salary\n"); ! z. S$ D- E1 h# N
scanf("%20s %d %lf", name, &amp;age, &amp;salary); " @" x' E+ G3 O7 B4 [3 }
</FONT></P>% l1 P  \% {) R/ p4 y
<P><FONT color=#0000ff>/* Print out the data that was input */ 7 S" \- a/ O5 H1 ^% _
printf("\n\nTable %s\n",label);
" D- Y- P% [  B9 F  G0 Yprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
: Q% T; E, o* g* I# z! sprintf("-----------------------------------------------------\n");
7 L% T  _% N; r- _' pfor (loop=0;loop<ENTRIES;++LOOP)
# ^" g- A+ u1 J printf("%4d | %-20s | %5d | %15.2lf\n",
& I, [3 q2 L$ @% iloop + 1,
0 ^4 [0 x" a7 V: L3 T: x, @entry[loop].name,
* ]9 u9 Y7 \' s, k; B* K" Qentry[loop].age,
/ l: s: _+ j* N3 E; M' b% C* b) Mentry[loop].salary); + a6 _; x3 p. g, K/ D% n+ A
printf("-----------------------------------------------------\n"); - S6 v5 h7 @* T; t6 Q  m  g/ B, B
return 0; $ w/ d' j  k* L7 r, r
}
6 T8 ]$ X9 A! M$ J- H7 H) T9 F: t; [1 W9 {$ D
</FONT></P>
2 k0 ?  t3 S+ _6 N, o<P><FONT color=#ff0000>函数名: stat </FONT>: V7 Y' ], T0 m- {9 a
功 能: 读取打开文件信息
- L" A# K  ]" }4 v/ j& V" G用 法: int stat(char *pathname, struct stat *buff); % Q' T2 ]* O7 ?" M* P' W4 o2 Z& N% x
程序例: </P>
7 ]1 R, M0 i/ V; z9 U1 b8 G<P><FONT color=#0000ff>#include <SYS\STAT.H>
1 k9 G0 M2 H! m#include <STDIO.H>
4 s/ L' L/ N( S* d1 Z#include <TIME.H></FONT></P>( q4 E5 _/ i: y0 f: A  [! S+ A
<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>7 o7 _# `3 n" ?, @/ {  i- W1 w
<P><FONT color=#0000ff>int main(void)
. B7 H2 D% P" I{
. T; ^, G% O6 m7 Estruct stat statbuf; . z7 @  t7 u8 g4 `% \- i
FILE *stream; </FONT></P>/ ?) k6 M/ J6 ^& b) c2 E) E
<P><FONT color=#0000ff>/* open a file for update */ % G$ @0 T) Y9 K
if ((stream = fopen(FILENAME, "w+")) == NULL) & p/ w7 g5 u" J: l( Z; h" O
{
5 ^. J( J0 z2 D1 Ffprintf(stderr, "Cannot open output file.\n");
+ b( Z9 ~% R- X: _return(1);
8 ~) m4 q  j& H7 ?0 X} </FONT></P>9 \* `$ n) P/ S5 Z: S
<P><FONT color=#0000ff>/* get information about the file */
; f6 J' {. I' y. N1 g2 U7 {" Kstat(FILENAME, &amp;statbuf); </FONT></P>- F5 O! ]% I( b2 v
<P><FONT color=#0000ff>fclose(stream); </FONT></P>  |' t8 X2 s$ J: l( U7 M
<P><FONT color=#0000ff>/* display the information returned */
" S. E, N# D7 v7 Q$ d$ b9 Lif (statbuf.st_mode &amp; S_IFCHR) & }2 p5 n% @6 ]+ N
printf("Handle refers to a device.\n"); ' D+ |* t5 w# e7 ~% \' m1 |
if (statbuf.st_mode &amp; S_IFREG) $ c5 D1 ?2 S. m4 L3 ~! K
printf("Handle refers to an ordinary file.\n");
3 |9 G( y9 O3 V; ~' K1 yif (statbuf.st_mode &amp; S_IREAD)
6 `( ]! R$ R5 P9 _. tprintf("User has read permission on file.\n");
2 c( C2 P, K5 f% ~* T- fif (statbuf.st_mode &amp; S_IWRITE)
% p. m: U2 o. e( J5 @2 ]- oprintf("User has write permission on file.\n"); </FONT></P>* {7 H( O# o" j0 p' n; o  {
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
/ o; e7 C2 j, F) N5 `printf("Size of file in bytes: %ld\n", statbuf.st_size); 4 g( J2 I/ x7 E$ B1 b' \' c& ?. D
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime)); 2 u8 m2 D8 y& l! G# X
return 0;
/ l" b: r0 d5 N; W# [  b}
, p5 G& q4 K' e& o& K/ ~1 h& [0 s+ g4 V3 Z! W- t
</FONT>+ `3 S1 b( i5 ?  E' E
</P>
- m# Y; V1 a) z( ?+ C<P><FONT color=#ff0000>函数名: _status87 </FONT>* @$ A, z4 h# y/ R, C3 z) g1 \1 I
功 能: 取浮点状态
, D: R2 ~$ f7 W6 O用 法: unsigned int _status87(void); 7 m8 @8 S2 O2 J: {% v
程序例: </P>
% `( p% m! b6 N6 _! ^<P><FONT color=#0000ff>#include <STDIO.H>
$ c% d, O+ Q% w3 J# z! s#include <FLOAT.H></FONT></P>; h8 C' J; ]- W4 B
<P><FONT color=#0000ff>int main(void) : D& G5 L- o/ s
{ ( P! `( R# L& I" k' }: t, n5 {6 t
float x;
, S) X( n, h) x. i0 v0 c  Wdouble y = 1.5e-100; </FONT></P>
1 x: O7 }2 v) L0 L* ]<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>8 B* c  e: n! ~# p; h7 @
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
. s# O4 W& I* a( J3 c3 D- k. C% ~y = x; </FONT></P>
4 v- _% S6 w* m2 c0 A% v4 L2 Z<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
2 K! j2 y. X& b, D' j1 f  h, u2 `return 0;
5 y3 a  n* A6 p8 R}
4 H: r+ ]7 T9 R, C</FONT>/ z# l7 ]; V! B/ F: B! f
</P>
1 c8 x# \- y' h: F<P><FONT color=#ff0000>函数名: stime </FONT># T  h. t- n" K. H1 v' ]# C7 h
功 能: 设置时间 ( D5 w  U2 c4 k
用 法: int stime(long *tp);
% H& \( I4 a% m0 `- w! ^+ Z( _程序例: </P>8 t) U# t: h5 |% a. v4 @% @* f; s
<P><FONT color=#0000ff>#include <STDIO.H>: U. c3 W8 I' e5 w! @
#include <TIME.H>: k* _7 R% z* F5 r1 i
#include <DOS.H></FONT></P>, g2 C) G+ b6 p: J
<P><FONT color=#0000ff>int main(void)
8 D! z7 [1 ^7 T! }% C1 [5 Z{
/ N" i: _" n! y( @time_t t; ! t: l9 v6 U$ `3 _
struct tm *area; </FONT></P>
3 }: K3 k' b& t! B# s, L<P><FONT color=#0000ff>t = time(NULL);
& `( g; ?6 W/ ]6 aarea = localtime(&amp;t); + m9 |' v( e+ \- Y, E& D6 q4 w
printf("Number of seconds since 1/1/1970 is: %ld\n", t);
* W. X9 w5 V9 a) a2 gprintf("Local time is: %s", asctime(area)); </FONT></P>
; v$ Q6 R0 P8 N0 @& S<P><FONT color=#0000ff>t++;
6 Q- R/ Y0 L3 N1 xarea = localtime(&amp;t);
' X7 G9 ~- L2 z1 fprintf("Add a second: %s", asctime(area)); </FONT></P>
3 @, K! d/ ~" i5 X/ u9 M3 F<P><FONT color=#0000ff>t += 60;
2 h; F$ l# m; v* U  tarea = localtime(&amp;t); ' p2 g# v3 A) t3 r2 [. O0 N
printf("Add a minute: %s", asctime(area)); </FONT></P>
8 w4 ?' _# G, e- c$ e. B  P<P><FONT color=#0000ff>t += 3600; 6 b8 B. n4 C. T
area = localtime(&amp;t);
# e  D7 L) R$ A8 P2 h* |printf("Add an hour: %s", asctime(area)); </FONT></P>
0 D# C3 v: I& I4 y<P><FONT color=#0000ff>t += 86400L;
- i2 M) s5 T* Warea = localtime(&amp;t);
7 ]8 a' `( M7 `1 [  |3 Gprintf("Add a day: %s", asctime(area)); </FONT></P>
# z. {' O+ S; p<P><FONT color=#0000ff>t += 2592000L; ) ~: Z0 ~  b/ ^
area = localtime(&amp;t);
, b, U: F9 M& p5 @, F1 i; H1 \printf("Add a month: %s", asctime(area)); </FONT></P>0 w/ s" r& W5 j0 v
<P><FONT color=#0000ff>t += 31536000L; 3 O- y$ h6 ^1 ]. s, ~
area = localtime(&amp;t);
; N3 I! V$ n0 ]5 z* P6 g! oprintf("Add a year: %s", asctime(area));
. s" x! z$ O5 c+ ]% D% H- ~7 mreturn 0; ' p; |4 V6 _( n4 c: s5 L
} </FONT>) `% u( T" ?" k. K! `6 M
5 Y2 X' N* A7 ~/ i6 v* r
$ R( c& z/ |' {+ S3 {
</P>, u) K1 J' V- K6 H
<P><FONT color=#ff0000>函数名: stpcpy </FONT>
" d/ Y& G& H, L9 y0 S5 O功 能: 拷贝一个字符串到另一个
! ]$ g! O1 `4 Y) i' s/ u" @用 法: char *stpcpy(char *destin, char *source);
, h4 d$ o4 K6 Q) k" `( [: r程序例: </P>: c4 K  g2 ?! o7 ^- Q, U
<P><FONT color=#0000ff>#include <STDIO.H>) M- J3 A+ W8 f
#include <STRING.H></FONT></P>* x' K7 l2 D4 H/ ]. @" l) Q% |% y
<P><FONT color=#0000ff>int main(void)
1 B# u+ A! t, Z+ R" S2 T! |{
" i1 a2 |' S- Q# {5 j3 b! e5 I& Schar string[10]; 2 e- T9 g& k! L
char *str1 = "abcdefghi"; </FONT></P>
8 u8 K0 d+ [# `: T<P><FONT color=#0000ff>stpcpy(string, str1);
9 \& I# D" L9 O- Aprintf("%s\n", string); % Y- t: M# h( e3 ^" e
return 0;
8 P- G8 ^" i- z$ v} + p# N6 F6 I8 C' i. q9 c6 G5 O

9 F8 `/ s( m7 n) `) v# c- F</FONT>
. {3 w1 b9 ^1 G* v</P>
* Q6 ~2 h4 R) b<P><FONT color=#ff0000>函数名: strcat </FONT>( `- n# ^- K  R: V" e- x& R
功 能: 字符串拼接函数   c' `  P: K1 s9 Y% X: M: u& c3 X# B
用 法: char *strcat(char *destin, char *source);
0 O8 d, c- \7 l7 o9 K+ D# I程序例: </P>3 A% `/ f! N7 {+ v0 ^5 d4 E* Y
<P><FONT color=#0000ff>#include <STRING.H>
3 q4 @5 h, e) V3 y#include <STDIO.H></FONT></P>7 `7 q+ k% s9 W/ }" B
<P><FONT color=#0000ff>int main(void) ( }' w+ ~# Y5 M5 v* s3 H6 h; i! [" y
{ 3 C' h- ^+ V7 h  j' R/ Q! \* l- P
char destination[25];
- m5 u) \3 h6 x% ]5 G; _- ^char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>5 A. G6 k9 b$ E0 H: W% \! M
<P><FONT color=#0000ff>strcpy(destination, Borland);
3 T* y, H3 }' o; E& R9 ostrcat(destination, blank); * Z7 N6 s. I% W3 b. B1 \
strcat(destination, c); </FONT></P>' s* z! g& E) n/ g) y; J( m
<P><FONT color=#0000ff>printf("%s\n", destination); & @, x$ l5 i- t$ L5 h4 `
return 0;
9 R( K4 K9 |2 s: T  q} ! x+ q* ]; C2 y6 L: p
$ ]$ m- J. V. k; x4 o, _7 P
</FONT><FONT color=#ff0000>
$ L* A7 y2 y5 G. V. A& f5 ?</FONT></P>, T4 [# ]7 g+ r" N8 ?6 r  n! J1 {
<P><FONT color=#ff0000>函数名: strchr </FONT>$ X4 V3 B  f( s" v$ A5 Q
功 能: 在一个串中查找给定字符的第一个匹配之处\
% R7 i/ Z3 ?! }& s3 }- f2 @. {用 法: char *strchr(char *str, char c); 7 {7 D; m2 m  K% u- w0 ]; ^
程序例: </P>
" j2 H3 h0 R6 S' W$ C7 v; {<P><FONT color=#0000ff>#include <STRING.H>
% S: e2 C) S* G#include <STDIO.H></FONT></P>* r! L9 R9 l2 U) E% ?+ C
<P><FONT color=#0000ff>int main(void)
# |% A6 {  t: \5 o, K8 q{ 0 [/ e0 Z) f% C
char string[15];
5 p3 v- c) Z# e( j' g: L$ ~char *ptr, c = 'r'; </FONT></P>
* f6 h$ U7 r. z/ Q# |<P><FONT color=#0000ff>strcpy(string, "This is a string"); & @* U6 b" l) c
ptr = strchr(string, c); , w2 c* E$ _" i" e  ?
if (ptr)
7 `: s2 h3 {5 eprintf("The character %c is at position: %d\n", c, ptr-string);
0 K- t% S6 M$ U! Aelse
# B6 Y% K" L6 C7 w, }) Fprintf("The character was not found\n"); % e6 Q+ H: w" H2 @/ |( U
return 0; , [6 V) X! T' u0 f5 t8 n
}
! t& D5 Y& H; o& i' r0 c</FONT>
% z6 |) ~) X. B' H& G+ F( g
' T* |, B! e4 [( t* a</P>
) S0 b5 a% B! @% Q. V" v<P><FONT color=#ff0000>函数名: strcmp</FONT> ! s: D  ^! b" g8 w! F! }
功 能: 串比较
5 x3 |4 ?* F* H2 @" Q用 法: int strcmp(char *str1, char *str2); 5 U5 L3 }/ f% z8 l( i- g
程序例: </P>
; o$ V  n  H5 t# u3 u/ ^+ q<P><FONT color=#0000ff>#include <STRING.H>5 Y9 [0 M* m3 j2 v5 |/ N6 i
#include <STDIO.H></FONT></P>' ~2 x" H0 I1 J! z0 m
<P><FONT color=#0000ff>int main(void) 6 C! j- J5 \! v8 W4 H2 e; Q3 w
{ 8 Q7 Z7 o3 `; S; z( o7 [7 U& d! x
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; $ V' y, j) U8 }- o# S
int ptr; </FONT></P>: M9 L2 I; N. r& N/ m) I8 z
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
$ ]* E1 q/ m/ I1 n" ]5 yif (ptr &gt; 0)
8 ^5 W2 {7 I: x) \- o1 t& t) Vprintf("buffer 2 is greater than buffer 1\n");
9 ?  s  g0 g4 u2 I; ielse : X6 I1 W6 D2 m5 H) {- G
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
, I! r7 k) z* T$ l' x<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
$ i6 Q' ^, O0 b) q8 ], cif (ptr &gt; 0) , w% M! I7 |3 y# y$ z. z
printf("buffer 2 is greater than buffer 3\n"); : p; \, O+ a- O  i. s1 Q4 f
else
( V+ |9 _# i0 Sprintf("buffer 2 is less than buffer 3\n"); </FONT></P>/ e) x' I, Q% ]9 y( q/ G
<P><FONT color=#0000ff>return 0; % }3 j  L6 T, f, U9 t9 `
} ! c8 L. L1 ?+ `% [& B7 u

  k7 |$ p% C3 ~& t/ B- [2 W, ]- O5 C, H/ @. E) q! X
</FONT></P>
* L! E& i) r( e. G<P><FONT color=#ff0000>函数名: strncmpi </FONT>
# `! @! B& }4 [, h+ E1 k! n5 Y功 能: 将一个串中的一部分与另一个串比较, 不管大小写 8 x4 S* e7 M4 e0 K( \2 ?
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
& P2 `4 s/ k8 Z' E$ {$ ]程序例: </P>- V% M# C- V  s" u* V
<P><FONT color=#0000ff>#include <STRING.H>; r' _+ Q3 O5 S% {
#include <STDIO.H></FONT></P>' E8 ~% l% G: Q, \" ^/ C3 H' l
<P><FONT color=#0000ff>int main(void) ! i' |1 @' F* O3 A/ m
{
% ~- ]$ ^: m' v( O" a! S! {* pchar *buf1 = "BBB", *buf2 = "bbb"; & O4 B+ C/ l3 w& k' a
int ptr; </FONT></P>
9 L& c* D, {" F2 c" w& s2 |, R; @<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
2 @& U' t5 a- s8 f4 w  B8 o<P><FONT color=#0000ff>if (ptr &gt; 0) $ D/ l+ t, k8 m0 f3 r# n7 s
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
: B5 `# n( Q- _5 Z! a4 L$ k# X6 ]1 D<P><FONT color=#0000ff>if (ptr &lt; 0)
& }, t3 t9 k* dprintf("buffer 2 is less than buffer 1\n"); </FONT></P>$ a% F( P- S3 a5 R0 K
<P><FONT color=#0000ff>if (ptr == 0)
. v5 w: B% J* n8 Eprintf("buffer 2 equals buffer 1\n"); </FONT></P>) s5 d! Z: l* b6 u7 D/ a& a
<P><FONT color=#0000ff>return 0; 5 P& ]/ V% Y4 g1 y3 {3 M
} 0 V. J3 N3 L. j
1 F5 x0 B+ X7 Z" Q0 I
</FONT>1 T/ n: Z9 r$ t
</P>9 N: _8 @9 t8 g) E7 @
<P><FONT color=#ff0000>函数名: strcpy </FONT>2 D) R" s6 E! z5 I) n
功 能: 串拷贝
# b- L# N) p( [5 _" D4 T6 ]用 法: char *strcpy(char *str1, char *str2);
2 ^* G4 B" |- L5 g3 ?( |程序例: </P>; I  v. q, N3 H$ V/ `
<P><FONT color=#0000ff>#include <STDIO.H>! R' V( ~. p$ {4 B# j: G
#include <STRING.H></FONT></P>) v1 p; {+ ?; o  O2 w. r$ ^: U
<P><FONT color=#0000ff>int main(void)
2 [" H9 D  f! }, C# {7 O% ]' f{ # f9 H! o2 f* Z7 M& c7 n
char string[10]; $ e- U/ X$ Z4 t' _6 V( w% e3 T) H% K
char *str1 = "abcdefghi"; </FONT></P>0 D) A1 ~% f4 |  \7 `, v" g5 F
<P><FONT color=#0000ff>strcpy(string, str1);
/ M% R+ E* m+ q# u) Q" Tprintf("%s\n", string); + O" g& V" r2 F. Z: `& i% S) d; V
return 0;
- b* K5 s1 k* m" {0 ^4 N9 `}
) a8 e1 o0 T; j: {# ]  f6 j</FONT>( y. h' i- m( E

# [& n7 B% f% D. F3 f</P>
- X9 l. Y3 h4 V! M6 \) h6 Z2 @" U6 v+ k<P><FONT color=#ff0000>函数名: strcspn </FONT>
- [. l. U. L( u" T* I功 能: 在串中查找第一个给定字符集内容的段
- V+ T3 M7 w- H& z5 H" }, \# e' J% R用 法: int strcspn(char *str1, char *str2);
, ]% W7 I8 s7 Y; Z* W8 D, G8 ~程序例: </P>
2 [' v3 |" Z6 m9 i" J+ h& z<P><FONT color=#0000ff>#include <STDIO.H>
* L/ l3 x8 P5 K3 ]0 e# S#include <STRING.H>
0 i* ?5 g: o% ]( Q#include <ALLOC.H></FONT></P>
$ B: H# a+ D( e; p<P><FONT color=#0000ff>int main(void) 2 B5 c0 Y& U- {" y; t/ ^. y
{
) q7 Z! k' u% N0 g1 N! B8 h( Zchar *string1 = "1234567890"; 5 X0 M* \) \* r$ S+ V- M
char *string2 = "747DC8";
, ~8 n$ ^. G5 k  J( Rint length; </FONT></P># g% m% g2 `3 K" H
<P><FONT color=#0000ff>length = strcspn(string1, string2); , y$ K0 |$ C$ G: x4 n+ x
printf("Character where strings intersect is at position %d\n", length); </FONT></P>
2 x% h- p- ~4 g* [0 v# O6 \<P><FONT color=#0000ff>return 0;
; u! k% `, Z9 a( T8 A}
3 f9 p& J+ E( V/ f</FONT>$ H3 V. k6 O8 Q* o7 Z- \1 \8 p
5 q5 d) [' Y1 q. o3 J# o1 d
</P>
# L) A3 y8 k; n% G8 i<P><FONT color=#ff0000>函数名: strdup </FONT>! e% |; U1 D" ~4 ]) r
功 能: 将串拷贝到新建的位置处
% i# r0 q6 U. c- v用 法: char *strdup(char *str); 9 U( x" y9 G$ y& v+ }7 b
程序例: </P>
! n( I. X! \  K5 D<P><FONT color=#0000ff>#include <STDIO.H>
5 L0 o- t! A3 ~#include <STRING.H>0 |0 k3 S. @- @- p/ b
#include <ALLOC.H></FONT></P>
! J7 \* c( z0 M" l6 Z) [, u<P><FONT color=#0000ff>int main(void) & h; Q# {; m. ]4 J8 ]0 D) U
{ # v' O2 z! J  o7 f
char *dup_str, *string = "abcde"; </FONT></P>
; @# Q* n) _6 H4 b<P><FONT color=#0000ff>dup_str = strdup(string);
- z9 B. p9 B6 n7 C) Mprintf("%s\n", dup_str); " ?! m" [* r/ X2 {: ~  p
free(dup_str); </FONT></P>) J1 M1 s# a4 \
<P><FONT color=#0000ff>return 0;
' S8 t1 @. g+ {6 B7 [}
2 k2 ~# _$ B" r. H: b: Y9 H
; }$ I* I. A1 T: {5 `( A4 X8 e</FONT>
6 B+ @7 W: p2 b</P>- U3 r7 T6 B- U# [! N" [2 J
<P><FONT color=#ff0000>函数名: stricmp </FONT>% g+ ~. P) ^. A7 m2 R+ i
功 能: 以大小写不敏感方式比较两个串 7 q& u) i0 K  c/ {6 f1 x3 i4 J: E+ h9 X  B
用 法: int stricmp(char *str1, char *str2);
/ b7 u$ w- d  r' {$ u2 P5 R程序例: </P>
* R& s5 Y& X: q" s# |<P><FONT color=#0000ff>#include <STRING.H>
% _" H; A& O# v/ w1 [; z#include <STDIO.H></FONT></P>- t, [- a4 u6 ~! e4 H
<P><FONT color=#0000ff>int main(void) 8 i& @; z3 n' H' m# d% e2 ?
{
, U9 v$ W' o: T! s/ kchar *buf1 = "BBB", *buf2 = "bbb";
: A  J2 O+ V  S* ?; X# [int ptr; </FONT></P>
4 K- L$ a4 r; p) E% o" T9 t3 u' F<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
1 d- g) {+ H3 e( o<P><FONT color=#0000ff>if (ptr &gt; 0) 5 y4 N7 U2 D- U0 x) b+ X
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
% Y) E5 J3 [% K7 s<P><FONT color=#0000ff>if (ptr &lt; 0) 7 j1 V" D- a7 F$ f8 {% x, Z8 O
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
& I  V/ ~% c/ ?7 M* K<P><FONT color=#0000ff>if (ptr == 0) ; P# \, m* Y: v+ [! j
printf("buffer 2 equals buffer 1\n"); </FONT></P># r3 ]+ |$ L! t: V
<P><FONT color=#0000ff>return 0; 5 S& P/ }: V* H! r. e6 A
}
& J* m5 P: c/ }$ G1 G* _/ O</FONT>, U& W3 b" S/ N2 Q4 b4 r
</P>
! b" |) z* J& U<P><FONT color=#ff0000>函数名: strerror </FONT>6 |6 t. \, A3 u- J8 F" g, b
功 能: 返回指向错误信息字符串的指针
/ ~4 ?7 ]. n! o用 法: char *strerror(int errnum); $ t1 V9 C5 k/ _! W! N
程序例: </P>
2 K0 x2 j4 r2 c; B/ s9 Z+ t. W<P><FONT color=#0000ff>#include <STDIO.H>0 |7 B( U: ~8 y9 J6 n5 \
#include <ERRNO.H></FONT></P>
0 S+ y, h. b2 U+ W9 |<P><FONT color=#0000ff>int main(void) . N; N+ B* D* b3 h+ W
{ + ^6 L. Y2 [2 X" f- k& [3 T
char *buffer; ; n+ [" b! R% R0 n" [  ^- e- p/ ?) U
buffer = strerror(errno);
! {; X: P% s$ L% Wprintf("Error: %s\n", buffer);
5 a* g  C& d' S0 t& j" qreturn 0; , u7 ?- a, `7 U: v- }1 y% K
}
$ d1 o4 z7 r+ R! M+ D- L0 W
$ v: a. d' F" I) C; P</FONT>
5 W& V( L6 H/ R4 Y</P>
2 M/ E4 F  v- o/ m<P><FONT color=#ff0000>函数名: strcmpi </FONT>7 C0 v) A$ D* {6 K7 e
功 能: 将一个串与另一个比较, 不管大小写
$ q/ m4 k5 _* ^! k+ n) j& h用 法: int strcmpi(char *str1, char *str2);
* s' M- l3 ^9 k* i程序例: </P>9 t5 S( L6 [* ~, {3 P
<P><FONT color=#0000ff>#include <STRING.H>
9 g# x' N8 X% O" i# ]) \  y#include <STDIO.H></FONT></P>
4 j, s+ [7 a# s. |4 i# @  s<P><FONT color=#0000ff>int main(void)
; b' K" U8 ^/ e2 M{
% l" w) N  w! j% G8 h" Vchar *buf1 = "BBB", *buf2 = "bbb";
, Y' ]; O+ }! r" w/ l& ~, y( Jint ptr; </FONT></P>8 x; n: J! }% ^
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
) ^0 X5 i; O  q3 f* y<P><FONT color=#0000ff>if (ptr &gt; 0) & ]3 c: V4 `  c
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
$ O  J2 G5 f' S$ L1 n- Q2 a<P><FONT color=#0000ff>if (ptr &lt; 0) ' R# w6 X( v0 y6 J* D  R- o
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
; h1 N% A& X; U2 N1 M- l5 c1 B, P<P><FONT color=#0000ff>if (ptr == 0) . ?* l+ V0 ?3 R% w
printf("buffer 2 equals buffer 1\n"); </FONT></P>
! a+ P% k6 K, L# h2 {5 |' L' v<P><FONT color=#0000ff>return 0;
# F. D& g) k5 u: d7 f+ `}
9 x2 w5 G+ j" g3 r3 c* t+ O</FONT>
! }' [2 ~6 g. a$ `7 q; U- t1 r- L# z8 ?0 o
</P>
7 O8 ~, F; {2 r) w<P><FONT color=#ff0000>函数名: strncmp </FONT>4 ?' z+ H4 Z$ H# P( i
功 能: 串比较 - R  F3 j. S# a1 u. C; W
用 法: int strncmp(char *str1, char *str2, int maxlen); : ]7 J3 d) r& ]* d; W  R
程序例: </P>
' G$ [$ Y5 c' \1 a8 z, ]<P><FONT color=#0000ff>#include <STRING.H>5 H/ }7 G/ G$ y1 ~% f
#include <STDIO.H></FONT></P>
4 i# D3 I! t& N' z) A& b7 S) _<P><FONT color=#0000ff>int main(void) </FONT></P>
1 v1 h/ r( K. F9 k9 w  ~3 u<P><FONT color=#0000ff>{ 0 T, x2 L1 C" _9 W% }# p
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
2 w( R. g$ e7 ]. {$ Z$ Qint ptr; </FONT></P>
/ [6 q+ A2 I3 Q3 f( j) \8 J6 x5 x<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
2 o3 ?$ f5 l9 _5 V/ Zif (ptr &gt; 0)
0 l! a9 _2 o7 w1 y- I$ [/ }* L, @printf("buffer 2 is greater than buffer 1\n"); 4 E, q. d: |; H& q5 w
else
+ n6 ]  G7 J, s+ o' a$ [+ `+ `+ Pprintf("buffer 2 is less than buffer 1\n"); </FONT></P>& C3 v8 D! u8 P/ [+ ~
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
$ Q3 j) U$ Q% Bif (ptr &gt; 0)
: ~% r: G: O; R: |/ {( Nprintf("buffer 2 is greater than buffer 3\n"); / Q8 {$ F# n3 Y& `) M% U
else , i  [% T5 j$ c2 F. O
printf("buffer 2 is less than buffer 3\n"); </FONT></P>5 h1 \5 z$ L1 E# z, l, u. j2 v, d
<P><FONT color=#0000ff>return(0);
7 ]) i" i2 q3 Y8 D# x}   _: u' t; X& T$ k

. Q- O5 Y3 D* Z</FONT></P>
. v- Y3 H2 V) q% [% y& n, n8 ~<P><FONT color=#ff0000>函数名: strncmpi </FONT>
* ~  j4 p6 Y6 X/ A1 n功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 7 k( ]) V/ k+ E
用 法: int strncmpi(char *str1, char *str2); + U9 {, h8 m7 D% M9 {0 i5 v, ]
程序例: </P>
$ l- I8 C  ~) ~* d5 y) [, Z6 m<P><FONT color=#0000ff>#include <STRING.H>% D" G) t* @  ^" Y% ]* |
#include <STDIO.H></FONT></P>0 d! X0 G% I, b0 H# |( @7 O
<P><FONT color=#0000ff>int main(void) - b+ V3 H* R) y$ E) A$ a! q% k
{   B  S' R' @- ]# O  z* z) p( P: d; n
char *buf1 = "BBBccc", *buf2 = "bbbccc";
5 P5 t! F% i& W5 S" U! V3 aint ptr; </FONT></P>
! \( D, r* `# Z! N1 [9 K4 I<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>
9 C* a0 Q9 h: x! k( g<P><FONT color=#0000ff>if (ptr &gt; 0) ) D- z" a# l5 i" `
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
6 s9 g. v. b3 s1 I<P><FONT color=#0000ff>if (ptr &lt; 0)
/ P% K; O6 n2 u% D% C9 I2 ?+ oprintf("buffer 2 is less than buffer 1\n"); </FONT></P>; ?) C  Q/ @& T  x/ }
<P><FONT color=#0000ff>if (ptr == 0)
" M0 ], y  c. }  [$ g1 b6 M6 Bprintf("buffer 2 equals buffer 1\n"); </FONT></P>' _5 g: {0 Y) T  K- M; e. M
<P><FONT color=#0000ff>return 0; </FONT>
  f% g2 n5 I" A, z3 }0 n} - k0 u3 g+ _. R. m- u" Y: f3 a
( ^2 E! x! v% a9 {# l) c% s( C
</P>
, m# B/ v! h: t1 L: G  B# T<P><FONT color=#ff0000>函数名: strncpy </FONT>
& C2 e2 Z* ?$ x功 能: 串拷贝 $ s; T3 G* \. L' ^
用 法: char *strncpy(char *destin, char *source, int maxlen);
2 |+ k7 C: v. M程序例: </P>
  n) n2 q# s# H6 Z0 C<P><FONT color=#0000ff>#include <STDIO.H>
. d7 K% z0 b9 P* }; L2 p#include <STRING.H></FONT></P>
+ h  e9 S2 _8 C5 ~<P><FONT color=#0000ff>int main(void) ; g3 O' @5 o/ N4 S
{ 5 `  S- Q8 K7 B8 h' o! W7 O
char string[10];
" m- h5 _2 `* i2 h6 Achar *str1 = "abcdefghi"; </FONT></P>$ m0 F/ a3 m& U6 Y: E
<P><FONT color=#0000ff>strncpy(string, str1, 3);
6 W1 u( Y! y  w! jstring[3] = '\0'; ) M- N8 ^! w6 _& d' J2 j
printf("%s\n", string); 0 h! ^& N& {: M) r: @- R% O2 ~# Z7 s
return 0; 3 F% ^5 P1 X: ~2 W2 z6 c5 T* |
} + i0 ]9 i  I" G
</FONT>
" i/ S& R! f/ u; J</P>( B" `7 f1 C, t5 x& U% S: ~
<P><FONT color=#ff0000>函数名: strnicmp </FONT>5 R, L; {; X9 s# j
功 能: 不注重大小写地比较两个串 - f! ^( c$ s/ u7 c# V# j- f/ n* m1 @
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
: W4 k' S! X1 b) Y程序例: </P>0 G4 Z! L: k$ C
<P><FONT color=#0000ff>#include <STRING.H>5 T4 |9 f. `7 L7 d' t" G3 Y9 ^  y
#include <STDIO.H></FONT></P>, u5 @9 U! _2 z( F+ _' s9 K0 d" i
<P><FONT color=#0000ff>int main(void)
# U  I  s# H3 P4 p/ u& ^5 ]. [{ 9 H' r, I  H3 k7 x/ |
char *buf1 = "BBBccc", *buf2 = "bbbccc";
9 A! a2 v, G  l2 B0 U: _/ r3 rint ptr; </FONT></P>! O! ]  R! A, b2 N7 k' t( s( _
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>  G9 n- k+ `" ]: U
<P><FONT color=#0000ff>if (ptr &gt; 0)
: I; {0 u9 j$ D2 A5 v, u8 c* Gprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>8 m1 t6 M5 K/ @
<P><FONT color=#0000ff>if (ptr &lt; 0) ( l$ j5 O9 w, D+ T) ]
printf("buffer 2 is less than buffer 1\n"); </FONT></P>! x/ z( l  V- O- n! F
<P><FONT color=#0000ff>if (ptr == 0)
2 o" k) V9 u0 F; n! p2 \printf("buffer 2 equals buffer 1\n"); </FONT></P>; }% A% z) a/ k! w+ a
<P><FONT color=#0000ff>return 0;
/ U5 `7 q( a- p. N: |& p/ i} 5 J  n2 @; l4 Z+ x4 P
% \$ D& `% u; e$ |% u. ?
</FONT>, X; |- H0 P9 V1 ^! j) ]6 X
</P>
/ j3 \9 [5 d# w; J8 V4 B! S<P><FONT color=#ff0000>函数名: strnset </FONT>$ r; Y; a$ v2 \9 r- M& I; [
功 能: 将一个串中的所有字符都设为指定字符
$ V5 E8 g9 p' {$ p& @) [用 法: char *strnset(char *str, char ch, unsigned n); + y/ F; V0 j) a0 m
程序例: </P>
+ @6 c5 G5 q! w: V2 \) S8 K<P><FONT color=#0000ff>#include <STDIO.H>
* u$ Z: ?8 P# u4 K#include <STRING.H></FONT></P>% A5 k& [) Q% C( }8 u5 \' j3 V7 g4 Q
<P><FONT color=#0000ff>int main(void) " R$ a+ L- d8 ]" W
{
0 m6 F0 o! V* S8 d8 v. q* Vchar *string = "abcdefghijklmnopqrstuvwxyz";
3 h0 b  T- L0 F- O) F- |char letter = 'x'; </FONT></P>
+ t2 e4 j2 V3 G<P><FONT color=#0000ff>printf("string before strnset: %s\n", string); 2 d; z0 g+ p) ]6 ^2 {! E
strnset(string, letter, 13); % X' q# M7 j5 ~1 O
printf("string after strnset: %s\n", string); </FONT></P>2 z) L" \# p7 u) W6 R
<P><FONT color=#0000ff>return 0; 7 I1 W7 t4 Y+ k6 n
}
  z+ l1 \% }/ y( A7 w; ~2 s</FONT>
7 o/ d- A6 A. Q1 S( Q. G</P>: e) G, y, c: y0 e- J: b4 d# L9 n# x+ S5 y
<P><FONT color=#ff0000>函数名: strpbrk </FONT>+ [# _: l4 @( D; L& v& N
功 能: 在串中查找给定字符集中的字符 2 a  N6 J9 D/ o5 n0 g
用 法: char *strpbrk(char *str1, char *str2);
1 P. h- v$ v5 M+ ~程序例: </P>6 ]2 w5 J: s: i6 L( G' P% r0 j
<P><FONT color=#0000ff>#include <STDIO.H>
) G/ e; X: Z1 H#include <STRING.H></FONT></P>
9 U8 _8 c8 f1 A  q3 @" J. O# {<P><FONT color=#0000ff>int main(void) ! Y7 [$ m5 A, u
{
; O1 N( |& O8 n" kchar *string1 = "abcdefghijklmnopqrstuvwxyz"; % q( u  U$ I% a2 C
char *string2 = "onm"; 9 W8 [7 n' B1 {, Y/ u/ @8 e8 _) {
char *ptr; </FONT></P>4 ?4 ~& W  F) i1 ~( e
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
6 l6 B9 ?! [9 h- Z" e' {<P><FONT color=#0000ff>if (ptr) 0 h( R- M7 Y" _' O, ?  z
printf("strpbrk found first character: %c\n", *ptr); . I( n8 X* w8 v7 G; R1 a8 b7 M' W
else
1 ~1 t! f$ _; w& i0 s2 H6 Lprintf("strpbrk didn't find character in set\n"); </FONT></P>; w, S" F0 J) n& X; b4 a
<P><FONT color=#0000ff>return 0;
# G. z  o  K# e/ e0 d} 4 i( {% x6 U) `5 p) J  y
( `* m, r; `5 p0 S
</FONT>' E* ~4 ^( S2 L! K# b$ k; g. [
</P>' s2 c0 I" j5 y6 ?( C6 c3 k) n
<P><FONT color=#ff0000>函数名: strrchr </FONT>9 Q, Z5 X- z+ f; N- r
功 能: 在串中查找指定字符的最后一个出现
1 [# q1 [2 D2 [1 Z用 法: char *strrchr(char *str, char c);
3 i* Z  B# ?6 a9 i2 ?程序例: </P>' ~* Z1 e8 M) Z5 z! d' @
<P><FONT color=#0000ff>#include <STRING.H>
# _% k0 }* w) M; \#include <STDIO.H></FONT></P>
% p/ V: u# O0 [% a1 G6 @  x- S<P><FONT color=#0000ff>int main(void) ) Q0 E5 t! h2 s7 x% r
{
5 O) Y& X+ x4 U  g# p9 P! achar string[15]; ' m) b# X( Q. n
char *ptr, c = 'r'; </FONT></P>0 ?& \8 W) U( e+ X9 _
<P><FONT color=#0000ff>strcpy(string, "This is a string");
; ^8 _, G# @7 f( M6 L8 J' ]ptr = strrchr(string, c); ; q. I" p7 m4 u; h& s& k
if (ptr)
+ y0 J6 o8 M" [5 jprintf("The character %c is at position: %d\n", c, ptr-string);
5 \9 F: ~6 p, t6 oelse
) \& B  j3 }1 I1 Sprintf("The character was not found\n"); % r4 c) s. {& f" C; ]: F
return 0;
; ]3 o% L6 Q* Q5 C4 V. p6 q. [} </FONT># L* m3 v+ N  m# l

& [% g; J$ l2 v) N2 h3 a8 {' m- `
) |0 p# {" J1 H' B/ D8 u: t8 I+ p</P>$ U- B$ [4 ?. Z! \) i: s* v" ]. ]
<P><FONT color=#ff0000>函数名: strrev </FONT>) b* ~; J3 V) k0 q; L6 b
功 能: 串倒转 / s  W  b4 q" V8 q+ l9 N+ A
用 法: char *strrev(char *str);
: a9 V! G1 A9 J, }4 Z程序例: </P>
( D9 O' f0 f& F+ g<P><FONT color=#0000ff>#include <STRING.H>
0 a& ]7 I: ?* m2 `9 \6 g#include <STDIO.H></FONT></P>3 A1 l+ w" v3 ^' F3 ?' T/ d2 l: q
<P><FONT color=#0000ff>int main(void)
* h5 [9 q7 G1 j, f{
) P7 m8 ^/ e6 P: e4 r% s; X" v+ j1 Cchar *forward = "string"; </FONT></P>
8 c+ A9 V* y5 g1 P$ K' q<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
4 h1 U8 K$ r" b) P. t0 ~* I0 l# Z( P( Rstrrev(forward);
% Y0 }; u; c/ q. U- ]  ^printf("After strrev(): %s\n", forward);
& Y/ M0 h+ e# V0 M3 W6 X, ~& j8 D5 yreturn 0;
, U. f' u+ |" I% M. w} </FONT>. b+ M: K4 L4 k& o# K
</P>
6 z! {' r4 k( ?& x<P><FONT color=#ff0000>函数名: strset </FONT>- W/ D. N$ Z5 k6 [. E2 S6 d
功 能: 将一个串中的所有字符都设为指定字符
- D/ Z1 J+ }( c+ R用 法: char *strset(char *str, char c); # T- }5 f9 F4 R3 z4 E
程序例: </P>! L( @' [( N7 E4 N# }
<P><FONT color=#0000ff>#include <STDIO.H>
6 z" e8 U5 G- K5 q$ l  u#include <STRING.H></FONT></P>
! M0 n! G* E# `: Y) R<P><FONT color=#0000ff>int main(void)
( w) m4 }. x/ d# Y; I) Z{
+ [+ W9 r8 I: \$ E5 ychar string[10] = "123456789"; : H4 q. x% E+ {" _: N9 Y* i
char symbol = 'c'; </FONT></P>
& x4 C6 d# v' ]<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
3 m3 [; n3 U% n5 l9 |strset(string, symbol);
' D0 s" n& W# q; z( _# yprintf("After strset(): %s\n", string); 7 P  h! i5 o: @$ Q  t
return 0;
- Y4 p. p0 J* y4 w# k}
3 h) a: N0 ]& ~# ~7 O  V" ^1 J, i+ L! q: t
</FONT>9 S: c+ M5 p7 w8 e' p  r: f
</P>
$ {  w+ n" j; n+ F3 L( n) V! i9 V6 v<P><FONT color=#ff0000>函数名: strspn </FONT>3 }5 m2 y. S3 M& K
功 能: 在串中查找指定字符集的子集的第一次出现
1 j5 r& Z9 k8 E5 i( Q用 法: int strspn(char *str1, char *str2);
1 k9 C- a0 |( g程序例: </P>; X5 B$ J, e6 ?( I  O9 j
<P><FONT color=#0000ff>#include <STDIO.H>
6 j* `5 m, v$ p; P6 ^0 w#include <STRING.H>
/ @& W  P  J! G6 Q6 y2 l#include <ALLOC.H></FONT></P>
( K" S" f5 ~' ?( m) V' z<P><FONT color=#0000ff>int main(void)
3 k( _' p7 X$ c. U. {  [{ 3 }/ s9 C% h6 ~& N
char *string1 = "1234567890"; 0 o( V) d. `" t/ ^" k% g
char *string2 = "123DC8";
' K( Z5 r- I  B7 E% w0 G" ~; k/ `int length; </FONT></P>
/ m  [% [, L8 e. r, x+ s. `<P><FONT color=#0000ff>length = strspn(string1, string2); $ D. M& ~# K0 T, C% e0 H
printf("Character where strings differ is at position %d\n", length);
9 i/ f+ l1 i8 {4 B! W) yreturn 0; + }; l/ y; l9 X4 d
} ' ^+ o& x. ?2 R8 C( P  A! X
</FONT>* S# J+ V. Z1 [# \( v4 q  `( Q
</P>
) [$ \( P, m  L, V<P><FONT color=#ff0000>函数名: strstr </FONT>' U+ o. x8 d8 u1 t# r+ v& o
功 能: 在串中查找指定字符串的第一次出现
7 b4 ?: n' m2 ]$ a用 法: char *strstr(char *str1, char *str2); 1 q$ _0 r+ i" Q) M# I8 c5 n
程序例: </P>
8 F$ d1 W) `! ]% ]2 ~) b4 I4 W. O3 n<P><FONT color=#0000ff>#include <STDIO.H>
  t- x# V  k* }: u) ]#include <STRING.H></FONT></P>
4 A0 K: h6 |0 i/ N4 l: P<P><FONT color=#0000ff>int main(void) 3 D( g$ g$ u. j; [( D. N& M. y8 n
{
* p1 Q4 }9 U# Y: N+ uchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>6 ]6 n; w* Q9 l# V7 w
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
2 ]% D0 U) e  o/ nprintf("The substring is: %s\n", ptr); 1 Y& a" S. D4 d% F4 @# [; l
return 0; : |  ?2 G7 n6 X( f8 \+ o. d
} </FONT># ?$ |! f) N2 x$ @& A: p! w! `

* H! f6 O, }: _  p8 K1 z</P>& B( R+ j- Y0 r9 y% t1 Q8 A# k
<P><FONT color=#ff0000>函数名: strtod </FONT>
: b6 Y0 G* J5 @2 k功 能: 将字符串转换为double型值 0 b9 u, f; Y( p6 z8 t) a1 X
用 法: double strtod(char *str, char **endptr);
* L2 [! g! b2 W0 y! t6 l程序例: </P>! }4 {5 q2 u0 y+ N
<P><FONT color=#0000ff>#include <STDIO.H>
* b  R- y, `7 v, @; K$ V, S#include <STDLIB.H></FONT></P>2 b" t) q  X' S. V  Y
<P><FONT color=#0000ff>int main(void) $ j! q7 \# t5 e' o* }4 O9 a
{ $ k4 j% Q- [- z/ B: {4 ]
char input[80], *endptr;
( C- S2 u' T  K, N8 edouble value; </FONT></P>
+ z) `( c, d4 D' W6 \<P><FONT color=#0000ff>printf("Enter a floating point number:"); & o0 V6 \& E: Y# u2 r5 R3 y. B* {
gets(input);
  C: u" U# m5 q3 M$ O- ]! dvalue = strtod(input, &amp;endptr);
  {8 b% N, S6 Q5 N, }8 r, A: N! Jprintf("The string is %s the number is %lf\n", input, value);
0 \  Y% n: [. L  q8 e& Kreturn 0; 7 d% X! w2 g; k6 X. B* _2 ^+ M
}
, d% g3 b8 E& D, m, p% j; Z</FONT># ]* B! q) m. F& B: a1 y# E
3 O# d2 L4 X# W* \$ [4 K% [
</P>* z) F5 y# o% Y3 i" t
<P><FONT color=#ff0000>函数名: strtok </FONT>
4 I) ~; _9 l' K功 能: 查找由在第二个串中指定的分界符分隔开的单词 $ u- k% `4 U: y: e
用 法: char *strtok(char *str1, char *str2);
. w* {4 `' J* T3 t程序例: </P>8 @) c! G# E. h" `% r) i4 b7 _
<P><FONT color=#0000ff>#include <STRING.H>3 s, {4 \5 C6 I
#include <STDIO.H></FONT></P># ]) b! s* V  V0 ~3 s0 x/ O5 \
<P><FONT color=#0000ff>int main(void)
6 v8 x$ [" d6 c& B: H{
$ H/ O- C. G$ F( [: Schar input[16] = "abc,d"; 6 M3 C+ e" ?' h2 |9 H9 Z9 W2 r! _
char *p; </FONT></P>
$ E4 o5 P. {+ J2 D<P><FONT color=#0000ff>/* strtok places a NULL terminator
# z7 d+ V. y% Din front of the token, if found */ 5 ~9 v1 \. r2 H$ d: j
p = strtok(input, ","); 5 h* E5 l# Q. n9 Z1 P7 X" z
if (p) printf("%s\n", p); </FONT></P>
2 @0 ?* X# G. ?. y<P><FONT color=#0000ff>/* A second call to strtok using a NULL 3 H& v$ e8 w5 Z% Q
as the first parameter returns a pointer " b0 b4 ~0 d7 G/ A; a3 Q
to the character following the token */ 4 H+ e' k) b; n- q9 b5 D, T
p = strtok(NULL, ",");
+ F5 y7 T' C. T# V8 zif (p) printf("%s\n", p);
' M7 c0 i1 `8 ?4 }& E7 wreturn 0;
6 ]. f" X3 }  T: |# N}
% O, Z( W/ U& w$ D( {
: W  i; g  G5 b  Q, x" Y5 ]0 N) m9 U5 X" P, r; `3 s! R
</FONT></P>
9 i% u; {1 h) l! B<P><FONT color=#ff0000>函数名: strtol </FONT>$ H( B4 f' E+ \; e+ W3 [3 s
功 能: 将串转换为长整数
3 ~9 Q( n& {& q( ~用 法: long strtol(char *str, char **endptr, int base); 0 _7 g+ B: o$ N. L4 E( ^
程序例: </P>
9 \8 q' p( }) H9 u1 J3 g<P><FONT color=#0000ff>#include <STDLIB.H>
# r6 F. F! n- u* @7 ?' q#include <STDIO.H></FONT></P>0 a+ W. O' D) h) y- R# ?
<P><FONT color=#0000ff>int main(void) # k- z/ a2 [4 F5 h% F/ |
{ 6 Z2 h  ?5 _$ U; l3 ]% b
char *string = "87654321", *endptr; " G$ p8 }( W7 E  ^
long lnumber; </FONT></P>6 p+ L1 V8 X; {( W( j1 X
<P><FONT color=#0000ff>/* strtol converts string to long integer */
6 G. |4 X% J" Q" q4 }3 qlnumber = strtol(string, &amp;endptr, 10); ; i0 E: H4 S# Z
printf("string = %s long = %ld\n", string, lnumber); </FONT></P>
+ X& b! [7 K1 U5 h<P><FONT color=#0000ff>return 0;
' ^2 m- u! j8 P+ e} </FONT>
; \% B4 x/ Z! ]* U</P>4 Q, |! \4 `8 W9 K
<P><FONT color=#ff0000>函数名: strupr </FONT>
  _  T2 H, r- C6 V3 p功 能: 将串中的小写字母转换为大写字母 ; G: P& [1 g3 p: ^0 a+ U2 r: x9 [
用 法: char *strupr(char *str); - L9 T6 u: }' d4 Q7 Y
程序例: </P>) |1 i8 N% U3 {1 v' t2 r+ l
<P><FONT color=#0000ff>#include <STDIO.H>$ g: [/ f% `, y3 F5 S# _/ f
#include <STRING.H></FONT></P>
) v5 B! d9 X& h( @<P><FONT color=#0000ff>int main(void)
8 P7 o# V0 V2 E6 x% y4 ?0 C{ 4 R' Q, d+ d2 M6 E! u; T
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
( Q: P! ~) N- p9 I<P><FONT color=#0000ff>/* converts string to upper case characters */
$ U3 b2 M6 y0 i# N& Z8 |/ |/ B" Cptr = strupr(string); : P* o5 j) r9 }0 y8 A
printf("%s\n", ptr);
1 }2 ^* d! h( i7 N+ r1 Vreturn 0; + _9 h4 j: D, l% Z: b$ ^, I
}
  k; l$ y6 y! l0 f' g* v+ c! D8 N* O- \- t2 L1 e1 ?8 q; {
</FONT>) p# R3 H6 k( }1 i9 x* v+ B% y8 G
</P>9 H6 E% V& C1 r; }: b
<P><FONT color=#ff0000>函数名: swab </FONT>/ U( R+ _# g1 K
功 能: 交换字节
9 j1 G9 _  {$ N( T! n用 法: void swab (char *from, char *to, int nbytes);
# g: M$ E5 P. D3 {6 p程序例: </P>4 k5 }) ^+ Q6 p9 N  O7 |0 n. f
<P><FONT color=#0000ff>#include <STDLIB.H>  ?% k. o; f3 A5 G
#include <STDIO.H>
/ i/ J( {$ [+ Z9 l; t& n% j#include <STRING.H></FONT></P>
2 Z5 j2 m6 B# o+ f- N<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
: ]9 p' _% q9 m) ?2 Z) e5 wchar target[15]; </FONT></P>
- L/ t4 c: J+ e, G<P><FONT color=#0000ff>int main(void) 3 X4 S% _4 A% j: s
{
1 C  [. ^3 U* {; r6 l7 u; I0 ?swab(source, target, strlen(source)); , q$ P: j- x5 [! y' q+ s
printf("This is target: %s\n", target);
' b! N- W! y; G/ `4 Ureturn 0; 8 N* H( o$ V! \# R% c0 B, y* i
}
* @8 p9 z0 Q. [1 p  O3 ~. `  r3 ^</FONT>
0 Z5 Y3 s0 ~% v+ G8 D- K6 B( Z5 A# F5 B. A
</P>" B: w5 r8 R, z6 \# e
<P><FONT color=#ff0000>函数名: system </FONT>" ]; n/ s% E+ _
功 能: 发出一个DOS命令 + }, I9 @0 S0 K9 Y% N$ r
用 法: int system(char *command); 1 T6 e; D: O) X  f1 @7 \5 M
程序例: </P>( Q' ?& t# n# ~% G  _
<P><FONT color=#0000ff>#include <STDLIB.H>- @- i3 `  ^" D
#include <STDIO.H></FONT></P>8 ?7 z: D& ]+ \' u
<P><FONT color=#0000ff>int main(void) # f  l$ ^" @7 F. a- s) A0 j
{
) L9 T$ o9 w8 |( A8 y! Nprintf("About to spawn command.com and run a DOS command\n"); , {4 S3 d% a, H% U
system("dir");
2 t+ v/ D6 u' g+ Areturn 0; # V8 h" V: d' w7 q
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 13:42 , Processed in 0.542549 second(s), 52 queries .

回顶部