QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2057|回复: 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>
4 T0 Q# V, S0 [; p% B8 S- T' h</P>
0 Z! y3 ~! s# ?$ F& r- F) Z
# `" B( p$ h2 t5 Q, B7 m1 H. }' }2 D8 r3 `- R
<><FONT color=#ff0000>函数名: ecvt </FONT>+ U" G. ?/ k+ w6 D
功 能: 把一个浮点数转换为字符串
1 ]( y* S6 d1 h8 x用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
) I0 x# L+ D  j. A# f程序例: </P>
9 s0 Z$ J' W. v8 D* H<><FONT color=#0000ff>#include <STDLIB.H>
0 m5 P2 D* k' {8 s#include <STDIO.H>
6 M+ Q) W% {1 K4 ?$ j#include <CONIO.H></FONT></P>+ V; |6 H5 u, Z$ g4 F
<><FONT color=#0000ff>int main(void)
- i1 H' k0 k4 i  {5 J! h{
4 v6 A" _8 [- g. ^& dchar *string;
; ^: p1 U7 g  P% \$ t" {' n- [double value; ) G0 L1 V) ]+ G* Q
int dec, sign;
2 q- Y0 Z* p$ d$ J. {4 o, J# _int ndig = 10; </FONT></P>
; P5 i0 m8 V- @+ z! s; `$ L<><FONT color=#0000ff>clrscr();
/ ~0 U0 g/ R  z$ K) J; D- cvalue = 9.876;
# A: K- j& e- b% nstring = ecvt(value, ndig, &amp;dec, &amp;sign);
' q0 ?" p$ q9 j+ `3 }! T7 Zprintf("string = %s dec = %d \ 3 U' k  S2 \5 i+ a: V# C: m. h
sign = %d\n", string, dec, sign); </FONT></P>) m$ A0 F2 Q# p1 J( _
<><FONT color=#0000ff>value = -123.45; 1 r; X0 Y" L( D$ E3 W5 W
ndig= 15; 4 ]- |8 u5 X7 c  i- l: D
string = ecvt(value,ndig,&amp;dec,&amp;sign); ( \2 O1 V8 i" E: J+ B4 y% q4 a
printf("string = %s dec = %d sign = %d\n", / y! j" L: t8 x! a* C; ~- J
string, dec, sign); 2 y  k; M! t* k& u0 j# a
</FONT></P>
8 J/ b6 r; ~' c" e7 @<><FONT color=#0000ff>value = 0.6789e5; /* scientific
% b  ?, N) @% m2 znotation */
( G! ]/ W: x5 v: W) n; n+ jndig = 5; . b1 z6 i9 J& ~
string = ecvt(value,ndig,&amp;dec,&amp;sign); 7 S( e6 P8 f$ ]4 u& U, W
printf("string = %s dec = %d\ 8 a' M1 @- }0 n% q7 Z" N
sign = %d\n", string, dec, sign); </FONT></P>
) l( Y; F. A( `* d<><FONT color=#0000ff>return 0;
1 l% i  t6 r% D) a$ X( {- u! z} </FONT>1 C5 m' a4 h5 `8 i, N
2 ?( \+ c5 ~7 U- o# i2 i4 r
</P>& Y* J: q" |" U1 {$ _
<><FONT color=#ff0000>函数名: ellipse </FONT>+ T) _9 L4 `6 U3 B& ]9 F" z
功 能: 画一椭圆 0 e& {7 m" M# }. ]3 `; c  j
用 法: void far ellipse(int x, int y, int stangle, int endangle, * U% u7 h: F0 J
int xradius, int yradius); 1 i1 W* q: K2 q6 C" a3 m( V( Z
程序例: </P>
* s0 n; x+ `, Z<><FONT color=#0000ff>#include <GRAPHICS.H>
& [8 F: N: j! b; B, b#include <STDLIB.H>
! G" o' T+ [, A#include <STDIO.H>
! b" B% p, C+ m8 m1 V#include <CONIO.H></FONT></P>2 K: c6 q* A% k, _9 x
<><FONT color=#0000ff>int main(void)
5 G% d: Y5 _# M6 y. s0 \  x1 o{ % H* n3 T. F$ \1 J% Z7 p; R0 A. T
/* request auto detection */ # T( p* B/ T! g! {7 x  q* t
int gdriver = DETECT, gmode, errorcode; $ x" T3 r: g& v0 y9 w' W
int midx, midy; 8 v2 N& s. H5 C% C
int stangle = 0, endangle = 360; / W( Z3 @; n; U  h: B/ {& G
int xradius = 100, yradius = 50; </FONT></P>
% i4 {/ D( J" _# R<><FONT color=#0000ff>/* initialize graphics, local variables */ 1 B' T( B# x- X* U
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>5 G. [( f$ W' o- O) h. \- E
<><FONT color=#0000ff>/* read result of initialization */ 2 q$ P) H7 X! w7 d! L
errorcode = graphresult();
: }" u7 t, |% c9 Nif (errorcode != grOk) & s" R5 y  R' h& z2 v
/* an error occurred */ 9 e" V. m" Q( v" D; x6 n8 S
{ * c6 n+ o' s2 o7 k; |, R$ E
printf("Graphics error: %s\n",
$ U+ \, o7 w: n: J; I2 Vgrapherrormsg(errorcode)); % B7 K* M+ b0 o0 g0 L" L3 ~. z
printf("ress any key to halt:");
' y+ n- ~2 p% v% j% Dgetch(); + z3 J) d+ V7 H6 X
exit(1); 5 p1 R3 `8 U+ \9 R: K& J: |
/* terminate with an error code */ % G+ t' j+ Q9 t  S/ e9 j
} </FONT></P>! S. g3 _  l' n
<><FONT color=#0000ff>midx = getmaxx() / 2;
8 ^7 R8 P7 q. W: jmidy = getmaxy() / 2;
0 \: q8 |2 w9 n' bsetcolor(getmaxcolor()); </FONT></P>
0 Z/ ^7 z# }. `<><FONT color=#0000ff>/* draw ellipse */ ) Y3 h6 w" n) t0 E) x' }( _6 A
ellipse(midx, midy, stangle, endangle,
- S  i/ A5 I7 f, Axradius, yradius); </FONT></P>
. e- W( L0 {! _5 W- T' r$ ~: z7 ]; \2 j<><FONT color=#0000ff>/* clean up */ . G7 N, L  Q. _* L5 k- z4 B' [  Y
getch(); 1 n( d! K, Q; g# j2 r; N! f. v
closegraph(); ! u! f1 F+ ?- A9 K) |# a
return 0;
+ X/ l, J, S( l4 o) _. f( S7 L. Y} </FONT>5 k; _: o1 X, G0 D

; p! c: i. X& k! ]7 k" p</P>. @- s% F# L# u& w6 l# F& O
<><FONT color=#ff0000>函数名: enable </FONT>
1 I; R1 F+ m. g" }" F2 B& G  }功 能: 开放硬件中断 9 p$ O" n! |1 ?0 n
用 法: void enable(void); ( E6 I5 ]7 J( h
程序例: </P>
/ D+ `- [9 C# y' K<><FONT color=#0000ff>/* ** NOTE: / W) L5 N" }: b8 L( m
This is an interrupt service routine. You can NOT compile this program
8 j4 |! f$ V" T" c  ]1 vwith Test Stack Overflow turned on and get an executable file which will 7 O: s  K  ]% k. V$ o4 h
operate correctly.
& ~! j! T+ I% F*/ </FONT></P># j- N" E; o; H0 j+ O
<><FONT color=#0000ff>#include <STDIO.H>
9 W' j2 k& `6 _' e" @#include <DOS.H>
) `  Y2 ?7 e2 Y- d#include <CONIO.H></FONT></P>
, H/ S6 \2 [) Q+ u+ [; e: j<><FONT color=#0000ff>/* The clock tick interrupt */
4 O* g4 s; h2 }$ h#define INTR 0X1C </FONT></P>/ E+ @  e- ]; r6 h- f
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
1 A; V+ }$ @. _. p% L9 [$ W% k: D4 Z<><FONT color=#0000ff>int count=0; </FONT></P>% `8 R5 @+ ?7 u1 S$ ~
<><FONT color=#0000ff>void interrupt handler(void)
) x6 _4 m0 }; G# L- c{ 4 q" U+ X. _7 M- k/ E. U
/* ! O# r0 l. a4 x6 T3 k
disable interrupts during the handling of the interrupt / C8 L4 {( I1 v) r5 E( Y
*/ 2 R! c: a7 Y0 }2 N" \! t. z
disable();
" [5 U6 x' D2 l3 ~/* increase the global counter */
- q; y. q. H4 A+ k- e# _- N+ K8 ocount++; " W6 j1 [* q9 r
/*
  d( \3 |/ Y# L$ Tre enable interrupts at the end of the handler
4 [4 G# b/ r& {$ \: y; J: V*/ ; n5 k9 v" F6 y. C7 Y% z% [
enable();
7 f) ?) h5 U. W4 g0 z7 j: Z4 N; Z% @/* call the old routine */ ; e" s4 m: B' v2 r$ d2 t
oldhandler();
" n. G6 T! x9 C' B% j: a! \} </FONT></P>( h4 A( i) s, z- M$ j! q3 q/ a
<><FONT color=#0000ff>int main(void) 5 a) X; X  L. a' E: w1 P
{
7 B1 ~* j! V4 K  F# i/* save the old interrupt vector */
: p" W% B6 c5 o4 r# ioldhandler = getvect(INTR); </FONT></P>* D* r/ U; |0 v; @
<><FONT color=#0000ff>/* install the new interrupt handler */
. k" L8 }! K% x  Ksetvect(INTR, handler); </FONT></P>. j/ I3 D* _! Q5 C3 u! }" l2 Z
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
+ M- F( Z% N" l& A# \; wwhile (count &lt; 20)
$ {9 I6 b1 _+ V6 yprintf("count is %d\n",count); </FONT></P>' m$ @& G( U$ F
<><FONT color=#0000ff>/* reset the old interrupt handler */
+ [& g3 e3 W! `. fsetvect(INTR, oldhandler); </FONT></P>( ^. z- F2 x: R. ~- o
<><FONT color=#0000ff>return 0; 6 X# n% T; \- o. y' T0 }- y' F* x+ K
} </FONT>
2 P' j2 Y  ~+ H- k+ D. |, l* [) c+ w6 r+ _" k" s: O& t
</P>: P, j! f- U; p5 _( J
<><FONT color=#ff0000>函数名: eof </FONT>; `$ V# O' ]7 A* W  W
功 能: 检测文件结束
0 ?# l8 [1 }' X. t: W# b2 u+ b1 N用 法: int eof(int *handle); " A7 M# Z3 \0 S0 C
程序例: </P>
- K8 S3 w0 q9 I" B# E9 k! ^1 Q<P><FONT color=#0000ff>#include <SYS\STAT.H>
- f3 K3 r' h  S4 C#include <STRING.H>) [( y' t% d# {1 f7 @; k
#include <STDIO.H>3 z6 |7 m3 X# [, U- ]; ]4 a1 @
#include <FCNTL.H>
$ ]5 z  W3 U7 R# ?) V: f0 }#include <IO.H></FONT></P>, S% g, v; O+ z! m+ j: Q7 o
<P><FONT color=#0000ff>int main(void) . V0 a3 u7 }( ?. T0 G* R! v# L
{ : O3 j2 ^6 P9 l- G; x( m
int handle; # n& g) x6 {* `' k* X5 x
char msg[] = "This is a test";
( L& [* N! n  Y5 Gchar ch; </FONT></P>
+ \2 J  a0 C! @: B6 I) T<P><FONT color=#0000ff>/* create a file */
  q8 |8 i4 y* a, L- Jhandle = open("DUMMY.FIL",
; K  u" e' y; b( b+ U' W; eO_CREAT | O_RDWR, + ~( x. T4 a/ F' e0 \. Z
S_IREAD | S_IWRITE); </FONT></P>
+ I5 Y6 ^# g3 e' w' W<P><FONT color=#0000ff>/* write some data to the file */
; H7 `. o- S1 P$ Pwrite(handle, msg, strlen(msg)); </FONT></P>
: x6 d  `  |# b* H, B/ i  U3 w1 z  B<P><FONT color=#0000ff>/* seek to the beginning of the file */
9 }$ ~0 X! {" vlseek(handle, 0L, SEEK_SET); </FONT></P>; n5 D4 S! b. r+ p" U' r* ]0 M
<P><FONT color=#0000ff>/*
+ n) a6 @5 T2 m- l9 E( {reads chars from the file until hit EOF
6 v& S' e) g* q: H*/ : ~7 M5 w6 H7 y& i( v
do
( e- W* J7 U8 F{
0 v0 Z& R1 Z% T8 q! ^; M9 ?5 Aread(handle, &amp;ch, 1);
- n. A  E- m  ^) s7 [* Lprintf("%c", ch);
, q/ y& ?) N4 X( b3 W} while (!eof(handle)); </FONT></P>
, d! R& k" r( @% D$ B<P><FONT color=#0000ff>close(handle); 9 Y# _. _( O. b* H2 e% s' ]
return 0; + G* o1 g) F, e7 t
} 0 V" A2 W' z7 a7 ]
</FONT>
% t6 K# g' u! n</P>
1 @$ K2 H6 h" P* p% {$ O# ]<P><FONT color=#ff0000>函数名: exec... </FONT>
7 k% p7 N6 U: q4 H" c2 P功 能: 装入并运行其它程序的函数
5 e( M) @+ l/ R3 }% n) x3 t用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
9 Y6 T' c2 }% P* Aint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
) g& I0 G% c" S# z6 Q/ i3 s  b2 Q  Dchar *envp[]);
6 q$ o9 N$ C; l+ {, l9 J) Fint execlp(char *pathname, char *arg0, arg1, .., NULL); $ J" }# @, q1 @% [' k: I% O: M0 J
int execple(char *pathname, char *arg0, arg1, ..., NULL, + `3 Q9 R3 f  d) ~
char *envp[]);
8 E. a( ?5 k" z  Zint execv(char *pathname, char *argv[]); 3 }8 z, X4 D8 G" ?) J
int execve(char *pathname, char *argv[], char *envp[]); 3 u7 G' f+ ^- N. n
int execvp(char *pathname, char *argv[]);
/ L" C% e& x" L6 I% p  G: oint execvpe(char *pathname, char *argv[], char *envp[]); " M5 h6 O% c% `+ m8 N' `
程序例: </P>6 P- R( f) F7 `7 b
<P><FONT color=#0000ff>/* execv example */
  f/ @$ K; f; V) e9 g, S* B( ~9 }#include <PROCESS.H>- ^: ^/ n- G' d6 f; z/ M3 Q
#include <STDIO.H>7 Q3 h* D8 H+ z- g% i$ e
#include <ERRNO.H></FONT></P># ^+ a; ^" X1 E% X, z
<P><FONT color=#0000ff>void main(int argc, char *argv[]) , J* Y- ~: r6 c, x5 L
{ 3 ^6 ?7 X' _: [& t2 `7 j; P/ T
int i; </FONT></P>
8 _& j( P8 s' b<P><FONT color=#0000ff>printf("Command line arguments:\n"); ) L; M' s! V# t# o" D1 R  Z2 F
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
* l# |/ v8 N  @; z4 T6 w3 ^<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); 5 j+ H$ `0 T- }$ J- u
execv("CHILD.EXE", argv); </FONT></P>6 k2 X! z' U1 u6 H
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>8 y" S% ]( H5 M; N: C
<P><FONT color=#0000ff>exit(1); 8 H  X1 p6 G6 ~. {* _* Z
} 6 U. y: ]+ Z& P# g. d1 D' D
</FONT>
' \  n6 }) b( z' f5 ~  v</P>
6 e" B3 X$ t+ e5 |% h<P><FONT color=#ff0000>函数名: exit </FONT>
1 Z& }8 V- Q. y. G/ M功 能: 终止程序 , o  m0 L& q: Q  _0 H
用 法: void exit(int status); " Y" [9 h% l, M* ~, _7 t6 e
程序例: </P>+ U/ s3 \! a, \" K* }8 e3 ^
<P><FONT color=#0000ff>#include <STDLIB.H>" \) i0 L: E+ c% ?' D
#include <CONIO.H>
6 `  H5 L+ X, z% U#include <STDIO.H></FONT></P>
9 d5 k3 A, h, H- J6 q5 R- v<P><FONT color=#0000ff>int main(void) 5 ?6 v2 r& \1 p
{
# d* J" T1 }: h" N1 F# \+ @int status; </FONT></P>
: \5 _" Z& W) p/ J1 T9 D  E" m  D<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
0 w; i/ U9 K6 e; R6 Kstatus = getch();
/ O+ Z6 D& O, `1 m5 X* f0 o0 [/* Sets DOS errorlevel */
0 c' j$ ~- Q2 \8 K4 P8 }5 e% P3 h0 h! eexit(status - '0'); </FONT></P>" F7 z( z; f! Q0 V' v( d2 c2 G  P  s
<P><FONT color=#0000ff>/* Note: this line is never reached */
- E; ?1 W& p3 k( M9 o; U2 xreturn 0; 3 }& o* J0 @0 @0 C/ P; Y: Z
}
" s) ?- p; |1 U</FONT>
5 \9 J( Q7 a; b; b$ ~% f</P>( p7 ~' ]. U7 U% o& V3 Q
<P><FONT color=#ff0000>函数名: exp </FONT>
" B" _  f, T" q1 |+ X- @( X功 能: 指数函数
$ {* D4 Z: p& w+ G, D) Y: B用 法: double exp(double x); + |: ^% t, P, l8 g, r6 l1 r
程序例: </P>" G3 r4 f  R) y  c
<P><FONT color=#0000ff>#include <STDIO.H>) S0 R( s$ X$ ^. |# d+ N
#include <MATH.H></FONT></P># @3 _' c7 t3 T/ d" n: e, X9 v
<P><FONT color=#0000ff>int main(void)
2 Y8 B' U$ a: Y2 c$ x0 g{ 3 H% ~' B# h& w# S& {1 }
double result; " F+ q/ s) s6 Z$ |5 @0 b4 m. i
double x = 4.0; </FONT></P>) J8 S, @4 n! d
<P><FONT color=#0000ff>result = exp(x);
5 ]2 N; ]& j; w& u+ ?3 dprintf("'e' raised to the power \
9 K1 \* O3 O' d5 U1 X: p' \of %lf (e ^ %lf) = %lf\n", 9 F$ @% B! f) H2 G' H! n9 [
x, x, result); </FONT></P>
) G1 t: E% b9 ?1 H<P><FONT color=#0000ff>return 0; 7 O6 U3 H" z& d& L  x
}
4 e& H( B$ o+ s/ A</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>
2 F# }& m3 a* c+ [" F</P>$ P9 D& U( I. p
<p><><FONT color=#ff0000>函数名: delay </FONT>% r# s6 ^: E/ A* |  {
功 能: 将程序的执行暂停一段时间(毫秒) 7 o+ \! a/ v* l) W: j
用 法: void delay(unsigned milliseconds); ' j- I' d& b( Z
程序例:
" x, y" B% E5 k9 H. U<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ' M: U% K0 n( a% ~  c
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
) i9 E$ y1 y& K5 H! I; ^{
0 S: U$ m4 W/ @3 c; o/ N0 W. qsound(440);
$ [; b, f" Y5 G6 ?, I! K1 bdelay(500);
) T0 C! T& \$ I9 inosound(); </FONT></P><><FONT color=#0000ff>return 0;
: u' d% ]1 F) n0 r3 g' ?* P, ~8 J}
/ F" L: K, o4 j, o! J
4 v7 W' l) I. O/ g2 C( b</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>' F6 b8 [. ?2 m6 i
功 能: 在文本窗口中删去一行 ) c2 ], [! t0 y. C  m
用 法: void delline(void); 8 {: ~- i, p3 q5 {* }0 m
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) : Y- m% u9 G+ p6 r  A
{ $ A' J) A$ I  N' V, h; Q% U
clrscr(); ! V; Z4 z# |) O- u6 \( k
cprintf("The function DELLINE deletes \ 2 i; i8 t4 {: z/ ?0 f
the line containing the\r\n"); 7 |4 G) y4 ~$ c
cprintf("cursor and moves all lines \ - Z# [, v( O; }5 O' Z5 x
below it one line up.\r\n"); / \6 z* G$ {( V7 v' D" {
cprintf("DELLINE operates within the \
' z" s; k, K% R* ]+ g. q- pcurrently active text\r\n");
* I! B* @- i# z9 T8 j0 E8 ]cprintf("window. Press any key to \
9 M( a( G) r5 g2 acontinue . . .");
& R0 K4 `3 V0 ggotoxy(1,2); /* Move the cursor to the
4 Q1 ]  d6 ~$ K( ]& D& `second line and first column */ , Y0 Q' N; J8 T+ A0 [, \
getch(); </FONT></P><><FONT color=#0000ff>delline();
, r0 S' @* q* z4 p8 X( Agetch(); </FONT></P><><FONT color=#0000ff>return 0; 5 o4 v& K7 V  o1 N  b
} </FONT>6 b" J. ]/ o: M* b) I& k, `
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
- d5 R/ Z# y3 ^+ a0 q& n' Y5 Y功 能: 通过检测硬件确定图形驱动程序和模式
* O! O$ B) F- Z. g用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 5 i" a/ J' n9 [5 m* s
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>: L; i8 }' k; Q7 c: B- O9 S2 ^
#include <STDLIB.H>
. M* b' [2 V, B  ^% p6 b$ U/ C#include <STDIO.H>
$ I2 q: [1 Y- |+ F4 i#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
- c2 y& L& ]; V+ j1 J& J& e: fchar *dname[] = { "requests detection", ( x9 T4 M- w- C% L* ^7 z
"a CGA", 7 o, I9 O* C" e+ b1 Z% E
"an MCGA", # M+ K4 J$ e, ^/ E
"an EGA", : J; r+ [% K0 A! m
"a 64K EGA",
2 R6 B3 e; j9 A# `"a monochrome EGA", 8 c# ^6 S, f3 o4 S8 F. X# x/ x2 G' s
"an IBM 8514", , X* \. Q- H1 \+ \: v  g
"a Hercules monochrome", ' K- E' l8 |: h. p% }) T
"an AT&amp;T 6300 PC", - r  o+ P& h6 a: J7 g# G1 H
"a VGA", * `! b: L2 y1 }. ~3 k
"an IBM 3270 PC" ) ~2 ^6 ^" o; @. R9 w$ e# [
}; </FONT></P><><FONT color=#0000ff>int main(void) - H" u0 Q0 Y9 [
{ # P* U# ]! b+ |2 W+ I
/* returns detected hardware info. */ $ ~/ K4 D4 b& t8 z/ p
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ # u7 I- q% _7 p
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ # @& m" v  A, V2 t1 F1 `
errorcode = graphresult();
: l8 U: u4 ~+ ^8 O1 nif (errorcode != grOk) /* an error
3 }5 m4 Y4 `3 r# x8 t- e: Zoccurred */
$ E* Y3 Q8 V1 U' I( Y{
% e; J2 f9 Q6 O) V; kprintf("Graphics error: %s\n", \
: R- e8 O$ \3 u5 r% S& S6 tgrapherrormsg(errorcode));
; z# K; ^  t& |' e" ?2 Q. z, tprintf("ress any key to halt:");
& e! i# e6 f8 A/ q# J" j/ E$ Tgetch(); / c# ]' d! _8 f8 |1 U+ E# t: ?
exit(1); /* terminate with an error 2 X$ ]. i+ z* T; M3 K
code */
8 S$ v$ [; `6 e# e} </FONT></P><><FONT color=#0000ff>/* display the information detected */
1 h3 r8 n9 C# a& Kclrscr();
% m8 s' y9 ?7 u9 [, \: hprintf("You have %s video display \ 7 `1 w. ?; U& n2 ?& }
card.\n", dname[gdriver]); 4 D8 X3 Z% b! t
printf("ress any key to halt:"); 8 n6 H3 [. j4 o7 N% h
getch();
  G% r. |- _4 p2 `! n. Sreturn 0; & l3 G+ t7 p+ g& q! G; d
} </FONT>
" s( w0 `8 k# G3 r. V
; O: U, C$ v' A. q( h% u4 {; C/ p9 \" Z, {0 E& |# ^$ W4 I$ W
</P><><FONT color=#ff0000>函数名: difftime </FONT>) |1 @' o  O  q
功 能: 计算两个时刻之间的时间差
; U$ D" H  Q1 e) h  z# K  j7 j/ E用 法: double difftime(time_t time2, time_t time1);
6 a2 W: q2 D' a6 H9 F程序例: </P><><FONT color=#0000ff>#include <TIME.H>: K0 l0 t) a8 x3 w- Y& n+ g
#include <STDIO.H>
. R- q" {5 r; |3 \7 Q9 `#include <DOS.H># y" p- |  C& p2 \) C
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
5 Y" u  e! j" \  s: L# e0 T  b! S% g{
* S' ?9 \) [3 Y! {2 |7 vtime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
1 |1 e+ z: q. V7 d; zfirst = time(NULL); /* Gets system
! p& w6 C% }9 `3 c, y7 Rtime */
' c2 n6 z: k1 H) u" w3 @: @delay(2000); /* Waits 2 secs */ ; |$ I4 j; f4 P' e1 K; O, u
second = time(NULL); /* Gets system time   w% i3 A4 `& j9 l
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
* Z; N* }" _1 V- zseconds\n",difftime(second,first));
8 g0 `2 Y/ o) ?7 kgetch(); </FONT></P><><FONT color=#0000ff>return 0; , h( T* b- b% x$ v, @
}
9 D2 i6 M$ Q7 G2 l& ]2 h</FONT>
0 N- o- z' z* i7 h3 W8 ?</P><><FONT color=#ff0000>函数名: disable </FONT>, b. H! S: X% [5 t3 l' r' W) _1 _
功 能: 屏蔽中断 # {6 v) L5 a5 v3 S: B/ `
用 法: void disable(void); 6 F* T! }2 o3 r, p) c4 a% M
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
  G: ?  U$ C4 f7 v/ Hroutine. You cannot compile this program
+ s) B% x9 a3 d9 Q% lwith Test Stack Overflow turned on and 7 _. G" t' k7 \; t
get an executable file that operates
5 Y3 ]% V- i# e' q# a2 A7 e: ?correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>$ D9 J- N/ k* Z5 i
#include <DOS.H>
. `: S) E/ u: W0 G5 L4 r' v#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
& S$ X" w9 p: v3 S+ M. C# o% Finterrupt */ </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) & P' s4 J( J! G; a& {! r
{
$ _* S( b9 v+ F/* disable interrupts during the handling of
9 e, }# b1 y1 d0 Z  Z1 ^the interrupt */
* Z3 w+ ]) L9 w7 v! J& z& @disable();
7 H& K8 K/ H  u, |0 g2 p/* increase the global counter */
" E$ v. p/ Z: O1 e1 gcount++; 1 p. m& T% v. N# G8 _& Z, K
/* reenable interrupts at the end of the 0 ?) T) ~% \6 ~2 L. o8 R. L
handler */ $ |$ g5 Y9 L; a0 C$ @5 z/ ?
enable(); , k5 Y" E2 h' i) [8 ?
/* call the old routine */
2 U/ Q8 q! k. X6 P8 foldhandler(); 5 t) s! h3 I: e9 V  z: {
} </FONT></P><P><FONT color=#0000ff>int main(void)
2 K, v: M2 E7 b$ ^& G+ }{
- c7 e3 B2 e+ W/* save the old interrupt vector */ ' S% }# `$ r: }8 C- `1 h
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
1 A; L. Z* ]& B  m% ]. o9 Tsetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ , m# s8 e  l& v
while (count &lt; 20) ; o) k* `8 `* W8 t
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ 7 b5 S" [" u% ^/ j( s  Z
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
* a6 N: M+ C  J& n: R; O: F} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
. t# \9 y) _" \+ w功 能: 将两个整数相除, 返回商和余数
; p" d" E$ M9 s. P/ g( A$ G, [3 D用 法: div_t (int number, int denom); . o! t6 |8 F6 w3 H
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
. P- N8 b+ J) w6 R" v#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) ! x/ I/ t. r' L. \9 \' e
{ ) i# T: [2 T& j1 n; C. ^; w
x = div(10,3);
1 v7 P* ~8 ^# X0 N1 S& {printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; ) U, U* t+ y8 g4 M
} " z, S7 p: z* ^
</FONT>/ l) f  E3 T8 O4 H( z5 Z) }. I
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
) x7 g6 n) }8 }, u9 @% q6 i功 能: 获取扩展DOS错误信息 # D" |: m. U: T: L2 A2 M
用 法: int dosexterr(struct DOSERR *dblkp); ! \. a7 @0 }0 F
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
% E3 p7 m' y  b#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
: a9 Q9 y, s2 b# F* c. y{
7 e- n& y' z7 G- t) r! kFILE *fp; & I, b- {5 g) h! d5 i1 p& k
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); 3 }5 e" f: a# k8 s
if (!fp) perror("Unable to open file for ; c3 L2 i9 Y; m. K1 k& U. i
reading"); # U. x( [  v* \, T' `
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ . Q& C8 g4 S% P3 Q9 j
information:\n"); ) N' n; b" Q6 {9 l! Y
printf(" Extended error: \
( ?9 d2 {4 S: v0 v. n%d\n",info.exterror); 9 \0 t8 K9 r/ D% q, L
printf(" Class: \ ! v- V7 ~2 n3 v- m5 A8 `% R
%x\n",info.class);
, e, n. H* W) l* X# L7 \3 sprintf(" Action: \
6 I( f2 L. D) I8 H1 H, T. Z4 Q%x\n",info.action); " ^& U7 q% y$ v. @4 N" ^
printf(" Error Locus: \ - |- `7 ~' _$ R: g$ i' R
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; ( z0 b0 L4 Z% t
} </FONT>$ g; j2 s  s$ B" _" D
! C" J& c3 e- Z* ^) j0 S+ C
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
' {7 H( j" ?) ~7 l功 能: 转换日期和时间为UNIX时间格式
: k# d4 j8 g) ~; ^用 法: long dostounix(struct date *dateptr, struct time *timeptr); $ Q2 R  E: v& i" [
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>; Z$ V* G. Y9 j/ T- m
#include <STDDEF.H>
' ~: O4 B7 l3 `: v1 M+ c* q$ T#include <DOS.H>
0 r% W9 M  q1 g- i+ \- ?8 s1 E# u+ z/ a#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)   c9 ~) X0 Q, J5 M
{
+ P3 N3 q! c' F0 p0 ]time_t t; ' @5 f% R& f' Y( [
struct time d_time; : H/ _/ e: a# a" H5 u* @
struct date d_date;
* J# Q& r$ H* ~6 G5 f: Zstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
" J7 Y9 w, G8 {. ^/ P6 i: igettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
# q; e0 y0 O  Z, ]local = localtime(&amp;t);   J+ t; ~3 M: d
printf("Time and Date: %s\n", \ / r6 ?" w/ s  [8 t
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
2 G) O9 |6 E! X5 v0 k} </FONT>3 Y3 H3 a0 ?% P- t3 W/ F
+ o( L+ j/ t# g! L* w) N, g4 [
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>7 q7 M$ s1 O7 z. ^
功 能: 画多边形 & [- o5 Y/ w2 J
用 法: void far drawpoly(int numpoints, int far *polypoints);
. R( b: ]1 \# r% {程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
/ Y" _8 {. j& D7 \#include <STDLIB.H>
. f8 b# u3 w* L7 C# M" \#include <STDIO.H>4 G  o5 z, e3 s: B# ?. a9 v+ d6 U
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
! x! _4 `4 x- t8 I{
+ V" L& u8 v+ O; ?, v7 t3 f0 k% C/* request auto detection */ % y1 k( L1 [( @, n: l. M
int gdriver = DETECT, gmode, errorcode; 4 _( y  j( N1 J. ]
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ 6 H5 }. N  I( y, Q0 F
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
* E6 o- d: z  O8 X5 bvariables */
" H1 M, L. v. D0 M, Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ ! F$ _! X) R- _1 m/ D; c
errorcode = graphresult(); ; G% `% _  s+ e! f. ^( W# X
if (errorcode != grOk)
3 b( I* l/ G8 H1 d/* an error occurred */
0 Y) t) t4 Z6 t+ W, n+ j( t( ]{ " c; \4 K6 l/ w, M
printf("Graphics error: %s\n", \ 2 s- H) q. j! s
grapherrormsg(errorcode)); 2 E1 k' ~! H. K% F3 I
printf("Press any key to halt:"); 2 W& ]$ y6 T9 d; n& L
getch(); ; [( X+ v7 J. Z' j# y5 u4 C! X
/* terminate with an error code */ & s9 s9 ^6 @- K/ }: z9 Y
exit(1); 9 w4 D& A: z! [3 W& N
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
( A- [9 J$ g) B( K: wmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */   _8 @! C( E0 S  ~- ^: T
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
/ p6 C; S9 z1 x8 npoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
6 z8 r# ~7 i4 M. Q7 U, U! Epoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
/ t2 `1 S" }5 T* d  ?poly[7] = maxy / 2; $ o+ `* A4 g1 t4 F9 _2 e
/*
8 _3 y4 w( d1 I8 z' N/ Adrawpoly doesn't automatically close
  w, P0 q! H4 ?5 f2 z+ g  k" b2 r! Ithe polygon, so we close it. : n+ |# f" N2 @8 N( b: T
*/
/ O! Z- {- {3 Z2 V( d2 e- Dpoly[8] = poly[0]; . W8 f" D: e% L" L# a1 h8 }
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
1 m) V3 M2 V. Q4 [. f3 mdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 0 O; q6 Y$ S1 a. B
getch();
  C9 n- I3 N, z4 N" k" iclosegraph(); # X& y  w# t; |& s2 M) K- {/ w
return 0; 4 `4 V' @. a1 A! g& l5 s) w) L* b# u9 }
} 1 g% C5 y5 Q( J. }, e0 R7 l
</FONT>
/ |" G9 m5 S2 h* [' r+ e</P><P><FONT color=#ff0000>函数名: dup </FONT>
: h. l( _# A# x+ I. U功 能: 复制一个文件句柄
( O& ]3 u- [8 I4 w3 {6 q3 |用 法: int dup(int handle);
# Z( v4 _+ g/ u5 c程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
7 Z; e3 Y$ Q& {% a9 j#include <STDIO.H>
+ f3 U: E. G0 e4 t#include <CONIO.H>
' p9 o0 Q& D' G: Z#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
$ p2 }3 z9 \1 |8 s8 k# h{
2 `/ ?  p( n6 F, L$ N1 o- |4 d0 TFILE *fp;
; {4 v; f! y) H6 m9 [5 T* mchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 7 Y/ a. |9 s! R
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ 2 ~6 d2 @. q; e
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 1 S, {/ z, t' A. w& l
printf("Press any key to flush \ ) r. l. q8 |, h  G" j
DUMMY.FIL:");
3 g* C( ~3 _3 R+ o/ x4 Z" d# i8 Rgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
6 \( A& p2 e" M: m/ T: Q, Hclosing it */
  [4 @0 f0 V& ]: k% @/ k0 u/ `flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ ! H6 u/ }4 s, w! T$ H
key to quit:");
, b; D7 l8 B+ E1 g# M1 _' F7 Bgetch();
1 _5 }+ `/ S1 H4 n  ]' K7 q, Vreturn 0;
5 \, r2 a$ s. [+ b9 C( q" P1 Y} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
( t! ^3 j6 J. j9 o2 f% m{ ) O' G9 A+ R$ h8 a' W: f
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ 3 `9 g& _5 k" n% E
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
* `) ~1 n* `9 e* A* X4 \: Oduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the " O$ _1 f) a: C- L- n
DOS buffer */ ; S/ v- ?* r' E. l- W, w
close(duphandle); 7 ]' T; u6 f) O
}
' `( ]7 T3 }+ Y- x( o0 O7 ]6 R% V; m
  [$ y$ }) v7 V- |8 B$ |/ N, n</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
3 T0 T3 Z% k! n  z2 V功 能: 复制文件句柄 6 @3 J9 A$ S9 M2 U9 y! O* q
用 法: int dup2(int oldhandle, int newhandle);
, E/ m4 }: r# {: f程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>. ~8 p# R9 U6 h$ x6 ]4 F4 p
#include <STRING.H>' a. ^0 k0 d- q0 C- ?. @7 r
#include <FCNTL.H>
7 i4 X; O: |% I#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
/ G3 V: B2 q" z% T5 t  e8 g{ 4 p8 w% a0 M# O8 d
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
. ^; ?. x9 P3 r+ U3 l! S3 schar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
( ^( H, V6 n3 g* }$ e" G/ knul = open("DUMMY.FIL", O_CREAT | O_RDWR, # ]# ~+ j5 c  c; t* \. `# y
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard $ v" _6 K# x, B1 F( L, C! l. j
output */
  A% v1 X) B1 J  B, N# Q, Koldstdout = dup(STDOUT); : e. I& {) \4 W2 k& \2 y
/*
: v% H! M$ ^5 ?1 Z1 Iredirect standard output to DUMMY.FIL
# o" P/ L! j2 J2 k' ]3 bby duplicating the file handle onto the
% B2 Y  B0 M- P  F. s- Q, _; i. Cfile handle for standard output.
) v+ ]3 I8 B- V*/
. N4 U" a/ M' m, @$ J7 U- Ydup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ $ v) E* ?. d. G# z5 R# x* |' Z
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
1 h# }, Q2 _3 y8 M  D/ X) Gwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
+ ]) [, G4 x6 E7 `' B1 mhandle */
" p0 i. y. F) ^1 c) ^dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ 0 L) @+ K8 }" z6 L! P
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 9 j  _# X0 \* Y8 t
}
/ Q/ H9 x7 H% U; ~( [</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 06:14 , Processed in 0.398706 second(s), 57 queries .

回顶部