QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2075|回复: 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>: U# H, B2 _7 v; E# O
</P>
! U* L1 _; }; ^) N& P( {3 x
/ g& N; b0 X, H( |$ }9 o5 ~' q" g
5 p' _2 ]) W4 x% C* {, u<><FONT color=#ff0000>函数名: ecvt </FONT>" _7 ~/ o/ J1 z- m8 s! x
功 能: 把一个浮点数转换为字符串
8 Y. l; N" Y, s0 l1 R用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); : p1 k7 ^0 m( d
程序例: </P>& j5 ]! X1 W& u6 s
<><FONT color=#0000ff>#include <STDLIB.H>
" K; `0 [& x$ P' q#include <STDIO.H>2 ~- z* i; y! Z* M# L
#include <CONIO.H></FONT></P>9 ?* z/ e3 `3 j7 v+ y, A
<><FONT color=#0000ff>int main(void)
/ B2 N; j+ I+ `$ r; u0 k{ ( V) M% G  j- V1 F& b9 d
char *string; 9 D1 B# y8 e; n* x" r
double value; ; _5 x& |% d1 k; Q: O5 B
int dec, sign;
% K! D% e% M) L+ H' Lint ndig = 10; </FONT></P>
7 C' b, L4 Y# y, }1 {" w: p5 j<><FONT color=#0000ff>clrscr(); 1 j) j5 J& o/ M& C' \' y# p
value = 9.876;
# t  U0 g2 v# sstring = ecvt(value, ndig, &amp;dec, &amp;sign); ' t& a, ^, S+ }% M$ Q8 Z# v
printf("string = %s dec = %d \
  ^- Y- q) s$ {" \sign = %d\n", string, dec, sign); </FONT></P>
4 ]* V- ?& w6 S( Z* B<><FONT color=#0000ff>value = -123.45; * x- [- h) F9 Y
ndig= 15; ' Q3 m. k# `" A, A0 R) Z9 Z
string = ecvt(value,ndig,&amp;dec,&amp;sign);
7 `5 ^% }2 S$ c, n8 N6 [printf("string = %s dec = %d sign = %d\n", 6 A  s6 d) s1 p# @
string, dec, sign); - A* D& t' v" k1 Z4 i3 m
</FONT></P>1 P4 r1 B; U0 ~: y$ o6 n) D
<><FONT color=#0000ff>value = 0.6789e5; /* scientific # }6 D) t( d$ E  c0 M
notation */ 0 [% O: ~  s! ^/ r
ndig = 5;
4 e4 N/ m& e7 f2 {* N  Xstring = ecvt(value,ndig,&amp;dec,&amp;sign); 1 }" M+ w) s6 N
printf("string = %s dec = %d\
% z3 H! X8 ^/ S( jsign = %d\n", string, dec, sign); </FONT></P>8 {2 W7 [! @) i& ^( l
<><FONT color=#0000ff>return 0; 4 t, M# {2 k+ ~% O# q, f3 z
} </FONT>8 z/ P$ B6 R' W& }& y

( z- T9 ^. p( M+ `</P>
3 H; k. r- s' w5 h; W' I<><FONT color=#ff0000>函数名: ellipse </FONT>
' D3 q. B( p9 L9 e, F功 能: 画一椭圆
8 B: O; r, B! }! p1 q5 ^$ H用 法: void far ellipse(int x, int y, int stangle, int endangle,
2 u% G- E! i3 P- hint xradius, int yradius);
, j1 ~+ _- z3 S; @4 H程序例: </P>. l' _1 f( q/ g9 \# i4 @6 i* Y( m
<><FONT color=#0000ff>#include <GRAPHICS.H>1 R- @, M  U3 o2 l, i' w! r  j
#include <STDLIB.H>3 d0 W' P* e2 M- z
#include <STDIO.H>
( h* a' P. N/ i; B9 v#include <CONIO.H></FONT></P>
6 t1 e- f' k$ d% S7 I+ w<><FONT color=#0000ff>int main(void)
7 L2 K2 @% Q' G' s{ . G) e9 h) T& N  k
/* request auto detection */ . f& ?2 r6 U4 |7 {$ r; W
int gdriver = DETECT, gmode, errorcode;
$ E. N2 ~- e! g1 eint midx, midy; 8 Q" K! ^& v2 Q0 p! j: S' r
int stangle = 0, endangle = 360; 8 \/ n, N# B+ L( ?' n1 m
int xradius = 100, yradius = 50; </FONT></P>* Y: m$ i6 J/ H8 k' U
<><FONT color=#0000ff>/* initialize graphics, local variables */
7 F; m+ d0 \0 A/ P, b+ \/ sinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>. n; B$ z* t* D& e- W# O) s
<><FONT color=#0000ff>/* read result of initialization */
7 R- F2 W5 q8 p5 c; u+ l$ U! N- ^- [errorcode = graphresult();
% |! }7 G( ]! Xif (errorcode != grOk)
) ]: E! [  W& z  J! x/* an error occurred */ & c3 j7 u0 i. J% q6 k4 B/ ?  k) M
{
0 W$ ?6 c2 u5 g; P& \printf("Graphics error: %s\n", 5 e7 `: I( t! y6 Q9 I' G7 Q/ C! e
grapherrormsg(errorcode)); ' \- u! Q( P* {( `
printf("ress any key to halt:");
4 w8 f: i: v2 Tgetch();
9 V) s. o% X+ Z$ M0 x9 a: c( Vexit(1);
  l1 {9 l4 N, j! Y0 L/* terminate with an error code */
; ?( `! w2 v* O5 g3 Z/ U9 V} </FONT></P>- v" |0 t3 ]+ O- d7 |  C0 y
<><FONT color=#0000ff>midx = getmaxx() / 2;
+ B8 k% m% {- @# _3 ~& {5 K# ^0 Lmidy = getmaxy() / 2;
; W, `7 U. R' Z1 J; zsetcolor(getmaxcolor()); </FONT></P>$ H: `% A. J: d8 {! N
<><FONT color=#0000ff>/* draw ellipse */
# |. k0 n8 q' Y! g7 P. xellipse(midx, midy, stangle, endangle, * q$ c3 r; V8 r. g2 p. d: x- f1 e2 `
xradius, yradius); </FONT></P>+ R( k* S& M9 a4 x+ ~. O/ b# h
<><FONT color=#0000ff>/* clean up */ 7 {% G9 K/ r: Z7 B5 j
getch();
* e0 Y  f( w4 O# vclosegraph();
8 _; s- z, s/ ?( w. Y) z) Preturn 0;
7 w& D* _$ @7 W8 p- d} </FONT>& T3 s, `- j" _/ d9 c; r$ e

1 Z4 I1 }! T' L; x4 e. S" H</P>( P. W7 m( ?" c' i$ L0 J
<><FONT color=#ff0000>函数名: enable </FONT>
; Z1 |: P# h2 [5 V5 w# c0 G* X功 能: 开放硬件中断
  M# ]  z/ F. S用 法: void enable(void); % [) }' D- n" }6 v4 h- q  U4 e
程序例: </P>
  s3 X2 C" A# c, T7 \" ~5 c  ]<><FONT color=#0000ff>/* ** NOTE:
" R; }3 [# ]; M$ ~7 hThis is an interrupt service routine. You can NOT compile this program
2 b. n' m" @' pwith Test Stack Overflow turned on and get an executable file which will
  ?) Z8 Y/ X& G! _  Q3 noperate correctly.
4 d% Q+ N. I- x! H: m% G*/ </FONT></P>. ~' r1 o# [( n$ `
<><FONT color=#0000ff>#include <STDIO.H>
2 C$ A1 Z- ~& `& D' m  e( s; D#include <DOS.H>8 e3 c* u9 ?4 s5 r: E6 x! Z, |
#include <CONIO.H></FONT></P>+ d5 z8 D! W' w7 R8 s% N8 t6 v
<><FONT color=#0000ff>/* The clock tick interrupt */
. E) U7 a( Y( k! a, _! v7 ?#define INTR 0X1C </FONT></P>
& U; S( T* S9 q3 [/ r* Q& ~<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>1 ]3 e. w& c9 v$ ?5 E& U. c
<><FONT color=#0000ff>int count=0; </FONT></P>  B5 o: {' I; d/ Q
<><FONT color=#0000ff>void interrupt handler(void) ; t3 c1 }  {4 e" z3 e! _# F
{ ! q/ T; `1 j6 P7 m# k* C
/*
3 m5 P8 p8 V. C0 [1 t3 _disable interrupts during the handling of the interrupt   t3 ^+ ~4 M: }5 ^
*/ 7 I+ W* w0 Z) G2 ?2 a' V
disable(); 3 }. s0 [0 ~6 k/ |  K; n
/* increase the global counter */ 4 o. o5 Z5 K# [+ U! l6 y( h2 W) A
count++; 2 j$ f6 s6 G# U" A  x
/*
' O1 X5 O3 w: l6 U' m: o! [re enable interrupts at the end of the handler
2 [! ~5 p, ?9 S' q- a) n*/ " J* ~$ t# J6 I6 [$ d4 y% G! D
enable();
# x8 Z2 r; I3 ]/* call the old routine */ 6 [9 ?! X$ Y9 q! b5 U/ k/ O
oldhandler();
' N2 |8 q# V; s3 |} </FONT></P>( B# `/ f$ b+ Y
<><FONT color=#0000ff>int main(void) ( e% Z; q! r: _! G# K* e2 y" q3 s; n
{ 6 P4 ^" _' ^$ y/ r8 ^# V! g
/* save the old interrupt vector */ - Q, ]8 j. _$ V! y" q
oldhandler = getvect(INTR); </FONT></P>
: F3 W' j6 _1 }' H3 M<><FONT color=#0000ff>/* install the new interrupt handler */ , T+ u7 C. T' P5 f3 V/ d
setvect(INTR, handler); </FONT></P>
: B* L8 J4 Y9 K' K3 ?6 _; Q<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
! u' k9 j/ N1 i  S- U" xwhile (count &lt; 20) 0 }' L+ u" G+ j! d3 _; f7 [6 [. Y2 k2 s
printf("count is %d\n",count); </FONT></P>
1 [: F- m( B5 ^! u0 ~<><FONT color=#0000ff>/* reset the old interrupt handler */
" a+ X7 D& O$ I# Q$ @7 Qsetvect(INTR, oldhandler); </FONT></P>2 u; q0 B- N6 f, ~$ G
<><FONT color=#0000ff>return 0;
: ~' L8 h, P7 _4 E/ {$ n4 N} </FONT>
% s1 a9 z. p0 p+ C
9 a- P) F. q) A. N</P>
: z+ o- O7 U, _# c<><FONT color=#ff0000>函数名: eof </FONT>
' d& \# R* F8 m. f功 能: 检测文件结束 % V3 {* b' K2 O$ T
用 法: int eof(int *handle);
, n2 F3 B- _) r8 h% W* F" V6 ~3 I程序例: </P>
, t' p; p, ?3 q3 P% f<P><FONT color=#0000ff>#include <SYS\STAT.H>/ V' y3 D2 m  ~7 {) v& O
#include <STRING.H>8 {/ u- z2 d% |8 ~# I+ G# Y/ A  y
#include <STDIO.H>
3 J! N) Y% R9 l#include <FCNTL.H>6 V/ Z' [! U& \
#include <IO.H></FONT></P>
/ l" N7 w( v/ u2 |6 I0 }<P><FONT color=#0000ff>int main(void)
6 O, v0 S2 B- r4 m5 I+ `{
8 I4 I+ b0 h% }int handle;
9 f0 R$ t9 M2 L/ @  \7 H# T( rchar msg[] = "This is a test"; 9 U% b* j2 o2 t
char ch; </FONT></P>
. W! @$ H; K& y# [<P><FONT color=#0000ff>/* create a file */ 1 r1 u) x1 \% `
handle = open("DUMMY.FIL",
  W/ M; Y1 O( l6 Q5 ~, [! M6 SO_CREAT | O_RDWR,
; v6 F* |/ L+ O# m8 ^9 rS_IREAD | S_IWRITE); </FONT></P>9 t: p! F; s. I8 Y
<P><FONT color=#0000ff>/* write some data to the file */
/ r0 P$ G* d1 e* O1 C0 ?write(handle, msg, strlen(msg)); </FONT></P>
3 N* `4 t% ~8 F; O9 D<P><FONT color=#0000ff>/* seek to the beginning of the file */ 7 s+ f( v5 R- n% N
lseek(handle, 0L, SEEK_SET); </FONT></P>
1 U& u2 ]$ k3 n' r5 c5 x<P><FONT color=#0000ff>/* 5 R5 a0 t/ v9 J+ N. r! M
reads chars from the file until hit EOF ) p, b/ H( X- s# y0 Z+ C
*/
4 Y, @9 Q! w* Y) Z! H4 F9 Ndo % V  C0 L( f4 c4 D
{ 3 w( `; H/ s/ Y0 `5 C
read(handle, &amp;ch, 1);
$ l6 |8 C9 \8 s& j- N1 jprintf("%c", ch); 2 L9 m& f# M- L7 {) |* z
} while (!eof(handle)); </FONT></P>: ]$ j$ _) K/ S" D( o
<P><FONT color=#0000ff>close(handle);
9 i! l7 f0 E" ireturn 0; / G0 m$ B) n1 h5 F( ^  w. F
}
0 T* w. |1 ?! o; `2 w</FONT>5 ]: _, K8 c$ P
</P>
7 z, L$ G) o6 z6 P0 Z; {<P><FONT color=#ff0000>函数名: exec... </FONT>9 J: x) F# u0 U2 J1 k1 H# h% L3 o
功 能: 装入并运行其它程序的函数
+ h! Q5 j$ g/ U* z+ H用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); ! D4 I- u% `5 L- z! u
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL, 0 H& t7 r: @5 H, p; ~
char *envp[]);
+ M1 ~( f# c1 Rint execlp(char *pathname, char *arg0, arg1, .., NULL);
  m# z6 ~' s& ]; h1 lint execple(char *pathname, char *arg0, arg1, ..., NULL,
7 ?7 _9 _* K3 s, p( y4 mchar *envp[]); . r% {1 H6 c8 T9 h! r5 p# Y
int execv(char *pathname, char *argv[]); 2 f  Q4 Z- e" ~9 A& d( R/ ]
int execve(char *pathname, char *argv[], char *envp[]); ; P: T! X4 k. X& R7 C1 V. U7 y
int execvp(char *pathname, char *argv[]);
8 A5 |) e( q9 Z* K+ Uint execvpe(char *pathname, char *argv[], char *envp[]); ; W- _  F1 u+ e5 g/ Q( i: ]
程序例: </P>! d) W  q! ]  r- ^$ r/ n, Y
<P><FONT color=#0000ff>/* execv example */ 9 {0 B  t9 d& a2 @6 ^) Y
#include <PROCESS.H>5 B5 p* _7 A, q8 Y0 ~. M4 H
#include <STDIO.H>+ r+ ?5 U, ^1 G5 G+ q; T6 m( [' M
#include <ERRNO.H></FONT></P>
  R- }( u1 W1 e4 P: E, c! e. s; s<P><FONT color=#0000ff>void main(int argc, char *argv[]) ; \: c* l" C3 S" F+ Z4 C" w, _/ d
{ 3 ~* y4 i4 K" L5 D- y2 ~
int i; </FONT></P>" E0 l5 ?' p! |, j* L3 V+ j
<P><FONT color=#0000ff>printf("Command line arguments:\n"); # |# a& N0 U8 P4 B5 L
for (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>
+ h: v& u4 X) L$ t# Z9 @$ X: F4 E<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n");
9 q5 e, O; ~9 l; s, x! vexecv("CHILD.EXE", argv); </FONT></P>
% |, P. P1 b  v' A! w! n<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
9 y- N! y8 E7 y* \. s' \<P><FONT color=#0000ff>exit(1);
6 h. l# E# O5 k" m/ @, k7 N8 ~) S} ; \2 g1 G, }/ v1 W+ |
</FONT>/ l* k  N) l) w
</P>6 ]* c; l6 _) i; y. {1 u
<P><FONT color=#ff0000>函数名: exit </FONT>
( |- G! x/ i( p% }: w- M) p6 ]功 能: 终止程序
) b  ]- ]7 e# p7 |1 Q- |( i用 法: void exit(int status);   J0 S" I" O& V8 {/ }2 Y8 t. y
程序例: </P>
/ f: L; K' O4 Y- ?5 K6 ]0 [' }  }<P><FONT color=#0000ff>#include <STDLIB.H>- K  E/ X1 i# \& l
#include <CONIO.H>0 {4 ]& F* ?7 C% ]( o& s+ D/ g* s; g
#include <STDIO.H></FONT></P>' |9 y% l: k  E+ r  B
<P><FONT color=#0000ff>int main(void)
& [/ h8 p7 n7 m2 \$ O9 Q{ , |6 u/ }- {& w+ @7 n' N
int status; </FONT></P>
" f% _: @4 i: Q) w<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); 6 L- Z% W8 K9 Q" e
status = getch();
5 T0 ]; q  ]3 n1 |3 x! Y$ U/* Sets DOS errorlevel */ + F/ _* C# n* ^5 ?' C; N
exit(status - '0'); </FONT></P>5 x) d) E* p' W/ j1 O6 P: v( r& P
<P><FONT color=#0000ff>/* Note: this line is never reached */
5 p1 G3 u) K6 ~4 G% E. }( sreturn 0; 4 I* g  h2 k& G5 E/ Z
} 1 T7 y: [) I1 p9 L) U
</FONT>. S: T# ]+ f2 {9 F: W
</P>
8 |, E$ U# t- o& s4 @<P><FONT color=#ff0000>函数名: exp </FONT>6 U1 x  g( G( p( e  B2 w
功 能: 指数函数
2 d7 Z& P7 s) t8 }6 S6 s用 法: double exp(double x); : N, H5 `( A- Y7 N
程序例: </P>- P  J0 Z. q: G3 W  S$ D9 p6 u6 t
<P><FONT color=#0000ff>#include <STDIO.H>; ^% b/ ]9 D& L/ o3 N9 L
#include <MATH.H></FONT></P>
$ e; ]5 H, B) `$ w# {$ x<P><FONT color=#0000ff>int main(void) * t2 h  C. p" z0 v+ l/ V* m
{
( Z# }% E* `) bdouble result;
& Y7 f; c3 S. N* d. M8 Pdouble x = 4.0; </FONT></P>
  l) N! c& j  X" j5 Q<P><FONT color=#0000ff>result = exp(x);
5 L5 f0 K9 D' b) T& f" Jprintf("'e' raised to the power \ 9 |7 n! i" @8 n5 [
of %lf (e ^ %lf) = %lf\n", ! F( m+ T1 U* q5 h( Y9 @4 b
x, x, result); </FONT></P>6 C! ?% i% I+ x
<P><FONT color=#0000ff>return 0;
0 A7 ?# C. \- }5 ?7 X( Y}
- Y- w3 l8 k5 o" k7 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>
- _, i# _3 r" G, [/ j, c/ [; D  `</P>  L- j8 M9 M" k5 H
<p><><FONT color=#ff0000>函数名: delay </FONT>
% R  N) y( q9 N: ]功 能: 将程序的执行暂停一段时间(毫秒) / r  l% F# H0 t( ^
用 法: void delay(unsigned milliseconds); " f5 `8 `2 y& o, \- ?: N
程序例: : U' [2 b) g3 Z/ o
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */ ' ]/ g, H/ {2 _3 k; Y' A4 j, S
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) : b' n; [' b+ S- K
{ % K( v; D- P! {) H: _: @
sound(440); - j! d3 I8 d$ E
delay(500);
$ h* d1 x/ x% h' X5 dnosound(); </FONT></P><><FONT color=#0000ff>return 0; 0 e% P8 w7 H  I; h
}
+ d" |" @% K7 i" r- F
& `2 i3 ?9 T" }3 k3 ]  E( B. \</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>0 Q( Q! Y2 b3 j  `8 O
功 能: 在文本窗口中删去一行
% Z, c0 B9 n/ n9 Y" S5 O用 法: void delline(void);
7 ^- ]: q# J/ N程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)   o! q3 _- r. ]' S
{ % x0 J; J) t1 k
clrscr();
' S4 H/ R% c6 o3 F; w( E! M4 Hcprintf("The function DELLINE deletes \ , @" U+ H- J+ c
the line containing the\r\n");
1 }7 D1 Y! h; j4 n1 O- W* lcprintf("cursor and moves all lines \ ' U0 l' d" c3 O7 B; V5 V& _* u
below it one line up.\r\n");
( Q( S) `! c* \! Y" _cprintf("DELLINE operates within the \ 8 Q: D4 J' i. r* c2 d
currently active text\r\n"); & p& v9 H( Q- [  v
cprintf("window. Press any key to \
' U2 x" v2 g8 w+ p: tcontinue . . .");
5 p4 |9 [! c: M& Zgotoxy(1,2); /* Move the cursor to the * F% o# U: |5 h' ~: z
second line and first column */
; e  Q& j" k" c' Z2 a; W5 a. Igetch(); </FONT></P><><FONT color=#0000ff>delline(); - j/ z) E4 A- d1 |
getch(); </FONT></P><><FONT color=#0000ff>return 0;
: D' v5 \4 b# R7 K! ^} </FONT>3 P3 x+ `# m& h: L3 }4 ^2 {
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
2 i$ ], i: c$ v* }$ m, C功 能: 通过检测硬件确定图形驱动程序和模式 - N* ?* S! q7 x; ^3 b( S! x  K
用 法: void far detectgraph(int far *graphdriver, int far *graphmode);
7 u0 K% O1 L) P4 \4 ]2 o程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
9 D) w9 N: x$ d' w#include <STDLIB.H>4 Y5 V" I# b% _% |
#include <STDIO.H>) J8 k+ Q$ G8 R5 g
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
+ F7 c1 b/ a; ]/ T% Schar *dname[] = { "requests detection",
2 @0 o& @; |( @4 T"a CGA",
& O8 `/ }9 \0 S  |4 T) P& V"an MCGA",
3 b; W& K$ H' A. E# G7 H! N4 y"an EGA",
# e* x/ M$ j+ d" @  O"a 64K EGA", : J$ Y# S" P% r5 y; |
"a monochrome EGA",
8 ]) p- A  L' ?- M) H"an IBM 8514",
5 Q/ J1 X9 T: I+ z"a Hercules monochrome",
$ Q0 j4 G3 ^3 {  s7 K: C' D5 ~"an AT&amp;T 6300 PC",
7 y5 o) A  \0 E"a VGA",
. j* b  o0 |1 h) u( X& f"an IBM 3270 PC"
) o0 w: ^/ K/ L% U. B$ W}; </FONT></P><><FONT color=#0000ff>int main(void)
6 d# V& u# o' F6 X+ o; R{
* ~/ \$ u5 |0 K3 ~5 A: ]/* returns detected hardware info. */ * ~$ a9 }5 X3 v. k: b& ]3 A, f7 o# j
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */ 1 D+ Q3 {/ r2 Z8 E' s) \( O0 w
detectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
2 k6 l' ]8 U6 u. e# y  Perrorcode = graphresult(); 8 j1 _; b# k. H1 M- @9 C
if (errorcode != grOk) /* an error
' m0 s& b4 A  M( j; y8 H2 ]7 v1 _occurred */
$ [1 Z( E! |8 n+ V3 \0 i7 i{
% Z' w" L9 f) {3 J9 m) Pprintf("Graphics error: %s\n", \ , C/ Y  F4 R, d5 Y3 D& y
grapherrormsg(errorcode)); . m0 o$ _4 e  A$ h5 s
printf("ress any key to halt:");
4 Q3 \2 i; \. B+ P# D6 o/ ~) Cgetch(); 7 H' t8 R1 U' n
exit(1); /* terminate with an error - z3 U" p/ }1 V2 [3 t" }. \
code */ / `( R# J9 a" Z) K- R0 B" F" q
} </FONT></P><><FONT color=#0000ff>/* display the information detected */   S% C6 C" p- a4 Y3 l$ o7 F
clrscr();
7 M  l  K1 k+ c8 pprintf("You have %s video display \
9 A$ @% [& o8 e+ L, ^* P8 mcard.\n", dname[gdriver]); ) b. L& w, {4 ~/ w3 g
printf("ress any key to halt:");
: t3 I0 H* E7 H1 J8 y1 z: r0 bgetch(); 6 }: g  r+ y( e$ |/ o3 g" r9 c: c
return 0;
( v% y0 y1 i; i} </FONT>. X5 B9 v  }* D
# a! m! ^9 J. U# E: u
/ e' A  r/ A! X& c! d1 V% _
</P><><FONT color=#ff0000>函数名: difftime </FONT>
6 |+ L# J" z7 F* T. c+ T2 h2 |功 能: 计算两个时刻之间的时间差 5 h& A. x! v+ I
用 法: double difftime(time_t time2, time_t time1); ( X: K. H. K9 B+ X, ^
程序例: </P><><FONT color=#0000ff>#include <TIME.H>4 Q/ D1 p# ^8 p4 n$ R
#include <STDIO.H>
" Z; y8 A: C3 |4 U#include <DOS.H>
0 e; a. T7 p' i1 [#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
$ ]# H+ j8 `( e  g+ {' o2 d{
+ G  u3 I4 e, l' I* Ctime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
, W3 E! A. u( rfirst = time(NULL); /* Gets system
6 P5 h# n2 H6 X* q6 u. ^7 C+ A3 f. F( htime */ # i  T! s3 z5 q& Z
delay(2000); /* Waits 2 secs */
- a) s! O: \* }" z! Csecond = time(NULL); /* Gets system time ' {& C$ A  \& _6 i; ]& S- ]6 a
again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \ 8 m' h2 ]  ]% r5 W5 J
seconds\n",difftime(second,first));
' }9 z5 I5 S+ ?4 H4 x. y) Ngetch(); </FONT></P><><FONT color=#0000ff>return 0; ' m: n. x- v; v- |6 H: s+ b
}
% g  I& n' D& z, f</FONT>
; B" O. f8 g8 E) I0 a, m7 M</P><><FONT color=#ff0000>函数名: disable </FONT>
7 e4 X; ^& [7 t5 o' G; v功 能: 屏蔽中断
5 c' C  b+ s0 q& s( K% K* {$ i* D用 法: void disable(void);
5 V0 q$ H! d+ B! V( m程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service
7 e3 \3 U* M. ?6 Kroutine. You cannot compile this program 2 a& y: r' }* a, z9 V
with Test Stack Overflow turned on and
* t7 p& b* `3 m2 j: p/ k% R) R; yget an executable file that operates
' T. @# }3 o' N: u+ bcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>$ t0 g, R; F2 |& {
#include <DOS.H>+ M  _  b# W& K5 |+ p
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick ! u% ^) _5 i7 o: a7 G
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) 6 K- G9 h+ {: s! ~
{
* j( n# T  i  P) E0 G! u! R/* disable interrupts during the handling of 0 A: l8 u& X$ z8 C8 v/ q/ B5 L( A8 f
the interrupt */
0 _8 l9 e( q$ X% K7 ^! o* `disable(); + l# O% y- Z0 W
/* increase the global counter */ 7 o/ j- \& C& |) M1 E" \
count++;
: z8 J, i! M% V) J4 ~/ O/* reenable interrupts at the end of the ) O' v# R' U; D( v& R4 @
handler */ % F/ z+ N7 ?4 o2 ?' ?% S
enable(); ) ~* ]( R2 t3 n3 W% N
/* call the old routine */
0 u! E% p) K9 S' {# Noldhandler(); # [8 q/ e2 N) ~, s( H% n. q6 K
} </FONT></P><P><FONT color=#0000ff>int main(void) ' T' j, t. X6 U+ z- {( n5 U
{
4 k  P  ?6 t& N' e/* save the old interrupt vector */
+ C/ S+ Y. M' L$ Yoldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
* B2 A! _0 D* y9 k) R* |setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
5 g, Z  |& U1 D7 q, C7 A! dwhile (count &lt; 20)
; q' r8 s, }8 @2 F% dprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ 9 q; ^, N! ^* O9 h/ X  j$ G! {
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; ( a6 j5 |0 w! L" q+ K0 L3 H5 E
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>- i- [/ l; {7 c6 A/ r8 F5 n9 ^
功 能: 将两个整数相除, 返回商和余数
+ {" M6 S- F' t& t+ G用 法: div_t (int number, int denom);
/ s& Q5 V' ~/ V- z& L程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>" c! a+ D  D5 a
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) 5 A+ ~) p$ t/ \7 S
{ 3 k) U) O2 x7 C! @# c5 @- }6 _
x = div(10,3); 6 ]- z* ^8 ?" ^5 S: R
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
" K+ }$ f# s9 E1 E" X9 w) r}
: X! x. n$ f. f: ]7 P5 o</FONT>% b8 j5 v3 i1 j; D- G1 D7 F
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>
2 v3 I5 w- e& r& P: i功 能: 获取扩展DOS错误信息
7 }9 d! J+ H9 I5 N用 法: int dosexterr(struct DOSERR *dblkp); ( z: x4 k( C" X
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>
* _9 V' J0 E: H#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) 8 ]# q* C9 }. {9 L% R3 a
{ . i% h% m3 ^7 Z( i- k/ A! I
FILE *fp;
: t& n, v8 x" S# V9 \- I1 x& ]struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
1 ]# @5 |3 l& R" f2 u$ s7 Mif (!fp) perror("Unable to open file for ' u8 T2 B! }! [7 B9 v3 H9 B  M
reading");
2 |3 w0 a/ b1 F" m$ k% s* d0 [8 kdosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \
7 ~4 k# ~0 N1 w0 n1 |+ o( finformation:\n"); 8 }3 e! {) |- o: v8 @( `8 c
printf(" Extended error: \
' T, U* ^( v4 j! s" }; c- ~%d\n",info.exterror); $ z" `! h+ e% j# n9 M
printf(" Class: \
) f: N+ N6 c+ l4 P$ K2 N%x\n",info.class);
4 L8 {9 J" A3 Yprintf(" Action: \ " l/ l9 F) T0 H+ \
%x\n",info.action); ' V+ _+ x' I: o% Y/ _/ }) y5 O8 l6 U
printf(" Error Locus: \ % B: `+ t/ y& a1 W. Z) i7 |
%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0; 9 d3 ?$ k4 q& j$ E% h; Y' {2 Q
} </FONT>( q2 ~1 H' B8 Y, F: L

( V# _1 d' ^( O</P><P><FONT color=#ff0000>函数名: dostounix </FONT>3 b: J& `1 k% g2 m* d: Q: {5 W, l
功 能: 转换日期和时间为UNIX时间格式 9 d0 ?5 V8 f6 @1 a+ u
用 法: long dostounix(struct date *dateptr, struct time *timeptr);
# N5 ~) h* n& N3 O( [程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
# N' M$ s, I4 L$ \! p7 f, D( z#include <STDDEF.H>
+ w( N: Q* a7 K! S" z#include <DOS.H>5 I0 o  i8 w* k2 U8 s# f
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
) l+ j& }, p: t+ ^0 P& _{
( J: f4 O: G& L# L% \! I! Stime_t t;
' E; {% C7 A7 u% P" ?struct time d_time;   ^' N# U& \) U2 K% U& ~4 ?) t4 ~
struct date d_date; 2 D5 [& i! h% Q! I( x( @$ Q
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); : k1 S  N8 U+ H9 P
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); & x9 v* R2 f6 K8 t8 q( [; v
local = localtime(&amp;t); ) ~" z) C: Y+ `1 ~( e* A6 R/ m  T
printf("Time and Date: %s\n", \
- R8 [; L/ }2 @7 C+ V; Easctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
3 F& F8 C7 ~, [" \6 A" U} </FONT>
; R6 j6 Y7 I4 s* C. m0 A6 c" a$ i. j% b+ M
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>+ e* O6 n* q3 s0 c7 x, f
功 能: 画多边形
" @8 {: P$ h8 D( S) l8 |# Q用 法: void far drawpoly(int numpoints, int far *polypoints); ) k  T" R6 e$ |) G# \( D
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>* l# H- W5 N: ]0 X5 z
#include <STDLIB.H>, N0 G8 F3 V- x5 [; a' T; O
#include <STDIO.H>" n. M! M, B( O& e( E
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
  a* U* Z& w$ r9 k{ - z: b, g6 T# G( O" v
/* request auto detection */
7 [( o1 w  d3 L  z7 ]int gdriver = DETECT, gmode, errorcode;
4 o  c; v$ S4 S8 R0 s' O7 ?int maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
1 d# X# x# p) h' M9 lint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local : V: q( _2 j5 m3 p
variables */ * f. W, y; z8 S: `" l
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */
7 j) h  b. f, ?# n: g. E9 p6 lerrorcode = graphresult(); % C% z, w3 \" J0 g, A6 }: f
if (errorcode != grOk) 1 v2 E2 V- e3 S9 c/ |( [
/* an error occurred */
" t& Q- @9 d  g+ B+ z, z2 G+ G$ E{ # F: T5 z' A/ R3 c
printf("Graphics error: %s\n", \ : D7 b& Y6 P- p2 U' Q# {# e4 s, J
grapherrormsg(errorcode));
8 |. g" L# C, B; B3 S: kprintf("Press any key to halt:"); ( l6 l5 l7 ~. n1 _
getch();
  w, Q; u6 O8 i4 n9 c  |8 ]2 n/* terminate with an error code */ * L* b: B+ m% m6 }/ Y* c
exit(1); # \3 c1 Q4 ^; A6 @9 X0 B6 Q+ N' L
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx();
1 @$ D+ I  N9 u- T* H: ^- _maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ . j! n# [6 d& v% ?; o4 o; ]$ R
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
+ K5 }. `% V( ^% D# ], Y0 \7 Spoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
" I3 r' t, h1 o3 Z. e  w! v$ h" Ipoly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */ 4 p9 y" ]- U+ _# Q8 u' ?, E
poly[7] = maxy / 2;
  a) n8 @( c# ^) C/ H) P0 Q5 c) i/*
' N+ b( E+ Z+ t" w# g9 tdrawpoly doesn't automatically close 4 R% p4 @, T3 i
the polygon, so we close it. , S4 x4 |+ j! P' t
*/
6 Z1 n+ `- Y% a0 a0 f! N: Apoly[8] = poly[0]; ' [# O+ _* _% G) T* n+ \& A
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */ " D$ M/ T2 Y  |+ \
drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
+ I+ ]" z* _5 d0 e% mgetch();
7 P; Q# n. f1 O: v5 n1 wclosegraph(); 3 C% h5 @- D9 d/ @9 c# d
return 0;
3 a; R9 ?( z% x. z  o2 G} 5 k9 R7 t: {  G; W' {4 J4 V8 K% J
</FONT>& a  A$ n/ X9 L1 Y7 |
</P><P><FONT color=#ff0000>函数名: dup </FONT>  T" u5 y/ R7 R1 t% Q7 j
功 能: 复制一个文件句柄 & e2 `5 q8 f5 ]) d% C7 P5 u# H& ~
用 法: int dup(int handle);
' d$ q1 {& v% S% ~$ q$ y" F程序例: </P><P><FONT color=#0000ff>#include <STRING.H>
5 h; K% b1 E2 W4 R#include <STDIO.H>7 [0 k5 b6 c" Q. Z& z
#include <CONIO.H>  E- n6 {( a  h: |& v% F1 [. p
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
0 k1 r. p: i: ~; ]) e; K' L0 w+ C{   Z8 o- [* z9 H
FILE *fp;
+ A& T& o+ K  s1 _$ ^/ G* vchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 9 e( I( z/ {8 l0 V1 P
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
; R( \8 i; f- ~& H, C  vfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
: a9 P$ |  f0 U7 J: a# Q! E, Rprintf("Press any key to flush \
5 o2 V  N, y  Q$ _# z" EDUMMY.FIL:");
1 b1 Q% N* I+ I1 a( Sgetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without ! C. y* o' q. E9 T# k$ ?
closing it */
9 c# B7 n1 Q( B8 Y* y0 dflush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ / s- X! L% P# M3 v* c  h' _# T
key to quit:");
1 ?0 W' ^, U% f1 c2 [3 A  Egetch(); 3 R: U4 e5 B+ v5 J
return 0; ! ^" E. @( i# `- w3 N7 p/ p; E2 C  T% r
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
/ d5 V( L+ X; l* ^' m2 h- ^* p% i{
, r. m$ W4 C# r4 D% i; mint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
9 ^& N% c- R1 _- b) O$ D1 V( afflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */
2 m% n4 E7 }( Z2 V' P' o6 }! Oduphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the 4 O6 S- S: u4 {7 h( a
DOS buffer */
+ D0 C1 v0 m( Dclose(duphandle);
7 P7 I5 e. G9 {/ t! o0 a}
5 ^4 z/ Y; X3 n. t9 Z6 A, V& h) Q. l$ C- C# P2 ^4 _7 A
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>: C" a4 N. J% W  C5 W4 L' x
功 能: 复制文件句柄 1 w1 j( Z! B. n& ]0 c
用 法: int dup2(int oldhandle, int newhandle); 5 i! z5 b! E; O% Q! U
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>: q8 O; I8 M0 M, s
#include <STRING.H>
  r! |1 z, n2 e& u  k* ]$ R( W#include <FCNTL.H>8 S5 v5 M" a- f7 Z
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void) 0 a! {9 M/ r, y4 B* F
{
8 j! [' S$ Y  W#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout;
% u4 I8 j9 {& S; N8 H! U% Zchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
3 l/ |5 p. I) I% X0 `2 F  L# y) |nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
! H- @2 a0 {( SS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
& u1 f1 o- @: T6 C: Poutput */ ; `6 Z8 p1 ]( T2 _# O8 U. x  V, ~3 M' s
oldstdout = dup(STDOUT); * O4 z+ }& A6 k3 x* B* Z
/*
, J- Q: Z* W+ N% O* k& J# Eredirect standard output to DUMMY.FIL
* y7 a- s7 c/ G  @. d( ]by duplicating the file handle onto the
! `% `; A' @/ Y3 f" p; afile handle for standard output.
$ G, [' ?) I8 R5 k& h. U) h$ A) O" w*/
5 H* D' u- z- m0 E* Q9 q! d2 f2 G6 wdup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ 0 ^) e- m0 m, a3 i
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
$ O9 V0 T: }- O$ D4 Cwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output ; v$ p" w) u* H/ n
handle */
( b- y/ r, q7 E9 n5 ^% |6 o$ ndup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
* P1 w& K7 s0 N: d( Z% yclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0;
" {+ @" P  V* \& x& b  X} 6 ^+ {' F) U1 [3 Z1 k) ?! |; x6 u7 T3 T
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-6-12 16:11 , Processed in 0.382948 second(s), 56 queries .

回顶部