QQ登录

只需要一步,快速开始

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

函数大全(e开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:01 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>
5 H: U7 ]7 o4 s/ k</P>
+ z# z, Y" J  u
' u0 Y/ R  y4 p0 k9 s  X. a) d; F: }$ k9 v, p9 h# ?4 ~
<><FONT color=#ff0000>函数名: ecvt </FONT>3 `) [5 u0 U: z
功 能: 把一个浮点数转换为字符串
$ S/ d* C0 `. p* `! _用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); 6 M6 c1 [, a/ W4 u3 d
程序例: </P>0 V# }8 F% e8 w# U2 v, s
<><FONT color=#0000ff>#include <STDLIB.H>
- O! n! h  L5 J5 V2 f3 r9 b% d* _#include <STDIO.H>: ?" h8 a9 U3 s9 c/ d
#include <CONIO.H></FONT></P>
! G* l3 E. `7 l& O<><FONT color=#0000ff>int main(void) ) ~3 H$ g8 S3 G- ^
{
! n/ i9 f& P5 D0 E' \char *string; 2 r3 b4 u! A$ Z% i$ S
double value;
5 `- V! Q) d, d( tint dec, sign;
( R3 H- M1 y  qint ndig = 10; </FONT></P>1 \& `- e- M. b% x. I$ L
<><FONT color=#0000ff>clrscr();
& y& H& m7 {6 ~value = 9.876; * \% j2 W& O5 M+ r/ M5 a
string = ecvt(value, ndig, &amp;dec, &amp;sign);
  U5 w, [8 [8 E4 e1 Y3 U7 d$ q  Fprintf("string = %s dec = %d \
5 n" a1 L/ H6 |" E4 osign = %d\n", string, dec, sign); </FONT></P>
. S$ ~* z+ P- w' G& y2 `<><FONT color=#0000ff>value = -123.45; ; c3 q) u& Q/ @
ndig= 15; * P; q) i; _4 s: ]  Z' J
string = ecvt(value,ndig,&amp;dec,&amp;sign);
2 b* x; K% @+ ~printf("string = %s dec = %d sign = %d\n",
. N$ G, V2 Y, F6 `3 ]0 astring, dec, sign);
. g9 U( @; \' g/ W# g, G</FONT></P>
" g# G6 \6 d3 X- L' v<><FONT color=#0000ff>value = 0.6789e5; /* scientific " L2 V) ?3 r7 s5 D
notation */ 2 M, r4 V. W% v7 a, L
ndig = 5;
/ H! \9 `5 u* n& h2 f4 l  ~/ Dstring = ecvt(value,ndig,&amp;dec,&amp;sign); 2 y! S: v$ [1 x8 E4 E5 E
printf("string = %s dec = %d\
8 }2 _6 }0 B) [3 [sign = %d\n", string, dec, sign); </FONT></P># ^* ^  m3 b' j9 G2 \4 _& ?; }( h5 X
<><FONT color=#0000ff>return 0;
" M- O3 j4 M& Z: Y1 D5 T} </FONT>! J/ Q* I# E2 f; d8 o9 A
1 ]& L; w: h- `$ ^7 V5 z
</P>
1 U4 \: X) |  D* L, v* o<><FONT color=#ff0000>函数名: ellipse </FONT>! \; s7 D* {* q& `  }
功 能: 画一椭圆   K$ I. r0 `5 u# b& u
用 法: void far ellipse(int x, int y, int stangle, int endangle,
& u0 J! k2 C6 R  |# @! @" N0 Lint xradius, int yradius);
: U8 i( C3 S/ ?' i( a程序例: </P>
  S9 g2 t# u: t  }! l% n, P1 k<><FONT color=#0000ff>#include <GRAPHICS.H>
* r5 G8 F% U& i8 A#include <STDLIB.H>  E8 ]( R) h. K2 K
#include <STDIO.H>
3 O+ G6 Y9 N* k2 c& P5 R#include <CONIO.H></FONT></P>
* U, y0 t; T  R- ]! v, t<><FONT color=#0000ff>int main(void)
0 ?! m6 }- E' W4 R) R- I{
- b/ k1 q0 W" [' r0 A" E6 y. r/* request auto detection */
7 _! D& P+ z  R% y1 x1 Kint gdriver = DETECT, gmode, errorcode;
$ J3 _, y0 Z3 W' ?) d# E' Pint midx, midy;
& G: O6 S# C8 n: _# N$ Gint stangle = 0, endangle = 360; ) p% T5 d+ v% g% A  Z% H
int xradius = 100, yradius = 50; </FONT></P>
: ?/ t( a. M4 M/ J% c! l( W; a1 b<><FONT color=#0000ff>/* initialize graphics, local variables */
" d! f+ M* x- Ginitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>( n, c. r$ A1 l8 Y. T$ `+ ~5 M/ a
<><FONT color=#0000ff>/* read result of initialization */ * {  K$ r5 [7 D# V1 _8 Z
errorcode = graphresult();
3 e8 ]; n5 i5 r: B. I; tif (errorcode != grOk)
' Q, H8 c4 _$ a  h8 \/* an error occurred */ $ s) G$ M( j  ~+ e2 q+ b. E
{
) s& n7 f2 L8 c+ ^9 y5 g: Wprintf("Graphics error: %s\n",
6 i3 z+ t' e$ d" X. N: E( Dgrapherrormsg(errorcode));
$ W0 Y4 `2 @$ e/ Y0 Vprintf("ress any key to halt:");
5 w+ A) |6 o: `0 ]getch(); ! M7 c3 V  [; q  \! y. Y/ |
exit(1); . W  M; K" V0 m, i2 U: x, _" ^' D
/* terminate with an error code */ 0 x; W# E: `; G) q
} </FONT></P>
; H7 R, E- N9 O& O<><FONT color=#0000ff>midx = getmaxx() / 2;
) J4 g6 @1 r1 \& h- c9 H5 Q3 e( Bmidy = getmaxy() / 2;
+ X' J3 A" d$ W, m! v" A  U# ]setcolor(getmaxcolor()); </FONT></P>
+ {; r; l8 A* o<><FONT color=#0000ff>/* draw ellipse */ % Q! T9 G' o. z# c- o' }$ F
ellipse(midx, midy, stangle, endangle, , s- |. h+ s$ L2 M0 ^
xradius, yradius); </FONT></P>  o8 e# Z* Q% ^. P1 b8 {
<><FONT color=#0000ff>/* clean up */ & P/ M7 K3 G! n& F! K
getch();
7 m$ _% r' Y" E2 l1 m& mclosegraph();
& a* J0 S# t/ h# I* Vreturn 0; . {8 B# E% ?3 x  l! j, G6 ?
} </FONT>
) R, e, z% ]; Z2 {' d' h% }7 Q# d$ Q6 ~
</P>& u, o. T6 y  Q2 o
<><FONT color=#ff0000>函数名: enable </FONT>
6 [" U: J# J" D* C' X1 T! z) d功 能: 开放硬件中断 $ @* n: k4 z7 i5 i# c  E8 B
用 法: void enable(void);
' C9 h" o3 J4 n( `& c" l程序例: </P>- \  G$ o( s( Z
<><FONT color=#0000ff>/* ** NOTE:
  B/ O9 i) {) IThis is an interrupt service routine. You can NOT compile this program : l, f; _. p1 \4 J# D3 D7 C
with Test Stack Overflow turned on and get an executable file which will
9 h7 ?0 {6 _% ^- Ioperate correctly. 5 j+ U0 ]) ~& H/ M$ @
*/ </FONT></P>* y3 ~4 p& @5 s1 P7 I5 s4 Q. a
<><FONT color=#0000ff>#include <STDIO.H>
7 }* P9 [$ K) z#include <DOS.H>7 |1 O: ]2 t8 b; E
#include <CONIO.H></FONT></P>
$ H, `# d6 D* k" V<><FONT color=#0000ff>/* The clock tick interrupt */
; L! A' {' K* ^% ]3 z#define INTR 0X1C </FONT></P>$ p. S- a$ [3 p$ b$ W3 b
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>/ z/ {0 K6 Q+ D( b. R
<><FONT color=#0000ff>int count=0; </FONT></P>4 w3 j) n, q. ?  j! C
<><FONT color=#0000ff>void interrupt handler(void) 5 A+ q# B* k$ }' b! y
{ + V! [' b, y7 O7 M
/*
6 T' ]. F# x1 M( U/ fdisable interrupts during the handling of the interrupt ; G8 N7 D0 G% U
*/
2 P& f; i# }$ {* D# d) P8 Sdisable(); ( r; O2 K9 v( W% v2 v/ t7 i
/* increase the global counter */ + `; M/ L. f( R# _' L
count++;
8 e) ], p; B  |" R1 X; G$ l5 v8 Y/* . M- q: a; e2 `# a) x% I7 @! B- }
re enable interrupts at the end of the handler
4 @7 S& l! i  S* _! Y*/
6 H/ J" s6 q4 j% t" aenable();
4 G: S4 f) L! c" w# R/* call the old routine */ ! O: {, w  v; z0 M
oldhandler(); * N) \1 f2 m0 u2 X' Q) i
} </FONT></P>
& c8 }7 @( H; l$ d' D' ^6 d<><FONT color=#0000ff>int main(void) + @; E  l. W) M0 d- @
{
) y+ @5 I0 x0 W7 u' {* Y. @4 ?/* save the old interrupt vector */ - n6 W9 K, r# m
oldhandler = getvect(INTR); </FONT></P>
: ^8 I4 \' w: o<><FONT color=#0000ff>/* install the new interrupt handler */
9 B: ~. d- J3 V# [) Asetvect(INTR, handler); </FONT></P>
" ^: Y$ D0 @& K. G4 j$ k( T<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
1 T% j7 ]/ ?1 Swhile (count &lt; 20) 5 B' v! N$ ~* Z9 B& m  }$ w
printf("count is %d\n",count); </FONT></P>
1 g0 \( F+ L" c# P1 H<><FONT color=#0000ff>/* reset the old interrupt handler */
! \$ E/ p0 r/ u4 `  a( F) @% lsetvect(INTR, oldhandler); </FONT></P>
4 Q6 C+ ]+ }- n) L4 Y' R<><FONT color=#0000ff>return 0;
* s) H! Y, s/ Q} </FONT>/ n( p% [7 d  B3 G( e; ~7 S3 E  c* K

! t# M$ t+ u5 e  {1 Z</P>
4 i$ N6 [) h( U5 O) F4 C8 q- j<><FONT color=#ff0000>函数名: eof </FONT>
" H8 ?0 m) L% L3 S( t: j: b- ]功 能: 检测文件结束 # S5 R" |$ q" v  C
用 法: int eof(int *handle); + t4 `' m; V1 Q* e8 S
程序例: </P>9 C* Z  W: m& C
<P><FONT color=#0000ff>#include <SYS\STAT.H>7 N* @( c( s& @, I1 Z% X
#include <STRING.H>6 D2 g% M, v3 q# J
#include <STDIO.H>
( S8 T- q* G: c2 V  m#include <FCNTL.H>( y2 w1 d7 |" G+ A
#include <IO.H></FONT></P>) ?) ?" N" V$ Q8 M, [) z
<P><FONT color=#0000ff>int main(void)
8 [( m3 V- z3 S{
/ P+ p4 `5 {) ~. k4 v+ ]5 wint handle; & M* D6 y# z: _. `  }4 e
char msg[] = "This is a test";
) |3 F$ q# i# p4 R+ \: M; Xchar ch; </FONT></P>5 Z" z4 ^% Q+ U( ~' \8 ]
<P><FONT color=#0000ff>/* create a file */ ' m# I9 e5 g. Q+ G6 S
handle = open("DUMMY.FIL", $ T- a4 K% |, t
O_CREAT | O_RDWR, * W3 d, L& z: A. J0 h
S_IREAD | S_IWRITE); </FONT></P>1 k# w2 P% C4 Q. d/ M
<P><FONT color=#0000ff>/* write some data to the file */ + G3 z, r7 r! f; a
write(handle, msg, strlen(msg)); </FONT></P>) T$ G$ v* `  S& y
<P><FONT color=#0000ff>/* seek to the beginning of the file */ / E3 j# }8 Q7 F
lseek(handle, 0L, SEEK_SET); </FONT></P>
* }1 w* j: b$ ?3 D' x, r<P><FONT color=#0000ff>/*
  X' G; V1 c6 B5 x% Freads chars from the file until hit EOF
9 i; @5 j9 E4 {2 D*/
  R& Y9 {4 J/ n4 ddo + ?. I$ Z; U# _8 i
{
3 S- t+ V* C9 z; E! L3 \+ {read(handle, &amp;ch, 1); 0 S8 s) |( I- r4 g
printf("%c", ch);
( Y+ A1 ?  n! W: c, X} while (!eof(handle)); </FONT></P>3 C! D. T- @; _1 Z4 k0 `
<P><FONT color=#0000ff>close(handle);
; b6 W0 U* Z, x, G- v+ zreturn 0;
! I% E& V3 i9 A* e# [  \}
: J. N/ A  y2 v7 z</FONT>
6 m* A. U# T+ ^8 Q! |$ d' `</P>
$ x% g4 l. V! }" X9 @<P><FONT color=#ff0000>函数名: exec... </FONT>: g: t6 t+ y. ?1 C5 C3 V( ~" j
功 能: 装入并运行其它程序的函数   g2 [" ^/ H" o) o4 K9 L+ s
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); - [7 M# f9 z# b; I, [. A
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
( K+ T3 E7 U9 o; H8 I6 h8 a4 ]char *envp[]); ) J, Y# ]1 E/ j- c0 s
int execlp(char *pathname, char *arg0, arg1, .., NULL); & P0 V+ w3 p5 I9 Q9 L2 W
int execple(char *pathname, char *arg0, arg1, ..., NULL,
9 _, `% c! l) P6 }5 echar *envp[]); % h  U; I% a3 S8 [$ M
int execv(char *pathname, char *argv[]);
' z0 J6 H) |& ]: N5 w. {, ^int execve(char *pathname, char *argv[], char *envp[]);
3 E0 N* G+ p! E% P! [- lint execvp(char *pathname, char *argv[]);
0 _3 {! Q& y- l7 R' Wint execvpe(char *pathname, char *argv[], char *envp[]); / e* C' S/ n4 E5 K
程序例: </P>
3 j* X8 ~0 ?% j+ x  G2 J<P><FONT color=#0000ff>/* execv example */ 9 K! b! T/ q# `! J, `. Y
#include <PROCESS.H>4 A% ^) ~+ g' d' x1 `1 x
#include <STDIO.H>
  P, z+ F( n$ ~6 f# w#include <ERRNO.H></FONT></P>7 ]  I) k0 D% n# P& a4 N: z7 u) K
<P><FONT color=#0000ff>void main(int argc, char *argv[])   b# k1 A% v) V. o  s1 p
{ : i$ n1 I$ q& p3 R5 w3 A6 l
int i; </FONT></P>' c$ f% u& M/ V: j( Z$ u, l
<P><FONT color=#0000ff>printf("Command line arguments:\n");
; @$ R# G2 Q6 ~' J1 Z( Q$ ~for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>" b8 a$ ^6 [2 h: e4 m2 o2 d& c
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); ' C8 _1 k: `# Q" ~" J8 s; P
execv("CHILD.EXE", argv); </FONT></P>
4 w) t; [! \7 Z: w, f) p<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
9 F  \) Q2 c" K) E+ e& M, C<P><FONT color=#0000ff>exit(1); ) \% U! ]5 x! V) b& @2 \% K: p
}
1 z. ^" e( M& i* J0 G, {- T0 f</FONT>
+ b5 c7 b) ^4 z</P>
7 E# A& \$ k' O7 @<P><FONT color=#ff0000>函数名: exit </FONT>
0 C, _" i" V* B7 y) s& U功 能: 终止程序 * O+ t, B( E4 D/ D  n3 W5 |9 @
用 法: void exit(int status);
$ c& W; u. U% ?* G8 O& v程序例: </P>
8 c( B1 n5 z- C! Y- F; a% t% f& p<P><FONT color=#0000ff>#include <STDLIB.H>
1 ]9 M0 j4 L( ^5 v0 V#include <CONIO.H>
5 u. y5 h3 V% B) Y6 Z# ~# S#include <STDIO.H></FONT></P>
  ^- D$ B5 D4 K* k# n8 \, r* ?8 Y<P><FONT color=#0000ff>int main(void)
6 D) O; |! x' z9 D2 t3 a{
4 g" a; |# ~; ~4 gint status; </FONT></P>8 x* }  X" l( W7 ^9 H
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); ; \4 _* |7 m" e4 m$ P8 L
status = getch(); # j. r$ q9 j" y
/* Sets DOS errorlevel */ + z. D1 P0 Y' Q& D% x
exit(status - '0'); </FONT></P>
3 w9 y0 g& x! |4 k: L4 H<P><FONT color=#0000ff>/* Note: this line is never reached */ * `1 Z7 a& L7 O8 G
return 0;
. j3 e3 Q3 V; |! e/ X, g}
' n) x# E$ M8 y* v7 j' Y% }</FONT>
+ T/ C3 S, \, `+ {  P$ Z' w0 w! K</P>
: N; h6 Q& I) p* ~, \, L<P><FONT color=#ff0000>函数名: exp </FONT>
2 x7 D; {$ M9 R$ z, G功 能: 指数函数
. c" h0 O( y/ l" T3 z, u' b, h) Z用 法: double exp(double x); 6 J. v4 {  ?+ {, n% I
程序例: </P>
2 X( D4 ~* @) o" B' `<P><FONT color=#0000ff>#include <STDIO.H>
$ L6 N( z) L: @) y#include <MATH.H></FONT></P>% \, A) r7 @& ^, l* A& C
<P><FONT color=#0000ff>int main(void)
3 E* _* g5 p0 q6 k{
: |4 K3 l" o5 {: y* y' F# Idouble result;
; X$ J0 C) T! T. Q/ Xdouble x = 4.0; </FONT></P>( h! `6 z0 J$ c  y) S
<P><FONT color=#0000ff>result = exp(x); $ [( n: m! ]% Z/ L) M  x7 O
printf("'e' raised to the power \
: S" V2 ]5 G. h% f3 ^/ Z) Qof %lf (e ^ %lf) = %lf\n", 9 G: \: Y5 j. L7 i- f, p# [
x, x, result); </FONT></P>( ?$ e4 v1 g4 E7 L! e& I' n
<P><FONT color=#0000ff>return 0;
# z) i* ~  d" X$ a+ a3 ?% |; s6 r}
# M, r) }8 M1 x8 l3 S- {</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>
( F- Z( d% m! A! ^2 h4 o  x9 E</P>3 g) h9 y1 T- ]! ]# `. N
<p><><FONT color=#ff0000>函数名: delay </FONT>
2 B  _+ `7 K1 H. D功 能: 将程序的执行暂停一段时间(毫秒) 3 V/ @* a2 D- o% K0 K
用 法: void delay(unsigned milliseconds);
$ v! W# z% r) l+ j程序例:
1 m5 e" w! A' h<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
" t9 V% o" T! l( O% M#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) " |9 s' I) q/ C0 i. W
{ / u8 ~0 C) n2 p  H* T
sound(440); 1 y% \' _! u& U7 i7 U9 S+ A
delay(500);
/ x. h# b3 ~! Q( Y$ R( @0 F$ Mnosound(); </FONT></P><><FONT color=#0000ff>return 0; 4 X1 I! `6 t# S* ]7 B
} , L3 z' c" j- z& p* o4 l& |) h; ?
1 v4 T* Z7 W9 G1 Y" N4 O5 u
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>: u, T- }- H$ K
功 能: 在文本窗口中删去一行   Y+ ]# p7 z7 {* A& ]( J' E$ [
用 法: void delline(void); + u# v! Q- F& y
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
5 N5 c5 j" E$ ]3 B, z3 y{
8 Q1 L! |' h- Gclrscr();
3 G4 H* n/ I; e5 dcprintf("The function DELLINE deletes \
6 P# q) D& y/ ?the line containing the\r\n");
  `- l$ v* d7 ?0 P, o  m8 a6 _cprintf("cursor and moves all lines \ ( Z7 N# l1 I! ~
below it one line up.\r\n");
. L8 ]/ @4 p) F+ C, ~7 pcprintf("DELLINE operates within the \
+ R5 L8 [- T9 h( I/ P2 dcurrently active text\r\n");
' j5 J, p# A% K8 K. Ucprintf("window. Press any key to \ . f2 s. a$ d; h* Q3 _- [0 g
continue . . ."); , q$ w0 a  g# ]5 ~* ]8 j
gotoxy(1,2); /* Move the cursor to the 9 S# S  i5 C: N/ U4 p  B
second line and first column */
, a0 n# a0 {; T# Y7 H& C" m1 [getch(); </FONT></P><><FONT color=#0000ff>delline(); ) \8 H5 H5 X$ T* \7 j. G* [% D2 \0 ^" @
getch(); </FONT></P><><FONT color=#0000ff>return 0; 1 M" [: p% v, H5 c: I( }. o
} </FONT>+ C/ x2 F' s) `4 ^/ ~
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>5 t% N; C6 e# e* M9 T& L- y# |5 a
功 能: 通过检测硬件确定图形驱动程序和模式
" c/ S$ n7 D7 h0 M用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
% a" s; e5 M" u0 R2 ]# `5 L( [+ B程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>0 @3 M- d6 L6 T8 A2 g) {
#include <STDLIB.H>3 k$ l% y  o, m+ x8 e- t
#include <STDIO.H>5 J3 a& T% m6 d  ~& C: N4 B3 W
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
/ W3 X! {6 Q0 C! X6 p7 hchar *dname[] = { "requests detection", " `' H; t. g+ F" M  m3 H/ B% O, F* o
"a CGA", , X& P* B+ R9 k
"an MCGA", # e# ^5 D4 ]' H% P
"an EGA", 2 e- _! _) q5 ]% E0 k' S
"a 64K EGA",
+ C+ p2 Z( M$ i"a monochrome EGA", # q, Y4 o% {  }2 |. u! s
"an IBM 8514", & V4 M( J/ g1 Y2 O% _
"a Hercules monochrome", " S' ^) }: d6 s2 G. k! ^9 j
"an AT&amp;T 6300 PC",
" I# a4 m5 y1 g! `; j/ s. s. n"a VGA",
% b7 i% C. L, a2 ], G( e"an IBM 3270 PC" . y2 d9 T6 P5 @7 w2 a) M
}; </FONT></P><><FONT color=#0000ff>int main(void)
: e" Y! c- e$ L; C3 _0 u% o{ . K. j4 E) i3 F' E) \: O
/* returns detected hardware info. */ ) I4 J, E& L& b
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ ; O: ?- ]9 U1 j/ |2 M
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ ; O% c6 V/ j. {: v( _* q
errorcode = graphresult(); ' z) O# D; W$ H- C. E  r0 V
if (errorcode != grOk) /* an error 5 {0 X/ ]! a! x& i: x, q
occurred */
, g  ~. y, B+ \, ]1 O: m4 k2 o{ ; ?7 i* K2 q: G# F7 k+ a  J3 Y
printf("Graphics error: %s\n", \
2 O1 }0 A4 d9 D7 lgrapherrormsg(errorcode)); & b3 ]: b; t% r) i. o# Y% @
printf("ress any key to halt:");
1 L- J4 v  p" d* J5 b$ j& `getch(); 4 N$ w; }3 C, H; Y
exit(1); /* terminate with an error
, w" K) G. v4 ]* D% W. ^" jcode */
3 J9 o# t+ p3 e6 _3 f0 n$ a' g} </FONT></P><><FONT color=#0000ff>/* display the information detected */ 5 F8 }' `. h) D8 n4 l5 P
clrscr();
; O9 u2 s  f5 C, b1 f' s' Wprintf("You have %s video display \ , {4 w9 w, a4 q+ r  b
card.\n", dname[gdriver]); 1 }0 k* ~# ]' u1 A  G
printf("ress any key to halt:");
3 U3 y9 G6 ~* P; Q% d/ u0 C! @7 e" hgetch(); 2 r( T8 k1 W: Q( [8 ~5 B
return 0;
& y# u  ^: a& I8 q; {  r} </FONT>$ f1 ^/ v" {6 P! K
, s2 w$ D7 g/ L6 n: u  p
/ w# t: R; Z; w; A7 |
</P><><FONT color=#ff0000>函数名: difftime </FONT>2 ^' _5 T3 J" S. a$ m
功 能: 计算两个时刻之间的时间差
2 I9 t) ^1 Z* H9 ?, m用 法: double difftime(time_t time2, time_t time1); 5 Z2 h3 B6 S# W! g6 v
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
7 T& `- E0 F3 n: B5 F( f* ]#include <STDIO.H>. J+ f  I7 [$ t2 f' r
#include <DOS.H>7 i3 I1 B% g3 w6 `' U7 e8 r
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) , m3 ]8 ~* p, P* x& R
{ 7 [; N8 `1 c! S& D& Q
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
5 N) U' x% a5 f7 `# hfirst = time(NULL); /* Gets system 6 S6 D3 X+ T# `5 c" `! j9 @% P
time */
4 w4 A  ?  f' V/ ], O8 L: zdelay(2000); /* Waits 2 secs */
9 E3 M, e0 D' {/ `0 l4 \+ v1 Isecond = time(NULL); /* Gets system time - G# d6 A( |$ l& U
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
" ]8 F* n0 |3 n- Z' X( Bseconds\n",difftime(second,first));
  k+ T3 r8 h3 jgetch(); </FONT></P><><FONT color=#0000ff>return 0; 0 U4 _) r# b& P& v
} ; q( ]" I, `: k$ \( H( L* T8 b
</FONT>  E4 ?8 \. R0 o7 b- [
</P><><FONT color=#ff0000>函数名: disable </FONT>; T% A3 w& f$ H$ z. d
功 能: 屏蔽中断
' ?9 R) y0 `3 l" J用 法: void disable(void); & ^' V6 w" e" _/ b' S. w9 @
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
% W" x' x6 Z4 m1 E& oroutine. You cannot compile this program / E. Z. A" I. L
with Test Stack Overflow turned on and - [5 x4 P, A# X
get an executable file that operates 3 y9 l$ n' x- ^: _1 S! b) j' S7 D
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>- L# \' A7 L; [& `8 G5 \
#include <DOS.H>
. `" u% k2 k) B3 G3 E0 e$ n0 s#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
9 R4 O% q4 T( A( B# L% R  ~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)
8 b& g/ R4 B" k; G" \{ 7 F8 t) |& D! f' ~6 \; |6 D4 o" p
/* disable interrupts during the handling of
. S$ y0 r( o6 X- g0 L3 h4 j8 D0 B% Fthe interrupt */
8 m% Y# Q5 p# X9 mdisable();   ^* u2 V* y+ m$ Z6 O, R' o  @/ Z/ y
/* increase the global counter */
! J+ W, j& H1 ^count++;
8 j1 Q4 W7 U! Q! c4 @" P2 Z3 Y. {, O/* reenable interrupts at the end of the
' t; F& h) @3 h# o) a& q5 y5 Shandler */
* b! Q  o. y6 G6 g3 M# R, I( nenable();
4 n8 p) C$ p: U' L/* call the old routine */ 2 C3 L7 [2 g" V( \8 p1 {4 U9 l, g
oldhandler();
0 t% s8 v$ Q7 q6 H} </FONT></P><P><FONT color=#0000ff>int main(void) # x! _$ r& l% c4 S0 i  F+ s
{
6 q9 x0 |5 b" g% Y" t/* save the old interrupt vector */ # C/ C; k2 F! d  l/ ^
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
2 T5 d0 Q4 L: I, n1 Ssetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
. k- C, C& I2 V1 q# k' Q& q' @3 r% Hwhile (count &lt; 20) & @* E/ a, e. M, t- S  [9 H- t8 o/ l# I
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
' y3 p8 A4 S/ Zsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; : _1 a; y- R$ _' |+ x$ @
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
* H( S' A/ h6 R1 a5 G功 能: 将两个整数相除, 返回商和余数 $ s; M6 z; A" V9 q$ l: @! a# @
用 法: div_t (int number, int denom);
  O9 |! @$ |& k, t0 C& l* k程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>. e" M; J( ~3 E3 \& j- U4 j
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
2 t+ e0 o# _3 |. O{ 9 R6 s8 Y& o' E; R, S
x = div(10,3);
2 \$ K0 G8 z2 Bprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; - F7 j+ L$ e, o' P
}
9 q. J5 B# O" u5 w# ^</FONT>
& _$ n2 y+ E) h  N7 V2 e( P</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
4 I% ~- \1 }# k! `# n  V) k功 能: 获取扩展DOS错误信息
, T- l2 k7 I4 h+ F+ q4 r* c5 [6 z. V用 法: int dosexterr(struct DOSERR *dblkp);
  M$ ^% Z- Q  m0 `: h5 X5 A+ }程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>5 `& u$ u) U% ]- U; W
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)   O' z2 {6 O$ a4 j8 e+ o; x; h3 v
{
3 B$ ^! m* c% R8 MFILE *fp; 9 Y) E/ S5 Z1 }5 \6 Q) D& ^' \4 Y
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); $ E4 }6 B' y+ J; M4 n3 h1 A8 J8 n
if (!fp) perror("Unable to open file for + T( r3 j+ p6 x, {0 E
reading"); ' G: G3 F3 D1 G8 c2 t3 e
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ 9 z6 {. y! L6 e/ U- p. W
information:\n");
2 P1 h! \. v! Y3 O+ Zprintf(" Extended error: \
! y$ m9 @- F( w* h" P" x8 {%d\n",info.exterror); , q" W- R0 l* n* y8 O% t  v
printf(" Class: \ 1 \  z! j/ S" K; n* f' c' O
%x\n",info.class);
/ I0 X% K9 t  N& X) h- n3 J" yprintf(" Action: \
3 J; f; e9 W, F7 l: K%x\n",info.action);
# }+ w% D- Q1 ^! L# qprintf(" Error Locus: \
- z  R4 n3 [$ C( Y%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
1 j0 y9 ~4 d/ x6 `} </FONT>
0 S/ J7 ]" k) o: p
7 `9 o4 S; n+ V4 E; a5 ]</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
* X! H0 m1 E0 _$ g: P6 N功 能: 转换日期和时间为UNIX时间格式
' {6 L4 U3 O6 A& _4 _$ A: }用 法: long dostounix(struct date *dateptr, struct time *timeptr);
5 m5 T$ M7 Y# f" _' ~5 x3 n5 m$ o程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
4 W- e% P/ g& T8 t#include <STDDEF.H>" j  u0 H+ o7 l2 o
#include <DOS.H>+ l! z8 Q7 Q# s) a% t; n
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) ' K9 y2 m; }5 @9 y. r/ J& f5 @) c9 z
{
- L& r* w7 U- z- etime_t t; ( l  S0 ?' P5 S/ F, ?0 W
struct time d_time;
# o2 b. c# z$ M& P! a0 Ustruct date d_date;
. I0 B# w* L% c4 Ostruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); 7 l/ V0 x' _7 T  Z3 \/ `
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
3 D8 O( m  K$ G) s: m& G4 Zlocal = localtime(&amp;t);
$ L- x7 N9 S# r0 ~8 Pprintf("Time and Date: %s\n", \ . Z# i$ q9 P9 Y& q/ A1 ?# @3 M
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; + P1 J7 S4 ]3 t  k9 K' r6 a
} </FONT>+ ~* [% v- ?& |9 D9 e
5 a7 R8 T0 W& D: S& n, R
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>' N; s# s% j9 b0 w+ r# {$ H
功 能: 画多边形 ; S/ \$ P% [8 t6 u( _
用 法: void far drawpoly(int numpoints, int far *polypoints);
& z4 s5 W( F% G: {! T7 r/ z, k程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>; m) M3 G) V: `- h& T. ]6 M
#include <STDLIB.H>( B+ N  x6 {! w2 F5 g
#include <STDIO.H>
; K6 M1 C+ Q  s& i# ]% M#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
: ?  ]& x4 C+ g- d; v" p8 H# z{
/ W, w* v% U8 }/* request auto detection */ * a5 T3 ~. x# ~
int gdriver = DETECT, gmode, errorcode; + ^" f' w' g2 S) L% X0 w
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ ' Q3 ~/ H0 v$ P4 y! O* B
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local * u$ g) ^  c! v9 o8 n
variables */
" {1 G  H7 f  f+ _" c# Qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ - x6 }" ~; Y$ ]8 C! K4 R, n3 g
errorcode = graphresult();
6 C4 a3 A% A# p0 N' P0 j, Y( Jif (errorcode != grOk) $ l) D5 e$ q5 c# j1 B/ V
/* an error occurred */ 3 x$ e. x! U$ \3 A
{ # Y2 f. @/ t% t. ^4 M7 B; a- Z
printf("Graphics error: %s\n", \
1 w) E* G* M, t# n3 @2 Q! Zgrapherrormsg(errorcode));
4 p' }5 l, j( t( u+ J- \printf("Press any key to halt:");
! }: l, a& q; jgetch(); - |7 t5 O, {3 W1 \3 }; {
/* terminate with an error code */
+ J% `  n4 H) e3 ~exit(1); : a) ]7 N. M5 r
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); 8 x3 P# H$ o4 Y; Q6 H
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
" N7 Q2 C! I8 A0 f4 w/ Bpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 6 B0 d# k/ O/ T5 u1 V7 ]3 r
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ 7 @2 L: t+ y' j. M
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
$ h. w: J* j* n- t8 P+ @" n9 F9 ipoly[7] = maxy / 2; . `' T0 a- [1 P- L# p
/*
7 e9 F" Z( [( xdrawpoly doesn't automatically close + M# x- T1 {6 a9 u  ]( T+ v
the polygon, so we close it. 7 S# B$ L( H, Y5 w. [9 X& W1 Q$ D
*/
6 r' X) s' ~2 ~9 ^# `  h0 u- Y) o) s& b: Dpoly[8] = poly[0];
! m9 F. Q2 F0 Wpoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ ( \1 k0 I0 e- x! [- k4 ]6 B4 C
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ # y2 P$ ^* t9 h# n. l+ |
getch(); , a1 n* O, k3 y1 n2 M
closegraph(); , ~8 @& ^$ T0 e
return 0;
6 O* f' B' K. ~. K: n} - h/ M8 d4 S& Z6 R5 P4 }, |& _
</FONT>
% ^  e  y! Y  ?' B; {9 U3 a3 M</P><P><FONT color=#ff0000>函数名: dup </FONT>; N8 |5 K6 L8 {% a: {. m7 N
功 能: 复制一个文件句柄 . ~# }3 M, I* `: }* B/ ~$ C
用 法: int dup(int handle);
( Z7 k9 \' Q% s2 D* x" @; W5 y. T程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
+ E7 ?1 Z+ b4 y& k* G$ h#include <STDIO.H>. T* t2 a" ?9 ^: l6 a) {2 K
#include <CONIO.H>0 V- A% R2 i- ~0 |3 ^% M
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) 9 \3 R: f& [- m1 ]5 }2 ]" `, ^
{
; _9 w: r/ P1 n, V0 ^. [' dFILE *fp; + F. ^' D5 j+ G2 s
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ " l+ D; D: `- W2 [8 k, y9 l, d
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ $ x$ Q/ q7 n! w2 s0 ~! E
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); : g  Y! w. y  k4 D4 {' t% X
printf("Press any key to flush \
' [" e2 U# C; t! p6 |+ EDUMMY.FIL:");
) X5 Q. B. ?# ?getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without ' E3 T- @( ]9 Q, M
closing it */ ! [- B2 a2 ^# {9 e/ d
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ & m: K& y' G: [) t
key to quit:"); ' L8 `3 ]6 @" w% v
getch(); 1 N) M- g) }: q
return 0; / U$ B7 g% l9 J7 B. F4 H  U
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
. q5 U* I1 C! Y; R{ ) q5 o2 \  I1 D! s4 h
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ , _( f' e9 g1 Y( u4 q$ ~
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
  H) p* F0 z1 k6 h& Z5 D- yduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
8 ^" f1 L( n. P9 {: W8 LDOS buffer */ 7 v5 \  V) u# [' p% U
close(duphandle);
4 g/ c  n! _0 @* x/ L7 b; _}
, C! L5 J4 T6 G" |6 P
  f) [) {7 x3 I  c1 j$ q  b</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
3 t0 P2 ^/ B+ H/ E8 Y. K功 能: 复制文件句柄
. y4 q# P2 P2 b* ~9 K  m用 法: int dup2(int oldhandle, int newhandle);
3 O5 w9 t4 i* U" X* p$ {# a( p程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
6 Q% L& K1 s' ]#include <STRING.H>3 c6 \' G; V# l( e8 o
#include <FCNTL.H>% V2 v% \% F: W) H$ [
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 0 f5 h! p  {$ E! E& I& n% M+ N
{
: n6 R6 \4 E+ h  a7 m& k7 I( ?#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; ) I7 [8 l' a. |
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
( |0 b3 W* U8 m: J) snul = open("DUMMY.FIL", O_CREAT | O_RDWR, : T. n' x- e+ s: v2 s
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard ; k) ?$ I: p3 k7 {
output */
& o, `7 `+ R" [4 x# i' Voldstdout = dup(STDOUT);
9 `$ M( q: Q& {/* 0 Q/ o/ U0 }& J$ W
redirect standard output to DUMMY.FIL / |& `1 n" {# O  H, @! [" Y9 g
by duplicating the file handle onto the 0 W2 r* `) k. M2 c" h/ L' n$ f
file handle for standard output.
* V4 A6 l: N3 x- q; s$ w; ?( }' \5 d*/
! P- ?- [; ^* \! z3 v1 g' ?# E# h2 tdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ & e/ J8 `. [+ K9 |+ P
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
  u9 w; x) Q0 m; _' X3 Twrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
5 k- v# H+ n' C0 A' ]handle */ 8 p3 Q5 W% }; i2 w. ?( z  a2 v
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ - j6 G1 b# H8 |, X+ V' u( A- c2 ?; I  |
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; " S0 _3 k% x7 w8 \/ x) X! Q
}
. U/ A# _, x3 J: d</FONT></P>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册地址

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 10:03 , Processed in 1.573534 second(s), 57 queries .

回顶部