QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2149|回复: 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>1 Q; u( n* V8 [9 e
</P>
& k: b# j  z6 P5 _! `/ ^/ d2 _! d- V" u

& V' C; a2 ^  H# ~/ f0 C2 q& r5 i# r<><FONT color=#ff0000>函数名: ecvt </FONT># K. I* f7 b/ W7 v  A7 w7 Q% d
功 能: 把一个浮点数转换为字符串
& O  j: ?2 Y; k% Q用 法: char ecvt(double value, int ndigit, int *decpt, int *sign);
1 F% K% l0 j: y/ h' p程序例: </P>9 p, D7 d1 ^, g1 X0 ]) W
<><FONT color=#0000ff>#include <STDLIB.H>
7 A, Y3 L) b4 Q6 i#include <STDIO.H>( Y& _& X% c$ J+ g, v
#include <CONIO.H></FONT></P>
4 r# g% o$ i5 R/ F: @7 q1 {<><FONT color=#0000ff>int main(void)
5 \: J% q) I* W6 Y" D- |7 N7 n{
+ W1 K, q! C8 K6 A+ Ochar *string;
* o8 v2 h5 J' Z8 P& v8 [double value; / m" _* E3 I$ |
int dec, sign;
8 i& ~  `1 T+ A' yint ndig = 10; </FONT></P>" N: z7 }/ f# `
<><FONT color=#0000ff>clrscr();
7 J% g- W- M  B5 w% y- R& jvalue = 9.876;
4 b( I" z( N3 A' `string = ecvt(value, ndig, &amp;dec, &amp;sign);
+ e# @7 h# C0 P* Mprintf("string = %s dec = %d \
3 U* R% z$ G9 ^' U9 ~1 Zsign = %d\n", string, dec, sign); </FONT></P>! ~8 ~) f2 c5 \) h- i
<><FONT color=#0000ff>value = -123.45;
0 r& }2 p1 W7 Y, k+ rndig= 15;
; S9 G2 |9 L) Estring = ecvt(value,ndig,&amp;dec,&amp;sign); + j& S6 S' p- l7 h/ x
printf("string = %s dec = %d sign = %d\n",   O7 x, e! x: Q( R3 e& w* W
string, dec, sign);
2 M# o7 w4 z, I$ Y</FONT></P>5 N& D& K6 q+ y! S/ J) q
<><FONT color=#0000ff>value = 0.6789e5; /* scientific ) m! G* c7 A( ^
notation */
) p0 z& u% h( l9 |- E4 l7 P' _0 ?" ]ndig = 5;
! X) H0 Y7 a- }, X# hstring = ecvt(value,ndig,&amp;dec,&amp;sign);
2 c3 e, E, V7 z% \# |+ Bprintf("string = %s dec = %d\
2 m' _0 }! P7 |+ c& ~; Isign = %d\n", string, dec, sign); </FONT></P>6 v; g, p/ B) K9 o! K' V# Y
<><FONT color=#0000ff>return 0; . |2 r& h( m; B+ R5 E
} </FONT>! P4 b3 B# w8 f8 P

9 o" v! F% ]5 B6 i5 I</P>8 i& X4 v; g1 f$ a$ {
<><FONT color=#ff0000>函数名: ellipse </FONT>2 E/ b8 @1 E; K" ^8 Y! }
功 能: 画一椭圆
/ `6 x% s8 p' M5 f% G用 法: void far ellipse(int x, int y, int stangle, int endangle,
, m8 z7 n& `/ R! z! W! rint xradius, int yradius); % Z0 G0 N* W' {' }: @: ^3 N" Z! c
程序例: </P>" P8 L7 Y( H. F
<><FONT color=#0000ff>#include <GRAPHICS.H>8 Z! g6 I8 S) Y. d
#include <STDLIB.H>
$ W0 c* l/ h& U; d( X* I#include <STDIO.H>% Z) f: G6 h9 ?
#include <CONIO.H></FONT></P>( }' o2 j3 i- `4 R1 j0 M- t
<><FONT color=#0000ff>int main(void)
+ i. Z4 e6 v$ B* [0 G{ " H! D) _7 \! n/ \$ U
/* request auto detection */
! a+ Q3 p) s, ]1 {! \9 Y2 ]int gdriver = DETECT, gmode, errorcode;
: `) R9 O9 L2 v7 o8 nint midx, midy; - z) a& p; Z, U  w' A
int stangle = 0, endangle = 360; $ e% |0 C% E. O) _5 l) l
int xradius = 100, yradius = 50; </FONT></P>
" O/ ?+ v+ `6 r/ W  N/ {<><FONT color=#0000ff>/* initialize graphics, local variables */
7 w- F2 v8 E# O) ~: cinitgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>
" \1 }3 v+ R% \( ~8 v- J: a<><FONT color=#0000ff>/* read result of initialization */
4 U% N6 C2 o, C6 Nerrorcode = graphresult(); 7 c( n( h3 g7 f' ]- G
if (errorcode != grOk) 8 y4 v, V" R5 M* L0 ~1 W5 o1 f3 X
/* an error occurred */
9 g( E2 y) ^/ v9 L5 I3 N% z{
( V+ B: R6 U+ J% P5 xprintf("Graphics error: %s\n", 9 z( D8 P) z; {' t! ]7 o8 B, Z
grapherrormsg(errorcode)); + \% O$ D# I5 j& C8 A! b
printf("ress any key to halt:");
  N+ S3 K0 m& d/ cgetch();
3 j- d0 U4 a, l; W$ v; Eexit(1); % C& ~& z5 q1 H4 ~' \- V, B
/* terminate with an error code */
: m( v9 T# t; t+ t! U1 }( y} </FONT></P>: |1 w1 A# b9 w) J7 |: d3 e7 N
<><FONT color=#0000ff>midx = getmaxx() / 2;   W8 e/ _% Q8 F) W6 B
midy = getmaxy() / 2;
0 _. I/ t" B- H- u* _* u2 Vsetcolor(getmaxcolor()); </FONT></P>% |% z) T) z- H( {7 u0 @+ ]
<><FONT color=#0000ff>/* draw ellipse */ % D$ Q# ]+ R" \2 _" Y
ellipse(midx, midy, stangle, endangle, ) H$ L. P9 k7 z& K
xradius, yradius); </FONT></P>1 \* e1 [( ^# X9 m
<><FONT color=#0000ff>/* clean up */ 3 V* V8 ~& o5 _; ~
getch();
, F5 \& c4 {1 R4 a7 t/ fclosegraph();
% F$ G; {. W; E' i& Treturn 0;
2 ]; q/ ^1 O, a8 {) P- h) x! l  j} </FONT>5 x& Z5 F3 T* w5 E- u8 R
8 v+ V+ G7 X0 ?  K3 E( H
</P>/ ?3 h( ]/ |. d& U: g6 c* F1 [% |
<><FONT color=#ff0000>函数名: enable </FONT>
8 j8 f1 D. ^4 w( K/ |功 能: 开放硬件中断
; B* _8 k# S- c& j) z用 法: void enable(void);
* m6 H% ]5 T3 Q3 e程序例: </P>0 M1 I, X8 l  Y; ]* }$ ?$ }# T
<><FONT color=#0000ff>/* ** NOTE: 6 ]4 N* r# o* C; b9 }
This is an interrupt service routine. You can NOT compile this program
0 h/ G8 w" u- T4 E% U1 {with Test Stack Overflow turned on and get an executable file which will
4 y9 k" v  k/ I6 C2 F5 a4 Noperate correctly.
5 D2 W  u. w& [% z+ v*/ </FONT></P>2 W" v$ K9 p" A5 T9 z
<><FONT color=#0000ff>#include <STDIO.H>) @% S2 q4 S+ }  N' f) U
#include <DOS.H>
( N. `+ |4 L) ]4 E# A- z- |#include <CONIO.H></FONT></P>! R; Y  E5 c& q- O7 N2 o5 t
<><FONT color=#0000ff>/* The clock tick interrupt */
# T) O4 [( R! ?#define INTR 0X1C </FONT></P>- k9 M7 q) _8 P' h2 q) z
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>
8 D/ G  Y4 K9 j3 O9 i7 r* m<><FONT color=#0000ff>int count=0; </FONT></P>
" {/ |* ^1 Q# ~( `<><FONT color=#0000ff>void interrupt handler(void)
7 W' h+ V7 |1 b{
1 x2 s9 z9 L) v8 w; ?/* 7 `7 z/ G% L- M* P6 W" W/ M. s
disable interrupts during the handling of the interrupt
) ^$ }8 p; x) b0 }! y*/
0 P. u. n! b9 P3 u& hdisable(); 6 z* ^$ v/ w- A# X% Z0 F
/* increase the global counter */ ( ?" O. }( g& x; M% T# L# c
count++; ) t1 q) j: `! ^5 N3 w* S
/*
3 }6 k4 W8 M8 z  K, P/ dre enable interrupts at the end of the handler 9 u: y# v( j. Q! o* [
*/
* t+ b1 x7 d7 m( s- F2 G5 menable(); ! Z) M2 W" ]5 H6 l7 U' f
/* call the old routine */ : D% K) J& `* L+ D" L+ O2 Z
oldhandler(); ; T% G, t5 L( D1 d
} </FONT></P>. L! ]5 t5 P7 D0 u' Q3 y
<><FONT color=#0000ff>int main(void) 7 U( L9 j1 }0 Z* E
{
' k+ J# u# c" e; \/* save the old interrupt vector */
. V/ _8 j: t: M/ Aoldhandler = getvect(INTR); </FONT></P>. G9 _. S: Q! Y2 s
<><FONT color=#0000ff>/* install the new interrupt handler */ ' {& c8 a) q' ~5 u: g) x
setvect(INTR, handler); </FONT></P>
! _2 W5 {$ d; u8 S. n1 }) v! o<><FONT color=#0000ff>/* loop until the counter exceeds 20 */
& h$ {" w4 Y& {% h+ m. v' Kwhile (count &lt; 20)
+ _' N! I/ I! ~( iprintf("count is %d\n",count); </FONT></P>
; A9 z8 t' x# G* ?  d<><FONT color=#0000ff>/* reset the old interrupt handler */
1 \4 M& ?8 y6 n( t% S+ Nsetvect(INTR, oldhandler); </FONT></P>
1 ?. H4 a7 m! g( G9 l<><FONT color=#0000ff>return 0; 3 d# d1 a- J! j5 v: s" l
} </FONT>9 }$ z& ]. ^' a1 s; Q
( R" v( M8 z. `
</P>5 O% e1 i) q6 T& C/ e7 y! C. I& `) H
<><FONT color=#ff0000>函数名: eof </FONT>. X$ R6 z$ s5 l1 R' o& M
功 能: 检测文件结束 6 Z, y: \& Z# N$ W. Z! s; p0 g
用 法: int eof(int *handle);
1 L  }: [: ?8 x2 i程序例: </P>; C3 v8 g7 `, o8 h, l
<P><FONT color=#0000ff>#include <SYS\STAT.H>
6 d* c% d  _/ w" K0 u/ N8 e#include <STRING.H># U9 Z0 [# i4 e  y8 J( \+ C
#include <STDIO.H>7 p3 z! R1 `+ S: ?. ~
#include <FCNTL.H>
/ \3 \" R. Q' {4 h: Q#include <IO.H></FONT></P>  r4 r: @3 K: Q3 b  S
<P><FONT color=#0000ff>int main(void)
9 G$ J& P" P$ K$ o{
  b9 G7 R- O, V3 M! l- uint handle;
4 |4 }( A0 D9 T( }4 u- Fchar msg[] = "This is a test"; . l$ a, A" ]; K+ W0 A. K$ @
char ch; </FONT></P>
5 r# `& K7 t3 k2 L<P><FONT color=#0000ff>/* create a file */ ' |  k' I. s: ?2 v$ d5 Z$ G% B6 g  \4 ]
handle = open("DUMMY.FIL", ! }4 p8 O3 R) M. [9 C
O_CREAT | O_RDWR, ; p# M2 I) {1 k9 k/ J# B2 E! [) o7 C9 t
S_IREAD | S_IWRITE); </FONT></P>/ s' C8 p1 d- M" `7 ^* j3 }
<P><FONT color=#0000ff>/* write some data to the file */ " J+ N% H$ G1 X& S7 g1 l  ~3 p/ O
write(handle, msg, strlen(msg)); </FONT></P>( r$ l  _( g  h: ^9 b* d! T& F$ Y
<P><FONT color=#0000ff>/* seek to the beginning of the file */
# X5 B( D: b+ }' e$ H9 Y1 z" N7 Nlseek(handle, 0L, SEEK_SET); </FONT></P>
6 ~4 t3 b; F0 O0 r; x<P><FONT color=#0000ff>/* ( Y& w; B: z( c- ]
reads chars from the file until hit EOF # d2 g& s$ a1 {
*/
; z3 {5 N- E% [$ G! Kdo
: A% O, R( u" o8 s{ 4 E+ ^7 b8 n- _
read(handle, &amp;ch, 1); $ a( O$ S6 n+ L5 n$ A: H% i
printf("%c", ch); 4 n( K  Y* d* R4 @; o( s
} while (!eof(handle)); </FONT></P>/ ]8 M% q' P2 J% K! q7 f9 x) F6 \* @1 J
<P><FONT color=#0000ff>close(handle);
& r* h8 b2 w; B' S" s7 F2 Q& nreturn 0;
$ u& h0 O" s: T}
% d$ ~9 R1 Q9 ]; y8 I</FONT>
4 I  [' V6 ~1 b</P>
0 n* w3 I) q- z" ?<P><FONT color=#ff0000>函数名: exec... </FONT>( m( d! y5 z" U7 F& q) }, y
功 能: 装入并运行其它程序的函数
: a( r2 ^" R6 u! a6 a用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
: H! S7 H7 @& m/ I  i' Rint execle(char *pathname, char *arg0, arg1, ..., argn, NULL, " C! [$ S0 X% l$ h! P1 l! P
char *envp[]); 3 [$ c- s8 x1 d  M/ G
int execlp(char *pathname, char *arg0, arg1, .., NULL);
+ c3 e7 C2 A2 m0 a; M% iint execple(char *pathname, char *arg0, arg1, ..., NULL,
/ d4 B" x7 Z5 V& U, Y' {char *envp[]);
: Z) d. _% e' c  vint execv(char *pathname, char *argv[]); % `$ J( |( M; u7 o2 X
int execve(char *pathname, char *argv[], char *envp[]);
0 y$ M+ B# w/ Lint execvp(char *pathname, char *argv[]); ' ^% R2 C* Y* V7 o2 i# N3 a
int execvpe(char *pathname, char *argv[], char *envp[]);
. S) n) p1 E2 I( c  b" H: }( {程序例: </P>
& U8 i# Q1 d9 M" t( [<P><FONT color=#0000ff>/* execv example */ 5 @* z% |( }; p9 o( X/ ~
#include <PROCESS.H>
' w0 V1 V' N  f, Y1 e7 H#include <STDIO.H>, x  \" o- ?- p" S* s
#include <ERRNO.H></FONT></P>% m, x0 J% e7 l4 J1 M! J. H& V6 A
<P><FONT color=#0000ff>void main(int argc, char *argv[]) 7 A3 q9 |! S4 U- L. o* k! P. R
{ & R2 h, @: _1 L+ E  N. r' F
int i; </FONT></P>' O7 P" e1 l8 L3 k% C3 k; n* _
<P><FONT color=#0000ff>printf("Command line arguments:\n");
1 O0 a' I2 F) V1 j/ c# {$ zfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>8 c- h! L! l; H% T% a1 D
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); $ H" D+ L; W0 R0 k; w# k
execv("CHILD.EXE", argv); </FONT></P>- D& J1 }* g: a: H$ p% Y! j
<P><FONT color=#0000ff>perror("exec error"); </FONT></P>- B4 |* W( }8 m4 j6 S
<P><FONT color=#0000ff>exit(1); - F0 ]6 h6 q3 s: n6 v" e) Q2 C
}
7 `2 i; [0 W8 M  e' Z6 o+ f</FONT>& y+ g+ o* n" r" l5 l
</P>( {! n: |) Q6 r4 a- I# k  T
<P><FONT color=#ff0000>函数名: exit </FONT>- A, [$ D0 b/ D+ ~: P
功 能: 终止程序
& w8 V/ ~# F) b8 X5 d" K0 x- T& L& I用 法: void exit(int status);
8 O  T2 R# M  }) ]+ @7 k) F程序例: </P>
+ ]4 Q; j+ j# j1 m9 @) Y1 @' i<P><FONT color=#0000ff>#include <STDLIB.H>% `- s4 b0 Q6 {% R2 z- a
#include <CONIO.H>  b8 g  I5 y( q  w5 @* j
#include <STDIO.H></FONT></P>
% g9 |6 E7 X6 K7 B# F6 Y% l<P><FONT color=#0000ff>int main(void) 6 @& y  y* }1 K, e! B5 t6 q
{
7 v0 d6 M0 |2 C4 Wint status; </FONT></P>
- z1 B4 u0 Q  \( m9 r$ W<P><FONT color=#0000ff>printf("Enter either 1 or 2\n"); " y$ |1 E% l+ @- f$ B+ ?2 {5 @
status = getch();
/ w9 L2 G- |" \! D3 r/* Sets DOS errorlevel */
2 b2 e0 K7 |: f' Z; x! M1 _4 Oexit(status - '0'); </FONT></P>
! _! U$ w: P1 |- t2 h2 C  l<P><FONT color=#0000ff>/* Note: this line is never reached */
3 Y, g, r' t3 B3 ~+ s$ d# ~0 Preturn 0; 2 p. f0 N9 L- H8 a4 I; [+ G
}
- z* T2 r9 d, Q) f3 I1 V' M# v6 `</FONT>( f6 C. w" G1 i* {8 a1 ^. }
</P>
% L: l2 |0 Y" I2 V: r- E<P><FONT color=#ff0000>函数名: exp </FONT>7 g% `) t/ ]+ q6 v4 |- L
功 能: 指数函数 3 E1 q( r# `4 K
用 法: double exp(double x);
) u! s( N( U# S程序例: </P>) k& R) T4 X7 s. R" k5 I  ~* q
<P><FONT color=#0000ff>#include <STDIO.H>7 C& x% g+ v/ ?5 n6 e
#include <MATH.H></FONT></P>
+ l  E9 N1 o1 K# w8 V<P><FONT color=#0000ff>int main(void) % u( H! D/ |* ]  v9 U6 f$ v6 o
{
" z8 D6 L' O" _3 r; H7 kdouble result;
5 G5 b; G4 B! Z2 q% E- Idouble x = 4.0; </FONT></P>
6 u  r4 x9 m* C1 |  L<P><FONT color=#0000ff>result = exp(x); # t9 Y# s& s  e) @
printf("'e' raised to the power \
4 D8 L9 L- s! S+ u, X8 vof %lf (e ^ %lf) = %lf\n", 0 [$ i3 U: k0 D( d* A4 W3 W  A
x, x, result); </FONT></P>2 G- Q8 {' |, H' V
<P><FONT color=#0000ff>return 0; % g) h6 ^! L6 f6 A
}2 H' ~( h$ m0 [% A" u( ]' L- y" i! r/ t
</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>
& j; b. W$ l- n</P>/ k$ H, v2 w& i0 ]1 {3 f$ ]  f9 r
<p><><FONT color=#ff0000>函数名: delay </FONT>
* n$ I1 q/ J# v, Y& W9 @% [功 能: 将程序的执行暂停一段时间(毫秒) + b3 I+ B. Z, p7 y9 M
用 法: void delay(unsigned milliseconds); ( n- P- t; W0 z2 T
程序例: # {2 ?$ [" X( ^+ C, |
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */
* f  x7 X+ o' M; q; f) M; h7 H#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) ; N; A/ q2 f. X
{
* \' _+ Q; }: I) h6 g* v0 P! rsound(440); 5 F7 r0 |1 W3 Q( V! }% L1 e' y7 W
delay(500); 2 V. C3 T% i9 o
nosound(); </FONT></P><><FONT color=#0000ff>return 0; ; |' L1 c% b) B
}
5 ^5 ~3 o4 H/ Q  ]/ X
* m- p: M/ A* X' ]# N2 |* B</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
/ e6 t0 t% {! J) J9 T功 能: 在文本窗口中删去一行
( C" Q' w$ P5 o; k$ t; _7 X用 法: void delline(void); # d1 m/ b; X* ^. a$ s2 O& i
程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
: r1 f# A0 v7 y$ S2 e{
5 W9 J( `, n0 L# d% g, I  I% dclrscr(); 8 I5 Q5 L8 Z' Z" q- e9 w% i
cprintf("The function DELLINE deletes \ $ m' Q/ ^) |) R8 N+ V/ N0 N
the line containing the\r\n");
9 N) C6 U- y" Fcprintf("cursor and moves all lines \
' m1 N3 d- \/ E3 k% \below it one line up.\r\n");
+ F9 o0 [$ D6 ?8 v: ?cprintf("DELLINE operates within the \ 2 f1 y7 J* c2 N4 b& ?( y* W
currently active text\r\n");
5 @0 t6 |3 k) l' k  o4 \cprintf("window. Press any key to \ - y  e5 Q- |  w7 y! c
continue . . .");
% I9 Y9 @# }! M# Cgotoxy(1,2); /* Move the cursor to the " L% ?) o: C& s
second line and first column */ 5 R# _$ ?, v. o4 S1 h+ D. {' e! q1 Y
getch(); </FONT></P><><FONT color=#0000ff>delline(); ) H* i% l  ]$ _0 D8 S  \2 [! o5 c
getch(); </FONT></P><><FONT color=#0000ff>return 0;
( ]8 ]: s: I8 d7 ~- s' @& m} </FONT>7 H  y% y) }4 V: F/ I$ ]
</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
4 d9 F1 h/ T) d7 [+ s' p功 能: 通过检测硬件确定图形驱动程序和模式 ' z2 A( v. Z: |/ F
用 法: void far detectgraph(int far *graphdriver, int far *graphmode); + a8 H# K$ s+ M3 j5 I8 j& [. R" a# J
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
! N; n8 D" w4 J" Y7 E#include <STDLIB.H>- L/ D- o6 Y* y0 Y, A" v
#include <STDIO.H>
2 V: p: o! S/ j5 [  y" s- g! l4 f( W* X#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */ " m. {0 y0 U% p* H" |2 R6 A+ i
char *dname[] = { "requests detection", * X  a. @2 B; U% N
"a CGA", 5 z8 F" ^1 V! h
"an MCGA", : a* @7 I) B' q; e3 a' e2 `) ^
"an EGA", 7 y& e4 r* I8 t7 O7 B% A1 t/ [
"a 64K EGA",
" I( \9 i- b+ c+ s"a monochrome EGA", 7 j" D* i; X7 H3 z
"an IBM 8514", - ^3 j1 m+ r$ {5 A& w* F
"a Hercules monochrome", 4 \6 Y( B7 L- j+ w* k
"an AT&amp;T 6300 PC",
& D3 |: G9 l: Q& P- I"a VGA", % I; O9 h+ {0 b0 J0 G3 G; y, [
"an IBM 3270 PC"
& [% x' N9 Q; W' P+ R5 _% e1 J4 u+ E}; </FONT></P><><FONT color=#0000ff>int main(void) % l8 p3 A) I. u
{
9 \7 T) C' k7 k/ Z3 s# @/* returns detected hardware info. */ 0 v' e( h2 u! T
int gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
, b5 K7 K. Y: a8 Hdetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */ ' M3 ^+ C* B% d& O9 v4 \! J4 L( J- x
errorcode = graphresult();
+ t/ D. a2 k  Y5 vif (errorcode != grOk) /* an error 4 e2 V, d1 E+ ~
occurred */
1 H1 o1 m! d* Q% Z. y" h{ $ i# E- v1 o! d* \) @( b" {
printf("Graphics error: %s\n", \
% r+ w' }$ h' `; H+ j1 a. egrapherrormsg(errorcode)); " s. C) ]: `' T) s# k' X
printf("ress any key to halt:");
* _; F, J( G2 L4 ogetch(); - D1 \8 @; ?8 `( K4 ^& f# S% x" Y+ Z1 [
exit(1); /* terminate with an error
. x" h& K  T/ V6 {9 ^3 P2 Rcode */
+ U" \% z6 x; R7 ~: q: H} </FONT></P><><FONT color=#0000ff>/* display the information detected */
, G' ]% ?  m. c5 {. Yclrscr();
5 }! q, ^& L& r- h. y2 A: jprintf("You have %s video display \ . a* h  C9 z6 z; P0 h, y
card.\n", dname[gdriver]);
* `( }$ G% j5 F- m  W' V9 \* cprintf("ress any key to halt:"); 1 b# C6 J# t+ O" |
getch();
3 m/ D1 |0 V1 R% l; {return 0; . b6 o+ F$ j! u' j0 s
} </FONT>
# N( _# l: h  A* ^0 F( A" H) c. t- c, W0 r# v& H6 T. p
9 @- j1 B) I- V0 _! Z/ h
</P><><FONT color=#ff0000>函数名: difftime </FONT>
; N$ r* i' _$ Z: ~. D) Z功 能: 计算两个时刻之间的时间差 ' H% g! ]6 G- Y8 J  t5 o
用 法: double difftime(time_t time2, time_t time1); , `3 F0 K6 D5 N
程序例: </P><><FONT color=#0000ff>#include <TIME.H>' M+ l5 ]) M9 ~' B. o
#include <STDIO.H>8 T% B( ^8 k$ X8 {( H8 }- s% A
#include <DOS.H>
9 D. H% Y7 N8 |2 V3 s$ x2 k6 O#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
% p4 s0 U! j4 c( e1 Y1 N{ 7 S5 [* @# x# F2 ^& b, B, R
time_t first, second; </FONT></P><><FONT color=#0000ff>clrscr(); ( K' [0 E1 E" Y% D; f! n/ G
first = time(NULL); /* Gets system 8 W- H% W. }5 M4 F' p
time */ . ~. G) P) \; s
delay(2000); /* Waits 2 secs */ & O5 s, C0 I0 S- j/ Y- o
second = time(NULL); /* Gets system time
% a# {4 {0 i+ r; Y* P1 {again */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
7 K& l% H$ M3 K2 _9 bseconds\n",difftime(second,first));
: @9 W* M$ K) E0 `2 y% N/ x2 [getch(); </FONT></P><><FONT color=#0000ff>return 0;
2 H% {$ e: l8 ]4 V# A, u}
% R6 r! Z9 V$ B8 R5 A1 H</FONT>* p3 Z! q4 J, k6 N) m0 A5 \
</P><><FONT color=#ff0000>函数名: disable </FONT>
% c' z1 K5 z% q# N/ G功 能: 屏蔽中断
* d: K; o( y7 U' k' Y5 O用 法: void disable(void); ) P7 A+ r) O" a  P( {' g3 H: r
程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service ' i% r0 p: n7 r" H: ~( K
routine. You cannot compile this program . g/ f' z4 [( A" {2 z9 E9 q) |
with Test Stack Overflow turned on and 6 S. v3 r2 w$ Y8 \
get an executable file that operates
5 s% i4 ]" s" xcorrectly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>
% A4 _. ~$ l" O! x, [1 Z% l% [, j#include <DOS.H>5 d1 \/ v& X  R' u- G  I& a, o
#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick - Y3 ?: n( _$ f8 \
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) 4 \- X& B. u/ h( h7 y6 Z
{ $ i" m$ F. t4 w( V
/* disable interrupts during the handling of + s( H) m- x2 x: `. P8 Q
the interrupt */ ; P, q  T! }4 R: o. s  X) V
disable();
5 @. _6 B3 t2 n& l/* increase the global counter */ 5 P+ _# s' n! H% E" E2 F5 f% M$ s
count++;
, A3 b% I3 e. I& Y9 X, C  l! K- C/* reenable interrupts at the end of the 9 o3 s4 z8 M8 u
handler */ " d& n% _4 m% l# J% y- c4 w/ U' q
enable(); ( M4 ?* l% q( o. c  O, ^4 }8 t* k5 l
/* call the old routine */ - w+ F3 J5 l1 c7 U
oldhandler(); ' A  B1 Y* N# s" l& I0 y0 }
} </FONT></P><P><FONT color=#0000ff>int main(void)
, X6 z+ p. J0 q) q' `8 {$ _* H- ^{
6 s" z% |# s, d4 [/* save the old interrupt vector */ / k5 i) K8 b; I4 X
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
0 T8 M7 \' D4 R/ E# v* zsetvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
# `) m$ ~& ^' a+ |while (count &lt; 20)
3 f, Y6 I6 P! gprintf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */ + W* p/ k) J3 a/ ^
setvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; ' A0 Z% t5 M4 V4 B4 A# E9 b
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>! J: d' r: ?) t9 j+ o6 ]. c
功 能: 将两个整数相除, 返回商和余数
. O( S3 O7 w/ r# L2 @7 W用 法: div_t (int number, int denom);
. b) s1 _( v2 e0 t程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>- }. I& |) v; j
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void)
8 i7 A; C4 {- ?3 j. U8 t8 J& D{
6 h3 h- }- g" g$ `9 ~/ o/ tx = div(10,3);
2 e5 X6 z/ \$ W1 l" Qprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0; : u5 q& b, h# Z
} : P+ ]7 F* `8 u6 _+ u
</FONT>6 A  t6 b4 B/ n) f/ |9 b
</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>1 `; _5 P6 h3 s% l- C, F8 D5 o- K
功 能: 获取扩展DOS错误信息 9 U* B& U- f; Z, L6 \' D& a
用 法: int dosexterr(struct DOSERR *dblkp);
( m9 P* I4 b' K, [6 g程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>, g) B1 F. i1 M9 J+ j" b
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) 4 g) X& _4 l* O. N) D0 s6 V
{ & t; ]7 K" K/ J  z8 ?# B
FILE *fp;
5 S4 ]! g8 p& \9 Pstruct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
: t8 G. y1 o9 J+ N3 M! e, z3 fif (!fp) perror("Unable to open file for
% H9 c0 B5 _7 D5 ]) |# h2 sreading");
- s: H' q- q% K; E  w9 _4 udosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ 9 \! J) I7 O2 k8 l- T
information:\n"); ! p. E+ L  i) i/ ?3 @- j
printf(" Extended error: \
( K  P( ~1 m7 ?, m! m2 u7 @%d\n",info.exterror); ' ^# [4 F3 u4 Y$ m- z% R
printf(" Class: \ ' `' r$ n  I5 v2 ^- T. j' \
%x\n",info.class);
) r. K& {- K1 B1 _% Dprintf(" Action: \ 8 y0 X, X/ {9 S+ C' K4 [5 _, A! W
%x\n",info.action);
0 g( s4 [' X$ u7 I  iprintf(" Error Locus: \
" l( V2 Z& H4 o) i  Q" [) N" d%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
. q7 \- p) c& h$ w+ L* M; T} </FONT>
6 X9 Z4 d4 h- q0 G# R$ q( B: ~& }: X0 H! i
</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
: M: a' c7 ^: A$ ^功 能: 转换日期和时间为UNIX时间格式 5 [* U" o3 v+ B0 T7 P
用 法: long dostounix(struct date *dateptr, struct time *timeptr); & E' Z+ r+ m/ M. j0 y6 J3 W
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>
) j: z% }$ Q$ P# ?#include <STDDEF.H>: F0 n; _. \8 H+ L
#include <DOS.H>
" ~% F* Q' S8 M& L9 h# g. ~, `( r9 o#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
1 ^2 r) I, E. t/ G' S{ + D* u6 m" K0 {# _
time_t t; ! p- f, D1 z6 P# R% ~" o
struct time d_time; ( f- n$ a# W. G
struct date d_date; % w. G% T% e: z- Z% B7 {
struct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date); ' o/ Q3 O/ w2 y
gettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time); : P- u4 K+ C* Z
local = localtime(&amp;t);
" @: ~: d; X& z6 W3 }printf("Time and Date: %s\n", \
- d! P% i1 U7 u. n* rasctime(local)); </FONT></P><P><FONT color=#0000ff>return 0;
( C* G4 R" R4 V% o! e} </FONT>4 B' }+ G$ ^) I- E+ |8 Y

' Q0 I  j; j  @6 C7 `; Z</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
9 P% q. P; j! h功 能: 画多边形 $ d$ x0 t0 a2 I
用 法: void far drawpoly(int numpoints, int far *polypoints); ; Z* S$ K2 [$ @- z4 D; r5 I$ J' n
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>( V& N0 P  k1 u$ @
#include <STDLIB.H>, @9 `; ~0 a7 w& _5 `( F9 R
#include <STDIO.H>
- h" a) }5 q3 e/ s' M; X8 a( a; |#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void) ( W/ R; {; R/ d( r6 I
{ + U$ b9 A/ I+ ~; L8 W9 W) F
/* request auto detection */
2 B( l  k0 P( h3 j- k/ eint gdriver = DETECT, gmode, errorcode;
  h0 P3 S( Y& |5 G1 Gint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */
5 H: S/ i4 D# L# \7 rint poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local ! R7 M- b, o+ l) v
variables */ 0 l" Y5 C1 x! X$ c; [2 T
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ . T" T; W4 _0 I* \% q3 n/ P7 c
errorcode = graphresult(); % B, Q6 k/ v: z- O4 t5 X
if (errorcode != grOk)
$ i3 J3 M% I7 r5 J# E* Q9 n/* an error occurred */
4 L4 x8 |+ }: L) @& ~% t# T) t{ $ l5 k5 J. |/ f8 h! T
printf("Graphics error: %s\n", \ 2 _" s. R0 [% R
grapherrormsg(errorcode)); , R! F# i+ U3 F+ K
printf("Press any key to halt:");
3 W. s& l- l. p& N" @getch();
, K, [) y% I; g, w" d/* terminate with an error code */ . J* p, c: s* d, B6 Z
exit(1); 8 f5 F% E* f8 R+ ^7 y
} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); % ~2 w( y5 ~: B% b2 }! |3 L3 h
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */
' ]0 K% s7 k- H! K- q7 g+ |+ bpoly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */
: k# L* {& O7 t9 J  K9 V) fpoly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */ ; r7 e' z4 \) Y4 I8 z! u
poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
2 j9 o+ p( t  f9 U: m3 T; v7 \poly[7] = maxy / 2;
7 t  A3 d" J- @3 E% g8 {; X" L/*
6 e( @9 Z5 I; @drawpoly doesn't automatically close " G3 O6 [' j* R
the polygon, so we close it. 2 f1 L( D, S3 b- Y% e
*/
, c6 D+ k1 x$ w" ^# e8 Ipoly[8] = poly[0]; ( O9 F- E  c0 L& Y
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
( V8 s/ `1 g; t0 rdrawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */ 2 r) x6 \+ v$ L
getch(); 4 r% d) _! L* X" ^
closegraph(); 1 |2 O, {5 {7 L) Y& b* }
return 0;
1 O; f1 t+ r+ g1 w% N. \: a& a} 3 E3 k5 E$ l( p7 H. K. y# \; c
</FONT>
# [( q/ d# w3 P! S9 T</P><P><FONT color=#ff0000>函数名: dup </FONT>
% Z) D. Z! f* ^% W9 b5 ^* k功 能: 复制一个文件句柄
# x2 t% T' C3 f2 N$ ]用 法: int dup(int handle); # k! j9 N. q0 C% c. w8 P8 G
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>0 U7 F! |+ ]9 \, f- k' m
#include <STDIO.H>
; z: Q$ l% Z7 S#include <CONIO.H>' `" ?" c5 e% c- \. F
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
) o7 |" ]1 M4 X% z{
, E, l2 a5 U0 O$ e0 K5 o/ h3 CFILE *fp;
+ P* X3 c3 o* T' nchar msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ / Y" U  S/ e' U3 \+ Y7 s6 x6 c
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */
' M( g/ r4 M3 d& V, X  y% Tfwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr();
' w; F. M& d8 o1 cprintf("Press any key to flush \
9 W/ Z/ L: H! f- c# m- ZDUMMY.FIL:");
5 g+ Z, {& w. Z+ ~8 m; f) u* Ogetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without , `) W) K  y6 E+ X# G0 k: N0 V
closing it */ " S+ b2 n" x( u7 D
flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \ 5 `0 _1 d- k( U  W  B  T4 k9 F
key to quit:"); * H0 Q: L* E1 x4 j! w5 D4 a" g
getch();
" J. H# R! q0 dreturn 0; 1 w4 W% t  t: ^, P! {( m2 \) E
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream)
8 S7 [+ k" B2 T% N' Q& |) ~{   S  U" k7 \: L1 V; K* q: ]
int duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */
  ~! \& K9 i- w% Ffflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ - \7 d9 n1 l: ]: K: e
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the
' {0 Z; U: M) m) e6 @4 l* k2 X# N) g5 dDOS buffer */ % T& h$ c7 X/ d
close(duphandle); , b' `0 q/ B8 f* U2 t
} 9 s# e" r/ B; o) T9 C0 I1 C
- h5 ]# s; i' \% e; _0 @6 R
</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>
  [3 v$ Y# R" j# S4 s* m功 能: 复制文件句柄
* h6 F$ o6 \8 n用 法: int dup2(int oldhandle, int newhandle); $ y# X# y: t7 W! i0 g
程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>
- Z9 c; L% V' N& r' P) R8 _2 |' C#include <STRING.H>
) G6 q2 i$ d  G: n, }$ R: _#include <FCNTL.H>8 a! f* X0 A+ [) ^* Y1 [8 A
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
) D2 h* |. s# M: D) ~4 H5 }' Y1 l{
9 F/ A' y  w. n' r#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; & h# E2 G) W! C3 P5 [! J% E  r* k: ]" ^
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */
. c3 A# F* `# Ynul = open("DUMMY.FIL", O_CREAT | O_RDWR,
' U# }/ |3 G% {( [5 B- vS_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard
5 z2 u( [6 k! ?$ A' j+ z  R( s: voutput */ 9 Q$ O+ n/ C  j$ S
oldstdout = dup(STDOUT);
, Q6 t: F) v$ a, e8 }9 w/*
0 f7 R1 _2 m  M! y% n& Z, aredirect standard output to DUMMY.FIL
  v9 B8 [; S3 F! `4 Y4 Sby duplicating the file handle onto the
# O+ g  O  p: t$ M8 S5 D# ^file handle for standard output.
* W' \: T: Q+ G*/
5 a- q+ a2 x  s) [. M  \dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */ ! A2 s+ v3 k5 H* L
close(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */ - I4 |7 n1 O% Y* D7 U
write(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output : `# G+ w8 n5 H" Q! \6 ]
handle */ ) ]" g0 d1 a7 @
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
8 m: F  B7 i' R, J6 Aclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; 7 u% h5 Z: L: @7 a
}
- i! ^* O) l5 b) N</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-10-25 03:55 , Processed in 0.528756 second(s), 56 queries .

回顶部