- 在线时间
- 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>5 \) ~( P! m0 n) [
功 能: 建立一个硬件错误处理程序
5 p/ U) ?8 s7 J; L; Q# }用 法: void harderr(int (*fptr)()); 0 N. q/ ?, C# e# z; l" t, V
程序例: ( H6 Z% N4 y. J4 P9 ?9 U' U% J
<FONT color=#0000ff>/*This program will trap disk errors and prompt
) ~2 e" p1 S& _the user for action. Try running it with no
9 F0 g4 N# i1 f& o4 Xdisk in drive A: to invoke its functions.*/ </FONT></P>) V- k$ G; n5 ]7 g: V* c
< ><FONT color=#0000ff>#include <STDIO.H>
5 F+ U3 v/ s7 [#include <CONIO.H>3 n( s0 m. r* h/ ]
#include <DOS.H>2 N2 c/ p6 K8 |- A$ f6 N# Z: v- g! m
#define IGNORE 0
x9 Y2 T. X9 F#define RETRY 1 8 \' ^6 ^0 k- ]# A& D! E
#define ABORT 2 $ e( ], n: l3 }' p
int buf[500];
' R& f5 F0 p B0 J! q1 L/ S. n/*define the error messages for trapping disk problems*/
; Q$ Y9 U) y" q- U( X4 S" fstatic char *err_msg[] = { * P P' n0 @6 x7 \& a u8 J
"write protect",
& f- X2 b1 v* y6 ]0 `, d"unknown unit", $ V- y4 I* c! _ |
"drive not ready", 4 } d+ V8 A2 K7 b5 o
"unknown command",
. V) \1 s& R3 o3 V7 H"data error (CRC)",
0 i+ f7 E0 ]* r"bad request", 0 q0 B9 Z, M9 P9 N8 @0 [
"seek error",
; e) s5 z0 j! h" A) A"unknown media type",
3 d. ]* J" Z: } V& ?# M& |; \"sector not found",
& _8 a x6 q- J! g"printer out of paper", ) T; @( {' E* R1 Y, j! f
"write fault", - ?6 ] @6 u7 J2 ?
"read fault", 9 E5 I% o& Q U6 i1 X
"general failure",
4 [0 [5 m. Y1 J. R6 M* ^3 [+ d"reserved", 7 z: L" |$ d2 d9 W( `7 x+ }
"reserved",
$ T/ P' j& ~$ a7 h- t' z9 ]"invalid disk change"
& s. c. o$ X: a}; </FONT></P>& M8 X7 K; W; y# P" n4 F
< ><FONT color=#0000ff>error_win(char *msg) 1 z# `6 v' f& Y. P: O4 o' j
{ + q/ h: b% C2 @5 E/ O3 R! G
int retval; </FONT></P>
2 Y( ~5 y- K1 m% E; t; G9 g< ><FONT color=#0000ff>cputs(msg); </FONT></P>. p: S, j; g: a1 j! P# X+ h* U
< ><FONT color=#0000ff>/*prompt for user to press a key to abort, retry, ignore*/
, b- i+ g( o4 {while(1)
1 w- m* C; k6 _. k* {$ o3 q, `. q{
. K2 G$ C- y. [7 Eretval= getch(); 5 A* ?& q. Y4 s: m
if (retval == 'a' || retval == 'A')
4 W" S) r c p6 U{ + I. v* B5 C& H4 z+ `8 a
retval = ABORT;
& [: F, W3 w9 o8 Z, ^1 g& p: X0 `# _break; + l0 |. `7 P; U. `4 H/ t
}
( j* A3 {: ~% {7 A$ q. s5 [; iif (retval == 'r' || retval == 'R') b% c. U2 r% H; S/ }
{ 9 M+ s3 U2 A) I$ X" X7 ~6 h
retval = RETRY;
4 J& v; g- K! Y, [8 obreak; 6 a* Q2 Y1 @6 v, p
} ; @2 z9 p9 c8 h7 ?
if (retval == 'i' || retval == 'I')
6 H& i: n0 R! f+ Y0 T{
1 F4 d7 l6 y. P" h) ]retval = IGNORE;
# T% S8 w4 e* K7 T" w2 Zbreak; ; E& w7 C) u6 h. I; V3 G
}
3 @, A2 c* p& ]2 k7 d7 f} </FONT></P>( @, Q" o0 a! L- I* \" [$ ^
< ><FONT color=#0000ff>return(retval);
. O* o7 y/ z7 O' v; d4 w} </FONT></P>
8 I0 p7 D6 w4 _+ R+ {/ ]< ><FONT color=#0000ff>/*pragma warn -par reduces warnings which occur
7 E; w8 D) q- X: J' a) R+ fdue to the non use of the parameters errval,
+ x: ~0 O8 @5 r9 m9 ebp and si to the handler.*/ 0 p$ O- W+ r* D8 d! B3 D
#pragma warn -par </FONT></P>
. Q( I/ A4 |" x< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si) ( o" J- G; {( I6 S; _1 @
{
. a+ T7 ]7 t! A" L& _, W, Vstatic char msg[80]; . \- ~9 `4 L& \" K, C. D) [, Y- K
unsigned di;
( j$ e8 d( u2 i/ u" c& Wint drive; 7 B8 q" ?4 P) z! A7 g/ Z
int errorno; 4 q$ J- _' K0 p' R9 d
di= _DI;
! K7 Q, t8 L1 w6 Y$ {/*if this is not a disk error then it was
G( K) l. h( B3 @another device having trouble*/ </FONT></P>6 b' r! U/ G( T) ?! G2 ~ f$ _
< ><FONT color=#0000ff>if (ax < 0) . f P0 {: }9 u
{
& w" N+ C2 L- D/* report the error */ ; p+ M9 x5 s! a( w7 g4 J5 R
error_win("Device error"); 3 e) y& g' f9 e4 H. @+ V: d
/* and return to the program directly requesting abort */
1 Q6 p j* r6 H& { ?hardretn(ABORT); ) c1 g: {7 D: a
}
! h* \/ x% Q4 q6 ?/* otherwise it was a disk error */
/ K6 |. V1 N# Hdrive = ax & 0x00FF;
' _) ]% w; A5 @8 cerrorno = di & 0x00FF;
. R% E0 z& @4 u0 @( K# {/* report which error it was */
8 ?7 F- k. S1 D0 }sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", + w& e. K% P; P
err_msg[errorno], 'A' + drive);
- t- _* E- Z' N$ E/*
2 o' w1 Y8 R/ I; E7 u5 O1 H5 Oreturn to the program via dos interrupt 0x23 with abort, retry,
! M5 n/ V* X4 @1 D/ b" Hor ignore as input by the user.
+ O- c1 @: O, f*/ & U5 N; ^9 V# P1 v6 u2 t8 O
hardresume(error_win(msg)); & A1 X; Z# E# ?' W$ `
return ABORT; ' T; [& ?" a6 y8 ?1 a
}
G- L; H/ t3 v/ B/ b#pragma warn +par </FONT></P>8 u9 w! x& A5 R9 f
< ><FONT color=#0000ff>int main(void)
$ S) |4 a4 {2 v+ u: P{ ( w+ s2 q3 K- l+ R8 x. A. @
/* 9 R( L: g- H' l
install our handler on the hardware problem interrupt
' d5 [6 E; C6 l*/ 8 w& q1 b% _/ \, W
harderr(handler); 4 w" o- B# b" C4 k
clrscr();
8 U/ S; D; i/ k1 Y9 Uprintf("Make sure there is no disk in drive A:\n");
5 C7 N4 A9 L$ m2 {6 wprintf(" ress any key ....\n"); 4 x2 N- H- h/ y% |; x, K
getch();
. W6 ]% c6 o/ P! |. R+ v5 gprintf("Trying to access drive A:\n"); 7 R% M5 A; j' }7 W* A
printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
4 A) @$ ]* w0 L, e3 d) L2 A7 k# kreturn 0; g0 A# i1 {! c6 F+ L* \! W% ?
}
# M# F, p$ m [" w9 N6 ~</FONT>
4 n% ~7 o; c: S( w+ u</P>% P3 `6 _4 S' w4 n
< ><FONT color=#ff0000>函数名: hardresume </FONT>* i0 F" o7 O4 j6 k$ z# w
功 能: 硬件错误处理函数
# w" m2 Z7 O1 V: B6 v% I用 法: void hardresume(int rescode); l6 s- d( n- D% ~& R
程序例:
6 d7 S0 G3 J p+ k% J</P>! }0 o" b# v& _! M, P
< ><FONT color=#0000ff>/* This program will trap disk errors and prompt the user for action. */ * g0 N6 h% H% x7 t& D8 q
/* Try running it with no disk in drive A: to invoke its functions */ </FONT></P>2 o' R, K# J% _
< ><FONT color=#0000ff>#include <STDIO.H>6 w4 G( [$ L- [1 B: y {
#include <CONIO.H>
& f9 M T, A- C- S2 N#include <DOS.H></FONT></P>
* \1 x' |' k1 D0 c. w' f3 J1 D& ^< ><FONT color=#0000ff>#define IGNORE 0 4 c) r. ^% V# O2 ^7 E& ?7 e
#define RETRY 1
2 b. o* P: M4 K$ D. T$ T#define ABORT 2 </FONT></P>% I% w8 p( Z: j( [# V, V7 f8 ~+ w
< ><FONT color=#0000ff>int buf[500]; </FONT></P>2 ]. b6 y2 s! i! {% Q
< ><FONT color=#0000ff>/* define the error messages for trapping disk problems */
: c1 t# K5 F. D3 ~7 {, C7 N5 v9 Qstatic char *err_msg[] = {
- x. m% L; w& _; e) m"write protect", 2 p7 }1 }! o) D. {( S* l" B
"unknown unit",
. y% S6 B1 j5 [$ e"drive not ready",
$ y6 h/ E5 V, M7 N6 ^"unknown command",
& b# F' l; M6 W. b"data error (CRC)", # [5 j" Y: x" g5 X$ O7 `9 i; r
"bad request", 9 Z8 c- ^0 O- p* N
"seek error", ' U4 m- D3 Z* @/ u
"unknown media type", 3 r1 f0 s& s+ T5 R+ }
"sector not found", 1 j+ J+ P0 v9 K% w* W
"printer out of paper", & a1 ^4 \3 Y E4 i W& ^( n+ H
"write fault",
3 b& M, |4 {" y6 n/ G"read fault", # Z2 o/ O: N$ E9 P# t/ M5 S Y4 [8 B
"general failure", 0 K+ }( T8 t- h% [- }) D( r8 U6 v
"reserved", 5 ]+ R7 d: P' C4 Z6 j5 {
"reserved",
% p* Z, [( M7 J" Y% _"invalid disk change"
; F, c- J1 i4 h! p}; </FONT></P>" G6 n) W( L' ?/ m% O3 P+ I
< ><FONT color=#0000ff>error_win(char *msg)
1 c2 d' E3 k, H4 w& {{ ' q* L# Y" e1 B3 M
int retval; </FONT></P>
/ O) M' J3 c4 i* t f< ><FONT color=#0000ff>cputs(msg); </FONT></P>
4 P2 a4 x, c7 d9 Q& J7 x, o; Q< ><FONT color=#0000ff>/* prompt for user to press a key to abort, retry, ignore */ / _/ y, r1 R/ g6 [9 F. v- l$ |
while(1)
1 X, Z! F! |7 S( X( S# R* B{ 3 H' k) N3 f; J) \
retval= getch(); 4 H1 T" m) Z7 v# o- y+ m9 @
if (retval == 'a' || retval == 'A') + N. `2 d+ A2 m
{
# a! k( i# a) e; U, N( N) h! k6 ?retval = ABORT;
. G) Q9 s# D6 K& Y0 p& wbreak;
( X3 i( p; j$ U) v}
3 e2 U- _2 w0 s1 q( @9 k# _" w( jif (retval == 'r' || retval == 'R') 7 L; n9 e% `6 h+ V6 V' R# d. V
{ 3 d! x( b, y/ |0 s, r3 H, d
retval = RETRY; ; |; {! R: x$ q5 s$ V, {0 m
break; ; y& I1 T0 h0 S+ e
} , f5 A5 n. f' V0 i
if (retval == 'i' || retval == 'I') & V# P; B! J' `. s# I$ c( r5 d
{
5 O. E- x" O) Q+ Zretval = IGNORE;
$ ~+ t' J t9 c& [. \$ u, pbreak;
4 D8 y/ ?$ i/ w8 R( I! ]}
$ ~5 `9 Q% h) U7 L0 z} </FONT></P>
+ Q8 x& u/ Q9 ^! P< ><FONT color=#0000ff>return(retval); 4 T4 o' n2 l; M5 l0 x
} </FONT></P>
* w# L+ z" q V+ w+ R" E< ><FONT color=#0000ff>/* pragma warn -par reduces warnings which occur due to the non use */
3 _4 T7 ~6 Q4 @5 [ k, K/ b/* of the parameters errval, bp and si to the handler. */ 9 t0 r1 ^& [' [& c/ W
#pragma warn -par </FONT></P>- ^+ [ Z; P2 ~/ s& {7 w2 w
< ><FONT color=#0000ff>int handler(int errval,int ax,int bp,int si)
. R6 @/ q$ ~( N5 B{
1 d8 J8 a& W6 T: kstatic char msg[80]; $ M& D$ I- a2 N2 P5 ]* | t
unsigned di;
2 l, W$ o3 d: ]! b4 Wint drive;
( b# v* y2 u4 Kint errorno; </FONT></P>8 N7 `* R' C% z0 @# l
< ><FONT color=#0000ff>di= _DI; + @6 F" F" R Q4 | h( I1 y
/* if this is not a disk error then it was another device having trouble */ </FONT></P>( m) p; Z7 L, Y2 `! `5 N0 v
< ><FONT color=#0000ff>if (ax < 0)
- o5 _" _! \7 h" z; v{ ; N; { W- X: X
/* report the error */
! w& d- \. f; {" H. J: eerror_win("Device error"); 5 k5 ?) `& R" u; ]1 e+ @5 p
/* and return to the program directly
% H) H7 n) } x% wrequesting abort */ ! O8 F, E' G0 W. C1 Z1 \
hardretn(ABORT); 0 T% [$ b, A# k s( j
}
" m0 M* B" Y1 [) \! M/* otherwise it was a disk error */ ; R! v) k( D& Q5 k5 k$ X
drive = ax & 0x00FF; i; y3 z" c7 C5 w6 x
errorno = di & 0x00FF; " k# c8 l% t; G9 A
/* report which error it was */
: ~4 g/ `. O( |& M+ }7 o/ o( \sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
7 A) q9 Q3 O6 m6 n$ merr_msg[errorno], 'A' + drive);
# }" [+ ^6 d5 l& }. }! r/* return to the program via dos interrupt 0x23 with abort, retry */
2 o- F( L9 W+ d/* or ignore as input by the user. */
3 e: U, C( y) h0 \2 O, ^' G9 Uhardresume(error_win(msg));
U, j/ C! Q% _( h W A# \$ S' W Z+ qreturn ABORT; & a8 z) S- ]7 d! B
}
% @0 m& k! \6 R% I' \* X#pragma warn +par </FONT></P>" j7 a( n/ o& y* M U) E+ S
< ><FONT color=#0000ff>int main(void) 7 _2 a# d' |5 @2 P: ^' P
{ 5 d0 D+ `8 U, I3 H( S+ b, v
/* install our handler on the hardware problem interrupt */
% A8 d$ w& Y6 p1 S9 U* \: A1 |harderr(handler);
2 F. O( Z8 C' d7 P# k7 h3 L: c8 Bclrscr();
! o4 y5 [' }/ \9 ?6 w, A4 X) ~printf("Make sure there is no disk in drive A:\n"); & Z7 j" e) W9 ^( i: e6 Y. h
printf(" ress any key ....\n"); $ _- _- N. n2 y4 U9 s- z! @
getch(); ) C& L U: G9 N, x1 \
printf("Trying to access drive A:\n");
8 s3 ~# B( n* c) }8 {printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
3 E0 a; S% D5 B0 i! {' treturn 0;
& b& A: _9 g7 y4 P% d- z. k" e} 2 C6 Q2 z7 l* W- x# V
</FONT>
( b- ?9 a6 ?( D6 ?</P>
' W- j! ~" O& z8 X5 I- ^< ><FONT color=#ff0000>函数名: highvideo </FONT>" k4 `& q( d9 a* H( p6 E5 g
功 能: 选择高亮度文本字符 0 ?/ P) _; ]& [; f: b7 n* \, n
用 法: void highvideo(void); : ~3 X; L$ Q) \. `. u; |7 x
程序例: </P>' z' r, ^, L9 x8 L; |2 D$ x
< ><FONT color=#0000ff>#include <CONIO.H></FONT></P>
4 V- x% H1 v% H; k$ {< ><FONT color=#0000ff>int main(void)
3 ]4 u9 x. h+ `, @. o* M: \$ v{
* R0 I& D. b! d9 ]clrscr(); </FONT></P>, }& [5 f# W8 g# f& \. n4 J. _! Y
<P><FONT color=#0000ff>lowvideo();
; S% t5 \7 B5 I' q: acprintf("Low Intensity text\r\n"); & j2 t3 Q& D2 ?5 ?. p
highvideo(); ) g' }% u f" c* s1 \
gotoxy(1,2);
0 A6 O/ k" _/ B a% B- ecprintf("High Intensity Text\r\n"); </FONT></P>+ O) R/ i; d* \+ m; M
<P><FONT color=#0000ff>return 0; 0 U( {0 [7 b1 q) V4 y h
} , D p+ R' l3 N( C
</FONT>- @" w3 u' f5 q, ?4 y0 a. I
</P>$ i" j! u/ m9 M4 b/ p4 v8 j7 m# E
<P><FONT color=#ff0000>函数名: hypot </FONT>
$ d( b/ q0 j) c功 能: 计算直角三角形的斜边长 % ~/ Y; t6 w$ j: \0 P6 B
用 法: double hypot(double x, double y);
- B7 Z' {. t# p r* w$ q程序例: </P>
/ E- C) E8 m& M) y<P><FONT color=#0000ff>#include <STDIO.H>
9 z) z4 A3 E8 }, h( d#include <MATH.H></FONT></P>
$ C7 W4 a9 W' g3 M V$ ?<P><FONT color=#0000ff>int main(void)
( X. s' v8 j$ O$ t( U{
/ N; o* G4 g1 fdouble result;
/ K' d) s" D6 c$ f3 Kdouble x = 3.0;
/ `" C) f' `( y6 {4 `9 rdouble y = 4.0; </FONT></P>
; R7 T4 T1 r; d$ {! E" V<P><FONT color=#0000ff>result = hypot(x, y);
R' Y$ u+ M R/ Z& t0 wprintf("The hypotenuse is: %lf\n", result); </FONT></P>
/ J3 ~& @# B3 Z4 @' M, d) ]7 ^<P><FONT color=#0000ff>return 0;
+ }8 Z. K$ ^' e/ l* p: N) f+ a% A} </FONT>3 z( C7 [! f. V( S, @
</P> |
zan
|