数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:01
标题: 函数大全(e开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>
# `4 i3 P4 L/ w$ N. @, T( L% L) R; b</P>- x4 f- m* j  C1 N7 f

& c) m, u+ b/ k) Y
( P3 I& J" b4 j<><FONT color=#ff0000>函数名: ecvt </FONT>, E6 p$ x, w" S0 }& U4 u/ [
功 能: 把一个浮点数转换为字符串 $ n' w/ L1 G) m7 A# B
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
% P2 b* r& [1 Z9 K2 v程序例: </P>
  ^' [3 p/ y- N8 b<><FONT color=#0000ff>#include <STDLIB.H>6 ~+ J: b- H0 ?% T1 v9 D7 C7 P
#include <STDIO.H>
) G7 k8 l: S8 a6 A# e& g3 v#include <CONIO.H></FONT></P>0 q* d0 S- u7 q, m% u: l& S5 v
<><FONT color=#0000ff>int main(void)
. q8 L1 p7 J: Q  U5 P2 E8 a{ 7 f. N2 @7 g. u# t- N
char *string; " U6 f; u& S. C1 @$ r
double value; 7 l2 \" }+ _3 k! @% z7 z. W3 D0 C
int dec, sign; $ E; z) n- x4 {# O0 r3 Y
int ndig = 10; </FONT></P>
; A, a2 H, d( P" Q. O<><FONT color=#0000ff>clrscr(); " Y6 }' d3 j5 m8 l* S* h. T4 p* ]
value = 9.876; 8 q- O( g9 i6 ^4 `8 r& \* i
string = ecvt(value, ndig, &amp;dec, &amp;sign); 4 c  z  g( E# p+ J6 Z
printf("string = %s dec = %d \
/ y: Q5 y. A: y9 k, t  V4 A, qsign = %d\n", string, dec, sign); </FONT></P>
. |! O+ c$ i2 c  J, P& `<><FONT color=#0000ff>value = -123.45; ( C$ G( Q9 w! r1 w
ndig= 15;
4 R' }" {. j( d: d: N% [$ Tstring = ecvt(value,ndig,&amp;dec,&amp;sign);
! `1 e" V5 v# I' x% _7 Zprintf("string = %s dec = %d sign = %d\n",
4 U. s, W# p9 @string, dec, sign);
9 j7 V7 N* T2 n, L1 x- S. W</FONT></P>
# f! W- }4 t/ v( U<><FONT color=#0000ff>value = 0.6789e5; /* scientific 2 P# ~; ?/ J0 y% \( @
notation */ 0 j) N" Q: [9 i/ W, ~
ndig = 5; 4 P# e5 w( l: Q) W% Z5 }1 J+ Q) `
string = ecvt(value,ndig,&amp;dec,&amp;sign); ) u" K8 i/ b3 P0 m' ^; {/ g1 e! q1 Q
printf("string = %s dec = %d\
; v  d9 d  b4 k7 wsign = %d\n", string, dec, sign); </FONT></P>: s- [4 O, I6 \* X
<><FONT color=#0000ff>return 0; ' o% f5 y& w% `  S4 {& m: y
} </FONT>
9 f- A% X8 b2 Z$ p  Q. H& a. v% ?' V( ~, Q
</P>
/ u5 }0 O3 e8 r1 ]; w# ?<><FONT color=#ff0000>函数名: ellipse </FONT>
5 j5 _+ w- C3 X7 B功 能: 画一椭圆 6 h& G' A, |+ r* m& s
用 法: void far ellipse(int x, int y, int stangle, int endangle, & e2 \! g; U* z% N+ ^
int xradius, int yradius);
% y3 X: \. D/ \2 u6 `' ?7 m程序例: </P>' Z( Y: e& A9 m1 `  n' }" |
<><FONT color=#0000ff>#include <GRAPHICS.H>
- i: k$ p) y  E. D' h#include <STDLIB.H>
- T3 U6 G% v* Y% s3 x4 {8 O9 E8 g#include <STDIO.H>5 \! d$ C9 Q3 O8 x6 ?
#include <CONIO.H></FONT></P>
7 D* w- V% [: ]& f: m  r# Q( `<><FONT color=#0000ff>int main(void)
- ?2 h% q7 g- Z6 q5 J! X{ / N4 K$ R! d2 X4 O
/* request auto detection */ $ ?$ x6 Y* K; c$ Y3 m
int gdriver = DETECT, gmode, errorcode;
; r6 }: `4 ]4 t2 C. J3 @, L: E1 l. nint midx, midy; * B9 o1 \. r% Z
int stangle = 0, endangle = 360;
$ S7 t, H4 B! \& F- |, ?7 qint xradius = 100, yradius = 50; </FONT></P># R6 K- u0 e7 d5 f& e- h
<><FONT color=#0000ff>/* initialize graphics, local variables */
9 _; G9 ~( S9 m9 @' |$ winitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 x5 i/ f3 W6 O* ^9 z1 S2 c
<><FONT color=#0000ff>/* read result of initialization */
% g3 S2 d- h1 C# G% K+ X, ?errorcode = graphresult();
' \. j( O" S. N% _" L& [if (errorcode != grOk)
" z7 Y. Z5 z. \, ]- A+ m2 ~7 _/* an error occurred */
% n* ?+ ?+ _4 H{
- _  I3 t6 h; m( F* E& H  T: y8 Nprintf("Graphics error: %s\n", / n/ T) p, C& ^  x
grapherrormsg(errorcode));
+ F3 }4 ]3 ~# u+ w- E! U& A) Nprintf("ress any key to halt:");
* S4 _# M) B! m( ]getch(); " K3 }' J1 I2 m( A  Y
exit(1); 6 J& L" @: w& l& W; o0 ?1 D, ~4 e
/* terminate with an error code */ 1 X. E0 J: K6 i: F
} </FONT></P>
. {* W$ o1 Q) d5 A4 Q# S<><FONT color=#0000ff>midx = getmaxx() / 2; 4 q& a7 Y; U( Z9 b* W! S7 L" A
midy = getmaxy() / 2; " p. B" B5 h: I# ?' P5 R* B
setcolor(getmaxcolor()); </FONT></P>
% E) q+ T5 V' |9 [1 m<><FONT color=#0000ff>/* draw ellipse */ " C1 `4 l% y" L
ellipse(midx, midy, stangle, endangle, 1 O- k+ I3 e+ o
xradius, yradius); </FONT></P>
7 f# u% V; A/ m6 S  g# p# I5 F- x<><FONT color=#0000ff>/* clean up */ $ J" c6 K" c) n+ y6 n3 V- R  T! @! z# O
getch();
2 V" ^: `6 X" c& X+ @, k* Mclosegraph();   g3 z* z+ K$ h
return 0; ( ^5 d% F( J' t% F4 y/ p1 ^( f+ G
} </FONT>
5 L7 P% `& x% A" n3 ]7 w# y" M% G9 h. x( l
</P>
+ @  E* k9 N* H<><FONT color=#ff0000>函数名: enable </FONT>/ _) z8 c5 G* j& j5 S, G  d. ~1 e
功 能: 开放硬件中断 # z- S% c( k0 F* Z$ Y) W
用 法: void enable(void);
# `  ^5 t& c) e: Q程序例: </P>  F* Z# ~! J, l) ]5 Y+ J; M
<><FONT color=#0000ff>/* ** NOTE:   M  }. N6 g2 V
This is an interrupt service routine. You can NOT compile this program 4 Q. v9 A* j) I( h. T) p
with Test Stack Overflow turned on and get an executable file which will * e( j& m/ d/ h% V! N1 d& r  y* ~" D  h
operate correctly. 7 `+ r  i- o1 {: ]- z
*/ </FONT></P>
% X7 p) o4 U; \* _: Q* J9 @: x<><FONT color=#0000ff>#include <STDIO.H>
  m! J( c* H. O; T  o#include <DOS.H>
! a7 ]& s2 ^$ R#include <CONIO.H></FONT></P>
& Y- N7 @6 _3 l2 c<><FONT color=#0000ff>/* The clock tick interrupt */ 1 [8 T1 `# N: H, h" M; h4 B# ^
#define INTR 0X1C </FONT></P>. b# u" y- G. N- e! Q( I/ E' x0 u2 C1 h
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
4 j$ l, ]) O4 m9 A" u6 Y( w<><FONT color=#0000ff>int count=0; </FONT></P>7 \9 J* V5 a* R' P9 b$ e6 O. p; M
<><FONT color=#0000ff>void interrupt handler(void) 4 m) L3 U) T. @9 b/ e) v+ H
{ 3 A9 ]. k$ ]8 {8 A1 t
/* $ T7 r  n. G+ {6 [9 Y
disable interrupts during the handling of the interrupt : u1 F7 G! @$ s; w. y0 l
*/
# g5 X/ M; S9 o$ l4 kdisable(); ) b% D' K1 {1 J. A2 B: ?
/* increase the global counter */
3 {2 ?' G. A" h2 u+ icount++;
; x& s1 j+ E' v" x5 g+ c% F/*
# ]/ R2 x( ^0 H0 a. fre enable interrupts at the end of the handler 5 _6 s# b% K: ?$ h+ L/ V
*/   g: M3 m& x! t; ?
enable();
8 U4 T: Z$ Q; K1 R' n6 K$ s- I( x/* call the old routine */
% E' F9 n/ B1 Y& ~oldhandler();
3 ~- I0 ]3 x" O+ n5 N7 D& r+ a0 `} </FONT></P>3 H9 j9 Q/ Y9 Q  m7 o0 d2 D  x- h/ l
<><FONT color=#0000ff>int main(void) / C5 u/ @, G+ e
{
+ R) U% [; E$ ~/ V6 c/ I( }/* save the old interrupt vector */ ' Z7 S- y! w* j7 f
oldhandler = getvect(INTR); </FONT></P>; T7 a  l4 U( O2 n4 n" O( t
<><FONT color=#0000ff>/* install the new interrupt handler */
, K0 d4 M3 a' |/ A9 c: ^setvect(INTR, handler); </FONT></P>
' m9 {- w+ I! _2 c8 F<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
- w' ?6 Q6 D: q1 `: V9 u: I7 pwhile (count &lt; 20)
, ?' c- Z1 _5 I* p3 Y+ Q0 Aprintf("count is %d\n",count); </FONT></P>$ Q8 w( d7 S. a) b4 }+ {
<><FONT color=#0000ff>/* reset the old interrupt handler */
* Z( o& y# \6 F; ?9 ^setvect(INTR, oldhandler); </FONT></P>! g, p% r0 f8 F. F$ O
<><FONT color=#0000ff>return 0;
$ h/ f  C6 t" p* d6 f% ~} </FONT>$ h5 ~) V8 y9 q: j  n- d% a
" }8 @3 \/ f( L* ^) y% W
</P>. w$ d/ e. f& Y
<><FONT color=#ff0000>函数名: eof </FONT>
8 I: ^/ M9 C" b/ N5 Y# G功 能: 检测文件结束 . V- k3 o/ B8 }3 Z
用 法: int eof(int *handle); + b0 U9 e; S" H! I. d
程序例: </P>( y3 S# M$ R  e' `# @! C# b
<P><FONT color=#0000ff>#include <SYS\STAT.H>: \2 r8 y4 O; v; d9 `
#include <STRING.H>
  @5 n% m* {2 @( a#include <STDIO.H>
: n2 D8 D$ X, V, \9 i/ h: l5 F  R#include <FCNTL.H>1 N' u/ L0 W; g8 u9 N
#include <IO.H></FONT></P>
$ V% m% K+ e7 S# E. g4 U<P><FONT color=#0000ff>int main(void) / k6 T! Q/ B$ T
{   X. i; H; v8 R! c8 a
int handle; - D) S: U. Z2 B7 Y; E* k
char msg[] = "This is a test"; + B1 s5 C( _6 Z2 R
char ch; </FONT></P>
# C5 i* u3 |9 U* f* C. k<P><FONT color=#0000ff>/* create a file */ % g6 ]" d% H5 S! _2 U% F
handle = open("DUMMY.FIL", 3 J) ?$ i( a$ n
O_CREAT | O_RDWR,
; A( H7 f) L7 R: Q1 a9 lS_IREAD | S_IWRITE); </FONT></P>6 l1 z1 L# z: H  ?% `
<P><FONT color=#0000ff>/* write some data to the file */
% l7 v# c) h$ P: Q; nwrite(handle, msg, strlen(msg)); </FONT></P>* d8 p0 [* U4 w. x$ y$ c
<P><FONT color=#0000ff>/* seek to the beginning of the file */
& O8 W9 i; P$ d5 ^! o( dlseek(handle, 0L, SEEK_SET); </FONT></P>
4 o" W+ |* K1 Z# N& m<P><FONT color=#0000ff>/* # Z0 P+ U8 Y; A3 _& ^
reads chars from the file until hit EOF
' A8 ^& O& K& P6 {*/ ' J% J7 w) x; C( v; \. k$ L
do 3 ^% f: g! D8 s( Z! u, Q$ {
{
' U- s- L/ Q8 O0 l' Y4 Uread(handle, &amp;ch, 1); 2 v3 G5 k2 h. i1 Q+ x
printf("%c", ch); 0 o- C* W- K+ ]! m
} while (!eof(handle)); </FONT></P>5 i; B7 L# D/ m2 L2 B% \( e
<P><FONT color=#0000ff>close(handle);
- D, ]* O! _- ?' f+ G+ ^return 0; 5 u: s* ]6 W. @
} : T. F- f' ^! c. i
</FONT>1 F; J4 [. s4 v9 E
</P>
- u- W( W% g# k4 j# k/ f<P><FONT color=#ff0000>函数名: exec... </FONT>, L& X# t  [: h. M1 _0 Y) E4 h8 j( k
功 能: 装入并运行其它程序的函数
# v1 V1 |$ R* ]* o& n2 @* u用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); ; o" E& b  J5 S0 [2 m' C
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
7 [) x0 v2 q. p( E1 {char *envp[]);
! e6 ?- I! u9 ^3 R0 t9 ^int execlp(char *pathname, char *arg0, arg1, .., NULL);
$ r; [6 \$ }  A& V1 s( g' iint execple(char *pathname, char *arg0, arg1, ..., NULL,
9 x" D& x7 V4 f0 Vchar *envp[]); : u7 V3 H; W0 G. r2 z  h1 X
int execv(char *pathname, char *argv[]);
. H( E5 h$ V4 H) n! Y9 Lint execve(char *pathname, char *argv[], char *envp[]);
% z' D8 t: r+ Q& I0 }6 Yint execvp(char *pathname, char *argv[]); - U( I4 o9 ?' N3 J6 B6 O8 }7 K9 v
int execvpe(char *pathname, char *argv[], char *envp[]); % m4 x2 b6 _/ S2 |' J4 c
程序例: </P>. K" _/ d+ R. c8 o9 t# l; n
<P><FONT color=#0000ff>/* execv example */
7 s( b! {2 ?2 d; {! P#include <PROCESS.H>
! _  `7 P  @( ^#include <STDIO.H>, Z6 K% I( w. {* _. [: X' t
#include <ERRNO.H></FONT></P>7 n2 r5 b- n1 j: R# H, _
<P><FONT color=#0000ff>void main(int argc, char *argv[]) 1 h# B7 N1 q2 |5 o8 k! w
{ , W3 ?0 b0 e# t$ k7 ]9 E1 n
int i; </FONT></P>
3 H; p% E3 G* t<P><FONT color=#0000ff>printf("Command line arguments:\n"); 1 a0 X+ E1 y+ _+ H1 G( C
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
& r1 {+ `; \6 ?4 g6 F" P<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
9 y  _! X) t% |6 s6 Mexecv("CHILD.EXE", argv); </FONT></P>5 ?4 ^4 K5 t  r/ u' K
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
/ z$ N- f& [# ^( X9 ]<P><FONT color=#0000ff>exit(1);
- @' A1 N: K1 o. v3 [" R( R& ?}
  f' b: ?: B# ~( U/ h3 z</FONT>& F3 L( [4 }+ C4 d) ^, P0 B. W( H
</P>* n2 T# ]" D; {0 T6 @
<P><FONT color=#ff0000>函数名: exit </FONT>
7 a+ c+ B9 o5 D* ~! W) o功 能: 终止程序 9 b- a- u& D1 j2 o) m7 ?1 H
用 法: void exit(int status);
; S9 c' X+ m7 ~+ U0 r6 G- I" x5 Z+ C9 Z程序例: </P>. t+ J+ f4 A+ h' O3 A% {& n  H
<P><FONT color=#0000ff>#include <STDLIB.H>/ W8 g' B+ i* N4 j' X% F+ W$ C
#include <CONIO.H>1 U! f$ O. r& f: A. B8 u
#include <STDIO.H></FONT></P>' \' W- I# L. [
<P><FONT color=#0000ff>int main(void) # Y3 |  U% [! h" r  c1 q/ T4 g
{
6 |3 c6 j5 h9 a7 T; r! b( zint status; </FONT></P>
2 ?$ f7 o& X. V<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); 7 u" |5 d) S+ X5 R% u; D# r
status = getch(); & ?0 e% a% N) H1 S5 I
/* Sets DOS errorlevel */ - E7 z3 Y" V- E2 P1 s
exit(status - '0'); </FONT></P>
9 G4 t8 V0 i/ E" I- e. |! {<P><FONT color=#0000ff>/* Note: this line is never reached */ 2 \) J' y7 H+ O2 ^) U  |7 X/ V
return 0; ' l( K, I! Y/ w0 ?$ ?1 ?+ L
} , m. j' v1 D/ @% P3 W
</FONT>- p/ g. i* p) P) v3 I9 A
</P>
6 y1 a# f' ?% Y/ W6 g: K/ U<P><FONT color=#ff0000>函数名: exp </FONT>" u' `- X6 r+ K$ o  D, m
功 能: 指数函数 / m3 a2 g# L6 O* A. R9 ]$ k
用 法: double exp(double x); + O( \" w* W+ u; x
程序例: </P>
: _" ?2 c& j+ Q+ N9 J' h<P><FONT color=#0000ff>#include <STDIO.H>& s; T+ I8 c/ a
#include <MATH.H></FONT></P>% x+ u- D$ d) ?
<P><FONT color=#0000ff>int main(void) / I& d8 U7 o7 |0 U
{ * j+ O- Z* t! ^0 L3 m5 D3 N; O' J
double result; ! K/ ]2 @. C; I/ ~7 [" {) e
double x = 4.0; </FONT></P>
) X+ r( W1 h  A' O<P><FONT color=#0000ff>result = exp(x);
* l( _, S" ?& ]+ R6 y  Qprintf("'e' raised to the power \ 6 s' e8 f$ |: }; |8 k
of %lf (e ^ %lf) = %lf\n",
- l' r2 i4 i4 T* w9 q( u1 \' Bx, x, result); </FONT></P>4 Y# z  _4 b: k9 F6 t
<P><FONT color=#0000ff>return 0;
) ?6 x# y/ @2 F. g$ ^2 k& f( c}
% r5 G1 S- i* b2 }! Z& b# m</FONT></P>
作者: 韩冰    时间: 2004-10-4 03:02
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>+ ~  d# |0 I4 H% B. Q5 Q; _
</P>" b2 H4 q: z; s+ M$ a8 D
<p><><FONT color=#ff0000>函数名: delay </FONT>
. Y' U# T6 E  X0 Y! g功 能: 将程序的执行暂停一段时间(毫秒) & V0 w* B. Y. K/ M( _8 n
用 法: void delay(unsigned milliseconds);
& B' ?0 G: |9 ^' |! e1 ]程序例: 0 w( G9 D' `  }! ?
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
, r. Z  m" y+ n" G. ^/ F$ [#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) 6 ^9 O6 Z# V4 U5 S- y: G
{
* X9 o! [- w/ b; K  gsound(440); . k8 ~3 @  K; q) Y" }, S
delay(500); * R' A. C- y1 I! c
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
: t( i9 o  X+ L6 n5 U2 L} 5 B, P* \' Y" v( i
+ e' z, D7 t7 m. f( d; j
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>& J  K6 j% Q: I
功 能: 在文本窗口中删去一行
1 Q1 N$ R/ Y7 Y( X- u用 法: void delline(void); # _0 B- O* K# f& E, r: q) K
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) ) M& m, o8 [& ?2 d8 H
{
/ y: x# n' t# W4 N+ u* ]7 Dclrscr(); 1 \3 J& A0 n0 D
cprintf("The function DELLINE deletes \ 8 E: k3 _" }. f1 P: `3 v! l3 V4 r; T
the line containing the\r\n"); . o  }, b: F8 ~, \. o
cprintf("cursor and moves all lines \ ; c% _; J! M, R  `' _8 x
below it one line up.\r\n");
5 p8 f, u% Z& q. Q' ?1 [cprintf("DELLINE operates within the \ ) V: @, N& N  E
currently active text\r\n"); & g4 C' b) y" B% Y6 g
cprintf("window. Press any key to \ 5 g# Z0 t; b. }0 a9 v# S
continue . . .");
* l: Q2 O* ?6 h; Jgotoxy(1,2); /* Move the cursor to the
  x/ Y( F" x5 P6 S+ g2 f3 Gsecond line and first column */
9 q) m; m& p/ r! H6 S: j6 Xgetch(); </FONT></P><><FONT color=#0000ff>delline(); , p9 v( s6 w9 |' e, h
getch(); </FONT></P><><FONT color=#0000ff>return 0;
: x0 }0 k. |8 C8 U% k' y) W- I} </FONT>% q/ H" Q. ~* z& K  a* ^& \
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>& Z2 P7 L" {  h' L) j$ t! X
功 能: 通过检测硬件确定图形驱动程序和模式 + c1 a# N" }& @7 I- C  L* z) L6 s. t
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
# n) p3 Q; n, b  h: r9 Y4 ~# b程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>1 @$ x5 x& F) N. x
#include <STDLIB.H>
# V2 ?1 w' z, S/ t2 q#include <STDIO.H>% `& Y0 o+ w9 L# g3 o6 ?: l
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ 5 e: U9 B' ~& F2 k3 P( V
char *dname[] = { "requests detection", 9 c# Q* f! I8 p: U* |
"a CGA",
1 F, ~( z3 g' F( c"an MCGA",
" A2 \. W! L! R, r. H+ ^"an EGA",
6 g/ }8 C4 `0 q4 w5 u- Y* P"a 64K EGA",
7 _. b7 o/ B% k5 F& l"a monochrome EGA", + u# C7 L4 c% j* R7 {1 Y* |
"an IBM 8514",
1 u0 L$ I) G8 v6 |& ?2 g& ?5 n+ v"a Hercules monochrome",
2 E& J# I" z+ G$ e4 j) R6 y+ }: v"an AT&amp;T 6300 PC",
9 v2 q! u, x1 g6 O& ^"a VGA",
* [/ b  I$ Y9 o* H$ N5 q7 t"an IBM 3270 PC" ! V! ]* B9 x* P0 i
}; </FONT></P><><FONT color=#0000ff>int main(void)
  C  @) _& t( M; l7 _, f2 r. B{
6 h6 k- S4 b0 B- c  ?/* returns detected hardware info. */ 0 t) _. B3 t+ P8 P* O9 [
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
$ F! u- @9 S: ^0 ndetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ 6 y# f) W6 @4 E: U+ v# g
errorcode = graphresult();
4 x( v: g/ {9 W3 f' X9 |if (errorcode != grOk) /* an error 9 B( }7 s! a6 V1 V: \, P, H( u: U
occurred */ . x; [8 Y6 Q) t. k: n8 i! x& ?
{
5 s4 a! f5 ?7 {* Uprintf("Graphics error: %s\n", \ " \' i) _0 A* e
grapherrormsg(errorcode));
% M# v3 I. n" I! P/ Aprintf("ress any key to halt:");
) F7 V  r, J/ }3 Lgetch(); * y9 ?2 G/ p& Y' R) U; J% b1 S
exit(1); /* terminate with an error
9 c  \5 t8 q4 {% F1 icode */ " P' d/ W& W$ R9 g+ F) `
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
3 \) _( A8 a3 l0 I  D; j- ~clrscr();
- b# C1 ?: K! }; pprintf("You have %s video display \ 2 O; W9 z# e1 ~% r
card.\n", dname[gdriver]); 5 h2 E! t( D) D' K
printf("ress any key to halt:"); 0 B! r; c( e, c2 c3 M4 Y6 v
getch(); 0 O2 ^5 \( z0 O
return 0;
8 t4 ], g  C3 G; S} </FONT>
$ r8 @# f0 ^5 v1 t+ f! V4 `/ v( x7 `; c0 x) @" f

; f( C1 s) N& R0 C6 M/ C</P><><FONT color=#ff0000>函数名: difftime </FONT>" \& g3 l& }" ]  u0 A7 ]
功 能: 计算两个时刻之间的时间差
: K! T& }4 k2 [2 Q8 ^' {: t用 法: double difftime(time_t time2, time_t time1);
- {' l0 d& s  B程序例: </P><><FONT color=#0000ff>#include <TIME.H>
# H7 j3 P* `# Z. c2 a2 u# V' X4 f#include <STDIO.H>
- O) @8 k- q, L3 J2 Z#include <DOS.H>
5 |# U  |0 n5 R1 Z/ y, w! Q#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) 6 f" o4 W4 i/ D
{ - z, v& N& s- b# U, Y+ A) ]
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); ' e6 n, I" j$ X, D4 Z4 M) H4 @4 W
first = time(NULL); /* Gets system
+ l7 E; U' G6 \  atime */ 4 d) ~' @+ l2 \% {0 X
delay(2000); /* Waits 2 secs */
  q) Q; B7 z- C5 |second = time(NULL); /* Gets system time ! w# w2 L+ ^( j8 Z; _
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ $ O, c: j7 H( x
seconds\n",difftime(second,first));
4 e; N- [/ I/ m; w! }5 B( A- ^getch(); </FONT></P><><FONT color=#0000ff>return 0;   S. Z; _) }' f1 I/ ]" i) R: x
} ( x& Y/ M0 a5 D: r! y4 A; r  Y
</FONT>! O8 f  b  F: W' Y4 i4 U2 ]
</P><><FONT color=#ff0000>函数名: disable </FONT>
8 p, }7 Z7 E- W7 t, `( W功 能: 屏蔽中断 ) d9 Y0 t$ Y$ W+ F
用 法: void disable(void); / ~9 [/ Q0 ]. U# S
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
- g, ~$ X# s) W2 A# T" L# Z+ ~routine. You cannot compile this program
& Y) y( z4 c% r- p6 Jwith Test Stack Overflow turned on and 4 c4 `7 x: o+ i8 b2 b
get an executable file that operates
3 D) v/ M2 B  d5 Y8 d6 Xcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
9 s6 {: O6 k4 G4 I1 g4 P+ `% w# P#include <DOS.H>
5 ]0 i& H# J) |/ x#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick 1 [4 W4 H7 b+ f: t5 e
interrupt */ </FONT></P><><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P><><FONT color=#0000ff>int count=0; </FONT></P><P><FONT color=#0000ff>void interrupt handler(void)
: R6 O# C# A* S, ^6 l+ o{
( R1 |( n% V4 |  b/* disable interrupts during the handling of / ^" U- p4 m; ?5 W( B8 P% E' [
the interrupt */
- e8 Z/ ^7 C& o# U6 udisable(); 8 J  w9 E2 n' g# h; N3 q( W
/* increase the global counter */ ! w& U- Z7 @) d' T. O# J9 `2 f7 I
count++; 3 g0 y+ e$ L0 {1 R( v
/* reenable interrupts at the end of the ! M1 x0 ?) x, }7 y/ r
handler */ / \% i0 S2 n& V5 k/ G! p1 i# e
enable();
3 w! _+ i/ Z8 S7 l( d8 j+ D2 A/* call the old routine */ ' [$ g7 c6 o$ ^  C2 r  {6 v
oldhandler(); * Y! q) f- V) R
} </FONT></P><P><FONT color=#0000ff>int main(void)
/ V0 i9 {" Y2 l! M& @- Q{
( [0 o: S9 k4 T, _' ^" {2 ~' m/* save the old interrupt vector */
/ j7 J* a# g( _* m5 h" Ioldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
# k8 T' c9 E* X0 [setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ & Y' n- F. P6 j. D) n" _4 K/ p, m7 h
while (count &lt; 20)
$ Q! Z8 ^4 M& qprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
* w. s; @7 G) csetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
0 t  b7 I0 A" X} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>" x( ^; b. t1 }* `
功 能: 将两个整数相除, 返回商和余数
5 K+ N+ S7 T) x1 q- \* Q4 E用 法: div_t (int number, int denom); ) r- u, i. h0 b7 X7 T7 q
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
& r2 x4 ?; Q, S#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
# j( ^$ I1 V4 d7 J, t( y{ " U" Y, j' _+ R! b+ b! g
x = div(10,3);
% D9 S3 ~0 O/ V1 \' O6 v$ `' [printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
1 b/ I3 Y& w2 X2 W( w  H1 ]} % q$ g$ o& p2 p3 Z$ C
</FONT>
2 F1 A& F0 ?3 m" j1 s</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
8 Y2 ^$ ?4 [# @5 k7 C) b# s2 Q功 能: 获取扩展DOS错误信息
6 H9 c4 y$ O1 M+ O% |用 法: int dosexterr(struct DOSERR *dblkp);
$ U- ]7 @3 }; y- N2 \程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>6 x8 z2 F- H6 m; x; r: O8 r+ C
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) ; f6 ]0 E' f% d( m7 z: i& R5 G
{
: d- f8 ^4 _2 t4 f, JFILE *fp;
, V. @+ E) C" j" Dstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); ) G$ D. {; ?. O' Q+ U
if (!fp) perror("Unable to open file for
/ i' ]; `! r6 E! j0 M  y' z8 kreading");
& f8 R2 T9 B3 r+ U9 y: gdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
! y8 H3 E& g( |* T7 [information:\n");
0 ], x! Q& A9 l* x  {" |printf(" Extended error: \
/ F3 @2 ]% x, d! |3 @) }. S. b, x%d\n",info.exterror); 8 u  p/ J. }% N- r
printf(" Class: \
4 l# {; t1 p* B9 m%x\n",info.class);
( _8 Y. O  N) f; B1 Iprintf(" Action: \   H5 W+ W6 Q. o4 i
%x\n",info.action); 8 O1 p5 k/ H/ K2 j
printf(" Error Locus: \ : Z& q; i0 y9 A) s! O( K* c
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; 3 W2 w7 Y' S- [6 T( ^# }
} </FONT>
, H! g& L0 T& @( R( t+ E
0 r( }2 y7 u* T3 ]% r. m</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
9 y. J! E/ x% n; [功 能: 转换日期和时间为UNIX时间格式
( n( Z/ P7 J2 x; T) R& I用 法: long dostounix(struct date *dateptr, struct time *timeptr); " T, ?8 Z! O# g' }
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
+ P7 f# H- V& s$ j/ g#include <STDDEF.H>
% U& l0 ?) y" H5 G#include <DOS.H>
8 K- S( y* O) U9 f% |, X#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) " ]4 B% d) n8 k- g; p# q, x& j' b  x
{ 7 Q5 m/ {- v) j% |( @
time_t t;
, H0 F6 ]  ?" s* Hstruct time d_time;
* _+ B; z" i0 C1 v' R, P, D2 P+ estruct date d_date; 3 y  ^* V$ n# V2 {% ~2 H
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
8 p$ H- W7 a0 Q2 g5 _6 Ugettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); ' C3 W. x+ U" i& N5 S/ Q2 q
local = localtime(&amp;t);
0 v3 i4 `5 \" Kprintf("Time and Date: %s\n", \
$ C/ X$ @, T. c+ C/ G6 Fasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
# u" ?' \$ [$ k& K} </FONT>( z% B6 O) ]$ W5 N+ J3 |5 v
/ _; ]8 c4 X& ?, L
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
6 `( |0 C) r& A+ Q$ b# }功 能: 画多边形 , o5 o$ P7 C% d+ |7 m9 B" \
用 法: void far drawpoly(int numpoints, int far *polypoints); $ X0 H, A: ^1 W* }9 `& i0 i' p5 R, r
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>6 e4 ~8 a. L2 u
#include <STDLIB.H>, _8 }9 C) }/ d$ @4 B. w
#include <STDIO.H>
6 W; D6 g! S$ ^  V& w- R' ?#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) + J9 l% |$ l- J7 j
{ 4 V/ ]% W( y/ \2 A. x# R4 [- |
/* request auto detection */ # m7 p1 t' d0 @4 _4 E; ~
int gdriver = DETECT, gmode, errorcode;
9 i. Q& V. n$ A  M2 ?2 nint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ 6 T5 u% ?6 P. N( B5 l( M
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local 2 a5 _0 o! B1 J$ X2 E
variables */ # J( h! h- v' [2 i- R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ " ^) @7 }- ^- a- d; d6 Y- x! X
errorcode = graphresult();
- H4 J, b  ^. D5 \4 Zif (errorcode != grOk)
# ^* y- S% [6 E* m& o/* an error occurred */
9 a9 i+ V5 E; \1 _{
; k2 P3 P$ J5 {printf("Graphics error: %s\n", \ / Y+ p) \$ t. _: f' |; I# \$ d
grapherrormsg(errorcode)); 5 |7 K. v: J+ y  M7 R6 j
printf("Press any key to halt:"); 7 \* ]  H$ `' ]
getch();
! r* u5 B8 a( _3 E$ w/* terminate with an error code */ 9 d6 ^; V1 |* {6 }* e6 h
exit(1);
9 {) T" U% |2 n6 d- H! z, Y$ b. z} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
6 c+ ~, y& a0 R6 dmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ 5 M( z! F3 c, ~
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 6 b, v$ B' ~  o1 o0 d; C, ~- O
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ ) M5 O% p9 _2 Y2 @1 @
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
  Q- w  h4 T  C; Q- v; l- Fpoly[7] = maxy / 2; 3 U' |, P: p) ?* m+ g' k1 h
/* - m: F4 l" t* a# A( N9 ^
drawpoly doesn't automatically close
8 m8 ~0 G  P9 U, ?5 X1 ~1 Ithe polygon, so we close it.
9 K* S7 o) J! [2 z! d6 h*/
2 z1 r, Z9 m* E/ Q& x& T' ]poly[8] = poly[0];
* T- H( ^0 e: j' w! r$ A4 lpoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ 5 }' H, c' |+ G5 a" E( l
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */   }7 E5 S. {$ U& a$ Z6 c
getch();
( Z7 U) `5 d; u7 e- bclosegraph(); ' d! z. x2 L2 u
return 0; 3 h! w8 X9 q" i2 b6 y/ Y, }
}   |% I% z7 w# Q: Z! x: J+ ]
</FONT>* W* P4 N4 J# F" J' y, y
</P><P><FONT color=#ff0000>函数名: dup </FONT>
+ m. P- H- U  ^& w% j7 ?& }4 k功 能: 复制一个文件句柄 . H2 A; O, ^" A; ]
用 法: int dup(int handle); ! H8 t9 M6 }( ~& Z8 b
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>. |) R4 [5 @+ l+ V. A' a* W4 C7 J
#include <STDIO.H>
3 N( ?6 w! ^- }9 u0 D6 H#include <CONIO.H>
8 y7 ^+ p  N: `& m; X$ D, P" J#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
! O' `; D: x0 u: b9 Z8 \{ 2 j( l  l, l9 p; J' B% [9 N
FILE *fp;
3 U/ M  a% t! v# H) Ochar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
5 P; `9 q9 M* n4 @+ b* X* Wfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ / d& T( v0 [9 t; m5 @( @" b: P
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
6 v  U% \( C/ ^! i+ E( Vprintf("Press any key to flush \ ( n  P# H2 F& G4 K6 m5 R! R: S9 J
DUMMY.FIL:");
9 x, e  F: N4 a: Jgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
2 x( U0 D9 }7 bclosing it */ ' d* _( i+ }' o, X8 G4 E
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
- N# N5 q* E6 I( Lkey to quit:");
( v! F8 p' i9 a, F- Ygetch(); 3 ]( o2 y! u5 E' ^: K3 N
return 0;
5 S* p% i' e: A! u} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
( \  [) I5 B3 o{ : i" ?8 m2 ]+ z% k3 B$ `
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
- Z3 Q  D  u7 S  |/ ]. a( Kfflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ 3 ?, q/ q9 x1 B7 p. \
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 5 Y: H' I$ H4 H- P) Z( b- D
DOS buffer */
! p% P3 h, J) bclose(duphandle);
: z* a' {% J, [" u% ~8 E) i} 2 L3 r0 q& J) r
0 L6 g3 ?) ]5 J, s) V5 D
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
# h; d% ^$ p3 _, m/ V/ l$ q3 l功 能: 复制文件句柄 # D: C1 ?. w3 r) v1 R3 I; \7 i& V$ U
用 法: int dup2(int oldhandle, int newhandle);
( E1 b- @, Q. j5 X- w0 w4 @程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
) g: p) w3 K' F+ h#include <STRING.H>; A. L! s& B7 q% f( ~- s# ]
#include <FCNTL.H>
, S1 G) J+ M5 V4 V6 j/ }2 z3 B8 U#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) , r$ g5 t" S) G) q8 x0 j
{ : v* O+ w( M! x' [
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; 5 E/ G0 K# N7 v
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ % P  h$ j' C" S* }% ?2 p9 y
nul = open("DUMMY.FIL", O_CREAT | O_RDWR, ) {/ B. W% O% I* Y' Y
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
8 j0 |. i) ^3 g2 poutput */ ) _1 r; E- I* Z& Q- Y
oldstdout = dup(STDOUT);
  a& X! Z/ z) Z; X" M/*
% |# j. m8 g. J4 I0 g9 r+ aredirect standard output to DUMMY.FIL ( o0 y( M3 y3 {8 e  x
by duplicating the file handle onto the " e# P% ^( ?% J1 n" k/ [. f: R# c
file handle for standard output.
# F: D& w1 m3 Z2 ]*/
! N. p$ \# I  ]dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
. g0 T5 t7 D! Z+ {7 ]close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
' ~8 L& ^! X3 nwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
" C9 f& J; [0 C2 [  \5 Lhandle */ / c* B0 {) ^6 Q3 l
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
+ x& w' S, M" R+ O. P0 n+ `. Qclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 0 k% c4 O$ {$ x( S$ u0 ^
} 8 b5 V) Y  `9 |/ Y1 ^! {4 o
</FONT></P>




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