QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2087|回复: 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>
7 v* [! m) x! S& b0 k</P>5 I8 A, f& P& I1 o# F4 {7 T
6 t5 _. L" a# Z; E- R/ b/ Y: [3 \
2 O% A2 O- c! [2 Y7 M
<><FONT color=#ff0000>函数名: ecvt </FONT>
- M: T1 I) s% }' m  y6 ]; z; d功 能: 把一个浮点数转换为字符串
1 \0 }7 j# c" t0 L8 G. s, J用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
% {6 h  ~- V+ R0 m- J# A2 |, \9 y程序例: </P>- Z/ U  L+ O) O- F3 J
<><FONT color=#0000ff>#include <STDLIB.H>
  I# a, Y. [7 h4 G' D#include <STDIO.H>; w& o4 b* E! R) ?' _, D
#include <CONIO.H></FONT></P>3 y& E7 |+ ]: U) G4 |
<><FONT color=#0000ff>int main(void) ( g% I$ H! z: q, }  {/ z. H
{ 0 U1 \. R3 G1 Z0 s! k5 r7 i4 |
char *string;
( \( O9 _) y8 v2 N3 z0 t5 w6 i/ Ddouble value;
) c; D- S* ~$ t* y# l/ ~; V+ hint dec, sign;
7 l1 b8 C! d# U5 P# g' [int ndig = 10; </FONT></P>. d# c- ?. r: d1 a1 T4 Z& {9 t
<><FONT color=#0000ff>clrscr(); , V1 R6 F% A  E) W
value = 9.876; / ^6 h5 W3 m9 ~, J; n
string = ecvt(value, ndig, &amp;dec, &amp;sign); & r8 {6 }: g9 {1 ~
printf("string = %s dec = %d \
) `$ e% u& I) F( \0 @7 U* bsign = %d\n", string, dec, sign); </FONT></P>  y& }: e; W0 V7 z
<><FONT color=#0000ff>value = -123.45;
: D* l0 S/ W1 e5 f3 T# e$ xndig= 15; ! C" n) U! D2 ~4 G" l# V
string = ecvt(value,ndig,&amp;dec,&amp;sign); , A# ?) v8 {1 |7 }! a) M3 t& [" c
printf("string = %s dec = %d sign = %d\n",
8 M3 p+ {' k, V) Kstring, dec, sign);
  X: ~* z/ S, K</FONT></P>) T$ T, \& L( q( p% F( i
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
. J  T( Y' i$ M0 |7 d, \notation */ ( t( X! B+ A8 m2 T. ^6 x
ndig = 5;
6 s9 U- j/ W3 d+ Z: y% A( ^string = ecvt(value,ndig,&amp;dec,&amp;sign);
8 {0 V! ]; g+ u& A) N; Qprintf("string = %s dec = %d\
2 a; z/ d2 y# Z  asign = %d\n", string, dec, sign); </FONT></P>/ M5 r5 x( j- a3 R. q6 \% K
<><FONT color=#0000ff>return 0; 6 Y6 X9 Z4 u2 X1 F
} </FONT>% f% O5 t/ w2 z" ^$ L* Q& `
' |. W8 ?3 g; {/ t
</P>
' y. ?- I) r% n# o8 M5 s<><FONT color=#ff0000>函数名: ellipse </FONT>
" T( b/ x# I/ X$ y" S0 K功 能: 画一椭圆 / k0 I, l0 u# _7 T1 w+ ?
用 法: void far ellipse(int x, int y, int stangle, int endangle, * M+ H/ ~8 \/ g1 O
int xradius, int yradius); # T( u6 X) X4 X4 E
程序例: </P>
" C- S1 H7 L- V& ~" }2 Y<><FONT color=#0000ff>#include <GRAPHICS.H>  P) Y6 h3 X4 I0 K9 n+ W
#include <STDLIB.H>
! K! J) n: e8 g1 q( N6 d#include <STDIO.H># V2 j3 m9 v" h
#include <CONIO.H></FONT></P>- ?$ B; s! d4 ?
<><FONT color=#0000ff>int main(void) ; N' w# y& Y7 `: S) ?
{
, N) \5 H& W# a4 ]  z0 F2 t' i/* request auto detection */ * ~( O! G6 @' E5 a
int gdriver = DETECT, gmode, errorcode;
$ I# @2 b8 A5 _1 z) C' Kint midx, midy; 0 C6 X/ n) \9 ~5 S- a- E
int stangle = 0, endangle = 360; " q: I( k$ ~+ B' X3 g" V
int xradius = 100, yradius = 50; </FONT></P>7 f6 j) d; r) n$ @) f
<><FONT color=#0000ff>/* initialize graphics, local variables */
6 Q9 g% q# k& O  Z! G' J* x( Uinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
5 G: p; i/ }" W: [; B' u1 m<><FONT color=#0000ff>/* read result of initialization */ 6 Y. x5 c: @( k
errorcode = graphresult(); 0 z8 S. Y* i! c- v! {
if (errorcode != grOk) $ J# @: [- Q* R" g
/* an error occurred */ 8 |- N2 L* Z& h
{ 0 i- E4 f' V' K
printf("Graphics error: %s\n", 6 q/ V$ W% P: s2 c) p
grapherrormsg(errorcode));
2 q" X% h- Z" n7 r6 g& }printf("ress any key to halt:"); 8 u2 L9 s7 |" }0 j+ g+ d, R
getch(); - ?# C6 L7 F& g5 T! k& [8 h
exit(1);
& S! g# _; R2 a8 U9 z1 f/* terminate with an error code */
: L; Y6 o) _1 N} </FONT></P>
& A2 q9 I0 {; i) m<><FONT color=#0000ff>midx = getmaxx() / 2;
! _* M$ ]6 b. H$ Z# pmidy = getmaxy() / 2; 6 A1 ]. `! ^- E; }/ T8 ?# l5 P% b- Z
setcolor(getmaxcolor()); </FONT></P>
* n/ w% J$ d4 B! [/ i5 ~5 n<><FONT color=#0000ff>/* draw ellipse */ - b' u6 J! F* F$ c# f
ellipse(midx, midy, stangle, endangle, ! V" b( A2 M5 v# o1 c% a
xradius, yradius); </FONT></P>6 q) f3 W+ n5 g( Q8 R! B8 M4 O
<><FONT color=#0000ff>/* clean up */ 4 m, K( M  `6 r- S; I( S
getch(); 4 J1 R: j, a; Y8 N
closegraph(); 2 b; i- a) c& `, @* |$ T7 R' b+ ~
return 0; ) f, j# V1 `6 w% x$ A$ F$ v
} </FONT>
1 t  N9 I5 @4 ?+ e0 u
4 }: Y1 p' V' U0 n5 B4 e</P>
" _0 L7 ]: Z; c5 `5 ^, x" @7 I1 S<><FONT color=#ff0000>函数名: enable </FONT>
, p/ B7 y4 ?/ @1 k4 {( K功 能: 开放硬件中断
8 k7 A5 g' z" [, u用 法: void enable(void);
' ]7 c7 o; x+ u# h6 k程序例: </P>
3 f1 b8 _7 T. C% f4 X' M<><FONT color=#0000ff>/* ** NOTE: % P! B8 _5 W& R% o, @
This is an interrupt service routine. You can NOT compile this program   ?) M8 _6 L' {( t
with Test Stack Overflow turned on and get an executable file which will
: T$ ?9 r) ]2 ?) x! |operate correctly.
/ a) \  o+ H% w9 k0 _$ ~*/ </FONT></P>( T/ ^9 c3 H, a1 S) M
<><FONT color=#0000ff>#include <STDIO.H>
8 C. i- G: j5 k#include <DOS.H>6 \; x- ?, S) b- L& ]
#include <CONIO.H></FONT></P>  _, O2 F9 K; l3 h- H* ?/ {4 x
<><FONT color=#0000ff>/* The clock tick interrupt */
7 F6 [, k* V8 \& N: P#define INTR 0X1C </FONT></P>1 Z. V0 Q5 A& {! |, f
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>9 s- N1 y2 I6 Y0 A
<><FONT color=#0000ff>int count=0; </FONT></P>7 e  j4 j5 C+ ]3 Z" w' D- f5 X
<><FONT color=#0000ff>void interrupt handler(void)
! G3 d/ l9 m9 l1 o( s{
  z7 Y0 F& E3 {: O% \/*
) I; m2 _# P; ]5 _/ D& Edisable interrupts during the handling of the interrupt 8 U8 }' X0 l5 S# _! v, B* Z
*/ " D$ f/ V% G" `# r
disable(); ; ~/ M6 A- D9 R3 ~2 y0 W7 Q5 S' a
/* increase the global counter */ & e: S9 |, Z, }' U: ]# N3 o
count++;
9 |/ D4 b9 }8 j6 s3 D+ _* r/* ; H4 V3 w# U0 |6 X8 U3 U
re enable interrupts at the end of the handler
3 m# r' Z+ {+ Q*/ & M+ h$ \) i" m  M
enable();
$ Y$ v8 O# d% X! R/* call the old routine */
* [. s# Y5 ~! V, u! q8 woldhandler(); : T: H$ ]# [; E. ]6 y3 L& P4 x
} </FONT></P>- ]0 d& I+ E% n* G0 @
<><FONT color=#0000ff>int main(void)
! S6 ]; C% Z& @4 P1 }{
6 Q! ]/ q0 X. E& C0 W6 c/* save the old interrupt vector */ ' f. }6 T3 m! ]; b; t
oldhandler = getvect(INTR); </FONT></P>
' X( g1 a' `3 ~" A& W<><FONT color=#0000ff>/* install the new interrupt handler */
# x, l+ P$ k6 \3 rsetvect(INTR, handler); </FONT></P># c/ e6 ~% l+ }( O
<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
3 ^# m4 s( T8 B. q/ gwhile (count &lt; 20)
7 s1 e) G% b) {0 j& c. rprintf("count is %d\n",count); </FONT></P>
9 j0 r( i$ M) Z5 f) N<><FONT color=#0000ff>/* reset the old interrupt handler */ + h" f9 @1 v6 X$ j1 D" L
setvect(INTR, oldhandler); </FONT></P>5 |6 ~7 g3 ~# ]) t4 q! H
<><FONT color=#0000ff>return 0;
0 o: B8 k4 `/ q/ |  d} </FONT>) Y7 X8 f3 T( ~+ `; R* S
8 [* g( M. m. k; n) i  t  F% K5 Q1 i
</P>0 b2 d1 G# {% Z/ R# r
<><FONT color=#ff0000>函数名: eof </FONT>2 q- Z$ F% ?/ o- \
功 能: 检测文件结束
) b- {: I' W7 K* ]& V用 法: int eof(int *handle); 2 H9 B- O# n+ r
程序例: </P>
  m+ H8 \% A2 |2 W  ~<P><FONT color=#0000ff>#include <SYS\STAT.H>" \" e1 R- N' k) H% }  d! d
#include <STRING.H>5 U2 N/ W! K- ]9 h
#include <STDIO.H>
5 }8 b; l% O+ |. h#include <FCNTL.H>
2 Z1 u9 D1 w% ^0 W#include <IO.H></FONT></P>
' N7 W, D4 E# ?: }<P><FONT color=#0000ff>int main(void)
7 C2 F4 M1 Y: W) B& X; j{
( `+ C6 |6 r; i5 l+ _. H# Lint handle;
8 ~6 W$ U" d$ D& G8 Q0 p. Bchar msg[] = "This is a test"; : N7 B" V& u$ f+ G9 ~+ h" e4 C1 ~
char ch; </FONT></P>
( ?, m: i$ g% J) j6 w1 E* [- K) w# T<P><FONT color=#0000ff>/* create a file */ * Z: y& L9 C& g' V" D
handle = open("DUMMY.FIL", / J5 D' u$ S: b1 a5 Y8 a: a, o
O_CREAT | O_RDWR,
  _7 T- B* `; M/ j% D- S( C. U, [S_IREAD | S_IWRITE); </FONT></P>+ d% F& l0 h& z4 K& j" X; d! `) z  B
<P><FONT color=#0000ff>/* write some data to the file */
) f, h! B& G6 A0 k" A  v- m  |% u) p9 mwrite(handle, msg, strlen(msg)); </FONT></P>
- ]7 I; x( E7 j" O* b<P><FONT color=#0000ff>/* seek to the beginning of the file */
0 Z8 v/ q; y) X- |( [# b2 ^, [lseek(handle, 0L, SEEK_SET); </FONT></P>9 m" A) Q& u" @4 \& @/ l9 X& X' S
<P><FONT color=#0000ff>/*
: ?* G/ A# _9 vreads chars from the file until hit EOF ' M. S( H$ e& W8 ~: @% H. @& m# h
*/
& N+ x3 h) n' y( [9 _. T( g7 ?do + p9 I+ E3 q) W# _' k
{
4 E5 Y( s& r( Z+ j' [/ e  Dread(handle, &amp;ch, 1);
8 D( I7 m# w+ zprintf("%c", ch);
- r8 v' D% e0 \7 M* _0 q! r} while (!eof(handle)); </FONT></P>0 d- x2 A0 b" p2 b4 N2 j
<P><FONT color=#0000ff>close(handle); ! p* E4 v% E& I4 O* y, m9 V6 R% Y
return 0; - F  h0 t, d+ W9 I2 A
} ! E1 H$ q  F# z$ ]$ V4 @
</FONT>1 |/ @+ d+ b8 s. }# O' T+ s  u: A
</P>
; e0 N  s) |2 d' N/ P/ K" n4 j<P><FONT color=#ff0000>函数名: exec... </FONT>
8 u# O6 j( ]: b' ~  l& m功 能: 装入并运行其它程序的函数
( l( W% N  g5 V8 ]用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); . R- V" d' o3 {" [. ^% _  r1 s
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
8 s# n5 W- S' P( t* Z& uchar *envp[]); 3 o- w2 N" n9 c  D! L& v0 x9 R
int execlp(char *pathname, char *arg0, arg1, .., NULL);
: b* x8 v2 W% J; m1 }2 a$ i4 {int execple(char *pathname, char *arg0, arg1, ..., NULL, 5 R* Z3 A% n4 O) P
char *envp[]); 6 ?) K, h$ |5 H! {2 i
int execv(char *pathname, char *argv[]); 8 ]4 K% v% N" ]
int execve(char *pathname, char *argv[], char *envp[]);
9 R% I, K, A9 O4 q( `3 O. I2 L# L$ Hint execvp(char *pathname, char *argv[]);
) {6 ]0 m( y3 I2 ]7 o7 {8 ^3 ?int execvpe(char *pathname, char *argv[], char *envp[]);
& s5 A+ k% N6 K4 T$ t程序例: </P>
9 R  D7 B8 w. o2 F<P><FONT color=#0000ff>/* execv example */ * I, ]7 v% v7 m3 w# \+ B
#include <PROCESS.H>
5 L$ y, T1 @( [8 t$ t#include <STDIO.H>
! X* y9 Q0 @$ v) P, J#include <ERRNO.H></FONT></P>2 |( b! y% R4 s! B: T# @) j, [* C
<P><FONT color=#0000ff>void main(int argc, char *argv[])
: w1 n7 P! d# R$ w+ {. P: H4 C1 \{ * o- r6 h; h- G1 i5 U2 g0 h
int i; </FONT></P>
9 A3 c- i$ P: K" t8 z1 a<P><FONT color=#0000ff>printf("Command line arguments:\n");
$ ?' B9 ], ]+ P5 t  y5 Hfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>% j% ?1 M" Z+ l# Y8 m
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); ; ]  A1 q0 u* M- l9 `# g# @+ U6 A6 S
execv("CHILD.EXE", argv); </FONT></P>  n8 r7 q+ I6 x3 W1 o! P: }, f
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>0 X$ }4 W) F2 K1 ]
<P><FONT color=#0000ff>exit(1); . P: }- n* Z" w9 d  S
}
3 z/ [1 o% X) H# V1 K</FONT>
2 l4 E" F  ~7 Y- A! ~5 e0 q$ h- v</P>& t/ L/ W  y2 z4 o
<P><FONT color=#ff0000>函数名: exit </FONT>0 c& ?: |! H. Q9 ]% F. t5 q
功 能: 终止程序
# L2 H2 ^1 U, _* O1 W5 U用 法: void exit(int status); 8 S. Q* r" }# t; E$ J
程序例: </P>5 q3 d( m5 {: D3 t! i5 v
<P><FONT color=#0000ff>#include <STDLIB.H>5 f5 a. s' }# e$ {
#include <CONIO.H>
% J4 [1 k: ~* }8 m& ?( s3 l# j7 z#include <STDIO.H></FONT></P>
# A: S: p$ H9 P6 A) p- L4 P+ v<P><FONT color=#0000ff>int main(void) - E" o* s, f8 H% F3 v: t0 i5 Z
{
' J1 f( U7 J) @& K9 v5 Qint status; </FONT></P>: K$ c$ |+ J- G$ u
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
! S/ }4 t& v% w1 |status = getch();
! f: A$ R1 @8 T" @- x5 _/* Sets DOS errorlevel */
+ J, ?# U# L- V1 m# ?exit(status - '0'); </FONT></P>
7 ^: }/ ?# p' L<P><FONT color=#0000ff>/* Note: this line is never reached */
( i& I0 C6 M# S+ Y9 }# areturn 0;
7 }- i. M5 m( k! Z} 2 k: y3 r& k# Z+ G& G% Z) `" R1 m
</FONT>
' n- T/ a( f& f: b</P>
! K, c  u5 u- D0 S<P><FONT color=#ff0000>函数名: exp </FONT>( n5 @' t: r/ H1 a
功 能: 指数函数
& G: B7 Z7 O! ^' s9 r7 ~/ b- R用 法: double exp(double x); 3 m) r- ^& x5 A* S  L
程序例: </P>
; o, G% v1 a( V" J( {<P><FONT color=#0000ff>#include <STDIO.H>
. O8 ?0 j) m/ @5 [: u( v1 r#include <MATH.H></FONT></P>
6 [8 a/ O, o# G) S- z- M<P><FONT color=#0000ff>int main(void)
; w& H. N5 k# o, b7 {) C0 ]{
! o0 p. _' F; p2 f; k  adouble result; 6 n' r9 W- m" i. q
double x = 4.0; </FONT></P>
+ I3 h% l3 y" w" y; @# O<P><FONT color=#0000ff>result = exp(x);
8 D* Q/ [/ x5 W% |printf("'e' raised to the power \ 8 u3 l+ f% z. V! R
of %lf (e ^ %lf) = %lf\n",
+ z; S* x" }. \/ Q) F/ X  \* Ax, x, result); </FONT></P>
8 o$ l- `, D" _9 b$ |<P><FONT color=#0000ff>return 0;   a1 m% ]$ ?0 q0 z# y6 B
}
/ A9 q, D+ G- _- B& O" 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>
4 ]) K* D2 q5 I! g  G  ?0 R6 {</P>8 V4 B$ W2 y8 h9 a2 ?+ K* X
<p><><FONT color=#ff0000>函数名: delay </FONT>2 N1 y# \) I  T6 q
功 能: 将程序的执行暂停一段时间(毫秒) 9 K; k8 _$ o) E& R. I
用 法: void delay(unsigned milliseconds);
- q5 L1 g6 J. H程序例: 8 P: g3 ]1 ~4 s& y# C& c
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
; z6 Y+ e, ~9 p" G; o3 V#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
  X/ a& ~$ j) p2 D4 [; C{ " S4 ^9 Y  E/ v; q& f1 n
sound(440);
7 J- s1 k' y! B* Kdelay(500); 0 `( D8 p' V( t
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
$ X  a8 i) _  c- E% x}
! {$ V8 u  f0 E9 A
+ J* u1 W/ I5 A</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>- v2 B) c, j' N% T
功 能: 在文本窗口中删去一行 $ K" r" M' X$ C3 v, N0 Y4 j
用 法: void delline(void); 8 l: J* O) I; j& X# w( ^! j& \( L
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
  o8 a7 p8 z  g+ t+ M; b, Y{ ' C: k  a! Y% p+ u
clrscr();
9 \; v" T" y( C9 ]9 ]% @cprintf("The function DELLINE deletes \
/ `. k$ ?  d2 T1 @; i  Fthe line containing the\r\n");
3 e% p- m% F5 F5 J; h$ Rcprintf("cursor and moves all lines \
$ G5 }# U" U3 v5 x! h0 \. Y+ ]- e0 Nbelow it one line up.\r\n"); & |) R2 s4 {: O' ~- V  Z4 ]
cprintf("DELLINE operates within the \ $ R$ z' X' v0 U# k  K
currently active text\r\n"); 1 d8 o+ z% q! ~$ }4 f8 a+ ?2 B1 W
cprintf("window. Press any key to \ & v5 @! O) ?# @1 y# t+ Z0 }7 w
continue . . ."); # @$ C& A8 q, Z% S9 \' [7 Z& y0 i
gotoxy(1,2); /* Move the cursor to the , {- g; s' A6 [
second line and first column */
/ Z9 `6 f- x$ a9 s) d  v+ ]getch(); </FONT></P><><FONT color=#0000ff>delline();
' W3 X+ D: i+ @' q# F6 Lgetch(); </FONT></P><><FONT color=#0000ff>return 0;   E3 X8 y/ b  x5 B1 j7 c8 V, p
} </FONT>* |5 ^- x! e2 n. l9 a
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
) l$ d% h( L0 t3 e5 e9 ^7 K3 v1 h功 能: 通过检测硬件确定图形驱动程序和模式
" ^  H% K6 I0 u& w" N用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
: P) L+ x' {$ e2 ?程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
6 S$ {, B3 u% F+ i6 C1 ]/ {) Y' }# v  k#include <STDLIB.H>
& g+ g! n9 }' l5 {3 K8 R% |$ L  k#include <STDIO.H>$ G% [. v7 q/ e
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
+ y7 l- f. Q+ Bchar *dname[] = { "requests detection", + w; t: G' a3 [, C4 u
"a CGA",
# N' s9 f  x8 G( d  K9 Z0 Q6 a8 S"an MCGA", 6 e" h. C4 `& w# U
"an EGA", 7 W! a4 [: ?9 x6 e8 c
"a 64K EGA",
7 Z' Y' w( ]% C, p, ]. }8 v9 L"a monochrome EGA", ( [; w. z2 |: Q6 @+ l5 y7 V/ m
"an IBM 8514",
) P6 ]) h* ~6 f7 m( p"a Hercules monochrome", * n7 V; N! a6 @8 y8 e1 `
"an AT&amp;T 6300 PC",
, A3 D3 v  d# O1 y) d% b) M4 Z"a VGA",
- J& L3 ~5 H9 C0 E3 v+ p"an IBM 3270 PC" . r, `  K) L1 ]7 J' U  \
}; </FONT></P><><FONT color=#0000ff>int main(void)
5 }( Z  f4 V9 ~7 Z, k: Y6 {% O{
- f: E  }4 L: M0 A  F- ^/ B* C/* returns detected hardware info. */
& p3 S, ]. G$ \0 `+ S  ~) Lint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ + c* s6 j' a! B1 I$ K
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
5 U) U5 u) j5 n4 A/ S7 m3 Lerrorcode = graphresult(); $ h$ U9 P& T8 f
if (errorcode != grOk) /* an error 3 F0 W7 q8 K7 S& E% V
occurred */
; {7 ^1 @- B; W6 q{
. f7 y! [9 ^. P% W7 J: Sprintf("Graphics error: %s\n", \ 7 w+ c6 L! x9 F5 P" [) ~, q* T
grapherrormsg(errorcode)); 0 |6 K' b0 P, L' V  y# I% h
printf("ress any key to halt:"); / i9 b7 u9 p9 l
getch();
' ]' K4 u% r. w# X  F0 X- }0 q; Kexit(1); /* terminate with an error
/ ^5 a$ v. Y0 k) a# e9 I" }: Scode */ # X( p& t3 M. A; J8 c
} </FONT></P><><FONT color=#0000ff>/* display the information detected */ 2 k- Q5 ]; J- F7 W( E$ ^  h5 L
clrscr(); + ?; Y* W2 }7 h' |
printf("You have %s video display \
- J; i$ }! b) x3 jcard.\n", dname[gdriver]); & Z4 E) G/ o. Q6 f& r& ?
printf("ress any key to halt:"); 3 X8 B$ {/ `7 ~8 _
getch(); ) J" o, M' a! o2 ^5 p* G0 O- S
return 0;
9 F+ t8 U% g, \5 y8 z+ y8 L9 F} </FONT>. a; [, m' S1 H0 z5 n

* c$ t& ?  x; J9 }: Z9 r  K6 [8 V6 r+ l7 E8 k1 C
</P><><FONT color=#ff0000>函数名: difftime </FONT>9 s0 b0 v- d4 v5 X4 r: p! [" P
功 能: 计算两个时刻之间的时间差
! {: O% r& x  m- K' i用 法: double difftime(time_t time2, time_t time1); ' ?0 t% W4 z( r" J0 _& \
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
7 ?, M7 m$ W1 X, y5 T4 \2 g- X& V#include <STDIO.H>, v" p  s3 V6 _- P/ A
#include <DOS.H>
& E/ M6 V0 P$ ?8 W#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
) G, x3 I1 Q+ Q- l{ 1 W; z, }* H9 {# P
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); # g# R- v/ K) W. p! ^+ \( _9 s
first = time(NULL); /* Gets system / W( B/ |" V' d4 R' p
time */
8 k/ z: o# i8 y2 qdelay(2000); /* Waits 2 secs */
* \" ^  j' Z$ R  m# o/ dsecond = time(NULL); /* Gets system time
) f3 k  d. S( }1 Iagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
# I, h+ u$ _& Z& B* Useconds\n",difftime(second,first));
4 Y; `# _$ F1 g7 P6 Kgetch(); </FONT></P><><FONT color=#0000ff>return 0; ) c& ]8 a" Q4 J7 G4 X& T7 b
}
5 |3 ~; }3 i/ t: d: c</FONT>% c, T) t& Q( h8 }- ~1 {
</P><><FONT color=#ff0000>函数名: disable </FONT>3 y+ {% v4 d+ J& t$ I. S# i, B: u
功 能: 屏蔽中断 7 z+ Q4 R- Y! r; {. t4 I
用 法: void disable(void);
/ n9 Z+ f3 ?! R& {1 L程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service & A6 O+ S5 s0 M3 U
routine. You cannot compile this program
& D/ t9 Q' \* ~with Test Stack Overflow turned on and / s, z+ T/ S5 E/ |
get an executable file that operates
3 v3 k) \' M; ]6 _! y* s9 a- E. Gcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
* r8 {  @) N# J#include <DOS.H>
- ^1 @/ W1 P! F( O) O3 E0 C#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
7 B) w! o8 {, kinterrupt */ </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)
; d9 g, P' h$ ]" K8 ^) E3 p{ - e/ U9 W# K4 x9 [; A
/* disable interrupts during the handling of : @  T. n( C! ^
the interrupt */
$ s# r- Q% ^" R" |disable();
9 M3 Z- z+ G. i/* increase the global counter */ 0 S3 |9 z( g- A4 u
count++; ) y6 j; J, J8 ~5 `& A1 I
/* reenable interrupts at the end of the 0 N: ^6 D9 [" D. m0 M2 z! l0 m
handler */ 0 e; j0 q9 A, f% N1 I! O+ C
enable(); 5 q% b% A/ F  \
/* call the old routine */
. v, s+ \/ y9 w: [- poldhandler(); * V% a& B  q) @- t
} </FONT></P><P><FONT color=#0000ff>int main(void)
. A0 X+ o# L4 X, ^{
! Z+ e- S9 n; t3 Y, k" `/* save the old interrupt vector */ $ p1 L& N/ U! s& [4 I
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ + i/ A1 c+ H+ }  h& [2 P
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
" _/ z/ Q  ]! R. C7 `while (count &lt; 20) " L7 N- D# Z. b, _( V
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
$ s. Z. v0 _+ p' j  T  Esetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
  ^+ f( c0 j' H} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
# M+ C. g, h* l0 v) D/ Z功 能: 将两个整数相除, 返回商和余数 1 r1 o# y) u# C8 l
用 法: div_t (int number, int denom); , \) k' J; ^: @' j( Y6 Q, Y7 p
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
) W. h, J& f- X1 W4 i% ^4 m* [#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 7 F" k! t. _  d9 D8 d! {
{
5 w9 A; S( a$ [: U/ X% qx = div(10,3); ( E% p, y+ v. _8 C! |
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
: g/ u3 N) x% O3 f}
5 Z& R+ I8 R0 I</FONT>
: ^) C: d, ~% o</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>+ I( N2 v* G$ e  S4 M
功 能: 获取扩展DOS错误信息 - N2 c: V5 N5 q" _/ d, A5 I5 T
用 法: int dosexterr(struct DOSERR *dblkp); ) j4 G- E. E- `0 W) w) C. w$ D
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
4 x  f# H! D% E7 A- N% I#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) 9 ~  g; x* |$ Z& d! l
{ 4 S- T! W6 e+ Q3 B
FILE *fp;
) Z& ^5 x7 T0 F' {8 q$ pstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
6 J6 g; \% T( t* L- aif (!fp) perror("Unable to open file for % H( }. f, T5 {9 G. y
reading");
" u- B/ E6 J+ }6 y) d$ Odosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ 8 T$ Z* ~9 g- Z7 x8 a7 ?7 p
information:\n"); 8 u* M" W, P% z2 h
printf(" Extended error: \
) h: H/ {$ Z4 S1 X8 C2 w3 [%d\n",info.exterror); & M5 k4 K" K6 [1 M+ ]6 b5 V/ L/ Z+ ^
printf(" Class: \ % o+ t; G# `3 \8 c5 ^% e1 Y9 u4 h
%x\n",info.class);
- c5 d" ^7 {$ W% c2 wprintf(" Action: \
0 M3 U% D. H' t+ p' T%x\n",info.action); # N. X0 Q  M6 X8 e  R$ H7 d
printf(" Error Locus: \
& l6 Y8 u: E0 w5 ]%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; 3 W3 x8 j5 @& c
} </FONT>" q% d- F4 Z9 r
- t: @* L& y" `9 k9 T
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
, }. l# ]. a  p5 w功 能: 转换日期和时间为UNIX时间格式
$ m9 D# o5 C2 J5 T. b用 法: long dostounix(struct date *dateptr, struct time *timeptr); ! N% R! C7 \) a: {# u$ @
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
0 I. z! q5 O5 v2 C#include <STDDEF.H>
+ W( f  H/ ~- g6 x1 U#include <DOS.H>( ^9 }+ w: J3 @5 x8 O& l
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
& g5 Q0 z$ I. d0 v# |{
( X" c2 L7 O" v% itime_t t; 7 [0 ]& {2 C+ c  v  n) o
struct time d_time;
  n4 Q2 {) u) W. a  @struct date d_date; 7 ^$ l4 n3 m* _
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); 7 B) @; u' j7 q% O7 W9 z0 e  b+ Y6 U
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
* u! w7 K( B3 ]% n' J9 i/ Z& mlocal = localtime(&amp;t); 2 s3 C1 U" ?% J9 ^) i& g  K6 D
printf("Time and Date: %s\n", \ 8 @  ?7 H: l0 B0 m& [5 }; s
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; 8 A; c1 d2 A% f
} </FONT>
# b4 q, S( D) ]8 z' y' s* J. U& V8 n. S$ a# k0 v
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
; a3 I2 a& F3 W# J0 l功 能: 画多边形
4 A8 l( O6 B& w6 k7 t/ e, \用 法: void far drawpoly(int numpoints, int far *polypoints); ! P, O6 [3 T: ~# K& Y
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>
% Z, s) i. z! }#include <STDLIB.H>
. Z1 g0 ^. I1 d8 p# y6 d' G5 ^1 p#include <STDIO.H>
9 x% b1 c2 k  s0 D#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) : x8 H% D  e( X9 Q( H
{
: z: ^9 k( O7 i% ~" j( p8 u! K/* request auto detection */ $ a3 o3 y. I8 b& D3 J/ v1 y" [) D
int gdriver = DETECT, gmode, errorcode; - K8 ]9 j+ t" b* _; F1 }0 g+ |6 _
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
! ^1 [" W! A& z! ^0 w9 l( G! vint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local , h$ h" B- j6 \. U; @
variables */ " T  c& A0 k& e+ r; H$ p
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
$ u& t9 g  W7 F" herrorcode = graphresult();
4 |( x3 ]4 |, i( i) u+ @if (errorcode != grOk)
" h, I: x$ U/ Z4 w5 B7 |) {1 h/* an error occurred */
( l6 A! H+ A& x3 i- J& x{
* J9 E9 h. c$ i" Nprintf("Graphics error: %s\n", \
; L0 D3 {! b# s: y" Pgrapherrormsg(errorcode)); % E; ?# X9 e( Z0 |" l
printf("Press any key to halt:"); 9 L6 B( n4 H) j: F$ \0 H& D
getch();
% S5 R4 p/ q$ J" A! D/* terminate with an error code */ , G7 x$ M2 I* k, B5 q
exit(1);
; ?& U" l  a$ s} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
6 Q, T! ~+ a' }- Y/ ?0 kmaxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
6 w( Q: d4 ?6 _8 s, w# E' lpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ 5 t- k; u& u, [0 j" k
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ " i6 h% Z8 x% A. P
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ - @' Z8 i2 h8 m; C: Q  d
poly[7] = maxy / 2;
* z1 a! i1 r  A5 w3 k/*
2 h! x5 t2 o& Y+ a" s* @- rdrawpoly doesn't automatically close
' V( O2 k, _+ E* ~9 _4 sthe polygon, so we close it.
5 V; c8 h' f2 l) g$ f+ w1 ?*/
( i" e, n+ A3 r5 y* y- U* H  ?poly[8] = poly[0];
$ I/ Z9 k( B3 i4 I) epoly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
& C# ]4 l; L, {: I$ E+ l0 a7 [, ]drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
9 S: D& i8 _; e8 L. hgetch(); . {3 p5 b1 w1 [
closegraph(); - B6 ^6 m# n& C- U8 }. j
return 0; 4 m3 [# D( C5 J( }" X
} 1 \0 h( k/ l/ r- F* z( E1 A3 E
</FONT>! O% r/ B- J& @
</P><P><FONT color=#ff0000>函数名: dup </FONT>
1 K  m  c3 Z/ f3 e) `& |: e功 能: 复制一个文件句柄
6 v5 t4 a  c% k& o用 法: int dup(int handle);
5 X% T' x4 `7 q* p8 A+ ^6 I$ V8 _程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
6 t+ B% F8 Z- R  `! q7 w5 Q, m#include <STDIO.H>9 U. P# n3 j4 t; ?% I0 r
#include <CONIO.H>7 I2 r. w$ j$ M" N4 L
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void) & h. i, u6 L( l! R
{ ) F: u; D, v+ e. P
FILE *fp; 6 x! V1 }! @8 V$ s0 a1 ^* ~5 [
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
6 o4 y) l  G* X$ ^+ o% I! _: x# Hfp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ # e5 _  H6 x" H$ D5 x, n
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
2 f) x+ K/ k5 G0 q' V4 X7 lprintf("Press any key to flush \ ( l, j4 Y, N! u. B* E& c
DUMMY.FIL:"); ' S! o/ t. N- x5 ?  M# S* O
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without : l0 O' w1 m2 I+ u
closing it */ ) |5 R2 K! @) |2 h
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ 8 W7 ^# @/ [5 |' H
key to quit:");
% Q# W& B8 k; ^3 n0 N1 ngetch();
. k: z, _; m3 Freturn 0;
4 E: X& [; ~% ?# c" ?2 j9 h/ _  A} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) 5 V+ n  ?/ C  y8 N
{ : y& t2 S& u# S4 u. C6 ^
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ ' {! t4 c6 N- \
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ : i+ Z5 S# P( b8 ^
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
6 k" r- ]- T% }5 }DOS buffer */
6 r# G% w$ u# t3 X7 ^: H; N( E) |close(duphandle); - h3 g! @+ R4 k" l4 s/ I6 a
}
4 C$ h; v- P8 j) w+ B
) \% E! W( ^" n, ?5 |& y5 V7 y5 [: q</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
, _9 T' I" Y0 N& t4 R功 能: 复制文件句柄
3 b- E1 F) L2 u/ c用 法: int dup2(int oldhandle, int newhandle); $ T+ r' M5 w% P4 m+ y9 _/ G/ p* v* [
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>& ^2 H9 S% }1 o) D) Y1 ^
#include <STRING.H>; ~& _. v4 U' z( x. e+ E6 v
#include <FCNTL.H>
* P$ Y+ j9 l& j& b4 m#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
& X7 h- x" i  H3 L0 J{
8 K) u# Q& n9 O5 s% W8 \0 A5 C' l#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
; g6 |0 Z5 i3 u. Lchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
  g$ R# q7 r; N. D5 ?1 x( znul = open("DUMMY.FIL", O_CREAT | O_RDWR, & B% J$ N- g7 g; P
S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
. t3 T3 N4 {% p4 h, a( V/ {: Aoutput */ ; h7 y$ C, `* q6 D
oldstdout = dup(STDOUT);
1 ~# |, P8 r( r/* ! F8 l9 f% f8 B6 N$ ~
redirect standard output to DUMMY.FIL : \  S, o( q1 O, `! o
by duplicating the file handle onto the 7 k9 v* u* h# L$ |: V
file handle for standard output.
) ^  ?$ R4 O* c- E6 z*/ 0 ?, _: V$ V9 p- v
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
% Y% H4 H' ~: I6 sclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ : n& |3 Q: B6 l3 a" w+ \1 ?
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
, G6 A; {! N1 e# O( z9 `handle */ . f7 C0 v6 k4 Z' O# g1 y  X3 x
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
& e3 F# V. n' G* \close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 7 A8 V9 N$ M4 T0 M$ l
} 3 T, r" r4 X% H- `/ g7 e
</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 01:38 , Processed in 1.016604 second(s), 56 queries .

回顶部