QQ登录

只需要一步,快速开始

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

函数大全(e开头)

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

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

跳转到指定楼层
1#
发表于 2004-10-4 03:01 |只看该作者 |倒序浏览
|招呼Ta 关注Ta
< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(e开头)</FONT></B></FONT>9 H$ N- X/ x7 m* Q1 h! J. s
</P>
3 j1 H0 B: f2 E! L! ^  [* @% Y9 h/ D$ r% }3 t9 t# Y3 M
/ B* S& O! t% l6 m7 C, [1 y6 V
<><FONT color=#ff0000>函数名: ecvt </FONT>
0 w6 G2 `7 U) x, q' S; v功 能: 把一个浮点数转换为字符串 4 i7 `+ @8 Z9 d( k6 X
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
2 Y8 P* ~$ l; C2 A5 `6 L程序例: </P>2 |2 M* L+ S" m9 d( H; |
<><FONT color=#0000ff>#include <STDLIB.H>2 `* p# ^# D  d  w  I
#include <STDIO.H>9 |+ e. c1 s; N7 M# t
#include <CONIO.H></FONT></P>9 A6 U# `1 S6 m4 T2 @4 i
<><FONT color=#0000ff>int main(void) - q& s, d+ t* G8 r4 l; P1 M
{ 9 a2 u: ^8 I( ], s( B
char *string;
$ i" X; S5 r" Edouble value; ( \- t( }8 H" G- W( w" l9 Z9 z
int dec, sign; 0 @) @1 ^6 @3 s  X% a3 S1 u7 _
int ndig = 10; </FONT></P>2 L! k- o; f+ }+ ]8 B0 d
<><FONT color=#0000ff>clrscr();   R5 w  b; |: K! Y! x
value = 9.876; $ w' i6 r4 d3 L* A
string = ecvt(value, ndig, &amp;dec, &amp;sign); 1 w9 F0 L: h* Z5 t9 h
printf("string = %s dec = %d \ 3 d6 i3 |9 j# r$ v' S7 E& B- L& U
sign = %d\n", string, dec, sign); </FONT></P>
0 ^# A# Z. ^5 U/ v0 y<><FONT color=#0000ff>value = -123.45;
! }9 u" Z! v/ S- q9 L8 c, k) Vndig= 15; 9 Z8 t4 R# C) m1 B2 p# G2 ~* i
string = ecvt(value,ndig,&amp;dec,&amp;sign); # c4 n2 ?* Z+ b3 T. k; ]1 h
printf("string = %s dec = %d sign = %d\n", 5 }* \" g* u. r6 {1 {  l4 I
string, dec, sign); ; m( q/ r5 L& D* e- e, |9 Z
</FONT></P>+ k* N7 Y6 u8 N* ]( f. ~- M% q
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
+ S% i$ V* L1 W: g& b1 Dnotation */
% w& Y+ c3 t. m6 m) a- \* I6 Y; F7 Vndig = 5; + i# @  A3 e$ _  w: d1 D
string = ecvt(value,ndig,&amp;dec,&amp;sign);
% T1 x0 w( ]3 t( p: Mprintf("string = %s dec = %d\
& k! v+ n; E6 |# j2 Z1 s+ qsign = %d\n", string, dec, sign); </FONT></P>
, A# u- g! o; v+ q; {<><FONT color=#0000ff>return 0; + @: F9 x/ X( f6 M+ }
} </FONT>
/ B5 l* q% S0 Z% Q; u( I
$ L: ~+ f  S6 h0 ^2 R</P>+ f8 K4 z7 u; F: d  `$ \
<><FONT color=#ff0000>函数名: ellipse </FONT>& y. w$ H, V, ^. d8 ^  o2 u- ?
功 能: 画一椭圆
; Q; \! P9 e' ^3 d用 法: void far ellipse(int x, int y, int stangle, int endangle,
9 v( P( m6 S: @int xradius, int yradius);
2 w% K! c: J1 c9 M程序例: </P>5 o( C3 s( g. M6 m# P
<><FONT color=#0000ff>#include <GRAPHICS.H>
5 U/ p$ |8 A% S: J#include <STDLIB.H>( P4 h+ A# }6 t1 N
#include <STDIO.H>
0 d. o1 r( o( m% G# q! f#include <CONIO.H></FONT></P>$ K5 F& L5 m3 G
<><FONT color=#0000ff>int main(void)
8 b# C+ s" z' {{
/ K, B1 t; x1 h2 q/* request auto detection */ 2 `3 X+ _" S. h7 f, b$ i
int gdriver = DETECT, gmode, errorcode; 3 z2 `5 G! M/ o
int midx, midy;
9 o8 O6 D! Q+ l( U4 Fint stangle = 0, endangle = 360; ! d+ y1 s5 w+ S3 q7 B- A
int xradius = 100, yradius = 50; </FONT></P>* ~: q& b2 y! N6 l3 ^. V
<><FONT color=#0000ff>/* initialize graphics, local variables */
8 ]5 r, b1 k& qinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
) _, c6 ^# P1 x' J<><FONT color=#0000ff>/* read result of initialization */ : H5 f' D; }" Z3 w% T8 Z
errorcode = graphresult(); - z* [& B1 h' w- L
if (errorcode != grOk)
( t5 x$ r4 U, ^# u" \/* an error occurred */
' s9 ?& q  X' Q" x{ / i1 i; u% s/ R; q0 f; }) J
printf("Graphics error: %s\n", $ t4 O4 s! H: r3 Y9 G
grapherrormsg(errorcode));
/ P4 F3 C/ X( F$ C7 ]printf("ress any key to halt:");
& Q+ n' y" _4 l+ v6 Z9 R  K& C% Cgetch(); . e4 S; u7 g' t; C
exit(1);
, q6 t" b7 j0 `  A- U. e' A/* terminate with an error code */ 4 v7 P  V) y2 P4 E* N* h9 U1 o5 }  I
} </FONT></P>- |0 ]% E9 _7 }2 F
<><FONT color=#0000ff>midx = getmaxx() / 2;
. L1 O4 @% `( N2 W4 t) x3 u* Zmidy = getmaxy() / 2;
$ F3 c3 t  B! F& w+ u' `" Bsetcolor(getmaxcolor()); </FONT></P>
% k- U3 _+ M. E/ p( Z) _4 i<><FONT color=#0000ff>/* draw ellipse */
# _1 b+ o0 Z# A/ @1 c$ [ellipse(midx, midy, stangle, endangle, 4 [! Y4 f% f# q+ C# J
xradius, yradius); </FONT></P>, O/ b' e* U# V5 y
<><FONT color=#0000ff>/* clean up */ " f3 V2 A: c" Z8 I7 j5 n: v
getch(); # ~: _. z2 h* O7 i
closegraph();
6 ~. M$ v9 N3 N$ C7 I# k2 @return 0;
4 J! P6 ~  v  \. u- K8 U' h9 z6 H} </FONT>
! P( P9 R* q0 ~$ `
% R8 I1 M! g6 j( d</P>1 @5 F( w: s/ r- I( V& R8 M4 S' I
<><FONT color=#ff0000>函数名: enable </FONT>/ S! m$ R% N  ~- Q7 V4 Y' y, K
功 能: 开放硬件中断
5 ~% J/ M! C0 T" J/ \  z. [! R用 法: void enable(void);
/ W4 b! X5 f7 N( D程序例: </P>  n. ?/ X* K7 V7 U& h" Z5 G0 V4 k
<><FONT color=#0000ff>/* ** NOTE: ; S1 G3 s' v# U+ l5 Y' {4 R
This is an interrupt service routine. You can NOT compile this program
& c! \2 I. g5 lwith Test Stack Overflow turned on and get an executable file which will
  u4 b; `& m% h6 Toperate correctly.
" y+ v  K( [, \* {$ X2 [: v; k*/ </FONT></P>
. J  `3 ~% w- k& T# F8 M* y<><FONT color=#0000ff>#include <STDIO.H>! _0 H  {  H' |7 N* x0 L
#include <DOS.H>
* d7 g4 |$ x. {7 g7 h#include <CONIO.H></FONT></P>
5 Q- [9 W9 U) ]) p4 B/ c<><FONT color=#0000ff>/* The clock tick interrupt */ 4 n- Z& q% x' Y- V) z& q
#define INTR 0X1C </FONT></P>8 b. l2 t4 ]/ S0 c# X0 K! y
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
5 E! L- `6 E' T) @) q' D* W( ?<><FONT color=#0000ff>int count=0; </FONT></P>( k( K/ {  k: S- ~
<><FONT color=#0000ff>void interrupt handler(void)
8 `- {) |) U; k$ A" Z{ 6 A" E2 K& v/ H0 I  u1 d: j
/*   _# p0 [: g  A
disable interrupts during the handling of the interrupt
4 U' ?7 ]+ e2 J- p& e*/ ( W) `0 B+ J, ~  O  D
disable(); $ [0 |" e" B" {/ [, q' Z! b
/* increase the global counter */
7 m, X- D& c* N, zcount++; / [! Z8 O- E; a2 }' m7 w
/*
8 H( U+ k5 t2 y: _re enable interrupts at the end of the handler % s+ V  q: U$ M: H+ x0 F
*/
& g# {2 E. D6 C8 g  Menable(); . L3 k4 M- \; K4 q7 L1 W
/* call the old routine */
! x* D% Q7 m! G2 F! N/ f1 \( Toldhandler(); $ N* c% L) a7 P0 u5 A/ g  h
} </FONT></P>
2 l; O- _7 ~7 m/ K' m& d<><FONT color=#0000ff>int main(void)
0 }0 {5 X* I# V5 n% H{ # X4 U+ z9 K' e: d; U- g
/* save the old interrupt vector */ % Z! d8 ^/ r8 x1 L7 S2 d
oldhandler = getvect(INTR); </FONT></P>
. _- a: Y6 v, t8 Z<><FONT color=#0000ff>/* install the new interrupt handler */ 1 J& Q+ L( \* n" Z. M
setvect(INTR, handler); </FONT></P>- o7 D  _/ _" i
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 1 x; U- d1 c. X9 X
while (count &lt; 20)
% I  C4 Z; M2 I2 k# ?printf("count is %d\n",count); </FONT></P>0 f. m( n* n: T0 G/ v
<><FONT color=#0000ff>/* reset the old interrupt handler */
0 d9 {- n& |2 \' M! O- H* V& Ksetvect(INTR, oldhandler); </FONT></P>
* W% V% Z2 c$ Y" }5 k' V<><FONT color=#0000ff>return 0;
3 I% I  o% G1 q} </FONT>
& F; |! d" z7 B. l( S5 w, N9 l; A8 z5 R
</P>
. M1 T+ m  _/ i% t& c! o, P) X<><FONT color=#ff0000>函数名: eof </FONT>
* T2 z6 s, G! W2 F/ p  H功 能: 检测文件结束 4 R( `+ ~3 e3 t" C1 N" H0 h
用 法: int eof(int *handle); 6 N6 u4 Z# j. }. l8 u) i4 u
程序例: </P>
+ N4 w; z0 U0 s% z2 n& A! @<P><FONT color=#0000ff>#include <SYS\STAT.H>" V5 {& ^; x$ N) ]- G4 ^
#include <STRING.H>
# H2 A9 c' ^2 Y9 H* Q#include <STDIO.H>
- M/ U) ^% U. z4 h8 n4 ?& }( h#include <FCNTL.H>. y! e9 F5 S2 [' p6 p
#include <IO.H></FONT></P>
: |% s" d& c( Z<P><FONT color=#0000ff>int main(void) 2 k' l' i2 q8 t- I4 X5 T8 o  s
{
5 ]3 J$ X. }1 I  Q, X( Kint handle; 1 y5 Q, k6 ~; ^% S
char msg[] = "This is a test";
2 M, C" [/ {, ]+ s2 ^+ t: mchar ch; </FONT></P>
5 P% s" [( C/ s3 D6 F) f<P><FONT color=#0000ff>/* create a file */ $ I3 V1 T* I" P$ q2 ?
handle = open("DUMMY.FIL", ; N0 e, V! t" r/ @" g
O_CREAT | O_RDWR,
8 l" j5 D0 D, y3 H$ g' K4 `& jS_IREAD | S_IWRITE); </FONT></P>, B, C( E, g; D0 }- X% z
<P><FONT color=#0000ff>/* write some data to the file */
4 Y2 B. b; J( H! ~, Bwrite(handle, msg, strlen(msg)); </FONT></P>
3 i; [( H: N# F0 o9 [<P><FONT color=#0000ff>/* seek to the beginning of the file */ : ]7 x5 n; }/ U) X, [" b- h( _
lseek(handle, 0L, SEEK_SET); </FONT></P>3 ?# K" j4 w7 V6 R
<P><FONT color=#0000ff>/* - `& }. A! v2 r# _' l# q
reads chars from the file until hit EOF   y% |+ x3 x- b/ W, j" x
*/ 6 r  N7 {* ?! n/ \  K" g
do * R! b1 e. B+ C. X; {; m1 X' N
{ 5 F' V# T1 o6 F/ E: D
read(handle, &amp;ch, 1);
: ~/ k: W' T4 u$ Y/ n+ Tprintf("%c", ch);
1 J: _- [& f) ?1 Q, \} while (!eof(handle)); </FONT></P>+ v7 \2 S' w, {' C0 D: |* q
<P><FONT color=#0000ff>close(handle);
$ M" \8 f0 o5 c; _! ~return 0;
+ i: t+ j# P5 h. y( D1 a# C; G4 ]}
9 n" B' R% o% R, ?# U</FONT>) [- {" K1 m" I3 I/ _! V- Q0 [
</P>! X& `( W4 g5 \9 u* i3 ]9 g
<P><FONT color=#ff0000>函数名: exec... </FONT>
) A$ }, X' P" |- t5 b$ s功 能: 装入并运行其它程序的函数 $ m* E* r" V: m( h$ }7 ~
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
# y7 e$ Z( I5 U0 U- }% Q8 w$ f1 Tint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
: B7 a/ A+ f, Wchar *envp[]);
% {) @, G# g0 `$ Cint execlp(char *pathname, char *arg0, arg1, .., NULL);
+ V0 t- s# i! C( ^int execple(char *pathname, char *arg0, arg1, ..., NULL, 1 F, b% H: e9 R% s
char *envp[]);
4 a' P# |' [- {! a" _; [& }int execv(char *pathname, char *argv[]);
1 H) O6 Z0 v* n: bint execve(char *pathname, char *argv[], char *envp[]);
8 S( `  B6 V7 Y6 ]2 ^$ \& e  ]6 K9 {int execvp(char *pathname, char *argv[]);
) a3 N, ?" G* `! m% oint execvpe(char *pathname, char *argv[], char *envp[]);
/ s* V/ H- X2 K" b. d* q: p程序例: </P>
9 ]3 f3 }6 @5 x<P><FONT color=#0000ff>/* execv example */ ) x* h8 @& ]% i. ^# V6 O% s
#include <PROCESS.H>  T: g6 j  Z3 R
#include <STDIO.H>
8 @1 S+ c4 P' e2 t; m#include <ERRNO.H></FONT></P>4 f' R  A; f6 K6 g$ r$ ^
<P><FONT color=#0000ff>void main(int argc, char *argv[])
# c( p) h+ s1 z( P! u) }3 R! I{
3 m4 A( G8 H( Cint i; </FONT></P>
3 ~' d5 G4 j4 I( B  f# H<P><FONT color=#0000ff>printf("Command line arguments:\n"); $ k- y2 H6 D6 e1 C) ~7 d
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>! b5 P+ O$ m/ V1 U; i# d/ b
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
& X9 A' B2 X6 v% i3 ~9 m1 h# Oexecv("CHILD.EXE", argv); </FONT></P>! K1 H+ S7 W, d
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>( Z. J6 T0 ]- a- J% D- F
<P><FONT color=#0000ff>exit(1);
1 f* t* {. y/ s; \2 _$ ?} 1 [! X% A$ P; F; t! P" Z
</FONT>; a- ~6 Y& d! N: g  [5 j
</P># J% [: \9 L+ V( L6 w
<P><FONT color=#ff0000>函数名: exit </FONT>( }/ m  `/ e' L) B6 C0 R
功 能: 终止程序
& Y9 h9 a% I& v, J+ Q用 法: void exit(int status); ; U3 G6 a- {! w* P
程序例: </P>! P: |, a" j" X" ]7 m6 \
<P><FONT color=#0000ff>#include <STDLIB.H>. A+ q, n) _" T4 H! D* p6 r& R
#include <CONIO.H>. Y+ F9 a/ W: V5 k
#include <STDIO.H></FONT></P>
5 K! a0 W9 G; D6 H<P><FONT color=#0000ff>int main(void)
/ a9 n0 f. r- y% ]( n  u3 B{ + A" C4 C( b- w3 J, `: [$ f
int status; </FONT></P>7 h  Q* {- |2 Q0 w9 g4 n( E
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); - Z" b) e" V& Z
status = getch(); 3 N; U$ A) y! B$ L: h8 r! ]
/* Sets DOS errorlevel */
. R) o5 R7 G; b7 y: J4 Oexit(status - '0'); </FONT></P>
- e3 w7 K  A" V7 o+ d2 M<P><FONT color=#0000ff>/* Note: this line is never reached */
8 Y) `% a7 [1 [- @return 0; 5 S/ |$ r2 C; N6 v  W& @* U
}
; ]9 T! z6 [5 @- q: v# v</FONT>
$ b  \" z* _( w7 h/ q</P>
* _- V/ ~  h4 W2 A  _5 }( B3 S# P2 M3 z<P><FONT color=#ff0000>函数名: exp </FONT>) w/ B( h( D& k5 ?
功 能: 指数函数 - T4 N: `3 ?, Y8 _( ~2 y; e
用 法: double exp(double x);
; o* M9 O+ j5 B, K程序例: </P>
0 K8 O& M( ^9 V( i5 n2 {3 j<P><FONT color=#0000ff>#include <STDIO.H>0 q' y% |' y7 E! Q. ~8 T# }" o, J
#include <MATH.H></FONT></P>! V* c1 R) ?( I. M0 ^
<P><FONT color=#0000ff>int main(void) $ N! a4 f7 C( p0 r
{
* Z+ P* t& d: K# f$ b/ E7 e/ L  wdouble result;
" x. y2 s; Q! }( Y7 t: Rdouble x = 4.0; </FONT></P>
: \7 M* c0 M. c- Y$ Z% k4 Q& s1 Q* {<P><FONT color=#0000ff>result = exp(x);
3 O6 f- V7 x. {7 I% H9 f/ \printf("'e' raised to the power \ . D4 ]$ F: i! P3 a: v
of %lf (e ^ %lf) = %lf\n", ( l- F# `, s7 D$ V& h# i
x, x, result); </FONT></P>' m; ~6 E8 v7 {
<P><FONT color=#0000ff>return 0;
2 E5 q1 Z6 R! n2 M5 X}  Z5 o$ x8 N# U: g4 g
</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>
) @0 j& E5 z1 o- d9 N' x% H</P>
$ G. b7 \, A; R6 d3 V6 v: q<p><><FONT color=#ff0000>函数名: delay </FONT>
$ N; J$ y" L5 U! D功 能: 将程序的执行暂停一段时间(毫秒) 8 b5 H% v5 Q6 t& I' p: P; f
用 法: void delay(unsigned milliseconds); : Q- _7 b& u6 |& M# Z* _
程序例: 6 m" R- n" m! d: I# T3 g. ^
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ $ }0 w$ ?0 S/ T# _. Z4 @! u( O
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
- r" X0 _: Z! X' E! k2 Z% _{
5 \7 Q/ V! x2 x5 w, \) ?sound(440);
! [( x8 r: ?+ ]/ `- ~' ~, Ydelay(500);
. x4 a0 q, y/ c* t0 V5 ~nosound(); </FONT></P><><FONT color=#0000ff>return 0; - {1 L8 _, l0 j) l
}
& ^7 d6 l$ Y- V- O1 ^, @" ^" I. z  z
3 I1 G# W8 [: p6 s9 C+ t</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
% A' V7 a6 ?$ _/ P功 能: 在文本窗口中删去一行
6 u0 U3 _4 y3 d9 V+ T" ~用 法: void delline(void);
, J, i/ E* Y( Z* D程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) : \4 A9 e' C# S) f) T# Q. S' k1 r
{
& [+ q4 `9 G; M' h8 s+ fclrscr(); ; l5 n% T7 p: T# G8 x
cprintf("The function DELLINE deletes \
) C4 Y1 [2 p$ {5 _0 {the line containing the\r\n");
6 ]7 J  u, r7 z% C9 R: U5 S. Scprintf("cursor and moves all lines \ 0 Y& z- {# `! O, ~
below it one line up.\r\n"); # L) ~- @- U) Y& b9 \& N7 V2 E+ V0 y
cprintf("DELLINE operates within the \ 6 }) T. s2 a1 g+ X/ r% M  K5 p; @
currently active text\r\n");
/ ?, U0 @& j; V9 V9 _! ecprintf("window. Press any key to \
+ W# s1 \$ g8 ^/ v5 E2 C" z; vcontinue . . .");
4 X1 i9 n( B" N9 P3 D' f- jgotoxy(1,2); /* Move the cursor to the ; g  \7 B, h% |6 X% ?# d
second line and first column */ 1 u" d' \/ D$ o+ i' e# V3 X' e
getch(); </FONT></P><><FONT color=#0000ff>delline();
4 W6 E) }( X5 }- a7 Bgetch(); </FONT></P><><FONT color=#0000ff>return 0;   Z/ I2 m0 N7 ^
} </FONT>
9 \4 C1 K" T8 ^9 X* j+ [</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
/ O* E+ G( [2 }) L% Q功 能: 通过检测硬件确定图形驱动程序和模式 $ y3 a: B) o+ t; A0 }  z
用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 5 D% O  {6 ?" I  F' q1 D5 q  d# Q
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>3 b1 o' Y" G0 [3 ?; |$ a  o7 P
#include <STDLIB.H>7 q) D  y' I$ C8 X- n
#include <STDIO.H>( Q& b4 s9 @# A2 t$ z, l
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
$ v9 f6 K: J, M/ A/ b* ichar *dname[] = { "requests detection",
0 d8 I( y6 C! P+ e6 X"a CGA",   O- @! u% z: K; Y, i0 A
"an MCGA",
& P  H+ ^' K( a"an EGA",
! I2 Q9 V% O8 y% v2 \% o0 x+ W4 g"a 64K EGA", : Z% H4 v$ }7 h. `+ O4 |
"a monochrome EGA",
4 g0 u  r& B5 x4 e* ~+ L5 t; y" I"an IBM 8514", ; o3 t2 O" i/ c2 o9 @) M
"a Hercules monochrome",
+ Q& D6 {% Z0 x' w7 W"an AT&amp;T 6300 PC",
0 \, a7 ]) D, u"a VGA",
' l6 E6 y4 p7 f4 }+ n"an IBM 3270 PC"
# B9 [5 x! p2 _2 V- y- p" m! S! o}; </FONT></P><><FONT color=#0000ff>int main(void) ) h& \& j. K5 B% V# ]' B
{ 9 @& Y% |$ j; ~. ^( n6 o0 \1 A
/* returns detected hardware info. */ 4 I5 G5 W! \9 }2 f& [
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ ( `6 p3 P8 f4 z# J( @4 @. T+ J2 X* q
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
; _( D5 I2 D7 ~0 A& j" Ierrorcode = graphresult(); ) F: _, T& k' }0 C
if (errorcode != grOk) /* an error : U/ f( k% M1 x6 N; L
occurred */
* J( a% d* X# g- }4 |{ , y/ ?0 q1 B+ Q. \6 o% I" ~
printf("Graphics error: %s\n", \ , v% ]* C; ?3 P' U% a
grapherrormsg(errorcode));
* Z2 {+ ]$ J' ]/ Q) `6 xprintf("ress any key to halt:"); 1 _5 c2 V8 @" ?& J: L# v
getch(); , s% b* D* k9 B
exit(1); /* terminate with an error
/ [7 o  [4 |* C. ?# Q3 x: gcode */ # w9 S0 Z8 v: {" e
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
3 O5 W3 i) p% b' K/ Sclrscr();
& S! }' e* j* n* ~6 D  p# Z* Tprintf("You have %s video display \
- x, [/ C; [# s, W  F7 u. Wcard.\n", dname[gdriver]);
- p; n6 I* [- G+ Zprintf("ress any key to halt:");
0 m+ e5 t8 h3 c2 N2 ?getch();
4 ?- G+ K, [; ~+ Xreturn 0;
& k% q3 v7 \* k} </FONT>
0 ^. T4 D4 P6 {! K. ~% a8 A1 W. B. S. u3 f. u" S9 ?1 L$ S
( {4 H, S5 y" w4 ~) W2 \# Y# `! E; T
</P><><FONT color=#ff0000>函数名: difftime </FONT>* i/ n) ~5 o9 p$ ?' S
功 能: 计算两个时刻之间的时间差
' G( I" w) l, m1 [1 X用 法: double difftime(time_t time2, time_t time1);
/ Z  F" a1 y! g程序例: </P><><FONT color=#0000ff>#include <TIME.H>  J9 A; p2 @+ L7 |: U
#include <STDIO.H>
5 v7 y: m. k9 j: P7 p#include <DOS.H>; P1 P# t' D9 Y! Q- V) Z7 u6 ~
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) : h/ C2 I) H6 O5 m3 o4 O' t
{ & C& }& B) [; {$ s
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); 3 L8 n2 C$ W  B
first = time(NULL); /* Gets system ) v/ T1 m# C0 I6 N% z
time */ / O$ v  W+ F5 C. a
delay(2000); /* Waits 2 secs */
& h) A: O9 s# T  Y2 T, S& D3 _second = time(NULL); /* Gets system time
' s2 F7 |! S0 z) p# X6 Tagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
3 [* B8 b% E  m# J" {. X0 M/ [$ O& wseconds\n",difftime(second,first));
- s- o& |& V0 l5 ]getch(); </FONT></P><><FONT color=#0000ff>return 0;
0 x  n/ G5 o" k  v+ |} " L8 |( i, t, {" `" _0 e
</FONT>' B( Y. c: L, p: E6 Y1 v1 a( }: f
</P><><FONT color=#ff0000>函数名: disable </FONT>
1 O( k. K( u3 X, g1 b" N0 s功 能: 屏蔽中断 ) Z0 Z9 J+ U* H2 {+ U9 \
用 法: void disable(void);
: C6 T2 T. L  W* v+ t程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
6 w( r: G# M0 a' Yroutine. You cannot compile this program
' K/ }0 j+ _2 Swith Test Stack Overflow turned on and
, z8 F; l/ G. O# I0 qget an executable file that operates
( {# p* \" w7 r( ~8 dcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>( Q2 d4 K+ ^( Q* }; N1 |4 `
#include <DOS.H>2 d) X# e% i! g
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
, X7 t1 \$ F5 n  }2 K; X' einterrupt */ </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) " S5 p( D1 t0 e& U/ E
{ / J- @: }0 e8 _
/* disable interrupts during the handling of 0 b" H$ ?2 s7 H
the interrupt */ ' X, Y5 [. [3 n2 t3 e0 d
disable(); # g! P+ m  e: k, [. [) s
/* increase the global counter */ 6 @" @* p$ [% E* o
count++; 4 N% f  N; d) F/ {
/* reenable interrupts at the end of the   {9 H$ x3 c) h! ~
handler */
; \9 K+ S5 E5 c* i; y8 y3 Zenable(); + j8 B8 t# ]( Z" ]8 H) [, c
/* call the old routine */
) j# k6 h) |" R1 c  n: x4 q! woldhandler(); 5 J2 [7 V' `4 P
} </FONT></P><P><FONT color=#0000ff>int main(void)
& v: I8 ?7 B/ Q& W% y: S. u# z{ . k1 b! i, J, J" E' @, n% y3 ?" H
/* save the old interrupt vector */
1 P; M6 p1 C- D: ~7 K1 G, m3 roldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ & w" i0 X4 v/ i8 a: x& u' u
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
8 I. n0 Z9 H1 U" H6 b" G6 F+ Vwhile (count &lt; 20) - P! ~/ i  z' S4 \. a
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
9 f2 L4 N5 Z5 G' m- K6 Asetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
  y" K, b; d4 K% ?: Q( D} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
0 R7 C: R! \; J, X# x) O7 c功 能: 将两个整数相除, 返回商和余数
  m8 v$ K, P% b用 法: div_t (int number, int denom); 9 [1 _+ ~  P5 y3 Z0 \- m
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>, V7 r# z# t, b( P
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 2 J. b7 M; a' u- {; c
{
2 ~5 D' Z' p& D9 f& R3 Zx = div(10,3);
4 J  o8 g* w4 C+ i, i3 }5 Qprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
. Z7 b+ z; }6 F3 t}
( q5 K- o9 F6 x1 d7 p6 O</FONT>$ {- J' h" S( E7 f, M
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
! n' y# v( J' Z4 I- |0 g功 能: 获取扩展DOS错误信息 1 ^8 o( @7 d, C! i) b! C' E' C" G
用 法: int dosexterr(struct DOSERR *dblkp); 5 e' ?4 K" ~3 M
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>8 }7 X4 y* w& G5 G0 X! b
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) - E4 ?. J4 z6 m8 k1 i/ b! S
{ 2 ~' ^  o* t( e4 W, E
FILE *fp;
* a/ _, V$ @0 y3 Z8 ?struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
$ H7 Y# A  w* ~- v0 Aif (!fp) perror("Unable to open file for
, |( }3 Y8 {7 f5 ~reading");
& }; d0 i  a% L  \dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ & J+ r  G3 S& @+ l$ h3 K" r0 m  \7 `
information:\n");
' }  O) c# H/ e8 vprintf(" Extended error: \
8 v! C4 C6 f# f+ {, V%d\n",info.exterror); ( o- e! M6 `0 t, L% t$ E8 G
printf(" Class: \
0 X! l/ q% q. k" h%x\n",info.class); 3 `0 V9 b# [* v) v
printf(" Action: \ 6 Y9 G2 N- `; A4 ~  [
%x\n",info.action);
  b6 ?  @7 V* d5 c0 d; Jprintf(" Error Locus: \ 9 h& Q, L0 Y0 b3 `' Z: i% l2 K
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
( p' g1 d2 \( D* q$ W% a  c} </FONT>4 x0 V' i1 [4 z8 E9 g7 _% K9 Z

& e3 p( @( k' ^2 K0 ?. P</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
. C+ ?/ A8 t; w: H. m5 |. ^- n功 能: 转换日期和时间为UNIX时间格式 8 Y* ^9 N% y4 K6 j) h4 J
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
; G% J, E; y( u程序例: </P><P><FONT color=#0000ff>#include <TIME.H>3 Y9 b9 r* g4 q- F/ ^
#include <STDDEF.H>
: I% ~# m. x$ p) c#include <DOS.H>- I2 g) f! K* j- ]: s
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) + C: ^$ B; k5 r2 t3 G8 x  V
{ ( v% y; u: T5 _  D- ^4 I
time_t t; 5 g+ `2 V- _& c! _& ]" U
struct time d_time;
9 d' S5 f( z. ~' Q9 l3 Z2 rstruct date d_date; ! |) D% X0 E$ E3 b
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); : C. Q9 n- t  U
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); ( \1 s  G& [1 m* D6 s- E- K; S
local = localtime(&amp;t);
% v4 a( e& e" g- C9 c4 iprintf("Time and Date: %s\n", \
( o% q* i# q% V% @% n6 Rasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
7 }6 k) m$ A, V% c; i, e} </FONT>8 }" ]$ E4 k* A5 I

" v/ O( J* @; ~5 U# v7 t  y</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
" V- z: [9 s& r+ I* E0 V9 h功 能: 画多边形 5 H; P# Z1 i+ {- Z0 X' T
用 法: void far drawpoly(int numpoints, int far *polypoints); 2 C+ b9 X% P# W2 W7 M  a
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
5 E: F5 c4 V  A* v, E7 |#include <STDLIB.H>! |& ?4 n! Q( r/ {  G# C% w$ L
#include <STDIO.H>
6 ~/ g: G' J3 _#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) 6 G& P6 P- G8 i9 \8 x& r$ a7 s
{ & o7 a5 h& Y0 i* S
/* request auto detection */ # d8 @4 {" D! P+ G& G  c$ J( N
int gdriver = DETECT, gmode, errorcode;
5 z! j  y! o& O6 U5 `8 [int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ ' O4 d  l- e  V! _3 T) T* `
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local % @' X/ g( ?. M
variables */
8 T  g8 G. ?2 o& h9 `6 jinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
0 f8 e3 X8 D" S8 q: u3 l0 Rerrorcode = graphresult(); * i2 N$ z# M8 t, Z) o9 _
if (errorcode != grOk) 4 a1 P/ b5 P! |+ f8 A! J2 A
/* an error occurred */
4 p, `8 b; K. X& [. f{ , u4 V3 S, P& p$ q  K& m+ ]8 E' Y
printf("Graphics error: %s\n", \
. V9 M( x4 T0 m/ ?. u( [( Ygrapherrormsg(errorcode));
( R) ?2 U- B( ?6 d/ t! F1 f8 Hprintf("Press any key to halt:");
5 v( t, [' j/ ^' [  ^getch(); " d' D) p+ O+ R( N- J) F* p2 W
/* terminate with an error code */ % ~: k) R) q. W6 ~
exit(1);
. ?. ~( A! f6 M) s$ U! }: }8 O} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); 1 d8 J3 Y3 V& b2 C6 o  \' @  G8 O
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ * Y9 A+ L4 ~, o) K! R3 i5 p
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 9 |! U6 [$ M0 P2 k6 j- {! u7 s
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ $ E# a5 W) J3 D3 ~$ n5 J, F) }2 D/ A
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
. h; P" }0 Q* c+ D0 Spoly[7] = maxy / 2;
7 Y3 V4 a# [7 s& ?4 Y/* ; ?7 Q5 O- [$ F( f9 @/ s
drawpoly doesn't automatically close + }0 C7 Q" \0 Q) c% E9 m' C
the polygon, so we close it.
# U  ]  l+ n& g: h*/ & V9 J8 d* A# T% r5 s# }
poly[8] = poly[0];
. e$ C0 y- d! ?. Ppoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
5 B' b) @# r3 Mdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
3 N5 O# d$ C& v4 h1 d9 v2 fgetch();
3 M2 m. {/ @4 h  Sclosegraph(); ' l" c9 B5 ]9 }( t+ \7 |1 Z
return 0; + ]8 e* v- B9 n& [# n" q
}
" }. k! G/ r: B9 {; ]</FONT>/ Q! [$ a& f/ ^' K& [# \( I( T
</P><P><FONT color=#ff0000>函数名: dup </FONT>
2 I* R0 l+ ]6 [功 能: 复制一个文件句柄 7 m9 C! S# B$ t1 F3 ]! Q
用 法: int dup(int handle);
: ], b( K9 y! }程序例: </P><P><FONT color=#0000ff>#include <STRING.H>" S$ H9 p) ]& B7 M; P
#include <STDIO.H>, n9 h2 j% X, ]/ m7 N
#include <CONIO.H>
/ ]; ]* K( y  z8 A* p. L$ d* ?! }#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
9 O! ?$ `$ O9 K3 e2 V6 N0 x) Y! H{
( o2 ]- ~& z3 |  }+ x1 ?" NFILE *fp;
* I! d, y. u# L9 h) Wchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
. n" r$ \1 z: N( J  e9 k9 T1 Ofp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ 4 R9 i' S2 B9 E- l
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); ' d( R; J" y* G
printf("Press any key to flush \ ' W3 S. f* f9 {- y) B2 {* b8 A8 Z
DUMMY.FIL:"); 4 |* e6 E7 |. r6 K
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without & |2 Z# e8 h  _. e! i& z
closing it */ 1 i7 p* i; Y& b6 r
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
& @& t; [$ X! @" Y6 Skey to quit:"); & S0 @/ \5 G# K  _& s  S
getch(); 9 X# D) ]; w, \0 u2 ]9 t
return 0; 1 z$ M! |1 Z: y. R- ^; n: m
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) 2 t# P/ }4 y$ I, _  n
{
. z" l& T  l5 w- D" F. S! oint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
  ~+ L1 E; K& ]$ I* gfflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
+ z4 |7 k, q+ h8 M7 Vduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
; a$ N" B+ o, G  A1 `6 WDOS buffer */
# o( X+ [, j- a8 oclose(duphandle);
& ?# P; e$ m/ x8 Z3 s}
7 @- F' n* n3 ]) H% m- _# T; L" X& u2 e5 e4 l7 \8 a4 n5 r+ I
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>  G. J5 G. L6 K4 R3 O
功 能: 复制文件句柄 $ n- K& W$ |5 n& \0 s! Q+ [+ l
用 法: int dup2(int oldhandle, int newhandle); 6 s& E( }5 c2 L" F: D6 j. f
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
# \" e! {" b1 l#include <STRING.H>6 Z1 E+ |0 }" P  ~8 {6 F4 B
#include <FCNTL.H>0 q6 S( R5 |0 ?$ \4 R+ i9 P
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
6 G2 q4 ^8 q, m. c/ |; c{ - ?- f" \/ p" W/ o0 T5 Y3 t) q
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
. Q# H/ O* n+ L% u" {9 tchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
4 k9 m5 |# a) C& H1 Dnul = open("DUMMY.FIL", O_CREAT | O_RDWR,
3 M& r0 H9 Q# ]1 V/ f6 w1 FS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
6 c3 L0 e3 E: ~8 ]' d) ooutput */ " |5 ]6 N; O7 F( m& [( l: K" z
oldstdout = dup(STDOUT); + Q# G  i- @0 D6 C
/*
$ L- A/ ?' T/ E: C4 Wredirect standard output to DUMMY.FIL
# F5 R4 U$ L( A" C- R- U" bby duplicating the file handle onto the 4 E( b8 ~% n: C7 R9 ~4 @
file handle for standard output.
$ U; E" ~4 [5 n: J( @0 a# p*/ ; c/ I* g0 N9 p' C, M4 S. i, |. B
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */   ]# G" d- J; _& X: ]% d+ H
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
! l6 W6 L' }( nwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output # B6 E% c1 q3 {4 q& T- E) F
handle */
1 z( r1 @3 j1 a' ldup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ ; I; G" W; M4 k2 N& R
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 6 P4 ^6 ]" g- R4 }9 ~# g* D6 U
} ! ~- s& r8 j' }7 x4 M0 A
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-7-21 02:52 , Processed in 0.449433 second(s), 57 queries .

回顶部