数学建模社区-数学中国

标题: 函数大全(s开头) [打印本页]

作者: 韩冰    时间: 2004-10-4 02:55
标题: 函数大全(s开头)
<><FONT color=#ff0000>函数名: sbrk </FONT>
7 T/ i5 m" f1 t功 能: 改变数据段空间位置
4 M& S  i$ R7 O0 b! s  }# Y用 法: char *sbrk(int incr);
2 y+ _# ~+ z4 ^1 q0 Q: f程序例: </P>7 T" f- i! i  {9 J; v/ z$ P: \: x
<><FONT color=#0000ff>#include <STDIO.H>
, u2 r' v4 Z# S1 L" P#include <ALLOC.H></FONT></P>
$ Z" v7 L- i% G' ^/ {6 J* q<><FONT color=#0000ff>int main(void) & @2 g0 ~  q7 g
{
; |: W0 N, G$ ~printf("Changing allocation with sbrk()\n"); ! W. D! m% A, M6 z4 ]$ ?
printf("Before sbrk() call: %lu bytes free\n", : i* E% F- X) _' h
(unsigned long) coreleft());
' I* I0 ^2 p6 j' vsbrk(1000); 8 Z: i+ @% F9 g; b- _
printf(" After sbrk() call: %lu bytes free\n", - s; Z$ d0 t$ D% d
(unsigned long) coreleft()); % E" ~- A8 G! m+ Z: k; E
return 0; " O: x# B; Z' m5 x! ^  i
} 0 F( q! J5 E9 s% s4 L8 G4 P. S- g

( u* d& V2 O3 z/ q5 Y</FONT></P>+ E9 |  W1 f- i- b2 f. a
<><FONT color=#ff0000>函数名: scanf </FONT>! D8 u. H" X) O& G+ _; f
功 能: 执行格式化输入 6 ?7 C  a& E/ A  z
用 法: int scanf(char *format[,argument,...]);
7 o4 x' }% v% z0 R& c程序例: </P>) W9 T% q& n  g0 m: w8 P% v
<><FONT color=#0000ff>#include <STDIO.H>* U/ @3 X% G- Y( ~( {
#include <CONIO.H></FONT></P>, W% F5 s# X( ^" B: {
<><FONT color=#0000ff>int main(void) 3 E7 ], e- F3 B. z  M
{ ' {2 K0 k3 z9 r4 J$ n
char label[20]; 2 e2 |/ Q  i7 |
char name[20]; 7 s# a7 Y( L0 P
int entries = 0; % S* C0 i0 _( {& v' }3 F. I
int loop, age; , k) X. v3 A  M0 i
double salary; </FONT></P>
! c/ k: i& g$ T2 [! m<><FONT color=#0000ff>struct Entry_struct
# v( c& K* J( g! a& z3 m{ & x* i: }1 y- o# r0 r6 r0 G6 O
char name[20]; 9 z: X# N: G. J3 s4 H" ]
int age;
9 a& m+ k3 P3 H* m! _float salary; ' z% W$ m. x& i( o4 e% |! B
} entry[20]; </FONT></P>
; u* X! t  {1 L<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */
0 m6 N$ ~! g0 G  ]$ s% J$ {printf("\n\nPlease enter a label for the chart: ");
4 r8 V" d$ Z  p1 ~% @1 ?scanf("%20s", label); * Z6 c$ ]. H2 {8 A9 S
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>9 ]  k# u* \* b. k/ B$ [
<><FONT color=#0000ff>/* Input number of entries as an integer */ / {9 R# W6 Z; v# A/ R4 t
printf("How many entries will there be? (less than 20) ");
5 m, q, R" w. l2 [/ r  s4 h* W0 u  ascanf("%d", &amp;entries); 4 w4 C- D- ]7 H6 M
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>/ G& B3 @! M) [) H9 n4 W% E9 r
<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ 6 k1 Y# B2 J7 |3 d" T
for (loop=0;loop<ENTRIES;++LOOP) # ]* \) y/ o1 _; `+ J
{ ; X* Y0 I% O/ Q5 A
printf("Entry %d\n", loop);
, C8 O4 w# a  G  Z5 ~printf(" Name : ");
/ }' f' X/ S/ P6 p( t5 i+ V2 T# ~scanf("%[A-Za-z]", entry[loop].name); 3 \' q# P' ]5 ~: z
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
( D2 B) M& l$ g& H! {5 H<><FONT color=#0000ff>/* input an age as an integer */   i  k( t3 F' P, Q
printf(" Age : "); 1 g& A* a8 B( L& O5 s6 i6 M
scanf("%d", &amp;entry[loop].age); " _5 z/ P, p* T% z( D1 y
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
6 E9 y4 c7 S$ B1 a$ J6 `$ ?, `<><FONT color=#0000ff>/* input a salary as a float */ ' ^! R9 m, ^: ^
printf(" Salary : ");
+ \2 B& U: |* @, m- G* u6 oscanf("%f", &amp;entry[loop].salary); : x( l) i. _' V" I
fflush(stdin); /* flush the input stream in case of bad input */
- J$ T0 T4 P" J4 _9 E, \+ q9 S} </FONT></P>& y5 ~5 q! `# T3 c
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ * {, u' O( w! o+ c5 M
printf("\nPlease enter your name, age and salary\n");
" p0 `; |+ ~, \+ T! ~- Mscanf("%20s %d %lf", name, &amp;age, &amp;salary);
0 x  j: n7 }) }</FONT></P>% t' ]- q6 J) _# x+ B6 y: V
<><FONT color=#0000ff>/* Print out the data that was input */
  V' e2 ~: _6 `printf("\n\nTable %s\n",label);
2 ?6 \8 N( D# r" U+ \( n+ fprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary); 2 E3 t5 @0 U& K* q7 j) j
printf("-----------------------------------------------------\n"); ( o# d0 w' G- ], t  C
for (loop=0;loop<ENTRIES;++LOOP) 5 G. R( Z7 H0 T4 l
printf("%4d | %-20s | %5d | %15.2lf\n", 3 o% {) J0 h; Z2 ?* ]
loop + 1, 6 r4 |3 |0 N. h: x
entry[loop].name, 0 ]2 h  L/ g  h5 U; t0 Y
entry[loop].age, 6 w2 }: @, D( F8 y3 a2 X
entry[loop].salary); & B; e0 B/ W+ j
printf("-----------------------------------------------------\n");
" y( l' D8 A& H' A" Z$ T+ dreturn 0;
  W2 E7 S" Z! P* M* Q}
- b; A9 C! e7 X2 u: M! S! T; G</FONT>
1 P* [! K0 `( D" a# c</P>7 P' A: I" ?) w  _
<><FONT color=#ff0000>函数名: searchpath </FONT>
' c) s! p- N. ~# K+ ]( g功 能: 搜索DOS路径 : j2 [( S8 \0 |
用 法: char *searchpath(char *filename);
8 v8 x% X1 e/ b) v5 J程序例: </P># f. x  S0 v5 U" K; d' f  M
<><FONT color=#0000ff>#include <STDIO.H>
6 b1 O, c) a) S' I. L#include <DIR.H></FONT></P>
$ V" z5 M0 O, S! t( J. m<><FONT color=#0000ff>int main(void) 8 S9 t0 T" n2 L' |% j, G' ~* d
{ 3 q! Y: ?- D. D+ w/ @" ~# P* z
char *p; </FONT></P>/ h7 G7 s0 t, h8 _: i' k
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
$ J0 x7 `6 ?, O; U. Oto the path */ ; V! `$ B$ q$ C( a5 \4 K# s8 }
p = searchpath("TLINK.EXE");
3 X6 g: t' x* q' p+ A* q1 uprintf("Search for TLINK.EXE : %s\n", p); </FONT></P>
& J' X; j, F; ^. }0 l) }7 D0 b<><FONT color=#0000ff>/* Looks for non-existent file */ + Z, A. a/ |0 f: l2 ?
p = searchpath("NOTEXIST.FIL"); 2 o. T/ O( A8 p/ @1 A: C
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>' U: p+ a2 [6 s
<><FONT color=#0000ff>return 0;
0 e2 X5 Q* Q$ ~9 R9 c. ~} ) b: }2 |6 e5 N" ~( K# m: t

1 d9 e" l0 I! c, B/ x% k" k6 a$ ~</FONT></P>
2 `. e9 a9 @0 J<><FONT color=#ff0000>函数名: sector </FONT>8 x, }6 t+ V8 w: Z' `# B$ M, T
功 能: 画并填充椭圆扇区 . P* m$ Z: B3 g5 g+ X+ z
用 法: void far sector(int x, int y, int stangle, int endangle); $ O- ^4 `% g! q6 r0 ~! H; v3 {# q. [* C
程序例: </P>- I( ^2 ^9 S$ B& t
<><FONT color=#0000ff>#include <GRAPHICS.H>
- Z. [3 w7 H( C#include <STDLIB.H>
  ^$ [3 ~  X$ [; u7 R#include <STDIO.H>1 n! q5 W% q9 A- n7 @3 J
#include <CONIO.H></FONT></P>4 e: Q+ o) K6 I6 L
<><FONT color=#0000ff>int main(void) 7 J* ?! H8 g6 X5 T9 |' X/ g; i
{
! P9 a. F+ M6 \+ }( d/* request auto detection */ , ?) O& e) Z( [
int gdriver = DETECT, gmode, errorcode; 2 s7 P+ b8 T* v' m+ [/ {. v) w  o  ?9 e. ^7 K
int midx, midy, i;
8 g0 f) b" |+ \, Cint stangle = 45, endangle = 135; " w4 r- n# j; g: l; N. Z
int xrad = 100, yrad = 50; </FONT></P>" P) {' X& P8 k9 h6 u3 `
<><FONT color=#0000ff>/* initialize graphics and local variables */
. H3 P- L/ @' Q+ ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) B! h2 u* E$ L5 Z<><FONT color=#0000ff>/* read result of initialization */ / i8 U3 s, s  y5 b8 O8 J! E
errorcode = graphresult(); % q* P- |& K- I
if (errorcode != grOk) /* an error occurred */ % N& k9 y- b8 j
{ 3 c! c7 d! h5 o5 K' V. H2 d. G
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . B$ M9 y; V  Q* H# R. d
printf("ress any key to halt:"); ; J, j+ o6 ?' k( E$ ]/ o% U
getch(); / I  [$ J0 X) L( T) Z
exit(1); /* terminate with an error code */
2 t4 X; N0 Y9 P6 J} </FONT></P>
, R1 y- N! A, }. q& M  s. F<><FONT color=#0000ff>midx = getmaxx() / 2;
3 C  L) ?5 G7 X/ C4 B. ^$ Z& K1 Lmidy = getmaxy() / 2; </FONT></P>/ n; j+ h$ U4 s9 Y! J2 w! P- f- I# }
<><FONT color=#0000ff>/* loop through the fill patterns */ $ R/ m" C! o3 u5 `6 A8 B
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> {
; m' L9 U% b' P9 {. o/* set the fill style */ 6 u: Y0 h! c1 ~; Y( h- E
setfillstyle(i, getmaxcolor()); </FONT></P>
* B% T$ W0 o9 K7 e3 P9 C! ^<><FONT color=#0000ff>/* draw the sector slice */ % ~$ J% X* C, V1 p( K+ m
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>
# r! Y5 e! @# N' b; k" |( \5 w<><FONT color=#0000ff>getch();
- l% h: t! G0 L% b} </FONT></P>
8 W- V0 K  `: |* r7 G/ {# s<P><FONT color=#0000ff>/* clean up */ # Q# J2 ^# v6 K7 e3 |
closegraph();
& v6 o8 ^' k4 N" @return 0;
4 `- ?# x+ r% [4 L( R* j}
. z, p  y# W* v6 H( G+ h3 ~</FONT></P>
1 ^% }  S% W% j" i2 _* N0 ?& e3 f<P><FONT color=#ff0000>函数名: segread </FONT>5 y  i3 C- @8 _
功 能: 读段寄存器值
' U& |1 ^' c( n" h- Q' @3 j6 T8 t; Q用 法: void segread(struct SREGS *segtbl);
. S; [0 Z- X- i: P) `: ]程序例: </P>5 {8 z- M  Y- Y1 S+ h: r" i
<P><FONT color=#0000ff>#include <STDIO.H>
9 ]- L9 X8 n' R" D#include <DOS.H></FONT></P>, ]% d4 _) u) v
<P><FONT color=#0000ff>int main(void)
. I! l0 q" E2 x9 E* _{
* W1 F( `9 n* Z5 W8 ~7 Xstruct SREGS segs; </FONT></P>1 q& [5 L) ?$ @  A& p
<P><FONT color=#0000ff>segread(&amp;segs); ! b% s& j7 \0 @# m% L/ {# ]
printf("Current segment register settings\n\n"); " J( l  P+ m. A6 p
printf("CS: %X DS: %X\n", segs.cs, segs.ds);
/ }0 I. v! A! i2 N. K# T( ~2 V: iprintf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>
  M2 w* _! _. L! p9 M$ {+ a<P><FONT color=#0000ff>return 0; 8 P4 h- z9 Z) C; |
} </FONT>; Q/ L$ @! G  t0 o9 G( Y4 D) W1 e1 v! k
% {* C- J+ {0 @5 j
</P>9 @0 `9 |/ ^& U/ d2 _1 }
<P><FONT color=#ff0000>函数名: setactivepage </FONT>/ }+ J! ^+ t. S' E
功 能: 设置图形输出活动页 2 |) c% d  v7 G7 I0 m+ Y. ~7 w
用 法: void far setactivepage(int pagenum);
, g$ [! B5 k% M4 J( }5 ~程序例: </P>
8 b( U% t5 ^0 d/ S<P><FONT color=#0000ff>#include <GRAPHICS.H>
* f: V2 h9 C# o: K( t; h3 `#include <STDLIB.H>
1 h5 a" f0 q  B$ _#include <STDIO.H>5 N6 r5 a! |: |2 U6 [$ z+ c2 _
#include <CONIO.H></FONT></P>
' _. O3 T4 P( k& C1 s& d<P><FONT color=#0000ff>int main(void) . n; A8 x" _& `& e) v# @9 d7 U
{ $ c3 t; _+ q' M9 V0 H; h$ n) C1 J1 [
/* select a driver and mode that supports */
; D  L; w5 P# t; w9 O/* multiple pages. */ 6 _0 L- x# J* R  r& Z
int gdriver = EGA, gmode = EGAHI, errorcode;
1 t8 u+ Q% C, j8 A, \8 Hint x, y, ht; </FONT></P>; w$ K- k! R/ @& h6 {
<P><FONT color=#0000ff>/* initialize graphics and local variables */
4 ^- V3 \1 }7 Dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
- q% X5 Y5 C' L; q6 @- u: Y<P><FONT color=#0000ff>/* read result of initialization */
# O- C+ ^, V0 U5 C. u; n; verrorcode = graphresult();
  S  J% M& E" [- E3 ^. m  E% ^4 \if (errorcode != grOk) /* an error occurred */
9 y+ o2 x3 J" E( v/ J{
% c* q0 g' M4 R3 m) a/ b% Zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 0 p" n. Z/ O: w' [& n# s$ B
printf("Press any key to halt:"); 4 g8 s- N7 N1 j% |/ f/ I
getch(); " _9 V8 G0 b+ b0 A  B3 l- A
exit(1); /* terminate with an error code */ 8 C% o, s" e) ~4 ?9 E, z8 y# S' R
} </FONT></P>
4 o$ D& j; }% a6 x; d. s, X<P><FONT color=#0000ff>x = getmaxx() / 2; # l5 V8 t+ F6 d; l
y = getmaxy() / 2;
' p5 A/ ~, T) n- cht = textheight("W"); </FONT></P>6 `# U1 s  v2 t
<P><FONT color=#0000ff>/* select the off screen page for drawing */
8 R6 g1 \1 X! k' Esetactivepage(1); </FONT></P>
8 [+ d6 k5 ?& k2 g. G& P: ~<P><FONT color=#0000ff>/* draw a line on page #1 */ ' C6 U% M2 \& _: ^, I8 W
line(0, 0, getmaxx(), getmaxy()); </FONT></P>7 n1 G+ g1 X1 t/ i
<P><FONT color=#0000ff>/* output a message on page #1 */ ; X1 `( M6 w$ U. _1 {; J
settextjustify(CENTER_TEXT, CENTER_TEXT);
! I' k0 c. e0 h2 ]% Routtextxy(x, y, "This is page #1:");
8 D- m' m* {2 |' ?) }" C+ x& Y9 Couttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>) r; Q* V( m3 c4 w' r
<P><FONT color=#0000ff>/* select drawing to page #0 */
$ s5 m" H+ V6 [, @$ ]/ bsetactivepage(0); </FONT></P>+ m9 }; v% m  u0 \9 \
<P><FONT color=#0000ff>/* output a message on page #0 */
2 d/ T  r0 F9 ~4 gouttextxy(x, y, "This is page #0.");
( o# k( |8 }# t8 ?  ^outtextxy(x, y+ht, "Press any key to view page #1:"); / m% ~( r. g5 |$ W. I9 c: a3 ^
getch(); </FONT></P>
/ E/ A& j! ?! n& X+ |, @<P><FONT color=#0000ff>/* select page #1 as the visible page */ 1 `( s4 @/ J0 V6 t7 ^
setvisualpage(1); </FONT></P>) q6 d! n5 Z5 U3 z4 N% \
<P><FONT color=#0000ff>/* clean up */
* R9 k* P- S8 ^: r( Ggetch(); # y+ o- B( g, z2 U. r/ U! k2 \$ |
closegraph(); ! d7 `$ n4 w/ t! r. m# ?! g
return 0; & @' L. j9 [! r5 X1 {
} : X5 A# u0 A! Q. M
</FONT>
) C" A. Y* Z0 n6 |' h</P>
: Z) b: x' O2 {% g0 h" @<P><FONT color=#ff0000>函数名: setallpallette </FONT>- \- ]8 Q, W3 R' M  `" r6 }
功 能: 按指定方式改变所有的调色板颜色
" F' L& z6 c0 L7 {5 I用 法: void far setallpallette(struct palette, far *pallette); - S4 N6 M" {4 o! o( H5 I( r: k& G
程序例: </P>
. l! Z" C6 Q7 e% q9 `<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 E' R7 T4 J' G+ s7 }#include <STDLIB.H>: L$ e, o) E4 W- G; Y, d7 e
#include <STDIO.H>
% j. O$ H) X/ {- c" b* H3 W; h#include <CONIO.H></FONT></P>6 B" A* O1 c- n2 b1 Y& a+ `
<P><FONT color=#0000ff>int main(void)
2 M) |7 ?0 g# N4 M* j( n0 _& s{ $ w4 _. p  r; h+ N- Y
/* request auto detection */
+ Y+ h% g* ]' [* `" C8 ]4 sint gdriver = DETECT, gmode, errorcode;
9 X1 `' r4 \) }1 @& a* F4 f) o9 Estruct palettetype pal; 7 N6 f" c% d* w. J* o( g! r
int color, maxcolor, ht;
' u: Y; q+ F2 ~+ P9 y5 iint y = 10; & ^; ]* K; `& o4 _% K
char msg[80]; </FONT></P>
. {& b( _6 P" P. z' ]  l( W$ X<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 k0 d/ V' i3 D, k" r" w5 k
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( u2 W. q5 E  J$ L( m; c<P><FONT color=#0000ff>/* read result of initialization */   d0 |* t( ^+ [7 L2 {/ \9 z* d
errorcode = graphresult();
+ c0 x+ E/ T6 ^+ T( pif (errorcode != grOk) /* an error occurred */ 1 f% W9 g: o3 s
{
' i+ |8 |2 m; l7 i: b2 W  Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
0 E0 t4 _& V+ t4 {/ {, U3 G. Qprintf("Press any key to halt:");
* D9 a0 e7 m/ sgetch(); - q5 ~2 m" q# v6 u# V% \
exit(1); /* terminate with an error code */
7 R* D' Y  [# Z, ]} </FONT></P>
; @7 J9 k, H% w; u7 c( x7 @) P<P><FONT color=#0000ff>maxcolor = getmaxcolor(); 7 `% e( G' z7 T, `% W5 u: ?$ E
ht = 2 * textheight("W"); </FONT></P>5 [6 N5 z* h5 a: E, A: ^
<P><FONT color=#0000ff>/* grab a copy of the palette */
+ T  B5 K. p- p' a" `8 I8 rgetpalette(&amp;pal); </FONT></P>
/ y7 B) {3 r- P4 |/ _6 e1 A<P><FONT color=#0000ff>/* display the default palette colors */
4 [% K, s- z% @: W! n6 v* ^for (color=1; color&lt;=maxcolor; color++)   x) ?9 x) Q) {! H7 x4 [
{ / G: G$ {9 t! C- r( U
setcolor(color);
6 S4 Y# p0 J9 e( Msprintf(msg, "Color: %d", color);
- ~2 y  ^, v( S. ^  Oouttextxy(1, y, msg); ! ~- G+ R7 B/ D( c+ V# Z
y += ht;
5 _: L$ A1 @& Q5 w# H} </FONT></P>
9 K6 ?3 u1 u/ j' Q3 q; U$ u2 E<P><FONT color=#0000ff>/* wait for a key */ - M* `; R6 ~3 j8 f' r' w6 |/ A4 q
getch(); </FONT></P>
# ~% y- G" K" O! j" |% J<P><FONT color=#0000ff>/* black out the colors one by one */ ) ]3 b* O/ \( `; q
for (color=1; color&lt;=maxcolor; color++) 0 k* O4 Y; |. u! a# t+ @
{ * i5 I: D4 x. q7 \9 q
setpalette(color, BLACK); . @  ?6 |# y( ~
getch();   [1 P% Q% `& ^/ Q: s/ {
} </FONT></P>
2 h7 c. c! I  M' z<P><FONT color=#0000ff>/* restore the palette colors */
, G( h4 i1 f9 e9 b* dsetallpalette(&amp;pal); </FONT></P>
* i% ?. s9 w, v- q<P><FONT color=#0000ff>/* clean up */
! e* L( q5 {" c; [/ `8 a4 cgetch(); : g0 U! @. M% O: i2 U
closegraph();
! x/ B0 m$ y: X: X# |return 0; 7 t! m# w0 R  @) D- }  s" V
} / x( _! f( q0 o4 Q) i# D

8 s# x4 d  F" |/ c: M- U</FONT></P>/ ~& b: @8 {1 z& e
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>0 K" P2 V0 z! o+ h. \
功 能: 设置图形纵横比 9 S( ?# C! T$ ?+ h  V6 \7 @& \* g
用 法: void far setaspectratio(int xasp, int yasp);
. b$ F! N+ R% g1 o7 H4 D* q9 g程序例: </P>
; Z; m! K  S% n+ K3 U: G; `& k<P><FONT color=#0000ff>#include <GRAPHICS.H>
' O8 {+ {% p% G) ~1 v# U7 _#include <STDLIB.H>
: S, G5 I) K1 t3 D2 V#include <STDIO.H>
0 b; d. i  z4 n4 A1 {#include <CONIO.H></FONT></P>
" K+ w! q8 A+ ?. X- q' Z) g<P><FONT color=#0000ff>int main(void)   k- ]7 L+ W2 ^% D
{
; P2 Q+ L, @( [; b- B/* request auto detection */
3 w" w. q4 _6 @' _- Gint gdriver = DETECT, gmode, errorcode; 6 ]! O  {' b4 m. B& p
int xasp, yasp, midx, midy; </FONT></P>
( _; u+ F; R# u* B. N% \6 ?% U<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 |& C& y$ E7 e7 V9 S7 W3 |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# l1 n: C" X  _! f<P><FONT color=#0000ff>/* read result of initialization */
6 ~: P7 R0 h5 \% m( e" ^: cerrorcode = graphresult();
" e1 i" H1 _7 R( o: S, Vif (errorcode != grOk) /* an error occurred */ $ F: B0 K* a. S. x/ o
{ . H: d% B. t! X. {. y6 G2 _) w# U. a
printf("Graphics error: %s\n", grapherrormsg(errorcode));
: X$ ?" Y8 M& R- r* [printf("Press any key to halt:"); & o9 M6 _8 ]- j8 {0 P. C, t# w/ d
getch();
9 w9 R# G" c: G3 M; m5 L# R3 mexit(1); /* terminate with an error code */ ; y6 o& `& d3 C- f* j2 z( j
} </FONT></P>: r7 u% ~1 @( W- @4 a+ e
<P><FONT color=#0000ff>midx = getmaxx() / 2;
; O1 x8 P9 A6 S, dmidy = getmaxy() / 2; ( H( I0 R* o3 V" p, T. G, @
setcolor(getmaxcolor()); </FONT></P>
# @+ L- f/ f/ ?/ i% ^1 R<P><FONT color=#0000ff>/* get current aspect ratio settings */
. B' \, \* L; S$ y9 y3 p: {getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
2 @! _; n9 {# A* V  B- u/ t# l" Q<P><FONT color=#0000ff>/* draw normal circle */ 8 i$ b) G9 R; J0 C& ?. t  Z: Q) [+ q! o
circle(midx, midy, 100);
  G4 v: q7 Q0 x  m( @getch(); </FONT></P>5 }$ z! @2 ~, S( C3 [' I
<P><FONT color=#0000ff>/* claer the screen */ " z' g9 b  ~' k) m4 Q0 }3 a- N& l( J
cleardevice(); </FONT></P>& C1 k# U+ _# D2 k' ?6 @6 R8 T; [
<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */ & M$ V- q/ p% s+ h7 P, _9 |: r
setaspectratio(xasp/2, yasp);
' [9 @* P2 O: ~2 j+ @  M+ O1 gcircle(midx, midy, 100);
; C+ l3 b1 F$ N+ x+ Qgetch(); </FONT></P>
% t* s0 l7 o2 V" @3 Z# c<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ 5 O! _. M; w0 x0 K' E+ J
cleardevice(); " z) G: s6 |; i0 i1 L
setaspectratio(xasp, yasp/2); 0 }! a* I4 D5 x. F; D& Q- ?
circle(midx, midy, 100); </FONT></P># f5 m+ {% I7 c: P$ b' d. D
<P><FONT color=#0000ff>/* clean up */ , J+ }/ I4 y4 I6 O# g
getch();
5 c* c; u6 `7 j! yclosegraph(); , [. F( j1 \0 U" Y
return 0;
. Q7 y( M8 g7 k} 8 Z  W, Z, f/ h, g
</FONT>
8 R/ T# y) `9 R* \$ s</P>
: Z& Y- \, \2 r/ b# I+ }<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
7 v* D5 L9 Y9 y/ [( I功 能: 用调色板设置当前背景颜色
9 n9 c" a0 M7 v! {2 L" V/ v; e用 法: void far setbkcolor(int color); / `! M6 ]1 b8 n4 o
程序例: </P>" b7 W4 |# O. F/ h
<P><FONT color=#0000ff>#include <GRAPHICS.H>
2 z6 \7 z# }2 X* s#include <STDLIB.H>
# [( |7 Z$ @; @#include <STDIO.H>
$ E% l8 u+ L9 N. q3 _#include <CONIO.H></FONT></P>
- c% R5 S9 H4 L. N( r/ i+ `<P><FONT color=#0000ff>int main(void)
2 P$ m. q: V3 h" n7 I{
# M0 o6 G, W/ q- X. o/* select a driver and mode that supports */
: t9 f0 M2 |0 k/ Y5 X4 F8 i3 Z/* multiple background colors. */ ' \2 ~0 \, y6 w
int gdriver = EGA, gmode = EGAHI, errorcode; ' x( D/ q* m* f1 V1 v- p! W; E
int bkcol, maxcolor, x, y;
: A" t- I* H! Mchar msg[80]; </FONT></P>: C. |. A5 P8 d# j  n( z; X2 L' K
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 3 w; G) z! I$ d2 c! Z" j1 C6 Y+ u
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
- `( @4 ]: r/ u# r7 y( O<P><FONT color=#0000ff>/* read result of initialization */
9 c4 w2 j7 G4 `) ~" N3 R. M) Verrorcode = graphresult();
: j* x% J3 C4 s9 `$ uif (errorcode != grOk) /* an error occurred */
9 }% f7 a# A; U  H{
' ?. [) p- ?8 R0 Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
) ?# j& k' R. o3 o* jprintf("Press any key to halt:"); / j5 P* e1 U+ w5 i8 _
getch();
+ I) `, S' P% o5 ^$ q6 wexit(1); /* terminate with an error code */ 2 e# ?0 T# d; D
} </FONT></P>
$ m) Z/ M. Z" y& b3 ~" {<P><FONT color=#0000ff>/* maximum color index supported */ & N. t% ?1 y4 c
maxcolor = getmaxcolor(); </FONT></P>
1 b5 @' G" g6 Z$ U& {<P><FONT color=#0000ff>/* for centering text messages */
3 R  C! l3 {4 k3 y# o. N" k& K7 Isettextjustify(CENTER_TEXT, CENTER_TEXT);
& D6 u" ^+ B; V; Q, S1 {! b4 S8 @3 xx = getmaxx() / 2;
2 a8 e% N" Y; W0 B! I) j+ }y = getmaxy() / 2; </FONT></P>) W: H7 q+ Q5 D/ u5 {$ N
<P><FONT color=#0000ff>/* loop through the available colors */ / Z1 f: r) A: ]4 q4 B/ k7 ^
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
- `6 B5 v, I" E5 h) X5 g{
5 W1 P! u$ b! g& [/* clear the screen */ 7 m! e1 {$ C, T& S3 z; e
cleardevice(); </FONT></P>
0 f% r" X- z' F! o3 w0 F1 ^<P><FONT color=#0000ff>/* select a new background color */ ( G9 I6 k9 R' R! H- x" [
setbkcolor(bkcol); </FONT></P>
  a) k9 Z0 U# K5 ]" r, J1 M2 i3 f<P><FONT color=#0000ff>/* output a messsage */ + Y+ P0 c* h# v# |) N. |
if (bkcol == WHITE)
) z: e/ x1 J8 p! Msetcolor(EGA_BLUE); ) u* ]: k8 ~0 P0 `7 r
sprintf(msg, "Background color: %d", bkcol); 7 w+ `$ S) [* Y3 F% z; h! D
outtextxy(x, y, msg); - U  D/ p7 f( v, d6 p, j" z# `
getch(); - C% L+ ?5 n7 l% O+ n* z# P
} </FONT></P>
0 X5 }7 H& r- F6 p: o<P><FONT color=#0000ff>/* clean up */ % A4 B, F5 O. u
closegraph();
1 F6 p0 J- Y( z, Zreturn 0; # z8 d6 \* z$ H/ o
} </FONT>: p5 _7 o6 O* r( _; U8 O

7 ?' U& `# a- \5 l7 V, m9 m  U</P>3 ]8 s- d: U5 G% _1 N
<P><FONT color=#ff0000>函数名: setblock </FONT>$ o' O, M6 p2 r4 h4 S% R2 d
功 能: 修改先前已分配的DOS存储段大小 & {6 }: [5 ?3 s; A
用 法: int setblock(int seg, int newsize); : X  B) ]6 o# r! P$ ^, p+ P! V( K
程序例: </P>: }4 Q, F  m; x9 o+ [, V( l
<P><FONT color=#0000ff>#include <DOS.H>; x( _: r0 L. E# }$ g2 X
#include <ALLOC.H>; E# C: q  x  B4 l3 a
#include <STDIO.H>
1 |% a3 P2 z. j& |1 e/ ~* _8 U5 r9 x#include <STDLIB.H></FONT></P>
! f7 W. k! D" |1 \  u$ l, m<P><FONT color=#0000ff>int main(void) / N. Z4 Z! d- d/ v
{
: k- v, {7 Y; a5 s6 w! e: G6 Qunsigned int size, segp; 8 b: G8 [$ L: D2 `
int stat; </FONT></P>
7 v9 z6 P' R0 S' x, @: y<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */ 7 x* [3 b# M$ Y8 c3 a. U
stat = allocmem(size, &amp;segp); 9 A% Z+ N' C) q. b
if (stat == -1)
% ~9 F" e, x# U" ]printf("Allocated memory at segment: %X\n", segp); $ m9 {0 A- t. f
else % _6 w- ^. L0 {+ {$ k
{ - Y4 c+ T5 r4 U. x" H* T
printf("Failed: maximum number of paragraphs available is %d\n",
) i* x3 A' k" xstat); 7 C4 L+ s# B/ ^- V1 y5 R1 l
exit(1); : V, F$ \. @% k, g1 O: ^
} </FONT></P>2 J& Y- r( F0 q1 Q$ S
<P><FONT color=#0000ff>stat = setblock(segp, size * 2); ! f2 n/ U+ k- U  v& C4 X" k
if (stat == -1)
$ N7 H+ M9 _8 x. [( a! X, Nprintf("Expanded memory block at segment: %X\n", segp);
; R: s- B$ x: d$ yelse ) t7 x, r1 O. E
printf("Failed: maximum number of paragraphs available is %d\n", / M# B* X3 z3 D) T7 B% l6 v
stat); </FONT></P>- T, A" b6 Y  T' M5 s3 g
<P><FONT color=#0000ff>freemem(segp); </FONT></P>3 \* y& y2 X; w; n0 @. c
<P><FONT color=#0000ff>return 0;
% u5 a5 B/ h2 M2 j}
2 ?1 b9 \! Q7 f3 o4 _</FONT>- ]8 H+ {3 M8 T, _+ I
</P>% |* T5 `0 ?) _! O, `& b
<P><FONT color=#ff0000>函数名: setbuf </FONT>9 P; L8 u  Q9 w* J
功 能: 把缓冲区与流相联
& r; q/ \1 S$ b5 y3 F/ s3 w0 J  u用 法: void setbuf(FILE *steam, char *buf); 9 s8 J  G0 J, V5 W) K
程序例: </P>+ P# p; e7 N1 ]* q8 u- m  V
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
; H7 ~; N1 B  e5 P# f* F* U<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */ 6 s( F9 b7 y0 S% u
char outbuf[BUFSIZ]; </FONT></P>
1 p0 Z$ Z% R6 A9 Q* E<P><FONT color=#0000ff>int main(void) 5 J$ @8 ~" l# o8 n
{
6 Y8 p' b2 f, R. O0 m1 l7 c/ W/ V/* attach a buffer to the standard output stream */
4 Y, @& n# w: Z4 u+ o2 a( c/ u2 i: Rsetbuf(stdout, outbuf); </FONT></P>: T* C4 ]+ G5 R  G
<P><FONT color=#0000ff>/* put some characters into the buffer */ - w# R( T$ G  E$ c: y
puts("This is a test of buffered output.\n\n");
4 P5 `# |; i+ f( X9 g, ?5 L: H  C1 Jputs("This output will go into outbuf\n"); 0 ^# w" R5 Z# {  S, W7 n& m3 t- i
puts("and won't appear until the buffer\n");
2 ~7 o" B( c" O4 b) O5 |puts("fills up or we flush the stream.\n"); </FONT></P>
* a) ?7 K% t2 Q/ ^<P><FONT color=#0000ff>/* flush the output buffer */ 5 J- R9 I4 _* M1 u- U  ^
fflush(stdout); </FONT></P>3 G- y# [2 {; g6 e0 u
<P><FONT color=#0000ff>return 0;
) }3 P; s7 x2 d/ i- [} ' Q6 P( V& ]& T2 E  n0 W8 t5 l
</FONT>
  R( p: i% J5 A' |) y2 `( W$ F</P>1 O3 v5 P1 V- {; ?" b
<P><FONT color=#ff0000>函数名: setcbrk</FONT>
! K% i# q* K. w. m. G% s; o3 @功 能: 设置Control-break - X# O5 a- }/ B9 G1 A
用 法: int setcbrk(int value); # E5 T; E. G8 E5 K
程序例: </P>, `& s; A1 T8 g" Y  k
<P><FONT color=#0000ff>#include <DOS.H>
' ]0 G9 j5 y  f( O#include <CONIO.H>/ u" X, K) s4 g) Q
#include <STDIO.H></FONT></P>0 s" M3 L( g, n9 T
<P><FONT color=#0000ff>int main(void) : T3 j6 ^8 Q4 Q) \& l# {: p. X
{ $ Q7 K0 F$ Q( G; k. C
int break_flag; </FONT></P>, r0 h2 }0 m3 Z# c4 a3 Q5 ^% P! Z( {
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n"); # J+ }& T3 `7 ~- `9 M- s
printf("Enter 1 to turn control break on\n"); </FONT></P>
) j$ ?; j' y7 s6 E( _<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>" ^, D/ ~( s/ D! k# g
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>
. E4 e5 [2 |7 G6 m1 p<P><FONT color=#0000ff>if (getcbrk())
- ~6 Q* z0 `7 Dprintf("Cntrl-brk flag is on\n"); 9 }" o, w8 ^: p: C
else 7 c( _' s6 W9 \! M/ o$ n3 F
printf("Cntrl-brk flag is off\n");
, G" h; I, l7 ]' u& e1 }! c0 l5 creturn 0; ; e9 D4 a& Z+ P9 [/ V9 N
}
; Z0 N; s* l8 B& F9 L! c) l* ^* n. i6 I- M) [8 A
</FONT>, V1 m, E7 e! e3 G  X
</P>. k  i5 o! x1 j, u
<P><FONT color=#ff0000>函数名: setcolor</FONT>
% T4 E7 J! a8 n9 ?! y* [7 F功 能: 设置当前画线颜色 ' z4 ~3 |0 G& i
用 法: void far setcolor(int color); ) y( V5 o) ~  Y$ N
程序例: </P>! K6 w1 ~, h! j0 o! [. P' b! ~0 R! }
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 H: P+ a7 l6 I! Q+ }#include <STDLIB.H>& ~$ N3 |2 C  c7 g
#include <STDIO.H>
( u' R9 M! l( K- P6 [#include <CONIO.H></FONT></P>
9 E7 P0 b" [) X: G! i; n. C<P><FONT color=#0000ff>int main(void) ) k& G- N4 i3 y* R+ ]
{
2 ?1 q2 T7 M; \3 ^! ?$ A1 @/* select a driver and mode that supports */
# m6 r& {8 X& e( r9 Z" b. J/* multiple drawing colors. */
! L* j" s  h! _: M9 lint gdriver = EGA, gmode = EGAHI, errorcode; 0 [, ?" R0 @9 Y5 O7 ]) K4 K; x
int color, maxcolor, x, y; 9 [, K: s5 ]7 @/ z; R
char msg[80]; </FONT></P>
. ?5 ?' H  L( M/ K  X( N<P><FONT color=#0000ff>/* initialize graphics and local variables */
, l2 Q2 P% k+ {/ Uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ h$ a# [% t6 k6 _1 o& b
<P><FONT color=#0000ff>/* read result of initialization */ $ e2 h7 Z; d; V+ ~* D
errorcode = graphresult(); + v+ _; V- b: Q9 V# d
if (errorcode != grOk) /* an error occurred */ 8 j, b( K) |2 r2 n9 F' w4 i  h+ H
{ # e1 P7 z9 I  ~1 M- S/ B
printf("Graphics error: %s\n", grapherrormsg(errorcode));
. w( t9 V% r% n1 l0 a7 pprintf("Press any key to halt:"); " S% G; ]- P2 q4 m; k. o
getch(); 1 i7 W8 z# \$ P& ?! B+ @0 f$ w4 U0 r
exit(1); /* terminate with an error code */ 2 y) b4 I. [9 e& T
} </FONT></P>: q8 `$ S: [; {
<P><FONT color=#0000ff>/* maximum color index supported */ 3 H7 t, n/ m4 h. Z! A
maxcolor = getmaxcolor(); </FONT></P>; c( \0 ]5 p' P
<P><FONT color=#0000ff>/* for centering text messages */ 4 ^0 S' f3 Q! B4 D+ Z
settextjustify(CENTER_TEXT, CENTER_TEXT); 1 U5 q6 W) l" ]7 S7 E" D
x = getmaxx() / 2;
; j  x* n9 G' A: uy = getmaxy() / 2; </FONT></P>
% a# A- q) L6 {4 L5 `9 k( X" @$ X<P><FONT color=#0000ff>/* loop through the available colors */
! }$ P9 N( T( j" B3 j  Tfor (color=1; color&lt;=maxcolor; color++)
5 \0 O2 T" @5 n: \) v{ 5 K3 L* W# J% Z4 h5 V4 t
/* clear the screen */ - p) g6 k! x5 e+ }8 y. X
cleardevice(); </FONT></P>+ j* M+ j3 z( v
<P><FONT color=#0000ff>/* select a new background color */
- p2 x7 D3 }+ D; m- l$ |) Asetcolor(color); </FONT></P>
" ]. J; u2 \) c8 p, c: p<P><FONT color=#0000ff>/* output a messsage */ # k$ N1 k: {/ O$ c
sprintf(msg, "Color: %d", color); # Q6 |/ x. J3 h: p8 O
outtextxy(x, y, msg); 1 o5 O% e& a; n% Q( T0 I+ O
getch(); 9 Q  z6 o5 V$ `, Q3 Y1 L
} </FONT></P>
+ J' p: D4 Q: Y7 e9 e1 J<P><FONT color=#0000ff>/* clean up */
2 |4 ~6 }8 @9 D* K3 Y5 nclosegraph(); 9 b9 B# e- V9 K% P+ [0 f
return 0; 8 u* Y, l( ^# i+ P# t* z$ Y
} % X/ [+ [% y% u; P& @* ]( u* m
</FONT>* }, ^, T& D4 I% L
</P>2 t$ n+ X3 p5 O' W% }& Y" F
<P><FONT color=#ff0000>函数名: setdate </FONT>2 O1 h2 a' [8 Q& T
功 能: 设置DOS日期 : \! C4 H6 V# G; d
用 法: void setdate(struct date *dateblk); 5 c+ j  \: z7 P" [! {4 s6 d* Z2 N
程序例: </P>: |: `9 _  W; h% X. Y: I5 q4 G- O
<P><FONT color=#0000ff>#include <STDIO.H>
  R( D+ Z  \: ~2 ~#include <PROCESS.H># c0 g* U) Q: b+ a9 Q" k3 B7 I
#include <DOS.H></FONT></P>
# D$ K% B. a, r5 C1 @<P><FONT color=#0000ff>int main(void) ; w; P  C: N. P
{ % y$ F% z, i4 r. t, x8 `
struct date reset;
' a( y5 |4 W2 U) C: r1 p) a2 S% Hstruct date save_date; </FONT></P>
- _- d, Y' x, i: q<P><FONT color=#0000ff>getdate(&amp;save_date);
" _; a% O; j# Zprintf("Original date:\n"); 5 o2 N1 Z+ r. l+ }- ?/ L2 l( ]3 E2 U
system("date"); </FONT></P>! U4 A* q; r9 \6 j. h( J5 ]4 Z! {
<P><FONT color=#0000ff>reset.da_year = 2001;
" N. }8 j1 H1 A! J* ~reset.da_day = 1;
% U- M3 f" O4 g* h, P- f" Nreset.da_mon = 1;
+ X* D  q% y; N( ssetdate(&amp;reset); </FONT></P>
1 T. E6 |1 \1 K' H% h$ H: k1 s<P><FONT color=#0000ff>printf("Date after setting:\n");
% C+ |$ |  B7 h: Q5 e- L* E1 ^system("date"); </FONT></P>
+ E. M! m( r9 \1 `; N* |<P><FONT color=#0000ff>setdate(&amp;save_date); ' E2 {/ g4 ^5 v# g% p  n
printf("Back to original date:\n"); ' y/ B0 t* }+ m
system("date"); </FONT></P>+ h- t! g7 ^2 o$ b
<P><FONT color=#0000ff>return 0; 9 `5 d/ x  w$ w3 G, F
}
3 M0 `  {8 ~9 Y# q2 |5 ~& v. g) Z! ^</FONT>
1 ]; f# H9 i7 @. a/ U: K</P>4 \" i4 D, s; g. C
<P><FONT color=#ff0000>函数名: setdisk </FONT>
  X3 u1 [/ ?( x! X1 r功 能: 设置当前磁盘驱动器
" a' E0 m: j7 V1 @- Z# D用 法: int setdisk(int drive); 6 w% H! K  C, u/ C
程序例: </P>0 e+ `! P- N- h, x$ k; K7 p
<P><FONT color=#0000ff>#include <STDIO.H>9 r1 n( L8 f: C+ I1 C
#include <DIR.H></FONT></P>. d' ]! N6 q; v. P* u$ }, T
<P><FONT color=#0000ff>int main(void) / U& e: s# z4 G* V8 c
{
, e& A! P2 j) s, H- y2 sint save, disk, disks; </FONT></P>
0 c9 x+ G5 [- S' A8 T9 z# g5 v) a  q<P><FONT color=#0000ff>/* save original drive */ 7 q5 A6 v  c3 o; d
save = getdisk(); </FONT></P>
+ r! T+ q* }4 |0 W5 c<P><FONT color=#0000ff>/* print number of logic drives */ 6 z% G& J2 E  ?3 U3 c
disks = setdisk(save); " H* c' S7 F) V- N) v5 M. g" J
printf("%d logical drives on the system\n\n", disks); </FONT></P># b: b# Z+ u; w) T% B
<P><FONT color=#0000ff>/* print the drive letters available */ ( j3 I3 i  x( V
printf("Available drives:\n");
! x8 {  e8 W2 E, q' t) R! ffor (disk = 0;disk &lt; 26;++disk) . c5 ^% T+ g' O+ ~
{
+ a1 i. z; V: k6 ^8 f. w' D% ]setdisk(disk); $ d( E6 v. d' h5 n
if (disk == getdisk()) 6 y3 M; {( T  B3 i% M
printf("%c: drive is available\n", disk + 'a');
# |% J) F6 D& n} ( L0 A! y( u& c" y; T% S
setdisk(save); </FONT></P>" z% i5 ?6 J  ~0 U
<P><FONT color=#0000ff>return 0;
3 D2 n) `8 [6 p5 w} </FONT>; {  Y' s! i: J. {- L

: ]: K& J! h7 g( g1 |</P>* R, Z" @4 d0 b7 V( w! N
<P><FONT color=#ff0000>函数名: setdta </FONT>
5 S- T3 ?1 W+ b, D: W' d" j功 能: 设置磁盘传输区地址 ; T( q+ H. n' d: m
用 法: void setdta(char far *dta);
0 t/ Y$ \1 d) K1 C$ r程序例: </P>% G: w" O9 ]( E% |/ ~5 z! W6 n' O1 _
<P><FONT color=#0000ff>#include <PROCESS.H>
7 ]' B  ^, V/ ]#include <STRING.H>& E, M: K9 n  u* d! [3 x
#include <STDIO.H>
1 A3 C3 Y; W  U- T. w+ k8 ]#include <DOS.H></FONT></P>
' O0 j/ `/ e/ {, C' V<P><FONT color=#0000ff>int main(void) ' k. K3 |! G. w% O% p" C
{ 6 ~5 ^/ ~  K$ A9 t( C, v4 m, \
char line[80], far *save_dta; : a0 `$ K4 i! |* t7 J
char buffer[256] = "SETDTA test!";
# y7 e# ], r' nstruct fcb blk;
! X6 H  ?/ y  |- p' a8 B% Y$ Zint result; </FONT></P>1 h. k: W% d- g, w. y" T7 v
<P><FONT color=#0000ff>/* get new file name from user */ 7 {$ |! n1 ]" N/ q$ `
printf("Enter a file name to create:");
" x1 G" A! |8 i% g1 ?6 qgets(line); </FONT></P>, v% }) z# s; w$ r
<P><FONT color=#0000ff>/* parse the new file name to the dta */ 9 Q# D* r! o9 J/ v
parsfnm(line, &amp;blk, 1); - a: S- D8 W4 d+ @5 ~5 I) l9 V: z
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
* o' `3 j( h" N1 ]<P><FONT color=#0000ff>/* request DOS services to create file */ ( e' h  e; L. V# o3 y: O( {
if (bdosptr(0x16, &amp;blk, 0) == -1)   F" O8 r* A+ [
{
9 |6 s* L2 T" Fperror("Error creating file");
9 S3 c& M9 d0 ^$ H" Y  a# \, Pexit(1);
0 m- Q! ]% q& t' q7 o4 [} </FONT></P>7 |! I& O! N0 ~$ ?: N
<P><FONT color=#0000ff>/* save old dta and set new dta */ ' F+ v- k3 G% [" O; L
save_dta = getdta(); # S. f8 V0 h9 w5 K5 ~- N- n
setdta(buffer); </FONT></P>% X& N5 y2 [$ S
<P><FONT color=#0000ff>/* write new records */
5 [0 T0 V6 y4 ?4 U$ @  r( Pblk.fcb_recsize = 256;
1 _/ ^4 J" ~9 `3 v* X/ d( z% \1 ]blk.fcb_random = 0L; 9 l: m" p" u" k8 l# t( Y- g
result = randbwr(&amp;blk, 1);
: [4 [8 A$ v+ B$ {0 g% Aprintf("result = %d\n", result); </FONT></P>; v3 N5 [/ }2 X6 M
<P><FONT color=#0000ff>if (!result)
3 ?# \! U- G# w% U: k% a2 V6 Mprintf("Write OK\n"); 9 u6 y6 p7 t$ z+ u+ n
else 5 f: ]2 w3 M& L8 Q4 }& a
{ . x( g% w" Y8 h8 H$ c2 z. ^
perror("Disk error"); ! P1 C  w* R! Y9 M5 Y# V
exit(1);
& l1 D) T, Q8 R. S. A  V8 c} </FONT></P>
- Q' S" a" p; \# G& u<P><FONT color=#0000ff>/* request DOS services to close the file */ " }- }* }" H% k0 d' w
if (bdosptr(0x10, &amp;blk, 0) == -1)
- E. G, v3 H, S) z, c{
: x  b& q( a+ t+ Z" fperror("Error closing file");
, N& l8 l& U2 N7 o. kexit(1);
, s, N/ V( L, ~* v. K- _' K} </FONT></P>
  R5 ~/ _' F6 ]' f# E5 i' v$ U1 a! B<P><FONT color=#0000ff>/* reset the old dta */
* M6 A  A0 Q1 }1 v' A% Wsetdta(save_dta);
  F/ O+ @! E8 a& P. ~8 ]+ V! A( kreturn 0; " t9 b) A: x  f) S# ?  `
}
3 T. L& v3 N0 u' Z9 T# v</FONT>% L: x+ M3 l( h+ m
</P>1 J  ?* C4 H* S3 @
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
/ S& Y. r: j* Z* B/ b9 a' \0 y功 能: 选择用户定义的填充模式 % i. l. }6 m" p7 v1 W
用 法: void far setfillpattern(char far *upattern, int color);
- g& }5 g3 e! }6 j程序例: </P>, L. F* i6 s+ u# I
<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 Q* S. F2 V0 n& x4 m: t8 c#include <STDLIB.H>
: ^, Z' F: d9 C6 [1 q& R#include <STDIO.H>
1 u4 Q$ b1 l4 {1 E  l$ B: ~#include <CONIO.H></FONT></P>9 a& O" G4 X2 }/ J7 l
<P><FONT color=#0000ff>int main(void) 3 Z0 ~1 E' v0 a( M, a$ O
{ 5 M7 L0 z3 k* g) i- w# K
/* request auto detection */ # Y) B: c! s" Q9 d! R
int gdriver = DETECT, gmode, errorcode;
# K. V+ V5 p+ i0 v, iint maxx, maxy; </FONT></P>
) S3 B1 s0 O' N: I+ ^; {<P><FONT color=#0000ff>/* a user defined fill pattern */ 8 j  ~3 b6 {: L$ |# }; v  }
char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>
! Z6 Z, w  {' r1 |2 X1 ^<P><FONT color=#0000ff>/* initialize graphics and local variables */
# k7 B+ a' \4 Q# ^1 Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! T; x, a; U  {8 R, j( O
<P><FONT color=#0000ff>/* read result of initialization */
7 m& W7 H0 R8 |. x, Jerrorcode = graphresult();
) q1 ^+ @7 z& e: a. oif (errorcode != grOk) /* an error occurred */
4 S! A) n" {/ n: E{
5 ~9 N6 A: t7 eprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! j% S$ q2 s4 \+ X& Y. h) {printf("Press any key to halt:");
6 z4 B) h5 l9 Hgetch();
3 W, K8 ]# A1 x; ~$ Qexit(1); /* terminate with an error code */
) O; C4 o# y+ C& _5 e} </FONT></P>; v: c3 X& X5 [. _" t
<P><FONT color=#0000ff>maxx = getmaxx(); ; ?; l$ S1 }. N- o) H
maxy = getmaxy();
" `0 u* s% y2 m9 k! B: _: ]& asetcolor(getmaxcolor()); </FONT></P>
! f" j  F: e6 N: J4 U<P><FONT color=#0000ff>/* select a user defined fill pattern */ ( _+ C) D' Y$ O: N
setfillpattern(pattern, getmaxcolor()); </FONT></P>
/ l+ G" c$ k2 H& v<P><FONT color=#0000ff>/* fill the screen with the pattern */ : v2 e) K; i$ Q; t% ~/ y
bar(0, 0, maxx, maxy); </FONT></P>
& `8 k: S  i" K/ d<P><FONT color=#0000ff>/* clean up */ # b) T7 W8 w3 b% f3 r
getch();   p# Y, G& n' _7 d" c
closegraph(); 8 a4 x! Q& Q1 A, T$ v. |+ l
return 0;
: n% {  q  h# I} 1 b, b5 _- S2 J* G0 l" U/ ~; `
</FONT>" |0 U5 g2 m# f$ E, x) y- f
</P>
# [1 L6 k$ k. z0 V  p' g& b# r<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
) Z( [7 E# r( V/ f& e0 Q' ^功 能: 设置填充模式和颜色 / w1 v: V$ h4 L* u: |& l
用 法: void far setfillstyle(int pattern, int color); # l. m) |) N: g2 D
程序例: </P>" \. c& V$ P8 ^. T
<P><FONT color=#0000ff>#include <GRAPHICS.H>  Q2 X/ i& _0 N8 z- J- ~
#include <STDLIB.H>
- T1 B' @+ x0 D#include <STRING.H>& s( Q- Y) O# X
#include <STDIO.H>
5 E" c) H# P7 k#include <CONIO.H></FONT></P>7 K/ s8 i- {  W8 S
<P><FONT color=#0000ff>/* the names of the fill styles supported */
  p, n# K! j( j( f/ `+ }; nchar *fname[] = { "EMPTY_FILL",
! N8 c* I  G, u. @/ D  O3 ^% \/ b"SOLID_FILL", ! r: P) t6 v# V, Q" X6 W" H
"LINE_FILL", , J; z9 ^) F9 m6 s3 z/ i; R. g* F7 d
"LTSLASH_FILL",
$ @" y; I5 ~; Y1 j7 E7 O"SLASH_FILL", 2 `. R& R' r# w8 l% j& Y
"BKSLASH_FILL",
0 w$ _% G: `9 b/ \"LTBKSLASH_FILL",
  d+ j# ^# D, C- V"HATCH_FILL", ; w9 P0 I9 x# J4 H: C
"XHATCH_FILL", 5 N/ w5 ^' o, E
"INTERLEAVE_FILL",
% g5 |0 x. I" r"WIDE_DOT_FILL", 8 J# i5 E) U5 h$ o
"CLOSE_DOT_FILL", 6 |# C# {" ?, c2 P# ^
"USER_FILL" # \7 e( p7 s; A$ |0 i
}; </FONT></P>( e6 {+ P& \1 _1 V2 m. V, }
<P><FONT color=#0000ff>int main(void)
- H- {. G/ d1 z: B% o7 ?8 y{ $ g+ ^. r2 @6 g* A; \% M/ E
/* request auto detection */ 1 ]$ V6 N8 k* |
int gdriver = DETECT, gmode, errorcode;
3 n2 g( Z0 i/ a& yint style, midx, midy;
5 r" [% ^& v; f9 i9 |5 xchar stylestr[40]; </FONT></P>0 x4 F' S2 }. D; i2 j
<P><FONT color=#0000ff>/* initialize graphics and local variables */
/ {' F' J& A2 b, b( L% Yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% l9 G- W( O6 B+ B<P><FONT color=#0000ff>/* read result of initialization */
) A% P) o% E9 i( J/ p2 M  Rerrorcode = graphresult();
1 {' p  b/ r9 lif (errorcode != grOk) /* an error occurred */ 1 N# P3 {/ p* r; M  g
{ * I6 H& c# X/ W  c$ b; U* v: P' ?6 A9 ~
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( K% `/ G  P/ {$ C6 Wprintf("Press any key to halt:"); % o% J9 O' L/ _7 @- O* g4 C5 Q
getch();
& v- h6 ?6 {4 V) ?( Y, }1 zexit(1); /* terminate with an error code */ # C5 f: P5 m" F* E) Y; t
} </FONT></P>
2 p- w- `. H5 t<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 Q. j( ^: p2 {) e, A; S5 omidy = getmaxy() / 2; </FONT></P>, E1 h  J1 ^3 _- b# {
<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) 4 R  }" a% F; Z! c
{
. [& f' ]" q# u+ q1 l. ]5 e/* select the fill style */
5 U; a8 w" l% {1 a5 ssetfillstyle(style, getmaxcolor()); </FONT></P>
- s3 t2 ^2 U- V# D<P><FONT color=#0000ff>/* convert style into a string */ 0 [9 t" S: ?, O1 W7 l  u: i  V& V
strcpy(stylestr, fname[style]); </FONT></P>
5 I# |; K( ]: M$ Q/ X; w<P><FONT color=#0000ff>/* fill a bar */ 3 t' A$ }+ F# k5 I1 d; R& A6 \9 z
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>
7 ]$ H2 W" D- j3 t3 R; O' I, J<P><FONT color=#0000ff>/* output a message */
2 q2 [4 T  Y* ?; T) qouttextxy(midx, midy, stylestr); </FONT></P>; e- n7 M# [* V% Y- j% q+ C( a
<P><FONT color=#0000ff>/* wait for a key */ # \3 n9 w/ E# A
getch(); $ {4 I: Y. I1 o8 }) S
cleardevice();
  `& A3 A2 I& _" l3 H} </FONT></P>
1 i5 q% X5 H. l1 T; @7 k. o<P><FONT color=#0000ff>/* clean up */ ) ?- e( P; E! G7 H) s5 a# l
getch(); ; |( g/ G5 q' M) Z1 s& N# K, P
closegraph();
) h0 W. \8 Q. Y/ }return 0; $ R& C" H; v3 Y3 a1 W9 c; }3 O
} </FONT>3 w% C+ \6 }+ O

5 h4 c6 H, b& x</P>
5 g, H9 s( h7 k6 O" D<P><FONT color=#ff0000>函数名: setftime </FONT>
' H! E' g( r4 G7 m: K9 a) G功 能: 设置文件日期和时间
# {. ~7 @& u7 T" i9 y用 法: int setftime(int handle, struct ftime *ftimep); 5 x. Y+ j( E! |% C5 i5 G- f8 V
程序例: </P>+ U5 @2 M% V" a, F/ q* r, k
<P><FONT color=#0000ff>#include <STDIO.H>
; w/ _/ k7 H2 |9 P0 ?+ a' J$ R#include <PROCESS.H>0 @# |. y; t$ @
#include <FCNTL.H>% V( R" J" d' F# f6 \
#include <IO.H></FONT></P>
8 L4 |9 L, p5 t$ I" o<P><FONT color=#0000ff>int main(void) * S' l* F2 `6 T5 x9 z
{
8 a2 i8 _; h9 V& n- P" V6 Rstruct ftime filet;
3 F" d$ q- \( ?5 f9 B" ?FILE *fp; </FONT></P>
9 E- V, X" T. U! b3 S<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL)
! f+ m% k% T7 y+ T{
  B- V: C. T# e! C. i! Operror("Error:"); 1 ?( K  U! t3 E0 z& J7 H
exit(1);
" U6 x; O8 @" D2 J8 T} </FONT></P>" q7 q" y0 s8 |5 x' A( ~
<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>0 E* G) b2 B% R7 F& u0 Y/ R: S! u& N+ X
<P><FONT color=#0000ff>/* load ftime structure with new time and date */   u  V6 D& N3 C
filet.ft_tsec = 1;
: d3 U# r( S% n" t' }. N, p/ cfilet.ft_min = 1; & @% l9 }) v( T" h% r
filet.ft_hour = 1;
8 j7 n! {; s* i. [filet.ft_day = 1; + a) @0 I+ T3 K" f  |9 T+ U: B
filet.ft_month = 1; 6 T1 C5 j9 d% @3 p& Y: Q% s
filet.ft_year = 21; </FONT></P>2 {( O' E5 Y% K+ q5 b
<P><FONT color=#0000ff>/* show current directory for time and date */   w3 N0 m2 h% Z3 F5 p6 a
system("dir TEST.$$$"); </FONT></P>
2 h. _, V0 }9 u) O+ b<P><FONT color=#0000ff>/* change the time and date stamp*/ " x9 _. }7 I2 y6 e2 f' z
setftime(fileno(fp), &amp;filet); </FONT></P>
; G; u/ |( T3 l3 X<P><FONT color=#0000ff>/* close and remove the temporary file */ & C. C4 K# K: l3 |, b* O
fclose(fp); </FONT></P>
) a5 @7 @- q% Y- x$ ^<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>) v/ _- F6 x* s- a1 e; J! A
<P><FONT color=#0000ff>unlink("TEST.$$$"); 3 m8 ]6 H) ^( v
return 0; / f, u' w4 G0 c. H% i( K$ S
} 4 \( o: z& S: p# w& r$ Z
</FONT>
0 `( V; }/ l% e+ A3 \</P>: b1 w0 K. L5 R( H4 t
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
6 ~8 ^* [: X8 T+ ~: u% J* g8 {% q功 能: 改变内部图形缓冲区的大小
1 p# Y* q' L% m1 z) Y8 B用 法: unsigned far setgraphbufsize(unsigned bufsize);
& U, x" ?6 J% ^9 W8 y程序例: </P>5 j7 Y; q$ }$ d: C8 |
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ ^  B' g3 M, u#include <STDLIB.H>
3 d; j9 l- K/ H5 N#include <STDIO.H>
$ B7 C3 \9 |  n' C, }( u#include <CONIO.H></FONT></P>
+ c" ~* `3 X7 x<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>. I$ J/ F$ a. P
<P><FONT color=#0000ff>int main(void)
0 U% {; i1 j) ~9 v( \6 m' g  r{
# }9 W& y' g; z& A# Q6 \/* request auto detection */ 0 O" [0 D& m( d* d: S& r
int gdriver = DETECT, gmode, errorcode; . `7 _1 ^9 U4 q( n
int x, y, oldsize;
* [+ `* r  G6 o. _- m# Hchar msg[80]; </FONT></P>7 L7 G) h% I  E) l9 g# f
<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
/ N, o& \! G/ f# v# O! H+ N/* before making a call to initgraph. */ + I( N% I3 e* g) z" m
oldsize = setgraphbufsize(BUFSIZE); </FONT></P>
! Y& w3 o3 t% M# i! H, d<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 \* p' E+ M$ A: j" ^: q& F
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' J3 Q+ M1 M* ~<P><FONT color=#0000ff>/* read result of initialization */ & B" Z, C* }  \0 l* \  h. J
errorcode = graphresult();
( F0 ?7 c* L" ?- P3 M- [if (errorcode != grOk) /* an error occurred */ 7 A2 f6 x# H1 O% x% W6 i/ U4 D
{ 9 k5 A+ A4 r1 U8 Q- S9 z. z
printf("Graphics error: %s\n", grapherrormsg(errorcode)); * Y9 `3 P5 s8 P. p, P/ a$ f7 H0 O2 Z
printf("Press any key to halt:");
# E$ U  `5 m! Fgetch(); 8 m5 `5 x8 i) u' ~
exit(1); /* terminate with an error code */
" i! t: \9 a" h0 F} </FONT></P>! P) k- Z7 J( ]* w; U+ S8 I6 w+ B
<P><FONT color=#0000ff>x = getmaxx() / 2;
9 e  B& x& P8 f# V5 L- Ry = getmaxy() / 2; </FONT></P>1 g+ O6 b: X5 Z. z$ p8 q
<P><FONT color=#0000ff>/* output some messages */ ! H! c  ?5 B$ A, U- T( S  ?) m
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
  @$ A; R8 P, x6 x7 csettextjustify(CENTER_TEXT, CENTER_TEXT);
+ G# @/ o2 [0 U% k+ @9 V% iouttextxy(x, y, msg); # V9 _9 R' o% W# x* I
sprintf(msg, "Old graphics buffer size: %d", oldsize); 5 O/ [) m! h" h+ Z7 e9 N0 u
outtextxy(x, y+textheight("W"), msg); </FONT></P>
( \( t) Y5 W* r7 W1 X7 m<P><FONT color=#0000ff>/* clean up */ 4 M7 Q$ ~# p6 D8 i, x7 ^
getch(); 2 }& _6 p: F/ ?/ s% Y, ?
closegraph(); % @  t  E- c6 j( [" w. S' T
return 0;
; Q7 u* F! s) `1 X: z; h}
( Z" g6 C; A2 b# _; t$ b( N; a
/ R. J( \! B$ R" {3 K0 V# O7 ^$ a6 m/ N1 U
</FONT></P>" t3 c- J# k) E& e7 a
<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
( c( u* K1 c8 z+ [1 n1 x9 J功 能: 将系统设置成图形模式且清屏
; ]' P$ D9 d* X" K9 o0 M用 法: void far setgraphmode(int mode);
7 d; L  s) t8 w4 g程序例: - {! c+ F8 @* K2 ~! t6 R% G

3 b( T  ^9 q# M<FONT color=#0000ff>#include <STDLIB.H>
. B( Y) ]# u* E. w8 c# r#include <STDIO.H>
9 v; B: L/ j( E) r: L/ @#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
' i# ?% v& E8 r9 ~4 w5 ~/ T2 b+ P- V/ @<P><FONT color=#0000ff>int main(void)
/ `% I$ q5 Z8 w0 I{
/ q, u1 L0 w; o1 y9 H. A: k/* request auto detection */   l; X1 ]" O' q" d/ t* W
int gdriver = DETECT, gmode, errorcode;   X1 A& E2 A+ Q' |/ [& W5 q4 f
int x, y; </FONT></P>
# n, B* e, n& n% Q. d<P><FONT color=#0000ff>/* initialize graphics and local variables */ % n7 h+ o$ a8 Q- O, V7 h5 |- \
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' y7 R2 ]% P- \" H* S<P><FONT color=#0000ff>/* read result of initialization */ " u! R2 G7 f" o+ H$ e/ Q: \
errorcode = graphresult();
( _) V( A+ x& lif (errorcode != grOk) /* an error occurred */
4 s3 u8 a- R3 h' P% v: i{
; q- I$ y2 a/ y* H- p! v8 Aprintf("Graphics error: %s\n", grapherrormsg(errorcode));
# ~( r( w; D5 i4 [# [printf("Press any key to halt:"); $ Y" o0 H" P7 O" F' Z# t
getch(); * L7 k$ h. ^# G2 d$ p
exit(1); /* terminate with an error code */ : o, I6 f% ^6 [; j2 z) M& K4 s
} </FONT></P>
3 n' G( g' U+ |' p<P><FONT color=#0000ff>x = getmaxx() / 2;
) A% w. K9 N9 u9 W& P. F/ ay = getmaxy() / 2; </FONT></P>/ H' u3 k9 z" B2 W, q: A$ w% @. r5 ~
<P><FONT color=#0000ff>/* output a message */
7 q; g& h' {; y( o4 h  y+ u# Xsettextjustify(CENTER_TEXT, CENTER_TEXT); 7 A& Q% G& H5 F; g# c  Y& R" l
outtextxy(x, y, "Press any key to exit graphics:"); % ~! B# p/ B. ^9 b! U) C
getch(); </FONT></P>
3 _# |+ d' u/ W- A  g) |<P><FONT color=#0000ff>/* restore system to text mode */
8 E$ ~4 Q" K0 T" orestorecrtmode(); 1 }, S6 g3 k5 M! |7 ~
printf("We're now in text mode.\n"); 3 M, [1 h; [8 `$ ^7 j4 L
printf("Press any key to return to graphics mode:"); 8 g  ^+ o- K0 X  R# U# R
getch(); </FONT></P>3 r' i4 J+ w6 n5 T9 y: n9 F
<P><FONT color=#0000ff>/* return to graphics mode */ ; q/ y* f- W+ I+ i# {5 ~7 B+ {
setgraphmode(getgraphmode()); </FONT></P>7 J$ ]  o. b, ~. q% H* f
<P><FONT color=#0000ff>/* output a message */ 8 ]! G3 Q/ f( M$ y; o: X4 D
settextjustify(CENTER_TEXT, CENTER_TEXT);
% H# W! c# e6 E  W& Routtextxy(x, y, "We're back in graphics mode.");
/ m' I2 S  U' j/ u9 Louttextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>5 g$ R' c0 m# J# j) b
<P><FONT color=#0000ff>/* clean up */
1 w0 U" y" `7 ygetch(); ) m* \6 \/ f: g* _' E; {
closegraph(); ' g6 S7 v  U! a* ~3 O' I
return 0;
  n/ G6 T. Z- A+ |! `}
9 e0 H! K. \" ]! n7 g; k
1 ^% o% _& T6 o* `# J0 J* r* [
</FONT><FONT color=#ff0000></FONT></P>
  D+ N2 t& h. `$ y4 Q, |$ c<P><FONT color=#ff0000>函数名: setjmp </FONT>. \  x7 z. |. n3 a: {: b* U/ x, u
功 能: 非局部转移 + ^2 M" X: c7 N4 C  L- P
用 法: int setjmp(jmp_buf env);
+ y7 \* f& O1 ?) n$ L程序例: </P>
4 B% @. w# c1 j8 b: o# ?- |<P><FONT color=#0000ff>#include <STDIO.H>6 H- @4 I5 X. [4 g4 l+ y6 _
#include <PROCESS.H>
& w2 h6 x" p- i1 P#include <SETJMP.H></FONT></P>& L4 K* f% Z8 B' u3 m0 t. ]* Z
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>" t1 l& a( O- ]4 W. F) S! R: S
<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>/ Q; s) p  l; ^
<P><FONT color=#0000ff>int main(void) ; y4 [2 j$ X/ |0 `9 q4 V4 ~; Z
{ : F8 h0 P/ ]+ [9 e9 q$ |! n% a
int value; </FONT></P>
9 a- @- p; a; Y1 p" O<P><FONT color=#0000ff>value = setjmp(jumper);
9 F, e) v8 S8 X3 Y5 F+ ?- Zif (value != 0)
: \9 f( z5 n9 s) X* T{ , ]" @& V) p$ I) Q+ Z; f5 y- F
printf("Longjmp with value %d\n", value);
" a) F; i# r4 t4 X2 v1 dexit(value);
' K) Z0 H" i" |, a4 P6 \6 B, F5 K}
: f& L4 u, }. [& M: l# i2 _. dprintf("About to call subroutine ... \n");
$ i) r) j4 A2 lsubroutine(); " P3 m7 U- ~' C% I
return 0;   j6 f$ K& U0 @) s+ g
} </FONT></P>- z; V3 l- e8 a, j) H- C. n
<P><FONT color=#0000ff>void subroutine(void) - [; v+ W1 b8 T5 z, o4 s$ M/ x7 y/ d
{ 9 L; U: G# ?* r% i  _6 j5 V
longjmp(jumper,1);
- H% y/ x4 B8 G) U( p& x8 w} ) ^/ O: W! ~9 R' D! W: D9 o$ w- E
</FONT>
5 o. S  a/ b' y& h9 H8 f0 y</P>0 c/ I, k# r* v  Y/ M8 l
<P><FONT color=#ff0000>函数名: setlinestyle </FONT>) @3 Y! L# C; K! m
功 能: 设置当前画线宽度和类型 " l' l* x6 J" A/ w- P* S. G( y
用 法: void far setlinestyle(int linestype, unsigned upattern); % y% l0 X( h  _3 U
程序例: </P>
4 C1 \8 s$ b* }9 H. Z! t! H<P><FONT color=#0000ff>#include <GRAPHICS.H>
* r$ Y" `6 u1 @8 }9 |: n#include <STDLIB.H>
) T! g/ k# k! Q! A7 \' n6 u0 @3 F#include <STRING.H>
) @4 M" I  n, f! p#include <STDIO.H>
- n& Z. m7 [+ i2 g#include <CONIO.H></FONT></P>
. }9 A9 e! D/ \& W/ _& f<P><FONT color=#0000ff>/* the names of the line styles supported */ 5 J; U  Z' Q3 {* ]. _
char *lname[] = { + N9 N  H6 I, P* F$ ], u2 g" p
"SOLID_LINE",
: H. a: g! C8 k2 r5 w"DOTTED_LINE",
& N0 w1 j; l1 b4 p& G  R0 I"CENTER_LINE", 6 n0 I- g  R0 e
"DASHED_LINE", * H& Z- `$ s. e! E$ u" S7 d
"USERBIT_LINE"
( p$ t- s. E5 r: X2 h( f2 e9 h}; </FONT></P>
/ Q- ^: T0 g4 \. j4 N. w) G<P><FONT color=#0000ff>int main(void)
7 G. m2 W' f# u; M+ k* o- _{ / s4 n, G+ s' t
/* request auto detection */
% D0 }, K* H' t7 B  ]int gdriver = DETECT, gmode, errorcode; </FONT></P>+ K+ O5 h' y- I. s. i
<P><FONT color=#0000ff>int style, midx, midy, userpat;
2 o7 }% R5 Y6 a  x) B0 B* }4 S2 }char stylestr[40]; </FONT></P>
: h) G( V6 C& S7 f! a& y<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' {( ^0 i0 L5 k  i
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
; `* X! P7 d4 v8 {4 M' c5 q7 `<P><FONT color=#0000ff>/* read result of initialization */ 8 H0 `; K7 w7 l+ I' M- o
errorcode = graphresult();
: h/ I+ }) D  m6 x5 d* ~% m. V) Gif (errorcode != grOk) /* an error occurred */
- R6 _3 o: N  M( a  e+ ]; F7 M9 O{
; y. ]2 t: N$ B- A% Z6 n& |printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 |$ b0 ?# c8 v7 `  r1 c: dprintf("Press any key to halt:"); , t. \9 o2 y7 K. S7 i$ J* Y+ l
getch();
5 q2 `) r  g5 |7 a3 g; ?. h6 @4 aexit(1); /* terminate with an error code */ " w/ Z) f4 w4 P  }, C( ^* H6 \
} </FONT></P>
% E. d1 {- V- x<P><FONT color=#0000ff>midx = getmaxx() / 2;
' \; O! J7 x2 i) }/ _4 Mmidy = getmaxy() / 2; </FONT></P>2 D9 L, u$ s3 W! m
<P><FONT color=#0000ff>/* a user defined line pattern */ & g& q, K5 t' |8 V5 U. R
/* binary: "0000000000000001" */
" i9 s$ J2 N  l! x4 \userpat = 1; </FONT></P>
& U# W4 p/ Y( P: I+ C<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++) , X3 x2 |8 q# G, U. M" l
{ % c& Y/ h  A# |6 a8 k) e* ~
/* select the line style */ " q1 t4 f- G: @; e# E+ O: b# A
setlinestyle(style, userpat, 1); </FONT></P>) Z& _' L1 k: X  b. y# k
<P><FONT color=#0000ff>/* convert style into a string */
6 g% [" S# h2 x/ Lstrcpy(stylestr, lname[style]); </FONT></P>
* a3 b# C' l7 f- j$ o) J) \3 H<P><FONT color=#0000ff>/* draw a line */
1 t) E: G2 b, r6 p% Y' yline(0, 0, midx-10, midy); </FONT></P>
2 S3 t  j4 @9 |% J, T6 F( i<P><FONT color=#0000ff>/* draw a rectangle */
1 a7 W$ X% ]( p) v# w2 Q  m% U4 |- Yrectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>, P. p; N  l. P
<P><FONT color=#0000ff>/* output a message */
+ ^2 a0 ?5 v, j( u* x. o' C/ s8 n; Pouttextxy(midx, midy, stylestr); </FONT></P>
# F8 X+ W' S  h7 J/ o8 O<P><FONT color=#0000ff>/* wait for a key */
! T* R, x, i4 zgetch();
  q8 v. t, q8 B$ F8 }; j/ B/ J: lcleardevice(); + N* u) q! W6 q  ?: q' ~) _" g
} </FONT></P>
6 t4 {7 y" ^( P- S- H, ^) E. m<P><FONT color=#0000ff>/* clean up */
! u- |/ `- ^% |% y! P  Sclosegraph(); 1 u7 Q$ r( P& f5 g; Q6 V
return 0; ( v6 o( l! j! ^$ X, F/ F# P+ f. H! z, ?
} </FONT>
9 x+ r$ `7 Q3 q3 v& E$ N
( n) K5 K8 V7 V/ m& H8 f0 D
- X( u( \# ~. n8 w) w. I8 z</P>+ g! e8 H# m6 Y! ~1 C
<P><FONT color=#ff0000>函数名: setmem </FONT>
" F& [' `9 k* S! ?% c功 能: 存值到存储区
+ s  z8 F4 C# }: O5 K( ~用 法: void setmem(void *addr, int len, char value); % E9 E$ Y: j, I) K
程序例: </P>, m3 |" T3 v( e3 m. t) ]
<P><FONT color=#0000ff>#include <STDIO.H>! T2 m4 b! m# ]* G% c0 Y5 |4 {
#include <ALLOC.H>
8 l4 D; e5 b3 I4 M8 V#include <MEM.H></FONT></P>
9 N. h5 ~# y% ?% z<P><FONT color=#0000ff>int main(void)
3 {6 @! [0 i+ v{ 5 g% Z/ B0 @% ?" T3 J% u  H0 f  ^
char *dest; </FONT></P>8 g3 o, D. V3 z% ]
<P><FONT color=#0000ff>dest = calloc(21, sizeof(char)); ; s% F/ S- R' h0 _
setmem(dest, 20, 'c'); * W8 I! ]9 V+ J
printf("%s\n", dest); </FONT></P>
  @+ o1 h3 @1 p4 M4 x<P><FONT color=#0000ff>return 0;
% `9 [8 Z4 U  K% k; J( K} </FONT>
0 ?7 R1 O( U2 U% ~" D1 V8 o4 @6 B' S8 N" |

. o# x- b& X2 ], H: b! a4 K</P>, v1 M; k9 `- P0 i) ]; w0 z
<P><FONT color=#ff0000>函数名: setmode </FONT>
- p2 A( E. ?9 {功 能: 设置打开文件方式
0 ^  G  M3 v2 W3 |$ Z: a0 t( s用 法: int setmode(int handle, unsigned mode); ( V, N7 q6 \+ J0 k( p# f0 _% X& l
程序例: </P>4 ~# l9 h- M) ]+ U
<P><FONT color=#0000ff>#include <STDIO.H>$ i& d( Z5 V" p) C
#include <FCNTL.H># h( X* F! o, [2 h1 W+ p7 v
#include <IO.H></FONT></P>1 `( Q" _. r+ |; D% Y
<P><FONT color=#0000ff>int main(void)
& h' L1 C2 W7 Y# {- N# m( c8 x4 @{ 8 t* _: \% z% V* Y4 Y$ n2 y' w
int result; </FONT></P>
0 Y% J. H  b. T0 H; \' [) k6 u<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT);
. r" \1 r$ [* R( p9 q# F# vif (result == -1) % x4 l; x6 ~/ s  C2 M. I
perror("Mode not available\n"); 6 c/ a4 c! r' G4 s' u
else
  S9 B; r' Z* a. _1 N+ d" K3 Uprintf("Mode successfully switched\n"); : N$ l2 B/ L0 G  W  t9 H
return 0;
* b: l) X5 U" p- V8 x6 D/ ?} 9 Z  O7 M# `1 B* D  F

9 Q9 J. y  p( w, x! \6 z# _& K</FONT>. ?1 |+ p( `; e4 g1 z6 E% U: {
</P>3 J$ d4 A3 L9 h8 ]# b/ B" w
<P><FONT color=#ff0000>函数名: setpalette </FONT>, B4 k& W3 w3 Q
功 能: 改变调色板的颜色 ! B9 V- o: _" o- |8 N) A: ~' S
用 法: void far setpalette(int index, int actural_color); 0 Y6 ^! b0 J& S3 T6 _
程序例: </P>
6 Q* y+ d! m% Q( E' k2 u2 R! O<P><FONT color=#0000ff>#include <GRAPHICS.H>+ u) L7 D1 ?# U7 B' |( n+ p
#include <STDLIB.H>$ d- x% m+ j; V
#include <STDIO.H>
( \2 Q% Q. ?; _7 b0 Q#include <CONIO.H></FONT></P>
  C2 r5 w# ^) z<P><FONT color=#0000ff>int main(void) 5 U) H1 P) u% m) h% O
{
* J% S: }3 v1 `( b/* request auto detection */
1 c+ B$ p% v# d( V# G( C; ^( `int gdriver = DETECT, gmode, errorcode;
/ C6 K  T% x6 hint color, maxcolor, ht;
3 S* h" ^7 y8 @0 Vint y = 10; & \$ @1 d; p( q( B; B
char msg[80]; </FONT></P>0 D' v  u" d2 s- v8 K3 k3 j/ `+ q& U
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& l# G9 E6 c5 f' `" p0 x( P' hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  G5 ]3 P* _. L# ~2 ^<P><FONT color=#0000ff>/* read result of initialization */
5 `  {% M' J7 V1 Serrorcode = graphresult(); 1 [- Z3 ^4 M' x1 F% s7 d
if (errorcode != grOk) /* an error occurred */ ' {( e9 P& t! P$ Z' C
{
* p$ \, b0 G( L% o: |( fprintf("Graphics error: %s\n", grapherrormsg(errorcode));
7 w0 H, ?1 L2 F* |/ Vprintf("Press any key to halt:");   P* a. R* I  A" r9 v9 u! `
getch(); " G1 D/ C2 {# X. F
exit(1); /* terminate with an error code */
; g/ ~$ \: j! g9 O9 U" ^# i} </FONT></P>2 M% A& h0 l  [/ q
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
% q) g, p, I. V: D# Hht = 2 * textheight("W"); </FONT></P>
+ U$ a, V$ w5 |; q* h& h<P><FONT color=#0000ff>/* display the default colors */ ) E5 b. S) S* D1 _; q
for (color=1; color&lt;=maxcolor; color++)
8 {8 l  W2 G, G/ _. v/ a{
+ C* [' l& l( d& w5 R" Ysetcolor(color);
# M, \4 I6 Z7 h5 u. {5 t. }/ ysprintf(msg, "Color: %d", color);
5 v3 M8 j6 ^  B0 J7 y. m, fouttextxy(1, y, msg); ( z  x9 S, U" W
y += ht; " @. Q, l4 h: I  E8 x! t' f
} </FONT></P>
7 Y/ L# H7 H, C  \5 S& A- K<P><FONT color=#0000ff>/* wait for a key */
7 p; v; I0 z$ P. C9 w; R! P  Ogetch(); </FONT></P>1 l# w+ @; r! ~3 G7 @
<P><FONT color=#0000ff>/* black out the colors one by one */
; w  ?8 R' b  M/ X$ [9 t1 ^for (color=1; color&lt;=maxcolor; color++) 6 q  ?0 f* `' H3 r6 _* T! _9 a7 l
{ # K$ e4 M; O# I; ]) a: O8 ]
setpalette(color, BLACK); ) X% X7 n* K( @8 L. f6 ^
getch();
7 e1 U! Z! O- |) @5 |( J} </FONT></P>
2 g" e$ a, W5 N: n. `! I. i0 ?<P><FONT color=#0000ff>/* clean up */
2 Q% J- B) a! `7 j5 o0 xclosegraph(); ( p; _: h( h: r3 A
return 0;
( X0 O/ C3 _6 ]6 ]. `' n, l}
5 i$ {& Z. [# h* V& Z0 j</FONT>
1 ]0 g: a; b( v; w$ F' y  N2 X$ ?  X</P>6 ?  R  d$ C# A
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
# h) O: H% a( C0 Z6 ^# h" [功 能: 定义IBM8514图形卡的颜色
) m9 h+ U* h  b1 a用 法: void far setrgbpalette(int colornum, int red, int green, int blue);
* {- L$ W) n: c8 k( f+ @程序例: </P>
8 K; A: L$ M0 A2 V9 @9 R<P><FONT color=#0000ff>#include <GRAPHICS.H>+ i  V6 D' @2 s- x% Z, G( z* F+ e: f
#include <STDLIB.H>
- R8 X. T7 b* z1 b4 O2 @+ A3 v#include <STDIO.H>0 `/ q$ B% S  ^* i/ k8 d1 L. c
#include <CONIO.H></FONT></P>
9 D$ N; Q9 l7 S, I' i* I<P><FONT color=#0000ff>int main(void) 7 \) s$ b3 ~) l: F& d  P( `
{ * Y! V. T  ?5 L) H( z4 O
/* select a driver and mode that supports the use */
* R0 Q) r+ O- ]  ~  x/* of the setrgbpalette function. */ ) I- r, ]0 b- Q( E/ t
int gdriver = VGA, gmode = VGAHI, errorcode; " r9 w- S5 x; P5 v" q4 r5 P" S5 d
struct palettetype pal; 5 m% z5 P* N8 i2 y/ ~
int i, ht, y, xmax; </FONT></P>
( n% O0 ]) P. j  j6 m1 P<P><FONT color=#0000ff>/* initialize graphics and local variables */ & U9 ~# n! K6 K9 ^7 k
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
' g+ ]/ F7 g* j; `<P><FONT color=#0000ff>/* read result of initialization */ , d5 j6 x. R) I- C" Y. a" A- G
errorcode = graphresult(); % [3 }: N6 j5 e, n  R, W; o
if (errorcode != grOk) /* an error occurred */
) i# V: E8 P: u6 K{ : u6 h. o& m: ^. A( r! Y# j
printf("Graphics error: %s\n", grapherrormsg(errorcode));
( b1 S3 w0 P0 Z+ G( zprintf("Press any key to halt:");
7 Y5 r* x& D8 Y, t' ~, ^getch(); # I. ?  I. F  z) a1 A$ ?- C
exit(1); /* terminate with an error code */
( E- h% G# r6 K( B- ]7 l} </FONT></P>9 v8 B0 x* B; h2 o& b; Z
<P><FONT color=#0000ff>/* grab a copy of the palette */ 9 s: ^) R& m4 m1 K! q
getpalette(&amp;pal); </FONT></P>
! N6 U7 n8 ?! @) P! J<P><FONT color=#0000ff>/* create gray scale */
4 O  K) v- N4 J# a% C4 Kfor (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>8 S( ^  w- z$ B/ A9 i2 z4 V
<P><FONT color=#0000ff>/* display the gray scale */   S0 G* l) j; P' `
ht = getmaxy() / 16; ; B) J. U6 k7 u1 N9 Y$ C
xmax = getmaxx();
* ^  h6 F- e3 u" J, ^- `0 U- ty = 0;
9 r1 B0 v$ ~, V, I& l5 L) b  Gfor (i=0; i<PAL.SIZE; <br i++)> {
: B) E9 v5 Z$ L$ G/ w2 xsetfillstyle(SOLID_FILL, i);
$ b: }9 m, K2 D; E% G& T8 d4 Ebar(0, y, xmax, y+ht);
* u" U3 M# d7 m8 iy += ht;
2 }/ }8 U- Y, T2 B} </FONT></P>
: {, g+ y% M. E1 @- `! {<P><FONT color=#0000ff>/* clean up */
- ^7 B6 J* o2 C# i$ T" pgetch();
- n/ ?2 M2 U! N  a6 [4 w! k' \closegraph(); , M# e( W, b  O. d# E( Y6 c9 D
return 0; % A2 W( G) x" \' n7 H
}
& B, z; @. C$ G: z2 R</FONT>
2 p+ F" U2 `9 A' J2 z" ?+ @9 Y3 q# H. y; ?" }: D! X
</P>4 L8 g* l5 N8 m
<P><FONT color=#ff0000>函数名: settextjustify </FONT>
' J3 ^+ ]4 S/ i4 `功 能: 为图形函数设置文本的对齐方式 * [  p& r* \( G
用 法: void far settextjustify(int horiz, int vert); ; T% I( o, B, u" ^1 T
程序例: </P>
$ T( K7 [2 S/ ^$ `- D9 K  U: y( J<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 }4 f# A1 j6 {& Z+ W#include <STDLIB.H>& N4 U% S! M+ J$ H) I8 m
#include <STDIO.H>6 \4 d" Y0 N' i: D# q
#include <CONIO.H></FONT></P>; p+ S4 i3 ?) h/ O) [8 \, N% d: k( M7 }
<P><FONT color=#0000ff>/* function prototype */
7 J* M, [, B- h2 R0 n) g2 F8 K0 nvoid xat(int x, int y); </FONT></P>5 b) _; `/ \6 ?3 H* p/ P
<P><FONT color=#0000ff>/* horizontal text justification settings */
! F/ P8 L* s4 n% i' bchar *hjust[] = { "LEFT_TEXT", ! h+ h8 u* c! `9 t1 R
"CENTER_TEXT", 6 v7 q# c2 l* W+ H. z( {6 U
"RIGHT_TEXT" & x4 J9 L0 h( t/ s
}; </FONT></P>: C* H+ e! o) ?' C) ?% d
<P><FONT color=#0000ff>/* vertical text justification settings */ * e1 _# K# ]0 o$ `# t
char *vjust[] = { "LEFT_TEXT", 9 A6 g( a% a$ r: d7 f& p0 r
"CENTER_TEXT",
0 ?! m# l3 ^1 j0 s( Y' V. ^9 L9 V. V"RIGHT_TEXT" 8 S3 }6 N* n+ v. m0 `
}; </FONT></P>
7 {$ @" Z- W% _0 c) B' ]! C<P><FONT color=#0000ff>int main(void)
) [* ~1 ?* c; G  N5 Z{ - m0 o- K, V3 j  }8 }/ h
/* request auto detection */ 8 j  H3 j8 k* ^9 e8 [1 M2 W
int gdriver = DETECT, gmode, errorcode;
. b9 f, v( A4 p& L, d8 `, G' p* kint midx, midy, hj, vj; " L  n- B: l3 v9 N# Y8 Z1 o
char msg[80]; </FONT></P>: m! R' q) ?% h$ r
<P><FONT color=#0000ff>/* initialize graphics and local variables */ : V2 g: A- i' |8 O$ [5 q1 N0 H7 u
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 q9 F7 w4 ^/ t; p6 @<P><FONT color=#0000ff>/* read result of initialization */ + D& L9 t4 G* J2 N
errorcode = graphresult();
1 K. l0 V- S4 d5 O- R2 N2 {  oif (errorcode != grOk) /* an error occurred */ # B# z# m; `2 s3 Z
{   t8 ?0 v1 o7 Y, S) H* n5 `
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # X8 M5 ~8 `! s! |* J2 _% b6 g
printf("Press any key to halt:");
8 A! m, i: b% D! vgetch();
0 x/ ~5 m+ v1 {+ U1 L/ W4 Fexit(1); /* terminate with an error code */
# j1 o7 l- {1 m} </FONT></P>
( |0 y/ T3 w1 x# I9 i1 ]<P><FONT color=#0000ff>midx = getmaxx() / 2;
, L6 Q+ X% ]0 H. B& Z6 Mmidy = getmaxy() / 2; </FONT></P>
) k  G# V9 t8 @( ^- Z$ E$ m<P><FONT color=#0000ff>/* loop through text justifications */ ) `' O& T9 A& j- j- r
for (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) 3 d8 k4 {8 m; }- a( Z2 ~* e) p
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++) " {# h4 ~( x& v( c4 Z6 A
{ $ [0 y5 u5 w" c& W
cleardevice();
: f5 s% @- A* M5 b+ _, `/* set the text justification */
$ h5 i7 p/ v' {) Vsettextjustify(hj, vj); </FONT></P>. p$ |$ k1 g$ z5 v/ q* X
<P><FONT color=#0000ff>/* create a message string */
8 B. |( R. i9 b( Zsprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>3 s; y* @! ~# n) ~
<P><FONT color=#0000ff>/* create cross hairs on the screen */ 7 |% v) a" j' Y( L$ W
xat(midx, midy); </FONT></P>
* c0 N$ w) n, f" P) y( l<P><FONT color=#0000ff>/* output the message */
9 |5 Z. z+ I5 Houttextxy(midx, midy, msg); - y8 E4 @3 }1 z' @! v: s
getch(); / p- m+ o/ O% V8 Q' J
} </FONT></P>
2 X' Y  n, ^2 v8 r8 p<P><FONT color=#0000ff>/* clean up */ ' P- H5 e. P5 m: Z
closegraph();
% V8 c. S  M; S6 c5 @# Zreturn 0;
8 [" D! j4 i, |8 D3 F} </FONT></P>' a6 Y, B# g- _* j0 R
<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
' K( a& e5 ], ]: Z1 }void xat(int x, int y)
; q, {" G0 Y. {: v{ 8 n8 A4 w5 U) d* z) `
line(x-4, y, x+4, y);
& ~6 g) p% x4 l( }' z3 g, Wline(x, y-4, x, y+4); 3 O0 ~. A5 @7 }0 Z; x
} </FONT>
' y& @( y8 b$ r7 ~' z1 V4 D- X. E7 Z0 Z$ D; u: ^- S4 {
</P>5 z6 s# w8 \; Y& U6 X) p
<P><FONT color=#ff0000>函数名: settextstyle </FONT>6 t, h2 A+ i2 V
功 能: 为图形输出设置当前的文本属性 5 `% {) |* n; j7 a6 m
用 法: void far settextstyle (int font, int direction, char size); ; I* T/ }7 v' P" V" B
程序例: </P>; ?/ R0 |3 B& y5 e6 Z" ~$ @
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ ]2 M. J! ?' ^: T
#include <STDLIB.H>
+ w$ x$ v6 U8 D" h$ F8 g#include <STDIO.H>
' D5 R/ P" y' C( T9 p#include <CONIO.H></FONT></P>) n! q! i6 c0 d2 d
<P><FONT color=#0000ff>/* the names of the text styles supported */
, t) g6 p' |4 w8 E* ^char *fname[] = { "DEFAULT font", ( y" G# D  o. R" L1 s+ c, X
"TRIPLEX font", : j. W$ @1 k  W* F3 T1 o4 ]
"SMALL font",
9 R, d9 @" h3 b  U" N. H"SANS SERIF font", - x6 L# j: U  p  M7 `$ |
"GOTHIC font"
; c6 m# E4 l; v" _6 E2 `}; </FONT></P>
  p- c0 l2 K# Y' ]& B+ G$ a3 S9 w<P><FONT color=#0000ff>int main(void) 6 j9 K0 G7 Z- ?1 m
{
7 O# x* w0 O2 }% R9 M/* request auto detection */
+ J' V) o- [" |, z0 W: R7 y9 vint gdriver = DETECT, gmode, errorcode;
  B! J/ `& H* P$ B  e/ L2 K. Y0 _6 tint style, midx, midy;
: c; B4 J" Y' {) M* Qint size = 1; </FONT></P>
4 G8 F! [6 W; O4 a  z; r7 U<P><FONT color=#0000ff>/* initialize graphics and local variables */
, p5 X5 v+ p  H, |. G1 G, j% E5 E6 hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 J  F+ V$ U: P$ J- M
<P><FONT color=#0000ff>/* read result of initialization */
' k2 o1 d* [( P7 berrorcode = graphresult();
4 B+ w2 Q- K4 o5 N7 y. f( q2 Hif (errorcode != grOk) /* an error occurred */ 6 }! }* S7 t/ {! ?# R0 O9 b" V
{
! }$ F$ o. s" w! G/ B$ pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
7 g! T) M; _% s4 i3 s6 `printf("Press any key to halt:"); * U& S7 A  r4 u9 l; Y
getch(); % Z; m  t! k# i4 H) T& D
exit(1); /* terminate with an error code */
0 M7 ?$ A! R1 C3 q* q} </FONT></P>
8 y: }' P9 ~0 o1 K6 M  u; T4 q<P><FONT color=#0000ff>midx = getmaxx() / 2; * H* q% x' w5 c2 \4 {$ B
midy = getmaxy() / 2; </FONT></P>
/ W) H* {/ x8 w8 z<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>& l! o3 i; i& E1 i3 n8 q
<P><FONT color=#0000ff>/* loop through the available text styles */
9 g4 c: E1 e3 t# ^9 R9 _for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) ; ~2 g# E+ Q3 U9 I$ n% }2 D
{ ( M) s# p) |! T& e0 Q$ ?
cleardevice();
3 T( Q- U, B; v$ k( r% bif (style == TRIPLEX_FONT)
  u* q- P# Y3 V& G0 N0 f1 @size = 4; </FONT></P>
" `9 X' x2 m( p4 p<P><FONT color=#0000ff>/* select the text style */
/ f8 Z* Y6 N: o0 Y' \9 _+ ^/ |7 bsettextstyle(style, HORIZ_DIR, size); </FONT></P>, C5 v! m: ?8 o" \+ x+ t6 U7 l
<P><FONT color=#0000ff>/* output a message */ ! o0 y$ x# o: `
outtextxy(midx, midy, fname[style]);
, J- r: W' b* P* W9 L9 j. ^! Rgetch(); 9 e1 {; s4 k( P% D4 S+ _+ H
} </FONT></P>
& U$ c4 K& [& T  r! Z! W* r<P><FONT color=#0000ff>/* clean up */ 9 Z5 z; M# T& D# a( C2 r0 u& P
closegraph();
! N8 P4 G/ A9 H# G* Oreturn 0;
- Z& Y5 k/ K0 o+ M. I3 V}
& `$ f5 w, k; ?8 Q</FONT>
: V0 p0 h* w5 ]' \# v$ N$ |</P>
1 h9 z, O: u" \  L4 ^<P><FONT color=#ff0000>函数名: settextstyle </FONT>  k& h" k3 l( E% E
功 能: 为图形输出设置当前的文本属性
: |3 I( {( D, j2 P$ _1 M. @用 法: void far settextstyle (int font, int direction, char size);
* p, H6 I; K/ E3 t& e. s5 [程序例: </P>
" c* V3 i9 X  {: E3 ]<P><FONT color=#0000ff>#include <GRAPHICS.H>
# T! V/ x+ {' X+ r2 S2 m#include <STDLIB.H>* W, h& l, k1 F$ u# s* J4 F
#include <STDIO.H>
; {* A4 t, P9 E2 b; r$ ^#include <CONIO.H></FONT></P>  N3 t9 j7 V$ U) i8 G$ J& _
<P><FONT color=#0000ff>/* the names of the text styles supported */ 0 g0 T/ P. U  Q* L
char *fname[] = { "DEFAULT font",
4 K. ~# P: T/ S& L+ b) E! L"TRIPLEX font", 1 V6 q( L! `* m) B
"SMALL font",
( x: a- k& x4 W"SANS SERIF font", 0 a3 q5 W. _# k7 n/ m, `; o
"GOTHIC font"
& K3 _: @1 R5 z}; </FONT></P>+ Y4 j. }& F+ S' R
<P><FONT color=#0000ff>int main(void) . _# X% ~7 f1 _$ _! }1 ^
{
- X" y6 M) ~% ~  K, ?/* request auto detection */
. a0 [) n: _% v8 c6 `int gdriver = DETECT, gmode, errorcode; . ^' m! }& \$ T$ H3 M
int style, midx, midy;
7 R! U5 D+ h6 H$ rint size = 1; </FONT></P># n  d* Y& }1 K- e6 }8 h; R) ^: x' v
<P><FONT color=#0000ff>/* initialize graphics and local variables */
# B- p5 r! ]( s& d2 M8 yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ J6 I1 M9 q" e  y3 R7 i% ~
<P><FONT color=#0000ff>/* read result of initialization */
9 a1 B2 O6 W8 ]2 t8 @errorcode = graphresult();
9 g$ \/ X# x* y2 |& _8 o+ gif (errorcode != grOk) /* an error occurred */
; e; u2 p0 U4 {" D4 b# \1 t{
9 `, c1 ^( u8 C0 kprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ' B+ M; C. }9 d/ k* ]! t$ v
printf("Press any key to halt:");
5 ~! c6 X& K8 j' w& Dgetch(); 4 @2 J- ^% A0 e4 F; @
exit(1); /* terminate with an error code */ ! U/ k. z* t/ Z! i4 m
} </FONT></P>/ h) R/ A- p' R( V
<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 [% p! b1 v! R3 U& Emidy = getmaxy() / 2; </FONT></P>
% {" C# {& u7 |( D<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>/ z# w& p1 b* O* [
<P><FONT color=#0000ff>/* loop through the available text styles */ 3 A; d1 Q. w9 m! J( e2 Y
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) 0 D! Q) L$ W# h3 D: Z4 y. F- n
{ ) O5 N# |) K, }2 F( i0 n
cleardevice(); 2 N  B& e" U# s5 O: r0 e: ^
if (style == TRIPLEX_FONT) 6 t5 e. z" Q( o* w4 v  D+ G
size = 4; </FONT></P>8 s$ Q& h. P) b% t; Q( c
<P><FONT color=#0000ff>/* select the text style */
- Q6 ^# P- Z0 v6 H' ]settextstyle(style, HORIZ_DIR, size); </FONT></P>
# c" g: E' A" Z7 I& \6 k7 w<P><FONT color=#0000ff>/* output a message */ ) S# n& e! x! `- S6 O8 H
outtextxy(midx, midy, fname[style]); 2 [( V, v, K  u$ T( o" x) V/ h
getch(); " a8 e5 Z7 f2 v
} </FONT></P>6 R( m  W# B8 F  f+ b" r) B8 X
<P><FONT color=#0000ff>/* clean up */ # b' {8 E( K/ L2 B) E; G
closegraph();
! v! ]. I' P2 ~2 T8 j1 h& Kreturn 0; 8 |6 Y2 }+ k4 b8 V5 o# K, V6 |
} </FONT>6 a6 i- t  E. |, G! V3 w
! h' e- x) S4 G9 w# w
</P>
( p7 r( n$ r% U; h0 ]0 D3 ~+ y2 I6 d5 N<P><FONT color=#ff0000>函数名: settime </FONT>
& f0 H# W+ p7 A' a% ?7 H功 能: 设置系统时间
; d( R) ^, _3 v8 W7 s用 法: void settime(struct time *timep);
* R7 \1 o- k! o程序例: </P>$ i* W( L2 b6 s& a4 c* R
<P><FONT color=#0000ff>#include <STDIO.H>: H8 B. z" g+ R, R, m
#include <DOS.H></FONT></P>
* A6 }( x" e: r- ^3 r- j- d; k6 n  v5 ?<P><FONT color=#0000ff>int main(void)
& Z" n: O! K7 k# Y- Z9 d7 h& ]{
) e4 C& l# [: c0 x/ ?" gstruct time t; </FONT></P>
3 r/ u+ t% o! m9 U$ {9 F. y# q1 K<P><FONT color=#0000ff>gettime(&amp;t);
# |/ {& o9 \6 O! a# pprintf("The current minute is: %d\n", t.ti_min);
+ _# f4 D% Z7 n+ D; q( e  T! sprintf("The current hour is: %d\n", t.ti_hour); $ j+ w  J$ N1 m% Z6 U3 Y
printf("The current hundredth of a second is: %d\n", t.ti_hund);
5 j. V, }5 m( G+ p+ _" m* e6 Y. D% Mprintf("The current second is: %d\n", t.ti_sec); </FONT></P>
5 I  T1 C$ A% b$ Y  w1 s<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
8 V3 S4 w# J2 J7 h4 U0 Ft.ti_min++;
; g& w; ^) b* @9 z+ q! xsettime(&amp;t); </FONT></P>! l4 |. |+ s3 g$ S: I9 G
<P><FONT color=#0000ff>return 0;
0 r  }& S- l' N7 D! v1 d9 _2 j} </FONT>9 B& F6 g- h, T' x: b9 u7 @3 }: E

: d% L' P; ^, B  t+ n& X& y3 T  F</P>- G# `& b' f) x$ a7 G+ [
<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
0 j+ x+ w3 c# ]功 能: 为矢量字体改变字符宽度和高度
" M8 M. L0 g7 a+ A. @用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
0 k( V1 B7 N- V: p! n4 P& O程序例: </P>
& Y- v0 L0 H' ?$ a5 `<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ G0 R. t6 P# I#include <STDLIB.H>6 U, V! q9 g% Q6 J4 ~
#include <STDIO.H>
- o5 B6 m( A3 N#include <CONIO.H></FONT></P>
/ }$ v6 o: I0 K<P><FONT color=#0000ff>int main(void) - s' J$ U2 M# e' A$ L
{ + b4 O# D: ~% D& w  `5 ]
/* request autodetection */
! I3 w6 T3 x( j% w0 o5 Aint gdriver = DETECT, gmode, errorcode; </FONT></P>
! o) P4 K- Q9 }( x2 Y<P><FONT color=#0000ff>/* initialize graphics and local variables */ + s2 b+ P8 `+ ]/ t9 i
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 @: o- H6 _9 Y( y5 g& J/ [<P><FONT color=#0000ff>/* read result of initialization */
5 h0 x8 h' v) e2 `, a1 p8 j+ derrorcode = graphresult(); - p. h8 M/ n7 a# E1 U1 B- E
if (errorcode != grOk) /* an error occurred */
$ x$ J8 J: V* Y7 ]& c3 z{ + M4 ]( X' r* O* }
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ @$ R' C2 S; b- v4 v9 G, kprintf("Press any key to halt:");
, Y/ l3 B' @+ n( a" c* ogetch();
" D: d' }# Y/ @0 O% oexit(1); /* terminate with an error code */ ( N7 X- q! l  N5 [
} </FONT></P>
4 ~0 O7 b- [* s$ W0 n1 e<P><FONT color=#0000ff>/* select a text style */ + z$ M0 v9 D" i4 Q: w) L
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>
( @8 Q1 h1 `8 d9 |8 t( x<P><FONT color=#0000ff>/* move to the text starting position */
! T$ I, M: w' o( l3 ?moveto(0, getmaxy() / 2); </FONT></P>  b/ d& n4 z4 `2 f- H
<P><FONT color=#0000ff>/* output some normal text */ 5 z* z$ j6 _+ L4 b
outtext("Norm "); </FONT></P>
0 R0 j1 C: o0 j& f* F" n( q<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ 1 |- D; T/ d( v5 h5 y
setusercharsize(1, 3, 1, 1); 9 P0 I/ l9 v9 p5 A  v
outtext("Short "); </FONT></P>7 H: V! E1 S4 v; Y6 y
<P><FONT color=#0000ff>/* make the text 3 times normal width */ 0 B! b% }' H, q( u) y( G& _) C
setusercharsize(3, 1, 1, 1);
1 P, P) A; f' `; {9 B# vouttext("Wide"); </FONT></P>
& E! h- B( X4 N6 y0 y1 n4 a' A<P><FONT color=#0000ff>/* clean up */
+ n" o2 V- J. e0 c# ?; U6 e% m( Igetch();
) X2 N' n+ R& D9 z3 H8 Rclosegraph();
0 c/ J2 Y' ]( ^$ e" xreturn 0; 3 `% v+ _/ o9 Y9 ]1 y" [
} </FONT>7 ?7 V) R; Q2 s( S
</P>
  Z) h2 W$ j+ g+ Z<P><FONT color=#ff0000>函数名: setvbuf </FONT>
- d: R$ I% m8 |- j- p5 `功 能: 把缓冲区与流相关
; c' o" s6 W  e+ ^3 }3 D$ C用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); % Q1 q) w/ q+ o* {1 q; b
程序例: </P>: S0 H: c: D; @( J3 w! a6 ^
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
% ]: o; m. ]/ l$ v5 K8 D3 k<P><FONT color=#0000ff>int main(void)
/ g% I. D8 h' S( o{
0 [5 w0 Q1 z$ E1 r* \7 @FILE *input, *output;
* X' c- \- ~+ F% q2 fchar bufr[512]; </FONT></P>
9 z8 {. _5 e. Q6 t<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
% ^- l) k# y& h* f; Q9 }output = fopen("file.out", "w"); </FONT></P>" }( P6 A# `; y& g3 F
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,
) ?) }6 T) z/ p* Zusing our own character buffer */
3 J0 q0 m* g$ ?- uif (setvbuf(input, bufr, _IOFBF, 512) != 0)
# m9 E% G. t6 b7 z$ [printf("failed to set up buffer for input file\n"); 0 k8 _! ]9 c/ U) E) [& J! p7 L
else 8 ?+ x( \' |, K9 Y
printf("buffer set up for input file\n"); </FONT></P>
, [; M. C0 v- g<P><FONT color=#0000ff>/* set up output stream for line buffering using space that ' {- c: s( ^" Y: \
will be obtained through an indirect call to malloc */
+ ]  k' x  V  b; O5 ]0 Q, Kif (setvbuf(output, NULL, _IOLBF, 132) != 0) , p; e& B1 a2 C% O2 J; ]6 U
printf("failed to set up buffer for output file\n");
. ^. H5 h, n0 n1 yelse
" ?9 r/ `4 k. C& l2 T$ [6 Oprintf("buffer set up for output file\n"); </FONT></P>
" Q, S5 {, E8 O7 n) E9 T<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>3 {& k- E4 a% {$ E/ |+ R
<P><FONT color=#0000ff>/* close files */ $ }' B5 E# y* Q, a' ^- s2 p
fclose(input);
1 G! V3 I; V9 H, Y- vfclose(output);
& B, ?& C% s$ Y! R  G. e# vreturn 0;
3 t) ]4 w* S6 T) o2 o} / s* t, |& C5 P1 y- `" T5 n9 m
</FONT>
# I1 c3 N+ I( d$ S& k2 m% t! S* H" d( x
</P>
1 d, I" E# a) i3 {0 |<P><FONT color=#ff0000>函数名: setvect </FONT>
7 n. `$ Y, s0 U. e功 能: 设置中断矢量入口 + r. E& b; `- ~7 b
用 法: void setvect(int intr_num, void interrupt(*isr)()); + ~% ^4 l# X- |8 O/ S% ]1 f; c
程序例: </P># k6 o6 P1 b8 M$ X' E
<P><FONT color=#0000ff>/***NOTE:
$ e4 V/ ?, j/ \2 J  ^9 O- m+ X% EThis is an interrupt service routine. You can NOT compile this
9 y! Y1 `; Y  s) ?4 @& u' O1 j/ x* cprogram with Test Stack Overflow turned on and get an executable $ G- F7 s' F/ K8 Q5 k* u* k
file which will operate correctly. */ </FONT></P>
8 T# Z8 _* K6 L<P><FONT color=#0000ff>#include <STDIO.H>
$ I  G5 e6 z  C9 \8 \; [#include <DOS.H>2 l" m' K/ A! u
#include <CONIO.H></FONT></P>8 r! f5 @8 g1 B; e- F" U6 C9 O
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P># F, o' \3 f" }+ ?
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>* x  p% h& t3 G  k0 J
<P><FONT color=#0000ff>int count=0; </FONT></P>0 r+ m% d2 a. W( ~" ^, ?
<P><FONT color=#0000ff>void interrupt handler(void)
; W4 t* o+ {2 [{ 1 [8 K# T, ~/ L4 ^
/* increase the global counter */ 2 a( x: S. {0 T+ U: D2 b
count++; </FONT></P>$ A9 f$ @( m6 u$ A; Q0 c
<P><FONT color=#0000ff>/* call the old routine */ ! i2 q( N; s5 L; r1 n5 V, J( v
oldhandler(); ! `1 n7 Y. }1 W! q5 G- y
} </FONT></P>
  r* a4 g) u; o4 t$ V4 q; J/ y<P><FONT color=#0000ff>int main(void) 7 |% @* S) y8 ]( x* v3 E
{
. x& j6 \; y! f6 ^% |/* save the old interrupt vector */ 6 v4 V  ?2 X- b  Q$ I: Z
oldhandler = getvect(INTR); </FONT></P>; O0 Z5 B4 f* q+ V+ q( I
<P><FONT color=#0000ff>/* install the new interrupt handler */
& W" i8 O( x1 u: nsetvect(INTR, handler); </FONT></P>
, z0 `' f6 t/ h1 e( s<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
% U3 x. {. w# w( l+ Vwhile (count &lt; 20)
( E$ S* x1 `) oprintf("count is %d\n",count); </FONT></P>
7 R3 E) U$ O1 Y2 ~5 C# l$ P0 t. \<P><FONT color=#0000ff>/* reset the old interrupt handler */ . y5 S' _1 z# O# f% t; ]9 ]
setvect(INTR, oldhandler); </FONT></P>
+ `4 i% D4 h4 a% t<P><FONT color=#0000ff>return 0; ' m* E. c1 }( ?" b- M& K
} * W( @/ d7 Y# m
</FONT>
" S8 L) F2 A4 X9 y/ Y</P>, g1 x3 t+ P$ x, g
<P><FONT color=#ff0000>函数名: setverify </FONT>4 ]: X3 i$ Q" y# h+ n' z& ^
功 能: 设置验证状态
' x& k0 X: Q% J" l" Y+ s: d用 法: void setverify(int value); 7 b0 o, Q2 P5 I( x' h/ T
程序例: </P>+ [( F- {! H5 F% I. |1 e, t& Y# r
<P><FONT color=#0000ff>#include <STDIO.H>2 ]1 I6 a: p8 A* K3 z
#include <CONIO.H>6 E; W' A5 K3 k  ?% z
#include <DOS.H></FONT></P>
1 P0 x& k: B) a" U* z( B. ^<P><FONT color=#0000ff>int main(void) ! k/ ]- H% m" |/ c5 V' s$ {1 g; t
{ . r: t: M2 l& m$ z. k( u
int verify_flag; </FONT></P>4 v. B3 Z! |; N# y! v* a7 {
<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n"); & q: v$ y" M- |9 [
printf("Enter 1 to set verify flag on\n"); </FONT></P>+ W3 R* P+ S4 E& G& F" Y% F- n
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>+ a/ m* ?' Y: l5 D( d' H, W4 [) G4 S
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>; I4 V; t% \6 e# T0 Q1 }; T
<P><FONT color=#0000ff>if (getverify()) 7 K" b1 }$ O" z0 h2 ?3 ], t1 S' [
printf("DOS verify flag is on\n");
5 @6 E7 w" S; d( P- C- xelse
5 b" g8 @: A3 D6 \/ E8 \: @printf("DOS verify flag is off\n"); </FONT></P>
# m1 h2 k) p$ P# u<P><FONT color=#0000ff>return 0;
( J+ k/ y1 [  W+ H; I) B}
$ p/ T5 P1 |/ r. D" |<FONT color=#ff0000>5 f; ]( s7 F! _  B) R5 U% U
</FONT></FONT></P>& t9 C# L* y# r  `, @
<P><FONT color=#ff0000>函数名: setviewport </FONT>
3 G2 Q" Q; f. Q! E# G功 能: 为图形输出设置当前视口 # s; z& O; p3 h# V3 d: y
用 法: void far setviewport(int left, int top, int right,
& F9 |& r) J, d( P' F7 b1 ^' pint bottom, int clipflag); ! `- h4 _" g7 S: u/ _0 E1 s
程序例: </P>" b8 S1 E1 M, }
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 p! b( O9 M# \- ]9 d& O+ d' [$ N#include <STDLIB.H># J5 b; z& g7 k0 P; {( [( Q; u" O+ m
#include <STDIO.H>7 U2 I3 B, [: E
#include <CONIO.H></FONT></P>
$ R. j- i5 d% [* S+ w# ]. E' Y<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
+ j7 n% S' k6 O, p9 q4 S8 O7 |4 B( O<P><FONT color=#0000ff>int main(void)
; C& u- G, k; G5 V4 S! w. Y2 O{ 6 p) P" p7 ]7 c" Y
/* request auto detection */ # Q$ f9 \/ S# c
int gdriver = DETECT, gmode, errorcode; </FONT></P>
; z( T. P" q' E8 O: {5 @<P><FONT color=#0000ff>/* initialize graphics and local variables */
( B4 Z& ]- s, w3 z, n) iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 I2 Z# r. G2 B2 N<P><FONT color=#0000ff>/* read result of initialization */
' b+ }3 e3 w5 ?5 S: l% P; Werrorcode = graphresult(); 9 `2 E9 t$ j: S- I! q( E4 \, @
if (errorcode != grOk) /* an error occurred */
0 G: E: j5 Q# ^{ 4 U' s- b1 `( i2 f
printf("Graphics error: %s\n", grapherrormsg(errorcode));
3 J4 c4 }% ?7 _4 D6 q' h/ Kprintf("Press any key to halt:");
: x' A( v3 [: C( Egetch(); / O* ]0 z' q' I$ b: c
exit(1); /* terminate with an error code */
, M4 J$ y) P* }. z/ X6 A} </FONT></P>& f& j' G# W, M9 B) @: x
<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
5 u; P% G# z6 E  Q$ B% r<P><FONT color=#0000ff>/* message in default full-screen viewport */ 8 L- \9 Z. R$ T( D* A0 P% S' o$ U
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
, `: E, t- I6 Z1 ?/ q<P><FONT color=#0000ff>/* create a smaller viewport */
/ ~$ q# o6 h  asetviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>
% s( W8 A9 t1 @# g# v# ]<P><FONT color=#0000ff>/* display some text */
6 `$ t# c2 j/ L: A6 q5 j  Zouttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
9 O1 o$ N/ B# ^, l  J  I<P><FONT color=#0000ff>/* clean up */   s) x7 L* p5 I) U, c  E
getch();
. W' [, b. X& k$ x6 S7 t& c2 rclosegraph();
8 i( c1 H3 L: e, P3 X8 P4 w* dreturn 0; " O+ `# {' ?' C' q
}
$ A+ M$ ?1 \6 a  i3 V( n/ |4 r</FONT>
5 [2 [: o; ^) _/ C+ ~</P>
# d" A; l9 c- h3 t<P><FONT color=#ff0000>函数名: setvisualpage </FONT>" {+ h9 n5 l9 `4 {0 |5 ?
功 能: 设置可见图形页号 2 P7 i" B- n8 O! ^9 n
用 法: void far setvisualpage(int pagenum);
- b( e- y4 T$ q' O7 i0 M6 l程序例: </P>" |3 K3 @+ Y2 L  |+ V
<P><FONT color=#0000ff>#include <GRAPHICS.H>9 t8 w+ Q  o$ k& ]# c
#include <STDLIB.H>. W  s6 a- h5 i- V) D: l0 h* }
#include <STDIO.H>
* M) j: \) ~1 j0 j4 P$ r6 l#include <CONIO.H></FONT></P>3 X2 j& G) T% W" f
<P><FONT color=#0000ff>int main(void)
  a* l: _1 L$ f: R6 k0 g; G. ~{ " M- E$ G5 a8 P0 g* g
/* select a driver and mode that supports */
. S* B3 l7 I; u0 r' D3 ]; O/* multiple pages. */
5 i. |8 N# {& _' sint gdriver = EGA, gmode = EGAHI, errorcode; 2 a+ w9 ]5 R5 W4 S7 [5 H
int x, y, ht; </FONT></P>
6 D! R1 P, \. o: J+ C& D+ ]<P><FONT color=#0000ff>/* initialize graphics and local variables */ ' }' ^2 M9 t1 C3 q; F4 g) W
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: {7 U+ W- q* t  C8 d2 S' }4 p<P><FONT color=#0000ff>/* read result of initialization */ $ ^$ R/ e, q. j" E9 Y+ O3 u' y: z
errorcode = graphresult(); . S" N# J8 i  h  ?5 [
if (errorcode != grOk) /* an error occurred */ , E6 g0 D( B5 v+ j
{
0 D0 X- c; F0 Gprintf("Graphics error: %s\n", grapherrormsg(errorcode));
! ]$ O! ^! q/ k8 P* M! @* R. y2 g' Vprintf("Press any key to halt:");
6 C% ]2 ]6 z+ y5 h9 Y- ?getch(); 0 F, }5 S" Q; J. I2 t! \) D
exit(1); /* terminate with an error code */
# X" `" x6 c' V9 i+ ^, F5 ^3 I} </FONT></P>
6 v5 e0 |- z6 T* }0 f" h. d3 m<P><FONT color=#0000ff>x = getmaxx() / 2; / i. O4 f8 I) k& m
y = getmaxy() / 2;
* `. v2 U/ C6 D% w4 b) B8 _1 {ht = textheight("W"); </FONT></P>$ W0 t% I5 T( a# g  O2 o/ R0 V
<P><FONT color=#0000ff>/* select the off screen page for drawing */
8 }& A7 x* W+ b+ Y1 usetactivepage(1); </FONT></P>
7 a6 P/ e* Y' m<P><FONT color=#0000ff>/* draw a line on page #1 */ $ R2 }; b* t3 Q3 e2 u( F* a3 B
line(0, 0, getmaxx(), getmaxy()); </FONT></P># o) Y0 f& f$ m1 g
<P><FONT color=#0000ff>/* output a message on page #1 */ 7 w. G8 U3 {- l6 G+ [: G4 l1 V; r1 _
settextjustify(CENTER_TEXT, CENTER_TEXT); / i/ r0 a/ O' R/ Y6 B' n
outtextxy(x, y, "This is page #1:");
' e. N0 f$ ~( s5 o8 Routtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>& @2 j, |! b( ]" T% h, o+ h
<P><FONT color=#0000ff>/* select drawing to page #0 */
) a/ E/ o; w3 m  N! c5 o: Csetactivepage(0); </FONT></P>& u% r, B+ C( j1 N  o3 h
<P><FONT color=#0000ff>/* output a message on page #0 */
* O* K* a7 O/ O! o2 ^# {outtextxy(x, y, "This is page #0."); + s  H3 d! g% J& ~+ `- X9 w7 E1 i( c
outtextxy(x, y+ht, "Press any key to view page #1:"); 4 O0 ^/ g& U; o9 ?3 p
getch(); </FONT></P>0 N1 N$ L4 v4 L/ |8 |0 n! j, c
<P><FONT color=#0000ff>/* select page #1 as the visible page */
1 r  i) ~: [+ w) O1 P# |setvisualpage(1); </FONT></P>
8 ?0 K4 f9 O- e/ z0 H) w7 Y<P><FONT color=#0000ff>/* clean up */ 4 [* ?( E" X/ R
getch(); + u3 i1 s, w5 T* {
closegraph();
% `* j, L8 e: w) Ereturn 0;
9 ]: S; Y: k6 E4 ~} </FONT>- D, C7 d7 d# b/ G& ~& Y' ?
% u0 J+ ?' ?( X9 `' U
</P>
" P) p" `, t5 Z' N' I<P><FONT color=#ff0000>函数名: setwritemode </FONT>
$ U3 Y. o; l% B2 g) C* Y; O功 能: 设置图形方式下画线的输出模式
  i" O& r' E8 v$ R1 o6 l用 法: void far setwritemode(int mode); , {- M* M8 [5 Z" S; \; ]) f
程序例: </P>
% k7 `7 k7 Q8 N# N+ {# f<P><FONT color=#0000ff>#include <GRAPHICS.H>- o1 a8 M$ `& d3 R" z
#include <STDLIB.H>+ b9 J8 D" ~: \6 q
#include <STDIO.H>4 h3 y3 g& _: U% S% w+ H0 ^+ X
#include <CONIO.H></FONT></P>. x0 J/ K% H7 {. {, \4 ~3 u+ A: y0 N
<P><FONT color=#0000ff>int main() / [) y+ |$ L. t, H
{ 5 o' p/ M% \( z0 J+ f6 ^- C
/* request auto detection */ % h) \" l( r' J& O) F) h& v9 j
int gdriver = DETECT, gmode, errorcode;
+ ^7 }, }+ I% N; I3 q. z% Xint xmax, ymax; </FONT></P>8 }* R, s. N* v1 K2 ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, P8 G- F1 i2 T, oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! r# G1 N9 a* {  U
<P><FONT color=#0000ff>/* read result of initialization */ $ H2 K5 @* ]) U& E3 J
errorcode = graphresult();
% U8 F: R8 {9 ~if (errorcode != grOk) /* an error occurred */ 1 N/ i) @2 R$ z# u( k. _; Q
{ * x, @4 O7 a* r$ p1 @/ |4 m  z
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 b0 C# g. W0 C  Z( ^" s2 G! v* x6 p
printf("Press any key to halt:"); 8 ?0 U" G6 G& S; [% U
getch(); ' F4 H# j. e# ]' H) h5 B
exit(1); /* terminate with an error code */ ( ?6 P& e1 \7 Z3 B* b# Y9 f5 ~
} </FONT></P>4 i0 h; C0 [: B4 q. C
<P><FONT color=#0000ff>xmax = getmaxx();
- O9 m$ o  ]2 g# Oymax = getmaxy(); </FONT></P>: [" c7 C- c! s
<P><FONT color=#0000ff>/* select XOR drawing mode */
/ X+ |& Z+ O  L8 lsetwritemode(XOR_PUT); </FONT></P>5 K$ z  R9 l! p+ k$ Q
<P><FONT color=#0000ff>/* draw a line */ " ~6 M2 w2 s9 F" N/ Z5 y; n5 r5 ]
line(0, 0, xmax, ymax);
2 b5 S7 R4 u3 Q6 A- t, v5 cgetch(); </FONT></P>% z; j7 h6 g: x
<P><FONT color=#0000ff>/* erase the line by drawing over it */
$ u1 C% t3 {  A* p* Eline(0, 0, xmax, ymax);
9 ]! O. i' N( H* qgetch(); </FONT></P>
3 J  w' Y% V! \/ \& `<P><FONT color=#0000ff>/* select overwrite drawing mode */
3 ^: U- D' {- M' g" B' P$ qsetwritemode(COPY_PUT); </FONT></P>
8 C, s' A3 R. Y5 |& k: }; F8 v<P><FONT color=#0000ff>/* draw a line */
" q' U3 U; l, \- p8 Q4 A1 ?line(0, 0, xmax, ymax); </FONT></P>) O$ j, D3 P. Z
<P><FONT color=#0000ff>/* clean up */
3 k, ?( ?% E* y& U* p# K9 W) Xgetch();
0 F; p( g& g$ X5 P3 ]0 zclosegraph();
6 a$ D+ }$ M. ]3 C# K( O! z2 Kreturn 0; * Y- }: Q- h& J& f/ |$ E9 h
}
2 Y1 c+ y  `9 E, ?& v  y</FONT>
3 G* t0 Z$ n; G+ |& J& A( N/ p</P>
/ v: ?/ @9 u: ?- P* s% [<P><FONT color=#ff0000>函数名: signal</FONT>
" }  [6 S# v: H- m功 能: 设置某一信号的对应动作 $ ]9 z) e& f# c, y
用 法: int signal(int sig, sigfun fname);
0 w2 Z; t8 e5 T" D  g" y( |程序例: </P>$ S) n4 c6 S2 p$ u5 G8 ^
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, ( w: h. d5 v' J! S3 X) Z
catches an integer overflow condition, makes an adjustment
, g/ y* |1 e9 o5 p. `% ito AX register, and returns. This example program MAY cause
" b* I0 H" d7 o) }7 H+ z2 D2 ?$ t2 a4 Vyour computer to crash, and will produce runtime errors
" z( f( z: g, [) |3 Wdepending on which memory model is used. 3 q0 c8 ?. y( H: A' i
*/ </FONT></P>
1 J* H0 C  o( D5 P( ]$ q<P><FONT color=#0000ff>#pragma inline
( y) t6 Q! @" y. y( d#include <STDIO.H>. L. K( o' T& A
#include <SIGNAL.H></FONT></P>% ]/ ?4 b2 G0 k* e
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist) * N" _% v" f! H) s; Z  Q
{ & w4 z  V1 o% h  W6 y! o
printf("Caught it!\n");
6 W$ a& I" c8 n! S5 ?*(reglist + 8) = 3; /* make return AX = 3 */
+ t5 }  _# f  G; {, O} </FONT></P>
+ e+ x9 [! i, I<P><FONT color=#0000ff>int main(void) ( k& U" y! ]" Y8 N% e6 q
{ 9 G/ h- S; H) N: i) c# Q
signal(SIGFPE, Catcher); + H: m  q/ p1 D, Q. i* `* \: i
asm mov ax,07FFFH /* AX = 32767 */
. K0 c6 r4 L4 M5 @! Z3 H; wasm inc ax /* cause overflow */
  p9 L4 U$ x1 U9 ]- e1 M( e& Nasm into /* activate handler */ </FONT></P>. c# }2 {; h3 ~- j: j, w: [
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened,
# y7 b$ P, I* C' b3 m- Qthere would have been another exception when the next 'into'
, i6 g" y$ P7 Mwas executed after the 'dec' instruction. */
: S0 |# O2 c2 aasm dec ax /* no overflow now */
# K$ F$ i( ]: \# X# Wasm into /* doesn't activate */
6 P! m" `/ `3 F& M' {return 0; , M& `* c4 ?5 d8 I
}
7 V* Y' Z- \$ [6 }; ^8 h' i& J% y+ |- W( @4 D2 i, u% f+ R
/ q- y  I' L- k% f
</FONT></P>
* K# p. p9 q$ R4 g' H  ~5 r* N<P><FONT color=#ff0000>函数名: sin </FONT>
; J9 n) {) l3 j+ l功 能: 正弦函数
5 g$ w( n, ~& H) K1 E; T用 法: double sin(double x); 9 Z# y1 a# o  m9 j4 K9 o, M0 a2 ^+ @
程序例: </P>  ]6 O# H6 z$ z. }" ~/ _; d
<P><FONT color=#0000ff>#include <STDIO.H>( r; I% g2 \. ~( }
#include <MATH.H></FONT></P>% q0 ^" i- D- ]* B
<P><FONT color=#0000ff>int main(void) , O, ?4 ?5 M1 s' I" e% [, Q3 C$ z
{ 7 b! G& D5 o: d" [- ^
double result, x = 0.5; </FONT></P>2 m# G8 X* x8 I
<P><FONT color=#0000ff>result = sin(x);   `6 ?8 B8 T4 g* t$ _
printf("The sin() of %lf is %lf\n", x, result); . u, |9 ?) R) @
return 0;
5 A; E4 A4 v" X& ~! w9 s+ c} ; [% Q5 s, f% y' z  h3 e/ }! ]+ N
# C6 D9 P8 A$ m
</FONT></P>8 V4 ~) q! @. f  ]7 R
<P><FONT color=#ff0000>函数名: sinh </FONT>
' q* D0 y; z$ y0 H& c. K1 _功 能: 双曲正弦函数 $ e4 m/ \# _9 Z
用 法: double sinh(double x);
7 S1 c2 _% E9 F: A0 i程序例: </P>6 P# l( p3 G% r0 H" i
<P><FONT color=#0000ff>#include <STDIO.H>
( H4 w7 }8 y. B5 m- L#include <MATH.H></FONT></P>
; k, l- F9 ]- H1 D$ z& I# Y<P><FONT color=#0000ff>int main(void)
- `4 O  U/ S* [- g: i  z1 p{
( H3 ^- m1 h! V' X- Y- G3 v# Qdouble result, x = 0.5; </FONT></P>
- M5 ?6 @9 b: v. C<P><FONT color=#0000ff>result = sinh(x);
! S8 U" R6 i/ B2 X0 ?printf("The hyperbolic sin() of %lf is %lf\n", x, result); 3 d5 {; |6 j/ W  I2 [+ P# s
return 0;
$ ~- b, U2 ~1 h! I" z; w) T} , [0 W* t6 I5 a; z( d. p( M

2 c' @# }3 [6 ~  w9 b# `9 R1 s$ H5 X
</FONT></P>" n) Q+ H  P: |- L
<P><FONT color=#ff0000>函数名: sleep </FONT>, x3 G" W! @& x% c  k
功 能: 执行挂起一段时间
: C, s( k3 W9 m  B) f4 D) f用 法: unsigned sleep(unsigned seconds);
; O6 t3 F1 Y9 q; \! n) @程序例: </P>) a3 L3 l0 a4 ]  j
<P><FONT color=#0000ff>#include <DOS.H>; Z$ \  T1 X5 E
#include <STDIO.H></FONT></P>& Q$ ~; O2 w& J  _0 p
<P><FONT color=#0000ff>int main(void)
" q9 y8 h* g" j* @{
3 a1 `  {* ^3 J5 x+ z3 c: @int i; </FONT></P>; a$ p2 f- W- L/ p( B- u% V$ b
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
8 f- A/ ?4 S) i8 ^{ ; e: V8 [( u" }; [
printf("Sleeping for %d seconds\n", i); 1 P7 m- c* b: y7 X$ [
sleep(i); 8 }( v2 l1 }) k/ s4 ^
} & G4 ?; e% P* b  @1 l
return 0;
: R6 I+ n' e& d, A' N/ w7 ]} - C3 v) e- N2 w! S7 Q8 A

2 N! M% c! q4 J0 R</FONT>8 j; q) Z7 }0 u% D2 I8 F
</P>2 X0 ?) |2 M6 ]- f4 R9 c' b/ C
<P><FONT color=#ff0000>函数名: sopen </FONT># t8 u3 i% R8 ?. ]5 `: ]
功 能: 打开一共享文件
9 @$ H9 O. x/ ^3 {4 M" T用 法: int sopen(char *pathname, int access, int shflag, int permiss); 6 `/ O/ e' Y8 e  D3 ]5 G- C
程序例: </P>$ d  D2 D4 H' J0 ?' I; V
<P><FONT color=#0000ff>#include <IO.H>
: B1 l' k$ J+ I#include <FCNTL.H>: C$ J6 a8 Q% j0 t" `
#include <SYS\STAT.H>
$ o, T7 k, l4 m8 B" e) _#include <PROCESS.H>5 a1 e: a4 C5 f* c  U
#include <SHARE.H>5 D3 L  ^0 @# B- N  e. c; N
#include <STDIO.H></FONT></P>/ f4 Y9 i& q0 G2 ^& J. b1 t
<P><FONT color=#0000ff>int main(void)
: G/ ?. X( ^$ u{ 8 L, Q: ]9 J/ n) R& ]' f
int handle; " F# u' Y/ v' B4 e8 x* R% I, \
int status; </FONT></P>
: i7 g, V+ E1 c  w) M<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>
# [6 O# A! W: f) s<P><FONT color=#0000ff>if (!handle)
7 d. x2 Q# L+ H, _% D5 ^2 L/ W{
8 D, P" x# a* w% z2 Q$ Sprintf("sopen failed\n");
) e8 h6 x8 V1 \8 lexit(1);   N$ F+ s2 W+ H+ ~2 m) _$ `
} </FONT></P>
. V$ J  G/ @! m0 @<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6); ; D2 j8 i* f/ ]1 [0 q
if (status == 0) . Y% M' T8 c& P% U, }' V" D3 ^
printf("read/write access allowed\n"); ' j& \3 J9 I. G+ z$ D$ C8 c
else
5 w. W4 d- |4 r- _; e" nprintf("read/write access not allowed\n"); </FONT></P>* `8 k' X6 T  K% c6 N1 ~2 ]
<P><FONT color=#0000ff>close(handle); ! O6 I1 P- v5 q0 C. W& {* z
return 0;
. g, a0 S. b# @' ~& O0 F$ @4 m/ z; _}
& m# m5 ]# Q. A" j
( E2 o8 Z2 P+ O$ g) S6 V</FONT>3 D8 r* u: Z! p" O
</P>
4 n6 H. ?0 {: I% Q% |<P><FONT color=#ff0000>函数名: sound </FONT>+ b3 V. I' g2 n3 T5 z7 h) Q
功 能: 以指定频率打开PC扬声器
. _1 R4 b1 f4 m. I8 _% z, J用 法: void sound(unsigned frequency); & T5 }& A0 ?( L' D! m  W0 ]8 }
程序例: </P>2 h- e* H: X8 J3 O& ]4 s3 c
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds.
0 g2 d5 X* \1 }Your PC may not be able to emit a 7-Hz tone. */ # ?) j& D3 x( X! Y/ B5 H( n  b8 t
#include <DOS.H></FONT></P>9 ]2 s) J' o# Q4 x6 M1 y
<P><FONT color=#0000ff>int main(void)
, y; |- T# Y( e  F{ 2 Y# t$ Q& u9 L2 v2 U& E, D
sound(7);
1 y; h5 D$ a9 f1 Idelay(10000);
% [1 c4 U3 v  v+ y2 A( pnosound();
4 n1 G7 v4 k) Yreturn 0;
- o. R4 z% O. K( D* M} </FONT>
- i* D5 F$ P+ z  n* ]5 V' r7 {  f# ]9 a

' i3 Q: t4 q3 X) M$ w! ?! B</P>
. s( y8 V& `' `2 y<P><FONT color=#ff0000>函数名: spawnl </FONT>
8 [( T& q* }% Y6 _# X功 能: 创建并运行子程序 6 [, }  t1 e( j  G$ w
用 法: int spawnl(int mode, char *pathname, char *arg0,
3 ^& h* O9 J% E8 u7 Barg1, ... argn, NULL);
# N6 p7 H: m. q0 \程序例: </P>
4 Y$ n; q' f6 H6 g. q4 V' s<P><FONT color=#0000ff>#include <PROCESS.H>
/ C3 J( T9 T' |# l; `& O; N8 _8 C& Y#include <STDIO.H>9 x2 A% e) I+ M$ @' W
#include <CONIO.H></FONT></P>4 E2 }. x' w& T5 |$ u4 s! M' {
<P><FONT color=#0000ff>int main(void) 3 x6 H; V9 O6 ~& G: ~; Z
{
. H% a" o5 |, u9 q: ~6 y. Oint result; </FONT></P>- ?0 h* d# q7 q  f( F
<P><FONT color=#0000ff>clrscr();
- l) c9 g( P( p/ G! x- E) fresult = spawnl(P_WAIT, "tcc.exe", NULL); $ H8 I1 w2 F1 a+ d3 ]
if (result == -1)
; w; e) t2 R: V4 z9 T) W4 j! e" S{
. Z2 G: m) Y) D% N1 a% Mperror("Error from spawnl");
7 {9 X3 Q2 d' U& I% aexit(1);
( o) G7 U0 P1 ?0 x+ A} 9 ~( F/ L6 w* o9 ?, `% }& V
return 0; ) n. A/ }$ w2 ~! Y4 R
} 0 r+ k& [' C: E9 ~5 ~: j
</FONT>5 B2 L8 {- u- q5 R3 I: n+ W
</P>  U* o: F4 g8 ?" H
<P><FONT color=#ff0000>函数名: spawnle </FONT>
0 e/ n$ L. p- |4 W9 g功 能: 创建并运行子程序
4 ^2 o/ U3 V9 O) d3 a, n4 O' l& ~用 法: int spawnle(int mode, char *pathname, char *arg0,
" I  A/ k  {9 j# J! i% m& x2 Darg1,..., argn, NULL); 7 c& F# a1 y& ^! o
程序例: </P>
  o% K. E8 M' T5 j  x<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>
- z/ o3 u/ n8 Q4 p: t<P><FONT color=#0000ff>#include <PROCESS.H>" \1 I/ c% I! V7 u( Q5 C
#include <STDIO.H>7 }- f9 _( r. @$ O  D+ F
#include <CONIO.H></FONT></P>
. {9 z* ]" z1 d' I: i% D<P><FONT color=#0000ff>int main(void) ' ^' R3 y4 }; e' S  t2 P- K
{
6 p- Y" j( g# N9 n8 k6 e0 fint result; </FONT></P>
! A3 h3 ?. @: g8 W/ U) U: j3 w<P><FONT color=#0000ff>clrscr(); . X% y* J) \" s$ X% X: |) C
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
1 q3 D. \) R8 i! p) pif (result == -1) * G) b/ I  {- c7 @$ ?
{ ( I1 G/ g" P: k' {0 M+ f5 M
perror("Error from spawnle"); " q, G( D  N+ E, O! T* |' v
exit(1); 2 ~6 J& S7 ?) o+ ~
}
- m+ ]0 r% v( X4 ^: Oreturn 0;
/ A7 H  t6 F9 E# d0 Y}
: v% u% n& L9 q( N8 f: G* L% J+ J8 X: I0 W5 Z0 C3 \1 f
, o: M2 d' ^6 f* U
</FONT></P>
1 Q  i0 O9 O* w<P><FONT color=#ff0000>函数名: sprintf </FONT>
3 B- i# h* j1 N/ z( P功 能: 送格式化输出到字符串中 % d, T+ y  r2 o4 X7 N
用 法: int sprintf(char *string, char *farmat [,argument,...]);
$ b' X% K; Q8 r; g# l  G8 H, k) F) F程序例: </P>
- X: R* ]+ a. l" l6 x<P><FONT color=#0000ff>#include <STDIO.H>
0 J6 B/ L  @  `#include <MATH.H></FONT></P>
/ \% n) w2 g5 \. S/ v7 I3 R9 t<P><FONT color=#0000ff>int main(void)
7 r7 ?) n9 f* |/ a$ I( s{
5 L5 A6 G. ]: b; _& q/ z  nchar buffer[80]; </FONT></P># q' Q. w+ \: H- j6 X& u; q, |
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
! O7 h6 E0 S, \9 V& w( S' ^/ D) n/ Dputs(buffer);
" {: K! z+ K; Qreturn 0;
/ U2 e3 _" {6 j) ]} # u; C1 `( L* l) i; H) g. M8 I& L
</FONT>
2 E' |" J$ a, _3 o- p( _</P>
( e1 y; `% G6 m* W  g( X<P><FONT color=#ff0000>函数名: sqrt </FONT>! |* p3 C& u; q  H
功 能: 计算平方根 $ Q( h$ s. v( l& v7 L& L" W
用 法: double sqrt(double x);
3 H* `" G" J4 h* b7 k7 |程序例: </P>
* `! x/ S- @) D: [" Z% D. q3 t$ a<P><FONT color=#0000ff>#include <MATH.H>( G8 ^7 e& \4 E8 m
#include <STDIO.H></FONT></P>8 z. D( U9 R( O( n' ?
<P><FONT color=#0000ff>int main(void) - v8 L+ A, W1 i+ X
{
7 A3 B* \' v- z2 H7 P; u  ldouble x = 4.0, result; </FONT></P>
# n4 A% ]7 i3 Y( |* s+ o<P><FONT color=#0000ff>result = sqrt(x);
4 R! o) V. b: z7 R0 {printf("The square root of %lf is %lf\n", x, result); 1 Y  a% d+ h' L$ q
return 0;
, s% s& X5 F, g# y/ m/ Q8 u} ; x: {9 l  v9 ?  ~( y
</FONT></P># V+ o9 o0 C3 ^" B" K. T7 j( C' V
<P><FONT color=#ff0000>函数名: srand </FONT>6 q+ X$ Y* ]- `8 D  q8 J
功 能: 初始化随机数发生器
9 f9 `; V/ [1 F# g& [用 法: void srand(unsigned seed);
5 h  k$ f( v! u& w程序例: </P>0 s5 Q) R& _$ y  E- H, K% g+ ?9 |
<P><FONT color=#0000ff>#include <STDLIB.H>
/ p. l& ?" Y9 V# }7 g. N2 S- U#include <STDIO.H>
0 p7 k( Q: I, @7 [- A1 q8 E$ h2 e#include <TIME.H></FONT></P>, V: u7 x. ?! Z$ d( r" ^4 T
<P><FONT color=#0000ff>int main(void)
- y9 V$ R9 Y: Y& w# e* a, X{ & d$ ^/ `0 z9 s# K5 d0 Y
int i; ; u( n+ f3 p4 W! O) r
time_t t; </FONT></P>( @6 B7 b' y9 N8 d, B
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
, C: `9 G/ y. C  `printf("Ten random numbers from 0 to 99\n\n"); # x7 k  f  s2 Z% d
for(i=0; i&lt;10; i++)
4 _% F" O$ H0 i, z! N" Y+ jprintf("%d\n", rand() % 100);
0 w9 X  s# y1 {" Q0 preturn 0;
0 @9 |' f% T0 B% o0 J( M4 g3 V}
/ [7 c, a$ n5 l& J; t* f</FONT>
/ V* v- X* `- C, u</P>
4 m# ?( G3 M6 e  d- @<P><FONT color=#ff0000>函数名: sscanf </FONT>
3 B  e3 m. U' ^9 n功 能: 执行从字符串中的格式化输入
8 W$ A' e- h) Y6 M; C% B! F; [用 法: int sscanf(char *string, char *format[,argument,...]); 8 U4 T' M. u8 f# q  x6 r
程序例: </P>
9 d/ q6 W; ~4 n<P><FONT color=#0000ff>#include <STDIO.H>
/ Q) F- ?) Y1 [+ q. q#include <CONIO.H></FONT></P>
/ q: K. T% P' N6 Q<P><FONT color=#0000ff>int main(void) 7 @* J* `' g  z9 J$ \
{
+ J' H! J, o5 Schar label[20]; 9 {4 H3 p) F5 m. y1 O
char name[20]; ) [$ N! ]9 z5 z( r
int entries = 0; . x4 ]7 }( d( H' o! f; U: @
int loop, age; : ?: {% }& I  ?9 s$ K
double salary; </FONT></P>
, K& M' V5 M! P% D0 r7 [<P><FONT color=#0000ff>struct Entry_struct ) K1 x/ Z- t& Y* ]: ?' m
{
6 x) w9 f& p" t& c( dchar name[20];
# E$ ~" f  `% gint age;
, ~0 k  M* \- O, ^" `float salary; # Q5 N- d8 f8 J* m) u
} entry[20]; </FONT></P>
- V9 q3 n8 T/ c5 D<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ 9 g2 w' S* @  n/ R$ [6 F
printf("\n\nPlease enter a label for the chart: ");
6 }4 q; t/ Q% @- P- F9 |( Gscanf("%20s", label);
8 ~2 G) W2 V, \% s4 ufflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
+ B! i# K5 C2 I+ x<P><FONT color=#0000ff>/* Input number of entries as an integer */ 1 Z( L2 c2 j5 L$ n1 I* u
printf("How many entries will there be? (less than 20) ");   D, h* d6 F/ R9 Q
scanf("%d", &amp;entries);   N3 P% t- @7 t& K* A# [& ~
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
/ Z! i/ s2 s; Q# ^7 {  q4 Q' e<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
& f7 s5 X' d  i+ ]for (loop=0;loop<ENTRIES;++LOOP)
$ X5 D3 y* {0 A5 w/ h {
& j9 {9 }- M, j  v; W, _: M  }1 cprintf("Entry %d\n", loop);
; W; s, P& }+ O5 L7 Gprintf(" Name : ");
( }: Z& W0 M3 t9 F. @6 F; _scanf("%[A-Za-z]", entry[loop].name); 1 P3 Y* V4 b2 f3 j
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>, ]. T6 F* F8 `% S
<P><FONT color=#0000ff>/* input an age as an integer */ + C0 J) f9 x- S
printf(" Age : "); + N5 Z7 k' n) h. W
scanf("%d", &amp;entry[loop].age);
. {) h: D. q( h3 I0 [  W1 Yfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
  p6 R8 T5 E. s1 U; w9 w<P><FONT color=#0000ff>/* input a salary as a float */ - A/ `( R1 e9 b* g$ K9 ?
printf(" Salary : "); 1 {8 d7 T8 N+ R1 V0 A  k
scanf("%f", &amp;entry[loop].salary); 6 [; J' q0 Z9 `! e5 B! n
fflush(stdin); /* flush the input stream in case of bad input */ ; a2 G# ~3 M; c( }8 S  H6 b1 t
} </FONT></P>
# S* q4 z* u& L1 L4 \# k8 g<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
1 I' o) F# e, }, @. j9 l; {; ^printf("\nPlease enter your name, age and salary\n");
  e  k7 Q/ G4 ?4 q' _scanf("%20s %d %lf", name, &amp;age, &amp;salary);
/ ?: L+ _  o7 `0 ?" k3 i4 e! F</FONT></P>9 m+ @. X! g: S& u) ~
<P><FONT color=#0000ff>/* Print out the data that was input */ 4 B0 b2 G7 k$ R* `
printf("\n\nTable %s\n",label); $ z. I& A7 F) ]' {) e
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
) }+ C+ d& u3 E5 J$ |printf("-----------------------------------------------------\n"); . ?+ F7 n( H. O& e
for (loop=0;loop<ENTRIES;++LOOP)
( F' P0 E+ l& ~# f0 m6 S6 B, O printf("%4d | %-20s | %5d | %15.2lf\n", 1 g7 U# V# y' b+ _9 ?- Q
loop + 1,
8 E1 d; Y* b0 Q+ l5 E% aentry[loop].name,
9 k: M8 F4 _4 ]- B, Uentry[loop].age, ( P$ }' Z' _2 _$ I7 B* G8 G0 R
entry[loop].salary); . l. h+ [, E' @# o6 u: e
printf("-----------------------------------------------------\n");
3 S% K; r; H; k' B: I+ Sreturn 0;
! H/ [2 G% l2 m' L$ \} : e6 b; ]$ q/ a, v2 }
: X; m* @# U! K0 A% N7 @. b8 E
</FONT></P>
+ q: @5 I  R- s<P><FONT color=#ff0000>函数名: stat </FONT>
1 K; w( B/ D6 x; C, r( G功 能: 读取打开文件信息 ! Y  u6 a0 q  H4 j+ \) J
用 法: int stat(char *pathname, struct stat *buff); 2 F6 x, `& x* S5 c, T& y6 p
程序例: </P>1 M1 d  _: K8 R, G! Z0 ?1 y6 m
<P><FONT color=#0000ff>#include <SYS\STAT.H>9 S# \* @; p8 R; L0 X
#include <STDIO.H>7 H6 v- |) G. w
#include <TIME.H></FONT></P>
  m' K5 ^' @" N) L<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
, h, Y6 {9 s0 Y<P><FONT color=#0000ff>int main(void) . G: D; F5 T. X, d$ Q
{ 1 |# U+ x& v$ l+ ^- ~, H# g' w
struct stat statbuf;
4 k6 u# h$ U. ]9 }FILE *stream; </FONT></P>
8 X( p" {5 Q/ D1 x& T5 d( S<P><FONT color=#0000ff>/* open a file for update */
7 A! i. I  I& N! M* r8 oif ((stream = fopen(FILENAME, "w+")) == NULL) % |. i; i- a: ~5 x/ ^
{ ; P$ o1 U: F& W2 c
fprintf(stderr, "Cannot open output file.\n"); / c1 E( U4 `$ B# ^( x) P" q, ]
return(1);
' W5 q0 v" X) D. t) E% F- s5 m} </FONT></P>) r2 U+ i5 J5 l  B. L
<P><FONT color=#0000ff>/* get information about the file */
% [- Y' Z! j2 }# Xstat(FILENAME, &amp;statbuf); </FONT></P>
( l, h$ [0 s7 N2 D! v! h3 X<P><FONT color=#0000ff>fclose(stream); </FONT></P>
' k4 i% _! q9 h; @( d3 B* G<P><FONT color=#0000ff>/* display the information returned */
. s2 Y9 m1 T" dif (statbuf.st_mode &amp; S_IFCHR) 2 z+ [9 d  n, s) |" L1 p# w" \
printf("Handle refers to a device.\n");
! ~$ y) T& f; X( f4 ^if (statbuf.st_mode &amp; S_IFREG)
8 w1 y6 |/ h- c4 o1 ^4 fprintf("Handle refers to an ordinary file.\n"); ) M; `- ]) U4 D0 p4 d3 @
if (statbuf.st_mode &amp; S_IREAD)
3 F: q: E8 S# {; y/ bprintf("User has read permission on file.\n");
# E7 q7 f- [+ W& t+ m$ z" L- E4 U  rif (statbuf.st_mode &amp; S_IWRITE)
: t0 V7 r: d. }8 W: bprintf("User has write permission on file.\n"); </FONT></P>0 A/ N7 c# ?2 W0 ~; V
<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
6 D5 D, ]0 b, o* `8 Jprintf("Size of file in bytes: %ld\n", statbuf.st_size); 1 f7 x9 }& T! A/ z2 T6 l
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime)); * k5 @& b) L7 T! I: C* X
return 0;
" W+ W: l8 D( |" L: Y9 c} : i" Z1 k2 T% t- f/ Y) Y
9 z# J% O: p* c, L* ^3 X" L4 t3 q
</FONT>
/ r1 E4 y% X+ D</P>
# Y0 @7 b( O# B3 D<P><FONT color=#ff0000>函数名: _status87 </FONT>
% h5 ]0 F  n% Z5 L" e! e( L6 O% F功 能: 取浮点状态 5 k; A! V2 k* n6 G: ?4 N5 S
用 法: unsigned int _status87(void);
4 M  W" }8 g& k; C% u程序例: </P># n7 q# }: }6 U5 r
<P><FONT color=#0000ff>#include <STDIO.H>9 r- j2 k" }% x' q# h
#include <FLOAT.H></FONT></P>2 b" F: M0 e% X
<P><FONT color=#0000ff>int main(void) % ?- ?5 n; j% O$ ]
{
- Z$ z( B4 z9 I* i/ bfloat x;
+ u6 J7 h. z- |6 w8 N4 sdouble y = 1.5e-100; </FONT></P>
2 c1 k! N- F1 \/ W# b' y# A<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
9 U6 y+ B7 M7 U' u% J& a<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */ * K1 G+ P' v# ^* R9 s( l
y = x; </FONT></P>6 v5 @. e1 L  f* v8 R
<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
6 R: a4 ~! x- M! ?0 z+ sreturn 0;
( U: `( n" y' Z}
( Z+ F1 k% X9 M3 P0 W8 K4 p3 b& x</FONT>
. p# m2 ^4 t/ T( U</P>9 q  h. h" Y1 |9 `$ }7 b0 x
<P><FONT color=#ff0000>函数名: stime </FONT>1 V* I, R+ W' |7 {* G
功 能: 设置时间
' V5 Y' _2 t6 \" B0 {: F" z用 法: int stime(long *tp); 7 A% Y9 D5 L7 E  j8 A7 ~* T
程序例: </P>
. t) n4 d4 p; c8 t<P><FONT color=#0000ff>#include <STDIO.H>
3 ]  v: m3 e5 T3 U#include <TIME.H>
8 R4 \) B. M5 G6 D$ F#include <DOS.H></FONT></P>7 [% Y7 F! d& q. ^% s0 s
<P><FONT color=#0000ff>int main(void) % s; q6 [/ G8 R, T- N
{ ! i* W- P0 h$ N; _
time_t t; ( \- }3 g/ _2 [
struct tm *area; </FONT></P>
2 T: u6 n/ j) z0 r" Z- Q- V( B<P><FONT color=#0000ff>t = time(NULL);
+ Z+ }' D  q9 }, O; M+ x  l& Jarea = localtime(&amp;t);
  D$ I+ W& H/ ^9 _printf("Number of seconds since 1/1/1970 is: %ld\n", t);
3 E: ?1 c8 H& t2 T' |printf("Local time is: %s", asctime(area)); </FONT></P>; h, d3 l& F# }3 K3 q
<P><FONT color=#0000ff>t++;
4 f, _8 ]# C: R: z; Y# G: uarea = localtime(&amp;t); 1 x) A; [) @( I; U' l
printf("Add a second: %s", asctime(area)); </FONT></P>9 E  D4 ^8 A) A% U
<P><FONT color=#0000ff>t += 60; 9 a7 i- g9 q- ~7 E. X
area = localtime(&amp;t);
" Y( \+ j! b, m  @* C1 {printf("Add a minute: %s", asctime(area)); </FONT></P>$ Z- J  Z# H5 B) T% o
<P><FONT color=#0000ff>t += 3600;
3 v5 y" G5 O/ q6 }& B7 p3 iarea = localtime(&amp;t);
; H# _( B) g- N8 r! dprintf("Add an hour: %s", asctime(area)); </FONT></P>
1 f2 g+ l* i. c' f8 T9 N+ \<P><FONT color=#0000ff>t += 86400L;
& ^" K1 J2 P  Z8 N0 Jarea = localtime(&amp;t);
0 \4 M% t2 D4 rprintf("Add a day: %s", asctime(area)); </FONT></P>
+ I1 b4 `2 g9 P, ?: ^<P><FONT color=#0000ff>t += 2592000L; , \# L( D+ i7 P: f4 D( C
area = localtime(&amp;t); ( b2 }+ U2 ^1 q4 f# N
printf("Add a month: %s", asctime(area)); </FONT></P>
* y; k+ b! ~6 }<P><FONT color=#0000ff>t += 31536000L; & W9 p, N' E* c! ~" N7 i8 I
area = localtime(&amp;t); ! [/ I4 O# S7 T3 a. w2 M
printf("Add a year: %s", asctime(area)); ; _: }* \4 l5 I- Y9 y5 H( P
return 0;
* K6 g+ e( {, }/ S: Y} </FONT>
6 \$ I, h: }- ]  D* A- o
1 C7 d; ^" @* ~
" l6 v. d2 F2 W3 n( S" [  [</P>
" l. N$ B3 r/ B2 b9 O<P><FONT color=#ff0000>函数名: stpcpy </FONT>
2 B  Z. R5 e  F% q5 X3 t# O功 能: 拷贝一个字符串到另一个   H$ G0 p$ n4 W
用 法: char *stpcpy(char *destin, char *source);
1 Z9 z, R* o7 Q" p; I/ K2 c) G程序例: </P>$ r8 P  b' w, }
<P><FONT color=#0000ff>#include <STDIO.H>& x6 z0 M, a+ C% {
#include <STRING.H></FONT></P>
  c$ T2 c0 q7 E<P><FONT color=#0000ff>int main(void)
0 o4 v) m* U. _- B{   l5 `0 o2 I- O, [3 \6 j) M) S6 `0 T
char string[10];
) L$ F3 ]5 U: P: w& M) W$ ~char *str1 = "abcdefghi"; </FONT></P>$ p4 E- b; R6 ~
<P><FONT color=#0000ff>stpcpy(string, str1); / G6 r+ G; P8 X
printf("%s\n", string);
5 l, ^: H; G. p& q! k' y( {. freturn 0;
7 j! j) g  |7 A6 ]}
4 K, j  x) q1 B  @, X/ O9 u3 M! a; K, V+ \1 W
</FONT>
$ Q7 y  K4 q* _' m& i# S1 ~</P>
, ?) m$ e% x$ q& p<P><FONT color=#ff0000>函数名: strcat </FONT>
6 Z0 T2 w/ _2 W功 能: 字符串拼接函数
. }; E3 a. H8 f- {- y用 法: char *strcat(char *destin, char *source);
/ W; U5 e) y/ o& u' z$ A程序例: </P>
, O1 Q3 H8 [8 N- `<P><FONT color=#0000ff>#include <STRING.H>
6 j& X. ]2 h1 i9 f#include <STDIO.H></FONT></P>
- T9 N& w2 t. j+ t. R( |<P><FONT color=#0000ff>int main(void) ! |; Z$ I% i* B2 R2 b1 c
{ % y+ N5 U- \. U% `2 t0 h% e
char destination[25];
, j  a: ~" ]0 U1 h( f( W, Xchar *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
4 a' k2 r- b8 v<P><FONT color=#0000ff>strcpy(destination, Borland);
5 y" H7 Z" R9 Lstrcat(destination, blank); , C, X4 r: E. Z
strcat(destination, c); </FONT></P>
7 r" c+ i: {* ]% t7 J! M<P><FONT color=#0000ff>printf("%s\n", destination);
# x) ?& d  U! t; \return 0; 8 Y: @0 N2 u6 M& f0 G9 B: }8 V
}
: H; g0 v( o0 Q7 \
* E. Y0 |" M* f</FONT><FONT color=#ff0000>
, e" W4 @' s3 D* i  I8 f2 o. _0 K: `* E</FONT></P>
7 V9 {/ B( q+ U6 x) z<P><FONT color=#ff0000>函数名: strchr </FONT>
) W. R; W* Y& M9 p/ |2 ^功 能: 在一个串中查找给定字符的第一个匹配之处\
$ t  y+ n, j6 \( h! S用 法: char *strchr(char *str, char c); * [" g% m. q- E. W. N& B% K
程序例: </P>; V0 ?. k' J+ H/ q: F8 v! g
<P><FONT color=#0000ff>#include <STRING.H>
% e/ b! S5 x/ ~9 ]. j#include <STDIO.H></FONT></P>( m( h' E! y5 `% ~8 P
<P><FONT color=#0000ff>int main(void)
6 c) P7 s9 E/ [{ 6 I+ u* n* X- B) s9 e8 `
char string[15];
  A0 ?4 C: B* o( Z0 v4 J- Ychar *ptr, c = 'r'; </FONT></P>, ~! T4 M5 R; Q) K) P
<P><FONT color=#0000ff>strcpy(string, "This is a string"); # `2 `0 `% V5 F8 p( t; t( n6 u* @
ptr = strchr(string, c); ' Q0 S8 H8 j2 y5 a, t* W
if (ptr)
0 k0 F/ d+ X/ ]6 kprintf("The character %c is at position: %d\n", c, ptr-string);
- v; s/ g- Z& Oelse 3 Y, B8 L0 T" m) `
printf("The character was not found\n");
' l  _& y1 _4 |) R4 a" s8 P9 hreturn 0;
9 b$ j. m; e4 n/ K4 M8 F' A5 W6 L} ' S  R) H+ W1 u" F0 t& P  s: j
</FONT>" O1 U5 ^' H2 G6 i; u
4 |6 l% o! j; N, ^
</P>
2 i: ~1 X+ T3 y<P><FONT color=#ff0000>函数名: strcmp</FONT>
# _+ }* J# a% O4 m) |8 Y8 P功 能: 串比较
7 z: R% c4 z: \( v# n9 B用 法: int strcmp(char *str1, char *str2);
9 t; c0 i- W0 D程序例: </P>
7 h8 b  s  B% t5 F<P><FONT color=#0000ff>#include <STRING.H>
; H' n/ i; Z! n. E( Q/ r#include <STDIO.H></FONT></P>
& h! A! F1 a$ u$ b6 m0 k  D" K<P><FONT color=#0000ff>int main(void)
+ Z. |+ i/ i, o; @6 X{ ; O# f/ i! c2 z" ]
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc"; % x( m5 G" o. I- q: ~7 D3 n
int ptr; </FONT></P>
' f! }- a; ?8 ]; \<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
6 v4 u! Z8 Q. b1 t( T) o2 `if (ptr &gt; 0)
8 j5 z4 r5 V1 m2 I# s# K0 b$ {8 Hprintf("buffer 2 is greater than buffer 1\n"); ' q, Q, E" {5 E% J/ I) j
else : `+ W# s7 I2 m0 N& T; C
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
; B+ j1 {# m* ?: r/ q' f  n<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3);
5 v" G- N9 L+ t& H! X: n% K! w4 Q/ Vif (ptr &gt; 0)
  R8 e: y7 e2 k; g1 K% qprintf("buffer 2 is greater than buffer 3\n"); , s, e+ h$ J7 V! d# N' L
else
! O9 f' p# ~7 iprintf("buffer 2 is less than buffer 3\n"); </FONT></P>
+ r/ O% ^& ?7 z7 a6 g+ D. R, S9 }<P><FONT color=#0000ff>return 0;
4 O3 A8 M3 X+ l7 M- @' }}
+ W. u' V' P1 \& e# b
6 p- D9 A. \2 U7 W; h: n# {& d. F5 f' q! b7 T2 ]: S
</FONT></P>; |9 U- |6 Q3 r  W2 Q% b
<P><FONT color=#ff0000>函数名: strncmpi </FONT>
( j/ `( F* }( K9 U$ D功 能: 将一个串中的一部分与另一个串比较, 不管大小写 . J" l( ^7 v8 Q  N  q
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); # h( R$ k9 [8 @" q- O8 z+ Z
程序例: </P>" j7 W5 f+ _0 H5 Z  m+ t! K" g
<P><FONT color=#0000ff>#include <STRING.H>
2 c8 f; d# q- c# q+ j) @6 s#include <STDIO.H></FONT></P>' @+ v/ y1 @/ g6 j1 e) Q
<P><FONT color=#0000ff>int main(void)
$ q6 |' T+ u. t% g{
( g7 [0 U" H* Dchar *buf1 = "BBB", *buf2 = "bbb";
; P7 O4 Y0 I! Y, Yint ptr; </FONT></P>
+ _& i$ T3 Q& ]1 o; f0 N5 k<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>( ~% Z$ I8 s- I, L+ p2 m
<P><FONT color=#0000ff>if (ptr &gt; 0) 5 Y. I7 P" ?% a, H
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
( L% T% y( h0 M<P><FONT color=#0000ff>if (ptr &lt; 0)
; A" W" Z  y/ r1 U# v- ~1 O1 Mprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
3 X& C' W% y4 g2 y* P! Z- U; }- Q2 V# L<P><FONT color=#0000ff>if (ptr == 0) 0 v6 U0 o, m9 y8 B/ x% i1 H7 G
printf("buffer 2 equals buffer 1\n"); </FONT></P>  Z6 w( z" d  {, a* X- E7 A7 r4 [
<P><FONT color=#0000ff>return 0; % P2 A" Z+ `) i& }& z0 Y( ~( {( X
}
: v0 H* a; X1 m* u' A9 H. q2 f' n1 \2 K: l  s* W/ U$ l, a) U
</FONT>
3 V7 p' T7 @8 X5 {6 f2 v  f, r( u0 ~</P>
  q  g4 F7 \  C1 {+ c<P><FONT color=#ff0000>函数名: strcpy </FONT>
; C  r$ x5 B+ z' n功 能: 串拷贝 % X) p9 X0 q1 v; u) F5 W$ E
用 法: char *strcpy(char *str1, char *str2); . Y, K( X6 `( ^6 s% o( E/ a; l
程序例: </P>, [/ q4 B6 q/ L1 l( q4 z) ]1 H
<P><FONT color=#0000ff>#include <STDIO.H>
. }- [. W. s! d' q5 R#include <STRING.H></FONT></P>
) t, `/ _: j" L8 F+ |( [/ ^<P><FONT color=#0000ff>int main(void)
: Q1 a. J, Y/ k7 |7 I7 C{
1 y# a+ U0 B* m% n$ K; a5 xchar string[10]; % i7 W' c; h. Q; D% o5 F7 v/ f" p
char *str1 = "abcdefghi"; </FONT></P>
! B" t! d; v8 \# w) M<P><FONT color=#0000ff>strcpy(string, str1);
& G# A2 x; z4 I9 l/ b6 u" n" Wprintf("%s\n", string);
, C: p2 {* ~; d* T8 f+ Jreturn 0;
* b: ^8 d0 E1 v}
( e! D6 X6 V# `</FONT>& o  {  R  a2 p5 N' [. J

% u$ U0 p5 v  H$ B( `</P>) Z5 s  ^# n1 l( u: n: u% J3 G
<P><FONT color=#ff0000>函数名: strcspn </FONT>( ^9 {- D4 D# M( u7 f
功 能: 在串中查找第一个给定字符集内容的段 : E  k! h) e/ f- b5 m! z
用 法: int strcspn(char *str1, char *str2);
6 M8 h) f& C0 H7 k程序例: </P>+ J; L5 H5 n+ _3 C
<P><FONT color=#0000ff>#include <STDIO.H>
# K: h2 ^9 q5 k- f#include <STRING.H>
5 I& G& W6 [1 t" T; K4 E4 Y  H#include <ALLOC.H></FONT></P>& h. l' k" x# @8 j+ n6 }
<P><FONT color=#0000ff>int main(void) & a0 v) I0 z6 D0 `! v( u4 f
{ $ E; ^" f# u- b$ T8 Z
char *string1 = "1234567890"; 1 r. Y: U. o+ l
char *string2 = "747DC8";
6 `9 _, W; {9 U7 Hint length; </FONT></P>
# j3 t. [. T: ^; F/ [2 _) {<P><FONT color=#0000ff>length = strcspn(string1, string2);
0 G- p% ]0 N4 ^6 |# Q6 N' y. }# ~printf("Character where strings intersect is at position %d\n", length); </FONT></P>
% s$ N9 u0 P, b) A9 E" J* h( g! a1 }<P><FONT color=#0000ff>return 0;
+ U2 j! Y$ M9 O} & G7 W. ]/ k3 S: O
</FONT>/ K/ L/ g! K9 c" P2 L6 ~8 o% y
) G2 W* C& V8 c, e9 W3 q
</P>
- L3 q9 X8 s( v. ~/ t! e<P><FONT color=#ff0000>函数名: strdup </FONT>( y9 i6 y. \7 Y, {- Z
功 能: 将串拷贝到新建的位置处 3 V/ i; p# w- X' d# G- T8 J" R6 c) x
用 法: char *strdup(char *str); : k% M' E9 ?9 x) a! ?$ r8 ]
程序例: </P>9 O3 N& M/ Q# f& E$ ^2 W- J
<P><FONT color=#0000ff>#include <STDIO.H>1 T: T4 [) f) m
#include <STRING.H>
( a! }- O: Y* k; j3 s" s#include <ALLOC.H></FONT></P>
: |- g/ e  y6 y; v% s$ o<P><FONT color=#0000ff>int main(void)
% {9 o8 f6 L2 ?{
( j: b9 F; Y- cchar *dup_str, *string = "abcde"; </FONT></P>
5 D5 Q$ t! |$ w% K% y" Y5 B<P><FONT color=#0000ff>dup_str = strdup(string);
) Y' x' |1 U/ }0 K, W0 |5 h9 L+ Oprintf("%s\n", dup_str); 9 H, e, m: t- u/ r, l7 ?& d) ~; J' p
free(dup_str); </FONT></P>
' \/ q, d: C! Z1 k3 w, M; Y  S<P><FONT color=#0000ff>return 0; 3 A+ x  T: y" D
} 4 w8 R8 v% F; W9 [: n

" f  h( v  _$ H1 l$ }/ c, k. i</FONT>
5 z' c; w9 B, S/ M</P>& ^+ j$ c: i, b; y1 M- ^
<P><FONT color=#ff0000>函数名: stricmp </FONT>: [8 I8 I3 b6 Q( h
功 能: 以大小写不敏感方式比较两个串 3 Q% A! @% b3 J& x, B+ g! ^  L
用 法: int stricmp(char *str1, char *str2); ' r9 O: N! @) G- U0 H0 m2 F) \
程序例: </P>8 J" n# G! O# K* p( D
<P><FONT color=#0000ff>#include <STRING.H>
! h$ f& K0 O: Z- y+ X$ j#include <STDIO.H></FONT></P>
- \9 g6 m2 ?4 e# p/ s<P><FONT color=#0000ff>int main(void)
  c$ w  o, Z( v/ o) U* _2 m{ / B# _: e  B/ Q3 F4 x0 @
char *buf1 = "BBB", *buf2 = "bbb";
. C; X0 ~8 _% D8 C6 }int ptr; </FONT></P>
; z# }2 L- s1 x8 r- M<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
) B0 I1 ?: ?6 i8 o<P><FONT color=#0000ff>if (ptr &gt; 0)
3 X/ n$ m: ]7 b* P1 pprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
# w4 M& m) v1 d9 j/ V! m9 ^, Z, X<P><FONT color=#0000ff>if (ptr &lt; 0)
: x( j% E% Q' C6 ~& ^( hprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
3 }9 R# X: [/ h) J' f<P><FONT color=#0000ff>if (ptr == 0) , a1 @8 a3 I8 x" I9 y, h+ ?( e
printf("buffer 2 equals buffer 1\n"); </FONT></P>
" Y7 I- e. m7 D3 ^+ N' ]5 D<P><FONT color=#0000ff>return 0; ! P' ^8 K; v4 |# W7 v8 @) ]
}
, F, d4 u5 ^) @/ P  d' Q8 t</FONT>; R/ r8 Q" Y/ Y
</P>6 v4 w8 H1 q) W% L1 L
<P><FONT color=#ff0000>函数名: strerror </FONT>3 m% R0 b  K5 b6 y8 {& O
功 能: 返回指向错误信息字符串的指针
- e: K* {0 w- d/ P- ~0 c5 {% B用 法: char *strerror(int errnum); 1 Z  p5 h  w) l1 A
程序例: </P>5 @  _. J, w) I: q9 D
<P><FONT color=#0000ff>#include <STDIO.H>4 i8 a+ |! L4 I6 g% L& E
#include <ERRNO.H></FONT></P>
) s1 I- M6 y3 q6 E' B  P! F1 C7 V<P><FONT color=#0000ff>int main(void) & D; A! E6 Z0 z( E) V9 P
{
6 Q8 y: C- K/ \' c7 Jchar *buffer;
( D4 M$ f4 B9 R! ]4 zbuffer = strerror(errno); ! n( N) J: I1 s. E. B
printf("Error: %s\n", buffer);
/ \2 P; E2 F5 J- S4 _' Rreturn 0; / _2 l7 `6 i! b9 X  y
} 0 f$ G5 D3 U$ W0 M

, o) _1 _/ z  X* ?1 A</FONT>
0 L1 C* Y) {: k2 L* i5 `</P>4 g- I0 s( E, s/ J
<P><FONT color=#ff0000>函数名: strcmpi </FONT>' l8 R& ^8 S, W1 _! L
功 能: 将一个串与另一个比较, 不管大小写
0 u0 |% j; F! |1 X+ ?  k2 T* K用 法: int strcmpi(char *str1, char *str2); 8 x( |1 t$ w, V( {/ Z
程序例: </P>3 @) U8 z' |& b, o0 h# y
<P><FONT color=#0000ff>#include <STRING.H>
- c  }4 X3 e# X* r8 S! b#include <STDIO.H></FONT></P>
( G4 v1 ?3 j% v6 C/ I5 S9 F9 T<P><FONT color=#0000ff>int main(void) ! z1 U! c( H" n, g& i% e
{
' k' q+ Q$ X* D" W9 _9 uchar *buf1 = "BBB", *buf2 = "bbb"; - c3 i1 u% K- X3 p) y/ w
int ptr; </FONT></P>  m/ v. ^$ f' Q
<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
% M/ I: ]& a3 _<P><FONT color=#0000ff>if (ptr &gt; 0)
# q8 {. c2 R: a. X3 bprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
) L' H) ]1 n+ b1 A4 U& d+ G* t& }<P><FONT color=#0000ff>if (ptr &lt; 0) 7 q2 N, H$ ~3 R3 y
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
' b5 V$ a/ ~' i- L1 I+ F<P><FONT color=#0000ff>if (ptr == 0) * a9 z6 U' N8 o, @4 V% f' B& z
printf("buffer 2 equals buffer 1\n"); </FONT></P>2 O9 {- q# ^, a; m- S" f/ w" ]) Q
<P><FONT color=#0000ff>return 0;
# O* c- e2 }5 r4 A}
; X, R2 e2 @6 ?. M6 S</FONT>8 K/ X- o. p6 ]6 ?7 y5 D4 Q7 J
1 R5 r. F- @- {& H3 i1 G( @) M
</P>
5 d% N. n2 v3 b<P><FONT color=#ff0000>函数名: strncmp </FONT>+ H8 I( g- j2 Z- j7 E3 j
功 能: 串比较 - d; i. N! V% E$ T8 o6 {
用 法: int strncmp(char *str1, char *str2, int maxlen); ! I. e. v3 ?& X) v
程序例: </P>' H1 @2 ~7 ^8 s4 [- J) Z& l
<P><FONT color=#0000ff>#include <STRING.H>3 ]' x6 P6 Q( u) e, A. X& ?, E3 g
#include <STDIO.H></FONT></P>
0 [- J0 B  \: j( p5 \* h3 ~8 n# }: O2 }<P><FONT color=#0000ff>int main(void) </FONT></P>, c! E# A+ w: Z+ _
<P><FONT color=#0000ff>{ 3 p+ N% N/ q0 g1 K4 h- K5 M5 I* ?- }
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc"; 5 `' a; d2 C/ S7 }+ g
int ptr; </FONT></P>
, s+ H0 R8 f0 J! N<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
. ]( O$ s6 t( sif (ptr &gt; 0)
- W1 X( \9 a* T( C$ t8 ^! qprintf("buffer 2 is greater than buffer 1\n");
5 }% G% x# L/ B2 x8 celse
! V9 `$ c4 y4 w2 X6 t* R, {9 M, lprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
/ T0 S/ @; a6 x" f& {0 n7 V<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
( G$ v  }2 o5 M" c2 b( kif (ptr &gt; 0) # X/ U' Q( v; ^* I- `
printf("buffer 2 is greater than buffer 3\n");
1 Y, H( W9 g# @5 C$ L8 ~9 p% lelse 2 E' v! m( C+ Q( g) ~% u  }
printf("buffer 2 is less than buffer 3\n"); </FONT></P>! U! [: r$ K7 d( W' g; w
<P><FONT color=#0000ff>return(0);
4 L% x' ^6 S7 U! P7 A8 J7 M8 M7 V}
' u9 Y! E: o- R( w; m, c
) `7 M! q5 S% |4 ~) ?7 Y& _8 o0 ^8 L2 E</FONT></P>
8 Z9 g4 d& P* j9 R& R& M% ]$ P<P><FONT color=#ff0000>函数名: strncmpi </FONT>1 d7 z( O: U9 y- j' S8 k/ }
功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 + r. e+ U& ?% F4 h. s  a+ f5 X
用 法: int strncmpi(char *str1, char *str2); * `2 T5 C( ^/ i, c7 C; S. k( N
程序例: </P>
( ^0 p! d' {3 B* k- H<P><FONT color=#0000ff>#include <STRING.H>
' y3 \* }- w- C( M+ J#include <STDIO.H></FONT></P>6 J7 v/ C/ [+ {, @" K# B
<P><FONT color=#0000ff>int main(void)
: f% R2 |9 s4 ]0 q3 {/ \{ ' }* f. n1 Z* z5 n4 r: n
char *buf1 = "BBBccc", *buf2 = "bbbccc";
$ ~2 E$ m$ C7 P5 N+ c) {int ptr; </FONT></P>
/ V& q/ L8 y+ d, u, K<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>% r# O% U% {6 Q3 T# N" v
<P><FONT color=#0000ff>if (ptr &gt; 0)
: O; M' i$ |* S3 hprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
$ L4 t" |/ g' o8 W<P><FONT color=#0000ff>if (ptr &lt; 0)
3 p0 K+ a$ {% U3 ]& _( y8 [4 b- pprintf("buffer 2 is less than buffer 1\n"); </FONT></P>; h$ O) K6 C% Y. ]
<P><FONT color=#0000ff>if (ptr == 0) 9 `6 ^+ ~4 b5 B+ M0 O
printf("buffer 2 equals buffer 1\n"); </FONT></P>
& ^8 P. d2 g% x# h% ?<P><FONT color=#0000ff>return 0; </FONT>6 B1 ~. E$ {* V6 U# d2 a
} 1 \/ v; V  j' r+ H% B( S
6 ~1 {7 E- T: h0 _: J; W
</P>
# A# r$ f" x) G7 f: l) R& @<P><FONT color=#ff0000>函数名: strncpy </FONT>
- m6 e0 v0 @4 A8 O功 能: 串拷贝 , w# b6 W% F8 l0 h8 f) u$ z/ S
用 法: char *strncpy(char *destin, char *source, int maxlen);
5 g  j- N" c' X4 k8 k* o程序例: </P>" _2 B+ O6 k: [$ Z+ i1 m8 [6 F
<P><FONT color=#0000ff>#include <STDIO.H>
! r5 E! [& c! ]  D7 m/ c/ e4 g#include <STRING.H></FONT></P>) ]) W/ y4 w8 i; K. r9 Z/ ?6 B- D" N
<P><FONT color=#0000ff>int main(void) + O, y' N- `9 o) M4 {' [
{ , |5 v+ B" j7 T# S- X, u# r
char string[10]; 2 W4 z; i* A! v3 P4 D. v  ~6 {
char *str1 = "abcdefghi"; </FONT></P>
- A4 E: B* P0 J2 }<P><FONT color=#0000ff>strncpy(string, str1, 3); ( |3 Y4 [0 U5 D  X3 i
string[3] = '\0';
# c! P. Y1 h( C8 C) u9 Uprintf("%s\n", string);
" ^; x) d. i, r% p3 R/ g  U' Treturn 0; * v) Y! K3 b$ _
} , j# c- d0 Y5 e$ _. q
</FONT>
" Q- s3 L+ N. D% U2 B4 r) S- o</P>
0 b8 |3 \, R/ q1 v# P<P><FONT color=#ff0000>函数名: strnicmp </FONT>
1 O8 j0 o& o- W; c/ c# S; f: d功 能: 不注重大小写地比较两个串 # W! M: T4 |/ O. e" s5 T
用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); ) G* ?" R, C& c2 p
程序例: </P>
7 b, \- g+ v8 |0 N. _$ t<P><FONT color=#0000ff>#include <STRING.H>7 q- T0 y. y8 _
#include <STDIO.H></FONT></P>8 J) R9 g) c4 Z# m( V: U/ _
<P><FONT color=#0000ff>int main(void)
! f" h" t. H1 q6 Z: i{ 4 u& E/ e0 r+ [$ N8 P. Z
char *buf1 = "BBBccc", *buf2 = "bbbccc";
& }1 O. P6 n; S$ v$ I' {8 ?% ]int ptr; </FONT></P>
4 M& i. K7 h0 b+ |8 y5 ?<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
4 `/ Y7 S8 e6 E' [$ @<P><FONT color=#0000ff>if (ptr &gt; 0)
4 e8 X/ c0 ~: e% r* kprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>: f- O( B  V9 G8 E  }( X2 B' K
<P><FONT color=#0000ff>if (ptr &lt; 0)
% ]: W" g5 k8 c+ kprintf("buffer 2 is less than buffer 1\n"); </FONT></P>! B9 c1 m, G! O% _9 g
<P><FONT color=#0000ff>if (ptr == 0) 8 r% e. }8 [  R) T* Y9 m, ?, G
printf("buffer 2 equals buffer 1\n"); </FONT></P>
. w, ^2 {; v* b$ E, F<P><FONT color=#0000ff>return 0;
0 E  Y) I5 @9 \1 ~}
% {0 I/ F3 v; `/ U  u! m
1 t( N7 c3 u- b+ Q5 O& P</FONT>
; J" B1 |$ i8 X8 }</P>
  K1 A, o: s7 P' ?# ]" I<P><FONT color=#ff0000>函数名: strnset </FONT>; |3 I" w. X9 q0 q
功 能: 将一个串中的所有字符都设为指定字符
9 y$ Z! j' h6 k/ n用 法: char *strnset(char *str, char ch, unsigned n); % Q, U- a1 t* T1 j2 ]: K
程序例: </P>
* z7 f" }# x; Z<P><FONT color=#0000ff>#include <STDIO.H>% S1 u2 U" j8 R$ r" F6 D
#include <STRING.H></FONT></P>
" [) U+ @; S! ~2 ~" V+ K3 J4 F0 T<P><FONT color=#0000ff>int main(void) " V* V. Y# S2 K7 u- P: a/ h% q
{
4 c7 w9 P: h6 Gchar *string = "abcdefghijklmnopqrstuvwxyz"; 0 P# y% d* q! M6 Q
char letter = 'x'; </FONT></P>. W+ |* ~6 J3 |
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string); 3 [4 q# E6 F9 p1 r
strnset(string, letter, 13); ( B% m& X( S: R
printf("string after strnset: %s\n", string); </FONT></P>5 V4 P8 P: V, T5 a0 L* x( f
<P><FONT color=#0000ff>return 0; , ~7 ?1 T# ~( O7 p- ~
}
' z/ {! o/ z% m</FONT>) H0 N) R' @9 Q" {' @+ n; z% ~
</P>1 C# E7 F+ I, Q  M
<P><FONT color=#ff0000>函数名: strpbrk </FONT>, Y% K: F) T7 b5 z4 G
功 能: 在串中查找给定字符集中的字符
7 I% X; P* Q( m# N3 J  |用 法: char *strpbrk(char *str1, char *str2); * |3 {. \* G( s1 n: T
程序例: </P>
' f3 l  P2 s, Q/ V<P><FONT color=#0000ff>#include <STDIO.H>1 `9 Q9 R& C9 A1 n) {6 Y2 l
#include <STRING.H></FONT></P>" z- h8 t7 X( r7 {. `' R% `
<P><FONT color=#0000ff>int main(void) , m, b. O4 J- n+ f5 g
{ 6 F6 c9 Q, C, m- V8 Z
char *string1 = "abcdefghijklmnopqrstuvwxyz"; # M, L5 Q: {5 q4 C4 X/ w! r
char *string2 = "onm"; & @4 c9 {( f6 ~
char *ptr; </FONT></P>2 c1 `6 z0 h9 K& V9 o+ S
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
* H# M% [: l1 ]& b<P><FONT color=#0000ff>if (ptr) 0 Q% I: B: f5 B4 ~7 C+ j4 b
printf("strpbrk found first character: %c\n", *ptr);
& x* q- r& P0 e4 d& l" velse
6 m4 @, v8 u7 b5 \printf("strpbrk didn't find character in set\n"); </FONT></P>3 I" ~7 I; ]" Q" n0 w
<P><FONT color=#0000ff>return 0;
( ~* D1 n; `  l7 y! {+ F# z6 y}
4 h0 S5 k0 _6 u3 B0 E- t- z' w5 N. s8 r7 Q2 v& U1 j! ^
</FONT>
2 y# J8 P) ^# z; t1 G; c</P>$ K1 Q( u1 @3 |. {5 A& ]
<P><FONT color=#ff0000>函数名: strrchr </FONT>
( D  S% ^# s' ^5 f/ J! j* Q6 K功 能: 在串中查找指定字符的最后一个出现 & j$ ^# v( b4 a
用 法: char *strrchr(char *str, char c); 2 v7 I! a8 S, c3 w' o
程序例: </P>
* F# I& I* a3 v. ~6 O7 I<P><FONT color=#0000ff>#include <STRING.H>3 }! {5 [' U! J6 J
#include <STDIO.H></FONT></P>
% n# c! W, G) g, ?. o7 T8 c<P><FONT color=#0000ff>int main(void) & }( m- b) h! T: Y2 ]! ^  g& F
{
0 d% I7 U+ T) v) R5 t7 J" M* zchar string[15];
% S, o% `' R8 achar *ptr, c = 'r'; </FONT></P>
  S& s# e3 X, `) Z3 @- V0 K0 ^<P><FONT color=#0000ff>strcpy(string, "This is a string"); ( g& y6 r7 y* U6 o3 n
ptr = strrchr(string, c);
9 N9 o$ L  W9 h+ a" Kif (ptr) . q* `1 s  {1 I' W
printf("The character %c is at position: %d\n", c, ptr-string); . T. g, w7 x, B
else
* S3 ~. Q0 E2 t6 d6 H& A* \printf("The character was not found\n");
- S& h* a9 X- q: A( t1 Ureturn 0; + D8 M( {2 }3 b6 v. Y/ [& a
} </FONT>+ A3 b* B( J4 g! `4 s& i

! b; W1 e9 M2 D1 ~9 i
. U2 b, [( j. M+ Y</P>
# u( O+ U% V" z, O) v<P><FONT color=#ff0000>函数名: strrev </FONT>
. H; W  `* j( n: F0 n功 能: 串倒转 ! G" s: Q  F2 a6 E. Z9 S3 G
用 法: char *strrev(char *str);   u% X" e4 m" k3 X+ X
程序例: </P>' w! K; |! b& G0 ^! |2 o5 N" v/ y
<P><FONT color=#0000ff>#include <STRING.H>' k, s  g) J* X7 \* }2 V& E7 R1 r
#include <STDIO.H></FONT></P>% J& F; ^' {& ~$ d( U+ z5 C
<P><FONT color=#0000ff>int main(void) $ A, d3 n" }" E
{ 8 w( x/ ]( p4 R
char *forward = "string"; </FONT></P>
; D# N3 O/ Z" x. `% ^# T<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward); ) M" L7 Z6 Q3 Y# C: N
strrev(forward);   u5 y1 C1 p. R4 j' V& ~
printf("After strrev(): %s\n", forward); - U- m# f2 ]1 V, H! {$ C$ L
return 0; % o5 {6 v; ?6 I- n" b7 T$ d& {' R
} </FONT>& ~. U" {9 n% A1 H9 z4 r8 B
</P>9 a% e9 g% D+ U6 u# W& D8 H
<P><FONT color=#ff0000>函数名: strset </FONT>
/ O% z6 L4 N5 N/ e6 ]  P功 能: 将一个串中的所有字符都设为指定字符
, G- N2 `3 q1 b用 法: char *strset(char *str, char c); ( g* T6 X# W# }/ W) S
程序例: </P>4 ^/ j6 P- l6 R
<P><FONT color=#0000ff>#include <STDIO.H>/ X3 j% c; d% M4 [/ T0 L/ h
#include <STRING.H></FONT></P>
7 v- c0 |9 Q* c4 f5 ]0 [+ ]<P><FONT color=#0000ff>int main(void) 0 w* I+ Y& {) n/ x& A' j9 i) s+ V
{ ; d4 a3 ]' V5 f2 h$ b) k
char string[10] = "123456789";
9 {  U/ k. W; a8 ^char symbol = 'c'; </FONT></P>
0 {4 D& _! L& ?- A' p, w  ^; o# [3 Y; V<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
8 J3 Y4 |+ u0 {6 H+ Jstrset(string, symbol); 6 E! q+ J+ I- l" a8 e9 x8 K- B' k
printf("After strset(): %s\n", string);
7 [0 K% F3 V& q% creturn 0; 9 C; @( R; Y" t5 j. s( d
}
. @1 R' k  k% V0 Y$ a! S3 j* d( P4 K: J1 _0 ?8 R
</FONT>% I% y/ U5 W0 x. F- k2 D
</P>
$ Z7 C8 H# z  h$ D7 r+ h& Z<P><FONT color=#ff0000>函数名: strspn </FONT>
& W( g3 j7 m" i' g) K0 i' c, z  u: o功 能: 在串中查找指定字符集的子集的第一次出现
- `1 n6 h+ }$ E1 j  H; T用 法: int strspn(char *str1, char *str2);
" }1 \6 d+ C$ G  U6 w5 b程序例: </P>
) `* y- Z7 P$ h' j8 T# Q<P><FONT color=#0000ff>#include <STDIO.H>( y" I5 j5 W+ O
#include <STRING.H>
5 ^; H& ~/ ?/ K6 X7 Z* n  n$ d#include <ALLOC.H></FONT></P>
4 W; F$ ?$ ~2 Y2 l+ F<P><FONT color=#0000ff>int main(void)
7 [# H9 X' F- W: T, Q, s{
5 Z* G% J& J6 t  O( Vchar *string1 = "1234567890";   ^+ N3 w/ g; D7 ?6 ^1 |8 U
char *string2 = "123DC8"; , v* @6 _# K( {7 I& I" E
int length; </FONT></P>$ l8 \" P( [' q+ T( k& N+ n& _' g: g
<P><FONT color=#0000ff>length = strspn(string1, string2); 2 a5 }0 N4 U" M
printf("Character where strings differ is at position %d\n", length); 7 @: t' i( D7 b5 {8 J5 R1 j8 c
return 0;
- I8 B7 U8 C# C4 K( p8 N+ X}
$ H5 r7 o( Q' I2 i6 D2 M</FONT>' a* c% @* Y) U' e
</P>7 y5 ]( O" T0 I. J
<P><FONT color=#ff0000>函数名: strstr </FONT>
  ?! d3 z0 G7 H功 能: 在串中查找指定字符串的第一次出现 2 |6 e8 |1 Z3 O  D+ L
用 法: char *strstr(char *str1, char *str2);
0 d8 D) M! @0 I* O: c; Q程序例: </P>: n$ m& h# `8 Z8 i$ H
<P><FONT color=#0000ff>#include <STDIO.H>6 d! W+ [9 F1 d- d  t: G7 N9 [: d+ _& q( j
#include <STRING.H></FONT></P>: ?0 w8 R' S+ m7 s. I) T
<P><FONT color=#0000ff>int main(void) + Y0 ?2 r% u; c3 O6 \+ D9 c9 }, O
{
% v4 w) P9 m; Lchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>( v2 u! ~- a' S5 f( v: x
<P><FONT color=#0000ff>ptr = strstr(str1, str2);
4 r4 m5 V% N' G7 D+ Y, K  mprintf("The substring is: %s\n", ptr); - w; m- n! M3 a$ V, F+ v: x1 d* B
return 0;
/ f1 n4 m7 A: S$ X* K. x} </FONT>
! ^, ~. u+ ~! g( O9 H4 {# M. X  c# F- m' I" O
</P>
8 c  a% U# R" B6 A1 a/ B6 G<P><FONT color=#ff0000>函数名: strtod </FONT>" ~( v( U* n% t% v
功 能: 将字符串转换为double型值
0 T1 N7 g! s' x% v& L用 法: double strtod(char *str, char **endptr); # B3 j  X/ p/ h$ G& I/ ~
程序例: </P>
' E, ~* q" E6 J1 `<P><FONT color=#0000ff>#include <STDIO.H>
" z% |2 a( {' N+ Z. z2 {, ]#include <STDLIB.H></FONT></P>4 i! w2 e5 W! w
<P><FONT color=#0000ff>int main(void) : g& N4 j/ \, Z9 a& n2 E& \' K
{ & k4 ]3 g: O$ i9 C8 Q
char input[80], *endptr;
( ^% r% Q& q# o; m# z. J% l  f, Tdouble value; </FONT></P>
" @2 Q* A& \% C* u4 C<P><FONT color=#0000ff>printf("Enter a floating point number:");
  a" L5 ^: g2 tgets(input); 9 G! g  ~# \9 ]4 M$ @
value = strtod(input, &amp;endptr); * C# \9 V% K  Q9 g; k  \  v
printf("The string is %s the number is %lf\n", input, value); / e2 O) W6 c- A( t7 L  S/ S: U" T7 }4 @
return 0;
- r. S6 P, e0 p$ B0 o9 O}
5 f. g. }5 R8 ]</FONT>. l+ h5 \  [/ u* G- Z/ P

: V/ w! v: u! L. i</P>$ h4 b  Z( _# {( ?- e! n3 ]
<P><FONT color=#ff0000>函数名: strtok </FONT>) \. o* Y; j* X, P) |8 Y
功 能: 查找由在第二个串中指定的分界符分隔开的单词
- v1 A) Y; v3 Z+ _' z: O' ]" j: A用 法: char *strtok(char *str1, char *str2);
8 ?& h2 _# G+ t) s1 `3 t程序例: </P>
4 u1 c* T# T! \/ \/ S2 Y<P><FONT color=#0000ff>#include <STRING.H>
9 U* E1 H* H- R9 C9 s#include <STDIO.H></FONT></P>7 g. `3 Q" h1 F# a5 q6 l2 C& s
<P><FONT color=#0000ff>int main(void)
3 S( P9 ~+ a' t, E% q{ & ^9 y! R& r% @: ~3 U4 F
char input[16] = "abc,d"; , R, H+ S+ L9 P; ^; M/ f$ `# L8 i
char *p; </FONT></P>$ z8 z9 D& Y) C! u* O5 y  m  i5 u, z
<P><FONT color=#0000ff>/* strtok places a NULL terminator
% v% T# ]* z" ]) hin front of the token, if found */
' b2 ~) F( D- Z: Wp = strtok(input, ",");
( g% A* w$ V; O1 oif (p) printf("%s\n", p); </FONT></P>+ Q% v- }) B/ b) J( b+ {
<P><FONT color=#0000ff>/* A second call to strtok using a NULL / ~5 q* u7 S( }9 D: `* R
as the first parameter returns a pointer $ @$ S) h# M  X& K4 C7 c+ J# b
to the character following the token */ ) _* T7 Q/ E1 y; g. ~3 T5 o( ]$ A1 _
p = strtok(NULL, ",");
( Q; q( i, {+ D9 Tif (p) printf("%s\n", p); ( Y5 ~' ?1 s" w1 B
return 0; $ {  a  R; T8 K2 o
}
4 O  g0 l$ I$ F' N' c( f4 E) u5 R; `* x8 Z$ z' A/ \* _; f
$ p6 m4 }8 L  i  e) p( x4 W$ ^
</FONT></P>
" Y* M+ T3 [+ c0 T- H) F8 w5 M" m6 }<P><FONT color=#ff0000>函数名: strtol </FONT>
! w  l* |3 l# |0 D$ x* h% N3 H% U功 能: 将串转换为长整数 1 f0 s. Q/ A4 m
用 法: long strtol(char *str, char **endptr, int base); 6 U  Q% V6 K; q) F2 z5 {0 U7 M
程序例: </P># @( i9 @/ D# r( H! a( H
<P><FONT color=#0000ff>#include <STDLIB.H>8 I: w, J% V* h- {9 q  y9 L
#include <STDIO.H></FONT></P>
& r% T" P! C7 r; o, ]3 q6 M<P><FONT color=#0000ff>int main(void) 2 k9 s2 j3 p  |
{
" w; V( b: d1 A1 s! I6 I8 Qchar *string = "87654321", *endptr; . N$ Z6 ]- c* U% s) t$ y( I  t
long lnumber; </FONT></P>
% z0 E: H( j& C7 b8 W<P><FONT color=#0000ff>/* strtol converts string to long integer */
5 S% Z9 R. @8 {" g) flnumber = strtol(string, &amp;endptr, 10);
+ J: h* k. N5 r# ^5 ^6 ^printf("string = %s long = %ld\n", string, lnumber); </FONT></P>) n6 Z# t$ n& m- ^2 ]4 z- ~
<P><FONT color=#0000ff>return 0;
4 {: u, _" |. i) B- J. [" M} </FONT>! k' R6 C+ |, j$ R6 Z- S
</P>% p4 {& \* U" P; \5 K
<P><FONT color=#ff0000>函数名: strupr </FONT>
9 S2 U; v/ i' G5 p功 能: 将串中的小写字母转换为大写字母 7 @& z1 `0 \: T: Y6 r0 a- S: ~
用 法: char *strupr(char *str);
+ p/ J  h$ d' X# e- R' k0 H4 Y* m; \程序例: </P>
* q7 |$ r# N3 O' `- _) V<P><FONT color=#0000ff>#include <STDIO.H>, B$ n7 {. |2 B) a* c  O. Y8 `! L
#include <STRING.H></FONT></P>0 m2 c- A9 N6 e" n
<P><FONT color=#0000ff>int main(void)
6 o% i- I  q! q- S: V( M{
/ n0 Q; {( `3 q3 s7 ~- y7 qchar *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
  A/ P4 o9 O3 v# c5 n<P><FONT color=#0000ff>/* converts string to upper case characters */
) A$ [; `+ B, h5 x2 i; y- D) S$ jptr = strupr(string); 6 @$ P9 C3 n  `5 m! z6 }% ]. F4 M4 [
printf("%s\n", ptr); $ V. H/ P2 A% E; ?9 U: ]
return 0; ( }9 P% D7 O& S: C8 u( h; c# w
} 5 \9 ?; o; v5 O

' B, H% K. r" a8 k  H. O2 F</FONT>
4 I, w7 s/ x* ~$ f8 \0 X- d5 ^* Q</P>
* e) n9 l, l- Q$ p<P><FONT color=#ff0000>函数名: swab </FONT>- a/ y: G( q+ d! d8 r: }
功 能: 交换字节
8 T* D# L1 ?+ L4 F. B用 法: void swab (char *from, char *to, int nbytes); & e" |' r$ V; w9 p& B
程序例: </P># }+ F7 g  D! g+ I
<P><FONT color=#0000ff>#include <STDLIB.H>/ y2 q2 J% i8 d3 j/ B0 B, |
#include <STDIO.H>
) K  @; p% b2 I* X6 R2 ]#include <STRING.H></FONT></P>' D/ j( I. n: U5 s+ E& i; ~
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
- h: \6 J0 s0 F  v  j+ Nchar target[15]; </FONT></P>& C/ ]0 p/ x1 ~7 R' W
<P><FONT color=#0000ff>int main(void)
% k" F: r9 v  {( m" ^& O# a{
# q9 Q5 [( j# J" J- sswab(source, target, strlen(source));
9 q! e# x- g2 v; sprintf("This is target: %s\n", target); 9 P/ {  T3 R$ e  I, W
return 0; 0 `# h% q" s$ \1 s. C) v  V- u
}
- d. t& _( I, S* c$ x3 D3 \: M</FONT>% [% u( h+ p5 c! j7 _% P: e
; G9 p1 b- D/ I7 t2 o4 ?" E) }
</P>4 v1 D) X9 e0 i, n- B) w' A
<P><FONT color=#ff0000>函数名: system </FONT>
; Z$ f* a) W+ m功 能: 发出一个DOS命令
! ]# m  v: o" \/ L1 y/ P. ^- s3 Y! B用 法: int system(char *command); : H$ T* b5 M& G. H: s8 l( v
程序例: </P>
# y" O2 [5 U( @3 _4 \<P><FONT color=#0000ff>#include <STDLIB.H>% c4 b4 n  w6 w  G& p
#include <STDIO.H></FONT></P>! d$ {$ ~+ Y$ I2 r' J* F
<P><FONT color=#0000ff>int main(void)
* N  v. D7 ?5 Q5 ]1 V( Z" J, j{ 3 q8 q7 ^4 w7 N
printf("About to spawn command.com and run a DOS command\n");
% \" \# B6 J! j& B, Msystem("dir"); # Q1 K7 H, T( X' a
return 0;
. m" ?* a4 h& O; T* ?} </FONT></P>




欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5