数学建模社区-数学中国

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

作者: 韩冰    时间: 2004-10-4 03:01
标题: 函数大全(e开头)
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>3 B% Z; o" o0 Z/ ?' M
</P>
# x1 A5 q0 d% [: ?5 I/ A( e1 W: g4 e2 ]2 B0 S2 U
2 D. \" a; T6 m! a. |
<><FONT color=#ff0000>函数名: ecvt </FONT>% }% f1 ^8 P7 b! }6 f- \
功 能: 把一个浮点数转换为字符串
/ z8 y- \# c, s# s( m6 f2 ?) x用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); $ O3 x; r9 A, K6 }+ f" G4 f
程序例: </P>! _; O1 d( t+ Z/ k2 _
<><FONT color=#0000ff>#include <STDLIB.H>
. b; D% C: V; k& s#include <STDIO.H>
3 a; z8 }: {2 e/ G/ Q: j( l#include <CONIO.H></FONT></P>
1 n! d' s6 L' S- {<><FONT color=#0000ff>int main(void)
: N( Y# b/ ^5 P$ x4 A0 U{ ' t& c, Z. C8 x/ n
char *string;
' r4 L, c. m: e8 N( g* q* p! edouble value;
  @% l& ]- k8 x5 qint dec, sign; % N; V6 S$ R# }2 d6 _- V1 s7 n8 d
int ndig = 10; </FONT></P>
; R- [9 x8 D. G6 F5 C8 e! m<><FONT color=#0000ff>clrscr();
: }* c. d7 G6 T  k0 @# J5 ~value = 9.876;
4 J7 l1 N2 z! |! V6 o. ]0 w0 ^string = ecvt(value, ndig, &amp;dec, &amp;sign); ( @1 e5 I2 E8 A% P
printf("string = %s dec = %d \ # k5 a  |" Z1 X$ [
sign = %d\n", string, dec, sign); </FONT></P>! x2 ]* v3 ]% f" I0 F9 a: T$ N- M
<><FONT color=#0000ff>value = -123.45; , ?# O; c. D, h( @' q& U
ndig= 15; * J# |& A0 A, V* h) t
string = ecvt(value,ndig,&amp;dec,&amp;sign);
5 V" m  w5 |) F2 a! U  Y; }' `printf("string = %s dec = %d sign = %d\n",
) ?7 x8 D0 l2 |2 F1 E% ~! estring, dec, sign);
! R5 a3 z: R8 ^# A6 n8 {</FONT></P>% f2 [3 [# w# G$ N  i& I0 k  {
<><FONT color=#0000ff>value = 0.6789e5; /* scientific 8 }) n8 e. u* C+ `9 t- V7 [
notation */
, s  @- u. z& A) Endig = 5; * U4 d2 B3 ^, K5 V$ z  [
string = ecvt(value,ndig,&amp;dec,&amp;sign); . J" V6 [3 W0 v" q/ x" B
printf("string = %s dec = %d\
( u8 {, ?% U: _- b/ O# esign = %d\n", string, dec, sign); </FONT></P>
( b3 `3 ^9 w- c* F, n& C<><FONT color=#0000ff>return 0; : y& j" @; h/ w. V+ ~  P: q7 _2 r
} </FONT>
( O4 k1 }* G" _$ r  J5 A1 |/ D/ y. X, z& v1 ?' Q
</P># {7 P6 h- {9 @7 z6 ~2 k0 i" N
<><FONT color=#ff0000>函数名: ellipse </FONT>
) Q6 l! v( N) W2 b' t( o功 能: 画一椭圆 ( R( l; F( y6 T
用 法: void far ellipse(int x, int y, int stangle, int endangle,
+ s5 o7 n4 d+ `5 ~5 I9 i6 pint xradius, int yradius);
2 X& A% r' D: Y5 G+ C, ^程序例: </P>/ q) Y* ~! x. u) X* a7 ?2 M3 B! R9 i
<><FONT color=#0000ff>#include <GRAPHICS.H>
# W+ J/ q! k1 f& n9 q#include <STDLIB.H>
  v/ q; N- `- u2 H! K#include <STDIO.H>1 Y$ q- h3 C: T! x0 ?
#include <CONIO.H></FONT></P>
2 W/ j! R0 b1 X% Y4 a/ A<><FONT color=#0000ff>int main(void)
9 a* B( }$ t5 T* y& p9 W{
. B2 i6 w/ N6 |# r8 R% I/* request auto detection */
7 p: M! c2 H0 T4 E- D2 R2 gint gdriver = DETECT, gmode, errorcode;
! O( e( h' _8 y( Yint midx, midy; * x$ s1 r( d( P/ D: {; p9 t
int stangle = 0, endangle = 360;
& `  n, d7 t2 w: Z  Z0 Lint xradius = 100, yradius = 50; </FONT></P>2 [+ o9 ?2 B+ |/ I9 L
<><FONT color=#0000ff>/* initialize graphics, local variables */
% G9 a  i0 ~: ]! E- e+ ?+ J( R& ninitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>9 n2 n  x4 W9 L' F5 u
<><FONT color=#0000ff>/* read result of initialization */
$ S4 k8 Q7 s. U7 y: h5 derrorcode = graphresult();
; }" J. S8 w$ V+ Vif (errorcode != grOk) * K- [% E/ E" r4 s$ H1 y6 ?9 w9 S  i* H
/* an error occurred */
: T$ u# c  D- O' y. g{ , {! h$ H. f; R( E
printf("Graphics error: %s\n",
7 r( Q% f2 X- R$ s8 `' R' Y* m7 D' Egrapherrormsg(errorcode));
' r& d  j8 p* X8 ^printf("ress any key to halt:");
# V9 R' U# N9 _9 l' W3 Kgetch(); # N& A* n, \2 z- S
exit(1); # w: r+ Z* z& M% N- x1 c, y8 E4 b
/* terminate with an error code */ / p7 M  g( G- C2 w, o; l
} </FONT></P>/ p) ~9 X: b$ @+ t! x. z, @
<><FONT color=#0000ff>midx = getmaxx() / 2;   n3 S2 o0 |6 m8 g$ q! i& x- k
midy = getmaxy() / 2;
% y5 l' Y3 z* A  F9 ^! K+ U+ xsetcolor(getmaxcolor()); </FONT></P>: h' S  e5 ~8 q# \
<><FONT color=#0000ff>/* draw ellipse */
7 V& e- X7 Z& N; Wellipse(midx, midy, stangle, endangle, / [* T2 S8 ^& P5 H" h# @# v6 a) r" g
xradius, yradius); </FONT></P>) @8 L, P- H: t/ g0 b
<><FONT color=#0000ff>/* clean up */ 7 U- N8 ~  D2 B( W6 b
getch();
0 |" D; g! U2 o) Z1 Q: \0 ~0 qclosegraph(); 8 c- L8 t9 Q) b! `' ~8 x" w
return 0; 9 S0 c# X7 n1 I3 C4 r
} </FONT># G# G6 m& b/ Z0 A) s) j
/ u2 ]9 T# l! F( m. k  d/ ^" N
</P>9 x% a/ E, Q3 ?6 J5 w/ R7 C
<><FONT color=#ff0000>函数名: enable </FONT>% k% j8 N2 v# `5 `' o+ s+ _, X2 x
功 能: 开放硬件中断
& V0 z: A& o" d  U! k8 M( m8 b用 法: void enable(void);
' F: a( G. O9 e* l$ T& W程序例: </P>% M. A2 ~3 v* x( Z  E* V2 |1 \+ F
<><FONT color=#0000ff>/* ** NOTE:
5 k8 b* D/ e5 a5 |" H, cThis is an interrupt service routine. You can NOT compile this program
2 S4 y4 V/ n% K* a5 ]7 H5 ?% A4 Pwith Test Stack Overflow turned on and get an executable file which will
2 V9 {1 i$ ?5 ioperate correctly.
6 R2 |& l* h8 J) H+ o( A7 j*/ </FONT></P>
7 [% Q  I2 {  `<><FONT color=#0000ff>#include <STDIO.H>
/ f! P3 I; T) ~4 N% Y" b$ S#include <DOS.H>
0 n9 ^- l6 ~# O) j. _#include <CONIO.H></FONT></P>
+ C8 L" S9 H0 V  M9 `) \5 x/ l<><FONT color=#0000ff>/* The clock tick interrupt */ ) _9 A$ y* j7 b8 C2 P
#define INTR 0X1C </FONT></P>
7 j% L; }8 m2 k. N5 {<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
0 Y3 t+ E. g9 l" @<><FONT color=#0000ff>int count=0; </FONT></P>
2 `9 H0 d( w; S; Z, _<><FONT color=#0000ff>void interrupt handler(void)
( ~6 Y4 K) U2 E& {{
: {) r  E" p% L, a5 u- x/*
* q( y, A6 t2 N8 z$ E& Gdisable interrupts during the handling of the interrupt
8 |. d7 @0 v5 U; v& B1 W3 [1 o( t*/ $ f# ]* q- |' S) |7 s. X
disable(); . g/ X/ M' }* L
/* increase the global counter */
! S3 [" I- E! w, a4 T+ b' Rcount++; 2 T, ~+ F& r. g; M
/* + H" B* R( t% @  R% ~1 J6 V
re enable interrupts at the end of the handler - [# p: x+ e. U2 Q/ i+ |
*/ * }  n  Z$ E3 i" |2 y# R. `$ U9 \
enable(); $ H7 h. H; Q& ]2 y$ c
/* call the old routine */
: L" [* ^2 c8 ], zoldhandler();
6 ]( J2 O5 _! H} </FONT></P>4 q( I; j$ B: {4 j6 F
<><FONT color=#0000ff>int main(void) # E% ^- H. H. Y1 K' h# t$ B7 Z
{
) C- \4 P/ P$ D- Y- @% G& `( c/* save the old interrupt vector */ 4 m4 l" h/ {, b/ ^3 j0 C
oldhandler = getvect(INTR); </FONT></P>2 p( a- x+ {: N) M0 D- l1 n$ I/ p
<><FONT color=#0000ff>/* install the new interrupt handler */ 5 M, i: l1 s, z) N# K/ Y5 c) N
setvect(INTR, handler); </FONT></P>
: r6 n; Z) q( V8 d- g: w<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ ' a/ `- X8 p. a) ^' K1 s5 J& e
while (count &lt; 20) 2 S0 ?0 S' J: \9 l6 @2 }; `- a
printf("count is %d\n",count); </FONT></P>6 T* p0 h- Q2 |% X
<><FONT color=#0000ff>/* reset the old interrupt handler */
! E6 e* ^6 H$ l4 ^0 o8 psetvect(INTR, oldhandler); </FONT></P>
$ H! f8 s9 p+ E7 ~<><FONT color=#0000ff>return 0; 3 l. _' H4 z3 N7 U
} </FONT>& ^8 O2 \- }4 B% c

& _3 F/ G$ y, n+ f</P>2 l% v9 Z; v8 S8 j& X' X
<><FONT color=#ff0000>函数名: eof </FONT>
' G; \% {7 i# Z& _9 H# y! c. C* W功 能: 检测文件结束
2 i8 [! }2 }2 {% i用 法: int eof(int *handle); 1 H5 e0 \7 m5 n7 K! C7 C/ i
程序例: </P>( C. o  I- l9 z
<P><FONT color=#0000ff>#include <SYS\STAT.H>- M: K/ i9 A0 r/ }# e
#include <STRING.H>6 j1 O# c& x- G0 R' u4 G7 ?3 ?
#include <STDIO.H>
8 y+ K- Q: l/ l#include <FCNTL.H>; R6 v) T6 z9 q9 `$ |( f( ]/ |
#include <IO.H></FONT></P>
. [$ J+ {% a' j' n<P><FONT color=#0000ff>int main(void)
# I$ q; ?; w4 H- @{
$ n8 x) \7 ^4 z) ~int handle;
  h2 N/ p# o& w5 }9 P0 ]char msg[] = "This is a test"; % A" K. m+ h$ Q1 [
char ch; </FONT></P>
% ~# F% `- v7 x4 J<P><FONT color=#0000ff>/* create a file */
7 o( J$ i& q) h: ihandle = open("DUMMY.FIL", 0 U1 K5 I6 m# J7 c* O9 W) j
O_CREAT | O_RDWR,
* c* T; |9 f& j& G% O" uS_IREAD | S_IWRITE); </FONT></P>' o" w* r' v- m7 j% h
<P><FONT color=#0000ff>/* write some data to the file */ " h2 \* J6 ?6 w, }: [4 Q+ U. b9 f  w! G
write(handle, msg, strlen(msg)); </FONT></P>- ?' I$ G; n2 l0 c- r; E& s  X' }
<P><FONT color=#0000ff>/* seek to the beginning of the file */
: N' E* q7 ?& O, }$ K" {" H' Dlseek(handle, 0L, SEEK_SET); </FONT></P>; [) y0 J9 c6 P  O9 R; J; W
<P><FONT color=#0000ff>/*
1 x, b! [, n' Y8 yreads chars from the file until hit EOF : [; {6 m# O1 r2 y2 K! F/ [
*/
& ?- `( V& a3 L8 }! L( qdo # D. r7 }; D  j5 T9 ~( {5 e
{
: N) f* L% p# @1 O/ ]! C/ tread(handle, &amp;ch, 1); ' C/ P/ E; \) T2 s5 K
printf("%c", ch); : L' W2 {/ S3 b2 l
} while (!eof(handle)); </FONT></P>4 L5 n4 @* B! \. B7 }
<P><FONT color=#0000ff>close(handle);
. c! b; N6 _! Q3 n) V# t; ~9 breturn 0; / c# b4 v) F& G2 R: ?( Q) g" F
}
9 \0 |, Y0 X+ S* o  w3 B5 ~</FONT>
2 v% C7 q8 F' Z( l$ p: U9 x5 {</P>2 w$ a. a- M9 |) x6 P: L
<P><FONT color=#ff0000>函数名: exec... </FONT>5 h. Z% ?1 r; U$ ?. X+ K2 u
功 能: 装入并运行其它程序的函数
! ]7 c, t5 U6 V/ R" x用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); 2 t+ i+ h0 g/ ?) U. |: L9 X1 K& u3 \
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, . e' k( j; X2 Z# w
char *envp[]); / o1 ]+ n9 D" f7 V
int execlp(char *pathname, char *arg0, arg1, .., NULL);
1 @+ P" D) G8 S& b. z6 e( l. J. uint execple(char *pathname, char *arg0, arg1, ..., NULL,
* H0 {) |8 S. e- g2 Mchar *envp[]);
$ T" P  \- Y8 v: d7 sint execv(char *pathname, char *argv[]);
  m* R9 Z* c+ c1 ^# Lint execve(char *pathname, char *argv[], char *envp[]); : g6 ]3 s9 i4 `$ r) h: R% e
int execvp(char *pathname, char *argv[]);
3 v9 `0 }$ J' T% ]int execvpe(char *pathname, char *argv[], char *envp[]);
* T& b  [! Q% l: g: t8 e% @9 f程序例: </P>4 L1 I+ {7 s3 t% V& B. Y& H* _
<P><FONT color=#0000ff>/* execv example */ - r9 L- k0 l2 E( D5 Z. C, d& I
#include <PROCESS.H>  `; w) w* N2 d1 c. f1 A
#include <STDIO.H>: F" R8 M- C) j! L$ R9 [( K
#include <ERRNO.H></FONT></P>
& R; q9 z; p8 s0 }/ Y<P><FONT color=#0000ff>void main(int argc, char *argv[]) $ {# B4 H8 B" V5 E2 j- w
{
9 Z& D% t1 ^4 ~7 U0 Dint i; </FONT></P>8 s7 Y3 I2 c& k7 |8 u& H8 F) ]
<P><FONT color=#0000ff>printf("Command line arguments:\n");
) a, _/ |( q) b( a5 ^for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>  K/ B+ A9 v" G4 a* g) `* H
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); $ J4 {+ T9 l( z6 F& D
execv("CHILD.EXE", argv); </FONT></P>9 M$ R) N, k2 a  \# n6 ?! }0 o
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>, h" g/ U! J# V. h/ N
<P><FONT color=#0000ff>exit(1);
/ p7 o! r! h! M: x6 [}
; d1 F: i0 ?+ ?8 N, m</FONT>4 k* W5 d& R" S5 X6 x4 e3 }; J
</P>
# E& y3 ~) c1 R. P<P><FONT color=#ff0000>函数名: exit </FONT>8 C& t; I2 {* A7 v- W8 F
功 能: 终止程序 2 m! B% f7 U) o/ q
用 法: void exit(int status); 6 ~- e8 k/ E# `. j8 i1 F- g" j- n
程序例: </P>  I7 t6 \8 ~" ?8 Y: b2 V
<P><FONT color=#0000ff>#include <STDLIB.H>
! {$ K: O3 q5 F$ K( \#include <CONIO.H>
% A* N  C1 W6 ?#include <STDIO.H></FONT></P>
: R: n7 g- l7 X<P><FONT color=#0000ff>int main(void)
2 n1 ?5 e- b& g) B* c- q{
, e$ @2 n6 v7 L1 v, v, o8 }int status; </FONT></P>
. \0 c8 d1 s. E6 S6 s; w! `$ Y<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); " N8 @( M6 V% G, W$ }1 c
status = getch(); # r% ~# F7 M0 ^$ e
/* Sets DOS errorlevel */ , @( w& p3 [0 T
exit(status - '0'); </FONT></P>
& o- i+ Y2 G8 [<P><FONT color=#0000ff>/* Note: this line is never reached */
( ]# Z2 `# e* g! u, E6 nreturn 0;
$ p9 k: q; K% R" b: i: g}   {  T8 j3 m& s. {4 d3 r- ?0 j
</FONT>. x& X/ e- h6 ~  u' m! Q
</P>
$ k: G7 R7 Q0 \9 H7 {9 X2 ^8 Z<P><FONT color=#ff0000>函数名: exp </FONT>7 n2 C3 Q5 l8 I6 v/ t' A
功 能: 指数函数
& I0 h. D8 F/ q9 i! L用 法: double exp(double x);
4 A. u) L5 B& K7 o* A程序例: </P>
9 q4 L2 b" o+ z7 Y$ k- r0 d<P><FONT color=#0000ff>#include <STDIO.H>+ \! q- b" I$ A- P6 t  q
#include <MATH.H></FONT></P>
& T/ m% x+ [9 Z6 i8 e4 x<P><FONT color=#0000ff>int main(void)
# i% K5 {9 Q+ x& m{
/ Z, o7 g! \+ u9 |1 u- C5 Jdouble result; 5 p# \, D2 n9 C$ B  a8 i9 X& x
double x = 4.0; </FONT></P>9 h, g6 `. F8 r6 y/ J# s8 ?" X3 O9 Q
<P><FONT color=#0000ff>result = exp(x); 0 U% K# ^; A& }7 h+ b# j# p3 `
printf("'e' raised to the power \ + U% n7 E! }2 C$ k9 U' p
of %lf (e ^ %lf) = %lf\n", $ q0 e- k% H" L5 K
x, x, result); </FONT></P>
* X6 M  O; p- _0 ?& I6 a6 z( Y1 s<P><FONT color=#0000ff>return 0; 6 l: I! K$ u& B, f6 N0 \* @% ~
}5 |5 j$ X& g7 h& `
</FONT></P>
作者: 韩冰    时间: 2004-10-4 03:02
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>
* U* y- r/ R+ m8 }  u9 [</P>
5 m9 ?2 ?' e( B<p><><FONT color=#ff0000>函数名: delay </FONT>2 L1 ]7 y% X; ]: W( `, w& W  H
功 能: 将程序的执行暂停一段时间(毫秒)
3 @2 \& I* t/ k" e' R4 L) N* X$ o用 法: void delay(unsigned milliseconds); 5 _& J/ [1 {1 O$ Q
程序例: & W% F. d/ i& I7 \, W% P
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
( O$ v- H7 V0 V- w2 M/ w3 H#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) ( T. Z2 X3 j/ D) Z2 s, z8 e
{   v7 Z& B* U! g2 u4 |  T
sound(440); , e* C4 a$ _& u' R# G9 i
delay(500);
! s1 X+ ]8 O& s1 Q1 xnosound(); </FONT></P><><FONT color=#0000ff>return 0;
3 ^3 ^' Q3 V  M" a$ W}
' @# H1 i# b! w/ ]6 {1 K- m( U  m5 e; m2 n+ ^5 V2 p
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>' E) g; x% `0 s% I
功 能: 在文本窗口中删去一行
1 `& p1 x: A5 e! M! |! P2 |用 法: void delline(void);
' n' z4 B& l3 k0 [! n/ i( c程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
, g6 p# u/ s/ `# O& e{
( }# S( W6 X: n$ h3 w; M4 Eclrscr();
/ v  v1 I) D" i6 `4 T4 Ecprintf("The function DELLINE deletes \ 7 c$ z: e/ @- s/ `. t( ~
the line containing the\r\n");
& |" s7 n4 @6 K: v- Y1 [. f9 Lcprintf("cursor and moves all lines \
$ L# P# a9 E3 t+ qbelow it one line up.\r\n");
( R5 R; p$ c- g& ~cprintf("DELLINE operates within the \
1 y! C3 B  `  ^. J! }currently active text\r\n"); " ]) n  \* W% k$ y# j
cprintf("window. Press any key to \ : E9 \# P, A. Q
continue . . ."); / Y1 f/ W4 q7 M! f, t1 w
gotoxy(1,2); /* Move the cursor to the : t2 p/ D) V# p/ S0 F* l
second line and first column */ ! \( @8 B0 x0 W( n
getch(); </FONT></P><><FONT color=#0000ff>delline();
2 [' Y9 s1 }5 }$ Pgetch(); </FONT></P><><FONT color=#0000ff>return 0;
( I6 _- p+ a0 C0 i. j} </FONT>
; n% J0 b- h( K</P><><FONT color=#ff0000>函数名: detectgraph </FONT>" q0 G# }3 O' s
功 能: 通过检测硬件确定图形驱动程序和模式
8 A% w2 v) y& X5 T, h8 X用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 4 {; ^7 A- I! I* J4 o8 W
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>6 h+ ?' T! K' a4 d
#include <STDLIB.H>
* h, j: {! D& {$ ~# d#include <STDIO.H>
5 L2 |! B( H  Z2 e1 p#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
4 [  F$ d* v, e  O$ N8 Wchar *dname[] = { "requests detection", 1 J. A+ I7 [2 E4 w+ b  V
"a CGA", + ?2 S: A  P$ U5 `
"an MCGA",
, ?3 c0 p+ b  Z# ^* A"an EGA", 2 i+ X1 O9 P+ s" {$ K( {' q
"a 64K EGA", 8 a% G  y# b7 A" e: B. {/ H! y
"a monochrome EGA",
  w( D% F" G  X6 S& \1 M& Q- G- H"an IBM 8514",
+ s8 _. l$ C/ P! x. {"a Hercules monochrome", 1 J6 s( v+ e& L' i; @7 U" r/ I
"an AT&amp;T 6300 PC", : ]( _9 Z1 {/ {# {
"a VGA", 6 d* {& E' \( E
"an IBM 3270 PC" 2 j# w+ i/ \$ k- n, L
}; </FONT></P><><FONT color=#0000ff>int main(void)
; U( I& E; k8 s0 h! m{
2 q& v8 a2 ~& V/* returns detected hardware info. */ & f, n0 h4 |) ?3 M
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ * x1 u; G, ^4 s/ n0 J8 X
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ + g% q* U5 m  O8 n* J. X, c
errorcode = graphresult(); & x8 W/ s& H: r0 `3 q! @
if (errorcode != grOk) /* an error
1 k* A6 R5 B$ J" R# Z3 R8 Yoccurred */ : X( J# Y( b. T) Z7 T6 C, D
{ : B7 @1 e2 [% V, U; V
printf("Graphics error: %s\n", \ $ y$ K1 @/ n' x& H
grapherrormsg(errorcode));
, e" L, J# p' T/ X( Uprintf("ress any key to halt:"); * A3 \: v9 o$ Z2 r0 g3 h
getch(); 0 m# N, c0 {/ X4 a
exit(1); /* terminate with an error
2 X  ~1 d& b/ y9 F: o; u! I9 @code */
0 f6 w, m3 Q# ?} </FONT></P><><FONT color=#0000ff>/* display the information detected */ * d2 v5 z+ |/ l' s5 V( E7 O2 \0 j
clrscr(); 8 O! u) C" h. P% y" u( R8 r
printf("You have %s video display \ ; ~# I8 i3 q9 V6 P# k
card.\n", dname[gdriver]); ( M1 t2 q/ T( }
printf("ress any key to halt:");
0 H2 L9 f1 ~* J8 W6 Y6 L4 x; a9 Q7 sgetch();
2 D$ K/ x# ?9 v; B( N; xreturn 0; ) w5 j& w0 v8 V+ e, S$ e0 m
} </FONT>
0 C) k" U* T  y' p  v5 X) ~1 @, Q  J# Z

$ t/ S5 V" S3 ~1 S$ Z</P><><FONT color=#ff0000>函数名: difftime </FONT>
; q' M  R8 [8 M) w% \: o6 O功 能: 计算两个时刻之间的时间差
0 ?+ o% W' f: ]" Z$ A用 法: double difftime(time_t time2, time_t time1); 0 {7 R8 g9 K: j2 p8 Z
程序例: </P><><FONT color=#0000ff>#include <TIME.H>; D( b, u3 V2 r
#include <STDIO.H>
0 H4 ~& X( ]* G& d# L& P#include <DOS.H># O7 m8 N9 y. P9 R/ r8 e) q+ @- a# R5 n
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) 5 W; l! l0 _0 u+ ^+ R' o
{ % d: E$ o& b! ?' f
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
! c: _0 @+ c9 m( X& @1 v& B- n( Afirst = time(NULL); /* Gets system
4 g  p6 W2 K0 `' vtime */ 5 m6 t2 H" e/ b
delay(2000); /* Waits 2 secs */ * A! r( y  ?# A: n" Z
second = time(NULL); /* Gets system time
9 ~) o, n. A  Uagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ - e7 [& `9 V5 E; t, ^3 z
seconds\n",difftime(second,first)); 9 ]$ \0 e! i7 e3 t
getch(); </FONT></P><><FONT color=#0000ff>return 0;
. d. n# h; E  b7 Q+ D}
! [, I4 Q7 o1 r% G5 d! m</FONT>5 }* f6 t* ]: G5 S, i
</P><><FONT color=#ff0000>函数名: disable </FONT>/ B3 m# z2 W9 D% H
功 能: 屏蔽中断 * j8 ^7 x7 z8 |% l8 n3 w
用 法: void disable(void);
& a  k* [9 m% [, w& O! r# h8 a程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service . ^5 v2 o9 F& Y$ m7 C( I
routine. You cannot compile this program
4 U9 d* v/ }" d! _' R8 Swith Test Stack Overflow turned on and . H9 S& W  k) l+ @+ h; F( u
get an executable file that operates ) ]9 n7 M. _, D7 T4 ]
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
* A  Z6 O0 c5 d% K( I#include <DOS.H>
, X- T4 M( {7 |# i0 u) a#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
/ S. U# m6 w4 f$ Linterrupt */ </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) 1 n% ~* K4 P! T# A* V1 w: w0 R+ B
{ 5 i3 W0 l4 V% R
/* disable interrupts during the handling of ! K  x7 z' m' w, U: C
the interrupt */ : V0 j9 Q* A# B4 N4 Q- P! f# }
disable();
: c7 p5 w3 p7 w/* increase the global counter */ : s: T  Y. J7 [$ ]# L3 X
count++; 6 v$ r& k4 z3 _3 w( D
/* reenable interrupts at the end of the
4 N+ }- P: [( ~) A% O. b' [handler */ ! T8 m" T9 ~& A" n* Y( A) a! v
enable();
. ?* a9 G6 J: H1 J9 _/* call the old routine */ + x3 n2 P' r9 W* w0 T' U: u
oldhandler();
: c: x/ g5 ?; a9 u8 E. m6 R  C} </FONT></P><P><FONT color=#0000ff>int main(void) - g& y* w. I$ V
{
" M8 j2 K8 h- }/* save the old interrupt vector */
: E" p6 h* ?, v; d  ?/ ]0 g, f* ?oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
/ U! m  b7 ~" q) m1 Asetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 6 {+ A% {  F9 @5 A3 ~$ s% z+ B
while (count &lt; 20) ; f4 I) R* U7 ]) \' i
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
# A* ~1 Z  Z" G' m7 q5 ysetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
/ l2 t- m4 m) _6 O1 l} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>2 O6 Z5 J/ C9 i1 C4 d$ o$ f
功 能: 将两个整数相除, 返回商和余数 2 ]: S2 u3 a" s6 i
用 法: div_t (int number, int denom);
/ L4 g% D; m/ C0 O程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>8 t+ p9 `. F( T- I) G  H3 R  i1 w4 I! n
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 5 ?# Z+ D. f9 v% r
{
! Y* V% V: D5 }! g4 t% Ax = div(10,3);
* N- v% W$ u4 i! C) Mprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
$ J* q% Y& g2 L; j, W- W8 t}
: `9 V) R7 P- G8 f0 y4 z, w" i( B( s, W</FONT>! K$ `6 k9 t9 J% w; T) B* e# @
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>. Y$ s$ S2 q/ l, S' i) L
功 能: 获取扩展DOS错误信息
' g! z+ a( N. t; _用 法: int dosexterr(struct DOSERR *dblkp);
" w$ r& Z1 x3 {% {2 Y0 F程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
( g% g7 q8 E5 X* o7 d#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
* i/ Y" S. @% ^* P% [2 \, k8 W  q{ & Z8 @4 I" X& C) Y% ^& m) U
FILE *fp;
: F. Z7 \- s% U. xstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); 5 k, _- x+ n7 _/ x/ U, J
if (!fp) perror("Unable to open file for 1 m* T! {  t# L$ R
reading");
$ J' u) I) Z2 }& \( y7 i( Tdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ ; X" j( t0 F6 ~$ ~1 k
information:\n");
9 O' R1 ?- A9 z$ dprintf(" Extended error: \ , r1 D, }! F9 |2 E8 M) n: b: p6 f
%d\n",info.exterror);
" {- M+ V7 q! [0 i; p" ]printf(" Class: \ ' ^( M: M" ^0 Y
%x\n",info.class);
* K8 d' z9 `$ y5 sprintf(" Action: \
+ M9 t0 w7 K* {4 Q- B7 m) w%x\n",info.action); ) i7 t) {0 R) ?
printf(" Error Locus: \ % q" w* Z/ M" I
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
+ V7 n1 }; D% H% J. T} </FONT>
7 Y1 }9 }, s+ W' U" b
. P% b! g' N5 b. y0 O</P><P><FONT color=#ff0000>函数名: dostounix </FONT>0 e& i' S! f1 y  U7 g+ J2 Q
功 能: 转换日期和时间为UNIX时间格式 : [, p+ V& B. v+ C+ M) i
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
( X; p, p/ e) j& P+ Q程序例: </P><P><FONT color=#0000ff>#include <TIME.H>0 u  e; ]7 r4 U0 z; n# C
#include <STDDEF.H>
4 p9 B3 I3 M; E0 i#include <DOS.H>$ h" Z9 C( f5 m; g0 w# E+ q# y, c9 i
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) 8 Q" J- G: y* u0 b" k
{ 8 t' N- j: h8 M8 t3 D$ I& J. a
time_t t; ; Q" i2 W6 y2 {9 Y0 C$ V! g! f% R. `
struct time d_time; , G7 i; W. F- n* u3 W! O$ z2 t+ F
struct date d_date;
$ ?0 m" R5 j. S% {struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
7 j! Y4 c7 Y. A: B5 k/ wgettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);   T* i4 W$ Q* P  o
local = localtime(&amp;t); / ]0 K' t- p2 k3 q! D
printf("Time and Date: %s\n", \
+ d8 W* m, T: G7 Z" s( j5 k- w- Nasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
, M+ w$ q6 d+ e4 {; f# a} </FONT>9 d; F* U* h( Z# R* Z  N
. R1 g/ I6 ^; U, M& p, _" @% v
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>. P. Y: W5 @0 C
功 能: 画多边形 1 `4 M# V# H9 s1 O- ?8 K, @7 [9 D
用 法: void far drawpoly(int numpoints, int far *polypoints); 5 L1 n! q3 P4 `! L0 T) t0 J
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>) r, E  F# P, f: s; F8 U
#include <STDLIB.H>
/ Z+ f# s) k: U) h#include <STDIO.H>
$ t3 F. B1 Q+ G2 [#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) 5 J. B, o2 B. D! e2 H
{   I$ ^" ~/ G6 u) O  }8 @/ O
/* request auto detection */ ; p8 b8 j( w2 W) u5 _* \# h0 O
int gdriver = DETECT, gmode, errorcode;
+ f* d, K" l8 t$ x* J/ pint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ + a* {5 `1 b" u3 U
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local ; L6 A: ^6 t( K0 h) C: m+ `
variables */ % i& k; Z+ g" Q" ~. ?+ `
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ % ^. N' C' c" r  ]9 f
errorcode = graphresult();
8 j4 d- K3 J9 S2 v5 t8 oif (errorcode != grOk)   p# O: {: {  z4 X
/* an error occurred */ $ l4 y: v) e7 Z
{ 3 b2 N; N2 H1 j6 V8 j7 D" e
printf("Graphics error: %s\n", \
8 \3 x# S/ U7 p1 @' C6 c' j& p* [grapherrormsg(errorcode));
7 J, N! f, L0 I& r/ Uprintf("Press any key to halt:"); - j5 ^# b% S) ]5 F% Q
getch(); 8 B* g' O3 ~5 ]% t+ B
/* terminate with an error code */ / _# E4 N6 i2 i( Z: K
exit(1);
& o% ^2 h! E# \  x} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); - m- @# ^+ R: m) s7 g' t- }
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ ! w& `. b2 i" R- z
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 9 O3 f' f' ]$ [# a
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ : y$ R4 m: \2 {8 G# i
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
2 E# G; z" y, z  x7 Lpoly[7] = maxy / 2; 6 G5 [# \! {  W* Y
/*   ^; a# R( N' J
drawpoly doesn't automatically close
5 k: X9 N, ]9 d4 i' X5 u% O/ \5 Pthe polygon, so we close it. ; @' G7 N' N8 N3 A$ f' K
*/
+ l! \7 p# ?' Y1 F* `* T- H: Gpoly[8] = poly[0]; 1 Y& Q4 q, ^' `3 y# o2 n
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
+ O; p% l+ k9 G  F# wdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
8 i; v( }# }4 R: o; Zgetch();
3 F; {+ p9 [8 ?5 y; r' mclosegraph();
4 e" Z& k  f- k2 Preturn 0; 5 r* V1 r( u& H) E: C
}
9 k- j% K# p% S+ d</FONT>
' m' c' |3 A. k! \2 u2 {/ b6 a5 y8 f6 C" m</P><P><FONT color=#ff0000>函数名: dup </FONT>  B; [, g! D( o$ O( z; {# r" K
功 能: 复制一个文件句柄 9 ~% V. G- E9 \  r
用 法: int dup(int handle); 2 ]$ R$ a% O* Z+ X+ o6 D
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
5 u" x7 h5 j  y  U" N+ s/ S7 t#include <STDIO.H>: R! H: |5 P' M, J' A7 b9 W
#include <CONIO.H>
0 S. q4 o# f9 |* r#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) ) S) j2 v; k& t) f2 F+ {
{ ) W3 S6 ^8 K8 j8 |+ _
FILE *fp;
, w" v2 m0 X$ v  Z3 t7 s4 R2 q6 Wchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 3 r6 o, o3 l8 a: G9 E- {
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
. O: H$ }# |9 f" e' P% Qfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 1 s  W" {" }7 ]& I  }- `$ t
printf("Press any key to flush \ . [7 `; ~; g7 N: c1 C; w
DUMMY.FIL:"); 4 f4 y' V" J: H6 b: @! [. K
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without / g/ C8 a% B- U5 I. s$ T) T
closing it */ & T& s7 r/ q& Z. r4 D
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
  \6 ^5 A4 I6 t7 a  lkey to quit:");
( R; ~6 }/ k0 c" Y# E4 M1 n  Q/ y) Cgetch(); ! f% ^* M6 x9 u" v# U
return 0; ! N: {& }: e% d* r2 a
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
. Q, o9 P+ B2 _1 a9 j{ - n# g, u2 y: q+ i& P
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ / ]+ T0 |. S( N3 i# U& @6 c# Q! w
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
  p& }, @- C# d: ]duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the / l7 o5 q; {0 b4 A" H/ h+ W, h
DOS buffer */
3 ?& k! A8 ?* v0 y$ D8 n; x7 Eclose(duphandle); / i$ W) N3 W! o
}
: Q5 r2 C; [0 S- ?4 U2 K& s3 @' K! P' @2 ?* y, p
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>  _% a+ ?9 u# a8 a/ M; R
功 能: 复制文件句柄 1 t, \+ m' V$ c7 e  r# D
用 法: int dup2(int oldhandle, int newhandle); : k* u! h/ [: m7 J9 f$ m6 O
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
) m$ J& t2 _4 Q2 c4 f; t#include <STRING.H>  R4 s, v8 {0 H0 u: s" y; I
#include <FCNTL.H>' }0 i" W* y6 w/ K
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) * S) T- B, `3 A" m7 T+ T5 ?
{
' g3 e4 g( N4 g- ~) F* l#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
9 A" p- L0 _. i, M4 ^char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 4 z. f- f: r) b) E" t+ ]& r+ O2 |
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
# U) S# F# [. I- Z) D" J# ?7 Z! nS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard - V; C2 d, |+ V9 P5 k! D4 U. X
output */ * M+ k+ ]1 Z  m. n- L- g8 G$ I
oldstdout = dup(STDOUT); 3 W/ b, x1 m' j
/*
% E7 M# n' i7 c1 q0 n# t! Nredirect standard output to DUMMY.FIL   G( T4 k1 \& r9 L/ O/ T  u6 S
by duplicating the file handle onto the
0 ?7 _5 I6 ~9 x& rfile handle for standard output. % s$ V$ u; Q" j
*/ 3 `5 x* E/ Y6 b2 [
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ 6 j+ `9 t: }6 T" S0 E; [, W, `7 s/ Y
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ 6 C& c" r( Y/ @, w/ ?# n) k
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
. E! v+ \8 X( M$ q7 F) rhandle */ 0 d2 T6 a$ x; J- V& w. _
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
+ o0 `% ?9 X2 f+ O1 ?close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
% z0 N( U4 q7 K$ n" T/ I, X}
/ v1 p) E, J; G1 G4 N* q) L</FONT></P>




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