QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2148|回复: 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>
. V* v' g) g9 T. k1 w</P>
( h1 A, L8 t& D) Y& R8 V: e! Z9 p% A

/ _! L0 j+ ?$ z- h) K# s8 {& k<><FONT color=#ff0000>函数名: ecvt </FONT>% K) y3 i, ?$ N; T
功 能: 把一个浮点数转换为字符串
3 E' I, D- ~4 b0 H5 \; B. u( B; Q用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); " A3 Z5 }( \) L* R/ O+ Z9 v" G
程序例: </P>
! }5 v# V$ F- n+ ^<><FONT color=#0000ff>#include <STDLIB.H>
6 J6 C+ g- k& G9 e: }4 _6 A! Y! K#include <STDIO.H>
9 K) g' W" v" X& d6 [. y! T- N" _#include <CONIO.H></FONT></P>, G0 [; B% `4 n. l, j8 M3 ^- H: ]
<><FONT color=#0000ff>int main(void) . J9 r' u% d8 a# W
{
2 B. a6 Y8 \3 Y) U7 wchar *string; 5 o' `2 s& H  Q( X. f6 e( U9 w4 W
double value; 1 z) I, ], q# g9 n1 [
int dec, sign;
, b- e* U( n) v; ~8 U! Iint ndig = 10; </FONT></P>1 L( o/ U/ F. [8 s
<><FONT color=#0000ff>clrscr();
2 J" @* y/ x: m) T3 s3 avalue = 9.876; . m1 C# Q& ^, q- y$ `8 ~( v5 d# \- x
string = ecvt(value, ndig, &amp;dec, &amp;sign);
& b4 p1 A* y3 dprintf("string = %s dec = %d \
) W, A) x: t$ isign = %d\n", string, dec, sign); </FONT></P>! v( Q8 s; a2 z0 G
<><FONT color=#0000ff>value = -123.45;
% X# E7 J; Z8 [ndig= 15; 1 e( n8 a2 E( y; D5 `
string = ecvt(value,ndig,&amp;dec,&amp;sign); 7 y' _. s! o0 j1 H
printf("string = %s dec = %d sign = %d\n",
5 h) e1 M: u! i: M. c0 lstring, dec, sign);
( a3 A3 X5 T! g5 b% @4 ]. N( `0 u</FONT></P>
! N; `* M( P6 O  ^* ]4 H<><FONT color=#0000ff>value = 0.6789e5; /* scientific
+ r+ g0 I6 `0 F7 A" W3 n9 Q+ [notation */ 8 a  \) q  i( p. Q5 F
ndig = 5;
" I/ ^# M3 }- J: M+ B1 n  Istring = ecvt(value,ndig,&amp;dec,&amp;sign);
. w) `+ K" x5 k$ I6 I- ~. Bprintf("string = %s dec = %d\
8 B. I3 i( ]7 c" V4 qsign = %d\n", string, dec, sign); </FONT></P>8 e1 Y+ g8 t' E4 V4 i+ `0 _# g! K
<><FONT color=#0000ff>return 0; & d3 G! K; R8 Q- ?2 ^
} </FONT>4 ?7 U* K4 ]' I  G. L2 A5 e

" D% T) Y! Z2 S" M$ _$ }9 r</P>5 m: b6 x' a. K+ A; Z9 h, D; S3 c1 e7 p
<><FONT color=#ff0000>函数名: ellipse </FONT>' s3 L% J% X- o4 W
功 能: 画一椭圆 : S3 x" D9 d( g& j& F8 i) {% L
用 法: void far ellipse(int x, int y, int stangle, int endangle, # v0 l( E8 [8 }# [8 Q
int xradius, int yradius);
+ o0 U' b9 h+ N$ [% M3 m程序例: </P>7 w' ^) s  F" o6 F; c" m) x
<><FONT color=#0000ff>#include <GRAPHICS.H>
- {% F9 q) |: ~# x% u" v. g  ?- v* W#include <STDLIB.H>) o& S, _$ _+ `" E: I0 V
#include <STDIO.H>: ?% `3 G! ~4 y- |( l! _
#include <CONIO.H></FONT></P>. G  m  k7 x+ B+ n/ X% n
<><FONT color=#0000ff>int main(void) 0 M4 C+ {- C9 T3 n# N
{
9 _, m1 K- t6 j/* request auto detection */
# l: r( V  G; D3 l* Jint gdriver = DETECT, gmode, errorcode;
* j! G" F- |2 W; n0 Y, eint midx, midy;
! q' P% x7 E& D  aint stangle = 0, endangle = 360;
  f* A6 {: [' a+ pint xradius = 100, yradius = 50; </FONT></P>
$ C5 C% Z4 a( L8 k; |<><FONT color=#0000ff>/* initialize graphics, local variables */
7 ~% x1 ~$ T' E5 F! I  J: einitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
1 k# o9 o; \8 _. f- s<><FONT color=#0000ff>/* read result of initialization */ ' l, [8 l+ r: k) T- j
errorcode = graphresult();
, N6 p. h8 y/ w) A1 J- l+ H1 s4 wif (errorcode != grOk) % n$ D% H' _, u8 S. i( Z
/* an error occurred */ ) m" R5 m  {. W& U! {7 ?/ ?
{
  \4 a8 M/ ~* w, F% Eprintf("Graphics error: %s\n",
/ B& A5 N9 @. }grapherrormsg(errorcode)); & I0 o' S2 a! T! A4 v1 w
printf("ress any key to halt:");
1 l* s8 P. N1 Z0 Q9 ?getch();
& i5 S5 G6 {$ P" _% Vexit(1);
9 |  H6 Z1 M8 q3 Y/* terminate with an error code */
# g* w0 Z! g# u( E} </FONT></P>) a, U0 a: x  Y1 y4 L. j" y! h
<><FONT color=#0000ff>midx = getmaxx() / 2; ' b: ^- Q  d9 H9 v9 l3 Y) _
midy = getmaxy() / 2;
, P0 A4 p7 r3 _: lsetcolor(getmaxcolor()); </FONT></P>
! c; \/ J8 n. Z- g9 {<><FONT color=#0000ff>/* draw ellipse */
. A/ t" R" V* B3 Q: r/ O7 \ellipse(midx, midy, stangle, endangle,
! `! |2 b1 \2 l3 l0 vxradius, yradius); </FONT></P>$ N4 A  X8 u' e# _- d
<><FONT color=#0000ff>/* clean up */ ! k% o1 e) x1 X( ~" \) t
getch(); # E, V1 S! Z0 k: L# U! Z; I
closegraph();
0 g1 S! |& `1 B( W) U2 L/ Ireturn 0; 2 y! G+ r7 k9 L# u& t, \" |/ h+ x- l
} </FONT>1 z# p# j# V" \8 q
8 d7 Q* j6 \: M5 J
</P>% A8 ]" ]% p, N- ]
<><FONT color=#ff0000>函数名: enable </FONT>& d/ ]4 K8 T6 ~5 Y
功 能: 开放硬件中断
  p) W" Z1 ]$ T, u  W用 法: void enable(void); 1 `5 _# Y1 X+ \! i& Q( P
程序例: </P>( \! ^  p1 J( i) w; A0 i
<><FONT color=#0000ff>/* ** NOTE:
! ?' Y  u, ]9 H& iThis is an interrupt service routine. You can NOT compile this program
3 h# h$ }. m4 gwith Test Stack Overflow turned on and get an executable file which will   s. z! [6 h2 z1 t$ W! ~
operate correctly. / i$ p1 [! k4 n2 e2 _7 ?
*/ </FONT></P>, `0 m& n+ ^: h  Q# B& V
<><FONT color=#0000ff>#include <STDIO.H>  P# J& Y2 z* H" B* X
#include <DOS.H>
/ x$ B' _( T& V" O#include <CONIO.H></FONT></P>5 ~5 g) w) @& M
<><FONT color=#0000ff>/* The clock tick interrupt */
9 |5 v; U" n# u#define INTR 0X1C </FONT></P>
% w# k5 e4 j# P8 X- i+ p<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>. {3 P+ p6 u9 Z& U; @
<><FONT color=#0000ff>int count=0; </FONT></P>1 n* ^, v# a; B) q; m; P4 `7 t
<><FONT color=#0000ff>void interrupt handler(void) " L! {  C5 t  h8 r0 J2 I; s: V" `) J
{
. `: V8 r  v$ G+ R/*
0 a- Q6 s" b& L, pdisable interrupts during the handling of the interrupt 2 F# f0 u; `) ]& E  {/ v8 M) f6 `) d
*/
/ e5 U$ P) E  Z4 u' fdisable(); 6 r; x" w: h0 [- O! q+ d
/* increase the global counter */ # |, a/ _% {, Q( k5 |5 z
count++;
3 r& b' c, L4 o/ T3 z& f/*
7 o3 e- N8 ^: @7 rre enable interrupts at the end of the handler 3 J1 z" a2 j! W
*/
) G1 P' b- u& {" L6 S# Y* |9 `enable(); : J2 U( Z# h  T4 [+ V* @, D4 w# P
/* call the old routine */
9 O  V9 |$ I& t1 D% u* Noldhandler();
7 |% _/ Y! l! k" R" }9 v3 x} </FONT></P>
# b) W1 c: L8 K$ y, Q8 Z- Q<><FONT color=#0000ff>int main(void) 6 e, `3 ~8 o- s8 D8 g7 O
{   @; s8 Z; Q3 a/ A+ B# c. h- U
/* save the old interrupt vector */
8 h% M9 P# n0 G! \" \: ^oldhandler = getvect(INTR); </FONT></P>
* P% \3 n( x( n" y<><FONT color=#0000ff>/* install the new interrupt handler */
* D8 {( ^: ^3 Q! N" _6 Q* Esetvect(INTR, handler); </FONT></P>
5 C$ H7 \# q& |1 T3 t<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ " Q( M6 m9 |- q3 Z) G
while (count &lt; 20)
3 s3 m: k1 O; @+ Y1 u/ Y3 _+ {, Dprintf("count is %d\n",count); </FONT></P>
. \5 _! q9 r. s7 `<><FONT color=#0000ff>/* reset the old interrupt handler */
( P6 Q+ |. A  V0 w) X  [setvect(INTR, oldhandler); </FONT></P>
. [- ?% f5 l: D( t<><FONT color=#0000ff>return 0;
9 N3 B. Q* l; @9 @} </FONT>
! c$ J6 [0 ?2 L0 G% W
/ m7 E. `: y) [# R$ G$ w</P>
2 Z* u( {/ ~9 N8 r<><FONT color=#ff0000>函数名: eof </FONT>" m1 L, h, s0 n9 |3 i+ f
功 能: 检测文件结束
6 Z. ^) x) C8 b5 C' ~; [2 |/ \用 法: int eof(int *handle);
' R+ @2 w5 H3 J. s8 D程序例: </P>
* x) z1 p: C6 c8 U$ |9 s( l# K<P><FONT color=#0000ff>#include <SYS\STAT.H>5 m+ F+ ]7 J$ \) Q
#include <STRING.H>/ }/ a2 X! P* A; K' g
#include <STDIO.H>: d" p' H0 Y+ \3 R/ Y* W4 S) G
#include <FCNTL.H>7 k( C- |0 f6 `& `
#include <IO.H></FONT></P>
2 n4 \3 N8 E: Z6 Q4 u<P><FONT color=#0000ff>int main(void)
0 H" F' R  r( }" |{
+ I  D& @: w% hint handle;
4 ~7 d; G# D% g& X- ichar msg[] = "This is a test"; , s) }! I8 W! ^7 B9 H) M0 z1 q
char ch; </FONT></P>
- j# Q) h) a6 B2 D5 Z0 ~<P><FONT color=#0000ff>/* create a file */ ) D: J' z+ B& W- Z$ c3 J5 k
handle = open("DUMMY.FIL", 6 @* z5 E- [4 |* z
O_CREAT | O_RDWR, 9 p2 ?7 Y" F( V  e+ I9 t7 k
S_IREAD | S_IWRITE); </FONT></P>
! O1 I% E3 p4 x. m/ x% X2 w- e# w( m<P><FONT color=#0000ff>/* write some data to the file */ 4 g' V- S. ]) D
write(handle, msg, strlen(msg)); </FONT></P>
7 m2 A" }$ E5 O0 ]# M' ^5 t<P><FONT color=#0000ff>/* seek to the beginning of the file */
- y! t' \9 T0 t4 Z7 }lseek(handle, 0L, SEEK_SET); </FONT></P>
, v. M! d+ ]0 o<P><FONT color=#0000ff>/*
5 C+ V2 u8 [! ?# U9 h- k, O" dreads chars from the file until hit EOF + a7 P: z4 R& ?: i- r% \
*/
' \5 m, B  o% sdo 3 I% o6 A$ d# G$ V( w! _; Z; u
{
$ ~4 ^# M0 B5 d/ Q8 y* U3 U+ I- vread(handle, &amp;ch, 1);
; u0 q2 o+ b8 ]# Pprintf("%c", ch);
# m0 V& O  a' C& i1 Y# J+ _1 T} while (!eof(handle)); </FONT></P>1 s1 A5 P- r4 P- S( n
<P><FONT color=#0000ff>close(handle);
/ |( O5 [' Q0 W& dreturn 0; / {; ?# z( [5 P* U  x: v$ e
} $ y" ~$ s( I4 p% o7 L/ Z
</FONT>
/ a/ |4 C1 ?6 o/ ^</P>5 g6 F7 L. X1 M! X1 F4 `
<P><FONT color=#ff0000>函数名: exec... </FONT>
, ^1 l" k& T3 F5 E3 D0 x功 能: 装入并运行其它程序的函数 + A: C% n- s- p" u, Y6 ^. }
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); 4 J# L* o* b) }
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
/ {5 x- @5 K* O$ l  kchar *envp[]);
4 B$ u# q3 I3 ]& k- N- |int execlp(char *pathname, char *arg0, arg1, .., NULL);
6 b: r* h" l4 Eint execple(char *pathname, char *arg0, arg1, ..., NULL,
$ `: l1 q5 q! D0 M/ v1 Lchar *envp[]); # g% {' M8 y- I5 m* o% d
int execv(char *pathname, char *argv[]);
+ a2 E; v. @. bint execve(char *pathname, char *argv[], char *envp[]);
9 V* ~1 F: P- ~% b/ f6 T1 zint execvp(char *pathname, char *argv[]); $ y5 A1 l8 U4 t8 o+ E* o
int execvpe(char *pathname, char *argv[], char *envp[]);
0 m3 j5 w5 w4 Z; p程序例: </P>
1 i, v( e7 }0 D& A<P><FONT color=#0000ff>/* execv example */
2 k$ p  t  L- r#include <PROCESS.H>
) Q1 O( a+ w) S/ R' R. v7 ?4 q#include <STDIO.H>4 l9 Q! {; y1 n2 `. `% i) [
#include <ERRNO.H></FONT></P>" K1 J* y/ ^5 p. k$ L" _  C' O
<P><FONT color=#0000ff>void main(int argc, char *argv[])
; K3 _) ]/ ^( S/ k$ J0 L2 J$ U; s$ F$ W{
" T' D/ l: n- L* [" Jint i; </FONT></P>7 }( R7 J/ v( X6 w$ a/ k
<P><FONT color=#0000ff>printf("Command line arguments:\n"); 1 c2 ?' ~% Z( X* d
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
6 L( s* G% i$ Y1 `1 B/ ?<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
, o# J5 E5 v% O5 d% n; w* |execv("CHILD.EXE", argv); </FONT></P>
( F5 _) I$ a. G- R4 g7 |3 ^# b8 g<P><FONT color=#0000ff>perror("exec error"); </FONT></P>3 _9 o. U7 K, p) z0 U
<P><FONT color=#0000ff>exit(1); 5 }8 S- m; h; F) E& A
} / b; A6 k* [9 @9 }4 D
</FONT>& n. K, A8 V6 q: l
</P># `: V. I9 u2 I4 p3 Q3 |
<P><FONT color=#ff0000>函数名: exit </FONT>0 U2 y: ?$ S3 g* N. d- F* ]* t) R
功 能: 终止程序 ' U6 C" a2 b: L( O* }* O8 s7 z0 p
用 法: void exit(int status);
1 H. C* m6 P; i0 M程序例: </P>2 {" x/ O0 p; Z9 ?% ?  u
<P><FONT color=#0000ff>#include <STDLIB.H>
/ C* g, Y) n0 q9 t8 L% f7 R#include <CONIO.H>  \& q, H) p" {
#include <STDIO.H></FONT></P>4 W7 C1 s2 G" g4 h" F
<P><FONT color=#0000ff>int main(void)
) v! `4 a& m# w3 ^& P{
  A2 O/ R' A# F/ a' Zint status; </FONT></P>
( @6 y8 i4 r, V  }/ p, g8 ~<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); + w3 }+ h0 x% R
status = getch();
/ ^6 H) x# x6 o; |6 ~: A/* Sets DOS errorlevel */
0 D; T2 c' T$ R/ v8 W3 y# Oexit(status - '0'); </FONT></P>
# R$ @, z2 F/ m8 q5 `4 z) i! ~<P><FONT color=#0000ff>/* Note: this line is never reached */   ^, [$ L, K; n
return 0;
4 n8 v* _8 R5 J, e+ _: G} 6 j5 t8 F: ?) \# Q* Z# a+ _# S
</FONT>! ?! p8 Q9 w5 a% H: m5 v
</P>
4 i: q9 u4 D* s; a- X& o<P><FONT color=#ff0000>函数名: exp </FONT>/ M' \5 @1 [4 |) v. U
功 能: 指数函数
  [1 Z3 K" R# l8 T* I用 法: double exp(double x); $ h0 G. p6 E$ }$ t' g; d
程序例: </P># t6 {+ c  N4 o% o( K1 |+ L
<P><FONT color=#0000ff>#include <STDIO.H>
) d5 ^$ u* [1 M1 y#include <MATH.H></FONT></P>2 s) F" r8 A! H
<P><FONT color=#0000ff>int main(void)
' \# y5 K" B/ Z4 b4 F! m{
- ]2 X- X5 G/ X4 `. Tdouble result;
/ i  [1 {7 f' u  [# W7 B3 H+ @double x = 4.0; </FONT></P>% b7 R0 J1 m  Y: K0 _% r
<P><FONT color=#0000ff>result = exp(x); " I+ W  q3 Z# `+ O. X. P) c, q
printf("'e' raised to the power \ # n+ g% E" M8 Q% p+ K
of %lf (e ^ %lf) = %lf\n", 4 Q# z1 O7 W& O; L
x, x, result); </FONT></P>' w  ~3 m% S/ G% y' Z7 K' X- k( ^
<P><FONT color=#0000ff>return 0; 5 g+ x7 Z: ^3 e3 H& Z# [
}
% @" c' `5 `4 ~, _7 S</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>
5 @0 A8 r, P7 X</P>0 V3 g: A7 V' c2 f% i6 j) w
<p><><FONT color=#ff0000>函数名: delay </FONT>6 Y3 G3 `2 i9 A" C0 R$ l
功 能: 将程序的执行暂停一段时间(毫秒) 4 p0 m3 D# k6 N2 e3 [1 [& ~5 g
用 法: void delay(unsigned milliseconds); 5 l* K( l& I0 A
程序例: 9 f& v. b, u  i* C& c
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ( q9 x& m. ]2 x* A: T' ]
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) ( ~; w3 m' ?7 G
{
- L5 o! f, D4 [% Q! isound(440);
) L$ D* d6 I2 w) D, G2 ^) I  qdelay(500);
: L- W# O( A5 r  d  k$ dnosound(); </FONT></P><><FONT color=#0000ff>return 0; " K: ]  n: ?; b: S7 B
} # k% i# x8 D9 E7 x. y9 x; F7 m! e8 ~

/ ?/ r" z0 D, k' x) N8 K</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>2 a$ e+ o; D  h+ y
功 能: 在文本窗口中删去一行
/ f( s0 x4 w" k用 法: void delline(void); ! f, @6 @" J/ j' o7 @+ t
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
7 N* f+ x! q- D( c% ~( T. F3 D" }{
7 `$ D* P8 |+ ?9 f, s4 w/ fclrscr();
* l  Z; m0 y+ p% G1 ]; ^cprintf("The function DELLINE deletes \ 2 U4 R) m% R, F$ i+ J4 L1 c
the line containing the\r\n"); - L7 z9 j0 t/ E# P0 g7 P
cprintf("cursor and moves all lines \
1 L0 t7 v  n' ]% v, {3 mbelow it one line up.\r\n");
3 I% Q) s, r; y! s8 pcprintf("DELLINE operates within the \
: `) o3 b+ U4 l! J! K2 I1 kcurrently active text\r\n"); ; x" {8 e1 U7 `; n/ h" w4 G
cprintf("window. Press any key to \
2 c! V$ W& w7 ccontinue . . .");
7 o0 e% X+ C% Q, }) Egotoxy(1,2); /* Move the cursor to the
3 P. w& ^, e( J1 T# u+ o4 Rsecond line and first column */
( @1 r4 a1 y4 \* L2 Kgetch(); </FONT></P><><FONT color=#0000ff>delline();
. T# x) }* C; a1 R: C0 S8 }6 ygetch(); </FONT></P><><FONT color=#0000ff>return 0; 2 B" C1 A& H1 |! S2 x
} </FONT>, ~, }5 m0 J; o7 Z4 ~- V1 V# Q7 P
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
4 m; E, y/ l% k功 能: 通过检测硬件确定图形驱动程序和模式 5 h' L7 k) X8 i& {* Z
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
$ V6 x/ w" Q  y  Y* x程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>2 Q$ ~' [+ ~7 z
#include <STDLIB.H>
- a# j2 C# r3 I/ ?#include <STDIO.H>% ?) H' Z" x( I7 W( v8 f5 \
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ ' k2 a7 s5 y9 u8 n! Y3 B8 {
char *dname[] = { "requests detection", , T% t3 a' `. p% Z0 i; n
"a CGA", ' \$ l8 ?' ]( T' f2 O- l
"an MCGA", ) @9 j# _: L" G; [/ T0 ^6 S' c5 w+ F
"an EGA", & ~  B& v2 c' `  K
"a 64K EGA",
0 W5 E" ^5 P3 s9 {1 c5 t/ k"a monochrome EGA",
1 J8 [* o7 K4 \7 R) i% P, Q"an IBM 8514", # ]: [- @( |* v: s% y8 U+ i
"a Hercules monochrome",
5 ]6 e( B; u! q; O"an AT&amp;T 6300 PC", ( t( H' n& {  g. Z% v7 W% ?3 a
"a VGA", # i0 v, w, ~* O3 @" l2 b7 r4 J
"an IBM 3270 PC"
* e$ }( L) ?8 V" Z% G}; </FONT></P><><FONT color=#0000ff>int main(void) 1 q: {6 _# P& n+ I6 d9 Y7 _5 r
{
+ ]* @8 ?5 ^9 D9 z7 ^/* returns detected hardware info. */
( w% S9 P7 J4 f: y/ y1 Z6 u* ~int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ . p! }7 O8 B+ T, g$ d: G- P
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
* U: Z# _- t: f0 v2 @; Xerrorcode = graphresult();
+ J/ K8 B5 w$ C# nif (errorcode != grOk) /* an error : z# T, o9 o, ~! J. Q
occurred */ 7 b6 Y! E, g  p. \0 t1 j. j
{
) C) p# {9 [  L% v+ s3 hprintf("Graphics error: %s\n", \
; Q/ e+ j, Z' D$ Ugrapherrormsg(errorcode)); " G8 d3 s  [4 k/ [# l$ k
printf("ress any key to halt:"); 5 c. W. {1 X; w  [: W
getch();
* F9 A! D  k$ M3 R; p* o% |exit(1); /* terminate with an error ' s! e# k+ {. t; Z3 ^8 C
code */
3 t, y4 \/ u2 \' c' N! i} </FONT></P><><FONT color=#0000ff>/* display the information detected */ ! |3 \6 g# `; K) s" ~) H
clrscr();
* _. L. S! X/ _% I+ pprintf("You have %s video display \
7 C5 |2 D" f6 @card.\n", dname[gdriver]); , H5 f& @  ]- M/ f, `6 Z' y
printf("ress any key to halt:"); 7 K5 ?- w: r% `# v+ M' C
getch();
! d8 v+ n+ X) p5 S* [7 Zreturn 0; . N" ^" N/ p+ W9 S, q
} </FONT>
" ]+ K, u5 n3 y
! |) B7 b  V! C
* _+ U: D1 a% Q</P><><FONT color=#ff0000>函数名: difftime </FONT>; X* L) t. {; g3 {1 v
功 能: 计算两个时刻之间的时间差
. T" b  b2 c3 m- y4 c用 法: double difftime(time_t time2, time_t time1); + n& n3 w1 j; h. `
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
9 e% E' `! C2 ~0 m5 W+ G#include <STDIO.H>
, O/ k" \' x. D$ t#include <DOS.H>
# x) Q! q* \7 [7 s. v% H#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
: t) S* X" d  ]) ^- b. @2 r{ . y+ p( l2 ^$ V! c" _8 u
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); " Q7 W, v) O& y* O" s4 H
first = time(NULL); /* Gets system 9 u; p& J* E+ E
time */ 1 p0 F! }& U7 L
delay(2000); /* Waits 2 secs */
0 o. Z0 I: z  L# ^9 gsecond = time(NULL); /* Gets system time 0 ?# y5 }8 x& N8 {# i
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
$ h2 N; b2 t' zseconds\n",difftime(second,first)); 6 |" u2 e  X- t/ Y1 G/ |' M( d- O1 K
getch(); </FONT></P><><FONT color=#0000ff>return 0;
- T( Q/ W, [% f5 R' C5 p7 k3 J} % r. d6 b/ U: r" c+ o5 m5 n
</FONT>/ Q" j; t$ `3 N
</P><><FONT color=#ff0000>函数名: disable </FONT>
' Z8 R+ K+ T/ s1 d8 r% T, g功 能: 屏蔽中断 8 j* p8 _- ~8 J- ?! D
用 法: void disable(void);
: ~: d" b5 a1 Q, e程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service ; T; D; @! d+ _' A# f
routine. You cannot compile this program , _- [" C8 R5 j6 _5 i- n9 ^
with Test Stack Overflow turned on and - l% c4 G  B8 e/ S* N+ E/ n
get an executable file that operates 9 f9 G: C$ o* n9 n6 {$ v
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
) z* d6 W" |: ^8 B, H% J#include <DOS.H>
" \3 X3 M6 _$ Q5 T#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
. |0 o& L& Y' W- ~3 {9 winterrupt */ </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)   e2 g- J* _/ O
{
0 L( q9 V, S7 l/* disable interrupts during the handling of + `' r5 L: E2 t0 k* C' ^
the interrupt */
# j  N! u* [: a! B# H8 ?disable(); 5 i# D+ O6 O. ~9 n  G
/* increase the global counter */
) p" a4 ^, L, O5 ^4 {count++;
2 o: D9 |# E; ^% S/* reenable interrupts at the end of the
  T$ j0 D; B1 p1 [" \+ X5 shandler */ 6 A* [+ |2 q9 |
enable(); ; k5 G. o+ d  q6 X
/* call the old routine */
7 t6 X2 G0 j* g( Yoldhandler();
  Z9 U) r/ d0 N+ I, i5 s+ T} </FONT></P><P><FONT color=#0000ff>int main(void)
% R% ~! a4 D* C{
2 `7 F5 ?$ o0 F1 o0 W/* save the old interrupt vector */ - {9 f8 T3 J& W1 q8 R' d! L
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ 3 J5 B& B# M' K' p: |7 }5 W
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 8 B% a7 O7 B) `
while (count &lt; 20) ; A% Y1 N, v/ m& U$ S
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
  n- U: o7 X+ k$ z! G* a/ dsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
8 t1 e  }0 ]9 P- m% p  }} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
* v6 {( v2 l. B0 J8 H4 L功 能: 将两个整数相除, 返回商和余数
9 ~; ^( y; n4 L% g5 Q用 法: div_t (int number, int denom);   O7 N% D; e0 }# ?& L( G
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
7 Z1 a6 \) D3 p. b, j#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 5 [: p) u* J! [% L6 i: |3 y) [( W" J
{
" O0 W: z/ A1 m- ~! w- x. tx = div(10,3); ! ?9 b( r3 J. A- @8 d8 x$ r
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; 1 N* P* a' i- K+ G3 ~
} $ ^5 s  V. U7 I
</FONT>' a' M% d  c+ ?. T! i* s
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
! Y4 J1 J4 X9 _# [" h9 ^% g/ v功 能: 获取扩展DOS错误信息 " O) v9 {' H& P2 H  W: R
用 法: int dosexterr(struct DOSERR *dblkp); 8 c" k* d- d; D' V* a# q, ]# }' B
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>/ {( D: h) I$ v+ ?
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) * o( P" u" @, f# h' V6 L
{
3 D; d9 p1 }! oFILE *fp; 6 ]: E) O: ^9 r3 c" M
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); ; ~4 P+ ?8 j7 d: d
if (!fp) perror("Unable to open file for ; [4 C! H* {+ c& q$ C
reading");
! d; a3 G% j" a: Z( O8 rdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ 6 g9 s0 |6 K. Z: D
information:\n");
; M% {+ Y) q0 K1 S+ q$ E- b7 j1 u" Bprintf(" Extended error: \ " T+ q! u+ t0 \+ [+ k
%d\n",info.exterror); / ]3 j, y3 j' w" A' \
printf(" Class: \
8 I% a1 I7 z3 G( w0 o%x\n",info.class); / U  s, _( p" A( U! M
printf(" Action: \ ; s# I9 x+ O" z7 L$ n! D
%x\n",info.action);
& l" @# M  O( u. r) fprintf(" Error Locus: \
& x1 W0 Y8 F# N" y( a( P2 m%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
' P! P' K& S1 K# A9 ^, d; P} </FONT>. q; R5 g: h( N& _  l0 }

2 b4 T+ r; O# W# Q</P><P><FONT color=#ff0000>函数名: dostounix </FONT>5 ?1 h  j3 Z/ {9 r! c7 B/ |
功 能: 转换日期和时间为UNIX时间格式 ( K6 f+ S0 F* z# c, C% r8 H9 u( H3 b
用 法: long dostounix(struct date *dateptr, struct time *timeptr); % _" T( y0 i* n' L5 l& o* f5 q
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
. [! D) k8 N( t5 ^: S! s8 H* y#include <STDDEF.H>
0 S( z) Y5 K3 q( Y9 ^+ U#include <DOS.H>
7 c4 t, E$ h' K7 A  U! A: b#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
4 @( k) z% t/ {# b/ d" l{ ' P0 b; n, _" I. G/ m; A
time_t t; / p# w" n: B; A3 z4 |, [" j0 h5 l
struct time d_time; 9 e# e, k. d' V0 R( D+ }
struct date d_date;
) u  L! D! q* o, k- hstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
1 ]+ c9 R6 u! l% H% @gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); 0 C& L0 V; {* A& [4 W
local = localtime(&amp;t);
$ }+ R" S* V6 h: h& u8 }% x3 Fprintf("Time and Date: %s\n", \ 2 a3 R% b# S/ ^( O# ]; B
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
! u7 J3 \- P8 f; y9 Y} </FONT>+ n$ k: D* m+ c0 p, u7 A
6 G5 B# U! u# l+ J
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>: M( ?0 H& Y8 w4 W" r7 e3 z$ M
功 能: 画多边形
/ C, e1 S$ ^7 y& X! e用 法: void far drawpoly(int numpoints, int far *polypoints);
; M! s" b2 G) a1 k; x' A0 E* s程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
( n0 m" c; n4 i3 {) c, a. R#include <STDLIB.H>
% y& C% H) B! M4 z8 c) U#include <STDIO.H>
( v0 }5 }7 D: r5 a  [+ K" P7 Q#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
9 q/ r: k9 t6 t7 N. h{ ) ^/ W7 F7 Q6 w, K6 i
/* request auto detection */ 9 P1 G$ C2 [, |4 w* {3 W8 v- D
int gdriver = DETECT, gmode, errorcode; , _  k) E. L% ]- ^
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ $ g! r. c$ i! S3 Z) o- g/ F
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local 3 O* S7 t, `2 j5 `# E6 |5 b' {9 d
variables */ & p- h* \* a& [) M+ h4 a( b" b
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ % Z" |4 o, j, @  P* h  w, ?
errorcode = graphresult();
# Q. ?/ p# o: j4 Q( Dif (errorcode != grOk) 4 U+ ]5 D% I4 {
/* an error occurred */
8 ~) J1 ]% f( q) Z{
1 G: ~$ v) y- ?printf("Graphics error: %s\n", \ 3 a3 ?: C) l1 E( g% |
grapherrormsg(errorcode));
  Q6 N% W4 f! y( _" u+ P" ^printf("Press any key to halt:"); + c/ i* `% t6 C
getch(); $ X- ]  r6 y) |; C& ?3 C# w
/* terminate with an error code */ 2 |% s2 I5 C5 H) z7 x$ _
exit(1);
( d8 n+ E+ W1 F' o: J} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
5 {# U% s7 x: ]8 T% W9 Gmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
: J" W2 p- k7 \, I0 V# G5 X/ J- \poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
4 s: Z% I2 n; opoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
, w% h% D7 H! e! Y: o3 G$ Bpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
. E" `& O) z# y* w; p+ wpoly[7] = maxy / 2; 2 L7 c/ u  W4 X8 \
/*
# V; b. l, B+ Udrawpoly doesn't automatically close * ?- d. e& u( v4 g# b: l
the polygon, so we close it.
: O: k1 S+ z; d8 p5 ?) Z*/ $ ^0 F( Q6 W8 }4 j. b9 d# f
poly[8] = poly[0];
  G; n- w/ u0 ]1 }0 {/ W0 s0 n1 V  _poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ ! v# j  [( L% B! S2 |5 ]8 Q
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
' z: G8 M9 w; wgetch(); 0 b9 f! v4 K+ q  ?' s0 w! ?4 O
closegraph();
/ C+ Q/ P  i' Z0 ]9 I' }return 0;
# j0 H/ U- O) h$ g% ?7 J}
0 [' M$ g( K$ {6 ^# p) c: J</FONT>. p! t" P4 _7 ~. N! F; H9 h+ m
</P><P><FONT color=#ff0000>函数名: dup </FONT>" }$ m0 I( j$ l1 w$ E- ?* F$ J7 i  e
功 能: 复制一个文件句柄
0 Y, e. }$ A! R. @8 @: p) Z( z用 法: int dup(int handle); 3 t/ x$ S4 g* C' y: ~0 t  Z- b
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>' k4 j/ l7 p8 s9 Y
#include <STDIO.H>
  o2 z3 O+ V) |" ?- X9 E#include <CONIO.H>0 k0 m& j* i4 I7 }
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
" ~" x& K2 J9 R4 Q# B% W! C  t5 o- L{ 8 z8 E9 p$ g- d& l# A7 \9 h3 }
FILE *fp;
) o0 ~+ q' R0 H: H6 zchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 1 o% a, o# F, l! v, b1 l, ]
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
/ {; {# W5 t0 f4 }% Gfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
2 N2 W/ u3 V1 E" r" ]8 k5 @printf("Press any key to flush \
+ c6 b* V9 H7 y4 m4 a0 g7 cDUMMY.FIL:");
% a3 L+ `6 S& Ngetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without 6 _5 e5 U: u; j/ t6 {- U% W1 \' s
closing it */
- O% |) [  _! u6 L2 rflush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ $ n  r6 ^' j; n/ I
key to quit:"); ; q5 w) N: `4 F, r
getch(); , k( V% A, d/ r9 C4 ]! ?) b9 L
return 0;
4 d$ C: ]0 c+ J} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
) ?% A5 S2 F$ R) C{
: K2 Q+ X2 l. _% l5 b9 k+ T5 z( `int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ $ G3 m2 @. j. G4 d
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ 9 V! |2 f6 {* B6 r9 T5 l
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 7 P3 _# s' Y; T& |
DOS buffer */
8 \2 k( S5 A: r3 A- xclose(duphandle); ) x! V; y% w# w2 m4 S
}
/ y) h4 d! E1 d6 I: A$ R4 R# \2 ?- c' r" Y; Y9 |' W
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>% t; z+ q" B! v$ K7 ^- |
功 能: 复制文件句柄 $ o1 _- I% e. k$ F' u3 b
用 法: int dup2(int oldhandle, int newhandle);
5 l- I5 h' [, C. L- W程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
7 v: T0 c$ K4 b- Q1 V; B" G; x! F5 k#include <STRING.H>
0 N* y1 @) ^1 h2 R  o; N4 ~#include <FCNTL.H>
" E# d! ^' I. q3 c, G* N  ]#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) $ F% s0 }: g1 D4 O/ x0 M5 g
{
- ?4 S! K) I- ?* q# n#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; 2 Y$ H+ |* O( z* f
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
4 {4 l2 ]1 E) ~+ Z" `nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
# R5 q, j7 F$ |/ \7 x* yS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
1 M3 J* D% p0 m# U; s5 T! Q4 Moutput */ 0 B4 F' l  e1 ~% t7 e$ ^
oldstdout = dup(STDOUT); . b% D" |$ ~+ F; A( O
/* . W8 I/ H/ [9 T/ ?/ o; h
redirect standard output to DUMMY.FIL 4 l* Q1 W1 {/ r
by duplicating the file handle onto the & @6 T" p" s. s. O5 m
file handle for standard output. 8 h7 R3 m( |; u% `1 k8 n
*/
) F. X3 n6 S6 s7 @. mdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ - ]! Z; v4 T  }+ |; Z  B, j
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
/ ~" ^4 T4 B6 E* awrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
( F' U% K5 A. @/ v( Phandle */ 5 Z" @: R& k* J6 |) B% d! z
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
+ a# L" b1 \$ O) jclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; " B$ P: o6 a+ x
}
+ g1 {2 c; `7 a: k* g! K! O4 k1 @</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-24 15:18 , Processed in 1.653497 second(s), 58 queries .

回顶部