QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2062|回复: 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>
3 ]3 i- b! ?/ ^* B2 d% P</P>
3 F$ @0 y" n# Z# p) H. F  g% k" N3 Z2 D7 |! P6 [- {& S

5 q, y6 V3 x0 d/ t- m% [4 M, f<><FONT color=#ff0000>函数名: ecvt </FONT>- k$ i& ?0 K' g/ m
功 能: 把一个浮点数转换为字符串 4 Y; j0 L0 s1 u9 K
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
* l2 ~4 v* U; N% x. J- J) X2 b程序例: </P>- Q) L5 S( i7 z) P! t, Z6 f
<><FONT color=#0000ff>#include <STDLIB.H>6 u) B8 k' D5 O1 P$ i/ S7 q
#include <STDIO.H>( H/ J, ?8 {& n4 i6 t; u
#include <CONIO.H></FONT></P>
% J" X4 G/ U( E& I' Q7 V( C7 S( J& V<><FONT color=#0000ff>int main(void)   c8 |  b5 R$ t2 O! F
{
, z* \4 f: s9 cchar *string; + R! @* C2 i6 p7 D  B2 z8 a
double value; % T+ n, i7 ]" s! X6 o
int dec, sign;
9 V( j* G9 k' L3 ?% ^6 l. h4 r& m! Gint ndig = 10; </FONT></P>0 ]; F( k5 r& _2 I0 v
<><FONT color=#0000ff>clrscr();
9 H$ G1 G( i8 Y! Vvalue = 9.876;
8 g# q9 [  d: Fstring = ecvt(value, ndig, &amp;dec, &amp;sign);
; Z. C- C$ k/ F$ X; ]3 C# dprintf("string = %s dec = %d \ - v0 M. p- v' }" t3 H6 {+ N
sign = %d\n", string, dec, sign); </FONT></P>) }6 b, ?9 y5 Y' @: |
<><FONT color=#0000ff>value = -123.45; * j( ^6 G) S& U  y8 l8 \
ndig= 15; 2 B- @* S! j4 X" @' R7 L8 f# o; m+ w9 v
string = ecvt(value,ndig,&amp;dec,&amp;sign); 1 j; P, j) l9 |  d$ k2 |! O
printf("string = %s dec = %d sign = %d\n",
1 Y5 X: p3 ]5 \) ^3 b/ Q" tstring, dec, sign);
4 v: O, s6 Y) O: I</FONT></P>) M" ]8 r. R. P5 b5 V# R
<><FONT color=#0000ff>value = 0.6789e5; /* scientific 5 ]2 |4 p* G3 X" u& @# a" q
notation */ ' I7 L7 e6 L6 O7 U$ I  w( S
ndig = 5;
, s1 G' Z- K5 b9 B  G0 \: vstring = ecvt(value,ndig,&amp;dec,&amp;sign);
: o" C. s8 [1 \/ A5 cprintf("string = %s dec = %d\
  y8 Y1 H: f9 t5 t/ c4 Wsign = %d\n", string, dec, sign); </FONT></P>- A* ~& R; ~+ Z' M
<><FONT color=#0000ff>return 0; % I, k( _. g" Z' B
} </FONT>& ^/ `  K$ d$ a9 c9 `
/ F3 \7 ?' Y. \2 t
</P>5 n( p1 G! x: k6 L5 u
<><FONT color=#ff0000>函数名: ellipse </FONT>
  k! ^3 l  t: w( Z+ e功 能: 画一椭圆 5 u8 ^3 j! b0 M& m
用 法: void far ellipse(int x, int y, int stangle, int endangle,
# \5 b" \+ s, w# ?2 Nint xradius, int yradius);
3 }" A9 m1 t) a# X5 K程序例: </P>% U# h' B) ~/ j' _3 _( F* e
<><FONT color=#0000ff>#include <GRAPHICS.H>2 a4 I- Y/ M4 R; G
#include <STDLIB.H>
3 B& H1 r+ p5 |& i: u% X#include <STDIO.H>! o: R- B6 F6 n3 N( T8 s
#include <CONIO.H></FONT></P>, g  f8 C2 N$ C$ ?' B% [
<><FONT color=#0000ff>int main(void)
: y+ o1 K! }/ i0 f6 s/ t{
0 e) s% s& V4 A. |) i! {3 h) n/* request auto detection */ * V: i0 }8 L2 N" |. w0 [2 M
int gdriver = DETECT, gmode, errorcode;
; y6 C: y- A. d* {6 vint midx, midy;
1 e3 O& F0 p# ~7 M8 ?3 Uint stangle = 0, endangle = 360; . \/ D+ S, L) I. ?' Y8 Q
int xradius = 100, yradius = 50; </FONT></P>) ^( r/ Y8 o6 b
<><FONT color=#0000ff>/* initialize graphics, local variables */ # }$ m6 E. \: w; ?% S2 ]
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% y4 M) Q) f1 z% N<><FONT color=#0000ff>/* read result of initialization */ 7 t& U$ O- c/ ?! f3 `
errorcode = graphresult(); 6 x! j2 }' A; T
if (errorcode != grOk)
' c6 v$ i: l" _2 n8 d$ D/* an error occurred */
- I: ?" [: q7 J% z5 N{ " R  s0 n$ w; [4 I) G6 V
printf("Graphics error: %s\n",
+ H% E9 B4 \2 s( Hgrapherrormsg(errorcode)); . e/ g$ s4 ]) h$ }0 S  P
printf("ress any key to halt:");   W8 V' {' [1 y$ r0 g
getch(); 5 w: L0 y6 T: m- E! v4 M
exit(1); 3 s: t8 L5 c& B* p% v/ w6 ?
/* terminate with an error code */
4 q8 i8 H- U6 B' H- |) d} </FONT></P>. N+ O1 C0 A: ]$ X8 M, }# t* O$ N' v
<><FONT color=#0000ff>midx = getmaxx() / 2; 5 f* T  y% ?3 V! Q  R& m, v( M
midy = getmaxy() / 2;
4 Z; K" x$ z" msetcolor(getmaxcolor()); </FONT></P>
0 a. ]6 @* H9 t<><FONT color=#0000ff>/* draw ellipse */ : z2 f% O# ^9 j
ellipse(midx, midy, stangle, endangle, ! I& ]8 m3 X8 v1 `: v. x
xradius, yradius); </FONT></P>
5 t8 V; {& B  v<><FONT color=#0000ff>/* clean up */
* K$ R8 _3 _$ d5 s) o, M/ M" Q5 \4 Lgetch(); 8 r% H4 p( K! m
closegraph(); / e4 d( ]2 p- J3 z5 a" q. X) B' u
return 0;
7 A& Z0 J/ }+ [1 X! N8 C3 @  t} </FONT>8 E* f: V3 \4 p# b8 o- @6 ?. Y7 n

6 r6 p3 o6 o3 N2 `" S</P>
2 t: [; r. b9 P9 L2 w: k<><FONT color=#ff0000>函数名: enable </FONT>! d+ y+ U, `, F$ s2 A; e* E
功 能: 开放硬件中断 ; H" Z9 T; g, }% i, f% d( r! @
用 法: void enable(void); 5 x9 y2 B! D( ~' U4 F
程序例: </P>
% B: \) X/ ~' a8 }" J$ c6 I<><FONT color=#0000ff>/* ** NOTE: 0 r' K4 V9 K8 v' P8 Z8 |
This is an interrupt service routine. You can NOT compile this program   j- [; v/ P% P; U1 R$ ?) a
with Test Stack Overflow turned on and get an executable file which will + a0 g) [8 G  k* \& Z( @
operate correctly.
$ L4 d. {8 o5 V- W$ {- b*/ </FONT></P>8 _' R/ y* ^+ Q
<><FONT color=#0000ff>#include <STDIO.H>; z1 ?5 S- a/ G9 L# L
#include <DOS.H>
# ?' m3 i) B& x+ n& l; e# f#include <CONIO.H></FONT></P>5 J8 I# N. f7 H  H  D3 A
<><FONT color=#0000ff>/* The clock tick interrupt */ 5 m2 f; s- E% w9 s7 c: u& i
#define INTR 0X1C </FONT></P>' [! k- D8 f3 p& ]& V% K
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
& K! g% G/ w/ n3 r" g2 X/ I$ C<><FONT color=#0000ff>int count=0; </FONT></P>
2 |  \; e- s4 _2 m& c2 U7 X<><FONT color=#0000ff>void interrupt handler(void) 5 m+ {9 j" h( B# w8 ]; H, e
{
; y. N! y- v) x# t/* , V: G" O. d- b7 ]  E
disable interrupts during the handling of the interrupt
9 f# T" D, G$ n) |! M- u; l' O*/ / [5 l; ?/ R& |" x& O( ?
disable(); 1 @9 I- [. m9 h, n  h
/* increase the global counter */   L8 ], T  e" z  w/ x& c5 c
count++;
0 P9 }5 K* d0 C* z) x- X; s/* 3 c3 W' |  Z: n+ i. i6 |
re enable interrupts at the end of the handler * ?9 J, p6 ]" P" F- R
*/
  X9 w5 s/ _, J& m* K3 b- ?2 Q* t. penable();
- s! W, ^0 n+ @; ]9 Y8 Q: i/* call the old routine */ 8 e5 F1 f' t5 H) i' ~' |+ m7 x# a
oldhandler(); : H1 v/ C6 r2 U6 ?1 W% c
} </FONT></P>
9 W. |* M8 S6 T5 V<><FONT color=#0000ff>int main(void) % a4 ~4 {, c2 e, ~
{
. O: g0 j" B" _/* save the old interrupt vector */ " h* z+ e1 r8 b
oldhandler = getvect(INTR); </FONT></P>: w. x* H* E" m( V" K" e0 h
<><FONT color=#0000ff>/* install the new interrupt handler */ ; q4 Z; ]' x. W$ r+ S% K! @4 p
setvect(INTR, handler); </FONT></P>* ~, A( I7 V8 Q1 @3 F$ x
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
1 h! y6 k/ v& ?( f+ p" Nwhile (count &lt; 20)
& T" g' l9 |9 ]% d0 C9 E6 }. }printf("count is %d\n",count); </FONT></P>6 @5 d) d. ]- B
<><FONT color=#0000ff>/* reset the old interrupt handler */ 3 A! R4 C" `1 j9 p  d+ x; N
setvect(INTR, oldhandler); </FONT></P>4 L$ t, z0 M3 P1 b( K3 T4 u
<><FONT color=#0000ff>return 0; 7 [* k8 y7 x2 v: ?: r9 a$ v
} </FONT>  L' w7 ]# A! r- O
7 W/ D! _% k( t5 A% E4 a
</P>/ G- r5 I0 [0 C  t+ l
<><FONT color=#ff0000>函数名: eof </FONT>
4 n# g3 j7 {# C1 k+ \0 X7 V+ _功 能: 检测文件结束
0 h  `3 m9 Z* ?! Z) M, F, q用 法: int eof(int *handle); + X% K* H) p+ W6 z; g. V
程序例: </P>
+ d% x2 I/ m5 B' E# l9 g& p8 W<P><FONT color=#0000ff>#include <SYS\STAT.H>. c4 R1 o5 m3 x3 m! O8 S* n& ^
#include <STRING.H>$ }  c# s* K0 }& b& R# w5 c# @# ~
#include <STDIO.H>
& _: q7 Z& ^4 D% L4 P) V/ l#include <FCNTL.H>3 y" n* m9 E$ |) E9 B$ Z0 h
#include <IO.H></FONT></P>9 H' [) l) C$ Y0 Q$ V2 I
<P><FONT color=#0000ff>int main(void)
) `. m" F9 n7 M, Y! t: g{
# E" ]% \( S0 n  n# eint handle;   M3 n  Y5 l: l
char msg[] = "This is a test"; 0 Z  Y; `7 v. m/ Z& z
char ch; </FONT></P>
1 L! K8 x, A, E$ Z' e5 ^6 F<P><FONT color=#0000ff>/* create a file */ $ e4 i* X+ w# Z" {4 X1 }9 H
handle = open("DUMMY.FIL",
) T! s# s! y6 _* Y0 ], K, V0 }+ MO_CREAT | O_RDWR,
5 ]; c: G6 ~; {# LS_IREAD | S_IWRITE); </FONT></P>4 y  r" C. q# k. @+ s2 w, A3 d5 C, ?
<P><FONT color=#0000ff>/* write some data to the file */ 8 p+ c  ?5 i2 D7 n! I
write(handle, msg, strlen(msg)); </FONT></P>
# k8 r# E+ G- K# o/ {+ Y/ \<P><FONT color=#0000ff>/* seek to the beginning of the file */
# n; `' \/ p1 u* Vlseek(handle, 0L, SEEK_SET); </FONT></P>8 k" F1 l; f8 {1 O
<P><FONT color=#0000ff>/*
3 }' F9 X* C. ]  Freads chars from the file until hit EOF
! g2 t) d1 [$ _1 q* p2 l. }*/
: c8 ~9 O" H3 v4 fdo
+ i; N6 d( {$ X+ _% A4 Z. D{
# m: B) N+ P% w( [0 fread(handle, &amp;ch, 1);
0 e# ^$ k# K4 j! Oprintf("%c", ch);
3 p& _. I" H* i2 A} while (!eof(handle)); </FONT></P>6 u% v0 q1 A( x; d
<P><FONT color=#0000ff>close(handle);
, e: u  @7 h; G( ]  I6 o7 v2 yreturn 0; 5 b: H$ _; Q3 D9 Z8 m* K
} 1 S9 g9 k8 `& G7 @
</FONT>  K5 s. S5 g8 J
</P>' @0 Y( A! W4 T) @
<P><FONT color=#ff0000>函数名: exec... </FONT>
0 t( H' X9 U/ B& [* S6 W, [功 能: 装入并运行其它程序的函数
4 _9 e. _8 j6 X5 y$ b# @! F% C# f$ C用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
. [; x5 d7 p# }& K$ lint execle(char *pathname, char *arg0, arg1, ..., argn, NULL, , d; o0 M8 U: w8 {$ L$ e
char *envp[]);
" B- A: N: L8 i4 bint execlp(char *pathname, char *arg0, arg1, .., NULL); 9 C: a! z# l7 l" m) Z
int execple(char *pathname, char *arg0, arg1, ..., NULL, 1 g5 d! h! v  Q/ l7 c
char *envp[]);   Y8 r4 j- V' s- r% Q# J
int execv(char *pathname, char *argv[]);
; n( o: B# |4 \8 d- i/ f" Tint execve(char *pathname, char *argv[], char *envp[]); / ]- P( `  D$ J( X% ^8 I
int execvp(char *pathname, char *argv[]);
9 b& w8 A( e" f. `int execvpe(char *pathname, char *argv[], char *envp[]);   a4 p9 h' n, R$ m
程序例: </P>
! F, `/ ~7 o8 R3 S! s8 t<P><FONT color=#0000ff>/* execv example */
3 C5 W5 R" v! |8 V. [#include <PROCESS.H># _! O7 V% W: B: \1 S5 i
#include <STDIO.H>
2 X7 _7 Y  U; N8 }5 w#include <ERRNO.H></FONT></P>) x  f. [" ^8 ?# q' H
<P><FONT color=#0000ff>void main(int argc, char *argv[]) " n- `' _+ B/ g1 l
{ / e5 Z7 {7 \, n' `
int i; </FONT></P>7 g" o: [( ]5 y; s5 _* u$ Q6 b
<P><FONT color=#0000ff>printf("Command line arguments:\n"); $ D+ R. X4 w) ^6 m8 w8 s8 Q
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
9 B2 d: [2 X. V4 g) f<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
, a- H7 C+ o- b' K& Rexecv("CHILD.EXE", argv); </FONT></P>
0 Y  ^6 T' [& J* Y0 T<P><FONT color=#0000ff>perror("exec error"); </FONT></P>& f; ?$ F+ N/ s  H: ?, f" m
<P><FONT color=#0000ff>exit(1); & g1 J9 @3 g& U2 R
} 4 L# l+ v  v: k" `8 U( x
</FONT># k1 P, b+ P: h9 G2 [
</P>& [/ S: f& v; G) z
<P><FONT color=#ff0000>函数名: exit </FONT>  E, g# N. V' ]
功 能: 终止程序
* C- O& X9 v, C8 j$ {+ U; l% x用 法: void exit(int status);
( |) s5 M1 z' \$ m( @& m程序例: </P>
, y' d% e8 ?4 j<P><FONT color=#0000ff>#include <STDLIB.H>
# n- b$ N; y5 c: |- E6 b  _, a1 q& Q#include <CONIO.H>
4 |, X9 h8 T) i: S4 ]. L#include <STDIO.H></FONT></P>
( w& G# p0 ?1 w* I, ^<P><FONT color=#0000ff>int main(void) 8 u/ O7 \$ o" [! ?# P
{
+ h( i5 l# G% J# w+ Nint status; </FONT></P>! Q( R* }6 H+ T- T+ o4 V" E, W. v
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
9 K0 l8 z, e- w5 I3 {, ostatus = getch(); : Z# G) v- P# e9 ^- I+ ^
/* Sets DOS errorlevel */
8 I" Z5 g- M8 Mexit(status - '0'); </FONT></P>/ A8 X# X2 G- b4 O# v
<P><FONT color=#0000ff>/* Note: this line is never reached */
6 [; B) l0 L- i+ _% X; L% c4 {return 0;
( d# E& D$ b  j2 {$ M- c# _5 A7 {} " s, r8 a& e# g, _% T  B! n
</FONT>: m3 f- e; c1 O
</P>
: M2 X( U5 l0 T8 ?2 @/ B" q8 Z<P><FONT color=#ff0000>函数名: exp </FONT>
/ \% z! S5 N) z5 ?功 能: 指数函数
8 l. Y0 }9 B; U& a" V1 C; S用 法: double exp(double x);
; l- Y* ?+ `. p; W/ y3 B' [程序例: </P>
/ `" T6 c" e1 I# @8 _% y<P><FONT color=#0000ff>#include <STDIO.H>
( `1 P& n* [1 r$ l# o, K# {#include <MATH.H></FONT></P>
$ @- @+ j5 {; w<P><FONT color=#0000ff>int main(void)
; m- }; `8 z4 ~. K! P: {{ 4 ]3 I, s8 w" X" e5 a1 ^3 }
double result;
8 ]$ |3 y; U) g' Idouble x = 4.0; </FONT></P>, ^2 b; Z5 Y, `/ s! H' b* u
<P><FONT color=#0000ff>result = exp(x); ' I4 R9 J* [6 I9 O6 a
printf("'e' raised to the power \   }' C" w3 T1 |4 l
of %lf (e ^ %lf) = %lf\n",
( u2 \+ ], P, u$ L% Wx, x, result); </FONT></P>
. u, t) B7 S9 U' u<P><FONT color=#0000ff>return 0;
1 ]; G3 a( ^' m5 u0 A}, W2 G0 j/ N0 ]$ i$ B$ P
</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>; ^; K/ N4 M# L3 z' |7 E
</P>
, O2 c5 [0 I. U: V<p><><FONT color=#ff0000>函数名: delay </FONT>" _( ]$ X- K, ]6 W
功 能: 将程序的执行暂停一段时间(毫秒)
+ L) g4 x/ y) h3 q2 R用 法: void delay(unsigned milliseconds);
4 n$ R5 g2 i. G* I- L1 J程序例: * N$ f! e0 G( v3 `& _9 N
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ : P/ S; a; U) R* }4 v+ }
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
/ a; r% R! v! [+ c; H0 }4 v+ b$ l6 u{
" i0 y5 n6 n" ?sound(440); 4 K; P( n+ X5 f/ D8 {% I
delay(500); ( L* j6 T8 O0 q, o, r4 k4 ]. t6 r
nosound(); </FONT></P><><FONT color=#0000ff>return 0;   \5 F4 T$ Q) |& u! Z+ x
}
- t( ?+ g  B! e! t8 {
8 W% [3 t  T$ `* N$ J& n* r</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>0 x3 s: P1 C. d
功 能: 在文本窗口中删去一行
  W/ _' D5 K6 h; H! [用 法: void delline(void); , ^6 i/ G. n% @3 e/ x- s. d
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
$ y+ W8 y  b8 u! d( g: ~5 z{ 0 i2 \: |5 D+ H) |1 H( k* o
clrscr(); : b! K5 u' I) [
cprintf("The function DELLINE deletes \ $ j! d' i- Y7 @) F! o
the line containing the\r\n"); ! v. f" y% }7 B. G( v$ |
cprintf("cursor and moves all lines \ 9 I5 x- t# K! O5 d. X. F
below it one line up.\r\n");
8 h0 s: ?9 N$ q  z! Hcprintf("DELLINE operates within the \ ; ?6 D! W+ H: Q7 z' D! C
currently active text\r\n"); ! P  N: ?( F2 w+ `' O+ z
cprintf("window. Press any key to \ * e& U' F0 c7 F5 X
continue . . .");
5 u+ c" f1 I$ A2 {gotoxy(1,2); /* Move the cursor to the 8 Z* P7 N" _/ J3 B, R, Z% U
second line and first column */
+ p) `. V3 t) F! R' O2 L/ H$ h8 ~! cgetch(); </FONT></P><><FONT color=#0000ff>delline();
/ x* d& B" U- m( q6 Wgetch(); </FONT></P><><FONT color=#0000ff>return 0; 0 Q2 z( D7 ]5 J7 s
} </FONT>
% {) }* f6 H* ?! S; R</P><><FONT color=#ff0000>函数名: detectgraph </FONT>2 s& |+ [+ c! y: Y) d! E
功 能: 通过检测硬件确定图形驱动程序和模式 ' @2 M; R9 k. J1 z
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
  J, v4 J9 c/ d9 o程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
) t+ Z" E& g: z7 o#include <STDLIB.H>
) B. s2 X* j* Z0 f  m0 y: @$ Z#include <STDIO.H>+ ]' B7 E" g& e( U! C' F8 _' j6 v
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ 0 }4 }/ k/ j! Z, g+ L* e
char *dname[] = { "requests detection",
2 a+ s) o, C# I: G* x' ~2 |* i6 x"a CGA",
, V; ?. S' ]7 ~) w# T8 V"an MCGA",
# u/ f# a. S+ x4 U"an EGA",
& U9 \0 v! t# \$ k' d# D$ u) I"a 64K EGA", 6 G+ g+ U& o9 v0 ~8 s2 R! p
"a monochrome EGA",
2 N. F. z/ M! M4 i" T% L* i/ ?"an IBM 8514", ! F( Z8 }& d7 k% I  i1 A2 i/ U3 Y
"a Hercules monochrome",
. F+ f1 a2 Y2 L, B) W"an AT&amp;T 6300 PC",
! |  F, C1 Z* U4 |7 o* |3 Q3 Z6 j"a VGA", 8 J5 j" |& k& O' y2 P! g; K
"an IBM 3270 PC" ' K% y/ l# T9 w$ h5 Q
}; </FONT></P><><FONT color=#0000ff>int main(void) - l7 r8 |, T/ Y) t/ R
{
# z$ `  B1 S  G1 w9 e: N/* returns detected hardware info. */ 7 d" F1 o( G, h7 S+ s9 K0 X
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
3 K) h8 v9 q6 B2 ?8 e& @- C6 odetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ 3 I5 M# M" \% ~9 ?1 o8 `
errorcode = graphresult(); 4 f" ]4 I7 a$ `+ g, |
if (errorcode != grOk) /* an error # K; Y( w8 H: e0 w( V
occurred */
2 P4 U/ g7 {4 g$ D0 z+ ]& J{ % _: S. k$ \2 G6 C  m4 v
printf("Graphics error: %s\n", \
8 s( F% R% J  c0 O: h. B- Mgrapherrormsg(errorcode)); 5 R& y+ }1 }# I  n. j* j
printf("ress any key to halt:"); , r6 m- b: d9 M5 F; w# \7 ~% x. I
getch();   y7 S" ~2 {' `7 z4 R
exit(1); /* terminate with an error
8 z  D6 w; M$ n. a: @7 xcode */ . h6 i. {! e+ e% D
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
6 H2 F8 W( u$ d' Y# `0 [clrscr();
1 y5 s$ O+ K8 Oprintf("You have %s video display \ 4 Y* u. w6 H9 O" T: d
card.\n", dname[gdriver]);
3 X. V$ D0 w$ A0 ]& ~0 R7 Xprintf("ress any key to halt:");
5 u, C9 U* M, `5 b; |& D- {" Agetch();
. y4 u, K5 p3 V5 V( ?9 Oreturn 0;
4 h4 V/ |) w- g2 @# M} </FONT>
$ ?" ^9 l, ^! y. f+ E- ]3 Y; K1 w& t5 e, a. n& W

2 V' }/ [6 L/ N* _% O</P><><FONT color=#ff0000>函数名: difftime </FONT>. _* T  e% O; z. Q6 B7 ^
功 能: 计算两个时刻之间的时间差
9 H/ I3 k# C1 k# j& \0 q0 K- U* S用 法: double difftime(time_t time2, time_t time1); & W6 w- k6 t% L1 j6 W' a
程序例: </P><><FONT color=#0000ff>#include <TIME.H>5 H' O" n5 I$ C3 s
#include <STDIO.H>/ I+ w5 l3 {6 p) f3 d
#include <DOS.H>/ r2 ~: o# T- P+ i, y
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
8 Z& n1 F) @8 D, F{
# q7 V# i4 p- O+ A2 _) }time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
( y) ~! l+ O# o  b' _1 r' Ufirst = time(NULL); /* Gets system # |6 u8 E( w7 D% r
time */ ; U6 H% B; x5 b0 {3 N6 u2 y" {
delay(2000); /* Waits 2 secs */ + P3 w9 l: c7 d/ c) u
second = time(NULL); /* Gets system time ' y/ b3 H0 v% V- q6 I8 q4 j
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
+ [4 A* z: \8 L! k5 _) Vseconds\n",difftime(second,first)); / b! M# O8 K9 }" W
getch(); </FONT></P><><FONT color=#0000ff>return 0; 0 i7 y8 @% z! q7 g5 u9 a0 o- G
}
/ h: ~  d1 X# Z2 L</FONT>0 ]. I! r+ l5 Y* l: W7 W: V/ F* U
</P><><FONT color=#ff0000>函数名: disable </FONT>
$ ~5 h5 U: y3 l) k3 a$ }功 能: 屏蔽中断
7 H. h+ T: H" r# X  m+ A4 \用 法: void disable(void); % f6 t  j* P! V# E1 e0 _8 c
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
7 K) ?) ?7 _  r3 q5 Y. U2 yroutine. You cannot compile this program 1 J$ s) B4 k% R- ~0 J
with Test Stack Overflow turned on and
$ ~2 b/ C, T- \) m0 hget an executable file that operates ' \# B% {9 d0 B) V# q+ n
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>' h# A* X4 U8 y
#include <DOS.H>4 m% y0 e% X3 o" {& Z2 s: F
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
4 Y9 D3 Y0 s( u$ o( E8 _: S/ }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)
1 c# a! }0 x* {{
- r$ J+ B; e8 U" D! u0 P: F/ F/* disable interrupts during the handling of / b. g7 T7 o9 d- f
the interrupt */
; _; Q$ u8 X! V; |disable();
3 y4 ?  ~$ I% G3 [6 ~7 G/ V. s2 q/* increase the global counter */
7 o  y3 C4 h4 N! e$ M8 U8 }$ pcount++; " \( g# F0 I! {! E' u9 G3 B
/* reenable interrupts at the end of the
( B7 i7 X* C& |8 u% g2 b4 S/ ghandler */ 2 x. C& Q5 x; R- u0 N8 y$ l0 c
enable(); - {( @4 E6 @7 [$ ^* m# w9 `
/* call the old routine */
/ W" q% k5 o% T  ?' S" xoldhandler(); 4 d/ l7 R' f! z& o, D' B
} </FONT></P><P><FONT color=#0000ff>int main(void) 1 j2 W7 P( E9 H  Q
{ 8 ~- Z  G( S2 ^) J* o% T. T
/* save the old interrupt vector */
& n/ |$ @  r- F" M1 {& Moldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
- v8 S/ K& f$ i1 F4 bsetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */ , z. \( H8 U* v& {
while (count &lt; 20)
/ @- u! \1 Y+ s: |printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ # ]- i3 T5 G% g& w" e( K4 t
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; 1 A; q7 i1 P3 `+ I+ x8 |
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
9 T4 A7 L. [* V- Q; z2 `( g5 ?0 k功 能: 将两个整数相除, 返回商和余数
7 q2 ]' ?1 k0 k- z# k4 b5 h用 法: div_t (int number, int denom); / n/ B) J$ K$ I7 j1 w8 n9 Q
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
  c& ^# {4 V/ X& c" _#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) ! s+ u, j" l5 E  \8 t
{ * l% v3 D8 X" `4 L7 l, W+ [
x = div(10,3); % d# s# r7 p, Q8 J5 |4 z. X8 y
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
0 h- h& ^  m' G! y$ ?3 ?# v} 0 x- N' @: j5 U5 h( X4 t8 Q; W: {: ?1 f
</FONT>; U3 ?& m: j7 U! n6 e0 ?
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
' L* A; r1 a, E4 f功 能: 获取扩展DOS错误信息
5 I6 ?* q! X5 F' D用 法: int dosexterr(struct DOSERR *dblkp);
# G- K; u, _7 v程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
  A4 i. z) ?$ I8 e- l) R3 D! v#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) % d  ?+ |7 b; R! I$ Z" I
{
5 n8 M# R5 a& L+ c' JFILE *fp; , O. k" n9 f$ Z% o2 a
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r"); ( @, _" S9 h8 x6 C& Q0 O" ]
if (!fp) perror("Unable to open file for
4 l% B! d5 `4 |reading");
1 P( ^  @3 p3 z0 r6 w  `( Pdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ 1 Z0 C! y0 _% \- u" ^$ G" p, \
information:\n"); 4 ?- A) f& O$ d0 V& t
printf(" Extended error: \ " K' a" |# q2 M. ^
%d\n",info.exterror); 2 `# \0 q5 D7 N5 u: F) r3 ~) s8 W
printf(" Class: \ 2 H1 {. R% o* e6 J0 W# R4 q
%x\n",info.class);
% E) B! N- l, n' Y0 O& p5 dprintf(" Action: \ ; Z2 G7 m7 @2 B5 z
%x\n",info.action); ) F% l" I$ p" ?
printf(" Error Locus: \
! X& ]0 b/ D) `" c%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
5 x5 V( C  h# C) O1 Y} </FONT>
* \" x) `' _! q9 B5 Y: M
, t  c% O5 e3 a) d</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
/ ]- T+ e; S- S4 I7 ]$ b功 能: 转换日期和时间为UNIX时间格式
, i/ b; S8 S9 G用 法: long dostounix(struct date *dateptr, struct time *timeptr);
( ]2 t* S: a! u程序例: </P><P><FONT color=#0000ff>#include <TIME.H>+ L+ e  q4 y3 X9 F0 h. ]8 B6 u  Q* `
#include <STDDEF.H>
  s4 C: M, q) S, ?- u#include <DOS.H>
1 _" `1 h; s# v5 i#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void) # d& v6 C# }8 o
{ 7 d6 y% O8 A( |9 B
time_t t;
/ c6 r3 ]; `9 k; X4 {struct time d_time; ) Y, Z8 M8 j) Q& B7 E7 h& v
struct date d_date;
# X% Q( v2 J! g/ P1 fstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
& T! H! l6 G6 r: agettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); + V7 m; J/ P8 V2 x7 |% q
local = localtime(&amp;t);
' ~8 h. v" d8 p: q( Iprintf("Time and Date: %s\n", \ 7 F/ o0 m" B/ l& u+ l; R
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
* y0 w8 l) t8 S3 a% R4 ]  ~& e' B} </FONT>. i% @6 I! ^. {1 r

- ?+ g( W3 v' H# ]</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
; M8 K2 T* ^( d8 ?* _( l功 能: 画多边形
; n; [3 C: F9 d( B# H用 法: void far drawpoly(int numpoints, int far *polypoints);
0 X- I: i) C) r* ]$ x1 Q8 K' h% m程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
3 t  U( U4 l- b7 n3 Z9 |7 D#include <STDLIB.H>
; o, P5 m" M9 s: `3 _. N7 v$ q#include <STDIO.H>* N" V/ [/ m% O) ^  R$ L2 E/ b; p
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
* g: |0 F# x- P# N) G{ 2 X8 k) ~" ~# Z) v  a, f
/* request auto detection */ ' j( e$ g1 V( ?/ m7 Z% v, m& _* b
int gdriver = DETECT, gmode, errorcode; ! a5 r% {9 E, R$ }8 D
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
8 |% p2 O- H1 p, dint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
+ a+ j" U) A3 Q. p% G3 {+ }variables */ 4 t$ `5 c4 C8 v+ U" G4 B
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
# e+ @" v$ Z0 C* e% Nerrorcode = graphresult(); & i( O* Y) i' {. Y
if (errorcode != grOk)
+ }$ h5 ^# W5 A/ i" |/* an error occurred */ " J  c+ h: V- K2 ]/ K, m+ ]
{ ' @+ y* D  V/ G
printf("Graphics error: %s\n", \
  ~: H0 y1 M# p3 M# Q# Z. K$ pgrapherrormsg(errorcode));
. c& w6 z4 l' |- lprintf("Press any key to halt:");
8 l7 q. s. w5 s/ Zgetch();
$ z9 _! t7 }8 s# _# l* R/* terminate with an error code */ & v0 i% e: u2 E- w6 [  [
exit(1);
9 `! [: h' z4 \4 C) ^} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
# z# b, |, C. N, bmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
; M( v/ Z6 z1 [8 T5 j4 Fpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ . T4 I$ o' y; c7 }
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
7 A  g1 I* z& a6 U  hpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ ! v1 U+ l9 @2 h2 R4 L  h, Z
poly[7] = maxy / 2; # J4 Z( ^: a5 R! t, z+ C3 c
/* 2 C  o) s; E8 j9 e& s
drawpoly doesn't automatically close / g! [+ u* Q' _8 ^& e3 L' z( X- \
the polygon, so we close it. 8 u; I" o6 B. J& C# @; u! y; L
*/
& q6 S+ ]7 w- qpoly[8] = poly[0];
/ W- Y5 u, `" C. L. |9 f. qpoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
( p. g6 y- A  |, d" W: X9 }/ Tdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ : L5 }# @9 f8 w  e7 m
getch();
/ Q, p2 B/ A; ]closegraph();
$ p6 ?' ?6 J$ V1 U- N8 h/ O8 ^! Breturn 0; . h/ t1 Z3 G+ i$ }- V( Q; X- @1 n
}
  G. p/ _$ E; O! O</FONT>
8 o  [9 U, m  X( i* Q1 h</P><P><FONT color=#ff0000>函数名: dup </FONT>' v+ t$ _2 z* r
功 能: 复制一个文件句柄 ( f2 f9 u. i* e' q3 Z5 ^2 {
用 法: int dup(int handle);
; H2 \: a, w! F程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
/ m% v9 X/ x8 n9 B( n1 P#include <STDIO.H>
8 d. [9 Z; i" j+ F( w" W#include <CONIO.H>% f5 b7 z- A% ]4 B, T
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
. T$ |# @/ y6 r& k{ 4 R5 }! l: U# B1 Z
FILE *fp; 9 s7 p' T" A) w
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ " A: s% K% U7 c8 A& E7 f
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
( n/ b# [0 B+ m" {fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
# A3 m# i  l8 B- a& Pprintf("Press any key to flush \ 9 m. `) F2 m. T$ v# v
DUMMY.FIL:");
5 W0 d+ I& z% ]$ |3 R; G2 ?# jgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
( J) Z' ]/ F. L$ e, R' i# N4 F) y/ }closing it */
$ Y! [2 T) N( U( ?" i$ dflush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ % _/ W+ S$ H. u) w0 c4 A% _
key to quit:"); $ S# R; o1 t) Y4 i
getch();
2 B9 q9 E0 S( R# Oreturn 0; 5 @9 H, ]7 A4 U, d0 W
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
3 O2 Y, C; l0 _. a4 W2 ]# J{
% C; i& v# h- R0 o( O* vint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ ' O1 ^/ A2 }- F% A
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
7 M  e5 Z) T# r0 X# l$ xduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
+ T( p$ Q4 w9 p2 d5 n" zDOS buffer */
+ _( ]2 S( c( {close(duphandle);
2 l7 v! I9 `- t" A7 @4 A4 d}
3 Z+ G2 |# ]6 X
. s, {* j8 _6 B2 }6 @8 j</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>6 H9 a6 w! T* |2 a4 r
功 能: 复制文件句柄
/ u- M$ O1 c2 M4 \3 s  X用 法: int dup2(int oldhandle, int newhandle);
0 ~' e1 E  k& }! d) [: n程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
* x$ M( v3 g; w% q0 k( p/ t! W5 `#include <STRING.H>
4 ~8 c; a/ m7 F; r& d$ l6 [5 u* ?#include <FCNTL.H>
1 U- u9 y$ {) i" Z#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) / Z2 p# d3 D2 E2 N
{ , u9 W  q- V; g2 q
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
. S7 ^0 [* V3 i+ e: @* Z" A/ rchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
  e5 z+ L* L2 `+ |1 |9 mnul = open("DUMMY.FIL", O_CREAT | O_RDWR,
& S/ v5 m' c9 y; d, LS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard + F+ \' b  ^. w/ a$ v* b( t
output */
5 r: p- Q5 }8 t6 t% ^oldstdout = dup(STDOUT); , v; ]: B. o& L' |, j) h
/*
4 H" O. o( M7 f" K8 fredirect standard output to DUMMY.FIL
! R0 c7 @; c8 Qby duplicating the file handle onto the 7 t+ s) `! ^% J/ U" q; N" }4 g; k
file handle for standard output. * b. j7 _6 k& V( R5 A
*/ 9 n& ?, H% U, h5 J7 f% N
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ ; {5 h( L5 ]9 b. o% E' n
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
( n6 `: U+ g. v' Q4 b' Dwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
) E% u) _4 W  c/ M; x. Khandle */
4 w0 @/ F' o  C1 k" Ddup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */ ; l6 A" b( Q5 F% ^0 b8 @
close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 6 H/ ^4 e% G, Z* G+ w% q5 M
}
8 T( k+ M1 b, T9 {8 v3 p</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-21 04:54 , Processed in 0.444274 second(s), 57 queries .

回顶部