QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2058|回复: 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>! A$ X0 y3 \' O5 y
</P>5 |+ ^' I& y; S/ y7 o
" L- M& T3 y+ X8 n

4 f5 o' \2 ^/ N<><FONT color=#ff0000>函数名: ecvt </FONT>, p9 {1 u9 e0 p. A: w5 y% O
功 能: 把一个浮点数转换为字符串 & h" O; \) _7 G. ?! I& Z
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
/ Q. ~1 t  I9 a6 B/ a1 X9 X6 m程序例: </P>, I+ z! K% v& D2 c4 e
<><FONT color=#0000ff>#include <STDLIB.H>  W3 @2 F* d5 P5 }& V9 F  N' {/ R
#include <STDIO.H>
3 F0 K% u  H4 x  k0 N5 v) ]#include <CONIO.H></FONT></P>
- ~' H( w) [# R6 `* `' R8 g! D<><FONT color=#0000ff>int main(void)
. C8 s0 r. _9 L6 O2 a( o) d{ 7 P9 w# G2 i% l( r4 s
char *string; ) ~7 v5 y% E2 h0 m9 Q
double value; ) q1 h9 h; m9 Y( Q9 A6 J
int dec, sign; $ R* C' W3 b2 l4 X, m
int ndig = 10; </FONT></P>( s# ]. Z* @" E$ N/ m7 i3 E: [
<><FONT color=#0000ff>clrscr(); $ {. R8 O( p- o- [
value = 9.876;
& q% a) i3 A" D& h1 v$ k/ Ostring = ecvt(value, ndig, &amp;dec, &amp;sign);
1 t9 a. ^5 d! g) ]2 X- G# Zprintf("string = %s dec = %d \
# g( g6 z1 P7 g, Hsign = %d\n", string, dec, sign); </FONT></P>
( n6 i3 z1 a% n<><FONT color=#0000ff>value = -123.45;
7 f8 F2 w, t( Y7 X6 mndig= 15;
. X$ o4 X" A7 {5 ]8 B9 \string = ecvt(value,ndig,&amp;dec,&amp;sign); % P% G1 W3 L8 e% g0 ]- l) [
printf("string = %s dec = %d sign = %d\n", 5 U( e& O& I, C! p' t+ I
string, dec, sign);
/ g  x! T% {. R+ s/ G. s</FONT></P>2 N" A/ j- Z/ r
<><FONT color=#0000ff>value = 0.6789e5; /* scientific ! b0 I( \" n: H8 F, G
notation */
3 w* p9 V7 G4 z' mndig = 5;
" a" _+ _; `8 ~# F+ z6 ?8 Tstring = ecvt(value,ndig,&amp;dec,&amp;sign); 9 s" d% L! Z9 a1 Y# j3 d
printf("string = %s dec = %d\ * ~7 P$ i/ h; R$ A$ Z" ~
sign = %d\n", string, dec, sign); </FONT></P>$ [- t0 F' _$ g& m
<><FONT color=#0000ff>return 0;
! F7 ^9 X# t7 _! P} </FONT>4 ]- N6 o. S% Q* N0 e" z9 i

% e& b9 s3 c( V1 K# G, Y+ ^</P>
$ w9 e6 A; @# S5 S% \3 ^. x- Z% K$ g<><FONT color=#ff0000>函数名: ellipse </FONT>
1 U) a, M$ I- T6 u' p$ \4 u功 能: 画一椭圆 " H1 N2 ~$ b8 w4 C' C
用 法: void far ellipse(int x, int y, int stangle, int endangle,
' Q) Z! N3 h+ l+ M' P, h% \- uint xradius, int yradius); 2 a5 S( E5 K2 Z) c9 Y. g
程序例: </P>
& U1 c; r6 K8 r! L! j<><FONT color=#0000ff>#include <GRAPHICS.H>
" H3 L' h) r2 s1 d; W6 k#include <STDLIB.H>
6 Z/ _3 \- ?; P, p. K2 Y/ {1 [#include <STDIO.H>! {: t% }+ Y6 X2 w# ]4 K6 ]8 t
#include <CONIO.H></FONT></P>
5 u% f2 z- V5 \' {" ^; |<><FONT color=#0000ff>int main(void) ) f- W- g1 Q4 h
{
5 E" @6 K9 C* c: |% N8 P; b/* request auto detection */
0 p- q" W2 y; y) b7 H" Q& @6 jint gdriver = DETECT, gmode, errorcode; " ]# K; w: K, J" d& {3 N( }0 c* K; Q
int midx, midy; ' ~" C# i- c1 d% E) n- ^. A4 a
int stangle = 0, endangle = 360;
( Z: |# X1 r, L5 l9 Lint xradius = 100, yradius = 50; </FONT></P>
8 @# J, F3 g( {) W) C4 ?<><FONT color=#0000ff>/* initialize graphics, local variables */ 5 m$ a9 M: [6 \3 _; q5 H% ^, b
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>1 ]* I  _4 E2 D" G
<><FONT color=#0000ff>/* read result of initialization */
% e) _" J; e7 a% c& s! Rerrorcode = graphresult(); . q5 F( F/ }6 x3 h
if (errorcode != grOk)
0 l, m9 o+ E2 A+ Q/* an error occurred */
$ c0 g, P- Z/ Y8 I) Z% A{ $ |* g7 D/ r" a8 y* l8 O) V
printf("Graphics error: %s\n", & D. }/ ^  ?2 Z0 ^
grapherrormsg(errorcode));   X0 \+ Y5 j+ A! i* f5 o# u8 k
printf("ress any key to halt:"); 7 M' s- R, F* ?( \: V" B( `
getch(); , }2 G* A4 q+ @# H
exit(1);
* ?1 h, X+ @! w. {0 Y4 N/* terminate with an error code */ % l8 U) U5 B8 M) f1 X4 W
} </FONT></P>
7 `. @: [7 w' @/ ^+ U; C0 Y( L<><FONT color=#0000ff>midx = getmaxx() / 2; 5 U2 g3 ?5 i! d- E; Q# a" ^, l
midy = getmaxy() / 2; % y& O6 F8 x) e+ a9 d* ~
setcolor(getmaxcolor()); </FONT></P>
0 L! D& T8 P3 W4 S4 M3 c<><FONT color=#0000ff>/* draw ellipse */
1 k6 q1 S$ {1 oellipse(midx, midy, stangle, endangle,
0 ^3 u% r+ P8 L: W( Gxradius, yradius); </FONT></P>
- M& Z% K: I6 O2 Z& Q7 X8 ?<><FONT color=#0000ff>/* clean up */ # i" {3 @$ v! n5 c: I
getch();
  ^' I) l; E3 X0 K8 K' L  Oclosegraph();
8 ?* H! M& `* |6 W+ n- x9 W1 j( zreturn 0;
& i9 c4 h& o8 g0 X, l1 S0 N+ Z} </FONT>
- t2 [! v# U, W! m3 [6 I% x6 Z
$ {- |* r2 y/ p6 a! J. f5 J</P>
( E( ~+ R! ?* ^8 \8 k<><FONT color=#ff0000>函数名: enable </FONT>, V& Y# b& k/ ^6 K& ~' D) j
功 能: 开放硬件中断 * I# c/ {+ z1 T+ D) U
用 法: void enable(void); , {+ @5 }' o. u8 Q* v
程序例: </P>
1 Q0 w6 \$ P* m% e1 P7 t<><FONT color=#0000ff>/* ** NOTE:
, A* V/ k1 D: f+ P. FThis is an interrupt service routine. You can NOT compile this program ) ]3 f% Y7 @2 d
with Test Stack Overflow turned on and get an executable file which will 4 A4 o. Y- }* ~* n5 d
operate correctly.
6 `0 L2 o+ Y2 W0 v% R*/ </FONT></P>4 z7 Q$ Z+ e) E) {6 W* j0 M
<><FONT color=#0000ff>#include <STDIO.H>4 _# W8 r. x$ ^0 q! O7 V- G: c  H
#include <DOS.H>8 J& |, L; x5 F, E+ s0 c4 L# |/ |- b
#include <CONIO.H></FONT></P>8 @, P% ?& z( k6 L$ m8 N- c8 W
<><FONT color=#0000ff>/* The clock tick interrupt */
5 t# Z5 H( `+ j/ S' z9 @/ ^3 l#define INTR 0X1C </FONT></P>: D5 I% G) V( M: j0 U
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>, C5 J) I- ~. L& D/ d( B( m6 o
<><FONT color=#0000ff>int count=0; </FONT></P>% _2 W' j( Q; \; k  w  P
<><FONT color=#0000ff>void interrupt handler(void)
  @' N& J4 d) N7 [) Y: k7 r6 x{ 2 V5 x+ U4 w: D
/*
( b& \0 |# J& }9 Kdisable interrupts during the handling of the interrupt
: e5 Q/ ~/ v4 y9 R7 |- `7 D5 m& {*/
7 [  p0 a  ^0 zdisable();
- p# j" S8 ?* U2 P! b8 l/* increase the global counter */
8 t. ?' I- |# g2 V- T/ `9 _count++;
3 [) ]! k, a; D* M& E8 T( K/* - b) E! X8 o1 x* g
re enable interrupts at the end of the handler 3 [, U& C' s5 z) K( H7 ~
*/
" P7 _/ ~8 y1 Penable();
& z6 j! l7 z6 ~4 O; s% I/* call the old routine */ 7 F- @' m4 S; S
oldhandler();
+ P: A. Q3 V# M} </FONT></P>
$ R0 c" V( ^6 G7 r$ a( H6 B<><FONT color=#0000ff>int main(void)
$ n( N% P8 u! i/ }3 w" _{ " z. S( P' f6 z1 \
/* save the old interrupt vector */ - ^' u( L& Q$ `, @! \
oldhandler = getvect(INTR); </FONT></P>, L; }# J" p: H4 l
<><FONT color=#0000ff>/* install the new interrupt handler */ 4 x9 q1 r0 ^$ d3 |( N6 R' \5 \0 J
setvect(INTR, handler); </FONT></P>
! H8 U/ z. a. o) X<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 9 c: E2 t. c  Z! V- v$ U7 X9 T
while (count &lt; 20) 7 a: v$ Y% `( {; i
printf("count is %d\n",count); </FONT></P>9 |3 a6 p5 D! F8 k
<><FONT color=#0000ff>/* reset the old interrupt handler */
7 v! \9 W9 Z4 U+ y# p* ksetvect(INTR, oldhandler); </FONT></P>8 k6 c' S( G1 N1 n# z
<><FONT color=#0000ff>return 0;
  D& A& z6 B  {# }} </FONT>8 `+ a6 @8 }! A9 M1 o' _5 @- b
8 q! w5 {, p5 d8 x( x. u
</P>
0 H7 l" P$ m" i" q5 _<><FONT color=#ff0000>函数名: eof </FONT>
* P! M# v4 F. g0 |功 能: 检测文件结束 * w; I* d1 R0 X5 ~
用 法: int eof(int *handle); # E4 ?, e, t7 Z' q$ I5 d
程序例: </P>
5 t& y, e& _! d* h7 q6 b7 b<P><FONT color=#0000ff>#include <SYS\STAT.H>
8 R  c% Q" c' q$ r3 V4 T' i4 w#include <STRING.H>
$ h8 `0 p2 w* {3 t#include <STDIO.H>8 Q5 W. C& E1 x$ S# o. U  X1 y/ u
#include <FCNTL.H>
6 ?0 N9 d$ J2 K( W* g; x#include <IO.H></FONT></P>
9 W% n/ {' I% l' \<P><FONT color=#0000ff>int main(void) 9 j0 M" P! G& A6 a3 L
{ / A* B( A) N+ m$ S8 r9 J
int handle;
6 j$ F7 _. R& O1 k7 D3 j4 wchar msg[] = "This is a test";
2 K: `2 n1 `; z2 G* m8 r3 n# Ochar ch; </FONT></P>
$ l; W2 p; S5 s5 r* [/ \<P><FONT color=#0000ff>/* create a file */
. u9 q: h7 E& q+ g# ahandle = open("DUMMY.FIL",
$ c2 d! f# x, B* U' dO_CREAT | O_RDWR, + l/ z0 ^( V  K& Z* f- f& N- Y
S_IREAD | S_IWRITE); </FONT></P>
' v' T6 `, P* N: p& D<P><FONT color=#0000ff>/* write some data to the file */ , S1 k$ f3 V" N! {, z0 ^; b
write(handle, msg, strlen(msg)); </FONT></P>
; }9 _4 F. m; d" V) ?9 e4 [<P><FONT color=#0000ff>/* seek to the beginning of the file */
2 Y1 ], ]0 @4 m: s+ Alseek(handle, 0L, SEEK_SET); </FONT></P>/ x# S: |# l# ]/ W/ v+ P8 `
<P><FONT color=#0000ff>/* / w5 [" w; s' `5 s7 ~( `7 o
reads chars from the file until hit EOF
0 y3 W7 E4 ^2 ]3 N6 F; N*/ 2 g6 I4 ]( A) V
do * |3 }1 ^: y# \! ]
{
7 F5 ~% O6 K& Z4 y7 _2 B% I9 C! Dread(handle, &amp;ch, 1); ! t; z# l5 x! e# k  d: i
printf("%c", ch); , m: V: L; `3 z% C' r% D
} while (!eof(handle)); </FONT></P>, n6 h2 M) t' w$ s8 o- T/ }4 s
<P><FONT color=#0000ff>close(handle);
) b, S! W! j% j* J. U% Creturn 0;
. r) p" L6 D6 S0 \& o6 U- a}
5 d1 ?# B1 }: U' y. r. O</FONT>
3 p3 o4 Q/ Y; a9 g& m6 r, a</P>( p5 ]( {4 |  N9 X: F3 C8 o
<P><FONT color=#ff0000>函数名: exec... </FONT>
4 w. Y; H# c' z" W% {9 q/ N" m& o功 能: 装入并运行其它程序的函数
- L  X/ x8 [, |9 v: E用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); : a' _8 \, Q; O! m
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
. V7 F1 l% ?5 p6 f, `char *envp[]);
4 S. f& e) L7 z7 [9 _int execlp(char *pathname, char *arg0, arg1, .., NULL);
* Y+ e2 D+ P$ h9 o6 fint execple(char *pathname, char *arg0, arg1, ..., NULL, ; U% }, i4 A$ \/ G/ e$ j
char *envp[]);
3 B- Y( p0 D. y9 h; I" p9 F8 fint execv(char *pathname, char *argv[]); 3 y1 z% y$ \* i+ Z7 _+ N
int execve(char *pathname, char *argv[], char *envp[]); 5 ^& k" M$ d1 \# P# d- H/ l" d
int execvp(char *pathname, char *argv[]); # L# [# D# G  ^
int execvpe(char *pathname, char *argv[], char *envp[]); , v) \/ i! p: n9 I) P
程序例: </P>
1 x  V+ `: M2 ^: U<P><FONT color=#0000ff>/* execv example */ 8 ]% v4 u' @! |" u: f- l. D, }' L
#include <PROCESS.H>
, \( S; H6 e0 W: A4 B#include <STDIO.H>
! x* F, Q  \+ ^: j" l#include <ERRNO.H></FONT></P>; y+ i" A2 x8 X) h  K" K& J6 ?
<P><FONT color=#0000ff>void main(int argc, char *argv[])
3 I8 Y# A$ ]2 T2 w( M# _8 [{
5 X7 X8 z, I4 }3 T5 Qint i; </FONT></P>
0 |  N* y3 n2 Z. W( W+ b- o<P><FONT color=#0000ff>printf("Command line arguments:\n"); 1 w. ~4 C6 c1 x; M1 B1 X( E
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>. H; A/ ~) y+ e& y0 Y
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); & O, ^+ F! i0 I
execv("CHILD.EXE", argv); </FONT></P>
5 a' ]* @3 m% M3 E/ Z<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
6 }! z: k0 p3 `1 e  l: g<P><FONT color=#0000ff>exit(1);   o! U2 t2 \; _8 ^$ A# ]+ X
} + N% P8 h: z# e5 ?: _2 T  S
</FONT>
% n! |, }9 ?, ^( M- u- Z5 g</P>
- g* j/ n4 l6 E8 n! Z<P><FONT color=#ff0000>函数名: exit </FONT>5 ~8 q. \+ G% [3 b4 T2 f# {" N0 r" k
功 能: 终止程序
) s3 w6 z  x( A+ E  z! ^' D用 法: void exit(int status);
$ R3 t% _: Y9 g9 H9 P- m+ D; g程序例: </P>
& ~. v# D* V' L5 x5 O/ W& ]<P><FONT color=#0000ff>#include <STDLIB.H>6 `1 g$ T" `, u3 N, X
#include <CONIO.H>
2 L' p8 r9 G8 c1 j#include <STDIO.H></FONT></P>
( \9 Y3 c# b& u/ b: s<P><FONT color=#0000ff>int main(void)
/ V# S# _/ p+ m- V& n7 R! W# R9 K{ * Y  L: ]8 Z2 l5 E
int status; </FONT></P>
) A, C; Q- z% P<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
7 ~( J! Q8 R4 }5 y0 j9 Y  f( k5 Qstatus = getch(); 3 A, @4 k, _/ N9 J0 _- q5 n
/* Sets DOS errorlevel */
) g: h  T0 K( y5 [  u5 vexit(status - '0'); </FONT></P>
0 N" W. h5 p, x1 X2 d  e<P><FONT color=#0000ff>/* Note: this line is never reached */ ) [" e; g' a6 |6 r9 V# q( C
return 0; ( F1 u+ g# p5 ^+ I3 o6 c  e& Y
}
3 X2 c- i. F7 Y</FONT>; v- O/ F: ~) ~# n7 ^" H# ~! A
</P>: l4 H3 x  h" r  [# Z
<P><FONT color=#ff0000>函数名: exp </FONT>. Y; o6 z1 B, L8 X8 z
功 能: 指数函数
3 ?9 \8 m; p: f7 u3 t. Y; \用 法: double exp(double x);
, K# D: N8 I- G1 N8 f6 Y程序例: </P>$ o* P0 k/ z; K; k* p2 Z! r
<P><FONT color=#0000ff>#include <STDIO.H># m( u( s1 c# B9 \) v& b
#include <MATH.H></FONT></P>' w8 W5 P8 f2 Z- e& e; H  F. W
<P><FONT color=#0000ff>int main(void)
$ U6 k  U, V  H{ ( u) X+ w+ X7 |: U9 S( O- ~+ i2 R! X" P
double result; 6 h9 L/ Z/ b  M$ E- _% i
double x = 4.0; </FONT></P>
% V; ~; C; K8 Y  t  u2 s/ f<P><FONT color=#0000ff>result = exp(x); . e1 Q9 {$ f+ G" ]( o) ^7 l4 t
printf("'e' raised to the power \ " ]0 h5 W& S* C0 A" B/ H5 R6 {
of %lf (e ^ %lf) = %lf\n", + l  Y6 X  e9 X" K, U2 w
x, x, result); </FONT></P>" O( d' m' Z& Z3 }* }$ y
<P><FONT color=#0000ff>return 0; ! Z9 X" D& C- k
}
' g% B* g2 D/ A9 q# d: t. \5 E</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>
& ~6 K) e+ s, v' @& X2 R, k9 N</P>
; `! @2 ~5 h0 _; F<p><><FONT color=#ff0000>函数名: delay </FONT>
- a' w3 a; r$ }& c+ Y! Z+ Z功 能: 将程序的执行暂停一段时间(毫秒) ! N5 l2 U$ x$ V  I) t: c: c
用 法: void delay(unsigned milliseconds);
; P, J0 l$ q6 M- {" m/ h9 k程序例: " l1 A  W6 X3 m/ s* n8 `
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ! V' E8 l' ^. N
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
, O, b4 ]* N/ T, C3 m{ 0 C0 J" G( Y3 i; a: U$ w4 X+ F7 \
sound(440);
/ o$ Y8 N4 d' I$ J) D/ ~" udelay(500);
* |3 ^* x5 V  t2 S+ F- qnosound(); </FONT></P><><FONT color=#0000ff>return 0;
1 t$ d5 _% H* i% J% n, @0 q1 O3 K}
6 J$ E  w% f  `6 i$ }8 j! r  L/ `$ d' B4 F. W
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
, ]! o9 [0 G" [功 能: 在文本窗口中删去一行
& g% }) a, y9 l$ n用 法: void delline(void); ( `: g5 \) f3 j; |3 L2 R
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
) P. n/ ?" ~. e' y  J5 }- |& O. p{
7 {( z+ `) W; N" N/ o- gclrscr(); 5 k  O" G1 \8 N* n/ D; n
cprintf("The function DELLINE deletes \ ! n: B; E' |) w2 _4 u1 Z
the line containing the\r\n");
; Z7 Q' X* Z7 R; h4 @& B* C  y  tcprintf("cursor and moves all lines \ 9 m" k5 b6 Q$ ^3 {- F& @" Q
below it one line up.\r\n"); 0 _" r/ e* ~3 F
cprintf("DELLINE operates within the \ 4 F$ V1 p7 W* G  u
currently active text\r\n");
8 @; g- `, \# W3 ccprintf("window. Press any key to \
+ P" k& Q3 @7 J, C9 jcontinue . . .");
/ n7 X' A/ `' a. j1 S7 T  qgotoxy(1,2); /* Move the cursor to the 9 V/ K9 f" O% O. @* \/ @+ T, @* x
second line and first column */
7 Z# A5 F7 H& U$ A8 ]0 Igetch(); </FONT></P><><FONT color=#0000ff>delline(); " B% r, r3 A" j$ @' ^: {0 t; S
getch(); </FONT></P><><FONT color=#0000ff>return 0;
) F. @4 H" y* ]- _} </FONT>, D; _  O4 B% E' {! Q6 \
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
) N! o8 x" u$ J& I/ t. k% h功 能: 通过检测硬件确定图形驱动程序和模式 : b& Y, \$ o7 [5 O3 `1 r
用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 6 Z8 p) P( G6 W  e4 m1 E/ V/ |* g3 g
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>6 g0 V$ W! A2 x. C- t& m  S
#include <STDLIB.H>
1 M4 k1 V# I- [#include <STDIO.H>
0 T( I: P" I, L: H) K- c#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
% e& e' d+ a6 y" b2 |char *dname[] = { "requests detection", 6 y1 P+ Y; z) D: [# K, h4 r1 R
"a CGA", + Q* |& _! X. N: ^% j+ E# L
"an MCGA", $ m1 r, c& W+ O7 |
"an EGA", 4 _8 ]  m# @: ^6 }
"a 64K EGA",
, L" ?9 {1 P3 ~! c1 R( O" F"a monochrome EGA",
& N+ x& T. A4 v' s"an IBM 8514", 2 U, ]3 V/ w: F6 ~2 H
"a Hercules monochrome", 2 x9 j  D9 ?6 Z& N: R& P
"an AT&amp;T 6300 PC",
, b* k1 U; [+ z/ A! u8 d$ B"a VGA",
9 i, n- Y$ O" L# Q9 Q  U"an IBM 3270 PC"
) ^' u, T5 a/ c% Q}; </FONT></P><><FONT color=#0000ff>int main(void)
' B3 M2 B' v- H8 D6 X. K, g{ & j. r' r6 ^* f9 M
/* returns detected hardware info. */ 5 c  _5 k! W% R- q- d' ~2 Y
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
( c" _1 U  T1 y# F% fdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
7 |0 o! p. P+ U8 R) r$ herrorcode = graphresult();
. a8 Z5 g7 C" p6 ]9 e9 e# e/ \if (errorcode != grOk) /* an error 6 \& A6 w/ x% ]" e. _
occurred */
1 ~; h' ?7 H  r, V( u{ * ]& n. ~$ l7 O4 a
printf("Graphics error: %s\n", \ ; J6 {! S9 l" j  g4 A
grapherrormsg(errorcode)); + J7 r0 b) ?2 T% n' k& {) G& Z4 u
printf("ress any key to halt:");
; C0 |5 Z. t0 q! D+ S  n" agetch(); 2 r) {' Y: I7 O: t* ?( P2 r
exit(1); /* terminate with an error 9 s: y8 c' }6 `% C/ ]/ F/ f3 I* M
code */
8 r# T  _2 ~' M* M$ z0 P} </FONT></P><><FONT color=#0000ff>/* display the information detected */
4 }. b; c! P) _, W: ~* ^. j4 E! Nclrscr();
6 a  a6 V6 o- o& ?  I$ o6 Eprintf("You have %s video display \ ' }% W) |. r; z
card.\n", dname[gdriver]);
. i9 }2 l6 \: w/ X6 ]1 e. vprintf("ress any key to halt:");
9 @3 g7 q: u4 h5 d9 z: ]9 Z9 Z- wgetch();
8 D2 ^' D# ~7 J  T7 ^; nreturn 0; 7 f; d; N$ h' T3 R8 U' M
} </FONT>7 H7 s2 J! H; ^# p+ S
/ K  E! M5 p- p" R; f. J' x$ _

6 O5 f  v2 B7 }% L5 M$ l1 z5 f7 e4 j</P><><FONT color=#ff0000>函数名: difftime </FONT>
$ T: F* K! p: D: j功 能: 计算两个时刻之间的时间差
& n* h' e) @$ J; w3 Q用 法: double difftime(time_t time2, time_t time1); 2 u8 {' c# m, J2 i8 `1 @* i
程序例: </P><><FONT color=#0000ff>#include <TIME.H>+ n$ X6 y" V! I1 Y, D, o
#include <STDIO.H>
$ z" x2 R* _- g( V. g#include <DOS.H>
6 v0 L. N1 C: m. l& `1 W7 m) ]# a0 c  C#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) + Q+ ~( ?; K# ]( B  ?7 O3 k
{
: f: ^% ^) G5 H2 Y$ G; Rtime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
4 H6 \$ r$ R7 _2 y; ~2 efirst = time(NULL); /* Gets system
/ m) G, Z+ K9 a  _5 Btime */ ; r+ h/ V* a, Y# e- G4 \
delay(2000); /* Waits 2 secs */
8 b  G( M( a; v2 i/ ]second = time(NULL); /* Gets system time
, A. j$ h$ M* Y# Y3 uagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ ! t. y: y$ R/ r4 m/ _
seconds\n",difftime(second,first));
/ m" \# v8 r( N# v3 b9 D) rgetch(); </FONT></P><><FONT color=#0000ff>return 0;
* }4 p- v# {6 V+ R} ; q/ H1 U. C# Y6 {6 j8 L
</FONT>
! y7 t% K  r& J& e</P><><FONT color=#ff0000>函数名: disable </FONT>
2 G+ X' ]) K7 w3 P功 能: 屏蔽中断 5 a+ J3 ?, f( S/ ]1 @5 Y& L
用 法: void disable(void);
; G3 `/ t. M  P( o- e/ J/ T! m程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service : W' E3 E: l; v' g
routine. You cannot compile this program 8 O( I' N2 C8 _* G! j% @
with Test Stack Overflow turned on and + U, K; {, l! q2 g5 `! ^+ @
get an executable file that operates 1 e7 G8 t! ]5 t. W
correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
1 M6 l- G6 ]" D" J: {6 C! c) p#include <DOS.H>6 Q* k) c7 L( \& A9 O) M9 ~* U
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick 6 d' I2 ~. i8 ]3 r
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) 8 h7 A5 e7 P  \6 E/ `
{
3 v( m4 Y2 C1 }6 K5 U$ U/* disable interrupts during the handling of
0 v/ W) J  y! O, d# |: h6 y( ethe interrupt */ + j: \3 t+ B/ I2 C$ |9 Y, E
disable(); " ^" U! |/ s5 R4 |# U" i
/* increase the global counter */ . U) k/ l1 |# J! M+ i
count++;
( v. b7 j+ X& f/ ~% E% }/* reenable interrupts at the end of the 9 V2 p. W6 ]  F: y0 ]; j# P
handler */
3 i8 @( @! j4 c) Aenable();
; G3 ]$ V% G8 u9 P( o8 w, G5 O/* call the old routine */ $ k" }* O- D, _
oldhandler();
+ U( C8 _3 C1 [& T3 |0 j} </FONT></P><P><FONT color=#0000ff>int main(void) 0 h4 D, Y# H* U1 \" V3 Y
{
. q& H( I+ |9 F! u- d/* save the old interrupt vector */
5 ]9 K! a$ ^! J4 y! L+ {" {4 Woldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
1 m4 @' G7 t) l6 Psetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
7 w5 R/ W. u: `: H' B$ ^while (count &lt; 20)
3 ^: [4 h" T2 f* K6 F, ]' eprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ # \$ S# a6 _, }" L
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; : N# L* v8 ^0 Y' A" k: C8 T0 J
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>. L8 A" o% @+ ^. y3 ], h
功 能: 将两个整数相除, 返回商和余数 9 J  r0 z8 c* c: J: O+ P6 v4 g
用 法: div_t (int number, int denom);
/ N# k1 C+ o5 E+ T3 J+ `程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
$ k9 ?  G+ u/ B) y( I/ \- X1 v#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) " k- S& [/ A/ ^  o) F; p
{
( T, B3 [9 ]: f, Dx = div(10,3);
. W+ l/ F9 v) H# Wprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; 1 O1 B* F' J- X/ A. N
}
; U2 G8 i) F* Y$ @9 h</FONT>
- W$ H7 T9 ^9 [! c# h" i4 i</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>$ M7 d/ I8 G6 Z, c8 Q9 z  Y
功 能: 获取扩展DOS错误信息
1 o  Z  Y+ d' p# C用 法: int dosexterr(struct DOSERR *dblkp); 8 q6 ^- C8 t6 j5 \
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>4 Q6 `  Q6 t. y
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) " r6 [! z' K0 w" c# d& t
{ 5 |' [" s: Q  X* W
FILE *fp; " r3 I8 k) [* q* u" ?" w+ t: D
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
' \0 x2 N1 z! n2 J2 ?9 b- Y/ uif (!fp) perror("Unable to open file for ) [" R: z" }+ L" r- y" T
reading"); 7 c; d! q3 n" p9 Y6 m7 a
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
, L+ f& H9 k2 |  r( b3 \, Pinformation:\n");
# G. P5 m2 e' `: G9 _printf(" Extended error: \
* E! {. Q- b- ?( z( ?% B%d\n",info.exterror); 2 a8 i2 y$ f' x6 }
printf(" Class: \
1 @3 j9 Q/ r& L4 b& Z%x\n",info.class);
- @# V8 N, r" s/ j2 S5 S1 aprintf(" Action: \ ( Q) D  w7 u7 `1 G$ S  }. h
%x\n",info.action); ) Q" q+ p; V0 [( M* v6 B
printf(" Error Locus: \
5 u* E1 t+ g+ T$ w  _%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
; H  ]$ M! N  f2 D3 I' A  H' m} </FONT>
( V+ U& o0 W; o" K8 ^& l
4 W& a; y' i: A6 X" v5 s% [8 G2 X' m</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
; |/ x4 S% N3 T  L: [2 w" |1 P功 能: 转换日期和时间为UNIX时间格式
9 S. Y% P  F' f  V用 法: long dostounix(struct date *dateptr, struct time *timeptr); # a* j6 ^5 M) }' y
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>! t" i8 S& ?4 p6 x5 @
#include <STDDEF.H>
. u, ]7 R! O' _+ B- n: R#include <DOS.H>- D  A) b* g7 X% z9 @
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
' z: l! X) b2 C& R{ % c1 b2 n9 Q* Q1 D7 n
time_t t; ! z$ i" @3 \8 S" }6 M9 r
struct time d_time;   i4 L" b/ k' F1 q
struct date d_date; % |5 r- g. \" T3 s8 @0 y/ s  f
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
' z& r& ^0 V+ K7 ygettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
( |7 p/ i* w" ^2 G/ Clocal = localtime(&amp;t); 0 y. z9 V& n6 p4 X  d3 h% V0 N
printf("Time and Date: %s\n", \ ! S4 L+ w6 Z+ B
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; 0 R+ l: c& S) B/ \6 [
} </FONT>
+ N! l( H' ?( _& g5 i8 i7 o
3 h( `, c0 g" |: g5 ~</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>3 E! o: I8 w, p  Z4 U
功 能: 画多边形 ! E# Y; F; i& @- C0 G4 i& h2 _! F. z! z$ C
用 法: void far drawpoly(int numpoints, int far *polypoints); 9 K: l5 n- Y( b" [6 g6 d. n
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
  h& |! ?" _+ g+ P4 @& Q#include <STDLIB.H>
8 r% [( H& T8 `( }5 k) w7 ?2 Z#include <STDIO.H>" p5 p  x  Y6 i
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
+ t+ ^; E; Z  J! h( F% I+ {{ / F, `5 {7 z8 M$ o8 [) k
/* request auto detection */ ' D7 T2 E- |7 f! b
int gdriver = DETECT, gmode, errorcode; * L# X! ~' A, [  Y
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
3 @$ e! H6 O# E, C& }int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
) U$ }1 l! M( L: K2 Zvariables */
! x- T! C9 l' r" ~2 Cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
" j5 ~) l) ^" y. P# F( o3 Uerrorcode = graphresult();
: n! Q/ e% y  r& v4 \# g# }if (errorcode != grOk) % \) U2 O$ s8 ]  t  d& V
/* an error occurred */
5 I# [) N. n0 x{ , h. [9 R+ d6 D0 c/ N% @
printf("Graphics error: %s\n", \
0 v8 [8 H) j6 m. J6 kgrapherrormsg(errorcode));
: H1 j4 _6 {% C  h3 hprintf("Press any key to halt:");
- P4 V' S0 m! rgetch(); , d1 R% w* {5 t" s
/* terminate with an error code */
3 A* O2 [+ c2 S1 Y- s6 }) G/ Fexit(1);
. i; `$ l8 U3 d4 ]1 Y  _} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); * M+ y4 W" i" f# P" Z
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
* n* T$ h- ~+ f6 {" Mpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
1 {7 h) n2 y6 B! Spoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ , f' ?* p, q/ Y) T) l7 Q$ p* N% e
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
$ F! y2 ?& b+ P/ C# Upoly[7] = maxy / 2;
  m* \( U& d& w/ T9 P2 C/ O/*
# d4 O  b* y8 c/ Z/ Pdrawpoly doesn't automatically close
  l! G- |8 L/ l; j1 s* N- T2 Jthe polygon, so we close it. ( [0 v0 u7 w6 H/ u, e8 i% O
*/
8 i3 ^. N2 n8 Apoly[8] = poly[0];
* ^" |4 ~1 t' z  [8 Gpoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
* H7 {$ ]3 j9 f- {% w4 c- Vdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ ( c2 I" G4 Q  c
getch(); 9 {9 k& z5 j" m/ ]; ~6 |+ a
closegraph();
$ b, E6 p2 F9 U' U/ \. _; ~return 0; % A- r& w1 M" C7 o: ]1 z# A
} 5 T& U8 t* Q8 W! `' j/ o5 s% ?  w
</FONT>
6 g. |' U3 B) z</P><P><FONT color=#ff0000>函数名: dup </FONT>% B3 b& I  m  y+ l
功 能: 复制一个文件句柄
8 p) K  |, c7 v% E- R用 法: int dup(int handle); 3 E) O# I' b* q
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>5 K0 m3 I% a3 G
#include <STDIO.H>
. ~1 \* Q5 J8 O: X3 g8 ~- z#include <CONIO.H>! K/ i' j  h/ l: T  U8 X: ^
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
- W4 V" M1 n6 O# T. z! h{ : t9 n2 Y  M- A! c) D& X, I
FILE *fp; / ?# y+ z6 v5 w% M" p, ]
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ , K* z& _5 T; ]8 o+ Y; ]4 C7 M/ [
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
* p4 z7 O$ R6 j! j& zfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); , C: ^; d1 l3 Y2 T# C/ w6 T; y; _
printf("Press any key to flush \
  l+ n9 C- t5 D4 y9 ?DUMMY.FIL:");
; X, e1 ^8 y" k) h+ d& }# }getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
6 e$ {  h# j5 v5 v! y( ~closing it */
+ `+ s+ i; U$ I2 P# r6 I) Kflush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
, V5 C, U. E/ {; K! O5 J. c( Skey to quit:");
  K3 a5 a8 D+ r, l6 F4 |getch();
) h" {* a: u, U/ a* u) P# z8 Vreturn 0; 5 |5 U! a% t$ U+ E& n4 _/ z
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) . M$ U* C* @% h" @
{   W+ D8 W" O; \, {7 E) M. V
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ * v: @5 ~% z$ c7 U8 U
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
( N1 ?6 b) ~$ S6 u6 O# Sduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the + _* h% g1 @( }# I
DOS buffer */
: I" Q+ S7 o: j5 G; ^- jclose(duphandle); 7 Q/ q' O0 u' n& N, ?- ~
}
, ~# j* P0 ~' r. L1 K' c/ T4 p
3 \7 v: H& W8 h) }$ ]7 W$ C</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
2 n1 L% a5 v4 y- v9 ^功 能: 复制文件句柄   ~# o2 s; v% F! p- G
用 法: int dup2(int oldhandle, int newhandle);
" n* I- k( t! h% k( f程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>7 Y5 `5 \4 Y& G; P' g
#include <STRING.H>
5 _0 B0 o# P* F9 j$ |: j/ Q9 O#include <FCNTL.H>4 o. X! E2 P8 X4 T" h1 j
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
- D" ?, p7 R7 G2 P) ?" `0 ~- w{
6 `+ ]8 B9 D* M2 k#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
5 ^- x8 Z9 N/ B" m' u: J# ^char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */   o  d, `# k! d8 E' T
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
, z: a) f' ~& XS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard ; ^& s4 M$ @. p
output */
/ T0 y0 W0 s- T" z& Xoldstdout = dup(STDOUT);
# i+ j# U* q9 A! h  U/*
  |2 G5 }, V- C5 z+ p, D4 X: Uredirect standard output to DUMMY.FIL . P2 \9 H8 s# _( E3 d5 G- z
by duplicating the file handle onto the $ m' z  |: z5 c$ h( c+ @! ?7 M
file handle for standard output.
9 A; P7 Y" O  D- D+ r/ z*/
: v# y' L1 _3 T$ {2 h  f# Jdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
% U+ |  K! [+ _. \3 Y) Kclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ 5 P1 h6 x( F6 o4 R
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
, e: V) l8 I$ Q# s9 Qhandle */
  |/ V4 |7 C" d. E  c- Gdup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
* T& F5 Z, G* D  S0 A1 E0 Rclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
/ C: n/ g' r* j! O8 l- {! X6 V- N}   q6 w: K- F* o' H/ ~
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 09:55 , Processed in 0.397448 second(s), 62 queries .

回顶部