QQ登录

只需要一步,快速开始

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

函数大全(s开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 02:55 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
<><FONT color=#ff0000>函数名: sbrk </FONT>1 B3 S: x# G! R5 v! b( G/ ?
功 能: 改变数据段空间位置
. s; N" g7 C/ l0 u' Z# k用 法: char *sbrk(int incr); $ y& V" I7 x$ M. J
程序例: </P>
5 l% E  M, a" k; e0 L+ S, h7 [; H<><FONT color=#0000ff>#include <STDIO.H>" s8 o, O4 i. a* W
#include <ALLOC.H></FONT></P>
5 K: W9 @, K# [5 N<><FONT color=#0000ff>int main(void)
/ c3 l9 J' a1 d7 i- {) _{
/ ]+ S$ o# Y( r1 ?$ xprintf("Changing allocation with sbrk()\n"); 8 x% |4 i# V8 U8 `+ Q
printf("Before sbrk() call: %lu bytes free\n",
  L& y5 V& x1 [$ b+ Z+ o, A9 X8 B  ?(unsigned long) coreleft()); 3 h" \5 A# f: I3 j
sbrk(1000);
% E; M5 p8 M( }' jprintf(" After sbrk() call: %lu bytes free\n", + N7 D7 y1 a- B. a. A: t+ n
(unsigned long) coreleft()); 5 l8 g! ]% }: p
return 0; ) o* H* P- e' z9 a
} ) {# o6 w8 V2 A" u1 ?# o3 A- v5 H
/ ^5 ]" S& N, `/ T. _% Q
</FONT></P>
7 E. F4 D7 O& Z8 u<><FONT color=#ff0000>函数名: scanf </FONT>* ~4 q) K* k  t) O4 Y
功 能: 执行格式化输入
. p5 f: D5 X# \用 法: int scanf(char *format[,argument,...]);
) J# n4 L- Q# Q, `7 b* e程序例: </P>
, E  Z( q+ w5 U' \& Z<><FONT color=#0000ff>#include <STDIO.H>
3 x0 \2 L$ Z0 ~/ R- A+ ]#include <CONIO.H></FONT></P>
7 P# H- [- m1 s: x$ s7 @% N<><FONT color=#0000ff>int main(void)
, w: b, w5 M' R& e' U# k$ A& v! P5 `{
, |5 l' J! C: r5 ]  E; I& Gchar label[20]; 7 W4 m% Y$ t8 y9 x
char name[20];
" L: r$ ~" r) }$ T5 V1 _% g1 Uint entries = 0;
, U; c1 T% [' Xint loop, age; - O! l; I( b  \  C3 `
double salary; </FONT></P>
; S6 [- i) v9 H  i  @6 a: b2 l<><FONT color=#0000ff>struct Entry_struct 3 S/ L2 N" R/ ~7 \) ^, K
{ ! j5 x3 f1 X8 _' I
char name[20];
3 e) M( Y& K! C3 E* k! fint age;
- |0 z0 N/ m* Afloat salary;
* \2 H0 y- Q! {+ L, W} entry[20]; </FONT></P>
7 o. h3 I8 n, _4 W  H2 m  ?, n1 [<><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ + ^2 P. W/ v! ^, K* l) ~9 L$ R* ?
printf("\n\nPlease enter a label for the chart: "); 5 d' D2 ?+ x3 g! u
scanf("%20s", label); ( o  o. l5 B: J- h
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>) c+ ?' y1 y3 I0 I. {
<><FONT color=#0000ff>/* Input number of entries as an integer */ ' t7 B- C" s/ t+ R
printf("How many entries will there be? (less than 20) "); + `  s) t- w' J- L  ]- U
scanf("%d", &amp;entries);
# i$ }+ \6 _0 \0 U) efflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
" P0 K8 z8 l7 A/ P5 `: @( ~<><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */ + I9 \4 B5 U0 k: ?; J
for (loop=0;loop<ENTRIES;++LOOP) 4 `$ U* r2 ^% O7 t! ?) u! g
{ 9 [' a8 Z& i5 p3 u* U
printf("Entry %d\n", loop); 8 L# X: x# t7 r0 _$ ?0 ?
printf(" Name : ");
/ M+ c- X6 W: h* u2 |scanf("%[A-Za-z]", entry[loop].name);
- t/ C. r5 `% v! c/ @# Ffflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>5 S$ @) L3 N2 r) Q( g# X, n
<><FONT color=#0000ff>/* input an age as an integer */
% t8 c# `; }% r! j- j4 m+ s; V$ Cprintf(" Age : ");
8 o$ R  \. X9 v- c1 e+ A. {scanf("%d", &amp;entry[loop].age); . O+ L' _+ t' i( z( ?
fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>- b# S2 }8 z6 {7 `( \& y( E
<><FONT color=#0000ff>/* input a salary as a float */ . x- `3 x! ?: B# W
printf(" Salary : "); : P* f+ Y) ?( `( d3 T
scanf("%f", &amp;entry[loop].salary);
( e3 z4 I8 r% n3 s8 ?* d* `fflush(stdin); /* flush the input stream in case of bad input */
1 f; R' ?5 m  F. T$ I& T} </FONT></P>* Q. B- ^8 m' c$ v# o3 G
<><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */ 8 h% H% q0 D! ^- ^2 n( T
printf("\nPlease enter your name, age and salary\n");
/ }8 g! @% Y/ d% w* n" \- _% hscanf("%20s %d %lf", name, &amp;age, &amp;salary); 3 u6 @& x$ x, }$ H
</FONT></P>- m  i( b) a1 I$ V9 u4 n" S
<><FONT color=#0000ff>/* Print out the data that was input */ . V% |/ D' T- i" H! q
printf("\n\nTable %s\n",label);
: t! |( k) @3 B/ i4 s8 @2 B% mprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary);   s2 F( @, }2 [8 l" a
printf("-----------------------------------------------------\n"); ( i# H1 n# a- C1 k# P9 k7 F
for (loop=0;loop<ENTRIES;++LOOP) - i. R: j, `  R& ?  N. R: A. f
printf("%4d | %-20s | %5d | %15.2lf\n",
+ i' j$ C9 s- j# q3 tloop + 1,
2 ^/ z; u2 u% E4 a& centry[loop].name, 4 c4 v9 D, n* F" U7 G" U
entry[loop].age,
! G; B  I5 n0 _3 j$ o. N7 @entry[loop].salary);
$ a$ s* d- H" [  D; ]printf("-----------------------------------------------------\n"); " B+ w1 b* \! Y- {! j
return 0; 9 D3 z5 o/ y) e/ M8 d; B/ x
} # F# M* ^9 z- c: p8 e" B2 ?6 G
</FONT>  E% E8 U: Y- G+ E
</P>; s( }/ U! d, t% U
<><FONT color=#ff0000>函数名: searchpath </FONT>" U3 J, a% P' g( j8 U0 b8 X
功 能: 搜索DOS路径
+ j$ ~) ^: w" D2 Q+ g" Q# M! n用 法: char *searchpath(char *filename); % P8 D- Q7 e6 S6 P
程序例: </P>
* k1 ^% f* e$ W+ e8 P! X<><FONT color=#0000ff>#include <STDIO.H>
+ D" a' `' k5 w8 d' g8 {/ q9 U#include <DIR.H></FONT></P>
. C  v# D7 a" G" l<><FONT color=#0000ff>int main(void)
; t) s3 C9 \, S{
$ b$ M5 f+ n' H6 J* Xchar *p; </FONT></P>, z; i2 B- `6 r% s3 U- {5 t
<><FONT color=#0000ff>/* Looks for TLINK and returns a pointer
" L! q3 V2 b% c! r' ~to the path */
) x, E6 C5 ]( B- i, b/ }/ xp = searchpath("TLINK.EXE"); ; U* H2 @' F) y7 d4 h& ]* h5 c$ @5 X
printf("Search for TLINK.EXE : %s\n", p); </FONT></P>
7 D2 G6 s( l# O! C<><FONT color=#0000ff>/* Looks for non-existent file */
" z* C) p8 A+ [$ U/ ~p = searchpath("NOTEXIST.FIL"); . d- |; _$ S' n$ {7 S$ V
printf("Search for NOTEXIST.FIL : %s\n", p); </FONT></P>
& v9 E  F" s: ]  l# }0 s, D3 O! j<><FONT color=#0000ff>return 0;
1 t" {! Q( g& v' O( m}
, n1 U# n  X6 P( I( B' q+ `
- U/ h) k; q2 Z</FONT></P>% X- E/ R, ?" s) Q" v4 L
<><FONT color=#ff0000>函数名: sector </FONT>, L% Z3 H8 W% `
功 能: 画并填充椭圆扇区
0 Z7 p  \+ a0 u- C: e: S2 z用 法: void far sector(int x, int y, int stangle, int endangle);
' x+ \5 ^' I& C: A, g4 n' a程序例: </P>
$ Q) E$ U3 ]5 c4 W<><FONT color=#0000ff>#include <GRAPHICS.H>2 O3 F& b4 r; j; p9 |% D: ~! V
#include <STDLIB.H>
) }, s% E) T: \2 o1 e#include <STDIO.H>
% S! B& @5 V- U#include <CONIO.H></FONT></P>
# y7 B3 ]( c, U<><FONT color=#0000ff>int main(void)
1 A, U+ t! z2 f{
9 l; B, p; H4 h; f5 c2 @/* request auto detection */
6 A$ l0 k0 y2 Yint gdriver = DETECT, gmode, errorcode;
8 F0 T. v5 h* }7 yint midx, midy, i; ) s" l: e5 @' ^
int stangle = 45, endangle = 135; , E$ A5 {* }# _* t
int xrad = 100, yrad = 50; </FONT></P>
: y' u  Q  u5 i$ W7 S3 e; v<><FONT color=#0000ff>/* initialize graphics and local variables */ . e3 i- s+ I5 {  K" \/ g. r
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 T  N( i/ c/ O
<><FONT color=#0000ff>/* read result of initialization */ 0 `1 h+ R" t# o6 Y4 R" p' k& i
errorcode = graphresult(); % n6 c2 q( N. K
if (errorcode != grOk) /* an error occurred */ 5 ]1 E/ m2 {+ [# j- K1 j$ u) a+ l
{
" l3 r: P! }/ ?9 O- t  H$ H% n9 i* C& Nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
5 K, b8 \% f3 t$ X) |6 Iprintf("ress any key to halt:");
, U$ y" c& e) b! X5 C7 }8 m/ o  Zgetch();
  ^5 \3 D% m$ n( n8 F5 [# R5 q- _exit(1); /* terminate with an error code */
3 v/ h! g- ~; [$ C& ^+ z+ ^} </FONT></P>
- H5 ^! [' h! s- u: U& ]* O<><FONT color=#0000ff>midx = getmaxx() / 2; ! B5 {4 e. T7 A  S3 _
midy = getmaxy() / 2; </FONT></P>
, ], L5 n; H6 z6 r<><FONT color=#0000ff>/* loop through the fill patterns */ ) {, j  Y. x, J+ y! R5 E5 x
for (i=EMPTY_FILL; i<USER_FILL; <br i++)> { 3 T0 S7 x1 w# _2 s1 ]
/* set the fill style */ 2 n' Y% V9 A! ?1 q; J0 c9 X
setfillstyle(i, getmaxcolor()); </FONT></P>, x% e4 J: t* v" H7 F
<><FONT color=#0000ff>/* draw the sector slice */ ; w4 t: ?$ p, v& G2 `
sector(midx, midy, stangle, endangle, xrad, yrad); </FONT></P>
9 v5 e; M0 C* I# [2 T% L$ {<><FONT color=#0000ff>getch(); + a/ e3 S( O- a, J: c4 ]
} </FONT></P>
. w; F2 Q7 p7 B' m* d<P><FONT color=#0000ff>/* clean up */
8 v7 y  i; k6 r" A2 t* P" Cclosegraph(); , q# O* M& v4 ?# z/ E9 F* h- h
return 0; ! E8 H9 e$ j/ t! n, i1 B
}
* I- P2 X; K) N. C9 e' K</FONT></P>
4 O$ p& x5 o. _5 m, I  q<P><FONT color=#ff0000>函数名: segread </FONT>
0 e/ G2 D4 q: \( F2 [0 u功 能: 读段寄存器值
2 L4 _. T' b1 Y. H7 H7 Q用 法: void segread(struct SREGS *segtbl); . b; n. M9 M0 F7 R0 g3 t3 W
程序例: </P># e+ l+ q) X$ S2 p7 W5 W
<P><FONT color=#0000ff>#include <STDIO.H>
8 s# |, b" W) x#include <DOS.H></FONT></P>
7 a+ [3 t% c8 n* O. P  M: Z<P><FONT color=#0000ff>int main(void)
- s# X& S' x6 v" y" L5 t{ ) k0 L6 }/ n( k" e: u1 v
struct SREGS segs; </FONT></P>3 t! b& b3 N* L, Q
<P><FONT color=#0000ff>segread(&amp;segs);
( h: a7 ^0 j5 O1 B" P0 b9 \printf("Current segment register settings\n\n"); 5 X" e+ C2 h5 P! l+ _9 C5 ?7 L
printf("CS: %X DS: %X\n", segs.cs, segs.ds); 0 b  k' t7 w+ H" L* F9 Q  g/ {8 Q
printf("ES: %X SS: %X\n", segs.es, segs.ss); </FONT></P>+ m  n5 [$ @9 Y1 W0 c! @' a
<P><FONT color=#0000ff>return 0;
1 I4 s( K9 G5 E9 ^+ \, k& B} </FONT>
; h- m1 Z' ~/ P, w& b/ y6 }" X: {" R8 d* {: u; i" k/ V
</P>
7 t3 b1 C0 z7 P<P><FONT color=#ff0000>函数名: setactivepage </FONT>
# j8 T+ E" N& p7 g( m, N功 能: 设置图形输出活动页 ) D, O& y3 ]) f6 ^, f2 B
用 法: void far setactivepage(int pagenum);   H2 `( b, x6 H* S* v4 ]
程序例: </P>1 Q9 I; X: C, P0 o; s3 U- Y( ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>3 x2 {) q. F6 F3 z- z
#include <STDLIB.H>
$ t# l- j) M5 O2 E#include <STDIO.H>
" l, X8 \/ S- O# Z#include <CONIO.H></FONT></P>
* \7 n) Q& g' ]<P><FONT color=#0000ff>int main(void)
$ v( r- C0 a  n{ 0 b1 O$ c' y8 @2 p' D# ~* [
/* select a driver and mode that supports */ ! x- Z0 _2 G+ L& H
/* multiple pages. */ $ ]9 E9 e2 ?- T/ r
int gdriver = EGA, gmode = EGAHI, errorcode; 8 o) d1 }; \7 t" i: _4 {) e& K4 B' y
int x, y, ht; </FONT></P>8 a" j5 ^. Z3 e5 _( w
<P><FONT color=#0000ff>/* initialize graphics and local variables */
' T- r1 e! p* k2 rinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 S" |( V$ _: E% [<P><FONT color=#0000ff>/* read result of initialization */
0 S( H# V6 E' uerrorcode = graphresult();
% H  E/ O" K7 n. S, F' m% Vif (errorcode != grOk) /* an error occurred */ % P. N" q' L: e5 t. c
{ 4 q: p5 W' l) Y6 ?
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ' U3 I2 U' h! N) Q& ?) Y/ W! S
printf("Press any key to halt:"); . K  A' C0 _2 P* h' c
getch(); 2 b1 t' u% v( r/ e; I4 b
exit(1); /* terminate with an error code */
$ K* h, v' D) X) R} </FONT></P>
$ w6 n% _* w# W! D, r/ U<P><FONT color=#0000ff>x = getmaxx() / 2;
, P8 E1 a$ x  a. c& N8 }y = getmaxy() / 2;
5 F3 E0 ?4 M9 \) D' a3 |ht = textheight("W"); </FONT></P>
1 B1 l$ Y* s$ Y0 l3 F) U$ r<P><FONT color=#0000ff>/* select the off screen page for drawing */
3 R$ M8 E' T, hsetactivepage(1); </FONT></P>
9 K% V: @5 P: ]+ V( v; H" p<P><FONT color=#0000ff>/* draw a line on page #1 */ " c# M! U, _; J8 t& k' h
line(0, 0, getmaxx(), getmaxy()); </FONT></P>
2 y4 ]( v8 Y" Z" h& o7 v& E<P><FONT color=#0000ff>/* output a message on page #1 */ . {" `9 q+ P' r
settextjustify(CENTER_TEXT, CENTER_TEXT); ( G" H1 n: A2 G* P7 B$ s) t: s
outtextxy(x, y, "This is page #1:"); 5 V. [* C. ?5 s! \; T6 P
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>4 b+ M0 K6 G! l' G
<P><FONT color=#0000ff>/* select drawing to page #0 */ ; e& B7 I4 @, e5 f8 @. \, H6 T
setactivepage(0); </FONT></P>! a- h5 Q5 c# @, b
<P><FONT color=#0000ff>/* output a message on page #0 */
4 |$ M( B8 r  h4 V* Jouttextxy(x, y, "This is page #0."); & D1 l4 e5 Q% N$ ^3 P( m
outtextxy(x, y+ht, "Press any key to view page #1:"); 3 ~2 k5 S0 t, t0 g" N3 B. a  f
getch(); </FONT></P>
( `1 \3 y. h! L: y7 z+ {! }<P><FONT color=#0000ff>/* select page #1 as the visible page */
$ M. @3 Z) [8 j5 |: I9 Jsetvisualpage(1); </FONT></P>
' n5 Z. s* g# {, s5 y7 v<P><FONT color=#0000ff>/* clean up */ 8 U, T& D4 v0 j+ `/ j$ w6 D
getch();
$ W# ?+ p7 A* |( u3 ~' Q" Zclosegraph(); / v3 z  H0 Y" k
return 0;
3 {2 x$ }: e+ {3 q/ `( y! T} , [# P/ z0 T" x2 A( V
</FONT>
' ~- t& r! `- X" E. |6 F</P>/ ?1 q) I& M5 D* ^) Y
<P><FONT color=#ff0000>函数名: setallpallette </FONT>
+ D+ @4 I* ?7 S, m4 h# P功 能: 按指定方式改变所有的调色板颜色 0 [$ [& F4 x6 ^
用 法: void far setallpallette(struct palette, far *pallette);
# l; o6 m+ P& \  e# j: b* Y& H程序例: </P>5 m& E+ _7 r) |7 ^6 B) d1 n" P
<P><FONT color=#0000ff>#include <GRAPHICS.H>: r! h% @+ A& h# n( p8 R
#include <STDLIB.H>! O8 ^  K. i' d, h5 Y( {
#include <STDIO.H>
% {( z4 N0 J, E: K) @#include <CONIO.H></FONT></P>
$ G4 }( E) _( v" ?+ n1 Y/ c: M<P><FONT color=#0000ff>int main(void)   {/ p" s, w' ~3 o- T, B' t1 n
{
4 N$ W& a$ }0 G3 K% T+ i/* request auto detection */ ; p1 _( a& o3 u1 R2 O
int gdriver = DETECT, gmode, errorcode; # X8 r. f+ ]' C* @3 f# Q$ P
struct palettetype pal; + B- h' i' C; s6 |# h
int color, maxcolor, ht;
+ E1 g1 H5 @: Q5 l( Kint y = 10;
+ {" _* R* T$ z: y8 mchar msg[80]; </FONT></P>
- n/ e8 t& h: F. r2 K<P><FONT color=#0000ff>/* initialize graphics and local variables */ 2 R& _/ _% I5 f5 t. B
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" y# m6 W4 b! L% b! A<P><FONT color=#0000ff>/* read result of initialization */ 7 r; v7 p( z5 _2 \  V0 s
errorcode = graphresult();
2 J" ^! t  f; u: e  Zif (errorcode != grOk) /* an error occurred */
; L0 v* c. `3 q3 F$ y: S" w  A! n{
1 p5 C4 f) \+ l" A6 nprintf("Graphics error: %s\n", grapherrormsg(errorcode));
. a2 V1 J5 e$ Yprintf("Press any key to halt:"); 4 c+ X( s. F+ l, _  ~1 C
getch(); + |, g3 s1 O8 _3 e- A% c
exit(1); /* terminate with an error code */
+ X+ q4 U5 k" Z. a) b3 M3 m} </FONT></P>
5 T/ @5 R: o3 V; K: ^$ |) D1 `<P><FONT color=#0000ff>maxcolor = getmaxcolor(); : T5 x3 L3 x# Y3 o# v
ht = 2 * textheight("W"); </FONT></P>
! A, t( H& w. T" U& u5 E+ C' T# m<P><FONT color=#0000ff>/* grab a copy of the palette */
. p& v2 G" _' q7 U/ U( V0 c8 \& s* Fgetpalette(&amp;pal); </FONT></P>3 A; o+ G# X! e
<P><FONT color=#0000ff>/* display the default palette colors */
, z* u+ @& h9 h7 q7 A+ o, C; Ifor (color=1; color&lt;=maxcolor; color++)
0 n. P5 u& {' j% T$ r{
: K' \0 Y- P" U+ Ksetcolor(color); & D  P6 o! M# r, S$ r
sprintf(msg, "Color: %d", color);
$ U$ v1 w; y/ touttextxy(1, y, msg); 9 G3 }0 t1 ]7 h( t; V3 N! Q$ @* _1 Z
y += ht;
- K8 {* s0 |1 [2 R4 @} </FONT></P>
: z1 J' w- r& ]) {$ V! r( v6 r<P><FONT color=#0000ff>/* wait for a key */ 4 s  I' E7 j2 C- l) {  @! u& a
getch(); </FONT></P>
8 f+ M7 k4 j0 f. p+ |' T; W<P><FONT color=#0000ff>/* black out the colors one by one */ - b0 s1 x0 a# C8 z0 d: U
for (color=1; color&lt;=maxcolor; color++)
; b/ s" Y5 g" ]/ R{ 3 y8 W' T) p5 q3 `8 d
setpalette(color, BLACK); 4 Q7 ^0 e( v9 G: C5 r2 }
getch();   U3 r0 U2 R; D6 R) J+ K+ ]
} </FONT></P>$ b# y8 Y% e6 W# H2 s9 S. o& ^
<P><FONT color=#0000ff>/* restore the palette colors */
( u8 c: I6 T: K' n' usetallpalette(&amp;pal); </FONT></P>
# v* u6 \, f3 K) u2 |<P><FONT color=#0000ff>/* clean up */ / u6 z2 E, [1 H! d+ t# D1 K
getch();
. l% T" v+ V2 `, I; yclosegraph(); 8 y- k. Q1 \! U! r- ]2 D! _
return 0; ) ]$ I! p. E. h
} - @$ X+ b, U& \- c8 H
/ m) F1 s) n" u1 \. _
</FONT></P>8 h( C- ]/ N2 V+ y/ l; M' p
<P><FONT color=#ff0000>函数名: setaspectratio </FONT>
. g( J( ~! W2 r7 g3 p# C$ u0 p6 o功 能: 设置图形纵横比 + u( ^8 t2 v4 U; a  T& ]7 `
用 法: void far setaspectratio(int xasp, int yasp);
7 C  Q7 ]/ T5 y+ d2 C, t! X程序例: </P>
5 }8 T- ?+ l9 p+ Z7 @% s  k0 d( R<P><FONT color=#0000ff>#include <GRAPHICS.H>1 M! o) U. b2 @3 `) B' }" z
#include <STDLIB.H>
5 f2 |# t% X' j* _8 M) b#include <STDIO.H>
. {. s+ D/ }2 Y5 _7 n#include <CONIO.H></FONT></P>" W4 c; ?; \4 W' y! ?' _; c0 S
<P><FONT color=#0000ff>int main(void)
0 q: i9 O$ ?4 q- P  t) H! j{ 1 s; c3 n8 U" _9 Y
/* request auto detection */ 2 a: ?0 G( q; H4 Z
int gdriver = DETECT, gmode, errorcode;
% [* C1 p$ \4 Y2 h* L; ]" ~: Jint xasp, yasp, midx, midy; </FONT></P>
+ U, C0 s0 N  K7 W, X- I( y<P><FONT color=#0000ff>/* initialize graphics and local variables */
, ^% v: `* ]1 M4 ?6 Z: p8 M- Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>  w; b$ I- T& o" h) G9 ?6 i
<P><FONT color=#0000ff>/* read result of initialization */ ' l5 }* X: v6 e1 G1 T* H, n
errorcode = graphresult(); & j. l4 `0 t& Y, f/ x1 A' `  i1 U
if (errorcode != grOk) /* an error occurred */
/ x- }- d. t  G2 B' x, o% r{
( p9 X8 D5 w0 J& U; Pprintf("Graphics error: %s\n", grapherrormsg(errorcode));
/ f2 N" r) o* s! V' Lprintf("Press any key to halt:"); 6 P- |! \/ z+ X& Y4 d
getch();
* H& S& X) l% s( B* Eexit(1); /* terminate with an error code */
8 c; t4 o$ x8 e' r3 {, Q} </FONT></P>
: `% _% p4 }  Q5 O9 P<P><FONT color=#0000ff>midx = getmaxx() / 2; * R3 I; [; c: C
midy = getmaxy() / 2;
6 T( e* b3 }, F: ~. X$ @  lsetcolor(getmaxcolor()); </FONT></P>* R- G4 e! q3 Y# P/ U; ]% l9 b
<P><FONT color=#0000ff>/* get current aspect ratio settings */ : q8 x$ @0 c! ~( T' \" }
getaspectratio(&amp;xasp, &amp;yasp); </FONT></P>
/ @8 B0 J3 n. f- c<P><FONT color=#0000ff>/* draw normal circle */ 8 K! [2 [' i0 K7 Z* }
circle(midx, midy, 100); ) u3 N, k/ S5 q
getch(); </FONT></P>
& k8 B4 i9 f+ t" ~<P><FONT color=#0000ff>/* claer the screen */
( `* W4 W" k+ k4 scleardevice(); </FONT></P>
' r5 o* b+ B5 ^( X. z7 F<P><FONT color=#0000ff>/* adjust the aspect for a wide circle */
5 u& V9 E5 P6 F- b" o6 xsetaspectratio(xasp/2, yasp);
! ?+ }  s" U9 o+ V; Gcircle(midx, midy, 100);
  H8 K# ~# {) U: L, G* a8 Egetch(); </FONT></P>! J. i9 s7 m5 m
<P><FONT color=#0000ff>/* adjust the aspect for a narrow circle */ * p: b& s+ y# e6 m
cleardevice(); * R! e4 i6 K4 k
setaspectratio(xasp, yasp/2);
2 @7 D0 u/ V+ x- P& U* s! }. Pcircle(midx, midy, 100); </FONT></P>* d4 L& G$ F' n4 N4 u
<P><FONT color=#0000ff>/* clean up */ 1 h) v# z9 ?& _8 E; ~% r
getch();
( }# A0 F4 G0 W: s) Dclosegraph();
8 \8 q1 l% P4 n7 j1 J3 m9 Treturn 0; * ^4 m. `2 a5 v+ }5 B& k5 }; k* P) Q1 C# `5 f
}
0 s/ }9 g$ Q& {+ f</FONT>3 ]6 H1 t. m) e
</P>  t$ j/ b! l, D; L! e/ _: G
<P><FONT color=#ff0000>函数名: setbkcolor </FONT>
& F1 s6 m9 C+ C9 S/ L* C% K/ V功 能: 用调色板设置当前背景颜色 - h% Y$ a2 u' R6 E
用 法: void far setbkcolor(int color);
1 H, f: C! F+ s# ?5 E( Y: o程序例: </P>
0 t3 {& z3 r, L0 z" L<P><FONT color=#0000ff>#include <GRAPHICS.H>. j: n% P( E; ^! n) F! m
#include <STDLIB.H># ?8 W% a3 k) \6 h/ o
#include <STDIO.H>; @8 W2 H4 Z' Y1 \. v
#include <CONIO.H></FONT></P>; ^6 x  ^5 H4 A; |0 u6 t1 j1 e
<P><FONT color=#0000ff>int main(void) 3 t8 a' c) @; g9 w8 x' |. B
{ : X- `- _2 N1 J7 P; I! }
/* select a driver and mode that supports */
  c. Q4 c% O4 r3 G/* multiple background colors. */
# I  D% `. u' |int gdriver = EGA, gmode = EGAHI, errorcode;
$ L  q0 c: I  I" r* ~int bkcol, maxcolor, x, y; - r- H. |8 Q4 U4 n7 |9 J
char msg[80]; </FONT></P>* b0 P/ F8 v( R
<P><FONT color=#0000ff>/* initialize graphics and local variables */ ( j% g6 F6 N- M6 K
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! n# e. x3 w* f* t( `! }+ `
<P><FONT color=#0000ff>/* read result of initialization */
* ]/ ~- m& }! R- Z; G+ T1 M8 yerrorcode = graphresult();
  u8 j' u& P0 b( T8 sif (errorcode != grOk) /* an error occurred */ ! C0 A% c4 o$ A' d
{
! n, v0 {/ F4 o9 H  w2 N4 U2 zprintf("Graphics error: %s\n", grapherrormsg(errorcode)); / E, Q+ M2 E' F+ \. ~
printf("Press any key to halt:");
' C; g9 ?2 H( p: Fgetch();
8 [* O& B* M& `1 ~$ d& V7 `8 Qexit(1); /* terminate with an error code */   f9 T- J% ~! ?. K: W% G) ?
} </FONT></P>
& u& k8 p3 w( V5 c. @% B8 t<P><FONT color=#0000ff>/* maximum color index supported */
9 ]4 G) u8 L2 A0 B5 Kmaxcolor = getmaxcolor(); </FONT></P>
# G0 P# |3 W  K) l! F) a<P><FONT color=#0000ff>/* for centering text messages */ 2 `8 g7 d* ?/ r" N1 \, h; Q* a
settextjustify(CENTER_TEXT, CENTER_TEXT); 0 ~# i) ]# k8 I* ~- T6 ]- g
x = getmaxx() / 2; 9 I' R$ _& _9 _. ?! v: `
y = getmaxy() / 2; </FONT></P>
( P( }, m- L% O<P><FONT color=#0000ff>/* loop through the available colors */
. ?' n9 H- B6 E# }8 Vfor (bkcol=0; bkcol&lt;=maxcolor; bkcol++)
- W( ^9 V, f. R! W4 f4 p; [{
- X7 m5 A# \7 ~/ o1 O  ?- G" l/* clear the screen */
% F/ f$ P# O3 Y+ l; a+ scleardevice(); </FONT></P>
3 Q4 T5 ^1 T2 H: C# ^  h! V<P><FONT color=#0000ff>/* select a new background color */
* h; N6 f0 W8 fsetbkcolor(bkcol); </FONT></P>) s. y5 Y- |9 f2 N
<P><FONT color=#0000ff>/* output a messsage */ ( A. R/ L- h2 ^, L- Y7 Z0 e5 H
if (bkcol == WHITE) 9 s( S7 n8 z0 i9 W( r
setcolor(EGA_BLUE); , V2 V! m# s6 s1 Z9 t/ }
sprintf(msg, "Background color: %d", bkcol); ' X2 C$ w) ]1 j, ?7 \" Q! U- |# g6 D( z
outtextxy(x, y, msg);
* f2 `  O. w( f9 D0 Lgetch(); / \& _6 x" I, x* M- s6 p- `
} </FONT></P>
: x+ x" `" Z% w( n<P><FONT color=#0000ff>/* clean up */ & O, i3 b% B9 T9 T
closegraph(); : e& S7 l; ]! ]5 G7 t0 j: a, z
return 0; " I( y: f' r8 g/ q4 S6 l, l
} </FONT>
8 r# d+ P: z' t, Q9 ]+ q" ^' x* ~* M
</P>
! M8 g- z# U1 [0 s2 W<P><FONT color=#ff0000>函数名: setblock </FONT>
3 J1 D7 U. X  e/ ~- f$ \功 能: 修改先前已分配的DOS存储段大小
% e$ s# L+ K7 s, N( z用 法: int setblock(int seg, int newsize); " g( [6 I0 y# w( C6 {( ^* I
程序例: </P>
0 z5 E8 J) b. \2 h<P><FONT color=#0000ff>#include <DOS.H>6 p9 g* r' n  W
#include <ALLOC.H>5 m4 q5 O& e$ X% P, u  \
#include <STDIO.H>
# r( r( [2 U) a: h1 v0 |#include <STDLIB.H></FONT></P>
! e0 s. I/ S* Y. p( U- m# @5 h<P><FONT color=#0000ff>int main(void)
) k: m3 w8 H8 ]: F- B{
0 k+ o* t; t( E: l* X. tunsigned int size, segp;
5 i* z: \1 {2 ]7 c1 qint stat; </FONT></P>
( A/ o. d5 l' l" N( W<P><FONT color=#0000ff>size = 64; /* (64 x 16) = 1024 bytes */
; u& A& {3 C9 }" L- A* Pstat = allocmem(size, &amp;segp); 1 d! P; @5 s5 Q3 ]+ j
if (stat == -1)   X7 r( l+ |, f/ v' C0 ^
printf("Allocated memory at segment: %X\n", segp); + j, P8 A" \, E; A4 |+ W4 H9 n% G
else # o! x* o5 U: Y3 r4 F( v! f
{
$ I4 o$ x; _$ l0 g3 O5 Fprintf("Failed: maximum number of paragraphs available is %d\n", 8 f9 t0 E* O* ]  M+ c! g2 B9 B, K
stat); 2 J. m* s' V# L" ^: m
exit(1); 6 P( D0 |: ]& y8 m+ h, J: z
} </FONT></P>
( ?7 V& n4 u' k! g" o2 T<P><FONT color=#0000ff>stat = setblock(segp, size * 2);
% K$ m4 o+ d1 n4 I* x* `( Rif (stat == -1)
; O# F3 Z( p, w( X2 n6 Eprintf("Expanded memory block at segment: %X\n", segp);
. y; u8 u/ C& l% ?6 g) \8 n& b! yelse
; g; z1 X9 u" A! U' U. a# K& y- ~printf("Failed: maximum number of paragraphs available is %d\n", " X: h  S( Z9 C( w
stat); </FONT></P># e  g( o3 n; e- U, }
<P><FONT color=#0000ff>freemem(segp); </FONT></P>
  n3 o4 x2 s4 d; N<P><FONT color=#0000ff>return 0; 5 Q  F3 r' N' W+ @( S: a* {) c1 `
}
( f# G4 Z  _, I1 T! c' @</FONT>/ u0 X" {3 C* {$ r6 T2 i% t* B
</P>
+ N& R0 a7 v3 A: A' M) }# G/ I<P><FONT color=#ff0000>函数名: setbuf </FONT>
- j5 i) @& W9 ~6 b" b! f# h功 能: 把缓冲区与流相联 ' G6 Q/ G1 W3 R2 X1 `3 p
用 法: void setbuf(FILE *steam, char *buf); 8 v2 Q% |1 Y% I
程序例: </P>% K( U! ~1 G$ y
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>) x& r7 o; }+ I8 f+ c' D7 J
<P><FONT color=#0000ff>/* BUFSIZ is defined in stdio.h */
3 y7 Y% ?1 Q8 F! D$ Mchar outbuf[BUFSIZ]; </FONT></P>
: p' Z. N2 d2 J& _5 p<P><FONT color=#0000ff>int main(void)
7 c6 p' l, X4 g$ k$ r{
6 B5 @7 I2 Z+ n  D( Q0 l/* attach a buffer to the standard output stream */ ' P( L5 w! t9 @
setbuf(stdout, outbuf); </FONT></P>
* J( A$ Z$ D( w4 j- }  n<P><FONT color=#0000ff>/* put some characters into the buffer */
* _9 D: u* q% z, Q0 N1 rputs("This is a test of buffered output.\n\n");
0 D1 i) q" c; F9 l6 A$ S' C) bputs("This output will go into outbuf\n");
1 D: Q6 I: I: N" bputs("and won't appear until the buffer\n"); - g( A4 R# T; r; @1 w( i
puts("fills up or we flush the stream.\n"); </FONT></P>& Z2 g" P) m8 i1 E& K* ?7 B
<P><FONT color=#0000ff>/* flush the output buffer */ 7 E: h0 B" R' b4 I
fflush(stdout); </FONT></P>
+ o" g/ \+ n- a<P><FONT color=#0000ff>return 0;
5 P0 _1 H) k6 z}
4 H3 Z8 ?2 N+ \- q* Y; O: w/ O- Z</FONT>
. c! Y" @0 c0 i! m5 K2 o</P>8 D& q+ i% G6 R$ O4 K
<P><FONT color=#ff0000>函数名: setcbrk</FONT>
% `: v4 G9 {) q% Z+ k# O. S; `功 能: 设置Control-break % d' j. E5 h8 l# B
用 法: int setcbrk(int value); 1 R1 s) L& j8 n- s. B6 u0 U, N5 V
程序例: </P>
  B- J; i( u8 v+ S& S' k! j7 d! I<P><FONT color=#0000ff>#include <DOS.H>
9 Z/ B. E7 @- P" q: R% [, h#include <CONIO.H>" t. G9 V6 ~/ C7 A/ ~
#include <STDIO.H></FONT></P>  N) B5 d! j3 D* I$ a! H
<P><FONT color=#0000ff>int main(void) 7 H5 z4 v5 i" o) a2 l
{
7 l3 n7 P* L) M1 hint break_flag; </FONT></P>
7 X" O, r  ^0 h. d<P><FONT color=#0000ff>printf("Enter 0 to turn control break off\n"); $ T& O& d9 p4 n$ O
printf("Enter 1 to turn control break on\n"); </FONT></P>: d$ g: G7 v4 w: W5 S: X
<P><FONT color=#0000ff>break_flag = getch() - 0; </FONT></P>: d1 @' Z. Z, v( E! D1 \* [
<P><FONT color=#0000ff>setcbrk(break_flag); </FONT></P>: N# L9 j& k  o
<P><FONT color=#0000ff>if (getcbrk()) 4 Q+ a7 C2 ^# N% l. U6 A
printf("Cntrl-brk flag is on\n");
! i  p6 m  z1 U' f1 Q1 Z' o" Selse . K6 k: s; U7 T$ w7 X; a
printf("Cntrl-brk flag is off\n"); 2 \0 s9 G# E3 C) X6 L  X3 S* p
return 0; , T! o$ ]2 ^" Z; P& P
} 0 G: N7 T0 L* Z% ^3 D8 Z

% y" J- s% |9 B; [1 v7 w4 L</FONT>
* C: C& B; o2 |</P>$ x* d/ |  t$ z" i1 {% N- M, _8 M( q; }
<P><FONT color=#ff0000>函数名: setcolor</FONT>
- G/ K: ~: H6 e1 N功 能: 设置当前画线颜色 3 L, l  Q& b: B0 i2 H
用 法: void far setcolor(int color);
0 Z3 D. _4 q/ R& g7 n" l4 G/ \+ T4 `0 Z程序例: </P># o: m# \9 [. p% v' J/ o
<P><FONT color=#0000ff>#include <GRAPHICS.H>
: ~8 k( k% t1 w! u! W, V& i#include <STDLIB.H>$ O( F9 e$ M* `! c
#include <STDIO.H>/ @% ]% m. ]0 L( S. v
#include <CONIO.H></FONT></P># F* t, Z3 h+ `* R
<P><FONT color=#0000ff>int main(void)   f3 f& s& x6 ^, ]1 c2 S3 J' u4 a
{
& S4 V& S2 k+ m5 I4 x$ `$ ~: a/* select a driver and mode that supports */
4 A5 N2 X: I0 g1 t$ t/* multiple drawing colors. */ + S  m. p6 A) n$ j) s
int gdriver = EGA, gmode = EGAHI, errorcode; * K4 s+ J6 `4 C8 i8 i
int color, maxcolor, x, y; * `& ^0 F4 N5 i& G! L( W
char msg[80]; </FONT></P>2 x; _0 [9 k! ]9 ]
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - h/ c4 D& Z, h& t
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 O" n. N+ i8 _. I7 X# E5 N- C<P><FONT color=#0000ff>/* read result of initialization */ 6 r& [. I; l0 C8 Y$ b  c% E
errorcode = graphresult(); " s6 V2 n0 B0 L5 a* z2 n4 |
if (errorcode != grOk) /* an error occurred */
3 u2 B! h+ {/ ]% {7 U) j4 P$ Y; U{
4 z- N5 P/ C' O4 T# M' eprintf("Graphics error: %s\n", grapherrormsg(errorcode)); : j2 h( E9 d5 w8 d2 _
printf("Press any key to halt:");
, y6 ?# ^) X. v6 ?& ugetch();
! [: {  o" B) ~( ?9 x1 @exit(1); /* terminate with an error code */   o8 Z: Y' M( d  Z9 V5 Z3 ?4 X
} </FONT></P>4 l4 w: L. E# \. b$ r8 j, Y5 g
<P><FONT color=#0000ff>/* maximum color index supported */ ( Z+ k( i* W1 K7 C  }6 h
maxcolor = getmaxcolor(); </FONT></P>8 t0 ?7 C/ s2 X7 L2 q
<P><FONT color=#0000ff>/* for centering text messages */ 9 q! y9 U1 r: w4 Y
settextjustify(CENTER_TEXT, CENTER_TEXT);
. d4 h" b3 \# L/ I! g" dx = getmaxx() / 2;
, S+ o: L6 W& [, O- o" y8 N7 Gy = getmaxy() / 2; </FONT></P>
8 ]: J2 \7 v  I1 ~4 D0 I<P><FONT color=#0000ff>/* loop through the available colors */
+ T- [8 @; E; z% E% Z& }for (color=1; color&lt;=maxcolor; color++)
4 O: L* W/ \, T& ]{ 4 r4 R7 R" c8 y: o* {( r; N% w
/* clear the screen */ " I# M4 a. H8 h7 J) Q
cleardevice(); </FONT></P>9 W/ k; ^; G7 N
<P><FONT color=#0000ff>/* select a new background color */ 2 B0 F6 S$ |$ `6 e1 d
setcolor(color); </FONT></P>$ r9 I( v1 D4 X  e) X& @1 }
<P><FONT color=#0000ff>/* output a messsage */ & }2 H) _) }! J
sprintf(msg, "Color: %d", color); ; x3 i, |' W: Q) H, w7 {, \9 S
outtextxy(x, y, msg); 1 B" j: w4 }7 x8 f
getch();
" \# k) P, X, I4 ]# V! ?} </FONT></P>$ \; U# D! X6 U; k  Q# S2 _
<P><FONT color=#0000ff>/* clean up */ , f4 \" G2 @( n. l% y6 R5 |
closegraph();
* ?& I! M: ]6 s( i& l+ ?return 0;
& l, g0 g) q6 m5 h3 q1 l& k* {} 9 o* n+ S8 ^8 M5 n% E5 i- `! I
</FONT>
+ C9 i& x, u' N. L' M</P>
7 J5 ~' Z$ a% T  L<P><FONT color=#ff0000>函数名: setdate </FONT>
/ k7 A/ I" @' |1 I  x$ z功 能: 设置DOS日期
6 s) g% ^6 O7 J4 x7 n5 E用 法: void setdate(struct date *dateblk); 6 e/ p* [! W2 K% t. h7 Q9 \0 g9 |
程序例: </P>9 P) I, c" x; o; Y8 c
<P><FONT color=#0000ff>#include <STDIO.H>
) }$ H. r4 {6 H' u3 k#include <PROCESS.H>
3 f$ d' T- m, @3 c( _# e5 e#include <DOS.H></FONT></P>
8 M$ N, |8 M. ^' j4 B<P><FONT color=#0000ff>int main(void) ( t' @7 N4 {9 I0 t  a" J: I9 |
{
" f. K: L) e# N: |- c  dstruct date reset; 6 f7 e8 p% p& s" g' A2 M( ~0 u1 I( v
struct date save_date; </FONT></P>/ x" d( v& M, g
<P><FONT color=#0000ff>getdate(&amp;save_date); / v  k0 J/ A4 z: O1 |6 v9 ]2 A" x
printf("Original date:\n"); ) k: F! ?$ o; ~. @4 G4 m
system("date"); </FONT></P>
5 A+ {/ p+ y; x- k/ ]5 ~6 [<P><FONT color=#0000ff>reset.da_year = 2001;
0 m# X* l* e, Q; z, u, I- V  Lreset.da_day = 1;
1 A+ w- r* p6 H+ ]9 Ureset.da_mon = 1; ; T, t" Z0 g! Q# f' W( B  h
setdate(&amp;reset); </FONT></P>
! Q5 t8 Y( c- L& y. ^<P><FONT color=#0000ff>printf("Date after setting:\n"); ) x) c8 @% j2 ]5 n! {' {3 m2 D
system("date"); </FONT></P>
5 ^- p/ p) h' n2 e4 m+ Q<P><FONT color=#0000ff>setdate(&amp;save_date);
9 b& n+ k0 f2 B2 W2 A& rprintf("Back to original date:\n");
8 S7 m( R' R8 O9 [system("date"); </FONT></P>) N5 G2 [8 ]1 ^2 }7 }! y
<P><FONT color=#0000ff>return 0;
6 U2 Y- O+ `6 X5 K* E3 |6 _& |9 b}   V+ @" T! n3 L6 B, d. L& }5 g$ g
</FONT>
% z5 f- R9 L( Z; s</P>" V3 ]: b) m0 N
<P><FONT color=#ff0000>函数名: setdisk </FONT>2 N! [7 s( Y7 E5 e
功 能: 设置当前磁盘驱动器
0 A$ R# J. ]7 N用 法: int setdisk(int drive);
3 Z3 P0 y( {/ d( u0 [/ H8 q; t程序例: </P>+ o  O) j" T- n3 w4 _, ?
<P><FONT color=#0000ff>#include <STDIO.H>" ~$ Q% c) r+ d1 w; O# d! O6 H
#include <DIR.H></FONT></P>
( e% p& g4 u. l9 e8 p6 K  S) _<P><FONT color=#0000ff>int main(void)
3 K# `* p, E( S7 p2 @1 a* a3 i6 r{
& u/ d, X: ?$ wint save, disk, disks; </FONT></P>
& K6 Z- ^# A! v! q7 J* g' h! O2 b<P><FONT color=#0000ff>/* save original drive */ 4 n# }; @; W7 `2 p. H
save = getdisk(); </FONT></P>0 \. {3 x& a% E* e. k
<P><FONT color=#0000ff>/* print number of logic drives */
8 M1 t2 M6 l1 @' W, h3 ^  ydisks = setdisk(save);
$ X, j- o4 B* `: t* d* hprintf("%d logical drives on the system\n\n", disks); </FONT></P>
+ [6 Y  P1 M+ b& p* ?$ N<P><FONT color=#0000ff>/* print the drive letters available */
4 e- }8 i7 S5 @) e' P; X4 oprintf("Available drives:\n"); 7 j5 C& P7 ]3 _/ F+ F
for (disk = 0;disk &lt; 26;++disk)
3 N' J% X8 W1 ?0 q. e{ + w4 p$ _; r  q8 l- g! e. K
setdisk(disk);
0 t8 e- E" P! H% }" Q( fif (disk == getdisk()) ! b: k- s( J' K" F9 [
printf("%c: drive is available\n", disk + 'a');
5 C2 l4 l* p: k  T} 3 w) O/ X( M5 z! ?5 U
setdisk(save); </FONT></P>
; C) I$ Y; f/ c5 t; n<P><FONT color=#0000ff>return 0;
3 u6 }4 D& }; N; Z. k, ^4 X$ ~} </FONT>
. B: A4 h, O: V6 b
6 @5 p- [* E) B1 R</P>
2 y8 e& Z2 A- O; o<P><FONT color=#ff0000>函数名: setdta </FONT>
8 h% X& U3 g5 L% _/ N9 G( x# J) H- J, G功 能: 设置磁盘传输区地址
$ H( x; y3 f0 p# ]) l0 C用 法: void setdta(char far *dta);
; Z# M. m" W( F程序例: </P>
8 h9 c' X$ c2 m- o+ R<P><FONT color=#0000ff>#include <PROCESS.H>
) c/ ?# z, E" G3 [% t#include <STRING.H>  |0 \8 G+ S4 R8 {( q3 u% m
#include <STDIO.H>
3 V) b4 ~/ F8 z. Q- v; W) P8 a#include <DOS.H></FONT></P>: O$ z$ c- _' ?* a' @
<P><FONT color=#0000ff>int main(void)
# J. f/ D  n8 K% G- S) B( d{ ) f7 U6 u( v" S/ P
char line[80], far *save_dta;
) q$ Z- I( |3 h! Xchar buffer[256] = "SETDTA test!"; - \4 f: h' L9 u# z4 C' ^
struct fcb blk;
2 H4 k) B" t, s: T* Z6 f4 Mint result; </FONT></P>
# b1 M$ M- o# K: T7 m  Y<P><FONT color=#0000ff>/* get new file name from user */ ( E8 ^* X1 w4 x7 }  y
printf("Enter a file name to create:");
6 A0 y: n3 K% g* [) e( y: O( J) |gets(line); </FONT></P>
$ N* f; \9 `2 t$ _<P><FONT color=#0000ff>/* parse the new file name to the dta */ & \. S3 }# D" l8 b( J& B
parsfnm(line, &amp;blk, 1); 5 D" ?+ i( G- T+ }# c: g) [3 u5 Z) W
printf("%d %s\n", blk.fcb_drive, blk.fcb_name); </FONT></P>
& T9 `, F& |( X1 e: e<P><FONT color=#0000ff>/* request DOS services to create file */
3 G5 |5 ^; B  c: ~* d% Vif (bdosptr(0x16, &amp;blk, 0) == -1) 7 b3 e( S! x1 M9 z! X: |# M
{ . p  y# ~; {  A, n) e4 h
perror("Error creating file");
' n* A$ w- N# V1 Y: O- Aexit(1);
- g, X  m7 C- p3 A: |$ \' k1 L} </FONT></P>3 n5 K4 A8 s$ J/ t: T1 x3 p2 J
<P><FONT color=#0000ff>/* save old dta and set new dta */
6 D% t: h/ v+ msave_dta = getdta();
; |" u. A7 J% d, U4 Tsetdta(buffer); </FONT></P>0 [  ?! c6 Z  \6 A" Y7 Q' J
<P><FONT color=#0000ff>/* write new records */ # E: O/ q; U/ {- y- y
blk.fcb_recsize = 256; 9 p, H* f0 P8 Q5 }" G( k
blk.fcb_random = 0L;
" c, w! M; ]$ r- u- f  Lresult = randbwr(&amp;blk, 1);
! y( |! m% c- y, O3 l6 X- aprintf("result = %d\n", result); </FONT></P>1 Z& v+ l! t; [8 ^
<P><FONT color=#0000ff>if (!result)
( X! Y0 X% a7 t; z8 ^1 rprintf("Write OK\n");
0 r- w; H. E  O1 h  Relse - x# S0 s  m) p/ L8 C; g
{
0 w/ [. |; x7 a2 sperror("Disk error");
9 \1 d& }, |7 Y9 b! Kexit(1);
3 j% Z$ U; O- }} </FONT></P>
) b7 g& l' j& T& e<P><FONT color=#0000ff>/* request DOS services to close the file */ - \4 D& m% W& U* I, ]8 G
if (bdosptr(0x10, &amp;blk, 0) == -1)
8 f, [  X! u5 g# y: h) E1 @1 ~* f{
# ]6 ]& \- i2 v; K4 Eperror("Error closing file");
9 z: y# W3 t; F1 xexit(1);
( k& f9 G7 m4 j: o& e* T; K} </FONT></P>
# S; N3 J. o8 B0 [. y: f, h9 d<P><FONT color=#0000ff>/* reset the old dta */ ! I- d4 R3 T2 s: V2 ]
setdta(save_dta);
! V2 w$ K' Z2 breturn 0; 7 i/ v) ~7 a2 ?7 `# r
} 4 M  s9 G+ e/ j3 Y; _# m
</FONT>
- c! ~9 P5 n2 ]6 y3 ]8 H2 D% M</P>
( M& x  s( _1 r6 H1 Y<P><FONT color=#ff0000>函数名: setfillpattern </FONT>
) Q2 S8 [% g$ B! S2 a9 Y功 能: 选择用户定义的填充模式 1 \6 _' J% r$ g. |1 r1 r, K: X
用 法: void far setfillpattern(char far *upattern, int color);
( \% S+ ~1 `1 T* d1 @: ~  b程序例: </P>
5 v: g0 S9 x) L3 N2 z3 E# E8 ~<P><FONT color=#0000ff>#include <GRAPHICS.H>. u: z9 G) h4 o1 i" g, B
#include <STDLIB.H>
4 |7 V7 ]( J, t#include <STDIO.H>
) H. ?( p7 e/ c, s  f9 Y* o" }; i$ W#include <CONIO.H></FONT></P>
  I8 r5 J( r! N, x2 y; |6 K<P><FONT color=#0000ff>int main(void)
  X3 m/ S0 _3 C$ J" W) y{
7 l# e' S2 N+ z' Q. x& j/* request auto detection */   c  |# }  i* p' B$ _( [1 _( s
int gdriver = DETECT, gmode, errorcode; 4 }6 g+ H, w3 f: j
int maxx, maxy; </FONT></P>+ a  T5 Z2 j8 J0 j
<P><FONT color=#0000ff>/* a user defined fill pattern */
# Q$ A0 y2 {9 ?$ s; Y& o' uchar pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00}; </FONT></P>0 A: m, c' x: [, v% W, S8 f+ S
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 g8 z- q; s8 \6 O8 h
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 C* {3 g! d0 q* g5 G<P><FONT color=#0000ff>/* read result of initialization */ & J& L1 ~3 \1 d7 _1 v
errorcode = graphresult(); 5 S0 }& D& K/ o  b% @
if (errorcode != grOk) /* an error occurred */ 6 B- I! B. s4 m: O
{ % ]; t5 d2 o6 j* A8 p, G8 H4 f
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ) \. q8 ]; W, ~% [
printf("Press any key to halt:");
8 n4 @( E" X) F5 i! y% Y! zgetch();
: o7 J$ u9 L  E! B+ y, Wexit(1); /* terminate with an error code */ 0 j0 t4 [* ~) ^3 \
} </FONT></P>
! B" N# u" \8 D<P><FONT color=#0000ff>maxx = getmaxx(); 7 [# Q3 a: O+ Q! r0 A* c4 ~
maxy = getmaxy(); / U2 c- t& w/ Z( w. V  x
setcolor(getmaxcolor()); </FONT></P>
% u; r; X5 c0 _. e; d/ S<P><FONT color=#0000ff>/* select a user defined fill pattern */ " z5 Z0 O8 u/ e9 @
setfillpattern(pattern, getmaxcolor()); </FONT></P>
- T8 Q. S# ~7 r, g  t' y* V+ N1 B7 U: r<P><FONT color=#0000ff>/* fill the screen with the pattern */
8 \8 Q/ v8 m  R9 @6 }9 fbar(0, 0, maxx, maxy); </FONT></P>
, g3 o) m& q2 e" n" m' r<P><FONT color=#0000ff>/* clean up */
. q6 O# m0 h5 o3 e( ]7 Egetch(); & F# l, ]+ I! {; _* T
closegraph(); % Q# u; [  h% Z6 S" u
return 0; 2 r" F: n) n* F5 J
} ! O# y1 F6 Z1 B, g
</FONT>
+ t: O: Z, \% s. t7 {; M</P>
% U1 s1 q7 b) U, b& R* o  H' z2 C<P><FONT color=#ff0000>函数名: setfillstyle </FONT>
9 Q, f) W" I: N- O6 _* E+ a8 K功 能: 设置填充模式和颜色
+ ]# d( e/ [# o) ~" a8 Q$ F用 法: void far setfillstyle(int pattern, int color);
* W) ^5 X8 L/ y程序例: </P>" C1 d0 M+ B3 W2 n; V. M+ S6 p
<P><FONT color=#0000ff>#include <GRAPHICS.H>$ {) h9 @" q: m# P! H
#include <STDLIB.H>; Q+ T5 A% |. {5 T3 b& X4 F
#include <STRING.H>
5 R9 V! S1 Q. N' v* J#include <STDIO.H>
2 ^/ }4 U8 O) S#include <CONIO.H></FONT></P>+ a3 R# q2 v1 g" y- d+ b% ^
<P><FONT color=#0000ff>/* the names of the fill styles supported */ ) y/ @7 k  K, v  U
char *fname[] = { "EMPTY_FILL",
8 A. m- n! L6 P! V( n# t"SOLID_FILL",
! Q; E4 k: _$ m, u4 W- j"LINE_FILL",
1 A  J1 @2 Y% P1 A* g"LTSLASH_FILL", : R; h# ~/ ?6 W) b+ K; s+ Y
"SLASH_FILL",
9 \$ n! r' @. ~! U" q5 d"BKSLASH_FILL", & }2 U1 A( s3 H1 f; O" o5 F
"LTBKSLASH_FILL",
1 Q7 G2 `+ O7 d) T/ ?( W, H( |"HATCH_FILL", . ^. D5 X1 O+ `" r3 P
"XHATCH_FILL",
4 S+ p, E& R# I# i/ Z( p+ ~8 |2 s"INTERLEAVE_FILL", : t$ D% T  g+ Q* l' ]
"WIDE_DOT_FILL",
, C' M0 c# T) O' V4 ]"CLOSE_DOT_FILL",
+ _3 I) L( R# y7 E9 C, L. e) C"USER_FILL"
5 U7 T: t+ \% c- R5 ~  W}; </FONT></P>
: a$ y4 k; V9 k$ ^7 Z" }7 e; p3 E<P><FONT color=#0000ff>int main(void)
, l" o) l% ~) H5 w' h) }" ^{
; L4 O/ X, m( G& k1 j8 E0 P  V/* request auto detection */ . Q* M! Z, a" q7 C
int gdriver = DETECT, gmode, errorcode; 1 x6 T1 x# _* x, K( p
int style, midx, midy;
+ B* t, V- C. Q' f8 cchar stylestr[40]; </FONT></P># W& R. j5 e$ L- s5 u3 n& n* @# x
<P><FONT color=#0000ff>/* initialize graphics and local variables */ - p% L9 R$ [* Y8 w8 L" Y
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>2 T3 P8 @6 l2 V1 ]% l1 w. O9 O
<P><FONT color=#0000ff>/* read result of initialization */ ! Y4 t4 u! v* N
errorcode = graphresult();
" b( @: |. a: X- @5 Yif (errorcode != grOk) /* an error occurred */
+ ~# ~" g  c0 n5 f( a{
% B0 |) C; Y# D3 T$ Sprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 3 e- @2 O. ]% L. N& f. L
printf("Press any key to halt:");
) S- s+ q/ p! T' tgetch();
4 Y" b0 c4 H; \' k& m" f2 [$ texit(1); /* terminate with an error code */
6 C; n$ E) w7 }/ B4 G+ P$ m} </FONT></P>
( z6 Q! o: N, M/ {' b<P><FONT color=#0000ff>midx = getmaxx() / 2;
: o5 \- W0 W  X" Y  l/ Amidy = getmaxy() / 2; </FONT></P>
% L9 u! m9 [( _/ Z- p<P><FONT color=#0000ff>for (style = EMPTY_FILL; style &lt; USER_FILL; style++) 2 L- o7 P! Y7 L( }, a
{ + x# r/ Q5 J: ]# q
/* select the fill style */ ) q$ y/ D+ D/ ]0 D9 \
setfillstyle(style, getmaxcolor()); </FONT></P>
( _# K& e* V2 P<P><FONT color=#0000ff>/* convert style into a string */ 3 F7 d  g  F6 z7 X! n' G
strcpy(stylestr, fname[style]); </FONT></P>
/ n5 e) W+ s" g- r7 |+ i<P><FONT color=#0000ff>/* fill a bar */ 9 k& R2 F8 n1 S+ t4 }$ X, ~8 O$ _
bar3d(0, 0, midx-10, midy, 0, 0); </FONT></P>* E& F& Q: i# r, c+ K7 L9 ~
<P><FONT color=#0000ff>/* output a message */   _4 q' ~. |1 s4 P9 @
outtextxy(midx, midy, stylestr); </FONT></P>
3 g% e$ D0 P& {# ]<P><FONT color=#0000ff>/* wait for a key */
& q/ ^7 y8 s; Dgetch(); 2 `3 B9 @; o6 z5 N- n
cleardevice();
8 I6 u( w' c  S1 R" o9 M& ~2 L} </FONT></P>! {% H: W& j$ Y" [. }* z, j- R: x
<P><FONT color=#0000ff>/* clean up */
' K3 y/ I; u( E7 z/ sgetch();
0 }3 g5 \: n& e. U; sclosegraph();
: n6 O1 T5 q. v+ Y* @! A" Preturn 0;
, f8 i6 u) E* p: x9 s: a, B} </FONT>4 h6 Y  \2 V6 _7 I
3 o! x' n- |: @- z8 Y8 O" R; s
</P>
; ?* l5 e& C& t4 y! J<P><FONT color=#ff0000>函数名: setftime </FONT>
  ^9 g% I# Z( Q功 能: 设置文件日期和时间 # Y4 P6 P0 q! ]) \+ {/ s
用 法: int setftime(int handle, struct ftime *ftimep); : X6 S" i+ V3 y3 v& j8 N1 G, Y6 N
程序例: </P>
3 ]: E* E: a: a- m7 H* G+ \4 Y<P><FONT color=#0000ff>#include <STDIO.H>
9 _0 [4 @/ w  O: J; C2 X  ?1 h#include <PROCESS.H>
' x$ ]1 `) E3 F#include <FCNTL.H>' ?, I  h) ~9 P; M  S
#include <IO.H></FONT></P>
$ R3 D4 k0 j& J+ A$ Y) e+ s* n<P><FONT color=#0000ff>int main(void) ' }5 ~# K5 ?' e- ?
{ % G9 L1 M+ h8 B4 U
struct ftime filet; 4 D9 P2 N+ h$ m: H- ~( s9 H9 o* h  F
FILE *fp; </FONT></P>
, A  T8 |4 P/ ?& R( D1 B. Q<P><FONT color=#0000ff>if ((fp = fopen("TEST.$$$", "w")) == NULL) # Z1 M* t" V0 P% r+ O
{
/ n% ?- t- \1 T; }  rperror("Error:"); ' e- f( K$ p4 A6 h9 F- m% C
exit(1);
) ]7 m- x% `0 R} </FONT></P>
6 r- w+ ~! a4 J% V4 @% H<P><FONT color=#0000ff>fprintf(fp, "testing...\n"); </FONT></P>2 W& ]1 w; b2 L9 F5 P& {& {
<P><FONT color=#0000ff>/* load ftime structure with new time and date */ " }3 A3 E4 U, d# |& _( i
filet.ft_tsec = 1;
2 [4 m) v, g1 ]5 cfilet.ft_min = 1;
" t2 O0 e9 B7 A- b2 e: D& Bfilet.ft_hour = 1; 0 l+ ]6 Q3 a- |9 ]+ H" y
filet.ft_day = 1;
" T  N0 `! }* L. f# xfilet.ft_month = 1;
! e. p; I. I' G2 ]" [1 ufilet.ft_year = 21; </FONT></P>1 T3 k$ b9 k! F( ]- B
<P><FONT color=#0000ff>/* show current directory for time and date */
* f1 U; t1 f1 J- }0 m4 Osystem("dir TEST.$$$"); </FONT></P>% B$ F" |- c/ R) y/ F
<P><FONT color=#0000ff>/* change the time and date stamp*/ " I* g4 ~9 z) K" _+ }
setftime(fileno(fp), &amp;filet); </FONT></P>
' a( Q4 t8 m& M9 t<P><FONT color=#0000ff>/* close and remove the temporary file */ ! T# B: }5 g" V' u0 B" Z
fclose(fp); </FONT></P>
9 q; s. M8 T. n<P><FONT color=#0000ff>system("dir TEST.$$$"); </FONT></P>
, o; c9 t4 s- G/ y3 F( Y" Y<P><FONT color=#0000ff>unlink("TEST.$$$"); 7 Q2 z  I& e# O8 _
return 0;
$ v# C8 \' f( a: C' I) H}
9 ?; \+ [  L9 J& {% R</FONT>
2 i" ]/ R; |# k2 s( y3 K</P>
# L+ X% V: E; `- {" A<P><FONT color=#ff0000>函数名: setgraphbufsize </FONT>
/ L. w1 r& s- c功 能: 改变内部图形缓冲区的大小
# K3 Y/ e$ z' ]+ B3 \用 法: unsigned far setgraphbufsize(unsigned bufsize); : P- x$ P6 a& ?: f/ e5 i; j3 T
程序例: </P>
$ u/ [- g' {9 J6 e* x" x<P><FONT color=#0000ff>#include <GRAPHICS.H>
6 D' P( `' }0 }& e; S8 ~#include <STDLIB.H>, _9 ?; t  j4 R7 f0 }7 G
#include <STDIO.H>2 s4 ?: g$ B6 x% T
#include <CONIO.H></FONT></P>
% O2 i4 v  g8 O* W1 E  K6 H<P><FONT color=#0000ff>#define BUFSIZE 1000 /* internal graphics buffer size */ </FONT></P>4 Y' _5 A" W7 q7 K
<P><FONT color=#0000ff>int main(void) / P2 f. H- n/ m
{
- j9 Q  Q# x7 g( D" c/* request auto detection */
% A/ e- R! Q4 X2 m1 Oint gdriver = DETECT, gmode, errorcode; ) u: j5 K- i: x. j
int x, y, oldsize; ) l. S: @/ ?% F8 g
char msg[80]; </FONT></P>
# u$ r& c9 V0 Y% c0 b<P><FONT color=#0000ff>/* set the size of the internal graphics buffer */ ( Z4 x0 Z( N0 T
/* before making a call to initgraph. */
7 ^, J! N# h% M/ Ioldsize = setgraphbufsize(BUFSIZE); </FONT></P>
# e# H* k, n+ Z! O<P><FONT color=#0000ff>/* initialize graphics and local variables */ 6 r. g  m3 |6 ^
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
4 M/ _& c! ?% B! O. K8 B& y<P><FONT color=#0000ff>/* read result of initialization */ ; t# h# l) {) R- Q6 t& B) D
errorcode = graphresult();
" y3 U  O  g: s+ s( Y: wif (errorcode != grOk) /* an error occurred */
6 Z+ L4 d. H& Z) [. n' g) P{
9 z0 Y* x& c1 `2 pprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ; g/ X3 ?% K& a3 ]% k; _
printf("Press any key to halt:");
7 c9 u0 Q+ J( ]6 ?( Fgetch();
# [4 B! s+ X9 s) Q0 G: c+ ?exit(1); /* terminate with an error code */ ! K/ p7 v& L6 `$ V
} </FONT></P>
) R( R  z6 V: G3 C7 v$ \& D1 z<P><FONT color=#0000ff>x = getmaxx() / 2;
3 }2 ^$ S& W7 U, n8 F2 My = getmaxy() / 2; </FONT></P>
2 G! a- c! J; U/ K) W<P><FONT color=#0000ff>/* output some messages */   J% u, H& ^0 {. I- X# k5 C& t
sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
( ?% l% S/ Z; y! K# Ssettextjustify(CENTER_TEXT, CENTER_TEXT);
7 l/ @/ v/ R7 couttextxy(x, y, msg);
: Q1 F6 D4 }/ Zsprintf(msg, "Old graphics buffer size: %d", oldsize);
9 B* b3 E( G5 C; K, X( Bouttextxy(x, y+textheight("W"), msg); </FONT></P>; W. _9 v2 ~6 u3 U5 }+ D
<P><FONT color=#0000ff>/* clean up */ 2 k7 n2 U: O6 G/ t/ Z1 A
getch(); 3 H6 ^1 |+ ]6 r) h5 |2 k
closegraph();
8 Z; U8 ]3 b! @1 P; Oreturn 0;
1 R, ^# q3 O5 w+ Z# M7 U# D1 t}
8 i+ t( M% q$ d& Q
3 o+ c# _% x3 g4 j6 q& E9 z7 c% ~
</FONT></P>
9 q6 |( x0 B. y3 o<P><FONT color=#ff0000>函数名: setgraphmode </FONT>+ r7 q& z/ e) n; ]9 K
功 能: 将系统设置成图形模式且清屏
: O+ V0 j& E5 @& O. B: w用 法: void far setgraphmode(int mode); - ^! H1 H8 R  \
程序例:
. N9 K" x" f) P: I, z. ?# y9 O9 W7 T" b
<FONT color=#0000ff>#include <STDLIB.H>
. ]$ H* X; d* ?0 t9 W$ Z4 `#include <STDIO.H>* N+ n( o" @+ q' [* E/ @
#include <GRAPHICS.H>#include <CONIO.H></FONT></P>
+ Z8 Q/ l6 ?2 P+ |; @2 w0 N3 r, k<P><FONT color=#0000ff>int main(void) 1 F* M4 A! I8 n
{
: `% B5 ^6 ^' F3 ?" T2 O( A: a1 ^/* request auto detection */
% k3 E. P3 O2 j3 A9 Q% k8 aint gdriver = DETECT, gmode, errorcode;
7 T; U! x' F& ]0 i, r4 j7 c) xint x, y; </FONT></P>5 D' f# y/ F2 A' v4 S
<P><FONT color=#0000ff>/* initialize graphics and local variables */
6 a$ m$ [$ G, V5 h" _initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 u6 z7 p7 G2 Z) I6 P+ x6 M
<P><FONT color=#0000ff>/* read result of initialization */
$ L% L* j% e7 k* ]errorcode = graphresult(); : n5 Q6 Y! ]9 c1 B( q( c
if (errorcode != grOk) /* an error occurred */ 5 {8 Z7 w) o9 ^1 w0 a; |
{
. V7 g/ e8 O( y/ X- P# |( Y% N2 Yprintf("Graphics error: %s\n", grapherrormsg(errorcode)); 4 V5 k" ?1 @& j
printf("Press any key to halt:");
4 x+ O2 m' z7 W* a. egetch(); ! z: z/ E9 z4 R. r  a" V
exit(1); /* terminate with an error code */
/ o+ V/ a1 b1 C. t- M. n- d} </FONT></P>
* \- k' F6 F2 A: f. I* G<P><FONT color=#0000ff>x = getmaxx() / 2;
0 u, e" i2 M/ I/ Uy = getmaxy() / 2; </FONT></P>
& w7 S5 h2 T9 [& F* x  r  x# z<P><FONT color=#0000ff>/* output a message */
% i( R; q/ D* {, c8 f3 dsettextjustify(CENTER_TEXT, CENTER_TEXT);
9 E1 v+ y7 g5 Z6 u0 F5 zouttextxy(x, y, "Press any key to exit graphics:");
* D8 Y! S  z6 I  `  Fgetch(); </FONT></P>, D; w$ i, }: ^7 j5 [$ z' y
<P><FONT color=#0000ff>/* restore system to text mode */
3 z, d' H; ]  r$ s1 n6 s! R! v* jrestorecrtmode();
& c5 d* v8 I6 k7 ~# w' m0 B9 \printf("We're now in text mode.\n"); # {- k- V% g) {2 q
printf("Press any key to return to graphics mode:"); - _3 c8 Z, i1 S2 ^) B4 n
getch(); </FONT></P>
; ]. T' s4 ^5 v% [$ E. I<P><FONT color=#0000ff>/* return to graphics mode */
: V3 {% F, I( {0 g$ I* }$ esetgraphmode(getgraphmode()); </FONT></P>6 K: ~, |3 ]+ c, N8 s
<P><FONT color=#0000ff>/* output a message */
3 Q+ w7 a) \; G3 ksettextjustify(CENTER_TEXT, CENTER_TEXT);
( K4 c: X- c9 B! Zouttextxy(x, y, "We're back in graphics mode.");
& l) |8 a7 `! A; i+ |outtextxy(x, y+textheight("W"), "Press any key to halt:"); </FONT></P>
, f- N+ J5 x# C+ X; h<P><FONT color=#0000ff>/* clean up */
2 C; L+ F6 H7 wgetch(); 1 \; L& T+ I* N, u2 U
closegraph();
; Z. K  e4 d6 t% Z* C+ }# sreturn 0;
8 t( A5 z4 `4 u! I% C6 w' y} & o2 W# q7 |: Y0 t% H2 ^
, J/ m% c, ^" s9 }1 u

6 B1 ?! s9 B7 o; d6 x' s% c</FONT><FONT color=#ff0000></FONT></P>
7 U% V# X$ x% K9 I<P><FONT color=#ff0000>函数名: setjmp </FONT>2 m% n! k! V  `; F8 ]: A' z
功 能: 非局部转移 / J7 c, l9 E! h% i
用 法: int setjmp(jmp_buf env);
% ~( b( f. F! X1 `程序例: </P>
' L( f: s/ H5 X<P><FONT color=#0000ff>#include <STDIO.H>
0 n! n- S5 W, ]6 u4 l#include <PROCESS.H>% I2 ^& N( T. u1 I
#include <SETJMP.H></FONT></P>. ?) G* d4 S' P
<P><FONT color=#0000ff>void subroutine(void); </FONT></P>  P# [, m5 s. a& F# f5 @6 e
<P><FONT color=#0000ff>jmp_buf jumper; </FONT></P>) C: F) ~: r& P! J: p$ Y! P
<P><FONT color=#0000ff>int main(void) 0 Q3 I5 x3 f4 p# A4 E
{
' m2 }- J, c; uint value; </FONT></P>
; q8 n# N: \; c$ Y, s5 a6 A3 i! u+ A<P><FONT color=#0000ff>value = setjmp(jumper);
% n  q& B2 C7 ]/ {, gif (value != 0)
' J6 V3 ~5 S. H7 U) H6 S% o{
+ b$ T: v; m4 X+ F, Y: G5 k6 Aprintf("Longjmp with value %d\n", value); 9 s/ r8 c( Y; M% U* @! k
exit(value); 9 j) D: @! \3 F( k( {
} 4 o/ H$ ~4 t% A6 a# H
printf("About to call subroutine ... \n"); / P1 V; [- v- n
subroutine(); ' c* Y: z& n3 s( S4 K/ J
return 0; : J$ A+ D7 G0 Q! `1 a- x0 g3 Z1 Z0 v
} </FONT></P>
8 D( z6 |5 O2 p2 O0 y0 r/ \<P><FONT color=#0000ff>void subroutine(void) % T2 m% m5 U7 c% Y" u3 e( H
{ # \. ~* t1 B. i0 |; [
longjmp(jumper,1); ' r3 c4 T3 t8 p+ l5 v, r& x3 T3 J
} . U! x2 v* P1 b8 G8 K- a  p
</FONT>
- e- E& C1 [4 x" C% m5 [: o: h</P>
: P$ |: P" N4 s0 L' n<P><FONT color=#ff0000>函数名: setlinestyle </FONT>
+ L: A2 z1 M6 ^5 w0 d( J3 w功 能: 设置当前画线宽度和类型
5 h) M8 ?  `+ _) E用 法: void far setlinestyle(int linestype, unsigned upattern); ) K9 x8 F, j- [9 ]; _$ P3 z
程序例: </P>
: W. V  n+ {' C& ~8 L<P><FONT color=#0000ff>#include <GRAPHICS.H>$ J4 s- Q) V; ?' E$ F  E6 T
#include <STDLIB.H>
7 z6 Z! v# A& _. I- }#include <STRING.H>) v: i0 O' E8 z5 q- o: Y
#include <STDIO.H>
/ o' m2 g0 j$ @+ e: x3 ?0 g; ]#include <CONIO.H></FONT></P>3 u6 a; _8 a/ z
<P><FONT color=#0000ff>/* the names of the line styles supported */ # G, U: O; p# G
char *lname[] = {
' |- v. Y9 W% w- }6 ]"SOLID_LINE",
3 A+ B2 O( H! T  w5 N"DOTTED_LINE", * p1 z' W8 p# M, k- ]
"CENTER_LINE",
2 g, E% `" `& U  C+ v& z  T"DASHED_LINE",
8 s: ?* H8 e$ ^' }& \! J# W"USERBIT_LINE" * {1 x( h7 z1 `/ d4 q
}; </FONT></P>
4 ]1 c& q) U! s& X9 |5 b<P><FONT color=#0000ff>int main(void)
# ]9 `* A7 m7 w{
+ Y7 l* ?' F# ]$ x/* request auto detection */
6 A$ O# Z2 q. y- oint gdriver = DETECT, gmode, errorcode; </FONT></P>3 w. g" y) Z# k6 w6 ^# j1 b
<P><FONT color=#0000ff>int style, midx, midy, userpat;
/ y% W9 G& L! a3 g+ s; k; Gchar stylestr[40]; </FONT></P>2 W7 Q: A0 x4 j+ a' h
<P><FONT color=#0000ff>/* initialize graphics and local variables */
- O: L( E4 L7 I) P* X- ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 y$ H1 ]$ D' ?; a2 t$ k
<P><FONT color=#0000ff>/* read result of initialization */ : S" |* E) E7 ]4 R+ y0 G4 ]0 ]; G7 M
errorcode = graphresult(); 5 ]. c( ]4 J5 k' ~2 t
if (errorcode != grOk) /* an error occurred */ 1 \' i3 p* w) C3 p
{
' F" u1 a8 M8 `$ d$ o4 }( Y* Iprintf("Graphics error: %s\n", grapherrormsg(errorcode)); ) b- `7 q* N2 U6 i* Y
printf("Press any key to halt:"); 4 ^8 E5 P' |2 ]! F
getch(); ( ^0 V) i7 |( n1 W
exit(1); /* terminate with an error code */
, I& `2 J  s- U& t& l7 B  P} </FONT></P>1 B. s& J: [8 m0 N& C
<P><FONT color=#0000ff>midx = getmaxx() / 2;
0 s# J6 M) }7 P. f7 [  Tmidy = getmaxy() / 2; </FONT></P>
, }) j& w) g( D+ P<P><FONT color=#0000ff>/* a user defined line pattern */ . `; b- z) [6 M+ b* C# L" y
/* binary: "0000000000000001" */   B& `7 k2 z' p. p9 p$ F" n, X' w/ Z
userpat = 1; </FONT></P>
7 ^" p" U% d: N+ H+ K3 b% c3 L& `<P><FONT color=#0000ff>for (style=SOLID_LINE; style&lt;=USERBIT_LINE; style++) 9 `" V1 j; w- x, V; |* s5 w) q
{
8 p* [0 W" d5 X) @/* select the line style */ : E0 l3 `# r0 f
setlinestyle(style, userpat, 1); </FONT></P>
8 g  }% B1 e/ y/ K0 I<P><FONT color=#0000ff>/* convert style into a string */
* M- Z" R1 i+ u7 Y* Y1 \6 q) xstrcpy(stylestr, lname[style]); </FONT></P>  N7 v7 Q* o( `5 e1 R3 ?
<P><FONT color=#0000ff>/* draw a line */ ' v$ P# N1 k1 [: m
line(0, 0, midx-10, midy); </FONT></P>) ]8 V# ?5 [! o
<P><FONT color=#0000ff>/* draw a rectangle */
& [4 n. `3 O7 f) t& F1 a5 [+ frectangle(0, 0, getmaxx(), getmaxy()); </FONT></P>
0 |2 ~0 j% G: v. k9 f3 z<P><FONT color=#0000ff>/* output a message */ 0 a$ y2 Z) w; k
outtextxy(midx, midy, stylestr); </FONT></P>' G0 H$ a6 C8 ]) I
<P><FONT color=#0000ff>/* wait for a key */
& l1 q" M8 g5 D8 \getch(); 2 y) n( E7 W$ L- {4 `8 }
cleardevice();
. \) b3 U, z" c! Q% Q} </FONT></P>
* X* W- |0 k' H; G) m! h- _; _<P><FONT color=#0000ff>/* clean up */
) r. d7 c" a- L3 @/ rclosegraph();
7 Z) u/ t$ X1 \3 `return 0;
& J& E( h3 o3 B; G, ?. [} </FONT>
" ~$ h9 l2 l4 G0 B: }
" q1 T6 H7 _, @7 b! |5 y% s2 l  s4 H9 x. V# u* y' s+ [. F
</P>( [( [  G$ l% l: H6 {  k- D- V
<P><FONT color=#ff0000>函数名: setmem </FONT>
# F1 Z/ F% @* ^* }2 }功 能: 存值到存储区
% ^) R; R( k7 e7 \1 g" W9 {用 法: void setmem(void *addr, int len, char value); # Z1 U6 W+ \' u- o) ~
程序例: </P>
2 p3 h2 b6 s* _4 [4 C- ^<P><FONT color=#0000ff>#include <STDIO.H>
7 D. W& K0 K' n; J  w9 J- b#include <ALLOC.H>
& o1 b% [3 b5 B' v9 V& \! Y#include <MEM.H></FONT></P>
9 X- _: ?1 W: u  U+ x<P><FONT color=#0000ff>int main(void) + _8 C, R; ?3 o, n, M
{ 6 ?# s! `4 a3 Z; X9 x2 X! v
char *dest; </FONT></P>* q7 Z) U! Q' q& t! i$ `1 f& L9 a
<P><FONT color=#0000ff>dest = calloc(21, sizeof(char)); ( O7 t1 s7 B4 C
setmem(dest, 20, 'c');
) l5 U7 S! \, J+ E& k3 Hprintf("%s\n", dest); </FONT></P>9 F* a! G. |4 k7 {* \; C' P* M+ V; Z
<P><FONT color=#0000ff>return 0;
& f  W( H4 Y5 C6 N. G9 [5 u} </FONT>' D) d; @( j6 h6 o( ^3 Y
- h' Z, A  c7 G  o( a) K" {

* V! `8 L# {4 n</P>
6 y( F9 A7 ?4 S' X, l; w% Z5 `<P><FONT color=#ff0000>函数名: setmode </FONT>* W+ l4 M. B4 y% a1 h' `8 M
功 能: 设置打开文件方式 , `4 n! q8 V' b( V
用 法: int setmode(int handle, unsigned mode);
3 C5 t7 H9 e& ~程序例: </P>
, O8 B1 U0 l2 _, N<P><FONT color=#0000ff>#include <STDIO.H>) U$ J& \2 T" K; h* z
#include <FCNTL.H>
8 Y8 H0 s- U  ~( T#include <IO.H></FONT></P>1 l% t6 J" e; Z4 X
<P><FONT color=#0000ff>int main(void)
  W! F% ?& q  r: s- F1 S3 D9 g{ 9 I: a6 v$ N' i# K/ a2 X9 T5 c7 k' M! m0 L
int result; </FONT></P>
! j7 `# A6 t8 x* P- Z( C' e4 V+ j<P><FONT color=#0000ff>result = setmode(fileno(stdprn), O_TEXT); ; s' g  f  u, [/ p
if (result == -1)
; s$ {' H' @1 }. ], gperror("Mode not available\n"); 1 \, Q: P# f) W  ^. d
else + g$ m9 P* c/ A( J/ l, L- @
printf("Mode successfully switched\n"); ; ~0 K( ~2 G$ U! i
return 0; 3 d) |' ^7 R9 N8 K
} 2 m8 e/ i7 J: e$ `% a+ R
; y. `" P4 W. b. {* V' }7 T7 Y
</FONT>1 m% a/ o8 u2 i' _2 e& w5 b
</P>
* A6 ?0 C6 l1 Y. C<P><FONT color=#ff0000>函数名: setpalette </FONT>5 D$ v4 x: R; L+ X- ?1 K1 N
功 能: 改变调色板的颜色
( l7 t* N- U  R( k& z8 D9 o用 法: void far setpalette(int index, int actural_color);
; g1 N1 T8 |2 d2 @7 j程序例: </P>
- O  n5 u' [1 S  [6 c: O2 U<P><FONT color=#0000ff>#include <GRAPHICS.H>
5 J8 n" f2 x3 ~#include <STDLIB.H>, }: `) S$ k9 \- T6 s6 `
#include <STDIO.H>
. R, u  m/ W: S, h. Z0 N#include <CONIO.H></FONT></P>
8 t. Y2 m6 V0 b1 P- Y! G0 [<P><FONT color=#0000ff>int main(void)
* E3 K6 K4 ~, S! j8 g{
% Q6 J4 Q! E( B5 s8 w8 W/* request auto detection */
2 E0 ^9 z/ J5 J) Nint gdriver = DETECT, gmode, errorcode; ( j+ R8 z6 T8 R3 s: K
int color, maxcolor, ht;
* h' [+ X7 f8 Y. v, _int y = 10; 2 ^( r! }- e, g6 _
char msg[80]; </FONT></P>
  q4 o& D1 N) D<P><FONT color=#0000ff>/* initialize graphics and local variables */
$ `$ Z7 o  w* h0 q5 R  r7 kinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
* w/ Y5 B6 R& ?<P><FONT color=#0000ff>/* read result of initialization */ . K# v0 M- J* i/ t
errorcode = graphresult(); $ }# X0 t4 t* J9 ~- @
if (errorcode != grOk) /* an error occurred */ 9 |, z$ E, g' A, r- I# M" G
{ ; l& {4 E, z) ?$ H2 }& u$ Q, _
printf("Graphics error: %s\n", grapherrormsg(errorcode));
' k0 C* P9 C/ p% }0 O6 o5 j* }printf("Press any key to halt:");
7 b2 M% s, F' F; C) Kgetch(); ) L8 P) l; u7 E' {- r) s
exit(1); /* terminate with an error code */
3 v& V2 ^( ^$ n8 q; D$ U0 G} </FONT></P>4 e7 c# M( J, D1 @
<P><FONT color=#0000ff>maxcolor = getmaxcolor();
' O0 [9 D. H0 Q! tht = 2 * textheight("W"); </FONT></P>
! y( a) L9 U7 J<P><FONT color=#0000ff>/* display the default colors */ ; N3 n; ?! _2 ~
for (color=1; color&lt;=maxcolor; color++)
& t2 B% N- q6 Y4 |8 y{ 7 G- c1 B/ U; H* b& S# C! I$ p/ ]
setcolor(color);
) G; D3 a: V6 n& Isprintf(msg, "Color: %d", color);
4 ?" z2 p' C3 h6 R. T- z8 B7 Aouttextxy(1, y, msg); 9 B: J6 ^" k0 q
y += ht; 4 D8 W  u+ C4 v
} </FONT></P>+ W! n2 v4 g% M4 D/ s# r( B
<P><FONT color=#0000ff>/* wait for a key */
& H5 D6 D; }$ w2 i5 s7 cgetch(); </FONT></P>: K; k% w! d, D1 _6 m
<P><FONT color=#0000ff>/* black out the colors one by one */ 8 T5 ?  l  K, `  F
for (color=1; color&lt;=maxcolor; color++)
, `8 j) Y0 {5 e{ ' a6 [: g2 k% ?
setpalette(color, BLACK);
  b; z- e. Z7 kgetch();
% W5 ^* h2 j; X8 u( l- b, F& Y} </FONT></P>
- C; D: h) s; l' a3 F/ i, H8 ?<P><FONT color=#0000ff>/* clean up */
1 b+ I% [: C) I+ _closegraph();
- Y9 F; f6 b" R& W7 Y5 X2 w' o5 t2 Breturn 0; + e9 w# ~8 R# m; H
} 7 u: Y& ~& @5 P3 N
</FONT>4 v# r3 Z9 g, p* v# j; z9 U
</P>
4 o5 H* G3 w7 W<P><FONT color=#ff0000>函数名: setrgbpalette </FONT>
: p+ h* M4 h% m+ S% [功 能: 定义IBM8514图形卡的颜色
, Z1 x4 }9 s' P用 法: void far setrgbpalette(int colornum, int red, int green, int blue);
9 L- p4 ?2 \$ J$ v, x1 B程序例: </P>0 q. O- f; n& a+ s- E
<P><FONT color=#0000ff>#include <GRAPHICS.H>
+ g  H$ N. V2 ]#include <STDLIB.H>
  n  T; E$ X3 a#include <STDIO.H>1 j3 ]8 L& M; ?/ q
#include <CONIO.H></FONT></P>5 l% ~1 ]% d. S8 ^2 Y4 R; N
<P><FONT color=#0000ff>int main(void)
# P! r1 b: }1 d$ @/ {  h9 u4 m{
' c+ P+ i4 E$ l2 {, Y/* select a driver and mode that supports the use */ . G/ h, E, \2 [: x% t) p# G
/* of the setrgbpalette function. */ ( L  l1 A# U1 g; G3 r% v
int gdriver = VGA, gmode = VGAHI, errorcode; . u! C: l. x4 P& ?% l! N, z% i
struct palettetype pal; # |# y" ?( e& `2 R
int i, ht, y, xmax; </FONT></P>
/ k9 x7 F- H' ^- [+ g<P><FONT color=#0000ff>/* initialize graphics and local variables */ % J0 w  i! ^7 |" L% o. l. W
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
# p1 y; {$ F. u7 w6 M8 y7 B<P><FONT color=#0000ff>/* read result of initialization */ 5 V+ V' O- S8 l' K( Z
errorcode = graphresult(); 8 \2 w. J" V) T
if (errorcode != grOk) /* an error occurred */
7 Y" r! [4 w, ]. P& G' N{ ( v( A" c( F8 S3 D1 c
printf("Graphics error: %s\n", grapherrormsg(errorcode));
0 I! i/ V+ L' _  j! @7 Xprintf("Press any key to halt:");
; d* o3 u  q5 s  p/ s' \getch();
( Z5 R  H5 Q! R& \exit(1); /* terminate with an error code */ * Y0 L: [, g$ Q& a. Z. p
} </FONT></P>
- N5 k' K6 }: z# Q<P><FONT color=#0000ff>/* grab a copy of the palette */
$ z( Z- e8 w8 [, F5 ?getpalette(&amp;pal); </FONT></P>4 l& t7 x( ]2 q) @+ [0 H" F
<P><FONT color=#0000ff>/* create gray scale */ ' X& b& e5 w9 s
for (i=0; i<PAL.SIZE; <br i++)> setrgbpalette(pal.colors, i*4, i*4, i*4); </FONT></P>2 m  s' |& f/ M  J, ~8 {2 i
<P><FONT color=#0000ff>/* display the gray scale */ 8 ~9 i5 F6 _% S& P: B7 O% g
ht = getmaxy() / 16; - X# i( u7 h5 [* {( o. d- C) a2 X1 F  i
xmax = getmaxx(); ( |1 V5 J; M' V) y
y = 0; , ^7 z5 j/ l- m9 q! ~% Q* Y! h
for (i=0; i<PAL.SIZE; <br i++)> { , p# Q6 h# G7 S) m
setfillstyle(SOLID_FILL, i);
! ?4 ?! `, B4 I4 N+ {bar(0, y, xmax, y+ht);
9 R/ H* ?- n' b# ]4 \y += ht; 3 u; G; e- Y. ?( B3 w8 a# B7 S4 c
} </FONT></P>( A( @* [- L( Y: [5 V
<P><FONT color=#0000ff>/* clean up */ # B, d  z) C/ V/ L; ]9 \
getch(); & Y$ r: D) r0 I% U
closegraph();
4 I: D7 y- d; F/ areturn 0; 0 d- f6 G; ~/ V8 |! [. b) f
} 3 l5 d4 @% R( w& H2 }
</FONT>$ j" q6 k- m! h! _6 L
+ s: \4 R4 w0 a. f6 E" T1 R
</P>
' C3 x6 R2 L" _5 ?<P><FONT color=#ff0000>函数名: settextjustify </FONT>* r- d/ `+ F% P
功 能: 为图形函数设置文本的对齐方式
5 k- ^& d4 s5 s* q用 法: void far settextjustify(int horiz, int vert);
9 D. x9 v7 e2 O程序例: </P>
0 g. e5 y% \. o0 b9 T7 z0 j<P><FONT color=#0000ff>#include <GRAPHICS.H>
# f6 R9 _) z2 ~: M; a2 X#include <STDLIB.H>: t6 s# z  S5 |
#include <STDIO.H>
0 i# a6 s' ]& |! a6 [#include <CONIO.H></FONT></P>
: X- G$ L; C' g; U* E- i<P><FONT color=#0000ff>/* function prototype */ ) C  M9 k/ X! w6 g" R( o' S
void xat(int x, int y); </FONT></P>
' G# }/ o5 }: Y. a; o5 m1 @  p<P><FONT color=#0000ff>/* horizontal text justification settings */
+ Y! _8 V$ \5 U/ J2 `. Pchar *hjust[] = { "LEFT_TEXT",
3 `( j5 l# N# I2 O5 ]9 O"CENTER_TEXT", 7 J6 k6 W5 o2 O+ c
"RIGHT_TEXT" ; W- l/ B; w  u
}; </FONT></P>
. m4 U) F: S, R9 ?- L/ i<P><FONT color=#0000ff>/* vertical text justification settings */
2 O% T) H3 `4 w# N# G/ C9 gchar *vjust[] = { "LEFT_TEXT", / \- F$ S0 B9 L& S/ P/ J3 N4 f
"CENTER_TEXT", / P' V9 u; ~6 f  X
"RIGHT_TEXT" / x: n& W# q8 Z$ g) j, d/ q, n
}; </FONT></P>
7 |# `# x/ c5 W7 ~; e<P><FONT color=#0000ff>int main(void)
+ `; T8 |7 O9 @* s  b  L, x  d{ ; o- J* ?& G2 H& W2 s+ r$ f% l
/* request auto detection */ 6 P7 Z1 g7 Z# w% W
int gdriver = DETECT, gmode, errorcode;
0 d* P* D) c7 T% \8 s' Q/ tint midx, midy, hj, vj; * P% S) ~8 o) {7 n: H
char msg[80]; </FONT></P>. d* ~* a1 e- ^# G( ~0 V1 J
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 5 R) u( C7 k  b& b% [( l* q1 U
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: U: R, C' w5 a8 ~+ m& N6 U<P><FONT color=#0000ff>/* read result of initialization */
. k. l2 @: m! P8 r/ x7 C7 `errorcode = graphresult(); & W$ U. k, q" G
if (errorcode != grOk) /* an error occurred */
/ n2 H% G8 u0 n6 K- U2 d1 A& y{
# g$ F. a7 {9 E! ^0 e! l% ?3 F( ?printf("Graphics error: %s\n", grapherrormsg(errorcode)); " j' J' B2 V! R$ v! N1 A
printf("Press any key to halt:");
5 a+ ^' u  V! N1 ~* h7 ygetch(); # ?, T7 _! T. T& K
exit(1); /* terminate with an error code */
3 q1 w8 S( ~% C- }0 D} </FONT></P>
: ~. k1 i5 R8 C4 F<P><FONT color=#0000ff>midx = getmaxx() / 2; : [0 \* S( r5 K/ l8 i
midy = getmaxy() / 2; </FONT></P>
6 m# C! K. ~! c! m<P><FONT color=#0000ff>/* loop through text justifications */
' M; q& r( b( U$ w; qfor (hj=LEFT_TEXT; hj&lt;=RIGHT_TEXT; hj++) + E8 C  c- T( g2 c: U$ h
for (vj=LEFT_TEXT; vj&lt;=RIGHT_TEXT; vj++)
5 \" d' c6 d8 Q4 N{
0 Y( Y- y' P. P9 r0 C4 O. b) Rcleardevice();
) q" f  K( Z" m% x/* set the text justification */ + a8 e6 \7 {5 e0 A
settextjustify(hj, vj); </FONT></P>
! X& \+ n$ C- r! H3 r) R  R<P><FONT color=#0000ff>/* create a message string */
# t$ V/ ?/ S" D$ P6 J/ Z5 ?sprintf(msg, "%s %s", hjust[hj], vjust[vj]); </FONT></P>
" @, z. l9 X. H6 c<P><FONT color=#0000ff>/* create cross hairs on the screen */ # p7 d% k+ Y* _: n' U
xat(midx, midy); </FONT></P>
. V' ]4 r: G! J  R3 z<P><FONT color=#0000ff>/* output the message */
# y# l- v: n4 kouttextxy(midx, midy, msg);
9 l/ V  I" @! ], Fgetch();
' V( _; y# G' [: @# k} </FONT></P>
& z( E' G) I9 Q  n! C) Z<P><FONT color=#0000ff>/* clean up */
+ j( M: F+ j+ N: T4 ]closegraph(); ! m2 H4 j# ~4 N; o
return 0;
1 j, ^# F. w: m" {} </FONT></P>" B# K% X3 p! m1 X3 Y4 p
<P><FONT color=#0000ff>/* draw an "x" at (x, y) */ ; H- J+ g' o0 q( `
void xat(int x, int y) 4 a/ h7 Y) J% t/ ^' y9 [' O+ J
{ $ i% z% _, [# ]2 N" `
line(x-4, y, x+4, y); ; |# D9 T( F; t
line(x, y-4, x, y+4);
3 b& v" w, f  m' D: d! i} </FONT>% @9 D- z( Q8 q" r$ p7 O4 P/ t
* P- J! p) n1 S4 R
</P>7 g: g" S% H3 `- {5 Y
<P><FONT color=#ff0000>函数名: settextstyle </FONT>
- j# Q$ x' a; P' c9 ~" J/ X功 能: 为图形输出设置当前的文本属性 & F' {3 N% n  ?0 f2 f) r* y$ S( t$ g
用 法: void far settextstyle (int font, int direction, char size);
4 c/ @1 Z/ @5 M5 B/ b4 d% y+ E7 {程序例: </P>
" N( v7 y# H  `: S<P><FONT color=#0000ff>#include <GRAPHICS.H>
% Z4 B; r7 g& [7 M#include <STDLIB.H>
9 r, N( W9 K8 Z" t1 |, d7 C0 ^#include <STDIO.H>- n& V" I" e$ z/ U& e, @" u
#include <CONIO.H></FONT></P>* z0 L+ U, a  f* `$ w- ]/ K; C
<P><FONT color=#0000ff>/* the names of the text styles supported */ & }6 q* u) j# i# J' |0 V, R
char *fname[] = { "DEFAULT font", / S1 t/ `: z, W2 Q
"TRIPLEX font",
) R9 ~4 {: v" o7 ]0 N2 z- R"SMALL font",
" m- s- Q- e$ p2 C6 v. G"SANS SERIF font", - _; o# k( P1 G* ^
"GOTHIC font" + V; D! k$ c/ h0 {. ~8 ]
}; </FONT></P>
; D/ y  f$ S% _% s& p# v5 q<P><FONT color=#0000ff>int main(void)
1 g7 u! i9 _- Y( O{
+ e4 {4 R+ |) ]; B, Z7 q8 N- S/* request auto detection */
: y$ f  o8 z( d; S* i/ O( d8 Y! |int gdriver = DETECT, gmode, errorcode;
% p' \" [9 p8 M1 M; O" |, Iint style, midx, midy;
) J  Y2 k- M: t0 R7 j+ A0 l  E, lint size = 1; </FONT></P>  s) U( S$ u5 P6 Z! K
<P><FONT color=#0000ff>/* initialize graphics and local variables */
7 x3 t& ]4 `0 v3 T1 q0 w1 Tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 J( ^6 R3 z& }
<P><FONT color=#0000ff>/* read result of initialization */
! f. R6 Z* |1 `, ?errorcode = graphresult();
2 ~, ?& {0 }$ }8 }6 ]if (errorcode != grOk) /* an error occurred */
4 v( f2 B  R: c2 J# H{ + {1 V& U$ R: J9 w  ]' u
printf("Graphics error: %s\n", grapherrormsg(errorcode)); , d+ u" j' A& C1 |" E  k
printf("Press any key to halt:");
6 c+ X& A8 F  f, w2 _getch();   X" O. C! c' B3 u$ Q$ {
exit(1); /* terminate with an error code */ ' a# t4 Q$ S) Z: q! {
} </FONT></P>7 w- T; b& t8 X& T: H* z
<P><FONT color=#0000ff>midx = getmaxx() / 2;
7 ?  I7 q/ S: d" d" y/ y. rmidy = getmaxy() / 2; </FONT></P>; t! Y8 u7 b  N7 r
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
0 c' B: H4 r7 O5 u$ c& J<P><FONT color=#0000ff>/* loop through the available text styles */ ; Z1 n3 H5 `: n  F. f/ Y
for (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) * {, r7 E0 y& W4 z! f9 u
{
* R4 R" Q5 c: C. ?cleardevice(); 2 f+ n& D& m7 ~
if (style == TRIPLEX_FONT) . d# w5 q$ g* n! N  d
size = 4; </FONT></P>
* b3 u3 x3 A* y1 B/ t$ G1 o" d<P><FONT color=#0000ff>/* select the text style */
2 B( F- |% I4 u' z" Nsettextstyle(style, HORIZ_DIR, size); </FONT></P>" a: w' ~6 K7 b0 J' q* A
<P><FONT color=#0000ff>/* output a message */   o- G( m* z" c
outtextxy(midx, midy, fname[style]);
# [8 q3 O: ^8 xgetch(); 4 R: b) g5 I0 s" c  G7 q8 ~
} </FONT></P>& b! M) ~! t& y! O/ v
<P><FONT color=#0000ff>/* clean up */ 2 m6 U+ f) x. ]/ L. K) f
closegraph();
' v; s2 J8 E' `2 u/ nreturn 0; 6 x. I8 h# E; @) G
} & l( r  D2 f  Z% b8 J1 k* ^
</FONT>3 Q* j2 N1 e  ]3 h
</P>
9 m' F, \6 _: s$ X( f8 n8 T<P><FONT color=#ff0000>函数名: settextstyle </FONT>
) T1 ^9 y: v7 t: v, S功 能: 为图形输出设置当前的文本属性
8 _9 s/ b$ G" l7 u, V' V6 X9 Z$ l用 法: void far settextstyle (int font, int direction, char size); ) L$ \/ }8 }% N5 N+ ^
程序例: </P>* N6 m, O& L9 D2 ]) m0 T$ |
<P><FONT color=#0000ff>#include <GRAPHICS.H>
( b  r& q: _$ {6 V' l) `1 r: j0 n#include <STDLIB.H>
8 \5 f" s8 P- t4 C, h. [#include <STDIO.H>
& H8 f* u( O. [#include <CONIO.H></FONT></P>4 p* I/ {% ~! `+ h- e) K8 l
<P><FONT color=#0000ff>/* the names of the text styles supported */ 7 a! s% C: O6 }! \! J
char *fname[] = { "DEFAULT font",
) z- o9 q6 U/ t1 f"TRIPLEX font", 8 [# ?3 ^' s8 q. r, M- h; l8 ]0 o
"SMALL font",
4 n( {& ~7 _  S+ R, K( Q; I- l"SANS SERIF font",
( c' N. F2 U4 Z"GOTHIC font"
; a( S/ {# M; c}; </FONT></P>
* O0 R+ r! T! s$ q4 E0 [1 \) e<P><FONT color=#0000ff>int main(void) 2 J4 A% N8 _1 t6 y& H3 n$ G% D4 N
{
$ A) X- _1 v4 j- f8 C. O/* request auto detection */
' s1 R) l1 }8 D6 _7 \: q! Vint gdriver = DETECT, gmode, errorcode; ; B( Y9 q0 N, J5 T# g
int style, midx, midy; . i( L* N$ ], d) y  y
int size = 1; </FONT></P>
, B  Q0 z" G% H. d4 c<P><FONT color=#0000ff>/* initialize graphics and local variables */ * A; B5 P/ |. {
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>" v. {$ I2 Y- `7 A0 f" f
<P><FONT color=#0000ff>/* read result of initialization */
3 J% H" ~) s2 j  perrorcode = graphresult(); ; M! K* j1 v) @2 D
if (errorcode != grOk) /* an error occurred */
% _4 y1 b6 q6 N$ R: g: ^7 y2 T  b{ ) j6 V; _, T; z
printf("Graphics error: %s\n", grapherrormsg(errorcode)); ( w3 Q! }% I1 G/ {5 k4 C* R' R
printf("Press any key to halt:"); $ S7 ~  h, n. Q& P) t' M
getch();
" P8 q5 w! i" d+ _0 j3 xexit(1); /* terminate with an error code */
: x/ e# q* T" b6 k8 [( F, q$ x& @8 M0 c} </FONT></P>* N4 w& g& Q' v: s3 ?% T  Q' O
<P><FONT color=#0000ff>midx = getmaxx() / 2; 3 ~& s9 q1 U8 |- j
midy = getmaxy() / 2; </FONT></P>! D3 Y1 X/ j* `0 e8 j2 L4 l7 e
<P><FONT color=#0000ff>settextjustify(CENTER_TEXT, CENTER_TEXT); </FONT></P>
8 t: J+ ^; }  Z& U" x' }<P><FONT color=#0000ff>/* loop through the available text styles */
% K$ ~  y3 o8 dfor (style=DEFAULT_FONT; style&lt;=GOTHIC_FONT; style++) , l4 r9 s5 N: [# e
{
( I% J) `! ?; A. M6 dcleardevice();
" X5 @" \; K3 p. wif (style == TRIPLEX_FONT)
9 a* E7 L: E$ [2 a* Gsize = 4; </FONT></P>
/ s+ i6 L# h9 j. x6 o  Y<P><FONT color=#0000ff>/* select the text style */
2 m0 ]3 B$ Q4 n; [settextstyle(style, HORIZ_DIR, size); </FONT></P>1 p+ x* D1 H$ Q" f
<P><FONT color=#0000ff>/* output a message */ 9 |! Q4 a8 a: H# o4 H$ J/ V
outtextxy(midx, midy, fname[style]);
8 l: G6 j5 r% w9 G4 A) B; [; Agetch();
, q! e& Z# \! @/ g- X5 n+ ^} </FONT></P>3 t4 ^. K# q  d; w$ |3 g
<P><FONT color=#0000ff>/* clean up */ $ {" N7 S- V2 t6 P! a3 U
closegraph();
, {  M; M) u( S/ n8 o; Z2 Ireturn 0; + |8 z" j' I7 h, {( u. u
} </FONT>
3 X) z9 s0 P0 j- P' ^2 z: a
( S  @) v' V, v3 f</P>) L: e# p& A5 i5 u
<P><FONT color=#ff0000>函数名: settime </FONT>
$ s8 ^8 {" T8 D功 能: 设置系统时间
6 g! h# c+ u5 J# P# r3 N  |用 法: void settime(struct time *timep);
" d4 L6 y# n# k1 O1 J. q" J程序例: </P>/ V* G7 F! s" G& n% q0 ?- \1 r9 W% L
<P><FONT color=#0000ff>#include <STDIO.H>' l/ I3 ~7 V: Q* l7 F
#include <DOS.H></FONT></P>" O, L" ]4 v/ L# `; i" ]
<P><FONT color=#0000ff>int main(void) 2 U4 T7 I" f; O1 r
{
6 a, l+ E: T8 f5 Ystruct time t; </FONT></P>
: b2 ~/ @7 s9 `+ ]# ~1 x/ a<P><FONT color=#0000ff>gettime(&amp;t); % H' R  ?3 J, a) }0 c3 \
printf("The current minute is: %d\n", t.ti_min);
5 y  ?3 ?  D9 ?8 z7 n3 _printf("The current hour is: %d\n", t.ti_hour);
" @0 H, A2 x7 M! u+ G. c* }  l3 sprintf("The current hundredth of a second is: %d\n", t.ti_hund);
* W& E+ d; ~2 i+ Nprintf("The current second is: %d\n", t.ti_sec); </FONT></P>
3 ]% s6 J: g5 u" Z$ w& A2 l<P><FONT color=#0000ff>/* Add one to the minutes struct element and then call settime */
( K: S- a5 v$ c( D/ Pt.ti_min++; : c  ~9 |6 s6 C. E
settime(&amp;t); </FONT></P>
0 B! Y. N  s' W0 Z<P><FONT color=#0000ff>return 0; 1 E  C9 }( z+ O% U, ~& N) K; s" G
} </FONT>& m% J2 J) p: A

- ~+ S2 r/ t* e' ]: p, s</P>
. c; l) s- }, k$ `4 d& A7 p<P><FONT color=#ff0000>函数名: setusercharsize </FONT>
. T5 k6 @2 J1 J- c4 _功 能: 为矢量字体改变字符宽度和高度
& q  Z1 b: s& u" l) e5 C用 法: void far setusercharsize(int multx, int dirx, int multy, int diry);
8 Z  ^" ~- \6 B- j( }/ q程序例: </P>5 P  u& N; Q/ N. H; d, T0 ^
<P><FONT color=#0000ff>#include <GRAPHICS.H>+ j6 z$ i# r* K3 @% ?5 }
#include <STDLIB.H>7 G$ e, T- w5 s# A' P
#include <STDIO.H>
  o9 l$ N# M4 n+ k5 t#include <CONIO.H></FONT></P>7 e- T8 K! z9 [
<P><FONT color=#0000ff>int main(void)
9 `" K6 W6 B% i. e7 R{
0 l& z% Z4 g1 }# J/* request autodetection */
+ u  K+ O: s! Q8 h1 ]int gdriver = DETECT, gmode, errorcode; </FONT></P>/ T, u1 j* W' c# t& r
<P><FONT color=#0000ff>/* initialize graphics and local variables */ 1 h3 @; X( z  g7 q: v8 [$ X
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ N0 Z: C, k8 R  e
<P><FONT color=#0000ff>/* read result of initialization */ 0 W+ g9 B/ J' |
errorcode = graphresult();
0 R# s- l- e2 t* n+ Nif (errorcode != grOk) /* an error occurred */ 1 T4 n9 M% q  `. U
{
2 U& i+ C, E. R8 a- n$ Jprintf("Graphics error: %s\n", grapherrormsg(errorcode)); $ `7 K7 ~: q2 Y
printf("Press any key to halt:");
7 c" z1 a* B% A# u; xgetch(); 7 D3 Z1 B) [9 R3 ?8 g
exit(1); /* terminate with an error code */
2 h" I( w) a; {3 S  b& B" c} </FONT></P>4 ^: J7 B5 P/ h8 d
<P><FONT color=#0000ff>/* select a text style */
; T5 J) T/ \1 J' tsettextstyle(TRIPLEX_FONT, HORIZ_DIR, 4); </FONT></P>5 c, U  T8 M: G2 W' F, G9 y- d
<P><FONT color=#0000ff>/* move to the text starting position */ . J% J% n+ z. ]8 Q) s: V8 m
moveto(0, getmaxy() / 2); </FONT></P>+ z) M: I7 x9 G5 G* ?. L+ ^  p
<P><FONT color=#0000ff>/* output some normal text */
0 d% n2 a3 o9 h9 m0 d0 J% ?outtext("Norm "); </FONT></P>
2 `7 ^2 C' S! O( T( [5 R" G<P><FONT color=#0000ff>/* make the text 1/3 the normal width */ - q: [( }( o' W: w0 N& T
setusercharsize(1, 3, 1, 1); # m" N1 p  X) K
outtext("Short "); </FONT></P>
, M# d* h2 f  J% x) c<P><FONT color=#0000ff>/* make the text 3 times normal width */
% v) @6 X, z, Q/ i' E. c3 L& ^: bsetusercharsize(3, 1, 1, 1); 8 L/ p8 B  U7 ~6 m2 H' T
outtext("Wide"); </FONT></P>3 n7 e% {0 b. J, i
<P><FONT color=#0000ff>/* clean up */ 8 W3 Q( e  W$ Y3 J2 @
getch();
4 b* @9 ~. O+ Z! V5 Oclosegraph(); % e4 C6 H% n; m+ l' f) ^& l/ ~
return 0;
8 L$ ?: _# u8 Z. O2 |} </FONT>
6 z( ~- ~/ Y: M* Z9 m  q& ]5 N</P>4 b& G3 b( Q0 K9 c/ Y0 m
<P><FONT color=#ff0000>函数名: setvbuf </FONT>
3 {1 A" F- `9 @$ y5 X! H# J功 能: 把缓冲区与流相关   G4 ?% f+ b" m0 _9 x
用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size);
6 U/ n4 W& s" [7 l4 x- h程序例: </P>1 M, N, s8 b  P! \! ^8 v
<P><FONT color=#0000ff>#include <STDIO.H></FONT></P>- v% c" j, H3 A2 Y7 b
<P><FONT color=#0000ff>int main(void)
- J$ s' E2 |7 S- {: W{
+ u% v. c* E2 b# a) f+ Z% RFILE *input, *output;
# P1 h7 a6 z8 x2 k- vchar bufr[512]; </FONT></P>* Q7 U) L- b' w. ]& Y% M5 A
<P><FONT color=#0000ff>input = fopen("file.in", "r+b");
! X* B# y: _) a. c/ @4 z5 Routput = fopen("file.out", "w"); </FONT></P>: z, l# U' ~( F5 m$ i* G/ @
<P><FONT color=#0000ff>/* set up input stream for minimal disk access,   s3 u( A  i7 W8 P0 z, S! o' r
using our own character buffer */
/ G  ?, L# D3 ]6 c) |' aif (setvbuf(input, bufr, _IOFBF, 512) != 0)
' y/ ^& L1 i, n( R) l5 sprintf("failed to set up buffer for input file\n");
4 n" M$ {" p! t  R4 N0 oelse
% x% _# x# }5 U/ f8 Bprintf("buffer set up for input file\n"); </FONT></P>
( W1 U4 z- b; U2 Q<P><FONT color=#0000ff>/* set up output stream for line buffering using space that
0 v, X3 c1 l+ e' `# f8 |4 kwill be obtained through an indirect call to malloc */ ; x6 |, U3 [- _/ r2 e' N
if (setvbuf(output, NULL, _IOLBF, 132) != 0) ; T+ j0 T; U- v) \( k6 W
printf("failed to set up buffer for output file\n");
# L, h  q% B, {7 D, ^else
, `) p1 ?! a' c. A% Oprintf("buffer set up for output file\n"); </FONT></P>/ t! b4 Z9 C% C. I( a
<P><FONT color=#0000ff>/* perform file I/O here */ </FONT></P>
, [- p. K$ ?0 d0 y) q<P><FONT color=#0000ff>/* close files */ 8 b' V' g; G# @% ^; ]
fclose(input); " O7 Q- Q! W' P
fclose(output);
& U/ g! a& q7 B: G0 w, preturn 0;
( i1 D8 s" r1 k}
& A. c6 s1 m/ ?* ]4 ~' r5 a5 ^4 t</FONT>
8 R+ [* g8 [" @3 I- q* Y
+ Y, t+ K) p- _</P>
3 b; k9 t& N  ?+ V2 l<P><FONT color=#ff0000>函数名: setvect </FONT>
* ]- a' \" X& m# U0 [" h& W% q功 能: 设置中断矢量入口
' T) |; a6 p8 p8 Q% Y用 法: void setvect(int intr_num, void interrupt(*isr)()); 5 x. s$ R% c9 _6 V
程序例: </P>
* T. k. G# I6 U7 e<P><FONT color=#0000ff>/***NOTE: + M7 q' k' o0 K
This is an interrupt service routine. You can NOT compile this
/ b: _$ Z1 l$ r3 @8 v0 sprogram with Test Stack Overflow turned on and get an executable / g, c# c5 F5 b+ U' [
file which will operate correctly. */ </FONT></P>( n) ^2 J$ ^. S4 C, M$ x
<P><FONT color=#0000ff>#include <STDIO.H>
. @5 z) E2 Q! e8 [% Y7 m#include <DOS.H>4 }; H( Z/ y, r; l" A( M
#include <CONIO.H></FONT></P>
) n- G& m# r- v<P><FONT color=#0000ff>#define INTR 0X1C /* The clock tick interrupt */ </FONT></P>
  ~, M3 @0 J1 f  p5 A# A" f<P><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
4 ?* m/ j2 ^$ T# \9 t<P><FONT color=#0000ff>int count=0; </FONT></P>
8 z% f  ?  \1 l$ L<P><FONT color=#0000ff>void interrupt handler(void)
8 @0 K- @7 `+ A% V* w2 |/ s{
* z  B2 R6 e6 ^. C, i/* increase the global counter */ 0 K1 j, m3 Z, G$ \, W3 ]& i+ D0 v0 u
count++; </FONT></P>
% g8 q; T6 o2 y4 k  @<P><FONT color=#0000ff>/* call the old routine */ 9 _# F+ z8 X* v' w
oldhandler(); 4 }: O2 `% @- ?# N( W. H
} </FONT></P>
! M+ u; g9 X7 C- F<P><FONT color=#0000ff>int main(void) 1 e4 }! C: n8 d% b; }
{
' F% E8 x3 ?; _: |" q/* save the old interrupt vector */ 2 y* \4 k( t2 h
oldhandler = getvect(INTR); </FONT></P>
. E. m. y) A3 ?3 K8 ~4 I<P><FONT color=#0000ff>/* install the new interrupt handler */ 5 o1 s2 g( }9 Q, H
setvect(INTR, handler); </FONT></P>
7 `" p, L1 K5 V( K7 D: {& Q<P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
$ A$ L  E( C' _: |, kwhile (count &lt; 20)
, I& E: c. T* R( V- Sprintf("count is %d\n",count); </FONT></P>% w2 g8 u# ]- r
<P><FONT color=#0000ff>/* reset the old interrupt handler */ , o# T& {0 u9 g* [
setvect(INTR, oldhandler); </FONT></P>, J, L/ n6 X5 h! O$ H" f% P
<P><FONT color=#0000ff>return 0;
3 C' `+ g1 b1 v% A6 q( Q( x) u}
# p% j. i$ I: p' ^</FONT>% m: M; A; u& q
</P>
; Q2 E1 K3 C1 U$ R. P- ~& W1 {6 n<P><FONT color=#ff0000>函数名: setverify </FONT>7 v" b  e  s. J# o- d" }' d! J
功 能: 设置验证状态 ; p) u( H/ u1 A* Z$ W# g6 X
用 法: void setverify(int value); # _5 V" Q$ A5 ?) k2 {) d! H% p
程序例: </P>. N  ^$ [) t! w7 h
<P><FONT color=#0000ff>#include <STDIO.H>- ^" I+ \% J, a4 h. C# O
#include <CONIO.H>2 c+ \$ J2 G7 F
#include <DOS.H></FONT></P>
- C# W" q: s* r<P><FONT color=#0000ff>int main(void) 3 M7 X7 r: Y# J6 g- M" F9 {3 k
{
4 ~: q% U; l# f6 X% Kint verify_flag; </FONT></P>
; ?; V( [( L, q4 s( [4 H<P><FONT color=#0000ff>printf("Enter 0 to set verify flag off\n");
" l, S$ n! Q1 d# ]1 eprintf("Enter 1 to set verify flag on\n"); </FONT></P>9 f/ q# p( i2 B$ d2 Y& c: g: \
<P><FONT color=#0000ff>verify_flag = getch() - 0; </FONT></P>
# Q- x9 Q7 h  M2 V  A6 U: I5 z<P><FONT color=#0000ff>setverify(verify_flag); </FONT></P>
) e! q0 g+ a4 d( e+ A; m<P><FONT color=#0000ff>if (getverify()) , h: G7 U0 h( D8 L8 Y. J
printf("DOS verify flag is on\n"); % F. i) `4 @. n
else
& m, F) c# p5 N: O. ?printf("DOS verify flag is off\n"); </FONT></P>
: Q5 d0 A( h+ j% y& i: a! l' F- S<P><FONT color=#0000ff>return 0; : r. a5 k9 V3 `. L
}
" |3 T2 ~, L( |. u- |, q/ F8 I<FONT color=#ff0000>0 L0 p$ P$ |5 d3 p
</FONT></FONT></P>2 P) C& S$ U, [% |4 c; t6 o  {% E8 g
<P><FONT color=#ff0000>函数名: setviewport </FONT>" z$ s$ ~4 }$ \, G2 c: w
功 能: 为图形输出设置当前视口 3 j  e. O* x# `, _) a
用 法: void far setviewport(int left, int top, int right,
# j, M' i1 j9 m; k% R# p' nint bottom, int clipflag);
5 p/ w* U; G$ r程序例: </P>& o& @  D" w( \7 L! x- `
<P><FONT color=#0000ff>#include <GRAPHICS.H>
- D( n+ [( ?) b8 t! r#include <STDLIB.H>' H1 c( S  _) }7 m& k
#include <STDIO.H>& h+ u7 s; H& E
#include <CONIO.H></FONT></P>
2 ~7 t% _) F8 p" @" f# F$ c5 }<P><FONT color=#0000ff>#define CLIP_ON 1 /* activates clipping in viewport */ </FONT></P>5 X9 J+ ~, ]' z; n- F2 g2 Y
<P><FONT color=#0000ff>int main(void)
; n- y* y* j  @: u" [& }* u{ - j8 C+ E+ k5 n/ P2 P9 D
/* request auto detection */
/ q% j: ^4 J  ]. b& o+ N, rint gdriver = DETECT, gmode, errorcode; </FONT></P>* W. P% j9 S  p4 \+ P* D9 t  q
<P><FONT color=#0000ff>/* initialize graphics and local variables */
& \/ h, V7 @% ]% L  a' \. tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 L# H2 k$ G0 ^
<P><FONT color=#0000ff>/* read result of initialization */ 6 r! M, [2 p( v  U
errorcode = graphresult();
! q" C( G9 c5 Aif (errorcode != grOk) /* an error occurred */ 6 E" }6 k; |6 \+ |
{
" z  W% z/ m- X' Lprintf("Graphics error: %s\n", grapherrormsg(errorcode)); - ?$ s, N7 X. p! {' k8 F
printf("Press any key to halt:");
+ [+ t+ v2 A& j6 h* |  Y2 {) Jgetch();
( O) f+ ]% T$ p- Eexit(1); /* terminate with an error code */
/ a. m1 G& |/ g# z} </FONT></P>
& x+ j. U1 I- w9 w7 a2 t<P><FONT color=#0000ff>setcolor(getmaxcolor()); </FONT></P>
2 ?, }: |$ c+ D: S<P><FONT color=#0000ff>/* message in default full-screen viewport */ ; @# Y2 I7 n; r: Y, @% V1 p$ h) e
outtextxy(0, 0, "* &lt;-- (0, 0) in default viewport"); </FONT></P>
! M3 v1 L# Y1 _5 y  s# g<P><FONT color=#0000ff>/* create a smaller viewport */ ' F( w9 y. g( n2 q, P
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </FONT></P>  Q0 B! j; N3 v$ ^# O
<P><FONT color=#0000ff>/* display some text */ * U4 m. A* K$ O8 U7 |' E) p. P: t# U
outtextxy(0, 0, "* &lt;-- (0, 0) in smaller viewport"); </FONT></P>
1 ]# B+ V! W5 Q2 }5 Y/ U<P><FONT color=#0000ff>/* clean up */
  A( p# T. z! O% l/ Ugetch(); . k+ T5 w/ B9 h& `) N6 X9 h
closegraph();
1 X. t6 ^& E- F$ x1 p# S( dreturn 0; , Z8 q3 ]6 M2 q: X! a4 e1 d
}
/ T& U0 p: c* ]& x% `/ _8 r+ d</FONT>, B2 A! E) R; Q: u) L' y
</P>+ y% g) j1 Z0 [8 O( e/ p8 w0 H
<P><FONT color=#ff0000>函数名: setvisualpage </FONT>
  l/ `4 ~/ \/ y$ {) V5 `功 能: 设置可见图形页号
* {9 n& e0 d' |! t5 M2 i' ~用 法: void far setvisualpage(int pagenum);
+ v1 u* `2 w5 ?) f程序例: </P>
' w: p  F! q9 }, r<P><FONT color=#0000ff>#include <GRAPHICS.H># z5 M, L; r) A' q: R
#include <STDLIB.H>8 ]0 `+ e; v' \
#include <STDIO.H>
1 W2 u; k# S; U9 `. V7 o" P7 [#include <CONIO.H></FONT></P># V# i" E7 g; \
<P><FONT color=#0000ff>int main(void) / K  E, O2 j3 V4 t* k, s+ P1 _
{
% u1 h3 R0 S0 j/* select a driver and mode that supports */
2 c' s+ n' {+ H& k" _% W) \/* multiple pages. */ 7 f* k( v( Y; v
int gdriver = EGA, gmode = EGAHI, errorcode; 7 f6 `8 G* n% K6 N; Y  P0 x7 S
int x, y, ht; </FONT></P>1 l; K4 N4 K6 I" C7 |& f
<P><FONT color=#0000ff>/* initialize graphics and local variables */
, d; \! n9 |3 n* G! t* ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>$ W0 f8 G/ i$ ^4 L
<P><FONT color=#0000ff>/* read result of initialization */ ; w  ?/ Z! J# _: G) S8 |" u
errorcode = graphresult();   J, m1 W: |5 J1 |
if (errorcode != grOk) /* an error occurred */ 1 A, B* G0 n. J4 o+ t
{ 6 M/ s) n! v  y  h! O* z5 h* O0 F
printf("Graphics error: %s\n", grapherrormsg(errorcode));
7 O9 A: ~: P* f& W0 iprintf("Press any key to halt:"); 0 e4 O9 z4 b4 [/ t( {. W  @' e
getch(); ! i( t8 Y! l# [: M2 @
exit(1); /* terminate with an error code */ * b1 p6 t& S. }/ |2 F' `
} </FONT></P>' [6 j0 A7 K2 l
<P><FONT color=#0000ff>x = getmaxx() / 2; 8 b5 E  p; J2 Q9 g9 c; F7 ~4 s
y = getmaxy() / 2; 2 {1 A/ N* J, A0 O6 O4 F5 R
ht = textheight("W"); </FONT></P>* X) K& }% y; d% A) |5 W
<P><FONT color=#0000ff>/* select the off screen page for drawing */
" o+ p& j" v$ i9 V: o9 Hsetactivepage(1); </FONT></P>
; [5 K. p; {) n9 v3 R+ }. ~<P><FONT color=#0000ff>/* draw a line on page #1 */
- I7 {* h# {  A9 G8 nline(0, 0, getmaxx(), getmaxy()); </FONT></P>
# b" i) g+ S2 H' f. \<P><FONT color=#0000ff>/* output a message on page #1 */ 7 V% Y. r8 h5 D% \7 u
settextjustify(CENTER_TEXT, CENTER_TEXT); 4 \4 K; [, X# l+ a# ~
outtextxy(x, y, "This is page #1:"); : P, {6 P1 Y6 U! K1 u4 ^( G
outtextxy(x, y+ht, "Press any key to halt:"); </FONT></P>6 G# o# I& t* v) J- l$ ~  h
<P><FONT color=#0000ff>/* select drawing to page #0 */ , i- l- L2 p& D" {8 y% A
setactivepage(0); </FONT></P>
0 _  D+ p6 [1 }4 o8 [<P><FONT color=#0000ff>/* output a message on page #0 */
$ u% \$ O- Q+ u9 q3 U2 \outtextxy(x, y, "This is page #0.");
% K, e3 f9 M" |6 Louttextxy(x, y+ht, "Press any key to view page #1:");
9 k$ d8 y. v4 G5 G. }getch(); </FONT></P>
5 e2 }. ~. G* J# h<P><FONT color=#0000ff>/* select page #1 as the visible page */ 5 G- x; v, j0 S: B% i- B/ B
setvisualpage(1); </FONT></P>7 L, n8 ?& u/ U, m0 ]# I0 H/ _9 }
<P><FONT color=#0000ff>/* clean up */
! k2 {! U) N5 ^getch();
5 e6 q2 F( F2 C7 Y5 p6 d0 bclosegraph();
3 `6 u" Q" _0 K, {& I# _! v* n$ Ureturn 0; 1 J+ M* j) `, D
} </FONT>
. v3 N- l' _  f6 G$ c, L- E0 l7 i/ \6 f4 s6 ]5 @
</P>
! @% j% k! ~# V) r- ?/ F1 l<P><FONT color=#ff0000>函数名: setwritemode </FONT>( ~6 C3 W1 i1 t, y6 T
功 能: 设置图形方式下画线的输出模式 1 a  F& p( m8 s2 `9 a3 k4 `
用 法: void far setwritemode(int mode); # f1 H$ G5 w* [5 X
程序例: </P>
) L) ^* u2 x3 Z<P><FONT color=#0000ff>#include <GRAPHICS.H>; `) P$ P: Q0 M% h5 H
#include <STDLIB.H>
" U5 D9 G6 m  V7 e6 h" n#include <STDIO.H>$ {+ K1 e' m  t4 d5 f9 Q3 Y! c' x
#include <CONIO.H></FONT></P>: U% C  Y7 x8 q8 D8 w; P
<P><FONT color=#0000ff>int main()
+ m" a) R- n5 N# N4 s$ M{
% p0 {/ E' `5 p) z5 ^/* request auto detection */ ) k* g8 x& M% c2 R! x* \. _" _) b
int gdriver = DETECT, gmode, errorcode; % A5 r$ f( l9 T' U0 c$ W1 X5 d
int xmax, ymax; </FONT></P>
7 O: @4 u/ J& y6 E% b7 Z<P><FONT color=#0000ff>/* initialize graphics and local variables */
. G8 g+ @( |0 q  w( J: u% t4 hinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
6 S6 |" e7 p1 \9 \6 h% _& \<P><FONT color=#0000ff>/* read result of initialization */
; s& u$ V1 D3 {5 l* I  [" l+ [errorcode = graphresult(); # J  Z& A; d. M( {9 S
if (errorcode != grOk) /* an error occurred */ $ X4 i' r: ]& u% B2 T3 X
{   U5 q7 M! J* Z
printf("Graphics error: %s\n", grapherrormsg(errorcode));
- Q0 M' t! q. U9 c6 ]printf("Press any key to halt:"); 7 g( u6 c* L8 ]- c
getch();
/ \8 s+ _- s. @) r6 qexit(1); /* terminate with an error code */
5 ]1 g7 {5 R) }) `  k} </FONT></P>$ B* I* p1 E/ ~" h( B1 f) q
<P><FONT color=#0000ff>xmax = getmaxx();
6 k4 P8 x( O2 e5 Q$ x$ Pymax = getmaxy(); </FONT></P>
, c0 a: I9 ?; j/ t<P><FONT color=#0000ff>/* select XOR drawing mode */ / f: f: ~5 C0 ^, h0 Y7 E
setwritemode(XOR_PUT); </FONT></P>0 T0 V) w8 p5 G6 h5 D
<P><FONT color=#0000ff>/* draw a line */
- V, @% D$ Y' |6 a  H5 c2 Hline(0, 0, xmax, ymax);
3 ]8 Y7 X8 U$ Zgetch(); </FONT></P>
$ M1 `% A+ R! n2 C' M( _' r<P><FONT color=#0000ff>/* erase the line by drawing over it */
# |2 ?8 n/ J) T# t3 F' g4 _line(0, 0, xmax, ymax); " O) I# T( s2 t' p1 \
getch(); </FONT></P>8 o1 }% |7 W& B
<P><FONT color=#0000ff>/* select overwrite drawing mode */ + L/ d/ ?" f9 J/ [0 f' t7 U& b6 S$ [, f
setwritemode(COPY_PUT); </FONT></P>) Z2 m' ?% d7 E2 a  k+ b! v9 q" `& G7 Q
<P><FONT color=#0000ff>/* draw a line */ # {$ w! x! f! X* w
line(0, 0, xmax, ymax); </FONT></P>/ q3 i$ d, z  F( J% q9 Z; E! K
<P><FONT color=#0000ff>/* clean up */ & x/ s+ Y4 m# y  @
getch(); 6 @$ G; u# n& d3 w( e
closegraph();
8 Y) S1 _% M) E$ @3 s- ]return 0;
, J, F: y# G. x- r} ' O, ~; n6 t( K3 j4 K
</FONT>4 D1 D3 [/ g$ C& L
</P>
' w0 A2 n, f; {<P><FONT color=#ff0000>函数名: signal</FONT> 6 X8 ~$ y5 j# ]3 l1 ~
功 能: 设置某一信号的对应动作 ( Z7 t( I9 b2 x' Z5 b  }$ C
用 法: int signal(int sig, sigfun fname); / E4 U9 G; u( G& _
程序例: </P>; [- S/ H' o, p  Y7 |$ J4 V
<P><FONT color=#0000ff>/* This example installs a signal handler routine for SIGFPE,
8 r9 y. a; s' {/ [. [catches an integer overflow condition, makes an adjustment
' `1 g$ I+ F4 l' ~to AX register, and returns. This example program MAY cause 8 t1 j  J1 r* z# n8 A1 I
your computer to crash, and will produce runtime errors
. ~& o) j8 o1 Kdepending on which memory model is used. 2 y" `, S, G% O9 v& X0 }
*/ </FONT></P>
! ^1 f1 P; C1 |7 f+ q<P><FONT color=#0000ff>#pragma inline
/ I+ I  d+ [* N( T: D+ i  i#include <STDIO.H>
8 Y2 A0 q7 x/ f! ~+ Z#include <SIGNAL.H></FONT></P>, \3 [$ O! C& V& I1 f* M5 s
<P><FONT color=#0000ff>void Catcher(int sig, int type, int *reglist)
. {4 a( P5 a: Y7 C) Y{
0 H( O; Z" F. m. F7 `printf("Caught it!\n");
8 Q) X! k6 J# e& |+ `# D, a, {6 L*(reglist + 8) = 3; /* make return AX = 3 */ # f7 i0 \- x; x0 @9 P7 P; M$ `
} </FONT></P>
& T& p- m* F4 ]8 X- G<P><FONT color=#0000ff>int main(void)
! `4 ~  p, P: I, `) ~( C{
2 M1 G9 F$ L6 k2 _8 x* g; Bsignal(SIGFPE, Catcher);
4 F9 b* s$ G0 Sasm mov ax,07FFFH /* AX = 32767 */
8 Y1 @  h$ }$ {/ ?5 R, ~6 easm inc ax /* cause overflow */ " {; A" X4 I% J# H. s1 L( U) w
asm into /* activate handler */ </FONT></P>
  l  Y8 O% r! ]8 Q, O- p  w' a<P><FONT color=#0000ff>/* The handler set AX to 3 on return. If that hadn't happened, + Z' s: v* G/ Y9 a' ^  ?8 \. B
there would have been another exception when the next 'into' - y  s, N3 ?) W+ A
was executed after the 'dec' instruction. */ " q- w" w- E" ^
asm dec ax /* no overflow now */
0 N1 W# s# A7 r. q# }, v5 _! k# ?asm into /* doesn't activate */ - a- `9 e( ^7 u5 {4 P
return 0; ; [* t9 I0 S, b
} , D  m8 u4 f- i4 _' F' F# }4 I0 R

6 f; S2 |, S+ A
- t, e: V- X% N' ~</FONT></P>
- P+ u" e6 O# Z9 [. K& L. k/ m<P><FONT color=#ff0000>函数名: sin </FONT>
0 Y  h$ c, ~  e功 能: 正弦函数 . v- i& y6 ?$ b+ ^/ d
用 法: double sin(double x);
& ?& |, H  z* {$ M/ U. b程序例: </P>
( P1 j, e0 u& ^0 H  X. Z; u2 x<P><FONT color=#0000ff>#include <STDIO.H>$ q, }+ M6 U' K5 Z0 L
#include <MATH.H></FONT></P>- P' I& [: O- Y
<P><FONT color=#0000ff>int main(void)
3 g* X6 o/ h8 @{ & A# Y0 z1 k6 o, [
double result, x = 0.5; </FONT></P>
9 [1 P# ?% H! M' Q6 h<P><FONT color=#0000ff>result = sin(x); " }0 m, C1 J" R6 S4 k
printf("The sin() of %lf is %lf\n", x, result);
( x& A) A# A. v: k2 w$ g  Mreturn 0;
1 f: A3 u: w% x, Q* x} 3 f$ }) S8 r' I8 h
' g1 z) h* k- @3 S) g
</FONT></P>
8 v: b+ R+ f- P- R. D: y2 \5 L: T<P><FONT color=#ff0000>函数名: sinh </FONT>( A. z5 r) f/ r) j, J
功 能: 双曲正弦函数
, _2 v( g" W3 h0 o" S& K) q; s用 法: double sinh(double x); 3 i: \- S; I: {. O: r' T. I. X3 X
程序例: </P>1 A$ M& ~( h% R- b
<P><FONT color=#0000ff>#include <STDIO.H>
3 V" N- x0 t1 C* H#include <MATH.H></FONT></P>" z1 {; z! ~+ x" _& n" j& ?& r
<P><FONT color=#0000ff>int main(void) * a$ _& e$ O- d- h) ?7 u/ s
{ & v+ q9 d- n- _
double result, x = 0.5; </FONT></P>
& _1 a; n. {. C1 J) Y) ]( j! O<P><FONT color=#0000ff>result = sinh(x); ' x" o( R8 E# j- d+ z) Q: H
printf("The hyperbolic sin() of %lf is %lf\n", x, result);
# c8 h6 l6 Y0 M+ m$ Sreturn 0;
% [& k3 g8 t6 _& {* ]  _+ }  u7 L}   {. J- ^- O/ l+ a

; _$ J! P  G) l2 b! w" `5 Q# \) Y7 ?6 E- O7 e
</FONT></P>
7 I$ `) Z4 `; E" K* O! @3 o<P><FONT color=#ff0000>函数名: sleep </FONT>, n& g9 _% Z$ v: h
功 能: 执行挂起一段时间 6 N' `, ]; C& f4 A7 S9 M" Y6 m
用 法: unsigned sleep(unsigned seconds); 3 [0 A9 Y( U# W7 Z( o9 c, P
程序例: </P>1 K* r- k5 E! q& B; ^- J
<P><FONT color=#0000ff>#include <DOS.H>0 k- M7 B: z! A6 i1 w  Y7 a
#include <STDIO.H></FONT></P>% h% n  j6 c' S1 _5 g# k' H- O( a
<P><FONT color=#0000ff>int main(void) / A7 I9 ^" }! ?0 }9 r- X
{ - F# \2 `/ I2 x5 S4 {; o+ T" }
int i; </FONT></P>0 Q5 f7 [2 ~+ I7 Q5 R! c
<P><FONT color=#0000ff>for (i=1; i&lt;5; i++)
1 k7 A: k4 Z6 A# k9 ?{
7 M: I  n6 ~+ c3 I  ?7 s! Zprintf("Sleeping for %d seconds\n", i); $ D$ |& K. W: W, w( O+ A
sleep(i); 1 r1 l" Y7 j+ x# a% N4 `# T! s
}
4 j6 y2 W& s+ w  N6 ]return 0;
9 X3 s3 T- D7 Z) \8 _} , R& a  Y- r- ]# s
: T5 D& Y6 }$ v  J0 ]  c
</FONT>$ k8 e1 ~: ]* W# L3 A* O
</P>2 Z  M% J  b" U4 t2 Q9 B
<P><FONT color=#ff0000>函数名: sopen </FONT>4 z, }7 d% x6 n6 X; B
功 能: 打开一共享文件
) E& J/ @" |8 _用 法: int sopen(char *pathname, int access, int shflag, int permiss);
/ z/ X# ]: }. q9 o% V程序例: </P>" v6 C% ], s4 v0 Q  |5 m
<P><FONT color=#0000ff>#include <IO.H>% ?5 a) c8 Y- u) u
#include <FCNTL.H>
4 I9 y. n* |: V) L2 e#include <SYS\STAT.H>
$ Y- Q% L1 m( O/ a#include <PROCESS.H>
' t% O+ z- y# s1 r6 E+ n" Z#include <SHARE.H>0 i8 `( e; N' Z, e& \! A6 l
#include <STDIO.H></FONT></P>
* y7 ]7 I2 x  q8 [! u<P><FONT color=#0000ff>int main(void)
& t) `& [4 `: V- i0 @' h9 p  p{ : p9 n0 w! E% `8 e( V: n: ?
int handle; + \9 w( W- E. m4 f9 N+ w
int status; </FONT></P>
  }2 }! u! ~3 E2 G$ T& ]<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat", O_RDONLY, SH_DENYNO, S_IREAD); </FONT></P>
* [  v6 E5 x) r! G! W<P><FONT color=#0000ff>if (!handle) : z% ?* g' e+ D* Q
{ 0 r3 s& ^& u2 a9 V4 g$ H
printf("sopen failed\n");
! Q2 F8 Y7 b& m% a  C* ?" f$ G! Fexit(1); * y/ r! N' [8 ^& |6 h9 \% q; z
} </FONT></P>
+ r4 x2 l2 [  _1 @- ]<P><FONT color=#0000ff>status = access("c:\\autoexec.bat", 6);
( l8 g) n. b7 r4 ^if (status == 0) 5 N3 M3 f; [" _0 \& l
printf("read/write access allowed\n"); 8 a; H) `; `. w, i( s- |2 L  q! h
else
4 k8 \% C) T, y0 K! sprintf("read/write access not allowed\n"); </FONT></P>
; p; `- {* C" D' F8 [$ u- [' W, Z<P><FONT color=#0000ff>close(handle); ( H# E, A5 L$ b2 L; `6 \
return 0;
. u9 z0 t  F* T- I" {) d# \5 \} 1 X( u' x6 _3 l; |6 D8 g& _* J

4 _7 Z1 H' w1 `: L</FONT>
! n: ~1 ]( k4 Y" s</P>
, a; w# D/ b2 p2 M$ x<P><FONT color=#ff0000>函数名: sound </FONT>; P9 t- [7 N7 x; y/ t, \
功 能: 以指定频率打开PC扬声器
3 w0 h0 h1 ?. M0 {/ E用 法: void sound(unsigned frequency);
" F( Z( m  V8 K( \) o) D& ]; ~/ h程序例: </P>6 X0 p& ^9 J. t) o0 D/ _
<P><FONT color=#0000ff>/* Emits a 7-Hz tone for 10 seconds. 9 k. Q( L! H/ w9 R2 }9 d" q  @
Your PC may not be able to emit a 7-Hz tone. */ 9 ~( v- D* _& h% b  ]) i4 O
#include <DOS.H></FONT></P>
! ]6 H' [4 p; ~3 i' @  f- Y<P><FONT color=#0000ff>int main(void)
" h, g, [2 y# \+ V{   I! M( ?0 q3 V4 s* ]3 l
sound(7);
/ C7 E% U+ ^) }: p: ~- S$ d6 Udelay(10000); $ q4 x! A% X$ |6 t  ^
nosound(); & g, Y, \/ }3 a7 D- T' U+ y1 m# m" u
return 0;
+ B, L. J0 P: ~- |0 @3 D} </FONT>
, P- ~" f4 ^9 q' E9 F6 X; g  M0 c3 M2 B
; f2 T5 O9 d" i
</P>5 v1 C; ?6 P8 P/ c
<P><FONT color=#ff0000>函数名: spawnl </FONT>4 B5 B$ A5 ^4 B% s, w3 v- m' c; k
功 能: 创建并运行子程序 8 l3 w: C  ~/ ~# P# S$ x5 v# I. J
用 法: int spawnl(int mode, char *pathname, char *arg0, 3 X- D2 h, n1 H4 ~' b
arg1, ... argn, NULL);
6 C7 {1 ]- K2 ~1 f程序例: </P>7 [2 R, P$ P1 Q% u. Z
<P><FONT color=#0000ff>#include <PROCESS.H>0 m& \* t) n9 q* Y' e# A  N
#include <STDIO.H>1 B& }3 M) g: j: h0 G# J' ~
#include <CONIO.H></FONT></P>) n) w6 y$ ]2 C% g9 K* {
<P><FONT color=#0000ff>int main(void) ! ^3 U* }" {$ w9 e! B* w- q! t# j
{
# q7 b) \: n( f5 }6 V2 X4 k" P# Mint result; </FONT></P>: T8 Z0 p! ?6 Y; m
<P><FONT color=#0000ff>clrscr(); # e! t/ x. d1 r2 R
result = spawnl(P_WAIT, "tcc.exe", NULL);
# x, ], |' o) M; L5 C5 b1 [1 S% g, gif (result == -1) " x5 [; ~- K$ l( k
{
& u$ Z* Q; z" k2 P% i+ G  l9 Vperror("Error from spawnl");
  ]% K8 @  P4 [9 k# P6 m* Dexit(1);
7 K4 f; d8 G0 N}
% y( ?7 T' ]7 L$ j; x! Greturn 0;
( R# g) K- J: u8 c$ d# c} 3 w, y& i0 ^' R" q( }  N
</FONT>
4 C$ r% W8 R- f, J</P>; j) T/ P7 H( q/ c5 A
<P><FONT color=#ff0000>函数名: spawnle </FONT>
) I8 p2 u9 ^8 w0 f1 P- e' d功 能: 创建并运行子程序
( @2 Q+ ^8 \* O- {3 f  Y. S用 法: int spawnle(int mode, char *pathname, char *arg0,
' `3 P9 |8 Q5 ^( J# q, karg1,..., argn, NULL);
- l2 I; P- V$ k1 m4 f% z- }程序例: </P>
8 F1 m- d) K$ B) k& ~<P><FONT color=#0000ff>/* spawnle() example */ </FONT></P>: J- W& M# T5 k- m% }
<P><FONT color=#0000ff>#include <PROCESS.H>1 n4 r% y  I; ]6 y: @( s$ F6 Q4 H9 u
#include <STDIO.H># `0 K) j( D7 u7 m
#include <CONIO.H></FONT></P>
; a. ]) K" _6 m# T1 _  s7 x7 d<P><FONT color=#0000ff>int main(void)
' |  r& q- ?( D4 z, [{
% @! c# b; Z' t2 Z8 ^+ P8 P2 rint result; </FONT></P>
& i' s2 H8 W8 E/ Y' t<P><FONT color=#0000ff>clrscr(); % T5 @0 f; Y( ?, G/ H
result = spawnle(P_WAIT, "tcc.exe", NULL, NULL);
0 X2 {/ O0 @6 @7 X: I# y* uif (result == -1) 6 I) Z" U+ {: ?7 J1 d
{ & F. r' }& r0 N+ ]! E
perror("Error from spawnle"); 2 f% R0 F$ {! J
exit(1); , y/ g8 J+ M. k' e; X: D! i
}
. y; v5 Y( r8 P% p$ C' Greturn 0; 7 {1 ?2 |8 W+ W% D
} ' T% K# ^* ?1 k4 S) a! g

' G" @* j1 m/ M. }* r7 l# p& m: z2 [; v% D- y) r
</FONT></P>" t6 Y9 ~: A) w# Z" w! F- Y  ^
<P><FONT color=#ff0000>函数名: sprintf </FONT>
% O6 F* K7 [' h( I' h4 w. f功 能: 送格式化输出到字符串中 & D6 [2 h8 D& V1 f0 J; Q* a
用 法: int sprintf(char *string, char *farmat [,argument,...]); 2 [$ h; r$ \# Z7 U* ?: l3 Z
程序例: </P>
# U6 p$ d4 a) G  @+ u' M1 @<P><FONT color=#0000ff>#include <STDIO.H>) W7 i9 |* C) X: J5 t
#include <MATH.H></FONT></P>: v2 ]- }; g6 v9 i+ S7 d, r+ C
<P><FONT color=#0000ff>int main(void)
6 T8 \6 G, r0 z  D{ , f+ K1 B0 ]& f. {6 q- T( n
char buffer[80]; </FONT></P>) x1 f2 g1 M/ @9 T6 i
<P><FONT color=#0000ff>sprintf(buffer, "An approximation of Pi is %f\n", M_PI); ) i) v' A& s0 S; D8 x9 o0 i4 W3 }( s
puts(buffer);
8 `9 K; A3 |# l& M/ S; Q7 jreturn 0;
5 \- J* l$ p! w5 g}
" v  L; j+ r* _6 c& ~3 T" g</FONT>, Y8 ?( T/ V2 T0 z
</P>
% i8 [8 [) D3 L. c! L<P><FONT color=#ff0000>函数名: sqrt </FONT>
; A  ~- J) m! P- c0 [4 e# _功 能: 计算平方根 0 u6 Y3 k9 }0 E: O
用 法: double sqrt(double x);
: W" W- U; y4 U; S5 F+ Q程序例: </P>
1 S1 u1 q5 v5 o$ b7 C<P><FONT color=#0000ff>#include <MATH.H>
1 h& @, U. x6 b. g#include <STDIO.H></FONT></P>: _  k7 ]9 r2 r! [) a0 U. h
<P><FONT color=#0000ff>int main(void) * \0 U- H; i) v0 F5 q6 m1 l
{ : G& w2 Y6 s! p9 u; ~$ k- G! T
double x = 4.0, result; </FONT></P>
7 t% f9 H- J% ?# B1 u: V6 w* t<P><FONT color=#0000ff>result = sqrt(x); ) ]& E+ O' i* D: H
printf("The square root of %lf is %lf\n", x, result);
  |: t2 r' [2 Y; Y$ o: ^0 `return 0;
) A: a4 a1 Z8 a} & _* G8 K3 F  O7 X
</FONT></P>
& O+ G6 j- s" Q4 d<P><FONT color=#ff0000>函数名: srand </FONT>+ Y2 G9 J& }% f4 u4 H6 W
功 能: 初始化随机数发生器 ; w' h5 v- E: \8 i( w* N6 k! x! w
用 法: void srand(unsigned seed);
, ?9 p3 \3 I7 g( ?  U1 I程序例: </P>
& m7 y% z2 i7 }: G$ Y<P><FONT color=#0000ff>#include <STDLIB.H>
  \; M0 X+ R* p  c#include <STDIO.H>
; F8 L+ c4 x: H. `: ~/ a! z#include <TIME.H></FONT></P>
4 o; A2 z( B' [7 J# g<P><FONT color=#0000ff>int main(void) 3 n; Z7 y6 ?1 P2 v/ L- b9 _. y) @
{ ; W0 ^/ O8 k# w2 h1 ^
int i;
8 K$ {* }0 w% k# l" M4 a) j6 \time_t t; </FONT></P>1 ]- }) x; W6 n& n
<P><FONT color=#0000ff>srand((unsigned) time(&amp;t));
3 U/ E) X$ s" |+ n% m( Fprintf("Ten random numbers from 0 to 99\n\n");
4 a# w; e' g& ~/ Q% \for(i=0; i&lt;10; i++)
" g! ^- l0 `- t' Tprintf("%d\n", rand() % 100);
1 A* b& {2 B% y5 d. j+ L5 nreturn 0;   a; Y- c! T/ r6 e: R0 X; K$ \4 u
} $ c* Z" V) m/ D1 W; H9 i
</FONT>
9 ^; }: E/ Y1 c. W) e# o" f& d</P>' l6 S% k( @+ U$ e/ |
<P><FONT color=#ff0000>函数名: sscanf </FONT>
0 R% c% l6 ~2 _0 C0 [& Q2 U" Y" a功 能: 执行从字符串中的格式化输入
; Z% j7 A  `6 P1 [& @: U用 法: int sscanf(char *string, char *format[,argument,...]);
0 `; J+ o7 h1 x" g+ u程序例: </P>
7 e: E: L9 E0 E" J<P><FONT color=#0000ff>#include <STDIO.H>
9 N, [5 s, s0 N, R9 v#include <CONIO.H></FONT></P>
2 n& S# ~* w" K$ P5 d/ w" ?<P><FONT color=#0000ff>int main(void)
3 G- J0 t( u- n0 t( b$ l: [{ 4 V" T3 y% i& }0 z9 F2 l
char label[20];
! B/ W, U  t3 Z* q: p( F! e& bchar name[20];
1 X* ~7 K7 k- d* kint entries = 0; " G& J2 _6 z" J$ z  @" a6 E; G2 G2 H
int loop, age; : Q5 W  b3 J2 ?7 V4 v
double salary; </FONT></P>/ N8 ^! u6 |7 P* M+ d" t9 Z3 Q( f$ I
<P><FONT color=#0000ff>struct Entry_struct
& E, h7 N$ D2 H{ : h- h) Z* o2 S$ i0 ]! {! d
char name[20]; % ~' @' N9 e' A4 e
int age;
$ w( H+ K7 v1 M. r$ x% Cfloat salary; ' M& d+ K5 c5 f) d8 W
} entry[20]; </FONT></P>! ~9 f- w$ T- X% s
<P><FONT color=#0000ff>/* Input a label as a string of characters restricting to 20 characters */ 5 V  K( L% B3 I- _2 b+ d& R- k1 x8 [
printf("\n\nPlease enter a label for the chart: "); / H/ o2 l1 }5 q
scanf("%20s", label);
! z' ^  M7 ]& ]fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>9 b9 T/ c. v0 D  r
<P><FONT color=#0000ff>/* Input number of entries as an integer */ ; m) ]  P2 l. Z( m. P* Q, X5 P
printf("How many entries will there be? (less than 20) "); ' u$ H7 c# u, n% u' u( \
scanf("%d", &amp;entries);
$ @+ P& Z: I' ]: W& c2 ?7 Nfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
, C' u$ y* V+ Y<P><FONT color=#0000ff>/* input a name restricting input to only letters upper or lower case */
  J% w' z! z2 {* _for (loop=0;loop<ENTRIES;++LOOP)
1 e8 G8 g7 h* n! e+ F( g4 Q1 ?+ ~ { 9 n4 {+ t7 f3 a- h# A) S
printf("Entry %d\n", loop);
  A( E( d% B1 b! z( l1 |! vprintf(" Name : ");
5 g9 D) U  `4 a- i8 u9 sscanf("%[A-Za-z]", entry[loop].name);
- m# U: P  @1 l7 v% _fflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>1 f/ x8 e9 M- [
<P><FONT color=#0000ff>/* input an age as an integer */
" P, X) d- z& i/ Q( W8 Wprintf(" Age : "); 1 j1 Y; ?- P0 e) I1 {2 G7 L: [4 x
scanf("%d", &amp;entry[loop].age);
9 i" }$ k) M3 ^# T6 z) Jfflush(stdin); /* flush the input stream in case of bad input */ </FONT></P>
) l: g1 @6 K% a8 F+ Q7 N; b& f4 A<P><FONT color=#0000ff>/* input a salary as a float */ 0 W8 [' a: ~# M
printf(" Salary : "); 7 \' T. w8 V9 S& e
scanf("%f", &amp;entry[loop].salary);
9 {7 Y# \8 f0 g; T9 L/ ~1 R4 efflush(stdin); /* flush the input stream in case of bad input */
- x7 M' g! f- n- d0 ]} </FONT></P>' R0 t2 s8 \, J; v$ y! B
<P><FONT color=#0000ff>/* Input a name, age and salary as a string, integer, and double */
6 e$ I, t' D' w0 Dprintf("\nPlease enter your name, age and salary\n"); 6 A" r  q$ ~( p2 z( k: W
scanf("%20s %d %lf", name, &amp;age, &amp;salary);   E' S: d4 X7 v6 t  T9 k& S* B: i8 C
</FONT></P>
4 x* F8 p3 c8 e<P><FONT color=#0000ff>/* Print out the data that was input */ 8 y  s3 M3 i8 U; p# B9 U5 [6 n. ?9 o
printf("\n\nTable %s\n",label);
8 c; C# G* D& R4 t; \* F, L1 pprintf("Compiled by %s age %d $%15.2lf\n", name, age, salary); 9 I  D' x9 O! I$ ?( ~# Q( ?- |
printf("-----------------------------------------------------\n"); 7 E& J3 T" s1 G1 @  h
for (loop=0;loop<ENTRIES;++LOOP) , l8 P( E8 Y. O: ]9 q
printf("%4d | %-20s | %5d | %15.2lf\n",
; F& {( u/ ]2 H/ ^+ f. T4 wloop + 1, / F. {' ^6 k& o4 j  t6 f7 h. e
entry[loop].name, ; H" i" @7 y2 g, a. y3 h( ~
entry[loop].age, , m/ d- u4 s1 L) j" ?$ P8 [
entry[loop].salary);
" d: H0 H4 S( F5 ~- j3 Tprintf("-----------------------------------------------------\n");
: a6 ~8 @( H7 R, ?, m! }! d, A' hreturn 0;
$ Z: |& h$ x* t+ j7 E9 v}
3 S9 q2 c. x/ k2 l; P/ `. x" u
9 f2 L5 P  i/ \; ~' j5 _</FONT></P>
3 B4 j' |% \6 ?<P><FONT color=#ff0000>函数名: stat </FONT>
, W7 d; a* B" |' t5 L+ b$ _功 能: 读取打开文件信息
' J- T5 g* g8 Q/ @5 N  F用 法: int stat(char *pathname, struct stat *buff);
2 R6 t  M( c! i6 Z& c# x/ G9 U  R程序例: </P>% _3 W0 G) I5 Z( Q5 c# ^
<P><FONT color=#0000ff>#include <SYS\STAT.H>
% t1 [3 F- j' c( [6 [4 G5 ?& J#include <STDIO.H>& @" @' \4 g# C/ L0 {3 Y3 @. ?
#include <TIME.H></FONT></P>
5 H- m2 _# ]. H6 }6 M<P><FONT color=#0000ff>#define FILENAME "TEST.$$$" </FONT></P>
- T- H5 Y- |( E% c9 `' L. P) j<P><FONT color=#0000ff>int main(void)
  {9 d' {' Z1 W1 r/ q9 D0 {6 [{ 6 ?- ?6 p0 K& n' T
struct stat statbuf;
! y: b+ N8 _1 `6 C; pFILE *stream; </FONT></P>0 b# u# l" h9 A& i6 y2 w
<P><FONT color=#0000ff>/* open a file for update */
$ ?  _& \1 C. ]4 q. Lif ((stream = fopen(FILENAME, "w+")) == NULL) 4 w! v& @# g$ f
{
  E% S0 G$ Z+ b, {9 i7 V2 nfprintf(stderr, "Cannot open output file.\n"); " r; b- ]& u1 a1 q. y2 z1 O2 u) g
return(1); 6 q+ t3 ]+ ~, s# \! k/ ~5 @+ a% s  ]
} </FONT></P>
8 C7 M" S6 F9 ~7 s5 r( I<P><FONT color=#0000ff>/* get information about the file */ / K& M7 z( Y  l# i
stat(FILENAME, &amp;statbuf); </FONT></P>/ J1 M$ b7 ^5 q- {. [, l" ^
<P><FONT color=#0000ff>fclose(stream); </FONT></P>5 ?5 Z: n9 Z9 n9 ]
<P><FONT color=#0000ff>/* display the information returned */
' D+ T6 X8 K" q+ k6 b, o( `if (statbuf.st_mode &amp; S_IFCHR) 4 h7 @# c& R! b$ @$ w6 C# D2 f
printf("Handle refers to a device.\n"); . k2 L4 `4 q6 {! X: M
if (statbuf.st_mode &amp; S_IFREG)
- k, d" j8 }; X& C  E6 cprintf("Handle refers to an ordinary file.\n"); ; [4 s5 k( m% O% v2 v9 ?7 J
if (statbuf.st_mode &amp; S_IREAD)
# u; {8 }/ z, i$ X3 T* k3 sprintf("User has read permission on file.\n");
/ V! _- |$ b5 O! `" Z, C9 Jif (statbuf.st_mode &amp; S_IWRITE)
3 s$ q* N1 B6 `printf("User has write permission on file.\n"); </FONT></P>
8 H2 Q& v5 P) t7 F- i2 G<P><FONT color=#0000ff>printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); / G8 {; n  G& X0 U7 y9 O2 K
printf("Size of file in bytes: %ld\n", statbuf.st_size); 5 [! J" v: \# K8 a+ }; h9 Y) H; `; x
printf("Time file last opened: %s\n", ctime(&amp;statbuf.st_ctime));
9 R1 @5 @; X/ v& P8 d4 g( K: t. {1 xreturn 0; - T! _# L9 ]/ {% w) y
}
2 L7 O: J6 A! }6 N6 e& g2 t7 R& S  G3 x# I9 N3 W  C. q
</FONT>6 r, k4 M, U4 }) [' i
</P>
9 c' z& P8 l9 Q5 L/ b' b. i+ p1 f  J<P><FONT color=#ff0000>函数名: _status87 </FONT>6 y* y1 Y# ?$ h( B
功 能: 取浮点状态
+ \$ K1 |2 d$ b0 G% I" l用 法: unsigned int _status87(void); + ?5 e' i. }2 s: n' y5 P3 p
程序例: </P>( }4 K5 r  y% Q, Q1 Z$ U
<P><FONT color=#0000ff>#include <STDIO.H>
  j7 }; n. e" w9 w: B4 Z) v  ?#include <FLOAT.H></FONT></P>9 L) H. ?  p) C' M1 d; @" k
<P><FONT color=#0000ff>int main(void)
  _: F! P; T* c2 ]! Y) c- ~{
: A3 x& H( n0 m. b% Lfloat x;
. E) N( `+ U2 h' [, s6 I  u: M( Pdouble y = 1.5e-100; </FONT></P>
  t" D. l& D% N& w: U<P><FONT color=#0000ff>printf("Status 87 before error: %x\n", _status87()); </FONT></P>- j' S  j/ U" e  j
<P><FONT color=#0000ff>x = y; /* &lt;-- force an error to occur */   x  A2 p! ~, g7 W7 L7 H! K
y = x; </FONT></P>
  g; X( x8 i# j' M, C+ W<P><FONT color=#0000ff>printf("Status 87 after error : %x\n", _status87()); 7 i" ]) i* {% c. k; s, I3 b
return 0;
- w( @5 t" ?# M9 h' `& m1 m' X}
% U9 q/ C3 b$ U8 l, H</FONT>
: J( k: b/ U7 A) g; U; U; D</P>
" n" X' Z; p$ c8 S# N. `5 v* s<P><FONT color=#ff0000>函数名: stime </FONT>$ U% z: J# m4 [- u
功 能: 设置时间 - i2 n* W! l) \# R4 z( q
用 法: int stime(long *tp); % T# c* C+ v, \+ l$ z6 r
程序例: </P>( u  C) ?1 W& b5 L2 y3 s3 O( c3 Y
<P><FONT color=#0000ff>#include <STDIO.H>- p( s8 c/ S& o. q$ `4 Z
#include <TIME.H>+ @, |& ^/ k. H& q$ a
#include <DOS.H></FONT></P>8 u* p& K& J6 N7 d
<P><FONT color=#0000ff>int main(void)
$ b2 L" l$ E- \" K. y{
& W; T: a: j4 y4 Q- dtime_t t;
4 }9 S- e, s* b- [9 }struct tm *area; </FONT></P>
% P$ O5 U7 \1 R; S( L( n<P><FONT color=#0000ff>t = time(NULL);
% k; ^- K* p4 uarea = localtime(&amp;t);
3 Z) c6 }' ~6 @5 Dprintf("Number of seconds since 1/1/1970 is: %ld\n", t);
9 e& [  {0 d6 R; }3 {7 Uprintf("Local time is: %s", asctime(area)); </FONT></P>- F, n5 K8 m) h1 W/ ~
<P><FONT color=#0000ff>t++; % E7 i3 z; V5 j6 F; B/ M# T0 C6 t
area = localtime(&amp;t); & p; F+ [  c( P: H
printf("Add a second: %s", asctime(area)); </FONT></P>6 D* {. D, s# v8 x5 b" x% \
<P><FONT color=#0000ff>t += 60;
3 `- D" f! [9 I8 {/ O' [area = localtime(&amp;t); * X. u4 o& G" p2 G) N8 h" G
printf("Add a minute: %s", asctime(area)); </FONT></P>8 q/ {6 v( R3 Z& I& ~# Q
<P><FONT color=#0000ff>t += 3600; 0 `4 `( w& k- H+ P9 {& F7 [: A
area = localtime(&amp;t); - L$ T8 R! x7 V& n. y" h
printf("Add an hour: %s", asctime(area)); </FONT></P>& L  k/ Q; M; w
<P><FONT color=#0000ff>t += 86400L;
5 ^! l) ^0 b% z& K: m" W- rarea = localtime(&amp;t);   l1 H. B7 h6 @. o2 G) E9 L- J
printf("Add a day: %s", asctime(area)); </FONT></P>& w/ w4 W3 H! {1 b
<P><FONT color=#0000ff>t += 2592000L; * o: R7 b' e1 O, [$ U
area = localtime(&amp;t);
! G' N4 Y1 }0 q, eprintf("Add a month: %s", asctime(area)); </FONT></P>
- h( `  A- T3 G. t<P><FONT color=#0000ff>t += 31536000L;
: z1 Z5 d( G& u) }2 Sarea = localtime(&amp;t);
2 ?3 N. n' Q; F+ Rprintf("Add a year: %s", asctime(area)); ' B( S' B, r4 @+ Y2 D- }
return 0;
; J3 W- j. l" N9 F" B# L% Y; w} </FONT>' \7 O& _& b8 r" v! G: X8 X  ^

* O; t" L+ R5 E7 ?
, \6 h  v# @: X  K& m</P>
( P# O1 t  |  @<P><FONT color=#ff0000>函数名: stpcpy </FONT>
) o, i. i# B! b( @* @9 }: j" l6 E功 能: 拷贝一个字符串到另一个
5 C. B! v5 T  N3 {' J: v5 h0 @& q用 法: char *stpcpy(char *destin, char *source); ' U3 M" N0 Q# h/ w0 E7 i8 r
程序例: </P>
& p8 o% G6 N, v( x0 w, c' r<P><FONT color=#0000ff>#include <STDIO.H>
% O- F% e  J) C" C#include <STRING.H></FONT></P>9 b2 T' a$ I6 i5 [" k  _
<P><FONT color=#0000ff>int main(void) 7 n- Y$ P- A; z5 t" M/ Q" C* _
{ / _4 t5 v; a  v; W$ p
char string[10];
- G( y5 Z$ v, N. D9 ^) q5 C- Vchar *str1 = "abcdefghi"; </FONT></P>
& Y) W; ]. s4 ^! k5 Y<P><FONT color=#0000ff>stpcpy(string, str1); : W! y0 w9 t: L# f9 w% v# w& u
printf("%s\n", string); 4 D: M/ P. f! f% `$ x
return 0; $ w4 Z8 u8 B) u& r2 C$ }0 x
} 5 G2 L# i  r+ H  Q7 x
5 u+ r( T9 c2 V* r: }- H! b" R
</FONT>6 y# X9 ^; A# C
</P># I% ]  H$ k: a9 |1 y
<P><FONT color=#ff0000>函数名: strcat </FONT>) O# c9 H( n: o$ G% O
功 能: 字符串拼接函数 5 Z: N. R6 K6 j& a
用 法: char *strcat(char *destin, char *source);
6 B4 }- E$ ], k- T程序例: </P>( H8 g2 s  A$ D4 B
<P><FONT color=#0000ff>#include <STRING.H>
' ?) T' U# [. k4 g  m$ k#include <STDIO.H></FONT></P>
2 D1 P0 ~5 Y( r- I7 o2 ^<P><FONT color=#0000ff>int main(void) 6 S6 X% t" q% g1 ?8 Q7 E
{
, n  O# w, v8 o! g! a$ b0 J4 fchar destination[25]; - X3 J7 F* g: D
char *blank = " ", *c = "C++", *Borland = "Borland"; </FONT></P>
# K5 W+ u& b# y4 W" E% v9 q8 D<P><FONT color=#0000ff>strcpy(destination, Borland); 9 o5 k! o: f! K: M
strcat(destination, blank); " F: z% s+ m# b2 P
strcat(destination, c); </FONT></P>
5 x" [0 f" U6 v) H: _- f! P<P><FONT color=#0000ff>printf("%s\n", destination);
8 |% [, j6 P5 F6 @) n( G- jreturn 0;
: _0 x" D, R" I  E8 M! S7 V1 W} # \( H4 A) H, O7 E6 Q9 W0 ~' s

! Q& O$ E, g) N2 R% J1 O6 }</FONT><FONT color=#ff0000>
! X! l" X$ e$ r9 `</FONT></P>
  C8 K. f* t6 m3 c/ J. O<P><FONT color=#ff0000>函数名: strchr </FONT>, J6 i) a9 R$ _  }
功 能: 在一个串中查找给定字符的第一个匹配之处\ % `0 n4 g! }$ {+ W4 t
用 法: char *strchr(char *str, char c);
- j; t: x, M4 G5 i% Z4 @- J/ d程序例: </P>$ u! R/ C! b3 h" H4 d) m" R5 M
<P><FONT color=#0000ff>#include <STRING.H>
9 I1 Q) u3 T: g) C; H! g: o#include <STDIO.H></FONT></P>
( _/ W2 ^& o* q7 f0 {<P><FONT color=#0000ff>int main(void)
/ }2 Q( l  Z' ?7 @$ H+ k( f{ 1 y, [% ]9 [$ c, [3 {, R
char string[15]; & M' h. \: f+ G* ]- }6 n
char *ptr, c = 'r'; </FONT></P>: w( I5 x3 d+ @. l1 m+ n( n, M' |
<P><FONT color=#0000ff>strcpy(string, "This is a string"); / C# v  x. _# y( w" ~& v  r& t1 e
ptr = strchr(string, c); ( m: d$ @4 n" L( {8 t$ T' @
if (ptr) 7 P8 U$ _# H. A/ s7 A* E' H
printf("The character %c is at position: %d\n", c, ptr-string);   ~$ }) f4 T- N! k
else # j( V% B6 }$ H  x5 G4 E
printf("The character was not found\n");
$ r* m7 v7 u3 _/ x" z3 @& kreturn 0;
% \5 ^4 ]) S- y( S}
& _6 O2 [0 g9 `  O4 |6 P5 {# q</FONT>
! p- x& o  Q; y0 {. M/ q. u. B; D3 u, O# e# N: i9 N: Z
</P>
8 r4 C7 B* T$ ^. M9 [<P><FONT color=#ff0000>函数名: strcmp</FONT>
% `6 c3 {; n- l2 I% a功 能: 串比较
, q3 E: ^- ^  }. c用 法: int strcmp(char *str1, char *str2); ; d* T: J  u: I: V  g! v- p7 L
程序例: </P>
% |7 i; D9 }3 b<P><FONT color=#0000ff>#include <STRING.H>' H1 ]& A5 F- X
#include <STDIO.H></FONT></P>5 ~, r2 Y- B2 y  c# y
<P><FONT color=#0000ff>int main(void) , T1 t1 J  h: ]; O
{   ]" G) J! s, j( t4 s
char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";   i" ]" o3 C9 o* Y
int ptr; </FONT></P>5 A# G4 g: N7 {0 z4 D% T
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf1);
! `9 F' {  H+ x- A( I, g. Zif (ptr &gt; 0) 9 \! X$ ]5 |. v* R4 O  G0 l9 V
printf("buffer 2 is greater than buffer 1\n");
/ n7 _- V& {5 C  B" N# [' Zelse
6 n- z  [, P- a( F+ U4 W, Kprintf("buffer 2 is less than buffer 1\n"); </FONT></P>: ~- R- f5 y/ ?4 ~
<P><FONT color=#0000ff>ptr = strcmp(buf2, buf3); ) k" D4 C% ^- O3 Z
if (ptr &gt; 0)
4 {" T- K$ Q$ _/ E- p( a! Bprintf("buffer 2 is greater than buffer 3\n"); ' R# O8 Z* V1 b0 _7 d, `! I
else + d' T" W, U* a' m5 I
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
  T# _+ H% ?* v' u6 N<P><FONT color=#0000ff>return 0; / x: x. s! D8 ]' Q! z3 T1 _
}
% T$ A7 {: g  Q! a: Q) o0 i6 [! E3 D) i; Z

! a" Q  C7 x+ O" x0 a</FONT></P>6 Z2 }# @) `4 [/ d, P
<P><FONT color=#ff0000>函数名: strncmpi </FONT>- ]0 b, P7 A9 m
功 能: 将一个串中的一部分与另一个串比较, 不管大小写
9 U, `1 X7 e& o用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);
! R# R" {( u9 ~. m程序例: </P>
; K" L) g8 }9 W7 i; f  x" g<P><FONT color=#0000ff>#include <STRING.H>' x) {& B- p& ?. Y5 U. f
#include <STDIO.H></FONT></P># r5 S, K8 I: F! R9 O  L; l
<P><FONT color=#0000ff>int main(void)
6 |8 X& a* J+ t. Z{
6 \1 p' O4 B3 Z" M0 \char *buf1 = "BBB", *buf2 = "bbb"; + t: v! ^0 g/ A7 u4 W) r0 [
int ptr; </FONT></P>
# I" p$ r- K1 m: R; b0 \3 L" `6 N<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
9 Z, J0 F8 c0 o4 _% }) T<P><FONT color=#0000ff>if (ptr &gt; 0)
5 e) ?8 V+ m: xprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
1 F: _* q: g3 B& Y<P><FONT color=#0000ff>if (ptr &lt; 0) ( {" X6 b; Y0 L  \! \0 m* P
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
; V' Z$ I& C& E. Y& }, I1 Q0 Q<P><FONT color=#0000ff>if (ptr == 0)
- E5 o# r% `, q$ E" D" V/ sprintf("buffer 2 equals buffer 1\n"); </FONT></P>
9 {# a  r- G3 `  n3 P; @( T<P><FONT color=#0000ff>return 0;
+ ^" F0 o; r* V, J8 h2 R6 \' w} - ]( s& J7 k- @- I- R! K) X0 \

* H4 g) p( y( u8 C$ e</FONT>  ?% e& C! R! m  J& K3 |
</P>
& D; u" f$ L- U1 i! s) n+ @<P><FONT color=#ff0000>函数名: strcpy </FONT>: S2 }- x5 P! u
功 能: 串拷贝
7 ?$ z8 ?3 C# ]用 法: char *strcpy(char *str1, char *str2);
9 e: u* a0 R7 U程序例: </P>5 H6 n. [' u) k( ~( m+ d. p6 Y
<P><FONT color=#0000ff>#include <STDIO.H>
! N& Z# G7 M3 ]7 l4 e& N: B- n  Q#include <STRING.H></FONT></P>
' T( w6 b  f& o! x<P><FONT color=#0000ff>int main(void)
7 i( _1 z+ J' r4 d% K; c: s1 L{
9 f- y' }/ h  J6 w& Echar string[10];
' x1 }: b2 F( ?5 a0 @char *str1 = "abcdefghi"; </FONT></P>: }5 W* y, t9 B3 f* z
<P><FONT color=#0000ff>strcpy(string, str1); , M* j. l: H1 l
printf("%s\n", string);
1 ]4 U3 Q4 H3 ~9 h8 @3 }" Ireturn 0; 5 b5 i4 i2 q& O& Q' m) B
} 8 J% C! r& @3 _
</FONT>3 T7 U, `5 S1 P' X& K+ L

; S5 c( j) x2 l" O/ M& z</P>  c0 q+ Y( ?: R" Y. }9 n
<P><FONT color=#ff0000>函数名: strcspn </FONT>3 C4 o" |& r/ K8 g( s+ Y
功 能: 在串中查找第一个给定字符集内容的段
: t) C- E% m$ T4 k; ?用 法: int strcspn(char *str1, char *str2);
2 C5 s8 Z( A: U; z7 M! m程序例: </P>% M& E+ p- y4 R' |7 [$ q. [
<P><FONT color=#0000ff>#include <STDIO.H>
/ Q. O; P: M7 A2 g+ Y8 x3 z$ K1 ]2 }#include <STRING.H>
1 H/ L7 V9 V0 m9 y2 \6 y#include <ALLOC.H></FONT></P>
9 W+ p4 ^1 m, k/ x+ e# \& H8 @, b<P><FONT color=#0000ff>int main(void) / w  r, S' I& @4 E" a1 Z0 ]
{ 4 T1 Z, y: U# G1 [! P5 \
char *string1 = "1234567890"; & u! D8 [; k$ ~; `- W  N7 `
char *string2 = "747DC8"; & u" O; g' h1 s( i1 b
int length; </FONT></P>
4 K$ @4 e" U! x, A& @<P><FONT color=#0000ff>length = strcspn(string1, string2);
9 X* c) ]/ @  z3 W8 L& Q" @printf("Character where strings intersect is at position %d\n", length); </FONT></P>( P7 H; k" D7 w; ]
<P><FONT color=#0000ff>return 0; ! `, P4 x: c$ L* p
} ' S% b# B' B9 Q9 J4 a1 Z& W  @
</FONT>
8 c! O" v' x+ [( P. E# q0 E
! `" z, W% g! b' t# t: J</P>( r) R  e6 P5 l8 |5 H
<P><FONT color=#ff0000>函数名: strdup </FONT>2 e9 i  S  z* V2 ]8 R
功 能: 将串拷贝到新建的位置处
! A) [6 @/ z2 m用 法: char *strdup(char *str); 4 u* L! i6 F) [
程序例: </P>; Y; t( l- n/ \7 g
<P><FONT color=#0000ff>#include <STDIO.H>
+ h+ `* G, j. D1 V) S#include <STRING.H>9 Y# N: l3 x1 H5 K7 h1 @& _8 M
#include <ALLOC.H></FONT></P>' u2 C' @: ^) X. E. E( `# S
<P><FONT color=#0000ff>int main(void) 6 o3 s* M' w- J2 W
{
* l9 u3 a$ u& ]  e# echar *dup_str, *string = "abcde"; </FONT></P>
/ A0 [: K: j& |$ b4 e( u- B- L<P><FONT color=#0000ff>dup_str = strdup(string); & B& y! G& K8 q; I. e! k
printf("%s\n", dup_str); + N# d" R: D5 |/ p
free(dup_str); </FONT></P>
7 }. {) @) _6 W<P><FONT color=#0000ff>return 0; ' D( ]% U, l  R$ o. L1 |5 p, ]
} 5 Z" V+ Z  C4 E' T7 D  O, |
  R& J) n2 Z. ~1 T
</FONT>. g9 R, A+ Q8 z/ W; Y% @
</P>* @$ g. z  c9 ~* H
<P><FONT color=#ff0000>函数名: stricmp </FONT>0 w( u  I2 _* J7 [
功 能: 以大小写不敏感方式比较两个串 ! {3 x! |: R3 {$ A, l- z
用 法: int stricmp(char *str1, char *str2); ( u' o4 p. V4 I* b3 _5 f% f8 W
程序例: </P>
( {3 N( ~2 x& g. s1 Z<P><FONT color=#0000ff>#include <STRING.H>: A5 U' V* u# q
#include <STDIO.H></FONT></P>2 ~! q2 \* D2 ?" j- l, F
<P><FONT color=#0000ff>int main(void)
; L: }6 f6 C% b# c# f{ # y8 }$ H; p. O
char *buf1 = "BBB", *buf2 = "bbb";
5 Y6 s$ b: a  \int ptr; </FONT></P>- D$ f6 ^  Y: a8 k
<P><FONT color=#0000ff>ptr = stricmp(buf2, buf1); </FONT></P>
& M* ?* e! n) V4 Y. N4 W<P><FONT color=#0000ff>if (ptr &gt; 0)
' |. T  j9 P5 W: M9 s. ?/ d/ N8 t6 Tprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
, d& M2 I: N0 B' S" s; J, {<P><FONT color=#0000ff>if (ptr &lt; 0) 4 }4 t. P2 r  a- h% O! L
printf("buffer 2 is less than buffer 1\n"); </FONT></P>
3 N0 S$ P( C' t  z3 I6 W6 m<P><FONT color=#0000ff>if (ptr == 0)
, w& [; M9 q- P7 v% Iprintf("buffer 2 equals buffer 1\n"); </FONT></P>% l4 |6 @3 J9 m6 ^- }
<P><FONT color=#0000ff>return 0; * P4 O% k: e2 V+ }/ ?
} & d5 z5 N4 q& C% j9 X
</FONT>
( P+ a) X7 F' r' w* {4 U</P>' ^  n6 Q, q) N
<P><FONT color=#ff0000>函数名: strerror </FONT>& y0 i* z1 L; Y( Y
功 能: 返回指向错误信息字符串的指针
+ l0 O2 y) P8 }$ ~% ?; d2 |用 法: char *strerror(int errnum);
/ _& Y+ D( h" _# v程序例: </P>
+ m  O3 O- N$ a  q, g7 B' l! N<P><FONT color=#0000ff>#include <STDIO.H># ^% `  r2 K, [9 L& `
#include <ERRNO.H></FONT></P>9 W9 S. ^3 K/ ]. o8 l2 f8 F: m/ h% U/ {
<P><FONT color=#0000ff>int main(void) : H, ~4 ~! f7 ~2 r% g- W( x1 E
{
7 e) s- t2 [0 `% f; [2 Cchar *buffer; $ F* N4 q$ }; ?9 _( d1 z+ H0 Q
buffer = strerror(errno); + W; c1 I; j# s8 t' e
printf("Error: %s\n", buffer);
9 B- b. [, L1 f) z) y7 G5 freturn 0; 5 i. n; G' t5 ?2 \3 A6 d
}
; {* H0 N8 B2 Y* r* n+ P( ~4 P
( d$ [% N2 ^. F4 _- |% m+ Z</FONT>, e. [% x/ P; E" Q* g- ~# d
</P>
; k0 z2 ?+ f0 R8 {% Y1 Y# B2 Q7 _! N<P><FONT color=#ff0000>函数名: strcmpi </FONT>$ c$ T5 s. j; x/ H& F
功 能: 将一个串与另一个比较, 不管大小写 6 e4 G, Y7 m" t7 F2 g# _) w
用 法: int strcmpi(char *str1, char *str2); & N$ Y1 n* Y+ G  }  j3 e# w. q
程序例: </P>: L" Z, X/ L, A& C+ K
<P><FONT color=#0000ff>#include <STRING.H>
, k( t9 m. O0 l  Z1 W- L' M; d#include <STDIO.H></FONT></P>2 B# m0 k, j- t: ^
<P><FONT color=#0000ff>int main(void) 4 }, ^& R3 }0 E* u8 K
{
. V  X5 t" x  e. Kchar *buf1 = "BBB", *buf2 = "bbb";
9 e" d: T  i# I' n  s1 Bint ptr; </FONT></P>
" w, p+ G1 r7 C$ M/ J/ v$ h<P><FONT color=#0000ff>ptr = strcmpi(buf2, buf1); </FONT></P>
6 b6 o2 r% p# ]9 ]<P><FONT color=#0000ff>if (ptr &gt; 0)
+ [0 C2 ~+ w8 E2 S) vprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>
* G) R9 e. L; u' c7 R<P><FONT color=#0000ff>if (ptr &lt; 0)
0 D6 r7 `2 L: L: M) W9 uprintf("buffer 2 is less than buffer 1\n"); </FONT></P>7 |& J) y- s9 d+ K: |! Z
<P><FONT color=#0000ff>if (ptr == 0) : |' V: G1 P2 A+ I, z
printf("buffer 2 equals buffer 1\n"); </FONT></P>  v0 {/ y6 a* Q  \+ S
<P><FONT color=#0000ff>return 0; % m2 ]- l( Q5 ^1 }0 Y. F
} 9 P0 H* g& }% L4 m  f
</FONT>
6 l# `2 ?2 r: n) b& k- d: T/ y; M+ a5 k0 C8 Q( u% M3 u/ g
</P>
& }: p' k4 M. A& t<P><FONT color=#ff0000>函数名: strncmp </FONT>- C) X! C2 A: X* n+ w
功 能: 串比较 4 @0 e2 z" |4 b. ~) o
用 法: int strncmp(char *str1, char *str2, int maxlen); 5 n3 _3 S3 O) l! h3 B) \
程序例: </P># U& d% @4 U& ?
<P><FONT color=#0000ff>#include <STRING.H>4 [+ C# f/ v% E& g8 P
#include <STDIO.H></FONT></P>3 g2 _) a4 K( V/ W- g+ H, H
<P><FONT color=#0000ff>int main(void) </FONT></P>
0 d4 h5 i& ~4 ~, L<P><FONT color=#0000ff>{
+ T8 K9 F9 B- q; d) p1 o. Y3 `char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";   a6 I; C4 d! W6 G) g6 c( k$ v
int ptr; </FONT></P>
$ V( L/ _. W; T  ]3 w/ j<P><FONT color=#0000ff>ptr = strncmp(buf2,buf1,3);
8 m3 q" j$ Y7 Z' \if (ptr &gt; 0) # e8 I* c+ Z+ m* K! c, a
printf("buffer 2 is greater than buffer 1\n");
* D1 o  r' X) @( Telse
( g' X4 G# F$ r  l+ aprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
+ |) ]1 A. m/ G) I7 U<P><FONT color=#0000ff>ptr = strncmp(buf2,buf3,3);
) l# w9 l6 y9 Z, v3 n7 x; xif (ptr &gt; 0)
; K$ M4 o' u' Y# W5 Q( k* Bprintf("buffer 2 is greater than buffer 3\n");
& ^" |. ]: \' Z- relse 8 c  R7 z: e% `7 u0 q; x
printf("buffer 2 is less than buffer 3\n"); </FONT></P>
& w2 i0 @7 d) N<P><FONT color=#0000ff>return(0);
: b+ o' B: c) q0 W} ) K9 [% ^6 A2 O# x

' [- T$ b- \8 h2 `5 N; k</FONT></P>
" D, p7 g6 }* [1 q$ U<P><FONT color=#ff0000>函数名: strncmpi </FONT>
# |; N& _8 H& c) h功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写
5 R/ E' U* D0 R7 u用 法: int strncmpi(char *str1, char *str2);
! T2 M7 J1 i# F) j程序例: </P>- ^: p8 T1 M9 _
<P><FONT color=#0000ff>#include <STRING.H>% B1 t. o# I" M: [3 i
#include <STDIO.H></FONT></P>- B: g- y5 X7 b5 n' g3 T( F
<P><FONT color=#0000ff>int main(void) ; x) L4 d* S- a/ ^2 ^+ A/ F9 S) D
{ ! w7 T4 H. K5 t8 L+ ]" I* J& f
char *buf1 = "BBBccc", *buf2 = "bbbccc"; / B) f: v, P' o, O# h
int ptr; </FONT></P>
" o4 @% Q. n1 g) x9 L<P><FONT color=#0000ff>ptr = strncmpi(buf2,buf1,3); </FONT></P>" v! h* j5 G# @( ?
<P><FONT color=#0000ff>if (ptr &gt; 0)
* ~9 z+ O1 i/ W& hprintf("buffer 2 is greater than buffer 1\n"); </FONT></P>& {# U) V0 J6 x7 p
<P><FONT color=#0000ff>if (ptr &lt; 0)
8 b& z: E$ s; t6 \8 sprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
: g- G( {  o3 |, c" _) z! R: d6 C<P><FONT color=#0000ff>if (ptr == 0) 1 f' D5 i1 O9 p: v; \+ P# V
printf("buffer 2 equals buffer 1\n"); </FONT></P>
2 ~; _, p7 M0 \3 \9 m5 S0 P* `<P><FONT color=#0000ff>return 0; </FONT>
4 Q* C, J, Y5 m1 n+ P}
: H* D1 }: W! {' V
6 a' _$ O8 G6 P# s- W</P>2 T) ~; f" A9 Q" W( _
<P><FONT color=#ff0000>函数名: strncpy </FONT>
) ?2 g7 X7 Y& J2 [1 D! j4 z功 能: 串拷贝 . f( D6 w1 D' W4 z% r( w# n
用 法: char *strncpy(char *destin, char *source, int maxlen); : [/ q, C1 F  w9 l8 q
程序例: </P>' e, B" W( ]5 s: E( s
<P><FONT color=#0000ff>#include <STDIO.H>
9 t/ f5 v4 J% p; r! l#include <STRING.H></FONT></P>
3 E+ q4 }2 p+ L. Z$ l* y2 B<P><FONT color=#0000ff>int main(void)
/ s) S' A% y6 m& t0 `' A{ 5 S) t/ R# A/ s; N! w
char string[10];
5 G! r) B+ N4 A8 n: Rchar *str1 = "abcdefghi"; </FONT></P>
* O8 \" B& M' A9 k<P><FONT color=#0000ff>strncpy(string, str1, 3); % u' m. f1 X7 X  N
string[3] = '\0';
! @6 E. ~: g( r+ T; n) `2 C: uprintf("%s\n", string);
8 P1 U' Y: D1 a2 x7 ~return 0; " M9 E' V* H: u7 Q
} 8 k7 ]* W! m; q2 y
</FONT>9 {, a/ k: a2 [/ h2 d8 P
</P>% z% l( \8 {- Z
<P><FONT color=#ff0000>函数名: strnicmp </FONT>( _4 U  Y) l7 r. F8 r
功 能: 不注重大小写地比较两个串
$ N1 q+ A9 w0 ]8 v* ~用 法: int strnicmp(char *str1, char *str2, unsigned maxlen); 3 J* r1 M6 T# ]1 x0 I' W
程序例: </P>: V; K' q0 s% F3 G6 w
<P><FONT color=#0000ff>#include <STRING.H>
1 N  [, U6 Q" G#include <STDIO.H></FONT></P>* E/ i4 d0 K# L0 m
<P><FONT color=#0000ff>int main(void)
, h" B: K% P( K) W+ ~{ ! U1 h6 U- @; w, f+ X
char *buf1 = "BBBccc", *buf2 = "bbbccc"; 0 _/ R6 y" B: t
int ptr; </FONT></P>. t" L8 y$ y8 a. n
<P><FONT color=#0000ff>ptr = strnicmp(buf2, buf1, 3); </FONT></P>
6 |3 R. m0 r/ ^8 S<P><FONT color=#0000ff>if (ptr &gt; 0) ' J8 t0 J7 s8 F  @3 m1 U/ z
printf("buffer 2 is greater than buffer 1\n"); </FONT></P>$ r5 m( |1 H5 M7 ?/ d
<P><FONT color=#0000ff>if (ptr &lt; 0)
7 d# {5 W+ @+ x# wprintf("buffer 2 is less than buffer 1\n"); </FONT></P>
* x6 o1 |, w- B0 T- k; g/ m<P><FONT color=#0000ff>if (ptr == 0)
5 q6 c) E+ f& Y1 T; |( V& T0 nprintf("buffer 2 equals buffer 1\n"); </FONT></P>
' x  s/ ~' j6 {( Z<P><FONT color=#0000ff>return 0; ) {# m/ a" Y: U5 C; m7 n1 k
}
7 E- p" J' m  |4 F3 v" E% ~* |! C8 S) t3 x9 F( I' M: G" @
</FONT>( A9 ~  b1 A& v5 I9 R' \+ s
</P>
: V. k' B1 u* d( A<P><FONT color=#ff0000>函数名: strnset </FONT>
0 {& i) e6 Q6 x  J% D功 能: 将一个串中的所有字符都设为指定字符 : c( h) K$ ]( o( d1 J* U4 V! c
用 法: char *strnset(char *str, char ch, unsigned n);
/ i; L- r% }5 N( ~  F" S程序例: </P>
4 q3 p7 p3 a6 d! {* t3 v* z<P><FONT color=#0000ff>#include <STDIO.H>% e3 L0 b4 X. a6 O. Q
#include <STRING.H></FONT></P>5 L) N; [8 w* K, Y! G
<P><FONT color=#0000ff>int main(void) & k5 P" ~6 _1 `1 [
{
, c1 @/ J9 i4 Zchar *string = "abcdefghijklmnopqrstuvwxyz"; 6 y3 x, ^8 h8 j7 I5 G- U# q/ o9 F
char letter = 'x'; </FONT></P>+ E' I6 ~% @6 k7 u  G
<P><FONT color=#0000ff>printf("string before strnset: %s\n", string);
) T; K. U6 R9 ~( a' istrnset(string, letter, 13);
$ ~# Z/ N8 m8 vprintf("string after strnset: %s\n", string); </FONT></P>
9 z2 W' f, t; ^: F, B<P><FONT color=#0000ff>return 0; ! b; p5 S8 j7 R3 }+ t) @6 ~
} % j: i% J& l+ a% G$ ^- C& X
</FONT>
* |  ^6 D3 k8 R/ D% E. y7 {8 ]</P>) E5 V+ F1 i# m+ `
<P><FONT color=#ff0000>函数名: strpbrk </FONT>% w% N% p5 g; V+ w
功 能: 在串中查找给定字符集中的字符
1 @0 @: W) Z$ b: x- f. b用 法: char *strpbrk(char *str1, char *str2); 7 t! f9 \4 D5 @" J- y( |) R. A, ~
程序例: </P>& F+ y9 U' @; L( h+ ?
<P><FONT color=#0000ff>#include <STDIO.H>% p0 X, Q* |5 B1 E
#include <STRING.H></FONT></P>
! Q# O9 g. Z* M  q! ~<P><FONT color=#0000ff>int main(void) , c7 f4 r; w& O+ d( t' C/ c
{ $ j2 B5 C0 C4 n: V) X% x( |
char *string1 = "abcdefghijklmnopqrstuvwxyz"; 9 C; L' D3 [- K0 K' `6 P0 e
char *string2 = "onm"; $ s+ Q/ j6 ]: t/ ?4 S
char *ptr; </FONT></P>
8 a+ W3 c3 G+ i; ]9 u7 k<P><FONT color=#0000ff>ptr = strpbrk(string1, string2); </FONT></P>+ D& t/ {$ P5 V: r) M- @9 O0 u. s
<P><FONT color=#0000ff>if (ptr)
$ G3 Y( B7 B8 I6 m" F! Bprintf("strpbrk found first character: %c\n", *ptr);
6 }4 ~- C0 Z# {/ _. L& B5 Q5 A6 welse
4 c: ~" p( d7 v* L  E5 c) y! ?printf("strpbrk didn't find character in set\n"); </FONT></P>
) |; N% Y7 y4 u- {<P><FONT color=#0000ff>return 0; ! H: e( z8 c- z- ^0 E. F7 ?4 ~
} 3 a0 o$ L% j2 `1 G) Q
+ E0 L/ L7 C* U7 E! }. Y# |
</FONT>
0 `0 @1 w. h/ G* Q) ~! M</P># o4 o5 C3 F( L" O
<P><FONT color=#ff0000>函数名: strrchr </FONT>
; L: q$ z8 G& Y; x6 |$ h功 能: 在串中查找指定字符的最后一个出现
% U9 C6 z: @" p7 x6 X0 }用 法: char *strrchr(char *str, char c); 0 a: K" m) F7 O& Q: u7 w
程序例: </P>+ R. Y' t  I" R
<P><FONT color=#0000ff>#include <STRING.H>/ @* z9 A% u" R9 A
#include <STDIO.H></FONT></P>7 W: A8 i$ b0 p4 P1 q' Z9 G9 p
<P><FONT color=#0000ff>int main(void)
) S  [4 Z6 @3 A{
% A$ T% t4 _! A7 K# bchar string[15]; 0 x, q5 d, ~' U; i  t  K
char *ptr, c = 'r'; </FONT></P>7 s6 Z& O! a2 O7 L$ k, V# S
<P><FONT color=#0000ff>strcpy(string, "This is a string");
5 U  e& \/ n  r7 u* L. \ptr = strrchr(string, c); 4 c- W2 }4 y) i- }% s* u
if (ptr) 2 M8 j! M' U9 b, o3 q1 c
printf("The character %c is at position: %d\n", c, ptr-string); * H7 I0 C5 ?% V) G: `# i% }4 |
else ! l$ [2 E6 @# @
printf("The character was not found\n"); & u) j* H1 D9 Z+ A
return 0;
8 S- B9 |% @/ I! y5 F} </FONT>
7 b1 ~% j& ~* K2 d2 x. G2 d7 q! b6 ~! D# z3 f4 X

# @1 q+ l0 q# S: _; g/ G</P>9 E* o& O( B' h, S" I5 h, S' U9 J
<P><FONT color=#ff0000>函数名: strrev </FONT>
3 `) K5 s2 I; Q" a- t: i7 @& e功 能: 串倒转
* g. P. k% f' Q5 |+ u用 法: char *strrev(char *str);
" O" A) e% v+ F" u程序例: </P>
* Z- o8 @" L8 s! R3 q2 }<P><FONT color=#0000ff>#include <STRING.H>; ]. {5 E4 f# j9 {/ ]7 C
#include <STDIO.H></FONT></P>% m) {$ n+ o. g) L0 e) w& C
<P><FONT color=#0000ff>int main(void)
) k: [# w2 x" l{ 6 U1 X# w2 t: i/ x9 h0 \& S
char *forward = "string"; </FONT></P>
# s) E# n5 e4 R3 T2 \6 p<P><FONT color=#0000ff>printf("Before strrev(): %s\n", forward); % y% i# k( c  V  i2 U8 r; N- W
strrev(forward);
2 |+ H) z9 v, z1 R3 }+ C# ^printf("After strrev(): %s\n", forward);
+ l. G* G+ ?, t2 F# {return 0;
6 l# I, y, {5 A& `/ _5 \' ^) f5 n. V3 g} </FONT>  W! V' R8 V( G, M7 f
</P>
1 V5 P& {' l- p5 }& w; R- I6 d+ g. T<P><FONT color=#ff0000>函数名: strset </FONT>. U8 L9 q4 |. e# B: d  I
功 能: 将一个串中的所有字符都设为指定字符 8 C7 A) U, i' Q* R. S) h0 h
用 法: char *strset(char *str, char c); % z0 f' r* |) _+ {( e+ o
程序例: </P>7 F  b, D' G  F6 M* e) ]# V* r
<P><FONT color=#0000ff>#include <STDIO.H>
: S" ?* m' P5 @/ t5 u#include <STRING.H></FONT></P>, c6 Y1 P" T7 `. G
<P><FONT color=#0000ff>int main(void) ! M/ |- ^) i/ |7 o+ M; A( Z
{
; |) r( ?( F) L8 C* G) vchar string[10] = "123456789"; ; n2 E, v2 h9 u: F
char symbol = 'c'; </FONT></P>0 Q8 J( E) y# z% u. Q* r
<P><FONT color=#0000ff>printf("Before strset(): %s\n", string);
; j3 O! @1 o' Z1 X# i* [( {strset(string, symbol);
* `; M3 R# P$ e4 S) t( d, F6 wprintf("After strset(): %s\n", string);
6 E1 h/ k, T# ^return 0; 0 ~' `% @  r# g& U9 M
}
9 ~1 Z0 @, n$ q! D
1 t$ ]0 v2 l" B7 K; V</FONT>7 F: ^; ~, O" ~1 n
</P>
4 z1 [. \: T. Z5 I& r7 \/ D<P><FONT color=#ff0000>函数名: strspn </FONT>
2 h" v0 v" _* }0 {5 }& k* z功 能: 在串中查找指定字符集的子集的第一次出现
* a9 {# U5 t: Z3 t2 |" M用 法: int strspn(char *str1, char *str2);
% y" ^& ~3 z: X3 d( @程序例: </P>6 L7 n' q" m) }5 o3 R
<P><FONT color=#0000ff>#include <STDIO.H>
2 f8 o% l! W/ U( W+ v$ u#include <STRING.H>
; V  |; v0 L9 C" {#include <ALLOC.H></FONT></P>3 D. a( P# u' ]6 j! q
<P><FONT color=#0000ff>int main(void)
+ v4 e* c2 b7 s, S( s5 o{
8 A- W1 ^% C7 H& t$ @" z( D- Hchar *string1 = "1234567890"; 8 L- @3 M/ y* D" H0 r7 G, }
char *string2 = "123DC8"; * Z) N" S1 M2 @9 m
int length; </FONT></P>
9 r. t% {4 I5 W: v  O( {+ d<P><FONT color=#0000ff>length = strspn(string1, string2);
1 S( l( K  ]& H9 L8 rprintf("Character where strings differ is at position %d\n", length); 9 n7 m8 ]; O' ~! z8 ]# k1 O
return 0;
% c' M# Z- u( v9 c: J} ) ~1 `1 \% l2 r5 A4 o7 {
</FONT>0 I" p9 s" T0 h! y2 N! X. f: D* b4 [
</P>
! w( g' n  }" D+ W: }# O8 _<P><FONT color=#ff0000>函数名: strstr </FONT>
+ u  ]( |6 e  b功 能: 在串中查找指定字符串的第一次出现 # Z& o+ ^+ }, i
用 法: char *strstr(char *str1, char *str2); * M& y' x4 ^* f/ {/ `/ R3 o% Y# f
程序例: </P>+ T  Y0 k8 r& ~, o  S
<P><FONT color=#0000ff>#include <STDIO.H>' t0 o: i6 y" B) Y1 T: W% q0 G
#include <STRING.H></FONT></P>
6 D5 n* p6 E% o<P><FONT color=#0000ff>int main(void) 1 y9 N' ~  a4 }- C
{
  |# K. {( A/ ^) Lchar *str1 = "Borland International", *str2 = "nation", *ptr; </FONT></P>
; l3 _+ E' _  W$ i6 r7 t6 _1 E<P><FONT color=#0000ff>ptr = strstr(str1, str2);
# m" n0 t, i! N& Dprintf("The substring is: %s\n", ptr);
* ?* q4 k5 I' E# O5 C6 D7 N- V( C8 ]return 0;
! v6 ^2 F# u& |} </FONT>
0 v/ U+ W% U  @5 B4 g
; O% l. H. Z. p4 x! k( w</P>, W* i: s. \# V. {  p  Q, ]  p
<P><FONT color=#ff0000>函数名: strtod </FONT>  L  @7 S6 g' ?  o2 m( s
功 能: 将字符串转换为double型值
4 @' k# x# V3 \1 V) e用 法: double strtod(char *str, char **endptr);
9 D' }0 y* ?7 i  a9 _) i; i: W; v$ M程序例: </P>! k. M2 \8 [: }1 q
<P><FONT color=#0000ff>#include <STDIO.H>
( E9 {( a8 `+ w# a: U- P9 i2 \#include <STDLIB.H></FONT></P>6 F, F/ k" r) X$ }8 k
<P><FONT color=#0000ff>int main(void)
+ g( S0 U$ V. \5 f9 i{
, U: ~$ W' R6 Lchar input[80], *endptr;
5 C* j' B5 h3 Ddouble value; </FONT></P>. B% `( q5 Q* c6 n5 B. f7 d8 X, l
<P><FONT color=#0000ff>printf("Enter a floating point number:"); 5 d: _& i, |) L8 w
gets(input); 4 y" W" |: P0 f( c
value = strtod(input, &amp;endptr);
+ g' T+ y, U: R7 ~printf("The string is %s the number is %lf\n", input, value); & O" E6 M4 s2 \9 g* _6 f+ Z* n
return 0; - p5 b8 X7 m3 W; o! r
} : z1 J; g3 ]1 J8 }( r* ~
</FONT>
2 [, Z! e% E9 R: l1 H  R
5 N8 E' z$ @( C' U</P>
  a5 s7 \4 z- f) G<P><FONT color=#ff0000>函数名: strtok </FONT>+ H( t0 l5 g" o" }3 D
功 能: 查找由在第二个串中指定的分界符分隔开的单词 ( P5 ~# W# f  ^/ N5 U
用 法: char *strtok(char *str1, char *str2); 4 Z0 i( A4 g: Q, N) i
程序例: </P>
' Z8 b, e# }6 H) e; a7 p5 ]<P><FONT color=#0000ff>#include <STRING.H>
2 U, d$ L5 Q$ o- I#include <STDIO.H></FONT></P>
# K/ ]4 e( X4 F3 z  P<P><FONT color=#0000ff>int main(void)
. y' W* n# `3 C# ]$ z{ $ x4 Y6 C9 B3 P# F- [$ G
char input[16] = "abc,d";
4 S4 l, ?% g$ t8 z3 H3 R) Tchar *p; </FONT></P>
8 i  y) g5 F. g<P><FONT color=#0000ff>/* strtok places a NULL terminator
5 u3 f  X9 @. k  gin front of the token, if found */
; w! o- }4 x  |7 rp = strtok(input, ",");
# v2 A& F8 S$ L! xif (p) printf("%s\n", p); </FONT></P>
1 N& N4 j7 Y( d  Y" ^+ ]<P><FONT color=#0000ff>/* A second call to strtok using a NULL
- }+ }8 v" O. \3 ^  }4 Vas the first parameter returns a pointer
1 h$ f1 @1 b( j, ~# i% J9 {to the character following the token */
# q/ N, z$ q( L0 Sp = strtok(NULL, ",");
% W: |% A, `0 p- W$ Tif (p) printf("%s\n", p); % \  _5 T6 U4 s* \: Q- Y) m, d
return 0;
- B" }! c1 F+ N1 V: b}
/ N! O3 m- H) f( ]* q. j& D0 g1 t# o& y
* V9 o5 r: `" W. ]; D  ^) D# B
</FONT></P>- T  v$ ]* G9 n8 _' n, S
<P><FONT color=#ff0000>函数名: strtol </FONT>, j' v) f) z  s
功 能: 将串转换为长整数
1 m5 L" |4 w  x! L用 法: long strtol(char *str, char **endptr, int base);
( C1 q& a. a& q# x$ M( N程序例: </P>
7 W* Y# i  b& ]" z" K<P><FONT color=#0000ff>#include <STDLIB.H>5 Y7 S/ m' C& [: }& _; c' ]5 U
#include <STDIO.H></FONT></P>% ?' J( \6 V0 R4 c5 h8 x
<P><FONT color=#0000ff>int main(void) % g8 F% K4 n2 f! u7 @0 d
{
/ E% Y# L  C% ?0 Y" C% t. h; O# }char *string = "87654321", *endptr; ( l. [) W' H/ j  @8 o
long lnumber; </FONT></P>
/ o% d. H+ u5 l7 q<P><FONT color=#0000ff>/* strtol converts string to long integer */ - X: B: M% g, C
lnumber = strtol(string, &amp;endptr, 10);
- f9 `# E: k4 _/ K# x. Z1 qprintf("string = %s long = %ld\n", string, lnumber); </FONT></P>" i) M5 A1 O. h) Y; ^' L- q2 x
<P><FONT color=#0000ff>return 0; % g0 X# g- J( d) a3 B
} </FONT>; Z7 ^9 _2 l- a# x( y# [
</P>/ C1 m9 I. A% W% {) @1 {. R
<P><FONT color=#ff0000>函数名: strupr </FONT>
8 I0 J( a2 a( m$ D3 z" x功 能: 将串中的小写字母转换为大写字母 1 @5 c, l2 U5 t! z3 _
用 法: char *strupr(char *str);
+ D) F$ V: k4 B程序例: </P>
, s/ F3 K$ r$ Z$ \4 m3 ?2 `<P><FONT color=#0000ff>#include <STDIO.H>
( B" z5 S% p$ q3 g7 H- O. ^#include <STRING.H></FONT></P># S8 x# [1 v& f5 {/ N
<P><FONT color=#0000ff>int main(void) # q( H9 I: }* ]2 Z. E# m5 c
{ , D/ j! m% D6 T( @0 O7 B3 e  D; @, I
char *string = "abcdefghijklmnopqrstuvwxyz", *ptr; </FONT></P>+ ?8 q( p; U- P1 F3 `, t- O3 H* J& Y
<P><FONT color=#0000ff>/* converts string to upper case characters */
0 T. r% M0 x' A5 _ptr = strupr(string);
4 f+ p/ u2 E# o- T8 i! V, Fprintf("%s\n", ptr);
% l/ y( n. y# ^% K! n7 Mreturn 0; 5 e+ X. k% b' q3 l1 r% v# o! T- Z- B
}   ^" Z; M3 }3 K1 L% b$ b

# {$ g% ^" v( J5 a& L& {</FONT>
7 A$ F5 @7 D+ m! e# q</P>
- ^) S+ K  e5 H8 Q8 R; R<P><FONT color=#ff0000>函数名: swab </FONT>
# b0 G4 V1 y, H2 b3 x9 {7 N+ M功 能: 交换字节
( Z* M/ I8 r# q! c; x6 L, |3 T8 W3 W0 U用 法: void swab (char *from, char *to, int nbytes);
2 v0 ]2 b" V' ]4 t& V4 r& L程序例: </P>
) s, H; m6 H8 Q: p3 s8 B2 a, I<P><FONT color=#0000ff>#include <STDLIB.H>
/ T/ ^$ c4 }# ~# G! {; Q/ w5 T#include <STDIO.H>
+ N8 b& i8 ^) n7 N, e3 B9 }" s#include <STRING.H></FONT></P>0 r8 I. k* F" K& K, K- s+ G
<P><FONT color=#0000ff>char source[15] = "rFna koBlrna d";
: E/ d7 T# l4 y4 _char target[15]; </FONT></P>
$ e6 f. P# f, a& ~' i<P><FONT color=#0000ff>int main(void)
6 w- n; S! F) E/ t6 _{ 5 f8 N& \! |# R) q# r6 J
swab(source, target, strlen(source)); 5 l7 ?' s" e' t2 N8 ^6 q3 N
printf("This is target: %s\n", target); $ h, B# p; u# L: ~. I  L: K
return 0;
0 Y4 y1 R+ C- z& [}
9 y$ X2 h' P7 N# M* K, h% A</FONT>
' R) f1 d5 T- P+ u% g) {
) |5 R' A$ v! T  P! J2 K% p: c+ B</P>
+ M5 U4 C* o" m( A, c& x  R<P><FONT color=#ff0000>函数名: system </FONT>0 \/ l7 }* V, @4 x! o
功 能: 发出一个DOS命令
, k% h. \' V5 W用 法: int system(char *command); # m9 V, @7 D9 D) d; W# A- w' b
程序例: </P>
% |- k+ q3 W1 A2 e3 C2 O; L/ v<P><FONT color=#0000ff>#include <STDLIB.H>
( @0 X8 a/ J( e6 M8 r' j#include <STDIO.H></FONT></P>! b, a- @8 [$ `6 Y% E9 W
<P><FONT color=#0000ff>int main(void)
3 c( y. h4 r2 S9 S  L{ ' E' G" V' |+ {3 V' T
printf("About to spawn command.com and run a DOS command\n");
. F; j2 L4 O* S; n( N3 s8 p, c1 ~+ q9 ~system("dir");
/ [/ I! O' }3 [6 q# dreturn 0;
) d- ]/ b$ l! ^} </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-21 08:05 , Processed in 0.553940 second(s), 51 queries .

回顶部