QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2141|回复: 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>/ t# \0 o+ i8 I0 W3 e
</P>3 I/ j6 k; j. M; {9 k4 h
" \- P" h  k" y% M- Z3 z: Z

& e" D- I8 @! [6 o# n$ ?<><FONT color=#ff0000>函数名: ecvt </FONT>3 G  y3 q! E9 I9 H
功 能: 把一个浮点数转换为字符串
+ }; M$ U+ r6 E" n5 T. L7 l用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); 7 R. j+ A7 @* h2 t
程序例: </P>
! _) O: D( {& W& V1 M" J<><FONT color=#0000ff>#include <STDLIB.H>
" T% r* ]' ~, S4 G. O#include <STDIO.H>
  \2 {/ g* P) {' h! {4 J; p2 i) O#include <CONIO.H></FONT></P>
# y7 Y5 n8 I3 T) u<><FONT color=#0000ff>int main(void) & x4 s$ D- x* m( k
{ # {0 g& L  z3 M) y
char *string; * r8 c, E$ t+ _* C+ A
double value;
2 Y2 X1 M' P: V  r. V4 Lint dec, sign;
& B$ b0 M2 I0 _7 Q3 M' a  k. U1 p9 Lint ndig = 10; </FONT></P>/ u- `+ Q% h* N7 x$ A, Q
<><FONT color=#0000ff>clrscr(); 8 E5 U9 N' \, s8 y& W
value = 9.876; # i0 i; y% ]1 Y
string = ecvt(value, ndig, &amp;dec, &amp;sign); ! l. [8 k1 E6 M7 q8 I9 I
printf("string = %s dec = %d \ * R, g& U& M0 s+ x0 U: @
sign = %d\n", string, dec, sign); </FONT></P>3 V6 z+ d7 U9 t( W
<><FONT color=#0000ff>value = -123.45; + W' c/ X0 g) |0 @, u1 J7 b
ndig= 15;
; g* r7 T# z9 x8 U+ v/ x6 L' dstring = ecvt(value,ndig,&amp;dec,&amp;sign); 3 m% C3 q  u: l6 q
printf("string = %s dec = %d sign = %d\n", . `7 ]/ V! G4 H; K1 m
string, dec, sign); ) b4 z- A% C" r( P
</FONT></P>% x% `5 r, D: t! X$ m) j  K! A
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
' b: a3 j9 {0 Tnotation */
8 S! T  }# I# @/ }  [ndig = 5; 4 E; `" V) K) }: G' h
string = ecvt(value,ndig,&amp;dec,&amp;sign); / N0 T) R- X* H- |  @& Q
printf("string = %s dec = %d\
- r0 k/ x8 G$ Nsign = %d\n", string, dec, sign); </FONT></P>
7 r( P7 g$ {+ S4 D<><FONT color=#0000ff>return 0; - h; @# p; e4 j) a
} </FONT>* `2 C1 N! v) |4 |

' p  s) ~4 o' G; H% b; B$ {7 [</P>. V& {, s$ Y4 C4 r+ `7 a8 W
<><FONT color=#ff0000>函数名: ellipse </FONT>
( c) \& q- ^" ]& _% y功 能: 画一椭圆
( k2 @8 k9 n% D% O& r用 法: void far ellipse(int x, int y, int stangle, int endangle, 0 C5 \3 ]7 a6 Z: S% \$ i- \/ g
int xradius, int yradius); : ^5 M2 f" _; @# A/ h! E& Z
程序例: </P>) D) C; ]) C9 N$ a
<><FONT color=#0000ff>#include <GRAPHICS.H>: c# Y$ q% Y  d
#include <STDLIB.H>
0 Y, T; t# @0 z9 p  i0 e#include <STDIO.H>
7 N5 ]1 b8 f, R4 V5 S+ h#include <CONIO.H></FONT></P>
; Y% O( z% W) |1 d5 J<><FONT color=#0000ff>int main(void) + `! R+ }1 G- z9 x4 S
{
- ]' q! D/ R, r! \+ i7 w/* request auto detection */ 6 n' {) {4 y# P: q1 _# T3 X; N' Z
int gdriver = DETECT, gmode, errorcode;
7 m4 e$ y9 ~- w: ^& bint midx, midy;
. e2 t& d: U; d! Uint stangle = 0, endangle = 360;
5 D8 @9 p( U( H9 a% `int xradius = 100, yradius = 50; </FONT></P>
& a9 j- }4 h! [2 f- o<><FONT color=#0000ff>/* initialize graphics, local variables */ 0 P$ x4 \( H1 G: U
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) v0 g& a0 k- v$ S4 n: o! U<><FONT color=#0000ff>/* read result of initialization */
* l" h& Y0 v, ~# d! ]' @5 }errorcode = graphresult(); ; ^3 X$ s1 I  H7 T! v$ Q8 p$ X- i! {
if (errorcode != grOk)
  H% O; t. V$ \9 D% `/* an error occurred */
! v7 Q8 O! Z% y' b! I& `3 }{ / N; y  l2 s# C8 @3 L# x$ M3 i- @
printf("Graphics error: %s\n",
& R# @4 K& V( l: X" f( ~7 Cgrapherrormsg(errorcode));
3 S+ \+ E: q% ^* |/ Qprintf("ress any key to halt:");
8 W; m, y* }/ A0 N% T3 n7 e9 {. |getch();
0 ~& m, t; n! g5 Oexit(1); 1 J" S1 `$ t9 w' L/ Y
/* terminate with an error code */ / w1 a8 c/ r  l. [$ G4 S$ M
} </FONT></P>1 j/ t, U4 `7 K/ K) ]6 ]
<><FONT color=#0000ff>midx = getmaxx() / 2;
$ E2 t# }1 Q  V" amidy = getmaxy() / 2; 5 p0 ]( p# C5 i2 s4 T
setcolor(getmaxcolor()); </FONT></P>
% ~0 B1 V5 c+ Z  W& ?9 Y0 I. o/ `) R<><FONT color=#0000ff>/* draw ellipse */ 0 D7 T* `9 t8 G8 H3 j
ellipse(midx, midy, stangle, endangle,
5 d; \7 u0 C! J8 I4 \3 m6 U; Exradius, yradius); </FONT></P>
" y, M2 }' Y4 K7 V<><FONT color=#0000ff>/* clean up */ ; ^9 _5 }7 L5 F0 i( K
getch();
, n& k; V$ y7 V8 O! |$ |: Xclosegraph(); 5 @7 c5 t: Z2 G
return 0;
  O: c9 d# e; q9 @1 C( Q} </FONT>: e7 X' x$ t/ V  G4 p( C
( S4 _& @. a7 P8 O% g
</P>
5 y  _; D+ f0 U( D<><FONT color=#ff0000>函数名: enable </FONT>
' b4 i/ e0 y+ |3 G" s% ^) m0 B$ g功 能: 开放硬件中断
3 v* ]' E, e9 y! V4 F& G用 法: void enable(void); - S  w: O+ j0 {% p& s7 [3 _
程序例: </P>/ }" {- o. N3 ~7 n" [$ L  g
<><FONT color=#0000ff>/* ** NOTE:
* J* \# y, o9 R% bThis is an interrupt service routine. You can NOT compile this program
7 f) |7 n) z4 nwith Test Stack Overflow turned on and get an executable file which will
0 w5 Z8 y1 K/ `9 G1 }operate correctly.
1 `" g+ {/ S6 e1 L# S0 `0 U/ O% c*/ </FONT></P>
7 E( m) K/ o6 A<><FONT color=#0000ff>#include <STDIO.H>
! a, L7 U& n, Y5 [' [#include <DOS.H>
$ E! y' ^* @. ]) h#include <CONIO.H></FONT></P>0 K( @, j) p9 O# B, A: f
<><FONT color=#0000ff>/* The clock tick interrupt */
2 i) }: w+ F, U# Z#define INTR 0X1C </FONT></P>; o; B' B/ u$ c! i6 X5 \+ X& h" O$ t
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>! M0 G( C2 ^! d) ~3 ~
<><FONT color=#0000ff>int count=0; </FONT></P>
: t4 U$ ]. R  [" O% L<><FONT color=#0000ff>void interrupt handler(void)
' t  l/ e! ]# q2 U0 L5 y{ 9 X" P  @# [3 d8 h# c, K
/* ' q/ ^. P. n1 R/ u4 w- [
disable interrupts during the handling of the interrupt 5 D# I' s# ?+ }  `4 n2 A
*/ + c( g  L4 e9 K
disable();
* D; P; Z! T3 L- y/* increase the global counter */ ) L) `' u. }+ G# s
count++;
  C9 k  I0 V! N' m0 u0 k/ C* W/* ; N1 ~3 m8 Q2 c! O
re enable interrupts at the end of the handler / P9 j- p+ G7 X  _
*/
4 S% o; p; |! kenable(); ( t( u( a* O. S. X. t
/* call the old routine */
  N# Q6 d9 p3 ]% xoldhandler();
9 q' {3 Y# }: d/ `} </FONT></P>
# g+ `3 ?) Z2 g% n) g+ S0 Y5 O<><FONT color=#0000ff>int main(void) 6 Z3 H9 `) D. B) E
{
  X* B$ I) d+ S# m& l/* save the old interrupt vector */
! s  T4 I8 L/ u& A: _) O  \* zoldhandler = getvect(INTR); </FONT></P>8 z( C6 g9 Q5 W, Z6 ?. W% ^- G$ h  r
<><FONT color=#0000ff>/* install the new interrupt handler */
' l' f+ D5 I$ n. u  _$ asetvect(INTR, handler); </FONT></P>" i0 r2 g- i( n4 d! E2 v! ~9 K
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
  P) v+ m/ G$ F$ E& u0 l: _- wwhile (count &lt; 20) 8 `8 i, |  M9 ?4 A
printf("count is %d\n",count); </FONT></P>* C8 n/ v+ q, l9 `3 a
<><FONT color=#0000ff>/* reset the old interrupt handler */ ; h6 G7 i4 T6 v$ @
setvect(INTR, oldhandler); </FONT></P>
  R' O& k7 X( k% {7 Z<><FONT color=#0000ff>return 0;
( m' J( U$ v# V} </FONT>
1 z5 R; ^. M! N  K! n9 y; J7 Q9 W4 o1 o+ @, {
</P>
6 b: w' @! o, q<><FONT color=#ff0000>函数名: eof </FONT>
: V: e6 G: d; a功 能: 检测文件结束 3 ?' r. i" s! S4 J) h2 l) A  O2 R
用 法: int eof(int *handle);
% F8 T* ~5 E# j. \: \" ]程序例: </P>. ?5 F5 B7 v9 v5 a  _% H4 z
<P><FONT color=#0000ff>#include <SYS\STAT.H>' V  o5 O6 m# X' c! T0 G( o& k1 ^3 q  I
#include <STRING.H>4 D$ q+ A1 J5 l, s* A* P
#include <STDIO.H>+ p3 y' ]% G; j5 L( V* N, Y
#include <FCNTL.H>
/ y% B7 K! A2 C  j: M#include <IO.H></FONT></P>
/ d0 K# z. M/ m: k0 A2 i  ~- H<P><FONT color=#0000ff>int main(void) , r/ p8 N8 K; I& x! z( d
{ ! Q2 Q$ _- d/ C# k7 r
int handle;
: w' p8 a2 d% C7 m" }0 ]char msg[] = "This is a test"; / F# y9 g4 I( w% }3 Q
char ch; </FONT></P>
* y) p/ q* I! a' G/ C7 M; c<P><FONT color=#0000ff>/* create a file */ 6 L) t3 n- |$ p# v
handle = open("DUMMY.FIL", ' i) z& f  ?% t% }
O_CREAT | O_RDWR, 3 @( Y5 ^- h/ i4 q" y2 ^
S_IREAD | S_IWRITE); </FONT></P>
; m9 |8 I6 R5 _: T8 s<P><FONT color=#0000ff>/* write some data to the file */ 2 [- D$ C% ]. k5 ?
write(handle, msg, strlen(msg)); </FONT></P>
, k# |$ o% C! F) l$ Y* y6 T, C- \8 I<P><FONT color=#0000ff>/* seek to the beginning of the file */ 1 S  g* \: ~1 d
lseek(handle, 0L, SEEK_SET); </FONT></P>) c6 E0 t5 v1 \( Z3 W6 A. V1 p- f. J
<P><FONT color=#0000ff>/* * i: @  o0 a4 F  z7 O, v2 r3 E3 E9 L" f6 g
reads chars from the file until hit EOF
$ T: |; K7 M8 X' M8 D*/
8 s8 l! Q# F6 f, D* a, udo   K# i" |2 \. }5 c, `
{ ( m8 `) a( {1 n$ A  m0 a
read(handle, &amp;ch, 1);
( C9 j+ p5 n! f+ }3 i- F, zprintf("%c", ch);
& {2 ~& N( x' ?  t9 n% Q} while (!eof(handle)); </FONT></P>
( B% z0 }* P( T- G& k. n<P><FONT color=#0000ff>close(handle);
3 X! l8 ^$ J1 o3 g! m$ y- j) Dreturn 0;
, A! V. K: l/ ]+ |6 \} 1 C9 f* G" i: }, ]5 v. ^* X! D
</FONT>9 o- P5 \( g1 m/ ?# f1 g% j
</P>% u1 k( U) t1 a: F  W
<P><FONT color=#ff0000>函数名: exec... </FONT>' \6 y2 t4 ~8 \4 a% m5 T. v6 ^
功 能: 装入并运行其它程序的函数 + T: ?+ `$ u, s: m* K0 E" O) Y
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
1 F+ e) i) h* q# I. m6 xint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
( N0 q# G: K1 a2 ]$ ^! F% ochar *envp[]);
7 d7 y/ K( Y9 Kint execlp(char *pathname, char *arg0, arg1, .., NULL);
& c! W* ^' k2 X* W$ C1 D4 y" aint execple(char *pathname, char *arg0, arg1, ..., NULL,
' P/ }, y: t5 \char *envp[]); # u1 f" G8 S0 z) U/ ^; E
int execv(char *pathname, char *argv[]);
( j2 s! Y+ g2 Iint execve(char *pathname, char *argv[], char *envp[]); & c$ T$ U7 ^5 K# I: n
int execvp(char *pathname, char *argv[]); " g  X5 g1 P  ]# d. [" X8 r1 w
int execvpe(char *pathname, char *argv[], char *envp[]); % G  f1 s! [" W6 ~0 L) I
程序例: </P>
( s+ I6 B1 i. S<P><FONT color=#0000ff>/* execv example */ * Y$ J3 S' w  Q- f7 H
#include <PROCESS.H>9 v$ V8 F" O3 O" |  ]: A
#include <STDIO.H>
5 K$ ]$ i* T1 O0 i* h/ S( R# O$ t5 ?#include <ERRNO.H></FONT></P>5 N3 U1 p" t. u( [3 O3 w
<P><FONT color=#0000ff>void main(int argc, char *argv[])
3 a# H7 |- s9 ?+ }{ . Q" d! M/ R6 b, l: z
int i; </FONT></P>* I1 J9 b, ^0 o3 |$ Q6 @
<P><FONT color=#0000ff>printf("Command line arguments:\n");
! [" f4 ~6 S; hfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
) i+ d9 B, @4 K( Z# P<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); / i" W0 R6 g( S9 I/ N( F3 |
execv("CHILD.EXE", argv); </FONT></P>
; h, G9 O- X: [+ g<P><FONT color=#0000ff>perror("exec error"); </FONT></P>' x$ n: o' u' _4 G0 L4 _3 ]
<P><FONT color=#0000ff>exit(1);
* G1 A: a0 H+ ~; b}   l: U* B; ~9 e' F5 c6 X* }5 P
</FONT>2 B+ ~+ }' I- E" W5 A/ e
</P>
. Z$ O2 G8 ^" b3 f  j<P><FONT color=#ff0000>函数名: exit </FONT>5 i% J) p" ?2 a
功 能: 终止程序 & [2 m5 _7 E; }1 l3 P4 i
用 法: void exit(int status);
+ N# \# z9 Z: ?7 _程序例: </P>- W4 F- J& n* B! n; e7 M- C
<P><FONT color=#0000ff>#include <STDLIB.H>
5 B( u+ |* Z5 W' L- Z: K" ?# \#include <CONIO.H>
% T" a8 y6 H8 z4 F! @# A3 y#include <STDIO.H></FONT></P>
% |7 `6 x5 P. x- {: z; m( g<P><FONT color=#0000ff>int main(void)
4 ~% M. Q4 A$ n' S* t, b{
( O) l, f- y; N% T9 T3 `% M% Tint status; </FONT></P>
5 }( A; w4 V' t8 A& o<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
3 P: }/ i) B: J: @/ p9 @% zstatus = getch(); 2 `6 \4 K! S; k3 v. E7 a6 ]4 z
/* Sets DOS errorlevel */
) H: Q$ R, `# G6 X) h( jexit(status - '0'); </FONT></P>
5 L# d7 v+ U3 `: i<P><FONT color=#0000ff>/* Note: this line is never reached */
% V* j( f/ k1 D3 j$ r" m) Rreturn 0;
7 s2 {. j" _) q( N& \  j}
" g" P) O6 V  X0 F</FONT>
# k" G9 ~3 _+ ?* V8 ~3 ?5 r7 t$ g</P>
. K2 f5 y8 E8 K9 e<P><FONT color=#ff0000>函数名: exp </FONT>: g7 u1 L' g8 j; h: v
功 能: 指数函数
( q( }6 {$ k' y, ]# A: W用 法: double exp(double x);
$ e' p; I7 b5 k( p. W. U程序例: </P>' i8 h6 }/ L# k1 g) H) h3 Q
<P><FONT color=#0000ff>#include <STDIO.H>) k: H" @7 A5 d! `, A0 b
#include <MATH.H></FONT></P>+ @& I' K5 P, A4 }( V4 L: t
<P><FONT color=#0000ff>int main(void) 3 g/ _% T5 t4 x- l
{
2 N2 u/ P5 J+ h$ ddouble result; . |2 b# O& Z# u( M5 P
double x = 4.0; </FONT></P>
7 a" x% C7 `- k# ?4 l: n0 G<P><FONT color=#0000ff>result = exp(x); " D% p( v+ ]$ X  z6 G7 _
printf("'e' raised to the power \
$ s# t) e6 N9 A% A+ U- G7 vof %lf (e ^ %lf) = %lf\n",
9 V+ |- Q9 _. n; e9 t: zx, x, result); </FONT></P>; z8 E1 v/ E, I- o) c+ D/ A2 C9 r
<P><FONT color=#0000ff>return 0; 7 x9 }' T9 t' T. i; u
}
9 _" j" V( I. p& p9 v</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># }/ P/ u. A, G3 S4 b: K
</P>
# S5 {3 q* W$ @% b- a<p><><FONT color=#ff0000>函数名: delay </FONT>  l4 f  C9 @( r. k  ~
功 能: 将程序的执行暂停一段时间(毫秒)
9 X6 z* M4 r& ]/ F+ K用 法: void delay(unsigned milliseconds); 4 n4 @2 ~5 ]( a' t+ C1 \! V1 [
程序例:
7 i( Y0 {# |+ f9 k: G) Y3 t' O<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
! \8 r: x" Q* D#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) 5 N6 V6 j, C, F6 u; Z8 c
{
. N% b. e6 q' s; Zsound(440);
, f$ d) l1 ^) s" Y. h& J- Q% H4 }delay(500);
- I$ q9 L8 }, R2 ~7 ]nosound(); </FONT></P><><FONT color=#0000ff>return 0; 9 r: `! x3 o5 h# E# V0 p$ K
}
* h! p) N& R+ G7 n0 {: Q! k4 h0 Z- [% M2 `) S: q
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
" v3 N6 g! I/ ~9 |6 G- R功 能: 在文本窗口中删去一行 - E: v- Z; V9 g) T) j; O  r
用 法: void delline(void); : Z, W; N, s, e2 R( R6 E3 z
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
+ m' U; X% B. K8 R/ G, z: H) k) t{ 2 T. j/ J) o! p, h
clrscr(); 3 S0 A1 ~! C! g, X& w( \$ U
cprintf("The function DELLINE deletes \
1 c$ T: ]! f, i- h9 B' |5 T; Mthe line containing the\r\n"); ; h' a% E& h  f& L& P2 j. Q% c
cprintf("cursor and moves all lines \ / z: }! Z% s7 ~
below it one line up.\r\n");
' T( s, T5 s! h# j! b, G3 qcprintf("DELLINE operates within the \
- \% l7 [4 k; c1 Scurrently active text\r\n"); % I5 P; p5 W( L  K# q# i
cprintf("window. Press any key to \ - C, ~( Z: B2 c1 G% b8 \
continue . . ."); - v1 q9 Q' R4 A5 P% h
gotoxy(1,2); /* Move the cursor to the 3 H8 c* ^6 M7 j7 f3 h  O  a. h
second line and first column */ % [2 |0 z( m/ I
getch(); </FONT></P><><FONT color=#0000ff>delline(); : F  @/ f1 y6 f6 s3 f
getch(); </FONT></P><><FONT color=#0000ff>return 0; 2 x3 T( c2 D8 @9 Y" v: s+ B
} </FONT>* j1 u& }! A; m+ n& H: J+ Y, L
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
) l" v; R* j: ~功 能: 通过检测硬件确定图形驱动程序和模式 ( N/ s& K. \) |" f/ W# ^, g
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
  E6 p6 z$ l. }( c2 I程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>0 w& x4 f6 `8 D" V
#include <STDLIB.H>  n- F% U2 T  ?9 i, c/ f4 B- I
#include <STDIO.H>$ F2 o2 k  u: y5 ^$ c5 u
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
  A/ t  S2 u! O4 H+ e0 e+ [1 mchar *dname[] = { "requests detection", - Q/ v# r, a6 y4 B4 D8 a7 X' |
"a CGA",
( w: A  Q' t" O, S"an MCGA", ' _" y. L6 o1 N1 x
"an EGA",
+ R2 p7 \3 N! K"a 64K EGA", 9 u& ?- d% w# |, e
"a monochrome EGA", 4 j7 [3 Z8 Q- L  y
"an IBM 8514", ; j: ^. e. }3 U, y" `$ E8 b, w4 T
"a Hercules monochrome", 0 |$ I$ E. k' g$ q0 _
"an AT&amp;T 6300 PC", ; T* r, S1 e+ k2 P5 o2 a6 B
"a VGA", + |5 n/ l' z2 Q
"an IBM 3270 PC" ; W" b4 b0 E9 ?$ b: J. C
}; </FONT></P><><FONT color=#0000ff>int main(void) . z& y2 J4 X, d- |8 o. m
{
9 Q' K" S/ V5 Z' Z" X  T% [$ d' ]0 q. V/* returns detected hardware info. */ . \' V3 G2 h5 A7 N0 K' x' B9 K7 j
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
( e% x# Z" b9 r0 o8 Zdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */   G& c# @4 K! F" A) g% I* C
errorcode = graphresult();
/ f9 d3 x8 m% d* D- Aif (errorcode != grOk) /* an error
8 }# K" G" ]! P; R' Q5 J5 `# doccurred */
) Y! ]' h1 Y2 h0 O) u. z9 m7 g{ 3 v* V1 K- z7 |. e% ~0 r% m
printf("Graphics error: %s\n", \
) }5 Z2 Q. c4 W2 E6 C6 g8 Agrapherrormsg(errorcode)); % z9 J: V. W4 ?, I+ T/ O$ D
printf("ress any key to halt:"); ! Q& R' g7 ~' B+ l  R2 W
getch(); $ J8 L4 C3 M4 N
exit(1); /* terminate with an error 3 |2 [& x; I% E* H2 z9 D( o) A
code */ : {7 k4 |, Q8 W3 l/ n
} </FONT></P><><FONT color=#0000ff>/* display the information detected */ 1 d- o( C/ L) y2 k
clrscr();
6 x1 R; `* \8 L9 M  t: _* ]1 Zprintf("You have %s video display \ ! J% }, ^+ b+ w- }" T6 b
card.\n", dname[gdriver]);
3 Q( K! a) k% Bprintf("ress any key to halt:"); $ I  _% P) A) u3 O
getch(); % Y. l5 Z5 h0 ]6 h/ J
return 0;
9 N5 Q/ k3 H. D' d& r8 o} </FONT>$ ]: ]& |+ u' C% I8 X* _

/ D$ d- A* S/ e- U( h! b% s
; F+ I  R( P) b</P><><FONT color=#ff0000>函数名: difftime </FONT># l; W7 A$ h( m$ d8 |
功 能: 计算两个时刻之间的时间差 % {6 S* A& i3 r) V0 d9 O
用 法: double difftime(time_t time2, time_t time1);
7 r: b2 B. q$ c* j! |$ X程序例: </P><><FONT color=#0000ff>#include <TIME.H>' b: J- l1 q# w: h8 v# j* C. c
#include <STDIO.H>
+ i& @( z( p/ @7 e: L9 ~#include <DOS.H>
8 D3 P: Z8 u( `) [6 `#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) 5 A. X6 w  G) S# a) E
{ . S* Q) c8 o& g
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); & X0 m/ W' Z. S9 Q  J
first = time(NULL); /* Gets system 5 R' v$ r1 V9 j, E" \) r1 ?
time */
2 i2 p2 C" ~2 a9 y8 ]: qdelay(2000); /* Waits 2 secs */
: J$ {7 A0 t8 C5 \8 e& `second = time(NULL); /* Gets system time
, O, m1 \$ E- y) |+ i8 [5 M7 v* \again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ & d" _  \, R. b: e' m
seconds\n",difftime(second,first));
9 O1 U& k6 S, W# wgetch(); </FONT></P><><FONT color=#0000ff>return 0;
' {) u/ U: t5 e, T% B8 b3 l) D} 3 E( S+ w& C3 [: s- ~
</FONT>
% u& m- j4 u7 F# _& K3 @, b</P><><FONT color=#ff0000>函数名: disable </FONT>
5 A2 f5 `; r9 h! j( u功 能: 屏蔽中断 ' b7 f4 t# T( E: i
用 法: void disable(void);
  T( w: ?. P8 w. f/ d5 L$ N" w$ j程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
/ t, l( d% C* b- c. y# K( droutine. You cannot compile this program
( U/ m* n% s5 l: w) E8 e* E* Vwith Test Stack Overflow turned on and
9 E1 T) C/ s' Sget an executable file that operates
1 C9 A; A8 h& w, @5 Ucorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
/ h% L+ |: j3 j2 @8 r: B#include <DOS.H>, ^; o8 q% x, ~  j* \! k; M2 B' g
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
9 I8 A. y: I  [4 @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) ( @( U1 x; E. d+ \. W' q  ]
{ / E1 s! V3 a. D9 R" \3 Y
/* disable interrupts during the handling of & p" K9 h' L) d2 T4 l1 [0 X( [
the interrupt */
! v3 a( Q$ F- Y9 wdisable();
2 |9 ^9 a7 b- X6 E/* increase the global counter */ ' d8 U7 H+ T0 u5 s+ M0 E4 l
count++;
- l3 C9 }5 k; C/* reenable interrupts at the end of the " t' j3 ^, O  g
handler */
- K9 _: F$ T$ o0 Y( y7 Tenable(); , L- Q6 ?8 v+ N2 n! y. C
/* call the old routine */
3 U9 ~* C/ c; a% _7 o# w3 ooldhandler(); / Q" x) s9 G% _! k7 s, H
} </FONT></P><P><FONT color=#0000ff>int main(void)
$ R* {( u9 n1 ^; W% R7 m{
) k) y6 ~5 s+ Y8 T  r9 d/* save the old interrupt vector */
: k. }  J2 k% u' C4 |8 O* B5 Roldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ 3 y$ l3 d( T# z  S
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 5 w7 S7 K. Z- R/ r- I0 V
while (count &lt; 20)
% Z1 X  M( b0 P- [# F1 Tprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
8 V; E0 `3 a. J$ I( Ssetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; % d, w2 E6 K0 j, N, F$ }) m
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
( n& d( B! c2 {# b% H9 b功 能: 将两个整数相除, 返回商和余数 3 y8 y0 Y, Y( h, n' S* r
用 法: div_t (int number, int denom); ' |! M& E6 \6 n# S5 ]4 Y# g3 G
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>& u: X4 g: Y5 M% `: R2 f8 s0 e) [
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) , u8 K9 l$ p8 a9 ?8 ~
{
6 q- ^! q9 L: K  cx = div(10,3);
' |  l7 x) u( n. P: r$ T% o  B6 Q9 Gprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
( s4 H- h- j- q9 Q}
, ^, }% F& e3 _& n. A- b* g</FONT>! Q. p8 P" a+ C. C& j$ h
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
9 X9 @* p- b" c5 ]功 能: 获取扩展DOS错误信息 . R( e/ B" t. d( l
用 法: int dosexterr(struct DOSERR *dblkp);   X; G. N. I2 g& ~: {
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
# S4 y% I) |% ^5 S  r7 }& m#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
& |6 r, ^, `1 \& J! y  c{ 1 y. H& b7 }$ V! m! d( U- d! q; k7 k
FILE *fp; 1 N+ L! \4 _* E- T* Y  K* q
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); : s$ C4 s) G9 Y
if (!fp) perror("Unable to open file for
  z1 @3 H7 h& B: W* ]! ~reading"); / Y2 U" u& k/ E
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
) G' p$ J  W" \+ c  t3 @information:\n"); 7 O1 J: y; b; f1 h0 z3 @- i& q* v
printf(" Extended error: \
$ C: F3 d7 f3 m% H& y' r- k%d\n",info.exterror);
6 t3 K! m& l0 Wprintf(" Class: \ * M, \3 c7 |. c, Q  C- w% J9 m
%x\n",info.class); 3 y2 y+ `/ l5 F7 _6 V3 O' n
printf(" Action: \
+ J/ i* _; V4 s5 p$ w/ C%x\n",info.action); " x: C! v2 Z8 l( M; d3 A! n
printf(" Error Locus: \
8 _0 J$ P9 g2 w9 L) q. `( G+ P%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; . i. h& W% }! a/ P
} </FONT>
* P  v3 p: s+ Q8 F9 T: G" L
- Y7 Z; h3 i5 K" n+ c, {  H</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
6 X: J( @3 q& i; n5 p功 能: 转换日期和时间为UNIX时间格式 4 y) N7 D; M4 D5 X% @, a) Z: Q
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
) |5 N2 B: M- H6 S程序例: </P><P><FONT color=#0000ff>#include <TIME.H>( Z, U4 Z6 y4 X
#include <STDDEF.H>4 v  w" g- d3 D4 v9 _) R  N
#include <DOS.H>
( S. o9 R2 n5 p* [2 Z  e#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
% R: E! B4 h( W1 B* I1 Z{
0 t1 B& L$ f0 |% c0 F8 T3 Jtime_t t;
( r0 v+ x' R6 h6 t) [struct time d_time; . d, V$ H6 m" {" u4 {  a0 f
struct date d_date;
. e' `8 j& R' z4 G' ~. Xstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); ! {. M; o- L" w6 t5 W( }0 q* X  T
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); 2 S! o) b9 n/ ^. b; }  q# p
local = localtime(&amp;t); , l* t1 B/ W9 T# l$ Y$ N
printf("Time and Date: %s\n", \
; D5 n$ c2 T( N/ A. E8 r6 T+ Qasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; & i7 }; L+ n, D# C; R, L
} </FONT>. M/ O+ x  v4 O
3 l7 f  Q6 v* P6 X
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>! E+ B: b+ z7 Y$ J8 M6 F
功 能: 画多边形 8 [1 H+ q# s6 V/ [
用 法: void far drawpoly(int numpoints, int far *polypoints);
% v/ u6 t$ n+ F+ z5 F, O9 W) T% w程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>( X! k, b4 v! k, E* w6 G
#include <STDLIB.H>3 u/ A7 E+ N  ~! ]4 O( N' z: t8 \
#include <STDIO.H>7 s$ A. A, G. N0 E
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) - l8 R  L1 m& t7 \' q
{ 5 X+ W- h$ K4 H. X% M! i; O$ ^
/* request auto detection */ 7 |3 G3 s) D, q* e
int gdriver = DETECT, gmode, errorcode;
2 R  w/ f9 C: R, ~int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
" r9 U6 ?  v0 ?2 p2 C" X8 I+ ?1 Xint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local " a/ \6 p3 I6 W$ C* x* L" \
variables */ + J; B/ s5 b+ F- V# |
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ " k/ K' j1 A/ H8 {# u3 j
errorcode = graphresult();
# s. t9 K) W3 W- o* }' h& pif (errorcode != grOk) 1 _4 E0 Z& p! |0 u, c. g
/* an error occurred */
* Z: R4 L# p7 E0 u- C/ M{ " B% n- F" k; @" h6 O; @7 V& M6 a# s
printf("Graphics error: %s\n", \ ' U5 A! ^$ x3 I6 l4 V' |
grapherrormsg(errorcode)); : M6 P9 j$ e7 X: Q8 O! Q3 s
printf("Press any key to halt:");
$ Z5 l2 b9 f3 B/ T" H5 ]getch();
+ V0 Z. j4 `$ U% |/ \% b8 M: q: h/* terminate with an error code */ * u: c! j1 l, ?0 d6 U- c+ y1 s4 H
exit(1); 6 e8 G: ~# ?/ M
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
1 }9 n1 n7 {1 k5 a& o4 j& Y& A0 V1 t/ Hmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ - |4 k. L3 ^5 Z7 G( y
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ % i5 P8 G8 u+ n/ J9 R3 ^/ v
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
6 c2 }3 C8 v, j( I+ Rpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
/ v6 }6 x2 ^2 u. _" y% ?' Wpoly[7] = maxy / 2;
  {8 J4 ?9 e) O; a/*
, [( ~, K0 `6 v3 O# }. w9 [1 Edrawpoly doesn't automatically close + ^$ s4 o, a7 _4 M6 W
the polygon, so we close it.
5 w+ x% A# n* K  G7 n1 A*/ / [6 {5 D3 |* \# }& D; l
poly[8] = poly[0]; & P2 d! E+ R5 a6 M' D
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ ) U2 k3 O0 ?% o3 |, K
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 7 @* G( V4 z: |. U' D
getch(); / k3 l5 Q8 \8 o* ?! M. s- w' m
closegraph(); ( A+ j- |3 P! N) P4 J
return 0; . {$ ~4 O; N; B4 C
} 3 u& ~' L! q4 l9 [1 P9 v1 U! E
</FONT>% J% ^" s1 u" E+ M5 X
</P><P><FONT color=#ff0000>函数名: dup </FONT>  Q+ p' C! X. p# Z0 z6 T
功 能: 复制一个文件句柄 , C4 v- F' ]2 n5 c& b4 Y0 f
用 法: int dup(int handle);
7 A' f: \( }- i! G+ y; V, S. j+ E程序例: </P><P><FONT color=#0000ff>#include <STRING.H>5 S  Q& |# M- Y& q
#include <STDIO.H>& a' I$ g  v/ p8 J) n( e
#include <CONIO.H>
- [! ~/ @" x; q9 ^#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) # H8 ~0 D/ ]/ Z2 v
{ 6 L# M) o7 H" _2 {( a
FILE *fp;
) a% k5 v; d. [( C2 Q9 {char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
. F$ H4 t5 B' @& A" a4 x! tfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ , L' O- S7 M! w  ^& c
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 8 \$ B; a+ W8 d7 a
printf("Press any key to flush \ 5 Z7 {8 O$ `, k$ N7 X/ G/ {
DUMMY.FIL:");
" ]) y# D* m3 S3 m9 Mgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without - j$ J# V% |4 h0 @, m2 e
closing it */ 1 L+ C; C0 ~' H: f, o3 P9 o
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
7 s" q* V5 K! A, B! ukey to quit:"); : }4 P# n# U' r
getch();
; q5 v, w7 U; q6 z( p4 Kreturn 0; 6 g8 J$ Y/ a$ u3 \0 @, x/ H) @
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) / p5 Z/ P% b/ ~
{
. E( e5 [3 k" c6 N# P, Eint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ ; t3 r5 `  `, ?+ A- `
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
! o4 u, N9 a9 }% M" s+ gduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
! [% S/ b8 _4 J  oDOS buffer */
; ]* G" C& m7 c& o9 |9 x+ U. Q+ R* vclose(duphandle); 5 b  r4 H: r8 A8 F0 i% U. `+ b
}
- j1 ]1 {7 m6 r# F$ V( d! @! g' w1 W+ M& |
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>5 E- Q# S( o  c" ?% v, _
功 能: 复制文件句柄 0 T* s! u7 ?! e' Z3 D
用 法: int dup2(int oldhandle, int newhandle);
- _/ i  {2 I: t0 }5 u程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>3 C% k6 z1 p7 I7 f' Y
#include <STRING.H>8 l/ A+ j" w( B: X3 F5 h+ R( r
#include <FCNTL.H>
! _/ k0 ?1 ]' g& Q, D#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
7 s" O& Q5 J+ Q{
% Z5 ?* Q- W  w#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
( t& Y( a4 ~0 v1 U5 Rchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ / Z( b% D! B. P4 `
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,   `% B3 B3 i9 g
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard # h2 I0 `# |# `7 l( k
output */
' y, [/ ]7 Q; G! V. G. T- Poldstdout = dup(STDOUT);
' a6 g8 m8 h' ?6 r& ~: z" \# i/*
7 q, K1 _- Q' y; S* ]$ H: lredirect standard output to DUMMY.FIL
1 e4 N" h& ]1 r! M% j" `by duplicating the file handle onto the 5 e6 R$ |$ A" [  J
file handle for standard output.
% I& A4 v( B% r# B3 i' s*/
- M" Q' v7 _" S1 ]7 @dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
( S6 c/ M/ a" G2 w* S" Aclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
7 `5 B' X9 l' q9 X: Dwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output # o2 H  N6 w- @# ]
handle */
6 j$ x' c0 K# _1 x5 Bdup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
% g' G+ \: g& p! fclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; $ k1 h  `/ W! `9 d; g
} $ y4 }' t8 q9 a; E4 c
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-23 08:50 , Processed in 0.441943 second(s), 56 queries .

回顶部