QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>- w9 u  P/ I/ O/ Z* U* Z" v- ?
功 能: 改变数据段空间位置 5 v5 v  v9 O1 s) d
用 法: char *sbrk(int incr);
" B7 m7 L! C. E5 w* r程序例: </P>
% P: ]8 M6 B: o- M) ^<><FONT color=#0000ff>#include <STDIO.H>! Y, b$ F/ l3 N9 D; @7 ^( W9 {
#include <ALLOC.H></FONT></P>: P3 P/ Z9 T  K: d
<><FONT color=#0000ff>int main(void) . b0 }9 F2 v- d* b5 A# r5 h1 I- W
{
4 K3 Y: W, k4 Z  O$ W/ kprintf("Changing allocation with sbrk()\n"); ) W) F# ?2 I, S# Q4 s
printf("Before sbrk() call: %lu bytes free\n",
5 i$ U6 x& t. u0 T5 |(unsigned long) coreleft()); 9 N/ L/ O5 V6 D7 F! d: z$ {* k
sbrk(1000); # H% D7 A6 l* @4 W! w
printf(" After sbrk() call: %lu bytes free\n", 7 q+ g; X9 `9 f: O" w
(unsigned long) coreleft());
" H. W7 S& T5 D5 ~return 0; ; P# J% P# y; V" R- a0 `
} - y) K6 t' ]3 I7 t$ h& ^, K2 J2 P
5 i$ |4 y$ t7 k5 |! M6 I6 i
</FONT></P>7 \  y& o' K# y6 N! U
<><FONT color=#ff0000>函数名: scanf </FONT>+ s1 n6 h1 L3 r
功 能: 执行格式化输入
! I+ F2 Y: V6 Y$ ]* F用 法: int scanf(char *format[,argument,...]); & m/ e) q6 T" C
程序例: </P>' j& l, `0 `+ ?$ g2 D1 S- H/ N* L" z
<><FONT color=#0000ff>#include <STDIO.H>
% C: ~2 [8 w, J. h( t$ ^#include <CONIO.H></FONT></P>
! I) s# r# f2 {2 Q<><FONT color=#0000ff>int main(void) - w& {& Z" x1 ?( O
{ 4 d' b; f, Q# q$ K% o( f
char label[20];
1 \0 n1 @# p# V# v  u- n* i  ~. schar name[20]; ) E) z$ H4 x, l' F% s$ t, f. S
int entries = 0;
9 \0 C+ Z/ p& ]' w* {; o" ^int loop, age; 7 o/ h- t' w9 Y# O9 P
double salary; </FONT></P>3 j; D# W9 I1 g1 Q
<><FONT color=#0000ff>struct Entry_struct 1 `" M6 q! r" v& e) o5 ^8 h
{ + D# F% o' q2 D1 [9 n; j5 M
char name[20];
6 J: C1 W, F5 f) Qint age;
" x, C8 q) a$ w. dfloat salary;
# d# f- H$ o, S, `) u/ |} entry[20]; </FONT></P>8 ^4 u5 k% J, K' K6 F/ v& C
<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
3 t: m, G( K2 D- O* v% D: W' }3 ]. ]printf("\n\nPlease enter a label for the chart: ");
1 y2 G9 @5 d# Dscanf("%20s", label);
: ^3 a4 S' C# ufflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>$ h0 P  _8 K4 ~  [( }
<><FONT color=#0000ff>/* Input number of entries as an integer */
# \; r5 r  H: M+ _printf("How many entries will there be? (less than 20) ");
. s& {1 J5 S  Lscanf("%d", &amp;entries);
6 h. S) A' r7 n& x$ A4 I8 G  kfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
) f9 ]$ C0 u2 C9 }. s# G% z<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ / o+ [( Y8 S6 r! Q: A
for (loop=0;loop<ENTRIES;++LOOP)
7 K" V' @0 ~4 G9 e7 B. e2 _7 P {
5 t% v, _, {" p! g+ U! Vprintf("Entry %d\n", loop); 2 k- a! \. d- j1 ]8 Q9 X
printf(" Name : "); # a) z( S# d1 k- m# W4 c0 Q( R4 v
scanf("%[A-Za-z]", entry[loop].name); ' D& _, u/ M  Z7 W! V; j
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
' v! s: y( V0 b% i+ |2 t<><FONT color=#0000ff>/* input an age as an integer */
% {# w5 O* H' h( \. W6 U/ v. E5 tprintf(" Age : ");
# Y/ }* ^' [0 m) t! f5 Sscanf("%d", &amp;entry[loop].age);
$ [  H, X+ n( h& Q" w0 L* Vfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
/ v' {; T( ^8 a" }) N& C# q! _<><FONT color=#0000ff>/* input a salary as a float */
, I7 X- G8 V' ~1 B) eprintf(" Salary : ");
# S- K# r  W9 ?, [scanf("%f", &amp;entry[loop].salary); 5 b) |* [9 e( F7 L4 {) V% y7 T" }
fflush(stdin); /* flush the input stream in case of bad input */
; r8 B0 K  y; L! J} </FONT></P>* M# \  c( g( {. z' a5 n7 J
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
8 Q0 I& v. i+ _, E  T: h; Uprintf("\nPlease enter your name, age and salary\n");
7 j2 ^! ?' a/ e: _$ A  Q" I# ^( Yscanf("%20s %d %lf", name, &amp;age, &amp;salary); 5 f. h- X  i! s* Z- |! q
</FONT></P>+ q/ t! T0 `; E3 s- x
<><FONT color=#0000ff>/* Print out the data that was input */   s) s( G0 Z4 ^/ k
printf("\n\nTable %s\n",label); ! Q+ E* y9 n! {/ n; a5 T9 I
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); ( l/ m% i6 U: u3 {1 }4 W% Q
printf("-----------------------------------------------------\n");
, i* R6 t. R/ \7 K! yfor (loop=0;loop<ENTRIES;++LOOP)
1 {! r7 X4 d# H! ]& [ printf("%4d | %-20s | %5d | %15.2lf\n",
* x2 c( {+ n1 kloop + 1, 4 Q3 m( I3 F. W
entry[loop].name, ; `7 Y+ w6 u. w9 F9 H- b
entry[loop].age, * n/ `! u2 ]5 B9 p' e
entry[loop].salary);
# T/ {% {6 @: N" p, oprintf("-----------------------------------------------------\n"); 1 X2 W7 \6 z- ~$ @
return 0;
; S% |# @4 k( p; z; Z5 d; z% N& L} 6 y' f1 _1 v/ s3 P5 g! r5 \
</FONT>
  \' }4 V/ ^- I+ v# ]7 f$ Z</P>
1 v+ A! |% C3 I" g: [<><FONT color=#ff0000>函数名: searchpath </FONT>
+ a9 k8 ], Q6 q6 x功 能: 搜索DOS路径
% u" C. V( g- k8 D: t" e6 x" L用 法: char *searchpath(char *filename);
; C. n! C. T6 u0 C1 P$ [程序例: </P>
6 L( j; Z: `1 q, ~8 L( h2 ^<><FONT color=#0000ff>#include <STDIO.H>
' K! F& P+ G- L; I! Z#include <DIR.H></FONT></P>
/ u2 y5 V7 ]. b<><FONT color=#0000ff>int main(void) & G+ p) ~3 z! B
{
' Y! o: F9 E% v8 S% x. D$ bchar *p; </FONT></P>
- f5 t9 w5 U6 A<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer 2 W+ P% o* ]1 T
to the path */ * R/ t: ]( K: H" A( D- ]! H
p = searchpath("TLINK.EXE");
) o& b3 b1 w2 h& \% U% x9 \& f. ]printf("Search for TLINK.EXE : %s\n", p); </FONT></P>4 t6 A; A8 U/ S4 p
<><FONT color=#0000ff>/* Looks for non-existent file */
; x5 Y* @$ @* ?$ y) s& s- Tp = searchpath("NOTEXIST.FIL"); " w  V2 G* q, [$ E- n
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>- I+ t7 p) t5 z5 F
<><FONT color=#0000ff>return 0;
5 s! n8 f3 ~! [8 X* Q, E- h9 |} ' ~# f6 Q+ Z/ y, {. e

; s3 Q1 _% N& Q0 v</FONT></P>+ `& M! L8 e( r/ F9 B
<><FONT color=#ff0000>函数名: sector </FONT>0 X0 r) j0 N- N3 B1 F! c
功 能: 画并填充椭圆扇区 7 t1 k9 b- u( ]( l! v% |& f) M
用 法: void far sector(int x, int y, int stangle, int endangle);
# F/ |/ ~$ i9 H% b: m程序例: </P>. {- r% z! Q2 g6 w9 h* s$ V+ E9 ^
<><FONT color=#0000ff>#include <GRAPHICS.H>
3 i; C! E, X7 {# v# \#include <STDLIB.H>! V6 `% d8 a4 q' Q: g/ [2 z
#include <STDIO.H>
) y! x6 @! F0 B% A1 v#include <CONIO.H></FONT></P>
( B9 I8 i/ O, V5 g<><FONT color=#0000ff>int main(void)
9 W! j8 A6 z! r. e" h{
! \+ t* r/ M: ^, O6 d: u/* request auto detection */
( \  w* \! E( H6 i. E- qint gdriver = DETECT, gmode, errorcode; : [: c. k. z4 J; ^- u& C
int midx, midy, i; - d$ [5 q. T3 B% U1 x
int stangle = 45, endangle = 135;
! V! ~9 u' \) ~$ A3 B2 vint xrad = 100, yrad = 50; </FONT></P>7 d7 i; S3 s% X  u
<><FONT color=#0000ff>/* initialize graphics and local variables */ 9 P7 W& T% a* ?  N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, M" o5 a0 h1 @* T<><FONT color=#0000ff>/* read result of initialization */ % w/ p! l2 M$ L2 T8 U9 e
errorcode = graphresult();
( a( R5 x5 u' ]+ R1 b2 Q. W% Nif (errorcode != grOk) /* an error occurred */ 8 j! r( f1 J& J$ d, X
{ 7 S& X9 Y+ u7 {9 K/ N- f1 v# f
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 V# D& g5 d' Y$ z# [0 p; Rprintf("ress any key to halt:");   U/ l+ g* G: y8 b; }1 ~6 w: z. ?
getch(); - K' M* u4 y8 ~' p2 F
exit(1); /* terminate with an error code */
1 p- R3 W! u3 @& Y7 C} </FONT></P>
+ F. k7 z! D6 ~; w<><FONT color=#0000ff>midx = getmaxx() / 2; " Y% q, P% R2 F! M5 P
midy = getmaxy() / 2; </FONT></P>
0 M7 c! o8 I; D5 `/ Y<><FONT color=#0000ff>/* loop through the fill patterns */
6 }' V+ R3 q. Z  }2 ~8 Tfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ( L6 Z$ I& N$ E
/* set the fill style */ 9 z( ^6 |) k" m
setfillstyle(i, getmaxcolor()); </FONT></P>
% Z" u, L1 b4 J' F  h. N7 D<><FONT color=#0000ff>/* draw the sector slice */
5 V% X+ u. u- t4 b# P" c, Psector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>8 O! ^+ X3 I) d8 e3 O7 u
<><FONT color=#0000ff>getch();
: a& X! n* h& A, t2 F  [* t} </FONT></P>5 F0 o# o, z0 o) S: b
<P><FONT color=#0000ff>/* clean up */ ) L7 b" N. E) B* p9 E- i
closegraph();
7 _. t7 m6 ]2 Q. Y$ m7 Dreturn 0; - }) b# ?1 P" ?) O# Q
}
7 W6 k% z4 z' ]( X) S3 x# i</FONT></P>& Y0 P0 U6 @. U: `0 B' F
<P><FONT color=#ff0000>函数名: segread </FONT>
/ k: Z- J5 O9 S7 Q, I功 能: 读段寄存器值 # u, c# ]: @( W' F7 I( J- C5 D4 t
用 法: void segread(struct SREGS *segtbl);   f# f" \5 v7 _+ l$ ^0 \- A* V
程序例: </P>
/ t- d' p" r' K. P4 P/ i<P><FONT color=#0000ff>#include <STDIO.H>
" y7 G- s) v0 V& ^6 a- R- {#include <DOS.H></FONT></P>
' T* l1 `6 a3 W4 G<P><FONT color=#0000ff>int main(void) , l# z' d  W* o, U: H6 E* u
{
6 D& Z! U, ]# b' ^struct SREGS segs; </FONT></P>
% \" X, U$ n2 S; @9 [<P><FONT color=#0000ff>segread(&amp;segs); 6 v! P* M7 [1 m& s( R
printf("Current segment register settings\n\n");
" z' O/ M  E; a, n' S* Lprintf("CS: %X DS: %X\n", segs.cs, segs.ds);
: t; k- T. R1 X! v+ {! B- ?printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
7 F; h6 J  S. o4 o2 d( y" t$ V<P><FONT color=#0000ff>return 0;
+ H* w7 @# p/ W# {' J, n& f/ Y} </FONT>) ?+ s& h# C# u" ^
+ i' F6 r' \0 n; o
</P>! |: g8 C$ B1 J% M
<P><FONT color=#ff0000>函数名: setactivepage </FONT>
5 }, c8 x6 ^) @# n功 能: 设置图形输出活动页 # R5 y$ Q+ m: G4 ~% [, P. f. d
用 法: void far setactivepage(int pagenum);
. Q- L- ^6 N$ ^/ i% ?/ D程序例: </P>+ ]" U! t* _" x/ S$ h0 q1 k3 ~
<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 C6 C" ], v8 |4 m& s2 p#include <STDLIB.H>2 g& f5 M5 o7 c) Q0 \
#include <STDIO.H>
" c- x  i2 |& m9 q/ D#include <CONIO.H></FONT></P>+ n  I" `! ?1 }% U
<P><FONT color=#0000ff>int main(void) ( `2 e' s/ Y4 c% s
{ + B* _7 u6 U" e# o4 ~
/* select a driver and mode that supports */ : ~' @. R0 o# |9 Q
/* multiple pages. */ 7 n, [: Y- f) W! d. ?* `% b! Z" ]$ h
int gdriver = EGA, gmode = EGAHI, errorcode; % K/ h/ b3 p3 ]1 F- y4 G
int x, y, ht; </FONT></P>" e( z, T+ S. g' ~
<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 K  e7 C$ A( [6 ]' k/ n! @$ Kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 J2 c- m2 c! E% J<P><FONT color=#0000ff>/* read result of initialization */ / o" p/ R; x8 l0 w  m" v/ J
errorcode = graphresult(); $ M1 g2 ^6 E3 \1 y
if (errorcode != grOk) /* an error occurred */ ! \" C( p4 d0 Z2 I
{ 6 T( r7 w4 T; P5 a; {0 _
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( w6 C: H  J7 s  \printf("Press any key to halt:"); $ b4 X5 O0 K* ?% Y9 q$ v4 o1 V8 t
getch();
$ ?5 B$ J$ Z: f9 `exit(1); /* terminate with an error code */
  L1 H5 [0 u5 `- i2 q+ z} </FONT></P>
5 g6 p# ?* g  J7 r) M$ L<P><FONT color=#0000ff>x = getmaxx() / 2;
1 A: z! ?/ n: U! ~" {1 cy = getmaxy() / 2;
0 n# S) q. ]5 Jht = textheight("W"); </FONT></P>
" l2 H' ^3 L9 N" f( i5 T2 O$ D<P><FONT color=#0000ff>/* select the off screen page for drawing */   A/ O% z* U2 O" E, j8 p! _& C
setactivepage(1); </FONT></P>
3 h& k3 I1 O  X0 s% [5 D<P><FONT color=#0000ff>/* draw a line on page #1 */
6 o* \! E, @0 Z: S& \; }: w( Lline(0, 0, getmaxx(), getmaxy()); </FONT></P>! e5 z. l$ R# I; P, h
<P><FONT color=#0000ff>/* output a message on page #1 */
0 {: j7 m1 n" @# |+ }1 Gsettextjustify(CENTER_TEXT, CENTER_TEXT); 6 L# `' [6 x- q2 L2 m% u$ Z
outtextxy(x, y, "This is page #1:");
4 @: I2 _" F0 |outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>. U$ N3 j/ \2 K0 B4 k2 U
<P><FONT color=#0000ff>/* select drawing to page #0 */
1 }/ M# G0 ?5 X' _setactivepage(0); </FONT></P>; ^  F: ]9 B! l; f8 g
<P><FONT color=#0000ff>/* output a message on page #0 */ $ ]5 D3 v& H+ u% e9 Z
outtextxy(x, y, "This is page #0.");
& j# E; C; ^- _( Oouttextxy(x, y+ht, "Press any key to view page #1:"); 6 r- k5 f, g0 H
getch(); </FONT></P>
" Z- O  Q7 [+ ~/ v2 W) a. Q8 P<P><FONT color=#0000ff>/* select page #1 as the visible page */ " x7 C; c* _9 v; ?5 B+ b
setvisualpage(1); </FONT></P>2 e, F5 n3 [& t, P+ m
<P><FONT color=#0000ff>/* clean up */ + J7 `' J  v% V& A7 f/ p4 K% J
getch(); & \2 M2 h1 K: s) i+ K; x
closegraph(); # C9 N. ?0 m% u: W
return 0; / f# X' e* `: \" E- h9 n4 g
}   Y( a3 o" E- ]3 d* l% L3 X. f
</FONT>
0 m7 T5 }6 D7 d. f. A' d</P>
1 r" y2 k: h  v% y% d6 ^<P><FONT color=#ff0000>函数名: setallpallette </FONT>3 x# v/ p8 l/ Y* v  {
功 能: 按指定方式改变所有的调色板颜色 % ^2 K& w2 d; ]4 r( g5 u9 {
用 法: void far setallpallette(struct palette, far *pallette); . x" N8 L% Q- e# x1 M! i! t1 _6 d
程序例: </P>
: T: _& _  k& k( p+ z" V8 L  P  s<P><FONT color=#0000ff>#include <GRAPHICS.H>2 D# C0 _* a4 f% I2 U% I2 i
#include <STDLIB.H>5 m0 b! s! @: R& Y! M
#include <STDIO.H>( P- C% q( o' L% ]& S9 e% q
#include <CONIO.H></FONT></P>
" O; W; K( b* K5 y" c1 g<P><FONT color=#0000ff>int main(void)
/ M5 t* f3 p$ \$ b/ Z{
  b6 r- @" O9 b, |$ {* Q/ I/* request auto detection */
, W' S- n1 }" k, v2 ~int gdriver = DETECT, gmode, errorcode; 7 e. q8 o* J, P; \
struct palettetype pal;
. R& C0 E- }8 Y% J! sint color, maxcolor, ht;
1 z. @+ q8 H3 `+ X# S" O, _* C/ Qint y = 10;
0 j/ I2 ^# k8 s+ r1 Schar msg[80]; </FONT></P>
. W+ V0 \) X( i# o! B6 E; `<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 D" g) d2 F: x2 @! D9 q$ N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( L$ Y# b7 Y" o( q
<P><FONT color=#0000ff>/* read result of initialization */
- U4 v8 h# F5 M) T! uerrorcode = graphresult(); 2 M$ a) }0 N' \! A( @8 Q
if (errorcode != grOk) /* an error occurred */
4 m, f+ N$ A3 c" F% n{
/ y- ?1 a* \8 e7 Yprintf("Graphics error: %s\n", grapherrormsg(errorcode));
* i. V, P, |: |0 Q9 n1 zprintf("Press any key to halt:");
2 w; G# N& T9 @1 ~0 e1 S5 cgetch(); " w% a# D7 E0 g% r8 z0 J7 Z3 r8 u
exit(1); /* terminate with an error code */
2 b' c0 G: W; k$ d; X6 K2 z} </FONT></P>
" J1 u3 W3 k5 a3 H) n<P><FONT color=#0000ff>maxcolor = getmaxcolor();
9 k* t, o2 Z3 h. fht = 2 * textheight("W"); </FONT></P>
& ^/ P! E- k! l: U, C0 N6 n<P><FONT color=#0000ff>/* grab a copy of the palette */
. L9 ^0 j, j- {# |getpalette(&amp;pal); </FONT></P>
$ C1 \( e, i% L$ G9 ^  G<P><FONT color=#0000ff>/* display the default palette colors */
7 B5 ^3 a+ P, m: s% Wfor (color=1; color&lt;=maxcolor; color++) ; \* ?, |: ?) J+ x$ Q
{
6 ]! I, \" g  Y2 x( isetcolor(color);
+ p0 h3 `7 J9 H3 O: U2 bsprintf(msg, "Color: %d", color); 4 o' G9 [' p6 [# v% c; m( ]
outtextxy(1, y, msg);
9 O& x. P2 E) l/ ^: d. s, Yy += ht; 7 z. C$ g- e/ F" e7 d4 s
} </FONT></P># j+ Y2 D6 d  j& v5 C+ f
<P><FONT color=#0000ff>/* wait for a key */
9 f) u7 ^2 e% _1 P# S. O# ggetch(); </FONT></P>
$ j4 D* f+ I# r" Q3 u<P><FONT color=#0000ff>/* black out the colors one by one */
6 i- M/ z% r* U8 R! v, C8 Ufor (color=1; color&lt;=maxcolor; color++) ( q$ D2 X# X/ I8 u: V3 o
{
% [. D% f8 |( F( ~( R" C4 p' isetpalette(color, BLACK);
- I! K, U3 M8 ~4 e  _/ u* zgetch();
* W, A0 W/ W8 n- l$ L% a} </FONT></P>8 J) |8 s" H7 r; ]2 q  j
<P><FONT color=#0000ff>/* restore the palette colors */ 9 {( Q0 r7 e2 e; o$ L5 Z( i
setallpalette(&amp;pal); </FONT></P>
' }4 r0 ?7 x  q% a+ p* E<P><FONT color=#0000ff>/* clean up */
$ k: D. G4 F$ S* P7 k- d7 T* Agetch(); 1 p6 T" J$ J# s* z9 ^# j: V
closegraph(); 4 l# J0 I! A; O
return 0;
$ _2 k; K- E9 c# t} . F9 S" B  E# F. x% x" M

9 a  N- M% {1 Y+ d/ a, ~1 p</FONT></P>
/ E5 a" m' _/ ]  |* i( e<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
  J8 Z1 c2 v2 @  T! u功 能: 设置图形纵横比 : |0 ^" U1 m2 E) a
用 法: void far setaspectratio(int xasp, int yasp);
4 {$ ~  u& a3 |3 Q& G* }4 m! o程序例: </P>* w) P( R5 A8 Y1 L5 b
<P><FONT color=#0000ff>#include <GRAPHICS.H>! M# S3 o' p, c2 E  J
#include <STDLIB.H>
$ t! _  O4 X) a/ C. [#include <STDIO.H>
0 H( W0 h3 U3 [#include <CONIO.H></FONT></P>
$ }& r8 l1 ^! R) S3 l# P/ R* K$ X<P><FONT color=#0000ff>int main(void)
; s+ O* [- ]0 D& t{
5 f  S, ^- h7 f  f3 K- ~/* request auto detection */ : u- q2 M! R- p9 W$ G" ]% D
int gdriver = DETECT, gmode, errorcode;
- m  L8 b. R: a: L$ a) Zint xasp, yasp, midx, midy; </FONT></P>
  \* f& L9 f4 m, }! Z+ N8 q<P><FONT color=#0000ff>/* initialize graphics and local variables */ * \9 |$ U- ~2 d5 _: d- l5 ^. f
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 i3 u, g/ \0 |/ P6 l6 N2 ?$ ^& m
<P><FONT color=#0000ff>/* read result of initialization */
/ V4 M* f! z6 |" _errorcode = graphresult(); $ i3 t' m/ @$ V& w$ f
if (errorcode != grOk) /* an error occurred */
2 @1 _1 C! I/ `& C2 Z{ 8 j; W! [* X: L  y1 ^
printf("Graphics error: %s\n", grapherrormsg(errorcode));
1 _3 e/ Z, I* _7 ?- U1 Tprintf("Press any key to halt:"); " b$ {" M( O8 Q2 L2 m2 u
getch(); 5 x) z3 ?4 J% K" A$ M, f
exit(1); /* terminate with an error code */
/ {- m6 q3 ^' Q$ u- v+ [} </FONT></P>, |7 T: T" ?$ v$ n
<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 s+ `5 `/ ]5 ^+ X( ?; G/ imidy = getmaxy() / 2; " d0 \2 p, ?0 e% M5 z+ B: \# E
setcolor(getmaxcolor()); </FONT></P>7 C6 p3 v6 I% `" x% @+ h
<P><FONT color=#0000ff>/* get current aspect ratio settings */ / ]! M  z  k4 k* s
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>" X) h& Q8 ]' N& B# ?# p0 g+ N( U6 Q$ `
<P><FONT color=#0000ff>/* draw normal circle */ . ~5 y/ W: y" F, F9 c. a  J
circle(midx, midy, 100); , @: d% w: ]$ x9 t* z3 C7 f
getch(); </FONT></P>
2 j3 e( D+ Q. t) U! w1 y<P><FONT color=#0000ff>/* claer the screen */ ' k2 J7 `8 r5 b- P
cleardevice(); </FONT></P>! e1 l1 T/ Q+ O/ J  ^( t  E, g
<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */
+ V* P' t2 |+ u! a1 _7 L, @setaspectratio(xasp/2, yasp); 6 ]% k& C' K7 T
circle(midx, midy, 100);
: y; G3 }5 p, s- G. b+ l& Vgetch(); </FONT></P>
- K! q2 R* l+ Y/ j9 [' n/ P4 V<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
5 `% i( q+ r& Q0 \- Xcleardevice(); 6 v) M7 w$ v0 n
setaspectratio(xasp, yasp/2);
; |$ l) o$ I0 k4 P% ecircle(midx, midy, 100); </FONT></P>
8 G7 [& q" A$ J$ `8 s, z<P><FONT color=#0000ff>/* clean up */ & q+ W; e' U. B
getch(); 9 P" J! ^( p' x! U( \' `
closegraph();
, w% W4 w" ?- h8 `5 vreturn 0; ( j: e% F  r5 o/ t
} 6 i) ?9 n; e4 ?0 U- }0 ^
</FONT>" `/ O' h7 Y, b1 n6 c
</P>
- c5 [' j9 y) F+ ]) _8 P, |6 R<P><FONT color=#ff0000>函数名: setbkcolor </FONT>+ d* P1 y- Y. C, F! B7 C, D
功 能: 用调色板设置当前背景颜色
8 V( B0 T7 a! I' u% h' b1 N用 法: void far setbkcolor(int color); $ q: {0 S0 I8 {( A' Q6 g9 d
程序例: </P>: G( t# H8 n) d3 \5 j( U7 [2 I
<P><FONT color=#0000ff>#include <GRAPHICS.H>
, {4 t$ r8 F$ y9 a( t- j#include <STDLIB.H>& i: h% v$ y2 m1 l8 W
#include <STDIO.H>) [6 t* _/ T' A) A% P
#include <CONIO.H></FONT></P>
; d5 F4 H7 _3 S# d/ N<P><FONT color=#0000ff>int main(void) 8 M9 ~' E1 e$ A
{
- b# K2 W/ u1 v( V" k4 Q' o/* select a driver and mode that supports */ " v: c5 A4 |  q8 s, D! N
/* multiple background colors. */
, T7 U2 ]' y( h4 e0 q  Eint gdriver = EGA, gmode = EGAHI, errorcode;
; y. [) l3 q2 O% ^4 B$ S9 pint bkcol, maxcolor, x, y;
8 @5 n0 q; V$ c' q" l! K- Schar msg[80]; </FONT></P>
8 C' M/ E5 {2 p# f2 E2 X<P><FONT color=#0000ff>/* initialize graphics and local variables */ + m2 _5 t) w% X$ f" h, y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( @$ e3 _; V4 V) S/ @
<P><FONT color=#0000ff>/* read result of initialization */ $ i9 [( b. j/ t( r  H/ t) a0 [
errorcode = graphresult();   b& m6 X, d1 X' D7 m& V! F
if (errorcode != grOk) /* an error occurred */
9 b. ?4 e+ c0 K0 R' k  V{
5 U5 g! S% U+ ?1 j8 \7 m+ jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : C* ^" f9 v. y9 {6 n, r. q, [0 _- P
printf("Press any key to halt:");
; a8 Y8 f3 r' g0 A+ R; `; o; a5 Mgetch(); % [5 x/ {0 U+ Y
exit(1); /* terminate with an error code */
5 k4 k* n2 k9 n0 h  a} </FONT></P>
, ]$ e# `& Z0 u7 Z<P><FONT color=#0000ff>/* maximum color index supported */ 7 M. @. X8 ?8 ]2 H9 T5 @
maxcolor = getmaxcolor(); </FONT></P>2 m4 L# Q( X' g
<P><FONT color=#0000ff>/* for centering text messages */
* n* l, ?$ ~3 I5 S3 H+ n+ Ssettextjustify(CENTER_TEXT, CENTER_TEXT);
( U' Q* j  L0 y% R5 a. P" px = getmaxx() / 2;
4 @; ^* k8 B2 W6 V6 jy = getmaxy() / 2; </FONT></P>( X4 u! g  g0 t$ R
<P><FONT color=#0000ff>/* loop through the available colors */ . S% j9 K6 T) }5 u" I
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) . I# {- \, ]7 w* S
{ - j) H' \, [/ l4 V0 E% l
/* clear the screen */
$ J( [9 N. |5 l5 y" {) Q, n  Rcleardevice(); </FONT></P>
6 Z9 L0 O2 m& K<P><FONT color=#0000ff>/* select a new background color */ 8 N" e, n9 B7 T- r
setbkcolor(bkcol); </FONT></P>
, F% E1 N- o) v9 A5 f" a- D<P><FONT color=#0000ff>/* output a messsage */ + I5 L8 m0 t+ N
if (bkcol == WHITE)
* r! s* K9 c- c: t( _! [. vsetcolor(EGA_BLUE);
5 I: f. q" |4 v( J* K/ I$ ^& a7 dsprintf(msg, "Background color: %d", bkcol);
, }4 j8 \4 T) m9 souttextxy(x, y, msg);
' U% t; _6 v' d# {getch();
% S3 Q& h" V2 M3 q, L% V} </FONT></P>7 m# j( K! P, U; B1 U
<P><FONT color=#0000ff>/* clean up */
4 T" z1 f4 m2 v% eclosegraph(); ; }+ k/ x% }, [9 R2 l+ }
return 0;
& V% M  P' M4 K$ ]} </FONT>
. @" a# H4 q: B' w, L9 C0 v: l) L5 A
</P>
7 {# x& R! n, B2 L1 ^# i6 a<P><FONT color=#ff0000>函数名: setblock </FONT>* I* I, f6 j) C/ O
功 能: 修改先前已分配的DOS存储段大小
2 H8 M! I3 O% x0 k! z: d用 法: int setblock(int seg, int newsize);
: T" A) D' ], k( E2 z程序例: </P>
  B. P3 `9 u  z9 J% K  ]<P><FONT color=#0000ff>#include <DOS.H>/ I7 c0 U% H  E
#include <ALLOC.H>& n7 D9 K6 {3 w2 W/ v1 \) `
#include <STDIO.H>
% @  ]/ X; K( l& Z) K#include <STDLIB.H></FONT></P>
, |- i1 p9 o2 @- u# k; V& ]: W<P><FONT color=#0000ff>int main(void) + a! Q$ O1 f9 s: J
{
% x" u* Y( `+ r# p5 G, runsigned int size, segp; 8 U5 M6 P1 C' B9 z8 ?9 p% E
int stat; </FONT></P>
. C% |4 V& N9 D<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */ 4 b6 k8 J) [9 R* z- A  F
stat = allocmem(size, &amp;segp); & X5 O  ]# C$ K5 s
if (stat == -1) 4 B+ m, C' D* c% l/ ]) y5 Z
printf("Allocated memory at segment: %X\n", segp);
9 b/ {, I* G6 L, O- z( k# felse 4 j3 K- p$ _9 _  F% a% h
{ " ~+ V( e' `8 v
printf("Failed: maximum number of paragraphs available is %d\n",
  j" Y% {% a+ z( Kstat); ! y# k: O& u- }) l! |6 d
exit(1);
( L/ [" d) X0 w: V} </FONT></P>
6 A8 v9 ?2 p! Q<P><FONT color=#0000ff>stat = setblock(segp, size * 2); : r% r  {5 v0 J* @
if (stat == -1) 2 `# R5 M) c0 Z& |
printf("Expanded memory block at segment: %X\n", segp);
2 ~$ Y* @, C# eelse " V3 d. x5 H  K8 k" J" i
printf("Failed: maximum number of paragraphs available is %d\n", % q9 p1 Z5 P7 W
stat); </FONT></P>+ r, h9 }( \" G0 G; ~% c$ ]
<P><FONT color=#0000ff>freemem(segp); </FONT></P>) Z. ~, t* a' b7 J' l+ o
<P><FONT color=#0000ff>return 0;
4 l# A8 ?2 M" Z! x' c}
$ h! ]/ L% h9 a7 E" c4 O</FONT>- y9 R6 K! y& G7 N5 ~4 a
</P>) ?7 G( P0 R1 `  d8 I/ f
<P><FONT color=#ff0000>函数名: setbuf </FONT>
. y! ~6 `" d6 g6 x功 能: 把缓冲区与流相联 $ l( _- C, k( R' {$ J  z
用 法: void setbuf(FILE *steam, char *buf); 3 H7 w9 ?# f2 F# E5 N5 W
程序例: </P>; ?' x5 Q# o  o+ d8 H3 O
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>; j5 j' Y) Y. G. k3 M2 Q+ j; I" g
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ ) h7 a4 o8 ~/ A6 M# m/ {- d( N
char outbuf[BUFSIZ]; </FONT></P>8 L* [0 o' h5 [" a
<P><FONT color=#0000ff>int main(void)
0 M% @' c) h% M: r{ ' k$ x1 R  e3 E/ I5 W8 q
/* attach a buffer to the standard output stream */
! w  i- K& X* J3 ?$ B. L) k+ v- y* ^setbuf(stdout, outbuf); </FONT></P>2 }9 m7 W( p' n1 P. W, r
<P><FONT color=#0000ff>/* put some characters into the buffer */ $ H6 ?7 A7 j9 F6 q
puts("This is a test of buffered output.\n\n");
; E+ c# C& O- \8 I! ~; [puts("This output will go into outbuf\n"); ) g6 h3 P4 K. L& o  J
puts("and won't appear until the buffer\n");
( P) r5 r( M  gputs("fills up or we flush the stream.\n"); </FONT></P>
6 J( Q/ ]0 J" w' r! d<P><FONT color=#0000ff>/* flush the output buffer */
/ ^8 }% Y; P# S. S4 v" l  tfflush(stdout); </FONT></P>2 a' P1 s8 ^/ X/ X7 X
<P><FONT color=#0000ff>return 0; 0 k5 i3 i/ J9 f( {/ ~' Z
} ) o. y) |3 z4 _" T% b! B
</FONT>
% H- g8 ~0 L$ `: c( a8 o</P>! l: g1 f7 {( h  v
<P><FONT color=#ff0000>函数名: setcbrk</FONT>
) E2 g5 r" W( X) m功 能: 设置Control-break
( m! y9 ?& Z9 B& E( U  [& M用 法: int setcbrk(int value); $ v) r2 F6 b% z' f( b( q  Y* R
程序例: </P>- `8 j7 r& B0 x2 N
<P><FONT color=#0000ff>#include <DOS.H>
! o# O; R5 t! A# l, I1 d( m: H#include <CONIO.H>0 S# b( A1 g! R- f# U! K, q: T7 t
#include <STDIO.H></FONT></P>$ k! V7 L# z. {( L4 Q
<P><FONT color=#0000ff>int main(void)
" J6 l1 t2 a$ b6 [- X3 o" Z5 v( }" q$ ~{
) ^7 q: n4 y# Q5 S$ Gint break_flag; </FONT></P>
3 A1 s5 c7 q6 v( Q! Z1 d1 X0 D<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
# Q9 |* A5 c3 c3 A5 t2 X" ~printf("Enter 1 to turn control break on\n"); </FONT></P>
  w  K7 z; h# \# ]/ Q: f- x<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>
& L  g, e6 v. q<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>  N) K" I5 V% _4 x
<P><FONT color=#0000ff>if (getcbrk()) , c4 l/ m3 b) D: s
printf("Cntrl-brk flag is on\n"); 4 G- y$ ]4 N! k" U2 n7 c0 H
else
& j5 a" K& M5 c4 _printf("Cntrl-brk flag is off\n");
0 g% b! Q. C8 @2 O% Vreturn 0; . T: Z$ P8 u) o5 G/ e7 t7 w
} 2 D; N2 ~/ s5 y) C6 H; G" X# L" v

$ e0 c' F2 q( T+ W</FONT>, t* M; w3 }' G. j0 J
</P>
& p: O" V. |/ |6 l% X+ W<P><FONT color=#ff0000>函数名: setcolor</FONT>
% N; o1 H8 e1 R' c& A7 A功 能: 设置当前画线颜色
0 p! [. A9 F- \: v' d+ I. L# P用 法: void far setcolor(int color);   |4 J) w+ c" b8 k
程序例: </P>
6 f2 [/ }( v  T6 a: c<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ x: j' x' i3 K#include <STDLIB.H>
8 H; S4 n$ q, k) {  Z+ P#include <STDIO.H>
9 q& A+ u9 E1 A6 O#include <CONIO.H></FONT></P>
; S2 H: n. j. Y7 e2 g% V# g) c<P><FONT color=#0000ff>int main(void) 8 K$ i; F( p5 F$ E7 A+ Q0 M7 @2 {
{
. S! s, W7 Z' O% g/* select a driver and mode that supports */ / |  ^1 `' r. h/ d/ A6 n8 f' _3 P7 Y
/* multiple drawing colors. */
- |1 O( N! O6 Y0 j8 F5 Cint gdriver = EGA, gmode = EGAHI, errorcode; . G" M1 x" D+ S8 Q
int color, maxcolor, x, y; 2 Y, r& b  z$ Z0 Q! \) }( G
char msg[80]; </FONT></P>! x4 g. n1 j. P. T5 Y2 C3 o: y) N
<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ A' u! T6 \; M1 B5 H" ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( S* W, i: @) ^' X$ Z2 P<P><FONT color=#0000ff>/* read result of initialization */
' [/ Z' O4 D5 lerrorcode = graphresult(); 5 R+ r' q- \, ^, v8 {' }* T( P) t
if (errorcode != grOk) /* an error occurred */ ) D3 P! r6 X) i/ D. O+ B1 r
{ % v8 M7 G8 |% F! V# S  O& [+ [
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 ~2 t* J* O5 q% K
printf("Press any key to halt:");
/ }  u( ?$ R) F& {; S2 Tgetch(); + q) R+ a$ N9 u, S; N# e# E$ J
exit(1); /* terminate with an error code */
2 Y3 O% t0 J: `+ \- [} </FONT></P>$ z6 R! ^: i! A9 {+ ~& k
<P><FONT color=#0000ff>/* maximum color index supported */
  O. \- V( F6 g$ Fmaxcolor = getmaxcolor(); </FONT></P>3 M* q, @( k% r: s6 H" x8 R
<P><FONT color=#0000ff>/* for centering text messages */
! Y" x6 _  W: b4 usettextjustify(CENTER_TEXT, CENTER_TEXT);
0 ]9 P% n) H7 V! E0 r* Px = getmaxx() / 2; 1 n# \- j" k$ n: z, [' ~
y = getmaxy() / 2; </FONT></P>( k& Z& Y! V3 K! B6 K! f
<P><FONT color=#0000ff>/* loop through the available colors */ & [3 o$ I$ o9 o
for (color=1; color&lt;=maxcolor; color++)
) N( Z- x  X) f' j: D6 ]{ 2 ?1 v5 T2 j# y
/* clear the screen */
4 I8 C$ ^+ Y5 b- a7 icleardevice(); </FONT></P>
* ^0 b; ]  D, X& Q) a8 J! H+ K- y<P><FONT color=#0000ff>/* select a new background color */
: _# J; t0 I. J; i- G; ~& Jsetcolor(color); </FONT></P>3 V6 G8 x4 p: y: J8 F$ R
<P><FONT color=#0000ff>/* output a messsage */
: U; d; G0 m7 Qsprintf(msg, "Color: %d", color); # J6 V0 |' M# C5 r" t0 b
outtextxy(x, y, msg);
* K. n% O3 B' a7 T3 o& zgetch();
+ M7 T+ V# e# x- @( W8 _6 Q# ^' R7 t} </FONT></P>+ w+ ?  J1 l( L1 [
<P><FONT color=#0000ff>/* clean up */
$ J4 M- s5 V7 m& mclosegraph();
. Y  s/ D. G7 c$ y6 vreturn 0;
, M) G; i  ~, w} 2 w: Q& C1 H( A
</FONT>
& x  E8 R+ v* _3 |</P>) i0 \& w, a0 n$ Q8 G: g% T
<P><FONT color=#ff0000>函数名: setdate </FONT>
/ a" C  U2 |8 ^- x# ^9 `8 w功 能: 设置DOS日期 ( l" r& g$ |" x+ N, [/ ]. M2 n. o
用 法: void setdate(struct date *dateblk);
0 v/ ?9 j& x' S7 G- U程序例: </P>
% p2 V+ R7 N4 V" p<P><FONT color=#0000ff>#include <STDIO.H>( W8 B" J7 a4 m4 V) S' c
#include <PROCESS.H>9 D; B$ z# C+ [' x3 v
#include <DOS.H></FONT></P>& \1 M" f1 x0 [  R! X- a$ u
<P><FONT color=#0000ff>int main(void)
8 \/ z! |' W% ^( h0 u{ : ]- Y0 ~, w+ q+ v& i
struct date reset; # ?# |3 m: R' a8 N5 J! m
struct date save_date; </FONT></P>/ l6 b9 N- W8 z0 X
<P><FONT color=#0000ff>getdate(&amp;save_date);
- K0 p5 I1 f; aprintf("Original date:\n");
8 i5 z" e" x+ Q5 F9 N6 usystem("date"); </FONT></P>
2 b1 u; P9 }  a<P><FONT color=#0000ff>reset.da_year = 2001;
1 V3 U) G9 e. f' m: Z( ^/ [% ?reset.da_day = 1;
9 T8 x- x; m* y) K- wreset.da_mon = 1;
. b: U  y0 x8 k" [$ Y( O8 p& [2 q/ Ssetdate(&amp;reset); </FONT></P>
' R/ t  I6 b' d' k* T; m<P><FONT color=#0000ff>printf("Date after setting:\n"); , I) Q5 |" z6 K% v3 f
system("date"); </FONT></P>5 G8 I" q/ t; m4 O( L$ [% c
<P><FONT color=#0000ff>setdate(&amp;save_date); * T( f& ]; }" V& r- j, S0 Z
printf("Back to original date:\n");
$ x' p" \) v) rsystem("date"); </FONT></P>1 u8 o0 ]9 [8 T5 d5 j: Z
<P><FONT color=#0000ff>return 0; / _* P" [5 t; X( c2 V5 g
}
8 }, J: r9 n! I</FONT>
" a6 a( R# h6 W$ k' d% s! l# s% F</P>  D+ l- A3 |# S; S$ D; T' i
<P><FONT color=#ff0000>函数名: setdisk </FONT>
' a: C1 \+ E2 o" c, |功 能: 设置当前磁盘驱动器
1 V; o8 a4 h2 h# G0 _6 d% A2 b( Y; w4 f用 法: int setdisk(int drive);
5 n) F: _( O( R4 O* `' m# e程序例: </P>
, N9 g- i8 U# F+ I, W<P><FONT color=#0000ff>#include <STDIO.H>$ m/ B. g9 n9 }2 X+ ?
#include <DIR.H></FONT></P>
, `' Z! S* u. e8 x& W' q& h& M<P><FONT color=#0000ff>int main(void) " K/ j0 V9 }' O0 i7 e
{
) |+ I( l$ z% r4 l7 pint save, disk, disks; </FONT></P>" e1 `3 m; t, h# X, z
<P><FONT color=#0000ff>/* save original drive */
9 Z! C' i$ L! E* x: qsave = getdisk(); </FONT></P>
% A! R2 U& Q; z<P><FONT color=#0000ff>/* print number of logic drives */
  R/ @$ [, ^0 Gdisks = setdisk(save); , {3 ]9 ^/ {& R- @# f) @
printf("%d logical drives on the system\n\n", disks); </FONT></P>
+ k# }. h9 p. r! T& l<P><FONT color=#0000ff>/* print the drive letters available */
+ C. ]& r' f+ G: C' U% C) V' Aprintf("Available drives:\n"); " }% h$ ~9 T# Y% i
for (disk = 0;disk &lt; 26;++disk)
9 I: W' U8 h8 s! v{ 4 U$ x. x; ~) {0 ~2 c( r
setdisk(disk);
5 c8 k1 \. J! Z' f0 `if (disk == getdisk()) ' t  X) ?/ ~- {
printf("%c: drive is available\n", disk + 'a');
' d! g8 l; {& S} 9 _+ U! g1 \* ^6 q1 E
setdisk(save); </FONT></P>
4 {2 j0 m( e; E1 z& f' l<P><FONT color=#0000ff>return 0; ' E- Q. R( G6 m% J7 |9 |
} </FONT>
8 P. l7 T+ h3 b1 N, o
. e. W' n3 n$ Q5 C</P>
0 ]; Q/ ?$ G" u+ T( T<P><FONT color=#ff0000>函数名: setdta </FONT>
3 X# P8 V  W- Z) ~5 p3 A功 能: 设置磁盘传输区地址
$ N4 l. w6 Q& a8 h用 法: void setdta(char far *dta); . W' m2 a2 t6 n' l0 a7 D$ }$ q
程序例: </P>
0 e# z3 v, V! J2 E* c<P><FONT color=#0000ff>#include <PROCESS.H>4 R+ F- ?% k" n& k/ v! @. ^- y
#include <STRING.H>7 `6 n& {% I! R( e, z0 J6 O
#include <STDIO.H>. ?# n: U# t: p5 t9 z% H: d
#include <DOS.H></FONT></P>
: w9 F9 l. `& J<P><FONT color=#0000ff>int main(void) : \- J: m- n% f" Y
{ ) h. m8 [& \* R4 F. g6 ]; q, \
char line[80], far *save_dta;
5 v, o% A, I: k; b, lchar buffer[256] = "SETDTA test!"; + I. A' s* ]( b* X* t  Y4 C5 G
struct fcb blk; + d- N1 E1 _# e( D1 u# v! S
int result; </FONT></P>% r4 s$ Y0 x  L( c6 X
<P><FONT color=#0000ff>/* get new file name from user */
+ G1 Y- {  K4 a9 J2 Kprintf("Enter a file name to create:"); 1 T) @; A: J2 K6 {0 }8 Q5 _( A
gets(line); </FONT></P>- b  \: d, R" u4 G0 ~4 |
<P><FONT color=#0000ff>/* parse the new file name to the dta */
& a1 R4 v( E+ t2 S- K. G6 y7 P2 ]parsfnm(line, &amp;blk, 1); ( H% `4 y. ]( f9 `, Y# t; M
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
' b& K( A+ p" y2 |: s<P><FONT color=#0000ff>/* request DOS services to create file */ 4 E9 r; l' w9 @& u4 A
if (bdosptr(0x16, &amp;blk, 0) == -1)
7 Z# [( [* S+ s4 A, x: m5 I{
8 V( D1 B- w9 b$ |- Eperror("Error creating file");
* p8 N+ R/ l, ]7 ?exit(1); 5 ^2 V0 R6 U" I/ m- s; R
} </FONT></P>- v" d0 ~$ i( |8 ?
<P><FONT color=#0000ff>/* save old dta and set new dta */
7 p1 z. }7 Q' q% v. D9 b! I+ _save_dta = getdta(); 7 K+ Y) S+ Q& x+ v! l- `
setdta(buffer); </FONT></P>
- ]9 ]; y0 e' B: P<P><FONT color=#0000ff>/* write new records */ 5 p+ X  w/ ?0 V( \  b1 A
blk.fcb_recsize = 256; . Q7 t; D6 k" b% A7 z4 s2 d6 o7 C
blk.fcb_random = 0L;
0 b- }9 U' H' Mresult = randbwr(&amp;blk, 1);
; J* j) Q; P7 K1 lprintf("result = %d\n", result); </FONT></P>
, g% S- \! \. c- S) r! p, [# j6 w- x<P><FONT color=#0000ff>if (!result) + ~' @4 H9 _$ ?$ b
printf("Write OK\n");
7 D+ X2 t' ?- R5 T3 I* u8 M9 v+ belse 6 _; b% H, u+ [! |4 e: z9 W0 Q
{ $ \, m$ d, D' z, h8 L
perror("Disk error"); 8 B# z. C! j1 w0 J
exit(1);
, f3 i3 f+ W( \! X} </FONT></P>4 p$ X9 Q9 T, y, d+ q
<P><FONT color=#0000ff>/* request DOS services to close the file */
0 Z2 a6 L& w0 u0 G+ Yif (bdosptr(0x10, &amp;blk, 0) == -1)
2 u" F; o; \* d+ @/ T{
0 a# @- n7 K5 y* r, Kperror("Error closing file"); 4 Y7 Q( ^# ]( H$ K" [0 \" |
exit(1); , t( e1 g& p3 v8 i4 ?
} </FONT></P>
% l1 Z- A# |; U# a+ F) a5 j* c<P><FONT color=#0000ff>/* reset the old dta */ % U% N( {2 \* U0 ~+ W. v1 B
setdta(save_dta);
! ~) q- I. R2 greturn 0;
* A2 ~8 G/ l( M; L/ ^7 L} * _4 n+ d3 e, B, J
</FONT>( C5 O- R5 K' l, ]3 Y1 I6 i
</P>
0 u/ _8 b, `1 H<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
8 O( J* I$ G- r& f3 k功 能: 选择用户定义的填充模式 8 g0 A( r" l* `8 a
用 法: void far setfillpattern(char far *upattern, int color); 8 Z% U; C. g, @. Z" V: u- X
程序例: </P>  Q" U  j  L4 ?# |
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( X9 u! [) a9 R7 ]#include <STDLIB.H>
5 S" e% a4 z: z" E#include <STDIO.H>  ^8 I# m1 Y3 p
#include <CONIO.H></FONT></P>
8 Q: f* c+ N' Z; T; f" c1 |<P><FONT color=#0000ff>int main(void)
( X4 g. A# p5 w/ O2 A* h1 [# u. u{ , p7 Q+ H- I6 N: G$ ~
/* request auto detection */
8 X3 Y2 }7 g5 N6 D' }" p' mint gdriver = DETECT, gmode, errorcode; ( Y$ s4 i  A7 p- r& g) w& _9 ^
int maxx, maxy; </FONT></P>
: G) Y) W* g# n0 F<P><FONT color=#0000ff>/* a user defined fill pattern */
6 l" a+ d* u# z1 M2 S- Jchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>
2 U) O. w( U" ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
  h* z9 C& @8 R: Z+ Binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ y, f# L2 w3 t: T( o<P><FONT color=#0000ff>/* read result of initialization */
& ^4 }1 G0 E: v2 oerrorcode = graphresult(); & `8 u. d8 S$ ?3 f
if (errorcode != grOk) /* an error occurred */
9 q; J$ [; X8 x* p{ 7 k; D1 m# p4 S
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 U, Z- m' d. F1 y% x; Z- j  gprintf("Press any key to halt:");
( ?$ ^! F4 K5 q2 i" Xgetch();
6 c+ y$ T4 n7 A" w; Texit(1); /* terminate with an error code */
) C9 Q1 R( h* {" n6 R} </FONT></P>& N7 D& g$ J1 {
<P><FONT color=#0000ff>maxx = getmaxx(); 5 B3 s. x' t* L) z' c) a
maxy = getmaxy(); ' h, M( x5 |, Y- R: r- o/ G
setcolor(getmaxcolor()); </FONT></P>8 _3 \/ f1 o% [* Q/ _  m
<P><FONT color=#0000ff>/* select a user defined fill pattern */ ( c/ @, U6 O3 o0 Z7 ^
setfillpattern(pattern, getmaxcolor()); </FONT></P>' I. d/ ^4 W' J1 A; V/ t" x  s
<P><FONT color=#0000ff>/* fill the screen with the pattern */ * u9 B2 J6 `1 l' \7 R, b
bar(0, 0, maxx, maxy); </FONT></P>
, R1 W) {/ L. w( p, S% O<P><FONT color=#0000ff>/* clean up */
! O1 X( S5 y; K" T0 Cgetch(); 8 ~$ L( U# `8 K( x8 E* t6 y
closegraph();
' L3 }7 c9 B6 Preturn 0;
! v$ Z! ]9 d9 R' @" V' _} 0 s) v6 ?! |; h
</FONT>
: W8 f, O$ j4 J. `& n  m</P>
' k9 M! t4 z+ t" y<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
9 j' w( _) L+ d1 X8 f功 能: 设置填充模式和颜色
* k2 y$ y6 h7 Z9 i用 法: void far setfillstyle(int pattern, int color); 9 V  S4 H0 g( `$ C4 C4 ~& g
程序例: </P>1 `6 B8 ~) x  h7 [1 C
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* {: D2 _2 `) N" [( m0 x#include <STDLIB.H>/ B/ w3 Y& L6 r4 ^
#include <STRING.H>- c$ |! U  M6 T; {8 P) j+ J! E0 C
#include <STDIO.H>- Y$ l: _5 B8 b
#include <CONIO.H></FONT></P>" L4 Q" k& \; q* ?3 M
<P><FONT color=#0000ff>/* the names of the fill styles supported */ ; H9 p! Y; ^) ~2 a
char *fname[] = { "EMPTY_FILL",
7 o' {) K# C% \8 o1 F"SOLID_FILL", ! [6 |. L( K+ r) E! r" W
"LINE_FILL", # ]& u0 ?, s$ B: H0 j0 I
"LTSLASH_FILL",
8 e; k% U1 N& p. x' M( A9 I" R"SLASH_FILL", # h1 i1 ~/ [( Q: b  `; }
"BKSLASH_FILL",
! W* ~8 F* Q- K' Y0 F& k' F"LTBKSLASH_FILL",
2 H* ^7 r; W! {"HATCH_FILL", . y- e8 P: H$ `. r5 C( f
"XHATCH_FILL", / v# t5 J. x( t  ^' j+ w) R
"INTERLEAVE_FILL", : c9 S, N8 G8 C( |  D# }
"WIDE_DOT_FILL",
' z6 {6 G) ]+ p( T/ V"CLOSE_DOT_FILL", ' B0 ?( g# K; ]/ Y
"USER_FILL" 0 G% }* [( o0 o$ h2 _* `( H
}; </FONT></P>
, d' y  s9 y# i5 }) X<P><FONT color=#0000ff>int main(void)
. y' @- B5 @2 U1 G{
8 U2 i2 ^* B7 m; `/* request auto detection */ % m0 }8 x" {1 `; S" Q* _/ A
int gdriver = DETECT, gmode, errorcode;
: x$ x% j, H( ?8 x0 Fint style, midx, midy; ( S  [+ \7 U- U. u% d6 E# g
char stylestr[40]; </FONT></P>
4 C& ]9 j9 m9 f7 N  |- p, h<P><FONT color=#0000ff>/* initialize graphics and local variables */ # i6 L/ A: c9 c) h7 A6 J
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># r$ k9 K4 x* j0 {$ O1 L
<P><FONT color=#0000ff>/* read result of initialization */
! x9 c; t! ?( L# p8 U6 merrorcode = graphresult();
' o0 _8 b+ `6 [9 Vif (errorcode != grOk) /* an error occurred */
. o, j- U3 ?3 S' a7 i9 y+ R% ~{ 3 Z1 p6 S" O7 D# b/ q% M2 r/ N
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 F% p# q' L, W5 `1 f8 \2 Q
printf("Press any key to halt:");
- T( h! |( s% a  Sgetch();
; p/ m3 ?8 s6 B6 u) F8 Pexit(1); /* terminate with an error code */ % P( l3 f4 W9 \1 J+ b: r7 ?% _
} </FONT></P>5 Q  [3 R4 D+ n6 P) N: c0 P% B
<P><FONT color=#0000ff>midx = getmaxx() / 2;
( t9 Y6 Y1 D  c  }3 e; Pmidy = getmaxy() / 2; </FONT></P>4 b/ H9 U7 x' A; R3 U  `2 I8 R
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) * N+ q" e# u9 O2 V- C, m
{ $ s" C8 W( X. C  @, h  U
/* select the fill style */
3 r$ \. V) \  R  r, \' ~setfillstyle(style, getmaxcolor()); </FONT></P>  \+ S: w# @* r# }& w
<P><FONT color=#0000ff>/* convert style into a string */ 6 q1 o7 Z- Y" q" u: L+ T
strcpy(stylestr, fname[style]); </FONT></P>
+ l$ U4 v; T1 D) O# S( _& e/ M<P><FONT color=#0000ff>/* fill a bar */
: I$ l2 ^! ]+ ]0 d+ C) |* ubar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>- A; q9 }3 D. x! N3 x8 f
<P><FONT color=#0000ff>/* output a message */
) Y# F: v" z( T6 L* _9 n5 [: {outtextxy(midx, midy, stylestr); </FONT></P>
  K8 T2 y4 v3 u) }) k5 g<P><FONT color=#0000ff>/* wait for a key */ 8 R3 D3 T4 q% s* R7 z8 ~
getch(); # q2 d- h, l8 F8 @# C- Y
cleardevice();
( t  ^% Z4 d* G} </FONT></P>! X/ j. t  h/ `/ a5 B3 L( T: s
<P><FONT color=#0000ff>/* clean up */
" h! p# m: r0 z/ u  n) Igetch(); ( L% X- j1 g- \2 D; r1 \" v
closegraph(); : l+ v1 O/ ^! Y& Z. v0 l, B9 v
return 0;
, M8 T" ]0 I8 y# J6 q5 f} </FONT>
0 L( }. h" h- J) g
5 s6 c' e; r+ _</P>
/ h9 o) ]% J- R" x6 e1 Q( h, a* \: m<P><FONT color=#ff0000>函数名: setftime </FONT>! h! ^& i: K$ ~; |/ \* D* r7 U* I
功 能: 设置文件日期和时间 $ s+ u7 a9 E8 G8 W
用 法: int setftime(int handle, struct ftime *ftimep); ; o4 R, w* D6 A  X7 V$ T0 g9 Y2 H
程序例: </P>
; A0 I1 b6 u- z! [0 ]<P><FONT color=#0000ff>#include <STDIO.H>
( b* v  Z' o% ]( C# R' G! {7 \#include <PROCESS.H>1 Z9 j5 d  Q( @# @3 r' ~
#include <FCNTL.H>0 m" m, }" Y: Q, C6 F
#include <IO.H></FONT></P>6 w9 L9 d# F5 i2 f. V# C! P
<P><FONT color=#0000ff>int main(void) 8 t; E# i: O5 y) x. z3 m
{ # }2 @! s) J3 G
struct ftime filet; 4 j1 `0 ~4 ?# `* q" [4 v# Y
FILE *fp; </FONT></P>0 r  s6 `7 [5 D3 o/ p1 v* V- U
<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) - v3 k4 r6 R% l+ D, m% Q
{ ; A$ p, ^8 E( g" y
perror("Error:");
2 b- K. f* i2 v3 Z6 P/ L: C9 fexit(1); 7 M2 C* o, ?; [2 N. U) I
} </FONT></P>
; F( \; `0 s* v& h9 v# c1 }* i8 M<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>
9 c9 j- `4 ]8 e! g8 R, @* H; |<P><FONT color=#0000ff>/* load ftime structure with new time and date */ $ B1 f# D. B$ I" T9 t" l5 s( {
filet.ft_tsec = 1; . j' u! I4 x- h
filet.ft_min = 1; ) {3 \  _: b' O7 E# ?
filet.ft_hour = 1; ) s9 |8 J# z6 |9 u( U. Q" s
filet.ft_day = 1;
& X3 e0 w. s8 G7 w( ~; B2 Y' qfilet.ft_month = 1;
/ o& m/ `0 G2 W6 F1 mfilet.ft_year = 21; </FONT></P>% m' A* D% h6 ^& Y) B% u% ]" V; W
<P><FONT color=#0000ff>/* show current directory for time and date */ ' H' ^- M/ l+ L
system("dir TEST.$$$"); </FONT></P>* R, l/ s$ @6 C' i7 F$ h3 w) R* j
<P><FONT color=#0000ff>/* change the time and date stamp*/ # K! f( F' X* \
setftime(fileno(fp), &amp;filet); </FONT></P>
7 l3 G; K/ U) i& r; R<P><FONT color=#0000ff>/* close and remove the temporary file */
* D. c3 I" S, E4 l$ e% L$ efclose(fp); </FONT></P>' G: e; S) C% |4 u
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>) ]- g) v( x( L! U
<P><FONT color=#0000ff>unlink("TEST.$$$");
5 m$ z- C* P3 R2 z* h3 z9 R6 `return 0; - Y9 S% R# k% J+ w, G
} ' f$ \1 Z. U% N6 X5 _. R
</FONT>) m& H6 {7 i, z% X  d8 Y) t
</P>% \9 B- E+ R/ R- |  T
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
, U. g. u1 r. G% g6 w3 T功 能: 改变内部图形缓冲区的大小 9 J: r7 c3 T" U/ P6 }
用 法: unsigned far setgraphbufsize(unsigned bufsize); 6 {9 H) ]1 K( F
程序例: </P>6 u* z" B0 l$ N
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 A% B/ h7 }5 ?* R* R! V$ n5 H
#include <STDLIB.H>
% P! G' U8 R: P  ^8 j1 ]$ [" z#include <STDIO.H>6 k8 K2 K2 W# s, i
#include <CONIO.H></FONT></P>+ T. X5 g0 K5 W
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>
9 s; N5 Z6 J+ |9 H<P><FONT color=#0000ff>int main(void) 3 t+ l& q  k2 p* ~" W! h; n
{
' Q; t# D) ?* T" F9 {* B, R( o  z/* request auto detection */ ( x; I% X8 j: X2 L) r- r
int gdriver = DETECT, gmode, errorcode; 2 Z* J' B0 `2 v& N% _& \8 q
int x, y, oldsize; $ z6 i) T$ T2 H3 Y: ^
char msg[80]; </FONT></P>
4 W* q: K1 u# W/ E2 A<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
# Z- f& o7 y8 }+ n/* before making a call to initgraph. */
0 H/ K$ c$ O7 U3 Coldsize = setgraphbufsize(BUFSIZE); </FONT></P>
2 x% z4 {  W$ v% \9 q. P<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 o: J1 p* v4 ~! K; D6 A% h9 @2 {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* }# {5 [( b; l; r
<P><FONT color=#0000ff>/* read result of initialization */   e" ?6 @+ [  d  G( s- u
errorcode = graphresult(); # @. N' @( o" m# L0 u# D- }9 x
if (errorcode != grOk) /* an error occurred */
( p# u+ [" d9 H4 N% t{
$ E5 h) f. e! O9 T5 m" n" M6 yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / L6 W: H2 E( U4 e$ g, a% X! J, t
printf("Press any key to halt:");
. v( Q( g! @6 ]9 Zgetch();
/ |& P* `9 r+ r" S( O/ q$ yexit(1); /* terminate with an error code */
  |* W8 z1 |" [& U, i! c- q} </FONT></P>
* d6 x5 @& x; s$ e5 _3 N% M6 F<P><FONT color=#0000ff>x = getmaxx() / 2;
# s) y6 h& U. \7 m/ z; W( jy = getmaxy() / 2; </FONT></P>
! e, ]* V- p, x! f- e7 Y<P><FONT color=#0000ff>/* output some messages */ 6 M3 [$ U2 d( e! @- p8 p/ N! T
sprintf(msg, "Graphics buffer size: %d", BUFSIZE); * N+ f! x( b/ F! Z( ~6 T
settextjustify(CENTER_TEXT, CENTER_TEXT); ) [. l5 \' }! P+ k! {8 b( e
outtextxy(x, y, msg);
) e5 Y$ [/ E7 H* N- A' Isprintf(msg, "Old graphics buffer size: %d", oldsize);
' W3 z) Q; L4 Mouttextxy(x, y+textheight("W"), msg); </FONT></P>. `% n: w# |/ B8 P# g; T
<P><FONT color=#0000ff>/* clean up */
5 T8 F# B8 M: E: Vgetch(); * Q$ e8 N4 c2 c
closegraph();
. e0 w9 R0 @( p0 v2 m) @, {1 p- greturn 0;
& R, \# r6 p0 o& U/ k; F, D} 8 V# i+ J' X( h! K4 X- }3 z4 w4 c

6 A/ J- x7 u$ X- O( w; P
! U' ]+ Z/ w( ?& ~</FONT></P>
" @& a$ G+ m: q( L. U<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
4 Y0 q+ ^4 }+ N+ j功 能: 将系统设置成图形模式且清屏
& T! w1 d/ s8 V3 T( |用 法: void far setgraphmode(int mode);
& H" j. M" t7 m: P, m, s程序例: 3 `  z# [5 Y( Q% M3 O/ N- K( {2 Q

$ ]% L$ o2 l8 E8 J* @<FONT color=#0000ff>#include <STDLIB.H>
4 B9 n! v% Z" m. [! U$ {#include <STDIO.H>
# b8 r6 N$ y; b* r4 G* D6 P#include <GRAPHICS.H>#include <CONIO.H></FONT></P>( P7 V. s* \4 o  I
<P><FONT color=#0000ff>int main(void) , ^5 x: F  I/ B) Z9 v) Z  ]  D" J9 j
{ 9 Y/ f+ j4 y; b1 p" o! j  J# ~
/* request auto detection */
' e+ t2 K+ ~* q1 s0 c5 M/ Xint gdriver = DETECT, gmode, errorcode;
0 `$ ^9 n" h3 \9 p" Cint x, y; </FONT></P>
+ e$ T! \7 K1 Z<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( V+ P- W& B4 G/ x6 x* }4 X
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; u) @5 ~# N( u' U1 L<P><FONT color=#0000ff>/* read result of initialization */ ( c* A( d  t; s- z0 n
errorcode = graphresult(); ( }' E  T  N/ t* i" ^, ^
if (errorcode != grOk) /* an error occurred */ 5 x) T, O% b8 {! S
{
9 l( ~4 R! T3 q9 l" Kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
- ]( ^( W6 V# ?; |( i' uprintf("Press any key to halt:");
  Z1 @- v) @. ugetch(); ( \9 j! G- v6 j, L7 Q
exit(1); /* terminate with an error code */ 9 Z& Q% i& G# w" f
} </FONT></P>
+ ^1 \' W/ T' H' a6 r& y* m7 }' D<P><FONT color=#0000ff>x = getmaxx() / 2; " u. B7 O# K. ?- X. d
y = getmaxy() / 2; </FONT></P>
8 u1 \0 h. W$ F' ~6 l<P><FONT color=#0000ff>/* output a message */ 5 C* C2 k& p! Z: }8 ~; h
settextjustify(CENTER_TEXT, CENTER_TEXT);
- G5 V: a% d$ q0 l0 ~- p! @  O% souttextxy(x, y, "Press any key to exit graphics:"); 6 q/ u% P/ h# m3 }3 s
getch(); </FONT></P>, Q2 {2 H+ Q$ D6 \
<P><FONT color=#0000ff>/* restore system to text mode */ ; J% ]. @  }( y7 e" l
restorecrtmode(); / X7 y. d, n3 U4 o. g# H! S
printf("We're now in text mode.\n"); 3 ~# L- Q8 s* [; b  ~* y
printf("Press any key to return to graphics mode:");
7 j' d$ I) ^  {' d" x# Egetch(); </FONT></P>
6 E" q! _* L! R+ B; e/ I<P><FONT color=#0000ff>/* return to graphics mode */
0 }, w2 K$ \+ r* x3 b' P. esetgraphmode(getgraphmode()); </FONT></P>
5 S, x- j5 P+ G<P><FONT color=#0000ff>/* output a message */   l1 }) X. c& @! d6 g5 J) u
settextjustify(CENTER_TEXT, CENTER_TEXT); # O1 y1 p. \. y: M4 V
outtextxy(x, y, "We're back in graphics mode.");
8 g$ ~. B) M( D8 D/ louttextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>" {5 X5 m" j; }( M0 d: A0 T
<P><FONT color=#0000ff>/* clean up */ 3 ?$ K1 i4 M. ^0 V* m
getch(); + I  E8 I. c1 p
closegraph(); , v8 l" j+ O5 F6 }0 @8 j
return 0;
- v: w8 ?4 X2 v4 }6 A! @}
6 z" Q; E& O6 O; \/ y7 y8 b. ^7 @/ j  x
7 [2 }5 E0 T. q5 w. ~* X. X9 O. O4 W
</FONT><FONT color=#ff0000></FONT></P>
, y0 b+ D# _) i# d" c<P><FONT color=#ff0000>函数名: setjmp </FONT>
$ G# w+ A4 ?( w功 能: 非局部转移
& n; X5 B% h$ a- H. J2 N" h* [- G用 法: int setjmp(jmp_buf env);
: q9 ~8 v7 s' Q2 H$ v- U" _程序例: </P>% `& w/ ^3 H! B, Q, q1 ^1 y/ B( P8 U
<P><FONT color=#0000ff>#include <STDIO.H>  n6 n( v* C- R* w
#include <PROCESS.H>5 T; [9 J! Z  d& _) @) |
#include <SETJMP.H></FONT></P>5 l) g' E, g/ }; p* E( c! Z
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
' {9 u" A, E# |7 J/ |6 y<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>" Q/ x0 ]/ {* D5 |, T* s/ }
<P><FONT color=#0000ff>int main(void) ( m3 y/ O4 v! G7 q
{
5 Q. a) a' h3 b/ j. P# C, K* \int value; </FONT></P>4 Y9 A6 F3 y/ A' X0 [
<P><FONT color=#0000ff>value = setjmp(jumper); & \" `( |$ Q6 \/ b7 Y5 b
if (value != 0) + ^% f1 t& d9 u, y! F0 D
{
! ]# v4 x- i9 j* }3 _2 M. ]- ]printf("Longjmp with value %d\n", value);
! L6 [1 |- j4 L8 Aexit(value);
; \2 Q1 D+ }) ~  E8 G+ j} 7 J/ b' l5 o. V6 r& X2 Q
printf("About to call subroutine ... \n");
7 ]( V' T  E4 D" o6 Msubroutine();
2 u) x3 H; C# d3 m% D$ M3 t* l' lreturn 0; 1 P2 E; |7 z4 n, v  a: _( W" [* v
} </FONT></P>' v; @5 Y8 f8 `; ^
<P><FONT color=#0000ff>void subroutine(void)
& b& C: N6 z+ T$ H* h9 t{
, H* P" k  Z) q& e1 k. Z! [" F' plongjmp(jumper,1); + N7 t( q4 a9 O. ?) {
}
4 |0 o: d$ Z9 a7 e</FONT>
$ A, h: Y3 }+ E; {8 z</P>
6 `5 z+ j0 g7 R% a<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
( f: Z8 y( d/ \功 能: 设置当前画线宽度和类型
! J6 g) n# K1 ^: B- W用 法: void far setlinestyle(int linestype, unsigned upattern); 4 j) \  c' m+ P# Y; v3 W7 H% Y
程序例: </P>3 D! Y0 r6 a" h* a6 |
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: l$ d- a( [. x& a) j; y#include <STDLIB.H># Z2 l( F2 P) m/ |
#include <STRING.H>3 h/ p- G! r% c$ {4 Z- z1 b
#include <STDIO.H>' n, i9 L: U8 ~$ g) Y
#include <CONIO.H></FONT></P>
+ T- F1 n" c4 k. h) k& V& e<P><FONT color=#0000ff>/* the names of the line styles supported */ # C( ^' k2 w& n! g" t
char *lname[] = {
1 ?" u# L3 v7 m# Z+ p"SOLID_LINE",
, U" [& A# v0 V$ {' i"DOTTED_LINE", $ A8 H! o; ?: n; K2 K5 f
"CENTER_LINE",
+ N8 B: W% P* x/ N( `"DASHED_LINE",
! b( S$ {/ Y( u) \"USERBIT_LINE"
# ?6 e( `" f2 d  U2 S}; </FONT></P>, }) V7 P0 e, ?2 G
<P><FONT color=#0000ff>int main(void) / n5 I" ~0 I0 W1 t, r7 ?$ @
{ ( X# w- ?  g& L4 V7 Y
/* request auto detection */
8 m. @$ ^* U1 Iint gdriver = DETECT, gmode, errorcode; </FONT></P>
/ F, I4 Z0 Y# j" E8 X<P><FONT color=#0000ff>int style, midx, midy, userpat; 3 h3 L) @- y0 ^; N# X" y7 S' I
char stylestr[40]; </FONT></P>, n6 w0 r; A' ]2 E
<P><FONT color=#0000ff>/* initialize graphics and local variables */
  q& j$ o' x4 e. hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 ~! V- p; w) U% v& d
<P><FONT color=#0000ff>/* read result of initialization */ $ U+ b5 c- c6 e7 l
errorcode = graphresult();   ]. \  o8 H% P4 C! f) ^* y
if (errorcode != grOk) /* an error occurred */
; C) I, d3 S% n4 x4 L{
3 {! K2 V& d; h" ^, vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
7 @+ c, b* d7 _% t' `+ H2 Aprintf("Press any key to halt:");
6 y0 h9 a7 m7 Sgetch();
) o$ O4 R6 ~: L' D7 _" o* T4 ~3 l7 Bexit(1); /* terminate with an error code */   ^# V  F% G. g* c+ C3 s
} </FONT></P>$ l, z) l, J. o
<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ Q# M3 q2 Y) b1 O6 y2 kmidy = getmaxy() / 2; </FONT></P>5 S+ t. z- f; e6 h! ^+ {8 B- }
<P><FONT color=#0000ff>/* a user defined line pattern */ ( [& I) e# ~; I* ?3 m7 b0 k+ g* Q
/* binary: "0000000000000001" */
2 a; D/ L) k3 x$ i  Tuserpat = 1; </FONT></P>
" Q8 o# z# h4 T" B" D; n<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++) 9 G' t0 Y/ ~% P; p: i. {
{ ( B. ]6 |& Z3 E, F# g$ r
/* select the line style */
+ O$ `) F) }* F3 _' Qsetlinestyle(style, userpat, 1); </FONT></P>! v8 I. F1 e' }  T$ a* l$ Q$ U% U! [$ H
<P><FONT color=#0000ff>/* convert style into a string */ . H4 Y6 g# G! R% R
strcpy(stylestr, lname[style]); </FONT></P>
! G, l* r' [2 a" B# @( J& a2 {<P><FONT color=#0000ff>/* draw a line */
6 w/ m/ A6 E! q  D" t( c) Rline(0, 0, midx-10, midy); </FONT></P>: E  ^  P/ u5 S  l9 m3 O# ?9 P! @. k1 v
<P><FONT color=#0000ff>/* draw a rectangle */
! C: P/ J! q8 U: {+ Vrectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>' n( {3 z1 N' f( Q, ^* ~
<P><FONT color=#0000ff>/* output a message */ ! Y: F: B9 [- q
outtextxy(midx, midy, stylestr); </FONT></P>. @, G: c  P. n5 r0 x% Q% P6 _
<P><FONT color=#0000ff>/* wait for a key */
6 j  r9 L7 q% Z9 Q3 sgetch(); 6 r& H: |: n; F& j5 {
cleardevice(); ! f2 Q2 s4 h2 ]3 l6 Y# s
} </FONT></P>$ d0 A8 `, U, O* J& @/ o/ ?
<P><FONT color=#0000ff>/* clean up */
5 ?0 Y9 K7 [+ j; O9 ?% W5 Fclosegraph(); 2 g) V  Y! }/ ~3 R9 E
return 0; + F$ r, [* D$ e5 Q- M' _0 i
} </FONT>
) b* p3 A) ]4 m; O9 b  h! u2 l% V# U. w9 u6 K* o

1 Y# _1 n0 Q" i; h</P>1 h& K5 P# a3 ]' e6 p1 h3 v' q3 z
<P><FONT color=#ff0000>函数名: setmem </FONT>7 @/ _, f) b% [# b; ~# J) [( v
功 能: 存值到存储区
, I4 z7 {; j' E, k! Z0 I用 法: void setmem(void *addr, int len, char value); ; z! x8 X$ a" v" D# j7 A2 p
程序例: </P>" \9 o/ G+ g  r# p% t0 I% r
<P><FONT color=#0000ff>#include <STDIO.H>
8 U  h* Z& L/ c" o  J#include <ALLOC.H>
% w, N7 _; u' F  f) O/ O#include <MEM.H></FONT></P>
! }7 _4 J0 k) D4 M/ {<P><FONT color=#0000ff>int main(void) , @$ h; E# \# O7 k8 b) K. r
{
1 k8 C+ w6 w3 I2 V4 w  {7 p* x# Hchar *dest; </FONT></P>
# y& }4 [* S1 F<P><FONT color=#0000ff>dest = calloc(21, sizeof(char)); , m8 Y+ k2 j+ B: @3 N5 e; d
setmem(dest, 20, 'c');
; a0 D( w& w. G% nprintf("%s\n", dest); </FONT></P>" N' W7 Q9 z% t! w
<P><FONT color=#0000ff>return 0;
" ?- U, [1 M# ], r4 C( }} </FONT>
+ H! t" C/ T* w& ]5 o* J: d, S7 c* j$ c- I- f
. [( s) j# C1 z! g' Z( r
</P>+ Y# }6 O% ^+ x& j6 B
<P><FONT color=#ff0000>函数名: setmode </FONT>, i1 L4 V: |$ W8 ~- @3 p
功 能: 设置打开文件方式 9 ]* o* C% d7 l
用 法: int setmode(int handle, unsigned mode); 0 B0 B& w# K4 Q! q
程序例: </P>" E1 b# P4 h& i: M- I9 B
<P><FONT color=#0000ff>#include <STDIO.H>
, ?+ I( y3 ]' W. c( H#include <FCNTL.H>
; ]* c5 E6 |- t; `' T#include <IO.H></FONT></P>  M& n( [+ ~9 ^: o1 h, I
<P><FONT color=#0000ff>int main(void) , h& ]9 @! N4 ?: s
{ " R& k: x7 ]) R0 u
int result; </FONT></P>, i6 ^% X) z( j& u* t+ I6 o
<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); , v* b: P; `/ T9 P" F+ x
if (result == -1)
  W3 j1 p/ D* K7 w& z# Iperror("Mode not available\n"); + o- M, V8 _! q7 Z2 Y7 y
else
* ]& H5 A* \4 v, Z' `8 v" y, {printf("Mode successfully switched\n"); - E! @4 B3 l1 E! n) q7 K5 X( s
return 0; % c  q% k6 Z8 G+ e
} ' c5 `/ r: C0 ?3 Y, v7 c3 K

7 |( m2 Q6 }% w3 e" d+ G, t. x</FONT>
; ?2 q2 H+ t4 _/ Z( c# Q/ D7 V</P>) p, ~: J, C2 |
<P><FONT color=#ff0000>函数名: setpalette </FONT>5 X9 N  c3 r  R9 O7 X
功 能: 改变调色板的颜色   A4 u* o7 o# `9 A6 N+ b7 n& V
用 法: void far setpalette(int index, int actural_color);
" z/ I- d6 S' s9 F: m9 e4 S程序例: </P>
% H( N: E: v+ ]( ]/ s$ d( h/ ~<P><FONT color=#0000ff>#include <GRAPHICS.H>
9 \8 }+ p( T# b4 i#include <STDLIB.H>
& W; P" S$ y: R, {#include <STDIO.H>( ]  w! I, _; I$ V
#include <CONIO.H></FONT></P>
6 Q' n# ]7 b' u<P><FONT color=#0000ff>int main(void) + h7 p. z$ c" H- r
{ ( o& t+ V) Y$ L" [7 N
/* request auto detection */ 3 N2 u. Z( X, |2 O
int gdriver = DETECT, gmode, errorcode;
) c( K  `3 _' k, Y6 Y$ z$ w9 i. xint color, maxcolor, ht; , t3 A/ A" F' }
int y = 10; . E. h7 X/ \, F
char msg[80]; </FONT></P>
3 L6 p, `& Z; C<P><FONT color=#0000ff>/* initialize graphics and local variables */
( h  C& Q, v) T' Z' }) L+ @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>* h4 T6 C7 m- _
<P><FONT color=#0000ff>/* read result of initialization */ , s% J1 ^# N& h; W3 u7 r5 o
errorcode = graphresult();
: N1 ~4 q" @3 E1 B7 K; B  eif (errorcode != grOk) /* an error occurred */
+ y% |' }* z& y. J# i{ ' A$ P$ `# m3 _7 \+ P# z) K* _7 H
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 [. y: Y+ \! B) P% \# fprintf("Press any key to halt:");
' v# q  M3 m) P) q  }( ^getch();
1 Z7 E% q: H3 O/ ?exit(1); /* terminate with an error code */ ! X9 J/ o# X( J7 h
} </FONT></P>- u' Y% j( E. W0 r8 a1 F
<P><FONT color=#0000ff>maxcolor = getmaxcolor(); $ ?5 \; W% R' T' G" Y( l8 l
ht = 2 * textheight("W"); </FONT></P>  ?3 |2 E9 Y5 a
<P><FONT color=#0000ff>/* display the default colors */ 4 B  F" B0 A. w5 G; \* t8 b
for (color=1; color&lt;=maxcolor; color++) , ?7 W+ k3 u  m* g
{
5 ?+ ~! i; q/ U. ^% o6 dsetcolor(color);
0 K) x  L" C7 ssprintf(msg, "Color: %d", color);
$ M) w! I5 ]8 j" e, C. I0 Q# _& routtextxy(1, y, msg);
, `8 V0 m1 S; hy += ht;
( e& l$ i7 h; @( S! `} </FONT></P>) c/ [7 F! K' n
<P><FONT color=#0000ff>/* wait for a key */   |6 V( O0 r3 ?, V
getch(); </FONT></P>* f2 z9 f/ e) S8 Q9 [5 p8 ^
<P><FONT color=#0000ff>/* black out the colors one by one */
* F& [. H' s0 v1 L# q" Zfor (color=1; color&lt;=maxcolor; color++) * F; ^0 s' d$ @. a8 ^
{ : F  v1 I' I: T7 m+ y
setpalette(color, BLACK);   _( B; D  M7 _
getch(); ( ~8 z3 w! F: n- c0 g: n# {! U
} </FONT></P>+ [/ h" k( [) e
<P><FONT color=#0000ff>/* clean up */ 8 Z0 i$ R. \, r6 Z4 P
closegraph(); + J2 [4 i! |; U) Y
return 0; - R+ @# o5 d0 ]' _% C6 k
}
$ @( N( {- a) N0 a" p6 q/ x</FONT>
1 o5 d  M0 k6 H( I</P>: q8 o2 W; {! V# W
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
8 |8 a' S1 d* A1 E. @( b功 能: 定义IBM8514图形卡的颜色 * z* @5 u! `1 j; O) w* n$ D' ~6 b% W
用 法: void far setrgbpalette(int colornum, int red, int green, int blue);
) T) n, w$ {) O8 Q程序例: </P>
. B/ i* D6 V. p1 _/ v( W<P><FONT color=#0000ff>#include <GRAPHICS.H>
. [- n! u& L/ ?* Q8 V6 w$ x#include <STDLIB.H>/ _: l% M8 w# _* f) J6 m: M
#include <STDIO.H>
) T! ], \# z7 J* l  Q: F$ t#include <CONIO.H></FONT></P>
, H5 r: j- _8 O# d  d( e8 x<P><FONT color=#0000ff>int main(void)
, o  Q" H/ T& q1 P7 J0 I/ p{
  [3 L) X" @6 p% e/* select a driver and mode that supports the use */
3 l2 [  W- D# @" u9 ?/* of the setrgbpalette function. */
9 X  y1 [" d, m6 W, N( bint gdriver = VGA, gmode = VGAHI, errorcode; * O, V3 H7 d1 ?& G  O
struct palettetype pal;
. o- T$ d* u2 x! p2 G* T5 g0 o' M* ]* l+ p- hint i, ht, y, xmax; </FONT></P>& z: i& J0 ~  ]0 x  v- e6 M
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& W. k- Z- T, M5 ~2 a  H- f2 g0 linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 `1 _: ^# S; k- y* ~9 K
<P><FONT color=#0000ff>/* read result of initialization */ + A4 {0 m/ C0 |( A9 ^9 B
errorcode = graphresult();
: s! E& E5 r1 c& h0 ~5 kif (errorcode != grOk) /* an error occurred */
4 P/ C3 z( h0 Y. W0 n{ ( }/ @: z4 @7 Z- D; D: A
printf("Graphics error: %s\n", grapherrormsg(errorcode)); " C  @. T7 D& \$ l* X2 S
printf("Press any key to halt:"); : s  G6 |9 U; D
getch();
& w' P  v7 k2 ~exit(1); /* terminate with an error code */
4 `9 E! p; c) L/ T/ t; G9 @' Z} </FONT></P>
% Z; ^8 \! d+ U- @7 A( |% o<P><FONT color=#0000ff>/* grab a copy of the palette */
$ G$ ^' o* F: agetpalette(&amp;pal); </FONT></P>  e- G" p- e3 P
<P><FONT color=#0000ff>/* create gray scale */ , P( A9 T" s4 L1 V
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>+ Z$ S% j8 k4 e# X2 _' F, ?; j. E
<P><FONT color=#0000ff>/* display the gray scale */
' s9 Y' ^" h# i9 ~: p7 ^! ^0 {ht = getmaxy() / 16;
9 D" J$ {! S$ e- U: z& P3 D2 txmax = getmaxx();
( K8 y; f2 g% ]0 E" ty = 0;
$ I: ^8 X& ?' z& }( f2 ofor (i=0; i<PAL.SIZE; <br i++)> { & }7 F4 {2 x" |# `
setfillstyle(SOLID_FILL, i); 3 z4 L2 E1 h' y
bar(0, y, xmax, y+ht); 6 }$ O) c7 x& _, i
y += ht; ) ?1 a, `: ^  @, c! p( V; D
} </FONT></P>
$ U8 O+ c4 X$ ^. k: X* P1 z<P><FONT color=#0000ff>/* clean up */ # f0 E% P" x! d* ~
getch(); ) {- g6 ]1 i% W+ a) T/ [/ N7 _
closegraph();
. H- B: T8 p5 R) @- y& wreturn 0;
* E3 s1 F/ s$ n, Q8 {}
: `6 t+ V# y/ t, p: Y</FONT>7 S: G) H* s, t+ s0 ^

' q2 j7 o  r0 g4 B; m</P>7 E+ p7 d: o8 N6 P
<P><FONT color=#ff0000>函数名: settextjustify </FONT>
# Z3 S% ^: a, n% q9 E: w% o功 能: 为图形函数设置文本的对齐方式 + Q& Q" f3 |( P- a
用 法: void far settextjustify(int horiz, int vert);
( |  j( k; Q; C  {4 G' a程序例: </P>, _, S& `, S- b6 {9 A
<P><FONT color=#0000ff>#include <GRAPHICS.H>
& |; k4 O* ]( I3 I% C; g% ^7 |+ ^#include <STDLIB.H>
1 R$ s" n9 b- B, J1 h! g. L" L#include <STDIO.H>3 B& I2 q3 P5 ^! d2 M# Q4 N
#include <CONIO.H></FONT></P>
5 G" z. v, b9 v; {" o<P><FONT color=#0000ff>/* function prototype */
" {3 d9 Y+ ]6 d0 P/ H1 @) L: Bvoid xat(int x, int y); </FONT></P>
  K6 e7 I8 O7 f4 _' e; P' \6 l<P><FONT color=#0000ff>/* horizontal text justification settings */
0 _9 ^5 R4 J; n3 u6 y9 ^/ Ichar *hjust[] = { "LEFT_TEXT", % z; A) W" v! L( z
"CENTER_TEXT", ' S0 q; `- `" R1 e
"RIGHT_TEXT"
2 h4 U7 e. u' z}; </FONT></P>
+ L% X! y; v; v: h8 C( W% |<P><FONT color=#0000ff>/* vertical text justification settings */
- _) m" M9 N: @, H9 u3 Tchar *vjust[] = { "LEFT_TEXT", $ {7 V1 V6 |# f, D( T
"CENTER_TEXT", 7 `4 u; T% e, ?: g4 W: o, x- b
"RIGHT_TEXT"
  t1 J& D& A$ {& W- D: D( y}; </FONT></P>3 O) Z8 a0 |: R+ o  d2 e
<P><FONT color=#0000ff>int main(void) 6 k: ~6 [5 b2 }
{ 2 q4 x4 f% J0 `1 n: O  I
/* request auto detection */
9 ?) n# r# O# R0 [9 n3 ?int gdriver = DETECT, gmode, errorcode;
5 E$ n4 r8 v% q" J+ ~- }int midx, midy, hj, vj;
9 Z. E' |3 ~+ B8 c: P& ^char msg[80]; </FONT></P>; \( `0 c0 o+ ]4 Z/ i- D
<P><FONT color=#0000ff>/* initialize graphics and local variables */
1 h  k( I9 Q- uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ `+ r3 b! @- o5 |<P><FONT color=#0000ff>/* read result of initialization */
% e% P0 u& u* t/ @0 V8 @errorcode = graphresult();
& k6 R) P3 F& z6 Bif (errorcode != grOk) /* an error occurred */ / j' Q  J$ D- x5 j3 C4 \7 y3 u7 Y
{
/ u2 v- g4 m. t! D' _( `printf("Graphics error: %s\n", grapherrormsg(errorcode));
& L! {  `. r/ f! Iprintf("Press any key to halt:"); 1 W: F5 o0 w+ v2 ^4 M; O9 X
getch(); 9 f. D7 p, V4 G9 w+ ]2 k1 j4 z
exit(1); /* terminate with an error code */ ( a1 S: S7 [$ L. v
} </FONT></P>
1 O6 q9 h; ]! f<P><FONT color=#0000ff>midx = getmaxx() / 2; $ m; M/ A3 N% b0 @" }
midy = getmaxy() / 2; </FONT></P>4 X* P5 }. m$ [& ^3 u6 r1 A% a7 I& ^# B
<P><FONT color=#0000ff>/* loop through text justifications */
& b; ?1 x1 ?  D2 {) g* G/ jfor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
- o- _6 T) M: }% V" Afor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
" P8 A9 y0 x! L& Q{ " I  l4 Y6 T  R- U
cleardevice(); 8 Y$ B, j/ @% q" b' x5 h  o1 e" k0 r
/* set the text justification */ % j0 D6 y8 H& X' l3 y5 o9 p
settextjustify(hj, vj); </FONT></P>) Q, Z- z6 p5 m% u  I
<P><FONT color=#0000ff>/* create a message string */ / J4 g* n/ Z8 r! Z7 k
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
+ @" }* Y+ A7 W) S. w: ]<P><FONT color=#0000ff>/* create cross hairs on the screen */
  v* C" n* ~# |* S' i8 l5 Nxat(midx, midy); </FONT></P>
3 M/ T3 p+ V, i) F2 G& n* H" S<P><FONT color=#0000ff>/* output the message */
0 u. [" A4 M1 e6 h9 fouttextxy(midx, midy, msg); 0 K1 r8 Y1 f( {4 j) e( J% U! f& z
getch();
6 N; M! \8 F9 j9 x5 N8 Z4 @) V} </FONT></P>- g) K: B3 L/ u. v
<P><FONT color=#0000ff>/* clean up */
+ E) }, C" S1 h5 g2 mclosegraph();
/ m1 {, d0 \. O  Kreturn 0; , X9 T" L. q& f- p
} </FONT></P>
2 A0 u3 |) E# d<P><FONT color=#0000ff>/* draw an "x" at (x, y) */ $ V; Q! [1 s( o" i: \: A
void xat(int x, int y)
% `" `/ m0 z  I: V( T{ . V& X2 h& }, J
line(x-4, y, x+4, y); : w; S4 r8 y8 H  y: v
line(x, y-4, x, y+4); # h! O& y5 G: L3 H% t* ~# f  c
} </FONT>9 T7 i- w3 M9 v& e& E4 m" D7 n
  z2 S( @$ ?/ ]/ ~6 l8 M$ J
</P>
% Y* K# p' p4 Y<P><FONT color=#ff0000>函数名: settextstyle </FONT>
2 C& V3 M) d# N0 Y/ J功 能: 为图形输出设置当前的文本属性 + P4 f- a% P: b' I; E7 ]
用 法: void far settextstyle (int font, int direction, char size); 1 h0 T% G+ _0 n$ t' o0 \8 r; i% S
程序例: </P>' U4 O' U: k- r
<P><FONT color=#0000ff>#include <GRAPHICS.H>% G5 D. D. C: _7 o- S. d% h6 J; k
#include <STDLIB.H>! n/ L0 _1 S% l; [) A1 T& v
#include <STDIO.H>
" r5 n' x% s! l& U) t# I8 C  v#include <CONIO.H></FONT></P>+ Y" h. w) F8 i% f, ?, m1 q
<P><FONT color=#0000ff>/* the names of the text styles supported */ 0 E+ ?* q; J; s7 B" a& _1 |) @  t
char *fname[] = { "DEFAULT font",
5 a9 K7 a7 H! M5 K"TRIPLEX font",
9 p$ @$ F  ^% K! |2 u' U"SMALL font",
. X8 \. z  B+ b! j" Q* |& X"SANS SERIF font",
3 s8 [" j0 [: y# d! F"GOTHIC font" 8 G& e- Q9 u/ ]
}; </FONT></P>
4 O1 H4 K  p' D+ z) y  S8 l<P><FONT color=#0000ff>int main(void) 0 L/ ~9 X9 C$ L" ^/ k2 D/ ?5 C
{ ( W: y4 t9 d: e. U0 _$ }5 _& u
/* request auto detection */
; I1 n2 w- Y$ |( \int gdriver = DETECT, gmode, errorcode;
, z, }% j' S0 U% J2 [( {int style, midx, midy; * i: o* b$ p8 I$ r
int size = 1; </FONT></P>* v/ p: d8 ~# J1 g$ c$ `% k
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - S+ S% O  w. O: v  v
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) ~6 @6 v- s9 `<P><FONT color=#0000ff>/* read result of initialization */
" c- E& T2 Q6 k$ ~+ r+ C9 u: Aerrorcode = graphresult(); ! R+ l! y2 E9 m; |$ `! _. h+ L' G
if (errorcode != grOk) /* an error occurred */
4 Z4 N) W/ a8 \( t* }{ % s7 c; a; C' S( b/ a+ B4 Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
4 S) {: l" ^% e% ?. pprintf("Press any key to halt:");
3 p/ Z3 w1 `. B$ j* O6 M, p- o6 q1 Dgetch();   q7 ]; c; e  M% B; X* V
exit(1); /* terminate with an error code */
8 S( U4 O! }* l% \# y} </FONT></P>3 Z$ |/ _# g% q* n. D. {& O
<P><FONT color=#0000ff>midx = getmaxx() / 2; 8 C' b, }7 v1 ~( U
midy = getmaxy() / 2; </FONT></P>/ q( J3 J, a9 O* }4 ~# m: b
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
1 t# G) I3 T: x8 ]. t<P><FONT color=#0000ff>/* loop through the available text styles */
# P5 W2 ?3 r8 S1 u& {5 T0 f2 wfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) ' \" `( Y8 g7 |; U  c3 c2 Y
{
3 C0 y, _1 p" {% Dcleardevice();
& v/ W8 p8 _5 ?4 ?1 S0 _) ]! Sif (style == TRIPLEX_FONT)
9 I  n. Y7 j; |- lsize = 4; </FONT></P>
  D! _+ [: C, a6 S4 G<P><FONT color=#0000ff>/* select the text style */
% r/ f6 W* A% R& b; Usettextstyle(style, HORIZ_DIR, size); </FONT></P>- d+ r# Y8 {: d. N
<P><FONT color=#0000ff>/* output a message */ ; T  T6 o1 D' c
outtextxy(midx, midy, fname[style]);
4 _. D9 J, d- ~* t8 F/ E5 O( Sgetch(); % j$ q  ?  D5 x+ U6 @9 N
} </FONT></P>( p1 g8 K0 [) A9 \
<P><FONT color=#0000ff>/* clean up */ " e. i% Q2 T- T9 i% s
closegraph(); % ~' C) E& g1 x4 g2 |
return 0;
; x# r' u8 }0 G' B5 S; O, q5 G}
  W9 y+ f8 |& n" f/ m3 {</FONT>
% L+ [" b2 P- f/ L6 M</P>
3 Q# n8 `2 e" H+ T- d<P><FONT color=#ff0000>函数名: settextstyle </FONT>2 B- S* ?- U0 k7 w. ]+ N: W6 @
功 能: 为图形输出设置当前的文本属性 ( y% [. u8 M: t0 H. N6 H- g* v+ F+ k
用 法: void far settextstyle (int font, int direction, char size); 6 N8 a8 G/ V* ]6 G6 {* |
程序例: </P>, v5 \% u) e2 u5 j# b7 [
<P><FONT color=#0000ff>#include <GRAPHICS.H>
* U+ _- q& f  s8 _# x#include <STDLIB.H>6 R! w; M( e* c8 d
#include <STDIO.H>
+ g6 o0 \" G8 V4 d#include <CONIO.H></FONT></P>
% i- H( C* Q) K$ L2 n& G7 ?- R( m0 `<P><FONT color=#0000ff>/* the names of the text styles supported */ + u+ J+ O) j4 A& T: ~
char *fname[] = { "DEFAULT font",
( ^7 ?$ l% i/ T1 N0 \- Y& ^, V"TRIPLEX font", , J0 {5 H0 O9 K' D
"SMALL font",
: B9 U7 u' q+ C( }"SANS SERIF font", ) H" v( H( z# N( [0 ~
"GOTHIC font" ) p+ c* S4 X3 p2 X" h; K- a
}; </FONT></P>
5 M1 N7 u$ E- q/ f<P><FONT color=#0000ff>int main(void)
' q) h6 a2 t( s1 c  J{ ' w% K7 k: w/ a* N" R  A+ c3 v# c
/* request auto detection */
3 p3 n7 Z$ n( a: Gint gdriver = DETECT, gmode, errorcode; 8 P! g, s8 V5 D5 X; m$ `0 W/ z) |) ~
int style, midx, midy;
- W4 X$ [  t5 C, Oint size = 1; </FONT></P>
2 a1 S2 A9 ^# p( Y* J6 f+ m<P><FONT color=#0000ff>/* initialize graphics and local variables */
% k, x# z5 _0 L& P2 b5 d. hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 I+ u& [: Q5 ?2 v<P><FONT color=#0000ff>/* read result of initialization */ 2 l. n) k; t! t. s" m. P
errorcode = graphresult();
' k0 \6 `7 G0 V. i5 w- O. M4 vif (errorcode != grOk) /* an error occurred */
0 g. M; y# R. ?0 d& c, q! @{
  O. q9 `5 P& v6 W0 M9 @) Dprintf("Graphics error: %s\n", grapherrormsg(errorcode));
  x  d( Q/ n4 ~) [9 h& `$ p2 aprintf("Press any key to halt:"); 1 V% U  P6 J6 O
getch();
$ J* A; E- Z2 q3 Y+ Q# yexit(1); /* terminate with an error code */ 4 Z5 e: Q! d. ~  p* L' [
} </FONT></P>% o( {9 U) {$ G' {) e  }8 ~+ I
<P><FONT color=#0000ff>midx = getmaxx() / 2; # n- g; ~! ?4 |* d
midy = getmaxy() / 2; </FONT></P>$ n& H% i- x" A) x" j; k, ^
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>2 g% w- _. p3 X7 D" T9 s. l+ ?
<P><FONT color=#0000ff>/* loop through the available text styles */
" `4 B  y" t" D+ Y3 ufor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
3 B; ?' A. {$ ?% I{ 5 d9 m1 B+ @+ R3 a
cleardevice();
- O: R" F3 q1 f. ]; Uif (style == TRIPLEX_FONT) 5 I; V; }# u/ S( `) X
size = 4; </FONT></P>5 e3 [: K( E( c/ h+ ~& _
<P><FONT color=#0000ff>/* select the text style */
8 ^' a0 b& d, I1 psettextstyle(style, HORIZ_DIR, size); </FONT></P>7 i* n5 k! z0 E0 w4 V/ e- K
<P><FONT color=#0000ff>/* output a message */
+ [. Y; |" n  G8 d- ^outtextxy(midx, midy, fname[style]);
" c5 ]5 l. x5 \! p* k: Ygetch(); ! b. s/ b+ ]. a: M* M& N) A
} </FONT></P>
2 P1 b- g8 E6 d8 x<P><FONT color=#0000ff>/* clean up */
! A2 W1 ^6 w* I0 a: w$ eclosegraph();
9 t+ z* n; h' }) Ureturn 0;
0 h' o+ n# g6 {1 h} </FONT>- W* z8 V3 ~( h3 P/ `$ E+ Z
# a5 B8 Y4 G7 h7 u4 @+ }
</P>
/ ^; ^6 Z1 t8 |/ Z' k4 K6 t<P><FONT color=#ff0000>函数名: settime </FONT>5 H6 k6 d3 b* Q: j! D$ X
功 能: 设置系统时间 : ^+ Q4 A& ^0 X- W" V' D1 U
用 法: void settime(struct time *timep);
1 `+ j7 Q* R8 \- L程序例: </P>9 {( m, c4 ]. Y  w7 r
<P><FONT color=#0000ff>#include <STDIO.H>
5 {" `; j& Z+ l#include <DOS.H></FONT></P>9 E9 {* L3 {5 E. q
<P><FONT color=#0000ff>int main(void)
  Z8 U! N. ^  n1 `' H. k$ S{ 6 S: \( u( ]! e' `! E5 s
struct time t; </FONT></P>
7 @+ _$ P* ?' Q- B* [/ r' C/ }. o<P><FONT color=#0000ff>gettime(&amp;t); * G  e+ r& Z- C2 x; `% J5 B
printf("The current minute is: %d\n", t.ti_min); 7 z0 d9 v0 h+ f( z- |
printf("The current hour is: %d\n", t.ti_hour);
/ Q# k) W' y. ^( ^: ~printf("The current hundredth of a second is: %d\n", t.ti_hund); + M7 U) e, V: f3 i9 w% ^% I5 ]' u
printf("The current second is: %d\n", t.ti_sec); </FONT></P>2 i6 ]; Y# D$ e  A( Y
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
# E+ y2 a* K9 k2 t' V) Et.ti_min++; , k7 I2 o9 u1 k
settime(&amp;t); </FONT></P>
0 P3 ^4 }4 g0 E6 x7 S1 n5 M<P><FONT color=#0000ff>return 0; $ `: {6 W2 @- u% h" ~  B+ r
} </FONT>2 B2 D" L7 V% u8 |3 I3 ~
6 ?8 O% v" w6 ^
</P>
2 ]* K9 ]2 s: e; A' B% O9 |<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
, X- f( s# X( j5 e2 N2 M4 t功 能: 为矢量字体改变字符宽度和高度
: [" ^4 C$ w( w9 S" Y用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
% u# X7 @; `5 d7 M程序例: </P>- P1 D: ], _4 |: C" k& L- n' }* a
<P><FONT color=#0000ff>#include <GRAPHICS.H>. S  y& w! b( O; f1 ^  Q" i6 L
#include <STDLIB.H>
0 J0 \; a; @. }# _6 ?3 x7 O$ A- J#include <STDIO.H>9 }: h2 I' |. B: y# I& u6 |
#include <CONIO.H></FONT></P>1 _  J+ f- c! }1 J, f* p# z
<P><FONT color=#0000ff>int main(void) 5 J: ?: U4 u9 h
{ ! C+ }- D1 w" x. l' R
/* request autodetection */ # n# N9 c6 t, d& J/ k& L
int gdriver = DETECT, gmode, errorcode; </FONT></P>2 P. d# _! c9 q8 U4 V! F
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ y6 J, Y. Z% E
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>& F, I7 M2 `% T8 t/ w5 |2 I  c4 f
<P><FONT color=#0000ff>/* read result of initialization */
4 Q8 k2 l3 g0 ]" Yerrorcode = graphresult();
# i( J: Y: Q+ n7 Fif (errorcode != grOk) /* an error occurred */ * A* i  Q. J) h' v  T
{
2 }, i( Z& e) X. _7 Y. D6 Oprintf("Graphics error: %s\n", grapherrormsg(errorcode)); . t3 V( O5 _3 K8 M- S. R
printf("Press any key to halt:"); % r# S/ D+ a. F6 Y8 j9 o: H# w; ^
getch();
6 C: \. I+ E/ V$ J' y8 w+ dexit(1); /* terminate with an error code */ ' v/ I7 H, c: q$ z9 Y
} </FONT></P>9 I( T3 p6 R5 N1 K' h" ]( X! T  x
<P><FONT color=#0000ff>/* select a text style */
$ b3 p& K0 _4 U6 k: [  Jsettextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>8 q0 r. c, K7 V, \2 }9 j( B
<P><FONT color=#0000ff>/* move to the text starting position */ & F+ Z% G( i8 S- F0 Z) U
moveto(0, getmaxy() / 2); </FONT></P>( }* \" D- T6 I) f* S
<P><FONT color=#0000ff>/* output some normal text */
2 O: R) r" S* I/ |6 n* L+ `outtext("Norm "); </FONT></P>
) c( ~; M' ^* M. S" M/ y( y<P><FONT color=#0000ff>/* make the text 1/3 the normal width */
# L5 W6 [6 U% K" z; H* @setusercharsize(1, 3, 1, 1); / y' f' H- v, b
outtext("Short "); </FONT></P>2 y6 g/ z) B" z8 j9 K" Z2 X( v' j
<P><FONT color=#0000ff>/* make the text 3 times normal width */ / B. _5 p' p( ]7 G
setusercharsize(3, 1, 1, 1); 3 Z  g8 X3 z: b) k, k8 g9 c
outtext("Wide"); </FONT></P>
8 v+ c. t7 m  p! A4 U1 n<P><FONT color=#0000ff>/* clean up */ 2 V) \7 ~- }& l6 d7 J+ l
getch(); 5 H# T. P$ j; G! N8 m
closegraph();
; I- L0 @( D1 l1 F3 Ureturn 0; / o! n9 {$ T/ N
} </FONT>$ k/ u  A# l2 v) W
</P>4 {6 G+ m1 U& N$ D
<P><FONT color=#ff0000>函数名: setvbuf </FONT>
6 Q! u! ?! S; Y2 s+ ^0 j功 能: 把缓冲区与流相关
( n% y" }9 D" h2 d) M: S& w用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);   J1 u9 Z3 y: }$ \  W2 D6 v) ~' Q
程序例: </P>
* N- y& f0 y& |" s<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
& y/ D/ N9 e2 J' O# D$ J<P><FONT color=#0000ff>int main(void) + S$ o6 i9 E. R% u
{ / N0 \& [$ `* D5 E4 f
FILE *input, *output;
  D( C! ~( |8 d" O$ n, ?1 x. wchar bufr[512]; </FONT></P>
  ~. ~& A1 f6 v0 N9 w! j5 ]( ^<P><FONT color=#0000ff>input = fopen("file.in", "r+b");   ^; a9 l! K8 p% c) V* p1 ]
output = fopen("file.out", "w"); </FONT></P>" w6 y8 [2 L  D8 R, W
<P><FONT color=#0000ff>/* set up input stream for minimal disk access, 4 v+ j; D4 n0 ~3 T( j& j; E
using our own character buffer */ * W0 N3 G" `+ p$ P& Q% J
if (setvbuf(input, bufr, _IOFBF, 512) != 0) ; E8 l' @# M$ ]6 G
printf("failed to set up buffer for input file\n"); ! T# Q' n# s7 z) [5 Y. C# |6 D
else ' P& Y# R6 Z5 f' k8 J
printf("buffer set up for input file\n"); </FONT></P>
3 N. a% b/ X- F" _% ^<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
+ P6 ~; t% G0 pwill be obtained through an indirect call to malloc */ 2 v: G9 V: C& A
if (setvbuf(output, NULL, _IOLBF, 132) != 0) 4 u& ]/ _- v+ P+ d; E' ?
printf("failed to set up buffer for output file\n");
3 t, H0 R7 F) E0 b5 L( O! Felse ' S" K: A" c3 a7 A1 B
printf("buffer set up for output file\n"); </FONT></P>
' f+ |9 ~) ]/ f; G& r<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P># Y- b7 L1 F" d% z7 C2 S! q2 I
<P><FONT color=#0000ff>/* close files */ . D% R& v* o3 N; j2 O; p0 a
fclose(input);
& F; R) g! X. x9 K" U6 afclose(output);
, @& F, _: K: N& |% o" @5 e0 xreturn 0; : q. T1 c, z; f, h  ~6 m9 R6 X
}
0 X8 @. c' O8 ~/ Y4 c( l$ M' ]+ ^</FONT>
6 Z; W7 I0 |0 K: t" ?# Z
& y6 A) O/ @5 D% w, B1 v9 W. P</P>) B! O# {/ w& j: [$ N
<P><FONT color=#ff0000>函数名: setvect </FONT>% ^# t. j# d& A: Z% a
功 能: 设置中断矢量入口
* B7 R( m$ h6 k用 法: void setvect(int intr_num, void interrupt(*isr)());
' a; O! q1 f8 Q8 d0 {程序例: </P>: h! F2 j( T* S, e8 Q
<P><FONT color=#0000ff>/***NOTE:
! Y- N' \2 j9 C( c% P8 U6 M; aThis is an interrupt service routine. You can NOT compile this ' ]( J; E+ i/ {3 t  R( i' u1 j- w
program with Test Stack Overflow turned on and get an executable $ @/ C; ~; H7 }
file which will operate correctly. */ </FONT></P>
) s$ k$ F7 F2 ^7 D$ ?<P><FONT color=#0000ff>#include <STDIO.H>- Y7 g) n* V+ y  O; {; t! k
#include <DOS.H>
; E8 |+ ]2 r% [6 T6 |8 Z#include <CONIO.H></FONT></P># {+ T1 J, t2 i8 G+ [/ e- p% v
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>2 b5 e) {8 ]0 X; e* M9 ]! ]. X$ n
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
$ H+ U. F6 x2 Z+ g* j- z( X<P><FONT color=#0000ff>int count=0; </FONT></P>
$ F- n4 E' y0 {<P><FONT color=#0000ff>void interrupt handler(void) : j% E9 R5 {! l( c/ ^; \1 b
{
: K- a4 [  p% B6 Z: \9 ^. F/* increase the global counter */
# A9 ?+ Y- ?; J" m  N" O" Ycount++; </FONT></P>" p. d3 _3 T: M* F6 `' B
<P><FONT color=#0000ff>/* call the old routine */ 8 f$ c+ t% {- }: [+ r& h" O, {
oldhandler(); $ I' \3 I0 r" e6 R% e* ]7 P
} </FONT></P>
! f/ L& ]% x. ?% V: z6 w( ]<P><FONT color=#0000ff>int main(void)
) H# ~! z3 Y4 I; d4 e% _9 g( \* H{
  x& u* i1 q+ R% g/* save the old interrupt vector */
3 x9 r" n- y; @  K# t  m2 Roldhandler = getvect(INTR); </FONT></P>/ l& W; ?  o4 d
<P><FONT color=#0000ff>/* install the new interrupt handler */ . m) [3 I0 G+ F7 v3 W
setvect(INTR, handler); </FONT></P>
, t! q' y: u( o$ M7 V7 P/ x& n<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ " t" c' S" f" t% F- P# ~* Z# n
while (count &lt; 20) 4 M5 t& B2 E; ]# M7 i
printf("count is %d\n",count); </FONT></P>- w3 J% Y' u- T9 m0 n' a* L
<P><FONT color=#0000ff>/* reset the old interrupt handler */
$ r1 a: p0 }$ {  J9 hsetvect(INTR, oldhandler); </FONT></P>
+ G7 x9 W! ^0 l1 {<P><FONT color=#0000ff>return 0;
& W+ s( U) N1 q. w3 [# [! q: [/ I}
; q& g$ s& ?8 B4 }( R</FONT>% s$ m+ ^' {# |* A+ l. ~- e; Y$ e" K
</P>6 }% f) X) m) V4 ~3 R
<P><FONT color=#ff0000>函数名: setverify </FONT>
* ~4 I) k& y: F功 能: 设置验证状态
$ |& s8 k& o9 N3 C; O用 法: void setverify(int value);
9 F# F* ]  b2 B: I* G程序例: </P>
3 M" s# X# _: K2 E<P><FONT color=#0000ff>#include <STDIO.H>
; E1 O9 i$ A3 I: o#include <CONIO.H>7 l7 G' l3 N! e5 \
#include <DOS.H></FONT></P>$ G# O  i: F7 C5 B/ y9 w3 s
<P><FONT color=#0000ff>int main(void) 2 }' n. Y1 Z& v3 p( i& I4 T8 @
{ % v4 e8 N' [+ h- _( ]) I
int verify_flag; </FONT></P>
+ E% q) t# j/ V+ R0 b<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); ( a$ }  O  A( ]# G  q) P4 C
printf("Enter 1 to set verify flag on\n"); </FONT></P>0 F+ r2 @+ Q1 R- E, e# c; T
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>( v% ]( d  H2 U$ D( B) W+ j
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>6 ^* t9 F1 C7 J2 N# J" B
<P><FONT color=#0000ff>if (getverify())
/ x! ^$ {$ K9 z7 h# u; Cprintf("DOS verify flag is on\n");
1 J, l1 K4 l5 V) T' O' z5 l2 s) selse
. R1 k2 ^  ^: Z, m2 c6 V( F5 Mprintf("DOS verify flag is off\n"); </FONT></P>8 M  g( v0 e/ d
<P><FONT color=#0000ff>return 0; % y5 K# Y: U( r& _
} & M, v( y1 _! Z. W( c2 x# B
<FONT color=#ff0000>
7 D" W/ Y' ?2 F3 f  v</FONT></FONT></P>
, |! ^7 o2 J: B5 f7 b<P><FONT color=#ff0000>函数名: setviewport </FONT>$ r' J6 p" R4 \2 K+ l
功 能: 为图形输出设置当前视口 % g+ \/ i1 v8 `% w' j
用 法: void far setviewport(int left, int top, int right,
( o% \, R0 I1 A) {int bottom, int clipflag);
& o# {, k. ?9 g! |( J程序例: </P>
) u- T1 C$ ~0 H1 e" G<P><FONT color=#0000ff>#include <GRAPHICS.H>" \# I6 e* ~# G9 @- H
#include <STDLIB.H>
' ^/ I. j) R  l0 b# G' ?. r#include <STDIO.H>6 X: E4 C, _  v4 K3 z; g! d/ m
#include <CONIO.H></FONT></P>
4 O" T3 b) s8 d' \0 ?  U; Q' P5 p<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>7 K8 c# H" Z" ^- N5 T. T5 b
<P><FONT color=#0000ff>int main(void) 2 X/ W- D4 ?. N# j( g2 [! y" w) e, R
{
; q( I' T: g, o3 q+ p1 M, ?: ^/* request auto detection */ * {0 N6 l  I) I' t* D
int gdriver = DETECT, gmode, errorcode; </FONT></P>
, a7 `- v. n4 a: t9 U0 i<P><FONT color=#0000ff>/* initialize graphics and local variables */
' Q, d) {5 o8 N9 L5 g. ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 w- ?# Z4 K  t! r' w7 x
<P><FONT color=#0000ff>/* read result of initialization */
, j* n& q# e/ H! s" w- herrorcode = graphresult();
2 \: ]# X) w+ s; Y% A% x- Vif (errorcode != grOk) /* an error occurred */
4 B+ j. T8 T- y9 M: D+ G{ 7 [9 J% v8 m) R! H
printf("Graphics error: %s\n", grapherrormsg(errorcode));
6 A/ |" G; {+ S, z3 Vprintf("Press any key to halt:");
8 w  f; ~& g* ?. h! q0 ^getch(); ( _- h0 F; o  O* f8 d. r
exit(1); /* terminate with an error code */
! j; c. [! U% T} </FONT></P>2 s# o& o+ G8 `4 Q, g+ p9 _
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
& x) i: A4 W+ G, v, u( d<P><FONT color=#0000ff>/* message in default full-screen viewport */
. C5 O0 Z. }3 S; K; \outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
' F6 D; C! g: F<P><FONT color=#0000ff>/* create a smaller viewport */
- K2 R+ b9 a  `5 U  A7 u2 xsetviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>  T8 p$ F7 F* F  n, p7 A0 ~- _
<P><FONT color=#0000ff>/* display some text */ : \2 J' C" L& n7 d! z; _9 x
outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>$ y4 }( t. F* q/ }
<P><FONT color=#0000ff>/* clean up */ 7 N: ^( o3 P# @4 {* [; |
getch();
; z" T. t$ E) p* gclosegraph();
# t6 g( |/ h. Q% H0 g- Ireturn 0;
  K+ N7 Z; Z  e& a9 B. X} ) b+ ]# ~0 q+ {! |7 ]4 s- `
</FONT>  ?$ E5 C; [/ a; ^6 ^9 ?
</P>! ^3 c# b! r% i! o+ F) y: ?0 x7 H
<P><FONT color=#ff0000>函数名: setvisualpage </FONT># n! O2 |1 I' N! E, \
功 能: 设置可见图形页号 / L: q5 K. f* E* i5 q4 h
用 法: void far setvisualpage(int pagenum); * `8 L7 E" S/ @$ z7 T  B! {6 b/ k
程序例: </P>
: @% W4 }6 V$ ?/ [! R) ~<P><FONT color=#0000ff>#include <GRAPHICS.H>
) d' [8 ~3 |& b6 g+ N#include <STDLIB.H>) M  |; K* H6 U+ {
#include <STDIO.H>3 `6 b3 Z0 a8 N
#include <CONIO.H></FONT></P>
; s0 a  g! d- A- G- |" ]. X<P><FONT color=#0000ff>int main(void)
' N/ f! o: x( b; p" A7 D) |1 c, K. @{ ! U5 a9 Q8 {' x! h
/* select a driver and mode that supports */
+ i! k5 A9 x. i0 e4 ^/* multiple pages. */
& a3 _, h7 m5 [int gdriver = EGA, gmode = EGAHI, errorcode;
$ G" R- @4 m3 d4 @int x, y, ht; </FONT></P>" x; K0 W2 `; w* n0 M1 h: F
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . x" p5 ?; D$ x7 w' D1 l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 O1 O' k. l: \0 Q; {4 o
<P><FONT color=#0000ff>/* read result of initialization */ 8 f! q+ \% F, W* Y' F; K3 F
errorcode = graphresult();
& k+ I; s5 C' bif (errorcode != grOk) /* an error occurred */
4 l8 k/ T* C2 ?* x9 h& I; ^( Q{ % X, p: ^* _+ L
printf("Graphics error: %s\n", grapherrormsg(errorcode));
* b- _# W* E1 Q9 t5 l# sprintf("Press any key to halt:");   B5 l# R/ G) I7 R) g8 s* Z
getch(); 3 z* X. T0 a' B( K6 D! m& A
exit(1); /* terminate with an error code */   k$ f) J# r- [3 R0 x
} </FONT></P>3 v$ u- P; t6 }
<P><FONT color=#0000ff>x = getmaxx() / 2;
( s  m$ `# p" t" hy = getmaxy() / 2;
% x5 S, Q; }0 O/ tht = textheight("W"); </FONT></P>2 u3 O. V& P. H$ O0 n
<P><FONT color=#0000ff>/* select the off screen page for drawing */
# e) a) [0 W  F1 b/ n1 s0 ssetactivepage(1); </FONT></P>8 [1 R% h' h/ w2 O4 |( B" n( I
<P><FONT color=#0000ff>/* draw a line on page #1 */ 6 u. H6 x: N$ X, o1 V+ i+ k% d/ \0 K( w
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
+ c! |0 P3 g5 W5 g7 N& S, }<P><FONT color=#0000ff>/* output a message on page #1 */ ! x$ ~* E0 n4 x0 p
settextjustify(CENTER_TEXT, CENTER_TEXT);
% @+ Y+ a' ~! M8 oouttextxy(x, y, "This is page #1:");
2 p/ |7 d, q  H$ Z0 s! Vouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>" u2 I' V; w% w/ \: j( s  A9 h
<P><FONT color=#0000ff>/* select drawing to page #0 */ ' O" a5 i8 Z, H3 t# `
setactivepage(0); </FONT></P>/ c* X/ a( W# f  w- C8 H$ l8 G4 R
<P><FONT color=#0000ff>/* output a message on page #0 */
& f+ C1 _+ p; Zouttextxy(x, y, "This is page #0.");
- [0 y" |, M/ l, E- eouttextxy(x, y+ht, "Press any key to view page #1:"); * }; \' y9 [% g5 U
getch(); </FONT></P>6 v$ M0 O1 x9 o$ \* o" Y
<P><FONT color=#0000ff>/* select page #1 as the visible page */ / ~, [) y- Y* v$ A' v1 h( P% u
setvisualpage(1); </FONT></P>1 U* R( o) M& w2 r
<P><FONT color=#0000ff>/* clean up */
8 |( M* h/ Z! ~& g9 q  C% q0 mgetch();
; N/ ~( ]0 E; c2 C% P5 W; Qclosegraph(); 0 f$ W4 O$ ^; {* k1 Q" Y
return 0; 1 m* i0 w5 q6 |) o5 x5 Q
} </FONT>) p1 Z( L4 l# @* l* T' f2 F

  K# c" G& X0 u</P>
9 y2 ^2 a& W9 _<P><FONT color=#ff0000>函数名: setwritemode </FONT>0 S8 c& X! W8 W
功 能: 设置图形方式下画线的输出模式
" I! H2 Y7 n% z& `; \/ K用 法: void far setwritemode(int mode);
, g$ G& F; i  @. u) `' Z$ o9 I程序例: </P>
) O/ N7 ~7 U  U) v" }( A7 m<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 J! L; X/ x. Z2 y) I#include <STDLIB.H>6 A7 ]( \9 w5 I- S
#include <STDIO.H>+ g% D* R8 Z0 ]" E0 b. q4 ]4 Z
#include <CONIO.H></FONT></P>5 F7 T! |4 C# C
<P><FONT color=#0000ff>int main() 4 d* V/ M- ?6 ?3 A, E$ ]. _' M
{ : i# K% m) }  x' y
/* request auto detection */
  Y5 F+ |/ M/ mint gdriver = DETECT, gmode, errorcode; / X; d. d. ^2 P: G" P/ Y  {, Q' \# Q
int xmax, ymax; </FONT></P>
# H+ M0 x6 Y  v$ U* u5 u1 S6 T<P><FONT color=#0000ff>/* initialize graphics and local variables */
0 q5 R4 M$ W$ iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( U. [) ]; W; p( y( ^& E) c<P><FONT color=#0000ff>/* read result of initialization */ 8 X! }# L' ]' P7 q* Z( J7 m2 X
errorcode = graphresult(); / q7 O6 a+ ]0 v0 H3 a
if (errorcode != grOk) /* an error occurred */ * m# Y8 x9 M- T7 U  z  B
{ 2 P, ^1 \4 _8 J' J
printf("Graphics error: %s\n", grapherrormsg(errorcode));
8 J2 `8 C4 m$ n$ k3 g6 w8 H- Cprintf("Press any key to halt:"); 2 s, i/ N" k  ]1 b7 ^; N
getch();
% {" ]& M1 c; N. O4 Aexit(1); /* terminate with an error code */
2 l5 Z8 m( Y+ \2 C+ ~} </FONT></P>
! B' s. d+ K; y8 d" x. n7 \<P><FONT color=#0000ff>xmax = getmaxx();
- z% v2 k& q" m+ o. R/ V7 mymax = getmaxy(); </FONT></P>0 J, F& N. h% q* h1 D( b
<P><FONT color=#0000ff>/* select XOR drawing mode */
6 g3 [& A, y* Q/ G+ Ksetwritemode(XOR_PUT); </FONT></P>
. O- u2 Z8 {# y# s) F% U% Y. m<P><FONT color=#0000ff>/* draw a line */ # }. x) w, I2 z9 I0 N
line(0, 0, xmax, ymax); ' M! W3 C5 J% w+ U4 z2 ^
getch(); </FONT></P>% L: z" y2 ]" ?0 E7 _2 s+ _2 P
<P><FONT color=#0000ff>/* erase the line by drawing over it */
5 D" G. Q& ^, Dline(0, 0, xmax, ymax);
7 U% s9 F5 {% |7 a1 r4 Zgetch(); </FONT></P>
( d! {2 O! X( W6 ~<P><FONT color=#0000ff>/* select overwrite drawing mode */
' X4 b2 o* ~) Ysetwritemode(COPY_PUT); </FONT></P># A  R) c# U. V5 C: K4 a9 d, X3 g
<P><FONT color=#0000ff>/* draw a line */
9 M+ p) ^) |% |- P  x, nline(0, 0, xmax, ymax); </FONT></P>
% Y. r' i0 M# |% _! T<P><FONT color=#0000ff>/* clean up */
6 a$ u) J  m! x1 igetch(); # {7 Y. \* n2 Y0 C
closegraph();
9 j' f/ X; R& q6 ~return 0; / O/ g' m- ]3 Q; G
} ; v* p( E: S) l" ^0 m1 k" ^5 q
</FONT>- H0 w- P, D: J5 n6 Y8 L
</P>2 g$ W- i3 M! l
<P><FONT color=#ff0000>函数名: signal</FONT>
1 }2 x8 }  C# r: {0 x7 B功 能: 设置某一信号的对应动作
* ?8 \3 a+ g: h3 p& J, ?- f- S用 法: int signal(int sig, sigfun fname);
) |5 F/ M" B- B" v. e" j, b程序例: </P>
: y" D  b2 j0 E& f; x+ B<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE,
% Y% }% i; N; C# i2 A/ ^0 Lcatches an integer overflow condition, makes an adjustment 6 L  w! {9 Q" d; X  u5 D$ |
to AX register, and returns. This example program MAY cause
# v3 k9 Z9 @# e$ f* |1 f8 Wyour computer to crash, and will produce runtime errors
: W* x3 T. ^# ?! I2 `5 ?1 tdepending on which memory model is used.
0 }* n/ a  t2 P0 H+ @7 [*/ </FONT></P>
0 f8 Z: i0 s, a7 D<P><FONT color=#0000ff>#pragma inline
: k; M: r- \" ]1 m3 _8 E7 s#include <STDIO.H>
' _; J6 K3 D) ~#include <SIGNAL.H></FONT></P># W& f7 _% d! a8 J: J( }
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
: O% D& v# ^, f/ ]: h' X# L{
8 d4 k' R. ]1 e: R0 ^# vprintf("Caught it!\n");
( p( D8 E- A% n$ c! R) R*(reglist + 8) = 3; /* make return AX = 3 */ 7 A# k7 e* l2 N" P
} </FONT></P>
( H- @; l% Z# S1 _( v% X<P><FONT color=#0000ff>int main(void)
6 w; X  J; w5 K/ y" J% j( |9 C{ $ t% M1 ~" n! R! s
signal(SIGFPE, Catcher);
" O( Q+ s/ c) basm mov ax,07FFFH /* AX = 32767 */ * b1 Y# v0 H' ?# _0 Q2 j" v8 x
asm inc ax /* cause overflow */ % v" A+ V) C; t5 m
asm into /* activate handler */ </FONT></P>) P/ C" i8 |7 f, J
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, 5 x) x# A& V$ A1 W+ u
there would have been another exception when the next 'into'
. H. e& L3 r  \1 ]' kwas executed after the 'dec' instruction. */
, [0 x3 B" u) N3 J7 o4 r( Xasm dec ax /* no overflow now */
  |0 n) p& h) o5 _8 j2 easm into /* doesn't activate */
, _1 i6 N. y" U0 I3 [$ \return 0;
- A! q0 V- g$ w* `} 6 j- h0 B; h5 _# S% ~
) Q2 M7 L% x; p

# f4 }6 L# Z$ ~+ A+ O; X' S# {- G: \" b* [</FONT></P>
1 c2 T0 I& s! Y. i* I0 O( ~<P><FONT color=#ff0000>函数名: sin </FONT>
/ P9 q8 F+ D4 e" l2 e; y$ F功 能: 正弦函数
( y1 I: v1 G( v9 t& ^% _5 f用 法: double sin(double x); 0 b8 ]6 W8 E/ f4 {" _' C5 s& M2 Z* }
程序例: </P>
$ E7 a- C- y/ u6 b: f8 Z* V1 V% q! |2 u<P><FONT color=#0000ff>#include <STDIO.H>. |8 x, @' U2 o
#include <MATH.H></FONT></P>
) q6 I. d5 T" ?8 z9 f<P><FONT color=#0000ff>int main(void) 0 j9 z. g% f6 Y- U, D
{ 2 p$ w# ?  U  ?1 g' t" \
double result, x = 0.5; </FONT></P>/ u& m( d7 O: E! w0 M6 q
<P><FONT color=#0000ff>result = sin(x); ) D; G) I3 g' H0 k& i4 K2 T
printf("The sin() of %lf is %lf\n", x, result);
5 K; @% n& q# m& C; B& Creturn 0; - c: p! `9 ?: _4 x, n" R% b
} . B$ X# f2 W7 @  h8 c

/ ~, G3 M: n& J8 F</FONT></P>% E. ^+ V" E9 T) V4 [1 O" @2 e
<P><FONT color=#ff0000>函数名: sinh </FONT>
' j3 O) Y& I) a: D功 能: 双曲正弦函数 5 r5 t4 |6 r4 h; Z- L: v7 I/ J
用 法: double sinh(double x);
" Z4 I( O" _( A+ I0 \$ @. B$ E程序例: </P>
& }# S; P: n$ a/ S5 I# L" p- d<P><FONT color=#0000ff>#include <STDIO.H>
4 P( z, K% f. S1 k2 K# ^6 X#include <MATH.H></FONT></P>
2 ~! j+ Q) @4 r# O2 J0 e8 P- u- l/ h<P><FONT color=#0000ff>int main(void)
" c) t$ V5 K. [' Z$ u. @4 z# d{
; f) C" Y# t$ ddouble result, x = 0.5; </FONT></P>
' a0 |) I2 a4 Y: c1 m<P><FONT color=#0000ff>result = sinh(x);
/ h; m8 j3 I$ i2 k& [' C/ \% Fprintf("The hyperbolic sin() of %lf is %lf\n", x, result); 8 l' c' I3 j* q2 f; x) c" d% Y8 g
return 0;
8 _" L4 |3 u. j. G9 M. B2 H}
2 }$ q" a8 {/ {1 ^) T) s# Z0 l% g

) `$ N! I! S* j</FONT></P>
  Q0 F3 g% x5 d" b. g<P><FONT color=#ff0000>函数名: sleep </FONT>
# T; I0 V& v' R1 u' I功 能: 执行挂起一段时间 , Y' x# c# u1 x, V" h0 k
用 法: unsigned sleep(unsigned seconds);
# o' g$ P5 p/ @  C程序例: </P>
, c- r& `  [& B7 m' U2 W/ z( Z<P><FONT color=#0000ff>#include <DOS.H>
) C: O. X  @. A$ w#include <STDIO.H></FONT></P>
4 M* t+ ?2 ~4 V* l+ x3 ]0 J3 w7 T& p<P><FONT color=#0000ff>int main(void)   v$ J9 o$ `2 M6 u
{
6 o6 Z" F5 x! o* c1 e* uint i; </FONT></P>
8 P6 F! ~* ]  s: _0 s+ t<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
2 E* K! A! p0 R9 |7 V" \$ {1 g{ / K4 i0 A$ ]3 A1 m3 Y/ S9 k0 W
printf("Sleeping for %d seconds\n", i);
+ Z" B  Q5 a; w: x& x& psleep(i); " \. H( v: v! P& @  X5 G2 {
} # c, E* R, |& {% o
return 0;
6 \: b' `8 ~) `1 M' u5 m5 J} & ~2 J9 t. B, Y' m* z4 w$ D/ F
" |; ]; D% R( l* q* H: v
</FONT>' l7 o7 y1 b' x* ?* a" O( k9 b% {
</P># L% G' I3 e4 z. u& b1 s8 l6 d9 `! H! }
<P><FONT color=#ff0000>函数名: sopen </FONT>7 C9 ~* D' ]* B& V0 `! G1 K. x
功 能: 打开一共享文件 . ]3 `  \7 V8 ^/ Y. A# J
用 法: int sopen(char *pathname, int access, int shflag, int permiss); & T& H: v7 P( g: `6 Q, l- E  A9 [
程序例: </P>
5 d6 L, G5 W" G/ d<P><FONT color=#0000ff>#include <IO.H>; S3 J( u( \. c1 Q! i) C) a
#include <FCNTL.H>
5 O7 L& B! T. n#include <SYS\STAT.H>) P8 l8 r" j' }& m( j0 z6 P
#include <PROCESS.H>
8 M( O! P9 A3 b, m/ u#include <SHARE.H>
: l1 @1 x! t5 a2 M; d#include <STDIO.H></FONT></P>/ K# l9 N5 z/ f4 X" g; O- _$ Q- S4 q
<P><FONT color=#0000ff>int main(void) 0 p1 H, w6 X# s: }+ g' L. F1 T8 O
{   o8 }% z# P% F# q% c* f5 N
int handle; : ~4 |% W$ [$ Q, T- y0 k
int status; </FONT></P>4 u. Q+ o$ _; q6 ?2 @9 a
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>0 C, b$ j8 h% p, N; j
<P><FONT color=#0000ff>if (!handle)
* Y/ s. R- X1 F5 g7 ]# K{
+ ^$ j. l* H  N. Eprintf("sopen failed\n"); ! H, J, y; _4 y0 B; L  X; r" _4 I
exit(1);
7 G* I! P* F) Z* e8 _  t" }7 t} </FONT></P>7 c8 t1 L9 x' T0 e; j) @  H
<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); - O7 q: x: ~) ?
if (status == 0) 4 N( q, j# S5 l( Z  s% }* i3 V
printf("read/write access allowed\n"); 7 z( v( j2 Y5 I: q
else
/ z5 k: r7 D& T9 Q  J9 h! R( Kprintf("read/write access not allowed\n"); </FONT></P>
5 C0 Q1 N' M' h& D, F3 n" Q& u<P><FONT color=#0000ff>close(handle); * r% F+ s1 i) s0 Z
return 0;
! n$ y# V+ K& v4 F}
) u8 [1 j4 c5 ]; ]! `
# z& K) W" o2 _$ A# y4 m</FONT>8 b! k8 u& B4 ~" s) f
</P>
! ?7 z/ C/ Y0 E. ^) b9 {; X3 n0 J<P><FONT color=#ff0000>函数名: sound </FONT>
5 G+ r+ v7 F* R7 D( Z7 d4 G功 能: 以指定频率打开PC扬声器
, |% D$ e8 }# J2 x( a2 ?3 @. V3 n用 法: void sound(unsigned frequency); & T) V9 T8 I. g; t5 _) t# e2 l  b
程序例: </P>
6 K/ O4 g$ c, X/ d) I; Q<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds.
+ N7 v% W$ l2 s2 _" \' uYour PC may not be able to emit a 7-Hz tone. */
; j" a+ b6 R$ W, a9 N2 l#include <DOS.H></FONT></P>: n2 N! D0 |1 u: q% o" x/ h& G- F
<P><FONT color=#0000ff>int main(void)
2 s$ b, {2 y  v{
$ G2 A$ q" u6 Q# [9 i4 dsound(7);
0 {3 x' \8 [4 L/ H; q9 P! Y) f5 ?8 adelay(10000); ( {8 O% Y. |+ ?- J* C1 A
nosound(); 1 d8 \7 F0 C. j8 h1 P# ~
return 0; 1 }: [5 n' R* R; f
} </FONT>' m- u: l- v4 u  t% H& _
  p6 W/ \% X4 d3 C6 K
5 X2 a# H+ F, ^; k7 s4 r4 e
</P>
0 ^8 D. K+ B+ ~<P><FONT color=#ff0000>函数名: spawnl </FONT>: I2 p$ J9 c. g4 w0 G
功 能: 创建并运行子程序 & q: X. A1 c3 d( f6 h7 j) R1 q
用 法: int spawnl(int mode, char *pathname, char *arg0,
' s9 A& ]8 Z7 ~" @arg1, ... argn, NULL);
; T% r  {( R4 N程序例: </P>- Y( G1 J& L6 G3 {
<P><FONT color=#0000ff>#include <PROCESS.H>
+ p* W* x/ q; t- d#include <STDIO.H>
, C0 q% p- s( _8 G" t6 W* L#include <CONIO.H></FONT></P>
# ~; \, ?3 y8 O2 j' r<P><FONT color=#0000ff>int main(void)
$ E/ }2 h4 ~# B1 m  O7 j{
: Z3 G! q" B4 \: c$ U) J# xint result; </FONT></P>+ k) }! P) B, C3 v
<P><FONT color=#0000ff>clrscr();
; o/ K/ J; @7 f9 i3 I) F, S) Vresult = spawnl(P_WAIT, "tcc.exe", NULL);
1 F2 `; w: {' P0 Bif (result == -1) ) X# D; O7 l8 L  D* a
{ ' A( K) I8 E7 z3 I* \3 h
perror("Error from spawnl"); # y6 ?/ B1 g- I' x' |; x  H
exit(1); + u7 k& h/ H# G0 H4 a. C7 M# j
}
' {. S0 f$ r! Y) K& _return 0; ) r) w. O% P& P$ S: z; h+ j) M
} / @  N: ^4 Q' q  ~, l+ R
</FONT>5 z. F  [% ~: A
</P>
; R& r; e0 y4 r! S; h/ [5 B<P><FONT color=#ff0000>函数名: spawnle </FONT>
; i$ [$ y) Y; {; p0 B% C7 r8 T功 能: 创建并运行子程序 , m& [1 D- x9 S, b8 p- R
用 法: int spawnle(int mode, char *pathname, char *arg0, 1 _" W2 T& F1 R2 m% I3 N, b
arg1,..., argn, NULL);
1 _! }& U& [! U) f8 ]程序例: </P>
% ^. V. ]& E- s2 q/ Y+ _7 q* S' B: P<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>4 z* S4 q, Q# J0 E' X
<P><FONT color=#0000ff>#include <PROCESS.H>0 n2 Y7 }" A* L; ?7 F- ~
#include <STDIO.H>
$ F3 q0 i' |. y4 E4 m#include <CONIO.H></FONT></P>! m/ v4 ]  a6 w+ }
<P><FONT color=#0000ff>int main(void)
! J, W  }( ~" P; W, d{   H1 \3 {+ J/ `5 X" t5 M
int result; </FONT></P>7 k4 d7 {( N" B* M) m7 t
<P><FONT color=#0000ff>clrscr(); : ~0 i4 }2 n" u# P- {! ~
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL); 1 t- k5 V# D1 W, ~, t+ e0 m+ \
if (result == -1) ; |$ C3 B" N9 ^( F" g
{
( j! [* I' n% _6 d9 Y4 Aperror("Error from spawnle");
0 s; _- J/ Z: S% U2 gexit(1); . v& ~: b  M6 ]5 l2 n9 S6 y
} ) c+ I  s8 V+ w
return 0;
2 B  a/ t  p* V/ h}
6 y* }4 g5 J* x7 B3 v- ^/ d$ T. I! l$ x3 x7 p. s9 e* R4 A; P

; U9 z5 {$ }% [1 C9 h</FONT></P>% y+ N; Z/ Y4 }8 E8 X
<P><FONT color=#ff0000>函数名: sprintf </FONT>
- W4 J+ ~8 K) U/ }: N; }5 L功 能: 送格式化输出到字符串中 3 a; L  M% Z& Y$ j3 S$ X0 u
用 法: int sprintf(char *string, char *farmat [,argument,...]); 6 T) E7 `& V" R) Q
程序例: </P>
7 `* ?+ w- |% u: k" A9 m<P><FONT color=#0000ff>#include <STDIO.H>9 D! I  N  {* Y8 F8 g# c% z# M
#include <MATH.H></FONT></P>6 h3 H6 b* V; W! W3 N
<P><FONT color=#0000ff>int main(void)
/ P/ L, L. V3 v+ L: h{
( v; g: Q; L5 d: [' g2 hchar buffer[80]; </FONT></P>
& A9 _0 F6 f: T5 E+ b  b<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
6 E! n8 l  ]3 a+ d: E0 Vputs(buffer);
; J/ m% C1 e. r  |return 0;
0 h+ H4 |1 h7 _* I8 f}
8 c8 c/ S( q  H* \! N* z</FONT>0 B' c4 T4 _3 M- _7 e
</P>6 M* F  n/ m9 r9 q1 d' `
<P><FONT color=#ff0000>函数名: sqrt </FONT>
8 n; i, W; j0 `8 c6 H: B+ z功 能: 计算平方根 9 X) B1 N# S5 U" }4 s  G7 R
用 法: double sqrt(double x); 1 Q0 d4 |8 z2 y/ d# P/ [3 ~
程序例: </P>
( {$ X: _) J  J/ U, T& P<P><FONT color=#0000ff>#include <MATH.H>/ M! ?/ d6 z( X) I2 o
#include <STDIO.H></FONT></P>
# t* {- _2 x+ g7 G) t<P><FONT color=#0000ff>int main(void)
- e; n+ j# w. N  g* [+ G; |{
+ M7 x  J5 j6 c& C# \+ b' Idouble x = 4.0, result; </FONT></P>
2 d; l% ~; \2 u<P><FONT color=#0000ff>result = sqrt(x); , G  c# @! L! G6 M/ ~) \
printf("The square root of %lf is %lf\n", x, result);
  H  I: B  N" V# |. Ureturn 0; $ a& h5 ]( H  E! D6 a* e, c0 r& e
}
3 |* M% d1 q, D4 w. i! y" n- S4 q</FONT></P>
) W- q5 g& m& p% |, m# f3 e<P><FONT color=#ff0000>函数名: srand </FONT>
( F/ Z" S  U$ K功 能: 初始化随机数发生器 $ R* l: n+ t, a* u; p8 B6 T2 N
用 法: void srand(unsigned seed);
5 o. J$ @5 h7 t' h; ]程序例: </P>- ~9 p& ]) @7 u# @: Z. ]/ x) W9 p- W7 s
<P><FONT color=#0000ff>#include <STDLIB.H>' h; a( s7 ~" }& x: |4 |
#include <STDIO.H>3 @% c$ X: ]" y  z
#include <TIME.H></FONT></P>3 ^  z" Z$ E  Q( [8 {/ Y! n
<P><FONT color=#0000ff>int main(void) % Y- T/ O- N) |7 u4 {
{ 6 a& S: K5 r: A5 j
int i;
" Y/ a- R9 V; H1 `# htime_t t; </FONT></P>- _5 K6 C+ n4 \, I2 Y
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t)); . w0 v3 _' W5 m2 H
printf("Ten random numbers from 0 to 99\n\n");
5 U2 ?# W" d9 m9 d+ l$ ?for(i=0; i&lt;10; i++)
% c! w' O: a6 I5 {  v) Aprintf("%d\n", rand() % 100);
; `: t: Q% a/ O7 areturn 0; 6 M$ q, g7 \2 T: Y8 Q' W) F# I4 ]
}
3 P6 q; W% R( o' M- v</FONT>6 P" E: G+ b8 \3 ~* ]1 i7 [  l
</P>+ v& M0 ], u5 b5 {7 _- g
<P><FONT color=#ff0000>函数名: sscanf </FONT>
* e1 z& t6 _+ d( M0 i- f: ?功 能: 执行从字符串中的格式化输入
6 O) I; o( |2 m, O, S用 法: int sscanf(char *string, char *format[,argument,...]);
% v  u8 p' F/ y4 ~* v程序例: </P># x; E9 o) ?4 P/ A4 h
<P><FONT color=#0000ff>#include <STDIO.H>
; i. ^: l) U$ \* j& Y#include <CONIO.H></FONT></P>
) w# L7 W7 ~8 q0 ?) y* s6 S! j<P><FONT color=#0000ff>int main(void)
  @* w1 C7 |5 z( Y1 W( B{ 2 m5 }7 ]  B4 R4 n1 D( J# E: x
char label[20]; ) C. ^: e9 E6 I* \, H- P+ b
char name[20];
: M$ b; H' m- N6 Hint entries = 0;
3 q) z+ O; ^/ m8 b- ~  F+ Pint loop, age;
8 u/ ?0 H4 c/ p: Y( }+ e: Gdouble salary; </FONT></P>
! c- R1 }7 J) H5 X; V: [<P><FONT color=#0000ff>struct Entry_struct
+ I8 y4 N& G5 H- O' m{   i7 o- e4 t. _# U; R
char name[20];
/ J2 @4 d5 I: j/ Y8 a6 ]int age; " z# c  e# R4 v, a
float salary; 7 R& E2 |  L5 v! B$ j; \% W; |. f! J1 K0 G
} entry[20]; </FONT></P>3 f' l; C* p' B- [! C+ w
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ 0 Z$ }& O- R& u* H( H7 k( Z
printf("\n\nPlease enter a label for the chart: "); * Y+ n! _+ L3 o8 l7 T
scanf("%20s", label); : s- R/ M% C5 X+ M" Z; o  v& f5 i
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>3 N9 W* `! R+ v: G( o0 \
<P><FONT color=#0000ff>/* Input number of entries as an integer */ $ F% K0 X9 _1 n
printf("How many entries will there be? (less than 20) ");
4 R1 F0 ^; \2 N- o% x+ hscanf("%d", &amp;entries);
( k' w$ i! ~, D7 r% }1 ?4 r: X, vfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>) @' G6 d/ l% e
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ 1 M$ Y, P$ B9 ~) q1 X
for (loop=0;loop<ENTRIES;++LOOP)
$ Y; T! h. k4 o { 5 y; Y8 x" p- H
printf("Entry %d\n", loop);
& y% D+ O8 l: W6 h+ l( o8 u2 Nprintf(" Name : "); 9 B# u# U6 C: u# ^& `# a
scanf("%[A-Za-z]", entry[loop].name); 3 P( Q" j" ^; {
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>. |: h( K4 W7 p- S! ]+ o& ]6 [
<P><FONT color=#0000ff>/* input an age as an integer */ . n2 u4 z5 j7 r3 ?. b5 y. t. |$ k
printf(" Age : "); 4 k) L8 G, G3 \( e6 s' z* x
scanf("%d", &amp;entry[loop].age);
% e+ o0 o- X& u  v1 F3 ^/ }# W/ bfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
$ \2 T4 m! Q/ w  g3 b<P><FONT color=#0000ff>/* input a salary as a float */ * s2 t/ p7 K$ Q$ g3 V* h  k* w
printf(" Salary : ");
  X2 H" `: N) b" U% uscanf("%f", &amp;entry[loop].salary);
) o) @# d# F  e# {fflush(stdin); /* flush the input stream in case of bad input */
- m9 U1 }! }7 K1 x} </FONT></P>' F* p* i3 f0 \- R
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
1 I+ ~) o! p& Gprintf("\nPlease enter your name, age and salary\n"); 3 C3 g' y, }: r% s" y% ^
scanf("%20s %d %lf", name, &amp;age, &amp;salary); " [6 |: {. {& @% p
</FONT></P>
: d: R+ B6 O4 n1 v<P><FONT color=#0000ff>/* Print out the data that was input */
  ]# E% ]$ v! O/ J/ lprintf("\n\nTable %s\n",label);
! I9 V4 V" c# ^7 i- c1 {printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); " x6 G9 m) r$ a9 A' ]8 \
printf("-----------------------------------------------------\n");
9 t9 X+ T( m4 R/ {* t" y# \4 T& o( ]for (loop=0;loop<ENTRIES;++LOOP) 4 {9 o8 ?" Q' p8 Q( V" w
printf("%4d | %-20s | %5d | %15.2lf\n", 9 v+ v; G5 S" D+ l- ^8 r$ s1 g
loop + 1,
: f5 _7 e$ [) I2 {$ U, q( gentry[loop].name,
( }; {  T4 f% G# ?entry[loop].age,
& P+ ^0 O5 x) U+ l) Lentry[loop].salary); ' l5 _2 C4 s8 n5 I: c0 h2 S& `' j! h
printf("-----------------------------------------------------\n"); 2 G% P8 W6 \  i5 R
return 0;   w8 w9 c: ]0 [$ `8 ~- C6 M+ C
} ) C! G' l$ Q  y4 E& Y$ y

1 ?$ D/ H% i3 _- ]/ T</FONT></P>0 l8 l8 l( R+ }
<P><FONT color=#ff0000>函数名: stat </FONT>5 `6 u, N& P, _4 K
功 能: 读取打开文件信息
  Q  ^5 U) w( g* j; P% q/ [4 I用 法: int stat(char *pathname, struct stat *buff); 9 R- X" Q  v: q
程序例: </P>
- z# y; h" y6 v<P><FONT color=#0000ff>#include <SYS\STAT.H>4 [# f& y6 i+ D: @" z
#include <STDIO.H>
9 U/ I  V4 O5 w, o/ R#include <TIME.H></FONT></P>
1 v1 i4 L- }  H7 @" L<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>* R/ K6 U7 T: R! J
<P><FONT color=#0000ff>int main(void)
5 l7 {5 S  J6 h9 O1 j* s& Z{
6 N4 |7 F# V( z8 M9 ]( k% F0 Wstruct stat statbuf;
" d5 [* }+ x3 }( q2 kFILE *stream; </FONT></P>
$ p  E2 H7 n( N4 }+ H<P><FONT color=#0000ff>/* open a file for update */
+ k  y+ g$ M6 Nif ((stream = fopen(FILENAME, "w+")) == NULL)
8 Y8 }) L# I( V8 r# P{
* O$ m: }- Q/ ?fprintf(stderr, "Cannot open output file.\n"); # W- [0 d+ d, }- ~2 p
return(1);
* `0 e8 v) {& O# ?( h4 ^1 g8 o} </FONT></P>) k0 J6 R- E7 A& w, q! U  @
<P><FONT color=#0000ff>/* get information about the file */ - f( ]6 B; Y: A
stat(FILENAME, &amp;statbuf); </FONT></P>; _" t. T! D* [5 k) P6 u
<P><FONT color=#0000ff>fclose(stream); </FONT></P>
6 h6 b" D& y, q+ t8 Y6 J1 }<P><FONT color=#0000ff>/* display the information returned */
" n8 d+ |$ a; B2 T. f6 H$ Kif (statbuf.st_mode &amp; S_IFCHR)
5 H( L9 q# a6 k2 h, Y2 U3 Rprintf("Handle refers to a device.\n"); & p! w2 v0 D0 S5 R$ m
if (statbuf.st_mode &amp; S_IFREG)
. K+ `0 S" p  t% ]1 L3 lprintf("Handle refers to an ordinary file.\n");
. b9 I( Q" y: V8 sif (statbuf.st_mode &amp; S_IREAD) 6 l2 h$ V3 k4 J, ?6 P, t
printf("User has read permission on file.\n"); + `. q4 ?8 l) Q
if (statbuf.st_mode &amp; S_IWRITE)
9 ?( S6 ^& ~; r) fprintf("User has write permission on file.\n"); </FONT></P>5 K5 k! \  T0 ^$ R1 l
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); . K9 V# b9 {1 G4 k. B% m: ?) J
printf("Size of file in bytes: %ld\n", statbuf.st_size); / e* a  W9 m4 B. t
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime)); $ [7 }! u  ^9 ~7 R) P
return 0; 6 i) O1 J# Q0 G4 X8 i' ^/ N1 h
}
$ l9 D+ d+ q+ \$ d' H, j6 {% Z/ k7 R1 M% F- m
</FONT>
3 `4 M4 l, C: |  @, D! i2 n; V5 \</P>* c; a6 O; g6 {+ ^! X" H
<P><FONT color=#ff0000>函数名: _status87 </FONT># {- f/ L: X. ?3 R% I4 h" i
功 能: 取浮点状态
7 }  V: s+ |3 ^' }5 ^" x& ^用 法: unsigned int _status87(void);
. G* n3 P; x( M0 ^$ ?- \程序例: </P>% ?2 o* e$ T/ N! Z7 m3 R
<P><FONT color=#0000ff>#include <STDIO.H>
2 T2 u' C7 N1 R; T1 k#include <FLOAT.H></FONT></P>
; t8 ?  K- x7 n* ^. L# c) A+ ]$ N<P><FONT color=#0000ff>int main(void) ! B; Z) E( m  d2 H9 m3 Z
{
( F; r; {5 S: Z6 Cfloat x;
- \- r) f& D9 Z7 r3 y1 {double y = 1.5e-100; </FONT></P>
' \& _' R. k$ r4 r4 K<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>( x8 |( D( k: t; F
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
0 _( t4 B( d/ D0 B" Yy = x; </FONT></P>5 m: D* ?1 i& y" }; r
<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
# C1 X; ]6 ?( ^+ y$ j; ?return 0; 0 X7 N: F' V- b: A0 h: {$ Z
} 3 y! v& n4 Q( d4 N( j( b6 H  d
</FONT>  n3 U4 L" B2 y' R' G+ ]! z
</P>
1 w) }7 T9 v  Y- F& N<P><FONT color=#ff0000>函数名: stime </FONT>
" G5 N& Q% [0 _" L5 K& m" k功 能: 设置时间 $ m( t+ c; Z  ?6 u
用 法: int stime(long *tp); ; t( ]4 @: F6 L# r  |, }0 u
程序例: </P>
5 ?" E$ j: Y' C. I<P><FONT color=#0000ff>#include <STDIO.H>
5 r2 C- d% W" e) g& b: \#include <TIME.H>
7 P' ?3 ~! f8 n6 q$ D1 {1 `#include <DOS.H></FONT></P>5 z9 P4 `5 C' X4 |5 n- {
<P><FONT color=#0000ff>int main(void)
( r' p* K5 O/ b( I0 `{ " z5 r5 W% z" V- v- X0 b( ?9 K% f
time_t t;
) S0 C+ }% t( G, T3 X1 M6 t$ Rstruct tm *area; </FONT></P>
1 \! c1 u3 d% M. O<P><FONT color=#0000ff>t = time(NULL); ; V3 R% I! ]2 \* I8 R
area = localtime(&amp;t);
$ ]; q! G3 ~8 sprintf("Number of seconds since 1/1/1970 is: %ld\n", t); " Y8 f% J% l8 v' U& u
printf("Local time is: %s", asctime(area)); </FONT></P>: b2 J. H( k& b2 W& _
<P><FONT color=#0000ff>t++;
. T# b* y1 X+ k& o# T1 ^+ V# D$ farea = localtime(&amp;t); / w# D4 R7 x0 t$ L1 L# g) {
printf("Add a second: %s", asctime(area)); </FONT></P>: N& j. t$ ~* }, {7 J
<P><FONT color=#0000ff>t += 60; 5 J* j% j5 C% I. V, }  @
area = localtime(&amp;t); # O  ^. y* |; f  v7 i! d
printf("Add a minute: %s", asctime(area)); </FONT></P>
/ r! ?. y8 y+ }4 L) y<P><FONT color=#0000ff>t += 3600;
  T. H( W/ |1 ]* b* _area = localtime(&amp;t); ' E* D. g% x7 N7 ^
printf("Add an hour: %s", asctime(area)); </FONT></P>; S* x; C# c: n- a# ~1 t. k
<P><FONT color=#0000ff>t += 86400L;
# E2 E2 f* T) z% T( n$ U9 h1 carea = localtime(&amp;t);
4 T+ ^/ r5 C& o3 Q# r, i; [printf("Add a day: %s", asctime(area)); </FONT></P>
- x. j+ w$ Y3 d- U7 K, _<P><FONT color=#0000ff>t += 2592000L; $ j& L& n2 H9 ?7 t8 V% m  G
area = localtime(&amp;t); 0 v7 K- ]  U# F/ M/ Q
printf("Add a month: %s", asctime(area)); </FONT></P>. Y! B+ N5 ]* P9 |: w- ^
<P><FONT color=#0000ff>t += 31536000L; ) [- x0 {6 D+ D
area = localtime(&amp;t);
/ `) g3 G6 {- p) d& h/ n3 Fprintf("Add a year: %s", asctime(area)); - G4 a  _2 M0 o) a$ w4 Z
return 0; 2 o3 H0 X' K2 V$ T  {2 B
} </FONT>
* {2 b" B9 H6 w0 v6 g7 k# T7 _+ Q: v- }; d1 H( S: w# `+ B

% p2 y$ }2 S" L- g9 W& G7 S</P>
  K7 B7 k4 T0 o<P><FONT color=#ff0000>函数名: stpcpy </FONT>
* R8 V2 f& k7 r7 V3 M8 L2 P9 b, F功 能: 拷贝一个字符串到另一个
! L8 z9 F1 W4 C' s9 Q用 法: char *stpcpy(char *destin, char *source); # }* p1 X( |* c$ z
程序例: </P>4 t0 i  y3 d: C* `9 [# P, J
<P><FONT color=#0000ff>#include <STDIO.H>
4 b* E3 P$ F8 _2 Z8 h; z6 d6 W6 [#include <STRING.H></FONT></P>  m, f, f7 p  F" W: g) |
<P><FONT color=#0000ff>int main(void)
3 y  d3 p& @. P, ^# n{ % D# b) i/ a: H6 x: Q8 t: Z
char string[10];
% m2 [7 |: }. s' Echar *str1 = "abcdefghi"; </FONT></P>
3 Q* o" M$ h, N$ t) F* [. s<P><FONT color=#0000ff>stpcpy(string, str1); % k1 u5 K! G* K
printf("%s\n", string); . Q# }) k/ ]  w# @
return 0; # T/ R7 E6 k* k& P2 r. D
} ! d# c# _3 r( v" g7 O
  g1 j7 N+ y" S2 @$ Z& c6 B
</FONT>
3 N6 Y; N( U$ {& R0 C5 F</P>
0 k' i9 a; b7 j/ A<P><FONT color=#ff0000>函数名: strcat </FONT>
6 y: z) W6 A/ ^) D8 x: c# J/ a功 能: 字符串拼接函数
  V1 k' q, M- ]! j用 法: char *strcat(char *destin, char *source);
5 q) r% @. v0 _* ]" `! n# Q/ ^; F程序例: </P>
3 f" l9 W9 |$ o/ `1 d- W<P><FONT color=#0000ff>#include <STRING.H>4 q) t1 `0 I3 h8 l6 R2 j
#include <STDIO.H></FONT></P>2 Z. v0 V# y8 Q0 \' {
<P><FONT color=#0000ff>int main(void) 7 H( y' r+ u$ z  E, a7 T# F
{
. b. S$ E/ ?; U) h8 s1 A+ R* N. ]$ F0 tchar destination[25];   D7 O$ w+ F' b/ _9 o
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>- [$ V! ?; W2 c  ]' F( p
<P><FONT color=#0000ff>strcpy(destination, Borland);
+ _& I7 C/ ~7 C$ {& Y! {* _) m+ ^strcat(destination, blank);
# ?: ]+ W4 v' V0 c/ kstrcat(destination, c); </FONT></P>
& P) \' _- X3 O% D- i7 _, X4 u9 ]<P><FONT color=#0000ff>printf("%s\n", destination); 8 o4 h6 H, _4 i/ s
return 0; ! l; T( p) U0 Q& d; a2 q. ^" _/ g
}
& z9 ?+ D' \) p) i7 M/ C
1 h3 @, `# M& V2 t0 N" x; F& _( J</FONT><FONT color=#ff0000>
4 F& ~3 j% p$ p</FONT></P>
. z9 h; f! D2 {2 k<P><FONT color=#ff0000>函数名: strchr </FONT>
- J+ o9 u" {: r* {: c" B功 能: 在一个串中查找给定字符的第一个匹配之处\ : K% z3 ^0 v, g
用 法: char *strchr(char *str, char c); 2 |1 p2 C. @! [, T$ w8 b
程序例: </P>9 k$ Q# f; c( @+ N$ L- ?; S5 ]
<P><FONT color=#0000ff>#include <STRING.H>
6 R5 |! r# d" b+ |#include <STDIO.H></FONT></P>
& ]& S- N) W/ q, ?0 ?  A<P><FONT color=#0000ff>int main(void)
1 F: R$ E  k( E  I1 o0 P+ d: P{
9 i3 v9 p8 w( E- Z( J6 F, `char string[15]; 0 F3 U& R* [: S2 b' x
char *ptr, c = 'r'; </FONT></P>: P; e( w" G8 S; s" l
<P><FONT color=#0000ff>strcpy(string, "This is a string"); 4 n# f' }4 }* k; K* H& G
ptr = strchr(string, c);
  D) d. E5 x; K  v$ \/ ^if (ptr) * L3 }' a2 h3 B
printf("The character %c is at position: %d\n", c, ptr-string); & m: [! M3 P  p  Y
else
* B9 S* M/ l0 o6 J/ tprintf("The character was not found\n");
8 ~# P( z+ f5 B/ Q1 `/ b, B% y, @return 0; 4 c$ b/ {1 L: |
} 2 E' I4 q. k8 M! x6 D  }
</FONT>
. _7 U+ r$ L* @% F: m
/ R: h! c* E) @$ \* K</P>
2 \; w* R5 y. C5 R4 |0 I<P><FONT color=#ff0000>函数名: strcmp</FONT>
5 R  \& L2 }3 b功 能: 串比较
" i/ ~7 k! f4 O0 u* b用 法: int strcmp(char *str1, char *str2); $ p- d# t) ^4 Y2 _5 X2 N
程序例: </P>1 c4 p* [# ?( G( {/ C
<P><FONT color=#0000ff>#include <STRING.H>
1 H7 D- c9 c, T2 c! D#include <STDIO.H></FONT></P>
) w2 G( O# B6 F* E2 p<P><FONT color=#0000ff>int main(void) 1 I1 I- z* B+ r: `. c+ n+ O
{
" T% W1 \. o) o+ O( c& P9 p/ [char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
' |$ j6 }5 q3 W* v' pint ptr; </FONT></P>; w5 T) [! p" V/ y6 g
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
( y' [& V9 E% A$ Uif (ptr &gt; 0) 6 k) z) F) H" w# D
printf("buffer 2 is greater than buffer 1\n"); " G' v( D" z7 U% S6 I  l/ _
else
* K" w3 }! ~1 S* p: g( Z  gprintf("buffer 2 is less than buffer 1\n"); </FONT></P>- d- A+ b3 ]2 R5 }+ B/ U
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3); 9 H9 F2 J5 A% X  C4 `9 n
if (ptr &gt; 0) * [2 U0 L! N0 L; G
printf("buffer 2 is greater than buffer 3\n");
4 Q, P6 ^9 _" n, r9 P5 X8 ?3 kelse + R9 p5 X6 O- N( i) `3 K% n
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
- l. }* }( @5 f0 Y5 }0 T& s6 h<P><FONT color=#0000ff>return 0; ( W8 y2 P: Q9 J  ]
}
# S- }" z5 O8 E, e/ P* R
* Q! O+ U) O- m! k- G
" O4 Y4 x  l$ Q</FONT></P>) q7 y1 f. a0 @5 ~" `# U
<P><FONT color=#ff0000>函数名: strncmpi </FONT>% O3 M: ?7 j! r) C, t4 q& k9 ~  h
功 能: 将一个串中的一部分与另一个串比较, 不管大小写 + o( x0 v7 v- L) n! p# C/ U
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); % L+ y7 P+ q, I) Y
程序例: </P>
; v, d# p' `( y' B<P><FONT color=#0000ff>#include <STRING.H>6 O0 B" c6 v$ g3 r: ~# ~
#include <STDIO.H></FONT></P>
: N4 l5 z4 ~. k% A( v<P><FONT color=#0000ff>int main(void)
: h6 u/ E8 q$ ^; |{ & m; K) [1 b; x
char *buf1 = "BBB", *buf2 = "bbb"; . g# V, E/ w/ z( i
int ptr; </FONT></P>  t5 C, W. v. V9 a! Y9 b3 t
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>! \7 b$ a9 _; I! F/ X3 c) U. j3 t
<P><FONT color=#0000ff>if (ptr &gt; 0)
( w, {' J* X* W, Q& }printf("buffer 2 is greater than buffer 1\n"); </FONT></P>7 J' `; W% v  T" e4 a. |
<P><FONT color=#0000ff>if (ptr &lt; 0)
7 {9 G8 n" N% j* s, e" d5 ?printf("buffer 2 is less than buffer 1\n"); </FONT></P>
" V( l" C1 x" [+ c( p. l7 ]' A0 C5 N<P><FONT color=#0000ff>if (ptr == 0)
/ d8 g( W. N8 H+ n6 r2 B; y! Pprintf("buffer 2 equals buffer 1\n"); </FONT></P>
) f7 K4 I* |7 ~+ L<P><FONT color=#0000ff>return 0;
* {3 Q# m" Y: d& _4 |, B}
5 Z1 ~) Y% d6 O8 i  r4 ?
1 m  e8 g- Y9 ^( F5 Y</FONT>3 s0 M/ n! f& |
</P>
6 {8 [) R% i% G3 i4 F<P><FONT color=#ff0000>函数名: strcpy </FONT>2 G1 Q0 F* t" w
功 能: 串拷贝 + O- Y2 t9 X: u/ t1 a
用 法: char *strcpy(char *str1, char *str2); . _# [6 X7 L0 q7 S0 `6 W
程序例: </P># v8 r2 `/ o& o
<P><FONT color=#0000ff>#include <STDIO.H>) R1 e0 x: }. A, r8 {- t
#include <STRING.H></FONT></P>: r7 w! j( ?. Y, I+ g
<P><FONT color=#0000ff>int main(void) 9 ~; H9 Q& A- Q0 t3 @
{
  i7 U* e* j3 u& X! M& L, P$ q6 e% qchar string[10];   N1 R5 A+ C( ?, n0 w3 }! k1 |, z
char *str1 = "abcdefghi"; </FONT></P>" N% l0 S+ K" R; I- m- O& C4 L
<P><FONT color=#0000ff>strcpy(string, str1);
% U8 z, {( N* w  R% _% {printf("%s\n", string);
4 g4 |% {4 X1 o/ ?: ireturn 0;
, h9 J$ b. F+ f& q/ L}
: J. a4 g% r) Z" N( B</FONT>
1 g$ E4 K  `4 U9 t& A* d* @# m& t( |8 `. \* X7 B
</P>  A+ U. _& ]/ m! D# `& V
<P><FONT color=#ff0000>函数名: strcspn </FONT>
8 |) m& r2 [; y% P" V功 能: 在串中查找第一个给定字符集内容的段
% Y; `! h' W8 K+ K  R& H用 法: int strcspn(char *str1, char *str2);
  N8 x$ q/ ?5 \* [- w5 P程序例: </P>' ^- B. k4 P8 H8 {% a- m/ D" x' R
<P><FONT color=#0000ff>#include <STDIO.H>
" I- V9 h0 f+ M4 `#include <STRING.H>7 }# B& K+ t% m' d& {1 X
#include <ALLOC.H></FONT></P>
& \2 N$ E  q% d2 T+ r<P><FONT color=#0000ff>int main(void)
0 U3 d$ M6 K5 e0 Y* O1 w6 ?& u{ . q6 y$ a' O- U& o2 V0 g2 j7 G
char *string1 = "1234567890"; , m) e; f+ S' ^& N! Y( Q# Q
char *string2 = "747DC8"; : Y, i5 ~& W# o9 D
int length; </FONT></P>
! |( f* x9 Q, o4 F3 ?- w  }<P><FONT color=#0000ff>length = strcspn(string1, string2); - j( ~' k7 \7 }' |. [: q
printf("Character where strings intersect is at position %d\n", length); </FONT></P>
$ T) h1 i% r3 c5 g7 w<P><FONT color=#0000ff>return 0; 1 O! g) w  O  c6 d8 k, A
}
2 e; u2 }7 e, V! r  F+ H</FONT>
. {  Q  z' r8 T0 c4 s! P8 e$ r  P! L# w/ q0 k, v/ ~
</P>
& |* R2 K" `5 o" p2 N8 u<P><FONT color=#ff0000>函数名: strdup </FONT>2 s7 r! h9 k8 ]1 J7 h1 I2 E$ [
功 能: 将串拷贝到新建的位置处
+ [$ t/ R1 F) c) N; `0 @用 法: char *strdup(char *str);
) O5 E1 U! X  O2 c4 G程序例: </P>2 M& V# E5 ^: t4 F; F$ M2 ?; ]/ I
<P><FONT color=#0000ff>#include <STDIO.H>
6 V: j! o% V5 R9 {#include <STRING.H>
/ h5 W; U- q+ S/ M$ S! I9 o3 L, R4 }4 p#include <ALLOC.H></FONT></P>
2 g  y5 ]. e( t- G  T! H" i6 n: C<P><FONT color=#0000ff>int main(void)
4 I# p  Z% o* y3 |/ E5 G{ 9 c* N* \$ l) _8 o  Y9 d0 m
char *dup_str, *string = "abcde"; </FONT></P>8 I% }& g! P+ Y# L) {8 T
<P><FONT color=#0000ff>dup_str = strdup(string); . J- k8 P0 Y& Z; R$ x
printf("%s\n", dup_str); ) Y: \3 I/ m- n! [+ P. t6 U
free(dup_str); </FONT></P>
7 ~. u! c) v4 g% D5 s5 ?' m<P><FONT color=#0000ff>return 0; . d; v; I) V0 ?. w' @$ ~
}
/ |: ?/ p. Y0 r  X! Y4 c) X7 Y; a2 L/ v
</FONT>
  i* @5 b, w+ n) \/ r/ @</P>6 d3 e* ?7 `: D+ C7 b9 V
<P><FONT color=#ff0000>函数名: stricmp </FONT>
+ D: g- r3 D! N功 能: 以大小写不敏感方式比较两个串 , Q: b7 r+ O7 H0 b5 i" g
用 法: int stricmp(char *str1, char *str2);
$ U4 Z4 ]  P! S# F  H4 ]2 S程序例: </P>! d* U; p0 i7 Y* j
<P><FONT color=#0000ff>#include <STRING.H>
4 ?5 k( _0 ]0 f( X* |3 J( x- n% _) y  c#include <STDIO.H></FONT></P>
% e& I; D- W. P0 h2 u( ~<P><FONT color=#0000ff>int main(void)
' l2 q7 j; f6 W{
* ^  D6 W5 k$ B- E1 y# Hchar *buf1 = "BBB", *buf2 = "bbb";
0 e6 `2 A% w: T2 Q' Qint ptr; </FONT></P>
1 v3 m: y5 W/ P$ q<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
# y# K& Y7 @$ {0 g) E<P><FONT color=#0000ff>if (ptr &gt; 0)
4 X; j$ w" T8 d; a7 Oprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>/ q& p4 ?7 n4 {; ^
<P><FONT color=#0000ff>if (ptr &lt; 0) 6 P7 o& e9 I* ?$ o
printf("buffer 2 is less than buffer 1\n"); </FONT></P>2 p" F1 i2 F7 R
<P><FONT color=#0000ff>if (ptr == 0)
& E: b/ w; z7 X; {0 D5 e+ c" U4 dprintf("buffer 2 equals buffer 1\n"); </FONT></P>. U1 ~; v& v$ e
<P><FONT color=#0000ff>return 0;
- I9 N/ X- O9 X) E}
% V8 W, ?1 S6 X& I" Q7 Y( q</FONT>0 z7 Z, D2 k- Q7 |
</P>
, I6 }- k8 K- W: N; q! ^6 {- l, E<P><FONT color=#ff0000>函数名: strerror </FONT>
9 v4 h# D! S  g0 l* S功 能: 返回指向错误信息字符串的指针 , P' m, c1 J+ Q1 w" i( c7 I" g
用 法: char *strerror(int errnum);
5 Q* V5 q  m/ o& H# ~程序例: </P>
" d' h& H, n' D, N6 o<P><FONT color=#0000ff>#include <STDIO.H>$ e. I) m# o7 C: X' t/ z6 f
#include <ERRNO.H></FONT></P>3 N7 y- Y( E9 g- C
<P><FONT color=#0000ff>int main(void) ' z' k. h0 }$ X/ [2 F% L& U; m& ]- J
{ 5 X  g" h3 k1 a% M5 a3 U1 c
char *buffer; 2 B- s- A5 Z( H9 g
buffer = strerror(errno);
5 [7 \# j9 h8 nprintf("Error: %s\n", buffer);
' d1 ]: Z5 s, Z+ A8 greturn 0;
& M4 k1 p* v3 c- R( {: j8 H. k} 0 \8 s* T. \) l, @  N: i% i
) A8 T. j. S3 B# X% {/ P
</FONT>
2 X2 Y7 C9 Q- [( \  M5 P</P>
- z" r: V1 ~0 \# _9 U2 z/ o<P><FONT color=#ff0000>函数名: strcmpi </FONT>( D1 p' f& `7 L2 |( e# l7 X
功 能: 将一个串与另一个比较, 不管大小写 2 G6 l! Z, X$ U/ `! _$ e5 m
用 法: int strcmpi(char *str1, char *str2);
! J: E1 [! D! \$ G程序例: </P>6 M# L! L) ?! r# H6 |) \
<P><FONT color=#0000ff>#include <STRING.H>* |" M) b* E3 C
#include <STDIO.H></FONT></P># u$ g% h/ u5 J5 H! k* Q% y6 l) p
<P><FONT color=#0000ff>int main(void) 3 h4 p. G' i, l+ a" X+ k- o
{
1 f2 E2 E- I) X1 [" E0 m$ zchar *buf1 = "BBB", *buf2 = "bbb";
: G  q2 E7 g0 |( K. x2 P; c' r" Wint ptr; </FONT></P>
/ A3 [7 o, z: ?, N% S% X. r<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
. X+ E4 h$ ~/ Q$ z2 x& [<P><FONT color=#0000ff>if (ptr &gt; 0) & K+ U: d; U5 [. e- s
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>: j( y/ Y7 c0 V- r* J
<P><FONT color=#0000ff>if (ptr &lt; 0) # c7 s% ?, h& L) K9 L
printf("buffer 2 is less than buffer 1\n"); </FONT></P>6 T" A" a( a1 F- q
<P><FONT color=#0000ff>if (ptr == 0)
3 A" u8 |5 g: U( \, Q2 S- Qprintf("buffer 2 equals buffer 1\n"); </FONT></P>6 W2 C7 U+ t4 O
<P><FONT color=#0000ff>return 0;
: d5 ~  j. J$ s( Y4 h( `} " B* C. Y9 v6 M. E3 V
</FONT>
0 O. M; m- |/ ~, F
# o; }' K* f$ K/ P</P>  A. W$ [$ Z; ^8 x% O
<P><FONT color=#ff0000>函数名: strncmp </FONT>$ P6 p3 E9 `* j. Q1 l6 C
功 能: 串比较
1 D$ W. D) i* C7 x: ^用 法: int strncmp(char *str1, char *str2, int maxlen);
2 i8 Z4 q* E- d( X程序例: </P>& e1 t- m" K* p  ^  u+ Z+ g
<P><FONT color=#0000ff>#include <STRING.H>% q$ p% @, g* C) G+ a
#include <STDIO.H></FONT></P>
" f+ m! P7 L& ?8 F, h/ T* w3 H<P><FONT color=#0000ff>int main(void) </FONT></P>
0 f- z8 V0 t5 j" `6 w! a1 I<P><FONT color=#0000ff>{
# n% `0 M2 p7 n$ c5 Schar *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
$ A6 n% `* b+ |' y/ \! Dint ptr; </FONT></P>
% n, E' L0 u- j, b$ \9 t  [<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3); , N& g% }& D0 P0 h
if (ptr &gt; 0)
9 p, T* [3 M7 G5 |printf("buffer 2 is greater than buffer 1\n"); " v9 O  c% b" \( ~- @
else
# ^+ y2 |: P- `# H8 O5 ]printf("buffer 2 is less than buffer 1\n"); </FONT></P>
5 U9 x' [0 Y& e9 U0 d<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
) O" g# F+ x9 ~/ _if (ptr &gt; 0)
" H! g1 C( s; j9 h8 V. |: J  I; jprintf("buffer 2 is greater than buffer 3\n"); ' h% B* h1 Z( n# K& z6 k5 C' [
else * n, O& `+ e6 q! Y7 d0 r
printf("buffer 2 is less than buffer 3\n"); </FONT></P>6 s% n) [4 E( y" _
<P><FONT color=#0000ff>return(0);
+ a$ J3 X. V5 x: Z  ^- a9 G}
; ~. p1 R$ r. J, `' R# i/ o3 p' M4 f; {
</FONT></P>
7 p# o) o, o/ Y* \3 |  _- L( j<P><FONT color=#ff0000>函数名: strncmpi </FONT>
. M. ]' y" |+ S/ R4 i3 h' A+ `功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
6 R5 y! l7 ]1 v: |6 z& P5 t: s8 I; `用 法: int strncmpi(char *str1, char *str2);
% [3 h( R( B3 \+ p, }- D程序例: </P>4 ~5 w2 d; ]3 c: ?* l
<P><FONT color=#0000ff>#include <STRING.H>
! _6 P& t+ i" ?# `) l1 P9 O8 U) C#include <STDIO.H></FONT></P>
4 ?& x& h( x4 i& Y( s" o/ Z<P><FONT color=#0000ff>int main(void) 8 J4 C& |9 B# {
{ 9 k# S2 O. m+ j. g. n
char *buf1 = "BBBccc", *buf2 = "bbbccc";
# Q3 `+ @) L: ], Tint ptr; </FONT></P>
5 J! Y& p1 O  A" e<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>( a% ~8 A  i( l# w. f" J8 F$ |( o
<P><FONT color=#0000ff>if (ptr &gt; 0)
% \  w; n/ b. uprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
4 c" y2 C' X6 D7 Z: h& M9 r<P><FONT color=#0000ff>if (ptr &lt; 0) 6 i# l% m6 u; C2 i& u. i
printf("buffer 2 is less than buffer 1\n"); </FONT></P>1 ?% f' F/ A9 m9 e
<P><FONT color=#0000ff>if (ptr == 0)
8 o  v% {9 m, h1 D- l, Y( sprintf("buffer 2 equals buffer 1\n"); </FONT></P>
* K& u1 R! x; Y% ~7 w& N$ L% m<P><FONT color=#0000ff>return 0; </FONT>
9 M3 O( |; W5 ~% Q1 ]) r} / ?$ S$ p2 W' t( \% F  e

4 ]0 x8 U( T5 D; x& F  @' c</P>
& U1 t# W8 e* v* f' e<P><FONT color=#ff0000>函数名: strncpy </FONT>' J2 J6 |8 E- S- J1 M0 g+ f8 ~
功 能: 串拷贝
: z  E9 h0 X7 d& E$ E用 法: char *strncpy(char *destin, char *source, int maxlen);
; {1 i. b. l, {7 ]8 s8 }. X程序例: </P>* V& D7 w2 f; h
<P><FONT color=#0000ff>#include <STDIO.H>
. o0 J- R5 T) C9 O. H0 s#include <STRING.H></FONT></P>
% d1 R9 b0 I3 \3 i+ f8 p<P><FONT color=#0000ff>int main(void) ! D: t  B5 p, g- B/ i
{ 5 d" j: F' g* O5 p
char string[10];
( s$ Q4 b! B: @( ~5 Y+ \char *str1 = "abcdefghi"; </FONT></P>
  b2 H8 {4 F5 x<P><FONT color=#0000ff>strncpy(string, str1, 3);
4 K/ l9 A+ e, c2 K- t. q$ fstring[3] = '\0'; ; |  R" Z  ]( Y" j& c4 s+ J
printf("%s\n", string);
9 H$ `. y* U# f$ n3 F. f! Vreturn 0; 5 Y: _3 }! s) K3 E
} $ D5 x* R& O8 X3 V& P8 `2 g$ h& z
</FONT>* Z9 A( {; z, }6 Q  M& ?( r9 u8 V
</P>
* i1 v! l6 ?) [, ~5 C/ I<P><FONT color=#ff0000>函数名: strnicmp </FONT>
3 W1 y& D7 r* _' w2 C; L  d( N8 C功 能: 不注重大小写地比较两个串
3 r5 X# N4 _* h用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
# v9 `4 p: m* t+ D2 z1 z# O' c! r9 ?程序例: </P>
+ d# g; M5 L, o, ~<P><FONT color=#0000ff>#include <STRING.H>* c; p9 s/ }! ^2 P" C6 ~1 O4 y
#include <STDIO.H></FONT></P>6 k& F  n6 M/ b- }! d
<P><FONT color=#0000ff>int main(void)
1 c7 B. l6 g# r2 S, f, Y{
7 ]7 [# H9 L) y; Kchar *buf1 = "BBBccc", *buf2 = "bbbccc"; / C; Z4 Z) O* }6 G( ^+ |' }! V9 @& ]
int ptr; </FONT></P>" h$ w/ B2 H: n
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
# E" ^! p0 g% j- J. z<P><FONT color=#0000ff>if (ptr &gt; 0)
- B8 G; l  O7 C( hprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
8 s4 O6 F$ ?4 b( A<P><FONT color=#0000ff>if (ptr &lt; 0) " |: u, q6 i* D' ?3 f
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
5 D3 ^$ E8 `2 ^: }# s<P><FONT color=#0000ff>if (ptr == 0) / Q1 ?# m6 D6 U9 C
printf("buffer 2 equals buffer 1\n"); </FONT></P>
# ~  f* F; Z8 i! `$ Y8 K0 `- a" [<P><FONT color=#0000ff>return 0;
7 S$ h7 b5 @, R}
0 v4 F9 F; c  q* l: f" ?6 v, r/ b8 W3 T; A7 L) `+ V7 s
</FONT>
% o7 W0 E5 j, L8 d8 ?$ H9 T/ l% m</P>
4 J5 `7 h& }; V# I! N% R<P><FONT color=#ff0000>函数名: strnset </FONT>/ P; @+ s: m0 t
功 能: 将一个串中的所有字符都设为指定字符 + u5 M) P! W% G/ L/ c  k3 H, ]
用 法: char *strnset(char *str, char ch, unsigned n);
! H- |9 m9 p4 i9 ]程序例: </P>( w5 A( p) S. j1 B9 s  r
<P><FONT color=#0000ff>#include <STDIO.H>
6 G) P8 M& U( i1 y7 G7 }#include <STRING.H></FONT></P>! E; D# a) ~0 _6 b- u* V; x/ C) Y
<P><FONT color=#0000ff>int main(void) ( e, q4 Q' I/ \# e+ {+ `5 c# E. X, K
{
9 K& F$ J' W8 Z. zchar *string = "abcdefghijklmnopqrstuvwxyz";
: o2 y, h! V; Tchar letter = 'x'; </FONT></P>
  N1 [5 |, s) Y+ l+ m<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
3 }0 m4 ~7 k5 q( W1 n3 ]strnset(string, letter, 13);
/ m& O0 M4 z# j2 i% [printf("string after strnset: %s\n", string); </FONT></P>
& ~5 c# F; F# R( d8 C<P><FONT color=#0000ff>return 0; 4 k1 ?) X5 I* Y5 O6 R
}
- r3 [  Z  z7 _" z4 o1 z</FONT>; |+ a: I, e( e+ C) ?9 I# y  s
</P>
3 ]3 z! }" O1 V  @2 u% o! V& Q/ S<P><FONT color=#ff0000>函数名: strpbrk </FONT>' `0 U2 `; T' _& q
功 能: 在串中查找给定字符集中的字符 * ~+ }% O7 G! U2 u$ E% Q3 x
用 法: char *strpbrk(char *str1, char *str2); ; j9 {2 W3 [% v0 H1 H+ Y# n: P
程序例: </P>  v0 C5 c0 [3 ?+ u1 S% _# Q
<P><FONT color=#0000ff>#include <STDIO.H>
4 R* Y: S6 I, ~#include <STRING.H></FONT></P># `4 I) b9 P7 i; h
<P><FONT color=#0000ff>int main(void)
$ Q# r5 A/ E: T9 j  c5 J; R{ 6 r" I4 D* ?) X+ m+ ]
char *string1 = "abcdefghijklmnopqrstuvwxyz"; " N3 [6 Y, z3 X' }% z9 c3 l
char *string2 = "onm"; % m$ t6 p$ Z5 Q  V! F
char *ptr; </FONT></P>( ?8 K4 N0 u, Q+ m0 @
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
/ f4 F1 g4 W( [, k2 m  ?<P><FONT color=#0000ff>if (ptr)
+ [: N. F2 x" r$ o% |- L' h! g9 _printf("strpbrk found first character: %c\n", *ptr);
5 p+ Z* }7 ^+ o2 Melse
! X$ E4 S$ _$ W0 vprintf("strpbrk didn't find character in set\n"); </FONT></P>8 h! q& U7 i- Y5 z4 y
<P><FONT color=#0000ff>return 0; $ @1 l% }, d7 p4 U
}
8 l. P! p4 O# o
* D- Y$ R$ Y3 W) T+ g4 Z</FONT>
5 A8 `3 Y) Y  }8 q4 C; H/ |, H</P>! r& F% I7 }' h8 v3 _% A/ \( X
<P><FONT color=#ff0000>函数名: strrchr </FONT>
% d3 M1 B! M$ z7 Z功 能: 在串中查找指定字符的最后一个出现 & t7 q7 g4 U, |- B
用 法: char *strrchr(char *str, char c); 1 P; j( p/ \: N! i6 o, f3 w( b  a
程序例: </P>+ O8 }1 n) C2 X* L4 R7 I
<P><FONT color=#0000ff>#include <STRING.H>
# x# `6 h7 \' ^) Q' C! ?* x#include <STDIO.H></FONT></P>
  X* e7 y" j' P- V2 c" ]<P><FONT color=#0000ff>int main(void) 2 I+ ?( k. p  e& C, j
{ $ ?) O& N" A* }8 x9 F
char string[15]; & A) X9 R4 U1 r  J* b# _
char *ptr, c = 'r'; </FONT></P>
" O! U/ }, Q8 h+ f) d1 [<P><FONT color=#0000ff>strcpy(string, "This is a string"); " O& Y% Z* N) j4 g9 K( \% n8 ]  J7 w
ptr = strrchr(string, c); 9 P* r4 S) p& I$ J2 R. X; ]
if (ptr) 9 L  z7 T* r! y, V7 p: ^: W
printf("The character %c is at position: %d\n", c, ptr-string);
! |' B$ b5 ]2 D+ Nelse
& s- ^# `$ V5 S# P% g$ j$ m# Lprintf("The character was not found\n");
) m1 M4 ^: q6 ^( preturn 0; ( O7 N" N' @8 x' p" Z
} </FONT>% X  y# |! X- x
6 R( |: p$ j4 h( Q' }0 D

* [8 h) x' o. E/ Z4 a</P>$ V( j( q. m1 E! ?' Z; d. s
<P><FONT color=#ff0000>函数名: strrev </FONT>' {% ?* Y$ i+ c* U7 y) h
功 能: 串倒转
' f3 i% P2 J! Z用 法: char *strrev(char *str); ; o$ S# C2 B& f, h% a, [6 z
程序例: </P>: f6 W8 T% M8 @/ g  O' a/ l
<P><FONT color=#0000ff>#include <STRING.H>* Q( c! `+ L. z6 A. `; \) |  c
#include <STDIO.H></FONT></P>
% `4 \$ e+ H! b8 z8 p<P><FONT color=#0000ff>int main(void) ' Z1 l% L; x0 f+ f9 b% ]& k* L
{ 8 v$ [& O9 P( m3 I5 j  K; V2 h
char *forward = "string"; </FONT></P>
$ F; N1 ]! d1 N( p8 A1 a<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward); ' T% m# u) M* j
strrev(forward); 4 K6 }& Y6 Y1 Y7 H0 P. l
printf("After strrev(): %s\n", forward); : n8 K3 z6 ?" `* e/ t9 ~) k% t1 D
return 0; 9 g: x/ _2 _  O' e8 a$ u
} </FONT>
4 m, }/ `0 ^1 _, r3 r! |8 N/ y</P>
+ h, L* l2 h% }  j<P><FONT color=#ff0000>函数名: strset </FONT>
+ @/ U2 H+ j) F! G功 能: 将一个串中的所有字符都设为指定字符 ! F7 O3 Y6 ~6 C. W
用 法: char *strset(char *str, char c); 5 i0 u$ [* D3 ~5 S+ o
程序例: </P>
* n4 Q5 b% N" j# v<P><FONT color=#0000ff>#include <STDIO.H>
& g3 l1 O/ C! V1 c+ d0 h#include <STRING.H></FONT></P>" o  _" i; W8 q5 m5 P, |
<P><FONT color=#0000ff>int main(void)
1 z5 v+ J$ S; i6 W: K; C# {{   D% Q: o( O( k- ^1 U8 |9 ]
char string[10] = "123456789"; 1 N5 h5 v: P& g3 n. z. w) h4 j- X
char symbol = 'c'; </FONT></P>$ T. j% B% x6 d7 E) P/ F4 s" Z
<P><FONT color=#0000ff>printf("Before strset(): %s\n", string); 0 ]+ w/ N0 q/ {9 @
strset(string, symbol); 9 W- t) \8 R  F5 M- x) ~, p4 @% w
printf("After strset(): %s\n", string); 1 r9 B" r# U7 p7 p" ?
return 0;
5 Q; C7 A( H% i) D) c} * T3 }5 L6 D7 \# Y

3 P6 R" S6 y9 b8 q: E! K: k</FONT>
# T; q( m, i6 G8 z, H# ]# q</P>
8 g- R( l: v$ z: V% ^<P><FONT color=#ff0000>函数名: strspn </FONT>, ^  J5 \) }  W$ L
功 能: 在串中查找指定字符集的子集的第一次出现
* @7 s) i, |/ @9 C' ~# B; A( v' @( ^用 法: int strspn(char *str1, char *str2); 9 h# P. d8 f) `3 w: A8 T. {& L
程序例: </P>: a" i2 f8 V4 o. d4 Y# G2 h; W
<P><FONT color=#0000ff>#include <STDIO.H>
4 W5 W  E$ s  Y! [" B9 y8 P  ?; ]2 S#include <STRING.H>3 p2 ^& a7 p, ?4 R3 H& [7 D7 t
#include <ALLOC.H></FONT></P>% v( ^. }- ^6 b. V; q/ d
<P><FONT color=#0000ff>int main(void) 7 U% t/ T( I: t- m' n$ T
{ + f2 |" `: W4 V: R' x+ C8 T
char *string1 = "1234567890"; * c: c5 H0 n% _; T1 K
char *string2 = "123DC8"; 9 @0 c0 @2 o2 B# D( @
int length; </FONT></P>
" l) [& I2 P! s4 T; {: C3 W* _<P><FONT color=#0000ff>length = strspn(string1, string2); 5 j. L& p- c- a$ q
printf("Character where strings differ is at position %d\n", length);
: _+ C2 r% a; e% U4 ]" preturn 0;   x8 A- U! V2 t$ e4 S
} ; }4 P; q# P8 t
</FONT>% ?( r- e0 B  @: D
</P>
! U5 w1 d2 f& [. ?- ?3 r<P><FONT color=#ff0000>函数名: strstr </FONT># c5 V( R- A6 c
功 能: 在串中查找指定字符串的第一次出现 1 Z4 G, ?# F0 Z- h" {
用 法: char *strstr(char *str1, char *str2); 7 E4 W1 x7 K; o# ?5 s" J* c- O
程序例: </P>
# L* K+ x- p( ]* E6 I! h<P><FONT color=#0000ff>#include <STDIO.H>8 `) a7 F0 I+ i7 B9 U2 N7 E6 T
#include <STRING.H></FONT></P>
  H+ t4 N! H! D1 a3 X5 M! H<P><FONT color=#0000ff>int main(void)
8 B& S+ B! k% v- z{
' l* ^# h1 O) z2 jchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>
4 W# _0 ], ?) O1 s: w<P><FONT color=#0000ff>ptr = strstr(str1, str2);
. v  z5 U# u* r: W: pprintf("The substring is: %s\n", ptr);
- i' P' |  C% F  o9 |return 0; . B. ]. J0 U+ t
} </FONT>
: v% k- [) o/ e
; R. P( v$ {1 ^) a& {( }% M</P>4 L1 c- B! ^5 |& h; L
<P><FONT color=#ff0000>函数名: strtod </FONT># K7 ?' u, Y9 s% \9 {
功 能: 将字符串转换为double型值
$ H" u' z& Z" L4 G. ^8 q用 法: double strtod(char *str, char **endptr);
) o0 e$ y6 }1 N# \' y/ g2 U6 {* e程序例: </P>
% E8 B2 H5 `& n6 T+ E* D<P><FONT color=#0000ff>#include <STDIO.H>
- m8 g0 A' d, e  b. I#include <STDLIB.H></FONT></P>
2 ]5 m9 M8 k" c' i<P><FONT color=#0000ff>int main(void)
" e3 x+ N, Y9 A6 c& d0 J$ D2 w' x{
; u# u# n+ v; ~( j1 W& Vchar input[80], *endptr;
2 Q; d5 u$ Q3 Ddouble value; </FONT></P>
- b5 F+ |3 b/ F$ I% J( X9 d! O<P><FONT color=#0000ff>printf("Enter a floating point number:");
( x$ f2 X2 _/ O- k6 v, ?& ugets(input);
; p0 }: I2 K3 g. Ivalue = strtod(input, &amp;endptr); / x' @5 D# a, ?4 f0 h2 j. j
printf("The string is %s the number is %lf\n", input, value); 8 o$ I/ O, {$ ?' K( T/ r
return 0; 4 Z$ ^- u! y% a" g2 K6 H5 z
}
) W+ r* V. u- m2 |- j( P  T</FONT>
) U' l! t5 u6 T* Z
* {4 O& h) v8 z4 n</P>
5 S/ j* a9 u9 y& F, o<P><FONT color=#ff0000>函数名: strtok </FONT>, d" Q/ e$ a6 x( M
功 能: 查找由在第二个串中指定的分界符分隔开的单词 / w8 K! t1 S: [& U* d
用 法: char *strtok(char *str1, char *str2); - P0 n' x$ r: Z' X$ ?
程序例: </P>5 g9 r& D7 }1 _/ I' a
<P><FONT color=#0000ff>#include <STRING.H>
8 y7 q# p& N- z( m#include <STDIO.H></FONT></P>
8 ^- W: c# x  c* Q& G9 a, V<P><FONT color=#0000ff>int main(void)
* J! `; d# m8 W. o* f{
  m# Y3 w! T) _; Wchar input[16] = "abc,d"; 3 d0 t. E9 Y$ E* n
char *p; </FONT></P>. s% }/ ^- d' F. G0 q
<P><FONT color=#0000ff>/* strtok places a NULL terminator
% \  S* w' ^# o# yin front of the token, if found */
0 T" W" r% g- v: d# V: s) {p = strtok(input, ",");
& g7 S  X% L- aif (p) printf("%s\n", p); </FONT></P>! D4 A$ }3 `- q6 ?! h! N
<P><FONT color=#0000ff>/* A second call to strtok using a NULL : w' z  m* y) Y# C% Q& Q
as the first parameter returns a pointer $ W, @  l' t# U2 O; t' ~9 L
to the character following the token */ - [5 s3 C) W+ u7 k
p = strtok(NULL, ",");
9 {0 b( f) n9 jif (p) printf("%s\n", p);
4 C( \( T" \* r$ f2 Vreturn 0; ) }/ {: h3 H) M7 q6 A7 m( q  g+ K
}
0 c# g) h; \) j- G4 a% @+ r2 f8 p! O! {' y% q

* r/ C* j. p0 w</FONT></P>
; Y) r0 F3 }  t- W<P><FONT color=#ff0000>函数名: strtol </FONT>6 w4 b' P" N; q, t
功 能: 将串转换为长整数
' X5 i- B$ Y2 ?8 L. y% {" k用 法: long strtol(char *str, char **endptr, int base);
/ ?! e& _- @* u程序例: </P>; P4 j. P% ?9 n  {! {
<P><FONT color=#0000ff>#include <STDLIB.H>$ D4 S; \' N) L9 y: X% K' O0 t
#include <STDIO.H></FONT></P>
5 ?7 p+ W: Y; b# o- ]<P><FONT color=#0000ff>int main(void) 2 \" K" E0 q6 X" q
{ : i! p5 @( ]; X7 B  u
char *string = "87654321", *endptr; # }/ O4 s: W3 s- b$ l/ o* H
long lnumber; </FONT></P>/ ?/ }& u0 M6 t$ T" q* V
<P><FONT color=#0000ff>/* strtol converts string to long integer */ 0 d  D) S' b1 d/ ^
lnumber = strtol(string, &amp;endptr, 10); & ~. f  f8 D' ]) k
printf("string = %s long = %ld\n", string, lnumber); </FONT></P>. Z: H* C' V9 S& v- [
<P><FONT color=#0000ff>return 0;
0 U/ K, W) C& @9 `7 @/ e4 q. n} </FONT>7 v- f+ ~  F9 T
</P>/ \& m+ b/ P# C6 [
<P><FONT color=#ff0000>函数名: strupr </FONT>
/ m2 X6 k) @" U2 I. }功 能: 将串中的小写字母转换为大写字母
/ m9 s: F: m9 w8 z, D4 i用 法: char *strupr(char *str);
1 ^" J* c# Q5 M程序例: </P>
, Z6 \0 m7 c% c9 j. S8 P" T3 l<P><FONT color=#0000ff>#include <STDIO.H>! q9 C2 v. u+ ]
#include <STRING.H></FONT></P>; f- ^; W: `4 w7 C$ @! k4 I' F' C
<P><FONT color=#0000ff>int main(void) ; U, H8 D0 s+ n& \: r3 n' H) E6 D3 M
{ ) Q' Y/ I9 F2 T4 X
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>3 e/ U, P1 M9 l2 Y/ q& {/ f( n$ F
<P><FONT color=#0000ff>/* converts string to upper case characters */
+ [$ q1 N9 p: ]: tptr = strupr(string);
' h6 U* E. c" R4 _7 Vprintf("%s\n", ptr); : S1 W! a5 U* O7 {
return 0;
, Z# b3 s; d6 ?* E) R. E}
: c6 Z( X1 [5 Y3 b7 @! J" I
$ r* w9 `: h! `( N1 ?8 l& h. z- U7 p/ f</FONT>8 ]( C, ~& ]. q/ \$ y
</P>
, J; |1 z2 Z5 Y4 {) x. j<P><FONT color=#ff0000>函数名: swab </FONT>
. w% m4 w" k' x: k& {5 l3 K: U( T功 能: 交换字节 6 K  D" T( g! C% Q
用 法: void swab (char *from, char *to, int nbytes);
* J2 D( n0 [. G1 ~+ i* e程序例: </P>
* K; n" c% _" o7 v! I<P><FONT color=#0000ff>#include <STDLIB.H>
8 [6 P3 N- ?4 _& w' h% j! A  @#include <STDIO.H>
( v4 V; p$ k0 L2 _( G- L#include <STRING.H></FONT></P>& {) p( E7 e) X" m
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; * i+ [/ z2 E' c3 ?) u  @
char target[15]; </FONT></P>; p+ `0 S0 k" g; W1 s
<P><FONT color=#0000ff>int main(void) 1 l0 |( C& M2 M9 e2 P5 I0 L
{
4 N" R" {' {* `7 d7 m: {swab(source, target, strlen(source)); . n* \6 ]4 Y  l; U
printf("This is target: %s\n", target);
5 B8 g% r+ P) Q7 ^% |3 oreturn 0;
# S# e) H( F" D. w0 O}
# m4 c! C& u. ~</FONT>( E' _0 S2 s* u& V

2 j3 _) K) Y; c- m# Z  @- U( g</P>
! F8 _8 S1 w5 Z) ~/ t: t' T( i" D; N<P><FONT color=#ff0000>函数名: system </FONT>; r- C8 g" p; k5 ]% V2 c% b/ v
功 能: 发出一个DOS命令
% ?7 l* E6 Z) z: g. x! a  j: G. V用 法: int system(char *command); ; G( N/ _; W+ {3 Z6 _; R
程序例: </P>, f: r4 H* c, @. Z" X3 c
<P><FONT color=#0000ff>#include <STDLIB.H>
" @9 T7 A: h& R9 p9 U#include <STDIO.H></FONT></P>4 Q% r# m8 W% R( ?
<P><FONT color=#0000ff>int main(void)
8 A, V( N' q7 f& ?{   a- X8 d" c' {) A# I1 z- ^
printf("About to spawn command.com and run a DOS command\n"); # f" n6 j( l6 N$ r! z0 `
system("dir");
6 L, o8 ]- F8 o4 Treturn 0; : S, v5 G" B: C0 g; z0 p4 n2 P$ Q
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-25 04:54 , Processed in 1.444315 second(s), 51 queries .

回顶部