QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>
% L2 c, V) g1 Z* C功 能: 改变数据段空间位置 2 b/ R8 }! r, a/ s
用 法: char *sbrk(int incr);
2 M1 J! c0 _2 |0 C$ H程序例: </P>
3 F0 h. }1 [( i<><FONT color=#0000ff>#include <STDIO.H>3 y" T8 w' R' e7 F( P3 g7 s+ r
#include <ALLOC.H></FONT></P>
) L2 [" ~" v% D8 P<><FONT color=#0000ff>int main(void) + ~3 W2 f# T* m
{
. S4 a0 p' Y- u- V5 N7 a" Oprintf("Changing allocation with sbrk()\n");
. `' O/ R& l2 P5 b5 }0 K2 O* Pprintf("Before sbrk() call: %lu bytes free\n",
7 P, H0 o) T- B5 Y6 L7 R(unsigned long) coreleft());
! x2 j0 u3 R# R4 |/ p, Fsbrk(1000); - D% F( U( r4 p0 l
printf(" After sbrk() call: %lu bytes free\n",
% e  l0 L3 G+ r9 R2 A3 `(unsigned long) coreleft()); : S1 |4 ?4 s8 @4 X8 \) T
return 0; % a6 D$ W$ {  {3 u' _
} . S) J- m4 H3 f# E# x
$ W; [& x  K# T; P3 F/ ~8 ]% X
</FONT></P>
6 h) O% [9 M5 P0 Z! d2 |<><FONT color=#ff0000>函数名: scanf </FONT>
" t0 G5 Z" {7 b# ~功 能: 执行格式化输入 0 }6 f3 A6 F3 ^  H5 B' `5 z
用 法: int scanf(char *format[,argument,...]);
& s* ]2 ?' g9 Y程序例: </P>
( p" \5 D& P2 x& H<><FONT color=#0000ff>#include <STDIO.H>
3 H' g( F2 o5 x#include <CONIO.H></FONT></P>* U) A( Y! b  s; @% [: Q+ f
<><FONT color=#0000ff>int main(void)
: p+ w4 G: L4 }{ 5 p* q3 k% Q  y# Y
char label[20];
# D. Z( s* A- Fchar name[20];
9 }. d% K6 ]/ _. d! ?' U7 jint entries = 0; & {. O: i+ }( f/ F% c/ e) b
int loop, age;
  S& R8 O* t* L2 bdouble salary; </FONT></P>
, ~6 p* e% L$ o( _8 g<><FONT color=#0000ff>struct Entry_struct / ]# T5 `( R7 C" o
{
# _5 M; l+ A5 _! g' I( bchar name[20]; - r6 o! Z# F$ D" Y
int age; 5 ^' y& D6 F1 L; z, E
float salary; 3 K" M" M: d) C4 F! j# y+ h+ t$ @
} entry[20]; </FONT></P>
5 Z. B5 E2 ?$ a  z! I<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ ( @: `" H8 f% L8 Q+ G
printf("\n\nPlease enter a label for the chart: "); * O* ~/ N* f$ X8 k- n  ?
scanf("%20s", label);
! h% V. s/ o) b+ A2 L, X8 t' c4 Offlush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
# v/ ^! |: u  O2 E8 t8 Q% G9 Z<><FONT color=#0000ff>/* Input number of entries as an integer */ # v2 P. B8 [6 t$ Q! K( B
printf("How many entries will there be? (less than 20) ");
7 H7 W, \$ L5 Hscanf("%d", &amp;entries); 1 S. D  B( k3 R9 A
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>, I/ d' s6 h$ z4 N0 @
<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
+ I% U: g7 Y3 Y" ofor (loop=0;loop<ENTRIES;++LOOP) 1 q: a2 K1 G& f# S  V, a5 R
{
2 {' @  J% r  y$ O: qprintf("Entry %d\n", loop);
+ ?8 W' T+ q! L! G! Vprintf(" Name : ");
" @5 k' P6 [/ t7 f# a9 Y! ~scanf("%[A-Za-z]", entry[loop].name); 4 E8 w, F. g, B  P
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
, }8 f/ t+ z- v0 q<><FONT color=#0000ff>/* input an age as an integer */
! I3 y# z( x0 G. a& O$ |printf(" Age : ");
* c9 h5 `  p, L0 X9 @scanf("%d", &amp;entry[loop].age); 3 _' y/ \) T7 C
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>5 Q" c+ |; A% K' @
<><FONT color=#0000ff>/* input a salary as a float */
4 u. M+ W/ U6 `' ?: ]  |- Bprintf(" Salary : ");
" o9 F9 Q  }# ~7 |4 c$ Ascanf("%f", &amp;entry[loop].salary); $ [% h' u. r+ j' y  J# Q
fflush(stdin); /* flush the input stream in case of bad input */
$ x7 j6 s# t3 H& U3 b} </FONT></P>) n, P5 H6 L5 y$ E
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ 8 r  Q' j% r6 e7 N9 X
printf("\nPlease enter your name, age and salary\n"); $ A9 v) N0 P9 B% p6 g: r/ X
scanf("%20s %d %lf", name, &amp;age, &amp;salary);
4 z9 i4 v1 U+ p</FONT></P>5 r. g( Y7 c6 k
<><FONT color=#0000ff>/* Print out the data that was input */
- s: s* s' T9 |( s8 o- L. {9 ?/ Nprintf("\n\nTable %s\n",label); - ~( G$ b/ `' j: R1 h
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); * K7 P- Y+ B, u# H/ d. |* s6 D
printf("-----------------------------------------------------\n"); ! e/ j. @1 {# X0 `
for (loop=0;loop<ENTRIES;++LOOP)
1 r- E, _" V+ q7 A printf("%4d | %-20s | %5d | %15.2lf\n",
8 T3 _" w. E! I; B) p5 aloop + 1, % p9 Z2 B/ W7 o5 M7 x  p8 r
entry[loop].name, ( a& C9 \  v5 q# O+ ]. F
entry[loop].age, , s* z& ^4 s/ d" X  t3 z
entry[loop].salary);
. c4 C/ \/ j) P6 _3 q' m: [$ M8 aprintf("-----------------------------------------------------\n");
4 q! t; b7 K5 ]+ breturn 0;
8 y, O& ]6 w; l% L}
) u% [# D4 r2 A& P. h</FONT>2 f8 W/ x4 O, v0 U2 q" f
</P>
9 [. \$ O1 \1 m. Q$ w% K<><FONT color=#ff0000>函数名: searchpath </FONT>
. x7 d/ |$ y6 G, W& W功 能: 搜索DOS路径 4 B& `: L& `- @- B9 u7 c4 l& W
用 法: char *searchpath(char *filename);
* }0 E! [6 `4 w+ A6 i5 `( C3 Y) ]程序例: </P>0 m4 U" i4 H: Y( q8 p. M
<><FONT color=#0000ff>#include <STDIO.H>6 Y/ V4 u+ j1 f1 |) b+ a* d: V, y
#include <DIR.H></FONT></P># I& e: _2 O* D6 O) d$ T" C0 f
<><FONT color=#0000ff>int main(void)
8 m2 {9 }9 }& P{
8 j+ W* a' j& u% X  I; b6 g3 u' P) s. Schar *p; </FONT></P>
7 M! S7 y  T6 m2 c$ z<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
- B7 F" Q4 G; c& L/ \to the path */
( S2 H- ]) ]& fp = searchpath("TLINK.EXE"); * n  [8 c6 @; D- A: ]- o
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>& D0 c9 D" v  ]" m. y" k& W7 b4 \  z  x
<><FONT color=#0000ff>/* Looks for non-existent file */
* P- E! }. i& V1 T' v) S! pp = searchpath("NOTEXIST.FIL"); 1 d# I7 X( A; B0 ~8 E5 u6 E9 N
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>
- E. z, x+ ^; h: q<><FONT color=#0000ff>return 0;
0 T% ]4 b; }+ t} , V5 a- r" x8 z2 k. a7 u4 N
* o7 ?* C: v0 W; _/ k5 V$ p
</FONT></P>
& L0 N7 q- l% W6 V) M) d8 H. O<><FONT color=#ff0000>函数名: sector </FONT>" Y. @7 F' X+ i
功 能: 画并填充椭圆扇区
. Q( S/ |0 p) {  z: g用 法: void far sector(int x, int y, int stangle, int endangle); ( u# m: o, Z+ a7 R3 A
程序例: </P>
6 i3 H, r+ s# J% k  M2 r& F  E4 w<><FONT color=#0000ff>#include <GRAPHICS.H>
2 [3 d" b6 J4 ~: x#include <STDLIB.H>
  x+ S# s! N0 d5 ^#include <STDIO.H>
3 |  {$ I- [: X) U#include <CONIO.H></FONT></P>. C" f; S0 H: f) s; K/ ]  ~
<><FONT color=#0000ff>int main(void) - U  U+ Y. M& A
{ $ B  r5 {  @" p2 E# i
/* request auto detection */ , O1 f2 U1 P& S2 ]3 o
int gdriver = DETECT, gmode, errorcode; - p/ x6 W- Z* q7 F
int midx, midy, i;
/ g7 ?* E3 u" i1 jint stangle = 45, endangle = 135; 0 k5 A& T# l" i. n2 m
int xrad = 100, yrad = 50; </FONT></P>
2 V3 I" Z) [$ D3 g<><FONT color=#0000ff>/* initialize graphics and local variables */
) _! G2 G% k8 N, [initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ B* y7 I' r& k) q; C  H
<><FONT color=#0000ff>/* read result of initialization */
2 H  j+ l4 U% u" X, R& Verrorcode = graphresult();
% E& E- L/ n" j8 ~! @3 _" B2 Pif (errorcode != grOk) /* an error occurred */
1 x# @2 j( w+ I* v{
6 O8 u; [+ k0 I' c- U) B  s0 P5 Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 Y; e. p2 f) z1 _2 b: f: A# N
printf("ress any key to halt:");
+ P# M4 F0 m: A. M. c* z8 [getch(); . _" M( g( M* p
exit(1); /* terminate with an error code */
2 _/ U6 C' J2 L) ?! c6 s} </FONT></P>; G0 b7 F9 @* n. @/ I4 S! w
<><FONT color=#0000ff>midx = getmaxx() / 2;
7 D' Q. ~2 a9 O8 Imidy = getmaxy() / 2; </FONT></P>1 C% m% U' D. ?( m. v* R8 v
<><FONT color=#0000ff>/* loop through the fill patterns */ 2 P6 ?" X/ K, n
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { : W9 h- O9 E( ?/ f$ k" u2 S  _; p
/* set the fill style */
4 ?& O0 i- M* t/ h9 u0 s) J2 y  [* Qsetfillstyle(i, getmaxcolor()); </FONT></P>3 i9 J4 R1 r. B3 y+ ?/ M$ a( _
<><FONT color=#0000ff>/* draw the sector slice */ ) W- R- Q2 X: Z6 b; H0 q: M
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>
, K2 m2 ?% H! T9 \" G3 O<><FONT color=#0000ff>getch();
& e; R% G/ c* C4 w4 {% ]} </FONT></P>
- m) B$ b7 P& R9 j/ G<P><FONT color=#0000ff>/* clean up */
* R* e" S$ a0 }* T  i+ bclosegraph();
" Z" [/ I& J5 b7 |4 U* k: ^0 F7 Areturn 0;
9 q1 a. M+ n7 n0 o, v: W3 v* o- B} + Y' ^! i# T! @: q0 S5 K) r9 |
</FONT></P>: K$ B& J3 {6 U2 s) @, F, |: y
<P><FONT color=#ff0000>函数名: segread </FONT>3 D5 n. x: U# p8 k
功 能: 读段寄存器值 7 B7 }0 F# i: f& z# C
用 法: void segread(struct SREGS *segtbl);
) }2 ~0 c; \7 Z) w4 w6 l- _程序例: </P>% l0 O' ?: @: J7 B" |0 g6 n" d
<P><FONT color=#0000ff>#include <STDIO.H>2 h/ ^# i0 T0 ^
#include <DOS.H></FONT></P>
: b. y" i# I9 D<P><FONT color=#0000ff>int main(void)
# G5 F3 c- D1 }$ y$ m0 T% D; ~{ % i* P$ N6 r0 K) f- z
struct SREGS segs; </FONT></P>$ U; ?2 `5 `* ]; d4 a5 H" z- u
<P><FONT color=#0000ff>segread(&amp;segs);
+ u5 n) D% \3 L: o  D9 Mprintf("Current segment register settings\n\n"); 2 R6 E' x+ G* Q9 G' Q6 `) e
printf("CS: %X DS: %X\n", segs.cs, segs.ds);
# Z0 D( G' r' F$ Y0 P$ R/ I* wprintf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
% N9 R- z9 I3 _; W) K* Z. k0 `' V<P><FONT color=#0000ff>return 0; 2 D5 I; o8 |5 r3 r
} </FONT>' G: r) E; i+ l& A. l4 k
5 P8 I% g% H+ c' M
</P>- F6 Z0 S; |% W5 ~
<P><FONT color=#ff0000>函数名: setactivepage </FONT>  j, b  ^8 m' \* G2 l6 r
功 能: 设置图形输出活动页
. q: K3 o. D! c3 E& k9 a$ ?1 o用 法: void far setactivepage(int pagenum); $ \) A& d" _/ L0 V- D! k* @7 ]
程序例: </P>
/ C& O$ p' N; R( e0 f8 u9 \% M<P><FONT color=#0000ff>#include <GRAPHICS.H>
, m9 t# X/ x! L% x. S% a#include <STDLIB.H>
7 R2 v% E% Z$ O. P. ~6 g5 p#include <STDIO.H>; A1 @7 V% L7 R$ {& v
#include <CONIO.H></FONT></P>( W' x: _8 a: [; x8 s- w7 _
<P><FONT color=#0000ff>int main(void)
1 |" K& d- r. [: t# ?{
# T, ^; u# P- M7 r8 x" E/* select a driver and mode that supports */
1 ?$ c+ ^" L8 D# Q. t6 U/* multiple pages. */
: y& g) [/ a5 Z' K) V% v2 T$ Nint gdriver = EGA, gmode = EGAHI, errorcode;
# d4 o- W5 r8 B  X1 K" Oint x, y, ht; </FONT></P>$ Y$ y  B% ^) T3 ^$ J- C- h/ L) u  o
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 [3 w. W; c5 M  V9 V
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>& }* v) n" C0 |: I
<P><FONT color=#0000ff>/* read result of initialization */
6 O4 z" f. o+ Z, S) Yerrorcode = graphresult(); 3 E' B: T7 T  v/ K" G2 l- A7 l1 Y
if (errorcode != grOk) /* an error occurred */ ) b! \3 z, z3 I/ [, N9 z8 V# |
{
/ [4 Y7 {, |% T5 B9 U/ ?% v7 [6 E! x. ^printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( E, d, L( }$ Q/ @% z; j, F- u
printf("Press any key to halt:"); ' Q" g2 [5 s7 m( q1 }
getch(); $ z1 E7 d/ `; ]# L* k
exit(1); /* terminate with an error code */
2 T8 ]0 U; I5 [8 j  J} </FONT></P>
, j. m, o- e7 v<P><FONT color=#0000ff>x = getmaxx() / 2;
; L( l7 x6 m+ |0 R% Z9 W6 k7 f) s, o) My = getmaxy() / 2;
" @) _2 M, v% `( S( g& dht = textheight("W"); </FONT></P>& L& r0 P3 l+ _9 l$ D/ V, H
<P><FONT color=#0000ff>/* select the off screen page for drawing */
0 U: E% G9 |* v2 V: T8 Q3 Jsetactivepage(1); </FONT></P>: n. v7 k4 H3 }
<P><FONT color=#0000ff>/* draw a line on page #1 */
% l9 R( D- D$ T5 l4 k/ D5 E, wline(0, 0, getmaxx(), getmaxy()); </FONT></P># D' N- d! [: b9 H
<P><FONT color=#0000ff>/* output a message on page #1 */ ; K* r% V7 C+ C3 R$ B3 [
settextjustify(CENTER_TEXT, CENTER_TEXT); 4 t/ W- ]; V0 U! L" j4 Z
outtextxy(x, y, "This is page #1:");
; @' ]5 O( T& [7 v& q) x. uouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
0 G7 Q# q2 C8 X- Z" t* X<P><FONT color=#0000ff>/* select drawing to page #0 */
9 R6 g5 s8 Y& c4 H% ]( }+ u. bsetactivepage(0); </FONT></P>- ^) _: @* }! h( |
<P><FONT color=#0000ff>/* output a message on page #0 */ : e) t; B: n2 I( V8 v
outtextxy(x, y, "This is page #0.");
. n$ ]' d6 O' u; qouttextxy(x, y+ht, "Press any key to view page #1:");
! ^; g5 U% }! ~/ r- c7 d$ _0 B7 ^getch(); </FONT></P>$ p- Y" h7 z+ Y$ v
<P><FONT color=#0000ff>/* select page #1 as the visible page */
. P, W0 t" Z; w# lsetvisualpage(1); </FONT></P>
- u, X/ f7 x9 u! V8 z* u& m, }6 z<P><FONT color=#0000ff>/* clean up */
1 r! M3 ]" }' {, i6 v* ogetch(); 5 Y5 \8 i# Z: y  D: Z
closegraph();
: Y; v4 s- M6 K# Hreturn 0;
; E2 B5 n- G4 C9 K$ C) \9 _}
2 ]1 P  s9 Q) X1 ^</FONT>! j0 L+ Q( d, q' y
</P>
4 i3 S1 H: V+ M3 B/ }( G<P><FONT color=#ff0000>函数名: setallpallette </FONT>
5 C: T9 Z5 g& o  e; E2 ?+ j: [& g功 能: 按指定方式改变所有的调色板颜色 ) w! Z% m* _1 l3 D
用 法: void far setallpallette(struct palette, far *pallette); ! T$ F# B+ J/ {3 W9 r
程序例: </P>; M3 n5 Q2 f& }' }; `
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 W% |7 c5 {7 Q#include <STDLIB.H>+ G8 I- Q% U% |' r6 c8 G! l' D
#include <STDIO.H>0 t- a9 t9 r1 o7 C2 x
#include <CONIO.H></FONT></P>
# g* Q: h! G4 j: ?3 @<P><FONT color=#0000ff>int main(void)
! C4 d7 r" Q/ A; L{ 4 j. J8 S' F8 i+ t" V8 g- t5 b7 n$ q5 |0 L0 F
/* request auto detection */ / I$ a  J( C% a7 s1 Y6 j
int gdriver = DETECT, gmode, errorcode;
; @9 `: n& |# S% T7 {# |# l3 Bstruct palettetype pal; ; a1 z: Q  M2 D- n
int color, maxcolor, ht;
; g, ~/ L$ n* s! Eint y = 10; % |* u* z# e2 W8 p
char msg[80]; </FONT></P>
. W! n# C5 m8 M" k. Y! h  y<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 S6 y* T' m6 V7 S& {, M. Vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 A  ?+ s* [" `4 f& o
<P><FONT color=#0000ff>/* read result of initialization */
/ S7 ?0 \" X8 _; `' e, t( S: I& Perrorcode = graphresult();
: G, A3 c. j- l  y" N6 J: Z7 bif (errorcode != grOk) /* an error occurred */ 7 \/ v) X4 d8 R6 X" e5 j4 m
{
* R) X7 V* @# L9 V  ]. o- B: ?printf("Graphics error: %s\n", grapherrormsg(errorcode));
8 i8 V6 X! k! W% Zprintf("Press any key to halt:");
/ Q% v  `! M- W2 zgetch(); # O% D& [3 E( h9 n% M, M
exit(1); /* terminate with an error code */
3 l0 H* N' d& ^! }. L; }4 t7 z$ M3 |} </FONT></P># l! z9 ]! h( B( [3 F. g
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
- G: F  A! _- }, F1 Iht = 2 * textheight("W"); </FONT></P>% ~8 O- M3 F8 ~- ~$ J. s8 X9 ?1 O
<P><FONT color=#0000ff>/* grab a copy of the palette */ 4 g6 c" `- |4 a1 H
getpalette(&amp;pal); </FONT></P>; t% C( W9 ~) P, ^: H7 i
<P><FONT color=#0000ff>/* display the default palette colors */ . q, s4 X- r. k; X) ^9 r  f$ Z
for (color=1; color&lt;=maxcolor; color++) / v! V- s! O+ x; N( ~
{ + a: \! s9 j5 U% h- k' v4 D' R) P
setcolor(color); ; @% V6 T, o2 O
sprintf(msg, "Color: %d", color);
6 P2 I& m7 p0 @0 G' }outtextxy(1, y, msg);
) f. M9 Z9 p6 ^* a" E) My += ht;
2 T, p1 Y8 s" @: ~- {9 Q5 U} </FONT></P>2 B# R2 P" k) l) K
<P><FONT color=#0000ff>/* wait for a key */ - t" t- w  o+ S6 B! d' f! K9 T
getch(); </FONT></P>4 X0 K1 r6 f$ E  e& @7 _
<P><FONT color=#0000ff>/* black out the colors one by one */
. A8 v4 }: Q3 |: [/ H- ?8 e$ B% qfor (color=1; color&lt;=maxcolor; color++) # ^9 ]+ i1 Z8 P& F
{
8 f  G1 u: V, S8 l! \' u+ b. Z) ksetpalette(color, BLACK);   t  r: v/ \7 v* x, I! D1 B
getch(); 4 `! O# l8 V& L3 j' m: K
} </FONT></P>7 g" V0 Q9 i7 s) t3 u
<P><FONT color=#0000ff>/* restore the palette colors */ $ u$ ~9 z- `2 \+ Y3 {5 t
setallpalette(&amp;pal); </FONT></P>; a6 h6 {9 J2 F: \* l2 q8 {/ ^
<P><FONT color=#0000ff>/* clean up */
  A' J: M& Z) J  g7 R) |/ O0 pgetch();
: ^1 H4 N2 E. G* f. H; H5 C# Jclosegraph();
' S) H& q0 g0 T0 l# _* \5 Rreturn 0;
2 r: M, @6 L2 R}
' i( E# ]' U" p; b3 O- _3 T, G& O$ S' o" [7 a  x$ ]% k8 ?6 e* {
</FONT></P>
$ C  |0 m; n  e/ e; W! U<P><FONT color=#ff0000>函数名: setaspectratio </FONT>' W! |4 }( N! q: m# L$ V
功 能: 设置图形纵横比 ' K# G$ E8 \7 e3 F, J+ a
用 法: void far setaspectratio(int xasp, int yasp); 3 K6 ^  d/ T& y
程序例: </P>
3 S' ?+ R& p: y, l3 L/ ~! n<P><FONT color=#0000ff>#include <GRAPHICS.H>- r* L0 B6 Y+ \* u! H, ^& G) O3 F
#include <STDLIB.H>: E+ ]8 t0 b6 d9 X1 V
#include <STDIO.H>
0 O8 m( [9 o# v) P' i% v$ w0 v#include <CONIO.H></FONT></P>% j0 l- m, o2 I5 x6 K6 }
<P><FONT color=#0000ff>int main(void) - L6 f' b2 K1 l) Y( H' O5 ]0 d
{
6 o. g! t8 \! [  N2 J/* request auto detection */ & @+ J. T7 ^# S, u
int gdriver = DETECT, gmode, errorcode; ; V$ {5 f0 X6 v- s" I
int xasp, yasp, midx, midy; </FONT></P>
+ d' s1 w: U( N! g8 U<P><FONT color=#0000ff>/* initialize graphics and local variables */
' V7 [$ w+ h) j  @initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ D3 g" e  u* ^- W2 t/ Z9 ?<P><FONT color=#0000ff>/* read result of initialization */
' y2 t+ _' [/ T) ?. n& e' Z8 Xerrorcode = graphresult(); 7 ^+ d/ Y* n9 v+ n4 X
if (errorcode != grOk) /* an error occurred */
9 n( e% K3 a0 \- ?  E% v{ * p" }9 n, u8 i/ V% X: H; f
printf("Graphics error: %s\n", grapherrormsg(errorcode));   a: @. V6 q7 E3 `
printf("Press any key to halt:");
" [. i: I; @' A% w) Bgetch(); 4 u" Y& S% L, c7 G/ g
exit(1); /* terminate with an error code */
3 W0 I7 ~! ]2 {; ?9 o} </FONT></P>1 X6 S: n/ k& c* L) [3 }; y
<P><FONT color=#0000ff>midx = getmaxx() / 2;
6 ^- o  E" |$ O- Dmidy = getmaxy() / 2; 1 N' l+ K, h8 i
setcolor(getmaxcolor()); </FONT></P>* f4 Q$ b1 {4 Z4 @$ n4 @
<P><FONT color=#0000ff>/* get current aspect ratio settings */ 0 z8 B% Y% N9 y7 g" [
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
9 X+ r5 y& R$ k1 f- f5 j, N# n<P><FONT color=#0000ff>/* draw normal circle */
1 k1 [' ~6 s4 d1 Z5 c& V. }; \* ?circle(midx, midy, 100); , Q% k3 T" e4 m( P
getch(); </FONT></P>
7 N3 u# F! B. g8 c( |2 V<P><FONT color=#0000ff>/* claer the screen */ : h; T4 e# z3 J' x. [+ f. m. i2 U
cleardevice(); </FONT></P>
5 T2 v8 i/ s4 B<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ 3 _8 L3 |! g" b. h; Y# O4 j% x
setaspectratio(xasp/2, yasp);
3 p5 B+ j3 _( B1 G0 kcircle(midx, midy, 100);
$ p; h$ F) f( T1 O5 T; C, t4 v: mgetch(); </FONT></P>
; r% g8 |. r1 n( M. B7 y9 n<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
8 E& }3 p; n* P+ X3 f7 Hcleardevice();
% S' E! r4 V- R; asetaspectratio(xasp, yasp/2); " r9 a! J. ~, |) t8 C9 F
circle(midx, midy, 100); </FONT></P>
! V( j4 Q/ ?+ r9 L<P><FONT color=#0000ff>/* clean up */ . H+ d3 A5 ]$ d/ b- z/ |, p2 n* f4 ^
getch();
9 w0 V# g- \! M4 H- |closegraph(); 3 o, ^; D9 L4 r, U3 i
return 0; / }4 Z2 E8 X0 j+ ]: G; c  v9 U
} , T, ^* ~$ @2 F2 _: x6 B; p
</FONT>
( o1 C( J. J) F, ?, I</P>
  f4 w" ]  O, X8 K<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
" H6 v% w' J' q8 }功 能: 用调色板设置当前背景颜色 2 X/ }! b! l2 v( [3 d, Y
用 法: void far setbkcolor(int color); 2 F% X* c% N! p8 m# {4 \
程序例: </P>
9 D' i- A. ?2 d( m( ^" P<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ I  b. F0 K  P, U' W#include <STDLIB.H>. u- C6 t# J5 q4 w! C. \, u# `, V
#include <STDIO.H>
! Y8 u2 D( H! R4 m- J* J: n#include <CONIO.H></FONT></P>
& r4 O7 ~0 u& B) g* J6 q& e$ D# x<P><FONT color=#0000ff>int main(void) + Q# }- E! B. z. o0 E
{ 8 e2 P7 l, q: @: }5 V
/* select a driver and mode that supports */ ; a/ ^# [3 |4 U. W3 T8 ~  \$ x* a" U
/* multiple background colors. */
3 O" Z* ?* L0 r+ n  Aint gdriver = EGA, gmode = EGAHI, errorcode; * E# H6 |4 R$ l2 X+ A
int bkcol, maxcolor, x, y; ; i. S! H9 r" f  y( A" J% ~5 C
char msg[80]; </FONT></P>
3 M; }; T7 d1 e<P><FONT color=#0000ff>/* initialize graphics and local variables */ + j5 l; ?5 P" _7 `' z7 ^6 c2 O
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 Y9 ?+ ?; V/ o<P><FONT color=#0000ff>/* read result of initialization */
. V8 \! [! O* M1 l( m( K& zerrorcode = graphresult(); ' W6 e2 C, q$ X0 s( D" z
if (errorcode != grOk) /* an error occurred */
8 F% w: b5 \' g9 y{ ) r# E1 h% f2 W" n% o$ t7 Z
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 ]' h9 |0 s* V" h; {
printf("Press any key to halt:");
2 \1 _  E8 P2 F1 ?* C- ~* w* tgetch();
, Y! y8 I& q$ d2 t. A, Z& fexit(1); /* terminate with an error code */
% |4 N" a3 S. u. H0 y4 w( `} </FONT></P>& q4 T0 ~! a; K" P6 I- K
<P><FONT color=#0000ff>/* maximum color index supported */ " z; i% H3 V; ^  h! [: D) D
maxcolor = getmaxcolor(); </FONT></P>4 L, q: @: m$ t3 D, ?5 k$ n
<P><FONT color=#0000ff>/* for centering text messages */
# B* N- T/ j, [' Q, W! |9 Xsettextjustify(CENTER_TEXT, CENTER_TEXT); # G% D1 x" D' N( s8 H* E* Y
x = getmaxx() / 2;
, P# E; p# Z: g9 B9 @% \y = getmaxy() / 2; </FONT></P>
$ v5 [0 E' c, s2 A, s<P><FONT color=#0000ff>/* loop through the available colors */
/ }+ j( L- u! h" R4 Bfor (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
9 _3 @. q) }, y2 r. m1 m' A" E* j{
; Z! b. L4 N2 Q. v% z/* clear the screen */ 0 C. H1 |, f# f0 i/ |
cleardevice(); </FONT></P>
6 k* c6 ~4 t, z# `<P><FONT color=#0000ff>/* select a new background color */ 5 l- s& |& n% S( b
setbkcolor(bkcol); </FONT></P>" ?7 @: `7 a, d5 t$ I. |0 R! c8 ]
<P><FONT color=#0000ff>/* output a messsage */ # S7 |, B* E4 Z9 [! }
if (bkcol == WHITE)
4 q) I- p* {0 V% K+ e: osetcolor(EGA_BLUE);
+ {7 z# U! ?( j: T, esprintf(msg, "Background color: %d", bkcol);
; R: ?9 y2 `4 r/ O! T: S- Louttextxy(x, y, msg); ' p* w( [# Z2 N' H& i, T3 O
getch();
4 c) a. U2 c4 o, L; u6 H+ U% K} </FONT></P>  X9 {! `) x; ]2 B$ j0 ]9 x
<P><FONT color=#0000ff>/* clean up */
' Y! w5 e0 b; d7 Pclosegraph(); , ?/ w" i6 d+ f9 C" K* s, P
return 0; 1 i; C" a* ?/ b+ ^+ W2 _; ?
} </FONT>& v9 o& U5 b9 |+ p. V/ d- @% W
$ [$ B- m; ~7 m7 S0 C# B
</P>
5 A" |% `. [: g# @1 q; ^2 G4 t- d4 h<P><FONT color=#ff0000>函数名: setblock </FONT>
7 I" X  C+ t% p+ H5 ], ]功 能: 修改先前已分配的DOS存储段大小
( \9 ~% v/ h- ]) E! [9 Q3 d4 _用 法: int setblock(int seg, int newsize); 2 s( k- h! l5 m3 Q
程序例: </P>
+ J$ F. }, E! |2 v6 `' D& f' m<P><FONT color=#0000ff>#include <DOS.H>
/ v- ]9 ]* `1 {) ]; V#include <ALLOC.H>
) ]7 b4 o8 |# X* M#include <STDIO.H>
; r8 j* {  ]9 P) T3 ?* ~/ E1 V#include <STDLIB.H></FONT></P>7 `$ j' V) z, c0 ?! P7 H+ y
<P><FONT color=#0000ff>int main(void)
" E; Z! u; G# O; v  O{
- }+ B6 o, H  |- cunsigned int size, segp; ( |7 L5 Z) H$ Y, C  K! m
int stat; </FONT></P>
" g5 M% _# Q0 L' y+ t: Z1 ^+ G<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
; ]4 V! |; Z. q) O2 Z* `stat = allocmem(size, &amp;segp);
/ v1 w& b4 ?8 D, o2 t1 R- `if (stat == -1) ; p+ i  G3 ]9 R  a& s' U- `/ ?
printf("Allocated memory at segment: %X\n", segp);
: ^7 n* r" e9 Y5 ]& Aelse
4 K, c1 x5 j6 H) t{
/ M4 u' t% s" P* m" Xprintf("Failed: maximum number of paragraphs available is %d\n", " {. S0 J: d- G/ a, C. q
stat);
# j  @1 V/ L' p$ R* i' V( hexit(1);
' u# g( p1 E3 ?$ w# M} </FONT></P>
. g7 w3 d/ b- I2 R1 \# u<P><FONT color=#0000ff>stat = setblock(segp, size * 2); & O+ ?- W& g0 p) p8 \
if (stat == -1) % I; |8 S4 R4 U6 p" Z: |" h
printf("Expanded memory block at segment: %X\n", segp);
/ H" I. Z6 h5 A9 R* belse
% P5 r6 p7 X; J5 K) tprintf("Failed: maximum number of paragraphs available is %d\n",
9 s7 h# j6 s0 p' ?. b8 V: zstat); </FONT></P>
! E  l4 |$ G& x$ O- u5 U3 }<P><FONT color=#0000ff>freemem(segp); </FONT></P>4 j3 T; y6 A8 K* A: y
<P><FONT color=#0000ff>return 0; 7 D' C- C! L# k- h% P
} " h4 T) \. {7 Y
</FONT>
3 B9 c$ |8 H* I9 u</P>, Q$ Z7 U2 n" s9 f$ q
<P><FONT color=#ff0000>函数名: setbuf </FONT>
% F( J, _$ i- _* N/ S3 G, b; S功 能: 把缓冲区与流相联 $ C* x: m8 v: u) _
用 法: void setbuf(FILE *steam, char *buf); 8 N1 h* D" P% Y  g) u. o
程序例: </P>& S0 K8 [0 l) D3 {. K
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
/ Z5 Y& q5 Z0 ^) [( _; F<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ . N0 K! |$ U% J3 {8 a0 I
char outbuf[BUFSIZ]; </FONT></P>* V! P  x7 G" Y# L3 c4 I" e
<P><FONT color=#0000ff>int main(void) 7 q! S2 {& R: h! l0 c  b
{ 4 p0 q, p: y( m) R- q2 P- \
/* attach a buffer to the standard output stream */
$ N; L% P8 R+ u" Xsetbuf(stdout, outbuf); </FONT></P>
0 N* e' K8 z6 X* S4 V; N<P><FONT color=#0000ff>/* put some characters into the buffer */   e$ q+ {* A* }6 ?+ j; L
puts("This is a test of buffered output.\n\n");
! O8 N% R' Q) e) ]puts("This output will go into outbuf\n"); 8 K, Y: @# R! I+ ?
puts("and won't appear until the buffer\n"); & x9 P$ h- Q8 h
puts("fills up or we flush the stream.\n"); </FONT></P>7 D' R* T. g5 {& ]' u  a
<P><FONT color=#0000ff>/* flush the output buffer */ 1 E6 `- C) r" G
fflush(stdout); </FONT></P>  {. m. r2 q) Z$ \; a: i
<P><FONT color=#0000ff>return 0; 2 k4 B& @- M( H' [/ M2 H
}
4 k* X9 H( ^5 Q- g0 X& [</FONT>' B, R1 \# ]1 ~1 G2 V% N& l4 `
</P>
: D8 n4 [4 Y5 z: l( I2 X<P><FONT color=#ff0000>函数名: setcbrk</FONT> 8 R5 w0 @! Z3 N" ]$ k, Y
功 能: 设置Control-break * ]- Y& {5 s" n; v+ {! d
用 法: int setcbrk(int value);
8 s  Z4 R  w" y0 `程序例: </P>& Q) g5 c- d3 f* k. F' b8 B
<P><FONT color=#0000ff>#include <DOS.H>- s$ I5 n4 T8 p5 U
#include <CONIO.H>0 Q6 P) k( p, C# X0 D! S
#include <STDIO.H></FONT></P>
9 i1 L- m1 I- {<P><FONT color=#0000ff>int main(void) . D% X$ e3 [# |+ s! L8 v. L/ }
{
# t* @& g1 F, O7 Z# w( p4 I& qint break_flag; </FONT></P>( k5 \5 i6 d$ w
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
' r0 ^3 h/ v; v+ P9 Tprintf("Enter 1 to turn control break on\n"); </FONT></P>
& `& ~! P7 @. d<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>
. f1 {2 u) X  R- f* B* o<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
8 q& }0 C4 X: w- ]+ M$ {: {$ v<P><FONT color=#0000ff>if (getcbrk())
' e% e$ ^4 b; O) B0 J' W9 S  Q5 fprintf("Cntrl-brk flag is on\n");
' k6 d. v4 c  R  Q, l( `# Jelse " x( B, O6 b$ d
printf("Cntrl-brk flag is off\n");
+ w  Y; Z( Z. X: r( Z# oreturn 0;
: p3 I* r2 C9 y  K, s# K) [} 6 n/ X" T9 x  g  i! ?+ t

& R$ \% S3 r( V7 T8 T5 D</FONT>$ G' {, U; r( `. u
</P>5 c0 M0 Q& ~# C; q
<P><FONT color=#ff0000>函数名: setcolor</FONT> " j" w6 l0 L$ _+ G! T) A' X! w
功 能: 设置当前画线颜色 & v- T  L0 H) m2 e' P
用 法: void far setcolor(int color); 3 A$ Q& ^0 w0 G( I
程序例: </P>( l% ]' Y% n2 j4 h
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 o- n/ u1 N3 M3 @
#include <STDLIB.H>
" S1 C1 K+ o: b. ~" Q" y$ b$ Y#include <STDIO.H>2 l% E3 l6 s" v+ E. A
#include <CONIO.H></FONT></P>2 ~; f# N( `4 v, f/ Z
<P><FONT color=#0000ff>int main(void)
! l* e' A7 E7 @7 p' C# |6 N) v{ 4 ]/ g) O5 v. a& X' Q
/* select a driver and mode that supports */
1 k( v# E% T, W/ p6 ~/* multiple drawing colors. */ / U1 I9 C# x4 ]6 S3 r
int gdriver = EGA, gmode = EGAHI, errorcode;
0 C3 l/ A0 Z9 Bint color, maxcolor, x, y; , o: n4 v: D, Z) \/ B
char msg[80]; </FONT></P>, u  h9 I0 k  N3 ^$ b& M  v, a
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - |( z' r# x! m' R$ Q2 c5 D+ c
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) }- ]& Z) f$ [  D6 J<P><FONT color=#0000ff>/* read result of initialization */
# q6 a  \3 R, oerrorcode = graphresult();
, O, D$ i) T2 A! m" eif (errorcode != grOk) /* an error occurred */ ! H" Z7 t' K+ t4 x3 k
{ 1 y5 |' f% g0 k5 t, ?4 {
printf("Graphics error: %s\n", grapherrormsg(errorcode));
; w. D2 C3 N9 u2 l' U/ z& g+ mprintf("Press any key to halt:");
6 }" p6 ^& g9 }1 `: m+ O, Dgetch(); / {" y  `) i" H% V5 A0 N( _8 K
exit(1); /* terminate with an error code */
3 g* o3 o1 w) r% [/ @# E; k; I5 c  F} </FONT></P>( o* G: ]$ U- u6 U& _- `# R6 A. c0 i3 Y
<P><FONT color=#0000ff>/* maximum color index supported */
# ~- [$ ^' i8 q. B1 {# Hmaxcolor = getmaxcolor(); </FONT></P>" D# f- h* u0 A* u8 {' s; T
<P><FONT color=#0000ff>/* for centering text messages */ 4 J* g8 @. i7 \$ E# m- L" {
settextjustify(CENTER_TEXT, CENTER_TEXT); 6 b( U: h6 v1 @% X
x = getmaxx() / 2;
/ @3 H- {* a& E6 zy = getmaxy() / 2; </FONT></P>' T; S/ P* ]  J2 L" i/ s
<P><FONT color=#0000ff>/* loop through the available colors */ ; C8 e  l0 _* E" E
for (color=1; color&lt;=maxcolor; color++)
4 f$ I, e5 P) w9 v0 [9 {3 i; O& s{ # P6 L. f6 w1 {" c
/* clear the screen */ ' \+ R" `  n, v" A: S2 {
cleardevice(); </FONT></P>
( F  A& }8 k% U<P><FONT color=#0000ff>/* select a new background color */
( {+ p8 u8 z* q1 [setcolor(color); </FONT></P>
. ~; ^( q/ A3 \<P><FONT color=#0000ff>/* output a messsage */ ' x2 X* Q# J# N) j9 |( z3 ~
sprintf(msg, "Color: %d", color);
  o4 U+ G3 h# j; d9 T4 {outtextxy(x, y, msg);
) a2 e. d- c6 |& R# a) P, ugetch(); ) E5 V& H8 D& q1 }2 U
} </FONT></P>6 D- S. _( _) q: N" }; Y& E( Q: x( g# G
<P><FONT color=#0000ff>/* clean up */ # R5 F: D7 g4 t) a. _* w9 v
closegraph();
2 v; }" G, O4 j* h) J# o' r. Ireturn 0;
: o! c. v# N' F+ }0 J}
* D# H" I8 V3 t; C</FONT># f' Z' i% Q$ f: `5 N2 Y/ p5 `) `# J* T
</P>
8 Z- |  r9 }6 M7 i( p1 C- F<P><FONT color=#ff0000>函数名: setdate </FONT>
; H+ e: Z. `5 K4 G4 c9 a. w功 能: 设置DOS日期 % ]; A: h" h6 j8 l: N
用 法: void setdate(struct date *dateblk);
  d" @& ]! |6 k程序例: </P>( e5 D6 s( L' a  z" A
<P><FONT color=#0000ff>#include <STDIO.H>
2 i9 r- y6 T) }+ B; |#include <PROCESS.H>5 j( D8 R8 o# I& d. \+ m* T" I
#include <DOS.H></FONT></P>
3 P1 o$ U7 d% S, H# k<P><FONT color=#0000ff>int main(void)
2 D) Q/ U7 P& s; [+ Q{ 5 q9 ~& ]: N- L" l% }5 B
struct date reset;
* p% m8 t; y- L2 q8 |! f1 Pstruct date save_date; </FONT></P>
- U. _; j' g( Y8 Z& m7 `9 o<P><FONT color=#0000ff>getdate(&amp;save_date);
6 c' |" g% g* u9 U; X. R3 Sprintf("Original date:\n");
& Y0 f* D( v: c" u- l2 zsystem("date"); </FONT></P>
& E5 n0 F  ^  U( K9 ?<P><FONT color=#0000ff>reset.da_year = 2001;
" a  k% d! n( ?/ zreset.da_day = 1; 8 d+ }9 g- G6 r6 u. q6 y
reset.da_mon = 1; + u) r5 Z+ C8 K; A- |1 @
setdate(&amp;reset); </FONT></P>% A% ~9 ^+ e$ l; C# Y- M7 X8 n
<P><FONT color=#0000ff>printf("Date after setting:\n"); , `4 ~# L- q! j" O
system("date"); </FONT></P>( t1 E# c0 F9 D7 t
<P><FONT color=#0000ff>setdate(&amp;save_date);
+ k$ ]- a/ Y+ e  p) z: ^printf("Back to original date:\n"); ; w- _4 T; g5 F1 C
system("date"); </FONT></P>1 ~3 E' |/ L7 ]3 j7 @
<P><FONT color=#0000ff>return 0; ; l" I% u) X/ |
} " ^& Y; `: \; t* k' ]3 Y# |/ G
</FONT>
1 o8 k' K" @. ]3 V. S( s</P>& p3 N9 d- b, E! i9 e1 L# L
<P><FONT color=#ff0000>函数名: setdisk </FONT>2 U8 n& N7 f' n8 t# _+ @6 o7 E9 _
功 能: 设置当前磁盘驱动器
4 y9 y9 e# y* |1 G# T0 @" s! {: c用 法: int setdisk(int drive);
" K9 j! @8 n; D8 a0 w程序例: </P>
: z1 V% s' C: T& ^1 J2 N<P><FONT color=#0000ff>#include <STDIO.H>
6 @  J+ a8 P' c#include <DIR.H></FONT></P>: o* \) N0 g8 R
<P><FONT color=#0000ff>int main(void)
1 H% j% S& Z! V4 o{
5 A# m0 U2 O3 k. V) E& ~' L+ z' xint save, disk, disks; </FONT></P>
" f- W" O8 a* x, X<P><FONT color=#0000ff>/* save original drive */ ; D( c7 }( }/ n
save = getdisk(); </FONT></P>- G  H) W" ]- m/ y
<P><FONT color=#0000ff>/* print number of logic drives */ : ?* L. N# b( F9 c: y
disks = setdisk(save); 6 i  e$ \( C* F: U) _6 g
printf("%d logical drives on the system\n\n", disks); </FONT></P>
# _! h. r" D' g7 E, B& w, s<P><FONT color=#0000ff>/* print the drive letters available */ 3 j( n1 P9 f- F* P
printf("Available drives:\n");
: j* m+ o/ y% f) T$ s/ R7 wfor (disk = 0;disk &lt; 26;++disk) ! Y$ R  s0 l& R9 M/ i! a
{
" D* j, A8 z# ~7 _3 _$ |7 \setdisk(disk);
8 T2 W6 S  {7 }/ a7 f  v2 W7 nif (disk == getdisk()) # d( _! f+ @+ P' f+ j8 M
printf("%c: drive is available\n", disk + 'a'); ; N/ E" Y  o  @) z
} ! _- w( q0 u0 X6 c* |
setdisk(save); </FONT></P>
. t2 k6 X! [5 Y8 x9 l6 q<P><FONT color=#0000ff>return 0; : u! b- J- g) H
} </FONT>
9 f: c* M1 m+ E7 @/ G8 t) b+ Y* Y* a" a: U9 p* i% J
</P>
+ g; }5 A7 a6 p$ _% H4 Z<P><FONT color=#ff0000>函数名: setdta </FONT># ]; q" h- K( H
功 能: 设置磁盘传输区地址
2 N- V" q9 E5 w1 I4 N) A9 }用 法: void setdta(char far *dta); 7 r, D$ h3 i6 k- z, a
程序例: </P>+ h9 b! [) w% x6 i% ~
<P><FONT color=#0000ff>#include <PROCESS.H>
, J9 j# |) ?3 B5 p9 @* [+ p# C1 e#include <STRING.H>2 e( c: [0 ~' y2 y; T- f
#include <STDIO.H>% ~3 P+ U: a# W6 T- K* f; M
#include <DOS.H></FONT></P>
4 b- ]' ^8 v) y8 ^/ l; K% B' P<P><FONT color=#0000ff>int main(void) 6 z# `) u3 a. [
{ 6 l0 ?' B: }; v9 \+ B
char line[80], far *save_dta;
5 h6 ?. k, p2 R) x% d/ Ichar buffer[256] = "SETDTA test!"; " X% o, R: B* x
struct fcb blk; * W/ ?( D& z: [6 l4 B
int result; </FONT></P>
) Z; E# G! Z( h' i( c2 ^/ J6 g0 N<P><FONT color=#0000ff>/* get new file name from user */
# Z  w' M" J8 v2 T, b* Lprintf("Enter a file name to create:");
0 i/ m, M/ `  i' U; l  e3 mgets(line); </FONT></P>
1 u& s5 X8 l8 m  P8 R<P><FONT color=#0000ff>/* parse the new file name to the dta */
4 V5 J, N: S; Z' \  b: Wparsfnm(line, &amp;blk, 1);
% f- N- f: k& |* p9 }: Fprintf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>5 H& H0 M- E. W3 e/ y1 F( q
<P><FONT color=#0000ff>/* request DOS services to create file */
0 q8 V+ w. u8 K, X) \" Yif (bdosptr(0x16, &amp;blk, 0) == -1)
; w! J( M: S/ t; y{ * M4 }2 M" j+ G6 r
perror("Error creating file");
' x; n7 C' O# \8 N0 b$ x* T. z7 Uexit(1);
/ T9 h- t" u& I/ I} </FONT></P>7 C& M& h0 P9 @8 C5 D1 ^
<P><FONT color=#0000ff>/* save old dta and set new dta */
$ I3 N. D' M4 L. r( O8 _. Q* Usave_dta = getdta(); ) Y, B. x) a: S, ^2 B. _
setdta(buffer); </FONT></P>
( r  g$ x, P# J- T6 l$ o<P><FONT color=#0000ff>/* write new records */ 9 L4 P( d9 D' k2 P& ?0 Q" }* d/ e: c
blk.fcb_recsize = 256;
% f$ u9 A6 A/ \! [blk.fcb_random = 0L;
& M" j+ \: S7 [/ Y, B# zresult = randbwr(&amp;blk, 1); $ ~% O9 [. |  V* F
printf("result = %d\n", result); </FONT></P>- d, ~& R- v4 S4 N: v4 D% b
<P><FONT color=#0000ff>if (!result)
6 H- `% m$ M% w( S2 Rprintf("Write OK\n");
4 c7 i# a! j, h. celse " n  J& t8 Q# v- C
{
7 A5 q- f" D8 h2 b4 Gperror("Disk error"); 2 [0 d; B9 J$ m1 [- V
exit(1); - U# i. Z! }9 J% ?
} </FONT></P>
8 e7 Q# s+ ^/ t, q<P><FONT color=#0000ff>/* request DOS services to close the file */ $ n4 k- _* ~6 _6 [4 }$ n5 q
if (bdosptr(0x10, &amp;blk, 0) == -1) - o: v2 e6 r; h; w
{ * b- y# s8 w- [. b5 t
perror("Error closing file"); + Y" l% f& r6 f; ~* Y' z
exit(1);
! [; G# A( Z3 {+ Q/ `: c8 f} </FONT></P>( }" Z( q3 t$ x/ j- Z
<P><FONT color=#0000ff>/* reset the old dta */
% ?: j2 g& j$ osetdta(save_dta);
# G0 \3 M* P# \( ]; \; B1 i" k+ wreturn 0; 7 V2 x1 c5 A' x( j" Z+ |
} 5 a3 h9 M. ^5 r# }% Q9 |
</FONT>
& G! J) G, c+ ?$ S5 F</P>
& `6 [4 B  Y9 ~3 Y8 Q4 H/ ?# q; D<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
. {$ H9 k2 i1 N, X, Y功 能: 选择用户定义的填充模式
0 y. o4 _' ]. y  ~用 法: void far setfillpattern(char far *upattern, int color);
: g& Y  x) n: E' s程序例: </P>) \/ Q* y' V* h. O
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 E8 J% \) z6 U) y% E3 I6 a
#include <STDLIB.H>
& e! H  \. X4 Q# t( Z6 t#include <STDIO.H>/ u" m/ a  P! ]% p: u. w
#include <CONIO.H></FONT></P>
5 J2 Q: ^( U6 c( ?<P><FONT color=#0000ff>int main(void)
; H, }/ K3 x1 t4 e2 D{
0 g( ~% U5 k2 ]5 P" m* v2 L/* request auto detection */ & E' L5 `- M: W( J
int gdriver = DETECT, gmode, errorcode;
" B% J+ ]% P; u# Z. Gint maxx, maxy; </FONT></P>9 W1 {$ O, Q, _3 H  w; |- M  H
<P><FONT color=#0000ff>/* a user defined fill pattern */
) w) o; ~: A" T, R3 `char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>
! L5 M1 y) x- S5 J2 G+ c<P><FONT color=#0000ff>/* initialize graphics and local variables */
% B  g) }6 s/ k8 `5 {0 d1 f9 `initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, V7 c6 h# l* Z5 A5 S5 ~0 @
<P><FONT color=#0000ff>/* read result of initialization */
7 m3 L$ s) i" F& M) ~, P8 herrorcode = graphresult(); ( j/ [) t. k# w. k  t
if (errorcode != grOk) /* an error occurred */ 9 ^; H3 X4 H4 B6 b/ ?8 h
{
. R: i) x, ~) C1 k4 ^3 C3 A3 H$ dprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 9 _$ {) F4 d' Y4 q( _
printf("Press any key to halt:"); 7 D0 S5 I( V+ g  P' {
getch(); , B9 {9 i; K/ q" p0 Y, O1 j' c& O6 r
exit(1); /* terminate with an error code */
7 h# ]& e  {) E% q+ P% i4 [} </FONT></P>/ C2 r* D* C- c2 q
<P><FONT color=#0000ff>maxx = getmaxx(); * J$ Y, }1 i' X% p" b% ~' H
maxy = getmaxy(); / S% a0 E2 c* |2 p" Z0 h
setcolor(getmaxcolor()); </FONT></P>8 G2 v1 M# y/ j$ G1 s3 U- t2 C% h
<P><FONT color=#0000ff>/* select a user defined fill pattern */ % w' \8 ?8 F# Q. Q
setfillpattern(pattern, getmaxcolor()); </FONT></P>' q. h1 B5 ~! P; v& o2 U6 O  |( a
<P><FONT color=#0000ff>/* fill the screen with the pattern */ ; ?- J% q# k6 V/ P6 ?+ Q
bar(0, 0, maxx, maxy); </FONT></P>% X) g% P; ]$ z3 D, x- d
<P><FONT color=#0000ff>/* clean up */ " N4 _3 h) D. {
getch();
+ i# Q  r) S$ P+ Z# t5 X7 Jclosegraph();
' n' Z  G# H$ B/ L% Zreturn 0;
$ l. T7 k) U9 m9 x2 ?} & \' b  g) m3 D8 l7 e  ?& v4 k
</FONT>8 N! ?' G! D( `0 l$ p  a0 J
</P>
' B& r! _1 m4 D<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
7 H3 G  u; A- }' `& V功 能: 设置填充模式和颜色 ' c( D1 X5 t* p9 T. S* ^8 ^" L
用 法: void far setfillstyle(int pattern, int color);
3 ^1 u0 h3 O, q程序例: </P>
& f( `+ X5 R  c9 l; b( q<P><FONT color=#0000ff>#include <GRAPHICS.H>- j6 T. X3 n  q/ ~7 y/ x" w# O
#include <STDLIB.H>
3 {, E5 o1 X+ R- ?. A* @# O  E#include <STRING.H>& G1 Z6 X% O; Y
#include <STDIO.H>
0 W% E5 r  u3 _9 l% d6 m5 @#include <CONIO.H></FONT></P>
" T; w, v/ o. ]' h  P6 K5 \/ x<P><FONT color=#0000ff>/* the names of the fill styles supported */ 1 x1 J; P* Z: W" c& ~
char *fname[] = { "EMPTY_FILL", . Y) p0 q9 N+ [0 W% l7 {7 |4 l/ h5 c
"SOLID_FILL",
9 Q8 F* Y) V/ [9 H! i2 c"LINE_FILL",
0 P( [' p! U5 }" f"LTSLASH_FILL",
  O& ~- z8 h: X9 _5 K! X"SLASH_FILL",
8 S0 Z' F! [( V" F$ g+ W"BKSLASH_FILL",
5 y3 {9 D( |3 c' }0 V& |"LTBKSLASH_FILL",
4 E. u$ S: \" H# O8 J6 x2 @"HATCH_FILL",
8 E" c' S% T( x! N/ {$ I"XHATCH_FILL", 2 x8 G/ s5 u3 O. P7 l6 _& b  o" ~7 O
"INTERLEAVE_FILL", : Y8 p& d3 q/ P: E* j* x- C6 |
"WIDE_DOT_FILL",
& o/ T  h$ A1 C- Z"CLOSE_DOT_FILL", ( t2 U9 a; U, b- u
"USER_FILL" 4 |5 j+ V7 I2 q+ m1 G/ L. [
}; </FONT></P>
) L) a  o5 a" A, ], t" Y' [<P><FONT color=#0000ff>int main(void)
6 K* k' h- ~: b/ E; J1 V{
! l* R% \4 S0 z1 [/* request auto detection */   F/ {) ?/ x/ K# D. p$ g3 x+ b
int gdriver = DETECT, gmode, errorcode;   N+ _! h  D) ?/ k
int style, midx, midy; # T1 [" L$ u7 _, C' ^3 I* ?
char stylestr[40]; </FONT></P>3 v8 O& ^5 ?1 Y$ s' `4 Z
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ Y' e6 f) c  k9 J
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 ~6 n7 H+ G8 }* `3 K9 k
<P><FONT color=#0000ff>/* read result of initialization */ $ X0 J8 H8 y/ @9 p  S
errorcode = graphresult(); 5 @: D% }) a, d
if (errorcode != grOk) /* an error occurred */
9 z2 ]% W# I! v3 @; _: W. P% Z{ 3 N  Q, F! }! ?; f4 K1 Q# A& m/ C
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 u, D: k, {4 s& T
printf("Press any key to halt:"); 3 B: ]  W) {/ z
getch();
1 V; Y3 o1 k1 z) Kexit(1); /* terminate with an error code */ 4 x; O1 ~' b0 G
} </FONT></P>) S- ^4 `1 m6 S1 X+ t
<P><FONT color=#0000ff>midx = getmaxx() / 2; $ z# |3 b4 P1 Z" `
midy = getmaxy() / 2; </FONT></P>
* N6 u) }2 s9 D# o: e<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) ' v, F' B/ e: I( h
{ ; `' Y% I7 d* r* n: }/ y
/* select the fill style */ . E8 C7 C+ v" \; `  e
setfillstyle(style, getmaxcolor()); </FONT></P>
1 g) G: \* g4 g' k- H- |3 T0 q<P><FONT color=#0000ff>/* convert style into a string */ 6 @% E  G0 }+ E3 v$ |' _7 F1 H
strcpy(stylestr, fname[style]); </FONT></P>% f1 b, d! c2 d
<P><FONT color=#0000ff>/* fill a bar */ - n8 D  Q+ @6 p5 p, q/ w6 b: P
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>& v' R2 z) r' ]3 \2 n
<P><FONT color=#0000ff>/* output a message */   }; S( b3 t' B9 ~6 \5 V
outtextxy(midx, midy, stylestr); </FONT></P>7 S& `3 x2 x0 {2 M! H' l# s* U
<P><FONT color=#0000ff>/* wait for a key */
6 N7 M' G% e" Mgetch(); / j# ], h  L+ v" p6 S) x( {0 G3 z
cleardevice();   u& U0 d; u8 A6 p
} </FONT></P>
# f* S. M7 P2 u$ S<P><FONT color=#0000ff>/* clean up */
+ x$ K- n; I* S( {6 o  Jgetch();
! f" S8 Y# W3 e6 V+ D' \( ~" a, ?closegraph();
* {3 H9 V& r' V/ jreturn 0;
/ c/ t- K9 w7 h( Z0 T! O} </FONT>! a; F2 m1 a4 u1 U  Q7 i
4 M$ J$ `% y1 a4 h& ^
</P>
& r5 S7 z8 f: M" B8 u<P><FONT color=#ff0000>函数名: setftime </FONT>
5 v' e  t4 b: v/ |功 能: 设置文件日期和时间 : H6 e& J, i3 `, [& E+ m
用 法: int setftime(int handle, struct ftime *ftimep);
0 t( [8 E: x3 R6 y; g9 E5 H程序例: </P>
* ^$ D8 N* m" J4 C<P><FONT color=#0000ff>#include <STDIO.H>6 @% H1 {  y) U; a
#include <PROCESS.H>; c% d2 a& R8 @. v6 K$ m
#include <FCNTL.H>2 D. j6 l  n6 c, A5 G" M
#include <IO.H></FONT></P># l& [2 y6 D( |# O& M
<P><FONT color=#0000ff>int main(void)   G& M# b$ e$ F9 S
{ 2 y5 H, K9 \4 u
struct ftime filet;
  `0 Z" _8 D) eFILE *fp; </FONT></P>$ _$ m* r2 l* {  A" m3 f
<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL)
( E7 q& l( M* f& \( T, H3 V* W{ ; t& ~0 T1 }( v2 Q/ e7 ], l
perror("Error:"); ' S7 K2 C: Q" H5 {
exit(1); 9 f( M. ], i8 @9 @' I* q/ e
} </FONT></P>
( r6 g. X. t# [% @, l' V<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>2 K. R: p4 r+ q) `- o2 i
<P><FONT color=#0000ff>/* load ftime structure with new time and date */ 3 M1 `; ~" v* {9 A7 Q
filet.ft_tsec = 1;
7 z5 [! H1 U0 P  R# u5 H) J% hfilet.ft_min = 1;
" J. Y- v8 i! j  r# efilet.ft_hour = 1; * A9 v: e( |3 Z! Q) S' q* U4 M: R
filet.ft_day = 1;
7 D3 B5 `; L' g# h. V0 Lfilet.ft_month = 1; + e0 o& R% {/ n1 g0 b% x3 E2 q0 y
filet.ft_year = 21; </FONT></P>0 I$ y/ c. o1 T
<P><FONT color=#0000ff>/* show current directory for time and date */   T" e% @6 o. s  s) g
system("dir TEST.$$$"); </FONT></P>5 |+ x4 q. X6 ^  D: `4 v
<P><FONT color=#0000ff>/* change the time and date stamp*/
, N0 Q$ ^: s: y. s+ p, D7 I% O7 W9 ^! S* a6 Vsetftime(fileno(fp), &amp;filet); </FONT></P>+ Z5 P& k4 Z- O  g9 ~! T
<P><FONT color=#0000ff>/* close and remove the temporary file */   l% M, K( I% w9 F3 N: N1 C" Q4 ]# o5 ]
fclose(fp); </FONT></P>$ v/ e( M5 B+ B, b
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>
; v, }& K. `; J  S" [<P><FONT color=#0000ff>unlink("TEST.$$$"); ' D1 y- q' C4 U0 d
return 0;
& G1 K! l) ]3 }% ]$ F}
5 {; N# |9 g: o' e9 m' w</FONT>
( F# W  A: W* z8 @</P>
8 Q) Q) }2 C( Y9 M  t8 S<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>6 s, s, ?# S+ L! e6 e! _+ l
功 能: 改变内部图形缓冲区的大小 0 P' c( f' N% q' k
用 法: unsigned far setgraphbufsize(unsigned bufsize); - P6 l" R5 A" D5 S, [( C7 x
程序例: </P>' }5 {; p9 k  f$ o; N2 g0 \9 H( R! ~
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 ~6 S; ?- M9 X/ V) U# c
#include <STDLIB.H>
& s- ^7 X' S& x1 s+ n  u8 B4 l#include <STDIO.H>
9 ?* r8 R" G2 I! ]# ?#include <CONIO.H></FONT></P>& L0 M* h' c8 x! ]
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>* g( I- @4 R/ E+ y3 O
<P><FONT color=#0000ff>int main(void) 6 D8 t2 {1 v+ i
{
4 g1 G1 x. H' L5 ]/ S. [2 K/* request auto detection */ 3 M, S  V  P- W  t/ u6 G8 f3 I: X( Q5 Y
int gdriver = DETECT, gmode, errorcode;
: `4 }3 s" P5 F1 Q+ d) lint x, y, oldsize; & r, \- N7 [1 |9 B( n- @
char msg[80]; </FONT></P>
+ }+ h7 x5 n) @: W$ V- N<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ 3 r9 _% }! U4 i
/* before making a call to initgraph. */ 4 q+ w, b- t0 w$ `, `
oldsize = setgraphbufsize(BUFSIZE); </FONT></P>
8 V! p- U) n" i$ k. H! L$ S- ^<P><FONT color=#0000ff>/* initialize graphics and local variables */
+ x/ B; u' p" f! |" Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 t5 q3 r2 I; l1 q
<P><FONT color=#0000ff>/* read result of initialization */
- m0 p- z6 C) m. n; Eerrorcode = graphresult();
  l  `( u! C  x  M$ z8 y( J% X5 J3 yif (errorcode != grOk) /* an error occurred */   v+ X! f/ T0 _  ]
{
7 t3 `" ^' s, Q, a/ tprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 2 C8 D% o9 X) I/ T* {
printf("Press any key to halt:"); , b0 E% C) g. m, `, ^  o$ g1 z
getch(); . \9 y6 `, i- D- q2 e
exit(1); /* terminate with an error code */
" W+ k3 o* J! P8 j, @5 a5 K; r} </FONT></P>0 W! T+ H( C6 g
<P><FONT color=#0000ff>x = getmaxx() / 2; 2 F9 a0 ^7 O9 [( s
y = getmaxy() / 2; </FONT></P>  b! [9 g, J4 L0 [- E; i; t, }
<P><FONT color=#0000ff>/* output some messages */
) j% Y2 m0 i7 Psprintf(msg, "Graphics buffer size: %d", BUFSIZE); 6 v: f1 |# q& n8 B" j0 d1 i
settextjustify(CENTER_TEXT, CENTER_TEXT);
1 H; I) i  P) Z3 vouttextxy(x, y, msg); * M" Y! X! ^- n) r3 ~( ~
sprintf(msg, "Old graphics buffer size: %d", oldsize);
" ^. A8 F: r5 Mouttextxy(x, y+textheight("W"), msg); </FONT></P>
% g+ m: ~* ?/ e, b" w' n<P><FONT color=#0000ff>/* clean up */
" K* l6 z* h1 a" K  |getch(); 7 ]7 d3 q/ T- x" O( |
closegraph();
& F" l1 W, Y5 o# s. a0 p; L5 |return 0;
, B$ f9 @' l) ~}
: Y' ^" y0 m8 I0 E$ P' M7 z" Y3 u! b/ s% b( Q
  `- i8 N) n* A  ?6 J1 l6 Y  C
</FONT></P>- ]/ Z' ^  p% Q# C" `" a
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
+ N4 M$ U" y( b+ }  S! h功 能: 将系统设置成图形模式且清屏 ; r6 F# C9 H$ M" _$ u0 v9 n1 [! n
用 法: void far setgraphmode(int mode);
) k# W4 \9 n# ^/ c1 L( e$ C% j程序例:
; R* z6 B/ W$ i) Y4 [( D1 ^, G! y& W; c1 o
<FONT color=#0000ff>#include <STDLIB.H>" b. u' T; [& ~! D
#include <STDIO.H>
( k  p3 r; p* O) u' X#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
5 g0 N# Z' V4 f3 M1 T+ l$ ]# z<P><FONT color=#0000ff>int main(void) - l& }: V, E! [
{ 3 v1 i# u0 E2 W7 h
/* request auto detection */ * q% N7 j4 W9 D0 c! o/ t
int gdriver = DETECT, gmode, errorcode;
, x& F+ Q, e& G- G+ lint x, y; </FONT></P>
4 ]3 i) k' V2 I<P><FONT color=#0000ff>/* initialize graphics and local variables */ 0 K+ Y$ C- @# B* V, m
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, F* v5 J8 ~% F% i4 C) _, v* ]4 y<P><FONT color=#0000ff>/* read result of initialization */
. W) l. z$ u! eerrorcode = graphresult();
6 l8 D/ t/ I3 w5 [7 ]. m% D3 Mif (errorcode != grOk) /* an error occurred */
- k8 {' |. Y- U6 [0 Z7 [3 }% J{ ) k, I+ I) Q% X1 l7 c: a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 m! A/ g5 _9 [6 z% e$ R- }printf("Press any key to halt:"); * y3 L, H6 r+ N4 g4 L
getch(); $ ~8 q; {4 Y( k7 e4 n2 a. Y6 N% Z
exit(1); /* terminate with an error code */
2 t4 z" U: @) U9 v} </FONT></P>
! E! h% G7 v0 e- _  F' V5 O+ M1 \) H<P><FONT color=#0000ff>x = getmaxx() / 2; + N0 J2 p6 ]( j- F; r* I
y = getmaxy() / 2; </FONT></P>
; o' i6 B" E* @. c! g<P><FONT color=#0000ff>/* output a message */
  J5 n; v0 }& K' A8 m2 vsettextjustify(CENTER_TEXT, CENTER_TEXT);
+ p  a& G% S  V5 W% Houttextxy(x, y, "Press any key to exit graphics:");
- g4 K8 m% S+ U- N% p( Rgetch(); </FONT></P>  G4 \! o+ S0 g/ f) k
<P><FONT color=#0000ff>/* restore system to text mode */ / P$ R- @" L' s, W, ]
restorecrtmode(); # m6 r1 y( w5 S& p& G( a9 q
printf("We're now in text mode.\n");
$ Y5 \7 h3 |' U' u% p  N6 K+ F( ^5 j4 zprintf("Press any key to return to graphics mode:");
  c2 [; P6 `' agetch(); </FONT></P>
' u" n, o* _# w4 G- N7 H5 w; s<P><FONT color=#0000ff>/* return to graphics mode */ 7 T% z# p# f: [, w1 p% J2 l% B; X
setgraphmode(getgraphmode()); </FONT></P>) }3 c  O1 _# j( {
<P><FONT color=#0000ff>/* output a message */
0 o; o7 T& r' h- s' esettextjustify(CENTER_TEXT, CENTER_TEXT); 9 N8 D+ d3 d( q4 Q6 X! {) q
outtextxy(x, y, "We're back in graphics mode.");
# N3 R# W8 M9 |6 d! oouttextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>; X1 Q" |( W1 l
<P><FONT color=#0000ff>/* clean up */
# T, @, i& h8 E% r- ?% h5 D2 }, ^getch(); # p7 O* p. X# R' l4 j3 Q# F
closegraph(); ' I: s: Y" f. }% F3 W+ e
return 0;
% \/ ]3 K& a; K1 J}
! m$ m: ?) Z9 T- l+ O4 ]
6 v: t% [- @/ a& Q! P4 `7 F
. s) k* w4 v7 @  w/ A% @</FONT><FONT color=#ff0000></FONT></P>+ d/ b! Q* x  N4 w9 O; T7 P  B$ k
<P><FONT color=#ff0000>函数名: setjmp </FONT>
) L4 u6 R0 Q$ y$ J) ]+ `- g功 能: 非局部转移 $ c, i$ G. E  x0 @$ C
用 法: int setjmp(jmp_buf env);
- o4 N) V# A$ Q* E' a4 d程序例: </P>' Q* T- P7 Z  A3 D- C4 I
<P><FONT color=#0000ff>#include <STDIO.H>
8 x! `- E4 B+ T#include <PROCESS.H>- |, x2 e9 y- u
#include <SETJMP.H></FONT></P>
- i; H; c$ u; X3 |8 T8 S) f<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
. _# J; J! u' l$ U0 v! a<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>+ w. A+ l8 V( Q3 o! b5 i  t' W
<P><FONT color=#0000ff>int main(void)
! u) O  o# N) Y; t! ?9 ]6 Z{ : M  [' F5 O. g5 @
int value; </FONT></P>
% e2 D2 L" E" [5 o. f2 ^( ?<P><FONT color=#0000ff>value = setjmp(jumper); $ W8 g, i- D: z% S( n3 ]9 A: \5 ]+ I9 T
if (value != 0) & N" I8 h4 ]- b: b6 z4 B
{ . v$ S" ^; [( F2 S
printf("Longjmp with value %d\n", value); 1 b0 {# M5 ~7 r$ L- F
exit(value);
! E7 D9 k7 n6 s2 C' ?}
/ L. i* o2 g* T" ~$ X, k) N: dprintf("About to call subroutine ... \n");
& Y* S9 P) k. P2 Dsubroutine();
7 G' M7 k* v4 A# V9 q9 preturn 0; ! j1 c4 i* n" A, ~- T% d# X# [
} </FONT></P>" i; ]# P9 A" \0 o0 J. r
<P><FONT color=#0000ff>void subroutine(void) 9 k- i# S0 Z7 n/ a3 k
{
% z: o0 B8 k- q$ llongjmp(jumper,1); ) {, d" w: i* h) a% B! r' F& `
} . r9 _3 f/ n, b
</FONT>
, F2 C/ B, i+ l  s( G</P>3 g6 ~) @+ k7 o" J$ o
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
/ Y+ _7 E- n4 D: N  {7 e9 K8 x功 能: 设置当前画线宽度和类型
+ u/ D5 o8 Z5 P# i) T% x  m用 法: void far setlinestyle(int linestype, unsigned upattern);
, g$ m+ t" p+ e5 I8 n程序例: </P>
/ r) f1 _9 ?$ D. R  \<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 z6 Q3 h& l, D#include <STDLIB.H>
( P5 m8 V2 R6 j" \#include <STRING.H>
) F8 u) }9 v' E$ v7 d! U#include <STDIO.H>
' u1 r$ P; m/ P: E* n  p* Z#include <CONIO.H></FONT></P>
- B2 G, F8 t( y+ }7 v. V" }<P><FONT color=#0000ff>/* the names of the line styles supported */ * K5 Z% R, a2 B' K* E8 |, Z) D
char *lname[] = {
- j# a5 i8 ?' u3 Q8 V5 j7 m# Q& [7 w"SOLID_LINE", " z1 ?6 U1 m- I$ D& k
"DOTTED_LINE", , s, Q3 K7 h4 z0 \  v# a" \
"CENTER_LINE",   ^) C- C  R$ J' w, L% h
"DASHED_LINE",
: P0 Z2 |2 S: v7 U% b+ x"USERBIT_LINE"
% V- ^5 H3 s4 n  q0 |+ V6 ^}; </FONT></P>
, ^% \4 V) F: O! \0 @1 w3 c$ L2 ]<P><FONT color=#0000ff>int main(void) $ Y! P; T- X% v- H8 P
{
; p6 a, C; B# \' t/ t* J/* request auto detection */ ; v6 k* |2 Z! v6 K
int gdriver = DETECT, gmode, errorcode; </FONT></P>* ?3 h& o2 R6 O3 `4 ]7 ?1 A0 ^
<P><FONT color=#0000ff>int style, midx, midy, userpat; 9 Y5 S* d3 v1 T
char stylestr[40]; </FONT></P>
, I; Y# i% c- F5 q; S  Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ i5 N; `8 P7 oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
, J# X3 B* B  h& T# r<P><FONT color=#0000ff>/* read result of initialization */
# y: b$ E( O  o; \errorcode = graphresult();
* ^/ s5 U* E, o( d$ jif (errorcode != grOk) /* an error occurred */
6 P: t% M. b/ Q{
2 Z6 y6 r5 t5 v! _( kprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. P' B# }: d% m- J- Wprintf("Press any key to halt:");
) Z! y* v5 H3 u& h0 T8 Igetch(); ( e3 l- P: a* f  d# D
exit(1); /* terminate with an error code */ 3 v! \8 \8 N: \
} </FONT></P>
% A( n& Z: `8 H# b( ~2 u0 s& T<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 p+ [9 X  T" k" J( ^" u$ u8 xmidy = getmaxy() / 2; </FONT></P>
7 ~0 h' @/ Y7 ~' C; e0 _<P><FONT color=#0000ff>/* a user defined line pattern */ . T/ m$ c0 S9 T! z$ V
/* binary: "0000000000000001" */ % E+ [3 p) Y5 Z8 R
userpat = 1; </FONT></P>( C  S4 k. P; C% d8 F
<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
/ T8 j/ L5 A7 e3 y0 }{
. {# J7 }8 j  S3 X$ M/* select the line style */
% i" j. U9 `( g. J8 N! Dsetlinestyle(style, userpat, 1); </FONT></P>. y% i- A$ S$ ]& `9 q5 K
<P><FONT color=#0000ff>/* convert style into a string */
7 D$ t; R$ x& B1 G, ^% astrcpy(stylestr, lname[style]); </FONT></P>; _/ n. ?! E1 \3 E: E' {3 z
<P><FONT color=#0000ff>/* draw a line */ ) U2 B0 j' O/ t2 L
line(0, 0, midx-10, midy); </FONT></P>
+ {2 a  J" R: H8 d4 W<P><FONT color=#0000ff>/* draw a rectangle */ + L2 u3 @7 i9 N7 d# E6 {+ T$ C
rectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
' }' W) T/ E# f8 w6 p<P><FONT color=#0000ff>/* output a message */   ^( P, D$ Y9 d% G  V, `
outtextxy(midx, midy, stylestr); </FONT></P>
8 B' Z( b* E1 ~% X6 k: E<P><FONT color=#0000ff>/* wait for a key */
, D7 c  z9 |, Y( N' V- @getch(); 4 a: R& d. y0 N% Y  G
cleardevice();
7 M/ d; B7 k: W) k' g' k} </FONT></P>: l" L1 s& j2 m
<P><FONT color=#0000ff>/* clean up */ 3 S1 n( s7 ~  ~8 E) A
closegraph();
  p8 t* X, e8 u6 i2 O; `1 Oreturn 0; ) ?; O9 W- D" i: l2 q. P
} </FONT>
0 @: K2 O( |' U$ z' B1 L
3 A$ M* K3 ]; {  _5 ^
3 d( L9 P$ s+ W. z1 q9 D6 x</P>4 P, C# Z/ \5 V, `5 w. ?4 V
<P><FONT color=#ff0000>函数名: setmem </FONT>- m3 `( I4 o' ~0 S* \$ v9 j
功 能: 存值到存储区 + ~' S( l5 j+ s$ P* k
用 法: void setmem(void *addr, int len, char value);
! x4 g0 R2 z8 {  ~9 T3 l% a程序例: </P>
  e9 V; \; S7 s1 c<P><FONT color=#0000ff>#include <STDIO.H>, i& P  ~7 A; [$ v
#include <ALLOC.H>
% i# T! O  N  o. ~1 P0 P; Q#include <MEM.H></FONT></P>% d: u+ F8 i7 y" @
<P><FONT color=#0000ff>int main(void)
6 H2 x& k0 z2 R6 [/ I{
1 X3 {7 V& J. Mchar *dest; </FONT></P>
1 q0 ?! [0 S. P3 E4 W" F8 ~<P><FONT color=#0000ff>dest = calloc(21, sizeof(char)); 0 c3 b, y1 O9 _( o
setmem(dest, 20, 'c');
' F$ d) s8 Y5 F( _printf("%s\n", dest); </FONT></P>4 A) ^5 [8 I2 }/ V% f
<P><FONT color=#0000ff>return 0; 5 C/ f8 N$ C4 J) l$ I8 x9 ]
} </FONT>9 a3 S( k: s, F( a, u. Z9 o

0 K7 G0 P8 k( T, {2 P1 C  k" }2 Q4 K: }" T% b
</P>9 T3 l- S6 j: d4 M$ \; S
<P><FONT color=#ff0000>函数名: setmode </FONT>
* J+ q2 ?0 @# m/ Q* f5 U% F* Y功 能: 设置打开文件方式 ; X6 {. q2 G5 T. j
用 法: int setmode(int handle, unsigned mode); % H! z+ k2 x% Z. G$ A
程序例: </P>! j2 r/ s- k7 k! n% z
<P><FONT color=#0000ff>#include <STDIO.H>
( _/ T  E; Q, O$ {" s#include <FCNTL.H>
- H; J" V1 V* N8 ~2 B#include <IO.H></FONT></P>
" t: i5 f( H' P2 x# {<P><FONT color=#0000ff>int main(void)
3 L# q0 e# z- S6 Y- Y{
- m/ a5 i  [# hint result; </FONT></P>
; D! T, S: \% Z1 m- l8 `- r' f' o<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); ( T) O' |0 ]/ b) l
if (result == -1) 6 j  o/ ?2 e7 q2 b; e# Q, g  i
perror("Mode not available\n");
  m: C3 ]& O0 ^4 e- b# d7 Helse " a! v% c4 g+ ~; `  }) F, u
printf("Mode successfully switched\n");
9 j# s+ m; e4 }" ^- d+ Preturn 0;
0 h9 ?: u$ X. U. p6 J}
& Q+ r. Y0 |% a  D6 H  T- L8 B+ Y; h  F; ]1 x
</FONT>
5 E( ^- _% ]- X5 M; i</P>5 Z; t( ^/ D* ~# ?
<P><FONT color=#ff0000>函数名: setpalette </FONT>
* ?' n! U  w, B2 U! r% Y功 能: 改变调色板的颜色 3 v0 y! r5 ?8 s
用 法: void far setpalette(int index, int actural_color); ; @4 F+ p8 ^/ i7 J' e( r1 h
程序例: </P>0 ^; D& }, }9 q' f+ e6 c* P  F
<P><FONT color=#0000ff>#include <GRAPHICS.H>( {' R5 O4 O' i6 c( W( h" X- S
#include <STDLIB.H>
6 h) D6 H: E9 Y1 T2 H/ V* ]#include <STDIO.H>
' M) ^5 K4 I" c1 G3 I#include <CONIO.H></FONT></P>
( b  d9 _" L$ E3 o% z<P><FONT color=#0000ff>int main(void)
, Q& E5 k# k  |{
/ p/ |0 m/ R% q$ c/* request auto detection */
% Z. A% _6 o: J( O. Jint gdriver = DETECT, gmode, errorcode; 0 v. i$ D! T! m0 ?) L. ]
int color, maxcolor, ht;
+ Z$ @9 s3 Z. Oint y = 10; 4 J( R' r, P, N/ Q3 O" A( m! l
char msg[80]; </FONT></P>
6 z1 D: p4 g# Y$ R$ J' m8 @7 P<P><FONT color=#0000ff>/* initialize graphics and local variables */ % V+ @5 J" }( r- b
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 B' c3 E! R( v4 x1 C2 s8 m
<P><FONT color=#0000ff>/* read result of initialization */ ' ~7 Q0 k, M7 G6 K9 }8 h
errorcode = graphresult();
6 K! k! G' G3 _6 N6 H( mif (errorcode != grOk) /* an error occurred */
" M7 x, `9 V- u6 i( o{
* Y& S  t9 Q) L% K/ D5 K; fprintf("Graphics error: %s\n", grapherrormsg(errorcode));
( Q% M. t: Y5 b: |; H( ^; oprintf("Press any key to halt:");
" W0 |; g0 x! y, {# Z! r0 wgetch(); 3 A: A" r4 W% R1 N
exit(1); /* terminate with an error code */
  u) e0 J7 e/ h/ m} </FONT></P>
# ]6 u" k+ D( g<P><FONT color=#0000ff>maxcolor = getmaxcolor();
. h+ O# P& _. e+ n' r8 Hht = 2 * textheight("W"); </FONT></P>: c" p% Y* M1 O7 u
<P><FONT color=#0000ff>/* display the default colors */
. e* C4 x9 W) c7 X8 W9 Kfor (color=1; color&lt;=maxcolor; color++) 2 E5 V6 T% y( ~/ F3 p/ H" n
{
/ j& d  t" s8 {* ]$ C" Gsetcolor(color); * g8 P$ q4 q2 v  e
sprintf(msg, "Color: %d", color);
8 ~" g; O6 q7 O' Youttextxy(1, y, msg); 7 {0 a: O9 R$ t+ a2 {
y += ht; ' s- Y; O$ K  }6 a& Q1 X4 C3 G
} </FONT></P>
/ ~) t2 B! ~) T/ Y4 B7 a<P><FONT color=#0000ff>/* wait for a key */
1 y; z2 v; b0 Y' Vgetch(); </FONT></P>$ @0 B2 }1 K, X
<P><FONT color=#0000ff>/* black out the colors one by one */ / j: u3 n+ q+ j1 K# z
for (color=1; color&lt;=maxcolor; color++) " S, `. B  @# U8 W( D
{ 0 p) h7 @: h1 r# I& j
setpalette(color, BLACK); ! O; e: b8 O, I: o  B
getch(); 0 G- i& l8 g7 |  x
} </FONT></P>
, `2 t3 [: Z& @) t<P><FONT color=#0000ff>/* clean up */ " j1 B: K: y2 x8 ~. T% I$ x4 m
closegraph();
# a8 `8 N# w( Q5 n5 Hreturn 0;
  D, I4 g( `9 A5 @6 T} + I- R! I, ^& F
</FONT>
8 [& a; G9 ]( z; F</P>4 n6 m# R9 A: i% t5 @  H; i2 l
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
# p( n/ c- Z) [# r功 能: 定义IBM8514图形卡的颜色 ! N9 `7 p* Q2 H$ r0 i" l
用 法: void far setrgbpalette(int colornum, int red, int green, int blue); , W2 g! ?  s3 y4 O$ _
程序例: </P>" ?6 @- a: D: S7 i9 u. @* Q/ m7 S6 F/ H+ q
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ v& }4 V, f" r  `
#include <STDLIB.H>  u5 i7 b! G/ w
#include <STDIO.H>
8 l# o! G) B3 p  Z; ?% D#include <CONIO.H></FONT></P>, T9 A) E  P5 Y1 o
<P><FONT color=#0000ff>int main(void) ( C3 g! k5 l) u# q/ S4 v
{ 4 `! f* [2 g: I/ H
/* select a driver and mode that supports the use */ 0 T# Y" Q  u' p% h. _
/* of the setrgbpalette function. */ 2 q* i+ r6 X; P1 h
int gdriver = VGA, gmode = VGAHI, errorcode;
. @7 p7 y' B+ `3 u9 vstruct palettetype pal; + ]+ g) C8 n5 v0 s. Q& ~# o) T& A
int i, ht, y, xmax; </FONT></P>0 q2 O: v# d$ A% O+ i+ m
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , ?2 }* m- d# h& g4 o  Y! _
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, P5 p# ]& n/ r0 ~
<P><FONT color=#0000ff>/* read result of initialization */ 1 j* ?3 v9 l; S( ]& A5 b
errorcode = graphresult(); # X3 N1 Z$ W, e) X' G) f' b
if (errorcode != grOk) /* an error occurred */
6 ^; k6 ]9 ?4 U' a+ J1 P# v2 }{
* |% K0 O; s( }$ `4 Dprintf("Graphics error: %s\n", grapherrormsg(errorcode)); # N+ Z. r% C; ?' h! d" ~
printf("Press any key to halt:"); 1 Y. ~0 T! y- t5 \4 W5 {& @
getch();
, J' u7 K: N6 L* r- M0 j6 B. [6 M- t% gexit(1); /* terminate with an error code */ 7 f+ M' Q% C, S8 Q4 \0 o
} </FONT></P>
. Y$ `3 k9 z, e: |<P><FONT color=#0000ff>/* grab a copy of the palette */
2 U* r7 K6 w, w- I3 f' rgetpalette(&amp;pal); </FONT></P>0 H/ n2 n/ }$ u, c, a: }# o
<P><FONT color=#0000ff>/* create gray scale */ 0 ^% i/ G$ k+ B8 T* X
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>
5 ^9 c7 V! W) j. ^$ f<P><FONT color=#0000ff>/* display the gray scale */ / a. e  o6 s5 T
ht = getmaxy() / 16;
. y% ?! f# [7 B: Oxmax = getmaxx();
; d! Y+ Y; @. p, I! hy = 0;
* W* m# m) h, `7 z: ]) Mfor (i=0; i<PAL.SIZE; <br i++)> { 9 ^0 ~5 m, X% w  q
setfillstyle(SOLID_FILL, i);
, l( Y8 h! c" b& S; l; l9 @bar(0, y, xmax, y+ht);
1 `5 n# s4 B$ x- fy += ht;
7 J9 e2 e0 L. U( r} </FONT></P>! T- x" {2 C* i) v
<P><FONT color=#0000ff>/* clean up */ ) C& x5 H4 n3 A! u5 R, n
getch(); 1 a8 T: r1 X2 W, E
closegraph(); ! I1 ?7 G0 B# [: E$ V, t& Q# d
return 0;
: S+ i5 M0 |! j5 I7 L8 y} - h7 V1 v; O2 a
</FONT>( p/ s! F" }8 O/ Z" C8 d3 ~
: }- F) M  T/ Y- y* w8 j; @+ J
</P>( q( j! j4 \5 K: _3 z  p
<P><FONT color=#ff0000>函数名: settextjustify </FONT>
$ V+ ~' \' Y8 e8 L: `* T9 ]功 能: 为图形函数设置文本的对齐方式 3 y; D5 w1 {7 T0 }4 N, X
用 法: void far settextjustify(int horiz, int vert); 0 {% J& V1 b+ z$ s2 `. l7 a
程序例: </P>( E, }: j4 z( k6 Q4 \/ T
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 w7 B, P3 V0 R5 Q3 ~
#include <STDLIB.H>
4 I) Y) _, N* G1 B/ L; r* J#include <STDIO.H>  _3 c1 B% ]4 s* Q
#include <CONIO.H></FONT></P>* w6 `! v# E" Y# f
<P><FONT color=#0000ff>/* function prototype */
) I+ M1 v  J- v+ j# W5 v6 _void xat(int x, int y); </FONT></P>  X  f( Z. S9 C4 }! i4 T- m
<P><FONT color=#0000ff>/* horizontal text justification settings */
  |# S3 k' g5 `/ t7 M2 Pchar *hjust[] = { "LEFT_TEXT",
: K9 E& P- @2 S7 t"CENTER_TEXT", 4 M6 J- J+ b4 e& {3 Q
"RIGHT_TEXT"
* r* J1 ]3 Q+ w! L; z}; </FONT></P>
& ]! N# N4 p5 F, y- n) f0 K5 p<P><FONT color=#0000ff>/* vertical text justification settings */ : f( s$ |8 }7 v0 Z2 H
char *vjust[] = { "LEFT_TEXT",
  K, |5 ~9 k9 L"CENTER_TEXT",
, d. M2 V5 Q) c* A. ]4 P"RIGHT_TEXT" 0 ~1 @, j8 g/ {
}; </FONT></P>' }4 O' A# b% ^$ U, a3 f/ `
<P><FONT color=#0000ff>int main(void) & p* j2 r" @( P7 i% a) h
{
: y  E4 k; y; {. N& X, m$ g$ \/* request auto detection */
" e7 g9 ~. w: @% X9 @0 Sint gdriver = DETECT, gmode, errorcode;
) u8 L% s7 E0 ~: P; Jint midx, midy, hj, vj; & k9 W( z/ u% ~! I  d: @9 I
char msg[80]; </FONT></P>! ~* K& |" h1 U7 ]$ B. ?& ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */
" j7 @% u; T- L  G$ xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# x3 F0 F) e2 O1 p<P><FONT color=#0000ff>/* read result of initialization */
( f: ~$ D+ D- k- werrorcode = graphresult();
- M1 h0 l2 q. d6 l3 w9 c/ eif (errorcode != grOk) /* an error occurred */
8 _" r7 I: K, N/ l{
; W. ?: w2 X3 q8 ?, A, Sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); - b. H' d# ]/ D
printf("Press any key to halt:"); 6 X- x  K# m9 z+ z
getch(); + g( ]* L+ m5 J+ v  a, d$ p. b
exit(1); /* terminate with an error code */
7 _7 T5 ]! q- j5 O2 n} </FONT></P>
. ~3 q+ t- c# F+ |<P><FONT color=#0000ff>midx = getmaxx() / 2;
; z  P* T) f9 i- V7 ~% ^' rmidy = getmaxy() / 2; </FONT></P>
4 c8 U6 @3 x$ I+ T& O( S- e<P><FONT color=#0000ff>/* loop through text justifications */
7 @/ q# Y- z4 h3 j1 z+ S( xfor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
- Y& z8 b! n- F& Afor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
) }) ^7 N% n, ~) n8 T4 [/ i* x3 R{ - E& h1 k& x. }# Z
cleardevice(); - r5 I& t3 O. X/ v+ Z% Y
/* set the text justification */
! f4 Q6 I5 B& t5 o3 f) I8 xsettextjustify(hj, vj); </FONT></P>. t: v9 L& X  E3 ?9 s- I
<P><FONT color=#0000ff>/* create a message string */ # i- ~6 W) r8 u" j
sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>& ^) i4 s5 p  V3 F: J
<P><FONT color=#0000ff>/* create cross hairs on the screen */
( `8 e( F: P; x- v% u5 Z5 {xat(midx, midy); </FONT></P>
* d$ w' N% A2 X2 w; Z) K<P><FONT color=#0000ff>/* output the message */ , ^. V9 U$ \8 x6 p4 Z' D* }2 R
outtextxy(midx, midy, msg); . A$ W) i4 p7 E+ c$ Y! m
getch(); $ G) q& k! Z# f* A4 O0 P4 S
} </FONT></P>" g# }& w7 W; U( L
<P><FONT color=#0000ff>/* clean up */ % e' K- I6 \: r; t, `0 u9 B
closegraph();
- _0 ?4 l; V; n% c/ T7 nreturn 0; 8 T4 t- }8 O8 B
} </FONT></P>
$ u' |' x- T5 Q$ B<P><FONT color=#0000ff>/* draw an "x" at (x, y) */ 4 e8 U: T+ O- T" O$ w: |
void xat(int x, int y)
0 [5 \/ j# X  i3 ]% ?9 D{
& r+ ^! j+ \; l, b0 \1 F- gline(x-4, y, x+4, y); $ J2 ~  w) j6 S, e& F
line(x, y-4, x, y+4);
" |( J6 D6 |. p$ N/ W: ~0 B; E} </FONT>
+ ]6 N) N- V3 K; P* a3 |+ p! _9 ]$ O# k! z
</P>
! C; f9 Y: n) t" S<P><FONT color=#ff0000>函数名: settextstyle </FONT>
! E: E* N2 p5 {" q功 能: 为图形输出设置当前的文本属性 + t& b) s: d9 y8 s# P9 Z
用 法: void far settextstyle (int font, int direction, char size); 8 }9 P* [; T/ z0 F( \1 Y
程序例: </P>
: H: \" |$ o9 U1 O<P><FONT color=#0000ff>#include <GRAPHICS.H>* Y+ R( q7 b; {, z! k& d
#include <STDLIB.H>
( j$ E% Z' P* f" `8 K0 D& K#include <STDIO.H>
3 |& p3 y, T9 j  u& g! [#include <CONIO.H></FONT></P>+ X9 F! j( H# w
<P><FONT color=#0000ff>/* the names of the text styles supported */
1 `: S4 u5 n, Cchar *fname[] = { "DEFAULT font",   K* f" z5 i/ \1 i
"TRIPLEX font",
; a  |$ R' ]9 u/ M$ u% A"SMALL font", 9 J& t1 ], Z( {; U8 Y
"SANS SERIF font",
- M1 R4 l- s/ D" A: O"GOTHIC font"
0 o1 A: n: a4 r( A" n; ~+ s5 i}; </FONT></P>; L4 H1 V8 y' _% D1 @$ K
<P><FONT color=#0000ff>int main(void)
1 Q2 n5 C+ F' m) D& P. M{ - a; b& x; Q9 ]  w5 j1 {
/* request auto detection */ ( `' H; z3 c, M) L8 V3 I2 `
int gdriver = DETECT, gmode, errorcode; ; Y6 p  W4 M. F" x2 l
int style, midx, midy;
' ?& ^$ R( k/ p( w5 Eint size = 1; </FONT></P>1 }2 U8 M) d% `
<P><FONT color=#0000ff>/* initialize graphics and local variables */
- N; G3 p3 P* C4 F, W; d& V; H8 Vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ m" X" {, _% G<P><FONT color=#0000ff>/* read result of initialization */
3 {1 k4 Q' c: p1 g/ T' d& N: {7 q9 Berrorcode = graphresult(); ; V2 q3 Z: n! l& X& i9 X
if (errorcode != grOk) /* an error occurred */
/ x6 D- F3 b- n( }) U{
" O3 ?* Y3 f. |' Q; Oprintf("Graphics error: %s\n", grapherrormsg(errorcode));
( A$ \" {4 e) q0 uprintf("Press any key to halt:");
' k1 G8 P: }; M+ p# d4 wgetch(); 7 ~2 J8 `; x4 c' S! L" D
exit(1); /* terminate with an error code */
/ |7 ^# e6 n. A2 V# a} </FONT></P>
3 p: [! I8 e2 i4 {7 o<P><FONT color=#0000ff>midx = getmaxx() / 2; ; [8 Q$ R7 d4 E1 G1 C8 \
midy = getmaxy() / 2; </FONT></P>6 q* Z( Z/ e* X% w1 R
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
9 Q7 h0 |5 g/ k+ q+ s# g<P><FONT color=#0000ff>/* loop through the available text styles */
# M6 C) l4 J; F. H0 lfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 9 O) {2 H7 g- j: \4 {& \
{ : U# T3 p7 c$ _% T+ Y$ r7 V
cleardevice();
( t# @" A2 g- l! _# q, M1 F/ S; Kif (style == TRIPLEX_FONT) 7 b# ^/ u" t% h7 G
size = 4; </FONT></P>
  z3 v) w: G6 a1 j+ p- B' \$ {<P><FONT color=#0000ff>/* select the text style */ $ ~4 n2 s( s  o( E
settextstyle(style, HORIZ_DIR, size); </FONT></P>2 Y4 F  \: _, Z
<P><FONT color=#0000ff>/* output a message */
! ?& Z1 W& t; F" X& ]& M$ c; Douttextxy(midx, midy, fname[style]); % }* l- e+ g5 r2 I- }
getch(); 3 a- f5 {- o: |1 P
} </FONT></P>
: b, d8 O. ^# C4 e2 M% E4 m<P><FONT color=#0000ff>/* clean up */
% v8 Y! [3 ?- C5 F  bclosegraph();
" P, z2 P, g: b) F% T; Vreturn 0; 4 e3 M- H0 U- X
} % r/ C! c6 @3 R  s: K& m5 N
</FONT>. Y+ O0 d4 w9 O. v# T- \
</P>; l% {0 F( s$ ?  Q# p
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
% _/ o# D, F8 B+ D& j% L  ^- ?5 S功 能: 为图形输出设置当前的文本属性
5 u3 P$ k9 i1 W8 H2 V) D& r用 法: void far settextstyle (int font, int direction, char size);
6 Q$ {7 n' Y+ @2 v" S, z1 R; T程序例: </P>& I" s9 F8 e0 s5 g# H6 ?
<P><FONT color=#0000ff>#include <GRAPHICS.H>9 E( ^; {# m. W7 E0 _
#include <STDLIB.H>6 @" K( r; d9 b3 ?$ r
#include <STDIO.H>
7 W( t8 H7 J) r* I% y  q#include <CONIO.H></FONT></P>
; J. L* Y( u0 Y; n% h3 T<P><FONT color=#0000ff>/* the names of the text styles supported */
4 m0 A6 x6 }8 G* ^: Q) U6 S0 Gchar *fname[] = { "DEFAULT font", , s7 B. \) U4 H$ i' Z
"TRIPLEX font", ) g; B- x, {& B) \: H* q  \" ]
"SMALL font",
- f' F) f$ B, {: l; o+ n( ]2 v"SANS SERIF font",
* n2 ~& H0 e& K4 d8 \. @7 \1 [) ^" o"GOTHIC font" 6 T+ R" ]. h2 P! u3 F8 b! z
}; </FONT></P>: i3 N5 h, @2 c8 t6 r
<P><FONT color=#0000ff>int main(void)
, t, B  t# z& r. l9 G7 l9 W{ 0 B4 {* ?. i. o
/* request auto detection */ 0 D* H% b- j" y
int gdriver = DETECT, gmode, errorcode; 9 W% Y" v; ^5 U* ]4 t$ I
int style, midx, midy;
  k1 Z, g/ H& h9 bint size = 1; </FONT></P>
, w; ^; u* I% Z+ j<P><FONT color=#0000ff>/* initialize graphics and local variables */ / ?( y  ?  I! j( u: H) M/ X0 ]4 T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" ]3 h8 J- c! |$ \; f5 i! ?<P><FONT color=#0000ff>/* read result of initialization */ 6 q. F0 I. n8 l% I6 y9 ?
errorcode = graphresult(); 5 U% {6 P& F* ^1 d
if (errorcode != grOk) /* an error occurred */
" v( n" P6 x" w5 \0 l{
; H( Q: r0 z9 Uprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 F  t$ D# b) U! }( w
printf("Press any key to halt:");
. d; F4 C7 z7 h& s7 Ygetch();
1 ^( }1 e% S- i5 C0 j2 |exit(1); /* terminate with an error code */
  G; ]# M; ^8 X; o} </FONT></P>
, q4 J# @+ `2 w8 D! h<P><FONT color=#0000ff>midx = getmaxx() / 2;
+ I" ]1 }- n* v- Qmidy = getmaxy() / 2; </FONT></P>" @$ b( O# E2 y1 i
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>- A/ ~- g9 I' k/ s; {
<P><FONT color=#0000ff>/* loop through the available text styles */
, i. f$ Q8 L9 m" zfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 7 T4 B5 s! W  m8 M0 P% K
{
& {, y' P, }; u" A5 bcleardevice(); . v+ E5 o$ Y6 ?
if (style == TRIPLEX_FONT)
0 t( Y7 d8 E8 Rsize = 4; </FONT></P>* B* \. D/ M4 S4 i: b+ Y
<P><FONT color=#0000ff>/* select the text style */
: Q% C- k2 f; }settextstyle(style, HORIZ_DIR, size); </FONT></P>5 u0 G% k* Z; }( S3 B1 [
<P><FONT color=#0000ff>/* output a message */
% U% G! @5 X' z3 C" douttextxy(midx, midy, fname[style]); 9 W  P; j/ `( m( k
getch();
/ I) \9 {) F  I! I4 T: s$ B} </FONT></P>
+ x- L. m6 G8 I% u<P><FONT color=#0000ff>/* clean up */ 0 Z% W) Z1 m9 n% \, B3 ^1 N7 ]) B
closegraph(); % j' e+ v% L; @1 e3 a8 j
return 0; ) c7 Q2 W) Y+ R4 o) u0 B; S
} </FONT>) Z6 p& F. L  h% j
" v2 X( }. q. {8 Q9 K0 P$ q2 s4 |
</P>
8 i0 v4 o: a0 C* J! g<P><FONT color=#ff0000>函数名: settime </FONT>
8 C& Y- o" Z5 a% Q) U) F( M' x; [功 能: 设置系统时间 , a) ]. A: ?$ T+ g7 s6 n3 p& T
用 法: void settime(struct time *timep);
3 k% @) `5 O0 N: F4 |* _程序例: </P>% ^& B0 _. F, G6 i8 S" ]' S
<P><FONT color=#0000ff>#include <STDIO.H>8 V+ `6 z' B; G" L3 H' O) D9 l. q
#include <DOS.H></FONT></P>
- q9 x$ Q/ r0 r2 l, |9 v8 L6 j<P><FONT color=#0000ff>int main(void) ) m+ I+ Y% T) l
{
$ J  R2 Y; I, O: lstruct time t; </FONT></P>
+ [# S. N6 q$ C' ]- n2 S<P><FONT color=#0000ff>gettime(&amp;t); 9 B! t  ]8 K; c( G+ Z
printf("The current minute is: %d\n", t.ti_min);
% r3 ^; }; }1 }3 g' T9 c( C8 gprintf("The current hour is: %d\n", t.ti_hour);
) q3 r+ R; ]  V- k% Aprintf("The current hundredth of a second is: %d\n", t.ti_hund);
- g* O, k3 v% ]7 Iprintf("The current second is: %d\n", t.ti_sec); </FONT></P>
4 U# F7 r0 o+ u$ r' X" r  c# O<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */ 6 g+ R1 b+ E  T" J. \5 p+ b
t.ti_min++; 7 [3 o  l3 U/ s+ h" N5 s4 C
settime(&amp;t); </FONT></P>
! K: v+ o8 k/ U0 [. M<P><FONT color=#0000ff>return 0;
: A$ s( `. y* h) b6 g6 @} </FONT>% J! w3 G4 |% t, t1 p0 ^* B
6 l6 _$ d2 w; y
</P>
9 _8 o6 z: {/ F6 L7 u4 H' v<P><FONT color=#ff0000>函数名: setusercharsize </FONT>6 j) m; A- v: p* S+ i$ C% O4 }
功 能: 为矢量字体改变字符宽度和高度
" K  Z. y/ c/ T' A# B用 法: void far setusercharsize(int multx, int dirx, int multy, int diry); 3 F  w8 L1 x* G( ]# b2 L
程序例: </P>( j$ x! [2 k0 @" \- t
<P><FONT color=#0000ff>#include <GRAPHICS.H>" b4 t, y+ s& \( F
#include <STDLIB.H>2 V6 p( l" ?: y& s% ?% w
#include <STDIO.H>7 A* ]6 [) [; v& K7 j! q
#include <CONIO.H></FONT></P>
" }) k1 ^5 h( f0 g( Y<P><FONT color=#0000ff>int main(void) + ?0 f4 c' u/ @7 @
{ ( s& C* [5 E. o% e% j" R; t. b
/* request autodetection */
4 T) t+ j% P' Vint gdriver = DETECT, gmode, errorcode; </FONT></P>0 M5 e0 l1 A1 p+ L
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " F6 N; N+ V. P! v( {+ m
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>7 X0 Y4 M5 H* g5 F! q9 A
<P><FONT color=#0000ff>/* read result of initialization */
, t# f" w& V: K- Ferrorcode = graphresult(); * M# q% i, T0 b" v
if (errorcode != grOk) /* an error occurred */
# R9 [3 O! g  H  D{
* o9 v. \9 }2 a& D  \& b$ c' Wprintf("Graphics error: %s\n", grapherrormsg(errorcode));
4 v. |6 ~  R& \$ X; N, iprintf("Press any key to halt:"); ) A* e! ~+ r; Z3 O
getch();
) P2 G! l* N; |exit(1); /* terminate with an error code */
1 f; V2 Z: d& X% P} </FONT></P>2 V" q* G" a7 T& q2 h! X/ R1 P  v
<P><FONT color=#0000ff>/* select a text style */
# a7 y& D+ Q' S. E$ E/ }) W0 Usettextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
. B; f5 ^& o/ H6 C0 i7 u' o( V<P><FONT color=#0000ff>/* move to the text starting position */ 1 c/ Z8 r2 z/ Q/ y
moveto(0, getmaxy() / 2); </FONT></P>( k) \/ z; \  M. f
<P><FONT color=#0000ff>/* output some normal text */ 5 ]9 `% K. v3 u5 Y$ b: j) W
outtext("Norm "); </FONT></P>
7 I1 L" W, t( H+ _  M2 Y' H<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ 9 z+ L0 e% I  I! {
setusercharsize(1, 3, 1, 1); # ~& I# Y% l" K* h- Q
outtext("Short "); </FONT></P>
6 }" N4 @, v' H+ h. ?! ?1 |4 \( d<P><FONT color=#0000ff>/* make the text 3 times normal width */
/ j& I, ]5 u0 D; [2 z. hsetusercharsize(3, 1, 1, 1); / j0 f& \  ~' p4 R
outtext("Wide"); </FONT></P>
0 K% x  ~/ ~, P' G3 o4 o" q" @6 o<P><FONT color=#0000ff>/* clean up */
. ^; \. h. g6 f: H; p$ bgetch(); , C! V* ?  M8 h% X7 f  a% V7 R
closegraph(); 4 F2 Z4 w0 L) M5 |% g
return 0;
% {7 `% W% p. H: p- ~' u$ |} </FONT>  W( T# y& s. a: N7 [# K3 i6 `
</P>
5 o, D7 H+ h$ P3 T7 R<P><FONT color=#ff0000>函数名: setvbuf </FONT>2 V" q! A$ E$ w7 ]  B7 N6 g
功 能: 把缓冲区与流相关
9 @+ p& B; g3 M1 s用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); . L4 P' L0 k1 }0 \/ X, \
程序例: </P>7 D, y, `( u6 b
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
/ v* X7 T* L4 f<P><FONT color=#0000ff>int main(void) $ ~2 q9 J, d; }! V
{
' V/ f6 |" M; n0 N  cFILE *input, *output; 6 }, s8 K. N5 N4 l0 V( k
char bufr[512]; </FONT></P>  a3 r7 K& ^7 w% t5 P5 v+ z3 m4 T
<P><FONT color=#0000ff>input = fopen("file.in", "r+b"); 3 l) ?2 J+ b+ N7 I2 O2 v/ H
output = fopen("file.out", "w"); </FONT></P>
+ h* u$ f# _; m( J) U2 W<P><FONT color=#0000ff>/* set up input stream for minimal disk access, 7 U8 d9 _% W( B1 I
using our own character buffer */
. k2 W" m9 B# v; q9 R& dif (setvbuf(input, bufr, _IOFBF, 512) != 0) 8 U  B; F: q- Z1 H
printf("failed to set up buffer for input file\n");
& m$ |9 m* W+ @6 D1 A# T9 Q. {else ' ?) j9 q6 f6 x2 _- b! G8 }( ~9 P
printf("buffer set up for input file\n"); </FONT></P>8 X8 d% E! L4 k! h) X+ v( l
<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
+ X. P2 n6 \5 g3 Z: j. V1 \will be obtained through an indirect call to malloc */   e7 j: Q% v2 x" r  z' n+ r
if (setvbuf(output, NULL, _IOLBF, 132) != 0)   c* M- X: X5 Z; H
printf("failed to set up buffer for output file\n"); 5 E( Q6 X1 k7 P4 _
else , U& O; W# A1 j% Z& ~3 R( t1 _7 _) ?
printf("buffer set up for output file\n"); </FONT></P>+ c1 H+ t" `+ ~6 r) V, v+ b& v$ U
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
" O0 ]2 Q/ E  ]( O( d' g<P><FONT color=#0000ff>/* close files */
( ^3 J( q. v. R8 Q/ r- sfclose(input); ( o( H& Y* n, g$ S7 x
fclose(output);   J8 R8 a, f" t+ v! j) Q1 K
return 0;
* a4 F) i" O2 N) e6 d2 N5 ^} ) [( P4 _3 v- I  s% \* J- l9 |
</FONT>
. ?1 J$ Z' L& }- D, x
* \/ C+ e# H$ q' ~</P>
' W' y; l  S9 s8 e/ l<P><FONT color=#ff0000>函数名: setvect </FONT>
. U/ ?6 h0 P0 t2 C( l5 R& F. V' ?功 能: 设置中断矢量入口
4 R6 `, p0 ]4 Q. F用 法: void setvect(int intr_num, void interrupt(*isr)()); 0 V2 f% P: d8 E! {, d
程序例: </P>) G1 F* }$ c5 V+ t
<P><FONT color=#0000ff>/***NOTE:
, z3 l: Q; J' S8 a" B0 cThis is an interrupt service routine. You can NOT compile this ! v; E4 J/ _$ [* z2 ?
program with Test Stack Overflow turned on and get an executable + b; ]+ m8 v7 v( H/ l
file which will operate correctly. */ </FONT></P>/ j! b% I  ~! m6 ]& i" i0 e
<P><FONT color=#0000ff>#include <STDIO.H>
) ?# [# j3 _- o- ~* v#include <DOS.H>
; ?: k0 H) S% [* R% D" M0 [( U#include <CONIO.H></FONT></P>0 v. J" J: p( h+ ?6 ?4 f
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>
6 N/ K( C2 c! p- R6 L! v1 g6 M<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
% ?$ p8 e! l4 j! f. I% r+ ^<P><FONT color=#0000ff>int count=0; </FONT></P>
/ M2 D/ u: J* n$ u. x5 A<P><FONT color=#0000ff>void interrupt handler(void) " s2 e  B+ `1 J# y4 Y+ v! O* L
{
; m8 A, `- s. ?: t/* increase the global counter */ * `" K, Q- w( V+ N
count++; </FONT></P>  g8 ?/ o) V6 w- w2 e9 F
<P><FONT color=#0000ff>/* call the old routine */
3 _* t+ \$ Z4 L  L( `oldhandler(); , ^1 l' _, j( q* z! F' Y
} </FONT></P>
( w: O6 M7 u, _- _6 K$ U  V<P><FONT color=#0000ff>int main(void) 3 U. j" l2 d* J/ Y
{
6 e, q5 u4 h# d; b/* save the old interrupt vector */ 8 C; v# i9 p8 x+ B+ D7 U4 W
oldhandler = getvect(INTR); </FONT></P>2 k2 Q8 i' u! q$ W# E1 z( K
<P><FONT color=#0000ff>/* install the new interrupt handler */
: @  e. [2 s) jsetvect(INTR, handler); </FONT></P>" i1 _7 D4 o4 g' v. d3 C
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
1 c% @5 I; {& k# _. y/ v- Xwhile (count &lt; 20)
! a2 x% h5 ^. W" h& L3 q5 M8 ^printf("count is %d\n",count); </FONT></P>
) C& q; P) ?( ?9 m, |7 I' m<P><FONT color=#0000ff>/* reset the old interrupt handler */
1 `4 ]8 w( I; l0 Csetvect(INTR, oldhandler); </FONT></P>, ]# q  j, G- G: Q9 |; G+ D
<P><FONT color=#0000ff>return 0; % v& j$ V. W1 a; m5 p! r3 A
}
8 X, W; Y" M* B" _8 F0 Q</FONT>
" X/ e7 M8 D, n; k</P>! E- K- b* W) {" X# y% \( K, Z  v
<P><FONT color=#ff0000>函数名: setverify </FONT>
$ i- S, N5 Z  ~# Z1 k功 能: 设置验证状态 ; C  `  `1 v3 d5 K; Q
用 法: void setverify(int value); 8 C5 s) `1 ^2 J! o  x5 \$ G; B
程序例: </P>) P7 E3 t7 R8 V! H* j2 c
<P><FONT color=#0000ff>#include <STDIO.H>( X& ^9 N( M& r! _6 E9 a! A
#include <CONIO.H>  \; T( y2 _* T' S) {
#include <DOS.H></FONT></P>
7 p7 W- N6 b$ _2 L  c<P><FONT color=#0000ff>int main(void)
" x1 i) x7 e9 S- Y! Z{
' ]. V$ H) C7 A8 n  t% rint verify_flag; </FONT></P>: N  q- H3 G- D8 ]7 Y& [
<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
% l, N+ t# o/ w; jprintf("Enter 1 to set verify flag on\n"); </FONT></P>0 K, }5 y5 S- {9 D
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>
0 B0 ?, @# X9 b3 a1 z<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>
" P9 Z/ {: V% H8 s* ^0 X/ s<P><FONT color=#0000ff>if (getverify()) 5 \) v$ q5 r, @4 C
printf("DOS verify flag is on\n");
$ g5 r' J. f5 f3 ~* aelse * P, l; Q$ S' `) e$ |
printf("DOS verify flag is off\n"); </FONT></P>
- ^, [! E7 w3 A, }2 X; N, y<P><FONT color=#0000ff>return 0; ; {( ]( M/ @. W8 m: N) Z& S2 s
} & R2 Y3 ]9 e4 D* M6 K) \+ }  a6 I
<FONT color=#ff0000>, y. \7 m; B* T; f5 C* I
</FONT></FONT></P>8 Y1 ~* R5 x% ~$ ?# S/ p4 m3 J
<P><FONT color=#ff0000>函数名: setviewport </FONT>
$ H5 c+ u. q6 M: G! b5 U功 能: 为图形输出设置当前视口 # Z9 \: w) U- [' V' X) n: o
用 法: void far setviewport(int left, int top, int right,
$ P2 g! s: \( \( r$ u( }0 f8 Lint bottom, int clipflag); 4 c6 W1 z9 ?3 y# J0 K' D
程序例: </P>
! f- j6 R) s, M! r9 V% X( R<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 D# A! T7 P2 m0 V: L6 i#include <STDLIB.H>
6 G/ Z, G2 o6 f8 u" K) A# C4 y#include <STDIO.H>$ W( o, h4 u9 d- K* q8 R4 [
#include <CONIO.H></FONT></P>
9 m( i! M( P/ n4 Y# v<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
% M% k8 g7 R( H  T<P><FONT color=#0000ff>int main(void) $ p; ]1 B: I5 I! G) W
{ ) y' I8 c5 }" ?. m' `
/* request auto detection */ 1 V" w7 L6 v$ F
int gdriver = DETECT, gmode, errorcode; </FONT></P>
5 y# c: X0 a: c( e( O; F2 b<P><FONT color=#0000ff>/* initialize graphics and local variables */
) U- T0 e4 k6 O) J* R6 ~) l. winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  F8 a* v4 p5 t* Z<P><FONT color=#0000ff>/* read result of initialization */ % p' A# z! \! ~* u8 o
errorcode = graphresult();
: i4 ^$ K7 V& C, `6 T( S# @0 H7 o" m' zif (errorcode != grOk) /* an error occurred */ " f, d7 p- g6 y4 t
{
+ N+ d; Q7 f, ^/ t" aprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 x) c! V4 C& C- `7 A# J
printf("Press any key to halt:");
" O. t# j+ n$ g/ q: b0 [! Cgetch(); % g2 g# M- y- ^
exit(1); /* terminate with an error code */
" z. C6 S; c, U3 D} </FONT></P>
- S" W4 X! A# m<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
( m& @7 j9 ~2 e( Q( ?) k$ j: l<P><FONT color=#0000ff>/* message in default full-screen viewport */
# E5 R% E! ^3 a5 E" zouttextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
" I# f8 D; M7 f  ?4 K<P><FONT color=#0000ff>/* create a smaller viewport */
; ~* i  ^) c2 g- J$ u( \, tsetviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>4 }9 S' V0 G/ q5 N, v# q+ u4 n
<P><FONT color=#0000ff>/* display some text */
3 p2 P, J4 H3 x( K; C! L$ houttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>0 o/ [" S" [; q+ o
<P><FONT color=#0000ff>/* clean up */
6 [  e' p' w+ X- U+ f2 X! k' U* Tgetch();
2 m/ g# ]: _1 I2 ~1 Fclosegraph();
; A) h9 p- \" |' ?4 u' c1 H7 \return 0; ) s: v" c4 I" \' u2 C5 V% w
} + s0 O: a. A2 k( W  p8 ^
</FONT>
: N+ g9 S9 t+ ]</P>
" U. o6 f( E0 [" l0 b: n+ o<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
4 j4 i, |2 S* [9 P功 能: 设置可见图形页号
0 x9 T" U" @8 n% e$ `0 d用 法: void far setvisualpage(int pagenum);
4 P0 D6 U6 B* A: }& u* X+ @  y4 I7 |8 f) D程序例: </P>" Q8 L% Q: M- w- g& `
<P><FONT color=#0000ff>#include <GRAPHICS.H>  y8 {* n9 n- P! A* W/ N& N
#include <STDLIB.H>  ]1 \6 ?9 x% k- ^& `+ [3 j
#include <STDIO.H>: b1 M/ P1 B$ A
#include <CONIO.H></FONT></P>
4 T% o3 B4 b; x3 J4 z# p7 `% k  K8 x5 B<P><FONT color=#0000ff>int main(void) ' a) d0 u' g5 m* `
{
0 @7 D  G# p8 J+ M$ o/* select a driver and mode that supports */ 8 p7 ^# a$ @# x8 Z- p
/* multiple pages. */ 3 Z# ?3 L1 e7 O$ }
int gdriver = EGA, gmode = EGAHI, errorcode; 5 S9 u" S7 j3 \+ K0 M
int x, y, ht; </FONT></P>( ]( k8 [4 n  f9 F
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ g; c3 b/ z, b( m( P" [% u! J; kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
8 i) [5 e! c) O: ?0 S<P><FONT color=#0000ff>/* read result of initialization */
3 Y, Y- i$ h5 [; c- Y' l; {errorcode = graphresult(); ( s) t# `+ s: t' p  k, u! a7 @
if (errorcode != grOk) /* an error occurred */ 1 n) U9 B/ t7 Z' `- p8 m
{ 3 }. d; r. ?) m; N& R7 [7 P2 I
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( R4 z0 j+ u, {: {: J# t8 {
printf("Press any key to halt:"); ) c$ u8 W1 ]; t* p
getch(); $ H4 _7 u" B8 `# T+ _5 j
exit(1); /* terminate with an error code */
! u! b+ ~$ J1 P3 `0 T. {} </FONT></P>
4 y( D4 M$ t1 P$ m<P><FONT color=#0000ff>x = getmaxx() / 2;
, v+ \  ]# j3 C$ b8 L! {y = getmaxy() / 2; . I4 B* k) E$ w. k0 h# P
ht = textheight("W"); </FONT></P>8 g- m4 ?" Y$ t) r% h* f
<P><FONT color=#0000ff>/* select the off screen page for drawing */
, f9 x/ x/ _8 r$ S6 P* wsetactivepage(1); </FONT></P>
" ?' V; X; O- K& X6 W<P><FONT color=#0000ff>/* draw a line on page #1 */ ' x3 x! T% L5 a
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
2 x. m7 a; J8 S1 {<P><FONT color=#0000ff>/* output a message on page #1 */
# @1 I$ Y* E8 e% }( x! Isettextjustify(CENTER_TEXT, CENTER_TEXT); 8 r7 k7 D$ m% G
outtextxy(x, y, "This is page #1:");
% u: w+ Z5 |/ L8 Q4 Douttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
) A; S/ b" `, C1 g# c$ J<P><FONT color=#0000ff>/* select drawing to page #0 */
5 z' {& Q$ B, F; n! Ksetactivepage(0); </FONT></P>
, ], i# n- o8 }4 m<P><FONT color=#0000ff>/* output a message on page #0 */
3 B, t" K4 V7 ?9 Iouttextxy(x, y, "This is page #0."); 5 K+ }% |9 c, W& C
outtextxy(x, y+ht, "Press any key to view page #1:"); 4 q$ f( e5 j0 O2 p. X0 n
getch(); </FONT></P>
6 \  F$ W' k* e# |8 p% |<P><FONT color=#0000ff>/* select page #1 as the visible page */
( A4 n9 t7 t, a+ J* S4 m' c8 xsetvisualpage(1); </FONT></P>/ P' l; x1 m' p6 N8 q( a" A( S
<P><FONT color=#0000ff>/* clean up */ : o/ V. r& C& E2 z9 g9 c
getch(); 3 r8 s% m# ?2 W" D4 g" f# c
closegraph(); " e; N/ y5 Q9 r5 W9 d: M
return 0; 4 ]( L+ o1 X  s
} </FONT>
$ m% x2 W6 Q1 w/ H2 C- `
# S% c9 J) c, R/ p! E- ]</P>% M, ^* r/ I# L
<P><FONT color=#ff0000>函数名: setwritemode </FONT>
* W( ~5 T0 P1 z, U1 x功 能: 设置图形方式下画线的输出模式
# z, J" a7 U! d: F( Z; b2 W用 法: void far setwritemode(int mode); 1 a+ ~6 C: o- ]0 K+ }
程序例: </P>3 ?  Z$ O# g+ |4 c
<P><FONT color=#0000ff>#include <GRAPHICS.H>) b, e; M8 {6 S  D7 C
#include <STDLIB.H>
  H. L+ H; g' h( b#include <STDIO.H>
! C1 [$ D4 u3 z$ K6 M#include <CONIO.H></FONT></P>
3 N: X1 o, ~. @2 q# _, N. Q<P><FONT color=#0000ff>int main() ; M- B' S  e; A3 M
{ " G6 W: `+ J8 T# R' o
/* request auto detection */
* c' f6 n* ]8 ]  w! U( E3 z3 fint gdriver = DETECT, gmode, errorcode;
$ S; ^: c, d9 A: y! c: m8 Nint xmax, ymax; </FONT></P>0 T* |6 ]) [3 X# a9 z: V, r9 `
<P><FONT color=#0000ff>/* initialize graphics and local variables */ $ X' [- e! r7 i0 Q9 N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, l) M9 o& d, P% _- B* O
<P><FONT color=#0000ff>/* read result of initialization */
* g7 ~, O, |, W3 ~% y9 p- r8 kerrorcode = graphresult();
% }& W( q  {: u: P' j; u; A6 fif (errorcode != grOk) /* an error occurred */ . q7 f4 _% l) ]; C1 @3 M. Y
{
8 @4 x) n0 s% ]5 Iprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " v; X; i6 v* v: n8 s/ m0 I
printf("Press any key to halt:");
* V7 }6 t( @( |) U$ ngetch();
" u# @7 q( E8 {) l5 A0 ]: E& Rexit(1); /* terminate with an error code */
' i# [% P( Q* M; ~" M$ B& [- M; C} </FONT></P>& k, q$ j% V! Q& }% @" c
<P><FONT color=#0000ff>xmax = getmaxx(); 2 x) Q& q! e- U4 o4 p  J5 c
ymax = getmaxy(); </FONT></P>
7 Y2 h( W$ V" @6 M<P><FONT color=#0000ff>/* select XOR drawing mode */
1 l) r, F) D+ csetwritemode(XOR_PUT); </FONT></P>
, |; }4 w$ I1 s. i: W<P><FONT color=#0000ff>/* draw a line */ 9 p/ U& d) w, x5 n% ~5 D4 @
line(0, 0, xmax, ymax);
& d; c0 y! g1 O/ f2 r& Egetch(); </FONT></P>1 u/ f7 D. Y# Z9 v* m
<P><FONT color=#0000ff>/* erase the line by drawing over it */
% b/ c6 ^7 A* @0 bline(0, 0, xmax, ymax); 1 t7 M1 Q% F6 s( M
getch(); </FONT></P>, v9 x: E6 S. I
<P><FONT color=#0000ff>/* select overwrite drawing mode */
7 C; g6 D0 [+ @  d8 H( Lsetwritemode(COPY_PUT); </FONT></P>
# ]6 C1 d5 T6 M8 p<P><FONT color=#0000ff>/* draw a line */ " w2 F6 Y/ }  |1 P
line(0, 0, xmax, ymax); </FONT></P>% S" e7 L) N  O0 a
<P><FONT color=#0000ff>/* clean up */ ( U" ?  ^. w7 H: J% x
getch();
# W* _  _3 S# t7 fclosegraph();
% B/ O# F5 j% Freturn 0;
1 d1 R: T  K! W5 W* d, |} ( i3 X2 Q2 x; E; y+ G/ `: d
</FONT>
; j1 s+ G9 m6 o* O</P>$ ^- C) _3 `, ?% {$ p0 |) w" E
<P><FONT color=#ff0000>函数名: signal</FONT>
# y2 x' r% X, w& Q功 能: 设置某一信号的对应动作 " Q7 O8 l  l) K& p# m, Y$ P+ ^+ Q
用 法: int signal(int sig, sigfun fname); ( @& l/ J$ e) g! Z7 r/ i/ W
程序例: </P>
1 X) }& p3 X0 |  ^2 q/ `6 b<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, & f: v0 d7 g; G3 D
catches an integer overflow condition, makes an adjustment
  @& r- V0 V9 Kto AX register, and returns. This example program MAY cause , c8 s3 e$ ?  D2 ^  z
your computer to crash, and will produce runtime errors ) j% j- o, x4 }) Q0 M
depending on which memory model is used.
$ S$ d! o% D. h8 L*/ </FONT></P>  L$ y; ^  `; W9 O8 g
<P><FONT color=#0000ff>#pragma inline 8 f4 a; }: J% m* M2 R: G
#include <STDIO.H>
( `0 Z7 h* f) Q% ]# C' j# f#include <SIGNAL.H></FONT></P>6 ]" H: `+ E6 @& e
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist) ; ^0 T" v" h/ }. Y; _
{ 9 S8 [+ }, T7 D: e
printf("Caught it!\n"); 3 F* E+ C' \; E9 T7 P
*(reglist + 8) = 3; /* make return AX = 3 */ : S, R4 F. F/ ^- n/ K! M( [
} </FONT></P>
. M2 p% m( \( g2 K; j<P><FONT color=#0000ff>int main(void) 5 V5 |& \# {: _! c! Q% M. f. C
{ / g  E: c9 V9 T; v# l! @
signal(SIGFPE, Catcher);
4 `6 n& r7 n6 J8 Q- N& xasm mov ax,07FFFH /* AX = 32767 */ ' V, ?6 K" l. C
asm inc ax /* cause overflow */ ' {2 c: Q" ~9 d: m, B
asm into /* activate handler */ </FONT></P>) y3 }8 V" q7 E, h- ^* ~" j
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, ' D+ Z  s7 {6 ?5 b( f  T/ @
there would have been another exception when the next 'into' * G' M' o6 c" l+ M; ~* E( l
was executed after the 'dec' instruction. */
7 A1 [" v; c+ m" l# r+ zasm dec ax /* no overflow now */ $ p8 r" }8 G* `/ o4 q+ ?- g, h
asm into /* doesn't activate */ 1 n3 J; u2 \. G' K
return 0; ) ?# i! j" }4 ^7 G$ |( x
} . n: v) j' ^# S0 D% y
& o$ [5 ]$ M- w6 v

2 F& h: T  j+ T</FONT></P>' v. Q8 W/ g" t8 P# r
<P><FONT color=#ff0000>函数名: sin </FONT>
; T: x( k! S$ g5 g# \% ]功 能: 正弦函数 " I9 d* b) s* E2 c4 z9 V
用 法: double sin(double x);   ^4 y7 W. ?  N" i1 L) ^( C
程序例: </P>
; p3 q' J' C0 W! k<P><FONT color=#0000ff>#include <STDIO.H>7 A) ^1 ?$ O0 ?9 I( y
#include <MATH.H></FONT></P>+ p% @& B1 G8 H. Z$ S
<P><FONT color=#0000ff>int main(void) . |2 d& h' `/ h* m# h4 R: O
{ : g/ T, U+ @# n2 _$ ?5 _
double result, x = 0.5; </FONT></P>8 K9 E5 `/ u) ?/ i7 J- z
<P><FONT color=#0000ff>result = sin(x);
" U7 j8 h9 n3 U; ~% }" tprintf("The sin() of %lf is %lf\n", x, result); 1 B- L" @( e7 L: x9 A# M! \" m% r# w) s+ @
return 0; # q& @. Y& D1 ~
} 2 b/ H3 o, J' I9 ^9 o$ n0 C
+ C% a# j0 \  j! [9 i; K: _
</FONT></P>  z! E! y1 F  s: B5 P1 y
<P><FONT color=#ff0000>函数名: sinh </FONT>5 Z9 l# K$ T- ~# q# g5 U9 }" o: F1 K
功 能: 双曲正弦函数 $ [& c. V- C; s! ]8 p
用 法: double sinh(double x); : y: y- ~; \4 O+ h' R9 X( s8 Z
程序例: </P>
" d1 a  F( ?) ?! P: r<P><FONT color=#0000ff>#include <STDIO.H>) ~# o1 g9 m1 n  O: B
#include <MATH.H></FONT></P>
3 T6 V/ R+ r6 |3 {( I" p<P><FONT color=#0000ff>int main(void)
3 d0 U/ D' `; N2 ~8 u{ + ^2 ]# f/ i2 C; P8 c5 u& Z& o& E
double result, x = 0.5; </FONT></P>
4 t: f+ y  {$ x<P><FONT color=#0000ff>result = sinh(x); ) H% G) ~+ i$ G2 ~! C; ?& T/ N
printf("The hyperbolic sin() of %lf is %lf\n", x, result);
1 K5 E2 f1 K4 l4 T2 v* U  qreturn 0;
' m4 X7 C4 f! }. v0 e8 a0 e7 b5 U} & i/ K, a# ?, X  J5 {
/ I( t6 [, W5 @8 y$ Q7 m
' i4 D8 R/ n& d7 L
</FONT></P>9 F4 p0 u/ n- A, m  L
<P><FONT color=#ff0000>函数名: sleep </FONT>
. s. s, X8 g7 c; e功 能: 执行挂起一段时间
' A& W: I; C5 [: s6 j用 法: unsigned sleep(unsigned seconds);
3 @. b1 v, v/ G9 G0 n% ^程序例: </P>) T, ~+ V/ M* u8 d- h
<P><FONT color=#0000ff>#include <DOS.H>: H  \$ K6 A4 k$ L
#include <STDIO.H></FONT></P>
+ p( H, g: d0 o9 R<P><FONT color=#0000ff>int main(void)
" u- W( ~! S7 q# T0 v{
% S/ z5 Q7 \2 E  z) j6 Mint i; </FONT></P>
& H8 X3 u5 Z& D9 y<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
( |/ m! M/ D1 b0 ]) W{ 7 F# l7 R; P$ x- V
printf("Sleeping for %d seconds\n", i); # ?5 K# A/ k' S* f' |
sleep(i);
! P4 H# S  k5 v) k} : ~( j3 k" Z; p9 [3 e: F
return 0;
. N6 S# ^; M  {# f, ]} ! u& f2 Z% H% g, }3 `

$ x3 a1 i+ Z* E7 [2 J: d* N: ~</FONT>
# i5 Y" p+ ], R</P>
  Z8 s' }2 e  z: h( d3 p; \* D# A<P><FONT color=#ff0000>函数名: sopen </FONT>
: e& T: W: N+ ^8 a功 能: 打开一共享文件 $ l! ]- `* l( }2 |% }! u
用 法: int sopen(char *pathname, int access, int shflag, int permiss);
3 [3 a! h" v" M: k; v3 m程序例: </P>
% [- U. Z/ o8 O<P><FONT color=#0000ff>#include <IO.H>
1 A( Q3 f1 i. N, U#include <FCNTL.H>
5 V9 _2 [* s) N0 W2 C0 |+ O+ U#include <SYS\STAT.H>
! s9 m$ x/ A3 y7 _$ n4 K! `#include <PROCESS.H>, n# U! g8 \4 v! q  Q5 W1 I
#include <SHARE.H>
8 F2 O0 X" e, n' n# v#include <STDIO.H></FONT></P>
$ j: `4 q& ]; h0 r+ [<P><FONT color=#0000ff>int main(void) 0 {) I. D; C- Y- Z
{ # v+ u& y9 R6 O8 H% {: K0 r
int handle;
7 s/ K- O, N* \6 G/ ^) ~( C! q/ Aint status; </FONT></P>
/ B) o, D8 b8 _9 o$ v3 m<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>- ?; {, W5 q- Z7 ]+ Y+ M5 A
<P><FONT color=#0000ff>if (!handle) # J  ~3 N, e3 r# z
{
0 S/ |4 F% z/ Eprintf("sopen failed\n"); 6 \, h/ I$ Q" S+ l0 e4 E
exit(1);
0 t, `' R3 v) B& o( {. d8 P; w} </FONT></P>8 ~2 n- w7 c0 x: L/ i
<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); : J0 f1 w/ J& x' Y( |" B' ]$ d0 p5 b
if (status == 0) 8 u7 t5 g2 t) c) T, h$ v5 E: T
printf("read/write access allowed\n"); - e$ v" j8 {% F! w. l7 [+ G. C$ `$ w
else 3 _& ]4 X! M9 k4 f& k, i) C+ n
printf("read/write access not allowed\n"); </FONT></P>: i! l0 p* \  _& O) a6 t2 O
<P><FONT color=#0000ff>close(handle); ( k4 G6 z8 z; L5 d: f6 M
return 0;
" F; ^1 @6 V5 ?; N}
6 V5 G; S% B) P0 ^% {" |: x! |+ Z* j% Z% [) r: Q
</FONT>
  f0 Y. d6 K) V% o$ f' ^- [# I</P>
% A: [0 g1 g3 W( @7 U& I; m: u, t( r<P><FONT color=#ff0000>函数名: sound </FONT>
8 M+ {. ~% _, H功 能: 以指定频率打开PC扬声器   r( s( o) G4 m) T
用 法: void sound(unsigned frequency);
! u  F+ U. @- |: i* S% F程序例: </P>
$ U8 Z* J. A3 c) q8 t. p<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds.
8 u, {8 D, D0 C0 j) C2 CYour PC may not be able to emit a 7-Hz tone. */ ( [! Z) J% j% L
#include <DOS.H></FONT></P>, H. h8 H9 H  ]
<P><FONT color=#0000ff>int main(void)
5 M# v0 @, G/ M" L{ . s7 C  Y- p$ J9 Q1 w5 h- L" Y
sound(7);
* |  Z0 C( O! @2 [9 c; l3 L3 H& udelay(10000);
& t) P; i" e7 }. h% Xnosound();
  L0 ^( J( H% K( L0 f( h( _return 0;
6 }( D9 }/ X* E& m5 f+ i0 V} </FONT>
: [; V5 p2 }* ^/ c' [, Z! l8 B5 |, ^+ T7 \7 |2 V" ?4 n3 T2 z

1 V; T$ M" D, v2 p5 A. ]</P>0 b/ i3 i1 M' e% @; l) X5 d. Y- b
<P><FONT color=#ff0000>函数名: spawnl </FONT>% m) S2 V' D, L& k( }/ L
功 能: 创建并运行子程序 1 i; Q. a+ V" ]  C: u, Z3 @8 t8 y" w
用 法: int spawnl(int mode, char *pathname, char *arg0,
  L" H- j' c+ ?0 {) harg1, ... argn, NULL); 3 ^6 t5 M6 ?. T* n/ N0 O: E4 P' O
程序例: </P>
- k* Y( K! d0 E<P><FONT color=#0000ff>#include <PROCESS.H>/ ^! D1 X8 j7 S* ]* @5 `* j& g
#include <STDIO.H>
* x3 T# Z4 p0 r9 s% p% B) y: R#include <CONIO.H></FONT></P>% Q; ]' d" L& r+ K* K* I: F
<P><FONT color=#0000ff>int main(void) ) ]* \9 r" U; T+ j2 F
{ & `: h7 J9 l4 b) \( I2 e
int result; </FONT></P>8 m1 U+ R7 v" W5 c
<P><FONT color=#0000ff>clrscr();
$ h' i0 z3 p0 b9 Y$ D/ Kresult = spawnl(P_WAIT, "tcc.exe", NULL); # X; v7 X% ~  g7 p
if (result == -1) + F1 f; R# C5 k& t7 q
{
* s* H( ^( z. dperror("Error from spawnl");
5 r- i7 A. m- ~exit(1);
/ _7 G+ T( p  G! H, c3 W! o% ^2 n! s4 e0 h}
6 k# X0 R. c5 n* ~) j% U7 Creturn 0;
9 s- \, `0 G# S. c: h$ N/ |} ; ^. N# H0 _$ K- E3 w
</FONT>. ^# c9 H2 ]% F2 o5 i2 V/ A( e
</P>2 ]9 ^9 o% C: j  l. R2 J8 Q
<P><FONT color=#ff0000>函数名: spawnle </FONT>! s* G5 B( s/ m: c/ F
功 能: 创建并运行子程序
4 ]# _2 i( {+ {4 S: r8 W1 T用 法: int spawnle(int mode, char *pathname, char *arg0, 1 v& M  x* H; |- k# X
arg1,..., argn, NULL);
( K% p; x4 y+ ?1 y程序例: </P>
4 f* l% g, K$ [7 H: f9 N. P3 A4 d<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>  y/ C$ ^% \2 O1 \) i+ r  D
<P><FONT color=#0000ff>#include <PROCESS.H>
' s* [; G0 d, h7 L#include <STDIO.H>
7 ~0 C' @7 f$ ~. b6 r#include <CONIO.H></FONT></P>) ?4 S, n, ?: [0 E9 a9 z7 n
<P><FONT color=#0000ff>int main(void)   H7 v. Z) a! Y, J/ g
{
2 D9 H2 K% Z2 Nint result; </FONT></P>. w" d  ]! w: C9 S, ], M8 p0 `+ a
<P><FONT color=#0000ff>clrscr();
& W% z. c4 ?# ~3 L% n. oresult = spawnle(P_WAIT, "tcc.exe", NULL, NULL); ; ?7 ?) X# w: N. X0 K
if (result == -1) - L0 v6 U. q# C
{ ' s- m0 j$ @: z+ [+ L" v3 J& e
perror("Error from spawnle"); + D% R( }+ ]# I* U) Y
exit(1);
# S. z& F, X- _6 a$ W}
3 H) f/ k! ~* u, d) W& A2 ereturn 0;
3 v, m6 Z: U  _* Y, c; W  ^}
: [' q' t1 C9 j5 E2 v, V& k
5 P! n0 q  i6 c6 ?8 S1 ^( z8 K2 y) d2 f! [7 Z$ f; f) P
</FONT></P>
! u8 ]* ]0 R" d! N8 w1 n<P><FONT color=#ff0000>函数名: sprintf </FONT>0 O: L% o! l( D7 e/ b
功 能: 送格式化输出到字符串中
/ A# b+ v9 h2 i用 法: int sprintf(char *string, char *farmat [,argument,...]); & O+ _+ b6 Q. {$ i: S$ N! p+ U
程序例: </P>' ^, B$ m. c) O3 w0 Z
<P><FONT color=#0000ff>#include <STDIO.H>
0 N/ O* z# n% ]7 [$ P* S" n* X#include <MATH.H></FONT></P>  v# E5 {3 S, U& [' b: T. g
<P><FONT color=#0000ff>int main(void)
/ M0 p. \2 n+ l{ 0 p, A  \8 b' `* R1 B" i0 G
char buffer[80]; </FONT></P>& q6 S; p/ o% m* Z3 C$ g
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); ( ]; r+ `) E3 U9 n8 Q0 m" z8 Z5 u' Y* T
puts(buffer);
, v! M4 z3 D# V3 f7 q# Creturn 0;
6 p7 E; N( o7 c6 B) C3 H} 4 L( P/ J5 J9 F+ L
</FONT>: H$ ], _7 L' P
</P>. F1 h: w' J& C& o; m' E# N
<P><FONT color=#ff0000>函数名: sqrt </FONT>! Q! ^% ]' M$ Z, e: A7 o
功 能: 计算平方根
+ u6 b2 q& k2 p7 L- c/ T用 法: double sqrt(double x); 6 c' J4 I  w" R' M" j7 R
程序例: </P>( g0 ~2 }8 W# I
<P><FONT color=#0000ff>#include <MATH.H>/ B1 ~% W4 g0 M$ i  T2 Y' W. e
#include <STDIO.H></FONT></P>
2 D% q' s3 k/ i<P><FONT color=#0000ff>int main(void)
. ?8 V" _6 K# t9 ]{
1 n* Y8 _$ S" U# ]" rdouble x = 4.0, result; </FONT></P>
  g; T" [$ J9 O! c7 c<P><FONT color=#0000ff>result = sqrt(x);
+ A5 e7 P" \# z, _' ]% ?printf("The square root of %lf is %lf\n", x, result); 8 f) W5 s" I( e: V% W
return 0; . x9 F$ u8 ~& W% N$ a% R1 D+ m3 W
} ! B  q1 j1 ]- j7 `9 Z* t/ d
</FONT></P>! z5 o& M9 Q3 O% B5 d  ~5 F- C
<P><FONT color=#ff0000>函数名: srand </FONT>
- G7 p! C5 e1 n, m. X8 u功 能: 初始化随机数发生器
' ?, |" T$ r' L8 Q( Q0 v5 `1 w用 法: void srand(unsigned seed); 6 ~0 X6 H( c# E
程序例: </P>& w7 u6 A3 C7 R
<P><FONT color=#0000ff>#include <STDLIB.H>5 G' |, R) p3 W
#include <STDIO.H>' l7 E1 H1 N/ q8 H
#include <TIME.H></FONT></P>
5 C; y! Q' I  C; r: C% E8 M<P><FONT color=#0000ff>int main(void)
# a! P  d4 M1 b8 _( S{
% f- Z: t8 i. Eint i;
+ M$ ]6 m: h  r: ?8 Utime_t t; </FONT></P>
: D2 o- Y% `; M4 _1 `3 h<P><FONT color=#0000ff>srand((unsigned) time(&amp;t)); : [$ l# R: @* p8 W6 H1 F
printf("Ten random numbers from 0 to 99\n\n"); # Y% o+ r3 Q9 u) }2 a
for(i=0; i&lt;10; i++) + ~) V1 r7 e5 Y
printf("%d\n", rand() % 100); / n* K* u: ?  {* Y1 ^" j( t; ~8 e
return 0;
  G/ r$ \; E4 M0 m. j/ ]- w7 h}
) {1 `" Z% R4 n; j</FONT>
$ T, y8 C; H; G5 [8 ~* `</P>
% X# k* [% v4 t2 F' |<P><FONT color=#ff0000>函数名: sscanf </FONT>
5 G9 r1 T! j# `' y( @) p& N4 e- J功 能: 执行从字符串中的格式化输入
- F9 S! l8 R/ j) w用 法: int sscanf(char *string, char *format[,argument,...]); ' O$ |  d. O9 D+ p2 S
程序例: </P>
# S5 S. u  J4 [9 u$ \<P><FONT color=#0000ff>#include <STDIO.H>
, p2 }( S0 p6 R1 s' ~0 i& e# N5 B#include <CONIO.H></FONT></P>
2 u: |( M; N+ H2 }% ]- G; T1 i<P><FONT color=#0000ff>int main(void) + @+ R; C! e9 ?% L+ z
{ * C0 h% q( x# t
char label[20];
% O  x) C+ D: p2 {8 ?& N8 Hchar name[20]; ) n) }2 x. t: H; s% m
int entries = 0;
, I2 `8 U) L/ Z" w" s5 oint loop, age;
" o  |8 R" Q5 H" W2 r: sdouble salary; </FONT></P>
3 y. |1 `$ T1 f2 C" y2 _<P><FONT color=#0000ff>struct Entry_struct - f6 h8 z, d: r2 ~5 R
{   l  X" ~# |" K# E$ ?# ~0 Z
char name[20]; - V# m( [0 ~7 K7 s* L
int age;
8 @" w- c6 O2 u9 a" ^float salary; 1 i2 L$ U3 h4 ]- G6 u5 E
} entry[20]; </FONT></P>
0 ^+ U' g- t% l( p! h<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
( ^+ Q- w- \9 }1 z* hprintf("\n\nPlease enter a label for the chart: "); 1 H0 c" Z* J$ M1 S& L
scanf("%20s", label);
0 h9 h$ f/ Q3 Z# E! A* L8 cfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>; W! @8 \4 Z8 m1 w9 {) h
<P><FONT color=#0000ff>/* Input number of entries as an integer */ ; E+ w' ]  c) P: R$ s% s% W! k
printf("How many entries will there be? (less than 20) "); 9 J. h  P2 a  o2 h
scanf("%d", &amp;entries);
1 s6 Q) Y# B1 @" {7 A+ x! f. Lfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
" m6 }+ [! {# w! Q6 _% s( `$ q3 Z<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
! _# ^+ K0 w0 K0 lfor (loop=0;loop<ENTRIES;++LOOP)
  ^! X: Q2 {# \: x" Z3 q& Y7 K3 q9 x2 I {
4 z2 b8 ^/ o! [. `- P- ?printf("Entry %d\n", loop);
, v1 P) a2 p) x9 S' t' b; Xprintf(" Name : ");
& j' ?+ g9 G9 J2 u: k& o+ Q3 pscanf("%[A-Za-z]", entry[loop].name);
# Q# i* w, U# r. B# ?fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
4 H1 G3 t' S, q2 V2 @2 G+ K! \<P><FONT color=#0000ff>/* input an age as an integer */ " ~8 Y  g) f6 H4 F1 H, K7 j
printf(" Age : "); . Z' ^$ F, c: e4 e  C3 N
scanf("%d", &amp;entry[loop].age); ) m, J1 e) j. I* S; v: w; c
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>6 [7 u8 Y/ ]  @6 }
<P><FONT color=#0000ff>/* input a salary as a float */ 3 K. E# n% f6 \) D2 {' B, V
printf(" Salary : ");
! ~; A, L; Y) K: Wscanf("%f", &amp;entry[loop].salary);
( ]7 ?% r* M3 B2 mfflush(stdin); /* flush the input stream in case of bad input */ ; }4 K( y; T# k
} </FONT></P>4 ~/ M* Z, U+ h& v
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
/ R* V" Z. l/ `# ]8 i% v7 oprintf("\nPlease enter your name, age and salary\n");
3 ^" o& i2 U! F+ J3 `. o# x+ N& Q8 Uscanf("%20s %d %lf", name, &amp;age, &amp;salary);
4 {) z7 ]' c* {, s0 U: x</FONT></P>4 A# P( A( {9 t+ S  W0 E+ z' r
<P><FONT color=#0000ff>/* Print out the data that was input */ & w) ~8 V$ d& Q$ `
printf("\n\nTable %s\n",label);
( K0 m+ n  h. D+ k$ Gprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
+ b  t4 x% X- T* }, y( mprintf("-----------------------------------------------------\n"); ' m- f$ ]. w& v2 `" _: Z
for (loop=0;loop<ENTRIES;++LOOP) # z) u7 l: I* w: t3 m
printf("%4d | %-20s | %5d | %15.2lf\n",
# L% w7 ]- m2 P5 T3 j5 Gloop + 1, - @& o7 e8 ^" d3 A/ Y1 Z0 ?
entry[loop].name,
$ u# v" E3 }3 G% K. D8 Hentry[loop].age, 1 q! U& j3 [/ R; O5 c% O
entry[loop].salary);
( O* F. X; @' V% q/ K% M% @printf("-----------------------------------------------------\n");
- H4 q# z, v* l& `return 0; ' U- l% R6 p( Z7 p: @+ K1 R3 Y5 ~
} ! z3 `5 o" J: o6 `; ~
/ c! n% y! X. `4 O/ _+ ?0 T* S
</FONT></P>
( d8 T+ Y- I# u, A6 g: F# d% s<P><FONT color=#ff0000>函数名: stat </FONT>2 `6 Q2 E8 X# b8 T( a8 o5 z
功 能: 读取打开文件信息 0 u! ]  L- C1 E2 o
用 法: int stat(char *pathname, struct stat *buff); ; P6 c! F3 I2 t
程序例: </P>) P, M( Y) V1 I$ x9 w
<P><FONT color=#0000ff>#include <SYS\STAT.H>, e3 n' Z( o, K9 S) C" u
#include <STDIO.H>
4 h8 t; d7 f: d! m% k+ V. W; r#include <TIME.H></FONT></P>
4 `$ y" A" `- n) T<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
. ^6 v% Z/ j# |! y" ?2 P) Q<P><FONT color=#0000ff>int main(void) ; t# K6 k2 Q! L; R% v- b; w
{
' h" @& U* D  Y& bstruct stat statbuf;
0 X0 e, x- e" ]8 ]) ?3 @8 F: P: p8 D7 k2 eFILE *stream; </FONT></P>
8 x. a: G2 f. [/ h* \6 Q" C# }6 N! v<P><FONT color=#0000ff>/* open a file for update */ . v. ~1 B& B; s% f% h6 h6 w1 Q
if ((stream = fopen(FILENAME, "w+")) == NULL) / r& d5 d+ S7 w5 t  s! l/ u" S# ~
{
; N! s8 f) w1 B6 J3 H0 Yfprintf(stderr, "Cannot open output file.\n"); # q0 A& t7 Z2 d8 i# A; H' c; F! [
return(1);
: f0 ^% k& p" o! u- j} </FONT></P>/ w% Y/ z0 I) }5 ], o; T
<P><FONT color=#0000ff>/* get information about the file */
( \! B5 |' ~6 y( v( Fstat(FILENAME, &amp;statbuf); </FONT></P>
$ a2 h' K0 ^% f: F3 X: o& x, H$ w<P><FONT color=#0000ff>fclose(stream); </FONT></P>
7 |1 O8 N' ]: F8 \  E<P><FONT color=#0000ff>/* display the information returned */ $ Q7 K1 Z/ T; ]! J2 s
if (statbuf.st_mode &amp; S_IFCHR)
7 n# E6 S9 {& a1 M3 g6 iprintf("Handle refers to a device.\n"); ) O8 L4 B0 t- d' N
if (statbuf.st_mode &amp; S_IFREG)
8 v0 @2 {7 V$ Dprintf("Handle refers to an ordinary file.\n"); : ~' b$ e' q# P; X. L
if (statbuf.st_mode &amp; S_IREAD) * J$ {: Y: \/ W0 [$ T- U
printf("User has read permission on file.\n");
' w/ F' F% U2 ~& Xif (statbuf.st_mode &amp; S_IWRITE) % ?( J, d' {: L6 l- y  H
printf("User has write permission on file.\n"); </FONT></P># L" H6 B6 x  O0 e) ?
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); ' g: F2 J, B# E# R  s
printf("Size of file in bytes: %ld\n", statbuf.st_size);
3 o1 t' J: W* Z  i, K8 Hprintf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
  k' }6 Q4 c# o  |return 0;
; `* s7 z2 d' X4 t! b} 4 J* z& z/ G! |

$ k, o3 X1 u* P" S/ L3 ?</FONT>$ i7 q8 n+ O% {/ L5 d0 B
</P>
. t% G  ?* D6 j<P><FONT color=#ff0000>函数名: _status87 </FONT>
  l) t* o6 K* M. T3 p功 能: 取浮点状态
/ S8 f& P, v9 ~* ^, w" `7 o用 法: unsigned int _status87(void); 0 @4 d' B3 g7 D1 X! w3 _' K* ?/ j
程序例: </P>2 x; k7 q9 h) }$ N$ [" s# t' p/ p+ d
<P><FONT color=#0000ff>#include <STDIO.H>& s- y" x9 S2 e, n3 T) w
#include <FLOAT.H></FONT></P>
8 u$ v6 U5 j  @/ h2 J<P><FONT color=#0000ff>int main(void) 9 F- e/ e  K) A: P$ P/ ]
{   I8 e  _" p' k; ]5 Y
float x; ; S1 k, T6 o. o  b
double y = 1.5e-100; </FONT></P>: F$ C5 O+ J% y" ?
<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
% ^) l/ V! y' c- c7 ?! ]/ h<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
. t0 a+ Y' F% F, My = x; </FONT></P>
: |+ }! L. o7 C+ m* j2 s( p<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87()); # ~+ a2 D* g- b+ ]  _
return 0;   M& W! N6 {- b: P& x
}
+ K) N+ r0 e, V* ?/ S% s+ Z% M0 I/ d</FONT>
" F6 z8 \7 C! S: V) ?, u) n</P>1 t0 V( @% |5 i
<P><FONT color=#ff0000>函数名: stime </FONT>* u* f; J' k4 E1 p) K
功 能: 设置时间 % \+ d8 L% e0 q0 u
用 法: int stime(long *tp); / z3 ?# p7 m; N4 [+ R
程序例: </P>2 ?- F! F( ?2 ~
<P><FONT color=#0000ff>#include <STDIO.H>
( e; A7 ?- R9 R" y# U#include <TIME.H>
# k# B8 }; s! O: n  r8 F5 Z  h#include <DOS.H></FONT></P>9 X& Y3 _; R% k8 D
<P><FONT color=#0000ff>int main(void)
! U+ W- g, d/ V% g+ J# @( v{ " _$ q+ |, V8 i- L7 C# [' n2 w
time_t t;
5 Q: k: K$ F# tstruct tm *area; </FONT></P>
1 Z* T# ^: l. i( c' j* S<P><FONT color=#0000ff>t = time(NULL); * n7 Z7 A3 y, f! ^! h
area = localtime(&amp;t); 1 e, _7 c% h* O8 {. V/ r1 H
printf("Number of seconds since 1/1/1970 is: %ld\n", t);
2 ~  \- ?$ q6 \7 }' T' _! S5 qprintf("Local time is: %s", asctime(area)); </FONT></P>
9 I% H  A7 C+ `( U& P( ?5 `<P><FONT color=#0000ff>t++; 5 c( h5 s6 P& t6 I3 x! P. ^
area = localtime(&amp;t); 7 O! b) |5 V' \2 v: ~
printf("Add a second: %s", asctime(area)); </FONT></P>7 c/ P  B$ H. N
<P><FONT color=#0000ff>t += 60;
: @/ m5 ^( u, O( ]( M5 N6 t7 w+ Karea = localtime(&amp;t);
7 \) K; [: Q2 G4 b4 yprintf("Add a minute: %s", asctime(area)); </FONT></P>
! c( _% w- P2 ^5 o7 C0 ^2 Y<P><FONT color=#0000ff>t += 3600; 2 H; _! D9 U3 V( g  ]3 N
area = localtime(&amp;t); 5 @6 p% }8 I3 T4 w! Q$ |# q: u4 i
printf("Add an hour: %s", asctime(area)); </FONT></P>
& W3 F: g/ A2 ~$ e. K5 S<P><FONT color=#0000ff>t += 86400L; 1 S8 B  i3 g7 e7 r+ x
area = localtime(&amp;t);
/ D" S, t$ b5 z9 D% O! w  [3 a& \4 H& Kprintf("Add a day: %s", asctime(area)); </FONT></P>% o+ y, l( P) _0 \' f) G) D
<P><FONT color=#0000ff>t += 2592000L;
7 J4 S3 Q& k& f* z7 q9 p+ Darea = localtime(&amp;t); + q& Y. k1 w8 W3 ~0 f) ~3 ^. C
printf("Add a month: %s", asctime(area)); </FONT></P>) p/ i1 H8 e5 D" B# T0 K1 W" g
<P><FONT color=#0000ff>t += 31536000L;
( ?5 K& j& j' u) ]- z- r& rarea = localtime(&amp;t);
4 y# v# ^. a3 Y( ?% ]! O, `; qprintf("Add a year: %s", asctime(area)); ; h7 N# r) Z3 P& T7 \1 t1 k2 W
return 0;
* @4 l' e* V' B; \) V} </FONT>6 Z7 y3 v3 Y' t( h

9 g7 a# Y  o2 y5 {7 I% H5 \* |, j
</P>! T' ?! Y2 J  z9 x8 P7 q% X% |
<P><FONT color=#ff0000>函数名: stpcpy </FONT>
2 f/ L( z, c& n/ f功 能: 拷贝一个字符串到另一个
4 E/ r9 v+ z& r  T8 h用 法: char *stpcpy(char *destin, char *source);
: u9 t' @) v* r( d程序例: </P>3 ^8 q1 V& O; N! ?4 i' \9 q" R
<P><FONT color=#0000ff>#include <STDIO.H>( i; g; x; D& J# [3 G: j' i8 u& f
#include <STRING.H></FONT></P>* q& ?# k; l9 |  n, d4 V% Y
<P><FONT color=#0000ff>int main(void)
+ K3 g* `- p/ Z% O' w. U{
* C: i* T4 P% e9 y. x( M# ^char string[10]; - w; M3 y% D) v6 x# z9 g- j  g7 `
char *str1 = "abcdefghi"; </FONT></P>
# [3 m. |+ ~! K- f' B5 I9 K<P><FONT color=#0000ff>stpcpy(string, str1);
, ]  [. E' M; L9 D/ N5 sprintf("%s\n", string);
4 r! c$ Z1 z7 Z: p' Q$ yreturn 0;
( y( l" m. \, s; m4 \1 x}
, t+ R& \) c& e1 l* l! m- ]& R( N; C& N; I, ?2 b
</FONT>
! c9 u( O1 h# ?, i8 F5 U$ u</P># H' h$ N! ^) g4 q
<P><FONT color=#ff0000>函数名: strcat </FONT>, O2 L, I% T+ o( ]  Q; Q
功 能: 字符串拼接函数
& E2 y. x) g) l: w8 ?6 i用 法: char *strcat(char *destin, char *source);
' ^: m4 }( J' J2 G6 D. n/ o9 _5 V程序例: </P>
. D, u) X; k* m: k6 x<P><FONT color=#0000ff>#include <STRING.H>
6 V; o% D) G# g) ^#include <STDIO.H></FONT></P>+ _- L  E. S/ x7 J# K
<P><FONT color=#0000ff>int main(void) 1 f3 _8 ?$ q. R0 D
{ ! y' U' X$ c) x- n7 V
char destination[25]; ) p, P+ s) {' l. K
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>( @) c4 ~( M3 O/ `
<P><FONT color=#0000ff>strcpy(destination, Borland);
* R' K1 J0 r7 Q% bstrcat(destination, blank); % G4 i) ^, l/ _. G! h0 D
strcat(destination, c); </FONT></P>! ~5 P+ p# M$ i& b/ f, k: M8 q; F
<P><FONT color=#0000ff>printf("%s\n", destination);
& t0 {  T% \/ O6 i/ ireturn 0; 5 W7 r; T+ ]$ k1 U$ k3 y6 i
}
+ C4 T2 ~' Y* o) P( c
, J! A5 ~( h! S9 H3 J- _; y</FONT><FONT color=#ff0000>
7 Z! j1 \# V8 L$ W</FONT></P>$ B# S" t, Q, t8 f5 s; H# Z' l
<P><FONT color=#ff0000>函数名: strchr </FONT>" I5 |  U* C  e8 V% g+ X
功 能: 在一个串中查找给定字符的第一个匹配之处\ 9 s1 N! ~- z8 j" t- g
用 法: char *strchr(char *str, char c); 5 U6 [0 x5 Q2 C+ \4 Z8 T
程序例: </P>8 O- {% M% d7 s! Z. J1 i( W
<P><FONT color=#0000ff>#include <STRING.H>6 h+ p4 }( [/ i5 Z( X8 I2 L; m
#include <STDIO.H></FONT></P>5 D+ o# _0 A/ f
<P><FONT color=#0000ff>int main(void) ; a% r/ D* l: I4 A
{
, K* z: c% I- x$ F" P: h; xchar string[15]; " h) l% ?' R5 T3 v
char *ptr, c = 'r'; </FONT></P>3 i& A  W/ ~. T, w
<P><FONT color=#0000ff>strcpy(string, "This is a string"); - C0 g5 k8 A; ]  U& @
ptr = strchr(string, c); / d" b! |, T- e
if (ptr)
9 I- ]* d. B( k# x5 oprintf("The character %c is at position: %d\n", c, ptr-string);
; j* A1 u! ?/ J3 x" T" h1 telse
! R+ H, G; |' ]: z/ Rprintf("The character was not found\n");
# z) u3 w* Z5 [( |$ q; ureturn 0; + @0 c3 q* s& j
}
% G) v9 J& k8 I$ K5 K8 o</FONT>: e) S4 E# d9 X& x  b2 I, c
- [& _% N2 n" ]0 }" q9 X- \1 l& W
</P>
1 i+ c- r( W& S4 W<P><FONT color=#ff0000>函数名: strcmp</FONT> . ^3 n5 D5 k0 F) H$ \% K8 G+ O3 ?( [. x( ]% r
功 能: 串比较
; |& h7 Q1 ~6 O9 T6 @用 法: int strcmp(char *str1, char *str2); , ~8 C& s7 T0 G
程序例: </P>
2 B+ `. f0 R2 l  u: p# a<P><FONT color=#0000ff>#include <STRING.H>
* O: W# h' r; c#include <STDIO.H></FONT></P>
; W; D# h( p& n. b0 ]8 @, ~<P><FONT color=#0000ff>int main(void) 8 f: P2 G& o1 m  ]1 Q& Y8 |
{ ) J) o7 v' ^6 y( ?; f
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; ( v# N: [& s0 G. W! A" e  w$ k4 U; F0 v
int ptr; </FONT></P>4 J* Y+ o. S/ W. A" f9 t
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1); ) G$ G$ Z2 r; r- [8 J4 x& c  B% N
if (ptr &gt; 0) " E9 T5 t1 [6 N$ e
printf("buffer 2 is greater than buffer 1\n"); 0 g* F: X$ J$ B7 M
else
- s% m* d7 _+ p+ fprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
3 ?+ }! t& T' K; H- g+ a+ T* ]<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
( `- F+ `' m, L- \9 W" T; p7 o2 Xif (ptr &gt; 0)   i3 P3 j3 K$ c* m0 T, o( |! P
printf("buffer 2 is greater than buffer 3\n");
  J' E) T8 ]  [7 v! helse
2 ]& y; W' _- s+ A% `printf("buffer 2 is less than buffer 3\n"); </FONT></P>" v% F! `5 A5 v9 g3 g5 U: o7 t
<P><FONT color=#0000ff>return 0; ! o2 |6 z7 s& J' S& M5 m) S
} ! @: b0 V6 F/ V( ?# P
* Z# q0 o+ f9 d' ^

. b$ D" ~* i: v</FONT></P>1 k- {( v; l) U+ `- O) v* R) \2 N2 y
<P><FONT color=#ff0000>函数名: strncmpi </FONT>
" U5 q0 P! b) [! w. `1 S功 能: 将一个串中的一部分与另一个串比较, 不管大小写 * O* {0 [  D7 H4 |" V8 F
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); $ \- Y3 H. h4 ?0 Z) q; J) g, t
程序例: </P>$ O( k9 Y! N' Z
<P><FONT color=#0000ff>#include <STRING.H>. C% b% d) ^% x# w! z: |9 V" J
#include <STDIO.H></FONT></P>
; M9 N4 u7 v8 k+ s$ q' }- P9 `<P><FONT color=#0000ff>int main(void) & y! S0 _) N5 a! F  D3 ^
{ 2 S' m1 v  `3 r: L. e' }  \
char *buf1 = "BBB", *buf2 = "bbb";
! j5 o6 }' \& Z$ m  Hint ptr; </FONT></P>
: q! d% a8 i+ v6 T! M; \0 D3 o<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>( B/ K4 o8 R" X6 R; _6 g4 _7 L
<P><FONT color=#0000ff>if (ptr &gt; 0) 2 Y5 ?) t4 y3 M0 \
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
- B1 ?- t0 V) N' J* @<P><FONT color=#0000ff>if (ptr &lt; 0)
& N$ Z$ h( A7 f% m/ S) _: Aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>" M! ?' S5 C" o* \3 Z
<P><FONT color=#0000ff>if (ptr == 0) . b/ B% h, t2 G3 j; R4 y" K
printf("buffer 2 equals buffer 1\n"); </FONT></P>
9 S0 a% m0 U, z" J5 m7 i<P><FONT color=#0000ff>return 0;
0 {  k3 I3 [$ d7 J}
+ d+ Y6 l. K# n  s- k/ `& i4 i$ V( {1 Q, s! U
</FONT>
1 i: }0 A. Q4 Z- _9 B0 S& H( t2 C- U</P>
$ @, N5 D+ F; G) I9 A$ L<P><FONT color=#ff0000>函数名: strcpy </FONT>' c( t7 V4 _$ a+ @: |; ]  n+ ?
功 能: 串拷贝 , K$ N( W) H; G8 r& E
用 法: char *strcpy(char *str1, char *str2); 5 l; p3 r1 _3 I0 m9 n" Q
程序例: </P>0 N) h8 l9 ^5 D% ]7 A/ B
<P><FONT color=#0000ff>#include <STDIO.H>9 t1 ~& I3 X* C/ `' i, k
#include <STRING.H></FONT></P>- v6 \( e  u5 e
<P><FONT color=#0000ff>int main(void) $ p0 y( @3 _" t
{ / {- p) [' P8 [1 `0 Z" S, \
char string[10]; 1 s8 j: r7 g  V2 k4 T8 P
char *str1 = "abcdefghi"; </FONT></P>
& m) P1 J: T- z6 w5 B; G<P><FONT color=#0000ff>strcpy(string, str1);
! K: {; w# P3 F* oprintf("%s\n", string);
9 S7 [* a5 Q, {return 0; $ P8 k5 g. d8 m8 b4 i
}
8 {* q& [. ]/ A) ^; K, ~' M</FONT>
* ^! }3 _, w  h5 y' |
; s$ h( n# ~" w</P>. K5 i7 E$ g: w, [! t/ ^* N
<P><FONT color=#ff0000>函数名: strcspn </FONT>( k9 j# G1 F" V4 Y+ d
功 能: 在串中查找第一个给定字符集内容的段 2 U1 P6 z* h& \2 W
用 法: int strcspn(char *str1, char *str2);
/ o5 ^) o! c4 [* d程序例: </P>! S! w+ M8 s/ Y' a0 Y
<P><FONT color=#0000ff>#include <STDIO.H>& Z. n  B$ s+ T5 [8 k" V$ }4 S
#include <STRING.H>1 f+ K8 o& V  U; R9 J. h
#include <ALLOC.H></FONT></P>
# t+ p' G1 ^. e1 E4 y5 h<P><FONT color=#0000ff>int main(void) ( O+ G: j5 i% n0 Z# e1 G! l7 K
{
# j3 h5 ~8 X) d3 Mchar *string1 = "1234567890";
% [* B0 c8 O5 f, w& K7 Ychar *string2 = "747DC8";
# i; V0 Q- ?+ S( ~int length; </FONT></P>
  \: \; v- |7 e6 U8 f8 k<P><FONT color=#0000ff>length = strcspn(string1, string2); % P* Y! H4 o+ j1 Y! e( o
printf("Character where strings intersect is at position %d\n", length); </FONT></P>
0 |& U7 Q: b4 N/ f+ K% D<P><FONT color=#0000ff>return 0; ; P+ h  {5 \& B' _) |) `, l
}
: ]; ~% r1 ~+ n% n/ i" a) o</FONT>) z" O0 M; C) l( b) z+ ~
) e7 J0 W# ^- P- Y% a, o: K. Z2 e
</P>
, R) S3 P: h3 h) Q' s<P><FONT color=#ff0000>函数名: strdup </FONT>/ L; _5 O; {5 j8 M- k5 Q( Z2 m0 x! n8 _
功 能: 将串拷贝到新建的位置处
3 c" E" J' L4 Y& `4 s$ l, m# H4 v用 法: char *strdup(char *str); " `! f* N, Z' O: C  [6 `
程序例: </P>5 K! R2 ~+ H8 e3 F5 l$ D. C
<P><FONT color=#0000ff>#include <STDIO.H>
0 |1 O5 ~- R- j' @+ V" j#include <STRING.H>0 L4 Z/ W0 S) O3 O8 {
#include <ALLOC.H></FONT></P>3 V, `4 \$ B! U5 i3 B+ E5 p+ M
<P><FONT color=#0000ff>int main(void)
9 C: y4 ~% Q4 c) K- ]{ 1 Z: l4 F9 P1 T" K- `- E+ [* D
char *dup_str, *string = "abcde"; </FONT></P>* ]5 ?; h8 E0 ~/ t+ v' |6 `. p  d7 O; f
<P><FONT color=#0000ff>dup_str = strdup(string); 1 m6 p# o$ p+ d5 F
printf("%s\n", dup_str);
% X- K5 F9 `, s5 efree(dup_str); </FONT></P>
# y- r  h* A! Y4 b% U" f: d<P><FONT color=#0000ff>return 0;
& {% y# k6 C* ^0 B4 o( y}
  r7 a, k# Z) p: J) d& U5 M# x+ n: u/ R0 T: N
</FONT>8 u$ u# d, r+ Q# ?
</P>
8 |; q; x" J( }- g7 L<P><FONT color=#ff0000>函数名: stricmp </FONT>
- N. U5 {" c# O6 `' u) e2 C0 ~功 能: 以大小写不敏感方式比较两个串
" |' e; I& c* _' {用 法: int stricmp(char *str1, char *str2); 6 I  F. ?2 t' D4 `* H
程序例: </P>6 }1 I. E8 Y" |2 _4 ~
<P><FONT color=#0000ff>#include <STRING.H>( B5 K- ^1 Z% B) X' G
#include <STDIO.H></FONT></P>" [' y1 S7 ?0 F6 I
<P><FONT color=#0000ff>int main(void) ( T1 d( d  v* c/ P. U
{
# R) @' \$ J! {char *buf1 = "BBB", *buf2 = "bbb"; ( x, l' y: F9 X9 R! @
int ptr; </FONT></P>8 N8 Y0 Y9 k8 l5 W6 b% p
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>; |/ H! V' ~+ Z  u' ?
<P><FONT color=#0000ff>if (ptr &gt; 0) % u$ |) @: k- e' U/ e
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>: O' _# v  m; d3 f
<P><FONT color=#0000ff>if (ptr &lt; 0)
) s4 H% }$ f& ?. Z& P4 {! ^" _printf("buffer 2 is less than buffer 1\n"); </FONT></P>
3 j' u3 `* T4 B<P><FONT color=#0000ff>if (ptr == 0)
0 d+ Q; v# H: }% Tprintf("buffer 2 equals buffer 1\n"); </FONT></P>3 h- w6 z. f, r
<P><FONT color=#0000ff>return 0;
  X( h) m7 s& N% a5 M- Z/ @} 0 `5 L) h! S/ y% S4 w3 m
</FONT># T; P" w, d% k. O
</P>, q) Y! q$ }* X5 [8 j* U& B
<P><FONT color=#ff0000>函数名: strerror </FONT>5 x9 W& ~5 m& c0 Q' t
功 能: 返回指向错误信息字符串的指针 ; b6 T6 A, z$ o8 i- Y
用 法: char *strerror(int errnum);
+ l) \) W2 `- M2 @! r' S; c% z程序例: </P>! g$ u8 X+ K# n2 ]6 M) v5 {
<P><FONT color=#0000ff>#include <STDIO.H>
) u* @  K, b: l#include <ERRNO.H></FONT></P>
$ z* T: ?: z. P5 C. d<P><FONT color=#0000ff>int main(void) + x3 z& T! f- x( x% O/ `
{ & l  G" @+ F" V" v6 u$ l0 v0 N" A# E
char *buffer;
6 u5 z+ N. Z- D) i& Mbuffer = strerror(errno);
! g) ?+ w& M7 a. l; e4 \+ oprintf("Error: %s\n", buffer);
" ?9 _* K: a7 d' t, Y' e7 i' oreturn 0;
! n) |; `2 J2 R3 J* f# a. X}
* {: Z- U5 W5 O- k* p
+ Z/ D( u2 {: U</FONT>
4 M* s4 @7 m8 l% c! K</P>* X( I) V) a8 F* m) F/ Z; o
<P><FONT color=#ff0000>函数名: strcmpi </FONT>
! r+ h" ]8 h5 h- F8 X: Y/ a功 能: 将一个串与另一个比较, 不管大小写 - x+ z3 J/ K8 V: Z, x
用 法: int strcmpi(char *str1, char *str2);
3 y' f  i! g/ j) ?( O8 G4 E程序例: </P>
0 _4 w9 G" N7 u# x, X# o<P><FONT color=#0000ff>#include <STRING.H>7 {# I  F1 }) l0 ?
#include <STDIO.H></FONT></P>2 B# Y* i# G1 j4 ~5 D9 @# z
<P><FONT color=#0000ff>int main(void) 2 {, T# {% v0 }) }/ f, f) C# @) z
{ # |4 g* T/ c) Y1 q; j& P
char *buf1 = "BBB", *buf2 = "bbb";
% U2 ~1 b2 l1 kint ptr; </FONT></P>/ @6 I: u* R1 w$ C/ j) o6 F
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>3 ?) o7 x6 J' H( T
<P><FONT color=#0000ff>if (ptr &gt; 0) . n4 h3 s  H4 `  E) e
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>) n5 G$ G0 l4 o: L
<P><FONT color=#0000ff>if (ptr &lt; 0) 6 }# y2 n5 T' @" v; B
printf("buffer 2 is less than buffer 1\n"); </FONT></P>  T4 c; l0 V8 }4 d* r& H# R
<P><FONT color=#0000ff>if (ptr == 0) : T. O- \$ @, h
printf("buffer 2 equals buffer 1\n"); </FONT></P>
5 t3 \: N+ ?# z) {! @<P><FONT color=#0000ff>return 0;
8 R4 S, |& E" C7 E  w/ k( x. }: H}
& J, ~  }; P1 ^& A</FONT>
) S" R; B" Z0 U/ y) I1 b# }
! V0 {6 M* `& ^( D& K' L( Q6 ?</P>
' ]# p1 E9 w! `/ m0 }- X0 E6 v$ g/ f. K<P><FONT color=#ff0000>函数名: strncmp </FONT>7 w- c/ E) j/ \- R1 y% \; |+ p
功 能: 串比较 ; J$ D; z3 g: ]. V
用 法: int strncmp(char *str1, char *str2, int maxlen);
7 H2 Y% f( Z: W. h2 N4 P; m程序例: </P>
4 u6 P/ z% M. F. H2 t7 u5 ^<P><FONT color=#0000ff>#include <STRING.H>
/ Q4 j; m) w3 c" C3 L#include <STDIO.H></FONT></P>5 [) C& l2 G9 f% Y( e7 m
<P><FONT color=#0000ff>int main(void) </FONT></P>) N( S% h  Z/ N
<P><FONT color=#0000ff>{
' ^$ n- t5 _% U6 i  c% ]char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
8 n/ `' H0 p& @" z4 _" Oint ptr; </FONT></P>
0 l7 A+ b* o# c3 D<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
0 }/ e; v6 k7 D( a6 W4 y4 p4 n) t$ v$ G# \if (ptr &gt; 0) 8 X; y) Z8 t5 f! d5 Q7 V
printf("buffer 2 is greater than buffer 1\n"); 0 G$ _; G* w4 Z
else
* E2 |$ s7 u/ r. vprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
" l+ H% h2 o* b* c2 G5 s& x( D<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3); 6 K, J: j. G9 o" b6 e+ E
if (ptr &gt; 0)
( W' u# r' j% [% M! y5 `# _printf("buffer 2 is greater than buffer 3\n"); 5 I; d' s. I0 a7 }& F: L/ I( j
else 0 w/ V1 e8 G1 r) p) ?
printf("buffer 2 is less than buffer 3\n"); </FONT></P>1 y% y& l; t4 i. O
<P><FONT color=#0000ff>return(0);
6 s9 `4 Q- S1 u/ h7 N& r' h' i} . V  F% y, m; P* i$ h4 C6 p; }2 M

9 _1 j& w! |$ u7 a# Y% t</FONT></P>1 V  H# B* p6 i/ @$ h6 I# s8 g2 U
<P><FONT color=#ff0000>函数名: strncmpi </FONT>4 a% n  I0 l" m
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 * `  ?& c. l* X& k" Z0 y" H( @+ K
用 法: int strncmpi(char *str1, char *str2);
: F; J5 E! f! w: f1 Y( j: t程序例: </P>
6 D+ m2 O* s; J1 h, h6 F<P><FONT color=#0000ff>#include <STRING.H>8 L+ _% Y+ g7 R' g' ?" O4 b
#include <STDIO.H></FONT></P>
& Z2 l: {5 h" s* {$ ?0 N' [<P><FONT color=#0000ff>int main(void)
; D1 k- u7 k$ g6 d{ / ^) P2 A5 B. K# b: z* P" n
char *buf1 = "BBBccc", *buf2 = "bbbccc";
* ~5 P  g- g' b: iint ptr; </FONT></P>
: ^1 u- @+ ]" a0 |2 e<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>9 j. t6 X$ n, a9 J+ }7 h. n
<P><FONT color=#0000ff>if (ptr &gt; 0) , T! _# j' g9 z) A$ j, E. k
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>  @/ A& O" ?1 E
<P><FONT color=#0000ff>if (ptr &lt; 0) 4 L( S; m0 f& W' z
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
5 p" D- H' q) b<P><FONT color=#0000ff>if (ptr == 0)
' w$ w0 }* T; [- ^: ]4 G& bprintf("buffer 2 equals buffer 1\n"); </FONT></P>
. f) O9 t0 V- c  x<P><FONT color=#0000ff>return 0; </FONT>
9 T; B+ l6 {+ V6 H1 o( v} / A' N* J2 _! m/ C8 H$ G
4 j8 R6 _/ A  H$ J% |7 K, u$ k
</P>
4 P* Q8 Y1 U: g9 W9 p1 d<P><FONT color=#ff0000>函数名: strncpy </FONT>
# `" r5 I+ q( f* v功 能: 串拷贝
0 H- V! l( B* d9 `- l用 法: char *strncpy(char *destin, char *source, int maxlen);
; {9 h+ y  f! @1 q3 s( R9 @( E程序例: </P>
5 n" h" G5 z6 f# o6 f, I0 x; y4 \: @<P><FONT color=#0000ff>#include <STDIO.H>
; h$ J. Z; v& ]4 s2 q#include <STRING.H></FONT></P>9 g" z; H( s: a7 X" c3 c! g; I
<P><FONT color=#0000ff>int main(void) / t6 c% v2 a1 F# N! X4 `+ d9 V
{ 4 H0 B% D8 l, c1 R+ o, T$ h% f! [
char string[10];
" y+ }) J8 X9 ]% nchar *str1 = "abcdefghi"; </FONT></P>, ^0 t/ L# F: X5 a! `. u/ {
<P><FONT color=#0000ff>strncpy(string, str1, 3);
4 v( z# v& j: y2 ]0 D& lstring[3] = '\0'; & _/ p: h; t5 @4 U% }9 q- t
printf("%s\n", string);
# I6 P( r1 o8 f9 k2 \& Xreturn 0;
  D6 `& K! h& V* G}
" m' M" W9 V8 N</FONT>* y- w6 T8 g3 }# p% L! \( s
</P>0 W7 `8 j' N/ a; d
<P><FONT color=#ff0000>函数名: strnicmp </FONT>
6 G! j% I8 H8 X2 l! _3 I功 能: 不注重大小写地比较两个串
8 G0 Z  i3 s0 t/ }2 ?4 _用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
: z# J/ S/ P/ D; P* e! ~' z程序例: </P>
; r8 B6 R  J% _; g: l<P><FONT color=#0000ff>#include <STRING.H>
3 W& |" L8 B# a#include <STDIO.H></FONT></P>
8 d* O/ }" m! q+ z<P><FONT color=#0000ff>int main(void) 9 Q: R. W' m1 k+ @1 N! G
{
# O% z9 ~6 i! q  L" ^. G% I1 kchar *buf1 = "BBBccc", *buf2 = "bbbccc"; 2 q) B' a1 O4 [0 K
int ptr; </FONT></P>9 `$ X$ A% f& F
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>% e  @/ d- J6 p
<P><FONT color=#0000ff>if (ptr &gt; 0) & k' I, n, B4 [" z! j, f# k
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>6 s: X/ Q9 M' K0 S  B+ b
<P><FONT color=#0000ff>if (ptr &lt; 0) 1 W7 J. S0 d- X  B3 O' e. @' L
printf("buffer 2 is less than buffer 1\n"); </FONT></P>0 S# d1 j% y& z. D2 }
<P><FONT color=#0000ff>if (ptr == 0) ' a3 [+ W9 O* @: p
printf("buffer 2 equals buffer 1\n"); </FONT></P>/ S( O$ m/ g8 A0 {% t
<P><FONT color=#0000ff>return 0; + W  Q" g9 K) \/ O- ]4 J) `
} 9 }" r" i( ?$ v4 D$ U9 j

) L/ e$ D3 n2 @7 O+ n- J1 c</FONT>+ [0 V' {" b1 t  L7 s; o
</P>
& f( B- \" E) ^3 @<P><FONT color=#ff0000>函数名: strnset </FONT>
) \- a. V4 ~  J4 f功 能: 将一个串中的所有字符都设为指定字符 ; Z7 I1 P/ r% O( B7 t
用 法: char *strnset(char *str, char ch, unsigned n);
& Z* L: D* T5 r3 _" T7 |程序例: </P>
2 |$ M: T! j/ v<P><FONT color=#0000ff>#include <STDIO.H>
9 n7 X6 P0 u: a7 g' r6 |4 D#include <STRING.H></FONT></P>& Y+ t& Y9 {9 _2 r7 v6 z
<P><FONT color=#0000ff>int main(void)
. p+ V' d4 t" Z5 r# G% V{ - ^9 V1 W; @  v
char *string = "abcdefghijklmnopqrstuvwxyz";
1 N$ Z  H8 `0 e& mchar letter = 'x'; </FONT></P>3 V) Q; U0 {+ t" a" E& u
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
1 E. c5 ^( H' l* u' }1 jstrnset(string, letter, 13);
3 e$ K$ q6 D  ~printf("string after strnset: %s\n", string); </FONT></P>9 Z6 p  h6 h4 A- @: v# `
<P><FONT color=#0000ff>return 0;
. n0 l8 w8 E$ R7 Q* Z% s! a}
+ n* a" c$ c- m</FONT>
# D  z' t# D; s2 R* J</P>1 m  Y: y6 Q! o5 k+ i
<P><FONT color=#ff0000>函数名: strpbrk </FONT>5 h2 R7 ]% P1 B- p6 w2 p, x5 s$ y8 }
功 能: 在串中查找给定字符集中的字符
$ W; D8 ]# b0 v' F& P7 W/ Z用 法: char *strpbrk(char *str1, char *str2); 6 r7 ?4 `$ Q$ q& G* c
程序例: </P>7 \; I; P0 u1 O3 f4 r
<P><FONT color=#0000ff>#include <STDIO.H>6 |) R8 ?3 X+ x* u+ Q0 x" z
#include <STRING.H></FONT></P>+ U7 q+ J! y% n$ F+ K
<P><FONT color=#0000ff>int main(void)
2 ^3 R1 _0 D) {! F1 k: `) G{
$ K5 g) k( @( S+ J. w' d" qchar *string1 = "abcdefghijklmnopqrstuvwxyz";
; ]5 {2 I) c( v9 i  ~char *string2 = "onm"; 5 W9 ]3 w' M3 H" Q1 j5 r3 U% |
char *ptr; </FONT></P>% j; ^8 V( r+ S8 B
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>2 v* ?" ~; _% U5 U$ w2 H2 P. Z
<P><FONT color=#0000ff>if (ptr) : y! B+ o* N* K4 |# ^
printf("strpbrk found first character: %c\n", *ptr); 7 p4 x' m; R8 M  ?% f
else
8 l* h, ?& w5 W! B' hprintf("strpbrk didn't find character in set\n"); </FONT></P>
1 Q3 }5 c$ q5 y6 `<P><FONT color=#0000ff>return 0;
+ t- t8 s8 X, {& B} ( j4 t( D' p- U5 i8 A

$ V$ Q2 W4 T/ K" l2 e& s( `3 y/ F</FONT>
% @# Y; a" F, Y' W+ v</P>
: _" g  L5 f8 R<P><FONT color=#ff0000>函数名: strrchr </FONT>* x7 y7 k# A5 V
功 能: 在串中查找指定字符的最后一个出现
+ M% |- E  {# n) p用 法: char *strrchr(char *str, char c);
4 `% r, h5 S. }2 I程序例: </P>3 `4 P! H5 I1 @
<P><FONT color=#0000ff>#include <STRING.H>4 n) O) u- G5 `( y. @
#include <STDIO.H></FONT></P>" m2 o. O7 r7 ^# O8 C5 l# r
<P><FONT color=#0000ff>int main(void)
- K; Y8 H% t9 j9 z* O) v+ r1 l{
* @: c7 D. _' m( P/ g! `1 Fchar string[15];
+ q1 s! e- [/ hchar *ptr, c = 'r'; </FONT></P>
( R4 K5 R1 E; I) f4 v<P><FONT color=#0000ff>strcpy(string, "This is a string");
( c9 j" |1 c" K; p7 }* b/ Fptr = strrchr(string, c); ) A( d% g3 @: M' i; h! `
if (ptr) $ x, B0 a3 w; _" G  \# `7 K* G+ e
printf("The character %c is at position: %d\n", c, ptr-string);
5 c8 ^6 m% a9 Z7 h& ]' Q4 j/ Gelse
8 J9 ]' ?, \0 eprintf("The character was not found\n");
* r2 E% ?- D5 d3 e% [0 T# Greturn 0; 9 x9 J1 N7 V6 f# q8 g  s
} </FONT>0 F7 b, M- K! Z  i3 e
0 X5 a3 v5 ~! Z7 [+ b/ }
& ]7 Y* Q( h4 D( j; a
</P>
: f1 M0 v5 Y( p% o8 k' F<P><FONT color=#ff0000>函数名: strrev </FONT>2 m5 z* u4 X3 w9 |! k9 l
功 能: 串倒转 0 f" n! e7 E: v# f8 L5 C1 v( r# O
用 法: char *strrev(char *str); 4 w$ j$ U1 g5 a/ k
程序例: </P>/ o6 b. `6 M  T4 q5 @4 H
<P><FONT color=#0000ff>#include <STRING.H>
9 D5 a) ~. D$ U$ c- g3 Y+ V#include <STDIO.H></FONT></P>9 [  S: ?# w: U. [7 n
<P><FONT color=#0000ff>int main(void)
; Y) N  j) H( `7 k) }8 W8 C{
$ p0 w9 l) k2 s. i+ G6 t3 dchar *forward = "string"; </FONT></P>2 D% O, m) ?" B8 |4 b
<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward); 7 T4 `  k4 Y4 I5 k* i: Q# ^
strrev(forward); * b) u7 e4 z% A: S- h/ K$ S
printf("After strrev(): %s\n", forward); . l2 [# S& t4 L+ T( u' Q
return 0;
5 k9 _) D. p9 I} </FONT>
4 i8 }4 V2 A; ~* C/ S* @; {</P>
8 J8 T$ |. G+ M4 B1 N<P><FONT color=#ff0000>函数名: strset </FONT>  Z1 x) @3 v" c: u( x
功 能: 将一个串中的所有字符都设为指定字符
4 v# L- [$ |9 P* S用 法: char *strset(char *str, char c); 1 T6 I/ k- g9 w
程序例: </P>
: K, l, j( r' J3 c7 [<P><FONT color=#0000ff>#include <STDIO.H>, G6 o* Z- B% |: v, Y9 v
#include <STRING.H></FONT></P>
4 P* a( g5 N6 `; ~) r3 V5 N2 v<P><FONT color=#0000ff>int main(void) 9 b( {: M/ t8 B1 l! v. Y
{
4 d! f+ n  L  ^3 Nchar string[10] = "123456789";
' q1 T* u5 D# |0 pchar symbol = 'c'; </FONT></P>$ R8 q! r" [3 i
<P><FONT color=#0000ff>printf("Before strset(): %s\n", string); / K$ V# {- Y! |9 b
strset(string, symbol);
4 _5 t: C/ s0 pprintf("After strset(): %s\n", string); ! ]# ~  b4 U6 k5 C6 E
return 0; , r7 d$ K0 W* ^6 ?, `
} 7 Q9 a+ b  _  I' T3 i% S4 w* o

8 ]6 L, \; I. c9 e% n9 w! A2 y</FONT>
, Q6 O1 |6 A6 N/ }2 J' g</P>/ l% w8 z7 X1 o; Y, _0 j
<P><FONT color=#ff0000>函数名: strspn </FONT>  y+ r+ p4 l2 f5 ?4 E% j( y
功 能: 在串中查找指定字符集的子集的第一次出现
8 Z" [) r7 Z( a. z用 法: int strspn(char *str1, char *str2);
- p! d1 F# V8 l8 }程序例: </P>2 A% H$ Q0 X3 T9 P/ C
<P><FONT color=#0000ff>#include <STDIO.H>
  ~( j* T$ _$ d' I+ `6 d#include <STRING.H>5 l* Y3 V# o+ E! N) y8 ^
#include <ALLOC.H></FONT></P>* O3 ?# a0 T9 ?
<P><FONT color=#0000ff>int main(void) 3 @1 }, V9 x0 N, I& _! F# i
{
) Q& c. t) o& C5 b8 f8 M1 Echar *string1 = "1234567890";
: N8 f* O+ a! j# i$ ychar *string2 = "123DC8";
* f) Z1 E2 u- F( ~2 Y7 Zint length; </FONT></P>* D1 _* I: [7 ]) M! W
<P><FONT color=#0000ff>length = strspn(string1, string2); 5 x$ b- l5 p6 B4 z  w7 i
printf("Character where strings differ is at position %d\n", length);
/ e, U/ o  `# K8 s5 qreturn 0; 1 e* p8 C7 |2 q1 n, |# V9 H
} 6 f1 i' }% t5 U. v& s' S( M  d
</FONT>
/ ^( `8 R5 }4 E$ R$ s</P>  h! ~3 w- G8 M: E% P+ a: u6 P
<P><FONT color=#ff0000>函数名: strstr </FONT>3 Y. k' l/ H3 u
功 能: 在串中查找指定字符串的第一次出现
: s+ i3 J) k; u, a8 u7 J; q9 M用 法: char *strstr(char *str1, char *str2); 4 I" n! M# i/ Z( p# O: u- ^
程序例: </P>
) p, w9 k5 M2 M# J& r<P><FONT color=#0000ff>#include <STDIO.H>. m- [+ _2 d' F$ n) I- Z
#include <STRING.H></FONT></P>
: b5 p  d  o6 A6 X, J& S<P><FONT color=#0000ff>int main(void)
1 N  W3 d0 ?! P{
- F! B" |  D3 H7 achar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>4 ^9 m2 f9 \+ L' @* v  M- ]
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
; G3 f9 b1 D1 c, kprintf("The substring is: %s\n", ptr);
. k  y6 I0 I) K2 jreturn 0;
( g$ h+ b0 F. S3 H  |7 u1 t0 {} </FONT>
- v4 e: ]& T* }' b6 @3 r; ?( R+ F% p% r( U$ o1 U$ N
</P>
9 l/ R: f" W3 l0 z( t2 [# H' }- c) k<P><FONT color=#ff0000>函数名: strtod </FONT>
/ a# \- E5 c1 o$ t9 ~. Q6 E' Y+ ^: h功 能: 将字符串转换为double型值
3 Z2 q1 l) i4 W! h2 A用 法: double strtod(char *str, char **endptr); ; z/ b3 D4 x0 |+ Q4 y4 e* Y
程序例: </P>
* a$ {+ H$ K% n, h" W<P><FONT color=#0000ff>#include <STDIO.H>; {, `5 e3 m* l' ]' u' }; z
#include <STDLIB.H></FONT></P>% A; o! u* C9 D# P% q& S  o
<P><FONT color=#0000ff>int main(void) 0 E! U% h9 E; n0 V3 E
{ ' g/ G/ r3 @% C
char input[80], *endptr;
) K+ D! h' ?9 C. m" c4 p$ W- Jdouble value; </FONT></P>6 y7 F, [4 x) G7 D- Z' O' a
<P><FONT color=#0000ff>printf("Enter a floating point number:");
1 D3 t# H8 y3 xgets(input);
2 L! J* J+ s8 i8 G- }! U* H# |value = strtod(input, &amp;endptr); / t0 d3 V5 K+ y  F  q/ X7 p- i5 g
printf("The string is %s the number is %lf\n", input, value);   x5 M2 {6 L0 X  r
return 0; 1 d1 K, G$ E; z6 Q# {. c0 m
} / Y" D+ U9 H5 [# D6 y; @# i
</FONT>8 \' X" \( ]) R8 x
) O. }2 v( p" J, Q8 A
</P>
4 f$ u2 b* [- c<P><FONT color=#ff0000>函数名: strtok </FONT>1 U9 E- N$ c  V
功 能: 查找由在第二个串中指定的分界符分隔开的单词
' i4 |" w' T( y; f用 法: char *strtok(char *str1, char *str2);
, G9 I+ [! Z3 y; N6 r程序例: </P>
& i1 \8 T: l* S' U' Z<P><FONT color=#0000ff>#include <STRING.H>* i6 p! L. v' J
#include <STDIO.H></FONT></P>" z7 U: j8 c" \4 {" {. \
<P><FONT color=#0000ff>int main(void) * x- {' x' q/ d$ U7 ]! [6 i
{
: t9 @& z1 a2 u/ xchar input[16] = "abc,d";
- ?) N3 d; H3 U1 u1 K+ f5 Vchar *p; </FONT></P>% ~' b% x/ h* f+ Z
<P><FONT color=#0000ff>/* strtok places a NULL terminator
+ t1 l$ b& \4 h1 w: kin front of the token, if found */ + ~( D$ Z0 n( J- ?/ |. c/ _5 ?
p = strtok(input, ",");
, q& u+ H' B  b# c0 S4 I3 aif (p) printf("%s\n", p); </FONT></P>+ m# Z9 F, L9 ~& T! x
<P><FONT color=#0000ff>/* A second call to strtok using a NULL   K' ]- T. g7 @% L$ o% o
as the first parameter returns a pointer 8 H% U5 C8 }, N/ m" n: w0 U1 [
to the character following the token */ 0 E; Q6 U; J% `7 r' M, Q4 ?. k$ j
p = strtok(NULL, ",");
5 E* J! _" Z, E2 O$ Rif (p) printf("%s\n", p); ' I  E5 e  ?. k
return 0; 3 w0 _8 N$ H0 \$ q% M
}
! u4 ~2 z  |  E$ r
/ T1 P# K9 N) R$ P: |5 {# d
6 q5 u" y/ q; ]- r# D$ _</FONT></P>
/ o3 X6 p- q. g- Y! `$ e; T5 Z<P><FONT color=#ff0000>函数名: strtol </FONT>
3 V) Q9 r7 I5 I! i, ]+ C功 能: 将串转换为长整数
  s( v! N% s3 ]7 G. `用 法: long strtol(char *str, char **endptr, int base);
) [4 z5 {) U" d. j程序例: </P>
, F; {7 f6 Z8 S, M) l2 b5 u: `<P><FONT color=#0000ff>#include <STDLIB.H>
5 k9 C4 f& x% F1 V" q#include <STDIO.H></FONT></P>
( D+ ~, M5 _/ j7 b% z, z7 H<P><FONT color=#0000ff>int main(void)
* F, V+ I! }$ w$ N' G{
+ Y8 D7 q4 _! N& mchar *string = "87654321", *endptr;
1 w" Q; w  S* g7 z: L$ Xlong lnumber; </FONT></P>& ?( i. @) s7 @7 C) E- y
<P><FONT color=#0000ff>/* strtol converts string to long integer */
0 G; U' x1 `+ J. O0 ]lnumber = strtol(string, &amp;endptr, 10);
2 f! \2 L5 A0 }6 H" [+ w/ oprintf("string = %s long = %ld\n", string, lnumber); </FONT></P>
4 \) Q% q% O$ |) a# \  C; P" j<P><FONT color=#0000ff>return 0; - k8 }5 q. b3 ]+ s
} </FONT>
, i) K; C/ U5 ?4 a: Z( y; E</P>
0 E5 i6 \6 ~& ~! h) T<P><FONT color=#ff0000>函数名: strupr </FONT>* Y5 q- x! i( s7 z9 v( z" s* h+ _
功 能: 将串中的小写字母转换为大写字母
# q/ q7 q% z1 u, x1 C用 法: char *strupr(char *str);
, r7 k" {' T+ S9 G  {, m+ N: q程序例: </P>
3 I. f+ y! ~, v9 _<P><FONT color=#0000ff>#include <STDIO.H>
7 C$ x: s; m& k2 Y9 F#include <STRING.H></FONT></P>* y2 U/ H5 B* ^4 A( V
<P><FONT color=#0000ff>int main(void) ) ^" L( B. G! x1 X4 u/ g
{ 2 b0 s) s; F- U5 A7 g# ^
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
9 I9 U9 [  v+ X9 U<P><FONT color=#0000ff>/* converts string to upper case characters */ 1 w( x( j2 x$ m' C- u
ptr = strupr(string); 8 _: R- m1 Z0 N% W
printf("%s\n", ptr); : r3 j% ^! ]+ d3 M/ i! z. d
return 0;
% o  G4 c% Y+ Y+ s" y4 {}
: z0 }; a2 E* g- c6 ?9 a. B; k% O0 B  i! S+ {( L
</FONT>
$ B3 T) U; m# L</P>! x- C* ?' H. v/ q& b5 J* e
<P><FONT color=#ff0000>函数名: swab </FONT>
9 Z: O+ M7 h% Q6 v, R功 能: 交换字节
' h1 K/ b. @/ @* f用 法: void swab (char *from, char *to, int nbytes); 3 }" ^4 F- C* v% l1 M
程序例: </P>3 U* V  `& h% ]& V& y8 h8 l: T' H, Q
<P><FONT color=#0000ff>#include <STDLIB.H>: f+ H* m0 @6 b! O  O
#include <STDIO.H>
) p, s( u1 K# z7 G# s0 `#include <STRING.H></FONT></P>, l3 T4 w2 K. [- A7 _' b% r
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; 1 k9 b% ]2 o& \! f% h
char target[15]; </FONT></P>  ?8 F" e! p! m, ~
<P><FONT color=#0000ff>int main(void) - c" L, j1 x2 Y4 \
{ 2 ^; }% f( [1 W# B6 D
swab(source, target, strlen(source));
( ]% t( l2 x$ k- G# e  Wprintf("This is target: %s\n", target); & @- A/ F% ]0 |/ ]6 j
return 0;
6 G- x. k3 J" Y' v! L$ G7 H; O} & X: `, g- r! w/ [+ h" @  L
</FONT>
0 A  X+ I. K2 K! m5 q; a9 i; }9 n
+ j5 o* p1 p' Y+ c1 J( F. P</P>
7 w7 F0 u& H' }8 k9 N; d1 H' {<P><FONT color=#ff0000>函数名: system </FONT>  r3 Z; {- k# b% h$ b
功 能: 发出一个DOS命令
  Q! {2 k' J7 W* a0 e1 O用 法: int system(char *command);
2 l) @( D# b! S" e+ ^+ I5 h, X程序例: </P>/ R: e# [( q( J" I% r% @
<P><FONT color=#0000ff>#include <STDLIB.H>
* }- s+ x4 j1 |#include <STDIO.H></FONT></P>5 f$ E  ]9 C  s% `
<P><FONT color=#0000ff>int main(void)
2 _- d" ^2 L# w- u/ m$ n! y{
5 V" E* y" p3 |9 R$ ]% \printf("About to spawn command.com and run a DOS command\n");
% o' @  q6 C/ N$ }8 M: Q" I8 nsystem("dir");
6 H- u2 B+ K, u! C- n' Preturn 0; 6 D7 D9 ?1 k$ i& V
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

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

回顶部