QQ登录

只需要一步,快速开始

 注册地址  找回密码
查看: 2061|回复: 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>0 m% r6 B) K8 R/ b0 ?6 ^
</P>
- B1 ~( x" S" ~  S" @- f$ D, r) F# @6 G$ }% d2 V) F

0 k" G; f8 b2 I' S+ r<><FONT color=#ff0000>函数名: ecvt </FONT>
  d8 A" b4 F, }. L, @4 ^) _功 能: 把一个浮点数转换为字符串 ( L1 f  s0 v, p* h" v+ H  W
用 法: char ecvt(double value, int ndigit, int *decpt, int *sign); ' F' [1 `% E5 @# t" m
程序例: </P>
" K% O) v6 F0 }<><FONT color=#0000ff>#include <STDLIB.H>5 E/ V& v* L5 S6 _$ L
#include <STDIO.H>
0 Z1 L8 ]; D# ^+ H) D. i#include <CONIO.H></FONT></P>6 o: W1 J; B0 L$ _" Z: G
<><FONT color=#0000ff>int main(void) * R& O% c3 X/ O" {- ]1 K
{ $ P1 y8 p9 Y3 l6 Z* Q# F
char *string;
, E, q( n2 R6 e: }double value; 6 A  j+ z. ]1 x" Z
int dec, sign;
, ~( o% a3 L2 K/ r; P" H! ^  C! pint ndig = 10; </FONT></P>
. T3 v9 V$ u6 }<><FONT color=#0000ff>clrscr(); 0 L* W- @' W' b: U! W- O1 w
value = 9.876; 4 o0 L- w8 j. q% z: d
string = ecvt(value, ndig, &amp;dec, &amp;sign); - \& _+ h0 ?. w1 V; q: e+ K$ T+ K
printf("string = %s dec = %d \
2 ], g% Y- ~( C6 i5 M2 t$ n1 Lsign = %d\n", string, dec, sign); </FONT></P>7 l' U; n3 |6 m7 A
<><FONT color=#0000ff>value = -123.45; ) ?: W/ w% A3 W* z( s% q
ndig= 15;
+ _2 u+ e8 G* O' |string = ecvt(value,ndig,&amp;dec,&amp;sign);
" |7 k4 f$ J0 k: mprintf("string = %s dec = %d sign = %d\n",
, Y) J  [6 Z- K% D1 n) V5 H- Xstring, dec, sign); * B; Y0 Q  N( ~
</FONT></P>& `3 @# Y2 a) c3 R3 }) B
<><FONT color=#0000ff>value = 0.6789e5; /* scientific
9 @5 \) b5 W% w/ \4 Z0 @notation */
% |- v, H# ~4 m6 s. q7 j# m, Q. Qndig = 5; # T  k) I0 h  V7 _' W
string = ecvt(value,ndig,&amp;dec,&amp;sign);
; c; C: ~) h4 r3 t: Y* L$ M% wprintf("string = %s dec = %d\
3 C: x' l5 F  Q1 @sign = %d\n", string, dec, sign); </FONT></P>
0 C% b6 a7 A4 ?# v- |<><FONT color=#0000ff>return 0; $ R! P/ @2 B3 t7 R2 |, T1 Z7 r/ D
} </FONT>& i9 h8 p$ i0 S$ e: |- z. I4 Q
3 s9 k% B* |  N0 S( x8 Y+ K% f6 H# `* H
</P>
) H6 `0 C0 ?) u6 k<><FONT color=#ff0000>函数名: ellipse </FONT>. B3 b  p# t5 q6 R0 ^5 c8 W
功 能: 画一椭圆
) ^2 z$ O6 M. \9 c$ R用 法: void far ellipse(int x, int y, int stangle, int endangle,
4 V  I3 [3 Q- `: ~) n) nint xradius, int yradius); $ }8 P; M3 q, g& Z6 t
程序例: </P>
: b8 @  o5 Y( \2 G<><FONT color=#0000ff>#include <GRAPHICS.H>
4 p# Z4 q1 M3 N#include <STDLIB.H>
! {1 N. o+ F) I. D. ?#include <STDIO.H>
/ G' A5 S3 K$ D$ ?3 i9 d#include <CONIO.H></FONT></P>
# y5 d- b# I* y<><FONT color=#0000ff>int main(void) 8 E3 Z* Q% c, V  O2 H/ n
{ , ?; r* w4 m9 {5 R
/* request auto detection */
) n$ E) s! X/ Y8 Y4 j: F: O7 [int gdriver = DETECT, gmode, errorcode; & F# z5 l0 C" Z1 `
int midx, midy; $ J, r5 y' \  a; L1 U0 I6 X' p
int stangle = 0, endangle = 360; ! I0 F" k0 Z) U( O8 U
int xradius = 100, yradius = 50; </FONT></P>' `# f& Y9 A$ J$ [9 p
<><FONT color=#0000ff>/* initialize graphics, local variables */ # C% y  G" F( T) z9 c5 N
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P>6 T% P  L( B5 K' ^& ]5 c/ X4 P3 k
<><FONT color=#0000ff>/* read result of initialization */ ( M% z* t7 g' {& ~: w- h( y
errorcode = graphresult(); ( Q: _6 S  g' c) ]; R
if (errorcode != grOk) ' I+ H% F+ o+ U- ~9 J+ c
/* an error occurred */ / B" X/ `/ M- j0 C3 i# x7 E+ r( Y
{
$ ]$ r* G& `5 z! hprintf("Graphics error: %s\n",
" e8 j7 z4 z* q& P* O6 X4 dgrapherrormsg(errorcode));   o, J, ^9 ]) `9 B' L% |7 u4 ~
printf("ress any key to halt:"); 1 v" V: G: a' v+ m( l5 q
getch();
& R1 W1 V9 S: L6 Kexit(1); . \# r, C, G& p* \
/* terminate with an error code */
. [  H) n" ^7 E$ R7 U. R& V} </FONT></P>
$ v' B+ K: ]+ ?; t<><FONT color=#0000ff>midx = getmaxx() / 2;
1 X* k5 m7 i) \" G% A& omidy = getmaxy() / 2; 7 c6 B- N6 {2 ~# |- G0 p5 m
setcolor(getmaxcolor()); </FONT></P>
$ A( \# t5 L& f+ e4 i. [' i  b) ~$ ^2 A<><FONT color=#0000ff>/* draw ellipse */ & }# R% g. @+ C& _3 A9 Q* C
ellipse(midx, midy, stangle, endangle, 4 F6 n. X# z4 E, f; O
xradius, yradius); </FONT></P>! t" o5 G- |$ r. @- b
<><FONT color=#0000ff>/* clean up */
% e  ?7 _3 p, W. l' s" cgetch(); : \; [$ ~5 Y: R# x" r/ [
closegraph(); 3 B% }5 i" f( r3 d; X! R
return 0; + T: c' U5 ?' Y* @4 k  a: D
} </FONT>
. i4 Z6 Z# k2 g" _% w/ A+ c/ ]; h, y! ~3 V+ x: [0 B
</P>
2 e+ u' }. v; R8 y- e<><FONT color=#ff0000>函数名: enable </FONT>( F5 E+ a% ]8 J: B' W+ O
功 能: 开放硬件中断 7 `$ H, f0 u" {8 V2 \
用 法: void enable(void);
9 G! d% r4 S- b7 m" G程序例: </P>* t. I1 d7 Q2 z4 ^$ u+ X6 z. r- b
<><FONT color=#0000ff>/* ** NOTE:
; e, b& h1 z! g8 n% TThis is an interrupt service routine. You can NOT compile this program , Q* p* e( z! ]* I* r) ]# U
with Test Stack Overflow turned on and get an executable file which will
" D4 I- L7 _" T9 D' }9 n' Toperate correctly. ( T% x$ v' p! D. Z+ a
*/ </FONT></P>
0 _; ?+ L& t( R6 D  i+ q# A<><FONT color=#0000ff>#include <STDIO.H>) B/ ?+ {( D3 K; N$ o' R
#include <DOS.H>9 m) Z3 P1 |: k1 }6 f
#include <CONIO.H></FONT></P>
6 Q5 R5 i+ @4 D0 n+ c0 V; w<><FONT color=#0000ff>/* The clock tick interrupt */ ; S5 l' m5 x3 b! X* o6 u
#define INTR 0X1C </FONT></P>, h" i" Q( K, e2 t* R: ^2 G& R
<><FONT color=#0000ff>void interrupt ( *oldhandler)(void); </FONT></P>+ o, v) d: [/ T
<><FONT color=#0000ff>int count=0; </FONT></P>2 r" c. G5 g  ~4 f6 I7 I
<><FONT color=#0000ff>void interrupt handler(void) 1 ]8 i& I5 {; ^+ U, N8 D6 m2 \
{
% N. O. E! L9 A* s$ o7 w3 b$ O% r/*
' a  Y- |/ N  d/ ?  E; T7 T" c8 Udisable interrupts during the handling of the interrupt   u) K' _  }$ D! l' U2 ]
*/ : g. b& A7 m5 @) S
disable(); 1 k' \& z0 f* g8 k8 c3 N
/* increase the global counter */
' ?3 \% s8 g0 ]6 W) H+ d9 Acount++;
" k2 `8 }( x- P/* 4 Z+ ?+ H- q) r$ [: m
re enable interrupts at the end of the handler 9 p; g1 B& O% x
*/
" F& a1 o. B  ?$ w$ Nenable();
; x# v- T( u% H+ Q% ~. X( g/* call the old routine */ & ~; P8 }( r0 N9 T: Q
oldhandler(); 2 A1 u8 l& M$ k% _/ L* l
} </FONT></P>
9 `  c0 [8 n1 b5 e6 `* c; S) u6 t& \<><FONT color=#0000ff>int main(void) 6 X3 g5 M& H: L9 `' V9 g: W
{
( s/ k% ~3 @, b/* save the old interrupt vector */ ; H% ?7 t- L6 ]3 z9 U
oldhandler = getvect(INTR); </FONT></P>" b$ X5 g6 L1 ^7 [% D
<><FONT color=#0000ff>/* install the new interrupt handler */ 7 l4 \2 S1 T2 o
setvect(INTR, handler); </FONT></P>
* N- y: b+ m3 \8 m) U7 p; Q<><FONT color=#0000ff>/* loop until the counter exceeds 20 */ 3 p9 V2 z) c/ q' M5 S
while (count &lt; 20)
2 p( g# `9 o8 O% U7 ]; D1 g. J* Q; B7 jprintf("count is %d\n",count); </FONT></P>% f' f4 i2 t* n; @# l: Y: c1 n
<><FONT color=#0000ff>/* reset the old interrupt handler */ 1 O/ d  J' S% J8 J' h2 ?
setvect(INTR, oldhandler); </FONT></P>7 c. p2 `* m7 L7 m  N- n5 |* M
<><FONT color=#0000ff>return 0; 7 ?, E3 k2 D+ k# j. L9 Q0 h
} </FONT>
, U1 r: Q4 L% F% Z) P# O3 @: K
8 u) A  q$ O# k6 C1 f8 t  a6 [</P>
2 y" r0 d0 y6 z# @1 Z4 D<><FONT color=#ff0000>函数名: eof </FONT>2 ?6 `# C7 W4 M7 K
功 能: 检测文件结束
" L! A  o7 \3 N4 u用 法: int eof(int *handle);
% _8 e5 L8 b) A' X/ t9 F程序例: </P>9 _5 `# x1 i# W' ]
<P><FONT color=#0000ff>#include <SYS\STAT.H>: p5 {/ V7 {$ P3 G" {2 ^: T& O2 m* ^
#include <STRING.H>5 B$ z7 h7 c- R6 R' N
#include <STDIO.H>
* o& a, c( B/ Y$ n( |* K; T#include <FCNTL.H>
- B$ k) Z% V+ R  v7 ]3 \#include <IO.H></FONT></P>' Q# P& h$ ]' n
<P><FONT color=#0000ff>int main(void) 3 E; z/ ~6 r, N* Q( u9 `) v1 b
{
$ ?: o9 u; H/ _0 I- i! }, `8 yint handle; ( N. L$ y: C" s! R. O& H/ c. ]
char msg[] = "This is a test"; 7 w; `4 Y6 p2 D% p: Z0 K9 [
char ch; </FONT></P>
$ R7 w3 r. g+ s& d<P><FONT color=#0000ff>/* create a file */
. p! h+ E2 c) j: U1 W/ `+ G  e. chandle = open("DUMMY.FIL",   j, d* o- ~3 }$ m0 S
O_CREAT | O_RDWR,
3 L$ L/ K7 W, f+ T8 US_IREAD | S_IWRITE); </FONT></P>
4 x) E7 z- E2 A2 i4 V( @<P><FONT color=#0000ff>/* write some data to the file */ * {% Z2 J( m& L" g) |% d6 B
write(handle, msg, strlen(msg)); </FONT></P>
+ D9 [, E9 b! S) @+ `5 [<P><FONT color=#0000ff>/* seek to the beginning of the file */
4 R* I' e; t0 ?4 z! B" E, H3 Y: ilseek(handle, 0L, SEEK_SET); </FONT></P>
- U9 _$ k# l! W! |9 A<P><FONT color=#0000ff>/* % |7 u. u; J% S( O3 l9 l- M
reads chars from the file until hit EOF
9 k6 E) N6 F8 m*/
, k; N, M$ P0 V# T: ^# E7 ldo ( O3 K% X' P+ y4 t
{ & f- o3 d+ O. W9 O" A
read(handle, &amp;ch, 1); - J- L& L2 V% w
printf("%c", ch); * _+ o" V" J( N% V. s; v+ ~
} while (!eof(handle)); </FONT></P>
* ?% D; x6 m, I<P><FONT color=#0000ff>close(handle);
) d; Q5 _0 k% i3 h6 R& p1 Preturn 0; * C8 E" q7 L, x, K/ O- ?& ~2 |
} : a$ `$ s6 H* m: b
</FONT>
1 a; n& |; m& g/ d</P>- q! o- G* G7 f% K9 I" J0 k" W
<P><FONT color=#ff0000>函数名: exec... </FONT>
7 g2 R) T! A8 B! g, ?功 能: 装入并运行其它程序的函数 0 w& e5 ?7 O, ~; d# V4 B
用 法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
- U% I. A3 j' M7 G2 I9 Nint execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
4 U! d6 E5 N+ Y1 u" Mchar *envp[]); 0 }' d) f8 A' z( j
int execlp(char *pathname, char *arg0, arg1, .., NULL); - x. A/ ~1 u2 X" V9 R
int execple(char *pathname, char *arg0, arg1, ..., NULL,
7 U9 J' y9 ]& v, k7 l. A- {char *envp[]);
3 T( D4 A3 d" f0 ~4 b4 ?int execv(char *pathname, char *argv[]);
" p  K0 Q/ q; W- f3 ]1 [" P* sint execve(char *pathname, char *argv[], char *envp[]);
: m) j$ o9 Q0 ^int execvp(char *pathname, char *argv[]); 9 D2 u/ ]$ D. N, ^/ J2 L* I3 X
int execvpe(char *pathname, char *argv[], char *envp[]);
4 X3 l: o# I4 {程序例: </P>
3 o" j7 Y; b! m" S5 R( y" v<P><FONT color=#0000ff>/* execv example */ + i4 d" m- ^5 S* ]. p/ w5 k5 b
#include <PROCESS.H>
# M2 n; a3 @9 S3 Y1 r6 V#include <STDIO.H>3 |* q: E! b. U
#include <ERRNO.H></FONT></P>
2 p' p( J2 ^2 u! R2 o/ ^2 {<P><FONT color=#0000ff>void main(int argc, char *argv[]) $ m9 i( n7 j, ~( G( k% n6 Z
{ 6 D3 F+ V' y! j
int i; </FONT></P>+ N' a+ }9 }3 t5 i. a/ x
<P><FONT color=#0000ff>printf("Command line arguments:\n");
. Q5 _, S. x. W3 L; [+ Z8 kfor (i=0; i<ARGC; <br i++)> printf("[%2d] : %s\n", i, argv); </FONT></P>- l5 j7 B2 v- {  z# I9 K8 P8 T
<P><FONT color=#0000ff>printf("About to exec child with arg1 arg2 ...\n"); 8 `/ Z( H8 q. U9 a$ h9 l
execv("CHILD.EXE", argv); </FONT></P>
* b6 I7 r: P" d<P><FONT color=#0000ff>perror("exec error"); </FONT></P>
5 p0 z3 d6 j4 l<P><FONT color=#0000ff>exit(1);
- d  S: i! x. g. ~* i} 5 _+ s& N; K% E
</FONT>
1 I2 n; P/ j3 K# \/ ~</P>
+ Q! l# D+ s2 S$ ?0 W" y4 N1 m' t* E<P><FONT color=#ff0000>函数名: exit </FONT>
7 H; P4 ]* F: v8 {2 r7 }功 能: 终止程序
; |4 c8 c- r5 l: p用 法: void exit(int status);
1 n/ b6 }, C" |: p0 q! v% S% q程序例: </P>
. M: \4 u( _$ v" E6 f+ u<P><FONT color=#0000ff>#include <STDLIB.H>
/ ^1 Q+ _3 }) h5 D3 V0 d: c5 r#include <CONIO.H>) g& o8 S- \1 A8 j' v" Y5 j
#include <STDIO.H></FONT></P>& h( [* |. @1 V9 b9 F
<P><FONT color=#0000ff>int main(void) $ I: s0 s9 Z' i% d' M, Y/ N
{
; [7 R. }4 \. _: aint status; </FONT></P>" L9 B+ j/ ]9 `! M" E
<P><FONT color=#0000ff>printf("Enter either 1 or 2\n");
! Q. {9 \+ n  i! Vstatus = getch(); $ r8 e7 z3 ]8 F" W" g/ m; _
/* Sets DOS errorlevel */
! S7 F- ^7 g( {exit(status - '0'); </FONT></P>) w/ K# |) G# s! K
<P><FONT color=#0000ff>/* Note: this line is never reached */
$ B0 J( {/ z$ {) L4 Zreturn 0;
! p: B% E7 {- V# N% O  R( f) {! J}
  ^7 |# }: d0 D  |, a: W# Q& a</FONT>! m; W) l  y* ?, j9 F
</P>
) {! Z1 |, [8 H! ?$ m: X. m<P><FONT color=#ff0000>函数名: exp </FONT>
  [4 W5 v" e6 f/ \功 能: 指数函数
' l+ v4 a3 o) E# r. @用 法: double exp(double x);
# x& J* ?5 p' W. I  @0 ~% U1 `程序例: </P>
4 i1 Y% x4 r% P$ ]% U<P><FONT color=#0000ff>#include <STDIO.H>0 p2 I( T( G6 ^
#include <MATH.H></FONT></P>! k0 a9 n- n$ O, ?
<P><FONT color=#0000ff>int main(void)
6 B; {& t+ Z8 V, i, L# p, ]{ 9 P7 N, F2 J3 N4 y& N
double result; 6 z- W  ?3 N) O- ^2 l
double x = 4.0; </FONT></P>% k) G$ X* |( G7 `2 G: ^. z% v0 p
<P><FONT color=#0000ff>result = exp(x);
% n3 e. k6 E9 e6 C* \printf("'e' raised to the power \ 5 j! v( W! ^$ i. }/ |2 H
of %lf (e ^ %lf) = %lf\n", 6 T  E2 q+ o) }2 m8 z% t
x, x, result); </FONT></P>
* ^  w4 u7 y& y# Q6 _1 h<P><FONT color=#0000ff>return 0;
4 m* \; w% h$ l& Q4 D7 [}
9 R$ m* ]$ }/ }; s1 S% i</FONT></P>
zan
转播转播0 分享淘帖0 分享分享0 收藏收藏0 支持支持0 反对反对0 微信微信
韩冰        

823

主题

3

听众

4048

积分

我的地盘我做主

该用户从未签到

发帖功臣 元老勋章

< align=center><FONT color=#0000ff size=3><B><FONT color=#cc0000>函数大全(d开头)</FONT></B></FONT>6 c. g  X; U. K$ J
</P>
8 b$ W, ]$ k  @" k! o& T7 Y  M8 G5 n<p><><FONT color=#ff0000>函数名: delay </FONT>
' O6 v: e7 n3 {8 q功 能: 将程序的执行暂停一段时间(毫秒) 8 A; T) ~! H5 T% c9 y
用 法: void delay(unsigned milliseconds); / b4 K! j: T7 [( i- a9 F
程序例: ; V6 m( X3 _4 k& }! J0 b) k
<FONT color=#0000ff>/* Emits a 440-Hz tone for 500 milliseconds */   j1 @( t" v# a1 e6 b
#include <DOS.H></FONT></P><><FONT color=#0000ff>int main(void) 4 L8 v. Q1 U1 l. J2 \8 v9 b: G
{
. l8 H& C4 J1 `sound(440);
( H5 F5 V0 p" C+ F' Rdelay(500); 0 N* N, I) H" Z5 I
nosound(); </FONT></P><><FONT color=#0000ff>return 0;
1 W0 |' h& d- K+ J* `, Y}
; Q# r+ |  p1 z; J7 p7 t
4 T, _  g3 X% N; R</FONT></P><><FONT color=#ff0000>函数名: delline </FONT>
8 a4 @; r. x* m1 r4 q, i功 能: 在文本窗口中删去一行
) x0 g1 a; a7 M4 ?. i用 法: void delline(void);
) K: l3 b3 e+ \- a9 r' X& x程序例: </P><><FONT color=#0000ff>#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void)
; U' f+ O, H$ H{
( h/ k6 @( W7 l+ V) x4 Y* L( X( Eclrscr();
: u9 f4 `5 [# v( ]4 W- fcprintf("The function DELLINE deletes \ / S$ \# `5 x3 U) {4 _1 x, M& q: Q
the line containing the\r\n"); # v; I4 T& Z  X& b7 L2 \3 F8 n, X
cprintf("cursor and moves all lines \ & T. o3 [: t+ v
below it one line up.\r\n"); 4 P1 N: K' l9 Z  W7 U7 c1 _
cprintf("DELLINE operates within the \ ; ]/ S% P* ?! ]' g
currently active text\r\n");
/ p8 y* I5 T6 F$ D# f- kcprintf("window. Press any key to \ , ^& l8 W9 A- `& W) z
continue . . ."); + w& B  {! s; P; R- i7 P
gotoxy(1,2); /* Move the cursor to the
' ?/ L( k5 l$ O$ n% s) e' bsecond line and first column */
- r! M( Q3 m; {0 Egetch(); </FONT></P><><FONT color=#0000ff>delline();
8 p$ W. R7 P8 d" W4 y7 K$ tgetch(); </FONT></P><><FONT color=#0000ff>return 0;
3 H4 }$ s7 z* K1 u$ ~. r- D: Y, c} </FONT>
5 C* Q$ x# K5 X  @+ Q! W$ o$ h</P><><FONT color=#ff0000>函数名: detectgraph </FONT>
8 F. {  Z; p7 d2 L4 K6 H. p, X, `功 能: 通过检测硬件确定图形驱动程序和模式
3 k# t' c8 ?# q) D5 J用 法: void far detectgraph(int far *graphdriver, int far *graphmode); ) K0 A7 F7 O6 }2 h+ t
程序例: </P><><FONT color=#0000ff>#include <GRAPHICS.H>
' n; r6 H# ~3 x8 B2 U; d2 R3 d#include <STDLIB.H>" t; K- {) G* z; K- `0 u8 A
#include <STDIO.H>2 }6 N# T2 l% m( U0 @* l1 P
#include <CONIO.H></FONT></P><><FONT color=#0000ff>/* names of the various cards supported */
2 n+ o5 u# V2 [. T+ T! bchar *dname[] = { "requests detection", 5 x4 ]" K! s! P2 _& D7 c
"a CGA", ; w  d/ w+ u, r: G" l
"an MCGA", 8 @5 O. J& p5 [" n6 Z: F
"an EGA",
" c0 W- B4 H- z$ F"a 64K EGA",
6 V" ~- X$ D; y* G+ v"a monochrome EGA",
' D. c- ~9 U( `+ p"an IBM 8514", 4 a4 R! G1 e5 W) h
"a Hercules monochrome", , G  ^2 S- Z3 j1 w  b0 B5 M, t4 H/ l
"an AT&amp;T 6300 PC", 2 o& R; j, D, L3 z$ b3 H6 J
"a VGA", 0 e# Z+ r6 t* z6 R, W
"an IBM 3270 PC"
0 |' q, E: u' L5 z: W}; </FONT></P><><FONT color=#0000ff>int main(void)
- g3 e+ e! E5 u) \- V# F{
5 l4 ?& Y0 `5 c  i5 u- i/* returns detected hardware info. */
. B6 Q$ u8 ?  o( Bint gdriver, gmode, errorcode; </FONT></P><><FONT color=#0000ff>/* detect graphics hardware available */
8 ]% @8 N9 O! I+ _% u, g% adetectgraph(&amp;gdriver, &amp;gmode); </FONT></P><><FONT color=#0000ff>/* read result of detectgraph call */
9 Y8 V7 J& \4 ]7 M: w9 rerrorcode = graphresult();
" M; V: F' U9 U& k) h1 M, nif (errorcode != grOk) /* an error   f+ q5 `- \+ X0 y2 o
occurred */
. x4 ~8 t3 E$ Q{ ' G6 ?# g+ m/ ^0 b
printf("Graphics error: %s\n", \
1 E% t! T" J. q4 @grapherrormsg(errorcode)); : r2 T3 l& f' N' ~) Q, ^4 C
printf("ress any key to halt:");
1 a+ x. K# U4 D. F$ lgetch();
/ m3 y. y) w7 d' Vexit(1); /* terminate with an error
1 `( \2 h1 @; }* icode */ $ G$ Q9 w3 `% a( F* y
} </FONT></P><><FONT color=#0000ff>/* display the information detected */
' I4 C$ `: `4 J8 W) O5 Vclrscr();
5 N3 q8 H) x4 s+ s: oprintf("You have %s video display \ , R# `3 B) B7 j7 z5 U- |
card.\n", dname[gdriver]);
8 p; o& o  y; Y( {" u' n* Qprintf("ress any key to halt:"); 9 h4 [; o7 q7 z, E4 P
getch();
1 K3 x/ g2 `- D6 {return 0; 4 L4 I9 f- Z; p
} </FONT>% W( J- d; M$ o

* ?. K! i& N, q- j, Y- t6 g) N3 b5 y3 O2 q4 S$ \
</P><><FONT color=#ff0000>函数名: difftime </FONT>! o' Y7 o, O6 S3 A9 E; P7 e: i. e
功 能: 计算两个时刻之间的时间差
% e6 V5 |6 m- ]7 B7 p用 法: double difftime(time_t time2, time_t time1);   ?  k% M  r0 \6 e
程序例: </P><><FONT color=#0000ff>#include <TIME.H>2 B) B, E4 k7 u* h( u) Y/ w
#include <STDIO.H>
' L% x- {; ~) D" w8 _5 |5 K& Y#include <DOS.H>
0 J1 q: A  m% v  t( t#include <CONIO.H></FONT></P><><FONT color=#0000ff>int main(void) 4 A& y( m4 f5 y0 \/ n6 O3 p' ~4 A2 ?
{
" o- |6 Q7 w5 A( s* D: i5 ^/ i4 Dtime_t first, second; </FONT></P><><FONT color=#0000ff>clrscr();
8 d3 J8 v. x, ~first = time(NULL); /* Gets system
2 ?) h7 J3 G2 ltime */
" ?# X- j4 q4 G* ^( Y1 f! r! ]delay(2000); /* Waits 2 secs */
$ l) U4 g& R. t6 f4 Xsecond = time(NULL); /* Gets system time
7 v! O8 m" W: b+ W) a" g' R( J) yagain */ </FONT></P><><FONT color=#0000ff>printf("The difference is: %f \
8 d) b7 t3 ?0 O( T3 _! P" ~seconds\n",difftime(second,first)); % K6 K9 [; i: U' A1 f9 Y' R* W
getch(); </FONT></P><><FONT color=#0000ff>return 0; 8 {$ X, j, B3 Q
} : }- M+ C$ S$ H% t$ ?/ \
</FONT>
/ A5 j! Z! t! R9 M9 O</P><><FONT color=#ff0000>函数名: disable </FONT>
' B& |7 A  A7 A" ^) Y功 能: 屏蔽中断 ! D( V: o& |: D
用 法: void disable(void);
& d2 f0 ]# P; X程序例: </P><><FONT color=#0000ff>/***NOTE: This is an interrupt service 9 g$ A. O" j* Q$ Z  A: }
routine. You cannot compile this program # `) B& ]1 S% i. ?" q9 q% C
with Test Stack Overflow turned on and - Y5 l; B; U* m; o3 O* u2 N
get an executable file that operates
7 X4 U: s& w8 A. W) X) O$ y+ J1 @correctly. */ </FONT></P><><FONT color=#0000ff>#include <STDIO.H>8 T' n1 N0 t( X! T
#include <DOS.H>
* h! x3 z+ M* D- Y#include <CONIO.H></FONT></P><><FONT color=#0000ff>#define INTR 0X1C /* The clock tick
7 x$ S# s. c2 T1 b. h3 T7 z5 B# p3 Pinterrupt */ </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) : t9 P' `0 o+ [/ Y- `
{
. ?# ~: k9 A& ?9 m" \7 Z5 t/* disable interrupts during the handling of ) }' h. P( t1 M. @% v8 K9 w+ Z
the interrupt */   V! \% B- o- E  b- d) m6 J
disable();
0 Q: v" c+ h, e2 D+ E: I0 ?& [2 h/* increase the global counter */ , }) k) H3 s/ `/ m
count++; 6 W8 ]; O0 t+ G3 A
/* reenable interrupts at the end of the 5 f- q+ }* l4 g* g6 d, K
handler */   D( R0 z4 M: Z& C: C. P
enable();
. r- N3 P. v. ^( Q+ R7 f) w, M$ O/* call the old routine */ # M' z, ]1 y, c4 C2 ?0 W% z; N
oldhandler();   ?* }2 t: D* R0 e
} </FONT></P><P><FONT color=#0000ff>int main(void)
/ `- u1 Z1 S, c" c{
9 s0 P$ s" I0 h6 C* G' U/* save the old interrupt vector */ ( z2 w) b2 ^  d0 ~; _: }  q
oldhandler = getvect(INTR); </FONT></P><P><FONT color=#0000ff>/* install the new interrupt handler */
1 G7 ^8 b* L' f# X# I' P0 l( `setvect(INTR, handler); </FONT></P><P><FONT color=#0000ff>/* loop until the counter exceeds 20 */
. {9 \- I) A4 mwhile (count &lt; 20) " `. o" X3 }5 L( k
printf("count is %d\n",count); </FONT></P><P><FONT color=#0000ff>/* reset the old interrupt handler */
; M. C# [0 }& X2 f' }$ @: r! J7 osetvect(INTR, oldhandler); </FONT></P><P><FONT color=#0000ff>return 0; 4 C% Q8 v1 @0 ~  Z* g0 ^/ M% |
} </FONT></P><P><FONT color=#ff0000>函数名: div </FONT>
5 k' [: j& Q. ~. D6 G* T' K, P功 能: 将两个整数相除, 返回商和余数 & [) e$ T3 L6 s  O( N( z
用 法: div_t (int number, int denom); ' f  D; n- x* R
程序例: </P><P>#<FONT color=#0000ff>include <STDLIB.H>
- G( Y! g4 I- o" ~4 @; d# v#include <STDIO.H></FONT></P><P><FONT color=#0000ff>div_t x; </FONT></P><P><FONT color=#0000ff>int main(void) . d' @( g9 H( V4 r0 W% @$ R
{ 7 Q' `2 M% s" F( s3 i& J% I
x = div(10,3);
6 r1 W$ S. t# {1 X" D5 gprintf("10 div 3 = %d remainder %d\n", x.quot, x.rem); </FONT></P><P><FONT color=#0000ff>return 0;
3 f; b# C/ t$ _. F& C" A5 Y$ s} 9 E* g% ^; i8 H2 F
</FONT>
- J7 k8 @( e5 ~' b$ }0 K</P><P><FONT color=#ff0000>函数名: dosexterr </FONT>5 m, W: O2 x/ m
功 能: 获取扩展DOS错误信息 5 _* T1 e5 C; {- |7 `+ T' `
用 法: int dosexterr(struct DOSERR *dblkp); ( p5 Y& T1 F# s* i( j
程序例: </P><P><FONT color=#0000ff>#include <STDIO.H>/ f9 o3 b/ i# k+ S
#include <DOS.H></FONT></P><P><FONT color=#0000ff>int main(void) # I# N( }5 y- I8 n: @5 J
{
6 r6 l6 c% P4 s+ ]& AFILE *fp; ; z; ^" C5 l$ X! b& }  B8 ], ^
struct DOSERROR info; </FONT></P><P><FONT color=#0000ff>fp = fopen("perror.dat","r");
0 _- f; H8 E$ z9 [if (!fp) perror("Unable to open file for - V: f8 z5 z- v- P
reading"); ) o, _# ?3 p  M' Y8 ^, j, g
dosexterr(&amp;info); </FONT></P><P><FONT color=#0000ff>printf("Extended DOS error \ # i# [( }5 ]. B
information:\n");
  Y2 G$ C" r  H3 N9 K# z. P: F; Wprintf(" Extended error: \ - G) Y& W8 q7 v9 i, u/ U
%d\n",info.exterror); , l, l+ \0 b; {' k; d
printf(" Class: \ 4 N4 d5 N1 @  }! ^, }5 d
%x\n",info.class);
/ U- Z9 F* c4 X4 S, U" zprintf(" Action: \
8 c3 m  n4 x9 F- ?' T%x\n",info.action); 9 U' J' X6 Z9 g* C1 m1 @0 V
printf(" Error Locus: \
, S/ D0 N1 \9 \7 I' ]. a%x\n",info.locus); </FONT></P><P><FONT color=#0000ff>return 0;
& _/ b1 U0 [, k( T5 r} </FONT>
. `8 e; _) w* g0 W, G4 v
0 C/ I# K' L' L8 C</P><P><FONT color=#ff0000>函数名: dostounix </FONT>
# k, q+ z( G: F功 能: 转换日期和时间为UNIX时间格式 # b/ d: R/ T+ f
用 法: long dostounix(struct date *dateptr, struct time *timeptr); 3 e2 u8 p" [+ T8 C' y
程序例: </P><P><FONT color=#0000ff>#include <TIME.H>7 @& m: ^3 u4 L. k  l- t
#include <STDDEF.H>4 d9 m5 [. d6 O' e/ L2 {
#include <DOS.H>7 f6 V. ?4 F  ?/ O' u: f
#include <STDIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
4 V6 e  D& Q; t3 Q5 ^* s! u7 Y{ 3 t- w1 S3 C4 h8 d& q; z9 \! C
time_t t; # U; U4 S0 v3 c# J4 r6 ]
struct time d_time; ) O* B9 q9 `1 e: \* R: S; z: T
struct date d_date;
! ^& @7 h8 f5 d3 }. j7 _$ wstruct tm *local; </FONT></P><P><FONT color=#0000ff>getdate(&amp;d_date);
9 z: g0 T$ @1 L: x: o6 ogettime(&amp;d_time); </FONT></P><P><FONT color=#0000ff>t = dostounix(&amp;d_date, &amp;d_time);
2 P6 h9 L! w+ V; h. v$ d2 Flocal = localtime(&amp;t);
/ J9 c) D, g% |* C. r) K! e* w7 h$ eprintf("Time and Date: %s\n", \
5 w- u! T" B- Casctime(local)); </FONT></P><P><FONT color=#0000ff>return 0; $ ]& |% x( J4 |6 }& V
} </FONT>
: T" H5 n3 p0 N& }: p6 G& A: W  p! n2 `" V& c4 }
</P><P><FONT color=#ff0000>函数名: drawpoly </FONT>
6 @& _7 l+ t) i* W+ V) H+ X功 能: 画多边形 % V4 S; S2 j3 K/ O
用 法: void far drawpoly(int numpoints, int far *polypoints); # K7 a* w% l' a: U' S4 @7 \$ D
程序例: </P><P><FONT color=#0000ff>#include <GRAPHICS.H>7 A' v& d& L* t' M; ?
#include <STDLIB.H>
+ ?- G) m" A) O2 d$ s. D#include <STDIO.H>3 {: L% e8 m9 }5 }
#include <CONIO.H></FONT></P><P><FONT color=#0000ff>int main(void)
) w! d6 p( j, `5 ~6 P2 v{ : S$ r, m' ?1 t$ Z5 D
/* request auto detection */ 2 C+ F& H3 y. _- s. v2 O& Q
int gdriver = DETECT, gmode, errorcode;
. ^7 j8 f' ]5 p% X6 Gint maxx, maxy; </FONT></P><P><FONT color=#0000ff>/* our polygon array */ & @; M# x7 d9 w5 I( i. G
int poly[10]; </FONT></P><P><FONT color=#0000ff>/* initialize graphics and local + e+ J, m: y- f" Q0 p6 B
variables */ ) d; K: B& T- y% ], Q
initgraph(&amp;gdriver, &amp;gmode, ""); </FONT></P><P><FONT color=#0000ff>/* read result of initialization */ ! X0 Z5 @1 ?* q: {! c( o/ A5 K
errorcode = graphresult();
- K$ @5 C. ?# Y" A6 j* Kif (errorcode != grOk)   d" m# ?9 z. T& y4 w# }
/* an error occurred */
# K6 Z) Y, A/ Z1 H; f* @{ 2 x& D( O4 c- D$ O: E
printf("Graphics error: %s\n", \ # \1 k' x0 u/ b: T) T( ?; D8 E
grapherrormsg(errorcode));
2 i4 d; b- t" P5 L/ W5 cprintf("Press any key to halt:");
, F9 T* m# q3 o" n* f) d: U. q# {7 ?5 Pgetch();   L' _. a+ T3 T
/* terminate with an error code */ 9 w$ N/ a; Y# D  F' E  D6 O
exit(1);
+ o& O3 q7 `$ k% f  v5 m} </FONT></P><P><FONT color=#0000ff>maxx = getmaxx(); & i; n) P; t7 f7 y6 F* [" Y) T
maxy = getmaxy(); </FONT></P><P><FONT color=#0000ff>poly[0] = 20; /* 1st vertext */ 9 o/ A* c7 E3 @7 _! {6 i1 |
poly[1] = maxy / 2; </FONT></P><P><FONT color=#0000ff>poly[2] = maxx - 20; /* 2nd */ * d8 X/ M# e- u$ F7 |, a* W
poly[3] = 20; </FONT></P><P><FONT color=#0000ff>poly[4] = maxx - 50; /* 3rd */
/ r3 f" q/ ~0 e; D6 \poly[5] = maxy - 20; </FONT></P><P><FONT color=#0000ff>poly[6] = maxx / 2; /* 4th */
/ R8 B$ E: v* m% V" a# U9 opoly[7] = maxy / 2; 5 J- u' {4 T0 d) J7 D: ?$ Z
/*
- S* ]- L" s) Q3 h$ kdrawpoly doesn't automatically close
8 ?, d  a# c' y% kthe polygon, so we close it. 2 T' }4 X2 a$ U: m& B, Y* i
*/ / J2 T/ S8 V0 S; U! w; ^9 l( X
poly[8] = poly[0]; + t) g8 T  u9 s( A( Z
poly[9] = poly[1]; </FONT></P><P><FONT color=#0000ff>/* draw the polygon */
2 D5 N4 I# T" u3 p2 z: k* {drawpoly(5, poly); </FONT></P><P><FONT color=#0000ff>/* clean up */
% x1 M0 v: z2 P3 ~8 D- y4 Kgetch();
& K' {; W' |* O# {closegraph();
* {# d7 K( U6 g+ X. P$ R+ D5 Vreturn 0; . J2 s, F  _" y6 o4 f
}
) G% e- \3 w5 f% G5 _& L$ ?) Y# U</FONT>2 x$ t# ]: B7 @5 H' m
</P><P><FONT color=#ff0000>函数名: dup </FONT>
. [! }/ w/ E7 w, `, `功 能: 复制一个文件句柄 8 H+ f$ L5 f, b4 V5 N' C' {+ v
用 法: int dup(int handle); / _' T4 ?5 u2 I2 |3 \
程序例: </P><P><FONT color=#0000ff>#include <STRING.H>& w$ Y$ W9 e+ S1 S1 [
#include <STDIO.H>
: r" P1 }. y  ]5 T! c* H1 T7 x#include <CONIO.H>. V3 q- y) |, m$ y) B5 T% r
#include <IO.H></FONT></P><P><FONT color=#0000ff>void flush(FILE *stream); </FONT></P><P><FONT color=#0000ff>int main(void)
3 I  d0 c" \/ j2 [+ o4 ^9 g{ % a& m& ?2 T/ u4 n
FILE *fp;
1 D4 ?6 J9 v$ }8 O+ ]char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ ! m& G$ H; e9 W" j9 o* O3 C  a
fp = fopen("DUMMY.FIL", "w"); </FONT></P><P><FONT color=#0000ff>/* write some data to the file */ " h, n+ j: Q% o: E/ @7 f
fwrite(msg, strlen(msg), 1, fp); </FONT></P><P><FONT color=#0000ff>clrscr(); 5 G; G0 Q& t: g
printf("Press any key to flush \ 3 M4 u6 ]+ ?; _* |4 y
DUMMY.FIL:");
8 q6 |1 \* T; f& J9 s$ ugetch(); </FONT></P><P><FONT color=#0000ff>/* flush the data to DUMMY.FIL without ( n3 q: l- X( F  L
closing it */
6 q3 G$ ]3 V1 [flush(fp); </FONT></P><P><FONT color=#0000ff>printf("\nFile was flushed, Press any \   m: n% A* J- g$ @# Q
key to quit:"); ' T' i- w3 X! [1 v% z) n( t9 c+ g
getch(); & i) I$ h: ^/ P3 y5 h) ]
return 0; : y* @; i+ P* |. y2 Y! w
} </FONT></P><P><FONT color=#0000ff>void flush(FILE *stream) / n; n1 v5 A% M; ^: P5 p$ O
{
$ j1 }" [3 A/ q1 y+ I* lint duphandle; </FONT></P><P><FONT color=#0000ff>/* flush TC's internal buffer */ ; \! i  G! X! A. s2 T
fflush(stream); </FONT></P><P><FONT color=#0000ff>/* make a duplicate file handle */ 1 c' Z+ z+ h  t4 c1 O$ z/ G
duphandle = dup(fileno(stream)); </FONT></P><P><FONT color=#0000ff>/* close the duplicate handle to flush the - u+ P, A- d  y6 ^- ^
DOS buffer */
9 I7 y% T1 H! q; X! X" q8 Tclose(duphandle); 0 z/ h6 K0 K' q/ W7 y" X
} 2 w( S* R1 J7 ?

4 W0 B$ v7 ?# Y' C  w& o</FONT></P><P><FONT color=#ff0000>函数名: dup2 </FONT>+ h' P0 r& q& D1 Y
功 能: 复制文件句柄 9 R  z- b8 B- Y9 N: ?' _
用 法: int dup2(int oldhandle, int newhandle);
5 N: F) o. d; m6 E, M2 Z! g' E- L程序例: </P><P><FONT color=#0000ff>#include <SYS\STAT.H>  }" F0 k' P1 F& C3 X- q) D
#include <STRING.H>
, a9 c. \6 i  W5 V' {" f1 O3 g+ j% T#include <FCNTL.H>* N* ]* g- u; `+ U7 V  |
#include <IO.H></FONT></P><P><FONT color=#0000ff>int main(void)
9 e1 ]% y) n' M! z1 a$ w4 F{ - U7 p3 G5 b! o. `
#define STDOUT 1 </FONT></P><P><FONT color=#0000ff>int nul, oldstdout; $ R) o  b$ W6 T' i/ s- z7 b
char msg[] = "This is a test"; </FONT></P><P><FONT color=#0000ff>/* create a file */ 4 t5 x/ r1 j. g  h0 [4 w8 O
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
' X3 C( A5 C, @6 Q; o- f; ^S_IREAD | S_IWRITE); </FONT></P><P><FONT color=#0000ff>/* create a duplicate handle for standard / ?* u5 C$ v* I3 Y$ N9 L9 X
output */
' K' l& M$ R0 ~. K  S& |oldstdout = dup(STDOUT);
7 \/ Q  D+ G/ x: r1 m/* , F; N/ l8 I; i# `# T
redirect standard output to DUMMY.FIL ( K, S% G1 W( m$ z) `' c
by duplicating the file handle onto the
* j8 h& N& D+ W; T' ?file handle for standard output.
6 G" {- O* O, h/ A  |- t7 d1 |9 p*/ 6 t9 h0 Q0 P+ `/ s0 X; F
dup2(nul, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close the handle for DUMMY.FIL */
% u" {- \* q7 O' cclose(nul); </FONT></P><P><FONT color=#0000ff>/* will be redirected into DUMMY.FIL */
4 v' W0 {% ^6 v& G2 j9 v+ Vwrite(STDOUT, msg, strlen(msg)); </FONT></P><P><FONT color=#0000ff>/* restore original standard output
& G% t+ z% N9 w, zhandle */ , X8 l5 [! G" k: U* T. l" k- i
dup2(oldstdout, STDOUT); </FONT></P><P><FONT color=#0000ff>/* close duplicate handle for STDOUT */
' V) b/ [/ Q. |0 Hclose(oldstdout); </FONT></P><P><FONT color=#0000ff>return 0; ) I5 x9 Z. E4 G* X+ Z! l
} + n2 g- b- Z8 o; ?
</FONT></P>
回复

使用道具 举报

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

qq
收缩
  • 电话咨询

  • 04714969085
fastpost

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

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

蒙公网安备 15010502000194号

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

GMT+8, 2026-4-20 20:29 , Processed in 0.446035 second(s), 57 queries .

回顶部