QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>2 b/ t, R' A7 F$ O4 U
功 能: 改变数据段空间位置
" f! D2 @  \# n7 m  J* U用 法: char *sbrk(int incr);
9 `" X$ w* M0 ]7 e2 J+ r程序例: </P>* u, A5 K4 w# a; [) j
<><FONT color=#0000ff>#include <STDIO.H>
' a/ R/ A3 I  R6 K#include <ALLOC.H></FONT></P>$ _- M' \9 u! J! |
<><FONT color=#0000ff>int main(void) & {' q" b) ]4 F9 ?0 D7 j6 t2 i
{ 7 P9 L# |# h, c& e$ A% u
printf("Changing allocation with sbrk()\n"); 9 O0 j3 J  R1 e, Z( X4 J
printf("Before sbrk() call: %lu bytes free\n",
. J9 h7 X7 @7 |* p/ }1 f(unsigned long) coreleft()); " y" N5 y6 ?! r( N6 U. B
sbrk(1000); 2 l0 d; J6 c9 L% S/ b3 B7 Y
printf(" After sbrk() call: %lu bytes free\n", : V# Q; L' g8 R
(unsigned long) coreleft()); 7 f9 w  s+ G9 q! h
return 0;
* Z+ r9 S- H1 v2 E& Y}
5 t2 p: ~/ G, A0 o1 O* f# K* a" {$ Y, \# b/ i* o% J
</FONT></P>
& i' c9 g) a" N% ^( x: ^8 U<><FONT color=#ff0000>函数名: scanf </FONT>
7 r1 U/ w0 C  o+ O8 K功 能: 执行格式化输入
% T' W8 Q- X( O用 法: int scanf(char *format[,argument,...]);
: V6 }+ J. E6 w+ m% u- \程序例: </P>9 t' J4 A; t4 s% X  t; A9 [
<><FONT color=#0000ff>#include <STDIO.H>
2 |& z* j7 ^4 U5 i; v#include <CONIO.H></FONT></P>
! ]% X: ^) A: d' d  E<><FONT color=#0000ff>int main(void)
( G0 P: s. Y. g8 s. t& O{
1 S+ L( S  ^0 v5 Pchar label[20];
9 x& ~, R. @0 x8 g! h% {: nchar name[20]; ( i$ J) n" `9 P' n* R
int entries = 0;
. z0 W! ^/ c' S0 R" p. H* mint loop, age;
& O: n+ u' D3 Wdouble salary; </FONT></P>4 h0 b7 z- x" c' J' t4 ?
<><FONT color=#0000ff>struct Entry_struct ! D& r. ]8 m$ y6 _+ \0 L
{ 2 c2 k, U" p1 y$ z, T
char name[20];
# ~; i+ c5 }. M7 B  Lint age; - D% T; ~3 F) H) s) V6 O; f* T- X
float salary;
0 v* U) r& ?7 z& ^% h} entry[20]; </FONT></P>
4 u! W5 Z6 o1 t8 [0 j. H<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ % N" Q# `: d6 ?) T
printf("\n\nPlease enter a label for the chart: "); 2 p6 v1 a0 l2 N
scanf("%20s", label);
$ k$ W- b: |+ D* vfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
  n; j2 S+ H) U- a, T( W0 s8 ?! K<><FONT color=#0000ff>/* Input number of entries as an integer */
; b4 B' P4 l: P9 _# Z5 Fprintf("How many entries will there be? (less than 20) "); 2 C1 ~6 o, a5 g0 z8 m( p& p
scanf("%d", &amp;entries);
+ l' F! T5 b) g/ Cfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
( i% ]9 j% q, \  K& v3 ]( C3 A8 u% W<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ 0 G* p, Z& g( c  I
for (loop=0;loop<ENTRIES;++LOOP) 2 ?( N0 \: I9 O) n3 V
{
0 ^1 |+ i1 r, Sprintf("Entry %d\n", loop);
% F8 J9 ~! C) e6 h4 i1 [printf(" Name : "); . C) r* L3 N% S- K
scanf("%[A-Za-z]", entry[loop].name); : O6 `  l" L5 d8 Z
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
' m$ `& S( a* K9 O, X. ]<><FONT color=#0000ff>/* input an age as an integer */
* F# P5 V8 e5 Z# M, g/ Iprintf(" Age : "); 5 q+ @, f4 J  P* s
scanf("%d", &amp;entry[loop].age);
  R, W0 o1 u& V5 Z, S. qfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
  N1 Z2 M3 U6 E4 d<><FONT color=#0000ff>/* input a salary as a float */ & g) |; ~- v/ M' |+ e% S7 h
printf(" Salary : "); 9 L  \% P0 L2 Q+ ~& Y, }7 E0 M
scanf("%f", &amp;entry[loop].salary);
( }" F  _7 V- {2 G* O. Ifflush(stdin); /* flush the input stream in case of bad input */ 8 }7 J  ~! o3 e& u5 t* d
} </FONT></P>
0 \: a: t3 q# m. d<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
, q3 H6 }3 R) n$ }2 K- S$ x! @printf("\nPlease enter your name, age and salary\n"); * a* x: s% L$ |9 d4 s( q- W, ^, ^2 D
scanf("%20s %d %lf", name, &amp;age, &amp;salary); + j9 n7 x4 C+ _' R: [  O2 N
</FONT></P>$ n- ?: U3 i( x) c! l* k1 l5 P0 h
<><FONT color=#0000ff>/* Print out the data that was input */ ! t4 H: x( D& D8 r; H- U9 q
printf("\n\nTable %s\n",label); 5 ]+ a- X' m5 y5 @! k( `% S
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); 1 c, G7 J  Z! O7 c6 B! J6 G8 c1 M- _
printf("-----------------------------------------------------\n"); 1 R( E# b9 A8 F: A0 G% k/ C
for (loop=0;loop<ENTRIES;++LOOP)
+ l, d$ H" C9 b  P2 B printf("%4d | %-20s | %5d | %15.2lf\n",
* b$ B' d3 f0 jloop + 1, ' M2 [% k' S' `
entry[loop].name, + K$ H( ?( j% w
entry[loop].age,
- d% i* J9 y8 w( Hentry[loop].salary);
0 h) V( E7 N1 p. ?printf("-----------------------------------------------------\n"); 3 c$ {, U  o5 L1 d6 w' R! L7 P: {
return 0; . ^, m. @+ I/ h; W8 q* O
}
2 J* \, r4 b5 Q5 ?& N- C8 v6 i+ c</FONT>
  y7 D( Y+ q( T1 ]5 j/ I</P>, H) m/ ^6 @3 P
<><FONT color=#ff0000>函数名: searchpath </FONT>
7 a# m4 B2 ~% }. ~功 能: 搜索DOS路径 & L$ z& Y! a% E' W( {
用 法: char *searchpath(char *filename);
- N' X( Y3 n2 W1 z8 j程序例: </P>( J0 R0 X' v8 i7 k  d7 h
<><FONT color=#0000ff>#include <STDIO.H># P' m6 d! V. v& Q" Z
#include <DIR.H></FONT></P>: U; m- r- K  O; n3 G: H
<><FONT color=#0000ff>int main(void) ! [. W7 a1 C1 S' I6 Z! a9 e
{
' A# h& ~! T. A0 wchar *p; </FONT></P>1 ]8 I. B& v$ b$ P0 y4 d
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer 5 C; p# o$ u" m7 L8 y8 G
to the path */ ; v8 m  P  G' g/ O0 r. s
p = searchpath("TLINK.EXE"); 2 g. M: o0 l2 J4 n' i
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>
6 b* F9 V% U9 f' G<><FONT color=#0000ff>/* Looks for non-existent file */ / p" Q9 u- v& b$ k' p
p = searchpath("NOTEXIST.FIL");
' ]- f$ s. S+ p) f0 Qprintf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>
% R  f7 C6 S! |  M<><FONT color=#0000ff>return 0; 3 u: {/ g3 {" |, ~
}
. w0 G" n' a9 t5 C1 E
7 n' o5 i4 h: Q6 D" _</FONT></P>: O" d9 ~  X6 D6 C  N( S& J
<><FONT color=#ff0000>函数名: sector </FONT>3 o+ b+ e* `$ E+ @3 N: l
功 能: 画并填充椭圆扇区 4 `1 ~7 F3 p3 i0 C- r
用 法: void far sector(int x, int y, int stangle, int endangle); 3 ~( U; S% ^/ v$ |$ S' |
程序例: </P>& B; z& F- s$ A5 J3 ^5 E: Y
<><FONT color=#0000ff>#include <GRAPHICS.H>
) ^/ }9 j0 _3 t. |#include <STDLIB.H>
; |% k" {4 n% U* N#include <STDIO.H>& F* L& ]* t" M4 r1 J
#include <CONIO.H></FONT></P>: A. b: c1 r  x% r: W
<><FONT color=#0000ff>int main(void)
' C; z; d+ T( K, z{
' b: S4 V, y! M, t3 @3 J" T4 A/* request auto detection */
  ]" @; p4 T: K+ k: B- u. |' Y6 aint gdriver = DETECT, gmode, errorcode; 7 ?) d! [, ~% P) p
int midx, midy, i;
% W3 `% B" g6 K7 ~/ J9 Oint stangle = 45, endangle = 135;
  \- D% z/ I$ Qint xrad = 100, yrad = 50; </FONT></P>- @' @% X! O0 p" r; E/ E; L
<><FONT color=#0000ff>/* initialize graphics and local variables */
8 J$ V* ~# g! O" }initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ J/ J/ o& I. e( D1 {2 M& q<><FONT color=#0000ff>/* read result of initialization */
9 J" Q4 E& B  K& C% i2 t5 cerrorcode = graphresult();
, n8 c) m7 o7 P! Kif (errorcode != grOk) /* an error occurred */ . @% g8 T2 c( W
{ 3 r; z: k* ?2 y8 }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
! u% ?: }+ i  E; vprintf("ress any key to halt:");
5 f7 a- W# }3 F! k! @: fgetch();
9 i8 ?6 i1 z( ]) n% @( pexit(1); /* terminate with an error code */ ' u  t2 V7 o$ @& b
} </FONT></P>, E/ s8 H- y* }
<><FONT color=#0000ff>midx = getmaxx() / 2;
) S+ Z- Y1 z8 f7 @midy = getmaxy() / 2; </FONT></P>
8 ?% m: q7 I& D5 k<><FONT color=#0000ff>/* loop through the fill patterns */   _/ D" ?# Q/ L, m
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 1 k: H8 _1 K$ _9 ?% {
/* set the fill style */ 4 P6 f/ u1 v- t# D( O. H
setfillstyle(i, getmaxcolor()); </FONT></P>
& ^( w0 T7 H1 B, N<><FONT color=#0000ff>/* draw the sector slice */
" m& Y$ ~- v* Q4 i. usector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>
* q. Z8 r( l+ c1 [  }<><FONT color=#0000ff>getch();
% j( [) [( N1 l7 U7 @} </FONT></P>1 g0 x6 N4 x- e& {9 ^! X
<P><FONT color=#0000ff>/* clean up */
1 v) d' ~; G' N! Xclosegraph(); 6 ?6 W9 B0 O/ y3 ?5 b3 M5 G
return 0;
( L- _8 Z4 V9 P) @} - C' O" k2 {+ G7 g3 N& R
</FONT></P>& q& x* ^6 @4 J" T  \% I, R
<P><FONT color=#ff0000>函数名: segread </FONT>
6 V2 ]+ K1 m$ d功 能: 读段寄存器值
8 C( d. X. s' v6 }用 法: void segread(struct SREGS *segtbl);
) p- k" P6 j, i程序例: </P>
! Z& |7 ]2 b9 |: z/ c, j# n8 z- P. N9 m<P><FONT color=#0000ff>#include <STDIO.H>
7 z' l8 {! P. l$ A#include <DOS.H></FONT></P>2 b% n" g8 \- ~' L( f
<P><FONT color=#0000ff>int main(void) ! T( d: _: B! j6 M1 M. J- D6 j' D
{
! j. T- z& k$ r# f/ [* ?struct SREGS segs; </FONT></P>
/ z5 Z$ ?; U; D  J/ h<P><FONT color=#0000ff>segread(&amp;segs);
( G* K+ M7 X! g# D4 C( Z& sprintf("Current segment register settings\n\n");
6 Y& D* t; e3 Y; {5 Iprintf("CS: %X DS: %X\n", segs.cs, segs.ds);
' J& ~2 @. `- T; J( @- |) Oprintf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
. i1 p0 e* g7 k- d<P><FONT color=#0000ff>return 0;
+ M% l; [) H: q6 n* j8 a} </FONT>+ {7 h2 K3 E$ Q+ b8 @, S& f2 Q. [6 D
0 e6 V( m; n* {. B3 V4 c
</P># k0 a, [- R1 f* f; r
<P><FONT color=#ff0000>函数名: setactivepage </FONT>( \( f$ E- c# x8 H% K. d
功 能: 设置图形输出活动页 . `) B8 V  D2 l  }4 Y
用 法: void far setactivepage(int pagenum); : T) i  i3 \' i" R7 h
程序例: </P>' x1 y, |: T( }: U# E4 H& x
<P><FONT color=#0000ff>#include <GRAPHICS.H>- C' r6 D! U$ V* s" N; Q
#include <STDLIB.H>
% G! y5 n& \2 \% z* {, m#include <STDIO.H>0 l  {4 o& o, P  Q. b7 ?
#include <CONIO.H></FONT></P>
, z/ B- y* F' t) D, ]<P><FONT color=#0000ff>int main(void)
; y; Q$ q/ q4 r  U9 G$ ?8 P{
% `. H; i3 [* B/ L/* select a driver and mode that supports */ $ R0 b" C8 Z" J7 M
/* multiple pages. */ 9 W+ d: q8 R3 R. P6 ?; p- G
int gdriver = EGA, gmode = EGAHI, errorcode;
( c" u/ Y# R2 g7 f/ y( }3 d. N' xint x, y, ht; </FONT></P>
1 _* w( w) \  N+ T$ n: h- K* U+ @<P><FONT color=#0000ff>/* initialize graphics and local variables */ + }/ h  q  m; R$ I3 J# ?$ q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 e* ]7 }: w; I* U9 H: V<P><FONT color=#0000ff>/* read result of initialization */
5 z3 |( i# _/ G9 s) `, L" \errorcode = graphresult();
% \( `- l  ~7 `+ @4 T+ V4 z* Q- }4 Gif (errorcode != grOk) /* an error occurred */ * v/ v0 G7 B  ~" C) r
{
  V- D& \7 P9 r! H! B6 wprintf("Graphics error: %s\n", grapherrormsg(errorcode));
/ }" ^  ]  d/ l- Zprintf("Press any key to halt:"); + R1 L  x, I+ f' `- `5 u3 N9 @
getch(); * \; o" u4 c' u! b# z( J# ~
exit(1); /* terminate with an error code */ & e' `, w* F' b$ g6 m3 Z
} </FONT></P>& S0 W# `: A# ~$ \
<P><FONT color=#0000ff>x = getmaxx() / 2; 7 |/ ]" c& I. g$ X( z/ K, `4 }7 J
y = getmaxy() / 2;
" J! F. _# O9 e) E9 Dht = textheight("W"); </FONT></P>) q# M4 D$ E' `. I4 [' s  D- C
<P><FONT color=#0000ff>/* select the off screen page for drawing */ 1 W8 L# `. T% j7 k* }, g
setactivepage(1); </FONT></P>
9 c' u8 h" R; l- O  a  d<P><FONT color=#0000ff>/* draw a line on page #1 */
+ y5 B: g/ _& H/ h4 Iline(0, 0, getmaxx(), getmaxy()); </FONT></P>4 b+ N% Q, i7 n& j" y8 y
<P><FONT color=#0000ff>/* output a message on page #1 */
& E9 u( Z/ q2 H: n9 Zsettextjustify(CENTER_TEXT, CENTER_TEXT); 3 y1 x- y& P8 A" V  @( s5 J
outtextxy(x, y, "This is page #1:"); ) D( o' O- f/ z* ?0 O, S
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>
6 Z6 a2 T+ k7 ^4 E" q. E<P><FONT color=#0000ff>/* select drawing to page #0 */ 6 P7 o5 z7 V, K& [0 u
setactivepage(0); </FONT></P>
+ h; _5 k9 [! y* e! N( k. U( \<P><FONT color=#0000ff>/* output a message on page #0 */ * \" @/ n) w, r7 u3 A$ U2 [/ [
outtextxy(x, y, "This is page #0.");
- _+ u5 q. L/ g7 g9 Qouttextxy(x, y+ht, "Press any key to view page #1:"); 6 d# t+ C7 p# O) W8 Z# Y
getch(); </FONT></P>$ D1 i* T6 w/ I* j2 g3 b
<P><FONT color=#0000ff>/* select page #1 as the visible page */
/ n5 n! L- W# L+ f! hsetvisualpage(1); </FONT></P>) f* c: _* a2 {
<P><FONT color=#0000ff>/* clean up */ % @3 o4 G, o9 G5 i/ P6 J3 t3 f
getch();
0 ]% R  X0 R9 {( t1 i( @1 Qclosegraph(); 5 }3 p# r- ]8 l
return 0;
8 F( g: T4 n$ \+ o1 Z/ q} / ~9 R7 K2 ]2 t+ o- z0 T5 @% X
</FONT>
$ D! Y( i' g9 w! }$ {</P>
" D  t3 z8 t5 n2 b1 `- f& Y<P><FONT color=#ff0000>函数名: setallpallette </FONT>
2 L3 [  y1 M- e+ W0 W, O- [功 能: 按指定方式改变所有的调色板颜色
( E+ p( G; k4 w- t用 法: void far setallpallette(struct palette, far *pallette); - k* {1 r& J/ z) K% h9 j
程序例: </P>9 a& s. @0 |/ S6 W& x, L1 E
<P><FONT color=#0000ff>#include <GRAPHICS.H>( B& P' ~* @0 U2 z! e$ o! W
#include <STDLIB.H>% v- v! k) M  i( e/ Y- A
#include <STDIO.H>
# O: ~% Z  z6 |1 b! D#include <CONIO.H></FONT></P>% G' a+ V$ }# [" s$ F
<P><FONT color=#0000ff>int main(void) 0 {' y# r* g& X! l; N3 W( [
{   O& P+ U; U) i" h
/* request auto detection */
1 G  e0 Q7 B2 I9 p+ ]2 nint gdriver = DETECT, gmode, errorcode;
2 \+ C' l0 z' b1 a  K/ ^struct palettetype pal; $ `9 f+ V1 R$ T$ }9 }7 h2 F: F
int color, maxcolor, ht;
9 h1 x: L9 u5 S) ?6 ^int y = 10;
% {) T$ c2 `, P3 |4 @. w4 ichar msg[80]; </FONT></P>
: y0 q1 g$ b' x% N9 L4 c" w<P><FONT color=#0000ff>/* initialize graphics and local variables */
% ?5 o% L9 D) R% {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" @# ]% r9 t; d
<P><FONT color=#0000ff>/* read result of initialization */ ) I; l/ N5 U; @: y0 ~+ C# k1 [
errorcode = graphresult();
+ l1 h: H, m# Hif (errorcode != grOk) /* an error occurred */
- I8 S8 s$ |& ^7 D" E* o5 S6 K{ $ {6 j; U. _" V) X" {: S0 W
printf("Graphics error: %s\n", grapherrormsg(errorcode)); + T7 G1 b% B* X/ R! k; \% C
printf("Press any key to halt:");
5 q: w* H" {# Z8 f8 O' y( J4 Qgetch(); . t5 }* c: R' r- E
exit(1); /* terminate with an error code */ % F4 k9 Z0 p, K! F: {3 v
} </FONT></P>) \9 g# [! \) N* P4 O
<P><FONT color=#0000ff>maxcolor = getmaxcolor(); 9 I8 {" L7 V) @) F: @: i
ht = 2 * textheight("W"); </FONT></P>  ~4 |5 l  A2 I9 S' c2 D( X
<P><FONT color=#0000ff>/* grab a copy of the palette */ : E" W7 f2 _& ~! |
getpalette(&amp;pal); </FONT></P>; U4 Z, Y. P" E* |
<P><FONT color=#0000ff>/* display the default palette colors */
9 X/ `1 l/ w. F: a$ G8 H' ]9 M  tfor (color=1; color&lt;=maxcolor; color++)
- T6 D+ R  J& c. b+ R  o7 h" P{
) {" o( S& ^2 S' Y. t2 J! N) b1 Ysetcolor(color); ( p& V: X2 P" x6 d! N
sprintf(msg, "Color: %d", color); $ E& @( Y9 \/ F/ A4 ^$ r5 [
outtextxy(1, y, msg);
9 h; M. F# `  Xy += ht; % |: A" m, S" Q8 F
} </FONT></P>
: N5 J0 W2 e. ~( a<P><FONT color=#0000ff>/* wait for a key */ ! {0 s9 f( x# h/ o: e; t
getch(); </FONT></P>: Y- c  e; g+ p2 Z  k
<P><FONT color=#0000ff>/* black out the colors one by one */
- @# d) d& A* L3 f& U4 t- m# dfor (color=1; color&lt;=maxcolor; color++)
1 M( {2 |- P& M{ ' [: O: Y( h: J8 \+ J1 L
setpalette(color, BLACK); 6 e1 t1 \% I% g
getch();
4 j3 J  u& O4 m; K4 ]7 T" |! }3 A} </FONT></P>: x( q! g% [" `
<P><FONT color=#0000ff>/* restore the palette colors */
' t* i, E8 F2 ]0 `1 K$ Bsetallpalette(&amp;pal); </FONT></P>6 q4 y+ X) _% ?+ K9 `$ ]8 {
<P><FONT color=#0000ff>/* clean up */
, G& R1 i& `5 B0 X( \. W9 Ugetch(); # P+ k. _5 b: h$ e1 C2 }2 Q
closegraph(); : p! V4 x3 p! z  L. [
return 0;
# Q' o: `" [+ u  G1 f* S* N} 1 n- ?+ J: v  l9 L' K" \
% i6 ^& g5 C; o) X  I
</FONT></P>
4 J* g9 }  T! ~0 Y/ S- @5 a<P><FONT color=#ff0000>函数名: setaspectratio </FONT>1 E: y* ^" {( {5 V  ~" M% d* l
功 能: 设置图形纵横比
, x, Y, u% _+ |. u8 k/ J用 法: void far setaspectratio(int xasp, int yasp); % T" Q8 S8 l4 w0 Y% P* n; H
程序例: </P>
- G3 |! J7 Q  ~7 d7 H" s6 ^- j<P><FONT color=#0000ff>#include <GRAPHICS.H>
, X. k/ {# w' O1 D# j- J#include <STDLIB.H>
/ N3 g" R) e& Y4 }4 ]#include <STDIO.H>7 v, A7 B7 m, v0 D
#include <CONIO.H></FONT></P>" Y- N/ V- Z8 E, ^) K
<P><FONT color=#0000ff>int main(void) 5 _2 X5 Z- H( t* G
{ 1 X6 a1 s5 ^+ s- F4 K4 V
/* request auto detection */
) Z/ b, D9 Q: s( L5 [" J; T( w; o% Qint gdriver = DETECT, gmode, errorcode;
* W8 ^/ I5 t" M5 O  ?( i% x' Uint xasp, yasp, midx, midy; </FONT></P>
$ r4 M, u' `8 C. _<P><FONT color=#0000ff>/* initialize graphics and local variables */
" A' F5 @% t$ w  `4 binitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 d+ `# ]! Z5 S- j6 r( V2 [& d<P><FONT color=#0000ff>/* read result of initialization */ " }5 w9 ^' _  Y/ I/ b2 Z/ Q$ B
errorcode = graphresult(); + D% i2 J- @, S' ]
if (errorcode != grOk) /* an error occurred */ 5 O7 E2 |0 ^5 B" S# n' {. A. R5 d
{
& l: R% p! I- x! Y$ n1 k8 N" ]printf("Graphics error: %s\n", grapherrormsg(errorcode));
  b$ c4 `& s2 a$ V( @printf("Press any key to halt:"); ! K  C9 o0 i6 I  w  f
getch(); * i+ G8 a: a% ~
exit(1); /* terminate with an error code */ 0 j  |' V$ s! I9 S3 p, U
} </FONT></P>
, d  F& j% q9 x; \<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 D! S) W  F9 r0 }$ M# R3 V
midy = getmaxy() / 2;
, {8 G' Z9 l$ K/ b4 ~  ysetcolor(getmaxcolor()); </FONT></P>; Z9 ^7 P8 d% u7 z5 f# j8 c
<P><FONT color=#0000ff>/* get current aspect ratio settings */ * \5 x" V/ K# J' d
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
: S- Y1 w% k1 W* w7 r( x6 a<P><FONT color=#0000ff>/* draw normal circle */ . d( G% A9 f  h0 z$ t
circle(midx, midy, 100); 4 T7 ~5 |5 m' I: s
getch(); </FONT></P>
# [. G1 K. o$ Q<P><FONT color=#0000ff>/* claer the screen */ 8 z6 D' }& B8 u! w) R3 I
cleardevice(); </FONT></P>, ~: N5 v% q0 m6 Z
<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ 1 [. }' Q; Z- u" F* r0 L
setaspectratio(xasp/2, yasp);
' x7 v1 D9 |; P  E- S$ c& Ocircle(midx, midy, 100); $ f# w. A. O+ [% w
getch(); </FONT></P>* t5 b/ ]5 r4 f+ H: Q8 y) R2 a
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */
  k) n9 A* T5 Hcleardevice(); + s4 A; s$ E; J% J& r* ^
setaspectratio(xasp, yasp/2);
5 ]1 T2 |( E! G7 |circle(midx, midy, 100); </FONT></P>
! c  U- u3 l5 l1 T6 _<P><FONT color=#0000ff>/* clean up */   j" K/ ]# c( ]" G2 l" b, W
getch();
% ~2 ~& Y& e$ L6 P4 @6 O$ `1 P- Kclosegraph(); . W1 I- ~7 `4 X6 {3 ^; ^! n
return 0; ! S" [2 ?& h4 l4 C# R3 w
}
. n6 H, I/ h8 f) c3 n3 }; `+ D% c</FONT>( G1 Y) D" @: y0 @7 r. F" [
</P>
% t+ e0 m1 R% D6 Q* A$ S; u8 N5 e/ ?! K<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
/ \7 U$ S0 a) |6 y8 _. x功 能: 用调色板设置当前背景颜色 % n& C# e% I& f+ P& H/ t; u
用 法: void far setbkcolor(int color);
2 F' I) |  G. T/ R( i! n5 s程序例: </P>7 A7 Q, w( Z1 x, z1 @
<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 G8 J; g- M" x; O#include <STDLIB.H>
5 Y% j5 \2 o7 C* r#include <STDIO.H>
* L; [1 O3 Q0 e#include <CONIO.H></FONT></P>- g8 @1 E% [9 R8 K8 K+ U
<P><FONT color=#0000ff>int main(void)
7 t2 Q3 E/ o" w& K0 d$ B{ ( i3 B7 Y! i7 x8 b( l' N) D& d; E
/* select a driver and mode that supports */ ! E/ \* d0 I1 v3 T& R
/* multiple background colors. */
0 q) v4 a& w. k0 w6 i* e  p* [" ]int gdriver = EGA, gmode = EGAHI, errorcode; 6 D7 T( O- U9 b: P# ~; O% `/ h2 [
int bkcol, maxcolor, x, y; / Z6 I& F1 g, b
char msg[80]; </FONT></P>* o) T; o- x4 S3 |+ B
<P><FONT color=#0000ff>/* initialize graphics and local variables */ , g) u1 _- W8 H* q2 F$ J: ^
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ i0 D2 D$ i2 F9 z6 O- z<P><FONT color=#0000ff>/* read result of initialization */ 9 c) R$ i' h2 t
errorcode = graphresult();
5 B6 {$ O' ~( P! _8 Uif (errorcode != grOk) /* an error occurred */ 2 l( O3 e8 a  {; t, U: ]. ]
{ 0 R1 n  T7 Z; U
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( R: q& ^% A5 v3 T4 C  m. D
printf("Press any key to halt:");
1 o( d, z2 L7 S- Ugetch();
8 J8 R0 E; L% S$ Qexit(1); /* terminate with an error code */
/ y: o: `6 E5 w} </FONT></P>' D" s+ F# ]  p  s
<P><FONT color=#0000ff>/* maximum color index supported */ / |( q3 s0 S+ W4 y8 K7 I4 Y
maxcolor = getmaxcolor(); </FONT></P>, T4 F/ W* g0 j. ?9 I
<P><FONT color=#0000ff>/* for centering text messages */ ) P2 }* u% P- Q& u) n& T& \0 u; ^
settextjustify(CENTER_TEXT, CENTER_TEXT);
* V+ U9 I+ V$ ex = getmaxx() / 2; 7 a  i5 [+ G) o. ?
y = getmaxy() / 2; </FONT></P>
' z, X- Y  j8 p0 N* r8 J0 G<P><FONT color=#0000ff>/* loop through the available colors */ 1 P7 ^5 S( D6 B/ N6 u
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
# _0 `; W. l: n) Y{
" g; E: N7 j/ i" a* [/* clear the screen */
( n( l  O2 j  q4 @  h; Pcleardevice(); </FONT></P>
) p, |9 f& O* i<P><FONT color=#0000ff>/* select a new background color */
9 [3 i5 I7 j! P; p" Fsetbkcolor(bkcol); </FONT></P>9 @3 x3 J, z! c! z& u5 |
<P><FONT color=#0000ff>/* output a messsage */ 1 q* @# \/ S9 W3 q
if (bkcol == WHITE)
0 D2 Z0 Q( \* }9 {' O8 {setcolor(EGA_BLUE);
# m6 c# W' B$ F+ \$ _/ tsprintf(msg, "Background color: %d", bkcol);
0 w- c  Q1 j9 _) |outtextxy(x, y, msg); # K: a3 `, E+ J* Q% J# a
getch(); ) _8 F4 m6 `' {  e, y1 @% W
} </FONT></P>( r- Z( ]0 g, e- R
<P><FONT color=#0000ff>/* clean up */
' W2 @$ ~  \( t& S" S. Vclosegraph();
8 p2 x) Y' p4 I$ Q9 M) wreturn 0; 1 F8 ^  |' z3 W+ @
} </FONT>
. Z- v. {5 g5 Z4 N( m) ^- P' L" g- S$ x, k
</P>1 H; k8 A$ A3 T' L, ~1 D5 q
<P><FONT color=#ff0000>函数名: setblock </FONT>, a7 [2 a: O; V: I  m: W
功 能: 修改先前已分配的DOS存储段大小 + `0 c. }7 D; w. b/ y
用 法: int setblock(int seg, int newsize);
  E; F* j3 x& x+ q程序例: </P>2 E! K2 l# X9 r/ y' ]) u
<P><FONT color=#0000ff>#include <DOS.H>$ X4 c- |( d5 X5 R0 D. s# H8 F, E* v
#include <ALLOC.H>
, A# l* E6 i  ?' d2 [#include <STDIO.H>
* F4 j- O- M- a, W9 w% J9 n% Z2 t#include <STDLIB.H></FONT></P>" `+ f( m. r0 Y
<P><FONT color=#0000ff>int main(void)
+ n& R* T7 D- I' s% w) y{
8 k  q" M1 ?. |- w8 A) Ounsigned int size, segp; 5 r" S" e6 K4 e
int stat; </FONT></P>" x4 A" c" F. z" u: k  A" u, f  ?* L
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
: Q, A7 u& b, k9 B1 J' wstat = allocmem(size, &amp;segp);
9 N8 S% {! n( mif (stat == -1) - Y4 s/ A7 O  R( K# y  \2 x. C( ~
printf("Allocated memory at segment: %X\n", segp);
/ o, N/ _- R- t1 A  k, `) c# P8 Y, h8 xelse ) o! P% T' |4 c
{
8 \0 B) r+ g; b- i$ Iprintf("Failed: maximum number of paragraphs available is %d\n", " g" `- \$ [9 B* b
stat); ; B' O( T" ^& a/ T) x  u
exit(1);
$ H% A$ K3 a, ~1 ^} </FONT></P>
; p6 P# z# o4 t/ R, V2 D<P><FONT color=#0000ff>stat = setblock(segp, size * 2); ) g/ m! A  m) v- V' D
if (stat == -1)
$ j2 e2 H) [, z7 n( s0 r4 i# xprintf("Expanded memory block at segment: %X\n", segp);
' B' K' P; Q- b3 |4 welse
9 m, s/ C' `6 H6 G. j# h6 a4 qprintf("Failed: maximum number of paragraphs available is %d\n",
+ v! u$ m, i6 I2 Fstat); </FONT></P>
7 S. s1 ]. i9 Y7 X3 M2 M- r3 w* `<P><FONT color=#0000ff>freemem(segp); </FONT></P>
) b- o* f; @# u9 k! n* N) d<P><FONT color=#0000ff>return 0; " Y, C  @! s3 z' X4 ~
}
8 V3 F; s! Y! n, @</FONT>
8 [+ E2 c* D8 e+ \& H; B' ^: N</P>5 }- P+ y) p/ b4 }3 n
<P><FONT color=#ff0000>函数名: setbuf </FONT>$ r& I% u/ O, l5 w5 h) V* }" v
功 能: 把缓冲区与流相联
5 A+ o; O% O6 Y3 _用 法: void setbuf(FILE *steam, char *buf); 1 v7 G2 @" O  G5 P7 j( x2 _- E* F
程序例: </P>
) T* Q3 `. E2 {+ c) H$ V1 ~, N5 Z<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
4 F) Y! p6 u4 e- _<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ 2 ^$ E: N4 P! s6 W. I6 P
char outbuf[BUFSIZ]; </FONT></P>9 S7 b2 c+ [* C
<P><FONT color=#0000ff>int main(void)
: r; p& K4 S  ]6 w* r% u{ ) ~2 k! K8 A0 A/ M1 N
/* attach a buffer to the standard output stream */ * w, v6 ]& J4 g- U1 w
setbuf(stdout, outbuf); </FONT></P>+ c' b8 ~/ F9 G& Q$ ?
<P><FONT color=#0000ff>/* put some characters into the buffer */
; I8 W  {0 k+ U6 i* u' Cputs("This is a test of buffered output.\n\n");
0 \: M6 b# ?- H1 J; hputs("This output will go into outbuf\n");
2 ~' Q3 ~* G- h  e4 ^" l) Y1 }puts("and won't appear until the buffer\n"); % |& h9 y" k/ ]1 o: Z9 l
puts("fills up or we flush the stream.\n"); </FONT></P>
" i" C- m5 R  R0 E+ _<P><FONT color=#0000ff>/* flush the output buffer */ ; w  \+ |2 G+ q$ n4 o" x/ W
fflush(stdout); </FONT></P>' {+ D' ]/ |3 y! t$ l5 y4 t! k
<P><FONT color=#0000ff>return 0; * K6 n% b0 q, s. H
} ( F8 P& ]3 ~  n7 \4 {
</FONT>! P( G" y! i2 A; \* h4 N
</P>
5 N2 K: z) A) ^+ g: `, O, x/ A$ ^<P><FONT color=#ff0000>函数名: setcbrk</FONT>
3 p2 ]& l8 I3 J8 Y% a& P' x9 _( k$ m功 能: 设置Control-break , |/ S5 |4 d: K/ m- r. w2 @
用 法: int setcbrk(int value);
5 r4 z/ M# j5 C程序例: </P>0 Q6 g/ n& \. P( K
<P><FONT color=#0000ff>#include <DOS.H>
# U, e# p& g8 t* [/ t: l#include <CONIO.H>5 F3 a, G: B% G$ C# P! A
#include <STDIO.H></FONT></P>1 Z& }6 [* `2 \9 P
<P><FONT color=#0000ff>int main(void)
5 B3 i+ q3 k% u$ u{
% ~4 _5 z/ X, A0 m3 Z' T# g, ]' y2 h+ aint break_flag; </FONT></P>
# y) N: _* X: |1 v/ J<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
/ y- e; y$ o( P1 o9 B6 gprintf("Enter 1 to turn control break on\n"); </FONT></P>" A( I0 o2 O0 f) ~* W* t
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>
1 A! m0 {6 c7 d9 `3 ~<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>: E6 y( P9 p% l. H3 _& V
<P><FONT color=#0000ff>if (getcbrk())
  Y, b5 u; D0 k" Dprintf("Cntrl-brk flag is on\n"); - d  U4 j$ `. C1 b4 h) o
else
% t. Z- O2 ~; F* _2 S9 `0 Qprintf("Cntrl-brk flag is off\n");
; b, N! L7 V: z4 e* l+ Qreturn 0;
5 r8 r, Q, U& b$ h4 H- T} ( c1 }; V& X  o
" M) J3 b. ~0 ~8 H5 [
</FONT>  e  e6 q+ a( U  {6 N1 R4 I3 f
</P>
% O' b2 Y- o! k8 r0 e) \. M<P><FONT color=#ff0000>函数名: setcolor</FONT>
& P: X* E+ y; {2 s- ^4 V功 能: 设置当前画线颜色
- R4 K. h8 Z* n: M$ @- y1 m; x用 法: void far setcolor(int color);
: K0 I% [' i3 v+ q程序例: </P>6 X* u, L% n6 W! _
<P><FONT color=#0000ff>#include <GRAPHICS.H>
# o% K8 V: Z5 |5 h  h#include <STDLIB.H>
1 w! ~/ J' ?( |: j* g! h0 M, x$ w#include <STDIO.H>
& w( A' S: V" v) `! U% Z4 B#include <CONIO.H></FONT></P>* D- A: y4 M& a, |' D4 N/ i- A
<P><FONT color=#0000ff>int main(void)
1 A& w6 I4 c0 b1 Q; ~$ Q6 Z, o/ t{ + R2 j0 f" h, f6 H* ?+ y) V5 H1 I
/* select a driver and mode that supports */
. f; Z1 ~+ \; M2 W6 y/* multiple drawing colors. */ 4 o" Q5 O! g7 ]: r% a
int gdriver = EGA, gmode = EGAHI, errorcode;
/ I' k7 x! J- f( Qint color, maxcolor, x, y;
- a- ]- C/ y6 o( a: uchar msg[80]; </FONT></P>" D( d7 m1 h$ c
<P><FONT color=#0000ff>/* initialize graphics and local variables */ . G4 n- M# p/ v; ]; K
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- f# M( b) a$ a
<P><FONT color=#0000ff>/* read result of initialization */
" v2 c( x- V& S3 L; C" W1 }. Terrorcode = graphresult();
1 @, \$ F8 a) w2 l4 Yif (errorcode != grOk) /* an error occurred */
. p: Z" o' g) _1 u) f# J( _( {0 i{ 4 r" i1 A/ `1 R  L; R5 j: L
printf("Graphics error: %s\n", grapherrormsg(errorcode));
5 \! r- o! @% B8 K  n# hprintf("Press any key to halt:");
! b; A9 S5 w+ F& S% N+ I1 hgetch(); / f2 I; S& b" g
exit(1); /* terminate with an error code */ 1 O2 \3 i( \! X" D% l/ U
} </FONT></P>9 i  [( w1 Q  D
<P><FONT color=#0000ff>/* maximum color index supported */ ( ]& N3 N) u. f/ w4 @1 u
maxcolor = getmaxcolor(); </FONT></P>: C4 A7 Z; I8 Q( ^& T$ V$ [2 d6 [' G, u
<P><FONT color=#0000ff>/* for centering text messages */ " u# o0 b" a+ G
settextjustify(CENTER_TEXT, CENTER_TEXT);
* I2 ?* n( `9 k6 W9 G4 ~x = getmaxx() / 2;
: J" w  b# p0 o# s7 @y = getmaxy() / 2; </FONT></P>
1 v* u# W; @; v<P><FONT color=#0000ff>/* loop through the available colors */
9 }# ^) Q, t6 [4 l& g0 Z" w# {for (color=1; color&lt;=maxcolor; color++)
8 a8 w$ n) {3 @+ R+ L{
0 E3 m5 ]3 Q4 A3 E5 ?8 \/ G/* clear the screen */
( n9 u8 z2 T: E+ j# ^6 Scleardevice(); </FONT></P># }7 [: \- i  J  D) p( ~
<P><FONT color=#0000ff>/* select a new background color */
6 ^* k+ P4 }. j8 g5 fsetcolor(color); </FONT></P>
8 q' N0 a5 C4 |& b7 ~# [6 O$ p<P><FONT color=#0000ff>/* output a messsage */
7 w. z( s3 |, _) v0 b- W7 e; asprintf(msg, "Color: %d", color);
" V2 c1 t( c/ e8 Gouttextxy(x, y, msg);
0 Y, D3 g7 w. ^# t  X: a1 \8 K) rgetch();   Q6 g, S% A0 l: ?
} </FONT></P>- k; I& i3 ]- L; Z
<P><FONT color=#0000ff>/* clean up */ 8 i" A* {" O0 l" [0 k8 M
closegraph(); 9 T2 q9 W( Y) t
return 0;   G' i  D) s- t
} 1 Z' E. ~. d/ ]3 L
</FONT>
) d8 K/ v5 D- L7 }. P</P>0 t1 Q* {5 S* W1 j2 x0 P" x. ?+ [
<P><FONT color=#ff0000>函数名: setdate </FONT>7 j5 \) L8 {7 ^" _4 V8 l9 z
功 能: 设置DOS日期
5 Q" q6 Q- N% X9 G0 c( u用 法: void setdate(struct date *dateblk); 7 k! Q# B( j7 _
程序例: </P>
6 N, p8 g8 v& z% N<P><FONT color=#0000ff>#include <STDIO.H>* W( |& V6 k5 i" Z. B) j  g) n9 @
#include <PROCESS.H>
' I7 {( A0 b: \#include <DOS.H></FONT></P>9 ~* `9 h  }; ^- t# C* e1 i/ y
<P><FONT color=#0000ff>int main(void) 3 l- g; F0 S) q% v! \& d
{
" V/ y9 o5 d& a, K9 J- [. sstruct date reset;
4 x+ j1 [- A8 R2 Hstruct date save_date; </FONT></P>
) a7 T8 G9 |, [  h: }+ o<P><FONT color=#0000ff>getdate(&amp;save_date); ' B8 O- j# |7 V4 S4 \# |, ?
printf("Original date:\n");
3 W8 x/ y8 O- A6 Msystem("date"); </FONT></P>! {7 Y! T/ T0 r9 p
<P><FONT color=#0000ff>reset.da_year = 2001; ) e7 v, o0 {; o( F
reset.da_day = 1;
! r5 {* ?9 d: J" r, A! |reset.da_mon = 1;
0 F' Z, |/ g; r' V2 Psetdate(&amp;reset); </FONT></P>
, j; S* y! @, I8 x" ]% Y7 g/ w<P><FONT color=#0000ff>printf("Date after setting:\n");
4 b+ X, h. I, d) Q3 \; msystem("date"); </FONT></P>
: h& d9 ?8 z3 g  Z1 e! ~<P><FONT color=#0000ff>setdate(&amp;save_date); + k. _9 e3 B/ {; E- h  B3 \4 L
printf("Back to original date:\n"); 8 Q' ~) Y' ^4 t3 p( {/ i  ~
system("date"); </FONT></P>5 C2 S2 W1 f5 s
<P><FONT color=#0000ff>return 0;
; |$ |2 |$ Y4 y} : n) t3 D5 X2 x
</FONT>8 [  x0 G7 T! k; h. `
</P>/ n0 Y7 D3 F* D" [% K& K3 p1 o
<P><FONT color=#ff0000>函数名: setdisk </FONT>
8 R/ @: X$ ^' P- B5 o8 n& l, \! H功 能: 设置当前磁盘驱动器
+ b. d. ]  n5 w用 法: int setdisk(int drive); 7 l& y5 J% T$ [, m( z
程序例: </P>
* u1 f$ `- \1 `2 S<P><FONT color=#0000ff>#include <STDIO.H>* v# k0 M* L6 g
#include <DIR.H></FONT></P>4 u0 \' [/ z* U6 X3 Z% I$ F
<P><FONT color=#0000ff>int main(void)
' X7 j! k. j6 f* v9 j0 p9 n{ 8 t" t  L, t' d+ I' y; e
int save, disk, disks; </FONT></P>1 b4 T" M' N. f) c( S8 ]( z
<P><FONT color=#0000ff>/* save original drive */
4 X( ~' c  p$ h- f) h& t9 |( Vsave = getdisk(); </FONT></P>. l7 v% r6 [: l8 U6 ^" I# f% U
<P><FONT color=#0000ff>/* print number of logic drives */
) Z7 S! M+ n$ L2 c" e# Ndisks = setdisk(save);
, ?1 @! f6 ~2 A3 V" Wprintf("%d logical drives on the system\n\n", disks); </FONT></P>2 F) G3 E6 ]' v4 [
<P><FONT color=#0000ff>/* print the drive letters available */
$ k9 i2 C) Q9 k: M( lprintf("Available drives:\n");
1 x3 X# \0 `& O  ~, J; ^for (disk = 0;disk &lt; 26;++disk) ! p- [3 m: g  x) |
{ + f7 C. L. j* c5 e0 D
setdisk(disk);
. Z7 {! H! w- U7 g' Q! @& U) D* mif (disk == getdisk()) & E0 x% @5 a6 D$ I
printf("%c: drive is available\n", disk + 'a'); 4 \" A  E5 g0 E2 c9 M
} . t" O5 m2 B- l! @" m+ W. s
setdisk(save); </FONT></P>
7 @3 [9 a) v% j4 G) n<P><FONT color=#0000ff>return 0;
6 X$ s0 X0 {3 o0 M- C/ E} </FONT>4 a/ z' K" J; _2 c7 P
* y) C7 o; J& B
</P>0 j) y. `7 S6 u% G# O0 k
<P><FONT color=#ff0000>函数名: setdta </FONT>
/ k3 [  t) d" ?' @功 能: 设置磁盘传输区地址 & P( a1 V6 H+ P0 [
用 法: void setdta(char far *dta); 6 c2 ^, n9 n: _% P' `# `
程序例: </P>6 f+ n" m9 p' b7 y) a# C  N( H( p5 c
<P><FONT color=#0000ff>#include <PROCESS.H>0 u0 M+ Y9 s0 v3 s- b& _" m
#include <STRING.H>
) Q. |, `2 I; }#include <STDIO.H>& D( {0 Z0 L7 z( w5 s
#include <DOS.H></FONT></P>9 X! k. v4 E" R4 O
<P><FONT color=#0000ff>int main(void) $ K$ q* }8 }) {. b6 v
{ % e/ W6 Y! t! y( @9 j& E. ~9 g
char line[80], far *save_dta;
/ x! G, D" ]& P/ I9 Nchar buffer[256] = "SETDTA test!"; 8 Y9 P1 j/ R% f4 G. i* Y8 ?0 |
struct fcb blk;
( C' }- H: b6 N; H- N9 w! gint result; </FONT></P>, _* \# n/ T& S# S9 j; U/ k
<P><FONT color=#0000ff>/* get new file name from user */ ' E1 E: K" F- |* d: _/ [4 m
printf("Enter a file name to create:"); / W) H/ a- ?; j) u
gets(line); </FONT></P>
. q) x7 p/ o; r+ w<P><FONT color=#0000ff>/* parse the new file name to the dta */ 5 {/ f. W! Q) N
parsfnm(line, &amp;blk, 1); ( ^$ u1 ~: N" X6 @% E, S
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
( b# A6 r/ B" c<P><FONT color=#0000ff>/* request DOS services to create file */ 4 }# N( X; r( l
if (bdosptr(0x16, &amp;blk, 0) == -1)
+ J  K/ |4 Q" K* C( L: H{
/ {7 |: A+ O% w) fperror("Error creating file");
  v7 X' a$ F& u" s1 Uexit(1); $ M( ~5 M# O" F; n0 D1 x! v9 j) y
} </FONT></P>
4 V$ F, Z/ |& w" M7 y# M" _& v<P><FONT color=#0000ff>/* save old dta and set new dta */ : s- ~. ]7 f! V4 R
save_dta = getdta(); 8 j' R& a1 @$ U+ I! q! x) ^
setdta(buffer); </FONT></P>+ D2 Q" C4 B0 J! N) `; B1 A5 k' Z
<P><FONT color=#0000ff>/* write new records */ : j3 ]4 S+ q; C6 Y: O
blk.fcb_recsize = 256; 6 W- W/ M: d1 S  Y
blk.fcb_random = 0L; 0 w; C0 R: ]1 r# \' `6 P1 c
result = randbwr(&amp;blk, 1); 4 _% ]2 X3 E; ^0 P6 R) f: a8 y$ H7 ?
printf("result = %d\n", result); </FONT></P>1 D* p( v0 z4 e
<P><FONT color=#0000ff>if (!result)
% i5 x$ `( k* F4 v3 fprintf("Write OK\n"); ( `! i: \7 ?# O9 n0 e$ }% U
else 9 F3 `" }( F! X4 X" |( _0 v
{ 0 A! K& Z; b: w% x- x/ {( \+ _
perror("Disk error");
/ U! T9 b( M  X! Dexit(1);
* {/ H, j9 ~9 s! M0 _9 z} </FONT></P>
& Z. o0 R/ a9 e% p) G; D<P><FONT color=#0000ff>/* request DOS services to close the file */ 9 Y* ^  p/ Y5 U
if (bdosptr(0x10, &amp;blk, 0) == -1) % G5 b  m8 V8 g6 `9 _
{ ( z# b% |8 E$ v0 c: i% ~
perror("Error closing file"); / w( C) G& P4 U1 M5 G8 }5 R( ?
exit(1);
0 \8 O4 H4 n: ?" y7 r} </FONT></P>' d: V, e$ x$ O' n! M' W* ^
<P><FONT color=#0000ff>/* reset the old dta */ $ K, K: M4 O% c1 O+ e" L$ d
setdta(save_dta); 1 j: r, R6 E! B7 e% h
return 0;
' }; x4 ]. W3 Q2 ]% l& u1 U; ^6 ]} ) r, S+ D* Z+ V/ Z, E' S
</FONT>
2 e* z" }5 w" _4 }. N% d* h! k/ q</P>
: E; @; U7 ]2 }- @& c  M<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
$ L" _1 s* s" H+ s( w  ^% j功 能: 选择用户定义的填充模式
% y# c' i* H% f3 p5 h7 Y用 法: void far setfillpattern(char far *upattern, int color);
. }# ~4 v! r  D5 F9 I7 G) `4 @0 g; w程序例: </P>
, L8 u1 s) v; e0 z0 u6 x<P><FONT color=#0000ff>#include <GRAPHICS.H>6 x7 s# J8 J! k) Q1 B9 r
#include <STDLIB.H>" x; ]: t) o: W
#include <STDIO.H>) W6 a! o4 }: q5 N0 U' T
#include <CONIO.H></FONT></P># g0 I3 T- r$ J, |
<P><FONT color=#0000ff>int main(void)
" E( x2 h$ J4 W2 O" P! U# i# L; d{
7 k6 U1 v3 i, K; X% U+ ~& W1 x, w/* request auto detection */ 7 v! L; [9 l! n, y
int gdriver = DETECT, gmode, errorcode;
! O/ N9 I) i2 ?- f- Qint maxx, maxy; </FONT></P>
0 L% D7 W3 X- W& Z( X$ ^8 \<P><FONT color=#0000ff>/* a user defined fill pattern */ " L! \9 j, ~% y" E
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>8 F7 a0 T1 n3 Q( i% ~6 f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 }+ _  z+ c5 Vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( ?. y2 n1 j1 O4 j. o9 C/ E* h- x- S/ U<P><FONT color=#0000ff>/* read result of initialization */ * f% N9 e; O& O/ d
errorcode = graphresult(); / b- t" t5 L7 Y
if (errorcode != grOk) /* an error occurred */
5 s5 ]& V% Q" i; b/ q( T; a7 Z{
$ T' @5 l. q1 H- X4 G9 _' vprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 Z5 E) H! u2 p/ G8 ?. \) u  A
printf("Press any key to halt:");
3 E5 v; I8 l7 N" Rgetch(); 7 P* \: ]3 f. o! ~
exit(1); /* terminate with an error code */
& ^4 C- {0 P' f} </FONT></P>9 R3 }" [! e1 J# n- {
<P><FONT color=#0000ff>maxx = getmaxx();
" \* g/ z1 T' n3 ~, L# Nmaxy = getmaxy();
$ ~6 F# \* \/ w& zsetcolor(getmaxcolor()); </FONT></P>7 `: r1 U" v6 F$ K; ~, K
<P><FONT color=#0000ff>/* select a user defined fill pattern */ / b9 s7 a) i; |" e' H" U, w: C3 d
setfillpattern(pattern, getmaxcolor()); </FONT></P>5 O2 ~  e# V; {# L
<P><FONT color=#0000ff>/* fill the screen with the pattern */
& l* W1 G( t* d# jbar(0, 0, maxx, maxy); </FONT></P>) ~8 @* F( u' W, O) R! {! i" _
<P><FONT color=#0000ff>/* clean up */
/ z- C3 z# N- wgetch();
$ Q, R- @1 F5 v( G" f# M0 K! w% @closegraph();
3 w, V3 C! @0 p5 e( K; areturn 0; - ^& v9 I) K7 N$ C* I1 M
} 3 X+ A/ @9 s" O: M; y
</FONT># D- x( I/ @; S/ U7 q7 j! J+ f
</P>
) [) u- d2 X& j$ T, |" v; j2 A5 a<P><FONT color=#ff0000>函数名: setfillstyle </FONT>! s% Z& M, k/ K1 _
功 能: 设置填充模式和颜色
1 A2 F% P1 D0 d3 R/ k用 法: void far setfillstyle(int pattern, int color);
# f* R: f9 \0 g5 V# s$ R! n, b程序例: </P>! s% Z7 R. j8 R4 u" M% n
<P><FONT color=#0000ff>#include <GRAPHICS.H>8 r6 o- A: j! w& f
#include <STDLIB.H>! |# e4 T) A  k; ?& j" E$ h! ]4 Q
#include <STRING.H>
( V' @& v# P+ u# v#include <STDIO.H>8 l+ r/ n5 G' {$ K$ P
#include <CONIO.H></FONT></P>9 m8 K  u/ H# A( j7 S
<P><FONT color=#0000ff>/* the names of the fill styles supported */
8 |; i( Y& A5 o( R) pchar *fname[] = { "EMPTY_FILL", $ y7 t; D( C2 w' z6 s3 H
"SOLID_FILL", . c5 Y  R1 B; C& n. {6 `9 j
"LINE_FILL",
% r  _1 U; R: t+ i' R"LTSLASH_FILL",
. T2 o8 P3 |! O"SLASH_FILL",
6 H. Q. Z2 j' `+ s+ b"BKSLASH_FILL",
7 H) i7 V% u, o4 k"LTBKSLASH_FILL",
" s2 @; a0 M2 ^# k$ j- f* ^"HATCH_FILL", ) k; u6 k& u: L& Z2 d& g5 q: u* K
"XHATCH_FILL",
% Z1 ~! F  r1 |' S4 H7 w" C"INTERLEAVE_FILL",
" E% q( }" O, b6 z' k" M"WIDE_DOT_FILL",
0 R* Z7 b4 V* x0 c0 G# p" ?, ~9 s& x; k"CLOSE_DOT_FILL", . c: ~# ]$ J9 C
"USER_FILL" 4 B( p' D0 @" S( Y; k8 [
}; </FONT></P>6 \5 T7 A3 v1 ?) s$ p
<P><FONT color=#0000ff>int main(void) 2 C4 J4 S7 X2 i9 T9 P4 `. f
{ , b. A- l7 ~' P2 z3 D
/* request auto detection */ ' T2 R' m+ J/ Z: \
int gdriver = DETECT, gmode, errorcode;
3 l: V9 F5 v0 t, J. ]int style, midx, midy;
8 D9 z' H% N2 Y7 j9 o! Bchar stylestr[40]; </FONT></P>, c/ u0 x. R# }* ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( @# W5 I* o9 u, S& u' y7 \& S
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>- f& ^, S, S9 t) n+ A6 m
<P><FONT color=#0000ff>/* read result of initialization */
0 o! \: n% S9 S" `errorcode = graphresult(); $ ?0 V/ A/ R" K# ?
if (errorcode != grOk) /* an error occurred */
2 H# o# V. E7 V; b1 U3 B{
* k* a; K- D& eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" E6 [) {& o: j( u3 b+ W9 m8 ~printf("Press any key to halt:"); & R* ~; h7 ]. P1 }
getch(); * K( I- q8 h6 C: i- n- K2 c
exit(1); /* terminate with an error code */ 7 Y8 z' g" R  f" m! |
} </FONT></P>% r. z/ ~* Q$ U, j
<P><FONT color=#0000ff>midx = getmaxx() / 2; . M% U& }1 s  Z& o( k) A8 I) f/ p
midy = getmaxy() / 2; </FONT></P>9 \- V4 Q6 {* V" b* X
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
. N' K1 _- p) b' d( N' l{
  k& r8 Q2 m+ q/* select the fill style */
# m+ G6 p9 v, S* xsetfillstyle(style, getmaxcolor()); </FONT></P>6 m& Y$ X& W2 R* z% u- J
<P><FONT color=#0000ff>/* convert style into a string */
+ r* N5 e( H% ]strcpy(stylestr, fname[style]); </FONT></P>6 o0 a( P  P2 H5 T; t
<P><FONT color=#0000ff>/* fill a bar */ 9 s6 K; K& {1 m2 w" b7 B6 @
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>  d# w: X  U! b- u: t8 h
<P><FONT color=#0000ff>/* output a message */ / a$ v+ S/ j9 e; ^( S
outtextxy(midx, midy, stylestr); </FONT></P>  X( U/ j6 ]3 c' D- f/ B
<P><FONT color=#0000ff>/* wait for a key */ % `& W3 F, V( H; N. |! D( P8 P3 l7 U
getch();
/ G) h# S4 o. M0 l# tcleardevice(); - s* Z! Z: z/ i5 m
} </FONT></P>
1 J( X' b5 O- C% o5 d0 j5 a<P><FONT color=#0000ff>/* clean up */ 0 h4 E9 P3 [# ^/ \
getch(); # n% z  ~, N$ p* _/ ~* M0 n
closegraph();
9 J7 K$ ~5 f6 r8 Kreturn 0; / u. L% A7 R( J1 m
} </FONT>: R5 ~/ b! O+ h4 b0 e) ?0 u  l
8 G$ q( N6 P+ W3 }
</P>
( k# o+ @; h7 k' j5 b; r<P><FONT color=#ff0000>函数名: setftime </FONT>6 Q  t3 }1 S2 a4 c
功 能: 设置文件日期和时间 7 H8 Q( L8 U5 I) ~% w/ E
用 法: int setftime(int handle, struct ftime *ftimep); 6 Q( T7 W7 h8 K* O# b1 `
程序例: </P>
' ^: N9 D  t9 {0 [, C<P><FONT color=#0000ff>#include <STDIO.H>
: j% n: f  c" P6 S* s#include <PROCESS.H>
5 I, Z8 |' M- _3 R; P1 I#include <FCNTL.H>
( W6 B! h3 i1 X% v; l" N) [. V, N8 N#include <IO.H></FONT></P>
) t  F+ A( ^, l- o& w) w<P><FONT color=#0000ff>int main(void)
# |3 k* x4 {0 \) E{ . l2 G- {( j- E; T
struct ftime filet;
1 z/ |! e, Q" K  g- ]FILE *fp; </FONT></P>% n5 T/ a! p. @, U. ~* g: D0 K7 C
<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL)
* }0 _* k5 f1 m( h; Q' J( V{ 6 y2 S1 N2 Y+ j" c7 ~: M! q
perror("Error:"); 1 I+ m, v) n$ x; p
exit(1);
, q/ `0 R# M* o: D' y; N} </FONT></P># W  S5 G8 N1 L# |
<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>
6 u6 i6 o+ h' h- r0 |+ }<P><FONT color=#0000ff>/* load ftime structure with new time and date */
; \4 U7 x( {1 I0 Xfilet.ft_tsec = 1; , l  B/ J9 r( q
filet.ft_min = 1;
+ y9 L9 u5 A7 j8 p! Y3 zfilet.ft_hour = 1; ! Y* |& A% n5 d! q: R1 o
filet.ft_day = 1; * ]3 t: x0 V  G) Q1 z, G
filet.ft_month = 1;
6 a0 Y) [( p! A- N* @6 k$ c7 k" hfilet.ft_year = 21; </FONT></P>/ D6 V! C! i; e$ W9 K
<P><FONT color=#0000ff>/* show current directory for time and date */
; l% ]* p" c, x. m3 x$ U2 }system("dir TEST.$$$"); </FONT></P>$ |4 s+ e9 }5 @$ j% _( A: V
<P><FONT color=#0000ff>/* change the time and date stamp*/
) m( z5 ?! o8 D) l7 u: B" ysetftime(fileno(fp), &amp;filet); </FONT></P>: B  O" t7 z, u4 \2 ]/ B
<P><FONT color=#0000ff>/* close and remove the temporary file */ 9 t7 Y6 d2 W. F6 @) G1 H
fclose(fp); </FONT></P>. P: c/ f2 N5 o$ q% N6 A* D! P
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>
) ^7 R# o3 O, q2 ~3 U<P><FONT color=#0000ff>unlink("TEST.$$$"); . Q7 d7 s4 G/ I2 X# G
return 0;
! C' r9 b0 r: x5 M2 g* N}
! @2 D( f! A; k) Y7 L/ x& u</FONT>
6 \) O/ ]* W1 A% p0 t</P>
2 ]1 _- o3 F3 _  y' F( B<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>4 m8 ~+ d9 F- r
功 能: 改变内部图形缓冲区的大小
1 d: a3 ?" a" ]9 N6 I' h! F用 法: unsigned far setgraphbufsize(unsigned bufsize);
, c; G% ^, D- g* J1 x& z1 u程序例: </P>0 w& [" c; p4 |" b' N$ H
<P><FONT color=#0000ff>#include <GRAPHICS.H>7 r, i, L6 F, P' F5 |7 C/ C4 n) U& x
#include <STDLIB.H>1 r* s3 V+ v6 a5 X/ g: v
#include <STDIO.H>1 L& H% ?: m  A% Y2 x
#include <CONIO.H></FONT></P>
# \8 C4 ^' L" Q* ~+ T. m<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>/ Z1 p8 m! S2 O# ?6 X! ^/ C6 t
<P><FONT color=#0000ff>int main(void)
3 C: E9 k" c, r1 _- I! A/ `* o{ 4 t; r& H' o: X; K7 R
/* request auto detection */ * c0 W9 L+ Y/ w0 h# R& B
int gdriver = DETECT, gmode, errorcode; 2 V2 O: ^3 A) C' a/ J
int x, y, oldsize;
7 ]. D7 e9 U- c# v! Bchar msg[80]; </FONT></P>
: _! V# u! w4 X0 E% b+ O<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
0 l, M# A8 x& s6 s/* before making a call to initgraph. */
# g4 A: V% S" o2 K/ p" D% w- X6 koldsize = setgraphbufsize(BUFSIZE); </FONT></P>& ?$ V( q+ d" t7 B& T
<P><FONT color=#0000ff>/* initialize graphics and local variables */ # ^$ [( b. {9 x/ f$ C
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
9 }; k; b) \6 d+ s<P><FONT color=#0000ff>/* read result of initialization */
, H6 W5 A2 J0 ?" L: Aerrorcode = graphresult();
. ^0 ]/ G) ~; w7 gif (errorcode != grOk) /* an error occurred */
( D1 ?! U5 h  R& [, Y{ 9 s+ A" n0 P" H  Z- W  V4 O
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # y. `' W6 Q9 A3 x9 Y
printf("Press any key to halt:"); / X5 v/ S+ G3 g" S3 ^$ M
getch(); ! O3 `- Z  ]' I2 a" \7 v! _
exit(1); /* terminate with an error code */
1 u8 O, h4 y+ E} </FONT></P>. z! u4 w0 Y! f/ a2 l$ t) b
<P><FONT color=#0000ff>x = getmaxx() / 2; : t1 o, l  e9 {& q( c  j5 ~: ]; j
y = getmaxy() / 2; </FONT></P>
1 Y+ d, S2 o- @, `! y. v0 K<P><FONT color=#0000ff>/* output some messages */ ; Z1 f; p4 L4 ]
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
# R. c5 J5 J- H% G3 x6 N1 \* rsettextjustify(CENTER_TEXT, CENTER_TEXT);
' v) T  y4 m8 q* `outtextxy(x, y, msg); 9 \# [8 v' }) G* W! `
sprintf(msg, "Old graphics buffer size: %d", oldsize); ! M  X5 l9 B$ K4 Y; a
outtextxy(x, y+textheight("W"), msg); </FONT></P>
# S; c! A6 D1 ^$ V2 A0 z<P><FONT color=#0000ff>/* clean up */ 5 R1 y6 X( [* z  Q
getch();
! l, u( v& ~( E% Q  Zclosegraph();
3 e5 x$ q: m" D* [' Areturn 0;
$ J2 I- T8 m6 c# u}   G6 G4 A7 k) |! D# ?, I8 I
# I: g! Q( X6 S5 ?0 W+ q

4 M7 ^9 c# ?! I' m/ L+ c</FONT></P>7 X( ?0 \; h0 ^2 c
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
& \; w- t& Z. e+ Q$ V8 U2 M功 能: 将系统设置成图形模式且清屏 * ]" P6 |* @: ?5 t# n
用 法: void far setgraphmode(int mode);
5 I1 k7 X$ S3 Q/ c/ @2 e程序例:   v4 [; u' P( I/ X  H

5 h+ x+ K) ], u: y6 v8 l<FONT color=#0000ff>#include <STDLIB.H>
& e* ~, P1 r) o9 H. x! I2 r#include <STDIO.H>
7 k" J; g9 q  w9 D6 t#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
& \$ f; }% V/ J0 i<P><FONT color=#0000ff>int main(void)
+ B) @' ^* J7 R; n3 ]+ y& U{
( {, O/ |1 P7 F# {: n" B/* request auto detection */ . T+ d  N# q* J, E
int gdriver = DETECT, gmode, errorcode; 5 ^# u* `% d2 k3 x; E8 [! F
int x, y; </FONT></P>
9 F; F7 u& F' x<P><FONT color=#0000ff>/* initialize graphics and local variables */
& a3 w8 i" W( F8 ]( _# w: Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 u: _/ E4 Y1 U* b4 W
<P><FONT color=#0000ff>/* read result of initialization */ 5 b2 L) \# t9 s& Y: w6 c
errorcode = graphresult();
( x8 Z7 d- M& hif (errorcode != grOk) /* an error occurred */
4 E6 X4 {; h- M3 n: b( x5 L{
. y, B, e6 U8 cprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ) v" y- L2 A* }% v6 o
printf("Press any key to halt:");
- s+ X4 T& c$ B" ggetch(); # Q7 n5 h" Z' D- K
exit(1); /* terminate with an error code */ : N& ?3 T/ }1 ]7 T+ \
} </FONT></P>6 W' J; V9 C% j5 n& H/ a. Z5 i
<P><FONT color=#0000ff>x = getmaxx() / 2;
% B# e' ^( N/ e2 Y" P1 ay = getmaxy() / 2; </FONT></P>
$ H8 V( |0 p) R8 N<P><FONT color=#0000ff>/* output a message */ . Z* X8 G; l" G, G# R3 Q; K
settextjustify(CENTER_TEXT, CENTER_TEXT);
7 Q, L% g& M) G' @, c8 N* J8 Couttextxy(x, y, "Press any key to exit graphics:"); 9 v2 M; R( e4 g. [6 _, J
getch(); </FONT></P>5 D& Y% z- N% l
<P><FONT color=#0000ff>/* restore system to text mode */   F# N( L. @" R9 x( ?2 l
restorecrtmode(); 6 U9 {2 A! q( f+ Y9 U
printf("We're now in text mode.\n"); , `, a! c( J" s- d7 u
printf("Press any key to return to graphics mode:"); $ \# O# a2 K8 ], f9 a( n
getch(); </FONT></P>
4 D. h% g3 h7 l  u<P><FONT color=#0000ff>/* return to graphics mode */
, J! ]9 w: G6 e8 d# W" G$ Q8 I0 T: m* |setgraphmode(getgraphmode()); </FONT></P>2 b& w1 l8 ~- i$ v9 S/ R$ u! x
<P><FONT color=#0000ff>/* output a message */ & `' k/ r( x8 p' k( _
settextjustify(CENTER_TEXT, CENTER_TEXT); - Z1 @5 X5 n0 q3 I0 @, [$ h' m" Y
outtextxy(x, y, "We're back in graphics mode.");
- o( }4 U  ^* X, @5 routtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>
+ K; x9 l+ ^/ x+ [. c+ N<P><FONT color=#0000ff>/* clean up */
5 c3 c9 \7 a% W( r$ [) P% \getch(); # B' g4 K; @; S$ _
closegraph(); : O/ O; |( k$ x. C8 s  N
return 0; , e- _  \# G% E1 ?
} $ Q# U# h# G3 E* `3 Q8 D
2 W; s3 v  P/ F3 k
# k8 }' ?4 `9 H$ W# c  G
</FONT><FONT color=#ff0000></FONT></P>0 a' b( {/ E- f+ d
<P><FONT color=#ff0000>函数名: setjmp </FONT>
9 T; [3 q9 z% e# }功 能: 非局部转移
. ?+ V. s* c& @- }用 法: int setjmp(jmp_buf env); 0 v; N( f  M+ N+ W: F2 F
程序例: </P>' x% g; c& p" e! p5 W  u" Q
<P><FONT color=#0000ff>#include <STDIO.H>; M& p( I, o+ M' \; z
#include <PROCESS.H>
3 N% a) y* k' c9 J9 z3 N7 v#include <SETJMP.H></FONT></P>5 d& K1 a" c8 p0 k  `
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>% M. m6 f$ Y, Q" `) B6 J
<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>
3 {4 r- p' J; D* I& C/ _) T5 y<P><FONT color=#0000ff>int main(void) 8 [. r7 o4 t* g; @$ U
{ ( }* l) \; e+ e5 W
int value; </FONT></P>
  t7 ~/ a( g& H5 V. I<P><FONT color=#0000ff>value = setjmp(jumper); 8 h, p+ t- a$ T$ ?6 `
if (value != 0) 1 o3 i8 _0 m# ]% H3 X
{
' u6 H1 \8 b- O4 S3 Oprintf("Longjmp with value %d\n", value); : ~9 M, n4 P- j: E
exit(value); 7 W3 d2 c, z& Q3 v3 d( L3 S( m
} 0 b# Q4 u; V- c0 W) b
printf("About to call subroutine ... \n"); 2 W/ U3 t: L* d: C) `% g7 t
subroutine(); + T0 @& g- y- d& u( [" \" @/ a
return 0;
; R- E; y1 S! Y4 h} </FONT></P>( R1 ^: F0 s$ L% S* Q& v- E2 L
<P><FONT color=#0000ff>void subroutine(void)
, y. n4 [3 y* T. G{
$ g% S5 h& b0 b3 T1 k% o; nlongjmp(jumper,1); 6 [0 h: P* J; M- n$ \
} 5 u9 l( s' ?/ x' B2 l
</FONT>- {5 ?* F9 N+ I8 S; R+ n1 _8 P7 h- c
</P>" h3 _9 ]' C- S; t% M
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>7 @- ^7 }) B: G; |( I
功 能: 设置当前画线宽度和类型
& u: D" q& [; B用 法: void far setlinestyle(int linestype, unsigned upattern); ' K$ L8 X: P1 e; T' H1 U" R; S+ C
程序例: </P>
, K  S( n  k1 _% H2 j0 F& T! [<P><FONT color=#0000ff>#include <GRAPHICS.H>& F8 l* }* U5 K! J' q/ \
#include <STDLIB.H>
7 \& u  {2 ?: E% y2 I  ?! W& `6 T3 Q. N#include <STRING.H>6 r, X# \$ M8 P! R3 E7 c# M
#include <STDIO.H>
4 g8 \1 n# h" A1 t8 \1 W#include <CONIO.H></FONT></P>5 f, L6 o0 L" o1 ?5 a
<P><FONT color=#0000ff>/* the names of the line styles supported */
3 G( k4 Y- R  n8 C+ ^( a, Rchar *lname[] = { - F7 U: t5 P$ o1 \5 R0 \5 H
"SOLID_LINE",
5 t; L2 [, G" E( {"DOTTED_LINE",
: B* m! I3 O: Q/ u$ D"CENTER_LINE", ) s# x) y8 m' B: I4 Q" I
"DASHED_LINE",
/ o% }; Z$ Z6 m) }0 K: g"USERBIT_LINE"
, k& T6 d; S% z* h; n}; </FONT></P>
0 y' |4 k$ p! h) M4 f% B/ F' ?: }2 E<P><FONT color=#0000ff>int main(void) 6 k: t3 g9 ]1 t0 D3 u' g, U
{
( \( Q) P  \/ X3 B/* request auto detection */ 8 X/ n' ?8 Z% N" V
int gdriver = DETECT, gmode, errorcode; </FONT></P>1 A. ]6 @9 d0 `$ K
<P><FONT color=#0000ff>int style, midx, midy, userpat;
2 H$ B& C$ e- t; W. H9 |char stylestr[40]; </FONT></P>
/ r: |; g( @1 v1 _$ O- _<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 B& e7 \* U* y! H
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 J$ _: h" u1 M
<P><FONT color=#0000ff>/* read result of initialization */ , g2 z4 ?  o! e/ F' [
errorcode = graphresult(); 8 A- u+ ?$ d+ Y8 L& E6 Y9 t
if (errorcode != grOk) /* an error occurred */ 8 o# I7 g4 ]" S2 I, l  O; r
{ 1 f1 q2 _$ N9 Q  E0 P
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 b( {$ I" U: ^* P( s2 b8 i8 p
printf("Press any key to halt:");
1 g" O. ?3 V" \" E( Fgetch();
4 Q4 i, V# s8 W6 K* Eexit(1); /* terminate with an error code */ ! L& e" G# s' n  ~
} </FONT></P>) ^2 B  F2 k, z/ H; d
<P><FONT color=#0000ff>midx = getmaxx() / 2;
5 K( B7 p9 B, q: n% i% zmidy = getmaxy() / 2; </FONT></P>
& q( }0 l/ |+ G! z<P><FONT color=#0000ff>/* a user defined line pattern */
: t6 T0 Z3 y8 N4 v5 G/ ?' w; Y* j/* binary: "0000000000000001" */ % l. k" y+ J; ?; B4 M& B; V
userpat = 1; </FONT></P>- T8 o9 |  J' J% m) ~& A, x: k" R
<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
8 s4 @0 ~2 `1 G* S! _3 C# m{ % P. x: O& X- E5 ^7 c* i
/* select the line style */
. C8 F( x. z+ }& @# dsetlinestyle(style, userpat, 1); </FONT></P>
. c/ e. _$ w) [( {: a$ A' L<P><FONT color=#0000ff>/* convert style into a string */
% p0 E, i) r3 ~# o* y$ Z& kstrcpy(stylestr, lname[style]); </FONT></P>; v% _3 Y/ b- {5 S4 c
<P><FONT color=#0000ff>/* draw a line */
( A7 Q8 q7 i( d  f+ w0 G* v0 uline(0, 0, midx-10, midy); </FONT></P>  d2 w; F8 C9 X" z$ d
<P><FONT color=#0000ff>/* draw a rectangle */ 8 C5 N4 q1 ?3 s# }3 l& @. l
rectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>% h% s; ~! ^9 {
<P><FONT color=#0000ff>/* output a message */ 7 E/ l: T1 j4 I3 M9 \! y9 W
outtextxy(midx, midy, stylestr); </FONT></P>
9 n) J& W; ?' k<P><FONT color=#0000ff>/* wait for a key */ & q: r+ _. W; I
getch(); $ M3 Z' i* ^- C; P! f
cleardevice(); + n% b/ U9 j1 }! r+ E1 H# D
} </FONT></P>, R7 p* ^  w) f
<P><FONT color=#0000ff>/* clean up */
  r5 X. c% G( S* J8 sclosegraph(); $ m$ y. G/ L! a* P
return 0; # N, m+ _4 E, R2 H& {
} </FONT>
0 h- d- R; z0 `
. K! Y. O+ F) X, s% m) n  w, q( D8 X6 C
</P>$ O3 p( P7 u% Q6 \
<P><FONT color=#ff0000>函数名: setmem </FONT>
  y; e6 U# c. a功 能: 存值到存储区
/ j" c6 ?9 }4 ?' i" b: P: o用 法: void setmem(void *addr, int len, char value);
: g5 d  g% [' {程序例: </P>
; G. A+ X6 a2 ~1 I" \2 P" M/ K<P><FONT color=#0000ff>#include <STDIO.H>
' c1 |; s" D/ r) Z3 J#include <ALLOC.H>" j+ Z& @0 Z1 U1 L
#include <MEM.H></FONT></P>
* O4 P) [& x, I<P><FONT color=#0000ff>int main(void)
4 a( i: n$ y/ T& H0 t" N{
+ p) D5 u+ |  R) J; A! p& |char *dest; </FONT></P>/ J6 K; b; ^1 N( c  T
<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
* B7 ]& ~8 _6 i! Q; Ysetmem(dest, 20, 'c');
& ~: ?: `& U% fprintf("%s\n", dest); </FONT></P>
% g* x. t; q4 q, P. P, @<P><FONT color=#0000ff>return 0;
0 O, M' Y$ U# v+ t} </FONT>  w) \# [; D5 V7 y0 ?0 I& S. N

2 c! W' W! G0 i. N0 |  n. r" \: V
1 T' ]0 T  d- x0 ~3 x</P>
& C1 v! M+ \) ~<P><FONT color=#ff0000>函数名: setmode </FONT>
7 p* [" A' ?; \5 ?0 o功 能: 设置打开文件方式
/ C! \: [( Y+ ?用 法: int setmode(int handle, unsigned mode); 0 N' A* r3 P( r
程序例: </P>- _& ?1 {( X" x3 f
<P><FONT color=#0000ff>#include <STDIO.H>; G; d1 L& c# ^. e7 ^$ A
#include <FCNTL.H>
" q8 [& }) ^" Q( |. w#include <IO.H></FONT></P>) G% _8 I# E- J" u' c
<P><FONT color=#0000ff>int main(void)
4 G+ G- X& ?: b/ n, \( D2 L7 U{
) Y  m2 C, A* b% \, h: e* mint result; </FONT></P>& a! {8 _8 ?4 l( l& C) O
<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
. ^6 u5 u" ]% _3 j5 J7 l4 ~0 jif (result == -1)
0 b9 z( s( c: @, h& G# p& x6 W6 nperror("Mode not available\n");
9 U8 q# F9 h; l& A- ?else 4 o0 q& `6 e; D$ e. A$ G
printf("Mode successfully switched\n");
: n) q) z+ n1 f( {return 0;
# J  z4 `) G( ]: \+ B}
! g9 R3 L. S* C8 j2 ?' L; M, J3 G' e8 Y
</FONT>
) k  |- g+ f6 C. W& N</P>  k- I& M. X7 q* ]
<P><FONT color=#ff0000>函数名: setpalette </FONT>
, ?8 T+ t! V& K) d功 能: 改变调色板的颜色
! }& A0 G. A) M# I4 I! _! H用 法: void far setpalette(int index, int actural_color);
3 B% W' P# q: \! d8 C程序例: </P>
3 Z" P8 ^7 J, J$ o3 {  N<P><FONT color=#0000ff>#include <GRAPHICS.H>& w: @( `+ _: B& m# l  X: e/ \
#include <STDLIB.H>
6 A; D/ `( [- }#include <STDIO.H>
' J9 t/ Y9 w# z% j" v#include <CONIO.H></FONT></P>+ S! g- s* ^: \2 @1 F
<P><FONT color=#0000ff>int main(void)
- r! n( _8 W  E' `{
8 T" I9 B0 Q0 v# z9 [7 M/* request auto detection */
/ w( R; ?! d8 p6 g% T1 kint gdriver = DETECT, gmode, errorcode;
  ?( S1 f0 e5 Q0 p  l0 ~+ eint color, maxcolor, ht;
& r0 F5 \2 o1 J/ Z) L4 h# uint y = 10;
/ ~5 s/ \( Q/ U6 z6 F: Cchar msg[80]; </FONT></P>
- V  m; y* b7 [7 G<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 {& C1 S: b! V& U3 N' T1 z5 h7 yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  V9 \+ P( U! ?% E<P><FONT color=#0000ff>/* read result of initialization */ $ Q: l) _" F* Z& W- @, q9 t
errorcode = graphresult();
) v2 N: A3 N# C6 b4 kif (errorcode != grOk) /* an error occurred */
% S) z. {' D; g/ _* i{
9 A: q" N) t- H  e  vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
% M  `7 m! G6 O% Mprintf("Press any key to halt:");
5 U9 L* L  `9 Q/ X. ?- l" kgetch(); 4 Q& j) f# g# S5 ~$ `7 f. e6 j8 Q9 u
exit(1); /* terminate with an error code */ ' r4 m; K. F4 A5 U& I
} </FONT></P>: f: e- s0 g% T4 }8 p
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
$ Y7 z& H' l) h8 k' i) [$ V- Wht = 2 * textheight("W"); </FONT></P># `( V' e! L  }
<P><FONT color=#0000ff>/* display the default colors */
2 B4 G% _: [/ Z! s; _% pfor (color=1; color&lt;=maxcolor; color++)
- p# d  b* ]& h{ * X4 B5 j$ p& S- K* R2 |7 Z4 v/ d
setcolor(color);
& i4 d% D/ ^7 F9 B7 Ksprintf(msg, "Color: %d", color);
- D; A$ @& F. U0 ~- souttextxy(1, y, msg); # Y' X& n" G, g# `6 U
y += ht; $ F  M0 D  u6 g# N' ^
} </FONT></P>
4 I9 a8 l- L. ~' V<P><FONT color=#0000ff>/* wait for a key */ 8 W& r; x2 ^) u9 k8 H  f
getch(); </FONT></P>
! X: X" s& a! ?% X  M" q5 d<P><FONT color=#0000ff>/* black out the colors one by one */ ' A$ D5 D: y3 D1 w) Z: p
for (color=1; color&lt;=maxcolor; color++) % h9 v) t) }# Z, V( `  E7 M
{
2 [, I/ v" ~% u$ x, asetpalette(color, BLACK); 6 C: a: g0 @: G4 O5 e
getch();
& ^" x/ I1 b- U# T} </FONT></P>' @8 N) V. u5 n2 m# X( a/ s
<P><FONT color=#0000ff>/* clean up */
, x% r+ Y* J5 B9 k3 H6 j6 kclosegraph(); / n- W# r9 T7 g
return 0;
+ o, g' Z/ G( l* S4 `$ ~! G}
: l8 D1 }3 x; {</FONT>
: J  N, t7 ~7 }6 X</P>; N9 J3 ]$ b  v
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>6 L  o1 a7 @* x5 t/ U* ?0 Q
功 能: 定义IBM8514图形卡的颜色 1 C( h" O( X* l
用 法: void far setrgbpalette(int colornum, int red, int green, int blue);
" Q, S  F, n- h1 {* G" Q2 M程序例: </P># D  D. E2 F; u& H
<P><FONT color=#0000ff>#include <GRAPHICS.H>
! _, h+ J$ `) D( N- }#include <STDLIB.H>
( f- m  r: z( X- B3 y5 O#include <STDIO.H>
! S& d) L0 L5 i0 s6 k#include <CONIO.H></FONT></P># }7 H4 C; w: B" F+ K2 G5 U
<P><FONT color=#0000ff>int main(void) - n, u* E) F6 l+ q4 o, P
{
- ?4 I* q+ N6 D/* select a driver and mode that supports the use */
0 u* @2 \% }" b7 h/* of the setrgbpalette function. */
% \4 w% b% H- F1 a) P- G8 o# Uint gdriver = VGA, gmode = VGAHI, errorcode;
. D4 T7 J, q' y' }2 c6 dstruct palettetype pal; 8 u. R8 I* f+ }' o0 s  K
int i, ht, y, xmax; </FONT></P>: s( c& `4 y" }
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# N2 D: q. ]! S8 g2 F0 Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 L/ R' H% q$ e) y2 O  d5 P* ?
<P><FONT color=#0000ff>/* read result of initialization */
0 |7 Q" x% A3 j. a5 I5 l# k% Rerrorcode = graphresult();
. ]8 m6 U9 F/ pif (errorcode != grOk) /* an error occurred */ 9 z$ {' i. l$ @: c. Y
{
2 d3 S# V3 y5 p. E9 ]' Sprintf("Graphics error: %s\n", grapherrormsg(errorcode));
" d5 i1 C# q: _' oprintf("Press any key to halt:");
- K' p# l' E; Igetch();
: q' f& ?6 T1 C4 S* p. h, Gexit(1); /* terminate with an error code */ 4 c9 G6 m% {. J$ p( q  Q8 B9 i
} </FONT></P>
( T! e" \8 ?: m/ E' e9 R<P><FONT color=#0000ff>/* grab a copy of the palette */
4 Z4 b4 B7 {/ V& P5 u/ n" \getpalette(&amp;pal); </FONT></P>
+ _$ d" i8 D9 d: M4 ^5 K3 a+ e' R) r<P><FONT color=#0000ff>/* create gray scale */
& T6 {* C" l( r5 Bfor (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>8 A- D) B% h" K& I, l
<P><FONT color=#0000ff>/* display the gray scale */
9 {' e5 I- A7 o5 _& \- Uht = getmaxy() / 16; ; j7 G# G, ^$ H8 {
xmax = getmaxx(); 7 G% u' i9 ?% T/ T/ A; h
y = 0; 9 ?% ]) _- K' @; x: o2 S; P
for (i=0; i<PAL.SIZE; <br i++)> {
" Y- E3 f) ~, C/ X* tsetfillstyle(SOLID_FILL, i); 2 P1 k; C6 P- ], y& h. l
bar(0, y, xmax, y+ht);
" j8 M0 p; g. a, u! Z) ?  By += ht;
) }  t3 q  k9 N1 c( u} </FONT></P>
, b  O/ }( X/ P8 k! y% K* I- O<P><FONT color=#0000ff>/* clean up */ 7 a1 S; @+ \5 S4 u( V9 ^  x
getch();
4 v+ O; s6 c" gclosegraph();
  {5 }0 ?) U& a. K, F. Preturn 0; # N3 P, [: u& M+ j7 L0 L9 V/ N
}
8 ?( G1 c$ V8 w. n' v5 p) M) h</FONT>+ u" o% x4 T7 _! I
" w6 K+ ^5 }$ p$ ~# A
</P>3 H  c) L% i, Q
<P><FONT color=#ff0000>函数名: settextjustify </FONT>: D  K: @$ n  N4 Q
功 能: 为图形函数设置文本的对齐方式
4 i6 q# v% V" i1 d, s0 |用 法: void far settextjustify(int horiz, int vert); + F$ S: `9 ]3 ~1 r5 `! k$ j7 x
程序例: </P>
5 c1 a" K0 g+ I/ B& ?1 c* ?<P><FONT color=#0000ff>#include <GRAPHICS.H>8 o4 {8 p4 y3 I
#include <STDLIB.H>
7 t) M( V, }8 @  E5 x#include <STDIO.H>5 s& a# U# c2 J0 u. a4 U
#include <CONIO.H></FONT></P>
) L% w* a/ n6 J) O3 p. n  l& ?" a<P><FONT color=#0000ff>/* function prototype */
9 H' N' i, v, v! j2 _void xat(int x, int y); </FONT></P>$ i: l$ o# l7 a7 |  d
<P><FONT color=#0000ff>/* horizontal text justification settings */ 0 F- Q1 `; Z7 T( X+ d' U6 E  v
char *hjust[] = { "LEFT_TEXT",
' H9 m0 X8 w" v: U" E: r# h& \: i! P1 c2 w"CENTER_TEXT", ( `  `# j+ \9 {
"RIGHT_TEXT" 1 \% r& s8 f$ m) `/ N3 p, [
}; </FONT></P>
3 X! f. \1 q& G) d, Z0 w<P><FONT color=#0000ff>/* vertical text justification settings */
, O2 ?# X9 j7 _% q) |char *vjust[] = { "LEFT_TEXT", , t% d& z. I. z
"CENTER_TEXT", - S; P7 I  E/ A; V# _2 C0 R
"RIGHT_TEXT" 4 E5 y7 h/ H, \% a! j- O
}; </FONT></P>
0 {) `8 j$ T9 F2 i<P><FONT color=#0000ff>int main(void)
  b4 @& z8 c0 `* z$ F+ C& U{ 0 V1 w6 [1 \1 z& w" e5 m, |; H4 Q
/* request auto detection */
5 E' L0 ]3 {% n, \2 @( d) ?int gdriver = DETECT, gmode, errorcode;
# x, b! B7 x* s! c! {int midx, midy, hj, vj;
  B6 v+ O, G# s' ]char msg[80]; </FONT></P>
0 |5 ^  S$ |$ ?3 B( @- p; }<P><FONT color=#0000ff>/* initialize graphics and local variables */
& `; l0 M; W+ x! ?4 D7 zinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P># b3 E* X7 y0 K! H: q4 p, x7 r
<P><FONT color=#0000ff>/* read result of initialization */ , L9 L, L! H, p& G+ D" ~; X
errorcode = graphresult();   J! |- E. }+ b* k" H, Q
if (errorcode != grOk) /* an error occurred */
0 J6 p3 U' ^% r$ [$ ?+ K$ e6 n{
' I! C0 K  u6 ?5 {" ^printf("Graphics error: %s\n", grapherrormsg(errorcode));
" u7 N6 `! Y% u8 S0 ~printf("Press any key to halt:"); , i' @3 r, O4 c# _0 ~* W% Y1 ^
getch(); ; `+ U$ ]. P- W- h
exit(1); /* terminate with an error code */
: {/ b6 Y2 E$ d# i) I- P0 E$ u8 c} </FONT></P>* E; y; U4 p/ [6 ]; T9 u2 ]1 @
<P><FONT color=#0000ff>midx = getmaxx() / 2; 5 t! t' G. x4 V
midy = getmaxy() / 2; </FONT></P>6 a, c( \; `3 S# c
<P><FONT color=#0000ff>/* loop through text justifications */
% P0 F# @( n" \9 ]4 Tfor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
1 l" f* Z5 r4 b/ Bfor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++) $ ~5 Y! Z$ o0 n
{ : v( x: t" y8 E1 R9 }
cleardevice();
) _! z+ P/ n& z+ o/* set the text justification */
+ m) |0 g: ?& [settextjustify(hj, vj); </FONT></P>
# U- L" T5 C& N: L<P><FONT color=#0000ff>/* create a message string */
& G' B7 f, K, v# `. Psprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
# E6 p9 `" B/ C0 O8 O9 s5 z<P><FONT color=#0000ff>/* create cross hairs on the screen */
. B/ Y5 w+ d3 z8 R. X5 I" u1 qxat(midx, midy); </FONT></P>( R6 {1 c* O/ b( N
<P><FONT color=#0000ff>/* output the message */   I8 E. A: b/ J+ [2 U
outtextxy(midx, midy, msg);
2 S2 Y! Y1 S2 G8 V: ~& k9 Kgetch(); " j9 b. V1 A. b
} </FONT></P># Q) ~) Z5 \4 Z; F% S$ u8 a
<P><FONT color=#0000ff>/* clean up */   G+ h  m- y" L# k9 r6 x2 ~% w% s
closegraph(); 0 R) c5 m: Y( q: _
return 0;
" L& V/ w9 v  l- J! i, ]7 Z: I, M- `' V} </FONT></P>9 [. r1 Q" x. x/ J% }. H+ |& a
<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
% |/ ^; K& ~0 Xvoid xat(int x, int y)
9 a9 Q+ G8 J. r+ a+ y{
) A! K6 u8 Z1 Q; p( }' J; o% d1 ~line(x-4, y, x+4, y);
( @# B8 J1 R8 \1 `line(x, y-4, x, y+4);
  F4 q5 t* u# }& n& f} </FONT>) Y0 y& }0 d  P, L2 _: O, F
9 ~: S  u3 X' E3 w. k
</P>3 u: M/ M3 Z+ U. b( I0 d
<P><FONT color=#ff0000>函数名: settextstyle </FONT>& V4 ?- b2 m" K# z  _
功 能: 为图形输出设置当前的文本属性 . p& ]" E. r7 J+ G
用 法: void far settextstyle (int font, int direction, char size); ! ~! F7 }0 n0 O+ x
程序例: </P>
* l8 |" V3 E' K4 z" P2 I. K<P><FONT color=#0000ff>#include <GRAPHICS.H>
! q* n7 ~+ K  T#include <STDLIB.H>
7 X3 k$ O7 E+ o' R, ~" }6 Z1 d- a#include <STDIO.H>
* H; e7 [! L: u' p: t# }#include <CONIO.H></FONT></P>2 U) Q6 R, M3 q, d; w" O
<P><FONT color=#0000ff>/* the names of the text styles supported */ * X$ d  g+ d+ U9 ^2 e  l
char *fname[] = { "DEFAULT font",
( G) r- R% q' h% y% h" K- |' _"TRIPLEX font",
% X4 t2 {) {3 N8 y+ P"SMALL font", / k3 u% P/ h7 R9 o
"SANS SERIF font",
+ }( {) W, \! L+ |* _"GOTHIC font" 6 ^* [7 i$ t6 x  I. o- j
}; </FONT></P>
+ o. W) n% P0 i) F' X<P><FONT color=#0000ff>int main(void)
4 D/ m$ ]( L. X0 D{
* a& L/ b: b  L% C3 f4 g6 j/* request auto detection */ / m- g8 f: E' O! ]
int gdriver = DETECT, gmode, errorcode;
$ H( ]! @# D- g: P  U2 qint style, midx, midy;
$ T* i+ Y) T+ h3 e  i/ gint size = 1; </FONT></P>- _/ g5 l  r5 P2 {' z
<P><FONT color=#0000ff>/* initialize graphics and local variables */   Z5 l1 I( f& N, W+ u
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>/ \/ _& H, }- F. H& A  F3 Z
<P><FONT color=#0000ff>/* read result of initialization */
) ]3 P, O- a- ]/ A  C+ z' lerrorcode = graphresult();
2 B- Z! O8 F' |5 f( Jif (errorcode != grOk) /* an error occurred */ 9 r$ r2 p. k7 s6 @
{ ' Z# o% t0 L8 e1 w- w
printf("Graphics error: %s\n", grapherrormsg(errorcode)); / n: o# h- W! ?% j
printf("Press any key to halt:");
& ~  U1 V' E* N) k; ogetch(); : E4 o3 `! @* \4 B6 r( B; o$ k
exit(1); /* terminate with an error code */
0 O, E. u7 ]8 Q7 }} </FONT></P>
9 p6 s: s. Y/ d2 l/ L/ k1 o% [<P><FONT color=#0000ff>midx = getmaxx() / 2;
6 ~9 d7 z$ N: Dmidy = getmaxy() / 2; </FONT></P>, Q; Y- u; b( U  v
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
1 j+ C: U5 A. `8 Z0 `: v' S- J, J<P><FONT color=#0000ff>/* loop through the available text styles */
' R6 H" a5 e0 q- [/ ~% Zfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 5 W' @0 X) F& H& M
{
- o* X8 E8 I3 I- t9 g# z4 z% Ocleardevice(); # g1 M9 [) \! o
if (style == TRIPLEX_FONT)
3 w; k/ L$ u1 r3 D0 G% vsize = 4; </FONT></P>7 z8 y/ o8 J; L3 D. K$ ]3 h  T
<P><FONT color=#0000ff>/* select the text style */
9 c. y$ l. G" p) x7 V' V$ G, ysettextstyle(style, HORIZ_DIR, size); </FONT></P>
9 W; Q# Z: z2 a3 b- m9 Q  b& _<P><FONT color=#0000ff>/* output a message */ " p( S/ `" O( Y, l9 @1 L
outtextxy(midx, midy, fname[style]);
/ F( ~/ v" j1 r, q3 v% Sgetch(); ) i- t; a0 s! R% x/ C$ I
} </FONT></P>  q+ l( v0 h( j9 m
<P><FONT color=#0000ff>/* clean up */
4 o& f* w- {: L  l: y) p% a4 j5 r/ ?closegraph(); - ]- l" N- Q) n+ K& N$ u5 G
return 0; 6 W, r/ t# u% v0 T! T. `+ \
} " ^. o" h) u$ X5 Z( O3 V
</FONT>
: s1 [8 e1 m# ~</P>8 x* D4 F+ t6 k  Y* U
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
/ |* V8 L% }2 R! r功 能: 为图形输出设置当前的文本属性 4 x+ F3 |1 R6 i; h, A6 e
用 法: void far settextstyle (int font, int direction, char size); 4 J5 q3 y+ K% [% o. _7 e# Y) [
程序例: </P>/ @" R7 s4 g3 t6 I0 p( P  ]# L
<P><FONT color=#0000ff>#include <GRAPHICS.H>& x3 D0 v7 O7 @( E  m2 v
#include <STDLIB.H>3 x! k+ p$ u) }& r' D% B* Q% ^. R
#include <STDIO.H>
0 z  {( @/ [2 E  p1 h2 f#include <CONIO.H></FONT></P>) l& A4 g5 j* S; c
<P><FONT color=#0000ff>/* the names of the text styles supported */
9 @, u3 W+ g6 _char *fname[] = { "DEFAULT font",
0 d! \2 ~% A! y"TRIPLEX font",
3 ]( J2 S) r/ y"SMALL font", ) ^, B# P# I- O0 e' j
"SANS SERIF font", , T5 p& l8 f, q
"GOTHIC font"
. w7 _# R5 {8 E}; </FONT></P>+ f3 Q9 L, y7 d  `8 U' U* D, Z- _' {
<P><FONT color=#0000ff>int main(void) + O* ^" R( V, M2 [5 ?3 p2 G
{
: s4 L1 V$ |$ X  n) @% C& S/* request auto detection */ % H4 S6 f1 q, t9 L1 a
int gdriver = DETECT, gmode, errorcode;
- N: u2 T8 m! e" `  Aint style, midx, midy; ' b  ?& V; F8 M) M3 R7 C4 U
int size = 1; </FONT></P>' K. x' S7 A* g1 Y9 E; F! p
<P><FONT color=#0000ff>/* initialize graphics and local variables */ / T: j' o& `) @# ^4 o
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 Y6 a" U6 O3 @6 ^
<P><FONT color=#0000ff>/* read result of initialization */
- H! P! o5 B* q7 D6 Eerrorcode = graphresult(); ) i" L( Z1 d4 I* T0 w) ~! `
if (errorcode != grOk) /* an error occurred */ 7 O% d: |( @: S
{ $ V2 d. x+ E1 y
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ; t4 Y  }, M. z. [" E9 n% B& e
printf("Press any key to halt:");
/ X* N5 K# [0 N. x9 @. I! _6 lgetch(); 5 y  F* f3 D+ C+ v/ _
exit(1); /* terminate with an error code */
8 ^& y% l8 u* k: o} </FONT></P>
; ~3 n+ r4 h& ~5 U* G5 N<P><FONT color=#0000ff>midx = getmaxx() / 2; , h7 U2 r' _2 `& Z6 W
midy = getmaxy() / 2; </FONT></P>: D. M8 K9 }" v) }: P% n7 C
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
. e" h# v+ B" g; o<P><FONT color=#0000ff>/* loop through the available text styles */ . h; n- g& r! L- b3 @$ u$ [
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
1 f8 J* F6 w# _8 E; W{
" Y& y: L# K0 w6 n# V$ Ecleardevice(); $ R+ f' P! l& N( `' V0 C0 d5 r& ^( `
if (style == TRIPLEX_FONT) - [2 S' X1 P+ k6 Q% X
size = 4; </FONT></P>/ g3 O  f: v# R% x. |, z. O  F, g
<P><FONT color=#0000ff>/* select the text style */ # v7 t6 S) O- P" |1 x9 f
settextstyle(style, HORIZ_DIR, size); </FONT></P># v: Z0 _# U0 R8 {5 ~0 x# r! P1 O* E' r
<P><FONT color=#0000ff>/* output a message */
' |; f8 L2 {0 routtextxy(midx, midy, fname[style]); 9 K+ y, C, ?& }) K8 y9 v5 G
getch(); . }' O6 u. ]7 e$ n% n
} </FONT></P>
! V% O; A. ?4 b1 u<P><FONT color=#0000ff>/* clean up */ * x) |* t7 J9 y/ W
closegraph(); 3 S, J$ b% G  l8 }1 }4 ^1 n, U, I
return 0;
4 q; N+ E6 ^( A# L9 o: S} </FONT>
. g( p, k1 p" t9 D# `/ n* u0 l6 K' q( K" b; ]+ b
</P>
1 e0 z9 _+ }: \, X<P><FONT color=#ff0000>函数名: settime </FONT>
" Q& H+ i9 V; ^- v6 R" |功 能: 设置系统时间 9 G! r& ?% S% R2 l1 j0 e2 G, J$ Y
用 法: void settime(struct time *timep); & y% o0 Z) ~4 I2 B" \7 `* J
程序例: </P>3 }; s$ f$ U, r* \
<P><FONT color=#0000ff>#include <STDIO.H>
4 o, d5 x5 _6 m3 N#include <DOS.H></FONT></P>3 a  o$ |( s3 O
<P><FONT color=#0000ff>int main(void)   \6 x7 \- `7 H% d
{ 6 T. L) t* D( b* K' e" ^  I
struct time t; </FONT></P>5 Y2 g6 i% P/ _0 q* {$ F: _( v6 e
<P><FONT color=#0000ff>gettime(&amp;t);
- Y; ?( r& f) Y/ Q+ a8 O, Nprintf("The current minute is: %d\n", t.ti_min); % z. v- f' r* V
printf("The current hour is: %d\n", t.ti_hour); / Z, T2 u3 J% v" R; \$ `+ @2 p3 O
printf("The current hundredth of a second is: %d\n", t.ti_hund); ( K  v2 S1 m0 H! _! m3 z, h
printf("The current second is: %d\n", t.ti_sec); </FONT></P>& u& t2 b8 k; }8 ?& B7 }+ B7 l
<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */ 9 j0 s+ U! W3 `
t.ti_min++;
8 t) q0 \  }: f3 k, Y# W0 _5 \" Ysettime(&amp;t); </FONT></P>- P, J+ D5 V1 s; X- E/ u7 v
<P><FONT color=#0000ff>return 0;
% L+ H9 a9 H$ i# z} </FONT>
, o& @8 @9 A  ?* x! \( z5 Y8 t7 g3 ^# c4 [  k# O# k
</P>
7 w. y. ~4 Z- R% D( b0 t/ G$ E<P><FONT color=#ff0000>函数名: setusercharsize </FONT>" h4 H5 S% i- u6 }$ l
功 能: 为矢量字体改变字符宽度和高度
* s1 E1 ?5 B$ Y7 L* b用 法: void far setusercharsize(int multx, int dirx, int multy, int diry); 5 [9 }& X; b, R# W9 q
程序例: </P>
4 S7 L7 i8 M% |. d4 Z( n<P><FONT color=#0000ff>#include <GRAPHICS.H>8 z! C" a  o+ I; v
#include <STDLIB.H>2 ~" a2 r' D! |$ M) b
#include <STDIO.H>
8 A0 d+ a0 F; B8 B# G# Z#include <CONIO.H></FONT></P>- b3 a; @; c1 h' ?2 a+ \
<P><FONT color=#0000ff>int main(void)
0 |/ y* A, @1 h" A{ " Q! ~5 \1 ?$ J) y+ F1 [
/* request autodetection */ * ~; b1 r5 E# {" C
int gdriver = DETECT, gmode, errorcode; </FONT></P>
' |9 \+ H* a# l/ P) [, Q8 I<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 `3 z& D2 i2 W" i# oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" p9 l. ?' A3 K" F<P><FONT color=#0000ff>/* read result of initialization */ 2 S5 z& N- @/ Q1 D/ Q: O
errorcode = graphresult();
( v3 Z% z2 h* `9 tif (errorcode != grOk) /* an error occurred */
* Y( b8 c/ k1 e' a! n{ 1 E9 N& u( D2 n+ U8 q. D! i6 _$ x
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . q% \2 C/ o4 c# a
printf("Press any key to halt:"); 6 [5 K- |3 V4 ~+ |6 N
getch();
; x" T  x4 _* x  \exit(1); /* terminate with an error code */
6 K0 a; i- n% |, I, ^7 C} </FONT></P>
, V; r/ I9 M" i' m<P><FONT color=#0000ff>/* select a text style */ 0 w5 A3 K1 ]! W
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
" ~8 B9 M: B) j* G3 U/ q, ]8 E<P><FONT color=#0000ff>/* move to the text starting position */ / f* p" S; c8 m9 e( {6 E/ \
moveto(0, getmaxy() / 2); </FONT></P>3 t+ G; _+ U& Y1 \$ G
<P><FONT color=#0000ff>/* output some normal text */
) _* B; x" w$ s: \outtext("Norm "); </FONT></P>
% D2 t0 C7 j2 Y' d4 S<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ & k! n1 E, R, j8 K, j8 d
setusercharsize(1, 3, 1, 1);
: _7 i6 v0 F9 j+ m( g" o5 Qouttext("Short "); </FONT></P>5 K( l4 h; N6 R" i! B0 E5 t/ y8 y8 s
<P><FONT color=#0000ff>/* make the text 3 times normal width */
. z& o6 R4 P/ X( d( [setusercharsize(3, 1, 1, 1);
, l; k2 [9 x" x; e1 L9 Routtext("Wide"); </FONT></P>$ K& Z+ E4 d' g. I0 p: X  }! v
<P><FONT color=#0000ff>/* clean up */ ! a# k1 O" m) a+ V0 O7 n
getch();
1 [2 v% e& L. A# l6 Q' ]% pclosegraph(); # n' Y1 a9 ^  n, ~9 z) e
return 0;
- m' ^/ q- x: _6 b} </FONT>
6 Q* g5 r* E4 f5 @8 Q# N" _</P>( s/ N. Q2 Z6 @# X; a8 V. y8 N
<P><FONT color=#ff0000>函数名: setvbuf </FONT>9 s. g  Z2 |& R1 U
功 能: 把缓冲区与流相关
1 Q2 [- z$ m- j3 A. I  l' c用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
( p( ^  X5 P: d, P! e程序例: </P>4 m1 H! i! Z  m
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>8 {6 _0 O8 c4 j5 C4 b* q" P
<P><FONT color=#0000ff>int main(void)
" ^* b& s6 |6 z: O{
8 m6 }! A4 ^9 K  S) W! oFILE *input, *output; 5 i$ z% Q; }- \+ D7 s( y$ H/ v6 j
char bufr[512]; </FONT></P>7 t% {! ^8 e6 z# J$ G; F1 A% h8 b
<P><FONT color=#0000ff>input = fopen("file.in", "r+b"); / W8 h' n( Y' ^0 O8 A
output = fopen("file.out", "w"); </FONT></P>% Y0 r( M# x9 W
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,
# k* {/ P! x; r" cusing our own character buffer */   P+ ^4 e' n1 j; |& y! r: ~
if (setvbuf(input, bufr, _IOFBF, 512) != 0)
8 X# X& R: b9 D5 B! }, G# Gprintf("failed to set up buffer for input file\n");
  _( |$ `! n% V$ q  Gelse % |* u  y$ u  M4 D, i
printf("buffer set up for input file\n"); </FONT></P>
2 r4 V, ~0 i7 ^1 |<P><FONT color=#0000ff>/* set up output stream for line buffering using space that ( B0 ~) q1 s! {6 G; J5 w
will be obtained through an indirect call to malloc */ 8 k4 B, [' ^8 V9 U7 p; l. t1 L/ J5 N
if (setvbuf(output, NULL, _IOLBF, 132) != 0) " b1 F; U4 A2 ^
printf("failed to set up buffer for output file\n");
; w! f; |  H( q& O# M: [else
! S: Q6 E' W/ ^- Nprintf("buffer set up for output file\n"); </FONT></P>
2 ]9 u: I, x' U. i1 Y+ G<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
) k/ S# P# H9 c2 h; i- t( N<P><FONT color=#0000ff>/* close files */
' F  r# \% c( a% K' }  S% {fclose(input); & N& M9 @/ `4 |
fclose(output);
7 U  [: f/ E3 Y+ D$ K3 ireturn 0; # C# D" e! H3 x& j; M/ ]
}
9 H4 c1 A% n# J2 f# s# G9 J</FONT># M$ ?. Z+ O, s  k
* F  s+ L5 v- e1 ~( u! P6 `0 o
</P>  m5 c# O- A7 \
<P><FONT color=#ff0000>函数名: setvect </FONT>. j$ b$ Y, n6 E% j- V$ _! l2 A- ?
功 能: 设置中断矢量入口 ! l5 L. ~% {* [
用 法: void setvect(int intr_num, void interrupt(*isr)()); 2 N/ Q2 h% h; y( n
程序例: </P>
9 p. {0 C0 K& H) @<P><FONT color=#0000ff>/***NOTE:
1 J( T% B; Z/ x6 U7 pThis is an interrupt service routine. You can NOT compile this " @4 y/ R$ Z0 S+ C' Q
program with Test Stack Overflow turned on and get an executable
0 T+ |8 Q8 @# Zfile which will operate correctly. */ </FONT></P>
& k# H7 `# K: j; h1 K<P><FONT color=#0000ff>#include <STDIO.H>
' `& v8 Z) c* ~5 J5 [  q#include <DOS.H>
" [  E5 e2 D- K6 b5 B#include <CONIO.H></FONT></P>' ^/ T. \' q% U1 Z1 t; m* y
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>& E, A3 a& o& m1 h+ Z
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>& U. g1 q, k- d5 Y6 S5 R7 P2 ?
<P><FONT color=#0000ff>int count=0; </FONT></P>6 x/ M2 C0 o0 [9 ~% x* t
<P><FONT color=#0000ff>void interrupt handler(void) & o$ ?) b  D3 c/ H0 W# x6 v+ H; O
{ , q; m- ~3 f/ G
/* increase the global counter */ + N) v% k8 m- T: K) |0 ?6 [( a& P
count++; </FONT></P>
# o* f( k; m5 ~7 ^! ?2 {' p2 v5 M<P><FONT color=#0000ff>/* call the old routine */
  O$ |* o. |6 ~" |9 F# |% J6 C% P1 foldhandler(); # h/ E2 }  m) H% o% @" V$ U
} </FONT></P>3 L/ X8 R# E4 T" m9 y6 W
<P><FONT color=#0000ff>int main(void)
4 K3 u1 s: ^: {. K2 D! @" [{
0 u1 W1 q/ O4 |4 m/* save the old interrupt vector */ : E+ L" R1 o7 Y) W, [% e% r. B
oldhandler = getvect(INTR); </FONT></P>+ J3 a) }' s& o: b/ {
<P><FONT color=#0000ff>/* install the new interrupt handler */ * @2 b* n& N" o/ Q+ c6 h
setvect(INTR, handler); </FONT></P>
. Z) h, t; [5 U1 {! ?5 a<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
! A: f! A6 K6 L- N) B# uwhile (count &lt; 20)
- O: _) P+ t/ R) q% ]; Wprintf("count is %d\n",count); </FONT></P>
% T5 @, l! ~# o) N* j7 N, e<P><FONT color=#0000ff>/* reset the old interrupt handler */ 0 z2 K' z+ _' X! E+ b- j; g2 B
setvect(INTR, oldhandler); </FONT></P>' L  N# \3 ^! x/ K( Y
<P><FONT color=#0000ff>return 0; & E2 @. b* K( o; L
}
6 P+ }6 S; p) d8 ~5 z</FONT>  A4 i! ~. G1 @. D( X* S: L
</P>9 n' B+ ~0 n' N! u+ |; E& B
<P><FONT color=#ff0000>函数名: setverify </FONT>
' Q- c4 y  Q$ f# Z7 d# K) W功 能: 设置验证状态 4 x& M, N( [1 ]* h% H
用 法: void setverify(int value);
5 q% L5 E' A+ t7 O& F程序例: </P>
4 e. [, s0 c' T) E  k<P><FONT color=#0000ff>#include <STDIO.H>
8 _' R" a7 S" t" y' |5 M5 T6 |#include <CONIO.H>
, B4 i1 s4 B. L' [# `3 M6 L#include <DOS.H></FONT></P>
9 c2 w. J0 f( R1 E( A<P><FONT color=#0000ff>int main(void) % ]* t  `/ {% i' k, [+ `: D
{
: o* |" P" E' Aint verify_flag; </FONT></P>- z9 y+ J: t1 M3 R0 }( C- P
<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
# N) s! g; i/ {2 H4 Gprintf("Enter 1 to set verify flag on\n"); </FONT></P>
+ k3 W- [7 {8 }- ]  \! l0 Z( m( K! w<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>5 Z; m! J8 x$ A
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>
& D7 e$ B( @, u, l9 B1 R<P><FONT color=#0000ff>if (getverify()) . z2 l3 x7 _2 f
printf("DOS verify flag is on\n"); 1 T5 }9 P8 \# d: f/ O
else
$ s8 M  n' m* e8 N/ uprintf("DOS verify flag is off\n"); </FONT></P>8 i8 p! c! U  m
<P><FONT color=#0000ff>return 0;
2 u) L$ {0 I1 b}
0 p: t2 b" Z7 N/ {$ _* W: v- z8 ?<FONT color=#ff0000>
  y) H, i" F& O8 u' _8 Q</FONT></FONT></P>% z/ z4 d+ c0 h" a' _
<P><FONT color=#ff0000>函数名: setviewport </FONT>' p; T% _" Q" ?/ `
功 能: 为图形输出设置当前视口 ) B* E) k- v. d& i
用 法: void far setviewport(int left, int top, int right,
" [0 z7 B" ^7 s. m# H# Tint bottom, int clipflag); * c% Y5 |6 [! i$ t2 z
程序例: </P>$ _8 `" D. r- A8 d' f2 K& X0 c# Q
<P><FONT color=#0000ff>#include <GRAPHICS.H>" ?- x- t5 N0 U" d% Z  i
#include <STDLIB.H>1 l) T' h! H, F! j8 t
#include <STDIO.H>5 {# @, g4 u1 u; ?! C. D2 i( p
#include <CONIO.H></FONT></P>
: g/ J; q% k- G6 x4 n3 l. `<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>0 a; t2 P1 c& \" Z7 S; B- y4 c
<P><FONT color=#0000ff>int main(void)
  M5 A* R0 a2 f$ Q4 c- F{ " Q. }  Y% Y# }& t
/* request auto detection */ 2 w& }3 _: B6 S$ V, X. k
int gdriver = DETECT, gmode, errorcode; </FONT></P>
. T0 r( i( w- f7 Q  Q3 S<P><FONT color=#0000ff>/* initialize graphics and local variables */
( T$ R' J5 v- A& w/ K: V7 A8 Ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 c, e: x$ W  _( W. B8 N9 Y<P><FONT color=#0000ff>/* read result of initialization */
3 v+ @  r5 V6 v1 ?9 werrorcode = graphresult();
5 j5 P1 [/ w4 t5 e9 }( T+ yif (errorcode != grOk) /* an error occurred */
# A* u- A& V" |# J# }% e* p% J# ~{ 2 Z" h& q0 C3 E  @$ O
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 a7 J5 V( w9 sprintf("Press any key to halt:"); ( b# [1 q* H/ p) l, ~5 x
getch(); 8 t+ A8 ?: _, P: X2 w; F
exit(1); /* terminate with an error code */ ( L+ e' U) [9 {! O, [; j: ]. M1 d+ ?
} </FONT></P>0 d. ^( g0 R' e0 ?
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
  u# h: J/ l! @/ T<P><FONT color=#0000ff>/* message in default full-screen viewport */
& S# M5 ?  W+ @7 F9 s2 Wouttextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
$ F: Z7 y0 Z1 u- n: c/ R$ c- z<P><FONT color=#0000ff>/* create a smaller viewport */ : M6 `' C- Z- h! f- N
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
) A8 t* ~( v( L. t5 Q* d- \<P><FONT color=#0000ff>/* display some text */
& L# X$ m8 K& K3 A9 I$ J+ Routtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
8 N! k1 d5 [0 ^9 d1 }<P><FONT color=#0000ff>/* clean up */ % N; I' s/ Y% \; N& `# ]- n# P
getch();
8 r! j' c" a. S5 f1 d# xclosegraph();
8 e) v" S4 S9 v! E* l6 O4 qreturn 0;
2 A+ K3 Z! G9 X8 w# D  K}
, G3 o# T8 A' U& ^</FONT>
4 D2 b: F0 ~0 a; }; v, T</P>
& g3 W# M$ U: A' o4 ]; M+ i! T, o<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
  |/ T4 _( A1 A! H$ J功 能: 设置可见图形页号 ! t) M$ _# [/ h$ c* C. f
用 法: void far setvisualpage(int pagenum); 4 `4 t0 V. E( S' V0 `  X0 A
程序例: </P>  e2 @$ r; d( J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
' w) A% ]; `* I6 \. y: c#include <STDLIB.H>
0 s2 e8 J# @- p. v+ W#include <STDIO.H>
9 y" f. e3 C. ~& T$ w6 W* c#include <CONIO.H></FONT></P>
  k( C" F3 W5 Z<P><FONT color=#0000ff>int main(void)
5 N/ H& p7 S, U$ O+ t{ ! G$ p% }% D: r5 d2 {/ u
/* select a driver and mode that supports */
4 q" l2 D/ s) t9 s5 L; x! l! f/* multiple pages. */
3 r, e& O# B: L' @+ C* kint gdriver = EGA, gmode = EGAHI, errorcode;
! c( o/ M, \8 E! i0 a  Iint x, y, ht; </FONT></P>5 q! d- W$ F1 k! x& M( ?
<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ R  ~, `1 m; u0 a; k9 C, yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' j- k0 q1 t% q' K2 h' @. |' `$ {<P><FONT color=#0000ff>/* read result of initialization */
- u4 E  }& Y: gerrorcode = graphresult(); # U" A0 m# B* |0 K. q% B6 |
if (errorcode != grOk) /* an error occurred */
) m( ]2 Z5 ^! M( X* I{ # g4 a1 ]# l2 b2 l! r# e5 i
printf("Graphics error: %s\n", grapherrormsg(errorcode));
% R0 @9 h5 K6 Q% @# |printf("Press any key to halt:");
4 m, [5 s% S2 Q0 L/ N7 w" Z$ kgetch();
: u' v* g. |" Y: f0 z7 s) Qexit(1); /* terminate with an error code */ 7 H; S0 ^' u# X8 p& S& f# K* u( }
} </FONT></P>
1 T2 M" ^; m. c6 ~- c. _<P><FONT color=#0000ff>x = getmaxx() / 2;
' E, n( t3 s1 j% r. o  D" }y = getmaxy() / 2;
# {+ o( z1 w3 iht = textheight("W"); </FONT></P>2 V' @# {# I) p6 X/ l8 D4 j1 U2 g1 B
<P><FONT color=#0000ff>/* select the off screen page for drawing */
) [8 o3 q, A. g  U+ [" B7 ?. l: |setactivepage(1); </FONT></P>
; z9 _8 N( a5 g& _3 `0 g: F<P><FONT color=#0000ff>/* draw a line on page #1 */ % B2 L8 W! g3 q/ @# C7 [+ V. r9 w9 C
line(0, 0, getmaxx(), getmaxy()); </FONT></P>5 y3 n: a  F0 M
<P><FONT color=#0000ff>/* output a message on page #1 */
8 v+ |; M' b2 K  _+ \settextjustify(CENTER_TEXT, CENTER_TEXT); ) {" Y+ y( G* @: \, ?: p5 P
outtextxy(x, y, "This is page #1:");
1 a  M3 h  o. b9 I8 X9 Iouttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>. I$ {9 l# p4 }" n1 x0 e
<P><FONT color=#0000ff>/* select drawing to page #0 */ + J% m8 ]: W( j/ s
setactivepage(0); </FONT></P>
0 [& k5 j/ K: Q! F5 w( u: s0 P2 h<P><FONT color=#0000ff>/* output a message on page #0 */ 8 p: N. G# i$ A" K" E# `& p3 R
outtextxy(x, y, "This is page #0."); # G* m2 U& r& D
outtextxy(x, y+ht, "Press any key to view page #1:"); ( L! n! P8 r0 |7 [1 X8 V
getch(); </FONT></P>
( U1 f8 f% ?! i% Z% H' u<P><FONT color=#0000ff>/* select page #1 as the visible page */
: j1 i8 a8 n6 y' L7 z2 a! e5 Zsetvisualpage(1); </FONT></P>' B; [5 N6 z' A2 \! y$ R" F* V4 Y
<P><FONT color=#0000ff>/* clean up */
" @$ D: j: _' Q6 C1 Ugetch(); " j/ i8 I4 c( z  |4 d2 N6 _
closegraph();
! P& ~, L% W6 z+ ]. y9 M) ^, r; Mreturn 0; 4 h9 a2 t  E% F6 J- R* Z
} </FONT>" |6 u* j% E  d7 g* ^
) n0 a) n( H# W, j6 t
</P>
& Q4 s5 J9 l) i9 Q4 R<P><FONT color=#ff0000>函数名: setwritemode </FONT>9 u: V  D5 N( |( F8 b
功 能: 设置图形方式下画线的输出模式 6 K$ z* j$ H+ m4 D" v) `0 ?, l9 x
用 法: void far setwritemode(int mode); 6 T1 ]/ e$ V- u
程序例: </P>! i* P; H" a6 A. T
<P><FONT color=#0000ff>#include <GRAPHICS.H>
" H* ]  n& D( Z) L3 g$ m#include <STDLIB.H>
3 Z" C8 D4 ~( k  W1 C#include <STDIO.H>
0 }/ u7 b; k( S- p2 i$ |#include <CONIO.H></FONT></P>( D8 a( a" ~  H4 ^2 q. x
<P><FONT color=#0000ff>int main()
# B2 H2 B1 i! l  w" o. _{
3 G" r, ?7 g, k/* request auto detection */ 0 \  }: l, N$ T9 V
int gdriver = DETECT, gmode, errorcode; 0 k# U1 M8 g! |
int xmax, ymax; </FONT></P>
7 k( S$ L: w9 @( Z<P><FONT color=#0000ff>/* initialize graphics and local variables */ 9 Z. k8 Y  ^; q( a! D% M1 N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. ?! G* X7 P- ~
<P><FONT color=#0000ff>/* read result of initialization */ ) g5 Z: p" _' [- e# w0 j
errorcode = graphresult();
& h! {0 S4 M5 u4 s# e9 L+ ~  N% Aif (errorcode != grOk) /* an error occurred */ : Q- F" g- s! h  s2 V2 b0 m
{
6 `6 W5 C$ W( r- u$ T; b1 mprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : S5 o# C5 N4 I6 T! u5 f. P( |  L7 G: y# `
printf("Press any key to halt:");
# D' G1 X/ i! t9 ?" ugetch();
/ |" g+ \6 u% _6 P& qexit(1); /* terminate with an error code */
, ]8 d3 g* ?7 M7 H! W; @" c} </FONT></P>
6 d6 A- }! I% @+ @<P><FONT color=#0000ff>xmax = getmaxx();
. [* z! P+ v8 Q* Rymax = getmaxy(); </FONT></P>
$ g. r8 I% h) C/ ?1 D; F<P><FONT color=#0000ff>/* select XOR drawing mode */
$ J8 T9 d( T& ksetwritemode(XOR_PUT); </FONT></P>
4 a! p2 V& x2 d; O<P><FONT color=#0000ff>/* draw a line */ : a) W  ?8 W/ \8 g7 l0 C$ y
line(0, 0, xmax, ymax); ! Z$ D3 [4 {; d# v9 p/ ?
getch(); </FONT></P>1 p3 Y! s8 {- }2 \$ M/ _5 Z2 I1 O
<P><FONT color=#0000ff>/* erase the line by drawing over it */ " }3 \' d! o% v
line(0, 0, xmax, ymax); 4 E3 z( g4 p& ?/ k4 }
getch(); </FONT></P>
( f& `$ }/ A$ d% t<P><FONT color=#0000ff>/* select overwrite drawing mode */
' P! P0 q# I; H3 p, n9 s+ \setwritemode(COPY_PUT); </FONT></P>% N8 T: `* ^+ T+ ?5 H5 v
<P><FONT color=#0000ff>/* draw a line */
' Y' k+ k, f; H- c) iline(0, 0, xmax, ymax); </FONT></P>
5 H0 }: A" O0 D6 P3 W- u$ _<P><FONT color=#0000ff>/* clean up */
: K( I' P( J* Q0 b9 Jgetch(); & a* E' l5 C8 l1 a: k5 y# Y: r
closegraph();   y  H, c( }& m0 @/ B
return 0;
8 S( ?( {- h3 x" A' k} 7 C% D8 d, C4 U( r' X2 l+ C
</FONT>
  {, w, c( e) i6 R/ e</P>2 F) }6 I5 h& ^' M# X7 w/ e
<P><FONT color=#ff0000>函数名: signal</FONT> % X* H- Q- @5 j. P& L' ?6 w
功 能: 设置某一信号的对应动作
7 v% s) u) c5 Q9 M* K5 d( `用 法: int signal(int sig, sigfun fname); 3 ~' W1 p5 F8 g/ R0 B
程序例: </P>: Y+ B" `; J8 ]) ~& |
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, ( J: ^- f4 P5 E3 v9 ?. Q5 O5 T7 P
catches an integer overflow condition, makes an adjustment
) n) w2 D1 b& v% tto AX register, and returns. This example program MAY cause 9 t- p7 X; F1 \
your computer to crash, and will produce runtime errors / C3 m4 e% L( x; Y
depending on which memory model is used. , r' V! B% J7 y4 h, N* v
*/ </FONT></P>! C$ y  ~- A+ ?* w' K! t
<P><FONT color=#0000ff>#pragma inline
* _% y6 \- J- \) ~7 W9 B#include <STDIO.H>
% N( K% ?: ^( G: E* S9 G#include <SIGNAL.H></FONT></P>0 Q, f: x- \; D3 b' J: c$ w* U: X
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
1 O$ h( m. P! a: b  J{ - A8 z+ x, p1 Y. O9 s0 t' }% x. F1 c
printf("Caught it!\n"); / \7 F! m- ~3 C: }) s3 F
*(reglist + 8) = 3; /* make return AX = 3 */
$ ^+ l3 H2 }. E4 S, f} </FONT></P>
& O/ ]9 |" a! N<P><FONT color=#0000ff>int main(void)
5 Z) \2 [* E5 `7 n{ . K9 a- I. |: P8 {2 z: p+ {: M' j
signal(SIGFPE, Catcher); 1 N; }) ^# [" j# L9 i2 I- c$ T
asm mov ax,07FFFH /* AX = 32767 */ ) X5 _7 I* z- Y7 h! K1 q' X) J
asm inc ax /* cause overflow */
$ D* d' j3 |3 Q9 {. yasm into /* activate handler */ </FONT></P>
' i* D- P$ T( i1 k; x3 B<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, 5 M- }5 V' o! Z7 J; I8 M
there would have been another exception when the next 'into' 6 `4 C6 s, A; ^6 C) [" }$ \$ f3 _/ S# F
was executed after the 'dec' instruction. */ 1 W- ?: e  ^- Z# V* m2 @
asm dec ax /* no overflow now */
* @+ }: M+ E! o& v2 Z5 d0 V7 Lasm into /* doesn't activate */
. ?) R5 c) Q$ }return 0;
) P, h' K  h* d. |4 u} 9 b; n, ~% I7 c
( A7 r: S' ?7 @, V1 P, y+ n
  U7 I* x3 q4 u
</FONT></P>7 M2 ]- j  m- ^. j- I! T6 }
<P><FONT color=#ff0000>函数名: sin </FONT>( H3 @$ r# z3 h% ^1 {5 P9 A: S
功 能: 正弦函数 ; ^6 `" L: K4 a/ S  a
用 法: double sin(double x);
2 u' V) _& \# @7 b9 K  T程序例: </P>$ b' v; [" j8 u# f: j. Q
<P><FONT color=#0000ff>#include <STDIO.H>( r0 ]8 l  S$ a
#include <MATH.H></FONT></P>& x: o- y" G! U8 J' D6 k
<P><FONT color=#0000ff>int main(void) 3 d' [3 @8 ~9 ^! y" j3 \
{
' m0 {' A+ r! cdouble result, x = 0.5; </FONT></P>
, Q- _0 v# j- v$ A' C9 H" w: y% E- c<P><FONT color=#0000ff>result = sin(x);
/ C& `" Q8 q1 ^8 E0 Q" dprintf("The sin() of %lf is %lf\n", x, result); # q/ P) f) I! U/ z# R. J9 c! Y" a
return 0;
# `( b' U& z+ l' F( j4 ~; i}
( {9 X2 j4 v2 _0 z& c; U, u7 g# `* Z$ u: B
</FONT></P>
( b/ }0 d2 f8 E: Q$ o<P><FONT color=#ff0000>函数名: sinh </FONT>6 _' v+ R5 X2 C
功 能: 双曲正弦函数 7 z2 v  b5 L( L" c2 [
用 法: double sinh(double x);
, W, y+ i& I: J2 x; L  U程序例: </P>
3 J( J6 c6 O* a8 w<P><FONT color=#0000ff>#include <STDIO.H>& }' S: n5 q8 k' l
#include <MATH.H></FONT></P>
$ H! ?6 i7 `% k5 P2 N, |<P><FONT color=#0000ff>int main(void) - z0 g2 s- ]' C% v9 l
{
, \6 T9 A5 S+ U2 c1 v2 Wdouble result, x = 0.5; </FONT></P>
( d- |9 p( G6 M* @8 V( q3 o<P><FONT color=#0000ff>result = sinh(x); ; ~$ Z/ [* E+ p$ j( [9 @
printf("The hyperbolic sin() of %lf is %lf\n", x, result);
3 `1 \+ c. m% @! I7 mreturn 0;
8 x  ?) L) m0 C5 ^5 w} 9 J8 e$ X8 u4 q( U1 P

* `! E, a  E) e% y& J5 u% }3 F
- z0 j: h+ {$ y! m</FONT></P>
( e  K; Z5 m# n* M& a<P><FONT color=#ff0000>函数名: sleep </FONT>8 C# d7 X- h4 }# Q; p( i
功 能: 执行挂起一段时间 9 f0 Z$ U* \( M' ^. G
用 法: unsigned sleep(unsigned seconds);
; G: l6 C1 _6 E3 R. H% [/ L" M程序例: </P>
: d0 s( _' D9 R: F4 Z: A<P><FONT color=#0000ff>#include <DOS.H>( }  D/ }; S2 N7 \. }& ?
#include <STDIO.H></FONT></P>  o# R$ E& V; M6 S$ c0 W" S  z
<P><FONT color=#0000ff>int main(void) / Q0 h1 O+ p+ E
{ ) H; C9 S& Z  o" O0 B3 {- ~
int i; </FONT></P>5 k+ a( \; E6 Y% x& m; U
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
% R& T( H6 U$ z# Q{
* u9 A, Z, Z# @/ t3 m: Cprintf("Sleeping for %d seconds\n", i);
7 v2 p6 D0 k. U. o2 F& }# Nsleep(i); 7 f1 n  E- T- T  S  l
}
$ K8 Y8 Z3 e+ A; O& xreturn 0;
! J: _# j2 y. _- j; l} & m4 [. D2 L. W# w& p# M, f

4 H. o) y' v$ i% M3 |: n# C</FONT>
# @! ]/ @' D+ H) \1 w! K+ {</P>1 @7 I1 e4 ~4 s! q( {
<P><FONT color=#ff0000>函数名: sopen </FONT>( k6 e3 I# K; v. a7 z& b5 ?
功 能: 打开一共享文件
8 N' z  W2 G' K: \2 l+ S+ ?0 U用 法: int sopen(char *pathname, int access, int shflag, int permiss);
. v4 W* K. A1 _: l程序例: </P>  |& P. j9 B- f; v  N# q
<P><FONT color=#0000ff>#include <IO.H>% ?4 |5 @% C7 Y& @5 e7 L" m& b
#include <FCNTL.H>
  _& p) F/ }$ @8 f( R! A#include <SYS\STAT.H>& e  g: b$ o) T/ E" V# Z  M$ y
#include <PROCESS.H>
( \7 ?' u; q/ |, a  Z9 g, O2 C#include <SHARE.H>
8 [" q$ L: a( a5 P3 W1 }# L#include <STDIO.H></FONT></P>1 j0 w# \9 J8 z. i  {9 t; s& c
<P><FONT color=#0000ff>int main(void) ' z1 m; n" O: W: W2 J7 I. J! h
{ # n1 N5 \7 `) `# d8 X/ u" C
int handle; / d% |) K9 \( {2 ?" P7 K
int status; </FONT></P>
" J9 n) W- s2 n4 C<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P># \8 h5 n7 c. j" L
<P><FONT color=#0000ff>if (!handle)
, F5 C* j2 M7 b$ M9 t- [9 D/ K{ 3 W: G$ Z) ^3 V! s" v# R
printf("sopen failed\n"); 0 e6 A1 t2 P2 S# [1 h. \- @4 U; u% E
exit(1); , v$ B) r3 K0 x2 b0 h' Z& y
} </FONT></P>. {3 Q" Z& N8 A/ i
<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); 2 M/ C- H4 a1 U1 c5 Z! j
if (status == 0)
$ \: G9 _! C& F: L4 e  z; Gprintf("read/write access allowed\n"); 7 r! U+ s: ^& |. |" u5 D
else
8 W; m8 x* u4 R1 P' K) T; oprintf("read/write access not allowed\n"); </FONT></P>
, z3 o9 Q, c# q$ V& R8 K% l. L<P><FONT color=#0000ff>close(handle); ! A8 @# u) F8 }7 k4 A% }8 C/ _
return 0; . _/ F* \+ ~% @' J2 o
}
9 v. {) s/ G/ g: Z0 c6 n: ?5 L7 H0 r
</FONT>* |. \9 y) d2 p: x
</P>' ?) S5 v' Z8 k4 P
<P><FONT color=#ff0000>函数名: sound </FONT>
+ u* {# z7 ]8 c0 X7 C# @功 能: 以指定频率打开PC扬声器
- g% x$ ]6 e3 ^% n  D/ K& x用 法: void sound(unsigned frequency);
7 Y! I+ o( K1 U" M& ^; W程序例: </P>4 G- L* B) C7 g' [
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. : |, t7 C9 J1 V( Z* w1 K- o" l5 X
Your PC may not be able to emit a 7-Hz tone. */
/ N+ ]$ `, {: Z1 O# w$ ~8 ?#include <DOS.H></FONT></P>& m$ ^4 \0 `3 d
<P><FONT color=#0000ff>int main(void)
' l! T  N& O0 S{
7 k! Y( k# ]! F. f# M8 A& _sound(7); 9 C; |4 s1 S) \, i) `
delay(10000);
0 B) I3 c% q1 o2 \! J: Onosound(); ! H3 h0 d4 s2 I: d2 S7 ?
return 0;
3 A# d6 E! C" H7 M: Z; g} </FONT>6 O8 R5 j6 a, W# B9 K7 U( ?1 f
% C, L* p" O( L: o+ r

1 H( d6 s0 Q( }7 m0 W* G' L</P>
1 R2 L/ B% g' }6 M& |<P><FONT color=#ff0000>函数名: spawnl </FONT>. l6 q7 h# `4 r/ a6 `% `
功 能: 创建并运行子程序
$ a: ~& D5 a$ s8 o用 法: int spawnl(int mode, char *pathname, char *arg0,
( X: y+ ]7 b) A; ^7 r. q- Carg1, ... argn, NULL);
2 Z2 T5 S7 e2 A6 M, n# ]0 b程序例: </P>
, A- r- Q/ `- Q# Z) Z<P><FONT color=#0000ff>#include <PROCESS.H>3 T) A0 A, O, a( v+ S
#include <STDIO.H>; b+ h6 W  D; R3 i0 D% x7 I
#include <CONIO.H></FONT></P>
4 b' |4 @  I( I$ A  z<P><FONT color=#0000ff>int main(void)
# T; u; p- c  ~. d% Z$ A{ # E; T1 N5 j% b3 R3 ^
int result; </FONT></P>+ [0 R% r# ~+ ?; v
<P><FONT color=#0000ff>clrscr();
/ O* S3 \6 K$ R# S5 z- o$ G/ Uresult = spawnl(P_WAIT, "tcc.exe", NULL);
: I% A& B6 Q* }6 P+ Lif (result == -1)
' w. j4 ?4 S5 w{
/ |* o4 A% B" d2 [+ ]! c0 b' sperror("Error from spawnl"); 9 Z1 y  }  x1 F- v% ?' ~
exit(1); : V: F3 t) y! s1 i; S. Q+ M
}
/ T$ U: n# Z) L# _  N; Xreturn 0; % v$ R9 o6 J; O+ i
}
* G. O# [+ q5 u' c  E, L</FONT>
' S7 X9 }# F% s! @+ \# m</P>
( y7 s. Y5 l+ Y9 z% G<P><FONT color=#ff0000>函数名: spawnle </FONT>
1 t' u4 B4 z+ N  n1 a1 t功 能: 创建并运行子程序
- V7 f, m& g! X- O- A2 k) }用 法: int spawnle(int mode, char *pathname, char *arg0, 1 k& t& l0 p+ T9 I3 L* Y$ ^
arg1,..., argn, NULL);
& ]/ }* X' V; D- s' d程序例: </P>( t2 k7 K- R  |$ t+ b3 p) y/ B7 U0 S; D
<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>
2 o* Q' `: B0 q; S9 @9 H7 k. y) [<P><FONT color=#0000ff>#include <PROCESS.H>2 \. P, V- c" S  I
#include <STDIO.H>1 `9 d# i: N4 l9 ]1 g
#include <CONIO.H></FONT></P>
) y7 j2 K! X2 W+ j! E( W<P><FONT color=#0000ff>int main(void) 6 ^6 w* Q# f. j- l) T; S1 Q
{
, X) i3 }) ~2 Wint result; </FONT></P>
  n  A, ]% I1 O+ I  J* `<P><FONT color=#0000ff>clrscr(); ) X3 n. y* o2 @& ]* Z
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL); 0 R' [* b/ E5 ?0 R5 c% @+ W
if (result == -1) 6 J( _- q8 g0 V- x/ c
{
+ u1 M2 e& x" j- k' hperror("Error from spawnle"); , A' [0 f0 P4 I0 g* \% z8 y
exit(1);
, d6 h) B$ X0 S* k7 `$ a}
  Y( K7 O$ B  \/ e' F" c( x. p8 g& Ereturn 0;
( g0 S( s& m! l. N; \& {) D" ?$ x4 L+ q}
! o4 u) L- ^# A/ l: E" i9 F9 f
- ^2 w. W5 H; I# H6 P
4 j, g" b: Y+ }5 g</FONT></P>
7 l7 Z8 m) L, ]5 T8 s8 C# C<P><FONT color=#ff0000>函数名: sprintf </FONT>* `% b! q; _# z+ J# H. N6 N
功 能: 送格式化输出到字符串中 8 l& s) j7 j3 A3 U9 z7 g! I4 \8 F3 {* h
用 法: int sprintf(char *string, char *farmat [,argument,...]); . U, Q- o3 |. z* n' g+ Q1 R
程序例: </P>
/ u5 I5 Y5 b- I! L<P><FONT color=#0000ff>#include <STDIO.H>3 }" S% f0 X3 x9 r
#include <MATH.H></FONT></P>; m: R6 E% o- ~+ m5 v
<P><FONT color=#0000ff>int main(void) ! l+ {0 j0 |+ R' p. E
{ ) I# I$ T. o- }4 A1 }' l
char buffer[80]; </FONT></P>- z: x/ h) ]7 K& `# H
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); ( S/ j8 J& L9 T: E# p  A
puts(buffer);
: s* ^" R+ G$ q- ureturn 0;
6 t) @7 T1 {' {0 m} : Z8 P5 N% ^  P( v6 n
</FONT>
3 L% i8 ?1 x, _+ S! C. s  A</P>4 @) l: Q, ]% j8 ^( L8 q
<P><FONT color=#ff0000>函数名: sqrt </FONT>
9 {) y$ R$ o3 k! S7 K) k" C功 能: 计算平方根
( I2 J( G  q5 U& @* O/ w8 _# g5 L用 法: double sqrt(double x);
4 ^. y+ @# o! R* s程序例: </P>
8 }- ]/ D3 K6 d( _& g<P><FONT color=#0000ff>#include <MATH.H>
; Z2 k, J3 [4 a& S" U0 T#include <STDIO.H></FONT></P>
* m1 v# H! e  A' e1 m<P><FONT color=#0000ff>int main(void)
9 O8 m0 E" c& ?1 C' q7 t- A{
' E2 ?) v: |6 H/ Hdouble x = 4.0, result; </FONT></P>% B3 Q( Z2 }$ L
<P><FONT color=#0000ff>result = sqrt(x);
6 @: J% U* m' C2 u, a! kprintf("The square root of %lf is %lf\n", x, result);
2 E; P1 l3 v8 V1 ^/ O+ \; `return 0; 9 h" b$ m3 M! J, B& J8 `$ D; B7 a
} + J+ x6 g5 \1 A' V
</FONT></P>
  `4 i7 V) G, H9 d<P><FONT color=#ff0000>函数名: srand </FONT>
6 {5 x1 ^) b; \  |5 m6 _; _7 |功 能: 初始化随机数发生器
! o8 l2 Q4 a8 C. l用 法: void srand(unsigned seed); 6 S+ [( n, O7 F  N* b
程序例: </P>
0 y0 }4 T1 J! X5 e<P><FONT color=#0000ff>#include <STDLIB.H>2 L, q( Z* n; ?8 l
#include <STDIO.H>: S. x6 k7 `: d9 `% z& d$ W
#include <TIME.H></FONT></P>
( c, O' e/ Z: |" T: K<P><FONT color=#0000ff>int main(void) ; X5 j7 q; R  J2 t* @* p+ ]. q4 \
{
+ D6 B3 B& J9 v( T6 sint i; % z8 D! k! _8 W
time_t t; </FONT></P>
0 o$ A1 i) ~6 V( A* k- J<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
5 J8 g( Z5 O) D. _printf("Ten random numbers from 0 to 99\n\n"); $ u! q: {) x1 x$ D% c  N4 g
for(i=0; i&lt;10; i++) * X6 t, g4 \6 l6 k$ Q! T. F
printf("%d\n", rand() % 100);
% {' a4 d( I4 k; e# ~* N) D; o! Zreturn 0;
* t% O$ v% x  V' a) A}
/ D+ y, B1 a: ?  F% R7 I</FONT>6 V6 B; m& e& S% o3 v$ F  c
</P>9 Z  X, `- c) M* o5 Z7 {  f
<P><FONT color=#ff0000>函数名: sscanf </FONT>" V0 w( M! O' A; Z7 n
功 能: 执行从字符串中的格式化输入
* X' p4 i5 t3 W' L$ n: s用 法: int sscanf(char *string, char *format[,argument,...]);
9 F* t* h9 g4 l$ W( ~0 f程序例: </P>
4 c. {: s$ _$ C% V# K<P><FONT color=#0000ff>#include <STDIO.H>
: h. M, b8 N4 H- \3 E3 }#include <CONIO.H></FONT></P>
4 f: u  h% W5 Z' A+ c<P><FONT color=#0000ff>int main(void) 0 @9 B' b' R2 ^
{
3 D. J0 y/ b& Ichar label[20];
* |# g/ c# W, W, s2 h, L- J8 fchar name[20]; 6 x& l/ Z% v' s  B  z
int entries = 0; 4 Z3 S6 l4 F; J. N! R+ k6 R
int loop, age;
2 A9 _1 E& v5 ndouble salary; </FONT></P>
1 ^$ C0 Q# `6 q6 |  v<P><FONT color=#0000ff>struct Entry_struct
1 ^' U, K4 z! _{
7 i3 F% W$ D: y- T$ s' B, Z4 h6 j8 Mchar name[20]; 8 E; p- Q+ }5 T. k( J$ F; Q  E7 P7 A( `
int age;
5 K  A) Q4 H+ qfloat salary;
" \) V* A( v2 w0 l# r" W2 y} entry[20]; </FONT></P>
' I5 {$ v7 f4 N$ e  ^# d3 ]/ S<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
5 C- h/ G7 v9 c* W6 Qprintf("\n\nPlease enter a label for the chart: ");
5 M2 p) [" S- ?+ r+ a8 Iscanf("%20s", label);
( s) o/ _2 C9 V4 Z6 ufflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
2 z9 Y0 z" [. ^! ?: }; Q<P><FONT color=#0000ff>/* Input number of entries as an integer */
$ y* h  u- a: G/ M5 bprintf("How many entries will there be? (less than 20) "); % Y. c3 q3 M+ T( x3 Z4 ^0 R+ l
scanf("%d", &amp;entries);
) g# _; v$ }+ q9 {9 ]fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>5 D+ p8 \# [: B' `3 X& N/ _
<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
( H* W6 @7 _* U* v$ Bfor (loop=0;loop<ENTRIES;++LOOP)
: C/ b& Z& |. q* A- T { * }5 c; h0 {  T4 X
printf("Entry %d\n", loop);
; o& x7 l2 o, {printf(" Name : ");
" r" k4 C9 s# O0 F5 @scanf("%[A-Za-z]", entry[loop].name);
% W* F7 R! }. a: Nfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
7 ~; b7 V2 K9 W* a  d5 r4 T6 N<P><FONT color=#0000ff>/* input an age as an integer */
8 S3 s: @: c; z* |7 N/ Gprintf(" Age : "); ; T' y, V+ i6 h! w4 K/ f
scanf("%d", &amp;entry[loop].age); % O! I. Z) z) ]$ |) k1 e6 _, t
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
; B6 m/ R/ B! O. ?& P" c! ^) n<P><FONT color=#0000ff>/* input a salary as a float */
( O2 d5 Q; `  D8 z' c( \printf(" Salary : ");
7 r, P( x! {. x$ k! V; rscanf("%f", &amp;entry[loop].salary);
2 A) N7 H" E. X) b9 I! F+ bfflush(stdin); /* flush the input stream in case of bad input */
1 V( t1 s- A/ E% m9 A6 b} </FONT></P>
1 _1 g4 h& M$ r$ X<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ 0 g5 d) p0 ?; v$ L7 |, S- V5 S$ V
printf("\nPlease enter your name, age and salary\n"); % k7 l" ~: B6 c" a) I
scanf("%20s %d %lf", name, &amp;age, &amp;salary); 1 k! s' ^% S, R+ v1 t% B; R
</FONT></P>
% L, k' }; X& Q<P><FONT color=#0000ff>/* Print out the data that was input */
7 ?- O+ b$ p3 z7 x% `  vprintf("\n\nTable %s\n",label); 4 w& J. G& P+ L' a' `) b
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); % x  T# j$ ]' J6 }8 P3 Z2 _2 F6 S  R8 _
printf("-----------------------------------------------------\n"); - ^' D$ J8 S6 G2 F
for (loop=0;loop<ENTRIES;++LOOP)
7 s8 n+ c, B" j& l+ @0 Y+ k7 X8 q printf("%4d | %-20s | %5d | %15.2lf\n",   k- A8 `; u) |' M4 v1 e
loop + 1,
6 }4 I* z: R/ n* [: {% \entry[loop].name,
3 p6 w0 o6 I8 c0 aentry[loop].age, 4 L9 C6 M% @) @
entry[loop].salary); 1 E1 B% s: P. K5 P8 p
printf("-----------------------------------------------------\n"); + t: E* w0 d; a0 b$ S
return 0; + y5 J7 J+ Z: n4 y: M" h
}
, O) f5 L! {. {4 v7 q3 N8 @; b" _. K3 h8 M" B- j
</FONT></P>1 g) F8 I; Y1 Z& @/ }3 T* D
<P><FONT color=#ff0000>函数名: stat </FONT>1 d0 v% {: a3 C& A% X" G4 g" Y
功 能: 读取打开文件信息 ) V1 t+ {$ }1 {4 m: |- }/ M# e' V
用 法: int stat(char *pathname, struct stat *buff);
8 f, u: s* q. |1 g! @8 ]' N程序例: </P># o) u: g! \3 d- v# [
<P><FONT color=#0000ff>#include <SYS\STAT.H>
$ I" t7 c9 b! a0 s9 |#include <STDIO.H>
7 G( O/ o( r, G: I#include <TIME.H></FONT></P>; ]* _1 w* d6 o1 k4 S1 K3 n
<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>2 K) [& K1 P  |3 Z0 F' o
<P><FONT color=#0000ff>int main(void) - ?. c7 l- V; d9 E+ |/ k+ w" L
{ 1 T; @/ ~/ c# C+ k6 ?
struct stat statbuf;
/ M: b8 j3 t& s/ |0 `FILE *stream; </FONT></P>
/ {( A& u. G* o  Q5 }% H1 G7 R<P><FONT color=#0000ff>/* open a file for update */
3 m' D$ V  U8 s7 E3 R) aif ((stream = fopen(FILENAME, "w+")) == NULL) ( D. S; I* i; S* i/ `
{
' X: L  W5 B, afprintf(stderr, "Cannot open output file.\n");
' U8 H% V5 I# O# w, Yreturn(1);   _' U% S: g5 F8 t5 Q& C; u
} </FONT></P>- I' u5 R" W; w; }! _2 M2 p% `
<P><FONT color=#0000ff>/* get information about the file */
. [2 h7 \: M% J8 z. `& Z+ ]% G8 zstat(FILENAME, &amp;statbuf); </FONT></P>
  ]7 B# U; u. S5 R1 {# M* [' y<P><FONT color=#0000ff>fclose(stream); </FONT></P>
. w8 f* v. G+ W% W. {0 R<P><FONT color=#0000ff>/* display the information returned */
0 d( I9 W& s8 M3 g* Gif (statbuf.st_mode &amp; S_IFCHR)
5 S; t2 m& Y2 c+ d) Gprintf("Handle refers to a device.\n");
# S+ M9 b% I) S. |: C7 L! ^if (statbuf.st_mode &amp; S_IFREG)
- F9 ~2 G+ Y. H' g! ?* X. M2 Rprintf("Handle refers to an ordinary file.\n");
$ V2 f& L2 v0 ^0 c5 L$ k3 ?& mif (statbuf.st_mode &amp; S_IREAD)
0 w/ _% ^" y- F1 \* ^, \3 yprintf("User has read permission on file.\n");
& T) o/ w2 f5 i# `% nif (statbuf.st_mode &amp; S_IWRITE) 7 d7 o" L6 c$ V4 o! T& P- Y% y
printf("User has write permission on file.\n"); </FONT></P>( G/ l! g1 M# O, G& O
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); ' c* O* e  |. N! N9 x  s
printf("Size of file in bytes: %ld\n", statbuf.st_size);
2 X: h/ @5 n9 K3 l0 A3 I5 xprintf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
1 p  f2 r7 w' p$ wreturn 0;
: I3 j5 C& s% N( p3 ^, U2 o  P} * z# v. U! q+ S6 r; C% s# O

* H" f! p0 U7 U1 M. I8 w9 {. }* D</FONT>
% |, `; z( {7 }$ s3 y</P>/ V; r& p( O$ O: e. J7 J
<P><FONT color=#ff0000>函数名: _status87 </FONT>
/ x  X; k! ?# v  {6 ?9 _4 V7 \功 能: 取浮点状态
9 O  z5 q, g( k& z  H9 g/ X. C9 ^用 法: unsigned int _status87(void);
& M! s) i- D, Z. n' r程序例: </P>8 j3 e9 ?( U/ e. ?
<P><FONT color=#0000ff>#include <STDIO.H>
: y4 |+ t$ N6 E* I#include <FLOAT.H></FONT></P>+ ]+ j3 @! f( x: ~0 u4 d
<P><FONT color=#0000ff>int main(void)
  o3 Q* U! A# K{   o  D; r) E( O) w9 b
float x;
+ I0 [! O* Z6 i& k) n: J. Tdouble y = 1.5e-100; </FONT></P>) z. s9 ~) X: O3 H9 p2 o
<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>5 t; o! _- o- e* V$ L
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
6 x7 P" c# @% ~8 ]3 r0 J' K, {6 Hy = x; </FONT></P>
. o* ^6 H" Q, M" v% S<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
+ z( w% K7 k- rreturn 0; ; _: K! p2 Z* c7 X: D
} 2 i! a! S2 q3 s1 e! w
</FONT>3 N7 N1 _9 i! C
</P>
/ s5 j: n% X; Y7 n" A<P><FONT color=#ff0000>函数名: stime </FONT>
2 c# ?1 L/ A% K& Q5 B功 能: 设置时间
) q5 |, h% B% ^; W用 法: int stime(long *tp);
, ?) e* c" h1 g: N程序例: </P>
4 K' a/ G, M/ K7 \<P><FONT color=#0000ff>#include <STDIO.H>0 U* }- v9 x& u5 C) `
#include <TIME.H>, u% d# o% q) i  x  P8 ^$ d5 d
#include <DOS.H></FONT></P>, s. y& k. m: e* q
<P><FONT color=#0000ff>int main(void) $ h9 p( A) |  H6 s) G# @" [! G
{
+ c% j; `6 H2 ]time_t t; ' d; r1 R$ M' N0 l6 ]8 ?  x- {
struct tm *area; </FONT></P>2 S- h* n6 c9 F  Z+ z
<P><FONT color=#0000ff>t = time(NULL);
% g4 q4 ?2 H; Yarea = localtime(&amp;t);
- C- l9 w0 T* A* ^" R' l* yprintf("Number of seconds since 1/1/1970 is: %ld\n", t); 1 |8 A6 ~8 K( t
printf("Local time is: %s", asctime(area)); </FONT></P>2 m/ |2 v& X! |2 c0 E$ f$ X: [( [# q
<P><FONT color=#0000ff>t++;
2 c0 l9 J) g7 }& _% [area = localtime(&amp;t); / ^, j1 I% U5 T5 m* ]4 F" g: s
printf("Add a second: %s", asctime(area)); </FONT></P>1 y# `2 g2 Z. R# Y. l
<P><FONT color=#0000ff>t += 60;
% m, X9 B8 y  q. Qarea = localtime(&amp;t); ' E. `* e$ N" t& e2 \4 q1 D4 j' k
printf("Add a minute: %s", asctime(area)); </FONT></P>9 ]4 K, T9 K2 Z
<P><FONT color=#0000ff>t += 3600;
7 F. r$ i" _1 G2 D. @area = localtime(&amp;t); 2 ?: e: x) |& W* p/ E" w  }- A
printf("Add an hour: %s", asctime(area)); </FONT></P>- ^( L1 U8 R1 s) M! {9 G6 L
<P><FONT color=#0000ff>t += 86400L; ( r  p2 z. H2 B' Q1 W3 n+ r
area = localtime(&amp;t); ! t( l0 H7 z- X1 t# R  N
printf("Add a day: %s", asctime(area)); </FONT></P>! w( S4 v9 l, ]) d( E8 y, o% P
<P><FONT color=#0000ff>t += 2592000L; $ z6 a( m3 I7 F2 f# R" ], x
area = localtime(&amp;t); 1 q4 K5 D0 f. k- o; [
printf("Add a month: %s", asctime(area)); </FONT></P>- |9 Z: [( _4 ]2 t) ~
<P><FONT color=#0000ff>t += 31536000L;
- z4 S8 ?' w) z( Garea = localtime(&amp;t); 0 B3 f" U% z4 g7 f% m
printf("Add a year: %s", asctime(area));
3 z: o9 O$ s4 |$ G8 D% ureturn 0;
7 c; Y& ]9 H6 t} </FONT>- d% y  E% E; V7 ^

. \: ~) D% v1 Z3 M- _) `
) J. u5 a' ~& o/ k$ N# K</P>
( K  A# l& I' v+ n  @' {* G8 ~<P><FONT color=#ff0000>函数名: stpcpy </FONT>
. g+ A7 Z  j3 o6 s1 p! u! t) I功 能: 拷贝一个字符串到另一个
+ r5 O' e* [$ O9 T: ?- m用 法: char *stpcpy(char *destin, char *source); 5 ?# U/ \9 R3 l2 E
程序例: </P>
. d( J5 ~5 @, z% ]' |) M1 V: J<P><FONT color=#0000ff>#include <STDIO.H>
1 J/ {6 v" D3 _! r+ M#include <STRING.H></FONT></P>) z( \! c6 z8 y9 H% ]& Y
<P><FONT color=#0000ff>int main(void)
5 X% x- k* F! b# H3 x{ 6 d6 G! o6 N  Q# {% C" W
char string[10];
5 [$ J2 W  H) M( q' H6 n/ _3 U& vchar *str1 = "abcdefghi"; </FONT></P>
8 s& `) n9 t- }: n6 @$ C- g4 ~<P><FONT color=#0000ff>stpcpy(string, str1);
1 R( {0 N& g$ N0 ?printf("%s\n", string); + U, w- _/ t, }. e
return 0; / @4 m% y$ F1 g6 ~
}
% P# _% O8 g+ g1 }8 D' g* C& d) x* p
</FONT>
, }" u/ U: Z6 `* S* g; A- d# z</P>- I3 j7 H7 I5 l% k( g  H2 Y
<P><FONT color=#ff0000>函数名: strcat </FONT>8 }9 B. P. X3 o1 y; b
功 能: 字符串拼接函数
8 o0 q* y5 @0 u& h+ e. K% @! _用 法: char *strcat(char *destin, char *source); , c$ P/ _$ ~) v) g0 B& \
程序例: </P>
. X, z6 x  P* t( @0 v<P><FONT color=#0000ff>#include <STRING.H>
. ]( o8 A$ h. y6 C9 o& B8 Y#include <STDIO.H></FONT></P>) ]8 V5 S# U# ?
<P><FONT color=#0000ff>int main(void)
. K9 W- P8 V4 x- n{ : Y1 u1 O! B4 u: c. `/ x! h
char destination[25]; - Z. l' x" Z8 W' s% b- t
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>1 T6 S. t, K; q6 N9 J3 e
<P><FONT color=#0000ff>strcpy(destination, Borland); % u5 Z, b: a; y/ f9 ~
strcat(destination, blank); # g: u* i8 [( ?2 L; m- z& a
strcat(destination, c); </FONT></P>
" n* E7 W8 [! o" T6 y; l: U* p0 o) Y<P><FONT color=#0000ff>printf("%s\n", destination);
8 O$ J7 {' p$ }7 ]- |  Preturn 0;
- p1 u3 a3 C$ k$ L}
4 E) d) U' e) _: z5 ]# \0 r0 H7 M( C( _7 U4 X6 v
</FONT><FONT color=#ff0000>! x: y6 r2 E; Y! ^5 ]% i
</FONT></P>
4 i: I4 s1 a) e% n* x7 N<P><FONT color=#ff0000>函数名: strchr </FONT>$ R6 H, A9 g$ N
功 能: 在一个串中查找给定字符的第一个匹配之处\
% I! k* S: Z% i) L8 V用 法: char *strchr(char *str, char c); 1 D- j( S/ Z) i# C5 y# p# Q
程序例: </P>% r) B* V  y) V  ^7 g6 ~, K
<P><FONT color=#0000ff>#include <STRING.H>
8 @) N8 N# w  p9 ^0 [" l! j$ m#include <STDIO.H></FONT></P>- c# Z9 j  Y3 F4 R& E; R7 c
<P><FONT color=#0000ff>int main(void) 9 ]" N. b, E$ x* F
{
7 o! t, |( K4 _: P) `) m- U0 D% H  }* Achar string[15]; 7 y% X+ [: C6 h) J! i
char *ptr, c = 'r'; </FONT></P>
. b: ]6 e+ I3 r' O- m- s' j3 @2 E# o<P><FONT color=#0000ff>strcpy(string, "This is a string");
9 L! X8 _( ~% C8 Y& Y" y9 O! c1 pptr = strchr(string, c);
7 N- T& b" w7 x$ p/ Dif (ptr) & j, m) j: u' F0 D2 r0 B
printf("The character %c is at position: %d\n", c, ptr-string); - X; C; G6 u' Z+ M3 E' \
else
/ T! \) Q$ f; d) r: c, E7 B3 \" Eprintf("The character was not found\n"); ; [' b1 ?4 V, U, n
return 0;
! x" x% `" @( Y0 Z$ \}
# k: t7 @4 i2 }4 F7 d</FONT>9 k3 ~9 \. A, E( _1 U$ d
% @3 J7 H4 C! E5 a" ~% e
</P>* _6 y7 t: q! r. S
<P><FONT color=#ff0000>函数名: strcmp</FONT>
/ Z& c: w( Q5 D) e. {功 能: 串比较 2 f- q' c, d- z/ Y9 z$ g
用 法: int strcmp(char *str1, char *str2); ! ?9 |# _7 |0 O
程序例: </P>/ `) x( T3 U( V8 r) W. F4 {
<P><FONT color=#0000ff>#include <STRING.H>
3 C! Y; @* q5 Q) f4 X#include <STDIO.H></FONT></P>' ]5 f/ m+ ^0 i4 L
<P><FONT color=#0000ff>int main(void) ( W) y2 a3 h6 m$ m3 @3 Z; Q% b
{
1 i1 b, l4 v. k. g) Uchar *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
  i( A: |  N7 c. L6 Yint ptr; </FONT></P>3 P1 J, h" r' k
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
! }) _1 ^( C" f$ E( Lif (ptr &gt; 0)
$ A$ [. u* S6 d- B# Q1 wprintf("buffer 2 is greater than buffer 1\n"); / ~( S/ r1 P" `* g* h4 q
else 5 i! t. a( e9 _
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
) L$ W6 b$ ?( }! r- }4 J* f<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3); + Q4 B2 n$ C1 Q0 ^* A& p
if (ptr &gt; 0)
4 l6 {& }3 F9 u% T+ K3 Oprintf("buffer 2 is greater than buffer 3\n");
  y+ i" Z" F# }0 z1 D- I8 a& Ielse : Q4 c/ q* a. o/ R
printf("buffer 2 is less than buffer 3\n"); </FONT></P>& E8 l3 E8 C6 g% b
<P><FONT color=#0000ff>return 0; 1 K0 w, ?4 V" v! U- w
}
% J- k1 `, ~3 g1 E& e1 N2 [$ `/ V! r; c6 G/ y1 g6 M% {1 s

3 M1 Z5 C* P7 G# J# C6 N# K4 q; I) E</FONT></P>
1 E0 z4 L% T. |- Y<P><FONT color=#ff0000>函数名: strncmpi </FONT>" i1 U  s' A3 x, N  l+ L- M
功 能: 将一个串中的一部分与另一个串比较, 不管大小写 8 @4 d; Q) }( t/ V5 H4 L5 ~
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
" }7 Q& A0 c8 p  y8 |程序例: </P>
$ R: G& I# j1 {<P><FONT color=#0000ff>#include <STRING.H>
! o3 H6 p7 m; e( b' r' _3 T; u#include <STDIO.H></FONT></P>
5 G: y6 s+ Z: J( y" V<P><FONT color=#0000ff>int main(void)
$ u/ R- z  S4 Z  c{ 1 [) M& W" C% V$ x$ d8 S
char *buf1 = "BBB", *buf2 = "bbb";
( B5 R7 U0 Z4 @, Sint ptr; </FONT></P>
  M! n5 P- }$ j' Z<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>! ?* ?5 f$ C; f6 P. d
<P><FONT color=#0000ff>if (ptr &gt; 0)
4 T5 D. U& c, v. q" uprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
% D1 m& ]' N7 V* M4 y<P><FONT color=#0000ff>if (ptr &lt; 0)
& ]* J3 P# a  S& L: Aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>4 S  s$ F5 _. A1 Z6 j" G! e
<P><FONT color=#0000ff>if (ptr == 0)
% K1 R" u8 K0 C! r9 W1 O7 e0 [5 hprintf("buffer 2 equals buffer 1\n"); </FONT></P>
) h" r) |- i, H" _<P><FONT color=#0000ff>return 0; ' S$ q. B8 t4 _
} + H# r% K2 h/ ~5 V2 a" u
4 Y6 o; ^! t3 k4 x& ^8 k
</FONT>
* w( X/ f! c# F( V</P>7 e* b1 i7 c4 }5 O' f& I
<P><FONT color=#ff0000>函数名: strcpy </FONT>  L" m7 b8 N1 t8 |# e0 S9 [2 P
功 能: 串拷贝 ( j# [2 D! o' v. U
用 法: char *strcpy(char *str1, char *str2);
, k+ c. Q1 E/ k5 `' d) f程序例: </P>
# u1 N$ n1 n  f  d4 `9 F" y8 a<P><FONT color=#0000ff>#include <STDIO.H>8 G- q6 v' r+ e* I  M: \8 Z
#include <STRING.H></FONT></P>. ]3 f) \9 L, a6 F: X0 Y/ W
<P><FONT color=#0000ff>int main(void) ; l( M1 V3 N0 Z9 C. y. F; w
{ 7 ~6 i/ @1 w/ X; Y! G
char string[10]; ( H9 M6 a' x' b" p+ |
char *str1 = "abcdefghi"; </FONT></P>
( B0 Z) r$ Q, Z% s; W& U<P><FONT color=#0000ff>strcpy(string, str1); 7 G1 Z+ m' W" p+ k* I$ P
printf("%s\n", string);
6 x# Y# j& B9 t) w7 ^return 0;
! }9 L5 N5 ]: Y% D- @0 s} 8 \& z% m) B5 a6 l' t- ^, `7 Z. l
</FONT>
( \$ R* Y# y. D/ ~  b5 L3 q
5 f. w' `' ^# B7 J, H- {. A/ \( C9 b</P>
4 ?: ?, f; s7 H. D<P><FONT color=#ff0000>函数名: strcspn </FONT>
, d( ]8 p* ^7 E& E5 j功 能: 在串中查找第一个给定字符集内容的段 7 u0 }, E3 V( _8 N4 U. G! b
用 法: int strcspn(char *str1, char *str2); 7 g5 E) q. u  {$ d2 a% }
程序例: </P>% D" x& l/ D; \3 O3 J7 o
<P><FONT color=#0000ff>#include <STDIO.H>3 m- p7 M: r2 ~. N8 r( K" X2 N
#include <STRING.H>
' T6 B6 U- S; E2 H( U#include <ALLOC.H></FONT></P>
5 k1 N8 P/ e! T1 y) I# a- m. \<P><FONT color=#0000ff>int main(void) 2 J  L5 i2 t: ~, ~% M
{ 4 g6 ?3 t2 C. Y$ @
char *string1 = "1234567890"; $ v0 K+ l+ p  n% ?8 F4 u6 e
char *string2 = "747DC8";
, r$ ?2 k$ E7 d/ F2 V: Zint length; </FONT></P>
) k! g' m9 \7 U' A1 }, n<P><FONT color=#0000ff>length = strcspn(string1, string2);
. o9 F8 g+ O" J/ j0 h$ _printf("Character where strings intersect is at position %d\n", length); </FONT></P>
6 a5 \6 ]8 h  Z' d: t6 V& I+ H# P  b9 S<P><FONT color=#0000ff>return 0;
9 Y: ]. x5 r+ E! k0 [: q* b/ |$ K  v) U}
' L: P: e. w" [6 t</FONT>
0 w4 d- t* M1 [' M) l! [' m* n+ I# S4 V, N" c4 V+ m. h# J
</P>, R* s9 \6 n; G$ s: E
<P><FONT color=#ff0000>函数名: strdup </FONT>
5 q0 W" J$ B5 |8 Z' T' K' y功 能: 将串拷贝到新建的位置处
6 P& t8 J+ E7 E8 [* C) @7 S8 y8 A用 法: char *strdup(char *str); 2 E* O1 H6 }; r2 {! {0 _
程序例: </P>
8 Y( w" V. U$ n$ d<P><FONT color=#0000ff>#include <STDIO.H>
" y7 h2 e: ?) s8 L/ @9 U#include <STRING.H>
' n& z2 |% e3 \1 E5 d7 j3 m/ h#include <ALLOC.H></FONT></P>
( l, N( {0 S( C3 I! u<P><FONT color=#0000ff>int main(void)
1 f9 t( f/ `- C, }{
; |: u! p' F6 Uchar *dup_str, *string = "abcde"; </FONT></P>6 q: M% v" }) o1 s& b( N
<P><FONT color=#0000ff>dup_str = strdup(string); 7 i, l3 u" k/ H7 c/ P* ?$ {$ J
printf("%s\n", dup_str);
! Y, T4 s, V; u  Z9 Mfree(dup_str); </FONT></P>4 X) }- s0 F4 W% p
<P><FONT color=#0000ff>return 0;
  |, L7 G0 r2 u: v7 m8 k} # c3 b8 q3 f) b8 P  K  \3 H

- n7 M% m4 X/ X& M; {8 \) j4 [</FONT>
8 H' t: e% V( y. K</P>
9 R' ]( i# ]: I<P><FONT color=#ff0000>函数名: stricmp </FONT>
8 T0 F2 K7 B( N- B  Q9 T5 b功 能: 以大小写不敏感方式比较两个串 6 ]. c( D! H/ i4 K4 C9 u2 ]' B1 N# h
用 法: int stricmp(char *str1, char *str2); $ g# b1 T: ~, G6 P( C0 s6 r" D8 o5 C) ]
程序例: </P>
  D& z7 N( j6 Q7 ~5 e1 Q; W- k<P><FONT color=#0000ff>#include <STRING.H>! L$ a' B9 G- X  h9 B3 b! o3 I
#include <STDIO.H></FONT></P>
2 x' X% ]. J( G  T+ ~' ?$ L<P><FONT color=#0000ff>int main(void) + H: P1 Y+ M" l- Y) ~" P6 H
{ 8 U5 h: I, H7 @3 X
char *buf1 = "BBB", *buf2 = "bbb"; : x- K( [$ z% f3 E. Z# z3 h- K
int ptr; </FONT></P>$ d$ k# S7 j7 f! |' U
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>" S& ^' A7 `# G% t3 ~6 U6 j% G
<P><FONT color=#0000ff>if (ptr &gt; 0)
. _7 q( W8 F% b& _0 Q! ]; uprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
( J* o: t+ Y: t<P><FONT color=#0000ff>if (ptr &lt; 0) ( n- P2 i* b) v7 @
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
5 J* `/ d2 |7 v& [% F<P><FONT color=#0000ff>if (ptr == 0) 3 ^# N# l: o9 M4 u+ B6 l+ e
printf("buffer 2 equals buffer 1\n"); </FONT></P>4 |" t8 D$ W1 Q' `, b' K
<P><FONT color=#0000ff>return 0; . N5 B% k$ ?% `% u* M5 H! i
}
: O4 C7 n0 |- u, u8 B5 T</FONT>
1 M7 P6 p' H/ ^1 X9 C</P>
. m. h# c0 E* h1 t, T<P><FONT color=#ff0000>函数名: strerror </FONT>
+ B7 r6 W0 b0 V% L) t* s功 能: 返回指向错误信息字符串的指针
! K+ f5 p4 \  D$ T# s5 |用 法: char *strerror(int errnum);
2 L1 K0 c# c: A程序例: </P>9 `* N, }& v+ ~# s  V; q' l! W% F
<P><FONT color=#0000ff>#include <STDIO.H>" Z/ ?! f  w3 g9 U/ B
#include <ERRNO.H></FONT></P>- P, x; U! ^4 S. c2 C) b0 Z
<P><FONT color=#0000ff>int main(void) + \9 @: _# w: C, x0 i
{ 3 J; z, `: A- B+ O
char *buffer;
' {& h, B7 ^( S2 A: ]buffer = strerror(errno);
5 M4 A: l4 O' r  J* O# yprintf("Error: %s\n", buffer);
  l# j4 _# T+ R5 u7 Dreturn 0;
) `% H/ |2 h9 L8 C} & X2 p% U* Y' d9 Q+ g# G/ b, _  N) P

( z) \/ U- x2 G3 _$ v7 `# ]5 a1 ~</FONT>( K, p8 f+ J' K( o9 U* K% W
</P>
6 q# i( X" a* e9 i3 Z! [* x/ o<P><FONT color=#ff0000>函数名: strcmpi </FONT>
1 q: ^6 H; Y: ~; ~# A$ @功 能: 将一个串与另一个比较, 不管大小写
: c9 n0 K/ c. z6 L+ G用 法: int strcmpi(char *str1, char *str2); 0 o4 k* }" a4 ]$ t+ P
程序例: </P>+ H. O7 v- o  B  p8 G
<P><FONT color=#0000ff>#include <STRING.H>
5 E7 z) j2 m& w. D  c% t% F- b#include <STDIO.H></FONT></P>( J# S6 x" l% N( ~1 K1 i6 u# H
<P><FONT color=#0000ff>int main(void)
0 y. `/ P0 }* G. Q$ F2 W" C{ ' D3 y6 W, i0 R, e- J8 {
char *buf1 = "BBB", *buf2 = "bbb"; + c2 I  r8 y, [
int ptr; </FONT></P>
& U3 Y7 z! n+ U7 u( _, S  [<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
/ l$ G6 H' G7 t. e" _2 u<P><FONT color=#0000ff>if (ptr &gt; 0) . O! |4 k3 M% b
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>' @) |! o5 R9 `
<P><FONT color=#0000ff>if (ptr &lt; 0)
# q0 {) I" E3 U( `3 `printf("buffer 2 is less than buffer 1\n"); </FONT></P>" n5 g  D7 u: Q& t5 U/ Q: R% v/ v: N  Z
<P><FONT color=#0000ff>if (ptr == 0) 2 x1 C! Q2 {% o( y# X
printf("buffer 2 equals buffer 1\n"); </FONT></P>& F# a7 t5 R2 [; f$ F  l. e
<P><FONT color=#0000ff>return 0;
5 O0 u/ F  s' j, F9 c+ R' A- `! |# a}
4 V7 w  W. w$ z4 o; I# L8 h+ M7 H</FONT>; H9 A. ]% d3 f$ G, k/ v

6 S9 P1 p! s, s+ x+ T& \; y5 \</P>8 Q7 S& _8 C& s% Y, D: r; n( j& @& c
<P><FONT color=#ff0000>函数名: strncmp </FONT>; \: c5 K7 T. z7 t9 c" a% o
功 能: 串比较 . p2 n( n( A5 U
用 法: int strncmp(char *str1, char *str2, int maxlen); 7 c, S- N) j) S" A. K4 [
程序例: </P>0 Z1 M8 J+ n" H  X- n0 `* I
<P><FONT color=#0000ff>#include <STRING.H>, q: W+ E; \0 ]8 J7 C. N- J
#include <STDIO.H></FONT></P>, X9 W2 e" L0 e9 I5 l: \
<P><FONT color=#0000ff>int main(void) </FONT></P>
* W3 E/ j( U# q# E<P><FONT color=#0000ff>{ / |+ A- T& u! f: f: b6 k
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc"; % Q/ W% Z, Q+ m! n
int ptr; </FONT></P>3 |' F- {' u6 A4 T
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3); ! _: M2 M4 \8 Z# L( U8 }. O4 x+ |: |
if (ptr &gt; 0)
9 {5 n* E( t9 y  qprintf("buffer 2 is greater than buffer 1\n");
. x4 C  f1 @6 w- s2 celse 4 g0 x: Z7 r6 p- H. I
printf("buffer 2 is less than buffer 1\n"); </FONT></P># S! F' `( C4 |) \3 \" Y) Q
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3); 6 t2 I7 D. `& x
if (ptr &gt; 0)
# U: N: I- y% g1 d; @printf("buffer 2 is greater than buffer 3\n"); $ p' _: `9 n) }# ^2 m
else
& Q2 q5 M6 a. R# o, \3 Pprintf("buffer 2 is less than buffer 3\n"); </FONT></P>
' R. c, }! r  v4 T, X  I9 t: M( O<P><FONT color=#0000ff>return(0);
" t! S9 ~" v  T5 n/ A! ~}
! V8 P' \. X7 k4 k1 S2 \
1 y" q* ]+ i* W+ C: M</FONT></P>
+ B0 w& f% Z: j( N' h' F- H<P><FONT color=#ff0000>函数名: strncmpi </FONT>
6 T8 Z/ W* B6 y3 \# Q4 O7 c7 Q8 k' z功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 ) l7 j2 _; W, p
用 法: int strncmpi(char *str1, char *str2);
% r5 f' k6 |2 s5 z  |5 a4 K程序例: </P>
2 O: g+ H1 }6 d$ E& \9 _( g% {<P><FONT color=#0000ff>#include <STRING.H>; Z& G7 v9 k5 W( G( {3 u
#include <STDIO.H></FONT></P>
8 w  f) N" h1 j; d<P><FONT color=#0000ff>int main(void)
2 I. I0 b4 W& c4 j& D" ~( M; P. z{
" Q) k' P' N( \: ~; W7 Uchar *buf1 = "BBBccc", *buf2 = "bbbccc"; 9 K6 q8 C2 m8 Z( D, A$ f1 G
int ptr; </FONT></P>
, d+ J6 Z/ o# `& ~- p+ {  p<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>
5 {' m1 K( A) G( a$ q8 c<P><FONT color=#0000ff>if (ptr &gt; 0) & p- `/ B  n6 W; {
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
2 u; [8 {5 W. p( r- j8 A% V3 ?, \<P><FONT color=#0000ff>if (ptr &lt; 0)
# p! Q$ _( c& c: {printf("buffer 2 is less than buffer 1\n"); </FONT></P>, W: ^1 N0 b- x; Y& Y
<P><FONT color=#0000ff>if (ptr == 0)
9 {% ]9 o4 j5 D: w: oprintf("buffer 2 equals buffer 1\n"); </FONT></P>6 z# D  O% \( I3 m3 o
<P><FONT color=#0000ff>return 0; </FONT>- q5 e! Q) d3 I
} " E1 w' C4 W+ w& y% [: u

+ Y9 b; v3 p% Q" [( e</P># K! u/ p& \& L2 G6 N# G
<P><FONT color=#ff0000>函数名: strncpy </FONT>
  ]) ?/ P- [( c. [功 能: 串拷贝 $ l, `' r: S; a
用 法: char *strncpy(char *destin, char *source, int maxlen);
6 t" Y+ q1 j- G" Z- I程序例: </P>
7 ~: n1 R; Y- n0 p/ c: h# x0 d2 K* h<P><FONT color=#0000ff>#include <STDIO.H>0 H5 n( F% N; `7 M4 o2 b8 b9 B
#include <STRING.H></FONT></P>
4 `+ m* T% H+ g% F* C. X: k4 q<P><FONT color=#0000ff>int main(void) ' s" H+ R  b& D& V# y+ p
{
( s2 S6 C, j8 q2 X+ Z& Ochar string[10]; 3 K% B" @/ V, {; ]# B
char *str1 = "abcdefghi"; </FONT></P>
1 I4 {8 G) T' g0 ]<P><FONT color=#0000ff>strncpy(string, str1, 3);
1 b) q( s8 s  X% }# Y# v6 bstring[3] = '\0'; ; ^% a1 D% X, V
printf("%s\n", string); & J# b1 }) w% m8 Z% z7 o0 Z& S
return 0; 3 U' j# e& u* }% N9 E
}
6 ~" z1 m  p# `" }/ q# o</FONT>
. [$ p0 ~6 u- B) q. f6 N</P>
! l* s  a) g  y9 \1 p6 s) x<P><FONT color=#ff0000>函数名: strnicmp </FONT>/ l4 x) H/ w# |9 B
功 能: 不注重大小写地比较两个串
: M2 E% {" E. w" ^用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
  Z- k1 ^9 ?* J" I程序例: </P>% [% n3 f* R2 x: J: H8 W0 V2 ?
<P><FONT color=#0000ff>#include <STRING.H>
. e7 ^  i$ @- j. f  Q#include <STDIO.H></FONT></P>, R6 o4 W" v+ e' Y/ ]
<P><FONT color=#0000ff>int main(void) 9 c2 m' S# R* \
{
: n* O0 G. W0 [6 F# B5 t) ?char *buf1 = "BBBccc", *buf2 = "bbbccc";   Z1 [6 Y% N% l# [6 G7 D! o3 K
int ptr; </FONT></P>
! B' |5 D  p' R<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>  b; {4 ?' k9 {1 l/ x
<P><FONT color=#0000ff>if (ptr &gt; 0)
$ p1 n: D+ E0 W4 S+ tprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
% o" P7 C$ f1 b- i1 d- E% Q* H<P><FONT color=#0000ff>if (ptr &lt; 0) , I- J" l+ U0 _6 e3 D! r
printf("buffer 2 is less than buffer 1\n"); </FONT></P>' c% D# H& i  `2 D
<P><FONT color=#0000ff>if (ptr == 0)
! {' D' z" L) M6 [. ~8 \" Cprintf("buffer 2 equals buffer 1\n"); </FONT></P>
! ~& M- j2 N: X% r! Q<P><FONT color=#0000ff>return 0; + |; k8 o0 b6 c! ]
} 0 J' X. K: S! E1 M( T5 c, V

" F+ H2 c6 K8 M- t</FONT>) ]: S* G( _8 N9 V2 g$ Y% L9 w- E+ E
</P>
7 M8 M. H  `! N! V<P><FONT color=#ff0000>函数名: strnset </FONT>" a5 t; T/ k: H2 ]
功 能: 将一个串中的所有字符都设为指定字符
* X: P2 C- }' r; b5 J% S用 法: char *strnset(char *str, char ch, unsigned n); 9 e+ j, U; \' X' ~6 S2 r
程序例: </P>
; U! h7 Z3 e. ]8 P<P><FONT color=#0000ff>#include <STDIO.H>
3 |0 g, w9 {# c" g% V( I#include <STRING.H></FONT></P>4 i; ~8 \# n: y$ j0 g( I- x9 }% a
<P><FONT color=#0000ff>int main(void)
6 M9 y2 r' [( N. f( v{
6 A5 d6 q: H  U0 F, @: {char *string = "abcdefghijklmnopqrstuvwxyz";
& K7 p9 P- R1 R$ d9 k; h7 wchar letter = 'x'; </FONT></P>
& b! D  L4 G9 Z. `<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
; Y; G: O( j' [# g8 s6 vstrnset(string, letter, 13);
5 E3 M0 i. ]1 y+ _/ _$ ~' N; F- vprintf("string after strnset: %s\n", string); </FONT></P>
7 Q" R+ `" t  U% y<P><FONT color=#0000ff>return 0; 6 ^4 T/ S2 \0 T# Q  ]
} # |# o8 r+ O7 u9 h: O2 n- I+ {2 U$ C/ q
</FONT>
9 r7 x9 m6 ~2 q) \9 T$ v( Z( v</P>% J9 |" u* _+ y! i3 Y4 N
<P><FONT color=#ff0000>函数名: strpbrk </FONT>  b3 [: P+ ~# j; R! r* C5 l
功 能: 在串中查找给定字符集中的字符 . D2 [8 [4 S" q/ I) z
用 法: char *strpbrk(char *str1, char *str2);
4 k, _! `* |- e6 G; o程序例: </P>) B( @4 t. M0 m: f4 R( m+ z
<P><FONT color=#0000ff>#include <STDIO.H>
& K) M0 F. I8 e% [$ ^+ H" A  A#include <STRING.H></FONT></P>' G6 v: P: t+ V) }+ P$ k% `
<P><FONT color=#0000ff>int main(void)
$ J  h5 F; I* K: A% Z{ " V- i8 @1 k$ o( h, K: O
char *string1 = "abcdefghijklmnopqrstuvwxyz";
: B5 L0 `* H) ]- s8 D7 H3 Pchar *string2 = "onm"; 9 a9 T1 W) A! ^  F; G
char *ptr; </FONT></P>
) V+ s$ X/ d& F<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
1 O2 v* w" u3 P5 {5 z<P><FONT color=#0000ff>if (ptr) ( d8 j; G' ~) a4 h  O
printf("strpbrk found first character: %c\n", *ptr); 2 A. U/ P5 @+ |" ]5 m
else
' Q& L0 P( X: Vprintf("strpbrk didn't find character in set\n"); </FONT></P>+ N) [! W; C7 S
<P><FONT color=#0000ff>return 0;
! n; p; l' `  ^6 j. q4 q8 B} 2 \+ n4 u# g- @! z

; A# D+ {4 V5 {1 U7 ]) H</FONT>
0 V# U! t& P5 u, F4 y, L</P>
$ D# P0 [& B9 S9 C$ L& \<P><FONT color=#ff0000>函数名: strrchr </FONT>
" S7 a9 p; P- v" z$ @  S功 能: 在串中查找指定字符的最后一个出现
3 N6 l, M. S% `9 q- b用 法: char *strrchr(char *str, char c);
6 z" M! E: d4 ^8 h+ x程序例: </P>, G2 S% i' x5 {: W/ V
<P><FONT color=#0000ff>#include <STRING.H>
+ ?5 y2 a" W' a2 o#include <STDIO.H></FONT></P>
" b( ?- R- f( I" r1 r<P><FONT color=#0000ff>int main(void)
  z/ n8 H/ y2 U* ?" D" L{ % U. i" P! ^9 M! c' H" Q" [7 d
char string[15];
5 L% q- ^% v- s/ o6 U4 Pchar *ptr, c = 'r'; </FONT></P>  G  J# J' D  M& J
<P><FONT color=#0000ff>strcpy(string, "This is a string"); $ U! d- r" Y$ V, G' |& g0 i6 |
ptr = strrchr(string, c); 4 L/ W3 }5 @2 F. ^. Y( i  j& u
if (ptr) , Z9 G+ @) c  W9 K4 u3 F  \( T
printf("The character %c is at position: %d\n", c, ptr-string);   B0 M  j4 [6 F
else
# d. z+ W' v' {1 x# u" `* |printf("The character was not found\n");
2 h# C# R& L* B# A2 treturn 0;
$ z' W- p5 Z% [) v7 }} </FONT>, t% B( J1 G  w* g
% d' L" C; i0 ^, _

  a$ \, x! _, H6 }' f$ c! u</P>! S' H9 s0 K9 P% p- Z
<P><FONT color=#ff0000>函数名: strrev </FONT>% z& w& ?. G/ t' l  F
功 能: 串倒转 ' ?! x/ U1 C. g  y' }
用 法: char *strrev(char *str);
" e" ?& p  q# k2 I. v程序例: </P>& y; ]8 k8 y5 }' d  J+ F: n6 d
<P><FONT color=#0000ff>#include <STRING.H>
+ `+ r! g6 e! l#include <STDIO.H></FONT></P>0 R4 T' ]; C# w; e2 }
<P><FONT color=#0000ff>int main(void) , E) [& I( P. m; V+ s$ \
{
( l5 t7 X+ T' {$ S* ychar *forward = "string"; </FONT></P>1 b! H7 R  L& D8 ~) N- _9 W3 P
<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
! @: e/ H6 o& M# x6 X) ?9 dstrrev(forward);
+ H0 S& R% f! V9 D& A( v, ]6 e2 A$ Tprintf("After strrev(): %s\n", forward);
4 M& N6 ~) M* a5 P. rreturn 0;
! a% _  `: }% J1 X5 k+ z+ B8 l2 l} </FONT>
% O0 e& N9 n6 [+ x0 |, y: Q</P>, g* u  a) q3 ]# A6 s
<P><FONT color=#ff0000>函数名: strset </FONT>
1 H' d3 g3 r% M6 r# X功 能: 将一个串中的所有字符都设为指定字符   y, K$ I; o. M5 M
用 法: char *strset(char *str, char c); ( @. J  e/ E; D
程序例: </P>
' M7 ~. d$ |& F/ a' Q<P><FONT color=#0000ff>#include <STDIO.H>, |3 M# s+ b3 _: m, q* ?  I
#include <STRING.H></FONT></P>
9 C* N  `0 p2 M9 M<P><FONT color=#0000ff>int main(void) 9 L+ _" |/ P6 F: P9 Q% E# T
{ ) b+ V  j1 S0 U  y* S
char string[10] = "123456789"; # ^. x- E: U. e6 B
char symbol = 'c'; </FONT></P>
0 L4 D+ u7 o, q( M. M5 `' U; Q<P><FONT color=#0000ff>printf("Before strset(): %s\n", string); ' y9 z! T3 T; F2 g# C1 A1 ]
strset(string, symbol);
/ Z! p6 e+ p9 d5 r6 c0 ?printf("After strset(): %s\n", string); ( o: K8 F& `) D; R1 I/ m! Q
return 0; $ Q4 O! v( u; R3 V0 \
} 8 L; C& D: N  X, `6 j3 k7 K; B

. Q! Z. I/ }# x</FONT>& p$ W6 F7 q' R* G- B9 k
</P># ?. z  g2 F! o4 m7 c& Z5 f) K0 X* F) D
<P><FONT color=#ff0000>函数名: strspn </FONT>9 _0 o5 C, X( G, m
功 能: 在串中查找指定字符集的子集的第一次出现 ' t% g3 Z) \# L6 u: |9 |
用 法: int strspn(char *str1, char *str2);
+ L) i$ o1 f; Z. f程序例: </P>  Q0 \" ~% m2 ?) V! L
<P><FONT color=#0000ff>#include <STDIO.H>% i% c. ^1 S0 E  z
#include <STRING.H>
! y4 E8 l5 l( E  ]* r( f8 T: W) H#include <ALLOC.H></FONT></P>
8 k; c4 `3 x- M. |. g$ {+ s<P><FONT color=#0000ff>int main(void) * ^' R1 A  X. R0 y1 M
{
  o0 Y4 K7 T+ e% `5 _char *string1 = "1234567890";
  ^! Y* t* N; Xchar *string2 = "123DC8"; / J- O9 [) r0 Y/ i2 N' G. L, m
int length; </FONT></P>( {; D" W! V! x6 n7 W
<P><FONT color=#0000ff>length = strspn(string1, string2);
- w; m( p$ f# {$ g; hprintf("Character where strings differ is at position %d\n", length); ( G! a) }$ `: f3 [5 O& z* R
return 0; , u6 j/ g! A+ J
} ( i8 v! B9 C$ s9 ^
</FONT>
& y! B1 R, M6 |: b</P>5 s7 z9 w. j" \& A
<P><FONT color=#ff0000>函数名: strstr </FONT>
1 `( ?+ p1 X! Z- m  }6 v功 能: 在串中查找指定字符串的第一次出现 & Q' V5 q' u. x3 M
用 法: char *strstr(char *str1, char *str2);   h! P& c9 T3 o% q  M* B
程序例: </P>( w. `: A+ s: U: R1 G
<P><FONT color=#0000ff>#include <STDIO.H>3 P) h$ h$ j/ F/ U
#include <STRING.H></FONT></P>
% C/ S) u& Z' S% z% p: _/ a<P><FONT color=#0000ff>int main(void)
. v, e9 M6 ]4 J, O# D{ ) p8 ^( t7 |0 o; }' ~
char *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>
( g( [! T8 m7 p) U/ L9 T) u! h<P><FONT color=#0000ff>ptr = strstr(str1, str2);
7 O' H" _$ g/ m/ kprintf("The substring is: %s\n", ptr);
0 R1 X' I- q/ A( j9 E; o- qreturn 0;
' C: k) l% A4 j& v+ z0 O} </FONT>& E* T+ ~* ]3 h3 D+ Y) M' j' k
* a9 L. b, ^! l
</P>$ N2 o) _; k5 {) L
<P><FONT color=#ff0000>函数名: strtod </FONT>! a( L- ~% F& u6 P6 e. P8 \  ?. n1 i& Z
功 能: 将字符串转换为double型值 ' m/ z' @2 _- b# Z/ Y6 F6 Y, {  k7 l
用 法: double strtod(char *str, char **endptr);
0 T& `9 ~" U" _. V( S8 }2 h程序例: </P>
- W! W7 x) s9 G( b: O/ ~<P><FONT color=#0000ff>#include <STDIO.H>
7 v) Q" t5 {. P; k1 E#include <STDLIB.H></FONT></P>
3 h$ _: A" k! r; M" T<P><FONT color=#0000ff>int main(void)
) l5 t, q- {$ w2 o1 Z: Z, d4 S: V+ D{
  o- a/ J( K$ [* j" ochar input[80], *endptr;
. O: F: f, b( P+ ~double value; </FONT></P>( a  e( v: ~8 @0 k) s4 Q5 a
<P><FONT color=#0000ff>printf("Enter a floating point number:");
) w6 Y1 M; c1 L/ k" U% [+ F4 ggets(input); ; k1 I9 \% S  p8 B9 ^. u' C
value = strtod(input, &amp;endptr);
  l+ R7 Z4 W3 ~6 B3 m9 P& }" J/ Q( Jprintf("The string is %s the number is %lf\n", input, value); # `4 b! Q4 ^) U  N+ O) G
return 0; 3 L% v# d9 y/ Q
} ) ]+ X" U$ S3 q
</FONT>
2 k/ \& Z7 m$ Z3 u+ x
" }5 ~* a0 T* V0 l. Z</P>, o0 Y( H) N1 i. V( P; k
<P><FONT color=#ff0000>函数名: strtok </FONT>' h6 H* m: J9 D$ i
功 能: 查找由在第二个串中指定的分界符分隔开的单词 4 f# ?9 I* m1 P( A$ w& C  H
用 法: char *strtok(char *str1, char *str2);
5 K- t8 j& n! H# ?3 E* A4 g程序例: </P>" @6 @! O5 L" |4 p! t
<P><FONT color=#0000ff>#include <STRING.H>
# u/ o& r+ t3 Q#include <STDIO.H></FONT></P>2 h# B9 J3 d) D
<P><FONT color=#0000ff>int main(void)
$ g5 ]1 `7 ~. r# {9 ^{
5 f) g9 h2 ?9 j3 `) k9 Schar input[16] = "abc,d"; 5 R$ P2 J" v! M: B
char *p; </FONT></P>  o6 }: \& @  P, @
<P><FONT color=#0000ff>/* strtok places a NULL terminator & A* v7 G9 s/ r& I* \8 p
in front of the token, if found */ & ~3 W6 {- ]6 ]: Q, ]
p = strtok(input, ",");
- R) j4 M- }/ X' _- `if (p) printf("%s\n", p); </FONT></P>8 Z2 U% Y, E$ R, V# E3 [
<P><FONT color=#0000ff>/* A second call to strtok using a NULL " v6 q4 {. s+ Y
as the first parameter returns a pointer " z$ q% [" I- d, s
to the character following the token */
$ e( ~& @& G. Q$ `5 B( @p = strtok(NULL, ",");
0 p$ j2 P! P! u4 [8 N, {' A6 f0 V6 mif (p) printf("%s\n", p);
9 e& D' G, F3 I# Z# ^return 0;
& f+ K# O: R  Z0 h; G" F) q} ! ]! r- e% H& X3 M
9 r2 M/ z% J% b& Q

* m5 T/ L" X/ _8 Q: e</FONT></P>
) o) ]+ m, N4 O7 H: e+ j: e6 Q<P><FONT color=#ff0000>函数名: strtol </FONT>
' s4 a5 h5 Y  W4 S7 `9 ]! S功 能: 将串转换为长整数
2 M$ \- W& v$ e, ^; v$ u( Q9 j用 法: long strtol(char *str, char **endptr, int base);
/ r: X; ^( s7 q7 _0 }2 T0 |$ e程序例: </P>, A  M0 i# M9 a" @- k
<P><FONT color=#0000ff>#include <STDLIB.H>; l6 R! L! t. f$ g$ \8 q$ Q
#include <STDIO.H></FONT></P>* H5 x6 @1 C; w/ E/ `- V% O
<P><FONT color=#0000ff>int main(void) 5 _8 O8 s" B0 ]  q. q
{ : V5 n3 @1 `9 Y% U+ h& {; |$ P6 \- s
char *string = "87654321", *endptr; / `9 _# T& B9 D( V  j
long lnumber; </FONT></P>1 ]2 k4 }* e5 c
<P><FONT color=#0000ff>/* strtol converts string to long integer */
# U$ K& i+ ~! g! d% hlnumber = strtol(string, &amp;endptr, 10);
' O6 t# z1 P) u( W! Wprintf("string = %s long = %ld\n", string, lnumber); </FONT></P>$ T2 T- c, p% b* q+ t
<P><FONT color=#0000ff>return 0;
/ O$ ^  e$ s6 R" m* F} </FONT>" g4 I7 p/ k7 a. A/ @
</P># x& H/ Z; Q. n/ Q3 k; n
<P><FONT color=#ff0000>函数名: strupr </FONT>( K5 r) [; u* J& L" G
功 能: 将串中的小写字母转换为大写字母
# d5 H- G+ `" h# R( G& X, T) I用 法: char *strupr(char *str);
) ^0 d0 d" Y/ {$ ?. D程序例: </P>  A) X6 Q/ f+ C/ C& o
<P><FONT color=#0000ff>#include <STDIO.H>
/ k- E. G: D. D5 d  q' F! s#include <STRING.H></FONT></P>
- h* q! o" `: ^8 g" \<P><FONT color=#0000ff>int main(void) 2 Z! D1 H+ r. Q0 J4 Z8 w
{
4 [/ \* i) h0 c+ Tchar *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>7 _3 v) p7 Y9 J
<P><FONT color=#0000ff>/* converts string to upper case characters */
( S  `2 E5 M3 r5 mptr = strupr(string);
! f# ?* P! v& _+ cprintf("%s\n", ptr);
) a2 t/ {6 l5 p0 H& F' x" preturn 0;
: R( U6 N( I: o) d: Q$ G% g} ( T. e7 t: K3 n  X* Q

+ y, S" H0 e/ h# Q7 m' D</FONT>9 i3 [0 ^! ]* U1 D0 ?
</P>% f. p3 o' Q) T+ S/ s
<P><FONT color=#ff0000>函数名: swab </FONT>
2 d# k. D5 m( }0 @( A# {# S+ v功 能: 交换字节
6 S! u0 g5 S2 s1 ]. {2 z; N/ i/ k用 法: void swab (char *from, char *to, int nbytes);
) j* P# A4 A0 R* @. l- A: u. t程序例: </P>
0 P& g7 M# m! w6 F. O1 _<P><FONT color=#0000ff>#include <STDLIB.H>
* y+ c8 n' ~2 }  v( t#include <STDIO.H>4 v0 H5 a. U& I" K# _! _- z/ h7 W
#include <STRING.H></FONT></P>9 I. }& V  j8 p$ O
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; ( B) x+ u8 I0 N) x
char target[15]; </FONT></P>0 E2 @+ x6 l6 c( D8 m% s
<P><FONT color=#0000ff>int main(void) 1 ~( n  y* o( T
{ 0 @2 G6 d; l8 O8 Z* d
swab(source, target, strlen(source)); ( ]1 i  `% d3 ^, i8 K' G( J1 F
printf("This is target: %s\n", target);
& ]/ M' V& f4 q4 ^; Freturn 0;
1 _  A7 P5 k$ |5 ]% D+ W- V}
; X5 s( Q$ j3 @2 m</FONT>
, A0 d. t1 S  v# Y& Y- X2 n" \+ M- o( Y- q- V3 L
</P>
8 Y( k1 i6 s! H  B. \1 @4 D<P><FONT color=#ff0000>函数名: system </FONT># X) H8 Z5 _0 n3 d# ?, E7 _, q
功 能: 发出一个DOS命令
. ]2 K( g( j0 g& V, d. M& u8 o) O用 法: int system(char *command); " t/ m6 t# [3 j. I
程序例: </P>
( ]) P) b% A7 o<P><FONT color=#0000ff>#include <STDLIB.H>  S0 g  J0 _+ s7 j8 {( s% G0 |( }
#include <STDIO.H></FONT></P>' J, z, S- H: a8 |2 u7 O
<P><FONT color=#0000ff>int main(void) ! [( {5 Z1 _1 Q% Q& s
{
2 U% g5 _- O0 C- o8 p. Eprintf("About to spawn command.com and run a DOS command\n"); 5 r2 L+ R& v. o! t1 K
system("dir");
" j$ v% q; q) F$ g/ E5 Zreturn 0; ) s1 w) M/ o' E6 c
} </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-7-21 01:38 , Processed in 1.075189 second(s), 51 queries .

回顶部