- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< ><FONT color=#ff0000>函数名: harderr </FONT>" ]$ s5 `, r% m# H# D/ n. u
功 能: 建立一个硬件错误处理程序 q: c! j9 u6 L* r
用 法: void harderr(int (*fptr)());
+ b" d u( Z9 X: v1 ~程序例: 6 y7 G+ f- C% B6 ~$ O3 I
<FONT color=#0000ff>/*This program will trap disk errors and prompt 2 ]3 \3 t x& O
the user for action. Try running it with no
4 N3 T* h, s4 c3 Zdisk in drive A: to invoke its functions.*/ </FONT></P>
& h \+ x8 x' c% n2 U< ><FONT color=#0000ff>#include <STDIO.H>
B+ c; H% a! U O- b/ z#include <CONIO.H>
H4 t3 Y3 P7 ~) w' O( g#include <DOS.H>
+ O' B& J0 S& V4 |1 ^3 K( S0 ]' C#define IGNORE 0 i) ~; n! F l. f& Y8 d; Z
#define RETRY 1
3 v7 @- f2 ?1 n# L' q* F#define ABORT 2
8 s) o3 j ?/ l4 N% l% I4 u; Rint buf[500];
9 F& D; P! ]% z3 U, R/*define the error messages for trapping disk problems*/
- m& v& O' @$ Q& Lstatic char *err_msg[] = {
4 h1 l4 E1 j. q$ k6 t8 b1 p"write protect", 5 h6 W# \5 w' q H& b; n
"unknown unit",
9 q% q$ b( ` D5 H"drive not ready",
; i0 v9 f# Z" n2 M( M: T"unknown command",
* d: {& W# D) ^"data error (CRC)", ; B8 c5 I6 b- u5 Q5 q
"bad request", 2 H7 f1 K2 w; L
"seek error",
( P5 T8 p* m/ p T5 V8 e2 V"unknown media type",
) t9 ?7 q* B8 A2 C"sector not found",
* t$ z: D/ S% v4 U) S. p( A& @"printer out of paper",
9 r8 k. |# D1 M: F* I"write fault", 4 x- X( D# e5 m& F/ A' t
"read fault", $ M0 s: W& ^% E' u, q4 }# O) {
"general failure", * B9 |* [. A( \0 Z+ Z( M% ?# Y; l; I
"reserved", ; g/ c* l; G5 d+ R
"reserved", 3 m- }9 ?& M! H. H/ W3 y
"invalid disk change" 4 e* ?* p% @, r; Z
}; </FONT></P>
8 x& U- q$ x- `# a7 X6 K6 B! {0 q< ><FONT color=#0000ff>error_win(char *msg)
+ l3 S- a. f# H# D" q6 K1 x* _{
% Z1 U% N0 I4 _9 s" pint retval; </FONT></P>- D# {4 }; O: L" ^+ _6 o
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
- B" h1 R" O) L. {- P< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
3 M; \" X9 o3 f9 s; [! mwhile(1)
9 p) F) b+ t$ W# U$ K; Y{
0 x: I6 ~1 U* G kretval= getch(); % C. T; x0 z7 S8 Z
if (retval == 'a' || retval == 'A')
H" A8 @- P+ W1 H7 R7 \4 J5 K5 y{ : [- R4 @( _% D) y1 X
retval = ABORT;
: `# M, F: b3 ]4 g: [break;
3 l H; i. Z1 q& F, |/ L}
8 d+ W/ N, Y0 ^& ?; gif (retval == 'r' || retval == 'R')
$ @2 U" a( q4 c# @{
1 P8 D2 J2 E- ?( ]3 q0 ?9 n( Bretval = RETRY; 2 z7 e2 f/ \0 [* ], W c5 a) d4 j% R
break;
+ Y( k) `+ b$ R+ z7 D# Q' Z} ! s+ V/ n' c. N/ `' q
if (retval == 'i' || retval == 'I')
# [) \ F# E, |/ _% w w{ 1 C) j; J2 ]. K3 q, M4 u
retval = IGNORE; : t5 f1 W7 `+ q c
break; ' N$ Z( v+ r: m: a3 h L
}
; u$ e$ w& d% D0 h! p+ }} </FONT></P>
/ }( e/ Y0 E) L# ` N< ><FONT color=#0000ff>return(retval);
1 u3 n" y9 Y0 |4 G} </FONT></P>% d* a& E* Y/ P
< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur 1 F, \8 Z7 N( N8 g3 v
due to the non use of the parameters errval, * m7 q x* y u" h3 }
bp and si to the handler.*/
& P: i8 x4 o. z3 ~' M& h: [#pragma warn -par </FONT></P>7 ~0 W: M3 ]+ y1 I
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
3 H! F; E; X" r: n{
9 P* M5 Q2 K3 wstatic char msg[80]; 3 B1 k1 N( q+ d
unsigned di; 3 @$ ]1 B0 ~1 m P
int drive;
& A3 T. x. C; ]. ]3 iint errorno;
2 t9 ~' k8 c+ }8 jdi= _DI;
- V1 m# R2 u/ A: A! u. y1 d/*if this is not a disk error then it was 1 L" |$ i6 A+ \' U: R
another device having trouble*/ </FONT></P>
9 n. z$ A& S7 h y& v% K- H< ><FONT color=#0000ff>if (ax < 0) F G# I( D! Y
{ % D& Z! u+ j* Q; @
/* report the error */ * @3 ~" A; Q: z8 F
error_win("Device error");
2 i' f2 g( ~+ C1 u% t/* and return to the program directly requesting abort */ U- {, @- b' q+ H2 X$ s' ~
hardretn(ABORT);
. Z/ a6 t* a( I; p q- f- C# P} 0 e0 Y1 ^& f/ X8 I
/* otherwise it was a disk error */
( M% d$ d' c9 j# ?6 Idrive = ax & 0x00FF;
) d, M r ~6 ^6 {/ r3 {errorno = di & 0x00FF; / R! q6 A8 M N! |4 c" x/ r# }
/* report which error it was */
0 w) T+ [: c/ ^) B. Z6 esprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
5 S; c& l3 Y: x Xerr_msg[errorno], 'A' + drive); ( S5 V# p4 ~/ c3 q, g
/*
' ?4 I7 z! u1 i' `return to the program via dos interrupt 0x23 with abort, retry,
& h+ \3 \/ a1 g; \or ignore as input by the user.
l& F; \! q+ D, A4 x+ E*/ 6 i% B- _ {3 p$ E6 t
hardresume(error_win(msg)); . m# g( G/ Y5 X" q/ `/ Z
return ABORT;
% u, ]9 b5 U) `3 t}
- `# p4 f/ J+ T1 E! `#pragma warn +par </FONT></P>
7 P: b) Y9 F1 I6 c3 S< ><FONT color=#0000ff>int main(void)
5 \% h6 @! k% S7 N{ 6 j9 |6 k0 n+ s& s8 Y9 e) u3 I
/*
: g f* q. [) H# k! J- X* q4 uinstall our handler on the hardware problem interrupt
! R; w9 G( _1 ]: V7 [% z*/
( W# c8 T% \% }# [harderr(handler);
: _ {4 |* Y9 w2 c& hclrscr();
3 ^) ^" z+ s1 `$ ]4 X1 Nprintf("Make sure there is no disk in drive A:\n");
% }: ?3 x7 l6 O) u0 h7 J. U* pprintf(" ress any key ....\n"); 5 \" o& G8 ]( R0 P& w9 x1 {7 z, @
getch();
0 s: i2 d- E! q2 G Y3 |printf("Trying to access drive A:\n"); 3 S: V# h$ c& ]
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
) L6 p* }9 }8 i2 o1 ]( o& _& areturn 0; 0 I8 E* ^5 h; f( ^! k- A" U- o4 A f
}
4 G+ Y$ Y' M" j* j</FONT>
8 i3 l5 X: ~5 g8 r% X& W2 c</P>
: t' s6 S( P( |' q$ a: ]% h( }6 |< ><FONT color=#ff0000>函数名: hardresume </FONT>: T! Y9 x9 g! B8 @* B4 Z) s7 i
功 能: 硬件错误处理函数
/ K- o" `" e6 a9 t+ T; c用 法: void hardresume(int rescode);
6 v+ ^; x- U9 J' u5 M程序例:
! L/ X/ W/ f6 K5 b! p. W/ `( g</P>: W, I; z$ z; Z5 [
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
" d2 b3 |) Z" C* S) h) D+ i/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>8 {( p9 D6 d+ o# n
< ><FONT color=#0000ff>#include <STDIO.H>
9 H8 U: p0 D) a5 F#include <CONIO.H>
' ~! t/ \8 v4 b. j7 ^9 M" ]#include <DOS.H></FONT></P>
. @1 U. h9 {; m$ b< ><FONT color=#0000ff>#define IGNORE 0
* z( v4 ?4 R5 Y3 m#define RETRY 1 1 C# r7 G+ W) s, h
#define ABORT 2 </FONT></P>% _. {5 S9 }, X: u( ]3 B% @
< ><FONT color=#0000ff>int buf[500]; </FONT></P>3 i9 h# K3 |& q* e- T2 H. ]2 }4 E, }
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */
4 K- {6 P) |( I5 j+ e, `: Gstatic char *err_msg[] = {
6 H Y: s/ ?# n+ m+ P+ k: t"write protect",
5 ?3 B, c% F1 S2 y"unknown unit",
3 A) X6 Z) V# n, C; l. n"drive not ready", 2 [( M% e1 [( p) @
"unknown command", / J" P* d7 E: D7 r5 G% [9 }" W
"data error (CRC)",
: E4 e/ W0 } P) u) Z; Q"bad request",
2 Q2 m% t! v/ y. V0 o9 d! B9 h+ M"seek error", ; I2 i; k l& f' `- P
"unknown media type", 4 J6 X/ \, W$ M- @
"sector not found", ; N$ r3 T4 Q, i3 j7 r. Y; @1 n
"printer out of paper", 6 ~+ e* z5 a a
"write fault", % e* d) ]+ I) b& t9 K- ?
"read fault",
) J+ e# {) j% k4 B, W5 f7 @" h"general failure", 5 I1 a" U9 X( P4 P- Z+ n: ~4 h
"reserved", / r1 y l9 y3 r7 l; \: d
"reserved",
" _. z/ h1 b1 }' O"invalid disk change" 6 v) T! |% ]8 ]. o* @. s
}; </FONT></P>
( l0 j' S# | \/ ^4 f< ><FONT color=#0000ff>error_win(char *msg) 3 z; i/ g" g& \5 V7 Q% v! K5 j
{ ' l0 y4 S3 O& p' C, P
int retval; </FONT></P>$ M; X7 B1 V% n) `: r* [* @
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
, Y8 D) ~" ~9 A2 w7 h< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ , q, o9 v( D5 O4 P" X7 p0 P) t9 \
while(1) 0 R& r0 o1 ]" E: K- X' J! @" ]
{
# F' c* e( X! Y" b2 ~5 yretval= getch();
( g# ^( e% P) x) a% J! }/ i' A9 I% {if (retval == 'a' || retval == 'A') 8 q; {: s5 `) ~* J, i
{ 4 k J" I' W, ^' h1 a
retval = ABORT;
0 g! ^8 Z8 c* b7 dbreak; ' i6 X8 d' W, T- f2 u) w. Y! O7 E* F
} " l$ I" v7 Y+ z' @+ ^
if (retval == 'r' || retval == 'R')
. F: L% |$ {3 Z5 C: D% ^. |+ e{ - M2 I# u7 t4 ?& B( E; }* Q3 c
retval = RETRY; 1 D4 L* m7 \ s! @) Y3 `3 A* K
break; M4 Y6 r& G o% c
} ! l3 c; u, G( D4 E* r' J$ j& g
if (retval == 'i' || retval == 'I')
3 c8 g! C: P* N# O2 o$ H{ 8 G5 ^% y& R a' s4 X* K
retval = IGNORE;
, E! x$ @' W9 m G' ^+ `break;
7 _& V4 p$ k2 B) g} z- L! V* s+ o/ G4 b' A q6 M
} </FONT></P>
# X6 h4 i. e- J1 f: N. N" X4 ~7 @< ><FONT color=#0000ff>return(retval); 7 a% Y' E( L4 E7 A0 h8 o
} </FONT></P>! @- b4 M$ n- @1 C3 C/ l9 l- ]% ?
< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
' Y, j0 S1 e3 J/* of the parameters errval, bp and si to the handler. */
7 Z' ?1 o/ p; n6 d- \5 a1 }#pragma warn -par </FONT></P>: g8 s. I- x8 m! O
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
4 Z% T9 N* H! p{ 6 |, f# c3 i( E1 L4 _: l8 Y0 r4 g# Z
static char msg[80]; * \* K! x( Z$ r1 r) y, ^6 L/ M
unsigned di;
# d, L7 ^1 u$ g2 Xint drive; : K" h* a9 n$ v' G/ b2 Q4 u
int errorno; </FONT></P>
. o6 e1 N3 K3 X- O4 s/ i< ><FONT color=#0000ff>di= _DI;
# F7 I: ]+ _) i9 k( x/* if this is not a disk error then it was another device having trouble */ </FONT></P>
% W% Q v2 \" d& N, m" D3 ~3 A$ T) W< ><FONT color=#0000ff>if (ax < 0) 7 f3 L# ?/ ]& `( q& u
{
4 D# G% j- I: G/ ]4 _1 v/* report the error */
' {9 Q: |+ f7 ]; B5 D5 Merror_win("Device error"); ) q$ k7 c) [- {; G" `* P( s
/* and return to the program directly 3 h" b" N, c) p. S* ~
requesting abort */
: ~7 r5 d2 u# G" X3 ihardretn(ABORT); / m' ]* `' `! G7 x1 {
} % ]7 k- N! P: z1 ^7 v, c2 d2 s8 H
/* otherwise it was a disk error */ 9 w. N! }1 y- t1 p7 b
drive = ax & 0x00FF;
% Q8 A& u1 \$ a; r3 {errorno = di & 0x00FF; - P5 p. y3 P3 P+ `
/* report which error it was */
1 E( R0 ` n( J C. ^& Fsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
/ U# v. m$ L! h6 @. o. serr_msg[errorno], 'A' + drive); , e0 U, S* F% z- @8 o& D
/* return to the program via dos interrupt 0x23 with abort, retry */ 9 I( w( L8 S( l: e' h
/* or ignore as input by the user. */
; G" |( r% K+ d. U& n) c1 Bhardresume(error_win(msg)); : b, W+ Z5 K# t. ~6 _2 [( X
return ABORT; 2 t+ c. M. c1 [+ q
} 7 R; |0 ~, \$ Y! C4 u h
#pragma warn +par </FONT></P>8 E( L; Q/ F: U- M& e3 B$ \" J
< ><FONT color=#0000ff>int main(void)
; H! N/ y: _ k9 g. ~{ ! \3 H3 Y' T* E7 l
/* install our handler on the hardware problem interrupt */
3 O% C" v& X4 |harderr(handler);
j7 I* w8 y7 p# q0 W+ p, Hclrscr(); 8 k5 ~/ a* U C$ j& U# }: F$ V
printf("Make sure there is no disk in drive A:\n");
1 j. g# N& @- c' Yprintf(" ress any key ....\n");
7 G( G O* G" \5 q; @getch(); ( n, [8 ^* [0 v( g* O
printf("Trying to access drive A:\n"); * ~9 z' U; K$ V: e
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); , z0 F/ R8 o4 s' _& X
return 0; * F2 ~* i; P2 G) L
}
7 N, n, P- O! C</FONT>7 j: r* g6 U a# D! J$ x
</P>
' K4 g& a5 U/ @! D( ~< ><FONT color=#ff0000>函数名: highvideo </FONT>% k! V8 k6 ^) Q9 T1 ^! c) Y
功 能: 选择高亮度文本字符 5 t1 q) t: t' z6 T3 r, `4 b0 I
用 法: void highvideo(void); + }$ h! T' q; P+ f0 o$ i7 E
程序例: </P>4 c) \% s, G' O- F# o7 k# y
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
' `9 a5 l5 Y+ b+ _6 l' |& H< ><FONT color=#0000ff>int main(void) , o0 Q n5 y: D8 j7 U; E* y
{
( H9 L% m$ o, o9 w# Oclrscr(); </FONT></P>( Z- U& N1 L* F) D6 M( Y
<P><FONT color=#0000ff>lowvideo();
5 J* ?" L7 N: W/ Bcprintf("Low Intensity text\r\n"); ' ^. d Y! F) g3 o' ^
highvideo(); u8 z) c. g- [" D' ~7 w$ ?
gotoxy(1,2);
) w! r- u0 a5 `7 z" wcprintf("High Intensity Text\r\n"); </FONT></P>+ d3 D6 ?( _/ }2 A
<P><FONT color=#0000ff>return 0; : h* J* E' A0 f* _, V' `5 {0 F2 @
}
; g# f# X& }/ q" z" D- t/ G</FONT>
6 W; O, Q( l" ?7 d/ }</P>6 c7 R2 L' J- ^/ _0 i) s
<P><FONT color=#ff0000>函数名: hypot </FONT>
- u' J, S" j4 @9 J功 能: 计算直角三角形的斜边长 / z2 _1 S: _: @" {# Y
用 法: double hypot(double x, double y); 0 c R8 D) H4 U7 r/ g
程序例: </P>8 h8 h6 _- T8 `
<P><FONT color=#0000ff>#include <STDIO.H> _! S( `1 k, y
#include <MATH.H></FONT></P>3 n6 L/ C1 r0 \6 H& |0 i
<P><FONT color=#0000ff>int main(void) 6 W0 m5 F- i5 [$ F. y& Q
{ / }! v9 U1 X$ {0 k/ q/ b$ s7 {
double result;
* `4 c% m6 l, v: J) adouble x = 3.0; ! B% k) M( ]0 U* C1 _$ [8 K' u
double y = 4.0; </FONT></P>- ]/ B; b! n& H
<P><FONT color=#0000ff>result = hypot(x, y);
$ R- l4 e+ S, Yprintf("The hypotenuse is: %lf\n", result); </FONT></P>( u" o7 ~8 {0 V
<P><FONT color=#0000ff>return 0;
! m6 T, E* O3 y2 t6 k( }! i# |} </FONT>
8 b) y, g0 i) T' g1 H! p1 n</P> |
zan
|