QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2072|回复: 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>) t6 N) E. x$ ^9 N+ r
</P>) ~. M- r: }5 r9 I9 }
6 u$ p/ [) L9 Y" F

: ]) J. b+ \% z/ b, |/ C" y) M2 g<><FONT color=#ff0000>函数名: ecvt </FONT>
3 u% O4 b( e0 y' }功 能: 把一个浮点数转换为字符串
% T. f/ c, o6 |) J/ i用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
; j; o% g- r8 [+ w* z! q$ A程序例: </P>
' C. f% Y/ k4 I$ d<><FONT color=#0000ff>#include <STDLIB.H>
$ `6 M  u9 N/ J. V6 o" U#include <STDIO.H>
4 Z* ]$ x$ u7 N  [$ m3 e0 ?#include <CONIO.H></FONT></P>
' m8 @+ B! a  j; t2 _- d4 {<><FONT color=#0000ff>int main(void)
/ x0 H  b" x& z{
6 c5 A& p/ W$ H& h  wchar *string;
0 L; q% {. q+ H. f" |double value; 0 [/ Y2 b' c. m4 o& E# Q
int dec, sign;
3 z: [- k+ d- sint ndig = 10; </FONT></P>; w4 @( G- r" q5 v. y
<><FONT color=#0000ff>clrscr();
% j% T" _" h- l& F: evalue = 9.876; 8 ^$ g: U  V* \' k# [. M+ C* p
string = ecvt(value, ndig, &amp;dec, &amp;sign); * D: p$ ~; V% T  w& N
printf("string = %s dec = %d \ 8 x9 n, [* T; ?4 G  [! x  ?, n3 u
sign = %d\n", string, dec, sign); </FONT></P>0 o, W. C4 Z1 F6 N7 I6 P4 o
<><FONT color=#0000ff>value = -123.45;
0 h( N; B) m9 T6 ]8 ]& [ndig= 15; / y" _- {7 m3 H+ Z' {. o
string = ecvt(value,ndig,&amp;dec,&amp;sign);
6 M  R2 }4 s/ T6 N5 u; Wprintf("string = %s dec = %d sign = %d\n", ! d. o7 R1 P2 c& M+ Z/ J$ G
string, dec, sign); 6 I; d" q' l7 l# b
</FONT></P>
2 z* H7 ?* |" O- V9 G6 {<><FONT color=#0000ff>value = 0.6789e5; /* scientific
) V0 W' a/ b" U2 R& {: r  `notation */
: \! l+ O! u9 t' Zndig = 5;
# q7 D7 g% [* j  hstring = ecvt(value,ndig,&amp;dec,&amp;sign); ; `- d  Z4 k& M. J& R$ P; E: }
printf("string = %s dec = %d\
, e4 u' H. t) L4 _0 Ysign = %d\n", string, dec, sign); </FONT></P>' X9 q4 |% g$ E) }& Y( M6 b9 W& k1 Q
<><FONT color=#0000ff>return 0;
1 h5 k4 ^- v! A, t7 p} </FONT>) N4 D! u* y. C7 ?0 l/ g
$ c- Q1 q6 Y; N. m* n
</P>
7 p' c! k2 q7 q$ d<><FONT color=#ff0000>函数名: ellipse </FONT>
4 R. F; v% Y) l+ V5 m  p功 能: 画一椭圆
# @8 t  k# J; O9 K, Y' e5 R6 i) F- w4 W用 法: void far ellipse(int x, int y, int stangle, int endangle, * s* H; P  l' c/ s3 u, S
int xradius, int yradius);
4 V% k" S! c4 p2 H+ |! L: ~程序例: </P>
6 \! B: [) T! L% \<><FONT color=#0000ff>#include <GRAPHICS.H>  F6 _2 D3 E- y" n* R# f
#include <STDLIB.H>/ Q8 C% H/ B8 A" o' u: a2 B
#include <STDIO.H>
1 _) g) D4 Z0 ^/ M, l0 q; B$ |#include <CONIO.H></FONT></P>
* {0 [+ s( a3 l! f$ v1 Z( {<><FONT color=#0000ff>int main(void) 1 a, @8 U' v/ e5 T7 `( X- g
{ " `6 \9 F' P: s! C) i! p
/* request auto detection */ ( R2 n/ ^2 F2 s( m- L3 }
int gdriver = DETECT, gmode, errorcode; ; Y) K9 A4 H& l  Y8 b5 P
int midx, midy; , U4 q1 t- Y3 c. O% R. ]" t" c
int stangle = 0, endangle = 360;
3 o9 }, l# J! F& h  aint xradius = 100, yradius = 50; </FONT></P>
" R; m# l  K) R0 a( i7 s3 h8 |<><FONT color=#0000ff>/* initialize graphics, local variables */ ' p$ w- g& v3 X/ D
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
: g3 r2 U8 U+ c% |8 ]; I4 D: f' B<><FONT color=#0000ff>/* read result of initialization */ & l  U2 K0 h/ o+ {  @& ?
errorcode = graphresult();
) |- i- T; R1 G0 d% w$ `/ d$ Lif (errorcode != grOk)
5 M4 p2 N1 i( ?0 @/* an error occurred */ , B$ {$ ~' s/ t; ?9 r
{
: [/ R- O  g5 g+ D! _printf("Graphics error: %s\n", . i2 G# Z( {7 ?7 G9 V) G
grapherrormsg(errorcode)); * L/ I; U. |: m3 @! C: z) A7 B8 R  a
printf("ress any key to halt:");
% ^; P4 l7 J3 k; Y2 wgetch(); 7 m3 \. C2 m7 |0 H' B6 y$ |* a
exit(1); ( ]1 I7 q2 ^0 @5 V
/* terminate with an error code */ 2 [# |) {1 U) I8 ~3 O- X
} </FONT></P>
1 G0 u: U. ?. ~9 h<><FONT color=#0000ff>midx = getmaxx() / 2; 4 ]3 a8 g+ n( S
midy = getmaxy() / 2; 0 I  u6 Y! V5 D/ e$ C7 A, X5 _
setcolor(getmaxcolor()); </FONT></P>% }( [  w2 O& W3 {; _
<><FONT color=#0000ff>/* draw ellipse */
" F8 s) l* b. a, i! P3 w# U  V0 g- sellipse(midx, midy, stangle, endangle,
5 @( l9 ^8 P) `, Lxradius, yradius); </FONT></P>, X4 ]6 m7 |! x+ h$ K) |: K. ~
<><FONT color=#0000ff>/* clean up */ + ~/ w, Q. i2 U
getch(); . _9 v3 ?8 A# \( c* Y
closegraph(); : K6 t1 |; \+ \! O  f9 i* C0 q
return 0;
. i; {+ Z/ p: w5 |- @$ x} </FONT>
4 p. l% i* d0 c+ V; S! R( a) _* L& d, g; o1 ^) j2 }$ ?
</P>, x. A1 v9 W! y& i# q! o
<><FONT color=#ff0000>函数名: enable </FONT>
/ s9 Q+ C- O, q2 R/ M. w- S5 Y功 能: 开放硬件中断
4 V& {7 j  O: x6 M# ?/ e用 法: void enable(void);
" c, u. C: }6 x程序例: </P>
4 y4 S% ?/ y; r, g+ t# K' e, W4 x<><FONT color=#0000ff>/* ** NOTE: / H# Q1 B! D9 e: Q3 B) Z
This is an interrupt service routine. You can NOT compile this program ; `4 W. p8 o* K: E5 Q# l% b6 y  S- D# c
with Test Stack Overflow turned on and get an executable file which will $ ^6 [$ i! t, [! y5 p% J
operate correctly.
  U" T7 I5 I1 v1 |2 ]9 D! [1 m! C*/ </FONT></P>
3 B& m, U" U" J1 t6 f<><FONT color=#0000ff>#include <STDIO.H>
' L( A# h$ Y. ?) D; A. m#include <DOS.H>2 K6 @" M+ S5 S& W2 \% d
#include <CONIO.H></FONT></P>
. i! @! w1 ~3 [6 _" K1 ~" u% H$ P* z3 z" }<><FONT color=#0000ff>/* The clock tick interrupt */ ! h2 K8 y- o, p1 z6 v/ I7 ?; j
#define INTR 0X1C </FONT></P>
/ j. H" B0 L+ {' |% L1 S0 \8 x<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>9 X5 @4 R' D- I9 F" K7 ^. ?- |8 [' s+ \
<><FONT color=#0000ff>int count=0; </FONT></P>
" c1 R5 R$ _6 \1 _, M8 Y& U<><FONT color=#0000ff>void interrupt handler(void) ! x& G0 i  q( B2 w) s8 l  C
{
  y. x% m0 f4 ?" G' F7 ^/*
7 L1 R: P" ]1 {$ {0 ]" f' ydisable interrupts during the handling of the interrupt
. W5 s( {. O0 s1 r2 ^: {" g*/ 7 A" f& f0 i. ]  k" Y1 \
disable(); . ]: A  a# M! H0 N
/* increase the global counter */
$ g5 F* e5 G( I+ Y, |' n" wcount++; , [/ v- u. L& X  Q7 v: q5 `
/*
; r1 _$ Y5 R' U3 S0 ~% J9 F" Xre enable interrupts at the end of the handler
. \. m* Q! \4 N* W& k*/
. U5 K/ V' G3 |7 Oenable(); % U9 Q5 \' j9 F! _! R! y$ ]
/* call the old routine */ 6 y+ f. n! `9 q2 l
oldhandler();
+ c( d  D) w& r/ ?3 W/ U/ R% n# C} </FONT></P>) ^& O% r0 _3 \3 \3 I4 M" q/ M
<><FONT color=#0000ff>int main(void) 8 I1 m. ~0 n- {. C% \/ I, W
{ ! F+ S8 Y, E/ Q# y8 m/ N! V' @1 f
/* save the old interrupt vector */ " c( q0 X' Y2 L/ v# g
oldhandler = getvect(INTR); </FONT></P>
$ R) j3 t+ [4 A3 N9 H<><FONT color=#0000ff>/* install the new interrupt handler */
+ {* ?) r; D9 e$ s8 x2 G+ ysetvect(INTR, handler); </FONT></P>
% ?; g( u; r& ^0 B<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 4 k. t- g7 f% D0 f3 I
while (count &lt; 20) $ }5 }% p6 r5 p: }. N4 H9 ]: V. _
printf("count is %d\n",count); </FONT></P>
: s3 O: w+ `& t<><FONT color=#0000ff>/* reset the old interrupt handler */ 3 z/ G- i+ j! t! |
setvect(INTR, oldhandler); </FONT></P>
3 A# `6 z: s; \) l<><FONT color=#0000ff>return 0;
" Y7 }- C4 U8 Z( b& a. {& ~$ c} </FONT>) I/ B) V. f9 b3 y! S5 E3 ~5 h

$ W3 G) J  e" U* p: l( K</P>0 V3 G% K+ B6 O7 ~% G$ }
<><FONT color=#ff0000>函数名: eof </FONT>3 Y: |: b, E, h% v6 c3 a7 W  j
功 能: 检测文件结束
; T& p# ~" D# I/ u$ Q- a用 法: int eof(int *handle); . ], M$ |) V, t  r, O6 A# K; d, h
程序例: </P>2 M  Q( h5 n+ v7 y
<P><FONT color=#0000ff>#include <SYS\STAT.H>- e6 S2 l3 d; G
#include <STRING.H>
8 C5 @9 I' ~( f: V#include <STDIO.H>2 x  J3 b, b+ v, ^& s4 u+ U( i2 X( J
#include <FCNTL.H>0 ^; Y7 G1 c) \* R4 [9 u
#include <IO.H></FONT></P>; d* ~- F5 F. v0 z$ A0 ]
<P><FONT color=#0000ff>int main(void) 9 E2 D" y2 c( T: G2 b( C
{ 0 U+ a7 g* x: u' W" ]% o
int handle;
( \+ q  q9 A( `+ q8 fchar msg[] = "This is a test"; / O, c4 ?1 I- q  H; y" U4 C
char ch; </FONT></P>
! V. l3 P3 x. k( A<P><FONT color=#0000ff>/* create a file */
! b& w% ?1 I& \% Khandle = open("DUMMY.FIL",
: g  i3 @. |) y* r6 Z5 J3 s! C4 \O_CREAT | O_RDWR,
4 I5 h7 Z7 u, f" d! CS_IREAD | S_IWRITE); </FONT></P>9 B- h& ]; g+ u3 ^
<P><FONT color=#0000ff>/* write some data to the file */ % y( d# k+ @* V  b# r
write(handle, msg, strlen(msg)); </FONT></P>
# d# A/ o9 A" f% ~2 S<P><FONT color=#0000ff>/* seek to the beginning of the file */
$ e$ {9 G  y; ?. [$ ^! T+ Olseek(handle, 0L, SEEK_SET); </FONT></P>
  x6 P2 q, S7 a" z<P><FONT color=#0000ff>/*
( ]) S2 w9 m+ J, Treads chars from the file until hit EOF
) A6 @8 l* `8 ?*/ * q7 Q1 o0 y8 n2 N4 E4 ^4 O# o
do   `: Y* ~# f. k. b
{ % U9 Q' s+ b+ I6 V: d, e
read(handle, &amp;ch, 1);
) B9 O& e  h: ]; q8 w! s( j6 }printf("%c", ch);   H3 G' f9 l$ @3 }
} while (!eof(handle)); </FONT></P>
" o9 K- W5 M3 H: ^<P><FONT color=#0000ff>close(handle);
  A/ i3 e5 q- N. nreturn 0; 3 u: u1 L& k* l# ^4 g7 [) u2 e  \
} # l6 Q# m8 o6 ?: E/ P: b) p0 U
</FONT>) Q5 I" n$ ?1 D7 U
</P>
0 u+ V' T, z' b/ A( i8 a<P><FONT color=#ff0000>函数名: exec... </FONT>
5 K  M( J* ?4 F  e) f功 能: 装入并运行其它程序的函数 : b7 I3 z1 V1 U1 h9 ^
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); 9 x  W$ r, z, e" _" u% i
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
& B- ]$ h; s5 l- s* Zchar *envp[]);
6 }: ^" {5 g! Hint execlp(char *pathname, char *arg0, arg1, .., NULL); 5 k% U  ?! T" h' o7 ^0 G- S3 {
int execple(char *pathname, char *arg0, arg1, ..., NULL,
( d0 N; V1 @+ m# t& Q7 rchar *envp[]); + e% L4 W" U9 j, ^+ r% h/ [% h* P
int execv(char *pathname, char *argv[]);
: p7 O( a( L! ^" g6 ~int execve(char *pathname, char *argv[], char *envp[]); 9 d" U/ J; A+ J. ?9 G5 z8 O
int execvp(char *pathname, char *argv[]); 5 g0 L( V9 i! J8 m; h  _
int execvpe(char *pathname, char *argv[], char *envp[]);
, T) y+ J: |# v  q  H# \) \程序例: </P>! |- U* [! ~% W& \" E# f" ^
<P><FONT color=#0000ff>/* execv example */
/ {! E5 M. }4 G% |! Q#include <PROCESS.H>
. p( e! G+ g6 a* u: ^! l#include <STDIO.H>
: x! I* j1 {6 `3 ~, k3 Q  X#include <ERRNO.H></FONT></P>6 m5 G9 p( `4 Y, s
<P><FONT color=#0000ff>void main(int argc, char *argv[])
- D4 \! g3 L+ w{ / P' `- c- h- R8 G, w( z
int i; </FONT></P>
8 z0 c2 S2 v7 {2 K- @* H<P><FONT color=#0000ff>printf("Command line arguments:\n"); & P  q% E# C) j; G* ?
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
* H7 g$ i- w- B: z! I, y  O% I<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
$ L* \3 z; r5 `) D) p, nexecv("CHILD.EXE", argv); </FONT></P>) ]2 p, K. r0 j
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
- C- A, @# X7 e9 j( H/ s! e. j<P><FONT color=#0000ff>exit(1); 9 e! B0 R6 S9 o2 B0 A( s( R% m
} 9 {, S" {  h, B: A( y3 T- K3 w% P
</FONT>
1 c0 p0 R3 ?% {- D+ Y1 k) B2 V' F</P>
$ `2 N; x" r2 ]0 Y! F<P><FONT color=#ff0000>函数名: exit </FONT>( f' ?8 |) J) a6 {: {! P
功 能: 终止程序 7 {3 E1 e9 k7 s0 H8 q2 m
用 法: void exit(int status);
( E' P! S/ r/ D" M8 I程序例: </P>
2 a3 ^" a) d! H1 w<P><FONT color=#0000ff>#include <STDLIB.H>4 B9 z/ y2 d2 U" e- q: F, f2 C
#include <CONIO.H>
" w2 i+ p$ L; q7 u8 ~#include <STDIO.H></FONT></P>
) [9 S1 d9 {' A1 N$ f<P><FONT color=#0000ff>int main(void)
8 I+ ^9 {; v8 _& \2 O; X$ i{
- C, w$ c; {6 r7 N* u" vint status; </FONT></P>" K. c% s7 i7 ~/ Q
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
9 D& p3 z6 u* p6 H/ o8 Jstatus = getch(); 2 V6 _! u7 K/ a% P4 W
/* Sets DOS errorlevel */
5 ^  j1 g! t+ ]/ E) Q. D. d0 Wexit(status - '0'); </FONT></P>; t& q; y% Q  q) B- x+ d. q. Y1 A. e
<P><FONT color=#0000ff>/* Note: this line is never reached */
0 C3 C8 {" r7 e( \return 0; 3 m! u6 l/ b- `: z
}
9 I) q! a! n. |+ d# K1 |+ s( S$ \</FONT>
" f4 L. ]0 O: R" ^6 P: O) ^( Z</P>1 I4 A  ]# B$ s* w. `# F0 w3 P6 G
<P><FONT color=#ff0000>函数名: exp </FONT>/ c/ D: e4 s) n- ]2 S, ^: Z& }
功 能: 指数函数
: a5 Q/ p0 z% n, q* M用 法: double exp(double x);
! H4 k2 c! M, v, Q- N6 n) v$ L1 V' w$ `程序例: </P>
! V( i- N: s6 x$ M<P><FONT color=#0000ff>#include <STDIO.H>
$ w' n5 D3 Z6 j; k* g#include <MATH.H></FONT></P>
" H. U7 W, P& x* `<P><FONT color=#0000ff>int main(void)
6 I/ G. B  j, D7 G0 |! A" O/ a{
# _' H' ^4 [2 h2 S, ^( l1 d0 R0 Ndouble result;
; N, D  s2 B1 k" U/ F2 `' Wdouble x = 4.0; </FONT></P>5 |$ d7 G% q0 k2 f
<P><FONT color=#0000ff>result = exp(x);
2 C" d) h/ l9 r* a7 a$ Yprintf("'e' raised to the power \
$ d$ a: ?$ g: g4 P, Qof %lf (e ^ %lf) = %lf\n",
& i3 J( {* K' m4 P) Hx, x, result); </FONT></P>4 M# X( G! B5 N3 x
<P><FONT color=#0000ff>return 0; # X7 y1 \) U! d  I" d
}' W5 m. I8 `3 E  Y0 W
</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>& b; m* _8 O7 f* q6 v* k2 G
</P>
" q# R9 A3 v4 U/ Z7 t- ?" A" K4 r<p><><FONT color=#ff0000>函数名: delay </FONT>
8 D/ e+ g  g# \) H功 能: 将程序的执行暂停一段时间(毫秒) . |7 p' ], K3 y
用 法: void delay(unsigned milliseconds);
- X( j! A- l8 @% M程序例:
' G4 k  n! s$ i" k, C5 U<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ) f. x8 A' n  V; x+ }4 l* z1 @
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
& d7 ?5 X* z. w8 ?. C" d{ 4 g3 B! y; K5 r; _  g
sound(440); * A( t  V  [( g0 l
delay(500);
8 B, i3 a- l9 |4 i! i/ D2 Mnosound(); </FONT></P><><FONT color=#0000ff>return 0;
5 ?. w, {+ L" r! F3 G) {# I} ; k- L! K: r2 {& j* @
/ z9 r0 }5 P; U+ ?9 {! N  l3 r
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>' \* M5 @8 P" C5 u
功 能: 在文本窗口中删去一行 & \2 u6 c* _- @( a8 J
用 法: void delline(void);
4 \/ n$ |& x! w* s程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
4 G% X3 r3 J. I{
8 W7 D# S: U9 n; }6 S- b+ pclrscr(); & B/ t! ~5 Q( S  c& P
cprintf("The function DELLINE deletes \
/ L  i; }: Y& K. lthe line containing the\r\n");
( X9 l* `4 r4 y1 `: ]6 g1 a  Tcprintf("cursor and moves all lines \
& X+ W) D. w: abelow it one line up.\r\n"); ( j3 H0 T3 t/ K, E5 m
cprintf("DELLINE operates within the \
, S) @2 z4 b0 p7 C( t3 Mcurrently active text\r\n"); / c% Z. d* G5 x1 M% @5 H- E4 _$ J4 c
cprintf("window. Press any key to \ $ _  S* j( E3 N3 U" j  O- f
continue . . .");
5 m1 w3 D; L5 N* c  l( L0 i) Sgotoxy(1,2); /* Move the cursor to the 4 N0 l2 l% _6 o( \; }
second line and first column */ & w% o4 }4 }$ n4 M9 d! q' d' z
getch(); </FONT></P><><FONT color=#0000ff>delline();
) a$ ]: O8 v7 u1 Cgetch(); </FONT></P><><FONT color=#0000ff>return 0; % h1 w) l' T5 {/ @
} </FONT>
2 M8 ~2 G) w$ }8 k0 a& C( o9 p3 e" x' `5 x</P><><FONT color=#ff0000>函数名: detectgraph </FONT>% G; C: @+ J0 o
功 能: 通过检测硬件确定图形驱动程序和模式 # W6 r/ W' F; g) G) Y  B' G
用 法: void far detectgraph(int far *graphdriver, int far *graphmode); ) d$ J7 c. w5 z
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>$ z3 O. U7 E( g0 n2 x4 j7 b1 W. ]
#include <STDLIB.H>
! F: E3 l6 [) X! J3 j1 f#include <STDIO.H>
# T8 Z0 c9 q" c. \  P7 ~4 g#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
  {* ~. E2 O! W$ @: O, u3 Ochar *dname[] = { "requests detection",
( f4 \6 b4 q; E"a CGA", 1 \5 T& O/ E2 [/ M) ?& D
"an MCGA",   U9 n# X5 s. Y9 q7 I
"an EGA", # f( ~# G1 ^2 d4 X, e+ w5 K- [' \
"a 64K EGA", : Z$ ^/ \* h3 J5 i
"a monochrome EGA", # L3 T6 y  `8 G  t
"an IBM 8514",
5 p% W. u+ ]' r, i"a Hercules monochrome",
  t$ Z7 D1 |& f3 }3 V. j7 X"an AT&amp;T 6300 PC",
' H. ]) I6 D3 A9 m( n+ ~" a+ y"a VGA", . G+ h' f/ C# u
"an IBM 3270 PC" * V- l3 ?. p  ?6 \9 d3 \$ P$ j! k
}; </FONT></P><><FONT color=#0000ff>int main(void)
- A2 @* F. c. ?, R' W{
) \% F* P6 _7 i" V$ B9 L/* returns detected hardware info. */
$ O; q& o; P9 E5 _; X! L; P9 Jint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
# y/ `2 M) }2 E7 |detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ % V% ]9 r7 b" \
errorcode = graphresult();
8 O4 K2 [7 {+ K) o2 d* ?if (errorcode != grOk) /* an error
: s( z: k2 Q$ Q$ ?* y! ooccurred */
% X% p4 G$ j+ Q) n1 T( X0 c/ L{ 1 ?% ?! a, l% \! O2 c6 a0 ]
printf("Graphics error: %s\n", \
$ L8 C) j  A# `- {  `$ egrapherrormsg(errorcode)); 7 e" K1 c' R% _3 O
printf("ress any key to halt:");
1 q" }, F) `  c5 y2 \0 egetch(); - W3 n7 ~8 i. {9 r9 [, P
exit(1); /* terminate with an error
0 |. y8 N1 O7 G1 Wcode */
* V7 O% F, ?0 p} </FONT></P><><FONT color=#0000ff>/* display the information detected */ / C5 `3 E8 M+ |2 q; u, D$ R
clrscr();
0 T& r8 g( D# W- mprintf("You have %s video display \ 8 h7 a8 _6 n" R( u  J. P& T
card.\n", dname[gdriver]); . i2 |1 h% L6 I- f9 u/ G# n8 Q
printf("ress any key to halt:"); 0 I6 M( x  ?% ^+ j8 t
getch(); 7 Y' K0 }; A' f' y4 v9 c
return 0;
0 I, N6 X3 p& ?: a9 i# j. U} </FONT>
  ]% D: S6 S6 U! O2 L9 d" d/ k$ C- Q( D5 l. G; T

7 L; ~7 d) c/ B7 s. D7 ?. D2 X. j) \</P><><FONT color=#ff0000>函数名: difftime </FONT>4 A( w1 A& a9 F0 h, d  }: \8 {! {
功 能: 计算两个时刻之间的时间差 7 j8 Q/ y( Y2 v% H* d
用 法: double difftime(time_t time2, time_t time1); 1 ^) u: m/ _* ?3 @$ Y2 n- W
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
8 x: R" t: d; C' C9 y* e( Y#include <STDIO.H>4 i; c+ r# x  H3 F, O; s* h4 C
#include <DOS.H>
9 Q. ?  D$ @. z( o9 x* T  \/ i" h#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) " m6 `7 }' f% g! p, W# E* a7 L
{
0 F8 f, L* g, t5 s3 Z& Otime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
" _. M" A( ^# s3 _  O5 Zfirst = time(NULL); /* Gets system 4 m  L. f6 r. L9 `9 [
time */
9 U" R7 [% P' w3 c  h6 p; n7 Adelay(2000); /* Waits 2 secs */
  S6 [( T* N2 `4 N; u8 }second = time(NULL); /* Gets system time 2 v7 |0 _4 V# Z3 r
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
$ U8 v9 K# c5 O6 v, r) [4 ^2 Sseconds\n",difftime(second,first)); " p! I7 G. j( Q' s2 v
getch(); </FONT></P><><FONT color=#0000ff>return 0; / L9 a  w8 E, \: l# ~: }
}
+ q4 o0 O, i$ s3 R1 {( c</FONT>& P1 v6 [0 V2 q% q
</P><><FONT color=#ff0000>函数名: disable </FONT>* j. _+ J$ t9 b2 s
功 能: 屏蔽中断 # i  e2 J7 i% e
用 法: void disable(void); 3 C7 ?" b! c0 }1 ]' v
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service ) ]6 w, j/ I4 l# r0 G" M$ U
routine. You cannot compile this program ) m( H3 U' P" v/ V" h, K* y) X+ k
with Test Stack Overflow turned on and
+ B5 |: u3 K# t4 D2 ^+ z% ]get an executable file that operates
8 M7 O8 P9 C7 {( W& N0 m2 ^% dcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
5 ~" B+ @' ?: a#include <DOS.H>: e1 e0 S( B/ f. Q4 p8 X2 t& M4 L
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick ( |5 Y1 P9 }2 F8 D8 q+ O" e
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) 7 N: ?5 S5 ^* U- e8 C9 j& w
{
- J3 H$ ?# o/ [; I) Q/ }2 c$ Q6 |/* disable interrupts during the handling of
6 f2 k6 {1 L# O; ], uthe interrupt */
& c+ ^7 w6 k* P! p) X& edisable();
5 j. U! Z8 L: ^+ p" g- ]0 X9 q/* increase the global counter */
. U( E$ r0 G( G) t1 icount++; % b! d8 x' D( {3 Z& j3 R/ F5 z
/* reenable interrupts at the end of the
7 M; T0 @: o* P$ t" c# Phandler */
9 `, P! y" [, E3 tenable();
$ l" g. R3 S, i+ n, u" a/* call the old routine */ " T" a* D' Q0 u! a  g  e9 ^6 b0 Z
oldhandler();
5 _( D3 @& `7 ^$ N  ?} </FONT></P><P><FONT color=#0000ff>int main(void)
" K) T- G; d/ d9 {0 L* E{
, Q6 ?, {+ r+ D* D$ N) Y/* save the old interrupt vector */
: d" ^3 n* E1 L4 L0 G5 F$ ]oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ " Y9 J5 O9 O! h
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ & `" s0 M! ~3 E! B! ~7 D! s- O
while (count &lt; 20) 4 W. Z, j% T0 }; u9 W( H: [
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
6 D/ _. i- ?' z& q* f7 V" {' _5 wsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; ' B( m! F8 H7 i
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>2 G. w; W) C* p' _5 O8 s
功 能: 将两个整数相除, 返回商和余数 5 b" U' ~' C! Y) A$ o( |$ s/ `
用 法: div_t (int number, int denom);
2 ]0 L# `, [  X9 B, x* k程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
6 r) K9 J1 m7 k+ a$ F0 ]#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
. J( q: A0 t' x" a6 m{ . g" x4 o+ `% R" O8 P+ N
x = div(10,3); - h- @7 W. ~! E; z( j
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
4 S, H+ O* e1 m2 L: E} 7 ~  s) L+ @4 q* s/ W. O
</FONT>1 X! s. G" W2 Q0 Z( E% E7 n
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT># h& ~9 V, x! ]8 Z! d& G: g( ^
功 能: 获取扩展DOS错误信息
+ i0 L; m  ~' v- U用 法: int dosexterr(struct DOSERR *dblkp);
1 o8 R/ w7 o8 h1 y程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>$ f( j0 F  r# T" |
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
+ [0 H- k' x2 j# A3 T; V- z{ ; ]3 g4 E7 c& S. `
FILE *fp; # Q) l+ Y& A) S2 f! m- m# ]
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
! x1 {8 W5 y( Y3 o/ y) Jif (!fp) perror("Unable to open file for
% q* E/ u) z. J4 Y; d1 }( O  hreading");
! I( D$ J& r% U1 T* |. u. ndosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ . Y, R5 I* Z( }
information:\n"); 0 y4 ^; B8 F5 `4 q' J  l
printf(" Extended error: \
# B5 P9 f: @+ C- Q5 e6 Z8 q2 I%d\n",info.exterror);
- W3 L5 x8 A) Y$ N6 v+ ]printf(" Class: \
: k1 `4 M# k( W9 ^  N( a2 y( V%x\n",info.class);
! @1 Y3 v$ f: R( f# k: bprintf(" Action: \
( E. ^! d4 H! [* ~" D%x\n",info.action); # l6 m5 l, D) X  C! z- c1 t% D; A
printf(" Error Locus: \ * _: \8 S8 J/ c5 Z- A. [
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; + f5 N, b( m* ]2 N
} </FONT>
" q1 I( M8 c: M" v4 a. W
1 s- }$ w! ?3 X$ n2 C- e; f+ c% U</P><P><FONT color=#ff0000>函数名: dostounix </FONT>' J; T/ Q/ Q! b. B/ Y
功 能: 转换日期和时间为UNIX时间格式
2 V' X' P4 B5 ]用 法: long dostounix(struct date *dateptr, struct time *timeptr); / k0 ^0 B" J& T) l  V7 \
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
+ c; n$ W3 f# m  ]" f# F7 Z#include <STDDEF.H>
* R0 u/ `- x# Y* m  A6 q* q0 N" s#include <DOS.H>
3 Z7 h) l  n/ E7 d. K' B- c#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
3 J4 t  q$ i) ~: g{ 4 y$ F0 W' H4 |- t* J4 @) @
time_t t; ) [; }& ?# J: }! N" l5 ^( z
struct time d_time; : L4 s7 z& A9 ~5 J$ K3 W( e
struct date d_date; ' y: n2 f6 m' A
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
" I  F$ E1 Z. H1 S9 V( D. ~9 O+ y2 B5 sgettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); ! d1 d2 t) E& \, z* Y7 Z& a7 P
local = localtime(&amp;t); 8 L* l1 ^: p( I$ Z1 ^) \+ `- E! Q/ W6 b9 h" Z
printf("Time and Date: %s\n", \
0 e6 a/ F1 H+ n9 Oasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; 0 T: S2 }; r6 Y. K8 E6 w3 u" J
} </FONT>
9 W* H* C+ B1 y! o& w
$ w; G$ i; W/ g% |</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
: y, s8 C' }" ^/ c! D功 能: 画多边形
9 d+ V/ W  Q" j& e4 W  {! ~用 法: void far drawpoly(int numpoints, int far *polypoints);
. E, P6 H/ J. n$ _/ W: E$ x程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
& z2 d5 E/ r; ~6 Q#include <STDLIB.H>0 \! Y* M# S, K2 l) i! G) ~
#include <STDIO.H>
' z: a8 S% R- F2 |#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
( z' z0 s6 R6 Z! Z{ 3 x8 k8 _% f( D, i
/* request auto detection */
  u, s* G' g3 g* B3 T' dint gdriver = DETECT, gmode, errorcode; - o2 V* m$ [: ?  n- U% V* t+ W3 d
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ 4 e8 Z$ r# O, d9 k( L4 Y& F
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
6 O+ Q$ ?9 l: u. s8 G4 u- x# E5 J: P$ bvariables */ 4 q- a- E  [4 P  |' H" w+ x, }
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
: `6 U; x4 p" ^/ T7 i9 herrorcode = graphresult(); 5 _  ^) s  Q2 h) T2 \7 b
if (errorcode != grOk)
. P' U) W' T% L4 t# v# {/* an error occurred */ 4 o" c2 ~6 S& K3 m: ~/ y! r* t6 m
{
# @5 ?' n- A0 ?6 `! rprintf("Graphics error: %s\n", \ * z, V! `6 t3 Z3 a* G% n2 x0 X: z) U, W
grapherrormsg(errorcode)); # Y7 A0 q2 p+ l% T
printf("Press any key to halt:");
5 @7 V- }- d0 e) E  Q! ^' ]getch(); 1 N5 T2 E# {% C! E" W  K5 \
/* terminate with an error code */
! N0 N. X( M0 e( G7 Q# T5 A) {exit(1); $ O" `. ?+ B5 f# E  |" ?* s
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
, P: W4 Q, s- }0 ]1 g  fmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ 4 I# E$ C6 P; s' b7 m
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ # l4 n7 R+ Z5 q7 \4 x
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
9 l* `7 W2 m+ X3 o: Z0 Jpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
% t. h3 G3 ^! M4 j! h8 t9 X, f# npoly[7] = maxy / 2;
2 ^, c/ Z1 S, m& f- g$ G3 c: j/*
* z/ ^7 \. A; Zdrawpoly doesn't automatically close
8 j5 g; Q$ y' U% [the polygon, so we close it. ; o' D; W2 l% x& v& z1 L8 p' j
*/
6 c  W3 B, a. I* R' V" [4 t: cpoly[8] = poly[0]; / n0 ~- k3 }" o% H
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ , u4 ?4 ^  o; V8 v7 D
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ . [5 @& j7 g. a: G
getch();
, c/ I* D- n& K8 rclosegraph(); / `/ r# z' p" J* @: Q* @
return 0; " M3 v7 H) j; D2 V0 [
} ! k  T0 h7 k" p' f6 z5 z
</FONT>
9 m" d; U3 `7 r. ]</P><P><FONT color=#ff0000>函数名: dup </FONT>
' Y6 E& o0 m# n功 能: 复制一个文件句柄
5 k- X' o3 A4 h6 i: n( E; t% _: k用 法: int dup(int handle);
, `3 P. ?. O. U5 v程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
* O- d* r6 U; _# ~6 I#include <STDIO.H>% h; D& f3 t; z$ G2 w( j
#include <CONIO.H>8 {7 U6 J/ s! v4 Y
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) ' k; h5 A! Z" T& o7 m+ K
{
. ?6 }" X: Q6 }/ S( J- UFILE *fp; 6 o7 x" Z& E: |5 g
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ % N) I! n6 B( s$ D' y: {
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
6 M2 S2 K6 x) ^fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
  M5 i$ q9 S& x$ ~1 Vprintf("Press any key to flush \ : G' `% \9 b- P4 u) B0 q) l
DUMMY.FIL:");
/ g7 ~. ^- J9 r7 R& wgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without , Q. b7 o- U) h: i2 J, P
closing it */ ; v$ I. O& Z$ d: Y5 @! K
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
* D- B$ K* ~: P  c. W6 Okey to quit:"); 0 _) n9 P2 T# G8 @0 c
getch(); 4 b( I& }2 Q  X1 N6 ~' ^7 E8 v) l
return 0; 2 J, ?0 c( h! r1 F" H' q# c
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
- f: ^" ^  q. Q' d{
; c3 C3 F* b* }. D) e: s8 eint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
* r" m9 ?! b/ l% vfflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ # s. J3 F9 P0 f; Y0 G; e
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 6 K+ @3 t! A* v  ~4 z6 X
DOS buffer */
: h  p3 o# ~/ t# l2 p$ t7 r# U; Bclose(duphandle); 7 \; i. O# |" b$ E2 C# k$ W/ f
}
. M1 A8 ~" ?% a# ]  l8 s& [: K; ^0 U) H- [4 E
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>3 L7 L  E/ e. A9 ]5 u0 N
功 能: 复制文件句柄 3 T6 h% v; k+ p- h; k7 \
用 法: int dup2(int oldhandle, int newhandle);
5 G* D2 z. a2 |4 \$ d+ k" a% f程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
, @; r, f" ^; [8 h: A7 h" w( ]+ l#include <STRING.H>( y% G6 L2 I  `* W- ~  w: z
#include <FCNTL.H>! ^" k  v+ K3 J8 B5 i  b3 F
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 7 \7 Y7 N8 P& V' c, z
{
& w0 h( ^5 {* [: p#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; . D  {1 W  \# E4 V- C, P% r
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
: E" E/ ]% ^! I( {nul = open("DUMMY.FIL", O_CREAT | O_RDWR, + K2 \+ ?/ Y: \" B) U
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
4 ^( G! N' }9 z% J' v1 }output */
1 m9 u4 G6 ], L9 C7 ]9 Eoldstdout = dup(STDOUT);
. f' T- i( @( v/* / q: j7 w; O# L) @& u6 \
redirect standard output to DUMMY.FIL
5 P; e- u. Z9 _  X' Q# Lby duplicating the file handle onto the / ^! J( R4 `& R+ X
file handle for standard output.
; x1 m3 r2 V- l; e- W& T5 \*/ 1 U; m, b$ Y/ P5 Z9 U* @, p
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
  S8 w( Y6 F4 G" J: l3 aclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
& ?+ s9 T* s9 q, @write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
( B$ X1 n" H* L$ h$ o% shandle */
4 m& I" G- z7 p* x6 I  @# z$ t; Sdup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
% n; }, z8 J1 w$ b0 d5 Fclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; # y1 T6 M* Q2 {
}
1 j, P/ n* N7 E: s: r</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-6-11 10:07 , Processed in 0.360197 second(s), 56 queries .

回顶部