QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2060|回复: 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>
% H% q! Y! A, o4 _3 v, b</P>! u' F$ [; y# W6 K/ {

9 u6 e+ \( w* L& K/ o# E% |$ p% r& x: o6 V( C
<><FONT color=#ff0000>函数名: ecvt </FONT>
2 y+ ~4 p4 k0 {& h. h, K功 能: 把一个浮点数转换为字符串
# m% B7 D$ {9 p/ [3 `用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); ) U4 Q" R1 R, t: X6 O  K
程序例: </P>
/ A% I! W  s- c  k. C) d! V<><FONT color=#0000ff>#include <STDLIB.H>' {1 V3 x  _: @; Y
#include <STDIO.H>
6 H' h! t1 @8 `. M#include <CONIO.H></FONT></P>& h! `! @2 ~; t: ~
<><FONT color=#0000ff>int main(void) 7 K# X: Q' H9 Y& m( C( h8 I
{
: _" M# D8 X+ q* u. Uchar *string;
8 R& B3 B" Z7 l2 d7 q5 \' a/ O3 X; Qdouble value; + Y0 g; {$ Z9 I
int dec, sign;
6 i4 s& b, b8 B* f( Eint ndig = 10; </FONT></P>  I) h! N, N6 q) A
<><FONT color=#0000ff>clrscr(); + q$ x' _  V; O5 s( q9 ~
value = 9.876;
8 g8 c7 o' |* q5 Q7 i# |5 Ustring = ecvt(value, ndig, &amp;dec, &amp;sign); 2 ~0 U0 H! r* Q, g+ c# a
printf("string = %s dec = %d \   M# |  q3 e, ?& [! u- F7 P# f
sign = %d\n", string, dec, sign); </FONT></P>/ m* y0 V1 O" t; ]
<><FONT color=#0000ff>value = -123.45; ; c8 g2 ~; T, j' r7 D
ndig= 15;
8 }$ o# q" O: c0 W$ ystring = ecvt(value,ndig,&amp;dec,&amp;sign); 3 F8 h/ }! P) d  H
printf("string = %s dec = %d sign = %d\n",
8 j4 r3 q! O' S5 G* ?string, dec, sign);
/ U7 K1 m2 W' M# ~</FONT></P>8 V- v$ t  N( {, @! ]! x
<><FONT color=#0000ff>value = 0.6789e5; /* scientific $ e' S1 _' C4 N+ ~/ H( b% e: O
notation */ - y9 ^1 }. Y% _( u* p; E
ndig = 5; $ ], Z- V8 x% Z: S6 W
string = ecvt(value,ndig,&amp;dec,&amp;sign); 7 i# m% M0 m: @8 G
printf("string = %s dec = %d\
% {" S* u$ C) ]: c+ ?0 w- V; ysign = %d\n", string, dec, sign); </FONT></P>: L) W( l7 E# ~" l
<><FONT color=#0000ff>return 0;
0 c, Z: }* S* T/ D1 a$ v, _% f} </FONT>1 u% y1 c/ g& X, v9 W. G
8 ^# C/ F6 T- _% a/ n
</P>. z0 S$ m/ H& _6 x5 W4 `8 }
<><FONT color=#ff0000>函数名: ellipse </FONT>
& }3 O  i+ O; X+ F8 k- _功 能: 画一椭圆
1 p$ ?" o) s4 p2 [- h/ g用 法: void far ellipse(int x, int y, int stangle, int endangle,
( P4 N& Z" g/ o+ b7 C8 O- P5 g/ D4 \  gint xradius, int yradius);
% T. A0 ~: N2 q- S+ g程序例: </P>3 w  a6 ?1 Z- m
<><FONT color=#0000ff>#include <GRAPHICS.H>
6 l$ p, K" l8 y! G5 @#include <STDLIB.H>4 {: S) ~- `7 K" ^! @3 G
#include <STDIO.H>
1 E' w0 B5 z  m& V: {#include <CONIO.H></FONT></P>  X' {0 p! U0 i
<><FONT color=#0000ff>int main(void)
3 N" |, h, Y- F2 v{
) `( h5 P8 k) W: v6 T/* request auto detection */ 6 s. o# u8 L- X3 ]& O5 W
int gdriver = DETECT, gmode, errorcode;
; H3 n# P: n% _: l3 \1 M4 q1 w  Yint midx, midy;
$ `# A/ q# z3 l+ @6 Hint stangle = 0, endangle = 360;
. v" z( M& K6 I: }/ V: Oint xradius = 100, yradius = 50; </FONT></P>
# u4 z2 o1 u$ |0 s" i( A! @<><FONT color=#0000ff>/* initialize graphics, local variables */
2 x( s& }9 J9 X2 Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
7 [9 U0 z0 m; b8 s9 X# {( q<><FONT color=#0000ff>/* read result of initialization */ 8 W4 {5 }9 v  N0 J% w+ V
errorcode = graphresult();
# }4 Q. a( L4 `7 q# sif (errorcode != grOk)
# O- d' \# I5 j1 g1 S/* an error occurred */
  Q& i! C6 o) x! s6 m% T( M9 ?{
# V# `# @! G0 N5 ?* x4 |1 eprintf("Graphics error: %s\n",
/ ^1 F) l! K8 }- W& p2 _3 ?8 Egrapherrormsg(errorcode));
5 V, o4 s. d+ E' R+ Vprintf("ress any key to halt:"); ) M: l6 O+ G# @4 Y# ]8 ^, p, A9 x
getch(); 6 Q. B; {6 T2 ?# I
exit(1); # A/ D( I7 ], Y
/* terminate with an error code */
. [# u+ ?# c! `$ \} </FONT></P>4 Q: W. |9 `. s+ x# K& r
<><FONT color=#0000ff>midx = getmaxx() / 2;
2 g4 b" w- W6 f. f- E6 tmidy = getmaxy() / 2;
# t7 v' k( ?' z# ~* ysetcolor(getmaxcolor()); </FONT></P>
) W- o  m$ j* ]<><FONT color=#0000ff>/* draw ellipse */
, S+ u5 Q4 m1 }* z2 A- g" yellipse(midx, midy, stangle, endangle, + ~: J$ e* @3 m. D
xradius, yradius); </FONT></P>9 N/ K, H% r! [# ?) G8 c+ _
<><FONT color=#0000ff>/* clean up */
: P) A  O" r) P; k) P, M- Egetch();
! I& R% B+ S) Q) R4 sclosegraph();
, g& n) X" Q0 t8 N1 j$ V2 @return 0;
) d) w1 i# l4 o( |: I- K  b} </FONT>" Y4 y3 ]# V) p: y1 H
  d5 ]4 _: r8 A3 G, f
</P>; B7 u  g& ~: p. _1 V8 I5 ?4 t1 k
<><FONT color=#ff0000>函数名: enable </FONT>8 A8 |) _, s! ~$ v& q. b
功 能: 开放硬件中断 + W# e1 X( t) R; J& m8 a
用 法: void enable(void); 8 `+ }) b9 \. p1 b2 L
程序例: </P>6 {) x& j4 H0 q# n- l9 t
<><FONT color=#0000ff>/* ** NOTE:
. U, w, K1 c  w( b3 ^, K$ S1 VThis is an interrupt service routine. You can NOT compile this program & ?6 g. M# [* ?7 F8 Q
with Test Stack Overflow turned on and get an executable file which will , c" z& K  s% b0 m: i( M* Z
operate correctly.
( t$ `0 `7 w, w4 Q( F0 c* N*/ </FONT></P>! I0 \4 D, Z! K5 a
<><FONT color=#0000ff>#include <STDIO.H>
6 j+ `7 @+ m: c) Y3 E! t#include <DOS.H>
1 K/ _' U4 l+ T#include <CONIO.H></FONT></P>7 g7 e; l' x* T' i. c! D
<><FONT color=#0000ff>/* The clock tick interrupt */
) f% Y  _) K& V9 C$ g/ Q- Y#define INTR 0X1C </FONT></P>: c8 w! D1 R0 t: V! K/ {7 J
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
, p, f. h8 h; Q<><FONT color=#0000ff>int count=0; </FONT></P>
- m7 ~, x7 b' h) ]<><FONT color=#0000ff>void interrupt handler(void) " W; h( ]# p2 D7 A
{ % \1 x, o# ]) P. [, t# P
/*
6 K& m- R' z8 r2 r/ W- Pdisable interrupts during the handling of the interrupt
# {) O+ v0 G8 r! k  [) ~: X! B# v*/
, J4 x6 I4 g. ~0 ]3 Y) idisable(); 7 f/ G7 Q& k' }; |8 P
/* increase the global counter */
. ^& m; j& v/ ecount++; * R0 L1 O, B/ |, f9 [
/* 3 e. a% U5 i& U5 s3 S5 U& D
re enable interrupts at the end of the handler * ?  R* x7 y' R8 ]& S
*/
( i. |3 N5 C8 f7 Menable(); ' @  c( y- J+ e- h, e
/* call the old routine */ 0 R0 l3 Y( Z* a$ F
oldhandler();
/ E" G- j$ ?' }- M! i2 `} </FONT></P>6 N+ [) k" N1 {
<><FONT color=#0000ff>int main(void) + H/ r" ?3 O# V: _: G$ L/ D% _
{ ; r) b% e' ^) I# |9 O
/* save the old interrupt vector */ & q) B. b  Y% }& p
oldhandler = getvect(INTR); </FONT></P>9 E+ x9 ~. N" g6 t' J7 L
<><FONT color=#0000ff>/* install the new interrupt handler */ 7 r4 S) l( |" Z; u% p+ }8 x$ E
setvect(INTR, handler); </FONT></P>
# `$ `$ ~1 H4 Y5 E/ H<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
1 m8 L* J, l0 ^  h5 W: Dwhile (count &lt; 20) 9 `" g2 p: h) h& x, U" [7 y
printf("count is %d\n",count); </FONT></P>
' r& s" f& C( q) t, i* u% Y/ m<><FONT color=#0000ff>/* reset the old interrupt handler */   @2 ]1 G+ M" x  c9 K
setvect(INTR, oldhandler); </FONT></P>
, d$ \5 m3 V- j; X<><FONT color=#0000ff>return 0;
$ _/ Z; R& `& a# c8 b} </FONT>
+ q# J% ^" x6 i+ u9 X" o
- z1 F0 e# m, G$ g</P>
( o& V  c5 g" j<><FONT color=#ff0000>函数名: eof </FONT>
8 b0 h" h) d5 }9 P% E功 能: 检测文件结束
0 q' y- x$ C7 Y7 i用 法: int eof(int *handle);
# a; |: B; a3 N0 A! o* Z程序例: </P>
6 @, _" |; q3 ~) e3 H$ T) h. `, b<P><FONT color=#0000ff>#include <SYS\STAT.H>! z( ]& C% L) Q! b" u
#include <STRING.H>
/ p1 V3 C/ ]) X#include <STDIO.H>
  U. L* z9 r* G8 V2 G3 j#include <FCNTL.H>
$ e9 q5 P' k; c#include <IO.H></FONT></P>
: C1 Y1 B$ w. O/ k2 u<P><FONT color=#0000ff>int main(void)
$ b- p$ j( o( [. u: k: ]9 R% o{
" ~9 M9 H$ ^7 a- s3 y( |% B# aint handle;
/ P+ H& w0 L1 n2 lchar msg[] = "This is a test";
. F+ u" f$ R1 h( t5 n. V! achar ch; </FONT></P>+ y' z2 h, L3 R) l+ b) Y+ {
<P><FONT color=#0000ff>/* create a file */ 4 y7 {% d. _; C* b
handle = open("DUMMY.FIL",
) X$ a) U: X6 v6 t  QO_CREAT | O_RDWR,
( n1 C. k$ `; N2 gS_IREAD | S_IWRITE); </FONT></P>
" }# s. e: H5 A. W( G<P><FONT color=#0000ff>/* write some data to the file */ - p: o  E; Z. s" U2 p
write(handle, msg, strlen(msg)); </FONT></P>% N" w- k, F+ c% R5 h3 A9 p- A1 O
<P><FONT color=#0000ff>/* seek to the beginning of the file */ 0 S5 n5 c7 D5 A
lseek(handle, 0L, SEEK_SET); </FONT></P>7 Y6 x/ m( \9 u$ B8 z
<P><FONT color=#0000ff>/*
. F, O( o( v7 D% f9 Vreads chars from the file until hit EOF
2 {& P$ I$ V- n) K% a*/ ( V5 u3 ^9 `+ ]. N  {2 U% \, m( A
do
$ d2 G  R3 ]3 \: v( p{
2 [- p) c; W7 u2 n# dread(handle, &amp;ch, 1); % C! T' [( m( y' T9 I7 q7 l
printf("%c", ch); ) q3 E* K. T% U- u% A5 s5 f
} while (!eof(handle)); </FONT></P>
: w. E3 b; {  o9 q<P><FONT color=#0000ff>close(handle); # Q* P9 W) b3 [! `- h
return 0;
- C+ p$ o; S( ]: |4 S9 k}
3 L3 z' u- M0 N! }" l5 r6 R</FONT>
% j4 e, D( M: e/ |2 U4 @, \: A( q</P>3 g/ l* `7 ]6 v5 r
<P><FONT color=#ff0000>函数名: exec... </FONT>: M* G% i2 H: r2 b5 C5 ~2 [6 X
功 能: 装入并运行其它程序的函数
( \6 `6 q$ i8 i3 x% C, ]; @0 w; A用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
9 n* |* Q# ~" L0 i! l5 b+ P9 Bint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
8 a6 @/ s3 J/ {, t, c3 p/ zchar *envp[]);
2 C& m; M2 M  Q, A' `int execlp(char *pathname, char *arg0, arg1, .., NULL);
  _0 c7 r" h$ R# u3 H. w. Wint execple(char *pathname, char *arg0, arg1, ..., NULL, " J3 z4 h7 p( i, r
char *envp[]);
  ]0 H( A# k+ ~% V/ \+ _int execv(char *pathname, char *argv[]);
- l9 P0 I7 A  H  Y: g) Kint execve(char *pathname, char *argv[], char *envp[]);
( }5 K( A7 |) ^int execvp(char *pathname, char *argv[]); , h" l0 A/ N9 P, {# r, H
int execvpe(char *pathname, char *argv[], char *envp[]); 4 u6 S$ d) @5 w
程序例: </P>
- ?2 J" E3 B# g, X. [* \( @<P><FONT color=#0000ff>/* execv example */
3 V( P  I+ F, _6 |#include <PROCESS.H>  q0 P, d9 \4 K( q
#include <STDIO.H>* T5 V2 B3 [+ f  g. x: Y' T
#include <ERRNO.H></FONT></P>
: ]2 {4 h& }: s* t, S# m<P><FONT color=#0000ff>void main(int argc, char *argv[]) 3 c( J( |7 T" q6 ^9 b: p9 L
{
0 r, G. R7 B( C6 u, kint i; </FONT></P>
1 c7 G" K  j8 t* R4 N<P><FONT color=#0000ff>printf("Command line arguments:\n"); ( V- f( j) {+ T/ ?  e
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>  q* g1 c7 G  G- C! T
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); 7 a! L7 U# r; b& u: h
execv("CHILD.EXE", argv); </FONT></P>% x* z" e) X' t6 f6 e( |
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>2 P! S6 t( A, V8 C1 _+ s1 W9 l
<P><FONT color=#0000ff>exit(1);
5 Y  N) d9 _6 ~" G: p6 \} # x1 q' K* ^, O9 T+ x0 i
</FONT>
3 C3 L  A/ a/ u# C3 j</P>4 M# s; C7 }; _! u7 a: }
<P><FONT color=#ff0000>函数名: exit </FONT>* `* d2 S1 D2 m: j3 B& h
功 能: 终止程序 ; }5 x# U1 w8 F" X/ c# D3 |
用 法: void exit(int status); , P+ A5 G/ Y& G, q0 p2 l! ], p2 ]+ r0 S
程序例: </P>
0 u/ H5 u2 n( x3 \9 \, r+ e% o4 L<P><FONT color=#0000ff>#include <STDLIB.H>& ~9 V/ r& ^* N4 F( U- J/ [
#include <CONIO.H>
' v0 q4 b' p- _; v# C5 g#include <STDIO.H></FONT></P>
% ~' Q+ A+ a  Q1 t" H<P><FONT color=#0000ff>int main(void)
; k5 W+ B- r" {# F* S* ~9 T: h, F0 E{
) M& K5 f) _" x% l8 }4 r- qint status; </FONT></P>
# X) ]/ F, W7 j& ?) d<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
" x3 R$ z! t2 {  Y& `6 g( pstatus = getch(); 3 h& }; z* L9 v0 S0 c% N  q
/* Sets DOS errorlevel */
  L5 C; z2 c2 J& _$ fexit(status - '0'); </FONT></P>
: G% X% c4 z+ |9 [; \) Q% R* @. h" U<P><FONT color=#0000ff>/* Note: this line is never reached */
( r* W, f! i) N) R6 i9 J. ^return 0;
( U( {; e4 ~- I  R3 O}
# g6 I: f& {$ ^0 w6 b</FONT>, n) E: t: E& t3 w6 Q
</P>
2 j' q. ~7 z% I<P><FONT color=#ff0000>函数名: exp </FONT>1 P2 h% Z) B7 T9 D0 G5 `
功 能: 指数函数 % L/ i2 E. u4 i) R$ v. R
用 法: double exp(double x); ; M# |4 d% ]2 b% P! K0 T, k! d
程序例: </P>
  j, e) f% _  e0 c& r<P><FONT color=#0000ff>#include <STDIO.H>* l$ R. E; }" E7 d. D* `4 m
#include <MATH.H></FONT></P>
$ n) O& c5 y2 P* d$ G" u! I6 m<P><FONT color=#0000ff>int main(void) & Z, }% m2 |' h0 q( M
{ & u+ G2 C$ f; y" z1 b
double result;
2 m1 D# D  W4 z: E7 Ndouble x = 4.0; </FONT></P>, s% h+ Q, Q/ ]/ a2 Z" V
<P><FONT color=#0000ff>result = exp(x);
, Z& f" i# ~& ]* z+ _9 }printf("'e' raised to the power \ * p" d' I% ~3 }* i+ a& E! ~3 F
of %lf (e ^ %lf) = %lf\n",
$ }1 K3 E! c! t5 f7 gx, x, result); </FONT></P>6 H8 z# y" v( ?
<P><FONT color=#0000ff>return 0;
+ r/ f7 @2 I, d( R  t7 B3 X( G4 ]  Y1 w, d& a}
7 T2 z) k8 F6 L4 @/ k, h</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>9 N( o4 r1 B2 S  P% m1 H
</P>
8 _; V4 \( Y. ~$ R* g! g* v5 g* e<p><><FONT color=#ff0000>函数名: delay </FONT>+ v9 y5 f6 G$ @/ t9 e# O
功 能: 将程序的执行暂停一段时间(毫秒) 8 O% j9 J  I* j
用 法: void delay(unsigned milliseconds);
: H! Y& L) u! X- a# w2 j程序例:
3 |, W2 `* E1 [% o0 Q( I<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
( E* i/ w4 q8 n* ?6 q#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
' Z! [8 u) e2 v! _{
" s+ H% B9 _( Jsound(440); " q) X/ r1 i, ^
delay(500); % T1 B( b9 m- n) n7 _7 `
nosound(); </FONT></P><><FONT color=#0000ff>return 0; * v4 }0 a+ @- n3 `1 i
}
9 ?$ n7 E. @( j4 z) I$ W1 @- M! U5 d1 `
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
. M, ], v' ^' `6 |4 J功 能: 在文本窗口中删去一行 ) W) h5 \- ]8 ]9 v" _
用 法: void delline(void);
* K/ |( k2 K, n+ `" r程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) . S! I( G- ~8 D! {5 W% |
{
, \  g5 m6 g0 Z& c4 \. hclrscr();
( B  K1 |, y9 P, ~) |7 Ecprintf("The function DELLINE deletes \ ; Y. c. P; u* k9 C7 H& C
the line containing the\r\n");
0 ^9 t  k3 V4 ^' Y5 a+ Qcprintf("cursor and moves all lines \
  w% ?; U% H- x. z. Q3 n1 Mbelow it one line up.\r\n");
7 o; j! X/ Z3 J) N, g% Ucprintf("DELLINE operates within the \
: R8 y( I8 i) \+ Icurrently active text\r\n");
5 ?: _6 d, s9 p4 xcprintf("window. Press any key to \
9 v: ]2 [/ `' t# Zcontinue . . .");
9 o/ V# S2 u6 ~5 |* Z' q3 wgotoxy(1,2); /* Move the cursor to the 4 n  A0 t/ V1 x9 n8 n6 j0 W
second line and first column */ / I  @( c" a* o! T
getch(); </FONT></P><><FONT color=#0000ff>delline(); 9 V- [% ^/ q, J
getch(); </FONT></P><><FONT color=#0000ff>return 0;
. S! G# H6 T3 j+ T* h$ H0 H" `! b2 c1 S} </FONT>% a9 I' P7 z! v8 _+ f' ]* M2 x
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>7 N+ ?+ Q( K' I! l, r
功 能: 通过检测硬件确定图形驱动程序和模式
/ l% r; ]' n% {& f: \2 U! i* H) b用 法: void far detectgraph(int far *graphdriver, int far *graphmode);   H! |7 b! C% {( [7 J
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
- |* P$ f# o( X/ t' C#include <STDLIB.H>* |% f, W' z$ p4 |( i! g( x' F
#include <STDIO.H>
! m. r  ?6 F8 a8 K9 D8 {4 H0 t. ^#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ ' N( U9 J+ F6 Y, Q; J6 x+ y
char *dname[] = { "requests detection",
& L2 v# \& N# q# f' Q9 C( c"a CGA", + i8 i3 e+ K# e  E, p
"an MCGA", 8 b5 I. {  k% M& d
"an EGA",
* ?8 e. W: Q' K' B2 u"a 64K EGA",
% P" _) l; v: x, ~0 ]' A"a monochrome EGA", " V! I4 [& m, U% T! `# s' r
"an IBM 8514", 0 u) B( h" x! \' R* k
"a Hercules monochrome",
$ a' A4 Q4 N( M"an AT&amp;T 6300 PC", 4 M. b3 i3 E2 U+ o# s$ h& ~
"a VGA", 3 h" V! z5 \0 X: _3 l) {/ J
"an IBM 3270 PC"
, ^# h3 {8 X3 g3 e}; </FONT></P><><FONT color=#0000ff>int main(void) + e# R/ ]( F! Y5 f
{ % w; m" u3 A& S! f* C! o; \
/* returns detected hardware info. */
% M* U/ `- m% O4 Sint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ % r- `/ Q9 E/ o  k8 n# k
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ & m- w4 M, l& v5 x3 H# U3 x
errorcode = graphresult(); 9 l* _8 y* w, j
if (errorcode != grOk) /* an error 5 {( [; H! k4 x) ^5 l
occurred */
* F( l: S8 z; t9 c9 X0 ?) Q{ . f- `/ j2 l+ B& h% D
printf("Graphics error: %s\n", \ ' D, M3 v6 Q3 [! |" n
grapherrormsg(errorcode)); 8 V& o6 @( J* o
printf("ress any key to halt:"); # R2 L& }, A6 h: l9 X  @
getch();
: k- K7 L& ~5 Y0 j3 n- V! uexit(1); /* terminate with an error
* ?5 b  ?$ ]7 q4 S) ?code */
( |6 e5 b2 B& }9 C: w& T} </FONT></P><><FONT color=#0000ff>/* display the information detected */
( J( Z! t& J/ dclrscr();
+ D# c  r" g6 W9 e0 I# pprintf("You have %s video display \
% x# l! m' W5 z% g' ucard.\n", dname[gdriver]); 5 p: H8 ?- s4 U. T
printf("ress any key to halt:");
& {* _* X1 Q6 M9 Y" a+ fgetch();
: z& Y! y' E) A" P" M5 y/ z2 Hreturn 0; 7 ^1 }+ W3 G" f& e, r' s' i" e
} </FONT>& d! A0 v% \* ^' E! y. \, C% J# `
; o3 Q: t+ \  A" a/ G+ F) E; \2 Z$ F

9 O6 Z+ j: _  u  R</P><><FONT color=#ff0000>函数名: difftime </FONT>
' i3 c! X: W3 S" s4 \3 H2 m功 能: 计算两个时刻之间的时间差 " m8 ]! S4 N# f7 p
用 法: double difftime(time_t time2, time_t time1);
1 C) Y5 Q7 A) p, ~1 }# D' M. ]" \程序例: </P><><FONT color=#0000ff>#include <TIME.H>2 t$ W  F8 d; P' e3 L  d( {
#include <STDIO.H>" B+ W/ U" O# t8 s, P- @8 ]
#include <DOS.H>2 D* \( `' A2 u0 O/ k
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) - O+ z0 J* Z2 G0 v
{ ; Q8 b+ d& |4 ]; Y. [
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
3 ^. j7 k' ^9 ?' ], j: O  Tfirst = time(NULL); /* Gets system ) s+ R: b) D# ^* f$ a0 H3 w+ s: s
time */
6 [( b: W4 T9 \, U% W0 |( ydelay(2000); /* Waits 2 secs */
# r) V. K  g! q! Hsecond = time(NULL); /* Gets system time
3 M) p2 X* ?$ i0 O/ A! \4 lagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
5 l- i$ @- e" X) @& |- E3 |seconds\n",difftime(second,first));
. D/ ~; D& Q: Ngetch(); </FONT></P><><FONT color=#0000ff>return 0;
- v9 `: D4 t; v% w}
: N0 S+ q) B, d+ s! F5 ~</FONT>
% n: B( |; v% I7 ?' R</P><><FONT color=#ff0000>函数名: disable </FONT>! `6 N" q1 G& p" p" y
功 能: 屏蔽中断
7 j7 I9 t! K  C6 K: @0 |% f. D" z用 法: void disable(void); ; w: ~; {8 B  C1 n/ C
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
5 R- ]6 {' q) _, d9 _, kroutine. You cannot compile this program 1 p/ ]) X/ T0 c8 O9 t: L# M
with Test Stack Overflow turned on and
0 M: O4 y+ e; E' |2 L$ [* Fget an executable file that operates
% ^( O* S% \5 y$ d& Z; ycorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
& F$ J' i- Y1 ^# l% [#include <DOS.H>( f: c3 O# L) C% a" F
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
3 U% T, q: f+ W2 Q2 O# y7 einterrupt */ </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)
9 W- e7 B& G0 V" e& ^, _- {1 R9 x{ $ r$ V! h, t1 u! b1 m) x
/* disable interrupts during the handling of
0 B, ^8 }: v/ {7 [3 |* xthe interrupt */ ' |: I: J, Y8 X- z8 o+ H3 I, G: h
disable(); ! m# j- ]; X+ _$ b. m% G% {8 R
/* increase the global counter */
7 m4 ^' y9 a) [% W: ^3 n8 fcount++; : i+ S; H3 r$ y# N" c* q
/* reenable interrupts at the end of the
3 s8 O7 h5 K  _5 lhandler */
: }( ~- q" z6 r& L: senable();
3 M7 x& D/ B# U, i  V/* call the old routine */ . d5 P9 K- L3 q) q! `9 d
oldhandler(); ' S' K5 P! |  O) W" \* s4 y
} </FONT></P><P><FONT color=#0000ff>int main(void)
/ M3 [( F4 g" M' I  R! N2 a7 l{ 4 E' _$ s- W5 z3 \" F+ ~8 J; w" Q
/* save the old interrupt vector */ 4 G& k6 x0 B4 g  _! x
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
. V% `; E( d* j# W' o/ i" B" I; m0 isetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
6 u: {" l; R3 I( @; uwhile (count &lt; 20)
6 s" C9 g1 b- r/ o4 w  Aprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
/ a& X, r9 g, Osetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
  n; [( K  N  i% |& Z} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
$ b1 ?4 e# s  F! C7 {7 J: K功 能: 将两个整数相除, 返回商和余数
" \) O5 `2 d8 o用 法: div_t (int number, int denom);
5 H, ]1 o3 M- }& \2 o程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
* q+ Q% ?% ?5 @+ Z3 F+ y#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
5 }1 M( z# G7 u- V- L{ * G( u! g& D4 L( U
x = div(10,3);
) z! L4 c/ Z& L; A3 [printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; ! y9 x1 |7 a( C4 m' P: J  N
} - F% Z  `' d* P( \) V8 u: W
</FONT>  r; {. V: g3 k
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
: E% ^; S& v* m4 [) V: h功 能: 获取扩展DOS错误信息 ) R3 \6 R* q6 z7 G
用 法: int dosexterr(struct DOSERR *dblkp); 7 b5 K' X( e. g5 v
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
- T1 H) c# u" b4 a5 F2 c#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) , \; v0 l/ q- X% C, O7 J
{ . D. a2 A8 f* N! A  j0 k' X0 U
FILE *fp;
. a9 R. I# P# f+ w- N7 _4 h' Astruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
. d: ], s" q/ p9 wif (!fp) perror("Unable to open file for
& d% ?" a8 c3 ^4 d4 ?reading");
/ ^8 }; }" d+ q. Ndosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ ) {8 W" c3 m- V5 ^# s" ~
information:\n"); ) b5 z; A2 b! k6 y
printf(" Extended error: \
+ ?, B& V0 l  E2 U%d\n",info.exterror); ! L! F. ], G2 k* p2 E) R+ I" r) G8 j
printf(" Class: \
* o" _2 S" y+ e%x\n",info.class);
$ R+ h' ?! B$ s. j" `6 Gprintf(" Action: \
$ t7 X. z/ |* b& C%x\n",info.action); + }) `% D5 L" R* p0 @$ c% N
printf(" Error Locus: \ 6 w1 I! `' I9 k' E7 C
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
  _# P0 s7 g# F6 k3 T} </FONT>
; m* W4 ~8 K9 O; `1 Z3 ~; O7 m
3 p3 v- b! n. }7 O+ K6 F& \</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
. Q+ z8 q0 C  p) }# S  r& z' @功 能: 转换日期和时间为UNIX时间格式
# S, x" q' a; ~0 a9 {4 M用 法: long dostounix(struct date *dateptr, struct time *timeptr); ! {1 H+ m' Y2 Q# H1 @+ P* r
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>. \( p; k( m$ D! F# \
#include <STDDEF.H>
. A; i- M& Z; @6 `9 b6 ~#include <DOS.H>
& P; @+ J2 e  E+ k% N: m, i#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) & K% F- b7 J) _
{ 0 a  J0 k( ]! Z% d; y2 ~
time_t t; 4 g2 e/ H  c. v9 e7 i
struct time d_time;
) n% f7 H* q+ ?0 s* Y4 t0 cstruct date d_date; " V. m$ d! e( F4 Q6 z
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); , _7 b! Z3 |" O8 W+ N5 U4 d! t' }1 y
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
0 C' g% o+ y) c0 w* P4 e9 S. o1 `local = localtime(&amp;t); , L6 c! y  w6 n# \4 X7 T
printf("Time and Date: %s\n", \
1 u4 a) b+ ~2 \2 D' pasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; : J7 {: G9 b: E1 X# G; U
} </FONT>
+ B6 o$ A, I1 {4 [; M' b
7 u$ A& I7 D( L) i</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>1 c6 E1 x2 @: ~" l
功 能: 画多边形
* L* P8 Z$ X; t# q用 法: void far drawpoly(int numpoints, int far *polypoints);
% m6 h) v) b6 R8 j程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>3 q) B3 E. R  a& y8 _; O6 u2 L
#include <STDLIB.H>
9 Z" H+ W" N& n, w5 V#include <STDIO.H>5 r, n$ _( e' r. j- l# Z
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) . M5 x# K; s# y- Z4 q! ~; j9 R
{
6 z2 N( D9 {( K! N- t- Z/* request auto detection */
4 O4 \# U; O; n8 g4 P/ c: e5 P; V! pint gdriver = DETECT, gmode, errorcode; 1 ^. k  l4 n9 L8 ]
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ ' k. R" l5 q1 o3 X
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local % T0 m7 C3 w; g& ?/ Z* [/ t, n  y" l. p
variables */ * |7 o7 C. h, x: z! l, x
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
4 ?0 B) F7 a0 q8 d4 X2 Werrorcode = graphresult();
4 [2 z' P( j7 z6 K% o1 g$ Kif (errorcode != grOk)
* @& t( A& b* I# E+ f/* an error occurred */
9 O1 D! J) S" r5 t6 Y{ + Z- i; d! z4 H, V7 N' Z% q
printf("Graphics error: %s\n", \ * j+ Q9 L1 y$ `* |  {& U7 r7 \/ ?
grapherrormsg(errorcode)); . L) v' c. {' i3 s* ^
printf("Press any key to halt:");
7 `7 I) ~& n& @' x; Sgetch();
3 s2 b1 I7 t+ n( u' z( L/* terminate with an error code */
: D4 Z$ C- J( u8 xexit(1);
  Y% \; n: y; n- s, K+ }  t/ P  A} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); 8 S8 A7 l# f& b* ^
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ , h1 p( O  E6 p8 u7 t
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
5 U1 m. a8 U' n3 U. ?+ Qpoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ # `3 S8 H7 \- h5 U3 ^+ G3 b
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
; l( j2 ~( E0 y$ D8 E. ^- o8 epoly[7] = maxy / 2;
- {& r2 M( V# d( N/ |/* - m( G. z* i% N/ i
drawpoly doesn't automatically close
! U/ k9 L- V) b+ `' M2 Ethe polygon, so we close it. 5 o& i, a8 x, [# f
*/
9 L2 N; J; C! U* L2 Epoly[8] = poly[0];
, z! w, o! h; N7 X. U4 C7 ^poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ 9 ?  z& C& n& k5 N
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 1 o9 x6 w/ b2 U1 ^- g4 c
getch(); 5 Y6 R+ j. p( t: n. C
closegraph();
# N* e" x+ h0 V# dreturn 0;
8 q9 m1 K/ y/ C% j* C} ; B$ M3 G* k8 @$ s; G+ F
</FONT>0 M- D/ w  j, z( f0 Z
</P><P><FONT color=#ff0000>函数名: dup </FONT>
2 |0 h+ r- R% B4 A- S9 [功 能: 复制一个文件句柄
. k6 W' r1 o  V' k/ s0 K用 法: int dup(int handle); 1 }& \  I  z, C; t
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
; Y; Z; ~) J4 m8 _& P. {0 P; c#include <STDIO.H>
) r/ I* Z. ?/ D) M. E( d#include <CONIO.H>/ ?$ B8 _* O+ r! @3 W* T
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
+ n% p! h# d/ H* z0 W{
* {4 L6 w. ~# \7 |) RFILE *fp; % {3 f! @' q0 L4 ]3 [
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
" y' x, ?5 z+ T5 rfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
- p6 h$ P; p7 yfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
7 j3 k+ K1 n( W1 nprintf("Press any key to flush \
6 B9 m/ E; J6 n5 @+ ?% O: z. ODUMMY.FIL:"); 6 e/ q7 D1 S$ b/ o2 _
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
' S1 m' |+ M% x2 m2 Bclosing it */ 7 R! M2 g' p0 c8 Z& x/ c
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ : [) y  E" d) k- a9 d# t
key to quit:"); + _6 X: J$ X- q2 Q; C
getch();
% S. t' E) p7 B5 @2 breturn 0; * j1 Z3 t) x2 D, f* h2 g
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
2 o6 l. F, O& s! k{ 1 m0 c" d% n" Q1 E6 @0 n% B
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ & [" X7 w; o, V) T  n
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
$ d# I. X. @0 s' G& t4 dduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
$ |* }% V& H. Q- P+ EDOS buffer */
  D% w- }: {2 hclose(duphandle);
* _( F+ T- U. G3 \1 B4 m* X* E}
; s3 H7 d' _/ w4 ]
/ v/ P5 E) d& Q- D4 k! k1 f. n</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>- j1 G& H$ Y. e- v
功 能: 复制文件句柄
1 M! X4 u- g1 E7 `4 {+ E, x用 法: int dup2(int oldhandle, int newhandle);
$ y& H* n. N% {: D0 f' I程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
2 E4 O) o8 a- g  W$ g' B#include <STRING.H>
7 ^5 ]$ {# Z+ e3 `#include <FCNTL.H>
9 m/ ?0 i! @8 @; H4 w5 I4 s2 f#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
6 e! I6 K( Y$ Z, s9 h% O$ U$ T{ 1 k2 H5 W' [- v6 T. g" ~% F" B
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
1 _  f5 a) f2 v$ u/ `char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 3 D# S$ q6 E7 y3 e0 I
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
. V3 e' c( v/ U. BS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
+ f" |3 Q1 F) @# b- P9 u7 ?output */
9 s' X1 }# F  T. q+ B# L$ ]oldstdout = dup(STDOUT); ; a. |( \) ^1 d) ]" }: \
/*   }1 E9 ~- b' j' E2 I+ T
redirect standard output to DUMMY.FIL
, u9 h+ ?" }0 Q* A. jby duplicating the file handle onto the 5 z1 t8 Z  ~- g1 B. D! w
file handle for standard output.
9 z" H6 ~5 o  U. H*/
8 P% u& I0 a+ ~6 \! Bdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
6 O, t$ ~- A5 l  s- Oclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ & L9 {! u# T  G" V; ?
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
  j; S; ~" k+ r1 |* F: g- _handle */ 5 t8 I/ T" Q) F! N1 x
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ 6 y3 ^7 z3 J: S4 U) n" k( i
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 3 M" `/ |0 g0 g: T( F" C5 G, n8 ~
}
" P2 y* A! N0 G- z0 X</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 11:50 , Processed in 0.411485 second(s), 57 queries .

回顶部