QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>
7 t) W7 y, W' i+ T功 能: 改变数据段空间位置
) u, X- G) J9 X/ s8 d. Z/ }  S5 F用 法: char *sbrk(int incr); # M' U, b2 N6 ^, \& C+ Q, o$ t
程序例: </P>
7 a7 {9 E( \' C+ }5 n<><FONT color=#0000ff>#include <STDIO.H>7 k4 z' a5 @: x, g0 @
#include <ALLOC.H></FONT></P>" ?) ?& J& Y$ ^, S3 T5 ]
<><FONT color=#0000ff>int main(void)
3 _! W  L5 V/ m$ n' B( J0 N{
0 J% P  i% m0 W/ B+ L6 |1 n  Fprintf("Changing allocation with sbrk()\n");
9 j- V, N. T1 ~7 p3 ?printf("Before sbrk() call: %lu bytes free\n",
( J/ u/ N2 N+ v  h; V+ X(unsigned long) coreleft());
; y0 m1 i( c- [/ W" hsbrk(1000); 5 c3 Y0 i4 a% ?/ a, S$ e, h1 m# k0 u
printf(" After sbrk() call: %lu bytes free\n",
! f& {- I, O) c- m+ ]/ I$ b(unsigned long) coreleft()); ; n8 B% Z+ z* y3 e! T) G3 F
return 0;
2 i' w# n& y- r' {/ }  k0 K}
% _. x* ]7 [6 U8 Q" P# n9 l; c/ T% E* i; i- F. `4 \7 i
</FONT></P>& e/ }9 W' P) s% q3 t
<><FONT color=#ff0000>函数名: scanf </FONT>
8 g: ^; m4 x4 B2 x! ~功 能: 执行格式化输入 $ T6 H; {( V3 j9 C3 Z
用 法: int scanf(char *format[,argument,...]); % C& E* t, K* T8 S
程序例: </P>
) O( s) _; H* f2 b, G<><FONT color=#0000ff>#include <STDIO.H>
* k+ s4 j4 v2 r#include <CONIO.H></FONT></P>
" C* A* X9 }- D- D<><FONT color=#0000ff>int main(void)
$ v! H; p0 w9 I/ m! c( i; r8 O, D9 M{ ( z* Z2 H! T2 m7 }# P$ f
char label[20]; ( X- H2 |  U- ?* l( d: f
char name[20];   ^$ }) d0 h# y: S7 z6 G
int entries = 0; - R: }7 t" X1 T
int loop, age;
# C( x% Y, H" Y; R7 C" R! U$ Tdouble salary; </FONT></P>6 ~; T3 Q% Y: B! u' W
<><FONT color=#0000ff>struct Entry_struct
5 L4 v. a. W, U{ 3 ]1 ?2 S+ f+ ?( C9 F
char name[20];
4 B  B+ D0 f' H1 \int age;
9 G' X6 A8 B$ hfloat salary; 3 i& g9 G  S6 @* ]- d
} entry[20]; </FONT></P>) b# n; \! A4 a' q
<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */   n7 \7 W1 I- Y% i* Y
printf("\n\nPlease enter a label for the chart: ");
3 K1 {2 ~1 S3 c$ G' gscanf("%20s", label); 1 x' O( l/ v! A' C) a
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
! G/ V2 W, e" @! _1 E8 ^<><FONT color=#0000ff>/* Input number of entries as an integer */ 8 w) y! y9 O$ I: E1 `: d  t
printf("How many entries will there be? (less than 20) "); ! Z) K3 Z3 L3 Y( a7 x$ \: C
scanf("%d", &amp;entries);
5 Y$ c! N  H2 F9 E4 E7 g, \% Pfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>: Y0 C+ |$ y* K4 b3 X
<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
5 ~) W* Q& r# B" s) `for (loop=0;loop<ENTRIES;++LOOP) , P, {* d. g) Y& i9 K- R; O) h
{ : N: F. N  h2 P" L
printf("Entry %d\n", loop); ) z. y; T. [) o6 ]  D. e
printf(" Name : "); # L0 d5 ~9 O3 A! C. G
scanf("%[A-Za-z]", entry[loop].name);
9 x; e  j9 t1 n. Vfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
" B4 h2 @; I0 l<><FONT color=#0000ff>/* input an age as an integer */ 6 ]& |! i7 @$ J5 p: H
printf(" Age : "); 1 T, @, d. s2 k$ `+ s( Y( P9 a; p$ L
scanf("%d", &amp;entry[loop].age); $ V5 w5 u4 `2 c3 ~( K4 _2 \
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
" l8 `  _3 C( p/ n$ o9 S9 R<><FONT color=#0000ff>/* input a salary as a float */ 1 n  u8 b; x* r- f8 k+ g7 e; O
printf(" Salary : ");
# k9 W# e: \1 Z4 qscanf("%f", &amp;entry[loop].salary); $ j+ i4 `8 ?6 d) `& n6 I5 ?
fflush(stdin); /* flush the input stream in case of bad input */
. @% t% I3 F3 l4 M* ?} </FONT></P>
! @' v8 _5 ?: i( |<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
1 i: R, r& `# [% D' `5 nprintf("\nPlease enter your name, age and salary\n"); ) z" H: c% Z5 M# ^5 F6 B
scanf("%20s %d %lf", name, &amp;age, &amp;salary);
! O: q1 G/ @  u8 c6 N6 Y</FONT></P>. u! p2 T5 y! `/ V" u. t( |  B
<><FONT color=#0000ff>/* Print out the data that was input */ 2 Z: W; n3 c7 J& P  A
printf("\n\nTable %s\n",label);
. W5 F$ H' H$ Mprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
* [9 S0 Y6 |9 d" D' v- N3 fprintf("-----------------------------------------------------\n"); 9 q7 k, C) r7 P# ^+ ~; a- M( S( R
for (loop=0;loop<ENTRIES;++LOOP)
, E/ K: I, W3 X2 t  k& [& F printf("%4d | %-20s | %5d | %15.2lf\n",
0 N9 x1 M2 a( ^1 C) [loop + 1,
) a/ |- @( J2 C$ R2 t2 {- D8 N: \entry[loop].name,
( C1 V- i7 D3 I* b, e: A* ~* ~7 Bentry[loop].age, : s: a! a: i; ~2 Z- p6 ~% g
entry[loop].salary); 3 _: Q- M9 B4 b3 n
printf("-----------------------------------------------------\n"); # f) O+ S0 P/ V7 T" n
return 0; 0 d! e: a. A1 W7 r3 x! _
} 5 C% y, @) n  S4 P
</FONT>
" Z" }. w- N8 R+ z/ D% _6 z4 H! E, }</P>
; d4 @) x; a4 B* b; \<><FONT color=#ff0000>函数名: searchpath </FONT>
9 \2 p& i, y0 ~. ?) C" J; O9 D功 能: 搜索DOS路径
+ A9 T$ _5 E) q' [/ R9 }" ~用 法: char *searchpath(char *filename); 6 B8 I+ Q+ p  x. p1 _6 X# h
程序例: </P>% J6 G. X( l! o- e3 f' k% ^
<><FONT color=#0000ff>#include <STDIO.H>
+ ~) u, c5 s* U4 l1 Q#include <DIR.H></FONT></P>
6 s6 ?9 y$ Y: ~7 F<><FONT color=#0000ff>int main(void) * ^6 I5 I4 m  g+ Q4 b; t
{
- X7 {" @# r1 i6 ]$ vchar *p; </FONT></P>  R$ |( u- w" {8 _' q+ c& Y
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
  v" R# b% m1 x/ M% H" yto the path */ ' P6 H$ T1 {) f* l, X% {
p = searchpath("TLINK.EXE");
2 G9 o" E& _2 G% K9 @printf("Search for TLINK.EXE : %s\n", p); </FONT></P>
9 P. O/ ]! p9 }- ^. w7 g5 ?6 J<><FONT color=#0000ff>/* Looks for non-existent file */
, j9 N8 Y5 H$ H! n" yp = searchpath("NOTEXIST.FIL");
3 X' R* ~5 Z( }" U  S& o4 k" w! Hprintf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>9 x/ V& }" p( U6 m
<><FONT color=#0000ff>return 0; $ Y) B2 y1 h: q, {& s
} 9 k; D8 x3 `  h9 k! z

; p9 Y+ x# O$ |</FONT></P>1 S4 y/ t2 }6 w! i
<><FONT color=#ff0000>函数名: sector </FONT>
! a, j% V( `# A功 能: 画并填充椭圆扇区 ) a% |' f6 S: i' `4 g( c
用 法: void far sector(int x, int y, int stangle, int endangle);
5 T3 }7 ~& W6 |* J程序例: </P>
8 g3 z4 f* {" @0 @) P6 b<><FONT color=#0000ff>#include <GRAPHICS.H>
4 O% b# E7 J' K% s#include <STDLIB.H>
% f# }3 B* w$ k; a#include <STDIO.H>
) k! |+ P+ c5 {/ }#include <CONIO.H></FONT></P>1 ~! N: _! [- _% b9 m8 w
<><FONT color=#0000ff>int main(void)
, ?( n/ i( a, U! P4 {{ $ N  K5 v# E( ^2 n
/* request auto detection */
2 B3 t: t0 C& E' T8 Nint gdriver = DETECT, gmode, errorcode;
+ a4 u6 f3 ^7 i. r/ ]int midx, midy, i; 9 f# T- r1 N: [9 Z- p$ A
int stangle = 45, endangle = 135; + |2 R/ V4 m, v5 }6 U- `8 f$ _& i
int xrad = 100, yrad = 50; </FONT></P>
5 j7 D, U2 x' o4 A) n; j" ]  _# j<><FONT color=#0000ff>/* initialize graphics and local variables */
) S+ c+ v2 ^3 W  ?initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 v. l! k: r5 F+ x
<><FONT color=#0000ff>/* read result of initialization */
! |( w9 W4 O" a9 G: v+ herrorcode = graphresult();
, m, W4 @2 x- hif (errorcode != grOk) /* an error occurred */ ' B, P4 ~" M& Z+ B
{ ' z% H; A; o. G
printf("Graphics error: %s\n", grapherrormsg(errorcode));
/ s! F9 k" k7 c! j3 N3 Aprintf("ress any key to halt:");
  N5 U! w" i) l( |getch();
& L7 k; t8 A+ y& |4 F1 ^exit(1); /* terminate with an error code */ ) [: G9 |& s" {+ E
} </FONT></P>0 \: C" M, X2 n: R' h5 ]7 I4 [
<><FONT color=#0000ff>midx = getmaxx() / 2; % D& @) O0 s3 `2 H6 U. s9 z
midy = getmaxy() / 2; </FONT></P>% N0 D1 s) U- d1 w- S, t' ^
<><FONT color=#0000ff>/* loop through the fill patterns */
7 {, g. a3 X& M0 kfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 8 j9 a$ M( ?, g$ X, ]/ I
/* set the fill style */ 1 E. L3 X7 S; d! `
setfillstyle(i, getmaxcolor()); </FONT></P>
! ^) x( U) E: Q8 v" j<><FONT color=#0000ff>/* draw the sector slice */ / z- F$ f/ \4 ?& t" s% H+ Z' Z
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>$ m0 x& W( h& I" I
<><FONT color=#0000ff>getch(); 0 W% X8 c* N2 F, {* g2 Q/ F
} </FONT></P>. ?8 D% T7 y0 Q* j& v( t
<P><FONT color=#0000ff>/* clean up */ ; q, D4 q4 s/ N. |+ }
closegraph();
- S5 H4 p) L/ J- e9 C% }! treturn 0;
" u) D. |7 z) F6 {; B+ i6 A7 u( `2 M+ j1 a} , E; {/ F" k% i0 z4 K/ @
</FONT></P>2 ~, w" a( C+ E
<P><FONT color=#ff0000>函数名: segread </FONT>7 w+ Q8 h+ u) {# F; C
功 能: 读段寄存器值
1 N2 a, i* N! x9 E8 f) n用 法: void segread(struct SREGS *segtbl);
6 C0 c: @6 q9 G2 _程序例: </P>2 H& Q5 B" O  F% n) j) X
<P><FONT color=#0000ff>#include <STDIO.H>
" ^: W" C) K6 r2 U#include <DOS.H></FONT></P>
9 ]) c* R- l! [  H3 p9 p<P><FONT color=#0000ff>int main(void)
! ^! D2 p+ ^5 g$ G{ ( v; ?% ~" h2 x
struct SREGS segs; </FONT></P>4 K% q( Y, D8 l6 x3 K- T6 ], D" `2 H
<P><FONT color=#0000ff>segread(&amp;segs);
8 }! ?; a9 |6 W8 p9 }5 vprintf("Current segment register settings\n\n"); 7 h* W# L7 |; a; A# X3 l% g2 }
printf("CS: %X DS: %X\n", segs.cs, segs.ds);
! [% y, H' s; j. D( e- ^printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
$ }: R1 i8 @9 F9 _. }<P><FONT color=#0000ff>return 0; # m% o3 A9 X) H) I3 X3 L
} </FONT>. _( E  g4 s2 ]+ Z* O
# j3 E. t6 Y" o$ Y7 g7 A
</P>
7 ^. T$ U2 M* c# A; c<P><FONT color=#ff0000>函数名: setactivepage </FONT>
- ]; R. B5 T! Z! w1 }功 能: 设置图形输出活动页 $ f3 }0 E4 `& i& G8 H
用 法: void far setactivepage(int pagenum);
! F( [' H/ ^; {: Y  ^( U程序例: </P>$ J" m9 Z$ d% X1 ?# ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>
; N, s3 m& n. ?( `9 G#include <STDLIB.H>
6 q, R( {3 c( A: C' Y$ i. d#include <STDIO.H>
2 y6 ?/ @1 k. K8 F& L. m#include <CONIO.H></FONT></P>
2 V9 M5 Y' X# h4 F; o9 O9 y) j- H<P><FONT color=#0000ff>int main(void) 0 ~  Z: l- v* s9 B2 g
{
6 n3 w: f, ~% k; z/* select a driver and mode that supports */
2 Z! _, o+ a0 Y3 m( e/* multiple pages. */
8 i4 N% J3 X; A$ B9 oint gdriver = EGA, gmode = EGAHI, errorcode;
5 W+ c9 D. m1 ^* Z9 Qint x, y, ht; </FONT></P>, W+ w. L- G+ `: D8 H$ u' X$ a
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' C4 M5 C/ c. x. D) F& ^
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ y2 c' C6 d( z# x<P><FONT color=#0000ff>/* read result of initialization */
  I7 F7 B5 F+ @$ g; y8 Perrorcode = graphresult();   R% ^, o/ E9 `4 y5 `
if (errorcode != grOk) /* an error occurred */
  y# _- w6 j4 e* }6 p{
& d& `+ y- _! W3 P; P' Sprintf("Graphics error: %s\n", grapherrormsg(errorcode));
7 `! j2 w5 R% D( q/ fprintf("Press any key to halt:"); # N  P2 I: k4 m$ |9 u" [9 k
getch();
$ r' ~6 z* Y7 o0 nexit(1); /* terminate with an error code */
8 Z! X- L' \# h7 I% U4 ^} </FONT></P>& U% x; O6 Q) E  B0 u! p3 ~
<P><FONT color=#0000ff>x = getmaxx() / 2; 0 T' g: g8 m5 ^  |/ d. }+ C$ i
y = getmaxy() / 2; 6 I3 n# i0 e5 x8 t. |: u9 T
ht = textheight("W"); </FONT></P>, C4 [3 n+ D$ r) {5 ]' [
<P><FONT color=#0000ff>/* select the off screen page for drawing */
" a1 R  v* ~, s3 W  C2 Wsetactivepage(1); </FONT></P>- ], s( }  e- B1 B8 m9 ]7 m
<P><FONT color=#0000ff>/* draw a line on page #1 */
# C( S) u% }8 M1 v4 pline(0, 0, getmaxx(), getmaxy()); </FONT></P>7 `# ^2 y" I5 _1 ]( E; j: g7 ?
<P><FONT color=#0000ff>/* output a message on page #1 */
# v# B4 A6 q' J6 _settextjustify(CENTER_TEXT, CENTER_TEXT);
' i  }' R" q2 X$ J3 j2 H& ^outtextxy(x, y, "This is page #1:");
0 \- W- [0 v$ I) A& W- h8 n7 kouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>3 u7 z5 P2 {8 |0 r2 ~9 \1 G
<P><FONT color=#0000ff>/* select drawing to page #0 */ $ @$ C2 R  |  K. a
setactivepage(0); </FONT></P>6 `2 \6 V2 R6 k. q# W% g
<P><FONT color=#0000ff>/* output a message on page #0 */
% B7 y9 N% V: ?; d" j1 Gouttextxy(x, y, "This is page #0."); 6 Z: G/ R9 j( [0 w( K2 ^
outtextxy(x, y+ht, "Press any key to view page #1:"); . ~8 `* _# w# V7 @; B  }9 T5 N9 R
getch(); </FONT></P>
" t0 A; ?- ~3 A5 Z) R* u& ]$ v<P><FONT color=#0000ff>/* select page #1 as the visible page */
/ s+ o6 J0 |4 [# tsetvisualpage(1); </FONT></P>
9 a  D9 @2 S1 u5 F  H<P><FONT color=#0000ff>/* clean up */ 2 T; [, k- m0 P/ A/ q
getch(); 5 Q- R# ^0 d3 ^! G( G' L
closegraph();
0 a7 i' k/ {2 c" Lreturn 0;
$ s: ]$ s/ R: X} + C1 g1 ?; U4 S/ x  S& c" w
</FONT>
. ?0 \, O- S$ s</P>/ u1 M% J' v' n% s+ R# a
<P><FONT color=#ff0000>函数名: setallpallette </FONT>
- K7 E0 e. |7 U6 t功 能: 按指定方式改变所有的调色板颜色 3 O* \1 l3 `& t4 i, ~6 a
用 法: void far setallpallette(struct palette, far *pallette);
0 w, B" f" [- M) y程序例: </P>
! f2 K8 T& O9 K<P><FONT color=#0000ff>#include <GRAPHICS.H>
& r/ X: Y- @, Y9 @#include <STDLIB.H>
. }# j4 u5 w, Y7 q: T#include <STDIO.H>9 M1 _# L! B9 V# O
#include <CONIO.H></FONT></P>
3 y  i6 v/ D6 `2 I( k<P><FONT color=#0000ff>int main(void) / Y3 p# |( [  X6 K4 ~
{ ! p, m5 o3 e+ d3 f
/* request auto detection */
8 C" j) ?5 A* q) D! @int gdriver = DETECT, gmode, errorcode; 3 K# a+ o; l8 _& }; a
struct palettetype pal; 6 U1 `$ `: A. h% ^/ M) }
int color, maxcolor, ht; % a: t! C" d0 @1 ^* u
int y = 10; ; J7 r  K7 J6 D4 v
char msg[80]; </FONT></P>5 V5 S8 d+ Z, I- [+ l; P
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 7 b9 i# d! k1 ]5 ^  e" d8 ?2 c2 y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>% c* |6 @6 X! [' g6 B2 V2 C8 _
<P><FONT color=#0000ff>/* read result of initialization */ ' Q, m8 `1 v. X, j" y9 A  X
errorcode = graphresult(); 1 N0 ]. \% f7 P! l
if (errorcode != grOk) /* an error occurred */
/ j4 m2 l' x8 D% y7 A+ L1 e{
2 T  N5 H) R) ?% ]: X0 W' a% cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 v3 O) q. I% i6 d# q
printf("Press any key to halt:");
) ~, t6 u: v/ a- X  l2 c. C6 c' A! U+ lgetch();
, R! G1 `! F- B; z) _# @# e* Texit(1); /* terminate with an error code */
4 {: }; @  c% W& q6 z# a4 S4 t} </FONT></P>
8 v9 T$ B- S5 i<P><FONT color=#0000ff>maxcolor = getmaxcolor();
' n" A: p" l& x* @7 D: Kht = 2 * textheight("W"); </FONT></P>2 t$ r8 Q& l5 Z3 N+ G* `
<P><FONT color=#0000ff>/* grab a copy of the palette */ , [, {7 T# i  g5 k5 Z
getpalette(&amp;pal); </FONT></P>
; h/ H; z: Z3 W/ `* m2 C  d; Y<P><FONT color=#0000ff>/* display the default palette colors */
1 q6 Y) s* F; w, Ofor (color=1; color&lt;=maxcolor; color++) 3 }9 c* {+ [& P
{ 0 J: p6 o: t  J$ Q5 d4 f1 ?/ K
setcolor(color); : C- u1 X, D- h* O
sprintf(msg, "Color: %d", color);
# e' }9 D0 H6 R( r/ C, }outtextxy(1, y, msg); : w% F) R& h8 s& T; y
y += ht;
+ W, [& J3 P; j1 o6 j} </FONT></P>
; j- \: B3 g! w<P><FONT color=#0000ff>/* wait for a key */
, A8 ^) |6 G* [, {1 T! O9 ~4 [getch(); </FONT></P>
5 t3 z& S, g. W5 K<P><FONT color=#0000ff>/* black out the colors one by one */ , t  V* ~2 R( U5 ^8 q8 g
for (color=1; color&lt;=maxcolor; color++) , ]2 a( K+ E$ l: p
{ 4 T4 T8 T. A1 E
setpalette(color, BLACK);
' {: u! ?: ^( g/ l1 h+ X/ ngetch();
7 C: ~) A8 S( k0 E0 G2 |2 ^9 U6 A0 k} </FONT></P>
% f& K  I/ t5 ]: w( u; ]  U<P><FONT color=#0000ff>/* restore the palette colors */
3 _+ W: f5 \7 _8 r( \; |+ s9 L6 g$ Vsetallpalette(&amp;pal); </FONT></P>
* y+ [" G' E+ u! P<P><FONT color=#0000ff>/* clean up */
1 ~8 k: y* M" `getch(); & }/ _0 b6 H( b4 z' k8 O
closegraph(); 1 L* f+ _+ N' m9 p  ^3 @: r
return 0;
6 t; D5 l7 A3 W% I}
  p5 [9 }( y0 [' I7 @3 U( G
- u+ K* s5 ]& `, r" |5 g</FONT></P>4 N. M: R: l& N. @: u$ }
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>6 J! S8 ^* R' M4 Z$ I9 F0 L
功 能: 设置图形纵横比
0 v# M0 M5 y- v* `  R  K用 法: void far setaspectratio(int xasp, int yasp);
/ H( g2 R( ~! T9 x# J程序例: </P>
" c6 t6 D6 e2 D8 ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
; W. B: C1 N" i/ [: F#include <STDLIB.H>
$ J* {9 H: k& t+ R' U4 J) h7 I, o& ?#include <STDIO.H>
1 `9 Y7 ?# i  v1 M! y8 V#include <CONIO.H></FONT></P>; U( b: e6 m$ O7 p+ ]
<P><FONT color=#0000ff>int main(void) * M8 W) e6 l+ I6 d, o
{
) Y; @8 F8 b( ], i' M1 f/* request auto detection */
2 W. p  _2 O  r5 w9 |. ^int gdriver = DETECT, gmode, errorcode; 7 s& O* ~2 Q. V  O& q" }+ o
int xasp, yasp, midx, midy; </FONT></P>& G# P2 E) x# e" m! L8 s
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ) X, |; I% y) C4 c
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>; |5 A, h/ q% F. |2 U  z5 q
<P><FONT color=#0000ff>/* read result of initialization */ 4 h- ^3 w! w0 v; \3 j
errorcode = graphresult();
& }# t1 z$ y6 Z! y: cif (errorcode != grOk) /* an error occurred */ # L% A  F) \" g6 g
{
+ X3 |( w9 ]; E6 {0 {  nprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ! E' V; o' g  a: r
printf("Press any key to halt:"); - C5 |! `; X$ V
getch(); $ g- B9 `6 T7 t
exit(1); /* terminate with an error code */
6 t; n+ o% l/ Y  Z} </FONT></P>
9 f* t! s3 x# _+ `4 ?<P><FONT color=#0000ff>midx = getmaxx() / 2; 4 Q8 k/ ~% a$ \
midy = getmaxy() / 2; 7 `, r& I" x% m
setcolor(getmaxcolor()); </FONT></P>' c: a% b$ _  v+ M0 _
<P><FONT color=#0000ff>/* get current aspect ratio settings */ % ?1 w( U7 \+ d
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
/ ^. p4 G  F0 K1 T/ B/ _( k<P><FONT color=#0000ff>/* draw normal circle */ - A# w1 p+ ?) A: q/ O* ?* H2 S
circle(midx, midy, 100);
& ]/ z( }, o. P( V  ygetch(); </FONT></P>/ `; c+ G( O& ?# J/ p5 p
<P><FONT color=#0000ff>/* claer the screen */
' w$ F. k2 a8 S! c/ _. |4 acleardevice(); </FONT></P>
1 F% S: \/ p* f<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ 8 _: Z# {5 h9 d, g6 X- H
setaspectratio(xasp/2, yasp);
% B$ ~8 {6 J0 Z8 V( tcircle(midx, midy, 100); 1 a( Z3 u9 F+ l. X6 Z3 Z
getch(); </FONT></P>2 {& e# G; w; t. x$ Y, A4 y
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ 9 J' e# A/ f. d+ x( }
cleardevice(); * G: X8 U" e+ b7 R# X! f% x
setaspectratio(xasp, yasp/2); ( ]6 O% x' D( }1 J  }( g; N5 I$ j
circle(midx, midy, 100); </FONT></P>. m& K9 t) Z! x. U2 q$ q5 ]5 C
<P><FONT color=#0000ff>/* clean up */
% c/ i" K0 w2 _# b5 ^1 }getch();
, r5 v; |) D4 ]; R4 hclosegraph();
2 O' F: d' F1 q( Ereturn 0;
1 a5 G7 D; ^: K+ ]; ~2 e0 [: z}
4 T5 r9 d9 ?0 T9 J</FONT>
, _/ I; y5 t9 q) f# n0 @+ N</P>
7 J% P9 I3 u# M- \<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
  {: V/ x9 g) V& }2 l1 L' s% t功 能: 用调色板设置当前背景颜色
4 v+ }& N# `! Y% D/ b; t用 法: void far setbkcolor(int color);
$ ?' S) o! l: b% y程序例: </P>/ _0 `- ^, M0 u0 J3 q% |
<P><FONT color=#0000ff>#include <GRAPHICS.H>  q+ X( g" ~2 h, R: b
#include <STDLIB.H>
: w+ Z) z8 e4 D" ~5 x+ M#include <STDIO.H>
" g/ k& j) c1 e8 t" v$ a5 b6 K#include <CONIO.H></FONT></P>
, H8 ~! w1 g: u5 M" ?" P* S<P><FONT color=#0000ff>int main(void) . O# R; y0 J: j0 B- [
{ 2 X9 n2 e  |0 |
/* select a driver and mode that supports */ - q: X# x1 B3 [% H5 i' H3 ?' G' V
/* multiple background colors. */ " d1 O1 c# S* a& L8 ]+ M+ X- N
int gdriver = EGA, gmode = EGAHI, errorcode;
7 V3 v$ B7 v- C% Oint bkcol, maxcolor, x, y;
/ i9 }; w$ E3 K, }6 [char msg[80]; </FONT></P>
  C: S/ v* A8 P# x5 P; ~<P><FONT color=#0000ff>/* initialize graphics and local variables */
) h+ z5 }9 j. \initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( J2 C" q/ i" l7 s<P><FONT color=#0000ff>/* read result of initialization */ & Z/ M7 \% b7 U) }3 ]" O
errorcode = graphresult();
* ^9 ?1 c3 Q9 g% H( d% k6 E& w4 Zif (errorcode != grOk) /* an error occurred */
6 k$ r! R; N7 ]7 e{
1 A. g9 Y. p: Q+ ?8 yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' l* h! h9 p' ]: Q  J2 V) n( Y% g
printf("Press any key to halt:");
1 `) F! J7 |6 p. Q" n) `getch(); ) z+ o& {2 H$ k$ o
exit(1); /* terminate with an error code */ 6 J/ _- m1 A. ~7 y2 c& a6 H# E
} </FONT></P>- |" q( @* O- @3 }3 T
<P><FONT color=#0000ff>/* maximum color index supported */ " F# `5 ?8 H& J9 p1 @( f
maxcolor = getmaxcolor(); </FONT></P>$ m% B( z$ f% j0 P
<P><FONT color=#0000ff>/* for centering text messages */
/ h4 c. s$ i! j5 s  w( Z% P8 psettextjustify(CENTER_TEXT, CENTER_TEXT); - w1 O7 g! r1 s1 J$ e6 ~" z8 N& d, [
x = getmaxx() / 2;
; [9 ~; d( K, B3 g$ l% Vy = getmaxy() / 2; </FONT></P>
7 R# a; |& ?; g- ]. s( b/ e, ?<P><FONT color=#0000ff>/* loop through the available colors */ 7 k# C6 Y) p; R. D3 A4 `/ c* b4 |
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) $ m& T- R; w, z) S' r1 j$ @
{ 4 A  k1 `, S# ?: N0 Z# E
/* clear the screen */   B. M) J, t$ q8 O: t
cleardevice(); </FONT></P>' {5 Q& L& `. D1 a
<P><FONT color=#0000ff>/* select a new background color */ 5 u* X4 L& w0 ^  [8 [& L- e
setbkcolor(bkcol); </FONT></P>
! ?) E) u% A' \: h8 [+ x7 S<P><FONT color=#0000ff>/* output a messsage */
( ]* B7 ?% ?1 |& Q; Dif (bkcol == WHITE)
- K  _* d; y8 Tsetcolor(EGA_BLUE);
; |, D1 O& P& G, w% F6 Jsprintf(msg, "Background color: %d", bkcol); * `0 P) d5 y0 |, ?4 j0 N
outtextxy(x, y, msg);
6 D' f+ u' `' U: ]* @" Z" Ugetch(); ) I7 f& G9 \$ M
} </FONT></P>+ U: T. r! @1 C  U& \" B9 K' C
<P><FONT color=#0000ff>/* clean up */ . h' S6 {( x  u5 I7 s$ N5 g
closegraph(); ' s9 ?' |$ p: s) j2 X3 w, l7 q
return 0; ! x4 Z/ Y  W! E( T9 K& j9 {
} </FONT>  `7 r  ^+ N' t# k
7 K' v  s4 {. i7 ]& h
</P>
; v& v+ {4 w( x# E6 |<P><FONT color=#ff0000>函数名: setblock </FONT>
) w: c, v+ ~' m: n" o4 R) [功 能: 修改先前已分配的DOS存储段大小 + C& Q! J- f8 {8 F8 j# J) U& L
用 法: int setblock(int seg, int newsize); & ~0 n4 ]0 C5 }# u$ M4 [1 h  B
程序例: </P>
7 }8 h/ S; n+ i2 r7 ?6 w<P><FONT color=#0000ff>#include <DOS.H>
/ D# o, X$ Q, }1 f9 k6 s) G#include <ALLOC.H>% X( p8 u! ?+ U, l
#include <STDIO.H>6 \$ i! m0 t  h/ s) e; G/ ~
#include <STDLIB.H></FONT></P>
- b$ k. G! I: d2 M# H' t<P><FONT color=#0000ff>int main(void)
5 Q) m  \& J. P; H/ v1 a/ s" x{ : V, C5 I/ \! i& T
unsigned int size, segp;
  X3 @6 m2 M" gint stat; </FONT></P>0 }9 d2 u2 z0 r9 Y/ k; K
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */ . J0 ?8 \9 e5 T" T
stat = allocmem(size, &amp;segp); , n; J2 j: P  ^7 r
if (stat == -1)
" Q3 ?7 R1 _8 E' d$ rprintf("Allocated memory at segment: %X\n", segp); , Z% \" A+ Q9 V, G/ O0 `" R
else
: a: d) K/ W9 L9 D0 N& S; A{ + s" o- i7 T, H- m
printf("Failed: maximum number of paragraphs available is %d\n", - l  @9 \% a7 N( W$ E9 S+ l
stat);
) |0 X9 x  c+ x3 V7 _+ M- Wexit(1); 2 r- K2 |- f/ P5 L, u
} </FONT></P>, s- I9 [3 @5 g0 n- S8 p
<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
, ~1 A! z7 u3 U, x- ]9 R. t, `if (stat == -1) & A+ }5 L4 w6 o" L7 `' Q9 E
printf("Expanded memory block at segment: %X\n", segp);
* Q/ U7 f' ^: {' a+ Ielse
1 ], C$ R& @$ ^" d7 W* c/ m  kprintf("Failed: maximum number of paragraphs available is %d\n",
3 W% R4 m6 j- S) w8 U: A* ^* Dstat); </FONT></P>
' h- ~( ?& m/ s1 c# k<P><FONT color=#0000ff>freemem(segp); </FONT></P>' W' T% y) q8 I! n4 f1 B
<P><FONT color=#0000ff>return 0; / z& {( b, Z9 l- T! c- ~" h' b
} 3 ^: z$ S5 H+ u/ Z
</FONT>% ?- a; _; R/ B& r9 N. D
</P>, n2 k/ @7 r, t  G
<P><FONT color=#ff0000>函数名: setbuf </FONT>
8 E' N% j. P, ~( X6 ^功 能: 把缓冲区与流相联 , P" U8 L  V$ I+ _
用 法: void setbuf(FILE *steam, char *buf); $ n+ `* x* G2 ?, w' Z2 [0 h8 {# A. r
程序例: </P>
4 T, D* l+ Z% G3 s% Z* f<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>( I% k& H: F4 D, X- r( U
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ - K& g' q4 |8 l# f  M0 e
char outbuf[BUFSIZ]; </FONT></P>4 m3 Y6 b- }8 G! G+ \4 [5 C
<P><FONT color=#0000ff>int main(void) : Q# ^- P" K$ F' ?2 ]/ N! q
{
7 W$ q& t# t6 u9 V2 R/* attach a buffer to the standard output stream */
) }4 _5 D' E1 k+ ~setbuf(stdout, outbuf); </FONT></P>' c( v1 J( F0 }; o
<P><FONT color=#0000ff>/* put some characters into the buffer */
% d1 C9 u. z1 O9 z% {! Kputs("This is a test of buffered output.\n\n"); # D5 ?! s+ R3 j7 A: b! o4 B/ p
puts("This output will go into outbuf\n"); / [! E( T$ g) F6 t6 L( u
puts("and won't appear until the buffer\n");
: j1 I/ C, ~6 J* Eputs("fills up or we flush the stream.\n"); </FONT></P>
6 \6 q' X- s; C<P><FONT color=#0000ff>/* flush the output buffer */
3 j. I0 p' Z* yfflush(stdout); </FONT></P>
# y2 m$ @& y6 w8 I0 i; L( |0 V1 R<P><FONT color=#0000ff>return 0; 5 ^' S* s* m0 O) G8 X
}
$ k4 G% L% I; }/ p</FONT>: G2 h% W& S* y& Q
</P>
" \% e; u# c# V/ L<P><FONT color=#ff0000>函数名: setcbrk</FONT>
% I4 v6 V- o. y0 J  P: M0 p+ d功 能: 设置Control-break 5 l5 h/ Z5 l8 ^- N
用 法: int setcbrk(int value);
- s+ R' l% c" `" [/ |- n. r9 O程序例: </P>
' H. r- M7 R% Z8 ~0 Q, Q3 Q<P><FONT color=#0000ff>#include <DOS.H>
0 _7 H  O7 K0 S% h0 ^3 P, {$ t' Z#include <CONIO.H>
0 [! r5 {  ~- H. F#include <STDIO.H></FONT></P>* P6 Y1 I# H, y$ Y1 y' P* `
<P><FONT color=#0000ff>int main(void)
: V5 k: j2 X: L5 Y" k2 Y& Z{ $ y, ^2 \3 n# ]4 t! o. t2 K* I
int break_flag; </FONT></P>) L0 x6 e: |% r6 ]/ o
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n"); & r0 Z0 X! R# z" _' _
printf("Enter 1 to turn control break on\n"); </FONT></P>3 V* e. V+ W- g
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>6 o$ X8 M$ d9 y0 x% E+ D% N6 m
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
( j6 @9 d0 l' S3 N% j' h8 d<P><FONT color=#0000ff>if (getcbrk())
& Q! }' L8 v3 V- P4 c6 Jprintf("Cntrl-brk flag is on\n");
; }' X0 b# k3 ~. A0 Uelse
* G& ~& Y. |0 m: z" j! v7 J4 Mprintf("Cntrl-brk flag is off\n");
* r! U' q1 t8 A7 B9 _return 0; : K7 [; T: f9 s: V$ v# e
} 2 P( y6 ]  u( ^! n$ d/ }+ D
# d2 s+ u6 W9 l' l2 Y0 m$ P! N% `
</FONT>5 a5 o. C1 j7 @
</P>& X; F, \) i4 x& ?- E3 F# d
<P><FONT color=#ff0000>函数名: setcolor</FONT> ( @7 U; r; n) t" w- k- `3 x: G  g; ]
功 能: 设置当前画线颜色 8 \" d# l( K( v: u
用 法: void far setcolor(int color); & P3 ^/ f; c1 t' q7 C
程序例: </P>
2 r/ M. a9 I" |* M* q' p9 o2 L<P><FONT color=#0000ff>#include <GRAPHICS.H>
, ?0 H1 M" ?0 Q#include <STDLIB.H>
* ?6 L4 t3 u) X5 i; J9 a#include <STDIO.H>
0 `- W7 r3 B8 k8 {% C0 }7 r#include <CONIO.H></FONT></P>9 i! w6 k) t' B7 i( y
<P><FONT color=#0000ff>int main(void) ; a  i: i. m9 m$ j4 o: g
{
% P! A# b1 X! |$ \  ?/* select a driver and mode that supports */ * ]  I' W9 R4 `, y3 R; r' c
/* multiple drawing colors. */ ( W0 _; v# I/ d( }
int gdriver = EGA, gmode = EGAHI, errorcode; 4 }: |3 B" b# W2 }  O, E
int color, maxcolor, x, y; 1 w* z2 n4 j7 Y7 V9 E; ~$ {
char msg[80]; </FONT></P>
. K5 b% L% p* G+ f1 x& n0 d<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( [+ t% w9 ~7 U
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
& X  Q% w/ g. \; j+ q<P><FONT color=#0000ff>/* read result of initialization */ ) N1 W' @$ F) B; @  c
errorcode = graphresult();   X8 f; ^% o$ ]" U2 ^  ?
if (errorcode != grOk) /* an error occurred */ 4 z9 C- I& A# F# x+ C( y
{ . D. t! n% n* \4 K& \5 F
printf("Graphics error: %s\n", grapherrormsg(errorcode)); & F6 y9 ~6 t- r$ V
printf("Press any key to halt:");
+ i- `8 S1 ^& Y4 k& lgetch();
4 r3 R7 J" V$ iexit(1); /* terminate with an error code */
+ X) G5 a) K& ?) C4 C4 l} </FONT></P>2 }  |7 q- h4 r' h0 G6 d
<P><FONT color=#0000ff>/* maximum color index supported */ * U6 U1 P8 l( K
maxcolor = getmaxcolor(); </FONT></P>
3 z5 A9 h% }8 W$ g* D<P><FONT color=#0000ff>/* for centering text messages */
: {- p$ s" F6 p! n- z) n& ?# n- }: psettextjustify(CENTER_TEXT, CENTER_TEXT); # Z) J' X' k% a1 R$ R7 D, k- w& F
x = getmaxx() / 2;
9 b+ P# Y& ]$ A  {6 fy = getmaxy() / 2; </FONT></P>
! Z3 u' f. U' B! G% A. k; ^<P><FONT color=#0000ff>/* loop through the available colors */   ]) E* X/ A- `0 Y3 t6 `  O
for (color=1; color&lt;=maxcolor; color++) / u% {! u* U7 l* y' d- s) C
{
7 {7 n2 a2 e! {9 H6 @% i/* clear the screen */
8 z3 ?/ L% M1 S' lcleardevice(); </FONT></P>
. k' ^+ y, C+ t4 J& C2 L/ E<P><FONT color=#0000ff>/* select a new background color */
* n' Q9 v( K1 Q# zsetcolor(color); </FONT></P>
+ P3 U% m" {) _. }<P><FONT color=#0000ff>/* output a messsage */ . q1 ~! S* X- X* {1 N8 q, E
sprintf(msg, "Color: %d", color);
5 k+ E: C3 {$ q; oouttextxy(x, y, msg); 8 [: Q3 W( I1 i% @: s  X0 b2 H% |
getch(); " A: K. d4 K/ F; W) f
} </FONT></P>: c* s# V! F% H! A& t" o
<P><FONT color=#0000ff>/* clean up */ 7 ?2 b1 `! n( p& W  U- ~
closegraph(); ! M7 v  e  ~/ x: n& i: U
return 0; 8 i( |' ?0 k$ n  }7 `3 N& X
}
0 C# |* K5 y: [( @</FONT>1 M, t& }3 B' I$ J. I' ^
</P>% z( A+ h0 w5 ?6 F) v( W9 ^" J: U
<P><FONT color=#ff0000>函数名: setdate </FONT>
5 D. S* t) V; l! c9 l) k功 能: 设置DOS日期
: ]/ t- D/ J; |; |$ A0 l4 V用 法: void setdate(struct date *dateblk);
- o9 v4 u: ]% O" g* T$ ~8 A程序例: </P>& J( g/ V% `- }/ E# \* p
<P><FONT color=#0000ff>#include <STDIO.H>' h0 j5 r" Y( Y! c
#include <PROCESS.H>
$ O$ Z' v: m9 ^; p) V# y#include <DOS.H></FONT></P>
! v; c' {* s. J<P><FONT color=#0000ff>int main(void) 2 H+ b) M; x$ P! [7 r4 f3 B' s
{ % ?7 s$ D. }, @
struct date reset; . d8 B0 D! b( d
struct date save_date; </FONT></P>
( p8 c& x8 T9 S3 z: [$ W<P><FONT color=#0000ff>getdate(&amp;save_date); 7 P/ v8 S  {$ I8 r6 C
printf("Original date:\n"); 3 X0 Y- v+ S+ D! _1 |
system("date"); </FONT></P>
6 d$ U# I+ r! I" V- p6 a<P><FONT color=#0000ff>reset.da_year = 2001;
) S2 W% p. C5 D; F. Q- Xreset.da_day = 1;
  E0 U6 p( }1 E: Z7 ?; oreset.da_mon = 1;
( {0 N1 [. A+ v, F6 y% vsetdate(&amp;reset); </FONT></P>) K$ t0 E) ^% h+ p; i) f
<P><FONT color=#0000ff>printf("Date after setting:\n"); / }- r7 \5 M# r  g( S' h1 I2 _
system("date"); </FONT></P>' h& B% N: ~. X! K* S
<P><FONT color=#0000ff>setdate(&amp;save_date); 9 s9 J6 {4 M4 v5 }$ {
printf("Back to original date:\n"); 3 k( A+ }( j, Y  C- n9 Q+ u( m, L
system("date"); </FONT></P>
+ r- Q. H1 A* @  `# o) @8 w<P><FONT color=#0000ff>return 0;
# a- Z1 i& ?+ A. ?' ~$ G} , G! X( v3 I1 N4 E! x) ]
</FONT>  j* v2 r$ m; d: X# d% l
</P>; S0 C% Z" z5 R, w; c8 m
<P><FONT color=#ff0000>函数名: setdisk </FONT>
3 I9 o$ n+ C) y功 能: 设置当前磁盘驱动器 1 S: G- X, A8 M2 e. h& _. z" @
用 法: int setdisk(int drive);
; b' ]3 i) T! V, w) {程序例: </P>
$ v+ F: v5 \( i& K8 }) {+ o+ W: P  E<P><FONT color=#0000ff>#include <STDIO.H>" U: v' v, i6 r3 G4 R* L
#include <DIR.H></FONT></P>
- w- p. s, ~/ ?4 P# N$ f0 G0 f<P><FONT color=#0000ff>int main(void)   U8 m' d; e  N& y* @0 I* U
{ 6 S2 M8 x" u8 c0 d4 n2 z8 M/ Y: [& T
int save, disk, disks; </FONT></P>; I% N. f1 |  @( E1 Y" e
<P><FONT color=#0000ff>/* save original drive */ . [2 I6 Z1 Q, ?: g; ]$ F8 [
save = getdisk(); </FONT></P>
: k1 G( D/ b% K( o- l<P><FONT color=#0000ff>/* print number of logic drives */
+ b4 g( q. p6 B0 ddisks = setdisk(save); 2 r2 [( E) w( @6 v& r) M, n" P
printf("%d logical drives on the system\n\n", disks); </FONT></P>  r& b" U8 P! \: P
<P><FONT color=#0000ff>/* print the drive letters available */ " `7 r4 v( ]) G$ g0 i0 \
printf("Available drives:\n");
9 g  t9 Q, g& zfor (disk = 0;disk &lt; 26;++disk)
  K* x( Y6 N& m4 ?0 G% ?, ]{
7 r) Z. Q, u& _8 i; Z* f$ i, S- Nsetdisk(disk);
( z, w( c8 R$ t2 M. nif (disk == getdisk())
6 Q. @1 _& H% ?1 M0 k( Rprintf("%c: drive is available\n", disk + 'a'); - W  S" N0 L: j" ]5 h
} $ M) d6 }' F4 a# X! U
setdisk(save); </FONT></P>
6 @+ l1 u8 g" {- n. U<P><FONT color=#0000ff>return 0;
! u) f9 y. O+ Q* j} </FONT>( G" s6 a: z) m0 X& Y- ~" Y
2 z1 U! o2 W& _& P/ [# |: p
</P>0 V% J& D* O5 A! |) a. B1 H- p
<P><FONT color=#ff0000>函数名: setdta </FONT>
  Z% E! G9 m6 a- D6 h功 能: 设置磁盘传输区地址
$ j/ i- K) @, Q; `; k% ?用 法: void setdta(char far *dta); 5 j. z+ T& ^6 _0 E6 h8 \2 T
程序例: </P>8 U& F4 T. @- }
<P><FONT color=#0000ff>#include <PROCESS.H>" d, B/ R0 |+ W3 @: t
#include <STRING.H>
3 i( U7 l' }( I, ~0 Z& a5 `' B: H#include <STDIO.H>
1 Y: V. C* [" K7 p#include <DOS.H></FONT></P>' G8 ^( @9 E5 t% A' q
<P><FONT color=#0000ff>int main(void)
9 L: d+ p- _& j/ p( y' a! O{ 4 m+ F) A$ w0 P$ a; _8 X
char line[80], far *save_dta; 4 @7 }8 e, t/ `. Q4 }) {
char buffer[256] = "SETDTA test!";
4 Y) {9 M( T. [2 W1 |1 f" Nstruct fcb blk;   E5 {# h* }" l8 c3 P6 x
int result; </FONT></P>
1 ?3 Y2 `  k% D! N  D. G- W5 g5 T<P><FONT color=#0000ff>/* get new file name from user */
/ b$ V; Z6 w: H3 u' C# R. |printf("Enter a file name to create:"); / N% C! d% W: q! c6 y
gets(line); </FONT></P>, ^( P9 n" ]  u$ G& m9 F
<P><FONT color=#0000ff>/* parse the new file name to the dta */
( T4 |# Q: w7 n- T' u8 i/ Aparsfnm(line, &amp;blk, 1); ( D, _! Z* t) c! `1 L: x9 V
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>5 l; v" J7 W5 _2 r2 A6 C9 m
<P><FONT color=#0000ff>/* request DOS services to create file */ 6 ?8 Y5 L* H& i6 B7 F) ?
if (bdosptr(0x16, &amp;blk, 0) == -1) ; a+ l1 R1 t) w: X
{ : R) Y' d6 ?& _, `
perror("Error creating file");
* d" |7 q+ F8 r" ^( k: b& ?  jexit(1); 0 K7 L1 w% `. ]+ N3 K* q4 r. E1 L8 Q
} </FONT></P>
7 m# E% c" |9 o: b" F# x! T7 y% |( E<P><FONT color=#0000ff>/* save old dta and set new dta */ . ~. ?& t; X6 k. c& c
save_dta = getdta();
8 ?3 w& g' T2 J$ xsetdta(buffer); </FONT></P>
1 B/ t1 N0 m" E0 R7 i<P><FONT color=#0000ff>/* write new records */ ' Z* k' c% K# L' d1 o
blk.fcb_recsize = 256;
$ d( l# w  \+ P. yblk.fcb_random = 0L; , l/ j  ]: }4 F3 S
result = randbwr(&amp;blk, 1);
: b" r( E* x0 T" I$ m* Sprintf("result = %d\n", result); </FONT></P>
8 `1 Y; W/ g6 H, Y2 b6 X+ ?- `<P><FONT color=#0000ff>if (!result) 8 d5 B3 c4 [" m7 d  S7 M8 G  \
printf("Write OK\n"); ( c+ l: ?) w" o6 n8 {; b
else * Q% M) n* {- D: O
{
" l! V4 R; A7 j+ Lperror("Disk error"); * w: }0 U  U* ~# ?
exit(1);
+ [2 h: M7 T. w$ F} </FONT></P>
7 t5 }& b3 z6 L<P><FONT color=#0000ff>/* request DOS services to close the file */
  r& R& @8 Y4 y9 O. o) dif (bdosptr(0x10, &amp;blk, 0) == -1) ) W# H+ X0 P0 `# H
{
0 P8 {' M6 q/ dperror("Error closing file"); 5 R( |7 @2 e- I6 o7 L: E& _; E
exit(1); 4 E- L5 i9 z( |, [
} </FONT></P>2 e& ^/ R. J1 G( v
<P><FONT color=#0000ff>/* reset the old dta */
& b" u) N0 I2 F1 vsetdta(save_dta);
- H, `* v0 \& Greturn 0; ) y* Q9 L  s7 ^% F
} : Z8 S7 P) n* b" @
</FONT>, V. K" O5 G% T2 J4 Z
</P># C0 n2 l/ v% u# p6 F' q5 R! n6 _
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
1 D1 \* T# f7 n4 j, }功 能: 选择用户定义的填充模式
/ K- z; `5 S4 H3 A* m) H- A用 法: void far setfillpattern(char far *upattern, int color);
$ @$ t4 F$ ]& l1 s# \$ n3 ]9 C4 z; p程序例: </P>- a+ R; R! u: e
<P><FONT color=#0000ff>#include <GRAPHICS.H>4 J8 O, Z; h" }7 L, `
#include <STDLIB.H>
# F  e4 u3 E2 o1 m) L# P#include <STDIO.H>
) `  X0 ?6 @6 Z  p8 Y#include <CONIO.H></FONT></P>
2 ^+ \/ \  V  n. A: i<P><FONT color=#0000ff>int main(void)
% |+ p$ S4 H& T' \4 Y! L# z) @% W{ % n9 x8 Z0 s4 q/ n* i3 o4 @* J0 l
/* request auto detection */ $ @# b5 G* P4 R6 \% z! ]* i) K
int gdriver = DETECT, gmode, errorcode;
6 k1 W7 c4 h/ f7 b1 M. _int maxx, maxy; </FONT></P>( [* D# C5 n$ ~, x. [6 I
<P><FONT color=#0000ff>/* a user defined fill pattern */ 9 o, g6 A; x) P; G8 m
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>% B2 ~7 F2 n+ t% o
<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 G& b+ x( f3 d/ Z# r! ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: Q+ P: N+ g. Z) l* I<P><FONT color=#0000ff>/* read result of initialization */
0 d6 d- [" z5 i) y- @0 a8 Perrorcode = graphresult();   h  ^$ I. ~9 x/ g+ A& @
if (errorcode != grOk) /* an error occurred */ ! ?6 ^* T! l/ y% M4 |
{ % g$ ~! d" p# k8 M
printf("Graphics error: %s\n", grapherrormsg(errorcode));
% V0 w" [: ~+ Vprintf("Press any key to halt:"); & a! Y0 [0 f1 {& E
getch();
& f; _: [3 f) x/ _1 T9 ]4 pexit(1); /* terminate with an error code */
/ ]% Q* I) ~& a1 c" {7 ]1 r} </FONT></P>
/ Z1 M/ e/ _* w<P><FONT color=#0000ff>maxx = getmaxx(); 7 V. a  o) R" D
maxy = getmaxy(); 2 s1 `/ c5 q. {. ?$ \, g- ?
setcolor(getmaxcolor()); </FONT></P>
! _; J: p- [$ D, |; ~8 ?* a" G<P><FONT color=#0000ff>/* select a user defined fill pattern */ 3 p) H2 }' k  j# w& E
setfillpattern(pattern, getmaxcolor()); </FONT></P>! K% g, R7 y  u$ V7 C6 T# V
<P><FONT color=#0000ff>/* fill the screen with the pattern */ ; x: Y  c6 z8 |4 \) C0 o
bar(0, 0, maxx, maxy); </FONT></P>
. E, v6 V. g) ^6 R<P><FONT color=#0000ff>/* clean up */ ) I/ T# r5 f1 d+ h
getch();
+ i3 I( W6 ]/ G3 x8 @' b: W: mclosegraph(); 9 Q4 Q, O+ y% u- C" a) P) w  i4 O
return 0;
( u, S6 k4 k* O- y} & Z3 v9 z4 G" u
</FONT>$ @# Y; {9 c: Q' ~4 `1 A4 X
</P># M/ E$ P* N, m# V
<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
6 {: `5 z# j& Z4 O$ Q; @$ ^# M( N功 能: 设置填充模式和颜色
' h7 I7 t  q& _: b' e7 |- |用 法: void far setfillstyle(int pattern, int color);
" \$ R: o! r5 m& \程序例: </P>
, `. m! O" X* s+ p<P><FONT color=#0000ff>#include <GRAPHICS.H>+ p( H+ _# [9 p1 E2 q- j
#include <STDLIB.H># E+ r# @3 b  o  f* l
#include <STRING.H>% P0 ~7 H( W7 m2 x! C
#include <STDIO.H>: F, N. z) i+ @" o, ]; a
#include <CONIO.H></FONT></P>  |' G( }$ I6 d1 l
<P><FONT color=#0000ff>/* the names of the fill styles supported */
+ ]; b6 k+ C4 [& n& S; }7 R8 Tchar *fname[] = { "EMPTY_FILL", , V1 }4 Z" [+ r" M- B; b
"SOLID_FILL", ) Q5 S2 A1 W; Q" W$ q. n9 T
"LINE_FILL", 4 j* `0 [$ w: y0 Q# P- ~8 m
"LTSLASH_FILL", & p: m# c1 m0 T$ }; x0 J- n
"SLASH_FILL",
& }7 S4 \- n- }2 v"BKSLASH_FILL",
+ B7 T$ v1 g/ C. j# T: S"LTBKSLASH_FILL",
( {  _6 d5 C$ H3 r2 d5 |9 N, b"HATCH_FILL", $ ]" ~) h8 ~' X( [2 l" d# ^7 F
"XHATCH_FILL",
5 ~* o  G, Y$ V- ?( `"INTERLEAVE_FILL",
' }# ~* g1 c, b! h# ^3 s"WIDE_DOT_FILL",
& K) q! b+ s+ Y7 K) w' R+ X. `+ u"CLOSE_DOT_FILL", 5 J2 C9 x+ o( u7 w0 e
"USER_FILL"
# W; c( A# O6 b7 B0 I& i}; </FONT></P>
( `" ?9 A+ f3 B. H+ L* M/ X2 g<P><FONT color=#0000ff>int main(void)
. K7 X3 r/ O8 q{
) c: S( a- c( G1 c' H" }5 Y5 H, m1 q/* request auto detection */
4 M: |* \- s& Sint gdriver = DETECT, gmode, errorcode; + m2 f2 C0 b% m$ j* h4 g; f
int style, midx, midy;
" b) l: ^4 j8 w( X% p" ]3 ochar stylestr[40]; </FONT></P>
1 D9 b3 ~, A- b4 _7 {4 v5 W<P><FONT color=#0000ff>/* initialize graphics and local variables */
" M1 L7 @5 D! o4 uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) z! d, S& P8 K% d<P><FONT color=#0000ff>/* read result of initialization */ : v; y: v1 L8 ?1 i) g0 g
errorcode = graphresult();
5 a% [* M  Z7 S  x% Fif (errorcode != grOk) /* an error occurred */
3 n' f  j8 }4 ?8 [* ]{
; p, m  x/ y* \printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 T' Q6 E, L) j& S" }
printf("Press any key to halt:");
, F! [2 p" H1 T5 `getch();
# @2 W' y' X1 r0 U  Lexit(1); /* terminate with an error code */ , e# N- W5 N$ _3 r, I; ~6 P2 D
} </FONT></P>/ D, `. n3 k/ S; n
<P><FONT color=#0000ff>midx = getmaxx() / 2; # f% K" f: \- V7 n
midy = getmaxy() / 2; </FONT></P>
* l' s$ x  k9 f) t: P2 E8 h<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
( S+ l; [& E: X+ K. {' n{
/ f6 b7 a; F3 A  w8 G/* select the fill style */ / J! R' k5 p% @+ B
setfillstyle(style, getmaxcolor()); </FONT></P>
6 C( p$ C3 T$ X8 u/ a<P><FONT color=#0000ff>/* convert style into a string */ , Q9 L) D  u5 U, X7 a
strcpy(stylestr, fname[style]); </FONT></P>/ }4 r+ a" Y* A' U5 N9 d
<P><FONT color=#0000ff>/* fill a bar */
0 k! [* Z) j; ~- {bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
% _* \5 h7 b5 r' M8 X0 `<P><FONT color=#0000ff>/* output a message */
8 C1 @4 x! A& X# X5 O; i2 F0 M1 Zouttextxy(midx, midy, stylestr); </FONT></P>/ }6 E! Z! W  q9 t0 C5 d0 j
<P><FONT color=#0000ff>/* wait for a key */ ! X2 f8 v3 Z$ A1 ~) j( [- J
getch(); # j' M1 E* z: M( @3 ]0 d
cleardevice();
8 Q* |$ E& l$ k5 P} </FONT></P>
  ?- d+ B+ V9 {  w  H# L<P><FONT color=#0000ff>/* clean up */ 6 ]  g* s2 z5 S( y# X2 I
getch(); , |" r: O$ ^2 h+ t7 a  h5 b5 M
closegraph();
" V5 w7 b0 j8 f/ u0 Jreturn 0;
7 _% O& L4 \  d+ V5 v, _7 G0 {} </FONT>
/ a  X" P' n# t2 |
3 Z+ W0 V9 h$ V+ a* ~6 ?</P>
2 m0 ?* s( `( o: i  ^1 a7 W<P><FONT color=#ff0000>函数名: setftime </FONT>2 O  f: N3 e8 e7 \& G1 q
功 能: 设置文件日期和时间 " M% z+ {' x* l
用 法: int setftime(int handle, struct ftime *ftimep);
" W# Z& O' ~( q/ b2 _& {: _; P5 c( \/ g程序例: </P>% k5 [* D# y( [: q4 N9 u. F( M
<P><FONT color=#0000ff>#include <STDIO.H>
( Q, u2 n$ u' h" w#include <PROCESS.H>
5 j+ H4 i3 b, T# E( I/ x#include <FCNTL.H>) B  d; F- f/ h5 v# e& J
#include <IO.H></FONT></P>8 j1 ^/ F& K: Q
<P><FONT color=#0000ff>int main(void) & k5 U7 B7 r" _( D* w! J2 r, |
{ : K7 K/ U; `; v3 P3 i% Z# M- i
struct ftime filet;
$ P* D+ Z( j( Y$ @FILE *fp; </FONT></P>$ H) A  ~% h5 E" H/ Y' Q- U; ?# n
<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) # p; V( }& ^' r. m$ B0 K  |: `5 D0 K
{ 6 o# W+ T- H: d7 h$ t- {0 x* G
perror("Error:"); ( V2 E; H8 `! e7 j- l
exit(1); * T. U( c) ^  r1 `7 E' D
} </FONT></P>! a% l2 Y# c2 G, z" a
<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>
7 D8 d) H! f  W<P><FONT color=#0000ff>/* load ftime structure with new time and date */
) O3 t/ r4 A' s, i! l8 Zfilet.ft_tsec = 1;
; _: w5 s3 h3 u6 G: q" z7 y2 |filet.ft_min = 1; ) G; y( H- g5 r8 ?9 E
filet.ft_hour = 1; 7 Z# ]+ I$ M* x" h; m" L
filet.ft_day = 1; . P' w* C; A- \' O! @2 v! H6 N/ K
filet.ft_month = 1; " s: W# d+ g" W/ I8 P# ]
filet.ft_year = 21; </FONT></P>
7 Y$ C7 \7 @& W+ x% \' |<P><FONT color=#0000ff>/* show current directory for time and date */
* R4 H4 x: \+ J! J* h& jsystem("dir TEST.$$$"); </FONT></P>( Q8 B6 k" @# }2 N. _
<P><FONT color=#0000ff>/* change the time and date stamp*/ - ]* @" W& {/ J. I6 o! M, Y
setftime(fileno(fp), &amp;filet); </FONT></P>% I& t$ J& _6 Y( g( F0 o
<P><FONT color=#0000ff>/* close and remove the temporary file */
) V* a. ^6 n5 \7 b% |fclose(fp); </FONT></P>
( D) `# o- u+ z2 L" w, m<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>3 m6 X- }0 t. P. Y) S3 g$ ?3 S" U4 C
<P><FONT color=#0000ff>unlink("TEST.$$$"); ( \1 x5 b" q8 f+ `
return 0;
( R8 }# d+ A6 D7 w% }0 Q$ B( {}
) `" _1 U, A; {</FONT>' x1 z9 A0 D, w! V
</P>' m# Y/ Q5 S, |& n& a0 {9 {
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>- ^, A1 Q% d/ d% \+ t; D3 X
功 能: 改变内部图形缓冲区的大小
) [4 Z, J7 P- W* q) q2 ]& T6 z用 法: unsigned far setgraphbufsize(unsigned bufsize);
4 A2 b' E8 j( \% |# }, L/ P程序例: </P>
' l: U) n* Q: |<P><FONT color=#0000ff>#include <GRAPHICS.H>. b/ P; ]  o3 V+ s. [& Q
#include <STDLIB.H>$ h& O# m! ^% m( C
#include <STDIO.H>
- }1 ~1 T& ]$ }#include <CONIO.H></FONT></P>/ u+ A& |6 \1 X- c7 j- k
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>) C' V5 X) j4 n/ X
<P><FONT color=#0000ff>int main(void) 6 B$ b+ ?+ n0 H
{   o. M- D& ]5 J* [6 k# g( K
/* request auto detection */ 7 R0 d5 P; U2 d0 W1 N- u
int gdriver = DETECT, gmode, errorcode;
7 [9 ~! b) T( h6 D' v! _int x, y, oldsize;
3 i1 A$ H! ?' B6 }& @" v" W4 Jchar msg[80]; </FONT></P>7 ^2 T( p6 s( M. z
<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
6 G% \9 E3 e6 _6 e/* before making a call to initgraph. */
7 t9 H. \( C# @$ poldsize = setgraphbufsize(BUFSIZE); </FONT></P>
& r5 G+ O; R8 A<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 v4 k$ ^) y6 W! G" M
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 y! j6 g4 ^" \' `: O- u
<P><FONT color=#0000ff>/* read result of initialization */ 9 {+ w/ ?8 A0 q- V4 w. m
errorcode = graphresult();
* S& O4 O: O* j) F1 r  f& bif (errorcode != grOk) /* an error occurred */
8 t* V" N) T; N1 w5 q2 b; m{ : b& m0 o& R+ A" C6 o% r3 D
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 n* ^+ n/ w2 k) M
printf("Press any key to halt:"); # r) @9 t$ e  U. w* _
getch(); , C0 l- Z$ O* U/ F* A) h6 a" o
exit(1); /* terminate with an error code */ / G/ T- ?! g6 I: |
} </FONT></P>! Y% [3 [: x4 X/ [/ q5 W
<P><FONT color=#0000ff>x = getmaxx() / 2;
5 D2 h5 y6 l5 p/ s+ g% i' Yy = getmaxy() / 2; </FONT></P>, J: H9 L+ h' j0 n
<P><FONT color=#0000ff>/* output some messages */ % n6 e3 o! Y, Z: W8 l: W- C$ Y" y
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
, t  N6 u& _- H* H: f. g1 m* V2 S8 @settextjustify(CENTER_TEXT, CENTER_TEXT);
) c- V) n* H% k' P! n% w9 J0 f2 Zouttextxy(x, y, msg);
) I: L& n8 K4 }: l/ usprintf(msg, "Old graphics buffer size: %d", oldsize); 9 C  \5 {  F+ @
outtextxy(x, y+textheight("W"), msg); </FONT></P>
. O1 V/ }* O5 K- F<P><FONT color=#0000ff>/* clean up */ & g; \# B. H( M! q; |
getch();
8 q. h) Y$ k+ A( O0 Z, [) Gclosegraph(); 1 D- h. i) t/ g$ n' U
return 0;
) N* U$ ]# L8 Q! p& E, ?& A} : z% g* T4 i2 b5 y5 P4 @- f

  P$ S/ Q! C. I9 w
+ j/ [# N* s9 X, d% _0 l</FONT></P>+ a' [/ F; f4 L' W, F: t
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
0 s9 P2 U0 d4 }) _* a功 能: 将系统设置成图形模式且清屏
& j/ f6 f1 ^8 S8 s4 R用 法: void far setgraphmode(int mode); . c6 E# R( m: H* o6 a/ c
程序例:
8 u3 r$ ^  p, {$ v  B% A
# C! n& G  U  P6 p4 r" N1 Z<FONT color=#0000ff>#include <STDLIB.H>4 S1 c5 v6 E3 z$ q; m& u/ u
#include <STDIO.H>2 D5 G- }# v( E+ N4 N4 K2 |3 M2 h
#include <GRAPHICS.H>#include <CONIO.H></FONT></P>9 ]( ~% q. b+ _9 i0 v& ^1 x1 U
<P><FONT color=#0000ff>int main(void)
6 }) c: i, ^, `{ & Z% |% F& o' r7 F$ _6 A7 [2 I4 E
/* request auto detection */
1 n5 _5 g- ^$ t+ s: _/ Xint gdriver = DETECT, gmode, errorcode;
5 O7 O8 O2 |& a+ q4 a" J) [6 s; \int x, y; </FONT></P>
) Y4 `5 ^$ a2 i8 B<P><FONT color=#0000ff>/* initialize graphics and local variables */ + ?9 Q( `. S( `* X& s7 B" H
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, d4 z; o' E# f<P><FONT color=#0000ff>/* read result of initialization */
; B. S  J! w1 }/ P3 Uerrorcode = graphresult(); 9 B2 g7 K( r$ `1 `
if (errorcode != grOk) /* an error occurred */
( a) a) O9 \( A; i% }. B; G* K{ 7 N; k# v1 O' C+ G' V/ Y- r) ^% ]
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 n+ ?/ W) G6 ~
printf("Press any key to halt:"); * O1 X' A3 n2 b% U/ B
getch();
0 r5 ~% C6 M: ^* Aexit(1); /* terminate with an error code */ * X) T* P: Z0 V9 w/ S1 h0 T0 q' c2 s
} </FONT></P>
$ k, A% Z( T' B3 z# E<P><FONT color=#0000ff>x = getmaxx() / 2;
! f' @' g3 J( by = getmaxy() / 2; </FONT></P>1 z5 I9 n0 M& z$ K6 j/ u, M' l
<P><FONT color=#0000ff>/* output a message */
+ v( m* Q; l6 U3 W6 f& E+ R: asettextjustify(CENTER_TEXT, CENTER_TEXT); ! M* P, p' p6 R+ f% E
outtextxy(x, y, "Press any key to exit graphics:");   n6 }& i3 E1 J5 _' |8 I% K
getch(); </FONT></P>. q6 v5 i2 s! h1 Y. F; P! }
<P><FONT color=#0000ff>/* restore system to text mode */ " y. o# p! d: y& c
restorecrtmode();   I) B/ _( W9 C% \5 T
printf("We're now in text mode.\n");
6 q$ a- w) k9 y. |8 @7 W) Lprintf("Press any key to return to graphics mode:");
  p5 P2 b$ I) e! l  Zgetch(); </FONT></P>0 {$ p5 S0 K+ c/ I8 @
<P><FONT color=#0000ff>/* return to graphics mode */
& w$ S! z; w2 {$ gsetgraphmode(getgraphmode()); </FONT></P>
: N7 g! F2 j& a( S% ^<P><FONT color=#0000ff>/* output a message */
+ U- u, K+ J1 d; X/ U  p8 J# q. qsettextjustify(CENTER_TEXT, CENTER_TEXT); ; N, S3 S( y" \* Y9 \
outtextxy(x, y, "We're back in graphics mode."); 3 m: I; D$ H0 i& p. g* F$ \
outtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>7 h9 `% m/ w  C" ^
<P><FONT color=#0000ff>/* clean up */
+ T/ p) ]0 z' ~  `, ]7 ggetch();
9 Q! P$ G9 t2 j' v- Vclosegraph();
( V" S+ T1 Z! F% ^) yreturn 0; % }# s. C2 q4 I* E  t3 b# ?
}
3 a% M* U0 @# ?- h9 D" c+ t# ]2 c  s5 Y, ~  F
2 A' K3 e8 }  L( c5 [
</FONT><FONT color=#ff0000></FONT></P>
$ @3 l4 D/ S1 C" S2 ~% y/ [4 h<P><FONT color=#ff0000>函数名: setjmp </FONT>+ N9 q' {, {, q% C
功 能: 非局部转移
4 d# a2 S( G. J$ e& ^3 T5 f6 _- C用 法: int setjmp(jmp_buf env);
* G1 _- O  P- {0 z7 z程序例: </P>
8 {3 \7 R; J, y* O<P><FONT color=#0000ff>#include <STDIO.H>
( F& t, o; Y- J6 H#include <PROCESS.H>
, t. t1 A/ i* k$ w* A8 H#include <SETJMP.H></FONT></P>8 m: w* A' L' _8 h/ p$ {: \* Z$ r
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
* G  J- E- n: u/ m4 R# p<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>% w, M7 [% d( L7 S* G3 K4 V
<P><FONT color=#0000ff>int main(void)
: }  [  W  ^$ b{ ' t6 R0 c  v2 v( b# r+ }  k
int value; </FONT></P>( G3 M  t, Y' W2 r
<P><FONT color=#0000ff>value = setjmp(jumper); . x# |3 g6 r: g0 R
if (value != 0) ! S) N7 i; L, ^' Q( f0 Q
{
' {; V  X  d# i! S4 b* s0 eprintf("Longjmp with value %d\n", value); " ]. G% y: y) \) \8 R
exit(value);
4 _' p& f: x  q- H6 m) n$ L} ; e' Y4 Z, f1 ~$ m
printf("About to call subroutine ... \n"); ) ?" t9 K3 w, F2 L8 o) ?1 P* Y0 a2 {
subroutine();
* r3 l# }6 j: ]2 Ureturn 0; 7 x+ ^" m7 d/ X+ o, X: l" T
} </FONT></P>6 w. Y0 b0 X6 V) l) j
<P><FONT color=#0000ff>void subroutine(void) 0 z. K5 r; Q0 ?- B! {- m
{ ( M9 ]1 `/ f7 X- }
longjmp(jumper,1);
0 l" d& b, t- R) ?1 C6 p} ' l$ L/ d) ]% p# R! H
</FONT>" A6 c* ?+ w" p2 L  n
</P>
: q: B7 I; r8 U8 [; \8 U  e/ v# n<P><FONT color=#ff0000>函数名: setlinestyle </FONT>9 @" j( E7 Y! c+ @3 E# B
功 能: 设置当前画线宽度和类型 + R* |7 \  @$ N6 [5 j2 o  ^5 r4 @' W
用 法: void far setlinestyle(int linestype, unsigned upattern); 2 Y9 n4 ~. [# D& o1 ]: k" N
程序例: </P>5 }  F9 Z% S( R- B
<P><FONT color=#0000ff>#include <GRAPHICS.H>
. T2 x5 l  ~6 a5 G1 D/ q1 j; Z+ P#include <STDLIB.H>
, ?7 {+ k( n3 b9 t: b/ P) V#include <STRING.H>
$ |$ B0 ^* ^$ \* F6 x#include <STDIO.H>- M# T' |- ~4 m& @2 G
#include <CONIO.H></FONT></P>
% b. S3 z- D5 [<P><FONT color=#0000ff>/* the names of the line styles supported */ & [( U& R1 a) z( K$ e
char *lname[] = { " F( W4 L' w# g
"SOLID_LINE", ' q8 m) w- ?9 v6 b5 |2 f8 G  g
"DOTTED_LINE",
! {) ?5 C' {8 u8 y9 F; T- p3 v"CENTER_LINE",
1 H0 N$ m  v4 ^"DASHED_LINE",
: V4 \) g& M9 }# B" ["USERBIT_LINE"
! j; f- e( g) {* y! K}; </FONT></P>
/ }+ Z3 X* }- E8 f* Q) [<P><FONT color=#0000ff>int main(void)
. ~8 k2 ]6 A- C- H  u{ 9 c1 s! ?# A6 j6 E: P% H4 D
/* request auto detection */ 7 P, c; {# E0 g% X# E" _4 ?
int gdriver = DETECT, gmode, errorcode; </FONT></P>8 i, a+ z1 @0 v! z
<P><FONT color=#0000ff>int style, midx, midy, userpat;
& F9 k7 O, j' K( }# ]char stylestr[40]; </FONT></P>
4 M# S! B3 }9 ~  \& u<P><FONT color=#0000ff>/* initialize graphics and local variables */
. X* _3 t! R" c$ ^. {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" c7 y! q" W. }  ^! R" |<P><FONT color=#0000ff>/* read result of initialization */ ( U  a' N( {; e3 p" y0 ~4 |
errorcode = graphresult();
- h5 ^$ G6 U9 ?# vif (errorcode != grOk) /* an error occurred */ 1 ~5 F0 n; M. h7 r$ r% `
{
. i% c/ o5 G# N  M: b/ _printf("Graphics error: %s\n", grapherrormsg(errorcode));
" X! ?1 }% t  ~) O- V$ aprintf("Press any key to halt:"); , l; Z3 `/ E8 P+ O6 @
getch(); % n3 a2 W! {# d; y! u$ m
exit(1); /* terminate with an error code */
* N7 x; H/ e. h/ T; G9 z1 o# x4 C& O} </FONT></P>
7 l% r% U% o: X- `& V<P><FONT color=#0000ff>midx = getmaxx() / 2;
* Y- P! W; N* a/ Umidy = getmaxy() / 2; </FONT></P>' d9 u( F# p% [
<P><FONT color=#0000ff>/* a user defined line pattern */
- O, A& w3 X+ F/ a, u/* binary: "0000000000000001" */ + u; x) _: F+ M9 G0 Z1 n
userpat = 1; </FONT></P>
8 _$ l7 C4 z+ D8 l<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
- }: c+ R0 L$ D1 c" s& \" U& s{ # f% T+ l+ g* F. j3 ]7 L
/* select the line style */ / `) s9 Y% a% d4 @% G3 |/ I/ S, X
setlinestyle(style, userpat, 1); </FONT></P>6 E4 S2 E0 R: O/ U
<P><FONT color=#0000ff>/* convert style into a string */ + x7 j9 w3 \# Q, [0 I: B
strcpy(stylestr, lname[style]); </FONT></P>% j! E, d) i9 I# b
<P><FONT color=#0000ff>/* draw a line */
! G* K" W  @5 n  Z) Zline(0, 0, midx-10, midy); </FONT></P>7 h8 g1 D: |1 J3 {- C
<P><FONT color=#0000ff>/* draw a rectangle */
- b- X7 ?4 ]2 K% Jrectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>! g! F/ M3 G# x8 N. n
<P><FONT color=#0000ff>/* output a message */ . c- e6 B2 M3 t& }2 Q0 c
outtextxy(midx, midy, stylestr); </FONT></P>5 R" o( v' q+ m! P2 l
<P><FONT color=#0000ff>/* wait for a key */
, _8 Y: Z2 O- tgetch(); - ]; V  ?0 ?) l8 J% r. q
cleardevice();   F1 _6 @2 T- s! v( d
} </FONT></P># y& b3 W" f$ W# W3 }
<P><FONT color=#0000ff>/* clean up */ / T7 P" }6 l. |! J* ~9 ?4 p
closegraph(); , E+ I. j. x, q% z
return 0;
7 V3 I" n9 _0 |7 y9 T" y5 [5 D} </FONT>! z' _( ?0 O4 i: K1 ~
  M2 I, U/ ~8 B* i6 `) z( @. E0 h

' V! K$ R) I1 ?, V</P>* W; f' {+ g/ h9 N* N) Z% H
<P><FONT color=#ff0000>函数名: setmem </FONT>( E4 K) N7 z  [6 `
功 能: 存值到存储区 $ q( e. b7 f7 n6 p
用 法: void setmem(void *addr, int len, char value); 9 ]/ d* L) E' B" V
程序例: </P>
. N& ^. H7 v+ ^  E& D<P><FONT color=#0000ff>#include <STDIO.H>
6 S  \! X% r9 N1 D#include <ALLOC.H>' c& t% B  B5 r
#include <MEM.H></FONT></P>, c5 Q. Q' O" P8 w
<P><FONT color=#0000ff>int main(void)
) f" f/ E* H; ?) O# k9 V{ * x& \- v4 ?0 X0 I6 o+ Q/ U
char *dest; </FONT></P>& X6 k# b) z! X7 w; f# J
<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
- L# G1 @1 U) Z: asetmem(dest, 20, 'c'); 1 u9 M( g/ I; N& d: b  u1 d
printf("%s\n", dest); </FONT></P>
6 J5 k1 q5 U7 Z" |0 r. T<P><FONT color=#0000ff>return 0; & J1 K# s+ q/ y. e# k
} </FONT>& S, k8 K$ I# o- m

' G. M0 F6 t  {, ^* q6 U& m! j5 P+ o6 Y6 w. N$ s% I7 \( M! t
</P>
1 ^% ^  F- e4 l$ @) R9 s. m- b<P><FONT color=#ff0000>函数名: setmode </FONT>9 {! m7 |. {& |! Z
功 能: 设置打开文件方式 ; `% x+ {2 d$ |7 t
用 法: int setmode(int handle, unsigned mode);
9 R( t. Q" g8 O! M8 s1 U  [! L+ a- O程序例: </P>
5 {( E0 N3 a1 h4 G$ ?2 S<P><FONT color=#0000ff>#include <STDIO.H>
6 R/ @4 i" e+ }8 }: G. m' o#include <FCNTL.H>
+ I) E- M- @7 F+ W#include <IO.H></FONT></P>
' T( f- S! N( n% N& a9 K<P><FONT color=#0000ff>int main(void) " Q& D4 z- \5 G( C7 i$ C6 }& q
{
/ C. M5 v* j, e. W7 c# I6 u  \int result; </FONT></P>
( G7 K% T" m' L$ U<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
+ d" ~+ @1 d  rif (result == -1)   b. d& T1 i4 `, u8 k* d
perror("Mode not available\n");
1 |* v# v: b. g. M! q5 Aelse 1 M1 z, s& \+ |& x$ w
printf("Mode successfully switched\n"); % Y* `! T$ |, v" W, j
return 0;
+ h9 h5 d( P# G1 ]$ w0 C# x  U} " ~4 e9 b* {1 r) ]* O3 {

6 t: }* @3 G* B4 O6 _& ~+ e. I</FONT>: M$ U: k5 s2 p3 D5 z: g
</P>
+ Z" w/ P6 J/ z: l7 S<P><FONT color=#ff0000>函数名: setpalette </FONT>1 E, L2 F8 M- v
功 能: 改变调色板的颜色
/ u+ ], S7 P# E用 法: void far setpalette(int index, int actural_color);
% e  z1 o+ r! F; ]3 q) [程序例: </P>3 p3 o  g6 w6 {  ?" g. A% ?5 ]
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ a  v) o. C% t. ~6 @9 J+ k+ f#include <STDLIB.H>
, t3 j3 w  o% I#include <STDIO.H>2 U$ F  w/ r# \8 v
#include <CONIO.H></FONT></P>& ^) L" S* c  f7 S8 w# V
<P><FONT color=#0000ff>int main(void)
! L- a4 |4 N4 ~- g7 ?+ i' Q6 l{ 3 T/ N$ n! V9 M# ~( [
/* request auto detection */ 3 j2 ^4 ?) O7 Q7 F
int gdriver = DETECT, gmode, errorcode;
8 w2 z9 J- q, `int color, maxcolor, ht;
6 L. H; A9 t5 dint y = 10; 9 a0 l$ S3 r/ O% L; A
char msg[80]; </FONT></P>7 T( d! U; ?" T8 {
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' z+ A  o$ T- g# Sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 N# n7 K' K* h  A( E3 c
<P><FONT color=#0000ff>/* read result of initialization */ * J: U- u( Z& t$ R) n1 ^7 Y5 Q+ ]5 ~
errorcode = graphresult();
8 z7 P* B& G* ~if (errorcode != grOk) /* an error occurred */ # Q* |1 x% v6 ~% F  j0 _+ b2 b
{ $ J2 }$ B3 q* u& J
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 l  x! G5 e* {: b  C
printf("Press any key to halt:");
, p+ L# k8 I* R8 Y% F5 ^; egetch();
! f. F1 c/ D7 i! o7 K3 iexit(1); /* terminate with an error code */ + @" e) {* U% u+ _
} </FONT></P>
) S6 R8 I- J4 u1 q  l<P><FONT color=#0000ff>maxcolor = getmaxcolor(); 1 J& s0 _1 S; ~+ V, U: w9 b/ I2 q
ht = 2 * textheight("W"); </FONT></P>
; s/ j' Y, Z+ T<P><FONT color=#0000ff>/* display the default colors */
$ U  h& p" v6 j5 ^# ~9 kfor (color=1; color&lt;=maxcolor; color++) 3 U; I& Z+ h7 M6 {* Y
{
$ j$ z( a7 v: Q2 Lsetcolor(color); 3 a) {. m4 v* X' Q
sprintf(msg, "Color: %d", color);
0 j: g: b' ^; V" d+ z2 \& kouttextxy(1, y, msg);
$ [) V3 j# ]* @1 u( Gy += ht;
/ Y) h/ N( z3 p* M/ z) j} </FONT></P>+ W! a, s0 G( v; ^1 E
<P><FONT color=#0000ff>/* wait for a key */
9 M4 `' A& l. O+ E+ u9 H( hgetch(); </FONT></P>
3 X0 S, P2 a! Q( S<P><FONT color=#0000ff>/* black out the colors one by one */
0 ^9 R. H0 f. K* ?for (color=1; color&lt;=maxcolor; color++) ' j/ T- x+ J$ O) U% ]
{   b+ R$ k0 W' _: ^/ Z& t- P& i
setpalette(color, BLACK);
1 c& B+ X# [( X( @5 K! q7 e/ Ygetch(); ; P% d% e$ ^, C9 X1 N3 y: Y. y
} </FONT></P>
- I3 H  V& @: D8 Y<P><FONT color=#0000ff>/* clean up */
# x) }) [( R3 x# ]6 Fclosegraph(); ; v, u: L; H( q9 ], J  _
return 0;
5 ^- l; i: G, q$ L: H}
0 T. }, Q! F5 G8 v$ p  V0 T</FONT>. ?6 |7 U: B& j7 j3 O4 y2 \: M
</P>
- d; H! V7 r% j2 {/ L<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
, O6 Q; u. e& f  ^9 V; C3 U功 能: 定义IBM8514图形卡的颜色 8 H+ F8 O& K5 g7 A1 y
用 法: void far setrgbpalette(int colornum, int red, int green, int blue); + m  a" N8 Z  x/ c$ D& t2 m& I, \
程序例: </P>
* P# S0 o$ W8 o" [, G<P><FONT color=#0000ff>#include <GRAPHICS.H>
. J6 e' Y- p3 j1 C- Z#include <STDLIB.H>
- |* L8 y8 _* c) \#include <STDIO.H>
3 k& \2 w* o0 M8 m" y& p#include <CONIO.H></FONT></P>
0 c8 T+ q' a. M$ d* e<P><FONT color=#0000ff>int main(void)   m3 _# s8 c$ }) E; S
{
, E; W: \% Q! }7 x4 w& L+ V/* select a driver and mode that supports the use */ : x. c: @5 E' f2 {5 t
/* of the setrgbpalette function. */ - w2 C' [) L! C0 ^. _
int gdriver = VGA, gmode = VGAHI, errorcode; / {5 v/ d' R, u2 V" y. ?+ Q! b: M
struct palettetype pal;   J) X- B* ]% [) Q* X: t# r1 V
int i, ht, y, xmax; </FONT></P>7 S8 b4 p0 C: l* y
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( r' ~* J3 c: o2 D& ]+ o& j
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" h. p2 I4 J  j$ L- @' U5 \
<P><FONT color=#0000ff>/* read result of initialization */ 6 E8 U5 M4 X# Y
errorcode = graphresult();
6 V6 S: h7 i/ G4 _% {if (errorcode != grOk) /* an error occurred */ 2 c. U9 ^# K. R" T, Y
{   R+ ^! D6 K& a8 d
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 C1 `, v& T1 T" z+ |$ s
printf("Press any key to halt:");
  |8 m7 |. c0 D( m* a. _getch(); $ y2 k1 s9 z1 L
exit(1); /* terminate with an error code */ 6 r9 @+ `$ I2 Y0 p! W
} </FONT></P>5 ]  [, ~2 Q" k( ?% N4 a
<P><FONT color=#0000ff>/* grab a copy of the palette */ ' R/ s* ?3 z6 ]+ Q# z4 y
getpalette(&amp;pal); </FONT></P>
0 k4 }/ ~' l' k<P><FONT color=#0000ff>/* create gray scale */ 0 {# X4 ?) ?, O4 Q2 l. i7 O
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>% N4 X+ d& C- T# m5 N5 e+ ~
<P><FONT color=#0000ff>/* display the gray scale */ - `/ p" _5 o8 d: t
ht = getmaxy() / 16;
8 j) \% p3 [: x3 a. L& w( Kxmax = getmaxx(); , I, t6 J; m& o0 O; B: j0 J; s4 v
y = 0; ' m& k- E9 `& k3 a7 Y& U3 m
for (i=0; i<PAL.SIZE; <br i++)> {
3 m- e$ ~6 h4 ?0 v8 ksetfillstyle(SOLID_FILL, i);
3 e- j$ }: o, q: U+ A% {bar(0, y, xmax, y+ht); , q$ L" E' g3 i9 ?  g* _, R5 @
y += ht;
* \4 ^) _% r' j3 x' U% R} </FONT></P>: v" ]' E, o. k7 @8 x1 M
<P><FONT color=#0000ff>/* clean up */
0 n. N' U8 [6 O  ?0 q% e0 Vgetch(); 9 a1 d7 {  \) c5 r# F
closegraph(); # E6 z7 X( {: p. M$ X
return 0; 9 Y! e1 [# T* K0 Q
} 2 U* T, i; I! S5 z  J2 ~: D
</FONT>
, p4 X$ }6 X" S4 L7 }- L8 Z, s# y  ^3 @# S( x6 e6 P8 R
</P>8 K+ Q9 Z8 [) x  K
<P><FONT color=#ff0000>函数名: settextjustify </FONT>- R7 v" [, j! I# z9 ^' }
功 能: 为图形函数设置文本的对齐方式
# ]2 |* @$ F6 p) V2 |用 法: void far settextjustify(int horiz, int vert); 2 h7 ]0 m" G0 r% v- u
程序例: </P>- T( m" Q* ]9 P3 U3 L
<P><FONT color=#0000ff>#include <GRAPHICS.H>& ~2 T1 l. B7 k# v4 q8 g# h
#include <STDLIB.H>, |' {5 F. V# q/ g% b4 u
#include <STDIO.H>. L% A; x* u7 ?, |4 l
#include <CONIO.H></FONT></P>
/ P9 a# ^4 |$ h; I  v<P><FONT color=#0000ff>/* function prototype */ * m6 _- A; y. r7 S4 {' a" d: S
void xat(int x, int y); </FONT></P>; t0 q+ c+ `) S: o3 E  v' `
<P><FONT color=#0000ff>/* horizontal text justification settings */
* S* [3 {5 ~9 n2 M3 Q/ Kchar *hjust[] = { "LEFT_TEXT",
( h' T" f- l( q. ^+ T"CENTER_TEXT", ( N! I' S5 V* ?: U; U
"RIGHT_TEXT" : o0 R; V# @" X+ l) }
}; </FONT></P>
0 ]9 O/ b2 e, |) D+ H; `<P><FONT color=#0000ff>/* vertical text justification settings */
( s9 n0 Z" ]) k5 ^char *vjust[] = { "LEFT_TEXT", ( M$ O3 `' E. a& t
"CENTER_TEXT", 4 M( R. \) z; `; @8 U  n
"RIGHT_TEXT" 8 E5 z0 i* F# n4 x" U4 J" Z
}; </FONT></P>: T/ k9 O3 b8 d* o  Y/ l
<P><FONT color=#0000ff>int main(void) ' M% E+ r! L# W8 R8 e  }
{
9 g) P( J3 t9 N4 `$ R6 P- P# n. A/* request auto detection */
' u; ~$ `) C+ p- b, L$ G4 Wint gdriver = DETECT, gmode, errorcode;
+ i3 t- c, P- n/ q. ^$ Xint midx, midy, hj, vj;
6 }$ v) W: \  _# Xchar msg[80]; </FONT></P>! z( K6 V4 b# p% v- y" K
<P><FONT color=#0000ff>/* initialize graphics and local variables */
% s9 n2 x6 b& n: Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ X: @  o  G1 J' `) R<P><FONT color=#0000ff>/* read result of initialization */ ; {( o. n( A+ t+ V0 r% G4 A
errorcode = graphresult(); ' V  {  u9 L% L: \) w6 o
if (errorcode != grOk) /* an error occurred */ ( q1 m& S; \  p8 d: R- {$ P5 l; n$ ]
{
8 m+ T+ R5 F! o: d- l4 ?! Vprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ; E7 H2 x& J7 z% M
printf("Press any key to halt:");
9 f) H% |6 {+ A% ]9 M" b- igetch(); 5 a! Q& O& X( q( I. u
exit(1); /* terminate with an error code */ + g* U. I6 D( }% J
} </FONT></P>( n0 d) Y. B* R9 m: _0 b. i5 y
<P><FONT color=#0000ff>midx = getmaxx() / 2;
8 ^$ c0 m7 W" [, J7 F9 E+ vmidy = getmaxy() / 2; </FONT></P>2 a9 e8 G  C7 K# y% m( g' X
<P><FONT color=#0000ff>/* loop through text justifications */
9 z; ^- ?6 T2 F: N+ x( }' ofor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) - g7 f  z6 H) T# e; Q; A' _1 |
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
: v1 O8 C6 `8 l& [. L! C, v5 u{
) M/ f3 G' \: [1 |/ p) E4 Acleardevice(); 0 }9 ]8 J+ \: ?
/* set the text justification */
2 D4 y! d. F# R4 v4 A' \settextjustify(hj, vj); </FONT></P>' e3 }& c  ?7 t6 Q
<P><FONT color=#0000ff>/* create a message string */ & X2 e+ a2 O2 |: s0 v4 L
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>" o2 F* D6 E) y' m
<P><FONT color=#0000ff>/* create cross hairs on the screen */
; N* Y& c* g7 Rxat(midx, midy); </FONT></P>8 l4 V: B0 C# }. h, I
<P><FONT color=#0000ff>/* output the message */ 3 |0 Z2 T+ O. O7 |% x
outtextxy(midx, midy, msg);
4 p9 L* H3 e/ ygetch();
2 g2 f9 Y0 p+ o) U# X} </FONT></P>
3 G9 `8 i- B  D; Y( J4 [<P><FONT color=#0000ff>/* clean up */ 2 `- z4 x& x& v8 K
closegraph();
2 Y4 n+ y1 ^; d  j: z( g4 V+ Mreturn 0;
7 @; ^7 _, P6 d$ n0 Q3 H8 ]} </FONT></P>9 l/ E7 y. t! u+ O' w+ f
<P><FONT color=#0000ff>/* draw an "x" at (x, y) */ * f( Z  D" T, v( I
void xat(int x, int y) $ i5 Z& F2 O1 L; Z; b+ X, Z
{ $ O3 d8 s" ]8 A& d: R
line(x-4, y, x+4, y); / T  C1 b$ \) L* F
line(x, y-4, x, y+4); ! b2 [! X2 a* S; D
} </FONT>0 ]. R. o" k; B: B" R
# h; B  x+ O8 B9 |. ]
</P>9 m4 d+ ?9 ?; }: G& G% J
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
, l. S9 {( q0 N, k" T2 S功 能: 为图形输出设置当前的文本属性 4 |* ?7 O; Z- h7 u  o/ \
用 法: void far settextstyle (int font, int direction, char size); 5 w8 w: O, D* U1 \8 z+ Z
程序例: </P>
% W: S) N) T8 Y2 S8 Y<P><FONT color=#0000ff>#include <GRAPHICS.H>
- {: c4 o2 A8 f8 Z, b#include <STDLIB.H>; J; r4 S$ x& d' g
#include <STDIO.H>5 X2 y% c# A- b( _# G
#include <CONIO.H></FONT></P>: _' e: p- D! B. `% n6 g4 |6 o/ G
<P><FONT color=#0000ff>/* the names of the text styles supported */ + }0 h- M7 s3 O* k
char *fname[] = { "DEFAULT font", 6 d- d% v6 L& j& a4 c; {7 ]
"TRIPLEX font",
: O3 Z$ T0 \1 V' F4 h"SMALL font", 0 O$ c! M/ O8 q) c; A$ ^2 \
"SANS SERIF font",
4 l# H& m" M6 S% ?# e) W"GOTHIC font" ) X. x+ y$ B2 N1 Z6 `$ D9 a
}; </FONT></P>
/ x' f  o! x, h0 ^+ M<P><FONT color=#0000ff>int main(void) . u' J# Z! L. ^" V5 w$ b& o
{ % z! X3 I  Q# E2 U, V$ U
/* request auto detection */ ) O+ R/ t+ I) A% Y2 d3 i0 D
int gdriver = DETECT, gmode, errorcode; 8 _- N! c% p  o" J9 z
int style, midx, midy; ! ^( J1 {* J2 H6 h. o& e
int size = 1; </FONT></P>; I3 H) {! O/ b' {$ F) Q
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' m5 |2 p/ x3 A2 I
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>0 C' E% l* V& ?9 n$ t  \: x% M
<P><FONT color=#0000ff>/* read result of initialization */
. ]$ b$ e" }3 f* d0 X. u  S& Serrorcode = graphresult(); - v  I( Z' ~1 ]: t
if (errorcode != grOk) /* an error occurred */
  T$ }* V( s, y: {2 ~: [; M( C{
7 f) }- y; [* @& F* v- C+ Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' Q7 h3 d) B- l2 |. P
printf("Press any key to halt:");
& P  l2 c8 a& U2 ]: Mgetch(); 2 i$ w! r: r- M  K, U  C0 J/ ~
exit(1); /* terminate with an error code */ 8 z3 u+ J' F/ \0 T0 y3 T
} </FONT></P>
4 q4 K$ B5 m3 Z9 l<P><FONT color=#0000ff>midx = getmaxx() / 2;   T' e! n' f  i% t! Q" d& G
midy = getmaxy() / 2; </FONT></P>9 _; `4 u  n) t( H4 l
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
) z8 C1 Y; d) B, \1 O<P><FONT color=#0000ff>/* loop through the available text styles */ $ [" {8 o1 a) [; c
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
" {- p* p) ^2 d# k) k' T- z{
! M( N/ I! `! T  n/ P, l5 P2 {$ Fcleardevice();
: M- R" ?" J% C4 d" pif (style == TRIPLEX_FONT)
1 ~3 p- O4 d6 |) Q1 _" Lsize = 4; </FONT></P>
: G8 d% e' T; j( D% Q( ]<P><FONT color=#0000ff>/* select the text style */ 4 k" s2 f- Z8 f5 F( @
settextstyle(style, HORIZ_DIR, size); </FONT></P>
% b7 W0 s" L% L7 H; ^<P><FONT color=#0000ff>/* output a message */
! P" `: E1 r6 routtextxy(midx, midy, fname[style]); # m3 X  B+ |$ [- l
getch();
% n1 K# ]* T" h: n  p. o, h5 M} </FONT></P>5 v7 b+ I* r; u8 ~" ]9 w
<P><FONT color=#0000ff>/* clean up */
# o# h) i# \# l& vclosegraph(); ' c" F- g/ H4 y# d2 ]
return 0; 0 |, o7 s4 s5 I
} ) e+ }6 O2 g3 f
</FONT>- M/ z; X6 I5 O$ d# E( V
</P>& M9 h% a3 V3 K$ z7 |7 l  F
<P><FONT color=#ff0000>函数名: settextstyle </FONT>( E8 M. ?/ [3 }7 P$ q
功 能: 为图形输出设置当前的文本属性
5 n7 @; X, Z' E) d用 法: void far settextstyle (int font, int direction, char size); ' B) u3 O5 R( g- n* F
程序例: </P># X/ w' C- N3 A- L) `
<P><FONT color=#0000ff>#include <GRAPHICS.H>6 |. V- q6 J+ H6 x
#include <STDLIB.H>
' p/ h, B9 N6 `* {( x( Q#include <STDIO.H>
5 R7 ?  t# ^' i( N#include <CONIO.H></FONT></P>
+ U3 L5 M1 {* v* K<P><FONT color=#0000ff>/* the names of the text styles supported */ 1 X$ b2 v7 \( e- ~5 B$ J7 n
char *fname[] = { "DEFAULT font", ( R% L' Y2 s! Q8 Q; ?2 C
"TRIPLEX font",
9 l3 o: d$ g+ E8 W"SMALL font",
6 p, R6 p9 U4 G( [# k9 k"SANS SERIF font", 5 b, e! b" i0 u/ K+ S, I
"GOTHIC font" ; B" G6 j, ?* b5 |9 }+ E
}; </FONT></P>
: m4 E# y) x, ^<P><FONT color=#0000ff>int main(void) + j- e1 s3 Q( s0 S, Z
{
5 N- F' H3 Y* {' _$ S2 v1 f/* request auto detection */
& M/ h- M8 e3 Yint gdriver = DETECT, gmode, errorcode;
, p8 G! y% o1 w+ G: d: aint style, midx, midy; + i( {) J$ l1 Q* f1 T' T( a
int size = 1; </FONT></P>
- l9 I) E2 L! m0 o# p% U<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 d9 G2 P0 s& Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 g8 a0 r; C; w3 z  S, h
<P><FONT color=#0000ff>/* read result of initialization */ ' ?3 u8 r  t% a
errorcode = graphresult();
" T3 k5 c" K, N! X" t$ N0 Oif (errorcode != grOk) /* an error occurred */ 9 R5 f; ?6 r! |: z
{ 3 T- v7 y) _! z. V; x
printf("Graphics error: %s\n", grapherrormsg(errorcode));
; A2 F( b8 Y& Z6 A( \3 `( Nprintf("Press any key to halt:");
% Y. |" l) T% u" v: L& v8 R% S1 C1 Tgetch(); . r- z- u* C$ N, Z6 M0 Q  V# t
exit(1); /* terminate with an error code */
  t) s* ^6 h7 `/ [} </FONT></P>
( T# b, K) i0 R2 R- E/ o<P><FONT color=#0000ff>midx = getmaxx() / 2;
  R3 M9 {& A/ r0 k& Pmidy = getmaxy() / 2; </FONT></P>
0 d8 p, V% A1 r* N8 ]<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>! T2 w' ~; t. _
<P><FONT color=#0000ff>/* loop through the available text styles */
' ?/ p( \" k* l$ T! Cfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
* v+ }8 Y, e9 n& Z5 Q5 W) g{
% P3 h; Y8 F& \* _1 ycleardevice();
0 p' k$ j9 _! U! X3 y6 H1 x6 mif (style == TRIPLEX_FONT) 9 n: e1 [% V  h9 P$ N
size = 4; </FONT></P>& p5 }; T2 U* ^9 Q' D
<P><FONT color=#0000ff>/* select the text style */
0 B7 H8 K$ C8 r5 ?+ a' [8 hsettextstyle(style, HORIZ_DIR, size); </FONT></P>
: j1 h* e  L) A8 E2 k3 w: b9 L<P><FONT color=#0000ff>/* output a message */
/ Z3 n( Q& d6 B- ]( U1 w6 ~9 X) aouttextxy(midx, midy, fname[style]); 3 F, {4 q) g. h. R
getch(); + z4 t! b3 Y4 Z9 ~# |- f" ^
} </FONT></P>
. m4 C, p7 [) e. @5 q' ~9 p<P><FONT color=#0000ff>/* clean up */ ' ~7 i( p2 l" y8 }) `( U5 g; q
closegraph();
) I4 x$ |& J" r$ B$ j4 Sreturn 0;
( f  o  C/ K! @  k0 M7 z* Y} </FONT>: ^( C9 N- w# R1 J1 |% w' n

' f" k! K1 k& B7 v9 a5 f: z$ G$ ^! n</P>! k4 l( g3 W4 R
<P><FONT color=#ff0000>函数名: settime </FONT>  E8 l1 g/ S( Z8 h
功 能: 设置系统时间 1 n6 s" D; T. Y8 z; u3 c8 J* P
用 法: void settime(struct time *timep);
# {+ l6 r: p8 O程序例: </P>1 I! `4 X6 O( b
<P><FONT color=#0000ff>#include <STDIO.H>9 c4 D3 N& D2 `* g  ?% H- u: o
#include <DOS.H></FONT></P>
8 W6 O; w  _( d7 ^1 E9 X& K<P><FONT color=#0000ff>int main(void)
# w1 k0 E" m$ S- s9 Q3 x0 J{
+ ^3 a) }' [* B$ {- astruct time t; </FONT></P>
4 Z3 L, s" D- e5 ~" I<P><FONT color=#0000ff>gettime(&amp;t);
3 j! L# v& |2 p9 ]) }9 aprintf("The current minute is: %d\n", t.ti_min);
+ `7 o! Y( d2 lprintf("The current hour is: %d\n", t.ti_hour); - ~* v% ~! L/ ^6 j
printf("The current hundredth of a second is: %d\n", t.ti_hund);
2 k. B4 ?& j* n0 E+ o4 Tprintf("The current second is: %d\n", t.ti_sec); </FONT></P>
! D: g' ?( f$ a7 v/ h* H2 m<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
+ M' v* l. {) j; X8 Ot.ti_min++;
5 q7 G: x& K! @settime(&amp;t); </FONT></P>, {/ a! G5 C/ u) A
<P><FONT color=#0000ff>return 0; ( F$ K, A# K3 v+ _0 p
} </FONT>
/ P& }0 U" N, T4 P4 ]9 \( J% W9 t# F6 _* ^! c
</P>
9 {' ]0 N5 }* l" X# T; F<P><FONT color=#ff0000>函数名: setusercharsize </FONT>. k; G! b  m* `) S$ h3 J! q2 L
功 能: 为矢量字体改变字符宽度和高度 1 L; `6 Z- z' ~: C7 @- Q& _
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry); ; C, w  F( y" \( e" P+ G9 h/ k+ L
程序例: </P>
. m9 a5 y8 R* P' U/ [  F0 s<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 }4 V) i- o* n- o+ ]& T- J#include <STDLIB.H>
% o% E$ J! y% u; ~) G& k8 [#include <STDIO.H>3 u. s- p* C- `/ n& T% x; q! F; e
#include <CONIO.H></FONT></P>
4 Y) c% o- T; h9 P<P><FONT color=#0000ff>int main(void)
# S4 l# s* r3 l% s8 z{ & X& ^) S" g2 |6 ?+ U. B
/* request autodetection */
1 ~' `9 Q+ ~  ~; E) [4 Wint gdriver = DETECT, gmode, errorcode; </FONT></P>  Z, f$ Y  {- D: n* _% h
<P><FONT color=#0000ff>/* initialize graphics and local variables */
) E$ I" i- I* T' y; D$ \/ @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 k- b: G8 f: g" u( G: v) x+ F
<P><FONT color=#0000ff>/* read result of initialization */ 4 d3 p7 w4 E5 [6 G
errorcode = graphresult(); # O8 K+ p* b- M% g
if (errorcode != grOk) /* an error occurred */
' B$ s3 X  P6 F; e- L6 A; V6 e{ 1 ~# j' P) v% M9 y( o- Y" U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 d; q1 |# l2 D2 n
printf("Press any key to halt:");
5 f7 q3 G0 t/ R) w( L8 b- tgetch();
9 J" \, d$ X+ Lexit(1); /* terminate with an error code */
2 D+ f  r( P) ^/ E- |} </FONT></P>
' L0 K* @8 ?( ^" V8 i) m  M<P><FONT color=#0000ff>/* select a text style */ 2 P* E& v$ X) X5 r. I& F
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>- k4 O6 J9 X' U2 Z, p8 h
<P><FONT color=#0000ff>/* move to the text starting position */
; J. I) s; A% pmoveto(0, getmaxy() / 2); </FONT></P>9 U" q) N# S7 g9 A8 e4 D; G% a
<P><FONT color=#0000ff>/* output some normal text */
' Q6 W2 b- e4 z& \4 Y' C) Houttext("Norm "); </FONT></P>
& S- h. A4 t! t1 [<P><FONT color=#0000ff>/* make the text 1/3 the normal width */
; J1 p4 k& Z+ b. q- Gsetusercharsize(1, 3, 1, 1); " A7 q" o1 \# p. ~) l
outtext("Short "); </FONT></P>" B" K$ U/ x# i0 z8 E  m1 o% z" r+ n
<P><FONT color=#0000ff>/* make the text 3 times normal width */
' m- f* ~+ m+ v) fsetusercharsize(3, 1, 1, 1);
" U$ v8 C1 W/ a$ \outtext("Wide"); </FONT></P>4 c5 A# D& M& u/ P
<P><FONT color=#0000ff>/* clean up */ : f- `' A* j2 J2 k* ?& E
getch(); 8 }9 ~1 M6 m# _! a
closegraph(); ( d6 P$ n. L4 J8 }" a2 y, p7 z
return 0; # L2 N  O% U+ W& i( a
} </FONT>
! V2 b7 d: f& O1 x0 H</P>4 G2 y; z. s& {0 l+ X9 {8 G2 |7 r) |
<P><FONT color=#ff0000>函数名: setvbuf </FONT>
; N4 H- L# U  E  j功 能: 把缓冲区与流相关 & j/ w9 C2 L+ h' F
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); 2 `1 D, j* d/ b0 q+ A
程序例: </P>
$ v6 C( d1 [# d  m2 J/ g<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>3 ~: O2 ]' _9 B
<P><FONT color=#0000ff>int main(void)
4 M7 N' h- `' X' q3 Y6 H; |{
: X9 [& L, ?. x/ LFILE *input, *output; 8 e4 ^6 U) M5 f( {& h' M! i& U
char bufr[512]; </FONT></P>
6 V4 D3 B# C. L, h; b- K<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
# G0 y+ y+ R" y7 `output = fopen("file.out", "w"); </FONT></P>( X% j& c) [; o8 n9 B7 g9 X
<P><FONT color=#0000ff>/* set up input stream for minimal disk access, % k) \- w: t' i) U. Q  ?
using our own character buffer */
  R! Y% y/ a- s* j  u6 p& t8 ^if (setvbuf(input, bufr, _IOFBF, 512) != 0) ' }! _7 u7 P6 @# ?& `0 X* v$ d+ |
printf("failed to set up buffer for input file\n"); - _1 D8 }6 M! S' i
else
+ I7 \/ L3 _  tprintf("buffer set up for input file\n"); </FONT></P>6 r: _$ d  l0 P$ f1 R5 R6 j
<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
) K$ Q8 v% ~$ G) ]will be obtained through an indirect call to malloc */
) T7 `4 v) {$ ]' ~, x# Zif (setvbuf(output, NULL, _IOLBF, 132) != 0) 9 l9 y' A0 c) S# R2 B
printf("failed to set up buffer for output file\n");
3 b: c1 V/ L( U% aelse 2 Z) {4 w; F# J! w/ f; l
printf("buffer set up for output file\n"); </FONT></P>: {3 p* v. V2 J! ]. _
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P># ]% m- E9 Q- I( t, r
<P><FONT color=#0000ff>/* close files */ & O* t8 W3 M4 ~! B/ }
fclose(input); + Q1 G  y, s$ a0 r1 Q+ }* _
fclose(output);
0 ^) Z6 F' o; i- Q6 areturn 0;
* R" }8 ^6 E8 E* L} : k6 D: @, ?! D2 S5 z1 c. M2 |4 v
</FONT>
, @2 e7 `. e4 h: e0 C$ Q
0 M' D$ X- I. f! T7 v</P>7 b; {+ |. D. Y" f% B0 H
<P><FONT color=#ff0000>函数名: setvect </FONT>
' N5 P! \  m1 {1 i功 能: 设置中断矢量入口
; v5 J+ p7 ?- u3 T. H! r  T用 法: void setvect(int intr_num, void interrupt(*isr)());
  J# O) C+ h& k; h; v( N程序例: </P>
+ z1 m) C- H7 H1 {! v( h0 S/ b<P><FONT color=#0000ff>/***NOTE:
' O- t# f6 ?' D/ aThis is an interrupt service routine. You can NOT compile this ' ]! R! q# W3 [; d' d6 b
program with Test Stack Overflow turned on and get an executable
4 n3 _( }2 F% ^# M. M" M% vfile which will operate correctly. */ </FONT></P>
2 ]0 L( T* t. t7 Q+ r<P><FONT color=#0000ff>#include <STDIO.H>
1 j  P: o. l7 N7 _( w# R#include <DOS.H>
5 Y3 `% @1 y5 y( I1 |6 B3 Z#include <CONIO.H></FONT></P>
7 q0 ?3 \( B2 n' [7 _<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>
8 k5 A- g- c( o- [<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
* B2 ]! [2 t3 s* [<P><FONT color=#0000ff>int count=0; </FONT></P>: g  H+ {0 [' L" [- j0 H
<P><FONT color=#0000ff>void interrupt handler(void) 8 s" R, U1 m4 Y$ v0 n! i1 f" f( H
{ . J$ V$ J6 h' `$ u/ |1 F
/* increase the global counter */ 4 B+ p/ @* t# P. ^6 D& M# h2 D' U
count++; </FONT></P>9 q+ e4 [: y% B0 P0 @  t. ~
<P><FONT color=#0000ff>/* call the old routine */
- u+ S. E0 F4 q+ Zoldhandler();
- q  q0 ^5 T1 J, _1 F} </FONT></P>: v" U9 K7 h$ p* O5 f  g5 E
<P><FONT color=#0000ff>int main(void)
  G" A  p* |, D% x{ % ~- Z, }( F8 k
/* save the old interrupt vector */ 7 O; v' W$ ~* A9 i, }
oldhandler = getvect(INTR); </FONT></P>2 O5 _+ c- @+ B
<P><FONT color=#0000ff>/* install the new interrupt handler */ 3 i# n  {+ O( y, Z9 s
setvect(INTR, handler); </FONT></P>
: M1 E) e% T1 g$ Z5 x<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ / |6 C8 C. ^! F% t, T( H8 w+ l
while (count &lt; 20) 1 M/ ^1 n8 X6 i0 }$ e1 s
printf("count is %d\n",count); </FONT></P>* X. B' E9 z7 W& ^6 y6 N+ N* ~
<P><FONT color=#0000ff>/* reset the old interrupt handler */ 4 W( M4 u8 A1 ~. G# [) z
setvect(INTR, oldhandler); </FONT></P>
& h  x- O6 O8 q( V; S% O<P><FONT color=#0000ff>return 0; 9 m9 n# w0 S" a$ N0 {  X
} ; h4 ]; w. h9 I( Y6 k! e* N* }6 c
</FONT>
2 b( ?( l# o7 @/ |! i5 r</P>4 u$ z0 p& D! Q) H$ C" T7 D3 M
<P><FONT color=#ff0000>函数名: setverify </FONT>
% D8 S: I8 B4 H2 g; o& ?6 R5 X. _2 o功 能: 设置验证状态 * F2 i' Q* c) |* f, L  h" h
用 法: void setverify(int value); ; H: x+ Z5 C: I5 n
程序例: </P>' _" r* C4 G; e' [; `# Z: {( G- m9 l+ y
<P><FONT color=#0000ff>#include <STDIO.H>
# o$ ^8 k' [( P7 B  V4 S% o#include <CONIO.H># {4 W) c0 F! W% K
#include <DOS.H></FONT></P>
& O  w+ |9 A5 R5 T- Z<P><FONT color=#0000ff>int main(void)
; e) V$ u1 c% R# V* r# ~! P{ # m! @. C* j0 `0 h0 f
int verify_flag; </FONT></P>! P! O* ]$ |9 d9 i) j
<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); " }5 X3 r1 T, K& v) v6 E' K; d5 Q
printf("Enter 1 to set verify flag on\n"); </FONT></P>0 W) }" n2 \6 d0 j6 [9 o
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>
! H$ b; U6 D+ y/ ~9 F& G<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>. {  e" J- T) m! X0 q( K) ]
<P><FONT color=#0000ff>if (getverify())
+ `/ y4 `2 z# h, jprintf("DOS verify flag is on\n");
+ ?2 z# I0 f. s7 n' D/ n3 C6 `else
, h8 X- ?' b& Z. N+ L8 cprintf("DOS verify flag is off\n"); </FONT></P>* O6 I" {6 f+ q% \
<P><FONT color=#0000ff>return 0;
7 p( i! o- _9 X4 k3 B7 Y1 l}
0 D9 O, R, q/ i: |! P, ?1 v& b<FONT color=#ff0000># W; I# N; u4 O3 G8 ]' ]
</FONT></FONT></P>% ?5 |: ?. v" B# w6 ~; P5 o
<P><FONT color=#ff0000>函数名: setviewport </FONT>0 f4 Y% x6 U8 e
功 能: 为图形输出设置当前视口 - C0 m( F! @) P$ r" j: Y: z
用 法: void far setviewport(int left, int top, int right, - f- u, l  P* o
int bottom, int clipflag);
1 [, y' r: z+ m2 G% N/ l* C; c* p9 ]程序例: </P>
, X: S- a4 M7 Z2 f$ Y, I<P><FONT color=#0000ff>#include <GRAPHICS.H>1 {1 G& h4 o+ t0 s0 D  a; K
#include <STDLIB.H>
! F, O. E' s; Z4 K#include <STDIO.H>
" \% a6 K% U# g  X#include <CONIO.H></FONT></P>
, v$ t6 r0 _. C" u<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
( F" M( p& x7 Y! F. f5 h<P><FONT color=#0000ff>int main(void)
) v8 @/ E6 x& u{
0 p* E- }. B6 r2 F' _  o6 G/* request auto detection */
4 m8 N+ G+ P" N3 m2 t8 gint gdriver = DETECT, gmode, errorcode; </FONT></P>
! [1 H0 y: L7 q4 j. a- p1 N<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 ]5 L! r$ W4 W/ X$ p! V! Z0 T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, R4 y5 Z6 I! f& T
<P><FONT color=#0000ff>/* read result of initialization */ , B3 |' U. X0 w- W* \0 Y4 o2 w
errorcode = graphresult(); + ^) |& O5 Z2 Y# \
if (errorcode != grOk) /* an error occurred */ ' H  |8 Y  \- o! u. |
{ 5 W' v- z& t/ ^: x$ `
printf("Graphics error: %s\n", grapherrormsg(errorcode));
& x* @/ I4 U7 Y/ h2 x; H# k2 hprintf("Press any key to halt:"); / N. t1 J. Q8 U5 O# |
getch(); - i7 G+ |5 T# ?; b2 Z
exit(1); /* terminate with an error code */ 4 ]9 X% d% o, z4 b/ O
} </FONT></P>
4 d+ b1 i1 S  r  ^$ i' Q<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
8 @$ ^4 m) q) t  A  v<P><FONT color=#0000ff>/* message in default full-screen viewport */ 2 d! Y& ~' Y7 m6 Q0 r; S4 }1 E, E! J
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
; S% R/ m- Q* C+ b<P><FONT color=#0000ff>/* create a smaller viewport */ ' B( k( U8 x2 s6 t4 }& G
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>' k9 {* G/ j) u
<P><FONT color=#0000ff>/* display some text */
) e7 \, l' H" K& e8 Z$ j6 Souttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
, ^% N0 P( |: O6 v<P><FONT color=#0000ff>/* clean up */
1 b- \, C  `9 d) U" p7 Y4 ?& ~getch(); ; V2 p: c2 j2 X: y/ P3 M
closegraph(); 9 A1 q+ ^6 [) I' V7 p
return 0; ( ^; C8 {9 J9 [1 ]6 X
} ' {5 C0 c4 x  c; s
</FONT>/ _. Z, j8 X% K% k! C+ J
</P>
, D' f2 `$ y3 q1 c<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
: K  q5 a+ I" Q" Z6 z9 v2 N1 E功 能: 设置可见图形页号
! j$ r# y8 S* ~7 ^用 法: void far setvisualpage(int pagenum); 8 d( Z* j! Q3 R4 t7 z% f
程序例: </P>
; N! O* t/ f4 t& C7 V6 K<P><FONT color=#0000ff>#include <GRAPHICS.H>" E+ V0 c* V% Z3 n' @; |: |7 m: k. t
#include <STDLIB.H>
3 m+ B) `2 T% W1 P#include <STDIO.H>
9 ]/ k% f  S; L0 f# j#include <CONIO.H></FONT></P>& i* A( n5 x+ m  i  L3 |
<P><FONT color=#0000ff>int main(void)   x* H. h, M' _8 J  Z
{ 5 v( d& `, @4 e) D
/* select a driver and mode that supports */
% }' m' r1 o3 ~' N# M5 h9 h/* multiple pages. */ # o# I- o0 }3 J2 I! _6 i- q
int gdriver = EGA, gmode = EGAHI, errorcode; 8 |. ?2 i5 W1 L# x0 F. i4 L
int x, y, ht; </FONT></P>1 k- W5 d! \2 F% |2 u
<P><FONT color=#0000ff>/* initialize graphics and local variables */ * q! _  i* y" w7 Z8 M
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" Z( e+ o. \1 ~, W
<P><FONT color=#0000ff>/* read result of initialization */ 9 N3 x9 C+ s  b" f6 h
errorcode = graphresult();
- P1 M$ w2 @" Z1 e" L: Y* Gif (errorcode != grOk) /* an error occurred */ 6 l0 @1 T$ U+ G9 @! j
{ ( O: e# l6 v* r: }* l- N
printf("Graphics error: %s\n", grapherrormsg(errorcode));   y! `) s) \/ C' x3 r! k" q( l
printf("Press any key to halt:"); ! f' ]$ L0 T6 F9 f3 i! Y4 S
getch();
' _- R: Q6 H) t: m- L3 c; Fexit(1); /* terminate with an error code */ 2 H' u6 U! X; x, t8 w( @5 P( I5 D
} </FONT></P>8 U0 S5 r* f) J* T, o
<P><FONT color=#0000ff>x = getmaxx() / 2;
5 U, u+ }* b5 _/ ay = getmaxy() / 2;
' d9 V- Z4 E! u) pht = textheight("W"); </FONT></P>
' ~( t  e6 X1 h) R! J# S7 l" U<P><FONT color=#0000ff>/* select the off screen page for drawing */
* T: [) K7 U, bsetactivepage(1); </FONT></P>
  q2 \; Z5 M. {/ a0 O; c<P><FONT color=#0000ff>/* draw a line on page #1 */
1 ~+ I" Z, S2 |1 k$ Y$ k' i7 Sline(0, 0, getmaxx(), getmaxy()); </FONT></P>
) ]9 x7 \( `, H$ y) V( D<P><FONT color=#0000ff>/* output a message on page #1 */
# ?$ m5 f" M! N/ U' k% l: Lsettextjustify(CENTER_TEXT, CENTER_TEXT); 9 c4 Y- l3 s3 v
outtextxy(x, y, "This is page #1:"); " S; k9 d& H2 e7 A% l$ ~" l  Q* M
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>9 q; I& \9 ~- d6 w
<P><FONT color=#0000ff>/* select drawing to page #0 */ $ I4 e  o2 r' e
setactivepage(0); </FONT></P>6 u! q  B( A# \
<P><FONT color=#0000ff>/* output a message on page #0 */
+ V0 Z. m- l0 N  aouttextxy(x, y, "This is page #0."); 1 x7 c4 j; m- D# |7 I) }& @
outtextxy(x, y+ht, "Press any key to view page #1:");
) c' h! Q% [* C2 d3 W  X  b) B- Hgetch(); </FONT></P>
# S3 O5 |6 |( d+ h5 c! w1 |<P><FONT color=#0000ff>/* select page #1 as the visible page */ # b+ V5 ~2 q/ V( y
setvisualpage(1); </FONT></P>3 x* Z5 Y1 p8 H# P* c
<P><FONT color=#0000ff>/* clean up */ . n6 F# G2 l, j" d; x, |
getch(); $ d- i( u" ?( D7 ~& }9 q
closegraph(); 8 `, [) R& [# n3 S; p+ U
return 0;
( S( ?; C& t( W" ?% e- J* G' a0 j} </FONT>
6 S4 A& D& F% S9 I* C; z  l( `2 v) y; L1 @6 l
</P>
# Y& f& n% b. z( ^8 v<P><FONT color=#ff0000>函数名: setwritemode </FONT>& b# Z8 n' [* }1 q: }0 z
功 能: 设置图形方式下画线的输出模式 , L  U" B% w) L
用 法: void far setwritemode(int mode); * H! G' D- c9 d) }6 h; T
程序例: </P>
/ m8 K, ]$ |8 w; ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
  s4 ]" W! |; J, s  @#include <STDLIB.H>/ D" y2 |& f* V* c' d
#include <STDIO.H>
) X. e5 E! q7 j& R9 z#include <CONIO.H></FONT></P>' }1 E7 Z) t9 \7 D4 y1 @
<P><FONT color=#0000ff>int main() ' s( {4 k5 T5 a  o5 T
{ ' a) P* R- u3 u6 C5 V
/* request auto detection */
! L1 I8 V4 V+ _, _9 h2 ^int gdriver = DETECT, gmode, errorcode;
: m. e7 K/ x; z( l0 D# _$ aint xmax, ymax; </FONT></P>; m( [$ E3 j& f( z* v$ H
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" _' G" R' H4 n4 E& Winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, {* ^, @* O2 X  S0 T1 D6 p
<P><FONT color=#0000ff>/* read result of initialization */
/ O6 _! p2 y, C( k* U" Kerrorcode = graphresult();
6 D7 t" E! K& M) Q5 K% \6 Nif (errorcode != grOk) /* an error occurred */
- h/ Q- S! p8 S& ]9 C$ X{ $ _' n6 o* _9 A) Z# m! r/ ^: u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 V' p0 L! D3 {, K
printf("Press any key to halt:");
* a/ q: X' p) g. Q" Bgetch();
8 G- ]8 E( S9 F( N! W1 Rexit(1); /* terminate with an error code */ ) ], T' s9 h2 M1 Y+ O
} </FONT></P>- H9 r( N  W2 K2 U* e( O& a9 B
<P><FONT color=#0000ff>xmax = getmaxx();
: w# l# D  o- q- D% K+ wymax = getmaxy(); </FONT></P>
$ ?: ]& o: F- ?/ M& b7 X<P><FONT color=#0000ff>/* select XOR drawing mode */
0 \0 d' ^' R( _' w  S0 Wsetwritemode(XOR_PUT); </FONT></P>( c4 w& y: r$ R6 s: V, h8 q
<P><FONT color=#0000ff>/* draw a line */
8 I3 o7 d; Z$ f, ]line(0, 0, xmax, ymax); ' G* a, T- O/ z3 |# T# |  f0 ]5 P
getch(); </FONT></P>
0 ]* ?/ Q2 Z7 x2 J<P><FONT color=#0000ff>/* erase the line by drawing over it */
% }) `" [( A, T+ Iline(0, 0, xmax, ymax);
) |4 _" ?8 k3 y+ m: o5 E* ~* ?8 ]getch(); </FONT></P>9 q/ |- Z* [1 o+ V9 f# d& N; o; V
<P><FONT color=#0000ff>/* select overwrite drawing mode */ 7 }5 p% h/ G2 A
setwritemode(COPY_PUT); </FONT></P>
& O8 o3 `+ ]3 P- R* X9 G! q- T  G<P><FONT color=#0000ff>/* draw a line */
( i( U5 \# z8 @3 Y/ x  Lline(0, 0, xmax, ymax); </FONT></P>; Z+ O5 C. @; V
<P><FONT color=#0000ff>/* clean up */
! V& R7 I& l  }; G, kgetch();
& n+ @. f+ x) ^0 t* Oclosegraph(); 7 }  w: O3 N. [% o6 z' H
return 0;
- j1 r( }& i# W0 j; N" G' {( ~% }: O} , e" E& @- \. l) f$ j' E5 @
</FONT>
* g( E3 c# J7 H</P>: T7 R: B" H1 Z
<P><FONT color=#ff0000>函数名: signal</FONT> 1 e, ^- q8 X5 M5 ?% e  q
功 能: 设置某一信号的对应动作
# F1 t3 z) w! s9 n  F用 法: int signal(int sig, sigfun fname); 9 p0 Z5 ~& D9 e
程序例: </P>) L9 R* p  q! K) T' U. g6 M, O
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, 3 U0 [) A) A6 I1 ~
catches an integer overflow condition, makes an adjustment 4 }: q5 o: \0 L9 ^! P% c; L
to AX register, and returns. This example program MAY cause & q7 l' I- W$ ]$ Y5 P. c$ C
your computer to crash, and will produce runtime errors - T# S- |' l* ?% M3 d4 _" F
depending on which memory model is used.
" L  p; {& N: P" [  j% S*/ </FONT></P>! {( i- `$ P2 x6 z* n
<P><FONT color=#0000ff>#pragma inline
4 t" l' S8 t& B) \" c" D0 c#include <STDIO.H>
( Q1 J- ]9 n7 G1 X+ }$ h#include <SIGNAL.H></FONT></P>8 U. m' }6 V+ _9 K/ q% r, [  D% M
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
" ?! F/ i% v) C4 n, O2 i: C{ 1 F3 X, n  n( k
printf("Caught it!\n"); ) ?. W3 H, B) t- ]5 S
*(reglist + 8) = 3; /* make return AX = 3 */
* ~' l7 \2 L1 i} </FONT></P>. [. {& y2 N- g
<P><FONT color=#0000ff>int main(void) " J( K) \( }& y" |; L
{ : c& ~% e3 J0 \0 b
signal(SIGFPE, Catcher);
( h6 X: {0 Z3 y$ Iasm mov ax,07FFFH /* AX = 32767 */
4 c: z- F( |: e8 T0 Wasm inc ax /* cause overflow */ 8 d* O" i' k  V% r* R. Y9 W
asm into /* activate handler */ </FONT></P>
1 }, ~+ B  f, t+ V  k4 d  d<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened,
: ?- Z. ~1 k9 Q$ O5 b$ L8 qthere would have been another exception when the next 'into'
# |3 X: G4 x/ Cwas executed after the 'dec' instruction. */ ; F5 k0 B& t: r8 V- ~) ]9 L
asm dec ax /* no overflow now */ " {5 G5 ], S2 Y% j7 N; [* T% y
asm into /* doesn't activate */
2 c' x) v; J0 H% `' Qreturn 0;   V, [% D! |' _
}
3 D1 m# h9 M2 @2 A' r  {* ]* f9 b/ e0 y
) A/ e( {4 S( F5 b4 \- M5 [- ?% v
</FONT></P>
2 a% l: S' z1 j' d" J. X<P><FONT color=#ff0000>函数名: sin </FONT>
( j* {% z$ e  D0 E- v. l" A功 能: 正弦函数 # A. }$ v- }- P1 P6 e7 _
用 法: double sin(double x);
$ x. N2 J7 o& ^; }程序例: </P>
- h2 ?  D; k7 b8 q; H<P><FONT color=#0000ff>#include <STDIO.H>
* u) j' h  N0 @#include <MATH.H></FONT></P>* ]4 J3 C0 L( x5 S; P1 D, v& g
<P><FONT color=#0000ff>int main(void)
* a4 F2 a0 @. L6 u{ 3 Y( u! M9 E# ^6 n
double result, x = 0.5; </FONT></P>, r3 ^. U; q& t
<P><FONT color=#0000ff>result = sin(x); 1 {/ C+ x$ X: \$ G2 d+ i
printf("The sin() of %lf is %lf\n", x, result);
' \+ a7 R- P$ h9 E4 ureturn 0;
' E0 Y% G  j& K  `$ p: b7 V} + X: p* Z. R( }' j- ~

! l% f7 ?  z- S( H; H8 i</FONT></P>2 m, Y7 L0 [6 ]  m( |  u3 Z. v
<P><FONT color=#ff0000>函数名: sinh </FONT>; ?# S9 n/ F3 |" I- f- Q& N, B
功 能: 双曲正弦函数 # s$ a) f% w" \
用 法: double sinh(double x);
4 Y4 Y4 H9 H4 a+ N程序例: </P>
- R7 q. y$ b6 P  ~<P><FONT color=#0000ff>#include <STDIO.H>8 j8 n" }- o0 |. d2 I/ A8 X
#include <MATH.H></FONT></P>$ c/ E8 g2 q- |! p) U, g" S$ B
<P><FONT color=#0000ff>int main(void) ! G' N* w7 t8 I* s  X. ^
{ " W& _+ L$ H9 t- f. G
double result, x = 0.5; </FONT></P>
' ^$ Q! s9 h' W: p% o<P><FONT color=#0000ff>result = sinh(x);
0 p2 b2 j" |# Q/ N2 U$ Z" D  \8 pprintf("The hyperbolic sin() of %lf is %lf\n", x, result); 9 @& i4 U2 q. }+ @- ]9 D0 M
return 0;
9 a7 e( q& K. c, |7 ?' X$ z}
6 f- [% Z6 t& n) O% j% V/ c
9 g1 P  R/ L; Y* M5 I2 p
  x: q% N# k6 G* K</FONT></P>
2 F+ E: {  y* o  Y9 f0 ^! \( X1 P<P><FONT color=#ff0000>函数名: sleep </FONT>
! R/ r9 W- y9 G: p) f功 能: 执行挂起一段时间
9 b0 q  i0 t6 @6 s/ @2 h8 \& \4 m用 法: unsigned sleep(unsigned seconds); 1 r9 f: ^! h$ k; X! F  @% P+ @. o, w
程序例: </P>
) s# n+ @+ b7 L+ Y+ K<P><FONT color=#0000ff>#include <DOS.H>9 b+ o4 p3 D# H; s
#include <STDIO.H></FONT></P>1 l& c) G9 v. A. }8 D
<P><FONT color=#0000ff>int main(void) 3 Z9 K& M4 q; H8 B# x
{ 3 D# X) P- Q8 {8 S, m* {6 W! @
int i; </FONT></P>
) c8 `" v' k) e! i<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
4 \' e" K: C8 o& W* j{
& w0 s  ^2 x* k* F* |9 B& V! `printf("Sleeping for %d seconds\n", i);
2 Q# `3 j" ?) W5 s; O1 J! t) Gsleep(i);
% V% b, t+ N: h0 E} : Y/ [- h2 r" X- r: }( \8 m/ ]& I" b- m
return 0;
! H) M9 `  }4 K}
5 f# Y* y4 m; B, \( v& X4 L; D2 k% E/ b
</FONT>
& r, e* H2 ]- S5 u: U4 ~</P># `* \5 _# K. @8 n+ W
<P><FONT color=#ff0000>函数名: sopen </FONT>
0 w6 G6 J% H" W9 W8 Q# |/ J5 A功 能: 打开一共享文件 0 O2 A  @" t$ x* ?5 k* h4 F1 H' L. P
用 法: int sopen(char *pathname, int access, int shflag, int permiss);
: D! Y( v! h* r- W/ g程序例: </P>( X4 P& ]/ Q8 t" m- }* {7 `
<P><FONT color=#0000ff>#include <IO.H>8 X; ~: K& w# A' ^% @
#include <FCNTL.H>1 S4 Y; G1 r  @. ?0 s* `" C  P5 {; E
#include <SYS\STAT.H>! e7 H* q& D# C$ s  Z
#include <PROCESS.H>
# {  G, j9 O/ H, u- [8 y#include <SHARE.H>; F& O2 I; n  C) f# l& k! }" d% _
#include <STDIO.H></FONT></P>( n- O3 U" |; b& h2 l1 ]1 H7 a
<P><FONT color=#0000ff>int main(void)
, |7 N1 v! i0 e- N/ F3 ^{
, |3 T) n% i  @: _/ qint handle;
  ]1 O9 o% T, q  Fint status; </FONT></P>
) K+ Q* H4 K* j& ^! W<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>6 {* m1 a8 y" k# ?5 U
<P><FONT color=#0000ff>if (!handle) 9 e6 {* Z* y1 ]' w
{ ! \$ L4 A9 D/ A3 W2 T
printf("sopen failed\n"); & S5 ]& D: s$ D& j9 e8 [- V# L! D% [
exit(1);
" `5 ^% k& _, [/ ]: a& f} </FONT></P>
# w' L, d1 C, ]( f<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
, W/ n' G. f8 c7 O0 M+ N: k6 ?if (status == 0) 2 k' Y2 l$ E9 _! C0 j  n$ g
printf("read/write access allowed\n");
5 s. J+ B1 z0 A# v- _else
& h* X* y: `) i' }4 fprintf("read/write access not allowed\n"); </FONT></P>
( A$ w( ^5 o. O<P><FONT color=#0000ff>close(handle); + y9 H& S& O% n2 M1 x% e
return 0; # H; A' i2 C( k. H- e( [0 J
}
- ~; e* H+ |& B" x1 ~# q( X6 t; C
</FONT>6 Y# v4 u' W* [- Q3 i% U
</P>) e5 \( U  I) ?) b$ o" g& X$ q, K
<P><FONT color=#ff0000>函数名: sound </FONT>
  k( z! R9 s0 q3 Y. y, e功 能: 以指定频率打开PC扬声器
' L9 ]: U  G3 V9 r  {6 y& e用 法: void sound(unsigned frequency);
  k/ p% ~3 n- k0 Q/ A8 P( I程序例: </P>0 ?6 Q! S7 [" \) L. ^: s1 ^
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. . X4 h7 c' ~: F. y  v3 r
Your PC may not be able to emit a 7-Hz tone. */ ( T" V5 b3 `* e7 v
#include <DOS.H></FONT></P>
6 ~8 ]7 ]& d1 j4 H# ?! T; s<P><FONT color=#0000ff>int main(void) 6 M+ V& u% q, y# P6 C  ]# H2 L
{ ) w4 ^, C% A  @/ [' a( s* Q7 S: |
sound(7); 7 Q) n7 Q4 }# j
delay(10000); ' J, E. u% E$ M  K* G6 m7 r
nosound();
* s. ^/ N5 L  _7 ?9 n. qreturn 0;
  i7 h( z/ \$ x: h) I) g" {2 V} </FONT>
  J0 g( c7 a' l: ]$ K3 }' M* @, y
0 M. q, j  L$ B* G8 q- g) N' ^) n2 G3 L
</P>& z% b/ u2 d" V5 D3 i
<P><FONT color=#ff0000>函数名: spawnl </FONT>
& u6 m3 l1 }# s! m3 S功 能: 创建并运行子程序
' D8 [0 s% E* V4 {) F/ x用 法: int spawnl(int mode, char *pathname, char *arg0, 3 f  K$ L4 \- H% I) j# w
arg1, ... argn, NULL); " j' z7 X( Y# {! G# w
程序例: </P>) L% I% N6 t0 N: @
<P><FONT color=#0000ff>#include <PROCESS.H>0 w, K6 `0 E" T0 D% k! U! M
#include <STDIO.H>  }- O7 D- E" S  f
#include <CONIO.H></FONT></P>  U1 X/ t+ d. [3 r* w; {7 U$ k
<P><FONT color=#0000ff>int main(void)
! n# K* Q* F6 \# @. r- K8 d, W. C7 G{
6 h6 ^" y" D/ ^1 {) {3 V6 Vint result; </FONT></P>( T# Z7 Z1 Y7 g$ H$ `2 I
<P><FONT color=#0000ff>clrscr();
, E; S  ]9 g1 u# {) Kresult = spawnl(P_WAIT, "tcc.exe", NULL);
9 L. y- I' `0 V* |if (result == -1)
# v& r' ~- K0 G) Q0 F{ / S9 E# j$ C& ^& y0 z4 o
perror("Error from spawnl");
) _2 a4 v3 k/ u1 m- o% E  W& ^exit(1);
2 |5 s1 ?- V' M. K}
" |) p1 N- w5 ^4 m2 B2 k: M$ ireturn 0;
/ x5 [9 I0 u; b}
  g" E# W- E0 [7 F</FONT>
) ^& D3 `. z, C' o* [</P>
0 u7 r" O; Z" `<P><FONT color=#ff0000>函数名: spawnle </FONT>
, y" |  q' ^4 T- H功 能: 创建并运行子程序 ! s5 F; g6 m- S5 u/ T
用 法: int spawnle(int mode, char *pathname, char *arg0,
- |0 K3 z) \3 f8 f. Q( T1 Iarg1,..., argn, NULL);
. x& F* Y. M  U' o  T程序例: </P>
0 c) C; f. E! `* J) }<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>
" q3 y/ ]! [, r) O+ y8 E8 `<P><FONT color=#0000ff>#include <PROCESS.H>& F- N) R! |2 ]
#include <STDIO.H>( N* L  T/ w7 `9 k( j; A
#include <CONIO.H></FONT></P>
4 Q& `% Y7 P3 `5 ]+ Z<P><FONT color=#0000ff>int main(void)
) g  @, P0 K$ E+ ]' j' Q5 j. N{ 7 T% L! E. q: i/ L9 s( e
int result; </FONT></P>
" J( f6 X  }$ O$ y% t4 p# H1 S) C<P><FONT color=#0000ff>clrscr(); ) x; A' A$ A/ R$ b! }9 `
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
( J8 ^* G& }9 {if (result == -1) 9 Q$ l' @/ {& U9 l. u1 n
{
3 P  {2 B* ~5 _, Vperror("Error from spawnle");
# Y/ v3 a9 ]- l2 Z. ?7 xexit(1);
! e, w  y  r. V3 Z, j2 U/ h}
5 `. R' D. F! s1 |( ]return 0;
+ ]! O0 c, ~$ I$ n1 \}
1 l( l, ?! S9 O8 \& [& Z' @3 D" J3 h. B9 S( d& A
0 z( L$ j) T: g% ^% O. `
</FONT></P>
! q2 p$ Z8 e1 q; _. Z$ [) k$ G# W3 b+ X<P><FONT color=#ff0000>函数名: sprintf </FONT>
5 Z0 ~- t6 X% z7 ~, ?! f功 能: 送格式化输出到字符串中 # R/ R% b: u( Z  l2 d, L+ @6 j
用 法: int sprintf(char *string, char *farmat [,argument,...]);
  N& l% n- Z* e4 B$ r程序例: </P>5 j1 ^  K* e3 r  H
<P><FONT color=#0000ff>#include <STDIO.H>
+ y) T8 [% K( H* B9 }! s: s% i#include <MATH.H></FONT></P>) S& B6 W! U; n" R: K5 y( w# u+ J
<P><FONT color=#0000ff>int main(void) 5 P; Z. O/ m8 I
{ - }, u1 M' ?9 o) r. L, g
char buffer[80]; </FONT></P>
3 V) f4 ^+ R& h<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
4 Y" L6 A7 D* o, |/ `puts(buffer);
9 c. j% C& o  R- \% Mreturn 0; 4 _# K) g6 e$ B2 e
} & U' F* b  s9 g8 W
</FONT>
3 d& J, z( Q- L: k, y9 h</P>
" F1 p$ b1 y" o  i* T<P><FONT color=#ff0000>函数名: sqrt </FONT>
$ T5 y! D( ~, e5 I  ~0 g: J: q功 能: 计算平方根   q. t& Z6 L1 U  `) w+ F
用 法: double sqrt(double x);
- L( w* b6 U1 ?1 Y5 x程序例: </P>
* P5 q* U) t, H# ?) `<P><FONT color=#0000ff>#include <MATH.H>$ A, I1 Y- |% D6 q' j) E$ ~# N$ S9 s
#include <STDIO.H></FONT></P>* |9 C- V$ \: B( `
<P><FONT color=#0000ff>int main(void) 5 S8 m5 f/ `/ ]3 ~! g5 T
{ 2 k( b; }) y5 G
double x = 4.0, result; </FONT></P>
. ]9 u9 A4 q, M! c% g<P><FONT color=#0000ff>result = sqrt(x); 5 [1 v! Q3 t5 K# u  Z3 a% q; |( Y
printf("The square root of %lf is %lf\n", x, result); - m8 Z" H0 Q1 `- S
return 0; % X! ]$ G- E+ H, X
} 3 K5 g" E% t- E; X
</FONT></P>" I+ P! K5 i# B. H' V; G
<P><FONT color=#ff0000>函数名: srand </FONT>
5 o  g# e" w) w2 W1 n功 能: 初始化随机数发生器 % X' E! y9 W. `9 J7 f" u4 ^$ ~
用 法: void srand(unsigned seed);
2 b0 l% X) m: b( j程序例: </P>/ ^6 V3 o6 s) \0 E- `2 E
<P><FONT color=#0000ff>#include <STDLIB.H>
$ C  g9 x9 o9 D5 c5 Y# T#include <STDIO.H>, O: u4 h% M* m! [5 y2 N
#include <TIME.H></FONT></P>0 ?1 w( ]9 ^+ P. J
<P><FONT color=#0000ff>int main(void) " K9 Z) [6 S/ q4 v, C- k: c
{
$ e6 ~1 N% B0 O4 }5 w, nint i; 5 |) X/ ]1 ~( i1 {) e
time_t t; </FONT></P>8 {3 n9 L' D; P+ R
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
+ Z: T; D5 ~) B. V4 _! H+ W; Yprintf("Ten random numbers from 0 to 99\n\n");
" @/ j+ b) T( P# C6 Y' ifor(i=0; i&lt;10; i++) . l/ Z' q3 d$ Y" a4 e; G* Z3 u& P
printf("%d\n", rand() % 100); ( A3 g: }: a' O
return 0; ( }. d( S1 |% ~
} 2 f/ B# Q7 X9 z0 k# C* h5 H; S
</FONT>
' G1 O; Y+ g- r' r  H' M</P>
" c+ m. @% N; C5 D  L6 g9 T; f* C<P><FONT color=#ff0000>函数名: sscanf </FONT>
+ [" |% @1 Q$ x2 f2 v7 d. W功 能: 执行从字符串中的格式化输入
7 F) k$ H; r; v! D4 Z% @0 q用 法: int sscanf(char *string, char *format[,argument,...]); 9 j. Y: X7 a0 h, F# S" A# F0 V8 m* j
程序例: </P>3 _  o- x* ?6 |
<P><FONT color=#0000ff>#include <STDIO.H>
) i  B( J9 E. o& O9 J' l& L) n#include <CONIO.H></FONT></P>, V/ d" t8 }) b; E8 F: a4 z, D
<P><FONT color=#0000ff>int main(void)
1 \: w6 h; a0 m: L{ 2 l& ^: p8 Q: o$ n& q* T
char label[20]; . |) \7 u( P! u4 ?" h
char name[20]; # B. C) q% \. X* \& U
int entries = 0;
0 j7 n5 u& E' Z' yint loop, age;
* c% V: @9 O/ X* T8 E. o. s& q! q1 q; Wdouble salary; </FONT></P>4 L8 `$ _" ~9 L7 e' P
<P><FONT color=#0000ff>struct Entry_struct
& Z8 o: L; D( [; v6 @8 v" E( _{
3 O( I0 D# H% [, uchar name[20];
6 F" L  {+ H7 C" X9 j7 i/ }int age; - k/ x& j* t% x6 u" T
float salary; 6 \* T+ _% b2 t: ?% y& M$ A
} entry[20]; </FONT></P>. w3 M- T/ G8 g' i
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
# h" h" F+ z6 a( N8 `printf("\n\nPlease enter a label for the chart: "); 9 w1 m1 t2 t, H7 ]$ l0 P. a) A$ G, N
scanf("%20s", label);
9 p2 F+ Z0 A4 H- v' ufflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
& k8 c0 `! v; i9 O6 S<P><FONT color=#0000ff>/* Input number of entries as an integer */ 0 C! w1 U9 o4 @$ [% Y" G% ?, O
printf("How many entries will there be? (less than 20) "); , v  N8 E. S- ^/ @9 S( b+ s3 S
scanf("%d", &amp;entries);
) l  }8 v  R0 c) b( a0 Sfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>3 E; k1 |( Z) I
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
2 ]7 K' W, v4 t- p( Mfor (loop=0;loop<ENTRIES;++LOOP)
' _- l+ R; n1 Q* L  o) a: l# a { ' t: Z9 H; r3 ]. H' Z2 E" u
printf("Entry %d\n", loop); 7 n9 a% x7 e5 m+ _
printf(" Name : ");
" m/ @& t9 ]# |( x; |scanf("%[A-Za-z]", entry[loop].name);
# ~% i' r) Z. Y4 q& C7 {fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
7 j( J" e& s8 m* D+ M" Z  I<P><FONT color=#0000ff>/* input an age as an integer */
( I) c0 u: T" b: ?2 u/ G# \printf(" Age : "); ; ^7 i" m2 N5 H% O9 m
scanf("%d", &amp;entry[loop].age);
; _- O" P# P0 V+ r- K; _; j, Rfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>. b  ^0 ]: K% Z+ v8 E
<P><FONT color=#0000ff>/* input a salary as a float */
8 g# F9 I) f( z* A. Mprintf(" Salary : ");
/ t: t4 F: r" ?( G# V  n- e( G4 uscanf("%f", &amp;entry[loop].salary); + \8 ]  K# A2 z  @5 N/ W
fflush(stdin); /* flush the input stream in case of bad input */ 0 Y; m- e1 j. I6 |% k4 k
} </FONT></P>: }* H1 p* Q; v8 [/ U
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
0 V* G$ L" e" v% Dprintf("\nPlease enter your name, age and salary\n");
$ e4 W" j; P5 S1 bscanf("%20s %d %lf", name, &amp;age, &amp;salary);
) q1 H0 i( u( N$ V) I; j</FONT></P>: M% E5 h7 u( m9 l: N# s
<P><FONT color=#0000ff>/* Print out the data that was input */ 9 d) a) b9 @0 ~5 R
printf("\n\nTable %s\n",label);
* S% q1 g3 K7 V! k, }/ x! Nprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
/ W& P0 C- y% ^4 M0 sprintf("-----------------------------------------------------\n"); $ `2 D$ n3 j' K5 F; @$ i' @
for (loop=0;loop<ENTRIES;++LOOP)
8 q4 ?* F9 r0 k; f printf("%4d | %-20s | %5d | %15.2lf\n", & K+ w4 L8 ~: A* {0 f
loop + 1, 4 i& o. n( m- [. D$ S
entry[loop].name,
4 E2 f% o" Z2 T1 B( yentry[loop].age, ; v. K+ d4 L. R
entry[loop].salary); * X5 l( H6 \2 h* U+ j, L- C
printf("-----------------------------------------------------\n"); 8 [1 K5 R6 W: T  n, B" Z
return 0;
  f& s/ q# j+ B0 a}
3 v: o) o( T0 K9 P5 V
" i/ I9 l2 W& D' z& U</FONT></P>' _9 Q$ G4 k5 c; H$ R
<P><FONT color=#ff0000>函数名: stat </FONT>$ z! C+ O/ o0 r$ L4 p
功 能: 读取打开文件信息
5 u5 I' ?5 y6 U% M/ M6 w用 法: int stat(char *pathname, struct stat *buff);
9 g& H8 t. W4 j2 t+ F1 t7 E! X程序例: </P>3 N6 g8 H- J# u$ Y/ s
<P><FONT color=#0000ff>#include <SYS\STAT.H>4 w; B* L# F: J
#include <STDIO.H>
4 ^. V# b( m# g5 e$ d5 b#include <TIME.H></FONT></P>  J  J1 |& B' z; }* [, l- O
<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>& Z3 ?! a! v0 p# O( Q
<P><FONT color=#0000ff>int main(void) : _0 m; a6 \4 l2 ^, u$ n
{
- s( X# d# [/ ?" {$ _, `' g0 Pstruct stat statbuf; ' v( E, x. h# m: l8 t: f! r
FILE *stream; </FONT></P>
3 h% b  @0 I6 n<P><FONT color=#0000ff>/* open a file for update */ . N5 l$ D4 F9 G
if ((stream = fopen(FILENAME, "w+")) == NULL) 6 U& v% G( Y3 t' g
{
; ]! S" Q9 `* t: u. {: c! Sfprintf(stderr, "Cannot open output file.\n");
. t3 P4 }; N! [) `9 Breturn(1); ) [( D5 d: R; m( e0 x" j1 D  O5 ]
} </FONT></P>7 _2 ~( u' _( ]# v3 Y4 Y+ V# \
<P><FONT color=#0000ff>/* get information about the file */
  R! v' Z9 [! hstat(FILENAME, &amp;statbuf); </FONT></P>
$ x7 x. i& o5 P( n  A<P><FONT color=#0000ff>fclose(stream); </FONT></P>7 T. S& b0 ^; u, D* E
<P><FONT color=#0000ff>/* display the information returned */
* r: z: z* N# s1 c; P; @- Sif (statbuf.st_mode &amp; S_IFCHR) ! R, e0 w8 |- [( o3 \8 e
printf("Handle refers to a device.\n");
* n5 Z8 a" y3 \; G) X4 [. T( K1 Gif (statbuf.st_mode &amp; S_IFREG)
. e* Z1 H- J: h; V# X: |6 cprintf("Handle refers to an ordinary file.\n");
7 z! M, A( T1 `7 pif (statbuf.st_mode &amp; S_IREAD) 2 c5 z+ f6 U6 J* d1 d7 J
printf("User has read permission on file.\n");
/ r8 O# O! o! o7 r( Lif (statbuf.st_mode &amp; S_IWRITE) ( q7 K5 s9 k  M# X% o" A
printf("User has write permission on file.\n"); </FONT></P>
3 \$ X' c) p5 d$ V( B! k6 b<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
5 I8 u0 R( C4 O& p' aprintf("Size of file in bytes: %ld\n", statbuf.st_size); / H% g/ G! K5 \& Y4 c5 l
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
; Q! m! [0 J" n+ n' l# W1 Lreturn 0; " r( H3 i/ h0 D# x! N& }
}
0 p* C% a. v  m' U1 u7 H; z4 E5 r
</FONT>) M8 i4 `% ]' f' l. I& ]
</P>! t+ ^2 [, m5 g
<P><FONT color=#ff0000>函数名: _status87 </FONT>- Y" |7 P8 R3 Q, l' O6 D. _, n
功 能: 取浮点状态
( j9 i8 m, a. ^: _用 法: unsigned int _status87(void); 8 o6 L  s% ]( d7 O- c; Q& t8 E
程序例: </P>8 r: B+ n2 w3 d, ]
<P><FONT color=#0000ff>#include <STDIO.H>) y" }, A( W" W
#include <FLOAT.H></FONT></P>, p# @  F8 z4 t/ b
<P><FONT color=#0000ff>int main(void) * Q/ @& x0 w- \
{ 7 i* p' J9 G! a3 L4 ?6 {6 H
float x;
1 }6 q! U! P0 W: M. a0 Gdouble y = 1.5e-100; </FONT></P>/ f1 T/ \6 X, Q2 Z1 x' ^
<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
; \- U. X+ w5 w% f! Z) L' l<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
& S* b% q: x0 ay = x; </FONT></P>
3 u( {+ V+ V/ k: ~<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
/ k" w- Y/ k/ S# M& vreturn 0;
" X( E0 C1 `! h+ f% u. K0 ^$ l* U% v, t} / f+ K3 u. Y& j: g7 z3 M: a7 L
</FONT>7 x, q& }* H! c
</P>
7 e8 ]7 O( h& p( s6 x* A; C1 L<P><FONT color=#ff0000>函数名: stime </FONT>/ e6 H2 @! Q6 [
功 能: 设置时间
6 ^0 q! W, W& W' `+ [% t% @用 法: int stime(long *tp);
* P& W/ h7 U' R. |1 j: Q. m1 _+ S程序例: </P>& j, \. b' h# h$ {% i
<P><FONT color=#0000ff>#include <STDIO.H>
7 p* s: _; k/ C4 V0 W4 Q! T+ }#include <TIME.H>" ~/ Y; f5 z  Q. I& `
#include <DOS.H></FONT></P>
0 Q4 ]: l& e4 J& W; L<P><FONT color=#0000ff>int main(void) , G( o0 D6 p; n
{ 7 Y: W5 j( x+ K( Q; |
time_t t;
  W- Q0 ?5 W2 c) q7 s8 kstruct tm *area; </FONT></P>% s' A. u( j' p% `& O* v  J0 O  T
<P><FONT color=#0000ff>t = time(NULL);
4 q% c9 l& i. ~* r$ Y+ s+ }9 V" a: farea = localtime(&amp;t); 7 B: K2 ~1 ~, M9 p% s( r% `
printf("Number of seconds since 1/1/1970 is: %ld\n", t);
3 n/ Y- w6 }: n- b( Y( f5 I$ v& eprintf("Local time is: %s", asctime(area)); </FONT></P>  F9 }$ y) _3 @1 r
<P><FONT color=#0000ff>t++; & f' Q9 S* Q3 f( K& `" y3 N4 P$ O  ?
area = localtime(&amp;t); / j" P) {8 b" g+ c5 Q
printf("Add a second: %s", asctime(area)); </FONT></P>4 f1 u7 t- x1 ?& p  X
<P><FONT color=#0000ff>t += 60; 3 o/ d- d4 K5 g2 |$ M/ b+ X$ f1 Y. G
area = localtime(&amp;t);
# Q8 c' v6 Z9 t/ A% }printf("Add a minute: %s", asctime(area)); </FONT></P>7 \" @" r' W' x' i, x
<P><FONT color=#0000ff>t += 3600;
6 N$ G1 O0 {0 y; h/ G8 _area = localtime(&amp;t);
9 ?& ?4 e  r- j: t2 I" C, h- Q& [! yprintf("Add an hour: %s", asctime(area)); </FONT></P>; K2 S; f" F3 c% n* q$ K
<P><FONT color=#0000ff>t += 86400L; * t. Y; s& E2 M' R2 r# y
area = localtime(&amp;t);
$ d6 B  d, g8 Bprintf("Add a day: %s", asctime(area)); </FONT></P>. E4 e3 I: f- `! F7 i* y8 A$ h; N1 j
<P><FONT color=#0000ff>t += 2592000L; - C% D& `0 ?% C* Z3 \
area = localtime(&amp;t);
5 p) J: x, q/ e# A$ ^9 t* \) Aprintf("Add a month: %s", asctime(area)); </FONT></P>  {1 u. B2 t9 |; M* z& F
<P><FONT color=#0000ff>t += 31536000L; ; \1 z% _9 R4 m/ \% S
area = localtime(&amp;t); ! q1 f, z: m8 \! O1 i, a4 b3 v
printf("Add a year: %s", asctime(area)); 8 Y) e1 _5 ?) X
return 0;
0 F* L$ L9 _: c; }" L8 b} </FONT>1 k  p& G. h7 h5 U# A  ?

+ b- v: G0 m4 X  h9 }& P% t, I0 v( B
</P>& Q. m3 W$ A% U- [' Q
<P><FONT color=#ff0000>函数名: stpcpy </FONT>1 c* ?# r: w" A- P
功 能: 拷贝一个字符串到另一个
8 M3 N% l' r  i5 M& P( {0 `用 法: char *stpcpy(char *destin, char *source); / i- v0 |5 [9 ~& k7 E0 ^
程序例: </P>
1 f, ^$ A: {5 w- B<P><FONT color=#0000ff>#include <STDIO.H>. s6 ^; H. e* z. n. \
#include <STRING.H></FONT></P>+ v, c0 p. Z, U5 a2 N
<P><FONT color=#0000ff>int main(void)
3 L. I! `* V, T1 @  M! x{
* l+ O/ z8 T+ u4 }  |char string[10]; 5 g% y+ ^' z% z: B& s! U
char *str1 = "abcdefghi"; </FONT></P>: }' Y5 ~6 t+ w9 s7 j
<P><FONT color=#0000ff>stpcpy(string, str1);
5 X3 w" I- ^. K& iprintf("%s\n", string); 8 D" m9 v. f8 y+ g$ {
return 0; " ?# l' n+ z) w4 E! [
}
1 {$ G; @: n+ X8 _. z( Z7 n- G) A4 n2 c4 i
</FONT>/ N4 ~1 Y. d: \% g- x' d
</P>  o6 Q( D: L! e+ r6 u! N
<P><FONT color=#ff0000>函数名: strcat </FONT>0 [, j; \( }2 g- V4 F" S
功 能: 字符串拼接函数
, k6 O+ [+ L) g% G用 法: char *strcat(char *destin, char *source); 3 X: S: g) W+ T5 R) R2 Q* }
程序例: </P>
$ W# l9 F  m% a& ]5 _1 Y8 F4 O+ J4 B<P><FONT color=#0000ff>#include <STRING.H>
/ r! ?; p' e1 v  O3 l4 _" s#include <STDIO.H></FONT></P>
' r8 H. [" n$ h* W9 q9 Z" c# P7 F7 F5 S<P><FONT color=#0000ff>int main(void)
& C- u& ]8 q. O' c{ . h) T+ }' T3 X9 f  u
char destination[25]; / |& w. }- j( e8 d/ t1 N2 P) C6 O4 g
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
( w, P' A- d; ^* e( L: R# o  j" F<P><FONT color=#0000ff>strcpy(destination, Borland); : R& a9 R6 r: ^3 C
strcat(destination, blank); ' |" @( p6 @- S: `
strcat(destination, c); </FONT></P>
2 O" r  e& L8 q3 q+ p) k  b<P><FONT color=#0000ff>printf("%s\n", destination); & {, ]: @3 D/ U% V
return 0; / q' ]3 m0 b- r* R/ Y( O
}
; P5 }/ ~  n& \. \$ Y4 [9 Q4 R4 [8 L, l1 Q
</FONT><FONT color=#ff0000>
) j, P2 o. i0 w+ Q7 H</FONT></P>/ G% \9 u) D" ?# ~2 x. m+ e/ |
<P><FONT color=#ff0000>函数名: strchr </FONT>( p* _/ p& u6 D' `+ `, j
功 能: 在一个串中查找给定字符的第一个匹配之处\ + H5 X1 B- S+ s
用 法: char *strchr(char *str, char c); , x% Z. |& E9 h+ n) m
程序例: </P>
8 X2 t0 T( r; G7 B3 f<P><FONT color=#0000ff>#include <STRING.H>
' K; ?: b- ~7 K4 \, |8 E#include <STDIO.H></FONT></P>
; R- a) h& g0 N% e<P><FONT color=#0000ff>int main(void) ; H% g7 [, m% R7 E
{ 9 y; b7 K# j7 W, ^( s4 u8 I. N+ k
char string[15];
0 M8 n, s: {6 f1 Q& {$ Rchar *ptr, c = 'r'; </FONT></P>
( x2 R$ K! Q1 G5 t. ~- B<P><FONT color=#0000ff>strcpy(string, "This is a string"); ) V2 y4 H% e) F8 m( k3 x7 V
ptr = strchr(string, c);
' Z$ O8 D5 Q2 z+ Cif (ptr) & O) l" B" t1 l+ A3 D( U
printf("The character %c is at position: %d\n", c, ptr-string);
' b1 \& O, Q4 t" \6 _. \else
  s4 f5 j. \3 G8 A7 Q3 p( S0 l( G4 t5 H/ Hprintf("The character was not found\n"); & x8 H0 Y5 @0 K' v6 S9 E* f( ^
return 0;   Y9 K! p* r4 ]
} 2 |7 {" i% x& R* x
</FONT>) k0 Z! |3 V" S6 q1 K+ {

0 F$ {5 [$ n+ \  P) `</P># p) x# U. h7 W: @
<P><FONT color=#ff0000>函数名: strcmp</FONT> ) m& v& I+ p$ B3 {0 V/ ?6 W
功 能: 串比较 $ S& |& f: C3 {( [* u' _
用 法: int strcmp(char *str1, char *str2); 0 O# }* x# K. F  A$ g- |
程序例: </P>: p8 ^& C* y7 Q8 z5 `
<P><FONT color=#0000ff>#include <STRING.H>1 J$ M/ S- S! S9 S& Q9 ?! I
#include <STDIO.H></FONT></P>. L) ]8 A& F- y" T: q
<P><FONT color=#0000ff>int main(void) , i3 {6 G* R3 B2 @/ R4 T
{
) |3 }/ m- C' K" jchar *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
% b3 F8 \' s/ q3 J& ]6 ]/ |int ptr; </FONT></P>! Z$ R2 ~! @) g' y
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1); $ u9 z% ~( W/ B% i
if (ptr &gt; 0) 3 q) J5 W9 z2 s
printf("buffer 2 is greater than buffer 1\n");
' y% i) L) e$ P; Y0 `0 s* helse " N6 k* J5 @( n
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
9 F- C$ Q) R1 V, U<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3); - \0 q1 ]+ }% F2 T* b1 Y) C7 V
if (ptr &gt; 0) 3 _: r% e2 r( ]# q6 {9 j
printf("buffer 2 is greater than buffer 3\n");
7 L/ W5 d" ^- Oelse
- B: R' ?- m2 q1 oprintf("buffer 2 is less than buffer 3\n"); </FONT></P>
, u, c8 l/ d/ p5 f3 }<P><FONT color=#0000ff>return 0; " t1 X# O; a" Y! L+ o3 `
} ; G2 s$ s' H# T5 I% ]

5 d1 b( E% Z5 V5 m
3 `. T0 b. E( M5 @# k</FONT></P>
# ?1 ]) \' m& l6 l<P><FONT color=#ff0000>函数名: strncmpi </FONT>6 W' z6 k0 W0 Y2 U. w- `2 B
功 能: 将一个串中的一部分与另一个串比较, 不管大小写
6 q/ D7 O! E3 P5 ~4 C2 ~用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); ; d; l0 B; j4 J- b0 ?4 \6 X2 Q
程序例: </P>! o) e4 `# g" A3 ~
<P><FONT color=#0000ff>#include <STRING.H>' U8 M8 c# p& @; x- H- u4 A
#include <STDIO.H></FONT></P>0 m2 x* |5 A  `
<P><FONT color=#0000ff>int main(void) 9 R5 r+ c5 E; R/ z0 u$ T
{
& X& X1 b0 v; z4 g5 dchar *buf1 = "BBB", *buf2 = "bbb";
$ e0 y# a+ ~) M3 }* G, S/ x4 Lint ptr; </FONT></P>2 H" P2 S) F* c1 a. F4 P$ `# ?
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
5 I+ K! m- _0 P( \<P><FONT color=#0000ff>if (ptr &gt; 0)
4 t: ~2 ?. j7 ?' n2 I6 ~9 I% ~2 q, iprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>$ u& Q' |* H* o! _
<P><FONT color=#0000ff>if (ptr &lt; 0) . N  n2 u/ s( g( l4 ~6 ~
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
% i" h- D; m6 @<P><FONT color=#0000ff>if (ptr == 0) 9 T( z: i# Z+ L* r. t% n
printf("buffer 2 equals buffer 1\n"); </FONT></P>
7 H+ N4 s7 v8 ^3 x; X& R<P><FONT color=#0000ff>return 0; 7 |3 y, f6 H8 b# ?
} / {7 i9 n" B2 K6 {1 B, I4 Y7 G9 F

2 Q8 L8 q% s- D3 A% P/ T</FONT>4 k: H" D5 h9 }  j
</P>9 k$ Y3 }( ^7 b7 [
<P><FONT color=#ff0000>函数名: strcpy </FONT>
; b8 u( ?0 m, N+ u. |功 能: 串拷贝 9 C' [2 \2 |3 p
用 法: char *strcpy(char *str1, char *str2); , Z6 A# ~- y; O
程序例: </P>
3 |7 E- u1 d5 c: D<P><FONT color=#0000ff>#include <STDIO.H>& P8 m5 v1 o- H9 l1 F- [
#include <STRING.H></FONT></P>9 W- L& E1 ?: p3 ?" c7 C
<P><FONT color=#0000ff>int main(void) 3 ~, }% g  e/ p9 _1 l4 q
{
0 i/ a/ [( f9 u9 q+ p+ achar string[10];
8 \; P8 ^4 {3 w% ~! C* Jchar *str1 = "abcdefghi"; </FONT></P>
& c- U+ _1 \+ I8 y<P><FONT color=#0000ff>strcpy(string, str1);
6 K& m8 Y$ g; K) Iprintf("%s\n", string);
; {0 j0 m- J' ], D- ~return 0; 4 g6 a  p# U/ ^+ j! t0 X
}
) k5 Z  F& d7 `) r, Q</FONT>
. v( I: `! m3 G' D& k0 N7 ]+ _! W( F; J, `0 D3 M
</P>1 s8 ^1 k7 f# B
<P><FONT color=#ff0000>函数名: strcspn </FONT>8 y9 E0 z8 Y$ t
功 能: 在串中查找第一个给定字符集内容的段
: |( _# {2 m* z5 X用 法: int strcspn(char *str1, char *str2);   W4 w  C+ J7 s" S3 p4 o' V
程序例: </P>
0 L7 R0 N2 K" V+ d<P><FONT color=#0000ff>#include <STDIO.H>$ b7 i! ^* D# x' F7 h8 k8 f) J! k1 \' H5 T
#include <STRING.H>5 _6 O3 S$ I* }
#include <ALLOC.H></FONT></P>
; P9 z2 X( J3 y$ P- S<P><FONT color=#0000ff>int main(void)
% x" ^* |- r0 v! A) m9 R& w4 b{ 3 v8 g, T. U! e, I& Z& X
char *string1 = "1234567890"; 2 c) a( c+ C% |! D/ X5 V
char *string2 = "747DC8"; ; }$ }6 ]) {% l! s, @
int length; </FONT></P>
2 f6 w' Y' R) L8 s: H2 J<P><FONT color=#0000ff>length = strcspn(string1, string2);
7 h% O9 {. ^# d1 rprintf("Character where strings intersect is at position %d\n", length); </FONT></P>
2 C3 m8 K% {( K* c; u: A<P><FONT color=#0000ff>return 0; $ b" [) @% }  A! V) d: i. p# ?" u
} - T1 @& |( W7 ]( S
</FONT>0 N' [3 e, Z+ _% m

/ i! d+ x% ~, y! |9 k</P>
0 ?3 O6 H3 H7 ]% U<P><FONT color=#ff0000>函数名: strdup </FONT>. R" \1 G9 d5 e- }. u6 F
功 能: 将串拷贝到新建的位置处 , P' w" C% z6 _, h7 f# [: I: f3 u
用 法: char *strdup(char *str);
% l1 l" ^/ s# @程序例: </P>* g- q. Z$ l+ E/ P( W" H/ l
<P><FONT color=#0000ff>#include <STDIO.H>
! }6 b* a9 r3 W1 C& H' N+ e#include <STRING.H>
+ l( ]3 A% e/ E, v0 q8 T#include <ALLOC.H></FONT></P>) H) s# ^+ y. T
<P><FONT color=#0000ff>int main(void)
; Q$ m# z: e$ [{ " v1 J9 {' p9 A
char *dup_str, *string = "abcde"; </FONT></P>
8 t6 M9 w2 e/ F* b. S) \; a<P><FONT color=#0000ff>dup_str = strdup(string);   [% _* c" A; s
printf("%s\n", dup_str); % J- K9 q3 g6 R8 g/ f$ P
free(dup_str); </FONT></P>& a- A8 C+ h3 w" P! U" M
<P><FONT color=#0000ff>return 0;
  E! U3 ]5 `/ E  A* J}
! ?8 ]; w: Z0 |9 c8 e# d& }3 g
</FONT>* y, X6 k! G1 ^  X- m) O. ^
</P>
: B, R- V, q) w' o+ Z8 J' s<P><FONT color=#ff0000>函数名: stricmp </FONT>
4 e, L; y. y: r) M4 \功 能: 以大小写不敏感方式比较两个串
+ i: ~* E3 Z  L. R1 {用 法: int stricmp(char *str1, char *str2); % t9 B4 x! A6 }+ s4 }0 M7 o
程序例: </P>! N  A. T. O( I, T: q# `
<P><FONT color=#0000ff>#include <STRING.H>1 p9 U( ]2 c/ {& Y* W5 W
#include <STDIO.H></FONT></P>
" K, I& `8 t! ~7 u<P><FONT color=#0000ff>int main(void)
( @  N2 q  f* }3 q* y$ G7 `9 x{
9 c) `( i. l% Q' Ichar *buf1 = "BBB", *buf2 = "bbb";
" A1 n9 M% ?# M5 Q8 m  ~int ptr; </FONT></P>
$ Y( ]: l, s  J; j- E( T, ~: t<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
$ _6 v# s( x2 m/ b: L+ Y/ f+ D<P><FONT color=#0000ff>if (ptr &gt; 0)
8 L; Q" f1 ]3 y, Pprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>+ G+ S% v+ T% p# i" j
<P><FONT color=#0000ff>if (ptr &lt; 0)
$ R; z# N/ @2 Yprintf("buffer 2 is less than buffer 1\n"); </FONT></P># V0 f  n' E4 j6 G6 g/ ^' b
<P><FONT color=#0000ff>if (ptr == 0)
1 o! n( K# E7 e( ^2 }! {2 cprintf("buffer 2 equals buffer 1\n"); </FONT></P>/ q+ a6 G# P6 Z' Y1 t, O6 {
<P><FONT color=#0000ff>return 0; 3 U; \& p  o8 N+ Q% p
}
% Y6 E& T4 y# n& |</FONT>
# a" b  d! H6 R. b  E; N</P>
7 I* A0 ^, z, G( l<P><FONT color=#ff0000>函数名: strerror </FONT>
! N/ W7 W! Q# c8 J& A; F功 能: 返回指向错误信息字符串的指针 9 t) f: S6 l1 b- f1 n/ x# g
用 法: char *strerror(int errnum); . c/ z9 ~; t- h9 g4 U& Y
程序例: </P>/ j* T5 A2 d, ^2 t) R
<P><FONT color=#0000ff>#include <STDIO.H>
! O: j0 V0 ^: q  ^#include <ERRNO.H></FONT></P>: r# B$ y2 ]* v
<P><FONT color=#0000ff>int main(void)
! n. l+ W) I+ H& R/ `{ . @2 h7 m; j* g5 Y) q
char *buffer;
. C9 y7 R* g0 C1 wbuffer = strerror(errno);   ?( O: J- e9 Q" c3 l' |
printf("Error: %s\n", buffer);
! e; ~  {" a" z( F3 zreturn 0;
! B: ]% B8 s% i  e6 P* x: ?} 3 Q8 A6 L7 \9 [  r) k

4 G3 p2 X: X9 {1 e( J7 f4 o3 y</FONT>/ D, n4 K7 V9 P8 C
</P>
/ v% Z4 T  G; L, w<P><FONT color=#ff0000>函数名: strcmpi </FONT>8 J- F( H. s2 Q
功 能: 将一个串与另一个比较, 不管大小写
" H$ t; @# K4 k; u# W2 j用 法: int strcmpi(char *str1, char *str2);
1 ~3 \  {. _  I4 j0 ~: d% S程序例: </P>* K0 M! T5 \6 c" ?4 X  F1 r
<P><FONT color=#0000ff>#include <STRING.H>
0 S: h- [" n# n/ j#include <STDIO.H></FONT></P>
: A( i9 q& [5 F; a; a<P><FONT color=#0000ff>int main(void)
1 i& J) @/ ]7 p$ g{
! l! E# h: k% F; a/ |3 ~char *buf1 = "BBB", *buf2 = "bbb";
- k4 {- s. V& x% [, x6 Pint ptr; </FONT></P>  H1 a9 R2 P: y) x; l7 H0 x) {( U
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
  v" d  g  V  S7 h* ]7 X<P><FONT color=#0000ff>if (ptr &gt; 0)
3 D0 _4 o& e& x2 t: ]" i3 [printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
8 N! o  u! I' d/ |) g<P><FONT color=#0000ff>if (ptr &lt; 0) * {1 [! y2 F2 _( G: O# m9 U* d) ]
printf("buffer 2 is less than buffer 1\n"); </FONT></P>% `! I2 r4 _, p; E
<P><FONT color=#0000ff>if (ptr == 0)
, p; R+ ?' ?7 Zprintf("buffer 2 equals buffer 1\n"); </FONT></P>9 z. G& x; s" C: ]. ?; w
<P><FONT color=#0000ff>return 0; : Q! L& `; b' T8 g( ]7 k; n
}
. l5 V$ Q% H# l% l' u5 A/ z</FONT>0 [6 H  A+ V/ k& K2 M

8 e# Y% b1 q3 J</P>
. k0 p0 T/ g- O$ R% N5 X" D3 k+ V<P><FONT color=#ff0000>函数名: strncmp </FONT>& f; e0 r/ t/ B) Q# S" W- i- P
功 能: 串比较 ' y' }% Z) P7 P7 @
用 法: int strncmp(char *str1, char *str2, int maxlen);
. i; U" @* ?9 y' F3 x2 ^程序例: </P>$ i4 v+ y$ R2 g3 K- k7 \6 E
<P><FONT color=#0000ff>#include <STRING.H>
: z5 s4 \- B" p% J#include <STDIO.H></FONT></P>) {$ ^% }8 r7 H, f) G: S, _3 G
<P><FONT color=#0000ff>int main(void) </FONT></P>
9 Y" L4 S: j4 b1 f) |<P><FONT color=#0000ff>{ % Y- f7 _$ L) ~0 U  Q* ^, V  A2 x) z
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
5 D8 i8 y" a3 [int ptr; </FONT></P>$ }% e; r/ t3 Q" Q+ f
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3); / F- g) O6 k8 S% R
if (ptr &gt; 0) / U1 c+ h% o* V: y- a" f
printf("buffer 2 is greater than buffer 1\n");
7 n0 F+ Q/ b' w- S* D; Velse 4 G0 B2 X( K( m5 n& u/ h  ?
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
- T3 j; ?* H% x3 {/ m5 l0 Z<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3); ) n$ o: f; n2 {: @4 H* g
if (ptr &gt; 0) 7 v' f0 d2 E- j. U% x7 c
printf("buffer 2 is greater than buffer 3\n");
/ e& l0 j% p+ i9 e/ S5 _else
1 e# [" a$ o9 k: fprintf("buffer 2 is less than buffer 3\n"); </FONT></P>& R. ^- f' z1 m
<P><FONT color=#0000ff>return(0); ( i- @1 t" [. t$ ]' x
} ' G' `/ K4 r) w( _

8 E6 u- g6 \8 [</FONT></P>
* _  Z* m1 f3 O; z5 B7 u<P><FONT color=#ff0000>函数名: strncmpi </FONT>
7 `9 v2 d1 W; k8 z6 |, y9 E% f功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 , X9 z% A4 H" A  {$ H/ q
用 法: int strncmpi(char *str1, char *str2); : ~) {: o- ~4 i& R
程序例: </P>
* k" d) }/ w+ ?( `& ?* [( j<P><FONT color=#0000ff>#include <STRING.H>
2 x! j. E' i* s( o#include <STDIO.H></FONT></P>
' K! n/ A5 [6 K. i+ v9 X# P<P><FONT color=#0000ff>int main(void) - F4 I/ I1 G' {& R1 P
{ $ Z" |7 \, f: t2 i/ \! i
char *buf1 = "BBBccc", *buf2 = "bbbccc";
9 V* h9 }$ S2 _, sint ptr; </FONT></P>+ ]8 D  W  X* N7 @
<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>, e' E) q  `! o' H7 U
<P><FONT color=#0000ff>if (ptr &gt; 0)
7 w' T% K% a9 |printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
2 V; p6 @6 R- w5 n& O0 j<P><FONT color=#0000ff>if (ptr &lt; 0)
! t/ Y. j  P- \$ @: Qprintf("buffer 2 is less than buffer 1\n"); </FONT></P>/ s9 M3 o1 _/ m0 e0 f' L" W5 E& M
<P><FONT color=#0000ff>if (ptr == 0) " l' ~: g4 {" s8 S0 Q+ z7 O
printf("buffer 2 equals buffer 1\n"); </FONT></P>6 y3 \, s9 o) ]5 k( c
<P><FONT color=#0000ff>return 0; </FONT>5 ?/ I5 Q7 b4 S5 A, p$ T. ^8 m
}
# [/ p4 g! K- }; S2 m3 }4 N- {( l" q/ ~$ C/ T, \
</P>
% W# }- c4 N! S& H! u% ~. Q<P><FONT color=#ff0000>函数名: strncpy </FONT>
1 @7 Y1 _* w3 f* d. V功 能: 串拷贝
9 U0 D2 p9 z  [" e用 法: char *strncpy(char *destin, char *source, int maxlen);
- Q% J$ E, {: w) w0 @" }程序例: </P>
  T7 c" \* x& w) v1 [<P><FONT color=#0000ff>#include <STDIO.H>
1 X0 @  K' [4 [: v2 J- B7 z" S. F#include <STRING.H></FONT></P># E6 a* V5 `- j/ ~" H
<P><FONT color=#0000ff>int main(void)
) Z, q, p( X0 F& z  F! L{
9 U( k9 X( c7 G2 A! }char string[10];
1 E8 n7 z5 s/ n, m  Y! K6 Dchar *str1 = "abcdefghi"; </FONT></P>2 D+ y% w% V* V; N
<P><FONT color=#0000ff>strncpy(string, str1, 3);
' \2 J! s; R6 x" vstring[3] = '\0'; ( Z" {8 R7 ^( i) f8 [2 G
printf("%s\n", string); ' R3 ~7 x9 m- L6 T8 y9 o9 `! w0 [8 a
return 0;
: \4 I; Y( [& R! [& A1 Y} % M8 Q& U8 z8 R& `- }  |1 ]0 X7 j
</FONT>
$ R/ l- E9 v! S0 [1 v# O</P>
% B: C- N; M8 d5 z<P><FONT color=#ff0000>函数名: strnicmp </FONT>
/ o! l8 S2 C9 ^4 O1 v3 X功 能: 不注重大小写地比较两个串   w2 ]; c8 [% _  J! F, O& q
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
4 Q7 s' M9 w! J# s) f程序例: </P>
7 v# n3 A6 M6 r9 l- y/ e+ y<P><FONT color=#0000ff>#include <STRING.H>
  x2 l  D/ ?3 u8 U  D6 L1 P#include <STDIO.H></FONT></P>8 X" p$ }# O& F* V. O) U; [
<P><FONT color=#0000ff>int main(void) 4 i6 n8 {" }$ Z/ @9 v) K
{ . d  f3 ^5 z$ A) M
char *buf1 = "BBBccc", *buf2 = "bbbccc"; 6 C! K# |1 }3 Q+ |& H" d4 ^
int ptr; </FONT></P>
% p4 s$ d7 X" g+ |& ?<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>' v6 p3 _7 N' M
<P><FONT color=#0000ff>if (ptr &gt; 0) 7 N. X5 G2 M2 @8 d6 ?2 C* N
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>1 L( ]( W) C2 d+ i: @  s! g. Y
<P><FONT color=#0000ff>if (ptr &lt; 0)
6 {$ D- P; J# l0 ]printf("buffer 2 is less than buffer 1\n"); </FONT></P>7 a4 t' x9 V5 K$ Q+ q' c1 Q: C
<P><FONT color=#0000ff>if (ptr == 0)
2 r7 D& F3 r# c1 s" X, l2 ]9 Pprintf("buffer 2 equals buffer 1\n"); </FONT></P>
0 ?3 P) y6 d2 \( J. |8 a<P><FONT color=#0000ff>return 0; ( H. L' T7 `* {
} % j; y! a0 u( C* S8 j$ g

8 Y1 D* Q; ^4 s</FONT>
9 k" G4 Y! W& s+ y</P>
4 h$ r0 v, ]8 g0 K! c<P><FONT color=#ff0000>函数名: strnset </FONT>
5 y4 K4 b+ a0 N* I* O功 能: 将一个串中的所有字符都设为指定字符
6 e6 o) L) w1 s: y; ^# D# X) d0 R8 |用 法: char *strnset(char *str, char ch, unsigned n); , R  E! v: U9 V
程序例: </P>
0 |6 A; s* s; Y<P><FONT color=#0000ff>#include <STDIO.H>- j0 P# M9 J' X, E
#include <STRING.H></FONT></P>
/ W" W& b# k6 M/ G5 u8 k<P><FONT color=#0000ff>int main(void) : W9 G9 i' Q( g( m5 Q* F4 C
{ 1 @8 Y! S; O; I! w
char *string = "abcdefghijklmnopqrstuvwxyz"; / |6 }4 E3 ^( W$ P
char letter = 'x'; </FONT></P>, Z6 u4 ^5 X' s, H: k+ X1 ^$ {" q
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string); ) a4 G) ~4 H6 H* [9 @. N9 G+ M
strnset(string, letter, 13);
" p8 p  j' v& P9 a7 ?) |; Tprintf("string after strnset: %s\n", string); </FONT></P>
3 H: X. Q" k# r1 U, \* G0 j<P><FONT color=#0000ff>return 0;
1 [. a4 ?( F6 ?4 l. X}   }8 `$ L3 G- u
</FONT>
, I; r5 v. Q1 E8 ]</P>
  |4 Y$ _' \3 f: v7 ~7 q& A<P><FONT color=#ff0000>函数名: strpbrk </FONT>/ p: `8 t+ K9 k+ Q
功 能: 在串中查找给定字符集中的字符 5 k& W7 _9 P/ j
用 法: char *strpbrk(char *str1, char *str2);
1 B( ?3 y+ I& c& ]+ z0 B" u/ Z& h3 [6 s程序例: </P>6 W  X* }- ^# R9 i& s  G
<P><FONT color=#0000ff>#include <STDIO.H>4 Z8 G' ?/ n1 z+ Q
#include <STRING.H></FONT></P>  I' E6 E7 f; F6 Q1 b) D- ^
<P><FONT color=#0000ff>int main(void)
1 I; z& ^- N8 [# X$ ?% h* z{ 1 _3 Y" C7 c  T1 T
char *string1 = "abcdefghijklmnopqrstuvwxyz";
  y) O1 j; x- Y" E! ychar *string2 = "onm"; + @( }; `) W5 C5 _- U: r
char *ptr; </FONT></P>
# u0 |( h. [" e! h8 j7 w& F  D<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>" F$ H" L5 n5 W# e9 d& D% I& R
<P><FONT color=#0000ff>if (ptr)
+ \6 u$ L  q4 d- j! Kprintf("strpbrk found first character: %c\n", *ptr); " z4 c* W" H  F2 ?) l$ W/ o& X
else / ]5 e4 L8 Q5 p
printf("strpbrk didn't find character in set\n"); </FONT></P>- x1 [& z9 }9 z" ^( D3 |4 h
<P><FONT color=#0000ff>return 0;
* e- s7 N( g. a# {6 U! X" Y( q}
2 Z* p! b% I& L3 ^5 e; e0 }# L5 A" z3 K5 q1 d- F9 n6 [
</FONT>
& E4 `$ P1 T! g* b</P>( ]0 N4 B; a/ a
<P><FONT color=#ff0000>函数名: strrchr </FONT>
" A: C% f! U$ x8 w  @- }9 v功 能: 在串中查找指定字符的最后一个出现 . p0 t4 b. _. V; @, f+ o  o
用 法: char *strrchr(char *str, char c); 4 z! r7 _. |& \! e
程序例: </P>
$ o# _6 s  D4 Y# E, k" J/ H<P><FONT color=#0000ff>#include <STRING.H>
' \3 P$ V' L) \: o; l' o. w#include <STDIO.H></FONT></P># l& H9 c: T8 a! b
<P><FONT color=#0000ff>int main(void) 7 L% s% I5 S. q. @8 ]/ k! N& I& n
{ 3 ~% y0 B; o8 e1 e8 }6 ~
char string[15]; % l/ r0 \/ u" v% Q7 {: T$ E3 |/ E
char *ptr, c = 'r'; </FONT></P>- }6 l; T7 }- u+ r9 A
<P><FONT color=#0000ff>strcpy(string, "This is a string"); 4 d+ `9 N! E/ I1 k- L
ptr = strrchr(string, c); 5 K; Z4 f/ a& r
if (ptr)
) \2 @) [8 x: X, {+ X. h  J" }7 I) \printf("The character %c is at position: %d\n", c, ptr-string);
& ?: J/ P( t4 P  N0 telse
1 U. B7 U( G* G+ g; M2 Aprintf("The character was not found\n"); 3 N, Z% d% V+ h% W- P7 @
return 0;
. J2 C1 N/ t: Y* _% D} </FONT>4 @  X" b; v5 H- p5 A' f
# ]! Z( n; J7 r% A9 G

6 a( h8 x. r$ i& T! {</P>8 Q% r9 h: ~% S6 }9 g4 r
<P><FONT color=#ff0000>函数名: strrev </FONT>
- u1 [* E: F. s* E* n功 能: 串倒转 & e& H0 _* K% I( \# l1 c% U1 U
用 法: char *strrev(char *str); 9 Q! [% d; _# x3 `; y: O: {
程序例: </P>9 M' R2 O5 u3 R$ u
<P><FONT color=#0000ff>#include <STRING.H>0 a/ K) a1 P, i: z# C+ A
#include <STDIO.H></FONT></P>, |3 m. E4 Q* f' h$ u" T
<P><FONT color=#0000ff>int main(void) : f9 }1 W7 {5 D) e3 ^
{ ) V2 R: O/ J: [9 A6 g
char *forward = "string"; </FONT></P>
, }6 i, q$ s$ X: p) H- {# E<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward); 0 g" v: e& j$ N- V' G
strrev(forward);
- ^! V3 _* q$ ]3 _2 t, jprintf("After strrev(): %s\n", forward);
7 d$ [! m( I6 f; N9 Yreturn 0; . P  J: L  U8 ]; o4 D( m, l
} </FONT>: e2 V7 G8 [. ~& Q. Y3 W
</P>
. u4 ~, q8 h) b/ f0 |<P><FONT color=#ff0000>函数名: strset </FONT>0 u8 s: C; u  {( a8 g4 v
功 能: 将一个串中的所有字符都设为指定字符
6 I+ J/ D4 K+ G8 Z7 x! r用 法: char *strset(char *str, char c); " B3 j" ]5 L* a
程序例: </P>$ n2 a! ^5 I  T( J  e* V+ y3 O
<P><FONT color=#0000ff>#include <STDIO.H>4 ?0 I( Y4 K* b
#include <STRING.H></FONT></P>& v9 v" \% Q) ?
<P><FONT color=#0000ff>int main(void) 0 i' X7 I) K; d& i" I; @
{ - w7 {1 E% E  R2 w7 |1 o1 j
char string[10] = "123456789";
6 u4 V, O9 [# _6 B) \, o/ ~' \" Q8 echar symbol = 'c'; </FONT></P>& m6 X- s! Q1 T& a+ i2 T
<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
% Q5 h' g& k9 c5 |. B: M4 ]* j+ Nstrset(string, symbol); ! R- o4 v% V* q) Q; D; h$ _
printf("After strset(): %s\n", string); ) |" p8 U8 _) g2 d9 ?. s/ c) O
return 0; ) t8 {/ P( z; q( T7 M1 m" l
}
% m1 j0 L; k* I1 M9 O; B1 P/ N: W  P. w
</FONT>
+ `: N  T$ I! n$ }, |. T5 P</P>
' h9 p* G1 [% |; w<P><FONT color=#ff0000>函数名: strspn </FONT>  O5 R$ V8 M, l$ c
功 能: 在串中查找指定字符集的子集的第一次出现 ' ~* a5 |2 k( [4 p5 S/ i
用 法: int strspn(char *str1, char *str2);
4 ^/ {2 N. c( l, ?  Y% E' p% I2 n程序例: </P>( J/ _7 t) L. D
<P><FONT color=#0000ff>#include <STDIO.H>
  a6 O4 p+ t4 r1 H' n#include <STRING.H>5 Y0 i5 ^$ L9 o2 i/ }
#include <ALLOC.H></FONT></P>: r$ ?* l: P8 N
<P><FONT color=#0000ff>int main(void)
  o  M: i( W/ {% C{
2 t% B: X7 `7 w: h4 F9 rchar *string1 = "1234567890"; ; \$ N. ~; y9 K$ S4 H
char *string2 = "123DC8";
$ L3 O5 c& k) t7 z$ pint length; </FONT></P>* h5 {& ~% z& B; }0 W; ]5 N
<P><FONT color=#0000ff>length = strspn(string1, string2);
! y3 h( b6 z5 m4 S9 B, ~printf("Character where strings differ is at position %d\n", length);
$ }' c/ J/ w4 @: S0 D% ^; Lreturn 0;
. R! y9 N# g1 x# C7 @}
; m& V- I* k" d1 R9 A5 S</FONT>3 {3 z4 ^! O8 k: U0 B( v
</P>
3 l# y, ]# Z8 ]; D<P><FONT color=#ff0000>函数名: strstr </FONT>. T, G2 p' X( b; J" ]
功 能: 在串中查找指定字符串的第一次出现 0 D* M/ l! h; U
用 法: char *strstr(char *str1, char *str2);
2 Y3 O% t* \" {4 Q程序例: </P>
) X- P7 g# t/ C% @. s3 ]+ _* W" I<P><FONT color=#0000ff>#include <STDIO.H>
2 ]- X  s2 w8 d4 [" P+ x0 P#include <STRING.H></FONT></P>
0 w2 _! y- ~4 N! m<P><FONT color=#0000ff>int main(void) ( c- A2 H/ @& b7 Q: }3 `
{
& s6 Y2 I/ Q# z0 f. H' H0 qchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>" P8 X7 l) N. R' Y- h. Q' [
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
- v4 |0 \9 [" Y6 K- n  Oprintf("The substring is: %s\n", ptr); 8 f8 i0 |7 S9 A# m4 m6 h, E. b; x
return 0;
( ?! w8 X% M. }/ d# W: Y% `+ a- v} </FONT>! u5 O9 P, q4 v

' x- T' Z+ n( h8 l! @, L' Q0 K2 d</P>- H1 F( h# T/ d$ F8 @4 N
<P><FONT color=#ff0000>函数名: strtod </FONT>4 M+ T! j+ A0 A" J4 p5 u4 \, Y7 N9 w
功 能: 将字符串转换为double型值
( b4 P% j& y9 b4 f+ M+ O. J2 a' ^" P用 法: double strtod(char *str, char **endptr);
: [4 x1 z: J3 K7 c程序例: </P># L  O/ d) D( K% N& H
<P><FONT color=#0000ff>#include <STDIO.H>
8 G4 O- ?  J/ p4 A1 `% e# V#include <STDLIB.H></FONT></P>
" w9 |& }: R  C, w: @3 l<P><FONT color=#0000ff>int main(void)
2 H% d; G7 E, Y{ + Q, L# N$ M! X& L2 _) s! R
char input[80], *endptr; 0 Q8 o) |# X* J( T' U
double value; </FONT></P>
# E) K0 L6 X, L<P><FONT color=#0000ff>printf("Enter a floating point number:"); . ?2 }. m3 P! J" n' E; }+ z2 c* O
gets(input); . e$ S9 s1 g3 ]/ K) x
value = strtod(input, &amp;endptr); ) _4 j* |0 ?; V  F0 u) K8 t+ `5 F& u
printf("The string is %s the number is %lf\n", input, value); 3 r  F6 ^7 o2 k  Q
return 0;
  K$ _4 C6 V# S( h5 f- E# v} 5 F) ?  |) o  q% G! X$ S
</FONT>* e8 e4 M5 u! ~9 g) q7 h: ^: A
# k: C1 b  N9 }- b- f* Y- w8 S: c
</P>
4 U& e% ^( N6 }5 V8 V/ W<P><FONT color=#ff0000>函数名: strtok </FONT>
2 g; E' x1 A0 R8 y7 m3 y" a功 能: 查找由在第二个串中指定的分界符分隔开的单词 ) g+ d, L6 _- Y- U. _
用 法: char *strtok(char *str1, char *str2); 1 z# V+ F0 W6 ^- C
程序例: </P>! Z8 @( R0 A! j% m: q1 o1 w  U3 J
<P><FONT color=#0000ff>#include <STRING.H>
) V) r! [) e7 b3 Q#include <STDIO.H></FONT></P>4 v( ]0 @& U- R1 e
<P><FONT color=#0000ff>int main(void)   f! ]5 {! s3 O
{
* d, a9 Q+ I9 `* ?% N" cchar input[16] = "abc,d"; % Z/ G2 t1 w: Z' a
char *p; </FONT></P>% T9 b- u! F5 i9 \% X* F( O
<P><FONT color=#0000ff>/* strtok places a NULL terminator
( z$ I2 ?1 s2 @( e  zin front of the token, if found */ . s# h6 V. P- R. I
p = strtok(input, ",");
/ L; [! I+ k  R7 H/ zif (p) printf("%s\n", p); </FONT></P>7 J5 p4 S0 Q# c9 Y$ R- [; H5 `6 |
<P><FONT color=#0000ff>/* A second call to strtok using a NULL
% k3 L5 Y) p% b0 z. {3 R1 Aas the first parameter returns a pointer 5 k6 w& m8 V" I  M# x2 f
to the character following the token */ % [/ a4 G0 H: S2 O5 L
p = strtok(NULL, ",");
2 d) d9 C, d5 o  p  q! Wif (p) printf("%s\n", p);
) G+ P% \7 e) i( ]return 0;
$ d( R7 ^. Q: |0 u9 w! h' z} 9 |" W! A$ \' U8 r6 V' o

. e/ b% {4 o6 P5 t" N9 k& b7 v- X
</FONT></P>
9 x7 b- _# e2 x/ R/ W<P><FONT color=#ff0000>函数名: strtol </FONT>
* d& I% a0 g4 h功 能: 将串转换为长整数
8 V5 H8 M# d% r用 法: long strtol(char *str, char **endptr, int base); 3 L  `2 e4 \) {% e. X
程序例: </P>
0 B$ P0 M+ \& ~1 y. |. V<P><FONT color=#0000ff>#include <STDLIB.H>
) R/ o& g2 z" V# U#include <STDIO.H></FONT></P>
5 o9 p0 ?. H8 h" }( n; p<P><FONT color=#0000ff>int main(void) ) p! K) ~" d0 W0 y7 f. D
{ ; g( C6 x3 E+ O: t* U2 M
char *string = "87654321", *endptr; . r/ T1 D7 a; C
long lnumber; </FONT></P>
; L, R! F1 \; b<P><FONT color=#0000ff>/* strtol converts string to long integer */
& `( p9 @% U( c) I  o# y2 Glnumber = strtol(string, &amp;endptr, 10); , k4 y0 F2 f8 z
printf("string = %s long = %ld\n", string, lnumber); </FONT></P>" G+ q1 s' }2 U7 s* |; v
<P><FONT color=#0000ff>return 0; 7 k/ y) Q3 K0 m8 i
} </FONT>! |1 d$ y3 L/ @. j" z3 i( N
</P>
; ^* X1 Y) |+ D, x: r<P><FONT color=#ff0000>函数名: strupr </FONT>
+ `8 j. p& M  O" K2 t功 能: 将串中的小写字母转换为大写字母
: Z3 b7 `! V8 Q. S: R( N用 法: char *strupr(char *str); / F3 L3 A' A5 u. n& h
程序例: </P>  X9 e' p# T% c
<P><FONT color=#0000ff>#include <STDIO.H>
/ y7 B& g& K' t5 Y0 V+ d#include <STRING.H></FONT></P>
. s( |+ X: E# C  A" A8 d<P><FONT color=#0000ff>int main(void)
! Y0 v  n( ~2 q  w0 V9 i" y{ 8 O0 q" r! \7 `* t+ n9 ?  e/ W3 J
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>7 k4 S- P4 [1 r4 y7 i/ s" p4 x
<P><FONT color=#0000ff>/* converts string to upper case characters */ $ ^& Y, h' c8 `3 J& P! b
ptr = strupr(string);
" \. V' t" A6 s- T1 Rprintf("%s\n", ptr); 8 F) V/ m, `, n' @6 M' ]
return 0;
5 F4 I: `* z; v2 W4 @} 7 U! T6 w8 |% y/ u5 w5 ?' l
4 P0 Z1 F: }) ^( G" x" \8 P
</FONT>
& Z% x2 Z4 T/ V/ P0 l9 F3 [5 W</P>
1 n% c7 L& y9 D" p" S; \) |) \<P><FONT color=#ff0000>函数名: swab </FONT>
) c1 [$ }/ B$ N* ]1 B- y5 ^. l2 R& ~功 能: 交换字节 * q  Q+ U1 P2 c6 u6 e
用 法: void swab (char *from, char *to, int nbytes);
( q) t3 B& y4 {# D1 }' V* V程序例: </P>/ v" D6 m, d4 H$ E
<P><FONT color=#0000ff>#include <STDLIB.H>7 ?% f4 X- @/ [* V6 G
#include <STDIO.H>: m% s" d0 M: s! P% m4 o
#include <STRING.H></FONT></P>
) W$ }9 R6 O$ q4 Y. I<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
% q6 k: L" s9 j- w2 V& i# [8 {4 F2 Qchar target[15]; </FONT></P>
; N9 t* ]" t8 Y9 ~<P><FONT color=#0000ff>int main(void) - }$ [8 m$ p/ f1 \3 Y- I" F+ w# \
{
" O) J6 a- y# ]3 g# B4 k- m9 q. Pswab(source, target, strlen(source));
( G* e( R$ w4 Q- U% n2 Xprintf("This is target: %s\n", target); 7 G. `0 o9 S3 {9 c8 v
return 0;
0 q- }  C1 m/ g0 L2 ?} / m$ N' T5 J0 K9 R( M
</FONT>( e  ~5 A% ^5 p1 \$ q/ W+ |
' D' L" W3 r! B' F' T
</P>1 x7 s/ y) O( Q+ p/ S
<P><FONT color=#ff0000>函数名: system </FONT>. L% N8 E, W" s& `# V. y
功 能: 发出一个DOS命令 : s4 G0 o/ u# J2 n) \
用 法: int system(char *command);
7 A3 D6 S# L  z, b0 I9 F% w# W程序例: </P>
0 e" z: _& [6 \: K0 r) X0 Y- B' r0 [<P><FONT color=#0000ff>#include <STDLIB.H>" h. t2 J! T6 n9 x* o, @+ ~
#include <STDIO.H></FONT></P>4 y+ h' ~& {4 i& |8 d' V9 v0 Y
<P><FONT color=#0000ff>int main(void) % {) K8 ^+ i7 a5 Y1 [
{ + w0 n) F5 m# b% z. t' h
printf("About to spawn command.com and run a DOS command\n");
$ b, K- a5 v* ^5 a# F8 |/ t' W* ysystem("dir");
# e" S( G* r3 nreturn 0;
5 C1 f0 M: S2 v# y} </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:41 , Processed in 0.553487 second(s), 52 queries .

回顶部