数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:01
标题: 函数大全(e开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>
" y2 h+ U, T  i7 ^, ?1 O</P>
- @% t* ^/ w  K' a1 b# l8 I' {( \. S" N: D5 ^+ F# ^  Q8 A

) h8 v( H% Y9 [& ^- g4 H0 L) u<><FONT color=#ff0000>函数名: ecvt </FONT>7 e. Z5 N% x' L8 v# v
功 能: 把一个浮点数转换为字符串 - a% X3 N( d: g/ B
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
9 C; |* {9 p# B: o. H5 l程序例: </P>9 K/ }1 T# U  v$ K" T; h
<><FONT color=#0000ff>#include <STDLIB.H>. s. y: I9 L6 p1 [( \# Z( P7 a8 Y8 z
#include <STDIO.H>5 w& L. Q; y% Y7 }+ n' p
#include <CONIO.H></FONT></P>
- w! w! C( \& z* p<><FONT color=#0000ff>int main(void)
" g% |$ p& r( E1 s; @. S{ * v: _3 D0 S! O5 |! h% r' A
char *string;
# ~( |, u0 \; f6 `: f% ydouble value;
; }8 q7 g; z4 I8 Y6 i9 U) @int dec, sign;
- @0 G# X0 ?( M' a8 iint ndig = 10; </FONT></P>
( A0 p# M* y/ z<><FONT color=#0000ff>clrscr();
: \* f0 W0 J) o$ Hvalue = 9.876;
/ ~3 S6 e* h( e  Estring = ecvt(value, ndig, &amp;dec, &amp;sign);
. i; ~3 R1 I+ w; L0 ?$ \printf("string = %s dec = %d \ + K; r; e' k3 B  z2 U
sign = %d\n", string, dec, sign); </FONT></P>
' h8 d: I; q' \5 L# j7 M  e<><FONT color=#0000ff>value = -123.45; " ]* @3 O2 E) S) S" ?/ X# R; v0 A
ndig= 15; 4 n1 ~. h% O- z( M
string = ecvt(value,ndig,&amp;dec,&amp;sign); & M8 W7 N/ O5 _8 F  A' `
printf("string = %s dec = %d sign = %d\n",
6 G' V) ]8 z# Lstring, dec, sign);
3 s" L. C: i4 m: r: z! ~</FONT></P>5 @' D* D5 n) b- @
<><FONT color=#0000ff>value = 0.6789e5; /* scientific 8 q" H% A3 K: g8 h: w$ ~
notation */ . G0 }9 s7 j: J3 I/ d" K" ^2 U
ndig = 5; % P$ |, d8 `9 ], R
string = ecvt(value,ndig,&amp;dec,&amp;sign); 0 N: H4 a& l/ t# E  T8 M
printf("string = %s dec = %d\ ' v# q- \, {1 y, I
sign = %d\n", string, dec, sign); </FONT></P>
- Z' N* M, S7 s<><FONT color=#0000ff>return 0;
3 Y3 _4 n% y. c} </FONT>
1 k+ ?, R5 ]) M9 `2 ]7 H( `: T4 @" ^6 U$ i
</P>
2 ~5 m0 c1 n& [3 \( Q2 X<><FONT color=#ff0000>函数名: ellipse </FONT>0 N, j% u+ F+ k
功 能: 画一椭圆 & _# _, P2 T+ b: s
用 法: void far ellipse(int x, int y, int stangle, int endangle, % _( ^2 }$ L8 ]5 ]
int xradius, int yradius); + J' k: z7 \9 t
程序例: </P>5 j* M, v( F: T: f. d& [
<><FONT color=#0000ff>#include <GRAPHICS.H>
! d5 v2 Y5 A& D) h2 N#include <STDLIB.H>; l$ `2 o. k# R2 ?! c2 y
#include <STDIO.H>
3 _& k! q8 P; i, q( T% @; a5 A  a3 _6 Q#include <CONIO.H></FONT></P>0 n& o5 G8 ~, N* `
<><FONT color=#0000ff>int main(void) ) F  D/ {) Z% @" Z2 M0 t! @) X1 j
{
! f  U% p' U5 m* o# K* L/* request auto detection */ 4 u4 u. ~; q# E$ U
int gdriver = DETECT, gmode, errorcode;
- }7 x$ A& i; z! b3 `9 Bint midx, midy;
9 n2 L2 n8 Y7 Tint stangle = 0, endangle = 360;
: z: r- }6 J" p, C  g- V1 Nint xradius = 100, yradius = 50; </FONT></P>" V4 p. I" j+ S2 k" {3 k5 B8 ^
<><FONT color=#0000ff>/* initialize graphics, local variables */ 1 x' b* c2 L0 \$ r9 g- R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>3 M0 [! i+ U$ d# W" V) u
<><FONT color=#0000ff>/* read result of initialization */ / [/ o, ]5 V1 Y/ @* c1 v
errorcode = graphresult();
' N, ~& k# B+ H# aif (errorcode != grOk)   q' m+ r+ j: I1 l4 N/ t
/* an error occurred */   e9 [0 ?4 ]4 j5 j
{
- f) o9 u4 T& T* z5 tprintf("Graphics error: %s\n",
5 f# r* q4 K& t3 \. qgrapherrormsg(errorcode));
0 [0 Z0 @% J! A. [% }printf("ress any key to halt:");
1 b( g- M! r5 Mgetch();
# M& f1 S: O9 uexit(1); / M9 [( y8 t% Y* H3 f: Y8 Q0 t
/* terminate with an error code */
2 A$ Z, p2 z- e} </FONT></P>3 P* J0 L8 e) |5 r4 m* V: c/ b) q
<><FONT color=#0000ff>midx = getmaxx() / 2;
7 [% N  j1 t" h5 xmidy = getmaxy() / 2;
; a1 u% ?3 @/ ]" R5 A; w1 H8 ~setcolor(getmaxcolor()); </FONT></P>. ?3 `7 j: m0 W
<><FONT color=#0000ff>/* draw ellipse */ 9 }" d. F2 J8 r2 q; j  V4 `4 S
ellipse(midx, midy, stangle, endangle,
2 J; _4 c( ]* k1 k* Z/ pxradius, yradius); </FONT></P>, @, P- H9 U3 Y, M2 d
<><FONT color=#0000ff>/* clean up */
! e; Z+ Z9 L! |! B  ~8 H$ }getch();
1 W/ V9 g3 Y4 _, ]( L/ _1 o7 Cclosegraph();   h1 r/ L, J& Y3 |! o) \& @3 g) C8 g$ P: v
return 0; " S; b. `' m4 S
} </FONT>
1 n. q! r" C: I1 n0 O' l4 K! c/ Y/ n; X; [" N9 @1 O6 h( W, I7 {
</P>/ R4 [" m5 K, l1 H% @' c9 t
<><FONT color=#ff0000>函数名: enable </FONT>/ t/ W' r9 O9 U
功 能: 开放硬件中断
9 k2 _: A- r7 e% Q5 B. L用 法: void enable(void); 6 }1 F$ a! h- Z
程序例: </P>8 V/ o6 d0 ?3 s/ I/ Y
<><FONT color=#0000ff>/* ** NOTE: # p, r. n4 w; c4 T/ @1 k5 }
This is an interrupt service routine. You can NOT compile this program
& _1 k( q: V$ i5 _3 Bwith Test Stack Overflow turned on and get an executable file which will 1 O: f8 _/ [( A; w6 N2 e/ G4 {+ N
operate correctly. / \" D4 r6 X6 M' C' J( x9 F
*/ </FONT></P>
1 L7 V; z- E2 f<><FONT color=#0000ff>#include <STDIO.H>
( c: |/ k+ i& L: `#include <DOS.H>
* }( a  Y% X1 G  k9 j( I& w) `* S#include <CONIO.H></FONT></P>8 _! `7 L3 ^) B! Y$ }: @
<><FONT color=#0000ff>/* The clock tick interrupt */ 6 n( _1 W: x; k, k
#define INTR 0X1C </FONT></P>
  r" D) O. B$ x% Q* i8 k9 Y; `+ \<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>2 |0 `) f7 M' V! N! Q
<><FONT color=#0000ff>int count=0; </FONT></P>) x% t5 g+ }# n& R
<><FONT color=#0000ff>void interrupt handler(void) " L. l: H+ r0 l; e1 J9 D
{ 6 C" m4 v1 m; |
/*
; w* e7 @! R3 l+ g8 ^4 i% `( s2 H4 ddisable interrupts during the handling of the interrupt
" w0 h: Q' k1 A; E& ]& I( Z) ]) D*/ # C* U* _+ C" x& S
disable();
# g, d9 C7 D8 K* g* }/* increase the global counter */ 5 [' D* k5 g3 A( [
count++;
7 i0 w5 b* {2 e1 W8 a4 B/*   t7 {& ~9 t# _" l" r% Z
re enable interrupts at the end of the handler
' {7 B: z- v4 X1 y9 P4 B" L4 L4 J*/   B6 x  ^5 I3 D) V
enable();
, f. f6 M, K4 D7 w: a/* call the old routine */
" L3 r/ {. k# q. s- Joldhandler();
. T) J& o' M; t3 Q+ }- \" a} </FONT></P>0 m- H; s. f6 ~9 @
<><FONT color=#0000ff>int main(void)
5 R. d+ y# c5 q# N{
4 A0 l0 l  Q/ t: w- R0 M/* save the old interrupt vector */
8 m. F9 y; Y. @* D$ A9 ^. @. Y7 `oldhandler = getvect(INTR); </FONT></P>
7 V5 v# D4 |/ `3 o) k5 G<><FONT color=#0000ff>/* install the new interrupt handler */
  ^0 Y- D- T! T+ j+ fsetvect(INTR, handler); </FONT></P>5 Z+ m$ ?' _6 h$ g
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
3 X. d* G/ D% r% y; M2 {3 I5 `while (count &lt; 20)
: _, O- x$ D4 S4 k8 p2 a# ^& uprintf("count is %d\n",count); </FONT></P>& u3 q) ?# y8 S2 B
<><FONT color=#0000ff>/* reset the old interrupt handler */ 9 j  X4 q* h8 V
setvect(INTR, oldhandler); </FONT></P>
7 d3 X( j6 }8 Y" X+ q<><FONT color=#0000ff>return 0;
$ ?: \2 G0 p; [& R- D0 h  ?% _} </FONT>
; C3 d7 W  A% F% N  ^- o4 ^& u+ W4 {. P# h2 v4 ^) h8 e1 K
</P>
4 x9 {  |9 Q: G) o' k" t6 b8 P<><FONT color=#ff0000>函数名: eof </FONT>- i: y& ^( ~" E) G1 K
功 能: 检测文件结束
6 Y) m# l' Y( D1 w! @! B/ _  a8 H用 法: int eof(int *handle); ! g7 F' \5 W% ?. n5 F
程序例: </P>
7 Q) P7 D* P0 W4 m: Y- N<P><FONT color=#0000ff>#include <SYS\STAT.H>' P  B# N/ _) z" {: s  W, @- k
#include <STRING.H>
$ {/ d6 h5 r4 Y3 K#include <STDIO.H>
' B. J7 E- i0 @  `" I( o#include <FCNTL.H>& I2 W  ]- T- j; r8 A8 @, v# @
#include <IO.H></FONT></P>, d  w$ C- R. ]9 A' H
<P><FONT color=#0000ff>int main(void)
! W) a: K% {3 h; b{
: h/ V+ c9 ^1 B4 w1 T6 O( {int handle; 7 z4 g5 _# W# L" [% y$ b
char msg[] = "This is a test"; # k2 M! i# ~& @2 c) `/ Q. f
char ch; </FONT></P>
; H1 o' z/ n4 ]3 C/ J' D8 O7 T<P><FONT color=#0000ff>/* create a file */
6 K& I& d% `! a6 d) W' `# Hhandle = open("DUMMY.FIL", ' Q' f9 Q0 G8 _: Y+ k
O_CREAT | O_RDWR,
; P/ F( Z! o' T2 Z) R( `S_IREAD | S_IWRITE); </FONT></P>5 h; M) B1 i, Z+ ?5 w. E
<P><FONT color=#0000ff>/* write some data to the file */ 5 i6 @7 K7 D3 Y+ ]6 \
write(handle, msg, strlen(msg)); </FONT></P>
3 d( S' i6 S0 Y# y; w/ d<P><FONT color=#0000ff>/* seek to the beginning of the file */ " B# a9 b: b; t6 A
lseek(handle, 0L, SEEK_SET); </FONT></P>
& J% w9 Q9 q& ~) B& a- Z<P><FONT color=#0000ff>/*
1 c0 ?9 J: M2 B: T0 e9 s& X% Vreads chars from the file until hit EOF
1 w& F# k" m7 ~*/ 8 A1 m5 F4 f" m" |$ X  D" X
do : i- m1 n/ K) |9 D( R
{
- s  T. F1 l7 @( Rread(handle, &amp;ch, 1);
8 O" q) O. o) [$ U$ ~0 gprintf("%c", ch); 8 x3 c  v4 N( K1 N! F5 g
} while (!eof(handle)); </FONT></P>. u3 v! [; m- B. V6 ^
<P><FONT color=#0000ff>close(handle);
) _  b- ~+ \) j/ n2 ~return 0; % }8 |! @$ L3 R/ k+ Z/ I# y5 i
}
! S1 Q  l* V/ t</FONT>
- Q8 U; h9 ?8 |0 l) ~4 D</P>9 D( U& f, t* m* Z2 U# n* o( x
<P><FONT color=#ff0000>函数名: exec... </FONT>
% T' `8 V" ~" @5 x- A功 能: 装入并运行其它程序的函数 9 j' J4 T( ?$ M& a% O8 ?
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
; ]9 `( E2 e% O, I$ T3 }' ]int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
5 i& R$ i0 a* n, T1 d! p" Dchar *envp[]); 7 b% H) n$ p0 ]2 [3 J
int execlp(char *pathname, char *arg0, arg1, .., NULL); / h( p: D9 i8 l' E3 H$ m# N
int execple(char *pathname, char *arg0, arg1, ..., NULL, / h1 [% p# f1 n+ q. Y
char *envp[]);
# D. q+ p* z# mint execv(char *pathname, char *argv[]);
, N& u1 ?+ W6 ~, wint execve(char *pathname, char *argv[], char *envp[]); : @3 Z6 ]. p# k+ v; e' _1 O
int execvp(char *pathname, char *argv[]); 1 f& h/ `6 S2 f. y! k
int execvpe(char *pathname, char *argv[], char *envp[]); 9 S! R2 q) W3 B- p/ E. u
程序例: </P>
! C. f" [+ w% V- i<P><FONT color=#0000ff>/* execv example */ 3 I. i$ |% ]5 N# @9 C: Y" P
#include <PROCESS.H>
1 f9 H% O- U$ \" o3 y9 j1 {5 j3 a#include <STDIO.H>' Y0 Y9 ~( t- O, e  w' ^; G
#include <ERRNO.H></FONT></P>
, @: J, O4 J6 [9 g  c<P><FONT color=#0000ff>void main(int argc, char *argv[]) # k1 Q$ h8 ?5 A2 a1 _; N
{ ( f$ _, i% w0 J  Y5 |. U
int i; </FONT></P>" [% n6 O0 D: Y! i5 R
<P><FONT color=#0000ff>printf("Command line arguments:\n");
) o7 m, u$ E1 e+ ~3 Sfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
* I$ N/ P7 m5 Q* Q% i<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); / q/ X! M& g4 ^$ E: L% f
execv("CHILD.EXE", argv); </FONT></P>
4 A/ c  S) g+ d. H8 r<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
$ c2 D9 H! p% T2 ~+ A<P><FONT color=#0000ff>exit(1);
( @5 s" H2 w. X% z, K9 @4 s8 H# ^# U} 5 t5 |6 J) M- w4 J( @
</FONT>4 M# H6 E+ L9 A6 A9 ?
</P>
8 R# Z* j5 O. r! L' N<P><FONT color=#ff0000>函数名: exit </FONT>
% K( @- F2 \! ]% P" z- _. e功 能: 终止程序 % N& c$ v. Z# u+ _  V! H3 t
用 法: void exit(int status); ) _6 z! r. z, u/ e' Y
程序例: </P>/ [9 g1 K& Y  f
<P><FONT color=#0000ff>#include <STDLIB.H>
. }2 n* r- m, v1 ^3 M. E7 {#include <CONIO.H>
2 K1 B! d! x# c, j- G; R#include <STDIO.H></FONT></P>
$ s* b& I/ k2 t7 k9 ^7 B& r0 |<P><FONT color=#0000ff>int main(void)
1 g* n7 h  l  u{
$ r0 l* O  `) Q# c! q( xint status; </FONT></P>* v# ~0 a2 N- `2 t  V# z/ E$ T; I
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); 5 |7 y  K5 ?# W. K& F( e" g3 M
status = getch(); . m" b/ s3 H  G6 d* Z
/* Sets DOS errorlevel */ : e8 ~6 ^/ r3 J+ Y; P$ s  G
exit(status - '0'); </FONT></P>1 g# Z  ~4 B' w  \& i# E  q5 V
<P><FONT color=#0000ff>/* Note: this line is never reached */ 4 ]( D# ]0 Q  G3 v3 ^) g
return 0; * @" l9 }& r5 N8 m+ v, S5 M1 R1 s0 H
}
- e" l5 r0 E2 t! q8 v</FONT>
$ X! R* _2 p* [</P>7 \. ^# R! l' m
<P><FONT color=#ff0000>函数名: exp </FONT>
: L8 [2 A1 j) J" r/ R( ~功 能: 指数函数 9 g# j# S5 R. U
用 法: double exp(double x);
$ @1 h- {6 }+ E! _. Z& ~程序例: </P>
5 B2 Q' v3 l& h8 N. X# f<P><FONT color=#0000ff>#include <STDIO.H>% o" s* {) C% `2 s% U% w  a/ v
#include <MATH.H></FONT></P>
$ i& x; [1 V# p<P><FONT color=#0000ff>int main(void)   g* I5 f% s, F; M/ L) h
{ 4 y9 b) L# E$ e; ]2 Z' g9 |
double result; 8 v, E8 @; C" }- L% R* g6 f* e: {$ [+ N
double x = 4.0; </FONT></P>! x! Q1 c- x0 H0 W
<P><FONT color=#0000ff>result = exp(x); # Y* U" X8 S  D& {4 u" j
printf("'e' raised to the power \
1 z6 @- ^! k( F2 A2 yof %lf (e ^ %lf) = %lf\n",
/ [( Q# h# _' A7 ]4 p2 U4 d( _* yx, x, result); </FONT></P>
& t7 Y1 i, E3 d4 ]' v) ^<P><FONT color=#0000ff>return 0;
7 ?+ r5 K- a" [" ~) p$ Y}
) S0 j* G4 `2 d</FONT></P>
作者: 韩冰    时间: 2004-10-4 03:02
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>$ s& T7 \" u6 Q. ~
</P>+ k8 s6 v; }! u; R
<p><><FONT color=#ff0000>函数名: delay </FONT>
' L8 A" K6 }: A- ]8 i" A  ^功 能: 将程序的执行暂停一段时间(毫秒) : S  |9 W, u& H) a/ v
用 法: void delay(unsigned milliseconds); ( m$ g3 v3 v$ S+ @
程序例:
( P, M- X/ s2 k, N1 G<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
5 N8 Q) ]) i2 r1 s4 \6 k#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) / v4 Y+ Y; r; u
{ * ~8 j# A, ^) ]- a) r* o
sound(440); 4 o' O! E: B" N7 z
delay(500);
9 c! I; p! M6 N, Lnosound(); </FONT></P><><FONT color=#0000ff>return 0;
4 G2 V1 ~4 |% U" ]! S" O# r3 z' [}
3 A( d$ c6 T7 A) t9 ?& R! d+ _; f3 F) {8 k
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>8 K6 X" R6 P8 n/ q& }4 r" Z
功 能: 在文本窗口中删去一行
1 Y; P1 q& T3 f0 I' \用 法: void delline(void); 2 k/ m- d6 @' }& _% o) v/ b" V
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
: U- F! A, B  T0 l+ M0 R2 _5 N{
6 Z; ]' w5 ?$ \- w3 F8 tclrscr(); / y' b8 q9 ?4 y& g1 X) P
cprintf("The function DELLINE deletes \ ) h8 @& {4 T- ]& i3 ^! m9 ~
the line containing the\r\n");
2 c4 L( V. {& C+ I/ }- m9 Ocprintf("cursor and moves all lines \ 4 S3 u" I& Z3 `4 U
below it one line up.\r\n");
2 ^6 s0 o6 s) m. X/ k3 tcprintf("DELLINE operates within the \ 7 V  ~  b8 F5 i9 {7 }
currently active text\r\n"); ' }" r8 b% A# x8 @1 N
cprintf("window. Press any key to \ 9 m2 e# h) ?' P
continue . . .");
* ^& J3 ?! V: P8 ?% ~* lgotoxy(1,2); /* Move the cursor to the
. R$ K! h6 D" p4 I9 l" csecond line and first column */
( K* n, t5 w2 a7 h# Lgetch(); </FONT></P><><FONT color=#0000ff>delline(); / [  r1 K+ w& h! N! }
getch(); </FONT></P><><FONT color=#0000ff>return 0;
& _" |: [2 K- F, p4 b) ~} </FONT>, D& n; p3 [. ]- r, U
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
( k2 w' e/ b" d# L5 m功 能: 通过检测硬件确定图形驱动程序和模式
" r# I9 ?* w2 s- `1 K7 W/ G, c用 法: void far detectgraph(int far *graphdriver, int far *graphmode); * S$ k: L3 M4 W: E8 U5 y0 N- v  f
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
$ Y0 C9 h& n, i- p+ T/ T#include <STDLIB.H>- j6 ^' f& T" O1 @2 _6 R2 F% f- s
#include <STDIO.H>* k6 V2 a- _* h1 D
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
; T1 b  k9 `) C! T3 d% m4 Xchar *dname[] = { "requests detection",
  u# ?7 m7 w  s"a CGA",
- J* j0 a8 [& z* s/ @"an MCGA", , `0 G1 t( l4 m' h/ E: _1 i: E
"an EGA",
, V  o3 ~2 H2 m" O9 X" r"a 64K EGA", # P1 w. ]7 ^' |1 u- i
"a monochrome EGA",
2 C8 \6 U7 o4 q! D$ H( Z"an IBM 8514",
7 ^( L0 L/ f+ \"a Hercules monochrome",
8 b9 O6 p; w) h. T/ |0 ?"an AT&amp;T 6300 PC",
2 m* W! E, k) a) P/ R"a VGA", 1 D1 M* q- A5 s2 C5 D; Z  `
"an IBM 3270 PC"
# [) w- E2 A1 a& C% f0 H, S}; </FONT></P><><FONT color=#0000ff>int main(void) ; }. f2 I/ r  g+ v+ x8 C" A
{
6 j- c: v" [' b8 l* H1 i3 X1 @/* returns detected hardware info. */
! D' P& l5 e/ W1 nint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
( h/ o( b+ r  d* Z7 E0 l4 Cdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ 4 m9 ~9 @4 m( [- e2 j5 W. G
errorcode = graphresult(); ! I) J$ ^$ ^" f# P
if (errorcode != grOk) /* an error 5 F4 N( J' G* _/ s1 ^5 {
occurred */
3 Y) K1 z+ ~5 h+ l0 H: C2 i7 D{
' w8 V3 q- X$ h- N1 v' N$ }printf("Graphics error: %s\n", \ 5 E7 ^' d7 l6 \/ l$ ]8 ?' i
grapherrormsg(errorcode)); : M+ y8 Z, j7 V, \' \4 O
printf("ress any key to halt:"); & D- X& t, n7 \; W
getch(); ' `& C# P  M( S/ D  W
exit(1); /* terminate with an error
6 T5 ~8 k9 D/ B: hcode */ - {% x" x+ [  B( D) c! E  A
} </FONT></P><><FONT color=#0000ff>/* display the information detected */ & P& H$ f" ]! Z
clrscr();
* n7 t2 f& I9 x3 ]printf("You have %s video display \ 8 k5 v) {, }5 }; V, X9 n, B+ N
card.\n", dname[gdriver]); . c) t/ O+ t8 O: T$ `
printf("ress any key to halt:"); 2 c: ^' z2 s4 c/ B: q/ Z
getch();
/ Y* O7 ^$ L; C, i% W; ureturn 0;
+ i8 h7 v- T; x6 j1 ^} </FONT>2 M% M# n1 I& W% o

6 {5 k% D- g9 s+ d# i2 O  D- H) y1 |- d$ p
</P><><FONT color=#ff0000>函数名: difftime </FONT>
% o1 W  Y6 ~# V+ O功 能: 计算两个时刻之间的时间差
1 @3 y5 M# G6 f( K1 \$ s$ l4 o2 T用 法: double difftime(time_t time2, time_t time1); # `; O% b; [9 X4 N$ r
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
) u) v" \! `5 n1 @  L#include <STDIO.H>: O; t% {+ p$ Y+ e
#include <DOS.H>
5 D# k2 i0 M2 V#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) 2 _# _- G: ~% F8 V6 c# m
{
- z4 ^: ~# u& Ftime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
  ]5 l7 s' j5 ]# j; ]4 @  rfirst = time(NULL); /* Gets system 1 {+ F4 Q, m' x0 S  S0 F
time */   |% k( [0 S7 s4 L5 l
delay(2000); /* Waits 2 secs */
& D. x1 _' _& P( M! `! C8 j: Isecond = time(NULL); /* Gets system time
( d3 h, Q2 p0 [1 k% Tagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
; c6 n" A9 \  W' W# \, E: v. b1 @1 Vseconds\n",difftime(second,first)); & A. J7 @; }# o' G& ~6 r
getch(); </FONT></P><><FONT color=#0000ff>return 0; : u2 t1 N' s3 |- Z& a2 Z3 a: n
}
5 {- v& _: G0 l# h  _: R2 W</FONT>' x" z" E2 \( w& P; k# A' M
</P><><FONT color=#ff0000>函数名: disable </FONT>
  q9 U: \1 x2 q; V0 M* z' M6 i功 能: 屏蔽中断 * b& j4 r2 ]) f
用 法: void disable(void);
6 v( g1 O- a9 x程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service 1 E* F$ w7 [9 S$ q! O0 X2 g  Y
routine. You cannot compile this program
/ N( F: @. u. P# \2 ~/ }2 M5 `& Ewith Test Stack Overflow turned on and
) s: c! W, m8 z1 |get an executable file that operates
$ a: J( K! w) g7 A! X$ lcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
0 i( {7 V; E8 k) n/ a% L* @#include <DOS.H>: O  w# f$ A1 z/ I  V
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick : j  d, S* O' }5 J2 s& J3 G
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)
: g5 R; l/ j2 H1 V" z, K{
2 ]: F* z# c, j% R  M/* disable interrupts during the handling of 8 f: J. P+ H2 F9 J
the interrupt */ / {" R6 \9 Q5 ], O+ R7 B4 `, X
disable();
/ h1 _" V/ K9 d7 V" V/* increase the global counter */
/ F* R) C6 d4 s# W2 \count++; 1 }9 p% f+ f! Q" }  J) q
/* reenable interrupts at the end of the , @$ ]8 W4 I1 k( \; s8 x
handler */
5 ~( M( K: u7 q! z# f* \, henable();
) A) p$ b% _$ T% V1 N) E  x/* call the old routine */ - l- @+ [) E6 r& d5 {
oldhandler(); & x0 h/ {3 D! k( p# X5 _6 H
} </FONT></P><P><FONT color=#0000ff>int main(void)
0 h& q* {! n6 A- e0 h& f{
/ j0 |7 T0 w! b  D: h/* save the old interrupt vector */
: n; b* `7 h4 g0 c, U  ~3 y9 zoldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ 9 F5 y1 S3 s5 N/ L( c2 Y
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
- E% p# {$ C2 O1 ^5 Vwhile (count &lt; 20) . u# l5 h* v0 k, |. c9 ~
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ % r6 s/ _& [, \# v; D' B4 k
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; 2 l* ~9 j- ], D  c& p1 B
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>' e# c# d  n/ a- g) {' I+ b+ ^, E
功 能: 将两个整数相除, 返回商和余数 8 ^/ Q& I2 s" w. X  ~4 K2 V4 f
用 法: div_t (int number, int denom); 6 N8 z- a$ l8 J( j
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
) t3 I3 t/ d1 q& G6 U; l#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 3 D: B* r" v- T7 U3 J" M/ \
{
0 A& X0 ~$ P2 ]" cx = div(10,3);
1 Q. H, Z9 l6 Y" I" f+ n% Lprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; 4 x7 q* J8 M! h! n2 \) P; i, T
} ) ]' R, r9 r( c1 }
</FONT>; G( u5 A7 z3 w; B  g4 e# a
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>6 d* B$ K2 z9 C5 a
功 能: 获取扩展DOS错误信息 ! x2 S  \7 g& ~9 c
用 法: int dosexterr(struct DOSERR *dblkp); , j# P" ?( @, R
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>! E4 e1 F7 j* Y$ Z; G2 q/ ^' E
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
# U5 P4 L8 _" D3 I1 b1 O( ?{ - O: H6 U, @0 h  |$ e) W2 H6 r
FILE *fp; , Z( x; X% U. w/ I
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
7 F2 I% j* A# l8 Y3 F3 G$ ?% p7 Zif (!fp) perror("Unable to open file for
; X/ V5 e* T! c) G* [4 E! {" Oreading"); 6 c/ I1 q" s3 K6 ~. _: ?
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
1 u1 `! G8 Z' F9 {9 d0 E- {  X0 R( ainformation:\n"); : a8 U  N  g5 |# u
printf(" Extended error: \ 6 I- v, X$ ?& H7 \
%d\n",info.exterror);
: I4 z, K4 u) v3 y4 A* w( Oprintf(" Class: \ 3 K; B3 j- }; ^/ A
%x\n",info.class); & c  N. K. L5 w) _6 q1 D
printf(" Action: \
' ^& Z1 x; E/ ?& e%x\n",info.action); 0 V% ?2 m. n$ v3 b/ X' p' p5 E+ I
printf(" Error Locus: \
# n& p6 m$ D* t& q3 ?%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
; v+ K0 `% U2 V8 V, D# i+ ]} </FONT>
5 o, i5 q3 n/ P( v1 [! w2 }* x. p) J3 X  r6 K! W
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>* I+ l, S+ t' Z* h2 T6 q$ z
功 能: 转换日期和时间为UNIX时间格式
7 z0 Q, T/ J4 H1 L6 f7 i6 [% ]用 法: long dostounix(struct date *dateptr, struct time *timeptr); " k4 S3 _. J3 ~: g0 a$ ]7 {' Q
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
1 h  W5 Y& K4 N  Z" m#include <STDDEF.H>
4 I6 E- E4 H/ m  `6 K: K7 \! t7 I#include <DOS.H>6 M5 F$ |6 \" u5 L5 E
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) : l4 S* h. U; ]
{ # ^  B; D5 k& }: O$ [5 o& p+ \
time_t t;
! X; {# v8 W7 R% l4 A  kstruct time d_time;
, Z# I8 s1 j( v1 `% g! I! sstruct date d_date; % P1 t% Z/ i+ x" n
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
! K, _7 M! [$ R- igettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); + b: a1 J9 W4 [% C+ r- j) C
local = localtime(&amp;t); - B+ q6 }0 d/ f0 R/ @
printf("Time and Date: %s\n", \ 0 v8 o: c* p+ ]( J& @' S
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
- q! e# {1 h* {6 B4 k, c( h# A' p} </FONT>
! P4 Q) r, v6 C3 C& Y2 j2 K( a# i/ j1 x
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>" I' g9 s* r; b3 j
功 能: 画多边形
8 l8 N* S+ [2 g1 z用 法: void far drawpoly(int numpoints, int far *polypoints); 2 K- H9 \8 [5 o$ R, c
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
# o' d, C9 n- x) j9 b#include <STDLIB.H>
2 z1 l  ?6 P1 u7 a  B% y#include <STDIO.H>) G2 Q) ]* r4 |( t) }" d7 y
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) 8 h7 O4 g6 R! b& A- w. d
{
- B) V) ?2 s  x* e! k/* request auto detection */ . M- x: Q7 ]! c3 O
int gdriver = DETECT, gmode, errorcode;
) R- m. w1 p! b$ }8 B1 k$ z7 z8 fint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
! G) q5 U5 Q3 s" C. c" l. X" g; m7 qint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local * }. L, y( P: b  A# u
variables */ + \, B: a. G/ |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
4 p2 R1 {8 m) ~4 Werrorcode = graphresult();
4 g' G' L) J8 d5 E% Aif (errorcode != grOk) / y9 J5 x, Q( \" @# c! d
/* an error occurred */
( u6 _; R2 L  E; q' Z{ / I" k- }1 O) O) x; |2 M  X) s
printf("Graphics error: %s\n", \
" b) L$ D- o. igrapherrormsg(errorcode)); # p0 q+ b+ n& [; H: ~0 x
printf("Press any key to halt:"); - M2 n0 T: z4 b9 Q: ~% j; X% d
getch();
& |/ @$ A! G+ L/* terminate with an error code */ # x9 f9 L  x  Q
exit(1); / S% F& @( ]3 x
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
  G7 S  t' p7 g. F4 p# v# A0 n9 hmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
3 [* i& y+ F% R4 k6 t  j$ L% hpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
# X" S( `6 d" I+ A0 E5 }1 hpoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ ! M; l$ n5 c6 A+ {
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ " f* y" B! m6 Y6 r, H
poly[7] = maxy / 2;
# \$ k6 [, ~# x3 w/*
- t4 w2 I2 l# m" E4 Vdrawpoly doesn't automatically close
: S8 R( a; f4 X% h- @5 p, y; |the polygon, so we close it.
& L4 ~+ l6 `! Z3 y: }6 W& K7 t0 q: Q*/ ' L$ m: G+ k: ]
poly[8] = poly[0]; , V) A& P+ b3 @  T% {7 ^; J- x; P
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
) H2 v% d  @2 Q' P1 Ldrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ , R% U4 }" D5 E
getch();
' h* ~6 ^1 x$ R, T' uclosegraph(); 2 x1 r4 i5 n. o# }
return 0;
9 [2 V- C3 ^' P9 ~1 g- h3 J} * w8 @- t, `* f+ |: n  I. c
</FONT>1 U9 ?7 h% Y: z1 L0 {
</P><P><FONT color=#ff0000>函数名: dup </FONT>( B, g$ p8 H- u
功 能: 复制一个文件句柄 ' P8 t' {8 F, I: V0 U+ F9 r3 B4 P( q* p
用 法: int dup(int handle);
$ ?4 O3 A2 l7 ^6 D/ @1 I程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
! y( |1 _( |( t' c/ X7 w& U  w6 C% e#include <STDIO.H>0 p1 {+ e7 _4 v8 N, x  V& J
#include <CONIO.H>
; X, ~: i6 \/ Y#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
3 \1 h0 Q/ ~2 T; F; E{
; {( ^2 Q5 P% OFILE *fp; # W- G1 K8 _' `1 j
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ ( v* J$ k3 w+ S3 q, T' C
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ , h: |1 L, ]2 x+ L
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 4 B- X6 Y8 ~" H
printf("Press any key to flush \ + Q/ b; T: m7 l+ I* g5 u
DUMMY.FIL:");
8 w; r# u8 {! w; {9 W6 ^getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
4 K  B7 N, A; cclosing it */
3 _8 L4 T) T0 i8 x( W0 L3 H8 _flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ $ H' M! Q" n* |$ ~1 k& {4 k8 r
key to quit:"); 3 V3 Q  l& \/ p, s
getch();
7 k5 m; S* {0 @- X& P* Greturn 0;
/ u+ @- P1 Q, s/ N} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
3 v8 g) i) r9 u& o{
: E) L9 j- j$ M! Oint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ 6 U( C6 d. e0 |( X+ V3 @8 _
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ 4 V  g. `+ h0 _
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 5 {  v6 r. n2 i8 V  K/ C
DOS buffer */ , Z- P& Z6 s6 g5 q) }& O0 s& I' k
close(duphandle);
$ N% X0 G# z4 b# @5 T+ q6 U}
: ^  X4 r/ A$ q$ m) a) o* P  L! h
" [5 F& b& ?- A/ o$ N/ w9 |</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>% q) F3 m( Q  l% r: |
功 能: 复制文件句柄 # P7 E5 F; R/ U' K/ L2 T+ W$ ?
用 法: int dup2(int oldhandle, int newhandle);
$ }% {0 s+ B. d程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>- b% ^" R0 t$ S
#include <STRING.H>9 ?) j2 i6 I' ]" y, P% o- X0 M
#include <FCNTL.H># q+ l" r! q7 X: Z" C: O, a" f
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) % w7 O8 X( n" u$ r$ e2 p$ a
{ 4 y6 J4 v* ^/ a/ e0 e+ t
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
1 g: C' N3 X* W- v& X! k2 schar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
% F- M; `5 _. J" xnul = open("DUMMY.FIL", O_CREAT | O_RDWR, " L* O$ N+ c( x3 q
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard ! {2 Z. ^# P6 W! ~; H) d
output */
8 ]" u* P7 n% B$ a7 N# Toldstdout = dup(STDOUT); ) e- O" F  g$ k  ~
/* 0 d* N; V# X" W: N: @$ K
redirect standard output to DUMMY.FIL & h# R/ `. h4 t7 F# P
by duplicating the file handle onto the
! q0 }0 _0 R2 O" l& tfile handle for standard output.
, p( ~6 a9 ~5 R*/ 7 f6 l# m4 J2 A5 @: M
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
( `& N7 @7 r* q, k; s- d( B3 Tclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
7 h2 e1 Z, l% L7 owrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output / M; i, U% \3 r! q, |. b( N
handle */ , N% h9 D0 Z: |/ B
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ ! a3 V* i' u% P# f) u+ o
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 3 }# j: A; D$ ]4 {" U* d6 \& L
} 4 ?$ N7 M& e+ _. [& f
</FONT></P>




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