- 在线时间
- 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>
6 [6 K! u* h" G8 `) m功 能: 建立一个硬件错误处理程序 % ~3 V ?# q. I! x- I& w& T, f$ a
用 法: void harderr(int (*fptr)()); 1 p, C( W7 h2 G; x/ K
程序例: ( E4 z- r0 T, l, h. ?
<FONT color=#0000ff>/*This program will trap disk errors and prompt
, ~3 x% O& E5 \) Qthe user for action. Try running it with no
$ M9 P, h+ q2 Q8 Vdisk in drive A: to invoke its functions.*/ </FONT></P>% ], \; p. n; H, u/ \; L
< ><FONT color=#0000ff>#include <STDIO.H>& m5 X" W, @; o7 i: x( Y
#include <CONIO.H>
6 [8 _& }% M! r+ p. g/ `#include <DOS.H>$ q0 }. W% m$ F
#define IGNORE 0
8 a: s0 a; e1 I1 ?) F+ }#define RETRY 1
]; D" j F. V& A- D9 q/ x- Y#define ABORT 2 $ f$ c) C ?) _) Q: g! C" J! p6 ^
int buf[500];
' j& f+ u: k' B+ i1 o- C3 v! W/*define the error messages for trapping disk problems*/ / {0 {6 G6 e5 q6 E
static char *err_msg[] = {
! G& {" Z& {3 n$ P9 d6 r# t# V"write protect",
; x3 a$ [& I7 q, F3 j( s$ l, ]"unknown unit", 9 b2 \4 k6 U+ G, K, U1 T
"drive not ready", , N1 y9 a* Y2 ]1 J' c
"unknown command",
5 D& h+ A. [2 I"data error (CRC)", & _* v0 n5 l2 p5 ^, C: [
"bad request",
, Z" B, a* V* C: t/ \$ w5 z"seek error", 9 [4 y+ f: H! n# Z6 U& W( b
"unknown media type",
. M( L2 {. d* E. Z4 W"sector not found", % T$ @ R1 T9 C5 r% E+ ~4 E* X
"printer out of paper", 6 j) n' j$ T: G
"write fault",
# i9 _$ C) @! Y6 i1 ]" ^"read fault",
% f7 X$ j2 T1 U# |' d"general failure", & ^' m8 n( Z6 w8 [4 [( x& q# A
"reserved", $ U8 p% l7 \ X# V9 L
"reserved",
# t7 t( l8 x1 [ F) l7 x: N"invalid disk change" 8 x. c0 ]8 j' p6 f) j: g
}; </FONT></P>
8 s; w8 x1 p9 b2 E< ><FONT color=#0000ff>error_win(char *msg) 1 g& M9 I9 V. b x4 U* M
{
( ~7 I8 {' l* O7 e9 hint retval; </FONT></P>
: l$ v" c5 \" S/ S( a# \/ B< ><FONT color=#0000ff>cputs(msg); </FONT></P>
' U) D; T2 ]& f< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/ 1 k/ ]1 p( c, V" ]: n
while(1)
/ c7 B9 b% [; e: a* l7 Z+ C{
7 E1 Y2 F* c1 M% sretval= getch();
, B2 i# w. X* ^) K" D6 ~if (retval == 'a' || retval == 'A')
& [% M ^7 b0 A$ Q5 v{ 1 Z9 u) |9 i, {5 d3 S% g2 o/ o5 T
retval = ABORT; 0 A2 |% e& U" s) g5 [+ ~3 h& \0 X
break; + e- e P* T8 a3 F0 P; x' P
}
' R5 c: P8 M* o4 D: |+ Jif (retval == 'r' || retval == 'R')
$ R0 h/ ^2 I& ?' c- W: a" W{ 5 c, T0 X( r, w) c$ _. q& T. K
retval = RETRY; # J2 n" n) D d" T( z2 W4 L
break;
3 O% u/ \7 w, ~( h7 X& V} " r+ F/ v$ h6 {- B' |" W7 ]+ H
if (retval == 'i' || retval == 'I') $ r7 b- ?/ K. J6 P
{
/ M7 X9 a2 Y; W3 Z' v, M1 aretval = IGNORE;
8 j4 ], b- q1 @4 ~2 @" e7 Jbreak; $ n- B5 e$ }2 l. `: Y
} ; `- _" A L$ F+ w! h
} </FONT></P>
: h( D) m8 N7 _5 \1 E$ x9 V. `9 i< ><FONT color=#0000ff>return(retval);
! `. A/ Z, x" [8 m! B6 A7 r! M} </FONT></P>3 [3 W/ O$ f3 L& _+ P% p5 X
< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur V" B9 F( A5 j% ]% @( K: ?. _3 P6 z1 S
due to the non use of the parameters errval,
3 }2 k1 N/ A+ K! jbp and si to the handler.*/
! d- Y. h" p' Z& ^: k7 D6 \#pragma warn -par </FONT></P>- C7 e0 J5 H0 P+ r
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
/ K: _4 _5 w+ g n{ 6 a& e: }' Z- S% v$ u) F2 l! [( c
static char msg[80];
! `+ l4 U t1 Z t& J2 U0 g( hunsigned di; & B' |1 k2 X6 `5 m, [' A; b
int drive; ; q/ T( W7 V0 c ^, S- D5 D
int errorno;
* e9 a$ l/ V6 [2 }' ]$ c* ydi= _DI; : G8 Y I: F$ ?# D7 u2 ]" v( {
/*if this is not a disk error then it was
/ v$ ?( z5 `4 hanother device having trouble*/ </FONT></P>" p; P" p8 B0 t m3 d& ^& J
< ><FONT color=#0000ff>if (ax < 0) ) o( d% D1 V' q7 u+ Q7 } T* r
{
: z2 x+ S6 y5 f/* report the error */ 5 f o5 E I" e) ^/ f
error_win("Device error");
& {6 n* J6 }1 [ K2 g/* and return to the program directly requesting abort */ # V5 G4 Q+ R( u0 J* @* Q8 W
hardretn(ABORT);
1 v( B; [8 g3 ?9 D" S4 k1 s R( I} 8 H/ a/ |6 @3 p1 {6 ]) I
/* otherwise it was a disk error */
- q1 o% x* r- fdrive = ax & 0x00FF;
# L! Z1 B& h9 v5 t- {( t. N# Merrorno = di & 0x00FF; * g( B/ A, J- V9 X( e0 {; R0 C
/* report which error it was */
# C% |& W: j. v) R9 l5 x* Msprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
5 V% W6 O. f5 \9 A& Y$ V. serr_msg[errorno], 'A' + drive); # U/ r, F) \, G: L- V
/* $ L! d7 z8 Q( x$ R, T
return to the program via dos interrupt 0x23 with abort, retry,
, i1 r$ c) V9 q9 z% Zor ignore as input by the user.
( {2 o) Z! o! q" V( O% S*/
6 }, E: j5 @! F0 A7 u6 dhardresume(error_win(msg)); : N3 u! f. J3 ?5 \- d6 K- J
return ABORT; 7 K3 x2 S- J: L
}
* u. L0 f1 W! b4 z/ D#pragma warn +par </FONT></P>+ K: H4 J% m' r* d: j5 s
< ><FONT color=#0000ff>int main(void) % B, D$ j: K6 z8 s" E2 R: `
{
3 C- r$ `1 E" Z9 e" d4 f g/ F/* . R( k7 n: `) B+ _ E: M
install our handler on the hardware problem interrupt
* k* ]& j6 A$ r" A*/
: e S1 F2 g" N1 \4 u0 y' U4 dharderr(handler); & I3 O$ p; V0 T- _
clrscr(); 8 ]8 k4 A# Q( p* F
printf("Make sure there is no disk in drive A:\n");
9 X9 ^0 X7 y/ r5 Yprintf(" ress any key ....\n"); / A' D% A2 Y5 H7 m: D' g3 i Z
getch(); 0 }$ t# x) x1 x' L4 m8 x
printf("Trying to access drive A:\n"); 9 t- S3 J$ O' e- F
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); 1 \- s. ?9 K" U$ a6 u' I6 D! s
return 0;
+ D# I- J; R, T ~8 G8 y} , Y# m) u9 s$ z5 q! i
</FONT>
5 x8 |8 p N$ N( ~: u _, S& S</P>
, J' E% t% S5 G( H( v' E" H< ><FONT color=#ff0000>函数名: hardresume </FONT>
% _# C9 f' A. I/ T8 V功 能: 硬件错误处理函数 0 _# Z; u" E+ J. U. Z4 U9 t8 G4 f
用 法: void hardresume(int rescode); 6 T! O% Y) Z# {) e/ [! D
程序例:
7 `4 _3 u) A: \; Z5 |; \, {; M</P>
8 {: T ]8 b K# [< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */
2 Z0 W0 O( }" l7 V( s/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>
K: `5 J. K: g) p5 ?< ><FONT color=#0000ff>#include <STDIO.H>
! v8 s! ]6 u' O2 P+ Q2 [6 w#include <CONIO.H>( U i1 p) q: Q9 W( `0 I5 Q: N
#include <DOS.H></FONT></P>8 U* @& B6 h! e, u
< ><FONT color=#0000ff>#define IGNORE 0 L9 g0 p% p" ^4 j
#define RETRY 1 " ~5 W4 f, W* z _8 n9 N
#define ABORT 2 </FONT></P>/ R+ z2 e9 L* e; _) B
< ><FONT color=#0000ff>int buf[500]; </FONT></P>+ H. e2 ^8 k. g) W9 s) }0 U2 ~
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */ % g, Z) p4 l) J! y q! U: l& C: {
static char *err_msg[] = { 0 T+ v2 {, {; H8 P
"write protect",
) n$ k6 ]2 |3 K9 S+ W& r3 _"unknown unit", ) S- {, @! w2 y! c8 C. d6 B* u
"drive not ready", $ o# j1 m' `' b3 U& {
"unknown command", " [( X" T$ e" Y. |! d3 b8 Z
"data error (CRC)",
* D: w3 }: ^* F$ n( ?' O"bad request",
3 ~" e* P; x- d; J"seek error",
! r" G8 i4 Z" e& ~" Z"unknown media type", " V/ x. [( o0 n- G% j2 X* s
"sector not found",
$ O5 q% e8 f0 K! C- T5 v N"printer out of paper",
3 p* S1 R$ T4 J: W# Z: c3 R"write fault", - W, {/ e) P, T7 Q, k1 `" W: a
"read fault",
( ]5 e! q, Y, B4 i"general failure", ( w' E) j5 A( h) F
"reserved",
2 a/ A/ k2 A, r ?1 b9 J% d1 m"reserved",
* n$ H+ ^) h% W9 v7 m( B5 M7 f"invalid disk change" 5 }% w- f# G& u* x1 @6 B# ^" M
}; </FONT></P>
& z v; ^( z, Z# O! m) {+ T/ _< ><FONT color=#0000ff>error_win(char *msg) 0 x. r7 @( J% J6 I7 l3 S
{
3 b0 a9 I0 ?3 k# f' K, Kint retval; </FONT></P>4 a0 `6 w7 [, C6 C
< ><FONT color=#0000ff>cputs(msg); </FONT></P>
7 [8 u0 t3 d/ u q( S# {5 D< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */
1 r+ R, N* Q% x8 T" Z6 swhile(1) - t* J2 b% [" x4 m
{ $ Q" `+ a _. c: \2 A
retval= getch();
$ U6 w. Q a5 Q8 E3 ~& kif (retval == 'a' || retval == 'A') 7 l3 U: G: S0 z' j) z& p2 A
{ 9 D! m$ A7 @( o. c
retval = ABORT; 8 W2 T+ O5 Q7 l( Q
break;
- M# t: i8 w, f2 B _ I* e}
- | F2 r6 q' q# h4 Yif (retval == 'r' || retval == 'R')
7 q% U+ y: [7 v; I{
! H/ G$ V3 Q0 K+ \7 U6 ?retval = RETRY;
- g1 s% c6 q5 v6 |! cbreak; $ U4 Z+ |; ]' v
} 7 H' k& |; h. F2 w
if (retval == 'i' || retval == 'I') ' @$ A* V' \& G. d
{
7 R0 O6 c0 w2 O# x/ {. R/ oretval = IGNORE;
& R$ ]3 d D" e3 mbreak;
4 X! ]5 r& b% t: U8 e- G5 T, c}
P+ h! R7 z/ S' O} </FONT></P>
9 {# Z+ ?) O( [* m7 Q! ?0 x< ><FONT color=#0000ff>return(retval); 6 l0 ]7 f R' w. W* i7 n0 l& \4 W
} </FONT></P>
1 b* V, T9 h4 _/ T0 t6 H0 E< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
+ i' x5 h' S/ Q8 }! e, `" X/* of the parameters errval, bp and si to the handler. */
0 N7 I8 N7 J# {4 J O& l#pragma warn -par </FONT></P>
0 c% ^2 l9 i/ V$ X3 q< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
& n+ O1 Q5 @5 U* H1 V{ $ p$ }; E5 L0 T+ L
static char msg[80];
; _, i. y9 N/ B1 kunsigned di;
! X* N2 f! K! w& G. v& K7 R: Cint drive; ! A& S1 X0 X+ ?! [7 L& |+ M2 Y0 v& {
int errorno; </FONT></P>
3 T2 K) R, |/ f! X2 _3 S< ><FONT color=#0000ff>di= _DI; ' x ~8 E0 ?7 u) P( h! Y& [+ ~
/* if this is not a disk error then it was another device having trouble */ </FONT></P>
% n! f+ w' H$ R% _1 s1 g1 }< ><FONT color=#0000ff>if (ax < 0)
' C' h: k" N4 F$ X2 H: L{ / R! L5 Z3 S# }
/* report the error */
" h6 {! R! [0 u# e: Z/ Perror_win("Device error");
) B K! B, }* J9 p V( f0 P% m/* and return to the program directly J8 j* y$ d* |0 v
requesting abort */
% f4 w" c0 R k! b! O8 S4 u- Uhardretn(ABORT); ! L+ K( P7 _" A* s) l4 F
}
* @- c; @$ Y6 m% j/* otherwise it was a disk error */ ) ~. ]0 Q; b: d& }, s
drive = ax & 0x00FF;
+ H! Q6 P/ s2 M& u& s1 Kerrorno = di & 0x00FF;
% l/ V g; U }# B5 f/* report which error it was */
9 K! J0 u' M: L* @- Lsprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
5 O* K' E6 K! j, o5 cerr_msg[errorno], 'A' + drive); % W8 K% Z5 K7 ~* U1 B* u
/* return to the program via dos interrupt 0x23 with abort, retry */
8 g" q$ g; K9 E. T/* or ignore as input by the user. */ : D4 M! ?7 d# J9 \5 c2 b/ z
hardresume(error_win(msg)); * D4 H' K/ |2 A; G* {
return ABORT; 4 J; x/ u' O2 f& g: m; b0 x1 w5 P
} 7 P V/ o1 V- m/ o
#pragma warn +par </FONT></P>$ T4 e' T6 ~$ C& i- U
< ><FONT color=#0000ff>int main(void) & {" u# h8 f0 t8 y, f6 D
{
/ H4 H" k) @+ Y1 Z0 I7 _/* install our handler on the hardware problem interrupt */
: o* U/ a" I: U9 L4 n: E& lharderr(handler); " V ~" B/ C8 O7 z$ x
clrscr();
. E, L* j! F2 k0 m5 X8 Zprintf("Make sure there is no disk in drive A:\n");
5 W- @7 j# O1 `( nprintf(" ress any key ....\n"); : B: y% E: V( n* k1 u; F
getch(); ( S H2 a3 p3 a
printf("Trying to access drive A:\n"); ! k* ?! c( d- n9 G
printf("fopen returned %p\n",fopen("A:temp.dat", "w")); : y$ [; A1 x; p9 C, |
return 0; 4 O9 b& G6 O! c
} 8 }& B7 ~4 D1 B+ X. k7 k2 E* b
</FONT>; _- L5 t& P y7 U4 Z
</P>' z. k# a/ P- s7 w% y
< ><FONT color=#ff0000>函数名: highvideo </FONT>
: Q" y3 f; `# \# u8 n9 X% l7 q; F* V功 能: 选择高亮度文本字符 & W2 }/ s, X8 W) W" M$ X3 j% Z
用 法: void highvideo(void); 2 H8 p/ Y: C. I! x9 f
程序例: </P>) W2 R1 B# N; k# b. b
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P># R+ N6 W3 V8 T( ^9 R
< ><FONT color=#0000ff>int main(void) 3 O$ W1 c9 x# r) v
{
! P! K9 @: P$ Iclrscr(); </FONT></P>
/ M5 {8 T3 `$ \3 L<P><FONT color=#0000ff>lowvideo(); % E- {2 \( y" U4 i
cprintf("Low Intensity text\r\n"); 7 }% [: l1 @- Y3 O
highvideo();
1 N" X' v5 z, A. Y0 K3 n2 Jgotoxy(1,2);
5 a. p' {. Z/ G$ kcprintf("High Intensity Text\r\n"); </FONT></P># ~' c! b& Z2 F; }; \, J8 Q3 Y% C
<P><FONT color=#0000ff>return 0; ) p( ]# [* J0 O9 D; ^6 ?1 U
} 3 N! r0 T" X/ }' Y, b
</FONT>
5 S. R( x% x! i6 ^</P>0 t3 t- s3 c8 z& J" y
<P><FONT color=#ff0000>函数名: hypot </FONT>2 b; H& z! b7 z9 h' ?
功 能: 计算直角三角形的斜边长 ; T7 t3 \+ x' M
用 法: double hypot(double x, double y);
- R8 M. G4 [; u7 [! a程序例: </P>; b3 n/ O2 R. a
<P><FONT color=#0000ff>#include <STDIO.H>
) d7 m2 U3 O1 \#include <MATH.H></FONT></P>
4 N" l# [' [% [% v9 o' C2 o<P><FONT color=#0000ff>int main(void) 0 F3 M1 S! s, H- s' R6 l6 r; n
{ ; v& r' b" G% l, |, Y
double result;
2 |/ }; j |# P6 z$ l0 edouble x = 3.0;
- w2 s9 o6 G3 Y$ bdouble y = 4.0; </FONT></P>, w+ b! c' l" q1 _: U. I
<P><FONT color=#0000ff>result = hypot(x, y);
. z! Q( s- ?; p. T6 Tprintf("The hypotenuse is: %lf\n", result); </FONT></P>
: e# C( V( i: f; }! ^) O<P><FONT color=#0000ff>return 0; % m; d! w* C' F7 @+ T9 L
} </FONT>
5 Y- x# ?, B. P! w" i" |) j# y) o" {: Z( r# |</P> |
zan
|