QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>% d; k- ]4 Y5 M- _$ ~; _  |
功 能: 改变数据段空间位置
/ M0 k& X/ U+ B4 Z6 X- f. p用 法: char *sbrk(int incr); 2 _' U, E6 ^0 F- |! `* ^
程序例: </P>
  F3 W# b- D4 \1 N7 m# o, `<><FONT color=#0000ff>#include <STDIO.H>
* q, H1 v; P% ~* S4 b7 A2 h( j  m  P#include <ALLOC.H></FONT></P>
. [* f' g/ ^9 ~; [<><FONT color=#0000ff>int main(void)
. K8 z9 x3 r+ h( ]2 P6 z{
/ j8 z, L7 ?6 l' bprintf("Changing allocation with sbrk()\n");
) Y6 v3 |4 F- {- _, `" a; Pprintf("Before sbrk() call: %lu bytes free\n",
9 ~* x/ J9 D( S( p' K(unsigned long) coreleft());
6 Y: S3 b- \1 n+ y' u9 dsbrk(1000); 3 u! c# _% ?. A* M' @- Y3 w6 M
printf(" After sbrk() call: %lu bytes free\n", 2 D5 I6 G% z' S& `6 e: H
(unsigned long) coreleft());
! R" k6 m$ J. rreturn 0; " j. L- n9 M, j4 c% _& {
} & n2 G, c- o; i% [4 D  u, c
4 q0 B( [1 a. D* G# X& V- j
</FONT></P>6 y& i' L8 c% ~  P: S
<><FONT color=#ff0000>函数名: scanf </FONT>5 v- T: [1 e- Y$ y
功 能: 执行格式化输入
; n1 M+ l: n( t, F用 法: int scanf(char *format[,argument,...]);
/ u6 G# ~, c# G8 T2 D程序例: </P>* ]. L, c! B/ Z+ g
<><FONT color=#0000ff>#include <STDIO.H>
6 d* ?) j5 }' p) j( `& X#include <CONIO.H></FONT></P>
3 J3 Q& o) ~2 R/ Q4 [( ^( w<><FONT color=#0000ff>int main(void)
* E# }3 G' }- ~{
5 [9 k0 s6 V3 A/ Z; D6 ^7 uchar label[20]; % c. J$ q3 x) B% }
char name[20];
5 b) @4 K+ u9 K0 u5 o* L! vint entries = 0; 0 @* q% k% P$ G% D& V( }1 E
int loop, age;
9 m6 |3 ]0 a& edouble salary; </FONT></P>
- z; f7 {" B0 O4 H4 `<><FONT color=#0000ff>struct Entry_struct
$ f& h2 U7 ]7 ^) K+ f6 E{
# P0 z' t* _. C% Ychar name[20]; ; l1 u0 I4 T0 x% b
int age;
1 Y* g: Z* k$ Z8 O3 pfloat salary; 7 y/ }" Q" G0 c1 y! Y
} entry[20]; </FONT></P>
8 O: j1 c+ q3 T& ~7 f<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ / n9 x/ W- r* u9 S9 h
printf("\n\nPlease enter a label for the chart: "); : e7 p; N6 M$ j7 g/ W9 e7 c
scanf("%20s", label);
) U8 y  E8 D, l5 [fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
4 e3 e% n- d+ Y2 T6 B; Q% Z  g<><FONT color=#0000ff>/* Input number of entries as an integer */
1 W5 i5 Y8 A& T8 i# ]# a+ h6 _3 z7 Gprintf("How many entries will there be? (less than 20) "); $ x: E. \) Z! J
scanf("%d", &amp;entries);
6 s) K0 a/ c1 Offlush(stdin); /* flush the input stream in case of bad input */ </FONT></P>3 S% u& H; ~3 v! x0 O; C
<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
' f% J% e4 t6 k5 N. bfor (loop=0;loop<ENTRIES;++LOOP) ) s9 t& O* k/ m4 I, _  }
{
. j% \2 U# `$ s( J; ^5 Wprintf("Entry %d\n", loop); 3 e" G% H% x/ a6 I0 r% j" K
printf(" Name : ");
# [7 k) u! i% t% G4 ?  Fscanf("%[A-Za-z]", entry[loop].name); 2 ^  w$ |% U8 S9 e3 u
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
4 ~6 s1 x8 z+ \4 i) P, Z, u0 a<><FONT color=#0000ff>/* input an age as an integer */ 6 s5 J8 M7 z0 L+ Y% I
printf(" Age : ");
( v, ~: d. I; ^7 X7 o2 `scanf("%d", &amp;entry[loop].age);
) K/ w& _8 N% }9 Y8 t# y: Ufflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
5 v9 ]' g0 r: b, a/ x/ ^' P) p<><FONT color=#0000ff>/* input a salary as a float */ ; h' s' i4 S. F3 h/ Y8 x0 w
printf(" Salary : "); ( h- m+ r; L2 E
scanf("%f", &amp;entry[loop].salary);
5 |3 r9 Y+ d) \6 t; tfflush(stdin); /* flush the input stream in case of bad input */
- L0 O8 A0 I+ Y0 p} </FONT></P>
- m6 X* ~: H6 J/ n<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
/ W: H6 v$ }5 P# a5 ]4 |! z5 `printf("\nPlease enter your name, age and salary\n"); + b) J( Y, N6 R! d9 E& ^" i! X
scanf("%20s %d %lf", name, &amp;age, &amp;salary);
: l3 U! b$ |+ o</FONT></P>
' d. B+ D! O! k5 M  {+ l5 E<><FONT color=#0000ff>/* Print out the data that was input */
/ B& T: {' o7 Q4 ]5 Iprintf("\n\nTable %s\n",label); ( }* }+ J4 n2 N) p" ]2 F* z
printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);   B3 w, J& V$ q3 U
printf("-----------------------------------------------------\n");
" J* L9 D2 h, T" pfor (loop=0;loop<ENTRIES;++LOOP)
1 x4 k: B" z. ^" e+ ~( G printf("%4d | %-20s | %5d | %15.2lf\n", 5 v* @; _: N! I7 n2 F
loop + 1, : `3 t$ n* Y! R; e$ f
entry[loop].name,
, ?. y+ T$ X2 aentry[loop].age, 4 t+ X+ H5 l) R2 e# _  P# a
entry[loop].salary);
; O6 ?, p9 k1 ~" T! ^" N& @  Eprintf("-----------------------------------------------------\n");
3 m, z; z4 p+ ~; l' Kreturn 0; + I1 H8 z: V. o) `' m, W+ c% g7 \
} . H% b1 S3 l% M# X" Q
</FONT>0 t9 D/ q1 J& f7 [) S1 [
</P>$ J  _* e3 H( L
<><FONT color=#ff0000>函数名: searchpath </FONT>
6 A) r( l# H' a功 能: 搜索DOS路径 6 q2 U% Q. x- ?& J! b% @
用 法: char *searchpath(char *filename);   T+ p; A$ ?; {7 {
程序例: </P>$ i/ }, _% R- t, l. j8 ]' C
<><FONT color=#0000ff>#include <STDIO.H>! @2 m7 s1 }: z' ]# o$ K! I
#include <DIR.H></FONT></P>
) r: t! ]6 y5 X) c' D  M: D) Y5 Q0 A<><FONT color=#0000ff>int main(void)
. n5 A. B1 K% {- Z{
2 n2 u) |9 V' j1 N, y: W& d: T! ochar *p; </FONT></P># Q  G' S' {. e! y
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer 2 {* _, N; P% t- m6 c
to the path */   O4 I  a! O2 {! t  U: U$ w  E
p = searchpath("TLINK.EXE"); 4 G; M4 U+ {- ~
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>% c: o7 X, G2 L( [0 b
<><FONT color=#0000ff>/* Looks for non-existent file */
0 w4 l- \3 \; wp = searchpath("NOTEXIST.FIL");
3 `( C+ t! A# y( s7 Gprintf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>
  M; F- Y% U) a<><FONT color=#0000ff>return 0;   _7 F" C! A) U, M/ Y" H8 F
}   o. |& x( i0 {9 m) F* [8 [

( N  X6 f+ }" J  v' c  l! K- \" X</FONT></P>
& F* b5 T4 f2 j6 _! Z) V7 p<><FONT color=#ff0000>函数名: sector </FONT>
1 t0 y( U* U5 _7 o% A8 {功 能: 画并填充椭圆扇区
% u7 z, L$ S' P# j( @9 u9 w% n) A用 法: void far sector(int x, int y, int stangle, int endangle); - T2 {" I, p5 B& h" [( \: W3 G
程序例: </P>  c" M3 @. ?) X# H8 {7 ?( }5 y' u
<><FONT color=#0000ff>#include <GRAPHICS.H>7 _9 O3 D% n, k% L+ E
#include <STDLIB.H>
- r2 b, R8 `' z#include <STDIO.H>
  o! D, [/ {* n% R/ U#include <CONIO.H></FONT></P>
) z5 n( M! V% p<><FONT color=#0000ff>int main(void)
# {& m  |! b. w# \{ & ]( g; }  R; R# I7 a
/* request auto detection */
/ B' f2 r# v  j# ^9 n5 sint gdriver = DETECT, gmode, errorcode;
2 q1 r" W! g8 y3 jint midx, midy, i; % F4 |# i' l9 d$ V$ _
int stangle = 45, endangle = 135; , F$ \; R0 t, T- a) I
int xrad = 100, yrad = 50; </FONT></P>) z/ K+ s% g( H5 j5 J
<><FONT color=#0000ff>/* initialize graphics and local variables */
3 m* [6 }1 g9 I! a) F! v0 ]initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>, |0 K7 }1 g' n8 t
<><FONT color=#0000ff>/* read result of initialization */
' z1 Y9 N* G. n$ n9 D5 W  `errorcode = graphresult();
% ~0 k2 Z6 ~6 ]& E# s2 \if (errorcode != grOk) /* an error occurred */
/ j9 F* d  z2 R{
( I0 K+ [% y  |6 b" Lprintf("Graphics error: %s\n", grapherrormsg(errorcode));
$ |" K$ |  f. A; n4 V! ~" T# m4 B1 dprintf("ress any key to halt:");
& D/ z9 k/ P  Lgetch(); " e- C7 U7 B% q% O- ~
exit(1); /* terminate with an error code */ ! h  p7 z$ ]/ L
} </FONT></P>
' S/ h$ a, x9 ^( i1 v<><FONT color=#0000ff>midx = getmaxx() / 2;
5 d7 f6 K' C$ h  ymidy = getmaxy() / 2; </FONT></P>
: ^  S- O: l: L  f# ?( H* d<><FONT color=#0000ff>/* loop through the fill patterns */
6 Q; z1 P/ V" P; c/ P! G3 u, }8 Xfor (i=EMPTY_FILL; i<USER_FILL; <br i++)> { ' ^, o( Q" s) U
/* set the fill style */ / i% B$ k! p. T" ]7 N0 z
setfillstyle(i, getmaxcolor()); </FONT></P>
' ~4 L6 B: ]- l; W- \; W) s<><FONT color=#0000ff>/* draw the sector slice */
3 s8 e+ E( f* Tsector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>6 [; i5 }% e! _
<><FONT color=#0000ff>getch();
! n/ i9 e! c7 r" J9 Q} </FONT></P>: Q5 K6 N. [" T6 y* ]
<P><FONT color=#0000ff>/* clean up */
7 H; h; M! k( Y% J% A5 rclosegraph(); $ `% ~+ F2 O: Y% l& S. f
return 0;
# z1 r! u. X4 }! W}
( }+ O+ C) {+ p" ?# `5 Y8 x4 R</FONT></P>4 Q! |* o' y5 ?* G: b7 C7 v& K
<P><FONT color=#ff0000>函数名: segread </FONT>
7 l0 l  B" h- Y! V功 能: 读段寄存器值
" k% Y6 T+ y  N7 j6 R用 法: void segread(struct SREGS *segtbl); ; u  O8 y* B4 f- m  g
程序例: </P>, R0 O% \' t' W6 U5 a9 e% M( ]1 p: t/ i
<P><FONT color=#0000ff>#include <STDIO.H>1 }& |' k/ z6 f1 U+ a" P3 \
#include <DOS.H></FONT></P>
- m* G( E; ?) i& C, A$ N$ u<P><FONT color=#0000ff>int main(void) * ]2 H& t! }! d& C& l+ k
{
$ x- b9 f2 d6 m( M# f- Ostruct SREGS segs; </FONT></P>
7 l' e+ q: u, y0 C<P><FONT color=#0000ff>segread(&amp;segs);
3 f- ]" k- J8 q3 G! U( _! Uprintf("Current segment register settings\n\n");   b1 B6 Q" K+ \% }0 C
printf("CS: %X DS: %X\n", segs.cs, segs.ds);
5 i3 Y* w3 N! [" i1 ?printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>4 P2 c& j) v0 e7 F( ~7 I
<P><FONT color=#0000ff>return 0; ! I3 G" U7 Y% C* \+ E
} </FONT>
' T0 l) u8 `6 G! Y
/ Y% p+ E5 |! ]4 k</P>
+ Z) R3 A+ r8 L5 l8 l, t<P><FONT color=#ff0000>函数名: setactivepage </FONT>: N- L" C8 H5 Y3 x  F
功 能: 设置图形输出活动页
! u3 l: A+ @9 {9 v) B# H7 k* C3 O用 法: void far setactivepage(int pagenum); ; |2 w- b# ~8 E1 o9 k! `% c
程序例: </P>/ w# d& N* d0 B4 x+ |! L5 W
<P><FONT color=#0000ff>#include <GRAPHICS.H>( [; @/ b6 c' @+ y& _% @! Z( A3 q
#include <STDLIB.H>. `4 M7 e9 F4 D
#include <STDIO.H>
% J6 t' C; b. v" U( ^#include <CONIO.H></FONT></P># n& g+ Z- `$ I) I- G+ ?
<P><FONT color=#0000ff>int main(void)
3 t& a" ?* W. p3 N  w) F{
) n  f' m+ `; T/ o2 H4 [/* select a driver and mode that supports */ ; d( j1 q3 `0 M5 M5 F- @# _
/* multiple pages. */
4 g7 a2 |' [  f( C7 hint gdriver = EGA, gmode = EGAHI, errorcode;
) H$ u; n4 u% C+ {5 cint x, y, ht; </FONT></P>
3 e4 R7 F* D- l# h! {<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 q6 L+ Z* V* n) F" d  _( X
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 L, K' z# D+ S( K4 J7 ]' y<P><FONT color=#0000ff>/* read result of initialization */ + o7 N9 k2 `& ^' l! d
errorcode = graphresult(); 4 N  m3 V8 _* K
if (errorcode != grOk) /* an error occurred */
# W& k# A' U- ^8 j{
7 \# f' A6 o; w( c& s1 `% tprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 A! |( L/ d7 b
printf("Press any key to halt:"); : ]+ Y/ V1 e5 R6 s
getch(); , _6 ^( i! w( U. K2 i8 |. C7 J3 T
exit(1); /* terminate with an error code */ 0 Y! ?* J7 r* i  o; K
} </FONT></P>, N# R6 T/ w( N+ M0 f1 q: Z
<P><FONT color=#0000ff>x = getmaxx() / 2;
' I1 ?( o4 x6 x' hy = getmaxy() / 2;
4 O, _) ?1 p4 o0 Y0 G# Pht = textheight("W"); </FONT></P>1 Y$ Z, C0 R; {4 F% K
<P><FONT color=#0000ff>/* select the off screen page for drawing */
& Y. b6 n' y! p( z4 A8 {setactivepage(1); </FONT></P>( f. Q( S1 k/ N$ [
<P><FONT color=#0000ff>/* draw a line on page #1 */
* a" b& V4 P! s; r3 u' ^7 Rline(0, 0, getmaxx(), getmaxy()); </FONT></P>2 z! b$ C+ v  Z5 B7 z0 z
<P><FONT color=#0000ff>/* output a message on page #1 */
$ D8 z* I  [$ F$ E) x$ \; ssettextjustify(CENTER_TEXT, CENTER_TEXT); . K- P" H3 [( @: o" S" Z% v0 n
outtextxy(x, y, "This is page #1:");
5 z/ o# o8 ^0 i& v! \2 k- Couttextxy(x, y+ht, "Press any key to halt:"); </FONT></P>% n- C0 P9 e4 t
<P><FONT color=#0000ff>/* select drawing to page #0 */
8 j1 j; R$ E! i: k% U0 o) i( Hsetactivepage(0); </FONT></P>( T! k; E" S" Q2 Y( W- ]
<P><FONT color=#0000ff>/* output a message on page #0 */
# v$ N  j% f# f; }7 R/ ~outtextxy(x, y, "This is page #0."); ! }. g! F6 R5 _- j$ q) k% t
outtextxy(x, y+ht, "Press any key to view page #1:"); ) S  D) l- k; o3 G: c3 a
getch(); </FONT></P>
1 t- u: R' [$ O<P><FONT color=#0000ff>/* select page #1 as the visible page */ % ]3 M5 {! x- C% G( X9 s! n& A6 m2 e
setvisualpage(1); </FONT></P>
- X, b+ q) P! @! O' |<P><FONT color=#0000ff>/* clean up */ 9 a2 x: R% M1 j# O. E1 ]/ U" A
getch(); % h7 a0 g# r$ B# s, n1 n1 t
closegraph(); % J' \0 S9 n# S! s* v' j
return 0; 1 ]5 [) Q6 I0 f, o2 ^
}
- X; L) Z; c5 G) b  T: c4 Y, Y& h</FONT>
, [; c0 T* }  [3 ?( ]$ j</P>9 I; S6 S5 p& j
<P><FONT color=#ff0000>函数名: setallpallette </FONT>
3 r; d; C2 {, g$ }5 e3 y: {" m功 能: 按指定方式改变所有的调色板颜色
/ q9 j0 V& P- T* i5 S4 F1 {用 法: void far setallpallette(struct palette, far *pallette);
/ w. l% D( ~( a$ g7 i) E  J程序例: </P>
, R8 ?4 T4 o% _<P><FONT color=#0000ff>#include <GRAPHICS.H>
/ k8 A8 p4 _1 ^, _#include <STDLIB.H>
. f; e# v* }  }0 |( T+ j! A: x5 p#include <STDIO.H>5 q% S3 i  n: T
#include <CONIO.H></FONT></P>
7 C9 t4 ]: z6 Q( s5 c; k<P><FONT color=#0000ff>int main(void)
! x0 m  Z2 J% O+ h- u$ Y* M+ U0 k: g{ % r9 h$ v) J  j- R0 g. C
/* request auto detection */ * v2 L8 j# Y  w1 K  T0 S4 T& K
int gdriver = DETECT, gmode, errorcode;
$ x: T: r( K2 E; Q1 F/ u4 H1 {# vstruct palettetype pal; $ f) g) H% a) i" U& e9 m1 {
int color, maxcolor, ht;
7 p" ]* \% N: r8 R1 \* t5 Mint y = 10; : L) B) x4 I' i
char msg[80]; </FONT></P>! T" l# \; }& Z. N1 V
<P><FONT color=#0000ff>/* initialize graphics and local variables */
  g3 Q5 Y6 \& {initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 E6 B* H# y) j+ z+ K/ |# c3 }
<P><FONT color=#0000ff>/* read result of initialization */ & l6 N! a% a9 ?  C
errorcode = graphresult();
7 x1 D0 C. F1 Q, ]if (errorcode != grOk) /* an error occurred */
; w& N, k+ i9 C3 W6 n  ~  m& u# }2 l{
) |# \  q! i7 x) {% f/ e* ~printf("Graphics error: %s\n", grapherrormsg(errorcode));
' K* b5 Y" g' X; R  X! Qprintf("Press any key to halt:"); & ~0 t# _  l1 Z$ _) O
getch();
) f% b/ m% H& i0 L- Texit(1); /* terminate with an error code */ 4 I% _& Q  ?8 m
} </FONT></P>, l) M6 z9 a- q, X; c; A. Z
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
; I) g% t: d( Lht = 2 * textheight("W"); </FONT></P>
1 T" N. z' I! M) f+ }<P><FONT color=#0000ff>/* grab a copy of the palette */ 4 S4 X! }# p7 N
getpalette(&amp;pal); </FONT></P>
' `! X- b) J' g2 O9 N! c) D<P><FONT color=#0000ff>/* display the default palette colors */ ( {0 E* {5 A5 Z( A
for (color=1; color&lt;=maxcolor; color++)
6 F' c3 s$ r; h/ I# s. a. }2 e3 \{ 7 \, j6 V& C. v$ Q" h
setcolor(color);
$ a2 w, y& r  J" ^# H* ?sprintf(msg, "Color: %d", color);
' T% \. S. ?7 R. Mouttextxy(1, y, msg); " y( j0 k+ s/ K0 {* I( I- ?
y += ht; 4 y" ~! W! x( P' n
} </FONT></P>
# \5 A% b5 S: q% v<P><FONT color=#0000ff>/* wait for a key */ 4 i/ {# n) _( R3 a9 O# J
getch(); </FONT></P>, R. u4 x0 u3 H! m; j
<P><FONT color=#0000ff>/* black out the colors one by one */
& Q1 T% U% x% f3 Dfor (color=1; color&lt;=maxcolor; color++) 4 ?& v+ Q* t/ ]3 ?, S% f3 u
{
$ i4 j$ Q9 I$ h2 W  l3 x1 ^7 |setpalette(color, BLACK);
% N, q0 G# v% T) v5 rgetch();
% C: ~2 @/ N- h" D0 e" i7 A4 ^} </FONT></P>& R! ]# ]1 H- _! {4 s7 m
<P><FONT color=#0000ff>/* restore the palette colors */
5 d7 d. |+ v+ Lsetallpalette(&amp;pal); </FONT></P>
4 O* x) L3 q4 R& J<P><FONT color=#0000ff>/* clean up */
/ Y9 o9 E3 I5 R) Z) D* D2 y. Mgetch(); 7 C9 R5 s/ u) c/ _1 K& S5 T9 P  |
closegraph();
; {1 n2 d$ O: T5 O" i- U% j: Z+ treturn 0;
/ L) v6 l) N0 \- E7 K4 l1 t6 P} ; k- U# ]& Y; [. |4 v& i$ [, s

. l% m. o8 f: l) {! e</FONT></P>6 _# O) |3 U7 g8 f2 z& J
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
# G. ~' ]' M2 |0 U: p功 能: 设置图形纵横比
( d* O& x# ^; p9 K用 法: void far setaspectratio(int xasp, int yasp); , F5 u7 R) o' V  i- }, D
程序例: </P>
# ?9 a% p: l3 v7 m/ A<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 a# [, x1 r- j! W  D#include <STDLIB.H>
7 W! O+ l9 s( K) q* a#include <STDIO.H>
) z) J5 g! D& j4 l4 ^6 }#include <CONIO.H></FONT></P>1 z  Y9 `; a% w  x, R, E7 e
<P><FONT color=#0000ff>int main(void)
3 e) W6 a, w. F+ @{
1 e3 T" T$ y2 N$ I0 d# o/* request auto detection */
0 G( b' |6 m1 J! i. x4 x, `int gdriver = DETECT, gmode, errorcode;
( Y9 X' ]$ ?( i5 Sint xasp, yasp, midx, midy; </FONT></P># \: t5 J8 ^/ R% X5 \
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' H/ d& [# E4 B& D. Oinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>: e& W, m  M3 w+ `& N; J- H& b
<P><FONT color=#0000ff>/* read result of initialization */
+ o0 H# q; b, q* p2 _. y! verrorcode = graphresult(); / R6 l% `5 e! e$ O* V5 D
if (errorcode != grOk) /* an error occurred */
( m) w1 F8 S% `# s2 I- }{ ' V4 h( J5 C9 L: z, p7 @1 w& u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); % l1 [( }( h9 G% |8 M) H
printf("Press any key to halt:"); 0 Q! Y+ F# t0 [" g
getch(); % p5 s* e* v- b: N( L
exit(1); /* terminate with an error code */ 9 l# R" d. L# S1 x8 T! P1 Q" B. l
} </FONT></P>" W+ ?' @2 P7 ]/ Y" \
<P><FONT color=#0000ff>midx = getmaxx() / 2;
1 G3 L% z' A$ [4 Q; Y4 T/ Y, Smidy = getmaxy() / 2; * G5 }8 a7 o( T5 v$ }# l6 |
setcolor(getmaxcolor()); </FONT></P>
% Y1 S; x( U( ~7 H<P><FONT color=#0000ff>/* get current aspect ratio settings */
$ A3 z/ f- A* D$ @8 Ggetaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
( j, B* }& z- J* o3 g! d$ w: ^<P><FONT color=#0000ff>/* draw normal circle */ ' t6 o( E8 L" P# p1 N) l
circle(midx, midy, 100);
( |1 T% M, k+ V  p8 I, pgetch(); </FONT></P>
. a9 Y6 ?* n$ a# I- M% [' h( R<P><FONT color=#0000ff>/* claer the screen */ 3 [* ?! ?9 X2 _/ A# ~- u
cleardevice(); </FONT></P>
( P) S; h5 |, r& t8 G1 f<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */
# P1 E- m( B1 ?: \: l) y8 s6 P5 usetaspectratio(xasp/2, yasp);
) d5 l  z6 l1 P, gcircle(midx, midy, 100); : p$ R3 h2 J5 F4 N$ k, \# e
getch(); </FONT></P>% X$ ?: ]: M( d* n3 D# w7 [
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ ' X% Z0 S, ~* m+ E' B* j4 m
cleardevice();
: p  t( @2 A) ?9 O8 G/ E$ D& b5 Lsetaspectratio(xasp, yasp/2);
  Q' G# w( _$ M" y" \circle(midx, midy, 100); </FONT></P>; g% q0 p/ ]9 x) h
<P><FONT color=#0000ff>/* clean up */
2 T5 Q- v+ F. i0 qgetch(); 3 O+ |) ]. I; K2 D3 M
closegraph(); ( |5 S6 K  p; {+ m  V
return 0; * a) @1 z; t6 F4 u
} 1 x. x: ]; z7 w
</FONT>6 D( t% W. x$ w: v
</P>! q" S, y: b/ A, t6 @
<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
$ k' Y/ Z# b* V* d功 能: 用调色板设置当前背景颜色 1 G- h1 n. t1 [1 r
用 法: void far setbkcolor(int color);
0 @  b, ^$ _. q+ q3 g! r: w程序例: </P>; ]' U% [$ p3 q8 u# r
<P><FONT color=#0000ff>#include <GRAPHICS.H>
$ j4 i) c2 |$ F7 J0 f#include <STDLIB.H>: H+ D  z( P; U' O/ g
#include <STDIO.H># b4 |6 `0 S7 _2 v3 h
#include <CONIO.H></FONT></P>
8 D# j4 ^! u( `7 X  q/ Y3 Q; P4 k<P><FONT color=#0000ff>int main(void)
0 l* i0 [) h; o2 Y- P# S{ : p' ]8 w3 h. K
/* select a driver and mode that supports */
' ^; C+ _2 ?/ y2 u, t! K+ h; F4 I/* multiple background colors. */
0 x7 Y$ u: i) M$ h: Vint gdriver = EGA, gmode = EGAHI, errorcode;
7 ?& |! r- O: h# e* T9 o' _int bkcol, maxcolor, x, y;
8 k$ ^0 {" W) w" f. qchar msg[80]; </FONT></P>
  F# ^" b7 p# w. b' W+ T<P><FONT color=#0000ff>/* initialize graphics and local variables */
. D% }7 N- u* s3 Ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 D1 ^% v: M, f+ V4 k+ Q& Z<P><FONT color=#0000ff>/* read result of initialization */ ' }: g3 f# [/ `: W+ s* u
errorcode = graphresult();
8 P+ }' C1 K/ |8 E! d: I! Cif (errorcode != grOk) /* an error occurred */ 8 _" l% N# e7 e: X) W6 J5 q
{
/ e1 D$ Q. m* i8 hprintf("Graphics error: %s\n", grapherrormsg(errorcode)); * K, }6 N. I0 T! [, C
printf("Press any key to halt:");
' R2 H9 f( m& P5 g5 ggetch();
! N5 E( B- Y# V  K! e4 l: Uexit(1); /* terminate with an error code */
" K* C. g# A& P1 ?} </FONT></P>
+ U, d: ?; N) j/ Y4 M. M; T<P><FONT color=#0000ff>/* maximum color index supported */
* d; N; y, M& Y+ S5 \maxcolor = getmaxcolor(); </FONT></P>1 L3 a  H7 N. V" e9 x0 m! @
<P><FONT color=#0000ff>/* for centering text messages */ 2 b* Q5 m0 y5 r, K) L
settextjustify(CENTER_TEXT, CENTER_TEXT); 1 A% n' m, @/ r! G( ~- Y
x = getmaxx() / 2; / f: Y3 a  Y5 Q, A
y = getmaxy() / 2; </FONT></P>; I( j9 U: p. m5 n3 C6 C& f
<P><FONT color=#0000ff>/* loop through the available colors */ 5 {- l$ z! u( ]! ^! I  m
for (bkcol=0; bkcol&lt;=maxcolor; bkcol++) " \0 r) k% z8 Z1 \
{
/ D' P' _% ^/ l/ x& P/* clear the screen */
0 ?# G* E+ y- Rcleardevice(); </FONT></P>6 F$ T9 h9 q9 s" K0 r, a! C
<P><FONT color=#0000ff>/* select a new background color */ 3 }/ D: H3 Z5 N: J
setbkcolor(bkcol); </FONT></P>
% g; T% M4 a7 m* s" R, \, ^8 D- [<P><FONT color=#0000ff>/* output a messsage */ + N1 Z1 G$ s6 j& ~9 T: B; c
if (bkcol == WHITE)
  G& L% D7 d0 psetcolor(EGA_BLUE); + `6 N6 R* W) W  s5 o1 L- F- ^2 S; c
sprintf(msg, "Background color: %d", bkcol);
" S* @* v6 \. r$ b, v4 h) a& A4 ^outtextxy(x, y, msg); ( C! T6 ^. G  M$ _% S
getch(); 0 t  c) A( q* T* V% U) B8 E' d, ]: T
} </FONT></P>
) L! A0 e2 q, M; N" T: P3 X<P><FONT color=#0000ff>/* clean up */ * b/ B/ c: E" ]
closegraph(); ; _4 r5 J! f7 k& R+ m2 [( ]
return 0;
, ]: j" M; r1 g1 X" C9 Y7 f} </FONT>, ~; s; `$ M  g0 C

5 Z# C) ]& r3 L0 u5 L</P>
2 M% `1 ?/ E# }$ ]. p4 P1 B<P><FONT color=#ff0000>函数名: setblock </FONT>2 V$ o! L+ d# g4 {9 O% W7 w
功 能: 修改先前已分配的DOS存储段大小
  x, Q) C+ C. K" P用 法: int setblock(int seg, int newsize);
6 _9 w! I( t1 |8 {8 \' g程序例: </P>
, S" s6 b1 S; f( m<P><FONT color=#0000ff>#include <DOS.H>
* ^5 I, w$ u8 t' E, Z2 G' V6 Z9 u& }#include <ALLOC.H>7 I2 p$ e0 J, s2 L3 }; ~
#include <STDIO.H>- Q3 D" |: H' d0 p& [
#include <STDLIB.H></FONT></P>/ ^/ J) w0 @: A2 |; s- E# |" i4 {
<P><FONT color=#0000ff>int main(void)
' \- T" i1 ~' A7 z  j; a{
8 Q0 q' k4 a" Y: Aunsigned int size, segp;
! B) t2 |( l4 _int stat; </FONT></P>' {; D8 V1 d  i
<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
) |3 A6 W& l% C$ V8 {stat = allocmem(size, &amp;segp);
, ^: }6 f  {9 tif (stat == -1) % `4 m, i. @8 f( N; f
printf("Allocated memory at segment: %X\n", segp);
; X% T- E& U4 ?' I% Selse
+ K% g% n; s* r$ _- L. M{
3 H& S5 j2 r, J$ h7 x" yprintf("Failed: maximum number of paragraphs available is %d\n",
5 d: A& N" q  I/ }2 v5 Lstat); % U5 I1 Z& J# u: r8 ~1 l" \
exit(1); . E( N; b* y' A  k9 v6 ?
} </FONT></P>
) X3 s6 |, o6 o( y<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
# J6 x; Z- D% C, t$ J. B: Cif (stat == -1)
9 W% e$ E+ N3 [5 A4 H" e& cprintf("Expanded memory block at segment: %X\n", segp); : S8 R" Q$ W. c3 O& V: X& W
else
7 d  U9 U4 _/ p. L# L' Eprintf("Failed: maximum number of paragraphs available is %d\n", 7 a" W; g) H) u- ?9 t/ j6 A
stat); </FONT></P>
- j/ q9 Z7 _' H9 J) `<P><FONT color=#0000ff>freemem(segp); </FONT></P>
0 u. a# V3 d* H- q1 e+ k! {& l<P><FONT color=#0000ff>return 0;
- _; m# Z# `/ W: w/ D: S8 _3 t5 L& j} & m5 `" d; ~! W( D3 L- f5 J. K
</FONT>+ G: F2 c3 M4 {1 e8 O# N
</P>/ R0 w, v, m$ k8 ~# w7 w
<P><FONT color=#ff0000>函数名: setbuf </FONT>
# C; R. ^/ U3 G+ Y# S8 y3 _) V3 s功 能: 把缓冲区与流相联 # H) b( k; r5 O, z
用 法: void setbuf(FILE *steam, char *buf);
- t% T1 p+ z& w2 y5 I4 N" b程序例: </P>
. E, K2 Y% ^, Z( h9 i<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>5 ~$ ?8 W# n' L4 {. v. e
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */
- j( i# T7 M0 x9 hchar outbuf[BUFSIZ]; </FONT></P>/ E. C5 M, P1 `" k/ Z6 c
<P><FONT color=#0000ff>int main(void)
2 g" U) R5 L& m{
7 ^1 s1 Q6 _& j# t/* attach a buffer to the standard output stream */
8 B4 N( T7 E( x# }setbuf(stdout, outbuf); </FONT></P>
* ]- m5 M; I. L9 I  [! t) h# L<P><FONT color=#0000ff>/* put some characters into the buffer */ ; d4 Q$ ~2 l) c0 I. ^3 v, X
puts("This is a test of buffered output.\n\n");
2 }7 y* _5 M2 E' A# g- d* K" cputs("This output will go into outbuf\n"); 0 x& b; a( N: {* l; Z
puts("and won't appear until the buffer\n"); ) Z7 T" h; C" p4 k, _
puts("fills up or we flush the stream.\n"); </FONT></P>2 K" C" K/ n. f
<P><FONT color=#0000ff>/* flush the output buffer */
! f8 D* D9 _5 h$ @fflush(stdout); </FONT></P>
+ S0 N$ {5 U9 {, F* @: X<P><FONT color=#0000ff>return 0; 6 u5 x! I  @( T3 ~2 w& z: h8 {& u
} & c% j. U& p/ K: a- e
</FONT>0 V; Y# K8 _0 p- e7 Q2 }' F
</P>
, O: k1 H( ]0 _# m' G% ?0 b<P><FONT color=#ff0000>函数名: setcbrk</FONT> - H1 E( r+ M0 q. P% w) Q
功 能: 设置Control-break
0 m( ]5 O' [$ O5 }* w用 法: int setcbrk(int value); ; n. T9 y  ?6 Z- a! U0 O0 O
程序例: </P>
1 u9 G+ `- ^0 p% {<P><FONT color=#0000ff>#include <DOS.H>
& \3 T* r- U+ a9 ^9 J5 {#include <CONIO.H>
. W( w: Y2 s+ \) s3 B3 X#include <STDIO.H></FONT></P>, Z+ J1 {/ ^. q6 b: k- V3 D  y& e0 ^
<P><FONT color=#0000ff>int main(void) 6 `( e9 i6 x% J. ^+ ~) [
{
8 z8 P+ F( j4 w5 b9 wint break_flag; </FONT></P>- Z+ c( i: B; F7 f  Q
<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n");
% s0 E& F! A$ b" P, D  `; cprintf("Enter 1 to turn control break on\n"); </FONT></P>& D4 P( y0 w3 ~# v' R- B
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>$ o( X& E! j; P( c7 _
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>- w6 A0 h. t1 O8 g4 K
<P><FONT color=#0000ff>if (getcbrk()) : X8 }" s' j  s  }! G9 I+ G
printf("Cntrl-brk flag is on\n"); % a; p3 P; o7 u- U
else 8 g' V$ h# l, P2 X" P3 H
printf("Cntrl-brk flag is off\n");
7 K$ f: e% E( g8 q  U# ]return 0; # `$ W* E0 k1 S0 v/ H! J( F  ?9 v
} - X; e1 z& ]: ~5 V6 Z, ?
+ N( z* B# g2 c
</FONT>
1 ~% x; z9 ]  M</P>
4 W8 ?7 i7 j: M# P, @<P><FONT color=#ff0000>函数名: setcolor</FONT>
1 Z: N4 E. O( {  K8 Y- I( F5 N! }功 能: 设置当前画线颜色 & Y; ]% h7 U6 ~& t6 A  C8 N8 ?( h
用 法: void far setcolor(int color);
2 d' v. ?. v$ R; k9 P9 h! K程序例: </P>+ v2 ]* I# N7 K( i7 c# {* J
<P><FONT color=#0000ff>#include <GRAPHICS.H>
7 c) B0 X9 [) f  \#include <STDLIB.H>
0 [! \& U$ }. O: n) U( S#include <STDIO.H>' [+ Y3 j/ [3 a+ F. }. F& y
#include <CONIO.H></FONT></P>: z9 e) V! C4 g7 i- ?# m1 B% k
<P><FONT color=#0000ff>int main(void) % d- c& M" [6 \
{ ( ~' A: L, @$ ?# R) i4 o3 y
/* select a driver and mode that supports */
& O3 ~/ ?9 ~5 D6 u/* multiple drawing colors. */
) {7 Q' w. M6 {1 g3 u0 D6 cint gdriver = EGA, gmode = EGAHI, errorcode;
7 o/ Q3 T, R& B  N* H. eint color, maxcolor, x, y;
9 ~. l3 @* m# ~$ t, S9 Ochar msg[80]; </FONT></P>
( Y8 e0 a8 b2 g9 @( S<P><FONT color=#0000ff>/* initialize graphics and local variables */
2 t* Y: U4 M/ z: c% z# xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( s- p' N5 T  ?1 ]+ H. p
<P><FONT color=#0000ff>/* read result of initialization */
5 b+ O: y* m* I( c5 M+ l4 Perrorcode = graphresult();
( A7 d5 H, s4 A& N, `  C6 ?if (errorcode != grOk) /* an error occurred */
- j5 R8 ^: w. e9 F{
$ n" i% u3 a, S  [# q. Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
/ ~7 j0 c: c# ~* J) r* R8 hprintf("Press any key to halt:"); 6 H8 A1 P' `% H  ], M9 Q
getch(); # e! G7 i5 Q3 W! Z, n  d
exit(1); /* terminate with an error code */ . j5 O# T# e& m/ E. y# b- G
} </FONT></P>
+ t8 M" T" l' H1 ?<P><FONT color=#0000ff>/* maximum color index supported */
* |- q+ ?+ W- I" h  J6 k/ fmaxcolor = getmaxcolor(); </FONT></P>3 h; u( {1 n- Y& Q
<P><FONT color=#0000ff>/* for centering text messages */ 9 u! G7 K4 r0 {  C3 p: k7 p
settextjustify(CENTER_TEXT, CENTER_TEXT); 8 v/ x+ C" h( h2 n( [6 ^
x = getmaxx() / 2; % V0 q& ^+ y' m3 {
y = getmaxy() / 2; </FONT></P>9 T# {* @, ?- `& q8 B
<P><FONT color=#0000ff>/* loop through the available colors */
6 q. B6 }2 m1 X" i. G$ Kfor (color=1; color&lt;=maxcolor; color++)
0 ]% I) R1 T, a7 g' W* R2 t, }{
8 D. w$ U& X9 ]/* clear the screen */ ) s& q9 o8 p0 h* f* N; f
cleardevice(); </FONT></P>
! S. P  t" O- x6 U5 _. Z<P><FONT color=#0000ff>/* select a new background color */ $ M( ~/ `1 A  |, D  L( h
setcolor(color); </FONT></P>
$ U. Q4 }- [) F6 v<P><FONT color=#0000ff>/* output a messsage */ ( Y; ^( n: n; K
sprintf(msg, "Color: %d", color);
/ }$ R$ [6 b5 M* l0 Y, @outtextxy(x, y, msg); & r* \/ W9 |1 }% f- a& t
getch(); / Z% d, _' ?7 n+ a5 ]6 q; \" j6 h; S
} </FONT></P>
3 _  h( l6 X. ?2 n: g<P><FONT color=#0000ff>/* clean up */
0 a4 ]  G8 @( Fclosegraph();
- y# }0 o2 q: i5 Ereturn 0; 1 z4 h1 B" f1 P* i8 ~& A# j
}
( G( y6 S7 B5 a" y</FONT>
# n: x( F, A2 l2 k$ e+ x0 J</P>
. z7 E+ w4 [1 P<P><FONT color=#ff0000>函数名: setdate </FONT>8 H/ a) n" V: C% E3 L
功 能: 设置DOS日期 0 N$ j; d" L/ B: `0 Q; d
用 法: void setdate(struct date *dateblk);
- [1 r/ D) K" G程序例: </P>7 [6 ~* Z! K$ q; a
<P><FONT color=#0000ff>#include <STDIO.H>
6 m  R# [- J  E1 \' \5 W#include <PROCESS.H># @7 n1 ^( q0 P  B
#include <DOS.H></FONT></P>
2 V( d9 C* W7 x- J<P><FONT color=#0000ff>int main(void)
; k9 Y+ I& ?0 R% d) o: ~{ , B$ a7 a+ ]3 T2 T) Q
struct date reset;
$ u; o$ o% z- b7 Q. ~' E2 N# Pstruct date save_date; </FONT></P>
1 u! Q; Y& b2 M0 `4 G<P><FONT color=#0000ff>getdate(&amp;save_date);
! U9 M) d3 Y2 x# s1 U5 q: Pprintf("Original date:\n"); / @# ^$ y6 o0 l+ b$ @. c
system("date"); </FONT></P>' C& O7 I) K' g/ O$ @1 J+ y
<P><FONT color=#0000ff>reset.da_year = 2001; . }' ?5 v4 {2 k3 Y0 d" B
reset.da_day = 1;
* f! J& C7 g4 v/ k6 l3 R/ Jreset.da_mon = 1;
# s3 W0 Y; P& B7 w1 isetdate(&amp;reset); </FONT></P>
! Y/ f/ b6 r# G9 \<P><FONT color=#0000ff>printf("Date after setting:\n"); : N6 p; z' i- D  |
system("date"); </FONT></P>7 h1 s. w# N( [: Z# Q
<P><FONT color=#0000ff>setdate(&amp;save_date);
  o9 d3 L6 M' X; j" Hprintf("Back to original date:\n"); , n9 g0 h6 V3 ^* d* ]3 u" v- X
system("date"); </FONT></P>1 e& @2 B: Q1 a
<P><FONT color=#0000ff>return 0; ; Y, ?& T/ s+ ]; V0 V
} ; I2 ~! U) `  y; S/ e" s; v/ Z- z
</FONT>
0 A! ]* h+ S( f+ I</P>
9 C5 n2 @/ C0 `. n0 P<P><FONT color=#ff0000>函数名: setdisk </FONT>1 i# y- R+ K- e
功 能: 设置当前磁盘驱动器 & w4 |. b* K0 S
用 法: int setdisk(int drive);   s% `6 ?% v) B$ t7 r* k* ^
程序例: </P>  Q+ b/ j! s& `1 ~  |1 d
<P><FONT color=#0000ff>#include <STDIO.H>
6 k; }/ f7 m6 G3 U#include <DIR.H></FONT></P>& r% @! `, u) _
<P><FONT color=#0000ff>int main(void) 6 Q, h' w3 c. [
{
& B, y/ V& l9 O! w; z% yint save, disk, disks; </FONT></P>
5 h5 x4 y  L. `: U$ f& K<P><FONT color=#0000ff>/* save original drive */ ; W: y- M3 {7 W8 g2 e2 r
save = getdisk(); </FONT></P>
6 k7 f) _4 \7 o: T6 z% D+ O* \8 B<P><FONT color=#0000ff>/* print number of logic drives */ $ ]5 ?8 N2 E1 }3 ^1 ~5 y' ^& Y, ]) h# x
disks = setdisk(save); 9 r! ], t4 d' K' ^: G
printf("%d logical drives on the system\n\n", disks); </FONT></P>6 i4 T, P+ K. l( |- Q5 C
<P><FONT color=#0000ff>/* print the drive letters available */ 6 U% |& n; k4 f% V, U- a
printf("Available drives:\n");
2 G4 Z9 M! q$ {& Ufor (disk = 0;disk &lt; 26;++disk) + v, c4 c, l5 `0 x
{ . W3 L  I! @6 ^' H+ P. @
setdisk(disk); , h6 z( V2 w/ s$ A
if (disk == getdisk())
1 `4 l5 H4 V7 R3 Jprintf("%c: drive is available\n", disk + 'a');
% A3 q+ D9 E/ ^3 T: p8 I}
9 u  t5 M6 m6 |" u7 Vsetdisk(save); </FONT></P>, }9 p9 a: {5 y5 u8 p- }
<P><FONT color=#0000ff>return 0;
4 ?  W# t4 E+ ?9 a} </FONT>
1 f* C! S! U3 [4 t: r
, X) e9 o4 l# _8 L0 o</P>: v* Z6 f9 a0 i  ^1 b- `
<P><FONT color=#ff0000>函数名: setdta </FONT>" h3 L5 \% {2 ]' A9 N2 E( E1 \, ^
功 能: 设置磁盘传输区地址
9 z* X0 O6 D: F( }" \用 法: void setdta(char far *dta);
& t5 E+ q, @1 ?程序例: </P>
6 [4 y0 [3 K* `2 y' X<P><FONT color=#0000ff>#include <PROCESS.H># G5 x+ M6 D; M
#include <STRING.H># s4 A: j# G% R1 Z; L
#include <STDIO.H>
8 q0 [/ U' S9 G. [7 S#include <DOS.H></FONT></P>
3 y- p* w8 ?+ T. I8 ~<P><FONT color=#0000ff>int main(void) 7 n* k2 m9 M2 f0 ]; a
{ 5 f5 i7 c, V) K4 A- `0 X
char line[80], far *save_dta;
" V# O* L9 s* n$ C) B; o6 achar buffer[256] = "SETDTA test!"; + S3 r  Q5 _' G0 d* z
struct fcb blk;
& z4 X" M5 U( K* |* Sint result; </FONT></P>
( w7 T* N# \" S/ {9 u* {: T<P><FONT color=#0000ff>/* get new file name from user */ * j8 ?4 F, r4 o7 D: X
printf("Enter a file name to create:");
# d; G1 g# E' N6 h3 z1 a; \0 Xgets(line); </FONT></P>
, i  L/ H" u# M6 X$ B$ v<P><FONT color=#0000ff>/* parse the new file name to the dta */
# F: q+ x8 j( O- W5 C3 s! Tparsfnm(line, &amp;blk, 1); % D# }9 [# J3 [2 |
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
$ ^! D) S+ C2 h<P><FONT color=#0000ff>/* request DOS services to create file */
- [- v% j1 ]3 G0 V) N6 ]if (bdosptr(0x16, &amp;blk, 0) == -1) 9 }) W5 u( l/ l; G" ]7 F/ B6 R
{
3 @- u7 @) F6 g9 J+ Y6 u% M) F" Yperror("Error creating file");   w% {. k, \4 W
exit(1);
- C- \0 f% N9 Z0 Q* |: Q} </FONT></P>
1 {6 Q* C7 @* _! k  |3 C<P><FONT color=#0000ff>/* save old dta and set new dta */ 0 a) A, A4 R% ?& p
save_dta = getdta(); . _4 \) @( C1 `$ |* w
setdta(buffer); </FONT></P>
0 }; X# M3 w: m5 T" G# R& a2 r<P><FONT color=#0000ff>/* write new records */ . }- ?2 Z( l8 r6 i- s
blk.fcb_recsize = 256;
5 R& c' O, X  G: S0 cblk.fcb_random = 0L; . \7 ?5 `8 ]! j& O, k7 E' k
result = randbwr(&amp;blk, 1);
9 ^0 n- z& n$ P& S: Gprintf("result = %d\n", result); </FONT></P>
, Q4 n) K* U/ f# {$ c<P><FONT color=#0000ff>if (!result)
0 z4 A+ p# ?# T" q2 e1 c& Y7 _printf("Write OK\n");
  C# b4 y( p; \( d( helse
6 q2 ]8 z1 G5 X- @{ 3 C( V  q) U6 y+ R
perror("Disk error"); 7 p% j, q* p' ^, c9 o2 H
exit(1); 6 ?: V. P; `* S, D$ t
} </FONT></P>
7 {  e" }7 p# ?- N3 Y- ?<P><FONT color=#0000ff>/* request DOS services to close the file */
  }7 z. O  O& }) |& oif (bdosptr(0x10, &amp;blk, 0) == -1)
  L* R  H! R: `; l{
* Z2 E3 C8 }6 Kperror("Error closing file");
( g1 |) ^6 V2 |! N0 e  ]2 J* zexit(1); / L# V; x. Q/ q3 ]/ c! b
} </FONT></P>
; ^( ]) y3 k3 `' m<P><FONT color=#0000ff>/* reset the old dta */
; E; V; b" y/ H- d. f" qsetdta(save_dta);
# {, Z. G5 ^8 W9 q7 y: T- {return 0; 0 e  F/ [; S1 R1 R; T  y
} # g# M: p$ O. K! Z- o' ~- v
</FONT>
+ U( f7 V5 w: u2 r8 c; W</P>% X; d/ x' U" K2 s5 e( E, d& j1 C
<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
7 E, o! Q6 y* B) R' s功 能: 选择用户定义的填充模式
0 ?& ], G7 N0 k0 G. s# q用 法: void far setfillpattern(char far *upattern, int color); - u+ A; N: U! L, f9 H
程序例: </P>
: A" a) k. }* ?# X' ~+ `<P><FONT color=#0000ff>#include <GRAPHICS.H>+ b2 ^3 ?  m, r
#include <STDLIB.H># u! ]$ }) W' V! Y. V
#include <STDIO.H>/ v2 R  X# \- F* z- `
#include <CONIO.H></FONT></P>! Q) X8 ^0 F( g( L1 Y6 O: o" u2 Y# f
<P><FONT color=#0000ff>int main(void) 7 q* L0 V+ Z7 C6 {" f
{ % Y8 c7 m* C7 |! W( Y9 w
/* request auto detection */ * s& h7 X3 I0 T9 l' s0 K8 \
int gdriver = DETECT, gmode, errorcode; % ^- v5 J. F; Q4 m& [
int maxx, maxy; </FONT></P>
6 H2 z: _7 {! h1 ?8 M( V2 L<P><FONT color=#0000ff>/* a user defined fill pattern */
- r6 j) q+ G% t, }3 l! X: T) [char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>
" N5 u8 C! n! s7 j% a1 o<P><FONT color=#0000ff>/* initialize graphics and local variables */
3 J) q  O& \- D  R" \3 Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
+ `$ a1 O" r7 U4 T7 Z6 e( k<P><FONT color=#0000ff>/* read result of initialization */
; O2 H2 X0 o  u% ?9 ~errorcode = graphresult();
) |; H1 F, z/ G+ I1 @" zif (errorcode != grOk) /* an error occurred */
5 x. Q" u! @$ a8 ]8 ?- f2 k{ 4 v, p; F0 l# ~5 I9 \
printf("Graphics error: %s\n", grapherrormsg(errorcode));
+ }% R& S+ }6 L% Gprintf("Press any key to halt:");
, v, F! r7 V6 D/ Igetch(); . \+ r- k3 @1 Z) [3 Q6 W
exit(1); /* terminate with an error code */ ! ]' d$ L5 m6 |
} </FONT></P>+ K; o2 Q  k  ^( K1 a
<P><FONT color=#0000ff>maxx = getmaxx(); & ]( I0 J: {2 O
maxy = getmaxy();
5 F. |: l3 y6 j! x! esetcolor(getmaxcolor()); </FONT></P>
$ G) |! Z: c, d+ C1 ~. H+ @+ X<P><FONT color=#0000ff>/* select a user defined fill pattern */ / T1 b6 f$ n6 F+ Q' M5 T3 ^
setfillpattern(pattern, getmaxcolor()); </FONT></P>2 n, f; `4 Q) \+ e
<P><FONT color=#0000ff>/* fill the screen with the pattern */
3 E. o, B+ C2 }! Y! ibar(0, 0, maxx, maxy); </FONT></P>% r3 F, N) L  w4 [" X! J
<P><FONT color=#0000ff>/* clean up */
$ [6 S) g* E: A9 H- o3 `+ p8 ?& qgetch();
. q! q) k( e+ _  }9 n! ?closegraph();
( H/ ?# d# o- preturn 0;
% j: v# t2 ^6 v: F- n}
$ y. ?3 i+ v2 k4 K' l( h  L. |</FONT>9 K8 o2 x" {  M( C
</P>- c! a/ _" X9 f% }# i6 g1 r* u
<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
$ `& I" o# x/ X, g: G% X' S; v' @功 能: 设置填充模式和颜色
% N# t3 A$ ?& _4 J用 法: void far setfillstyle(int pattern, int color); . W. y7 v! J+ @2 X4 H: H( F0 d: Z
程序例: </P>
' L7 b+ m8 M0 C% F- s<P><FONT color=#0000ff>#include <GRAPHICS.H>' i2 P, {% `7 k
#include <STDLIB.H>% }  H1 J: F1 h: l
#include <STRING.H>5 A: s1 B* O2 W, w$ Q# w9 R2 F
#include <STDIO.H>9 D  V) t( Z3 q9 V$ A( `+ L2 i
#include <CONIO.H></FONT></P>4 D6 ]5 n1 B4 G8 U
<P><FONT color=#0000ff>/* the names of the fill styles supported */
8 E! ~, U- {& b3 R7 }6 H  {5 pchar *fname[] = { "EMPTY_FILL",
! h5 G) C4 Q' a; C$ a3 v"SOLID_FILL", " o0 P2 b& V" p4 B
"LINE_FILL", 8 Q  H, `0 |5 o7 H3 x1 `
"LTSLASH_FILL", + ]5 \+ K5 J: {3 N! w+ s$ V( a
"SLASH_FILL",
7 q" g4 B9 R& C"BKSLASH_FILL",
+ J! b+ V1 v1 y  H7 R+ |+ F2 F"LTBKSLASH_FILL", ) O8 W% j0 k* M% B
"HATCH_FILL", ! Q% P* v* E3 m1 C  _5 s1 m
"XHATCH_FILL",
! R6 z8 z5 [# L( x2 r, q"INTERLEAVE_FILL", ; {0 E& _9 [/ g
"WIDE_DOT_FILL",
6 @8 {% b- b- o& O# H/ {5 F"CLOSE_DOT_FILL", / Y4 O; k9 b1 A5 ~) s- o: A
"USER_FILL"
0 L2 O% l" Z: L4 G8 W) Q3 W}; </FONT></P>6 m* a" X& t0 ~; B" j2 m
<P><FONT color=#0000ff>int main(void)
9 ]3 ~& Z( G& l" S{ 8 c" y8 x. M8 n3 W  p+ B; K
/* request auto detection */
, \0 F( k2 ~) M& \& S5 W% b4 i2 Fint gdriver = DETECT, gmode, errorcode; : V! z8 x( I9 K( P
int style, midx, midy;
; O9 {/ X1 v0 uchar stylestr[40]; </FONT></P>
9 |2 s" V2 E; ]<P><FONT color=#0000ff>/* initialize graphics and local variables */
' P- F$ U; A8 e  k8 J  y8 w  Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 P- f( N( `8 a
<P><FONT color=#0000ff>/* read result of initialization */ , y1 y1 D1 o0 B8 ^
errorcode = graphresult(); 7 C9 @9 H! ^. M
if (errorcode != grOk) /* an error occurred */ ! }- @, v; l  z
{ 8 e0 c. ^  N' S/ d; {) X: X7 L
printf("Graphics error: %s\n", grapherrormsg(errorcode)); & m6 r9 V$ A+ S% [$ J- a
printf("Press any key to halt:"); # ]" W0 I+ E" K
getch();
# q, {% ]  K/ Gexit(1); /* terminate with an error code */ . h5 d2 j4 u" U/ |) t2 h
} </FONT></P>- J: x4 ]/ p# u7 ?$ J% c
<P><FONT color=#0000ff>midx = getmaxx() / 2; 7 J! I1 y3 O. w5 K# |
midy = getmaxy() / 2; </FONT></P>
* D4 h" K' T2 O1 b0 `<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++)
- P: l5 q3 I8 I( z9 d1 o{ % ?8 ~6 ~4 |/ _2 S- L" y4 W9 X
/* select the fill style */ " J" M% K. Q; \: s9 f& q- K0 m
setfillstyle(style, getmaxcolor()); </FONT></P>+ o# V& I+ H& K! O
<P><FONT color=#0000ff>/* convert style into a string */
- e: c" H* K2 J) v4 _! d( `4 Q. O7 Rstrcpy(stylestr, fname[style]); </FONT></P>
, B6 y: R# o; O3 r- V<P><FONT color=#0000ff>/* fill a bar */ 9 C) K* `  Y# n6 d
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>0 Y. o# U& `% L2 n) i1 |; Q
<P><FONT color=#0000ff>/* output a message */ : f: |5 N4 x, N% r& R
outtextxy(midx, midy, stylestr); </FONT></P>
! w* \4 |  z1 }/ F<P><FONT color=#0000ff>/* wait for a key */ ' P0 u) ]# E/ ]& e# f  U
getch();
. O0 S; L+ S) J7 O' c. o5 \5 ~6 ycleardevice();
- D# m; x; g, S. g6 N+ F/ k0 v} </FONT></P>: F8 a8 r3 Q. F8 m- N; y
<P><FONT color=#0000ff>/* clean up */ 4 Z# i0 H9 Y! w, B& ]+ t
getch(); 5 n' q# ^4 M9 L" J8 d
closegraph();
# X- v# ?8 a( Jreturn 0;
- W4 Q1 o+ ~* n% x( P9 M} </FONT>/ q+ _; y( j3 O+ \$ q

7 B4 x, W4 X/ F- e, k</P>
8 _" R4 }5 H0 Z& Q- S7 E<P><FONT color=#ff0000>函数名: setftime </FONT>
1 O/ p. M* J- {# R; k  l6 U( F功 能: 设置文件日期和时间 9 ~+ i" a- H( d
用 法: int setftime(int handle, struct ftime *ftimep); 9 ]1 k! L' f7 y3 g# b
程序例: </P>
: @  h# k0 }- L6 o' `" j7 N; }3 m% S<P><FONT color=#0000ff>#include <STDIO.H>
& f" `* x# D/ m#include <PROCESS.H>- C- g1 v1 n1 Q; n9 O
#include <FCNTL.H>8 I& U1 ?7 Y: T' z
#include <IO.H></FONT></P>+ P) Q6 i! `$ |8 r* v
<P><FONT color=#0000ff>int main(void) # M2 X+ b" @/ `3 O
{ / c" \+ `% o$ {. r$ F8 f: Y
struct ftime filet; 4 b5 b7 h7 _6 B! {8 ~& a
FILE *fp; </FONT></P>
/ ?/ \9 c% |: ~  n<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL)   ]7 m$ g7 Z' c4 o$ i
{ 9 L+ r+ I4 c3 T! i1 D& {
perror("Error:"); 7 W1 ?: W, j" i* w5 y6 A& p
exit(1);
# x8 H! ^$ R; w  j3 N. L} </FONT></P>* j& S, A1 r# F5 }5 N
<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>
, r* Y( b# ]4 z, [3 z0 y/ V<P><FONT color=#0000ff>/* load ftime structure with new time and date */ 5 P4 E- o" L3 [/ b
filet.ft_tsec = 1; & u3 X7 g/ @1 s  Q
filet.ft_min = 1;
+ ?" j/ W6 }$ w- X! sfilet.ft_hour = 1;
3 H* b5 f) S' c# qfilet.ft_day = 1;
6 `8 h' v/ ~% X& X" G3 x( afilet.ft_month = 1;
' V+ K3 L0 H  k) E! |* Zfilet.ft_year = 21; </FONT></P>
8 [, v( r1 k3 J9 f$ ^4 I* t, W<P><FONT color=#0000ff>/* show current directory for time and date */ ! P. a, ]" i) F; @+ U
system("dir TEST.$$$"); </FONT></P>3 ~7 V: Q" J2 i- m  f
<P><FONT color=#0000ff>/* change the time and date stamp*/
: H# k. w$ G+ m5 U' g( X0 v% y  D' ysetftime(fileno(fp), &amp;filet); </FONT></P>
2 q7 Z! T7 z0 Z<P><FONT color=#0000ff>/* close and remove the temporary file */ % H# M; B+ H9 T: f: D. o. v3 D( _6 a9 A
fclose(fp); </FONT></P># ]3 J( o/ S+ n1 U+ |% n, `" q" u
<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>) X) I9 F; ?5 d# `1 d
<P><FONT color=#0000ff>unlink("TEST.$$$"); $ V) ~/ v3 V6 a0 ]9 [! W! d
return 0;
$ H- o$ Y( r/ b2 L! K} * r4 i9 N, Z9 ~: V: w
</FONT>1 B7 L& `! l. j7 L
</P>  ]) D' M) p- k; R8 q, ~, ]1 n
<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
/ g) }1 q7 t: d" U1 l功 能: 改变内部图形缓冲区的大小 / n" K$ p: B- E  Q* i! @  a. o7 W/ W
用 法: unsigned far setgraphbufsize(unsigned bufsize); / m( L6 X7 e/ r* w& Z0 z
程序例: </P>
& j! x! F) V0 |3 z2 l1 o) f) E<P><FONT color=#0000ff>#include <GRAPHICS.H># q* Q1 T4 a8 v2 Y. @5 s
#include <STDLIB.H>9 W% r# r$ {. R' J& k, D
#include <STDIO.H>
5 H  w2 `( h& N; g1 d, I& a! S#include <CONIO.H></FONT></P>8 _; t1 F; z  @3 x6 d
<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>; E4 v% U  ]2 j6 ^" W8 }
<P><FONT color=#0000ff>int main(void)
9 r, C; T! y% L) ?# Q3 P{
! K# p3 d7 X9 U; n/* request auto detection */ 9 L0 X. p) i6 B! W% x5 B
int gdriver = DETECT, gmode, errorcode;
4 r7 J5 g0 h" x9 w. ]: V- _int x, y, oldsize; # ^5 W5 |1 O) ]" F1 M3 ]+ ?2 ^
char msg[80]; </FONT></P># M; i* B: k# f* Y3 u& |
<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */
1 r: @; @% |# z, R4 R/* before making a call to initgraph. */
" e3 F" [+ T5 Noldsize = setgraphbufsize(BUFSIZE); </FONT></P>; l) ~3 v, f8 L4 ?8 k: [7 f
<P><FONT color=#0000ff>/* initialize graphics and local variables */ " s% ^; ^5 Y; m! X  p
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 k: o2 l) R. U* Y<P><FONT color=#0000ff>/* read result of initialization */
+ }5 _3 Q) Y& U$ }errorcode = graphresult(); # Y* E$ F+ g' D  ~9 u2 ^4 t
if (errorcode != grOk) /* an error occurred */ ; G- H! `( {$ F+ B
{ $ P& j3 {& k7 E1 Q$ r! X$ W  E
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . K" ~( Q4 ~7 a9 \
printf("Press any key to halt:"); # I. K, h: `, [5 H+ ^4 k. P
getch(); ) n! V! E5 I3 e# V0 Y9 `5 c
exit(1); /* terminate with an error code */ + s8 o2 {4 W' X# T' g/ ?, u- l& ~
} </FONT></P>
' N) q; D" v% O4 q, i<P><FONT color=#0000ff>x = getmaxx() / 2; / b: n' K8 W6 E
y = getmaxy() / 2; </FONT></P>
: o3 b0 A  r- V3 w7 B<P><FONT color=#0000ff>/* output some messages */ 6 n; n* y: F, c1 y( l7 B& d# [6 a' W2 D1 S
sprintf(msg, "Graphics buffer size: %d", BUFSIZE); 8 ?* U# I4 R3 h: w8 O
settextjustify(CENTER_TEXT, CENTER_TEXT);
6 h6 [0 i4 g; |/ U* H- x" ^% xouttextxy(x, y, msg); ' c* l, \& U$ n& m; d8 ~7 n, P
sprintf(msg, "Old graphics buffer size: %d", oldsize); 1 `  @" h( [1 @$ D# }7 `
outtextxy(x, y+textheight("W"), msg); </FONT></P>% _$ d, y' }  \* j$ f5 Q
<P><FONT color=#0000ff>/* clean up */ 6 f$ b7 a4 x8 f( Z% F  ?$ {
getch();
5 q& _5 n' ~# t3 J+ @4 Vclosegraph();
: }! n+ }1 ~1 M# W# ], breturn 0;
' ^0 X0 Q, s+ j5 y}
- }: m1 h! {/ ~- ^* u9 n  u
, B0 M* F" B0 A. m, N# e' n8 i& Q6 r: z, c! N: b* z/ V. p7 c
</FONT></P>
9 ?1 K! L4 r5 X; u) \<P><FONT color=#ff0000>函数名: setgraphmode </FONT>
$ |) L, c1 o# j$ g功 能: 将系统设置成图形模式且清屏
- d7 c9 A% g) R9 ?  A用 法: void far setgraphmode(int mode); - Z/ F+ v# p& e
程序例:
$ B' x; M, ]& o, c/ ^0 |2 g- _3 [6 l
<FONT color=#0000ff>#include <STDLIB.H>
% B! F, _! O7 \# A  J5 g! {# w#include <STDIO.H>0 k/ q, e6 Z9 q
#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
0 z: v7 \  K- b<P><FONT color=#0000ff>int main(void) ' @( V3 w0 ^' B/ j' J
{ : z% a, s+ x  k- d* e  v% a
/* request auto detection */
- g% N, N1 K( N3 yint gdriver = DETECT, gmode, errorcode; % Z+ O' D/ s0 I6 |" n& d( ]6 ^0 P
int x, y; </FONT></P>
1 O0 I! z3 @; f6 k0 L& H<P><FONT color=#0000ff>/* initialize graphics and local variables */
% ~0 t$ H7 j4 I, j/ Y- z# O2 H1 Ainitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>) N4 v9 W. T! N$ L6 I1 k0 [
<P><FONT color=#0000ff>/* read result of initialization */ $ z" X7 X' _1 P4 {
errorcode = graphresult(); - l# h) g) D. ^& [0 l
if (errorcode != grOk) /* an error occurred */
' Z4 h! c/ ~! R{   Q5 R8 G$ z6 h
printf("Graphics error: %s\n", grapherrormsg(errorcode));   v9 Y7 H$ O& {
printf("Press any key to halt:");
- [9 {' u8 m' e4 |7 lgetch(); ' F" X0 h* _% Y% y5 y
exit(1); /* terminate with an error code */
8 y- W: b; v( G, P} </FONT></P>4 c1 A' u/ i  K8 q; U, r  R
<P><FONT color=#0000ff>x = getmaxx() / 2; : F" |! l4 a; m, p; `0 m1 T, o
y = getmaxy() / 2; </FONT></P>5 j7 S. m6 h) V
<P><FONT color=#0000ff>/* output a message */ 5 U3 C$ f" p( G- J9 L- J* g
settextjustify(CENTER_TEXT, CENTER_TEXT); ; o& t9 {7 `3 U4 E8 a
outtextxy(x, y, "Press any key to exit graphics:"); & N# w3 s$ _+ x( Q
getch(); </FONT></P>4 v$ K8 C) Q+ Y
<P><FONT color=#0000ff>/* restore system to text mode */ ! }( s1 T; b" W+ M) k
restorecrtmode(); 6 |+ q$ m* ^+ q5 Z- L4 P  T
printf("We're now in text mode.\n"); # z/ ~2 v3 _0 @0 H4 {
printf("Press any key to return to graphics mode:"); ( m: a5 w4 ~3 R9 v  {4 Q
getch(); </FONT></P>$ l  H0 _0 P5 Q  @7 |
<P><FONT color=#0000ff>/* return to graphics mode */ 1 Z' [- ^5 w9 q  M0 f) }# n
setgraphmode(getgraphmode()); </FONT></P>
2 f3 }# K+ L& ]% y7 K<P><FONT color=#0000ff>/* output a message */
4 u7 I2 p+ F  N9 l# csettextjustify(CENTER_TEXT, CENTER_TEXT); " @9 M$ o; h7 j% o* a" L
outtextxy(x, y, "We're back in graphics mode."); 7 V1 p: R- y& Q% m- ~; s2 M+ I8 m' |5 l  O
outtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>5 E% K& p, a+ A  ?8 X
<P><FONT color=#0000ff>/* clean up */ 2 X5 V6 Q. i* t+ g7 ?$ I
getch(); ; [3 n' S! U  W; P$ F7 z2 c
closegraph();
9 t7 _( O! {3 P: g$ ~; Z* Dreturn 0; ; }4 m/ _% b, W! g0 }# L( f/ e1 y
}
0 f  E; N. }  k# r* c4 j
3 l1 M6 k9 O; H7 `: u$ V1 U' {: S" ]
* A, }) h* b* f0 I</FONT><FONT color=#ff0000></FONT></P>
$ {+ B* G0 u& v0 p; M' g9 ~<P><FONT color=#ff0000>函数名: setjmp </FONT>
: V4 i* L+ H; e5 b# L. x功 能: 非局部转移
, F7 r% F( d( D: O8 Z4 r) N+ K用 法: int setjmp(jmp_buf env); / h+ Q9 t! g4 h$ t
程序例: </P>
. u) j6 [& s# _: p<P><FONT color=#0000ff>#include <STDIO.H>
1 @! k8 l" {( M4 M& c% g( y#include <PROCESS.H>
% R/ x) H! q6 ~: a#include <SETJMP.H></FONT></P>
* c  Q" I% J) ^% }<P><FONT color=#0000ff>void subroutine(void); </FONT></P>
$ A4 E1 r- d( ~<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>6 |* C6 C5 Y$ Z4 Y/ X2 u3 {. k
<P><FONT color=#0000ff>int main(void) # c) m, u1 o2 W" x& ~9 Z
{ 5 j, H, Z( ~$ e9 }  }% ]" _# V
int value; </FONT></P>
& ^* ?+ j4 y3 k- P5 l2 t' v5 [<P><FONT color=#0000ff>value = setjmp(jumper); 3 i) F- j1 k; b: H9 C, I
if (value != 0) 6 A% S0 b6 E0 M1 z. o
{ ( H# ^8 u+ c! x5 i8 Z
printf("Longjmp with value %d\n", value); * _6 |5 ^+ @1 V. ^; P$ l
exit(value);
) l: I2 U1 m: c/ \& |9 f; o, l6 M} . o8 b- }+ [0 _1 c4 L+ D2 I* A
printf("About to call subroutine ... \n"); 9 s" ?; B) [" ^
subroutine();
9 h% C2 M5 j- |) @8 X) H0 w8 X* K: `return 0; ' X" |2 X- c" S2 [% }
} </FONT></P>. `: D- W- _8 _& {+ u2 H3 f
<P><FONT color=#0000ff>void subroutine(void) $ j. m% i" r8 m9 U# ?! N) l  e1 w5 K
{ # M( ~$ d, \% ?5 P& q( o! |
longjmp(jumper,1);
1 c3 u% [) t! M9 F1 M5 g}
* l1 ^: q& m. }, B</FONT>
4 [, l1 L$ ^4 f9 a9 D2 @; q</P>
- \; \/ D' v; W5 R: K<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
; G% i, f/ Y, S0 j- x功 能: 设置当前画线宽度和类型
. f8 P+ u# _+ h7 F: Y用 法: void far setlinestyle(int linestype, unsigned upattern);
7 U9 j" x- k, s9 F5 Q程序例: </P>
4 q8 ~8 L" y: \) F( V# _<P><FONT color=#0000ff>#include <GRAPHICS.H>
: K+ ^( V) M1 p' v#include <STDLIB.H>& X: y& v+ x, A1 y
#include <STRING.H>
4 p& X- S% p- {: \" [) t) _! X$ w( N#include <STDIO.H>
6 z7 @" U1 Q8 a( u* K0 i#include <CONIO.H></FONT></P>% L  l6 _6 A8 J9 P0 m5 c9 Q( j- O
<P><FONT color=#0000ff>/* the names of the line styles supported */ 6 E! L( s0 R( g( T% J+ F
char *lname[] = { 4 g/ C' C! y1 m. C0 c- h/ b
"SOLID_LINE",
9 x5 s' w  W; [, o"DOTTED_LINE", 6 ]/ P7 S  v* }! H# j7 u
"CENTER_LINE", - F$ K4 a! s; M6 Q+ A" n
"DASHED_LINE", % ^6 F. X1 h, z. K8 k0 L7 `
"USERBIT_LINE" 5 v8 a- c- H; s2 f0 s* D' L6 c, R
}; </FONT></P>
5 ^7 E. P4 R( W- t, `<P><FONT color=#0000ff>int main(void) $ O4 E) j9 |1 I% p8 |  B2 J, P
{ + f; k& _% L3 b5 @9 @' x, O
/* request auto detection */ % \; W! D3 [* ~7 u6 V. x  Y
int gdriver = DETECT, gmode, errorcode; </FONT></P>
, ]3 G' D; [% _; C3 ^- k<P><FONT color=#0000ff>int style, midx, midy, userpat; 5 w4 p* w% ?  u' F
char stylestr[40]; </FONT></P>4 w! C  B& B2 w" H$ B& a
<P><FONT color=#0000ff>/* initialize graphics and local variables */ & N9 p* t, _5 T. P
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) j# V+ ?$ n$ V. b<P><FONT color=#0000ff>/* read result of initialization */ 1 C' f7 X0 B& V8 `5 ~* V
errorcode = graphresult(); ( J5 s6 u. G, a- k$ V0 W( g( [, j
if (errorcode != grOk) /* an error occurred */
2 ?7 R) U- S9 M; A* X# W1 y{
; [( B3 b; g  l4 r( v5 [printf("Graphics error: %s\n", grapherrormsg(errorcode));
: j; M( z$ q( E! w' F' qprintf("Press any key to halt:"); 2 ~% n3 Y( t8 W7 M
getch(); 5 F2 ?- w  a9 L" v  ?: k
exit(1); /* terminate with an error code */
# L/ S5 V5 r+ ?( A' y0 Z% l} </FONT></P>
, T/ w0 E1 z; R<P><FONT color=#0000ff>midx = getmaxx() / 2;
9 B/ @: B& ~5 cmidy = getmaxy() / 2; </FONT></P>
, P- G+ L9 `* t1 N<P><FONT color=#0000ff>/* a user defined line pattern */
9 U: M* \3 Y% M5 I' H7 e  Z3 P5 ~2 C/* binary: "0000000000000001" */ & l5 l7 u$ T" t' m; C% c
userpat = 1; </FONT></P>
5 v% m% e5 g- l( m1 R5 X<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++)
8 J% Y( Z" S) N. s{ 1 g0 e5 v. d1 Q. U( o: _7 ~. i
/* select the line style */ $ ?: d* Q# {- _
setlinestyle(style, userpat, 1); </FONT></P>
  V0 B' w8 C# w6 @1 j# y<P><FONT color=#0000ff>/* convert style into a string */ 5 w' ~! |) r9 E6 ^0 w$ f
strcpy(stylestr, lname[style]); </FONT></P>
0 M- F0 e/ W9 X* C<P><FONT color=#0000ff>/* draw a line */
) F; i! n+ w6 vline(0, 0, midx-10, midy); </FONT></P>" B7 g' [5 X) f) t* U* g& P5 s# _9 _
<P><FONT color=#0000ff>/* draw a rectangle */
7 c- Y9 Q6 J6 W; r1 l5 o! Zrectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>1 z0 W% Z' j$ n
<P><FONT color=#0000ff>/* output a message */ , L" [  I5 y# X0 F6 ?
outtextxy(midx, midy, stylestr); </FONT></P>
& V! u- l% u' g9 Q6 W3 Y& S- m<P><FONT color=#0000ff>/* wait for a key */
4 R; W4 l6 {0 s& F& M# ~% P1 z7 Ygetch();
; N5 Z. \- c; b/ V5 E# Gcleardevice();
, `& n0 {% ^( c3 M$ F} </FONT></P>- p6 h- e2 Y+ P) c4 |& ]
<P><FONT color=#0000ff>/* clean up */ ) E4 I% J* Q  Y$ w5 F8 J; i- _, N
closegraph();
# X+ b! w9 @2 oreturn 0;
! E$ x! y- H' R6 h( l} </FONT>
+ D" L# g' U! n, a
: y: r5 d# N, S1 |$ q3 ?! J% U" V: c" R5 x
</P>
* v5 a0 e2 v! ^* s<P><FONT color=#ff0000>函数名: setmem </FONT>% a1 D# T/ \9 n: h- n4 X
功 能: 存值到存储区 * [; L- N5 V$ _' b% w% g
用 法: void setmem(void *addr, int len, char value);
7 [) F0 ]. g' J) V& M+ R; V程序例: </P>
" Z" A+ j" ]' x6 U1 q/ J( I<P><FONT color=#0000ff>#include <STDIO.H>: i. @; q. p  P' t: E8 _# j
#include <ALLOC.H>$ ?3 J# Y, {6 b. L
#include <MEM.H></FONT></P>" K  m: j- X, N
<P><FONT color=#0000ff>int main(void) + J7 ]' }) i& B& D
{
' y3 j& Z' v# S! t$ Ochar *dest; </FONT></P>
' v: r! d+ i9 Y6 O- v& Q<P><FONT color=#0000ff>dest = calloc(21, sizeof(char));
6 P4 m, {/ w( r* T/ A6 Q  [/ ysetmem(dest, 20, 'c'); / C4 O/ m  l+ B) A" G% D
printf("%s\n", dest); </FONT></P>
, e/ d: v* b) J<P><FONT color=#0000ff>return 0; ! g2 E/ F; j: P1 t7 Q9 A2 |
} </FONT>7 H2 R$ u* P6 |5 c
2 T0 d, p0 Z6 ~) }; L

. v8 W/ F9 y7 `2 y- Y</P>
' ?: R! Y  R7 c5 H/ j7 ]* X5 L. ]<P><FONT color=#ff0000>函数名: setmode </FONT>- w9 J3 r1 _4 P% k; C) o: k
功 能: 设置打开文件方式 0 ?& @, {- {6 a+ M  N
用 法: int setmode(int handle, unsigned mode); 3 O8 J" Y1 R6 V' A' D
程序例: </P>
, p' S  b  o( i6 B/ R1 Q<P><FONT color=#0000ff>#include <STDIO.H>
. V0 @2 J5 O9 z6 P#include <FCNTL.H>
& B* N' x: W9 {" K5 y#include <IO.H></FONT></P>7 u  k1 {7 k6 ]1 A1 c
<P><FONT color=#0000ff>int main(void)
. k  L( C/ d3 }  X3 H{
8 D( ?; F8 T. h  F" V0 a+ [5 K( |int result; </FONT></P>
; `: e: E: {$ h, {5 q, S<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); / w1 s( V) E" h9 z) G. u& I' @
if (result == -1)   z/ O6 z- P/ v  k8 L/ D
perror("Mode not available\n"); / s% ?' R( M# c% I  ^, Y8 e
else / P& I0 g% m* e, {9 b. c5 X
printf("Mode successfully switched\n"); , {# _% _) U0 u% s1 c# v( R( e- M/ Y0 l
return 0; 6 N& f. `6 b6 K  a4 f" ~' q( Z$ K+ b" m
} % T/ {- {8 L, E4 A0 z; `/ Y

' b9 q% w1 g8 J' \</FONT>) W5 m. @$ p: @2 }
</P>$ ]  X+ d' l  o2 t: d. ~9 p
<P><FONT color=#ff0000>函数名: setpalette </FONT>
  u6 D' |( z0 X/ Z+ y功 能: 改变调色板的颜色 6 m5 ^' r0 L2 e2 `6 \
用 法: void far setpalette(int index, int actural_color);
( r/ t4 I7 u! k3 r$ l3 V4 \程序例: </P>5 K, b+ s- S1 b2 @" H+ Y2 ^$ S
<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 @; ]% H* a3 s#include <STDLIB.H>
$ C5 T' p9 C. j8 x9 _: G$ d#include <STDIO.H>& `8 G( q3 H. l7 X  i
#include <CONIO.H></FONT></P>
8 C* w  f- h0 c+ w5 k5 C<P><FONT color=#0000ff>int main(void) : Y/ c" {. ?+ g0 b& |  F/ E
{
; g2 D4 O8 ^9 F2 F1 w  H/* request auto detection */
4 W. h  D) h! s* P& C5 N7 F4 |+ jint gdriver = DETECT, gmode, errorcode; : O! s7 |& x: @5 N; @1 [. s1 `
int color, maxcolor, ht;
4 v' h' [' S7 Sint y = 10; 2 v% F+ e7 |6 s4 z* ?' a1 C! |
char msg[80]; </FONT></P>
& \& Y) Y- G" F( n7 E! ~( ]* Z<P><FONT color=#0000ff>/* initialize graphics and local variables */ 8 E4 D: i- H1 T! m9 E, o2 g( T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
  `+ X  b! |$ v) }2 V! O/ o- a+ k<P><FONT color=#0000ff>/* read result of initialization */ : z2 q' B) e! {' {) M0 @
errorcode = graphresult();
7 F; d2 @6 Z  G2 C% t" i( Oif (errorcode != grOk) /* an error occurred */ ; ?/ U; d# I  B- z4 V, \" T
{ 2 ~8 w8 j2 Q5 i" g0 q, m3 @
printf("Graphics error: %s\n", grapherrormsg(errorcode)); . X% ~" h: z/ G) |$ t
printf("Press any key to halt:"); ( Q* {; P7 ~7 _. M& c
getch();
2 d8 q! J. i1 T" x4 R- {exit(1); /* terminate with an error code */ ) V) A3 a2 G4 A8 K/ h# H
} </FONT></P>
1 m- R/ O) I* z5 |+ f- E9 \, b<P><FONT color=#0000ff>maxcolor = getmaxcolor();
3 k/ c' h5 |0 jht = 2 * textheight("W"); </FONT></P>
+ ?& L# r' `  Y# Q; H+ }/ D. g<P><FONT color=#0000ff>/* display the default colors */ 2 @3 h$ M3 r  w9 ]! `+ ?7 P
for (color=1; color&lt;=maxcolor; color++)
; h3 S) R1 p; k6 Q{ , h+ q% }* h' Y% f) u$ w, W
setcolor(color); 2 S3 R( l6 P; d' k& n- m
sprintf(msg, "Color: %d", color); 1 y; x) H) E7 S) O1 E$ s* n' \
outtextxy(1, y, msg); 0 `* ~# w2 v' p9 P
y += ht;
8 V! F9 C& ]$ D3 L} </FONT></P>6 L& W: v9 V; }
<P><FONT color=#0000ff>/* wait for a key */ * h; g/ m1 b9 Z( w& ~( h
getch(); </FONT></P>
( ]+ y3 y5 Y( m<P><FONT color=#0000ff>/* black out the colors one by one */
, \) q! B" \' {% _" P8 E" N/ Ffor (color=1; color&lt;=maxcolor; color++) % f! `. n: h. f8 D( O$ R
{
2 \0 b# n1 i8 G# [/ x9 s4 Y6 hsetpalette(color, BLACK); 0 q, G8 J9 [: X6 `
getch();
& d/ U" }5 k' t8 v- p* u" S1 K9 h} </FONT></P>3 L5 }* B. d/ S- P
<P><FONT color=#0000ff>/* clean up */ # e# l- M. H  F1 `" \0 b
closegraph(); % ^+ j) U% m- g/ ?! n1 }7 x* W) y
return 0;
# d& l1 L  w1 r' [0 {* j; J}
& v4 V7 K: y) h: _' [& g: |9 u9 P& W</FONT>
1 z* J- u7 w% a$ z</P>& u" m& f* P* d' c+ }6 h$ [% v3 f
<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>/ m2 E; X6 R/ n- }! X# d
功 能: 定义IBM8514图形卡的颜色 ! v2 o* W  _8 U* ]+ \
用 法: void far setrgbpalette(int colornum, int red, int green, int blue); $ A4 i" f( E4 {7 `! Y& m
程序例: </P>5 S6 B& \8 Z9 ]6 {' g
<P><FONT color=#0000ff>#include <GRAPHICS.H>
4 L  l1 X- I+ P& J#include <STDLIB.H>- W2 i. F9 o6 B5 e# V0 l2 \
#include <STDIO.H>
2 I7 o8 E" p# k+ i# A/ e. V#include <CONIO.H></FONT></P>
4 @" `; v$ E! Y& X<P><FONT color=#0000ff>int main(void) + W% ~) q  O$ A9 w
{
3 A5 w# X. A5 }3 {/* select a driver and mode that supports the use */ 6 ]# |: ~3 X7 H; @
/* of the setrgbpalette function. */ 4 m( f( M3 s  g0 o
int gdriver = VGA, gmode = VGAHI, errorcode; , D. g( R( x8 U5 W# J/ S: d
struct palettetype pal;
2 s, F, q( E( Z  w* j. v6 U- Jint i, ht, y, xmax; </FONT></P>
: q! I; ^/ w6 Q, D# K( n! ~3 N, p<P><FONT color=#0000ff>/* initialize graphics and local variables */
* D( G% c' m* d% sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ [( v( }! q) z* O7 ^7 ^7 \- k<P><FONT color=#0000ff>/* read result of initialization */ ' {- M) y, d& H9 c0 B" E
errorcode = graphresult();
! [1 a: A0 M- K  E; V1 p2 Tif (errorcode != grOk) /* an error occurred */
1 P" v* R* `' A{ 8 v+ O" P1 O4 X0 g; l
printf("Graphics error: %s\n", grapherrormsg(errorcode)); # o, G3 k1 J6 w  R2 Z  ^0 c
printf("Press any key to halt:");
2 o0 k+ ?# s1 v# Rgetch();
$ g" S* H9 f$ j2 N2 F$ O& H, C( Xexit(1); /* terminate with an error code */ . A+ f; T7 U6 r% J
} </FONT></P>
* M& Y' E1 `7 A" @! K<P><FONT color=#0000ff>/* grab a copy of the palette */ 3 T) m8 {/ B% n
getpalette(&amp;pal); </FONT></P>) C5 i1 p& T0 x, A0 n+ Z
<P><FONT color=#0000ff>/* create gray scale */ + M/ W9 A8 F% U, I8 f+ N
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>0 c7 s9 L# ?8 S( N6 {# @
<P><FONT color=#0000ff>/* display the gray scale */
3 o+ M+ ?1 E, a% z. I* W, Zht = getmaxy() / 16; 2 @% L2 ]$ s8 _
xmax = getmaxx();
5 X2 G& B, C4 m1 U/ u. r3 Gy = 0;
( Z& o8 c7 `8 _/ ^+ c  P$ Gfor (i=0; i<PAL.SIZE; <br i++)> {
2 D& q3 p1 R  n# q9 Asetfillstyle(SOLID_FILL, i);
& ]7 T3 y8 L0 v. _) e! R+ ^bar(0, y, xmax, y+ht);
; P5 d4 [6 m2 {, |3 fy += ht;
$ h- j5 p5 {# s/ b/ ~/ F% n5 S} </FONT></P>/ ?+ k2 ?* ~1 m8 ^
<P><FONT color=#0000ff>/* clean up */ 0 c/ r# Y$ D! k$ x
getch(); - a# x3 ^& }/ }4 w
closegraph();
# U) B8 _8 P% }1 W8 _1 ^- u' N1 xreturn 0; " |: E4 z+ I& L
}
9 a. s( j5 b6 F' h  \. f</FONT>
# B1 ]3 l2 j! z5 D! C; m- O+ A! P8 q
</P>  B5 E3 D- e4 s9 }, x! O
<P><FONT color=#ff0000>函数名: settextjustify </FONT>
3 }; |$ l* A1 n% u1 i( q功 能: 为图形函数设置文本的对齐方式 $ O6 A/ X+ K+ X( q$ U
用 法: void far settextjustify(int horiz, int vert); 9 D) f/ d4 ~8 k% n1 x( q! M* f
程序例: </P>
0 _  s& L# ]( c) R<P><FONT color=#0000ff>#include <GRAPHICS.H>
0 e: O* t) ]$ M7 U7 v: b: h#include <STDLIB.H>
7 Q5 ?, f0 ?- x1 F  Z9 k! ]#include <STDIO.H>
5 S. E/ W- R5 J5 W" h5 {2 G#include <CONIO.H></FONT></P>; q6 l9 Z4 A" e" `1 O/ k; m$ ]
<P><FONT color=#0000ff>/* function prototype */
; Y0 Z/ a* X8 Rvoid xat(int x, int y); </FONT></P>/ v) b$ a5 H, K
<P><FONT color=#0000ff>/* horizontal text justification settings */
0 J  r+ @, v8 V; J: R$ c9 p# k* gchar *hjust[] = { "LEFT_TEXT", 4 N3 d) ~7 R) \$ i/ _6 A
"CENTER_TEXT", 2 e, m7 J/ W2 j+ ?) S* m: Y' T
"RIGHT_TEXT"
6 P1 D4 J" c) h' N1 m" Q}; </FONT></P>
2 f: x' d8 q4 N; g- \- |# @  h$ b<P><FONT color=#0000ff>/* vertical text justification settings */ 5 i1 U# `: O' d
char *vjust[] = { "LEFT_TEXT",
" e8 S' J; ^1 d* }$ C4 {9 {: M"CENTER_TEXT",
! ]" L8 G& J6 Y' Y8 G7 L9 a"RIGHT_TEXT" 2 f6 F: l' l( k# T, @
}; </FONT></P>
/ m2 S& A+ J; t( B<P><FONT color=#0000ff>int main(void)
) N. j: t2 g8 Z9 w  H& n{
. j) @" ?3 }0 z% z! _  S& x/* request auto detection */ 0 E: {3 ^- l+ z
int gdriver = DETECT, gmode, errorcode;
1 P. m! K; L5 S' u  L  r3 {* Uint midx, midy, hj, vj;
8 M8 M; J8 q( d) ]! g5 c1 V) Schar msg[80]; </FONT></P>
# Y0 Z6 z* ~+ M. u( N1 t<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 u: H8 G! \( I6 s
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>+ }7 v9 n2 ~* L  o/ j
<P><FONT color=#0000ff>/* read result of initialization */
" x. Y2 ~. G2 ?errorcode = graphresult();
* R/ v" J; h4 D' i# @, A2 n- Z. r) rif (errorcode != grOk) /* an error occurred */ , F( Q6 L3 Z, U1 _) i3 H8 [5 z8 ]. v
{ 1 Z& c9 K) J' H4 q$ U
printf("Graphics error: %s\n", grapherrormsg(errorcode));
, A: I# V8 d% A/ r1 N6 dprintf("Press any key to halt:"); ) C, v! R( \+ ^6 U
getch(); - R! g* b) m# s+ j: q
exit(1); /* terminate with an error code */
, o+ ~3 r, }4 x} </FONT></P>; B( R6 \7 E- A
<P><FONT color=#0000ff>midx = getmaxx() / 2;
& M' O3 R0 n+ `8 X7 E" Vmidy = getmaxy() / 2; </FONT></P>
& i) D( o7 c: P6 F6 k' d<P><FONT color=#0000ff>/* loop through text justifications */
/ z/ ^2 |% f1 I$ R* b1 U- vfor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++)
- E% m% T; V. M% B, K9 a. [  Wfor (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
7 M0 H7 n2 z' Q{
) E% x/ J. R* c/ y: P3 Xcleardevice();
! G( M' S6 T" ~5 C/* set the text justification */ : ?- R' l8 o% Y& F3 D' l4 a6 y5 Q
settextjustify(hj, vj); </FONT></P>) I% m6 B: J  _2 C% H; v* O
<P><FONT color=#0000ff>/* create a message string */
8 E( @8 h+ {; @sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>5 O2 a3 r& @" Y% Q, k4 l
<P><FONT color=#0000ff>/* create cross hairs on the screen */ 5 M  r* H4 V# m: n; M
xat(midx, midy); </FONT></P>
6 b+ H  q9 K- ]4 q  q<P><FONT color=#0000ff>/* output the message */
2 `" o2 o# p$ d- y0 C9 Mouttextxy(midx, midy, msg);
2 b9 ]0 H3 c, f; igetch(); 7 Y( r0 B2 g8 d! m5 m& u& W$ M
} </FONT></P>" M1 Q1 e1 {  I$ |1 W
<P><FONT color=#0000ff>/* clean up */ ( z; i: G3 ]" J! V: G+ I9 F; x
closegraph();
( Y0 a9 {/ f" _( rreturn 0; 2 U8 x# G( g# B7 D) N! ~. Y( R7 S, P
} </FONT></P>
; s7 s: U, A# y$ W<P><FONT color=#0000ff>/* draw an "x" at (x, y) */
) I# n- u! j2 Y, Nvoid xat(int x, int y) 6 k1 Q6 [- l, b8 T
{
: v2 c9 U  z9 |3 a& |" u, C0 m' Wline(x-4, y, x+4, y);
; y) E% m8 B# D4 S) s4 e, Lline(x, y-4, x, y+4);
" D4 e: n6 G$ F6 E) b} </FONT>2 \: s6 o* e0 o4 k7 R' \0 _

+ q% U6 E: v9 l6 W0 O+ h: A  W</P>% r$ f! v  g3 w- P4 p
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
6 @& v1 ~4 }! m  M( |* K功 能: 为图形输出设置当前的文本属性 % h4 y5 j  L4 W5 p
用 法: void far settextstyle (int font, int direction, char size);
+ I5 U( Z6 w$ \程序例: </P>; ?. x+ w0 a3 l
<P><FONT color=#0000ff>#include <GRAPHICS.H>
1 |- Q5 ~/ |  U* B#include <STDLIB.H>
+ j/ A  N7 ^. O#include <STDIO.H>
/ N  A# B; f3 G  {, ~" ~- B. t#include <CONIO.H></FONT></P>
) y7 v/ @$ F; \; T( W<P><FONT color=#0000ff>/* the names of the text styles supported */
  s% ~1 X& a4 L& t# Y6 O5 `3 @char *fname[] = { "DEFAULT font",
* o! ?5 i! f  F! b9 {"TRIPLEX font", - v4 D/ L0 t( Z5 V
"SMALL font",
0 H; o: \2 A8 o6 m1 r$ I"SANS SERIF font",
! K% Z3 y# _5 e- V& H6 A& z"GOTHIC font" # }2 U# d8 o! g9 \3 h
}; </FONT></P>
' ?: v0 ?( ~7 }; }0 M<P><FONT color=#0000ff>int main(void) 9 @( p  _2 T" Z; U/ X2 N/ F2 g7 R
{ # h6 S; b6 k6 R
/* request auto detection */ 7 E5 M* {8 D9 W0 W* ]; S
int gdriver = DETECT, gmode, errorcode; * D2 `) B$ k# J& S7 o
int style, midx, midy;
" j& _$ b& ?- ?1 s* Y; m& r; Z! \int size = 1; </FONT></P>1 I: U6 g8 z! k! s4 @# M
<P><FONT color=#0000ff>/* initialize graphics and local variables */
8 Q/ F5 B* [: h2 Z# Hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
0 z  i. @. Y& h* O6 G<P><FONT color=#0000ff>/* read result of initialization */
4 @2 [, p5 T+ t) [7 Rerrorcode = graphresult();
, \  j/ o- E6 I' Cif (errorcode != grOk) /* an error occurred */ ' F( F. l6 H5 Y. u6 ^; _
{
; j8 ^* a& h3 K5 h0 P: ^printf("Graphics error: %s\n", grapherrormsg(errorcode)); 6 ^. G5 v4 b) b% L! i* |; P$ a/ s
printf("Press any key to halt:"); 4 g# c8 a# `. k% a& _! ~( ^7 M
getch(); 0 ?$ ~0 @7 ]' ^  i9 N% A" Z, h
exit(1); /* terminate with an error code */ " |6 R( A. |" P6 \9 I, \/ G# H; m" l
} </FONT></P>
( z, d7 f* Q% ?/ c/ e9 ]  ?- H0 h<P><FONT color=#0000ff>midx = getmaxx() / 2; / u4 e; n/ l9 A) C% q/ L' w8 d
midy = getmaxy() / 2; </FONT></P>
9 |8 q. L8 x! T) ~# V$ P<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
# x5 g' u# Z/ R, E<P><FONT color=#0000ff>/* loop through the available text styles */
2 k$ `- k" C+ v9 _+ U  i6 Z& zfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
7 a3 y, O# G! A3 \0 R$ F0 }- w{
8 r; g! d* }# Q+ L% ocleardevice();
  P( a+ ]& k8 Z6 N: rif (style == TRIPLEX_FONT) ' B/ f3 t5 l: \6 }  J0 a5 `2 |/ i
size = 4; </FONT></P>1 D1 k, |' a' A( }' f
<P><FONT color=#0000ff>/* select the text style */ 2 j! S) Z7 \7 _6 P0 W
settextstyle(style, HORIZ_DIR, size); </FONT></P>) U1 E6 ~4 O) j0 N3 b; a9 H, ]
<P><FONT color=#0000ff>/* output a message */
7 a' V& E( _% ~7 e- mouttextxy(midx, midy, fname[style]); ) |1 e1 n8 K5 K% F
getch();
4 U) a8 }) |! q" I9 T5 s8 S} </FONT></P>
  i- z3 R! K6 N7 w<P><FONT color=#0000ff>/* clean up */ + V5 O% z, M  f+ i% {" u
closegraph(); " I. _" l9 X7 K1 j, O
return 0;
9 m2 ?0 T; X7 T- k: L}
8 ?' Y: ]- _6 o% L, x</FONT>
/ }! {/ J3 O' J+ ~0 D</P>
" ^$ a8 @7 W) I4 a: v& }<P><FONT color=#ff0000>函数名: settextstyle </FONT>
5 k( u* [! I! t6 O3 l/ |- ^5 m: i功 能: 为图形输出设置当前的文本属性
( \" x! x  x7 o用 法: void far settextstyle (int font, int direction, char size);
; A0 x0 S* i7 U6 f. _' w程序例: </P>
) y3 I% F. K3 R4 W2 |& B<P><FONT color=#0000ff>#include <GRAPHICS.H>9 S& [' |0 v. K) E3 N
#include <STDLIB.H>
$ X! d0 V$ J9 L" b1 M; ]#include <STDIO.H>
8 g$ L% Q3 d% G! T#include <CONIO.H></FONT></P>
( n1 }/ |2 }$ E& Z7 ^2 |9 |" l<P><FONT color=#0000ff>/* the names of the text styles supported */ ; R. q# J! P% `% P7 A1 z5 ?0 S
char *fname[] = { "DEFAULT font", # n7 k; {) B& w% g
"TRIPLEX font",
, m0 s% S$ Y( M2 U! x/ O2 K& r"SMALL font", 2 H8 B; C' j/ X9 l! X
"SANS SERIF font",
( X* ^/ `& a$ R; s"GOTHIC font" 4 _' @7 ^& o$ G, j; l8 T" ^
}; </FONT></P>) e8 ^- ^) {+ m
<P><FONT color=#0000ff>int main(void) - J# f" U2 G1 ~
{
# z! L/ w" I+ B$ w- E( S4 w' d/* request auto detection */
8 Q! ?: Y8 l4 t7 ~int gdriver = DETECT, gmode, errorcode;
; i, O6 Z( j: O' _! E% C+ L& S! N4 R& Xint style, midx, midy;
  \* D2 q2 ~6 u, _9 cint size = 1; </FONT></P>; C; u/ Z4 v7 Q1 p, g
<P><FONT color=#0000ff>/* initialize graphics and local variables */ % s8 I1 _; b# ?
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  B) S9 n% v! t2 @& Q1 p$ {  z0 I
<P><FONT color=#0000ff>/* read result of initialization */ $ X; o4 }5 J" R" n. r
errorcode = graphresult();
  z$ `' ~6 h% iif (errorcode != grOk) /* an error occurred */
4 {! B5 V1 r" J6 m  g5 r{
# c+ W; Y+ q1 L7 ^printf("Graphics error: %s\n", grapherrormsg(errorcode)); 1 z* f4 }0 I* s. p6 A/ X
printf("Press any key to halt:"); : p! v0 Y1 j) [  x
getch();
+ l2 b! N4 U- F. D" cexit(1); /* terminate with an error code */ ( g6 Z' N. w. E( b# `9 I
} </FONT></P>5 v4 |! O" i4 ^4 o. [; x
<P><FONT color=#0000ff>midx = getmaxx() / 2;
! B; d5 `0 j0 e9 V" Y1 n7 {midy = getmaxy() / 2; </FONT></P>6 d/ ^# w9 b/ F% Z2 E% Q3 Q
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
- L" n$ @7 T5 a6 A3 Q6 r<P><FONT color=#0000ff>/* loop through the available text styles */
; \: {% Y- I* \1 V: p( w" wfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++)
, h) x  S3 M& k{   e8 R8 Y; L' y" @
cleardevice();
* Z: A* x* C0 }" w% Wif (style == TRIPLEX_FONT)
0 l7 v* }6 Y/ G' K% {* s- Zsize = 4; </FONT></P>
$ ~; M& |! T5 g: ]* g4 p<P><FONT color=#0000ff>/* select the text style */
, [) `+ F( `0 Z  O0 Wsettextstyle(style, HORIZ_DIR, size); </FONT></P>
/ @9 `% f" Q2 l' Y2 c' L% ?6 v) \<P><FONT color=#0000ff>/* output a message */ 2 \; x4 n5 R/ Z; `
outtextxy(midx, midy, fname[style]);
2 r3 r! M3 S  egetch(); 3 z/ L! W4 R& j
} </FONT></P>6 }! o3 D$ y  ]0 v  O
<P><FONT color=#0000ff>/* clean up */
# q2 y1 [% s" {0 ]- }9 o& @- h& Zclosegraph(); ' _$ \- F2 N$ B! W7 O) q
return 0;
2 a" n5 l8 K! `& V5 s9 p} </FONT>
. U0 G0 L3 e- f4 n& K2 h' D  Q4 }( S9 H; o" n- n
</P>
! ?. }9 o0 X4 J+ r) G$ B6 I9 M4 G" L<P><FONT color=#ff0000>函数名: settime </FONT>
; f+ a; n2 J) }6 n/ P1 X功 能: 设置系统时间
- @3 X2 U. [; ]& p+ q2 t用 法: void settime(struct time *timep);
# s3 P/ Q* k1 d0 k" B程序例: </P>' ~  G: E9 h: m$ s& P2 P" z7 F
<P><FONT color=#0000ff>#include <STDIO.H>
' a- U5 Q% Z4 ?5 W1 J' f0 D#include <DOS.H></FONT></P>
0 F& a8 t0 F; f3 t<P><FONT color=#0000ff>int main(void) - f6 S  ~) O5 t* _* }
{
! F+ `" t4 X& z3 }) tstruct time t; </FONT></P>" d7 T6 g: r4 p" N, v% s
<P><FONT color=#0000ff>gettime(&amp;t);
2 w5 v( f; G% W9 I4 {8 y. P5 Cprintf("The current minute is: %d\n", t.ti_min);
2 }" o# ~0 B% y  }6 X8 uprintf("The current hour is: %d\n", t.ti_hour);
- D  y1 p5 v  pprintf("The current hundredth of a second is: %d\n", t.ti_hund); 6 a! X* L; k( g9 G: C, i: V
printf("The current second is: %d\n", t.ti_sec); </FONT></P>
3 z2 Z) B) s4 X( {" X<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
9 n  a7 g0 ?7 t' It.ti_min++; ! B/ b6 b( I0 n( ~! d
settime(&amp;t); </FONT></P>: @- Z% h' d  S: T+ C
<P><FONT color=#0000ff>return 0; ! n, c# r: K) h3 e3 n: V' L# s9 S
} </FONT>3 ^6 O. R- X  O/ @0 F( w! `9 f
! L' d; C1 m; K6 h; y! |
</P>% S' ]7 b/ _3 l; ]/ P8 j2 J
<P><FONT color=#ff0000>函数名: setusercharsize </FONT>( E1 D. W2 F, s$ G
功 能: 为矢量字体改变字符宽度和高度 - `% v: A% F( q
用 法: void far setusercharsize(int multx, int dirx, int multy, int diry); 7 @3 ^5 y$ j0 b5 l# p  k
程序例: </P>4 P; _( z/ U9 O8 o, u4 j/ x* F. l& c% _
<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 e# n9 v7 w* Y$ p#include <STDLIB.H>7 Q% `: Z- C: o) B4 T! X  t3 X9 D
#include <STDIO.H>
, w4 q# n. U+ h% G( o0 E0 h#include <CONIO.H></FONT></P>1 S; f: l' w5 z; G. h
<P><FONT color=#0000ff>int main(void)
% ]" E* s9 |$ _$ u- O1 o{
* |4 H" O4 S" @  Y/* request autodetection */
+ H5 m: D* Y1 _- M1 q" yint gdriver = DETECT, gmode, errorcode; </FONT></P>. O4 s7 Q4 o5 ]: \  b7 x1 L: q7 @
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 Q+ a0 O+ j$ R" F" d0 y3 Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
( c3 C) p. l: a8 A<P><FONT color=#0000ff>/* read result of initialization */
2 K8 A* D( ^) f8 E# berrorcode = graphresult();
- u" G1 G0 ]! \/ [9 O5 V$ Nif (errorcode != grOk) /* an error occurred */ , _- w: q3 A- M$ ?# g
{ ( z0 ~9 K* Y% n/ c
printf("Graphics error: %s\n", grapherrormsg(errorcode)); 5 I0 [# F- E4 q+ ]! K: `6 Y% |
printf("Press any key to halt:");
/ a& ^: G, U+ O! F, z* jgetch();
. t4 o( o# c0 [" \$ @exit(1); /* terminate with an error code */
. J+ J& _: _: \} </FONT></P>
6 X" r2 c" |' z! _4 a<P><FONT color=#0000ff>/* select a text style */ $ f/ A+ d2 D1 A- J7 G# {; x- _
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>2 _/ R5 R' j4 w# T3 A
<P><FONT color=#0000ff>/* move to the text starting position */
& s8 Y3 [9 r/ _: \moveto(0, getmaxy() / 2); </FONT></P>
1 F+ h  ]3 \3 M1 `: `" s% g<P><FONT color=#0000ff>/* output some normal text */ : q7 K+ l- T' c1 ]+ S; S
outtext("Norm "); </FONT></P>
8 t2 T0 Z3 ]$ m: R<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ ; U6 L. F- @/ f( e
setusercharsize(1, 3, 1, 1);
/ `% T3 B1 R* q* [1 C9 Douttext("Short "); </FONT></P>" Q! @+ {( P+ p0 w# ~5 ]
<P><FONT color=#0000ff>/* make the text 3 times normal width */ ; E4 M. z! k3 c3 D$ _9 ]7 f8 M
setusercharsize(3, 1, 1, 1);
  n7 R/ Y: M- u% Z' Z9 R8 o) ~4 h: Touttext("Wide"); </FONT></P>
$ p0 D, P0 i3 E0 a  e<P><FONT color=#0000ff>/* clean up */
8 q1 y0 X" X9 A1 i5 ~1 s% v2 pgetch();
4 t0 [- e7 l7 x+ r( J5 m! P, W& Hclosegraph();
0 S' g& u9 A* q6 S) Areturn 0;
$ }2 A" p4 j, G1 u# E: s* ]; T  R+ {} </FONT>
" r$ I! R8 w% Y0 `# `& T  I# p9 k</P>
" N8 D  w% s# C) w<P><FONT color=#ff0000>函数名: setvbuf </FONT>( b/ O1 z/ V1 e2 @6 O8 s. e
功 能: 把缓冲区与流相关
" z# O+ ?: J; O7 V. n/ y' T用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size); - m) i% u; d3 z1 }( T- B
程序例: </P>- r" I4 Z9 \) B
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>
5 @8 D# W+ V- R6 J# K9 `% Y9 c<P><FONT color=#0000ff>int main(void) 5 b% {. Y8 _  d5 g
{
* u/ d' S: N+ c9 c* K7 eFILE *input, *output;
  d! _* K& z! }$ \5 t/ d1 u* _5 ychar bufr[512]; </FONT></P>
+ q% w1 w3 ~* c! U8 `7 c# k# _2 ~2 S<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
8 A, e, I0 c! T6 F, loutput = fopen("file.out", "w"); </FONT></P>
% X4 P* D5 x& l<P><FONT color=#0000ff>/* set up input stream for minimal disk access, 7 l4 F' x1 M$ A  _* f- K2 ?
using our own character buffer */
/ R( u; @0 W3 N9 j) |if (setvbuf(input, bufr, _IOFBF, 512) != 0) " w4 i4 \: J) F4 f) O* L
printf("failed to set up buffer for input file\n"); 4 i" s9 ]1 p8 f
else
  {# D, q* ^4 p6 P9 ~: Z2 mprintf("buffer set up for input file\n"); </FONT></P>
& T/ v# W/ L" F/ o<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
" u, P# ^/ ]( e. |& ywill be obtained through an indirect call to malloc */ , u1 j; [7 V) ^9 |$ q7 v
if (setvbuf(output, NULL, _IOLBF, 132) != 0) 5 |+ Q; U+ ?' |9 R9 y8 [
printf("failed to set up buffer for output file\n"); ) i: S( h# a7 ?7 I2 }$ n) u
else
$ J4 T9 j' [0 z+ b( @; _% Fprintf("buffer set up for output file\n"); </FONT></P>
$ h5 \% ~0 W( k<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
1 p+ G9 }! R+ }2 c0 l<P><FONT color=#0000ff>/* close files */ 0 E/ J" c( Q3 b# \8 o
fclose(input);
/ _9 B/ K6 \% p# b5 lfclose(output);
- J8 Y/ v& D3 y" \  treturn 0;
# w, J- P0 t; o} 1 C8 S9 x/ r! o9 [; C
</FONT>
/ Z2 T6 f# t$ e* ~; U# n) p
9 T) F9 J9 o: R, z1 R. f</P>
- ~# I% A  ^  K5 v<P><FONT color=#ff0000>函数名: setvect </FONT># q0 d+ R' [+ n5 T' @" w/ i
功 能: 设置中断矢量入口 ! @- b* `5 {, g0 y9 s( O% u$ Q- Z: C
用 法: void setvect(int intr_num, void interrupt(*isr)()); " x1 n: t0 n4 E* U, B$ i
程序例: </P>* _9 Y( Y* W, S& N0 Z# W
<P><FONT color=#0000ff>/***NOTE: : Z  J. I& D* @. q0 I" L* Y
This is an interrupt service routine. You can NOT compile this 7 v6 x/ U( Y3 z/ F1 w
program with Test Stack Overflow turned on and get an executable
( i. q6 W  U5 {8 Z3 |/ r, Ufile which will operate correctly. */ </FONT></P>' j6 g9 G/ E9 b8 k; _2 e" d
<P><FONT color=#0000ff>#include <STDIO.H>) W! E% w0 g$ D% c- \
#include <DOS.H># Z& T; c4 ?8 C
#include <CONIO.H></FONT></P>& h% `/ `. _" {
<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>6 M0 U+ D; Y7 |6 |3 U% J& Q: N
<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
7 O2 Q" _# S, s6 q* Q<P><FONT color=#0000ff>int count=0; </FONT></P>
0 Z( T+ B8 A- b! r0 j: D: r<P><FONT color=#0000ff>void interrupt handler(void)
$ T  j, O6 o$ D/ H& F{ 7 j3 [- H8 C- k' `+ P
/* increase the global counter */ 5 i4 o2 i3 ^0 |2 h* \0 G
count++; </FONT></P>% f) p! t; [' m2 e2 O# E
<P><FONT color=#0000ff>/* call the old routine */
1 V  B4 H3 t: Y% `- ~# M) F  ooldhandler();
/ L# T3 B! T- u. }0 x+ Y* d: v} </FONT></P>
  H7 x  X+ a% A) a9 J! U<P><FONT color=#0000ff>int main(void) % f: d0 f2 i" B
{
. L8 w8 _+ f& C0 `/ d3 c- j/* save the old interrupt vector */
( [+ o3 ~7 C% }) Voldhandler = getvect(INTR); </FONT></P>7 S) f1 `3 Z2 b) ~
<P><FONT color=#0000ff>/* install the new interrupt handler */
( f- a: p& x$ L9 X3 Hsetvect(INTR, handler); </FONT></P>* u3 x* v- d: ~& N
<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
: O" d4 @! }. W7 t. Gwhile (count &lt; 20)
8 t8 k$ `* Q* t+ @9 c0 e' P5 wprintf("count is %d\n",count); </FONT></P>; M5 @$ s( k- P: E  i' r5 {
<P><FONT color=#0000ff>/* reset the old interrupt handler */
: w3 i8 z$ h* Y" n# t: _. v3 [setvect(INTR, oldhandler); </FONT></P>( i1 }( ~4 }# w5 E; \( R
<P><FONT color=#0000ff>return 0;
0 `0 S3 e# ]/ Q) `& u2 E}
! U8 Z7 S+ ~& U& f</FONT>
' O8 I7 c! @# u- j* g& z8 H</P>
" F( l9 K  d& X8 Q<P><FONT color=#ff0000>函数名: setverify </FONT>
/ e. D0 k, H. R: R* V功 能: 设置验证状态 9 z5 q) Q1 Y. s+ {% \" v
用 法: void setverify(int value);
9 z, q8 F6 P7 q: U# X( V程序例: </P>. i$ R! c% b% c3 \
<P><FONT color=#0000ff>#include <STDIO.H># n! g' N! e$ w) }: y8 @/ }& ]
#include <CONIO.H>
* z% z" x; X4 e. f9 @#include <DOS.H></FONT></P>
6 {$ K; L+ T& M+ w6 B. ?<P><FONT color=#0000ff>int main(void)
9 `5 }$ U4 _* e- h{
: s- z0 E8 D6 {1 Nint verify_flag; </FONT></P>
% g, N# ~+ ], J7 j<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
0 U, V3 _- S  |4 zprintf("Enter 1 to set verify flag on\n"); </FONT></P>
3 U8 Z5 b5 m: {" g' [7 j& Y<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>  Q4 ^: }* g6 V, p  f+ m
<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>
8 |6 p+ a9 ]9 \1 }<P><FONT color=#0000ff>if (getverify()) ) z! S4 F2 K: O, q9 `' s7 l+ |* Q1 A
printf("DOS verify flag is on\n");
4 e( f! J4 x: v6 |% t5 v& s" yelse
: u. d" r& _: k/ g- q4 t1 Eprintf("DOS verify flag is off\n"); </FONT></P>5 r; |1 R% z$ }! Y4 t
<P><FONT color=#0000ff>return 0;
) b7 x+ G# d; P' E  s) o5 p' b} + V. m' V. g0 C. P& U$ Y) ^
<FONT color=#ff0000>
2 t( m; ~* u! ]5 M! W" T</FONT></FONT></P>
3 m8 t) F" q! ]: u1 |, h2 K+ |# B( c<P><FONT color=#ff0000>函数名: setviewport </FONT>
) l+ I3 o& E* a1 o9 S9 E功 能: 为图形输出设置当前视口
4 K$ h# m1 N$ X用 法: void far setviewport(int left, int top, int right, - {; t* Z, s) w7 B3 h  n1 Q7 B
int bottom, int clipflag);
. Q! {) N# y7 B4 K# x0 X2 U程序例: </P>2 W$ f- c! Y5 q" I1 y. y7 `  b
<P><FONT color=#0000ff>#include <GRAPHICS.H>0 Q, n8 F$ N; N) x1 A* W
#include <STDLIB.H>) u8 p& j; V' P7 i" y3 G* C
#include <STDIO.H>  |8 [+ M9 r" [: u
#include <CONIO.H></FONT></P>
1 y' P" Q  O6 r% w7 F( g5 ~  M) V3 a, e<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>
: t9 b3 o( `5 e5 ^<P><FONT color=#0000ff>int main(void)
. i9 |3 P% U7 h8 o5 X1 @2 }{ ! z3 L6 h7 ^7 d; h3 R$ z# S/ ^+ l" `: p* f
/* request auto detection */
/ @( O. y$ v: W3 M2 K9 \int gdriver = DETECT, gmode, errorcode; </FONT></P>- _1 `' I9 v5 J' d+ I9 K: V
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& }( N7 {9 s- T2 dinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 ]9 a3 A# v- b2 c  X
<P><FONT color=#0000ff>/* read result of initialization */ $ ^3 h+ u! H$ Q* ^  L/ r3 |
errorcode = graphresult();
% v0 K* Y0 z1 ~if (errorcode != grOk) /* an error occurred */ 5 j" l8 C) T: t$ |1 ?$ G
{
! t, Z+ J; M& Vprintf("Graphics error: %s\n", grapherrormsg(errorcode));
6 E! _) L& r7 F* j' iprintf("Press any key to halt:");
$ V' ]+ L0 [) A' y7 E) v1 J0 v; Hgetch(); 9 Y' l* R! l/ `( R1 \
exit(1); /* terminate with an error code */
9 r, R6 v( _, l/ l- `3 |4 H} </FONT></P>
& w' ?5 X- q& [" h1 p8 o! i<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>7 a4 L$ t6 c! G! c9 l) [0 M
<P><FONT color=#0000ff>/* message in default full-screen viewport */ " U. y) R, B! @! L/ }
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
% t: i" I9 ~* T5 {<P><FONT color=#0000ff>/* create a smaller viewport */ 7 b& E4 z& p1 K7 W: e- }
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>; z6 g: L3 G- e; W' H5 y6 L' h7 e! ]
<P><FONT color=#0000ff>/* display some text */
2 u' y* q# z5 ^1 Wouttextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>0 e! b3 @3 y5 i1 I) u
<P><FONT color=#0000ff>/* clean up */ 1 G0 c8 l* B4 _1 R' y+ N
getch();
8 G6 M. k5 R/ \# z8 F8 A" lclosegraph(); # E2 g! ]  G% \+ X
return 0; 6 a  p' [; U: S
}
$ B/ b0 C5 ]) N. N8 J6 R$ Z</FONT>
* k. p2 k, q5 n0 z( ^2 z- V6 {</P># h' @& e5 A6 X# F. n
<P><FONT color=#ff0000>函数名: setvisualpage </FONT>+ Q# K& W5 P  x7 K& M; R
功 能: 设置可见图形页号 : _& j  W$ D# c& ~
用 法: void far setvisualpage(int pagenum);
( X7 Q( W. x+ s/ ?  @! m6 C9 C- I& O程序例: </P>
3 I& \# i. t4 D' L<P><FONT color=#0000ff>#include <GRAPHICS.H>5 q8 B' u6 o$ B6 m, M
#include <STDLIB.H>. G" h" E% I; V+ ~4 v' T
#include <STDIO.H>
, u, M8 s) r- ]4 V* G# n#include <CONIO.H></FONT></P>4 |) c! h, @- L; G  s) }
<P><FONT color=#0000ff>int main(void)
" D& i8 U. p% ?; O6 W2 a# i{
4 [4 ]# q: C# i1 w/* select a driver and mode that supports */ 6 w: \: ~' a. e8 e  ?2 [: F
/* multiple pages. */
; z7 @! N5 \' A# Fint gdriver = EGA, gmode = EGAHI, errorcode;
& S9 s/ Z. G) z  cint x, y, ht; </FONT></P>
/ g1 t9 _0 h8 Z1 O4 x<P><FONT color=#0000ff>/* initialize graphics and local variables */ ; f2 I9 n. u: S  l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 U' p$ p+ q9 ], l& T6 \, b# m* F
<P><FONT color=#0000ff>/* read result of initialization */ ! |) l3 l1 L3 U0 d* a+ p# Y  s* @; ?# a
errorcode = graphresult();
5 P, \  K- C. j8 G$ O: C; B/ j- Q) [if (errorcode != grOk) /* an error occurred */
0 `. ~$ ?, j+ v, z% [7 F8 q{
% f  D/ c0 O/ ?! U- o# jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); " e  N3 n0 B: h8 M. n
printf("Press any key to halt:");
, G0 J  x6 M( Dgetch();
0 @6 S( p! T  J( P  Gexit(1); /* terminate with an error code */
) v" Y1 u6 T# e3 L/ N# ~8 b. E} </FONT></P>
7 h8 M; d4 V4 [( m4 a3 W<P><FONT color=#0000ff>x = getmaxx() / 2;
/ z8 }9 x! o( {4 g+ S! Wy = getmaxy() / 2;
* h! I% w- Y1 U- Z) {ht = textheight("W"); </FONT></P>
% k/ t9 Q/ `8 H, A" A" s<P><FONT color=#0000ff>/* select the off screen page for drawing */ ( t% H. Y9 v& x# Z, c5 T9 A% ~
setactivepage(1); </FONT></P># W  V% D2 X& F; Q- ~: c
<P><FONT color=#0000ff>/* draw a line on page #1 */
7 l9 y! {( K  lline(0, 0, getmaxx(), getmaxy()); </FONT></P>
& g2 Z( t& _1 F* V<P><FONT color=#0000ff>/* output a message on page #1 */ - w5 D: {& ^4 t2 I0 `1 J
settextjustify(CENTER_TEXT, CENTER_TEXT); ) F# K/ u# d' I3 T4 h
outtextxy(x, y, "This is page #1:"); , E6 r3 n) ^/ P2 S4 L
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>* Q. o6 k* o/ V6 x$ D
<P><FONT color=#0000ff>/* select drawing to page #0 */ ; P* c3 d% A* r' d3 W
setactivepage(0); </FONT></P>- u/ p* Z4 w8 D2 g+ ^
<P><FONT color=#0000ff>/* output a message on page #0 */ / P: f/ B2 o) w2 T! I, K- ^  F# l# r
outtextxy(x, y, "This is page #0."); ' F' \% }* m1 Y2 N* ~- J. B
outtextxy(x, y+ht, "Press any key to view page #1:");
/ B& W* O% l1 i' D! mgetch(); </FONT></P>
( O3 B% Q3 G  C# c' f<P><FONT color=#0000ff>/* select page #1 as the visible page */ 4 T  T! u$ x  V2 V: W( A' ?
setvisualpage(1); </FONT></P>
. j8 j+ k) [8 }& _( O3 S<P><FONT color=#0000ff>/* clean up */ ' [: f. V: J9 _; x
getch(); # s  q* \1 \9 P0 h
closegraph(); % `& R8 |* S" M4 P  d/ K7 p
return 0;
. i3 l: F3 z" n9 R& K* H} </FONT># x; Q3 u' ^/ d% N) U. H

8 ~/ {7 P0 d' c</P>; d% t# W) s$ W: ]% o6 a. i
<P><FONT color=#ff0000>函数名: setwritemode </FONT>
) R% d) s" j5 l. o功 能: 设置图形方式下画线的输出模式
0 w: v, ~9 Q/ C# |" ?9 h用 法: void far setwritemode(int mode); 4 s; v( u1 [; F. x3 v* N0 P. a
程序例: </P>
3 c+ ?( f: |1 R; ]<P><FONT color=#0000ff>#include <GRAPHICS.H>2 R/ U4 r. i9 N1 G2 w
#include <STDLIB.H>
% O6 _; P) |: H#include <STDIO.H>
" o4 l3 O2 p+ ~; j. ~#include <CONIO.H></FONT></P>
& s/ l" K5 D) l  g! o" b+ U9 ]<P><FONT color=#0000ff>int main() - e6 T, }( F2 A% r; B6 n
{ & g+ j7 v* P1 ]
/* request auto detection */
- G8 ~. b3 f- Z" }# Yint gdriver = DETECT, gmode, errorcode; ; }0 j: |# }1 _5 s; c7 s3 x
int xmax, ymax; </FONT></P>0 f0 d( w* m4 k3 J
<P><FONT color=#0000ff>/* initialize graphics and local variables */
5 P6 L" ^( ~  F, F: Yinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 R7 C6 l3 }# G8 W2 D1 e/ G- E' T, ~
<P><FONT color=#0000ff>/* read result of initialization */ ; W* W' M2 d9 S4 ]4 x# o
errorcode = graphresult();   {4 n; ?- m. E
if (errorcode != grOk) /* an error occurred */
! m- b& `4 y7 s9 m) w{ " W, R1 m$ c( A; @, J6 g, j
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 `. }8 @8 ]' F2 D. |' ]  aprintf("Press any key to halt:"); 3 {8 O9 t( Y6 x' |! ?# B
getch();
! r0 N, @6 ~* c: X* B2 ~+ Vexit(1); /* terminate with an error code */
$ J% q4 j+ n0 U5 B} </FONT></P>7 v# q" r' @7 C$ R$ U5 b6 n' ?
<P><FONT color=#0000ff>xmax = getmaxx(); 8 N9 C3 k2 E7 U9 Y- M% a
ymax = getmaxy(); </FONT></P>/ {0 x1 Y  h* N+ p! Q' T* \! L
<P><FONT color=#0000ff>/* select XOR drawing mode */
/ l- M" f* C9 D- ]setwritemode(XOR_PUT); </FONT></P>
5 e: u4 Q# C! q<P><FONT color=#0000ff>/* draw a line */ 4 f5 Q: F+ C& D: p. D6 W4 @
line(0, 0, xmax, ymax);
8 j4 F: W# x/ k) N6 |getch(); </FONT></P>: m7 K9 o4 N3 k8 y# K7 q9 c4 T
<P><FONT color=#0000ff>/* erase the line by drawing over it */   @% o6 |( H. L% w" y( {6 G: X# I
line(0, 0, xmax, ymax);
5 S, {0 v' B* Ygetch(); </FONT></P>
: }6 o  Q+ _1 a, q+ E0 k0 ^<P><FONT color=#0000ff>/* select overwrite drawing mode */ 6 u$ C& k* s1 P& K8 A6 P
setwritemode(COPY_PUT); </FONT></P>9 Y' l. s  u, n/ n) W
<P><FONT color=#0000ff>/* draw a line */ + N. K5 l' [+ P3 x9 a
line(0, 0, xmax, ymax); </FONT></P>1 Q+ E& _5 n9 U1 r
<P><FONT color=#0000ff>/* clean up */ 1 Z0 H# E" ?9 D7 g# K. R
getch(); ) n; ^* d2 v% S4 e3 D
closegraph(); 0 o$ g5 I1 h3 I* q8 S5 L
return 0; : C! d0 ?( q/ A6 y2 p; `7 q& f$ H
}
- k1 [$ Q! e) R; ]4 t  U/ t5 U</FONT>
/ `! D2 O* A- c</P>
, _. j2 @2 C- U4 Y<P><FONT color=#ff0000>函数名: signal</FONT>
( B8 a1 N7 V4 z  t功 能: 设置某一信号的对应动作 ' x3 B+ }* `1 d6 g- J. ?
用 法: int signal(int sig, sigfun fname); $ P; b! t9 s4 S! m* Y% ?
程序例: </P>
( r$ ]6 [/ l! C* M! H3 Z$ E. ~<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE, " o9 {3 }& E9 _5 b6 W
catches an integer overflow condition, makes an adjustment ) Z% d8 n5 H+ A, v% @) W5 l
to AX register, and returns. This example program MAY cause ) Q9 X5 @4 B* }" ~; H6 a1 e1 y2 g9 [
your computer to crash, and will produce runtime errors " Y& O2 h6 q# k6 r
depending on which memory model is used. 7 b" I8 p7 x' {* N
*/ </FONT></P>% Y3 O* l! }0 l  h- o
<P><FONT color=#0000ff>#pragma inline
* d8 m0 Q6 S( {- W' V6 S: w) v7 V6 e#include <STDIO.H>
0 ^- k8 {5 }: b3 `1 m3 z#include <SIGNAL.H></FONT></P>
. `0 n( o+ \6 _' \/ p( v* H<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
1 Q3 M7 g& s) l" u{
3 @) V. r' Q8 D; k) lprintf("Caught it!\n");
. p! f% q# F! _, b*(reglist + 8) = 3; /* make return AX = 3 */
9 s4 W5 z. I( ]" a3 A' c} </FONT></P>" `8 g: I* Q4 i" P( x9 G5 Z1 B
<P><FONT color=#0000ff>int main(void) % o" n' D) O! k  k# ]: c
{ . K( g+ u6 g2 S- ?4 ]- q$ m, `
signal(SIGFPE, Catcher); , i  D. k; u! I0 ]/ m5 g! b4 M
asm mov ax,07FFFH /* AX = 32767 */
- U, {' k! \* Y) Easm inc ax /* cause overflow */
2 M: \) m1 ?$ g8 Dasm into /* activate handler */ </FONT></P>- C  b4 y# a, l  N+ _4 B
<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, : k- K1 F/ B" j- J% g
there would have been another exception when the next 'into' : E$ K; M/ o+ I
was executed after the 'dec' instruction. */   ]1 I, h* I) X# K0 n: Q  ?( i
asm dec ax /* no overflow now */ ; F0 J7 y. o$ g" r
asm into /* doesn't activate */
/ z' ~2 R7 Q( F: ^return 0; 6 ^) u) R9 j0 t2 L6 @
} 1 X/ }" d& Z3 M2 m

6 I2 Z; X& B) U/ b( K' I" n
% @# Y& p! ^/ W5 r; G7 }5 q</FONT></P>
. Y( q! m0 n, @2 M% Z) t6 u6 y6 H+ u<P><FONT color=#ff0000>函数名: sin </FONT># d7 P0 e/ \$ |8 M; W4 i
功 能: 正弦函数
* B4 ]/ M2 c2 ^& d6 H& }( H用 法: double sin(double x); 9 P# r: A) r, c7 ]3 t! E& ?) I
程序例: </P>5 X: w7 j; G9 Y2 L
<P><FONT color=#0000ff>#include <STDIO.H>
+ N" @2 z; B0 f5 q2 M; k4 d  V# Q#include <MATH.H></FONT></P>( K3 o- o/ z+ c
<P><FONT color=#0000ff>int main(void)
: x6 R2 X' R* B  J: a9 g{ 8 W7 D3 P8 `/ [( ]( C' l
double result, x = 0.5; </FONT></P>5 f; g0 |2 |# A8 W. D6 O  o
<P><FONT color=#0000ff>result = sin(x); . v7 R6 N7 a* v- z
printf("The sin() of %lf is %lf\n", x, result);
+ D) h/ E7 ^2 Y3 L, M, O- r4 creturn 0; # g. r) [( \  o& }' @4 i
} : u: H' T; J: E2 `6 s

, x. B+ [- k+ I* P, `* \) L& b2 ?</FONT></P>
& \/ R+ w! ]4 b- e+ W! E<P><FONT color=#ff0000>函数名: sinh </FONT>
% r- H. ~. K+ j3 n! z功 能: 双曲正弦函数
3 K9 ]* J- h/ y5 U7 F' T用 法: double sinh(double x);
4 b" }0 F) a% E9 C4 _. x; m7 H/ x2 Y程序例: </P>
" x9 i: e7 F3 [/ Y<P><FONT color=#0000ff>#include <STDIO.H>  B  A+ B" r$ S% e3 M
#include <MATH.H></FONT></P>
! h7 B" z$ J1 @& M' I<P><FONT color=#0000ff>int main(void)
3 L" V! l/ Q: p: _{
: r; F- F: M2 G4 f0 E. c. \/ A' S* Fdouble result, x = 0.5; </FONT></P>
5 \: v2 t  X6 }: c<P><FONT color=#0000ff>result = sinh(x); 9 B7 u0 e6 r. T% U
printf("The hyperbolic sin() of %lf is %lf\n", x, result); 1 `6 V3 U9 ]& t
return 0; / F: [+ _  a7 Z5 E
}   v9 n  `- O% u6 _" f
/ k% M8 u" K( l" S7 \9 a9 j9 Q

3 Z6 l1 `1 l7 ], X- t</FONT></P>
' A& }* O: Z; U) L<P><FONT color=#ff0000>函数名: sleep </FONT>7 f# `- o& V6 P& d( `8 B9 O
功 能: 执行挂起一段时间
! \) K0 Y5 s* T/ F5 [用 法: unsigned sleep(unsigned seconds); 8 K! v1 k' l! [8 @7 Z
程序例: </P>! u( Y6 S) q- ~, B, X) s; T
<P><FONT color=#0000ff>#include <DOS.H>
, c3 }2 Q2 n, }- ^( |  h9 R* ?#include <STDIO.H></FONT></P>
8 u" ~/ h$ _3 y8 S6 y: Z1 D<P><FONT color=#0000ff>int main(void) 9 ~5 _, @$ i7 G5 G8 f( Z
{ + U" d1 P# C" U" @( g2 p
int i; </FONT></P>
! T& [* X4 ?; f: N<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
- [( ?2 _) D/ ?# \. i! u) L7 l{ / \! X+ r' K, c
printf("Sleeping for %d seconds\n", i); " h' E6 X! B. B5 s$ D5 c
sleep(i);
4 r) ?! J2 E8 [} ' H# N5 t; Q- R/ ^1 k. S
return 0;
$ `' v: S+ @3 D  v}
8 |- n$ ~9 ^: w4 \  v
  w; T: f" I( u, F</FONT>
- x+ T5 H; s% K6 o" S3 ~( o</P>
% A3 Q9 B# @6 ]7 T$ \- g/ _<P><FONT color=#ff0000>函数名: sopen </FONT>
' d% L+ N3 C, i! Q功 能: 打开一共享文件
9 R, \3 I. S2 ~用 法: int sopen(char *pathname, int access, int shflag, int permiss); " `7 N- i+ h5 H5 [: N  I
程序例: </P>' O" J, L. o. d" ?+ Q( M
<P><FONT color=#0000ff>#include <IO.H>
% @# a2 O: |/ r+ C! @. H* Q% w#include <FCNTL.H>: V0 Z4 \+ \9 n. b: Q4 u" E- c
#include <SYS\STAT.H>- N4 E1 }+ ]0 m/ B" z' x5 ?( X
#include <PROCESS.H>* v" X; `/ T1 b, o" [3 a
#include <SHARE.H>
2 a, M. i5 D, b8 e5 \: c: t3 Z#include <STDIO.H></FONT></P>1 M) B* H/ @% K) e! [  I
<P><FONT color=#0000ff>int main(void)
# j/ |9 L- ~5 L" H4 j6 }4 s{
$ J* S' z$ E  S  F- O& fint handle;
# v3 G4 P& N4 v# I" _int status; </FONT></P># w, y' b  Y# j4 w
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P># A. s9 q4 t5 R* ~
<P><FONT color=#0000ff>if (!handle) / x6 ]! a5 B, w) m
{
6 C7 ]) h& x/ t6 n5 R# ?& @3 Yprintf("sopen failed\n");
. I6 z* {2 D2 P; Y( y6 }: h9 V3 rexit(1); " G' ~9 a7 k8 d! T: y, Z
} </FONT></P>
- t/ q) i. g/ q6 k$ Y<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
0 M& A' m* t1 G$ k7 n& \if (status == 0)
! n: K# u2 X" T% U7 O3 Yprintf("read/write access allowed\n"); * l6 J5 a& r% V9 b, h# S( R
else   U8 d# Z; Q* `" Z( d: [
printf("read/write access not allowed\n"); </FONT></P>
( I' e& F/ C. f<P><FONT color=#0000ff>close(handle); - l' p2 e4 m, `0 v5 g
return 0; - y6 W8 |4 h. v6 z! c) o
}
+ U6 ?0 c* {3 H) L3 [: c
' @8 |% {" N, C. S</FONT>
4 z: N: }& h; M: F( b</P>5 r# K* a. D1 d) H
<P><FONT color=#ff0000>函数名: sound </FONT>
! m4 _$ E6 p* z3 p& I) E, {) m; }功 能: 以指定频率打开PC扬声器 3 x4 k( _- {5 }$ T; r9 t: Z/ E
用 法: void sound(unsigned frequency); 3 w: g3 P; A9 V; {$ w
程序例: </P>8 j% A- p! j5 g! I1 j' h( |
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. 4 u& R& N5 f# Q+ P3 Y
Your PC may not be able to emit a 7-Hz tone. */ $ c, u$ v: d+ u9 G5 z$ `  M
#include <DOS.H></FONT></P>
, K& u. X3 U* J0 }6 l$ j<P><FONT color=#0000ff>int main(void) 0 _+ g% [% n9 T* M
{
: _: g) S1 d- v/ z7 }sound(7);
" z7 ^7 T9 C2 L2 f, N6 Rdelay(10000);
2 }# P) z5 U* M9 G* ]nosound(); ; d+ Q0 i- U  ]
return 0; ' m; T+ Z1 O+ @1 `
} </FONT>
- t7 ~& y+ {* c" O9 T( r$ L$ Y; k9 p
* [& j' c2 Z! z! U
</P>: e, r- G% L3 _" ^
<P><FONT color=#ff0000>函数名: spawnl </FONT>& [6 u+ K$ o: G- Z: U
功 能: 创建并运行子程序
/ U4 O- i7 c$ ]用 法: int spawnl(int mode, char *pathname, char *arg0, 3 N8 B  R# j; V
arg1, ... argn, NULL);
* ?! `0 C. o' @- C; M- D- O程序例: </P>
, e- s! M0 q9 ^- Y$ D<P><FONT color=#0000ff>#include <PROCESS.H>: [: G6 r; n- N" G% P
#include <STDIO.H>
6 ~1 Z6 s; ?- v# q* x#include <CONIO.H></FONT></P>6 `6 Z! w) p( z) Z
<P><FONT color=#0000ff>int main(void)
) {/ d7 L2 s8 v8 S{
5 l0 G; [" n4 }( X* pint result; </FONT></P>0 n- E7 E, H/ c- O# G8 g
<P><FONT color=#0000ff>clrscr();
" d1 W2 W- R, k' Z/ H& cresult = spawnl(P_WAIT, "tcc.exe", NULL);
% x) s/ {4 _) v/ @: I5 H7 s  \if (result == -1) . ~# q9 H$ O  ]; T) A# t8 N& `- n: H
{
  c, |% g8 y7 _9 y9 l9 ?# D& v, W% zperror("Error from spawnl"); ; P$ P# H; I0 E0 _4 ]# K; V4 D$ l
exit(1); % S2 i' q6 r( Y  c- Y) o
} # @4 x: M# |! ?* u
return 0;
$ v0 p: z' T4 }3 d4 c} 3 l8 m$ B  F9 W9 h  d
</FONT>0 o3 O/ E/ Z* q& k" ^! z* X
</P>
2 b! `/ u% d* I4 u0 W+ c' D<P><FONT color=#ff0000>函数名: spawnle </FONT>8 l) j) P  h, l0 ?4 @
功 能: 创建并运行子程序 8 U& m3 [2 v0 n# m% T0 {) V; m$ Q
用 法: int spawnle(int mode, char *pathname, char *arg0, 8 E5 u8 v( ^: x# f* k) K$ |
arg1,..., argn, NULL);
" {' t+ ^4 Y, g  s: P) D程序例: </P>
4 D! B- D. f( \* e  m9 L<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>0 A. P' m  o9 i& v! X6 o& B
<P><FONT color=#0000ff>#include <PROCESS.H>1 ~* h' a- X# c; i
#include <STDIO.H>% A, Z# W! x- l" M" U
#include <CONIO.H></FONT></P>
, L, ^! o# p+ N0 Y6 J<P><FONT color=#0000ff>int main(void)
) I8 y3 x8 S( L2 W: l1 ~{ & M) @7 C6 g; g: h$ Q
int result; </FONT></P>
! ]- a* a  K8 m. c. ?<P><FONT color=#0000ff>clrscr(); 6 G: r2 E) e, a0 J" M
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
: e  k) w9 R/ L9 X" |7 q" vif (result == -1) 1 f1 T# s6 |5 J# V5 [5 {" s) C% k
{ . K2 m  i% P. L
perror("Error from spawnle"); : Q3 H5 ^3 l  v, K; O
exit(1); % z3 b% G3 e/ L2 f9 s2 d1 @
}
4 [  P, u* E& t, jreturn 0; . |! R4 }" {3 F7 C) J) @: c; u
}
. p0 Q. i8 {7 \6 Z* K6 b, |9 C. W% p( R

& K4 [  O, q/ x' s3 B  m</FONT></P>( _+ q4 W! R) ~6 Q; t3 ?4 U
<P><FONT color=#ff0000>函数名: sprintf </FONT>/ f* }' J) p/ e0 ^  }
功 能: 送格式化输出到字符串中
0 V$ \& C+ N- }9 [) J" N+ Y* }$ J用 法: int sprintf(char *string, char *farmat [,argument,...]); . e& k9 ^( ]0 G) U  g/ I
程序例: </P>0 v( }5 q# P' h
<P><FONT color=#0000ff>#include <STDIO.H>$ O  r0 q; w2 k
#include <MATH.H></FONT></P>
& q& q( F3 n2 b! X; `% P<P><FONT color=#0000ff>int main(void)
* B! `+ t2 u9 m  }- y0 i; r$ c{
" C1 o2 H& j4 x/ _# G/ z9 t+ \char buffer[80]; </FONT></P>( P7 X1 t5 Z# Z. O8 P# C4 U
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI);   v7 C) `3 t* @; e
puts(buffer); " X; a$ _' h* v% W# `  W0 A7 [
return 0;
. a. s' p" c: `$ A# M: \} , U! f7 T8 q9 }4 _( o* s2 f- z' \
</FONT>9 t/ I! k0 E  }# T
</P>
; M) z3 D2 o3 l' N<P><FONT color=#ff0000>函数名: sqrt </FONT>
* O# e4 }8 ~2 y( {; D. _( e功 能: 计算平方根 1 H! K! Q1 l, A" Q* \. i1 \( m2 f
用 法: double sqrt(double x); * K) t6 u1 Q2 n5 e; r
程序例: </P>5 D- _& D3 Y2 \+ l$ @+ c( A
<P><FONT color=#0000ff>#include <MATH.H>& ^" l+ a. g, a" b
#include <STDIO.H></FONT></P>  V* ]: x/ Q# ]9 s8 l& a
<P><FONT color=#0000ff>int main(void) . k3 w! J% Y. P! u% J
{ $ p5 n- a1 R" p$ a+ R9 @
double x = 4.0, result; </FONT></P>
% ?4 v; Z/ h" _3 z0 c<P><FONT color=#0000ff>result = sqrt(x); ) N" Z: }: h% G7 t% {, Z: G
printf("The square root of %lf is %lf\n", x, result);
+ L5 W& e1 j7 e# H: S. yreturn 0; & |* H8 B- v0 b, Q9 d5 v0 O
} 3 m* A. ~/ M' W8 F
</FONT></P>
) b+ o; B' t' L: d8 l/ p<P><FONT color=#ff0000>函数名: srand </FONT>
- U( f- \' n& E- o3 r功 能: 初始化随机数发生器
; q$ f$ H" O( Z' @! @用 法: void srand(unsigned seed);
; u( P# l) u, i& C程序例: </P>
- C" y. p" l1 v" L( o<P><FONT color=#0000ff>#include <STDLIB.H>
9 R  y7 Y3 A$ o6 c' o' p4 V# ?#include <STDIO.H>8 s1 A- b; p5 Y- f9 N
#include <TIME.H></FONT></P>) J' k7 h* T# W8 q1 w, X8 v
<P><FONT color=#0000ff>int main(void)
2 \% Q+ {9 z$ |; ?( T+ K0 Y{
' L1 A1 z% E% {* y+ @5 uint i; ( R; w5 ~$ \0 R  s& Z
time_t t; </FONT></P>3 o3 \- C1 s( g# b
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
, _$ M1 x: C0 `! z  g( p1 Jprintf("Ten random numbers from 0 to 99\n\n");
1 ~0 r3 b1 j( h  l+ L2 L! L6 Nfor(i=0; i&lt;10; i++)
: R* S2 }) n. Y" O- o3 ~8 x- l' Aprintf("%d\n", rand() % 100);
1 y0 `4 [6 Z6 Z, {2 Y, ~$ v& oreturn 0;
' m; G7 b0 ~+ u/ ~3 `5 \} ( A; p8 a6 f3 C9 C/ Z4 }. d+ p
</FONT>
& z' p" x/ m2 n: w/ `</P>
- }. F) v8 t( j, i+ U  n4 r<P><FONT color=#ff0000>函数名: sscanf </FONT>$ P4 U. x4 Y% H1 u9 e- `
功 能: 执行从字符串中的格式化输入 ) @; Z7 z* V" x+ j( i) M
用 法: int sscanf(char *string, char *format[,argument,...]); ! Z) W8 r5 l: y
程序例: </P>
6 t+ y9 L! {- |! q8 V: B<P><FONT color=#0000ff>#include <STDIO.H>
% S1 u& ^8 q! r7 |#include <CONIO.H></FONT></P>9 _7 T+ C+ \; a/ d
<P><FONT color=#0000ff>int main(void) 0 s1 P% P# c9 G
{ ; ]$ t! K& [/ ?# Q6 T. p
char label[20];
# ^8 v- z9 T# ?1 R) W- v% dchar name[20]; 9 B3 G7 S+ X' _% P6 @+ r; [
int entries = 0; ' `) t- N3 M+ p2 X( e0 z, j7 ~8 H
int loop, age; 2 i( ~1 R4 x. n. k# ]  W2 W0 d* g. M
double salary; </FONT></P>6 |7 ^2 \# ~( H9 H  t2 l: n
<P><FONT color=#0000ff>struct Entry_struct
/ i. Q" k( O  `% y{ + O1 y; R4 w" u( G) L# ~$ }
char name[20]; * j% M) n" F0 @: o' K. N* l
int age; 3 G1 d5 [8 S( Z. D" g  b
float salary;
( m# R; M! n  N' L. s} entry[20]; </FONT></P># ]; J9 T4 i, H+ {
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ ) K  @! b/ @. P& o; ^+ [0 H! b
printf("\n\nPlease enter a label for the chart: ");
" F0 U+ m" q5 Wscanf("%20s", label);
- A# k  `+ b9 D+ ^& ~# e$ {fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>' x$ y6 W8 X: \& Z  E" A7 o
<P><FONT color=#0000ff>/* Input number of entries as an integer */
, M2 K- v" r3 w' L, x/ ?printf("How many entries will there be? (less than 20) "); / b( s, i3 J( R' K/ V% S
scanf("%d", &amp;entries);
. }$ |: O7 z9 l. J& Yfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
' Y  e8 H& T2 T( v! ^8 F<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
+ V, [9 _# @$ u, @2 M; Ofor (loop=0;loop<ENTRIES;++LOOP)
! U& ?2 [8 t- a { + v9 t- @& M) h' r4 P* e
printf("Entry %d\n", loop); ) M) A8 a1 [, d, f8 i4 \% R
printf(" Name : "); + y$ L$ k7 f; T
scanf("%[A-Za-z]", entry[loop].name); 4 J. |! @" I; v: [. ~' P
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P># {! s0 S" G5 \" @
<P><FONT color=#0000ff>/* input an age as an integer */   V( m8 A) A! V' k
printf(" Age : "); $ a+ k1 D% e/ J
scanf("%d", &amp;entry[loop].age); 7 X7 l1 g% G8 l
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>, b: k+ n5 C0 a1 N% K* Y0 i' y
<P><FONT color=#0000ff>/* input a salary as a float */ 1 D7 w  s! d  @- E
printf(" Salary : "); + R7 @$ p) s: \/ H
scanf("%f", &amp;entry[loop].salary);
6 [) _- \, F3 A4 n# Efflush(stdin); /* flush the input stream in case of bad input */ 3 ~* U' k0 Z: n4 e0 }
} </FONT></P>/ S) }4 H& W! d% h* T9 J2 t
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
' H4 u$ `$ Y( _- H, w0 uprintf("\nPlease enter your name, age and salary\n");
- C8 ^1 T  f2 S- tscanf("%20s %d %lf", name, &amp;age, &amp;salary);
/ W, w, |  b$ Q& v- X</FONT></P>
( k" N- S6 [* ~" s. C9 d<P><FONT color=#0000ff>/* Print out the data that was input */ 5 B* e3 ~  w: L0 V) l0 @
printf("\n\nTable %s\n",label);
8 i/ C) Q4 v- E3 O0 U9 g2 P1 N. q# `printf("Compiled by %s age %d $%15.2lf\n", name, age, salary); # Q, Q/ d6 _, b6 |0 ]: D' N. {
printf("-----------------------------------------------------\n");
* u4 Z- J& }$ w# F+ n+ gfor (loop=0;loop<ENTRIES;++LOOP) + B/ _" z6 ~. ~: B: A% a; N' U7 o6 m
printf("%4d | %-20s | %5d | %15.2lf\n",
3 f: X, _5 U4 Eloop + 1, - V0 I3 V" W6 M7 m1 p& E& l
entry[loop].name, 1 w# A) N% j+ s! B; T/ R3 F3 L$ d
entry[loop].age,
% u: q4 ~$ q* d) eentry[loop].salary); ; r, E" Z3 a9 @9 o+ R
printf("-----------------------------------------------------\n");
0 k4 P& a2 `& P( x( @0 x" u0 Dreturn 0; / K# \5 g6 y; F. j
}
, x2 ~: t7 r9 {! I) A( u' u8 f) j5 t
</FONT></P>
+ W6 Y1 L" m  i) A- r<P><FONT color=#ff0000>函数名: stat </FONT>& l5 P4 K0 l6 |( \% Q
功 能: 读取打开文件信息 / M3 |: g6 [8 q+ x$ s
用 法: int stat(char *pathname, struct stat *buff); ' f/ E; X3 \: V; z4 K, F. Y( H; u  z
程序例: </P>8 o  {# g1 S3 a% w1 m
<P><FONT color=#0000ff>#include <SYS\STAT.H>
' q* Y, T0 D) S6 [. z#include <STDIO.H>, ]7 \# v( y" M' Y3 @- T
#include <TIME.H></FONT></P>, Z3 J+ j- X9 s" h2 T
<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>& P3 K; W; d  Z
<P><FONT color=#0000ff>int main(void) 7 Q: I8 ?; R2 l+ h+ E
{
0 g% M$ r3 m( a+ }struct stat statbuf;
* ^1 s" |5 @! r& r& s5 xFILE *stream; </FONT></P>
/ D( k! T: s2 N6 J<P><FONT color=#0000ff>/* open a file for update */
! l( `+ ]8 s1 o& k) h' M# Rif ((stream = fopen(FILENAME, "w+")) == NULL)
$ N# h! B9 o+ n, I9 G{ 6 V# k5 }+ x+ N
fprintf(stderr, "Cannot open output file.\n"); ) r5 w- V$ x+ N: _" _2 g% f
return(1);
; w; q4 V$ j+ ^( p' b: s* h} </FONT></P>( m1 `8 H8 E* b- [) W
<P><FONT color=#0000ff>/* get information about the file */
5 Z7 ^0 a" b# j* j" Ostat(FILENAME, &amp;statbuf); </FONT></P>1 v1 ?% K8 B( w
<P><FONT color=#0000ff>fclose(stream); </FONT></P>
' f8 A& V& x! D/ ~9 v4 g2 _<P><FONT color=#0000ff>/* display the information returned */
* d5 P  g# L8 u( \6 |$ B8 Qif (statbuf.st_mode &amp; S_IFCHR)
$ X: ?0 s3 _# ?. P% j- T- dprintf("Handle refers to a device.\n"); 0 I4 t) B7 }8 `: u7 B9 P2 Q0 h
if (statbuf.st_mode &amp; S_IFREG) 1 }0 N+ s) \" C0 ^5 G
printf("Handle refers to an ordinary file.\n");
" g3 @8 ]7 i. {& P- l0 V4 Rif (statbuf.st_mode &amp; S_IREAD)
/ q, J* v! p+ iprintf("User has read permission on file.\n");
5 V3 k. ^% i3 h, v' b) m4 y9 j, Sif (statbuf.st_mode &amp; S_IWRITE) 9 ]0 p2 Q% A6 h2 w# t, U) ]
printf("User has write permission on file.\n"); </FONT></P>
- P8 y3 b3 j, ?; ~8 Q. i) y+ F<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); ; z8 `7 R9 X; B& _: c9 i6 N
printf("Size of file in bytes: %ld\n", statbuf.st_size); + A4 W/ ?# \# r3 H$ S6 B+ c
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime)); / Y2 t# A/ [$ O. E
return 0;
* i. y8 S# [* y6 o3 Z. H+ {}
6 T/ X. P+ q) P
; N0 {2 E9 [( M" r1 L" p* s: i4 J</FONT>
! |" @- t2 ^9 g6 m+ t6 X</P>
4 Y0 k1 ]4 g! O* Y<P><FONT color=#ff0000>函数名: _status87 </FONT>. G! G/ A9 Z: c% K0 Q! O
功 能: 取浮点状态
6 |3 G: {0 j" t  t! H0 u6 K用 法: unsigned int _status87(void); " ]# A5 E' i! Y" k2 y5 |9 k
程序例: </P># n0 ~+ i# A, d6 G& r
<P><FONT color=#0000ff>#include <STDIO.H># d1 N9 @4 I  r5 A
#include <FLOAT.H></FONT></P>) a+ S& q. L4 B9 K- ?- c) E
<P><FONT color=#0000ff>int main(void)
* M6 G+ r1 z$ n+ J* K{
3 W- N. C  C0 @" e+ [float x;
; O& ^3 g+ Z& v. Udouble y = 1.5e-100; </FONT></P>
3 ]- I& }" s* Y/ K6 ?<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>
/ @) ^1 u. q- w8 [+ ^3 g<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */
, E2 h& N- e# x8 M# jy = x; </FONT></P>
- k1 n# Y. |+ [0 q<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87());
$ H! F/ p  U6 `3 p; d% f3 r0 lreturn 0; 7 i! a5 r: C( B+ E7 N- n
}
" K- ?/ Y* K. y$ E% J! J! h8 k& ~</FONT>3 ?$ a# f& H5 Z  D- T5 R
</P>
8 ~" ^9 Q- @7 D! @. ~<P><FONT color=#ff0000>函数名: stime </FONT>
3 |5 l# ~8 r8 d/ z8 U) C, I1 F功 能: 设置时间
7 s5 z  }& G, \用 法: int stime(long *tp); * Y3 U) J, M" h% Q. Z! T, L, x7 D
程序例: </P>
7 |5 e. D6 Y- M* c) u' Z<P><FONT color=#0000ff>#include <STDIO.H>8 s/ y% b9 [/ O( `
#include <TIME.H>
3 O) r! A- Z: j6 g7 A#include <DOS.H></FONT></P>
- |8 b( L: j9 B- ]5 K1 L/ s<P><FONT color=#0000ff>int main(void)
( u7 ~" e. N3 }, n6 T{
- w1 b+ {" e. z( htime_t t; 6 d5 P- s, ]7 ^3 y
struct tm *area; </FONT></P>
) _. R( T/ P* E; t2 w. k<P><FONT color=#0000ff>t = time(NULL);
# `- p6 ?8 s# H' l# a/ M3 larea = localtime(&amp;t);
4 y& C5 O  X! \1 `# }- Zprintf("Number of seconds since 1/1/1970 is: %ld\n", t);
/ h! g6 o: K$ a& X- gprintf("Local time is: %s", asctime(area)); </FONT></P>) j3 x9 x! W2 h& f" T1 `0 k  I5 Y8 O
<P><FONT color=#0000ff>t++;
( V# I- I. `6 K3 A) p) K: sarea = localtime(&amp;t);
: r5 X2 A6 `- a% U, N8 }printf("Add a second: %s", asctime(area)); </FONT></P>
! [& w# y% d8 P' }0 A, |# \<P><FONT color=#0000ff>t += 60; + Z5 O. ]( J3 W
area = localtime(&amp;t); ( p+ M3 x: N+ c" h' B8 J% j
printf("Add a minute: %s", asctime(area)); </FONT></P>
6 ~/ r; [9 i4 @0 b% w9 a$ |<P><FONT color=#0000ff>t += 3600; . a7 k( ]& d1 _% }0 |7 m
area = localtime(&amp;t);
% u, N# f- D7 x/ T; c9 @( P4 |' Iprintf("Add an hour: %s", asctime(area)); </FONT></P>/ ~8 |% X  }+ X% J! S& b7 e
<P><FONT color=#0000ff>t += 86400L; ) D: _: F9 K& c
area = localtime(&amp;t);
/ f. [- L6 p$ B& [# uprintf("Add a day: %s", asctime(area)); </FONT></P>( x1 P; m$ U7 u. x- [- \
<P><FONT color=#0000ff>t += 2592000L; / l) P1 B9 l8 g# H1 C
area = localtime(&amp;t); 6 M2 V  D) ]2 [( ?. I. G# T
printf("Add a month: %s", asctime(area)); </FONT></P>2 j6 I$ n/ o4 \( [1 {# C" z
<P><FONT color=#0000ff>t += 31536000L; : N( j4 ~; {+ g. n
area = localtime(&amp;t);
" a) ^, I, X. N. mprintf("Add a year: %s", asctime(area)); 8 ?' o3 H: c' Q0 @$ ]& \2 `* y
return 0;
2 W; Z& T" @; P4 v  i3 {} </FONT>
, i( O' I; x6 Q5 z4 t
5 S" V& Y, ?) j7 E+ m- n5 e% |8 b& E, U0 ~
</P>
1 h) i! U$ H: v* f<P><FONT color=#ff0000>函数名: stpcpy </FONT>& |; C. e2 `3 H- {$ I; y
功 能: 拷贝一个字符串到另一个
, W1 a" A8 c' T2 h用 法: char *stpcpy(char *destin, char *source); : Y6 M2 N+ n: p3 K& c  B+ S9 o6 `
程序例: </P>
+ N- W# Z+ ~6 c; K# {; y<P><FONT color=#0000ff>#include <STDIO.H>+ Y6 x" S9 t% U+ |
#include <STRING.H></FONT></P>
+ W" T% O, T* |7 v8 U3 a<P><FONT color=#0000ff>int main(void) 0 f8 x& T- V+ U1 @& O
{
) d% [- Y* P$ S* Hchar string[10];
$ F, ~  v( ?$ K2 ^8 ychar *str1 = "abcdefghi"; </FONT></P>
3 [' ^6 D9 ?! t$ }2 K2 B) L<P><FONT color=#0000ff>stpcpy(string, str1); / _0 I3 H. j6 @$ T
printf("%s\n", string);
7 @& y& I; ]* k/ `' t7 Z* Greturn 0; - I5 Y) J; A+ _! m
} / K% P; r' {3 V7 M/ @7 R

" n1 m0 A( U; n9 t/ C% \</FONT>
2 b, e2 l( u2 D. r</P>
( z7 [* t4 J  e2 f$ \3 v<P><FONT color=#ff0000>函数名: strcat </FONT>
4 |) }* ~  @  ]6 m( K/ ]) E! M功 能: 字符串拼接函数 1 c! A2 N! m) d4 |) f, J) t+ A
用 法: char *strcat(char *destin, char *source); ; O' S% M+ q% F' {
程序例: </P>
/ l! e  U5 n2 }4 ?8 K& ?3 p<P><FONT color=#0000ff>#include <STRING.H>
9 t; X8 J4 S, [+ I#include <STDIO.H></FONT></P>
+ ]; ]+ P. j2 |/ ^<P><FONT color=#0000ff>int main(void)
8 L% F) @8 f% T5 k& o' ~. t2 X7 S{
" ], j- ?$ @' a" L1 vchar destination[25]; & ]  r" {* a7 a) Q
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
: H* R8 ]- X+ ^0 d<P><FONT color=#0000ff>strcpy(destination, Borland);
' B7 n6 d! y) @" A* P) w! A. G. `strcat(destination, blank);
& J" D7 ~$ U; }, Z8 o1 [strcat(destination, c); </FONT></P>
- ^* ]8 @( Y+ i# N6 b1 A2 l3 j2 Z' M7 t<P><FONT color=#0000ff>printf("%s\n", destination);
, `8 Q% I* L8 n( hreturn 0;
0 c$ v) t: p" D3 E6 C! ]5 }} 2 j; r+ A# f3 G- k& p" T) c
$ k! Y4 g  s* m$ j) t1 O+ @
</FONT><FONT color=#ff0000>
8 J( e5 }0 k8 j1 D) C9 c! G</FONT></P>
  s% J0 a7 }+ v) Z4 `7 u6 Z<P><FONT color=#ff0000>函数名: strchr </FONT>
% y! ?$ l# j' e0 b, ~; y7 [2 l功 能: 在一个串中查找给定字符的第一个匹配之处\ . ?6 q% }  p/ t# |4 \4 m7 R
用 法: char *strchr(char *str, char c);
" F( e8 E5 a) ]$ i1 g% T7 p程序例: </P>
/ [0 a7 j' J3 O* a2 l+ d<P><FONT color=#0000ff>#include <STRING.H>
# k& R1 X; o3 }1 F#include <STDIO.H></FONT></P>
# n0 z9 e  K# r1 k<P><FONT color=#0000ff>int main(void)
! I# T8 ?) p0 b, {2 J. v: r- y{
5 g6 {" P+ ?" ~char string[15];
0 c. F/ W& L% o- H4 Z2 {char *ptr, c = 'r'; </FONT></P>1 Y- `0 j. H: h+ @; }9 i& U
<P><FONT color=#0000ff>strcpy(string, "This is a string"); 0 k& b: g; k6 W4 H! B
ptr = strchr(string, c); ) Y( N+ w$ h- a# z
if (ptr) $ Z. O9 ?. F4 H- t
printf("The character %c is at position: %d\n", c, ptr-string); ! |  U! t9 Z% Q5 e. S  [
else
& M% O  d; M' l% M: a5 ]2 Vprintf("The character was not found\n");
9 A! O' h. ~/ Q8 ~# i9 s) }return 0; ! ~2 I4 H/ ^- X3 D+ h
}
: ?7 i$ C0 G0 U; a/ v' n; _, A</FONT>
; s1 x6 ~# [2 Y7 F/ G$ h- b# e
, P) n$ Y; G( ~</P>
6 }; J, H- ]$ r0 {<P><FONT color=#ff0000>函数名: strcmp</FONT> ; Q( Y. t7 Z. l! m1 A9 a
功 能: 串比较 : H8 c/ o6 v; y4 j) l% j/ q
用 法: int strcmp(char *str1, char *str2); ; D+ L8 S2 w( A% O
程序例: </P>2 ?% ^  V# I0 H2 F) k/ ~
<P><FONT color=#0000ff>#include <STRING.H>
" e* R* }! i1 q- s#include <STDIO.H></FONT></P>/ j( _, S( V* v' [
<P><FONT color=#0000ff>int main(void)
1 r( u' q! R/ U" @* \{
: q% I5 Y8 k. d+ ^6 H. Ychar *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";
9 x1 @+ a( F+ F0 hint ptr; </FONT></P>
! W% a; H4 b+ D<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
  w- a' N. w* vif (ptr &gt; 0)
! E, L! A! R! G5 C. Bprintf("buffer 2 is greater than buffer 1\n");
. e  N3 k0 n9 _' J8 C3 yelse
% S. d: w+ ?! |* w/ bprintf("buffer 2 is less than buffer 1\n"); </FONT></P>/ `6 C3 U5 b, R' `! R+ d
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3); ' H, S; n3 B0 A6 u- A; B
if (ptr &gt; 0)
0 O% \0 W' A+ F. p) Hprintf("buffer 2 is greater than buffer 3\n"); ) w+ n( l2 T5 Z, u4 l
else - v; S; X* Q- N1 |, ~7 _
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
& {& J" _+ H2 q7 m2 d! i9 D2 F<P><FONT color=#0000ff>return 0;
, ]- r4 G# f) F$ D}
  g& x9 g$ E! a: l2 O1 {2 _- j; h3 z5 _% Y, v

3 ~  M* l! H! I</FONT></P>
, `0 c) ^4 l9 j1 L$ p) R<P><FONT color=#ff0000>函数名: strncmpi </FONT>
2 f* ~( H# K4 R1 g功 能: 将一个串中的一部分与另一个串比较, 不管大小写 6 j, n$ w$ y7 G$ B# }% N. |" W; K
用 法: int strncmpi(char *str1, char *str2, unsigned maxlen); & o) \- x- e6 z0 d1 b7 s
程序例: </P>7 M" _  ?. L( S, X4 ^) Q. v" G
<P><FONT color=#0000ff>#include <STRING.H>
- E  o4 s- Z# Q9 k( k#include <STDIO.H></FONT></P>
) l3 q8 H$ F$ T  k) @( b7 B  ]- W<P><FONT color=#0000ff>int main(void)
% ]- `( O! ^0 O% Z3 s6 Z{ " l$ j1 |. Z( p) V5 c: }- B+ d% I
char *buf1 = "BBB", *buf2 = "bbb";
* R, J* r' P9 G" P8 H" I* }int ptr; </FONT></P>
% z6 B/ s( f  q$ B& _2 K% P5 O<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
. q9 W. `5 h0 ]<P><FONT color=#0000ff>if (ptr &gt; 0)
$ M3 N# r+ ]! Y" R! ?4 h+ ~3 eprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>" V+ V9 G# q3 f
<P><FONT color=#0000ff>if (ptr &lt; 0)
) a: `; D' a) g: {9 k3 aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>0 \# g; W) P3 K- Z2 x
<P><FONT color=#0000ff>if (ptr == 0)
0 n( ]. Q3 g/ W: j- c1 j* pprintf("buffer 2 equals buffer 1\n"); </FONT></P>  ]7 S6 E- o- E! e) |
<P><FONT color=#0000ff>return 0; $ b1 O3 o) Q$ }; R
}
; B# `, h' }" D, e
2 s' M1 R( B" i" u6 E8 \: ~7 q</FONT>
% L& N0 b5 L2 h</P>* |' }' g+ ]/ X! a7 u
<P><FONT color=#ff0000>函数名: strcpy </FONT>
' \( d# f5 o7 `* o功 能: 串拷贝
9 Y& X( Q7 ]) v% m/ ^6 j$ g2 l用 法: char *strcpy(char *str1, char *str2); " g( T+ u& R+ z' _
程序例: </P>- U" D! |( \3 b% U0 b! m
<P><FONT color=#0000ff>#include <STDIO.H>
% }9 A# y9 [; v9 `1 u" t; B7 I#include <STRING.H></FONT></P>; R" E) A4 h( [4 w0 `
<P><FONT color=#0000ff>int main(void) . B6 s- C# W. z, j
{ ; y! L6 i  z6 {
char string[10];
$ I  I+ {  }  K' q8 Mchar *str1 = "abcdefghi"; </FONT></P>
8 q* Y* {4 ^$ p$ A; i/ \<P><FONT color=#0000ff>strcpy(string, str1);
# v. d% O9 Q2 Q, g' Mprintf("%s\n", string); ! V; R; b% D2 B
return 0;
! }: t% k1 [9 a& Z3 r5 _}
& x) ^5 k' L2 E7 Z: i</FONT># M' k7 b3 o. h

8 y# G  r; B! h& C, y</P>
8 n# Q2 I, u6 t0 G<P><FONT color=#ff0000>函数名: strcspn </FONT>
, ^2 J$ _' Z1 {- u9 p  d功 能: 在串中查找第一个给定字符集内容的段 / ?8 M6 a9 ]  j
用 法: int strcspn(char *str1, char *str2);
7 g1 X$ @0 p4 P3 y+ Y4 }9 R程序例: </P>  U3 F$ R% @$ ]  o3 A
<P><FONT color=#0000ff>#include <STDIO.H>6 r7 o$ V- w2 u- M1 x' j
#include <STRING.H>7 a% g$ [  x3 h, ^8 r/ m7 }
#include <ALLOC.H></FONT></P># i% w) G/ o% M9 j* X, }
<P><FONT color=#0000ff>int main(void)
( \" m/ `7 B- u8 r% J  i  U{ - W. Q: X  I! Q) p9 ^" K
char *string1 = "1234567890";
3 b5 o, M, ~9 T+ C3 f! Vchar *string2 = "747DC8";
6 R: Y; j8 a: V8 ~1 }int length; </FONT></P>
2 |" t* ?9 b4 Y4 }; T, Q<P><FONT color=#0000ff>length = strcspn(string1, string2); 8 m4 x7 ~, O0 _+ X1 W5 k8 ^
printf("Character where strings intersect is at position %d\n", length); </FONT></P>
3 \7 w/ [/ X  y, ^- o+ {9 w<P><FONT color=#0000ff>return 0;
6 e& r1 [  Y. ^% h} - H$ t, \7 X% X9 g0 I' ~2 p
</FONT>
7 ~8 c# O. Q* \; ^1 q; R% e
3 d. m) [" g) V+ a5 D</P>+ ]. P# M( W7 l' j/ }" x9 O$ T
<P><FONT color=#ff0000>函数名: strdup </FONT>
% I! W- Z# _. h& _功 能: 将串拷贝到新建的位置处
1 z- d* @0 c* G6 @+ @( B8 H用 法: char *strdup(char *str);
, L6 X! g& M! s. j) R, y4 _程序例: </P>
" O" G# G0 g; B, j% _<P><FONT color=#0000ff>#include <STDIO.H>
8 P/ i7 X' A( E" q1 `#include <STRING.H>- \% i( Q; A- \. ~" p! @+ p4 R
#include <ALLOC.H></FONT></P>" \4 Y# c. k+ H0 O7 o/ m
<P><FONT color=#0000ff>int main(void)
! I2 M: a- J( c8 h6 G: V: Z{ / n5 f9 h% o7 i: N/ i
char *dup_str, *string = "abcde"; </FONT></P>. A- s4 T& \4 F$ M8 B2 e
<P><FONT color=#0000ff>dup_str = strdup(string); 1 F6 E% x. s+ g: a( r; ~4 I% e
printf("%s\n", dup_str);
( q0 O+ ~4 i  R) S+ `! b" Ifree(dup_str); </FONT></P>7 x/ N4 y4 x$ r- C8 q- q7 V+ P6 i
<P><FONT color=#0000ff>return 0; 4 `# B2 u5 N" b2 Y3 ?: F* j; F
}
" m0 M+ ]7 i' n; T5 }7 s" _/ H. ^( t% f) v1 M
</FONT>
5 s$ c' w1 R; C( x, d</P>$ T* R. _: Y! z# \9 n5 d
<P><FONT color=#ff0000>函数名: stricmp </FONT>3 ]) Y$ U& j  W: O) v
功 能: 以大小写不敏感方式比较两个串 , J0 O5 K9 l' `$ _
用 法: int stricmp(char *str1, char *str2); ' b" |' Y( N/ f+ |0 j
程序例: </P>  v$ [3 v' G* V$ d0 [( j" M# x! f
<P><FONT color=#0000ff>#include <STRING.H>
/ \* t; o( B2 D/ M* \: X! \' P#include <STDIO.H></FONT></P>- R9 a1 M* q6 X) h& N
<P><FONT color=#0000ff>int main(void)
4 t0 \# U: t3 E; A& E7 g{ # B- n- s% N* v; a
char *buf1 = "BBB", *buf2 = "bbb";
2 b5 y5 ]: ^: x  P$ Wint ptr; </FONT></P>  ?# d4 F) W( U
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>7 p7 ^4 K4 C4 y! W8 q3 [6 e# O
<P><FONT color=#0000ff>if (ptr &gt; 0)
5 Q* E4 g8 M0 m0 N/ d) ], g+ C( J6 W2 A7 fprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>( M, T) K6 H" y6 i6 V, H  F+ Y( z
<P><FONT color=#0000ff>if (ptr &lt; 0) 1 G: n4 {5 ~+ `5 s3 D& |/ d
printf("buffer 2 is less than buffer 1\n"); </FONT></P>; u( v3 _4 _' T8 P
<P><FONT color=#0000ff>if (ptr == 0)
/ v# n5 g# d8 u8 K, e8 e! _  Vprintf("buffer 2 equals buffer 1\n"); </FONT></P>
+ s0 V+ \& O: M1 {8 x% Z<P><FONT color=#0000ff>return 0;
) w/ ^. A4 u; |* P( _) c1 T) F} / r7 o4 p" O4 g1 N0 t
</FONT>
3 D6 t3 |- a. L% u0 x- p</P>
4 Z$ v% _' Q; @( Z( H- l<P><FONT color=#ff0000>函数名: strerror </FONT>
! g5 @, E* w% `功 能: 返回指向错误信息字符串的指针
  z9 T9 g- p6 @( Q: p用 法: char *strerror(int errnum); ) y: y# E& l% ?$ r6 I* T
程序例: </P>: U3 N/ g. p  m: |) D# \- C. Y
<P><FONT color=#0000ff>#include <STDIO.H>
$ t3 U& V6 i% }4 _#include <ERRNO.H></FONT></P>
; O1 L% K5 C, ]7 J% B  P  D<P><FONT color=#0000ff>int main(void) + r2 E2 P! c1 a: [1 I; c
{
# g5 o+ Y9 B3 d- x! Y1 z& t0 G& Wchar *buffer;
% s9 e# z  A2 ^2 p$ D+ v; tbuffer = strerror(errno); : y% Z  X3 y3 F. e
printf("Error: %s\n", buffer); " U6 r$ K6 `( ^6 K% z
return 0;
/ J6 g  t2 W% E) o}
9 E; \8 U! U  E! U( Y# p$ H
: x( E' m; l: s, l6 W3 m2 {</FONT>
9 f- x/ M" c8 Q4 D+ ~3 ?; f" ]</P>
/ C  N) v0 K- p, h$ g/ v+ x<P><FONT color=#ff0000>函数名: strcmpi </FONT># C0 e9 V( g  r, q. ~' F% L0 [
功 能: 将一个串与另一个比较, 不管大小写
1 J  W/ _* G( |- s用 法: int strcmpi(char *str1, char *str2); / T$ V. @% V: g! E5 p
程序例: </P>
, o+ u* ^' o7 t; B<P><FONT color=#0000ff>#include <STRING.H>
" a/ f: U5 _, t#include <STDIO.H></FONT></P>' L" ~3 \0 R$ W! v1 {- \4 y5 M
<P><FONT color=#0000ff>int main(void)
) z' l4 c, p* J* r0 ^0 Y8 Z{   m0 F! _* M3 w1 k9 N3 Z
char *buf1 = "BBB", *buf2 = "bbb";
) Y, y# ]( Y8 ^, @+ K! ^* y, |$ Dint ptr; </FONT></P>
0 x! Q. L# k. Q5 Q" d! T<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
/ C- Y' [8 ~: P* Z! Z<P><FONT color=#0000ff>if (ptr &gt; 0)
% T0 W+ L) s/ S+ N/ @4 y% J* sprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>' w  \2 U, A; a$ E  B
<P><FONT color=#0000ff>if (ptr &lt; 0) $ r! D$ \( r0 P" t; D) a
printf("buffer 2 is less than buffer 1\n"); </FONT></P>" c  y) g" E( v2 [' W' H! ?% H
<P><FONT color=#0000ff>if (ptr == 0) ) H% v* s" x6 V, ?9 C8 `
printf("buffer 2 equals buffer 1\n"); </FONT></P>
# _2 V  q4 k+ ?- Z( q5 C<P><FONT color=#0000ff>return 0; * ^, h) P& X8 R+ s' N2 `
}
% m2 Z' r4 u0 h/ [</FONT>
# u7 b% @: e" A: q* [6 Y, |9 n* w' o! m
</P>% H) [0 x: }2 S  ?$ s) X6 N
<P><FONT color=#ff0000>函数名: strncmp </FONT>
1 r; y  F0 h! r1 m/ E功 能: 串比较
: H% R  X9 |: K( `# h) P/ V1 p用 法: int strncmp(char *str1, char *str2, int maxlen); / S  f+ P# G2 g! z
程序例: </P>! W' D7 {8 `. W$ E8 w
<P><FONT color=#0000ff>#include <STRING.H>) k$ x) l/ {2 L2 q* ?
#include <STDIO.H></FONT></P>
5 n% B1 g5 e8 c6 x! y! d4 ?<P><FONT color=#0000ff>int main(void) </FONT></P>
6 j% ^* Y8 g# S) t% ]: e2 Z) ]( i1 w<P><FONT color=#0000ff>{ ( W5 |0 j/ p" r
char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";
8 j: e. B; K/ u' R5 a9 O5 R$ Z& bint ptr; </FONT></P>, Y  l9 ^) M- I
<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3); 4 g( K- Y7 @5 g# E
if (ptr &gt; 0) - o+ o8 j  j4 s/ P6 J7 ]
printf("buffer 2 is greater than buffer 1\n"); ) L5 {# a3 u" k' O- y" a. u
else 4 Y5 c$ k6 g( d1 V( [6 Z& f5 t
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
4 b$ K- e4 d, T  D' V* ^, T3 b. D# t<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
! ~# v( A5 m( C5 J4 aif (ptr &gt; 0)
. W; [) u/ a9 G2 I) Hprintf("buffer 2 is greater than buffer 3\n"); 8 R2 ?) R* Z3 @5 k& p9 j& K. E) W
else * `5 }& C1 K+ f/ a
printf("buffer 2 is less than buffer 3\n"); </FONT></P># {" m" }( k& g$ D6 C2 A, g
<P><FONT color=#0000ff>return(0);
  d4 d+ [  C0 T# R}
- m7 t% l! l. g/ B+ m, E  j# K5 q, }% y5 G6 {
</FONT></P>7 r8 d2 s) ?+ b, m) N
<P><FONT color=#ff0000>函数名: strncmpi </FONT>
8 R: W5 N/ P& E功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写 ; O) C% o4 T& T( |5 @" `
用 法: int strncmpi(char *str1, char *str2);
) w2 K  u2 U' h程序例: </P>+ I+ m  W) A5 X6 }7 \/ k3 p  j, [
<P><FONT color=#0000ff>#include <STRING.H>3 X! Z6 [3 J- X8 E0 C; v' }" k
#include <STDIO.H></FONT></P>
& C. J* V7 f" v- ~<P><FONT color=#0000ff>int main(void)
. f. f* W* |! E0 T$ T% f{ 0 M$ o" t9 i) L- z' r* X
char *buf1 = "BBBccc", *buf2 = "bbbccc"; # c( f% M' B' J( E
int ptr; </FONT></P>
* K1 P8 h; s" ^$ a5 O8 `<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>
+ m! O6 P, ^2 ]3 }, v3 |<P><FONT color=#0000ff>if (ptr &gt; 0)
, u: x) j3 l$ V& x+ t5 |6 kprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
; B' i$ }5 l( f" g- K6 S' d9 z<P><FONT color=#0000ff>if (ptr &lt; 0) , _2 P  Y, ~  K2 I
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
1 \2 Z( y0 e) Z  K# Q- f<P><FONT color=#0000ff>if (ptr == 0)
3 b% O+ ?8 k% z4 tprintf("buffer 2 equals buffer 1\n"); </FONT></P>
3 T7 Y( g* h6 ^. m# H" X<P><FONT color=#0000ff>return 0; </FONT>. ?7 [# {' \6 u
} $ M) z+ s$ _0 f4 p: }/ Q; I# W

; D4 ^8 V$ n; ~9 O, ~& q5 M</P>
* o0 s6 O- U9 [; Y8 Q<P><FONT color=#ff0000>函数名: strncpy </FONT>: _! n2 E1 Y% L! [5 b: q2 f
功 能: 串拷贝 % h) U  m: I3 K
用 法: char *strncpy(char *destin, char *source, int maxlen);
$ Z" Y7 B% ?% Q& Z) Y: O5 t程序例: </P>1 X0 O  l' Y( r" O1 |0 ]
<P><FONT color=#0000ff>#include <STDIO.H>" q# w+ t- x' l; C: V7 I$ Y7 Z
#include <STRING.H></FONT></P>
$ F; }  }4 @. @1 |<P><FONT color=#0000ff>int main(void) & I% ]+ ~: `8 A: u9 ~5 y
{ - u8 O3 O- ]' {& M
char string[10]; 8 y( `: W0 Q4 k  c4 A
char *str1 = "abcdefghi"; </FONT></P>8 W3 e! U1 g' o* k$ u( i
<P><FONT color=#0000ff>strncpy(string, str1, 3); " F$ f; S" G4 \% w$ X/ ]- }  g+ y
string[3] = '\0';
" ~3 s3 o; e* Y. z& R( Yprintf("%s\n", string); : H+ h% k: s; q; g& D& o. v
return 0; 6 Q5 S- }% o% ?7 V. \0 x9 N' {& z4 C
} + {1 t, }7 M2 @+ d" A  Z
</FONT>$ T+ R8 P7 P: E' U( o" v% h; e8 I
</P>
7 l/ S; A% v/ h4 ]3 {<P><FONT color=#ff0000>函数名: strnicmp </FONT>1 Z. U7 T0 b7 k0 e' E
功 能: 不注重大小写地比较两个串
0 e# J1 w) g7 W4 T+ b用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);
3 H: L$ E: J) V8 k8 e5 T% m程序例: </P># D( O& A* v! ^2 C0 `0 v
<P><FONT color=#0000ff>#include <STRING.H>
  u% l$ ~# v. x7 z! Z8 n: H#include <STDIO.H></FONT></P>
5 `( k! e0 _' Z9 Y# v<P><FONT color=#0000ff>int main(void) 5 I7 K5 Z2 |: Q. j! Z" R
{
  E" j; A) f: N* o5 gchar *buf1 = "BBBccc", *buf2 = "bbbccc";
8 a0 G- Z* O  B+ F! M, Aint ptr; </FONT></P>( I  o6 |6 Z. R* _
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
; A& `- e' N0 l; |8 a  C) X<P><FONT color=#0000ff>if (ptr &gt; 0) ( S9 X! y+ s0 P, m
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>
' m8 l* x1 x$ H$ Q* y" v<P><FONT color=#0000ff>if (ptr &lt; 0)
* L: [2 u: Y6 h* d6 Z; F) `( Cprintf("buffer 2 is less than buffer 1\n"); </FONT></P>' \4 o! u' k1 J2 x' t5 f) x
<P><FONT color=#0000ff>if (ptr == 0) ; b! Q# A' f( }: P/ E( P9 P
printf("buffer 2 equals buffer 1\n"); </FONT></P>
; d6 ?- H: {- w<P><FONT color=#0000ff>return 0; / v1 q% a8 W& L* ^+ e2 V/ h' g
} / Z4 F6 i' b8 A* n- y  p) J
7 E0 e5 W; P) k5 l
</FONT>
- H) @6 ^) @; `</P>% V/ W; M" e. [  \* V) l: C5 u3 i
<P><FONT color=#ff0000>函数名: strnset </FONT>) X+ X+ L) T, S
功 能: 将一个串中的所有字符都设为指定字符
; d2 ]- Y, o" D: G9 n+ T9 l用 法: char *strnset(char *str, char ch, unsigned n);
; r- n# Z' t# U4 Q- a) {% _: v# N程序例: </P>6 I( q) f0 C4 s  l2 y
<P><FONT color=#0000ff>#include <STDIO.H>
+ \2 E2 Y4 H8 ]' c! a" L#include <STRING.H></FONT></P>
9 B- a( A( ]# F* o. `+ {<P><FONT color=#0000ff>int main(void) * c* ?3 T  K# V% B
{ # ^, \* ^* O$ z* d8 s. h" a
char *string = "abcdefghijklmnopqrstuvwxyz";
2 @4 E* [  l: W$ ^% Achar letter = 'x'; </FONT></P>" {9 U2 m: \' N% P! y& ^1 D
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
' f8 Y) [& ^$ P- istrnset(string, letter, 13); ! U! [: ~3 b( n3 I2 b
printf("string after strnset: %s\n", string); </FONT></P>. d) K! \& ?! z1 a4 I
<P><FONT color=#0000ff>return 0;
4 g9 q" |0 I9 F$ j  x: n} 9 P2 Q/ [( [% |# B# _% r
</FONT>: v* ?; ~8 u( v6 j9 Y3 }
</P>
" D' T* i) m! z4 Y: G' A<P><FONT color=#ff0000>函数名: strpbrk </FONT>$ t' ?" j& A) L, O2 t4 ^8 p- h
功 能: 在串中查找给定字符集中的字符
5 z' u2 {! t, ~5 N7 i用 法: char *strpbrk(char *str1, char *str2);
% y6 c: s* B9 A4 Y% @. F1 T程序例: </P>
0 J* \) J/ |3 G1 ^' ?$ u<P><FONT color=#0000ff>#include <STDIO.H>
$ u) l4 w- }  Q( h( [3 t; M, V& X#include <STRING.H></FONT></P>: Z( Y& S% T0 ^' O. }  S6 o- ^  [
<P><FONT color=#0000ff>int main(void)   i: ^8 `* t4 b5 h5 a. w
{ * m& T( c% R4 N' L% q1 j
char *string1 = "abcdefghijklmnopqrstuvwxyz"; 1 e9 @( D& J5 T( l" E6 u
char *string2 = "onm"; 5 Q2 C+ B3 d  O
char *ptr; </FONT></P>7 Q( Q6 y  O( C* d- D& q3 p& E2 ]
<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>
- _9 f& c  x, k* {<P><FONT color=#0000ff>if (ptr) ' L9 h2 C7 l# u4 b# m3 O* p
printf("strpbrk found first character: %c\n", *ptr);
9 r2 {' u8 c; U, c, M6 q8 Melse $ q" e% I% b: s/ t: j
printf("strpbrk didn't find character in set\n"); </FONT></P>+ Q9 P' x2 z; S& k0 i; y
<P><FONT color=#0000ff>return 0; : `- D* M' J. Y
} - ~9 U& x1 Z: h5 ?2 y" @

6 Z$ C: T7 |4 R: o8 K</FONT>: o% k  o  b, I8 H$ S/ D/ D3 ~) S
</P>
, L" w# B  \4 q; u2 c% E0 }+ S, C<P><FONT color=#ff0000>函数名: strrchr </FONT>. A( o: `4 P' V4 k
功 能: 在串中查找指定字符的最后一个出现
2 Q# P% |( A+ r' E3 ]用 法: char *strrchr(char *str, char c); 6 g8 {! s) l. k
程序例: </P>
8 H( W3 b* a1 W* U8 ]8 M% P3 J. v<P><FONT color=#0000ff>#include <STRING.H>
2 d7 I1 P- @- e  f* w* ~' c% f#include <STDIO.H></FONT></P>0 G% B9 N8 Q. H* M& G7 s
<P><FONT color=#0000ff>int main(void)
6 z4 p/ l. p. b) {{
9 j9 q; N# K& b5 F  U- x# N' `char string[15];
( f8 o6 L2 i8 ?/ v* ^# f" R+ Achar *ptr, c = 'r'; </FONT></P>3 j' M8 G, n* n8 e* G
<P><FONT color=#0000ff>strcpy(string, "This is a string");
& x) O% j3 k7 }2 F, Xptr = strrchr(string, c); 4 b) z3 @0 P, ~
if (ptr)
$ w  P6 y8 X- [0 D5 o" ?7 Rprintf("The character %c is at position: %d\n", c, ptr-string); / T9 {1 V0 a# [1 A4 k; L. h/ H6 O6 v
else ( E8 X! m' ?7 Z* ~
printf("The character was not found\n"); ! c$ T4 L, s3 Z/ {# x3 a
return 0;
$ W: R" n% n- O- W2 r  P} </FONT>
+ E1 U6 r) `, z0 y! _% n! z
8 L3 h6 _# H5 p' J4 t* j# M9 U+ b% |) A- ^# m# e
</P>% z' M% c! e: l* q3 p1 R
<P><FONT color=#ff0000>函数名: strrev </FONT>) S; A, [+ G/ `$ V# ^1 u! k
功 能: 串倒转
8 @8 s! l/ Y1 N3 L用 法: char *strrev(char *str); " G% z+ l$ y) u+ X2 d8 C  E
程序例: </P>  }' ~1 |* w, {
<P><FONT color=#0000ff>#include <STRING.H>! w7 \- b' V) K- s- V
#include <STDIO.H></FONT></P>
# P& O1 y  W. ?( j- v8 B. [5 O* n4 v<P><FONT color=#0000ff>int main(void)
, c* L4 G1 V1 b0 F0 l3 K. S{
: i7 u* |% c8 _char *forward = "string"; </FONT></P>
, u, i  p+ Z) ^5 Q+ t1 X1 X<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward);
5 p" [' x" k. p! j2 c$ F' Kstrrev(forward); ! T% h! h; t8 i+ Y. a+ ]) |
printf("After strrev(): %s\n", forward);
/ O1 L  F) u1 n2 Z* {3 Z" dreturn 0; ) N: p# O' v, {* y. v$ ]" R
} </FONT>  s/ }5 B* N) y0 t
</P>
" {( q, [  u2 l2 Q7 J+ S0 ]% @<P><FONT color=#ff0000>函数名: strset </FONT>5 D, e. C+ E$ U; |; ~3 R4 R
功 能: 将一个串中的所有字符都设为指定字符 8 R' P+ O1 _7 H! {, n8 K
用 法: char *strset(char *str, char c);
0 ^: @( P2 P% Q1 C程序例: </P>
+ }* Z% j, L/ H) I. Z  u& N<P><FONT color=#0000ff>#include <STDIO.H>6 _/ P8 x9 B" ^+ ]* p; k* i
#include <STRING.H></FONT></P>
# H! g) `* c: B, y- W<P><FONT color=#0000ff>int main(void) 8 j6 Y. m4 K" U" B
{ # o; M2 F. L; ^0 F
char string[10] = "123456789";   e- n1 i1 R/ G
char symbol = 'c'; </FONT></P>
6 |6 T2 w2 F; a/ T% n: U<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
- j& Z3 {4 F! ~4 Nstrset(string, symbol); ( P0 q% B& y4 v/ S% `
printf("After strset(): %s\n", string);
2 m' A( T6 H" B0 m* l1 R3 ereturn 0; - e; V1 _/ X7 @' t" }( f7 I
} 6 ]7 c+ ?! m- e2 D: L

- X8 [2 ?; p" u! {" S</FONT># C1 W( Y# }; p) n) g) A
</P>
  @3 b- S- r- b" D+ d<P><FONT color=#ff0000>函数名: strspn </FONT>
; Q8 O  u( J! K3 ~1 D. a功 能: 在串中查找指定字符集的子集的第一次出现
" T+ b" Q5 l1 ^% |* `" B( @9 F% `用 法: int strspn(char *str1, char *str2); ! k' ~) B$ M+ d' u0 }# o, m
程序例: </P>/ d: U4 _- d* P! i3 Q* a3 a9 v  M
<P><FONT color=#0000ff>#include <STDIO.H>
7 ]1 g3 _: r/ B1 X& Y#include <STRING.H>. @5 ~3 {+ M5 y) ~0 d
#include <ALLOC.H></FONT></P>
2 ^/ N$ Z( w! ]; V9 D$ \<P><FONT color=#0000ff>int main(void) - _* B9 k& d, w! e- W! a
{
1 Z3 j* \& M7 g7 w/ T9 }8 ichar *string1 = "1234567890";
/ x5 R2 \" w2 }5 w0 [. S% vchar *string2 = "123DC8"; - m: n) N$ K' L! U4 q
int length; </FONT></P>
) r2 N5 C2 g+ x2 D% w<P><FONT color=#0000ff>length = strspn(string1, string2); - O1 b" x2 \9 [# w" R
printf("Character where strings differ is at position %d\n", length); + e0 |; z: W  U: v0 {5 m
return 0; 4 ~5 e+ L' D, Y
}
; T, M8 I8 C+ O5 c</FONT>& B: L  o+ I1 u! ^
</P>, }( y. Z8 {) f1 M
<P><FONT color=#ff0000>函数名: strstr </FONT>
3 ~+ J: q: h; X, u) _: @功 能: 在串中查找指定字符串的第一次出现
0 r* u9 P% k; u5 g用 法: char *strstr(char *str1, char *str2); 7 R# E8 O5 h. R  d
程序例: </P>- L: K# w" A; w6 A
<P><FONT color=#0000ff>#include <STDIO.H>* k5 p' Z% H2 k' d' {) V
#include <STRING.H></FONT></P>8 p4 A) `8 @8 D8 }% u" T) E5 ~) r% u2 A( d
<P><FONT color=#0000ff>int main(void)
) Y- t6 t1 c, }{
" ~+ Q+ S% @3 U; V. E$ Z( bchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>3 [- T9 T* b/ [* U: s' D
<P><FONT color=#0000ff>ptr = strstr(str1, str2); * _4 M) g4 f: }3 q+ f1 J  P
printf("The substring is: %s\n", ptr); 9 t1 z/ R! F2 n5 g4 _& y* q
return 0;
+ C. R  M& B- a4 z1 h5 L} </FONT>
% k# \6 F6 Y& F
8 c( ~: q% [+ y/ i# c* |$ m</P>7 C5 c) \7 @6 B6 w9 V
<P><FONT color=#ff0000>函数名: strtod </FONT>
9 s! m; e4 m9 i6 Z% b" J* p功 能: 将字符串转换为double型值
7 B0 b- t% m" h2 i) |& S1 [- j1 o用 法: double strtod(char *str, char **endptr);
0 b: D" E0 V9 o" J+ o0 N程序例: </P>
, `( K5 U: e2 o2 k% b3 y- z<P><FONT color=#0000ff>#include <STDIO.H>
. X0 t  J7 z, F8 N+ p#include <STDLIB.H></FONT></P>
! _2 Q; I) R% }<P><FONT color=#0000ff>int main(void) 9 O2 D+ ~: d: o5 f" A1 D# J3 m
{ + V. F2 {  X% k0 K" f2 C3 U
char input[80], *endptr;
3 o. s9 i7 a/ l2 O; w7 c5 odouble value; </FONT></P>
/ T8 p/ Y: l) x1 a6 X' s<P><FONT color=#0000ff>printf("Enter a floating point number:"); # N3 I, L: e4 o/ v
gets(input); 4 e" ~/ O( _8 r8 d. m1 p
value = strtod(input, &amp;endptr); - z& Q& `! q9 ^" m- A/ \! [& a+ l
printf("The string is %s the number is %lf\n", input, value);
6 d4 G9 Y, O% j, Lreturn 0;
- k! g* s) p/ x} 8 V. k( L: C  V6 t
</FONT>7 ?$ O6 ?  w3 w' G
7 i% J5 ]. R6 F0 {; r
</P>
1 ^1 O; ^+ E$ N. E5 u6 T- o' j<P><FONT color=#ff0000>函数名: strtok </FONT>
5 d. s. l! Y! e; ~* X功 能: 查找由在第二个串中指定的分界符分隔开的单词
6 r) C: ~" s( F用 法: char *strtok(char *str1, char *str2); % G0 O- Y! p, q: P% a1 ~& n
程序例: </P>1 {3 T% e' ]7 A( A- [( t  d5 t
<P><FONT color=#0000ff>#include <STRING.H>' h$ y, W  Q9 m" Q% ?: C
#include <STDIO.H></FONT></P>. F" _( P% x& O: r/ d8 [6 C
<P><FONT color=#0000ff>int main(void) % b  H$ |1 u2 B5 l. _. R# O7 J
{ , J* Z" }- S$ D) P
char input[16] = "abc,d"; * b3 _( y# c# q* I
char *p; </FONT></P>
; }& s0 j7 |+ F. a<P><FONT color=#0000ff>/* strtok places a NULL terminator ) o4 N- _7 m, J4 q$ h
in front of the token, if found */
+ s/ Q& [7 x  U; j& ], h8 cp = strtok(input, ","); : c* R1 }0 w; H, ], s4 ^6 ^
if (p) printf("%s\n", p); </FONT></P>' W/ y4 `+ d% z! i9 N
<P><FONT color=#0000ff>/* A second call to strtok using a NULL
5 E5 i! g: i/ has the first parameter returns a pointer
  O& y) E  Z  U3 n! d/ _to the character following the token */
. `! B/ C6 B4 b  xp = strtok(NULL, ",");
. p) A0 M- m1 H. uif (p) printf("%s\n", p); ) [2 l# K2 U/ K3 p  m
return 0; , B% r# R7 D$ w; n, T' P
} 4 A! c  r* U; I: V7 M
5 C& R3 @8 T, i

- D- B. ]+ H% K7 U. M# N9 S' p9 ^</FONT></P>, g( T4 w+ H0 }: K# ~7 I
<P><FONT color=#ff0000>函数名: strtol </FONT>
# l: u* J( _& G功 能: 将串转换为长整数 : U2 i0 ^4 s- B9 T" D: V/ Q8 Y
用 法: long strtol(char *str, char **endptr, int base);
, y5 E& T; U+ D程序例: </P>
  q8 F' b1 v7 s. B0 e, q  q<P><FONT color=#0000ff>#include <STDLIB.H>
" V' r9 J2 f( w' J+ d  F#include <STDIO.H></FONT></P>
. y& F$ t8 \/ \6 q' z; r9 Q<P><FONT color=#0000ff>int main(void) % A$ ]/ J5 T2 A+ ^( _6 t3 L
{
; @/ O; k$ N3 j) q0 M4 X, p0 Gchar *string = "87654321", *endptr;
$ n/ U1 B5 G3 c' y$ clong lnumber; </FONT></P>
* O* }  V) u7 q% q( A  a" N% S<P><FONT color=#0000ff>/* strtol converts string to long integer */
" ?* w: l& }& Q; j$ r' {lnumber = strtol(string, &amp;endptr, 10); - Q. p" J$ U4 B! b
printf("string = %s long = %ld\n", string, lnumber); </FONT></P>
! k+ H6 s) z! j' u! L<P><FONT color=#0000ff>return 0; 7 w, e& x3 y  Q* u9 [
} </FONT>& u) @7 X5 `  y1 A3 c4 I' g+ l* Z
</P>. C) f$ Y3 m" j
<P><FONT color=#ff0000>函数名: strupr </FONT>0 K& H9 a& j! b! a! @$ j) q5 P
功 能: 将串中的小写字母转换为大写字母 # I3 ?* M- U; D9 z2 o
用 法: char *strupr(char *str); ; P% c" b4 i, X; b. m8 v
程序例: </P>
* J5 R2 t% x/ A7 s/ F$ J6 }  m<P><FONT color=#0000ff>#include <STDIO.H>
: i9 K& V7 O8 J; [. L#include <STRING.H></FONT></P>2 H+ N  z3 S7 j5 A% D! W$ q
<P><FONT color=#0000ff>int main(void)
; j" L+ b$ j2 h* g. i3 `{ 9 }6 x8 d+ \3 r% A; R) f0 A
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>
: b  H) X% q" O7 X: X<P><FONT color=#0000ff>/* converts string to upper case characters */ 5 a* s' R( D/ V4 h
ptr = strupr(string);
/ g2 i  ]  d& ~" O# z5 ?" d* fprintf("%s\n", ptr);
; W) N! [8 n1 p# G, e, g9 {: _return 0;
  L* v' X) \& [6 Q; r}
! g  }8 S) L8 m# b' x5 I# R+ c$ y6 t" R8 F$ ^/ E* z
</FONT>& }. g  P( {* |
</P>
; l  k$ @0 Q8 i$ T3 }2 }8 [8 x/ s<P><FONT color=#ff0000>函数名: swab </FONT>5 L% f" n" c' v7 F) n5 J5 z
功 能: 交换字节
, F3 M2 G& C( k8 }用 法: void swab (char *from, char *to, int nbytes);
$ E  K2 b' s& j& W# u程序例: </P>0 A( J2 w0 R/ ^7 P7 b" p4 `  J
<P><FONT color=#0000ff>#include <STDLIB.H>
" \1 l2 `: [# Q7 {' y#include <STDIO.H>
+ \: g! r0 r% E0 K9 V4 O% k% u; q#include <STRING.H></FONT></P>8 M* z9 Y+ N3 M! Q
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d"; . o/ J/ `! z0 j( ]) M3 k2 j" I% ^' n
char target[15]; </FONT></P>" o' ?. d3 D( k- O1 U+ J# Z- H
<P><FONT color=#0000ff>int main(void) 0 ~+ F% S. ]; {
{   k; C2 f  G% F' R! G
swab(source, target, strlen(source)); ; V7 S: e2 H; A5 E
printf("This is target: %s\n", target); & [0 r" f- L0 E$ Z+ m- D
return 0;
9 T% }+ \2 y( p& z2 k# n( u* u9 m}
& o: t: ]) R4 b9 E8 _8 N2 e: L4 @: ]</FONT>" K' c5 j( W/ F; a) ?
# X" m% v, B# L2 x6 P* j7 `
</P>3 m& {9 M: z' n* }
<P><FONT color=#ff0000>函数名: system </FONT>
! F$ k; ]" O, K% @# [7 i! ?% L功 能: 发出一个DOS命令 8 k& S& m" R  G, W! p, Q4 w. d7 u+ s
用 法: int system(char *command);
& _9 Y7 V* u9 p/ v! _程序例: </P>9 n+ L/ U: F, B# E& E  q4 `
<P><FONT color=#0000ff>#include <STDLIB.H>( f2 v- i& M: h0 Q
#include <STDIO.H></FONT></P># b' v; Y- s( B9 X/ e9 Z' c
<P><FONT color=#0000ff>int main(void) # N/ Z* f; C7 g; O2 h3 A2 @
{
! H3 B+ T: T; W& M1 F& N, d. yprintf("About to spawn command.com and run a DOS command\n"); ) |+ o8 v5 b8 L* Q; k% E
system("dir"); / P6 ?* {# B# ^9 B# v% I+ W/ i
return 0; ; J/ v2 T. f2 _6 Q8 F$ C
} </FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 09:56 , Processed in 0.454822 second(s), 52 queries .

回顶部