QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2159|回复: 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>
+ O, ?% _" I9 K* z, r</P>
) _# p; t9 _/ B4 W2 [1 Q& X. e* X) l

' u% w& @* m/ h$ C( \4 ~* }& k2 v! ?<><FONT color=#ff0000>函数名: ecvt </FONT>2 }! G. ~4 o3 f/ p
功 能: 把一个浮点数转换为字符串 $ V5 y  c+ D2 [# E3 m7 m; N
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
. N/ c7 B" M* [& `程序例: </P>
3 @% z" e( \; E<><FONT color=#0000ff>#include <STDLIB.H>, ~' f( Z9 L+ M' `
#include <STDIO.H>" ^* M0 Z1 r0 S
#include <CONIO.H></FONT></P>
7 c% i4 F4 D! }<><FONT color=#0000ff>int main(void) 8 l3 ]7 E9 z  w' v3 ^# ~% p" D8 }) {
{ ! H: j0 ^( v$ s" ~$ C/ f
char *string;
; v6 h# y" ?& A$ s9 I+ ?double value;
7 S) Z# k  {. \, `int dec, sign; 6 L) |. K# e* N5 A. j0 y6 H
int ndig = 10; </FONT></P>& i, h1 g- Z" Z5 z4 @* e* i. J6 ]
<><FONT color=#0000ff>clrscr(); 3 P' z& A3 Y' g7 ?% W) F
value = 9.876;
; E/ r6 x8 t6 k: p- ostring = ecvt(value, ndig, &amp;dec, &amp;sign); 6 \- F+ d! B* m! _
printf("string = %s dec = %d \
2 }: M2 N! n% {) nsign = %d\n", string, dec, sign); </FONT></P>
, c' Y, C$ ]. Q9 P: y. b3 b<><FONT color=#0000ff>value = -123.45;
. A3 [, G# ?/ z9 c$ s3 |4 l# zndig= 15;
" k9 g- l( F, q( o7 r# q# ystring = ecvt(value,ndig,&amp;dec,&amp;sign); 2 e- v9 E$ @4 I- |, H
printf("string = %s dec = %d sign = %d\n", 7 r* v, M8 q+ Y. q4 F* l; }
string, dec, sign);
. m" C! Z" L3 ~/ O2 B& C& |  L2 e" h</FONT></P>( o  [" X7 n7 c4 G
<><FONT color=#0000ff>value = 0.6789e5; /* scientific # i) h, o5 i1 \' j" i
notation */
) r0 }0 {# S0 Z. dndig = 5; . n8 q( P3 ^3 K
string = ecvt(value,ndig,&amp;dec,&amp;sign); ) }$ v2 x8 j# T+ g7 C
printf("string = %s dec = %d\
6 Q1 v6 G4 w; E4 V! Lsign = %d\n", string, dec, sign); </FONT></P>$ s6 W' Q/ P. {+ c) @. r
<><FONT color=#0000ff>return 0;
9 _" e1 z4 T# L( Z' b! j3 F: B} </FONT>
/ Z% W8 g& M' x! z2 h* F# l& X' }, o* I
</P>
4 a4 h1 S5 _# |" v8 v" I/ w; i<><FONT color=#ff0000>函数名: ellipse </FONT>
' f6 d7 t: I. Q5 ^功 能: 画一椭圆
9 s/ [% Z0 N* J用 法: void far ellipse(int x, int y, int stangle, int endangle, * L" _) d/ y9 X0 M# R4 m) K
int xradius, int yradius); % W& ^; i+ G+ u  ?. S- ^
程序例: </P>! v1 n" N8 _: I$ E! I7 |8 x/ v
<><FONT color=#0000ff>#include <GRAPHICS.H>0 N* l' `8 Z! u4 k: b6 }/ W
#include <STDLIB.H>
8 j" d( [, t! R* D. A0 i+ a#include <STDIO.H>  p' l* k$ @' s$ p( r7 K# C9 b' ]
#include <CONIO.H></FONT></P>/ L4 n- M- Z! V) S4 @3 D
<><FONT color=#0000ff>int main(void) ! N1 f3 m$ W% R
{
' d+ O4 y  g1 A+ G3 y+ @/* request auto detection */ ; H. _) _8 a% ]  Z" ^( A
int gdriver = DETECT, gmode, errorcode; 7 ^1 |% f( g# c4 ~5 l
int midx, midy;
& E. U* s7 L* s/ t. }# o. Z4 y2 `int stangle = 0, endangle = 360; , x1 o6 |# U# m% q; H4 z! M2 ^4 N
int xradius = 100, yradius = 50; </FONT></P>* _' ?8 J2 Q9 n1 W: K- @( B9 D
<><FONT color=#0000ff>/* initialize graphics, local variables */ 7 `, J6 j* [% m2 P( O, ~* z, p
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
! V7 x: y# u! z  _<><FONT color=#0000ff>/* read result of initialization */
! \2 i+ Q. g# ?8 L, t' lerrorcode = graphresult(); 4 h% T! {) H% u3 r) e# l; [% p
if (errorcode != grOk) 7 A8 r: k/ |2 o# t, y% y9 b
/* an error occurred */ 2 A5 q' k3 d, \9 C) f9 z) K
{ ! u5 L; r) n0 `7 u% r
printf("Graphics error: %s\n",
+ m7 c3 }' v  P0 ^+ U# K9 hgrapherrormsg(errorcode));
0 G) z+ ?1 L- _) F* y! q6 {printf("ress any key to halt:");
" t5 @' L& t- r# k) s: B/ vgetch(); 9 l. p, ?, {( K2 E& M+ e* [# x9 g
exit(1);
- R: C6 M6 Y- H9 R9 L0 j# U: Q/* terminate with an error code */
- B; b5 [6 o) @  X* `} </FONT></P>
# _) G  V  K- R<><FONT color=#0000ff>midx = getmaxx() / 2; ; f2 n4 F% x0 a$ z- v- A0 H$ B. t0 X
midy = getmaxy() / 2;
. _2 e4 ]' @8 y9 s) csetcolor(getmaxcolor()); </FONT></P>
8 y6 n. W, t+ j<><FONT color=#0000ff>/* draw ellipse */ 2 g1 y' L5 l* ^  m7 d4 D6 [0 A. o
ellipse(midx, midy, stangle, endangle,
7 R5 K2 G/ {# |xradius, yradius); </FONT></P>
* \6 o& h* k. o" A" X0 G<><FONT color=#0000ff>/* clean up */ * d6 b8 l$ l) W0 h
getch(); & Z9 o# d8 d7 L% ]
closegraph();   W& m1 @$ m5 d5 g& O, A; o# d9 m
return 0;
6 u* [0 B& V! L0 j' H2 C) G} </FONT>: [' i3 j# z1 N# ]7 u
# `7 b; V' J- |5 u( {& e7 t
</P>
% G+ c  x- i  Q* M3 ?<><FONT color=#ff0000>函数名: enable </FONT>
/ k# m2 {+ p3 j7 r1 ~, \功 能: 开放硬件中断
% Q2 P9 W3 n; G+ q用 法: void enable(void); , `& {% c0 A1 |% N7 X+ Y
程序例: </P>
, d! w& P& F: K) [  }! S<><FONT color=#0000ff>/* ** NOTE:
& ]7 M6 g: Z; EThis is an interrupt service routine. You can NOT compile this program
( z8 O" D/ M1 ?3 c" [2 q: C. }! twith Test Stack Overflow turned on and get an executable file which will 6 r. u$ A; U& p' b
operate correctly.
+ z( P% [6 d* j$ {$ }. U( [*/ </FONT></P>
1 W( ]# |" t: h' l. o7 s: t<><FONT color=#0000ff>#include <STDIO.H>
: Z, r$ n  O4 Y$ r( o1 Q#include <DOS.H># A( m5 C* O% k& v
#include <CONIO.H></FONT></P>
( ]* y/ A; h; e) T' {7 i+ G# R<><FONT color=#0000ff>/* The clock tick interrupt */ - @  a2 h" Q7 k; N% N
#define INTR 0X1C </FONT></P>+ E- ~$ B  z; y7 R# s8 z  f% A* D
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
% ~! @* C9 L% O' A* }<><FONT color=#0000ff>int count=0; </FONT></P>  F& U1 |1 d6 w
<><FONT color=#0000ff>void interrupt handler(void) ( V# l4 B7 Q. v" v' e$ {0 H" {4 z
{
% o" c3 f; ~( _" F  O% @3 r! |/*
$ ~- ]) e: N3 Z% |disable interrupts during the handling of the interrupt
7 S% B+ h" t; L' u*/ 6 |" X* C' w5 U0 u2 H8 d
disable();
& k: j8 w/ U- `: g# q/* increase the global counter */ ; E+ P% @' L* ~0 S1 G
count++;
% e1 G, n1 e9 {3 S! m. w6 B/*
+ f/ w3 h3 D% @+ [9 L3 \9 mre enable interrupts at the end of the handler
$ }, ?+ K8 e5 F- N6 ~3 e. g: b/ N*/
; U* a% }" t7 `/ lenable();
: @  j: a/ V( X1 {/* call the old routine */ * ^% T% k8 p. ?5 `# S5 X
oldhandler(); % z+ a8 A: `6 g6 I2 v; j
} </FONT></P>
. K4 ^+ A1 m8 n2 ?$ O( g" M2 G<><FONT color=#0000ff>int main(void)
7 Y$ x7 ^: {$ r, R{
0 R2 Y) B+ H, k/* save the old interrupt vector */ * A% a0 n3 i# }+ u2 X0 A2 k1 o! d
oldhandler = getvect(INTR); </FONT></P>; O/ s' \# i& x8 n2 q
<><FONT color=#0000ff>/* install the new interrupt handler */
+ ], G, c* E0 i( ~4 C( `" `: fsetvect(INTR, handler); </FONT></P>/ m( K, J$ t- [& D" Z5 Y9 O
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
% X: U/ B4 `- q: L1 Awhile (count &lt; 20)
' U% h* r6 r$ v5 T$ K" r3 Aprintf("count is %d\n",count); </FONT></P>
  ~) z0 j- z/ |/ e: ^) B  w. g<><FONT color=#0000ff>/* reset the old interrupt handler */
9 y7 H& ?# P- Q; C. Nsetvect(INTR, oldhandler); </FONT></P>
0 k( O9 ?5 h$ R0 J6 \<><FONT color=#0000ff>return 0;
2 R* O# O  z/ @7 D: l' {' ~} </FONT>. ~) J3 f6 |/ R" q: k+ C( `/ N" B

. D" l9 \+ U' S3 Y- E. W9 t8 J. G</P>
$ k7 p/ n9 P. W, g/ K<><FONT color=#ff0000>函数名: eof </FONT>$ Q* Q1 P* N! q- z' t
功 能: 检测文件结束
# ?3 Y5 I0 S0 t用 法: int eof(int *handle);
. o' l/ u8 Y/ K" M# ?. |程序例: </P>9 X! r. b# C! R. F1 B: J1 U
<P><FONT color=#0000ff>#include <SYS\STAT.H>
( a) t9 r9 o* Q8 N- l7 ~6 s#include <STRING.H>
+ ~+ A4 }% Q) m3 J1 |7 t  y" C#include <STDIO.H># d5 p, |: v4 M/ ~  P# o
#include <FCNTL.H>
$ H+ g+ ~* c( ^( T& v#include <IO.H></FONT></P>
" J' f! ^" h$ W( [) y, o<P><FONT color=#0000ff>int main(void) ' Y4 C0 e. K5 i( E
{
/ Z" m5 |) d: J$ q1 `' eint handle; 0 U2 p6 Q+ {/ d. V
char msg[] = "This is a test"; 1 E" v. c9 p  o/ B* M
char ch; </FONT></P>- e2 @4 J( A6 ?5 d# Y) q0 P
<P><FONT color=#0000ff>/* create a file */
7 Q( O; P! x: w$ Nhandle = open("DUMMY.FIL",
8 x& c+ m6 v1 U+ `7 \  \O_CREAT | O_RDWR,
* Q7 _& A( `) b3 X5 |' ZS_IREAD | S_IWRITE); </FONT></P>( \1 l% x8 r" J, [
<P><FONT color=#0000ff>/* write some data to the file */
  a* m9 X4 @. M2 N$ gwrite(handle, msg, strlen(msg)); </FONT></P>
2 {$ v2 B* j9 _% I<P><FONT color=#0000ff>/* seek to the beginning of the file */
  g6 i% X1 }, i- v0 a; P- ]& s& Ilseek(handle, 0L, SEEK_SET); </FONT></P>
4 \0 o! V( z4 @2 w<P><FONT color=#0000ff>/*
# r, H, M. @; x- G. X% e. Hreads chars from the file until hit EOF 0 ^8 I2 T5 F; G
*/
  _0 Y3 `6 H, [: y3 Q6 ^: kdo   H4 {# a6 Z6 y& m; K, w/ Z
{
9 a4 C+ W) |" B2 P4 f& kread(handle, &amp;ch, 1);
& o; V8 R$ R) q3 U5 F! Fprintf("%c", ch);
4 X6 X& d7 h; J# K% b) l} while (!eof(handle)); </FONT></P>) t/ U% h8 x6 S
<P><FONT color=#0000ff>close(handle);
! B1 ?, D; {2 o. ]* ^return 0; 3 Z) U' ]6 N3 K4 I  ]
}
# @1 K* {: j1 f* \8 P</FONT>
6 ?) G; f; J5 }9 @</P>- C0 z8 i: U2 D9 `8 l$ v
<P><FONT color=#ff0000>函数名: exec... </FONT>! l" v( i) I8 A0 p( h& ?; p, Y. m7 ^
功 能: 装入并运行其它程序的函数
* J1 \6 c7 x/ L+ M  f/ R用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
2 r) q5 B3 A% d( dint execle(char *pathname, char *arg0, arg1, ..., argn, NULL, 5 Y$ w$ W! x  E- y5 Y
char *envp[]);
- e7 H1 f# @& Bint execlp(char *pathname, char *arg0, arg1, .., NULL); # N. z! m( B  q% [* r3 z* t. |
int execple(char *pathname, char *arg0, arg1, ..., NULL, : M5 F1 m5 M# O- A) A# j
char *envp[]); 0 n. N3 C9 F. W& M4 M) t, W& e
int execv(char *pathname, char *argv[]);
+ P. e/ [3 t2 k7 q3 D& gint execve(char *pathname, char *argv[], char *envp[]);
3 S' u( n: A2 uint execvp(char *pathname, char *argv[]); : q0 X, {3 n0 I% E4 s
int execvpe(char *pathname, char *argv[], char *envp[]); ! l: r/ z( B2 ]( X( ~5 V# z
程序例: </P>
9 o9 y2 N! [9 ?# G" H<P><FONT color=#0000ff>/* execv example */ , N& S+ T  V; ?: D  w
#include <PROCESS.H>
3 C3 @. g% V' u9 c+ {0 F* T) f#include <STDIO.H>0 s- M9 ^* ~0 ?5 C) V# p- _
#include <ERRNO.H></FONT></P># W; n( T4 v4 J* s8 W: O4 j7 T
<P><FONT color=#0000ff>void main(int argc, char *argv[])
9 J4 q( @( w, t1 z7 K{ ( ?  f4 p! ~* q8 c3 }
int i; </FONT></P>( A0 |. E0 P7 b+ R
<P><FONT color=#0000ff>printf("Command line arguments:\n");
( Z2 r: Q2 M! W( n" Ifor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>! K; t, b9 w) K  Y4 w3 \
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); ( s, Z4 z9 \5 |" l2 {" g% ^
execv("CHILD.EXE", argv); </FONT></P>$ ~  W( Z% y: u& n
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
/ ~- j) r- [: w' g1 D<P><FONT color=#0000ff>exit(1);
! m1 M- T5 `7 x1 c} ; u/ V( r* ]9 {+ l7 A) R0 J, C9 T
</FONT>, s+ G0 x: q7 f+ o8 _6 W
</P>' X# Q7 L' v; }9 @
<P><FONT color=#ff0000>函数名: exit </FONT>
7 y3 g; K# e$ ?3 \2 Z4 X$ \+ _功 能: 终止程序
0 W& G% f! h. j, @4 y) c用 法: void exit(int status); 1 j$ \  B4 _4 \
程序例: </P>
5 e$ i% Z, W' X% @<P><FONT color=#0000ff>#include <STDLIB.H>
. `8 h5 R( t- v# L; C: ?" ~#include <CONIO.H>5 T8 @7 c# g+ ]& k8 j: W: Q$ \: P
#include <STDIO.H></FONT></P>8 Z! W3 g! Y. P8 b6 M
<P><FONT color=#0000ff>int main(void)
! C7 e, D) C+ O) e{ , F/ `% R) F, i9 K+ N* Q3 J
int status; </FONT></P># C6 A3 D$ J; I% f* G$ y; e8 k
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
- u0 x( w% i+ J- g2 A& kstatus = getch(); % b  A( {/ o, y# p! J
/* Sets DOS errorlevel */ , D% _7 g. U4 E) p
exit(status - '0'); </FONT></P>. m% _* T1 z6 i
<P><FONT color=#0000ff>/* Note: this line is never reached */ # `& z1 b& D! l$ w
return 0; ' |! W5 a2 i! |' Q2 o
}
2 _3 r3 ?; l  M, o7 _9 a9 \</FONT>. y/ a4 W+ i# R3 T0 \: f$ \
</P>
* c- Z* e) a% I<P><FONT color=#ff0000>函数名: exp </FONT>
' a# s/ H' [3 V& I; _功 能: 指数函数 + I6 L: V- R5 e
用 法: double exp(double x);
6 i, q- U( ]' G+ r' o程序例: </P>- [! a9 E6 F+ ^) x7 t# T5 T
<P><FONT color=#0000ff>#include <STDIO.H>
- G1 r1 M3 Q( C+ Z) H#include <MATH.H></FONT></P>
, m+ D) Q  Z- G8 ]& r( D<P><FONT color=#0000ff>int main(void) : y: l' m- c0 {. I
{
. K" d4 R$ ~9 i2 D+ o* L6 D. Edouble result;
! Z5 ?3 I* ~9 P9 P2 _9 Q9 bdouble x = 4.0; </FONT></P>/ }% m( m! Z4 \4 J9 [! n
<P><FONT color=#0000ff>result = exp(x); " i2 o/ N/ |; E: H, N7 T
printf("'e' raised to the power \
0 t6 @6 ^3 ~& h. u' u) J4 |7 Cof %lf (e ^ %lf) = %lf\n",
) w/ `3 E! o6 q" Qx, x, result); </FONT></P>4 v/ y+ W$ J% t3 R, P, x- C
<P><FONT color=#0000ff>return 0; , K6 L6 B9 `0 B% V) x+ b
}9 N( @% I9 g' N1 A; @& U4 t
</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>. W4 K4 U1 r9 B  r- u/ F: C
</P>6 V% p9 s" s' B$ d) o8 z8 O
<p><><FONT color=#ff0000>函数名: delay </FONT>9 `) w5 t  y$ t5 J% \; J8 K  o
功 能: 将程序的执行暂停一段时间(毫秒)
1 R. H* J, J5 [用 法: void delay(unsigned milliseconds); ' g6 |7 l( E" F4 r( L5 e( i9 G: C' D
程序例: ( e+ c) U( i0 m. G- \, O4 y% a( b
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ 5 ~1 g- n+ N4 O8 F- I3 j& N
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) 7 M& w. a: n" Q" ~! }/ H
{
) z1 H; R# ?: U! c* `) Zsound(440); % q! x% N8 A% v3 u- K" d% K
delay(500); % @# J: R. w3 G: O' b+ L0 x7 G8 x
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
' Y/ `2 b6 }' w* ^* D4 F. N}
3 d, R. d0 [: h& E; h$ Y9 X/ A6 s' A
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>0 T$ o3 h& ~6 y9 s# M
功 能: 在文本窗口中删去一行
- c5 D3 T1 m% E7 s# K用 法: void delline(void);
6 z) I# H1 ^. [& D: S2 I程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) . a; ~  k/ D; @  p6 `# F5 T% p
{
7 t; h. R3 [8 [6 {9 z& Y& f! Y5 kclrscr();
4 Y6 |. w: j' U( ~) Ncprintf("The function DELLINE deletes \ " {- _! O9 ~8 Q/ C
the line containing the\r\n"); $ n1 _( `- O& N$ K
cprintf("cursor and moves all lines \ + @9 J. w9 P+ a! `, P
below it one line up.\r\n"); + x$ m2 b8 z) V6 Y- Q
cprintf("DELLINE operates within the \ * u6 D$ @$ T& w; z
currently active text\r\n");   {% I, @1 F& I
cprintf("window. Press any key to \ ) }+ P; b! @1 }3 O0 W9 i
continue . . ."); 0 P8 S0 Y9 m# ]4 D9 G! I9 Q6 q
gotoxy(1,2); /* Move the cursor to the
- g# `# Z  [6 _9 Y" V$ m* ^second line and first column */ & V+ a% G) ]7 p: U
getch(); </FONT></P><><FONT color=#0000ff>delline();
$ X4 w4 o$ F, C. l: m* I0 l" Pgetch(); </FONT></P><><FONT color=#0000ff>return 0; * C. L+ p4 p& Z- N
} </FONT>( @* L& a4 c* @
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>' \+ V: v3 o$ G
功 能: 通过检测硬件确定图形驱动程序和模式 1 ^. p) ?& C* Q4 k5 z
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
  t& `. B- I0 T程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>' z& u2 `. C5 X$ f: d" U+ \
#include <STDLIB.H>2 F7 z5 s, E6 k
#include <STDIO.H>+ R1 j8 C+ Z8 N1 r6 R% T) ?- u3 q6 M! ~
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
2 a# r+ G" `  t! P- {# q* @; Achar *dname[] = { "requests detection", 1 J2 y8 u- Q3 p1 e
"a CGA", ) ~9 Z, ^; i4 q! f: z" ^
"an MCGA", 1 K. A  p  S0 T, h) P/ }
"an EGA",
, z  t. l8 m. g# R/ k( p. K"a 64K EGA",
" ~, c* `: @: p0 Z"a monochrome EGA", 0 b: k- v/ M) X0 G7 g) C7 ^' p" L
"an IBM 8514", , z% M6 e- X4 b3 g8 F! q
"a Hercules monochrome", 0 E& d4 _" m$ z$ _
"an AT&amp;T 6300 PC", 6 r: W4 X3 S& \3 {! L$ f
"a VGA", 5 i% `5 i5 h- f9 Y, t* g
"an IBM 3270 PC"
/ w5 O" N$ d: Q1 m) M/ |}; </FONT></P><><FONT color=#0000ff>int main(void) : t! k% k: s: L4 B$ v, L
{
3 y1 i3 T4 t( L$ R$ e( a/* returns detected hardware info. */ 0 V$ Y5 k9 ?2 g) z+ g
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
! T# s3 g# r/ w6 y, I9 g; pdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
/ P3 u& \: `( \& o1 ^errorcode = graphresult();
( _  t0 P0 N8 ?2 E( v7 _- @! zif (errorcode != grOk) /* an error 3 Q7 \/ h# C, [" S% u
occurred */ $ F8 T. i8 ^$ S1 K* l% T# }" C
{
/ Z' |( L5 h  y8 Z: s: O6 Wprintf("Graphics error: %s\n", \
5 S, W8 {3 T$ _& I3 mgrapherrormsg(errorcode)); 5 f9 W. O) T4 g' ^& }. l; W
printf("ress any key to halt:"); ; j1 m5 {; k; b+ K5 y
getch();
5 e* |5 G# T% \" |exit(1); /* terminate with an error
5 E0 r% ^5 M5 @; C1 X) ucode */ 0 Z: K7 T& }+ k( q) f  i4 P; S! N- q
} </FONT></P><><FONT color=#0000ff>/* display the information detected */ : ~8 z' `( K' n$ T
clrscr();
6 o' D# z+ d, p2 Yprintf("You have %s video display \
; W2 B8 }+ W( ~2 S! lcard.\n", dname[gdriver]); 8 |# _- B3 x3 M. e' X
printf("ress any key to halt:"); ( D% y: ^$ _% @4 Y7 h9 O
getch(); + o. c+ d! G; d7 Z+ d
return 0;
) c+ F3 ?1 p% a3 u+ |& O7 H8 C} </FONT>9 h/ X; R' G+ ^! [: B

8 L/ f6 _9 X: F. B: H7 _# q. T" B& `
</P><><FONT color=#ff0000>函数名: difftime </FONT>& F6 {$ D+ J) H4 m) F/ \/ M' _
功 能: 计算两个时刻之间的时间差
8 D" H' c0 P: R用 法: double difftime(time_t time2, time_t time1); & e0 Y7 x7 q* M; {
程序例: </P><><FONT color=#0000ff>#include <TIME.H>; f5 C8 N# n' M6 o8 b8 Y
#include <STDIO.H>
4 C5 J% ?5 M* e% t" W! y/ X# |" L#include <DOS.H>
$ P! m  U4 F; B4 N- f5 J( Y#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
7 c% ?# M/ |/ U/ [9 }; D6 a{ ; ?- i/ T) t( Q1 L# ]" U( h( h+ J
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
2 U0 f9 G- b7 ?+ bfirst = time(NULL); /* Gets system ( G1 B  a  O; O1 D% \/ i& V5 T
time */ , N- w6 D+ k2 e& I& r, e- E- r
delay(2000); /* Waits 2 secs */ : c. D7 k) S& v. j# I3 j
second = time(NULL); /* Gets system time
& @( O8 W, q7 O) P/ nagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ 4 w  `+ _! C% b7 ^9 t5 U- X
seconds\n",difftime(second,first));
; R$ W4 c+ |9 n" v6 Ggetch(); </FONT></P><><FONT color=#0000ff>return 0; 6 f0 v% d. [6 F3 s* W
} 0 |5 @2 }/ \4 l: d; _8 k0 v. L
</FONT>
) I( A7 b( e% [* T" P* w8 V</P><><FONT color=#ff0000>函数名: disable </FONT>
- ^5 r3 Q, I% V  Q! N6 B9 @功 能: 屏蔽中断 ; v/ O6 k+ \% Y  {# G
用 法: void disable(void);
$ {$ K- g: E( q& G0 U, O程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service : K+ N# l! f0 F4 p8 o/ R
routine. You cannot compile this program : S+ {; s' s) Z3 |" d% h7 ?1 b$ @
with Test Stack Overflow turned on and
' @6 n4 z6 |/ e$ Cget an executable file that operates
, ^$ L" y" i2 G/ vcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>. C. [0 U, u; `" J
#include <DOS.H>
$ f3 }( |8 D6 T$ B& ]  l0 B) y. L; I2 E#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick 4 F) }' B4 @  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)
- g& q  [( G+ o, C{
0 ]" l4 N4 X* v$ c/* disable interrupts during the handling of 9 N) r' I+ e1 P2 z" }$ c: E5 r
the interrupt */ & Z. x" [1 Y  H: k: O& J! [7 f
disable();
5 H% A4 {7 U( n3 I6 [; ~5 l/* increase the global counter */ 5 W1 V+ y) C& ]( [/ N& `/ V
count++;
: x) t, B: M* y: Y/* reenable interrupts at the end of the
$ C  S2 w! \4 ~0 [) n% v1 Jhandler */ & Z0 ?, s4 A9 t# v) z7 U! v
enable(); % i, X, ?7 i% P$ l* M
/* call the old routine */ # E9 E; `( X& C4 h( I
oldhandler();
- f* R7 D9 h0 x& U" _0 Z8 Y7 R} </FONT></P><P><FONT color=#0000ff>int main(void)
% I: R+ I& z& r: M# a# `{
8 d) X0 L5 m, Y$ R4 p( m. r/* save the old interrupt vector */ 4 b* Z8 A# d: i( R& u+ ^8 y
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
$ I$ I5 i6 ]! Y2 ^- [- B4 w, nsetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ ! H' t' {- \& |& e& |3 F: A
while (count &lt; 20)
# J- L3 W9 v& g& hprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ ! F; q7 M4 O: Y* g+ N
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; , a1 B4 [3 h. p' D) L
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
7 U% h% M" J& ?/ x: T, g) }功 能: 将两个整数相除, 返回商和余数 1 U; P* F" x8 E8 a% r
用 法: div_t (int number, int denom); 8 b* V9 [/ f, u' [5 N
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>; h( }/ e5 |' S1 R( M
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) - Z( I( f" l3 n: P
{ $ }, H2 t9 k' h. w( ]
x = div(10,3); " a1 G* f- C0 @# t3 d- l
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
! n# q1 S7 h' w}
/ e( D* E1 n' j# p</FONT>
) N* `: c: Q' T: C% o8 j+ l1 D</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
8 G( X. K2 C$ v- R( x( `功 能: 获取扩展DOS错误信息 , S2 H: f3 \* {2 |' T
用 法: int dosexterr(struct DOSERR *dblkp);
, p5 V: E, `; e* z" ^# o7 o程序例: </P><P><FONT color=#0000ff>#include <STDIO.H># M3 n( t' P5 F
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) 4 S& W8 K' x6 J+ l) ]
{ * L( b: ^+ D$ N8 d+ M2 i1 S
FILE *fp; . y/ v, j3 X$ L
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); : m% d, P1 {% Z7 |3 M. C" J$ c% k
if (!fp) perror("Unable to open file for
3 K! z, {% G+ ireading"); 0 E" ?# A" B; Z
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ # }6 c# _% ~3 _$ A& C
information:\n");
5 O- D2 z! [, s6 w, bprintf(" Extended error: \
7 i- {; b6 B1 c9 S0 W; R. j! Q! A, V& `%d\n",info.exterror);
& a; w  F  }+ L2 o* nprintf(" Class: \ % M: e- n' F- J. g) w# H
%x\n",info.class);
- z$ ~- J/ [7 T# d. q0 i( y4 J9 Xprintf(" Action: \
8 A" M; @* V; p, d4 b%x\n",info.action); ! p2 u6 i5 K8 l9 F; I
printf(" Error Locus: \ 8 F- n0 k4 t9 l& M
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
9 j) K6 l- g" I# Q} </FONT>% @* A" c* ]; ~( j( K3 Q3 }

/ i3 i* O, ]  x# \" x</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
' i3 N3 b0 {: Y3 n( W/ ?功 能: 转换日期和时间为UNIX时间格式
8 Q% W8 Y# j. b: j% q用 法: long dostounix(struct date *dateptr, struct time *timeptr); 9 g! s/ i* Z+ d. `, j# a& I& f
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>0 {" J3 \4 D' O" T& _) e
#include <STDDEF.H>+ P5 H! b+ t) j( E& J
#include <DOS.H>
1 y( X, ~9 l% M9 ^- h) S#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) . a! E/ X  e  T0 _) J
{   p" `( ?; K3 a! o! S. Q0 R
time_t t;
! Y$ Q- I! I" s& hstruct time d_time; & X$ }6 X2 J- J8 ?) f$ n5 u
struct date d_date;
6 ?% [: o# z2 kstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); 5 p2 t9 V: b7 I/ L! p
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); , P# o5 S" f5 K/ F& p
local = localtime(&amp;t); 9 ]4 V$ X. }2 |9 M! ^) m3 Q6 n
printf("Time and Date: %s\n", \
$ r. B* e9 ?( I6 Y+ D8 n: M5 R% n3 basctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
* t% k+ {2 v4 O; H% b# C5 C} </FONT>
: x; e4 `; U/ M( u5 ^! W6 s+ W' v8 \0 c1 _
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
8 z" T" Z5 K* o* t1 a功 能: 画多边形
1 \- ]* N: @6 A3 D用 法: void far drawpoly(int numpoints, int far *polypoints); " S; X0 h, @# `9 Y$ H% |/ C
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
* q1 O  A' E& H2 e4 y#include <STDLIB.H>
- Y% L- {2 m2 l5 r( r#include <STDIO.H>
, D3 C# d! A( s' Y& @' B* ]#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) & g  e- R8 }1 Z/ P
{ 6 u: b! v- A/ Y5 i6 g) O' x
/* request auto detection */
" [  o3 H2 ^! ?. I0 U, aint gdriver = DETECT, gmode, errorcode; - p% Z0 ^# b4 f. S: @: q. G
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
) p1 D/ R6 W: P5 E2 pint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local & f2 e4 u9 L& h
variables */
! G! N! I9 A- q& {- R- T5 Tinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
/ ~/ F  Z! I1 }4 C& H( l4 |errorcode = graphresult(); # w# x4 {$ c- Q0 h
if (errorcode != grOk)
# |* y. H% [2 _7 e( X' z) b/* an error occurred */ 9 t9 E# v. v# g" s5 c' o5 {+ Q
{ $ ^) U2 w6 `3 i8 w
printf("Graphics error: %s\n", \ 0 M: k7 D& Q! r+ F7 X) A3 @1 r
grapherrormsg(errorcode)); ! ^2 v2 ]4 M# L" `1 A9 M" u
printf("Press any key to halt:");
, |* L7 c, D0 H; M: H4 ygetch();
! T# ]/ |1 U  ?$ h' H% ?/* terminate with an error code */
6 i2 Z: e; L$ S9 Wexit(1); 5 G2 B2 A+ Z- w8 D* w9 P
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); ; Z3 `/ ^1 c2 |# o& p
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
, A: B5 J2 `! Lpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
- ]1 G# M2 }! Z! A5 ?& Q2 ~8 Tpoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ 1 @: p9 {5 b! ~  b/ B2 s
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ 1 m9 V( v1 k; A
poly[7] = maxy / 2; $ o* R. l4 T$ l
/* # j, }  Z. H5 v5 J! k  n; I
drawpoly doesn't automatically close " R) V3 y6 `/ S
the polygon, so we close it. - ?! X0 L2 l" d$ O. r
*/ * v8 J! W& M! i* N
poly[8] = poly[0]; % B, G. y2 Q" I( ?5 J* M! B7 H
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ , N/ b4 E1 p9 D; l; [4 Z3 f. x& _! d
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ / t8 c" g6 [) A( t9 e' M2 t" h
getch();
; u; c+ t, k5 H* D& d% u7 }/ e( W6 lclosegraph();
. N3 S8 y1 H& D9 x: creturn 0;
) }8 \8 n( j. c}
# a9 k) s/ r8 c1 G</FONT>
+ _% {. N* i' n) c8 H* f! {! P& r</P><P><FONT color=#ff0000>函数名: dup </FONT>
( b9 t1 Q- h) h3 [- j, O! u$ S功 能: 复制一个文件句柄
/ ]9 a1 Z  N, K用 法: int dup(int handle); 7 |9 O6 H9 B5 x
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
  E" T' `% s0 A1 k- P, w#include <STDIO.H>
, C" \4 ^+ M7 ~6 V; G0 N! y#include <CONIO.H>
2 a$ r' u' y$ `# H5 A#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
; J9 z/ C( d. Z0 n& C{
: R8 r% ~* B# s) x6 [, z" EFILE *fp; 4 i) y/ }( O) G- z; E9 z: t6 h
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 0 N3 E" E0 ]# B# a
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ 9 W: {# A2 O3 q6 w
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 4 y- s) F9 V6 i7 }0 {0 e( I$ J  y
printf("Press any key to flush \
* N1 _6 {" Q5 ~/ R* v7 DDUMMY.FIL:"); % {8 \4 v7 d* ~6 ]4 |0 C
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
% B( E( @# @% A! Q! F; wclosing it */ ) o) f/ p* B6 e, {4 z' Y
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ 7 n- O' y6 J4 t
key to quit:"); . J& c' K6 i; c( V/ [1 l4 B  T
getch(); 1 o. [' L# x5 ^. A; I3 f
return 0; 6 u7 {* U) Q% M1 g, y: c+ Y
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
- y* E' a" G* \$ R; z{
# x2 s" k, }" h' _. V5 q3 Gint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
8 y: ~, i) \# n% |, P3 p- Vfflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ ( X2 Q7 u$ P, {- o/ v4 g4 v* {
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
, V' ]6 P1 I# BDOS buffer */ , J" d; S* E0 j2 a
close(duphandle); 4 _# n9 ~  s) A! ^0 e, i
} : N8 M, V& M; D  W2 t$ v

; f) l+ S3 ]8 Q3 s</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
3 {2 Q: G3 O9 [* m# u功 能: 复制文件句柄 2 R! ]# H5 L3 Y3 B/ Y
用 法: int dup2(int oldhandle, int newhandle);
7 p' n3 T. `7 w7 ^2 V程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
3 \3 o6 K3 C) c7 a. z+ \6 a) n# }#include <STRING.H>
0 i$ |5 T. o7 \( t) ?5 B#include <FCNTL.H>9 g7 k% M+ \1 y& Z* t0 r
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
* I" B  d" B/ P* t: I{
4 M' L2 @3 n- a* s; }  o#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; ! Y8 i# ]# ~" z( r9 }2 |
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ " y9 m  O* E+ E$ `& L) g
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
' g' r  A) k6 i4 C$ R# RS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard ! f' H+ d% Q8 M3 g% V
output */ / ^% X" l3 O8 t: Q
oldstdout = dup(STDOUT);
' d' r/ t& @! k, ~! f/* ' _- t' O( q/ s: S* [
redirect standard output to DUMMY.FIL   K. h; _$ T: u3 O& B
by duplicating the file handle onto the
! F% l- S' {: A6 Vfile handle for standard output. / n5 H$ `: S& M3 B$ M3 |
*/
) p  V7 A! C# s; r( s/ z& }0 pdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ 4 Z& h$ W! D5 L/ D9 i
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
/ O6 s* Y: \1 T% D) i. awrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
2 }2 ^# Y$ r, T0 C7 d' h* O3 ?handle */
$ j+ J4 w! v; s; w# pdup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
) Y) t$ i! v# \* C& q7 U- ?close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
" w8 g! S: s& I0 D} # a0 n& u/ |3 {! J( @& }7 g
</FONT></P>
回复

使用道具 举报

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

fastpost qq
收缩
  • 电话咨询

  • 04714969085

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-31 21:09 , Processed in 0.277909 second(s), 62 queries .

回顶部