- 在线时间
- 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>4 g7 b+ M% j3 b9 ~
功 能: 建立一个硬件错误处理程序 : U# |! g4 j% Z! {
用 法: void harderr(int (*fptr)());
* x3 \9 G& ?' i- E' O6 V4 s程序例: 2 b+ s, [+ I. q% B0 j" a3 v& Z; j/ r
<FONT color=#0000ff>/*This program will trap disk errors and prompt
9 }4 Y' e; Z2 J; T5 Pthe user for action. Try running it with no
1 Q! o1 e9 K+ u3 ^; Wdisk in drive A: to invoke its functions.*/ </FONT></P>
" }$ A: Z4 o: x; @; H, ^< ><FONT color=#0000ff>#include <STDIO.H>' B3 M. }8 o+ A% l3 y7 ^2 n3 v
#include <CONIO.H>
/ \/ {1 Y, H; x& Z. b#include <DOS.H>( }/ }* ?6 D/ Y, e% R
#define IGNORE 0
. C p/ U/ @$ B, i0 q6 v, q#define RETRY 1 : {9 p! e: g7 H/ U: T3 M
#define ABORT 2
G6 E) a' ^' z0 M& R- eint buf[500]; 3 t" l0 c, P3 |" q; W4 }! f
/*define the error messages for trapping disk problems*/
- h& F" V) `' x9 [0 ?4 g- mstatic char *err_msg[] = { : N7 f7 G6 E. j4 w- K/ _% y
"write protect", ; D0 o' n: n2 p
"unknown unit", " n. X( s2 l/ @: s, T! _
"drive not ready",
/ \' `* T4 u, R"unknown command", 9 B9 P# T- I* u5 o% }
"data error (CRC)", 9 E: U2 f" g+ T# ^8 u5 H
"bad request",
2 U) i& r% E! }"seek error",
3 U: a. K5 R+ |7 E; Q6 l"unknown media type",
. h% Z- G# R9 {2 C5 W' K"sector not found", 2 j* `# P+ \4 D' C8 {
"printer out of paper", 8 ]/ W: ?: b$ D1 E, ?# q" Z/ a7 `6 [1 j
"write fault", & k* O- A$ h0 d9 g" X
"read fault", 4 U4 F) l$ f4 u' ^. u' p
"general failure", 0 r5 V8 `9 T8 X4 ?
"reserved",
4 |, K w! { ?( T& \"reserved",
0 ~; @# q( ?, b/ \. e6 k"invalid disk change" 3 S/ I7 B5 P* A( g) F
}; </FONT></P>
5 { A* P+ ]4 x- R2 o8 n< ><FONT color=#0000ff>error_win(char *msg)
* ]( J9 l$ y# h( n; f' Y H{
7 o! C2 l; I1 L, ~' t) B; a4 |2 Vint retval; </FONT></P>7 p* w O; L+ P8 m+ N
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
6 n+ g- p! }" I c. `< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
/ J# `0 V! }& ?2 f' Twhile(1) ( F8 P! B$ W% w% {
{
# i" l' e- F) m' p! R/ L7 |( {retval= getch();
7 i- K/ }* V; z% `5 V1 u: |* Xif (retval == 'a' || retval == 'A')
" u& b" [/ D6 y4 x3 B! V; w4 ~{ 3 i5 r- N& @; Y5 [+ g8 S
retval = ABORT; ; \6 }2 N2 h k1 b9 P
break;
- n j- }2 k; Y}
* \( T6 s7 E K2 }. |2 }' \8 eif (retval == 'r' || retval == 'R')
( ~8 b: q7 r# m& X# R$ J. I& O! B{
" r. j. O+ g# F8 Z3 D; uretval = RETRY; ( E- P8 b& n7 b
break;
; Y! }" U4 F- M* S" L0 x, T5 r& m} / l: N, X3 C' C; F" ?% v5 Z8 {
if (retval == 'i' || retval == 'I') 9 D6 \3 F/ h: v$ c
{ 4 V, s' D/ ?! C8 R' O2 G
retval = IGNORE; K4 [! _0 ?2 P/ G" v7 G7 |
break; 7 M$ }& c' x5 W+ n
} 0 P4 p" |+ D: M! _1 ]4 l, h
} </FONT></P># a" ~5 \8 L) j) Y/ N8 c8 P" ~
< ><FONT color=#0000ff>return(retval);
# _; o1 {' W3 j, @} </FONT></P>
5 }" h( t; [" k3 Z8 _< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur 4 n( `- s: r7 H" C; ?& C) k
due to the non use of the parameters errval,
" N* E6 f/ ]* N Obp and si to the handler.*/ - c1 \5 ]- A$ h1 s- Z
#pragma warn -par </FONT></P>
) `8 J9 L) m6 s% D< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
' P, A( Y3 {; `7 j{ & W! g2 ~& E2 H7 ]% W1 v u9 x
static char msg[80];
7 ]9 l# J X) ^- s& ?: munsigned di;
& n; O" p+ n" q9 \7 U1 `int drive;
4 j, f) T$ A; @* S! e2 Gint errorno; % R# c& o# Y: d* E; V: M
di= _DI; . |6 T/ \' [3 j( V) I# ]' W/ c
/*if this is not a disk error then it was
4 H6 d- i/ g# Ranother device having trouble*/ </FONT></P>
, A2 J8 a: N( M$ }3 e! f" N< ><FONT color=#0000ff>if (ax < 0) + g+ |# e& @2 l
{ 5 A f$ S5 P4 @
/* report the error */
1 F/ L s. k% j6 k5 U0 ~error_win("Device error"); $ `. R3 F0 @+ B# n F
/* and return to the program directly requesting abort */
! r+ m9 U4 o: l% {, Vhardretn(ABORT); 5 T6 S/ M1 o3 U. k' I8 z
} . Y( V/ G$ t0 ]4 K: ]' ^) B
/* otherwise it was a disk error */ - k4 l, s- h4 `0 e8 I
drive = ax & 0x00FF; & o- a; S" H1 @' H" H0 X
errorno = di & 0x00FF;
3 {4 g8 M7 u2 h/* report which error it was */
5 v1 I: q# c( q$ O9 Zsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", ' Z4 W( L0 ]+ M- H& E) L" J4 y
err_msg[errorno], 'A' + drive); & S. L f& @5 w) l$ ?, l+ G! d
/*
0 i3 f" J1 M' M V# s Creturn to the program via dos interrupt 0x23 with abort, retry, $ P2 W* i- X4 c( u$ I5 H
or ignore as input by the user. A7 {4 u6 \" V7 {1 o
*/ ) [. I( h# A6 l, M) W8 b/ ^
hardresume(error_win(msg)); # `) ]5 `8 A: }7 ^% u, W; H. X
return ABORT; - ?$ Z7 ]- g$ U6 E& E( n: g/ j
} % h: h. \' A- ^* S% d; H8 C
#pragma warn +par </FONT></P>3 p" \: Q Q* d, F9 o7 j
< ><FONT color=#0000ff>int main(void)
\7 A: S Z N: b" ]! H{ 7 p7 r* q2 _2 H
/*
/ @6 r: `' N3 `3 U( \install our handler on the hardware problem interrupt 1 V! K- a: n) ~+ `
*/
0 S! R0 {2 d* Y* g) `harderr(handler);
+ Z }! C7 b- R2 F" W: m' I3 gclrscr();
8 c) s* M: T7 J4 y! q, Pprintf("Make sure there is no disk in drive A:\n");
: Y4 C1 y/ m# f( E. aprintf(" ress any key ....\n");
0 X4 m- r7 ~' ~5 E. {8 u% G/ Xgetch();
[) A. o* ]+ l& R! ?printf("Trying to access drive A:\n"); 2 @9 u0 V! t- t: i$ M9 j
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
# p" i% U9 S7 V' {' E2 {return 0;
- _+ Y& V' o. ]1 Y \1 G% ^/ y7 V} 8 `; D# G( l" \ V' |% X5 w
</FONT>
& L1 W7 S0 _7 ]- R! `</P>
* R0 f% _0 `; r6 P< ><FONT color=#ff0000>函数名: hardresume </FONT>
+ m% ^6 N) L) j) m功 能: 硬件错误处理函数
7 L- ?. i6 m; T0 W1 r5 E用 法: void hardresume(int rescode); & `2 b0 Q$ _) D) x9 M
程序例:
2 h" ?+ h- H% N# o/ z</P>. P3 l! n4 b" m3 t: {8 G, e
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
8 g" U! I$ j" ^! \/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>+ r9 Q8 P$ A5 S
< ><FONT color=#0000ff>#include <STDIO.H>
+ G/ u6 `$ U" V, n# x#include <CONIO.H>
: F q' U# R2 _+ s#include <DOS.H></FONT></P>5 a b" x* ] ?$ a. L
< ><FONT color=#0000ff>#define IGNORE 0 : E# v8 M$ F$ b4 }. p. \
#define RETRY 1
8 b7 ~3 R- \3 g6 y( X#define ABORT 2 </FONT></P>
9 d3 |! N, t1 Z9 d+ g- g& Z< ><FONT color=#0000ff>int buf[500]; </FONT></P>( y' k. u/ U: ^* {4 {
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */
2 }* D5 Y. W- S$ M* Q* ystatic char *err_msg[] = { 0 o) [' _( q! E
"write protect",
) V w' O0 p; n0 ~"unknown unit", , p6 a, v; ~' s. q! R4 E
"drive not ready", W& F4 G* O) L/ E& U
"unknown command", 8 a, m* ~1 d0 {* f( j
"data error (CRC)", 2 G, u8 F/ Z# G: Y" b: I* I! t
"bad request",
6 u5 W- I9 R4 y"seek error", 9 J8 J" J; M4 Y7 w* B8 I
"unknown media type",
5 z$ Y p7 v( u5 @* E7 A O"sector not found", 4 J0 {1 F ]6 U0 L0 V9 w, T6 }
"printer out of paper", # E& H: r- n) S2 o' k8 G) C! O4 n) q
"write fault", $ h) s* {; M; D7 u+ z0 B
"read fault",
* e# I: E$ Z u7 w* d8 j"general failure",
; ^! T8 R q% v* r7 L5 g, ]"reserved", ( v& M- G. K1 d6 q
"reserved", p+ G! |: [" M5 z( w% S' U ^1 N
"invalid disk change" 6 L9 u+ E+ y6 q
}; </FONT></P>" j7 O2 ]& N" y0 j. w
< ><FONT color=#0000ff>error_win(char *msg)
* |2 z4 X" r# [{
" T" B! G) P0 G$ wint retval; </FONT></P>, j: h' i3 X7 ], g5 |
< ><FONT color=#0000ff>cputs(msg); </FONT></P>: o- v" v( D) m8 h
< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ 6 M% G# g& d( z" V* O3 h
while(1) 7 U8 q& ^+ X5 Q0 r' x7 E! d( C# q
{ 3 U9 h' V' o" s) |5 S1 l8 b( l
retval= getch(); 6 G! W+ T4 n0 y
if (retval == 'a' || retval == 'A') 9 ^. P& J1 ~ R4 w( ^4 \
{ . J# J/ K6 G+ H3 [
retval = ABORT;
( M! e# K( y rbreak; & N* y- B, l' z
}
; i G4 M* Y9 J P: iif (retval == 'r' || retval == 'R') 4 y u) Y: e2 ~( H- A
{
8 K& T! S& }" @! F) \retval = RETRY; 4 z+ s2 N+ z+ }- E8 x
break;
% V% G3 b: I6 z5 ?1 n6 k6 b} $ U% T4 v9 s. F: I) P
if (retval == 'i' || retval == 'I')
- B9 D/ z `, N" [, p+ H1 A$ L{
# m" [* E2 \, e# d3 O( }' [( hretval = IGNORE; : K% v* |3 [/ \- o/ }
break;
; @" S& ?6 i2 O: Z- C}
/ |, F% B7 O) k} </FONT></P>6 j4 U9 v# q% e/ o! |) } g# T
< ><FONT color=#0000ff>return(retval);
! v+ X3 V- t0 A+ n- f: X} </FONT></P>, o; t- i' K; o% e
< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
0 k7 t& D: k2 r4 e0 x/ Q/* of the parameters errval, bp and si to the handler. */
/ `/ e) }' P; g! e( H1 i#pragma warn -par </FONT></P>: d, r+ L) @9 A# G
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
" w; y, |6 u" M b( E0 l, D4 u4 f{ + Q" u; p! O- C w, M
static char msg[80]; 5 n! F0 j) Q/ n+ r4 S$ K l( h
unsigned di;
' D7 i) b* j8 _" aint drive; / N& k: ?9 u! T/ K
int errorno; </FONT></P>
# I; J( j3 \/ D" Z* u. v* z$ }< ><FONT color=#0000ff>di= _DI;
- x+ L3 ^2 {) d) `* ~/* if this is not a disk error then it was another device having trouble */ </FONT></P>. W# ^ D/ i2 o
< ><FONT color=#0000ff>if (ax < 0)
& s/ H! @& |1 h; ?9 K{
* b; u# B, h9 o: P, c8 V% [0 Y/* report the error */ 5 V7 N) @0 ]5 [5 C, s
error_win("Device error"); 5 H% u7 V! o5 Y; {7 a' o
/* and return to the program directly
* X3 y3 {; l5 Q: C I: p+ f4 Brequesting abort */
: M9 T) j. u8 `* p5 j5 z2 Dhardretn(ABORT); 2 r: g3 p: w o: v. O4 f
}
0 p+ a- i2 v$ m% Z7 S/* otherwise it was a disk error */
6 j V9 e0 v* j6 o: G3 D8 idrive = ax & 0x00FF;
6 d% [1 {" p- k0 T/ H% V3 terrorno = di & 0x00FF; - b; S6 a6 E& ~; I1 w: U
/* report which error it was */
* L$ z1 k9 K$ q2 _" z6 ^) usprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", ; i3 X7 q0 C3 T: c( \, w8 r8 ^
err_msg[errorno], 'A' + drive); 3 Q7 ~! T0 t8 t7 v( X9 F/ I. h
/* return to the program via dos interrupt 0x23 with abort, retry */ 2 T0 c( F6 e- b* v5 Y, n' p
/* or ignore as input by the user. */
, \3 m& w" _+ X9 H4 xhardresume(error_win(msg)); 0 L, V5 |: W; z" O; g
return ABORT;
+ z& z& J4 Z J) ~ f# U8 E}
" ^) @' r% f9 z& u8 d. b" k7 A#pragma warn +par </FONT></P>
% a' _. _: ~; n: O" ?4 V< ><FONT color=#0000ff>int main(void) ! @( e5 G, x% Z) ?/ a4 b3 O
{
# Y3 X; m+ [2 E7 @0 W/ X/* install our handler on the hardware problem interrupt */
" N- U- J+ b+ f( C7 tharderr(handler);
7 M6 M$ J" H" ^8 ^) tclrscr();
! V4 H$ @( ?/ Y$ T2 x8 |4 ?: r; bprintf("Make sure there is no disk in drive A:\n");
7 a& X2 @1 C5 }* c& L) mprintf(" ress any key ....\n");
5 H9 Z' m, n* K2 q- lgetch(); ) z: u& |5 E( H+ V. `0 m8 o& @
printf("Trying to access drive A:\n"); " X# T# h& p9 D. o, e
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); 7 h X4 Q( v* i5 m& m+ g
return 0;
2 P$ @7 ~0 u; Q% q6 }9 x}
" j9 i9 |; m, o/ Q7 c6 D</FONT>2 p O4 I' z, K( V0 A
</P>
$ ~& y0 p5 C# F, t< ><FONT color=#ff0000>函数名: highvideo </FONT>2 Z3 W& D- _- d* z9 V8 o
功 能: 选择高亮度文本字符 - T7 f3 e4 ^) s" t- p( s
用 法: void highvideo(void); 8 _; K" ?2 p$ a. P& j* w1 P9 w
程序例: </P>
1 t L' H. C& ]( i. @. E2 a< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>+ f" W% m4 F# h% w
< ><FONT color=#0000ff>int main(void)
/ B' n1 T- F) A9 y" Q{
3 d, ^# Q( m' v- jclrscr(); </FONT></P>
2 r9 h7 B$ c: _/ t, f4 m<P><FONT color=#0000ff>lowvideo();
2 Z, N' g- J! zcprintf("Low Intensity text\r\n");
4 n3 c0 t4 h1 whighvideo();
. B( h$ g, Q: U6 |! Y" Ngotoxy(1,2); 1 z; F2 J0 p& i9 ?
cprintf("High Intensity Text\r\n"); </FONT></P>
9 n; m8 d9 `( p5 i; p<P><FONT color=#0000ff>return 0;
9 p5 G- o! v s} , X& \+ z& L" I" G, C8 t; w
</FONT>
! H: |' k- I2 s9 B% ] y) H</P>/ u0 P* E, E( j+ D1 O/ x: ? `
<P><FONT color=#ff0000>函数名: hypot </FONT>
2 N$ U! T1 t) n8 `功 能: 计算直角三角形的斜边长
; y. F. l' c" j2 A用 法: double hypot(double x, double y);
& y% m. ]% ]' E+ R" f- @! h/ `4 Z/ k程序例: </P>; b. Y6 L$ l' a
<P><FONT color=#0000ff>#include <STDIO.H>
2 Z, I& P. g" f4 K#include <MATH.H></FONT></P>
8 X y2 ?0 M, Q6 _: z- n<P><FONT color=#0000ff>int main(void) 3 b% [3 {8 y- A. x0 \2 O
{
" h( j$ c P. i, @- R- Idouble result; ' n- X- F4 N7 z8 d
double x = 3.0; ' N, k/ i) W; G3 M0 _$ H
double y = 4.0; </FONT></P>7 x# |; r3 B8 f: ` h
<P><FONT color=#0000ff>result = hypot(x, y); + M& R3 l; M. B
printf("The hypotenuse is: %lf\n", result); </FONT></P>( m+ }8 t3 [5 O8 q
<P><FONT color=#0000ff>return 0; # }. \5 m/ x7 E9 T! W
} </FONT>; }. N3 X8 J5 |& i* i# z
</P> |
zan
|