QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2073|回复: 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>9 T5 H8 k( a3 d9 Y9 A( }: \
</P>
5 J  z9 H# r3 v0 O5 m
  |/ x) z# d) ?7 W* H9 z! R$ l( c. s% I: S
<><FONT color=#ff0000>函数名: ecvt </FONT>+ F8 o$ \. S% r7 k# U
功 能: 把一个浮点数转换为字符串
% @3 h. ]- U! f& A# Y  y用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
9 i# X8 `; p% g& \8 K程序例: </P>0 x; l9 ], p. E9 ]. e6 s* p
<><FONT color=#0000ff>#include <STDLIB.H>
- q/ Z* x* ~: v5 D- w6 M. |#include <STDIO.H>
9 Q7 R) B8 o9 C7 b; x" t3 v& b* X#include <CONIO.H></FONT></P>) ^% {' C: S6 C. T  D8 k
<><FONT color=#0000ff>int main(void) , t& G& J6 [) R' U; |& r
{ $ H+ E# V% c2 Y/ Y; b: B9 r
char *string;
2 s4 @! b. |2 i( D- d5 B1 E, Idouble value;
9 o. L9 w- U) I3 S3 E- w) k; Bint dec, sign; + j$ p7 X$ T. V3 j, E, K
int ndig = 10; </FONT></P>
# x- A- M" r1 D5 h+ N<><FONT color=#0000ff>clrscr();
9 r: y* {$ ~; Y. i, L! avalue = 9.876; 5 R! E' V0 u/ X# ?
string = ecvt(value, ndig, &amp;dec, &amp;sign); # _- _3 `! V1 A6 |$ {) _
printf("string = %s dec = %d \
; n! a6 E: D$ U. `% J$ @3 C$ A! V" ]  Y- `sign = %d\n", string, dec, sign); </FONT></P>
2 n6 e5 b, O* v/ Q) l+ F, F* @<><FONT color=#0000ff>value = -123.45; " o8 _+ S4 Z7 s5 p
ndig= 15; - u" H2 ]# n/ _7 _/ k6 z& X& k7 s
string = ecvt(value,ndig,&amp;dec,&amp;sign);
8 T  v% u% r1 \" h% Q) ]4 Y2 _printf("string = %s dec = %d sign = %d\n", 9 u" q; [" y6 G) ]9 q" W
string, dec, sign); ( u/ n6 v+ ]9 R! j
</FONT></P>; N9 M! h+ N% S
<><FONT color=#0000ff>value = 0.6789e5; /* scientific 5 z# x; E6 a/ Y' V/ F  M
notation */
% a4 n$ X+ `' X# N9 nndig = 5;
8 o/ C+ ^2 b4 a/ pstring = ecvt(value,ndig,&amp;dec,&amp;sign);
3 Z& c2 N  A. x% qprintf("string = %s dec = %d\
5 A* r) G  I) J  S9 Rsign = %d\n", string, dec, sign); </FONT></P>9 T1 {7 ^, h+ U" n! C! \
<><FONT color=#0000ff>return 0; * Z0 ^! q) C8 o& S. v2 B
} </FONT>
6 H, d9 \, `0 R+ R5 }9 ]$ `3 e) ^% G/ ~, T- G- d' m
</P>- ^3 p$ J# O: M! M# r3 v, }
<><FONT color=#ff0000>函数名: ellipse </FONT>. d4 B! p% E6 Q/ z
功 能: 画一椭圆
! \& v, l; M& X& \用 法: void far ellipse(int x, int y, int stangle, int endangle,
/ H2 S; z9 B' ]! }int xradius, int yradius);
! M9 F1 d' X  b6 z- r程序例: </P>
6 p0 ^$ f' x" q# v* f- b' d<><FONT color=#0000ff>#include <GRAPHICS.H>
- q' W! \9 N/ s' g! w8 v- }#include <STDLIB.H>
. z8 x* \$ X9 i! g1 `2 e9 I1 M, ?#include <STDIO.H>
/ k, C. a' a1 [3 B# ]9 I; T#include <CONIO.H></FONT></P>
; s1 G7 F/ C& N8 t/ K! b& l9 d<><FONT color=#0000ff>int main(void) 3 v- k% _5 i, ^, o% l
{
( e2 t/ O: u; E4 `# v9 t/* request auto detection */ / J, y  c7 g, d3 g; w; B
int gdriver = DETECT, gmode, errorcode;
7 C; c/ Z: B: ^, L, S; Aint midx, midy;
2 t: K$ u9 c5 z( K$ i5 i6 C. fint stangle = 0, endangle = 360; ; \- T+ _0 a+ t
int xradius = 100, yradius = 50; </FONT></P>& F4 L% f& i/ L2 l9 j, d& V4 q4 P5 b
<><FONT color=#0000ff>/* initialize graphics, local variables */
% x" E& y& Y$ vinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>! N6 e4 t7 d1 J0 H# V% V9 C2 P
<><FONT color=#0000ff>/* read result of initialization */
! }2 }/ i/ e. N  S* y! k6 }errorcode = graphresult();
& h. z: y9 N6 o% a& O1 ^if (errorcode != grOk)
7 }7 t  a' z7 C1 x7 m/ ~5 @/* an error occurred */
: _6 ]2 P, N9 H' T+ e{ * @5 L: z( w  K/ b! J1 L
printf("Graphics error: %s\n",
, S1 Y  l$ G$ j- V9 N' b. M( `: F. agrapherrormsg(errorcode)); 9 |3 A. M; x; c+ ]7 x0 |/ T
printf("ress any key to halt:"); ' N" u6 \9 Z! X- s8 K( _& {) \
getch(); 7 M6 S0 m' j7 K3 w' ~  H0 E% @* h
exit(1);
4 {: }# s( ?6 d4 K5 [' V4 {2 x- l5 \/* terminate with an error code */   R9 S$ N/ i) f+ ^% }% l3 o
} </FONT></P>$ _# r/ d( {, O) ^
<><FONT color=#0000ff>midx = getmaxx() / 2; , U( A" O. ^4 T  q: a" Y7 _2 G! b
midy = getmaxy() / 2;
0 {) ?: u8 X. x) @8 G$ g; @6 [$ wsetcolor(getmaxcolor()); </FONT></P>) x& q& S4 J/ h
<><FONT color=#0000ff>/* draw ellipse */ 3 r4 Q( i! p2 E6 |* Q  Y8 h: e5 q
ellipse(midx, midy, stangle, endangle, - p' t! V. O- X% J* f
xradius, yradius); </FONT></P>
8 B: H5 n7 Z" z0 Y<><FONT color=#0000ff>/* clean up */ 6 `" k$ A* p4 T8 ^0 b$ a( C
getch();   j6 V8 @! i3 w, x& V" Y
closegraph(); 6 P% L8 ^1 @5 r' C. l4 C0 s0 T
return 0;
6 Y7 d5 @3 l; c* a} </FONT>
* }1 ?7 J; ~1 U+ g7 V0 z* ~0 _4 Y& n  ^2 `" |$ g' A# t
</P>
/ ]' e; c; {7 I& o<><FONT color=#ff0000>函数名: enable </FONT>8 \* m. K$ b) i& @) T
功 能: 开放硬件中断 + O. q+ s9 C: t
用 法: void enable(void); + Y$ r. G0 y7 S7 x
程序例: </P>
# X0 Y; Q" h6 ^& H' Z. n<><FONT color=#0000ff>/* ** NOTE: + l9 Y9 P$ B; u2 l) t- a
This is an interrupt service routine. You can NOT compile this program 1 j1 @' P! i: C+ q- ^9 R3 p2 D3 ]/ ]! J+ I
with Test Stack Overflow turned on and get an executable file which will
1 @2 w: ?5 B" D: a, J7 foperate correctly.
8 r  A' N0 y( t9 s9 p' s# o*/ </FONT></P>$ d+ x( H$ F* w
<><FONT color=#0000ff>#include <STDIO.H>
1 J: ~0 G! R5 v#include <DOS.H>
/ Q' P$ h/ b/ p6 w#include <CONIO.H></FONT></P>, Z" s. ]; p$ e- W3 V3 q0 Z
<><FONT color=#0000ff>/* The clock tick interrupt */
4 S8 |3 m; Z2 H2 J( Y$ l" c$ ^#define INTR 0X1C </FONT></P>
$ c5 j& b' X$ E<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
4 d0 ?  J% g0 K; @/ z& K<><FONT color=#0000ff>int count=0; </FONT></P>
- ^$ V( j5 B5 M! d5 d! N& r5 o<><FONT color=#0000ff>void interrupt handler(void) " d3 @0 A, C5 Y2 ?) S
{ 6 f2 M' ~% u- x" j2 ?
/* 2 O+ C1 v* Y5 n0 b$ D3 x6 e; m, k! G1 i) h
disable interrupts during the handling of the interrupt
. j' P: v. U3 i( A+ Z*/
: q$ Z# x+ L. ?. ndisable(); ( T8 a1 W0 l9 x1 E
/* increase the global counter */ & q; ^. C6 f) r( ]2 {  h1 G
count++; ! N9 ?+ H! _7 t1 c6 G
/*
2 W7 Y: L% p3 h9 Z! Q5 v8 w+ {re enable interrupts at the end of the handler 9 r3 I5 ?. Q+ Q: r& j: e
*/
4 q. f$ f- I8 t; Genable();
+ }! s3 a; o# K- R2 T/* call the old routine */
7 W+ G1 f, W! }# g  Soldhandler();
" a4 |7 a) J: ?6 E, i0 W} </FONT></P>
% K" [; l' X3 V& {  H+ i<><FONT color=#0000ff>int main(void)
. T: q4 b: L6 t( D8 I7 |{
1 D, [# z5 L- W" P4 n; K$ h( _, F/* save the old interrupt vector */
6 C* u1 \2 ~0 b1 Y. Uoldhandler = getvect(INTR); </FONT></P>' g6 {2 z# w8 m! ~& t! {
<><FONT color=#0000ff>/* install the new interrupt handler */
$ O4 `( X2 A1 e! Rsetvect(INTR, handler); </FONT></P>' c3 s0 ?+ K5 M0 ~8 w- t0 U
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
8 j- e4 C" R6 b. \# D7 ywhile (count &lt; 20) 5 k) C1 }3 G* B5 I! V
printf("count is %d\n",count); </FONT></P>7 h6 {9 c( U. E, M( d" k# X' J
<><FONT color=#0000ff>/* reset the old interrupt handler */ ' o9 K+ [: M- ?9 y
setvect(INTR, oldhandler); </FONT></P>* Y) O5 e* N* ~' \; `
<><FONT color=#0000ff>return 0;
0 V) m+ \# J" n$ E  f} </FONT>9 v4 `5 T* y! O( u9 |# Z- V* {, D
9 H7 m$ \# \( ]. V( e7 Z
</P>) o7 A, C! Q7 C
<><FONT color=#ff0000>函数名: eof </FONT>: Z2 T! C+ H( j" ?
功 能: 检测文件结束 , Z' B: s" B0 M- `" ]+ a
用 法: int eof(int *handle);
. c9 M6 D  G1 X程序例: </P>
$ u6 C3 \+ K0 X' b<P><FONT color=#0000ff>#include <SYS\STAT.H>
7 W0 l  K9 S5 }: ^- i* U$ A#include <STRING.H>
& z2 t4 B6 _; A9 `#include <STDIO.H>5 v" v& u: j) u" y- |: H0 p
#include <FCNTL.H>
6 A7 W+ m! @# b2 y#include <IO.H></FONT></P>0 W4 ~0 M9 E( U& c) s! N3 H! y% m: v
<P><FONT color=#0000ff>int main(void)
8 {% ?$ T' \1 T/ e  }5 o  {/ w{
4 q/ H# k  C1 Lint handle;
+ ]6 o' d: v1 r) e5 fchar msg[] = "This is a test";
9 _! _; r( B5 jchar ch; </FONT></P>
5 t" |5 S' ^& `+ ~<P><FONT color=#0000ff>/* create a file */ 8 [' U& b* Z4 \7 `
handle = open("DUMMY.FIL",
& }2 k, K2 P/ @& g' g1 FO_CREAT | O_RDWR,
) P$ W: Z- \: ?S_IREAD | S_IWRITE); </FONT></P>- Z6 A; }' K1 q9 O6 l5 i
<P><FONT color=#0000ff>/* write some data to the file */ 4 B/ n6 K- \" T
write(handle, msg, strlen(msg)); </FONT></P>+ l* S, o+ o7 }& I4 H% X
<P><FONT color=#0000ff>/* seek to the beginning of the file */
: t, h% R" X! d7 r2 |" F  m$ \  Tlseek(handle, 0L, SEEK_SET); </FONT></P>) o5 r" o& N4 O
<P><FONT color=#0000ff>/*
9 B$ W& n# t5 c- R+ l- m) p: m8 Creads chars from the file until hit EOF
  H+ m" J5 z! f# v: e*/ * S' D# B# ]6 e4 j0 h- W5 B
do 7 k4 B0 s) A3 _* k1 a  P0 u
{ ! r& S) T, `" z8 X1 j/ W8 D5 b
read(handle, &amp;ch, 1); - v7 u0 l1 F3 @7 _
printf("%c", ch); : P; E1 j# L( ^' V
} while (!eof(handle)); </FONT></P>$ U% ?; R4 D. x/ o+ _' k) w
<P><FONT color=#0000ff>close(handle);
$ w5 y: s0 E1 o' L/ l# y( m! sreturn 0;
( k' S: ]: b* ?' w} . ]9 c" s2 F' w; Y/ {3 r
</FONT>
) m2 r6 n0 D. z. C</P>
( {4 v- }; v+ Q" ~8 {<P><FONT color=#ff0000>函数名: exec... </FONT>
8 t# H9 b; m5 B6 N- N5 I3 w) X1 t% e功 能: 装入并运行其它程序的函数 9 m- m* I* D$ L  e* ]4 }
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); # {: b% T0 l- p
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, 7 |$ N$ r: o% n0 U* `0 I
char *envp[]);
2 s8 k1 H- J7 J* B% _  Y+ U- d2 ^int execlp(char *pathname, char *arg0, arg1, .., NULL);
' A, ^. r# o; N$ [7 }! Q( t1 oint execple(char *pathname, char *arg0, arg1, ..., NULL, " I9 Y% U- I5 {; O- R
char *envp[]);
' F4 k' |: X* S2 n# R  i; H' L( pint execv(char *pathname, char *argv[]);
- {0 }8 F" m; k+ q2 rint execve(char *pathname, char *argv[], char *envp[]);
8 _" B$ H2 ]+ h3 A6 b8 G. x9 t3 [0 kint execvp(char *pathname, char *argv[]);
3 q+ V4 ~; I0 O9 ^' ^int execvpe(char *pathname, char *argv[], char *envp[]); 3 b. b* E& [2 c: {; {
程序例: </P>8 b- I7 X% Y1 Y$ [4 A" B  F
<P><FONT color=#0000ff>/* execv example */ 7 w- B+ F( R' `
#include <PROCESS.H>, n7 L. b- ~5 H" |: V
#include <STDIO.H>
. p8 |1 y. M& {+ I$ ?3 q) `1 _- m5 p#include <ERRNO.H></FONT></P>
4 g# Q+ _+ I0 U, T7 u# e<P><FONT color=#0000ff>void main(int argc, char *argv[]) 6 i& E% f* M! G; @" w2 A
{
* l8 m+ F" q( z: I8 a+ aint i; </FONT></P>
+ y; H* _7 Z1 X9 o7 `<P><FONT color=#0000ff>printf("Command line arguments:\n");
/ M* |8 _6 P) lfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
3 A5 x% A0 [- ~3 \8 C8 ]& @<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); . c7 H( o) j  H4 g3 l/ i
execv("CHILD.EXE", argv); </FONT></P>
$ f8 j& s  @4 Q/ j0 V<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
. ?3 O- o! K3 i( T5 V5 T<P><FONT color=#0000ff>exit(1); 6 T7 W" q- ^% }+ ~& Q/ u2 H
}
: c7 }$ x. X& ?9 F6 Y. q3 ~1 t5 F</FONT>
/ e! c5 N9 ~1 O; o6 d5 f</P>5 o- N' b, O# n: w/ t& O4 d- K
<P><FONT color=#ff0000>函数名: exit </FONT>1 I! v$ ^% V6 G; L2 [+ K4 R+ a3 Q
功 能: 终止程序
: ?3 U3 K: ^( Z# g& o: B' z用 法: void exit(int status);
2 m. w6 }# d8 k3 ^: G8 D程序例: </P>1 W- q2 ~) O/ D% {/ H
<P><FONT color=#0000ff>#include <STDLIB.H>
# [1 s5 e7 o6 Y3 v9 N4 P2 G! A#include <CONIO.H>, G% e9 ^4 {; k5 b/ _( k2 z
#include <STDIO.H></FONT></P>. u2 F$ A8 o) R7 c
<P><FONT color=#0000ff>int main(void) 3 H5 G$ K( v2 r+ z
{
4 X9 s6 X: t6 q, I7 F1 F) [" R, i& ?. Oint status; </FONT></P>
5 d, l% w" }. ]1 P, J6 x- ~<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); % {" B7 F. Z* T3 k# @
status = getch(); 6 G+ h: L. p9 @
/* Sets DOS errorlevel */   R* ]4 [. m, ?1 ]
exit(status - '0'); </FONT></P>- e" I! ~& c5 o' f9 l& O9 W& T' U# N' g
<P><FONT color=#0000ff>/* Note: this line is never reached */
# n6 W" w6 G2 |return 0;
# j, X; g; x. w' p& V" l} - b7 b+ e2 Y4 [) n
</FONT>: T! h1 k6 v0 V5 i
</P>
( Y$ ?: [- u+ u. O<P><FONT color=#ff0000>函数名: exp </FONT>
9 ~! M* W9 d4 |9 A9 ~, I功 能: 指数函数 1 I2 {6 z# }3 s" r3 t. c6 J- }
用 法: double exp(double x);
7 F' h& f" g' O; S' X6 |' V! w8 ]7 a程序例: </P>3 \0 [( m4 A& s3 E+ p
<P><FONT color=#0000ff>#include <STDIO.H>
- c( w  G% o3 N  T( t: B7 R#include <MATH.H></FONT></P>9 n' o. |! h& H, O/ u* l: F: ]. u. r
<P><FONT color=#0000ff>int main(void) 2 F3 g" h5 j' d+ Y& G0 g, |7 S
{   K* A' b- S# D
double result; : P4 f! s3 \. K5 d/ z+ U
double x = 4.0; </FONT></P>
) ^% h) v1 {4 T. w2 u5 p) H/ a3 }<P><FONT color=#0000ff>result = exp(x);
4 n. y4 Q1 n" k! M7 b6 T9 w) Dprintf("'e' raised to the power \ , n; P' t* b  [- X( M( `0 s
of %lf (e ^ %lf) = %lf\n",
+ V4 q) B, |$ h5 mx, x, result); </FONT></P>
" @5 ^- k/ ?% T0 ^# ?+ P<P><FONT color=#0000ff>return 0;
- ^4 E5 `% ?. I6 q}7 n% H$ W4 A  C3 r( E, k, ~) @
</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>( S& Z# \* q6 o7 N) ?* j; O( x
</P>
- ~! `8 b% \% @4 n. J<p><><FONT color=#ff0000>函数名: delay </FONT>* p' C& O3 v& A
功 能: 将程序的执行暂停一段时间(毫秒) 5 s/ t6 ^7 |3 C6 `) O% z% N
用 法: void delay(unsigned milliseconds); ; M* g* ?( T6 P  O/ f8 M7 J
程序例: . j6 ^5 [0 i! R: I. s
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
2 n: y! V% }! I, p+ k#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
6 P3 J, h) b2 l# i{
/ T  \% w9 l! p: T. w9 s3 k+ tsound(440); 2 @! E! Q' U6 y6 V
delay(500); 3 b" m* E6 R" m& Z+ m: {1 j
nosound(); </FONT></P><><FONT color=#0000ff>return 0; / f% \8 X1 m* n! W- ^7 b2 D. A3 N
}
* B+ ~5 d* S  B" K; K7 F2 a' g) i8 @; C
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>- @8 `0 G2 x% H& L) d
功 能: 在文本窗口中删去一行
6 t. ~, }( E: [* p. P& C5 K% Q' R2 g用 法: void delline(void); 1 [1 d8 J3 D8 R. \
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
0 g6 p  z8 U9 K% J; l. d{
/ M( [  R4 R& p( L5 o# Gclrscr();
5 V: m4 S$ o% O! ecprintf("The function DELLINE deletes \ , ?* u2 B7 T5 D& r
the line containing the\r\n");
. J6 p. g0 M. @/ I2 ~! w7 ^% {9 `; A4 vcprintf("cursor and moves all lines \
9 R( o( k& q. @/ Y5 Q0 y- ebelow it one line up.\r\n");
# R' J2 }- K* |- o2 k1 ecprintf("DELLINE operates within the \
) r- {  k* [  U, b, A9 Tcurrently active text\r\n");
* s1 G; B3 R6 @cprintf("window. Press any key to \ 8 c' e. x. u5 z( J. ]! @
continue . . ."); ( D& @, U* B$ o! D
gotoxy(1,2); /* Move the cursor to the - j5 K. N$ k  w
second line and first column */ & F, V* d  b# V3 v0 l, x3 d- e5 a
getch(); </FONT></P><><FONT color=#0000ff>delline();
3 |0 [1 E  k( {1 B4 m$ x# M; bgetch(); </FONT></P><><FONT color=#0000ff>return 0;
9 p6 D- a7 t& z  k  n' `0 L# v} </FONT>8 m3 g) B6 y6 y. b7 V
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
6 ]% }6 R- [/ K) W, ~# d! R! H功 能: 通过检测硬件确定图形驱动程序和模式 7 k$ r+ g$ c; U! q2 g* }' m
用 法: void far detectgraph(int far *graphdriver, int far *graphmode); $ B+ q4 r) k6 Y5 u6 c. x) w
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
' Q2 D& I# g) `#include <STDLIB.H>3 K) a  ?9 }! K1 W$ A" u, W1 o
#include <STDIO.H>
6 i7 P2 X4 j9 X; Q: K% A#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
% }4 v: l" d* ~/ s& N& t4 mchar *dname[] = { "requests detection",
. w9 N. j" O$ n"a CGA", 2 q* {" c- T+ W: n
"an MCGA", / b3 K6 \( c- A
"an EGA", ( m3 ^# ^) C- R, g" M1 h
"a 64K EGA", / }6 S+ T( a- k9 I$ L
"a monochrome EGA", 6 G0 T+ c) Z; v' k. k1 [! _! f
"an IBM 8514", & Z  ]+ R, v0 C/ V, A
"a Hercules monochrome", , x/ \: m1 Z3 t/ b& q* t* Y$ u
"an AT&amp;T 6300 PC",
/ q# z1 E" K% M+ D0 w"a VGA", 6 y* x2 a% w1 o7 H8 s, {& Q# q4 D
"an IBM 3270 PC" ! [4 i8 t' O8 T# p' n% a0 Y
}; </FONT></P><><FONT color=#0000ff>int main(void) ' x& L1 s, J+ j, ]4 C
{ $ R1 M! _9 k( ^! z& E
/* returns detected hardware info. */ # |/ Y+ t9 X# l9 o" D% z9 v
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ / d/ c4 U( y, \
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
" A7 ]* I6 b( p% p  Y. ]1 cerrorcode = graphresult(); ; w; v/ h# ^* `1 P
if (errorcode != grOk) /* an error $ D0 ^9 f0 d5 c4 ]2 {
occurred */
2 l* i; Y3 O, P0 m2 O" l$ h{
0 ?$ Q% [/ B% w" sprintf("Graphics error: %s\n", \
" ]1 d$ l0 L- agrapherrormsg(errorcode)); 9 \8 {9 s# ]9 y& o0 G$ }
printf("ress any key to halt:");
  J, B; _* L, ], N- T4 Agetch();
+ ~: Q% B( F2 j3 y% Z: C8 rexit(1); /* terminate with an error
. `% S& W5 m5 d, n( A: j+ o- Jcode */ 2 X! Q& a2 y' _8 A; x
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
% n8 n. h  P4 Z9 ]5 k; Nclrscr(); & w" D1 B2 `2 I4 }4 D: z% B
printf("You have %s video display \ * U. J& N7 B! y. x! w3 |0 e  I
card.\n", dname[gdriver]); 1 K" [5 |! w) D+ ^$ h4 [' u' P- y/ S
printf("ress any key to halt:"); : c1 ~% r( ]3 |8 V2 C. y4 `6 {
getch();
1 M* o: H% n+ H9 L' v( Freturn 0; & {( c3 J; j4 c/ ~2 [* @. ^1 o$ D
} </FONT>- Q6 b4 P: ?  `, [
% \7 ?7 S3 z, t1 j: w
* o, P! j5 |- m8 l3 V* M" m$ b
</P><><FONT color=#ff0000>函数名: difftime </FONT>5 l. t: X3 t  s( o* D) B* r
功 能: 计算两个时刻之间的时间差
! G7 [9 H3 k# y" x1 o  \用 法: double difftime(time_t time2, time_t time1); * s5 B/ j. `% z0 J( l" x
程序例: </P><><FONT color=#0000ff>#include <TIME.H>, P8 \3 N: u) a
#include <STDIO.H>1 C" c$ R3 V5 L7 R
#include <DOS.H>6 r) J3 x5 F% g# C1 r0 N
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
! e! |8 _! f/ _1 v/ L{ 6 j( j9 n; c) p  Z, U
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
1 m; t- r* R! ffirst = time(NULL); /* Gets system
* S" |  o$ v+ E/ H. H2 Y+ |time */ 0 c2 W+ F8 W/ Z( W* ~6 q
delay(2000); /* Waits 2 secs */
" p+ Z4 e% o% U0 X2 M) Psecond = time(NULL); /* Gets system time ; F5 B0 o  s* S/ W! j: b
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
! X$ |9 W( h; P$ l! ]( [1 v) rseconds\n",difftime(second,first)); & B$ E% p+ M7 `, k4 E; B
getch(); </FONT></P><><FONT color=#0000ff>return 0;
1 s! @! f: o  Q% z2 C} ; W( @) U% Y6 I+ M5 J$ w4 p
</FONT>0 o+ y- G: V# S, F$ e+ H  @  ?
</P><><FONT color=#ff0000>函数名: disable </FONT>
8 J! o: c: j- S9 Z0 b, t+ X! A功 能: 屏蔽中断 $ }& R3 c) y7 l3 f8 Z, p8 h
用 法: void disable(void); ( o4 }# e# u: b
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service + q0 j4 z  z! B+ B. E$ `# O
routine. You cannot compile this program
. j& s  r' A' j+ y2 }2 v8 K1 Qwith Test Stack Overflow turned on and $ a/ M+ k! i4 e/ \
get an executable file that operates . ^+ g# X9 J/ M8 U4 r5 |
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
( u/ s5 t2 d* K' ^. N8 O#include <DOS.H>
! d" y0 o" x& l  v: y7 |6 n#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick + Q' I* w+ f. L
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) 9 |" l" B6 L: S/ Y$ n+ B+ Y4 h
{ 2 `# M( T; b7 D7 {4 S
/* disable interrupts during the handling of ) J  F8 n7 a! s1 k% j- Q
the interrupt */ / ^! C+ R4 M* p1 _4 w
disable();
) F' m3 c  N, g/ V) w$ ]* R* \0 u  R/* increase the global counter */
7 w3 ^5 P& Q: i: O/ \  Y% D- dcount++; 6 o5 k* A. x4 T& q* f
/* reenable interrupts at the end of the ( ~  \% z# M# Z; Y) Q7 V( h  B
handler */
7 w; g9 Q+ N6 S; wenable(); * y+ t" T' o" s8 e8 e$ e
/* call the old routine */
" H+ W$ R+ |0 f$ q& A* R! c: i6 b6 eoldhandler();
1 q3 [4 B/ c& Z} </FONT></P><P><FONT color=#0000ff>int main(void) 8 Q& ]% B; C$ v* ^' m
{ " {! r9 C+ V6 g1 S9 X# ?1 v1 O
/* save the old interrupt vector */ ! s7 P/ f2 `, i6 h
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
$ t8 \8 y( _" n( j. Esetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
9 ^3 i. N* ~( c# H5 w" Mwhile (count &lt; 20) 9 l4 |8 Z- _5 I9 A( z; m: p" {7 ^  ?! M4 G
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
: X' T$ x: K; ~0 S9 Tsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
  @6 D& M& \/ h0 j, `" i  }6 j} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
! k6 U. |0 x& @  G( B; y功 能: 将两个整数相除, 返回商和余数 + S! H5 I+ q, v+ S7 Y
用 法: div_t (int number, int denom);
4 c5 y, @/ q* J& N4 @: K程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>" q. y$ k) t4 i, E
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 8 e4 E; B* l* ~3 x
{ * z  v9 u7 M' v6 e
x = div(10,3);
! D" x) a. G& c; xprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; $ o5 ^9 z5 I0 |' X
}
0 Y$ Z+ B  W2 P</FONT>) f# L8 h0 a- ?- E. }3 l+ v6 n+ w; A
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>8 ]0 l* h" g+ N, F- f& a0 q
功 能: 获取扩展DOS错误信息 : I! M" K6 L; R' f% a$ e. S# P8 Z
用 法: int dosexterr(struct DOSERR *dblkp); 0 Q7 R# _* a+ t
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>* x% Q% }1 ~3 h4 a. X; ^1 m$ i
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
# C1 C' _4 K6 r0 `" L; p1 A1 d{
# X3 |3 w5 F9 t" {' D* I0 IFILE *fp;
$ K: K9 H0 A9 G9 Ystruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); 9 ^9 |3 C, G' X2 r
if (!fp) perror("Unable to open file for - J0 l5 t5 D# N
reading");
+ t2 r; c4 n. W2 O- d/ Edosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
5 j! _" B; r5 q6 l. u& {* Y  t, Iinformation:\n");
& U3 F% S8 [; f2 `/ s8 Nprintf(" Extended error: \ & [! H1 @9 M3 Z/ s+ r8 z
%d\n",info.exterror); : L& x; w  f" L; V' |
printf(" Class: \
9 j. `+ X8 E1 `$ T, n%x\n",info.class); ( X' ?4 [$ E5 R$ J4 B
printf(" Action: \ 9 @4 T" z% M( q9 K. ]
%x\n",info.action);
  N1 ^4 q+ K/ u7 Y( U$ U: c, Sprintf(" Error Locus: \ 7 Z- ?0 ]2 l. _( Q7 N8 l# ]
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
, G3 \8 F# S5 S& ?} </FONT>
2 Z) t/ d1 K1 R/ P) }% [7 h2 P+ z- j) U* ]
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>6 ]! {. p$ E- ~1 ?2 G& n5 z4 C
功 能: 转换日期和时间为UNIX时间格式 / d' ^! U' T) N. w9 S$ c
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
1 H7 B) K& r+ g% _" C; o0 ^1 k程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
) G( y- _9 B3 K9 p  ~1 B- E2 r$ y#include <STDDEF.H>  f" g% v0 v$ [" n& H2 T8 I
#include <DOS.H>
9 g1 H  Z; P+ v. D8 p, \$ k- U#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
7 j4 T9 I8 K" ~# r7 ~2 L{ 3 H- s, A6 C  W- U; k7 Q
time_t t;
5 s( ]/ n) s. v# ~! a+ estruct time d_time; 7 I+ `: d& I  S/ e" I
struct date d_date; # J8 v' k% N; d- o& K5 e
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
9 i% U5 H3 Y! g! cgettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
6 I6 s5 J8 Q( Plocal = localtime(&amp;t); 8 _; r( D& N* ]& t" d( b1 @& d
printf("Time and Date: %s\n", \ & o5 ^$ r5 z  q2 ~) }* ~  X0 D! g
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; / }5 w/ o, S+ I* M" C$ m: X, z3 @6 W
} </FONT>% \# l7 u# T; R2 Q$ Y0 P+ P& a

+ v4 Y/ p3 r. f- e5 K</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
/ {! @; y* v" O: m. d) Q功 能: 画多边形
0 Q/ j1 ?, r% Z* w用 法: void far drawpoly(int numpoints, int far *polypoints);
; v1 C9 K2 M6 O$ ~6 @6 p程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>/ F" T! W& b/ ~5 ~
#include <STDLIB.H>7 o2 p$ y* Q7 y6 [8 |; h
#include <STDIO.H>" H, I3 Z- z  }2 w. n
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) / B9 n2 t& d/ B# n! J
{
2 j" x/ [8 g; I3 p, U7 c  E/* request auto detection */
7 ?2 B2 p2 U0 P% H8 t0 ]+ ^; Dint gdriver = DETECT, gmode, errorcode;
( d4 n6 L' @, l3 R/ Nint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
8 ]% o4 H/ r! ^; H5 Y# d) T! {' yint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
: N5 s4 q& G) u" `  Ovariables */ + v; R6 p' N  {" e
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ ) @# q9 B; i2 X, @" F2 T
errorcode = graphresult();
$ a  I( n0 a: @0 M9 W& S5 Oif (errorcode != grOk) 3 B$ S& }/ ?  n+ f! ~2 d7 u
/* an error occurred */ + T( x: I9 N* m
{ 4 w0 A3 m$ g( t
printf("Graphics error: %s\n", \ ) X0 e: N" P4 R# a) V, k0 h
grapherrormsg(errorcode)); % ?9 w& D4 }. x' E* d, @
printf("Press any key to halt:"); , x+ G6 y# e* m  r: t
getch(); 5 |* g4 _1 P! y1 `% z* U
/* terminate with an error code */ 5 I: Y! [4 m) U% }' c0 T5 J! H! C% d+ v
exit(1); ( ^# C" T% l8 J( Z( e1 C
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); 1 g. E1 T( Y$ t0 A: w  C' G
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ 9 q+ Z9 s+ R. M( v' H; L! U9 }
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
$ z" e4 b8 x9 p  ~) mpoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
8 ?$ t: Z# t5 d1 s7 q. Tpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
3 S- Z3 ]7 D- q0 {2 |' \9 lpoly[7] = maxy / 2; 9 g# I2 R: Q- `: |$ E8 I
/*
* X: O/ w; T$ J( Qdrawpoly doesn't automatically close
) K9 c$ P* S0 R1 a$ L% ~5 x6 uthe polygon, so we close it. % `1 B) u, }/ |' |! H* X# X
*/ . S, Y' T* t( v6 ]6 w) x" `
poly[8] = poly[0];
* C* e  y# K5 J1 [. Epoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ $ U8 z, C4 E' y8 ~3 _
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 4 G; n4 J! H; {3 V5 A
getch(); 6 c9 r8 N! _% d; O
closegraph(); + H9 Z/ v( L0 k
return 0; ; K: }, q0 c. \& B7 H: u, F. l, |
}
4 N6 b1 [: S# i+ Y, H; T5 M4 j# u</FONT>2 Z! e8 ~* O0 T  V4 U. m
</P><P><FONT color=#ff0000>函数名: dup </FONT>
" C' U" |: T# l1 G& M' B, X功 能: 复制一个文件句柄
4 c) ?5 x/ r) F5 b3 H用 法: int dup(int handle); 8 M0 u% B  e5 @* e- Q
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
: V# e8 g" r/ `#include <STDIO.H>' H- _7 {5 a6 R" G
#include <CONIO.H>
9 k# j, y/ C' |5 i#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) 1 ?' N* ^, q9 H/ \
{
+ Z+ w( \4 N( R% a8 g/ BFILE *fp;
9 R# @! D$ \" {% j+ }char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
( O) ~( P2 t; K, dfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ + ]. N/ F9 C# _. E2 n, d$ a
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); % |  f' w  J5 C
printf("Press any key to flush \ ! o. I. l& _7 L% @3 F4 K
DUMMY.FIL:"); ) P$ |$ }5 u6 S- P$ }# @) J
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without 3 p' [5 d0 j5 ]$ H
closing it */ $ Z" Z7 Q, k3 E6 @- c
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
; B9 W$ v9 [* T5 wkey to quit:"); , j/ [* l; N; \4 `+ N. v
getch();
. x) b  M; F8 U' Y: V8 e/ q, xreturn 0;
- V0 P( n6 w2 g: `! q. @} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) ) \* k  }" v2 U# o7 O5 {9 j, c2 m7 k
{ , k. Q" A$ L  [
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ $ z# q" F9 @* C- Z) A
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
9 _* b& k* j3 m% x4 Wduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 4 S1 i" J2 W' ]5 F8 Q
DOS buffer */ 0 n) R9 c: L9 z5 F1 |7 ~
close(duphandle); , s- K; `& R3 T& }' p# _. H
} * B. \& H: ^+ o: L1 \+ `, P2 z, T

! ^  m' u! l, g9 a6 x# w* j</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>2 }6 K" V4 S/ c) q' @; u8 Z1 h
功 能: 复制文件句柄
7 c6 X* F$ Z5 V4 i用 法: int dup2(int oldhandle, int newhandle); # k" \( }  x, ~! L
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>7 C% h0 b- o3 ]7 S: @5 j! m; N
#include <STRING.H>. N, q! N9 Q! i3 {. s
#include <FCNTL.H>
, K+ D5 R6 d+ W( B7 R" ~5 B0 c4 V#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 7 n% ], I" a9 ]  i! i. _
{ & G6 `3 r9 ~- [
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
, }; K$ [0 K6 ^8 @2 S. X3 K3 {char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
  ^& ~" n3 A" j- Q7 ]nul = open("DUMMY.FIL", O_CREAT | O_RDWR, + K; X2 e) H1 P
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
$ D5 F3 C* `$ H' N, Z, ~  Goutput */ 7 h0 u* d7 {6 k/ Q/ Y( D
oldstdout = dup(STDOUT);
# O, U& Z4 n+ ?4 g3 }7 r  k  E) ~/*
/ s6 u; @5 Z0 T2 _) `' jredirect standard output to DUMMY.FIL # l& _0 _1 X( B0 m1 x* F6 o+ d9 V) w
by duplicating the file handle onto the
; W  ^# D$ n5 N/ ?file handle for standard output. ! h" r! o! M0 g! l) W' p
*/ 6 X' }0 u/ f/ V# w9 ~- A7 g! A/ V
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ 9 J. O/ e9 N6 J" a, Y- w& \
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
: z' ^; e) R4 U0 v# s& F- iwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
9 g+ B& t6 b8 Q7 A& }handle */ 3 b$ C; ]  i7 ]' Y( i! q! [
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ * R1 }6 m7 b5 O; ^
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; . E3 V" S6 O3 s* C" C7 X$ o7 e2 p
} 8 j7 k1 a9 o) w# u1 G5 B' G
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-6-12 08:28 , Processed in 0.656852 second(s), 56 queries .

回顶部