QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2076|回复: 1
打印 上一主题 下一主题

函数大全(e开头)

[复制链接]
字体大小: 正常 放大
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:01 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>4 P9 S) x7 j' I
</P>+ ~& V+ d9 j0 i% o+ ?; A+ Y2 o
& V1 h/ {7 p+ ^/ s

* o8 [" V6 K5 @) i' y; u6 T. |  s<><FONT color=#ff0000>函数名: ecvt </FONT>
" b4 ^+ b: E0 S) A8 [3 C功 能: 把一个浮点数转换为字符串 7 G  D  K9 h6 y4 y' A5 ]
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); ) O) O0 U0 a2 @- E1 E3 b
程序例: </P>$ l7 x/ {$ o5 N3 b" J
<><FONT color=#0000ff>#include <STDLIB.H>
0 L( K  @- A5 N- a#include <STDIO.H>
- J7 D2 X: ?! y: z#include <CONIO.H></FONT></P>
& H  ]7 q, `1 ]% @<><FONT color=#0000ff>int main(void) % w; f! a- y* n/ ]( K# u
{
8 z: @  d, {5 q4 a. d, nchar *string;
! E4 P8 b; E& [! Fdouble value;
& V% }3 ^! y9 K& k1 yint dec, sign;
% L; {; _& R$ ]+ R  g* X( t# ?int ndig = 10; </FONT></P>0 Z2 W( F) z& h7 [  g
<><FONT color=#0000ff>clrscr();
& n4 w5 G8 M% c; u9 m& D/ [; w# svalue = 9.876;
0 E& B5 M6 c: Sstring = ecvt(value, ndig, &amp;dec, &amp;sign); " e  b: v* H5 M; \8 ~6 i/ d" G
printf("string = %s dec = %d \
' ?7 T; g2 k# ^0 \sign = %d\n", string, dec, sign); </FONT></P>$ X3 b- {; _: Z6 i  n; x1 x
<><FONT color=#0000ff>value = -123.45; 8 E3 r& s' U, ]7 s: G  H' }& A
ndig= 15;
( |* a! Q1 [4 q) {; S8 O% Tstring = ecvt(value,ndig,&amp;dec,&amp;sign);   ?3 a, u6 S9 T# t0 S. D
printf("string = %s dec = %d sign = %d\n", # A8 o% v3 {, E2 Y
string, dec, sign);
+ V, X; P( [1 _! k: e</FONT></P>* F6 T1 ~/ U2 C7 _: V/ d
<><FONT color=#0000ff>value = 0.6789e5; /* scientific ! M6 w+ k; d- H* `$ A1 H
notation */
: x5 z" `6 s, ^) v& @# A; Z$ i' Wndig = 5;
& h7 d* v# t7 Q7 i$ y7 Pstring = ecvt(value,ndig,&amp;dec,&amp;sign);
! H# B/ Y" W9 uprintf("string = %s dec = %d\
- c* Z6 w- }0 Z' U7 Ssign = %d\n", string, dec, sign); </FONT></P>2 ~+ |( P( |4 A  j- h: k$ ~& K. A
<><FONT color=#0000ff>return 0;
! G) P/ F9 [1 ]+ L* }- w& o} </FONT>
3 n9 K# l, N& f6 m" G: H! M6 Q
0 X  h2 @! ~% `1 u9 K</P>" g3 P" _# U' G& q! m* i. k
<><FONT color=#ff0000>函数名: ellipse </FONT>. d5 Z7 B. Y/ S
功 能: 画一椭圆
- b- A; d! Q9 V! U用 法: void far ellipse(int x, int y, int stangle, int endangle,
" ^, ~; ~, O8 s: V7 H9 _int xradius, int yradius); 7 }( s+ D$ S3 E/ b# Z& X8 t
程序例: </P>
4 B% [$ T/ ?; X6 n" p% O' k<><FONT color=#0000ff>#include <GRAPHICS.H>
# j" i) P, O1 H2 x  @# k" e#include <STDLIB.H>5 u# K% Z2 ~! ^  Y$ a
#include <STDIO.H>/ D6 Q. m* c+ I
#include <CONIO.H></FONT></P>
, B6 d- P" p3 W" F; O, c8 j<><FONT color=#0000ff>int main(void)
2 y* E: @1 w- ?; t5 V* {{
" x+ g) n" l! G" K1 ~/* request auto detection */
6 }' Z6 Q1 i5 K  i- ^& Vint gdriver = DETECT, gmode, errorcode; 4 o) n4 |7 J' Q
int midx, midy;
, M; W  {( q4 rint stangle = 0, endangle = 360;
3 J0 t: C$ p& iint xradius = 100, yradius = 50; </FONT></P>' T0 x! M2 s* D8 \# J' p
<><FONT color=#0000ff>/* initialize graphics, local variables */
6 r' E! l. a* E9 {9 Iinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
3 O. X2 d5 B6 `- o; |0 j<><FONT color=#0000ff>/* read result of initialization */ * D: B) Q9 E% m- s) {8 W
errorcode = graphresult();
, Y6 v  A1 P+ z5 rif (errorcode != grOk)
. m: D' u1 l* X  D5 P$ P/* an error occurred */
- I8 [. b9 q* L* z{ ' e4 T6 s# K4 V) i; S: _  i
printf("Graphics error: %s\n", # |- Z2 |/ p9 ^* j2 S
grapherrormsg(errorcode)); 9 Q0 q* e7 F) h/ b; {% X: c  y
printf("ress any key to halt:"); : o6 v8 r4 Q0 F7 T" Z1 `9 |
getch(); , s8 ]1 N7 M. i: }/ ^2 i' K; H3 _8 a/ r
exit(1);
  Q3 _" U& j( \/* terminate with an error code */
2 B, [' G' {+ K} </FONT></P>$ P# d8 b8 ~) v7 F9 r( I
<><FONT color=#0000ff>midx = getmaxx() / 2;
6 v, l' b& b7 mmidy = getmaxy() / 2; ' G$ l5 b+ a- c* w; b3 ?( r+ d5 f
setcolor(getmaxcolor()); </FONT></P>8 t" x; H& N- `# X  }  Y
<><FONT color=#0000ff>/* draw ellipse */
6 V) o/ e' B" r  i0 r5 Vellipse(midx, midy, stangle, endangle, 4 ?) p+ ?3 ^* w' V  I4 d/ ]
xradius, yradius); </FONT></P>" k4 L& t! |! J. P! {. s
<><FONT color=#0000ff>/* clean up */ " _6 F9 D" @3 u2 c& C' ?! T7 V
getch(); . m; |; h6 h; T# q; t1 w
closegraph();
! u( B; ]' F8 i' @& freturn 0; - J# Y- l- \* ^; Y- t/ p" J
} </FONT>
! a5 J- J( x+ s! Y: v: m% q0 v! M7 D3 d9 ?+ x# A. _, \
</P>6 r) R4 T3 Z% L+ _7 p! ]
<><FONT color=#ff0000>函数名: enable </FONT>0 P5 a3 o+ e- z. V
功 能: 开放硬件中断 6 X" H$ A7 {' Z* G- k0 _
用 法: void enable(void);
) F1 q' z1 g& R: ~: n3 o( w# Q! }/ x程序例: </P>5 n+ R& U* Q6 X* x' G, [5 i
<><FONT color=#0000ff>/* ** NOTE:
9 J2 G6 u2 m4 l+ v: nThis is an interrupt service routine. You can NOT compile this program 3 x" w, `1 `# n
with Test Stack Overflow turned on and get an executable file which will
/ H& R5 N0 d* v( W6 uoperate correctly. ! r7 l! S; v1 C1 K, i6 w
*/ </FONT></P>& Z) R4 x$ p2 o2 o
<><FONT color=#0000ff>#include <STDIO.H>
2 N) R/ T' [1 b* F7 f#include <DOS.H>& b4 H8 P0 j7 i
#include <CONIO.H></FONT></P>6 r# w4 J/ o, [2 O& B, ^
<><FONT color=#0000ff>/* The clock tick interrupt */
3 K4 `4 Z# F! Z#define INTR 0X1C </FONT></P>
' |- f" `6 j+ x0 q<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>: n0 w) b& ^! r% y. J9 ]! e" H* ^2 ]
<><FONT color=#0000ff>int count=0; </FONT></P>
  J1 x  K9 m" A<><FONT color=#0000ff>void interrupt handler(void) 9 f. d4 Q# A# h1 D- j  r
{
4 i# P6 D' z' H6 y4 c( @/*
' J  l( v3 Y( F0 Adisable interrupts during the handling of the interrupt
# g" |6 g1 f* l7 O- i*/ 1 M$ [- @- Y/ m$ b- D5 L4 }& i
disable(); 7 Q! ]9 A$ X9 s3 E; x+ |# e
/* increase the global counter */ 7 b5 J. C2 y3 a2 L  \
count++; 0 F1 m+ ?/ K1 O7 R
/* ) j( I. w  |# X" X
re enable interrupts at the end of the handler ) M! _/ f2 S# y. `
*/ ; a" x7 F7 u# u: T; R, z
enable();
0 |0 w& U% f8 |; V7 ?/* call the old routine */ ! L" e( @7 e" t
oldhandler();
* X  F' j' W" @% R} </FONT></P>6 K3 f6 b3 W7 E1 d
<><FONT color=#0000ff>int main(void)
8 |" J& u7 \: k, N{ 6 i9 B2 l9 k: q& f/ H
/* save the old interrupt vector */ / v2 K& p, W) R. `2 l
oldhandler = getvect(INTR); </FONT></P>
7 f2 L% v4 z' L% T( Q8 `4 H<><FONT color=#0000ff>/* install the new interrupt handler */ 0 o7 e4 G1 `$ H; f/ F, |" x
setvect(INTR, handler); </FONT></P>4 r$ {% T/ \% [% _- Y4 i; e# D# l6 v5 U
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
0 k! _2 h! T# N+ iwhile (count &lt; 20) 5 m; L" }8 u: O
printf("count is %d\n",count); </FONT></P>% y; R4 A1 ^1 l5 d
<><FONT color=#0000ff>/* reset the old interrupt handler */
# r% t* J9 \* C5 j; Q) E9 msetvect(INTR, oldhandler); </FONT></P>+ R2 A0 O- J$ z0 O
<><FONT color=#0000ff>return 0; ! B* ]( j4 Q; s# x' c- g
} </FONT>. ]" \% z: ]& H, k( ]8 Z; v$ v/ s
8 y% s' h/ x6 a9 J: J: \
</P>
5 S( R$ F" t6 {! g9 d* S+ k<><FONT color=#ff0000>函数名: eof </FONT>
. G  U; l9 g$ G' Q8 Z功 能: 检测文件结束
& H' b5 ~! y1 i# P用 法: int eof(int *handle);
$ _2 E/ `, Z" P, _9 C, z! G! D! H# [程序例: </P>
1 F- E' t* v' Z/ }<P><FONT color=#0000ff>#include <SYS\STAT.H>) B2 H! e; R1 O
#include <STRING.H>6 _1 `5 f. ]  R& p: V, q
#include <STDIO.H>, M0 d3 c- e8 o' J, m- {  x. g
#include <FCNTL.H>
/ f7 }" F$ l; x4 R#include <IO.H></FONT></P>
  Q2 P1 z; q( [7 V2 F, x& r<P><FONT color=#0000ff>int main(void) % ?$ X# q( H4 Q" [% L8 P
{
8 g( O6 k4 D& R* Pint handle;
9 [6 @9 ?. a. `char msg[] = "This is a test";
! c- A3 s/ }' N3 [7 t' s. @char ch; </FONT></P>* W6 w& s4 y" e
<P><FONT color=#0000ff>/* create a file */ . r6 |$ {% x# Q
handle = open("DUMMY.FIL", ' `* v3 q/ |5 z5 _0 B- M3 T
O_CREAT | O_RDWR, ! ^) ]% Q: ]* T  p( P) W- {
S_IREAD | S_IWRITE); </FONT></P>( K% J. F& x; e$ ?- Z+ h% }
<P><FONT color=#0000ff>/* write some data to the file */
5 d$ i+ ~! X/ ewrite(handle, msg, strlen(msg)); </FONT></P>. ~+ e5 ?7 e/ v; \+ Z1 d8 x
<P><FONT color=#0000ff>/* seek to the beginning of the file */
1 _$ \# N) u! r6 d# k: H9 m, W: J7 H) elseek(handle, 0L, SEEK_SET); </FONT></P>
4 @% n: a( m4 S" X+ X" F% I<P><FONT color=#0000ff>/*
  L/ s4 Y$ o8 b2 z( ?reads chars from the file until hit EOF
, b" z0 \  @; X" Q" z4 y9 ^6 X*/ " K8 j- p& p  A9 Y
do
! k1 u  C$ K7 z5 ~{
# f+ e! @* n- ^& i! [read(handle, &amp;ch, 1); & V/ W5 p: V% U  U' |) ?6 P% r& ]2 {
printf("%c", ch);
2 y  T' _7 D6 U9 I4 {, H} while (!eof(handle)); </FONT></P>2 m# e' Q) K! u( X5 f9 m
<P><FONT color=#0000ff>close(handle); . l6 N- A9 ]: q% t$ C( ~! o" w
return 0; 5 s1 ]$ ~: \& D, m  i
}
- W+ f2 v! }, A1 [. L" Q3 l- e</FONT>, V' u: I5 z# O0 b$ A' @' X2 H9 R
</P>
- ]2 P8 t: M1 U" Q  K: X<P><FONT color=#ff0000>函数名: exec... </FONT>
7 v. T, Q; s% D& h$ A' i6 Q- a功 能: 装入并运行其它程序的函数 ) Y5 v8 o) m" T3 y" D
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
2 ?% S* w$ n1 D8 v8 ?+ lint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
7 _# m; |* c2 E+ ichar *envp[]); 4 _5 V: X5 W" Y
int execlp(char *pathname, char *arg0, arg1, .., NULL);
5 T# w2 R! [) e! _1 pint execple(char *pathname, char *arg0, arg1, ..., NULL, 7 \- r* g9 p! T, t6 j- S& C3 C
char *envp[]); & {9 ~. L8 b" j
int execv(char *pathname, char *argv[]); 6 `2 I8 y& F$ w+ x% f% I
int execve(char *pathname, char *argv[], char *envp[]); / F9 E' {4 h3 I
int execvp(char *pathname, char *argv[]); : y7 X3 I, b7 q- M3 t. a
int execvpe(char *pathname, char *argv[], char *envp[]); 3 M3 D1 ^: q8 G8 ^& ^6 w
程序例: </P>
1 w( z1 N$ H1 [/ W<P><FONT color=#0000ff>/* execv example */ - d$ y  z0 L& v4 R) C
#include <PROCESS.H>
' ~" V' }9 W; D: d2 k5 p#include <STDIO.H>& |7 H4 \2 h" h
#include <ERRNO.H></FONT></P>
6 a' J5 u" k8 h, I<P><FONT color=#0000ff>void main(int argc, char *argv[])
) j6 l( E0 S7 c{
! ^/ X( y! i+ `int i; </FONT></P>* l, H9 X/ [( O" f3 k4 S
<P><FONT color=#0000ff>printf("Command line arguments:\n");
/ }* u1 s9 K, R: v& ~for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>: T  \0 M; `& G
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); ! L' J' |7 V8 A$ \, ^) F+ [
execv("CHILD.EXE", argv); </FONT></P>
8 ]& K* b. F# ?, v- A- [7 M4 `<P><FONT color=#0000ff>perror("exec error"); </FONT></P># g& h* E) l+ C# m( j
<P><FONT color=#0000ff>exit(1);
, T" }, e9 L) \" d2 h}
: e5 r: J! V- a0 R6 V</FONT>
# f8 x3 L1 O2 t$ U* @) _</P>
* A% b* {" o: I8 U7 A( X& h/ ?3 {<P><FONT color=#ff0000>函数名: exit </FONT>
5 x' T! Y+ Z( S5 ~功 能: 终止程序 " P+ ?6 I3 w; N2 e+ Z' \1 D
用 法: void exit(int status); ; G, J) m  @0 e$ Z/ E( K6 a. s
程序例: </P>* X  _4 z5 K' n/ f* L- n1 ?
<P><FONT color=#0000ff>#include <STDLIB.H>
: [6 ?% Y* t- {5 V4 V5 u/ O! ]$ ]#include <CONIO.H>
3 n7 o1 }! S& h# z* I#include <STDIO.H></FONT></P>8 g5 j7 R: I* ]( F; A
<P><FONT color=#0000ff>int main(void) 2 a: W) r5 X( p+ R! d
{ , q/ B  X- x* [: Y+ ~) E, Q5 Q
int status; </FONT></P>1 J) B- y  ~! H# i3 `, E2 j4 X" U
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
4 h! O' v, {' U! Astatus = getch();
1 \' B# |2 W& C- R7 L/* Sets DOS errorlevel */
, ?9 d: A! k: rexit(status - '0'); </FONT></P>: I' O- E/ s7 m6 N, I1 u
<P><FONT color=#0000ff>/* Note: this line is never reached */   i3 X* v* H0 ~9 X4 l
return 0;
2 }' l- c# z$ D3 s  i}
& a8 v* J$ g# ]" H6 c0 h, V</FONT>. o6 J# i; m4 ~8 X' K
</P>
6 W5 x) `! o! z<P><FONT color=#ff0000>函数名: exp </FONT># E3 \" _* k& S* \) b
功 能: 指数函数 3 m6 q# }' u8 w2 o" N
用 法: double exp(double x); 5 S; l4 c+ w6 w2 |6 |, P
程序例: </P>: j/ m5 A3 U% e$ J, _  x" j: V
<P><FONT color=#0000ff>#include <STDIO.H>4 ?: [' q9 D- {. ?; C3 u2 m- w% o
#include <MATH.H></FONT></P>
8 f  \: h' v3 u# ^<P><FONT color=#0000ff>int main(void) $ |0 H- Y$ N9 K. S8 w
{ : ?* T5 B0 M# z, L. u6 |4 g
double result; 3 ^8 g2 k2 E2 @
double x = 4.0; </FONT></P>. h5 x, p, a9 ^2 O& @& }
<P><FONT color=#0000ff>result = exp(x);   e1 b8 P& ^, s5 ^: Z! j
printf("'e' raised to the power \ ) N6 c2 R* i+ D4 L
of %lf (e ^ %lf) = %lf\n", 6 R$ j/ }) |8 o0 c9 _4 A
x, x, result); </FONT></P>
9 T( v5 [, q2 d' F$ O" ?. N) ]<P><FONT color=#0000ff>return 0; 6 C0 S' K+ F/ W# d1 ?
}
  M8 o% A5 z1 _4 q4 `9 R</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' s- O" j7 q( N& C1 @6 y</P>1 g6 ~! M; v# X: @0 Z0 p( A& Y
<p><><FONT color=#ff0000>函数名: delay </FONT>
! S6 w* c* d" l: P+ K5 D功 能: 将程序的执行暂停一段时间(毫秒) 7 ?& m0 n9 w7 H3 A6 j& `
用 法: void delay(unsigned milliseconds);   M( P+ _6 E  D  _# K3 y
程序例:
5 \! P) ^* a. o! [+ `+ W<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
9 Z- \1 b4 H" J: h4 x1 z$ A#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
( x, d! Z" }! ~" h+ Y  W: E4 B{
% d( E' n7 e; i7 ^( Ssound(440);
- ^) Q; S/ v# ]# F6 }9 _/ K& g# \delay(500);
/ u$ R0 }- n( y+ wnosound(); </FONT></P><><FONT color=#0000ff>return 0;
! @  y* U* L" D  {0 X6 A+ a. F} + R! e1 B9 q0 h4 N+ ]

$ {) N8 t) b' H2 Y</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>% j7 S7 P9 O& @0 u( x
功 能: 在文本窗口中删去一行
0 c( _& l- t8 D0 S2 v( j' g用 法: void delline(void);
7 J1 U( p, L/ q8 |程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
$ b- W0 e/ G6 w+ V  \# j{ ( h, e- d; s- Z3 A: l- A5 V
clrscr();
* y# O7 \6 K. }( y) q/ f  @cprintf("The function DELLINE deletes \ 7 H* F8 P2 O3 V) }1 a9 j
the line containing the\r\n"); 5 L: l% A/ o2 S. J; y1 p% N
cprintf("cursor and moves all lines \ ) M+ k, V  O. I
below it one line up.\r\n"); 5 t8 u$ K- F# I! Q4 u9 F
cprintf("DELLINE operates within the \ ; P2 R9 s5 a2 U+ }2 D
currently active text\r\n");
1 M6 s+ v& _+ k% p2 q( Hcprintf("window. Press any key to \ 5 W9 R( n7 R. D2 q& V+ [9 w
continue . . ."); 7 n; `9 H, |9 B2 p, c$ p! h
gotoxy(1,2); /* Move the cursor to the
' x% Z- n; g! r' w7 u: P. o5 tsecond line and first column */
: B- B* E' o% j$ e6 e+ p3 Xgetch(); </FONT></P><><FONT color=#0000ff>delline(); ) U3 g2 @) H& E
getch(); </FONT></P><><FONT color=#0000ff>return 0; $ ~$ D8 q2 V" o) d1 t) F* G
} </FONT>
6 u, D- b# e2 q  W4 P. i</P><><FONT color=#ff0000>函数名: detectgraph </FONT>0 E! t: x' T! i
功 能: 通过检测硬件确定图形驱动程序和模式 $ Q( Y1 r$ z+ M0 W4 n$ ]
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
# F7 ^; i8 O( _$ F; B程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
+ X3 I7 o7 A) G' b& R#include <STDLIB.H>
" U3 z5 V% G0 N' [# o#include <STDIO.H>$ j; t* i: B! o6 ]3 d0 @; U; Z+ X6 ^
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
" ]3 j$ G4 F  W/ l/ y9 X8 @char *dname[] = { "requests detection", ) F# {: X% G; R; d4 \7 l. [- j6 s
"a CGA", * }, Y! O' t& \
"an MCGA", # y! \; L: o( R4 Y; o
"an EGA", 4 d9 T$ _- @: H
"a 64K EGA",
& z+ t  h; S+ l" i2 f"a monochrome EGA", / }* j4 Z( b6 o* I$ f+ p6 P
"an IBM 8514", 1 e( C' N3 L$ T0 q  P
"a Hercules monochrome", / T# [& d! s) l  B0 {" `0 p( ]2 d0 M
"an AT&amp;T 6300 PC",
  |7 i# R6 f5 B! e8 P"a VGA", 6 K0 W& [& Z1 ]9 e. q3 W! {
"an IBM 3270 PC" 2 h' s9 \3 a0 g& T
}; </FONT></P><><FONT color=#0000ff>int main(void)
. D: v+ Q3 P$ ~+ @% Q6 x{
% v; H* r1 |7 h1 |% i6 J# h/* returns detected hardware info. */
. F6 z/ D5 c+ @. pint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ , C" ^/ M% [! W  C" ^% r4 S
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
5 r; J: k7 k' L3 C+ T# ierrorcode = graphresult(); ; v0 Y: Y( S. {1 g8 x( u5 E
if (errorcode != grOk) /* an error 9 O7 F6 b5 g/ C  v, E
occurred */
: b% P( b6 Y& L+ ~4 l9 q{
# T  S5 w& T9 `+ F0 Sprintf("Graphics error: %s\n", \ + D3 i3 v8 B3 T2 ~$ u( q
grapherrormsg(errorcode));
  Y7 a  ?+ C* J3 d# F0 Tprintf("ress any key to halt:"); + p- Z8 U& w4 H( H( i5 ?9 i" ]
getch(); ) m2 E5 ^3 M' N1 o- S
exit(1); /* terminate with an error ; s# i- `4 D3 |0 w7 i1 \. i& U+ v3 l; V
code */
- E. {' a1 _. y) F7 ~( ~% C} </FONT></P><><FONT color=#0000ff>/* display the information detected */ 5 u5 g9 n4 l* F1 U7 p
clrscr();
. b! V$ B+ S- F# m7 }' vprintf("You have %s video display \ ' g  P; B) [6 Q. u  ~* o
card.\n", dname[gdriver]);
4 C6 X- p8 |2 f3 w6 v1 jprintf("ress any key to halt:");
/ x, x$ U$ J& w) n# k$ M& Cgetch(); 4 g7 V1 y2 Z: `
return 0;
, k; O6 P' Y) L  N* S( `3 ?} </FONT>8 U6 _4 o5 b! q/ H6 l3 u- ^* @

8 n% V9 d: ^4 Y0 L& E4 a
6 m5 i( ]7 P3 ^5 \5 W</P><><FONT color=#ff0000>函数名: difftime </FONT>; C5 {% V/ U7 x
功 能: 计算两个时刻之间的时间差
" X# i6 Y  e7 I! V. c! U/ S5 ~* y# ]用 法: double difftime(time_t time2, time_t time1); 8 ?" f# W( x! M- V8 ?2 l
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
7 s' }1 v+ q$ r1 l" o, k1 [' F4 Z: i4 \#include <STDIO.H>
  L4 B) O: p" E#include <DOS.H>
/ a4 X6 k; @9 t#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) ; c: H/ K' {4 b# I
{ ( P& C1 p: C3 c! W$ q: g
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); # p8 u- s/ J8 Y# u/ B
first = time(NULL); /* Gets system ' d: k  V5 |' E& j% z
time */
! \4 l2 Y& [/ t. `- B/ I6 `3 c6 Udelay(2000); /* Waits 2 secs */
+ [" R! ^; r+ \second = time(NULL); /* Gets system time
2 X5 d% g, c' [/ |" pagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ 4 u$ ?) c8 l2 d' ~! @
seconds\n",difftime(second,first));
& ]. l3 f+ O3 _: A5 B: `; Y% }+ m" kgetch(); </FONT></P><><FONT color=#0000ff>return 0;
* Q" {6 ~  k' X# |4 m} 0 g, g( o) q; s/ @% O
</FONT>% s& J& |7 A! e. Q$ W
</P><><FONT color=#ff0000>函数名: disable </FONT>9 u/ ~9 B8 ^# k0 W
功 能: 屏蔽中断
# P( d) f/ A( M' ^0 ~. T+ k% `用 法: void disable(void); 6 c# s: O3 w4 |7 R
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service " b4 F8 H! _9 b4 N* Z! Y- I
routine. You cannot compile this program
, v: N8 ^3 j: n7 h- Wwith Test Stack Overflow turned on and
* h  t" T; A- \- m: M1 m! sget an executable file that operates
) U$ I* q. G$ h( @# ocorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>/ ]2 C) M8 `' U, m
#include <DOS.H>1 X0 V; U' T$ W( j
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
: t4 B6 P2 m1 ?! ^3 finterrupt */ </FONT></P><><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P><><FONT color=#0000ff>int count=0; </FONT></P><P><FONT color=#0000ff>void interrupt handler(void)
1 ]1 m" H0 q  p8 X{ % x5 ^  [, O7 n* Z/ w
/* disable interrupts during the handling of
+ N! b7 t5 ^! B. R! Q5 P) }& `the interrupt */
/ `) ^( T( @. v3 k# udisable(); 4 i- L8 i3 n. \/ ?' Y9 z
/* increase the global counter */
6 f! l* |, {. @7 `$ Qcount++; ( }  H; k5 ]4 \( F+ b, F: D! v) h
/* reenable interrupts at the end of the 2 @% K; k$ }) r& j, x" P4 f& m( P
handler */ - m6 K) D8 q' {; C6 I! n
enable(); ! o( n. F% T- q3 `" t/ O2 a
/* call the old routine */
: R' j7 [: [' F/ N$ G. L7 Holdhandler(); . y/ ?  V# b0 E4 g) K
} </FONT></P><P><FONT color=#0000ff>int main(void) ; k( q- U2 f) D! M$ r& w* I4 _! u
{
3 x& I/ H# B; m* x: Q/ ~) c# x/* save the old interrupt vector */ : A1 z4 c3 H5 I/ Q! x
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ # U: w% t/ D* s. [5 \
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
1 ^- q- X: d' Q: swhile (count &lt; 20)
( B7 `: i- o+ Rprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
/ h+ S" M7 O$ K: j. v* X3 qsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
0 F, O/ D! ?7 _) n" V$ s% }} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>7 u5 j3 r  O% }( b7 S- s7 F, h
功 能: 将两个整数相除, 返回商和余数
& x4 A1 V( B* `2 N6 F# c7 L用 法: div_t (int number, int denom);
( L7 f* c1 p8 N2 i程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
% |- x8 @: s# W# a; a#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) : u' a3 ^: B* Z7 @$ e
{
, V  u5 D7 k7 i3 F5 bx = div(10,3); : f9 D* m( c% z
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
% E2 V* E8 N3 P! R( ?} - Q8 ?, g9 X0 w9 |6 M# ]5 o
</FONT>
4 E: d, \- M4 S' T8 E</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
4 q0 h' o* k: U功 能: 获取扩展DOS错误信息
1 [' D( D1 R& Z0 O0 [/ Q+ K" j9 |用 法: int dosexterr(struct DOSERR *dblkp);
$ l, y& A5 ?; s5 W% F程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>% U" y1 H( g( i
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
" N0 u: S& [7 j' S2 F* H5 h$ M{ . _: _; y+ H2 ~1 K' O
FILE *fp;
, r0 m/ L+ e  S' X/ hstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
& H2 O( G, O% E- iif (!fp) perror("Unable to open file for
5 W1 x( r5 \( ?/ `  G2 Dreading");
% M& F+ S" q* O5 zdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
7 ?1 i8 [& L  jinformation:\n");
8 r1 b  w& G$ Eprintf(" Extended error: \ 1 A, s1 n& D9 `7 v
%d\n",info.exterror); , n- W' A, A+ A6 N
printf(" Class: \
3 A: T, y& A( o%x\n",info.class);
( Y# `4 ^7 w& Gprintf(" Action: \   M1 ^6 @0 Z9 P; ?2 a+ Z+ R2 @
%x\n",info.action); . S; K+ }  ~5 Z& x8 P
printf(" Error Locus: \ 1 C# [$ L7 R( `- Z* \  C; j7 r
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
" j* K+ S) Q: U( }} </FONT>
8 N. n5 |- m  ?( Z: w' h0 }# C& e& `& A
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
; r$ ^+ w9 E# E6 I% O功 能: 转换日期和时间为UNIX时间格式
1 s# T0 b/ p0 K用 法: long dostounix(struct date *dateptr, struct time *timeptr);
, c3 c( q/ a- U3 `程序例: </P><P><FONT color=#0000ff>#include <TIME.H>* G# A' z9 n  X
#include <STDDEF.H># I. Q3 W( p, U$ `9 R
#include <DOS.H>) y* R$ {. e- i; G( O# S
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) ; T+ r! x) ^) F* t
{ 6 ]& M8 n( e$ e1 y2 B
time_t t; ) H0 R* j+ p, }5 D& m
struct time d_time; # X9 r1 f9 t0 M  ]
struct date d_date;
! K- {$ s8 j4 W* s- s2 bstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
8 d, s9 U3 @! X" Agettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
% m# T; y2 s! K- p: ~local = localtime(&amp;t); 4 {5 X2 K! F) @  ?* M8 w
printf("Time and Date: %s\n", \ " Y+ K; A' r7 V
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
9 z4 I2 r) }4 P7 S+ o5 i6 i. [} </FONT>
. k% y9 h# V; r6 G3 O
. J4 d0 z- R+ C' j) r</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
) g; y' B) F1 z. \! j功 能: 画多边形
" [. X  W3 K" A& b) F9 P用 法: void far drawpoly(int numpoints, int far *polypoints);
* [" m8 m0 a5 K7 T3 ^* Y程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
. v' u8 T/ x0 k/ t$ T#include <STDLIB.H>
+ V: V8 e2 K0 @7 E9 y7 k#include <STDIO.H>
3 p2 o& T$ `4 Q0 u#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
8 i/ l, M# U' `& A5 v{
& V3 m0 A& t# ~8 \0 y" C+ t/* request auto detection */
+ j9 R, k" n7 z- a! eint gdriver = DETECT, gmode, errorcode;
) O: \, c8 Q  t" i  \) J- nint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
* d' u$ \- m" aint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local ! b( {1 j$ N0 D/ q1 h' I; V
variables */
% B+ y/ D. i. B) d* W' Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
9 i+ _9 o' F( k6 gerrorcode = graphresult(); " V( Z9 M  C8 j) n7 t
if (errorcode != grOk) * N9 F0 R6 [% e" H4 R5 ^) O* G
/* an error occurred */
8 l6 F, j4 J6 X: B. u2 S% z{
# k! x0 b- F# P2 j3 R2 Dprintf("Graphics error: %s\n", \ : L4 F2 R3 [) k# a
grapherrormsg(errorcode)); " J5 ?4 k# }! J# {- N5 m
printf("Press any key to halt:"); $ \$ _7 G# Y4 @& i
getch(); . g9 q8 W5 L9 y! @, T" P
/* terminate with an error code */ & C* ?$ \7 |7 D  c! |% ]
exit(1); ( {6 `8 M- _& S2 _( y& J
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); ) P, X1 j" v- b' l' @' W
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ / r. E- G- W( B. q, W5 j
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
% r1 N9 D& d6 P( s' {poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ 1 ~$ F  E% b. n% s; s
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
+ ^" ]  p7 _+ F3 v! {poly[7] = maxy / 2;
! m5 `" u% z& T" i" W6 b3 y8 x/* ) Z: v) R9 L1 Z8 i
drawpoly doesn't automatically close
3 x. K% C) s( ethe polygon, so we close it. , B! r) @1 Y' ^) b' I
*/ 8 [/ h. p0 R3 }+ l5 Z
poly[8] = poly[0];
! `6 X+ U: O1 l. h1 M: Y9 Kpoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ ; T1 e9 X$ A4 g5 Y; [6 O, G
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ # X# ~5 M" W" S
getch();
: y$ w0 B- \$ g) r: zclosegraph(); 4 v6 g( s" R+ w) _1 F# n# w  U
return 0; 1 Z% y" h! x8 g$ _
} 0 Z% y0 _3 ~+ O" `+ m+ E3 J
</FONT>4 G& T3 `1 @9 {$ b5 V' G: L
</P><P><FONT color=#ff0000>函数名: dup </FONT>3 ^9 S! f. T& Y# U) n
功 能: 复制一个文件句柄 * ~% ]! U2 J$ T( Q  P
用 法: int dup(int handle);
( n/ L& x# V- s* ]( h+ z程序例: </P><P><FONT color=#0000ff>#include <STRING.H>; t/ T) ?/ _8 B( o5 I
#include <STDIO.H>
; N5 ]3 N0 Z4 {& g2 R#include <CONIO.H>- D9 M# Z- k& Y' M: S: m; J" k
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
+ z8 D2 G' y9 b! ]+ h{
+ u+ X* |" E3 T, b1 u! SFILE *fp; ( m- d7 h& Q1 t
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
9 H/ Q' @9 l2 Xfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
9 S' x" }3 u( ^4 z/ [- y4 a" rfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
, f4 C: |3 E0 V# O- Q1 }; Sprintf("Press any key to flush \ ( ?8 m2 k- k# @8 y  v
DUMMY.FIL:"); & w% O0 D# T- M9 C2 c
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
0 |; R: A6 F3 wclosing it */
1 X9 i2 r% s' c- P+ R- `flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
8 ]1 X& @+ K1 n2 ]+ t; E1 Skey to quit:"); 7 t5 Y+ {; [2 _: x  _
getch();
9 A9 Z# R4 Y* V2 k5 x$ creturn 0;
% M! I4 I! q- ~} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
  V& P0 L* b; }0 a{ / J) e5 h4 F8 \
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
1 e% b& K6 S7 x8 f1 Ffflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ 6 M& |( c; @# f
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
  r; i4 R" I) K9 Z: ^DOS buffer */ / [$ R% \4 f+ p5 _& N0 U: E5 T
close(duphandle); $ ~0 o& F/ b" W8 J8 e
}
: w. K/ b" {* @6 G
6 K( ?+ H# O4 s</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>) H. E" t; L) T. F# Y
功 能: 复制文件句柄 . L! o; {+ ]' ?3 S" P  a
用 法: int dup2(int oldhandle, int newhandle); % s$ e: k$ W/ x; S. g; e9 t
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>) [% h* |3 d6 q. d' t
#include <STRING.H>
4 F! R; C( R8 J; q' d#include <FCNTL.H>7 [' m' ~% O7 J6 i2 u1 Z0 W. @( R
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 2 A4 o4 |( Q' r
{ 3 S! F! e5 V4 K8 ~0 k. Z" R
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; ; B' ~9 F6 x- b8 F( h" f# L
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ # W4 ^' A0 S6 F$ n. ^6 _* F  K( d
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,   W* S! Z' b8 G) H2 @% ?, O. ^
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard ) Y9 ]& J& B' S  ^; c- ^7 N
output */
' R! v" p: h; l& ~5 b" loldstdout = dup(STDOUT);   z: \1 V0 ~% q" c9 P5 l
/*
$ j' F" w  q! y: t4 oredirect standard output to DUMMY.FIL & c2 U' D5 c% ^5 Z
by duplicating the file handle onto the . s/ G2 }$ g- E) v' X1 J0 [
file handle for standard output.
$ X! C+ b# r3 e# Q5 j% X2 `*/ " W; D% e# `( J: L+ M* U* N
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
- R0 L6 ^: g- w" b  Pclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ , p$ u. c$ d$ l5 I
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output # ~& x2 k! a8 z/ z9 U% H
handle */ 2 v: |! Q. f1 U* _* J
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
3 K) D) E+ S9 r" qclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 7 S. [$ G% {! K; S& ^' `8 D7 t
}
: V  `# x, k# P  y</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-6-13 08:25 , Processed in 0.393911 second(s), 57 queries .

回顶部