- 在线时间
- 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>
9 E2 L3 k& M X功 能: 建立一个硬件错误处理程序 ' Q) G6 x2 R+ y1 Y
用 法: void harderr(int (*fptr)());
4 e; t0 m* J+ V6 V程序例:
" n: G7 z+ n) B+ S: ?<FONT color=#0000ff>/*This program will trap disk errors and prompt
7 K' J6 f. f* n7 X2 cthe user for action. Try running it with no 9 o; C1 m8 ^; s1 S
disk in drive A: to invoke its functions.*/ </FONT></P>: \# b& M }+ c# x; z
< ><FONT color=#0000ff>#include <STDIO.H>
% B+ a) v- I" G8 l( c9 B L#include <CONIO.H>
6 t$ w" K+ W- \2 W' y5 p; ?#include <DOS.H>( I( i+ H2 d2 j5 b9 v
#define IGNORE 0
S \/ ^! u) Y* p% O/ K* s#define RETRY 1
, U8 ~& o6 q8 C3 k* `3 R3 ?5 ~#define ABORT 2
+ e+ l. M" Q+ B" ~+ A, B: d0 rint buf[500]; 9 P" @ R5 W* |& c% l6 i+ G
/*define the error messages for trapping disk problems*/
6 f& g- G: b: R s3 q1 Z, c; Kstatic char *err_msg[] = {
; ?! q( D [" t. Y1 @& C"write protect", / e! X3 q3 i+ K
"unknown unit", 6 q ~; G8 l; l! o: |; k! q
"drive not ready",
0 X% Z [7 z$ r0 Z"unknown command", & P1 e7 y# m( Y1 j+ w( k5 o8 y
"data error (CRC)",
% J, f/ q7 i9 {7 [ k5 n% m' A8 b"bad request",
: U5 U$ J* O4 P1 u. m' q" y. Q"seek error", 0 V) i( O* d+ _( p8 o
"unknown media type", ' P0 Z0 S* f+ g- c& Z ~' V4 I5 @
"sector not found",
( ~8 @- r9 v$ p/ s"printer out of paper",
* M& ?* P7 x. P$ {"write fault", 0 a$ W; C. E/ N$ I! [8 V2 p4 g8 E
"read fault",
9 w; z+ r$ r6 J" s% G+ R"general failure", ' c X: O7 w' M" d1 k7 h2 ~
"reserved",
% ?7 ]* a' e5 n& L1 e"reserved",
- _# H" K1 x. _8 T. {! g"invalid disk change"
1 y" _9 l' C" m( O+ z7 I/ ~}; </FONT></P>, n4 z. Z; q3 M O5 ]5 d
< ><FONT color=#0000ff>error_win(char *msg) 0 z: x# T2 n9 N
{
& {7 |3 }& Z4 E6 w; tint retval; </FONT></P>
& [0 a; R4 s9 P' \, q$ u< ><FONT color=#0000ff>cputs(msg); </FONT></P>* v; E+ X/ S! g' S4 _* J
< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ + R+ \0 m5 @: p1 s6 M4 d
while(1) " c! p9 g. c E0 C# Z# L+ j
{ 4 s8 ]# [) S2 w. ^6 O# z# B
retval= getch(); $ Z6 `# B' k: ^4 t7 ~% |' z
if (retval == 'a' || retval == 'A')
* t! R; _. {) r9 @5 P4 x{ 5 `1 j( T. F& b
retval = ABORT;
' ]3 v, u) s( W& ]break; 7 C3 M( R8 B5 G/ q4 D) v5 H8 D
}
# n' o/ E2 t9 C. @if (retval == 'r' || retval == 'R') 1 H$ V5 ^3 N( t' R
{
; @7 q5 d/ I( D. h; [retval = RETRY; * I! w- b0 R/ p2 I0 ^: B$ i: y. y
break; 9 }0 O. ]; Y \ ?0 _, T1 l \
} , S, i, {" M# L
if (retval == 'i' || retval == 'I') * [: u) z* B, D0 \3 t) K; v
{
/ j d' W! D; I9 lretval = IGNORE; 8 m8 ~/ K3 q0 K% g# ?+ ?
break;
, J- \5 i; `6 u, c& i} / ~% @5 p4 c( f' u8 e3 q
} </FONT></P>
0 f1 }& P* O$ X: [< ><FONT color=#0000ff>return(retval); 1 u2 i1 [2 T$ X& T9 Q$ e
} </FONT></P>
" g9 I, f4 h# H2 p9 Y< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
8 o2 O% q* E0 Udue to the non use of the parameters errval, ! Z6 X7 t- c- I9 l% u1 O4 S9 I
bp and si to the handler.*/ $ S+ V$ j2 ~$ S9 O
#pragma warn -par </FONT></P>
9 K( H' J7 s9 m# a< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
G, f: H) L5 H6 C1 D; d5 q{
# D8 U7 Y7 v) s# Jstatic char msg[80]; $ l) C6 X" p% S. b& ?' N$ f- e
unsigned di;
, l+ V( Q) k4 O/ l4 D* B) e5 ]int drive; % |3 _: H; Y4 n7 {% h
int errorno; # @* D0 J" d5 z- T. |
di= _DI;
7 c( b2 \2 x6 l/*if this is not a disk error then it was ) L% n A: n, B& ~. A9 {: i
another device having trouble*/ </FONT></P>
7 Q5 S' g0 t4 _< ><FONT color=#0000ff>if (ax < 0)
, \& R' F1 w. D9 ?{
% ~5 j7 @5 P6 a y6 O/* report the error */ , S) q( `* S- o4 M6 }# G4 g' P$ U
error_win("Device error"); [0 S( Z! d6 p* V
/* and return to the program directly requesting abort */ + Y9 x- @/ v& g& O. ~9 q
hardretn(ABORT); 8 Z1 Q1 ~( F0 j8 b
} 2 ^1 _* F9 m8 t+ D7 Z
/* otherwise it was a disk error */
# Q2 G3 k9 A7 q9 W% L# Bdrive = ax & 0x00FF; + o) {) T, H/ B3 T& p4 ^6 S% N
errorno = di & 0x00FF; 7 _$ T9 _$ U3 p" k/ E5 \! a
/* report which error it was */ / E& _ G& L) y) {, X
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
" ^$ I. W) {9 Z# o: @$ u* @, A' E( Perr_msg[errorno], 'A' + drive);
$ U n" F2 p3 J8 _2 C/* * A& Q2 q/ Y, A( |
return to the program via dos interrupt 0x23 with abort, retry, B: v* r8 d: ^4 Z% |6 B! \
or ignore as input by the user.
: | y& R! E8 k$ Y! D3 M*/ 3 ]# U' x1 ~4 `( D, w6 q6 r7 P/ x
hardresume(error_win(msg)); # k( j& {! E k S8 Z, D; }/ j
return ABORT;
( @+ D( d8 e Y* {. h6 ]} 3 O+ l9 O! h1 ?5 W
#pragma warn +par </FONT></P># I& I, C" ~. d9 T' C. ?4 P
< ><FONT color=#0000ff>int main(void)
" a% v, d& G% {/ w2 d2 ]{
! a: q* ]& M9 [0 L% p) r$ x/*
9 P$ S1 g0 l9 g& i2 B8 linstall our handler on the hardware problem interrupt 9 k. U1 P1 s4 O7 f
*/ $ `5 N" |* r) B) T, O. c
harderr(handler); j% v Q7 m3 t/ W
clrscr();
+ P$ H1 n0 O; c; K& ~* B# }. @printf("Make sure there is no disk in drive A:\n"); - A" y& \0 Q5 H7 R
printf(" ress any key ....\n"); 8 T6 _ x1 R7 ?- z! a
getch(); " q; v4 Y5 Z2 R K5 ^" l6 c& B) {! ]
printf("Trying to access drive A:\n");
( d& h! k: f- |1 I6 n; X- Bprintf("fopen returned %p\n",fopen("A:temp.dat", "w"));
% p7 c0 j! V6 X, m, f2 \+ P( r- Vreturn 0; " A" y7 O: T0 k; Z) d# z
} : m, R5 k6 \# o. J
</FONT>
! F5 t4 O; {7 }$ N t</P>
0 ?# @2 m4 v) b6 I$ V< ><FONT color=#ff0000>函数名: hardresume </FONT>
l4 r8 u* Q( j8 H K2 o \功 能: 硬件错误处理函数 2 D+ _6 I. B! J9 \
用 法: void hardresume(int rescode); 5 l+ ~) T7 e1 n+ C
程序例: 1 ?" V7 g2 E1 x5 f1 V5 l6 y- D: z& J
</P>0 V/ O; o$ |3 E' a! ~# L4 e
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
1 R k. n! z# @* Z0 w/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
5 @' ?7 E' U( s1 u0 B$ U3 `+ d< ><FONT color=#0000ff>#include <STDIO.H>
8 m& q2 d( y7 Z% o#include <CONIO.H>
( x/ @2 j! D' F9 g#include <DOS.H></FONT></P>) v- `9 {: L1 Y: C' \/ _# g
< ><FONT color=#0000ff>#define IGNORE 0 , v2 d8 i" c! | l8 ]
#define RETRY 1
1 `0 ?& h; G2 g9 K: M#define ABORT 2 </FONT></P>- w& D' K- B; v2 P O
< ><FONT color=#0000ff>int buf[500]; </FONT></P>/ [; O9 S" b/ Q/ N6 h! l
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */
3 x! B% a9 Q: u' r2 p, l$ Z7 k2 istatic char *err_msg[] = {
9 Z( o0 f% A. M" w, P9 f0 l+ K"write protect", Q1 I6 ^ `0 f$ B, C7 f
"unknown unit",
0 v6 C) j X% v! }3 p9 t5 _"drive not ready", ( w' H; x! s4 f2 R7 M5 N
"unknown command",
, S4 s3 G: _( c9 I4 l. B7 N"data error (CRC)", : ~ [$ e% B/ u
"bad request",
2 R; h9 p6 o7 c, V" Q( P2 c$ T"seek error", ' m6 O- k/ B! K L# |6 G: N9 d
"unknown media type", " B6 q4 c- p! s: k. d t* c8 `
"sector not found",
A' L$ Q) u0 K! ?"printer out of paper",
' U7 `- R7 z# F"write fault", # q# S, [4 K) u8 M. t K, s
"read fault", : x6 o5 t- h q _2 ^
"general failure", ( y& H2 a v+ ~ C0 \- w
"reserved", # h' ?" _% W% v. S8 @
"reserved", . Q9 Y0 I6 ]+ S/ o& v8 }) g
"invalid disk change"
; c8 l# t& t+ W+ m" k- A# f}; </FONT></P>/ N( C' L$ a# g: o0 O
< ><FONT color=#0000ff>error_win(char *msg) 0 M3 ?8 R8 z* n `1 j
{ 5 t6 ^- x2 Y( x! @. }& ^! P4 I9 C
int retval; </FONT></P>% w3 I4 p* r J0 E4 t
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
# a0 M$ ]8 f' M8 c< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
. t8 U9 C1 [/ W- o# D1 Gwhile(1)
, x5 ]* Z. U2 C$ d) n{ 8 B3 k! ^/ s0 t' J' \
retval= getch(); 8 E1 m, F8 ?' z G9 y$ S3 q5 j
if (retval == 'a' || retval == 'A')
: ` w' A6 a5 J4 }8 \{
" u% O' ]; \. [$ Z" _3 Yretval = ABORT;
+ \' ` B* C5 f4 Q) y: B" sbreak; 7 n- a$ Z5 e& h$ Z7 M
} ; o9 G- W& g; x9 ]6 p
if (retval == 'r' || retval == 'R')
+ v3 C4 L2 ~5 J P$ Q$ ]3 ^{
, M1 x. Q# H0 \* B# n! a/ G# W5 gretval = RETRY;
$ @' Z2 b: r5 e+ B7 o( \break; ' q' h$ G8 @) c4 R
} , ?5 p3 Y1 f& {+ [% U
if (retval == 'i' || retval == 'I')
$ ^* K9 _$ l/ x" T: n1 H{
4 h$ s* Y) {3 Q3 E+ Z8 w# ^retval = IGNORE; % E9 c) Z, e, d' ?* Y: Z3 Z; E
break;
) f2 k2 D/ N9 y7 f. u} * _- w+ l$ V1 k; F
} </FONT></P>: q/ o+ H# f& W6 H4 s: D
< ><FONT color=#0000ff>return(retval);
' ], L9 ]9 ^( W# y. } U} </FONT></P>
2 Q0 O5 d: k! q4 u* k< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
3 D2 M9 j) v- Y% B* |! @" z: |/* of the parameters errval, bp and si to the handler. */ 6 A$ ~9 a. C! J6 T6 i& {4 b
#pragma warn -par </FONT></P>0 J% B8 Y( C$ l, ]% X# J) m$ V
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
6 Y( |: T/ i C; S# N0 ]{ . R8 `9 @! v7 L
static char msg[80]; & d" G; R3 ]; ?( i% x
unsigned di; 6 ^% \- }$ `$ l, o
int drive;
" g5 f; t) q! w! g+ J) qint errorno; </FONT></P>1 x0 ~0 Q9 s- ^2 h) ?( P
< ><FONT color=#0000ff>di= _DI; - D) Q% e: h5 o- [+ y
/* if this is not a disk error then it was another device having trouble */ </FONT></P>% }' f" X$ m5 _
< ><FONT color=#0000ff>if (ax < 0)
x; Q* T/ t& l1 o{ ) v: l. ^/ s* O: f
/* report the error */ 5 ~! b- d- z" H& s
error_win("Device error");
6 T9 Z* r2 M) v: I* R4 B' M/* and return to the program directly , H2 `/ @: p3 o1 O9 P1 _
requesting abort */
* z6 I0 B$ y: [0 H4 d# _4 Khardretn(ABORT);
2 M! r- V$ X: k( I) n$ s' z} 3 z7 d1 d% C9 ]- q& y: E3 ~
/* otherwise it was a disk error */ * Y c* {9 J- p X( i2 V$ ~
drive = ax & 0x00FF;
- W1 }; [' [6 x0 herrorno = di & 0x00FF; ! ]; L" S: d) N5 s
/* report which error it was */ / o& c9 `! m, X/ _1 i2 P: j
sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
# l$ j. J# {; G5 ?% derr_msg[errorno], 'A' + drive); 7 G) Q: k+ U) j! r3 D7 t: Y
/* return to the program via dos interrupt 0x23 with abort, retry */ 1 t3 n; H8 V& B5 V7 s7 d
/* or ignore as input by the user. */
2 M) @$ v* t# u+ \& ihardresume(error_win(msg));
% Z6 |+ P `; E! Q# Y$ E) vreturn ABORT; , X* s: ?5 o5 v" X$ j4 d3 ^
} 9 Y6 M5 Y/ P' A
#pragma warn +par </FONT></P>+ T* N: f& m0 `
< ><FONT color=#0000ff>int main(void) + i, J+ O. l# x2 X- g v& u
{ 7 T: `0 c3 G2 }& }: h7 Q
/* install our handler on the hardware problem interrupt */ 3 Y" b2 G; G: h" c
harderr(handler);
: M/ j, f/ W: B# mclrscr();
7 e/ k9 z. F, i5 @: B- |9 Rprintf("Make sure there is no disk in drive A:\n"); + V/ G2 `/ }$ S! S: t" D- Z
printf(" ress any key ....\n");
3 T& @+ T& W3 k n1 B% Igetch();
, J, A' ~& i& l# f3 E: G+ Wprintf("Trying to access drive A:\n"); 8 } H8 h+ i5 M* _
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
5 ]+ O, t ?2 |return 0; 5 V- ]/ L6 j2 u v* ]1 n6 E
} 8 J( l$ W; \" m/ ?+ ?) ^
</FONT>- _: @: Y& d" N/ A, x3 K, D
</P>
% H! t/ y I+ G8 ^" Q5 }: ]< ><FONT color=#ff0000>函数名: highvideo </FONT>
; n9 w- h" j% r0 e功 能: 选择高亮度文本字符
! y3 }& ]9 d1 ^$ l* {" d2 T! u用 法: void highvideo(void); ' F4 B( K f2 f- [
程序例: </P># k0 q; r( M, v2 {, q/ g6 \; R2 B
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
! K6 n" |) h$ h6 m< ><FONT color=#0000ff>int main(void)
0 u/ M' O% e7 O3 V) F{ 9 X' j" \$ Q" Y& ?$ O
clrscr(); </FONT></P>
_! J/ Q. |2 @! c* b5 q* l<P><FONT color=#0000ff>lowvideo(); * D5 @3 c- c6 t3 ^% r1 G8 u
cprintf("Low Intensity text\r\n");
$ S# C8 W- P7 c: fhighvideo(); 9 Q3 e; [5 e3 j3 p' a) a2 T
gotoxy(1,2); , E/ n' R% F* I- u' G" L
cprintf("High Intensity Text\r\n"); </FONT></P>
2 w/ J, `+ z+ H; o<P><FONT color=#0000ff>return 0; 5 v2 u4 I1 _. L# U" C3 {+ P% `( l3 a
}
5 N8 m; U# i, u" l- a</FONT>- q1 O. f/ B4 ^( ]% G0 P
</P>/ U& b# X# x0 N5 @) s
<P><FONT color=#ff0000>函数名: hypot </FONT>
; ^ @: ]* B" n功 能: 计算直角三角形的斜边长 - Q1 \9 B2 j3 X; k+ e# T( Y% V' C3 j
用 法: double hypot(double x, double y); : v4 @" g- I, Q @3 v
程序例: </P>* M* N$ g) M) b9 @& @
<P><FONT color=#0000ff>#include <STDIO.H>: Z' D- k( n* Y, r
#include <MATH.H></FONT></P>! B1 i6 v( B; S( o6 R7 s
<P><FONT color=#0000ff>int main(void)
/ e# k1 j4 }1 I0 [. Z{
6 C' h4 u' a S/ W, Z- F/ A4 Cdouble result;
% O& D( ^6 L4 xdouble x = 3.0; * o9 m. e/ r# U9 r! C2 P
double y = 4.0; </FONT></P>3 w4 j$ K% @$ e1 `, p, T# B8 j
<P><FONT color=#0000ff>result = hypot(x, y);
- F5 h1 @! ~5 x& G& [! T) hprintf("The hypotenuse is: %lf\n", result); </FONT></P>
( B0 y9 i6 e9 P% v h9 M1 n<P><FONT color=#0000ff>return 0; & s3 F: H4 A' _- ~; P
} </FONT>) |5 j1 [( h# Y0 Y5 Y
</P> |
zan
|