QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2064|回复: 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>, Y- C1 H2 D6 S- t3 {# ?: ~
</P>. B3 ]& @' |" g
3 K: Z& D' B% }" L) ?+ i. A, W

' p4 A7 s5 ?# |# m1 [/ o' k/ g& m<><FONT color=#ff0000>函数名: ecvt </FONT>: b5 w% m# E6 ]+ D7 `
功 能: 把一个浮点数转换为字符串 ! l& w# s% A; o+ q# @
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); ) h6 L+ ~, s* b4 ^
程序例: </P>
; _( t9 H% X8 G( H5 }<><FONT color=#0000ff>#include <STDLIB.H>, Y4 |# h7 c8 n3 F: \/ v( e- m$ X! B
#include <STDIO.H>
. Z1 Q6 }* u! d1 {" T% R6 U6 K, V#include <CONIO.H></FONT></P>6 ^# w" z/ `0 y, w  S; }
<><FONT color=#0000ff>int main(void) ; [  p0 y$ X! u( F1 [) R% k/ S
{
# V. @6 R/ i; j2 r& u$ }8 Dchar *string;   _& E1 K' e+ J1 [
double value; " v* ?$ C3 v7 t
int dec, sign;
( p$ x) B& v1 V: n( V% M7 ]2 ]1 _0 Vint ndig = 10; </FONT></P>
5 [, L9 q* f9 n* y* J1 V+ p<><FONT color=#0000ff>clrscr();
6 S3 E* u3 V# r% }8 }value = 9.876; ! e4 W, b8 t/ G
string = ecvt(value, ndig, &amp;dec, &amp;sign);
$ h4 c" B9 i0 @9 Vprintf("string = %s dec = %d \ , k1 b- E, T! Z% l' A+ @+ p
sign = %d\n", string, dec, sign); </FONT></P>( {* e" v3 [& t# R1 v  e
<><FONT color=#0000ff>value = -123.45; 4 k' M) O$ R7 e0 l; ]
ndig= 15; 6 i# \- T3 M$ w# E' T
string = ecvt(value,ndig,&amp;dec,&amp;sign);
) |8 B: ^  l- Y( kprintf("string = %s dec = %d sign = %d\n", % l+ v& j6 T3 H; i$ w. h% A8 u( @
string, dec, sign);
4 x, L" z) y& k* @</FONT></P>
3 G  c5 p8 C( _! I) Y<><FONT color=#0000ff>value = 0.6789e5; /* scientific
2 Q8 _% [& L/ p6 \1 E+ a: h* _notation */
) v0 n! _1 q. ^! t) w. _ndig = 5; * q1 j7 p( s% F. p/ ]
string = ecvt(value,ndig,&amp;dec,&amp;sign);
" Q  l& }  }: a" |+ v, `' z4 Q7 Kprintf("string = %s dec = %d\ ; c# X; R" o" I/ J
sign = %d\n", string, dec, sign); </FONT></P>
( P, J# Q, h! {3 i% L/ ^" T<><FONT color=#0000ff>return 0; ( r0 f) g2 I6 h4 B% W% x: P
} </FONT>* n9 o& K* v# S* w5 _& [
7 P: ~9 e: j, o8 `/ E* ~5 N
</P>
! X8 Q8 r: F6 i7 a& H<><FONT color=#ff0000>函数名: ellipse </FONT>" J" s$ w8 C6 R9 h* i# U" V# z' \
功 能: 画一椭圆 * I& F- E0 p- f
用 法: void far ellipse(int x, int y, int stangle, int endangle,
" E8 c$ i9 Q" a* p: Hint xradius, int yradius);
# N( U! p5 F8 p7 b# t% L; d程序例: </P>+ ]8 E" x% S+ ^( |2 B
<><FONT color=#0000ff>#include <GRAPHICS.H>
+ j- K! h7 Z# @" J#include <STDLIB.H>
7 e+ v5 \4 l* C#include <STDIO.H>
. Z; W/ N! A6 {6 W+ n#include <CONIO.H></FONT></P>+ I/ }4 _/ I1 c* u; B, D0 p! m
<><FONT color=#0000ff>int main(void)
+ C( H7 H2 N6 J$ \* K$ i% u{ 0 \6 j6 Y+ |3 H1 j6 @! Z
/* request auto detection */
' Z) k6 u) n/ i$ F6 b/ J7 }int gdriver = DETECT, gmode, errorcode; 8 }$ `+ B- \8 Y& I. q6 D1 j
int midx, midy;
- d8 u; {1 E$ a! ^5 ]; A: i6 a& Lint stangle = 0, endangle = 360; 3 M8 t& \+ [8 n/ S% m' f" U
int xradius = 100, yradius = 50; </FONT></P>
0 z+ I9 S- a4 A1 v) i& O8 Z<><FONT color=#0000ff>/* initialize graphics, local variables */ & ^8 c! c5 X# T1 K8 k$ R, _
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
% p+ X" ~7 F) L<><FONT color=#0000ff>/* read result of initialization */
  Y& A# z, g' perrorcode = graphresult();
/ [; u& s, F7 ?  }# Qif (errorcode != grOk) + p1 V. n7 y1 R) G
/* an error occurred */
* r& f  c% g; d! l/ O{ & c  B  V% ~3 t; F
printf("Graphics error: %s\n", # E9 V; w: L* T( l* p& t0 M
grapherrormsg(errorcode)); 8 n% T  M3 s  G( x1 j7 V
printf("ress any key to halt:");
, R2 p* [, M" ^( J' rgetch();
6 R0 l/ O( J3 B/ q% L5 j( S9 o/ w" texit(1);
; D% n0 N4 H5 R3 W; Y  k/* terminate with an error code */   R+ O; D/ g6 U& T# R
} </FONT></P>5 T1 w9 p( q/ B$ `- s
<><FONT color=#0000ff>midx = getmaxx() / 2;
) |% c, a5 o7 C3 \; Y* Pmidy = getmaxy() / 2;
) u* }& {: E8 R8 nsetcolor(getmaxcolor()); </FONT></P>9 I, W6 o4 `/ \0 l
<><FONT color=#0000ff>/* draw ellipse */
/ w# a) }% K# \ellipse(midx, midy, stangle, endangle, 2 p2 y+ W, s2 U. u
xradius, yradius); </FONT></P>4 G; Z/ J/ p+ @
<><FONT color=#0000ff>/* clean up */
1 x  o3 G8 d+ M8 w; i5 k: Vgetch();
' P) W* `; o5 Tclosegraph();
8 V1 X; H& n- G8 Sreturn 0; ! @* w, F* S5 n/ F8 i( X
} </FONT>1 d7 P0 I8 W$ f( r& j" ]

6 z! M; S: ]1 J5 ]+ Y& v5 G* {</P>6 g1 w5 f* b; o! E( V5 g# U% c
<><FONT color=#ff0000>函数名: enable </FONT>  b, A6 u* y9 A. H1 G" `9 J
功 能: 开放硬件中断 ( Z/ v5 i  i: _
用 法: void enable(void); / J( p8 h- ]6 k
程序例: </P>" \; ]6 J( t2 K9 w5 J! K
<><FONT color=#0000ff>/* ** NOTE: % J! _% Y0 w6 A. c# N+ q
This is an interrupt service routine. You can NOT compile this program
- h+ k2 B( y8 @% W. L- Swith Test Stack Overflow turned on and get an executable file which will
! u6 ~! Y' o& f% I& L4 hoperate correctly.
; n+ r. r. Y, g  i( D1 n+ M3 F  I4 V*/ </FONT></P># Y/ V8 i6 r9 z
<><FONT color=#0000ff>#include <STDIO.H>6 n8 \9 [/ U$ Z5 o: [! `
#include <DOS.H>
2 T# r/ l- y2 N) s; U$ v6 _#include <CONIO.H></FONT></P>
* V, }) B( s7 w( s  Q+ Y$ _<><FONT color=#0000ff>/* The clock tick interrupt */
3 k# c) g, R5 C! j' ^#define INTR 0X1C </FONT></P>* W) X! ^# O  J7 r* k
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
3 O, s6 l8 l( y$ Q- I<><FONT color=#0000ff>int count=0; </FONT></P>7 m/ x" G& y9 k6 I! n
<><FONT color=#0000ff>void interrupt handler(void)
3 m9 x, f+ ?. p' Q/ R1 y2 x{
, l. @8 R$ @; b" i: M2 p! ^  [/* * p9 @7 T6 |4 W6 B7 T
disable interrupts during the handling of the interrupt
- B" J* y+ {3 b( ?*/ # w: t. M; X4 D
disable();
& j/ j7 n: S/ D0 Q! H/* increase the global counter */
- J2 j% Q) a6 w: w- y4 w/ c$ w* dcount++;
: P2 a( M$ f9 J4 _* n. j; T# ~4 {/* 8 ^4 O3 B/ K3 b; B0 C
re enable interrupts at the end of the handler 7 F* c" [, [8 X. k
*/
9 e1 p6 y8 M. ^enable(); ( z, t( n, r$ M+ p# ^! N: l
/* call the old routine */ 1 g9 r" X+ h2 S5 U* j' B& J  P+ P
oldhandler(); 6 p7 ~6 V8 h9 v1 O
} </FONT></P>
$ t% v& h; t7 q- k0 Q<><FONT color=#0000ff>int main(void) ; w4 [3 B* w7 d. i& b# @* y! T  M
{ # S9 R" w% d5 a! U9 F+ b
/* save the old interrupt vector */
5 B' Y: B# G4 {0 E$ M7 }/ [oldhandler = getvect(INTR); </FONT></P>
) u4 u, m1 q$ u( V& ?( z& }<><FONT color=#0000ff>/* install the new interrupt handler */ . D% T) \! v, Q, k9 v7 V
setvect(INTR, handler); </FONT></P>
3 ~) |7 C# n) K2 O8 V<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
& \8 g) {) r- K& |5 @+ cwhile (count &lt; 20)
3 B( _4 X7 a- R& v9 Oprintf("count is %d\n",count); </FONT></P>8 {0 L" I& ^1 L! t, `; |
<><FONT color=#0000ff>/* reset the old interrupt handler */ : ~5 k: Q$ V  Z; }9 ?
setvect(INTR, oldhandler); </FONT></P>6 p  r; }" T$ u- Q2 u: O8 `
<><FONT color=#0000ff>return 0;
( e! }$ F4 j3 ?7 ^5 s' c. \! [} </FONT>  z- m" `# F1 j  ]5 c

$ ^9 N! g/ s8 O7 ~- z</P>
- _( |6 h5 x% J# h* F8 O4 u<><FONT color=#ff0000>函数名: eof </FONT>
$ D8 P' h# X& r$ T9 o' Q* e功 能: 检测文件结束
( C6 f$ ~, X' U- r用 法: int eof(int *handle);
9 D* h% y. k8 n9 T7 j6 ]程序例: </P>$ L8 O" v8 m0 G9 t. h
<P><FONT color=#0000ff>#include <SYS\STAT.H>
- R- w! H  d5 _# L#include <STRING.H>7 t2 f9 u' r. `% v( k
#include <STDIO.H>
+ _  D& h+ k, H# @#include <FCNTL.H>. \; x* X$ e! y, j" B, [2 s
#include <IO.H></FONT></P>
/ {( h4 r, B) j! ~, ]* t7 G<P><FONT color=#0000ff>int main(void) + B8 U9 u% N, C8 t* R4 W6 X% j9 C
{ ! x2 c8 W$ P% Q/ J4 l3 R
int handle;
6 x0 e: a; t8 b$ [7 wchar msg[] = "This is a test"; ; a0 J0 q7 I& D  e" W; r8 J
char ch; </FONT></P>
7 w" Q+ b  B7 u, G0 D<P><FONT color=#0000ff>/* create a file */ " w& U3 K  d' i! U! G  S0 k6 X
handle = open("DUMMY.FIL",
: [: a, R, v5 |O_CREAT | O_RDWR,
" r' I2 n. I! Y- t. HS_IREAD | S_IWRITE); </FONT></P>
/ L, b0 [, Q1 |( @0 V; ~<P><FONT color=#0000ff>/* write some data to the file */ - ^' U: F$ q- `3 V" n
write(handle, msg, strlen(msg)); </FONT></P>0 t/ Z' }& k9 o& \$ h6 m3 ]
<P><FONT color=#0000ff>/* seek to the beginning of the file */ 5 s1 n' h9 _' `! W  P% E
lseek(handle, 0L, SEEK_SET); </FONT></P>
3 @- I$ B' C$ S  k  M<P><FONT color=#0000ff>/*
! v' r$ \& Q+ g% t# M+ B5 Ireads chars from the file until hit EOF
7 ^- [: @' Z( b9 @*/ 6 c+ v2 r: q6 d1 O/ B
do ! [1 D) U# W8 ]1 T/ }
{
; n8 }$ t) `6 y2 S" tread(handle, &amp;ch, 1); ! L2 r9 G  e* \9 k3 W& R% E
printf("%c", ch);
! s8 Z( K) D( J2 T4 N} while (!eof(handle)); </FONT></P>$ g. [. x1 \5 _/ {; T) g# U3 I
<P><FONT color=#0000ff>close(handle); * j# G% ~' @+ E" L- |+ Y0 ~
return 0;
& |+ Y2 Z1 m  X* [7 \3 u& x}
- ~# M1 c7 F) i1 m</FONT>: `0 d2 S* q) N& \3 W/ T
</P>
  d2 Z3 c: K+ Z. _, r7 u<P><FONT color=#ff0000>函数名: exec... </FONT>9 {- L0 }  v% E2 D9 Q( o7 C! C% k
功 能: 装入并运行其它程序的函数
7 a2 Q# [5 f$ e( p7 K; f用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); , _1 u' J' U  P6 v
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, ; n" d) C- I% {4 @: J
char *envp[]);
3 i  x8 z' H% H1 d* Rint execlp(char *pathname, char *arg0, arg1, .., NULL); ' ^; b8 d( s" n
int execple(char *pathname, char *arg0, arg1, ..., NULL, " g" z9 s- T8 X, g% ^; M
char *envp[]); ! v+ k$ j2 o$ t- D9 U
int execv(char *pathname, char *argv[]); % A8 h) p7 H. ?4 @
int execve(char *pathname, char *argv[], char *envp[]);
( R5 `% q! Y- eint execvp(char *pathname, char *argv[]);
( Z" A( U5 Y# K) fint execvpe(char *pathname, char *argv[], char *envp[]);
3 f: p/ V$ c" U( x; b9 x+ H* Y. o程序例: </P>
6 h  F0 {5 T6 B1 w8 M* i/ |<P><FONT color=#0000ff>/* execv example */
* q* F% O2 _3 W0 Y9 v- _# V#include <PROCESS.H>
, r: B* f9 r+ M( l; c#include <STDIO.H>
, b& s! K5 E1 `: p#include <ERRNO.H></FONT></P>8 z. _- {! c& B$ @" r
<P><FONT color=#0000ff>void main(int argc, char *argv[]) 6 A8 s0 O0 y2 @0 V3 h
{
) Z! A6 W* z2 O0 c$ Jint i; </FONT></P>
1 e: |6 B/ S3 N- z<P><FONT color=#0000ff>printf("Command line arguments:\n"); + s& Y0 D8 d9 ]4 x* f
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
6 ]3 H0 ~5 {5 E- m5 e3 y" W<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
: n0 t2 B3 }' C9 R- vexecv("CHILD.EXE", argv); </FONT></P>1 R( l% s' U  b
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
4 n7 c4 ]1 k2 u& e4 P<P><FONT color=#0000ff>exit(1); ! Y3 M9 y, q8 c! Z0 V) @
} # V0 Q4 _' w' Z/ v% r/ ~
</FONT>
8 j9 s2 b2 P+ C4 \8 ~  J5 C0 _</P>
& N; {7 ?5 @4 F/ U<P><FONT color=#ff0000>函数名: exit </FONT>+ w- Y1 q3 }2 t2 U. [6 _2 e  ?
功 能: 终止程序 3 {- M6 |% y6 l5 k- k' _4 J1 J  }
用 法: void exit(int status);
; t: I) ~8 A9 b$ O+ s; R程序例: </P>
9 K2 Y- V4 [7 ~/ W' p6 p0 j6 T<P><FONT color=#0000ff>#include <STDLIB.H>/ W, @# G9 G; A0 I, s2 Y# Z+ Z
#include <CONIO.H>
3 s5 v1 }5 y# C: C; B- o#include <STDIO.H></FONT></P>9 ~9 U6 P. C- `' b  G; b
<P><FONT color=#0000ff>int main(void) $ J6 R* m' y, i
{
7 n3 V0 n. w1 a3 k5 r. zint status; </FONT></P>: }/ Z6 I! c+ I9 a8 i8 _6 V( M
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); ( S+ D, r/ R0 r
status = getch();
) _/ r9 u2 ^; q8 n* c/* Sets DOS errorlevel */
' c% l6 {1 w) r$ Rexit(status - '0'); </FONT></P>
1 V  A, s  B+ w7 P<P><FONT color=#0000ff>/* Note: this line is never reached */ ( M# t6 t+ S1 A8 o
return 0; / C% @8 S" m" g3 k, F2 J; H
} ; Q' A- q- o, L2 D5 f
</FONT>; p' ]; P& W; p: a1 t1 w
</P>  [- `+ j; p. ~4 ^: a
<P><FONT color=#ff0000>函数名: exp </FONT># t: `5 {, x- X% L
功 能: 指数函数
! V& x, f2 m! C+ q& I用 法: double exp(double x);
6 M! h( h4 C2 Q, @2 b* h程序例: </P>7 @$ w7 Z8 O! _, D
<P><FONT color=#0000ff>#include <STDIO.H>7 s7 a- N# d0 ]- }
#include <MATH.H></FONT></P>1 k' X  A9 o) n2 L3 c
<P><FONT color=#0000ff>int main(void) 4 V8 d; G4 I4 k0 a3 `. b' D: y
{
# _; H4 ^5 `' ~1 V: |9 ]5 H+ n  @double result;
' c0 K. v2 g- t* p& ~% ^double x = 4.0; </FONT></P>1 b, @% o* [$ ?# J+ X: q" |7 s
<P><FONT color=#0000ff>result = exp(x);
7 e2 {3 J& ]( W/ N$ T: Eprintf("'e' raised to the power \
/ K5 K) l% ^0 \, sof %lf (e ^ %lf) = %lf\n", " A8 e7 q% J, O9 p
x, x, result); </FONT></P>9 e9 x% {: D7 w
<P><FONT color=#0000ff>return 0;
5 A+ ?, ]$ n8 h}% \' h) @. h) {: W9 L1 W
</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>, ?, ]- O0 z3 T7 ]- C: K. N$ T
</P>1 U- K4 ]2 v4 G' K) Q
<p><><FONT color=#ff0000>函数名: delay </FONT>4 u: }" Z0 i- m5 o: `7 q5 F
功 能: 将程序的执行暂停一段时间(毫秒)
5 s3 i( Y! u; S& U' C1 C# ~% i用 法: void delay(unsigned milliseconds);
3 w( g+ R. T4 A, O" z, z2 ^程序例: 8 G& Z( a; U2 ]: ]4 H
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ + n$ D8 b9 K* @/ V4 S" U
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void)
( {  L8 [7 Y9 A$ W' ?4 r& V& {% m0 M{
7 w. s$ O& B3 g! Vsound(440); . o: h4 ~4 S# `' ?1 T
delay(500); # x+ a, A3 M5 ~" I. \- M, q
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
' d! m2 K+ O; v6 W1 s} ' X7 d) ?" }0 s7 p/ W
" H' B( R: w' I7 {: q) Y5 h9 g
</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>- Z7 E8 }# o6 Z& H: H6 {! j4 N/ j" x
功 能: 在文本窗口中删去一行
+ S/ _: O$ I6 M; s7 h) g6 s用 法: void delline(void); / }, M& j# T  `
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
, ?3 [# v( g1 S2 K' y{ ) c: e) \- o3 ^2 C5 _# D( [; K
clrscr(); - \1 g! N  _! O1 U
cprintf("The function DELLINE deletes \ " f4 s+ N) U8 @4 \: f- b9 |
the line containing the\r\n");
9 j  t. t& z+ X8 X( mcprintf("cursor and moves all lines \
' o' s0 X2 V4 Y4 f6 Lbelow it one line up.\r\n"); ) t# c/ _$ U5 x" f, p
cprintf("DELLINE operates within the \ , |3 d. q; T& e" K. w9 \0 p% U
currently active text\r\n");
, d" B& M2 M9 u2 N( y, J1 X( Bcprintf("window. Press any key to \ - f9 u( A9 I& z! s
continue . . .");
' B0 _: R  |  J5 M  @gotoxy(1,2); /* Move the cursor to the + A0 Y* m7 K  H& j4 N$ A2 L! h
second line and first column */ , _# W+ k. N& Q) m$ m* A: @
getch(); </FONT></P><><FONT color=#0000ff>delline();
5 w7 _7 h! j7 f1 U% S4 [0 |getch(); </FONT></P><><FONT color=#0000ff>return 0; / `( l" L* Y  g: t- Q" U
} </FONT>
6 |+ x6 v" J; z3 l) x' G</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
6 [* y6 @* K1 u+ \! w5 ^0 E功 能: 通过检测硬件确定图形驱动程序和模式
6 Q0 _6 D7 \' F7 w% }7 ^: m用 法: void far detectgraph(int far *graphdriver, int far *graphmode); 4 p4 H0 A( [. Y4 j2 y7 I
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>, \5 @3 q, w/ c+ O' }
#include <STDLIB.H>9 H" F: `6 c' u# [
#include <STDIO.H>! I$ S# r# T' i, b) C4 ^; B" ]
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
4 \  N# ?0 r  d' G9 S- Echar *dname[] = { "requests detection",
& h# l+ S- w; ]  p"a CGA", : ^$ e! H- e2 b) t
"an MCGA",
/ N3 ]/ _* z% u"an EGA",
' P0 t* r- c! k: I7 X. l" [6 J"a 64K EGA",
/ H5 G8 H% Z0 J+ g7 \6 M"a monochrome EGA", , K( _; o6 f$ [
"an IBM 8514", ; Z; _, e7 ^) I8 ?
"a Hercules monochrome", 9 Z7 \2 }5 e! T/ N5 `# u3 L1 p
"an AT&amp;T 6300 PC", ! [. o- G/ m' ]
"a VGA", 2 T: J( D  |+ R
"an IBM 3270 PC"
+ k0 |- }, h; X3 O! K9 K4 A0 a}; </FONT></P><><FONT color=#0000ff>int main(void)
3 }6 X1 Z6 e. |& Y9 ?{
( n% A: q3 h# d0 `: \4 M/* returns detected hardware info. */ / w9 N  g# N% z4 t0 M  m; g! p. f
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
/ j  u( q  d* h4 k5 U0 t4 {2 tdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ % x" }9 P( `$ k! V6 ?8 ?
errorcode = graphresult();
9 ]8 o  N+ n5 fif (errorcode != grOk) /* an error
1 P( W* X3 q. v. K& Soccurred */
$ |  C9 l6 }( r  v* f" o0 J{ $ C6 z2 l/ Z' ~. M- Q
printf("Graphics error: %s\n", \
# D0 X/ ]" b9 i2 w7 J, Lgrapherrormsg(errorcode)); ' P, D1 a, M4 r& k4 ]
printf("ress any key to halt:");
2 `9 H2 m9 `4 {* Z" P) Q2 h9 n  Fgetch();
" Z: O* y$ K2 [2 K( Xexit(1); /* terminate with an error
( Z7 U9 ~0 y# K' Hcode */
; i# W5 O4 H* H3 B9 L) x1 S} </FONT></P><><FONT color=#0000ff>/* display the information detected */ 2 Y) |( H/ f  T0 ?8 k, k/ j- A
clrscr(); + K" o4 a  z9 o; E; H4 I; b
printf("You have %s video display \ 1 D+ C: q9 c- H) Z7 O1 ~& z& h
card.\n", dname[gdriver]);
5 S) s+ ]  b/ ?& P! z2 Zprintf("ress any key to halt:");
, W9 _1 v& l* Egetch(); ! S$ P2 d  K6 r3 B
return 0;
# z# E& Z* L5 p} </FONT>
7 b3 [/ G) O2 Q5 b. Q
# z6 G4 Q+ _  E+ R) s, N+ L# ~0 _) U; v3 \; H( W
</P><><FONT color=#ff0000>函数名: difftime </FONT>
. g. w! {/ j" Z) x, `9 l功 能: 计算两个时刻之间的时间差
, s1 v' q5 F; {* F9 N4 r! L! N, b4 g用 法: double difftime(time_t time2, time_t time1); 3 m/ @6 x; Q+ e$ {
程序例: </P><><FONT color=#0000ff>#include <TIME.H>
7 e  a# m- F! u) |! K- w" R- C- ?3 c#include <STDIO.H>
+ e3 G1 F$ T- k#include <DOS.H>8 X' n4 C: O% _
#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
: v) x+ g* `2 a* I5 k8 \6 I{ 4 _# K# b; J6 }
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
1 A0 a& Q5 ^; Y, [, Y5 r# x! Wfirst = time(NULL); /* Gets system % u8 Y( n% X  r0 m: S1 ~+ o; v
time */ " |& ^1 P8 f/ \4 F  X
delay(2000); /* Waits 2 secs */
+ a! r& i' S9 m: csecond = time(NULL); /* Gets system time # h2 D: d: x6 E, f$ [5 s
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ 6 _0 i3 g2 K9 y! r0 H* s8 X
seconds\n",difftime(second,first)); 9 f# Y# F1 y- X) c$ G
getch(); </FONT></P><><FONT color=#0000ff>return 0; " J, i1 U! @: K8 r" R! u- Q
}
7 g+ k5 A9 @, E$ n</FONT>7 j- B8 Q& F1 E& S+ G( s
</P><><FONT color=#ff0000>函数名: disable </FONT>
, z/ Z( Q  E  E& M" K* R功 能: 屏蔽中断 $ r: x) u6 E4 e2 ~0 B- s
用 法: void disable(void); 9 m5 l8 e8 V9 l( ?3 W% s7 Z3 Q  i
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service - J" C  s- U9 h
routine. You cannot compile this program 2 [% y5 X7 |+ u& j! K4 x' R/ ]
with Test Stack Overflow turned on and
) v) Q$ A; E" qget an executable file that operates
1 k5 b$ V) P6 ~correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>9 N- m& Y. f+ Z1 o$ _0 K- a
#include <DOS.H>
  Q: e- v! r: W6 u8 R2 l#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
$ U1 p3 e( P/ b# q! R: binterrupt */ </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) 2 L/ l& u# S: a+ b" K5 v
{ : G6 E" h9 u* V* a0 F3 Q7 U
/* disable interrupts during the handling of
* O& U. q8 g: bthe interrupt */
; @9 B' g, s& v  T4 K& k( vdisable();
/ d1 \2 d# c# S" {" D4 `/* increase the global counter */
% e$ z3 i; `2 g2 h2 w- P8 fcount++; % I( U9 u9 ]" {' Z
/* reenable interrupts at the end of the 6 z7 a5 @: x; @/ X* k
handler */ ; a" Z  c- e' I
enable();
* W; k& {; W- o0 }8 d5 q4 L" p: i/ n1 ~/* call the old routine */
* E  \0 V$ p; G+ C0 yoldhandler();
0 h2 W& P$ f# ~8 |} </FONT></P><P><FONT color=#0000ff>int main(void) " {5 r8 e- d- v3 X: O9 U
{
' b) \+ m2 ]( Q, {: {; Y! r" o1 s/* save the old interrupt vector */ 2 I  g# q& s0 T
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */ : D5 e% t2 W3 B
setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
2 d7 L2 A$ K+ ]" m) C, xwhile (count &lt; 20) $ J7 x! f+ p% f% y
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
8 m# w% }- p6 p' M- nsetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0;
9 v5 u6 p# J/ X} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>; A# R8 L  c) a2 r
功 能: 将两个整数相除, 返回商和余数 . p9 m+ }/ w# [0 q' \
用 法: div_t (int number, int denom);
- _$ }* k4 k+ M# [. l" [程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
/ E% \/ j* g# z! J0 z' {( Y$ a- n#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) ( o- p8 S- v' |7 C8 n3 q! B
{ ' n0 i' h+ z* o
x = div(10,3);
( h4 F( v: Z4 ]* p9 bprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
$ A; l9 H: Z5 p* h( |1 f' o} 6 c* q$ {1 b" j" A7 h; \
</FONT>) e2 ~3 J1 Q; b
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>+ l% g3 g  ^/ U- H
功 能: 获取扩展DOS错误信息 0 {8 J& R- b! x% |4 R# z+ P
用 法: int dosexterr(struct DOSERR *dblkp); 1 @( g; J6 n9 k- u) a8 O
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
) U3 e: s6 h1 B#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void)
  o% z2 V! ^, D{ ' Z; T& S6 U; D1 k( o0 Z9 O2 n
FILE *fp;
3 h$ E! m4 F* |4 `9 C+ tstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
4 G" Y0 a! {0 z" P4 p& Uif (!fp) perror("Unable to open file for 3 K* L1 G; _0 a8 P7 D
reading"); 9 X- Q6 P/ m2 l8 J9 P( J
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ & w. ?$ E1 S1 y0 U/ ^
information:\n"); - z+ p  Y# t0 V0 O( g
printf(" Extended error: \ 7 ]% r+ U4 g8 Q3 c" ^( i
%d\n",info.exterror);
: `9 y7 ]" Q0 ?2 [printf(" Class: \
" ]+ T4 M5 Q: J; K%x\n",info.class); : K$ b) s4 V' s9 U0 ~
printf(" Action: \
; f2 e' O& [1 j) a  `" H7 k%x\n",info.action);
1 ?( `, A/ y6 v3 Sprintf(" Error Locus: \
. Z2 L# S4 }+ g% h. F( d! o%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
4 n+ T8 t. e  K( M} </FONT>. _2 N! h/ x* ?, {

) T  R) _& K. |5 m& h</P><P><FONT color=#ff0000>函数名: dostounix </FONT>2 [. Q6 ?. d( ^, ?
功 能: 转换日期和时间为UNIX时间格式 , K9 V% M# I3 ~& F* z1 `
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
5 W% _7 s, F+ o8 U程序例: </P><P><FONT color=#0000ff>#include <TIME.H>4 n: F, w7 @" S3 n& O
#include <STDDEF.H>
6 J8 O! I8 X+ \7 L1 F#include <DOS.H>
6 {  A+ K* c4 n. Y% @#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
% n+ Q( O9 D# e) f( r) H5 x{ 4 L; v% Z! h- T5 x, X0 j1 L
time_t t; , D2 M& O; P% }7 \' {
struct time d_time;
% Z; }/ g. d! E# G7 Rstruct date d_date;
& t* u9 u5 I; q9 }- j: N. nstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); $ k9 b, ^- {0 ~  k, o! |- D
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
7 r$ v* c' i/ ]+ e( F  a; O- dlocal = localtime(&amp;t);
& z* b# c+ G2 e3 q' H  L2 nprintf("Time and Date: %s\n", \ + X0 W; W+ O; q; h- e# l9 l; ~' o
asctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
* v: p3 f  V0 [} </FONT>/ e/ k! E, p( l! ~
2 D+ u' B& X; N' l9 k/ i
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
* h1 Z  h9 \( D( L+ L8 \功 能: 画多边形 # H+ z# T# F& O" P; l1 k
用 法: void far drawpoly(int numpoints, int far *polypoints);
& J4 X' y7 ]. ~程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>3 _% ~& [6 L6 d4 u; f( T+ W
#include <STDLIB.H>
/ o; O" F) P% @5 K/ g* A#include <STDIO.H>
) J9 ~2 ~7 ^7 o4 S7 x9 i9 Y) P#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) " X# a$ u1 u8 q4 ~+ X, l
{
$ v# C5 h* T( g3 S/* request auto detection */
/ b5 g' e0 F' j; Q& c# ~* p- e3 }1 J2 Wint gdriver = DETECT, gmode, errorcode; 2 {& C# V0 j* v
int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ ' Q  f% n9 f3 s/ w1 l5 `
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local
8 k) c3 M0 H' b$ g! vvariables */
! {" ?) V/ e; A+ g/ t# Linitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ % ?1 q8 c3 L4 t  t' q
errorcode = graphresult();
$ Z# }6 ^7 r, Bif (errorcode != grOk) 5 ~- e% Z9 R; I' Z0 p
/* an error occurred */
" N1 j/ I6 r( [4 Y{ - t! f+ c  _- w0 q; h" k
printf("Graphics error: %s\n", \ ! }3 ^4 t% ], x" [# Z+ ]
grapherrormsg(errorcode));
9 q9 U1 ~% I0 V" C) D2 ^0 eprintf("Press any key to halt:"); ! o9 O; r- T0 \- [1 y
getch(); , O6 i7 k3 l% ^9 [
/* terminate with an error code */ ' Y* a. s9 w8 l2 p. L0 t& D6 T
exit(1);
9 X( Z* v3 D( u  K5 h( d} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); ! ~, K: B, _" Z$ v' ^
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ , k+ \8 @6 e' V. k( ?
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
. d1 w2 a% D5 \7 t5 O1 v# @poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
" \2 S& q8 {8 d2 u8 s8 G( d- Jpoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ 0 b0 q) b& u- y; Y5 g: G
poly[7] = maxy / 2;
1 s' t$ a. ~( w4 N) I, D5 G/* " e$ ~% s  D3 |  f4 |
drawpoly doesn't automatically close 6 w) f1 W3 n1 @$ F: v
the polygon, so we close it.
; T6 d# ^) M& y1 `! F*/ 6 R0 ?: @2 I9 B  M. V+ i* g. `
poly[8] = poly[0]; & p; z2 F! l* u! ^- T3 A
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
1 k& J. M' q) |drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
3 J6 X, j$ n" H6 g: Fgetch(); ( ~* u9 S& i2 e0 A" r
closegraph(); , O( [1 o3 b( s$ H
return 0;
& i+ [+ D: F( Q$ `5 k8 y} % A( l8 v( t! |" G8 a7 f
</FONT># S8 I% J! A8 Z3 Q# q0 }$ P
</P><P><FONT color=#ff0000>函数名: dup </FONT>
5 i6 L9 ]8 M) G, M1 f功 能: 复制一个文件句柄
% G# F3 h1 G2 e; _7 N9 ^3 @8 J用 法: int dup(int handle); 7 m: k8 [) f6 L1 T% m' ?3 W
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
! b9 W. J6 r. \# I7 ]' ]( I#include <STDIO.H>
" C9 t! \3 p- j2 ^0 m0 d8 J" I#include <CONIO.H>6 s  r/ v% s# F
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
+ `9 r  x1 m! ~" y+ ]( V2 Z+ d{
. r# t. S5 b. Q  M2 yFILE *fp;
6 R1 B* p7 _3 a5 i9 W( a0 Dchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ ! C; Y* N) R: C8 i
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
/ F4 U/ s: h$ l+ g  L3 O( O" \% Nfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
% K% B, X* A9 H$ m3 z) Z1 X! ]printf("Press any key to flush \ 4 D' y5 k4 B$ r) ~% L
DUMMY.FIL:"); 9 [- b) M- n2 ]2 l, ], d: F
getch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without
" `8 n  G+ o/ s* i) kclosing it */ 7 F5 w+ A/ T7 H1 n* k
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \
. W( y) r% ]% C3 E7 Ekey to quit:");
) i6 O3 U- R: h, x  agetch();
, q, C/ Y+ U1 b3 O( wreturn 0; # L9 V6 X$ M3 Z: G8 P" k/ ?5 Z7 J% B
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
& n/ U: z* F7 w' j* |' M{
+ u6 f/ z/ z7 I2 w1 Fint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
1 x* Q8 y$ N2 u, Z- R: pfflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
, E+ e5 w; c6 s8 Z  Cduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
- z, a9 S# T% ^3 w$ \! c$ \DOS buffer */ & \4 i) Y' y+ S0 `9 X2 w4 d
close(duphandle);
) f7 Z! @) D5 y% o6 x6 k}
+ t/ T" @# s1 b7 W0 d2 `; y7 c: S8 l  E1 T0 b' W
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT># G; y1 _3 ]7 c
功 能: 复制文件句柄 2 Y( O8 Z2 l' J
用 法: int dup2(int oldhandle, int newhandle); " |4 T, T$ ~+ K+ A: u7 ^
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>% ?: n  _5 c- p4 i% |
#include <STRING.H>2 X0 V2 z/ B3 L$ X: i2 @
#include <FCNTL.H>
4 r* {6 p" G. N% X2 s3 d/ {#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
/ R& {" g& ], X{ 5 i! M% B3 q! m6 v
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; 5 ?; o; ?5 l/ f$ L' Y
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 9 t. k- n0 d) N7 H. t
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
. n/ K+ Z; M6 `8 T( a: zS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard # b8 R; T  o7 X# V2 W, ^
output */ ! P' s( d0 g" p
oldstdout = dup(STDOUT); 0 k" O: ~3 l! ?3 ~# i; S6 d
/* , U8 m) Q2 w5 y+ v
redirect standard output to DUMMY.FIL ) X* t! ~+ o2 k2 V% d% ~
by duplicating the file handle onto the
9 P% G8 a( h7 P( P0 E# kfile handle for standard output.
; d/ _7 J( U3 i$ D$ @& j*/ 9 ]/ @+ V% n# ?5 q5 |
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
, w6 q: I1 J5 r- ~$ R% hclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ 6 k3 F! `7 ^6 B/ @7 m
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output ' Z2 w4 `& W( V0 q) i
handle */ 4 k  k/ h5 W; B0 O7 C9 D) W/ T
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
. b$ h+ t9 A7 ^; u* @close(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
9 c) v" `2 G4 d9 Y* a# s} 9 |6 Q! f' j& ~: b4 x+ e
</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 13:32 , Processed in 0.449471 second(s), 56 queries .

回顶部