QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2142|回复: 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>
0 E/ G/ N! p/ t</P>
) o6 U6 E2 v6 e' m- @2 g* U# Z- M2 c3 k0 W6 |+ C9 ?
( F$ A) K/ {3 r6 r
<><FONT color=#ff0000>函数名: ecvt </FONT>
# c/ K/ _- F$ {* Q功 能: 把一个浮点数转换为字符串 # d( \/ w; m0 h( Y5 c
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); ' v8 K; o3 a4 t- J9 \
程序例: </P>
3 |/ c' U2 g9 E+ D<><FONT color=#0000ff>#include <STDLIB.H>
; s# j0 s# x; x: ~9 `#include <STDIO.H>. T3 M3 Z  C8 ]( h$ |& \* Y+ K1 l% P
#include <CONIO.H></FONT></P>: S  {" n+ @/ e
<><FONT color=#0000ff>int main(void) 5 l8 V. r* p2 H) |
{
& E5 `' b" g) ^; p) Rchar *string; , O  }* {; U+ C) h1 Y# Q, Y
double value;   m" O/ I$ G2 `# k
int dec, sign;
( d* x, {3 M, D8 z4 Pint ndig = 10; </FONT></P>' g; I+ {$ }2 i* n' T5 e* [
<><FONT color=#0000ff>clrscr(); - |! z9 v3 B; k
value = 9.876;
9 j* f! Y2 E& p" Qstring = ecvt(value, ndig, &amp;dec, &amp;sign);
+ l( _4 J& U* Iprintf("string = %s dec = %d \
: j7 E7 g1 p4 F5 s8 l. dsign = %d\n", string, dec, sign); </FONT></P>
* P% W: O2 @1 T! E( C) T: V<><FONT color=#0000ff>value = -123.45; + @: l( h; ~% X: R9 q
ndig= 15; : [6 d; Q4 I/ D+ O0 q8 c* \  }
string = ecvt(value,ndig,&amp;dec,&amp;sign);
4 ]! g: u% l" P9 K+ D! l1 h* vprintf("string = %s dec = %d sign = %d\n",
. }1 ]. d9 j$ I/ h/ pstring, dec, sign);
$ Z" M5 g9 L: e$ q/ b) y1 s/ W</FONT></P>8 |, A% a# C/ f1 V  e# L
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
! J/ A9 I' U& v2 A/ \6 u' [* P5 Unotation */
& L$ x" M) c5 ~0 d, B, S/ U: {' Tndig = 5; : m) d# H+ F' m4 D" j( \- I" t  P
string = ecvt(value,ndig,&amp;dec,&amp;sign);
0 I, u! s7 m" y, {, s! ]9 oprintf("string = %s dec = %d\ ) U) K+ I, P' b6 P* C* {
sign = %d\n", string, dec, sign); </FONT></P>
( P" y$ h8 p( p( V" _% W/ E1 ]<><FONT color=#0000ff>return 0; ' H% l+ _& l3 d3 `
} </FONT>
3 p" R% ~6 Z3 g8 k& S% O) e$ n$ X. |7 X" {/ u' v
</P>
9 H( n2 {( C$ z- C: l, O  B<><FONT color=#ff0000>函数名: ellipse </FONT>
" T- t  x+ q, k" b功 能: 画一椭圆 5 ]) O0 _% H$ o6 U4 \
用 法: void far ellipse(int x, int y, int stangle, int endangle, $ N  {0 n# N5 ~+ X, Y$ ~
int xradius, int yradius); ! W+ @. W9 \4 A0 {' E) Y0 m. [0 X
程序例: </P>- d3 k/ D- v/ \" x5 a
<><FONT color=#0000ff>#include <GRAPHICS.H>; d/ q9 e; \! [' i5 h
#include <STDLIB.H>
, o5 s- k1 D: A2 N9 w* ~4 J5 z5 O#include <STDIO.H>
4 g" ]  x7 U* _3 F#include <CONIO.H></FONT></P>  `9 K! {, j, h  l% n* j
<><FONT color=#0000ff>int main(void)
: j! W' R0 X# d{
7 U2 x  g6 {7 e2 T7 Z% S0 y8 L2 F/* request auto detection */   W9 J. d+ N$ b5 ]( n
int gdriver = DETECT, gmode, errorcode;
1 T+ u" T" Z" x  M3 x" jint midx, midy;
6 m* R" n9 i; M2 k# ~3 Vint stangle = 0, endangle = 360; 5 d( s5 Y( \( Y3 _
int xradius = 100, yradius = 50; </FONT></P>" h. \  n* d5 ?8 k2 c5 f1 @
<><FONT color=#0000ff>/* initialize graphics, local variables */ * ^& b9 s9 a% V4 M( a
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>8 r- M8 y8 I' b  E
<><FONT color=#0000ff>/* read result of initialization */
& |; N) Q5 ~% P' t# G6 @errorcode = graphresult();
! S( ?- m! d! ^( H) l4 Z# rif (errorcode != grOk) + a! C) q) `' i/ R
/* an error occurred */ 1 [( r4 J. b/ {3 t2 {0 C* w
{
% r: j6 j! h5 O: Eprintf("Graphics error: %s\n",   a! g+ D4 Z/ t6 |( S/ ^
grapherrormsg(errorcode)); 7 k; ~$ K" s( ?2 c8 A, Z
printf("ress any key to halt:"); ! X0 T7 M! T6 W: ?0 ]! M$ |; \
getch(); 7 U( L8 {$ x0 C7 x* J% Y
exit(1); $ I) A* k- S) w5 Y
/* terminate with an error code */ 3 H7 W- g" \, K5 {% U: L3 {
} </FONT></P>
/ {$ i+ b4 q6 q1 s# {9 v7 u<><FONT color=#0000ff>midx = getmaxx() / 2; 8 _2 L- j! t. G" L% x
midy = getmaxy() / 2; ( g8 Q2 ~! k; @* k# K
setcolor(getmaxcolor()); </FONT></P>& D% X% f0 q0 A1 B7 x$ ^* L) J% f
<><FONT color=#0000ff>/* draw ellipse */ * q; P/ r$ C8 ^5 D: m% X! I: [
ellipse(midx, midy, stangle, endangle,
+ b8 u' Y) @3 {0 q$ c( Z8 Uxradius, yradius); </FONT></P>
/ j4 c; g8 \( F7 r4 `<><FONT color=#0000ff>/* clean up */ % ?) n5 W2 k$ j
getch(); * _4 ~- e+ A) `# ?
closegraph(); % a, _: h' H$ l- y
return 0; ( l; e% D1 g, A4 U
} </FONT>
( E" R2 r& B1 x# f9 Z9 B9 W  O/ I% j- A0 H$ |
</P>- c; ^) _- ]4 C
<><FONT color=#ff0000>函数名: enable </FONT>9 U( {% a! m+ g8 G
功 能: 开放硬件中断
6 r" k& h  S# }6 u& j: l7 O用 法: void enable(void); 2 T1 I( v5 a+ e  ^+ l) }6 v1 V
程序例: </P>
) y1 s% y2 q: U; r* a$ g+ y  Q<><FONT color=#0000ff>/* ** NOTE: $ C0 B0 t4 j1 o( B) m' w8 H4 s
This is an interrupt service routine. You can NOT compile this program   l3 i8 c5 [! w: v
with Test Stack Overflow turned on and get an executable file which will . H/ q- h- R2 `# X
operate correctly.
5 M4 v" ^: D# v) p*/ </FONT></P>
3 ]( J% x6 w. o<><FONT color=#0000ff>#include <STDIO.H>
; z1 Y) ]$ l2 q, f#include <DOS.H>% s. R/ j2 x5 O, r) l5 w( O
#include <CONIO.H></FONT></P>
5 N! I4 |% [  @0 q: y+ S+ X<><FONT color=#0000ff>/* The clock tick interrupt */ % \0 \1 a( V* a9 z$ y& |# K6 Y+ n
#define INTR 0X1C </FONT></P>
) |% _4 e: [6 G<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
8 p+ S: ^8 y0 i/ I8 c<><FONT color=#0000ff>int count=0; </FONT></P>
. M$ |) P6 [. y* T# P) ^2 e<><FONT color=#0000ff>void interrupt handler(void) . J. W1 o8 y$ e% d- T( W
{
$ F$ h& I2 v( z1 M/* # `4 l, t3 k' E8 H" k
disable interrupts during the handling of the interrupt
& L6 K5 {9 c! @  F4 ?) @0 l0 m*/
, ^: T& u2 M5 Y" q* xdisable();
& x( Z. M9 g  P$ n' C/* increase the global counter */ . e2 ]: E" [3 T# q
count++;
; Z5 c) w% Q& B/ {% H' X/*
* d6 t7 Z% N2 F9 `; f) sre enable interrupts at the end of the handler
: ~# N6 G* _4 E*/ & ]8 ^9 n. V9 P/ A# L6 y# M* O
enable();
  H; c+ m, n( v6 ~/* call the old routine */
, ?2 G# n2 r+ d  u/ C: Poldhandler(); % B  c' N' n8 @$ o4 g3 {9 s
} </FONT></P>
$ k' I" q  H) t8 n. Q<><FONT color=#0000ff>int main(void)
" f' u% K- d4 h2 V{
4 }+ L, V' W: Z/* save the old interrupt vector */
' ~. c1 }$ d" n& Holdhandler = getvect(INTR); </FONT></P>, K; Z' [2 Z$ g
<><FONT color=#0000ff>/* install the new interrupt handler */ 2 V9 B/ _) M; v+ s
setvect(INTR, handler); </FONT></P>3 N  b# G- J9 D) A! N- C
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 5 o3 l! D% _  U
while (count &lt; 20)
* F% h6 K2 U. d; T; U* z8 F: Vprintf("count is %d\n",count); </FONT></P>
- D8 Y4 b3 T, q: C; L7 x; K<><FONT color=#0000ff>/* reset the old interrupt handler */
7 g8 m% s% R! P3 \7 Hsetvect(INTR, oldhandler); </FONT></P>: H; g' M' n' L# X
<><FONT color=#0000ff>return 0; % `& G  r% d& Y( g/ I# B  J
} </FONT>
+ [1 d1 S& b/ B8 Y+ u# B3 f; Y" Z% d4 d  w  f/ W
</P>$ @% b3 R+ Z) w; {2 R- d/ q* v  b
<><FONT color=#ff0000>函数名: eof </FONT>; K* X1 p  w# t' p- a
功 能: 检测文件结束
' p5 z* _- v+ }* Y. X' _$ K用 法: int eof(int *handle);
6 P9 H* r% i- }: C& O" N: n程序例: </P>8 m) y9 s( ]; ~! o5 B+ Y, U$ W
<P><FONT color=#0000ff>#include <SYS\STAT.H>
1 n6 Z' T. u8 P#include <STRING.H>
. G# q0 c' f6 Z% L5 V& t#include <STDIO.H>: b3 E# {9 z0 d4 o
#include <FCNTL.H>
" z5 S: n6 ?( K3 l( q5 {. o" a& q; S#include <IO.H></FONT></P># C3 H$ u& I( M
<P><FONT color=#0000ff>int main(void)
! Q/ C: g3 s* C) z( w8 ]{ # ~/ ?5 Y4 n; J8 S" h  J5 w
int handle;
( {( q# z- ?7 z; |char msg[] = "This is a test"; $ ^. l3 E2 Y  D1 t- L/ j* |  }2 q- R
char ch; </FONT></P>; G, w3 d# s" {% \0 r) `
<P><FONT color=#0000ff>/* create a file */
) C( W& U% h% v0 dhandle = open("DUMMY.FIL",
! Z, u$ B2 i6 d% H7 `8 {$ uO_CREAT | O_RDWR,
1 |8 s2 U3 n  P* T( r7 ]3 B+ \S_IREAD | S_IWRITE); </FONT></P>
/ W! O7 _' U, L2 O<P><FONT color=#0000ff>/* write some data to the file */
9 h9 B8 F5 k* ?0 b9 p' g+ Hwrite(handle, msg, strlen(msg)); </FONT></P>
$ E2 S) q, w# h/ f. b<P><FONT color=#0000ff>/* seek to the beginning of the file */
# X# y) H+ Q. e$ zlseek(handle, 0L, SEEK_SET); </FONT></P>
2 L" t# Z; H  Y2 I; V<P><FONT color=#0000ff>/*
2 t! P2 \& J2 I1 `" F/ c' k9 Wreads chars from the file until hit EOF
! c6 X) _' |) R4 t2 Z% t3 N& K" Z*/
8 G3 `4 C* d: E" P8 _do : T. d" K3 R+ u/ |
{ 8 s# L* O" m9 t# A
read(handle, &amp;ch, 1);
  z8 k& O  W; \9 E8 C! rprintf("%c", ch); 1 ]) P' j) O( G" I
} while (!eof(handle)); </FONT></P>
' t* E9 M# [# X  j: `! `% J& r<P><FONT color=#0000ff>close(handle);
9 c6 k# ~7 ]/ V) Nreturn 0;   m' G; V) @2 Z2 M' _% o
} % _) L, h) o, _" u# N
</FONT>
7 @6 [  Z' Z$ u* R" C7 W; G7 h</P>
& p; B  ^& P! N. F7 t# V<P><FONT color=#ff0000>函数名: exec... </FONT>
3 \# q9 z. Y  ~功 能: 装入并运行其它程序的函数
! J+ E7 Z2 y" t7 a# ]3 o- X- x1 I用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); ) e0 u7 V# g, U9 V% J
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, * N+ t' M  G9 p, k8 x; Y
char *envp[]); 9 r& \9 V% E) @' S7 M( C& n% p
int execlp(char *pathname, char *arg0, arg1, .., NULL); * b$ m- I$ I& v+ }# J! r
int execple(char *pathname, char *arg0, arg1, ..., NULL, , d9 q, W. k# t# g, V: \0 f+ ?
char *envp[]); ! i6 m6 P  z/ R
int execv(char *pathname, char *argv[]); 0 T0 D$ q3 \' P6 s' q! \9 E
int execve(char *pathname, char *argv[], char *envp[]);
) D# ~3 Z- c  U1 h8 L" pint execvp(char *pathname, char *argv[]);
4 _8 f" `+ f( gint execvpe(char *pathname, char *argv[], char *envp[]); % K. v( B- x) o2 _5 I6 w; m
程序例: </P>
4 H" \, |+ f/ b6 ]<P><FONT color=#0000ff>/* execv example */ . N$ v; w1 r# {
#include <PROCESS.H>- G/ q7 }8 \& ]+ J: P( q7 L
#include <STDIO.H>- d( Y( L$ g+ A( Q
#include <ERRNO.H></FONT></P>
' Q8 Z+ e! S$ Q6 x& ?9 x<P><FONT color=#0000ff>void main(int argc, char *argv[])
0 ^* E8 ]9 {9 m9 O' ]{ / X6 b3 s. J9 l0 a0 V( c2 V
int i; </FONT></P>
, @/ p* f/ A, M, J! Q3 y% i* q<P><FONT color=#0000ff>printf("Command line arguments:\n");
+ G1 U! f/ e  g6 G8 ifor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>0 N$ P2 X' H" g" T# c
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); ) m" M+ E1 }5 l4 G; C" d
execv("CHILD.EXE", argv); </FONT></P>3 _! S7 u4 X6 T* K
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
" h# D$ q+ k: U$ p3 f6 C9 F. }<P><FONT color=#0000ff>exit(1); ' K2 W- e0 W) L: T5 t
}
1 h$ |* B! Y( Q& n0 a</FONT>
7 s& s  J% H, r; W1 w2 [  B</P>
) ?* K) U5 d1 K6 I<P><FONT color=#ff0000>函数名: exit </FONT>) ]9 @3 H+ E) S* k7 t' M4 C
功 能: 终止程序
$ i6 c8 [7 W9 y用 法: void exit(int status);
" K9 h+ b! D$ ~( ~9 i" v" s程序例: </P>5 p# E/ N- K& K; T* d1 E: s4 [* J3 r
<P><FONT color=#0000ff>#include <STDLIB.H>; Z6 t  H' m. M0 g3 N
#include <CONIO.H>
: `( \  @! j. p1 F& I; \- }#include <STDIO.H></FONT></P>7 P7 `+ |& c* l
<P><FONT color=#0000ff>int main(void) . q( ], X+ G# i; V$ O
{ : q1 F  i. |( H4 I8 i
int status; </FONT></P>
6 H- P! N/ h; B& ]; c<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); ! V# a; f5 }1 K5 |7 m% d
status = getch(); ) c' c+ F' Q9 l" w% \# J
/* Sets DOS errorlevel */ ; A$ K( d1 c5 P3 f; V
exit(status - '0'); </FONT></P># Z! E& y  x# z1 T' w
<P><FONT color=#0000ff>/* Note: this line is never reached */ ; T  G! O$ [! E" Z6 t# g  g
return 0; . q7 |& @) c/ U8 g& S9 B
}
/ G5 x0 |0 m/ D! v- k5 @  ]/ z& Y! o5 _</FONT>' q$ G) W4 i* Y/ {' W2 A
</P>% c/ }7 k& P8 Z$ _7 P* m
<P><FONT color=#ff0000>函数名: exp </FONT>
* F) `6 o5 n; [8 r! ?& t功 能: 指数函数
( k; K2 a- d* O* N! i* B3 y用 法: double exp(double x); % j5 N' ]0 k5 [
程序例: </P>
. W2 n6 G2 R8 Y; H4 G<P><FONT color=#0000ff>#include <STDIO.H>: z" a/ c' i+ B3 D
#include <MATH.H></FONT></P>
' N1 A! t& K& U0 b/ H<P><FONT color=#0000ff>int main(void) 7 @  k3 A9 G; O/ }3 v9 o
{
+ u# O6 t& P' p: s8 O& tdouble result; 8 U% l" w3 \$ O% G2 R
double x = 4.0; </FONT></P>
/ S8 G2 `% K/ i1 a4 C<P><FONT color=#0000ff>result = exp(x);
; X7 g2 K& ]) x& H( u5 V+ bprintf("'e' raised to the power \ ' o2 R6 ~  X4 [3 H4 J! Q! r" ~5 U3 o
of %lf (e ^ %lf) = %lf\n",
) A. O. E. z5 @7 z) o+ Ex, x, result); </FONT></P>( x9 ]. s! h+ y0 z( L1 h; E/ s) \
<P><FONT color=#0000ff>return 0; ( g( r/ Y/ o; K- P; I7 S* y* ^# ?
}: v1 d; B1 P% ]% 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>; q4 b; t- y4 x- {
</P>
! I! Y1 U7 o" `( O<p><><FONT color=#ff0000>函数名: delay </FONT>
! D) m- Y. S* U2 w& K功 能: 将程序的执行暂停一段时间(毫秒)
) a  t  I$ e& S6 O用 法: void delay(unsigned milliseconds);
& k3 N4 y" p( ^程序例: ! A# [9 Q4 |! S- q$ p# M3 T
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ; R# n2 D" f$ C- s& V
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
* f3 g/ H3 D, W/ T" s2 E: @) [{ 4 x1 S7 d! Q$ \* U
sound(440); . V: g2 Z' M8 j' }, c5 g
delay(500); ; B8 T; B" J( {0 C( A, E! \& c
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
# r: a' _& m, t: q} * u) D( {* s5 D- {, h
% s2 j" q3 B5 k8 w: R
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
* D+ o: A8 \1 ?. e功 能: 在文本窗口中删去一行
! e7 n& |, d  |2 O9 W用 法: void delline(void); , I8 g3 P5 P7 \6 G+ ]# P" l
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) $ f2 X6 ~  }5 L5 G8 J8 Q8 ~4 Z% n0 G
{
6 m; V6 b$ ~$ G% F: y% @clrscr();
9 ~: T2 m3 Z0 J2 O% z4 t8 Gcprintf("The function DELLINE deletes \
( g, O1 D. F# o4 T9 N& Ethe line containing the\r\n"); ; g" h5 n5 F  ]1 {5 E& _
cprintf("cursor and moves all lines \ ; D% L" D& b" Z
below it one line up.\r\n"); 8 j( y7 ?0 T6 y, f6 [- L: m$ i
cprintf("DELLINE operates within the \
& C4 Y4 @1 Y, u  S4 t8 e- i7 Ycurrently active text\r\n"); & `( m" K5 S' m3 n
cprintf("window. Press any key to \
% H% u# w+ f  ]& J5 qcontinue . . .");
1 ~# d! p# [0 m1 ?gotoxy(1,2); /* Move the cursor to the
# ^7 [/ r/ \3 V6 J# M: P8 b0 ?" {  Esecond line and first column */
& ?4 C/ b1 h' {, |4 j& k1 rgetch(); </FONT></P><><FONT color=#0000ff>delline();
; F8 n1 p, k) c" ~" k9 a( Lgetch(); </FONT></P><><FONT color=#0000ff>return 0;
& b. P& {/ M% i5 R) b  j% I  i  B} </FONT>
# `5 Y$ T, u& `</P><><FONT color=#ff0000>函数名: detectgraph </FONT>, q: I6 s* s" A; a* F8 c$ A5 D
功 能: 通过检测硬件确定图形驱动程序和模式
5 H* _; N" |' b. o0 b( E- S4 M" j用 法: void far detectgraph(int far *graphdriver, int far *graphmode); & e% w- h+ V2 o# y, L. {! \, G
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>) L0 K+ p/ W% \4 H/ L
#include <STDLIB.H>
) [( J; c9 k0 K#include <STDIO.H>
/ C( n$ Y; g9 D4 \% N. Y#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ % ~& N, [; _3 G( ]* R+ [% \
char *dname[] = { "requests detection",
4 R. ^) U1 ~- h3 k& l0 x- Z4 J"a CGA",
) j  ]& Q; S6 I1 `1 x"an MCGA",
1 P2 t) x1 c5 q4 [9 x% w% z. o"an EGA", : ~# U0 g( Q5 d: {. z5 P3 H
"a 64K EGA", 5 |8 R, `$ @7 |7 O* d7 J
"a monochrome EGA",
( `& w: U3 ]7 }/ f0 d. k"an IBM 8514",
( W1 C  ~0 Q0 \4 c" h4 C1 @6 N5 |"a Hercules monochrome",
) ]4 h4 u* D. i* l8 G2 u! ["an AT&amp;T 6300 PC", - E  o  \$ ?  x. ?/ n' Y! D
"a VGA", % h+ G1 C, P; {* m
"an IBM 3270 PC"
1 C5 s+ {2 M$ d0 x' k}; </FONT></P><><FONT color=#0000ff>int main(void)
! B# z2 [( c. ?) u5 [, Z{
" w8 H4 V; j; B6 h& L/* returns detected hardware info. */ & q+ @, p2 S# x" `9 R8 R" ]" e8 Y
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ 7 u# d+ m. m  r; P/ N, n
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ - @/ |; {& ^* Q5 d) W( h* M! g% c
errorcode = graphresult(); ) [+ `! n$ b4 j/ o5 r9 |8 l' w
if (errorcode != grOk) /* an error + \% K6 R0 D+ v* x1 e: a  x: \' [
occurred */
! k; v) c  b4 S: i. j4 J% \{ " c3 G' y6 o- M  d4 v6 z7 u/ J2 I
printf("Graphics error: %s\n", \
4 G) @# `' S# a" F3 O$ o( c( @* V2 egrapherrormsg(errorcode));
3 K7 u6 U( ]- bprintf("ress any key to halt:");
3 t6 D5 q; x; C* s( f. L  B/ ?- Kgetch(); 1 C8 V( E7 T2 i( P- ^( k
exit(1); /* terminate with an error
3 I& M7 d0 [. ?+ S0 T: s$ ucode */ . k3 p' T7 i  _4 v* [
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
# O1 n0 E& p4 h6 h7 O. Rclrscr(); . r& t0 N" m7 N4 w8 q% K/ |
printf("You have %s video display \
2 I( n- I% z+ V6 s  @  X0 mcard.\n", dname[gdriver]);
4 \) ]( B- U4 M1 ]' eprintf("ress any key to halt:");
5 q% D! d& _. y: xgetch();
" {! c+ b) B; j  G0 i8 ]( w5 mreturn 0;
' S& o9 P/ {. ]# g, }} </FONT># ^3 o& c, K0 C  H

7 ]) t/ }2 _2 [4 s
! t! z+ w/ d2 u- P+ l4 ]</P><><FONT color=#ff0000>函数名: difftime </FONT>
0 ?5 g, ]7 v; i  w7 A, U/ I功 能: 计算两个时刻之间的时间差
2 j  T) W7 H! A) q用 法: double difftime(time_t time2, time_t time1);
5 z/ G- C1 }8 }程序例: </P><><FONT color=#0000ff>#include <TIME.H>
: D9 d5 p- L5 ^* i3 q. S/ X8 f  j7 f#include <STDIO.H>( j) L0 [9 {2 _7 x
#include <DOS.H>, [. c8 i6 L5 I. a* H2 s: t
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
4 r. C7 S$ O% ^* P: S{ ( N9 C) n2 p  B/ q' f1 J+ T
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
; x/ ~" X3 ~; W: j, afirst = time(NULL); /* Gets system 2 q. R# N! c8 e! y/ A# {4 U$ c
time */
  f* \* G* `/ D8 }% Fdelay(2000); /* Waits 2 secs */ ! T8 p; n' k. l0 D6 ^
second = time(NULL); /* Gets system time
: q3 X/ f8 D3 Pagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
% h& F/ d5 D/ Dseconds\n",difftime(second,first)); . Q& l# U& N1 S' W9 |
getch(); </FONT></P><><FONT color=#0000ff>return 0;
" b# J% W( w& o9 }& m} 8 r3 T7 B5 f" m5 w# ?* |
</FONT>
  o6 c& d1 z& T</P><><FONT color=#ff0000>函数名: disable </FONT>
' r5 s6 D5 h' G& h功 能: 屏蔽中断 5 F$ u% \7 k: a. ]0 f% t% O
用 法: void disable(void);
% l* y1 R! F6 L1 \) g" [程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
2 o4 V3 V7 X: H# X: Kroutine. You cannot compile this program + f% G& v; @; V. [7 {# s
with Test Stack Overflow turned on and - f6 q& p; M) V$ N6 G- ^
get an executable file that operates 0 L8 d7 B6 J" W+ N4 t4 }$ i; H
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
; Y3 S& G: y  z#include <DOS.H>  U( W1 n# f7 ?5 ~( Z/ }' T( S# Q
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
* X7 H# [9 W( sinterrupt */ </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) : K: J: H; z( M+ l2 r
{ " p$ A3 u9 ]6 L; B
/* disable interrupts during the handling of 7 k+ O/ l' d0 e
the interrupt */ 7 Z2 D$ [4 K- T8 w! p8 M; x. z
disable();   M: ~; K5 V$ R- I$ X
/* increase the global counter */ 6 q8 Q2 }& [, h; ]7 t* B" d+ \
count++; % \* x; G3 D/ `- }. \) B
/* reenable interrupts at the end of the 8 l* e4 `5 r& `; u# W3 U! Y& y
handler */
2 q4 |' v+ ~' L! a# I* @4 ]0 ]6 D$ V- Venable(); 9 E/ y$ c3 t- K( @" t$ P3 n. A
/* call the old routine */
3 p/ D+ O4 {$ @6 o$ t! f# Z9 goldhandler(); 9 f! ~* c7 S! B4 i3 S. j+ a1 |
} </FONT></P><P><FONT color=#0000ff>int main(void)
9 E- F. j# y+ |; g8 `+ x{ . q/ _; n% [6 C. f" q: C! a9 f
/* save the old interrupt vector */
- J2 \; i1 q2 ?oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ , k# @/ I# e/ X1 s) _' O
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 6 R- J$ ?6 [. W1 K, Y) e" a2 U
while (count &lt; 20)
7 q) h, i+ d/ Z( L  Z# Cprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */   ?# q2 M3 A. [7 u( @( k& C! e, f
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; & X: z) r% K0 b6 }+ q2 \, x
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
% K9 u5 R. w; a. P7 y9 t& ^9 R功 能: 将两个整数相除, 返回商和余数
5 B+ ]! G% F3 x) v' c. Y用 法: div_t (int number, int denom);
& I  ], @6 S/ A/ W$ D程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H># {# L7 o/ f3 I* u# h
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)   T2 S- u4 w$ O3 @- P8 \4 [) U# t: |
{
) D: W, b  _5 Cx = div(10,3); # U- E$ a# G% Z- w( d* w
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; 2 c  r( N" U: U+ t  \+ D
}
4 a$ I$ h; E! s* X6 ?, x4 Z/ S$ i</FONT>
* S/ }: z- B; X( l( P/ H</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>. ]+ Z  C/ {8 F6 M$ q' W/ Z
功 能: 获取扩展DOS错误信息 / o' @+ N+ e# C' ~) F. s
用 法: int dosexterr(struct DOSERR *dblkp);
- t3 u" Q, T% \0 O  s  r程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
5 `( W" J" k6 c- H0 K8 ?& n3 |& O#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) * ^6 |' |* p2 r% y
{
: ]2 d& f' ]: X1 E6 _- d/ HFILE *fp;
4 O- A- J1 V% R2 g9 a$ [struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
- m% X2 X3 z* t+ Y, P* T) o; a) yif (!fp) perror("Unable to open file for 7 o3 ?1 E: t: ~- L( R
reading");   t4 {7 s) |/ f3 V, s
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ ! E5 ~: y% X8 b$ _9 T8 y9 m$ N
information:\n");
; X2 a/ J0 f6 yprintf(" Extended error: \ ; q% A5 A% _- z- n$ O* l! f( A% H; z" [
%d\n",info.exterror);
* k) p1 z  x7 F: {printf(" Class: \ 3 k/ E3 l4 J2 k' L" B6 h
%x\n",info.class);
# h; c; A$ V, o- }printf(" Action: \ 8 Q. a2 l5 F, g! x- _& @- q
%x\n",info.action);
# n" T6 t1 c9 U" C* \9 lprintf(" Error Locus: \ ' t9 I# [/ A1 h; m4 Q' v- p1 H' j
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;   C: A0 y! F; s, R
} </FONT># h' o( \& T* W9 @
- d8 d+ B. U. l& J3 ]3 d( I
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>  }& `" q! V: E( z) }0 f3 v
功 能: 转换日期和时间为UNIX时间格式   F8 r% c! B. ^. r
用 法: long dostounix(struct date *dateptr, struct time *timeptr); 1 S  b2 ^/ Y$ e" U
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>" v! a0 Y1 W3 u2 G( v" A  d: W* }
#include <STDDEF.H>3 o9 }8 e' b: O) b/ l
#include <DOS.H># y4 V7 t- F3 \2 e# C
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) ' z2 y6 h8 ^7 L
{ ; C- g+ P3 X5 c  P2 `9 |
time_t t; + f2 _9 R5 c& F
struct time d_time; * V* q# |( g! f
struct date d_date;
$ ~- x: ]" L/ j8 N$ \0 N% z; jstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
8 s- S$ W2 M2 k% {4 n  o6 U9 [gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
6 y+ z% B/ x9 ~" m8 I  P& i0 @7 klocal = localtime(&amp;t);
' w$ p% N- Z" v0 @; G* p0 jprintf("Time and Date: %s\n", \ : E1 E/ \( \' N0 m$ }
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; , H/ \1 }' I7 i' Z' O2 G  w- ?/ F
} </FONT>) L7 C& m9 C" L" r# T0 M  q

. h/ R# s- Q  W, ^% Y  T9 X</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
& v4 B5 B8 I3 C5 Z$ E% a* a! B功 能: 画多边形
& Y( \# x) z: W0 ?7 h6 r用 法: void far drawpoly(int numpoints, int far *polypoints); ' D2 X% s) ~& @) Z# V
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>6 c$ P% z) Y% q* i
#include <STDLIB.H>- w6 W7 F2 Z# N$ z; ?* L9 V
#include <STDIO.H>8 S3 [% b+ P& u
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
# e' q5 d$ E" |9 P3 l8 m{ ) \6 U6 v" H; O$ v7 \# B
/* request auto detection */
8 m1 Y3 B: J* |7 _int gdriver = DETECT, gmode, errorcode;
7 E, H9 p3 X* W1 ?# ]int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ ' Y$ r% F& S2 A* ]# }
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
8 {$ v" ^9 j: ^$ pvariables */ ( P' W$ F' c1 D; a* R
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
5 [, b+ y1 L: h2 terrorcode = graphresult(); * B/ U9 w, T( x
if (errorcode != grOk)
$ C$ c, O* c, S9 c7 Q" k/* an error occurred */
( w% N3 a7 `6 [+ X/ A" ~{
; R4 S( w9 W2 \1 Yprintf("Graphics error: %s\n", \   U: V7 D" Q  z; O# n% q
grapherrormsg(errorcode)); 9 o6 C% M* Z& q; B
printf("Press any key to halt:"); 7 T! G; b) S! c# Y; G( P9 e1 y
getch(); ) Q4 a/ d$ L9 A
/* terminate with an error code */
" K- r8 |# ]5 M* E' lexit(1); 5 |9 D9 [: A& M& ?; _$ A4 d
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
8 ^! @3 e3 g) B/ @% M$ s& Y: Y% Imaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ - @* H% ]  [7 S6 e/ `
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 5 ?& [' Y! M5 e# B( E' E( O/ I  O
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
( \4 C! s$ `) B$ [" J8 W5 r- l% Npoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
# ~! F* D2 R, H' W& H# g% B, |poly[7] = maxy / 2;
6 ]5 i6 Q1 j( B1 a. j- H; E/*
3 _4 i  c& {$ p/ I6 o2 Idrawpoly doesn't automatically close
' Q* M, z7 C( Cthe polygon, so we close it. " w3 u3 T2 _+ e0 Q% y6 q
*/
* A& K6 W8 v9 W; q  w9 @7 Wpoly[8] = poly[0]; + L0 m+ x9 [4 f/ @: s
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
, i# S2 \* V1 U( X; }drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
$ \$ I& a5 t1 M" ?. u3 agetch();
5 T2 Z% E# u6 }3 X- Fclosegraph(); 2 B4 i9 z' ^, d, j$ _& z: V$ V
return 0;
8 }" F' A' K, y5 Y5 e# f} ! ^/ s6 I8 C( V9 n' e( s
</FONT>! W& }3 P# D' j# ^; z6 \
</P><P><FONT color=#ff0000>函数名: dup </FONT>1 a1 ^% j) h$ q& _. i3 x2 i( r
功 能: 复制一个文件句柄 6 b: G& B. W/ k3 x' F/ Z
用 法: int dup(int handle); ' O+ `& Q+ T3 m; n$ j
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>4 ~0 m' U4 W4 S# o
#include <STDIO.H>
2 C8 O6 n' g/ a. U6 S& ~* q! ?#include <CONIO.H>
$ b: E$ Q: N7 H" t' J#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) 1 W. `: \, a6 G
{ $ ~, f: q- d- u0 O$ E/ a* Z
FILE *fp;   w* O$ @# O, Y3 F  A; D' I; [) N
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ ( S# Y! Y% L/ ~' b
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ 8 R" _* C4 H- J5 R5 P7 V4 [
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
% c: W4 B8 _/ W/ L5 ~printf("Press any key to flush \
- ]& G' C2 M4 J  cDUMMY.FIL:");
; q; Z' j) }$ {' [getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
) F' K% i9 J# |( f, m, Wclosing it */ ) \) F2 ~: n. \! A1 ?7 z
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
. k5 B, M# B5 Q( r- D4 o/ ikey to quit:");
( F* X' l( m% @% g6 V4 agetch();
$ N" k7 n3 z6 v% vreturn 0; " O  ?: r! Q( ]" L0 H
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) / X: r; V( [6 w  A: ~
{ 9 C, [. \  }1 [) J
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ 8 B1 c& f* n& R, x% h
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
5 H' h' s; ^" a# nduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the ( L$ A( }. Y+ i& Q* Z( C2 B! T
DOS buffer */ . Z( P# A8 c: L9 m- P
close(duphandle); : I  A: e! a8 d; S" n" l
}
' L' n- e; `, c2 A# y7 O; K6 a3 u3 t/ f) x6 E  N6 w, _$ s
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>, I, f) Y4 }: X7 E& @2 u0 x
功 能: 复制文件句柄 6 I, @+ m( Z- @  u2 y: f
用 法: int dup2(int oldhandle, int newhandle); ) ~5 e7 N7 ^$ _' T0 g5 {! M7 T
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>  I/ Y8 b  R* J% C3 G3 {
#include <STRING.H>
( u& a' D. G/ [3 y5 w8 B8 w1 \#include <FCNTL.H>0 j5 `7 V/ t2 u! I- @
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 4 Z$ f, b$ `0 P+ w0 a2 @% \" r
{ * V1 E9 A& c! W7 }% ]! r
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
- D! q1 u8 h2 Ichar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
- s% x; `" W/ T# v( p4 Z6 J$ g- Hnul = open("DUMMY.FIL", O_CREAT | O_RDWR, ( Z7 O) {4 ^1 i( H# p+ v1 o, u, V9 S
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
4 E: {; Z2 J) Q% E' Goutput */
9 `5 F' l* O: j2 r, T2 P' koldstdout = dup(STDOUT);
1 _: u7 f) I7 y$ _. g% C/* ; S9 S) M6 I! Y/ L% g' C. l' [
redirect standard output to DUMMY.FIL 0 `3 }* a: |7 K! K( T# R, |* r
by duplicating the file handle onto the 7 E4 h% p# ]5 l5 s, [
file handle for standard output. 8 I0 J9 n- c# K) ~
*/
5 [! S' U* F' e# V6 n3 `2 ~0 ]0 w" ndup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
, @$ q# M1 I& h8 X6 @( o9 l0 a# nclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
5 n' j3 z& g& m/ _8 V9 Bwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output 0 C& L5 `( D5 M' O  C. B# q
handle */ 9 X1 R2 N) F/ u* U
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ & I, ]8 u) Q# j0 Z
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
+ x4 T8 p; c* Q$ F- J} " v" v9 I7 Z/ y/ B! o9 T( {5 T
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-23 09:00 , Processed in 1.311555 second(s), 56 queries .

回顶部