QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2074|回复: 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 ^$ p  Z* F' P# Q& g- j$ Y) q5 j: u</P>- t& d. J4 v( N
6 z2 W# Q+ X4 H

0 d7 x$ l+ O. M, [& S<><FONT color=#ff0000>函数名: ecvt </FONT>
0 E+ X8 t) T# H功 能: 把一个浮点数转换为字符串
- s! _% S% Q  Z7 }, j. K+ M7 A6 w用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); 5 V+ K# ]0 X  L* w
程序例: </P>1 C( X, N* Y9 t% Y" C
<><FONT color=#0000ff>#include <STDLIB.H>
6 T, k8 W8 `0 g: u" ?& M' {9 U#include <STDIO.H>
3 S/ o! S5 o8 \$ k/ O- w# ?8 A0 S% b#include <CONIO.H></FONT></P>
; d7 b8 g! L8 Z6 b! g- P4 D; T' j<><FONT color=#0000ff>int main(void) 2 ^4 Y, m" F- Z3 F. `- W( b2 r  e' l
{ ; E+ Y$ Q8 Y; P+ i
char *string;
& c+ S% N2 H! Ydouble value; + J4 T: W- f& g* ?
int dec, sign; : h; I; a1 ]! ^: E" u' w
int ndig = 10; </FONT></P>
* G  X/ U. @8 S% d; A<><FONT color=#0000ff>clrscr();
# z- J" o: c# e3 Yvalue = 9.876; ( T5 ~* S" l3 ~4 C9 c
string = ecvt(value, ndig, &amp;dec, &amp;sign); : U* V# u8 \; C5 }
printf("string = %s dec = %d \
1 n$ n, x1 s6 \+ H' T; i) [sign = %d\n", string, dec, sign); </FONT></P>
4 K5 C, o' D' a$ p4 D+ ?<><FONT color=#0000ff>value = -123.45;
; r6 c8 Q' v( R2 sndig= 15;
4 ~' b6 E5 _& g0 pstring = ecvt(value,ndig,&amp;dec,&amp;sign);
! x' L  j9 v3 d9 dprintf("string = %s dec = %d sign = %d\n",
) w7 k5 ^" ~2 m' W8 Wstring, dec, sign);
' y: q! c+ K0 ]6 G' d# a2 L) j</FONT></P>/ \& T1 \- K- n( q1 K
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
6 Q+ s2 W  F5 W; L5 }0 @" f2 O3 Lnotation */   a: L' Z& z5 h$ R& j8 D6 G
ndig = 5; ) k" [) T, D- [" J4 ?8 S2 d  C
string = ecvt(value,ndig,&amp;dec,&amp;sign);
+ J+ ?* c1 q3 ^, ?" j1 U" s# Iprintf("string = %s dec = %d\
' I/ l, J6 T* ?4 C$ _sign = %d\n", string, dec, sign); </FONT></P>  S1 }  l: m0 W
<><FONT color=#0000ff>return 0;
1 ?! @* g$ ?9 U/ G1 f. K} </FONT>6 N! s* V, W' z/ I
. g1 \) N1 }# b
</P>
& }1 C: r3 ?; p<><FONT color=#ff0000>函数名: ellipse </FONT>+ i+ c# w6 F* j, _6 `( R* c
功 能: 画一椭圆 3 e8 e# W, ?, w( V- m
用 法: void far ellipse(int x, int y, int stangle, int endangle,
5 e: ?7 e- c" C4 p8 Tint xradius, int yradius); 7 N; R" r2 ]: e. V$ y( H
程序例: </P>. o0 d6 I" _! ?
<><FONT color=#0000ff>#include <GRAPHICS.H>
' e! h% j0 O, _) X% y0 J# R! d#include <STDLIB.H>
1 l2 D3 R1 H9 L* x# c- w' |#include <STDIO.H>
' v# |; w6 E% f#include <CONIO.H></FONT></P>: X0 s; X/ V' y. j( a
<><FONT color=#0000ff>int main(void) ! G2 y8 T1 D. h. b. s9 M
{ 5 w+ G) h) {; F  j& N6 K9 M. j8 \
/* request auto detection */ $ ]( [/ O( n) D( o+ ?# Q
int gdriver = DETECT, gmode, errorcode;   z% N% w2 s% T9 p
int midx, midy;
, y3 [: m$ J$ {int stangle = 0, endangle = 360; 3 b' `0 G' v9 _' m2 y/ ?
int xradius = 100, yradius = 50; </FONT></P>4 U) Z# R3 {0 n8 h3 j
<><FONT color=#0000ff>/* initialize graphics, local variables */
0 ^' G% W; u8 t9 Minitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
$ i4 p; V$ a4 t' P1 E" x+ N<><FONT color=#0000ff>/* read result of initialization */ 2 T- u: _6 s$ V$ T4 x1 n
errorcode = graphresult(); ; x# Y9 s3 W% y: a
if (errorcode != grOk)
2 v# h# ~, J4 `1 J/* an error occurred */
2 k. ]+ J. E5 ?3 b/ M{
$ w, t4 R$ G$ ~. D7 j+ n( a! }! G- dprintf("Graphics error: %s\n", : H4 `/ n& e# \7 z( F
grapherrormsg(errorcode)); ( Z: M0 O  U* k2 H6 n/ b7 l
printf("ress any key to halt:"); : J) |; h' H  j' C- O! T
getch();
8 ?- \1 ?7 @1 H) X$ V' qexit(1);
3 K% S! n8 @8 j9 O, u' D/* terminate with an error code */ " p; Y+ z" [7 C+ w
} </FONT></P>8 _: U- d$ j( I, ]8 F) Z) ~
<><FONT color=#0000ff>midx = getmaxx() / 2; & c8 O0 p& u5 X5 o0 w# y
midy = getmaxy() / 2;
( ?1 C" E8 r1 Rsetcolor(getmaxcolor()); </FONT></P>9 _/ E5 ]: ?6 Q9 a
<><FONT color=#0000ff>/* draw ellipse */
, f, i" k7 o6 y" H+ ?' `$ @ellipse(midx, midy, stangle, endangle,
8 Z% t3 ^. v9 ~. H' X! [xradius, yradius); </FONT></P>
" j. b; l$ V* V; S<><FONT color=#0000ff>/* clean up */ 0 b) G4 k. h' e7 l7 u5 _, P& U, a
getch();
: E* A/ b: K& F: A  Xclosegraph(); ; T' [6 z  {# x$ h
return 0; 7 L. W. }: t# H- p& M8 v' |" y1 ]4 b$ i
} </FONT>
) \- M0 Q) p, J' U+ N: L- u
9 H  W& u% }3 d. L2 z</P>' i* L& S1 z2 v: g; I: L0 ~
<><FONT color=#ff0000>函数名: enable </FONT>
2 h& _& m9 B- t1 T8 [  ~# Z4 b; X( T功 能: 开放硬件中断 * l5 ~) F$ z4 @* x" W, X
用 法: void enable(void); 3 q* D; N$ I3 y, j4 ?
程序例: </P>
0 T) d9 U8 B" Y$ ?- c( j; r<><FONT color=#0000ff>/* ** NOTE: 8 E) W9 |* u* x
This is an interrupt service routine. You can NOT compile this program
) I! q: d0 Y+ X0 }" ?with Test Stack Overflow turned on and get an executable file which will
* {" k+ u0 i0 J4 L3 roperate correctly.
6 E2 I7 t% U1 R3 P2 W*/ </FONT></P>1 q$ j& `( t# v1 f5 o
<><FONT color=#0000ff>#include <STDIO.H>
8 I7 K6 C8 ~' `1 R2 A#include <DOS.H>
" I& {; M: f& a8 {" @#include <CONIO.H></FONT></P>( j, y+ r2 o4 u, K4 v/ J
<><FONT color=#0000ff>/* The clock tick interrupt */ . o8 E3 v7 G: s' s: c5 W; X( x
#define INTR 0X1C </FONT></P>, e2 ~4 r% O! E+ g3 Q6 `: _
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>1 d6 f' s# r; q: a2 I% E
<><FONT color=#0000ff>int count=0; </FONT></P>% k5 X$ A, k6 b$ A
<><FONT color=#0000ff>void interrupt handler(void) ) l' Z  W! `8 d  D$ Z
{ ) n1 c" z! `) O
/*
, }  f, y5 q; y: ]/ M( Sdisable interrupts during the handling of the interrupt
  n. m. g5 v1 }! N7 Z*/ * F# M' E/ F* m' I; F
disable();
4 ~* V' J9 t8 {" A  u4 ~; v  l/* increase the global counter */ $ O# x  n" l6 U  e: C) }3 ~
count++; ! s$ V6 B8 e( Y, G
/*
$ ?/ e6 }' F3 D+ M3 v( \2 d& H! b3 Lre enable interrupts at the end of the handler
& h2 Z5 y$ K: a4 q$ a*/ ) m0 ?* J& z, H5 A8 m) F, D
enable(); ; d1 q# _5 L  B8 L5 {0 e+ ~7 d/ b
/* call the old routine */
8 ^# {8 I( E; w5 Zoldhandler();
  H1 L! e$ `2 L9 P" Z. _} </FONT></P>' q, R( }8 {3 F+ ^0 k) r4 [
<><FONT color=#0000ff>int main(void)
8 s" ]. Z' P4 Q, f1 a  l* }' T# u{
( l/ J# Y7 ]2 b" }/* save the old interrupt vector */
* t% |9 I. u* ]8 U1 qoldhandler = getvect(INTR); </FONT></P>* p/ w* q5 b5 I& t# g2 A) X  r
<><FONT color=#0000ff>/* install the new interrupt handler */ ( a5 f1 A$ X2 ?
setvect(INTR, handler); </FONT></P>3 ?) e5 ^( z( S4 ?  u5 e
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ , d9 O' S3 E, H/ _6 P  I. T
while (count &lt; 20) ! n5 Z! ?9 ~7 p0 p
printf("count is %d\n",count); </FONT></P>. |, {6 S" }; Z2 _  V; L) s
<><FONT color=#0000ff>/* reset the old interrupt handler */
: f) _% D# J0 F3 ~* l' M4 ^setvect(INTR, oldhandler); </FONT></P>0 H  t* F! M) Z9 M
<><FONT color=#0000ff>return 0;
) j4 ^. W" z' ^4 k) U} </FONT>: V( V& r' c' y6 Y

, k' j4 L' C; f( I% S- W) U</P>
& G- S" M9 p# S7 ?<><FONT color=#ff0000>函数名: eof </FONT>5 k& Q$ f& R7 t) ]5 l, P- I% F
功 能: 检测文件结束 $ H/ ~& Q$ n3 T8 o
用 法: int eof(int *handle); 7 J% W! J. f1 }- y9 X. v6 G
程序例: </P>$ Z/ l' v; J+ C0 ^5 w
<P><FONT color=#0000ff>#include <SYS\STAT.H>  K: r5 d* d1 ~6 Y; L* R- \
#include <STRING.H>% x, R$ d" G  A# O) L2 _
#include <STDIO.H>
5 z9 P- P: n- ^0 {#include <FCNTL.H>
8 k( i, Y- x8 a& y; s#include <IO.H></FONT></P>6 w; g  @; c) j$ Y+ m' {, s/ K
<P><FONT color=#0000ff>int main(void) ; w, q+ v  |/ h4 J& ^$ a' `
{ ) O( N8 Z, X7 M6 i. `
int handle; ( U/ ^, a1 @; n9 a
char msg[] = "This is a test"; 5 x% D9 f; z$ @# C* F( W
char ch; </FONT></P>* B3 M4 c. P$ q8 o, t# B* F
<P><FONT color=#0000ff>/* create a file */ 0 _/ B- `$ t1 n2 G, ^
handle = open("DUMMY.FIL",
1 T* m; A$ Q: DO_CREAT | O_RDWR,
8 c  p2 j+ \+ ~7 l& pS_IREAD | S_IWRITE); </FONT></P>
1 v- w% u, m. G, s" p0 Q<P><FONT color=#0000ff>/* write some data to the file */ 3 j& @- o8 A3 P& q
write(handle, msg, strlen(msg)); </FONT></P>
0 q" m5 U. k5 n/ N( ~4 Y- e<P><FONT color=#0000ff>/* seek to the beginning of the file */ ! H& d# P* ^9 V- c1 ~$ z' u
lseek(handle, 0L, SEEK_SET); </FONT></P>% V( k, S$ }1 \4 ]& l
<P><FONT color=#0000ff>/* 8 o( ?9 n3 x; F' I2 q  N. j
reads chars from the file until hit EOF ) |" L  F$ z! h" _* y
*/ * f% s2 I9 u  y4 {6 L" R- r" z
do 0 k# `6 P1 ]" w# h. Q
{
/ k) P& X* z% J* vread(handle, &amp;ch, 1); : ~: [# ?6 r' |
printf("%c", ch);
/ {7 y. u# w" b* _  e5 y9 M0 M/ i} while (!eof(handle)); </FONT></P>
6 {) o3 n* U7 ^7 M: ^0 X<P><FONT color=#0000ff>close(handle);
. R) X3 W4 X/ f# Q6 B# Freturn 0;
8 }8 i7 y6 y5 {  E}
0 n: q8 ?& O  y+ d</FONT>  n4 L9 Y2 ]" q
</P>
: m; ]$ v/ }+ A. |4 P<P><FONT color=#ff0000>函数名: exec... </FONT>7 I( B( m8 |3 L+ m, o: o
功 能: 装入并运行其它程序的函数
: a5 C( ?6 X* y4 p. G用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); 5 i4 l  U7 o1 i
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, + P3 Z4 i) a5 c) c: D
char *envp[]); + z, W  V1 n% c7 g% L: [1 y4 c
int execlp(char *pathname, char *arg0, arg1, .., NULL);
" [: d. J. A+ i* v. xint execple(char *pathname, char *arg0, arg1, ..., NULL,
# `- Q5 l; M; n; K/ y' l8 ~char *envp[]);   D7 U) j! V* x& F6 \' q8 S
int execv(char *pathname, char *argv[]); 5 J4 g+ P+ L3 |* I* A/ G
int execve(char *pathname, char *argv[], char *envp[]); + i! S0 f( d- G+ y2 p* ?; A' l
int execvp(char *pathname, char *argv[]);
, y- G7 ]( y, ~: ^int execvpe(char *pathname, char *argv[], char *envp[]);
4 M. P5 C+ o; i: l2 a4 n. }程序例: </P>
# O' p6 |' B4 m! g% a. h) X<P><FONT color=#0000ff>/* execv example */ # ^4 \& V3 [; F3 i# j- d5 x
#include <PROCESS.H>, e" B- ?9 }. V- s
#include <STDIO.H>. F. K- y$ z" L2 l( G& y
#include <ERRNO.H></FONT></P>
) Z0 d" m0 J8 f<P><FONT color=#0000ff>void main(int argc, char *argv[]) 9 y. U0 L8 b0 `  t6 V$ `* \$ G6 f
{
8 I/ [  C, i( T7 \+ _int i; </FONT></P>* f( j# u' i" g( R& L7 @8 X
<P><FONT color=#0000ff>printf("Command line arguments:\n");
0 S- o* ^0 l5 t) o. K, Q) s2 Zfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
/ R; z  w0 a9 k1 V<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); + n+ O1 U( ]" k" {! W& ]: k
execv("CHILD.EXE", argv); </FONT></P>
" A/ M7 Z/ _8 c6 V7 w<P><FONT color=#0000ff>perror("exec error"); </FONT></P>! A1 T1 K; v7 N' T4 ~
<P><FONT color=#0000ff>exit(1); , S; v& ]/ t: L; o
} " ]6 Q; ^% w9 U" ?
</FONT>
1 j3 X- z8 F! L* U. e</P>
7 O7 r; m0 N7 w' @5 C<P><FONT color=#ff0000>函数名: exit </FONT>
+ U# ~& T( x2 J) P) N9 D. z) X功 能: 终止程序 # \, G2 W3 p0 ]7 s! a4 i
用 法: void exit(int status); - _5 @$ K: J& {/ v& [' y
程序例: </P>
' h9 D. F( l4 a7 \- R<P><FONT color=#0000ff>#include <STDLIB.H>
# M3 ]$ F( b, D#include <CONIO.H>
* c8 ^' w! _2 J# i#include <STDIO.H></FONT></P>  |0 G+ ^9 n8 `  d
<P><FONT color=#0000ff>int main(void)
1 [9 V* V- d3 P0 v) ^{ ! u# V1 E! A/ Q, N2 ^* S: s& ?
int status; </FONT></P>
) L! X3 V) ]" y4 n) t<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
; j4 L2 r/ \, Y6 l) j1 l3 jstatus = getch(); 5 F8 v/ G/ k" j$ T" j
/* Sets DOS errorlevel */
- u& Z% P, N+ p( j- }0 @exit(status - '0'); </FONT></P>
0 r) P, r- d( m$ ?& O" S<P><FONT color=#0000ff>/* Note: this line is never reached */
, ?) O' D: a. j! Vreturn 0;
" @$ U2 ?  t6 D* G8 }; y}
2 m. m1 P4 R9 y" ]</FONT>* F) w! L& U9 Q3 G4 O
</P>
2 k7 {" |- I# @8 g<P><FONT color=#ff0000>函数名: exp </FONT>, V+ x, f8 l, R8 \
功 能: 指数函数
# i% _& G4 D3 V, ]# R) C2 f  R用 法: double exp(double x);
* y+ W8 \/ f. m程序例: </P>
6 c  |+ v* I0 v7 a6 M4 }- F) t) U4 l<P><FONT color=#0000ff>#include <STDIO.H>
1 c, r" b, m, i( n4 \; R) @! f9 p#include <MATH.H></FONT></P>2 X1 i8 n" i2 R# i6 q: M; d* ?
<P><FONT color=#0000ff>int main(void) ) x& @; `: ~6 y. G6 w) Y
{ ' @  V! I0 G8 |0 ]1 ?; I" K
double result; 6 @" `% E* Y0 `2 T, g
double x = 4.0; </FONT></P>; D0 s8 N6 I/ p* D2 y
<P><FONT color=#0000ff>result = exp(x); ! F: ~6 |6 |: O' {& h1 _
printf("'e' raised to the power \
& u. b+ h$ ~+ Rof %lf (e ^ %lf) = %lf\n", , @0 U( h& f2 P2 P6 P) d
x, x, result); </FONT></P>2 z0 G6 [' G) e
<P><FONT color=#0000ff>return 0; * f' g$ R+ `0 ]) G' v& n
}
7 x$ K" |' s! o</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>
, e  O, j- E7 o# C+ g</P>1 e& _6 j8 G. H! F2 ^
<p><><FONT color=#ff0000>函数名: delay </FONT>
1 Y0 C, |- {$ ]+ d功 能: 将程序的执行暂停一段时间(毫秒)
! x0 h* i( p- R: C4 a1 {) C用 法: void delay(unsigned milliseconds); 7 i. t" d, [4 o; ~
程序例: ; ^) A# w8 i- [9 s- Z% d$ ]
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
* @8 {6 i5 F' ~& L. ]#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
6 q8 ?6 k( k, x/ _% ?$ V7 J$ l{
" O" N& i, x4 u/ ~9 S1 K3 k9 W. fsound(440); 3 ^4 b% h: o  ~) ^; }4 j
delay(500); 8 o6 d8 |' w/ F3 B
nosound(); </FONT></P><><FONT color=#0000ff>return 0; . J  z  ?: }8 _4 J( Y
}
8 }0 j9 H* p$ d% t6 l5 g+ h; j% I! G. o0 q! z/ D& o; K
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>0 X4 a3 f5 S' G" K/ f
功 能: 在文本窗口中删去一行 1 O3 U) [% ?, z  j; e1 ]. _9 i! F. u6 a
用 法: void delline(void);
/ S1 w; D( F8 a3 P; a5 Y程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) - n4 n- A5 [. z: A0 j- ~  B2 Y* q
{
, M4 [$ d/ z, Q" h( c+ p2 g9 jclrscr(); ) V7 }/ f2 b$ R& J
cprintf("The function DELLINE deletes \
) L, _; h8 |& \7 [$ Z  e' N: w- gthe line containing the\r\n"); 7 A6 S1 u) z! B1 T6 O6 p
cprintf("cursor and moves all lines \
7 k, W) [& S: ^  cbelow it one line up.\r\n");
  {0 ^7 _$ N' `3 p) C$ i7 P9 Fcprintf("DELLINE operates within the \ , z8 l6 p4 v2 e( M
currently active text\r\n"); 4 r, ^4 B" v# |; J% g0 ^
cprintf("window. Press any key to \ & `6 \0 l+ u, Z' q! {1 I6 Y, y/ M/ P
continue . . ."); # X$ D6 p/ G6 G
gotoxy(1,2); /* Move the cursor to the
3 z- B' i) P+ u/ p# x6 {second line and first column */ + s! D, o- ?2 A% P
getch(); </FONT></P><><FONT color=#0000ff>delline();
) C7 A4 y- s+ ~# ~getch(); </FONT></P><><FONT color=#0000ff>return 0;
2 c  a7 G% W2 O% [$ J} </FONT>
2 q. x$ l$ _" p' E. E- C</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
5 e1 v8 B! y; D& \+ x( ?  \, x1 |功 能: 通过检测硬件确定图形驱动程序和模式
3 ?' |, Q( I  x& z) l- L4 F; _/ L用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
9 T0 a2 S6 B* ]4 P6 ^程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
% D+ R* L7 }% [) @1 l8 N4 ?: a#include <STDLIB.H>$ v- p- S4 B9 \$ U  m
#include <STDIO.H>
/ f" h/ T; [8 R; k, L#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
  G- P4 k% y+ R: xchar *dname[] = { "requests detection",
: `: U" Q- n  C9 e$ ["a CGA", ' h: H1 h( L) j- c
"an MCGA", 8 K0 F$ W+ k/ Y8 G9 k
"an EGA",
/ d! x+ {1 r; g  z% p9 ~: |7 f"a 64K EGA",
1 e3 C* U: u; P) J; w$ ?7 M* F, b"a monochrome EGA", * i9 B5 W( C8 R. F* G
"an IBM 8514",
" o% m& Z: H1 D2 G9 N"a Hercules monochrome", 4 n- G2 `& [* a+ j. j
"an AT&amp;T 6300 PC",
7 n4 h7 y9 Z/ [) I"a VGA",
; T3 l, m1 y; A9 z"an IBM 3270 PC" 4 X0 q5 F! G$ i- I
}; </FONT></P><><FONT color=#0000ff>int main(void) 3 N! ]+ m' R5 _9 G6 s
{
2 `! G) g% s5 I: }+ r* O# S/* returns detected hardware info. */
. c) g" b; G: H; p, Jint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ 8 W- i; v# `3 m4 ]/ E
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
. l7 f6 h8 Q- Z1 [$ Zerrorcode = graphresult(); 9 p$ @1 M2 \4 T1 _
if (errorcode != grOk) /* an error
) T4 E& e& I* q  ]2 moccurred */ 3 k' f( H; h  Z4 `
{ - j+ I' J  Y- B8 h: I& I& R
printf("Graphics error: %s\n", \
* q* W7 v+ E8 U3 T& L$ T2 z* ^grapherrormsg(errorcode));
! ~3 `& h6 b0 Q, v# U3 xprintf("ress any key to halt:"); % E2 M0 Y2 `6 Y' ^0 G
getch(); ) @! j2 b7 Q# y( V
exit(1); /* terminate with an error
" g7 B; u5 z. w3 B1 mcode */
4 T* f" M# |- _, M} </FONT></P><><FONT color=#0000ff>/* display the information detected */ ' I5 o* f& N8 N4 y4 t0 N1 w
clrscr(); % `  \: ]1 F* A3 v
printf("You have %s video display \ * \' G$ y; \) ~# S' n' f
card.\n", dname[gdriver]);
7 \/ Q4 C) e( h* g9 w7 pprintf("ress any key to halt:");
6 ^9 R; x! J! C/ Ggetch(); 0 j4 J: o, M* w  }+ Z. p$ c
return 0; - F# `7 C' p* \
} </FONT>
) J- r8 H: F1 N
' u  a! D, F: @" Z* c# C
! w) {( C! V( F8 B5 ?2 ?</P><><FONT color=#ff0000>函数名: difftime </FONT>
+ j' G( @& s& k2 F/ t7 U5 s+ o$ P功 能: 计算两个时刻之间的时间差 # E3 f$ ^1 v4 N9 u/ a7 d
用 法: double difftime(time_t time2, time_t time1); 5 S- Y% U( X, k8 |5 h% f2 V2 [
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
# y& x6 ~/ M9 B/ }#include <STDIO.H>
9 O8 X' S/ r0 @5 L0 Y+ c5 |#include <DOS.H>
! @; H" b3 F' N7 D4 p( q+ {#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
6 C$ W( i1 h$ Z( W# t{ $ C" Q, Q: G3 e0 d+ W
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); 5 M6 |) F* B' Y7 Z* y- e
first = time(NULL); /* Gets system * y! _3 x* d8 o  H& c
time */
8 n0 K. P1 B0 d+ Gdelay(2000); /* Waits 2 secs */
. g. j+ w2 h6 A4 _second = time(NULL); /* Gets system time 3 H8 [. G  [1 C5 d# a& X) B
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
% M4 y; `4 L0 o+ d6 u7 Pseconds\n",difftime(second,first)); ! q" g0 j/ U8 G) ~9 b
getch(); </FONT></P><><FONT color=#0000ff>return 0; & E! b! o- _  {! H% _
}
* _) `. P7 B$ c/ X7 M- N7 n</FONT>
. T/ }2 {8 h. g; a</P><><FONT color=#ff0000>函数名: disable </FONT>- ?1 [- l* D! x8 n5 y
功 能: 屏蔽中断
$ x6 p4 A% Y) b4 o( M( e% l( K用 法: void disable(void); , ?+ v7 \0 o5 O
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
& i. K' D2 O  k! B) \) o; ~' Qroutine. You cannot compile this program 2 D! m# H: ], Q/ f# w9 \& s% Z
with Test Stack Overflow turned on and + P; L  `( l* Y( u, }
get an executable file that operates , S& ~8 M- |* Y9 Z* \3 N8 @
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>. z$ G, c2 d: v
#include <DOS.H>
# u+ g( q6 F6 X: D  p( y& A#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick 5 ~% x. _; @+ q4 l) u; _7 ^" i
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)
! J% y. C/ Y6 Q* c; H/ G{
9 v2 ]- }" _- O7 i: W* c/* disable interrupts during the handling of 2 k6 y, |) U4 }( \. F
the interrupt */
. o# Y+ u3 [6 _; {disable();
0 L$ T1 S, @7 Z4 \. O7 [/* increase the global counter */ 6 J9 n) l! @( B8 _  E. \
count++;
, i( w5 ?' |% Z6 h/* reenable interrupts at the end of the
3 t$ {& e4 `" _5 i9 p* P5 ghandler */ % T% m0 v, t8 X+ `, o0 s# b' l
enable(); : p  S, u" y0 \0 N7 `  s$ n
/* call the old routine */
6 t2 T, f3 Y# e6 toldhandler();
- \0 u8 s4 B( }/ `} </FONT></P><P><FONT color=#0000ff>int main(void) , S5 |8 @  {4 I
{ ' n* l: I/ Y% y% _
/* save the old interrupt vector */ ) I- \' G3 f1 s
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
0 Q0 R' ^# T8 G! Psetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 4 w8 }( S- e# I3 t
while (count &lt; 20) 4 V1 Y2 ?- x- t& [9 O! `) m
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ + B" B6 x, [3 P
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; ) u- _( e# M. v" |
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>0 A  `4 E8 Y8 `# k
功 能: 将两个整数相除, 返回商和余数 ! k' Y: v* h3 u! \
用 法: div_t (int number, int denom);
  M& Z3 {) r! x程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>0 m1 j- e& k9 o, L' K8 t
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 0 n) O# p  _8 J
{
1 l" c, i) c+ Px = div(10,3);
. e2 _$ M( K* d3 Yprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
) }4 H/ E1 q+ `  F) w) v" u} 3 ?5 W2 f0 o+ x% o7 w: o8 ]
</FONT>" |0 p& d( [8 Z' A/ |) h
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
$ |. P1 f, w0 U& P9 Q* L功 能: 获取扩展DOS错误信息
% d, j  c0 e$ E3 _用 法: int dosexterr(struct DOSERR *dblkp);
, G, I, I# \4 _/ p  N程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
) m$ E4 I* L9 [$ g$ j' B: Z#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) 5 J" x" x6 Y! {' ^0 O
{ ; r$ V) K6 y' q8 y- M/ g
FILE *fp; % G& D4 s1 V2 o: [, x! a4 n
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); + H) W$ o) ~8 f: z: l9 ^9 o" |
if (!fp) perror("Unable to open file for 8 d3 a- c2 [" D5 Y1 O% t
reading");
! n8 A2 l. G) x! U' a/ Zdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
" |1 q" w3 U6 y+ S% p5 {6 rinformation:\n");
1 D& _/ p/ c$ F; hprintf(" Extended error: \ ; [( X1 ^! u: h1 d. M/ u( }! g
%d\n",info.exterror); 6 z4 [6 D# f0 j0 m8 n
printf(" Class: \
1 p1 n% f4 b0 N7 W( ^2 O, W6 ?%x\n",info.class); 0 Q' [4 x8 i1 Q1 f8 U4 g
printf(" Action: \ 9 P1 Q/ r4 \: q0 G$ w$ c) s
%x\n",info.action); 7 e! \* |$ p# m3 w0 ~
printf(" Error Locus: \ : S3 W* p. b' t5 t& x0 Q
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;   M4 G6 l+ o8 Y( L4 N1 L
} </FONT>! R- k' z' k, i3 f6 A* S
6 \: z; h% b: f
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
; C& ^6 m1 c9 [+ V' Z$ g$ e" B功 能: 转换日期和时间为UNIX时间格式 8 i7 F; s0 ^+ ^
用 法: long dostounix(struct date *dateptr, struct time *timeptr); - _: V) J8 O* p! z: Q( S/ _' k
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
5 T& }0 V& M3 `# l* u#include <STDDEF.H>- Z" Q3 D5 b7 t7 V  y
#include <DOS.H>
6 [9 f, D. G) ?, |. d$ X8 [#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
* k! D* v" S: f0 p5 F{
) T% n3 f  ?+ {, ^. `time_t t; # g" J( e; M8 K) C
struct time d_time;
% `, g% H, S/ I! z- {struct date d_date; 4 |- E* L8 p2 [7 [  m$ U
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); ( }' w7 Z; @# w* \1 R& d
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); & Y: {* u7 {) O4 c: o- p0 ~+ r
local = localtime(&amp;t); , d& m6 Y, }7 y: A$ ~) e# M
printf("Time and Date: %s\n", \
+ z4 i3 O0 C& @; \2 Q, |( zasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
+ y" l9 u" u5 E& V( A, n0 I8 C} </FONT>
& D& ^$ {2 y( B. e! D, l
& Q& q2 S) n8 Y! E</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
# Q- [. X! g. v5 u7 u6 p: @* f功 能: 画多边形
  o* i5 v" t5 M3 h/ @6 N用 法: void far drawpoly(int numpoints, int far *polypoints);
* e/ m* j. `# O1 `程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
  E5 S' Y5 Z( z4 ^#include <STDLIB.H>: c  ]+ W1 E+ I5 P7 x$ ^
#include <STDIO.H>8 B- h( \/ z* {. Q6 e9 c( d8 k8 J, [
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) 3 q4 D2 ^7 j4 N' s3 P! h$ ?
{
6 t; P5 L6 H4 J4 f5 |# d' A/* request auto detection */ ; |) d) C# ?. W) |
int gdriver = DETECT, gmode, errorcode; % \) y( x( _& Z+ o& D6 b6 J# {
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ 9 r& D2 ]* E; \6 }8 K! h) O. Q+ P
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local * }6 [0 F( K+ g" [2 d0 T& K
variables */
; W; `; f2 s3 v% ?" k0 |) J8 Xinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ / M6 U  Y7 l5 a
errorcode = graphresult(); # b4 C1 b2 z6 N( g' v
if (errorcode != grOk)
5 F9 T" Z# b- u/* an error occurred */ . x" a" H+ G9 {8 k  G9 ?
{
4 \' r, `9 e6 S8 t5 w. Xprintf("Graphics error: %s\n", \ 4 p8 R' }) y; Z2 i
grapherrormsg(errorcode)); 0 t$ v# I) c4 [& W' C
printf("Press any key to halt:");
# B. y2 v9 Q, Y6 }getch();
/ j) e6 S0 d3 {- e* o- Y0 d/* terminate with an error code */ ) M8 x# J: B4 P# |  M9 t
exit(1);
2 V* O& D' e. N0 H  Q3 q  x+ L} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); / E1 K: k7 Z. |  c& U9 P7 X- t
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ $ q- k% y6 W  }# d9 O
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
% P+ M5 S! Z% }5 l# H: r% ?! d, \poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
! D0 z7 @( @4 Vpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
$ v0 H& p  S( \0 Z: rpoly[7] = maxy / 2; 3 U! N9 ~! \1 e1 |/ w% v3 O
/* & }1 z5 Z$ k# d1 m8 K' l  K1 {! Y
drawpoly doesn't automatically close 5 S- G* C) ~7 a4 `4 x6 Y  I! y
the polygon, so we close it.
8 [, x1 ]3 v( y' E7 U6 `*/ 9 q) h  ?% D4 c5 l$ q
poly[8] = poly[0]; 9 A" Q" @7 ], u4 I# T
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ 2 j* e3 |$ v* w' P& Q; I$ S! A
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ # w. L2 M7 |* P4 |& X# r
getch();
0 a. q: ?& J! f. x' j+ Tclosegraph();
5 p+ w8 Q; y: l' E" dreturn 0;
+ G3 [0 N' R4 ~9 k1 z( C}
; c' O8 }  }, K* N' E2 d! a/ X</FONT>* Q, i# w5 U# K3 _: e
</P><P><FONT color=#ff0000>函数名: dup </FONT>2 q) A3 |0 k& W/ C
功 能: 复制一个文件句柄
- |, ^% R3 w) @! @' `( Z用 法: int dup(int handle); 7 c+ I& u/ z- ^9 F
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
( T1 @$ Q  X# U, v6 d3 f#include <STDIO.H>
) Y# t% `! j$ N0 E1 b/ T#include <CONIO.H>. y' V. f! m3 w! P* S/ L' {
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) ( B3 [7 z4 a& i5 b7 N+ t5 Y7 n
{
$ P& \4 s6 |& B& E# Y- \+ PFILE *fp;
2 P5 d, }' O% C, m1 s6 V) Cchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ : j& @0 }, g( `. H* t( s1 q" ?
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ - u: j6 w* G/ r9 V/ @
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 5 D6 s0 ~* c% G7 ^
printf("Press any key to flush \ # L6 w  x" p8 v1 z
DUMMY.FIL:");
4 N0 D$ d: t) i% A; w/ sgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without " N, B- e4 s: f( i( g; {
closing it */ / P0 m. f) n4 l0 W7 o. P% Y$ Q* ~
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ . b! O  J! R5 ?3 ^3 k4 s1 c6 \
key to quit:");
1 n/ q5 s# L* R3 f# a" xgetch(); : Z6 H+ r+ B6 M+ X* }
return 0; " c. L/ `  i/ m3 d3 i; G
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
# a9 r6 Z; L* m2 r5 n9 h$ `8 Y2 S{ # d+ c7 G: l  f) S9 a
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ 1 ^& ?7 K( W- U+ g$ v2 C! a9 h
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ " `$ ~8 [' E& a' X$ q9 b9 Y; J
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 7 Q* l/ m  U) d3 G% g( a
DOS buffer */
5 i. i- z3 I1 l1 ^3 }5 E$ Eclose(duphandle); # l' m# ^' q3 h# l" l5 S. Q8 r1 D3 Y
} ; Z& D. W& ~% b

8 K+ w- j- }, N; \3 y) C3 U5 m" H$ K</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>9 W+ k1 O# F/ \; J1 R- j6 Q
功 能: 复制文件句柄
& p$ W) S$ R+ B. V用 法: int dup2(int oldhandle, int newhandle);
  f; f6 E! o# F* R% Z程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>% Y! G/ [3 Y0 v5 g+ j& N$ d
#include <STRING.H>
8 \# ?% G# K) L$ V5 i#include <FCNTL.H>) b9 ]) B! ^$ C. g/ Y: h9 N* Z
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
: m8 ^/ z1 R- O{ + y/ S# F, L7 P! O8 o  v7 s' k
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; 7 F4 @# P5 o+ [; V* \
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
  ?! V3 ^4 s2 knul = open("DUMMY.FIL", O_CREAT | O_RDWR, 0 @" z1 ]6 a) R1 w$ ^4 o
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard $ q( c4 w0 i' X2 b+ G
output */
: R% J6 o' F8 ^+ ]' L0 k0 K) h9 eoldstdout = dup(STDOUT); ) o+ H& {% \+ B- b% i2 L
/* & I6 F7 `: ^1 i1 A
redirect standard output to DUMMY.FIL
# i& G8 K; H7 Lby duplicating the file handle onto the
2 _6 c6 v9 H5 G/ j- a. ^file handle for standard output. / K" J6 O& u6 c8 f+ B' g( W! o
*/
8 N9 P/ |+ ]0 n7 V; Y. z/ wdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
5 p# K* _7 ]  k7 Nclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
2 F, H5 l( v3 `7 @9 twrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output " V# I" C/ R: q; D1 k% r" r2 d+ _
handle */
( p  P  S  g. h3 s" V& h' Ndup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ 5 G& j9 o( z/ y: W
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 3 D  i/ y  A, x7 |
}
. D: |  {  Y; N+ N; d</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 11:48 , Processed in 0.449475 second(s), 57 queries .

回顶部